| 89 | |
| 90 | |
| 91 | auto 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 | |
| 132 | auto wrapper(const GlobalType* type) -> vec<byte_t> { |
| 133 | auto size = 25 + zero_size(type->content()); |
no test coverage detected