Commit Graph

32 Commits

Author SHA1 Message Date
Pietro Fezzardi de7089cbc4 Handle breaks from loops from within switches 2019-05-06 11:19:41 +02:00
Pietro Fezzardi a946f2ba9a Add SwitchBreakNode 2019-05-06 11:19:41 +02:00
Andrea Gussoni e6ec54c9bc Enforce const on member functions 2019-04-16 10:19:34 +02:00
Pietro Fezzardi 9e4c5f0ece Add support for functions returning structs 2019-04-02 11:57:07 +02:00
Pietro Fezzardi d50f9d0036 Improve prototypes of ASTNode members 2019-03-25 16:08:41 +01:00
Andrea Gussoni 9dc26b6d05 Create SwitchCheckNode
We now match the `IfCheckNode` trees created by the dispatchers
insertion as an unique switch.

To this we introduced a new `SwitchCheckNode` AST type, which cannot
inherith from the `SwitchNode` since the underlying container for the
`case`s is different (the index is saved as an `unsigned`, while instead
in the `SwitchNode` we use a `ConstantInt *`.
2019-03-21 14:25:48 +01:00
Pietro Fezzardi 65e1d9e35b Emit switch 2019-03-20 19:37:29 +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 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
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 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 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 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 939c632e3b Remove spurious debug messages 2019-03-08 15:17:31 +01:00
Pietro Fezzardi 3b2dac4e85 Enforce clang-format 2019-02-25 12:29:15 +01:00
Pietro Fezzardi cb08b4ac31 tmp 2019-02-12 20:55:28 +01:00
Andrea Gussoni f790e308e1 Add ID for AST nodes
Added a unique ID to AST nodes, which is useful for serialization
purposes after flattening.
2019-02-11 14:15:07 +01:00
Pietro Fezzardi f0b9648d4a Remove checks that are now redundant 2019-02-11 12:18:44 +01:00
Pietro Fezzardi 463c40a9cf Add ASTNode children BreakNode and ContinueNode 2019-02-11 12:18:44 +01:00
Andrea Gussoni 929c0c4cdf Flattening for AST
Implemented the flattening also for the AST trees, taking also care of
adjusting the pointers to the new BBNode in the `root` `RegionCFG`.
2019-02-11 12:18:44 +01:00
Andrea Gussoni 2e9ff8449f Improved debugging messages 2019-02-05 10:17:47 +01:00
Andrea Gussoni c70b6f1097 Implemented de-optimization on RegionCFGTree
Now, during the simplification of short-circuits the so called
`de-optimization` is also applied to the corresponding `RegionCFGTree`.

This allows us to avoid loss of information during the iterative
refinement phase, which basically divides for ever the existencies of
two nodes that have been cloned starting from a single original one.
2019-01-25 13:45:03 +01:00
Andrea Gussoni 7de353785e Implemented conditional node list for IfNode
After short-circuit simplification, we can have that a conditional node
corresponds to more than one `BasicBlockNode`.

This change reflects this fact, and takes care of merging blocks during
short-circuit simplification, and of representing this change in the
serialization.
2019-01-25 13:32:29 +01:00
Andrea Gussoni 9876e514d5 Improved isEqual operator with deep comparison
Now the `isEqual` operator does what we call a `deep` comparison,
meaning for every type of `ASTNode` it recursively check if the
structures of the AST tree originating in that node can be considered
equivalent (e.g., two sequence nodes are considered equal if every node
they contain is in turn equal).

This operator gives more space to the short-circuit simplification,
which relies heavily on the `isEqual` operator.
2019-01-22 19:16:48 +01:00
Pietro Fezzardi 5805679ead RestructureCFGPass: fix use of include directory 2019-01-15 16:57:15 +01:00
Andrea Gussoni 06717a6185 Import RestructureCFGPass from revamb branch
Import the RestructureCFGPass from the `feature/the-comb` branch on the
`revamb` repository.
2019-01-14 15:45:08 +01:00