1
2
3
4
5
6 #ifndef CMAJOR_IR_GEN_OBJECT_INCLUDED
7 #define CMAJOR_IR_GEN_OBJECT_INCLUDED
8 #include <cmajor/ir/IrApi.hpp>
9 #include <stdint.h>
10
11 namespace cmajor { namespace ir {
12
13 class Emitter;
14
15 enum class OperationFlags : uint16_t
16 {
17 none= 0,
18 addr= 1 << 0,
19 deref= 1 << 1,
20 virtualCall= 1 << 2,
21 leaveFirstArg= 1 << 3,
22 copyFirst= 1 << 4,
23 functionCallFlags= leaveFirstArg,
24 derefCount= 0xFF << 8
25 };
26
27 inline OperationFlags operator|(OperationFlags left, OperationFlags right)
28 {
29 return OperationFlags(uint16_t(left) | uint16_t(right));
30 }
31
32 inline OperationFlags operator&(OperationFlags left, OperationFlags right)
33 {
34 return OperationFlags(uint16_t(left) & uint16_t(right));
35 }
36
37 inline uint8_t GetDerefCount(OperationFlags flags)
38 {
39 return uint8_t(uint16_t(flags & OperationFlags::derefCount) >> 8);
40 }
41
42 inline OperationFlags SetDerefCount(OperationFlags flags, uint8_t n)
43 {
44 return OperationFlags(flags | OperationFlags(n << 8));
45 }
46
47 class GenObject
48 {
49 public:
50 GenObject();
51 virtual ~GenObject();
52 virtual void Load(Emitter& emitter, OperationFlags flags) = 0;
53 virtual void Store(Emitter& emitter, OperationFlags flags) = 0;
54 void SetType(void* type_) { type = type_; }
55 void* GetType() { return type; }
56 private:
57 void* type;
58 };
59
60 class NativeValue : public GenObject
61 {
62 public:
63 NativeValue(void* value_) : value(value_) {}
64 void Load(Emitter& emitter, OperationFlags flags) override;
65 void Store(Emitter& emitter, OperationFlags flags) override;
66 private:
67 void* value;
68 };
69
70 } }
71
72 #endif // CMAJOR_IR_GEN_OBJECT_INCLUDED