Commit Graph

2366 Commits

Author SHA1 Message Date
Alessandro Di Federico d8e41028b7 RegisterClobberer -> OpaqueRegisterUser
Extend RegisterClobberer to support also performing opaque reads.
Also, record all the generated instructions for easy purging.
2023-12-11 16:29:13 +01:00
Alessandro Di Federico 02458724b0 Drop CallSummarizer::RegistersClobberedPool 2023-12-11 16:29:13 +01:00
Giacomo Vercesi 8504a96020 RawFunctionType: use NamedTypedRegister for return
Use the `NamedTypedRegister` type for return values in
`RawFunctionType`. This allows return values to be renamed at the user's
discretion.
2023-12-11 12:03:45 +01:00
Giacomo Vercesi 194bcecc41 Drop getReturnField
Drop the `getReturnField` helper, the cases in which it was used are now
covered by the `NamedTypeRegister::name` method.
2023-12-11 10:21:40 +01:00
Giacomo Vercesi fd24487666 C code: fix location for RawFunction return struct
Fix the needed attributes to allow navigation from the use of an
artificial return struct for raw functions to their definition in
`types-and-globals.h`.
2023-12-11 10:21:40 +01:00
Pietro Fezzardi 1c5e8371a7 DLA: add isNonStridedInstance helper 2023-12-05 16:59:08 +01:00
Alessandro Di Federico 10dcb7be11 Fix semantics of model::Types purging passes
One of the two passes to purge unused types from the model had a
ill-defined semantics.

This commit simplifies them in two passes: one that purges all the types
unreachable from outside `Binary::Types` and one that does the same but
also preserves types with a `CustomName` or an `OriginalName`.
2023-12-05 16:19:39 +01:00
Pietro Fezzardi bbcb4df839 TypeSystemPrinter: print segment types 2023-12-05 16:19:39 +01:00
Pietro Fezzardi 1285c6e7af Make RawFunctionType::StackArgumentsType a TTR
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:19:38 +01:00
Pietro Fezzardi 48b27af795 Make Segment::Type a TupleTreeReference
This is homogeneous with all other nullable reference to types in the
model, like the StackFrameType in model::Function, and others.
2023-12-05 16:19:38 +01:00
Andrea Gussoni 078cc1222a InlineDispatcherSwitch: introduce beautify pass
We introduce the `InlineDispatcherSwitch` beautify pass. Its goal is to
try and inline the body of some of the `case`s of a exit dispatcher, in
place of the `SetNode` corresponding to that `case`, if this doesn't
introduce duplication in the code (i.e., a single `SetNode` for that
specific case value is present).

Additionally, if the inlining procedure is able to completely remove the
necessity of an exit dispatcher altogether, the pass removes it.

The pass is able to handle chains of weaved dispatcher `switch`es
referring to the same original dispatcher `switch`, by handling the
inline operation and the possible simplification level-wise.

The inlining procedure, cannot take place if a `SetNode` is contained in
the body of the case we are trying to inline, since this can possibly
break the semantics of the state variable of a loop, by placing a
`SetNode` in a more internal loop.
2023-11-28 16:19:08 +01:00
Andrea Gussoni ca422bafd2 PromoteCallNoReturn: introduce beautify pass
We introduce the PromoteCallNoReturn beautification pass. Its goal is to
restructure sequence of statements, in order to have `call`s to
`noreturn` functions as _inlined_ in the middle of the statement
sequence, and leave _non local control flow statements_ at the end of
that scope. E.g., we prefer:
```
if (cond)
  call noreturnfunc();
return;
```
to
```
if (!cond)
  return;
call noreturnfunc();
```

In order to do this, contextually, we restructure the routine computing
the `fallthrough` property, in order to be able to differentiate between
the _non local control flow statements_, a call to a `noreturn`
function, or a generic mix of the two (useful when combining results
from the two situations above).

The new analysis is also used in the `promoteNoFallThrough` promotion
pass.
2023-11-28 16:19:08 +01:00
Andrea Gussoni 1b19e5a9ef ASTNode: introduce DispatcherKind attribute
Introduce the `DispatcherKind` attribute as a field in the
`BasicBlockNode` and `ASTNode` classes, in order to be able to
distinguish entry and exit dispatchers, and the related set nodes.
2023-11-28 16:19:08 +01:00
Andrea Gussoni 1e8b37ce51 ASTNode: remove unused SwitchNode constructor 2023-11-28 16:19:08 +01:00
Pietro Fezzardi 3e49213b43 Drop needsTopScopeDeclaration hack
This commit drops `needsTopScopeDeclaration`.
Now all the LocalVariables are declared at the top of the function.
In DecompileFunction.cpp, the emission of LocalVariables if handled at
the scope of GHAST `ASTNode`s instead of being LLVM BasicBlock-based.
This enables in the future to design and implement an analysis that for
each LocalVariable decides the C scope (represented by an `ASTNode`)
where it's declaration should be emitted to always be visible in all its
uses.
2023-11-28 15:46:19 +01:00
Pietro Fezzardi 83f0457a7f Add getNonConst helper
This function returns the first non-const qualified view of a
model::QualifiedType.
2023-11-27 18:02:21 +01:00
Pietro Fezzardi dd8049abcc Add LiteralPrintDecorator Tag
This Tag is used to tag all the funcitons that we use to decorate
integer literals to decide how to print them.
Using a single Tag shared among all the decorators enables more concise
code to handle it.
2023-11-20 22:36:39 +01:00
Massimo Fioravanti fdf5cf0325 Fix incorrect usage of TaggedFunctionKinds
A bug in revng allowed to use any TaggedFunctionKinds in place of any
other one. That bug has been fixed and the wrong usages in revng-c have
been updated.
2023-11-06 14:35:06 +01:00
Pietro Fezzardi 2b2b7e3123 RegionCFG: drop old unused PDT and IFDT fields 2023-11-06 13:50:54 +01:00
Giacomo Vercesi da144f1fee revng trace run: allow providing resume directory
Allow the `revng trace run` to provide a resume directory from the
command line to use when creating the first manager.
2023-11-03 18:29:10 +01:00
Giacomo Vercesi 6d03b5874e InitRevng: HideUnrelatedOptions only when provided
Avoid calling `HideUnrelatedOptions` in InitRevng if the
`CategoriesToHide` option is empty.
2023-11-03 18:29:10 +01:00
Giacomo Vercesi 68f71c3b39 Adopt new PTML tags
Change the emitted decompile code to include the
`data-action-context-location` and `data-name-of` tags.
2023-11-03 16:31:06 +01:00
Giacomo Vercesi 94efdc142a Drop model::editPath helpers
With the introduction of `data-action-context-location` the helpers in
the `model::editPath` namespace are no longer needed.
2023-11-03 16:31:02 +01:00
Giacomo Vercesi db1691b03f Adopt new PTML tags
Change the emitted disassembly to include the
`data-action-context-location` and `data-name-of` tags.
2023-11-03 16:30:40 +01:00
Giacomo Vercesi 94aa2b51d2 Add Context Global Index 2023-11-03 12:13:58 +01:00
Giacomo Vercesi 04698bb550 Return invalidations when deserializing container
When deserializing a container in the pipeline, return the invalidations
that have been caused by the container changing content.
2023-11-03 12:13:58 +01:00
Giacomo Vercesi 56af9c1f9d Propagate errors from Analysis/Pipes to daemon
Leverage the `rp_error` mechanism to propagate errors from analyses and
pipes to the GraphQL schema.
2023-11-03 12:13:58 +01:00
Giacomo Vercesi 3b0d708a2f Drop custom globals mutator from PipelineC
Remove globals mutator from PipelineC api, as there are analyses present
that allow changing them.
2023-11-03 12:13:58 +01:00
Giacomo Vercesi 4f94988a4d Add Globals Analyses
Add analyses that allow the modification of globals via the analysis
mechanism of Pipeline.
2023-11-03 12:13:58 +01:00
Giacomo Vercesi 37adeb7eeb Pipeline options: introduce -path options
In the case of string options, the pipeline will also create a `-path`
option, which makes the option contents from reading the specified file.
2023-11-03 12:13:58 +01:00
Giacomo Vercesi acd498bf25 Pipeline options: restrict to int and strings
Restrict the type of pipeline options to integers and strings. Rework
the CLOpt mechanism to avoid parsing the string twice.
2023-11-03 12:13:57 +01:00
Giacomo Vercesi fec3d1d92e StorageClient.h: remove mention of dummy client 2023-11-03 12:13:57 +01:00
Giacomo Vercesi 94eb1a1d43 Prototypes.h: drop old LENGTH_HINTS
Remove `LENGTH_HINTS` that are no longer applicable to the API exposed
by PipelineC.
2023-11-03 12:13:57 +01:00
Giacomo Vercesi ca0a6f82eb Global.h: remove dead code
Remove the `HasVerify` concept as it is a leftover that's currently
unused.
2023-11-03 12:13:57 +01:00
Giacomo Vercesi 6f4fa9853a Assert.h: drop dead code
The `AbortHook` functionality has been dropped since `7fda1ef4`, but the
header declarations were not removed.
2023-11-03 12:13:57 +01:00
Andrea Gussoni eed117f75d ASTNode: fix updateASTNodesPointers method
Fix the `updateASTNodesPointers` method for the `SwitchBreakNode` class,
updating the `ParentSwitch` field.
2023-11-03 11:44:09 +01:00
Ivan Krysak 65fa67df84 YAMLTraits: specialize for std::byte 2023-11-02 17:10:04 +01:00
Ivan Krysak 775852c6c9 ABI: fix a problem with return value location
If the location was not also used a normal argument, it would get lost
when sorting argument registers.
2023-11-02 17:10:04 +01:00
Ivan Krysak dbc99ff587 ABI: improve a register sorting error message 2023-11-02 17:10:03 +01:00
Ivan Krysak cfe28d8e56 Stop using std:: prefix for u?int\d+_t types 2023-11-02 17:10:03 +01:00
Giacomo Vercesi ce446576a4 Fix typos 2023-11-02 16:49:49 +01:00
Giacomo Vercesi 0cb3e497a4 Fix typos 2023-11-02 16:48:33 +01:00
Andrea Gussoni 3e13765267 BeautifyGHAST: handle noreturn calls in beautify
Improve the `fallThroughScope` computation, in order to handle calls to
`NoReturn` functions in the analysis, representing the fact that they
induce a `noFallthrough` scope (i.e., execution will not ever resume
after the call, and therefore we can later improve the nesting of the
code with the `promoteNoFallthrough` pass).
2023-10-23 18:16:20 +02:00
Andrea Gussoni 733f5008b3 BeautifyGHAST: implement DualSwitch simplify
We introduce a simplification step, which looks for `switch`es that can
be reduced to simpler `if` statements.

Specifically, the logic is the following:
1) When we identify a `switch` statement composed by a single `case` and
   a possible default, we transform it into an `if` with the `case` now
   corresponding to the `then`, and the `default` corresponding to the
   `else`, if present.
2) When we identify a `switch` statement composed by two `case`s, and no
   `default` is present, we can promote it to an `if` with `then` `else`
   branches.

Other key details:
- The promotion happens only if we can identify at least one of the
  `case`s that have a single element in the `case` label. If this is not
  the case, we do not promote one to RHS of the `if` condition.
- A new `CompareNode` class, inheriting from `ExprNode`, is created, in
  order to represent the equality or inequality condition of an `IfNode`
  instance that is the result of the promotion. This `CompareNode` can
  represent for the LHS both an `llvm::Value` or the `loop_state_var`,
  while it embeds the RHS constant which completes the comparison.
- We remove `SwitchBreak` AST nodes that may now appear as children of
  an `if` node promoted from a `switch`.
- We introduce in the `CompareNode` the `weaved` concept. Indeed, if a
  promotion of a weaved `switch` happens, we should avoid the
  serialization of the instructions leading to the computation of the
  condition of the original `switch`, because they have been already
  emitted by the main related dominating `switch`.

We also introduce an additional simplification step, which takes care
of:
- Promoting `!(==)` to `(!=)` and `!(!=)` to `(==)`, if the inner
  equal/not equal is represented via a `CompareNode`.
- Promoting `x == 0` to `!x` and `x != 0` to `x`.

To be able to correctly emit (or not) the instructions computing a
condition of an `IfNode`, we need to add the `EmittBB` flag, an
additional parameter to the `buildGHASTCondition` function, which
controls the emission of the statements of a basic block computing a
condition.

Consequently, the `IfNode` acquires a `IsWeaved` field, which is used to
mirror the property having the same name on `SwitchNode`. Being now
possible a promotion from a dual `SwitchNode` to an `IfNode`, we need to
represent this property on the `IfNode` too.
2023-10-23 18:16:20 +02:00
Andrea Gussoni 2cef075697 ASTNode: refactor default in SwitchNode
The `default` `case` is now a standard `case`, and it is identified only
by having the `label` set empty.

Therefore, a list of beautify and transformation actions now do not need
special casing in order to handle the `default` `case`, which is reached
during the standard iteration over the `case`s.

A special accessor is still necessary, in order to correctly emit the
`default` `case` in the backend.
2023-10-23 18:16:20 +02:00
Andrea Gussoni 061bc52bc2 BeautifyGHAST: implicit statements simplification
Introduce implicit statements simplification phase, specifically:
- A implicit `return` simplification: `return` statements in `void`
  type functions, which are not followed by any other scope, can be
  omitted.
- A implicit `continue` simplification: `continue` statements whose
  fallthrough leads directly to the end of the cycle scope (i.e., to
  execute another iteration of the enclosing loop), can be omitted.

In order to avoid the printing of the implicit `return`, we need an
additional `emitReturn` parameter in the `emitBasicBlock` method of the
`CCodeGenerator` class.
2023-10-23 18:16:20 +02:00
Andrea Gussoni a2e51a191c ASTNode: remove IsEmpty field from ASTNode
Remove the `IsEmpty` field from the `ASTNode` class, since that
information is redundant.
2023-10-23 18:16:20 +02:00
Andrea Gussoni 4c461c24ac ASTNode: uniform nodes printing syntax
Now, also `break` and `continue` on the AST, when printed, have the ID
number of the `ASTNode`, and in the name they preserve the original
`CFGNode` one also.
2023-10-23 18:16:20 +02:00
Andrea Gussoni f98e72d9a7 BeautifyGHAST: move SimplifyHybridNot header 2023-10-23 18:16:20 +02:00
Andrea Gussoni effbb461fd GenerateAST: improve UntangleWeight explanation 2023-10-23 18:16:20 +02:00