Added a fixme for platform specific GetDirSeparator().
[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 // Returns the platform specific directory separator via #ifdefs.
13 // FIXME: This currently work on linux and windows only. It does not 
14 // work on other unices. 
15 static std::string GetDirSeparator(void) {
16 #ifdef __linux__
17   return "/";
18 #else
19   return "\\";
20 #endif
21 }
22
23 namespace hooks {
24 // Get the dir where c16 executables reside.
25 std::string GetBinDir (void) {
26   // Construct a Path object from the program name.  
27   void *P = (void*) (intptr_t) GetBinDir;
28   sys::Path ProgramFullPath 
29     = sys::Path::GetMainExecutable(llvmc::ProgramName, P);
30
31   // Get the dir name for the program. It's last component should be 'bin'.
32   std::string BinDir = ProgramFullPath.getDirname();
33
34   // llvm::errs() << "BinDir: " << BinDir << '\n';
35   return BinDir + GetDirSeparator();
36 }
37
38 // Get the Top-level Installation dir for c16.
39 std::string GetInstallDir (void) {
40   sys::Path BinDirPath = sys::Path(GetBinDir());
41
42   // Go one more level up to get the install dir.
43   std::string InstallDir  = BinDirPath.getDirname();
44   
45   return InstallDir + GetDirSeparator();
46 }
47
48 // Get the dir where the c16 header files reside.
49 std::string GetStdHeadersDir (void) {
50   return GetInstallDir() + "include";
51 }
52
53 // Get the dir where the assembler header files reside.
54 std::string GetStdAsmHeadersDir (void) {
55   return GetInstallDir() + "inc";
56 }
57
58 // Get the dir where the linker scripts reside.
59 std::string GetStdLinkerScriptsDir (void) {
60   return GetInstallDir() + "lkr";
61 }
62
63 // Get the dir where startup code, intrinsics and lib reside.
64 std::string GetStdLibsDir (void) {
65   return GetInstallDir() + "lib";
66 }
67 }