feat(mir)链接完整的 SysY 运行时库

mxr 4 weeks ago
parent 966b5b9c7f
commit bbfb8f2c69

Binary file not shown.

@ -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

@ -2,6 +2,7 @@
#include <ostream>
#include <stdexcept>
#include <set>
#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<std::string> 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";

@ -7,7 +7,7 @@
#include "ir/IR.h"
#include "utils/Log.h"
#define DEBUG_Lower
//#define DEBUG_Lower
#ifdef DEBUG_Lower
#include <iostream>

Loading…
Cancel
Save