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