-
Notifications
You must be signed in to change notification settings - Fork 4
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
Global variable code generation #170
Conversation
6331706
to
f2984a9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, in the type checker, declarations and their corresponding InitExpr
are set as global if they are in file scope. Additionally, IdExpr
and ArrSubExpr
are set as global if they refer to global identifiers. However, since global variables can only be initialized with constant expressions (such as constant integers and enums), is it possible that we don't need to mark them specially? Constant expression nodes hold their value, so we can directly access those values when generating code, which means GlobalVarInitVal
can be removed as well. For ArrSubExpr
, we can check whether they refer to a global array during code generation.
With these changes, only DeclNode
and IdExprNode
need to hold the is_global
data member. Additionall, we can merge the id_is_global
map with the symbol table, making it one of its fields.
Please consider these possible modifications, and let me know if there's anything I might have misunderstood!
Not possible with the current infrastructure. We still need to mark
It is doable for
There's a
In conclusion, I agree that not every AST node needs |
Btw, I haven't rebase and implemented LLVM's part yet! 🫡 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. 🙆♂️ Let's only restrict the scope of is_global
and keep the others as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for implementing these; this is yet another complicated PR. 😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
is_global
member forDeclNode
andExprNode
.is_global
in type checking stage.struct GlobalVarInitVal
with members ofvalue
andtype
and a functionGenerateQBEInit
, so that we can generate corresponding QBE IR.P.S: I also found a bug for struct and union declaration. I'll fix that first before jumping into struct, union code generation.