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
fd08b327
There was an error fetching the commit references. Please try again later.
Verified
Commit
fd08b327
authored
6 years ago
by
Recolic Keghart
Browse files
Options
Downloads
Patches
Plain Diff
[DO NOT BUILD] fix func calling
parent
37ea8f4f
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
+24
-10
24 additions, 10 deletions
src/main/java/chocopy/pa3/CodeGenImpl.java
with
24 additions
and
10 deletions
src/main/java/chocopy/pa3/CodeGenImpl.java
+
24
−
10
View file @
fd08b327
package
chocopy.pa3
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Stack
;
import
java.util.*
;
import
chocopy.common.analysis.SymbolTable
;
import
chocopy.common.analysis.AbstractNodeAnalyzer
;
...
...
@@ -219,7 +216,6 @@ public class CodeGenImpl extends CodeGenBase {
stmt
.
dispatch
(
stmtAnalyzer
);
}
backend
.
emitLocalLabel
(
stmtAnalyzer
.
epilogue
,
"Epilogue"
);
betterBackend
.
emitFunctionEnd
(
funcInfo
.
getFuncName
(),
null
,
null
);
}
...
...
@@ -268,6 +264,16 @@ public class CodeGenImpl extends CodeGenBase {
private
int
_r_local_label_counter
=
427
;
// Extend StackVarInfo to add more info.
private
Map
<
String
,
Integer
>
funcArgsMap
=
new
HashMap
<>();
// Map from StackVarInfo to offset of FP.
public
void
initArgsMap
(
List
<
String
>
args
)
{
for
(
int
i
=
0
;
i
<
args
.
size
();
++
i
)
{
int
offset
=
(
i
)
*
backend
.
getWordSize
();
funcArgsMap
.
put
(
args
.
get
(
i
),
offset
);
}
}
/** An analyzer for the function described by FUNCINFO0, which is null
* for the top level. */
StmtAnalyzer
(
FuncInfo
funcInfo0
)
{
...
...
@@ -320,12 +326,15 @@ public class CodeGenImpl extends CodeGenBase {
// 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."
);
if
(
funcArgsMap
.
containsKey
(
stackVarInfo
.
getVarName
()))
{
// is a function argument.
backend
.
emitSW
(
tmpReg
,
FP
,
funcArgsMap
.
get
(
stackVarInfo
.
getVarName
()),
"Assign to function param var"
);
}
else
throw
new
RuntimeException
(
"ASSIGN to stack variable: NOT IMPLEMENTED: StackVarInfo not implemented."
);
}
}
return
null
;
...
...
@@ -453,15 +462,20 @@ public class CodeGenImpl extends CodeGenBase {
@Override
public
Void
analyze
(
Identifier
id
)
{
// NOT DONE
SymbolInfo
ident
=
sym
.
get
(
id
.
name
);
// global var case
if
(
ident
instanceof
GlobalVarInfo
)
{
backend
.
emitLW
(
A0
,
((
GlobalVarInfo
)
ident
).
getLabel
(),
"Load identifier"
);
backend
.
emitSW
(
A0
,
SP
,
0
,
"Push to stack"
);
}
else
if
(
ident
instanceof
StackVarInfo
){
// local variable
//TODO: Figure out how we can keep track of whether the var has already been pushed to stack.
StackVarInfo
identVar
=
(
StackVarInfo
)
ident
;
if
(
funcArgsMap
.
containsKey
(
identVar
.
getVarName
()))
{
// is a function arg.
backend
.
emitLW
(
T6
,
FP
,
funcArgsMap
.
get
(
identVar
.
getVarName
()),
"Idnet:get FuncArg identifier value to reg"
);
backend
.
emitSW
(
T6
,
SP
,
0
,
"Push to stack without decrease SP"
);
return
null
;
// DO NOT RUN THE FUCKING SILLY CODE BELOW
}
// TODO: Function arg works, but local var won't work.
if
(
id
.
getInferredType
().
equals
(
SymbolType
.
INT_TYPE
))
{
IntegerLiteral
value
=
(
IntegerLiteral
)
(
identVar
.
getInitialValue
());
backend
.
emitLI
(
A0
,
value
.
value
,
"Load initial value of StackVar"
);
...
...
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