70 Commits

Author SHA1 Message Date
Pietro Fezzardi 80a33109eb Print opaque types in model header
Emit forward declarations and definitions of the opaque-array
artificial structs from the C model header (and from the helpers
header). Definitions are gated on a new DefineOpaqueTypes flag
threaded through PTMLHeaderBuilder::printModelHeader so that the
helpers header keeps emitting only the declarations.
2026-05-08 11:37:10 +02:00
Ivan Krysak 532f81edd3 Old Headers: fix a broken comment 2026-02-25 12:47:27 +01:00
Giacomo Vercesi 27f419c8cd Fix and ban namespace clobbering
Fix an instance where the `std` namespace got clobbered into the global
namespace by accident.
2026-02-16 10:34:38 +01:00
Alessandro Di Federico c883bed765 Drop Logger's StaticEnabled feature 2025-10-31 17:25:03 +01:00
Pietro Fezzardi ea3cbe4c1b Drop type inlining
Type inlining was a feature that allowed type definitions of
structs/unions/enums to be printed in C directly inside the definition
of another parent struct/union, if the inner type was only used once in
the parent type.

This kind of reasoning is inherently global: a type definition of the
subtype can be inlined in the parent type one only if *globally* the
subtype it isn't referred anywhere else.

This caused issues with type inlining inside definitions of stack types
in the body of functions. Indeed, for a given function, due to type
inlining, it was necessary to do global reasoning about what other types
could be inlined in the definition of the function's stack frame type.
This, in turn, had heavy consequences on invalidation, because any
change to any type (even if it wasn't referred in a given function's
body) was causing invalidation of all functions' bodies.

For this reason it was decided to drop the type inlining feature.
2025-05-28 17:11:56 +02:00
Pietro Fezzardi c8e8f095fb PTMLCTypeBuilder: replace getIndented{Tag,Scope}
These methods had a misleading name, because they always returned a
ScopeTag, and never indented anything.
As a result they were misused or used in a confusing way in most of
their uses.

They have now both been replaced by two different overloaded methods
with the name getScopeTag.

This commit also fixes all their broken uses.
2025-05-14 10:11:46 +02:00
Ivan Krysak 0a097c067b TypeNames: suppress selected comment newlines 2025-05-08 15:42:01 +02:00
Ivan Krysak 79964eac74 Avoid ' misuse in error messages and comments 2025-04-17 16:41:21 +02: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 98903f6b07 Move Ranks.h to revng 2024-11-04 15:09:56 +01: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
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
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 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
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
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 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
Alessandro Di Federico a207ef7c44 Minor changes 2023-08-23 16:12:51 +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
Ivan Krysak e0b956b1c2 Model: rework edit path helpers from the ground up 2023-07-21 04:58:50 +00:00
Ivan Krysak fe0531868c Use Container::contains() where appropriate 2023-07-05 06:07:09 +00:00
Djordje Todorovic 286eb4d734 c-backend: Introduce PTMLCBuilder
This will be used to generate plain C.
2023-06-09 15:40:23 +02:00
Djordje Todorovic ca7bc2e442 c-backend: Generate Inline Types in PTML
In ModelToHeader generate Inline Types in PTML by handling
Structs, Unions and Enums.

In addition, during the ModelToHeader we avoid producing
Structs that describe stacks, and in the DecompileFunction we
produce the definition of it inline if it is safe (referenced
only once).
2023-05-03 13:13:28 +02:00
Massimo Fioravanti 87aef3fbad revng-c now uses Model accessors 2022-12-12 11:35:52 +01:00
Pietro Fezzardi ee0dc97464 Uniform printing return types of functions 2022-11-30 18:16:13 +01:00
Pietro Fezzardi 7b66b9d7f6 TypeNames: fix redundant whitespaces in types 2022-11-30 18:16:13 +01:00
Pietro Fezzardi 389a184fc2 Handle CABIFunctionTypes returning struct types 2022-11-30 18:16:13 +01:00
Pietro Fezzardi 1bec5bd2ab Define all primitive types in dedicated header
This commit does the following:
- drops revngfloat.h
- disables printing primitive types in ModelToHeader
- creates a new header revng-primitive-types.h which includes all the
  declarations of all revng primitive types
2022-11-30 18:16:13 +01:00
Pietro Fezzardi 8aaa3ca92e Refactor PTML generation for functions 2022-11-16 16:02:09 +01:00
Pietro Fezzardi ff631c5364 PTMLC.h: switch to string-based return values 2022-11-15 15:54:20 +01:00