]> git.localhorst.tv Git - l2e.git/blob - src/loader/Compiler.h
ab26cea41e5ed955933c4a20e0598b9f1bbfc146
[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 "ObjectFile.h"
12
13 #include <iosfwd>
14 #include <map>
15 #include <memory>
16 #include <SDL.h>
17
18 namespace loader {
19
20 class Interpreter;
21
22 class Compiler {
23
24 public:
25         explicit Compiler(const Interpreter &intp);
26         ~Compiler() { }
27 private:
28         Compiler(const Compiler &);
29         Compiler &operator =(const Compiler &);
30
31 public:
32         void Write(std::ostream &);
33
34 private:
35         void WriteHeader(std::ostream &);
36         void WriteExports(std::ostream &);
37         void WriteExternals(std::ostream &);
38         void WriteExportStrings(std::ostream &);
39         void WriteExternalStrings(std::ostream &);
40         void WriteImages(std::ostream &);
41         void WriteObjects(std::ostream &);
42
43         void Write(std::ostream &, const char *data, int amount);
44         void Pad(std::ostream &, int to);
45         static int Remaining(int value, int alignment);
46
47         int ReferenceOffset(int typeId, int objectId, std::ptrdiff_t fieldOffset) const;
48         int ObjectOffset(int typeId, int objectId) const;
49         int GetTypeOffset(int typeId) const;
50
51 private:
52         const Interpreter &intp;
53
54         int cursor;
55
56         ObjectFileHeader fileHeader;
57
58         std::map<int, int> objectOffsets;
59
60 };
61
62 }
63
64 #endif /* LOADER_COMPILER_H_ */