Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs164_lab3_cg
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
recolic-hust
cs164_lab3_cg
Commits
d2cc5093
There was an error fetching the commit references. Please try again later.
Verified
Commit
d2cc5093
authored
6 years ago
by
Recolic Keghart
Browse files
Options
Downloads
Patches
Plain Diff
[DO NOT BUILD] working on push/pop
parent
69f303d4
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
src/main/java/chocopy/pa3/CodeGenImpl.java
+3
-6
3 additions, 6 deletions
src/main/java/chocopy/pa3/CodeGenImpl.java
with
3 additions
and
6 deletions
src/main/java/chocopy/pa3/CodeGenImpl.java
+
3
−
6
View file @
d2cc5093
...
@@ -299,7 +299,6 @@ public class CodeGenImpl extends CodeGenBase {
...
@@ -299,7 +299,6 @@ public class CodeGenImpl extends CodeGenBase {
@Override
@Override
public
Void
analyze
(
AssignStmt
node
)
{
public
Void
analyze
(
AssignStmt
node
)
{
backend
.
emitADDI
(
SP
,
SP
,
-
4
,
"Increment stack ptr by 1 for Condition"
);
node
.
value
.
dispatch
(
this
);
node
.
value
.
dispatch
(
this
);
RiscVBackend
.
Register
tmpReg
=
/*regMgr.borrowOneTmp()*/
T6
;
RiscVBackend
.
Register
tmpReg
=
/*regMgr.borrowOneTmp()*/
T6
;
RiscVBackend
.
Register
tmpReg2
=
/*regMgr.borrowOneTmp()*/
T5
;
RiscVBackend
.
Register
tmpReg2
=
/*regMgr.borrowOneTmp()*/
T5
;
...
@@ -358,7 +357,6 @@ public class CodeGenImpl extends CodeGenBase {
...
@@ -358,7 +357,6 @@ public class CodeGenImpl extends CodeGenBase {
@Override
@Override
public
Void
analyze
(
IfStmt
node
)
{
public
Void
analyze
(
IfStmt
node
)
{
backend
.
emitADDI
(
SP
,
SP
,
-
4
,
"Increment stack ptr by 1 for Condition"
);
node
.
condition
.
dispatch
(
this
);
node
.
condition
.
dispatch
(
this
);
RiscVBackend
.
Register
tmpReg
=
/*regMgr.borrowTmp()*/
T6
;
RiscVBackend
.
Register
tmpReg
=
/*regMgr.borrowTmp()*/
T6
;
betterBackend
.
emitPop
(
tmpReg
,
"IfStmt: Get condition"
);
betterBackend
.
emitPop
(
tmpReg
,
"IfStmt: Get condition"
);
...
@@ -389,7 +387,6 @@ public class CodeGenImpl extends CodeGenBase {
...
@@ -389,7 +387,6 @@ public class CodeGenImpl extends CodeGenBase {
Label
exitLabel
=
new
Label
(
labelPrefix
+
".exit"
);
Label
exitLabel
=
new
Label
(
labelPrefix
+
".exit"
);
backend
.
emitLocalLabel
(
beginLabel
,
"WhileStmt: Begin"
);
backend
.
emitLocalLabel
(
beginLabel
,
"WhileStmt: Begin"
);
backend
.
emitADDI
(
SP
,
SP
,
-
4
,
"Increment stack ptr by 1 for Condition"
);
node
.
condition
.
dispatch
(
this
);
node
.
condition
.
dispatch
(
this
);
RiscVBackend
.
Register
tmpReg
=
/*borrowOneTmp*/
T6
;
RiscVBackend
.
Register
tmpReg
=
/*borrowOneTmp*/
T6
;
betterBackend
.
emitPop
(
tmpReg
,
"GetCondition"
);
betterBackend
.
emitPop
(
tmpReg
,
"GetCondition"
);
...
@@ -472,20 +469,20 @@ public class CodeGenImpl extends CodeGenBase {
...
@@ -472,20 +469,20 @@ public class CodeGenImpl extends CodeGenBase {
SymbolInfo
ident
=
sym
.
get
(
id
.
name
);
SymbolInfo
ident
=
sym
.
get
(
id
.
name
);
if
(
ident
instanceof
GlobalVarInfo
)
{
// global var case
if
(
ident
instanceof
GlobalVarInfo
)
{
// global var case
backend
.
emitLW
(
A0
,
((
GlobalVarInfo
)
ident
).
getLabel
(),
"Load identifier"
);
backend
.
emitLW
(
A0
,
((
GlobalVarInfo
)
ident
).
getLabel
(),
"Load identifier"
);
backend
.
emit
SW
(
A0
,
SP
,
0
,
"Push to stack
"
);
b
etterB
ackend
.
emit
Push
(
A0
,
"Ident: GlobalVar
"
);
}
else
if
(
ident
instanceof
StackVarInfo
){
// local variable
}
else
if
(
ident
instanceof
StackVarInfo
){
// local variable
StackVarInfo
identVar
=
(
StackVarInfo
)
ident
;
StackVarInfo
identVar
=
(
StackVarInfo
)
ident
;
if
(
funcArgsMap
.
containsKey
(
identVar
.
getVarName
()))
{
if
(
funcArgsMap
.
containsKey
(
identVar
.
getVarName
()))
{
// is a function arg.
// is a function arg.
backend
.
emitLW
(
T6
,
FP
,
funcArgsMap
.
get
(
identVar
.
getVarName
()),
"Idnet:get FuncArg identifier value to reg"
);
backend
.
emitLW
(
T6
,
FP
,
funcArgsMap
.
get
(
identVar
.
getVarName
()),
"Idnet:get FuncArg identifier value to reg"
);
backend
.
emit
SW
(
T6
,
SP
,
0
,
"Push to stack without decrease SP
"
);
b
etterB
ackend
.
emit
Push
(
T6
,
"Ident: Arg
"
);
return
null
;
// DO NOT RUN THE FUCKING SILLY CODE BELOW
return
null
;
// DO NOT RUN THE FUCKING SILLY CODE BELOW
}
}
// TODO: Function arg works, but local var won't work.
// TODO: Function arg works, but local var won't work.
if
(
id
.
getInferredType
().
equals
(
SymbolType
.
INT_TYPE
))
{
if
(
id
.
getInferredType
().
equals
(
SymbolType
.
INT_TYPE
))
{
IntegerLiteral
value
=
(
IntegerLiteral
)
(
identVar
.
getInitialValue
());
IntegerLiteral
value
=
(
IntegerLiteral
)
(
identVar
.
getInitialValue
());
backend
.
emitLI
(
A0
,
value
.
value
,
"Load initial value of StackVar"
);
backend
.
emitLI
(
A0
,
value
.
value
,
"Load initial value of StackVar"
);
backend
.
emit
SW
(
A0
,
SP
,
0
,
"Push to stack
"
);
b
etterB
ackend
.
emit
Push
(
A0
,
"Ident: LocalVar
"
);
}
}
}
}
return
null
;
return
null
;
...
...
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