From c4b55610d8cdd58e09b570c33c7484a60e500389 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 3 Jun 2010 21:11:20 +0000 Subject: Add a emit-llvm option to the plugin and make the path argument to also-emit-llvm optional. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@105414 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/gold/gold-plugin.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'tools/gold') diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index f04d9358ce..e34f773579 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -53,12 +53,15 @@ namespace { }; lto_codegen_model output_type = LTO_CODEGEN_PIC_MODEL_STATIC; + std::string output_name = ""; std::list Modules; std::vector Cleanup; } namespace options { + enum generate_bc { BC_NO, BC_ALSO, BC_ONLY }; static bool generate_api_file = false; + static generate_bc generate_bc_file = BC_NO; static std::string bc_path; static const char *as_path = NULL; // Additional options to pass into the code generator. @@ -82,8 +85,13 @@ namespace options { } else { as_path = strdup(opt + 3); } + } else if (strcmp("emit-llvm", opt) == 0) { + generate_bc_file = BC_ONLY; + } else if (strcmp("also-emit-llvm", opt) == 0) { + generate_bc_file = BC_ALSO; } else if (llvm::StringRef(opt).startswith("also-emit-llvm=")) { const char *path = opt + strlen("also-emit-llvm="); + generate_bc_file = BC_ALSO; if (!bc_path.empty()) { (*message)(LDPL_WARNING, "Path to the output IL file specified twice. " "Discarding %s", opt); @@ -122,6 +130,9 @@ ld_plugin_status onload(ld_plugin_tv *tv) { case LDPT_GOLD_VERSION: // major * 100 + minor gold_version = tv->tv_u.tv_val; break; + case LDPT_OUTPUT_NAME: + output_name = tv->tv_u.tv_string; + break; case LDPT_LINKER_OUTPUT: switch (tv->tv_u.tv_val) { case LDPO_REL: // .o @@ -381,10 +392,20 @@ static ld_plugin_status all_symbols_read_hook(void) { } } - if (!options::bc_path.empty()) { - bool err = lto_codegen_write_merged_modules(cg, options::bc_path.c_str()); + + if (options::generate_bc_file != options::BC_NO) { + std::string path; + if (options::generate_bc_file == options::BC_ONLY) + path = output_name; + else if (!options::bc_path.empty()) + path = options::bc_path; + else + path = output_name + ".bc"; + bool err = lto_codegen_write_merged_modules(cg, path.c_str()); if (err) (*message)(LDPL_FATAL, "Failed to write the output file."); + if (options::generate_bc_file == options::BC_ONLY) + exit(0); } size_t bufsize = 0; const char *buffer = static_cast(lto_codegen_compile(cg, -- cgit v1.2.3