summary refs log tree commit diff
path: root/bit_field
Commit message (Collapse)AuthorAge
* Update syn, quote, and proc-macro past 1.0Dylan Reid2020-02-06
| | | | | | | | | | | | | | These were pinned at pre-1.0 versions. Update to the stable API to allow new features to be used in the future. Cq-Depend: chromium:2026764 Change-Id: Id2d979525e5210436cbb1cfa61e2b05fafb288f3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2025907 Tested-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Dylan Reid <dgreid@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: update xhci abi to use new bit_field featuresJingkui Wang2019-05-25
| | | | | | | | | | | | | | We don't need schema anymore. Will use bool and custom enums. BUG=None TEST=local build and run crosvm Change-Id: I1396916878f2903b17a75f375aee4eec1ced0583 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1564780 Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: add license blurb to all filesStephen Barber2019-04-24
| | | | | | | | | | | | | | A few files were missing license blurbs at the top, so update them all to include them. BUG=none TEST=none Change-Id: Ida101be2e5c255b8cffeb15f5b93f63bfd1b130b Reviewed-on: https://chromium-review.googlesource.com/1577900 Commit-Ready: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* edition: Eliminate ref keywordDavid Tolnay2019-04-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As described in: https://doc.rust-lang.org/edition-guide/rust-2018/ownership-and-lifetimes/default-match-bindings.html which also covers the new mental model that the Rust Book will use for teaching binding modes and has been found to be more friendly for both beginners and experienced users. Before: match *opt { Some(ref v) => ..., None => ..., } After: match opt { Some(v) => ..., None => ..., } TEST=cargo check --all-features TEST=local kokoro Change-Id: I3c5800a9be36aaf5d3290ae3bd3116f699cb00b7 Reviewed-on: https://chromium-review.googlesource.com/1566669 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* edition: Remove extern crate linesDavid Tolnay2019-04-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Rust 2018 edition, `extern crate` is no longer required for importing from other crates. Instead of writing: extern crate dep; use dep::Thing; we write: use dep::Thing; In this approach, macros are imported individually from the declaring crate rather than through #[macro_use]. Before: #[macro_use] extern crate sys_util; After: use sys_util::{debug, error}; The only place that `extern crate` continues to be required is in importing the compiler's proc_macro API into a procedural macro crate. This will hopefully be fixed in a future Rust release. extern crate proc_macro; TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu TEST=local kokoro Change-Id: I0b43768c0d81f2a250b1959fb97ba35cbac56293 Reviewed-on: https://chromium-review.googlesource.com/1565302 Commit-Ready: David Tolnay <dtolnay@chromium.org> Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* edition: Fill in macro importsDavid Tolnay2019-04-15
| | | | | | | | | | | | | | | | | | | | Macros were previously imported through `#[macro_use] extern crate`, which is basically a glob import of all macros from the crate. As of 2018 edition of Rust, `extern crate` is no longer required and macros are imported individually like any other item from a dependency. This CL fills in all the appropriate macro imports that will allow us to remove our use of `extern crate` in a subsequent CL. TEST=cargo check --all-features --tests TEST=kokoro Change-Id: If2ec08b06b743abf5f62677c6a9927c3d5d90a54 Reviewed-on: https://chromium-review.googlesource.com/1565546 Commit-Ready: David Tolnay <dtolnay@chromium.org> Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* Silence non_upper_case_globals warnings in macrosDaniel Verkamp2019-04-09
| | | | | | | | | | | | | | | | | | | | The enumn and bitfield macros generate global constants based on names that are typically in CamelCase, but the new on-by-default warning non_upper_case_globals complains about them. Fixes warnings of the form: warning: associated constant `...` should have an upper case name when using enumn or bitfield. BUG=None TEST=`cargo build` without warnings Change-Id: Id908df1dcdf58288c2cbdff574cb70be2026bde6 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1536558 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* cargo: Sort all dependency lists in Cargo.tomlDavid Tolnay2019-04-09
| | | | | | | | | | | | | | | This may help reduce cases of conflicts between independent CLs each appending a dependency at the bottom of the list, of which I hit two today rebasing some of my open CLs. TEST=cargo check --all-features Change-Id: Ief10bb004cc7b44b107dc3841ce36c6b23632aed Reviewed-on: https://chromium-review.googlesource.com/1557172 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
* edition: Update bit_field and bit_field_derive to 2018 editionDavid Tolnay2019-04-07
| | | | | | | | | | | | | | | | | | Separated out of CL:1513058 to make it possible to land parts individually while the affected crate has no other significant CLs pending. This avoids repeatedly introducing non-textual conflicts with new code that adds `use` statements. TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu Change-Id: Ie62d28d63257e59e6bee68b5c42a1f4cf7b47bed Reviewed-on: https://chromium-review.googlesource.com/1519690 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* improve bitfield type safety by allowing tuple struct fieldJingkui Wang2019-04-03
| | | | | | | | | | | | | user-defined tuple struct could be used to improve type safety. TEST=cargo test BUG=None Change-Id: I8ce10fc51b79c277ab23029513b707f3dd621af5 Reviewed-on: https://chromium-review.googlesource.com/1546432 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* implement bitfield for enum with a widthJingkui Wang2019-03-28
| | | | | | | | | | | | | | | If we know the width of an enum type, we don't need 'power of 2' number of variants. BUG=None TEST=cargo test Change-Id: I8148b28f86bb8e4fd4f67d8a6382fc713dad1439 Reviewed-on: https://chromium-review.googlesource.com/1530455 Commit-Ready: Jingkui Wang <jkwang@google.com> Tested-by: Jingkui Wang <jkwang@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* Change default field type to setter/getter types and remove generatedJingkui Wang2019-03-28
| | | | | | | | | | | | | | | | | | tests Setter/Getter types will allow better enum fields. Generated tests should be tests for bit_field cargo rather than the defined bit_field struct. BUG=None TEST=cargo test Change-Id: Ib3594e35e28fc393d49c476c9c83fc632cac3190 Reviewed-on: https://chromium-review.googlesource.com/1530454 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Jingkui Wang <jkwang@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* bitfield: Support BitFieldSpecifier for enumsDavid Tolnay2019-03-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, the getter and setter functions generated for a bitfield struct by #[bitfield] all operated on primitive types like bool, u8, u16 etc. This CL adds support for getters and setters defined in terms of user-defined enums. We make an enum bitfield-compatible by adding #[bitfield]. The number of variants must be a power of 2. #[bitfield] enum TwoBits { Zero = 0b00, One = 0b01, Two = 0b10, Three = 0b11, } And then it may be used to specify a field in a bitfield struct. #[bitfield] struct Struct { prefix: BitField1, two_bits: TwoBits, suffix: BitField5, } The generated getters and setters for this struct would have the following signatures: impl Struct { fn get_prefix(&self) -> u8; fn set_prefix(&mut self, val: u8); fn get_two_bits(&self) -> TwoBits; fn set_two_bits(&mut self, val: TwoBits); fn get_suffix(&self) -> u8; fn set_suffix(&mut self, val: u8); } TEST=`cargo test` the bit_field and bit_field_derive crates TEST=`cargo check` crosvm Change-Id: Ibc8923e2877fda6ae8da5767731edcb68721a434 Reviewed-on: https://chromium-review.googlesource.com/1519686 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
* Run `cargo fmt`Miriam Zimmerman2019-02-16
| | | | | | | | | | | | BUG=None TEST=None Change-Id: I6db08c2ccfc616e4e34ad0219580c084dda34675 Reviewed-on: https://chromium-review.googlesource.com/1475058 Commit-Ready: Miriam Zimmerman <mutexlox@chromium.org> Tested-by: Miriam Zimmerman <mutexlox@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* bitfield: Documentation and simplificationsDavid Tolnay2019-01-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Changes in this CL: - Crate-level documentation for bit_field crate! - Use absolute paths within generated code so that the caller is no longer required to have various implementation details from the bit_field crate in scope. - Check that the total number of bits is a multiple of 8. Previously, it would generate compilable code that panicked when invoking accessors. - Provide B0 .. B64 as shorthand for BitField0 .. BitField64. - Use `bool` as the bool specifier rather than BitFieldBool. - Disallow BitFieldSpecifier impls outside the bit_field crate. - Simplify declaration of the BitFieldN types by replacing the recursive macro_rules with a simpler procedural macro. TEST=`cargo test` in bit_field and in bit_field_derive Change-Id: Ica9347bc89901de85f74366edd038fb5d8042ee6 Reviewed-on: https://chromium-review.googlesource.com/1382578 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Jingkui Wang <jkwang@google.com>
* bitfield: update bitfield structs and support boolJingkui Wang2018-12-19
| | | | | | | | | | | | | | | BitFieldSpecifiers are now generated by macros. Can use BitFieldBool to specify a bool field. BUG=chromium:831850 TEST=local cargo build/test Change-Id: Id6b4a773ab612cea39ba811c3ec1da212b618ba2 Reviewed-on: https://chromium-review.googlesource.com/1356912 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* bitfield: reformat with cargo fmtDaniel Verkamp2018-12-12
| | | | | | | | | | | BUG=None TEST=cargo fmt --all -- --check Change-Id: Ieccf6d77af27d299a08d22d9b3ee4b44bd90c5b8 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1370625 Reviewed-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* macros: Clean up bitfield macro by replacing the input itemDavid Tolnay2018-12-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: #[derive(BitField)] #[passthrough(derive(Clone, Copy, PartialEq))] pub struct TrbSchema { parameter: B64, status: B32, cycle: B1, flags: B9, trb_type: B6, control: B16, } After: #[bitfield] #[derive(Clone, Copy, PartialEq)] pub struct Trb { parameter: B64, status: B32, cycle: B1, flags: B9, trb_type: B6, control: B16, } This change eliminates the need for the `passthrough` attribute, and avoids the separate `FooSchema` struct continuing to float around and disrupt IDE autocomplete. TEST=`cargo test` the bit_field_derive crate TEST=`cargo check` the devices crate against a migrated CL:1144264 Change-Id: I950ce896607468c73852aa181827f1a5dc0f0227 Reviewed-on: https://chromium-review.googlesource.com/1366539 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Jingkui Wang <jkwang@google.com>
* macros: Format code inside of quote! invocationsDavid Tolnay2018-11-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rustfmt currently does not touch the content of macro invocations. Also it used to have a bug where if it changed indentation of a block of code containing a multi-line macro invocation then the macro input would not get correspondingly indented. That bug was visible across some of the code here. For example: // rustfmt decides to un-indent the surrounding block: let data_size_in_bytes = quote!( ( #( #field_types::FIELD_WIDTH as usize )+* ) / 8 ); // poorly formatted resulting code: let data_size_in_bytes = quote!( ( #( #field_types::FIELD_WIDTH as usize )+* ) / 8 ); // should have been: let data_size_in_bytes = quote!( ( #( #field_types::FIELD_WIDTH as usize )+* ) / 8 ); TEST=cargo check crosvm TEST=cargo test each of the three proc-macro crates CQ-DEPEND=CL:1338507 Change-Id: Id2d456a8d85d719fbc0a65624f153f0f9df6f500 Reviewed-on: https://chromium-review.googlesource.com/1338508 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
* macros: Update syn to 0.15David Tolnay2018-11-21
| | | | | | | | | | | | | | | | | | | | | | | | | This brings us onto the stable API surface area for procedural macros that stabilized in Rust 1.30, rather than the string-based shim on older compilers. https://blog.rust-lang.org/2018/10/25/Rust-1.30.0.html Intervening release notes: - https://github.com/dtolnay/syn/releases/tag/0.13.0 - https://github.com/dtolnay/syn/releases/tag/0.14.0 - https://github.com/dtolnay/syn/releases/tag/0.15.0 TEST=cargo check crosvm TEST=cargo test each of the three proc-macro crates TEST=build_packages CQ-DEPEND=CL:1340766 Change-Id: Idcf14df0225ab41423b9a8639d0bba0a63513712 Reviewed-on: https://chromium-review.googlesource.com/1338507 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
* bitfield: Add fmt::DebugJingkui Wang2018-08-07
| | | | | | | | | | | | | implements fmt::Debug for bitfield BUG=chromium:831850 TEST=cargo test Change-Id: I58c2211a50726aaea0ea45164ae07c7b38eddea7 Reviewed-on: https://chromium-review.googlesource.com/1147111 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Jingkui Wang <jkwang@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: Add bit_field_deriveJingkui Wang2018-08-03
Support macro derive(BitField) to make life easier. BUG=None. TEST=local build and run test. Change-Id: I582620de250017fb7c0b601f9ad4fbcbbc2fe02a Reviewed-on: https://chromium-review.googlesource.com/1069331 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Jingkui Wang <jkwang@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>