Commit 9d7a38b4 authored by Kunshan Wang's avatar Kunshan Wang

Basid HAIL tests.

parent 63d8bde5
package uvm.hail.textinput
class HailTextReader {
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ import scala.collection.immutable.Stream
import java.io.StringWriter
import java.nio.CharBuffer
import uvm.utils.AntlrHelpers._
import uvm.utils.IOHelpers
class UIRTextReader(val idFactory: IDFactory) {
import UIRTextReader._
......@@ -25,20 +26,7 @@ class UIRTextReader(val idFactory: IDFactory) {
}
def read(ir: java.io.Reader, globalBundle: GlobalBundle): TrantientBundle = {
val sb = new StringBuilder()
val cb = new Array[Char](4096)
var finished = false
while (!finished) {
val actualRead = ir.read(cb, 0, 4096)
if (actualRead > 0) {
sb.appendAll(cb, 0, actualRead)
} else {
finished = true
}
}
read(sb.toString(), globalBundle)
read(IOHelpers.slurp(ir), globalBundle)
}
def read(source: String, ais: ANTLRInputStream, globalBundle: GlobalBundle): TrantientBundle = {
......
package uvm.refimpl
import java.io.Reader
import uvm.refimpl.mem.Mutator
/** Common implementations of operations on the MicroVM. Used by both the MuCtx and many comminsts. */
......@@ -16,10 +17,14 @@ object MetaOperations {
val bundle = microVM.irReader.read(s, microVM.globalBundle)
microVM.addBundle(bundle)
}
/** Load a HAIL script */
def loadHail(r: Reader)(implicit microVM: MicroVM, mutator: Mutator): Unit = ???
def loadHail(r: Reader)(implicit microVM: MicroVM, mutator: Mutator): Unit = {
microVM.hailScriptLoader.loadHail(r)
}
/** Load a HAIL script */
def loadHail(s: String)(implicit microVM: MicroVM, mutator: Mutator): Unit = ???
def loadHail(s: String)(implicit microVM: MicroVM, mutator: Mutator): Unit = {
microVM.hailScriptLoader.loadHail(s)
}
}
\ No newline at end of file
package uvm.refimpl
import scala.collection.mutable.HashSet
import uvm._
import uvm.ir.textinput.IDFactory
import uvm.ir.textinput.UIRTextReader
import uvm.refimpl.hail.HailScriptLoader
import uvm.refimpl.itpr._
import uvm.refimpl.mem._
import uvm.refimpl.mem.TypeSizes.Word
import scala.collection.mutable.HashSet
import uvm.ir.textinput.UIRTextReader
import uvm.ir.textinput.IDFactory
import uvm.refimpl.nat.NativeCallHelper
object MicroVM {
......@@ -16,8 +18,8 @@ object MicroVM {
}
class MicroVM(heapSize: Word = MicroVM.DEFAULT_HEAP_SIZE,
globalSize: Word = MicroVM.DEFAULT_GLOBAL_SIZE,
stackSize: Word = MicroVM.DEFAULT_STACK_SIZE) {
globalSize: Word = MicroVM.DEFAULT_GLOBAL_SIZE,
stackSize: Word = MicroVM.DEFAULT_STACK_SIZE) {
// implicitly injected resources
private implicit val microVM = this
......@@ -35,26 +37,26 @@ class MicroVM(heapSize: Word = MicroVM.DEFAULT_HEAP_SIZE,
val contexts = new HashSet[MuCtx]()
val irReader = new UIRTextReader(new IDFactory())
val hailScriptLoader = new HailScriptLoader()
{
// The micro VM allocates stacks on the heap in the large object space. It is represented as a bug chunk of byte array.
// VOID, BYTE, BYTE_ARRAY: The micro VM allocates stacks on the heap in the large object space.
// It is represented as a big chunk of byte array.
// So the GC must know about this type because the GC looks up the globalBundle for types.
globalBundle.typeNs.add(InternalTypes.VOID)
globalBundle.typeNs.add(InternalTypes.BYTE)
globalBundle.typeNs.add(InternalTypes.BYTE_ARRAY)
// Types for the @uvm.meta.* common instructions.
globalBundle.typeNs.add(InternalTypes.BYTES)
globalBundle.typeNs.add(InternalTypes.BYTES_R)
globalBundle.typeNs.add(InternalTypes.REFS)
globalBundle.typeNs.add(InternalTypes.REFS_R)
// BYTES, BYTES_R, REFS, REFS_R: Types for the @uvm.meta.* common instructions.
import InternalTypes._
for (ty <- Seq(VOID, BYTE, BYTE_ARRAY, BYTES, BYTES_R, REFS, REFS_R)) {
globalBundle.typeNs.add(ty)
}
// Some internal constants needed by the HAIL loader
// Some internal constants needed
constantPool.addGlobalVar(InternalTypes.NULL_REF_VOID)
constantPool.addGlobalVar(InternalTypes.NULL_IREF_VOID)
constantPool.addGlobalVar(InternalTypes.NULL_FUNCREF_VV)
constantPool.addGlobalVar(InternalTypes.NULL_THREADREF)
constantPool.addGlobalVar(InternalTypes.NULL_STACKREF)
for (c <- Seq(NULL_REF_VOID, NULL_IREF_VOID, NULL_FUNCREF_VV, NULL_THREADREF, NULL_STACKREF)) {
globalBundle.constantNs.add(c)
constantPool.addGlobalVar(c)
}
}
/**
......@@ -101,7 +103,7 @@ class MicroVM(heapSize: Word = MicroVM.DEFAULT_HEAP_SIZE,
} catch {
case e: NoSuchElementException => throw new UvmRefImplException("No Mu entity has ID %d".format(id), e)
}
/**
* Set the trap handler.
*/
......
......@@ -45,7 +45,7 @@ abstract class MuValue {
def ty: Type
def vb: ValueBox
def showTy: String = "%s: %s".format(this.getClass.getSimpleName, ty.repr)
def showTy: String = "%s: %s".format(this.getClass.getSimpleName, ty)
}
abstract class MuSeqValue extends MuValue {
......@@ -418,6 +418,7 @@ class MuCtx(_mutator: Mutator)(
val (ptr, ty) = loc.ty match {
case TypeIRef(t) => (false, t)
}
val uty = InternalTypePool.unmarkedOf(ty)
val addr = MemoryOperations.addressOf(ptr, loc.vb)
val nb = ValueBox.makeBoxForType(uty)
......
......@@ -52,8 +52,8 @@ object InternalTypes {
val NULL_REF_VOID = ConstNull(REF_VOID) := internal("null_ref_void")
val NULL_IREF_VOID = ConstNull(IREF_VOID) := internal("null_iref_void")
val NULL_FUNCREF_VV = ConstNull(FUNCREF_VV) := internal("null_funcref_vv")
val NULL_THREADREF = ConstNull(STACKREF) := internal("null_threadref")
val NULL_STACKREF = ConstNull(THREADREF) := internal("null_stackref")
val NULL_THREADREF = ConstNull(THREADREF) := internal("null_threadref")
val NULL_STACKREF = ConstNull(STACKREF) := internal("null_stackref")
}
object InternalTypePool {
......@@ -82,6 +82,7 @@ object TypeInferer {
case c: Constant => c.constTy
case g: GlobalCell => irefOf(g.cellTy)
case f: Function => funcOf(f.sig)
case e: ExposedFunc => funcPtrOf(e.func.sig)
case p: NorParam => p.ty
case p: ExcParam => REF_VOID
case r: InstResult => {
......
......@@ -49,23 +49,23 @@ case class TypeUFuncPtr(var sig: FuncSig) extends AbstractPointerType
object Type {
def prettyPrint(ty: Type): String = ty match {
case TypeInt(length) => "int<%d>".format(length)
case TypeFloat() => "float"
case TypeDouble() => "double"
case TypeRef(ty) => "ref<%s>".format(ty.repr)
case TypeIRef(ty) => "iref<%s>".format(ty.repr)
case TypeWeakRef(ty) => "weakref<%s>".format(ty.repr)
case TypeStruct(fieldTy) => "struct<%s>".format(fieldTy.map(_.repr).mkString(" "))
case TypeArray(elemTy, len) => "array<%s %d>".format(elemTy.repr, len)
case TypeHybrid(fixedPart, varPart) => "hybrid<%s %s>".format(fixedPart.repr, varPart.repr)
case TypeVoid() => "void"
case TypeFuncRef(sig) => "funcref<%s>".format(sig.repr)
case TypeThreadRef() => "threadref"
case TypeStackRef() => "stackref"
case TypeTagRef64() => "tagref64"
case TypeVector(elemTy, len) => "vector<%s %d>".format(elemTy.repr, len)
case TypeUPtr(ty) => "uptr<%s>".format(ty.repr)
case TypeUFuncPtr(sig) => "ufuncptr<%s>".format(sig.repr)
case _ => "unknown type " + ty.getClass.getName
case TypeInt(length) => "int<%d>".format(length)
case TypeFloat() => "float"
case TypeDouble() => "double"
case TypeRef(ty) => "ref<%s>".format(ty.repr)
case TypeIRef(ty) => "iref<%s>".format(ty.repr)
case TypeWeakRef(ty) => "weakref<%s>".format(ty.repr)
case TypeStruct(fieldTys) => "struct<%s>".format(fieldTys.map(_.repr).mkString(" "))
case TypeArray(elemTy, len) => "array<%s %d>".format(elemTy.repr, len)
case TypeHybrid(fieldTys, varPart) => "hybrid<%s %s>".format(fieldTys.map(_.repr).mkString(" "), varPart.repr)
case TypeVoid() => "void"
case TypeFuncRef(sig) => "funcref<%s>".format(sig.repr)
case TypeThreadRef() => "threadref"
case TypeStackRef() => "stackref"
case TypeTagRef64() => "tagref64"
case TypeVector(elemTy, len) => "vector<%s %d>".format(elemTy.repr, len)
case TypeUPtr(ty) => "uptr<%s>".format(ty.repr)
case TypeUFuncPtr(sig) => "ufuncptr<%s>".format(sig.repr)
case _ => "unknown type " + ty.getClass.getName
}
}
......@@ -16,7 +16,7 @@ object AntlrHelpers {
lazy val sourceLines = ArrayBuffer(source.lines.toSeq: _*)
override def syntaxError(recognizer: Recognizer[_, _], offendingSymbol: Object,
line: Int, charPositionInLine: Int, msg: String, e: RecognitionException): Unit = {
line: Int, charPositionInLine: Int, msg: String, e: RecognitionException): Unit = {
val theLine = sourceLines(line - 1)
val marker = " " * charPositionInLine + "^"
buf += "line %d:%d %s\n%s\n%s".format(line, charPositionInLine, msg, theLine, marker)
......@@ -35,4 +35,35 @@ object AntlrHelpers {
val near = tok.getText()
return "At %d:%d near '%s': %s".format(line, column, near, s)
}
}
\ No newline at end of file
}
trait AdvancedAntlrHelper {
def sourceLines: IndexedSeq[String]
def inCtx(ctx: ParserRuleContext, s: String): String = {
val tok1 = ctx.getStart
val tok2 = ctx.getStop
val firstLine = nearTok(tok1, s)
val line = tok1.getLine()
val theLine = sourceLines(line - 1)
val line2 = tok2.getLine()
val column = tok1.getCharPositionInLine()
val end = if (line == line2) tok2.getCharPositionInLine else theLine.length()
val near = tok1.getText()
val marker = " " * column + "^" + "~" * (end - column)
"At %d:%d near '%s': %s\n%s\n%s".format(line, column, near, s, theLine, marker)
}
def inCtx(ctx: TerminalNode, s: String): String = nearTok(ctx.getSymbol, s)
def nearTok(tok: Token, s: String): String = {
val line = tok.getLine()
val column = tok.getCharPositionInLine()
val near = tok.getText()
return "At %d:%d near '%s': %s".format(line, column, near, s)
}
}
\ No newline at end of file
package uvm.utils
import java.io.Reader
object IOHelpers {
def slurp(r: Reader): String = {
val sb = new StringBuilder()
val cb = new Array[Char](4096)
var finished = false
while (!finished) {
val actualRead = r.read(cb, 0, 4096)
if (actualRead > 0) {
sb.appendAll(cb, 0, actualRead)
} else {
finished = true
}
}
sb.toString()
}
}
\ No newline at end of file
This diff is collapsed.
package uvm.refimpl.hail
import java.io.FileReader
import uvm.refimpl.MuCtx
import uvm.refimpl.UvmBundleTesterBase
class UvmHailTesterBase extends UvmBundleTesterBase {
def loadHailFromFile(ctx: MuCtx, fileName: String): Unit = {
val r = new FileReader(fileName)
ctx.loadHail(r)
r.close()
}
}
\ No newline at end of file
// hail
.new $h_i8 <@i8>
.new $h_i16 <@i16>
.new $h_i32 <@i32>
.new $h_i64 <@i64>
.new $h_float <@float>
.new $h_double <@double>
.new $h_rv <@refvoid>
.new $h_irv <@irefvoid>
.new $h_frv_v <@frv_v>
.init $h_i8 = @I8_42
.init $h_i16 = @I16_43
.init $h_i32 = @I32_4
.init $h_i64 = @I64_5
.init $h_float = @F_6
.init $h_double = @D_7
.init $h_rv = $h_rv
.init $h_irv = @g_rirv
.init $h_frv_v = @foo
.init @g_ri8 = $h_i8
.init @g_ri16 = $h_i16
.init @g_ri32 = $h_i32
.init @g_ri64 = $h_i64
.init @g_rfloat = $h_float
.init @g_rdouble = $h_double
.init @g_rrv = $h_rv
.init @g_rirv = $h_irv
.init @g_rfrv_v = $h_frv_v
// hail
.init @g_uptr1 = 42
.init @g_uptr2 = @P1
.init @g_ufp1 = 43
.init @g_ufp2 = @P2
.init @g_ufp3 = @foo_native
.init @g_tr1 = 3.14d
.init @g_tr2 = 0xfedcba9876543
.init @g_tr3 = {NULL 31}
.init @g_tr4 = @D_7
.init @g_tr5 = @I52_99
.new $empty <@void>
.init @g_tr6 = {$empty @I6_15}
.init @g_empty = $empty
// hail
.init @g_small_struct = {1 2 3 4}
.init @g_big_struct = {5.0f {6 7 8 9} 10.0d}
.init @g_small_array = {1 2 3 4 5 6}
.init @g_vector = {@F_1 @F_2 @F_3 @F_4}
.init @g_big_struct2 = {3.14f}
.init @g_big_struct2[1][2] = 3
.init @g_small_array2 = {1 2 3}
.init @g_small_array2[5] = 6
.newhybrid $hy <@my_hybrid> 3
.init $hy = {1 2.0d {3 4 5}}
.init @g_my_hybrid_r = $hy
// hail
.new $h_i8 <@i8>
.new $h_i16 <@i16>
.new $h_i32 <@i32>
.new $h_i64 <@i64>
.new $h_float <@float>
.new $h_double <@double>
.new $h_rv <@refvoid>
.new $h_irv <@irefvoid>
.new $h_wrv <@weakrefvoid>
.new $h_frv_v <@frv_v>
.new $h_thread <@thread>
.new $h_stack <@stack>
.init $h_i8 = 0x5a
.init $h_i16 = 0x55aa
.init $h_i32 = 0x55aa55aa
.init $h_i64 = 0x5a5a55aa5a5a55aa
.init $h_float = 3.14f
.init $h_double = 6.28d
.init $h_rv = NULL
.init $h_irv = NULL
.init $h_wrv = NULL
.init $h_frv_v = NULL
.init $h_thread = NULL
.init $h_stack = NULL
.init @g_ri8 = $h_i8
.init @g_ri16 = $h_i16
.init @g_ri32 = $h_i32
.init @g_ri64 = $h_i64
.init @g_rfloat = $h_float
.init @g_rdouble = $h_double
.init @g_rrv = $h_rv
.init @g_rirv = $h_irv
.init @g_rwrv = $h_wrv
.init @g_rfrv_v = $h_frv_v
.init @g_rthread = $h_thread
.init @g_rstack = $h_stack
// uir
// require "../uvm-refimpl-test/primitives.uir"
.typedef @refrefvoid = ref<@refvoid>
.typedef @refirefvoid = ref<@irefvoid>
.typedef @refweakrefvoid = ref<@weakrefvoid>
.typedef @reffrv_v = ref<@frv_v>
.typedef @refthread = ref<@thread>
.typedef @refstack = ref<@stack>
.global @g_ri8 <@refi8>
.global @g_ri16 <@refi16>
.global @g_ri32 <@refi32>
.global @g_ri64 <@refi64>
.global @g_rfloat <@reffloat>
.global @g_rdouble <@refdouble>
.global @g_rrv <@refrefvoid>
.global @g_rirv <@refirefvoid>
.global @g_rwrv <@refweakrefvoid>
.global @g_rfrv_v <@reffrv_v>
.global @g_rthread <@refthread>
.global @g_rstack <@refstack>
.const @I8_42 <@i8> = 42
.const @I16_43 <@i16> = 43
.funcdecl @foo <@v_v>
.expose @foo_native = @foo #DEFAULT @I64_2
.const @P1 <@ptrvoid> = 0x123456789abcdef0
.const @P2 <@fpv_v> = 0xfedcba9876543210
.global @g_uptr1 <@ptrvoid>
.global @g_uptr2 <@ptrvoid>
.global @g_ufp1 <@fpv_v>
.global @g_ufp2 <@fpv_v>
.global @g_ufp3 <@fpv_v>
.global @g_tr1 <@tagref64>
.global @g_tr2 <@tagref64>
.global @g_tr3 <@tagref64>
.global @g_tr4 <@tagref64>
.global @g_tr5 <@tagref64>
.global @g_tr6 <@tagref64>
.global @g_empty <@refvoid>
.const @I52_99 <@i52> = 99
.const @I6_15 <@i6> = 15
.typedef @small_struct = struct <@i8 @i16 @i32 @i64>
.typedef @big_struct = struct <@float @small_struct @double>
.typedef @small_array = array <@i32 6>
.global @g_small_struct <@small_struct>
.global @g_big_struct <@big_struct>
.global @g_small_array <@small_array>
.global @g_vector <@4xfloat>
.global @g_big_struct2 <@big_struct>
.global @g_small_array2 <@small_array>
.typedef @my_hybrid = hybrid <@i64 @double @i8>
.typedef @my_hybrid_r = ref<@my_hybrid>
.global @g_my_hybrid_r <@my_hybrid_r>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment