summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/tool-utils.h37
-rw-r--r--src/tools/wasm-as.cpp7
2 files changed, 44 insertions, 0 deletions
diff --git a/src/tools/tool-utils.h b/src/tools/tool-utils.h
new file mode 100644
index 000000000..a897e01f0
--- /dev/null
+++ b/src/tools/tool-utils.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2017 WebAssembly Community Group participants
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Shared utilities for commandline tools
+//
+
+#include <string>
+
+namespace wasm {
+
+// Removes a specific suffix if it is present, otherwise no-op
+inline std::string removeSpecificSuffix(std::string str, std::string suffix) {
+ if (str.size() <= suffix.size()) {
+ return str;
+ }
+ if (str.substr(str.size() - suffix.size()).compare(suffix) == 0) {
+ return str.substr(0, str.size() - suffix.size());
+ }
+ return str;
+}
+
+} // namespace wasm
+
diff --git a/src/tools/wasm-as.cpp b/src/tools/wasm-as.cpp
index e8003a5ca..d4b495562 100644
--- a/src/tools/wasm-as.cpp
+++ b/src/tools/wasm-as.cpp
@@ -24,6 +24,8 @@
#include "wasm-binary.h"
#include "wasm-s-parser.h"
+#include "tool-utils.h"
+
using namespace cashew;
using namespace wasm;
@@ -68,6 +70,11 @@ int main(int argc, const char *argv[]) {
});
options.parse(argc, argv);
+ // default output is infile with changed suffix
+ if (options.extra.find("output") == options.extra.end()) {
+ options.extra["output"] = removeSpecificSuffix(options.extra["infile"], ".wast") + ".wasm";
+ }
+
auto input(read_file<std::string>(options.extra["infile"], Flags::Text, options.debug ? Flags::Debug : Flags::Release));
Module wasm;