@@ -36,6 +36,8 @@ int main(int argc, const char *argv[]) {
3636 bool legalizeJavaScriptFFI = true ;
3737 Asm2WasmBuilder::TrapMode trapMode = Asm2WasmBuilder::TrapMode::JS;
3838 bool wasmOnly = false ;
39+ std::string sourceMapFilename;
40+ std::string sourceMapUrl;
3941 std::string symbolMap;
4042 bool emitBinary = true ;
4143
@@ -99,9 +101,15 @@ int main(int argc, const char *argv[]) {
99101 [&legalizeJavaScriptFFI](Options *o, const std::string &) {
100102 legalizeJavaScriptFFI = false ;
101103 })
102- .add (" --debuginfo" , " -g" , " Emit names section and debug info (for debug info you must emit text, -S, for this to work )" ,
104+ .add (" --debuginfo" , " -g" , " Emit names section in wasm binary (or full debuginfo in wast )" ,
103105 Options::Arguments::Zero,
104106 [&](Options *o, const std::string &arguments) { options.passOptions .debugInfo = true ; })
107+ .add (" --source-map" , " -sm" , " Emit source map (if using binary output) to the specified file" ,
108+ Options::Arguments::One,
109+ [&sourceMapFilename](Options *o, const std::string &argument) { sourceMapFilename = argument; })
110+ .add (" --source-map-url" , " -su" , " Use specified string as source map URL" ,
111+ Options::Arguments::One,
112+ [&sourceMapUrl](Options *o, const std::string &argument) { sourceMapUrl = argument; })
105113 .add (" --symbolmap" , " -s" , " Emit a symbol map (indexes => names)" ,
106114 Options::Arguments::One,
107115 [&](Options *o, const std::string &argument) { symbolMap = argument; })
@@ -136,8 +144,9 @@ int main(int argc, const char *argv[]) {
136144 }
137145
138146 Asm2WasmPreProcessor pre ;
139- // wasm binaries can contain a names section, but not full debug info
140- pre .debugInfo = options.passOptions .debugInfo && !emitBinary;
147+ // wasm binaries can contain a names section, but not full debug info --
148+ // debug info is disabled if a map file is not specified with wasm binary
149+ pre .debugInfo = options.passOptions .debugInfo && (!emitBinary || sourceMapFilename.size ());
141150 auto input (
142151 read_file<std::vector<char >>(options.extra [" infile" ], Flags::Text, options.debug ? Flags::Debug : Flags::Release));
143152 char *start = pre .process (input.data ());
@@ -204,6 +213,10 @@ int main(int argc, const char *argv[]) {
204213 writer.setDebugInfo (options.passOptions .debugInfo );
205214 writer.setSymbolMap (symbolMap);
206215 writer.setBinary (emitBinary);
216+ if (emitBinary) {
217+ writer.setSourceMapFilename (sourceMapFilename);
218+ writer.setSourceMapUrl (sourceMapUrl);
219+ }
207220 writer.write (wasm, options.extra [" output" ]);
208221
209222 if (options.debug ) std::cerr << " done." << std::endl;
0 commit comments