source2il: implement alignment support #112
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implement internal support for locations with an alignment requirement
greater than 1 byte. This is a preparation for the source language
gaining type alignment requirements.
Details
The alignment for numeric types (int and float) is equal to their size,
while for aggregate types (other than
seq
) it's that of their mostaligned constituent type.
The size of aggregate types is padded to be a multiple of their
alignment. This is so that their size matches the space they would take
up within an array, while still allowing copying
size
bytes from apointer to a location of said type to be valid, regardless of where the
location is located. Record fields are placed such that their relative
offset is a multiple of their alignment requirement.
The allocator procedures
alloc
andrealloc
take an additionalparameter specifying the allocation's required alignment.
grow
andpreparedAdd
also take an additional parameter, which specifies thealignment of the dynamic array's element type. The callsites of all
four procedures are updated accordingly.
Finally, the value rendering in
vmexec
is updated to take the newobject layout into account.
Notes For Reviewers
asm.js
translation pass, asasm.js
doesn't have native support for misaligned memory access