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 ZeroFillDirective = 0;
33 NonexecutableStackDirective = 0;
40 FirstOperandColumn = 0;
43 PrivateGlobalPrefix = ".";
44 LinkerPrivateGlobalPrefix = "";
45 JumpTableSpecialLabelPrefix = 0;
46 GlobalVarAddrPrefix = "";
47 GlobalVarAddrSuffix = "";
48 FunctionAddrPrefix = "";
49 FunctionAddrSuffix = "";
50 PersonalityPrefix = "";
51 PersonalitySuffix = "";
52 NeedsIndirectEncoding = false;
53 InlineAsmStart = "#APP";
54 InlineAsmEnd = "#NO_APP";
56 AllowQuotesInName = false;
57 ZeroDirective = "\t.zero\t";
58 ZeroDirectiveSuffix = 0;
59 AsciiDirective = "\t.ascii\t";
60 AscizDirective = "\t.asciz\t";
61 Data8bitsDirective = "\t.byte\t";
62 Data16bitsDirective = "\t.short\t";
63 Data32bitsDirective = "\t.long\t";
64 Data64bitsDirective = "\t.quad\t";
65 AlignDirective = "\t.align\t";
66 AlignmentIsInBytes = true;
67 TextAlignFillValue = 0;
68 SwitchToSectionDirective = "\t.section\t";
69 TextSectionStartSuffix = "";
70 DataSectionStartSuffix = "";
71 SectionEndDirectiveSuffix = 0;
72 JumpTableDirective = 0;
73 // FIXME: Flags are ELFish - replace with normal section stuff.
74 StaticCtorsSection = "\t.section .ctors,\"aw\",@progbits";
75 StaticDtorsSection = "\t.section .dtors,\"aw\",@progbits";
76 GlobalDirective = "\t.globl\t";
79 COMMDirective = "\t.comm\t";
80 COMMDirectiveTakesAlignment = true;
81 HasDotTypeDotSizeDirective = true;
82 HasSingleParameterDotFile = true;
86 // FIXME: These are ELFish - move to ELFTAI.
87 HiddenDirective = "\t.hidden\t";
88 ProtectedDirective = "\t.protected\t";
89 AbsoluteDebugSectionOffsets = false;
90 AbsoluteEHSectionOffsets = false;
92 HasDotLocAndDotFile = false;
93 SupportsDebugInformation = false;
94 SupportsExceptionHandling = false;
95 DwarfRequiresFrameSection = true;
96 DwarfUsesInlineInfoSection = false;
97 Is_EHSymbolPrivate = true;
98 GlobalEHDirective = 0;
99 SupportsWeakOmittedEHFrame = true;
100 DwarfSectionOffsetDirective = 0;
101 DwarfAbbrevSection = ".debug_abbrev";
102 DwarfInfoSection = ".debug_info";
103 DwarfLineSection = ".debug_line";
104 DwarfFrameSection = ".debug_frame";
105 DwarfPubNamesSection = ".debug_pubnames";
106 DwarfPubTypesSection = ".debug_pubtypes";
107 DwarfDebugInlineSection = ".debug_inlined";
108 DwarfStrSection = ".debug_str";
109 DwarfLocSection = ".debug_loc";
110 DwarfARangesSection = ".debug_aranges";
111 DwarfRangesSection = ".debug_ranges";
112 DwarfMacroInfoSection = ".debug_macinfo";
113 DwarfEHFrameSection = ".eh_frame";
114 DwarfExceptionSection = ".gcc_except_table";
118 TargetAsmInfo::~TargetAsmInfo() {
121 /// Measure the specified inline asm to determine an approximation of its
123 /// Comments (which run till the next SeparatorChar or newline) do not
124 /// count as an instruction.
125 /// Any other non-whitespace text is considered an instruction, with
126 /// multiple instructions separated by SeparatorChar or newlines.
127 /// Variable-length instructions are not handled here; this function
128 /// may be overloaded in the target code to do that.
129 unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
130 // Count the number of instructions in the asm.
131 bool atInsnStart = true;
133 for (; *Str; ++Str) {
134 if (*Str == '\n' || *Str == SeparatorChar)
136 if (atInsnStart && !isspace(*Str)) {
137 Length += MaxInstLength;
140 if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
147 unsigned TargetAsmInfo::PreferredEHDataFormat() const {
148 return dwarf::DW_EH_PE_absptr;
151 unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
155 Size += sizeof(int8_t);
160 unsigned TargetAsmInfo::getSLEB128Size(int Value) {
162 int Sign = Value >> (8 * sizeof(Value) - 1);
166 unsigned Byte = Value & 0x7f;
168 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
169 Size += sizeof(int8_t);