Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 1 | //===-- ARMTargetAsmInfo.cpp - ARM asm properties ---------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the declarations of the ARMTargetAsmInfo properties. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "ARMTargetAsmInfo.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 15 | #include "ARMTargetMachine.h" |
Dale Johannesen | 24fb52d | 2007-04-23 20:04:35 +0000 | [diff] [blame] | 16 | #include <cstring> |
| 17 | #include <cctype> |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 18 | using namespace llvm; |
| 19 | |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 20 | const char *const llvm::arm_asm_table[] = { |
Chris Lattner | a93ca92 | 2009-06-18 23:41:35 +0000 | [diff] [blame] | 21 | "{r0}", "r0", |
| 22 | "{r1}", "r1", |
| 23 | "{r2}", "r2", |
| 24 | "{r3}", "r3", |
| 25 | "{r4}", "r4", |
| 26 | "{r5}", "r5", |
| 27 | "{r6}", "r6", |
| 28 | "{r7}", "r7", |
| 29 | "{r8}", "r8", |
| 30 | "{r9}", "r9", |
| 31 | "{r10}", "r10", |
| 32 | "{r11}", "r11", |
| 33 | "{r12}", "r12", |
| 34 | "{r13}", "r13", |
| 35 | "{r14}", "r14", |
| 36 | "{lr}", "lr", |
| 37 | "{sp}", "sp", |
| 38 | "{ip}", "ip", |
| 39 | "{fp}", "fp", |
| 40 | "{sl}", "sl", |
| 41 | "{memory}", "memory", |
| 42 | "{cc}", "cc", |
| 43 | 0,0 |
| 44 | }; |
Lauro Ramos Venancio | 61718a6 | 2007-06-08 21:06:23 +0000 | [diff] [blame] | 45 | |
Anton Korobeynikov | d49ea77 | 2009-06-26 21:28:53 +0000 | [diff] [blame] | 46 | ARMDarwinTargetAsmInfo::ARMDarwinTargetAsmInfo(const ARMBaseTargetMachine &TM): |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 47 | ARMTargetAsmInfo<DarwinTargetAsmInfo>(TM) { |
Dan Gohman | 8f09225 | 2008-11-03 18:22:42 +0000 | [diff] [blame] | 48 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Anton Korobeynikov | 0f3cc65 | 2008-08-07 09:54:23 +0000 | [diff] [blame] | 49 | |
Anton Korobeynikov | 0f3cc65 | 2008-08-07 09:54:23 +0000 | [diff] [blame] | 50 | ZeroDirective = "\t.space\t"; |
| 51 | ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill |
| 52 | SetDirective = "\t.set\t"; |
Anton Korobeynikov | 0f3cc65 | 2008-08-07 09:54:23 +0000 | [diff] [blame] | 53 | ProtectedDirective = NULL; |
Anton Korobeynikov | 0f3cc65 | 2008-08-07 09:54:23 +0000 | [diff] [blame] | 54 | HasDotTypeDotSizeDirective = false; |
Devang Patel | 14a55d9 | 2009-06-19 21:54:26 +0000 | [diff] [blame] | 55 | SupportsDebugInformation = true; |
Anton Korobeynikov | 0f3cc65 | 2008-08-07 09:54:23 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Anton Korobeynikov | d49ea77 | 2009-06-26 21:28:53 +0000 | [diff] [blame] | 58 | ARMELFTargetAsmInfo::ARMELFTargetAsmInfo(const ARMBaseTargetMachine &TM): |
Chris Lattner | 8d4a0a3 | 2009-08-02 04:27:24 +0000 | [diff] [blame^] | 59 | ARMTargetAsmInfo<TargetAsmInfo>(TM) { |
Dan Gohman | 8f09225 | 2008-11-03 18:22:42 +0000 | [diff] [blame] | 60 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Anton Korobeynikov | 0f3cc65 | 2008-08-07 09:54:23 +0000 | [diff] [blame] | 61 | |
| 62 | NeedsSet = false; |
| 63 | HasLEB128 = true; |
| 64 | AbsoluteDebugSectionOffsets = true; |
Anton Korobeynikov | 0f3cc65 | 2008-08-07 09:54:23 +0000 | [diff] [blame] | 65 | PrivateGlobalPrefix = ".L"; |
| 66 | WeakRefDirective = "\t.weak\t"; |
| 67 | SetDirective = "\t.set\t"; |
| 68 | DwarfRequiresFrameSection = false; |
| 69 | DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",%progbits"; |
| 70 | DwarfInfoSection = "\t.section\t.debug_info,\"\",%progbits"; |
| 71 | DwarfLineSection = "\t.section\t.debug_line,\"\",%progbits"; |
| 72 | DwarfFrameSection = "\t.section\t.debug_frame,\"\",%progbits"; |
| 73 | DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",%progbits"; |
| 74 | DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",%progbits"; |
| 75 | DwarfStrSection = "\t.section\t.debug_str,\"\",%progbits"; |
| 76 | DwarfLocSection = "\t.section\t.debug_loc,\"\",%progbits"; |
| 77 | DwarfARangesSection = "\t.section\t.debug_aranges,\"\",%progbits"; |
| 78 | DwarfRangesSection = "\t.section\t.debug_ranges,\"\",%progbits"; |
Chris Lattner | b839c3f | 2009-06-18 23:31:37 +0000 | [diff] [blame] | 79 | DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"\",%progbits"; |
Anton Korobeynikov | 0f3cc65 | 2008-08-07 09:54:23 +0000 | [diff] [blame] | 80 | |
Devang Patel | 14a55d9 | 2009-06-19 21:54:26 +0000 | [diff] [blame] | 81 | SupportsDebugInformation = true; |
Anton Korobeynikov | 0f3cc65 | 2008-08-07 09:54:23 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 84 | /// Count the number of comma-separated arguments. |
| 85 | /// Do not try to detect errors. |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 86 | template <class BaseTAI> |
| 87 | unsigned ARMTargetAsmInfo<BaseTAI>::countArguments(const char* p) const { |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 88 | unsigned count = 0; |
| 89 | while (*p && isspace(*p) && *p != '\n') |
| 90 | p++; |
| 91 | count++; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 92 | while (*p && *p!='\n' && |
| 93 | strncmp(p, BaseTAI::CommentString, |
| 94 | strlen(BaseTAI::CommentString))!=0) { |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 95 | if (*p==',') |
| 96 | count++; |
| 97 | p++; |
| 98 | } |
| 99 | return count; |
| 100 | } |
| 101 | |
| 102 | /// Count the length of a string enclosed in quote characters. |
| 103 | /// Do not try to detect errors. |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 104 | template <class BaseTAI> |
| 105 | unsigned ARMTargetAsmInfo<BaseTAI>::countString(const char* p) const { |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 106 | unsigned count = 0; |
| 107 | while (*p && isspace(*p) && *p!='\n') |
| 108 | p++; |
| 109 | if (!*p || *p != '\"') |
| 110 | return count; |
| 111 | while (*++p && *p != '\"') |
| 112 | count++; |
| 113 | return count; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 114 | } |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 115 | |
| 116 | /// ARM-specific version of TargetAsmInfo::getInlineAsmLength. |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 117 | template <class BaseTAI> |
| 118 | unsigned ARMTargetAsmInfo<BaseTAI>::getInlineAsmLength(const char *s) const { |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 119 | // Make a lowercase-folded version of s for counting purposes. |
| 120 | char *q, *s_copy = (char *)malloc(strlen(s) + 1); |
| 121 | strcpy(s_copy, s); |
| 122 | for (q=s_copy; *q; q++) |
| 123 | *q = tolower(*q); |
| 124 | const char *Str = s_copy; |
| 125 | |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 126 | // Count the number of bytes in the asm. |
| 127 | bool atInsnStart = true; |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 128 | bool inTextSection = true; |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 129 | unsigned Length = 0; |
| 130 | for (; *Str; ++Str) { |
| 131 | if (atInsnStart) { |
| 132 | // Skip whitespace |
| 133 | while (*Str && isspace(*Str) && *Str != '\n') |
| 134 | Str++; |
| 135 | // Skip label |
| 136 | for (const char* p = Str; *p && !isspace(*p); p++) |
| 137 | if (*p == ':') { |
| 138 | Str = p+1; |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 139 | while (*Str && isspace(*Str) && *Str != '\n') |
| 140 | Str++; |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 141 | break; |
| 142 | } |
Chris Lattner | eda2ec3 | 2009-03-11 16:14:25 +0000 | [diff] [blame] | 143 | |
| 144 | if (*Str == 0) break; |
| 145 | |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 146 | // Ignore everything from comment char(s) to EOL |
Chris Lattner | eda2ec3 | 2009-03-11 16:14:25 +0000 | [diff] [blame] | 147 | if (strncmp(Str, BaseTAI::CommentString, |
| 148 | strlen(BaseTAI::CommentString)) == 0) |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 149 | atInsnStart = false; |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 150 | // FIXME do something like the following for non-Darwin |
| 151 | else if (*Str == '.' && Subtarget->isTargetDarwin()) { |
| 152 | // Directive. |
| 153 | atInsnStart = false; |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 154 | |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 155 | // Some change the section, but don't generate code. |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 156 | if (strncmp(Str, ".literal4", strlen(".literal4"))==0 || |
| 157 | strncmp(Str, ".literal8", strlen(".literal8"))==0 || |
| 158 | strncmp(Str, ".const", strlen(".const"))==0 || |
| 159 | strncmp(Str, ".constructor", strlen(".constructor"))==0 || |
| 160 | strncmp(Str, ".cstring", strlen(".cstring"))==0 || |
| 161 | strncmp(Str, ".data", strlen(".data"))==0 || |
| 162 | strncmp(Str, ".destructor", strlen(".destructor"))==0 || |
| 163 | strncmp(Str, ".fvmlib_init0", strlen(".fvmlib_init0"))==0 || |
| 164 | strncmp(Str, ".fvmlib_init1", strlen(".fvmlib_init1"))==0 || |
| 165 | strncmp(Str, ".mod_init_func", strlen(".mod_init_func"))==0 || |
| 166 | strncmp(Str, ".mod_term_func", strlen(".mod_term_func"))==0 || |
| 167 | strncmp(Str, ".picsymbol_stub", strlen(".picsymbol_stub"))==0 || |
| 168 | strncmp(Str, ".symbol_stub", strlen(".symbol_stub"))==0 || |
| 169 | strncmp(Str, ".static_data", strlen(".static_data"))==0 || |
| 170 | strncmp(Str, ".section", strlen(".section"))==0 || |
| 171 | strncmp(Str, ".lazy_symbol_pointer", strlen(".lazy_symbol_pointer"))==0 || |
| 172 | strncmp(Str, ".non_lazy_symbol_pointer", strlen(".non_lazy_symbol_pointer"))==0 || |
| 173 | strncmp(Str, ".dyld", strlen(".dyld"))==0 || |
| 174 | strncmp(Str, ".const_data", strlen(".const_data"))==0 || |
| 175 | strncmp(Str, ".objc", strlen(".objc"))==0 || //// many directives |
| 176 | strncmp(Str, ".static_const", strlen(".static_const"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 177 | inTextSection=false; |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 178 | else if (strncmp(Str, ".text", strlen(".text"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 179 | inTextSection = true; |
| 180 | // Some can't really be handled without implementing significant pieces |
| 181 | // of an assembler. Others require dynamic adjustment of block sizes in |
| 182 | // AdjustBBOffsetsAfter; it's a big compile-time speed hit to check every |
| 183 | // instruction in there, and none of these are currently used in the kernel. |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 184 | else if (strncmp(Str, ".macro", strlen(".macro"))==0 || |
| 185 | strncmp(Str, ".if", strlen(".if"))==0 || |
| 186 | strncmp(Str, ".align", strlen(".align"))==0 || |
| 187 | strncmp(Str, ".fill", strlen(".fill"))==0 || |
| 188 | strncmp(Str, ".space", strlen(".space"))==0 || |
| 189 | strncmp(Str, ".zerofill", strlen(".zerofill"))==0 || |
| 190 | strncmp(Str, ".p2align", strlen(".p2align"))==0 || |
| 191 | strncmp(Str, ".p2alignw", strlen(".p2alignw"))==0 || |
| 192 | strncmp(Str, ".p2alignl", strlen(".p2alignl"))==0 || |
| 193 | strncmp(Str, ".align32", strlen(".p2align32"))==0 || |
| 194 | strncmp(Str, ".include", strlen(".include"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 195 | cerr << "Directive " << Str << " in asm may lead to invalid offsets for" << |
| 196 | " constant pools (the assembler will tell you if this happens).\n"; |
| 197 | // Some generate code, but this is only interesting in the text section. |
| 198 | else if (inTextSection) { |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 199 | if (strncmp(Str, ".long", strlen(".long"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 200 | Length += 4*countArguments(Str+strlen(".long")); |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 201 | else if (strncmp(Str, ".short", strlen(".short"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 202 | Length += 2*countArguments(Str+strlen(".short")); |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 203 | else if (strncmp(Str, ".byte", strlen(".byte"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 204 | Length += 1*countArguments(Str+strlen(".byte")); |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 205 | else if (strncmp(Str, ".single", strlen(".single"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 206 | Length += 4*countArguments(Str+strlen(".single")); |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 207 | else if (strncmp(Str, ".double", strlen(".double"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 208 | Length += 8*countArguments(Str+strlen(".double")); |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 209 | else if (strncmp(Str, ".quad", strlen(".quad"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 210 | Length += 16*countArguments(Str+strlen(".quad")); |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 211 | else if (strncmp(Str, ".ascii", strlen(".ascii"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 212 | Length += countString(Str+strlen(".ascii")); |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 213 | else if (strncmp(Str, ".asciz", strlen(".asciz"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 214 | Length += countString(Str+strlen(".asciz"))+1; |
| 215 | } |
| 216 | } else if (inTextSection) { |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 217 | // An instruction |
| 218 | atInsnStart = false; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 219 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 220 | // BL and BLX <non-reg> are 4 bytes, all others 2. |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 221 | if (strncmp(Str, "blx", strlen("blx"))==0) { |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 222 | const char* p = Str+3; |
| 223 | while (*p && isspace(*p)) |
| 224 | p++; |
| 225 | if (*p == 'r' || *p=='R') |
| 226 | Length += 2; // BLX reg |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 227 | else |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 228 | Length += 4; // BLX non-reg |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 229 | } else if (strncmp(Str, "bl", strlen("bl"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 230 | Length += 4; // BL |
| 231 | else |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 232 | Length += 2; // Thumb anything else |
| 233 | } |
| 234 | else |
| 235 | Length += 4; // ARM |
| 236 | } |
| 237 | } |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 238 | if (*Str == '\n' || *Str == BaseTAI::SeparatorChar) |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 239 | atInsnStart = true; |
| 240 | } |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 241 | free(s_copy); |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 242 | return Length; |
| 243 | } |
Anton Korobeynikov | 6381a13 | 2008-10-05 08:53:29 +0000 | [diff] [blame] | 244 | |
| 245 | // Instantiate default implementation. |
| 246 | TEMPLATE_INSTANTIATION(class ARMTargetAsmInfo<TargetAsmInfo>); |