#include <stdint.h>
#include <string>
+#include <sstream>
#include <stdlib.h>
#include "s2wasm.h"
struct BinaryenRustModule {
BufferWithRandomAccess buffer;
+ std::string sourceMapJSON;
};
struct BinaryenRustModuleOptions {
bool ignoreUnknownSymbols;
bool debugInfo;
std::string startFunction;
+ std::string sourceMapUrl;
BinaryenRustModuleOptions() :
globalBase(0),
importMemory(false),
ignoreUnknownSymbols(false),
debugInfo(false),
- startFunction("")
+ startFunction(""),
+ sourceMapUrl("")
{}
};
options->startFunction = start;
}
+extern "C" void
+BinaryenRustModuleOptionsSetSourceMapUrl(BinaryenRustModuleOptions *options,
+ char *sourceMapUrl) {
+ options->sourceMapUrl = sourceMapUrl;
+}
+
extern "C" void
BinaryenRustModuleOptionsSetStackAllocation(BinaryenRustModuleOptions *options,
uint64_t stack) {
{
WasmBinaryWriter writer(&linker.getOutput().wasm, ret->buffer, options->debug);
writer.setNamesSection(options->debugInfo);
- // FIXME: support source maps?
- // writer.setSourceMap(sourceMapStream.get(), sourceMapUrl);
+
+ std::unique_ptr<std::ostringstream> sourceMapStream = nullptr;
+ {
+ sourceMapStream = make_unique<std::ostringstream>();
+ writer.setSourceMap(sourceMapStream.get(), options->sourceMapUrl);
+ }
// FIXME: support symbol maps?
// writer.setSymbolMap(symbolMap);
writer.write();
+
+ if (sourceMapStream) {
+ ret->sourceMapJSON = sourceMapStream->str();
+ }
}
return ret.release();
}
return M->buffer.size();
}
+extern "C" const char*
+BinaryenRustModuleSourceMapPtr(const BinaryenRustModule *M) {
+ return M->sourceMapJSON.data();
+}
+
+extern "C" size_t
+BinaryenRustModuleSourceMapLen(const BinaryenRustModule *M) {
+ return M->sourceMapJSON.length();
+}
+
extern "C" void
BinaryenRustModuleFree(BinaryenRustModule *M) {
delete M;