Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Haley Sapphie Owsianko
ACC-project
Commits
cf388c4a
Commit
cf388c4a
authored
Mar 26, 2021
by
Luca Bataillard
Browse files
sythetic tests pass, examples do not
parent
e160007d
Changes
1
Hide whitespace changes
Inline
Side-by-side
compiler/src/l3/CPSValueRepresenter.scala
View file @
cf388c4a
...
...
@@ -26,6 +26,7 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
case
H
.
If
(
cond
,
args
,
thenC
,
elseC
)
=>
transformIf
(
cond
,
args
,
thenC
,
elseC
)
case
H
.
Halt
(
v
)
=>
L
.
Halt
(
rewrite
(
v
))
case
_
=>
throw
new
Exception
(
"Unimplemented: "
+
tree
.
getClass
.
toString
)
}
...
...
@@ -48,15 +49,18 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
maskAndCheck
(
4
,
0x2
)
case
L3
.
CharP
=>
maskAndCheck
(
3
,
0x6
)
case
L3
.
Eq
=>
L
.
If
(
CPST
.
Eq
,
args
.
map
(
rewrite
),
thenC
,
elseC
)
case
L3
.
IntLe
=>
???
case
L3
.
IntLt
=>
???
case
L3
.
Eq
=>
L
.
If
(
CPST
.
Eq
,
args
.
map
(
rewrite
),
thenC
,
elseC
)
case
L3
.
IntLe
=>
L
.
If
(
CPST
.
Le
,
args
map
rewrite
,
thenC
,
elseC
)
case
L3
.
IntLt
=>
L
.
If
(
CPST
.
Lt
,
args
map
rewrite
,
thenC
,
elseC
)
}
}
private
def
rewriteIndex
(
idx
:
H.Atom
)
:
L.Atom
=
idx
match
{
case
H
.
AtomN
(
n
)
=>
L
.
AtomN
(
n
)
case
H
.
AtomL
(
IntLit
(
i
))
=>
L
.
AtomL
(
i
.
toInt
)
case
_
=>
throw
new
Exception
(
f
"Cannot rewrite atom {idx} which is not Name or Int Literal"
)
}
private
def
getMaskR
(
numBits
:
Int
)
:
Either
[
H.Atom
,
L.Atom
]
=
Right
(
L
.
AtomL
((
1
<<
numBits
)
-
1
))
...
...
@@ -83,12 +87,14 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
}
prim
match
{
case
L3
.
BlockSet
=>
???
case
L3
.
BlockSet
=>
val
block
=
rewrite
(
x
)
val
idx
=
rewriteIndex
(
y
)
val
value
=
rewrite
(
z
)
L
.
LetP
(
n
,
CPS
.
BlockSet
,
Seq
(
block
,
idx
,
value
),
apply
(
body
))
case
L3
.
BlockGet
=>
// In theory, x has to be a name, since there cannot be pointer literals
val
block
=
rewrite
(
x
)
val
idx
=
rewrite
(
y
)
// NOTE: I'm not sure about this. I might have misunderstood something
val
idx
=
rewriteIndex
(
y
)
L
.
LetP
(
n
,
CPS
.
BlockGet
,
Seq
(
block
,
idx
),
apply
(
body
))
case
L3
.
IntAdd
=>
tempLetP
(
CPS
.
Sub
,
Seq
(
Left
(
x
),
lAtomOne
))
{
x1
=>
...
...
@@ -123,7 +129,7 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
case
L3
.
IntShiftRight
=>
tempLetP
(
CPS
.
ShiftRight
,
Seq
(
Left
(
y
),
lAtomOne
))
{
y1
=>
tempLetP
(
CPS
.
ShiftRight
,
Seq
(
Left
(
x
),
Right
(
y1
)))
{
z
=>
L
.
LetP
(
n
,
CPS
.
Add
,
Seq
(
z
,
L
.
AtomL
(
1
)),
apply
(
body
))
L
.
LetP
(
n
,
CPS
.
Or
,
Seq
(
z
,
L
.
AtomL
(
1
)),
apply
(
body
))
}
}
...
...
@@ -139,19 +145,42 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
}
case
L3
.
BlockAlloc
(
tag
)
=>
???
case
L3
.
BlockAlloc
(
tag
)
=>
tempLetP
(
CPS
.
ShiftRight
,
Seq
(
Right
(
rewrite
(
x
)),
lAtomOne
))
{
t1
=>
L
.
LetP
(
n
,
CPS
.
BlockAlloc
(
tag
),
Seq
(
t1
),
apply
(
body
))
}
case
L3
.
BlockTag
=>
// Unsure how I'm doing this, but in theory, addresses can never be
// literals, therefore we can assume x is a name
L
.
LetP
(
n
,
CPS
.
BlockTag
,
Seq
(
rewrite
(
x
)),
apply
(
body
))
case
L3
.
BlockLength
=>
???
case
L3
.
ByteWrite
=>
???
tempLetP
(
CPS
.
BlockTag
,
args
map
(
x
=>
Right
(
rewrite
(
x
))))
{
t1
=>
tempLetP
(
CPS
.
ShiftLeft
,
Seq
(
Right
(
t1
),
lAtomOne
))
{
t2
=>
L
.
LetP
(
n
,
CPS
.
Add
,
Seq
(
t2
,
L
.
AtomL
(
1
)),
apply
(
body
))
}
}
case
L3
.
BlockLength
=>
tempLetP
(
CPS
.
BlockLength
,
args
map
(
x
=>
Left
(
x
)))
{
t1
=>
tempLetP
(
CPS
.
ShiftLeft
,
Seq
(
Right
(
t1
),
Right
(
L
.
AtomL
(
1
))))
{
t2
=>
L
.
LetP
(
n
,
CPS
.
Add
,
Seq
(
t2
,
L
.
AtomL
(
1
)),
apply
(
body
))
}
}
case
L3
.
ByteRead
=>
tempLetP
(
CPS
.
ByteRead
,
Seq
()){
t1
=>
tempLetP
(
CPS
.
ShiftLeft
,
Seq
(
Right
(
t1
),
lAtomOne
))
{
t2
=>
L
.
LetP
(
n
,
CPS
.
Add
,
Seq
(
t2
,
L
.
AtomL
(
2
)),
apply
(
body
))
}
}
case
L3
.
ByteWrite
=>
tempLetP
(
CPS
.
ShiftRight
,
Seq
(
Left
(
x
),
lAtomOne
))
{
t1
=>
L
.
LetP
(
n
,
CPS
.
ByteWrite
,
Seq
(
t1
),
apply
(
body
))
}
case
L3
.
CharToInt
=>
L
.
LetP
(
n
,
CPS
.
ShiftRight
,
Seq
(
rewrite
(
x
),
L
.
AtomL
(
2
)),
apply
(
body
))
case
L3
.
Id
=>
L
.
LetP
(
n
,
CPS
.
Id
,
Seq
(
rewrite
(
x
)),
apply
(
body
))
case
L3
.
IntToChar
=>
???
case
L3
.
IntToChar
=>
tempLetP
(
CPS
.
ShiftLeft
,
Seq
(
Left
(
x
),
Right
(
L
.
AtomL
(
2
)))){
t1
=>
L
.
LetP
(
n
,
CPS
.
Add
,
Seq
(
t1
,
L
.
AtomL
(
2
)),
apply
(
body
))
}
case
_
=>
throw
new
Exception
(
"Unreachable code (unary letP) "
+
prim
.
getClass
)
}
...
...
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