2014-12-29 05:12:47 +00:00
|
|
|
#ifndef __debug_template_h__
|
|
|
|
#define __debug_template_h__
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace Debug {
|
|
|
|
|
|
|
|
|
2014-12-29 20:15:34 +00:00
|
|
|
enum {
|
|
|
|
|
|
|
|
// 0x8000 = pointer
|
|
|
|
// 0x1000 = unsigned
|
|
|
|
// 0x0f00 = size
|
|
|
|
// 0-255 - type
|
|
|
|
|
|
|
|
kSInt64 = 0x0800,
|
|
|
|
kUInt64 = 0x1800,
|
|
|
|
|
|
|
|
kSInt32 = 0x0400,
|
|
|
|
kUInt32 = 0x1400,
|
|
|
|
|
|
|
|
kSInt16 = 0x0200,
|
|
|
|
kUInt16 = 0x1200,
|
|
|
|
|
|
|
|
kSInt8 = 0x0100,
|
|
|
|
kUInt8 = 0x1100,
|
|
|
|
|
|
|
|
kStruct = 0x0000,
|
|
|
|
kStructPtr = 0x8000,
|
|
|
|
|
|
|
|
// ptrs are a special case where size = 0
|
|
|
|
//kVoid = 0x0001,
|
|
|
|
kVoidPtr = 0x8001,
|
|
|
|
|
|
|
|
// these exist for display purposes.
|
|
|
|
kCStringPtr = 0x8002,
|
|
|
|
kPStringPtr = 0x8003,
|
|
|
|
|
|
|
|
kOSType = 0x00404,
|
|
|
|
kBoolean = 0x0105,
|
|
|
|
kOSErr = 0x0206,
|
|
|
|
kHandle = 0x04007,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
inline unsigned MakePtr(unsigned type) { return type | 0x8000; }
|
|
|
|
inline unsigned MakeType(unsigned size, bool sign, bool ptr) {
|
|
|
|
unsigned rv = size << 8;
|
|
|
|
if (!sign) rv |= 0x0100;
|
|
|
|
if (ptr) rv |= 0x8000;
|
|
|
|
return rv;
|
|
|
|
}
|
2014-12-29 05:12:47 +00:00
|
|
|
|
|
|
|
enum {
|
2014-12-29 20:15:34 +00:00
|
|
|
kDisplayNative = 0,
|
|
|
|
kDisplayStringPtr, // p-string
|
|
|
|
kDisplayCStringPtr, // c-string
|
|
|
|
kDisplayOSType, // four-cc
|
|
|
|
kDisplayBoolean, // unsigned char, display true/false
|
|
|
|
kDisplayOSErr,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
struct Type {
|
|
|
|
enum {
|
|
|
|
kSimpleType,
|
|
|
|
kStructType,
|
|
|
|
kPointerType,
|
|
|
|
};
|
|
|
|
uint16_t tag;
|
|
|
|
uint16_t size;
|
2014-12-29 05:12:47 +00:00
|
|
|
};
|
|
|
|
|
2014-12-29 20:15:34 +00:00
|
|
|
// handles [signed/unsigned] type, type[], *type, and *type[]
|
|
|
|
struct SimpleType : public Type {
|
|
|
|
unsigned rank:16; // int == int[1]
|
|
|
|
unsigned display:14; //
|
|
|
|
|
|
|
|
unsigned sign:1;
|
|
|
|
unsigned pointer:1;
|
|
|
|
|
|
|
|
SimpleType() {
|
|
|
|
tag = kSimpleType;
|
|
|
|
size = 0;
|
|
|
|
rank = 0;
|
|
|
|
display = 0;
|
|
|
|
sign = 0;
|
|
|
|
pointer = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PointerType: public Type {
|
|
|
|
Type *type;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StructType : public Type {
|
|
|
|
unsigned total_size;
|
|
|
|
FieldEntry *firstField;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2014-12-29 05:12:47 +00:00
|
|
|
|
|
|
|
struct FieldEntry;
|
2014-12-29 20:15:34 +00:00
|
|
|
typedef FieldEntry *Template;
|
2014-12-29 05:12:47 +00:00
|
|
|
|
|
|
|
struct FieldEntry {
|
|
|
|
std::string *name;
|
|
|
|
unsigned type;
|
|
|
|
unsigned count;
|
2014-12-29 20:15:34 +00:00
|
|
|
Template tmpl;
|
2014-12-29 05:12:47 +00:00
|
|
|
FieldEntry *next;
|
2014-12-29 20:15:34 +00:00
|
|
|
unsigned struct_size; // only populated for head entry.
|
2014-12-29 05:12:47 +00:00
|
|
|
};
|
|
|
|
|
2014-12-29 20:15:34 +00:00
|
|
|
struct TemplateParseInfo {
|
|
|
|
std::unordered_map<std::string, Template> *templates;
|
|
|
|
std::unordered_map<std::string, unsigned> *types;
|
|
|
|
int LineNumber;
|
2014-12-29 05:12:47 +00:00
|
|
|
};
|
|
|
|
|
2014-12-29 20:15:34 +00:00
|
|
|
|
|
|
|
void CreateTypedef(const std::string *name, int type, TemplateParseInfo *);
|
|
|
|
void CreateTemplate(const std::string *name, FieldEntry *firstField, TemplateParseInfo *);
|
|
|
|
|
|
|
|
|
|
|
|
bool LoadTemplateFile(const std::string &filename, std::unordered_map<std::string, Template> &);
|
|
|
|
|
2014-12-29 05:12:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|