at least everything compiles
This commit is contained in:
parent
4458c23fc7
commit
4706c79a6d
@ -303,8 +303,7 @@ public:
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG(WARNING) << "Unexpected pointer type" << pointer->to_string();
|
LOG(WARNING) << "Unexpected pointer type" << pointer->to_string();
|
||||||
aim_to = pointer;
|
aim_to = nullptr;
|
||||||
panic("message");
|
|
||||||
}
|
}
|
||||||
element_type = extract_type(pointer, indices);
|
element_type = extract_type(pointer, indices);
|
||||||
operand_list.push_back(pointer);
|
operand_list.push_back(pointer);
|
||||||
|
|||||||
@ -65,7 +65,7 @@ class Compiler:
|
|||||||
Print_C.print_procedure(f"Generating {self.scheme}.ll")
|
Print_C.print_procedure(f"Generating {self.scheme}.ll")
|
||||||
completed = subprocess.run(frontend_instr.format(header=header, sy=sy, ir=ir).split(), stdout=log_file, stderr=log_file, bufsize=1)
|
completed = subprocess.run(frontend_instr.format(header=header, sy=sy, ir=ir).split(), stdout=log_file, stderr=log_file, bufsize=1)
|
||||||
if completed.returncode != 0:
|
if completed.returncode != 0:
|
||||||
Print_C.print_error(f"Generating {self.scheme}.ll failed! See {log}")
|
Print_C.print_error(f"Generating {self.scheme}.ll failed! See {log} | {sy}")
|
||||||
self.count_error += 1
|
self.count_error += 1
|
||||||
log_file.close()
|
log_file.close()
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ class Compiler:
|
|||||||
for testcase in self.testcases:
|
for testcase in self.testcases:
|
||||||
Print_C.print_subheader(f"[Compiling {self.scheme} | {testcase}]")
|
Print_C.print_subheader(f"[Compiling {self.scheme} | {testcase}]")
|
||||||
self.sy_to_ir(frontend_instr=frontend_instr, testcase=testcase, category=category)
|
self.sy_to_ir(frontend_instr=frontend_instr, testcase=testcase, category=category)
|
||||||
if self.count_error >= 5:
|
if self.count_error >= 1:
|
||||||
Print_C.print_error(f"Test script stopped due to too many errors")
|
Print_C.print_error(f"Test script stopped due to too many errors")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@ -34,8 +34,8 @@ class Tester:
|
|||||||
def compile(self):
|
def compile(self):
|
||||||
self.compiler.compile_all_tests(frontend_instr=self.frontend_instr, emit_llvm_ir=self.emit_llvm_ir)
|
self.compiler.compile_all_tests(frontend_instr=self.frontend_instr, emit_llvm_ir=self.emit_llvm_ir)
|
||||||
|
|
||||||
def compile_rubbish(self):
|
def compile_rubbish(self, category):
|
||||||
self.compiler.compile_rubbish(frontend_instr=self.frontend_instr, category="functional")
|
self.compiler.compile_rubbish(frontend_instr=self.frontend_instr, category=category)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.runner.run_all_tests()
|
self.runner.run_all_tests()
|
||||||
@ -103,7 +103,7 @@ my_scheme = {"scheme": "my",
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
testcases = get_sy_testcases(sub_dir="functional")
|
testcases = get_sy_testcases(sub_dir="functional_test")
|
||||||
all_schemes = [clang_llvm_scheme, thu_llvm_scheme, thu_thu_scheme] # gcc_gcc_scheme, ustc_ustc_scheme, ustc_ustc_no_vec_scheme]
|
all_schemes = [clang_llvm_scheme, thu_llvm_scheme, thu_thu_scheme] # gcc_gcc_scheme, ustc_ustc_scheme, ustc_ustc_no_vec_scheme]
|
||||||
testers = []
|
testers = []
|
||||||
Print_C.print_header("[Removing old data...]\n\n")
|
Print_C.print_header("[Removing old data...]\n\n")
|
||||||
@ -113,7 +113,7 @@ if __name__ == '__main__':
|
|||||||
subprocess.run("rm -rf build/log/run_log".split())
|
subprocess.run("rm -rf build/log/run_log".split())
|
||||||
subprocess.run("rm -rf build/log/test_result.log".split())
|
subprocess.run("rm -rf build/log/test_result.log".split())
|
||||||
|
|
||||||
Tester(my_scheme, True, testcases).compile_rubbish()
|
Tester(my_scheme, True, testcases).compile_rubbish(category="functional_test")
|
||||||
|
|
||||||
# for scheme in all_schemes:
|
# for scheme in all_schemes:
|
||||||
# tester = Tester(scheme, is_trivial=True)
|
# tester = Tester(scheme, is_trivial=True)
|
||||||
|
|||||||
@ -683,13 +683,13 @@ std::any Visitor::visitNumber(SysyParser::NumberContext *ctx) {
|
|||||||
std::any Visitor::visitIntConst(SysyParser::IntConstContext *ctx) {
|
std::any Visitor::visitIntConst(SysyParser::IntConstContext *ctx) {
|
||||||
int const_int = 0;
|
int const_int = 0;
|
||||||
if (ctx->DECIMAL_CONST()) {
|
if (ctx->DECIMAL_CONST()) {
|
||||||
const_int = std::stoi(ctx->DECIMAL_CONST()->getText(), nullptr, 10);
|
const_int = std::stol(ctx->DECIMAL_CONST()->getText(), nullptr, 10);
|
||||||
}
|
}
|
||||||
else if (ctx->HEXADECIMAL_CONST()) {
|
else if (ctx->HEXADECIMAL_CONST()) {
|
||||||
const_int = std::stoi(ctx->HEXADECIMAL_CONST()->getText(), nullptr, 16);
|
const_int = std::stol(ctx->HEXADECIMAL_CONST()->getText(), nullptr, 16);
|
||||||
}
|
}
|
||||||
else if (ctx->OCTAL_CONST()) {
|
else if (ctx->OCTAL_CONST()) {
|
||||||
const_int = std::stoi(ctx->OCTAL_CONST()->getText(), nullptr, 8);
|
const_int = std::stol(ctx->OCTAL_CONST()->getText(), nullptr, 8);
|
||||||
}
|
}
|
||||||
return build_ConstantInt("", const_int);
|
return build_ConstantInt("", const_int);
|
||||||
}
|
}
|
||||||
@ -730,6 +730,7 @@ std::any Visitor::visitLVal(SysyParser::LValContext *ctx) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
case Type::TypeTag::PointerType: {
|
case Type::TypeTag::PointerType: {
|
||||||
|
sysy_assert(0);
|
||||||
if (ctx->exp().empty()) {
|
if (ctx->exp().empty()) {
|
||||||
// ??? Pointer
|
// ??? Pointer
|
||||||
// @retval: InstLoad
|
// @retval: InstLoad
|
||||||
@ -743,6 +744,7 @@ std::any Visitor::visitLVal(SysyParser::LValContext *ctx) {
|
|||||||
auto pointed_type = std::dynamic_pointer_cast<PointerType>(lval->type)->pointed_type;
|
auto pointed_type = std::dynamic_pointer_cast<PointerType>(lval->type)->pointed_type;
|
||||||
auto inst_load = build_InstLoad(lval, pointed_type, _state.current_bb);
|
auto inst_load = build_InstLoad(lval, pointed_type, _state.current_bb);
|
||||||
|
|
||||||
|
LOG(INFO) << lval->to_string() << " " << lval->type->to_string();
|
||||||
auto ptr = build_InstGEP(inst_load, {CONST0}, _state.current_bb);
|
auto ptr = build_InstGEP(inst_load, {CONST0}, _state.current_bb);
|
||||||
pointed_type = std::dynamic_pointer_cast<PointerType>(ptr->type)->pointed_type;
|
pointed_type = std::dynamic_pointer_cast<PointerType>(ptr->type)->pointed_type;
|
||||||
LOG(INFO) << pointed_type->to_string();
|
LOG(INFO) << pointed_type->to_string();
|
||||||
@ -778,7 +780,11 @@ std::any Visitor::visitLVal(SysyParser::LValContext *ctx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case Type::TypeTag::ArrayType: {
|
case Type::TypeTag::ArrayType: {
|
||||||
sysy_assert(!ctx->exp().empty());
|
if (ctx->exp().empty()) {
|
||||||
|
// passing an array to function
|
||||||
|
auto ptr = build_InstGEP(lval, {CONST0, CONST0}, _state.current_bb);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
// get &array[0]
|
// get &array[0]
|
||||||
auto ptr = build_InstGEP(lval, {CONST0, CONST0}, _state.current_bb);
|
auto ptr = build_InstGEP(lval, {CONST0, CONST0}, _state.current_bb);
|
||||||
auto pointed_type = std::dynamic_pointer_cast<PointerType>(ptr->type)->pointed_type;
|
auto pointed_type = std::dynamic_pointer_cast<PointerType>(ptr->type)->pointed_type;
|
||||||
@ -806,7 +812,12 @@ std::any Visitor::visitLVal(SysyParser::LValContext *ctx) {
|
|||||||
return arr_elem_ptr;
|
return arr_elem_ptr;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
panic("Should be int");
|
// return the address of an sub array
|
||||||
|
auto array_type = std::dynamic_pointer_cast<ArrayType>(pointed_type);
|
||||||
|
auto dim_size = ConstantInt::make_shared(array_type->element_count);
|
||||||
|
auto inst_mul = build_InstBinary(InstTag::Mul, offset, dim_size, _state.current_bb);
|
||||||
|
auto arr_elem_ptr = build_InstGEP(ptr, {CONST0, offset}, _state.current_bb);
|
||||||
|
return arr_elem_ptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -879,8 +890,9 @@ std::any Visitor::visitFuncFParam(SysyParser::FuncFParamContext *ctx) {
|
|||||||
dim_list.push_back(exp_val->value);
|
dim_list.push_back(exp_val->value);
|
||||||
}
|
}
|
||||||
auto array_type = ArrayType::build_from_list(dim_list);
|
auto array_type = ArrayType::build_from_list(dim_list);
|
||||||
auto true_array_type = std::make_shared<PointerType>(array_type);
|
// auto true_array_type = std::make_shared<PointerType>(array_type);
|
||||||
return {true_array_type};
|
// return {true_array_type};
|
||||||
|
return {array_type};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user