#pragma once // // This file is distributed under the MIT License. See LICENSE.md for details. // #include "revng/GraphLayout/Graphs.h" #include "revng/Pipeline/Location.h" #include "revng/Pipes/Ranks.h" #include "revng/Support/BasicBlockID.h" #include "revng/Yield/BasicBlock.h" namespace yield::cfg { class Node { private: /// Stores a serialized `pipeline::Location` indicating what this node /// represents contextually. As of now, it's only allowed to be set to /// `revng::ranks::BasicBlock` but that's likely to be extended in the future. std::string Location = {}; private: using BasicBlockRank = decltype(revng::ranks::BasicBlock); public: Node() = default; Node(const yield::BasicBlock &Block, const MetaAddress &Function = MetaAddress::invalid()) : Location(pipeline::locationString(revng::ranks::BasicBlock, Function, Block.ID())) {} explicit Node(const pipeline::Location &Location) : Location(Location.toString()) {} Node &operator=(const pipeline::Location &NewLocation) { Location = NewLocation.toString(); return *this; } public: bool isEmpty() const { return Location.empty(); } BasicBlockRank::Type getBasicBlock() const { revng_assert(!isEmpty()); auto MaybeResult = pipeline::locationFromString(revng::ranks::BasicBlock, Location); revng_assert(MaybeResult.has_value()); return MaybeResult->at(revng::ranks::BasicBlock); } }; enum class EdgeType { Unconditional, Call, Taken, Refused }; struct Edge { EdgeType Type = EdgeType::Unconditional; }; using PreLayoutNode = layout::InputNode; using PreLayoutGraph = layout::InputGraph; using PostLayoutNode = layout::OutputNode; using PostLayoutGraph = layout::OutputGraph; } // namespace yield::cfg