| 1 | /*
|
| 2 | * Souffle - A Datalog Compiler
|
| 3 | * Copyright (c) 2019, The Souffle Developers. All rights reserved
|
| 4 | * Licensed under the Universal Permissive License v 1.0 as shown at:
|
| 5 | * - https://opensource.org/licenses/UPL
|
| 6 | * - <souffle root>/licenses/SOUFFLE-UPL.txt
|
| 7 | */
|
| 8 |
|
| 9 | /************************************************************************
|
| 10 | *
|
| 11 | * @file SwigInterface.h
|
| 12 | *
|
| 13 | * Header file for SWIG to invoke functions in souffle::SouffleProgram
|
| 14 | *
|
| 15 | ***********************************************************************/
|
| 16 |
|
| 17 | #pragma once
|
| 18 |
|
| 19 | #include "souffle/SouffleInterface.h"
|
| 20 | #include <iostream>
|
| 21 | #include <string>
|
| 22 |
|
| 23 | /**
|
| 24 | * Abstract base class for generated Datalog programs
|
| 25 | */
|
| 26 | class SWIGSouffleProgram {
|
| 27 | /**
|
| 28 | * pointer to SouffleProgram to invoke functions from SouffleInterface.h
|
| 29 | */
|
| 30 | souffle::SouffleProgram* program;
|
| 31 |
|
| 32 | public:
|
| 33 | SWIGSouffleProgram(souffle::SouffleProgram* program) : program(program) {}
|
| 34 |
|
| 35 | virtual ~SWIGSouffleProgram() {
|
| 36 | delete program;
|
| 37 | }
|
| 38 |
|
| 39 | /**
|
| 40 | * Calls the corresponding method souffle::SouffleProgram::run in SouffleInterface.h
|
| 41 | */
|
| 42 | void run() {
|
| 43 | program->run();
|
| 44 | }
|
| 45 |
|
| 46 | /**
|
| 47 | * Calls the corresponding method souffle::SouffleProgram::runAll in SouffleInterface.h
|
| 48 | */
|
| 49 | void runAll(const std::string& inputDirectory, const std::string& outputDirectory) {
|
| 50 | program->runAll(inputDirectory, outputDirectory);
|
| 51 | }
|
| 52 |
|
| 53 | /**
|
| 54 | * Calls the corresponding method souffle::SouffleProgram::loadAll in SouffleInterface.h
|
| 55 | */
|
| 56 | void loadAll(const std::string& inputDirectory) {
|
| 57 | program->loadAll(inputDirectory);
|
| 58 | }
|
| 59 |
|
| 60 | /**
|
| 61 | * Calls the corresponding method souffle::SouffleProgram::printAll in SouffleInterface.h
|
| 62 | */
|
| 63 | void printAll(const std::string& outputDirectory) {
|
| 64 | program->printAll(outputDirectory);
|
| 65 | }
|
| 66 |
|
| 67 | /**
|
| 68 | * Calls the corresponding method souffle::SouffleProgram::dumpInputs in SouffleInterface.h
|
| 69 | */
|
| 70 | void dumpInputs() {
|
| 71 | program->dumpInputs();
|
| 72 | }
|
| 73 |
|
| 74 | /**
|
| 75 | * Calls the corresponding method souffle::SouffleProgram::dumpOutputs in SouffleInterface.h
|
| 76 | */
|
| 77 | void dumpOutputs() {
|
| 78 | program->dumpOutputs();
|
| 79 | }
|
| 80 | };
|
| 81 |
|
| 82 | /**
|
| 83 | * Creates an instance of a SWIG souffle::SouffleProgram that can be called within a program of a supported
|
| 84 | * language for the SWIG option specified in main.cpp. This enables the program to use this instance and call
|
| 85 | * the supported souffle::SouffleProgram methods.
|
| 86 | * @param name Name of the datalog file/ instance to be created
|
| 87 | */
|
| 88 | SWIGSouffleProgram* newInstance(const std::string& name) {
|
| 89 | auto* prog = souffle::ProgramFactory::newInstance(name);
|
| 90 | return new SWIGSouffleProgram(prog);
|
| 91 | }
|