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