-
Notifications
You must be signed in to change notification settings - Fork 18
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
Initial Register and BitField macros #4
Conversation
adds initial macros for declaring symmetric and asymmetric registers composed of bitfields.
This doesn't yet have complete tests, nor does it incorporate @jckarter's suggestions. These may come in a future PR, right now I'm trying to land on a good enough API for initial users, before polishing up the internals. |
The protocol hierarchy also feels like a mess... |
\(declAccessLevel) init(unsafeAddress: UInt) { self.unsafeAddress = unsafeAddress } | ||
""", | ||
"\(declAccessLevel) var unsafeAddress: UInt", | ||
"\(declAccessLevel) init(unsafeAddress: UInt) { self.unsafeAddress = unsafeAddress }", |
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.
I don't think this can be uniformly UInt
some registers will be defined as UInt8
, UInt16
, UInt32
or Uint64
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.
Note: This is the address of the register, not the value of the register itself
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.
should it then contain the size in the initializer?
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.
You mean the macro arguments?
case reserved = "Reserved" | ||
case readWrite = "ReadWrite" | ||
case readOnly = "ReadOnly" | ||
case writeOnly = "WriteOnly" |
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.
what about writeOnce
and readWriteOnce
types?
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.
Forthcoming...
- Rewrite diagnostics system - Add `require` helpers methods which throw on error and emit diagnostics - Refactors macros to leverage `require` methods - Expands MacroArgumentParser to emit better diagnostics and fixits
1b2dbc3
to
289fea6
Compare
Add initial Register and BitField macros Adds an initial set of macros for declaring symmetric and asymmetric registers composed of bit fields. The new `@Register` macro can be applied to a struct only containing stored properties marked with one of the new bit field macros: `@Reserved`, `@ReadWrite`, `@ReadOnly`, or `@WriteOnly`. The bit field macros take bit range argument which the register macro uses to create three views of the register. The first is a raw view which provides untyped access to the bits of the register. The second is a read view which only provides typed getters for the readable bit fields. The last is a write view which provides setters. Additional bit field macros such as `@Write1Clear` will be introduced in a future PR. Sample usage: ```swift @register(bitWidth: 32) struct Example { @readwrite(bits: 0..<1) var en: EN } var example = Register<Example>(...) example.modify { $0.en = 0x1 } ``` Miscellaneous changes Rewrites diagnostics system leveraging a new `MacroContext` type which handles prefixing diagnostics with the name of the macro which produced them. Adds helper methods prefixed by "require" to swift-syntax types which take a macro context, emit a diagnostic and throw `ExpansionError` if the requirement is not met. Adds MMIOKindMacro protocol wrappers which suppresses thrown `ExpansionErrors` to allow macros to be written as simpler straight line code e.g. `try value.requireSomething(context)`. Replaces `MacroArgumentParser` with `ParsableMacro` leveraging `MacroContext` which emits better diagnostics and fix-its.
Add initial Register and BitField macros Adds an initial set of macros for declaring symmetric and asymmetric registers composed of bit fields. The new `@Register` macro can be applied to a struct only containing stored properties marked with one of the new bit field macros: `@Reserved`, `@ReadWrite`, `@ReadOnly`, or `@WriteOnly`. The bit field macros take bit range argument which the register macro uses to create three views of the register. The first is a raw view which provides untyped access to the bits of the register. The second is a read view which only provides typed getters for the readable bit fields. The last is a write view which provides setters. Additional bit field macros such as `@Write1Clear` will be introduced in a future PR. Sample usage: ```swift @register(bitWidth: 32) struct Example { @readwrite(bits: 0..<1) var en: EN } var example = Register<Example>(...) example.modify { $0.en = 0x1 } ``` Miscellaneous changes Rewrites diagnostics system leveraging a new `MacroContext` type which handles prefixing diagnostics with the name of the macro which produced them. Adds helper methods prefixed by "require" to swift-syntax types which take a macro context, emit a diagnostic and throw `ExpansionError` if the requirement is not met. Adds MMIOKindMacro protocol wrappers which suppresses thrown `ExpansionErrors` to allow macros to be written as simpler straight line code e.g. `try value.requireSomething(context)`. Replaces `MacroArgumentParser` with `ParsableMacro` leveraging `MacroContext` which emits better diagnostics and fix-its.
adds initial macros for declaring symmetric and asymmetric registers composed of bitfields.