This commit enables to emit accesses with the square bracket array
access operator on pointers.
This is accomplished by adding an additional mandatory argument to
ModelGEP (AND NOT to ModelGEPRef) to represent this case.
MakeModelGEPPass is updated to take this into account, together with all
the other passes that handle ModelGEPs.
Not equal is handled separatedly during the decompilation process in
order to add the appropriate cast.
Currently, the code only triggers when the not equal is the outermost
operation in the expression - case for which there are no tests in the
test suite.
In ModelToHeader generate Inline Types in PTML by handling
Structs, Unions and Enums.
In addition, during the ModelToHeader we avoid producing
Structs that describe stacks, and in the DecompileFunction we
produce the definition of it inline if it is safe (referenced
only once).
This commit refactors the C Backend as follows.
- The emission of basic blocks is now statement based.
There are some instructions that are handled as statements.
Those instructions are the points where the codegen starts from when
emitting C.
Conversely, all the other instructions are initially ignored when
iterating on instructions in a basic block, and are only reached when
traversing the dataflow that originates from statements.
- The TokenMap, that originally included all the string representing all
the instructions, is now used only to store the names of funciton
arguments and instructions representing local variables.
- Starting from each statement-like instruction, the C codegen is driven
by a traversal of the dataflow of the operands. The dataflow is
traversed recursively with the `getToken` method, materializing
strings on the fly until the visit reaches "leaves" i.e. instruction
that represent local variables, constants, or function arguments.
Adopting this approach allowed to reduce the peak memory consumption of
the backend, as well as making it faster on our benchmarks.
Since when we added the -exit-ssa pass, loads and stores 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.
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.
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
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.