Commit Graph

32 Commits

Author SHA1 Message Date
Pietro Fezzardi c2e8e65baa CDecompilerBeautify: weaken simplifyLastContinue
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.
2020-10-26 14:17:25 +01:00
Pietro Fezzardi a2e9a7660d ASTNode and ASTTree: cleanup of data members
This commit removes the old unused field `Processed` from `ASTNode`, and
fixes the default construction of `ASTTree` data memebers.
2020-10-26 14:09:02 +01:00
Andrea Gussoni 3128c1a4b6 Factor generateAST out as function 2020-10-26 14:07:54 +01:00
Andrea Gussoni dd3325f8a3 [INLINING] TEMP: skip tile nodes 2020-10-26 13:57:43 +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 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
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 f95899c7ac Fix LLVM-style RTTI destruction for ASTNode 2019-11-20 15:16:17 +01:00
Pietro Fezzardi cb58b8a526 Fix destruction of ExprNodes class hierarchy
`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.
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 08f68994bd Add SwitchBreakNodes in fixSwitchBreaks() 2019-05-06 11:19:41 +02:00
Andrea Gussoni e8ad1e542b Fixes and improvements suggested by MR 2019-05-03 15:46:07 +02:00
Andrea Gussoni 485a253dec Improve serialization on files 2019-04-19 10:34:31 +02:00
Andrea Gussoni e6ec54c9bc Enforce const on member functions 2019-04-16 10:19:34 +02:00
Andrea Gussoni 95ddb2b36b BasicBlockNode and RegionCFG now template
`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`.
2019-04-15 17:30:37 +02:00
Pietro Fezzardi 743b2e522c Fix switches with empty cases 2019-04-12 18:25:15 +02:00
Pietro Fezzardi 9e4c5f0ece Add support for functions returning structs 2019-04-02 11:57:07 +02:00
Andrea Gussoni 9dc26b6d05 Create SwitchCheckNode
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 *`.
2019-03-21 14:25:48 +01:00
Pietro Fezzardi 8993ae644d Fix flattening of ExprNode 2019-03-21 10:46:25 +01:00
Andrea Gussoni 8aaae2548b IfNode now using ExprNode
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.
2019-03-20 15:24:28 +01:00
Andrea Gussoni c930d1a7fd Remove pointer to CFGNode from ASTNode.
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.
2019-03-14 12:23:25 +01:00
Andrea Gussoni 4a49a60b99 Fix and convention enforcing
Some fixes and conventions enforcing before decompilation pipeline
restructure.
2019-03-12 13:49:53 +01:00
Andrea Gussoni 969b5e7601 Remove reference to original switch
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.
2019-03-11 11:24:18 +01:00
Andrea Gussoni 9f00e3125e Add SwitchNode AST type
Match and create the `SwitchNode` node when we encounter a chain of
`IfEqualNode` nodes.
2019-03-08 15:31:30 +01:00
Pietro Fezzardi 3b2dac4e85 Enforce clang-format 2019-02-25 12:29:15 +01:00
Andrea Gussoni f790e308e1 Add ID for AST nodes
Added a unique ID to AST nodes, which is useful for serialization
purposes after flattening.
2019-02-11 14:15:07 +01:00
Pietro Fezzardi 463c40a9cf Add ASTNode children BreakNode and ContinueNode 2019-02-11 12:18:44 +01:00
Andrea Gussoni 929c0c4cdf Flattening for AST
Implemented the flattening also for the AST trees, taking also care of
adjusting the pointers to the new BBNode in the `root` `RegionCFG`.
2019-02-11 12:18:44 +01:00
Andrea Gussoni 0cdb63630e Restructure ASTTree anatomy
Added a pointer to the `RootNode` in the ASTTree, and added a
`dumpOnFile` method for easier serialization.
2019-01-30 18:35:24 +01:00
Pietro Fezzardi da299f3095 EnforceCFGCombingPass: inject dummy nodes in CFG 2019-01-16 12:53:08 +01:00
Pietro Fezzardi 5805679ead RestructureCFGPass: fix use of include directory 2019-01-15 16:57:15 +01:00
Andrea Gussoni 06717a6185 Import RestructureCFGPass from revamb branch
Import the RestructureCFGPass from the `feature/the-comb` branch on the
`revamb` repository.
2019-01-14 15:45:08 +01:00