--- /dev/null
+/*
+ * Compiler.h
+ *
+ * Created on: Sep 11, 2012
+ * Author: holy
+ */
+
+#ifndef LOADER_COMPILER_H_
+#define LOADER_COMPILER_H_
+
+#include <iosfwd>
+#include <map>
+#include <memory>
+#include <SDL.h>
+
+namespace loader {
+
+class Interpreter;
+
+class Compiler {
+
+public:
+ explicit Compiler(const Interpreter &intp);
+ ~Compiler() { }
+private:
+ Compiler(const Compiler &);
+ Compiler &operator =(const Compiler &);
+
+public:
+ void Write(std::ostream &);
+
+ struct Export {
+ int nameOffset;
+ int typeId;
+ int dataOffset;
+ };
+
+ struct External {
+ int nameOffset;
+ int referenceOffset;
+ int inlined;
+ };
+
+ struct ImageProperties {
+ Uint32 flags;
+ int width;
+ int height;
+ int depth;
+ Uint32 rmask;
+ Uint32 gmask;
+ Uint32 bmask;
+ Uint32 amask;
+ };
+
+private:
+ void WriteHeader(std::ostream &);
+ void WriteExports(std::ostream &);
+ void WriteExternals(std::ostream &);
+ void WriteExportStrings(std::ostream &);
+ void WriteExternalStrings(std::ostream &);
+ void WriteImages(std::ostream &);
+ void WriteObjects(std::ostream &);
+
+ void Write(std::ostream &, const char *data, int amount);
+ void Pad(std::ostream &, int to);
+ static int Remaining(int value, int alignment);
+
+ int ReferenceOffset(int typeId, int objectId, std::ptrdiff_t fieldOffset) const;
+ int ObjectOffset(int typeId, int objectId) const;
+ int TypeOffset(int typeId) const;
+
+private:
+ const Interpreter &intp;
+
+ int cursor;
+
+ int exportsOffset;
+ int externalsOffset;
+ int externalStringsOffset;
+ int exportStringsOffset;
+ int imagesOffset;
+ int objectsOffset;
+
+ std::map<int, int> objectOffsets;
+
+};
+
+}
+
+#endif /* LOADER_COMPILER_H_ */