FuelLabs/sway
View on GitHubAllow use of `consts` in place of immediates in asm blocks
Open
#810 opened on Feb 17, 2022
P: lowcompilerenhancementgood first issuelanguage featureteam:compiler
Repository metrics
- Stars
- (61,702 stars)
- PR merge metrics
- (Avg merge 22h 6m) (16 merged PRs in 30d)
Description
Motivation
https://github.com/FuelLabs/sway-lib-std/pull/46
We should be able to directly use the const in the asm block if it is small enough to fit in that immediate size.
Summary
Currently, immediates are size-checked in the compiler. If an opcode takes a 12-bit immediate, the size of that immediate is checked at compile time. Since we also know the value of consts at compile time, we should be able to directly allow the use of consts inside of asm blocks instead of passing them in. This will require a modification to the grammar and then size checking the const.