-
Notifications
You must be signed in to change notification settings - Fork 211
SWIG
An option to run SWIG to generate the wrapper files has been implemented for Souffle. This enables a program written in other languages such as Java and Python to read in the Datalog input file through the wrapper files and output the corresponding CSV files. These wrapper files are generated through first generating the C++ file for the Datalog file and then compiling it using SWIG.
To run the SWIG command line option in Souffle, run
./souffle -s <language> <.dl file>
Currently, the languages supported are Java and Python. The language given must be all lowercase.
Once the wrapper files have been generated, to use them in your program, you need to import the SwigInterface. Then you may run your program to generate the CSV files.
To use the interface in your Java program, add
System.loadLibrary("SwigInterface")
MAC users may need to add this instead
System.load(System.getProperty("java.library.path")+ "/" + "libSwigInterface.so")
You are now able to use the SwigInterface to create an instance of the input file to be loaded and run.
SWIGSouffleProgram p = SwigInterface.newInstance("<name of .dl file without extension>")
p.loadAll(".");
p.run();
p.printAll(".");
p.finalize();
Compile your program and run it with the -D option to specify the directory of your SwigInterface
java -Djava.library.path=<path of SwigInterface> <.java>
To use the interface in your Python program, add at the top of the file
import SwigInterface
You are now able to use the SwigInterface to create an instance of the input file to be loaded and run.
p = SwigInterface.newInstance("<name of .dl file without extension>")
p.loadAll('.')
p.run()
p.printAll('.')
Run your program to see the outputted CSV files.
newInstance("<name of .dl file without extension>")
: creates a new instance from a Datalog file
loadAll("<input directory>")
: loads all input relations
run()
: executes the Datalog program
printAll("<output directory>")
: prints all output relations