Commit Graph

838 Commits

Author SHA1 Message Date
Alessandro Di Federico e23656fa5f MakeSegmentRef: ignore 128-bit integer constants 2022-08-08 16:22:14 +02:00
Alessandro Di Federico d9d45fa79b ModelToHeader: fake functions no longer exist 2022-08-08 16:22:14 +02:00
Alessandro Di Federico 662cbfda84 Minor changes 2022-08-08 16:22:14 +02:00
Antonio Frighetto e06f9841ed DLA/Frontend: support Segment.Type struct already filled
Avert DLA's middle-end from performing optimizations by
making new segment nodes point placeholder nodes.
2022-07-29 11:05:22 +02:00
Pietro Fezzardi 7948d8ce56 MakeModelGEPPass: ignore callees of indirect calls 2022-07-29 09:24:21 +02:00
Antonio Frighetto 19d7f8b2c9 Late decompilation: support model::Segment
Backend and InitModelTypes now handle the opaque `segmentRef` marker.
2022-07-19 13:53:21 +02:00
Antonio Frighetto 19dd1a34dd OperatorPrecedenceResolutionPass: add segmentRef 2022-07-19 13:52:13 +02:00
Antonio Frighetto a7ddddce92 DLA: recover model::Segment type
DLA now handles `segmentRef` opaque function calls.
2022-07-19 13:51:06 +02:00
Antonio Frighetto 9a08671dae DuplicateReferences: support segmentRef call 2022-07-19 13:49:58 +02:00
Antonio Frighetto d9bc64b29d Introduce MakeSegmentRefPass
A simple pass that scans constant expressions and literals and
replaces them with opaque calls so that they can be easily dealt
with by the Backend, in an attempt of emitting better-looking
decompiled code.
2022-07-19 13:48:50 +02:00
Antonio Frighetto 0ca87e8840 ModelHelpers: drop createEmptyStruct
`createEmptyStruct` has been upstreamed into revng.
2022-07-19 13:47:44 +02:00
Pietro Fezzardi 7d70881060 VMA: restructure getAcceptedColors
Now the two cases (with and without Model) are more clearly separated,
allowing for e.g. special handling of Function arguments in the future.
2022-07-18 18:33:29 +02:00
Pietro Fezzardi cecb02f3da Move getAcceptedColors where it's used 2022-07-18 15:37:31 +02:00
Alvise de Faveri c5e24053a7 Run VMA during InitModelTypes 2022-07-18 15:37:31 +02:00
Alvise de Faveri 52ae6595ad VMA: Migrate VMA to VMAPipeline
Add an engine for running VMA in different modes. User can:
- Decide how to initialize the colors (e.g. from the Model or from
  the LLVM IR)
- Decide what to do with the final TFG obtained by VMA
- Decide whether or not the Mincut algorithm should run
2022-07-18 15:37:31 +02:00
Alvise de Faveri 06e2f16e93 VMA: Make TypeFlowNode members private
Candidate colors, accepted colors and content are now accessible
only with setters and getters. In this way, we can check that
the Candidates are always a subset of the Accepted colors.
2022-07-18 15:37:31 +02:00
Alvise de Faveri a788a5ba62 Add helpers for inferring model types from the IR
1. Add a common helper to traverse ModelGEPs (`traverseModelGEP`)
2. Add a centralized way to deduce the model type of values that
   have strong model information attached to them (e.g. isolated
   functions and ModelGEPs)
3. Add a similar helper for deducing formal types of operands in known
   cases
2022-07-18 15:37:31 +02:00
Alvise de Faveri 490a09e8c1 Add Marker tag to Parentheses 2022-07-15 17:17:04 +02:00
Alvise de Faveri 557b43d525 Never include RecursiveCoroutine-coroutine.h 2022-07-15 17:17:04 +02:00
Alvise de Faveri cbeb006e11 Backend: Check that AddressOf is never a cast 2022-07-15 17:17:04 +02:00
Alvise de Faveri c2481aeb7b Support: Add deserializeFromLLVMString
Instead of having `paseQualifiedType` and `parseAndDeserialize`,
we now have a single function that is symmetric to
`serializeToLLVMString`.
2022-07-15 17:17:04 +02:00
Alvise de Faveri c9930528ee ModelGEP: Fix pointee type in makeBestGEPArgs 2022-07-15 17:17:04 +02:00
Giacomo Vercesi 1f69e58af8 DecompileFunction: Add indentation to C code
Add proper indentation to the generated C code with the use of
mlir::raw_indented_ostream
2022-06-28 11:26:41 +02:00
Alvise de Faveri d98db76ce1 IRCanonicalization: Add DuplicateReferences pass
This pass adds robustness to the IRCanonicalization pipeline. It
ensures that no reference opcode has more than one use.
2022-06-28 10:30:32 +02:00
Alvise de Faveri be6b35bbbc Marker: Check that we never mark references 2022-06-28 10:30:10 +02:00
Alvise de Faveri f3b2bf2e2d IRCanonicalization: Remove early-cse 2022-06-28 10:29:54 +02:00
Alvise de Faveri 2ffa537605 IRCanonicalization: Add Copy()
Use the `Copy` opcode to substitute load instructiobs.
2022-06-28 10:28:38 +02:00
Pietro Fezzardi d9d9294fe5 MarkAssignment: fix taint set and aggregate types 2022-06-28 10:28:08 +02:00
Alvise de Faveri fefe460ae4 Add parentheses logic for reference opcodes 2022-06-28 10:27:52 +02:00
Alvise de Faveri 6b258c83a1 IRCanonicalization: Fold ModelGEP(AddressOf())
- `FoldModelGEP` folds `ModelGEP(AddressOf())` into `ModelGEPRef`
- `RemoveRefDeref` remove `ModelGEPRef`s with no arguments
2022-06-28 10:26:50 +02:00
Alvise de Faveri 123a1777cd IRCanonicalization: Add RemoveLoadStore pass 2022-06-28 10:25:49 +02:00
Alvise de Faveri f7866ddd85 IRCanonicalization: Add MakeLocalVariables pass 2022-06-28 10:24:48 +02:00
Alvise de Faveri da46b38644 Backend: Various improvements to variables declaration 2022-06-28 10:24:18 +02:00
Alvise de Faveri 221b8f74d9 Add reference semantics to stack opcodes
`revng_stack_frame` and `revng_stack_args` are treated as returning
a reference, and are always followed by an `AddressOf` call.
2022-06-28 10:23:45 +02:00
Alvise de Faveri ad524a4d4d ModelGEP: Return the size of the gepped field
ModelGEP calls in LLVM IR now return an integer that has the same
size of the field being addressed by the ModelGEP.

AddressOf calls, instead, can accept any integer size as argument but
always return a pointer-sized integer.
2022-06-28 10:14:10 +02:00
Alvise de Faveri f010aea785 ModelGEP: Don't generate index-less GEPs 2022-06-28 10:13:37 +02:00
Alvise de Faveri a31fd8587d AssignmentMarker: Handle variables scoping
If we find values to be used outside their scope, we need to always
mark them for assignment, so that they have a dedicated variable that
is declared in the right scope. To do this we:

1. Export the logic that decides if a value needs a top-scope variable
in a public header, to be used by both `VariableScopeAnalysis` and
`MarkAssignments`.
2. Add the `HasUsesOutsideBB` reason for assignment markers
2022-06-28 10:13:07 +02:00
Alvise de Faveri a1ae60dc77 IRCanonicalization: Add RemovePointerCasts pass 2022-06-28 10:12:52 +02:00
Alvise de Faveri de334a92e9 Backend: Make IntToPtr and PtrToInt transparent 2022-06-28 10:12:22 +02:00
Alvise de Faveri fa68b56573 Add ReadsMemory and WritesMemory Tags
Add `ReadsMemory` and `WritesMemory` Tags and restructure the
logic that decides whether two instructions are interfering
as follows:

1. Consider `Store`s and anything with a `WritesMemory` tag as
   having side effects
2. Consider all the `TaintSet` of an instruction when deciding
   if two instructions interfere
3. Consider both `ReadsMemory` and `WritesMemory` Tags when
   deciding interference
2022-06-28 10:11:06 +02:00
Alvise de Faveri e05972bd88 Make ref opcodes ReadOnly and InaccessibleMem
Add `ReadOnly` and `InaccessibleMemOnly` attributes to the following
functions:

- `revng_stack_frame`
- `revng_call_stack_arguments`
- `ModelGEP`
- `AddressOf`

This prevents `CSE` from grouping together any of these calls, while
still enabling `DCE` to remove calls that are not used.
2022-06-23 11:23:34 +02:00
Alvise de Faveri 66c243c46d Backend: Don't emit "undef" when logging
Since the InlineLogger is emitted inside a `/* */` comment, we should
not emit the undef comment there.
2022-06-23 11:23:34 +02:00
Pietro Fezzardi 1b1198ae5f PromoteInitCSVToUndef now removes init_* calls 2022-06-22 15:21:02 +02:00
Antonio Frighetto 97e79783ae Backend: handle Parentheses and ModelCast markers
`DecompileFunction` now handles the opaque `parentheses` and
`ModelCast` markers as part of beautifying the decompiled code
with proper parenthesized expressions. Should OPRP not be enabled,
we fallback to the case in which parentheses are always emitted.
2022-06-15 10:28:50 +02:00
Antonio Frighetto cd65fd1554 Introduce OperatorPrecedenceResolutionPass
A simple pass that maps LLVM IR instructions to C operators,
taking into account their precedence and associativity to
emit nice-looking parenthesized expressions.
2022-06-15 10:28:50 +02:00
Antonio Frighetto 4a045cce53 Introduce MakeModelCastPass
A pass that strips the casts off from some instructions, including
`ModelGEP`s, general function calls, return and store ones, and
embeds the cast into new dedicated `ModelCast` function calls.
2022-06-15 10:28:50 +02:00
Pietro Fezzardi 8b812680ea DLACollapsSingleChild: push padding to parent 2022-06-14 12:51:48 +02:00
Pietro Fezzardi af760942e7 DLATypeSystem: add API to move edge target 2022-06-14 12:51:48 +02:00
Pietro Fezzardi 89734f6208 DLA: add pointer placeholders to model types
This commit adds placeholder pointer nodes to the DLA graph during
initialization, to point to nodes that represent model types whose size
should not altered during the Middleend.
2022-06-14 12:51:48 +02:00
Pietro Fezzardi ad81bc7020 Enable addtional compilation warnings
These warnings are not enabled by default with -Wall nor with -Wextra.
2022-06-14 12:48:54 +02:00