blob: 4c6100ba8822d4486f998c7505166b193b5c82fe [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- TargetAsmInfo.cpp - Asm Info ---------------------------------------==//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines target asm properties related what form asm statements
11// should take.
12//
13//===----------------------------------------------------------------------===//
14
Anton Korobeynikovb4f658c2008-06-28 13:45:57 +000015#include "llvm/Constants.h"
asl4eeee012009-01-27 22:29:24 +000016#include "llvm/DerivedTypes.h"
Anton Korobeynikovb4f658c2008-06-28 13:45:57 +000017#include "llvm/GlobalVariable.h"
18#include "llvm/Function.h"
19#include "llvm/Module.h"
20#include "llvm/Type.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021#include "llvm/Target/TargetAsmInfo.h"
Chris Lattner2a7dd7d2009-07-26 06:11:33 +000022#include "llvm/Target/TargetData.h"
Anton Korobeynikov1dc008a2009-03-29 17:13:49 +000023#include "llvm/Target/TargetMachine.h"
Anton Korobeynikovb4f658c2008-06-28 13:45:57 +000024#include "llvm/Target/TargetOptions.h"
Anton Korobeynikov65c0d872008-02-27 23:33:50 +000025#include "llvm/Support/Dwarf.h"
Edwin Török675d5622009-07-11 20:10:48 +000026#include "llvm/Support/ErrorHandling.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000027#include <cctype>
28#include <cstring>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000029using namespace llvm;
30
Chris Lattner224957e2009-07-24 20:14:10 +000031TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm) : TM(tm) {
Anton Korobeynikov3829e8a2008-09-25 21:00:33 +000032 BSSSection = "\t.bss";
Anton Korobeynikov3829e8a2008-09-25 21:00:33 +000033 ZeroFillDirective = 0;
34 NonexecutableStackDirective = 0;
35 NeedsSet = false;
36 MaxInstLength = 4;
37 PCSymbol = "$";
38 SeparatorChar = ';';
David Greene63486122009-07-13 20:25:48 +000039 CommentColumn = 60;
Anton Korobeynikov3829e8a2008-09-25 21:00:33 +000040 CommentString = "#";
David Greene47974bf2009-07-20 22:02:59 +000041 FirstOperandColumn = 0;
42 MaxOperandLength = 0;
Anton Korobeynikov3829e8a2008-09-25 21:00:33 +000043 GlobalPrefix = "";
44 PrivateGlobalPrefix = ".";
Chris Lattnerc889b3b2009-07-21 17:30:51 +000045 LinkerPrivateGlobalPrefix = "";
Anton Korobeynikov3829e8a2008-09-25 21:00:33 +000046 JumpTableSpecialLabelPrefix = 0;
47 GlobalVarAddrPrefix = "";
48 GlobalVarAddrSuffix = "";
49 FunctionAddrPrefix = "";
50 FunctionAddrSuffix = "";
51 PersonalityPrefix = "";
52 PersonalitySuffix = "";
53 NeedsIndirectEncoding = false;
54 InlineAsmStart = "#APP";
55 InlineAsmEnd = "#NO_APP";
56 AssemblerDialect = 0;
Chris Lattner690b02c2009-06-18 23:41:35 +000057 AllowQuotesInName = false;
Anton Korobeynikov3829e8a2008-09-25 21:00:33 +000058 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;
76 CStringSection = 0;
Anton Korobeynikov3829e8a2008-09-25 21:00:33 +000077 // 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";
81 SetDirective = 0;
82 LCOMMDirective = 0;
83 COMMDirective = "\t.comm\t";
84 COMMDirectiveTakesAlignment = true;
85 HasDotTypeDotSizeDirective = true;
Rafael Espindola5cf2e552008-12-03 11:01:37 +000086 HasSingleParameterDotFile = true;
Anton Korobeynikov3829e8a2008-09-25 21:00:33 +000087 UsedDirective = 0;
88 WeakRefDirective = 0;
89 WeakDefDirective = 0;
90 // FIXME: These are ELFish - move to ELFTAI.
91 HiddenDirective = "\t.hidden\t";
92 ProtectedDirective = "\t.protected\t";
93 AbsoluteDebugSectionOffsets = false;
94 AbsoluteEHSectionOffsets = false;
95 HasLEB128 = false;
96 HasDotLocAndDotFile = false;
97 SupportsDebugInformation = false;
98 SupportsExceptionHandling = false;
99 DwarfRequiresFrameSection = true;
Devang Patel88bf96e2009-04-13 17:02:03 +0000100 DwarfUsesInlineInfoSection = false;
Chris Lattner5c3475e2009-07-17 20:46:40 +0000101 Is_EHSymbolPrivate = true;
Anton Korobeynikov3829e8a2008-09-25 21:00:33 +0000102 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";
Devang Patel88bf96e2009-04-13 17:02:03 +0000111 DwarfDebugInlineSection = ".debug_inlined";
Anton Korobeynikov3829e8a2008-09-25 21:00:33 +0000112 DwarfStrSection = ".debug_str";
113 DwarfLocSection = ".debug_loc";
114 DwarfARangesSection = ".debug_aranges";
115 DwarfRangesSection = ".debug_ranges";
Chris Lattnerecbf73b2009-06-18 23:31:37 +0000116 DwarfMacroInfoSection = ".debug_macinfo";
Anton Korobeynikov3829e8a2008-09-25 21:00:33 +0000117 DwarfEHFrameSection = ".eh_frame";
118 DwarfExceptionSection = ".gcc_except_table";
119 AsmTransCBE = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000120}
121
122TargetAsmInfo::~TargetAsmInfo() {
123}
124
125/// Measure the specified inline asm to determine an approximation of its
126/// length.
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.
133unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
134 // Count the number of instructions in the asm.
135 bool atInsnStart = true;
136 unsigned Length = 0;
137 for (; *Str; ++Str) {
138 if (*Str == '\n' || *Str == SeparatorChar)
139 atInsnStart = true;
140 if (atInsnStart && !isspace(*Str)) {
141 Length += MaxInstLength;
142 atInsnStart = false;
143 }
144 if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
145 atInsnStart = false;
146 }
147
148 return Length;
149}
150
Chris Lattner8b0bb372009-07-31 21:39:55 +0000151unsigned TargetAsmInfo::PreferredEHDataFormat() const {
Anton Korobeynikov65c0d872008-02-27 23:33:50 +0000152 return dwarf::DW_EH_PE_absptr;
153}
154
aslc200b112008-08-16 12:57:46 +0000155unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
156 unsigned Size = 0;
157 do {
158 Value >>= 7;
159 Size += sizeof(int8_t);
160 } while (Value);
161 return Size;
162}
163
164unsigned TargetAsmInfo::getSLEB128Size(int Value) {
165 unsigned Size = 0;
166 int Sign = Value >> (8 * sizeof(Value) - 1);
167 bool IsMore;
168
169 do {
170 unsigned Byte = Value & 0x7f;
171 Value >>= 7;
172 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
173 Size += sizeof(int8_t);
174 } while (IsMore);
175 return Size;
176}