Silence -Wunused-variable in release builds.
[llvm/stm8.git] / tools / llvmc / examples / mcc16 / Hooks.cpp
blob95158efeece06b9a5036a6af6980d13e6efb2b30
1 #include "llvm/Support/Path.h"
2 #include "llvm/Support/CommandLine.h"
3 #include "llvm/Support/raw_ostream.h"
5 #include <string>
7 namespace llvmc {
8 extern char *ProgramName;
10 namespace autogenerated {
11 extern llvm::cl::opt<std::string> Parameter_p;
15 using namespace llvm;
16 using namespace llvmc;
18 // Returns the platform specific directory separator via #ifdefs.
19 // FIXME: This currently work on linux and windows only. It does not
20 // work on other unices.
21 static std::string GetDirSeparator() {
22 #if __linux__ || __APPLE__
23 return "/";
24 #else
25 return "\\";
26 #endif
29 namespace hooks {
30 // Get preprocessor define for the part.
31 // It is __partname format in lower case.
32 std::string
33 GetLowerCasePartDefine(void) {
34 std::string Partname;
35 if (autogenerated::Parameter_p.empty()) {
36 Partname = "16f1xxx";
37 } else {
38 Partname = autogenerated::Parameter_p;
41 std::string LowerCase;
42 for (unsigned i = 0; i < Partname.size(); i++) {
43 LowerCase.push_back(std::tolower(Partname[i]));
46 return "__" + LowerCase;
49 std::string
50 GetUpperCasePartDefine(void) {
51 std::string Partname;
52 if (autogenerated::Parameter_p.empty()) {
53 Partname = "16f1xxx";
54 } else {
55 Partname = autogenerated::Parameter_p;
58 std::string UpperCase;
59 for (unsigned i = 0; i < Partname.size(); i++) {
60 UpperCase.push_back(std::toupper(Partname[i]));
63 return "__" + UpperCase;
66 // Get the dir where c16 executables reside.
67 std::string GetBinDir() {
68 // Construct a Path object from the program name.
69 void *P = (void*) (intptr_t) GetBinDir;
70 sys::Path ProgramFullPath
71 = sys::Path::GetMainExecutable(llvmc::ProgramName, P);
73 // Get the dir name for the program. It's last component should be 'bin'.
74 std::string BinDir = ProgramFullPath.getDirname();
76 // llvm::errs() << "BinDir: " << BinDir << '\n';
77 return BinDir + GetDirSeparator();
80 // Get the Top-level Installation dir for c16.
81 std::string GetInstallDir() {
82 sys::Path BinDirPath = sys::Path(GetBinDir());
84 // Go one more level up to get the install dir.
85 std::string InstallDir = BinDirPath.getDirname();
87 return InstallDir + GetDirSeparator();
90 // Get the dir where the c16 header files reside.
91 std::string GetStdHeadersDir() {
92 return GetInstallDir() + "include";
95 // Get the dir where the assembler header files reside.
96 std::string GetStdAsmHeadersDir() {
97 return GetInstallDir() + "inc";
100 // Get the dir where the linker scripts reside.
101 std::string GetStdLinkerScriptsDir() {
102 return GetInstallDir() + "lkr";
105 // Get the dir where startup code, intrinsics and lib reside.
106 std::string GetStdLibsDir() {
107 return GetInstallDir() + "lib";