]> git.localhorst.tv Git - l2e.git/blob - src/loader/Compiler.h
2f89752690664d3a33426621cc33a3a4f8c92a30
[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         void WriteImages(std::ostream &);
36
37         void Relocate(std::iostream &);
38         void RelocateArray(char *, int size);
39         void Relocate(unsigned int pos, char *dest, const TypeDescription &);
40
41         void PrepareExport(Export &, const std::string &);
42         void PrepareExternal(External &, const Interpreter::PostponedDefinition &);
43         void PrepareObject(Object &, const TypeDescription &, void *);
44
45         void Write(std::ostream &, const void *data, int amount);
46         void Pad(std::ostream &, int to);
47         void Fill(std::ostream &, int count, char c = '\0');
48         static int Remaining(int value, int alignment);
49
50 private:
51         const Interpreter &intp;
52
53         ObjectFileHeader fileHeader;
54
55         std::map<const void *, unsigned int> addressMap;
56         std::map<unsigned int, void *> images;
57
58 };
59
60 }
61
62 #endif