inline structures and unions for api

This commit is contained in:
Sean 2020-03-03 16:32:46 -07:00
parent c8b5738fb6
commit 2dbbc8866e
No known key found for this signature in database
GPG Key ID: B111C910D99B42B8
2 changed files with 28 additions and 7 deletions

View File

@ -210,6 +210,7 @@ void API::search(std::string keyword, uint32_t org) {
});
if (it != s.first.end()) {
dumpSymbol(s.second, org);
printf("\n");
}
}
}
@ -226,7 +227,14 @@ void API::dumpRef(std::shared_ptr<symbol::Ref> ref) {
}
}
void API::dumpSymbol(std::shared_ptr<symbol::Symbol> sym, uint32_t org) {
static void indent(int depth) {
for (int i = 0; i < depth; i++) {
printf(" ");
}
}
void API::dumpSymbol(std::shared_ptr<symbol::Symbol> sym, uint32_t org, int depth) {
indent(depth);
printf("%s: ", sym->name.c_str());
switch (sym->kind) {
case symbol::Kind::isIntrinsic:
@ -250,7 +258,6 @@ void API::dumpSymbol(std::shared_ptr<symbol::Symbol> sym, uint32_t org) {
printf("int32");
break;
}
printf("\n");
break;
case symbol::Kind::isEnum:
{
@ -259,24 +266,30 @@ void API::dumpSymbol(std::shared_ptr<symbol::Symbol> sym, uint32_t org) {
for (auto entry : e->entries) {
printf(" %s = $%x,\n", entry.first.c_str(), entry.second);
}
printf("}\n");
printf("}");
}
break;
case symbol::Kind::isAlias:
case symbol::Kind::isRef:
dumpRef(std::static_pointer_cast<symbol::Ref>(sym));
printf("\n");
break;
case symbol::Kind::isStruct:
{
auto s = std::static_pointer_cast<symbol::Struct>(sym);
printf("struct { // $%x bytes\n", sym->size);
for (auto &f : s->fields) {
indent(depth);
printf(" %s: ", f.key.c_str());
switch (f.value->kind) {
case symbol::Kind::isRef:
dumpRef(std::static_pointer_cast<symbol::Ref>(f.value));
break;
case symbol::Kind::isStruct:
dumpSymbol(f.value, org, depth + 1);
break;
case symbol::Kind::isUnion:
dumpSymbol(f.value, org, depth + 1);
break;
default:
printf("%s", f.value->name.c_str());
break;
@ -289,7 +302,8 @@ void API::dumpSymbol(std::shared_ptr<symbol::Symbol> sym, uint32_t org) {
}
org += f.value->size;
}
printf("}\n");
indent(depth);
printf("}");
}
break;
case symbol::Kind::isUnion:
@ -302,6 +316,12 @@ void API::dumpSymbol(std::shared_ptr<symbol::Symbol> sym, uint32_t org) {
case symbol::Kind::isRef:
dumpRef(std::static_pointer_cast<symbol::Ref>(f.value));
break;
case symbol::Kind::isUnion:
dumpSymbol(f.value, org, depth + 1);
break;
case symbol::Kind::isStruct:
dumpSymbol(f.value, org, depth + 1);
break;
default:
printf("%s", f.value->name.c_str());
break;
@ -313,7 +333,8 @@ void API::dumpSymbol(std::shared_ptr<symbol::Symbol> sym, uint32_t org) {
printf("%04x\n", org);
}
}
printf("}\n");
indent(depth);
printf("}");
}
break;
case symbol::Kind::isFunction:

View File

@ -74,7 +74,7 @@ class API {
API(unsigned char *dat, unsigned int len);
std::map<std::string, std::shared_ptr<symbol::Symbol>> symbols;
void search(std::string keyword, uint32_t org);
void dumpSymbol(std::shared_ptr<symbol::Symbol> symbol, uint32_t org);
void dumpSymbol(std::shared_ptr<symbol::Symbol> symbol, uint32_t org, int depth = 0);
void dumpRef(std::shared_ptr<symbol::Ref> ref);
private: