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
e5daa180
Commit
e5daa180
authored
5 years ago
by
pycsham
Browse files
Options
Downloads
Plain Diff
solve git conflicts
parents
acf76f90
50525682
No related branches found
Branches containing commit
No related tags found
2 merge requests
!14
Insta field
,
!13
merge Code gen field
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ExprPrimaryNodes.py
+27
-31
27 additions, 31 deletions
ExprPrimaryNodes.py
with
27 additions
and
31 deletions
ExprPrimaryNodes.py
+
27
−
31
View file @
e5daa180
...
@@ -353,7 +353,7 @@ class ClassCreateNode(ASTNode):
...
@@ -353,7 +353,7 @@ class ClassCreateNode(ASTNode):
def
codeGen
(
self
):
def
codeGen
(
self
):
if
hasattr
(
self
,
"
code
"
):
if
hasattr
(
self
,
"
code
"
):
return
return
self
.
code
=
""
self
.
code
=
""
# 1. Allocating space for the object in heap
# 1. Allocating space for the object in heap
...
@@ -385,7 +385,7 @@ class ClassCreateNode(ASTNode):
...
@@ -385,7 +385,7 @@ class ClassCreateNode(ASTNode):
p
(
instruction
=
"
pop
"
,
arg1
=
"
eax
"
,
comment
=
"
eax now contains pointer to newly created object
"
)
p
(
instruction
=
"
pop
"
,
arg1
=
"
eax
"
,
comment
=
"
eax now contains pointer to newly created object
"
)
self
.
code
+=
"
;End of object creation
\n
"
self
.
code
+=
"
;End of object creation
\n
"
#################################################################################
#################################################################################
# condOrExpr
# condOrExpr
class
ExprNode
(
ASTNode
):
class
ExprNode
(
ASTNode
):
...
@@ -492,7 +492,7 @@ class ExprNode(ASTNode):
...
@@ -492,7 +492,7 @@ class ExprNode(ASTNode):
# ebx = left result
# ebx = left result
# eax = right result
# eax = right result
# so, basically do "eax = ebx op eax"
# so, basically do "eax = ebx op eax"
# Binary operations:
# Binary operations:
# Add, Subtract, Multiply
# Add, Subtract, Multiply
if
self
.
op
in
[
'
+
'
,
'
-
'
,
'
*
'
]:
if
self
.
op
in
[
'
+
'
,
'
-
'
,
'
*
'
]:
...
@@ -681,47 +681,43 @@ class FieldAccessNode(ASTNode):
...
@@ -681,47 +681,43 @@ class FieldAccessNode(ASTNode):
# result stored in eax (address)
# result stored in eax (address)
# NOTE: this is always called by codeGen, so self.code is already intialized to ""
# NOTE: this is always called by codeGen, so self.code is already intialized to ""
def
addr
(
self
):
def
addr
(
self
):
result
=
""
fieldNode
=
self
.
ID
.
prefixLink
fieldNode
=
self
.
ID
.
prefixLink
if
fieldNode
.
__class__
.
__name__
==
"
VarDclNode
"
:
fieldNode
=
self
.
ID
.
staticField
if
"
static
"
in
fieldNode
.
mods
:
if
"
static
"
in
fieldNode
.
mods
:
if
fieldNode
.
__class__
.
__name__
==
"
VarDclNode
"
:
fieldNode
=
self
.
ID
.
staticField
label
=
fieldNode
.
typeName
+
"
_
"
+
fieldNode
.
name
label
=
fieldNode
.
typeName
+
"
_
"
+
fieldNode
.
name
self
.
code
+=
"
; Start of calculating address for static field:
"
+
label
+
"
\n
"
+
\
result
+=
"
; Start of calculating address for static field:
"
+
label
+
"
\n
"
+
\
importHelper
(
fieldNode
.
typeName
,
self
.
typeName
,
"
S_
"
+
label
)
+
\
importHelper
(
fieldNode
.
typeName
,
self
.
typeName
,
"
S_
"
+
label
)
+
\
p
(
instruction
=
"
mov
"
,
arg1
=
"
eax
"
,
arg2
=
"
S_
"
+
label
,
comment
=
"
getting address to static field
"
)
+
\
p
(
instruction
=
"
mov
"
,
arg1
=
"
eax
"
,
arg2
=
"
dword
S_
"
+
label
,
comment
=
"
getting address to static field
"
)
+
\
"
; End of field access
\n
"
"
; End of field access
\n
"
else
:
else
:
self
.
code
+=
"
; Start of calculating address for non-static field
\n
"
result
+=
"
; Start of calculating address for non-static field
\n
"
self
.
primary
.
codeGen
()
self
.
primary
.
codeGen
()
self
.
code
+=
self
.
primary
.
code
result
+=
self
.
primary
.
code
# Null check
# Null check
# At this point, eax stores the address of the object
# At this point, eax stores the address of the object
self
.
code
+=
p
(
instruction
=
"
call
"
,
arg1
=
"
H__Null_Check
"
,
comment
=
"
calling null check function
"
)
result
+=
p
(
instruction
=
"
call
"
,
arg1
=
"
H__Null_Check
"
,
comment
=
"
calling null check function
"
)
# Make eax store the address to the field we're accessing
# Make eax store the address to the field we're accessing
self
.
code
+=
p
(
instruction
=
"
add
"
,
arg1
=
"
eax
"
,
arg2
=
self
.
ID
.
prefixLink
.
offset
,
comment
=
"
calculating pointer to the field
"
)
result
+=
p
(
instruction
=
"
add
"
,
arg1
=
"
eax
"
,
arg2
=
self
.
ID
.
prefixLink
.
offset
,
comment
=
"
calculating pointer to the field
"
)
self
.
code
+=
"
; End of calculating address for non-static field
\n
"
result
+=
"
; End of calculating address for non-static field
\n
"
def
codeGen
(
self
):
if
hasattr
(
self
,
"
code
"
):
return
fieldNode
=
self
.
ID
.
prefixLink
label
=
fieldNode
.
typeName
+
"
_
"
+
fieldNode
.
name
self
.
code
=
"
; Accessing a field :
"
+
label
+
"
\n
"
# Evaluating the address of the field we're trying to access
self
.
addr
()
self
.
code
+=
p
(
instruction
=
"
mov
"
,
arg1
=
"
eax
"
,
arg2
=
"
[eax]
"
)
+
\
"
; End of field access
\n
"
return
result
def
codeGen
(
self
):
if
hasattr
(
self
,
"
code
"
):
return
fieldNode
=
self
.
ID
.
prefixLink
label
=
fieldNode
.
typeName
+
"
_
"
+
fieldNode
.
name
self
.
code
=
"
; Accessing a field :
"
+
label
+
"
\n
"
# Evaluating the address of the field we're trying to access
self
.
code
+=
self
.
addr
()
self
.
code
+=
p
(
instruction
=
"
mov
"
,
arg1
=
"
eax
"
,
arg2
=
"
[eax]
"
)
+
\
"
; End of field access
\n
"
###################################################################################
###################################################################################
...
...
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