1 #include "llvm/Support/Path.h"
2 #include "llvm/Support/CommandLine.h"
3 #include "llvm/Support/raw_ostream.h"
9 extern const char *ProgramName;
11 namespace autogenerated {
12 extern llvm::cl::opt<std::string> Parameter_p;
17 using namespace llvmc;
19 // Returns the platform specific directory separator via #ifdefs.
20 // FIXME: This currently work on linux and windows only. It does not
21 // work on other unices.
22 static std::string GetDirSeparator() {
23 #if __linux__ || __APPLE__
31 // Get preprocessor define for the part.
32 // It is __partname format in lower case.
34 GetLowerCasePartDefine(void) {
37 if (autogenerated::Parameter_p.empty()) {
40 Partname = autogenerated::Parameter_p;
43 std::string LowerCase;
44 for (unsigned i = 0; i < Partname.size(); i++) {
45 LowerCase.push_back(std::tolower(Partname[i], loc));
48 return "__" + LowerCase;
52 GetUpperCasePartDefine(void) {
55 if (autogenerated::Parameter_p.empty()) {
58 Partname = autogenerated::Parameter_p;
61 std::string UpperCase;
62 for (unsigned i = 0; i < Partname.size(); i++) {
63 UpperCase.push_back(std::toupper(Partname[i], loc));
66 return "__" + UpperCase;
69 // Get the dir where c16 executables reside.
70 std::string GetBinDir() {
71 // Construct a Path object from the program name.
72 void *P = (void*) (intptr_t) GetBinDir;
73 sys::Path ProgramFullPath
74 = sys::Path::GetMainExecutable(llvmc::ProgramName, P);
76 // Get the dir name for the program. It's last component should be 'bin'.
77 std::string BinDir = ProgramFullPath.getDirname();
79 // llvm::errs() << "BinDir: " << BinDir << '\n';
80 return BinDir + GetDirSeparator();
83 // Get the Top-level Installation dir for c16.
84 std::string GetInstallDir() {
85 sys::Path BinDirPath = sys::Path(GetBinDir());
87 // Go one more level up to get the install dir.
88 std::string InstallDir = BinDirPath.getDirname();
90 return InstallDir + GetDirSeparator();
93 // Get the dir where the c16 header files reside.
94 std::string GetStdHeadersDir() {
95 return GetInstallDir() + "include";
98 // Get the dir where the assembler header files reside.
99 std::string GetStdAsmHeadersDir() {
100 return GetInstallDir() + "inc";
103 // Get the dir where the linker scripts reside.
104 std::string GetStdLinkerScriptsDir() {
105 return GetInstallDir() + "lkr";
108 // Get the dir where startup code, intrinsics and lib reside.
109 std::string GetStdLibsDir() {
110 return GetInstallDir() + "lib";