3016 Commits

Author SHA1 Message Date
Pietro Fezzardi 490b5eaef8 Apply clang format 2019-04-02 15:30:17 +02:00
Pietro Fezzardi 9e4c5f0ece Add support for functions returning structs 2019-04-02 11:57:07 +02:00
Pietro Fezzardi b514cc9399 Add virtual destructors for ExprNode 2019-03-28 11:20:25 +01:00
Pietro Fezzardi e6e2f52aa2 Add virtual destructors to ASTNodes 2019-03-28 11:11:57 +01:00
Pietro Fezzardi 25d9a8f3d5 Handle Set/Check nodes for loop state variables 2019-03-26 13:51:06 +01: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
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 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 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 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 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 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
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 5b8ebd505c BasicBlockNode: add getNodeType method 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 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
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 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
Pietro Fezzardi 76135b76fb Add RemoveDbgMetadata FunctionPass 2019-03-08 15:00:59 +01:00
Alessandro Di Federico 9b070d8856 SA: use deque were appropriate
In certain locations we were using a `std::vector`, taking a reference
to it, adding elements and ending up in a reference invalidation issue.

This commit replaces those `std::vectors` with `std::deque` which do not
present this issue.
2019-03-08 15:00:59 +01:00
Alessandro Di Federico 467d916aac Ignore pc and sp in ABI analysis
They are not really part of the ABI.
2019-03-08 15:00:59 +01:00
Alessandro Di Federico 5dc8056b8c Introduce enforce-abi pass
This commit introduces the `enforce-abi` pass, which consumes the
information provided by the ABI analysis and enforces them in the
isolated functions adding actual arguments.

This commit also rewrites the logic of `ResultsPool::finalize` and
changes the semantic of `Yes` statements on arguments to `YesOrDead`.
2019-03-08 15:00:59 +01:00
Alessandro Di Federico 2bd8c468bc Introduce empty-newpc pass
`empty-newpc` is a simple pass suppose to provide an empty body for
the `newpc` function, allowing further optimization pass to take out
all its calls.
2019-03-06 10:31:23 +01:00
Alessandro Di Federico cb2bd9a3ce IRHelpers: introduce getCallToHelper 2019-03-06 10:31:23 +01:00
Alessandro Di Federico 0fa2d79fe4 Introduce ZipMapIterator
`ZipMapIterator` allows you to iterate in parallel over two
`std::map`-like containers.

In the ABI analysis, this allows us to be much more efficient. In
practice, if we have two maps with M and N elements, we pass from
performing N*log(N) + M*log(M) queries to the size of the union of the
set of keys of the two maps.
2019-03-06 10:31:23 +01:00
Alessandro Di Federico 7476eb5cbf MonotoneFramework: allow successors in final BBs
This will be necessary to correctly handle infinite loops.
2019-03-06 10:31:23 +01:00
Alessandro Di Federico b232678477 GCBI: collect and expose ABI registers 2019-03-06 10:31:23 +01:00
Alessandro Di Federico b7b82a55a9 Marker functions: add the function isolation ones 2019-03-06 10:31:23 +01:00
Alessandro Di Federico 52f847a4df IRHelpers: introduce getName(Function *) 2019-03-06 10:31:23 +01:00
Alessandro Di Federico 103df1e46c Backward BFSVisitor: include starting instruction
The `BFSVisitorBase` can go forward and backward starting from a certain
instruction. When going backward, it used to skip the starting
instruction.

For simmetry purposes, this commit changes that.
2019-03-06 10:31:22 +01:00
Alessandro Di Federico 2d521285bb Handle helper functions in StackAnalysis
In the stack analysis, we used to consider helper functions as indirect
calls. However, the `CPUStateAccessAnalysis` provides us accurate
information about what an helper function does.

This commit transforms calls to helper functions in a series of ABI IR
instructions reading all the input registers of the helper functions and
a series of instructions writing the output registers.

Note that, while this is a serious improvement over considering them
indirect function calls, it's still suboptimal since
`CPUStateAccessAnalysis` doesn't provide us information as fine-grained
as the ABI analysis.
2019-03-06 10:31:19 +01:00
Alessandro Di Federico 17b1eb19a9 Introduce revng.csv for listing CSVs
Previously, to enumerate all the CSVs we had to go through the
`GlobalVariable` of a `Module` and see if the were being used in
rev.ng-generated code.

Now we have a named metadata for that: `revng.csv`.
2019-03-06 09:04:58 +01:00
Alessandro Di Federico 75914742d7 Use BlockType by name in metadata
We used to save the type of a block in the `revng.block.type` metadata
as a number. This commit serializes it as a string.

In order to do this, the `BlockType` enum has been promoted to a
namespace with the usual `getName` and `fromName` functions.
2019-03-06 09:04:58 +01:00
Alessandro Di Federico 45172f52d9 LazySmallBitVector: introduce operator<
`LazySmallBitVector` was lacking a comparison operator, which prevented
it from being used as the key of a `std::map`.

This commit implements such operator, along with the `reserve` method.
2019-03-06 09:04:58 +01:00
Pietro Fezzardi baa68faaf9 Fix linking erros with librevngSupport.so
`extern` declarations of template specializations for Logger<true> and
Logger<false> caused weak symbols to be emitted in librevngSupport.so
and into its users.
Dynamic loading then failed because both symbols were weak.
This commit removes the `extern` declarations so that dynamic loading
succeeds.
2019-03-06 09:04:58 +01:00