Skip to content

Commit

Permalink
[EH] Replace event with tag
Browse files Browse the repository at this point in the history
We recently decided to change 'event' to 'tag', and  'event section' to
'tag section', out of the rationale that the section contains a
generalized tag that references a type, which may be used for something
other than exceptions, and the name 'event' can be confusing in the web
context.

See
- WebAssembly/exception-handling#159 (comment)
- WebAssembly/exception-handling#161
  • Loading branch information
aheejin committed Jun 22, 2021
1 parent c6cd633 commit db2283b
Show file tree
Hide file tree
Showing 78 changed files with 1,741 additions and 1,749 deletions.
26 changes: 13 additions & 13 deletions src/apply-names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ class NameApplier : public ExprVisitor::DelegateNop {
Result UseNameForGlobalVar(Var* var);
Result UseNameForTableVar(Var* var);
Result UseNameForMemoryVar(Var* var);
Result UseNameForEventVar(Var* var);
Result UseNameForTagVar(Var* var);
Result UseNameForDataSegmentVar(Var* var);
Result UseNameForElemSegmentVar(Var* var);
Result UseNameForParamAndLocalVar(Func* func, Var* var);
Result VisitFunc(Index func_index, Func* func);
Result VisitGlobal(Global* global);
Result VisitEvent(Event* event);
Result VisitTag(Tag* tag);
Result VisitExport(Index export_index, Export* export_);
Result VisitElemSegment(Index elem_segment_index, ElemSegment* segment);
Result VisitDataSegment(Index data_segment_index, DataSegment* segment);
Expand Down Expand Up @@ -183,12 +183,12 @@ Result NameApplier::UseNameForMemoryVar(Var* var) {
return Result::Ok;
}

Result NameApplier::UseNameForEventVar(Var* var) {
Event* event = module_->GetEvent(*var);
if (!event) {
Result NameApplier::UseNameForTagVar(Var* var) {
Tag* tag = module_->GetTag(*var);
if (!tag) {
return Result::Error;
}
UseNameForVar(event->name, var);
UseNameForVar(tag->name, var);
return Result::Ok;
}

Expand Down Expand Up @@ -335,7 +335,7 @@ Result NameApplier::EndTryExpr(TryExpr*) {

Result NameApplier::OnCatchExpr(TryExpr*, Catch* expr) {
if (!expr->IsCatchAll()) {
CHECK_RESULT(UseNameForEventVar(&expr->var));
CHECK_RESULT(UseNameForTagVar(&expr->var));
}
return Result::Ok;
}
Expand All @@ -347,7 +347,7 @@ Result NameApplier::OnDelegateExpr(TryExpr* expr) {
}

Result NameApplier::OnThrowExpr(ThrowExpr* expr) {
CHECK_RESULT(UseNameForEventVar(&expr->var));
CHECK_RESULT(UseNameForTagVar(&expr->var));
return Result::Ok;
}

Expand Down Expand Up @@ -442,9 +442,9 @@ Result NameApplier::VisitGlobal(Global* global) {
return Result::Ok;
}

Result NameApplier::VisitEvent(Event* event) {
if (event->decl.has_func_type) {
CHECK_RESULT(UseNameForFuncTypeVar(&event->decl.type_var));
Result NameApplier::VisitTag(Tag* tag) {
if (tag->decl.has_func_type) {
CHECK_RESULT(UseNameForFuncTypeVar(&tag->decl.type_var));
}
return Result::Ok;
}
Expand Down Expand Up @@ -486,8 +486,8 @@ Result NameApplier::VisitModule(Module* module) {
CHECK_RESULT(VisitFunc(i, module->funcs[i]));
for (size_t i = 0; i < module->globals.size(); ++i)
CHECK_RESULT(VisitGlobal(module->globals[i]));
for (size_t i = 0; i < module->events.size(); ++i)
CHECK_RESULT(VisitEvent(module->events[i]));
for (size_t i = 0; i < module->tags.size(); ++i)
CHECK_RESULT(VisitTag(module->tags[i]));
for (size_t i = 0; i < module->exports.size(); ++i)
CHECK_RESULT(VisitExport(i, module->exports[i]));
for (size_t i = 0; i < module->elem_segments.size(); ++i)
Expand Down
72 changes: 38 additions & 34 deletions src/binary-reader-ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ class BinaryReaderIR : public BinaryReaderNop {
Index global_index,
Type type,
bool mutable_) override;
Result OnImportEvent(Index import_index,
string_view module_name,
string_view field_name,
Index event_index,
Index sig_index) override;
Result OnImportTag(Index import_index,
string_view module_name,
string_view field_name,
Index tag_index,
Index sig_index) override;

Result OnFunctionCount(Index count) override;
Result OnFunction(Index index, Index sig_index) override;
Expand Down Expand Up @@ -144,7 +144,7 @@ class BinaryReaderIR : public BinaryReaderNop {
Index* target_depths,
Index default_target_depth) override;
Result OnCallExpr(Index func_index) override;
Result OnCatchExpr(Index event_index) override;
Result OnCatchExpr(Index tag_index) override;
Result OnCatchAllExpr() override;
Result OnCallIndirectExpr(Index sig_index, Index table_index) override;
Result OnReturnCallExpr(Index func_index) override;
Expand Down Expand Up @@ -194,7 +194,7 @@ class BinaryReaderIR : public BinaryReaderNop {
Result OnStoreExpr(Opcode opcode,
Address alignment_log2,
Address offset) override;
Result OnThrowExpr(Index event_index) override;
Result OnThrowExpr(Index tag_index) override;
Result OnTryExpr(Type sig_type) override;
Result OnUnaryExpr(Opcode opcode) override;
Result OnTernaryExpr(Opcode opcode) override;
Expand Down Expand Up @@ -252,10 +252,10 @@ class BinaryReaderIR : public BinaryReaderNop {
Index index,
string_view name) override;

Result BeginEventSection(Offset size) override { return Result::Ok; }
Result OnEventCount(Index count) override { return Result::Ok; }
Result OnEventType(Index index, Index sig_index) override;
Result EndEventSection() override { return Result::Ok; }
Result BeginTagSection(Offset size) override { return Result::Ok; }
Result OnTagCount(Index count) override { return Result::Ok; }
Result OnTagType(Index index, Index sig_index) override;
Result EndTagSection() override { return Result::Ok; }

Result OnInitExprF32ConstExpr(Index index, uint32_t value) override;
Result OnInitExprF64ConstExpr(Index index, uint64_t value) override;
Expand All @@ -274,8 +274,10 @@ class BinaryReaderIR : public BinaryReaderNop {
Index global_index) override;
Result OnSectionSymbol(Index index, uint32_t flags,
Index section_index) override;
Result OnEventSymbol(Index index, uint32_t flags, string_view name,
Index event_index) override;
Result OnTagSymbol(Index index,
uint32_t flags,
string_view name,
Index tag_index) override;
Result OnTableSymbol(Index index, uint32_t flags, string_view name,
Index table_index) override;

Expand Down Expand Up @@ -525,15 +527,15 @@ Result BinaryReaderIR::OnImportGlobal(Index import_index,
return Result::Ok;
}

Result BinaryReaderIR::OnImportEvent(Index import_index,
string_view module_name,
string_view field_name,
Index event_index,
Index sig_index) {
auto import = MakeUnique<EventImport>();
Result BinaryReaderIR::OnImportTag(Index import_index,
string_view module_name,
string_view field_name,
Index tag_index,
Index sig_index) {
auto import = MakeUnique<TagImport>();
import->module_name = module_name.to_string();
import->field_name = field_name.to_string();
SetFuncDeclaration(&import->event.decl, Var(sig_index, GetLocation()));
SetFuncDeclaration(&import->tag.decl, Var(sig_index, GetLocation()));
module_->AppendField(
MakeUnique<ImportModuleField>(std::move(import), GetLocation()));
return Result::Ok;
Expand Down Expand Up @@ -975,8 +977,8 @@ Result BinaryReaderIR::OnStoreExpr(Opcode opcode,
return AppendExpr(MakeUnique<StoreExpr>(opcode, 1 << alignment_log2, offset));
}

Result BinaryReaderIR::OnThrowExpr(Index event_index) {
return AppendExpr(MakeUnique<ThrowExpr>(Var(event_index, GetLocation())));
Result BinaryReaderIR::OnThrowExpr(Index tag_index) {
return AppendExpr(MakeUnique<ThrowExpr>(Var(tag_index, GetLocation())));
}

Result BinaryReaderIR::OnLocalTeeExpr(Index local_index) {
Expand Down Expand Up @@ -1482,10 +1484,10 @@ Result BinaryReaderIR::OnLocalName(Index func_index,
return Result::Ok;
}

Result BinaryReaderIR::OnEventType(Index index, Index sig_index) {
auto field = MakeUnique<EventModuleField>(GetLocation());
Event& event = field->event;
SetFuncDeclaration(&event.decl, Var(sig_index, GetLocation()));
Result BinaryReaderIR::OnTagType(Index index, Index sig_index) {
auto field = MakeUnique<TagModuleField>(GetLocation());
Tag& tag = field->tag;
SetFuncDeclaration(&tag.decl, Var(sig_index, GetLocation()));
module_->AppendField(std::move(field));
return Result::Ok;
}
Expand Down Expand Up @@ -1548,20 +1550,22 @@ Result BinaryReaderIR::OnSectionSymbol(Index index, uint32_t flags,
return Result::Ok;
}

Result BinaryReaderIR::OnEventSymbol(Index index, uint32_t flags,
string_view name, Index event_index) {
Result BinaryReaderIR::OnTagSymbol(Index index,
uint32_t flags,
string_view name,
Index tag_index) {
if (name.empty()) {
return Result::Ok;
}
if (event_index >= module_->events.size()) {
PrintError("invalid event index: %" PRIindex, event_index);
if (tag_index >= module_->tags.size()) {
PrintError("invalid tag index: %" PRIindex, tag_index);
return Result::Error;
}
Event* event = module_->events[event_index];
Tag* tag = module_->tags[tag_index];
std::string dollar_name =
GetUniqueName(&module_->event_bindings, MakeDollarName(name));
event->name = dollar_name;
module_->event_bindings.emplace(dollar_name, Binding(event_index));
GetUniqueName(&module_->tag_bindings, MakeDollarName(name));
tag->name = dollar_name;
module_->tag_bindings.emplace(dollar_name, Binding(tag_index));
return Result::Ok;
}

Expand Down
46 changes: 23 additions & 23 deletions src/binary-reader-logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,16 @@ Result BinaryReaderLogging::OnImportGlobal(Index import_index,
global_index, type, mutable_);
}

Result BinaryReaderLogging::OnImportEvent(Index import_index,
string_view module_name,
string_view field_name,
Index event_index,
Index sig_index) {
LOGF("OnImportEvent(import_index: %" PRIindex ", event_index: %" PRIindex
Result BinaryReaderLogging::OnImportTag(Index import_index,
string_view module_name,
string_view field_name,
Index tag_index,
Index sig_index) {
LOGF("OnImportTag(import_index: %" PRIindex ", tag_index: %" PRIindex
", sig_index: %" PRIindex ")\n",
import_index, event_index, sig_index);
return reader_->OnImportEvent(import_index, module_name, field_name,
event_index, sig_index);
import_index, tag_index, sig_index);
return reader_->OnImportTag(import_index, module_name, field_name, tag_index,
sig_index);
}

Result BinaryReaderLogging::OnTable(Index index,
Expand Down Expand Up @@ -614,14 +614,14 @@ Result BinaryReaderLogging::OnSectionSymbol(Index index,
return reader_->OnSectionSymbol(index, flags, section_index);
}

Result BinaryReaderLogging::OnEventSymbol(Index index,
uint32_t flags,
string_view name,
Index event_index) {
LOGF("OnEventSymbol(name: " PRIstringview " flags: 0x%x index: %" PRIindex
")\n",
WABT_PRINTF_STRING_VIEW_ARG(name), flags, event_index);
return reader_->OnEventSymbol(index, flags, name, event_index);
Result BinaryReaderLogging::OnTagSymbol(Index index,
uint32_t flags,
string_view name,
Index tag_index) {
LOGF("OnTagSymbol(name: " PRIstringview " flags: 0x%x index: %" PRIindex
")\n",
WABT_PRINTF_STRING_VIEW_ARG(name), flags, tag_index);
return reader_->OnTagSymbol(index, flags, name, tag_index);
}

Result BinaryReaderLogging::OnTableSymbol(Index index,
Expand Down Expand Up @@ -802,7 +802,7 @@ DEFINE_LOAD_STORE_OPCODE(OnAtomicNotifyExpr);
DEFINE_OPCODE(OnBinaryExpr)
DEFINE_INDEX_DESC(OnCallExpr, "func_index")
DEFINE_INDEX_INDEX(OnCallIndirectExpr, "sig_index", "table_index")
DEFINE_INDEX_DESC(OnCatchExpr, "event_index");
DEFINE_INDEX_DESC(OnCatchExpr, "tag_index");
DEFINE0(OnCatchAllExpr);
DEFINE_OPCODE(OnCompareExpr)
DEFINE_OPCODE(OnConvertExpr)
Expand Down Expand Up @@ -842,7 +842,7 @@ DEFINE0(OnReturnExpr)
DEFINE_LOAD_STORE_OPCODE(OnLoadSplatExpr);
DEFINE_LOAD_STORE_OPCODE(OnLoadZeroExpr);
DEFINE_LOAD_STORE_OPCODE(OnStoreExpr);
DEFINE_INDEX_DESC(OnThrowExpr, "event_index")
DEFINE_INDEX_DESC(OnThrowExpr, "tag_index")
DEFINE0(OnUnreachableExpr)
DEFINE0(OnUnwindExpr)
DEFINE_OPCODE(OnUnaryExpr)
Expand Down Expand Up @@ -898,10 +898,10 @@ DEFINE_INDEX(OnInitFunctionCount)
DEFINE_INDEX(OnComdatCount)
DEFINE_END(EndLinkingSection)

DEFINE_BEGIN(BeginEventSection);
DEFINE_INDEX(OnEventCount);
DEFINE_INDEX_INDEX(OnEventType, "index", "sig_index")
DEFINE_END(EndEventSection);
DEFINE_BEGIN(BeginTagSection);
DEFINE_INDEX(OnTagCount);
DEFINE_INDEX_INDEX(OnTagType, "index", "sig_index")
DEFINE_END(EndTagSection);

// We don't need to log these (the individual opcodes are logged instead), but
// we still need to forward the calls.
Expand Down
32 changes: 16 additions & 16 deletions src/binary-reader-logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Index global_index,
Type type,
bool mutable_) override;
Result OnImportEvent(Index import_index,
string_view module_name,
string_view field_name,
Index event_index,
Index sig_index) override;
Result OnImportTag(Index import_index,
string_view module_name,
string_view field_name,
Index tag_index,
Index sig_index) override;
Result EndImportSection() override;

Result BeginFunctionSection(Offset size) override;
Expand Down Expand Up @@ -166,7 +166,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Index* target_depths,
Index default_target_depth) override;
Result OnCallExpr(Index func_index) override;
Result OnCatchExpr(Index event_index) override;
Result OnCatchExpr(Index tag_index) override;
Result OnCatchAllExpr() override;
Result OnCallIndirectExpr(Index sig_index, Index table_index) override;
Result OnCompareExpr(Opcode opcode) override;
Expand Down Expand Up @@ -217,7 +217,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnStoreExpr(Opcode opcode,
Address alignment_log2,
Address offset) override;
Result OnThrowExpr(Index event_index) override;
Result OnThrowExpr(Index tag_index) override;
Result OnTryExpr(Type sig_type) override;
Result OnUnaryExpr(Opcode opcode) override;
Result OnTernaryExpr(Opcode opcode) override;
Expand Down Expand Up @@ -346,14 +346,14 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnSectionSymbol(Index index,
uint32_t flags,
Index section_index) override;
Result OnEventSymbol(Index index,
uint32_t flags,
string_view name,
Index event_index) override;
Result OnTagSymbol(Index index,
uint32_t flags,
string_view name,
Index tag_index) override;
Result OnTableSymbol(Index index,
uint32_t flags,
string_view name,
Index event_index) override;
Index tag_index) override;
Result OnSegmentInfoCount(Index count) override;
Result OnSegmentInfo(Index index,
string_view name,
Expand All @@ -366,10 +366,10 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnComdatEntry(ComdatType kind, Index index) override;
Result EndLinkingSection() override;

Result BeginEventSection(Offset size) override;
Result OnEventCount(Index count) override;
Result OnEventType(Index index, Index sig_index) override;
Result EndEventSection() override;
Result BeginTagSection(Offset size) override;
Result OnTagCount(Index count) override;
Result OnTagType(Index index, Index sig_index) override;
Result EndTagSection() override;

Result OnInitExprF32ConstExpr(Index index, uint32_t value) override;
Result OnInitExprF64ConstExpr(Index index, uint64_t value) override;
Expand Down
Loading

0 comments on commit db2283b

Please sign in to comment.