[llvm-commits] [llvm] r61117 - in /llvm/trunk: include/llvm/CompilerDriver/Common.td tools/llvmc/doc/LLVMC-Reference.rst utils/TableGen/LLVMCConfigurationEmitter.cpp
Mikhail Glushenkov
foldr at codedgers.com
Tue Dec 16 18:47:03 PST 2008
Author: foldr
Date: Tue Dec 16 20:47:01 2008
New Revision: 61117
URL: http://llvm.org/viewvc/llvm-project?rev=61117&view=rev
Log:
Some enhancements for the 'case' expression.
Add (error) and (empty).
Modified:
llvm/trunk/include/llvm/CompilerDriver/Common.td
llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst
llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
Modified: llvm/trunk/include/llvm/CompilerDriver/Common.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CompilerDriver/Common.td?rev=61117&r1=61116&r2=61117&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CompilerDriver/Common.td (original)
+++ llvm/trunk/include/llvm/CompilerDriver/Common.td Tue Dec 16 20:47:01 2008
@@ -67,6 +67,7 @@
def forward_as;
def stop_compilation;
def unpack_values;
+def error;
// Increase/decrease the edge weight.
def inc_weight;
Modified: llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst?rev=61117&r1=61116&r2=61117&view=diff
==============================================================================
--- llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst (original)
+++ llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst Tue Dec 16 20:47:01 2008
@@ -387,6 +387,9 @@
user.
Example: ``(not_empty "o")``.
+ - ``empty`` - The opposite of ``not_empty``. Equivalent to ``(not (not_empty
+ X))``. Provided for convenience.
+
- ``default`` - Always evaluates to true. Should always be the last
test in the ``case`` expression.
@@ -487,7 +490,11 @@
- ``append_cmd`` - append a string to the tool invocation
command.
- Example: ``(case (switch_on "pthread"), (append_cmd "-lpthread"))``
+ Example: ``(case (switch_on "pthread"), (append_cmd
+ "-lpthread"))``
+
+ - ``error` - exit with error.
+ Example: ``(error "Mixing -c and -S is not allowed!")``.
- ``forward`` - forward an option unchanged.
Example: ``(forward "Wall")``.
Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp?rev=61117&r1=61116&r2=61117&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Tue Dec 16 20:47:01 2008
@@ -798,7 +798,7 @@
if (ActionName == "forward" || ActionName == "forward_as" ||
ActionName == "unpack_values" || ActionName == "switch_on" ||
ActionName == "parameter_equals" || ActionName == "element_in_list" ||
- ActionName == "not_empty") {
+ ActionName == "not_empty" || ActionName == "empty") {
checkNumberOfArguments(&Stmt, 1);
const std::string& Name = InitPtrToString(Stmt.getArg(0));
OptionNames_.insert(Name);
@@ -877,6 +877,7 @@
std::ostream& O) {
checkNumberOfArguments(&d, 1);
const std::string& OptName = InitPtrToString(d.getArg(0));
+
if (TestName == "switch_on") {
const OptionDescription& OptDesc = OptDescs.FindOption(OptName);
if (!OptionType::IsSwitch(OptDesc.Type))
@@ -893,9 +894,11 @@
// TODO: make this work with Edge::Weight (if possible).
O << "LangMap.GetLanguage(inFile) == \"" << OptName << '\"';
return true;
- } else if (TestName == "not_empty") {
+ } else if (TestName == "not_empty" || TestName == "empty") {
+ const char* Test = (TestName == "empty") ? "" : "!";
+
if (OptName == "o") {
- O << "!OutputFilename.empty()";
+ O << Test << "OutputFilename.empty()";
return true;
}
else {
@@ -903,7 +906,7 @@
if (OptionType::IsSwitch(OptDesc.Type))
throw OptName
+ ": incorrect option type - should be a list or parameter!";
- O << '!' << OptDesc.GenVariableName() << ".empty()";
+ O << Test << OptDesc.GenVariableName() << ".empty()";
return true;
}
}
@@ -1196,6 +1199,12 @@
const std::string& Cmd = InitPtrToString(Dag.getArg(0));
O << IndentLevel << "vec.push_back(\"" << Cmd << "\");\n";
}
+ else if (ActionName == "error") {
+ O << IndentLevel << "throw std::runtime_error(\"" <<
+ (Dag.getNumArgs() >= 1 ? InitPtrToString(Dag.getArg(0))
+ : "Unknown error!")
+ << "\");\n";
+ }
else if (ActionName == "forward") {
checkNumberOfArguments(&Dag, 1);
const std::string& Name = InitPtrToString(Dag.getArg(0));
@@ -1535,12 +1544,23 @@
const DagInit& d = InitPtrToDag(i);
const std::string& OpName = d.getOperator()->getAsString();
- if (OpName == "inc_weight")
+ if (OpName == "inc_weight") {
O << IndentLevel << "ret += ";
- else if (OpName == "dec_weight")
+ }
+ else if (OpName == "dec_weight") {
O << IndentLevel << "ret -= ";
+ }
+ else if (OpName == "error") {
+ O << IndentLevel << "throw std::runtime_error(\"" <<
+ (d.getNumArgs() >= 1 ? InitPtrToString(d.getArg(0))
+ : "Unknown error!")
+ << "\");\n";
+ return;
+ }
+
else
- throw "Unknown operator in edge properties list: " + OpName + '!';
+ throw "Unknown operator in edge properties list: " + OpName + '!' +
+ "Only 'inc_weight', 'dec_weight' and 'error' are allowed.";
if (d.getNumArgs() > 0)
O << InitPtrToInt(d.getArg(0)) << ";\n";
More information about the llvm-commits
mailing list