diff options
author | David 'Digit' Turner <digit@google.com> | 2014-09-13 02:30:32 +0200 |
---|---|---|
committer | David 'Digit' Turner <digit@google.com> | 2014-09-13 02:30:32 +0200 |
commit | 60f24c2c943cdcbc12f20c4019650536991a8f04 (patch) | |
tree | 6ed9742ae357e157299c6497b4928a2d49f4c750 /emulator | |
parent | a0bf2facc25c00e023f5cdd4e4c8479465cbea3e (diff) | |
download | sdk-60f24c2c943cdcbc12f20c4019650536991a8f04.zip sdk-60f24c2c943cdcbc12f20c4019650536991a8f04.tar.gz sdk-60f24c2c943cdcbc12f20c4019650536991a8f04.tar.bz2 |
emulator/opengl/emugen: Get rid of VarConverter.
This patch simplifies VarType.h a bit, since there is no point
in having a specialized class like VarConverter to essentially
hold what is a size in bytes!
Change-Id: Idbba469a8594d1e964bbe79bbbea65934c42c033
Diffstat (limited to 'emulator')
-rw-r--r-- | emulator/opengl/host/tools/emugen/TypeFactory.cpp | 41 | ||||
-rw-r--r-- | emulator/opengl/host/tools/emugen/VarType.h | 76 |
2 files changed, 45 insertions, 72 deletions
diff --git a/emulator/opengl/host/tools/emugen/TypeFactory.cpp b/emulator/opengl/host/tools/emugen/TypeFactory.cpp index 8884225..357d6b3 100644 --- a/emulator/opengl/host/tools/emugen/TypeFactory.cpp +++ b/emulator/opengl/host/tools/emugen/TypeFactory.cpp @@ -24,32 +24,14 @@ TypeFactory * TypeFactory::m_instance = NULL; -static Var0 g_var0; -static Var8 g_var8; -static Var16 g_var16; -static Var32 g_var32; - typedef std::map<std::string, VarType> TypeMap; static TypeMap g_varMap; static bool g_initialized = false; static int g_typeId = 0; -static VarConverter * getVarConverter(int size) -{ - VarConverter *v = NULL; - - switch(size) { - case 0: v = &g_var0; break; - case 8: v = &g_var8; break; - case 16: v = &g_var16; break; - case 32: v = &g_var32; break; - } - return v; -} - #define ADD_TYPE(name, size, printformat,ispointer) \ - g_varMap.insert(std::pair<std::string, VarType>(name, VarType(g_typeId++, name, &g_var##size , printformat , ispointer))); + g_varMap.insert(std::pair<std::string, VarType>(name, VarType(g_typeId++, name, (size + 7) >> 3, printformat , ispointer))); void TypeFactory::initBaseTypes() { @@ -122,20 +104,27 @@ int TypeFactory::initFromFile(const std::string &filename) return -2; } - VarConverter *v = getVarConverter(atoi(size.c_str())); - if (v == NULL) { - fprintf(stderr, "Error: %d : unknown var width: %d\n", lc, atoi(size.c_str())); - return -1; - } + size_t bitSize = atoi(size.c_str()); + size_t byteSize = (bitSize + 7) >> 3; if (getVarTypeByName(name)->id() != 0) { fprintf(stderr, "Warining: %d : type %s is already known, definition in line %d is taken\n", lc, name.c_str(), lc); } - g_varMap.insert(std::pair<std::string, VarType>(name, VarType(g_typeId++, name, v ,printString,isPointer))); + g_varMap.insert(std::pair<std::string, VarType>( + name, VarType(g_typeId++, + name, + byteSize, + printString, + isPointer))); std::string constName = "const " + name; - g_varMap.insert(std::pair<std::string, VarType>(constName, VarType(g_typeId++, constName, v ,printString,isPointer))); //add a const type + g_varMap.insert(std::pair<std::string, VarType>( + constName, VarType(g_typeId++, + constName, + byteSize, + printString, + isPointer))); //add a const type } g_initialized = true; return 0; diff --git a/emulator/opengl/host/tools/emugen/VarType.h b/emulator/opengl/host/tools/emugen/VarType.h index 41bb645..b6937a0 100644 --- a/emulator/opengl/host/tools/emugen/VarType.h +++ b/emulator/opengl/host/tools/emugen/VarType.h @@ -18,60 +18,44 @@ #include <string> -class VarConverter { -public: - VarConverter(size_t bytes) : m_bytes(bytes) {} - size_t bytes() const { return m_bytes; } -private: - size_t m_bytes; -}; - -class Var8 : public VarConverter { -public: - Var8() : VarConverter(1) {} -}; - -class Var16 : public VarConverter { -public: - Var16() : VarConverter(2) {} -}; - -class Var32 : public VarConverter { -public: - Var32() : VarConverter(4) {} -}; - -class Var0 : public VarConverter { -public: - Var0() : VarConverter(0) {} -}; - - +// VarType models the types of values used on the wire protocol by +// both encoders and decoders. Each type is identified by a unique id, +// and a name, and provides a size in bytes for the values, a printf-like +// formatter string, and a flag telling if the value corresponds to a +// pointer. class VarType { public: VarType() : - m_id(0), m_name("default_constructed"), m_converter(NULL), m_printFomrat("0x%x"), m_isPointer(false) - { - } - - VarType(size_t id, const std::string & name, const VarConverter * converter, const std::string & printFormat , const bool isPointer) : - m_id(id), m_name(name), m_converter(const_cast<VarConverter *>(converter)), m_printFomrat(printFormat), m_isPointer(isPointer) - { - } + m_id(0), + m_name("default_constructed"), + m_byteSize(0), + m_printFormat("0x%x"), + m_isPointer(false) {} + + VarType(size_t id, + const std::string& name, + size_t byteSize, + const std::string& printFormat, + bool isPointer) : + m_id(id), + m_name(name), + m_byteSize(byteSize), + m_printFormat(printFormat), + m_isPointer(isPointer) {} + + ~VarType() {} - ~VarType() - { - } - const std::string & name() const { return m_name; } - const std::string & printFormat() const { return m_printFomrat; } - size_t bytes() const { return m_converter->bytes(); } - bool isPointer() const { return m_isPointer; } size_t id() const { return m_id; } + const std::string& name() const { return m_name; } + size_t bytes() const { return m_byteSize; } + const std::string& printFormat() const { return m_printFormat; } + bool isPointer() const { return m_isPointer; } + private: size_t m_id; std::string m_name; - VarConverter * m_converter; - std::string m_printFomrat; + size_t m_byteSize; + std::string m_printFormat; bool m_isPointer; }; |