1
2
3
4
5
6 #include <cmajor/cmsxi/BasicBlock.hpp>
7 #include <soulng/util/TextUtils.hpp>
8
9 namespace cmsxi {
10
11 BasicBlock::BasicBlock(int id_) : id(id_)
12 {
13 }
14
15 void BasicBlock::AddInstruction(Instruction* instruction)
16 {
17 instructions.push_back(std::unique_ptr<Instruction>(instruction));
18 }
19
20 void BasicBlock::Write(CodeFormatter& formatter, Function& function, Context& context)
21 {
22 int indent = formatter.IndentSize();
23 bool indentDecremented = false;
24 if (formatter.CurrentIndent() > 0)
25 {
26 formatter.DecIndent();
27 indentDecremented = true;
28 }
29 formatter.Write(Format("@" + std::to_string(id), indent, FormatWidth::min));
30 bool first = true;
31 for (const auto& inst : instructions)
32 {
33 inst->Write(formatter, function, context);
34 formatter.WriteLine();
35 if (first)
36 {
37 if (indentDecremented)
38 {
39 formatter.IncIndent();
40 }
41 first = false;
42 }
43 }
44 }
45
46 }