Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mu-impl-ref2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mu
mu-impl-ref2
Commits
b028c4e5
Commit
b028c4e5
authored
Aug 01, 2014
by
Kunshan Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test and fix constant parsing
parent
2d453cba
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
161 additions
and
23 deletions
+161
-23
src/main/scala/uvm/ir/textinput/irReader.scala
src/main/scala/uvm/ir/textinput/irReader.scala
+1
-1
src/test/scala/uvm/ir/textinput/AbstractReaderSpec.scala
src/test/scala/uvm/ir/textinput/AbstractReaderSpec.scala
+3
-0
src/test/scala/uvm/ir/textinput/ExtraMatchers.scala
src/test/scala/uvm/ir/textinput/ExtraMatchers.scala
+49
-1
src/test/scala/uvm/ir/textinput/TestingBundlesValidators.scala
...est/scala/uvm/ir/textinput/TestingBundlesValidators.scala
+108
-21
No files found.
src/main/scala/uvm/ir/textinput/irReader.scala
View file @
b028c4e5
...
...
@@ -132,7 +132,7 @@ object UvmIRReader {
case
FloatConstCons
(
num
)
=>
ConstFloat
(
t
,
num
)
case
DoubleConstCons
(
num
)
=>
ConstDouble
(
t
,
num
)
case
StructConstCons
(
fs
)
=>
ConstStruct
(
t
,
null
).
later
(
phase2
)
{
_
.
fields
=
for
(
f
<-
fs
)
yield
resGV
(
t
,
f
)
_
.
fields
=
for
(
(
ft
,
f
)
<-
t
.
asInstanceOf
[
TypeStruct
].
fieldTy
.
zip
(
fs
))
yield
resGV
(
f
t
,
f
)
}
case
NullConstCons
=>
ConstNull
(
t
)
}
...
...
src/test/scala/uvm/ir/textinput/AbstractReaderSpec.scala
View file @
b028c4e5
...
...
@@ -18,11 +18,14 @@ trait AbstractReaderSpec extends FlatSpec with Matchers
}
it
should
"read simple constant definitions"
in
{
val
b
=
parseFile
(
"tests/uvm-parsing-test/constants.uir"
)
validateConstants
(
b
)
}
it
should
"read simple function definitions"
in
{
val
b
=
parseFile
(
"tests/uvm-parsing-test/functions.uir"
)
validateFunctions
(
b
)
}
it
should
"read simple instruction definitions"
in
{
val
b
=
parseFile
(
"tests/uvm-parsing-test/instructions.uir"
)
validateInstructions
(
b
)
}
}
\ No newline at end of file
src/test/scala/uvm/ir/textinput/ExtraMatchers.scala
View file @
b028c4e5
...
...
@@ -3,6 +3,11 @@ package uvm.ir.textinput
import
scala.reflect._
import
org.scalatest._
import
uvm._
import
uvm.types._
import
uvm.ssavalues._
import
uvm.ifuncs._
trait
ExtraMatchers
extends
Assertions
with
Matchers
{
implicit
class
AnythingExtraMatchers
(
val
thing
:
Any
)
{
def
shouldBeA
[
T:
ClassTag
](
f
:
T
=>
Unit
)
:
Unit
=
{
...
...
@@ -12,11 +17,54 @@ trait ExtraMatchers extends Assertions with Matchers {
}
f
(
thing
.
asInstanceOf
[
T
])
}
def
shouldBeATypeIntOf
(
len
:
Int
)
{
thing
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
len
}
}
def
shouldBeAConstIntOf
(
len
:
Int
,
num
:
BigInt
)
{
thing
shouldBeA
[
ConstInt
]
{
its
=>
its
.
ty
shouldBeATypeIntOf
(
len
)
its
.
num
shouldEqual
num
}
}
def
shouldBeAConstFloatOf
(
something
:
Any
)
{
thing
shouldBeA
[
ConstFloat
]
{
its
=>
its
.
ty
shouldBeA
[
TypeFloat
]
thatsIt
something
match
{
case
`nan`
=>
assert
(
its
.
num
.
isNaN
)
case
ExactFloat
(
num
)
=>
its
.
num
shouldEqual
num
case
num
:
Float
=>
its
.
num
shouldEqual
(
num
+-
0.001F
)
case
_
=>
its
.
num
shouldEqual
something
}
}
}
def
shouldBeAConstDoubleOf
(
something
:
Any
)
{
thing
shouldBeA
[
ConstDouble
]
{
its
=>
its
.
ty
shouldBeA
[
TypeDouble
]
thatsIt
something
match
{
case
`nan`
=>
assert
(
its
.
num
.
isNaN
)
case
ExactDouble
(
num
)
=>
its
.
num
shouldEqual
num
case
num
:
Double
=>
its
.
num
shouldEqual
(
num
+-
0.001F
)
case
_
=>
its
.
num
shouldEqual
something
}
}
}
}
val
thatsIt
=
{
f
:
Any
=>
}
case
object
nan
case
class
ExactFloat
(
num
:
Float
)
case
class
ExactDouble
(
num
:
Double
)
def
exactly
(
num
:
Float
)
=
ExactFloat
(
num
)
def
exactly
(
num
:
Double
)
=
ExactDouble
(
num
)
def
bitsf
(
num
:
Int
)
=
java
.
lang
.
Float
.
intBitsToFloat
(
num
)
def
bitsd
(
num
:
Long
)
=
java
.
lang
.
Double
.
longBitsToDouble
(
num
)
}
object
ExtraMatchers
extends
ExtraMatchers
{
object
ExtraMatchers
{
}
\ No newline at end of file
src/test/scala/uvm/ir/textinput/TestingBundlesValidators.scala
View file @
b028c4e5
...
...
@@ -13,6 +13,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
def
ty
=
b
.
typeNs
def
const
=
b
.
globalValueNS
def
globalValue
=
b
.
globalValueNS
def
globalData
=
b
.
globalDataNS
def
sig
=
b
.
funcSigNs
def
func
=
b
.
funcNs
}
...
...
@@ -20,11 +21,11 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
def
validateTypes
(
bundle
:
Bundle
)
{
val
our
=
bundle
our
ty
"@i1"
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
1
}
our
ty
"@i8"
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
8
}
our
ty
"@i16"
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
16
}
our
ty
"@i32"
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
32
}
our
ty
"@i64"
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
64
}
our
ty
"@i1"
shouldBeA
TypeIntOf
(
1
)
our
ty
"@i8"
shouldBeA
TypeIntOf
(
8
)
our
ty
"@i16"
shouldBeA
TypeIntOf
(
16
)
our
ty
"@i32"
shouldBeA
TypeIntOf
(
32
)
our
ty
"@i64"
shouldBeA
TypeIntOf
(
64
)
our
ty
"@f"
shouldBeA
[
TypeFloat
]
thatsIt
our
ty
"@d"
shouldBeA
[
TypeDouble
]
thatsIt
...
...
@@ -33,37 +34,37 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
our
ty
"@irv"
shouldBeA
[
TypeIRef
]
{
_
.
ty
shouldBeA
[
TypeVoid
]
thatsIt
}
our
ty
"@wrv"
shouldBeA
[
TypeWeakRef
]
{
_
.
ty
shouldBeA
[
TypeVoid
]
thatsIt
}
our
ty
"@ri16"
shouldBeA
[
TypeRef
]
{
_
.
ty
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
16
}
}
our
ty
"@ri16_2"
shouldBeA
[
TypeRef
]
{
_
.
ty
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
16
}
}
our
ty
"@ri16"
shouldBeA
[
TypeRef
]
{
_
.
ty
shouldBeA
TypeIntOf
(
16
)
}
our
ty
"@ri16_2"
shouldBeA
[
TypeRef
]
{
_
.
ty
shouldBeA
TypeIntOf
(
16
)
}
our
ty
"@s0"
shouldBeA
[
TypeStruct
]
{
_
.
fieldTy
shouldBe
empty
}
our
ty
"@s1"
shouldBeA
[
TypeStruct
]
{
its
=>
its
fieldTy
0
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
8
}
its
fieldTy
1
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
16
}
its
fieldTy
2
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
32
}
its
fieldTy
3
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
64
}
its
fieldTy
0
shouldBeA
TypeIntOf
(
8
)
its
fieldTy
1
shouldBeA
TypeIntOf
(
16
)
its
fieldTy
2
shouldBeA
TypeIntOf
(
32
)
its
fieldTy
3
shouldBeA
TypeIntOf
(
64
)
its
fieldTy
4
shouldBeA
[
TypeFloat
]
thatsIt
its
fieldTy
5
shouldBeA
[
TypeDouble
]
thatsIt
its
fieldTy
6
shouldBeA
[
TypeRef
]
{
_
.
ty
shouldBeA
[
TypeVoid
]
thatsIt
}
its
fieldTy
7
shouldBeA
[
TypeIRef
]
{
_
.
ty
shouldBeA
[
TypeVoid
]
thatsIt
}
its
fieldTy
8
shouldBeA
[
TypeWeakRef
]
{
_
.
ty
shouldBeA
[
TypeVoid
]
thatsIt
}
its
fieldTy
9
shouldBeA
[
TypeRef
]
{
_
.
ty
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
16
}
}
its
fieldTy
10
shouldBeA
[
TypeRef
]
{
_
.
ty
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
16
}
}
its
fieldTy
9
shouldBeA
[
TypeRef
]
{
_
.
ty
shouldBeA
TypeIntOf
(
16
)
}
its
fieldTy
10
shouldBeA
[
TypeRef
]
{
_
.
ty
shouldBeA
TypeIntOf
(
16
)
}
}
our
ty
"@cons"
shouldBeA
[
TypeStruct
]
{
its
=>
its
fieldTy
0
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
64
}
its
fieldTy
0
shouldBeA
TypeIntOf
(
64
)
its
fieldTy
1
shouldBeA
[
TypeRef
]
{
_
.
ty
shouldBe
(
our
ty
"@cons"
)}
}
our
ty
"@a0"
shouldBeA
[
TypeArray
]
{
its
=>
its
.
elemTy
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
8
}
its
.
elemTy
shouldBeA
TypeIntOf
(
8
)
its
.
len
shouldEqual
100
}
our
ty
"@a1"
shouldBeA
[
TypeArray
]
{
its
=>
its
.
elemTy
shouldBeA
[
TypeStruct
]
{
whose
=>
whose
fieldTy
0
shouldBeA
[
TypeDouble
]
thatsIt
whose
fieldTy
1
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
64
}
whose
fieldTy
1
shouldBeA
TypeIntOf
(
64
)
}
its
.
len
shouldEqual
10
}
...
...
@@ -74,7 +75,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
our
ty
"@h0"
shouldBeA
[
TypeHybrid
]
{
its
=>
its
.
fixedPart
shouldBeA
[
TypeVoid
]
thatsIt
its
.
varPart
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
8
}
its
.
varPart
shouldBeA
TypeIntOf
(
8
)
}
our
ty
"@h1"
shouldBeA
[
TypeHybrid
]
{
its
=>
its
.
fixedPart
shouldBeA
[
TypeStruct
]
{
whose
=>
...
...
@@ -82,7 +83,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
whose
fieldTy
1
shouldBe
(
our
ty
"@i32"
)
whose
fieldTy
2
shouldBeA
[
TypeFloat
]
thatsIt
}
its
.
varPart
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
64
}
its
.
varPart
shouldBeA
TypeIntOf
(
64
)
}
our
ty
"@v"
shouldBeA
[
TypeVoid
]
thatsIt
...
...
@@ -92,10 +93,10 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
its
.
sig
.
paramTy
shouldBe
empty
}
our
ty
"@f1"
shouldBeA
[
TypeFunc
]
{
its
=>
its
.
sig
.
retTy
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
32
}
its
.
sig
.
paramTy
(
0
)
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
32
}
its
.
sig
.
retTy
shouldBeA
TypeIntOf
(
32
)
its
.
sig
paramTy
0
shouldBeATypeIntOf
(
32
)
its
.
sig
.
paramTy
(
1
)
shouldBeA
[
TypeIRef
]
{
_
.
ty
shouldBeA
[
TypeIRef
]
{
_
.
ty
shouldBeA
[
TypeInt
]
{
_
.
length
shouldEqual
8
}
}
_
.
ty
shouldBeA
TypeIntOf
(
8
)
}
}
}
...
...
@@ -103,4 +104,90 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
our
ty
"@st"
shouldBeA
[
TypeStack
]
thatsIt
our
ty
"@tr64"
shouldBeA
[
TypeTagRef64
]
thatsIt
}
def
validateConstants
(
bundle
:
Bundle
)
{
val
our
=
bundle
our
const
"@ci8"
shouldBeAConstIntOf
(
8
,
127
)
our
const
"@ci16"
shouldBeAConstIntOf
(
16
,
32767
)
our
const
"@ci32"
shouldBeAConstIntOf
(
32
,
2147483647
)
our
const
"@ci64"
shouldBeAConstIntOf
(
64
,
9223372036854775807L
)
our
const
"@ci64neg"
shouldBeAConstIntOf
(
64
,
BigInt
(-
42L
)
&
0xffffffffffffffff
L
)
our
const
"@cio64"
shouldBeAConstIntOf
(
64
,
BigInt
(
"777"
,
8
))
our
const
"@cix64"
shouldBeAConstIntOf
(
64
,
BigInt
(
"123456789abcdef0"
,
16
))
our
const
"@cixovf"
shouldBeAConstIntOf
(
64
,
BigInt
(
"ffffffffffffffff"
,
16
))
our
const
"@cixovf2"
shouldBeAConstIntOf
(
64
,
BigInt
(
"8000000000000000"
,
16
))
our
const
"@cf"
shouldBeAConstFloatOf
3.14F
our
const
"@cfnan"
shouldBeAConstFloatOf
nan
our
const
"@cfninf"
shouldBeAConstFloatOf
Float
.
NegativeInfinity
our
const
"@cfpinf"
shouldBeAConstFloatOf
Float
.
PositiveInfinity
our
const
"@cfbits"
shouldBeAConstFloatOf
exactly
(
bitsf
(
0x12345678
))
our
const
"@cd"
shouldBeAConstDoubleOf
6.28D
our
const
"@cdnan"
shouldBeAConstDoubleOf
nan
our
const
"@cdninf"
shouldBeAConstDoubleOf
Double
.
NegativeInfinity
our
const
"@cdpinf"
shouldBeAConstDoubleOf
Double
.
PositiveInfinity
our
const
"@cdbits"
shouldBeAConstDoubleOf
exactly
(
bitsd
(
0xfedcba9876543210
L
))
our
const
"@cs1"
shouldBeA
[
ConstStruct
]
{
its
=>
its
.
constTy
shouldBeA
[
TypeStruct
]
{
whose
=>
whose
fieldTy
0
shouldBeATypeIntOf
(
64
)
whose
fieldTy
1
shouldBeA
[
TypeDouble
]
thatsIt
}
its
fields
0
shouldBeAConstIntOf
(
64
,
100
)
its
fields
1
shouldBeAConstDoubleOf
200.0D
}
our
const
"@cs2"
shouldBeA
[
ConstStruct
]
{
its
=>
its
.
constTy
shouldBeA
[
TypeStruct
]
{
whose
=>
whose
fieldTy
0
shouldBeA
[
TypeDouble
]
thatsIt
whose
fieldTy
1
shouldBeA
[
TypeStruct
]
{
where
=>
where
fieldTy
0
shouldBeA
[
TypeFloat
]
thatsIt
where
fieldTy
1
shouldBeATypeIntOf
(
64
)
}
whose
fieldTy
2
shouldBeATypeIntOf
(
32
)
}
its
fields
0
shouldBeAConstDoubleOf
1.0D
its
fields
1
shouldBeA
[
ConstStruct
]
{
whose
=>
whose
fields
0
shouldBeAConstFloatOf
2.0F
whose
fields
1
shouldBeAConstIntOf
(
64
,
3
)
}
its
fields
2
shouldBeAConstIntOf
(
32
,
4
)
}
our
const
"@cons"
shouldBeA
[
ConstStruct
]
{
its
=>
its
.
constTy
shouldBe
(
our
ty
"@Cons"
)
its
fields
0
shouldBeAConstIntOf
(
64
,
42
)
its
fields
1
shouldBeA
[
ConstNull
]
{
_
.
ty
shouldBeA
[
TypeRef
]
{
_
.
ty
shouldBe
(
our
ty
"@Cons"
)
}}
}
our
const
"@cr"
shouldBeA
[
ConstNull
]
{
_
.
ty
shouldBeA
[
TypeRef
]
{
_
.
ty
shouldBeATypeIntOf
(
64
)
}}
our
const
"@cir"
shouldBeA
[
ConstNull
]
{
_
.
ty
shouldBeA
[
TypeIRef
]
{
_
.
ty
shouldBeA
[
TypeFloat
]
thatsIt
}}
our
const
"@cwr"
shouldBeA
[
ConstNull
]
{
_
.
ty
shouldBeA
[
TypeWeakRef
]
{
_
.
ty
shouldBe
(
our
ty
"@Cons"
)
}}
our
const
"@cfu"
shouldBeA
[
ConstNull
]
{
_
.
ty
shouldBeA
[
TypeFunc
]
{
_
.
sig
shouldBeA
[
FuncSig
]
{
its
=>
its
.
retTy
shouldBeA
[
TypeVoid
]
thatsIt
its
.
paramTy
shouldBe
empty
}}}
our
const
"@cth"
shouldBeA
[
ConstNull
]
{
_
.
ty
shouldBeA
[
TypeThread
]
thatsIt
}
our
const
"@cst"
shouldBeA
[
ConstNull
]
{
_
.
ty
shouldBeA
[
TypeStack
]
thatsIt
}
our
globalData
"@gi64"
shouldBeA
[
GlobalData
]
{
_
.
ty
shouldBeATypeIntOf
(
64
)
}
our
func
"@fdummy"
shouldBeA
[
Function
]
{
_
.
sig
shouldBeA
[
FuncSig
]
{
its
=>
its
.
retTy
shouldBeA
[
TypeVoid
]
thatsIt
its
.
paramTy
shouldBe
empty
}}
}
def
validateFunctions
(
bundle
:
Bundle
)
{
val
our
=
bundle
}
def
validateInstructions
(
bundle
:
Bundle
)
{
val
our
=
bundle
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment