Skip to content

Commit

Permalink
Added unclonable record and anvil.{hls, test} annotation support.
Browse files Browse the repository at this point in the history
  • Loading branch information
robby-phd committed Mar 9, 2025
1 parent ad6c985 commit 71ccb1d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 75 deletions.
2 changes: 1 addition & 1 deletion jvm/src/test/scala/org/sireum/anvil/IRSimulatorTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class IRSimulatorTest extends SireumRcSpec {
override def string: String = "AnvilTest.Output"
}, reporter) match {
case Some(ir) =>
val state = IRSimulator.State.Ext.create(ir.anvil.config.memory, ir.maxRegisters)
val state = IRSimulator.State.create(ir.anvil.config.memory, ir.maxRegisters)
IRSimulator(ir.anvil).evalProcedure(state, ir.procedure)
val displaySize = ir.anvil.config.printSize
val offset = ir.globalInfoMap.get(Anvil.displayName).get.offset + ir.anvil.spTypeByteSize +
Expand Down
4 changes: 2 additions & 2 deletions jvm/src/test/scala/org/sireum/anvil/example/add-test.sc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import org.sireum._
import org.sireum.U16._

def add(x: U16, y: U16): U16 = {
@anvil.hls def add(x: U16, y: U16): U16 = {
return x + y
}

def testAdd(): Unit = {
@anvil.test def testAdd(): Unit = {
println(add(u16"3", u16"5"))
}
27 changes: 11 additions & 16 deletions shared/src/main/scala/org/sireum/anvil/IRSimulator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ package org.sireum.anvil

import org.sireum._
import org.sireum.lang.{ast => AST}
import org.sireum.U8._
import org.sireum.U64._

object IRSimulator {
@msig trait State {
def memory: MSZ[U8]

def temps: MSZ[U64]

@record @unclonable class State(val memory: MSZ[U8], val temps: MSZ[U64]) {
def cpIndex: Z = {
return temps.size - 3
}
Expand Down Expand Up @@ -134,9 +131,7 @@ object IRSimulator {
}
}

@ext("State_Ext") object Ext {
@pure def create(memory: Z, temps: Z): State = $
}
@strictpure def create(memory: Z, temps: Z): State = State(MSZ.create(memory, u8"0"), MSZ.create(temps + 3, u64"0"))

}

Expand Down Expand Up @@ -815,14 +810,9 @@ import IRSimulator._
}
}

@pure def evalBlock(state: State, b: AST.IR.BasicBlock): Unit = {
val edits = ops.ISZOps((for (g <- b.grounds) yield evalGroundOrJump(Either.Left(g))) :+
@pure def evalBlock(state: State, b: AST.IR.BasicBlock): ISZ[State.Edit] = {
return ops.ISZOps((for (g <- b.grounds) yield evalGroundOrJump(Either.Left(g))) :+
evalGroundOrJump(Either.Right(b.jump))).parMapUnordered((f: State => State.Edit) => f(state))
var i = 0
while (i < edits.size) {
edits(i).update(state)
i = i + 1
}
}

def evalProcedure(state: State, p: AST.IR.Procedure): Unit = {
Expand All @@ -845,7 +835,12 @@ import IRSimulator._
while (state.CP != u64"0" && state.CP != u64"1") {
val b = blockMap.get(state.CP).get
//log("Evaluating", b)
evalBlock(state, b)
val edits = evalBlock(state, b)
var i = 0
while (i < edits.size) {
edits(i).update(state)
i = i + 1
}
}

//println(s"End state: $state")
Expand Down
56 changes: 0 additions & 56 deletions shared/src/main/scala/org/sireum/anvil/State_Ext.scala

This file was deleted.

0 comments on commit 71ccb1d

Please sign in to comment.