blob: bbb8438bc37966f027748bb6f80fda0c6353b53e [file] [log] [blame]
Michael J. Spencer3cc52ea2010-11-29 18:47:54 +00001#include "llvm/Support/Path.h"
Mikhail Glushenkov086976d2010-10-23 07:33:02 +00002#include "llvm/Support/CommandLine.h"
3#include "llvm/Support/raw_ostream.h"
4
5#include <string>
Oscar Fuentes796f9252011-07-25 17:24:54 +00006#include <locale>
Mikhail Glushenkov086976d2010-10-23 07:33:02 +00007
8namespace llvmc {
Oscar Fuentes796f9252011-07-25 17:24:54 +00009 extern const char *ProgramName;
Mikhail Glushenkov086976d2010-10-23 07:33:02 +000010
11 namespace autogenerated {
12 extern llvm::cl::opt<std::string> Parameter_p;
13 }
14}
15
16using namespace llvm;
17using namespace llvmc;
18
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.
22static std::string GetDirSeparator() {
23#if __linux__ || __APPLE__
24 return "/";
25#else
26 return "\\";
27#endif
28}
29
30namespace hooks {
31// Get preprocessor define for the part.
32// It is __partname format in lower case.
33std::string
34GetLowerCasePartDefine(void) {
Oscar Fuentes796f9252011-07-25 17:24:54 +000035 std::locale loc;
Mikhail Glushenkov086976d2010-10-23 07:33:02 +000036 std::string Partname;
37 if (autogenerated::Parameter_p.empty()) {
38 Partname = "16f1xxx";
39 } else {
40 Partname = autogenerated::Parameter_p;
41 }
42
43 std::string LowerCase;
44 for (unsigned i = 0; i < Partname.size(); i++) {
Oscar Fuentes796f9252011-07-25 17:24:54 +000045 LowerCase.push_back(std::tolower(Partname[i], loc));
Mikhail Glushenkov086976d2010-10-23 07:33:02 +000046 }
47
48 return "__" + LowerCase;
49}
50
51std::string
52GetUpperCasePartDefine(void) {
Oscar Fuentes796f9252011-07-25 17:24:54 +000053 std::locale loc;
Mikhail Glushenkov086976d2010-10-23 07:33:02 +000054 std::string Partname;
55 if (autogenerated::Parameter_p.empty()) {
56 Partname = "16f1xxx";
57 } else {
58 Partname = autogenerated::Parameter_p;
59 }
60
61 std::string UpperCase;
62 for (unsigned i = 0; i < Partname.size(); i++) {
Oscar Fuentes796f9252011-07-25 17:24:54 +000063 UpperCase.push_back(std::toupper(Partname[i], loc));
Mikhail Glushenkov086976d2010-10-23 07:33:02 +000064 }
65
66 return "__" + UpperCase;
67}
68
69// Get the dir where c16 executables reside.
70std::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);
75
76 // Get the dir name for the program. It's last component should be 'bin'.
77 std::string BinDir = ProgramFullPath.getDirname();
78
79 // llvm::errs() << "BinDir: " << BinDir << '\n';
80 return BinDir + GetDirSeparator();
81}
82
83// Get the Top-level Installation dir for c16.
84std::string GetInstallDir() {
85 sys::Path BinDirPath = sys::Path(GetBinDir());
86
87 // Go one more level up to get the install dir.
88 std::string InstallDir = BinDirPath.getDirname();
89
90 return InstallDir + GetDirSeparator();
91}
92
93// Get the dir where the c16 header files reside.
94std::string GetStdHeadersDir() {
95 return GetInstallDir() + "include";
96}
97
98// Get the dir where the assembler header files reside.
99std::string GetStdAsmHeadersDir() {
100 return GetInstallDir() + "inc";
101}
102
103// Get the dir where the linker scripts reside.
104std::string GetStdLinkerScriptsDir() {
105 return GetInstallDir() + "lkr";
106}
107
108// Get the dir where startup code, intrinsics and lib reside.
109std::string GetStdLibsDir() {
110 return GetInstallDir() + "lib";
111}
112}