Change public functions of LTOCodeGenerator from ret-false-on-succ to ret-true-on-succ.

As of this revision, all functions of LTOCodeGenerator are consistent in
ret-true-on-succ.

Tested on multiple OSes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187864 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Shuxin Yang 2013-08-07 05:19:23 +00:00
parent 51c9043f3b
commit 235089bdae
3 changed files with 30 additions and 26 deletions

View File

@ -128,31 +128,29 @@ bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) {
for (int i = 0, e = undefs.size(); i != e; ++i)
_asmUndefinedRefs[undefs[i]] = 1;
return ret;
return !ret;
}
bool LTOCodeGenerator::setDebugInfo(lto_debug_model debug,
std::string& errMsg) {
void LTOCodeGenerator::setDebugInfo(lto_debug_model debug) {
switch (debug) {
case LTO_DEBUG_MODEL_NONE:
_emitDwarfDebugInfo = false;
return false;
return;
case LTO_DEBUG_MODEL_DWARF:
_emitDwarfDebugInfo = true;
return false;
return;
}
llvm_unreachable("Unknown debug format!");
}
bool LTOCodeGenerator::setCodePICModel(lto_codegen_model model,
std::string& errMsg) {
void LTOCodeGenerator::setCodePICModel(lto_codegen_model model) {
switch (model) {
case LTO_CODEGEN_PIC_MODEL_STATIC:
case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
_codeModel = model;
return false;
return;
}
llvm_unreachable("Unknown PIC model!");
}
@ -160,7 +158,7 @@ bool LTOCodeGenerator::setCodePICModel(lto_codegen_model model,
bool LTOCodeGenerator::writeMergedModules(const char *path,
std::string &errMsg) {
if (!determineTarget(errMsg))
return true;
return false;
// Run the verifier on the merged modules.
PassManager passes;
@ -173,7 +171,7 @@ bool LTOCodeGenerator::writeMergedModules(const char *path,
if (!ErrInfo.empty()) {
errMsg = "could not open bitcode file for writing: ";
errMsg += path;
return true;
return false;
}
// write bitcode to it
@ -184,11 +182,11 @@ bool LTOCodeGenerator::writeMergedModules(const char *path,
errMsg = "could not write bitcode file: ";
errMsg += path;
Out.os().clear_error();
return true;
return false;
}
Out.keep();
return false;
return true;
}
bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) {
@ -198,7 +196,7 @@ bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) {
error_code EC = sys::fs::createTemporaryFile("lto-llvm", "o", FD, Filename);
if (EC) {
errMsg = EC.message();
return true;
return false;
}
// generate object file
@ -209,23 +207,23 @@ bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) {
if (objFile.os().has_error()) {
objFile.os().clear_error();
sys::fs::remove(Twine(Filename));
return true;
return false;
}
objFile.keep();
if (!genResult) {
sys::fs::remove(Twine(Filename));
return true;
return false;
}
_nativeObjectPath = Filename.c_str();
*name = _nativeObjectPath.c_str();
return false;
return true;
}
const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg) {
const char *name;
if (compile_to_file(&name, errMsg))
if (!compile_to_file(&name, errMsg))
return NULL;
// remove old buffer if compile() called twice

View File

@ -61,9 +61,11 @@ struct LTOCodeGenerator {
LTOCodeGenerator();
~LTOCodeGenerator();
// Merge given module, return true on success.
bool addModule(struct LTOModule*, std::string &errMsg);
bool setDebugInfo(lto_debug_model, std::string &errMsg);
bool setCodePICModel(lto_codegen_model, std::string &errMsg);
void setDebugInfo(lto_debug_model);
void setCodePICModel(lto_codegen_model);
void setCpu(const char* mCpu) { _mCpu = mCpu; }
@ -78,11 +80,13 @@ struct LTOCodeGenerator {
//
void setCodeGenDebugOptions(const char *opts);
// Write the merged module to the file specified by the given path.
// Return true on success.
bool writeMergedModules(const char *path, std::string &errMsg);
// Compile the merged module into a *single* object file; the path to object
// file is returned to the caller via argument "name". Return *FALSE* on
// *SUCCESS*, true otherwise.
// file is returned to the caller via argument "name". Return true on
// success.
//
// NOTE that it is up to the linker to remove the intermediate object file.
// Do not try to remove the object file in LTOCodeGenerator's destructor

View File

@ -140,20 +140,22 @@ void lto_codegen_dispose(lto_code_gen_t cg) {
/// which code will be generated. Returns true on error (check
/// lto_get_error_message() for details).
bool lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod) {
return cg->addModule(mod, sLastErrorString);
return !cg->addModule(mod, sLastErrorString);
}
/// lto_codegen_set_debug_model - Sets what if any format of debug info should
/// be generated. Returns true on error (check lto_get_error_message() for
/// details).
bool lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model debug) {
return cg->setDebugInfo(debug, sLastErrorString);
cg->setDebugInfo(debug);
return false;
}
/// lto_codegen_set_pic_model - Sets what code model to generated. Returns true
/// on error (check lto_get_error_message() for details).
bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model) {
return cg->setCodePICModel(model, sLastErrorString);
cg->setCodePICModel(model);
return false;
}
/// lto_codegen_set_cpu - Sets the cpu to generate code for.
@ -185,7 +187,7 @@ void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg,
/// that contains the merged contents of all modules added so far. Returns true
/// on error (check lto_get_error_message() for details).
bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) {
return cg->writeMergedModules(path, sLastErrorString);
return !cg->writeMergedModules(path, sLastErrorString);
}
/// lto_codegen_compile - Generates code for all added modules into one native
@ -202,7 +204,7 @@ const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) {
/// native object file. The name of the file is written to name. Returns true on
/// error.
bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
return cg->compile_to_file(name, sLastErrorString);
return !cg->compile_to_file(name, sLastErrorString);
}
/// lto_codegen_debug_options - Used to pass extra options to the code