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) 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) 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') out = result.stdout.split(b'\n')
print(str(result.returncode).encode())
if result.returncode != b'': if result.returncode != b'':
out.append(str(result.returncode).encode()) out.append(str(result.returncode).encode())
for i in range(len(out)-1, -1, -1): for i in range(len(out)-1, -1, -1):
@ -39,6 +38,7 @@ def eval(EXE_PATH, TEST_BASE_PATH, optimization):
out.remove(b'') out.remove(b'')
case_succ = True case_succ = True
with open(OUTPUT_PATH, "rb") as fout: with open(OUTPUT_PATH, "rb") as fout:
print(out[i])
i = 0 i = 0
for line in fout.readlines(): for line in fout.readlines():
line = line.strip(b'\r').strip(b'\n') 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); tmpInst = builder->create_fcmp_lt(lhs, rhs);
} }
else { else {
tmpInst = builder->create_icmp_gt(lhs, rhs); tmpInst = builder->create_icmp_lt(lhs, rhs);
} }
break; break;
case SyntaxTree::BinaryCondOp::LTE: case SyntaxTree::BinaryCondOp::LTE:
@ -315,7 +315,9 @@ void IRBuilder::TypeConvert(Ptr<Value> origin, Ptr<Type> expected) {
origin = builder->create_load(origin); origin = builder->create_load(origin);
tmpInst = origin; tmpInst = origin;
} }
if (expected->is_pointer_type()) {
expected = expected->get_pointer_element_type();
}
if (type == INT32_T && expected == INT1_T) { if (type == INT32_T && expected == INT1_T) {
tmpInst = builder->create_icmp_ne(origin, CONST_INT(0)); tmpInst = builder->create_icmp_ne(origin, CONST_INT(0));
return; return;
@ -344,7 +346,7 @@ void IRBuilder::TypeConvert(Ptr<Value> origin, Ptr<Type> expected) {
if (tmpFloat != nullptr) { if (tmpFloat != nullptr) {
if (expected == INT32_T) if (expected == INT32_T)
tmpInst = tmpInst =
CONST_INT(static_cast<int>(tmpInt->get_value())); CONST_INT(static_cast<int>(tmpFloat->get_value()));
else if (expected == INT1_T) else if (expected == INT1_T)
tmpInst = CONST_INT(tmpFloat->get_value() != 0); tmpInst = CONST_INT(tmpFloat->get_value() != 0);
} }
@ -566,7 +568,7 @@ void IRBuilder::visit(SyntaxTree::AssignStmt &node) {
auto target = tmpInst; auto target = tmpInst;
node.value->accept(*this); node.value->accept(*this);
auto value = tmpInst; auto value = tmpInst;
TypeConvert(value, target->get_type()); TypeConvert(value, target->get_type()->get_pointer_element_type());
value = tmpInst; value = tmpInst;
builder->create_store(value, target); builder->create_store(value, target);
} }
@ -603,10 +605,10 @@ void IRBuilder::visit(SyntaxTree::ReturnStmt &node) {
// Finish // Finish
void IRBuilder::visit(SyntaxTree::BlockStmt &node) { void IRBuilder::visit(SyntaxTree::BlockStmt &node) {
scope.enter(); scope.enter();
auto i = 0;
for (const auto &stmt : node.body) { for (const auto &stmt : node.body) {
//std::cout << "Block1" <<std::endl; //std::cout << stmt->loc <<std::endl;
stmt->accept(*this); stmt->accept(*this);
//std::cout << "Block2" <<std::endl;
} }
scope.exit(); scope.exit();
return ; return ;
@ -725,16 +727,16 @@ void IRBuilder::visit(SyntaxTree::FuncCallStmt &node) {
auto name = node.name; auto name = node.name;
auto funcIdent = dynamic_pointer_cast<Function>(scope.find(name, true)); auto funcIdent = dynamic_pointer_cast<Function>(scope.find(name, true));
std::vector<Ptr<Value>> funcRParam; std::vector<Ptr<Value>> funcRParam;
auto arg = funcIdent->arg_begin(); auto funcArgs = funcIdent->get_args();
auto arg_end = funcIdent->arg_end(); auto param = node.params.begin();
for (const auto &param : node.params) { auto param_end = node.params.end();
if(arg == arg_end) { auto i = 0;
break; for (const auto &arg : funcArgs) {
} (*param)->accept(*this);
param->accept(*this); TypeConvert(tmpInst, arg->get_type());
TypeConvert(tmpInst, (*arg)->get_type());
funcRParam.push_back(tmpInst); funcRParam.push_back(tmpInst);
arg++; param++;
i++;
} }
tmpInst = builder->create_call(funcIdent, funcRParam); tmpInst = builder->create_call(funcIdent, funcRParam);
} }

Loading…
Cancel
Save