Skip to content

Commit

Permalink
load schema from json file to db
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Oct 9, 2024
1 parent 6ac0415 commit 594cbc6
Show file tree
Hide file tree
Showing 19 changed files with 501 additions and 11 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ set(CMAKE_INSTALL_RPATH ${Z3_INCLUDES})
link_libraries(${Z3_LIBRARIES})
include_directories(SYSTEM ${Z3_INCLUDES})

# Add the libneo4j library to all targets of SVF
find_library(NEO4J_CLIENT_LIBRARIES neo4j-client REQUIRED PATHS /usr/local/lib)
include_directories(SYSTEM /usr/local/include)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};/usr/local/lib")
include_directories(SYSTEM /usr/local/include)
link_directories(/usr/local/lib)
link_libraries(/usr/local/lib)


# Add the actual SVF and SVF-LLVM targets
add_subdirectory(svf)
add_subdirectory(svf-llvm)
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ if [[ ! -d "$Z3_DIR" ]]; then
fi

# Add LLVM & Z3 to $PATH and $LD_LIBRARY_PATH (prepend so that selected instances will be used first)
PATH=$LLVM_DIR/bin:$Z3_DIR/bin:$PATH
LD_LIBRARY_PATH=$LLVM_DIR/lib:$Z3_BIN/lib:$LD_LIBRARY_PATH
PATH=$LLVM_DIR/bin:$Z3_DIR/bin:/usr/local/lib:$PATH
LD_LIBRARY_PATH=$LLVM_DIR/lib:$Z3_BIN/lib:/usr/local/lib:$LD_LIBRARY_PATH

echo "LLVM_DIR=$LLVM_DIR"
echo "Z3_DIR=$Z3_DIR"
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ set_target_properties(SvfLLVM PROPERTIES
)

# Link LLVM's libraries to SvfLLVM, as well as the SVF core library
target_link_libraries(SvfLLVM PUBLIC ${llvm_libs} SvfCore)
target_link_libraries(SvfLLVM PUBLIC ${llvm_libs} ${NEO4J_CLIENT_LIBRARIES} SvfCore)

# Get the source files (i.e. all *.c/*.cpp files) for SVF's subprojects and add them to SvfLLVM
file(GLOB_RECURSE SVF_LLVM_SOURCES lib/*.cpp)
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/tools/AE/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_llvm_executable(ae ae.cpp)
target_link_libraries(ae PUBLIC ${llvm_libs} SvfLLVM)
target_link_libraries(ae PUBLIC ${llvm_libs} ${NEO4J_CLIENT_LIBRARIES} SvfLLVM)
2 changes: 1 addition & 1 deletion svf-llvm/tools/CFL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_llvm_executable(cfl cfl.cpp)
target_link_libraries(cfl PUBLIC ${llvm_libs} SvfLLVM)
target_link_libraries(cfl PUBLIC ${llvm_libs} ${NEO4J_CLIENT_LIBRARIES} SvfLLVM )
2 changes: 1 addition & 1 deletion svf-llvm/tools/DDA/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_llvm_executable(dvf dda.cpp)
target_link_libraries(dvf PUBLIC ${llvm_libs} SvfLLVM)
target_link_libraries(dvf PUBLIC ${llvm_libs} ${NEO4J_CLIENT_LIBRARIES} SvfLLVM)
2 changes: 1 addition & 1 deletion svf-llvm/tools/Example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_llvm_executable(svf-ex svf-ex.cpp)
target_link_libraries(svf-ex PUBLIC ${llvm_libs} SvfLLVM)
target_link_libraries(svf-ex PUBLIC ${llvm_libs} ${NEO4J_CLIENT_LIBRARIES} SvfLLVM)
2 changes: 1 addition & 1 deletion svf-llvm/tools/LLVM2SVF/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_llvm_executable(llvm2svf llvm2svf.cpp)
target_link_libraries(llvm2svf PUBLIC ${llvm_libs} SvfLLVM)
target_link_libraries(llvm2svf PUBLIC ${llvm_libs} ${NEO4J_CLIENT_LIBRARIES} SvfLLVM)
2 changes: 1 addition & 1 deletion svf-llvm/tools/MTA/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_llvm_executable(mta mta.cpp)
target_link_libraries(mta PUBLIC ${llvm_libs} SvfLLVM)
target_link_libraries(mta PUBLIC ${llvm_libs} ${NEO4J_CLIENT_LIBRARIES} SvfLLVM)
2 changes: 1 addition & 1 deletion svf-llvm/tools/SABER/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_llvm_executable(saber saber.cpp)
target_link_libraries(saber PUBLIC ${llvm_libs} SvfLLVM)
target_link_libraries(saber PUBLIC ${llvm_libs} ${NEO4J_CLIENT_LIBRARIES} SvfLLVM)
2 changes: 1 addition & 1 deletion svf-llvm/tools/WPA/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

add_llvm_executable(wpa wpa.cpp)
target_link_libraries(wpa PUBLIC ${llvm_libs} SvfLLVM Threads::Threads)
target_link_libraries(wpa PUBLIC ${llvm_libs} ${NEO4J_CLIENT_LIBRARIES} SvfLLVM Threads::Threads)
2 changes: 2 additions & 0 deletions svf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Define the core library
add_library(SvfCore)

target_link_libraries(SvfCore PRIVATE ${NEO4J_CLIENT_LIBRARIES})

# Add the public headers as an include directory
target_include_directories(SvfCore
PUBLIC
Expand Down
2 changes: 2 additions & 0 deletions svf/include/Graphs/CallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
#include "SVFIR/SVFValue.h"
#include "Graphs/ICFG.h"
#include <set>
#include "SVFIR/GraphDBClient.h"

namespace SVF
{

class CallGraphNode;
class SVFModule;
class GraphDBClient;


/*
Expand Down
63 changes: 63 additions & 0 deletions svf/include/SVFIR/GraphDBClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#ifndef INCLUDE_GRAPHDBCLIENT_H_
#define INCLUDE_GRAPHDBCLIENT_H_
#include <neo4j-client.h>
#include "Util/SVFUtil.h"


namespace SVF
{
class GraphDBClient{
private:
neo4j_connection_t* connection;

GraphDBClient()
{
const char* uri = "bolt://localhost:7687";
neo4j_config_t* config = neo4j_new_config();
if (neo4j_config_set_username(config, "admin") != 0 &&
neo4j_config_set_password(config, "73@TuGraph") != 0){
SVFUtil::outs() << "Failed to connect to GraphDB.\n";
} else {
connection = neo4j_connect(uri, config, NEO4J_INSECURE);
if (connection == nullptr) {
SVFUtil::outs() << "Failed to connect to GraphDB.\n";
} else {
SVFUtil::outs() << "Connected to GraphDB successfully.\n";
}
}

}

~GraphDBClient()
{
if (connection != nullptr)
{
if (neo4j_close(connection) !=0){
SVFUtil::outs() << "Failed to close GraphDB.\n";
} else {
SVFUtil::outs() << "GraphDB connection closed.\n";
connection = nullptr;
}
}
}
public:
static GraphDBClient& getInstance()
{
static GraphDBClient instance;
return instance;
}

GraphDBClient(const GraphDBClient&) = delete;
GraphDBClient& operator = (const GraphDBClient&) = delete;

neo4j_connection_t* getConnection()
{
return connection;
}

void loadSchema(neo4j_connection_t* connection, const std::string& filepath, const std::string& queryParam);
};

}

#endif
11 changes: 11 additions & 0 deletions svf/lib/Graphs/CallGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "Util/SVFUtil.h"
#include "Graphs/CallGraph.h"
#include "SVFIR/SVFIR.h"
#include "SVFIR/GraphDBClient.h"

using namespace SVF;
using namespace SVFUtil;
Expand Down Expand Up @@ -110,6 +111,16 @@ CallGraph::CallGraph(CGEK k): kind(k)
{
callGraphNodeNum = 0;
numOfResolvedIndCallEdge = 0;
neo4j_connection_t* dbConnection = SVF::GraphDBClient::getInstance().getConnection();
if (dbConnection != nullptr)
{
if (dbConnection != nullptr) {
SVF::GraphDBClient::getInstance().loadSchema(dbConnection, "./DBSchema/CallGraphEdgeSchema.json", "CALL db.createEdgeLabelByJson($edge_schema)");
SVF::GraphDBClient::getInstance().loadSchema(dbConnection, "./DBSchema/CallGraphNodeSchema.json", "CALL db.createVertexLabelByJson($node_schema)");
} else {
SVFUtil::outs() << "Failed to connect to the database.\n";
}
}
}

/*!
Expand Down
29 changes: 29 additions & 0 deletions svf/lib/Graphs/DBSchema/CallGraphEdgeSchema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"schema": [
{
"label":"CallRetEdge",
"type":"EDGE",
"properties" : [
{
"name" : "csid",
"type":"INT32",
"optional":false,
"index":true
},
{
"name":"kind",
"type":"STRING",
"optional":false,
"index":false
},
{
"name":"isDirectCall",
"type":"BOOL",
"optional":false,
"index":false
}
]
}
]
}

30 changes: 30 additions & 0 deletions svf/lib/Graphs/DBSchema/CallGraphNodeSchema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"schema": [
{
"label" : "CallGraphNode",
"type" : "VERTEX",
"primary" : "id",
"properties" : [
{
"name" : "id",
"type":"INT32",
"optional":false,
"index":true
},
{
"name":"function_name",
"type":"STRING",
"optional":false,
"index":false
},
{
"name":"isReachableFromProgEntry",
"type":"BOOL",
"optional":false,
"index":false
}
]
}
]
}

Loading

0 comments on commit 594cbc6

Please sign in to comment.