Skip to content

Commit 2b79eb1

Browse files
Generate unsafe IO for each exported memory (#11)
1 parent 9752a8e commit 2b79eb1

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/wasm2c/initcomposer.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,17 +300,17 @@ void InitComposer::write_unsafe_io()
300300
{
301301

302302
result_ << "extern void fixpoint_unsafe_io(uint32_t index, uint32_t length, wasm_rt_memory_t* main_mem);" << endl;
303-
result_ << "void " << ExportName( "fixpoint", "unsafe_io" );
304-
result_ << "(struct w2c_fixpoint* instance, uint32_t index, uint32_t length) {" << endl;
305303

306-
// Only call fixpoint_unsafe_io if there is a memory called "memory"
307-
// Otherwise unsafe_io is a no op.
308-
if ( inspector_->ExportsMainMemory() ) {
309-
result_ << " wasm_rt_memory_t* main_mem = " << ExportName( module_prefix_, "memory" ) << "(("
310-
<< state_info_type_name_ << "*)instance);" << endl;
311-
result_ << " fixpoint_unsafe_io(index, length, main_mem);" << endl;
304+
for ( Export* export_ : current_module_->exports ) {
305+
if ( export_->kind == ExternalKind::Memory ) {
306+
result_ << "void " << ExportName( "fixpoint", export_->name + "_unsafe_io" );
307+
result_ << "(struct w2c_fixpoint* instance, uint32_t index, uint32_t length) {" << endl;
308+
result_ << " wasm_rt_memory_t* mem_instance = " << ExportName( module_prefix_, export_->name ) << "(("
309+
<< state_info_type_name_ << "*)instance);" << endl;
310+
result_ << " fixpoint_unsafe_io(index, length, mem_instance);" << endl;
311+
result_ << "}\n" << endl;
312+
}
312313
}
313-
result_ << "}\n" << endl;
314314
}
315315

316316
void InitComposer::write_get_attached_tree()

0 commit comments

Comments
 (0)