]> git.localhorst.tv Git - l2e.git/blob - src/loader/Compiler.h
added Compiler to turn an interpretation into an object file
[l2e.git] / src / loader / Compiler.h
1 /*
2  * Compiler.h
3  *
4  *  Created on: Sep 11, 2012
5  *      Author: holy
6  */
7
8 #ifndef LOADER_COMPILER_H_
9 #define LOADER_COMPILER_H_
10
11 #include <iosfwd>
12 #include <map>
13 #include <memory>
14 #include <SDL.h>
15
16 namespace loader {
17
18 class Interpreter;
19
20 class Compiler {
21
22 public:
23         explicit Compiler(const Interpreter &intp);
24         ~Compiler() { }
25 private:
26         Compiler(const Compiler &);
27         Compiler &operator =(const Compiler &);
28
29 public:
30         void Write(std::ostream &);
31
32         struct Export {
33                 int nameOffset;
34                 int typeId;
35                 int dataOffset;
36         };
37
38         struct External {
39                 int nameOffset;
40                 int referenceOffset;
41                 int inlined;
42         };
43
44         struct ImageProperties {
45                 Uint32 flags;
46                 int width;
47                 int height;
48                 int depth;
49                 Uint32 rmask;
50                 Uint32 gmask;
51                 Uint32 bmask;
52                 Uint32 amask;
53         };
54
55 private:
56         void WriteHeader(std::ostream &);
57         void WriteExports(std::ostream &);
58         void WriteExternals(std::ostream &);
59         void WriteExportStrings(std::ostream &);
60         void WriteExternalStrings(std::ostream &);
61         void WriteImages(std::ostream &);
62         void WriteObjects(std::ostream &);
63
64         void Write(std::ostream &, const char *data, int amount);
65         void Pad(std::ostream &, int to);
66         static int Remaining(int value, int alignment);
67
68         int ReferenceOffset(int typeId, int objectId, std::ptrdiff_t fieldOffset) const;
69         int ObjectOffset(int typeId, int objectId) const;
70         int TypeOffset(int typeId) const;
71
72 private:
73         const Interpreter &intp;
74
75         int cursor;
76
77         int exportsOffset;
78         int externalsOffset;
79         int externalStringsOffset;
80         int exportStringsOffset;
81         int imagesOffset;
82         int objectsOffset;
83
84         std::map<int, int> objectOffsets;
85
86 };
87
88 }
89
90 #endif /* LOADER_COMPILER_H_ */