Pass all test

main
Odeinjul 11 months ago
parent 52ae9de107
commit 7dd4ceb63f
No known key found for this signature in database
GPG Key ID: E384228B2B38FFBB

@ -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')

@ -255,7 +255,7 @@ void IRBuilder::BinaryCondExprGen(Ptr<Value> lhs, Ptr<Value> 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<Value> origin, Ptr<Type> 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<Value> origin, Ptr<Type> expected) {
if (tmpFloat != nullptr) {
if (expected == INT32_T)
tmpInst =
CONST_INT(static_cast<int>(tmpInt->get_value()));
CONST_INT(static_cast<int>(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" <<std::endl;
//std::cout << stmt->loc <<std::endl;
stmt->accept(*this);
//std::cout << "Block2" <<std::endl;
}
scope.exit();
return ;
@ -725,16 +727,16 @@ void IRBuilder::visit(SyntaxTree::FuncCallStmt &node) {
auto name = node.name;
auto funcIdent = dynamic_pointer_cast<Function>(scope.find(name, true));
std::vector<Ptr<Value>> funcRParam;
auto arg = funcIdent->arg_begin();
auto arg_end = funcIdent->arg_end();
for (const auto &param : 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);
}

Loading…
Cancel
Save