Add uppercase and lowercase part defines in driver.
[oota-llvm.git] / tools / llvmc / example / mcc16 / plugins / PIC16Base / PluginMain.cpp
1 #include "AutoGenerated.inc"
2
3 #include "llvm/System/Path.h"
4 #include "llvm/Support/raw_ostream.h"
5
6 using namespace llvm;
7
8 namespace llvmc {
9   extern char *ProgramName;
10 }
11
12   
13
14 // Returns the platform specific directory separator via #ifdefs.
15 // FIXME: This currently work on linux and windows only. It does not 
16 // work on other unices. 
17 static std::string GetDirSeparator() {
18 #if __linux__ || __APPLE__
19   return "/";
20 #else
21   return "\\";
22 #endif
23 }
24
25 namespace hooks {
26 // Get preprocessor define for the part.
27 // It is __partname format in lower case.
28 std::string
29 GetLowerCasePartDefine(void) {
30   std::string Partname;
31   if (AutoGeneratedParameter_p.empty()) {
32     Partname = "16f1xxx";
33   } else {
34     Partname = AutoGeneratedParameter_p;
35   }
36
37   std::string LowerCase;
38   for (unsigned i = 0; i <= Partname.size(); i++) {
39     LowerCase.push_back(std::tolower(Partname[i]));
40   }
41
42   return "__" + LowerCase;
43 }
44
45 std::string
46 GetUpperCasePartDefine(void) {
47   std::string Partname;
48   if (AutoGeneratedParameter_p.empty()) {
49     Partname = "16f1xxx";
50   } else {
51     Partname = AutoGeneratedParameter_p;
52   }
53
54   std::string UpperCase;
55   for (unsigned i = 0; i <= Partname.size(); i++) {
56     UpperCase.push_back(std::toupper(Partname[i]));
57   }
58
59   return "__" +  UpperCase;
60 }
61
62
63 // Get the dir where c16 executables reside.
64 std::string GetBinDir() {
65   // Construct a Path object from the program name.  
66   void *P = (void*) (intptr_t) GetBinDir;
67   sys::Path ProgramFullPath 
68     = sys::Path::GetMainExecutable(llvmc::ProgramName, P);
69
70   // Get the dir name for the program. It's last component should be 'bin'.
71   std::string BinDir = ProgramFullPath.getDirname();
72
73   // llvm::errs() << "BinDir: " << BinDir << '\n';
74   return BinDir + GetDirSeparator();
75 }
76
77 // Get the Top-level Installation dir for c16.
78 std::string GetInstallDir() {
79   sys::Path BinDirPath = sys::Path(GetBinDir());
80
81   // Go one more level up to get the install dir.
82   std::string InstallDir  = BinDirPath.getDirname();
83   
84   return InstallDir + GetDirSeparator();
85 }
86
87 // Get the dir where the c16 header files reside.
88 std::string GetStdHeadersDir() {
89   return GetInstallDir() + "include";
90 }
91
92 // Get the dir where the assembler header files reside.
93 std::string GetStdAsmHeadersDir() {
94   return GetInstallDir() + "inc";
95 }
96
97 // Get the dir where the linker scripts reside.
98 std::string GetStdLinkerScriptsDir() {
99   return GetInstallDir() + "lkr";
100 }
101
102 // Get the dir where startup code, intrinsics and lib reside.
103 std::string GetStdLibsDir() {
104   return GetInstallDir() + "lib";
105 }
106 }