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