Commit Graph

2425 Commits

Author SHA1 Message Date
Andrea Gussoni da31adc83c ASTTree: clear internal fields on constructor 2025-06-19 09:48:39 +02:00
Andrea Gussoni 333903e86e ScopeGraph: ScopeGraphBuilder const methods 2025-06-12 15:31:38 +02:00
Lauri Vasama 4bf1d8fe99 Remove Clift backend transform and model option 2025-06-04 15:13:47 +02:00
Lauri Vasama 7c9031bd98 Change MLIRContainer to focus on Clift, rename 2025-06-04 15:13:47 +02:00
Lauri Vasama cc94e2d290 Constrain returnable types 2025-06-04 15:13:47 +02:00
Lauri Vasama 047511b1ed Remove Clift break and continue ops 2025-06-04 15:13:47 +02:00
Lauri Vasama 3e065cb23d Remove local and label names 2025-06-04 15:13:47 +02:00
Lauri Vasama fdbc7b57fb Add SwitchOp::getCaseRegions 2025-06-04 15:13:47 +02:00
Lauri Vasama a0ec1305f1 Move ReturnOp type verification to FunctionOp 2025-06-04 15:13:47 +02:00
Lauri Vasama f0091e699f Remove clift::ModuleOp
A new dialect attribute is instead used to verify mlir::ModuleOp:

```
module attributes {clift.module} {
}
```
2025-06-04 15:13:47 +02:00
Lauri Vasama 51c4ed8201 Make Clift.td formatting more consistent 2025-06-04 15:13:47 +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 6f3c8ee418 Add PrimitiveType builder with default const=false 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
Lauri Vasama d17d23b8fc Add getHandle on GlobalOpInterface 2025-06-04 15:13:47 +02:00
Lauri Vasama a3ee0349a6 Inherit GlobalOpInterface from Symbol 2025-06-04 15:13:47 +02:00
Lauri Vasama c44df5d591 Improve CliftOpInterfaces formatting consistency 2025-06-04 15:13:47 +02:00
Lauri Vasama 957150915c Fix LocalVariableHelpers const correctness 2025-06-04 15:13:47 +02:00
Lauri Vasama 336b18d937 Overhaul Clift type syntax
* Removed syntax for defined type attributes.
* Added !clift.const<T> and removed const syntax from types kinds.
* Some restructuring of class type internals.
2025-06-04 15:13:47 +02:00
Lauri Vasama 460af9d7d4 Use full paths for Clift .td includes 2025-06-04 15:13:47 +02:00
Pietro Fezzardi df3b4758e4 Add initModeTypesConsideringUses
Before this commit, initModelTypes always looked at uses of each
instructions to see if its knowledge of the instruction's model type
could be improved.

This is useful in some cases, but it's detrimental when building model
casts, because this requires to see the exact type computed for an
instruction.

This commit introduces a new function initModeTypesConsideringUses,
which works like old initModelTypes, considering uses.
In this way we can make sure that uses are considered when necessary,
like when computing types to build new local variables, and ignored when
necessary, e.g. when building model casts.
2025-05-29 09:38:01 +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 a4d45d0788 Add abi::FunctionType::Layout::argumentTypes 2025-05-28 17:11:11 +02:00
Pietro Fezzardi 7aab7ba843 Add abi::FunctionType::Layout::returnValueTypes 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 b106024a13 NameBuilder: fix artificialArrayWrapperNameImpl
This commit fixes a copy-paste error that unfortunately did not lead to
compilation errors, but caused null pointer dereference every time the
method was called with a model::PointerType or model::PrimitiveType
argument.
2025-05-14 10:15:14 +02:00
Pietro Fezzardi 76c63ae5b7 CommonTypeMethods: add getArrayElement 2025-05-14 10:12:03 +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 872d6016a5 Doxygen: allow suppressing newlines before 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 6fd6a0af43 Pipes: add a rank for raw stack arguments 2025-05-08 15:42:00 +02:00