1
2
3
4
5
6 #ifndef CMAJOR_CMSXI_FUNCTION_INCLUDED
7 #define CMAJOR_CMSXI_FUNCTION_INCLUDED
8 #include <cmajor/cmsxi/Type.hpp>
9 #include <cmajor/cmsxi/BasicBlock.hpp>
10
11 namespace cmsxi {
12
13 class Context;
14
15 class Function : public Value
16 {
17 public:
18 Function(const std::string& name_, FunctionType* type_, Context& context);
19 Function(const Function&) = delete;
20 Function& operator=(const Function&) = delete;
21 BasicBlock* CreateBasicBlock();
22 BasicBlock* CreateCleanupBasicBlock();
23 void Finalize();
24 uint64_t GetNextResultNumber() { return nextResultNumber++; }
25 Type* GetType(Context& context) override { return type; }
26 Value* GetParam(int index) const;
27 std::string Name(Context& context) override { return "@" + name; }
28 void Write(CodeFormatter& formatter, Context& context);
29 void SetLinkOnce() { linkOnce = true; }
30 void SetMdId(int mdId_) { mdId = mdId_; }
31 private:
32 std::string name;
33 FunctionType* type;
34 std::vector<Instruction*> params;
35 std::unique_ptr<BasicBlock> entryBlock;
36 std::vector<std::std::unique_ptr<BasicBlock>>basicBlocks;
37 std::vector<std::std::unique_ptr<BasicBlock>>cleanupBasicBlocks;
38 uint64_t nextResultNumber;
39 bool linkOnce;
40 int mdId;
41 int nextBBNumber;
42 };
43
44 }
45
46 #endif // CMAJOR_CMSXI_FUNCTION_INCLUDED