use wasm_encoder::{Function, ValType};
pub(super) struct ServerHandlerIndices {
#[allow(dead_code)]
pub fn_type: u32,
#[allow(dead_code)]
pub fn_idx: u32,
pub string_type_idx: u32,
pub http_request_type_idx: u32,
pub http_response_type_idx: u32,
pub headers_keys_array_type_idx: u32,
pub headers_values_array_type_idx: u32,
pub headers_map_type_idx: u32,
pub list_string_type_idx: u32,
pub option_list_string_type_idx: u32,
}
pub(super) struct ServerHandlerHelperFns {
pub cabi_realloc_fn: u32,
pub str_to_lm_fn: u32,
pub from_lm_fn: u32,
pub incoming_request_method_fn: u32,
pub incoming_request_path_with_query_fn: u32,
pub incoming_request_headers_fn: u32,
pub incoming_request_consume_fn: u32,
pub drop_incoming_request_fn: u32,
pub fields_entries_fn: u32,
pub drop_fields_fn: u32,
pub incoming_body_stream_fn: u32,
pub incoming_body_finish_fn: u32,
pub drop_incoming_body_fn: u32,
pub blocking_read_fn: u32,
pub drop_input_stream_fn: u32,
pub drop_future_trailers_fn: u32,
pub fields_new_fn: u32,
pub fields_append_fn: u32,
pub outgoing_response_new_fn: u32,
pub set_status_code_fn: u32,
pub outgoing_response_body_fn: u32,
pub outgoing_body_write_fn: u32,
pub outgoing_body_finish_fn: u32,
pub blocking_write_fn: u32,
pub drop_output_stream_fn: u32,
pub drop_outgoing_body_fn: u32,
pub response_outparam_set_fn: u32,
pub map_set_fn: u32,
pub map_get_fn: u32,
pub user_handler_fn: u32,
}
const INITIAL_CAP: i32 = 16384;
const METHOD_NAMES: &[&[u8]] = &[
b"GET", b"HEAD", b"POST", b"PUT", b"DELETE", b"CONNECT", b"OPTIONS", b"TRACE", b"PATCH",
];
pub(super) fn emit_aver_http_handle(
indices: &ServerHandlerIndices,
h: &ServerHandlerHelperFns,
) -> Function {
use wasm_encoder::{BlockType, HeapType, Instruction, MemArg, RefType};
let string_idx = indices.string_type_idx;
let req_idx = indices.http_request_type_idx;
let resp_idx = indices.http_response_type_idx;
let keys_arr_idx = indices.headers_keys_array_type_idx;
let values_arr_idx = indices.headers_values_array_type_idx;
let map_idx = indices.headers_map_type_idx;
let list_str_idx = indices.list_string_type_idx;
let opt_list_str_idx = indices.option_list_string_type_idx;
let s_ref = ValType::Ref(RefType {
nullable: true,
heap_type: HeapType::Concrete(string_idx),
});
let req_ref = ValType::Ref(RefType {
nullable: true,
heap_type: HeapType::Concrete(req_idx),
});
let resp_ref = ValType::Ref(RefType {
nullable: true,
heap_type: HeapType::Concrete(resp_idx),
});
let map_ref = ValType::Ref(RefType {
nullable: true,
heap_type: HeapType::Concrete(map_idx),
});
let keys_arr_ref = ValType::Ref(RefType {
nullable: true,
heap_type: HeapType::Concrete(keys_arr_idx),
});
let values_arr_ref = ValType::Ref(RefType {
nullable: true,
heap_type: HeapType::Concrete(values_arr_idx),
});
let list_str_ref = ValType::Ref(RefType {
nullable: true,
heap_type: HeapType::Concrete(list_str_idx),
});
let opt_list_str_ref = ValType::Ref(RefType {
nullable: true,
heap_type: HeapType::Concrete(opt_list_str_idx),
});
let i32_count = 52u32 - 2; let mut f = Function::new([
(i32_count, ValType::I32),
(8, s_ref),
(1, keys_arr_ref),
(1, values_arr_ref),
(1, list_str_ref),
(2, map_ref),
(1, opt_list_str_ref),
(1, list_str_ref),
(1, req_ref),
(1, resp_ref),
]);
let p_req = 0u32;
let p_outparam = 1u32;
let l_retptr_method = 2u32;
let l_retptr_path = 3u32;
let l_method_disc = 4u32;
let l_path_opt_tag = 5u32;
let l_url_ptr = 6u32;
let l_url_len = 7u32;
let l_q_pos = 8u32;
let l_path_len = 9u32;
let l_query_len = 10u32;
let l_body_buf = 11u32;
let l_body_cap = 12u32;
let l_body_len = 13u32;
let l_data_ptr = 14u32;
let l_data_len = 15u32;
let l_retptr_read = 16u32;
let l_new_cap = 17u32;
let l_k = 18u32;
let l_req_fields = 19u32;
let l_retptr_entries = 20u32;
let l_entries_ptr = 21u32;
let l_entries_len = 22u32;
let l_h_idx = 23u32;
let l_h_entry_addr = 24u32;
let l_h_name_ptr = 25u32;
let l_h_name_len = 26u32;
let l_h_val_ptr = 27u32;
let l_h_val_len = 28u32;
let l_retptr_consume = 29u32;
let l_body_handle = 30u32;
let l_retptr_stream = 31u32;
let l_stream = 32u32;
let l_trailers = 33u32;
let l_out_fields = 34u32;
let l_ob_retptr_4 = 35u32;
let l_uh_idx = 36u32;
let l_uh_cap = 37u32;
let l_uh_key_len = 38u32;
let l_uh_val_len = 39u32;
let l_uh_key_buf = 40u32;
let l_cl_body_len = 41u32;
let l_cl_buf = 42u32;
let l_cl_pos = 43u32;
let l_cl_n = 44u32;
let l_out_response = 45u32;
let l_ob_retptr = 46u32;
let l_ob_handle = 47u32;
let l_ob_stream = 48u32;
let l_ob_finish_retptr = 49u32;
let l_ob_body_len = 50u32;
let l_ob_off = 51u32;
let l_method_str = 52u32;
let l_path_str = 53u32;
let l_query_str = 54u32;
let l_body_str = 55u32;
let l_h_name_str = 56u32;
let l_h_val_str = 57u32;
let l_uh_key = 58u32;
let l_uh_val = 59u32;
let l_uh_keys = 60u32;
let l_uh_values = 61u32;
let l_uh_node = 62u32;
let l_req_headers_map = 63u32;
let l_resp_headers_map = 64u32;
let l_h_opt = 65u32;
let l_h_tail = 66u32;
let l_req_struct = 67u32;
let l_resp_struct = 68u32;
let mem1 = MemArg {
offset: 0,
align: 0,
memory_index: 0,
};
let mem1_o4 = MemArg {
offset: 4,
align: 0,
memory_index: 0,
};
let mem4 = MemArg {
offset: 0,
align: 2,
memory_index: 0,
};
let mem4_o4 = MemArg {
offset: 4,
align: 2,
memory_index: 0,
};
let mem4_o8 = MemArg {
offset: 8,
align: 2,
memory_index: 0,
};
let push_static_str = |f: &mut Function, bytes: &[u8]| {
f.instruction(&Instruction::I32Const(bytes.len() as i32));
f.instruction(&Instruction::ArrayNewDefault(string_idx));
for (i, b) in bytes.iter().enumerate() {
f.instruction(&Instruction::LocalTee(l_method_str));
f.instruction(&Instruction::I32Const(i as i32));
f.instruction(&Instruction::I32Const(*b as i32));
f.instruction(&Instruction::ArraySet(string_idx));
f.instruction(&Instruction::LocalGet(l_method_str));
}
if bytes.is_empty() {
}
};
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(4));
f.instruction(&Instruction::I32Const(12));
f.instruction(&Instruction::Call(h.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_retptr_method));
f.instruction(&Instruction::LocalGet(p_req));
f.instruction(&Instruction::LocalGet(l_retptr_method));
f.instruction(&Instruction::Call(h.incoming_request_method_fn));
f.instruction(&Instruction::LocalGet(l_retptr_method));
f.instruction(&Instruction::I32Load8U(mem1));
f.instruction(&Instruction::LocalSet(l_method_disc));
for (disc, name) in METHOD_NAMES.iter().enumerate() {
f.instruction(&Instruction::LocalGet(l_method_disc));
f.instruction(&Instruction::I32Const(disc as i32));
f.instruction(&Instruction::I32Eq);
f.instruction(&Instruction::If(BlockType::Empty));
push_static_str(&mut f, name);
f.instruction(&Instruction::LocalSet(l_method_str));
f.instruction(&Instruction::End);
}
f.instruction(&Instruction::LocalGet(l_method_disc));
f.instruction(&Instruction::I32Const(9));
f.instruction(&Instruction::I32Eq);
f.instruction(&Instruction::If(BlockType::Empty));
{
let str_ptr_l = l_data_ptr; let str_len_l = l_data_len;
f.instruction(&Instruction::LocalGet(l_retptr_method));
f.instruction(&Instruction::I32Load(mem4_o4));
f.instruction(&Instruction::LocalSet(str_ptr_l));
f.instruction(&Instruction::LocalGet(l_retptr_method));
f.instruction(&Instruction::I32Load(mem4_o8));
f.instruction(&Instruction::LocalSet(str_len_l));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalGet(str_ptr_l));
f.instruction(&Instruction::LocalGet(str_len_l));
f.instruction(&Instruction::MemoryCopy {
src_mem: 0,
dst_mem: 0,
});
f.instruction(&Instruction::LocalGet(str_len_l));
f.instruction(&Instruction::Call(h.from_lm_fn));
f.instruction(&Instruction::LocalSet(l_method_str));
}
f.instruction(&Instruction::End);
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(4));
f.instruction(&Instruction::I32Const(12));
f.instruction(&Instruction::Call(h.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_retptr_path));
f.instruction(&Instruction::LocalGet(p_req));
f.instruction(&Instruction::LocalGet(l_retptr_path));
f.instruction(&Instruction::Call(h.incoming_request_path_with_query_fn));
f.instruction(&Instruction::LocalGet(l_retptr_path));
f.instruction(&Instruction::I32Load8U(mem1));
f.instruction(&Instruction::LocalSet(l_path_opt_tag));
f.instruction(&Instruction::LocalGet(l_path_opt_tag));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Eq);
f.instruction(&Instruction::If(BlockType::Empty));
{
f.instruction(&Instruction::LocalGet(l_retptr_path));
f.instruction(&Instruction::I32Load(mem4_o4));
f.instruction(&Instruction::LocalSet(l_url_ptr));
f.instruction(&Instruction::LocalGet(l_retptr_path));
f.instruction(&Instruction::I32Load(mem4_o8));
f.instruction(&Instruction::LocalSet(l_url_len));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalGet(l_url_ptr));
f.instruction(&Instruction::LocalGet(l_url_len));
f.instruction(&Instruction::MemoryCopy {
src_mem: 0,
dst_mem: 0,
});
f.instruction(&Instruction::LocalGet(l_url_len));
f.instruction(&Instruction::LocalSet(l_q_pos));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalSet(l_k));
f.instruction(&Instruction::Block(BlockType::Empty));
f.instruction(&Instruction::Loop(BlockType::Empty));
{
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::LocalGet(l_url_len));
f.instruction(&Instruction::I32GeU);
f.instruction(&Instruction::BrIf(1));
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::I32Load8U(mem1));
f.instruction(&Instruction::I32Const(b'?' as i32));
f.instruction(&Instruction::I32Eq);
f.instruction(&Instruction::If(BlockType::Empty));
{
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::LocalSet(l_q_pos));
f.instruction(&Instruction::Br(2)); }
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::LocalSet(l_k));
f.instruction(&Instruction::Br(0));
}
f.instruction(&Instruction::End);
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_q_pos));
f.instruction(&Instruction::LocalSet(l_path_len));
f.instruction(&Instruction::LocalGet(l_url_len));
f.instruction(&Instruction::LocalGet(l_q_pos));
f.instruction(&Instruction::I32GtU);
f.instruction(&Instruction::If(BlockType::Empty));
{
f.instruction(&Instruction::LocalGet(l_url_len));
f.instruction(&Instruction::LocalGet(l_q_pos));
f.instruction(&Instruction::I32Sub);
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Sub);
f.instruction(&Instruction::LocalSet(l_query_len));
}
f.instruction(&Instruction::Else);
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalSet(l_query_len));
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_path_len));
f.instruction(&Instruction::ArrayNewDefault(string_idx));
f.instruction(&Instruction::LocalSet(l_path_str));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalSet(l_k));
f.instruction(&Instruction::Block(BlockType::Empty));
f.instruction(&Instruction::Loop(BlockType::Empty));
{
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::LocalGet(l_path_len));
f.instruction(&Instruction::I32GeU);
f.instruction(&Instruction::BrIf(1));
f.instruction(&Instruction::LocalGet(l_path_str));
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::I32Load8U(mem1));
f.instruction(&Instruction::ArraySet(string_idx));
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::LocalSet(l_k));
f.instruction(&Instruction::Br(0));
}
f.instruction(&Instruction::End);
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_query_len));
f.instruction(&Instruction::ArrayNewDefault(string_idx));
f.instruction(&Instruction::LocalSet(l_query_str));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalSet(l_k));
f.instruction(&Instruction::Block(BlockType::Empty));
f.instruction(&Instruction::Loop(BlockType::Empty));
{
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::LocalGet(l_query_len));
f.instruction(&Instruction::I32GeU);
f.instruction(&Instruction::BrIf(1));
f.instruction(&Instruction::LocalGet(l_query_str));
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::LocalGet(l_q_pos));
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::I32Load8U(mem1));
f.instruction(&Instruction::ArraySet(string_idx));
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::LocalSet(l_k));
f.instruction(&Instruction::Br(0));
}
f.instruction(&Instruction::End);
f.instruction(&Instruction::End);
}
f.instruction(&Instruction::Else);
{
push_static_str(&mut f, b"/");
f.instruction(&Instruction::LocalSet(l_path_str));
push_static_str(&mut f, b"");
f.instruction(&Instruction::LocalSet(l_query_str));
}
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(p_req));
f.instruction(&Instruction::Call(h.incoming_request_headers_fn));
f.instruction(&Instruction::LocalSet(l_req_fields));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(INITIAL_CAP));
f.instruction(&Instruction::I32Const(INITIAL_CAP));
f.instruction(&Instruction::ArrayNewDefault(keys_arr_idx));
f.instruction(&Instruction::I32Const(INITIAL_CAP));
f.instruction(&Instruction::ArrayNewDefault(values_arr_idx));
f.instruction(&Instruction::StructNew(map_idx));
f.instruction(&Instruction::LocalSet(l_req_headers_map));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(4));
f.instruction(&Instruction::I32Const(8));
f.instruction(&Instruction::Call(h.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_retptr_entries));
f.instruction(&Instruction::LocalGet(l_req_fields));
f.instruction(&Instruction::LocalGet(l_retptr_entries));
f.instruction(&Instruction::Call(h.fields_entries_fn));
f.instruction(&Instruction::LocalGet(l_retptr_entries));
f.instruction(&Instruction::I32Load(mem4));
f.instruction(&Instruction::LocalSet(l_entries_ptr));
f.instruction(&Instruction::LocalGet(l_retptr_entries));
f.instruction(&Instruction::I32Load(mem4_o4));
f.instruction(&Instruction::LocalSet(l_entries_len));
f.instruction(&Instruction::LocalGet(l_entries_len));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Sub);
f.instruction(&Instruction::LocalSet(l_h_idx));
f.instruction(&Instruction::Block(BlockType::Empty));
f.instruction(&Instruction::Loop(BlockType::Empty));
{
f.instruction(&Instruction::LocalGet(l_h_idx));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32LtS);
f.instruction(&Instruction::BrIf(1));
f.instruction(&Instruction::LocalGet(l_entries_ptr));
f.instruction(&Instruction::LocalGet(l_h_idx));
f.instruction(&Instruction::I32Const(16));
f.instruction(&Instruction::I32Mul);
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::LocalSet(l_h_entry_addr));
f.instruction(&Instruction::LocalGet(l_h_entry_addr));
f.instruction(&Instruction::I32Load(mem4));
f.instruction(&Instruction::LocalSet(l_h_name_ptr));
f.instruction(&Instruction::LocalGet(l_h_entry_addr));
f.instruction(&Instruction::I32Load(mem4_o4));
f.instruction(&Instruction::LocalSet(l_h_name_len));
f.instruction(&Instruction::LocalGet(l_h_entry_addr));
f.instruction(&Instruction::I32Load(mem4_o8));
f.instruction(&Instruction::LocalSet(l_h_val_ptr));
f.instruction(&Instruction::LocalGet(l_h_entry_addr));
f.instruction(&Instruction::I32Load(MemArg {
offset: 12,
align: 2,
memory_index: 0,
}));
f.instruction(&Instruction::LocalSet(l_h_val_len));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalGet(l_h_name_ptr));
f.instruction(&Instruction::LocalGet(l_h_name_len));
f.instruction(&Instruction::MemoryCopy {
src_mem: 0,
dst_mem: 0,
});
f.instruction(&Instruction::LocalGet(l_h_name_len));
f.instruction(&Instruction::Call(h.from_lm_fn));
f.instruction(&Instruction::LocalSet(l_h_name_str));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalGet(l_h_val_ptr));
f.instruction(&Instruction::LocalGet(l_h_val_len));
f.instruction(&Instruction::MemoryCopy {
src_mem: 0,
dst_mem: 0,
});
f.instruction(&Instruction::LocalGet(l_h_val_len));
f.instruction(&Instruction::Call(h.from_lm_fn));
f.instruction(&Instruction::LocalSet(l_h_val_str));
f.instruction(&Instruction::LocalGet(l_req_headers_map));
f.instruction(&Instruction::LocalGet(l_h_name_str));
f.instruction(&Instruction::Call(h.map_get_fn));
f.instruction(&Instruction::LocalSet(l_h_opt));
f.instruction(&Instruction::LocalGet(l_h_opt));
f.instruction(&Instruction::StructGet {
struct_type_index: opt_list_str_idx,
field_index: 0,
});
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Eq);
f.instruction(&Instruction::If(BlockType::Result(list_str_ref)));
{
f.instruction(&Instruction::LocalGet(l_h_opt));
f.instruction(&Instruction::StructGet {
struct_type_index: opt_list_str_idx,
field_index: 1,
});
}
f.instruction(&Instruction::Else);
f.instruction(&Instruction::RefNull(HeapType::Concrete(list_str_idx)));
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalSet(l_h_tail));
f.instruction(&Instruction::LocalGet(l_h_val_str));
f.instruction(&Instruction::LocalGet(l_h_tail));
f.instruction(&Instruction::StructNew(list_str_idx));
f.instruction(&Instruction::LocalSet(l_h_tail)); f.instruction(&Instruction::LocalGet(l_req_headers_map));
f.instruction(&Instruction::LocalGet(l_h_name_str));
f.instruction(&Instruction::LocalGet(l_h_tail));
f.instruction(&Instruction::Call(h.map_set_fn));
f.instruction(&Instruction::LocalSet(l_req_headers_map));
f.instruction(&Instruction::LocalGet(l_h_idx));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Sub);
f.instruction(&Instruction::LocalSet(l_h_idx));
f.instruction(&Instruction::Br(0));
}
f.instruction(&Instruction::End); f.instruction(&Instruction::End);
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(4));
f.instruction(&Instruction::I32Const(8));
f.instruction(&Instruction::Call(h.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_retptr_consume));
f.instruction(&Instruction::LocalGet(p_req));
f.instruction(&Instruction::LocalGet(l_retptr_consume));
f.instruction(&Instruction::Call(h.incoming_request_consume_fn));
f.instruction(&Instruction::LocalGet(l_retptr_consume));
f.instruction(&Instruction::I32Load8U(mem1));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Ne);
f.instruction(&Instruction::If(BlockType::Empty));
f.instruction(&Instruction::Unreachable);
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_retptr_consume));
f.instruction(&Instruction::I32Load(mem4_o4));
f.instruction(&Instruction::LocalSet(l_body_handle));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(4));
f.instruction(&Instruction::I32Const(8));
f.instruction(&Instruction::Call(h.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_retptr_stream));
f.instruction(&Instruction::LocalGet(l_body_handle));
f.instruction(&Instruction::LocalGet(l_retptr_stream));
f.instruction(&Instruction::Call(h.incoming_body_stream_fn));
f.instruction(&Instruction::LocalGet(l_retptr_stream));
f.instruction(&Instruction::I32Load8U(mem1));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Ne);
f.instruction(&Instruction::If(BlockType::Empty));
f.instruction(&Instruction::Unreachable);
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_retptr_stream));
f.instruction(&Instruction::I32Load(mem4_o4));
f.instruction(&Instruction::LocalSet(l_stream));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Const(4096));
f.instruction(&Instruction::Call(h.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_body_buf));
f.instruction(&Instruction::I32Const(4096));
f.instruction(&Instruction::LocalSet(l_body_cap));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalSet(l_body_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(h.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_retptr_read));
f.instruction(&Instruction::Block(BlockType::Empty));
f.instruction(&Instruction::Loop(BlockType::Empty));
f.instruction(&Instruction::LocalGet(l_stream));
f.instruction(&Instruction::I64Const(4096));
f.instruction(&Instruction::LocalGet(l_retptr_read));
f.instruction(&Instruction::Call(h.blocking_read_fn));
f.instruction(&Instruction::LocalGet(l_retptr_read));
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_read));
f.instruction(&Instruction::I32Load8U(mem1_o4));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Eq);
f.instruction(&Instruction::If(BlockType::Empty));
f.instruction(&Instruction::Br(3));
f.instruction(&Instruction::End);
f.instruction(&Instruction::Unreachable);
}
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_retptr_read));
f.instruction(&Instruction::I32Load(mem4_o4));
f.instruction(&Instruction::LocalSet(l_data_ptr));
f.instruction(&Instruction::LocalGet(l_retptr_read));
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::BrIf(1));
f.instruction(&Instruction::LocalGet(l_body_cap));
f.instruction(&Instruction::LocalSet(l_new_cap));
f.instruction(&Instruction::Block(BlockType::Empty));
f.instruction(&Instruction::Loop(BlockType::Empty));
f.instruction(&Instruction::LocalGet(l_new_cap));
f.instruction(&Instruction::LocalGet(l_body_len));
f.instruction(&Instruction::LocalGet(l_data_len));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::I32GeU);
f.instruction(&Instruction::BrIf(1));
f.instruction(&Instruction::LocalGet(l_new_cap));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Shl);
f.instruction(&Instruction::LocalSet(l_new_cap));
f.instruction(&Instruction::Br(0));
f.instruction(&Instruction::End);
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_new_cap));
f.instruction(&Instruction::LocalGet(l_body_cap));
f.instruction(&Instruction::I32GtU);
f.instruction(&Instruction::If(BlockType::Empty));
{
f.instruction(&Instruction::LocalGet(l_body_buf));
f.instruction(&Instruction::LocalGet(l_body_cap));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::LocalGet(l_new_cap));
f.instruction(&Instruction::Call(h.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_body_buf));
f.instruction(&Instruction::LocalGet(l_new_cap));
f.instruction(&Instruction::LocalSet(l_body_cap));
}
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_body_buf));
f.instruction(&Instruction::LocalGet(l_body_len));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::LocalGet(l_data_ptr));
f.instruction(&Instruction::LocalGet(l_data_len));
f.instruction(&Instruction::MemoryCopy {
src_mem: 0,
dst_mem: 0,
});
f.instruction(&Instruction::LocalGet(l_body_len));
f.instruction(&Instruction::LocalGet(l_data_len));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::LocalSet(l_body_len));
f.instruction(&Instruction::Br(0));
f.instruction(&Instruction::End); f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_stream));
f.instruction(&Instruction::Call(h.drop_input_stream_fn));
f.instruction(&Instruction::LocalGet(l_body_handle));
f.instruction(&Instruction::Call(h.incoming_body_finish_fn));
f.instruction(&Instruction::LocalSet(l_trailers));
f.instruction(&Instruction::LocalGet(l_trailers));
f.instruction(&Instruction::Call(h.drop_future_trailers_fn));
f.instruction(&Instruction::LocalGet(l_req_fields));
f.instruction(&Instruction::Call(h.drop_fields_fn));
let _ = h.drop_incoming_body_fn;
f.instruction(&Instruction::LocalGet(l_body_len));
f.instruction(&Instruction::ArrayNewDefault(string_idx));
f.instruction(&Instruction::LocalSet(l_body_str));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalSet(l_k));
f.instruction(&Instruction::Block(BlockType::Empty));
f.instruction(&Instruction::Loop(BlockType::Empty));
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::LocalGet(l_body_len));
f.instruction(&Instruction::I32GeU);
f.instruction(&Instruction::BrIf(1));
f.instruction(&Instruction::LocalGet(l_body_str));
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::LocalGet(l_body_buf));
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::I32Load8U(mem1));
f.instruction(&Instruction::ArraySet(string_idx));
f.instruction(&Instruction::LocalGet(l_k));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::LocalSet(l_k));
f.instruction(&Instruction::Br(0));
f.instruction(&Instruction::End);
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_method_str));
f.instruction(&Instruction::LocalGet(l_path_str));
f.instruction(&Instruction::LocalGet(l_query_str));
f.instruction(&Instruction::LocalGet(l_body_str));
f.instruction(&Instruction::LocalGet(l_req_headers_map));
f.instruction(&Instruction::StructNew(req_idx));
f.instruction(&Instruction::LocalSet(l_req_struct));
f.instruction(&Instruction::LocalGet(l_req_struct));
f.instruction(&Instruction::Call(h.user_handler_fn));
f.instruction(&Instruction::LocalSet(l_resp_struct));
f.instruction(&Instruction::LocalGet(l_resp_struct));
f.instruction(&Instruction::StructGet {
struct_type_index: resp_idx,
field_index: 0, });
f.instruction(&Instruction::I32WrapI64);
f.instruction(&Instruction::LocalSet(l_ob_off));
f.instruction(&Instruction::LocalGet(l_resp_struct));
f.instruction(&Instruction::StructGet {
struct_type_index: resp_idx,
field_index: 2, });
f.instruction(&Instruction::LocalSet(l_resp_headers_map));
f.instruction(&Instruction::Call(h.fields_new_fn));
f.instruction(&Instruction::LocalSet(l_out_fields));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(4));
f.instruction(&Instruction::I32Const(4));
f.instruction(&Instruction::Call(h.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_ob_retptr_4));
{
f.instruction(&Instruction::LocalGet(l_resp_struct));
f.instruction(&Instruction::StructGet {
struct_type_index: resp_idx,
field_index: 1, });
f.instruction(&Instruction::ArrayLen);
f.instruction(&Instruction::LocalSet(l_cl_body_len));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Const(16));
f.instruction(&Instruction::Call(h.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_cl_buf));
f.instruction(&Instruction::LocalGet(l_cl_buf));
f.instruction(&Instruction::I32Const(16));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::LocalSet(l_cl_pos));
f.instruction(&Instruction::LocalGet(l_cl_body_len));
f.instruction(&Instruction::LocalSet(l_cl_n));
f.instruction(&Instruction::Loop(BlockType::Empty));
{
f.instruction(&Instruction::LocalGet(l_cl_pos));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Sub);
f.instruction(&Instruction::LocalSet(l_cl_pos));
f.instruction(&Instruction::LocalGet(l_cl_pos));
f.instruction(&Instruction::LocalGet(l_cl_n));
f.instruction(&Instruction::I32Const(10));
f.instruction(&Instruction::I32RemU);
f.instruction(&Instruction::I32Const(b'0' as i32));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::I32Store8(mem1));
f.instruction(&Instruction::LocalGet(l_cl_n));
f.instruction(&Instruction::I32Const(10));
f.instruction(&Instruction::I32DivU);
f.instruction(&Instruction::LocalSet(l_cl_n));
f.instruction(&Instruction::LocalGet(l_cl_n));
f.instruction(&Instruction::BrIf(0));
}
f.instruction(&Instruction::End);
for (i, b) in b"Content-Length".iter().enumerate() {
f.instruction(&Instruction::I32Const(i as i32));
f.instruction(&Instruction::I32Const(*b as i32));
f.instruction(&Instruction::I32Store8(mem1));
}
f.instruction(&Instruction::LocalGet(l_out_fields));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(14));
f.instruction(&Instruction::LocalGet(l_cl_pos));
f.instruction(&Instruction::LocalGet(l_cl_buf));
f.instruction(&Instruction::I32Const(16));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::LocalGet(l_cl_pos));
f.instruction(&Instruction::I32Sub);
f.instruction(&Instruction::LocalGet(l_ob_retptr_4));
f.instruction(&Instruction::Call(h.fields_append_fn));
}
f.instruction(&Instruction::LocalGet(l_resp_headers_map));
f.instruction(&Instruction::StructGet {
struct_type_index: map_idx,
field_index: 1, });
f.instruction(&Instruction::LocalSet(l_uh_cap));
f.instruction(&Instruction::LocalGet(l_resp_headers_map));
f.instruction(&Instruction::StructGet {
struct_type_index: map_idx,
field_index: 2, });
f.instruction(&Instruction::LocalSet(l_uh_keys));
f.instruction(&Instruction::LocalGet(l_resp_headers_map));
f.instruction(&Instruction::StructGet {
struct_type_index: map_idx,
field_index: 3, });
f.instruction(&Instruction::LocalSet(l_uh_values));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalSet(l_uh_idx));
f.instruction(&Instruction::Block(BlockType::Empty));
f.instruction(&Instruction::Loop(BlockType::Empty));
{
f.instruction(&Instruction::LocalGet(l_uh_idx));
f.instruction(&Instruction::LocalGet(l_uh_cap));
f.instruction(&Instruction::I32GeU);
f.instruction(&Instruction::BrIf(1));
f.instruction(&Instruction::LocalGet(l_uh_keys));
f.instruction(&Instruction::LocalGet(l_uh_idx));
f.instruction(&Instruction::ArrayGet(keys_arr_idx));
f.instruction(&Instruction::LocalSet(l_uh_key));
f.instruction(&Instruction::LocalGet(l_uh_key));
f.instruction(&Instruction::RefIsNull);
f.instruction(&Instruction::I32Eqz);
f.instruction(&Instruction::If(BlockType::Empty));
{
f.instruction(&Instruction::LocalGet(l_uh_values));
f.instruction(&Instruction::LocalGet(l_uh_idx));
f.instruction(&Instruction::ArrayGet(values_arr_idx));
f.instruction(&Instruction::LocalSet(l_uh_node));
f.instruction(&Instruction::Block(BlockType::Empty));
f.instruction(&Instruction::Loop(BlockType::Empty));
{
f.instruction(&Instruction::LocalGet(l_uh_node));
f.instruction(&Instruction::RefIsNull);
f.instruction(&Instruction::BrIf(1));
f.instruction(&Instruction::LocalGet(l_uh_node));
f.instruction(&Instruction::StructGet {
struct_type_index: list_str_idx,
field_index: 0,
});
f.instruction(&Instruction::LocalSet(l_uh_val));
f.instruction(&Instruction::LocalGet(l_uh_key));
f.instruction(&Instruction::Call(h.str_to_lm_fn));
f.instruction(&Instruction::LocalSet(l_uh_key_len));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::LocalGet(l_uh_key_len));
f.instruction(&Instruction::Call(h.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_uh_key_buf));
f.instruction(&Instruction::LocalGet(l_uh_key_buf));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalGet(l_uh_key_len));
f.instruction(&Instruction::MemoryCopy {
src_mem: 0,
dst_mem: 0,
});
f.instruction(&Instruction::LocalGet(l_uh_val));
f.instruction(&Instruction::Call(h.str_to_lm_fn));
f.instruction(&Instruction::LocalSet(l_uh_val_len));
f.instruction(&Instruction::LocalGet(l_out_fields));
f.instruction(&Instruction::LocalGet(l_uh_key_buf));
f.instruction(&Instruction::LocalGet(l_uh_key_len));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::LocalGet(l_uh_val_len));
f.instruction(&Instruction::LocalGet(l_ob_retptr_4));
f.instruction(&Instruction::Call(h.fields_append_fn));
f.instruction(&Instruction::LocalGet(l_uh_node));
f.instruction(&Instruction::StructGet {
struct_type_index: list_str_idx,
field_index: 1,
});
f.instruction(&Instruction::LocalSet(l_uh_node));
f.instruction(&Instruction::Br(0));
}
f.instruction(&Instruction::End);
f.instruction(&Instruction::End);
}
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_uh_idx));
f.instruction(&Instruction::I32Const(1));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::LocalSet(l_uh_idx));
f.instruction(&Instruction::Br(0));
}
f.instruction(&Instruction::End);
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_out_fields));
f.instruction(&Instruction::Call(h.outgoing_response_new_fn));
f.instruction(&Instruction::LocalSet(l_out_response));
f.instruction(&Instruction::LocalGet(l_out_response));
f.instruction(&Instruction::LocalGet(l_ob_off)); f.instruction(&Instruction::Call(h.set_status_code_fn));
f.instruction(&Instruction::Drop);
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(4));
f.instruction(&Instruction::I32Const(8));
f.instruction(&Instruction::Call(h.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_ob_retptr));
f.instruction(&Instruction::LocalGet(l_out_response));
f.instruction(&Instruction::LocalGet(l_ob_retptr));
f.instruction(&Instruction::Call(h.outgoing_response_body_fn));
f.instruction(&Instruction::LocalGet(l_ob_retptr));
f.instruction(&Instruction::I32Load8U(mem1));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Ne);
f.instruction(&Instruction::If(BlockType::Empty));
f.instruction(&Instruction::Unreachable);
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_ob_retptr));
f.instruction(&Instruction::I32Load(mem4_o4));
f.instruction(&Instruction::LocalSet(l_ob_handle));
f.instruction(&Instruction::LocalGet(p_outparam));
f.instruction(&Instruction::I32Const(0)); f.instruction(&Instruction::LocalGet(l_out_response));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I64Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::Call(h.response_outparam_set_fn));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(4));
f.instruction(&Instruction::I32Const(8));
f.instruction(&Instruction::Call(h.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_ob_retptr));
f.instruction(&Instruction::LocalGet(l_ob_handle));
f.instruction(&Instruction::LocalGet(l_ob_retptr));
f.instruction(&Instruction::Call(h.outgoing_body_write_fn));
f.instruction(&Instruction::LocalGet(l_ob_retptr));
f.instruction(&Instruction::I32Load8U(mem1));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Ne);
f.instruction(&Instruction::If(BlockType::Empty));
{
f.instruction(&Instruction::LocalGet(l_ob_handle));
f.instruction(&Instruction::Call(h.drop_outgoing_body_fn));
f.instruction(&Instruction::Unreachable);
}
f.instruction(&Instruction::End);
f.instruction(&Instruction::LocalGet(l_ob_retptr));
f.instruction(&Instruction::I32Load(mem4_o4));
f.instruction(&Instruction::LocalSet(l_ob_stream));
f.instruction(&Instruction::LocalGet(l_resp_struct));
f.instruction(&Instruction::StructGet {
struct_type_index: resp_idx,
field_index: 1,
});
f.instruction(&Instruction::Call(h.str_to_lm_fn));
f.instruction(&Instruction::LocalSet(l_ob_body_len));
super::wasip2_helpers::emit_chunked_blocking_write(
&mut f,
l_ob_body_len,
l_ob_off, h.blocking_write_fn,
&|f| {
f.instruction(&Instruction::LocalGet(l_ob_stream));
},
&|f| {
f.instruction(&Instruction::LocalGet(l_ob_body_len));
f.instruction(&Instruction::I32Const(15));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::I32Const(-16));
f.instruction(&Instruction::I32And);
},
None,
);
f.instruction(&Instruction::LocalGet(l_ob_stream));
f.instruction(&Instruction::Call(h.drop_output_stream_fn));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(0));
f.instruction(&Instruction::I32Const(8));
f.instruction(&Instruction::I32Const(40));
f.instruction(&Instruction::Call(h.cabi_realloc_fn));
f.instruction(&Instruction::LocalSet(l_ob_finish_retptr));
f.instruction(&Instruction::LocalGet(l_ob_handle));
f.instruction(&Instruction::I32Const(0)); f.instruction(&Instruction::I32Const(0)); f.instruction(&Instruction::LocalGet(l_ob_finish_retptr));
f.instruction(&Instruction::Call(h.outgoing_body_finish_fn));
f.instruction(&Instruction::LocalGet(p_req));
f.instruction(&Instruction::Call(h.drop_incoming_request_fn));
f.instruction(&Instruction::End);
f
}