import-trace: alias-based (importer) registry
This change implements a generic registry in order to clean up import-trace's code - it's possible (and reasonable) to use the registry for pruners as well. Importer now extends AliasedRegisterable; all importers have been adapted to suit the interface/abstract methods. Each AliasedRegisterable should have at least one alias (the class' name is a sensible choice) but can have several. The first specified alias is the class' prime alias which can be used e.g. to list all registered objects. Change-Id: If6daa34edce35a3b0194e4ba67ed3b44b74a49b0
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
#include <string>
|
||||
#include "MemoryImporter.hpp"
|
||||
#include "FullTraceImporter.hpp"
|
||||
#include "util/AliasedRegistry.hpp"
|
||||
|
||||
#ifdef BUILD_LLVM_DISASSEMBLER
|
||||
#include "InstructionImporter.hpp"
|
||||
@ -57,6 +58,28 @@ int main(int argc, char *argv[]) {
|
||||
ElfReader *elf_file = 0;
|
||||
MemoryMap *memorymap = 0;
|
||||
|
||||
AliasedRegistry registry;
|
||||
Importer *importer;
|
||||
|
||||
MemoryImporter mem;
|
||||
registry.add(&mem);
|
||||
FullTraceImporter fti;
|
||||
registry.add(&fti);
|
||||
|
||||
#ifdef BUILD_LLVM_DISASSEMBLER
|
||||
RegisterImporter reg;
|
||||
registry.add(®);
|
||||
RandomJumpImporter rjump;
|
||||
registry.add(&rjump);
|
||||
AdvancedMemoryImporter adv;
|
||||
registry.add(&adv);
|
||||
ElfImporter elf;
|
||||
registry.add(&elf);
|
||||
InstructionImporter instr;
|
||||
registry.add(&instr);
|
||||
#endif
|
||||
std::string importers = registry.getPrimeAliasesCSV();
|
||||
|
||||
// Manually fill the command line option parser
|
||||
CommandLine &cmd = CommandLine::Inst();
|
||||
for (int i = 1; i < argc; ++i)
|
||||
@ -123,42 +146,24 @@ int main(int argc, char *argv[]) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
Importer *importer;
|
||||
|
||||
// get the desired importer from the commandline; default to MemoryImporter
|
||||
std::string imp("MemoryImporter");
|
||||
if (cmd[IMPORTER]) {
|
||||
std::string imp(cmd[IMPORTER].first()->arg);
|
||||
if (imp == "BasicImporter" || imp == "MemoryImporter" || imp == "memory" || imp == "mem") {
|
||||
imp = "MemoryImporter";
|
||||
importer = new MemoryImporter();
|
||||
} else if (imp == "FullTraceImporter") {
|
||||
importer = new FullTraceImporter();
|
||||
#ifdef BUILD_LLVM_DISASSEMBLER
|
||||
} else if (imp == "InstructionImporter" || imp == "code") {
|
||||
imp = "InstructionImporter";
|
||||
importer = new InstructionImporter();
|
||||
|
||||
} else if (imp == "RegisterImporter" || imp == "regs") {
|
||||
imp = "RegisterImporter";
|
||||
importer = new RegisterImporter();
|
||||
|
||||
} else if (imp == "RandomJumpImporter") {
|
||||
importer = new RandomJumpImporter();
|
||||
} else if (imp == "AdvancedMemoryImporter") {
|
||||
importer = new AdvancedMemoryImporter();
|
||||
} else if (imp == "ObjdumpImporter" || imp == "objdump" || imp == "ElfImporter") {
|
||||
importer = new ElfImporter();
|
||||
#endif
|
||||
} else {
|
||||
LOG << "Unknown import method: " << imp << endl;
|
||||
exit(-1);
|
||||
}
|
||||
LOG << "Using " << imp << endl;
|
||||
|
||||
} else {
|
||||
LOG << "Using MemoryImporter" << endl;
|
||||
importer = new MemoryImporter();
|
||||
imp = cmd[IMPORTER].first()->arg;
|
||||
}
|
||||
|
||||
// try and get the according importer object ; die on failure
|
||||
if ((importer = (Importer *)registry.get(imp)) == 0) {
|
||||
LOG << "Unknown import method: " << imp << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
std::string prime;
|
||||
if (registry.getPrimeAlias(importer, prime)) {
|
||||
imp = prime;
|
||||
}
|
||||
LOG << "Using " << imp << endl;
|
||||
|
||||
if (importer && !(importer->cb_commandline_init())) {
|
||||
std::cerr << "Cannot call importers command line initialization!" << std::endl;
|
||||
exit(-1);
|
||||
|
||||
Reference in New Issue
Block a user