From cebb4ee93a0064e4a2cb1fd1da7455b01e5655cb Mon Sep 17 00:00:00 2001 From: David Greene Date: Wed, 22 Feb 2012 16:09:41 +0000 Subject: Add Foreach Loop Add some data structures to represent for loops. These will be referenced during object processing to do any needed iteration and instantiation. Add foreach keyword support to the lexer. Add a mode to indicate that we're parsing a foreach loop. This allows the value parser to early-out when processing the foreach value list. Add a routine to parse foreach iteration declarations. This is separate from ParseDeclaration because the type of the named value (the iterator) doesn't match the type of the initializer value (the value list). It also needs to add two values to the foreach record: the iterator and the value list. Add parsing support for foreach. Add the code to process foreach loops and create defs based on iterator values. Allow foreach loops to be matched at the top level. When parsing an IDValue check if it is a foreach loop iterator for one of the active loops. If so, return a VarInit for it. Add Emacs keyword support for foreach. Add VIM keyword support for foreach. Add tests to check foreach operation. Add TableGen documentation for foreach. Support foreach with multiple objects. Support non-braced foreach body with one object. Do not require types for the foreach declaration. Assume the iterator type from the iteration list element type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151164 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/TableGenFundamentals.html | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'docs/TableGenFundamentals.html') diff --git a/docs/TableGenFundamentals.html b/docs/TableGenFundamentals.html index 6db1827b3b..45baf19845 100644 --- a/docs/TableGenFundamentals.html +++ b/docs/TableGenFundamentals.html @@ -37,6 +37,7 @@
  1. File inclusion
  2. 'let' expressions
  3. +
  4. 'foreach' blocks
  • TableGen backends @@ -401,6 +402,14 @@ which case the user must specify it explicitly.
    list[4-7,17,2-3]
    A slice of the 'list' list, including elements 4,5,6,7,17,2, and 3 from it. Elements may be included multiple times.
    +
    foreach <var> = <list> in { <body> }
    +
    foreach <var> = <list> in <def>
    +
    Replicate <body> or <def>, replacing instances of + <var> with each value in <list>. <var> is scoped at the + level of the foreach loop and must not conflict with any other object + introduced in <body> or <def>. Currently only defs are + expanded within <body>. +
    (DEF a, b)
    a dag value. The first element is required to be a record definition, the remaining elements in the list may be arbitrary other values, including nested @@ -880,6 +889,39 @@ several levels of multiclass instanciations. This also avoids the need of using + +

    + Looping +

    + +
    +

    TableGen supports the 'foreach' block, which textually replicates +the loop body, substituting iterator values for iterator references in the +body. Example:

    + +
    +
    +foreach i = [0, 1, 2, 3] in {
    +  def R#i : Register<...>;
    +  def F#i : Register<...>;
    +}
    +
    +
    + +

    This will create objects R0, R1, R2 and +R3. foreach blocks may be nested. If there is only +one item in the body the braces may be elided:

    + +
    +
    +foreach i = [0, 1, 2, 3] in
    +  def R#i : Register<...>;
    +
    +
    +
    + +
    + -- cgit v1.2.3