summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binary-writer.cc37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/binary-writer.cc b/src/binary-writer.cc
index 6748559d..eab354ea 100644
--- a/src/binary-writer.cc
+++ b/src/binary-writer.cc
@@ -208,6 +208,7 @@ class BinaryWriter {
void BeginSubsection(const char* name, size_t leb_size_guess);
void EndSubsection();
Index GetLabelVarDepth(const Var* var);
+ Index GetExceptVarDepth(const Var* var);
Index GetLocalIndex(const Func* func, const Var& var);
void AddReloc(RelocType reloc_type, Index index);
void WriteU32Leb128WithReloc(Index index,
@@ -372,6 +373,11 @@ Index BinaryWriter::GetLabelVarDepth(const Var* var) {
return var->index;
}
+Index BinaryWriter::GetExceptVarDepth(const Var* var) {
+ assert(var->type == VarType::Index);
+ return var->index;
+}
+
void BinaryWriter::AddReloc(RelocType reloc_type, Index index) {
// Add a new reloc section if needed
if (!current_reloc_section_ ||
@@ -536,8 +542,9 @@ void BinaryWriter::WriteExpr(const Module* module,
write_opcode(&stream_, Opcode::Nop);
break;
case ExprType::Rethrow:
- // TODO(karlschimpf): Define
- WABT_FATAL("Rethrow: Don't know how to write\n");
+ write_opcode(&stream_, Opcode::Rethrow);
+ write_u32_leb128(&stream_, GetLabelVarDepth(&expr->rethrow_.var),
+ "rethrow depth");
break;
case ExprType::Return:
write_opcode(&stream_, Opcode::Return);
@@ -571,12 +578,25 @@ void BinaryWriter::WriteExpr(const Module* module,
break;
}
case ExprType::Throw:
- // TODO(karlschimpf): Define
- WABT_FATAL("Throw: Don't know how to write\n");
+ write_opcode(&stream_, Opcode::Throw);
+ write_u32_leb128(&stream_, GetExceptVarDepth(&expr->throw_.var),
+ "throw exception");
break;
case ExprType::TryBlock:
- // TODO(karlschimpf): Define
- WABT_FATAL("TryBlock: Don't know how to write\n");
+ write_opcode(&stream_, Opcode::Try);
+ write_inline_signature_type(&stream_, expr->try_block.block->sig);
+ WriteExprList(module, func, expr->try_block.block->first);
+ for (Catch* catch_ : *expr->try_block.catches) {
+ if (catch_->IsCatchAll()) {
+ write_opcode(&stream_, Opcode::CatchAll);
+ } else {
+ write_opcode(&stream_, Opcode::Catch);
+ write_u32_leb128(&stream_, GetExceptVarDepth(&catch_->var),
+ "catch exception");
+ }
+ WriteExprList(module, func, catch_->first);
+ }
+ write_opcode(&stream_, Opcode::End);
break;
case ExprType::Unary:
write_opcode(&stream_, expr->unary.opcode);
@@ -981,6 +1001,11 @@ Result BinaryWriter::WriteModule(const Module* module) {
}
}
+ if (module->excepts.size()) {
+ // TODO(karlschimpf) Define.
+ WABT_FATAL("write exception section not implemented");
+ }
+
return stream_.result();
}