Commit Graph

3168 Commits

Author SHA1 Message Date
Alessandro Di Federico ec6d4dbe74 Ensure all files end with a newline 2022-02-14 10:56:15 +01:00
Alvise de Faveri 7593d4da23 PromoteCSVs: promote PC CSVs 2022-02-12 12:04:14 +01:00
Alessandro Di Federico 48fcca58ae DetectStackSize: limit stack arguments/frame size 2022-02-11 17:28:02 +01:00
Alvise de Faveri 812b73f2a2 Remove opaquepc()
We can set the PC to the expected value after each call instead
of creating an `opaquepc()` call.
2022-02-11 13:42:29 +01:00
Alvise de Faveri 1a39994759 Add HelpersToHeader pass 2022-02-10 17:12:56 +01:00
Alvise de Faveri 73c743597b Pull out DepGraph and naming from ModelToHeader
Separate `ModelToHeader.cpp` into 3 different files:

1. DependencyGraph, used to calculate the precedence between
   type declarations
2. ModelTypeNames, that holds all the naming logic, whose
   primitives are accessible from other modules through a
   public header
3. ModelToHeader, that now contains only the logic to print
   out declarations and definitions

Also add a compilation test for the headers generated by this pass.
2022-02-10 17:12:56 +01:00
Alvise de Faveri 9a4da22e8c Move ModelToHeaderMain to a new tools/ folder 2022-02-10 17:12:56 +01:00
Alvise de Faveri 70724920bb Move ModelToHeader to HeadersGeneration 2022-02-10 17:12:56 +01:00
Alvise de Faveri cb3ee3c8ac Remove body of non-isolated functions from the IR
Before decompiling, we want to get rid of all unused stuff from the
IR. To do this, we have to:

1. Modify `FilterForDecompilation` so that it removes the body of
   all non-isolated functions
2. Add `strip-dead-prototypes` to the preparation pipeline, so that
   also the declarations of non-isolated functions that are not
   directly called inside an isolated function are stripped from
   the LLVM module. In this way, we can safely execute `HelpersToHeader`
2022-02-10 17:12:45 +01:00
Alvise de Faveri 691e55097c Add the condition's BB to ASTNode's debug info 2022-02-09 18:53:13 +01:00
Alvise de Faveri 19ae8757b0 Add -single-decompilation to BeautifyGHAST 2022-02-09 18:53:12 +01:00
Alvise de Faveri 0c3a8904c6 Prefer while over do-while in BeautifyGHAST
Run `matchWhile()` before `matchDoWhile()` in BeautifyGHAST.cpp.
Since `while` nodes cannot be transformed into `doWhile`s nor
vice-versa, this has the effect of giving priority to `while` loops
over `do-while`s in cases where you could emit both.
2022-02-09 18:53:12 +01:00
Alvise de Faveri 7b144b2556 Don't upgrade while and doWhile in the GHAST
We should never be changing the nature of a `while` node into a
`doWhile` and vice-versa: we only upgrade standard nodes in
either a `while` or a `doWhile`.
2022-02-09 18:53:12 +01:00
Pietro Fezzardi 0639cc8042 Enforce check-revng-conventions 2022-02-09 18:53:12 +01:00
Alessandro Di Federico e80d159944 revng-pipline: simplify Kinds.h 2022-02-08 17:44:33 +01:00
Alessandro Di Federico fa8061b805 Drop dead Kinds 2022-02-08 17:44:19 +01:00
Pietro Fezzardi 29c50fa909 Model: reserve names defined in stdint.h
This commit adds a bunch of type names and macro names to the set of
reserved keywords that cannot be used for names in the revng Model.
These are the names defined in the stdint.h standard C header, that is
included automatically by the decompiler in decompiled code.

We need to reserve these names otherwise it would be possible to add
things to the revng Model with names that clash with the names defined
in stdint.h, which would in turn break recompilation of decompiled code
because of conflicting definitions.
2022-02-08 15:54:02 +01:00
Massimo Fioravanti fe9686be03 revng-pipeline: introduce C API 2022-02-08 00:05:03 +01:00
Massimo Fioravanti a8a8da3bae Introduce revng pipes
This commit imports all the revng pipes (and other support utilities) to
be used with `revng-pipeline`. In particular, the pipes necessary for
binary translations have been introduced.
2022-02-08 00:05:03 +01:00
Massimo Fioravanti 6f0d0c4f9d CodeGenerator: accept an external model 2022-02-07 22:24:39 +01:00
Massimo Fioravanti 98ecd38162 Drop PureLLVMPipe
Now LLVM passes can be used directly in an LLVMPipe without specifying a
contract for it.
2022-02-07 22:24:39 +01:00
Alessandro Di Federico fec5f3537b s/Granularity/Rank/ 2022-02-07 22:24:39 +01:00
Alessandro Di Federico e2cd7cbcdf Pipeline: simplify LLVMContainer 2022-02-07 20:11:37 +01:00
Massimo Fioravanti 396095706f Minor changes to revngPipeline 2022-02-07 20:11:15 +01:00
Alessandro Di Federico 0f084ed620 Minor changes 2022-02-07 16:55:46 +01:00
Antonio Frighetto 212816753a Introduce TwosComplementArithmeticNormalizationPass 2022-02-03 20:12:23 +01:00
Alessandro Di Federico 280848484e SerializeModelPass: verify model 2022-01-31 16:28:17 +01:00
Alessandro Di Federico a353e00ac1 Introduce model passes 2022-01-31 16:28:14 +01:00
Alessandro Di Federico 05a4d72a08 Drop model::EnumEntry::Aliases
We're dropping them from revng.
2022-01-27 13:21:14 +01:00
Alessandro Di Federico c9f2b24b0b MakeModelGEP: Index might be larger than BaseOff
This is a temporary fix for an heisenbug.
2022-01-27 13:21:14 +01:00
Alessandro Di Federico b3d6c721ad Introduce purgeUnnamedAndUnreachableTypes 2022-01-27 11:51:03 +01:00
Alessandro Di Federico f14e722c86 Introduce deduplicateEquivalentTypes 2022-01-27 11:51:03 +01:00
Alessandro Di Federico d0bb3d4c2c CodeGenerator.cpp: use OriginalName for symbols 2022-01-27 11:51:03 +01:00
Alessandro Di Federico 445066bd0a CodeGenerator.cpp: posticipate DWARF import
This way we apply the optimization passes.
2022-01-27 11:51:03 +01:00
Alessandro Di Federico 2d08050220 DwarfImporter: adopt OriginalName 2022-01-27 11:51:03 +01:00
Alessandro Di Federico dd7477664c Update CustomName verification criteria
This commit ensures `CustomName` is unambiguous according to C symbols
rules.
2022-01-27 11:51:03 +01:00
Alessandro Di Federico 74a7496020 deduplicateNames -> promoteOriginalName
This commit switches from `deduplicateNames`, which changed certain
`CustomName` values, to `promoteOriginalName`, which updates empty
`CustomName` using non-ambiguous versions of `OriginalName`.
2022-01-27 11:51:03 +01:00
Alessandro Di Federico 863652f480 Introduce OriginalName in the type system
The goal of `OriginalName` is to keep track of the original name of a
symbol upon import.

In future, this will also be used to promote it to `CustomName`.
2022-01-27 11:51:03 +01:00
Alessandro Di Federico 8d22c5205f Push CustomName to model::Type
Before this commit `CustomName` was in each inheritor, except for
`model::PrimitiveType`.
2022-01-27 11:51:03 +01:00
Alessandro Di Federico 680924b643 CodeGenerator.cpp: drop some outdated assertions
Drop some outdated checks for `model::Binary::ImportedDynamicFunctions`
being sorted.
2022-01-27 11:51:03 +01:00
Alessandro Di Federico b31e7b1f5e Introduce model::Type::edges()
This makes building a graph for the type system very easy.
2022-01-27 11:51:03 +01:00
Alessandro Di Federico 80ed065206 model::Type: move makeTypeWithID to .cpp
It needs to see the full declaration of all concrete types.
2022-01-27 11:51:03 +01:00
Alessandro Di Federico 92ea78b0a8 Fix ReservedKeywords list
Commas were missing.
2022-01-27 11:51:03 +01:00
Alessandro Di Federico c9d47d4ee7 Drop model::EnumEntry::Aliases
They turn out to be problematic to handle in the model and not very
usable in practice.
2022-01-27 11:51:03 +01:00
Alessandro Di Federico 1ce1f1cbd6 model::Function::verify: relax assumptions
Now `model::Function` can miss the CFG, the `Prototype` and have
`Invalid` type.
2022-01-27 11:51:03 +01:00
Alessandro Di Federico 3799f1e973 Whitespace and other minor changes 2022-01-25 21:27:05 +01:00
Alessandro Di Federico 3ab32cd2ef tuple_tree_generator: make fully standalone 2022-01-21 18:05:51 +01:00
Alessandro Di Federico 020a7fc945 MakeModelGEP: ignore CABIFunctionTypes 2022-01-17 18:18:52 +01:00
Massimo Fioravanti 70ec456078 Introduce revng-pipeline 2022-01-17 18:17:54 +01:00
Massimo Fioravanti afbebaf531 ProgramRunner: fix misuse of executable path
ProgramRunner was using garbage data instead of correctly using the path
to the current executable directory.
2022-01-17 18:17:54 +01:00