diff --git a/Student/task3/test.py b/Student/task3/test.py index 79e5bf0..3f0404d 100644 --- a/Student/task3/test.py +++ b/Student/task3/test.py @@ -30,7 +30,6 @@ def eval(EXE_PATH, TEST_BASE_PATH, optimization): subprocess.run(ExeGen_ptn.format(optimization, TEST_PATH, LL_PATH), shell=True, stderr=subprocess.PIPE) result = subprocess.run(Exe_ptn.format(TEST_PATH), shell=True, input=input_option, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out = result.stdout.split(b'\n') - print(str(result.returncode).encode()) if result.returncode != b'': out.append(str(result.returncode).encode()) for i in range(len(out)-1, -1, -1): @@ -39,6 +38,7 @@ def eval(EXE_PATH, TEST_BASE_PATH, optimization): out.remove(b'') case_succ = True with open(OUTPUT_PATH, "rb") as fout: + print(out[i]) i = 0 for line in fout.readlines(): line = line.strip(b'\r').strip(b'\n') diff --git a/src/SysYFIRBuilder/IRBuilder.cpp b/src/SysYFIRBuilder/IRBuilder.cpp index 63117eb..a0f94bf 100644 --- a/src/SysYFIRBuilder/IRBuilder.cpp +++ b/src/SysYFIRBuilder/IRBuilder.cpp @@ -255,7 +255,7 @@ void IRBuilder::BinaryCondExprGen(Ptr lhs, Ptr rhs, SyntaxTree::Bi tmpInst = builder->create_fcmp_lt(lhs, rhs); } else { - tmpInst = builder->create_icmp_gt(lhs, rhs); + tmpInst = builder->create_icmp_lt(lhs, rhs); } break; case SyntaxTree::BinaryCondOp::LTE: @@ -315,7 +315,9 @@ void IRBuilder::TypeConvert(Ptr origin, Ptr expected) { origin = builder->create_load(origin); tmpInst = origin; } - + if (expected->is_pointer_type()) { + expected = expected->get_pointer_element_type(); + } if (type == INT32_T && expected == INT1_T) { tmpInst = builder->create_icmp_ne(origin, CONST_INT(0)); return; @@ -344,7 +346,7 @@ void IRBuilder::TypeConvert(Ptr origin, Ptr expected) { if (tmpFloat != nullptr) { if (expected == INT32_T) tmpInst = - CONST_INT(static_cast(tmpInt->get_value())); + CONST_INT(static_cast(tmpFloat->get_value())); else if (expected == INT1_T) tmpInst = CONST_INT(tmpFloat->get_value() != 0); } @@ -566,7 +568,7 @@ void IRBuilder::visit(SyntaxTree::AssignStmt &node) { auto target = tmpInst; node.value->accept(*this); auto value = tmpInst; - TypeConvert(value, target->get_type()); + TypeConvert(value, target->get_type()->get_pointer_element_type()); value = tmpInst; builder->create_store(value, target); } @@ -603,10 +605,10 @@ void IRBuilder::visit(SyntaxTree::ReturnStmt &node) { // Finish void IRBuilder::visit(SyntaxTree::BlockStmt &node) { scope.enter(); + auto i = 0; for (const auto &stmt : node.body) { - //std::cout << "Block1" <loc <accept(*this); - //std::cout << "Block2" <(scope.find(name, true)); std::vector> funcRParam; - auto arg = funcIdent->arg_begin(); - auto arg_end = funcIdent->arg_end(); - for (const auto ¶m : node.params) { - if(arg == arg_end) { - break; - } - param->accept(*this); - TypeConvert(tmpInst, (*arg)->get_type()); + auto funcArgs = funcIdent->get_args(); + auto param = node.params.begin(); + auto param_end = node.params.end(); + auto i = 0; + for (const auto &arg : funcArgs) { + (*param)->accept(*this); + TypeConvert(tmpInst, arg->get_type()); funcRParam.push_back(tmpInst); - arg++; + param++; + i++; } tmpInst = builder->create_call(funcIdent, funcRParam); }