Package com.aparapi.internal.instruction
Class ExpressionList
java.lang.Object
com.aparapi.internal.instruction.ExpressionList
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.
- Author:
- gfrost
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionadd
(Instruction _instruction) Add this instruction to the end of the list.createList
(Instruction _newTail) [1] [2] [3] [4] Note that passing null here essentially deletes the existing expression list and returns the expressionboolean
doesNotContainCompositeOrBranch
(Instruction _start, Instruction _exclusiveEnd) boolean
doesNotContainContinueOrBreak
(Instruction _start, Instruction _extent) Determine whether the sequence of instructions from _start to _extent is free of branches which extend beyond _extent.dumpDiagram
(Instruction _instruction) Aids debugging.boolean
foldComposite
(Instruction _instruction) Fold headTail.tail into valid compositesgetHead()
getTail()
void
insertBetween
(Instruction _prev, Instruction _next, Instruction _newOne) Insert the given instruction (_newone) between the existing entries (_prev and _next).void
replaceInclusive
(Instruction _head, Instruction _tail, Instruction _newOne) Inclusive replace between _head and _tail with _newOne.void
unwind()
-
Constructor Details
-
ExpressionList
-
-
Method Details
-
doesNotContainContinueOrBreak
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
-
unwind
public void unwind() -
createList
[1] [2] [3] [4] Note that passing null here essentially deletes the existing expression list and returns the expression- Parameters:
_newTail
-- Returns:
-
add
Add this instruction to the end of the list.- Parameters:
_instruction
-- Returns:
- The instruction we added
-
insertBetween
Insert the given instruction (_newone) between the existing entries (_prev and _next).- Parameters:
_prev
-_next
-_newOne
-
-
replaceInclusive
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
Fold headTail.tail into valid compositesif(??){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
-
dumpDiagram
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
-
getHead
-