mirror of
https://github.com/mrkite/regs.git
synced 2025-02-18 02:30:33 +00:00
inline structures and unions for api
This commit is contained in:
parent
c8b5738fb6
commit
2dbbc8866e
33
src/api.cc
33
src/api.cc
@ -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:
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user