summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2020-06-11 16:18:54 -0700
committerGitHub <noreply@github.com>2020-06-11 16:18:54 -0700
commit49f2443338c00931d2f30f9d8c1706398bd5cb34 (patch)
treebdb148f40eeacb4ef139c85bad17970a870b1880
parentf813ac9fd58849043ed25c8543af6f6a884d506c (diff)
downloadbinaryen-49f2443338c00931d2f30f9d8c1706398bd5cb34.tar.gz
binaryen-49f2443338c00931d2f30f9d8c1706398bd5cb34.tar.bz2
binaryen-49f2443338c00931d2f30f9d8c1706398bd5cb34.zip
Move optional metadata field so its not last (#2909)
To avoid the conditional trailing comma.
-rw-r--r--scripts/test/lld.py21
-rw-r--r--src/wasm/wasm-emscripten.cpp16
-rw-r--r--test/lld/basic_safe_stack.wat.out4
-rw-r--r--test/lld/bigint.wat.out4
-rw-r--r--test/lld/duplicate_imports.wat.out4
-rw-r--r--test/lld/em_asm.wat.mem.out4
-rw-r--r--test/lld/em_asm.wat.out4
-rw-r--r--test/lld/em_asm_O0.wat.out4
-rw-r--r--test/lld/em_asm_main_thread.wat.out4
-rw-r--r--test/lld/em_asm_shared.wat.out4
-rw-r--r--test/lld/em_asm_table.wat.out4
-rw-r--r--test/lld/em_js_O0.wat.out4
-rw-r--r--test/lld/gdollar_mainmodule.wat.out4
-rw-r--r--test/lld/hello_world.passive.wat.out4
-rw-r--r--test/lld/hello_world.wat.mem.out4
-rw-r--r--test/lld/hello_world.wat.out4
-rw-r--r--test/lld/init.wat.out4
-rw-r--r--test/lld/longjmp.wat.out4
-rw-r--r--test/lld/main_module.wat.out4
-rw-r--r--test/lld/main_module_table.wat.out4
-rw-r--r--test/lld/main_module_table_2.wat.out4
-rw-r--r--test/lld/main_module_table_3.wat.out4
-rw-r--r--test/lld/main_module_table_4.wat.out4
-rw-r--r--test/lld/main_module_table_5.wat.out4
-rw-r--r--test/lld/recursive.wat.out4
-rw-r--r--test/lld/recursive_safe_stack.wat.out4
-rw-r--r--test/lld/reserved_func_ptr.wat.out4
-rw-r--r--test/lld/safe_stack_standalone-wasm.wat.out2
-rw-r--r--test/lld/shared.wat.out4
-rw-r--r--test/lld/shared_add_to_table.wasm.out4
-rw-r--r--test/lld/shared_longjmp.wat.out4
-rw-r--r--test/lld/standalone-wasm-with-start.wat.out2
-rw-r--r--test/lld/standalone-wasm.wat.out2
-rw-r--r--test/lld/standalone-wasm2.wat.out2
-rw-r--r--test/lld/standalone-wasm3.wat.out2
35 files changed, 84 insertions, 75 deletions
diff --git a/scripts/test/lld.py b/scripts/test/lld.py
index 1407ea4b7..5732f7332 100644
--- a/scripts/test/lld.py
+++ b/scripts/test/lld.py
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import json
import os
from . import shared
from . import support
@@ -43,18 +44,26 @@ def run_test(input_path):
})
for ext, args in extension_arg_map.items():
expected_file = input_path + ext
- if ext != '.out' and not os.path.exists(expected_file):
- continue
+ if not os.path.exists(expected_file):
+ if ext == '.out':
+ shared.fail_with_error('output ' + expected_file +
+ ' does not exist')
+ else:
+ continue
cmd = shared.WASM_EMSCRIPTEN_FINALIZE + [input_path, '-S'] + args
cmd += args_for_finalize(os.path.basename(input_path))
actual = support.run_command(cmd)
- if not os.path.exists(expected_file):
- print(actual)
- shared.fail_with_error('output ' + expected_file +
- ' does not exist')
shared.fail_if_not_identical_to_file(actual, expected_file)
+ if ext == '.out':
+ start = actual.find('--BEGIN METADATA --\n')
+ end = actual.find('-- END METADATA --\n')
+ if start == -1 or end == -1:
+ shared.fail_with_error('json metadata tags not found')
+ the_json = actual[start + len('--BEGIN METADATA --\n'):end]
+ json.loads(the_json)
+
if ext == '.mem.out':
with open(mem_file) as mf:
mem = mf.read()
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index a57573254..4a8f2c0c3 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -1217,13 +1217,6 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata(
});
meta << "\n ],\n";
- meta << " \"features\": [";
- commaFirst = true;
- wasm.features.iterFeatures([&](FeatureSet::Feature f) {
- meta << nextElement() << "\"--enable-" << FeatureSet::toString(f) << '"';
- });
- meta << "\n ],\n";
-
// In normal mode we attempt to determine if main takes argumnts or not
// In standalone mode we export _start instead and rely on the presence
// of the __wasi_args_get and __wasi_args_sizes_get syscalls allow us to
@@ -1247,9 +1240,16 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata(
}
}
}
- meta << " \"mainReadsParams\": " << int(mainReadsParams) << '\n';
+ meta << " \"mainReadsParams\": " << int(mainReadsParams) << ",\n";
}
+ meta << " \"features\": [";
+ commaFirst = true;
+ wasm.features.iterFeatures([&](FeatureSet::Feature f) {
+ meta << nextElement() << "\"--enable-" << FeatureSet::toString(f) << '"';
+ });
+ meta << "\n ]\n";
+
meta << "}\n";
return meta.str();
diff --git a/test/lld/basic_safe_stack.wat.out b/test/lld/basic_safe_stack.wat.out
index 525a31ef2..a72f3d215 100644
--- a/test/lld/basic_safe_stack.wat.out
+++ b/test/lld/basic_safe_stack.wat.out
@@ -102,9 +102,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 1,
"features": [
- ],
- "mainReadsParams": 1
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/bigint.wat.out b/test/lld/bigint.wat.out
index 44146d07d..d45da9dea 100644
--- a/test/lld/bigint.wat.out
+++ b/test/lld/bigint.wat.out
@@ -42,9 +42,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/duplicate_imports.wat.out b/test/lld/duplicate_imports.wat.out
index 6493137e9..2163841ed 100644
--- a/test/lld/duplicate_imports.wat.out
+++ b/test/lld/duplicate_imports.wat.out
@@ -77,9 +77,9 @@
"invokeFuncs": [
"invoke_ffd"
],
+ "mainReadsParams": 1,
"features": [
- ],
- "mainReadsParams": 1
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/em_asm.wat.mem.out b/test/lld/em_asm.wat.mem.out
index 96346d374..c840be861 100644
--- a/test/lld/em_asm.wat.mem.out
+++ b/test/lld/em_asm.wat.mem.out
@@ -100,9 +100,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/em_asm.wat.out b/test/lld/em_asm.wat.out
index 68d1be09d..64cf00069 100644
--- a/test/lld/em_asm.wat.out
+++ b/test/lld/em_asm.wat.out
@@ -101,9 +101,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/em_asm_O0.wat.out b/test/lld/em_asm_O0.wat.out
index 232f0fa9d..f68965876 100644
--- a/test/lld/em_asm_O0.wat.out
+++ b/test/lld/em_asm_O0.wat.out
@@ -82,9 +82,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 1,
"features": [
- ],
- "mainReadsParams": 1
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/em_asm_main_thread.wat.out b/test/lld/em_asm_main_thread.wat.out
index d20895833..e6acc68d4 100644
--- a/test/lld/em_asm_main_thread.wat.out
+++ b/test/lld/em_asm_main_thread.wat.out
@@ -224,9 +224,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/em_asm_shared.wat.out b/test/lld/em_asm_shared.wat.out
index 4126a1abb..8819abed3 100644
--- a/test/lld/em_asm_shared.wat.out
+++ b/test/lld/em_asm_shared.wat.out
@@ -144,9 +144,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/em_asm_table.wat.out b/test/lld/em_asm_table.wat.out
index 9f01b5b7f..024298055 100644
--- a/test/lld/em_asm_table.wat.out
+++ b/test/lld/em_asm_table.wat.out
@@ -56,9 +56,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/em_js_O0.wat.out b/test/lld/em_js_O0.wat.out
index 8b5f3024e..af048242e 100644
--- a/test/lld/em_js_O0.wat.out
+++ b/test/lld/em_js_O0.wat.out
@@ -37,9 +37,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/gdollar_mainmodule.wat.out b/test/lld/gdollar_mainmodule.wat.out
index b7a55efb1..cbefc6c47 100644
--- a/test/lld/gdollar_mainmodule.wat.out
+++ b/test/lld/gdollar_mainmodule.wat.out
@@ -73,9 +73,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 1,
"features": [
- ],
- "mainReadsParams": 1
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/hello_world.passive.wat.out b/test/lld/hello_world.passive.wat.out
index 097a2de94..ab580104f 100644
--- a/test/lld/hello_world.passive.wat.out
+++ b/test/lld/hello_world.passive.wat.out
@@ -67,9 +67,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/hello_world.wat.mem.out b/test/lld/hello_world.wat.mem.out
index 0df58bb99..cdd378f72 100644
--- a/test/lld/hello_world.wat.mem.out
+++ b/test/lld/hello_world.wat.mem.out
@@ -56,9 +56,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/hello_world.wat.out b/test/lld/hello_world.wat.out
index f78baa05f..c33b0ff70 100644
--- a/test/lld/hello_world.wat.out
+++ b/test/lld/hello_world.wat.out
@@ -57,9 +57,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/init.wat.out b/test/lld/init.wat.out
index 32ae0dbc3..d5a3b8b81 100644
--- a/test/lld/init.wat.out
+++ b/test/lld/init.wat.out
@@ -69,9 +69,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/longjmp.wat.out b/test/lld/longjmp.wat.out
index 78ac95fe0..97c391ad0 100644
--- a/test/lld/longjmp.wat.out
+++ b/test/lld/longjmp.wat.out
@@ -177,9 +177,9 @@
"invokeFuncs": [
"invoke_vii"
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/main_module.wat.out b/test/lld/main_module.wat.out
index 826b58fa3..4169c9693 100644
--- a/test/lld/main_module.wat.out
+++ b/test/lld/main_module.wat.out
@@ -117,9 +117,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/main_module_table.wat.out b/test/lld/main_module_table.wat.out
index 08f3e6508..3f3c7ee10 100644
--- a/test/lld/main_module_table.wat.out
+++ b/test/lld/main_module_table.wat.out
@@ -61,9 +61,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/main_module_table_2.wat.out b/test/lld/main_module_table_2.wat.out
index df14789f0..af92e7ea2 100644
--- a/test/lld/main_module_table_2.wat.out
+++ b/test/lld/main_module_table_2.wat.out
@@ -61,9 +61,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/main_module_table_3.wat.out b/test/lld/main_module_table_3.wat.out
index d473959bc..2df18b7b3 100644
--- a/test/lld/main_module_table_3.wat.out
+++ b/test/lld/main_module_table_3.wat.out
@@ -61,9 +61,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/main_module_table_4.wat.out b/test/lld/main_module_table_4.wat.out
index fd78f9237..221864563 100644
--- a/test/lld/main_module_table_4.wat.out
+++ b/test/lld/main_module_table_4.wat.out
@@ -61,9 +61,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/main_module_table_5.wat.out b/test/lld/main_module_table_5.wat.out
index 01bb7ffaf..32a089127 100644
--- a/test/lld/main_module_table_5.wat.out
+++ b/test/lld/main_module_table_5.wat.out
@@ -67,9 +67,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/recursive.wat.out b/test/lld/recursive.wat.out
index eb0f04321..0e118dc13 100644
--- a/test/lld/recursive.wat.out
+++ b/test/lld/recursive.wat.out
@@ -115,9 +115,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/recursive_safe_stack.wat.out b/test/lld/recursive_safe_stack.wat.out
index d5a5d6303..b84820e09 100644
--- a/test/lld/recursive_safe_stack.wat.out
+++ b/test/lld/recursive_safe_stack.wat.out
@@ -177,9 +177,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/reserved_func_ptr.wat.out b/test/lld/reserved_func_ptr.wat.out
index 20ad96bf5..1ec059701 100644
--- a/test/lld/reserved_func_ptr.wat.out
+++ b/test/lld/reserved_func_ptr.wat.out
@@ -150,9 +150,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 1,
"features": [
- ],
- "mainReadsParams": 1
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/safe_stack_standalone-wasm.wat.out b/test/lld/safe_stack_standalone-wasm.wat.out
index 81f62a0dd..a7b828a03 100644
--- a/test/lld/safe_stack_standalone-wasm.wat.out
+++ b/test/lld/safe_stack_standalone-wasm.wat.out
@@ -186,7 +186,7 @@
"invokeFuncs": [
],
"features": [
- ],
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/shared.wat.out b/test/lld/shared.wat.out
index 973902149..f83855f3b 100644
--- a/test/lld/shared.wat.out
+++ b/test/lld/shared.wat.out
@@ -93,9 +93,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/shared_add_to_table.wasm.out b/test/lld/shared_add_to_table.wasm.out
index e64e031a9..26c0fa7af 100644
--- a/test/lld/shared_add_to_table.wasm.out
+++ b/test/lld/shared_add_to_table.wasm.out
@@ -118,9 +118,9 @@
},
"invokeFuncs": [
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/shared_longjmp.wat.out b/test/lld/shared_longjmp.wat.out
index eda443edc..4e6589f4a 100644
--- a/test/lld/shared_longjmp.wat.out
+++ b/test/lld/shared_longjmp.wat.out
@@ -198,9 +198,9 @@
"invokeFuncs": [
"invoke_vii"
],
+ "mainReadsParams": 0,
"features": [
- ],
- "mainReadsParams": 0
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/standalone-wasm-with-start.wat.out b/test/lld/standalone-wasm-with-start.wat.out
index 367a26168..d463d0bfb 100644
--- a/test/lld/standalone-wasm-with-start.wat.out
+++ b/test/lld/standalone-wasm-with-start.wat.out
@@ -44,7 +44,7 @@
"invokeFuncs": [
],
"features": [
- ],
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/standalone-wasm.wat.out b/test/lld/standalone-wasm.wat.out
index 3a483bdf7..3d1137fab 100644
--- a/test/lld/standalone-wasm.wat.out
+++ b/test/lld/standalone-wasm.wat.out
@@ -59,7 +59,7 @@
"invokeFuncs": [
],
"features": [
- ],
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/standalone-wasm2.wat.out b/test/lld/standalone-wasm2.wat.out
index d6a0c5505..8700e2844 100644
--- a/test/lld/standalone-wasm2.wat.out
+++ b/test/lld/standalone-wasm2.wat.out
@@ -56,7 +56,7 @@
"invokeFuncs": [
],
"features": [
- ],
+ ]
}
-- END METADATA --
;)
diff --git a/test/lld/standalone-wasm3.wat.out b/test/lld/standalone-wasm3.wat.out
index 65557a790..b0db5cb77 100644
--- a/test/lld/standalone-wasm3.wat.out
+++ b/test/lld/standalone-wasm3.wat.out
@@ -37,7 +37,7 @@
"invokeFuncs": [
],
"features": [
- ],
+ ]
}
-- END METADATA --
;)