Instruction mapper generator v1)

This commit is contained in:
Phosphorus15 2021-06-07 02:16:46 +08:00 committed by phosphorus
parent dc9e1482d4
commit 7dda80b67c
4 changed files with 1906 additions and 9 deletions

File diff suppressed because it is too large Load Diff

View File

@ -44,6 +44,7 @@
#include <vector>
#include "Capstone/CapstoneGenInfo.h"
#include "Capstone/CapstoneGenMapper.h"
namespace llvm {
@ -55,4 +56,8 @@ void EmitCapstone(RecordKeeper &RK, raw_ostream &OS) {
.run(OS);
}
void EmitCapstoneMapper(RecordKeeper &RK, raw_ostream &OS) {
CapstoneGenMapper(RK).run(OS);
}
} // end namespace llvm

View File

@ -58,6 +58,7 @@ enum ActionType {
GenDirectivesEnumDecl,
GenDirectivesEnumImpl,
GenCapstone,
GenCapstoneMapper,
};
namespace llvm {
@ -141,7 +142,9 @@ cl::opt<ActionType> Action(
clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
clEnumValN(GenCapstone, "gen-capstone",
"Generate file for capstone engine")));
"Generate file for capstone engine"),
clEnumValN(GenCapstoneMapper, "gen-capstone-mapper",
"Generate instruction mapper for capstone")));
cl::OptionCategory PrintEnumsCat("Options for -print-enums");
cl::opt<std::string> Class("class", cl::desc("Print Enum list for this class"),
@ -151,12 +154,12 @@ cl::opt<std::string> Class("class", cl::desc("Print Enum list for this class"),
bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
switch (Action) {
case PrintRecords:
OS << Records; // No argument, dump all contents
OS << Records; // No argument, dump all contents
break;
case PrintDetailedRecords:
EmitDetailedRecords(Records, OS);
break;
case NullBackend: // No backend at all.
case NullBackend: // No backend at all.
break;
case DumpJSON:
EmitJSON(Records, OS);
@ -218,20 +221,18 @@ bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
case GenOptRST:
EmitOptRST(Records, OS);
break;
case PrintEnums:
{
case PrintEnums: {
for (Record *Rec : Records.getAllDerivedDefinitions(Class))
OS << Rec->getName() << ", ";
OS << "\n";
break;
}
case PrintSets:
{
case PrintSets: {
SetTheory Sets;
Sets.addFieldExpander("Set", "Elements");
for (Record *Rec : Records.getAllDerivedDefinitions("Set")) {
OS << Rec->getName() << " = [";
const std::vector<Record*> *Elts = Sets.expand(Rec);
const std::vector<Record *> *Elts = Sets.expand(Rec);
assert(Elts && "Couldn't expand Set instance");
for (Record *Elt : *Elts)
OS << ' ' << Elt->getName();
@ -278,11 +279,14 @@ bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
case GenCapstone:
EmitCapstone(Records, OS);
break;
case GenCapstoneMapper:
EmitCapstoneMapper(Records, OS);
break;
}
return false;
}
}
} // namespace
int main(int argc, char **argv) {
InitLLVM X(argc, argv);

View File

@ -94,6 +94,7 @@ void EmitAutomata(RecordKeeper &RK, raw_ostream &OS);
void EmitDirectivesDecl(RecordKeeper &RK, raw_ostream &OS);
void EmitDirectivesImpl(RecordKeeper &RK, raw_ostream &OS);
void EmitCapstone(RecordKeeper &RK, raw_ostream &OS);
void EmitCapstoneMapper(RecordKeeper &RK, raw_ostream &OS);
} // End llvm namespace