Page MenuHomePhabricator

[TableGen] Allow lists to be concatenated through '#'
ClosedPublic

Authored by javedabsar on Mar 4 2019, 1:40 AM.

Details

Summary

Currently one can concatenate strings using hash(#), but not lists, although that would be a natural thing to do.
This was highlighted by Nicolai at a FOSDEM talk as well.
This patch allows one to write something like:

def : A<!listconcat([1,2], [3,4])>;

simply as :

def : A<[1,2] # [3,4]>;

Diff Detail

Repository
rL LLVM

Event Timeline

javedabsar created this revision.Mar 4 2019, 1:40 AM
hfinkel added inline comments.Mar 4 2019, 10:15 AM
lib/TableGen/TGParser.cpp
2124 ↗(On Diff #189126)

Does this change any current behavior? (i.e., if you try this now, does it cast each list to a string, or does it give an error, or something else?

nhaehnle accepted this revision.Mar 5 2019, 2:20 AM

Awesome :)
LGTM

lib/TableGen/TGParser.cpp
2124 ↗(On Diff #189126)
$ llvm-tblgen
def A {
  list<int> x = [4] # [5];
}
^D
<stdin>:2:17: error: Value 'x' of type 'list<int>' is incompatible with initializer '!strconcat(!cast<string>([4]), !cast<string>([5]))' of type 'string'
  list<int> x = [4] # [5];

The error isn't exactly user-friendly. If you try to make x a string it doesn't work either:

$ llvm-tblgen
def A {
  string x = [4] # [5];
}
^D
<stdin>:2:15: error: Type mismatch for list, expected list type, got string
  string x = [4] # [5];
              ^
<stdin>:2:15: error: expected ';' after declaration
  string x = [4] # [5];

Those errors seem even more confusing and I'm not sure where they're from, but the underlying point is that you cannot cast a list to a string:

$ llvm-tblgen
def A {
  string x = !cast<string>([4]);
}
^D
<stdin>:1:1: error: Initializer of 'x' in 'A' could not be fully resolved: !cast<string>([4])
def A {
^
This revision is now accepted and ready to land.Mar 5 2019, 2:20 AM
hfinkel accepted this revision.Mar 5 2019, 8:54 AM

Awesome :)
LGTM

Thanks, LGTM too.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2019, 9:15 AM