GitLab will be upgraded to the 12.10.14-ce.0 on 28 Sept 2020 at 2.00pm (AEDT) to 2.30pm (AEDT). 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 878c45f0 authored by Kunshan Wang's avatar Kunshan Wang

Test '&' operator.

parent 9d7a38b4
......@@ -26,6 +26,8 @@ lazy val root = (project in file(".")).settings(
"org.scalatest" %% "scalatest" % "2.2.4" % "test",
"junit" % "junit" % "4.12" % "test"
),
testOptions in Test += Tests.Argument("-oF"), // print full stack trace when testing
antlr4Settings,
......
......@@ -125,7 +125,7 @@ class UvmHailBasicTest extends UvmHailTesterBase {
assertTR64FP("@g_tr1", 3.14)
assertTR64Int("@g_tr2", 0xfedcba9876543L)
val nullref = mc.handleFromConst("@NULLREF").asInstanceOf[MuRefValue]
assertTR64Ref("@g_tr3", nullref, 31)
......@@ -256,6 +256,36 @@ class UvmHailBasicTest extends UvmHailTesterBase {
}
mc.closeContext()
}
it should "recognise the '&' expression to assign internal references" in {
val mc = microVM.newContext()
loadHailFromFile(mc, "tests/uvm-hail-test/basic-hail-test-5.hail")
val hBar = mc.loadGlobal("@g_my_hybrid_r").asInstanceOf[MuRefValue]
val hBarIr = mc.getIRef(hBar)
def assertIREqual(globalID: Int, expected: MuIRefValue): Unit = {
val hIr = mc.loadGlobal(globalID).asInstanceOf[MuIRefValue]
// printf("found offset: 0x%x expected offset: 0x%x\n", hIr.vb.offset, expected.vb.offset)
mc.refEq(hIr, expected) shouldBe true
}
assertIREqual("@g_iri64", mc.getFieldIRef(hBarIr, 0))
assertIREqual("@g_irdouble", mc.getFieldIRef(hBarIr, 1))
val hBarIr_vp = mc.getVarPartIRef(hBarIr)
assertIREqual("@g_iri8", hBarIr_vp)
val hBarIr_vp_2 = mc.shiftIRef(hBarIr_vp, mc.handleFromInt(2, 64))
val hBarIr_vp_3 = mc.shiftIRef(hBarIr_vp, mc.handleFromInt(3, 64))
assertIREqual("@g_iri8_2", hBarIr_vp_2)
assertIREqual("@g_irvoid", hBarIr_vp_3)
mc.closeContext()
}
}
object UvmHailBasicTest {
......
// hail
.newhybrid $bar <@my_hybrid> 5
.init @g_my_hybrid_r = $bar
.init @g_iri64 = &$bar[0]
.init @g_irdouble = &$bar[1]
.init @g_iri8 = &$bar[2]
.init @g_iri8_2 = &$bar[2][2]
.init @g_irvoid = &$bar[2][3] // implicit refcast
.init @g_irvoid2 = &@g_big_struct[2] // implicit refcast
// uir
// require "../uvm-refimpl-test/primitives.uir"
// test-1-2
.typedef @refrefvoid = ref<@refvoid>
.typedef @refirefvoid = ref<@irefvoid>
.typedef @refweakrefvoid = ref<@weakrefvoid>
......@@ -27,6 +29,8 @@
.funcdecl @foo <@v_v>
.expose @foo_native = @foo #DEFAULT @I64_2
// test-3
.const @P1 <@ptrvoid> = 0x123456789abcdef0
.const @P2 <@fpv_v> = 0xfedcba9876543210
......@@ -49,6 +53,8 @@
.const @I52_99 <@i52> = 99
.const @I6_15 <@i6> = 15
// test-4
.typedef @small_struct = struct <@i8 @i16 @i32 @i64>
.typedef @big_struct = struct <@float @small_struct @double>
.typedef @small_array = array <@i32 6>
......@@ -65,3 +71,12 @@
.global @g_my_hybrid_r <@my_hybrid_r>
// test-5
.global @g_iri64 <@irefi64>
.global @g_irdouble <@irefdouble>
.global @g_iri8 <@irefi8>
.global @g_iri8_2 <@irefi8>
.global @g_irvoid <@irefvoid>
.global @g_irvoid2 <@irefvoid>
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