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
c6cc359c
There was an error fetching the commit references. Please try again later.
Verified
Commit
c6cc359c
authored
6 years ago
by
Recolic Keghart
Browse files
Options
Downloads
Patches
Plain Diff
Assign Stmt
parent
75570697
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
src/main/java/chocopy/pa3/CodeGenImpl.java
+47
-6
47 additions, 6 deletions
src/main/java/chocopy/pa3/CodeGenImpl.java
with
49 additions
and
6 deletions
.gitignore
+
2
−
0
View file @
c6cc359c
...
@@ -147,3 +147,5 @@ tramp
...
@@ -147,3 +147,5 @@ tramp
Session.vim
Session.vim
.netrwhist
.netrwhist
*~
*~
*.gi
This diff is collapsed.
Click to expand it.
src/main/java/chocopy/pa3/CodeGenImpl.java
+
47
−
6
View file @
c6cc359c
...
@@ -9,6 +9,7 @@ import java.util.Stack;
...
@@ -9,6 +9,7 @@ import java.util.Stack;
import
chocopy.common.analysis.SymbolTable
;
import
chocopy.common.analysis.SymbolTable
;
import
chocopy.common.analysis.AbstractNodeAnalyzer
;
import
chocopy.common.analysis.AbstractNodeAnalyzer
;
import
chocopy.common.analysis.types.SymbolType
;
import
chocopy.common.analysis.types.SymbolType
;
import
chocopy.common.analysis.types.ValueType
;
import
chocopy.common.astnodes.*
;
import
chocopy.common.astnodes.*
;
import
chocopy.common.codegen.*
;
import
chocopy.common.codegen.*
;
...
@@ -220,7 +221,7 @@ public class CodeGenImpl extends CodeGenBase {
...
@@ -220,7 +221,7 @@ public class CodeGenImpl extends CodeGenBase {
}
}
/** An analyzer that encapsulates code generation for statments. */
/** An analyzer that encapsulates code generation for statments. */
private
class
StmtAnalyzer
extends
AbstractNodeAnalyzer
<
Object
>
{
private
class
StmtAnalyzer
extends
AbstractNodeAnalyzer
<
Void
>
{
/*
/*
* The symbol table has all the info you need to determine
* The symbol table has all the info you need to determine
* what a given identifier 'x' in the current scope is. You can
* what a given identifier 'x' in the current scope is. You can
...
@@ -302,7 +303,6 @@ public class CodeGenImpl extends CodeGenBase {
...
@@ -302,7 +303,6 @@ public class CodeGenImpl extends CodeGenBase {
stmt
.
value
.
dispatch
(
this
);
stmt
.
value
.
dispatch
(
this
);
backend
.
emitLW
(
A0
,
SP
,
0
,
"Load return value into A0"
);
backend
.
emitLW
(
A0
,
SP
,
0
,
"Load return value into A0"
);
return
null
;
return
null
;
}
}
@Override
@Override
...
@@ -311,6 +311,51 @@ public class CodeGenImpl extends CodeGenBase {
...
@@ -311,6 +311,51 @@ public class CodeGenImpl extends CodeGenBase {
return
null
;
return
null
;
}
}
@Override
public
Void
analyze
(
AssignStmt
node
)
{
node
.
value
.
dispatch
(
this
);
RiscVBackend
.
Register
tmpReg
=
/*regMgr.borrowOneTmp()*/
T6
;
RiscVBackend
.
Register
tmpReg2
=
/*regMgr.borrowOneTmp()*/
T5
;
betterBackend
.
emitPop
(
tmpReg
,
"ASSIGN: Get the value to assign: Pop the expr result from stack"
);
SymbolType
symbolType
=
null
;
for
(
Expr
expr
:
node
.
targets
)
{
if
(!
(
expr
instanceof
Identifier
))
{
throw
new
RuntimeException
(
"assignment target should be Identifier."
);
}
SymbolInfo
symbolInfo
=
sym
.
get
(((
Identifier
)
expr
).
name
);
Label
label
=
null
;
if
(
symbolType
==
null
)
{
// first run:
if
(
symbolInfo
instanceof
GlobalVarInfo
)
{
GlobalVarInfo
globalVarInfo
=
(
GlobalVarInfo
)
symbolInfo
;
symbolType
=
globalVarInfo
.
getVarType
();
}
else
if
(
symbolInfo
instanceof
StackVarInfo
)
{
StackVarInfo
stackVarInfo
=
(
StackVarInfo
)
symbolInfo
;
symbolType
=
stackVarInfo
.
getVarType
();
}
if
(
symbolType
.
equals
(
SymbolType
.
INT_TYPE
)
||
symbolType
.
equals
(
SymbolType
.
BOOL_TYPE
))
{
// first run:
/*
backend.emitLW(tmpReg, tmpReg, 3 * backend.getWordSize(), "ASSIGN: Load the value of INT or BOOL");
*/
}
}
// do assign
if
(
symbolInfo
instanceof
GlobalVarInfo
)
{
GlobalVarInfo
globalVarInfo
=
(
GlobalVarInfo
)
symbolInfo
;
symbolType
=
globalVarInfo
.
getVarType
();
backend
.
emitSW
(
tmpReg
,
globalVarInfo
.
getLabel
(),
tmpReg2
,
"ASSIGN: Assign to global var"
);
}
else
if
(
symbolInfo
instanceof
StackVarInfo
)
{
StackVarInfo
stackVarInfo
=
(
StackVarInfo
)
symbolInfo
;
symbolType
=
stackVarInfo
.
getVarType
();
throw
new
RuntimeException
(
"ASSIGN to stack variable: NOT IMPLEMENTED: StackVarInfo not implemented."
);
}
}
return
null
;
}
@Override
@Override
public
Void
analyze
(
CallExpr
callExpr
)
{
public
Void
analyze
(
CallExpr
callExpr
)
{
...
@@ -485,10 +530,6 @@ public class CodeGenImpl extends CodeGenBase {
...
@@ -485,10 +530,6 @@ public class CodeGenImpl extends CodeGenBase {
}
}
@Override
public
Void
analyze
(
AssignStmt
assignStmt
)
{
return
null
;
}
// FIXME: More, of course.
// FIXME: More, of course.
}
}
...
...
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