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:
Michael Lenz
2014-02-25 09:36:42 +01:00
parent 77b9b08a89
commit af92a751d9
13 changed files with 207 additions and 34 deletions

View File

@ -55,6 +55,10 @@ protected:
virtual bool handle_mem_event(fail::simtime_t curtime, instruction_count_t instr,
Trace_Event &ev);
virtual bool trace_end_reached();
void getAliases(std::deque<std::string> *aliases) {
aliases->push_back("AdvancedMemoryImporter");
}
};
#endif

View File

@ -71,6 +71,12 @@ public:
virtual bool create_database();
virtual bool copy_to_database(fail::ProtoIStream &ps);
virtual bool clear_database();
void getAliases(std::deque<std::string> *aliases) {
aliases->push_back("ElfImporter");
aliases->push_back("ObjdumpImporter");
aliases->push_back("objdump");
}
};
#endif

View File

@ -20,6 +20,11 @@ protected:
virtual bool add_trace_event(margin_info_t &begin, margin_info_t &end,
Trace_Event &event, bool is_fake = false);
virtual bool trace_end_reached();
public:
void getAliases(std::deque<std::string> *aliases) {
aliases->push_back("FullTraceImporter");
}
};
#endif

View File

@ -11,8 +11,9 @@
#include "util/Database.hpp"
#include "util/MemoryMap.hpp"
#include "comm/TracePlugin.pb.h"
#include "util/AliasedRegisterable.hpp"
class Importer {
class Importer : public fail::AliasedRegisterable {
public:
typedef unsigned instruction_count_t; //!< not big enough for some benchmarks
struct margin_info_t { instruction_count_t dyninstr; fail::guest_address_t ip; fail::simtime_t time; };

View File

@ -17,6 +17,11 @@ protected:
/* ignore on purpose */
return true;
}
void getAliases(std::deque<std::string> *aliases) {
aliases->push_back("InstructionImporter");
aliases->push_back("code");
}
};
#endif

View File

@ -11,6 +11,13 @@ protected:
Trace_Event &ev);
virtual bool handle_mem_event(fail::simtime_t curtime, instruction_count_t instr,
Trace_Event &ev);
public:
void getAliases(std::deque<std::string> *aliases) {
aliases->push_back("MemoryImporter");
aliases->push_back("BasicImporter");
aliases->push_back("memory");
aliases->push_back("mem");
}
};
#endif

View File

@ -35,6 +35,10 @@ protected:
virtual void open_unused_ec_intervals() {
/* empty, Memory Map has a different meaning in this importer */
}
void getAliases(std::deque<std::string> *aliases) {
aliases->push_back("RandomJumpImporter");
}
};
#endif

View File

@ -44,6 +44,12 @@ protected:
virtual void open_unused_ec_intervals() {
/* empty, Memory Map has a different meaning in this importer */
}
void getAliases(std::deque<std::string> *aliases) {
aliases->push_back("RegisterImporter");
aliases->push_back("regs");
}
};
#endif

View File

@ -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(&reg);
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);