From: Chris Lattner Date: Fri, 6 Feb 2004 06:37:00 +0000 (+0000) Subject: Add information about the piece I forgot to write: parameterized tablegen classes X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=23f54fa655dfc6eb9521aa99cb8ccf706483a39b;p=oota-llvm.git Add information about the piece I forgot to write: parameterized tablegen classes git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11147 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/TableGenFundamentals.html b/docs/TableGenFundamentals.html index c57cda26ebe..50349347dff 100644 --- a/docs/TableGenFundamentals.html +++ b/docs/TableGenFundamentals.html @@ -406,6 +406,13 @@ derive from the C class. Because of this, they both get the V bit value. The Y definition also gets the Greeting member as well.

+

+In general, classes are useful for collecting together the commonality between a +group of records, and isolating it in a single places. Also, classes permit the +specification of default values for their subclasses, allowing the subclasses to +override them as they wish. +

+ @@ -456,7 +463,84 @@ because the D class overrode its value.
-and default values... +

+TableGen permits the definition of parameterized classes as well as normal +concrete classes. Parameterized TableGen classes specify a list of variable +bindings (which may optionally have defaults) that are bound when used. Here is +a simple example:

+ +

+class FPFormat<bits<3> val> {
+  bits<3> Value = val;
+}
+def NotFP      : FPFormat<0>;
+def ZeroArgFP  : FPFormat<1>;
+def OneArgFP   : FPFormat<2>;
+def OneArgFPRW : FPFormat<3>;
+def TwoArgFP   : FPFormat<4>;
+def SpecialFP  : FPFormat<5>;
+

+ +

+In this case, template arguments are used as a space efficient way to specify a +list of "enumeration values", each with a "Value" field set to the specified +integer.

+ +

The more esoteric forms of TableGen expressions are +useful in conjunction with template arguments. As an example:

+ +

+class ModRefVal<bits<2> val> {
+  bits<2> Value = val;
+}
+
+def None   : ModRefVal<0>;
+def Mod    : ModRefVal<1>;
+def Ref    : ModRefVal<2>;
+def ModRef : ModRefVal<3>;
+
+class Value<ModRefVal MR> {
+  // decode some information into a more convenient format, while providing
+  // a nice interface to the user of the "Value" class.
+  bit isMod = MR.Value{0};
+  bit isRef = MR.Value{1};
+
+  // other stuff...
+}
+
+// Example uses
+def bork : Value<Mod>;
+def zork : Value<Ref>;
+def hork : Value<ModRef>;
+

+ +

+This is obviously a contrived example, but it shows how template arguments can +be used to decouple the interface provided to the user of the class from the +actual internal data representation expected by the class. In this case, +running tblgen on the example prints the following definitions:

+ +

+def bork {      // Value
+  bit isMod = 1;
+  bit isRef = 0;
+}
+def hork {      // Value
+  bit isMod = 1;
+  bit isRef = 1;
+}
+def zork {      // Value
+  bit isMod = 0;
+  bit isRef = 1;
+}
+

+ +

+This shows that TableGen was able to dig into the argument and extract a piece +of information that was requested by the designer of the "Value" class. For +more realistic examples, please see existing users of TableGen, such as the X86 +backend.

+
@@ -479,7 +563,7 @@ specified as a double quoted string immediately after the 'include' keyword. Example:

-  include "foo.td"
+include "foo.td"