-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #814 from herd/asl-getfields-to-call
[asl] Can call a setter or getter on bitfields with field access syntax. Check for existing getter (resp. setter) when typing field access (resp .update). This feature is useful to view subfields of bitfields as distinct objects. For instance, the fields `X` and `Y` below apparently belong to a single bitfield `STATE`, as we write `STATE.X` and `STATE.Y`. However they in fact correspond to different bitfields `_X` and `_STATE`. ``` type State of bits(2) { [0] X, [1] Y, }; var _X:State; var _STATE:State; // Defining the following canonical getter is mandatory to bridge the gap // between the name STATE and te type State. getter STATE[] => State begin return _STATE; end setter STATE[] = v : State begin _STATE = v; end getter STATE[n:integer] => bits(1) begin if n <= 0 then return _X[n]; else return _STATE[n]; end end setter STATE[n:integer] = v : bits(1) begin if n <= 0 then _X[n] = v; else _STATE[n] = v; end end func main() => integer begin STATE.X = '1'; STATE.Y = '1'; print(STATE.X,STATE.Y); print(_X,_STATE); return 0; end ``` As a result the above program will print two lines `'1' '1'` and `'01' '10'`. The framework is slightly more generic : multiple field accesses, such as `STATE.[X,Y]` are handled, provided the appropriate getter and setters are defined. Here, one should for instance define `getter STATE[n:integer,m:integer] => bits(2)` with whatever adequate body.
- Loading branch information
Showing
5 changed files
with
262 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.