forked from OSchip/llvm-project
634484885c
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 |
||
---|---|---|
.. | ||
BackEnds.rst | ||
BackGuide.rst | ||
ProgRef.rst | ||
index.rst |