From 7a57454d82625ff3325a378e5f0280128c4d1ee2 Mon Sep 17 00:00:00 2001 From: Mikhail Glushenkov Date: Fri, 20 Aug 2010 11:24:51 +0000 Subject: llvmc: Do not prefix option names with AutoGenerated. Since they now live in the namespace 'autogenerated'. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111620 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvmc/examples/mcc16/Hooks.cpp | 10 +++---- utils/TableGen/LLVMCConfigurationEmitter.cpp | 41 ++++++++++++++++++---------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/tools/llvmc/examples/mcc16/Hooks.cpp b/tools/llvmc/examples/mcc16/Hooks.cpp index dea97e3ae4..edb91e16aa 100644 --- a/tools/llvmc/examples/mcc16/Hooks.cpp +++ b/tools/llvmc/examples/mcc16/Hooks.cpp @@ -8,7 +8,7 @@ namespace llvmc { extern char *ProgramName; namespace autogenerated { - extern llvm::cl::opt AutoGeneratedParameter_p; + extern llvm::cl::opt Parameter_p; } } @@ -32,10 +32,10 @@ namespace hooks { std::string GetLowerCasePartDefine(void) { std::string Partname; - if (autogenerated::AutoGeneratedParameter_p.empty()) { + if (autogenerated::Parameter_p.empty()) { Partname = "16f1xxx"; } else { - Partname = autogenerated::AutoGeneratedParameter_p; + Partname = autogenerated::Parameter_p; } std::string LowerCase; @@ -49,10 +49,10 @@ GetLowerCasePartDefine(void) { std::string GetUpperCasePartDefine(void) { std::string Partname; - if (autogenerated::AutoGeneratedParameter_p.empty()) { + if (autogenerated::Parameter_p.empty()) { Partname = "16f1xxx"; } else { - Partname = autogenerated::AutoGeneratedParameter_p; + Partname = autogenerated::Parameter_p; } std::string UpperCase; diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp index 48c7cc375f..26e9fa4a9d 100644 --- a/utils/TableGen/LLVMCConfigurationEmitter.cpp +++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp @@ -49,7 +49,7 @@ const unsigned Indent4 = TabWidth*4; const char * const DefaultHelpString = "NO HELP MESSAGE PROVIDED"; // Name for the "sink" option. -const char * const SinkOptionName = "AutoGeneratedSinkOption"; +const char * const SinkOptionName = "SinkOption"; //===----------------------------------------------------------------------===// /// Helper functions @@ -261,7 +261,13 @@ struct OptionDescription { /// GenVariableName - Returns the variable name used in the /// generated C++ code. - std::string GenVariableName() const; + std::string GenVariableName() const + { return "autogenerated::" + GenOptionType() + EscapeVariableName(Name); } + + /// GenPlainVariableName - Returns the variable name without the namespace + /// prefix. + std::string GenPlainVariableName() const + { return GenOptionType() + EscapeVariableName(Name); } /// Merge - Merge two option descriptions. void Merge (const OptionDescription& other); @@ -315,6 +321,10 @@ struct OptionDescription { { return (OptionType::IsList(this->Type) && !OptionType::IsSwitchList(this->Type)); } +private: + + // GenOptionType - Helper function used by GenVariableName(). + std::string GenOptionType() const; }; void OptionDescription::CheckConsistency() const { @@ -428,22 +438,21 @@ const char* OptionDescription::GenTypeDeclaration() const { } } -std::string OptionDescription::GenVariableName() const { - const std::string& EscapedName = EscapeVariableName(Name); +std::string OptionDescription::GenOptionType() const { switch (Type) { case OptionType::Alias: - return "AutoGeneratedAlias_" + EscapedName; + return "Alias_"; case OptionType::PrefixList: case OptionType::ParameterList: - return "AutoGeneratedList_" + EscapedName; + return "List_"; case OptionType::Switch: - return "AutoGeneratedSwitch_" + EscapedName; + return "Switch_"; case OptionType::SwitchList: - return "AutoGeneratedSwitchList_" + EscapedName; + return "SwitchList_"; case OptionType::Prefix: case OptionType::Parameter: default: - return "AutoGeneratedParameter_" + EscapedName; + return "Parameter_"; } } @@ -2210,13 +2219,15 @@ void EmitGenerateActionMethod (const ToolDescription& D, O.indent(Indent2) << "}\n\n"; // Handle the Sink property. + std::string SinkOption("autogenerated::"); + SinkOption += SinkOptionName; if (D.isSink()) { - O.indent(Indent2) << "if (!" << SinkOptionName << ".empty()) {\n"; + O.indent(Indent2) << "if (!" << SinkOption << ".empty()) {\n"; O.indent(Indent3) << "for (cl::list::iterator B = " - << SinkOptionName << ".begin(), E = " << SinkOptionName + << SinkOption << ".begin(), E = " << SinkOption << ".end(); B != E; ++B)\n"; - O.indent(Indent4) << "vec.push_back(std::make_pair(" << SinkOptionName - << ".getPosition(B - " << SinkOptionName + O.indent(Indent4) << "vec.push_back(std::make_pair(" << SinkOption + << ".getPosition(B - " << SinkOption << ".begin()), *B));\n"; O.indent(Indent2) << "}\n"; } @@ -2365,7 +2376,7 @@ void EmitOptionDefinitions (const OptionDescriptions& descs, } O << val.GenTypeDeclaration() << ' ' - << val.GenVariableName(); + << val.GenPlainVariableName(); O << "(\"" << val.Name << "\"\n"; @@ -2427,7 +2438,7 @@ void EmitOptionDefinitions (const OptionDescriptions& descs, // Emit the sink option. if (HasSink) - O << "cl" << "::list " << SinkOptionName << "(cl::Sink);\n"; + O << "cl::list " << SinkOptionName << "(cl::Sink);\n"; O << '\n'; } -- cgit v1.2.3