pass records with only pointer without size

This commit is contained in:
vms 2020-07-26 21:42:39 +03:00
parent 7e1197b49b
commit a38d88a094
7 changed files with 40 additions and 15 deletions

View File

@ -31,13 +31,12 @@ impl FnArgGlueCodeGenerator for ParsedType {
| ParsedType::I32
| ParsedType::U8
| ParsedType::U16
| ParsedType::U32 => vec![WasmType::I32],
| ParsedType::U32
| ParsedType::Record(_) => vec![WasmType::I32],
ParsedType::I64 | ParsedType::U64 => vec![WasmType::I64],
ParsedType::F32 => vec![WasmType::F32],
ParsedType::F64 => vec![WasmType::F64],
ParsedType::Utf8String | ParsedType::ByteVector | ParsedType::Record(_) => {
vec![WasmType::I32, WasmType::I32]
}
ParsedType::Utf8String | ParsedType::ByteVector => vec![WasmType::I32, WasmType::I32],
}
}
}

View File

@ -110,7 +110,7 @@ fn generate_type_prolog(
GENERATED_RECORD_DESERIALIZER_PREFIX.to_string() + record_name
);
quote! {
let #generated_arg_id = #deserializer(#ptr, #size);
let #generated_arg_id = #deserializer(#ptr);
}
}
_ => panic!(

View File

@ -28,9 +28,18 @@ impl ForeignModArgGlueCodeGenerator for ParsedType {
let arg = crate::new_ident!(format!("arg_{}", arg_start_id));
match self {
ParsedType::Utf8String | ParsedType::ByteVector | ParsedType::Record(_) => {
ParsedType::Utf8String | ParsedType::ByteVector => {
quote! { #arg.as_ptr() as _, #arg.len() as _ }
}
ParsedType::Record(record_name) => {
let serializer = crate::new_ident!(
crate::token_stream_generator::GENERATED_RECORD_SERIALIZER_PREFIX.to_string()
+ record_name
);
quote! {
#serializer(#arg)
}
}
_ => quote! { arg },
}
}

View File

@ -64,10 +64,7 @@ impl ForeignModEpilogGlueCodeGenerator for Option<ParsedType> {
+ record_name
);
quote! {
#record_deserializer(
fluence::internal::get_result_ptr() as _,
fluence::internal::get_result_size() as _,
);
#record_deserializer(fluence::internal::get_result_ptr() as _)
}
}
_ => panic!(

View File

@ -99,9 +99,12 @@ fn generate_deserializer_fn(record: &fce_ast_types::AstRecordItem) -> proc_macro
return_type,
} = record.generate_deserializer(&record.name);
let record_size =
crate::utils::get_record_size(record.fields.iter().map(|ast_field| &ast_field.ty));
quote::quote! {
unsafe fn #deserializer_fn_name(offset: i32, size: i32) -> #return_type {
let raw_record: Vec<u64> = Vec::from_raw_parts(offset as _, size as _, size as _);
unsafe fn #deserializer_fn_name(offset: i32) -> #return_type {
let raw_record: Vec<u64> = Vec::from_raw_parts(offset as _, #record_size, #record_size);
#deserializer

View File

@ -118,13 +118,11 @@ impl RecordDeserializerGlueCodeGenerator for fce_ast_types::AstRecordItem {
}
ParsedType::Record(record_name) => {
let ptr_id = value_id;
let size_id = value_id + 1;
value_id += 1;
let record_deserializer =
new_ident!(GENERATED_RECORD_DESERIALIZER_PREFIX.to_string() + record_name);
quote! {
let #field = #record_deserializer(raw_record[#ptr_id] as _, raw_record[#size_id] as _);
let #field = #record_deserializer(raw_record[#ptr_id] as _);
}
}
};

View File

@ -39,3 +39,22 @@ macro_rules! prepare_global_data {
+ &$name.replace(".", "_");
};
}
pub fn get_record_size<'a>(
fields: impl Iterator<Item = &'a crate::parsed_type::ParsedType>,
) -> usize {
use crate::parsed_type::ParsedType;
let mut size = 0;
for field in fields {
let params_count = match field {
ParsedType::ByteVector | ParsedType::Utf8String => 2,
_ => 1,
};
size += std::mem::size_of::<u64>() * params_count;
}
size
}