|
|
|
@ -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 ¶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);
|
|
|
|
|
}
|
|
|
|
|