llvm-project/llvm/lib/TableGen
wangpc 634484885c [TableGen] Add new operator !exists
We can cast a string to a record via !cast, but we have no mechanism
to check if it is valid and TableGen will raise an error if failed to
cast. Besides, we have no semantic null in TableGen (we have `?` but
different backends handle uninitialized value differently), so operator
like `dyn_cast<>` is hard to implement.

In this patch, we add a new operator `!exists<T>(s)` to check whether
a record with type `T` and name `s` exists. Self-references are allowed
just like `!cast`.

By doing these, we can write code like:
```
class dyn_cast_to_record<string name> {
  R value = !if(!exists<R>(name), !cast<R>(name), default_value);
}
defvar v = dyn_cast_to_record<"R0">.value; // R0 or default_value.
```

Reviewed By: tra, nhaehnle

Differential Revision: https://reviews.llvm.org/D127948
2022-06-23 11:11:47 +08:00
..
CMakeLists.txt [TableGen] Add a library-based entry point for parsing td files 2022-03-03 16:14:03 -08:00
DetailedRecordsBackend.cpp Cleanup include dependencies for LLVMTableGen 2022-01-28 11:50:49 +01:00
Error.cpp [TableGen] Remove the use of global Record state 2022-05-11 11:55:33 -07:00
JSONBackend.cpp Cleanup include dependencies for LLVMTableGen 2022-01-28 11:50:49 +01:00
Main.cpp Cleanup include dependencies for LLVMTableGen 2022-01-28 11:50:49 +01:00
Parser.cpp [TableGen] Refactor TableGenParseFile to no longer use a callback 2022-05-11 11:55:33 -07:00
Record.cpp [TableGen] Add new operator !exists 2022-06-23 11:11:47 +08:00
SetTheory.cpp Cleanup include dependencies for LLVMTableGen 2022-01-28 11:50:49 +01:00
StringMatcher.cpp [llvm] Use range-based for loops (NFC) 2021-12-11 11:29:12 -08:00
TGLexer.cpp [TableGen] Add new operator !exists 2022-06-23 11:11:47 +08:00
TGLexer.h [TableGen] Add new operator !exists 2022-06-23 11:11:47 +08:00
TGParser.cpp [TableGen] Add new operator !exists 2022-06-23 11:11:47 +08:00
TGParser.h [llvm] Use = default (NFC) 2022-02-06 22:18:35 -08:00
TableGenBackend.cpp
TableGenBackendSkeleton.cpp Cleanup includes for LLVMTableGenGlobalISel 2022-01-28 11:50:50 +01:00