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
f43e96ab
Commit
f43e96ab
authored
5 years ago
by
Xun Yang
Browse files
Options
Downloads
Patches
Plain Diff
link to javalang.Object
parent
20d2d2fb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
TypeNodes.py
+22
-17
22 additions, 17 deletions
TypeNodes.py
with
22 additions
and
17 deletions
TypeNodes.py
+
22
−
17
View file @
f43e96ab
...
@@ -165,7 +165,7 @@ class ClassNode(ClassInterNode):
...
@@ -165,7 +165,7 @@ class ClassNode(ClassInterNode):
self
.
label
=
""
# label in assembly
self
.
label
=
""
# label in assembly
self
.
methodOffset
=
{}
# a dictionary that maps method signatures (method.name, method.paramTypes) to offsets in the CLASS memory layout
self
.
methodOffset
=
{}
# a dictionary that maps method signatures (method.name, method.paramTypes) to offsets in the CLASS memory layout
self
.
fieldOffset
=
{}
# a dictionary that maps field names to offsets in OBJECT memory layout
self
.
fieldOffset
=
{}
# a dictionary that maps field names to offsets in OBJECT memory layout
self
.
staticFieldLabels
=
[]
# a list of static field labels
self
.
staticFieldLabels
=
[]
# a list of static field labels
for
node
in
parseTree
.
children
:
for
node
in
parseTree
.
children
:
if
node
.
name
==
'
classMod
'
:
if
node
.
name
==
'
classMod
'
:
...
@@ -257,7 +257,12 @@ class ClassNode(ClassInterNode):
...
@@ -257,7 +257,12 @@ class ClassNode(ClassInterNode):
# overlapping class/interface logic
# overlapping class/interface logic
super
().
checkHierarchy
()
super
().
checkHierarchy
()
# point superClass to java.lang.Object after hierarchy checking is done
if
self
.
canonName
!=
'
java.lang.Object
'
and
not
self
.
superClass
:
self
.
superClass
=
self
.
env
.
getNode
(
'
java.lang.Object
'
,
'
type
'
)
def
checkType
(
self
):
def
checkType
(
self
):
super
().
checkType
()
super
().
checkType
()
...
@@ -278,19 +283,19 @@ class ClassNode(ClassInterNode):
...
@@ -278,19 +283,19 @@ class ClassNode(ClassInterNode):
self
.
label
=
pLabel
(
name
=
self
.
name
,
type
=
"
class
"
)
self
.
label
=
pLabel
(
name
=
self
.
name
,
type
=
"
class
"
)
self
.
code
+=
"
;START OF CLASS MEMORY LAYOUT FOR CLASS:
"
+
self
.
canonName
+
"
\n
"
self
.
code
+=
"
;START OF CLASS MEMORY LAYOUT FOR CLASS:
"
+
self
.
canonName
+
"
\n
"
self
.
code
+=
self
.
label
self
.
code
+=
self
.
label
# TODO: SIT and subtype testing tables
# TODO: SIT and subtype testing tables
####### ADDING METHODS TO CLASS MEMORY LAYOUT AND FIELDS TO FIELD OFFSET TABLE #########
####### ADDING METHODS TO CLASS MEMORY LAYOUT AND FIELDS TO FIELD OFFSET TABLE #########
# 1.
# 1.
# a) Copying over the offsets of methods from superclass and DECLARING memory segment for the methods
# a) Copying over the offsets of methods from superclass and DECLARING memory segment for the methods
# b) copying over the offsets of fields from superclass (TO BE USED LATER FOR OBJECT MEMORY LAYOUT)
# b) copying over the offsets of fields from superclass (TO BE USED LATER FOR OBJECT MEMORY LAYOUT)
lastMethodOffset
=
-
4
# stores the largest method offset in the superCalss
lastMethodOffset
=
-
4
# stores the largest method offset in the superCalss
# TODO: set this to 4 after the implemntation of both the SIT and subtype testing table
# TODO: set this to 4 after the implemntation of both the SIT and subtype testing table
# Note: This is 4 less than the offset of where the next method would be located
# Note: This is 4 less than the offset of where the next method would be located
# This is to accomodate for the addition of 4 to lastMethodOffset in EVERY (including the first) iteration in the
# This is to accomodate for the addition of 4 to lastMethodOffset in EVERY (including the first) iteration in the
# loops that loops through self.constructors and self.methods, in the case where there is no superClass
# loops that loops through self.constructors and self.methods, in the case where there is no superClass
lastFieldOffset
=
0
lastFieldOffset
=
0
if
self
.
superClass
:
if
self
.
superClass
:
if
not
hasattr
(
self
.
superClass
,
"
code
"
):
if
not
hasattr
(
self
.
superClass
,
"
code
"
):
...
@@ -301,20 +306,20 @@ class ClassNode(ClassInterNode):
...
@@ -301,20 +306,20 @@ class ClassNode(ClassInterNode):
self
.
code
+=
pLabel
(
name
=
self
.
name
+
"
_
"
+
key
[
0
]
+
"
_
"
+
key
[
1
],
type
=
"
vtable
"
)
self
.
code
+=
pLabel
(
name
=
self
.
name
+
"
_
"
+
key
[
0
]
+
"
_
"
+
key
[
1
],
type
=
"
vtable
"
)
self
.
code
+=
p
(
instruction
=
"
dd
"
,
arg1
=
64
)
# just declaring a memory segment with a random number
self
.
code
+=
p
(
instruction
=
"
dd
"
,
arg1
=
64
)
# just declaring a memory segment with a random number
lastMethodOffset
=
max
(
value
,
lastMethodOffset
)
lastMethodOffset
=
max
(
value
,
lastMethodOffset
)
# Iterating through field offset table sorted by offset
# Iterating through field offset table sorted by offset
for
key
,
value
in
self
.
superClass
.
fieldOffset
.
items
():
for
key
,
value
in
self
.
superClass
.
fieldOffset
.
items
():
self
.
fieldOffset
[
key
]
=
value
self
.
fieldOffset
[
key
]
=
value
lastFieldOffset
=
max
(
value
,
lastFieldOffset
)
lastFieldOffset
=
max
(
value
,
lastFieldOffset
)
# 2. Assigning offsets to constructors and DECLARING memory segment for the methods
# 2. Assigning offsets to constructors and DECLARING memory segment for the methods
for
method
in
self
.
constructors
:
for
method
in
self
.
constructors
:
lastMethodOffset
+=
4
lastMethodOffset
+=
4
self
.
methodOffset
[(
method
.
name
,
method
.
paramTypes
)]
=
lastMethodOffset
self
.
methodOffset
[(
method
.
name
,
method
.
paramTypes
)]
=
lastMethodOffset
self
.
code
+=
pLabel
(
name
=
self
.
name
+
"
_
"
+
method
.
name
+
"
_
"
+
method
.
paramTypes
,
type
=
"
vtable
"
)
self
.
code
+=
pLabel
(
name
=
self
.
name
+
"
_
"
+
method
.
name
+
"
_
"
+
method
.
paramTypes
,
type
=
"
vtable
"
)
self
.
code
+=
p
(
instruction
=
"
dd
"
,
arg1
=
64
)
# just declaring a memory segment with a random number
self
.
code
+=
p
(
instruction
=
"
dd
"
,
arg1
=
64
)
# just declaring a memory segment with a random number
# 3. Assigning offsets to methods that aren't in the super class DECLARING memory segment for the methods
# 3. Assigning offsets to methods that aren't in the super class DECLARING memory segment for the methods
for
method
in
self
.
methods
:
for
method
in
self
.
methods
:
if
not
(
method
.
name
,
method
.
paramTypes
)
in
self
.
methodOffset
:
if
not
(
method
.
name
,
method
.
paramTypes
)
in
self
.
methodOffset
:
lastMethodOffset
+=
4
lastMethodOffset
+=
4
...
@@ -324,13 +329,13 @@ class ClassNode(ClassInterNode):
...
@@ -324,13 +329,13 @@ class ClassNode(ClassInterNode):
# print(self.methodOffset)
# print(self.methodOffset)
self
.
code
+=
"
;END OF CLASS MEMORY LAYOUT FOR CLASS
"
+
self
.
name
+
"
\n
"
self
.
code
+=
"
;END OF CLASS MEMORY LAYOUT FOR CLASS
"
+
self
.
name
+
"
\n
"
# 4. Fill in the memory segment declared in step 1 and 2 with the addresses of the method implementations
# 4. Fill in the memory segment declared in step 1 and 2 with the addresses of the method implementations
for
key
,
value
in
self
.
methodOffset
.
items
():
for
key
,
value
in
self
.
methodOffset
.
items
():
vLabel
=
"
V_
"
+
self
.
name
+
"
_
"
+
key
[
0
]
+
"
_
"
+
key
[
1
]
+
""
# method at class's vtable
vLabel
=
"
V_
"
+
self
.
name
+
"
_
"
+
key
[
0
]
+
"
_
"
+
key
[
1
]
+
""
# method at class's vtable
mLabel
=
"
M_
"
+
self
.
name
+
"
_
"
+
key
[
0
]
+
"
_
"
+
key
[
1
]
# method implementation
mLabel
=
"
M_
"
+
self
.
name
+
"
_
"
+
key
[
0
]
+
"
_
"
+
key
[
1
]
# method implementation
self
.
code
+=
p
(
instruction
=
"
mov
"
,
arg1
=
"
eax
"
,
arg2
=
vLabel
,
comment
=
"
Filling in class memory segment for method
"
+
mLabel
)
self
.
code
+=
p
(
instruction
=
"
mov
"
,
arg1
=
"
eax
"
,
arg2
=
vLabel
,
comment
=
"
Filling in class memory segment for method
"
+
mLabel
)
self
.
code
+=
p
(
instruction
=
"
mov
"
,
arg1
=
"
[eax]
"
,
arg2
=
mLabel
)
self
.
code
+=
p
(
instruction
=
"
mov
"
,
arg1
=
"
[eax]
"
,
arg2
=
mLabel
)
#5. Adding in fields that are not inherited from parent class to offset table
#5. Adding in fields that are not inherited from parent class to offset table
# Note: excluding static fields
# Note: excluding static fields
for
field
in
self
.
fields
:
for
field
in
self
.
fields
:
...
@@ -339,7 +344,7 @@ class ClassNode(ClassInterNode):
...
@@ -339,7 +344,7 @@ class ClassNode(ClassInterNode):
self
.
fieldOffset
[
field
.
name
]
=
lastFieldOffset
self
.
fieldOffset
[
field
.
name
]
=
lastFieldOffset
# print(self.name)
# print(self.name)
# print(self.fieldOffset)
# print(self.fieldOffset)
# print(self.code)
# print(self.code)
###########################################################
###########################################################
...
@@ -350,7 +355,7 @@ class ClassNode(ClassInterNode):
...
@@ -350,7 +355,7 @@ class ClassNode(ClassInterNode):
if
c
and
hasattr
(
c
,
"
codeGen
"
):
if
c
and
hasattr
(
c
,
"
codeGen
"
):
if
not
hasattr
(
c
,
"
code
"
):
# children hasn't generated code yet
if
not
hasattr
(
c
,
"
code
"
):
# children hasn't generated code yet
c
.
codeGen
()
c
.
codeGen
()
self
.
code
+=
c
.
code
self
.
code
+=
c
.
code
#####################################################################
#####################################################################
...
...
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