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

View File

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