[visitors] ported llvm asm generator
[ozulis.git] / src / ozulis / visitors / sizeof.cc
blob27e3006319c264278a90a3830992b5963b1077a6
1 #include <ozulis/compiler.hh>
2 #include <ozulis/target-data.hh>
3 #include <ozulis/visitors/browser.hh>
4 #include <ozulis/visitors/sizeof.hh>
6 namespace ozulis
8 namespace visitors
10 Sizeof::Sizeof()
11 : ConstVisitor_t(),
12 size(0)
16 Sizeof::~Sizeof()
20 uint8_t
21 Sizeof::pointerSize()
23 return Compiler::instance().targetData().findPointer()->size;
26 #define CONST_SIZE_TYPE(Type_, Size) \
27 static void visit##Type_##Type(const ast::Node & /*node_*/, Sizeof & ctx) \
28 { \
29 ctx.size += Size; \
32 CONST_SIZE_TYPE(Pointer, Sizeof::pointerSize())
33 CONST_SIZE_TYPE(Reference, Sizeof::pointerSize())
34 CONST_SIZE_TYPE(Void, 1)
35 CONST_SIZE_TYPE(Bool, 1)
36 CONST_SIZE_TYPE(Float, sizeof (float))
37 CONST_SIZE_TYPE(Double, sizeof (double))
39 static void visitIntegerType(const ast::Node & node_, Sizeof & ctx)
41 const ast::IntegerType & node =
42 reinterpret_cast<const ast::IntegerType &> (node_);
43 ctx.size += (node.size >> 3) + !!(node.size & 0x7);
46 void
47 Sizeof::initBase()
49 #define REGISTER_METHOD(Class) \
50 registerMethod(ast::Class::nodeTypeId(), visit##Class)
52 REGISTER_METHOD(PointerType);
53 REGISTER_METHOD(ReferenceType);
54 REGISTER_METHOD(VoidType);
55 REGISTER_METHOD(BoolType);
56 REGISTER_METHOD(IntegerType);
57 REGISTER_METHOD(FloatType);
58 REGISTER_METHOD(DoubleType);
60 completeWith<ConstBrowser<Sizeof> >();