blob: 6686214e06f57f134b8e3e269ab09d832be5bbdb [file] [log] [blame]
Chris Lattneraf76e592009-08-22 20:48:53 +00001//===-- X86MCAsmInfo.cpp - X86 asm properties -----------------------------===//
Jim Laskey8e8de8f2006-09-07 22:05:02 +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 Laskey8e8de8f2006-09-07 22:05:02 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattneraf76e592009-08-22 20:48:53 +000010// This file contains the declarations of the X86MCAsmInfo properties.
Jim Laskey8e8de8f2006-09-07 22:05:02 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattneraf76e592009-08-22 20:48:53 +000014#include "X86MCAsmInfo.h"
Jim Laskey8e8de8f2006-09-07 22:05:02 +000015#include "X86TargetMachine.h"
Chris Lattnera7ac47c2009-08-12 07:22:17 +000016#include "llvm/ADT/Triple.h"
Chris Lattner74aae472010-04-08 21:26:26 +000017#include "llvm/MC/MCContext.h"
Chris Lattnerf9f93e42010-01-23 07:21:06 +000018#include "llvm/MC/MCSectionELF.h"
Chris Lattnerce914b82009-08-11 23:01:09 +000019#include "llvm/Support/CommandLine.h"
Rafael Espindolac85dca62011-01-23 04:28:49 +000020#include "llvm/Support/ELF.h"
Jim Laskey8e8de8f2006-09-07 22:05:02 +000021using namespace llvm;
Chris Lattnerce914b82009-08-11 23:01:09 +000022
23enum AsmWriterFlavorTy {
24 // Note: This numbering has to match the GCC assembler dialects for inline
25 // asm alternatives to work right.
26 ATT = 0, Intel = 1
27};
28
Chris Lattnerce914b82009-08-11 23:01:09 +000029static cl::opt<AsmWriterFlavorTy>
30AsmWriterFlavor("x86-asm-syntax", cl::init(ATT),
31 cl::desc("Choose style of code to emit from X86 backend:"),
32 cl::values(clEnumValN(ATT, "att", "Emit AT&T-style assembly"),
33 clEnumValN(Intel, "intel", "Emit Intel-style assembly"),
34 clEnumValEnd));
35
36
Chris Lattnera1a1f022009-08-11 21:57:08 +000037static const char *const x86_asm_table[] = {
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000038 "{si}", "S",
39 "{di}", "D",
40 "{ax}", "a",
41 "{cx}", "c",
42 "{memory}", "memory",
43 "{flags}", "",
44 "{dirflag}", "",
45 "{fpsr}", "",
46 "{cc}", "cc",
47 0,0};
Andrew Lenharth6c0695f2006-11-28 19:52:49 +000048
Chris Lattner8eeba352010-01-20 06:34:14 +000049X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &Triple) {
Chris Lattnera1a1f022009-08-11 21:57:08 +000050 AsmTransCBE = x86_asm_table;
Chris Lattnerce914b82009-08-11 23:01:09 +000051 AssemblerDialect = AsmWriterFlavor;
Chris Lattnera1a1f022009-08-11 21:57:08 +000052
Chris Lattnera7ac47c2009-08-12 07:22:17 +000053 bool is64Bit = Triple.getArch() == Triple::x86_64;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000054
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000055 TextAlignFillValue = 0x90;
Daniel Dunbarf6ccee52009-07-24 08:24:36 +000056
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000057 if (!is64Bit)
58 Data64bitsDirective = 0; // we can't emit a 64-bit unit
Bill Wendlingb6be1392009-07-13 18:48:39 +000059
Chris Lattnerfeeb93e2010-02-17 01:38:01 +000060 // Use ## as a comment string so that .s files generated by llvm can go
Chris Lattner52be68d2010-02-17 01:55:54 +000061 // through the GCC preprocessor without causing an error. This is needed
62 // because "clang foo.s" runs the C preprocessor, which is usually reserved
63 // for .S files on other systems. Perhaps this is because the file system
64 // wasn't always case preserving or something.
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000065 CommentString = "##";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000066 PCSymbol = ".";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000067
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000068 SupportsDebugInformation = true;
Devang Patel0f7fef32009-04-13 17:02:03 +000069 DwarfUsesInlineInfoSection = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000070
71 // Exceptions handling
Anton Korobeynikov3965b5e2011-01-14 21:58:08 +000072 ExceptionsType = ExceptionHandling::DwarfTable;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000073}
74
Chris Lattnerbcc5cb42010-03-11 00:06:19 +000075X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {
Chris Lattnera1a1f022009-08-11 21:57:08 +000076 AsmTransCBE = x86_asm_table;
Chris Lattnerce914b82009-08-11 23:01:09 +000077 AssemblerDialect = AsmWriterFlavor;
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +000078
Daniel Dunbar010b1b22010-02-25 18:07:10 +000079 TextAlignFillValue = 0x90;
80
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000081 PrivateGlobalPrefix = ".L";
82 WeakRefDirective = "\t.weak\t";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000083 PCSymbol = ".";
84
85 // Set up DWARF directives
86 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
87
88 // Debug Information
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000089 SupportsDebugInformation = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000090
91 // Exceptions handling
Anton Korobeynikov3965b5e2011-01-14 21:58:08 +000092 ExceptionsType = ExceptionHandling::DwarfTable;
93
Chris Lattnerbcc5cb42010-03-11 00:06:19 +000094 // OpenBSD has buggy support for .quad in 32-bit mode, just split into two
95 // .words.
96 if (T.getOS() == Triple::OpenBSD && T.getArch() == Triple::x86)
97 Data64bitsDirective = 0;
Chris Lattnerf9f93e42010-01-23 07:21:06 +000098}
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000099
Chris Lattner74aae472010-04-08 21:26:26 +0000100const MCSection *X86ELFMCAsmInfo::
101getNonexecutableStackSection(MCContext &Ctx) const {
Rafael Espindolac85dca62011-01-23 04:28:49 +0000102 return Ctx.getELFSection(".note.GNU-stack", ELF::SHT_PROGBITS,
Rafael Espindola3f2d13c2010-11-11 03:40:25 +0000103 0, SectionKind::getMetadata());
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000104}
105
Chris Lattner8eeba352010-01-20 06:34:14 +0000106X86MCAsmInfoCOFF::X86MCAsmInfoCOFF(const Triple &Triple) {
NAKAMURA Takumi63fbb522010-12-07 02:43:45 +0000107 if (Triple.getArch() == Triple::x86_64) {
Michael J. Spencerda0bfcd2010-08-21 05:58:13 +0000108 GlobalPrefix = "";
NAKAMURA Takumi63fbb522010-12-07 02:43:45 +0000109 PrivateGlobalPrefix = ".L";
110 }
Michael J. Spencerda0bfcd2010-08-21 05:58:13 +0000111
Chris Lattnera1a1f022009-08-11 21:57:08 +0000112 AsmTransCBE = x86_asm_table;
Chris Lattnerce914b82009-08-11 23:01:09 +0000113 AssemblerDialect = AsmWriterFlavor;
Daniel Dunbar010b1b22010-02-25 18:07:10 +0000114
115 TextAlignFillValue = 0x90;
Benjamin Kramer30fb00a2010-02-16 10:25:04 +0000116}