[Mlir-commits] [mlir] [MLIR][WASM] Extending the Wasm binary to WasmSSA dialect importer (PR #154053)

Mehdi Amini llvmlistbot at llvm.org
Mon Aug 18 02:27:54 PDT 2025


================
@@ -1229,6 +1465,51 @@ WasmBinaryParser::parseSectionItem<WasmSectionType::MEMORY>(ParserHead &ph,
   symbols.memSymbols.push_back({SymbolRefAttr::get(memOp)});
   return success();
 }
+
+template <>
+LogicalResult
+WasmBinaryParser::parseSectionItem<WasmSectionType::GLOBAL>(ParserHead &ph,
+                                                            size_t) {
+  FileLineColLoc globalLocation = ph.getLocation();
+  auto globalTypeParsed = ph.parseGlobalType(ctx);
+  if (failed(globalTypeParsed))
+    return failure();
+
+  GlobalTypeRecord globalType = *globalTypeParsed;
+  auto symbol = builder.getStringAttr(symbols.getNewGlobalSymbolName());
+  auto globalOp = builder.create<wasmssa::GlobalOp>(
+      globalLocation, symbol, globalType.type, globalType.isMutable);
+  symbols.globalSymbols.push_back(
+      {{FlatSymbolRefAttr::get(globalOp)}, globalOp.getType()});
+  auto ip = builder.saveInsertionPoint();
+  Block *block = builder.createBlock(&globalOp.getInitializer());
+  builder.setInsertionPointToStart(block);
+  parsed_inst_t expr = ph.parseExpression(builder, symbols);
+  if (failed(expr))
+    return failure();
+  if (block->empty())
+    return emitError(globalLocation, "global with empty initializer");
+  if (expr->size() != 1 && (*expr)[0].getType() != globalType.type)
+    return emitError(
+        globalLocation,
+        "initializer result type does not match global declaration type");
+  builder.create<ReturnOp>(globalLocation, *expr);
+  builder.restoreInsertionPoint(ip);
----------------
joker-eph wrote:

```suggestion
```

https://github.com/llvm/llvm-project/pull/154053


More information about the Mlir-commits mailing list