aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/SMT-Solver/hu.bme.mit.inf.dslreasoner.smt.reasoner/src/hu/bme/mit/inf/dslreasoner/smt/reasoner/builder/SmtSolverHandler.xtend
diff options
context:
space:
mode:
authorLibravatar OszkarSemerath <oszka@152.66.252.189>2017-06-10 19:05:05 +0200
committerLibravatar OszkarSemerath <oszka@152.66.252.189>2017-06-10 19:05:05 +0200
commit60f01f46ba232ed6416054f0a6115cb2a9b70b4e (patch)
tree5edf8aeb07abc51f3fec63bbd15c926e1de09552 /Solvers/SMT-Solver/hu.bme.mit.inf.dslreasoner.smt.reasoner/src/hu/bme/mit/inf/dslreasoner/smt/reasoner/builder/SmtSolverHandler.xtend
parentInitial commit, migrating from SVN (diff)
downloadVIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.tar.gz
VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.tar.zst
VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.zip
Migrating Additional projects
Diffstat (limited to 'Solvers/SMT-Solver/hu.bme.mit.inf.dslreasoner.smt.reasoner/src/hu/bme/mit/inf/dslreasoner/smt/reasoner/builder/SmtSolverHandler.xtend')
-rw-r--r--Solvers/SMT-Solver/hu.bme.mit.inf.dslreasoner.smt.reasoner/src/hu/bme/mit/inf/dslreasoner/smt/reasoner/builder/SmtSolverHandler.xtend64
1 files changed, 64 insertions, 0 deletions
diff --git a/Solvers/SMT-Solver/hu.bme.mit.inf.dslreasoner.smt.reasoner/src/hu/bme/mit/inf/dslreasoner/smt/reasoner/builder/SmtSolverHandler.xtend b/Solvers/SMT-Solver/hu.bme.mit.inf.dslreasoner.smt.reasoner/src/hu/bme/mit/inf/dslreasoner/smt/reasoner/builder/SmtSolverHandler.xtend
new file mode 100644
index 00000000..38ae1dae
--- /dev/null
+++ b/Solvers/SMT-Solver/hu.bme.mit.inf.dslreasoner.smt.reasoner/src/hu/bme/mit/inf/dslreasoner/smt/reasoner/builder/SmtSolverHandler.xtend
@@ -0,0 +1,64 @@
1package hu.bme.mit.inf.dslreasoner.smt.reasoner.builder
2
3import org.eclipse.emf.common.util.URI
4import java.io.InputStream
5import java.io.IOException
6import java.io.FileWriter
7import java.io.File
8import java.io.BufferedReader
9import java.io.InputStreamReader
10import org.eclipse.emf.common.CommonPlugin
11import hu.bme.mit.inf.dslreasoner.smt.reasoner.SmtSolverConfiguration
12
13class SmtSolverException extends Exception{
14 new(String s) { super(s) }
15 new(String s, Exception e) { super(s,e) }
16}
17
18class SmtSolverHandler {
19 public def callSolver(URI resourceURI, SmtSolverConfiguration configuration) {
20 val URI smtUri = CommonPlugin.resolve(resourceURI)
21 val File smtFile = new File(smtUri.toFileString())
22
23 val params =
24 '''/smt2 /st«
25 IF configuration.runtimeLimit != SmtSolverConfiguration::Unlimited» /T:«configuration.runtimeLimit»«ENDIF»«
26 IF configuration.memoryLimit != SmtSolverConfiguration::Unlimited» /memory:«configuration.memoryLimit»«ENDIF»«
27 IF configuration.fixRandomSeed» /rs:0«ENDIF
28 » «smtFile.path»'''
29
30 val Runtime runTime = Runtime.getRuntime()
31
32 try {
33 val process = runTime.exec(configuration.solverPath + " " + params)
34
35 val FileWriter writer = new FileWriter(smtFile,true)
36 writer.append("\n--------------\n")
37 appendStream(writer, process.getInputStream())
38 printStream(process.getErrorStream())
39 writer.close
40 } catch (IOException e) {
41 throw new SmtSolverException(
42 "Error during the input/output handling of the reasoner.", e)
43 }
44
45 return resourceURI
46 }
47
48 def private void printStream(InputStream inputStream) throws IOException {
49 val BufferedReader input = new BufferedReader(new InputStreamReader(inputStream))
50 var int line = -1
51 while ((line = input.read()) != -1) {
52 System.out.print(line as char)
53 }
54 input.close()
55 }
56
57 def private appendStream(FileWriter writer, InputStream inputStream) throws IOException {
58 val BufferedReader input = new BufferedReader(new InputStreamReader(inputStream))
59 var int line = -1
60 while ((line = input.read()) != -1) {
61 writer.append(line as char)
62 }
63 }
64} \ No newline at end of file