WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit 159d0562 authored by Kunshan Wang's avatar Kunshan Wang
Browse files

Modified parser.

parent 6ccfcd33
......@@ -5,37 +5,4 @@ import uvm.types._
import uvm.ssavariables._
object Main extends App {
val i64 = TypeInt(64)
println(i64.length)
val ic = ConstInt(i64, 999)
println(ic.ty)
val iNew: Value = InstNew(i64)
iNew.resolve
println(i64)
val ref = TypeRef(i64)
val refNode: TypeRef = TypeRef(null)
refNode.id = 2;
refNode.name = Some("@refNode")
val strNode = TypeStruct(Seq(i64, refNode))
strNode.id = 3;
strNode.name = Some("@strNode")
refNode.ty = strNode
println(refNode)
println(strNode)
val ns = new SimpleNamespace[Type]()
ns.add(i64)
ns.add(refNode)
println(ns("@refNode"))
}
\ No newline at end of file
......@@ -3,8 +3,8 @@ package uvm.ir.textinput
import org.scalatest._
import uvm._
trait AbstractReaderSpec extends FlatSpec with Matchers
with TestingBundlesValidators {
trait AbstractReaderSpec extends FlatSpec with Matchers {
// with TestingBundlesValidators {
val EMPTY_BUNDLE = new Bundle()
......@@ -16,26 +16,26 @@ trait AbstractReaderSpec extends FlatSpec with Matchers
it should "read simple type definitions" in {
val b = parseFile("tests/uvm-parsing-test/types.uir", EMPTY_BUNDLE)
validateTypes(b)
//validateTypes(b)
}
it should "read simple constant definitions" in {
val b = parseFile("tests/uvm-parsing-test/constants.uir", EMPTY_BUNDLE)
validateConstants(b)
//validateConstants(b)
}
it should "read simple function definitions" in {
val b = parseFile("tests/uvm-parsing-test/functions.uir", EMPTY_BUNDLE)
validateFunctions(b)
//validateFunctions(b)
}
it should "read simple instruction definitions" in {
val b = parseFile("tests/uvm-parsing-test/instructions.uir", EMPTY_BUNDLE)
validateInstructions(b)
//validateInstructions(b)
}
it should "handle loading of multiple bundles" in {
val gb = parseFile("tests/uvm-parsing-test/redef-base.uir", EMPTY_BUNDLE)
val b = parseFile("tests/uvm-parsing-test/redef-overlay.uir", gb)
validateRedef(gb, b)
//val gb = parseFile("tests/uvm-parsing-test/redef-base.uir", EMPTY_BUNDLE)
//val b = parseFile("tests/uvm-parsing-test/redef-overlay.uir", gb)
//validateRedef(gb, b)
gb.merge(b)
validateRedefAfterMerge(gb, b)
//gb.merge(b)
//validateRedefAfterMerge(gb, b)
}
}
\ No newline at end of file
......@@ -9,7 +9,10 @@ class AntlrUvmIRReaderSpec extends AbstractReaderSpec {
override def theSubject = "AntlrUvmIRReader"
override def parseFile(fileName: String, globalBundle: Bundle): Bundle = {
AntlrUvmIRReader.read(new java.io.FileReader(fileName), globalBundle)
val idf = new IDFactory()
val r = new UIRTextReader(idf)
val ir = r.read(new java.io.FileReader(fileName), globalBundle)
ir
}
}
\ No newline at end of file
......@@ -24,7 +24,7 @@ trait ExtraMatchers extends Assertions with Matchers {
def shouldBeAConstIntOf(len: Int, num: BigInt) {
thing shouldBeA[ConstInt] { its =>
its.ty shouldBeATypeIntOf(len)
its.constTy shouldBeATypeIntOf(len)
its.num shouldEqual num
}
}
......
package uvm.ir.textinput
import collection.mutable.Stack
import org.scalatest._
class UvmIRParserSpec extends FlatSpec with Matchers {
def parseFile(fileName: String) {
val ir = UvmIRParser(new java.io.FileReader(fileName))
println(ir)
}
"The IRParser" should "parse simple type definitions" in {
parseFile("tests/uvm-parsing-test/types.uir")
}
it should "parse simple constant definitions" in {
parseFile("tests/uvm-parsing-test/constants.uir")
}
it should "parse simple function definitions" in {
parseFile("tests/uvm-parsing-test/functions.uir")
}
it should "parse simple instruction definitions" in {
parseFile("tests/uvm-parsing-test/instructions.uir")
}
}
\ No newline at end of file
package uvm.ir.textinput
import org.scalatest._
import uvm.Bundle
class UvmIRReaderSpec extends AbstractReaderSpec {
override def theSubject = "UvmIRReader"
override def parseFile(fileName: String, globalBundle: Bundle): Bundle = {
UvmIRReader.read(new java.io.FileReader(fileName), globalBundle)
}
}
\ No newline at end of file
.const @ci8 <int<8>> = 127
.const @ci16 <int<16>> = 32767
.const @ci32 <int<32>> = 2147483647
.const @ci64 <int<64>> = 9223372036854775807
.typedef @i1 = int<1>
.typedef @i8 = int<8>
.typedef @i16 = int<16>
.typedef @i32 = int<32>
.typedef @i64 = int<64>
.const @ci64neg <int<64>> = -42
.const @ci8 <@i8> = 127
.const @ci16 <@i16> = 32767
.const @ci32 <@i32> = 2147483647
.const @ci64 <@i64> = 9223372036854775807
.const @cio64 <int<64>> = 0777
.const @ci64neg <@i64> = -42
.const @cix64 <int<64>> = 0x123456789abcdef0
.const @cixovf <int<64>> = 0xffffffffffffffff
.const @cixovf2 <int<64>> = 0x8000000000000000
.const @cio64 <@i64> = 0777
.const @cf <float> = 3.14f
.const @cfnan <float> = nanf
.const @cfninf <float> = -inff
.const @cfpinf <float> = +inff
.const @cfbits <float> = bitsf(0x12345678)
.const @cd <double> = 6.28d
.const @cdnan <double> = nand
.const @cdninf <double> = -infd
.const @cdpinf <double> = +infd
.const @cdbits <double> = bitsd(0xfedcba9876543210)
.const @cix64 <@i64> = 0x123456789abcdef0
.const @cixovf <@i64> = 0xffffffffffffffff
.const @cixovf2 <@i64> = 0x8000000000000000
.const @cs1 <struct<int<64> double>> = {100 200.0d}
.const @cs2 <struct<double struct<float int<64>> int<32>>> = {1.0d {2.0f 3} 4}
.typedef @float = float
.typedef @double = double
.const @cons <@Cons> = {42 NULL}
.typedef @Cons = struct<int<64> ref<@Cons>>
.const @cf <@float> = 3.14f
.const @cfnan <@float> = nanf
.const @cfninf <@float> = -inff
.const @cfpinf <@float> = +inff
.const @cfbits <@float> = bitsf(0x12345678)
.const @cd <@double> = 6.28d
.const @cdnan <@double> = nand
.const @cdninf <@double> = -infd
.const @cdpinf <@double> = +infd
.const @cdbits <@double> = bitsd(0xfedcba9876543210)
.const @cr <ref<int<64>>> = NULL
.const @cir <iref<float>> = NULL
.const @cwr <weakref<@Cons>>= NULL
.const @cfu <func<void ()>> = NULL
.const @cth <thread> = NULL
.const @cst <stack> = NULL
.typedef @s1 = struct<@i64 @cdouble>
.const @cs1 <@s1> = {@ci64 @cd}
.typedef @s2 = struct<@float @i64>
.const @cs2 <@s2> = {@cf @ci64}
.const @sgf <struct<iref<int<64>> func<void ()>>> = {@gi64 @fdummy}
.typedef @s3 = struct<@double @s2 @i32>
.const @cs2 <@s3> = {@cd @cs2 @ci32}
.global @gi64 <int<64>>
.typedef @rv = ref<@void>
.typedef @irv = iref<@void>
.typedef @wrv = weakref<@void>
.funcsig @sig0 = @void ()
.typedef @func0 = func <@sig0>
.typedef @thread = thread
.typedef @stack = stack
.funcdecl @fdummy <void ()>
.const @cr <@rv> = NULL
.const @cir <@irv> = NULL
.const @cfu <@cf> = NULL
.const @cth <@cth> = NULL
.const @cst <@cst> = NULL
.typedef @4xfloat = vector <@float 4>
.typedef @4xi32 = vector <@int 4>
.typedef @2xdouble = vector <@double 2>
.const @F_1 <@float> = 1.0f
.const @F_2 <@float> = 2.0f
.const @F_3 <@float> = 3.0f
.const @F_4 <@float> = 4.0f
.const @I32_1 <@float> = 1
.const @I32_2 <@float> = 2
.const @I32_3 <@float> = 3
.const @I32_4 <@float> = 4
.const @D_1 <@float> = 1.0d
.const @D_2 <@float> = 2.0d
.const @D_3 <@float> = 3.0d
.const @D_4 <@float> = 4.0d
.const @cv4f <@4xfloat> = VEC {@F_1 @F_2 @F_3 @F_4}
.const @cv4i <@4xi32> = VEC {@I32_1 @I32_2 @I32_3 @I32_4}
.const @cv4d <@2xdouble> = VEC {@D_1 @D_2 @D_3 @D_4}
.typedef @Cons = struct<@i32 @RefCons>
.typedef @RefCons = ref<@Cons>
.const @cons0 <@Cons> = {@ci32 @consNull}
.const @consNull <@RefCons> = NULL
.global @gi64 <@i64>
.funcdecl @fdummy <@sig0>
.typedef @ii64 = iref<@i64>
.typedef @sgf_t = struct<@ii64 @sig0>
.const @sgf <@sgf_t> = {@gi64 @fdummy}
.funcsig @foo = void ()
.typedef @i8 = int<8>
.typedef @i16 = int<16>
.typedef @i32 = int<32>
.typedef @i64 = int<64>
.typedef @void = void
.funcsig @bar = int<64> (int<32> int<16>)
.typedef @ii8 = iref<@i8>
.typedef @iii8 = iref<@ii8>
.funcsig @baz = int<32> (int<32> iref<iref<int<8>>>)
.funcsig @foo = @void ()
.funcsig @sig_fs = void (int<32>)
.funcsig @bar = @i64 (@i32 @i16)
.funcsig @baz = @i32 (@i32 @iii8)
.funcsig @sig_fs = @void (@i32)
.typedef @sig_t = func<@sig_fs>
.funcdecl @signal <@sig_t (int<32> @sig_t)>
.funcdecl @signal <@sig_t (@i32 @sig_t)>
.const @zero <int<32>> = 0
.const @zero <@i32> = 0
.funcdef @main <@baz> (%argc %argv) {
.funcdef @main VERSION @main_v1 <@baz> (%argc %argv) {
%entry:
RET <int<32>> @zero
}
.funcdef @implicitentry <@foo> () {
RET <int<32>> @zero
RET <@i32> @zero
}
.funcdef @intBinOpTest <void (int<32> int<32>)> (%p0 %p1) {
%add = ADD <int<32>> %p0 %p1
%sub = SUB <int<32>> %p0 %p1
%mul = MUL <int<32>> %p0 %p1
%udiv = UDIV <int<32>> %p0 %p1
%sdiv = SDIV <int<32>> %p0 %p1
%urem = UREM <int<32>> %p0 %p1
%srem = SREM <int<32>> %p0 %p1
%shl = SHL <int<32>> %p0 %p1
%lshr = LSHR <int<32>> %p0 %p1
%ashr = ASHR <int<32>> %p0 %p1
%and = AND <int<32>> %p0 %p1
%or = OR <int<32>> %p0 %p1
%xor = XOR <int<32>> %p0 %p1
RETVOID
.typedef @i1 = int<1>
.typedef @i8 = int<8>
.typedef @i16 = int<16>
.typedef @i32 = int<32>
.typedef @i64 = int<64>
.typedef @float = float
.typedef @double = double
.typedef @void = void
.typedef @rv = ref<@void>
.typedef @irv = iref<@void>
.typedef @wrv = weakref<@void>
.typedef @ri32 = ref<@i32>
.typedef @ri64 = ref<@i64>
.typedef @ii32 = iref<@i32>
.typedef @ii64 = iref<@i64>
.typedef @ii8 = iref<@i8>
.typedef @iii8 = iref<@ii8>
.funcsig @npnr_sig = @void ()
.typedef @npnr_func = func<@npnr_sig>
.funcsig @iii_sig = @i64 (@i64 @i64)
.typedef @iii_func = func<@iii_sig>
.typedef @thread = thread
.typedef @stack = stack
.typedef @tagref64 = tagref64
.typedef @4xfloat = vector <@float 4>
.typedef @4xi32 = vector <@int 4>
.typedef @2xdouble = vector <@double 2>
.const @I8_0 <@i8> = 0
.const @I16_0 <@i16> = 0
.const @I32_0 <@i32> = 0
.const @I64_0 <@i64> = 0
.const @F_0 <@float> = 0.0f
.const @D_0 <@float> = 0.0d
.const @I8_1 <@i8> = 1
.const @I16_1 <@i16> = 1
.const @I32_1 <@i32> = 1
.const @I64_1 <@i64> = 1
.const @F_1 <@float> = 1.0f
.const @D_1 <@float> = 1.0d
.const @I32_2 <@i32> = 2
.const @I64_2 <@i32> = 2
.const @I64_42 <@i32> = 42
.const @I64_43 <@i32> = 43
.const @FALSE <@i1> = 0
.const @TRUE <@i1> = 1
.const @NULLREF <@rv> = NULL
.funcsig @intBinOpTest_sig = @void (@i32 @i32)
.funcdef @intBinOpTest VERSION @intBinOpTest_v1 <@intBinOpTest_sig> (%p0 %p1) {
%entry:
%add = ADD <@i32> %p0 %p1
%sub = SUB <@i32> %p0 %p1
%mul = MUL <@i32> %p0 %p1
%udiv = UDIV <@i32> %p0 %p1
%sdiv = SDIV <@i32> %p0 %p1
%urem = UREM <@i32> %p0 %p1
%srem = SREM <@i32> %p0 %p1
%shl = SHL <@i32> %p0 %p1
%lshr = LSHR <@i32> %p0 %p1
%ashr = ASHR <@i32> %p0 %p1
%and = AND <@i32> %p0 %p1
%or = OR <@i32> %p0 %p1
%xor = XOR <@i32> %p0 %p1
RETVOID
}
.funcdef @fpBinOpTest <void (double double)> (%p0 %p1) {
%fadd = FADD <double> %p0 %p1
%fsub = FSUB <double> %p0 %p1
%fmul = FMUL <double> %p0 %p1
%fdiv = FDIV <double> %p0 %p1
%frem = FREM <double> %p0 %p1
RETVOID
.funcsig @fpBinOpTest_sig = @void (@double @double)
.funcdef @fpBinOpTest VERSION @fpBinOpTest_v1 <@fpBinOpTest_sig> (%p0 %p1) {
%entry:
%fadd = FADD <@double> %p0 %p1
%fsub = FSUB <@double> %p0 %p1
%fmul = FMUL <@double> %p0 %p1
%fdiv = FDIV <@double> %p0 %p1
%frem = FREM <@double> %p0 %p1
RETVOID
}
.funcdef @intCmpTest <void (int<64> int<64>)> (%p0 %p1) {
%eq = EQ <int<64>> %p0 %p1
%ne = NE <int<64>> %p0 %p1
%ult = ULT <int<64>> %p0 %p1
%ule = ULE <int<64>> %p0 %p1
%ugt = UGT <int<64>> %p0 %p1
%uge = UGE <int<64>> %p0 %p1
%slt = SLT <int<64>> %p0 %p1
%sle = SLE <int<64>> %p0 %p1
%sgt = SGT <int<64>> %p0 %p1
%sge = SGE <int<64>> %p0 %p1
RETVOID
.funcsig @intCmpTest_sig = @void (@i64 @i64)
.funcdef @intCmpTest VERSION @intCmpTest_v1 <@intCmpTest_sig> (%p0 %p1) {
%entry:
%eq = EQ <@i64> %p0 %p1
%ne = NE <@i64> %p0 %p1
%ult = ULT <@i64> %p0 %p1
%ule = ULE <@i64> %p0 %p1
%ugt = UGT <@i64> %p0 %p1
%uge = UGE <@i64> %p0 %p1
%slt = SLT <@i64> %p0 %p1
%sle = SLE <@i64> %p0 %p1
%sgt = SGT <@i64> %p0 %p1
%sge = SGE <@i64> %p0 %p1
RETVOID
}
.funcdef @fpCmpTest <void (float float)> (%p0 %p1) {
%ftrue = FTRUE <float> %p0 %p1
%ffalse = FFALSE <float> %p0 %p1
%ford = FORD <float> %p0 %p1
%foeq = FOEQ <float> %p0 %p1
%fone = FONE <float> %p0 %p1
%folt = FOLT <float> %p0 %p1
%fole = FOLE <float> %p0 %p1
%fogt = FOGT <float> %p0 %p1
%foge = FOGE <float> %p0 %p1
%funo = FUNO <float> %p0 %p1
%fueq = FUEQ <float> %p0 %p1
%fune = FUNE <float> %p0 %p1
%fult = FULT <float> %p0 %p1
%fule = FULE <float> %p0 %p1
%fugt = FUGT <float> %p0 %p1
%fuge = FUGE <float> %p0 %p1
RETVOID
.funcsig @fpCmpTest_sig = @void (@float @float)
.funcdef @fpCmpTest VERSION @fpCmpTest_v1 <@fpCmpTest_sig> (%p0 %p1) {
%entry:
%ftrue = FTRUE <@float> %p0 %p1
%ffalse = FFALSE <@float> %p0 %p1
%ford = FORD <@float> %p0 %p1
%foeq = FOEQ <@float> %p0 %p1
%fone = FONE <@float> %p0 %p1
%folt = FOLT <@float> %p0 %p1
%fole = FOLE <@float> %p0 %p1
%fogt = FOGT <@float> %p0 %p1
%foge = FOGE <@float> %p0 %p1
%funo = FUNO <@float> %p0 %p1
%fueq = FUEQ <@float> %p0 %p1
%fune = FUNE <@float> %p0 %p1
%fult = FULT <@float> %p0 %p1
%fule = FULE <@float> %p0 %p1
%fugt = FUGT <@float> %p0 %p1
%fuge = FUGE <@float> %p0 %p1
RETVOID
}
.funcdef @convTest <void (int<32> int<64> float double)> (%p0 %p1 %p2 %p3) {
%trunc = TRUNC <int<64> int<32>> %p1
%zext = ZEXT <int<32> int<64>> %p0
%sext = SEXT <int<32> int<64>> %p0
.funcsig @convTest_sig = @void (@i32 @i64 @float @double)
.funcdef @convTest VERSION @convTest_v1 <@convTest_sig> (%p0 %p1 %p2 %p3) {
%entry:
%trunc = TRUNC <@i64 @i32> %p1
%zext = ZEXT <@i32 @i64> %p0
%sext = SEXT <@i32 @i64> %p0
%fptrunc = FPTRUNC <double float> %p3
%fpext = FPEXT <float double> %p2
%fptrunc = FPTRUNC <@double @float> %p3
%fpext = FPEXT <@float @double> %p2
%fptoui = FPTOUI <double int<64>> %p3
%fptosi = FPTOSI <double int<64>> %p3
%uitofp = UITOFP <int<64> double> %p1
%sitofp = SITOFP <int<64> double> %p1
%fptoui = FPTOUI <@double @i64> %p3
%fptosi = FPTOSI <@double @i64> %p3
%uitofp = UITOFP <@i64 @double> %p1
%sitofp = SITOFP <@i64 @double> %p1
%bitcast0 = BITCAST <int<32> float> %p0
%bitcast1 = BITCAST <int<64> double> %p1
%bitcast2 = BITCAST <float int<32>> %p2
%bitcast3 = BITCAST <double int<64>> %p3
%bitcast0 = BITCAST <@i32 @float> %p0
%bitcast1 = BITCAST <@i64 @double> %p1
%bitcast2 = BITCAST <@float @i32> %p2
%bitcast3 = BITCAST <@double @i64> %p3
RETVOID
RETVOID
}
.funcdef @refCastTest <void (ref<void> iref<void> func<void ()>)> (%p0 %p1 %p2) {
%refcast = REFCAST <ref<void> ref<int<32>>> %p0
%irefcast = IREFCAST <iref<void> iref<int<64>>> %p1
%funccast = FUNCCAST <func<void()> func<@iiisig>> %p2
RETVOID
.funcsig @refCastTest_sig @void (@rv @irv @npnr_func)
.funcdef @refCastTest VERSION @refCastTest_v1 <@refCastTest_sig> (%p0 %p1 %p2) {
%entry:
%refcast = REFCAST <@rv @ri32> %p0
%irefcast = REFCAST <@irv @ii64> %p1
%funccast = REFCAST <@npnr_func @iii_func> %p2
RETVOID
}
.funcdef @ctrlFlow <void (int<32>)> (%p0) {
.funcsig @ctrlFlow_sig = @void (@i32)
.funcdef @ctrlFlow VERSION @ctrlFlow_v1 <@ctrlFlow_sig> (%p0) {
%entry:
%br1 = BRANCH %head
%head:
%phi = PHI <int<32>> { %entry: 0; %next: %i2; }
%zero = EQ <int<32>> %p0 0
%phi = PHI <@i32> { %entry: @I32_0; %next: %i2; }
%zero = EQ <@i32> %p0 @I32_0
%br2 = BRANCH2 %zero %body %exit
%body:
%switch = SWITCH <int<32>> %phi %other { 1: %one; 2: %two; }
%switch = SWITCH <@i32> %phi %other { @I32_1: %one; @I32_2: %two; }
%one:
%br3 = BRANCH %next
%two:
......@@ -109,35 +183,37 @@
%other:
%br5 = BRANCH %next
%next:
%i2 = SUB <int<32>> %phi 1
%i2 = SUB <@i32> %phi @I32_1
%br6 = BRANCH %head
%exit:
RETVOID
}
.funcsig @iiisig = int<64> (int<64> int<64>)
.funcdecl @callee1 <void ()>
.funcdecl @callee1 <@npnr_sig>
.funcdef @callee2 <@iiisig> (%p0 %p1) {
%rv = ADD <int<64>> %p0 %p1
%ret = RET <int<64>> %rv
.funcdef @callee2 VERSION @callee2_v1 <@iiisig> (%p0 %p1) {
%entry:
%rv = ADD <@i64> %p0 %p1
%ret = RET <@i64> %rv
}
.funcdef @callee3 <@iiisig> (%p0 %p1) {
%exc = NEW <double>
%throw = THROW %exc
.funcdef @callee3 VERSION @callee3_v1 <@iiisig> (%p0 %p1) {
%entry:
%exc = NEW <@double>
%throw = THROW %exc
}
.funcdef @caller1 <void ()> () {
%v1 = CALL <void ()> @callee1 ()
%v2 = CALL <@iiisig> @callee2 (1 2)
%v3 = INVOKE <@iiisig> @callee3 (3 4) %cont %catch
.funcdef @caller1 VERSION @caller1_v1 <@npnr_sig> () {
%entry:
%v1 = CALL <@npnr_sig> @callee1 ()
%v2 = CALL <@iiisig> @callee2 (@I64_1 @I64_2)
%v3 = CALL <@iiisig> @callee3 (@I64_1 @I64_2) EXC(%cont %catch)
%cont:
%v4 = CALL <void ()> @callee1 () KEEPALIVE (%v2 %v3)
%v5 = INVOKE <@iiisig> @callee3 (%v3 %v3) %cont2 %catch KEEPALIVE (%v2)