summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/llvmc2/Common.td5
-rw-r--r--tools/llvmc2/examples/Clang.td63
-rw-r--r--utils/TableGen/LLVMCConfigurationEmitter.cpp35
3 files changed, 86 insertions, 17 deletions
diff --git a/tools/llvmc2/Common.td b/tools/llvmc2/Common.td
index 78bca37ecd..046e19e444 100644
--- a/tools/llvmc2/Common.td
+++ b/tools/llvmc2/Common.td
@@ -69,6 +69,11 @@ def or;
def inc_weight;
def dec_weight;
+// Option list - used to specify aliases and sometimes help strings.
+class OptionList<list<dag> l> {
+ list<dag> options = l;
+}
+
// Map from suffixes to language names
class LangToSuffixes<string str, list<string> lst> {
diff --git a/tools/llvmc2/examples/Clang.td b/tools/llvmc2/examples/Clang.td
index f57c7266a3..07d59e8fbd 100644
--- a/tools/llvmc2/examples/Clang.td
+++ b/tools/llvmc2/examples/Clang.td
@@ -4,22 +4,55 @@
include "Common.td"
-def clang : Tool<
-[(in_language ["c", "c++", "objective-c"]),
+
+// TOFIX: Add an explicit option list for aliases and things like this.
+def Options : OptionList<[
+(switch_option "E",
+ (help "Stop after the preprocessing stage, do not run the compiler"))
+]>;
+
+class clang_base<string language, dag cmdline> : Tool<
+[(in_language language),
(out_language "llvm-bitcode"),
(output_suffix "bc"),
- (cmd_line (case (switch_on "E"), "clang -E $INFILE",
- (in_language "c"),
- "clang -emit-llvm-bc -x c $INFILE -o $OUTFILE",
- (in_language "c++"),
- "clang -emit-llvm-bc -x c++ $INFILE -o $OUTFILE",
- (in_language "objective-c"),
- "clang -emit-llvm-bc -x objective-c$INFILE -o $OUTFILE")),
- (switch_option "E", (stop_compilation), (output_suffix "i"),
- (help "Stop after the preprocessing stage, do not run the compiler")),
+ (cmd_line cmdline),
+ (switch_option "E", (stop_compilation), (output_suffix "i")),
(sink)
]>;
+def clang_c : clang_base<"c",
+(case
+(switch_on "E"),
+ (case
+ (not_empty "o"),
+ "clang -E -x c $INFILE -o $OUTFILE",
+ (default),
+ "clang -E -x c $INFILE"),
+(default),
+ "clang -emit-llvm-bc -x c $INFILE -o $OUTFILE")>;
+
+def clang_cpp : clang_base<"c++",
+(case
+(switch_on "E"),
+ (case
+ (not_empty "o"),
+ "clang -E -x c++ $INFILE -o $OUTFILE",
+ (default),
+ "clang -E -x c++ $INFILE"),
+(default),
+ "clang -emit-llvm-bc -x c++ $INFILE -o $OUTFILE")>;
+
+def clang_objective_c : clang_base<"objective-c",
+(case
+(switch_on "E"),
+ (case
+ (not_empty "o"),
+ "clang -E -x objective-c $INFILE -o $OUTFILE",
+ (default),
+ "clang -E -x objective-c $INFILE"),
+(default),
+ "clang -emit-llvm-bc -x objective-c $INFILE -o $OUTFILE")>;
+
// Default linker
def llvm_ld : Tool<
[(in_language "llvm-bitcode"),
@@ -43,7 +76,11 @@ def LanguageMap : LanguageMap<
// Compilation graph
def CompilationGraph : CompilationGraph<[
- Edge<root, clang>,
- Edge<clang, llvm_ld>
+ Edge<root, clang_c>,
+ Edge<root, clang_cpp>,
+ Edge<root, clang_objective_c>,
+ Edge<clang_c, llvm_ld>,
+ Edge<clang_cpp, llvm_ld>,
+ Edge<clang_objective_c, llvm_ld>
]>;
diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp
index 44a6ff4a40..77daf627a2 100644
--- a/utils/TableGen/LLVMCConfigurationEmitter.cpp
+++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp
@@ -647,9 +647,9 @@ CollectProperties::optionPropertyHandlers_;
bool CollectProperties::staticMembersInitialized_ = false;
-/// CollectToolProperties - Gather information from the parsed
-/// TableGen data (basically a wrapper for the CollectProperties
-/// function object).
+/// CollectToolProperties - Gather information about tool properties
+/// from the parsed TableGen data (basically a wrapper for the
+/// CollectProperties function object).
void CollectToolProperties (RecordVector::const_iterator B,
RecordVector::const_iterator E,
ToolPropertiesList& TPList,
@@ -657,7 +657,8 @@ void CollectToolProperties (RecordVector::const_iterator B,
{
// Iterate over a properties list of every Tool definition
for (;B!=E;++B) {
- RecordVector::value_type T = *B;
+ Record* T = *B;
+ // Throws an exception if the value does not exist.
ListInit* PropList = T->getValueAsListInit("properties");
IntrusiveRefCntPtr<ToolProperties>
@@ -669,6 +670,28 @@ void CollectToolProperties (RecordVector::const_iterator B,
}
}
+/// CollectToolPropertiesFromOptionList - Gather information about
+/// *global* option properties from the OptionList.
+// TOFIX - This is kinda hacky, since it allows to use arbitrary tool
+// properties in the OptionList. CollectProperties function object
+// should be split into two parts that collect tool and option
+// properties, respectively.
+void CollectPropertiesFromOptionList (RecordVector::const_iterator B,
+ RecordVector::const_iterator E,
+ GlobalOptionDescriptions& OptDescs)
+{
+ // Iterate over a properties list of every Tool definition
+ ToolProperties ToolProps("dummy");
+ for (;B!=E;++B) {
+ RecordVector::value_type T = *B;
+ // Throws an exception if the value does not exist.
+ ListInit* PropList = T->getValueAsListInit("options");
+
+ std::for_each(PropList->begin(), PropList->end(),
+ CollectProperties(ToolProps, OptDescs));
+ }
+}
+
/// EmitCaseTest1Arg - Helper function used by
/// EmitCaseConstructHandler.
bool EmitCaseTest1Arg(const std::string& TestName,
@@ -1571,6 +1594,10 @@ void LLVMCConfigurationEmitter::run (std::ostream &O) {
GlobalOptionDescriptions opt_descs;
CollectToolProperties(Tools.begin(), Tools.end(), tool_props, opt_descs);
+ RecordVector OptionLists = Records.getAllDerivedDefinitions("OptionList");
+ CollectPropertiesFromOptionList(OptionLists.begin(), OptionLists.end(),
+ opt_descs);
+
// Emit global option registration code.
EmitOptionDescriptions(opt_descs, O);