comparison gen/linker.cpp @ 277:90a8c798b0db trunk

[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
author lindquist
date Fri, 20 Jun 2008 22:09:04 +0200
parents 21f85bac0b1a
children 30941d8ee320
comparison
equal deleted inserted replaced
276:21f85bac0b1a 277:90a8c798b0db
30 } 30 }
31 } 31 }
32 } 32 }
33 33
34 ////////////////////////////////////////////////////////////////////////////// 34 //////////////////////////////////////////////////////////////////////////////
35
36 static llvm::sys::Path gExePath;
35 37
36 int linkExecutable() 38 int linkExecutable()
37 { 39 {
38 Logger::println("*** Linking executable ***"); 40 Logger::println("*** Linking executable ***");
39 41
72 exestr.append(".exe"); 74 exestr.append(".exe");
73 75
74 std::string outopt = "-o=" + exestr; 76 std::string outopt = "-o=" + exestr;
75 args.push_back(outopt.c_str()); 77 args.push_back(outopt.c_str());
76 78
79 // set the global gExePath
80 gExePath.set(exestr);
81 assert(gExePath.isValid());
82
77 // create path to exe 83 // create path to exe
78 llvm::sys::Path exepath(exestr); 84 llvm::sys::Path exedir(gExePath);
79 exepath.set(exepath.getDirname()); 85 exedir.set(gExePath.getDirname());
80 exepath.createDirectoryOnDisk(true, &errstr); 86 exedir.createDirectoryOnDisk(true, &errstr);
81 if (!errstr.empty()) 87 if (!errstr.empty())
82 { 88 {
83 error("failed to create path to linking output\n%s", errstr.c_str()); 89 error("failed to create path to linking output\n%s", errstr.c_str());
84 fatal(); 90 fatal();
85 } 91 }
179 if (!errstr.empty()) 185 if (!errstr.empty())
180 error("message: %s", errstr.c_str()); 186 error("message: %s", errstr.c_str());
181 fatal(); 187 fatal();
182 } 188 }
183 } 189 }
190
191 //////////////////////////////////////////////////////////////////////////////
192
193 void deleteExecutable()
194 {
195 if (!gExePath.isEmpty())
196 {
197 assert(gExePath.isValid());
198 assert(!gExePath.isDirectory());
199 gExePath.eraseFromDisk(false);
200 }
201 }
202
203 //////////////////////////////////////////////////////////////////////////////
204
205 int runExectuable()
206 {
207 assert(!gExePath.isEmpty());
208 assert(gExePath.isValid());
209
210 // build arguments
211 std::vector<const char*> args;
212 for (size_t i = 0; i < global.params.runargs_length; i++)
213 {
214 char *a = global.params.runargs[i];
215 args.push_back(a);
216 }
217 // terminate args list
218 args.push_back(NULL);
219
220 // try to call linker!!!
221 std::string errstr;
222 int status = llvm::sys::Program::ExecuteAndWait(gExePath, &args[0], NULL, NULL, 0,0, &errstr);
223 if (!errstr.empty())
224 {
225 error("failed to execute program");
226 if (!errstr.empty())
227 error("error message: %s", errstr.c_str());
228 fatal();
229 }
230 }