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
87c9ebdc
Commit
87c9ebdc
authored
Oct 11, 2015
by
Kunshan Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Passes main test.
parent
0787369e
Changes
17
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
377 additions
and
349 deletions
+377
-349
src/main/scala/uvm/Bundle.scala
src/main/scala/uvm/Bundle.scala
+26
-3
src/main/scala/uvm/controlFlow.scala
src/main/scala/uvm/controlFlow.scala
+2
-2
src/main/scala/uvm/ir/textinput/UIRTextReader.scala
src/main/scala/uvm/ir/textinput/UIRTextReader.scala
+8
-8
src/main/scala/uvm/namespaces.scala
src/main/scala/uvm/namespaces.scala
+12
-5
src/main/scala/uvm/refimpl/MicroVM.scala
src/main/scala/uvm/refimpl/MicroVM.scala
+0
-3
src/main/scala/uvm/refimpl/clientInterface.scala
src/main/scala/uvm/refimpl/clientInterface.scala
+6
-6
src/main/scala/uvm/refimpl/itpr/ConstantPool.scala
src/main/scala/uvm/refimpl/itpr/ConstantPool.scala
+2
-1
src/main/scala/uvm/refimpl/itpr/InterpreterThread.scala
src/main/scala/uvm/refimpl/itpr/InterpreterThread.scala
+24
-20
src/main/scala/uvm/refimpl/itpr/boxes.scala
src/main/scala/uvm/refimpl/itpr/boxes.scala
+4
-4
src/main/scala/uvm/refimpl/itpr/operationHelpers.scala
src/main/scala/uvm/refimpl/itpr/operationHelpers.scala
+3
-3
src/main/scala/uvm/ssavariables/ssavariables.scala
src/main/scala/uvm/ssavariables/ssavariables.scala
+1
-3
src/test/scala/uvm/ir/textinput/TestingBundlesValidators.scala
...est/scala/uvm/ir/textinput/TestingBundlesValidators.scala
+4
-4
src/test/scala/uvm/refimpl/UvmBundleTesterBase.scala
src/test/scala/uvm/refimpl/UvmBundleTesterBase.scala
+2
-1
src/test/scala/uvm/refimpl/itpr/UvmInterpreterSpec.scala
src/test/scala/uvm/refimpl/itpr/UvmInterpreterSpec.scala
+46
-44
src/test/scala/uvm/refimpl/mem/UvmMemLayoutSpec.scala
src/test/scala/uvm/refimpl/mem/UvmMemLayoutSpec.scala
+6
-6
src/test/scala/uvm/refimpl/nat/NativeStackKeeperTest.scala
src/test/scala/uvm/refimpl/nat/NativeStackKeeperTest.scala
+7
-7
tests/uvm-refimpl-test/basic-tests.uir
tests/uvm-refimpl-test/basic-tests.uir
+224
-229
No files found.
src/main/scala/uvm/Bundle.scala
View file @
87c9ebdc
...
...
@@ -18,10 +18,10 @@ abstract class Bundle {
* + globalCellNs // Global cells
* + funcNs // Functions
* + expFuncNs // Exposed functions
* + localVarNs // Local variables (per basic block)
* + bbNs // Basic blocks (per function version)
*
* These namespaces are local, i.e. they cannot be directly looked up from a bundle:
* + bbNs // Basic blocks (per function version)
* + localVarNs // Local variables (per basic block)
* bbNs and localVarNs are part of particular FuncVers and BBs.
*/
val
allNs
=
new
NestedNamespace
[
Identified
](
None
)
...
...
@@ -64,6 +64,18 @@ class GlobalBundle extends Bundle {
for
(
cand
<-
newNs
.
all
)
{
try
{
oldNs
.
add
(
cand
)
def
assertPresent
[
T
<:
Identified
](
ns
:
NestedNamespace
[
T
],
obj
:
T
)
:
Unit
=
{
assert
(
ns
.
get
(
obj
.
id
)
==
Some
(
obj
))
if
(
obj
.
id
==
65731
)
{
printf
(
"Obj[65731] found in ns "
+
ns
)
}
ns
.
maybeParent
match
{
case
None
=>
case
Some
(
ns2
)
=>
assertPresent
(
ns2
,
obj
)
}
}
assertPresent
(
oldNs
.
asInstanceOf
[
NestedNamespace
[
T
]],
cand
)
}
catch
{
case
e
:
NameConflictException
=>
throw
new
IllegalRedefinitionException
(
...
...
@@ -78,6 +90,15 @@ class GlobalBundle extends Bundle {
fv
.
func
.
versions
=
fv
::
fv
.
func
.
versions
}
}
private
def
mergeLocalNamespaces
(
newBundle
:
TrantientBundle
)
{
for
(
fv
<-
newBundle
.
funcVerNs
.
all
)
{
fv
.
bbNs
.
reparent
(
allNs
)
for
(
bb
<-
fv
.
bbs
)
{
bb
.
localVarNs
.
reparent
(
allNs
)
}
}
}
def
merge
(
newBundle
:
TrantientBundle
)
{
// Only merge leaves
...
...
@@ -90,6 +111,8 @@ class GlobalBundle extends Bundle {
simpleMerge
(
expFuncNs
,
newBundle
.
expFuncNs
)
redefineFunctions
(
newBundle
.
funcVerNs
)
mergeLocalNamespaces
(
newBundle
)
}
}
\ No newline at end of file
src/main/scala/uvm/controlFlow.scala
View file @
87c9ebdc
...
...
@@ -32,7 +32,7 @@ class FuncVer extends IdentifiedSettable {
def
sig
:
FuncSig
=
func
.
sig
va
l
bbNs
=
new
SimpleNamespace
[
BasicBlock
]
va
r
bbNs
:
NestedNamespace
[
BasicBlock
]
=
null
// sub-namespace of allNs
}
class
BasicBlock
extends
IdentifiedSettable
{
...
...
@@ -40,5 +40,5 @@ class BasicBlock extends IdentifiedSettable {
var
excParam
:
Option
[
ExcParam
]
=
null
var
insts
:
Seq
[
Instruction
]
=
null
va
l
localVarNs
=
new
SimpleNamespace
[
LocalVariable
]
va
r
localVarNs
:
NestedNamespace
[
LocalVariable
]
=
null
// sub-namespace of allNs
}
src/main/scala/uvm/ir/textinput/UIRTextReader.scala
View file @
87c9ebdc
...
...
@@ -239,7 +239,7 @@ class UIRTextReader(val idFactory: IDFactory) {
case
t
:
TypeRefContext
=>
TypeRef
(
null
).
later
(
phase1
)
{
_
.
ty
=
t
.
ty
}
case
t
:
TypeIRefContext
=>
TypeIRef
(
null
).
later
(
phase1
)
{
_
.
ty
=
t
.
ty
}
case
t
:
TypeWeakRefContext
=>
TypeWeakRef
(
null
).
later
(
phase1
)
{
_
.
ty
=
t
.
ty
}
case
t
:
TypeStructContext
=>
TypeStruct
(
null
).
later
(
phase1
)
{
_
.
fieldTys
=
t
.
fieldTys
.
map
(
resTy
)}
case
t
:
TypeStructContext
=>
TypeStruct
(
null
).
later
(
phase1
)
{
_
.
fieldTys
=
t
.
fieldTys
.
map
(
resTy
)
}
case
t
:
TypeArrayContext
=>
TypeArray
(
null
,
t
.
length
.
longValue
()).
later
(
phase1
)
{
_
.
elemTy
=
t
.
ty
}
case
t
:
TypeHybridContext
=>
TypeHybrid
(
null
,
null
).
later
(
phase1
)
{
tt
=>
tt
.
fixedTy
=
t
.
fixedTy
;
tt
.
varTy
=
t
.
varTy
}
case
t
:
TypeVoidContext
=>
TypeVoid
()
...
...
@@ -295,12 +295,9 @@ class UIRTextReader(val idFactory: IDFactory) {
case
_:
TypeStruct
=>
ConstStruct
(
t
,
null
).
later
(
phase2
)
{
_
.
fields
=
for
(
gn
<-
cc
.
GLOBAL_NAME
())
yield
resGlobalVar
(
gn
)
}
case
_:
TypeArray
=>
ConstArray
(
t
,
null
).
later
(
phase2
)
{
case
_:
TypeArray
|
_
:
TypeVector
=>
ConstSeq
(
t
,
null
).
later
(
phase2
)
{
_
.
elems
=
for
(
gn
<-
cc
.
GLOBAL_NAME
())
yield
resGlobalVar
(
gn
)
}
case
_:
TypeVector
=>
ConstVector
(
t
,
null
).
later
(
phase2
)
{
_
.
elems
=
for
(
c
<-
cc
.
GLOBAL_NAME
())
yield
resConstByName
(
c
)
}
}
case
_:
CtorNullContext
=>
ConstNull
(
t
)
}
...
...
@@ -388,8 +385,9 @@ class UIRTextReader(val idFactory: IDFactory) {
ver
.
func
=
func
//func.versions = ver :: func.versions // Don't override here. Let the MicroVM redefine functions.
def
globalizeBB
(
name
:
String
)
:
String
=
globalize
(
name
,
verName
)
ver
.
bbNs
=
bundle
.
allNs
.
makeSubSpace
[
BasicBlock
]
def
globalizeBB
(
name
:
String
)
:
String
=
globalize
(
name
,
verName
)
// Resolve function version local entities
...
...
@@ -411,6 +409,8 @@ class UIRTextReader(val idFactory: IDFactory) {
bb
.
name
=
Some
(
bbName
)
ver
.
bbNs
.
add
(
bb
)
bb
.
localVarNs
=
bundle
.
allNs
.
makeSubSpace
[
LocalVariable
]
def
mkNorParam
(
ty
:
Type
,
name
:
String
)
:
NorParam
=
{
val
param
=
NorParam
(
ty
)
param
.
id
=
idFactory
.
getID
()
...
...
@@ -462,7 +462,7 @@ class UIRTextReader(val idFactory: IDFactory) {
val
(
sig
,
callee
,
argList
)
=
resFuncCallBody
(
fcb
)
cl
.
sig
=
sig
;
cl
.
callee
=
callee
;
cl
.
argList
=
argList
}
implicit
def
resDestClause
(
dc
:
DestClauseContext
)
:
DestClause
=
{
DestClause
(
dc
.
bb
,
dc
.
argList
())
}
...
...
@@ -473,7 +473,7 @@ class UIRTextReader(val idFactory: IDFactory) {
}
else
{
Some
(
ExcClause
(
ec
.
nor
,
ec
.
exc
))
}
// Make instruction
def
mkInst
(
bb
:
BasicBlock
,
instDef
:
InstContext
)
:
Instruction
=
{
...
...
src/main/scala/uvm/namespaces.scala
View file @
87c9ebdc
...
...
@@ -8,7 +8,7 @@ abstract class Namespace[T <: Identified] {
def
get
(
name
:
String
)
:
Option
[
T
]
def
add
(
obj
:
T
)
:
Unit
def
all
:
Iterable
[
T
]
}
...
...
@@ -37,21 +37,28 @@ class SimpleNamespace[T <: Identified] extends Namespace[T] {
idMap
.
put
(
obj
.
id
,
obj
)
obj
.
name
match
{
case
None
=>
case
None
=>
case
Some
(
name
)
=>
nameMap
.
put
(
name
,
obj
)
}
}
def
all
=
idMap
.
values
}
class
NestedNamespace
[
T
<:
Identified
](
va
l
maybeParent
:
Option
[
NestedNamespace
[
_
>:
T
]])
extends
SimpleNamespace
[
T
]
{
class
NestedNamespace
[
T
<:
Identified
](
va
r
maybeParent
:
Option
[
NestedNamespace
[
_
>:
T
<:
Identified
]])
extends
SimpleNamespace
[
T
]
{
override
def
add
(
obj
:
T
)
:
Unit
=
{
super
.
add
(
obj
)
maybeParent
.
foreach
(
_
.
add
(
obj
))
}
def
makeSubSpace
[
U
<:
T
]()
:
NestedNamespace
[
U
]
=
{
new
NestedNamespace
[
U
](
Some
(
this
))
}
def
reparent
[
U
>:
T
<:
Identified
](
newParent
:
NestedNamespace
[
U
])
=
{
maybeParent
=
Some
(
newParent
)
for
(
obj
<-
all
)
{
newParent
.
add
(
obj
)
}
}
}
src/main/scala/uvm/refimpl/MicroVM.scala
View file @
87c9ebdc
...
...
@@ -39,11 +39,8 @@ class MicroVM(heapSize: Word = MicroVM.DEFAULT_HEAP_SIZE,
{
// The micro VM allocates stacks on the heap in the large object space. It is represented as a bug chunk of byte array.
// So the GC must know about this type because the GC looks up the globalBundle for types.
globalBundle
.
allNs
.
add
(
InternalTypes
.
VOID
)
globalBundle
.
typeNs
.
add
(
InternalTypes
.
VOID
)
globalBundle
.
allNs
.
add
(
InternalTypes
.
BYTE
)
globalBundle
.
typeNs
.
add
(
InternalTypes
.
BYTE
)
globalBundle
.
allNs
.
add
(
InternalTypes
.
BYTE_ARRAY
)
globalBundle
.
typeNs
.
add
(
InternalTypes
.
BYTE_ARRAY
)
}
...
...
src/main/scala/uvm/refimpl/clientInterface.scala
View file @
87c9ebdc
...
...
@@ -86,19 +86,19 @@ class ClientAgent(mutator: Mutator)(
val
t
=
microVM
.
globalBundle
.
typeNs
(
typeID
).
asInstanceOf
[
TypeVector
]
val
et
=
t
.
elemTy
.
asInstanceOf
[
TypeInt
]
val
preparedVs
=
for
(
v
<-
vs
)
yield
OpHelper
.
trunc
(
v
,
et
.
length
)
newHandle
(
t
,
Box
Vector
(
preparedVs
.
map
(
BoxInt
)))
newHandle
(
t
,
Box
Seq
(
preparedVs
.
map
(
BoxInt
)))
}
def
putFloatVec
(
typeID
:
Int
,
vs
:
Seq
[
Float
])
:
Handle
=
{
val
t
=
microVM
.
globalBundle
.
typeNs
(
typeID
).
asInstanceOf
[
TypeVector
]
val
et
=
t
.
elemTy
.
asInstanceOf
[
TypeFloat
]
newHandle
(
t
,
Box
Vector
(
vs
.
map
(
BoxFloat
)))
newHandle
(
t
,
Box
Seq
(
vs
.
map
(
BoxFloat
)))
}
def
putDoubleVec
(
typeID
:
Int
,
vs
:
Seq
[
Double
])
:
Handle
=
{
val
t
=
microVM
.
globalBundle
.
typeNs
(
typeID
).
asInstanceOf
[
TypeVector
]
val
et
=
t
.
elemTy
.
asInstanceOf
[
TypeDouble
]
newHandle
(
t
,
Box
Vector
(
vs
.
map
(
BoxDouble
)))
newHandle
(
t
,
Box
Seq
(
vs
.
map
(
BoxDouble
)))
}
def
putPointer
(
typeID
:
Int
,
v
:
Word
)
:
Handle
=
{
...
...
@@ -156,7 +156,7 @@ class ClientAgent(mutator: Mutator)(
def
toIntVec
(
h
:
Handle
,
signExt
:
Boolean
=
false
)
:
Seq
[
BigInt
]
=
{
val
t
=
h
.
ty
.
asInstanceOf
[
TypeVector
]
val
et
=
t
.
elemTy
.
asInstanceOf
[
TypeInt
]
val
bv
=
h
.
vb
.
asInstanceOf
[
Box
Vector
]
val
bv
=
h
.
vb
.
asInstanceOf
[
Box
Seq
]
for
(
b
<-
bv
.
values
)
yield
{
val
ib
=
b
.
asInstanceOf
[
BoxInt
]
if
(
signExt
)
OpHelper
.
prepareSigned
(
ib
.
value
,
et
.
length
)
else
OpHelper
.
prepareUnsigned
(
ib
.
value
,
et
.
length
)
...
...
@@ -164,11 +164,11 @@ class ClientAgent(mutator: Mutator)(
}
def
toFloatVec
(
h
:
Handle
)
:
Seq
[
Float
]
=
{
h
.
vb
.
asInstanceOf
[
Box
Vector
].
values
.
map
(
b
=>
b
.
asInstanceOf
[
BoxFloat
].
value
)
h
.
vb
.
asInstanceOf
[
Box
Seq
].
values
.
map
(
b
=>
b
.
asInstanceOf
[
BoxFloat
].
value
)
}
def
toDoubleVec
(
h
:
Handle
)
:
Seq
[
Double
]
=
{
h
.
vb
.
asInstanceOf
[
Box
Vector
].
values
.
map
(
b
=>
b
.
asInstanceOf
[
BoxDouble
].
value
)
h
.
vb
.
asInstanceOf
[
Box
Seq
].
values
.
map
(
b
=>
b
.
asInstanceOf
[
BoxDouble
].
value
)
}
def
toPointer
(
h
:
Handle
)
:
Word
=
{
...
...
src/main/scala/uvm/refimpl/itpr/ConstantPool.scala
View file @
87c9ebdc
...
...
@@ -25,13 +25,14 @@ class ConstantPool(implicit microVM: MicroVM) {
case
ConstDouble
(
ty
,
num
)
=>
BoxDouble
(
num
)
case
ConstStruct
(
ty
,
flds
)
=>
BoxStruct
(
flds
.
map
(
maybeMakeBox
))
case
ConstNull
(
ty
)
=>
ty
match
{
case
_:
TypeVoid
=>
BoxVoid
()
case
_:
TypeRef
=>
BoxRef
(
0L
)
case
_:
TypeIRef
=>
BoxIRef
(
0L
,
0L
)
case
_:
TypeFuncRef
=>
BoxFunc
(
None
)
case
_:
TypeThreadRef
=>
BoxThread
(
None
)
case
_:
TypeStackRef
=>
BoxStack
(
None
)
}
case
Const
Vector
(
ty
,
elems
)
=>
BoxVector
(
elems
.
map
(
maybeMakeBox
))
case
Const
Seq
(
ty
,
elems
)
=>
BoxSeq
(
elems
.
map
(
maybeMakeBox
))
case
ConstPointer
(
ty
,
addr
)
=>
BoxPointer
(
addr
)
case
gc
:
GlobalCell
=>
BoxIRef
(
0L
,
microVM
.
memoryManager
.
globalMemory
.
addrForGlobalCell
(
gc
))
case
f
:
Function
=>
BoxFunc
(
Some
(
f
))
...
...
src/main/scala/uvm/refimpl/itpr/InterpreterThread.scala
View file @
87c9ebdc
...
...
@@ -176,9 +176,9 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
try
{
opndTy
match
{
case
TypeVector
(
scalarTy
,
sz
)
=>
{
val
op1Bs
=
boxOf
(
op1
).
asInstanceOf
[
Box
Vector
].
values
val
op2Bs
=
boxOf
(
op2
).
asInstanceOf
[
Box
Vector
].
values
val
rBs
=
boxOf
(
i
).
asInstanceOf
[
Box
Vector
].
values
val
op1Bs
=
boxOf
(
op1
).
asInstanceOf
[
Box
Seq
].
values
val
op2Bs
=
boxOf
(
op2
).
asInstanceOf
[
Box
Seq
].
values
val
rBs
=
boxOf
(
i
).
asInstanceOf
[
Box
Seq
].
values
for
(((
b1
,
b2
),
br
)
<-
((
op1Bs
zip
op2Bs
)
zip
rBs
))
{
doScalar
(
scalarTy
,
b1
,
b2
,
br
)
...
...
@@ -285,9 +285,9 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
opndTy
match
{
case
TypeVector
(
scalarTy
,
sz
)
=>
{
val
op1Bs
=
boxOf
(
op1
).
asInstanceOf
[
Box
Vector
].
values
val
op2Bs
=
boxOf
(
op2
).
asInstanceOf
[
Box
Vector
].
values
val
rBs
=
boxOf
(
i
).
asInstanceOf
[
Box
Vector
].
values
val
op1Bs
=
boxOf
(
op1
).
asInstanceOf
[
Box
Seq
].
values
val
op2Bs
=
boxOf
(
op2
).
asInstanceOf
[
Box
Seq
].
values
val
rBs
=
boxOf
(
i
).
asInstanceOf
[
Box
Seq
].
values
for
(((
b1
,
b2
),
br
)
<-
((
op1Bs
zip
op2Bs
)
zip
rBs
))
{
doScalar
(
scalarTy
,
b1
,
b2
,
br
)
...
...
@@ -420,8 +420,8 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
case
(
TypeVector
(
scalarFromTy
,
sz
),
TypeVector
(
scalarToTy
,
sz2
))
=>
{
if
(
sz
!=
sz2
)
throw
new
UvmRefImplException
(
ctx
+
"The source and dest vector types must have the same length"
)
val
bOpnds
=
boxOf
(
opnd
).
asInstanceOf
[
Box
Vector
].
values
val
rBs
=
boxOf
(
i
).
asInstanceOf
[
Box
Vector
].
values
val
bOpnds
=
boxOf
(
opnd
).
asInstanceOf
[
Box
Seq
].
values
val
rBs
=
boxOf
(
i
).
asInstanceOf
[
Box
Seq
].
values
for
((
bOpnd
,
br
)
<-
(
bOpnds
zip
rBs
))
{
doScalar
(
scalarFromTy
,
scalarToTy
,
bOpnd
,
br
)
...
...
@@ -446,10 +446,10 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
condTy
match
{
case
TypeVector
(
TypeInt
(
1
),
sz
)
=>
{
val
bConds
=
boxOf
(
cond
).
asInstanceOf
[
Box
Vector
].
values
val
bTrues
=
boxOf
(
ifTrue
).
asInstanceOf
[
Box
Vector
].
values
val
bFalses
=
boxOf
(
ifFalse
).
asInstanceOf
[
Box
Vector
].
values
val
bResults
=
boxOf
(
i
).
asInstanceOf
[
Box
Vector
].
values
val
bConds
=
boxOf
(
cond
).
asInstanceOf
[
Box
Seq
].
values
val
bTrues
=
boxOf
(
ifTrue
).
asInstanceOf
[
Box
Seq
].
values
val
bFalses
=
boxOf
(
ifFalse
).
asInstanceOf
[
Box
Seq
].
values
val
bResults
=
boxOf
(
i
).
asInstanceOf
[
Box
Seq
].
values
for
((((
bCond
,
bTrue
),
bFalse
),
br
)
<-
bConds
.
zip
(
bTrues
).
zip
(
bFalses
).
zip
(
bResults
))
{
doScalar
(
bCond
,
bTrue
,
bFalse
,
br
)
...
...
@@ -560,7 +560,7 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
}
case
i
@
InstExtractElement
(
vecTy
,
indTy
,
opnd
,
index
)
=>
{
val
ob
=
boxOf
(
opnd
).
asInstanceOf
[
Box
Vector
]
val
ob
=
boxOf
(
opnd
).
asInstanceOf
[
Box
Seq
]
val
indb
=
boxOf
(
index
).
asInstanceOf
[
BoxInt
]
val
ind
=
OpHelper
.
prepareUnsigned
(
indb
.
value
,
indTy
.
length
)
...
...
@@ -575,7 +575,7 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
}
case
i
@
InstInsertElement
(
vecTy
,
indTy
,
opnd
,
index
,
newVal
)
=>
{
val
ob
=
boxOf
(
opnd
).
asInstanceOf
[
Box
Vector
]
val
ob
=
boxOf
(
opnd
).
asInstanceOf
[
Box
Seq
]
val
indb
=
boxOf
(
index
).
asInstanceOf
[
BoxInt
]
val
ind
=
OpHelper
.
prepareUnsigned
(
indb
.
value
,
indTy
.
length
)
...
...
@@ -587,7 +587,7 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
val
indInt
=
ind
.
intValue
val
nvb
=
boxOf
(
newVal
)
val
ib
=
boxOf
(
i
).
asInstanceOf
[
Box
Vector
]
val
ib
=
boxOf
(
i
).
asInstanceOf
[
Box
Seq
]
for
(((
oeb
,
ieb
),
ind2
)
<-
(
ob
.
values
zip
ib
.
values
).
zipWithIndex
)
{
if
(
ind2
==
indInt
)
{
...
...
@@ -602,10 +602,10 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
case
i
@
InstShuffleVector
(
vecTy
,
maskTy
,
vec1
,
vec2
,
mask
)
=>
{
val
vecLen
=
vecTy
.
len
.
toInt
val
maskIntLen
=
maskTy
.
elemTy
.
asInstanceOf
[
TypeInt
].
length
val
vb1
=
boxOf
(
vec1
).
asInstanceOf
[
Box
Vector
]
val
vb2
=
boxOf
(
vec2
).
asInstanceOf
[
Box
Vector
]
val
mb
=
boxOf
(
mask
).
asInstanceOf
[
Box
Vector
]
val
ib
=
boxOf
(
i
).
asInstanceOf
[
Box
Vector
]
val
vb1
=
boxOf
(
vec1
).
asInstanceOf
[
Box
Seq
]
val
vb2
=
boxOf
(
vec2
).
asInstanceOf
[
Box
Seq
]
val
mb
=
boxOf
(
mask
).
asInstanceOf
[
Box
Seq
]
val
ib
=
boxOf
(
i
).
asInstanceOf
[
Box
Seq
]
for
(((
meb
,
ieb
),
ind
)
<-
(
mb
.
values
zip
ib
.
values
).
zipWithIndex
)
{
val
me
=
OpHelper
.
prepareUnsigned
(
meb
.
asInstanceOf
[
BoxInt
].
value
,
maskIntLen
)
...
...
@@ -1168,7 +1168,11 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
val
norArgs
=
destClause
.
args
// Copy to edge-assigned boxes, first.
assert
(
norArgs
.
length
==
dest
.
norParams
.
length
)
if
(
norArgs
.
length
!=
dest
.
norParams
.
length
)
{
throw
new
UvmRefImplException
(
ctx
+
"Wrong number of arguments. Basic block: %s, expected: %d, actual: %d"
.
format
(
dest
.
repr
,
dest
.
norParams
.
length
,
norArgs
.
length
))
}
for
((
arg
,
np
)
<-
norArgs
zip
dest
.
norParams
)
{
val
argBox
=
boxOf
(
arg
)
val
npEdgeBox
=
edgeAssignedBoxOf
(
np
)
...
...
src/main/scala/uvm/refimpl/itpr/boxes.scala
View file @
87c9ebdc
...
...
@@ -31,8 +31,8 @@ case class BoxFloat(var value: Float) extends ValueBox {
case
class
BoxDouble
(
var
value
:
Double
)
extends
ValueBox
{
def
copyFrom
(
other
:
ValueBox
)
:
Unit
=
{
this
.
value
=
other
.
asInstanceOf
[
BoxDouble
].
value
}
}
case
class
Box
Vector
(
var
values
:
Seq
[
ValueBox
])
extends
ValueBox
{
def
copyFrom
(
other
:
ValueBox
)
:
Unit
=
{
for
((
t
,
o
)
<-
this
.
values
.
zip
(
other
.
asInstanceOf
[
Box
Vector
].
values
))
t
.
copyFrom
(
o
)
}
case
class
Box
Seq
(
var
values
:
Seq
[
ValueBox
])
extends
ValueBox
{
def
copyFrom
(
other
:
ValueBox
)
:
Unit
=
{
for
((
t
,
o
)
<-
this
.
values
.
zip
(
other
.
asInstanceOf
[
Box
Seq
].
values
))
t
.
copyFrom
(
o
)
}
}
case
class
BoxRef
(
var
objRef
:
Word
)
extends
HasObjRef
{
def
copyFrom
(
other
:
ValueBox
)
:
Unit
=
{
this
.
objRef
=
other
.
asInstanceOf
[
BoxRef
].
objRef
}
...
...
@@ -93,12 +93,12 @@ object ValueBox {
case
_:
TypeInt
=>
BoxInt
(
0
)
case
_:
TypeFloat
=>
BoxFloat
(
0.0f
)
case
_:
TypeDouble
=>
BoxDouble
(
0.0d
)
case
TypeVector
(
elemTy
,
len
)
=>
Box
Vector
(
Seq
.
fill
(
len
.
toInt
)(
makeBoxForType
(
elemTy
)))
case
TypeVector
(
elemTy
,
len
)
=>
Box
Seq
(
Seq
.
fill
(
len
.
toInt
)(
makeBoxForType
(
elemTy
)))
case
_:
TypeRef
=>
BoxRef
(
0L
)
case
_:
TypeIRef
=>
BoxIRef
(
0L
,
0L
)
case
_:
TypeWeakRef
=>
throw
new
UvmRefImplException
(
"weakref cannot be an SSA variable type"
)
case
TypeStruct
(
fieldTys
)
=>
BoxStruct
(
fieldTys
.
map
(
makeBoxForType
))
case
_:
TypeArray
=>
throw
new
UvmRefImplException
(
"array cannot be an SSA variable type"
)
case
TypeArray
(
elemTy
,
len
)
=>
BoxSeq
(
Seq
.
fill
(
len
.
toInt
)(
makeBoxForType
(
elemTy
))
)
case
_:
TypeHybrid
=>
throw
new
UvmRefImplException
(
"hybrid cannot be an SSA variable type"
)
case
_:
TypeVoid
=>
BoxVoid
()
case
_:
TypeFuncRef
=>
BoxFunc
(
None
)
...
...
src/main/scala/uvm/refimpl/itpr/operationHelpers.scala
View file @
87c9ebdc
...
...
@@ -352,7 +352,7 @@ object MemoryOperations {
ty
match
{
case
TypeVector
(
ety
,
len
)
=>
val
brs
=
br
.
asInstanceOf
[
Box
Vector
].
values
val
brs
=
br
.
asInstanceOf
[
Box
Seq
].
values
val
elemSkip
=
alignUp
(
sizeOf
(
ety
),
alignOf
(
ety
))
for
((
brElem
,
i
)
<-
brs
.
zipWithIndex
)
{
loadScalar
(
ety
,
loc
+
elemSkip
*
i
,
brElem
)
...
...
@@ -411,8 +411,8 @@ object MemoryOperations {
ty
match
{
case
TypeVector
(
ety
,
len
)
=>
val
nvbs
=
nvb
.
asInstanceOf
[
Box
Vector
].
values
val
brs
=
br
.
asInstanceOf
[
Box
Vector
].
values
val
nvbs
=
nvb
.
asInstanceOf
[
Box
Seq
].
values
val
brs
=
br
.
asInstanceOf
[
Box
Seq
].
values
val
elemSkip
=
alignUp
(
sizeOf
(
ety
),
alignOf
(
ety
))
for
(((
brElem
,
nvbElem
),
i
)
<-
(
brs
zip
nvbs
).
zipWithIndex
)
{
storeScalar
(
ety
,
loc
+
elemSkip
*
i
,
nvbElem
,
brElem
)
...
...
src/main/scala/uvm/ssavariables/ssavariables.scala
View file @
87c9ebdc
...
...
@@ -29,11 +29,9 @@ case class ConstDouble(var constTy: Type, var num: Double) extends Constant
case
class
ConstStruct
(
var
constTy
:
Type
,
var
fields
:
Seq
[
GlobalVariable
])
extends
Constant
case
class
ConstArray
(
var
constTy
:
Type
,
var
elems
:
Seq
[
GlobalVariable
])
extends
Constant
case
class
ConstNull
(
var
constTy
:
Type
)
extends
Constant
case
class
Const
Vector
(
var
constTy
:
Type
,
var
elems
:
Seq
[
Constant
])
extends
Constant
case
class
Const
Seq
(
var
constTy
:
Type
,
var
elems
:
Seq
[
GlobalVariable
])
extends
Constant
case
class
ConstPointer
(
var
constTy
:
Type
,
var
addr
:
Long
)
extends
Constant
...
...
src/test/scala/uvm/ir/textinput/TestingBundlesValidators.scala
View file @
87c9ebdc
...
...
@@ -201,7 +201,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
our
const
"@cth"
shouldBeA
[
ConstNull
]
{
_
.
constTy
shouldBe
(
our
ty
"@thread"
)
}
our
const
"@cst"
shouldBeA
[
ConstNull
]
{
_
.
constTy
shouldBe
(
our
ty
"@stack"
)
}
our
const
"@cv4f"
shouldBeA
[
Const
Vector
]
{
its
=>
our
const
"@cv4f"
shouldBeA
[
Const
Seq
]
{
its
=>
its
.
constTy
shouldBe
(
our
ty
"@4xfloat"
)
its
elems
0
shouldBe
(
our
const
"@F_1"
)
its
elems
1
shouldBe
(
our
const
"@F_2"
)
...
...
@@ -209,7 +209,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
its
elems
3
shouldBe
(
our
const
"@F_4"
)
}
our
const
"@cv4i"
shouldBeA
[
Const
Vector
]
{
its
=>
our
const
"@cv4i"
shouldBeA
[
Const
Seq
]
{
its
=>
its
.
constTy
shouldBe
(
our
ty
"@4xi32"
)
its
elems
0
shouldBe
(
our
const
"@I32_1"
)
its
elems
1
shouldBe
(
our
const
"@I32_2"
)
...
...
@@ -217,7 +217,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
its
elems
3
shouldBe
(
our
const
"@I32_4"
)
}
our
const
"@cv4d"
shouldBeA
[
Const
Vector
]
{
its
=>
our
const
"@cv4d"
shouldBeA
[
Const
Seq
]
{
its
=>
its
.
constTy
shouldBe
(
our
ty
"@2xdouble"
)
its
elems
0
shouldBe
(
our
const
"@D_1"
)
its
elems
1
shouldBe
(
our
const
"@D_2"
)
...
...
@@ -243,7 +243,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
its
.
addr
shouldBe
0xfedcba9876543210
L
}
our
const
"@ary1"
shouldBeA
[
Const
Array
]
{
its
=>
our
const
"@ary1"
shouldBeA
[
Const
Seq
]
{
its
=>
its
.
constTy
shouldBe
(
our
ty
"@i32_3_ary"
)
its
elems
0
shouldBe
(
our
const
"@I32_1"
)
its
elems
1
shouldBe
(
our
const
"@I32_2"
)
...
...
src/test/scala/uvm/refimpl/UvmBundleTesterBase.scala
View file @
87c9ebdc
...
...
@@ -86,7 +86,8 @@ abstract class UvmBundleTesterBase extends FlatSpec with Matchers {
def
asStack
:
Option
[
InterpreterStack
]
=
vb
.
asInstanceOf
[
BoxStack
].
stack
def
asTR64Box
:
BoxTagRef64
=
vb
.
asInstanceOf
[
BoxTagRef64
]
def
asTR64Raw
:
Long
=
vb
.
asInstanceOf
[
BoxTagRef64
].
raw
def
asVec
:
Seq
[
ValueBox
]
=
vb
.
asInstanceOf
[
BoxVector
].
values
def
asSeq
:
Seq
[
ValueBox
]
=
vb
.
asInstanceOf
[
BoxSeq
].
values
def
asVec
:
Seq
[
ValueBox
]
=
vb
.
asInstanceOf
[
BoxSeq
].
values
def
asPointer
:
Word
=
vb
.
asInstanceOf
[
BoxPointer
].
addr
}
}
\ No newline at end of file
src/test/scala/uvm/refimpl/itpr/UvmInterpreterSpec.scala
View file @
87c9ebdc
This diff is collapsed.
Click to expand it.
src/test/scala/uvm/refimpl/mem/UvmMemLayoutSpec.scala
View file @
87c9ebdc
...
...
@@ -19,9 +19,9 @@ class UvmMemLayoutSpec extends FlatSpec with Matchers with BeforeAndAfter {
sizeOf
(
TypeIRef
(
TypeVoid
()))
shouldBe
16
sizeOf
(
TypeWeakRef
(
TypeVoid
()))
shouldBe
8
sizeOf
(
TypeVoid
())
shouldBe
0
sizeOf
(
TypeFunc
(
FuncSig
(
TypeVoid
(),
Seq
())))
shouldBe
8
sizeOf
(
TypeThread
())
shouldBe
8
sizeOf
(
TypeStack
())
shouldBe
8
sizeOf
(
TypeFunc
Ref
(
FuncSig
(
TypeVoid
(),
Seq
())))
shouldBe
8
sizeOf
(
TypeThread
Ref
())
shouldBe
8
sizeOf
(
TypeStack
Ref
())
shouldBe
8
sizeOf
(
TypeTagRef64
())
shouldBe
8
}
...
...
@@ -36,9 +36,9 @@ class UvmMemLayoutSpec extends FlatSpec with Matchers with BeforeAndAfter {
alignOf
(
TypeIRef
(
TypeVoid
()))
shouldBe
16
alignOf
(
TypeWeakRef
(
TypeVoid
()))
shouldBe
8
alignOf
(
TypeVoid
())
shouldBe
1
alignOf
(
TypeFunc
(
FuncSig
(
TypeVoid
(),
Seq
())))
shouldBe
8
alignOf
(
TypeThread
())
shouldBe
8
alignOf
(
TypeStack
())
shouldBe
8
alignOf
(
TypeFunc
Ref
(
FuncSig
(
TypeVoid
(),
Seq
())))
shouldBe
8
alignOf
(
TypeThread
Ref
())
shouldBe
8
alignOf
(
TypeStack
Ref
())
shouldBe
8
alignOf
(
TypeTagRef64
())
shouldBe
8
}
...
...
src/test/scala/uvm/refimpl/nat/NativeStackKeeperTest.scala
View file @
87c9ebdc
...
...
@@ -2,22 +2,22 @@ package uvm.refimpl.nat
import
org.scalatest.FlatSpec
import
org.scalatest.Matchers
import
com.kenai.jffi.CallingConvention
import
com.kenai.jffi.Closure
import
com.kenai.jffi.Closure.Buffer
import
com.kenai.jffi.ClosureManager
import
com.kenai.jffi.
{
Type
=>
JType
}
import
uvm.
{
Function
=>
MFunc
}
import
uvm.FuncSig
import
uvm.
{
Function
=>
MFunc
}
import
uvm.ir.textinput.ExtraMatchers
import
uvm.refimpl.itpr.BoxDouble
import
uvm.refimpl.itpr.BoxInt
import
uvm.refimpl.itpr.BoxPointer
import
uvm.types.TypeDouble
import
uvm.types.TypeFuncPtr
import
uvm.types.TypeInt
import
uvm.refimpl.MicroVM
import
uvm.ir.textinput.ExtraMatchers
import
uvm.refimpl.itpr.BoxDouble
import
uvm.types.TypeUFuncPtr
class
NativeStackKeeperTest
extends
FlatSpec
with
Matchers
with
ExtraMatchers
{
behavior
of
"NativeStackKeeper"
...
...
@@ -75,7 +75,7 @@ class NativeStackKeeperTest extends FlatSpec with Matchers with ExtraMatchers {
val
d
=
TypeDouble
()
val
dtdSig
=
FuncSig
(
d
,
Seq
(
d
))
val
dtd
=
TypeFuncPtr
(
dtdSig
)
val
dtd
=
Type
U
FuncPtr
(
dtdSig
)
val
sig
=
FuncSig
(
d
,
Seq
(
d
,
dtd
))
val
mockMuCallbackFunc
=
new
MFunc
()
...
...
@@ -139,7 +139,7 @@ class NativeStackKeeperTest extends FlatSpec with Matchers with ExtraMatchers {
val
d
=
TypeDouble
()
val
dtdSig
=
FuncSig
(
d
,
Seq
(
d
))
val
dtd
=
TypeFuncPtr
(
dtdSig
)
val
dtd
=
Type
U
FuncPtr
(
dtdSig
)
val
sig
=
FuncSig
(
d
,
Seq
(
d
,
dtd
))
val
clos
=
new
Closure
()
{
...
...
tests/uvm-refimpl-test/basic-tests.uir
View file @
87c9ebdc
This diff is collapsed.
Click to expand it.
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