229 Commits

Author SHA1 Message Date
Pietro Fezzardi 53c39d32f2 DecompileFunction.cpp: drop support for allocas
Since when we added the -exit-ssa pass, allocas are never supposed to
reach the C backend anymore.
This commit drops the code that supports them, that was effectively dead
code since a quite long time.
2023-04-04 09:33:22 +02:00
Kacper Kołodziej c61c59c474 Handle StringLiteral tag in DecompileFunction 2023-04-04 09:31:10 +02:00
Ivan Krysak 47213e1669 Backend: remove an obsolete log file 2023-03-15 10:28:24 +01:00
Ivan Krysak 85fcd92f0e Backend: reword a comment 2023-03-15 10:28:24 +01:00
Ivan Krysak c2f0fc19e5 ABI: FunctionType.h -> FunctionType/Layout.h 2023-03-15 10:28:24 +01:00
Djordje Todorovic 5482083e79 DecompileFunction.cpp: print debug info in PTML 2023-03-08 09:57:48 +01:00
Pietro Fezzardi f3e466c989 DecompileFunction.cpp: fix format for int literals 2023-03-01 12:22:35 +01:00
Kacper Kołodziej 5b94a5a649 HelpersToHeaders: skip unnecessary helpers 2023-02-07 17:43:05 +01:00
Pietro Fezzardi 97b23935de Handle FunctionTags::Exceptional
This is necessary for e.g. the abort function.
2023-01-17 11:14:47 +01:00
Kacper Kołodziej 568bd24900 Add UnaryMinus and BinaryNot 2023-01-09 15:01:16 +01:00
Andrea Gussoni 80ea234167 Fix ContinueNode emission 2023-01-05 16:33:21 +00:00
Pietro Fezzardi e9d84264ff Reduce the number of emitted local variables in C
This commit does various things oriented at reducing the number of local
variables emitted in C:
- MarkAssignments now know that @Copy and @Assign involving
  @LocalVariable only have side effects that affect the local variable
  itself; this enables to reduce the number of times we're forced to
  emit a local variable due to interfering side effects
- Drop the @AssignmentMarker FunctionTag; AddAssignmentMarkerPass now
  doesn't emit @AssignmentMarker anymore; instead it emits groups of
  @LocalVariable, @Copy, and @Assign, which benefit from the previous
  point
- Drop 2 MarkAssignments::Reasons: HasManyUses and HasUsesOutsideOfBB;
  both these have now been aggregated into the AlwaysAssign reason for
  simplicity, representing all reasons non involving side effects
- Update BeautifyGHAST and how it reasons about side effects when
  beautifying; before this commit it used @AssignmentMarker, now it
  looks at @Assign
- Simplify ExitSSA; before this commit it was trying hard to be smart on
  where it emitted the store instructions representing the incoming
  values of the PHI that was being destroyed; this seemed smart when we
  originally did it but it generated C code that was not really better
  to read, so this useless complexity is finally gone
2022-12-24 02:47:10 +01:00
Pietro Fezzardi c201990e5b Print stack variable at beginning of function body 2022-12-24 02:44:38 +01:00
Massimo Fioravanti 87aef3fbad revng-c now uses Model accessors 2022-12-12 11:35:52 +01:00
Pietro Fezzardi de0b22a842 DecompileFunction.cpp: avoid useless newline 2022-12-05 15:59:42 +01:00
Pietro Fezzardi e1d8d4ff9e DecompileFunction.cpp: fix hexLiteral
formatv("{0:x}", Int) was printing the address of the integer, not the
integer itself.
2022-12-02 14:40:09 +01:00
Kacper Kołodziej 83ab07d7fb Enable printing integers as bool, hex or char
This commit adds a new pass, PrettyIntFormatting, that injects calls to
decorator functions print_hex, print_char, and print_bool around
llvm::ConstantInt in various situations.

It also updates the rest of passes of the decompilation pipelin to
understand these new decorator functions and to properly emit decorated
integer literals in the decompiled C code.
2022-12-02 10:08:00 +01:00
Pietro Fezzardi ee0dc97464 Uniform printing return types of functions 2022-11-30 18:16:13 +01:00
Pietro Fezzardi 389a184fc2 Handle CABIFunctionTypes returning struct types 2022-11-30 18:16:13 +01:00
Alessandro Di Federico 800b8e6f16 DecompileFunction: handle string literals
We now emit global variables that are NULL-terminated strings inline.
2022-11-30 18:16:13 +01:00
Pietro Fezzardi d34abf3706 DecompileFunction.cpp: fix ModelGEP traversal
handleSpecialFunction was still traversing Qualifiers in the wrong
order.
2022-11-30 18:16:13 +01:00
Pietro Fezzardi 2ab5b5d9bf Fix handling of UndefValue and PoisonValue 2022-11-30 18:16:13 +01:00
Ivan Krysak 033ccbe51a Adopt FunctionType::Layout to improve CABI support 2022-11-30 18:16:13 +01:00
Ivan Krysak 654afbef0c Move pointer creation away from model::Binary 2022-11-30 18:16:13 +01:00
Massimo Fioravanti 335d402245 Change signatures to forward metadata cache. 2022-11-22 12:27:02 +01:00
Pietro Fezzardi e72a578743 Refactor PTML generation for local variables 2022-11-16 11:24:37 +01:00
Pietro Fezzardi a23d4f8dcf Ranks.h: simplify ranks, delete unnecessary ranks 2022-11-15 15:54:20 +01:00
Pietro Fezzardi 7ab10df8f9 Remove useless location definitions for arguments
The actual ptml::attributes::LocationDefinition for arguments is already
generated when emitting the prototype of the functions.
The removed calls were just serializing the location definition once
more and disposing of it without serializing it anywhere.
2022-11-15 15:54:20 +01:00
Pietro Fezzardi ff631c5364 PTMLC.h: switch to string-based return values 2022-11-15 15:54:20 +01:00
Pietro Fezzardi c93392fa3b Refactor PTML generation for helpers 2022-11-15 15:54:20 +01:00
Pietro Fezzardi e1ded3a479 HelpersToHeader: refactor PTML Tags 2022-11-15 15:54:20 +01:00
Pietro Fezzardi 690056a4a6 DecompileFunction.cpp: refactor PTML Tags 2022-11-15 15:54:20 +01:00
Pietro Fezzardi 2ec8b7e32c ModelToHeader: refactor creation of PTML Tags 2022-11-15 15:54:20 +01:00
Pietro Fezzardi 4b4531027b DecompileFunction.cpp: support PoisonValue 2022-11-10 13:05:51 +01:00
Pietro Fezzardi 0f8c07e71a DecompileFunction.cpp: fix typedef traversal
Before this commit, to emit field member accesses and array accesses in
C we performed a broken traversal of typedefs.
It was buggy since its inception but it was never triggered because no
typedefs actually reached this point.

This commit fixes that using the reworked peelConstAndTypedefs
machinery.
2022-11-09 12:02:26 +01:00
Pietro Fezzardi 25119c4377 Drop bugged addPointerQualifier for getPointerTo
This commit removes the bugged addPointerQualifier helper function,
that was wrongly pushing the pointer qualifier at the end.

Instead, we now use the correct model::Binary::getPointerTo method.
2022-10-21 09:45:28 +02:00
Giacomo Vercesi 72050274e2 getNamedCInstance: drop declaration parameter
In all cases this is false
2022-10-11 17:36:29 +02:00
Giacomo Vercesi e53033d0b8 Ranks: remove use of TypeField in locations
Use the new Ranks made available by revng
2022-10-11 17:36:29 +02:00
Massimo Fioravanti f1852166ab Pipeline: reworked cpp container types 2022-10-03 14:26:06 +02:00
Alessandro Di Federico e430891ef6 CCodeGenerator: do not generate %name
In certain code paths, CCodeGenerator would trigger the emission of
`%[number]`, which is very expensive since it requires to assign an ID
to a large amount of `llvm::Value`.

This commit ensure this doesn't happen, unless a logger is active.
2022-09-27 11:47:26 +02:00
Giacomo Vercesi 8e996d2394 Output PTML in revng-c
Change the output of the backend of revng-c to PTML
2022-09-01 16:59:29 +02:00
Antonio Frighetto 19d7f8b2c9 Late decompilation: support model::Segment
Backend and InitModelTypes now handle the opaque `segmentRef` marker.
2022-07-19 13:53:21 +02:00
Alvise de Faveri cbeb006e11 Backend: Check that AddressOf is never a cast 2022-07-15 17:17:04 +02:00
Alvise de Faveri c2481aeb7b Support: Add deserializeFromLLVMString
Instead of having `paseQualifiedType` and `parseAndDeserialize`,
we now have a single function that is symmetric to
`serializeToLLVMString`.
2022-07-15 17:17:04 +02:00
Giacomo Vercesi 1f69e58af8 DecompileFunction: Add indentation to C code
Add proper indentation to the generated C code with the use of
mlir::raw_indented_ostream
2022-06-28 11:26:41 +02:00
Alvise de Faveri 2ffa537605 IRCanonicalization: Add Copy()
Use the `Copy` opcode to substitute load instructiobs.
2022-06-28 10:28:38 +02:00
Pietro Fezzardi d9d9294fe5 MarkAssignment: fix taint set and aggregate types 2022-06-28 10:28:08 +02:00
Alvise de Faveri 6b258c83a1 IRCanonicalization: Fold ModelGEP(AddressOf())
- `FoldModelGEP` folds `ModelGEP(AddressOf())` into `ModelGEPRef`
- `RemoveRefDeref` remove `ModelGEPRef`s with no arguments
2022-06-28 10:26:50 +02:00
Alvise de Faveri 123a1777cd IRCanonicalization: Add RemoveLoadStore pass 2022-06-28 10:25:49 +02:00
Alvise de Faveri f7866ddd85 IRCanonicalization: Add MakeLocalVariables pass 2022-06-28 10:24:48 +02:00