blob: faf4f7ce64cf3bfeed41d9d3b47d55ce97fbbc19 [file] [log] [blame]
Chris Lattner7b26fce2009-08-22 20:48:53 +00001//===-- X86MCAsmInfo.cpp - X86 asm properties -----------------------------===//
Jim Laskey0e835412006-09-07 22:05:02 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Laskey0e835412006-09-07 22:05:02 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattner7b26fce2009-08-22 20:48:53 +000010// This file contains the declarations of the X86MCAsmInfo properties.
Jim Laskey0e835412006-09-07 22:05:02 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner7b26fce2009-08-22 20:48:53 +000014#include "X86MCAsmInfo.h"
Jim Laskey0e835412006-09-07 22:05:02 +000015#include "X86TargetMachine.h"
Chris Lattner9a6cf912009-08-12 07:22:17 +000016#include "llvm/ADT/Triple.h"
Chris Lattner5418dd52010-04-08 21:26:26 +000017#include "llvm/MC/MCContext.h"
Rafael Espindolac5dac4d2011-04-28 16:09:09 +000018#include "llvm/MC/MCExpr.h"
Chris Lattner76bdea32010-01-23 07:21:06 +000019#include "llvm/MC/MCSectionELF.h"
Rafael Espindolac5dac4d2011-04-28 16:09:09 +000020#include "llvm/MC/MCStreamer.h"
Chris Lattner1e9097e2009-08-11 23:01:09 +000021#include "llvm/Support/CommandLine.h"
Rafael Espindolaaea49582011-01-23 04:28:49 +000022#include "llvm/Support/ELF.h"
Jim Laskey0e835412006-09-07 22:05:02 +000023using namespace llvm;
Chris Lattner1e9097e2009-08-11 23:01:09 +000024
25enum AsmWriterFlavorTy {
26 // Note: This numbering has to match the GCC assembler dialects for inline
27 // asm alternatives to work right.
28 ATT = 0, Intel = 1
29};
30
Chris Lattner1e9097e2009-08-11 23:01:09 +000031static cl::opt<AsmWriterFlavorTy>
32AsmWriterFlavor("x86-asm-syntax", cl::init(ATT),
33 cl::desc("Choose style of code to emit from X86 backend:"),
34 cl::values(clEnumValN(ATT, "att", "Emit AT&T-style assembly"),
35 clEnumValN(Intel, "intel", "Emit Intel-style assembly"),
36 clEnumValEnd));
37
38
Chris Lattner09099182009-08-11 21:57:08 +000039static const char *const x86_asm_table[] = {
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000040 "{si}", "S",
41 "{di}", "D",
42 "{ax}", "a",
43 "{cx}", "c",
44 "{memory}", "memory",
45 "{flags}", "",
46 "{dirflag}", "",
47 "{fpsr}", "",
Eric Christopher719c2972011-07-07 22:54:12 +000048 "{fpcr}", "",
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000049 "{cc}", "cc",
50 0,0};
Andrew Lenharth2675e232006-11-28 19:52:49 +000051
Chris Lattner2b4364f2010-01-20 06:34:14 +000052X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &Triple) {
Chris Lattner09099182009-08-11 21:57:08 +000053 AsmTransCBE = x86_asm_table;
Chris Lattner1e9097e2009-08-11 23:01:09 +000054 AssemblerDialect = AsmWriterFlavor;
Eric Christopher719c2972011-07-07 22:54:12 +000055
Chris Lattner9a6cf912009-08-12 07:22:17 +000056 bool is64Bit = Triple.getArch() == Triple::x86_64;
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000057
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000058 TextAlignFillValue = 0x90;
Daniel Dunbar123686852009-07-24 08:24:36 +000059
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000060 if (!is64Bit)
61 Data64bitsDirective = 0; // we can't emit a 64-bit unit
Bill Wendling0a860df2009-07-13 18:48:39 +000062
Chris Lattnerd8716672010-02-17 01:38:01 +000063 // Use ## as a comment string so that .s files generated by llvm can go
Chris Lattnerb67807e2010-02-17 01:55:54 +000064 // through the GCC preprocessor without causing an error. This is needed
65 // because "clang foo.s" runs the C preprocessor, which is usually reserved
66 // for .S files on other systems. Perhaps this is because the file system
67 // wasn't always case preserving or something.
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000068 CommentString = "##";
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000069 PCSymbol = ".";
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000070
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000071 SupportsDebugInformation = true;
Devang Patel80be3512009-04-13 17:02:03 +000072 DwarfUsesInlineInfoSection = true;
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000073
74 // Exceptions handling
Rafael Espindolafc822362011-05-01 15:44:13 +000075 ExceptionsType = ExceptionHandling::DwarfCFI;
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000076}
77
Rafael Espindolac5dac4d2011-04-28 16:09:09 +000078const MCExpr *
79X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym,
Rafael Espindola95215a72011-05-01 04:19:24 +000080 unsigned Encoding,
Rafael Espindolac5dac4d2011-04-28 16:09:09 +000081 MCStreamer &Streamer) const {
82 MCContext &Context = Streamer.getContext();
83 const MCExpr *Res =
84 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOTPCREL, Context);
85 const MCExpr *Four = MCConstantExpr::Create(4, Context);
86 return MCBinaryExpr::CreateAdd(Res, Four, Context);
87}
88
89X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple)
90 : X86MCAsmInfoDarwin(Triple) {
91}
92
Chris Lattner963b2332010-03-11 00:06:19 +000093X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {
Chris Lattner09099182009-08-11 21:57:08 +000094 AsmTransCBE = x86_asm_table;
Chris Lattner1e9097e2009-08-11 23:01:09 +000095 AssemblerDialect = AsmWriterFlavor;
Anton Korobeynikovdaee2812008-07-09 13:28:49 +000096
Daniel Dunbar68e22cb2010-02-25 18:07:10 +000097 TextAlignFillValue = 0x90;
98
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +000099 PrivateGlobalPrefix = ".L";
100 WeakRefDirective = "\t.weak\t";
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +0000101 PCSymbol = ".";
102
103 // Set up DWARF directives
104 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
105
106 // Debug Information
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +0000107 SupportsDebugInformation = true;
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +0000108
109 // Exceptions handling
Rafael Espindolaa01cdb02011-04-15 15:11:06 +0000110 ExceptionsType = ExceptionHandling::DwarfCFI;
111
Chris Lattner963b2332010-03-11 00:06:19 +0000112 // OpenBSD has buggy support for .quad in 32-bit mode, just split into two
113 // .words.
114 if (T.getOS() == Triple::OpenBSD && T.getArch() == Triple::x86)
115 Data64bitsDirective = 0;
Chris Lattner76bdea32010-01-23 07:21:06 +0000116}
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +0000117
Chris Lattner5418dd52010-04-08 21:26:26 +0000118const MCSection *X86ELFMCAsmInfo::
119getNonexecutableStackSection(MCContext &Ctx) const {
Rafael Espindolaaea49582011-01-23 04:28:49 +0000120 return Ctx.getELFSection(".note.GNU-stack", ELF::SHT_PROGBITS,
Rafael Espindola19fa3802010-11-11 03:40:25 +0000121 0, SectionKind::getMetadata());
Anton Korobeynikov9a6ed372008-07-09 13:20:48 +0000122}
123
Chris Lattner2b4364f2010-01-20 06:34:14 +0000124X86MCAsmInfoCOFF::X86MCAsmInfoCOFF(const Triple &Triple) {
NAKAMURA Takumi547cc6f2010-12-07 02:43:45 +0000125 if (Triple.getArch() == Triple::x86_64) {
Michael J. Spencer377aa202010-08-21 05:58:13 +0000126 GlobalPrefix = "";
NAKAMURA Takumi547cc6f2010-12-07 02:43:45 +0000127 PrivateGlobalPrefix = ".L";
128 }
Michael J. Spencer377aa202010-08-21 05:58:13 +0000129
Chris Lattner09099182009-08-11 21:57:08 +0000130 AsmTransCBE = x86_asm_table;
Chris Lattner1e9097e2009-08-11 23:01:09 +0000131 AssemblerDialect = AsmWriterFlavor;
Daniel Dunbar68e22cb2010-02-25 18:07:10 +0000132
133 TextAlignFillValue = 0x90;
Benjamin Kramerd7d8afa2010-02-16 10:25:04 +0000134}