diff --git a/lib/libsysy.a b/lib/libsysy.a new file mode 100644 index 0000000..c6fe87c Binary files /dev/null and b/lib/libsysy.a differ diff --git a/scripts/verify_asm.sh b/scripts/verify_asm.sh index a4b8ae2..7b21379 100755 --- a/scripts/verify_asm.sh +++ b/scripts/verify_asm.sh @@ -52,7 +52,8 @@ expected_file="$input_dir/$stem.out" "$compiler" --emit-asm "$input" > "$asm_file" echo "汇编已生成: $asm_file" -aarch64-linux-gnu-gcc "$asm_file" -o "$exe" +# 静态链接 +aarch64-linux-gnu-gcc -no-pie "$asm_file" -L./lib -lsysy -static -o "$exe" echo "可执行文件已生成: $exe" if [[ "$run_exec" == true ]]; then diff --git a/src/mir/AsmPrinter.cpp b/src/mir/AsmPrinter.cpp index 4a35a81..5a45801 100644 --- a/src/mir/AsmPrinter.cpp +++ b/src/mir/AsmPrinter.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "utils/Log.h" @@ -447,10 +448,21 @@ void PrintAsm(const MachineModule& module, std::ostream& os) { os << ".size " << g.name << ", " << g.size << "\n\n"; } } - + + static const std::set externalFuncs = { + "getint", "getch", "getarray", "putint", "putch", "putarray", "puts", + "_sysy_starttime", "_sysy_stoptime", "starttime", "stoptime", + "getfloat", "putfloat", "getfarray", "putfarray", "memset", + "sysy_alloc_i32", "sysy_alloc_f32", "sysy_free_i32", "sysy_free_f32", + "sysy_zero_i32", "sysy_zero_f32" + }; DEBUG_MSG("module"); // 遍历所有函数,输出汇编 for (const auto& func : module.GetFunctions()) { + + if (externalFuncs.count(func->GetName())) { + continue; // 跳过库函数桩 + } DEBUG_MSG("func"); PrintAsm(*func, os); os << "\n"; diff --git a/src/mir/Lowering.cpp b/src/mir/Lowering.cpp index 80bd986..53c755d 100644 --- a/src/mir/Lowering.cpp +++ b/src/mir/Lowering.cpp @@ -7,7 +7,7 @@ #include "ir/IR.h" #include "utils/Log.h" -#define DEBUG_Lower +//#define DEBUG_Lower #ifdef DEBUG_Lower #include