@@ -94,6 +94,9 @@ lto::Config BitcodeCompiler::createConfig() {
9494 WriteBitcodeToFile (m, *os, false );
9595 return false ;
9696 };
97+ } else if (ctx.config .emit == EmitKind::ASM) {
98+ c.CGFileType = CodeGenFileType::AssemblyFile;
99+ c.Options .MCOptions .AsmVerbose = true ;
97100 }
98101
99102 if (ctx.config .saveTemps )
@@ -213,6 +216,8 @@ std::vector<InputFile *> BitcodeCompiler::compile() {
213216 pruneCache (ctx.config .ltoCache , ctx.config .ltoCachePolicy , files);
214217
215218 std::vector<InputFile *> ret;
219+ bool emitASM = ctx.config .emit == EmitKind::ASM;
220+ const char *Ext = emitASM ? " .s" : " .obj" ;
216221 for (unsigned i = 0 ; i != maxTasks; ++i) {
217222 StringRef bitcodeFilePath;
218223 // Get the native object contents either from the cache or from memory. Do
@@ -235,20 +240,21 @@ std::vector<InputFile *> BitcodeCompiler::compile() {
235240 if (bitcodeFilePath == " ld-temp.o" ) {
236241 ltoObjName =
237242 saver ().save (Twine (ctx.config .outputFile ) + " .lto" +
238- (i == 0 ? Twine (" " ) : Twine (' .' ) + Twine (i)) + " .obj " );
243+ (i == 0 ? Twine (" " ) : Twine (' .' ) + Twine (i)) + Ext );
239244 } else {
240245 StringRef directory = sys::path::parent_path (bitcodeFilePath);
241- StringRef baseName = sys::path::filename (bitcodeFilePath);
246+ StringRef baseName = sys::path::stem (bitcodeFilePath);
242247 StringRef outputFileBaseName = sys::path::filename (ctx.config .outputFile );
243248 SmallString<64 > path;
244249 sys::path::append (path, directory,
245- outputFileBaseName + " .lto." + baseName);
250+ outputFileBaseName + " .lto." + baseName + Ext );
246251 sys::path::remove_dots (path, true );
247252 ltoObjName = saver ().save (path.str ());
248253 }
249- if (ctx.config .saveTemps )
254+ if (ctx.config .saveTemps || emitASM )
250255 saveBuffer (buf[i].second , ltoObjName);
251- ret.push_back (make<ObjFile>(ctx, MemoryBufferRef (objBuf, ltoObjName)));
256+ if (!emitASM)
257+ ret.push_back (make<ObjFile>(ctx, MemoryBufferRef (objBuf, ltoObjName)));
252258 }
253259
254260 return ret;
0 commit comments