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 | // |
| 5 | // This file was developed by James M. Laskey and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
| 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 | |
| 20 | ARMTargetAsmInfo::ARMTargetAsmInfo(const ARMTargetMachine &TM) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 21 | const ARMSubtarget *Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Evan Cheng | e433ea9 | 2007-01-19 19:23:47 +0000 | [diff] [blame] | 22 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 23 | GlobalPrefix = "_"; |
Evan Cheng | e433ea9 | 2007-01-19 19:23:47 +0000 | [diff] [blame] | 24 | PrivateGlobalPrefix = "L"; |
| 25 | BSSSection = 0; // no BSS section. |
| 26 | ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 27 | SetDirective = "\t.set"; |
| 28 | WeakRefDirective = "\t.weak_reference\t"; |
Evan Cheng | a6f567c | 2007-01-23 19:06:03 +0000 | [diff] [blame] | 29 | HiddenDirective = "\t.private_extern\t"; |
Lauro Ramos Venancio | 0a18173 | 2007-04-30 00:23:51 +0000 | [diff] [blame^] | 30 | ProtectedDirective = NULL; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 31 | JumpTableDataSection = ".const"; |
| 32 | CStringSection = "\t.cstring"; |
Evan Cheng | 98ded76 | 2007-03-08 01:25:25 +0000 | [diff] [blame] | 33 | FourByteConstantSection = "\t.literal4\n"; |
| 34 | EightByteConstantSection = "\t.literal8\n"; |
| 35 | ReadOnlySection = "\t.const\n"; |
Evan Cheng | e433ea9 | 2007-01-19 19:23:47 +0000 | [diff] [blame] | 36 | HasDotTypeDotSizeDirective = false; |
Evan Cheng | b267ca1 | 2007-01-30 08:04:53 +0000 | [diff] [blame] | 37 | if (TM.getRelocationModel() == Reloc::Static) { |
| 38 | StaticCtorsSection = ".constructor"; |
| 39 | StaticDtorsSection = ".destructor"; |
| 40 | } else { |
| 41 | StaticCtorsSection = ".mod_init_func"; |
| 42 | StaticDtorsSection = ".mod_term_func"; |
| 43 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 44 | |
Evan Cheng | 8e1185b | 2007-01-19 18:59:56 +0000 | [diff] [blame] | 45 | // In non-PIC modes, emit a special label before jump tables so that the |
| 46 | // linker can perform more accurate dead code stripping. |
| 47 | if (TM.getRelocationModel() != Reloc::PIC_) { |
| 48 | // Emit a local label that is preserved until the linker runs. |
| 49 | JumpTableSpecialLabelPrefix = "l"; |
| 50 | } |
| 51 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 52 | NeedsSet = true; |
| 53 | DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug"; |
| 54 | DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug"; |
| 55 | DwarfLineSection = ".section __DWARF,__debug_line,regular,debug"; |
| 56 | DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug"; |
| 57 | DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug"; |
| 58 | DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug"; |
| 59 | DwarfStrSection = ".section __DWARF,__debug_str,regular,debug"; |
| 60 | DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug"; |
| 61 | DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug"; |
| 62 | DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug"; |
| 63 | DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug"; |
| 64 | } else { |
Lauro Ramos Venancio | c33f674 | 2007-02-01 21:43:53 +0000 | [diff] [blame] | 65 | PrivateGlobalPrefix = ".L"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 66 | WeakRefDirective = "\t.weak\t"; |
Lauro Ramos Venancio | 6d7dd8e | 2007-03-05 17:59:58 +0000 | [diff] [blame] | 67 | if (Subtarget->isAAPCS_ABI()) { |
| 68 | StaticCtorsSection = "\t.section .init_array,\"aw\",%init_array"; |
| 69 | StaticDtorsSection = "\t.section .fini_array,\"aw\",%fini_array"; |
| 70 | } else { |
| 71 | StaticCtorsSection = "\t.section .ctors,\"aw\",%progbits"; |
| 72 | StaticDtorsSection = "\t.section .dtors,\"aw\",%progbits"; |
| 73 | } |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 74 | TLSDataSection = "\t.section .tdata,\"awT\",%progbits"; |
| 75 | TLSBSSSection = "\t.section .tbss,\"awT\",%nobits"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 76 | } |
Lauro Ramos Venancio | ea9fc58 | 2007-01-26 23:24:43 +0000 | [diff] [blame] | 77 | |
| 78 | ZeroDirective = "\t.space\t"; |
| 79 | AlignmentIsInBytes = false; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 80 | Data64bitsDirective = 0; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 81 | CommentString = "@"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 82 | DataSection = "\t.data"; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 83 | ConstantPoolSection = "\t.text\n"; |
Lauro Ramos Venancio | ea9fc58 | 2007-01-26 23:24:43 +0000 | [diff] [blame] | 84 | COMMDirectiveTakesAlignment = false; |
| 85 | InlineAsmStart = "@ InlineAsm Start"; |
| 86 | InlineAsmEnd = "@ InlineAsm End"; |
| 87 | LCOMMDirective = "\t.lcomm\t"; |
Dale Johannesen | 24fb52d | 2007-04-23 20:04:35 +0000 | [diff] [blame] | 88 | isThumb = Subtarget->isThumb(); |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 89 | } |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 90 | |
| 91 | /// ARM-specific version of TargetAsmInfo::getInlineAsmLength. |
| 92 | unsigned ARMTargetAsmInfo::getInlineAsmLength(const char *Str) const { |
| 93 | // Count the number of bytes in the asm. |
| 94 | bool atInsnStart = true; |
| 95 | unsigned Length = 0; |
| 96 | for (; *Str; ++Str) { |
| 97 | if (atInsnStart) { |
| 98 | // Skip whitespace |
| 99 | while (*Str && isspace(*Str) && *Str != '\n') |
| 100 | Str++; |
| 101 | // Skip label |
| 102 | for (const char* p = Str; *p && !isspace(*p); p++) |
| 103 | if (*p == ':') { |
| 104 | Str = p+1; |
| 105 | break; |
| 106 | } |
| 107 | // Ignore everything from comment char(s) to EOL |
| 108 | if (strncmp(Str, CommentString, strlen(CommentString))==-0) |
| 109 | atInsnStart = false; |
| 110 | else { |
| 111 | // An instruction |
| 112 | atInsnStart = false; |
| 113 | if (isThumb) { |
| 114 | // BL and BLX <non-reg> are 4 bytes, all others 2. |
| 115 | const char*p = Str; |
| 116 | if ((*Str=='b' || *Str=='B') && |
| 117 | (*(Str+1)=='l' || *(Str+1)=='L')) { |
| 118 | if (*(Str+2)=='x' || *(Str+2)=='X') { |
| 119 | const char* p = Str+3; |
| 120 | while (*p && isspace(*p)) |
| 121 | p++; |
| 122 | if (*p == 'r' || *p=='R') |
| 123 | Length += 2; // BLX reg |
| 124 | else |
| 125 | Length += 4; // BLX non-reg |
| 126 | } |
| 127 | else |
| 128 | Length += 4; // BL |
| 129 | } else |
| 130 | Length += 2; // Thumb anything else |
| 131 | } |
| 132 | else |
| 133 | Length += 4; // ARM |
| 134 | } |
| 135 | } |
| 136 | if (*Str == '\n' || *Str == SeparatorChar) |
| 137 | atInsnStart = true; |
| 138 | } |
| 139 | return Length; |
| 140 | } |