-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathftdbmaps.cpp
76 lines (64 loc) · 2.84 KB
/
ftdbmaps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
extern "C" {
#include "pyftdb.h"
#include "utils.h"
}
#include <set>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
/*
Some precomputed maps
refmap: type_id -> type entry
hrefmap: type_hash -> type entry
frefmap: func_id -> func_entry
fhrefmap: func_hash -> func_entry
fnrefmap: func_name -> [func_entry, func_entry...]
grefmap: global_id -> global_entry
ghrefmap: global_hash -> global_entry
gnrefmap: global_name -> global_entry
fdrefmap: fdecl_id -> func_decl_entry
fdhrefmap: fdeclhash -> func_decl_entry
fdnrefmap: fdeclname -> [func_decl_entry, func_decl_entry...]
*/
int ftdb_maps(struct ftdb* ftdb, int show_stats) {
for (unsigned long i=0; i<ftdb->types_count; ++i) {
struct ftdb_type_entry* type_entry = &ftdb->types[i];
ulong_entryMap_insert(&ftdb->refmap,type_entry->id,type_entry);
stringRef_entryMap_insert(&ftdb->hrefmap, type_entry->hash, type_entry);
}
printf("refmap keys: %zu\n",ulong_entryMap_count(&ftdb->refmap));
printf("hrefmap keys: %zu\n",stringRef_entryMap_count(&ftdb->hrefmap));
std::map<std::string,std::vector<struct ftdb_func_entry*>> fnrefmap;
for (unsigned long i=0; i<ftdb->funcs_count; ++i) {
struct ftdb_func_entry* func_entry = &ftdb->funcs[i];
ulong_entryMap_insert(&ftdb->frefmap,func_entry->id,func_entry);
stringRef_entryMap_insert(&ftdb->fhrefmap, func_entry->hash, func_entry);
fnrefmap[func_entry->name].push_back(func_entry);
}
printf("frefmap keys: %zu\n",ulong_entryMap_count(&ftdb->frefmap));
printf("fhrefmap keys: %zu\n",stringRef_entryMap_count(&ftdb->fhrefmap));
BUILD_STRINGREF_ENTRYLIST_MAP(ftdb,fnrefmap,fnrefmap);
std::map<std::string,std::vector<struct ftdb_global_entry*>> gnrefmap;
for (unsigned long i=0; i<ftdb->globals_count; ++i) {
struct ftdb_global_entry* global_entry = &ftdb->globals[i];
ulong_entryMap_insert(&ftdb->grefmap,global_entry->id,global_entry);
stringRef_entryMap_insert(&ftdb->ghrefmap, global_entry->hash, global_entry);
gnrefmap[global_entry->name].push_back(global_entry);
}
printf("grefmap keys: %zu\n",ulong_entryMap_count(&ftdb->grefmap));
printf("ghrefmap keys: %zu\n",stringRef_entryMap_count(&ftdb->ghrefmap));
BUILD_STRINGREF_ENTRYLIST_MAP(ftdb,gnrefmap,gnrefmap);
std::map<std::string,std::vector<struct ftdb_funcdecl_entry*>> fdnrefmap;
for (unsigned long i=0; i<ftdb->funcdecls_count; ++i) {
struct ftdb_funcdecl_entry* funcdecl_entry = &ftdb->funcdecls[i];
ulong_entryMap_insert(&ftdb->fdrefmap,funcdecl_entry->id,funcdecl_entry);
stringRef_entryMap_insert(&ftdb->fdhrefmap, funcdecl_entry->declhash, funcdecl_entry);
fdnrefmap[funcdecl_entry->name].push_back(funcdecl_entry);
}
printf("fdrefmap keys: %zu\n",ulong_entryMap_count(&ftdb->fdrefmap));
printf("fdhrefmap keys: %zu\n",stringRef_entryMap_count(&ftdb->fdhrefmap));
BUILD_STRINGREF_ENTRYLIST_MAP(ftdb,fdnrefmap,fdnrefmap);
return 1;
}