[PATCH] D148197: [TableGen] Allow references to class template arguments in defvar

Wang Pengcheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 13 20:17:18 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfd5d0a88dde0: [TableGen] Allow references to class template arguments in defvar (authored by pcwang-thead).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148197/new/

https://reviews.llvm.org/D148197

Files:
  llvm/lib/TableGen/TGParser.cpp
  llvm/lib/TableGen/TGParser.h
  llvm/test/TableGen/defvar.td


Index: llvm/test/TableGen/defvar.td
===================================================================
--- llvm/test/TableGen/defvar.td
+++ llvm/test/TableGen/defvar.td
@@ -18,6 +18,18 @@
 defvar myvar = "another value";
 #endif
 
+// These variables should be overrided by template arguments.
+defvar a = 2333;
+defvar b = 2333;
+class VarScopeTest<int a, int b> {
+  defvar c = !add(a, b);
+  int value = !add(c, c);
+}
+
+// CHECK: def aaa_scope_test {
+// CHECK-NEXT: int value = 10;
+def aaa_scope_test: VarScopeTest<2, 3>;
+
 multiclass Test<int x> {
   // Refer to a global variable, while inside a local scope like a multiclass.
   def _with_global_string { string s = myvar; }
Index: llvm/lib/TableGen/TGParser.h
===================================================================
--- llvm/lib/TableGen/TGParser.h
+++ llvm/lib/TableGen/TGParser.h
@@ -231,7 +231,7 @@
   bool ParseDefm(MultiClass *CurMultiClass);
   bool ParseDef(MultiClass *CurMultiClass);
   bool ParseDefset();
-  bool ParseDefvar();
+  bool ParseDefvar(Record *CurRec = nullptr);
   bool ParseForeach(MultiClass *CurMultiClass);
   bool ParseIf(MultiClass *CurMultiClass);
   bool ParseIfBody(MultiClass *CurMultiClass, StringRef Kind);
Index: llvm/lib/TableGen/TGParser.cpp
===================================================================
--- llvm/lib/TableGen/TGParser.cpp
+++ llvm/lib/TableGen/TGParser.cpp
@@ -3023,7 +3023,7 @@
     return ParseAssert(nullptr, CurRec);
 
   if (Lex.getCode() == tgtok::Defvar)
-    return ParseDefvar();
+    return ParseDefvar(CurRec);
 
   if (Lex.getCode() != tgtok::Let) {
     if (!ParseDeclaration(CurRec, false))
@@ -3254,7 +3254,7 @@
 ///
 ///   Defvar ::= DEFVAR Id '=' Value ';'
 ///
-bool TGParser::ParseDefvar() {
+bool TGParser::ParseDefvar(Record *CurRec) {
   assert(Lex.getCode() == tgtok::Defvar);
   Lex.Lex(); // Eat the 'defvar' token
 
@@ -3273,7 +3273,7 @@
   if (!consume(tgtok::equal))
     return TokError("expected '='");
 
-  Init *Value = ParseValue(nullptr);
+  Init *Value = ParseValue(CurRec);
   if (!Value)
     return true;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148197.513425.patch
Type: text/x-patch
Size: 2082 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230414/3d2e53e5/attachment.bin>


More information about the llvm-commits mailing list