Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
llvm-epi-0.8
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Roger Ferrer
llvm-epi-0.8
Commits
55927236
Commit
55927236
authored
21 years ago
by
Chris Lattner
Browse files
Options
Downloads
Patches
Plain Diff
Add information about the piece I forgot to write: parameterized tablegen classes
llvm-svn: 11147
parent
1215e32e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
llvm/docs/TableGenFundamentals.html
+86
-2
86 additions, 2 deletions
llvm/docs/TableGenFundamentals.html
with
86 additions
and
2 deletions
llvm/docs/TableGenFundamentals.html
+
86
−
2
View file @
55927236
...
...
@@ -406,6 +406,13 @@ derive from the <tt>C</tt> class. Because of this, they both get the <tt>V</tt>
bit value. The
<tt>
Y
</tt>
definition also gets the Greeting member as well.
</p>
<p>
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.
</p>
</div>
<!----------------------------------------------------------------------------->
...
...
@@ -456,7 +463,84 @@ because the <tt>D</tt> class overrode its value.
</div>
<div
class=
"doc_text"
>
and default values...
<p>
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:
</p>
<p><pre>
<b>
class
</b>
FPFormat
<
<b>
bits
</b>
<
3
>
val
>
{
<b>
bits
</b>
<
3
>
Value = val;
}
<b>
def
</b>
NotFP : FPFormat
<
0
>
;
<b>
def
</b>
ZeroArgFP : FPFormat
<
1
>
;
<b>
def
</b>
OneArgFP : FPFormat
<
2
>
;
<b>
def
</b>
OneArgFPRW : FPFormat
<
3
>
;
<b>
def
</b>
TwoArgFP : FPFormat
<
4
>
;
<b>
def
</b>
SpecialFP : FPFormat
<
5
>
;
</pre></p>
<p>
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.
</p>
<p>
The more esoteric forms of
<a
href=
"#values"
>
TableGen expressions
</a>
are
useful in conjunction with template arguments. As an example:
</p>
<p><pre>
<b>
class
</b>
ModRefVal
<
<b>
bits
</b>
<
2
>
val
>
{
<b>
bits
</b>
<
2
>
Value = val;
}
<b>
def
</b>
None : ModRefVal
<
0
>
;
<b>
def
</b>
Mod : ModRefVal
<
1
>
;
<b>
def
</b>
Ref : ModRefVal
<
2
>
;
<b>
def
</b>
ModRef : ModRefVal
<
3
>
;
<b>
class
</b>
Value
<
ModRefVal MR
>
{
<i>
// decode some information into a more convenient format, while providing
// a nice interface to the user of the "Value" class.
</i>
<b>
bit
</b>
isMod = MR.Value{0};
<b>
bit
</b>
isRef = MR.Value{1};
<i>
// other stuff...
</i>
}
<i>
// Example uses
</i>
<b>
def
</b>
bork : Value
<
Mod
>
;
<b>
def
</b>
zork : Value
<
Ref
>
;
<b>
def
</b>
hork : Value
<
ModRef
>
;
</pre></p>
<p>
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
<tt>
tblgen
</tt>
on the example prints the following definitions:
</p>
<p><pre>
<b>
def
</b>
bork {
<i>
// Value
</i>
bit isMod = 1;
bit isRef = 0;
}
<b>
def
</b>
hork {
<i>
// Value
</i>
bit isMod = 1;
bit isRef = 1;
}
<b>
def
</b>
zork {
<i>
// Value
</i>
bit isMod = 0;
bit isRef = 1;
}
</pre></p>
<p>
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.
</p>
</div>
...
...
@@ -479,7 +563,7 @@ specified as a double quoted string immediately after the '<tt>include</tt>'
keyword. Example:
<p><pre>
<b>
include
</b>
"foo.td"
<b>
include
</b>
"foo.td"
</pre></p>
</div>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment