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"
21 const char *const llvm::arm_asm_table
[] = {
46 ARMDarwinTargetAsmInfo::ARMDarwinTargetAsmInfo(const ARMTargetMachine
&TM
):
47 ARMTargetAsmInfo
<DarwinTargetAsmInfo
>(TM
) {
48 Subtarget
= &TM
.getSubtarget
<ARMSubtarget
>();
51 PrivateGlobalPrefix
= "L";
52 LessPrivateGlobalPrefix
= "l";
53 StringConstantPrefix
= "\1LC";
54 BSSSection
= 0; // no BSS section
55 ZeroDirective
= "\t.space\t";
56 ZeroFillDirective
= "\t.zerofill\t"; // Uses .zerofill
57 SetDirective
= "\t.set\t";
58 WeakRefDirective
= "\t.weak_reference\t";
59 WeakDefDirective
= "\t.weak_definition ";
60 HiddenDirective
= "\t.private_extern\t";
61 ProtectedDirective
= NULL
;
62 JumpTableDataSection
= ".const";
63 CStringSection
= "\t.cstring";
64 HasDotTypeDotSizeDirective
= false;
65 HasSingleParameterDotFile
= false;
66 NeedsIndirectEncoding
= true;
67 if (TM
.getRelocationModel() == Reloc::Static
) {
68 StaticCtorsSection
= ".constructor";
69 StaticDtorsSection
= ".destructor";
71 StaticCtorsSection
= ".mod_init_func";
72 StaticDtorsSection
= ".mod_term_func";
75 // In non-PIC modes, emit a special label before jump tables so that the
76 // linker can perform more accurate dead code stripping.
77 if (TM
.getRelocationModel() != Reloc::PIC_
) {
78 // Emit a local label that is preserved until the linker runs.
79 JumpTableSpecialLabelPrefix
= "l";
83 DwarfAbbrevSection
= ".section __DWARF,__debug_abbrev,regular,debug";
84 DwarfInfoSection
= ".section __DWARF,__debug_info,regular,debug";
85 DwarfLineSection
= ".section __DWARF,__debug_line,regular,debug";
86 DwarfFrameSection
= ".section __DWARF,__debug_frame,regular,debug";
87 DwarfPubNamesSection
= ".section __DWARF,__debug_pubnames,regular,debug";
88 DwarfPubTypesSection
= ".section __DWARF,__debug_pubtypes,regular,debug";
89 DwarfStrSection
= ".section __DWARF,__debug_str,regular,debug";
90 DwarfLocSection
= ".section __DWARF,__debug_loc,regular,debug";
91 DwarfARangesSection
= ".section __DWARF,__debug_aranges,regular,debug";
92 DwarfRangesSection
= ".section __DWARF,__debug_ranges,regular,debug";
93 DwarfMacInfoSection
= ".section __DWARF,__debug_macinfo,regular,debug";
96 ARMELFTargetAsmInfo::ARMELFTargetAsmInfo(const ARMTargetMachine
&TM
):
97 ARMTargetAsmInfo
<ELFTargetAsmInfo
>(TM
) {
98 Subtarget
= &TM
.getSubtarget
<ARMSubtarget
>();
102 AbsoluteDebugSectionOffsets
= true;
103 CStringSection
= ".rodata.str";
104 PrivateGlobalPrefix
= ".L";
105 WeakRefDirective
= "\t.weak\t";
106 SetDirective
= "\t.set\t";
107 DwarfRequiresFrameSection
= false;
108 DwarfAbbrevSection
= "\t.section\t.debug_abbrev,\"\",%progbits";
109 DwarfInfoSection
= "\t.section\t.debug_info,\"\",%progbits";
110 DwarfLineSection
= "\t.section\t.debug_line,\"\",%progbits";
111 DwarfFrameSection
= "\t.section\t.debug_frame,\"\",%progbits";
112 DwarfPubNamesSection
="\t.section\t.debug_pubnames,\"\",%progbits";
113 DwarfPubTypesSection
="\t.section\t.debug_pubtypes,\"\",%progbits";
114 DwarfStrSection
= "\t.section\t.debug_str,\"\",%progbits";
115 DwarfLocSection
= "\t.section\t.debug_loc,\"\",%progbits";
116 DwarfARangesSection
= "\t.section\t.debug_aranges,\"\",%progbits";
117 DwarfRangesSection
= "\t.section\t.debug_ranges,\"\",%progbits";
118 DwarfMacInfoSection
= "\t.section\t.debug_macinfo,\"\",%progbits";
120 if (Subtarget
->isAAPCS_ABI()) {
121 StaticCtorsSection
= "\t.section .init_array,\"aw\",%init_array";
122 StaticDtorsSection
= "\t.section .fini_array,\"aw\",%fini_array";
124 StaticCtorsSection
= "\t.section .ctors,\"aw\",%progbits";
125 StaticDtorsSection
= "\t.section .dtors,\"aw\",%progbits";
129 /// Count the number of comma-separated arguments.
130 /// Do not try to detect errors.
131 template <class BaseTAI
>
132 unsigned ARMTargetAsmInfo
<BaseTAI
>::countArguments(const char* p
) const {
134 while (*p
&& isspace(*p
) && *p
!= '\n')
137 while (*p
&& *p
!='\n' &&
138 strncmp(p
, BaseTAI::CommentString
,
139 strlen(BaseTAI::CommentString
))!=0) {
147 /// Count the length of a string enclosed in quote characters.
148 /// Do not try to detect errors.
149 template <class BaseTAI
>
150 unsigned ARMTargetAsmInfo
<BaseTAI
>::countString(const char* p
) const {
152 while (*p
&& isspace(*p
) && *p
!='\n')
154 if (!*p
|| *p
!= '\"')
156 while (*++p
&& *p
!= '\"')
161 /// ARM-specific version of TargetAsmInfo::getInlineAsmLength.
162 template <class BaseTAI
>
163 unsigned ARMTargetAsmInfo
<BaseTAI
>::getInlineAsmLength(const char *s
) const {
164 // Make a lowercase-folded version of s for counting purposes.
165 char *q
, *s_copy
= (char *)malloc(strlen(s
) + 1);
167 for (q
=s_copy
; *q
; q
++)
169 const char *Str
= s_copy
;
171 // Count the number of bytes in the asm.
172 bool atInsnStart
= true;
173 bool inTextSection
= true;
175 for (; *Str
; ++Str
) {
178 while (*Str
&& isspace(*Str
) && *Str
!= '\n')
181 for (const char* p
= Str
; *p
&& !isspace(*p
); p
++)
184 while (*Str
&& isspace(*Str
) && *Str
!= '\n')
189 if (*Str
== 0) break;
191 // Ignore everything from comment char(s) to EOL
192 if (strncmp(Str
, BaseTAI::CommentString
,
193 strlen(BaseTAI::CommentString
)) == 0)
195 // FIXME do something like the following for non-Darwin
196 else if (*Str
== '.' && Subtarget
->isTargetDarwin()) {
200 // Some change the section, but don't generate code.
201 if (strncmp(Str
, ".literal4", strlen(".literal4"))==0 ||
202 strncmp(Str
, ".literal8", strlen(".literal8"))==0 ||
203 strncmp(Str
, ".const", strlen(".const"))==0 ||
204 strncmp(Str
, ".constructor", strlen(".constructor"))==0 ||
205 strncmp(Str
, ".cstring", strlen(".cstring"))==0 ||
206 strncmp(Str
, ".data", strlen(".data"))==0 ||
207 strncmp(Str
, ".destructor", strlen(".destructor"))==0 ||
208 strncmp(Str
, ".fvmlib_init0", strlen(".fvmlib_init0"))==0 ||
209 strncmp(Str
, ".fvmlib_init1", strlen(".fvmlib_init1"))==0 ||
210 strncmp(Str
, ".mod_init_func", strlen(".mod_init_func"))==0 ||
211 strncmp(Str
, ".mod_term_func", strlen(".mod_term_func"))==0 ||
212 strncmp(Str
, ".picsymbol_stub", strlen(".picsymbol_stub"))==0 ||
213 strncmp(Str
, ".symbol_stub", strlen(".symbol_stub"))==0 ||
214 strncmp(Str
, ".static_data", strlen(".static_data"))==0 ||
215 strncmp(Str
, ".section", strlen(".section"))==0 ||
216 strncmp(Str
, ".lazy_symbol_pointer", strlen(".lazy_symbol_pointer"))==0 ||
217 strncmp(Str
, ".non_lazy_symbol_pointer", strlen(".non_lazy_symbol_pointer"))==0 ||
218 strncmp(Str
, ".dyld", strlen(".dyld"))==0 ||
219 strncmp(Str
, ".const_data", strlen(".const_data"))==0 ||
220 strncmp(Str
, ".objc", strlen(".objc"))==0 || //// many directives
221 strncmp(Str
, ".static_const", strlen(".static_const"))==0)
223 else if (strncmp(Str
, ".text", strlen(".text"))==0)
224 inTextSection
= true;
225 // Some can't really be handled without implementing significant pieces
226 // of an assembler. Others require dynamic adjustment of block sizes in
227 // AdjustBBOffsetsAfter; it's a big compile-time speed hit to check every
228 // instruction in there, and none of these are currently used in the kernel.
229 else if (strncmp(Str
, ".macro", strlen(".macro"))==0 ||
230 strncmp(Str
, ".if", strlen(".if"))==0 ||
231 strncmp(Str
, ".align", strlen(".align"))==0 ||
232 strncmp(Str
, ".fill", strlen(".fill"))==0 ||
233 strncmp(Str
, ".space", strlen(".space"))==0 ||
234 strncmp(Str
, ".zerofill", strlen(".zerofill"))==0 ||
235 strncmp(Str
, ".p2align", strlen(".p2align"))==0 ||
236 strncmp(Str
, ".p2alignw", strlen(".p2alignw"))==0 ||
237 strncmp(Str
, ".p2alignl", strlen(".p2alignl"))==0 ||
238 strncmp(Str
, ".align32", strlen(".p2align32"))==0 ||
239 strncmp(Str
, ".include", strlen(".include"))==0)
240 cerr
<< "Directive " << Str
<< " in asm may lead to invalid offsets for" <<
241 " constant pools (the assembler will tell you if this happens).\n";
242 // Some generate code, but this is only interesting in the text section.
243 else if (inTextSection
) {
244 if (strncmp(Str
, ".long", strlen(".long"))==0)
245 Length
+= 4*countArguments(Str
+strlen(".long"));
246 else if (strncmp(Str
, ".short", strlen(".short"))==0)
247 Length
+= 2*countArguments(Str
+strlen(".short"));
248 else if (strncmp(Str
, ".byte", strlen(".byte"))==0)
249 Length
+= 1*countArguments(Str
+strlen(".byte"));
250 else if (strncmp(Str
, ".single", strlen(".single"))==0)
251 Length
+= 4*countArguments(Str
+strlen(".single"));
252 else if (strncmp(Str
, ".double", strlen(".double"))==0)
253 Length
+= 8*countArguments(Str
+strlen(".double"));
254 else if (strncmp(Str
, ".quad", strlen(".quad"))==0)
255 Length
+= 16*countArguments(Str
+strlen(".quad"));
256 else if (strncmp(Str
, ".ascii", strlen(".ascii"))==0)
257 Length
+= countString(Str
+strlen(".ascii"));
258 else if (strncmp(Str
, ".asciz", strlen(".asciz"))==0)
259 Length
+= countString(Str
+strlen(".asciz"))+1;
261 } else if (inTextSection
) {
264 if (Subtarget
->isThumb()) {
265 // BL and BLX <non-reg> are 4 bytes, all others 2.
266 if (strncmp(Str
, "blx", strlen("blx"))==0) {
267 const char* p
= Str
+3;
268 while (*p
&& isspace(*p
))
270 if (*p
== 'r' || *p
=='R')
271 Length
+= 2; // BLX reg
273 Length
+= 4; // BLX non-reg
274 } else if (strncmp(Str
, "bl", strlen("bl"))==0)
277 Length
+= 2; // Thumb anything else
283 if (*Str
== '\n' || *Str
== BaseTAI::SeparatorChar
)
290 // Instantiate default implementation.
291 TEMPLATE_INSTANTIATION(class ARMTargetAsmInfo
<TargetAsmInfo
>);