]> git.localhorst.tv Git - l2e.git/blob - src/loader/Compiler.h
new object file format in compiler
[l2e.git] / src / loader / Compiler.h
1 #ifndef LOADER_COMPILER_H_
2 #define LOADER_COMPILER_H_
3
4 #include "Interpreter.h"
5 #include "ObjectFile.h"
6 #include "TypeDescription.h"
7
8 #include <iosfwd>
9 #include <map>
10 #include <memory>
11 #include <SDL.h>
12
13 namespace loader {
14
15 class Compiler {
16
17 public:
18         explicit Compiler(const Interpreter &intp);
19         ~Compiler() { }
20 private:
21         Compiler(const Compiler &);
22         Compiler &operator =(const Compiler &);
23
24 public:
25         void Write(std::iostream &);
26
27 private:
28         void ReserveHeader(std::ostream &);
29         void WriteObjects(std::ostream &);
30         void WriteOwnStrings(std::ostream &);
31         void WriteArrays(std::ostream &);
32         void WriteHeader(std::ostream &);
33         void WriteExports(std::ostream &);
34         void WriteExternals(std::ostream &);
35
36         void Relocate(std::iostream &);
37         void RelocateArray(char *, int size);
38         void Relocate(char *, const TypeDescription &);
39
40         void PrepareExport(Export &, const std::string &);
41         void PrepareExternal(External &, const Interpreter::PostponedDefinition &);
42         void PrepareObject(Object &, const TypeDescription &, void *);
43
44         void Write(std::ostream &, const void *data, int amount);
45         void Pad(std::ostream &, int to);
46         void Fill(std::ostream &, int count, char c = '\0');
47         static int Remaining(int value, int alignment);
48
49 private:
50         const Interpreter &intp;
51
52         unsigned int cursor;
53
54         ObjectFileHeader fileHeader;
55
56         std::map<const void *, unsigned int> addressMap;
57
58 };
59
60 }
61
62 #endif