Skip to content

Commit 878dbc9

Browse files
committed
attempting to generate external utility functions
1 parent 3d5bf80 commit 878dbc9

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package sai.llsc
2+
3+
import sai.lang.llvm._
4+
import sai.lang.llvm.IR._
5+
6+
import sai.structure.freer._
7+
import Eff._
8+
import Freer._
9+
import Handlers._
10+
import OpenUnion._
11+
import State._
12+
13+
import lms.core._
14+
import lms.core.Backend._
15+
import lms.core.virtualize
16+
import lms.macros.SourceContext
17+
import lms.core.stub.{While => _, _}
18+
19+
import sai.lmsx._
20+
import sai.lmsx.smt.SMTBool
21+
22+
import scala.collection.immutable.{List => StaticList, Map => StaticMap, Set => StaticSet}
23+
import scala.collection.mutable.{Map => MutableMap, Set => MutableSet}
24+
25+
// Writing models of syscall/external functions is often painful and error-prone
26+
// in a low-level language, and we don't want to maintain multiple version of those
27+
// external/intrinsic functions with only slightly backend difference.
28+
// Can we generate them from our Scala DSL?
29+
30+
@virtualize
31+
trait GenExternal extends SymExeDefs with EngineBase {
32+
def sym_exit[T: Manifest](ss: Rep[SS], args: Rep[List[Value]]): Rep[T] = ???
33+
34+
def gen_llsc_assert[T: Manifest](ss: Rep[SS], args: Rep[List[Value]], k: (Rep[SS], Rep[Value]) => Rep[T]): Rep[T] = {
35+
val v = args(0)
36+
if (v.isConc) {
37+
// Note: we directly project the integer field of v, which is safe if
38+
// the source program is type checked against the C llsc_assert declaration.
39+
if (v.int == 0) sym_exit[T](ss, args)
40+
else k(ss, IntV(1, 32))
41+
} else {
42+
val ss1 = ss.addPC(v.toSMTBoolNeg)
43+
if (checkPC(ss1.pc)) sym_exit[T](ss1, args)
44+
else k(ss1, IntV(1, 32))
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)