summaryrefslogtreecommitdiff
path: root/utils/TableGen/LLVMCConfigurationEmitter.cpp
diff options
context:
space:
mode:
authorMikhail Glushenkov <foldr@codedgers.com>2008-05-30 06:13:02 +0000
committerMikhail Glushenkov <foldr@codedgers.com>2008-05-30 06:13:02 +0000
commit5c7578de087fb984473277316edd19908d0e8190 (patch)
tree42868b9dd13532077ed3f6c254cb05b5cd9d6cda /utils/TableGen/LLVMCConfigurationEmitter.cpp
parent08bd2e74dc542ab4e7484f1d61e22f6fd96c48ed (diff)
downloadllvm-5c7578de087fb984473277316edd19908d0e8190.tar.gz
llvm-5c7578de087fb984473277316edd19908d0e8190.tar.bz2
llvm-5c7578de087fb984473277316edd19908d0e8190.tar.xz
Make it possible to change the output file suffix based on command-line options.
For instance, the following command: llvmc2 -E hello.c now generates a file with the correct suffix (hello.i). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51733 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/LLVMCConfigurationEmitter.cpp')
-rw-r--r--utils/TableGen/LLVMCConfigurationEmitter.cpp35
1 files changed, 32 insertions, 3 deletions
diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp
index d160412cfa..2dfd17e7b4 100644
--- a/utils/TableGen/LLVMCConfigurationEmitter.cpp
+++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp
@@ -250,7 +250,7 @@ namespace ToolOptionDescriptionFlags {
Forward = 0x2, UnpackValues = 0x4};
}
namespace OptionPropertyType {
- enum OptionPropertyType { AppendCmd };
+ enum OptionPropertyType { AppendCmd, OutputSuffix };
}
typedef std::pair<OptionPropertyType::OptionPropertyType, std::string>
@@ -397,6 +397,8 @@ public:
optionPropertyHandlers_["append_cmd"] = &CollectProperties::onAppendCmd;
optionPropertyHandlers_["forward"] = &CollectProperties::onForward;
optionPropertyHandlers_["help"] = &CollectProperties::onHelp;
+ optionPropertyHandlers_["output_suffix"] =
+ &CollectProperties::onOutputSuffixOptionProp;
optionPropertyHandlers_["required"] = &CollectProperties::onRequired;
optionPropertyHandlers_["stop_compilation"] =
&CollectProperties::onStopCompilation;
@@ -487,11 +489,23 @@ private:
void onAppendCmd (const DagInit* d, GlobalOptionDescription& o) {
checkNumberOfArguments(d, 1);
- std::string const& cmd = InitPtrToString(d->getArg(0));
+ const std::string& cmd = InitPtrToString(d->getArg(0));
toolProps_.OptDescs[o.Name].AddProperty(OptionPropertyType::AppendCmd, cmd);
}
+ void onOutputSuffixOptionProp (const DagInit* d, GlobalOptionDescription& o) {
+ checkNumberOfArguments(d, 1);
+ const std::string& suf = InitPtrToString(d->getArg(0));
+
+ if (toolProps_.OptDescs[o.Name].Type != OptionType::Switch)
+ throw "Option " + o.Name
+ + " can't have 'output_suffix' property since it isn't a switch!";
+
+ toolProps_.OptDescs[o.Name].AddProperty
+ (OptionPropertyType::OutputSuffix, suf);
+ }
+
void onForward (const DagInit* d, GlobalOptionDescription& o) {
checkNumberOfArguments(d, 0);
toolProps_.OptDescs[o.Name].setForward();
@@ -1021,7 +1035,22 @@ void EmitInOutLanguageMethods (const ToolProperties& P, std::ostream& O) {
/// given Tool class.
void EmitOutputSuffixMethod (const ToolProperties& P, std::ostream& O) {
O << Indent1 << "const char* OutputSuffix() const {\n"
- << Indent2 << "return \"" << P.OutputSuffix << "\";\n"
+ << Indent2 << "const char* ret = \"" << P.OutputSuffix << "\";\n";
+
+ for (ToolOptionDescriptions::const_iterator B = P.OptDescs.begin(),
+ E = P.OptDescs.end(); B != E; ++B) {
+ const ToolOptionDescription& OptDesc = B->second;
+ for (OptionPropertyList::const_iterator B = OptDesc.Props.begin(),
+ E = OptDesc.Props.end(); B != E; ++B) {
+ const OptionProperty& OptProp = *B;
+ if (OptProp.first == OptionPropertyType::OutputSuffix) {
+ O << Indent2 << "if (" << OptDesc.GenVariableName() << ")\n"
+ << Indent3 << "ret = \"" << OptProp.second << "\";\n";
+ }
+ }
+ }
+
+ O << Indent2 << "return ret;\n"
<< Indent1 << "}\n\n";
}