Commit Graph

2117 Commits

Author SHA1 Message Date
Alessandro Di Federico cc28786000 DwarfToModelConverter: match existing functions
Unfortunately, in DWARF, there's no widespread indicator on whether a
function is regular ARM or Thumb. Therefore, in this commit, instead of
blindly creating a new function, we first check if, in the model, we
already have a function at that address.

This means that, if we have a Thumb function in DWARF, but it doesn't
already exist in the model, we will import as regular ARM, which is
wrong.
Specifically, this can happen with `revng model import debug-info`.
2026-05-15 11:27:34 +02:00
Alessandro Di Federico 7793543485 FindMissingTypes.h: split off findPrototype* 2026-05-15 11:27:33 +02:00
Roberto Bertolini 5dcd6334b3 Add Clift local variable scope tightening 2026-05-13 15:32:34 +02:00
Lauri Vasama 5d3e3f73d9 Add clift.require operation 2026-05-13 15:32:34 +02:00
Pietro Fezzardi 8de85c25a0 Remove array field of opaque struct types 2026-05-13 08:51:25 +02:00
Pietro Fezzardi abc3f45298 Drop duplicated BitCastOfBitCastPattern
This is now subsumed into CastCollapsingPattern.
2026-05-11 09:32:20 +02:00
Pietro Fezzardi da3ee051b9 Turn revng.stack_type into revng.stack_frame
The new named metadata doesn't embed the type of the stack anymore.
It's just a marker of the alloca that represents the stack frame.
2026-05-08 17:30:04 +02:00
Pietro Fezzardi dc23c6cf8b IRHelpers: add MST overload of dumpToString
Mirror the existing pointer overload of dumpToString but thread a
ModuleSlotTracker through to the underlying call, so that callers
can amortise slot-numbering work across many dumps. The new
overload returns "nullptr" when the input pointer is null,
matching the non-MST pointer overload.
2026-05-08 11:37:10 +02:00
Pietro Fezzardi a28e6b8b87 CliftTransforms: add BitCastOfBitCastPattern
Add a Clift expression-rewrite pattern that collapses
`(T2)(T1)x` into `(T2)x` when both casts are BitCastOps. A
matching mlir-lit test is added.
2026-05-08 11:37:10 +02:00
Pietro Fezzardi 51c5131554 Clifter.h: include Function.h instead of Module.h
The Clifter public header only needs llvm::Function, not the full
llvm::Module definition, so drop the Module.h include. This
shaves a non-trivial amount of compile time off the translation
units that depend on Clifter.h without pulling in Module.h
themselves.
2026-05-08 11:37:10 +02:00
Pietro Fezzardi 4f04d3c58d Drop !revng.variable_type metadata
Drop the !revng.variable_type metadata and the matching helpers,
along with the only place in the Clifter that still consumed them.
After the previous LVB cleanup nothing emits this metadata, and the
model variable type can be reconstructed from the alloca's array
type alone.
2026-05-08 11:37:10 +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
Pietro Fezzardi 306e8a93f1 Add OpaqueTypePrefix to model schema
Add an OpaqueTypePrefix string to the model configuration with
default `opaque_type_`. This is used to build the C name of the
artificial structs that wrap model array types and keeps the prefix
configurable alongside the other artificial-name prefixes.
2026-05-08 11:37:10 +02:00
Pietro Fezzardi 5a429d6f52 Add OpaqueType ranks
Define a new "opaque-type" rank in revng/Pipes/Ranks.h, keyed by
the byte size of the wrapped type. This rank is used by upcoming
commits to identify the artificial structs that wrap model array
types in Clift.
2026-05-08 11:37:10 +02:00
Pietro Fezzardi 81fd1a8b22 STS: use LLVM memory-access predicates
Replace the home-grown hasSideEffects, mayHaveSideEffects,
mayWriteToMemory and mayReadMemory helpers (in
DecompilationHelpers.h) with the equivalent predicates from
llvm::Instruction. The legacy code paths still need a few extra
checks, so the templated wrappers in SwitchToStatements.cpp
specialise on IsLegacy and fall back to the LLVM predicates in
non-legacy mode.

This removes the now-unused helpers from DecompilationHelpers.h.
2026-05-08 11:37:09 +02:00
Pietro Fezzardi 8ee6edfd15 Restructure LocalVariableBuilder
Reorganise LocalVariableBuilder so that the legacy and non-legacy
code paths are separated into two specialisations, and so that the
non-legacy specialisation does not need a model::Binary to operate.

This is a prerequisite for using LocalVariableBuilder from passes
that do not know about the model, e.g. unit tests for the new-PM
SwitchToStatements and the upcoming non-legacy decompilation
pipeline.
2026-05-08 11:37:09 +02:00
Pietro Fezzardi dc3f3f9c48 Add helpers for "revng.pointers" metadata
Introduce templated readers and writers for the "revng.pointers"
metadata in revng/Support/IRHelpers.h. The metadata is a pair of
boolean tuples describing, for an llvm::Function or llvm::CallInst,
which of its return values and which of its argument operands are
pointer-typed in the model. This is the model-agnostic
representation later passes (e.g. ArithmeticToGEP) consume to find
pointers without having to look at the model directly.
2026-05-08 11:37:09 +02:00
Lauri Vasama c7e3a12657 Add implicit cast elision pass 2026-05-04 10:49:07 +03:00
Lauri Vasama ad0c466d6d Remove revng/Support/CTarget.h 2026-05-04 10:49:06 +03:00
Lauri Vasama 04fe27b8e9 Migrate Clift users to CDataModel 2026-05-04 10:49:03 +03:00
Lauri Vasama dd4e452f96 Add data model import pipes 2026-05-04 10:48:16 +03:00
Lauri Vasama f6d2eaea4b Add Clift DataModelAttr 2026-05-04 10:48:03 +03:00
Lauri Vasama 9c5338913d Add TargetABI field in the model 2026-05-04 10:48:03 +03:00
Lauri Vasama 0ab9f769dd Add CDataModel in ABI definition 2026-05-02 17:21:47 +03:00
Lauri Vasama 27fb305c5a Add revng/Support/CDataModel
This structure describes the data model used by a C ABI.
2026-04-30 15:09:16 +03:00
Lauri Vasama 7f2bf61d10 Move cast collapsing rewrite to a separate set 2026-04-30 15:09:16 +03:00
Lauri Vasama 5a538c0f84 Add (*x).m -> x->m expression rewrite 2026-04-30 15:09:16 +03:00
Lauri Vasama e5fb446430 Rename BooleanNegations.h to Expressions.h 2026-04-30 15:09:16 +03:00
Lauri Vasama be564f8944 Migrate isIntegerType users to unwrapped_isa 2026-04-30 15:09:16 +03:00
Lauri Vasama 9dced83bd6 Add Clift IntegralType interface 2026-04-30 15:09:16 +03:00
Lauri Vasama b6283c8684 Add ExpressionRegionOpInterface on loops, branches 2026-04-30 15:09:16 +03:00
Lauri Vasama 7126513af8 Add CallOp::getFunctionType 2026-04-30 15:09:16 +03:00
Lauri Vasama 49cc67db11 Make DefinedType implement AddressableType 2026-04-30 15:09:16 +03:00
Lauri Vasama 5b13b6948c Add ScopedExchange::commit to persist the mutation 2026-04-30 15:09:16 +03:00
Lauri Vasama 4c97c6e7ab Make CAttributeListBuilder conversion explicit 2026-04-30 15:09:16 +03:00
Lauri Vasama c56742770b Use const ArrayRef in emitHelperHeader 2026-04-30 15:09:16 +03:00
Lauri Vasama b30b4feec9 Remove MLIRContext from TypeDefinitionEmitter API 2026-04-30 15:09:16 +03:00
Lauri Vasama 90e5dfd4c9 Pass MLIRContext by address
Passing by address is more conventional. This is what MLIR does most of
the time, and it avoids dereferences and addressofs everywhere.
2026-04-30 15:09:16 +03:00
Lauri Vasama ac5000b194 Add ModuleVisitor visitModuleOp call 2026-04-30 15:09:16 +03:00
Lauri Vasama 3d8d88096d Fix CIdentifierAttr formatting 2026-04-30 15:09:16 +03:00
Lauri Vasama 31c80b0625 Fix (&x)->m -> x.m expression rewrite 2026-04-30 15:09:16 +03:00
Lauri Vasama a338194eb7 Move namespace mlir::clift out of namespace mlir 2026-04-27 12:48:24 +03:00
Lauri Vasama 4b4d5a2c28 Fix clift::getOnlyUser 2026-04-27 12:48:24 +03:00
Alessandro Di Federico c1b3f23cf5 Uniform Binary::get{Definition,Binary}Reference 2026-04-24 17:54:09 +02:00
Alessandro Di Federico 2629f95dd1 Introduce ImportPrototypesFromDatabase
This commit introduces an analysis to import prototypes from a SQLite
database of well-known prototypes, typically built from debug info of
operating systems.

This analysis supersedes import-well-known-models.
2026-04-24 17:54:09 +02:00
Alessandro Di Federico 6894862ef2 Implement platform roots support
Refactor the binary import and dependency resolution infrastructure to
support multiple platforms (Linux, Windows, macOS) via a
configuration-driven root system.

Major changes:

* Overhaul PDB and DWARF importers for platform-aware debug info
  loading.
* Refactor LDDTree into a template-based architecture with
  platform-specific implementations (ELF, PE/COFF).
* Mostly rewrite the PDB importer, which had significant limitations.
2026-04-24 17:54:09 +02:00
Alessandro Di Federico 4a51b67700 TypeCopier: improve performance
This commit refactors `TypeCopier`. Among other things, it ensures we
invoke `initializeReferences` only in `finalize`, as opposed to every
time we invoke `copyTypeInto`.
2026-04-23 13:40:43 +02:00
Alessandro Di Federico 36a1295a8f Introduce Binary.getIdentifierBinaryReference 2026-04-23 13:40:43 +02:00
Alessandro Di Federico eb9e82477a Introduce WindowsApiSetSchemaParser 2026-04-23 13:40:43 +02:00