| 134 | } |
| 135 | |
| 136 | Validator::Validator(const WasmModule& module) : context(module.types, module.elems, module.datas) { |
| 137 | // imports |
| 138 | size_t idx = 0; |
| 139 | for(const WasmImport& import : module.imports){ |
| 140 | std::visit(overloaded { |
| 141 | [&](const index_t& index){ |
| 142 | if(index >= module.types.size()){ |
| 143 | std::stringstream ss; |
| 144 | ss << "import[" << idx << "]: type index " << index << " not exist"; |
| 145 | throw Exception::Exception(ss.str()); |
| 146 | } |
| 147 | context.funcs.emplace_back(module.types[index]); |
| 148 | }, |
| 149 | [&](const TableType& table){ |
| 150 | context.tables.emplace_back(table); |
| 151 | }, |
| 152 | [&](const MemType& mem){ |
| 153 | context.mems.emplace_back(mem); |
| 154 | }, |
| 155 | [&](const GlobalType& global){ |
| 156 | context.globals.emplace_back(global); |
| 157 | } |
| 158 | }, import.desc); |
| 159 | idx += 1; |
| 160 | } |
| 161 | // funcs |
| 162 | idx = 0; |
| 163 | for(const WasmFunc& func : module.funcs){ |
| 164 | if(func.typeidx >= module.types.size()){ |
| 165 | std::stringstream ss; |
| 166 | ss << "func [" << idx << "]: type index " << func.typeidx << " not exist"; |
| 167 | throw Exception::Exception(ss.str()); |
| 168 | } |
| 169 | context.funcs.emplace_back(module.types[func.typeidx]); |
| 170 | idx += 1; |
| 171 | } |
| 172 | // tables |
| 173 | for(const TableType& table : module.tables){ |
| 174 | context.tables.emplace_back(table); |
| 175 | } |
| 176 | // mems |
| 177 | for(const MemType& memory : module.mems){ |
| 178 | context.mems.emplace_back(memory); |
| 179 | } |
| 180 | // globals |
| 181 | for(const WasmGlobal& global : module.globals){ |
| 182 | context.globals.emplace_back(global.type); |
| 183 | } |
| 184 | } |