From 3e5291ad63f037fccf5ebddd15f8e8156d6f3508 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Sat, 3 Jun 2023 14:54:09 -0500 Subject: [PATCH] Generate a single Enum value file for system operands. --- llvm/utils/TableGen/Printer.h | 4 +- llvm/utils/TableGen/PrinterCapstone.cpp | 56 ++++++++----------------- 2 files changed, 18 insertions(+), 42 deletions(-) diff --git a/llvm/utils/TableGen/Printer.h b/llvm/utils/TableGen/Printer.h index 4074859e5c88..1e0b969a1abd 100644 --- a/llvm/utils/TableGen/Printer.h +++ b/llvm/utils/TableGen/Printer.h @@ -30,9 +30,7 @@ typedef enum { ST_NONE, ST_DECL_OS, ST_IMPL_OS, - ST_ENUM_SYSREG_OS, - ST_ENUM_SYSIMM_OS, - ST_ENUM_SYSALIAS_OS, + ST_ENUM_SYSOPS_OS, } StreamType; namespace llvm { diff --git a/llvm/utils/TableGen/PrinterCapstone.cpp b/llvm/utils/TableGen/PrinterCapstone.cpp index 42c54de19dce..8687f75ea73c 100644 --- a/llvm/utils/TableGen/PrinterCapstone.cpp +++ b/llvm/utils/TableGen/PrinterCapstone.cpp @@ -3155,20 +3155,10 @@ void PrinterCapstone::searchableTablesWriteFiles() const { raw_string_ostream &Impl = searchableTablesGetOS(ST_IMPL_OS); writeFile(Filename, Header.str() + Decl.str() + Impl.str()); - raw_string_ostream &SysRegEnum = searchableTablesGetOS(ST_ENUM_SYSREG_OS); - raw_string_ostream &SysImmEnum = searchableTablesGetOS(ST_ENUM_SYSIMM_OS); - raw_string_ostream &SysAliasEnum = searchableTablesGetOS(ST_ENUM_SYSALIAS_OS); - if (!SysRegEnum.str().empty()) { - Filename = TargetName + "GenCSSystemRegisterEnum.inc"; - writeFile(Filename, Header.str() + SysRegEnum.str()); - } - if (!SysImmEnum.str().empty()) { - Filename = TargetName + "GenCSSystemImmediateEnum.inc"; - writeFile(Filename, Header.str() + SysImmEnum.str()); - } - if (!SysAliasEnum.str().empty()) { - Filename = TargetName + "GenCSSystemAliasEnum.inc"; - writeFile(Filename, Header.str() + SysAliasEnum.str()); + raw_string_ostream &SysOpsEnum = searchableTablesGetOS(ST_ENUM_SYSOPS_OS); + if (!SysOpsEnum.str().empty()) { + Filename = TargetName + "GenCSSystemOperandsEnum.inc"; + writeFile(Filename, Header.str() + SysOpsEnum.str()); } } @@ -3179,19 +3169,13 @@ raw_string_ostream &PrinterCapstone::searchableTablesGetOS(StreamType G) const { static std::string SysRegDecl; static raw_string_ostream *SysRegDeclOS; static std::string SysRegEnum; - static raw_string_ostream *SysRegEnumOS; - static std::string SysImmEnum; - static raw_string_ostream *SysImmEnumOS; - static std::string SysAliasEnum; - static raw_string_ostream *SysAliasEnumOS; + static raw_string_ostream *SysOpsEnumOS; static std::string SysRegImpl; static raw_string_ostream *SysRegImplOS; if (!Init) { SysRegDeclOS = new raw_string_ostream(SysRegDecl); SysRegImplOS = new raw_string_ostream(SysRegImpl); - SysRegEnumOS = new raw_string_ostream(SysRegEnum); - SysImmEnumOS = new raw_string_ostream(SysImmEnum); - SysAliasEnumOS = new raw_string_ostream(SysAliasEnum); + SysOpsEnumOS = new raw_string_ostream(SysRegEnum); Init = true; } @@ -3202,12 +3186,8 @@ raw_string_ostream &PrinterCapstone::searchableTablesGetOS(StreamType G) const { return *SysRegDeclOS; case ST_IMPL_OS: return *SysRegImplOS; - case ST_ENUM_SYSREG_OS: - return *SysRegEnumOS; - case ST_ENUM_SYSIMM_OS: - return *SysImmEnumOS; - case ST_ENUM_SYSALIAS_OS: - return *SysAliasEnumOS; + case ST_ENUM_SYSOPS_OS: + return *SysOpsEnumOS; } } @@ -3458,6 +3438,10 @@ void PrinterCapstone::searchableTablesEmitMapI( raw_string_ostream &OutS = searchableTablesGetOS(ST_IMPL_OS); OutS << "static const " << getTableNamespacePrefix(Table, TargetName) << Table.CppTypeName << " " << Table.Name << "[] = {\n"; + + raw_string_ostream &EnumOS = searchableTablesGetOS(ST_ENUM_SYSOPS_OS); + EnumOS << "#ifdef GET_ENUM_VALUES_" << Table.CppTypeName << "\n"; + EnumOS << "#undef GET_ENUM_VALUES_" << Table.CppTypeName << "\n"; } void PrinterCapstone::searchableTablesEmitMapII() const { @@ -3566,17 +3550,8 @@ void PrinterCapstone::searchableTablesEmitMapIII(const GenericTable &Table, return; EnumNamesSeen.emplace(EnumName); - if (OpGroup == "SYSREG") { - raw_string_ostream &EnumOS = searchableTablesGetOS(ST_ENUM_SYSREG_OS); - EnumOS << "\t" + EnumName + " = " << format("0x%x", EnumVal) << ",\n"; - } else if (OpGroup == "SYSIMM") { - raw_string_ostream &EnumOS = searchableTablesGetOS(ST_ENUM_SYSIMM_OS); - EnumOS << "\t" + EnumName + " = " << format("0x%x", EnumVal) << ",\n"; - } else if (OpGroup == "SYSALIAS") { - raw_string_ostream &EnumOS = searchableTablesGetOS(ST_ENUM_SYSALIAS_OS); - EnumOS << "\t" + EnumName + " = " << format("0x%x", EnumVal) << ",\n"; - } else - llvm_unreachable("Unknown OpGroup"); + raw_string_ostream &EnumOS = searchableTablesGetOS(ST_ENUM_SYSOPS_OS); + EnumOS << "\t" + EnumName + " = " << format("0x%x", EnumVal) << ",\n"; } else { OutS << Regex("{ *}").sub("{0}", Repr); } @@ -3594,6 +3569,9 @@ void PrinterCapstone::searchableTablesEmitMapV() { if (DoNotEmit) return; OutS << " };\n\n"; + + raw_string_ostream &EnumOS = searchableTablesGetOS(ST_ENUM_SYSOPS_OS); + EnumOS << "#endif\n\n"; } } // end namespace llvm