Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some issues #1

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion llvm/utils/TableGen/DecoderEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2064,8 +2064,18 @@ static void setPrinterParameters(CodeGenTarget &Target, PrinterLanguage PL,
} else {
PredicateNamespace = Target.getName().str();
GPrefix = "if (";
GPostfix = " == MCDisassembler::Fail)";
L = "";

switch (PL) {
default:
PrintFatalNote("DecoderEmitter does not support the given output language.");
case llvm::PRINTER_LANG_CPP:
GPostfix = " == MCDisassembler::Fail)";
break;
case llvm::PRINTER_LANG_CAPSTONE_C:
GPostfix = " == MCDisassembler_Fail)";
break;
}
}

ROK = "S";
Expand Down
33 changes: 25 additions & 8 deletions llvm/utils/TableGen/PrinterCapstone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
//===----------------------------------------------------------------------===//

#include "Printer.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/CodeGen/ValueTypes.h"
#include "llvm/MC/MCInst.h"
#include "llvm/Support/FileSystem.h"
Expand Down Expand Up @@ -165,7 +167,8 @@ void PrinterCapstone::regInfoEmitEnums(CodeGenTarget const &Target,
"Register enum value mismatch!");
OS << " NUM_TARGET_REGS // " << Registers.size() + 1 << "\n";
OS << "};\n";
CSRegEnum << "\tARM_REG_ENDING, // " << Registers.size() + 1 << "\n";
CSRegEnum << "\t" << TargetName << "_REG_ENDING, // " << Registers.size() + 1 << "\n";

writeFile(TargetName + "GenCSRegEnum.inc", CSRegEnumStr);

const auto &RegisterClasses = Bank.getRegClasses();
Expand Down Expand Up @@ -2309,11 +2312,22 @@ std::string getImplicitDefs(StringRef const &TargetName,
return Flags;
}

static inline std::string
getNormalMnemonic(std::unique_ptr<MatchableInfo> const &MI, const bool upper = true) {
auto Mn = MI->Mnemonic.str();
std::replace(Mn.begin(), Mn.end(), '.', '_');
if (upper) {
std::transform(Mn.begin(), Mn.end(), Mn.begin(),
::toupper);
}
return Mn;
}

std::string getReqFeatures(StringRef const &TargetName,
std::unique_ptr<MatchableInfo> const &MI, bool UseMI,
CodeGenInstruction const *CGI) {
std::string Flags = "{ ";
std::string Mn = MI->Mnemonic.upper();
std::string Mn = getNormalMnemonic(MI);
// The debug if
if (CGI->isBranch && !CGI->isCall) {
Flags += TargetName.str() + "_GRP_JUMP, ";
Expand Down Expand Up @@ -2354,7 +2368,7 @@ void printInsnMapEntry(StringRef const &TargetName,
InsnMap.indent(2) << getLLVMInstEnumName(TargetName, CGI) << " /* " << InsnNum
<< " */";
InsnMap << ", " << TargetName << "_INS_"
<< (UseMI ? MI->Mnemonic.upper() : "INVALID") << ",\n";
<< (UseMI ? getNormalMnemonic(MI) : "INVALID") << ",\n";
InsnMap.indent(2) << "#ifndef CAPSTONE_DIET\n";
if (UseMI) {
InsnMap.indent(4) << getImplicitUses(TargetName, CGI) << ", ";
Expand Down Expand Up @@ -2536,7 +2550,7 @@ void printInsnOpMapEntry(CodeGenTarget const &Target,
// Write the C struct of the Instruction operands.
InsnOpMap << "{ /* " + LLVMEnum + " (" << InsnNum
<< ") - " + TargetName + "_INS_" +
(UseMI ? MI->Mnemonic.upper() : "INVALID") + " - " +
(UseMI ? getNormalMnemonic(MI) : "INVALID") + " - " +
CGI->AsmString + " */\n";
InsnOpMap << " 0 \n";
InsnOpMap << "},\n";
Expand Down Expand Up @@ -2601,7 +2615,7 @@ void printInsnOpMapEntry(CodeGenTarget const &Target,
// Write the C struct of the Instruction operands.
InsnOpMap << "{ /* " + LLVMEnum + " (" << InsnNum
<< ") - " + TargetName + "_INS_" +
(UseMI ? MI->Mnemonic.upper() : "INVALID") + " - " +
(UseMI ? getNormalMnemonic(MI) : "INVALID") + " - " +
CGI->AsmString + " */\n";
InsnOpMap << "{\n";
for (OpData const &OD : InsOps) {
Expand All @@ -2617,13 +2631,16 @@ void printInsnNameMapEnumEntry(StringRef const &TargetName,
std::unique_ptr<MatchableInfo> const &MI,
raw_string_ostream &InsnNameMap,
raw_string_ostream &InsnEnum) {
static std::set<StringRef> MnemonicsSeen;
StringRef Mnemonic = MI->Mnemonic;
static std::set<std::string> MnemonicsSeen;
auto Mnemonic = getNormalMnemonic(MI, false);
if (MnemonicsSeen.find(Mnemonic) != MnemonicsSeen.end())
return;
MnemonicsSeen.emplace(Mnemonic);

std::string EnumName = TargetName.str() + "_INS_" + Mnemonic.upper();
std::string Mn{mapped_iterator(Mnemonic.begin(), toUpper),
mapped_iterator(Mnemonic.end(), toUpper)};

std::string EnumName = TargetName.str() + "_INS_" + Mn;
InsnNameMap.indent(2) << "\"" + Mnemonic + "\", // " + EnumName + "\n";
InsnEnum.indent(2) << EnumName + ",\n";
}
Expand Down