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
4135d07a
There was an error fetching the commit references. Please try again later.
Verified
Commit
4135d07a
authored
6 years ago
by
Recolic Keghart
Browse files
Options
Downloads
Patches
Plain Diff
While stmt done. Warning: binary compare not working
parent
432b5aa9
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
WhileStmt.tmpTestCase.py
+12
-0
12 additions, 0 deletions
WhileStmt.tmpTestCase.py
src/main/java/chocopy/pa3/CodeGenImpl.java
+34
-6
34 additions, 6 deletions
src/main/java/chocopy/pa3/CodeGenImpl.java
with
46 additions
and
6 deletions
WhileStmt.tmpTestCase.py
0 → 100644
+
12
−
0
View file @
4135d07a
x
:
bool
=
True
y
:
int
=
5
while
x
:
print
(
123
)
y
=
y
-
1
print
(
y
)
y
=
y
-
1
print
(
y
)
x
=
False
print
(
y
)
print
(
"
Done
"
)
This diff is collapsed.
Click to expand it.
src/main/java/chocopy/pa3/CodeGenImpl.java
+
34
−
6
View file @
4135d07a
...
...
@@ -358,18 +358,23 @@ public class CodeGenImpl extends CodeGenBase {
return
null
;
}
private
String
getLablePrefix
(
String
name
)
{
String
labelPrefix
=
""
;
if
(
funcInfo
!=
null
)
{
labelPrefix
+=
"$"
+
funcInfo
.
getFuncName
();
}
labelPrefix
+=
"$"
+
name
+
_r_local_label_counter
;
++
_r_local_label_counter
;
return
labelPrefix
;
}
@Override
public
Void
analyze
(
IfStmt
node
)
{
node
.
condition
.
dispatch
(
this
);
RiscVBackend
.
Register
tmpReg
=
/*regMgr.borrowTmp()*/
T6
;
betterBackend
.
emitPop
(
tmpReg
,
"IfStmt: Get condition"
);
String
labelPrefix
=
""
;
if
(
funcInfo
!=
null
)
{
labelPrefix
+=
"$"
+
funcInfo
.
getFuncName
();
}
labelPrefix
+=
"$if"
+
_r_local_label_counter
;
++
_r_local_label_counter
;
String
labelPrefix
=
getLablePrefix
(
"if"
);
Label
elseLabel
=
new
Label
(
labelPrefix
+
".else"
);
Label
exitLabel
=
new
Label
(
labelPrefix
+
".exit"
);
...
...
@@ -387,6 +392,29 @@ public class CodeGenImpl extends CodeGenBase {
return
null
;
}
@Override
public
Void
analyze
(
WhileStmt
node
)
{
String
labelPrefix
=
getLablePrefix
(
"while"
);
Label
beginLabel
=
new
Label
(
labelPrefix
+
".begin"
);
Label
exitLabel
=
new
Label
(
labelPrefix
+
".exit"
);
backend
.
emitLocalLabel
(
beginLabel
,
"WhileStmt: Begin"
);
node
.
condition
.
dispatch
(
this
);
RiscVBackend
.
Register
tmpReg
=
/*borrowOneTmp*/
T6
;
betterBackend
.
emitPop
(
tmpReg
,
"GetCondition"
);
backend
.
emitBEQ
(
ZERO
,
tmpReg
,
exitLabel
,
"WhileSTmt, IfFalse, exit"
);
for
(
Stmt
stmt
:
node
.
body
)
{
stmt
.
dispatch
(
this
);
}
backend
.
emitJ
(
beginLabel
,
"WhileStmt: GOTO begin"
);
backend
.
emitLocalLabel
(
exitLabel
,
"WhileStmt: End"
);
return
null
;
}
@Override
public
Void
analyze
(
CallExpr
callExpr
)
{
...
...
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