Commit Graph

76 Commits

Author SHA1 Message Date
Ivan Krysak 79964eac74 Avoid ' misuse in error messages and comments 2025-04-17 16:41:21 +02:00
Ivan Krysak 61f2c122b1 Canonicalize: adopt helper registry 2025-04-17 11:19:17 +03:00
Ivan Krysak 93e44460bf ptml::CTypeBuilder: drop getPlainTypeName 2025-04-17 11:19:17 +03:00
Pietro Fezzardi f13e919678 MakeModelCastPass: allow casting non-scalars
Before this commit, MakeModelCastPass was assuming that it would never
try to emit casts involving non-scalars, which don't compile in C.

From now on, the semantic of ModelCast in understood to be bitcast, and
it's valid also when involving non-scalar types.
This may cause the emission of ModelCast that are then emitted in C as
casts that don't compile.
Since the LLVM-based decompilation pipeline is deprecated in favor of
the clift-based decompilation pipeline, this is now considered
acceptable, as long as the C backend prints a warning and a comment on
the broken cast.
2025-03-05 14:47:46 +01:00
Pietro Fezzardi 7f7c38fa35 MakeModelCastPass: postpone arguments computation
This commits reworks MakeModelCastPass so that the computation the of
arguments for the invocation of a ModelCast are now computed later: not
when we decided that a cast must be emitted, but right before we emit
the call.

This simplifies the code and lays the groundwork for relaxing some
assertions later.
2025-03-05 14:47:46 +01:00
Pietro Fezzardi bd1f2f3422 MakeModelCastsPass: add model::Binary * member
This field is initialized at the entry of the `runOnFunction` method, to
avoid passing it throughout a bunch of methods as explicit argument.
2025-03-05 14:47:46 +01:00
Pietro Fezzardi 556e14dfb1 MakeModelCastsPass: drop unused member 2025-03-05 14:47:46 +01:00
Pietro Fezzardi f5b1622a0b RemoveLoadStore: handle not areMemOpCompatible
This commit adds support in RemoveLoadStore for load/store instructions
such that the pointee of their pointer operand on LLVM is does not match
the pointee type on the Model (i.e. not areMemOpCompatible).

These cases are handled by emitting a Copy/Assign whose address operand
is a ModelGEP with a type matching the LLVM pointee, so that when these
are emitted as expressions in C the dereference operation is guaranteed
to access memory at a size that is compatible with LLVM, which represent
the semantic of what happens in the binary.
2025-03-05 14:47:46 +01:00
Pietro Fezzardi 95d44d254b SwitchToStatement: emit copies on each use
Before this commit, SwitchToStatement, in Legacy mode, was evaluating
the injection of Copy instruction an all uses at the same time, while
it's perfectly feasible, depending on how the surrounding IR is shaped,
that calls to Copy are only necessary on some of the uses.

This commit fixes, that evaluating the emission of a call to Copy on
each Use separately.
2025-03-05 14:47:46 +01:00
Ivan Krysak 705e4a5955 auto [...] -> auto &&[...] 2025-02-13 13:10:51 +02:00
Ivan Krysak 45e01ae0d2 Introduce a pipe for embedding statement comments 2025-02-13 13:09:50 +02:00
Ivan Krysak 929cb4b35b Minor improvements 2025-02-13 13:09:50 +02:00
Pietro Fezzardi 9e0f015eb8 Drop old conversion from LLVM to MLIR
The previous conversion from LLVM to MLIR was translating plain LLVM IR
to LLVM MLIR Dialect, as a preliminary step for further conversion from
LLVM MLIR Dialect to Clift.
This is not how things are expected to work anymore, so the old code is
now dead and can be removed.
2025-01-29 23:55:49 +01:00
Pietro Fezzardi 391f5c780f SwitchToStatements: use LocalVariableBuilder 2025-01-29 23:55:49 +01:00
Pietro Fezzardi e9528f4647 Fix getCopyType function type
This commit changes the prototype of getCopeType, so that it now takes 2
arguments.
1. The llvm::Type returned by the Copy function. This can be any scalar
   llvm::Type.
2. The llvm::type of the argument representing the reference to the
   value being copied. This should be a pointer-sized integer, where
   pointer-sized means with the same size of a pointer in the
   architecture in the input binary.

The second argument is not strictly necessary for now, because the whole
decompilation framework expects a binary with a single architecture,
hence a well defined unambiguous pointer size.
This will be used fully only when we start supporting multiple binaries.
Whenever that happens, if we haven't already fully dropped the Copy
helper function we will have to update the associated
OpaqueFunctionsPool to a type pair as key: the return type and the type
of the argument.
2025-01-29 15:17:15 +01:00
Alessandro Di Federico 36edf810ef Introduce support for function pointers 2025-01-28 15:20:45 +01:00
Alessandro Di Federico 143c315196 Merge revng-c into revng 2024-11-21 10:50:55 +01:00
Alessandro Di Federico 8cd4ee3b59 Move Kinds.h to revng 2024-11-04 15:09:56 +01:00
Alessandro Di Federico 4e670ac8e6 Either link revngcSupport or revngSupport 2024-11-04 15:09:56 +01:00
Alessandro Di Federico 2e4f4d09b9 Remaining FunctionTags have been moved to revng 2024-11-04 15:09:56 +01:00
Alessandro Di Federico e239e18b0c Adopt FunctionPoolTag 2024-11-04 15:09:56 +01:00
Alessandro Di Federico 800340d6e8 IRHelpers.cpp has been moved to revng 2024-11-04 15:09:56 +01:00
Alessandro Di Federico 36e2faad3d Introduce -Wunreachable-code-break 2024-10-31 17:19:55 +01:00
Ivan Krysak 1a35cbcb77 Introduce PTMLCTypeBuilder 2024-10-15 10:45:13 +03:00
Ivan Krysak f523edc863 Pipeline: toString -> locationString 2024-10-15 09:13:28 +02:00
Ivan Krysak 8288bd68d2 PTMLCBuilder: rename into ptml::CBuilder 2024-10-15 09:13:28 +02:00
Alessandro Di Federico 5d0d4005c5 s/Ctxt?/Context/g 2024-09-27 10:35:10 +02:00
Alessandro Di Federico 8a5ae5f9c1 s/ExecutionContext &Ctx/ExecutionContext &EC/g 2024-09-27 10:35:10 +02:00
Alessandro Di Federico 8706fd8459 Initialize pointers to nullptr 2024-09-27 10:35:10 +02:00
Alessandro Di Federico 9c99ac33ac s/serializeToLLVMString/toLLVMString/ 2024-09-27 10:35:10 +02:00
Alessandro Di Federico 08e1dc0f05 Drop no-op Pipe::checkPrecondition 2024-09-27 10:35:10 +02:00
Alessandro Di Federico ca99bbbb66 Adopt toString() 2024-09-26 17:51:08 +02:00
Alessandro Di Federico e1f46264f8 Ensure every pipe commits what it should 2024-09-26 17:51:07 +02:00
Ivan Krysak b4a6682a3e OperatorPrecedence: introduce forced parentheses 2024-09-10 11:49:42 +03:00
Ivan Krysak 5666b063cc OperatorPrecedence: handle logical or and and 2024-09-10 11:49:42 +03:00
Ivan Krysak 17cc3e497f OperatorPrecedence: rework precedence encoding 2024-09-10 11:49:42 +03:00
Ivan Krysak d5c7365f4f OperatorPrecedence: switch to cppreference scale 2024-09-05 10:18:55 +03:00
Alessandro Di Federico 0cb3eedd37 Do not use CallBase::getCalledFunction
Use our wrapper, which does not return nullptr if the `FunctionType`s do
not match.
2024-08-07 15:40:56 +02:00
Ivan Krysak 95cfa4785f MakeModelCastPass: remove an obsolete if branch 2024-06-27 11:07:02 +02:00
Ivan Krysak 74f56bcd93 Introduce a broken debug info removal pass 2024-06-27 11:07:02 +02:00
Ivan Krysak 31edf40695 ImplicitModelCastPass: better constness handling 2024-06-27 11:07:02 +02:00
Ivan Krysak 5ed120cdc9 ImplicitModelCastPass: extend logging 2024-06-27 11:07:02 +02:00
Ivan Krysak 94a0ad6b93 Adopt reworked model::Type 2024-06-27 11:07:01 +02:00
Ivan Krysak 504928d886 Minor improvements 2024-06-27 11:07:01 +02:00
Ivan Krysak c2b4fb70bb Model: rename TypePath to DefinitionReference 2024-06-27 11:07:01 +02:00
Ivan Krysak 3705906074 Model: rename Type into TypeDefinition 2024-06-27 11:07:01 +02:00
Alessandro Di Federico 5186a58053 s/FunctionMetadata/ControlFlowGraph/ 2024-06-18 17:56:24 +02:00
Alessandro Di Federico a6759b9231 LLVMIRForMLIR: name structs with growing numbers 2024-06-18 17:56:24 +02:00
Alessandro Di Federico 3dc8cf5e84 Minor changes 2024-06-18 17:56:24 +02:00
Pietro Fezzardi 7caa5eda96 PeepholeOptimizationPass can reorder instructions 2024-06-06 10:43:17 +02:00