llvm.org GIT mirror llvm / 235089b
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 Shuxin Yang 7 years ago
3 changed file(s) with 32 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
127127 for (int i = 0, e = undefs.size(); i != e; ++i)
128128 _asmUndefinedRefs[undefs[i]] = 1;
129129
130 return ret;
131 }
132
133 bool LTOCodeGenerator::setDebugInfo(lto_debug_model debug,
134 std::string& errMsg) {
130 return !ret;
131 }
132
133 void LTOCodeGenerator::setDebugInfo(lto_debug_model debug) {
135134 switch (debug) {
136135 case LTO_DEBUG_MODEL_NONE:
137136 _emitDwarfDebugInfo = false;
138 return false;
137 return;
139138
140139 case LTO_DEBUG_MODEL_DWARF:
141140 _emitDwarfDebugInfo = true;
142 return false;
141 return;
143142 }
144143 llvm_unreachable("Unknown debug format!");
145144 }
146145
147 bool LTOCodeGenerator::setCodePICModel(lto_codegen_model model,
148 std::string& errMsg) {
146 void LTOCodeGenerator::setCodePICModel(lto_codegen_model model) {
149147 switch (model) {
150148 case LTO_CODEGEN_PIC_MODEL_STATIC:
151149 case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
152150 case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
153151 _codeModel = model;
154 return false;
152 return;
155153 }
156154 llvm_unreachable("Unknown PIC model!");
157155 }
159157 bool LTOCodeGenerator::writeMergedModules(const char *path,
160158 std::string &errMsg) {
161159 if (!determineTarget(errMsg))
162 return true;
160 return false;
163161
164162 // Run the verifier on the merged modules.
165163 PassManager passes;
172170 if (!ErrInfo.empty()) {
173171 errMsg = "could not open bitcode file for writing: ";
174172 errMsg += path;
175 return true;
173 return false;
176174 }
177175
178176 // write bitcode to it
183181 errMsg = "could not write bitcode file: ";
184182 errMsg += path;
185183 Out.os().clear_error();
186 return true;
184 return false;
187185 }
188186
189187 Out.keep();
190 return false;
188 return true;
191189 }
192190
193191 bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) {
197195 error_code EC = sys::fs::createTemporaryFile("lto-llvm", "o", FD, Filename);
198196 if (EC) {
199197 errMsg = EC.message();
200 return true;
198 return false;
201199 }
202200
203201 // generate object file
208206 if (objFile.os().has_error()) {
209207 objFile.os().clear_error();
210208 sys::fs::remove(Twine(Filename));
211 return true;
209 return false;
212210 }
213211
214212 objFile.keep();
215213 if (!genResult) {
216214 sys::fs::remove(Twine(Filename));
217 return true;
215 return false;
218216 }
219217
220218 _nativeObjectPath = Filename.c_str();
221219 *name = _nativeObjectPath.c_str();
222 return false;
220 return true;
223221 }
224222
225223 const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg) {
226224 const char *name;
227 if (compile_to_file(&name, errMsg))
225 if (!compile_to_file(&name, errMsg))
228226 return NULL;
229227
230228 // remove old buffer if compile() called twice
6060 LTOCodeGenerator();
6161 ~LTOCodeGenerator();
6262
63 // Merge given module, return true on success.
6364 bool addModule(struct LTOModule*, std::string &errMsg);
64 bool setDebugInfo(lto_debug_model, std::string &errMsg);
65 bool setCodePICModel(lto_codegen_model, std::string &errMsg);
65
66 void setDebugInfo(lto_debug_model);
67 void setCodePICModel(lto_codegen_model);
6668
6769 void setCpu(const char* mCpu) { _mCpu = mCpu; }
6870
7779 //
7880 void setCodeGenDebugOptions(const char *opts);
7981
82 // Write the merged module to the file specified by the given path.
83 // Return true on success.
8084 bool writeMergedModules(const char *path, std::string &errMsg);
8185
8286 // Compile the merged module into a *single* object file; the path to object
83 // file is returned to the caller via argument "name". Return *FALSE* on
84 // *SUCCESS*, true otherwise.
87 // file is returned to the caller via argument "name". Return true on
88 // success.
8589 //
8690 // NOTE that it is up to the linker to remove the intermediate object file.
8791 // Do not try to remove the object file in LTOCodeGenerator's destructor
139139 /// which code will be generated. Returns true on error (check
140140 /// lto_get_error_message() for details).
141141 bool lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod) {
142 return cg->addModule(mod, sLastErrorString);
142 return !cg->addModule(mod, sLastErrorString);
143143 }
144144
145145 /// lto_codegen_set_debug_model - Sets what if any format of debug info should
146146 /// be generated. Returns true on error (check lto_get_error_message() for
147147 /// details).
148148 bool lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model debug) {
149 return cg->setDebugInfo(debug, sLastErrorString);
149 cg->setDebugInfo(debug);
150 return false;
150151 }
151152
152153 /// lto_codegen_set_pic_model - Sets what code model to generated. Returns true
153154 /// on error (check lto_get_error_message() for details).
154155 bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model) {
155 return cg->setCodePICModel(model, sLastErrorString);
156 cg->setCodePICModel(model);
157 return false;
156158 }
157159
158160 /// lto_codegen_set_cpu - Sets the cpu to generate code for.
184186 /// that contains the merged contents of all modules added so far. Returns true
185187 /// on error (check lto_get_error_message() for details).
186188 bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) {
187 return cg->writeMergedModules(path, sLastErrorString);
189 return !cg->writeMergedModules(path, sLastErrorString);
188190 }
189191
190192 /// lto_codegen_compile - Generates code for all added modules into one native
201203 /// native object file. The name of the file is written to name. Returns true on
202204 /// error.
203205 bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
204 return cg->compile_to_file(name, sLastErrorString);
206 return !cg->compile_to_file(name, sLastErrorString);
205207 }
206208
207209 /// lto_codegen_debug_options - Used to pass extra options to the code