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 const char *const llvm::arm_asm_table[] = {
46 ARMDarwinTargetAsmInfo::ARMDarwinTargetAsmInfo(const ARMTargetMachine &TM):
47 ARMTargetAsmInfo<DarwinTargetAsmInfo>(TM) {
48 Subtarget = &TM.getSubtarget<ARMSubtarget>();
50 ZeroDirective = "\t.space\t";
51 ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill
52 SetDirective = "\t.set\t";
53 ProtectedDirective = NULL;
54 HasDotTypeDotSizeDirective = false;
57 ARMELFTargetAsmInfo::ARMELFTargetAsmInfo(const ARMTargetMachine &TM):
58 ARMTargetAsmInfo<ELFTargetAsmInfo>(TM) {
59 Subtarget = &TM.getSubtarget<ARMSubtarget>();
63 AbsoluteDebugSectionOffsets = true;
64 CStringSection = ".rodata.str";
65 PrivateGlobalPrefix = ".L";
66 WeakRefDirective = "\t.weak\t";
67 SetDirective = "\t.set\t";
68 DwarfRequiresFrameSection = false;
69 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",%progbits";
70 DwarfInfoSection = "\t.section\t.debug_info,\"\",%progbits";
71 DwarfLineSection = "\t.section\t.debug_line,\"\",%progbits";
72 DwarfFrameSection = "\t.section\t.debug_frame,\"\",%progbits";
73 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",%progbits";
74 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",%progbits";
75 DwarfStrSection = "\t.section\t.debug_str,\"\",%progbits";
76 DwarfLocSection = "\t.section\t.debug_loc,\"\",%progbits";
77 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",%progbits";
78 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",%progbits";
79 DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"\",%progbits";
81 if (Subtarget->isAAPCS_ABI()) {
82 StaticCtorsSection = "\t.section .init_array,\"aw\",%init_array";
83 StaticDtorsSection = "\t.section .fini_array,\"aw\",%fini_array";
85 StaticCtorsSection = "\t.section .ctors,\"aw\",%progbits";
86 StaticDtorsSection = "\t.section .dtors,\"aw\",%progbits";
90 /// Count the number of comma-separated arguments.
91 /// Do not try to detect errors.
92 template <class BaseTAI>
93 unsigned ARMTargetAsmInfo<BaseTAI>::countArguments(const char* p) const {
95 while (*p && isspace(*p) && *p != '\n')
98 while (*p && *p!='\n' &&
99 strncmp(p, BaseTAI::CommentString,
100 strlen(BaseTAI::CommentString))!=0) {
108 /// Count the length of a string enclosed in quote characters.
109 /// Do not try to detect errors.
110 template <class BaseTAI>
111 unsigned ARMTargetAsmInfo<BaseTAI>::countString(const char* p) const {
113 while (*p && isspace(*p) && *p!='\n')
115 if (!*p || *p != '\"')
117 while (*++p && *p != '\"')
122 /// ARM-specific version of TargetAsmInfo::getInlineAsmLength.
123 template <class BaseTAI>
124 unsigned ARMTargetAsmInfo<BaseTAI>::getInlineAsmLength(const char *s) const {
125 // Make a lowercase-folded version of s for counting purposes.
126 char *q, *s_copy = (char *)malloc(strlen(s) + 1);
128 for (q=s_copy; *q; q++)
130 const char *Str = s_copy;
132 // Count the number of bytes in the asm.
133 bool atInsnStart = true;
134 bool inTextSection = true;
136 for (; *Str; ++Str) {
139 while (*Str && isspace(*Str) && *Str != '\n')
142 for (const char* p = Str; *p && !isspace(*p); p++)
145 while (*Str && isspace(*Str) && *Str != '\n')
150 if (*Str == 0) break;
152 // Ignore everything from comment char(s) to EOL
153 if (strncmp(Str, BaseTAI::CommentString,
154 strlen(BaseTAI::CommentString)) == 0)
156 // FIXME do something like the following for non-Darwin
157 else if (*Str == '.' && Subtarget->isTargetDarwin()) {
161 // Some change the section, but don't generate code.
162 if (strncmp(Str, ".literal4", strlen(".literal4"))==0 ||
163 strncmp(Str, ".literal8", strlen(".literal8"))==0 ||
164 strncmp(Str, ".const", strlen(".const"))==0 ||
165 strncmp(Str, ".constructor", strlen(".constructor"))==0 ||
166 strncmp(Str, ".cstring", strlen(".cstring"))==0 ||
167 strncmp(Str, ".data", strlen(".data"))==0 ||
168 strncmp(Str, ".destructor", strlen(".destructor"))==0 ||
169 strncmp(Str, ".fvmlib_init0", strlen(".fvmlib_init0"))==0 ||
170 strncmp(Str, ".fvmlib_init1", strlen(".fvmlib_init1"))==0 ||
171 strncmp(Str, ".mod_init_func", strlen(".mod_init_func"))==0 ||
172 strncmp(Str, ".mod_term_func", strlen(".mod_term_func"))==0 ||
173 strncmp(Str, ".picsymbol_stub", strlen(".picsymbol_stub"))==0 ||
174 strncmp(Str, ".symbol_stub", strlen(".symbol_stub"))==0 ||
175 strncmp(Str, ".static_data", strlen(".static_data"))==0 ||
176 strncmp(Str, ".section", strlen(".section"))==0 ||
177 strncmp(Str, ".lazy_symbol_pointer", strlen(".lazy_symbol_pointer"))==0 ||
178 strncmp(Str, ".non_lazy_symbol_pointer", strlen(".non_lazy_symbol_pointer"))==0 ||
179 strncmp(Str, ".dyld", strlen(".dyld"))==0 ||
180 strncmp(Str, ".const_data", strlen(".const_data"))==0 ||
181 strncmp(Str, ".objc", strlen(".objc"))==0 || //// many directives
182 strncmp(Str, ".static_const", strlen(".static_const"))==0)
184 else if (strncmp(Str, ".text", strlen(".text"))==0)
185 inTextSection = true;
186 // Some can't really be handled without implementing significant pieces
187 // of an assembler. Others require dynamic adjustment of block sizes in
188 // AdjustBBOffsetsAfter; it's a big compile-time speed hit to check every
189 // instruction in there, and none of these are currently used in the kernel.
190 else if (strncmp(Str, ".macro", strlen(".macro"))==0 ||
191 strncmp(Str, ".if", strlen(".if"))==0 ||
192 strncmp(Str, ".align", strlen(".align"))==0 ||
193 strncmp(Str, ".fill", strlen(".fill"))==0 ||
194 strncmp(Str, ".space", strlen(".space"))==0 ||
195 strncmp(Str, ".zerofill", strlen(".zerofill"))==0 ||
196 strncmp(Str, ".p2align", strlen(".p2align"))==0 ||
197 strncmp(Str, ".p2alignw", strlen(".p2alignw"))==0 ||
198 strncmp(Str, ".p2alignl", strlen(".p2alignl"))==0 ||
199 strncmp(Str, ".align32", strlen(".p2align32"))==0 ||
200 strncmp(Str, ".include", strlen(".include"))==0)
201 cerr << "Directive " << Str << " in asm may lead to invalid offsets for" <<
202 " constant pools (the assembler will tell you if this happens).\n";
203 // Some generate code, but this is only interesting in the text section.
204 else if (inTextSection) {
205 if (strncmp(Str, ".long", strlen(".long"))==0)
206 Length += 4*countArguments(Str+strlen(".long"));
207 else if (strncmp(Str, ".short", strlen(".short"))==0)
208 Length += 2*countArguments(Str+strlen(".short"));
209 else if (strncmp(Str, ".byte", strlen(".byte"))==0)
210 Length += 1*countArguments(Str+strlen(".byte"));
211 else if (strncmp(Str, ".single", strlen(".single"))==0)
212 Length += 4*countArguments(Str+strlen(".single"));
213 else if (strncmp(Str, ".double", strlen(".double"))==0)
214 Length += 8*countArguments(Str+strlen(".double"));
215 else if (strncmp(Str, ".quad", strlen(".quad"))==0)
216 Length += 16*countArguments(Str+strlen(".quad"));
217 else if (strncmp(Str, ".ascii", strlen(".ascii"))==0)
218 Length += countString(Str+strlen(".ascii"));
219 else if (strncmp(Str, ".asciz", strlen(".asciz"))==0)
220 Length += countString(Str+strlen(".asciz"))+1;
222 } else if (inTextSection) {
225 if (Subtarget->isThumb()) {
226 // BL and BLX <non-reg> are 4 bytes, all others 2.
227 if (strncmp(Str, "blx", strlen("blx"))==0) {
228 const char* p = Str+3;
229 while (*p && isspace(*p))
231 if (*p == 'r' || *p=='R')
232 Length += 2; // BLX reg
234 Length += 4; // BLX non-reg
235 } else if (strncmp(Str, "bl", strlen("bl"))==0)
238 Length += 2; // Thumb anything else
244 if (*Str == '\n' || *Str == BaseTAI::SeparatorChar)
251 // Instantiate default implementation.
252 TEMPLATE_INSTANTIATION(class ARMTargetAsmInfo<TargetAsmInfo>);