首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
CS 2210编程代写、Java程序语言代做
项目预算:
开发周期:
发布时间:
要求地区:
CS 2210 Programming Project (Part IV)
Code Generation
This project is intended to give you experience in writing a code generator as well as bring together
the various issues of code generation discussed in the text and in class.
Due date
The assignment is due December 9th, 2023, 11:59pm. This is the hard deadline and no extensions will be given for this project.
Project Summary
Your task is to write a code generator, the final phase of your compiler. It produces (target)
assembly code for the MIPS R2000 architecture. It takes as input the augmented AST and symbol
table produced by the previous phases of your compiler. The generated code will be executed using
SPIM S20, a simulator for the MIPS R2000.
Code generation will consist of assigning memory addresses for each variable used in the MINIJAVA program and translating subtrees of the AST (intermediate language representation) into
sequences of assembly instructions that perform the same task.
Code Generation
This is the only phase of your compiler which is machine dependent. Examples of assembly code
programs will be provided on the class webpage.
The important/interesting issues in generating code for MINI-JAVA are discussed in the following paragraphs. Please refer to chapter 7, 8 and class notes for further details on these issues,
You can make the following assumptions to simplify the project.
Code is generated for the intermediate instructions on a statement-by-statement basis without
taking into account the context of an intermediate instruction
code is generated for the intermediate instructions in the order that they occur within the
intermediate instruction sequence.
You may take advantage of any special instruction of the machine when choosing target
instructions for a given intermediate instruction.
You do not have to any fancy register allocation or optimization on your target code.
1
Computing Memory Addresses
Since address information has not been computed and entered into the symbol table by earlier
phases, the first task of the code generator is to compute the offsets of each variable name (both
global and local); that is, the address of each local data object and formal parameter within the
activation record for the block in which they are declared. This can be done by initializing a
variable offset at the start of each declaration section, and as each declaration is processed, the
current value of offset is entered as an attribute of that symbol, and offset is then incremented
by the total width of that data object (depending on its type).
The program execution begins with a method called main() being called. Since the language
has no way to initiate classes, all classes are instantiated when program execution begins. Thus,
all storage for all classes is allocated globally. The offsets of variables within classes should be
computed and stored as an attribute of the variable name, typically relative to the start of the class
or can just be relative to the start of the global storage.
For simplicity, declarations within a method donot contain any objects whose types are classes.
That is, local variables can only be of integer type or integer array type.
Call-by-value parameters will have a width dependent on the type of the parameter (remember
we are using only integer parameters), whereas call-by-reference parameters will have a width
equal to ONE word to store an address. The total activation record size of each method should be
computed at this time and entered in the symbol table as an attribute of the method name.
The machine architecture must be take into account when computing these widths, that is,
an integer in the MIPS processor is 4 bytes. Offsets of locals can be implemented as a negative
offset from the frame pointer while offsets of parameters can be positive from the frame pointer.
Thus, the computation of offsets of arguments and local variables can be done independently. This
information will be used upon every reference to the data object in addition to being used in the
allocation of storage for activation records.
Handling Structure Data Types
Storage for an array is allocated as a consecutive block of memory. Access to individual elements
of an array is handled by generating an address calculation using the base address of the array,
the index of the desired element, and the size of the elements. You are free to choose the layout of
elements of an array in your implementation (e.g., row major or column major order).
Simple Control Flow
Code for simple control statements, namely conditional and loops in MINI-JAVA, can be generated
according to the semantics of conventional programming languages using the compare and branch
instructions of the assembly language. Unique target labels will also have to be generated.
Method Invocation, Prologues, and Epilogues
Recursion in MINI-JAVA prevents the use of a static storage allocation strategy. However, the
language has no features that prevent the deallocation of activation records in a last-in-first-out
manner. That is, activation records containing data local to an execution of a method, actual
parameters, saved machine status, and other information needed to manage the activation of the
2
method can be stored on a run-time stack. The MIPS assembly language provides the subroutine
call mechanisms to manipulate the run-time user stack.
An activation record for a method is pushed onto the stack upon a call to that method, while
the activation record for the method is popped from the stack when execution of the method is
finished and control is to be returned to the caller. As MINI-JAVA does not allow dynamic classes
and arrays, the sizes of all activation records are known at compile time.
Method calls result in the generation of a calling sequence. Upon a call, an activation record for
the callee must be set up and control must be transferred to the callee after saving the appropriate
information in the activation record. For each method, the generated code sequence will consist of
a prologue, the code for the statements of the method, and the epilogue. Typically, the prologue
saves the registers upon a method call and allocates space on the stack for local variables, whereas
the epilogue consists of restoring the saved machine status and returning control to the point in the
caller immediately after the point of call. The handout on the MIPS assembly language explains
the instructions used to implement these actions.
Parameter passing
In order to correctly handle the formal parameters within the body of the callee, the symbol table
entry for each formal parameter must include an attribute that indicates the parameter passing
mode, that is, by-value or by-reference. Remember that we do not pass arrays as parameters. On
a method invocation, call-by-value parameters are handled by allocating the local store for the size
of the object in the activation record of the callee and then evaluating the actual parameter and
initializing the local store within the callee with the value of the actual parameter. All accesses to
that formal parameter will change the value in the local space, with no effect on the caller. On a
return, no values are copied back to the caller.
Call-by-reference parameters are handled by allocating local space in the callee’s activation
record for the address of the actual parameter and then copying the address of the actual parameter
into that local space. All accesses to that formal parameter during execution of the callee are indirect
accesses through this address, having a direct effect on the caller. On return, no action is taken
other than reclaiming the space.
Note that MIPS has a convention that the first 4 arguments of a method call are passed in
register $a0-$a3. You have the option to follow this convention.
Register Usage
In the MIPS processor, certain registers are typically reserved for special purposes. You should
abide by these conventions.
Possible Functions
You may want to write the following functions to help in the code generation.
1. emit call(func name, num arg)/*emit a call instruction; func name: function id lexeme pointer;
num arg: number of arguments */
2. emit label(l num)/*emit a definition of a label; l num: label number; example: L=102, code
generated = “L 102” */
3
3. emit goto(operator, l num) /*emit unconditional and conditional jump instructions; operator:
an operator in the branch-jump group; l num: label number */
4. emit data(name, type, size) /* emit one data line, which is used for STATIC allocation;
name: data object id lexeme pointer; type: type width; size: number of elements of above type
*/
5. emit str(name, str) /* emit a string constant definition line; name: pointer to the name
lexeme; str: pointer to the str */
6. emit most(operator, type, num op, op1, op2, op3) /* emit most of the instructions; operator:
one of the instructions in the general group; type: data type; num op: number of operators 1,
2 and/or 3; op1...3: operands, op2 and op3 can be omitted depending on num op */
Run-time Error Detection
You do not need to generate any run-time checks. Thus you can assume that array bounds are
within range and scalars are within range.
Testing your code
The code generated is MIPS assembly code and should follow the descriptions specified in the
handout SPIM S20. Samples will be put on the class webpage.
You can run the generated assembly code on the simulator and check the results. However, the
correct output does not guarantee that your code is completely correct. You should examine your
generated code carefully.
proj4> codeGen < sample1.java
proj4> spim -asm -file code.s
... ...
or
proj4> spim
(spim) load “code.s”
(spim) step
[0x00400000] 0x8fa40000 lw $4,0($29)
(spim) run
... ...
Assignment submission
Please submit your project in Canvas before the due time. The submission should be a compressed
file that contains your project source code and readme file (if any).
4
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代写dts207tc、sql编程语言代做
2024-12-25
cs209a代做、java程序设计代写
2024-12-25
cs305程序代做、代写python程序...
2024-12-25
代写csc1001、代做python设计程...
2024-12-24
代写practice test preparatio...
2024-12-24
代写bre2031 – environmental...
2024-12-24
代写ece5550: applied kalman ...
2024-12-24
代做conmgnt 7049 – measurem...
2024-12-24
代写ece3700j introduction to...
2024-12-24
代做adad9311 designing the e...
2024-12-24
代做comp5618 - applied cyber...
2024-12-24
代做ece5550: applied kalman ...
2024-12-24
代做cp1402 assignment - netw...
2024-12-24
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!