diff options
author | Ben Smith <binjimin@gmail.com> | 2019-02-12 14:41:34 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-12 14:41:34 -0800 |
commit | e448ac7cbd74f7a048b1de15ce1a2716340a57c8 (patch) | |
tree | 2cdbf9372eabfb2584d26279beee84062036c348 /src/wat-writer.cc | |
parent | 35ee613d4f8e65e730aaa6d519ee39ce581d4f24 (diff) | |
download | wabt-e448ac7cbd74f7a048b1de15ce1a2716340a57c8.tar.gz wabt-e448ac7cbd74f7a048b1de15ce1a2716340a57c8.tar.bz2 wabt-e448ac7cbd74f7a048b1de15ce1a2716340a57c8.zip |
Parse updated event text and binary format (#1014)
An event has a type-section index, like a function definition. The
current proposal doesn't specify the text format, so I assumed that it
would match the format of the other sections that reference function
types. This means that the following declaration styles are allowed:
```
(type $t (func (param i32)))
(event $e1 (type $t))
(event $e2 (param f32))
```
Diffstat (limited to 'src/wat-writer.cc')
-rw-r--r-- | src/wat-writer.cc | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/wat-writer.cc b/src/wat-writer.cc index 9ac76b59..5a3b1a25 100644 --- a/src/wat-writer.cc +++ b/src/wat-writer.cc @@ -157,7 +157,6 @@ class WatWriter { void WriteFunc(const Func& func); void WriteBeginGlobal(const Global& global); void WriteGlobal(const Global& global); - void WriteBeginEvent(const Event& event); void WriteEvent(const Event& event); void WriteLimits(const Limits& limits); void WriteTable(const Table& table); @@ -1071,7 +1070,7 @@ void WatWriter::WriteFoldedExpr(const Expr* expr) { auto throw_ = cast<ThrowExpr>(expr); Index operand_count = 0; if (Event* event = module_->GetEvent(throw_->var)) { - operand_count = event->sig.size(); + operand_count = event->decl.sig.param_types.size(); } PushExpr(expr, operand_count, 0); break; @@ -1382,17 +1381,18 @@ void WatWriter::WriteGlobal(const Global& global) { WriteCloseNewline(); } -void WatWriter::WriteBeginEvent(const Event& event) { +void WatWriter::WriteEvent(const Event& event) { WriteOpenSpace("event"); WriteNameOrIndex(event.name, event_index_, NextChar::Space); WriteInlineExports(ExternalKind::Event, event_index_); WriteInlineImport(ExternalKind::Event, event_index_); - WriteTypes(event.sig, nullptr); + if (event.decl.has_func_type) { + WriteOpenSpace("type"); + WriteVar(event.decl.type_var, NextChar::None); + WriteCloseSpace(); + } + WriteTypes(event.decl.sig.param_types, "param"); ++event_index_; -} - -void WatWriter::WriteEvent(const Event& event) { - WriteBeginEvent(event); WriteCloseNewline(); } @@ -1482,8 +1482,7 @@ void WatWriter::WriteImport(const Import& import) { break; case ExternalKind::Event: - WriteBeginEvent(cast<EventImport>(&import)->event); - WriteCloseSpace(); + WriteEvent(cast<EventImport>(&import)->event); break; } |