diff options
| author | Nicolai Haehnle <nhaehnle@gmail.com> | 2018-02-22 15:27:03 +0000 |
|---|---|---|
| committer | Nicolai Haehnle <nhaehnle@gmail.com> | 2018-02-22 15:27:03 +0000 |
| commit | 8fb962c04ea2fd0a91f2dcd70e141ffc2c83d2d4 (patch) | |
| tree | dfb559394eb3a7faff127126df06a4bed7b07aa7 /llvm | |
| parent | 81097ba6b578172a7ff68fb5e86c48fd60ff8a67 (diff) | |
| download | bcm5719-llvm-8fb962c04ea2fd0a91f2dcd70e141ffc2c83d2d4.tar.gz bcm5719-llvm-8fb962c04ea2fd0a91f2dcd70e141ffc2c83d2d4.zip | |
TableGen: Allow implicit casting between string and code
Summary:
Perhaps the distinction between the two should be removed entirely
in the long term, and the [{ ... }] syntax should just be a convenient
way of writing multi-line strings.
In the meantime, a lot of existing .td files are quite relaxed about
string vs. code, and this change allows switching on more consistent
type checks without breaking those.
Change-Id: If85e3e04469e41b58e2703b62ac0032d2711713c
Reviewers: arsenm, craig.topper, tra, MartinO
Subscribers: wdng, llvm-commits
Differential Revision: https://reviews.llvm.org/D43557
llvm-svn: 325799
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/TableGen/Record.h | 4 | ||||
| -rw-r--r-- | llvm/lib/TableGen/Record.cpp | 14 | ||||
| -rw-r--r-- | llvm/test/TableGen/code.td | 23 |
3 files changed, 41 insertions, 0 deletions
diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h index 12c902e46ee..0d55c032f22 100644 --- a/llvm/include/llvm/TableGen/Record.h +++ b/llvm/include/llvm/TableGen/Record.h @@ -141,6 +141,8 @@ public: static CodeRecTy *get() { return &Shared; } std::string getAsString() const override { return "code"; } + + bool typeIsConvertibleTo(const RecTy *RHS) const override; }; /// 'int' - Represent an integer value of no particular size @@ -176,6 +178,8 @@ public: static StringRecTy *get() { return &Shared; } std::string getAsString() const override; + + bool typeIsConvertibleTo(const RecTy *RHS) const override; }; /// 'list<Ty>' - Represent a list of values, all of which must be of diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp index 21689a4be27..9a9f43de167 100644 --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -97,10 +97,20 @@ bool IntRecTy::typeIsConvertibleTo(const RecTy *RHS) const { return kind==BitRecTyKind || kind==BitsRecTyKind || kind==IntRecTyKind; } +bool CodeRecTy::typeIsConvertibleTo(const RecTy *RHS) const { + RecTyKind Kind = RHS->getRecTyKind(); + return Kind == CodeRecTyKind || Kind == StringRecTyKind; +} + std::string StringRecTy::getAsString() const { return "string"; } +bool StringRecTy::typeIsConvertibleTo(const RecTy *RHS) const { + RecTyKind Kind = RHS->getRecTyKind(); + return Kind == StringRecTyKind || Kind == CodeRecTyKind; +} + std::string ListRecTy::getAsString() const { return "list<" + Ty->getAsString() + ">"; } @@ -433,6 +443,8 @@ StringInit *StringInit::get(StringRef V) { Init *StringInit::convertInitializerTo(RecTy *Ty) const { if (isa<StringRecTy>(Ty)) return const_cast<StringInit *>(this); + if (isa<CodeRecTy>(Ty)) + return CodeInit::get(getValue()); return nullptr; } @@ -440,6 +452,8 @@ Init *StringInit::convertInitializerTo(RecTy *Ty) const { Init *CodeInit::convertInitializerTo(RecTy *Ty) const { if (isa<CodeRecTy>(Ty)) return const_cast<CodeInit *>(this); + if (isa<StringRecTy>(Ty)) + return StringInit::get(getValue()); return nullptr; } diff --git a/llvm/test/TableGen/code.td b/llvm/test/TableGen/code.td new file mode 100644 index 00000000000..1f983e28240 --- /dev/null +++ b/llvm/test/TableGen/code.td @@ -0,0 +1,23 @@ +// RUN: llvm-tblgen %s | FileCheck %s +// XFAIL: vg_leak + +// CHECK: --- Defs --- + +// TODO: Both of these should result in CodeInits, i.e. print [{...}]. +// CHECK: def A0 { +// CHECK: code Code = "Simple"; +// CHECK: } + +// CHECK: def B0 { +// CHECK: code Code = "With paste 7"; +// CHECK: } + +class A<code c> { + code Code = c; +} + +def A0 : A<"Simple">; + +class B<int i> : A<"With paste " # i>; + +def B0 : B<7>; |

