Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion src/support/command-line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,12 @@ void Options::parse(int argc, const char* argv[]) {

// Non-positional.
std::string argument;
bool explicitArg = false;
auto equal = currentOption.find_first_of('=');
if (equal != std::string::npos) {
argument = currentOption.substr(equal + 1);
currentOption = currentOption.substr(0, equal);
explicitArg = true;
}
Option* option = nullptr;
for (auto& o : options) {
Expand Down Expand Up @@ -262,7 +264,7 @@ void Options::parse(int argc, const char* argv[]) {
}
[[fallthrough]];
case Arguments::N:
if (!argument.size()) {
if (!argument.size() && !explicitArg) {
if (i + 1 == e) {
std::cerr << "Couldn't find expected argument for '"
<< currentOption << "'\n";
Expand Down
9 changes: 8 additions & 1 deletion src/tools/wasm-split/split-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ WasmSplitOptions::WasmSplitOptions()
Options::Arguments::One,
[&](Options* o, const std::string& argument) {
importNamespace = argument;
hasImportNamespace = true;
})
.add("--placeholder-namespace-prefix",
"",
Expand All @@ -246,6 +247,7 @@ WasmSplitOptions::WasmSplitOptions()
Options::Arguments::One,
[&](Options* o, const std::string& argument) {
placeholderNamespacePrefix = argument;
hasPlaceholderNamespacePrefix = true;
})
.add("--placeholder-namespace",
"",
Expand All @@ -255,6 +257,7 @@ WasmSplitOptions::WasmSplitOptions()
Options::Arguments::One,
[&](Options* o, const std::string& argument) {
placeholderNamespacePrefix = argument;
hasPlaceholderNamespacePrefix = true;
})
.add("--jspi",
"",
Expand All @@ -272,7 +275,10 @@ WasmSplitOptions::WasmSplitOptions()
WasmSplitOption,
{Mode::Split, Mode::MultiSplit},
Options::Arguments::One,
[&](Options* o, const std::string& argument) { exportPrefix = argument; })
[&](Options* o, const std::string& argument) {
exportPrefix = argument;
hasExportPrefix = true;
})
.add("--profile-export",
"",
"The export name of the function the embedder calls to write the "
Expand Down Expand Up @@ -319,6 +325,7 @@ WasmSplitOptions::WasmSplitOptions()
Options::Arguments::One,
[&](Options* o, const std::string& argument) {
secondaryMemoryName = argument;
hasSecondaryMemoryName = true;
})
.add(
"--emit-module-names",
Expand Down
4 changes: 4 additions & 0 deletions src/tools/wasm-split/split-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ struct WasmSplitOptions : ToolOptions {
std::string secondaryOutput;

std::string importNamespace;
bool hasImportNamespace = false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make these all std::optional<std::string> instead of having separate bools.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Done: 5c4a57c

std::string placeholderNamespacePrefix;
bool hasPlaceholderNamespacePrefix = false;
std::string secondaryMemoryName;
bool hasSecondaryMemoryName = false;
std::string exportPrefix;
bool hasExportPrefix = false;

std::string manifestFile;
std::string outPrefix;
Expand Down
10 changes: 5 additions & 5 deletions src/tools/wasm-split/wasm-split.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ void instrumentModule(const WasmSplitOptions& options) {

uint64_t moduleHash = hashFile(options.inputFiles[0]);
InstrumenterConfig config;
if (options.importNamespace.size()) {
if (options.hasImportNamespace) {
config.importNamespace = options.importNamespace;
}
if (options.secondaryMemoryName.size()) {
if (options.hasSecondaryMemoryName) {
config.secondaryMemoryName = options.secondaryMemoryName;
}
config.storageKind = options.storageKind;
Expand Down Expand Up @@ -226,13 +226,13 @@ void setCommonSplitConfigs(ModuleSplitting::Config& config,
const WasmSplitOptions& options) {
config.usePlaceholders = options.usePlaceholders;
config.minimizeNewExportNames = !options.passOptions.debugInfo;
if (options.importNamespace.size()) {
if (options.hasImportNamespace) {
config.importNamespace = options.importNamespace;
}
if (options.exportPrefix.size()) {
if (options.hasExportPrefix) {
config.newExportPrefix = options.exportPrefix;
}
if (options.placeholderNamespacePrefix.size()) {
if (options.hasPlaceholderNamespacePrefix) {
config.placeholderNamespacePrefix = options.placeholderNamespacePrefix;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
;; RUN: wasm-split %s --instrument --in-secondary-memory --import-namespace=custom_env --secondary-memory-name=custom_name -all -S -o - | filecheck %s

;; RUN: wasm-split %s --instrument --in-secondary-memory --import-namespace= --secondary-memory-name= -all -S -o - | filecheck %s --check-prefix=EMPTY

;; Check that the output round trips and validates as well
;; RUN: wasm-split %s --instrument --in-secondary-memory -all -g -o %t.wasm
;; RUN: wasm-opt -all %t.wasm -S -o -
Expand Down Expand Up @@ -29,3 +31,11 @@
;; CHECK: (i32.atomic.store8 $custom_name
;; CHECK: (i32.atomic.store8 $custom_name offset=1
;; CHECK: (i32.atomic.load8_u $custom_name

;; Do the checks for an empty import namespace and empty secondary memory name
;; as well;
;; EMPTY: (import "" "" (memory $"" 1 1 shared))

;; EMPTY: (i32.atomic.store8 $""
;; EMPTY: (i32.atomic.store8 $"" offset=1
;; EMPTY: (i32.atomic.load8_u $""
144 changes: 144 additions & 0 deletions test/lit/wasm-split/multi-split-options.wast
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
;; RUN: wasm-split -all -g --multi-split %s --manifest %S/multi-split.wast.manifest --out-prefix=%t --placeholder-namespace=placeholder_env -o %t.wasm
;; RUN: wasm-dis %t.wasm | filecheck %s --check-prefix=PRIMARY-PLACEHOLDER-NAMESPACE

;; Check if empty strings work for options.
;; RUN: wasm-split -all -g --multi-split %s --manifest %S/multi-split.wast.manifest --out-prefix=%t --import-namespace= --placeholder-namespace= --export-prefix= -o %t.wasm
;; RUN: wasm-dis %t.wasm | filecheck %s --check-prefix=PRIMARY-EMPTY
;; RUN: wasm-dis %t1.wasm | filecheck %s --check-prefix=MOD1-EMPTY
;; RUN: wasm-dis %t2.wasm | filecheck %s --check-prefix=MOD2-EMPTY
;; RUN: wasm-dis %t3.wasm | filecheck %s --check-prefix=MOD3-EMPTY

(module
;; PRIMARY-OPTIONS: (type $ret-i64 (func (result i64)))

Expand All @@ -23,6 +30,11 @@
;; PRIMARY-PLACEHOLDER-NAMESPACE: (type $ret-f32 (func (result f32)))

;; PRIMARY-PLACEHOLDER-NAMESPACE: (type $ret-i32 (func (result i32)))
;; PRIMARY-EMPTY: (type $ret-i64 (func (result i64)))

;; PRIMARY-EMPTY: (type $ret-f32 (func (result f32)))

;; PRIMARY-EMPTY: (type $ret-i32 (func (result i32)))
(type $ret-i32 (func (result i32)))
(type $ret-i64 (func (result i64)))
(type $ret-f32 (func (result f32)))
Expand Down Expand Up @@ -59,6 +71,38 @@
;; MOD1-OPTIONS-NEXT: )
;; MOD1-OPTIONS-NEXT: (i32.const 0)
;; MOD1-OPTIONS-NEXT: )
;; MOD1-EMPTY: (type $0 (func (result i64)))

;; MOD1-EMPTY: (type $1 (func (result f32)))

;; MOD1-EMPTY: (type $2 (func (result i32)))

;; MOD1-EMPTY: (import "" "table" (table $timport$0 3 funcref))

;; MOD1-EMPTY: (import "" "trampoline_B" (func $trampoline_B (exact (result i64))))

;; MOD1-EMPTY: (import "" "trampoline_C" (func $trampoline_C (exact (result f32))))

;; MOD1-EMPTY: (elem $0 (i32.const 2) $A)

;; MOD1-EMPTY: (func $A (result i32)
;; MOD1-EMPTY-NEXT: (drop
;; MOD1-EMPTY-NEXT: (call_ref $2
;; MOD1-EMPTY-NEXT: (ref.func $A)
;; MOD1-EMPTY-NEXT: )
;; MOD1-EMPTY-NEXT: )
;; MOD1-EMPTY-NEXT: (drop
;; MOD1-EMPTY-NEXT: (call_ref $0
;; MOD1-EMPTY-NEXT: (ref.func $trampoline_B)
;; MOD1-EMPTY-NEXT: )
;; MOD1-EMPTY-NEXT: )
;; MOD1-EMPTY-NEXT: (drop
;; MOD1-EMPTY-NEXT: (call_ref $1
;; MOD1-EMPTY-NEXT: (ref.func $trampoline_C)
;; MOD1-EMPTY-NEXT: )
;; MOD1-EMPTY-NEXT: )
;; MOD1-EMPTY-NEXT: (i32.const 0)
;; MOD1-EMPTY-NEXT: )
(func $A (type $ret-i32) (result i32)
(drop
(call_ref $ret-i32
Expand Down Expand Up @@ -110,6 +154,38 @@
;; MOD2-OPTIONS-NEXT: )
;; MOD2-OPTIONS-NEXT: (i64.const 0)
;; MOD2-OPTIONS-NEXT: )
;; MOD2-EMPTY: (type $0 (func (result i32)))

;; MOD2-EMPTY: (type $1 (func (result f32)))

;; MOD2-EMPTY: (type $2 (func (result i64)))

;; MOD2-EMPTY: (import "" "table" (table $timport$0 3 funcref))

;; MOD2-EMPTY: (import "" "trampoline_A" (func $trampoline_A (exact (result i32))))

;; MOD2-EMPTY: (import "" "trampoline_C" (func $trampoline_C (exact (result f32))))

;; MOD2-EMPTY: (elem $0 (i32.const 0) $B)

;; MOD2-EMPTY: (func $B (result i64)
;; MOD2-EMPTY-NEXT: (drop
;; MOD2-EMPTY-NEXT: (call_ref $0
;; MOD2-EMPTY-NEXT: (ref.func $trampoline_A)
;; MOD2-EMPTY-NEXT: )
;; MOD2-EMPTY-NEXT: )
;; MOD2-EMPTY-NEXT: (drop
;; MOD2-EMPTY-NEXT: (call_ref $2
;; MOD2-EMPTY-NEXT: (ref.func $B)
;; MOD2-EMPTY-NEXT: )
;; MOD2-EMPTY-NEXT: )
;; MOD2-EMPTY-NEXT: (drop
;; MOD2-EMPTY-NEXT: (call_ref $1
;; MOD2-EMPTY-NEXT: (ref.func $trampoline_C)
;; MOD2-EMPTY-NEXT: )
;; MOD2-EMPTY-NEXT: )
;; MOD2-EMPTY-NEXT: (i64.const 0)
;; MOD2-EMPTY-NEXT: )
(func $B (type $ret-i64) (result i64)
(drop
(call_ref $ret-i32
Expand Down Expand Up @@ -161,6 +237,38 @@
;; MOD3-OPTIONS-NEXT: )
;; MOD3-OPTIONS-NEXT: (f32.const 0)
;; MOD3-OPTIONS-NEXT: )
;; MOD3-EMPTY: (type $0 (func (result i32)))

;; MOD3-EMPTY: (type $1 (func (result i64)))

;; MOD3-EMPTY: (type $2 (func (result f32)))

;; MOD3-EMPTY: (import "" "table" (table $timport$0 3 funcref))

;; MOD3-EMPTY: (import "" "trampoline_A" (func $trampoline_A (exact (result i32))))

;; MOD3-EMPTY: (import "" "trampoline_B" (func $trampoline_B (exact (result i64))))

;; MOD3-EMPTY: (elem $0 (i32.const 1) $C)

;; MOD3-EMPTY: (func $C (result f32)
;; MOD3-EMPTY-NEXT: (drop
;; MOD3-EMPTY-NEXT: (call_ref $0
;; MOD3-EMPTY-NEXT: (ref.func $trampoline_A)
;; MOD3-EMPTY-NEXT: )
;; MOD3-EMPTY-NEXT: )
;; MOD3-EMPTY-NEXT: (drop
;; MOD3-EMPTY-NEXT: (call_ref $1
;; MOD3-EMPTY-NEXT: (ref.func $trampoline_B)
;; MOD3-EMPTY-NEXT: )
;; MOD3-EMPTY-NEXT: )
;; MOD3-EMPTY-NEXT: (drop
;; MOD3-EMPTY-NEXT: (call_ref $2
;; MOD3-EMPTY-NEXT: (ref.func $C)
;; MOD3-EMPTY-NEXT: )
;; MOD3-EMPTY-NEXT: )
;; MOD3-EMPTY-NEXT: (f32.const 0)
;; MOD3-EMPTY-NEXT: )
(func $C (type $ret-f32) (result f32)
(drop
(call_ref $ret-i32
Expand Down Expand Up @@ -245,3 +353,39 @@
;; PRIMARY-PLACEHOLDER-NAMESPACE-NEXT: (i32.const 2)
;; PRIMARY-PLACEHOLDER-NAMESPACE-NEXT: )
;; PRIMARY-PLACEHOLDER-NAMESPACE-NEXT: )

;; PRIMARY-EMPTY: (import ".2" "0" (func $placeholder_0 (result i64)))

;; PRIMARY-EMPTY: (import ".3" "1" (func $placeholder_1 (result f32)))

;; PRIMARY-EMPTY: (import ".1" "2" (func $placeholder_2 (result i32)))

;; PRIMARY-EMPTY: (table $0 3 funcref)

;; PRIMARY-EMPTY: (elem $0 (i32.const 0) $placeholder_0 $placeholder_1 $placeholder_2)

;; PRIMARY-EMPTY: (export "trampoline_B" (func $trampoline_B))

;; PRIMARY-EMPTY: (export "trampoline_C" (func $trampoline_C))

;; PRIMARY-EMPTY: (export "trampoline_A" (func $trampoline_A))

;; PRIMARY-EMPTY: (export "table" (table $0))

;; PRIMARY-EMPTY: (func $trampoline_B (result i64)
;; PRIMARY-EMPTY-NEXT: (call_indirect (type $ret-i64)
;; PRIMARY-EMPTY-NEXT: (i32.const 0)
;; PRIMARY-EMPTY-NEXT: )
;; PRIMARY-EMPTY-NEXT: )

;; PRIMARY-EMPTY: (func $trampoline_C (result f32)
;; PRIMARY-EMPTY-NEXT: (call_indirect (type $ret-f32)
;; PRIMARY-EMPTY-NEXT: (i32.const 1)
;; PRIMARY-EMPTY-NEXT: )
;; PRIMARY-EMPTY-NEXT: )

;; PRIMARY-EMPTY: (func $trampoline_A (result i32)
;; PRIMARY-EMPTY-NEXT: (call_indirect (type $ret-i32)
;; PRIMARY-EMPTY-NEXT: (i32.const 2)
;; PRIMARY-EMPTY-NEXT: )
;; PRIMARY-EMPTY-NEXT: )
Loading