llvm-project/lld/test/wasm/import-memory.test
Andy Wingo 9ac5620cb8 [WebAssembly] Rename WasmLimits::Initial to ::Minimum. NFC.
This patch renames the "Initial" member of WasmLimits to the name used
in the spec, "Minimum".

In the core WebAssembly specification, the Limits data type has one
required "min" member and one optional "max" member, indicating the
minimum required size of the corresponding table or memory, and the
maximum size, if any.

Although the WebAssembly spec does instantiate locally-defined tables
and memories with the initial size being equal to the minimum size, it
can't impose such a requirement for imports.  It doesn't make sense to
require an initial size for a memory import, for example.  The compiler
can only sensibly express the minimum and maximum sizes.

See
https://github.com/WebAssembly/js-types/blob/master/proposals/js-types/Overview.md#naming-of-size-limits
for a related discussion that agrees that the right name of "initial" is
"minimum" when querying the type of a table or memory from JavaScript.
(Of course it still makes sense for JS to speak in terms of an initial
size when it explicitly instantiates memories and tables.)

Differential Revision: https://reviews.llvm.org/D99186
2021-03-24 09:10:11 +01:00

51 lines
1.9 KiB
Plaintext

# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/start.s -o %t.start.o
# RUN: wasm-ld --import-memory -o %t.wasm %t.start.o
# RUN: obj2yaml %t.wasm | FileCheck %s
# Verify the --import-memory flag creates a memory import
# CHECK: - Type: IMPORT
# CHECK-NEXT: Imports:
# CHECK-NEXT: - Module: env
# CHECK-NEXT: Field: memory
# CHECK-NEXT: Kind: MEMORY
# CHECK-NEXT: Memory:
# CHECK-NEXT: Minimum: 0x2
# CHECK-NEXT: - Type:
# RUN: wasm-ld --import-memory --initial-memory=262144 \
# RUN: --max-memory=327680 -o %t.max.wasm %t.start.o
# RUN: obj2yaml %t.max.wasm | FileCheck -check-prefix=CHECK-MAX %s
# Verify the --initial-memory and --max-memory arguments work with imports
# CHECK-MAX: - Type: IMPORT
# CHECK-MAX-NEXT: Imports:
# CHECK-MAX-NEXT: - Module: env
# CHECK-MAX-NEXT: Field: memory
# CHECK-MAX-NEXT: Kind: MEMORY
# CHECK-MAX-NEXT: Memory:
# CHECK-MAX-NEXT: Flags: [ HAS_MAX ]
# CHECK-MAX-NEXT: Minimum: 0x4
# CHECK-MAX-NEXT: Maximum: 0x5
# CHECK-MAX-NEXT: - Type:
# RUN: wasm-ld --import-memory --shared-memory --features=atomics,bulk-memory \
# RUN: --initial-memory=262144 --max-memory=327680 -o %t.max.wasm %t.start.o
# RUN: obj2yaml %t.max.wasm | FileCheck -check-prefix=CHECK-SHARED %s
# Verify the --shared-memory flag works with imports
# CHECK-SHARED: - Type: IMPORT
# CHECK-SHARED-NEXT: Imports:
# CHECK-SHARED-NEXT: - Module: env
# CHECK-SHARED-NEXT: Field: memory
# CHECK-SHARED-NEXT: Kind: MEMORY
# CHECK-SHARED-NEXT: Memory:
# CHECK-SHARED-NEXT: Flags: [ HAS_MAX, IS_SHARED ]
# CHECK-SHARED-NEXT: Minimum: 0x4
# CHECK-SHARED-NEXT: Maximum: 0x5
# CHECK-SHARED-NEXT: - Type: