diff options
Diffstat (limited to 'wasm/WriterUtils.cpp')
| -rw-r--r-- | wasm/WriterUtils.cpp | 82 | 
1 files changed, 43 insertions, 39 deletions
diff --git a/wasm/WriterUtils.cpp b/wasm/WriterUtils.cpp index 201529edeaa6..80bfc0916121 100644 --- a/wasm/WriterUtils.cpp +++ b/wasm/WriterUtils.cpp @@ -17,22 +17,6 @@  using namespace llvm;  using namespace llvm::wasm; -using namespace lld::wasm; - -static const char *valueTypeToString(uint8_t Type) { -  switch (Type) { -  case WASM_TYPE_I32: -    return "i32"; -  case WASM_TYPE_I64: -    return "i64"; -  case WASM_TYPE_F32: -    return "f32"; -  case WASM_TYPE_F64: -    return "f64"; -  default: -    llvm_unreachable("invalid value type"); -  } -}  namespace lld { @@ -73,21 +57,20 @@ void wasm::writeU32(raw_ostream &OS, uint32_t Number, const Twine &Msg) {    support::endian::write(OS, Number, support::little);  } -void wasm::writeValueType(raw_ostream &OS, uint8_t Type, const Twine &Msg) { -  writeU8(OS, Type, Msg + "[type: " + valueTypeToString(Type) + "]"); +void wasm::writeValueType(raw_ostream &OS, ValType Type, const Twine &Msg) { +  writeU8(OS, static_cast<uint8_t>(Type), +          Msg + "[type: " + toString(Type) + "]");  }  void wasm::writeSig(raw_ostream &OS, const WasmSignature &Sig) {    writeU8(OS, WASM_TYPE_FUNC, "signature type"); -  writeUleb128(OS, Sig.ParamTypes.size(), "param Count"); -  for (uint8_t ParamType : Sig.ParamTypes) { +  writeUleb128(OS, Sig.Params.size(), "param Count"); +  for (ValType ParamType : Sig.Params) {      writeValueType(OS, ParamType, "param type");    } -  if (Sig.ReturnType == WASM_TYPE_NORESULT) { -    writeUleb128(OS, 0, "result Count"); -  } else { -    writeUleb128(OS, 1, "result Count"); -    writeValueType(OS, Sig.ReturnType, "result type"); +  writeUleb128(OS, Sig.Returns.size(), "result Count"); +  if (Sig.Returns.size()) { +    writeValueType(OS, Sig.Returns[0], "result type");    }  } @@ -100,7 +83,7 @@ void wasm::writeInitExpr(raw_ostream &OS, const WasmInitExpr &InitExpr) {    case WASM_OPCODE_I64_CONST:      writeSleb128(OS, InitExpr.Value.Int64, "literal (i64)");      break; -  case WASM_OPCODE_GET_GLOBAL: +  case WASM_OPCODE_GLOBAL_GET:      writeUleb128(OS, InitExpr.Value.Global, "literal (global index)");      break;    default: @@ -117,7 +100,8 @@ void wasm::writeLimits(raw_ostream &OS, const WasmLimits &Limits) {  }  void wasm::writeGlobalType(raw_ostream &OS, const WasmGlobalType &Type) { -  writeValueType(OS, Type.Type, "global type"); +  // TODO: Update WasmGlobalType to use ValType and remove this cast. +  writeValueType(OS, ValType(Type.Type), "global type");    writeU8(OS, Type.Mutable, "global mutable");  } @@ -126,8 +110,17 @@ void wasm::writeGlobal(raw_ostream &OS, const WasmGlobal &Global) {    writeInitExpr(OS, Global.InitExpr);  } +void wasm::writeEventType(raw_ostream &OS, const WasmEventType &Type) { +  writeUleb128(OS, Type.Attribute, "event attribute"); +  writeUleb128(OS, Type.SigIndex, "sig index"); +} + +void wasm::writeEvent(raw_ostream &OS, const WasmEvent &Event) { +  writeEventType(OS, Event.Type); +} +  void wasm::writeTableType(raw_ostream &OS, const llvm::wasm::WasmTable &Type) { -  writeU8(OS, WASM_TYPE_ANYFUNC, "table type"); +  writeU8(OS, WASM_TYPE_FUNCREF, "table type");    writeLimits(OS, Type.Limits);  } @@ -142,6 +135,9 @@ void wasm::writeImport(raw_ostream &OS, const WasmImport &Import) {    case WASM_EXTERNAL_GLOBAL:      writeGlobalType(OS, Import.Global);      break; +  case WASM_EXTERNAL_EVENT: +    writeEventType(OS, Import.Event); +    break;    case WASM_EXTERNAL_MEMORY:      writeLimits(OS, Import.Memory);      break; @@ -178,13 +174,15 @@ void wasm::writeExport(raw_ostream &OS, const WasmExport &Export) {  std::string lld::toString(ValType Type) {    switch (Type) {    case ValType::I32: -    return "I32"; +    return "i32";    case ValType::I64: -    return "I64"; +    return "i64";    case ValType::F32: -    return "F32"; +    return "f32";    case ValType::F64: -    return "F64"; +    return "f64"; +  case ValType::V128: +    return "v128";    case ValType::EXCEPT_REF:      return "except_ref";    } @@ -193,20 +191,26 @@ std::string lld::toString(ValType Type) {  std::string lld::toString(const WasmSignature &Sig) {    SmallString<128> S("("); -  for (uint32_t Type : Sig.ParamTypes) { +  for (ValType Type : Sig.Params) {      if (S.size() != 1)        S += ", "; -    S += toString(static_cast<ValType>(Type)); +    S += toString(Type);    }    S += ") -> "; -  if (Sig.ReturnType == WASM_TYPE_NORESULT) +  if (Sig.Returns.size() == 0)      S += "void";    else -    S += toString(static_cast<ValType>(Sig.ReturnType)); +    S += toString(Sig.Returns[0]);    return S.str();  } -std::string lld::toString(const WasmGlobalType &Sig) { -  return (Sig.Mutable ? "var " : "const ") + -         toString(static_cast<ValType>(Sig.Type)); +std::string lld::toString(const WasmGlobalType &Type) { +  return (Type.Mutable ? "var " : "const ") + +         toString(static_cast<ValType>(Type.Type)); +} + +std::string lld::toString(const WasmEventType &Type) { +  if (Type.Attribute == WASM_EVENT_ATTRIBUTE_EXCEPTION) +    return "exception"; +  return "unknown";  }  | 
