summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/binary-reader-objdump.cc21
-rw-r--r--test/dump/global.txt84
-rw-r--r--test/dump/memory.txt24
3 files changed, 76 insertions, 53 deletions
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc
index ad265d5b..eac21ef3 100644
--- a/src/binary-reader-objdump.cc
+++ b/src/binary-reader-objdump.cc
@@ -1216,7 +1216,7 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
void PrintDetails(const char* fmt, ...);
Result PrintSymbolFlags(uint32_t flags);
Result PrintSegmentFlags(uint32_t flags);
- void PrintInitExpr(const InitExpr& expr);
+ void PrintInitExpr(const InitExpr& expr, bool as_unsigned = false);
Result OnCount(Index count);
std::unique_ptr<FileStream> out_stream_;
@@ -1685,7 +1685,7 @@ Result BinaryReaderObjdump::OnElemSegmentElemExprCount(Index index,
if (elem_flags_ & SegPassive) {
PrintDetails("\n");
} else {
- PrintInitExpr(current_init_expr_);
+ PrintInitExpr(current_init_expr_, /*as_unsigned=*/true);
}
return Result::Ok;
}
@@ -1704,7 +1704,8 @@ Result BinaryReaderObjdump::BeginGlobal(Index index, Type type, bool mutable_) {
return Result::Ok;
}
-void BinaryReaderObjdump::PrintInitExpr(const InitExpr& expr) {
+void BinaryReaderObjdump::PrintInitExpr(const InitExpr& expr,
+ bool as_unsigned) {
assert(expr.insts.size() > 0);
// We have two different way to print init expressions. One for
@@ -1757,10 +1758,18 @@ void BinaryReaderObjdump::PrintInitExpr(const InitExpr& expr) {
switch (expr.type) {
case InitExprType::I32:
- PrintDetails(" - init i32=%d\n", expr.insts[0].imm.i32);
+ if (as_unsigned) {
+ PrintDetails(" - init i32=%u\n", expr.insts[0].imm.i32);
+ } else {
+ PrintDetails(" - init i32=%d\n", expr.insts[0].imm.i32);
+ }
break;
case InitExprType::I64:
- PrintDetails(" - init i64=%" PRId64 "\n", expr.insts[0].imm.i64);
+ if (as_unsigned) {
+ PrintDetails(" - init i64=%" PRIu64 "\n", expr.insts[0].imm.i64);
+ } else {
+ PrintDetails(" - init i64=%" PRId64 "\n", expr.insts[0].imm.i64);
+ }
break;
case InitExprType::F64: {
char buffer[WABT_MAX_DOUBLE_HEX];
@@ -1952,7 +1961,7 @@ Result BinaryReaderObjdump::OnDataSegmentData(Index index,
if (data_flags_ & SegPassive) {
PrintDetails("\n");
} else {
- PrintInitExpr(current_init_expr_);
+ PrintInitExpr(current_init_expr_, /*as_unsigned=*/true);
}
out_stream_->WriteMemoryDump(src_data, size, data_offset_, PrintChars::Yes,
diff --git a/test/dump/global.txt b/test/dump/global.txt
index 9a270ff5..e5600681 100644
--- a/test/dump/global.txt
+++ b/test/dump/global.txt
@@ -8,7 +8,9 @@
(import "foo" "f64_global" (global f64))
(global i32 (i32.const 1))
+ (global i32 (i32.const -42))
(global i64 (i64.const 2))
+ (global i64 (i64.const -43))
(global f32 (f32.const 3))
(global f64 (f64.const 4))
@@ -59,48 +61,58 @@
; section "Global" (6)
0000053: 06 ; section code
0000054: 00 ; section size (guess)
-0000055: 08 ; num globals
+0000055: 0a ; num globals
0000056: 7f ; i32
0000057: 00 ; global mutability
0000058: 41 ; i32.const
0000059: 01 ; i32 literal
000005a: 0b ; end
-000005b: 7e ; i64
+000005b: 7f ; i32
000005c: 00 ; global mutability
-000005d: 42 ; i64.const
-000005e: 02 ; i64 literal
+000005d: 41 ; i32.const
+000005e: 56 ; i32 literal
000005f: 0b ; end
-0000060: 7d ; f32
+0000060: 7e ; i64
0000061: 00 ; global mutability
-0000062: 43 ; f32.const
-0000063: 0000 4040 ; f32 literal
-0000067: 0b ; end
-0000068: 7c ; f64
-0000069: 00 ; global mutability
-000006a: 44 ; f64.const
-000006b: 0000 0000 0000 1040 ; f64 literal
-0000073: 0b ; end
-0000074: 7f ; i32
-0000075: 00 ; global mutability
-0000076: 23 ; global.get
-0000077: 00 ; global index
-0000078: 0b ; end
-0000079: 7e ; i64
-000007a: 00 ; global mutability
-000007b: 23 ; global.get
-000007c: 01 ; global index
+0000062: 42 ; i64.const
+0000063: 02 ; i64 literal
+0000064: 0b ; end
+0000065: 7e ; i64
+0000066: 00 ; global mutability
+0000067: 42 ; i64.const
+0000068: 55 ; i64 literal
+0000069: 0b ; end
+000006a: 7d ; f32
+000006b: 00 ; global mutability
+000006c: 43 ; f32.const
+000006d: 0000 4040 ; f32 literal
+0000071: 0b ; end
+0000072: 7c ; f64
+0000073: 00 ; global mutability
+0000074: 44 ; f64.const
+0000075: 0000 0000 0000 1040 ; f64 literal
000007d: 0b ; end
-000007e: 7d ; f32
+000007e: 7f ; i32
000007f: 00 ; global mutability
0000080: 23 ; global.get
-0000081: 02 ; global index
+0000081: 00 ; global index
0000082: 0b ; end
-0000083: 7c ; f64
+0000083: 7e ; i64
0000084: 00 ; global mutability
0000085: 23 ; global.get
-0000086: 03 ; global index
+0000086: 01 ; global index
0000087: 0b ; end
-0000054: 33 ; FIXUP section size
+0000088: 7d ; f32
+0000089: 00 ; global mutability
+000008a: 23 ; global.get
+000008b: 02 ; global index
+000008c: 0b ; end
+000008d: 7c ; f64
+000008e: 00 ; global mutability
+000008f: 23 ; global.get
+0000090: 03 ; global index
+0000091: 0b ; end
+0000054: 3d ; FIXUP section size
;;; STDERR ;;)
(;; STDOUT ;;;
@@ -113,15 +125,17 @@ Import[4]:
- global[1] i64 mutable=0 <- foo.i64_global
- global[2] f32 mutable=0 <- foo.f32_global
- global[3] f64 mutable=0 <- foo.f64_global
-Global[8]:
+Global[10]:
- global[4] i32 mutable=0 - init i32=1
- - global[5] i64 mutable=0 - init i64=2
- - global[6] f32 mutable=0 - init f32=0x1.8p+1
- - global[7] f64 mutable=0 - init f64=0x1p+2
- - global[8] i32 mutable=0 - init global=0 <foo.i32_global>
- - global[9] i64 mutable=0 - init global=1 <foo.i64_global>
- - global[10] f32 mutable=0 - init global=2 <foo.f32_global>
- - global[11] f64 mutable=0 - init global=3 <foo.f64_global>
+ - global[5] i32 mutable=0 - init i32=-42
+ - global[6] i64 mutable=0 - init i64=2
+ - global[7] i64 mutable=0 - init i64=-43
+ - global[8] f32 mutable=0 - init f32=0x1.8p+1
+ - global[9] f64 mutable=0 - init f64=0x1p+2
+ - global[10] i32 mutable=0 - init global=0 <foo.i32_global>
+ - global[11] i64 mutable=0 - init global=1 <foo.i64_global>
+ - global[12] f32 mutable=0 - init global=2 <foo.f32_global>
+ - global[13] f64 mutable=0 - init global=3 <foo.f64_global>
Code Disassembly:
diff --git a/test/dump/memory.txt b/test/dump/memory.txt
index b7da2433..efe3fc58 100644
--- a/test/dump/memory.txt
+++ b/test/dump/memory.txt
@@ -4,7 +4,7 @@
(module
(memory 1)
(data (i32.const 10) "hello")
- (data (i32.const 20) "goodbye, Lorem ipsum dolor sit amet, consectetur"))
+ (data (i32.const 2147483648) "goodbye, Lorem ipsum dolor sit amet, consectetur"))
(;; STDERR ;;;
0000000: 0061 736d ; WASM_BINARY_MAGIC
0000004: 0100 0000 ; WASM_BINARY_VERSION
@@ -37,14 +37,14 @@
; data segment header 1
000001a: 00 ; segment flags
000001b: 41 ; i32.const
-000001c: 14 ; i32 literal
-000001d: 0b ; end
-000001e: 30 ; data segment size
+000001c: 8080 8080 78 ; i32 literal
+0000021: 0b ; end
+0000022: 30 ; data segment size
; data segment data 1
-000001f: 676f 6f64 6279 652c 204c 6f72 656d 2069
-000002f: 7073 756d 2064 6f6c 6f72 2073 6974 2061
-000003f: 6d65 742c 2063 6f6e 7365 6374 6574 7572 ; data segment data
-000000e: 40 ; FIXUP section size
+0000023: 676f 6f64 6279 652c 204c 6f72 656d 2069
+0000033: 7073 756d 2064 6f6c 6f72 2073 6974 2061
+0000043: 6d65 742c 2063 6f6e 7365 6374 6574 7572 ; data segment data
+000000e: 44 ; FIXUP section size
;;; STDERR ;;)
(;; STDOUT ;;;
@@ -57,10 +57,10 @@ Memory[1]:
Data[2]:
- segment[0] memory=0 size=5 - init i32=10
- 000000a: 6865 6c6c 6f hello
- - segment[1] memory=0 size=48 - init i32=20
- - 0000014: 676f 6f64 6279 652c 204c 6f72 656d 2069 goodbye, Lorem i
- - 0000024: 7073 756d 2064 6f6c 6f72 2073 6974 2061 psum dolor sit a
- - 0000034: 6d65 742c 2063 6f6e 7365 6374 6574 7572 met, consectetur
+ - segment[1] memory=0 size=48 - init i32=2147483648
+ - 80000000: 676f 6f64 6279 652c 204c 6f72 656d 2069 goodbye, Lorem i
+ - 80000010: 7073 756d 2064 6f6c 6f72 2073 6974 2061 psum dolor sit a
+ - 80000020: 6d65 742c 2063 6f6e 7365 6374 6574 7572 met, consectetur
Code Disassembly: