fix bug of big stack cost
This commit is contained in:
2
Makefile
2
Makefile
@ -1,6 +1,7 @@
|
|||||||
# 定义变量
|
# 定义变量
|
||||||
BUILD_DIR := makebuild # 构建目录
|
BUILD_DIR := makebuild # 构建目录
|
||||||
CMAKE_BUILD_TYPE := Release # 构建类型,可以是 Release 或 Debug
|
CMAKE_BUILD_TYPE := Release # 构建类型,可以是 Release 或 Debug
|
||||||
|
BUILTIN_ASM := src/IR/builtin.s # 内置汇编文件
|
||||||
|
|
||||||
# 默认目标
|
# 默认目标
|
||||||
all: build
|
all: build
|
||||||
@ -14,6 +15,7 @@ build:
|
|||||||
# 运行目标,运行生成的可执行文件
|
# 运行目标,运行生成的可执行文件
|
||||||
run:
|
run:
|
||||||
@cd $(BUILD_DIR) && ./zmxcc /dev/stdin -o /dev/stdout 2>/dev/null
|
@cd $(BUILD_DIR) && ./zmxcc /dev/stdin -o /dev/stdout 2>/dev/null
|
||||||
|
@cat $(BUILTIN_ASM) >>/dev/stdout
|
||||||
|
|
||||||
# 清理目标
|
# 清理目标
|
||||||
clean:
|
clean:
|
||||||
|
@ -12,6 +12,7 @@ class IRBuilder : public ASTNodeVirturalVisitor {
|
|||||||
std::shared_ptr<ModuleItem> prog;
|
std::shared_ptr<ModuleItem> prog;
|
||||||
std::shared_ptr<TypeDefItem> cur_class;
|
std::shared_ptr<TypeDefItem> cur_class;
|
||||||
std::shared_ptr<FunctionDefItem> cur_func;
|
std::shared_ptr<FunctionDefItem> cur_func;
|
||||||
|
std::shared_ptr<BlockItem> cur_alloca_block;
|
||||||
std::shared_ptr<BlockItem> cur_block;
|
std::shared_ptr<BlockItem> cur_block;
|
||||||
std::shared_ptr<BlockItem> main_init_block;
|
std::shared_ptr<BlockItem> main_init_block;
|
||||||
std::string cur_class_name;
|
std::string cur_class_name;
|
||||||
|
39
include/naivebackend/naivebackend.h
Normal file
39
include/naivebackend/naivebackend.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <ios>
|
||||||
|
#include <memory>
|
||||||
|
#include <ostream>
|
||||||
|
#include <string>
|
||||||
|
#include "IR/IR_basic.h"
|
||||||
|
class RISCVAsmItemBase {
|
||||||
|
public:
|
||||||
|
RISCVAsmItemBase() = default;
|
||||||
|
virtual ~RISCVAsmItemBase() = default;
|
||||||
|
virtual void RecursivePrint(std::ostream &os) const = 0;
|
||||||
|
};
|
||||||
|
namespace NaiveBackend {
|
||||||
|
class RISCVConstStrItem : public RISCVAsmItemBase {
|
||||||
|
public:
|
||||||
|
RISCVConstStrItem() = default;
|
||||||
|
~RISCVConstStrItem() = default;
|
||||||
|
void RecursivePrint(std::ostream &os) const override;
|
||||||
|
};
|
||||||
|
class RISCVGlobalVarItem : public RISCVAsmItemBase {
|
||||||
|
public:
|
||||||
|
RISCVGlobalVarItem() = default;
|
||||||
|
~RISCVGlobalVarItem() = default;
|
||||||
|
void RecursivePrint(std::ostream &os) const override;
|
||||||
|
};
|
||||||
|
class RISCVFuncItem : public RISCVAsmItemBase {
|
||||||
|
public:
|
||||||
|
RISCVFuncItem() = default;
|
||||||
|
~RISCVFuncItem() = default;
|
||||||
|
void RecursivePrint(std::ostream &os) const override;
|
||||||
|
};
|
||||||
|
class RISCVProgItem : public RISCVAsmItemBase {
|
||||||
|
public:
|
||||||
|
RISCVProgItem() = default;
|
||||||
|
~RISCVProgItem() = default;
|
||||||
|
void RecursivePrint(std::ostream &os) const override;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
void GenerateNaiveASM(std::ostream &os, std::shared_ptr<ModuleItem> prog);
|
@ -1,8 +1,9 @@
|
|||||||
add_subdirectory(ast)
|
add_subdirectory(ast)
|
||||||
add_subdirectory(semantic)
|
add_subdirectory(semantic)
|
||||||
add_subdirectory(IR)
|
add_subdirectory(IR)
|
||||||
|
add_subdirectory(naivebackend)
|
||||||
add_executable(zmxcc main.cpp)
|
add_executable(zmxcc main.cpp)
|
||||||
target_link_libraries(zmxcc semantic argparse IR)
|
target_link_libraries(zmxcc semantic argparse IR naivebackend)
|
||||||
set_target_properties(zmxcc PROPERTIES
|
set_target_properties(zmxcc PROPERTIES
|
||||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
|
||||||
)
|
)
|
@ -72,7 +72,9 @@ void IRBuilder::ActuralVisit(FuncDef_ASTNode *node) {
|
|||||||
std::dynamic_pointer_cast<UNConditionJMPAction>(cur_func->init_block->exit_action)->label_full =
|
std::dynamic_pointer_cast<UNConditionJMPAction>(cur_func->init_block->exit_action)->label_full =
|
||||||
current_block->label_full;
|
current_block->label_full;
|
||||||
is_in_func_def = true;
|
is_in_func_def = true;
|
||||||
|
cur_alloca_block=func_def->init_block;
|
||||||
node->func_body->accept(this);
|
node->func_body->accept(this);
|
||||||
|
cur_alloca_block=main_init_block;
|
||||||
is_in_func_def = false;
|
is_in_func_def = false;
|
||||||
|
|
||||||
if (!(cur_block->exit_action)) {
|
if (!(cur_block->exit_action)) {
|
||||||
@ -101,6 +103,7 @@ void IRBuilder::ActuralVisit(ClassDef_ASTNode *node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void IRBuilder::ActuralVisit(Program_ASTNode *node) {
|
void IRBuilder::ActuralVisit(Program_ASTNode *node) {
|
||||||
|
cur_alloca_block=main_init_block;
|
||||||
for (auto ch : node->sorted_children) {
|
for (auto ch : node->sorted_children) {
|
||||||
ch->accept(this);
|
ch->accept(this);
|
||||||
}
|
}
|
||||||
@ -149,7 +152,7 @@ void IRBuilder::ActuralVisit(DefinitionStatement_ASTNode *node) {
|
|||||||
} else {
|
} else {
|
||||||
for (const auto &var : node->vars) {
|
for (const auto &var : node->vars) {
|
||||||
auto var_def = std::make_shared<AllocaAction>();
|
auto var_def = std::make_shared<AllocaAction>();
|
||||||
cur_block->actions.push_back(var_def);
|
cur_alloca_block->actions.push_back(var_def);
|
||||||
var_def->num = 1;
|
var_def->num = 1;
|
||||||
var_def->type = Type_AST2LLVM(node->var_type);
|
var_def->type = Type_AST2LLVM(node->var_type);
|
||||||
var_def->name_full = "%.var.local." + std::to_string(node->current_scope->scope_id) + "." + var.first + ".addrkp";
|
var_def->name_full = "%.var.local." + std::to_string(node->current_scope->scope_id) + "." + var.first + ".addrkp";
|
||||||
@ -411,7 +414,7 @@ void IRBuilder::ActuralVisit(NewArrayExpr_ASTNode *node) {
|
|||||||
|
|
||||||
auto dim_info = std::make_shared<AllocaAction>();
|
auto dim_info = std::make_shared<AllocaAction>();
|
||||||
std::string dim_info_var = "%.var.tmp." + std::to_string(tmp_var_counter++);
|
std::string dim_info_var = "%.var.tmp." + std::to_string(tmp_var_counter++);
|
||||||
block->actions.push_back(dim_info);
|
cur_alloca_block->actions.push_back(dim_info);
|
||||||
dim_info->num = dims_with_size;
|
dim_info->num = dims_with_size;
|
||||||
dim_info->name_full = dim_info_var;
|
dim_info->name_full = dim_info_var;
|
||||||
dim_info->type = LLVMIRIntType(32);
|
dim_info->type = LLVMIRIntType(32);
|
||||||
|
@ -7,4 +7,6 @@ clang-18 -S -emit-llvm --target=riscv32-unknown-elf -O2 -fno-builtin-printf -fno
|
|||||||
builtin.c -o builtin_intermediate.ll
|
builtin.c -o builtin_intermediate.ll
|
||||||
sed 's/_builtin_/.builtin./g;s/string_/string./g;s/array_/array./g' builtin_intermediate.ll > builtin.ll
|
sed 's/_builtin_/.builtin./g;s/string_/string./g;s/array_/array./g' builtin_intermediate.ll > builtin.ll
|
||||||
rm builtin_intermediate.ll
|
rm builtin_intermediate.ll
|
||||||
llc-18 -march=riscv32 -mattr=+m builtin.ll -o builtin.s -O2
|
llc-18 -march=riscv32 -mattr=+m builtin.ll -o builtin_intermediate.s -O2
|
||||||
|
sed 's/Lfunc/builtin_Lfunc/g;s/L.str/builtin_L.str/g' builtin_intermediate.s > builtin.s
|
||||||
|
rm builtin_intermediate.s
|
126
src/IR/builtin.s
126
src/IR/builtin.s
@ -58,8 +58,8 @@
|
|||||||
lw s4, 8(sp) # 4-byte Folded Reload
|
lw s4, 8(sp) # 4-byte Folded Reload
|
||||||
addi sp, sp, 32
|
addi sp, sp, 32
|
||||||
ret
|
ret
|
||||||
.Lfunc_end0:
|
.builtin_Lfunc_end0:
|
||||||
.size .builtin.strcat, .Lfunc_end0-.builtin.strcat
|
.size .builtin.strcat, .builtin_Lfunc_end0-.builtin.strcat
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.option push
|
.option push
|
||||||
@ -78,8 +78,8 @@ string.length: # @string.length
|
|||||||
# %bb.2:
|
# %bb.2:
|
||||||
addi a0, a1, -1
|
addi a0, a1, -1
|
||||||
ret
|
ret
|
||||||
.Lfunc_end1:
|
.builtin_Lfunc_end1:
|
||||||
.size string.length, .Lfunc_end1-string.length
|
.size string.length, .builtin_Lfunc_end1-string.length
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.option push
|
.option push
|
||||||
@ -118,8 +118,8 @@ string.substring: # @string.substring
|
|||||||
lw s2, 0(sp) # 4-byte Folded Reload
|
lw s2, 0(sp) # 4-byte Folded Reload
|
||||||
addi sp, sp, 16
|
addi sp, sp, 16
|
||||||
ret
|
ret
|
||||||
.Lfunc_end2:
|
.builtin_Lfunc_end2:
|
||||||
.size string.substring, .Lfunc_end2-string.substring
|
.size string.substring, .builtin_Lfunc_end2-string.substring
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.option push
|
.option push
|
||||||
@ -131,16 +131,16 @@ string.parseInt: # @string.parseInt
|
|||||||
# %bb.0:
|
# %bb.0:
|
||||||
addi sp, sp, -16
|
addi sp, sp, -16
|
||||||
sw ra, 12(sp) # 4-byte Folded Spill
|
sw ra, 12(sp) # 4-byte Folded Spill
|
||||||
lui a1, %hi(.L.str)
|
lui a1, %hi(.builtin_L.str)
|
||||||
addi a1, a1, %lo(.L.str)
|
addi a1, a1, %lo(.builtin_L.str)
|
||||||
addi a2, sp, 8
|
addi a2, sp, 8
|
||||||
call sscanf
|
call sscanf
|
||||||
lw a0, 8(sp)
|
lw a0, 8(sp)
|
||||||
lw ra, 12(sp) # 4-byte Folded Reload
|
lw ra, 12(sp) # 4-byte Folded Reload
|
||||||
addi sp, sp, 16
|
addi sp, sp, 16
|
||||||
ret
|
ret
|
||||||
.Lfunc_end3:
|
.builtin_Lfunc_end3:
|
||||||
.size string.parseInt, .Lfunc_end3-string.parseInt
|
.size string.parseInt, .builtin_Lfunc_end3-string.parseInt
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.option push
|
.option push
|
||||||
@ -153,8 +153,8 @@ string.ord: # @string.ord
|
|||||||
add a0, a0, a1
|
add a0, a0, a1
|
||||||
lbu a0, 0(a0)
|
lbu a0, 0(a0)
|
||||||
ret
|
ret
|
||||||
.Lfunc_end4:
|
.builtin_Lfunc_end4:
|
||||||
.size string.ord, .Lfunc_end4-string.ord
|
.size string.ord, .builtin_Lfunc_end4-string.ord
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.option push
|
.option push
|
||||||
@ -164,14 +164,14 @@ string.ord: # @string.ord
|
|||||||
.type print,@function
|
.type print,@function
|
||||||
print: # @print
|
print: # @print
|
||||||
# %bb.0:
|
# %bb.0:
|
||||||
lui a1, %hi(.L.str.1)
|
lui a1, %hi(.builtin_L.str.1)
|
||||||
addi a1, a1, %lo(.L.str.1)
|
addi a1, a1, %lo(.builtin_L.str.1)
|
||||||
mv a2, a0
|
mv a2, a0
|
||||||
mv a0, a1
|
mv a0, a1
|
||||||
mv a1, a2
|
mv a1, a2
|
||||||
tail printf
|
tail printf
|
||||||
.Lfunc_end5:
|
.builtin_Lfunc_end5:
|
||||||
.size print, .Lfunc_end5-print
|
.size print, .builtin_Lfunc_end5-print
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.option push
|
.option push
|
||||||
@ -181,14 +181,14 @@ print: # @print
|
|||||||
.type println,@function
|
.type println,@function
|
||||||
println: # @println
|
println: # @println
|
||||||
# %bb.0:
|
# %bb.0:
|
||||||
lui a1, %hi(.L.str.2)
|
lui a1, %hi(.builtin_L.str.2)
|
||||||
addi a1, a1, %lo(.L.str.2)
|
addi a1, a1, %lo(.builtin_L.str.2)
|
||||||
mv a2, a0
|
mv a2, a0
|
||||||
mv a0, a1
|
mv a0, a1
|
||||||
mv a1, a2
|
mv a1, a2
|
||||||
tail printf
|
tail printf
|
||||||
.Lfunc_end6:
|
.builtin_Lfunc_end6:
|
||||||
.size println, .Lfunc_end6-println
|
.size println, .builtin_Lfunc_end6-println
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.option push
|
.option push
|
||||||
@ -198,14 +198,14 @@ println: # @println
|
|||||||
.type printInt,@function
|
.type printInt,@function
|
||||||
printInt: # @printInt
|
printInt: # @printInt
|
||||||
# %bb.0:
|
# %bb.0:
|
||||||
lui a1, %hi(.L.str)
|
lui a1, %hi(.builtin_L.str)
|
||||||
addi a1, a1, %lo(.L.str)
|
addi a1, a1, %lo(.builtin_L.str)
|
||||||
mv a2, a0
|
mv a2, a0
|
||||||
mv a0, a1
|
mv a0, a1
|
||||||
mv a1, a2
|
mv a1, a2
|
||||||
tail printf
|
tail printf
|
||||||
.Lfunc_end7:
|
.builtin_Lfunc_end7:
|
||||||
.size printInt, .Lfunc_end7-printInt
|
.size printInt, .builtin_Lfunc_end7-printInt
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.option push
|
.option push
|
||||||
@ -215,14 +215,14 @@ printInt: # @printInt
|
|||||||
.type printlnInt,@function
|
.type printlnInt,@function
|
||||||
printlnInt: # @printlnInt
|
printlnInt: # @printlnInt
|
||||||
# %bb.0:
|
# %bb.0:
|
||||||
lui a1, %hi(.L.str.3)
|
lui a1, %hi(.builtin_L.str.3)
|
||||||
addi a1, a1, %lo(.L.str.3)
|
addi a1, a1, %lo(.builtin_L.str.3)
|
||||||
mv a2, a0
|
mv a2, a0
|
||||||
mv a0, a1
|
mv a0, a1
|
||||||
mv a1, a2
|
mv a1, a2
|
||||||
tail printf
|
tail printf
|
||||||
.Lfunc_end8:
|
.builtin_Lfunc_end8:
|
||||||
.size printlnInt, .Lfunc_end8-printlnInt
|
.size printlnInt, .builtin_Lfunc_end8-printlnInt
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.option push
|
.option push
|
||||||
@ -240,8 +240,8 @@ toString: # @toString
|
|||||||
li a0, 15
|
li a0, 15
|
||||||
call malloc
|
call malloc
|
||||||
mv s1, a0
|
mv s1, a0
|
||||||
lui a0, %hi(.L.str)
|
lui a0, %hi(.builtin_L.str)
|
||||||
addi a1, a0, %lo(.L.str)
|
addi a1, a0, %lo(.builtin_L.str)
|
||||||
mv a0, s1
|
mv a0, s1
|
||||||
mv a2, s0
|
mv a2, s0
|
||||||
call sprintf
|
call sprintf
|
||||||
@ -251,8 +251,8 @@ toString: # @toString
|
|||||||
lw s1, 4(sp) # 4-byte Folded Reload
|
lw s1, 4(sp) # 4-byte Folded Reload
|
||||||
addi sp, sp, 16
|
addi sp, sp, 16
|
||||||
ret
|
ret
|
||||||
.Lfunc_end9:
|
.builtin_Lfunc_end9:
|
||||||
.size toString, .Lfunc_end9-toString
|
.size toString, .builtin_Lfunc_end9-toString
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.option push
|
.option push
|
||||||
@ -277,8 +277,8 @@ getString: # @getString
|
|||||||
li a0, 11
|
li a0, 11
|
||||||
call malloc
|
call malloc
|
||||||
mv s3, a0
|
mv s3, a0
|
||||||
lui a0, %hi(.L.str.4)
|
lui a0, %hi(.builtin_L.str.4)
|
||||||
addi s0, a0, %lo(.L.str.4)
|
addi s0, a0, %lo(.builtin_L.str.4)
|
||||||
addi a1, sp, 3
|
addi a1, sp, 3
|
||||||
mv a0, s0
|
mv a0, s0
|
||||||
call scanf
|
call scanf
|
||||||
@ -375,8 +375,8 @@ getString: # @getString
|
|||||||
lw s9, 4(sp) # 4-byte Folded Reload
|
lw s9, 4(sp) # 4-byte Folded Reload
|
||||||
addi sp, sp, 48
|
addi sp, sp, 48
|
||||||
ret
|
ret
|
||||||
.Lfunc_end10:
|
.builtin_Lfunc_end10:
|
||||||
.size getString, .Lfunc_end10-getString
|
.size getString, .builtin_Lfunc_end10-getString
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.option push
|
.option push
|
||||||
@ -388,16 +388,16 @@ getInt: # @getInt
|
|||||||
# %bb.0:
|
# %bb.0:
|
||||||
addi sp, sp, -16
|
addi sp, sp, -16
|
||||||
sw ra, 12(sp) # 4-byte Folded Spill
|
sw ra, 12(sp) # 4-byte Folded Spill
|
||||||
lui a0, %hi(.L.str)
|
lui a0, %hi(.builtin_L.str)
|
||||||
addi a0, a0, %lo(.L.str)
|
addi a0, a0, %lo(.builtin_L.str)
|
||||||
addi a1, sp, 8
|
addi a1, sp, 8
|
||||||
call scanf
|
call scanf
|
||||||
lw a0, 8(sp)
|
lw a0, 8(sp)
|
||||||
lw ra, 12(sp) # 4-byte Folded Reload
|
lw ra, 12(sp) # 4-byte Folded Reload
|
||||||
addi sp, sp, 16
|
addi sp, sp, 16
|
||||||
ret
|
ret
|
||||||
.Lfunc_end11:
|
.builtin_Lfunc_end11:
|
||||||
.size getInt, .Lfunc_end11-getInt
|
.size getInt, .builtin_Lfunc_end11-getInt
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.option push
|
.option push
|
||||||
@ -408,8 +408,8 @@ getInt: # @getInt
|
|||||||
.builtin.AllocateClassBody: # @.builtin.AllocateClassBody
|
.builtin.AllocateClassBody: # @.builtin.AllocateClassBody
|
||||||
# %bb.0:
|
# %bb.0:
|
||||||
tail malloc
|
tail malloc
|
||||||
.Lfunc_end12:
|
.builtin_Lfunc_end12:
|
||||||
.size .builtin.AllocateClassBody, .Lfunc_end12-.builtin.AllocateClassBody
|
.size .builtin.AllocateClassBody, .builtin_Lfunc_end12-.builtin.AllocateClassBody
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.option push
|
.option push
|
||||||
@ -430,8 +430,8 @@ getInt: # @getInt
|
|||||||
or a0, a0, a3
|
or a0, a0, a3
|
||||||
or a0, a0, a1
|
or a0, a0, a1
|
||||||
ret
|
ret
|
||||||
.Lfunc_end13:
|
.builtin_Lfunc_end13:
|
||||||
.size .builtin.GetArrayLength, .Lfunc_end13-.builtin.GetArrayLength
|
.size .builtin.GetArrayLength, .builtin_Lfunc_end13-.builtin.GetArrayLength
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.option push
|
.option push
|
||||||
@ -510,8 +510,8 @@ getInt: # @getInt
|
|||||||
lw s7, 12(sp) # 4-byte Folded Reload
|
lw s7, 12(sp) # 4-byte Folded Reload
|
||||||
addi sp, sp, 48
|
addi sp, sp, 48
|
||||||
ret
|
ret
|
||||||
.Lfunc_end14:
|
.builtin_Lfunc_end14:
|
||||||
.size .builtin.RecursiveAllocateArray, .Lfunc_end14-.builtin.RecursiveAllocateArray
|
.size .builtin.RecursiveAllocateArray, .builtin_Lfunc_end14-.builtin.RecursiveAllocateArray
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.option push
|
.option push
|
||||||
@ -541,35 +541,35 @@ getInt: # @getInt
|
|||||||
lw s0, 8(sp) # 4-byte Folded Reload
|
lw s0, 8(sp) # 4-byte Folded Reload
|
||||||
addi sp, sp, 16
|
addi sp, sp, 16
|
||||||
ret
|
ret
|
||||||
.Lfunc_end15:
|
.builtin_Lfunc_end15:
|
||||||
.size .builtin.AllocateArray, .Lfunc_end15-.builtin.AllocateArray
|
.size .builtin.AllocateArray, .builtin_Lfunc_end15-.builtin.AllocateArray
|
||||||
# -- End function
|
# -- End function
|
||||||
.option pop
|
.option pop
|
||||||
.type .L.str,@object # @.str
|
.type .builtin_L.str,@object # @.str
|
||||||
.section .rodata.str1.1,"aMS",@progbits,1
|
.section .rodata.str1.1,"aMS",@progbits,1
|
||||||
.L.str:
|
.builtin_L.str:
|
||||||
.asciz "%d"
|
.asciz "%d"
|
||||||
.size .L.str, 3
|
.size .builtin_L.str, 3
|
||||||
|
|
||||||
.type .L.str.1,@object # @.str.1
|
.type .builtin_L.str.1,@object # @.str.1
|
||||||
.L.str.1:
|
.builtin_L.str.1:
|
||||||
.asciz "%s"
|
.asciz "%s"
|
||||||
.size .L.str.1, 3
|
.size .builtin_L.str.1, 3
|
||||||
|
|
||||||
.type .L.str.2,@object # @.str.2
|
.type .builtin_L.str.2,@object # @.str.2
|
||||||
.L.str.2:
|
.builtin_L.str.2:
|
||||||
.asciz "%s\n"
|
.asciz "%s\n"
|
||||||
.size .L.str.2, 4
|
.size .builtin_L.str.2, 4
|
||||||
|
|
||||||
.type .L.str.3,@object # @.str.3
|
.type .builtin_L.str.3,@object # @.str.3
|
||||||
.L.str.3:
|
.builtin_L.str.3:
|
||||||
.asciz "%d\n"
|
.asciz "%d\n"
|
||||||
.size .L.str.3, 4
|
.size .builtin_L.str.3, 4
|
||||||
|
|
||||||
.type .L.str.4,@object # @.str.4
|
.type .builtin_L.str.4,@object # @.str.4
|
||||||
.L.str.4:
|
.builtin_L.str.4:
|
||||||
.asciz "%c"
|
.asciz "%c"
|
||||||
.size .L.str.4, 3
|
.size .builtin_L.str.4, 3
|
||||||
|
|
||||||
.ident "Ubuntu clang version 18.1.8 (++20240731024944+3b5b5c1ec4a3-1~exp1~20240731145000.144)"
|
.ident "Ubuntu clang version 18.1.8 (++20240731024944+3b5b5c1ec4a3-1~exp1~20240731145000.144)"
|
||||||
.section ".note.GNU-stack","",@progbits
|
.section ".note.GNU-stack","",@progbits
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "IR/IR.h"
|
#include "IR/IR.h"
|
||||||
|
#include "naivebackend/naivebackend.h"
|
||||||
#include "semantic/semantic.h"
|
#include "semantic/semantic.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
@ -28,6 +29,7 @@ int main(int argc, char **argv) {
|
|||||||
SemanticCheck(fin, ast);
|
SemanticCheck(fin, ast);
|
||||||
auto IR = BuildIR(ast);
|
auto IR = BuildIR(ast);
|
||||||
IR->RecursivePrint(fout);
|
IR->RecursivePrint(fout);
|
||||||
|
// GenerateNaiveASM(fout, IR);
|
||||||
} catch (const SemanticError &err) {
|
} catch (const SemanticError &err) {
|
||||||
std::cout << err.what() << std::endl;
|
std::cout << err.what() << std::endl;
|
||||||
return err.GetErrorCode();
|
return err.GetErrorCode();
|
||||||
|
5
src/naivebackend/CMakeLists.txt
Normal file
5
src/naivebackend/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
include_directories(${CMAKE_SOURCE_DIR}/include/naivebackend)
|
||||||
|
|
||||||
|
file(GLOB NAIVE_BACKEND_SOURCES "*.cpp")
|
||||||
|
add_library(naivebackend STATIC ${NAIVE_BACKEND_SOURCES})
|
||||||
|
target_link_libraries(naivebackend PUBLIC ast)
|
4
src/naivebackend/naivebackend.cpp
Normal file
4
src/naivebackend/naivebackend.cpp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#include "naivebackend.h"
|
||||||
|
void GenerateNaiveASM(std::ostream &os, std::shared_ptr<ModuleItem> prog) {
|
||||||
|
;
|
||||||
|
}
|
Reference in New Issue
Block a user