[backend]解决了数组访存地址计算问题,加入了参数控制的中端、后端调试选项
This commit is contained in:
@@ -18,6 +18,9 @@ using namespace antlr4;
|
||||
// #include "LLVMIRGenerator.h"
|
||||
using namespace sysy;
|
||||
|
||||
int DEBUG = 0;
|
||||
int DEEPDEBUG = 0;
|
||||
|
||||
static string argStopAfter;
|
||||
static string argInputFile;
|
||||
static bool argFormat = false;
|
||||
@@ -27,7 +30,7 @@ void usage(int code = EXIT_FAILURE) {
|
||||
"Supported options:\n"
|
||||
" -h \tprint help message and exit\n";
|
||||
" -f \tpretty-format the input file\n";
|
||||
" -s {ast,ir,asm,llvmir}\tstop after generating AST/IR/Assembly\n";
|
||||
" -s {ast,ir,asm,llvmir,asmd,ird}\tstop after generating AST/IR/Assembly\n";
|
||||
cerr << msg;
|
||||
exit(code);
|
||||
}
|
||||
@@ -80,10 +83,16 @@ int main(int argc, char **argv) {
|
||||
// visit AST to generate IR
|
||||
SysYIRGenerator generator;
|
||||
generator.visitCompUnit(moduleAST);
|
||||
if (argStopAfter == "ir") {
|
||||
if (argStopAfter == "ir" || argStopAfter == "ird") {
|
||||
if (argStopAfter == "ird") {
|
||||
DEBUG = 1;
|
||||
}
|
||||
auto moduleIR = generator.get();
|
||||
SysYPrinter printer(moduleIR);
|
||||
printer.printIR();
|
||||
if (DEBUG) {
|
||||
cout << "=== Original IR ===\n";
|
||||
printer.printIR();
|
||||
}
|
||||
auto builder = generator.getBuilder();
|
||||
SysYOptPre optPre(moduleIR, builder);
|
||||
optPre.SysYOptimizateAfterIR();
|
||||
@@ -91,19 +100,35 @@ int main(int argc, char **argv) {
|
||||
cfa.init();
|
||||
ActiveVarAnalysis ava;
|
||||
ava.init(moduleIR);
|
||||
printer.printIR();
|
||||
|
||||
|
||||
if (DEBUG) {
|
||||
cout << "=== After CFA & AVA ===\n";
|
||||
printer.printIR();
|
||||
}
|
||||
DeadCodeElimination dce(moduleIR, &cfa, &ava);
|
||||
dce.runDCEPipeline();
|
||||
|
||||
if (DEBUG) {
|
||||
cout << "=== After 1st DCE ===\n";
|
||||
printer.printIR();
|
||||
}
|
||||
Mem2Reg mem2reg(moduleIR, builder, &cfa, &ava);
|
||||
mem2reg.mem2regPipeline();
|
||||
printer.printIR();
|
||||
if (DEBUG) {
|
||||
cout << "=== After Mem2Reg ===\n";
|
||||
printer.printIR();
|
||||
}
|
||||
Reg2Mem reg2mem(moduleIR, builder);
|
||||
reg2mem.DeletePhiInst();
|
||||
printer.printIR();
|
||||
if (DEBUG) {
|
||||
cout << "=== After Reg2Mem ===\n";
|
||||
printer.printIR();
|
||||
}
|
||||
dce.runDCEPipeline();
|
||||
if (DEBUG) {
|
||||
cout << "=== After 2nd DCE ===\n";
|
||||
printer.printIR();
|
||||
}
|
||||
cout << "=== Final IR ===\n";
|
||||
printer.printIR();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -111,7 +136,11 @@ int main(int argc, char **argv) {
|
||||
auto module = generator.get();
|
||||
sysy::RISCv64CodeGen codegen(module);
|
||||
string asmCode = codegen.code_gen();
|
||||
if (argStopAfter == "asm") {
|
||||
if (argStopAfter == "asm" || argStopAfter == "asmd") {
|
||||
if (argStopAfter == "asmd") {
|
||||
DEBUG = 1;
|
||||
DEEPDEBUG = 1;
|
||||
}
|
||||
cout << asmCode << endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user