-
Notifications
You must be signed in to change notification settings - Fork 3
Support for raw pointers #532
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
base: master
Are you sure you want to change the base?
Conversation
// | Ptr( Address, MaybeValue ) // FIXME why maybe? why value? | ||
// address, metadata for ref/ptr | ||
| Ptr( Int, Place, Mutability, Int, Int) | ||
// stack depth (initially zero), place, mutablility, address, offset NOTE: First 3 fields are the same as Reference, last are needed for low level instructions |
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.
Nit-pick: long line
// stack depth (initially zero), place, mutablility, address, offset NOTE: First 3 fields are the same as Reference, last are needed for low level instructions | |
// stack depth (initially zero), place, mutablility, address, offset | |
// NOTE: First 3 fields are the same as Reference, last are needed for low level instructions |
rule #compute( | ||
BOP, | ||
typedValue(Integer(ARG1, WIDTH, _), _, _), | ||
typedValue(Integer(ARG2, WIDTH, _), _, _), | ||
false) // unchecked | ||
=> | ||
typedValue( | ||
Integer(onInt(BOP, ARG1, ARG2), WIDTH, false), | ||
TyUnknown, | ||
mutabilityNot | ||
) |
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.
Two things to correct:
- Your result is always unsigned but we have to keep the signedness flag from the arguments.
rule #compute( | |
BOP, | |
typedValue(Integer(ARG1, WIDTH, _), _, _), | |
typedValue(Integer(ARG2, WIDTH, _), _, _), | |
false) // unchecked | |
=> | |
typedValue( | |
Integer(onInt(BOP, ARG1, ARG2), WIDTH, false), | |
TyUnknown, | |
mutabilityNot | |
) | |
rule #compute( | |
BOP, | |
typedValue(Integer(ARG1, WIDTH, SIGNED), TY, _), | |
typedValue(Integer(ARG2, WIDTH, SIGNED), TY, _), | |
false) // unchecked | |
=> | |
typedValue( | |
Integer(onInt(BOP, ARG1, ARG2), WIDTH, SIGNED), | |
TY, | |
mutabilityNot | |
) |
- We have to ensure the
Ty
are the same for both arguments (I added the match onTY
above). There are rules that checks this, and the suitability of the operands, for arithmetic operations. Maybe we should add similar rules for bit-oriented ones, to signalTypeMismatch
orOperandMismatch
errors
typedValue(Ptr(_, _, _, ADDRESS, _), _, _), | ||
typedValue(Integer(VAL, WIDTH, _), _, _), |
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.
??? Do we really need this rule? I thought the Ptr
value gets cast to usize
before that, or not?
EDIT after reading the related cast rule: Maybe the cast should just be different and we delete this rule.
// requires TY_TO #in TYPEMAP | ||
// requires #is_valid_cast(TY_FROM.layout(), TY_TO.layout()) | ||
|
||
rule <k> #cast( typedValue(VALUE, _TY_FROM, LOCAL_MUT), castKindTransmute, TY_TO) => typedValue(VALUE, TY_TO, LOCAL_MUT) ... </k> |
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.
Well... this rule is certainly too generic.
Right now we only want to cast raw pointers and return their "Address" (IIUC, or something that is derived from it?), as a usize
value that will suit the example program...
rule <k> #projectedUpdate( | ||
_DEST, | ||
typedValue(Ptr(OFFSET, place(LOCAL, PLACEPROJ), MUT, _ADDRESS, _OFFSET2), _, _), | ||
projectionElemDeref PROJS, |
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.
There is also #readProjection
earlier in this module, which will require the same kind of extension to Deref
a pointer.
mir-semantics/kmir/src/kmir/kdist/mir-semantics/rt/data.md
Lines 314 to 322 in 1ee2475
rule <k> #readProjection( | |
typedValue(Reference(FRAME, place(LOCAL:Local, PLACEPROJS), _), _, _), | |
projectionElemDeref PROJS | |
) | |
=> | |
#readProjection( | |
{#localFromFrame({STACK[FRAME -Int 1]}:>StackFrame, LOCAL, FRAME)}:>TypedValue, | |
appendP(PLACEPROJS, PROJS) | |
) |
Raw pointers through
AddressOf
andAggregateKind::RawPtr
are required. Supporting pointers means we are going to have to support or stubAlignment
andLayout
in some manner to handle those MIR rvalues.