You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.1 KiB
33 lines
1.1 KiB
#include "irgen/IRGen.h"
|
|
|
|
#include <memory>
|
|
|
|
#include "SysYParser.h"
|
|
#include "ir/IR.h"
|
|
#include "ir/passes/ConstFold.h"
|
|
#include "ir/passes/ConstProp.h"
|
|
#include "ir/passes/DCE.h"
|
|
#include "ir/passes/Mem2Reg.h"
|
|
#include "ir/passes/PassManager.h"
|
|
#include "utils/Log.h"
|
|
|
|
// 修改 GenerateIR 函数
|
|
std::unique_ptr<ir::Module> GenerateIR(SysYParser::CompUnitContext& tree,
|
|
const SemaResult& sema_result) {
|
|
auto module = std::make_unique<ir::Module>();
|
|
IRGenImpl gen(*module, sema_result.context, sema_result.symbol_table);
|
|
tree.accept(&gen);
|
|
|
|
ir::PassManager pass_manager;
|
|
pass_manager.AddPass(std::make_unique<ir::Mem2RegPass>());
|
|
pass_manager.AddPass(std::make_unique<ir::ConstFoldPass>());
|
|
pass_manager.AddPass(std::make_unique<ir::ConstPropPass>());
|
|
pass_manager.AddPass(std::make_unique<ir::ConstFoldPass>());
|
|
pass_manager.AddPass(std::make_unique<ir::DCEPass>());
|
|
DebugStream() << "[DEBUG] IRGenDriver: before mem2reg" << std::endl;
|
|
pass_manager.Run(*module);
|
|
DebugStream() << "[DEBUG] IRGenDriver: after scalar opts" << std::endl;
|
|
|
|
return module;
|
|
}
|