Commit Graph

3168 Commits

Author SHA1 Message Date
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 ed43c2b84a func.entry: add an address field 2019-03-06 09:04:58 +01:00
Alessandro Di Federico 7db7309987 SA: Trunc is not identity
In the intraprocedural analysis of the stack analysis we implemented the
transfer function of the `Trunc` instruction as the identity function
(just as `PtrToInt` or `ZExt`). However this is not safe since `Trunc`
loses information. This lead to incorrect results in the ABI analysis.
2019-03-06 09:04:58 +01:00
Pietro Fezzardi e999665ff2 Remove unreachable blocks from isolated functions 2019-03-06 09:04:58 +01:00
Pietro Fezzardi 4fc4531403 Use nullptr instead of NULL for pointer constant 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
Pietro Fezzardi 33a8aeb64c MonotoneFramework: drop greaterThan from Lattices
All the definitions of `greaterThan` were `!lowerThanOrEqual`, and all
the uses were implicitly assuming this semantic.
However, this was confusing because in a Lattice the ordering is not
total, hence `!lowerThanOrEqual` is not equivalent to `greaterThan`.

This commit drops the `greaterThan` method altogether to avoid
confusion.
2019-03-06 09:04:58 +01:00
Alessandro Di Federico 8c49f47f26 Use DefaultInterrupt<LatticeElement> as default
In most cases, a user of MonotoneFramework does not need a
interprocedural analysis, nor an analysis whose results on
terminal labels have to be aggregated in a FinalResults.
DefaultInterrupt<LatticeElement> is designed exactly for those
cases, and is hence used as default template parameter for
MonotoneFramework.
2019-03-06 09:04:58 +01:00
Pietro Fezzardi 186b2d9a07 Rename isReturn method to isPartOfFinalResults 2019-03-06 09:04:58 +01:00
Pietro Fezzardi 08d0722bef MonotoneFramework: remove public typedef LabelRange 2019-03-06 09:04:58 +01:00
Pietro Fezzardi 4996a06517 MonotoneFramework: remove method extremalLabels
This method was unused.
2019-03-06 09:04:58 +01:00
Pietro Fezzardi a0cd9664ee Add IntersectionMonotoneSet and UnionMonotoneSet
The MonotoneFrameworkSet class had two sets of methods, one for handling
set operations on it, the other handling lattice ordering.
It also silently assumed that the lattice combine operation was the set
union, which is not true in general.

This commit decouples the set operations from the lattice operations.
This allows to provide two separate implementations of
IntersectionMonotoneSet (for which the compbine operation is the set
intersection) and UnionMonotoneSet (for which the combine operation is
the set union).
2019-03-06 09:04:58 +01:00
Pietro Fezzardi 4122f76a27 Avoid useless constructor 2019-03-06 09:04:58 +01:00
Pietro Fezzardi 6f77c27e9f CRDP: avoid useless std::move 2019-03-06 09:04:58 +01:00
Alessandro Di Federico e6928e34c1 Minor changes 2019-03-06 09:04:58 +01:00
Pietro Fezzardi 6f7d0e49c5 ASTBuildAnalysis: fix emission of short literals 2019-03-01 18:13:49 +01:00
Pietro Fezzardi 5b885d7eb4 Link libEnforceCFGCombingPass to librevng-c 2019-03-01 17:38:48 +01:00
Pietro Fezzardi a5ae26a7a9 EnforceCFGCombingPass depends on RemoveDbgMetadata
Before this change, `EnforceCFGCombingPass` was occasionally failing on
`verifyModule` if called from Caliban, with mismatches in the
`llvm.dbg.cu` debug metadata.
This metadata is a list of `DICompileUnit`, and `verifyModule` was
failing inside `verifyCompileUnits` because some of the visited compile
unit during the verify were not listed in `llvm.dbg.cu`.

One of the reasons of this problem might be that during
the enforcing we clone many things in the enforced function, and this
may cause the cloned stuff not to update the metadata accordingly.
I couldn't track down if this was caused by my misuse of LLVM's API for
cloning, of to some actual bug in LLVM.

In the end I couldn't find out the exact cause and fix it, so this
commit is a workaround. It adds a dependency on `RemoveDbgMetadata`, so
that the debug metadata causing `verifyModule` to fail are removed
before the enforcing, hence preventing things going astray during the
enforcing, and fixing the failure.

This workaround should be fine, because this is one of the last steps
before generating C code, and debug info are note serialized to C
anyway.
2019-03-01 15:55:04 +01:00
Pietro Fezzardi 84ca9f7b74 Fix computation of PHI nodes variable assignments 2019-02-26 10:36:31 +01:00
Pietro Fezzardi 3b2dac4e85 Enforce clang-format 2019-02-25 12:29:15 +01:00
Pietro Fezzardi b44c0dd71d Fix emission of negated if conditions 2019-02-25 11:58:19 +01:00
Alessandro Di Federico 72c34efc57 revng_add_analyses_library: add EXPORT_NAME 2019-02-22 11:36:36 +01:00
Pietro Fezzardi 63c8e164dd Create only a single Load for the removed PHI 2019-02-18 19:21:30 +01:00
Pietro Fezzardi 632020ab9b Properly decompile return values 2019-02-13 16:01:25 +01:00
Pietro Fezzardi 49da34f6a6 Fix print of function arguments 2019-02-13 15:27:59 +01:00
Andrea Gussoni 6e2f087583 Track IfNode condition negation
Added a method to check if the `then` and `else` branches of an `IfNode`
have been inverted.
2019-02-13 10:06:38 +01:00
Pietro Fezzardi 15bc2768d0 Fix empty and redundant scopes 2019-02-13 09:52:12 +01:00
Pietro Fezzardi e522d12d23 Properly decompile conditions of if statements 2019-02-13 09:26:57 +01:00
Pietro Fezzardi cb08b4ac31 tmp 2019-02-12 20:55:28 +01:00
Alessandro Di Federico 6ae0610e2d Force Python versions
This commit switches all scripts to Python 3, except for
`revng-merge-dynamic` which requires Python 2 due to a limitation of
pyelftools.
2019-02-12 18:40:24 +01:00
Alessandro Di Federico 53db84f7d6 s/revamb/revng/g 2019-02-11 16:09:23 +01:00
Pietro Fezzardi 188d8fbdbb Make DecompilationPass an llvm::FunctionPass 2019-02-11 15:10:27 +01:00
Andrea Gussoni 3e2751866e Improve ordering performances
The algorithm that order nodes following the (reverse)post-order now has
a complexity of NLog(N) instead of N^2.
2019-02-11 14:44:14 +01:00
Andrea Gussoni ec7f0f68e2 Disassemble switch in right order
Add the switch successor to the nested `if` tree in the right order.
2019-02-11 14:41:26 +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 c5df55dedc Expose DecompilationPass.h header for public use 2019-02-11 14:01:40 +01:00
Pietro Fezzardi f4d5fec5bc First fully functional EnforceCFGComingPass 2019-02-11 12:18:44 +01:00
Pietro Fezzardi b9d04e502c Remove unreachable blocks after RemoveSwitchPass 2019-02-11 12:18:44 +01:00
Pietro Fezzardi b436465921 Apply enforcing on AST 2019-02-11 12:18:44 +01:00
Pietro Fezzardi f0b9648d4a Remove checks that are now redundant 2019-02-11 12:18:44 +01:00
Pietro Fezzardi 1d49d61302 Fix assertion 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
Pietro Fezzardi 2b1843d898 Fix AST in EnforceCFGCombingPass 2019-02-11 12:18:44 +01:00
Andrea Gussoni 02e1b94daa Added RemoveSwitchPass
Added a new `FunctionPass` which converts `switch` instructions in a
nested chain of `if` checks.
2019-02-11 12:18:44 +01:00
Andrea Gussoni 1297f9645b Disable short-circuit simplification
Disable temporarly short-circuit simplification
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 dbffa54124 Handle check BBNode in inflate
Considering the `check` BBNode during the `inflate` procedure, and
fixing the functions handling edges and nodes successors accordingly.
2019-02-11 12:18:44 +01:00
Alessandro Di Federico d00bf31bca Reorganize the build system 2019-02-10 16:20:24 +01:00
Alain Carlucci b2629efd05 Avoid useless computations when decompiling a single function 2019-02-08 11:44:17 +01:00