IR passed test, but bugs may remain
This commit is contained in:
@ -319,6 +319,7 @@ class IDExpr_ASTNode : public BasicExpr_ASTNode {
|
|||||||
friend class ASTSemanticCheckVisitor;
|
friend class ASTSemanticCheckVisitor;
|
||||||
friend class IRBuilder;
|
friend class IRBuilder;
|
||||||
IdentifierType id;
|
IdentifierType id;
|
||||||
|
IRVariableInfo cached_var_info;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IDExpr_ASTNode() = default;
|
IDExpr_ASTNode() = default;
|
||||||
|
@ -121,6 +121,7 @@ void IRBuilder::ActuralVisit(DefinitionStatement_ASTNode *node) {
|
|||||||
var_def->type = Type_AST2LLVM(node->var_type);
|
var_def->type = Type_AST2LLVM(node->var_type);
|
||||||
var_def->name_raw = var.first;
|
var_def->name_raw = var.first;
|
||||||
if (var.second) {
|
if (var.second) {
|
||||||
|
cur_block = main_init_block;
|
||||||
var.second->accept(this);
|
var.second->accept(this);
|
||||||
std::string init_var = var.second->IR_result_full;
|
std::string init_var = var.second->IR_result_full;
|
||||||
if (init_var[0] == '#') {
|
if (init_var[0] == '#') {
|
||||||
@ -352,10 +353,12 @@ void IRBuilder::ActuralVisit(JmpStatement_ASTNode *node) {
|
|||||||
just_encountered_jmp = true;
|
just_encountered_jmp = true;
|
||||||
} else if (node->jmp_type == 0) {
|
} else if (node->jmp_type == 0) {
|
||||||
// return
|
// return
|
||||||
cur_block->exit_action = std::make_shared<RETAction>();
|
|
||||||
if (node->return_value) {
|
if (node->return_value) {
|
||||||
node->return_value->accept(this);
|
node->return_value->accept(this);
|
||||||
|
cur_block->exit_action = std::make_shared<RETAction>();
|
||||||
std::dynamic_pointer_cast<RETAction>(cur_block->exit_action)->value = node->return_value->IR_result_full;
|
std::dynamic_pointer_cast<RETAction>(cur_block->exit_action)->value = node->return_value->IR_result_full;
|
||||||
|
} else {
|
||||||
|
cur_block->exit_action = std::make_shared<RETAction>();
|
||||||
}
|
}
|
||||||
std::dynamic_pointer_cast<RETAction>(cur_block->exit_action)->type = cur_func->return_type;
|
std::dynamic_pointer_cast<RETAction>(cur_block->exit_action)->type = cur_func->return_type;
|
||||||
just_encountered_jmp = true;
|
just_encountered_jmp = true;
|
||||||
@ -982,13 +985,16 @@ void IRBuilder::ActuralVisit(TernaryExpr_ASTNode *node) {
|
|||||||
std::dynamic_pointer_cast<UNConditionJMPAction>(cur_block->exit_action)->label_full = new_block->label_full;
|
std::dynamic_pointer_cast<UNConditionJMPAction>(cur_block->exit_action)->label_full = new_block->label_full;
|
||||||
cur_func->basic_blocks.push_back(new_block);
|
cur_func->basic_blocks.push_back(new_block);
|
||||||
cur_block = new_block;
|
cur_block = new_block;
|
||||||
auto phi_act = std::make_shared<PhiItem>();
|
ExprTypeInfo void_std = IdentifierType("void");
|
||||||
phi_act->result_full = "%.var.tmp." + std::to_string(tmp_var_counter++);
|
if (node->expr_type_info != void_std) {
|
||||||
phi_act->ty = Type_AST2LLVM(node->expr_type_info);
|
auto phi_act = std::make_shared<PhiItem>();
|
||||||
phi_act->values.push_back(std::make_pair(node->src1->IR_result_full, src1_end_block->label_full));
|
phi_act->result_full = "%.var.tmp." + std::to_string(tmp_var_counter++);
|
||||||
phi_act->values.push_back(std::make_pair(node->src2->IR_result_full, src2_end_block->label_full));
|
phi_act->ty = Type_AST2LLVM(node->expr_type_info);
|
||||||
cur_block->actions.push_back(phi_act);
|
phi_act->values.push_back(std::make_pair(node->src1->IR_result_full, src1_end_block->label_full));
|
||||||
node->IR_result_full = phi_act->result_full;
|
phi_act->values.push_back(std::make_pair(node->src2->IR_result_full, src2_end_block->label_full));
|
||||||
|
cur_block->actions.push_back(phi_act);
|
||||||
|
node->IR_result_full = phi_act->result_full;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRBuilder::ActuralVisit(AssignExpr_ASTNode *node) {
|
void IRBuilder::ActuralVisit(AssignExpr_ASTNode *node) {
|
||||||
@ -1029,7 +1035,7 @@ void IRBuilder::ActuralVisit(ParenExpr_ASTNode *node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void IRBuilder::ActuralVisit(IDExpr_ASTNode *node) {
|
void IRBuilder::ActuralVisit(IDExpr_ASTNode *node) {
|
||||||
IRVariableInfo var_info = node->current_scope->fetch_variable_for_IR(node->id);
|
IRVariableInfo var_info = node->cached_var_info;
|
||||||
if (var_info.variable_type == 0 || var_info.variable_type == 1 || var_info.variable_type == 3) {
|
if (var_info.variable_type == 0 || var_info.variable_type == 1 || var_info.variable_type == 3) {
|
||||||
if (node->is_requiring_lvalue) {
|
if (node->is_requiring_lvalue) {
|
||||||
node->IR_result_full = var_info.GenerateFullName();
|
node->IR_result_full = var_info.GenerateFullName();
|
||||||
|
@ -462,6 +462,7 @@ void ASTSemanticCheckVisitor::ActuralVisit(IDExpr_ASTNode *node) {
|
|||||||
// TODO: Implement this method
|
// TODO: Implement this method
|
||||||
// TODO: process type
|
// TODO: process type
|
||||||
node->expr_type_info = node->current_scope->fetch_varaible(node->id);
|
node->expr_type_info = node->current_scope->fetch_varaible(node->id);
|
||||||
|
node->cached_var_info = node->current_scope->fetch_variable_for_IR(node->id);
|
||||||
node->assignable = true;
|
node->assignable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user