165 Commits

Author SHA1 Message Date
Ivan Krysak 29ff972daa Move the opaque type gatherer to model::Binary 2026-06-15 17:28:22 +02:00
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
Ivan Krysak de31315cd7 Model: rename Inline into AlwaysInline 2026-03-27 08:16:21 +00:00
Ivan Krysak 729b025de3 CAttributes.h: move back to PTML
When `revng` and `revng-c` were being merged, this header founds its
way into `revngSupport` even though it makes more sense under the PTML
umbrella.
2026-03-27 07:19:27 +00:00
Ivan Krysak e706628a49 Rename Annotations.h into CAttributes.h 2026-03-27 07:19:27 +00:00
Ivan Krysak 91ed5e33a8 PTML: make enum scope named for consistency sake 2026-02-25 12:47:27 +01:00
Ivan Krysak f73bbf7a08 Annotation: expose raw access
This allows the existing annotation registry to be reused in a more
convenient nature. Before now, it was only used for *parsing* or,
rather, *verifying* annotations. Now that we can take advantage of
it for emission as well, there's more control it needs to provide
in particular as far as annotation arguments are concerned.
2026-02-25 12:47:27 +01:00
Alessandro Di Federico c883bed765 Drop Logger's StaticEnabled feature 2025-10-31 17:25:03 +01:00
Alessandro Di Federico f8bd4c3bac Move around some files in preparation for libtcg
* Make the following private headers public:
  * Lift/CPUStateAccessAnalysisPass.h
  * Lift/CSVOffsets.h
  * Lift/PTCDump.h
  * Lift/VariableManager.h
* Move from revngSupport to revngLift:
  * IRAnnotators.{h,cpp}
  * SelfReferencingDbgAnnotationWriter.{h,cpp}
* Move from revngSupport to revngModel:
  * FunctionTags.{h,cpp}
  * ProgramCounterHandler.{h,cpp}
* Move from revngSupport to revngRecompile:
  * OriginalAssemblyAnnotationWriter.{h,cpp}
2025-10-24 15:34:11 +02:00
Ivan Krysak ecb9d76c64 Model: drop obsolete default value handling 2025-10-13 18:33:10 +03:00
Ivan Krysak f03654564e Emit _STARTS_AT on fields with custom names 2025-09-05 10:15:32 +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 97aa3c8247 std::string: use implicit default constructor 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 21734cad34 CTypeBuilder: add new variable and label tagging 2025-07-23 11:38:51 +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 6b6037fc7a DependencyGraph: add doxygen 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 82e57e1513 DependencyGraph: add addAndLogSuccessor helper 2025-05-28 17:11:54 +02:00
Pietro Fezzardi 75febb8aca Add DependencyGraph::Builder::addArtificialNodes 2025-05-28 17:11:53 +02:00
Pietro Fezzardi bdb59f597b Refactor DependencyGraph::Builder::addNodes
Now addNodes also adds an implicit dependency from the declaration node
to the definition node, and returns a data structure representing the
two nodes: declaration and definition.
2025-05-28 17:11:53 +02:00
Pietro Fezzardi 2d70710a55 DependencyGraph::Builder::addNodes returns nodes 2025-05-28 17:11:52 +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 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 62762c1e48 TypePrinters.cpp: improve logging of TypeNodes
reusing the same getNodeLabel function used by DOTGraphTraits.
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
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 0b2461e7b3 Wrap comments into a tag that allows commenting
This wraps most of the comments into a tag that lets them be edited
as they are, without needing to find where that comment is actually
attached to.
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 0a097c067b TypeNames: suppress selected comment newlines 2025-05-08 15:42:01 +02:00
Ivan Krysak 3808706a39 TypeNames: render return value register comment 2025-05-08 15:42:01 +02:00
Ivan Krysak 6d2b3169d8 TypeNames: render segment comment 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