|
|
|
@ -141,7 +141,7 @@ void IRBuilder::visit(SyntaxTree::Assembly &node) {
|
|
|
|
|
|
|
|
|
|
// You need to fill them
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
// FINISH
|
|
|
|
|
void IRBuilder::visit(SyntaxTree::InitVal &node) {
|
|
|
|
|
node.expr->accept(*this);
|
|
|
|
|
}
|
|
|
|
@ -219,7 +219,6 @@ void IRBuilder::visit(SyntaxTree::FuncParam &node) {
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
void IRBuilder::visit(SyntaxTree::VarDef &node) {
|
|
|
|
|
// TODO: high dim array (not now)
|
|
|
|
|
int arrayLength;
|
|
|
|
|
Ptr<Value> initVal;
|
|
|
|
|
if (node.is_constant) {
|
|
|
|
@ -350,12 +349,20 @@ void IRBuilder::visit(SyntaxTree::VarDef &node) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
// FINISH
|
|
|
|
|
void IRBuilder::visit(SyntaxTree::LVal &node) {
|
|
|
|
|
auto ident = scope.find(node.name, false);
|
|
|
|
|
|
|
|
|
|
if (!node.array_index.empty()) {
|
|
|
|
|
//TODO
|
|
|
|
|
node.array_index[0]->accept(*this);
|
|
|
|
|
auto constIndex = dynamic_pointer_cast<ConstantInt>(tmpInst);
|
|
|
|
|
auto globalIdent = dynamic_pointer_cast<GlobalVariable>(ident);
|
|
|
|
|
if(globalIdent != nullptr && globalIdent->is_const() && constIndex == nullptr) {
|
|
|
|
|
auto arrayInit = dynamic_pointer_cast<ConstantArray>(globalIdent->get_init());
|
|
|
|
|
tmpInst = arrayInit->get_element_value(constIndex->get_value());
|
|
|
|
|
} else {
|
|
|
|
|
tmpInst = builder->create_gep(ident, {CONST_INT(0), tmpInst});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (ident->get_type()->is_pointer_type() && ident->get_type()->get_pointer_element_type()->is_array_type()) {
|
|
|
|
@ -364,7 +371,7 @@ void IRBuilder::visit(SyntaxTree::LVal &node) {
|
|
|
|
|
tmpInst = ident;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
isAddr = true;
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FINISH
|
|
|
|
@ -413,8 +420,6 @@ void IRBuilder::visit(SyntaxTree::BlockStmt &node) {
|
|
|
|
|
scope.enter();
|
|
|
|
|
for (const auto &stmt : node.body) {
|
|
|
|
|
stmt->accept(*this);
|
|
|
|
|
if (builder->get_insert_block()->get_terminator() != nullptr)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
scope.exit();
|
|
|
|
|
return ;
|
|
|
|
|