Apply the short circuit simplification only if the basic block
associated with the internal node requires no statement serialization to
happen in the decompiled code. We use the information provided by the
`MarkForSerialization` to know this.
The condition inside the `IfNode`s are now represented using a custom
`ExprNode` object, which has a new hierarchy of possible nodes present
in an expression (`not`, `and` and `or`).
Moved the `flipEmptyThen` post-processing inside the beautify pass.
The ownership of the `ExprNode` is kept inside the `ASTTree` object.
This means that during the flattening we also need to transfer these
objects and to adjust the pointers inside the `IfNode`s.
Moved a lot of passes that apply optimizations on the AST in the
decompilation pass.
All the optimization functions are now in a dedicated file
(`CDecompilerBeautify.cpp`) and the only function used as interface with
the `CDecompilerAction` pass is the `beautifyAST` function.
This means that now the simplifications will be applied on the already
flattened AST.
Some basic transformations have been left in the `RestructureCFG` pass,
to avoid having an AST of poor quality as output of the pass.
Remove the pointer to the corresponding `BasicBlockNode` inside each
`ASTNode`.
We now keep directly a pointer to the original `llvm::BasicBlock`.
To do this we need to explicitly mantain some information, like the
emptyness of the node (dummy node in the `RegionCFG`).
Some little changes (like the way we retrieve the CFGNode corresponding
to an ASTNode) in the flattening have been necessary too.
Fixed the flattening algorithm, which contemplated only the situation
where the node head of the `Check` chain was directly preceded by only
`Set` nodes.
In reality we may also have in the middle `Dummy` nodes, and for this
reason we need to explore upwards the chain of node until we find all
the `Set` nodes. The implementation takes care of verifying that during
the upwards exploration we only encounter `Set` and `Dummy` nodes.
Add the `IfCheckNode` AST node type, which represents the `Check` nodes
in the RegionCFG. We need an explicit type in the AST since, with the
enforce pass drop before decompilation, we need to handle the code
emission for these type of nodes.
The type has been implemented as a derived type from the `IfNode`, since
they share a lot of similarities, in order to avoid modifications to the
AST simplification functions.
The methods that should not be invoked have been (as the ones that
modify the conditions of the nodes) override and implemented with an
`revng_abort` function
Add a new AST node type for representing the nodes which set the value
for the state variable before an entry or exit dispatcher.
In this way, when printing the decompiled code we do not need to inspect
the node further.
Removed the `Switch` BBNode, which was used to create the intermediates
nodes for making an original `switch` node a nested tree of `if` checks.
Also removed the `IfEqual` AST node, which was used to represent the
intermediate check nodes in the AST, for later reconstructing the
original `Switch` node in the AST, when possible.
Match `SwitchNode` on the AST, starting from the `IfNode` nested tree
structure which is generated during the preprocessing.
We basically match a consecutive chain of `IfNode`, checking that the
corresponding original `BasicBlock`s are composed by a couple of compare
and branch instructions, all over the same `Value`.
Remove from the `IfEqualNode` the reference to the BBNode corresponding
to the original `switch`, since we cannot have the guarantee that this
node will remain allocated in the same place (the pointer could be
invalidated).
Also insert other fixes.
Improved the method for matching the `then` and `else` branches when
creating the AST node for the `IfEqualNode`.
Also converted the name of an auxiliary pass to the convention.
Add a new AST node type for representing the nodes created starting from
the dummy nodes built in place of a `switch` statement.
These nodes contain also the information needed for emitting the code
relative to the checks performed by the node (the condition and the case
value).
This node type inherits from the `IfNode` node type, to avoid
reimplementing all the methods for its handling and transformation.
Add a pass which removes the `unexpectedpc` as successor of the `switch`
instructions. This simplifies the subsequent analyses.
This pass also removes the unreachable basic blocks dandling around (as
the `unexpectedpc` and `anypc` blocks when they are not needed).
Now considering the fact that the body of a loop may become empty if
some simplification take place (e.g. we match a `while` whose body is
composed only by a check with `break` and `continue` branches).
When a `while` loop is matched and promoted, add to every `continue`
node in the current scope the instructions needed for the computation of
the loop condition.
Match `do-while` and `while` loops, transform the in our AST preserving the
information about the `IfNode` which computes the condition of loop, and
emit them in the decompiled code.
Also added a pass which removes useless continue nodes.