2 //===-- ARMTargetAsmInfo.cpp - ARM asm properties ---------------*- C++ -*-===//
4 // The LLVM Compiler Infrastructure
6 // This file was developed by James M. Laskey and is distributed under the
7 // University of Illinois Open Source License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 // This file contains the declarations of the ARMTargetAsmInfo properties.
13 //===----------------------------------------------------------------------===//
15 #include "ARMTargetAsmInfo.h"
16 #include "ARMTargetMachine.h"
21 ARMTargetAsmInfo::ARMTargetAsmInfo(const ARMTargetMachine &TM) {
22 Subtarget = &TM.getSubtarget<ARMSubtarget>();
23 if (Subtarget->isTargetDarwin()) {
25 PrivateGlobalPrefix = "L";
26 BSSSection = 0; // no BSS section.
27 ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill
28 SetDirective = "\t.set";
29 WeakRefDirective = "\t.weak_reference\t";
30 HiddenDirective = "\t.private_extern\t";
31 ProtectedDirective = NULL;
32 JumpTableDataSection = ".const";
33 CStringSection = "\t.cstring";
34 FourByteConstantSection = "\t.literal4\n";
35 EightByteConstantSection = "\t.literal8\n";
36 ReadOnlySection = "\t.const\n";
37 HasDotTypeDotSizeDirective = false;
38 if (TM.getRelocationModel() == Reloc::Static) {
39 StaticCtorsSection = ".constructor";
40 StaticDtorsSection = ".destructor";
42 StaticCtorsSection = ".mod_init_func";
43 StaticDtorsSection = ".mod_term_func";
46 // In non-PIC modes, emit a special label before jump tables so that the
47 // linker can perform more accurate dead code stripping.
48 if (TM.getRelocationModel() != Reloc::PIC_) {
49 // Emit a local label that is preserved until the linker runs.
50 JumpTableSpecialLabelPrefix = "l";
54 DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
55 DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
56 DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
57 DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
58 DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
59 DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
60 DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
61 DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
62 DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
63 DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
64 DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
68 AbsoluteDebugSectionOffsets = true;
69 ReadOnlySection = "\t.section\t.rodata\n";
70 PrivateGlobalPrefix = ".L";
71 WeakRefDirective = "\t.weak\t";
72 DwarfRequiresFrameSection = false;
73 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",%progbits";
74 DwarfInfoSection = "\t.section\t.debug_info,\"\",%progbits";
75 DwarfLineSection = "\t.section\t.debug_line,\"\",%progbits";
76 DwarfFrameSection = "\t.section\t.debug_frame,\"\",%progbits";
77 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",%progbits";
78 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",%progbits";
79 DwarfStrSection = "\t.section\t.debug_str,\"\",%progbits";
80 DwarfLocSection = "\t.section\t.debug_loc,\"\",%progbits";
81 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",%progbits";
82 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",%progbits";
83 DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",%progbits";
85 if (Subtarget->isAAPCS_ABI()) {
86 StaticCtorsSection = "\t.section .init_array,\"aw\",%init_array";
87 StaticDtorsSection = "\t.section .fini_array,\"aw\",%fini_array";
89 StaticCtorsSection = "\t.section .ctors,\"aw\",%progbits";
90 StaticDtorsSection = "\t.section .dtors,\"aw\",%progbits";
92 TLSDataSection = "\t.section .tdata,\"awT\",%progbits";
93 TLSBSSSection = "\t.section .tbss,\"awT\",%nobits";
96 ZeroDirective = "\t.space\t";
97 AlignmentIsInBytes = false;
98 Data64bitsDirective = 0;
100 DataSection = "\t.data";
101 ConstantPoolSection = "\t.text\n";
102 COMMDirectiveTakesAlignment = false;
103 InlineAsmStart = "@ InlineAsm Start";
104 InlineAsmEnd = "@ InlineAsm End";
105 LCOMMDirective = "\t.lcomm\t";
108 /// Count the number of comma-separated arguments.
109 /// Do not try to detect errors.
110 unsigned ARMTargetAsmInfo::countArguments(const char* p) const {
112 while (*p && isspace(*p) && *p != '\n')
115 while (*p && *p!='\n' &&
116 strncmp(p, CommentString, strlen(CommentString))!=0) {
124 /// Count the length of a string enclosed in quote characters.
125 /// Do not try to detect errors.
126 unsigned ARMTargetAsmInfo::countString(const char* p) const {
128 while (*p && isspace(*p) && *p!='\n')
130 if (!*p || *p != '\"')
132 while (*++p && *p != '\"')
137 /// ARM-specific version of TargetAsmInfo::getInlineAsmLength.
138 unsigned ARMTargetAsmInfo::getInlineAsmLength(const char *Str) const {
139 // Count the number of bytes in the asm.
140 bool atInsnStart = true;
141 bool inTextSection = true;
143 for (; *Str; ++Str) {
146 while (*Str && isspace(*Str) && *Str != '\n')
149 for (const char* p = Str; *p && !isspace(*p); p++)
152 while (*Str && isspace(*Str) && *Str != '\n')
156 // Ignore everything from comment char(s) to EOL
157 if (strncmp(Str, CommentString, strlen(CommentString))==-0)
159 // FIXME do something like the following for non-Darwin
160 else if (*Str == '.' && Subtarget->isTargetDarwin()) {
163 // Some change the section, but don't generate code.
164 if (strncasecmp(Str, ".literal4", strlen(".literal4"))==0 ||
165 strncasecmp(Str, ".literal8", strlen(".literal8"))==0 ||
166 strncasecmp(Str, ".const", strlen(".const"))==0 ||
167 strncasecmp(Str, ".constructor", strlen(".constructor"))==0 ||
168 strncasecmp(Str, ".cstring", strlen(".cstring"))==0 ||
169 strncasecmp(Str, ".data", strlen(".data"))==0 ||
170 strncasecmp(Str, ".destructor", strlen(".destructor"))==0 ||
171 strncasecmp(Str, ".fvmlib_init0", strlen(".fvmlib_init0"))==0 ||
172 strncasecmp(Str, ".fvmlib_init1", strlen(".fvmlib_init1"))==0 ||
173 strncasecmp(Str, ".mod_init_func", strlen(".mod_init_func"))==0 ||
174 strncasecmp(Str, ".mod_term_func", strlen(".mod_term_func"))==0 ||
175 strncasecmp(Str, ".picsymbol_stub", strlen(".picsymbol_stub"))==0 ||
176 strncasecmp(Str, ".symbol_stub", strlen(".symbol_stub"))==0 ||
177 strncasecmp(Str, ".static_data", strlen(".static_data"))==0 ||
178 strncasecmp(Str, ".section", strlen(".section"))==0 ||
179 strncasecmp(Str, ".lazy_symbol_pointer", strlen(".lazy_symbol_pointer"))==0 ||
180 strncasecmp(Str, ".non_lazy_symbol_pointer", strlen(".non_lazy_symbol_pointer"))==0 ||
181 strncasecmp(Str, ".dyld", strlen(".dyld"))==0 ||
182 strncasecmp(Str, ".const_data", strlen(".const_data"))==0 ||
183 strncasecmp(Str, ".objc", strlen(".objc"))==0 || //// many directives
184 strncasecmp(Str, ".static_const", strlen(".static_const"))==0)
186 else if (strncasecmp(Str, ".text", strlen(".text"))==0)
187 inTextSection = true;
188 // Some can't really be handled without implementing significant pieces
189 // of an assembler. Others require dynamic adjustment of block sizes in
190 // AdjustBBOffsetsAfter; it's a big compile-time speed hit to check every
191 // instruction in there, and none of these are currently used in the kernel.
192 else if (strncasecmp(Str, ".macro", strlen(".macro"))==0 ||
193 strncasecmp(Str, ".if", strlen(".if"))==0 ||
194 strncasecmp(Str, ".align", strlen(".align"))==0 ||
195 strncasecmp(Str, ".fill", strlen(".fill"))==0 ||
196 strncasecmp(Str, ".space", strlen(".space"))==0 ||
197 strncasecmp(Str, ".zerofill", strlen(".zerofill"))==0 ||
198 strncasecmp(Str, ".p2align", strlen(".p2align"))==0 ||
199 strncasecmp(Str, ".p2alignw", strlen(".p2alignw"))==0 ||
200 strncasecmp(Str, ".p2alignl", strlen(".p2alignl"))==0 ||
201 strncasecmp(Str, ".align32", strlen(".p2align32"))==0 ||
202 strncasecmp(Str, ".include", strlen(".include"))==0)
203 cerr << "Directive " << Str << " in asm may lead to invalid offsets for" <<
204 " constant pools (the assembler will tell you if this happens).\n";
205 // Some generate code, but this is only interesting in the text section.
206 else if (inTextSection) {
207 if (strncasecmp(Str, ".long", strlen(".long"))==0)
208 Length += 4*countArguments(Str+strlen(".long"));
209 else if (strncasecmp(Str, ".short", strlen(".short"))==0)
210 Length += 2*countArguments(Str+strlen(".short"));
211 else if (strncasecmp(Str, ".byte", strlen(".byte"))==0)
212 Length += 1*countArguments(Str+strlen(".byte"));
213 else if (strncasecmp(Str, ".single", strlen(".single"))==0)
214 Length += 4*countArguments(Str+strlen(".single"));
215 else if (strncasecmp(Str, ".double", strlen(".double"))==0)
216 Length += 8*countArguments(Str+strlen(".double"));
217 else if (strncasecmp(Str, ".quad", strlen(".quad"))==0)
218 Length += 16*countArguments(Str+strlen(".quad"));
219 else if (strncasecmp(Str, ".ascii", strlen(".ascii"))==0)
220 Length += countString(Str+strlen(".ascii"));
221 else if (strncasecmp(Str, ".asciz", strlen(".asciz"))==0)
222 Length += countString(Str+strlen(".asciz"))+1;
224 } else if (inTextSection) {
227 if (Subtarget->isThumb()) {
228 // BL and BLX <non-reg> are 4 bytes, all others 2.
229 if (strncasecmp(Str, "blx", strlen("blx"))==0) {
230 const char* p = Str+3;
231 while (*p && isspace(*p))
233 if (*p == 'r' || *p=='R')
234 Length += 2; // BLX reg
236 Length += 4; // BLX non-reg
237 } else if (strncasecmp(Str, "bl", strlen("bl"))==0)
240 Length += 2; // Thumb anything else
246 if (*Str == '\n' || *Str == SeparatorChar)