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"),
@ -218,15 +221,13 @@ 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")) {
@ -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