1 //===-- TargetAsmInfo.cpp - Asm Info ---------------------------------------==//
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 defines target asm properties related what form asm statements
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Constants.h"
16 #include "llvm/DerivedTypes.h"
17 #include "llvm/GlobalVariable.h"
18 #include "llvm/Function.h"
19 #include "llvm/Module.h"
20 #include "llvm/Type.h"
21 #include "llvm/Target/TargetAsmInfo.h"
22 #include "llvm/Target/TargetData.h"
23 #include "llvm/Target/TargetMachine.h"
24 #include "llvm/Target/TargetOptions.h"
25 #include "llvm/Support/Dwarf.h"
26 #include "llvm/Support/ErrorHandling.h"
31 TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm) : TM(tm) {
32 BSSSection = "\t.bss";
33 ZeroFillDirective = 0;
34 NonexecutableStackDirective = 0;
41 FirstOperandColumn = 0;
44 PrivateGlobalPrefix = ".";
45 LinkerPrivateGlobalPrefix = "";
46 JumpTableSpecialLabelPrefix = 0;
47 GlobalVarAddrPrefix = "";
48 GlobalVarAddrSuffix = "";
49 FunctionAddrPrefix = "";
50 FunctionAddrSuffix = "";
51 PersonalityPrefix = "";
52 PersonalitySuffix = "";
53 NeedsIndirectEncoding = false;
54 InlineAsmStart = "#APP";
55 InlineAsmEnd = "#NO_APP";
57 AllowQuotesInName = false;
58 ZeroDirective = "\t.zero\t";
59 ZeroDirectiveSuffix = 0;
60 AsciiDirective = "\t.ascii\t";
61 AscizDirective = "\t.asciz\t";
62 Data8bitsDirective = "\t.byte\t";
63 Data16bitsDirective = "\t.short\t";
64 Data32bitsDirective = "\t.long\t";
65 Data64bitsDirective = "\t.quad\t";
66 AlignDirective = "\t.align\t";
67 AlignmentIsInBytes = true;
68 TextAlignFillValue = 0;
69 SwitchToSectionDirective = "\t.section\t";
70 TextSectionStartSuffix = "";
71 DataSectionStartSuffix = "";
72 SectionEndDirectiveSuffix = 0;
73 ConstantPoolSection = "\t.section .rodata";
74 JumpTableDataSection = "\t.section .rodata";
75 JumpTableDirective = 0;
77 // FIXME: Flags are ELFish - replace with normal section stuff.
78 StaticCtorsSection = "\t.section .ctors,\"aw\",@progbits";
79 StaticDtorsSection = "\t.section .dtors,\"aw\",@progbits";
80 GlobalDirective = "\t.globl\t";
83 COMMDirective = "\t.comm\t";
84 COMMDirectiveTakesAlignment = true;
85 HasDotTypeDotSizeDirective = true;
86 HasSingleParameterDotFile = true;
90 // FIXME: These are ELFish - move to ELFTAI.
91 HiddenDirective = "\t.hidden\t";
92 ProtectedDirective = "\t.protected\t";
93 AbsoluteDebugSectionOffsets = false;
94 AbsoluteEHSectionOffsets = false;
96 HasDotLocAndDotFile = false;
97 SupportsDebugInformation = false;
98 SupportsExceptionHandling = false;
99 DwarfRequiresFrameSection = true;
100 DwarfUsesInlineInfoSection = false;
101 Is_EHSymbolPrivate = true;
102 GlobalEHDirective = 0;
103 SupportsWeakOmittedEHFrame = true;
104 DwarfSectionOffsetDirective = 0;
105 DwarfAbbrevSection = ".debug_abbrev";
106 DwarfInfoSection = ".debug_info";
107 DwarfLineSection = ".debug_line";
108 DwarfFrameSection = ".debug_frame";
109 DwarfPubNamesSection = ".debug_pubnames";
110 DwarfPubTypesSection = ".debug_pubtypes";
111 DwarfDebugInlineSection = ".debug_inlined";
112 DwarfStrSection = ".debug_str";
113 DwarfLocSection = ".debug_loc";
114 DwarfARangesSection = ".debug_aranges";
115 DwarfRangesSection = ".debug_ranges";
116 DwarfMacroInfoSection = ".debug_macinfo";
117 DwarfEHFrameSection = ".eh_frame";
118 DwarfExceptionSection = ".gcc_except_table";
122 TargetAsmInfo::~TargetAsmInfo() {
125 /// Measure the specified inline asm to determine an approximation of its
127 /// Comments (which run till the next SeparatorChar or newline) do not
128 /// count as an instruction.
129 /// Any other non-whitespace text is considered an instruction, with
130 /// multiple instructions separated by SeparatorChar or newlines.
131 /// Variable-length instructions are not handled here; this function
132 /// may be overloaded in the target code to do that.
133 unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
134 // Count the number of instructions in the asm.
135 bool atInsnStart = true;
137 for (; *Str; ++Str) {
138 if (*Str == '\n' || *Str == SeparatorChar)
140 if (atInsnStart && !isspace(*Str)) {
141 Length += MaxInstLength;
144 if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
151 unsigned TargetAsmInfo::PreferredEHDataFormat() const {
152 return dwarf::DW_EH_PE_absptr;
155 unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
159 Size += sizeof(int8_t);
164 unsigned TargetAsmInfo::getSLEB128Size(int Value) {
166 int Sign = Value >> (8 * sizeof(Value) - 1);
170 unsigned Byte = Value & 0x7f;
172 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
173 Size += sizeof(int8_t);