ruda_kernel/dsl/frontend/operation/
native_memory.rs1use crate::dsl::prelude::*;
2use crate::dsl::ir::{BinaryOperator, Instruction, ManagedVariable, Operator, UnaryOperator};
3
4pub fn native_address<T: RudaPrimitive>(_input: &Slice<T>, _index: usize) -> u64 {
7 crate::dsl::unexpanded!()
8}
9
10pub mod native_address {
11 use super::*;
12 pub fn expand<T: RudaPrimitive>(scope: &mut Scope, input: SliceExpand<T, ReadOnly>, index: NativeExpand<usize>) -> NativeExpand<u64> {
13 let (array, offset) = input.__to_raw_parts();
14 let index = if index.expand.ty != usize::as_type(scope) {
15 let converted = scope.create_local(usize::as_type(scope));
16 cast::expand::<usize, usize>(scope, index, converted.clone().into());
17 converted.into()
18 } else { index };
19 let index = add::expand(scope, index, NativeExpand::new(ManagedVariable::Plain(offset)));
20 let ty = u64::as_type(scope);
21 let output = scope.create_local(ty);
22 scope.register(Instruction::new(Operator::NativeAddress(BinaryOperator {
23 lhs: array, rhs: index.expand.consume(),
24 }), *output));
25 output.into()
26 }
27}
28
29pub fn native_load<T: RudaPrimitive>(_address: u64) -> T {
32 crate::dsl::unexpanded!()
33}
34
35pub mod native_load {
36 use super::*;
37 pub fn expand<T: RudaPrimitive>(scope: &mut Scope, address: NativeExpand<u64>) -> NativeExpand<T> {
38 let ty = T::as_type(scope);
39 let output = scope.create_local(ty);
40 scope.register(Instruction::new(Operator::NativeLoad(UnaryOperator { input: address.expand.consume() }), *output));
41 output.into()
42 }
43}
44
45pub fn native_store<T: RudaPrimitive>(_address: u64, _value: T) {
48 crate::dsl::unexpanded!()
49}
50
51pub mod native_store {
52 use super::*;
53 pub fn expand<T: RudaPrimitive>(scope: &mut Scope, address: NativeExpand<u64>, value: NativeExpand<T>) {
54 scope.register(Instruction::no_out(Operator::NativeStore(BinaryOperator {
55 lhs: address.expand.consume(), rhs: value.expand.consume(),
56 })));
57 }
58}