From 73d7a299c94d9edb91ad352c7e871dc0d498dd5d Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Sat, 11 Oct 2008 13:07:59 +0200 Subject: [PATCH] Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s. Call to gcc to convert assembly to object file still required. --- dmd/mars.c | 37 +++++++++++++++++++++++++------------ dmd/mars.h | 6 ++++-- dmd/module.c | 2 +- gen/toobj.cpp | 42 ++++++++++++++++++++++++++---------------- 4 files changed, 56 insertions(+), 31 deletions(-) diff --git a/dmd/mars.c b/dmd/mars.c index e9e98006..6ece1e42 100644 --- a/dmd/mars.c +++ b/dmd/mars.c @@ -52,13 +52,13 @@ Global::Global() ddoc_ext = "ddoc"; // LDC - obj_ext = "bc"; ll_ext = "ll"; bc_ext = "bc"; + s_ext = "s"; #if _WIN32 - nativeobj_ext = "obj"; + obj_ext = "obj"; #elif POSIX - nativeobj_ext = "o"; + obj_ext = "o"; #else #error "fix this" #endif @@ -167,6 +167,10 @@ Usage:\n\ -od write object files to directory \n\ -op do not strip paths from source file\n\ -oq write object files with fully qualified names\n\ +\n\ + -output-ll write LLVM IR\n\ + -output-bc write LLVM bitcode\n\ + -output-s write native assembly\n\ \n\ -c do not link\n\ -L pass to llvm-ld\n\ @@ -216,7 +220,6 @@ Codegen control:\n\ -d allow deprecated features\n\ \n\ -annotate annotate the bitcode with human readable source code\n\ - -dis disassemble module after compiling\n\ -ignore ignore unsupported pragmas\n\ \n\ Path options:\n\ @@ -404,8 +407,6 @@ int main(int argc, char *argv[]) global.params.noruntime = 1; else if (strcmp(p + 1, "noverify") == 0) global.params.novalidate = 1; - else if (strcmp(p + 1, "dis") == 0) - global.params.disassemble = 1; else if (strcmp(p + 1, "annotate") == 0) global.params.llvmAnnotate = 1; else if (strncmp(p + 1, "enable-", 7) == 0 || @@ -463,6 +464,19 @@ int main(int argc, char *argv[]) global.params.fqnNames = 1; break; + case 'u': + if (strncmp(p+1, "output-", 7) != 0) + goto Lerror; + if (strcmp(p+8, "ll") == 0) + global.params.output_ll = 1; + else if (strcmp(p+8, "bc") == 0) + global.params.output_bc = 1; + else if (strcmp(p+8, "s") == 0) + global.params.output_s = 1; + else + goto Lerror; + break; + case 0: error("-o no longer supported, use -of or -od"); break; @@ -918,13 +932,12 @@ int main(int argc, char *argv[]) ext = FileName::ext(p); if (ext) { -#if IN_LLVM - if (strcmp(ext, global.nativeobj_ext) == 0 || - strcmp(ext, global.obj_ext) == 0) -#elif TARGET_LINUX - if (strcmp(ext, global.obj_ext) == 0) +#if TARGET_LINUX + if (strcmp(ext, global.obj_ext) == 0 || + strcmp(ext, global.bc_ext) == 0) #else - if (stricmp(ext, global.obj_ext) == 0) + if (stricmp(ext, global.obj_ext) == 0 || + stricmp(ext, global.bc_ext) == 0) #endif { global.params.objfiles->push(files.data[i]); diff --git a/dmd/mars.h b/dmd/mars.h index c4e0d0de..923a460c 100644 --- a/dmd/mars.h +++ b/dmd/mars.h @@ -145,7 +145,9 @@ struct Param char *tt_arch; char *tt_os; char *data_layout; - char disassemble; + char output_ll; + char output_bc; + char output_s; char llvmInline; char llvmAnnotate; char useInlineAsm; @@ -160,7 +162,7 @@ struct Global char *obj_ext; char *ll_ext; char *bc_ext; - char *nativeobj_ext; + char *s_ext; char *doc_ext; // for Ddoc generated files char *ddoc_ext; // for Ddoc macro include files char *hdr_ext; // for D 'header' import files diff --git a/dmd/module.c b/dmd/module.c index f603c386..d96d3993 100644 --- a/dmd/module.c +++ b/dmd/module.c @@ -180,7 +180,7 @@ void Module::buildTargetFiles() return; if(!objfile) - objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.bc_ext); + objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.obj_ext); if(doDocComment && !docfile) docfile = Module::buildFilePath(global.params.docname, global.params.docdir, global.doc_ext); if(doHdrGen && !hdrfile) diff --git a/gen/toobj.cpp b/gen/toobj.cpp index 8d605570..2300171d 100644 --- a/gen/toobj.cpp +++ b/gen/toobj.cpp @@ -179,33 +179,43 @@ void Module::genobjfile(int multiobj) // eventually do our own path stuff, dmd's is a bit strange. typedef llvm::sys::Path LLPath; - LLPath bcpath = LLPath(objfile->name->toChars()); - LLPath llpath = bcpath; - llpath.eraseSuffix(); - llpath.appendSuffix(std::string(global.ll_ext)); - // write bytecode - { + // write LLVM bitcode + if (global.params.output_bc) { + LLPath bcpath = LLPath(objfile->name->toChars()); + bcpath.eraseSuffix(); + bcpath.appendSuffix(std::string(global.bc_ext)); Logger::println("Writing LLVM bitcode to: %s\n", bcpath.c_str()); std::ofstream bos(bcpath.c_str(), std::ios::binary); llvm::WriteBitcodeToFile(ir.module, bos); } - // disassemble ? - if (global.params.disassemble) { + // write LLVM IR + if (global.params.output_ll) { + LLPath llpath = LLPath(objfile->name->toChars()); + llpath.eraseSuffix(); + llpath.appendSuffix(std::string(global.ll_ext)); Logger::println("Writing LLVM asm to: %s\n", llpath.c_str()); std::ofstream aos(llpath.c_str()); ir.module->print(aos, NULL); } - //TODO: command line switch - if(false) - { - //FIXME: Proper out file name. - Logger::println("Writing native asm to: %s\n", ""); - std::string err; - llvm::raw_fd_ostream out("test.s", err); - write_asm_to_file(*ir.module, out); + // write native assembly + LLPath spath = LLPath(objfile->name->toChars()); + spath.eraseSuffix(); + spath.appendSuffix(std::string(global.s_ext)); + if (!global.params.output_s) { + spath.createTemporaryFileOnDisk(); + } + Logger::println("Writing native asm to: %s\n", spath.c_str()); + std::string err; + llvm::raw_fd_ostream out(spath.c_str(), err); + write_asm_to_file(*ir.module, out); + + //TODO: call gcc to convert assembly to object file + + if (!global.params.output_s) { + spath.eraseFromDisk(); } delete ir.module;