Commit Graph

150 Commits

Author SHA1 Message Date
Pietro Fezzardi 80663458bb Pipeline: add loop-rotate, to match do-while loops 2024-06-06 11:27:48 +02:00
Pietro Fezzardi 19e3818521 Make test for implicit C casts more robust
Before this commit, the test was implicitly relying on control-flow
recovery and on the specific order of the then/else scopes in an
if-statement.

This commit relaxes that requirement, since it's not part of what the
test is designed to test.
2024-05-30 12:00:50 +02:00
Djordje Todorovic 6d31e1c0a9 Add test for simplify-switch 2024-05-29 16:27:52 +02:00
Djordje Todorovic 6941df12a3 Add SimplifySwitch Pipe 2024-05-29 16:27:52 +02:00
Lauri Vasama ba58ec8edb Add import-clift-types pipe 2024-05-29 15:43:35 +02:00
Lauri Vasama ba914a1bb5 Replace MLIR container and LLVM import pipe 2024-05-29 15:43:35 +02:00
Lauri Vasama e2f3f31093 Introduce RawFunctionType::Architecture 2024-05-29 15:43:35 +02:00
Alessandro Di Federico 9eb4726989 decompilation.yml: split off revng-c.decompilation 2024-05-21 09:44:04 +02:00
Alessandro Di Federico 22c97bce6b Drop model::Segment::Sections 2024-05-21 09:44:04 +02:00
Djordje Todorovic 0f46ec5578 Add tests for C cast expressions 2024-05-16 17:57:22 +02:00
Djordje Todorovic c58fec45e3 Add ImplicitModelCastPass
We introduce a new LLVM Pass that should detect implicit
casts, by marking the 3rd argument of ModelCast as `true`.
The backend will omit printing a cast expression if the
ModelCast is implicit one.
2024-05-16 17:57:22 +02:00
Andrea Gussoni 736e2509c0 Improve switch to if promotion test 2024-05-03 18:09:12 +02:00
Alessandro Di Federico ddc4e7146f Run DropOpaqueReturnAddress after early-optimize 2024-05-03 18:09:12 +02:00
Andrea Gussoni c7b0fb7c06 Introduce switch to if promotion test 2024-04-05 09:10:18 +02:00
Pietro Fezzardi abb9344242 Relax tests to cope with DetectABI nondeterminism
Currently, some non-determinism upstream in the ABI detection pipeline
causes the return type of the `compute` function to be misdetected, even
if only very rarely.
Exclud this return type from tests for now.
Consider to re-add it in the future if we enforce stricter determinism,
or when EFA 4 is ready.
2024-03-25 18:08:35 +01:00
Pietro Fezzardi c48908c6a6 Revamp decompilation tests
Many old unit tests were too rigid, using the model and the LLVM IR.
This commit drops them, and replaces them with decompilation tests based
on revng-qa, relying on `revng model compare` to test model properties,
and on `FileCheck` to test that we emit specific constructs in C.

The new tests cover various features of the decompiler.
* DLA capability to recover complex data structure like linked-lists and
  arrays.
* DLA capability to update segment and section types, so that we emit
  nice looking accesses to segments in C.
* Capability to emit nice looking integer literals in C
* Capability to emit inline string literals in C and update the model
  types of the segments containg such string literals.
2024-03-19 09:44:00 +01:00
Pietro Fezzardi 71f61d9eb5 Pipeline: execute ExitSSA after ternary reduction 2024-03-19 09:44:00 +01:00
Pietro Fezzardi 132adeecd5 Add PeepholeOptimization pass
This pass is dedicated to applying a bunch of peephole optimizations
that are useful for decompilation and haven't been implemented in LLVM
for whatever reason.

At the moment it only runs an optimization that tries to reduce the uses
of incoming values of PHINodes, under very specific condidtions, which
enables emitting less LocalVariables.
2024-03-19 09:44:00 +01:00
Pietro Fezzardi 70c8ae48ff Retire MarkAssignment for SwitchToStatements 2024-03-19 09:44:00 +01:00
Ivan Krysak 60cbf9a33f Use ABI test binaries for the entire pipeline 2024-03-15 19:05:10 +01:00
Andrea Gussoni 7d8b0139f3 SegregateStack: fix FileCheck directive
Add `%` in order to match precisely the argument LLVMIR value, and not
other spurious characters around.
2024-03-11 18:36:09 +01:00
Alessandro Di Federico 0c212b66d9 Relicense to MIT 2024-02-29 17:03:36 +01:00
Ivan Krysak 34039dea68 ABI: move ToCABIFunctionType analysis to revng 2024-02-09 16:07:59 +01:00
Alessandro Di Federico f74acda0f1 Import test for documentation 2024-02-09 09:04:25 +01:00
Alessandro Di Federico 490b9c6e7f Reorganize test suite 2024-02-09 09:04:25 +01:00
Alessandro Di Federico f6f542769b Convert all public strings to kebab-case 2024-02-09 09:04:25 +01:00
Alessandro Di Federico 911ab00107 s/CDecompilation/Decompile/g 2024-02-09 09:03:34 +01:00
Alessandro Di Federico ba94f0ddd4 s/DecompiledToYAML/Decompiled/g 2024-02-09 09:03:34 +01:00
Alessandro Di Federico 2c9d50bdec s/DecompiledYAMLToC/DecompileToSingleFile/g 2024-02-09 09:03:34 +01:00
Alessandro Di Federico 23b3bc9e16 s/ImportModelFromC/ImportFromC/g 2024-02-09 09:03:34 +01:00
Alessandro Di Federico 9c7aa51baa s/ToCABIFunctionType/FunctionsToCABI/g 2024-02-09 09:03:34 +01:00
Alessandro Di Federico 011d04eaaa Drop obsolete tools 2024-02-09 09:03:34 +01:00
Alessandro Di Federico 539b2bd435 Rename dla analysis into analyze-data-layout 2024-02-09 09:03:34 +01:00
Alessandro Di Federico 11308a1bc7 Rename steps and analyses 2024-02-09 09:03:33 +01:00
Alessandro Di Federico 5c8c87a428 Rename pipelines file 2024-02-09 09:02:56 +01:00
Pietro Fezzardi da87b94a03 Drop VMA tests
VMA is obsolete and scheduled to be removed. The tests we had in the
test suite before this commit were for a mode of operation that we're
not actively using for decompilation now, and that will be dropped.
This commits just removes those tests.
2024-02-05 18:00:06 +01:00
Ivan Krysak be385fdfe8 model-to-header: avoid raw primitive arguments
After updating the function type conversion to be extra strict about
type alignment, the model-to-header tests for all these primitive
types no longer pass: it's no longer valid for a CFT to use any
primitives ABI is not aware of as part of the prototype.

As a simple workaround, this commit replaces all the primitives
used by said prototypes with pointers.
2024-02-01 11:38:57 +01:00
Giacomo Vercesi ed1ad5e040 Add type.h artifact
Add the required container and pipes to produce `type.h`, a type-wise
file that shows the definition of a Model type in plain C.
2024-01-26 19:13:58 +01:00
Pietro Fezzardi c41a6392c0 Run loop-simplify to enable DLA to detect arrays 2024-01-26 16:49:52 +01:00
Pietro Fezzardi 04bb1d0fb3 Backend: avoid casting to uint8_t in conditions
Explicitly casting to uint8_t has the semantics of truncating, in case
the value being casted is larger than 8 bits.
Avoiding the cast default to regular C behavior, where every non-zero
integer is considered true.
2024-01-26 16:49:47 +01:00
Pietro Fezzardi 5d1ab13289 Drop old RemoveRefDeref pass
The pass has always been redundant, only used to simplify the IR and not
for anything useful.
Recently, after the work done to tidy up casts, it has started to give
problems: turns out ModelGEPRefs without indices are not always
redundant, and removing them can cause `trunc` instructions that then
end pessimizing the C code generation.

This commit drops the pass altogether.
2024-01-26 16:49:37 +01:00
Massimo Fioravanti 5a2e3b2359 Drop llvm pipeline 2024-01-02 11:05:50 +01:00
Alessandro Di Federico 3709deebc8 SegregateStack: use alloca for stack arguments
This commit:

1. Introduces an alloca for stack arguments of a function. This enables
   us to "write" to stack argument. In order to do so, we simply map the
   relevant stack portion to the alloca that, since it's a memory
   object, can be `load`'d from and `store`'d to.

   Note that `llvm::Argument`s are always scalar since if the original
   argument was an aggregate, it would have been passed as a pointer,
   which is a scalar.

   Note also that previously we were using scalar arguments as if they
   were *pointers* to the stack arguments. This commit fixes that too
   (and updates the tests accordingly).

2. Introduces an alloca for *scalar* stack arguments of a call site.
   The alloca is then mapped to the corresponding part of the stack.
   Previously, there was no redirection and negative offsets from
   `_stack_frame` would pop up.
2023-12-12 12:04:15 +01:00
Alessandro Di Federico 071cdb1781 Enable ConvertToCABI analysis 2023-12-12 12:04:13 +01:00
Giacomo Vercesi 194bcecc41 Drop getReturnField
Drop the `getReturnField` helper, the cases in which it was used are now
covered by the `NamedTypeRegister::name` method.
2023-12-11 10:21:40 +01:00
Massimo Fioravanti b3a1aeaa89 Unify pipeline pipes yml files 2023-12-06 16:26:19 +01:00
Pietro Fezzardi 24cb43ce9c Make RawFunctionType::StackArgumentsType a TTR
This is homogeneous with all other nullable references to types in the
model, such as the StackFrameType in model::Function, and others.
2023-12-05 16:56:52 +01:00
Ivan Krysak fa7bf17dae IRCanonicalization: introduce ternary-reduction 2023-11-21 17:05:18 +01:00
Pietro Fezzardi 75e98006d4 Rename artifacts for decompiled C headers
This also changes the names that show up in the VSCode-based UI, so that
they are coherent with what's included in the decompiled C code via the
related #include directives.
2023-10-19 17:12:25 +02:00
Pietro Fezzardi a78928141b Rename decompiled C headers 2023-10-19 17:08:25 +02:00