Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ Build with Gradle:
## Usage

To analyze Java source files:
```bash
./gradlew distZip
```

```bash
java -jar target/jlisa.jar -s <source-files> -o <output-directory> [-l <log-level>]
./build/distributions/jlisa-0.1/bin/jlisa -s path/to/File.java -o out/ -n ConstantPropagation
```

## Command Line Options
Expand All @@ -48,6 +51,7 @@ java -jar target/jlisa.jar -s <source-files> -o <output-directory> [-l <log-leve
| `-o` | `--outdir` | Path | Output directory for results |
| `-l` | `--log-level` | Level | Logging level (e.g., INFO, DEBUG, ERROR) |
| `-v` | `--version` | None | Version of current jlisa's implementation |
| `N/A` | `--no-html` | None | Disable html output |

## Architecture

Expand Down Expand Up @@ -77,7 +81,7 @@ Make sure to have the following prerequisites:
To run locally using Gradle:

```bash
./gradlew run --args="-s path/to/File.java -o out/"
./gradlew run --args="-s path/to/File.java -o out/ -n ConstantPropagation"
```

## License
Expand Down
43 changes: 27 additions & 16 deletions jlisa/src/main/java/it/unive/jlisa/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ public static void main(
throws IOException,
ParseException,
ParsingException {
// String source = "public class Hello { public static void main() {
// System.out.println(\"Hello World :)\"); } }";

// ASTParser parser = ASTParser.newParser(AST.getJLSLatest()); // NOTE:
// JLS8 is deprecated. getJLSLatest will return JDK23
// parser.setSource(source.toCharArray());
// parser.setKind(ASTParser.K_COMPILATION_UNIT);

// Define options
Options options = new Options();
Expand Down Expand Up @@ -97,6 +90,13 @@ public static void main(
.required(false)
.build();

Option noHtmlOutput = Option.builder()
.longOpt("no-html")
.desc("Disable HTML output (enabled by default)")
.required(false)
.build();
options.addOption(noHtmlOutput);

options.addOption(helpOption);
options.addOption(sourceOption);
options.addOption(outdirOption);
Expand All @@ -105,13 +105,15 @@ public static void main(
options.addOption(numericalDomainOption);
options.addOption(mode);
options.addOption(version);

options.addOption(noHtmlOutput);
// Create parser and formatter
CommandLineParser parser = new DefaultParser();
HelpFormatter formatter = new HelpFormatter();
String[] sources = new String[0];
String outdir = "";
String checkerName = "", numericalDomain = "", executionMode = "Debug";
boolean htmlOutput = true;

try {
CommandLine cmd = parser.parse(options, args);

Expand Down Expand Up @@ -146,6 +148,10 @@ public static void main(
LogManager.setLogLevel(level);
}

if (cmd.hasOption("no-html")) {
htmlOutput = false;
}

checkerName = cmd.getOptionValue("c", "Assert");
numericalDomain = cmd.getOptionValue("n");

Expand Down Expand Up @@ -173,10 +179,10 @@ public static void main(

switch (executionMode) {
case "Debug":
runDebug(sources, outdir, checkerName, numericalDomain);
runDebug(sources, outdir, checkerName, numericalDomain, htmlOutput);
break;
case "Statistics":
runStatistics(sources, outdir, checkerName, numericalDomain);
runStatistics(sources, outdir, checkerName, numericalDomain, htmlOutput);
break;
default:
LOG.error("Unknown execution mode: " + executionMode);
Expand All @@ -188,19 +194,21 @@ private static void runDebug(
String[] sources,
String outdir,
String checkerName,
String numericalDomain)
String numericalDomain,
boolean htmlOutput)
throws IOException,
ParseException,
ParsingException {
JavaFrontend frontend = runFrontend(sources);
runAnalysis(outdir, checkerName, numericalDomain, frontend);
runAnalysis(outdir, checkerName, numericalDomain, frontend, htmlOutput);
}

private static void runStatistics(
String[] sources,
String outdir,
String checkerName,
String numericalDomain) {
String numericalDomain,
boolean htmlOutput) {
JavaFrontend frontend = null;
try {
frontend = runFrontend(sources);
Expand All @@ -211,7 +219,7 @@ private static void runStatistics(
System.exit(1);
}
try {
runAnalysis(outdir, checkerName, numericalDomain, frontend);
runAnalysis(outdir, checkerName, numericalDomain, frontend, htmlOutput);
} catch (Throwable e) {
CSVExceptionWriter.writeCSV(outdir + "analysis.csv", e.getCause() != null ? e.getCause() : e);
LOG.error("Some errors occurred during the analysis. Check " + outdir + "analysis.csv file.");
Expand All @@ -233,14 +241,17 @@ private static void runAnalysis(
String outdir,
String checkerName,
String numericalDomain,
JavaFrontend frontend)
JavaFrontend frontend,
boolean htmlOutput)
throws ParseException {
Program p = frontend.getProgram();
LiSAConfiguration conf = new LiSAConfiguration();
conf.workdir = outdir;
conf.serializeResults = false;
conf.jsonOutput = true;
conf.analysisGraphs = LiSAConfiguration.GraphType.HTML_WITH_SUBNODES;
if (htmlOutput) {
conf.analysisGraphs = LiSAConfiguration.GraphType.HTML_WITH_SUBNODES;
}
conf.interproceduralAnalysis = new ContextBasedAnalysis<>(FullStackToken.getSingleton());
conf.callGraph = new JavaRTACallGraph();
conf.openCallPolicy = ReturnTopPolicy.INSTANCE;
Expand Down