fix cond gen
This commit is contained in:
parent
391b529960
commit
436d22b452
@ -41,7 +41,7 @@ std::shared_ptr<InstStore> build_InstStore(
|
||||
std::shared_ptr<BasicBlock> parent_bb
|
||||
);
|
||||
|
||||
std::shared_ptr<InstAlloca> build_InstAlloca(TypePtr_t type, std::shared_ptr<BasicBlock> parent_bb);
|
||||
std::shared_ptr<InstAlloca> build_InstAlloca(const std::string &str, TypePtr_t type, std::shared_ptr<BasicBlock> parent_bb);
|
||||
|
||||
std::shared_ptr<InstBinary> build_InstBinary(
|
||||
InstTag inst_tag,
|
||||
|
||||
@ -1,15 +1,17 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
assert len(sys.argv) > 2
|
||||
print("compile {}".format(sys.argv[1]))
|
||||
fullpath = sys.argv[1]
|
||||
libpath = sys.argv[2]
|
||||
(filename, extname) = os.path.splitext(sys.argv[1])
|
||||
assert len(sys.argv) > 3
|
||||
print("compile {}".format(sys.argv[2]))
|
||||
selector = sys.argv[1]
|
||||
fullpath = sys.argv[2]
|
||||
libpath = sys.argv[3]
|
||||
(filename, extname) = os.path.splitext(fullpath)
|
||||
'''
|
||||
python3 scripts/manual-compile.py build/manual-test/55_sort_test1.sy tools/sylib/libsysy_x86.a
|
||||
python3 my|clang scripts/manual-compile.py build/manual-test/55_sort_test1.sy tools/sylib/libsysy_x86.a
|
||||
'''
|
||||
# os.system(f"clang -emit-llvm -S {fullpath} -o {filename}.ll -O0 -fno-builtin")
|
||||
if selector != "my":
|
||||
print(f"clang -x c -c -m32 -emit-llvm -S {fullpath} -o {filename}.ll -O0 -fno-builtin")
|
||||
os.system(f"clang -x c -c -m32 -emit-llvm -S {fullpath} -o {filename}.ll -O0 -fno-builtin")
|
||||
print(f"llc --march=x86 --relocation-model=pic {filename}.ll -o {filename}.s")
|
||||
|
||||
8
scripts/simple-diff.sh
Executable file
8
scripts/simple-diff.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
basedir="build/output"
|
||||
for kase in `ls $basedir`
|
||||
do
|
||||
echo "$basedir/$kase"
|
||||
diff $basedir/$kase/my.out $basedir/$kase/llir.out
|
||||
done
|
||||
@ -116,16 +116,19 @@ if __name__ == '__main__':
|
||||
testcases = get_sy_testcases(sub_dir=category)
|
||||
all_schemes = [clang_llvm_scheme, thu_llvm_scheme, thu_thu_scheme] # gcc_gcc_scheme, ustc_ustc_scheme, ustc_ustc_no_vec_scheme]
|
||||
testers = []
|
||||
Print_C.print_header("[Removing old data...]\n\n")
|
||||
subprocess.run("rm -rf build/test_results/".split())
|
||||
subprocess.run("rm -rf build/output/".split())
|
||||
subprocess.run("rm -rf build/log/compile_log".split())
|
||||
subprocess.run("rm -rf build/log/run_log".split())
|
||||
subprocess.run("rm -rf build/log/test_result.log".split())
|
||||
|
||||
Tester(my_scheme, True, testcases).compile_rubbish(category=category)
|
||||
# Tester(llir_scheme, True, testcases).compile_reference(category=category)
|
||||
# Print_C.print_header("[Removing old data...]\n\n")
|
||||
# subprocess.run("rm -rf build/test_results/".split())
|
||||
# subprocess.run("rm -rf build/output/".split())
|
||||
# subprocess.run("rm -rf build/log/compile_log".split())
|
||||
# subprocess.run("rm -rf build/log/run_log".split())
|
||||
# subprocess.run("rm -rf build/log/test_result.log".split())
|
||||
|
||||
# mytester = Tester(my_scheme, True, testcases)
|
||||
# mytester.compile_rubbish(category=category)
|
||||
# mytester.run()
|
||||
clangtester = Tester(llir_scheme, True, testcases)
|
||||
clangtester.compile_reference(category=category)
|
||||
clangtester.run()
|
||||
# for scheme in all_schemes:
|
||||
# tester = Tester(scheme, is_trivial=True)
|
||||
# testers.append(tester)
|
||||
|
||||
@ -152,7 +152,7 @@ std::any Visitor::visitConstDef(SysyParser::ConstDefContext *ctx) {
|
||||
if (_scope_tab.get_level()) {
|
||||
// local const array
|
||||
// Keep a pointer to the base address, alloca_ = &array, *alloca_ = &array[0]
|
||||
auto alloca_ = build_InstAlloca(array_type, _state.current_bb);
|
||||
auto alloca_ = build_InstAlloca(const_name , array_type, _state.current_bb);
|
||||
_scope_tab.push_name(const_name, alloca_);
|
||||
// first dim base, ptr = *alloca_ = &array[0]
|
||||
auto base_ptr = build_InstGEP(alloca_, {CONST0, CONST0}, _state.current_bb);
|
||||
@ -205,7 +205,7 @@ std::any Visitor::visitVarDef(SysyParser::VarDefContext *ctx) {
|
||||
}
|
||||
// local variable
|
||||
else {
|
||||
auto alloca_ = build_InstAlloca(TypeHelper::TYPE_I32, _state.current_bb);
|
||||
auto alloca_ = build_InstAlloca(var_name, TypeHelper::TYPE_I32, _state.current_bb);
|
||||
_scope_tab.push_name(var_name, alloca_);
|
||||
if (ctx->initVal()) {
|
||||
auto init_val = any_to_Value(visitInitVal(ctx->initVal()));
|
||||
@ -224,7 +224,7 @@ std::any Visitor::visitVarDef(SysyParser::VarDefContext *ctx) {
|
||||
auto array_type = ArrayType::build_from_list(dim_list);
|
||||
// local array
|
||||
if (_scope_tab.get_level()) {
|
||||
auto alloca_ = build_InstAlloca(array_type, _state.current_bb);
|
||||
auto alloca_ = build_InstAlloca(var_name, array_type, _state.current_bb);
|
||||
_scope_tab.push_name(var_name, alloca_);
|
||||
if (ctx->initVal()) {
|
||||
_state.arr_dim_index = 0;
|
||||
@ -891,7 +891,7 @@ std::any Visitor::visitFuncFParams(SysyParser::FuncFParamsContext *ctx) {
|
||||
auto fparam_type = any_to_Type(visitFuncFParam(fparam_ctx));
|
||||
auto fparam_name = fparam_ctx->IDENT()->getText();
|
||||
auto fparam = std::make_shared<FParam>(fparam_name, fparam_type);
|
||||
auto alloca_ = build_InstAlloca(fparam_type, _state.current_bb);
|
||||
auto alloca_ = build_InstAlloca(fparam_name, fparam_type, _state.current_bb);
|
||||
build_InstStore(fparam, alloca_, _state.current_bb);
|
||||
_scope_tab.push_name(fparam_name, alloca_);
|
||||
_state.current_func->fparam_list.push_back(fparam);
|
||||
|
||||
@ -43,8 +43,9 @@ std::shared_ptr<InstStore> build_InstStore(
|
||||
}
|
||||
|
||||
// a little bit different, we put all alloca in the head of each basic block
|
||||
std::shared_ptr<InstAlloca> build_InstAlloca(TypePtr_t type, std::shared_ptr<BasicBlock> parent_bb) {
|
||||
std::shared_ptr<InstAlloca> build_InstAlloca(const std::string & name, TypePtr_t type, std::shared_ptr<BasicBlock> parent_bb) {
|
||||
auto inst_alloca = std::make_shared<InstAlloca>(type, parent_bb);
|
||||
inst_alloca->name = name;
|
||||
parent_bb->inst_list.insert(parent_bb->inst_list.begin(), inst_alloca);
|
||||
// parent_bb->inst_list.push_back(inst_alloca);
|
||||
return inst_alloca;
|
||||
|
||||
@ -179,7 +179,7 @@ static void _gen_blocks(std::ostream &ostr, const std::list<BasicBlockPtr_t> &bl
|
||||
assert(cond->ir_seqno >= 0);
|
||||
assert(bb_true->ir_seqno >= 0);
|
||||
assert(bb_false->ir_seqno >= 0);
|
||||
ostr << "i1 " << cond->ir_seqno << ", label %" << bb_true->ir_seqno << ", label %" << bb_false->ir_seqno;
|
||||
ostr << "i1 %" << cond->ir_seqno << ", label %" << bb_true->ir_seqno << ", label %" << bb_false->ir_seqno;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -401,6 +401,7 @@ static void _gen_blocks(std::ostream &ostr, const std::list<BasicBlockPtr_t> &bl
|
||||
assert(inst->ir_seqno != -1);
|
||||
auto pointer_type = Type::asType<PointerType>(inst->type);
|
||||
ostr << "%" << inst->ir_seqno << " = alloca " << pointer_type->pointed_type->to_IR_string() << ", align 4";
|
||||
ostr << " ;" << inst->name;
|
||||
break;
|
||||
}
|
||||
case InstTag::Zext: {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user