From 3763d781d39eb9872cd036bfc78d8024b6f888e3 Mon Sep 17 00:00:00 2001 From: Andrea Gussoni Date: Tue, 30 Apr 2024 17:02:27 +0200 Subject: [PATCH] InlineDispatcherSwitch: improve function signature --- lib/RestructureCFG/BeautifyGHAST.cpp | 4 ++-- lib/RestructureCFG/InlineDispatcherSwitch.cpp | 12 ++++++++---- lib/RestructureCFG/InlineDispatcherSwitch.h | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/RestructureCFG/BeautifyGHAST.cpp b/lib/RestructureCFG/BeautifyGHAST.cpp index 5e60c26f7..cc9d42ada 100644 --- a/lib/RestructureCFG/BeautifyGHAST.cpp +++ b/lib/RestructureCFG/BeautifyGHAST.cpp @@ -1016,12 +1016,12 @@ void beautifyAST(const model::Binary &Model, Function &F, ASTTree &CombedAST) { // Perform the `SwitchBreak` simplification revng_log(BeautifyLogger, "Performing SwitchBreak simplification"); - RootNode = simplifySwitchBreak(CombedAST, RootNode); + RootNode = simplifySwitchBreak(CombedAST); Dumper.log("After-switchbreak-simplify"); // Perform the dispatcher `switch` inlining revng_log(BeautifyLogger, "Performing dispatcher switch inlining\n"); - RootNode = inlineDispatcherSwitch(CombedAST, RootNode); + RootNode = inlineDispatcherSwitch(CombedAST); Dumper.log("after-dispatcher-switch-inlining"); // Perform the simplification of `switch` with two entries in a `if` diff --git a/lib/RestructureCFG/InlineDispatcherSwitch.cpp b/lib/RestructureCFG/InlineDispatcherSwitch.cpp index dc9bc9c24..6f792c1d4 100644 --- a/lib/RestructureCFG/InlineDispatcherSwitch.cpp +++ b/lib/RestructureCFG/InlineDispatcherSwitch.cpp @@ -767,12 +767,14 @@ inlineDispatcherSwitchImpl(ASTTree &AST, rc_return Node; } -ASTNode *inlineDispatcherSwitch(ASTTree &AST, ASTNode *RootNode) { +ASTNode *inlineDispatcherSwitch(ASTTree &AST) { // Compute the loop -> dispatcher switch correspondence LoopDispatcherMap LoopDispatcherMap = computeLoopDispatcher(AST); - RootNode = inlineDispatcherSwitchImpl(AST, RootNode, LoopDispatcherMap); + ASTNode *RootNode = inlineDispatcherSwitchImpl(AST, + AST.getRoot(), + LoopDispatcherMap); // Update the root field of the AST AST.setRoot(RootNode); @@ -945,13 +947,15 @@ simplifySwitchBreakImpl(ASTTree &AST, /// are superfluous. We consider such nodes as `SwitchBreakNode`s that compose /// the entirety of a `case` of a `switch`, which must not have a `default` /// `case`. -ASTNode *simplifySwitchBreak(ASTTree &AST, ASTNode *RootNode) { +ASTNode *simplifySwitchBreak(ASTTree &AST) { // Compute the loop -> dispatcher switch correspondence LoopDispatcherMap LoopDispatcherMap = computeLoopDispatcher(AST); // Simplify away `SwitchBreakNode`s from `switch`es - RootNode = simplifySwitchBreakImpl(AST, RootNode, LoopDispatcherMap); + ASTNode *RootNode = simplifySwitchBreakImpl(AST, + AST.getRoot(), + LoopDispatcherMap); AST.setRoot(RootNode); return RootNode; diff --git a/lib/RestructureCFG/InlineDispatcherSwitch.h b/lib/RestructureCFG/InlineDispatcherSwitch.h index 30db14aa8..8098a9b82 100644 --- a/lib/RestructureCFG/InlineDispatcherSwitch.h +++ b/lib/RestructureCFG/InlineDispatcherSwitch.h @@ -10,6 +10,6 @@ class ASTNode; class ASTTree; -extern ASTNode *inlineDispatcherSwitch(ASTTree &AST, ASTNode *RootNode); +extern ASTNode *inlineDispatcherSwitch(ASTTree &AST); -extern ASTNode *simplifySwitchBreak(ASTTree &AST, ASTNode *RootNode); +extern ASTNode *simplifySwitchBreak(ASTTree &AST);