Commit Graph

2939 Commits

Author SHA1 Message Date
Alain Carlucci f1808c9db6 TupleTree: extend FOR_EACH up to 16 arguments
This commit extends the support for the FOR_EACH macro used in
INTROSPECTION_NS to allow serialization of structs with more than
5 entries. Now it supports up to 16 entries.
2021-02-01 11:03:53 +01:00
Alessandro Di Federico 4982ba6922 KeyedObjectContainers: ensure serializability
This commit fixes a couple of bugs preventing SortedVector and
MutableSet from being serialized.
Also, it introduces minimal testing for serialization.
2021-01-28 17:45:14 +01:00
Antonio Frighetto 99274f1a41 GCBI: create wrappers to support old and new PM
The GeneratedCodeBasicInfo class has been disentangled in order to
create wrappers to support both the legacy and the new pass manager.
2021-01-28 17:03:31 +01:00
Antonio Frighetto eacc0b76b2 Refactor GCBI
Changes include:
- `getFunctionCall` has been moved in IRHelpers.h
- `getFallthrough` and `getFunctionCallCallee`
  have been simplified and added in IRHelpers.h (their old versions
  have been removed respectively from FCI.h and revng.h)
- `FCI::getCall` and `FCI::isCall` have been removed
  due to redundancy with `getFunctionCall`.
2021-01-28 17:03:30 +01:00
Antonio Frighetto 2283e0a4e7 Move isMarker-related helpers in IRHelpers.h 2021-01-28 17:02:17 +01:00
Antonio Frighetto 29ee916559 FCI: drop findPostDominatedCall and cfg
Unmaintained code has been removed.
2021-01-28 16:03:02 +01:00
Massimo Fioravanti 8ba9930638 Invert inheritance of GenericGraph nodes
GenericGraphs no longer require CRTP.
2021-01-27 19:46:53 +01:00
Alessandro Di Federico b544e214b8 ProgramCounterHandler: CSVs are internal
This commit fixes a bug that lead to be unable to instantiate from a
`Module` `ProgramCounterHandler`. The reason for this was that
`ProgramCounterHandler` was using `Module::getGlobalVariable` which, by
default, ignores variables with internal linkage.
2021-01-27 19:46:53 +01:00
Alessandro Di Federico 38031f2f8a Import preliminary model
This commit imports:

* support for (de-)serializing tuple-like objects in YAML
* the Model data structure
* the {Load,Serialize}ModelPass
2021-01-27 19:46:53 +01:00
Alessandro Di Federico 28cb935d39 ZipMapIterator: handle dishomogeneous containers
ZipMapIterator can now handle containers of different type, as long as
their keys are comparable.
2021-01-27 19:46:52 +01:00
Alessandro Di Federico 8aab914037 Import MutableSet and SortedVector
These data structures are substitutes for a `std::map<Key, Value>` where
`Key` is embedded in `Value`. Their main goal is to be serializable in a
YAML sequence while preserving the order enforced by the key.

`MutableSet` is implemented using a map.
`SortedVector` is implemented using a sorted vector.
2021-01-27 19:46:52 +01:00
Alessandro Di Federico e72bcf796f Simplify MetaAddress::operator== 2021-01-26 18:42:10 +01:00
Alessandro Di Federico 7a560adbfa MetaAddress: drop std::less specialization 2021-01-26 18:42:10 +01:00
Alessandro Di Federico 6359edebb7 GenericGraph: Node::has{Successors,Predecessors} 2021-01-26 17:44:21 +01:00
Alvise de Faveri 9eb9e9b1a1 ADT: fix neighbor constness for GenericGraph
Problem:
1. `ForwardNode::getConstNeighbor` returns a reference to a non-`const`
    object, but the referenced pointer is `const`
2. `FowardNode::toNeighborRange` checks if the type of the argument is
const, but since `Successors` is not declared const the resulting
`toNeighborRange(Successors)` is never executed in the const version

Solution:
1. Make `getConstNeighbor()` return a reference to a `const` pointer
2. Explicitly declare a separate `toNeighborRange()` function which
returns a `const_child_iterator` and remove the template parameter
2021-01-26 17:41:58 +01:00
Alessandro Di Federico 54ea92cfec Introduce GCBI::programCounterHandler 2020-12-31 14:37:53 +01:00
Alessandro Di Federico d3247870f0 Reorganize ProgramCounterHandler construction 2020-12-31 14:37:53 +01:00
Pietro Fezzardi e1b283b0b6 Add RecursiveCoroutine headers and tests
RecursiveCoroutines are a facility intended to be used as-drop in
replacement of recursive functions.

They provide the following features.
- They can be written almost as regular recursive functions,
  with 4 caveats.
  1. A recursive coroutine that returns a type `T`, needs to be declared
     to return a `RecursiveCoroutine<T>`.
  2. Inside the body of a recursive coroutine, when recursively calling
     another recursive coroutine, the recursive call needs to be
     prepended by the new keyword `rc_recur`.
  3. Inside the body of a recursive coroutine, the `return` statement
     needs to be substituted with `rc_return`.
  4. When launching a recursive coroutine `A` from a function that is
     not a recursive coroutine, `A` needs to be called with the provided
     dedicated template wrapper `rc_run`.
     The syntax is the following `rc_run(A, arg0, arg1, ...)`.
     This is necessary to enable swapping off recursive coroutine and
     fall back to regular recursion for debug.
     See below for how to do it.
- Unlike regular recursive functions, they don't use the system stack
  for recursion. They use a custom heap-allocated stack to manage
  recursion. This makes them more robust for implementing recursive
  functions that manipulate user-defined input, because they are much
  less likely to trigger stack overflow.
- They can be turned off compiling with
  `-DDISABLE_RECURSIVE_COROUTINES`, falling back to regular recursion,
  for debug purposes.
- They support both direct and indirect recursion, i.e. a recursive
  coroutine A can recursively call itself, or it can recursively call
  another recursive coroutine B, which in turns recursively calls A.
2020-12-29 16:15:31 +01:00
Alessandro Di Federico 3c58c7441b Whitespace changes 2020-12-29 16:14:49 +01:00
Pietro Fezzardi 5f90f7addb [TypeShrinking] Locally declare WorklistItem 2020-12-23 02:37:17 +01:00
Pietro Fezzardi 826033a63f [TypeShrinking] Fix comparisons of WorklistItem 2020-12-23 02:34:45 +01:00
Qian Matteo Chen 61c7f4cf0f [TypeShrinking] Fix use after destructor 2020-12-23 02:23:32 +01:00
Qian Matteo Chen 04085ecd99 [TypeShrinking] Fix styling issues 2020-12-23 02:23:00 +01:00
Qian Matteo Chen 007119af91 [TypeShrinking] Fix comment capitalization 2020-12-23 02:21:56 +01:00
Qian Matteo Chen 8d05cfc440 [TypeShrinking] Visit extremal labels first 2020-12-23 02:21:25 +01:00
Qian Matteo Chen 232c1596ce [TypeShrinking] Split passes in two 2020-12-23 02:20:21 +01:00
Qian Matteo Chen 0893cd824f [TypeShrinking] Handle rooted graphs 2020-12-23 02:19:49 +01:00
Qian Matteo Chen d085560674 [TypeShrinking] Sort nodes using RPOT for MFP 2020-12-23 02:16:07 +01:00
Qian Matteo Chen d6b4bcc185 [TypeShrinking] Allow personalized GraphTrait 2020-12-23 02:13:09 +01:00
Qian Matteo Chen bb8e98bfcb [TypeShrinking] Refactor using ranges .at() 2020-12-23 02:10:16 +01:00
Qian Matteo Chen b0542bbb64 [TypeShrinking] Use concepts in MFP implementation 2020-12-23 01:54:10 +01:00
Qian Matteo Chen 5ee2cdf004 [TypeShrinking] Refactor code
- Use uint32_t
- Define Top as uin32_t max
- Fix copyright notice
- Use using namespace llvm in cpp files
- Change hasSideEffects to isDataFlowSink
- Outline isAddLike
- Add option to ignore certain analysis results
2020-12-23 01:38:52 +01:00
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
Alessandro Di Federico c6d0ce9dec Don't use RPOT for DisjointRanges
Sorting the BasicBlocks on which DisjointRanges works is detrimental for
performance.  Using a random order takes less time. This is due to the
fact that the number of BasicBlocks to analyze is significantly smaller
than the whole list of BasicBlocks.
2020-11-23 14:52:46 +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