2006-09-07 22:05:02 +00:00
|
|
|
//===-- ARMTargetAsmInfo.cpp - ARM asm properties ---------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-09-07 22:05:02 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the declarations of the ARMTargetAsmInfo properties.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARMTargetAsmInfo.h"
|
2007-01-19 07:51:42 +00:00
|
|
|
#include "ARMTargetMachine.h"
|
2007-04-23 20:04:35 +00:00
|
|
|
#include <cstring>
|
|
|
|
#include <cctype>
|
2006-09-07 22:05:02 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2008-09-25 21:00:33 +00:00
|
|
|
const char *const llvm::arm_asm_table[] = {
|
2009-06-18 23:41:35 +00:00
|
|
|
"{r0}", "r0",
|
|
|
|
"{r1}", "r1",
|
|
|
|
"{r2}", "r2",
|
|
|
|
"{r3}", "r3",
|
|
|
|
"{r4}", "r4",
|
|
|
|
"{r5}", "r5",
|
|
|
|
"{r6}", "r6",
|
|
|
|
"{r7}", "r7",
|
|
|
|
"{r8}", "r8",
|
|
|
|
"{r9}", "r9",
|
|
|
|
"{r10}", "r10",
|
|
|
|
"{r11}", "r11",
|
|
|
|
"{r12}", "r12",
|
|
|
|
"{r13}", "r13",
|
|
|
|
"{r14}", "r14",
|
|
|
|
"{lr}", "lr",
|
|
|
|
"{sp}", "sp",
|
|
|
|
"{ip}", "ip",
|
|
|
|
"{fp}", "fp",
|
|
|
|
"{sl}", "sl",
|
|
|
|
"{memory}", "memory",
|
|
|
|
"{cc}", "cc",
|
|
|
|
0,0
|
|
|
|
};
|
2007-06-08 21:06:23 +00:00
|
|
|
|
2009-06-26 21:28:53 +00:00
|
|
|
ARMDarwinTargetAsmInfo::ARMDarwinTargetAsmInfo(const ARMBaseTargetMachine &TM):
|
2008-09-25 21:00:33 +00:00
|
|
|
ARMTargetAsmInfo<DarwinTargetAsmInfo>(TM) {
|
2008-11-03 18:22:42 +00:00
|
|
|
Subtarget = &TM.getSubtarget<ARMSubtarget>();
|
2008-08-07 09:54:23 +00:00
|
|
|
|
|
|
|
ZeroDirective = "\t.space\t";
|
|
|
|
ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill
|
|
|
|
SetDirective = "\t.set\t";
|
|
|
|
ProtectedDirective = NULL;
|
|
|
|
HasDotTypeDotSizeDirective = false;
|
2009-06-19 21:54:26 +00:00
|
|
|
SupportsDebugInformation = true;
|
2008-08-07 09:54:23 +00:00
|
|
|
}
|
|
|
|
|
2009-06-26 21:28:53 +00:00
|
|
|
ARMELFTargetAsmInfo::ARMELFTargetAsmInfo(const ARMBaseTargetMachine &TM):
|
2008-09-25 21:00:33 +00:00
|
|
|
ARMTargetAsmInfo<ELFTargetAsmInfo>(TM) {
|
2008-11-03 18:22:42 +00:00
|
|
|
Subtarget = &TM.getSubtarget<ARMSubtarget>();
|
2008-08-07 09:54:23 +00:00
|
|
|
|
|
|
|
NeedsSet = false;
|
|
|
|
HasLEB128 = true;
|
|
|
|
AbsoluteDebugSectionOffsets = true;
|
|
|
|
CStringSection = ".rodata.str";
|
|
|
|
PrivateGlobalPrefix = ".L";
|
|
|
|
WeakRefDirective = "\t.weak\t";
|
|
|
|
SetDirective = "\t.set\t";
|
|
|
|
DwarfRequiresFrameSection = false;
|
|
|
|
DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",%progbits";
|
|
|
|
DwarfInfoSection = "\t.section\t.debug_info,\"\",%progbits";
|
|
|
|
DwarfLineSection = "\t.section\t.debug_line,\"\",%progbits";
|
|
|
|
DwarfFrameSection = "\t.section\t.debug_frame,\"\",%progbits";
|
|
|
|
DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",%progbits";
|
|
|
|
DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",%progbits";
|
|
|
|
DwarfStrSection = "\t.section\t.debug_str,\"\",%progbits";
|
|
|
|
DwarfLocSection = "\t.section\t.debug_loc,\"\",%progbits";
|
|
|
|
DwarfARangesSection = "\t.section\t.debug_aranges,\"\",%progbits";
|
|
|
|
DwarfRangesSection = "\t.section\t.debug_ranges,\"\",%progbits";
|
2009-06-18 23:31:37 +00:00
|
|
|
DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"\",%progbits";
|
2008-08-07 09:54:23 +00:00
|
|
|
|
|
|
|
if (Subtarget->isAAPCS_ABI()) {
|
|
|
|
StaticCtorsSection = "\t.section .init_array,\"aw\",%init_array";
|
|
|
|
StaticDtorsSection = "\t.section .fini_array,\"aw\",%fini_array";
|
|
|
|
} else {
|
|
|
|
StaticCtorsSection = "\t.section .ctors,\"aw\",%progbits";
|
|
|
|
StaticDtorsSection = "\t.section .dtors,\"aw\",%progbits";
|
|
|
|
}
|
2009-06-19 21:54:26 +00:00
|
|
|
SupportsDebugInformation = true;
|
2008-08-07 09:54:23 +00:00
|
|
|
}
|
|
|
|
|
2007-05-02 01:02:40 +00:00
|
|
|
/// Count the number of comma-separated arguments.
|
|
|
|
/// Do not try to detect errors.
|
2008-09-25 21:00:33 +00:00
|
|
|
template <class BaseTAI>
|
|
|
|
unsigned ARMTargetAsmInfo<BaseTAI>::countArguments(const char* p) const {
|
2007-05-02 01:02:40 +00:00
|
|
|
unsigned count = 0;
|
|
|
|
while (*p && isspace(*p) && *p != '\n')
|
|
|
|
p++;
|
|
|
|
count++;
|
2008-09-25 21:00:33 +00:00
|
|
|
while (*p && *p!='\n' &&
|
|
|
|
strncmp(p, BaseTAI::CommentString,
|
|
|
|
strlen(BaseTAI::CommentString))!=0) {
|
2007-05-02 01:02:40 +00:00
|
|
|
if (*p==',')
|
|
|
|
count++;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Count the length of a string enclosed in quote characters.
|
|
|
|
/// Do not try to detect errors.
|
2008-09-25 21:00:33 +00:00
|
|
|
template <class BaseTAI>
|
|
|
|
unsigned ARMTargetAsmInfo<BaseTAI>::countString(const char* p) const {
|
2007-05-02 01:02:40 +00:00
|
|
|
unsigned count = 0;
|
|
|
|
while (*p && isspace(*p) && *p!='\n')
|
|
|
|
p++;
|
|
|
|
if (!*p || *p != '\"')
|
|
|
|
return count;
|
|
|
|
while (*++p && *p != '\"')
|
|
|
|
count++;
|
|
|
|
return count;
|
2006-09-07 22:05:02 +00:00
|
|
|
}
|
2007-04-29 19:17:45 +00:00
|
|
|
|
|
|
|
/// ARM-specific version of TargetAsmInfo::getInlineAsmLength.
|
2008-09-25 21:00:33 +00:00
|
|
|
template <class BaseTAI>
|
|
|
|
unsigned ARMTargetAsmInfo<BaseTAI>::getInlineAsmLength(const char *s) const {
|
2007-10-25 21:54:43 +00:00
|
|
|
// Make a lowercase-folded version of s for counting purposes.
|
|
|
|
char *q, *s_copy = (char *)malloc(strlen(s) + 1);
|
|
|
|
strcpy(s_copy, s);
|
|
|
|
for (q=s_copy; *q; q++)
|
|
|
|
*q = tolower(*q);
|
|
|
|
const char *Str = s_copy;
|
|
|
|
|
2007-04-29 19:17:45 +00:00
|
|
|
// Count the number of bytes in the asm.
|
|
|
|
bool atInsnStart = true;
|
2007-05-02 01:02:40 +00:00
|
|
|
bool inTextSection = true;
|
2007-04-29 19:17:45 +00:00
|
|
|
unsigned Length = 0;
|
|
|
|
for (; *Str; ++Str) {
|
|
|
|
if (atInsnStart) {
|
|
|
|
// Skip whitespace
|
|
|
|
while (*Str && isspace(*Str) && *Str != '\n')
|
|
|
|
Str++;
|
|
|
|
// Skip label
|
|
|
|
for (const char* p = Str; *p && !isspace(*p); p++)
|
|
|
|
if (*p == ':') {
|
|
|
|
Str = p+1;
|
2007-05-02 01:02:40 +00:00
|
|
|
while (*Str && isspace(*Str) && *Str != '\n')
|
|
|
|
Str++;
|
2007-04-29 19:17:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-03-11 16:14:25 +00:00
|
|
|
|
|
|
|
if (*Str == 0) break;
|
|
|
|
|
2007-04-29 19:17:45 +00:00
|
|
|
// Ignore everything from comment char(s) to EOL
|
2009-03-11 16:14:25 +00:00
|
|
|
if (strncmp(Str, BaseTAI::CommentString,
|
|
|
|
strlen(BaseTAI::CommentString)) == 0)
|
2007-04-29 19:17:45 +00:00
|
|
|
atInsnStart = false;
|
2007-05-02 01:02:40 +00:00
|
|
|
// FIXME do something like the following for non-Darwin
|
|
|
|
else if (*Str == '.' && Subtarget->isTargetDarwin()) {
|
|
|
|
// Directive.
|
|
|
|
atInsnStart = false;
|
2007-10-25 21:54:43 +00:00
|
|
|
|
2007-05-02 01:02:40 +00:00
|
|
|
// Some change the section, but don't generate code.
|
2007-10-25 21:54:43 +00:00
|
|
|
if (strncmp(Str, ".literal4", strlen(".literal4"))==0 ||
|
|
|
|
strncmp(Str, ".literal8", strlen(".literal8"))==0 ||
|
|
|
|
strncmp(Str, ".const", strlen(".const"))==0 ||
|
|
|
|
strncmp(Str, ".constructor", strlen(".constructor"))==0 ||
|
|
|
|
strncmp(Str, ".cstring", strlen(".cstring"))==0 ||
|
|
|
|
strncmp(Str, ".data", strlen(".data"))==0 ||
|
|
|
|
strncmp(Str, ".destructor", strlen(".destructor"))==0 ||
|
|
|
|
strncmp(Str, ".fvmlib_init0", strlen(".fvmlib_init0"))==0 ||
|
|
|
|
strncmp(Str, ".fvmlib_init1", strlen(".fvmlib_init1"))==0 ||
|
|
|
|
strncmp(Str, ".mod_init_func", strlen(".mod_init_func"))==0 ||
|
|
|
|
strncmp(Str, ".mod_term_func", strlen(".mod_term_func"))==0 ||
|
|
|
|
strncmp(Str, ".picsymbol_stub", strlen(".picsymbol_stub"))==0 ||
|
|
|
|
strncmp(Str, ".symbol_stub", strlen(".symbol_stub"))==0 ||
|
|
|
|
strncmp(Str, ".static_data", strlen(".static_data"))==0 ||
|
|
|
|
strncmp(Str, ".section", strlen(".section"))==0 ||
|
|
|
|
strncmp(Str, ".lazy_symbol_pointer", strlen(".lazy_symbol_pointer"))==0 ||
|
|
|
|
strncmp(Str, ".non_lazy_symbol_pointer", strlen(".non_lazy_symbol_pointer"))==0 ||
|
|
|
|
strncmp(Str, ".dyld", strlen(".dyld"))==0 ||
|
|
|
|
strncmp(Str, ".const_data", strlen(".const_data"))==0 ||
|
|
|
|
strncmp(Str, ".objc", strlen(".objc"))==0 || //// many directives
|
|
|
|
strncmp(Str, ".static_const", strlen(".static_const"))==0)
|
2007-05-02 01:02:40 +00:00
|
|
|
inTextSection=false;
|
2007-10-25 21:54:43 +00:00
|
|
|
else if (strncmp(Str, ".text", strlen(".text"))==0)
|
2007-05-02 01:02:40 +00:00
|
|
|
inTextSection = true;
|
|
|
|
// Some can't really be handled without implementing significant pieces
|
|
|
|
// of an assembler. Others require dynamic adjustment of block sizes in
|
|
|
|
// AdjustBBOffsetsAfter; it's a big compile-time speed hit to check every
|
|
|
|
// instruction in there, and none of these are currently used in the kernel.
|
2007-10-25 21:54:43 +00:00
|
|
|
else if (strncmp(Str, ".macro", strlen(".macro"))==0 ||
|
|
|
|
strncmp(Str, ".if", strlen(".if"))==0 ||
|
|
|
|
strncmp(Str, ".align", strlen(".align"))==0 ||
|
|
|
|
strncmp(Str, ".fill", strlen(".fill"))==0 ||
|
|
|
|
strncmp(Str, ".space", strlen(".space"))==0 ||
|
|
|
|
strncmp(Str, ".zerofill", strlen(".zerofill"))==0 ||
|
|
|
|
strncmp(Str, ".p2align", strlen(".p2align"))==0 ||
|
|
|
|
strncmp(Str, ".p2alignw", strlen(".p2alignw"))==0 ||
|
|
|
|
strncmp(Str, ".p2alignl", strlen(".p2alignl"))==0 ||
|
|
|
|
strncmp(Str, ".align32", strlen(".p2align32"))==0 ||
|
|
|
|
strncmp(Str, ".include", strlen(".include"))==0)
|
2007-05-02 01:02:40 +00:00
|
|
|
cerr << "Directive " << Str << " in asm may lead to invalid offsets for" <<
|
|
|
|
" constant pools (the assembler will tell you if this happens).\n";
|
|
|
|
// Some generate code, but this is only interesting in the text section.
|
|
|
|
else if (inTextSection) {
|
2007-10-25 21:54:43 +00:00
|
|
|
if (strncmp(Str, ".long", strlen(".long"))==0)
|
2007-05-02 01:02:40 +00:00
|
|
|
Length += 4*countArguments(Str+strlen(".long"));
|
2007-10-25 21:54:43 +00:00
|
|
|
else if (strncmp(Str, ".short", strlen(".short"))==0)
|
2007-05-02 01:02:40 +00:00
|
|
|
Length += 2*countArguments(Str+strlen(".short"));
|
2007-10-25 21:54:43 +00:00
|
|
|
else if (strncmp(Str, ".byte", strlen(".byte"))==0)
|
2007-05-02 01:02:40 +00:00
|
|
|
Length += 1*countArguments(Str+strlen(".byte"));
|
2007-10-25 21:54:43 +00:00
|
|
|
else if (strncmp(Str, ".single", strlen(".single"))==0)
|
2007-05-02 01:02:40 +00:00
|
|
|
Length += 4*countArguments(Str+strlen(".single"));
|
2007-10-25 21:54:43 +00:00
|
|
|
else if (strncmp(Str, ".double", strlen(".double"))==0)
|
2007-05-02 01:02:40 +00:00
|
|
|
Length += 8*countArguments(Str+strlen(".double"));
|
2007-10-25 21:54:43 +00:00
|
|
|
else if (strncmp(Str, ".quad", strlen(".quad"))==0)
|
2007-05-02 01:02:40 +00:00
|
|
|
Length += 16*countArguments(Str+strlen(".quad"));
|
2007-10-25 21:54:43 +00:00
|
|
|
else if (strncmp(Str, ".ascii", strlen(".ascii"))==0)
|
2007-05-02 01:02:40 +00:00
|
|
|
Length += countString(Str+strlen(".ascii"));
|
2007-10-25 21:54:43 +00:00
|
|
|
else if (strncmp(Str, ".asciz", strlen(".asciz"))==0)
|
2007-05-02 01:02:40 +00:00
|
|
|
Length += countString(Str+strlen(".asciz"))+1;
|
|
|
|
}
|
|
|
|
} else if (inTextSection) {
|
2007-04-29 19:17:45 +00:00
|
|
|
// An instruction
|
|
|
|
atInsnStart = false;
|
2009-07-08 23:10:31 +00:00
|
|
|
if (Subtarget->isThumb()) { // FIXME thumb2
|
2007-04-29 19:17:45 +00:00
|
|
|
// BL and BLX <non-reg> are 4 bytes, all others 2.
|
2007-10-25 21:54:43 +00:00
|
|
|
if (strncmp(Str, "blx", strlen("blx"))==0) {
|
2007-05-02 01:02:40 +00:00
|
|
|
const char* p = Str+3;
|
|
|
|
while (*p && isspace(*p))
|
|
|
|
p++;
|
|
|
|
if (*p == 'r' || *p=='R')
|
|
|
|
Length += 2; // BLX reg
|
2007-04-29 19:17:45 +00:00
|
|
|
else
|
2007-05-02 01:02:40 +00:00
|
|
|
Length += 4; // BLX non-reg
|
2007-10-25 21:54:43 +00:00
|
|
|
} else if (strncmp(Str, "bl", strlen("bl"))==0)
|
2007-05-02 01:02:40 +00:00
|
|
|
Length += 4; // BL
|
|
|
|
else
|
2007-04-29 19:17:45 +00:00
|
|
|
Length += 2; // Thumb anything else
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Length += 4; // ARM
|
|
|
|
}
|
|
|
|
}
|
2008-09-25 21:00:33 +00:00
|
|
|
if (*Str == '\n' || *Str == BaseTAI::SeparatorChar)
|
2007-04-29 19:17:45 +00:00
|
|
|
atInsnStart = true;
|
|
|
|
}
|
2007-10-25 21:54:43 +00:00
|
|
|
free(s_copy);
|
2007-04-29 19:17:45 +00:00
|
|
|
return Length;
|
|
|
|
}
|
2008-10-05 08:53:29 +00:00
|
|
|
|
|
|
|
// Instantiate default implementation.
|
|
|
|
TEMPLATE_INSTANTIATION(class ARMTargetAsmInfo<TargetAsmInfo>);
|