microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
compiler/qsc_data_structures/src/target.rs
40lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | use bitflags::bitflags; |
| 5 | |
| 6 | bitflags! { |
| 7 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 8 | pub struct TargetCapabilityFlags: u32 { |
| 9 | const Adaptive = 0b0000_0001; |
| 10 | const IntegerComputations = 0b0000_0010; |
| 11 | const FloatingPointComputations = 0b0000_0100; |
| 12 | const BackwardsBranching = 0b0000_1000; |
| 13 | const HigherLevelConstructs = 0b0001_0000; |
| 14 | const QubitReset = 0b0010_0000; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | impl std::str::FromStr for TargetCapabilityFlags { |
| 19 | type Err = (); |
| 20 | |
| 21 | fn from_str(value: &str) -> Result<Self, Self::Err> { |
| 22 | match value { |
| 23 | "Base" => Ok(TargetCapabilityFlags::empty()), |
| 24 | "Adaptive" => Ok(TargetCapabilityFlags::Adaptive), |
| 25 | "IntegerComputations" => Ok(TargetCapabilityFlags::IntegerComputations), |
| 26 | "FloatingPointComputations" => Ok(TargetCapabilityFlags::FloatingPointComputations), |
| 27 | "BackwardsBranching" => Ok(TargetCapabilityFlags::BackwardsBranching), |
| 28 | "HigherLevelConstructs" => Ok(TargetCapabilityFlags::HigherLevelConstructs), |
| 29 | "QubitReset" => Ok(TargetCapabilityFlags::QubitReset), |
| 30 | "Unrestricted" => Ok(TargetCapabilityFlags::all()), |
| 31 | _ => Err(()), |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | impl Default for TargetCapabilityFlags { |
| 37 | fn default() -> Self { |
| 38 | TargetCapabilityFlags::empty() |
| 39 | } |
| 40 | } |
| 41 | |