passed codegen local tests
This commit is contained in:
@ -32,7 +32,7 @@ inline void ScanForVar(FuncLayout &layout, std::shared_ptr<ActionItem> action,
|
|||||||
throw std::runtime_error("GetElementPtrAction should have a result_full");
|
throw std::runtime_error("GetElementPtrAction should have a result_full");
|
||||||
}
|
}
|
||||||
if (get_element_act->indices.size() == 1) {
|
if (get_element_act->indices.size() == 1) {
|
||||||
layout.AllocateItem(get_element_act->result_full, CalcSize(get_element_act->ty));
|
layout.AllocateItem(get_element_act->result_full, 4);
|
||||||
} else if (get_element_act->indices.size() == 2) {
|
} else if (get_element_act->indices.size() == 2) {
|
||||||
if (get_element_act->indices[0] != "0")
|
if (get_element_act->indices[0] != "0")
|
||||||
throw std::runtime_error("GetElementPtrAction with non-zero base index is not supported");
|
throw std::runtime_error("GetElementPtrAction with non-zero base index is not supported");
|
||||||
|
@ -88,7 +88,7 @@ inline void GenerateASM(std::shared_ptr<ActionItem> act, std::vector<std::string
|
|||||||
size_t element_sz = CalcSize(get_element_act->ty);
|
size_t element_sz = CalcSize(get_element_act->ty);
|
||||||
code_lines.push_back("slli t1, t1, " + std::to_string(std::countr_zero(element_sz)));
|
code_lines.push_back("slli t1, t1, " + std::to_string(std::countr_zero(element_sz)));
|
||||||
code_lines.push_back("add t2, t0, t1");
|
code_lines.push_back("add t2, t0, t1");
|
||||||
GenerateWriteAccess(get_element_act->result_full, element_sz, "t2", layout, code_lines);
|
GenerateWriteAccess(get_element_act->result_full, 4, "t2", layout, code_lines);
|
||||||
} else if (get_element_act->indices.size() == 2) {
|
} else if (get_element_act->indices.size() == 2) {
|
||||||
// struct access
|
// struct access
|
||||||
if (get_element_act->indices[0] != "0") {
|
if (get_element_act->indices[0] != "0") {
|
||||||
@ -138,6 +138,8 @@ inline void GenerateASM(std::shared_ptr<ActionItem> act, std::vector<std::string
|
|||||||
if (call_act->args_ty.size() != call_act->args_val_full.size()) {
|
if (call_act->args_ty.size() != call_act->args_val_full.size()) {
|
||||||
throw std::runtime_error("args_ty and args_full_name should have the same size");
|
throw std::runtime_error("args_ty and args_full_name should have the same size");
|
||||||
}
|
}
|
||||||
|
code_lines.push_back("addi sp, sp, -16");
|
||||||
|
code_lines.push_back("sw a0, 0(sp)");
|
||||||
for (size_t i = 0; i < num_of_args && i < 8; i++) {
|
for (size_t i = 0; i < num_of_args && i < 8; i++) {
|
||||||
IRVar2RISCVReg(call_act->args_val_full[i], CalcSize(call_act->args_ty[i]), "a" + std::to_string(i), layout,
|
IRVar2RISCVReg(call_act->args_val_full[i], CalcSize(call_act->args_ty[i]), "a" + std::to_string(i), layout,
|
||||||
code_lines);
|
code_lines);
|
||||||
@ -160,6 +162,8 @@ inline void GenerateASM(std::shared_ptr<ActionItem> act, std::vector<std::string
|
|||||||
size_t ret_sz = CalcSize(call_act->return_type);
|
size_t ret_sz = CalcSize(call_act->return_type);
|
||||||
GenerateWriteAccess(call_act->result_full, ret_sz, "a0", layout, code_lines);
|
GenerateWriteAccess(call_act->result_full, ret_sz, "a0", layout, code_lines);
|
||||||
}
|
}
|
||||||
|
code_lines.push_back("lw a0, 0(sp)");
|
||||||
|
code_lines.push_back("addi sp, sp, 16");
|
||||||
} else if (auto phi_act = std::dynamic_pointer_cast<PhiItem>(act)) {
|
} else if (auto phi_act = std::dynamic_pointer_cast<PhiItem>(act)) {
|
||||||
if (!process_phi) {
|
if (!process_phi) {
|
||||||
return; // for efficiency, phi actions are implemented as store action in the previous block
|
return; // for efficiency, phi actions are implemented as store action in the previous block
|
||||||
|
@ -32,6 +32,8 @@ class RISCVConstStrItem : public RISCVAsmItemBase {
|
|||||||
os << "\\t";
|
os << "\\t";
|
||||||
} else if (c == '\"') {
|
} else if (c == '\"') {
|
||||||
os << "\\\"";
|
os << "\\\"";
|
||||||
|
} else if (c == '\\') {
|
||||||
|
os << "\\\\";
|
||||||
} else {
|
} else {
|
||||||
os << c;
|
os << c;
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,11 @@ void IRBuilder::ActuralVisit(FuncDef_ASTNode *node) {
|
|||||||
size_t block_id = block_counter++;
|
size_t block_id = block_counter++;
|
||||||
current_block->label_full = "label_" + std::to_string(block_id);
|
current_block->label_full = "label_" + std::to_string(block_id);
|
||||||
|
|
||||||
if (node->func_name == "main") {
|
if (declare->func_name_raw == "main") {
|
||||||
func_def->init_block = main_init_block;
|
func_def->init_block = main_init_block;
|
||||||
} else {
|
} else {
|
||||||
func_def->init_block = std::make_shared<BlockItem>();
|
func_def->init_block = std::make_shared<BlockItem>();
|
||||||
func_def->init_block->label_full = "label_init_" + node->func_name;
|
func_def->init_block->label_full = "label_init_" + declare->func_name_raw;
|
||||||
for (auto &arg : node->params) {
|
for (auto &arg : node->params) {
|
||||||
std::string &arg_name_raw = arg.first;
|
std::string &arg_name_raw = arg.first;
|
||||||
std::string rvalue_full_name = "%.var.local." + std::to_string(scope_id) + "." + arg_name_raw + ".val";
|
std::string rvalue_full_name = "%.var.local." + std::to_string(scope_id) + "." + arg_name_raw + ".val";
|
||||||
|
Reference in New Issue
Block a user