Skip to content

Commit

Permalink
minor edits to the parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Gidon Ernst committed Feb 8, 2024
1 parent 9537562 commit cd38db2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
7 changes: 3 additions & 4 deletions examples/copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ void main() {
int a[n];
int b[n];
int i=0;
int k;
assume(0 <= k && k < n);

assume(0 <= n);

while(i<n)
// invariant $main_inv1
{
b[i] = a[i];
i++;
}
// assert $main_sum1

int k;
assert(i == n);
assume(0 <= k && k < n);
assert(a[k] == b[k]);
}
8 changes: 4 additions & 4 deletions korn/src/korn/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,12 @@ object Main {

def run(file: String) {
info("program: " + file)
val stmts = Tool.parse(file)

if (dry) {
Tool.parse(file)
// do nothing
} else if (tools.isEmpty) {
val unit = Tool.translate(file)
val unit = Tool.translate(file, stmts)

if (write) {
val to = write_smt2 getOrElse smt2(file)
Expand All @@ -217,6 +218,7 @@ object Main {
}
} else {
import scala.util.control.Breaks._
val unit = Tool.translate(file, stmts)

breakable {
for (tool <- tools) {
Expand All @@ -225,8 +227,6 @@ object Main {

info("running: " + tool.how)

val unit = Tool.translate(file)

val to = write_smt2 getOrElse smt2(file)
if (tool.write)
info("clauses: " + to)
Expand Down
2 changes: 2 additions & 0 deletions korn/src/korn/horn/Unit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ class Unit(val file: String, stmts: List[Stmt]) {

case FunDef(ret, "reach_error", formals, body) =>
// built-in

case stmt @ FunDef(ret, name, formals, body) =>
val loc = korn.unpack(stmt.loc, "no location for while loop")
define(loc, name, formals, ret, body)

case _ =>
// nothing to do
}
Expand Down
2 changes: 2 additions & 0 deletions korn/src/korn/tool/Solve.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ abstract class Solve extends Tool {
}

def check(unit: Unit, smt2: String) = {
unit.run()

val (in, err, proc) = if (write) {
val out = new PrintStream(new File(smt2))
write(out, unit)
Expand Down
13 changes: 5 additions & 8 deletions korn/src/korn/tool/Tool.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintStream
import korn.Main
import korn.horn.Unit
import korn.smt.Model
import scala.concurrent.duration.Duration
import korn.smt.Scanner
import korn.smt.Parser
import korn.horn.Unit

sealed trait Result
case class Unknown(status: String) extends Result
Expand Down Expand Up @@ -72,15 +72,12 @@ object Tool {
status == 0
}

def parse(file: String) {
val stmts = korn.c.parse(file)
def parse(file: String) = {
korn.c.parse(file)
}

def translate(file: String) = {
val stmts = korn.c.parse(file)
object unit extends Unit(file, stmts)
unit.run()
unit
def translate(file: String, stmts: List[korn.c.Stmt]) = {
new korn.horn.Unit(file, stmts)
}

def model(in: BufferedReader): Model = {
Expand Down

0 comments on commit cd38db2

Please sign in to comment.