binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

[Question] Multi-value Return using Tuple

Open bbbshaw opened this issue 9 months ago • 3 comments

I am building a project using C API. I have some questions regarding the multi-value return.

Suppose I want to construct a function with ( i32 i32 i32) as return values.

Q1: How should I define the type for both the call expression and return type of the function itself? Should I use BinaryenTypeCreate() to construct the type for both?

Q2: If I want to set the tuple as a local variable, should I reuse the type from BinaryenTypeCreate()?

Q3: If I want to set the tuple as a global variable, should I pass the result from BinaryenTypeCreate() to BinaryenAddGlobal() as the type?

Q3: I am modifying an existing function, is there any API I can use to add an extra local variable or modify the type of an existing local variable?

bbbshaw avatar May 03 '24 00:05 bbbshaw

Q1-Q3: Yes. Types are handles to types, so you can pass them around like that.

Q4: BinaryenFunctionAddVar adds a variable. I don't think we have a method to modify an existing one atm.

kripken avatar May 08 '24 22:05 kripken

Hi,

Thanks for your reply.

I call the BinaryenModuleValidate() to validate the generated module which uses the tuple feature. It reports error like: unexpected false: Tuples are not allowed unless multivalue is enabled, on Fatal: DWARF + multivalue is not yet complet How should I fix this error?

bbbshaw avatar May 18 '24 03:05 bbbshaw

The first is fixed by enabling multivalue, see BinaryenModuleSetFeatures().

For the second, you can either remove DWARF with --strip-dwarf as part of the wasm-opt invocation, or you can use a newer Binaryen as we did actually fix that recently (last few weeks - not in a release yet, but in main).

kripken avatar May 20 '24 19:05 kripken