Commit Graph

127 Commits

Author SHA1 Message Date
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
Pietro Fezzardi 4bc7a14649 ModelTypeNames: print function attributes 2023-10-18 15:39:17 +02:00
Alessandro Di Federico 2a7e06df1f printFunctionPrototype: add newline after ABI
This commit forces getLocationAttribute's argument to be false.
2023-10-06 17:14:29 +02:00
Djordje Todorovic 68400d9b30 Import from LLVM IR to MLIR
- Add PrepareLLVMIRForMLIR Pass.
  This Pass performs massaging of the LLVM IR
  produced by revng so it can be parsed/accepted
  for the LLVM MLIR Dialect.
- Introduce new pipeline branch: llvmir-to-mlir.yml.
- Add LLVMIRToMLIR step.
- Add ImportLLVMToMLIRPipe pipe.
2023-10-02 17:13:55 +02:00
Djordje Todorovic c5f9a61037 Remove make-segment-ref from segregate.yml
We remove this since that was ignored by the parser and didn't
have any effect.
2023-09-21 08:44:47 +02:00
Giacomo Vercesi d95c3b4732 Change extension for Decompiled container
The Decompiled container (which use FunctionStringMap) now uses
`.tar.gz` as the container format, as opposed to YAML. Change the
filename of the containers accordingly.
2023-09-06 11:23:40 +02:00
Giacomo Vercesi 187d2744e9 tests: add graphql --produce-artifacts
Add among the tests an invocation of `graphql --produce-artifacts`.
2023-08-23 17:45:36 +02:00
Giacomo Vercesi 4ca1d1237f Add component configuration for revng-c
`revng` now requires all pipeline files to have a `Component` field
which tells the command line driver to what component the pipeline
definition belongs to.
2023-08-23 17:45:36 +02:00
Alessandro Di Federico 30c127267c Improve ModelToHeader and HeaderToModel tests
* Fix non-PrimitiveTypes with low IDs.
* Ensure we use `revng model compare` to test the model.
* Updates the name to reflect the recent changes in naming convention
  and in the way we represent `model::Type::ID`s.
2023-08-23 16:37:39 +02:00
Alessandro Di Federico 330d2b6cc7 Model: rework how we name things
This commit:

* Introduces `_` as a prefix for all non-user entities we emit in
  decompiled code.
  Also, some names have been changed to be more concise.
  Specifically, the following entities have changed:
  `_ENUM_UNDERLYING`, `_ABI`, `_REG`, `_padding_at_`,
  `_artificial_struct_`, `_artificial_wrapper_`, `_stack`,
  `_break_from_loop_`, `_var_`, `_stack_arguments`,
  `_artificial_struct_returned_`, `_enum_max_value_`.
* Introduce _PACKED for `__attribute__((packed))`.
* `EnumEntry` name: drop the `EnumType` name prefix.
2023-08-23 16:37:39 +02:00
Pietro Fezzardi 9c755d89e6 Use only compact annotation macros in tests 2023-07-26 10:01:27 +02:00
Djordje Todorovic 1d3cacf6c2 HeaderToModel: support *80_t and *96_t primitives 2023-07-25 12:04:14 +02:00
Djordje Todorovic 943ceff61f Add tests for ImportModelFromC Analysis 2023-07-25 12:04:08 +02:00
Djordje Todorovic 262e579128 ModelToHeader: annotation for enum underlying type 2023-07-25 12:03:57 +02:00
Djordje Todorovic 5c0167f792 Add ImportModelFromC Analysis
This analysis will be used for the following features:

1) Edit Type in the Model
2) Edit Function Prototype in the Model
3) Add Type to the Model

It takes C code as an input, parses it and produces a Model
type that represents the C type.
2023-07-24 11:51:47 +02:00
Djordje Todorovic e6b128c17b ModelToHeader: Print annotation __attributes__
This will be useful for `edit/add type` feature,
since we will be able to specify which ABI describes
a function, from the source code written in C.
2023-07-24 09:17:08 +02:00
Pietro Fezzardi c06f963fe1 Test recompilation for i386 separately
This is necessary because i386 has weird sizes for `long double` that
result in `float86_t` in the model, so we need to pass additional
arguments to the recompilation tests, in order to avoid compiler errors.
2023-06-30 10:48:59 +02:00
Pietro Fezzardi d9b5bfd99a revng-primitive-types.h: improve generic{80,96}_t
Before this commit, both `generic80_t` and `generic96_t` were always
defined as structs containing an array of chars of the proper size.

This ensured that they always had the proper size, but it didn't play
well with recompilation of decompiled C code, because it wasn't possible
to assign e.g. a `float80_t` to a `generic80_t` (or viceversa), which
was the whole point of having `generic80_t` and `generic96_t`.

This commit works around this by making sure that, whenever `float80_t`
(and `float96_t`) is defined, the definition of `generic80_t` (and
respectively of `generic96_t`) always matches, allowing error-free
recompilation of decompiled sources.
2023-06-30 10:48:59 +02:00
Pietro Fezzardi 6bc5346733 Rename tests in revng-c-model-to-header.yml
This change is intended for the name not to clash with another set of
tests that lives in revng-c.yml.
The first is intended as a set of unittests for model-to-header,
the second is intended to generated headers to test recompilation of
decompiled C code.
2023-06-30 10:48:59 +02:00
Pietro Fezzardi eae5e3069d revng-primitive-types.h: fix 128-bits definitions
This commit guards 128-bits integer typedefs and helpers with:
`#ifdef __SIZEOF_INT128_`, because these are compiler extensions that
are not always guaranteed to be defined (e.g. they are not available
when compiling for x86 32-bits).
2023-06-30 10:48:59 +02:00
Pietro Fezzardi 6acd265c5a Add revng helpers to decompile llvm::UndefValue
Before this commit, we used to decomple UndefValue to the literal 0.

This was causing problems in some cases, such as switch(0 /*undef*/)
where clang was issuing a warning that was impossible do disable without
turning off -Wall alltogether, which is undesirable.

This commit introduces a set of helper functions in
revng-primitive-types.h, that are now used to avoid emitting undef as
constant.
This is more semantically meaningful when looking at the decompiled
code, and it has the nice side effect that it silences the clang
warnings mentioned above.
2023-06-30 10:48:59 +02:00
Pietro Fezzardi e2791443fb Remove extractvalue instructions in decompilation
Now extractvalue instruction are replaced by dedicated
OpaqueExtractValue custom opcode, that prevents LLVM from doing strange
things with extractvalues during optimizations (such as e.g. sinking).

This is important since extractvalue instructions and struct-typed
values in general in our LLVM IR are not real first-class citizens, but
only a byproduct of the binary lifting process, and they actually
represent bundles of registers that are returned from isolated
functions.
2023-06-30 10:48:59 +02:00
Pietro Fezzardi 1b575e75dc Drop restore-extractvalues from the pipeline
Before this commit we were restoring opaque extractvalue instructions to
actual non-opaque extractvalue instructions in the pipeline.
We will not do this anymore, since LLVM ends up messing around too much
with them and it breaks the somewhat assumptions we're making around
values with aggregate types, that in our IR only represent tuples of
registers coming from the binary.
2023-06-30 10:48:59 +02:00
Pietro Fezzardi d2c9cbafb8 Add a DCE pass before RemoveLiftingArtifacts
This is meant to get rid of dead stuff that is left around by the revng
lifting process, so that RemoveLiftingArtifacts can be kept simpler.
2023-06-30 10:48:59 +02:00