]> git.localhorst.tv Git - l2e.git/blob - src/loader/Compiler.h
new language, new 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 <utility>
12 #include <vector>
13 #include <SDL.h>
14
15 namespace loader {
16
17 class Compiler {
18
19 public:
20         explicit Compiler(const Interpreter &intp);
21         ~Compiler() { }
22 private:
23         Compiler(const Compiler &);
24         Compiler &operator =(const Compiler &);
25
26 public:
27         void Write(std::iostream &);
28
29 private:
30         void ReserveHeader(std::ostream &);
31         void WriteObjects(std::ostream &);
32         void WriteOwnStrings(std::ostream &);
33         void WriteArrays(std::ostream &);
34         void WriteHeader(std::ostream &);
35         void WriteExports(std::ostream &);
36         void WriteExternals(std::ostream &);
37         void WriteImages(std::ostream &);
38         void WriteScripts(std::ostream &);
39
40         void Relocate(std::iostream &);
41         void RelocateArray(char *, int size);
42         void Relocate(unsigned int pos, char *dest, const TypeDescription &);
43         void RelocateScript(char *, unsigned int);
44
45         void PrepareExport(Export &, const std::string &);
46         void PrepareExternal(External &, const Interpreter::PostponedDefinition &);
47         void PrepareObject(Object &, const TypeDescription &, void *);
48
49         void Write(std::ostream &, const void *data, int amount);
50         void Pad(std::ostream &, int to);
51         void Fill(std::ostream &, int count, char c = '\0');
52         static int Remaining(int value, int alignment);
53
54 private:
55         const Interpreter &intp;
56
57         ObjectFileHeader fileHeader;
58
59         std::map<const void *, unsigned int> addressMap;
60         std::map<unsigned int, void *> images;
61         std::vector<std::pair<const char *, unsigned int> > scripts;
62
63 };
64
65 }
66
67 #endif