MCPcopy Create free account
hub / github.com/WebAssembly/wasm-c-api / wrapper

Function wrapper

src/wasm-bin.cc:91–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89
90
91auto wrapper(const FuncType* type) -> vec<byte_t> {
92 auto in_arity = type->params().size();
93 auto out_arity = type->results().size();
94 auto size = 39 + in_arity + out_arity;
95 auto binary = vec<byte_t>::make_uninitialized(size);
96 auto ptr = binary.get();
97
98 encode_header(ptr);
99
100 *ptr++ = 0x01; // type section
101 encode_size32(ptr, 12 + in_arity + out_arity); // size
102 *ptr++ = 1; // length
103 *ptr++ = 0x60; // function
104 encode_size32(ptr, in_arity);
105 for (size_t i = 0; i < in_arity; ++i) {
106 encode_valtype(ptr, type->params()[i].get());
107 }
108 encode_size32(ptr, out_arity);
109 for (size_t i = 0; i < out_arity; ++i) {
110 encode_valtype(ptr, type->results()[i].get());
111 }
112
113 *ptr++ = 0x02; // import section
114 *ptr++ = 5; // size
115 *ptr++ = 1; // length
116 *ptr++ = 0; // module length
117 *ptr++ = 0; // name length
118 *ptr++ = 0x00; // func
119 *ptr++ = 0; // type index
120
121 *ptr++ = 0x07; // export section
122 *ptr++ = 4; // size
123 *ptr++ = 1; // length
124 *ptr++ = 0; // name length
125 *ptr++ = 0x00; // func
126 *ptr++ = 0; // func index
127
128 assert(ptr - binary.get() == size);
129 return binary;
130}
131
132auto wrapper(const GlobalType* type) -> vec<byte_t> {
133 auto size = 25 + zero_size(type->content());

Callers 2

make_funcFunction · 0.85
makeMethod · 0.85

Calls 11

encode_headerFunction · 0.85
encode_size32Function · 0.85
encode_valtypeFunction · 0.85
zero_sizeFunction · 0.85
encode_const_zeroFunction · 0.85
paramsMethod · 0.80
resultsMethod · 0.80
contentMethod · 0.80
mutabilityMethod · 0.80
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected