From 3d88d11176a26b1156b83a71bbc033c71772dabe Mon Sep 17 00:00:00 2001 From: Aleksander Guryanov Date: Mon, 23 Aug 2021 22:08:26 +0700 Subject: wasm-split: accept file in keep-funcs/split-funcs (#4053) --- src/tools/wasm-split.cpp | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'src/tools/wasm-split.cpp') diff --git a/src/tools/wasm-split.cpp b/src/tools/wasm-split.cpp index 6d4e8ed5c..83c170abe 100644 --- a/src/tools/wasm-split.cpp +++ b/src/tools/wasm-split.cpp @@ -39,15 +39,41 @@ namespace { const std::string DEFAULT_PROFILE_EXPORT("__write_profile"); -std::set parseNameList(const std::string& list) { +std::set parseNameListFromLine(const std::string& line) { std::set names; - std::istringstream stream(list); + std::istringstream stream(line); for (std::string name; std::getline(stream, name, ',');) { names.insert(name); } return names; } +std::set parseNameListFromFile(const std::string& filename) { + std::ifstream infile(filename); + if (!infile.is_open()) { + std::cerr << "Failed opening '" << filename << "'" << std::endl; + exit(EXIT_FAILURE); + } + + std::set names; + std::string line; + while (std::getline(infile, line)) { + if (line.length() > 0) { + names.insert(line); + } + } + + return names; +} + +std::set parseNameList(const std::string& listOrFile) { + if (!listOrFile.empty() && listOrFile[0] == '@') { + return parseNameListFromFile(listOrFile.substr(1)); + } + + return parseNameListFromLine(listOrFile); +} + struct WasmSplitOptions : ToolOptions { enum class Mode : unsigned { Split, @@ -143,7 +169,10 @@ WasmSplitOptions::WasmSplitOptions() .add("--keep-funcs", "", "Comma-separated list of functions to keep in the primary module, " - "regardless of any profile.", + "regardless of any profile. " + "You can also pass a file with a list of functions separated by new " + "lines. " + "To do this, prepend @ before filename (--keep-funcs @myfile)", {Mode::Split}, Options::Arguments::One, [&](Options* o, const std::string& argument) { @@ -153,7 +182,10 @@ WasmSplitOptions::WasmSplitOptions() "", "Comma-separated list of functions to split into the secondary " "module, regardless of any profile. If there is no profile, then " - "this defaults to all functions defined in the module.", + "this defaults to all functions defined in the module. " + "You can also pass a file with a list of functions separated by new " + "lines. " + "To do this, prepend @ before filename (--split-funcs @myfile)", {Mode::Split}, Options::Arguments::One, [&](Options* o, const std::string& argument) { -- cgit v1.2.3