58 Commits

Author SHA1 Message Date
Pietro Fezzardi 8de85c25a0 Remove array field of opaque struct types 2026-05-13 08:51:25 +02:00
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
Pietro Fezzardi 21063f1844 NameBuilder: support opaque types
Teach NameBuilder and ModelCBuilder how to produce names and
references for opaque-array types: NameBuilder gains
opaqueTypeName(ByteSize), ModelCBuilder gains the matching
reference and definition tags. Both rely on the new
Configuration::OpaqueTypePrefix.
2026-05-08 11:37:10 +02:00
Ivan Krysak 22fe32afa2 Minor improvements 2026-02-25 12:47:27 +01:00
Alessandro Di Federico 1dff54ba60 Make new backend independent from the old one 2025-12-03 17:59:18 +01:00
Ivan Krysak ecb9d76c64 Model: drop obsolete default value handling 2025-10-13 18:33:10 +03:00
Ivan Krysak cd7f3f8ffd ModelCBuilder: rework handling of padding fields 2025-09-04 16:57:16 +03:00
Ivan Krysak 3eea4c4094 Always emit _SIZE on struct definitions 2025-09-04 16:57:12 +03:00
Ivan Krysak c6a175a1b9 Rename _START_AT -> _STARTS_AT 2025-08-29 14:00:29 +03:00
Ivan Krysak f6970ff70a TypeNames: fix function prototype return value tag 2025-07-23 11:38:53 +02:00
Ivan Krysak 290d2e2c57 ptml::CTypeBuilder: rename into ModelCBuilder 2025-07-23 11:38:53 +02:00
Ivan Krysak 1930f72484 CTypeBuilder: drop replaced tag builders 2025-07-23 11:38:51 +02:00
Ivan Krysak 21734cad34 CTypeBuilder: add new variable and label tagging 2025-07-23 11:38:51 +02:00
Ivan Krysak a7bba503d3 CTypeBuilder: add counting name builder support 2025-07-23 11:38:51 +02:00
Ivan Krysak fd1ed20852 Ranks: update local variables and goto labels
Then now use corresponding model keys instead of raw names.
2025-07-23 11:38:51 +02:00
Ivan Krysak 031c4dfa2f Introduce ptml::CTypeBuilder::getFreeFormComment 2025-07-23 11:38:50 +02:00
Ivan Krysak b5337d78da Minor Improvements 2025-07-23 11:38:50 +02:00
Lauri Vasama 28550f2f57 Add explicit pointer size support in old backend
When `Configuration.ExplicitTargetPointerSize` is set, the backend uses
explicit pointer type sizes (e.g. `pointer32_t(T)`).
2025-07-17 16:45:03 +02:00
Lauri Vasama 206de51c69 Add API for helper PTML references by name
The Clift backend does not have access to any llvm::Function objects so
the helper C identifiers must be derived from the helper name alone.
2025-06-04 15:13:47 +02:00
Lauri Vasama a7eb86174b Add revng/Support/Identifier.h for id validation 2025-06-04 15:13:47 +02:00
Pietro Fezzardi e50bd12519 Drop unused printInlineDefinition 2025-05-29 09:31:26 +02:00
Pietro Fezzardi c66da0ab65 DependencyGraph: drop getDeclaration/getDefinition
These methods are now unused after the recent refactoring.
2025-05-29 09:31:26 +02:00
Pietro Fezzardi 0b977b85d6 DependencyGraph: add view() debug_function method
to open the graphviz visualization.
2025-05-29 09:31:26 +02:00
Pietro Fezzardi a71db5d243 DependencyGraph: refactor creation of nodes/edges 2025-05-28 17:11:57 +02: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 c4b637eaa4 DependencyGraph: hide all non-const methods
This commits wraps all the machinery that can mutate a DependencyGraph
inside the interval factory class DependencyGraph::Builder.
In this way, once a DependencyGraph is created, it cannot be mutated by
accident from outside.
This is important because mutating it from outside makes it easy to
break the consistency of internal maps.
This risk will only increase when supporting artificial struct wrapper
types, so we encapsulate this now to prevent issues in the future.
2025-05-28 17:11:49 +02:00
Pietro Fezzardi 2331f10282 DependencyGraph: add new factory method and class 2025-05-28 17:11:11 +02:00
Pietro Fezzardi 660cb89eb5 DepenencyGraph: introduce AssociatedNodes
This data structure is used to bind together a pair of pointers to
TypeDependencyNode, one referring to a declaration of a type and the
other referring to a definition of the same type.

The definition can be null if the type referred to is a type without an
explicit definition (e.g. typedefs), while it's never null for types
for which have forward declaration that is separate from the definition
(e.g. structs and unions).
2025-05-28 17:11:11 +02:00
Pietro Fezzardi e51fcfc01a DependencyGraph: add TypeNode helper methods 2025-05-28 17:11:11 +02:00
Pietro Fezzardi 28f180dcb8 Rename CTypeBuilder::printTypeDefinition
to printDefinition.
2025-05-28 17:11:11 +02:00
Pietro Fezzardi ec0c56abcc Rename CTypeBuilder::printTypeDeclaration
to printDeclaration.
2025-05-28 17:11:11 +02:00
Pietro Fezzardi 8c7a800de1 Rename CTypeBuilder::printForwardTypeDeclaration
to printForwardDeclaration.
2025-05-28 17:11:11 +02:00
Pietro Fezzardi f353af775e TypeNode: add entries for artificial wrappers
This commit adds two enum entries to TypeNode::Kind to represent forward
declarations and definitions of artificial struct wrappers, that are not
present in the model but that we're forced to print in C to overcome
its limitations in representing types.

At the moment, this is only going to be used for representing return
types of RawFunctionDefinitions whose Layout returns RegisterSet, which
can't be represented in C without a wrapper.
2025-05-28 17:11:11 +02:00
Pietro Fezzardi 0426c773b2 CABIFunctionDefinition: drop array argument/return
This commit bans from the model array types in as argument or return
types in CABIFunctionDefinition.
CABIFunctionDefinition implies we're decompiling towards C, and C does
not support array arguments (passed by copy) nor array return types.

Banning these from the model reduces the number of situations where we
have to emit artificial array wrappers (not present in the model) around
types when printing C code, simplifying the handling of such situations
when translating to clift and in general in the decompilation pipeline.
2025-05-28 17:11:11 +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 8a0d06831d PTMLCBuilder: factor out line length calculation 2025-05-08 15:42:01 +02:00
Ivan Krysak c7bba8c1b9 Prevent Support headers from depending on PTML 2025-05-08 15:42:01 +02:00
Ivan Krysak 82695ae8a6 PTMLCTypeBuilder: print RFT-RV wrapper comment
Before this definition of such wrappers allowed adding comments, but
never displayed them, which is confusing.
2025-05-08 15:42:01 +02:00
Ivan Krysak f25ea78aa8 PTMLCTypeBuilder: separate RFT-RV wrapper emission
This lets us drop the ability for the `getNamedInstanceOfReturnType`
to return definitions (this was the only user).
2025-05-08 15:42:01 +02:00
Ivan Krysak f4c4a47a99 PTMLCTypeBuilder: improve tag helper documentation 2025-05-08 15:42:01 +02:00
Ivan Krysak 0a097c067b TypeNames: suppress selected comment newlines 2025-05-08 15:42:01 +02:00
Ivan Krysak 6cdf5c01ef PTML: make commentability a property of a line
Before this, commenting is only possible on specific names, with this
the entire supported line is active (unless there are more grannular
comment contexts, for example, in the function prototype).

For example (commentable parts are marked with `^`):
```
// struct whatever {
// ...

// before this
  const my_type_name *my_field_name[10];
//                    ^^^^^^^^^^^^^

// after this
  const my_type_name *my_field_name[10];
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

// ...
// };
```
It's the same for all the others, like segments, arguments, and so on.
2025-05-08 15:42:00 +02:00
Ivan Krysak eac296a99f Standardize PTML tag emission in c backend 2025-05-08 15:42:00 +02:00
Ivan Krysak fa2f243f12 PTML: avoid auto in constexpr string literals 2025-05-08 15:42:00 +02:00
Ivan Krysak 66b42298de PTML: Emit a location for statement comments 2025-05-08 15:42:00 +02:00
Ivan Krysak c6e38cd485 Return to using constant name builders
Because of how name builders used to lazy gather namespaces on the first
requested name, the objects were self mutating. As such only non-const
references could be used to pass them around.

Since that is no longer the case, this restores most of lost const
qualifiers.
2025-04-17 11:19:17 +03:00
Ivan Krysak 57b5eb7f98 NameBuilder: allow different name checkers 2025-04-17 11:19:17 +03:00
Ivan Krysak 93e44460bf ptml::CTypeBuilder: drop getPlainTypeName 2025-04-17 11:19:17 +03:00
Ivan Krysak 57ac85d7a0 NameBuilder: introduce warning method 2025-04-17 11:19:17 +03:00
Ivan Krysak 25790b5a78 NameBuilder: change automatic segment name
Use index within the binary instead of address in order to make these
shorter.
2025-04-15 16:35:42 +03:00