File: PluginMain.cpp

package info (click to toggle)
llvm-2.7 2.7-6
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 59,992 kB
  • ctags: 49,499
  • sloc: cpp: 373,792; ansic: 16,885; sh: 12,614; asm: 6,809; ada: 3,083; ml: 2,942; python: 2,671; perl: 2,404; makefile: 1,691; pascal: 1,235; exp: 399; objc: 291; lisp: 184; csh: 117; xml: 38; f90: 36
file content (106 lines) | stat: -rw-r--r-- 2,524 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "AutoGenerated.inc"

#include "llvm/System/Path.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

namespace llvmc {
  extern char *ProgramName;
}

  

// Returns the platform specific directory separator via #ifdefs.
// FIXME: This currently work on linux and windows only. It does not 
// work on other unices. 
static std::string GetDirSeparator() {
#if __linux__ || __APPLE__
  return "/";
#else
  return "\\";
#endif
}

namespace hooks {
// Get preprocessor define for the part.
// It is __partname format in lower case.
std::string
GetLowerCasePartDefine(void) {
  std::string Partname;
  if (AutoGeneratedParameter_p.empty()) {
    Partname = "16f1xxx";
  } else {
    Partname = AutoGeneratedParameter_p;
  }

  std::string LowerCase;
  for (unsigned i = 0; i <= Partname.size(); i++) {
    LowerCase.push_back(std::tolower(Partname[i]));
  }

  return "__" + LowerCase;
}

std::string
GetUpperCasePartDefine(void) {
  std::string Partname;
  if (AutoGeneratedParameter_p.empty()) {
    Partname = "16f1xxx";
  } else {
    Partname = AutoGeneratedParameter_p;
  }

  std::string UpperCase;
  for (unsigned i = 0; i <= Partname.size(); i++) {
    UpperCase.push_back(std::toupper(Partname[i]));
  }

  return "__" +  UpperCase;
}


// Get the dir where c16 executables reside.
std::string GetBinDir() {
  // Construct a Path object from the program name.  
  void *P = (void*) (intptr_t) GetBinDir;
  sys::Path ProgramFullPath 
    = sys::Path::GetMainExecutable(llvmc::ProgramName, P);

  // Get the dir name for the program. It's last component should be 'bin'.
  std::string BinDir = ProgramFullPath.getDirname();

  // llvm::errs() << "BinDir: " << BinDir << '\n';
  return BinDir + GetDirSeparator();
}

// Get the Top-level Installation dir for c16.
std::string GetInstallDir() {
  sys::Path BinDirPath = sys::Path(GetBinDir());

  // Go one more level up to get the install dir.
  std::string InstallDir  = BinDirPath.getDirname();
  
  return InstallDir + GetDirSeparator();
}

// Get the dir where the c16 header files reside.
std::string GetStdHeadersDir() {
  return GetInstallDir() + "include";
}

// Get the dir where the assembler header files reside.
std::string GetStdAsmHeadersDir() {
  return GetInstallDir() + "inc";
}

// Get the dir where the linker scripts reside.
std::string GetStdLinkerScriptsDir() {
  return GetInstallDir() + "lkr";
}

// Get the dir where startup code, intrinsics and lib reside.
std::string GetStdLibsDir() {
  return GetInstallDir() + "lib";
}
}