Commit Graph

2366 Commits

Author SHA1 Message Date
Antonio Frighetto 9a59cee319 Introduce PromoteGlobalToLocalPass
A simple pass that promotes the CSVs to local variables.
2021-12-15 18:03:30 +01:00
Antonio Frighetto e9439a15e5 Introduce RemoveHelperCallsPass
A simple pass that removes the calls to the helpers and replaces them
with stores of an opaque value onto the CSVs clobbered by the helper.
2021-12-15 18:03:30 +01:00
Antonio Frighetto ba49937a69 Introduce RemoveNewPCCallsPass
A simple pass that removes the calls to `newpc` marker.
2021-12-15 18:03:30 +01:00
Antonio Frighetto cbd81e57d9 Improve MFP 2021-12-15 18:03:30 +01:00
Antonio Frighetto 47fa41d784 ProgramCounterHandler: add dissectJumpablePC
The new method `dissectJumpablePC` provides information about the
PC CSVs and allows not to make architecture-specific assumptions.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 4504b3d770 JumpTargetManager: move getOption in IRHelpers 2021-12-15 18:03:30 +01:00
Antonio Frighetto dc3f73c622 IRHelpers: ignore abort in getFunctionCall 2021-12-15 18:03:30 +01:00
Antonio Frighetto 8328575839 IRHelpers: refactor getPC
Dead code removal and various fixes while refactoring `getPC`.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 4a0dd2d2d6 IRHelpers: overload isCallTo and getCallTo 2021-12-15 18:03:30 +01:00
Antonio Frighetto 1d8a3281a8 GeneratedCodeBasicInfo: add purgeDomTree method
Erase element from the DominatorTree map when needed.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 5b4e4d8e84 GeneratedCodeBasicInfo: add invalidate method 2021-12-15 18:03:30 +01:00
Antonio Frighetto 34580789eb BinaryFile: add architecture-dependent fields
Add return address register and minimal final stack offset in Arch.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 4eb0f3c29a IRHelpers: overload extract for int64_t 2021-12-15 18:03:30 +01:00
Antonio Frighetto b80be110ae ZipMapIterator: add support for llvm::DenseMap 2021-12-15 18:03:30 +01:00
Antonio Frighetto f1ac5e4075 Model: handle NoReturn functions in CallEdge 2021-12-15 18:03:30 +01:00
Alessandro Di Federico 96d133d72f Introduce model::FunctionAttributes 2021-12-15 18:03:30 +01:00
Alessandro Di Federico 6dd346ab04 Move GCBI.getMetaAddressMetadata to IRHelpers.h 2021-12-15 18:03:30 +01:00
Alvise de Faveri 2f4b716e6b Add Model::toString() and writeToFile()
These functions can be used in conjunction to dump the Model on a
file during a gdb session, for example:

```
(gdb)  p  writeToFile(Model->toString(), "/tmp/model.yaml")
```
2021-11-19 10:17:09 +01:00
Alvise de Faveri bda519b3e2 Add AddPrimitiveTypesPass to Decompiler
This pass is in charge of creating all the primitive types for any
of the typical sizes used for numbers.
2021-11-18 11:13:36 +01:00
Alvise de Faveri 5b8529edd5 DLA: Generate Model Types
Add `MakeModelTypes` and `UpdateFuncPrototypes` to the DLA backend:
* `MakeModelTypes` adds to the model all the types recovered by the DLA
* `UpdateFuncPrototypes` updates function prototypes in the model that
have generic return values or arguments to use the types recovered by
the DLA
2021-11-16 17:00:53 +01:00
Alvise de Faveri 4c8215fc47 DLA: Add pointers
* Changes to the `LayoutTypeSystem` graph

Pointers are identified in the TypeSystem graph as leaf nodes which
have a new type of edge (PointerEdge) that connects them to another
node of the graph. The destination of the edge represents the layout of
the pointed type.

* Changes to the Front-end

Pointer edges, and their destination nodes, are created by the DLA
front-end (`DLACreateIntraProceduralTypes`) whenever an access node has
a size that is compatible with the size of a pointer in the current
Architecture.
Successors might then be added to the newly generated node, if any,
by looking up the llvm::Value it is attached to.

* Changes to the Middle-end

Most of the DLA passes should ignore Pointer Edges, so they are modified
accordingly. Most notably, nodes that represent pointed layouts should
never be merged/pruned-off.

* Changes to the Back-end

The `TypeDeclCreationAction` of the decompiler and the `DLAMakeLayouts`
step of the DLA back-end are modified to take into account the new
information about pointers.

⚠️ There is a known issue with this version of the decompiler,
namely the fact that type loops are not detected and can cause the
emitter to enter an infinite loop.
2021-11-16 17:00:34 +01:00
Andrea Gussoni 81782fe633 generateAst: new tile for matching inlined if
We introduce a new tile, for matching if node with a single and inlined
then/else. In these case, the not inlined successor should be connected
with the tile node.
2021-11-15 12:39:17 +01:00
Andrea Gussoni 6d306ee473 generateAst: improve switch postdominator identify
We now identify the postdominator of a switchnode if one of the cases is
the successor of all the other cases nodes.
2021-11-15 12:39:17 +01:00
Andrea Gussoni 46cb2be99c generateAst: Add parent switch in SwitchBreak 2021-11-15 12:39:17 +01:00
Andrea Gussoni ce902e36b6 generateAst: generalize the switch fallthrough 2021-11-15 12:01:00 +01:00
Andrea Gussoni 6dcffcce67 generateAst: Handle switch postdominator
Handle switch nodes with all but one case edges inlined, by electing the
not inlined edge as the path conducting to the postdominator, and
avoiding parts of the graph disconnecting during the tiling procedure.
2021-11-15 11:57:36 +01:00
Pietro Fezzardi 067f2fffe1 Add ModelToHeader 2021-11-15 11:47:17 +01:00
Ivan Krysak 52f7432f1b Add model::Architecture::getPointerSize() 2021-11-08 16:17:47 +01:00
Alvise de Faveri 2e19fade43 Fix memory leak in TupleTreeKeyWrapper::clone
ConcreteTupleTreeKeyWrapper::clone() should cleanup the Target object
befor cloning, otherwise the destructor of the inner Pointer object
is never called.
2021-10-27 08:42:53 +02:00
Pietro Fezzardi c050dcb621 Handle missing model in SerializeModelPass
Before this commit, SerializeModelPass and SerializeModelWrapperPass had
hard dependencies on the passes that load the model from LLVM-IR.

This commit makes this dependency optional. When the passes for model
serialization are executed, if they see that nobody requested to load
the model, they will not try to serialize it.

This prevents them from crashing when running in pipelines that only
contain passes that ignore the model.

This is particularly beneficial because `revng opt` automatically adds
`-serialize-model` at the end of each pipeline and, before this commit,
this meant that `revng opt` could not be used for unit-testing simple
llvm passes that do not use the model.

With this commit, `revng opt` can be used for unit-tests, even on LLVM IR
with missing model.
2021-10-21 15:02:01 +02:00
Alessandro Di Federico 83f420abda Introduce dump method for model structs 2021-10-21 15:02:00 +02:00
Alessandro Di Federico eb2c3df925 Tag with MetaAddress functions and call sites 2021-10-21 15:02:00 +02:00
Alessandro Di Federico 8546a0c786 CallEdge: only indirect calls have a prototype 2021-10-21 15:01:59 +02:00
Alessandro Di Federico 89532890ed Introduce support for importing DWARF information 2021-10-21 15:01:20 +02:00
Alessandro Di Federico 3a3eea0cf5 Introduce support for dynamic functions 2021-10-21 15:01:19 +02:00
Alessandro Di Federico a023bfa7f5 Introduce ABI handling 2021-10-18 20:44:58 +02:00
Alessandro Di Federico 0dfc81da41 Minor model improvements
* Introduce some documentation for the model.
* Improve the way enums are serialized/deserialized.
* Mark certain fields of model data structures as optional.
* introduces some error messages during model validation.
2021-10-18 20:44:58 +02:00
Alessandro Di Federico 5b50a3320f Introduce error messages during model validation 2021-10-18 20:44:58 +02:00
Alessandro Di Federico d5bfb872d6 Introduce SortedVector::isSorted
This is a debug method.
2021-10-18 20:44:58 +02:00
Alessandro Di Federico 18cfbdbfe0 Whitespace and other minor changes 2021-10-18 12:39:21 +02:00
Pietro Fezzardi 032463c539 Fix handling of calls with unnamed callees 2021-10-12 09:57:30 +02:00
Alvise de Faveri 43ae7a91cb DLA: Add DeduplicateUnionFields Step
Add a step that recognizes if two subtrees of a union node are
topologically equivalent and merges them. This corresponds to removing
duplicate fields in unions.

This deduplication was prevously done while emitting layouts.

A check is inserted into DLAMakeLayouts to assert that, after
constructing unions, no union has only one child, which could be the
case if we didn't deduplicate union fields in the graph.
2021-10-06 16:37:37 +02:00
Alvise de Faveri 7e72fc4be1 DLA: Add RemoveConflictingEdges step
Add a DLA step that removes all instance-at-offset-0 edges between nodes
that already have an inheritance edge between them.
2021-10-05 18:16:21 +02:00
Ivan Krysak 6714c4cb58 Add Node::copy() and Node::move()
Those member functions are an easy way to reach the underlying node data
without affecting the edges stored by the node.
2021-10-04 14:38:42 +02:00
Pietro Fezzardi fda2b0042f Drop Beautify dependency on MarkForSerialization 2021-09-22 19:01:44 +02:00
Pietro Fezzardi ce0083a7ff Extract MarkForSerialization in separate library 2021-09-22 15:03:12 +02:00
Pietro Fezzardi a0dbea19e5 Prevent model::Type CustomNames from colliding
This commit reserves the "unnamed_" prefix for revng.
The first use of this reserved prefix is in `model::Type`s
`CustomName`s and `model::Identifier`s.
This commit also makes the `verify()` method stricter for
`model::Identifier` so that an `Identifier` whose name starts with the
reserved prefix does fails verification.
2021-09-02 14:55:47 +02:00
Pietro Fezzardi 3d38451abd Enable error checking on Model deserialization
This commit changes the `TupleTree::deserialize` method to return an
`llvm::ErrorOr<TupleTree>`, enabling users to choose their policies on
error reporting.
2021-09-02 14:42:51 +02:00
Pietro Fezzardi bae9214652 Stricten verification for model::Identifier
Now only `Identifier`s that are valid C identifiers are guaranteed to
verify.
The `fromString` factory is updated accordingly.
2021-09-02 14:42:47 +02:00
Pietro Fezzardi 48f6a60629 Fix callOnPathSteps for KeyedObjectContainer
callOnPathSteps was using linear scan search in KeyedObjectContainer.
This commit fixes it for using binary search, dramatically improving
performance in workloads that do lots of lookups.
2021-09-02 14:39:23 +02:00