Example for structure of a POET file
1: include utils.incl
2: <*The code template type for all loops supported by the POET optimization library *>
3: <code Loop pars=(i:ID,start:EXP, stop:EXP, step:EXP) >
4: for (@i@=@start@; @i@<@stop@; @i@+=@step@)
5: </code>
6: <xform ReverseList pars=(list) prepend=""> <<* a xform routine which reverses the input list
7: result = HEAD(list) :: prepend;
8: for (p_list = TAIL(list); p_list != ""; p_list = TAIL(p_list))
9: {
10: result = HEAD(p_list) :: result;
11: }
12: result
13: </xform>
14:<define OPT_STMT CODE.Loop />
15:<parameter inputFile message="input file name"/>
16:<parameter inputLang default="" message="file name for input language syntax" />
17:<parameter outputFile default="" message="file name for output" />
18:<trace inputCode/>
19:<input cond=(inputLang!="") from=(inputFile) syntax=(inputLang) to=inputCode/>
20:<eval backward = ReverseList[prepend="Reversed\n"](inputCode);
        succ = XFORM.AnalzeOrTransformCode(inputCode);
/>
21:<output cond=(succ) to=(outputFile) syntax=(inputLang) from=inputCode/>
Overview of POET Language
  • The Type System POET supports two types of atomic values: integers and strings. Additionally, the following compound types are supported within POET:
    • Lists.A POET list is a singly linked list of arbitrary elements and can be constructed by simply enumerating all the elements. For example, (a "<=" b) produces a list with three elements, a, "<=", and b.
    • A POET tuple is a finite number of statically-composed elements separated by commas. For example, ("i", 0, "m", 1) constructs a tuple with four elements, "i", 0, "m", and 1.
    • Associative Maps. POET maps are used to associate pairs of arbitrary values and are constructed by invoking the MAP operator, e.g., MAP{3=>"abc"} builds a map that associates 3 with "abc".
    • Code Templates. Each POET code template is a distinct user-defined data type and is constructed using the # operator. They are used to build pointer-based data structures such as arbitrarily shaped trees and DAGs (directed acyclic graphs) and are used to construct internal representations of the input code that POET scripts operate on.
    • Xform Handles. Each POET xform handle is a global function pointer and is constructed by following the name of a POET xform routine with an optional list of values to pre-configure invocations of the routine. Each xform handle can be invoked by following it with a tuple of input parameters and will return the result of evaluating the corresponding routine using the given parameters.


  • Components of A POET Script POET supports:
    • A POET comment can appear anywhere and is either enclosed inside a pair of <* and *> or from <<* until the end of the current line.
    • Three categories of global variables, macros, command-line parameters, and trace handles.
      Macro can be used to reconfigure behavior of the POET interpreter.
      Command-line parameters whose values can be redefined via command-line options and are used to extensively parameterize POET scripts.
      Trace handle can act as an integral component of a compound data structure to trace transformations to the data.
    • Three types of executable commands, input, eval, and output
      Input command is used to parse a file named by variable say 'inputFile' using syntax descriptions contained in a file named by say 'inputLang'. The parsing result is then converted into an internal representation and stored to variable 'inputCode'.
      The eval command specifies a sequence of expressions and statements to evaluate.
      The Output Command is used to write the transformed internal representation (i.e., inputCode) to an external file named by 'outputFile'.


  • Variables And Assignments
    • Local variables, whose lifetime and scopes span through the bodies of single code templates or xform routines.
    • Static variables, whose lifetime and scopes are restricted within individual POET files to avoid naming conflicts from other files.
    • Global variables, whose lifetime and scopes span throughout the entire execution of a POET transformation engine and across multiple files. There are three categories of global variables: macros, command-line parameters, and trace handles, each of which serves a special purpose and must be explicitly declared in the global scope before used.