-
Notifications
You must be signed in to change notification settings - Fork 33
[Question] [Homework 2] implementing &(address) or *(Indirection) in IRGen #580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
Handling address operationsAs explained in #404, the address operator ( You may want to revisit the Lvalue chapter in the instruction videos.
This logic is handled in Handling indirection operations
Correct. Indirection can be implemented simply by inserting a load instruction. About the model solution output of pointer.cNote: You can comment out parts of the source file to observe which sections are translated into which IR.
That's all correct. The unused loads exist because the model solution's translation of unary operators always generates IR to compute the operand's value, even when unnecessary. Since most unary operations ( I might make a patch to the model solution to reduce redundant IR code. I'll let you know if I do. In later assignments, the compiler will be able to remove such unused code. |
In fact, I think the model solution having more |
I tried Thank you for very kind answer and clarification !!! I really appreciated it. |
We have updated the model solution (#584). The current model output for
Let us know if you encounter any other issues! |
Thank you for your help! |
Uh oh!
There was an error while loading. Please reload this page.
Question Summary : Can I get hints for implementing &(address) or *(Indirection) in IRGen?
I am struggling with 'pointer.c' when making IRGen.
I wanted to implement Address and Indirection unary operation in the function "fn translate unary function(..)"
I thought that how I can implement Address is "if operand is identifier, then use lookup_symbol_table, in the other case, use GetElementPtr" and how I can implement Address is using "Load instruction".
I also tried to modifying "fn translate_expr_rvalue" or "fn translate_expr_lvalue" and using only them, after reading #404
it didn't work.
If I insert pointer.c into the IRGen Model Solution in gg
there comes a IR like this(I posted only the IR of main function)
I think from i1 to i2 is
int* p = &a;
from i3 to i6 is
int** p2 = &*&p
;from i7 to i9 is
int* p3 = *&p
;from i10 to i26 is
*&*foo(*p2) += 1
;else part is
*foo(p3) += 1
;in the part of from i3 to i6, I cannot understand why
load %l1:i32**
is implemented 3 times in IRand, also, in the part of i7~i9,
load %l1:i32**
is implemented 2 times in IRThis seems unnecessary in the IR.
And also, why that
call @foo:[ret:i32* params:(i32*)]*(%b0:i11:i32*)
is implemented multiple times?For my solution and thinking the call expression function would be called once at each sentence.
I cannot see the pattern of
&
or*
when seeing IR or pointer.cI appreciate TA's effort for this class.
And also, Can I used GetElementPtr when implementing
&
or*
in IRGen?where to take, when to take, the coverage etc...
The text was updated successfully, but these errors were encountered: