Commit Graph

46 Commits

Author SHA1 Message Date
Pietro Fezzardi 93d9cbb67b Enforce new include conventions 2020-11-12 18:00:45 +01:00
Alessandro Di Federico 37fde04594 Move licensing details to LICENSE.md 2020-11-09 10:03:33 +01:00
Andrea Gussoni f3f11533b8 ASTTree: Reorganize AST dot printing
Reorganize the AST dot printing in order to use LLVM facilities for
files handling. In addition, clean up the code, and add a function
(useful in debug) in order to dump the dot of and AST from GDB (accepts
a `char *` instead of a `std::string`.
2020-11-06 15:08:00 +01:00
Andrea Gussoni df0985f1fc RegionCFG: dumpOnFile to dumpASTOnFile 2020-11-06 15:08:00 +01:00
Pietro Fezzardi 217a18edb1 Update copyright notice 2020-11-06 15:07:45 +01:00
Pietro Fezzardi f127764e0b CDecompilerBeautify: fix beautification of IfNodes
This commit fixes two interacting problems in the beautification of if
statements.

First, in `simplifyShortCircuit`, there were two assertion on null
pointers that were too strict. These assertions didn't take into
consideration that one among the "then" and the "else" branch of an
`IfNode` could be simplified away _during_ the beautification itself.

Second, a previous commit had moved the execution `flipEmptyThen` after
the two beautification of short-circuit, leading to assertions failed
in `simplifyTrivialShortCircuit`.
This was caused by the fact that `simplifyTrivialShortCircuit` only
never expected `IfNode`s with empty "then".
This was fixed by running `flipEmptyThen` also before
`simplifyTrivialShortCircuit`.
2020-11-04 09:32:36 +01:00
Pietro Fezzardi c2e8e65baa CDecompilerBeautify: weaken simplifyLastContinue
The simplifyLastContinue beautifier was too ambitious and there were
many corner cases that it handled in the wrong way, leaving the AST in a
shape that could not be emitted, or breaking the semantics.

This commit severely weakens the simplifyLastContinue, so that it does
not break things anymore.
It is now able to match only continue statements that are in the last
position of a sequence node which is the body of a ScsNode.

This obviously is not enough but allows revng-c to pass all the
decompilation tests.
In the future we will need to extend simplifyLastContinue to match more
cases in a sane way.
2020-10-26 14:17:25 +01:00
Pietro Fezzardi 88ecb5de14 CDecompilerBeautify: match short-circuits early
This commit moves the matching of short-circuited ifs before the stage
of flipping if nodes with emtpy then.
This is necessary because the if short-circuiting may produce if nodes
with empty then, which can be then flipped by the next beautify step.
2020-10-26 14:16:53 +01:00
Pietro Fezzardi f5e26febe2 Fix simplifyAtomicSequence for switches
Before this commit, we couldn't handle simplification of atomic
sequences in cases of switches that had a default.
The reason is that if you remove a case from a switch that has a
default, you are implicitly saying that the case that you remove will be
handled by the default, hence you're changing the semantics.

Now we handle this case by not removing the case, substituting it with a
SwitchBreak node instead.
2020-10-26 14:16:38 +01:00
Andrea Gussoni 7783794aa2 generateAst: delete old AST simplification helpers
Remove from the `RegionCFGTreeImpl.h` header the helper functions used
for the first AST simplification that are now part of the
`GenerateAst.h` header.
2020-10-26 14:11:16 +01:00
Pietro Fezzardi 755bca083a Beautify: debug print AST before beautification 2020-10-26 14:10:10 +01:00
Andrea Gussoni a71f06ebe6 Handle SwitchNode in flipEmptyThen method 2020-10-26 13:57:34 +01:00
Pietro Fezzardi 1a9ae59e4a RestructureCFG: major refactoring of switches
Now edges have sets representing labels.
There's no distinction between Dispatchers and Regular switches at the
GHAST level anymore.
2020-07-20 19:02:19 +02:00
Pietro Fezzardi f7e8599c5e Enforce check-conventions.sh
All commits should pass check-conventions.sh from now on.
2020-06-15 15:40:02 +02:00
Andrea Gussoni 95dbc22a36 Remove IfDispatcherNode
Remove the `IfDispatcherNode` from the hierarchy of the `ASTNode`s.
Disable the beautify routines since they are not relevant anymore.
2020-06-15 15:06:23 +02:00
Andrea Gussoni a264117aac Rename IfCheck in IfDispatcher
Now that check nodes are nomore a thing, rename the `ifcheck` in the
AST with a meaningful name.
2020-06-15 15:06:23 +02:00
Andrea Gussoni dc944d35f5 Rename SwitchCheck in SwitchDispatcher
Now that check nodes are nomore a thing, rename the switches in the AST
with a meaningful name.
2020-06-15 15:06:23 +02:00
Pietro Fezzardi 5a4e47c535 CDecompilerBeautify: fix wrong switch fallthrough 2019-11-25 15:30:41 +01:00
Pietro Fezzardi 650d255e74 add revng_unreachable in unexpected ASTNode kind 2019-11-20 15:16:17 +01:00
Pietro Fezzardi 429233f054 Fix more warnings left from -Weverything 2019-11-20 15:16:17 +01:00
Andrea Gussoni 335dc34ad1 Fix -Wshadow 2019-11-20 15:16:17 +01:00
Pietro Fezzardi f95899c7ac Fix LLVM-style RTTI destruction for ASTNode 2019-11-20 15:16:17 +01:00
Pietro Fezzardi cb58b8a526 Fix destruction of ExprNodes class hierarchy
`ExprNode` and its child classes use LLVM-style RTTI.

Until now their destruction was not handled properly, causing the
constructor-destructor type mismatch warnings on ASAN.
Despite this all the code was working properly, but just for luck,
because of the fact that these classes are very shallow.

This commit fixes the issue, and allow `ExprNode` and its child classes
to be extended without worrying about wrong destructors being invoked.
2019-11-20 15:16:17 +01:00
Andrea Gussoni 560a345a2c Enforce -Weverything extensively
Replicate the changes made by this commit
f2a0df309f78e1b5d7c5f81ada5110523644559e perfomed by Pietro on the
branch containing the development fixes for `revng-c`.
2019-11-20 15:16:17 +01:00
Pietro Fezzardi 02ea1e5f94 Fix warnings emerged with -Wextra and -Weverything 2019-11-20 15:16:17 +01:00
Pietro Fezzardi 569ec5658e Add and enforce -Wall and -Werror 2019-11-20 15:16:14 +01:00
Andrea Gussoni 4bead538a7 Collect metrics about short circuit simplification
Collection of the metrics related to the short circuit and trivial short
circuit simplification. The metrics are computed directly during the
beautify pass and later serialized on a .csv file.
2019-07-30 18:20:11 +02:00
Andrea Gussoni b6646b692e HACK: requiresNoStatement always true
The companion function for the short circuit simplification, which tells
if the computation of the condition of a conditional node can be
inlined, always returns true, and therefore enables all the possible
optimizations.
2019-07-30 18:20:11 +02:00
Andrea Gussoni 8eb5abaaeb Fix emission computation for continue nodes
Added a new attribute for the `ContinueNode`, which tells if a
`ContinueNode` should be considered implicit. An implicit continue node
means that it can be dropped without it altering the semantics of the
code (e.g., when the `continue` is the last statement inside the body of
a cycle).

This attribute enables us to avoid directly dropping the continue node,
which would also cause the computation attached to this node to be
dropped, also in the output of the decompiler pass.
2019-07-30 18:20:06 +02:00
Andrea Gussoni 39961f0ec3 Fix switch matching
For the switch reconstruction, we now only match basic block that we now
were created during the switch normalization pass.
2019-06-13 12:21:07 +00:00
Pietro Fezzardi b058c326c6 Enforce coding style 2019-05-08 17:40:53 +02:00
Pietro Fezzardi 8ab637df8a Fix missing default statements from switches 2019-05-06 11:19:41 +02:00
Pietro Fezzardi de7089cbc4 Handle breaks from loops from within switches 2019-05-06 11:19:41 +02:00
Pietro Fezzardi 08f68994bd Add SwitchBreakNodes in fixSwitchBreaks() 2019-05-06 11:19:41 +02:00
Pietro Fezzardi d04f6ba9de Add skeleton for fixSwitchBreaks() 2019-05-06 11:19:41 +02:00
Andrea Gussoni dee4db8216 DOT and AST only enabled in debug mode
To avoid skeing the results the serialization of `DOT` intermediate file
for both restructuring and AST semplification passes are now serialized
only when the corresponding loggers (`CombLogger` and `BeautifyLogger`)
are enabled.
2019-04-24 16:21:34 +02:00
Pietro Fezzardi 743b2e522c Fix switches with empty cases 2019-04-12 18:25:15 +02:00
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 25d9a8f3d5 Handle Set/Check nodes for loop state variables 2019-03-26 13:51:06 +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 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