-
Notifications
You must be signed in to change notification settings - Fork 2
add an IL with a dedicated pointer type #172
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
Conversation
It extends the `L0` language and is the basis for the `L1` language. The `L3` is modified such that the new `Offset` is removed again. While there's nothing preventing `Offset` from working in the `L3` and above, it's better if higher-level ILs don't have access to pointer arithmetic for now.
The pass has to use the `Ptr` type now, making the `ptrSize` parameter obsolete.
Size and alignment computation for simple types was assuming `Int`, `UInt`, and `Float` types, but now there's also the `Ptr` type, which has a different shape.
Same as with the stack allocation pass, `Ptr` has to be used now.
Pointers are no longer arithmetic types in the `L3`, meaning that `Add` and `Mul` are not applicable anymore. The pointer size still has to be passed to the pass, as the former is required for various type size computations.
The size computations need to consider the new `Ptr` type.
The need to manually do this does highlight an issue with the current system. A better solution would be for there to be some set(s) to which `Nil` and `Ptr` are added, with processing then looking for items of that set instead of enumerating all node kinds manually.
It's not exposed to the source language and only meant for internal use in `source2il`. `source2il` doesn't yet use it, however.
* `tkPointer` and procedure pointers now translate to `Ptr`. This requires some adjustments in the hand-written L30 code * the `pointerType` constant is replaced with using `tkPointer` directly
Aggregate parameter lowering, global lowering, and stack allocation all emit different code now.
This means: * translating all MIR pointer-like types to `Ptr` * adjusting the cast translation, which has to take into account pointer types not being numeric/arithmetic type anymore * using `Nil` instead of zero for representing nil pointers
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.
A couple of minor comments, nothing major.
On the topic of adding pointer and null, I wonder if some of the necessary changes would have been easier to catch with a push towards exhaustive cases?
It would have been, yea, but enumerating all syntax is would be a lot of work, currently. What's missing is the non-terminals from the IL grammars (e.g., Relatedly, whatever the experiment with a new IR will yield, one thing it has made obvious to me already is that the hierarchical, inheritance/extension-based language level design should be replaced with a compositional design, where there are atomic language features + capabilities that have dependencies on one another. |
Summary
Add the
LPtrIL providing a dedicated pointer type and anOffsetoperation for pointer arithmetic. Higher-level ILs as well as
skullyand
source2ilare changed to use the newPtrtype.Details
Idea
The idea behind a dedicated pointer type is to:
is implemented
how a pointer is implemented)
Implementation
LPtrproviding thePtrtype andNilandOffsetexpression. It extends the
L0IL and is the new basis for theL1ILptrToIntpass (LPtr->L0)into the main executable and the REPL
PtrandNilOffsetinstead of integerarithmetic
pass, to use
Ptrinstead of lowering toUIntptrToIntpassThe IL uses a symbolic name (rather than a numeric one) so that the
existing ILs don't have to be renamed.
Usage of
Offsetis disallowed past theL2IL for now, so that rawpointer arithmetic is not exposed to higher-level ILs for now.
Source2IL
tkPointertypepointerTypeconstant with usingtkPointerdirectlytkPointerand procedure pointers to the ILPtrtypeL30code to not use pointer arithmeticSkully
PtrNilfor representing nil pointersbeing arithmetic types
Notes For Reviewers
L3-> LLVM IR translation pass #146