Commit Graph

6113 Commits

Author SHA1 Message Date
Pietro Fezzardi f497df2d2f BeautifyGHAST independent of MarkForSerialization
This commits drop an old BeautifyGHAST's dependency on
MarkForSerialization.

This dependency was required because the beautification process makes
some choices (e.g. on short-circuiting ifs) based on knowledge of how
many instructions in a given basic block have side effects.
Informally speaking, if a basic block contains an instructions with side
effects, it cannot be moved before around "crossing" other stuff with
side effects. This is why it was necessary for BeautifyGHAST to know
about side effects.

Information about side effects was computed by BeautifyGHAST using
MarkForSerialization until now, but it was not properly used.
It was more like wishful thinking about what we wanted to do, but we
never fixed it.

So this commit takes a step in fixing this:
- drops dependency in BeautifyGHAST from MarkForSerialization, which was
  there but not used;
- starts taking the same information from calls to SerializationMarkers,
  if they are available in the IR.

Now, in all the decompilation pipelines we have in place, we don't
inject SerializationMarkers before BeautifyGHAST yet, so the behavior
in those pipelines is totally unmodified for what concerns side
effects.

However, for all new decompilation pipelines that we will build, we will
run IRCanonicalization passes before BeautifyGHAST. In this way, the IR
reaching BeautifyGHAST will have SerializationMarkers in place, and the
beautification process will work as intended.
2022-01-14 14:30:26 +01:00
Pietro Fezzardi 9e498f8b02 MakeModelGEP: switch to reference semantics 2022-01-14 14:29:57 +01:00
Pietro Fezzardi 9a27131303 Add argument to SerializationMarker functions
This commit adds a second argument to functions in the family of
SerializationMarker. The second argument is a boolean.
If it's true, it represents the information that the marked
llvm::Instruction was marked because it had side effects.
This information is necessary for various beautification tasks on the
GHAST, and we want it on the IR in order to be able to switch away from
the old MarkForSerializationPass.
2022-01-14 14:29:35 +01:00
Pietro Fezzardi d237bc439e IRCanonicalization: switch to FunctionTags 2022-01-14 14:29:05 +01:00
Pietro Fezzardi 48602f8930 CMakeLists.txt: uniform indentation for tests 2022-01-14 14:28:38 +01:00
Pietro Fezzardi 2fbb8df965 Add MakeModeGEPPass 2022-01-14 14:28:33 +01:00
Pietro Fezzardi 7a283e2d63 Add ExitSSAPass 2022-01-14 14:15:03 +01:00
Pietro Fezzardi 36c4e53307 Add AddIRSerializationMarkerPass 2022-01-14 14:14:19 +01:00
Pietro Fezzardi 0d57e89bf9 Merge feature/model-classes-generator into develop 2022-01-14 14:09:08 +01:00
Pietro Fezzardi 304f5009fc Rename directory FileCheckTests to llvm-lit-tests}
The new name is more sensible because the tests in that directory now
don't always use `FileCheck` anymore, but they are still all
detected using `lit`.
2022-01-14 14:06:59 +01:00
Alessandro Di Federico 0972a375a9 Model tests: adopt revng-compare-yaml 2022-01-14 14:06:59 +01:00
Filippo Cremonese b940af4692 Import recent changes to the model 2022-01-14 14:06:59 +01:00
Alessandro Di Federico b92d99e0a3 Merge branch 'feature/model-classes-generator' 2022-01-13 17:12:49 +01:00
Alessandro Di Federico fc02a84436 Test generated model can be loaded
This ensure we catch bugs in model deserialization early, while usually
they pop up in revng-c, which doesn't make much sense.
2022-01-13 14:34:11 +01:00
Filippo Cremonese 6e7439ad6d Check Python requirements at configure time 2022-01-13 14:34:11 +01:00
Filippo Cremonese 74217b4fe5 Generate C++ model from YAML definition
Model classes are now described by a YAML document, which is used to
generate C++ headers containing classes and all the boilerplate
required for YAML serialization/deserialization, usage in
SortedVectors, etc. See the README in include/revng/Model for more
info.
2022-01-13 14:34:11 +01:00
Alessandro Di Federico 7cb7c7f0cb Minor changes 2022-01-13 13:58:31 +01:00
Pietro Fezzardi f9f2d4e74b Loosen constness in SerializationMap
This will later enable its use in passes that change the IR.
2022-01-11 15:41:24 +01:00
Pietro Fezzardi ba923a90fa Move Mangling.h in Support 2022-01-11 15:41:20 +01:00
Pietro Fezzardi 7db2c64f61 MarkForSerialization now ignores duplicated uses
Remove the logic for detecting Instructions with duplicated uses
introduced by control-flow restructuring (the use is duplicated, but the
instruction is not).
By dropping this detection, we'll end up not marking for serialization
some Instructions. Hence, when emitting C code, such Instructions will
just be emitted as inline expressions, without declaring a dedicated
local variable to hold their value. This is somehow suboptimal w.r.t the
fact that the expression will be emitted many times, one for each
duplicated use. However, this is not semantically incorrect, just
verbose.

On the other hand, the logic for detecting Instructions with duplicated
uses has always been subtly broken, because it only looked at the number
of duplicates for a given basic block introduced by control-flow
restructuring.
This information is not enough to detect Instructions with duplicated
uses. Proper detection should actually be based on GHAST.
2022-01-11 15:07:33 +01:00
Pietro Fezzardi b24baaea34 MarkForSerializationPass never changes the IR 2022-01-11 09:47:32 +01:00
Pietro Fezzardi f2f783bf9d SegregateStackAccessPass: avoid 0-sized stacks 2022-01-11 09:46:21 +01:00
Filippo Cremonese fbeee896e1 Rename model::abi -> model::ABI 2022-01-10 10:31:27 +01:00
Filippo Cremonese a97efbaaf7 Add missing <map> include 2022-01-10 10:31:27 +01:00
Alessandro Di Federico 738637b673 Suggest DISABLE_RECURSIVE_COROUTINES usage 2022-01-09 19:00:57 +01:00
Alessandro Di Federico 546efa345a More verbose model verification failures 2022-01-09 19:00:57 +01:00
Alessandro Di Federico 7d4ef44cb7 DwarfImporter: ignore 0-sized arrays 2022-01-09 19:00:57 +01:00
Alessandro Di Federico 441a5552b7 ProgramRunner: do not depend on main
`main` is not in all cases a dynamically exported symbol, therefore,
it's not safe to rely on it.

This commit switches to use `PathList`'s `getCurrentExecutableFullPath`,
which reads `/proc/self/exe`.
2022-01-09 19:00:57 +01:00
Alessandro Di Federico 7a910eeb48 PromoteStackPointer: ignore CABIFunctionType 2022-01-09 14:14:03 +01:00
Alessandro Di Federico cfb47157b9 clang-tidy: readability-identifier-naming
This commit fixes all the non-compliance with our preliminary clang-tidy
configuration, which will be merged soon.
2022-01-07 09:18:05 +01:00
Alessandro Di Federico 40198d9659 Merge branch 'feature/pipeline-preliminary' 2022-01-05 15:44:47 +01:00
Pietro Fezzardi dd205cf2e7 Merge feature/dla-upgrades-stack-types in develop 2022-01-05 15:44:46 +01:00
Massimo Fioravanti b8f6303101 Fix wrong usages of StringRef::data
StringRef::data() does not ensure that the string is zero terminated,
thus when printed it can contain more data than expected.

Specifically, this triggered the reported name of the registers to be
incorrect, and this manifested itself as wrong inline assembly emitted.
2022-01-05 14:47:25 +01:00
Massimo Fioravanti bdcc1d2e30 BinaryFile::BinaryFile: accept object::Binary
The constructor now accepts a llvm::object::Binary directly rather than
a path. Will be used by the revng-pipeline which will retain ownership
of the binary.
2022-01-05 14:47:25 +01:00
Massimo Fioravanti 889b076828 AdvancedValueInfo: fix wrong NDEBUG check
A extra check was performed in release only rather than in debug only.
2022-01-05 14:47:25 +01:00
Massimo Fioravanti ec0fcfbe63 Model: separate mipsel from mips 2022-01-05 14:47:25 +01:00
Massimo Fioravanti fdfeb2b6e9 LoadModelPass: support for external model 2022-01-05 14:45:01 +01:00
Massimo Fioravanti 79d5ca1e27 Introduce FunctionTags::IsolatedRoot
This will be used by the revng-pipeline to tell apart a `root` calling
isolated functions from a regular one.
2022-01-05 14:45:01 +01:00
Massimo Fioravanti ca4c7e2c09 Add dereferenceIterator and mapToValueIterator
A dereference iterator is used to map a pointer-like object to the
pointee, as an example given a `vector<unique_ptr<int>> Vector`, using
`dereferenceRange(Vector)` will present a range of `int &` rather than a
range of `unique_ptr<int> &`.

mapToValueIterator can be used  on a map range
to access the underlying object directly rather
than the pair<key, object>.
2022-01-05 14:45:01 +01:00
Massimo Fioravanti 80c3121c29 Introduce ProgramRunner
The ProgramRunner will be used by revng-pipeline to invoke the external
linker to operate on object file stored on disk.
2022-01-05 14:45:01 +01:00
Massimo Fioravanti ac20314a92 Helpers to go from llvm:: to model::Function 2022-01-05 14:45:01 +01:00
Alessandro Di Federico d78993ac54 Add TupleTree file (de)serialization
Tuple tree file serialization will be used by the revng-pipeline as a
helper function to load and store the models in the working directory.
2022-01-05 14:44:57 +01:00
Alessandro Di Federico 41008d9a08 Merge branch 'feature/tupletreereference-to-const-model' 2022-01-05 14:38:42 +01:00
Pietro Fezzardi b689f7f0c0 lib/Model/Type.cpp: add global using llvm::Twine
This using was defined many times with local scope.
This commit makes it global.
2022-01-05 14:37:37 +01:00
Pietro Fezzardi 2f524114e8 RecursiveCoroutine: add operator* for ergonomics
This allows e.g. the following programming pattern:

```
RecursiveCoroutine<std::optional<SomeType>> f();

int g() {
  return *f();
}
```

Without operator* defined for `RecursiveCoroutine` this would fail,
requiring an explicit cast such as:

```
int g() {
  return *static_cast<std::optional<SomeType>>(f());
}
```
2022-01-05 14:37:37 +01:00
Pietro Fezzardi 94c1c5323a Improve error reporting for model::UnionType 2022-01-05 14:37:37 +01:00
Pietro Fezzardi 09dd05c975 UnionTypes with zero-sized fields don't verify 2022-01-05 14:37:37 +01:00
Pietro Fezzardi ff4f91a570 Model/Type.h: explicit constructors from uint64_t 2022-01-05 13:33:52 +01:00
Pietro Fezzardi a4c9d6c6fd Allow model::StructType with no fields
This is necessary for how we represent the type of the stack frames when
we know about its size but not yet about its fields.
2022-01-05 13:33:52 +01:00
Pietro Fezzardi e37425c686 TupleTreeReference: add getConst() method 2022-01-05 13:33:52 +01:00