blob: add1dbf5c375dfbfcaa54a2efea2ccf9a1bf023c [file] [log] [blame]
Jim Laskey7c95ad42006-09-06 19:21:41 +00001//===-- TargetAsmInfo.cpp - Asm Info ---------------------------------------==//
Jim Laskeyec0d9fe2006-09-06 18:35:33 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jim Laskeyec0d9fe2006-09-06 18:35:33 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines target asm properties related what form asm statements
11// should take.
12//
13//===----------------------------------------------------------------------===//
14
Anton Korobeynikov28a2b542008-06-28 13:45:57 +000015#include "llvm/Constants.h"
Anton Korobeynikov72bb4022009-01-27 22:29:24 +000016#include "llvm/DerivedTypes.h"
Anton Korobeynikov28a2b542008-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"
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000021#include "llvm/Target/TargetAsmInfo.h"
Chris Lattner8ca52092009-07-26 06:11:33 +000022#include "llvm/Target/TargetData.h"
Anton Korobeynikovdb232312009-03-29 17:13:49 +000023#include "llvm/Target/TargetMachine.h"
Anton Korobeynikov28a2b542008-06-28 13:45:57 +000024#include "llvm/Target/TargetOptions.h"
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000025#include "llvm/Support/Dwarf.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000026#include "llvm/Support/ErrorHandling.h"
Dale Johannesen3bb62832007-04-23 20:00:17 +000027#include <cctype>
28#include <cstring>
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000029using namespace llvm;
30
Chris Lattner0d4960c32009-07-24 20:14:10 +000031TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm) : TM(tm) {
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000032 ZeroFillDirective = 0;
33 NonexecutableStackDirective = 0;
34 NeedsSet = false;
35 MaxInstLength = 4;
36 PCSymbol = "$";
37 SeparatorChar = ';';
David Greene014700c2009-07-13 20:25:48 +000038 CommentColumn = 60;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000039 CommentString = "#";
David Greene76081c42009-07-20 22:02:59 +000040 FirstOperandColumn = 0;
41 MaxOperandLength = 0;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000042 GlobalPrefix = "";
43 PrivateGlobalPrefix = ".";
Chris Lattner90f8b702009-07-21 17:30:51 +000044 LinkerPrivateGlobalPrefix = "";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000045 JumpTableSpecialLabelPrefix = 0;
46 GlobalVarAddrPrefix = "";
47 GlobalVarAddrSuffix = "";
48 FunctionAddrPrefix = "";
49 FunctionAddrSuffix = "";
50 PersonalityPrefix = "";
51 PersonalitySuffix = "";
52 NeedsIndirectEncoding = false;
53 InlineAsmStart = "#APP";
54 InlineAsmEnd = "#NO_APP";
55 AssemblerDialect = 0;
Chris Lattnera93ca922009-06-18 23:41:35 +000056 AllowQuotesInName = false;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000057 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;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000072 JumpTableDirective = 0;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000073 // 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";
77 SetDirective = 0;
78 LCOMMDirective = 0;
79 COMMDirective = "\t.comm\t";
80 COMMDirectiveTakesAlignment = true;
81 HasDotTypeDotSizeDirective = true;
Rafael Espindola952b8392008-12-03 11:01:37 +000082 HasSingleParameterDotFile = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000083 UsedDirective = 0;
84 WeakRefDirective = 0;
85 WeakDefDirective = 0;
86 // FIXME: These are ELFish - move to ELFTAI.
87 HiddenDirective = "\t.hidden\t";
88 ProtectedDirective = "\t.protected\t";
89 AbsoluteDebugSectionOffsets = false;
90 AbsoluteEHSectionOffsets = false;
91 HasLEB128 = false;
92 HasDotLocAndDotFile = false;
93 SupportsDebugInformation = false;
94 SupportsExceptionHandling = false;
95 DwarfRequiresFrameSection = true;
Devang Patel0f7fef32009-04-13 17:02:03 +000096 DwarfUsesInlineInfoSection = false;
Chris Lattnere2cf37b2009-07-17 20:46:40 +000097 Is_EHSymbolPrivate = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000098 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";
Devang Patel0f7fef32009-04-13 17:02:03 +0000107 DwarfDebugInlineSection = ".debug_inlined";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000108 DwarfStrSection = ".debug_str";
109 DwarfLocSection = ".debug_loc";
110 DwarfARangesSection = ".debug_aranges";
111 DwarfRangesSection = ".debug_ranges";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000112 DwarfMacroInfoSection = ".debug_macinfo";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000113 DwarfEHFrameSection = ".eh_frame";
114 DwarfExceptionSection = ".gcc_except_table";
115 AsmTransCBE = 0;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000116}
Chris Lattnerf5b10ec2006-10-05 00:35:16 +0000117
118TargetAsmInfo::~TargetAsmInfo() {
119}
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000120
121/// Measure the specified inline asm to determine an approximation of its
122/// length.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000123/// 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.
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000129unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
130 // Count the number of instructions in the asm.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000131 bool atInsnStart = true;
132 unsigned Length = 0;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000133 for (; *Str; ++Str) {
134 if (*Str == '\n' || *Str == SeparatorChar)
Dale Johannesen3bb62832007-04-23 20:00:17 +0000135 atInsnStart = true;
136 if (atInsnStart && !isspace(*Str)) {
137 Length += MaxInstLength;
138 atInsnStart = false;
139 }
140 if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
141 atInsnStart = false;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000142 }
143
Dale Johannesen3bb62832007-04-23 20:00:17 +0000144 return Length;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000145}
Anton Korobeynikova6199c82007-03-07 02:47:57 +0000146
Chris Lattner7a01e952009-07-31 21:39:55 +0000147unsigned TargetAsmInfo::PreferredEHDataFormat() const {
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000148 return dwarf::DW_EH_PE_absptr;
149}
150
Anton Korobeynikovffe31d72008-08-16 12:57:46 +0000151unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
152 unsigned Size = 0;
153 do {
154 Value >>= 7;
155 Size += sizeof(int8_t);
156 } while (Value);
157 return Size;
158}
159
160unsigned TargetAsmInfo::getSLEB128Size(int Value) {
161 unsigned Size = 0;
162 int Sign = Value >> (8 * sizeof(Value) - 1);
163 bool IsMore;
164
165 do {
166 unsigned Byte = Value & 0x7f;
167 Value >>= 7;
168 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
169 Size += sizeof(int8_t);
170 } while (IsMore);
171 return Size;
172}