Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs444
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xun Yang
cs444
Commits
e3df80b0
Commit
e3df80b0
authored
5 years ago
by
Xun Yang
Browse files
Options
Downloads
Patches
Plain Diff
fix iffalse, not, static param offset"
parent
3029eb23
No related branches found
Branches containing commit
No related tags found
1 merge request
!20
Master
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CodeGenUtils.py
+1
-2
1 addition, 2 deletions
CodeGenUtils.py
ExprPrimaryNodes.py
+16
-13
16 additions, 13 deletions
ExprPrimaryNodes.py
MemberNodes.py
+7
-2
7 additions, 2 deletions
MemberNodes.py
with
24 additions
and
17 deletions
CodeGenUtils.py
+
1
−
2
View file @
e3df80b0
...
@@ -113,7 +113,6 @@ def iffalse(cond, label):
...
@@ -113,7 +113,6 @@ def iffalse(cond, label):
# else val == Int shouldn't happen here, since we already done typeCheck
# else val == Int shouldn't happen here, since we already done typeCheck
else
:
else
:
result
=
cond
.
getIfFalse
(
label
)
result
=
cond
.
getIfFalse
(
label
)
result
+=
p
(
"
jz
"
,
label
)
# jz: jump if 0
return
result
return
result
...
@@ -138,7 +137,7 @@ def genericHelperFunctions():
...
@@ -138,7 +137,7 @@ def genericHelperFunctions():
p
(
instruction
=
"
cmp
"
,
arg1
=
"
eax
"
,
arg2
=
"
[G__Zero]
"
)
+
\
p
(
instruction
=
"
cmp
"
,
arg1
=
"
eax
"
,
arg2
=
"
[G__Zero]
"
)
+
\
p
(
instruction
=
"
jle
"
,
arg1
=
"
H__Throw_Exception
"
)
+
\
p
(
instruction
=
"
jle
"
,
arg1
=
"
H__Throw_Exception
"
)
+
\
p
(
instruction
=
"
ret
"
,
arg1
=
""
)
p
(
instruction
=
"
ret
"
,
arg1
=
""
)
# Helper function to perform bounds check on array
# Helper function to perform bounds check on array
# eax = pointer to array
# eax = pointer to array
# ecx = index i
# ecx = index i
...
...
This diff is collapsed.
Click to expand it.
ExprPrimaryNodes.py
+
16
−
13
View file @
e3df80b0
...
@@ -173,7 +173,7 @@ class ArrayAccessNode(ASTNode):
...
@@ -173,7 +173,7 @@ class ArrayAccessNode(ASTNode):
result
+=
"
; Evaluating pointer to array
\n
"
+
\
result
+=
"
; Evaluating pointer to array
\n
"
+
\
self
.
array
.
code
+
\
self
.
array
.
code
+
\
p
(
instruction
=
"
push
"
,
arg1
=
"
eax
"
,
comment
=
"
push arrray pointer
"
)
p
(
instruction
=
"
push
"
,
arg1
=
"
eax
"
,
comment
=
"
push arrray pointer
"
)
# 2. Evaluating i
# 2. Evaluating i
if
not
hasattr
(
self
.
index
,
"
code
"
):
if
not
hasattr
(
self
.
index
,
"
code
"
):
self
.
index
.
codeGen
()
self
.
index
.
codeGen
()
...
@@ -184,8 +184,8 @@ class ArrayAccessNode(ASTNode):
...
@@ -184,8 +184,8 @@ class ArrayAccessNode(ASTNode):
# 3. Runtime checks
# 3. Runtime checks
result
+=
p
(
instruction
=
"
pop
"
,
arg1
=
"
eax
"
,
comment
=
"
eax is pointer to array
"
)
+
\
result
+=
p
(
instruction
=
"
pop
"
,
arg1
=
"
eax
"
,
comment
=
"
eax is pointer to array
"
)
+
\
p
(
instruction
=
"
call
"
,
arg1
=
"
H__Null_Check
"
)
+
\
p
(
instruction
=
"
call
"
,
arg1
=
"
H__Null_Check
"
)
+
\
p
(
instruction
=
"
call
"
,
arg1
=
"
H__Bounds_Check
"
)
p
(
instruction
=
"
call
"
,
arg1
=
"
H__Bounds_Check
"
)
# 4. Make eax store the address to the item we're accessing
# 4. Make eax store the address to the item we're accessing
result
+=
p
(
instruction
=
"
add
"
,
arg1
=
"
eax
"
,
arg2
=
8
,
comment
=
"
eax points at a[0]
"
)
+
\
result
+=
p
(
instruction
=
"
add
"
,
arg1
=
"
eax
"
,
arg2
=
8
,
comment
=
"
eax points at a[0]
"
)
+
\
p
(
instruction
=
"
imul
"
,
arg1
=
"
ecx
"
,
arg2
=
4
,
comment
=
"
ecx contains the number of bytes to shift according to i
"
)
+
\
p
(
instruction
=
"
imul
"
,
arg1
=
"
ecx
"
,
arg2
=
4
,
comment
=
"
ecx contains the number of bytes to shift according to i
"
)
+
\
...
@@ -195,7 +195,7 @@ class ArrayAccessNode(ASTNode):
...
@@ -195,7 +195,7 @@ class ArrayAccessNode(ASTNode):
result
+=
"
; End of calculating address for array access
\n
"
result
+=
"
; End of calculating address for array access
\n
"
return
result
return
result
def
codeGen
(
self
):
def
codeGen
(
self
):
if
hasattr
(
self
,
"
code
"
):
if
hasattr
(
self
,
"
code
"
):
return
return
...
@@ -266,14 +266,14 @@ class ArrayCreateNode(ASTNode):
...
@@ -266,14 +266,14 @@ class ArrayCreateNode(ASTNode):
aLabel
+=
self
.
arrayType
.
myType
.
name
aLabel
+=
self
.
arrayType
.
myType
.
name
else
:
else
:
aLabel
+=
self
.
arrayType
.
myType
.
typePointer
.
name
aLabel
+=
self
.
arrayType
.
myType
.
typePointer
.
name
self
.
code
+=
p
(
instruction
=
"
extern
"
,
arg1
=
aLabel
)
+
\
self
.
code
+=
p
(
instruction
=
"
extern
"
,
arg1
=
aLabel
)
+
\
p
(
instruction
=
"
mov
"
,
arg1
=
"
[eax]
"
,
arg2
=
"
dword
"
+
aLabel
,
comment
=
"
first item is vtable pointer
"
)
p
(
instruction
=
"
mov
"
,
arg1
=
"
[eax]
"
,
arg2
=
"
dword
"
+
aLabel
,
comment
=
"
first item is vtable pointer
"
)
# 3. Storing length in the second slot
# 3. Storing length in the second slot
self
.
code
+=
p
(
instruction
=
"
mov
"
,
arg1
=
"
[eax+4]
"
,
arg2
=
"
ecx
"
,
comment
=
"
storing array length in second slot
"
)
self
.
code
+=
p
(
instruction
=
"
mov
"
,
arg1
=
"
[eax+4]
"
,
arg2
=
"
ecx
"
,
comment
=
"
storing array length in second slot
"
)
# 4. Restoring ecx
# 4. Restoring ecx
self
.
code
+=
p
(
instruction
=
"
pop
"
,
arg1
=
"
ecx
"
,
comment
=
"
restoring register ecx
"
)
self
.
code
+=
p
(
instruction
=
"
pop
"
,
arg1
=
"
ecx
"
,
comment
=
"
restoring register ecx
"
)
self
.
code
+=
"
;End of array creation
\n
"
self
.
code
+=
"
;End of array creation
\n
"
...
@@ -605,7 +605,14 @@ class ExprNode(ASTNode):
...
@@ -605,7 +605,14 @@ class ExprNode(ASTNode):
return
return
if
self
.
op
==
'
!
'
:
if
self
.
op
==
'
!
'
:
self
.
code
+=
p
(
'
not
'
,
'
eax
'
)
n
=
getCFlowLabel
()
endLabel
=
"
_end
"
+
n
self
.
code
+=
p
(
"
cmp
"
,
"
eax
"
,
"
[G__Zero]
"
)
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
1
"
)
self
.
code
+=
p
(
"
je
"
,
endLabel
)
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
0
"
)
self
.
code
+=
p
(
endLabel
+
"
:
"
,
""
)
return
return
# Comparisons that short-circuit:
# Comparisons that short-circuit:
...
@@ -698,13 +705,9 @@ class ExprNode(ASTNode):
...
@@ -698,13 +705,9 @@ class ExprNode(ASTNode):
# generate shorter code if self.op = comparison
# generate shorter code if self.op = comparison
def
getIfFalse
(
self
,
label
):
def
getIfFalse
(
self
,
label
):
if
self
.
op
==
'
&&
'
:
if
self
.
op
not
in
[
'
==
'
,
'
!=
'
,
'
<=
'
,
'
>=
'
,
'
>
'
,
'
<
'
]:
result
=
self
.
left
.
getIfFalse
(
label
)
result
+=
self
.
right
.
getIfFalse
(
label
)
return
result
elif
self
.
op
not
in
[
'
==
'
,
'
!=
'
,
'
<=
'
,
'
>=
'
,
'
>
'
,
'
<
'
]:
self
.
codeGen
()
self
.
codeGen
()
return
self
.
code
return
self
.
code
+
p
(
"
cmp
"
,
"
eax
"
,
"
[G__Zero]
"
)
+
p
(
"
je
"
,
label
)
else
:
else
:
result
=
self
.
codeGenLeftRight
()
result
=
self
.
codeGenLeftRight
()
result
+=
p
(
"
cmp
"
,
"
ebx
"
,
"
eax
"
,
"
left
"
+
self
.
op
+
"
right
"
)
result
+=
p
(
"
cmp
"
,
"
ebx
"
,
"
eax
"
,
"
left
"
+
self
.
op
+
"
right
"
)
...
...
This diff is collapsed.
Click to expand it.
MemberNodes.py
+
7
−
2
View file @
e3df80b0
...
@@ -224,8 +224,13 @@ class MethodNode(ASTNode):
...
@@ -224,8 +224,13 @@ class MethodNode(ASTNode):
self
.
code
=
pLabel
(
self
.
typeName
+
"
_
"
+
self
.
name
+
"
_
"
+
self
.
paramTypes
,
"
method
"
)
self
.
code
=
pLabel
(
self
.
typeName
+
"
_
"
+
self
.
name
+
"
_
"
+
self
.
paramTypes
,
"
method
"
)
# params
# params
for
i
,
param
in
enumerate
(
self
.
params
):
stackoffset
=
12
param
.
offset
=
i
*
4
+
12
# 12 since the stack is now of the order: ebp, eip, o, params
if
'
static
'
in
self
.
mods
:
stackoffset
=
8
# no object as argument for static methods
rparams
=
self
.
params
.
copy
()
rparams
.
reverse
()
for
i
,
param
in
enumerate
(
rparams
):
param
.
offset
=
i
*
4
+
stackoffset
# 12 since the stack is now of the order: ebp, eip, o, params
if
self
.
body
:
if
self
.
body
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment