1 //===-- ARMTargetAsmInfo.cpp - ARM asm properties ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declarations of the ARMTargetAsmInfo properties.
12 //===----------------------------------------------------------------------===//
14 #include "ARMTargetAsmInfo.h"
15 #include "ARMTargetMachine.h"
20 static const char* arm_asm_table
[] = {"{r0}", "r0",
44 ARMTargetAsmInfo::ARMTargetAsmInfo(const ARMTargetMachine
&TM
) {
45 Subtarget
= &TM
.getSubtarget
<ARMSubtarget
>();
46 AsmTransCBE
= arm_asm_table
;
47 if (Subtarget
->isTargetDarwin()) {
49 PrivateGlobalPrefix
= "L";
50 BSSSection
= 0; // no BSS section.
51 ZeroFillDirective
= "\t.zerofill\t"; // Uses .zerofill
52 SetDirective
= "\t.set";
53 WeakRefDirective
= "\t.weak_reference\t";
54 HiddenDirective
= "\t.private_extern\t";
55 ProtectedDirective
= NULL
;
56 JumpTableDataSection
= ".const";
57 CStringSection
= "\t.cstring";
58 FourByteConstantSection
= "\t.literal4\n";
59 EightByteConstantSection
= "\t.literal8\n";
60 ReadOnlySection
= "\t.const\n";
61 HasDotTypeDotSizeDirective
= false;
62 NeedsIndirectEncoding
= true;
63 if (TM
.getRelocationModel() == Reloc::Static
) {
64 StaticCtorsSection
= ".constructor";
65 StaticDtorsSection
= ".destructor";
67 StaticCtorsSection
= ".mod_init_func";
68 StaticDtorsSection
= ".mod_term_func";
71 // In non-PIC modes, emit a special label before jump tables so that the
72 // linker can perform more accurate dead code stripping.
73 if (TM
.getRelocationModel() != Reloc::PIC_
) {
74 // Emit a local label that is preserved until the linker runs.
75 JumpTableSpecialLabelPrefix
= "l";
79 DwarfAbbrevSection
= ".section __DWARF,__debug_abbrev,regular,debug";
80 DwarfInfoSection
= ".section __DWARF,__debug_info,regular,debug";
81 DwarfLineSection
= ".section __DWARF,__debug_line,regular,debug";
82 DwarfFrameSection
= ".section __DWARF,__debug_frame,regular,debug";
83 DwarfPubNamesSection
= ".section __DWARF,__debug_pubnames,regular,debug";
84 DwarfPubTypesSection
= ".section __DWARF,__debug_pubtypes,regular,debug";
85 DwarfStrSection
= ".section __DWARF,__debug_str,regular,debug";
86 DwarfLocSection
= ".section __DWARF,__debug_loc,regular,debug";
87 DwarfARangesSection
= ".section __DWARF,__debug_aranges,regular,debug";
88 DwarfRangesSection
= ".section __DWARF,__debug_ranges,regular,debug";
89 DwarfMacInfoSection
= ".section __DWARF,__debug_macinfo,regular,debug";
93 AbsoluteDebugSectionOffsets
= true;
94 ReadOnlySection
= "\t.section\t.rodata\n";
95 PrivateGlobalPrefix
= ".L";
96 WeakRefDirective
= "\t.weak\t";
97 SetDirective
= "\t.set\t";
98 DwarfRequiresFrameSection
= false;
99 DwarfAbbrevSection
= "\t.section\t.debug_abbrev,\"\",%progbits";
100 DwarfInfoSection
= "\t.section\t.debug_info,\"\",%progbits";
101 DwarfLineSection
= "\t.section\t.debug_line,\"\",%progbits";
102 DwarfFrameSection
= "\t.section\t.debug_frame,\"\",%progbits";
103 DwarfPubNamesSection
="\t.section\t.debug_pubnames,\"\",%progbits";
104 DwarfPubTypesSection
="\t.section\t.debug_pubtypes,\"\",%progbits";
105 DwarfStrSection
= "\t.section\t.debug_str,\"\",%progbits";
106 DwarfLocSection
= "\t.section\t.debug_loc,\"\",%progbits";
107 DwarfARangesSection
= "\t.section\t.debug_aranges,\"\",%progbits";
108 DwarfRangesSection
= "\t.section\t.debug_ranges,\"\",%progbits";
109 DwarfMacInfoSection
= "\t.section\t.debug_macinfo,\"\",%progbits";
111 if (Subtarget
->isAAPCS_ABI()) {
112 StaticCtorsSection
= "\t.section .init_array,\"aw\",%init_array";
113 StaticDtorsSection
= "\t.section .fini_array,\"aw\",%fini_array";
115 StaticCtorsSection
= "\t.section .ctors,\"aw\",%progbits";
116 StaticDtorsSection
= "\t.section .dtors,\"aw\",%progbits";
118 TLSDataSection
= "\t.section .tdata,\"awT\",%progbits";
119 TLSBSSSection
= "\t.section .tbss,\"awT\",%nobits";
122 ZeroDirective
= "\t.space\t";
123 AlignmentIsInBytes
= false;
124 Data64bitsDirective
= 0;
126 DataSection
= "\t.data";
127 ConstantPoolSection
= "\t.text\n";
128 COMMDirectiveTakesAlignment
= false;
129 InlineAsmStart
= "@ InlineAsm Start";
130 InlineAsmEnd
= "@ InlineAsm End";
131 LCOMMDirective
= "\t.lcomm\t";
134 /// Count the number of comma-separated arguments.
135 /// Do not try to detect errors.
136 unsigned ARMTargetAsmInfo::countArguments(const char* p
) const {
138 while (*p
&& isspace(*p
) && *p
!= '\n')
141 while (*p
&& *p
!='\n' &&
142 strncmp(p
, CommentString
, strlen(CommentString
))!=0) {
150 /// Count the length of a string enclosed in quote characters.
151 /// Do not try to detect errors.
152 unsigned ARMTargetAsmInfo::countString(const char* p
) const {
154 while (*p
&& isspace(*p
) && *p
!='\n')
156 if (!*p
|| *p
!= '\"')
158 while (*++p
&& *p
!= '\"')
163 /// ARM-specific version of TargetAsmInfo::getInlineAsmLength.
164 unsigned ARMTargetAsmInfo::getInlineAsmLength(const char *s
) const {
165 // Make a lowercase-folded version of s for counting purposes.
166 char *q
, *s_copy
= (char *)malloc(strlen(s
) + 1);
168 for (q
=s_copy
; *q
; q
++)
170 const char *Str
= s_copy
;
172 // Count the number of bytes in the asm.
173 bool atInsnStart
= true;
174 bool inTextSection
= true;
176 for (; *Str
; ++Str
) {
179 while (*Str
&& isspace(*Str
) && *Str
!= '\n')
182 for (const char* p
= Str
; *p
&& !isspace(*p
); p
++)
185 while (*Str
&& isspace(*Str
) && *Str
!= '\n')
189 // Ignore everything from comment char(s) to EOL
190 if (strncmp(Str
, CommentString
, strlen(CommentString
))==-0)
192 // FIXME do something like the following for non-Darwin
193 else if (*Str
== '.' && Subtarget
->isTargetDarwin()) {
197 // Some change the section, but don't generate code.
198 if (strncmp(Str
, ".literal4", strlen(".literal4"))==0 ||
199 strncmp(Str
, ".literal8", strlen(".literal8"))==0 ||
200 strncmp(Str
, ".const", strlen(".const"))==0 ||
201 strncmp(Str
, ".constructor", strlen(".constructor"))==0 ||
202 strncmp(Str
, ".cstring", strlen(".cstring"))==0 ||
203 strncmp(Str
, ".data", strlen(".data"))==0 ||
204 strncmp(Str
, ".destructor", strlen(".destructor"))==0 ||
205 strncmp(Str
, ".fvmlib_init0", strlen(".fvmlib_init0"))==0 ||
206 strncmp(Str
, ".fvmlib_init1", strlen(".fvmlib_init1"))==0 ||
207 strncmp(Str
, ".mod_init_func", strlen(".mod_init_func"))==0 ||
208 strncmp(Str
, ".mod_term_func", strlen(".mod_term_func"))==0 ||
209 strncmp(Str
, ".picsymbol_stub", strlen(".picsymbol_stub"))==0 ||
210 strncmp(Str
, ".symbol_stub", strlen(".symbol_stub"))==0 ||
211 strncmp(Str
, ".static_data", strlen(".static_data"))==0 ||
212 strncmp(Str
, ".section", strlen(".section"))==0 ||
213 strncmp(Str
, ".lazy_symbol_pointer", strlen(".lazy_symbol_pointer"))==0 ||
214 strncmp(Str
, ".non_lazy_symbol_pointer", strlen(".non_lazy_symbol_pointer"))==0 ||
215 strncmp(Str
, ".dyld", strlen(".dyld"))==0 ||
216 strncmp(Str
, ".const_data", strlen(".const_data"))==0 ||
217 strncmp(Str
, ".objc", strlen(".objc"))==0 || //// many directives
218 strncmp(Str
, ".static_const", strlen(".static_const"))==0)
220 else if (strncmp(Str
, ".text", strlen(".text"))==0)
221 inTextSection
= true;
222 // Some can't really be handled without implementing significant pieces
223 // of an assembler. Others require dynamic adjustment of block sizes in
224 // AdjustBBOffsetsAfter; it's a big compile-time speed hit to check every
225 // instruction in there, and none of these are currently used in the kernel.
226 else if (strncmp(Str
, ".macro", strlen(".macro"))==0 ||
227 strncmp(Str
, ".if", strlen(".if"))==0 ||
228 strncmp(Str
, ".align", strlen(".align"))==0 ||
229 strncmp(Str
, ".fill", strlen(".fill"))==0 ||
230 strncmp(Str
, ".space", strlen(".space"))==0 ||
231 strncmp(Str
, ".zerofill", strlen(".zerofill"))==0 ||
232 strncmp(Str
, ".p2align", strlen(".p2align"))==0 ||
233 strncmp(Str
, ".p2alignw", strlen(".p2alignw"))==0 ||
234 strncmp(Str
, ".p2alignl", strlen(".p2alignl"))==0 ||
235 strncmp(Str
, ".align32", strlen(".p2align32"))==0 ||
236 strncmp(Str
, ".include", strlen(".include"))==0)
237 cerr
<< "Directive " << Str
<< " in asm may lead to invalid offsets for" <<
238 " constant pools (the assembler will tell you if this happens).\n";
239 // Some generate code, but this is only interesting in the text section.
240 else if (inTextSection
) {
241 if (strncmp(Str
, ".long", strlen(".long"))==0)
242 Length
+= 4*countArguments(Str
+strlen(".long"));
243 else if (strncmp(Str
, ".short", strlen(".short"))==0)
244 Length
+= 2*countArguments(Str
+strlen(".short"));
245 else if (strncmp(Str
, ".byte", strlen(".byte"))==0)
246 Length
+= 1*countArguments(Str
+strlen(".byte"));
247 else if (strncmp(Str
, ".single", strlen(".single"))==0)
248 Length
+= 4*countArguments(Str
+strlen(".single"));
249 else if (strncmp(Str
, ".double", strlen(".double"))==0)
250 Length
+= 8*countArguments(Str
+strlen(".double"));
251 else if (strncmp(Str
, ".quad", strlen(".quad"))==0)
252 Length
+= 16*countArguments(Str
+strlen(".quad"));
253 else if (strncmp(Str
, ".ascii", strlen(".ascii"))==0)
254 Length
+= countString(Str
+strlen(".ascii"));
255 else if (strncmp(Str
, ".asciz", strlen(".asciz"))==0)
256 Length
+= countString(Str
+strlen(".asciz"))+1;
258 } else if (inTextSection
) {
261 if (Subtarget
->isThumb()) {
262 // BL and BLX <non-reg> are 4 bytes, all others 2.
263 if (strncmp(Str
, "blx", strlen("blx"))==0) {
264 const char* p
= Str
+3;
265 while (*p
&& isspace(*p
))
267 if (*p
== 'r' || *p
=='R')
268 Length
+= 2; // BLX reg
270 Length
+= 4; // BLX non-reg
271 } else if (strncmp(Str
, "bl", strlen("bl"))==0)
274 Length
+= 2; // Thumb anything else
280 if (*Str
== '\n' || *Str
== SeparatorChar
)