[llvm-commits] [llvm] r51733 - in /llvm/trunk: tools/llvmc2/Tools.td utils/TableGen/LLVMCConfigurationEmitter.cpp
Mikhail Glushenkov
foldr at codedgers.com
Thu May 29 23:13:02 PDT 2008
Author: foldr
Date: Fri May 30 01:13:02 2008
New Revision: 51733
URL: http://llvm.org/viewvc/llvm-project?rev=51733&view=rev
Log:
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).
Modified:
llvm/trunk/tools/llvmc2/Tools.td
llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
Modified: llvm/trunk/tools/llvmc2/Tools.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/Tools.td?rev=51733&r1=51732&r2=51733&view=diff
==============================================================================
--- llvm/trunk/tools/llvmc2/Tools.td (original)
+++ llvm/trunk/tools/llvmc2/Tools.td Fri May 30 01:13:02 2008
@@ -30,10 +30,7 @@
"llvm-g++ -E -x c $INFILE -o $OUTFILE -emit-llvm",
(default),
"llvm-g++ -c -x c $INFILE -o $OUTFILE -emit-llvm")),
- // TOFIX: Preprocessed files currently have suffix ".bc".
- (switch_option "E", (stop_compilation),
- // Make this possible:
- // (output_suffix "i"),
+ (switch_option "E", (stop_compilation),(output_suffix "i"),
(help "Stop after the preprocessing stage, do not run the compiler")),
(sink)
]>;
@@ -47,7 +44,7 @@
"llvm-g++ -E -x c++ $INFILE -o $OUTFILE -emit-llvm",
(default),
"llvm-g++ -c -x c++ $INFILE -o $OUTFILE -emit-llvm")),
- (switch_option "E", (stop_compilation)),
+ (switch_option "E", (stop_compilation), (output_suffix "i")),
(sink)
]>;
Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp?rev=51733&r1=51732&r2=51733&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Fri May 30 01:13:02 2008
@@ -250,7 +250,7 @@
Forward = 0x2, UnpackValues = 0x4};
}
namespace OptionPropertyType {
- enum OptionPropertyType { AppendCmd };
+ enum OptionPropertyType { AppendCmd, OutputSuffix };
}
typedef std::pair<OptionPropertyType::OptionPropertyType, std::string>
@@ -397,6 +397,8 @@
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 @@
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 @@
/// 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";
}
More information about the llvm-commits
mailing list