summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-binary.cpp20
-rw-r--r--src/wasm/wasm-io.cpp9
2 files changed, 23 insertions, 6 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 514b489a9..44ce9a2d1 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -61,6 +61,9 @@ void WasmBinaryWriter::write() {
if (sourceMap) {
writeSourceMapEpilog();
}
+
+ writeUserSections();
+
finishUp();
}
@@ -551,6 +554,17 @@ static void writeBase64VLQ(std::ostream& out, int32_t n) {
}
}
+void WasmBinaryWriter::writeUserSections() {
+ for (auto& section : wasm->userSections) {
+ auto start = startSection(0);
+ writeInlineString(section.name.c_str());
+ for (size_t i = 0; i < section.data.size(); i++) {
+ o << uint8_t(section.data[i]);
+ }
+ finishSection(start);
+ }
+}
+
void WasmBinaryWriter::writeDebugLocation(size_t offset, const Function::DebugLocation& loc) {
if (lastBytecodeOffset > 0) {
*sourceMap << ",";
@@ -1626,9 +1640,9 @@ void WasmBinaryBuilder::readImports() {
case ExternalKind::Global: {
curr->globalType = getWasmType();
auto globalMutable = getU32LEB();
- if (globalMutable) {
- throw ParseException("imported globals cannot be mutable");
- }
+ // TODO: actually use the globalMutable flag. Currently mutable global
+ // imports is a future feature, to be implemented with thread support.
+ (void)globalMutable;
break;
}
default: {
diff --git a/src/wasm/wasm-io.cpp b/src/wasm/wasm-io.cpp
index ebc9af8de..1f50d7140 100644
--- a/src/wasm/wasm-io.cpp
+++ b/src/wasm/wasm-io.cpp
@@ -46,15 +46,18 @@ void ModuleReader::readBinary(std::string filename, Module& wasm) {
parser.read();
}
-void ModuleReader::read(std::string filename, Module& wasm) {
- // see if this is a wasm binary
+bool ModuleReader::isBinaryFile(std::string filename) {
std::ifstream infile;
std::ios_base::openmode flags = std::ifstream::in | std::ifstream::binary;
infile.open(filename, flags);
char buffer[4] = { 1, 2, 3, 4 };
infile.read(buffer, 4);
infile.close();
- if (buffer[0] == '\0' && buffer[1] == 'a' && buffer[2] == 's' && buffer[3] == 'm') {
+ return buffer[0] == '\0' && buffer[1] == 'a' && buffer[2] == 's' && buffer[3] == 'm';
+}
+
+void ModuleReader::read(std::string filename, Module& wasm) {
+ if (isBinaryFile(filename)) {
readBinary(filename, wasm);
} else {
// default to text