blob: 3d24d60c6a68aead999a4ccce9f234965216cbba [file] [log] [blame]
Jim Laskey8e8de8f2006-09-07 22:05:02 +00001//===-- 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 Chenga8e29892007-01-19 07:51:42 +000015#include "ARMTargetMachine.h"
Dale Johannesen24fb52d2007-04-23 20:04:35 +000016#include <cstring>
17#include <cctype>
Jim Laskey8e8de8f2006-09-07 22:05:02 +000018using namespace llvm;
19
20ARMTargetAsmInfo::ARMTargetAsmInfo(const ARMTargetMachine &TM) {
Evan Chenga8e29892007-01-19 07:51:42 +000021 const ARMSubtarget *Subtarget = &TM.getSubtarget<ARMSubtarget>();
Evan Chenge433ea92007-01-19 19:23:47 +000022 if (Subtarget->isTargetDarwin()) {
Evan Chenga8e29892007-01-19 07:51:42 +000023 GlobalPrefix = "_";
Evan Chenge433ea92007-01-19 19:23:47 +000024 PrivateGlobalPrefix = "L";
25 BSSSection = 0; // no BSS section.
26 ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill
Evan Chenga8e29892007-01-19 07:51:42 +000027 SetDirective = "\t.set";
28 WeakRefDirective = "\t.weak_reference\t";
Evan Chenga6f567c2007-01-23 19:06:03 +000029 HiddenDirective = "\t.private_extern\t";
Evan Chenga8e29892007-01-19 07:51:42 +000030 JumpTableDataSection = ".const";
31 CStringSection = "\t.cstring";
Evan Cheng98ded762007-03-08 01:25:25 +000032 FourByteConstantSection = "\t.literal4\n";
33 EightByteConstantSection = "\t.literal8\n";
34 ReadOnlySection = "\t.const\n";
Evan Chenge433ea92007-01-19 19:23:47 +000035 HasDotTypeDotSizeDirective = false;
Evan Chengb267ca12007-01-30 08:04:53 +000036 if (TM.getRelocationModel() == Reloc::Static) {
37 StaticCtorsSection = ".constructor";
38 StaticDtorsSection = ".destructor";
39 } else {
40 StaticCtorsSection = ".mod_init_func";
41 StaticDtorsSection = ".mod_term_func";
42 }
Evan Chenga8e29892007-01-19 07:51:42 +000043
Evan Cheng8e1185b2007-01-19 18:59:56 +000044 // In non-PIC modes, emit a special label before jump tables so that the
45 // linker can perform more accurate dead code stripping.
46 if (TM.getRelocationModel() != Reloc::PIC_) {
47 // Emit a local label that is preserved until the linker runs.
48 JumpTableSpecialLabelPrefix = "l";
49 }
50
Evan Chenga8e29892007-01-19 07:51:42 +000051 NeedsSet = true;
52 DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
53 DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
54 DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
55 DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
56 DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
57 DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
58 DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
59 DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
60 DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
61 DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
62 DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
63 } else {
Lauro Ramos Venancioc33f6742007-02-01 21:43:53 +000064 PrivateGlobalPrefix = ".L";
Evan Chenga8e29892007-01-19 07:51:42 +000065 WeakRefDirective = "\t.weak\t";
Lauro Ramos Venancio6d7dd8e2007-03-05 17:59:58 +000066 if (Subtarget->isAAPCS_ABI()) {
67 StaticCtorsSection = "\t.section .init_array,\"aw\",%init_array";
68 StaticDtorsSection = "\t.section .fini_array,\"aw\",%fini_array";
69 } else {
70 StaticCtorsSection = "\t.section .ctors,\"aw\",%progbits";
71 StaticDtorsSection = "\t.section .dtors,\"aw\",%progbits";
72 }
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000073 TLSDataSection = "\t.section .tdata,\"awT\",%progbits";
74 TLSBSSSection = "\t.section .tbss,\"awT\",%nobits";
Evan Chenga8e29892007-01-19 07:51:42 +000075 }
Lauro Ramos Venancioea9fc582007-01-26 23:24:43 +000076
77 ZeroDirective = "\t.space\t";
78 AlignmentIsInBytes = false;
Jim Laskey8e8de8f2006-09-07 22:05:02 +000079 Data64bitsDirective = 0;
Jim Laskey8e8de8f2006-09-07 22:05:02 +000080 CommentString = "@";
Evan Chenga8e29892007-01-19 07:51:42 +000081 DataSection = "\t.data";
Jim Laskey8e8de8f2006-09-07 22:05:02 +000082 ConstantPoolSection = "\t.text\n";
Lauro Ramos Venancioea9fc582007-01-26 23:24:43 +000083 COMMDirectiveTakesAlignment = false;
84 InlineAsmStart = "@ InlineAsm Start";
85 InlineAsmEnd = "@ InlineAsm End";
86 LCOMMDirective = "\t.lcomm\t";
Dale Johannesen24fb52d2007-04-23 20:04:35 +000087 isThumb = Subtarget->isThumb();
Jim Laskey8e8de8f2006-09-07 22:05:02 +000088}
Dale Johannesen86501992007-04-29 19:17:45 +000089
90/// ARM-specific version of TargetAsmInfo::getInlineAsmLength.
91unsigned ARMTargetAsmInfo::getInlineAsmLength(const char *Str) const {
92 // Count the number of bytes in the asm.
93 bool atInsnStart = true;
94 unsigned Length = 0;
95 for (; *Str; ++Str) {
96 if (atInsnStart) {
97 // Skip whitespace
98 while (*Str && isspace(*Str) && *Str != '\n')
99 Str++;
100 // Skip label
101 for (const char* p = Str; *p && !isspace(*p); p++)
102 if (*p == ':') {
103 Str = p+1;
104 break;
105 }
106 // Ignore everything from comment char(s) to EOL
107 if (strncmp(Str, CommentString, strlen(CommentString))==-0)
108 atInsnStart = false;
109 else {
110 // An instruction
111 atInsnStart = false;
112 if (isThumb) {
113 // BL and BLX <non-reg> are 4 bytes, all others 2.
114 const char*p = Str;
115 if ((*Str=='b' || *Str=='B') &&
116 (*(Str+1)=='l' || *(Str+1)=='L')) {
117 if (*(Str+2)=='x' || *(Str+2)=='X') {
118 const char* p = Str+3;
119 while (*p && isspace(*p))
120 p++;
121 if (*p == 'r' || *p=='R')
122 Length += 2; // BLX reg
123 else
124 Length += 4; // BLX non-reg
125 }
126 else
127 Length += 4; // BL
128 } else
129 Length += 2; // Thumb anything else
130 }
131 else
132 Length += 4; // ARM
133 }
134 }
135 if (*Str == '\n' || *Str == SeparatorChar)
136 atInsnStart = true;
137 }
138 return Length;
139}