blob: 2b8720bac34385c6d621930bfe25cbc87490f566 [file] [log] [blame]
Chris Lattner621c44d2009-08-22 20:48:53 +00001//===-- X86MCAsmInfo.cpp - X86 asm properties -----------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002//
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//
Chris Lattner621c44d2009-08-22 20:48:53 +000010// This file contains the declarations of the X86MCAsmInfo properties.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner621c44d2009-08-22 20:48:53 +000014#include "X86MCAsmInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000015#include "X86TargetMachine.h"
Chris Lattnerd88f9fd2009-08-12 07:22:17 +000016#include "llvm/ADT/Triple.h"
Chris Lattner6ef20132010-04-08 21:26:26 +000017#include "llvm/MC/MCContext.h"
Chris Lattner2dc6ddd2010-01-23 07:21:06 +000018#include "llvm/MC/MCSectionELF.h"
Chris Lattner2c048f22009-08-11 23:01:09 +000019#include "llvm/Support/CommandLine.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000020using namespace llvm;
Chris Lattner2c048f22009-08-11 23:01:09 +000021
22enum AsmWriterFlavorTy {
23 // Note: This numbering has to match the GCC assembler dialects for inline
24 // asm alternatives to work right.
25 ATT = 0, Intel = 1
26};
27
Chris Lattner2c048f22009-08-11 23:01:09 +000028static cl::opt<AsmWriterFlavorTy>
29AsmWriterFlavor("x86-asm-syntax", cl::init(ATT),
30 cl::desc("Choose style of code to emit from X86 backend:"),
31 cl::values(clEnumValN(ATT, "att", "Emit AT&T-style assembly"),
32 clEnumValN(Intel, "intel", "Emit Intel-style assembly"),
33 clEnumValEnd));
34
35
Chris Lattner4e765db2009-08-11 21:57:08 +000036static const char *const x86_asm_table[] = {
Anton Korobeynikov3829e8a2008-09-25 21:00:33 +000037 "{si}", "S",
38 "{di}", "D",
39 "{ax}", "a",
40 "{cx}", "c",
41 "{memory}", "memory",
42 "{flags}", "",
43 "{dirflag}", "",
44 "{fpsr}", "",
45 "{cc}", "cc",
46 0,0};
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047
Chris Lattner50f82ef2010-01-20 06:34:14 +000048X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &Triple) {
Chris Lattner4e765db2009-08-11 21:57:08 +000049 AsmTransCBE = x86_asm_table;
Chris Lattner2c048f22009-08-11 23:01:09 +000050 AssemblerDialect = AsmWriterFlavor;
Chris Lattner4e765db2009-08-11 21:57:08 +000051
Chris Lattnerd88f9fd2009-08-12 07:22:17 +000052 bool is64Bit = Triple.getArch() == Triple::x86_64;
Anton Korobeynikovf700e682008-07-09 13:20:48 +000053
Anton Korobeynikovf700e682008-07-09 13:20:48 +000054 TextAlignFillValue = 0x90;
Daniel Dunbar1e13b972009-07-24 08:24:36 +000055
Anton Korobeynikovf700e682008-07-09 13:20:48 +000056 if (!is64Bit)
57 Data64bitsDirective = 0; // we can't emit a 64-bit unit
Bill Wendling0ddb3862009-07-13 18:48:39 +000058
Chris Lattnerf4897622010-02-17 01:38:01 +000059 // Use ## as a comment string so that .s files generated by llvm can go
Chris Lattner186af7e2010-02-17 01:55:54 +000060 // through the GCC preprocessor without causing an error. This is needed
61 // because "clang foo.s" runs the C preprocessor, which is usually reserved
62 // for .S files on other systems. Perhaps this is because the file system
63 // wasn't always case preserving or something.
Anton Korobeynikovf700e682008-07-09 13:20:48 +000064 CommentString = "##";
Anton Korobeynikovf700e682008-07-09 13:20:48 +000065 PCSymbol = ".";
Anton Korobeynikovf700e682008-07-09 13:20:48 +000066
Anton Korobeynikovf700e682008-07-09 13:20:48 +000067 SupportsDebugInformation = true;
Devang Patel88bf96e2009-04-13 17:02:03 +000068 DwarfUsesInlineInfoSection = true;
Anton Korobeynikovf700e682008-07-09 13:20:48 +000069
70 // Exceptions handling
Jim Grosbach29feb6a2009-08-11 00:09:57 +000071 ExceptionsType = ExceptionHandling::Dwarf;
Anton Korobeynikovf700e682008-07-09 13:20:48 +000072}
73
Chris Lattner86697f12010-03-11 00:06:19 +000074X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {
Chris Lattner4e765db2009-08-11 21:57:08 +000075 AsmTransCBE = x86_asm_table;
Chris Lattner2c048f22009-08-11 23:01:09 +000076 AssemblerDialect = AsmWriterFlavor;
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +000077
Daniel Dunbar157e9e12010-02-25 18:07:10 +000078 TextAlignFillValue = 0x90;
79
Anton Korobeynikovf700e682008-07-09 13:20:48 +000080 PrivateGlobalPrefix = ".L";
81 WeakRefDirective = "\t.weak\t";
Anton Korobeynikovf700e682008-07-09 13:20:48 +000082 PCSymbol = ".";
83
84 // Set up DWARF directives
85 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
86
87 // Debug Information
Anton Korobeynikovf700e682008-07-09 13:20:48 +000088 SupportsDebugInformation = true;
Anton Korobeynikovf700e682008-07-09 13:20:48 +000089
90 // Exceptions handling
Jim Grosbach29feb6a2009-08-11 00:09:57 +000091 ExceptionsType = ExceptionHandling::Dwarf;
Chris Lattner86697f12010-03-11 00:06:19 +000092
93 // OpenBSD has buggy support for .quad in 32-bit mode, just split into two
94 // .words.
95 if (T.getOS() == Triple::OpenBSD && T.getArch() == Triple::x86)
96 Data64bitsDirective = 0;
Chris Lattner2dc6ddd2010-01-23 07:21:06 +000097}
Anton Korobeynikovf700e682008-07-09 13:20:48 +000098
Chris Lattner6ef20132010-04-08 21:26:26 +000099const MCSection *X86ELFMCAsmInfo::
100getNonexecutableStackSection(MCContext &Ctx) const {
101 return Ctx.getELFSection(".note.GNU-stack", MCSectionELF::SHT_PROGBITS,
102 0, SectionKind::getMetadata(), false);
Anton Korobeynikovf700e682008-07-09 13:20:48 +0000103}
104
Chris Lattner50f82ef2010-01-20 06:34:14 +0000105X86MCAsmInfoCOFF::X86MCAsmInfoCOFF(const Triple &Triple) {
Chris Lattner4e765db2009-08-11 21:57:08 +0000106 AsmTransCBE = x86_asm_table;
Chris Lattner2c048f22009-08-11 23:01:09 +0000107 AssemblerDialect = AsmWriterFlavor;
Daniel Dunbar157e9e12010-02-25 18:07:10 +0000108
109 TextAlignFillValue = 0x90;
Benjamin Kramerccc5ac32010-02-16 10:25:04 +0000110}