summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Smith <binjimin@gmail.com>2018-12-12 17:03:23 -0800
committerGitHub <noreply@github.com>2018-12-12 17:03:23 -0800
commitbfc4f5b9cf7d1e43896d825d5485621956a3ec3f (patch)
treee0d264bcd1098fe817fcec699f82479aa48095d8 /src
parenta5827e0c2e5d3e4a05a65853ec5b5284dffe9585 (diff)
downloadwabt-bfc4f5b9cf7d1e43896d825d5485621956a3ec3f.tar.gz
wabt-bfc4f5b9cf7d1e43896d825d5485621956a3ec3f.tar.bz2
wabt-bfc4f5b9cf7d1e43896d825d5485621956a3ec3f.zip
Pass function body size in BinaryReader callback (#975)
This is useful for finding large functions with wasm-objdump.
Diffstat (limited to 'src')
-rw-r--r--src/binary-reader-ir.cc4
-rw-r--r--src/binary-reader-logging.cc6
-rw-r--r--src/binary-reader-logging.h2
-rw-r--r--src/binary-reader-nop.h4
-rw-r--r--src/binary-reader-objdump.cc13
-rw-r--r--src/binary-reader.cc2
-rw-r--r--src/binary-reader.h2
-rw-r--r--src/interp/binary-reader-interp.cc4
8 files changed, 25 insertions, 12 deletions
diff --git a/src/binary-reader-ir.cc b/src/binary-reader-ir.cc
index 24828f2e..dd4ad01a 100644
--- a/src/binary-reader-ir.cc
+++ b/src/binary-reader-ir.cc
@@ -112,7 +112,7 @@ class BinaryReaderIR : public BinaryReaderNop {
Result OnStartFunction(Index func_index) override;
Result OnFunctionBodyCount(Index count) override;
- Result BeginFunctionBody(Index index) override;
+ Result BeginFunctionBody(Index index, Offset size) override;
Result OnLocalDecl(Index decl_index, Index count, Type type) override;
Result OnAtomicLoadExpr(Opcode opcode,
@@ -574,7 +574,7 @@ Result BinaryReaderIR::OnFunctionBodyCount(Index count) {
return Result::Ok;
}
-Result BinaryReaderIR::BeginFunctionBody(Index index) {
+Result BinaryReaderIR::BeginFunctionBody(Index index, Offset size) {
current_func_ = module_->funcs[index];
PushLabel(LabelType::Func, &current_func_->exprs);
return Result::Ok;
diff --git a/src/binary-reader-logging.cc b/src/binary-reader-logging.cc
index e31471df..934e125c 100644
--- a/src/binary-reader-logging.cc
+++ b/src/binary-reader-logging.cc
@@ -254,6 +254,11 @@ Result BinaryReaderLogging::OnExport(Index index,
return reader_->OnExport(index, kind, item_index, name);
}
+Result BinaryReaderLogging::BeginFunctionBody(Index value, Offset size) {
+ LOGF("BeginFunctionBody(%" PRIindex ", size:%" PRIzd ")\n", value, size);
+ return reader_->BeginFunctionBody(value, size);
+}
+
Result BinaryReaderLogging::OnLocalDecl(Index decl_index,
Index count,
Type type) {
@@ -669,7 +674,6 @@ DEFINE_END(EndStartSection)
DEFINE_BEGIN(BeginCodeSection)
DEFINE_INDEX(OnFunctionBodyCount)
-DEFINE_INDEX(BeginFunctionBody)
DEFINE_INDEX(EndFunctionBody)
DEFINE_INDEX(OnLocalDeclCount)
DEFINE_LOAD_STORE_OPCODE(OnAtomicLoadExpr);
diff --git a/src/binary-reader-logging.h b/src/binary-reader-logging.h
index 5d28c1b2..32480306 100644
--- a/src/binary-reader-logging.h
+++ b/src/binary-reader-logging.h
@@ -120,7 +120,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result BeginCodeSection(Offset size) override;
Result OnFunctionBodyCount(Index count) override;
- Result BeginFunctionBody(Index index) override;
+ Result BeginFunctionBody(Index index, Offset size) override;
Result OnLocalDeclCount(Index count) override;
Result OnLocalDecl(Index decl_index, Index count, Type type) override;
diff --git a/src/binary-reader-nop.h b/src/binary-reader-nop.h
index 059743dd..5cb926a9 100644
--- a/src/binary-reader-nop.h
+++ b/src/binary-reader-nop.h
@@ -154,7 +154,9 @@ class BinaryReaderNop : public BinaryReaderDelegate {
/* Code section */
Result BeginCodeSection(Offset size) override { return Result::Ok; }
Result OnFunctionBodyCount(Index count) override { return Result::Ok; }
- Result BeginFunctionBody(Index index) override { return Result::Ok; }
+ Result BeginFunctionBody(Index index, Offset size) override {
+ return Result::Ok;
+ }
Result OnLocalDeclCount(Index count) override { return Result::Ok; }
Result OnLocalDecl(Index decl_index, Index count, Type type) override {
return Result::Ok;
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc
index fb4c3d23..ca5e4332 100644
--- a/src/binary-reader-objdump.cc
+++ b/src/binary-reader-objdump.cc
@@ -331,7 +331,7 @@ class BinaryReaderObjdumpDisassemble : public BinaryReaderObjdumpBase {
std::string BlockSigToString(Type type) const;
- Result BeginFunctionBody(Index index) override;
+ Result BeginFunctionBody(Index index, Offset size) override;
Result OnLocalDeclCount(Index count) override;
Result OnLocalDecl(Index decl_index, Index count, Type type) override;
@@ -604,7 +604,8 @@ Result BinaryReaderObjdumpDisassemble::OnEndExpr() {
return Result::Ok;
}
-Result BinaryReaderObjdumpDisassemble::BeginFunctionBody(Index index) {
+Result BinaryReaderObjdumpDisassemble::BeginFunctionBody(Index index,
+ Offset size) {
const char* name = GetFunctionName(index);
if (name) {
printf("%06" PRIzx " <%s>:\n", state->offset, name);
@@ -718,6 +719,7 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
Result OnStartFunction(Index func_index) override;
Result OnFunctionBodyCount(Index count) override;
+ Result BeginFunctionBody(Index index, Offset size) override;
Result BeginElemSection(Offset size) override {
in_elem_section_ = true;
@@ -862,7 +864,7 @@ Result BinaryReaderObjdump::BeginSection(BinarySection section_code,
name, state->offset, state->offset + size, size);
break;
case ObjdumpMode::Details:
- if (section_match && section_code != BinarySection::Code) {
+ if (section_match) {
printf("%s", name);
// All known section types except the start section have a count
// in which case this line gets completed in OnCount().
@@ -978,6 +980,11 @@ Result BinaryReaderObjdump::OnFunctionBodyCount(Index count) {
return OnCount(count);
}
+Result BinaryReaderObjdump::BeginFunctionBody(Index index, Offset size) {
+ PrintDetails(" - func[%" PRIindex "] size=%" PRIzd "\n", index, size);
+ return Result::Ok;
+}
+
Result BinaryReaderObjdump::OnStartFunction(Index func_index) {
if (options_->mode == ObjdumpMode::Headers) {
printf("start: %" PRIindex "\n", func_index);
diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index e1c5e759..ebdcb547 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -2033,11 +2033,11 @@ Result BinaryReader::ReadCodeSection(Offset section_size) {
Index func_index = num_func_imports_ + i;
Offset func_offset = state_.offset;
state_.offset = func_offset;
- CALLBACK(BeginFunctionBody, func_index);
uint32_t body_size;
CHECK_RESULT(ReadU32Leb128(&body_size, "function body size"));
Offset body_start_offset = state_.offset;
Offset end_offset = body_start_offset + body_size;
+ CALLBACK(BeginFunctionBody, func_index, body_size);
uint64_t total_locals = 0;
Index num_local_decls;
diff --git a/src/binary-reader.h b/src/binary-reader.h
index e666089b..743103e9 100644
--- a/src/binary-reader.h
+++ b/src/binary-reader.h
@@ -168,7 +168,7 @@ class BinaryReaderDelegate {
/* Code section */
virtual Result BeginCodeSection(Offset size) = 0;
virtual Result OnFunctionBodyCount(Index count) = 0;
- virtual Result BeginFunctionBody(Index index) = 0;
+ virtual Result BeginFunctionBody(Index index, Offset size) = 0;
virtual Result OnLocalDeclCount(Index count) = 0;
virtual Result OnLocalDecl(Index decl_index, Index count, Type type) = 0;
diff --git a/src/interp/binary-reader-interp.cc b/src/interp/binary-reader-interp.cc
index abac55c7..ce8c8ac2 100644
--- a/src/interp/binary-reader-interp.cc
+++ b/src/interp/binary-reader-interp.cc
@@ -134,7 +134,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
wabt::Result OnStartFunction(Index func_index) override;
- wabt::Result BeginFunctionBody(Index index) override;
+ wabt::Result BeginFunctionBody(Index index, Offset size) override;
wabt::Result OnLocalDeclCount(Index count) override;
wabt::Result OnLocalDecl(Index decl_index, Index count, Type type) override;
@@ -1044,7 +1044,7 @@ void BinaryReaderInterp::PopLabel() {
}
}
-wabt::Result BinaryReaderInterp::BeginFunctionBody(Index index) {
+wabt::Result BinaryReaderInterp::BeginFunctionBody(Index index, Offset size) {
auto* func = cast<DefinedFunc>(GetFuncByModuleIndex(index));
FuncSignature* sig = env_->GetFuncSignature(func->sig_index);