1 #include "tir/Constant.h"
6 #include "tir/BasicBlock.h"
8 #include "utils/DotPrinter.h"
12 ConstantInt*
Constant::CreateInt(
Context& ctx, uint8_t bits, uint32_t value) {
13 return ConstantInt::Create(ctx, IntegerType
::get(ctx
, bits
), value);
17 return ConstantNullPointer::Create(ctx);
20 std::ostream& ConstantNullPointer::print(std::ostream& os)
const {
25 std::ostream& ConstantInt::print(std::ostream& os)
const {
26 os << *type() <<
" " << zextValue();
30 std::ostream& GlobalVariable::print(std::ostream& os)
const {
return os; }
32 Argument::Argument(Function* parent,
Type* type,
unsigned index)
33 :
Value{parent->ctx(), type}, parent_{parent}, index_{index} {
37 std::ostream& Argument::print(std::ostream& os)
const {
43 std::ostream& Function::print(std::ostream& os)
const {
45 if(isExternalLinkage()) os <<
"external ";
46 if(isNoReturn()) os <<
"noreturn ";
47 os << *getReturnType() <<
" "
48 <<
"@" << name() <<
"(";
50 for(
auto* arg : args()) {
51 if(!isFirst) os <<
", ";
59 bb->print(os) <<
"\n";
66 void Function::printDot(std::ostream& os)
const {
69 std::unordered_map<BasicBlock*,
int> bbMap;
70 std::vector<BasicBlock*> terms;
72 int id = bb->printDotNode(dp);
77 for(
auto succ : bb->successors()) terms.push_back(succ);
78 if(terms.size() == 2) {
82 for(
auto term : terms) {
90 utils::
Generator<BasicBlock*> Function::reversePostOrder()
const {
91 std::unordered_set<BasicBlock*> visited;
92 std::queue<BasicBlock*> next;
93 assert(hasBody() && getEntryBlock() &&
"Function has no entry block");
95 while(!next.empty()) {
96 auto* bb = next.front();
98 if(visited.count(bb))
continue;
101 for(
auto succ : bb->successors()) {