use crate::types::GaiaType;
use gaia_types::neural::NeuralNode;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum GaiaInstruction {
Core(CoreInstruction),
Managed(ManagedInstruction),
Domain(DomainInstruction),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum CoreInstruction {
Alloca(GaiaType, usize),
Load(GaiaType),
Store(GaiaType),
Gep {
base_type: GaiaType,
indices: Vec<usize>,
},
Add(GaiaType),
Sub(GaiaType),
Mul(GaiaType),
Div(GaiaType),
Rem(GaiaType),
And(GaiaType),
Or(GaiaType),
Xor(GaiaType),
Shl(GaiaType),
Shr(GaiaType),
Neg(GaiaType),
Not(GaiaType),
Cmp(CmpCondition, GaiaType),
Cast {
from: GaiaType,
to: GaiaType,
kind: CastKind,
},
PushConstant(crate::program::GaiaConstant),
Pop,
Dup,
LoadLocal(u32, GaiaType),
StoreLocal(u32, GaiaType),
LoadArg(u32, GaiaType),
StoreArg(u32, GaiaType),
Ret,
Br(String),
BrTrue(String),
BrFalse(String),
Label(String),
Call(String, usize),
CallIndirect(usize),
New(String),
NewArray(GaiaType, bool),
LoadField(String, String),
StoreField(String, String),
LoadElement(GaiaType),
StoreElement(GaiaType),
ArrayLength,
ArrayPush,
Throw,
StructNew(String),
StructGet {
struct_name: String,
field_index: u32,
is_signed: bool,
},
StructSet {
struct_name: String,
field_index: u32,
},
ArrayNew(String),
ArrayGet {
array_name: String,
is_signed: bool,
},
ArraySet(String),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum CmpCondition {
Eq,
Ne,
Lt,
Le,
Gt,
Ge,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum CastKind {
Bitcast,
Trunc,
Zext,
Sext,
FpToUi,
FpToSi,
UiToFp,
SiToFp,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ManagedInstruction {
CallMethod {
target: String,
method: String,
signature: crate::types::GaiaSignature,
is_virtual: bool,
call_site_id: Option<u32>,
},
CallStatic {
target: String,
method: String,
signature: crate::types::GaiaSignature,
},
Box(GaiaType),
Unbox(GaiaType),
InstanceOf(GaiaType),
CheckCast(GaiaType),
Initiate(usize),
Finalize,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum DomainInstruction {
Neural(NeuralNode),
MatMul {
a_shape: Vec<usize>,
b_shape: Vec<usize>,
transpose_a: bool,
transpose_b: bool,
},
Conv2D {
stride: [usize; 2],
padding: [usize; 2],
dilation: [usize; 2],
groups: usize,
},
ElementWise(GaiaType, String),
GetThreadId(usize),
GetGroupSize(usize),
Barrier,
}