GitLab will be partched to the latest stable version on 15 July 2020 at 2.00pm (AEDT) to 2.30pm (AEDT) due to Security Patch Availability. During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

Commit 7f3709b2 authored by Kunshan Wang's avatar Kunshan Wang

Hello world case with HAIL and native iface.

No C code written.
parent 878c45f0
package uvm.refimpl.hail
import org.scalatest._
import java.io.FileReader
import uvm._
import uvm.types._
import uvm.ssavariables._
import uvm.refimpl._
import uvm.refimpl.itpr._
import uvm.refimpl.mem._
import MemoryOrder._
import AtomicRMWOptr._
import uvm.refimpl.mem.TypeSizes.Word
import uvm.refimpl.TrapHandlerResult.{ ThreadExit, Rebind }
import uvm.refimpl.HowToResume.{ PassValues, ThrowExc }
import ch.qos.logback.classic.Level._
import uvm.refimpl.RichMuCtx._
import com.kenai.jffi.Library
class UvmHailHelloWorldTest extends UvmHailTesterBase {
setLogLevels(ROOT_LOGGER_NAME -> INFO,
"uvm.refimpl.hail" -> DEBUG //"uvm.refimpl.mem" -> DEBUG,
//"uvm.refimpl.itpr" -> DEBUG
)
preloadBundles("tests/uvm-refimpl-test/primitives.uir",
"tests/uvm-hail-test/hello-world-test.uir")
behavior of "The HAIL reader and the unsafe native interface"
it should "create string constants and print it using the 'write' syscall" in {
val mc = microVM.newContext()
loadHailFromFile(mc, "tests/uvm-hail-test/hello-world-test.hail")
// Resolve the function address for 'write'
val lib = Library.getDefault()
val funcAddr = lib.getSymbolAddress("write")
val hFuncAddr = mc.handleFromFP("@write.fp", funcAddr)
val hWrite = mc.handleFromGlobal("@write")
mc.store(NOT_ATOMIC, hWrite, hFuncAddr)
val func = mc.handleFromFunc("@main")
testFunc(mc, func, Seq()) { (ctx, th, st, wp) =>
val Seq(rv: MuIntValue) = ctx.dumpKeepalives(st, 0)
val rvInt = ctx.handleToSInt(rv).toLong
printf("[trap handler] %d bytes written\n", rvInt)
rvInt shouldBe 13
returnFromTrap(st)
}
mc.closeContext()
}
}
\ No newline at end of file
// hail
.newhybrid $hw <@string> 13
// "Hello world!\n"
.init $hw = {13 {72 101 108 108 111 32 119 111 114 108 100 33 10}}
.init @conststr_helloworld = $hw
// uir
// require "../uvm-refimpl-test/primitives.uir"
.typedef @size_t = int<64>
.funcsig @write.sig = (@i32 @ptrvoid @size_t) -> (@size_t)
.typedef @write.fp = ufuncptr<@write.sig>
.global @write <@write.fp>
.typedef @string = hybrid<@i64 @i8>
.typedef @string.r = ref<@string>
.global @conststr_helloworld <@string.r>
.const @STDOUT <@i32> = 1
.funcsig @main.sig = () -> ()
.funcdef @main VERSION %1 <@main.sig> {
%entry():
%str = LOAD <@string.r> @conststr_helloworld
%str.ir = GETIREF <@string> %str
%str.l = GETFIELDIREF <@string 0> %str.ir
%len = LOAD <@i64> %str.l // @i64 is the same as @size_t
%str.v = GETVARPARTIREF <@string> %str.ir
%write = LOAD <@write.fp> @write
%buf = COMMINST @uvm.native.pin <@irefi8> (%str.v)
%rv = CCALL #DEFAULT <@write.fp @write.sig> %write (@STDOUT %buf %len)
COMMINST @uvm.native.unpin <@irefi8> (%str.v)
[%trap] TRAP <> KEEPALIVE(%rv)
COMMINST @uvm.thread_exit
}
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