Skip to content

Commit

Permalink
Merge 1bd3223 into 9c3984f
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarzc authored Mar 22, 2024
2 parents 9c3984f + 1bd3223 commit 8054d99
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"compiler/qsc_parse",
"compiler/qsc_passes",
"compiler/qsc_project",
"compiler/qsc_rir",
"fuzz",
"katas",
"language_service",
Expand Down
11 changes: 11 additions & 0 deletions compiler/qsc_rir/Cargo.toml
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" }
7 changes: 7 additions & 0 deletions compiler/qsc_rir/src/lib.rs
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;
85 changes: 85 additions & 0 deletions compiler/qsc_rir/src/rir.rs
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),
}

0 comments on commit 8054d99

Please sign in to comment.