35 lines
1.1 KiB
C++
35 lines
1.1 KiB
C++
#include "3rdparty/easylogging++.h"
|
|
#include "common.h"
|
|
#include "llir.h"
|
|
#include "passes.h"
|
|
|
|
namespace antlrSysY {
|
|
|
|
static void connect(BasicBlockPtr_t pred, BasicBlockPtr_t succ) {
|
|
pred->successors.push_back(succ);
|
|
succ->predecessors.push_back(pred);
|
|
}
|
|
|
|
void PassBuildCFG::run(const Module &module) {
|
|
LOG(INFO) << "Run pass " << pass_name;
|
|
for (auto func : module.function_list) {
|
|
if (func->is_libfunc()) continue;
|
|
for (auto basicblock : func->bb_list) {
|
|
auto _inst_br = basicblock->inst_list.back();
|
|
if (!Value::is<InstBranch>(_inst_br)) continue;
|
|
auto inst_br = Value::as<InstBranch>(_inst_br);
|
|
if (inst_br->operand_list.size() == 1) {
|
|
connect(basicblock, Value::as<BasicBlock>(inst_br->operand_list[0]));
|
|
}
|
|
else if (inst_br->operand_list.size() == 3) {
|
|
connect(basicblock, Value::as<BasicBlock>(inst_br->operand_list[1]));
|
|
connect(basicblock, Value::as<BasicBlock>(inst_br->operand_list[2]));
|
|
}
|
|
else {
|
|
panic("br should have either 1 or 3 operands");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace antlrSysY
|