Change the AST debug printing from a recursive descent on the AST nodes
in the graph, to an iterative printing of respectively nodes and their
outgoing edges.
Also, we now print the edge going to the `Successor` field, if present.
Reorganize the AST dot printing in order to use LLVM facilities for
files handling. In addition, clean up the code, and add a function
(useful in debug) in order to dump the dot of and AST from GDB (accepts
a `char *` instead of a `std::string`.
The simplifyLastContinue beautifier was too ambitious and there were
many corner cases that it handled in the wrong way, leaving the AST in a
shape that could not be emitted, or breaking the semantics.
This commit severely weakens the simplifyLastContinue, so that it does
not break things anymore.
It is now able to match only continue statements that are in the last
position of a sequence node which is the body of a ScsNode.
This obviously is not enough but allows revng-c to pass all the
decompilation tests.
In the future we will need to extend simplifyLastContinue to match more
cases in a sane way.
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.
`ExprNode` and its child classes use LLVM-style RTTI.
Until now their destruction was not handled properly, causing the
constructor-destructor type mismatch warnings on ASAN.
Despite this all the code was working properly, but just for luck,
because of the fact that these classes are very shallow.
This commit fixes the issue, and allow `ExprNode` and its child classes
to be extended without worrying about wrong destructors being invoked.
Replicate the changes made by this commit
f2a0df309f78e1b5d7c5f81ada5110523644559e perfomed by Pietro on the
branch containing the development fixes for `revng-c`.
`BasicBlockNode` and `RegionCFG` classes are now template classes. This
means that the `BasicBlockNode` class can be used as a generic wrapper
for any type of object in the original graph (it is usually used to wrap
a `llvm::BasicBlock *` for decompilation purposes, but in tests it can
be used to wrap a `DotNode` object) that implementes `GraphTraits`.
We now match the `IfCheckNode` trees created by the dispatchers
insertion as an unique switch.
To this we introduced a new `SwitchCheckNode` AST type, which cannot
inherith from the `SwitchNode` since the underlying container for the
`case`s is different (the index is saved as an `unsigned`, while instead
in the `SwitchNode` we use a `ConstantInt *`.
The condition inside the `IfNode`s are now represented using a custom
`ExprNode` object, which has a new hierarchy of possible nodes present
in an expression (`not`, `and` and `or`).
Moved the `flipEmptyThen` post-processing inside the beautify pass.
The ownership of the `ExprNode` is kept inside the `ASTTree` object.
This means that during the flattening we also need to transfer these
objects and to adjust the pointers inside the `IfNode`s.
Remove the pointer to the corresponding `BasicBlockNode` inside each
`ASTNode`.
We now keep directly a pointer to the original `llvm::BasicBlock`.
To do this we need to explicitly mantain some information, like the
emptyness of the node (dummy node in the `RegionCFG`).
Some little changes (like the way we retrieve the CFGNode corresponding
to an ASTNode) in the flattening have been necessary too.
Remove from the `IfEqualNode` the reference to the BBNode corresponding
to the original `switch`, since we cannot have the guarantee that this
node will remain allocated in the same place (the pointer could be
invalidated).
Also insert other fixes.