//
//===----------------------------------------------------------------------===//
-#include "llvm/Transforms/Linker.h"
+#include "llvm/Transforms/Utils/Linker.h"
#include "llvm/Module.h"
#include "llvm/PassManager.h"
#include "llvm/Bytecode/Reader.h"
#include "llvm/Bytecode/WriteBytecodePass.h"
-#include "llvm/Transforms/SymbolStripping.h"
-#include "llvm/Transforms/CleanupGCCOutput.h"
-#include "llvm/Transforms/ConstantMerge.h"
-#include "llvm/Transforms/IPO/GlobalDCE.h"
+#include "llvm/Transforms/IPO.h"
+#include "llvm/Transforms/Scalar.h"
#include "Support/CommandLine.h"
#include "Support/Signals.h"
#include <fstream>
#include <algorithm>
#include <sys/types.h> // For FileExists
#include <sys/stat.h>
+using std::cerr;
+static cl::list<std::string>
+InputFilenames(cl::Positional, cl::desc("<input bytecode files>"),
+ cl::OneOrMore);
+
+static cl::opt<std::string>
+OutputFilename("o", cl::desc("Override output filename"), cl::init("a.out"),
+ cl::value_desc("filename"));
+
+static cl::opt<bool>
+Verbose("v", cl::desc("Print information about actions taken"));
+
+static cl::list<std::string>
+LibPaths("L", cl::desc("Specify a library search path"), cl::Prefix,
+ cl::value_desc("directory"));
+
+static cl::list<std::string>
+Libraries("l", cl::desc("Specify libraries to link to"), cl::Prefix,
+ cl::value_desc("library prefix"));
+
+static cl::opt<bool>
+Strip("s", cl::desc("Strip symbol info from executable"));
-cl::StringList InputFilenames("", "Load <arg> files, linking them together",
- cl::OneOrMore);
-cl::String OutputFilename("o", "Override output filename", cl::NoFlags,"a.out");
-cl::Flag Verbose ("v", "Print information about actions taken");
-cl::StringList LibPaths ("L", "Specify a library search path", cl::ZeroOrMore);
-cl::StringList Libraries ("l", "Specify libraries to link to", cl::ZeroOrMore);
-cl::Flag Strip ("s", "Strip symbol info from executable");
// FileExists - Return true if the specified string is an openable file...
static inline bool FileExists(const std::string &FN) {
if (Verbose) {
cerr << "Error opening bytecode file: '" << Filename << "'";
if (ErrorMessage.size()) cerr << ": " << ErrorMessage;
- cerr << endl;
+ cerr << "\n";
}
if (NextLibPathIdx == LibPaths.size()) break;
}
-
-
int main(int argc, char **argv) {
- cl::ParseCommandLineOptions(argc, argv, " llvm linker for GCC\n",
- cl::EnableSingleLetterArgValue |
- cl::DisableSingleLetterArgGrouping);
- assert(InputFilenames.size() > 0 && "OneOrMore is not working");
+ cl::ParseCommandLineOptions(argc, argv, " llvm linker for GCC\n");
unsigned BaseArg = 0;
std::string ErrorMessage;
if (!Libraries.empty()) {
// Sort libraries list...
- sort(Libraries.begin(), Libraries.end());
+ std::sort(Libraries.begin(), Libraries.end());
// Remove duplicate libraries entries...
Libraries.erase(unique(Libraries.begin(), Libraries.end()),
if (Verbose) cerr << "Linking in '" << InputFilenames[i] << "'\n";
if (LinkModules(Composite.get(), M.get(), &ErrorMessage)) {
- cerr << "Error linking in '" << InputFilenames[i] << "': "
- << ErrorMessage << endl;
+ cerr << argv[0] << ": error linking in '" << InputFilenames[i] << "': "
+ << ErrorMessage << "\n";
return 1;
}
}
// Now that composite has been compiled, scan through the module, looking for
// a main function. If main is defined, mark all other functions internal.
//
- // TODO:
+ Passes.add(createInternalizePass());
// Now that we have optimized the program, discard unreachable functions...
//
// Add the pass that writes bytecode to the output file...
std::ofstream Out((OutputFilename+".bc").c_str());
if (!Out.good()) {
- cerr << "Error opening '" << OutputFilename << ".bc' for writing!\n";
+ cerr << argv[0] << ": error opening '" << OutputFilename
+ << ".bc' for writing!\n";
return 1;
}
Passes.add(new WriteBytecodePass(&Out)); // Write bytecode to file...
RemoveFileOnSignal(OutputFilename+".bc");
// Run our queue of passes all at once now, efficiently.
- Passes.run(Composite.get());
+ Passes.run(*Composite.get());
Out.close();
// Output the script to start the program...
std::ofstream Out2(OutputFilename.c_str());
if (!Out2.good()) {
- cerr << "Error opening '" << OutputFilename << "' for writing!\n";
+ cerr << argv[0] << ": error opening '" << OutputFilename
+ << "' for writing!\n";
return 1;
}
Out2 << "#!/bin/sh\nlli -q $0.bc $*\n";