Skip to content

Commit d1dc519

Browse files
committed
Send program to Boogie via stdin
1 parent e4be814 commit d1dc519

1 file changed

Lines changed: 5 additions & 36 deletions

File tree

src/main/scala/viper/carbon/verifier/BoogieInterface.scala

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,15 @@ trait BoogieInterface {
159159
* Invoke Boogie.
160160
*/
161161
private def run(input: String, options: Seq[String]) = {
162-
// write program to a temporary file
163-
val tmp = File.createTempFile("carbon", ".bpl")
164-
tmp.deleteOnExit()
165-
val stream = new BufferedOutputStream(new FileOutputStream(tmp))
166-
stream.write(input.getBytes)
167-
stream.close()
168-
169162
reporter report BackendSubProcessReport("carbon", boogiePath, BeforeInputSent, _boogieProcessPid)
170163

171-
val cmd: Seq[String] = (Seq(boogiePath) ++ options ++ Seq(tmp.getAbsolutePath))
164+
// When the filename is "stdin.bpl" Boogie reads the program from standard input.
165+
val cmd: Seq[String] = Seq(boogiePath) ++ options ++ Seq("stdin.bpl")
172166
val pb: ProcessBuilder = new ProcessBuilder(cmd.asJava)
173167
val proc: Process = pb.start()
174168
_boogieProcess = Some(proc)
175169
_boogieProcessPid = Some(proc.pid)
176170

177-
178171
//proverShutDownHook approach taken from Silicon's codebase
179172
val proverShutdownHook = new Thread {
180173
override def run(): Unit = {
@@ -183,6 +176,8 @@ trait BoogieInterface {
183176
}
184177
Runtime.getRuntime.addShutdownHook(proverShutdownHook)
185178

179+
// Send the program to Boogie
180+
proc.getOutputStream.write(input.getBytes);
186181
proc.getOutputStream.close()
187182

188183
// _z3ProcessStream = Some(proc.descendants().toScala(LazyList))
@@ -239,30 +234,4 @@ trait BoogieInterface {
239234
case None =>
240235
}
241236
}
242-
243-
/* // TODO: investigate why passing the program directly does not work
244-
private def runX(input: String, options: Seq[String]): String = {
245-
def convertStreamToString(is: java.io.InputStream) = {
246-
val s = new java.util.Scanner(is).useDelimiter("\\A")
247-
if (s.hasNext) s.next() else ""
248-
}
249-
var res: String = ""
250-
var reserr: String = ""
251-
def out(input: java.io.InputStream) {
252-
res += convertStreamToString(input)
253-
input.close()
254-
}
255-
def err(in: java.io.InputStream) {
256-
reserr += convertStreamToString(in)
257-
in.close()
258-
}
259-
def in(output: java.io.OutputStream) {
260-
output.write(input.getBytes)
261-
output.close()
262-
}
263-
// Note: call exitValue to block until Boogie has finished
264-
// Note: we call boogie with an empty input "file" on stdin and parse the output
265-
(Seq(boogiePath) ++ options ++ Seq("stdin.bpl")).run(new ProcessIO(in, out, err)).exitValue()
266-
reserr + res
267-
}*/
268-
}
237+
}

0 commit comments

Comments
 (0)