Commit Graph

67 Commits

Author SHA1 Message Date
Alessandro Di Federico bf433d96f8 Drop rc_run
Recent updates in recursive coroutines handling no longer requires the
`rc_run` macro.
2021-05-06 10:37:56 +02:00
Pietro Fezzardi 572e04751f CDecompilerAction: fix parens in negateExpr 2021-04-27 21:19:06 +02:00
Pietro Fezzardi 36a525314a Detect isolated functions using FunctionTags 2021-04-27 21:19:06 +02:00
Pietro Fezzardi f49a8ce1e2 CDecompilerAction: fix order of type declarations 2021-04-01 12:51:02 +02:00
Pietro Fezzardi 42531f1701 Decompiler: avoid code duplication in do-while
When printing do-while loops in C, we wrongly emitted redundant
statements before the `do`, representing computation necessary for
evaluating the exit condition from the loop.

These statements were duplicated at end of the loop body, and were
entirely redundant before the `do`.
This commit removes them.
2021-03-29 17:49:25 +02:00
Pietro Fezzardi e95c21db25 Use Model to detect isolated functions 2021-02-23 10:39:05 +01:00
Pietro Fezzardi 148119c528 PromoteStackPointer: make local sp aligned 2021-02-09 15:07:04 +01:00
Pietro Fezzardi b98228eed0 Fix generation of bool typedef in C 2021-02-04 14:33:41 +01:00
Pietro Fezzardi ba0e57e956 DeclCreator: unify type mapping 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 821b430f40 Collapse FunctionDecls map into GlobalDecls map 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 3f1ee6ea64 Stub of DLA integration in Clang AST emission 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 088015e11c Forward SCEV and DLA results to decompilation 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 9d1d6afe6e MarkForSerialization: extract into its own Pass 2021-02-02 11:23:53 +01:00
Pietro Fezzardi f642a0983c Decompiler: make NDuplicates a const reference 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 2ff7044bb9 Decompiler: forward-declare types coming from DLA
This commits enable the emission of rich types associated with function
signatures. This types are forward-declared in the decompiled C code
before the definition of each decompiled function that uses them.

The types we emit for now are the types that the DLA is able to compute
(if any) for the return values and the arguments of the function.

Such types are not yet used in the body of the function, nor in the
function declaration. These are the next steps to come.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi b9c17362dd Decompiler: handle emission of logical operators
Before this commit, logical operators (&&, ||, !) were never emitted in
C. Bitwise operators were used instead (&, |, ~), relying on the
implicit equivalence of meaning.

This commit enables the emission of logical operators when the operands
are boolean types, making the emitted C more readable.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi ca999a7c3c Add DeclCreator class to unify forward declaration
Before this commit, the logic to generate all the emitted C forward
declarations (types, global variables, and functions) that has to be
printed before each decompiled function was scattered across three
classes: FuncDeclCreationAction, TypeDeclCreationAction, and
GlobalDeclCreationAction.

These are all gone now, because the scattered logic was very confusing
to follow. Now we only have a single class that takes care of
declarations with global scope: DeclCreator.

Thanks to this, I was able to drop a bunch of useless layers of software
engineering used to shape the creation of the declaration as if it was
some kind of clang ASTConsumer, which is pointless.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi 1e825a8201 Create IRASTTypeTranslator class
This class handles the creation of type declarations in clang's AST, and
holds the relationships between llvm Types and Values with those clang's
type declarations.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi cbbbdf660f [DLA] propagate DLA results to CDecompilerPass 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 93d9cbb67b Enforce new include conventions 2020-11-12 18:00:45 +01:00
Alessandro Di Federico 37fde04594 Move licensing details to LICENSE.md 2020-11-09 10:03:33 +01:00
Pietro Fezzardi 217a18edb1 Update copyright notice 2020-11-06 15:07:45 +01:00
Pietro Fezzardi 90ff17f107 Fix handling of switch default in GHAST 2020-11-04 09:32:36 +01:00
Pietro Fezzardi 2e7b6d171f CDecompilerAction: use logical not in if stmts
This commit fixes some warnings due to the wrong emission of bitwise not
instead of logical not in condition of if statements.
2020-11-02 18:33:57 +01:00
Pietro Fezzardi ecd9ac991f CDecompilerAction: fix print of conditional blocks
This commit fixes an issue that caused to emit duplicated statements
for BasicBlocks that terminated with a conditional branch.
This was caused by a redundant call to `buildStmtsForBasicBlocks()`
inside `createCondExpr`, that has now been removed.
2020-11-02 18:33:57 +01:00
Pietro Fezzardi 27f850e433 GlobalDeclCreationAction: fix short literals
Before this commit, when GlobalDeclCreationAction needed to emit
literals for initialization of global variables, it did it using
custom code.
This was not working properly, an in some cases it emitted short
literals which are not allowed in C.
Hence the generated C code that was impossible to recompile without
syntax errors.

This commit fixes this problem, using the getLiteralFromConstant method
of StmtBuilder.
In order to do this, we need to make the StmtBuilder available inside
the GlobalDeclCreationAction, which is not a very clean design.
However, we are already planning to merge the GlobalDeclCreationAction
and the StmtBuilder class, so this issue will be taken care of in the
future.
2020-10-29 14:27:38 +01:00
Andrea Gussoni 3128c1a4b6 Factor generateAST out as function 2020-10-26 14:07:54 +01:00
Pietro Fezzardi 3286789a9e SwitchNode: fix embedding of original BasicBlock
Before this commit, the original llvm BasicBlock was not embedded
properly in the GHAST SwitchNodes. This caused problems and crashes in
decompilation.

This commit SwitchNode constructors so the that the BasicBlock properly
reaches the GHAST and it is printed correctly by the decompiler.
2020-07-23 18:51:15 +02:00
Pietro Fezzardi 6d10120e2e Decompiler: fix emission of code before branches
Before this commit, the C statements before an IfNode or a SwitchNode
were not guaranteed to be emitted if they were not involved in the
computation of the branch condition.

This commit fixes this problem.
2020-07-22 17:27:02 +02:00
Pietro Fezzardi fc98fc69f5 Fix detection of isolated functions using metadata 2020-07-22 17:27:02 +02:00
Pietro Fezzardi 1a9ae59e4a RestructureCFG: major refactoring of switches
Now edges have sets representing labels.
There's no distinction between Dispatchers and Regular switches at the
GHAST level anymore.
2020-07-20 19:02:19 +02:00
Pietro Fezzardi f7e8599c5e Enforce check-conventions.sh
All commits should pass check-conventions.sh from now on.
2020-06-15 15:40:02 +02:00
Andrea Gussoni afa0cfbab4 Emit actual case values for regular switches
We now emit `RegularSwitch` node type creating the vector containing the
case values by inspecting the actual values of the `ConstantInt` in the
IR.

Due to the introduction of weaving, we can have a cascade of switches,
and in this case the top switch should bring to a certain weaving switch
for multiple values of the case label.
For this reason, switch case are now represented by sets, which are
usually populated by a single value, but in presence of a weaving
switches they can represent the fact that for each value contained in
the set we must take a certain case label.
The backend of the decompiler has been updated to reflect this change,
in order to emit all the values for a certain `CaseSet` in `or` if the
size of the seat is greater than 1.
2020-06-15 15:06:23 +02:00
Andrea Gussoni 95dbc22a36 Remove IfDispatcherNode
Remove the `IfDispatcherNode` from the hierarchy of the `ASTNode`s.
Disable the beautify routines since they are not relevant anymore.
2020-06-15 15:06:23 +02:00
Andrea Gussoni a264117aac Rename IfCheck in IfDispatcher
Now that check nodes are nomore a thing, rename the `ifcheck` in the
AST with a meaningful name.
2020-06-15 15:06:23 +02:00
Andrea Gussoni dc944d35f5 Rename SwitchCheck in SwitchDispatcher
Now that check nodes are nomore a thing, rename the switches in the AST
with a meaningful name.
2020-06-15 15:06:23 +02:00
Pietro Fezzardi fc2912ca32 enforce clang-format 2020-01-15 18:24:28 +01:00
Pietro Fezzardi 491e1b9aad Switch to c++2a 2020-01-15 18:24:28 +01:00
Pietro Fezzardi c3a6a09f11 Upgrade to llvm-9 2020-01-15 18:24:28 +01:00
Pietro Fezzardi c6c6f19535 Enforce check-conventions 2019-11-20 15:16:17 +01:00
Pietro Fezzardi 429233f054 Fix more warnings left from -Weverything 2019-11-20 15:16:17 +01:00
Andrea Gussoni b214dd1921 Enforce check-conventions.sh
Replicate this commit 72f836d30079c191d1c30e185114c4c0a0f914df made by
Pietro.
2019-11-20 15:16:17 +01:00
Andrea Gussoni 560a345a2c Enforce -Weverything extensively
Replicate the changes made by this commit
f2a0df309f78e1b5d7c5f81ada5110523644559e perfomed by Pietro on the
branch containing the development fixes for `revng-c`.
2019-11-20 15:16:17 +01:00
Pietro Fezzardi 02ea1e5f94 Fix warnings emerged with -Wextra and -Weverything 2019-11-20 15:16:17 +01:00
Pietro Fezzardi 569ec5658e Add and enforce -Wall and -Werror 2019-11-20 15:16:14 +01:00
Andrea Gussoni 8eb5abaaeb Fix emission computation for continue nodes
Added a new attribute for the `ContinueNode`, which tells if a
`ContinueNode` should be considered implicit. An implicit continue node
means that it can be dropped without it altering the semantics of the
code (e.g., when the `continue` is the last statement inside the body of
a cycle).

This attribute enables us to avoid directly dropping the continue node,
which would also cause the computation attached to this node to be
dropped, also in the output of the decompiler pass.
2019-07-30 18:20:06 +02:00
Andrea Gussoni 520e6fa0fd Do not emit the else when not necessary
We now check if the ASTNode of the `else` branch for which we try to
obtain a compound statement is non existing (`nullptr`), and in such
case we emit an ad-hoc if statement which does not have the else part.
2019-07-30 17:21:20 +02:00
Andrea Gussoni 11298108ff Handle variadic functions in decompilation
Handle the emission of variadic functions (such as the
`indirect_handler` helper function) both in regards if declaration and
definition.

Handle also `undef` values in calls to the `indirect_handler` function.
2019-06-13 12:10:38 +00:00
Pietro Fezzardi 494570f3df CDecompilerAction: fix assignments of PHINodes 2019-05-10 15:38:06 +02:00
Pietro Fezzardi ef3daf7a60 Refactor building AST for BasicBlocks 2019-05-10 11:53:28 +02:00