Commit Graph

111 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 57b5eb7f98 NameBuilder: allow different name checkers 2025-04-17 11:19:17 +03:00
Ivan Krysak f070f1f1e1 Model: sunset double name system 2025-04-17 11:19:17 +03:00
Ivan Krysak 645cf7fc2e NameBuilder: sunset deduplication
This reworks NameBuilder to ease the transition to the system where
the model will be guaranteed to never contain any name collisions, both
between user-specified names and the automatic ones.
2025-04-15 16:35:42 +03:00
Alessandro Di Federico 11d8515f46 ModelToHeader: adjust blank lines 2024-11-27 17:18:12 +01:00
Alessandro Di Federico 143c315196 Merge revng-c into revng 2024-11-21 10:50:55 +01:00
Ivan Krysak 7a827b4ef5 Use doxygen for header grouping 2024-11-06 19:18:53 +02:00
Ivan Krysak 64446d0453 Adopt name builder across the model users 2024-11-06 19:18:53 +02:00
Alessandro Di Federico 8cd4ee3b59 Move Kinds.h to revng 2024-11-04 15:09:56 +01:00
Alessandro Di Federico 98903f6b07 Move Ranks.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 89f828c694 Link some revng libraries 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
Ivan Krysak 94d860e2b2 Clean up builder configuration
This also re-enables stack inlining by default.
2024-10-15 10:45:13 +03:00
Ivan Krysak 1a35cbcb77 Introduce PTMLCTypeBuilder 2024-10-15 10:45:13 +03:00
Ivan Krysak 8aa7b55e2d PTMLIndentedOstream: rename into IndentedOstream 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 19d033958e Drop TargetListContainer 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 4653796008 Drop Pipe::print 2024-09-27 10:35:10 +02:00
Alessandro Di Federico e1f46264f8 Ensure every pipe commits what it should 2024-09-26 17:51:07 +02:00
Ivan Krysak 77c8e4b927 PTML: move annotation data to a new header 2024-09-04 16:43:57 +02:00
Ivan Krysak cae04be8fd PTMLCBuilder: clean up annotation method naming 2024-09-04 13:04:44 +03:00
Pietro Fezzardi 521baf38e8 PTML: honor GeneratePlainC 2024-06-27 17:30:56 -04:00
Pietro Fezzardi dfe3f4cb47 Rename revng C headers for decompiled code
Strip away the 'revng-' prefix from the filename.
2024-06-27 17:26:18 -04:00
Pietro Fezzardi 8a95a0b9c9 HelpersToHeader: enable printing plain C 2024-06-27 17:14:28 -04:00
Ivan Krysak 94a0ad6b93 Adopt reworked model::Type 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
Pietro Fezzardi 85340c8d84 ModelToHeader: disable type inlining by default
This is due to the fact that type inlining currently is broken in some
corner cases involving recursive types.
The bugs are caused by the fact that TypeInlineHelper uses its own
custom graph instead of using the DependencyGraph used by ModelToHeader,
causing different decisions about the order of emission of types.
As a result, the generated C types are not valid C, and they fail to
compile because a field of a struct has a type that is defined later
than its use.

After refactoring TypeInlineHelper to use DependencyGraph like
ModelToHeader, this can be reverted.
2024-06-26 12:21:58 +02:00
Pietro Fezzardi 7e44777c98 ModelToHeader: reduce lifetime of TypeInlineHelper 2024-06-07 17:59:06 +02:00
Pietro Fezzardi 84a40d0239 TypeInlineHelper: clean up members and methods 2024-06-07 17:59:06 +02:00
Pietro Fezzardi 8a7b5d4a25 ModelToHeader: refactor printTypeDefinitions
This refactoring makes the code less redundant, more concise,
and more explicit about how it handle's type inlining, while adding
documentation.
2024-06-07 17:58:36 +02:00
Pietro Fezzardi 746cf5b55d TypeInlineHelper: rename collectStackTypes method
to collectTypesInlinableInStacks and document it.
2024-05-29 15:34:26 +02:00
Alessandro Di Federico 0c212b66d9 Relicense to MIT 2024-02-29 17:03:36 +01:00
Alessandro Di Federico f6f542769b Convert all public strings to kebab-case 2024-02-09 09:04:25 +01:00
Pietro Fezzardi 8acf6c2f94 Allow type-less Segments in the Model 2024-02-09 09:04:23 +01:00
Giacomo Vercesi 7f8a83c34a ModelToHeader: add DisableTypeInlining option
When running ModelToHeader in HeaderToModel, all types need to be
defined in the header for clang to successfully parse the file. Add an
option to `ModelToHeaderOptions` that forces all types to be printed
regardless of stack or inlining rules.
2024-01-26 19:13:58 +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
Massimo Fioravanti 86e45461a0 Introduce pipeline execution context 2024-01-02 11:05:50 +01:00
Pietro Fezzardi 842b5e1075 Make Segment::Type a TupleTreeReference
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
Pietro Fezzardi 59603cdafb HeadersGeneration: make type dependency stricter
This commit makes some of the dependencies among types in
HeadersGeneration stricter than they were before.

The patch is a temporary workaround to the problem of pointers to arrays
of struct/union in C.

Basically, in C, `struct X (*ptr_to_array)[2];` declares a variable
`ptr_to_array` that points to an array with two elements of type `struct
X`. The problem is that, because of a quirk of paragraph 6.7.6.2 of the
C11 standard (Array declarators), to declare `ptr_to_array` it is required
to see the copmlete definition of `struct X`.
Even if MSVC seems to compile it just fine, clang and gcc don't.

In principle this could be worked around by doing the following two
things:
1) introducing wrapper structs around arrays of struct/union that are used
as pointees
2) postpone the complete definition of the wrapper to after the element
type of the array is complete.

However for now we just inject a stronger dependency to enforce ordering.
This is actually stricter than necessary and can yield to be unable to
print valid C code for model that was otherwise perfectly valid and could
have been fixed by injecting the wrapper structs properly.

This particular handling of pointers to array is more strict than actually
necessary. It has been implemented as a workaround, instead of handling
the emission of wrapper structs. This latter solution of emitting structs
has already been used in other places but, in all the other places where we
currently do it, it is possible to do it on-the-fly, locally.
On the other hand, for dealing with this case properly we'd have to keep
track of dependencies between the forward declaration of the wrapper, and
the full definition of the element type of the wrapped array.
The emission of the full definition of the wrapper must be postponed until
the element type of the wrapped type is fully defined, otherwise it would
fail compilation. So fow now we've put this forced dependency, that could
be relaxed if we properly handle the array wrappers.
2023-11-21 11:34:57 +01:00
Giacomo Vercesi ce446576a4 Fix typos 2023-11-02 16:49:49 +01:00
Pietro Fezzardi a97287cef3 ModelToPTMLTypeHelpers: refactor APIs
This commit reorders the argument passed to various `printDeclaration`
and `printDefinition` helper functions, to make them more uniform across
each other, and to accept the same arguments in the same order.
2023-10-18 15:19:53 +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
Alessandro Di Federico cb8aa3d929 Adopt .prototype()
Also adopt `QualifiedType::getFunctionType` where appropriate in order
to unwrap typedefs.
2023-10-05 19:18:38 +02:00
Pietro Fezzardi 8d9f07d7a7 Change indentation of all decompiled C code
This commit changes the indentation of all the C code we emit, from 4
whitespaces to only 2 whitespaces.
2023-09-21 15:17:44 +02:00
Alessandro Di Federico f3d6bbb047 s/ThePTMLCBuilder/B/g 2023-08-23 16:40:54 +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
Alessandro Di Federico f81e9d615b dumpModelToHeader: introduce struct for options
This commit also introduces a new option for emitting code right after
the `#include` section.
2023-08-23 16:37:39 +02:00