]> git.localhorst.tv Git - l2e.git/blob - src/loader/Loader.h
new language, new compiler
[l2e.git] / src / loader / Loader.h
1 #ifndef LOADER_LOADER_H_
2 #define LOADER_LOADER_H_
3
4 #include "ObjectFile.h"
5 #include "TypeDescription.h"
6
7 #include <iosfwd>
8 #include <map>
9 #include <string>
10 #include <vector>
11 #include <SDL.h>
12
13 namespace loader {
14
15 class Loader {
16
17 public:
18         Loader() { }
19         ~Loader();
20
21 public:
22         void Load(const std::string &file);
23
24         const std::map<std::string, LoadedExport> &Exports() const { return exports; }
25
26         std::ostream &Dump(std::ostream &) const;
27
28 private:
29         void LoadExports(char *src, Export *begin, Export *end);
30         void LoadExternals(char *src, External *begin, External *end);
31         void LoadImages(char *src, Image *begin, Image *end);
32         void LoadObjects(char *src, Object *begin, Object *end);
33         void LoadObject(char *src, char *dest, const TypeDescription &);
34         void LoadArrays(char *src, Array *begin, Array *end);
35         void LoadScripts(char *src, Script *begin, Script *end);
36
37         void InitObjects(Object *begin, Object *end);
38         void InitObject(char *object, const TypeDescription &);
39         void InitArrays(Array *begin, Array *end);
40
41         struct MissingExternal {
42                 std::string identifier;
43                 char *dest;
44                 int typeId;
45                 bool inlined;
46         };
47         void LinkExternal(const MissingExternal &, const LoadedExport &);
48
49 private:
50         std::map<std::string, char *> objectFiles;
51         std::map<std::string, LoadedExport> exports;
52         std::map<std::string, SDL_Surface *> images;
53         std::vector<MissingExternal> unlinked;
54
55 };
56
57 }
58
59
60 namespace std {
61
62 inline ostream &operator <<(ostream &o, const loader::Loader &l) {
63         return l.Dump(o);
64 }
65
66 }
67
68 #endif