Skip to content

Commit

Permalink
Fix handling of soDir path
Browse files Browse the repository at this point in the history
  • Loading branch information
cd1m0 committed Apr 4, 2024
1 parent 5050b06 commit 36ae397
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 26 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ src/gen/declarations.ts
src/lib/souffle/value_parser.ts
src/lib/souffle/parser/souffle_parser_gen.js
src/lib/souffle/parser/souffle_value_parser_gen.js
functors/functors.o
functors/libfunctors.so
src/functors/functors.o
src/functors/libfunctors.so
.vscode
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"transpile": "tsc",
"gen-translation-modules": "node scripts/gen_translation_modules.js && eslint --fix src/gen/translate.ts src/gen/declarations.ts",
"copy-dl": "cp -r src/lib/analyses dist/lib && cp -r src/lib/detectors dist/lib",
"copy-functors": "cp -r functors dist/",
"copy-functors": "cp -r src/functors dist/",
"build-functors": "./scripts/build_functors.sh",
"build": "npm run clean && npm run gen-translation-modules && npm run transpile && chmod a+x dist/bin/cli.js && npm run copy-dl && npm run build-functors && npm run copy-functors",
"test": "c8 mocha",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_functors.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env bash

MY_DIR=$(cd $(dirname $0) && pwd)
FUNCTOR_DIR=$MY_DIR/../functors/
FUNCTOR_DIR=$MY_DIR/../src/functors/

echo "Building functors..."
g++ $FUNCTOR_DIR/functors.cpp -c -fPIC -o $FUNCTOR_DIR/functors.o -I/home/dimo/.local/include
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ async function main() {

const reader = new ASTReader();
const units = reader.read(result.data);
const infer = new InferType(compilerVersion);
const infer = new InferType(result.compilerVersion as string);

const datalog = buildDatalog(units, infer);

Expand Down
File renamed without changes.
11 changes: 7 additions & 4 deletions src/lib/souffle/souffle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ANALYSES_DIR } from "../analyses";
import { DETECTORS_DIR } from "../detectors";
import { Issue, getIssues, loadDetectors, parseTemplateSignature } from "../detector";
import * as dl from "souffle.ts";
import { join } from "path";

export type OutputRelations = Map<string, dl.Fact[]>;

Expand Down Expand Up @@ -40,22 +41,24 @@ export function buildDatalog(units: sol.SourceUnit[], infer: sol.InferType): str
].join("\n");
}

const MY_DIR = __dirname;
const DIST_SO_DIR = join(MY_DIR, "../../functors");

/**
* Helper function to analyze a bunch of solc-typed-ast SourceUnits and output some of the relations
*/
export async function analyze(
units: sol.SourceUnit[],
infer: sol.InferType,
mode: dl.SouffleOutputType,
outputRelations: string[],
soDir?: string
outputRelations: string[]
): Promise<dl.SouffleCSVInstance | dl.SouffleSQLiteInstance> {
const datalog = buildDatalog(units, infer);

const instance =
mode === "csv"
? new dl.SouffleCSVInstance(datalog, soDir)
: new dl.SouffleSQLiteInstance(datalog, soDir);
? new dl.SouffleCSVInstance(datalog, DIST_SO_DIR)
: new dl.SouffleSQLiteInstance(datalog, DIST_SO_DIR);

await instance.run(outputRelations);
return instance;
Expand Down
7 changes: 1 addition & 6 deletions test/analyses.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ import * as sol from "solc-typed-ast";
import { OutputRelations, analyze } from "../src";
import { searchRecursive } from "../src/lib/utils";
import * as dl from "souffle.ts";
import { join } from "path";

const samples = searchRecursive("test/samples/analyses", (fileName) => fileName.endsWith(".json"));

const MY_DIR = __dirname;
const DIST_SO_DIR = join(MY_DIR, "../dist/functors");

/**
* Remove duplicate rows.
*/
Expand Down Expand Up @@ -75,8 +71,7 @@ describe("Analyses", () => {
units,
infer,
"csv",
targetAnalyses,
DIST_SO_DIR
targetAnalyses
)) as dl.SouffleCSVInstance;
const analysisResults = await instance.allFacts();
instance.release();
Expand Down
16 changes: 5 additions & 11 deletions test/succ.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import expect from "expect";
import fse from "fs-extra";
import path, { join } from "path";
import path from "path";
import * as sol from "solc-typed-ast";
import * as dl from "souffle.ts";
import { analyze } from "../src";
Expand Down Expand Up @@ -39,9 +39,6 @@ samples = samples.slice(
*/
const verbose = false;

const MY_DIR = __dirname;
const DIST_SO_DIR = join(MY_DIR, "../dist/functors");

export type NdGraph = Map<number, Set<number>>;
export type Reachable = Set<number>;

Expand Down Expand Up @@ -217,13 +214,10 @@ describe("Test succ relation for all samples", () => {

infer = new sol.InferType(result.compilerVersion as string);

const instance = (await analyze(
units,
infer,
"csv",
["succ", "succ_first"],
DIST_SO_DIR
)) as dl.SouffleCSVInstance;
const instance = (await analyze(units, infer, "csv", [
"succ",
"succ_first"
])) as dl.SouffleCSVInstance;
const analysisResults = await instance.allFacts();
//instance.release();
succ = analysisResults.get("succ") as dl.Fact[];
Expand Down

0 comments on commit 36ae397

Please sign in to comment.