Skip to content

Move event section before global section #1374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/binary-writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,19 @@ Result BinaryWriter::WriteModule() {
EndSection();
}

assert(module_->events.size() >= module_->num_event_imports);
Index num_events = module_->events.size() - module_->num_event_imports;
if (num_events) {
BeginKnownSection(BinarySection::Event);
WriteU32Leb128(stream_, num_events, "event count");
for (size_t i = 0; i < num_events; ++i) {
WriteHeader("event", i);
const Event* event = module_->events[i + module_->num_event_imports];
WriteEventType(event);
}
EndSection();
}

assert(module_->globals.size() >= module_->num_global_imports);
Index num_globals = module_->globals.size() - module_->num_global_imports;
if (num_globals) {
Expand All @@ -1025,19 +1038,6 @@ Result BinaryWriter::WriteModule() {
EndSection();
}

assert(module_->events.size() >= module_->num_event_imports);
Index num_events = module_->events.size() - module_->num_event_imports;
if (num_events) {
BeginKnownSection(BinarySection::Event);
WriteU32Leb128(stream_, num_events, "event count");
for (size_t i = 0; i < num_events; ++i) {
WriteHeader("event", i);
const Event* event = module_->events[i + module_->num_event_imports];
WriteEventType(event);
}
EndSection();
}

if (module_->exports.size()) {
BeginKnownSection(BinarySection::Export);
WriteU32Leb128(stream_, module_->exports.size(), "num exports");
Expand Down
2 changes: 1 addition & 1 deletion src/binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
V(Function, function, 3) \
V(Table, table, 4) \
V(Memory, memory, 5) \
V(Global, global, 6) \
V(Event, event, 13) \
V(Global, global, 6) \
V(Export, export, 7) \
V(Start, start, 8) \
V(Elem, elem, 9) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;;; ARGS2: --enable-exceptions
magic
version
section(EXPORT) { count[0] }
section(GLOBAL) { count[0] }
section(EVENT) { count[0] }
(;; STDERR ;;;
000000d: error: section Event out of order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
magic
version
section(EVENT) { count[0] }
section(GLOBAL) { count[0] }
section(MEMORY) { count[0] }
(;; STDERR ;;;
000000d: error: section Global out of order
000000d: error: section Global out of order
000000d: error: section Memory out of order
000000d: error: section Memory out of order
;;; STDERR ;;)