Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame^] | 1 | |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 2 | //===-- ARMTargetAsmInfo.cpp - ARM asm properties ---------------*- C++ -*-===// |
| 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file was developed by James M. Laskey and is distributed under the |
| 7 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | // |
| 11 | // This file contains the declarations of the ARMTargetAsmInfo properties. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "ARMTargetAsmInfo.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 16 | #include "ARMTargetMachine.h" |
Dale Johannesen | 24fb52d | 2007-04-23 20:04:35 +0000 | [diff] [blame] | 17 | #include <cstring> |
| 18 | #include <cctype> |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 19 | using namespace llvm; |
| 20 | |
| 21 | ARMTargetAsmInfo::ARMTargetAsmInfo(const ARMTargetMachine &TM) { |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame^] | 22 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Evan Cheng | e433ea9 | 2007-01-19 19:23:47 +0000 | [diff] [blame] | 23 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 24 | GlobalPrefix = "_"; |
Evan Cheng | e433ea9 | 2007-01-19 19:23:47 +0000 | [diff] [blame] | 25 | PrivateGlobalPrefix = "L"; |
| 26 | BSSSection = 0; // no BSS section. |
| 27 | ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 28 | SetDirective = "\t.set"; |
| 29 | WeakRefDirective = "\t.weak_reference\t"; |
Evan Cheng | a6f567c | 2007-01-23 19:06:03 +0000 | [diff] [blame] | 30 | HiddenDirective = "\t.private_extern\t"; |
Lauro Ramos Venancio | 0a18173 | 2007-04-30 00:23:51 +0000 | [diff] [blame] | 31 | ProtectedDirective = NULL; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 32 | JumpTableDataSection = ".const"; |
| 33 | CStringSection = "\t.cstring"; |
Evan Cheng | 98ded76 | 2007-03-08 01:25:25 +0000 | [diff] [blame] | 34 | FourByteConstantSection = "\t.literal4\n"; |
| 35 | EightByteConstantSection = "\t.literal8\n"; |
| 36 | ReadOnlySection = "\t.const\n"; |
Evan Cheng | e433ea9 | 2007-01-19 19:23:47 +0000 | [diff] [blame] | 37 | HasDotTypeDotSizeDirective = false; |
Evan Cheng | b267ca1 | 2007-01-30 08:04:53 +0000 | [diff] [blame] | 38 | if (TM.getRelocationModel() == Reloc::Static) { |
| 39 | StaticCtorsSection = ".constructor"; |
| 40 | StaticDtorsSection = ".destructor"; |
| 41 | } else { |
| 42 | StaticCtorsSection = ".mod_init_func"; |
| 43 | StaticDtorsSection = ".mod_term_func"; |
| 44 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 45 | |
Evan Cheng | 8e1185b | 2007-01-19 18:59:56 +0000 | [diff] [blame] | 46 | // In non-PIC modes, emit a special label before jump tables so that the |
| 47 | // linker can perform more accurate dead code stripping. |
| 48 | if (TM.getRelocationModel() != Reloc::PIC_) { |
| 49 | // Emit a local label that is preserved until the linker runs. |
| 50 | JumpTableSpecialLabelPrefix = "l"; |
| 51 | } |
| 52 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 53 | NeedsSet = true; |
| 54 | DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug"; |
| 55 | DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug"; |
| 56 | DwarfLineSection = ".section __DWARF,__debug_line,regular,debug"; |
| 57 | DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug"; |
| 58 | DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug"; |
| 59 | DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug"; |
| 60 | DwarfStrSection = ".section __DWARF,__debug_str,regular,debug"; |
| 61 | DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug"; |
| 62 | DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug"; |
| 63 | DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug"; |
| 64 | DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug"; |
| 65 | } else { |
Lauro Ramos Venancio | c33f674 | 2007-02-01 21:43:53 +0000 | [diff] [blame] | 66 | PrivateGlobalPrefix = ".L"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 67 | WeakRefDirective = "\t.weak\t"; |
Lauro Ramos Venancio | 6d7dd8e | 2007-03-05 17:59:58 +0000 | [diff] [blame] | 68 | if (Subtarget->isAAPCS_ABI()) { |
| 69 | StaticCtorsSection = "\t.section .init_array,\"aw\",%init_array"; |
| 70 | StaticDtorsSection = "\t.section .fini_array,\"aw\",%fini_array"; |
| 71 | } else { |
| 72 | StaticCtorsSection = "\t.section .ctors,\"aw\",%progbits"; |
| 73 | StaticDtorsSection = "\t.section .dtors,\"aw\",%progbits"; |
| 74 | } |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 75 | TLSDataSection = "\t.section .tdata,\"awT\",%progbits"; |
| 76 | TLSBSSSection = "\t.section .tbss,\"awT\",%nobits"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 77 | } |
Lauro Ramos Venancio | ea9fc58 | 2007-01-26 23:24:43 +0000 | [diff] [blame] | 78 | |
| 79 | ZeroDirective = "\t.space\t"; |
| 80 | AlignmentIsInBytes = false; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 81 | Data64bitsDirective = 0; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 82 | CommentString = "@"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 83 | DataSection = "\t.data"; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 84 | ConstantPoolSection = "\t.text\n"; |
Lauro Ramos Venancio | ea9fc58 | 2007-01-26 23:24:43 +0000 | [diff] [blame] | 85 | COMMDirectiveTakesAlignment = false; |
| 86 | InlineAsmStart = "@ InlineAsm Start"; |
| 87 | InlineAsmEnd = "@ InlineAsm End"; |
| 88 | LCOMMDirective = "\t.lcomm\t"; |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame^] | 89 | } |
| 90 | |
| 91 | /// Count the number of comma-separated arguments. |
| 92 | /// Do not try to detect errors. |
| 93 | unsigned ARMTargetAsmInfo::countArguments(const char* p) const { |
| 94 | unsigned count = 0; |
| 95 | while (*p && isspace(*p) && *p != '\n') |
| 96 | p++; |
| 97 | count++; |
| 98 | while (*p && *p!='\n' && |
| 99 | strncmp(p, CommentString, strlen(CommentString))!=0) { |
| 100 | if (*p==',') |
| 101 | count++; |
| 102 | p++; |
| 103 | } |
| 104 | return count; |
| 105 | } |
| 106 | |
| 107 | /// Count the length of a string enclosed in quote characters. |
| 108 | /// Do not try to detect errors. |
| 109 | unsigned ARMTargetAsmInfo::countString(const char* p) const { |
| 110 | unsigned count = 0; |
| 111 | while (*p && isspace(*p) && *p!='\n') |
| 112 | p++; |
| 113 | if (!*p || *p != '\"') |
| 114 | return count; |
| 115 | while (*++p && *p != '\"') |
| 116 | count++; |
| 117 | return count; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 118 | } |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 119 | |
| 120 | /// ARM-specific version of TargetAsmInfo::getInlineAsmLength. |
| 121 | unsigned ARMTargetAsmInfo::getInlineAsmLength(const char *Str) const { |
| 122 | // Count the number of bytes in the asm. |
| 123 | bool atInsnStart = true; |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame^] | 124 | bool inTextSection = true; |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 125 | unsigned Length = 0; |
| 126 | for (; *Str; ++Str) { |
| 127 | if (atInsnStart) { |
| 128 | // Skip whitespace |
| 129 | while (*Str && isspace(*Str) && *Str != '\n') |
| 130 | Str++; |
| 131 | // Skip label |
| 132 | for (const char* p = Str; *p && !isspace(*p); p++) |
| 133 | if (*p == ':') { |
| 134 | Str = p+1; |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame^] | 135 | while (*Str && isspace(*Str) && *Str != '\n') |
| 136 | Str++; |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 137 | break; |
| 138 | } |
| 139 | // Ignore everything from comment char(s) to EOL |
| 140 | if (strncmp(Str, CommentString, strlen(CommentString))==-0) |
| 141 | atInsnStart = false; |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame^] | 142 | // FIXME do something like the following for non-Darwin |
| 143 | else if (*Str == '.' && Subtarget->isTargetDarwin()) { |
| 144 | // Directive. |
| 145 | atInsnStart = false; |
| 146 | // Some change the section, but don't generate code. |
| 147 | if (strncasecmp(Str, ".literal4", strlen(".literal4"))==0 || |
| 148 | strncasecmp(Str, ".literal8", strlen(".literal8"))==0 || |
| 149 | strncasecmp(Str, ".const", strlen(".const"))==0 || |
| 150 | strncasecmp(Str, ".constructor", strlen(".constructor"))==0 || |
| 151 | strncasecmp(Str, ".cstring", strlen(".cstring"))==0 || |
| 152 | strncasecmp(Str, ".data", strlen(".data"))==0 || |
| 153 | strncasecmp(Str, ".destructor", strlen(".destructor"))==0 || |
| 154 | strncasecmp(Str, ".fvmlib_init0", strlen(".fvmlib_init0"))==0 || |
| 155 | strncasecmp(Str, ".fvmlib_init1", strlen(".fvmlib_init1"))==0 || |
| 156 | strncasecmp(Str, ".mod_init_func", strlen(".mod_init_func"))==0 || |
| 157 | strncasecmp(Str, ".mod_term_func", strlen(".mod_term_func"))==0 || |
| 158 | strncasecmp(Str, ".picsymbol_stub", strlen(".picsymbol_stub"))==0 || |
| 159 | strncasecmp(Str, ".symbol_stub", strlen(".symbol_stub"))==0 || |
| 160 | strncasecmp(Str, ".static_data", strlen(".static_data"))==0 || |
| 161 | strncasecmp(Str, ".section", strlen(".section"))==0 || |
| 162 | strncasecmp(Str, ".lazy_symbol_pointer", strlen(".lazy_symbol_pointer"))==0 || |
| 163 | strncasecmp(Str, ".non_lazy_symbol_pointer", strlen(".non_lazy_symbol_pointer"))==0 || |
| 164 | strncasecmp(Str, ".dyld", strlen(".dyld"))==0 || |
| 165 | strncasecmp(Str, ".const_data", strlen(".const_data"))==0 || |
| 166 | strncasecmp(Str, ".objc", strlen(".objc"))==0 || //// many directives |
| 167 | strncasecmp(Str, ".static_const", strlen(".static_const"))==0) |
| 168 | inTextSection=false; |
| 169 | else if (strncasecmp(Str, ".text", strlen(".text"))==0) |
| 170 | inTextSection = true; |
| 171 | // Some can't really be handled without implementing significant pieces |
| 172 | // of an assembler. Others require dynamic adjustment of block sizes in |
| 173 | // AdjustBBOffsetsAfter; it's a big compile-time speed hit to check every |
| 174 | // instruction in there, and none of these are currently used in the kernel. |
| 175 | else if (strncasecmp(Str, ".macro", strlen(".macro"))==0 || |
| 176 | strncasecmp(Str, ".if", strlen(".if"))==0 || |
| 177 | strncasecmp(Str, ".align", strlen(".align"))==0 || |
| 178 | strncasecmp(Str, ".fill", strlen(".fill"))==0 || |
| 179 | strncasecmp(Str, ".space", strlen(".space"))==0 || |
| 180 | strncasecmp(Str, ".zerofill", strlen(".zerofill"))==0 || |
| 181 | strncasecmp(Str, ".p2align", strlen(".p2align"))==0 || |
| 182 | strncasecmp(Str, ".p2alignw", strlen(".p2alignw"))==0 || |
| 183 | strncasecmp(Str, ".p2alignl", strlen(".p2alignl"))==0 || |
| 184 | strncasecmp(Str, ".align32", strlen(".p2align32"))==0 || |
| 185 | strncasecmp(Str, ".include", strlen(".include"))==0) |
| 186 | cerr << "Directive " << Str << " in asm may lead to invalid offsets for" << |
| 187 | " constant pools (the assembler will tell you if this happens).\n"; |
| 188 | // Some generate code, but this is only interesting in the text section. |
| 189 | else if (inTextSection) { |
| 190 | if (strncasecmp(Str, ".long", strlen(".long"))==0) |
| 191 | Length += 4*countArguments(Str+strlen(".long")); |
| 192 | else if (strncasecmp(Str, ".short", strlen(".short"))==0) |
| 193 | Length += 2*countArguments(Str+strlen(".short")); |
| 194 | else if (strncasecmp(Str, ".byte", strlen(".byte"))==0) |
| 195 | Length += 1*countArguments(Str+strlen(".byte")); |
| 196 | else if (strncasecmp(Str, ".single", strlen(".single"))==0) |
| 197 | Length += 4*countArguments(Str+strlen(".single")); |
| 198 | else if (strncasecmp(Str, ".double", strlen(".double"))==0) |
| 199 | Length += 8*countArguments(Str+strlen(".double")); |
| 200 | else if (strncasecmp(Str, ".quad", strlen(".quad"))==0) |
| 201 | Length += 16*countArguments(Str+strlen(".quad")); |
| 202 | else if (strncasecmp(Str, ".ascii", strlen(".ascii"))==0) |
| 203 | Length += countString(Str+strlen(".ascii")); |
| 204 | else if (strncasecmp(Str, ".asciz", strlen(".asciz"))==0) |
| 205 | Length += countString(Str+strlen(".asciz"))+1; |
| 206 | } |
| 207 | } else if (inTextSection) { |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 208 | // An instruction |
| 209 | atInsnStart = false; |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame^] | 210 | if (Subtarget->isThumb()) { |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 211 | // BL and BLX <non-reg> are 4 bytes, all others 2. |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame^] | 212 | if (strncasecmp(Str, "blx", strlen("blx"))==0) { |
| 213 | const char* p = Str+3; |
| 214 | while (*p && isspace(*p)) |
| 215 | p++; |
| 216 | if (*p == 'r' || *p=='R') |
| 217 | Length += 2; // BLX reg |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 218 | else |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame^] | 219 | Length += 4; // BLX non-reg |
| 220 | } else if (strncasecmp(Str, "bl", strlen("bl"))==0) |
| 221 | Length += 4; // BL |
| 222 | else |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 223 | Length += 2; // Thumb anything else |
| 224 | } |
| 225 | else |
| 226 | Length += 4; // ARM |
| 227 | } |
| 228 | } |
| 229 | if (*Str == '\n' || *Str == SeparatorChar) |
| 230 | atInsnStart = true; |
| 231 | } |
| 232 | return Length; |
| 233 | } |