Commit Graph

390 Commits

Author SHA1 Message Date
Pietro Fezzardi 444663ed94 RestructureCFG: refactor logging of MetaRegions 2021-02-18 11:59:04 +01:00
Pietro Fezzardi 2998494d18 RegionCFG: use meaningful names for dummy nodes
This helps debugging.
2021-02-18 11:59:03 +01:00
Alvise de Faveri 495e725d14 ADT: Enclose RPOExt in the llvm namespace 2021-02-17 16:50:32 +01:00
Pietro Fezzardi f01fe2ec7a MarkForSerialization: fix needsVarDecl 2021-02-05 15:45:11 +01:00
Pietro Fezzardi 904aab0f6f LayoutTypePtr: drop friend struct std::less
This was necessary before defaulting operator<=>, now it's not necessary
anymore.
2021-02-03 12:02:25 +01:00
Pietro Fezzardi 3f1ee6ea64 Stub of DLA integration in Clang AST emission 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 088015e11c Forward SCEV and DLA results to decompilation 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 9d1d6afe6e MarkForSerialization: extract into its own Pass 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 2ff7044bb9 Decompiler: forward-declare types coming from DLA
This commits enable the emission of rich types associated with function
signatures. This types are forward-declared in the decompiled C code
before the definition of each decompiled function that uses them.

The types we emit for now are the types that the DLA is able to compute
(if any) for the return values and the arguments of the function.

Such types are not yet used in the body of the function, nor in the
function declaration. These are the next steps to come.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi 476064d855 [DLA] kill structural deduplication of Layouts
Before this commit, the MakeLayout step of the DLA used to deduplicate
structurally equal Layouts. This has turned out to be wrong when going
forward with the emission of types in C.
Being able to tell apart two different types that are structurally equal
is important for the emission of C types. Throwing this information away
with deduplication is bad. This commit disables such deduplication.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi e0f9401ff8 ADT: add HeterogeneousPtrCompare template class
This is a utility class useful to make std::set<std::unique_ptr<T>>
searchable with raw pointers, by using
std::set<std::unique_ptr<T>, HeterogeneousPtrCompare<T>> instead.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi d6c8214d52 Decompiler: improve handling of command line flags
Handling of command line options that specify paths for output files
have been improved in the following ways:
- If the CDecompilerPass is not default-constructed, it already has a
  reference to the stream where outputs must be written. In this case,
  it is wrong to use a command line option to specify the output
  directory. If this happens the program is now able to detect it and to
  terminate with an error.
- If some of the specified paths is not found or has the wrong
  permission, the program fails early.
- On program failure because of one of the above safety checks, the
  program terminates with an informative error message.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi 1e825a8201 Create IRASTTypeTranslator class
This class handles the creation of type declarations in clang's AST, and
holds the relationships between llvm Types and Values with those clang's
type declarations.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi cbbbdf660f [DLA] propagate DLA results to CDecompilerPass 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 44564c2ba7 [DLA] export layouts to DLAPass 2021-02-02 11:23:53 +01:00
Pietro Fezzardi c553965b62 CDecompilerPass: addUsedIfAvailable<DLAPass>() 2021-02-02 11:23:53 +01:00
Pietro Fezzardi dda2b5aaa0 [DLA] Add skeleton for DLAPass 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 7ff39039a8 Add Liveness Analysis 2021-02-02 11:23:53 +01:00
Pietro Fezzardi a96f98821c [DLA] Add AdjustStackPointerPass FunctionPass
Add a pass that computes the lowest negative offset that is summed in
each isolated function to the local stack pointer returned by a call to
revng_init_local_sp (previously added by PromoteStackPointerPass).
After the computation, all the accesses relative to the stack pointer
are recomputed as if the stack pointer was lowered by the computed
amount.

This is useful to enable the DLA to easily recover layouts that are
placed at negative offsets from the stack pointer.
The reason is that the DLA in its current form does not handle negative
offsets, but at the same time negative offsets are important to recover
the layout of the local variables on the stack.

This pass implicitly depends on running PromoteStackPointerPass.
If PromoteStackPointerPass did not run before the execution of
AdjustStackPointerPass, the latter doesn't do anything.

For demonstration purposes, AdjustStackPointerPass has been implemented
both with LLVM's legacy PassManager and the new PassManager.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi a31bdbd602 [DLA] Add PromoteStackPointerPass 2021-02-02 11:23:53 +01:00
Alessandro Di Federico 433d8a9ddc Update GenericGraph<DataFlowNode>
This commit updates the `DataFlowNode` data structure used in
`TypeShrinking` to be compatible with the newer version `GenericGraph`
provided by revng.

The change basically encompasses inverting the inheritance and dropping
CRTP.
2021-02-01 18:21:38 +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