-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "qsc_rir" | ||
authors.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
version.workspace = true | ||
|
||
[dependencies] | ||
qsc_data_structures = { path = "../qsc_data_structures" } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#![warn(clippy::mod_module_files, clippy::pedantic, clippy::unwrap_used)] | ||
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)] | ||
|
||
pub mod rir; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
use qsc_data_structures::index_map::IndexMap; | ||
|
||
/// The root of the RIR. | ||
pub struct Program { | ||
pub blocks: IndexMap<BlockId, Block>, | ||
pub callables: IndexMap<CallableId, Callable>, | ||
pub entry: CallableId, | ||
} | ||
|
||
/// A unique identifier for a block in a RIR program. | ||
#[derive(Clone, Copy, Default)] | ||
pub struct BlockId(u32); | ||
|
||
/// A block is a collection of instructions. | ||
pub struct Block(pub Vec<Instruction>); | ||
|
||
/// A unique identifier for a callable in a RIR program. | ||
#[derive(Clone, Copy, Default)] | ||
pub struct CallableId(u32); | ||
|
||
/// A callable. | ||
pub struct Callable { | ||
/// The ID of the callable. | ||
pub id: CallableId, | ||
/// The name of the callable. | ||
pub name: String, | ||
/// The input type of the callable. | ||
pub input_type: Vec<Ty>, | ||
/// The output type of the callable. | ||
pub output_type: Option<Ty>, | ||
/// The callable body. | ||
/// N.B. `None` bodys represent an intrinsic. | ||
pub body: Option<BlockId>, | ||
} | ||
|
||
pub enum Instruction { | ||
Store(Variable, Value), | ||
Call(CallableId, Vec<Value>), | ||
Jump(BlockId), | ||
Branch(Value, BlockId, BlockId), | ||
Add(Value, Value), | ||
Sub(Value, Value), | ||
Mul(Value, Value), | ||
Div(Value, Value), | ||
LogicalNot(Value), | ||
LogicalAnd(Value, Value), | ||
LogicalOr(Value, Value), | ||
BitwiseNot(Value), | ||
BitwiseAnd(Value, Value), | ||
BitwiseOr(Value, Value), | ||
BitwiseXor(Value, Value), | ||
} | ||
|
||
#[derive(Clone, Copy, Default)] | ||
pub struct VariableId(u32); | ||
|
||
pub struct Variable { | ||
pub variable_id: VariableId, | ||
pub ty: Ty, | ||
} | ||
|
||
pub enum Ty { | ||
Qubit, | ||
Result, | ||
Boolean, | ||
Integer, | ||
Double, | ||
} | ||
|
||
pub enum Value { | ||
Literal(Literal), | ||
Variable(Variable), | ||
} | ||
|
||
#[derive(Clone, Copy)] | ||
pub enum Literal { | ||
Qubit(u32), | ||
Result(u32), | ||
Bool(bool), | ||
Integer(i64), | ||
Double(f64), | ||
} |