Commit Graph

3168 Commits

Author SHA1 Message Date
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 1b4c5b96f0 ASTTree: avoid printing Successors 2020-10-26 14:17:18 +01:00
Pietro Fezzardi cc3ed6c508 Remove all blacklisted function from decompilation 2020-10-26 14:17:02 +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
Pietro Fezzardi 38935f3a40 Remove functions from decompilation blacklist
We're now able to handle them, so there's no need to skip them anymore.
2020-10-26 14:13:31 +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
Pietro Fezzardi a84f69e7c9 ASTTree: add Successor edges to dot dumps 2020-10-26 14:11:49 +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 55731fd100 generateAst: fix createSequence 2020-10-26 14:10:58 +01:00
Pietro Fezzardi ee5e934e86 RestructureCFG: merge debug prints 2020-10-26 14:10:44 +01:00
Pietro Fezzardi 74698f9f95 ASTNode: print nodes based on ID 2020-10-26 14:10:36 +01:00
Pietro Fezzardi 755bca083a Beautify: debug print AST before beautification 2020-10-26 14:10:10 +01:00
Pietro Fezzardi c7b05cbb2c RestructureCFG: fix CollapsedMap 2020-10-26 14:09:41 +01:00
Pietro Fezzardi 432957c649 RestructureCFG: cleanump AST and NDuplicates 2020-10-26 14:09:26 +01:00
Pietro Fezzardi a2e9a7660d ASTNode and ASTTree: cleanup of data members
This commit removes the old unused field `Processed` from `ASTNode`, and
fixes the default construction of `ASTTree` data memebers.
2020-10-26 14:09:02 +01:00
Andrea Gussoni 3128c1a4b6 Factor generateAST out as function 2020-10-26 14:07:54 +01:00
Pietro Fezzardi b16d6dde86 RestructureCFG: prevent computing useless PDT 2020-10-26 14:00:16 +01:00
Andrea Gussoni dd3325f8a3 [INLINING] TEMP: skip tile nodes 2020-10-26 13:57:43 +01:00
Andrea Gussoni a71f06ebe6 Handle SwitchNode in flipEmptyThen method 2020-10-26 13:57:34 +01:00
Andrea Gussoni ced4f1a6a8 [TILING] Fix NDuplicates counting
Count the number of duplication (needed later in the `Mark` pass) right
before the AST generation phase, where the `RegionCFG` will be destroyed
by the tiling matching.
2020-10-26 13:57:17 +01:00
Andrea Gussoni b52206cb68 [TILING] Implement tiles creation
Now we implement correct tiles creation, and we handle correctly handle
different situations were inlining is present
2020-10-26 13:56:57 +01:00
Andrea Gussoni bee02ee5d1 [EDGEINLINE] Change findReachableNodes interface
Change the interface of the `findReachableNodes` helper function, so
that now accepts arguments passed by pointer instead of by reference.
Also, the helper function now does not accept a `nullptr` `Source`
parameter.
2020-10-26 12:17:20 +01:00
Andrea Gussoni 24712518b3 [EDGEINFO] Implement EdgeInfo for inlining info
The `Successors` and `Predecessors` field on the `BasicBlockNode` are
now promoted from being a `std::pair` composed by the pointer to the
successor and the set representing the cases, to a pair between the
pointer to the successor and a new struct called `EdgeInfo`.

This struct is used to contain both the information about the cases, the
information representing whether and edge is inlined or not, and
possibly more information in the future.
2020-10-26 12:16:55 +01:00
Alessandro Di Federico 5791429f91 ABIIR: prune on finalization
Under certain conditions, we ended up having code in the ABI IR which
was not reachable. This was due to the fact that a certain instruction
was initially detected as an indirect call, triggering inclusion in the
function of the fallthrough code, and then as a return, which has no
successors within the function.

This commit simply prunes the ABI IR in the finalization method.
2020-10-24 17:40:54 +02:00
Alessandro Di Federico 393508d92b Drop superflous -fno-rtti flags 2020-10-22 14:36:27 +02:00
Alessandro Di Federico cfaa453253 revng_add_analyses_library: fix CMake package name 2020-10-22 14:36:27 +02:00
Alessandro Di Federico 0e4c4aad59 Make --use-debug-symbols the default 2020-10-21 10:34:34 +02:00
Pietro Fezzardi 6313b3229a Decompiler: fix detection of revng-c include file.
This commit fixes the detection of the revng-c include file in build
directory, using the PathList facility provided by revng.
Before this commit, running revng-c from build directory failed to
properly identify the revng-c include if it was not already installed
but only available in the build directory itself.
2020-10-12 11:42:06 +02:00
Pietro Fezzardi 05e34ef6f9 Add functions to get installed resource files 2020-10-05 14:09:53 +02:00
Antonio Frighetto 11e9203de9 StackAnalysis: storing Type in copy() method
`FunctionType::Values Type` was not copied when returning an `IFS`
object. This issue was addressed by adding `Type` to `Result` as well.
2020-10-01 18:17:53 +02:00
Pietro Fezzardi a94371cca2 EnforceABI: promote CSV in ConstantExprs casts
EnforceABI promotes global variables representing parts of the CPU
states to arguments and return values of isolated functions.

This commit enables the promotion of CSV that are used in isolated
functions only indirectly, through `ConstantExpr`s casts.
2020-10-01 18:17:53 +02:00
Alessandro Di Federico 60fdcbc66a Whitespace changes 2020-10-01 17:40:17 +02:00
Pietro Fezzardi 927dab517a Run RemoveNewPCCalls only on isolated functions 2020-09-28 10:42:13 +02:00
Alain Carlucci 3cafe56223 MetaAddress::fromString: fix error handling
StringRef::getAsInteger() returns true on error; false on success. This
commit fixes the off-by-not.
2020-09-14 17:19:14 +02:00
Pietro Fezzardi 66243838c8 Allow decompiling functions called bb.main
They were disabled before this commit, to work around some limitation of
an old benchmark suite.
2020-09-11 18:29:37 +02:00
Andrea Gussoni 50f59b0eb9 Move ReachabilityPass to tests folder
Move the `ReachabilityPass` library to the `tests` folder, the only
place where it is used, and change it from static library to dynamic
library.
2020-09-09 11:16:50 +02:00
Alessandro Di Federico cbe36d5267 FunctionIsolation: enable/disable safety checks 2020-09-04 23:53:00 +02:00
Alessandro Di Federico ae3c800109 Implement MetaAddress::{from,to}String 2020-09-02 18:21:07 +02:00
Antonio Frighetto 76a6403ebd FunctionIsolation: drop ExceptionFlag
ExceptionFlag has been superseded by proper use of stack unwinding.
Our custom personality routine has been replaced with the GNU GCC
personality one.
2020-08-03 22:11:06 +02:00
Pietro Fezzardi 3286789a9e SwitchNode: fix embedding of original BasicBlock
Before this commit, the original llvm BasicBlock was not embedded
properly in the GHAST SwitchNodes. This caused problems and crashes in
decompilation.

This commit SwitchNode constructors so the that the BasicBlock properly
reaches the GHAST and it is printed correctly by the decompiler.
2020-07-23 18:51:15 +02:00
Pietro Fezzardi 6d10120e2e Decompiler: fix emission of code before branches
Before this commit, the C statements before an IfNode or a SwitchNode
were not guaranteed to be emitted if they were not involved in the
computation of the branch condition.

This commit fixes this problem.
2020-07-22 17:27:02 +02:00
Pietro Fezzardi fc98fc69f5 Fix detection of isolated functions using metadata 2020-07-22 17:27:02 +02:00
Pietro Fezzardi 1895a2de3e CDecompilerPass: fix detection of isolated funcs 2020-07-22 17:27:02 +02:00
Pietro Fezzardi f77b904d2a CDecompilerPass: remove dead code 2020-07-22 17:27:02 +02:00
Pietro Fezzardi e34dbe1b70 Add RemoveNewPCCallsPass
This pass removes all the calls to `newpc`.
This pass needs to run before the DLA and before the decompilation pass.
2020-07-20 19:02:20 +02:00
Pietro Fezzardi 2be51e97cd RemovePCStoresPass: fix return of runOnFunction 2020-07-20 19:02:20 +02:00
Pietro Fezzardi bbbe537b18 RemovePCStoresPass: prevent removing self loops 2020-07-20 19:02:20 +02:00