-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathRunCommandLine.java
More file actions
84 lines (72 loc) · 3.77 KB
/
RunCommandLine.java
File metadata and controls
84 lines (72 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* Alloy Analyzer 4 -- Copyright (c) 2006-2009, Felix Chang
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Modified from Alloy's ExampleUsingTheCompiler.java
* Copyright (c) 2017-2019 Khronos Group. This work is licensed under a
* Creative Commons Attribution 4.0 International License; see
* http://creativecommons.org/licenses/by/4.0/
*/
import edu.mit.csail.sdg.alloy4.A4Reporter;
import edu.mit.csail.sdg.alloy4.Err;
import edu.mit.csail.sdg.alloy4.ErrorWarning;
import edu.mit.csail.sdg.alloy4viz.VizGUI;
import edu.mit.csail.sdg.ast.Command;
import edu.mit.csail.sdg.ast.Module;
import edu.mit.csail.sdg.parser.CompUtil;
import edu.mit.csail.sdg.translator.A4Options;
import edu.mit.csail.sdg.translator.A4Solution;
import edu.mit.csail.sdg.translator.TranslateAlloyToKodkod;
/** This class demonstrates how to access Alloy4 via the compiler methods. */
public final class RunCommandLine {
/*
* Execute every command in every file.
*
* This method parses every file, then execute every command.
*
* If there are syntax or type errors, it may throw
* a ErrorSyntax or ErrorType or ErrorAPI or ErrorFatal exception.
* You should catch them and display them,
* and they may contain filename/line/column information.
*/
public static void main(String[] args) throws Err {
// The visualizer (We will initialize it to nonnull when we visualize an Alloy solution)
VizGUI viz = null;
// Alloy4 sends diagnostic messages and progress reports to the A4Reporter.
// By default, the A4Reporter ignores all these events (but you can extend the A4Reporter to display the event for the user)
A4Reporter rep = new A4Reporter() {
// For example, here we choose to display each "warning" by printing it to System.out
@Override public void warning(ErrorWarning msg) {
System.out.print("Relevance Warning:\n"+(msg.toString().trim())+"\n\n");
System.out.flush();
}
};
for(String filename:args) {
// Parse+typecheck the model
Module world = CompUtil.parseEverything_fromFile(rep, null, filename);
// Choose some default options for how you want to execute the commands
A4Options options = new A4Options();
options.solver = A4Options.SatSolver.SAT4J;
for (Command command: world.getAllCommands()) {
// Execute the command
A4Solution ans = TranslateAlloyToKodkod.execute_command(rep, world.getAllReachableSigs(), command, options);
if (ans.satisfiable()) {
System.out.println("SATISFIABLE");
} else {
System.out.println("NOSOLUTION");
}
}
}
}
}