1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00
llvm-mirror/test/TableGen/subst.td
Nicolai Haehnle 9a21ccd3ad TableGen: Streamline the semantics of NAME
Summary:
The new rules are straightforward. The main rules to keep in mind
are:

1. NAME is an implicit template argument of class and multiclass,
   and will be substituted by the name of the instantiating def/defm.

2. The name of a def/defm in a multiclass must contain a reference
   to NAME. If such a reference is not present, it is automatically
   prepended.

And for some additional subtleties, consider these:

3. defm with no name generates a unique name but has no special
   behavior otherwise.

4. def with no name generates an anonymous record, whose name is
   unique but undefined. In particular, the name won't contain a
   reference to NAME.

Keeping rules 1&2 in mind should allow a predictable behavior of
name resolution that is simple to follow.

The old "rules" were rather surprising: sometimes (but not always),
NAME would correspond to the name of the toplevel defm. They were
also plain bonkers when you pushed them to their limits, as the old
version of the TableGen test case shows.

Having NAME correspond to the name of the toplevel defm introduces
"spooky action at a distance" and breaks composability:
refactoring the upper layers of a hierarchy of nested multiclass
instantiations can cause unexpected breakage by changing the value
of NAME at a lower level of the hierarchy. The new rules don't
suffer from this problem.

Some existing .td files have to be adjusted because they ended up
depending on the details of the old implementation.

Change-Id: I694095231565b30f563e6fd0417b41ee01a12589

Reviewers: tra, simon_tatham, craig.topper, MartinO, arsenm, javed.absar

Subscribers: wdng, llvm-commits

Differential Revision: https://reviews.llvm.org/D47430

llvm-svn: 333900
2018-06-04 14:26:05 +00:00

68 lines
2.2 KiB
TableGen

// RUN: llvm-tblgen %s | FileCheck %s
// XFAIL: vg_leak
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>;
// CHECK: ------------- Classes -----------------
// CHECK-NEXT: class AName<string AName:name = ?, Honorific AName:honorific = ?> {
// CHECK-NEXT: string name = !subst("FIRST", "John", !subst("LAST", "Smith", AName:name));
// CHECK-NEXT: Honorific honorific = !subst(TVAR, Mr, AName:honorific);
// CHECK-NEXT: }
// CHECK-NEXT: class Honorific<string Honorific:t = ?> {
// CHECK-NEXT: string honorific = Honorific:t;
// CHECK-NEXT: }
// CHECK-NEXT: class Name<string Name:n = ?, Honorific Name:t = ?> {
// CHECK-NEXT: string name = Name:n;
// CHECK-NEXT: Honorific honorific = Name:t;
// CHECK-NEXT: }
// CHECK-NEXT: ------------- Defs -----------------
// CHECK-NEXT: def JaneSmith {
// CHECK-NEXT: string name = "Jane Smith";
// CHECK-NEXT: Honorific honorific = Ms;
// CHECK-NEXT: }
// CHECK-NEXT: def JimmyJohnson {
// CHECK-NEXT: string name = "Jimmy Johnson";
// CHECK-NEXT: Honorific honorific = Mr;
// CHECK-NEXT: }
// CHECK-NEXT: def JohnSmith {
// CHECK-NEXT: string name = "John Smith";
// CHECK-NEXT: Honorific honorific = Mr;
// CHECK-NEXT: }
// CHECK-NEXT: def JohnSmithJones {
// CHECK-NEXT: string name = "John Smith-Jones";
// CHECK-NEXT: Honorific honorific = Mr;
// CHECK-NEXT: }
// CHECK-NEXT: def Mr
// CHECK-NEXT: string honorific = "Mr.";
// CHECK-NEXT: }
// CHECK-NEXT: def Mrs {
// CHECK-NEXT: string honorific = "Mrs.";
// CHECK-NEXT: }
// CHECK-NEXT: def Ms {
// CHECK-NEXT: string honorific = "Ms.";
// CHECK-NEXT: }
// CHECK-NEXT: def TVAR {
// CHECK-NEXT: string honorific = "Bogus";
// CHECK-NEXT: }