use crate::dsl::prelude::*;
use crate::dsl::ir::{BinaryOperator, Instruction, ManagedVariable, Operator, UnaryOperator};
pub fn native_address<T: RudaPrimitive>(_input: &Slice<T>, _index: usize) -> u64 {
crate::dsl::unexpanded!()
}
pub mod native_address {
use super::*;
pub fn expand<T: RudaPrimitive>(scope: &mut Scope, input: SliceExpand<T, ReadOnly>, index: NativeExpand<usize>) -> NativeExpand<u64> {
let (array, offset) = input.__to_raw_parts();
let index = if index.expand.ty != usize::as_type(scope) {
let converted = scope.create_local(usize::as_type(scope));
cast::expand::<usize, usize>(scope, index, converted.clone().into());
converted.into()
} else { index };
let index = add::expand(scope, index, NativeExpand::new(ManagedVariable::Plain(offset)));
let ty = u64::as_type(scope);
let output = scope.create_local(ty);
scope.register(Instruction::new(Operator::NativeAddress(BinaryOperator {
lhs: array, rhs: index.expand.consume(),
}), *output));
output.into()
}
}
pub fn native_load<T: RudaPrimitive>(_address: u64) -> T {
crate::dsl::unexpanded!()
}
pub mod native_load {
use super::*;
pub fn expand<T: RudaPrimitive>(scope: &mut Scope, address: NativeExpand<u64>) -> NativeExpand<T> {
let ty = T::as_type(scope);
let output = scope.create_local(ty);
scope.register(Instruction::new(Operator::NativeLoad(UnaryOperator { input: address.expand.consume() }), *output));
output.into()
}
}
pub fn native_store<T: RudaPrimitive>(_address: u64, _value: T) {
crate::dsl::unexpanded!()
}
pub mod native_store {
use super::*;
pub fn expand<T: RudaPrimitive>(scope: &mut Scope, address: NativeExpand<u64>, value: NativeExpand<T>) {
scope.register(Instruction::no_out(Operator::NativeStore(BinaryOperator {
lhs: address.expand.consume(), rhs: value.expand.consume(),
})));
}
}