summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDavid Greene <greened@obbligato.org>2009-05-14 21:54:42 +0000
committerDavid Greene <greened@obbligato.org>2009-05-14 21:54:42 +0000
commit4afc509b7ffe2c4ea234dfd7af5105feb21685d9 (patch)
treee095d38947400d6afe3a6885a236a45e8cc3955a /test
parent94555c28462aab05157b41d78505d5753bd97dad (diff)
downloadllvm-4afc509b7ffe2c4ea234dfd7af5105feb21685d9.tar.gz
llvm-4afc509b7ffe2c4ea234dfd7af5105feb21685d9.tar.bz2
llvm-4afc509b7ffe2c4ea234dfd7af5105feb21685d9.tar.xz
Implement a !subst operation simmilar to $(subst) in GNU make to do
def/var/string substitution on generic pattern templates. For example: def Type; def v4f32 : Type; def TYPE : Type; class GenType<Type t> { let type = !(subst TYPE, v4f32, t); } def TheType : GenType<TYPE>; git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71801 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/TableGen/subst.td29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/TableGen/subst.td b/test/TableGen/subst.td
new file mode 100644
index 0000000000..ce9f45d0a4
--- /dev/null
+++ b/test/TableGen/subst.td
@@ -0,0 +1,29 @@
+// RUN: tblgen %s | grep {Smith} | count 7
+// RUN: tblgen %s | grep {Johnson} | count 2
+// RUN: tblgen %s | grep {FIRST} | count 1
+// RUN: tblgen %s | grep {LAST} | count 1
+// RUN: tblgen %s | grep {TVAR} | count 2
+// RUN: tblgen %s | grep {Bogus} | count 1
+
+class Honorific<string t> {
+ string honorific = t;
+}
+
+def Mr : Honorific<"Mr.">;
+def Ms : Honorific<"Ms.">;
+def Mrs : Honorific<"Mrs.">;
+def TVAR : Honorific<"Bogus">;
+
+class Name<string n, Honorific t> {
+ string name = n;
+ Honorific honorific = t;
+}
+
+class AName<string name, Honorific honorific> :
+ Name<!subst("FIRST", "John", !subst("LAST", "Smith", name)),
+ !subst(TVAR, Mr, honorific)>;
+
+def JohnSmith : AName<"FIRST LAST", TVAR>;
+def JaneSmith : AName<"Jane LAST", Ms>;
+def JohnSmithJones : AName<"FIRST LAST-Jones", Mr>;
+def JimmyJohnson : AName<"Jimmy Johnson", Mr>;