BRIDGE: fixed bridgegraph
This commit is contained in:
parent
0bc4ccbd27
commit
731eb00cfb
|
|
@ -12,14 +12,14 @@ typedef struct
|
|||
bool terminal; //node is a RET
|
||||
bool split; //node is a split (brtrue points to the next node)
|
||||
void* userdata; //user data
|
||||
ListOf(duint) exits; //exits (including brtrue and brfalse)
|
||||
ListInfo exits; //exits (including brtrue and brfalse, duint)
|
||||
} BridgeCFNodeList;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
duint entryPoint; //graph entry point
|
||||
void* userdata; //user data
|
||||
ListOf(BridgeCFNodeList) nodes; //graph nodes
|
||||
ListInfo nodes; //graph nodes (BridgeCFNodeList)
|
||||
} BridgeCFGraphList;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
@ -27,6 +27,7 @@ typedef struct
|
|||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
struct BridgeCFNode
|
||||
{
|
||||
|
|
@ -41,9 +42,9 @@ struct BridgeCFNode
|
|||
void* userdata; //user data
|
||||
std::vector<duint> exits; //exits (including brtrue and brfalse)
|
||||
|
||||
explicit BridgeCFNode(BridgeCFNodeList* nodeList)
|
||||
explicit BridgeCFNode(BridgeCFNodeList* nodeList, bool freedata = true)
|
||||
{
|
||||
if(!nodeList || !nodeList->exits || nodeList->exits->size != nodeList->exits->count * sizeof(duint))
|
||||
if(!nodeList || nodeList->exits.size != nodeList->exits.count * sizeof(duint))
|
||||
__debugbreak();
|
||||
parentGraph = nodeList->parentGraph;
|
||||
start = nodeList->start;
|
||||
|
|
@ -54,10 +55,12 @@ struct BridgeCFNode
|
|||
terminal = nodeList->terminal;
|
||||
split = nodeList->split;
|
||||
userdata = nodeList->userdata;
|
||||
auto data = (duint*)nodeList->exits->data;
|
||||
exits.resize(nodeList->exits->count);
|
||||
for(int i = 0; i < nodeList->exits->count; i++)
|
||||
auto data = (duint*)nodeList->exits.data;
|
||||
exits.resize(nodeList->exits.count);
|
||||
for(int i = 0; i < nodeList->exits.count; i++)
|
||||
exits[i] = data[i];
|
||||
if(freedata)
|
||||
BridgeFree(data);
|
||||
}
|
||||
|
||||
explicit BridgeCFNode(duint parentGraph, duint start, duint end)
|
||||
|
|
@ -77,6 +80,22 @@ struct BridgeCFNode
|
|||
: BridgeCFNode(0, 0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
BridgeCFNodeList ToNodeList() const
|
||||
{
|
||||
BridgeCFNodeList out;
|
||||
out.parentGraph = parentGraph;
|
||||
out.start = start;
|
||||
out.end = end;
|
||||
out.brtrue = brtrue;
|
||||
out.brfalse = brfalse;
|
||||
out.icount = icount;
|
||||
out.terminal = terminal;
|
||||
out.split = split;
|
||||
out.userdata = userdata;
|
||||
BridgeList<duint>::CopyData(&out.exits, exits);
|
||||
return std::move(out);
|
||||
}
|
||||
};
|
||||
|
||||
struct BridgeCFGraph
|
||||
|
|
@ -86,15 +105,17 @@ struct BridgeCFGraph
|
|||
std::unordered_map<duint, BridgeCFNode> nodes; //CFNode.start -> CFNode
|
||||
std::unordered_map<duint, std::unordered_set<duint>> parents; //CFNode.start -> parents
|
||||
|
||||
explicit BridgeCFGraph(BridgeCFGraphList* graphList)
|
||||
explicit BridgeCFGraph(BridgeCFGraphList* graphList, bool freedata = true)
|
||||
{
|
||||
if(!graphList || !graphList->nodes || graphList->nodes->size != graphList->nodes->count * sizeof(BridgeCFNode))
|
||||
if(!graphList || graphList->nodes.size != graphList->nodes.count * sizeof(BridgeCFNodeList))
|
||||
__debugbreak();
|
||||
entryPoint = graphList->entryPoint;
|
||||
userdata = graphList->userdata;
|
||||
auto data = (BridgeCFNode*)graphList->nodes->data;
|
||||
for(int i = 0; i < graphList->nodes->count; i++)
|
||||
AddNode(data[i]);
|
||||
auto data = (BridgeCFNodeList*)graphList->nodes.data;
|
||||
for(int i = 0; i < graphList->nodes.count; i++)
|
||||
AddNode(BridgeCFNode(&data[i], freedata));
|
||||
if(freedata)
|
||||
BridgeFree(data);
|
||||
}
|
||||
|
||||
explicit BridgeCFGraph(duint entryPoint)
|
||||
|
|
@ -124,6 +145,19 @@ struct BridgeCFGraph
|
|||
else
|
||||
found->second.insert(parent);
|
||||
}
|
||||
|
||||
BridgeCFGraphList ToGraphList()
|
||||
{
|
||||
BridgeCFGraphList out;
|
||||
out.entryPoint = entryPoint;
|
||||
out.userdata = userdata;
|
||||
std::vector<BridgeCFNodeList> nodeList;
|
||||
nodeList.reserve(nodes.size());
|
||||
for(const auto & nodeIt : nodes)
|
||||
nodeList.push_back(nodeIt.second.ToNodeList());
|
||||
BridgeList<BridgeCFNodeList>::CopyData(&out.nodes, nodeList);
|
||||
return std::move(out);
|
||||
}
|
||||
};
|
||||
|
||||
#endif //__cplusplus
|
||||
|
|
|
|||
|
|
@ -25,8 +25,6 @@ typedef unsigned long duint;
|
|||
typedef signed long dsint;
|
||||
#endif //_WIN64
|
||||
|
||||
#include "bridgegraph.h"
|
||||
|
||||
#ifndef BRIDGE_IMPEXP
|
||||
#ifdef BUILD_BRIDGE
|
||||
#define BRIDGE_IMPEXP __declspec(dllexport)
|
||||
|
|
@ -57,6 +55,17 @@ BRIDGE_IMPEXP bool BridgeSettingFlush();
|
|||
BRIDGE_IMPEXP bool BridgeSettingRead(int* errorLine);
|
||||
BRIDGE_IMPEXP int BridgeGetDbgVersion();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "bridgegraph.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//Debugger defines
|
||||
#define MAX_LABEL_SIZE 256
|
||||
#define MAX_COMMENT_SIZE 512
|
||||
|
|
|
|||
Loading…
Reference in New Issue