Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 1 | //===-- PIC16.h - Top-level interface for PIC16 representation --*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Sanjiv Gupta | 2d4e7f7 | 2008-05-14 06:50:01 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the entry points for global functions defined in |
| 11 | // the LLVM PIC16 back-end. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 15 | #ifndef LLVM_TARGET_PIC16_H |
| 16 | #define LLVM_TARGET_PIC16_H |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 17 | |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame^] | 18 | #include "llvm/Support/ErrorHandling.h" |
Bill Wendling | 98a366d | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetMachine.h" |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 20 | #include <iosfwd> |
| 21 | #include <cassert> |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 22 | #include <sstream> |
Nick Lewycky | 4a22886 | 2009-05-08 06:22:25 +0000 | [diff] [blame] | 23 | #include <cstring> |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 24 | #include <string> |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 25 | |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 26 | namespace llvm { |
| 27 | class PIC16TargetMachine; |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 28 | class FunctionPass; |
| 29 | class MachineCodeEmitter; |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 30 | class raw_ostream; |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 31 | |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 32 | namespace PIC16CC { |
| 33 | enum CondCodes { |
| 34 | EQ, |
| 35 | NE, |
| 36 | LT, |
| 37 | LE, |
| 38 | GT, |
Sanjiv Gupta | 08b9b05 | 2009-01-21 05:44:05 +0000 | [diff] [blame] | 39 | GE, |
| 40 | ULT, |
| 41 | UGT, |
| 42 | ULE, |
| 43 | UGE |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 44 | }; |
| 45 | } |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 46 | // A Central class to manage all ABI naming conventions. |
| 47 | // PAN - [P]ic16 [A]BI [N]ames |
| 48 | class PAN { |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 49 | public: |
| 50 | // Map the name of the symbol to its section name. |
| 51 | // Current ABI: |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 52 | // ----------------------------------------------------- |
| 53 | // ALL Names are prefixed with the symobl '@'. |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 54 | // ------------------------------------------------------ |
| 55 | // Global variables do not have any '.' in their names. |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 56 | // These are maily function names and global variable names. |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 57 | // Example - @foo, @i |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 58 | // ------------------------------------------------------- |
| 59 | // Functions and auto variables. |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 60 | // Names are mangled as <prefix><funcname>.<tag>.<varname> |
| 61 | // Where <prefix> is '@' and <tag> is any one of |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 62 | // the following |
| 63 | // .auto. - an automatic var of a function. |
| 64 | // .temp. - temproray data of a function. |
| 65 | // .ret. - return value label for a function. |
| 66 | // .frame. - Frame label for a function where retval, args |
| 67 | // and temps are stored. |
| 68 | // .args. - Label used to pass arguments to a direct call. |
| 69 | // Example - Function name: @foo |
| 70 | // Its frame: @foo.frame. |
| 71 | // Its retval: @foo.ret. |
| 72 | // Its local vars: @foo.auto.a |
| 73 | // Its temp data: @foo.temp. |
| 74 | // Its arg passing: @foo.args. |
| 75 | //---------------------------------------------- |
Sanjiv Gupta | e0b4b0e | 2009-05-11 08:52:04 +0000 | [diff] [blame] | 76 | // Libcall - compiler generated libcall names must start with .lib. |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 77 | // This id will be used to emit extern decls for libcalls. |
Sanjiv Gupta | e0b4b0e | 2009-05-11 08:52:04 +0000 | [diff] [blame] | 78 | // Example - libcall name: @.lib.sra.i8 |
| 79 | // To pass args: @.lib.sra.i8.args. |
| 80 | // To return val: @.lib.sra.i8.ret. |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 81 | //---------------------------------------------- |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 82 | // SECTION Names |
| 83 | // uninitialized globals - @udata.<num>.# |
| 84 | // initialized globals - @idata.<num>.# |
| 85 | // Function frame - @<func>.frame_section. |
| 86 | // Function autos - @<func>.autos_section. |
Sanjiv Gupta | d764941 | 2009-07-06 08:22:15 +0000 | [diff] [blame] | 87 | // Declarations - Enclosed in comments. No section for them. |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 88 | //---------------------------------------------------------- |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 89 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 90 | // Tags used to mangle different names. |
| 91 | enum TAGS { |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 92 | PREFIX_SYMBOL, |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 93 | GLOBAL, |
| 94 | STATIC_LOCAL, |
| 95 | AUTOS_LABEL, |
| 96 | FRAME_LABEL, |
| 97 | RET_LABEL, |
| 98 | ARGS_LABEL, |
| 99 | TEMPS_LABEL, |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 100 | |
| 101 | LIBCALL, |
| 102 | |
| 103 | FRAME_SECTION, |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 104 | AUTOS_SECTION, |
| 105 | CODE_SECTION |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 106 | }; |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 107 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 108 | // Textual names of the tags. |
| 109 | inline static const char *getTagName(TAGS tag) { |
| 110 | switch (tag) { |
| 111 | default: return ""; |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 112 | case PREFIX_SYMBOL: return "@"; |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 113 | case AUTOS_LABEL: return ".auto."; |
| 114 | case FRAME_LABEL: return ".frame."; |
| 115 | case TEMPS_LABEL: return ".temp."; |
| 116 | case ARGS_LABEL: return ".args."; |
| 117 | case RET_LABEL: return ".ret."; |
Sanjiv Gupta | e0b4b0e | 2009-05-11 08:52:04 +0000 | [diff] [blame] | 118 | case LIBCALL: return ".lib."; |
| 119 | case FRAME_SECTION: return ".frame_section."; |
| 120 | case AUTOS_SECTION: return ".autos_section."; |
| 121 | case CODE_SECTION: return ".code_section."; |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 122 | } |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 123 | } |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 124 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 125 | // Get tag type for the Symbol. |
| 126 | inline static TAGS getSymbolTag(const std::string &Sym) { |
| 127 | if (Sym.find(getTagName(TEMPS_LABEL)) != std::string::npos) |
| 128 | return TEMPS_LABEL; |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 129 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 130 | if (Sym.find(getTagName(FRAME_LABEL)) != std::string::npos) |
| 131 | return FRAME_LABEL; |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 132 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 133 | if (Sym.find(getTagName(RET_LABEL)) != std::string::npos) |
| 134 | return RET_LABEL; |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 135 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 136 | if (Sym.find(getTagName(ARGS_LABEL)) != std::string::npos) |
| 137 | return ARGS_LABEL; |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 138 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 139 | if (Sym.find(getTagName(AUTOS_LABEL)) != std::string::npos) |
| 140 | return AUTOS_LABEL; |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 141 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 142 | if (Sym.find(getTagName(LIBCALL)) != std::string::npos) |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 143 | return LIBCALL; |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 144 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 145 | // It does not have any Tag. So its a true global or static local. |
| 146 | if (Sym.find(".") == std::string::npos) |
| 147 | return GLOBAL; |
| 148 | |
| 149 | // If a . is there, then it may be static local. |
| 150 | // We should mangle these as well in clang. |
| 151 | if (Sym.find(".") != std::string::npos) |
| 152 | return STATIC_LOCAL; |
| 153 | |
| 154 | assert (0 && "Could not determine Symbol's tag"); |
Duncan Sands | f7f2d30 | 2009-07-03 16:11:34 +0000 | [diff] [blame] | 155 | return PREFIX_SYMBOL; // Silence warning when assertions are turned off. |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 158 | // addPrefix - add prefix symbol to a name if there isn't one already. |
| 159 | inline static std::string addPrefix (const std::string &Name) { |
| 160 | std::string prefix = getTagName (PREFIX_SYMBOL); |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 161 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 162 | // If this name already has a prefix, nothing to do. |
| 163 | if (Name.compare(0, prefix.size(), prefix) == 0) |
| 164 | return Name; |
| 165 | |
| 166 | return prefix + Name; |
| 167 | } |
| 168 | |
| 169 | // Get mangled func name from a mangled sym name. |
| 170 | // In all cases func name is the first component before a '.'. |
| 171 | static inline std::string getFuncNameForSym(const std::string &Sym1) { |
| 172 | assert (getSymbolTag(Sym1) != GLOBAL && "not belongs to a function"); |
| 173 | |
| 174 | std::string Sym = addPrefix(Sym1); |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 175 | |
| 176 | // Position of the . after func name. That's where func name ends. |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 177 | size_t func_name_end = Sym.find ('.'); |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 178 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 179 | return Sym.substr (0, func_name_end); |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 182 | // Get Frame start label for a func. |
| 183 | static std::string getFrameLabel(const std::string &Func) { |
| 184 | std::string Func1 = addPrefix(Func); |
| 185 | std::string tag = getTagName(FRAME_LABEL); |
| 186 | return Func1 + tag; |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 189 | static std::string getRetvalLabel(const std::string &Func) { |
| 190 | std::string Func1 = addPrefix(Func); |
| 191 | std::string tag = getTagName(RET_LABEL); |
| 192 | return Func1 + tag; |
| 193 | } |
| 194 | |
| 195 | static std::string getArgsLabel(const std::string &Func) { |
| 196 | std::string Func1 = addPrefix(Func); |
| 197 | std::string tag = getTagName(ARGS_LABEL); |
| 198 | return Func1 + tag; |
| 199 | } |
| 200 | |
| 201 | static std::string getTempdataLabel(const std::string &Func) { |
| 202 | std::string Func1 = addPrefix(Func); |
| 203 | std::string tag = getTagName(TEMPS_LABEL); |
| 204 | return Func1 + tag; |
| 205 | } |
| 206 | |
| 207 | static std::string getFrameSectionName(const std::string &Func) { |
| 208 | std::string Func1 = addPrefix(Func); |
| 209 | std::string tag = getTagName(FRAME_SECTION); |
Sanjiv Gupta | e0b4b0e | 2009-05-11 08:52:04 +0000 | [diff] [blame] | 210 | return Func1 + tag + "# UDATA_OVR"; |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | static std::string getAutosSectionName(const std::string &Func) { |
| 214 | std::string Func1 = addPrefix(Func); |
| 215 | std::string tag = getTagName(AUTOS_SECTION); |
Sanjiv Gupta | e0b4b0e | 2009-05-11 08:52:04 +0000 | [diff] [blame] | 216 | return Func1 + tag + "# UDATA_OVR"; |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | static std::string getCodeSectionName(const std::string &Func) { |
| 220 | std::string Func1 = addPrefix(Func); |
| 221 | std::string tag = getTagName(CODE_SECTION); |
Sanjiv Gupta | e0b4b0e | 2009-05-11 08:52:04 +0000 | [diff] [blame] | 222 | return Func1 + tag + "# CODE"; |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Sanjiv Gupta | 505996f | 2009-07-06 10:18:37 +0000 | [diff] [blame] | 225 | // udata, romdata and idata section names are generated by a given number. |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 226 | // @udata.<num>.# |
Sanjiv Gupta | 505996f | 2009-07-06 10:18:37 +0000 | [diff] [blame] | 227 | static std::string getUdataSectionName(unsigned num, |
| 228 | std::string prefix = "") { |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 229 | std::ostringstream o; |
Sanjiv Gupta | 505996f | 2009-07-06 10:18:37 +0000 | [diff] [blame] | 230 | o << getTagName(PREFIX_SYMBOL) << prefix << "udata." << num |
| 231 | << ".# UDATA"; |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 232 | return o.str(); |
| 233 | } |
| 234 | |
Sanjiv Gupta | 505996f | 2009-07-06 10:18:37 +0000 | [diff] [blame] | 235 | static std::string getRomdataSectionName(unsigned num, |
| 236 | std::string prefix = "") { |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 237 | std::ostringstream o; |
Sanjiv Gupta | 505996f | 2009-07-06 10:18:37 +0000 | [diff] [blame] | 238 | o << getTagName(PREFIX_SYMBOL) << prefix << "romdata." << num |
| 239 | << ".# ROMDATA"; |
| 240 | return o.str(); |
| 241 | } |
| 242 | |
| 243 | static std::string getIdataSectionName(unsigned num, |
| 244 | std::string prefix = "") { |
| 245 | std::ostringstream o; |
| 246 | o << getTagName(PREFIX_SYMBOL) << prefix << "idata." << num |
| 247 | << ".# IDATA"; |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 248 | return o.str(); |
| 249 | } |
| 250 | |
| 251 | inline static bool isLocalName (const std::string &Name) { |
| 252 | if (getSymbolTag(Name) == AUTOS_LABEL) |
| 253 | return true; |
| 254 | |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | inline static bool isLocalToFunc (std::string &Func, std::string &Var) { |
| 259 | if (! isLocalName(Var)) return false; |
| 260 | |
| 261 | std::string Func1 = addPrefix(Func); |
| 262 | // Extract func name of the varilable. |
| 263 | const std::string &fname = getFuncNameForSym(Var); |
| 264 | |
| 265 | if (fname.compare(Func1) == 0) |
| 266 | return true; |
| 267 | |
| 268 | return false; |
| 269 | } |
| 270 | |
| 271 | |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 272 | // Get the section for the given external symbol names. |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 273 | // This tries to find the type (Tag) of the symbol from its mangled name |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 274 | // and return appropriate section name for it. |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 275 | static inline std::string getSectionNameForSym(const std::string &Sym1) { |
| 276 | std::string Sym = addPrefix(Sym1); |
| 277 | |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 278 | std::string SectionName; |
| 279 | |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 280 | std::string Fname = getFuncNameForSym (Sym); |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 281 | TAGS id = getSymbolTag (Sym); |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 282 | |
| 283 | switch (id) { |
| 284 | default : assert (0 && "Could not determine external symbol type"); |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 285 | case FRAME_LABEL: |
| 286 | case RET_LABEL: |
| 287 | case TEMPS_LABEL: |
| 288 | case ARGS_LABEL: { |
| 289 | return getFrameSectionName(Fname); |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 290 | } |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 291 | case AUTOS_LABEL: { |
| 292 | return getAutosSectionName(Fname); |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | } |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 296 | }; // class PAN. |
| 297 | |
| 298 | |
| 299 | // External symbol names require memory to live till the program end. |
| 300 | // So we have to allocate it and keep. |
| 301 | inline static const char *createESName (const std::string &name) { |
| 302 | char *tmpName = new char[name.size() + 1]; |
| 303 | strcpy (tmpName, name.c_str()); |
| 304 | return tmpName; |
| 305 | } |
Sanjiv Gupta | 573eb5e | 2009-05-08 04:50:14 +0000 | [diff] [blame] | 306 | |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 307 | |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 308 | |
| 309 | inline static const char *PIC16CondCodeToString(PIC16CC::CondCodes CC) { |
| 310 | switch (CC) { |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame^] | 311 | default: LLVM_UNREACHABLE("Unknown condition code"); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 312 | case PIC16CC::NE: return "ne"; |
| 313 | case PIC16CC::EQ: return "eq"; |
| 314 | case PIC16CC::LT: return "lt"; |
Sanjiv Gupta | 08b9b05 | 2009-01-21 05:44:05 +0000 | [diff] [blame] | 315 | case PIC16CC::ULT: return "lt"; |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 316 | case PIC16CC::LE: return "le"; |
Sanjiv Gupta | 703e235 | 2009-06-03 13:36:44 +0000 | [diff] [blame] | 317 | case PIC16CC::ULE: return "le"; |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 318 | case PIC16CC::GT: return "gt"; |
Sanjiv Gupta | 08b9b05 | 2009-01-21 05:44:05 +0000 | [diff] [blame] | 319 | case PIC16CC::UGT: return "gt"; |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 320 | case PIC16CC::GE: return "ge"; |
Sanjiv Gupta | 703e235 | 2009-06-03 13:36:44 +0000 | [diff] [blame] | 321 | case PIC16CC::UGE: return "ge"; |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
Sanjiv Gupta | 08b9b05 | 2009-01-21 05:44:05 +0000 | [diff] [blame] | 325 | inline static bool isSignedComparison(PIC16CC::CondCodes CC) { |
| 326 | switch (CC) { |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame^] | 327 | default: LLVM_UNREACHABLE("Unknown condition code"); |
Sanjiv Gupta | 08b9b05 | 2009-01-21 05:44:05 +0000 | [diff] [blame] | 328 | case PIC16CC::NE: |
| 329 | case PIC16CC::EQ: |
| 330 | case PIC16CC::LT: |
| 331 | case PIC16CC::LE: |
| 332 | case PIC16CC::GE: |
| 333 | case PIC16CC::GT: |
| 334 | return true; |
| 335 | case PIC16CC::ULT: |
| 336 | case PIC16CC::UGT: |
| 337 | case PIC16CC::ULE: |
| 338 | case PIC16CC::UGE: |
| 339 | return false; // condition codes for unsigned comparison. |
| 340 | } |
| 341 | } |
| 342 | |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 343 | |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 344 | |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 345 | FunctionPass *createPIC16ISelDag(PIC16TargetMachine &TM); |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 346 | FunctionPass *createPIC16CodePrinterPass(raw_ostream &OS, |
Bill Wendling | 57f0db8 | 2009-02-24 08:30:20 +0000 | [diff] [blame] | 347 | PIC16TargetMachine &TM, |
Bill Wendling | 98a366d | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 348 | bool Verbose); |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 349 | // Banksel optimzer pass. |
| 350 | FunctionPass *createPIC16MemSelOptimizerPass(); |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 351 | } // end namespace llvm; |
| 352 | |
| 353 | // Defines symbolic names for PIC16 registers. This defines a mapping from |
| 354 | // register name to register number. |
| 355 | #include "PIC16GenRegisterNames.inc" |
| 356 | |
| 357 | // Defines symbolic names for the PIC16 instructions. |
| 358 | #include "PIC16GenInstrNames.inc" |
| 359 | |
| 360 | #endif |