use wasm_encoder::{Function, Instruction, ValType};
use super::restore_bump;
pub(in crate::codegen::wasm_gc) struct TcpWriteLineIndices {
pub fn_type: u32,
pub fn_idx: u32,
pub string_type_idx: u32,
pub tcp_connection_type_idx: u32,
pub tcp_slot_type_idx: u32,
pub tcp_pool_type_idx: u32,
pub write_err_segment_idx: u32,
pub write_err_len: u32,
pub unknown_segment_idx: u32,
pub unknown_len: u32,
}
pub(in crate::codegen::wasm_gc) struct TcpWriteLineHelperFns {
pub parse_id_fn: u32,
pub str_to_lm_fn: u32,
pub cabi_realloc_fn: u32,
pub blocking_write_fn: u32,
pub result_ok_fn: u32,
pub result_err_fn: u32,
pub tcp_pool_global: u32,
pub bump_alloc_ptr_global: u32,
}
pub(in crate::codegen::wasm_gc) fn emit_tcp_write_line(
indices: &TcpWriteLineIndices,
helpers: &TcpWriteLineHelperFns,
) -> Function {
use wasm_encoder::{BlockType, MemArg};
let slot_ref = ValType::Ref(wasm_encoder::RefType {
nullable: true,
heap_type: wasm_encoder::HeapType::Concrete(indices.tcp_slot_type_idx),
});
let mut f = Function::new(vec![
(2u32, ValType::I32),
(1u32, slot_ref),
(5u32, ValType::I32),
]);
let l_parsed_id: u32 = 2;
let l_slot_idx: u32 = 3;
let l_slot: u32 = 4;
let l_len: u32 = 5;
let l_off: u32 = 6;
let l_retptr: u32 = 7;
let l_nl_ptr: u32 = 8;
let l_saved_alloc: u32 = 9;
let mem1_zero = MemArg {
offset: 0,
align: 0,
memory_index: 0,
};
let emit_unknown_err = |f: &mut Function| {
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(indices.unknown_len as i32));
f.instruction(&Instruction::ArrayNewData {
array_type_index: indices.string_type_idx,
array_data_index: indices.unknown_segment_idx,
});
f.instruction(&Instruction::Call(helpers.result_err_fn));
restore_bump(f, l_saved_alloc, helpers.bump_alloc_ptr_global);
f.instruction(&Instruction::Return);
};
f.instruction(&Instruction::GlobalGet(helpers.bump_alloc_ptr_global));
f.instruction(&Instruction::LocalSet(l_saved_alloc));
f.instruction(&Instruction::LocalGet(0));
f.instruction(&Instruction::StructGet {
struct_type_index: indices.tcp_connection_type_idx,
field_index: 0,
});
f.instruction(&Instruction::Call(helpers.parse_id_fn));
f.instruction(&Instruction::LocalSet(l_parsed_id));
f.instruction(&Instruction::GlobalGet(helpers.tcp_pool_global));
f.instruction(&Instruction::RefIsNull);
f.instruction(&Instruction::If(BlockType::Empty));
emit_unknown_err(&mut f);
f.instruction(&Instruction::End);
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalSet(l_slot_idx));
f.instruction(&Instruction::Block(BlockType::Empty));
f.instruction(&Instruction::Loop(BlockType::Empty));
f.instruction(&Instruction::LocalGet(l_slot_idx));
f.instruction(&Instruction::I32Const(256));
f.instruction(&Instruction::I32GeU);
f.instruction(&Instruction::If(BlockType::Empty));
emit_unknown_err(&mut f);
f.instruction(&Instruction::End);
f.instruction(&Instruction::GlobalGet(helpers.tcp_pool_global));
f.instruction(&Instruction::LocalGet(l_slot_idx));
f.instruction(&Instruction::ArrayGet(indices.tcp_pool_type_idx));
f.instruction(&Instruction::LocalSet(l_slot));
f.instruction(&Instruction::LocalGet(l_slot));
f.instruction(&Instruction::RefIsNull);
f.instruction(&Instruction::I32Eqz);
f.instruction(&Instruction::If(BlockType::Empty));
f.instruction(&Instruction::LocalGet(l_slot));
f.instruction(&Instruction::StructGet {
struct_type_index: indices.tcp_slot_type_idx,
field_index: 4, });
f.instruction(&Instruction::LocalGet(l_parsed_id));
f.instruction(&Instruction::I32Eq);
f.instruction(&Instruction::LocalGet(l_slot));
f.instruction(&Instruction::StructGet {
struct_type_index: indices.tcp_slot_type_idx,
field_index: 3, });
f.instruction(&Instruction::I32And);
f.instruction(&Instruction::BrIf(2)); f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_slot_idx));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::LocalSet(l_slot_idx));
f.instruction(&Instruction::Br(0));
f.instruction(&Instruction::End); f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(1));
f.instruction(&Instruction::Call(helpers.str_to_lm_fn));
f.instruction(&Instruction::LocalSet(l_len));
f.instruction(&Instruction::LocalGet(l_len));
f.instruction(&Instruction::I32Const(15));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::I32Const(-16));
f.instruction(&Instruction::I32And);
f.instruction(&Instruction::GlobalGet(helpers.bump_alloc_ptr_global));
f.instruction(&Instruction::I32GtU);
f.instruction(&Instruction::If(BlockType::Empty));
f.instruction(&Instruction::LocalGet(l_len));
f.instruction(&Instruction::I32Const(15));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::I32Const(-16));
f.instruction(&Instruction::I32And);
f.instruction(&Instruction::GlobalSet(helpers.bump_alloc_ptr_global));
f.instruction(&Instruction::End);
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Const(2));
f.instruction(&Instruction::Call(helpers.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_nl_ptr));
f.instruction(&Instruction::LocalGet(l_nl_ptr));
f.instruction(&Instruction::I32Const(0x0d));
f.instruction(&Instruction::I32Store8(mem1_zero));
f.instruction(&Instruction::LocalGet(l_nl_ptr));
f.instruction(&Instruction::I32Const(0x0a));
f.instruction(&Instruction::I32Store8(MemArg {
offset: 1,
align: 0,
memory_index: 0,
}));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(4));
f.instruction(&Instruction::I32Const(12));
f.instruction(&Instruction::Call(helpers.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_retptr));
let string_type_idx = indices.string_type_idx;
let write_err_segment_idx = indices.write_err_segment_idx;
let write_err_len = indices.write_err_len;
let result_err_fn = helpers.result_err_fn;
let tcp_slot_type_idx = indices.tcp_slot_type_idx;
let blocking_write_fn = helpers.blocking_write_fn;
let bump_alloc_ptr_global = helpers.bump_alloc_ptr_global;
super::super::wasip2_helpers::emit_chunked_blocking_write(
&mut f,
l_len,
l_off,
blocking_write_fn,
&|f| {
f.instruction(&Instruction::LocalGet(l_slot));
f.instruction(&Instruction::StructGet {
struct_type_index: tcp_slot_type_idx,
field_index: 2, });
},
&|f| {
f.instruction(&Instruction::LocalGet(l_retptr));
},
Some(&|f| {
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(write_err_len as i32));
f.instruction(&Instruction::ArrayNewData {
array_type_index: string_type_idx,
array_data_index: write_err_segment_idx,
});
f.instruction(&Instruction::Call(result_err_fn));
restore_bump(f, l_saved_alloc, bump_alloc_ptr_global);
f.instruction(&Instruction::Return);
}),
);
let mem1 = MemArg {
offset: 0,
align: 0,
memory_index: 0,
};
f.instruction(&Instruction::LocalGet(l_slot));
f.instruction(&Instruction::StructGet {
struct_type_index: indices.tcp_slot_type_idx,
field_index: 2, });
f.instruction(&Instruction::LocalGet(l_nl_ptr));
f.instruction(&Instruction::I32Const(2)); f.instruction(&Instruction::LocalGet(l_retptr));
f.instruction(&Instruction::Call(helpers.blocking_write_fn));
f.instruction(&Instruction::LocalGet(l_retptr));
f.instruction(&Instruction::I32Load8U(mem1));
f.instruction(&Instruction::If(wasm_encoder::BlockType::Empty));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(indices.write_err_len as i32));
f.instruction(&Instruction::ArrayNewData {
array_type_index: indices.string_type_idx,
array_data_index: indices.write_err_segment_idx,
});
f.instruction(&Instruction::Call(helpers.result_err_fn));
restore_bump(&mut f, l_saved_alloc, helpers.bump_alloc_ptr_global);
f.instruction(&Instruction::Return);
f.instruction(&Instruction::End);
f.instruction(&Instruction::Call(helpers.result_ok_fn));
restore_bump(&mut f, l_saved_alloc, helpers.bump_alloc_ptr_global);
f.instruction(&Instruction::End);
f
}
pub(in crate::codegen::wasm_gc) struct TcpReadLineIndices {
pub fn_type: u32,
pub fn_idx: u32,
pub string_type_idx: u32,
pub result_type_idx: u32,
pub tcp_connection_type_idx: u32,
pub tcp_slot_type_idx: u32,
pub tcp_pool_type_idx: u32,
pub eof_segment_idx: u32,
pub eof_len: u32,
pub unknown_segment_idx: u32,
pub unknown_len: u32,
}
pub(in crate::codegen::wasm_gc) struct TcpReadLineHelperFns {
pub parse_id_fn: u32,
pub cabi_realloc_fn: u32,
pub blocking_read_fn: u32,
pub tcp_pool_global: u32,
pub bump_alloc_ptr_global: u32,
}
pub(in crate::codegen::wasm_gc) fn emit_tcp_read_line(
indices: &TcpReadLineIndices,
helpers: &TcpReadLineHelperFns,
) -> Function {
use wasm_encoder::{BlockType, HeapType, MemArg, RefType};
let s_ref = ValType::Ref(RefType {
nullable: true,
heap_type: HeapType::Concrete(indices.string_type_idx),
});
let slot_ref = ValType::Ref(RefType {
nullable: true,
heap_type: HeapType::Concrete(indices.tcp_slot_type_idx),
});
let mut f = Function::new(vec![
(2u32, ValType::I32),
(1u32, slot_ref),
(12u32, ValType::I32),
(1u32, s_ref),
]);
let l_parsed_id: u32 = 1;
let l_slot_idx: u32 = 2;
let l_slot: u32 = 3;
let l_in_handle: u32 = 4;
let l_buf_ptr: u32 = 5;
let l_buf_cap: u32 = 6;
let l_buf_len: u32 = 7;
let l_retptr: u32 = 8;
let l_byte: u32 = 9;
let l_j: u32 = 10;
let l_data_ptr: u32 = 11;
let l_data_len: u32 = 12;
let l_should_err: u32 = 13;
let l_new_cap: u32 = 14;
let l_saved_alloc: u32 = 15;
let l_arr: u32 = 16;
let mem4_o4 = MemArg {
offset: 4,
align: 2,
memory_index: 0,
};
let mem4_o8 = MemArg {
offset: 8,
align: 2,
memory_index: 0,
};
let mem1 = MemArg {
offset: 0,
align: 0,
memory_index: 0,
};
f.instruction(&Instruction::GlobalGet(helpers.bump_alloc_ptr_global));
f.instruction(&Instruction::LocalSet(l_saved_alloc));
f.instruction(&Instruction::LocalGet(0));
f.instruction(&Instruction::StructGet {
struct_type_index: indices.tcp_connection_type_idx,
field_index: 0,
});
f.instruction(&Instruction::Call(helpers.parse_id_fn));
f.instruction(&Instruction::LocalSet(l_parsed_id));
let result_type_idx = indices.result_type_idx;
let string_type_idx = indices.string_type_idx;
let unknown_segment_idx = indices.unknown_segment_idx;
let unknown_len = indices.unknown_len;
let bump_alloc_ptr_global = helpers.bump_alloc_ptr_global;
let emit_unknown_err = |f: &mut Function| {
f.instruction(&Instruction::I32Const(0)); f.instruction(&Instruction::RefNull(HeapType::Concrete(string_type_idx)));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(unknown_len as i32));
f.instruction(&Instruction::ArrayNewData {
array_type_index: string_type_idx,
array_data_index: unknown_segment_idx,
});
f.instruction(&Instruction::StructNew(result_type_idx));
restore_bump(f, l_saved_alloc, bump_alloc_ptr_global);
f.instruction(&Instruction::Return);
};
f.instruction(&Instruction::GlobalGet(helpers.tcp_pool_global));
f.instruction(&Instruction::RefIsNull);
f.instruction(&Instruction::If(BlockType::Empty));
emit_unknown_err(&mut f);
f.instruction(&Instruction::End);
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalSet(l_slot_idx));
f.instruction(&Instruction::Block(BlockType::Empty));
f.instruction(&Instruction::Loop(BlockType::Empty));
f.instruction(&Instruction::LocalGet(l_slot_idx));
f.instruction(&Instruction::I32Const(256));
f.instruction(&Instruction::I32GeU);
f.instruction(&Instruction::If(BlockType::Empty));
emit_unknown_err(&mut f);
f.instruction(&Instruction::End);
f.instruction(&Instruction::GlobalGet(helpers.tcp_pool_global));
f.instruction(&Instruction::LocalGet(l_slot_idx));
f.instruction(&Instruction::ArrayGet(indices.tcp_pool_type_idx));
f.instruction(&Instruction::LocalSet(l_slot));
f.instruction(&Instruction::LocalGet(l_slot));
f.instruction(&Instruction::RefIsNull);
f.instruction(&Instruction::I32Eqz);
f.instruction(&Instruction::If(BlockType::Empty));
f.instruction(&Instruction::LocalGet(l_slot));
f.instruction(&Instruction::StructGet {
struct_type_index: indices.tcp_slot_type_idx,
field_index: 4, });
f.instruction(&Instruction::LocalGet(l_parsed_id));
f.instruction(&Instruction::I32Eq);
f.instruction(&Instruction::LocalGet(l_slot));
f.instruction(&Instruction::StructGet {
struct_type_index: indices.tcp_slot_type_idx,
field_index: 3, });
f.instruction(&Instruction::I32And);
f.instruction(&Instruction::BrIf(2));
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_slot_idx));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::LocalSet(l_slot_idx));
f.instruction(&Instruction::Br(0));
f.instruction(&Instruction::End); f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_slot));
f.instruction(&Instruction::StructGet {
struct_type_index: indices.tcp_slot_type_idx,
field_index: 1,
});
f.instruction(&Instruction::LocalSet(l_in_handle));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Const(256));
f.instruction(&Instruction::Call(helpers.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_buf_ptr));
f.instruction(&Instruction::I32Const(256));
f.instruction(&Instruction::LocalSet(l_buf_cap));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalSet(l_buf_len));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(4));
f.instruction(&Instruction::I32Const(12));
f.instruction(&Instruction::Call(helpers.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_retptr));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalSet(l_should_err));
f.instruction(&Instruction::Block(BlockType::Empty));
f.instruction(&Instruction::Loop(BlockType::Empty));
f.instruction(&Instruction::LocalGet(l_in_handle));
f.instruction(&Instruction::I64Const(1));
f.instruction(&Instruction::LocalGet(l_retptr));
f.instruction(&Instruction::Call(helpers.blocking_read_fn));
f.instruction(&Instruction::LocalGet(l_retptr));
f.instruction(&Instruction::I32Load8U(mem1));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Eq);
f.instruction(&Instruction::If(BlockType::Empty));
f.instruction(&Instruction::LocalGet(l_retptr));
f.instruction(&Instruction::I32Load8U(MemArg {
offset: 4,
align: 0,
memory_index: 0,
}));
f.instruction(&Instruction::I32Eqz);
f.instruction(&Instruction::If(BlockType::Empty));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::LocalSet(l_should_err));
f.instruction(&Instruction::End);
f.instruction(&Instruction::Br(2));
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_retptr));
f.instruction(&Instruction::I32Load(mem4_o4));
f.instruction(&Instruction::LocalSet(l_data_ptr));
f.instruction(&Instruction::LocalGet(l_retptr));
f.instruction(&Instruction::I32Load(mem4_o8));
f.instruction(&Instruction::LocalSet(l_data_len));
f.instruction(&Instruction::LocalGet(l_data_len));
f.instruction(&Instruction::I32Eqz);
f.instruction(&Instruction::If(BlockType::Empty));
f.instruction(&Instruction::Br(2));
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_data_ptr));
f.instruction(&Instruction::I32Load8U(mem1));
f.instruction(&Instruction::LocalSet(l_byte));
f.instruction(&Instruction::LocalGet(l_byte));
f.instruction(&Instruction::I32Const(10));
f.instruction(&Instruction::I32Eq);
f.instruction(&Instruction::If(BlockType::Empty));
f.instruction(&Instruction::I32Const(2));
f.instruction(&Instruction::LocalSet(l_should_err)); f.instruction(&Instruction::Br(2));
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_buf_len));
f.instruction(&Instruction::LocalGet(l_buf_cap));
f.instruction(&Instruction::I32GeU);
f.instruction(&Instruction::If(BlockType::Empty));
f.instruction(&Instruction::LocalGet(l_buf_cap));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Shl);
f.instruction(&Instruction::LocalSet(l_new_cap));
f.instruction(&Instruction::LocalGet(l_buf_ptr));
f.instruction(&Instruction::LocalGet(l_buf_cap));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::LocalGet(l_new_cap));
f.instruction(&Instruction::Call(helpers.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_buf_ptr));
f.instruction(&Instruction::LocalGet(l_new_cap));
f.instruction(&Instruction::LocalSet(l_buf_cap));
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_buf_ptr));
f.instruction(&Instruction::LocalGet(l_buf_len));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::LocalGet(l_byte));
f.instruction(&Instruction::I32Store8(mem1));
f.instruction(&Instruction::LocalGet(l_buf_len));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::LocalSet(l_buf_len));
f.instruction(&Instruction::Br(0));
f.instruction(&Instruction::End); f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_should_err));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Eq);
f.instruction(&Instruction::If(BlockType::Empty));
f.instruction(&Instruction::I32Const(0)); f.instruction(&Instruction::RefNull(HeapType::Concrete(
indices.string_type_idx,
)));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(indices.eof_len as i32));
f.instruction(&Instruction::ArrayNewData {
array_type_index: indices.string_type_idx,
array_data_index: indices.eof_segment_idx,
});
f.instruction(&Instruction::StructNew(indices.result_type_idx));
restore_bump(&mut f, l_saved_alloc, helpers.bump_alloc_ptr_global);
f.instruction(&Instruction::Return);
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_should_err));
f.instruction(&Instruction::I32Const(2));
f.instruction(&Instruction::I32Eq);
f.instruction(&Instruction::LocalGet(l_buf_len));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32GtU);
f.instruction(&Instruction::I32And);
f.instruction(&Instruction::If(BlockType::Empty));
f.instruction(&Instruction::LocalGet(l_buf_ptr));
f.instruction(&Instruction::LocalGet(l_buf_len));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Sub);
f.instruction(&Instruction::I32Load8U(mem1));
f.instruction(&Instruction::I32Const(13));
f.instruction(&Instruction::I32Eq);
f.instruction(&Instruction::If(BlockType::Empty));
f.instruction(&Instruction::LocalGet(l_buf_len));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Sub);
f.instruction(&Instruction::LocalSet(l_buf_len));
f.instruction(&Instruction::End);
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_buf_len));
f.instruction(&Instruction::ArrayNewDefault(indices.string_type_idx));
f.instruction(&Instruction::LocalSet(l_arr));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalSet(l_j));
f.instruction(&Instruction::Block(BlockType::Empty));
f.instruction(&Instruction::Loop(BlockType::Empty));
f.instruction(&Instruction::LocalGet(l_j));
f.instruction(&Instruction::LocalGet(l_buf_len));
f.instruction(&Instruction::I32GeU);
f.instruction(&Instruction::BrIf(1));
f.instruction(&Instruction::LocalGet(l_arr));
f.instruction(&Instruction::LocalGet(l_j));
f.instruction(&Instruction::LocalGet(l_buf_ptr));
f.instruction(&Instruction::LocalGet(l_j));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::I32Load8U(mem1));
f.instruction(&Instruction::ArraySet(indices.string_type_idx));
f.instruction(&Instruction::LocalGet(l_j));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::LocalSet(l_j));
f.instruction(&Instruction::Br(0));
f.instruction(&Instruction::End); f.instruction(&Instruction::End);
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::LocalGet(l_arr));
f.instruction(&Instruction::RefNull(HeapType::Concrete(
indices.string_type_idx,
)));
f.instruction(&Instruction::StructNew(indices.result_type_idx));
restore_bump(&mut f, l_saved_alloc, helpers.bump_alloc_ptr_global);
f.instruction(&Instruction::End);
f
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn read_line_emit_compiles() {
let indices = TcpReadLineIndices {
fn_type: 0,
fn_idx: 0,
string_type_idx: 1,
result_type_idx: 2,
tcp_connection_type_idx: 3,
tcp_slot_type_idx: 4,
tcp_pool_type_idx: 5,
eof_segment_idx: 6,
eof_len: b"tcp: eof".len() as u32,
unknown_segment_idx: 7,
unknown_len: b"tcp: unknown connection".len() as u32,
};
let helpers = TcpReadLineHelperFns {
parse_id_fn: 7,
cabi_realloc_fn: 8,
blocking_read_fn: 9,
tcp_pool_global: 0,
bump_alloc_ptr_global: 1,
};
let _f = emit_tcp_read_line(&indices, &helpers);
}
#[test]
fn write_line_emit_compiles() {
let indices = TcpWriteLineIndices {
fn_type: 0,
fn_idx: 0,
string_type_idx: 1,
tcp_connection_type_idx: 2,
tcp_slot_type_idx: 3,
tcp_pool_type_idx: 4,
write_err_segment_idx: 5,
write_err_len: b"tcp: write failed".len() as u32,
unknown_segment_idx: 6,
unknown_len: b"tcp: unknown connection".len() as u32,
};
let helpers = TcpWriteLineHelperFns {
parse_id_fn: 6,
str_to_lm_fn: 7,
cabi_realloc_fn: 8,
blocking_write_fn: 9,
result_ok_fn: 10,
result_err_fn: 11,
tcp_pool_global: 0,
bump_alloc_ptr_global: 1,
};
let _f = emit_tcp_write_line(&indices, &helpers);
}
}