Commit Graph

6113 Commits

Author SHA1 Message Date
Pietro Fezzardi dadbf54631 Rework decompiler 2019-03-20 17:47:04 +01:00
Andrea Gussoni 00ce604293 Accessors for the ExprNode
Accessors for childs of the `not`, `and` and `or` `ExprNode`
2019-03-20 17:00:39 +01:00
Andrea Gussoni c778004638 Apply short circuit only when possible.
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.
2019-03-20 16:57:41 +01:00
Andrea Gussoni 8aaae2548b IfNode now using ExprNode
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.
2019-03-20 15:24:28 +01:00
Andrea Gussoni 0cc9ddbdd5 Add llvm::Value condition to SwitchNode.
Add a new private member in the `SwitchNode` to keep track of the
original `llvm::Value` which originated the `SwitchNode`.
2019-03-19 14:52:13 +01:00
Andrea Gussoni 3cf9ffd3ca Move beautify passes in DecompilationPass
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.
2019-03-14 18:03:36 +01:00
Andrea Gussoni c930d1a7fd Remove pointer to CFGNode from ASTNode.
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.
2019-03-14 12:23:25 +01:00
Pietro Fezzardi 77a6601837 Use new MarkForSerialization in CDecompilerAction 2019-03-14 10:06:25 +01:00
Pietro Fezzardi bc6e2fcb01 Add MarkForSerialization MonotoneFramework 2019-03-14 09:50:14 +01:00
Pietro Fezzardi d4dec0136c CDecompilerPass depends on PHIASAPAssigmentInfo 2019-03-14 09:50:14 +01:00
Pietro Fezzardi debdb6a9f4 Move PHIASAPAssignmentInfo in separate library 2019-03-14 09:50:14 +01:00
Pietro Fezzardi b4758ae02d Move PHI analysis in PHIASAPAssignmentInfo 2019-03-14 09:49:43 +01:00
Pietro Fezzardi d5fbf88e68 Add skeleton for PHIASAPAssignmentInfo Pass 2019-03-14 09:49:43 +01:00
Pietro Fezzardi 785638dc30 Add missing LICENSE header in file 2019-03-14 09:49:43 +01:00
Pietro Fezzardi c2f5c636ff Use uniform convention for include guards 2019-03-14 09:49:43 +01:00
Andrea Gussoni 7e4bbfb2d2 Fix flattening for CheckNode and SetNode
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.
2019-03-13 17:33:44 +01:00
Andrea Gussoni b1510fbc8e Add ifCheckNode AST type
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
2019-03-13 12:27:00 +01:00
Andrea Gussoni ca89792a30 Add SetNode AST type
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.
2019-03-12 15:40:41 +01:00
Andrea Gussoni 2e49e21925 Removed Switch BBNode and IfEqual AST node
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.
2019-03-12 14:55:02 +01:00
Andrea Gussoni 4a49a60b99 Fix and convention enforcing
Some fixes and conventions enforcing before decompilation pipeline
restructure.
2019-03-12 13:49:53 +01:00
Andrea Gussoni 9d7e2f25b7 Fix IfNode branch order for Switch match. 2019-03-11 18:50:03 +01:00
Pietro Fezzardi 2640bbfeeb Use uniform naming for decompiler source files 2019-03-11 18:11:05 +01:00
Pietro Fezzardi 5ed050dead DecompilationPass: remove dependency on enforcing 2019-03-11 18:11:05 +01:00
Pietro Fezzardi 0711d00c4b Flattening: remove Check and Set BasicBlockNodes 2019-03-11 18:11:05 +01:00
Pietro Fezzardi 5b8ebd505c BasicBlockNode: add getNodeType method 2019-03-11 18:11:05 +01:00
Pietro Fezzardi 094c435296 Fix assertion for 128 bit operations 2019-03-11 18:11:05 +01:00
Andrea Gussoni f15dd3da89 Match SwitchNode on AST
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`.
2019-03-11 18:11:05 +01:00
Andrea Gussoni 969b5e7601 Remove reference to original switch
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.
2019-03-11 11:24:18 +01:00
Andrea Gussoni 27192a251f Improved IfEqualNode then and else match
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.
2019-03-08 15:44:29 +01:00
Andrea Gussoni 9f00e3125e Add SwitchNode AST type
Match and create the `SwitchNode` node when we encounter a chain of
`IfEqualNode` nodes.
2019-03-08 15:31:30 +01:00
Andrea Gussoni f905a42ff6 Add SwitchNode AST type
Add a new AST node type for representing a `switch` node.
2019-03-08 15:31:30 +01:00
Andrea Gussoni f41453e3f3 Add IfEqualNode AST type
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.
2019-03-08 15:31:30 +01:00
Andrea Gussoni f27597b999 Introduce the Switch BasicBlockNode type
Introduced a new `BasicBlockNode` type to represent the nodes created
when building the nested tree in place of the `switch` instruction.
2019-03-08 15:31:30 +01:00
Andrea Gussoni b07176f898 Boilerplate for switch handling 2019-03-08 15:31:30 +01:00
Andrea Gussoni c05974478c Add RemoveUnexpectedPCPass
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).
2019-03-08 15:31:30 +01:00
Pietro Fezzardi 2bce929e4a Parenthesize negated conditions in if and loops 2019-03-08 15:27:50 +01:00
Andrea Gussoni 20cec12b5e After semplification while loops might be empty
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).
2019-03-08 15:27:50 +01:00
Andrea Gussoni 318c7dabd7 Add computation before continue nodes
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.
2019-03-08 15:27:50 +01:00
Andrea Gussoni 8ca3bbdf91 Negate loop condition when necessary 2019-03-08 15:27:50 +01:00
Andrea Gussoni eb78d6121f Match do-while and while loops
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.
2019-03-08 15:27:50 +01:00
Andrea Gussoni aee582a586 Make pass names compliant to the convention 2019-03-08 15:26:46 +01:00
Alessandro Di Federico 8337f70ca6 Merge branch 'feature/preliminary-c' 2019-03-08 15:25:39 +01:00
Andrea Gussoni 939c632e3b Remove spurious debug messages 2019-03-08 15:17:31 +01:00
Alessandro Di Federico 63f0efbada Temporarily disable OSRA-related failing tests 2019-03-08 15:05:10 +01:00
Pietro Fezzardi 76135b76fb Add RemoveDbgMetadata FunctionPass 2019-03-08 15:00:59 +01:00
Alessandro Di Federico 28ceefcac3 SA: unify management of CSV indices 2019-03-08 15:00:59 +01:00
Alessandro Di Federico 02273d58e6 Add ABI registers for architectures missing them 2019-03-08 15:00:59 +01:00
Alessandro Di Federico 489e4b1d87 ABI analysis: ignore non-CSV used by helpers 2019-03-08 15:00:59 +01:00
Alessandro Di Federico 5904e78bdb Disable exceptions 2019-03-08 15:00:59 +01:00
Alessandro Di Federico c2d39fb702 SA: reorganize the way functions are registered 2019-03-08 15:00:59 +01:00