mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
ca422bafd2
We introduce the PromoteCallNoReturn beautification pass. Its goal is to restructure sequence of statements, in order to have `call`s to `noreturn` functions as _inlined_ in the middle of the statement sequence, and leave _non local control flow statements_ at the end of that scope. E.g., we prefer: ``` if (cond) call noreturnfunc(); return; ``` to ``` if (!cond) return; call noreturnfunc(); ``` In order to do this, contextually, we restructure the routine computing the `fallthrough` property, in order to be able to differentiate between the _non local control flow statements_, a call to a `noreturn` function, or a generic mix of the two (useful when combining results from the two situations above). The new analysis is also used in the `promoteNoFallThrough` promotion pass.
33 lines
706 B
C++
33 lines
706 B
C++
#pragma once
|
|
|
|
//
|
|
// Copyright rev.ng Labs Srl. See LICENSE.md for details.
|
|
//
|
|
|
|
#include "revng/Model/IRHelpers.h"
|
|
|
|
// Forward declarations
|
|
class ASTNode;
|
|
class ASTTree;
|
|
|
|
// This `enum class` is used to represent the fallthrough type
|
|
enum class FallThroughScopeType {
|
|
FallThrough,
|
|
|
|
// This is a placeholder state to represent the combination of two no
|
|
// fallthrough states
|
|
MixedNoFallThrough,
|
|
CallNoReturn,
|
|
Return,
|
|
Continue,
|
|
LoopBreak,
|
|
SwitchBreak,
|
|
};
|
|
|
|
using FallThroughScopeTypeMap = std::map<const ASTNode *, FallThroughScopeType>;
|
|
|
|
bool fallsThrough(FallThroughScopeType Element);
|
|
|
|
extern FallThroughScopeTypeMap
|
|
computeFallThroughScope(const model::Binary &Model, ASTNode *RootNode);
|