Commit Graph

356 Commits

Author SHA1 Message Date
Qian Matteo Chen bd613d5c7f [TypeShrinking] Remove unused files 2020-12-23 01:29:43 +01:00
Qian Matteo Chen 479298d60c [TypeShrinking] Implement type shrinking pass 2020-12-23 01:17:55 +01:00
Qian Matteo Chen fa05ef07f9 [TypeShrinking] Make solving mfp static 2020-12-23 01:09:37 +01:00
Qian Matteo Chen 31b8ed7b14 [TypeShrinking] Move BitLiveness.h to local folder 2020-12-23 01:03:56 +01:00
Qian Matteo Chen ba099220da [TypeShrinking] Add type shrinking mvp 2020-12-23 00:14:03 +01:00
Qian Matteo Chen 86cd1d5505 [TypeShrinking] Add and fix copyright notices 2020-12-22 20:08:06 +01:00
Qian Matteo Chen cccd462b64 [TypeShrinking] Add example of MonotoneFramework 2020-12-22 18:33:24 +01:00
Qian Matteo Chen 60c4e59c6b [TypeShrinking] Refactor MFP to use GraphTraits 2020-12-22 18:30:33 +01:00
Qian Matteo Chen 3d8793fa2a [TypeShrinking] Move implementation to cpp file 2020-12-22 18:19:43 +01:00
Qian Matteo Chen 0bd393a691 [TypeShrinking] Use explicit pointer types 2020-12-22 17:07:51 +01:00
Qian Matteo Chen 473982966b [TypeShrinking] Combine isLess and areEqual 2020-12-22 17:04:55 +01:00
Qian Matteo Chen 335eb24191 [TypeShrinking] Remove c-style comments 2020-12-22 16:58:25 +01:00
Qian Matteo Chen 7feebad315 [TypeShrinking] Add implementation of MFP
See Principles of Program Analysis, Springer 2005, p 75
2020-12-22 16:55:16 +01:00
Qian Matteo Chen c1d144f186 [TypeShrinking] Add pass to print dataflow edges 2020-12-22 16:39:38 +01:00
Pietro Fezzardi ebe43602ac New FilterForDecompilation passes
This commits adds two passes
- FilterForDecompilationFunctionPass deletes the body of a Function if
  it's not a isolated function produced by revng
- FilterForDecompilationModulePass deletes all the bodies of the
  functions that are not isolated functions generated by revng

These passes are used at the beginning of the decompilation pipeline, to
prevent all the passes of the decompilation pipeline to run on root and
other big functions coming from QEMU that do not need to be decompiled.
2020-12-16 18:20:58 +01:00
Pietro Fezzardi 08c76374a2 MakeEnvNullPass is now a FunctionPass
This fixes an issue causing crashes when calling the public API
`decompileFunction`, that was internally adding a `MakeEnvNullPass`
(formerly a `ModulePass`) to a `FunctionPassManager.
2020-12-01 17:34:30 +01:00
Pietro Fezzardi d4d8430553 Add MakeEnvNull pass
This pass substitutes the `@env` global variable with a null pointer
`@env` is a pointer to the CPU state in QEMU, and is not meant to be
visible in the decompiled code.
This pass is used to remove all references to it before decompilation.
2020-11-17 14:33:19 +01:00
Pietro Fezzardi 429633b627 Use #pragma once for header include guards 2020-11-12 18:00:45 +01:00
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 6c8eb2fd53 ASTTree: remove Successor in sequence creation
When the `Successor` field is consumed to create the `Sequence` nodes,
we blank the field so that we do not have redundant information in our
graph representation.
2020-11-06 15:08:00 +01:00
Andrea Gussoni 1bade3fd88 ASTTree: delete sequence nodes in simplification
When performing `atomicSequenceSimplification`, actually remove the
nodes from the ASTTree.
2020-11-06 15:08:00 +01:00
Andrea Gussoni 5afaa7a90b ASTTree: AST debug printing is now iterative
Change the AST debug printing from a recursive descent on the AST nodes
in the graph, to an iterative printing of respectively nodes and their
outgoing edges.

Also, we now print the edge going to the `Successor` field, if present.
2020-11-06 15:08:00 +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 f3df7e2ab1 Fix inclusion order 2020-11-06 15:08:00 +01:00
Andrea Gussoni e6e5c73f62 ASTTree: Remove old version of dumpASTOnFile 2020-11-06 15:08:00 +01:00
Andrea Gussoni df0985f1fc RegionCFG: dumpOnFile to dumpASTOnFile 2020-11-06 15:08:00 +01:00
Andrea Gussoni eb1ddab86c RegionCFG: dumpDotOnFile to dumpCFGOnFile 2020-11-06 15:08:00 +01:00
Andrea Gussoni 7362e7beeb RegionCFG: Reorganize graph debug
Now, when the `debug-log=restructure` flag is active, debug graphs are
organized in a more rational way.

First of all, all the graphs are now put in a single directory, and are
divided first by function name and then by type.

Also, as in the case of the tiling debug graphs, their name is more
consistent with the rest of the codebase.
2020-11-06 15:08:00 +01:00
Pietro Fezzardi e0c5bba880 Drop UnitTestHelpers.h, now shipped by revng 2020-11-06 15:08:00 +01:00
Pietro Fezzardi 217a18edb1 Update copyright notice 2020-11-06 15:07:45 +01:00
Pietro Fezzardi 890d60833b Drop old obsolete RemovePCStoresPass 2020-11-04 09:42:13 +01:00
Pietro Fezzardi 8bfbb153ca libDecompiler: new public API decompileFunction 2020-11-04 09:32:36 +01:00
Pietro Fezzardi 90ff17f107 Fix handling of switch default in GHAST 2020-11-04 09:32:36 +01:00
Andrea Gussoni 6a8a1b613d Combing: fix conditional node edge inlining
Before marking any outgoing edge as inlined, check that the exit nodes
reachable from each successor of the conditional node are two disjoint
sets.
2020-11-04 09:32:36 +01:00
Andrea Gussoni 371dc7ea97 Remove exceptions before decompilation in pipeline
We now craft a new decompilation pipeline. We remove the exceptions
introduced as fallbacks to preserve the semantics, and we perform passes
of `dce` and `simplifycfg` to remove all the superfluos basic block
remaining after this change. To do this, we need an additional pass that
removes also the calls to the `llvm.assume` intrinsic, and another pass
of `dce` to remove all the dead uses.

In addition, we also remove dead stores to the `cpu_loop_exiting` global
variable in order to improve the decompiled code.

As a byproduct of this, we remove also the dependency from the
`-remove-pc-stores` pass, since its jobs is included by the changes
mentioned above.
2020-11-02 18:33:57 +01:00
Andrea Gussoni f57a96ab95 generateAst: Fix two successors two dominated tile
Now cover a corner case where we have a tile composed by two successors,
which we entirely dominate, and a common postdominator which we don't
postdominate (basically we miss a superfluos dummy here).

In this case, include in the tile `then` and `else` bodies, but do not
include in the tile the common postdom (it will be taken care by someone
else more higher in the CFG).
2020-10-30 16:58:00 +01:00
Pietro Fezzardi 2b599d0ebc RestructureCFG: fix NDuplicates 2020-10-30 01:12:03 +01:00
Pietro Fezzardi b2437ddabc Drop old unused pass RemoveUnexpectedPCPass 2020-10-29 09:34:05 +01:00
Pietro Fezzardi 6cea19ef4d generateAst: update ASTDT instead of recomputing 2020-10-28 18:34:09 +01:00
Pietro Fezzardi 4dcc02c550 weaving: avoid using Sink
Thanks to inlined edges, this is now not necessary anymore.
2020-10-26 17:05:15 +01:00
Pietro Fezzardi 7c2f70cdac Drop RemoveSwitchPass
Now that we fully support switches, there's no need for this pass to
exist anymore.
2020-10-26 14:48:37 +01:00
Pietro Fezzardi 049e687e3b Remove flattening 2020-10-26 14:29:47 +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 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
Pietro Fezzardi acb21bba5e RegionCFG: remove wrong assertion 2020-10-26 14:16:22 +01:00
Pietro Fezzardi 7ff0d0b8d0 RestructureCFG: Mark anyPC as inlined 2020-10-26 14:15:39 +01:00
Pietro Fezzardi 4fc2ab56a0 RegionCFG::inflate(): fix assertion 2020-10-26 14:15:28 +01:00
Pietro Fezzardi 6024ce9a1b RegionCFG: fix bug ini markUnexpectedPCAsInlined()
This commit fixes a bug causing iterator invalidation in
`markUnexpectedPCAsInlined`.
Before this commit we were iterating over a graph while adding nodes,
which could cause iteration invalidation on realloc.
2020-10-26 14:13:46 +01:00
Pietro Fezzardi 6dbb11f39b Drop RemoveBadPCPass
This pass is now useless in revng-c, since we have the
--isolate-no-safety-checks flag in revng.
2020-10-26 14:13:25 +01:00