1use crate::token::Span;
2
3#[derive(Debug, Clone)]
4pub struct Program {
5 pub dialect_directives: Vec<DialectDirective>,
6 pub modules: Vec<ModuleDecl>,
7}
8
9#[derive(Debug, Clone)]
10pub struct DialectDirective {
11 pub name: String,
12 pub span: Span,
13}
14
15#[derive(Debug, Clone)]
16pub struct ModuleDecl {
17 pub name: String,
18 pub functions: Vec<FuncDecl>,
19 pub span: Span,
20}
21
22#[derive(Debug, Clone)]
23pub struct FuncDecl {
24 pub name: String,
25 pub params: Vec<ParamDecl>,
26 pub returns: Vec<TypeExpr>,
27 pub body: Vec<Statement>,
28 pub span: Span,
29}
30
31#[derive(Debug, Clone)]
32pub struct ParamDecl {
33 pub name: String,
34 pub ty: TypeExpr,
35 pub span: Span,
36}
37
38#[derive(Debug, Clone)]
39pub enum Statement {
40 OpAssign(OpAssign),
41 Return(ReturnStmt),
42}
43
44#[derive(Debug, Clone)]
45pub struct OpAssign {
46 pub results: Vec<String>,
47 pub op_name: String,
48 pub operands: Vec<Operand>,
49 pub attrs: Vec<(String, AttrValue)>,
50 pub type_sig: Option<TypeSignature>,
51 pub span: Span,
52}
53
54#[derive(Debug, Clone)]
55pub struct ReturnStmt {
56 pub values: Vec<Operand>,
57 pub span: Span,
58}
59
60#[derive(Debug, Clone)]
61pub enum Operand {
62 Value(String),
63 FuncRef(String),
64 Literal(LiteralValue),
65}
66
67#[derive(Debug, Clone)]
68pub enum LiteralValue {
69 Integer(i64),
70 Float(f64),
71 Bool(bool),
72 String(String),
73}
74
75#[derive(Debug, Clone)]
76pub enum AttrValue {
77 Integer(i64),
78 Float(f64),
79 Bool(bool),
80 String(String),
81 Array(Vec<AttrValue>),
82}
83
84#[derive(Debug, Clone)]
85pub struct TypeSignature {
86 pub inputs: Vec<TypeExpr>,
87 pub outputs: Vec<TypeExpr>,
88}
89
90#[derive(Debug, Clone)]
91pub enum TypeExpr {
92 Tensor(TensorTypeExpr),
93 Qubit,
94 Bit,
95 Hamiltonian(usize),
96 Scalar(ScalarTypeExpr),
97 Void,
98 Index,
99 Function(Box<TypeSignature>),
100}
101
102#[derive(Debug, Clone)]
103pub struct TensorTypeExpr {
104 pub shape: Vec<DimExpr>,
105 pub dtype: String,
106}
107
108#[derive(Debug, Clone)]
109pub enum DimExpr {
110 Constant(usize),
111 Symbolic(String),
112 Dynamic,
113}
114
115#[derive(Debug, Clone)]
116pub struct ScalarTypeExpr {
117 pub name: String,
118}