229 Commits

Author SHA1 Message Date
Alvise de Faveri da46b38644 Backend: Various improvements to variables declaration 2022-06-28 10:24:18 +02:00
Alvise de Faveri a31fd8587d AssignmentMarker: Handle variables scoping
If we find values to be used outside their scope, we need to always
mark them for assignment, so that they have a dedicated variable that
is declared in the right scope. To do this we:

1. Export the logic that decides if a value needs a top-scope variable
in a public header, to be used by both `VariableScopeAnalysis` and
`MarkAssignments`.
2. Add the `HasUsesOutsideBB` reason for assignment markers
2022-06-28 10:13:07 +02:00
Alvise de Faveri de334a92e9 Backend: Make IntToPtr and PtrToInt transparent 2022-06-28 10:12:22 +02:00
Alvise de Faveri 66c243c46d Backend: Don't emit "undef" when logging
Since the InlineLogger is emitted inside a `/* */` comment, we should
not emit the undef comment there.
2022-06-23 11:23:34 +02:00
Antonio Frighetto 97e79783ae Backend: handle Parentheses and ModelCast markers
`DecompileFunction` now handles the opaque `parentheses` and
`ModelCast` markers as part of beautifying the decompiled code
with proper parenthesized expressions. Should OPRP not be enabled,
we fallback to the case in which parentheses are always emitted.
2022-06-15 10:28:50 +02:00
Pietro Fezzardi ad81bc7020 Enable addtional compilation warnings
These warnings are not enabled by default with -Wall nor with -Wextra.
2022-06-14 12:48:54 +02:00
Alvise de Faveri b13286cf04 Backend: Fix buildCastExpr() conditions 2022-06-13 15:20:57 +02:00
Alvise de Faveri c65b172af6 Backend: Emit '\n' after while loops 2022-06-13 15:18:22 +02:00
Alvise de Faveri fe09f519f7 Backend: Fix callee parentheses in indirect calls 2022-06-13 15:16:51 +02:00
Alvise de Faveri 91f9a17e4a Backend: Add cast to return value 2022-06-01 11:37:25 +02:00
Alvise de Faveri dd6ef1d4a8 Backend: Improve parenthesis 2022-06-01 11:35:50 +02:00
Alvise de Faveri 06d72f1cd9 Backend: Improve logging 2022-06-01 11:34:18 +02:00
Alvise de Faveri 51df8ad64d Backend: Fix select emission 2022-06-01 11:29:09 +02:00
Pietro Fezzardi 18b9e481c8 Backend: fix emission of integer constants
Before this commit we were using a suboptimal API that often resulted in
expressions with many zeros for the 0 constant, e.g. 0000000 instead of
just 0.

This commit fixes the problem.
2022-05-31 12:40:52 +02:00
Pietro Fezzardi 229648a6cb Backend: fix casts in assignments expressions
Before this commit source and destination types were swapped.
2022-05-31 12:40:52 +02:00
Pietro Fezzardi 4ed636cbba Support emission in C of null pointers 2022-05-31 12:40:52 +02:00
Pietro Fezzardi 35e0e688d2 Support emission in C of integer or pointers undef 2022-05-31 12:40:52 +02:00
Pietro Fezzardi 4188b709be Merge BeautifyGHAST back into RestructureCFG
The beautification library was split into a separate library for
historical reason, having to do with LLVM passes, their dependencies,
and dirty hacks we had around.

Now the LLVM passes, and the hacks are gone, so we can merge back
everything together.
2022-05-11 15:19:34 +02:00
Pietro Fezzardi d8d7779a37 DecompileFunction.cpp: improve logging 2022-05-11 15:19:34 +02:00
Pietro Fezzardi 29afe90460 DecompileFunction.cpp: skip over empty functions
This is necessary because with the port to revng-pipeline there will
be isolated functions with empty bodies.
2022-05-11 15:19:34 +02:00
Pietro Fezzardi 604d370239 Remove LLVM passes RestructureCFG, BeautifyGHAST
Now that the late stage of the decompilation pipeline is managed with
revng-pipeline, and we have a standalone tool for decompilation, we
have no need to use LLVM passes anymore for those stages.

This commit also renames the directories to avoid the confusing Pass
suffix, not what LLVM passes are gone.
2022-05-11 15:19:34 +02:00
Pietro Fezzardi fc40f646a4 Replace CBackendPass with revng-decompile tool
This commit replace the old CBackendPass with a standalone tool:
revng-decompile.
This pass at the moment runs the three stages of decompilation:
  - CFG restructuring
  - Beautify GHAST
  - C Code generation
2022-05-11 15:19:25 +02:00
Pietro Fezzardi 238b98c3da Switch all revng-c to revng-pipeline 2022-05-11 12:42:38 +02:00
Pietro Fezzardi 5071fe8dc4 Add CDecompilationPipe 2022-05-11 12:42:38 +02:00
Pietro Fezzardi 2c9829f042 Backend: skip dumpToString call when Loggers off
This brings a huge speedup to the new decompiler backend.
2022-04-26 18:12:08 +02:00
Pietro Fezzardi 55a23079da DecompileFunction: fix switch state variables 2022-04-26 10:18:46 +02:00
Pietro Fezzardi b909bb6629 New MarkAssignments library in IRCanonicalization
This library replaces the old AddIRSerializationMarkers, cleaning up a
lot of historcal baggage, merging Liveness and MarkAnalysis, and
adopting a more accurate naming across all the codebase.
2022-04-21 18:13:51 +02:00
Pietro Fezzardi 65c3460be1 Fix coding conventions 2022-04-20 18:06:53 +02:00
Alvise de Faveri e875b7f1c6 Add string-based C backend 2022-04-20 17:35:05 +02:00