Class ExpressionList

java.lang.Object
com.aparapi.internal.instruction.ExpressionList

public class ExpressionList extends Object
Essentially a glorified linked list of Instructions plus some additional state to allow us to transform sequences. ExpressionLists do have the notion of a parent which allows us to clone an existing parent, allow transformations and then possibly commit or abort the transformations at will.
  • Field Details

  • Constructor Details

  • Method Details

    • doesNotContainContinueOrBreak

      public boolean doesNotContainContinueOrBreak(Instruction _start, Instruction _extent)
      Determine whether the sequence of instructions from _start to _extent is free of branches which extend beyond _extent. As a side effect, if we find a possible branch it is likely a break or continue so we mark the conditional as such.
      Parameters:
      _start -
      _extent -
      Returns:
    • doesNotContainCompositeOrBranch

      public boolean doesNotContainCompositeOrBranch(Instruction _start, Instruction _exclusiveEnd)
    • unwind

      public void unwind()
    • createList

      public Instruction createList(Instruction _newTail)
      [1] [2] [3] [4] Note that passing null here essentially deletes the existing expression list and returns the expression
      Parameters:
      _newTail -
      Returns:
    • add

      public Instruction add(Instruction _instruction)
      Add this instruction to the end of the list.
      Parameters:
      _instruction -
      Returns:
      The instruction we added
    • insertBetween

      public void insertBetween(Instruction _prev, Instruction _next, Instruction _newOne)
      Insert the given instruction (_newone) between the existing entries (_prev and _next).
      Parameters:
      _prev -
      _next -
      _newOne -
    • replaceInclusive

      public void replaceInclusive(Instruction _head, Instruction _tail, Instruction _newOne)
      Inclusive replace between _head and _tail with _newOne.
         |      | --> |       | ---> ... ---> |       | ---> |      |
         | prev |     | _head |               | _tail |      | next |
         |      | invalid input: '<'-- |       | invalid input: '<'--- ... invalid input: '<'----|       | invalid input: '<'--- |      |
      
      To
         |      | --> |         | ---> |      |
         | prev |     | _newOne |      | next |
         |      | invalid input: '<'-- |         | invalid input: '<'--- |      |
      
    • foldComposite

      public boolean foldComposite(Instruction _instruction) throws ClassParseException
      Fold headTail.tail into valid composites
      if(??){then}...
        ?? ?> [THEN] ...
            -------->
      
      if (??){THEN}else{ELSE}...
      
        ?? ?> [THEN] >> [ELSE] ...
            ------------>
                      -------->
      
      sun for (INIT,??,DELTA){BODY} ...
      
         [INIT] ?? ?> [BODY] [DELTA] invalid input: '<'invalid input: '<' ...
                    ------------------>
                 invalid input: '<'-------------------
      
      sun for (,??,DELTA){BODY} ...
      
          ?? ?> [BODY] [DELTA] invalid input: '<'invalid input: '<' ...
              ------------------>
           invalid input: '<'-------------------
      
      sun while (?){l} ...
      
         ?? ?> [BODY] invalid input: '<'invalid input: '<' ...
             ----------->
          invalid input: '<'------------
      
      eclipse for (INIT,??,DELTA){BODY} ...
         [INIT] >> [BODY] [DELTA] ?? ?invalid input: '<' ...
                 ---------------->
                   invalid input: '<'-----------------
      
      eclipse for (,??,DELTA){BODY} ...
         >> [BODY] [DELTA] ?? ?invalid input: '<' ...
          --------------->
            invalid input: '<'-----------------
      
      eclipse while (??){BODY} ...
         >> [BODY] ?? ?invalid input: '<' ...
          -------->
            invalid input: '<'----------
      
      eclipe if (?1) { while (?2) {BODY} } else {ELSE} ...
         ?1 ?> >> [BODY] ?2 ?invalid input: '<' >> [ELSE] ...
                --------->
                   invalid input: '<'---------
             --------------------->
                                -------->
      
      sun for (,?1,DELTA){ if (?2) { THEN break; } BODY} ...
      
          ?1 ?> ?2 ?> [THEN] >> [BODY] [DELTA] invalid input: '<'invalid input: '<' ...
                    ----------->
              ---------------------------------->
                              ------------------>
          invalid input: '<'------------------------------------
      
      sun for (,?1,DELTA){ if (?2) { THEN continue; } BODY} ...
      
          ?1 ?> ?2 ?> THEN >> [BODY] [DELTA] invalid input: '<'invalid input: '<' ...
                    --------->
                            -------->
              -------------------------------->
          invalid input: '<'----------------------------------
      
      Some exceptions based on sun javac optimizations
      
      if (?1){ if (?2){THEN} }else{ ELSE } ...
        One might expect
         ?1 ?> ?2 ?> [THEN] >> [ELSE] ...
             ----------------->
                   -------->!
                             ------------->
        However the conditional branch to the unconditional (!) is optimized away and instead the unconditional inverted and extended
      
         ?1 ?> ?2 ?> [THEN] >> [ELSE] ...
             ----------------->
                   --------*--------->
      
      sun if (?1) { while (?2) {l} } else {e} ...
        One might expect
         ?1 ?> ?2 ?> [BODY] invalid input: '<'invalid input: '<' >> [ELSE] ...
             ------------------->
                   ----------->!
                 invalid input: '<'----------
                                -------->
      
        However as above the conditional branch to the unconditional (!) can be optimized away and the conditional inverted and extended
         ?1 ?> ?2 ?> [BODY] invalid input: '<'invalid input: '<' >> [ELSE] ...
             -------------------->
                   -----------*--------->
                 invalid input: '<'-----------
      
        However we can also now remove the forward unconditional completely as it is unreachable
         ?1 ?> ?2 ?> [BODY] invalid input: '<'invalid input: '<' [ELSE] ...
             ----------------->
                   ------------------>
                 invalid input: '<'-----------
      
      sun while(?1){if (?2) {THEN} else {ELSE} } ...
        One might expect
         ?1 ?> ?2 ?> [BODY] >> [ELSE] invalid input: '<'invalid input: '<' ...
              -------------------------->
                invalid input: '<'---------------------
                    ---------->
                              ------->!
      
        However the unconditional branch to the unconditional backbranch (!) can be optimized away and the unconditional wrapped back directly to the loop control head
         ?1 ?> ?2 ?> [BODY] invalid input: '<'invalid input: '<' [ELSE] invalid input: '<'invalid input: '<' ...
              -------------------------->
                invalid input: '<'---------------------
                    ---------->
                invalid input: '<'-----------
      
      
      Parameters:
      _instruction -
      Throws:
      ClassParseException
    • addAsComposites

      private void addAsComposites(InstructionSet.ByteCode _byteCode, Instruction _start, BranchSet _branchSet)
    • dumpDiagram

      public String dumpDiagram(Instruction _instruction)
      Aids debugging. Creates a diagrammatic form of the roots (+ tail instruction) so that we can analyze control flow.
      I I I C C I U I U[I]I
            |---------->1
              |---->1
                  |------>2
                      |-->2
      
      Parameters:
      _instruction - The instruction we are considering adding (may be null)
      Returns:
    • getTail

      public Instruction getTail()
    • getHead

      public Instruction getHead()