use super::common::{Instruction, Label};
use super::variable::{ParameterDirective, VariableDirective};
use crate::Spanned;
use crate::parser::Span;
use crate::r#type::{AttributeDirective, DataType, FunctionSymbol, VariableSymbol};
use serde::Serialize;
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub struct AliasFunctionDirective {
pub alias: FunctionSymbol,
pub target: FunctionSymbol,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub struct FuncFunctionDirective {
pub attributes: Vec<AttributeDirective>,
pub return_param: Option<ParameterDirective>,
pub name: FunctionSymbol,
pub params: Vec<ParameterDirective>,
pub directives: Vec<FuncFunctionHeaderDirective>,
pub body: Option<FunctionBody>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub struct EntryFunctionDirective {
pub name: FunctionSymbol,
pub params: Vec<ParameterDirective>,
pub directives: Vec<EntryFunctionHeaderDirective>,
pub body: Option<FunctionBody>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub enum FuncFunctionHeaderDirective {
NoReturn { span: Span },
Pragma { args: Vec<String>, span: Span },
AbiPreserve { value: u32, span: Span },
AbiPreserveControl { value: u32, span: Span },
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub enum EntryFunctionHeaderDirective {
MaxNReg { value: u32, span: Span },
MaxNTid { dim: FunctionDim, span: Span },
ReqNTid { dim: FunctionDim, span: Span },
MinNCtaPerSm { value: u32, span: Span },
MaxNCtaPerSm { value: u32, span: Span },
Pragma { args: Vec<String>, span: Span },
ReqNctaPerCluster { dim: FunctionDim, span: Span },
ExplicitCluster { span: Span },
MaxClusterRank { value: u32, span: Span },
BlocksAreClusters { span: Span },
}
#[derive(Debug, Clone, Default, PartialEq, Spanned, Serialize)]
pub struct FunctionBody {
pub statements: Vec<FunctionStatement>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub enum FunctionStatement {
Label {
label: Label,
span: Span,
},
Directive {
directive: StatementDirective,
span: Span,
},
Instruction {
instruction: Instruction,
span: Span,
},
Block {
statements: Vec<FunctionStatement>,
span: Span,
},
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub struct RegisterDirective {
pub ty: DataType,
pub registers: Vec<RegisterTarget>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub struct RegisterTarget {
pub name: VariableSymbol,
pub range: Option<u32>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub enum StatementDirective {
Loc {
directive: LocationDirective,
span: Span,
},
Pragma {
directive: PragmaDirective,
span: Span,
},
Section {
directive: SectionDirective,
span: Span,
},
Reg {
directive: RegisterDirective,
span: Span,
},
Local {
directive: VariableDirective,
span: Span,
},
Param {
directive: VariableDirective,
span: Span,
},
Shared {
directive: VariableDirective,
span: Span,
},
Dwarf {
directive: DwarfDirective,
span: Span,
},
BranchTargets {
directive: BranchTargetsDirective,
span: Span,
},
CallTargets {
directive: CallTargetsDirective,
span: Span,
},
CallPrototype {
directive: CallPrototypeDirective,
span: Span,
},
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub struct DwarfDirective {
pub kind: DwarfDirectiveKind,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Serialize)]
pub enum DwarfDirectiveKind {
ByteValues(Vec<u8>),
FourByteValues(Vec<u32>),
QuadValues(Vec<u64>),
FourByteLabel(Label),
QuadLabel(Label),
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub struct SectionDirective {
pub name: String,
pub entries: Vec<SectionEntry>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Serialize)]
pub enum SectionEntry {
Label { label: Label, span: Span },
Directive(StatementSectionDirectiveLine),
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub enum StatementSectionDirectiveLine {
B8 { values: Vec<i16>, span: Span },
B16 { values: Vec<i32>, span: Span },
B32Immediate { values: Vec<i64>, span: Span },
B64Immediate { values: Vec<i128>, span: Span },
B32Label { labels: Label, span: Span },
B64Label { labels: Label, span: Span },
B32LabelPlusImm { entries: (Label, i32), span: Span },
B64LabelPlusImm { entries: (Label, i64), span: Span },
B32LabelDiff { entries: (Label, Label), span: Span },
B64LabelDiff { entries: (Label, Label), span: Span },
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub struct LocationDirective {
pub file_index: u32,
pub line: u32,
pub column: u32,
pub inlined_at: Option<LocationInlinedAt>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub struct LocationInlinedAt {
pub file_index: u32,
pub line: u32,
pub column: u32,
pub function_name: FunctionSymbol,
pub label: Label,
pub label_offset: Option<i64>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub struct PragmaDirective {
pub kind: PragmaDirectiveKind,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Serialize)]
pub enum PragmaDirectiveKind {
Nounroll,
UsedBytesMask { mask: String },
EnableSmemSpilling,
Frequency { value: u32 },
Raw(String),
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub struct BranchTargetsDirective {
pub labels: Vec<Label>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub struct CallTargetsDirective {
pub targets: Vec<FunctionSymbol>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub struct CallPrototypeDirective {
pub return_param: Option<ParameterDirective>,
pub params: Vec<ParameterDirective>,
pub noreturn: bool,
pub abi_preserve: Option<u32>,
pub abi_preserve_control: Option<u32>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
pub enum FunctionDim {
X { x: u32, span: Span },
XY { x: u32, y: u32, span: Span },
XYZ { x: u32, y: u32, z: u32, span: Span },
}