2010-10-09 11:01:07 +00:00
|
|
|
//===- COFFAsmParser.cpp - COFF Assembly Parser ---------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/MC/MCParser/MCAsmParserExtension.h"
|
2011-07-25 17:55:35 +00:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2010-10-09 11:01:07 +00:00
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
|
|
#include "llvm/MC/MCContext.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2010-10-09 11:01:07 +00:00
|
|
|
#include "llvm/MC/MCParser/MCAsmLexer.h"
|
2011-07-18 20:57:22 +00:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2010-10-09 11:01:07 +00:00
|
|
|
#include "llvm/MC/MCSectionCOFF.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2011-07-26 00:24:13 +00:00
|
|
|
#include "llvm/MC/MCTargetAsmParser.h"
|
2010-10-09 11:01:07 +00:00
|
|
|
#include "llvm/Support/COFF.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class COFFAsmParser : public MCAsmParserExtension {
|
2013-01-16 00:50:52 +00:00
|
|
|
template<bool (COFFAsmParser::*HandlerMethod)(StringRef, SMLoc)>
|
2013-02-20 22:21:35 +00:00
|
|
|
void addDirectiveHandler(StringRef Directive) {
|
2013-01-16 00:50:52 +00:00
|
|
|
MCAsmParser::ExtensionDirectiveHandler Handler = std::make_pair(
|
|
|
|
this, HandleDirective<COFFAsmParser, HandlerMethod>);
|
2013-02-20 22:21:35 +00:00
|
|
|
getParser().addDirectiveHandler(Directive, Handler);
|
2010-10-09 11:01:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ParseSectionSwitch(StringRef Section,
|
|
|
|
unsigned Characteristics,
|
|
|
|
SectionKind Kind);
|
|
|
|
|
|
|
|
virtual void Initialize(MCAsmParser &Parser) {
|
|
|
|
// Call the base implementation.
|
|
|
|
MCAsmParserExtension::Initialize(Parser);
|
|
|
|
|
2013-02-20 22:21:35 +00:00
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveText>(".text");
|
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveData>(".data");
|
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveBSS>(".bss");
|
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseDirectiveDef>(".def");
|
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseDirectiveScl>(".scl");
|
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseDirectiveType>(".type");
|
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseDirectiveEndef>(".endef");
|
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseDirectiveSecRel32>(".secrel32");
|
2011-05-22 21:12:15 +00:00
|
|
|
|
|
|
|
// Win64 EH directives.
|
2013-02-20 22:21:35 +00:00
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartProc>(
|
2011-05-22 21:12:15 +00:00
|
|
|
".seh_proc");
|
2013-02-20 22:21:35 +00:00
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndProc>(
|
2011-05-22 21:12:15 +00:00
|
|
|
".seh_endproc");
|
2013-02-20 22:21:35 +00:00
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartChained>(
|
2011-05-22 21:12:15 +00:00
|
|
|
".seh_startchained");
|
2013-02-20 22:21:35 +00:00
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndChained>(
|
2011-05-22 21:12:15 +00:00
|
|
|
".seh_endchained");
|
2013-02-20 22:21:35 +00:00
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveHandler>(
|
2011-05-22 21:12:15 +00:00
|
|
|
".seh_handler");
|
2013-02-20 22:21:35 +00:00
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveHandlerData>(
|
2011-05-22 21:12:15 +00:00
|
|
|
".seh_handlerdata");
|
2013-02-20 22:21:35 +00:00
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSEHDirectivePushReg>(
|
2011-05-22 21:12:15 +00:00
|
|
|
".seh_pushreg");
|
2013-02-20 22:21:35 +00:00
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveSetFrame>(
|
2011-05-22 21:12:15 +00:00
|
|
|
".seh_setframe");
|
2013-02-20 22:21:35 +00:00
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveAllocStack>(
|
2011-05-22 21:12:15 +00:00
|
|
|
".seh_stackalloc");
|
2013-02-20 22:21:35 +00:00
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveSaveReg>(
|
2011-05-22 21:12:15 +00:00
|
|
|
".seh_savereg");
|
2013-02-20 22:21:35 +00:00
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveSaveXMM>(
|
2011-05-22 21:12:15 +00:00
|
|
|
".seh_savexmm");
|
2013-02-20 22:21:35 +00:00
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSEHDirectivePushFrame>(
|
2011-05-22 21:12:15 +00:00
|
|
|
".seh_pushframe");
|
2013-02-20 22:21:35 +00:00
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndProlog>(
|
2011-05-22 21:12:15 +00:00
|
|
|
".seh_endprologue");
|
2013-02-20 22:21:35 +00:00
|
|
|
addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymbolAttribute>(".weak");
|
2010-10-09 11:01:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ParseSectionDirectiveText(StringRef, SMLoc) {
|
|
|
|
return ParseSectionSwitch(".text",
|
|
|
|
COFF::IMAGE_SCN_CNT_CODE
|
|
|
|
| COFF::IMAGE_SCN_MEM_EXECUTE
|
|
|
|
| COFF::IMAGE_SCN_MEM_READ,
|
|
|
|
SectionKind::getText());
|
|
|
|
}
|
|
|
|
bool ParseSectionDirectiveData(StringRef, SMLoc) {
|
|
|
|
return ParseSectionSwitch(".data",
|
|
|
|
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
|
|
|
|
| COFF::IMAGE_SCN_MEM_READ
|
|
|
|
| COFF::IMAGE_SCN_MEM_WRITE,
|
|
|
|
SectionKind::getDataRel());
|
|
|
|
}
|
|
|
|
bool ParseSectionDirectiveBSS(StringRef, SMLoc) {
|
|
|
|
return ParseSectionSwitch(".bss",
|
|
|
|
COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
|
|
|
|
| COFF::IMAGE_SCN_MEM_READ
|
|
|
|
| COFF::IMAGE_SCN_MEM_WRITE,
|
|
|
|
SectionKind::getBSS());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ParseDirectiveDef(StringRef, SMLoc);
|
|
|
|
bool ParseDirectiveScl(StringRef, SMLoc);
|
|
|
|
bool ParseDirectiveType(StringRef, SMLoc);
|
|
|
|
bool ParseDirectiveEndef(StringRef, SMLoc);
|
2011-12-17 01:14:52 +00:00
|
|
|
bool ParseDirectiveSecRel32(StringRef, SMLoc);
|
2010-10-09 11:01:07 +00:00
|
|
|
|
2011-05-22 21:12:15 +00:00
|
|
|
// Win64 EH directives.
|
|
|
|
bool ParseSEHDirectiveStartProc(StringRef, SMLoc);
|
|
|
|
bool ParseSEHDirectiveEndProc(StringRef, SMLoc);
|
|
|
|
bool ParseSEHDirectiveStartChained(StringRef, SMLoc);
|
|
|
|
bool ParseSEHDirectiveEndChained(StringRef, SMLoc);
|
|
|
|
bool ParseSEHDirectiveHandler(StringRef, SMLoc);
|
|
|
|
bool ParseSEHDirectiveHandlerData(StringRef, SMLoc);
|
2011-05-24 20:06:30 +00:00
|
|
|
bool ParseSEHDirectivePushReg(StringRef, SMLoc);
|
|
|
|
bool ParseSEHDirectiveSetFrame(StringRef, SMLoc);
|
|
|
|
bool ParseSEHDirectiveAllocStack(StringRef, SMLoc);
|
|
|
|
bool ParseSEHDirectiveSaveReg(StringRef, SMLoc);
|
|
|
|
bool ParseSEHDirectiveSaveXMM(StringRef, SMLoc);
|
|
|
|
bool ParseSEHDirectivePushFrame(StringRef, SMLoc);
|
2011-05-22 21:12:15 +00:00
|
|
|
bool ParseSEHDirectiveEndProlog(StringRef, SMLoc);
|
|
|
|
|
|
|
|
bool ParseAtUnwindOrAtExcept(bool &unwind, bool &except);
|
2011-05-24 20:06:30 +00:00
|
|
|
bool ParseSEHRegisterNumber(unsigned &RegNo);
|
2011-07-25 17:55:35 +00:00
|
|
|
bool ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc);
|
2010-10-09 11:01:07 +00:00
|
|
|
public:
|
|
|
|
COFFAsmParser() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end annonomous namespace.
|
|
|
|
|
2011-07-25 17:55:35 +00:00
|
|
|
/// ParseDirectiveSymbolAttribute
|
|
|
|
/// ::= { ".weak", ... } [ identifier ( , identifier )* ]
|
|
|
|
bool COFFAsmParser::ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
|
|
|
|
MCSymbolAttr Attr = StringSwitch<MCSymbolAttr>(Directive)
|
|
|
|
.Case(".weak", MCSA_Weak)
|
|
|
|
.Default(MCSA_Invalid);
|
|
|
|
assert(Attr != MCSA_Invalid && "unexpected symbol attribute directive!");
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement)) {
|
|
|
|
for (;;) {
|
|
|
|
StringRef Name;
|
|
|
|
|
2013-02-20 22:21:35 +00:00
|
|
|
if (getParser().parseIdentifier(Name))
|
2011-07-25 17:55:35 +00:00
|
|
|
return TokError("expected identifier in directive");
|
|
|
|
|
|
|
|
MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
|
|
|
|
|
|
|
|
getStreamer().EmitSymbolAttribute(Sym, Attr);
|
|
|
|
|
|
|
|
if (getLexer().is(AsmToken::EndOfStatement))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (getLexer().isNot(AsmToken::Comma))
|
|
|
|
return TokError("unexpected token in directive");
|
|
|
|
Lex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-09 11:01:07 +00:00
|
|
|
bool COFFAsmParser::ParseSectionSwitch(StringRef Section,
|
|
|
|
unsigned Characteristics,
|
|
|
|
SectionKind Kind) {
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement))
|
|
|
|
return TokError("unexpected token in section switching directive");
|
|
|
|
Lex();
|
|
|
|
|
|
|
|
getStreamer().SwitchSection(getContext().getCOFFSection(
|
|
|
|
Section, Characteristics, Kind));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool COFFAsmParser::ParseDirectiveDef(StringRef, SMLoc) {
|
|
|
|
StringRef SymbolName;
|
|
|
|
|
2013-02-20 22:21:35 +00:00
|
|
|
if (getParser().parseIdentifier(SymbolName))
|
2010-10-09 11:01:07 +00:00
|
|
|
return TokError("expected identifier in directive");
|
|
|
|
|
|
|
|
MCSymbol *Sym = getContext().GetOrCreateSymbol(SymbolName);
|
|
|
|
|
|
|
|
getStreamer().BeginCOFFSymbolDef(Sym);
|
|
|
|
|
|
|
|
Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool COFFAsmParser::ParseDirectiveScl(StringRef, SMLoc) {
|
|
|
|
int64_t SymbolStorageClass;
|
2013-02-20 22:21:35 +00:00
|
|
|
if (getParser().parseAbsoluteExpression(SymbolStorageClass))
|
2010-10-09 11:01:07 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement))
|
|
|
|
return TokError("unexpected token in directive");
|
|
|
|
|
|
|
|
Lex();
|
|
|
|
getStreamer().EmitCOFFSymbolStorageClass(SymbolStorageClass);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool COFFAsmParser::ParseDirectiveType(StringRef, SMLoc) {
|
|
|
|
int64_t Type;
|
2013-02-20 22:21:35 +00:00
|
|
|
if (getParser().parseAbsoluteExpression(Type))
|
2010-10-09 11:01:07 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement))
|
|
|
|
return TokError("unexpected token in directive");
|
|
|
|
|
|
|
|
Lex();
|
|
|
|
getStreamer().EmitCOFFSymbolType(Type);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool COFFAsmParser::ParseDirectiveEndef(StringRef, SMLoc) {
|
|
|
|
Lex();
|
|
|
|
getStreamer().EndCOFFSymbolDef();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-17 01:14:52 +00:00
|
|
|
bool COFFAsmParser::ParseDirectiveSecRel32(StringRef, SMLoc) {
|
|
|
|
StringRef SymbolID;
|
2013-02-20 22:21:35 +00:00
|
|
|
if (getParser().parseIdentifier(SymbolID))
|
2011-12-17 01:14:52 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement))
|
|
|
|
return TokError("unexpected token in directive");
|
|
|
|
|
|
|
|
MCSymbol *Symbol = getContext().GetOrCreateSymbol(SymbolID);
|
|
|
|
|
|
|
|
Lex();
|
|
|
|
getStreamer().EmitCOFFSecRel32(Symbol);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-22 21:12:15 +00:00
|
|
|
bool COFFAsmParser::ParseSEHDirectiveStartProc(StringRef, SMLoc) {
|
2011-05-25 01:33:42 +00:00
|
|
|
StringRef SymbolID;
|
2013-02-20 22:21:35 +00:00
|
|
|
if (getParser().parseIdentifier(SymbolID))
|
2011-05-22 21:12:15 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement))
|
|
|
|
return TokError("unexpected token in directive");
|
|
|
|
|
2011-05-25 01:33:42 +00:00
|
|
|
MCSymbol *Symbol = getContext().GetOrCreateSymbol(SymbolID);
|
|
|
|
|
2011-05-22 21:12:15 +00:00
|
|
|
Lex();
|
2011-05-25 01:33:42 +00:00
|
|
|
getStreamer().EmitWin64EHStartProc(Symbol);
|
2011-05-22 21:12:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool COFFAsmParser::ParseSEHDirectiveEndProc(StringRef, SMLoc) {
|
|
|
|
Lex();
|
|
|
|
getStreamer().EmitWin64EHEndProc();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool COFFAsmParser::ParseSEHDirectiveStartChained(StringRef, SMLoc) {
|
|
|
|
Lex();
|
|
|
|
getStreamer().EmitWin64EHStartChained();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool COFFAsmParser::ParseSEHDirectiveEndChained(StringRef, SMLoc) {
|
|
|
|
Lex();
|
|
|
|
getStreamer().EmitWin64EHEndChained();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool COFFAsmParser::ParseSEHDirectiveHandler(StringRef, SMLoc) {
|
2011-05-25 01:33:42 +00:00
|
|
|
StringRef SymbolID;
|
2013-02-20 22:21:35 +00:00
|
|
|
if (getParser().parseIdentifier(SymbolID))
|
2011-05-22 21:12:15 +00:00
|
|
|
return true;
|
|
|
|
|
2011-05-25 01:33:42 +00:00
|
|
|
if (getLexer().isNot(AsmToken::Comma))
|
|
|
|
return TokError("you must specify one or both of @unwind or @except");
|
|
|
|
Lex();
|
2011-05-22 21:12:15 +00:00
|
|
|
bool unwind = false, except = false;
|
2011-05-25 01:33:42 +00:00
|
|
|
if (ParseAtUnwindOrAtExcept(unwind, except))
|
|
|
|
return true;
|
2011-05-22 21:12:15 +00:00
|
|
|
if (getLexer().is(AsmToken::Comma)) {
|
|
|
|
Lex();
|
2011-05-25 01:33:42 +00:00
|
|
|
if (ParseAtUnwindOrAtExcept(unwind, except))
|
2011-05-22 21:12:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement))
|
|
|
|
return TokError("unexpected token in directive");
|
|
|
|
|
2011-05-25 01:33:42 +00:00
|
|
|
MCSymbol *handler = getContext().GetOrCreateSymbol(SymbolID);
|
|
|
|
|
2011-05-22 21:12:15 +00:00
|
|
|
Lex();
|
2011-05-25 01:33:42 +00:00
|
|
|
getStreamer().EmitWin64EHHandler(handler, unwind, except);
|
2011-05-22 21:12:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool COFFAsmParser::ParseSEHDirectiveHandlerData(StringRef, SMLoc) {
|
|
|
|
Lex();
|
|
|
|
getStreamer().EmitWin64EHHandlerData();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool COFFAsmParser::ParseSEHDirectivePushReg(StringRef, SMLoc L) {
|
2011-05-24 20:06:30 +00:00
|
|
|
unsigned Reg;
|
|
|
|
if (ParseSEHRegisterNumber(Reg))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement))
|
|
|
|
return TokError("unexpected token in directive");
|
|
|
|
|
|
|
|
Lex();
|
|
|
|
getStreamer().EmitWin64EHPushReg(Reg);
|
|
|
|
return false;
|
2011-05-22 21:12:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool COFFAsmParser::ParseSEHDirectiveSetFrame(StringRef, SMLoc L) {
|
2011-05-24 20:06:30 +00:00
|
|
|
unsigned Reg;
|
|
|
|
int64_t Off;
|
|
|
|
if (ParseSEHRegisterNumber(Reg))
|
|
|
|
return true;
|
2011-05-25 21:43:45 +00:00
|
|
|
if (getLexer().isNot(AsmToken::Comma))
|
|
|
|
return TokError("you must specify a stack pointer offset");
|
|
|
|
|
|
|
|
Lex();
|
2011-05-24 20:06:30 +00:00
|
|
|
SMLoc startLoc = getLexer().getLoc();
|
2013-02-20 22:21:35 +00:00
|
|
|
if (getParser().parseAbsoluteExpression(Off))
|
2011-05-24 20:06:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Off & 0x0F)
|
|
|
|
return Error(startLoc, "offset is not a multiple of 16");
|
|
|
|
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement))
|
|
|
|
return TokError("unexpected token in directive");
|
|
|
|
|
|
|
|
Lex();
|
|
|
|
getStreamer().EmitWin64EHSetFrame(Reg, Off);
|
|
|
|
return false;
|
2011-05-22 21:12:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-23 16:43:09 +00:00
|
|
|
bool COFFAsmParser::ParseSEHDirectiveAllocStack(StringRef, SMLoc) {
|
|
|
|
int64_t Size;
|
2011-05-24 20:06:30 +00:00
|
|
|
SMLoc startLoc = getLexer().getLoc();
|
2013-02-20 22:21:35 +00:00
|
|
|
if (getParser().parseAbsoluteExpression(Size))
|
2011-05-23 16:43:09 +00:00
|
|
|
return true;
|
|
|
|
|
2011-05-24 20:06:30 +00:00
|
|
|
if (Size & 7)
|
|
|
|
return Error(startLoc, "size is not a multiple of 8");
|
|
|
|
|
2011-05-23 16:43:09 +00:00
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement))
|
|
|
|
return TokError("unexpected token in directive");
|
|
|
|
|
|
|
|
Lex();
|
|
|
|
getStreamer().EmitWin64EHAllocStack(Size);
|
|
|
|
return false;
|
2011-05-22 21:12:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool COFFAsmParser::ParseSEHDirectiveSaveReg(StringRef, SMLoc L) {
|
2011-05-24 20:06:30 +00:00
|
|
|
unsigned Reg;
|
|
|
|
int64_t Off;
|
|
|
|
if (ParseSEHRegisterNumber(Reg))
|
|
|
|
return true;
|
2011-05-25 04:51:25 +00:00
|
|
|
if (getLexer().isNot(AsmToken::Comma))
|
2011-05-25 21:43:45 +00:00
|
|
|
return TokError("you must specify an offset on the stack");
|
2011-05-25 04:51:25 +00:00
|
|
|
|
|
|
|
Lex();
|
2011-05-24 20:06:30 +00:00
|
|
|
SMLoc startLoc = getLexer().getLoc();
|
2013-02-20 22:21:35 +00:00
|
|
|
if (getParser().parseAbsoluteExpression(Off))
|
2011-05-24 20:06:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Off & 7)
|
|
|
|
return Error(startLoc, "size is not a multiple of 8");
|
|
|
|
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement))
|
|
|
|
return TokError("unexpected token in directive");
|
|
|
|
|
|
|
|
Lex();
|
|
|
|
// FIXME: Err on %xmm* registers
|
|
|
|
getStreamer().EmitWin64EHSaveReg(Reg, Off);
|
|
|
|
return false;
|
2011-05-22 21:12:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-24 20:06:30 +00:00
|
|
|
// FIXME: This method is inherently x86-specific. It should really be in the
|
|
|
|
// x86 backend.
|
2011-05-22 21:12:15 +00:00
|
|
|
bool COFFAsmParser::ParseSEHDirectiveSaveXMM(StringRef, SMLoc L) {
|
2011-05-24 20:06:30 +00:00
|
|
|
unsigned Reg;
|
|
|
|
int64_t Off;
|
|
|
|
if (ParseSEHRegisterNumber(Reg))
|
|
|
|
return true;
|
2011-05-25 04:51:25 +00:00
|
|
|
if (getLexer().isNot(AsmToken::Comma))
|
2011-05-25 21:43:45 +00:00
|
|
|
return TokError("you must specify an offset on the stack");
|
2011-05-25 04:51:25 +00:00
|
|
|
|
|
|
|
Lex();
|
2011-05-24 20:06:30 +00:00
|
|
|
SMLoc startLoc = getLexer().getLoc();
|
2013-02-20 22:21:35 +00:00
|
|
|
if (getParser().parseAbsoluteExpression(Off))
|
2011-05-24 20:06:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement))
|
|
|
|
return TokError("unexpected token in directive");
|
|
|
|
|
|
|
|
if (Off & 0x0F)
|
|
|
|
return Error(startLoc, "offset is not a multiple of 16");
|
|
|
|
|
|
|
|
Lex();
|
|
|
|
// FIXME: Err on non-%xmm* registers
|
|
|
|
getStreamer().EmitWin64EHSaveXMM(Reg, Off);
|
|
|
|
return false;
|
2011-05-22 21:12:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-23 16:43:09 +00:00
|
|
|
bool COFFAsmParser::ParseSEHDirectivePushFrame(StringRef, SMLoc) {
|
2011-05-25 04:08:15 +00:00
|
|
|
bool Code = false;
|
2011-05-23 16:43:09 +00:00
|
|
|
StringRef CodeID;
|
2011-05-25 04:08:15 +00:00
|
|
|
if (getLexer().is(AsmToken::At)) {
|
|
|
|
SMLoc startLoc = getLexer().getLoc();
|
|
|
|
Lex();
|
2013-02-20 22:21:35 +00:00
|
|
|
if (!getParser().parseIdentifier(CodeID)) {
|
2011-05-25 04:08:15 +00:00
|
|
|
if (CodeID != "code")
|
|
|
|
return Error(startLoc, "expected @code");
|
|
|
|
Code = true;
|
|
|
|
}
|
2011-05-23 16:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement))
|
|
|
|
return TokError("unexpected token in directive");
|
|
|
|
|
|
|
|
Lex();
|
|
|
|
getStreamer().EmitWin64EHPushFrame(Code);
|
|
|
|
return false;
|
2011-05-22 21:12:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool COFFAsmParser::ParseSEHDirectiveEndProlog(StringRef, SMLoc) {
|
|
|
|
Lex();
|
|
|
|
getStreamer().EmitWin64EHEndProlog();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool COFFAsmParser::ParseAtUnwindOrAtExcept(bool &unwind, bool &except) {
|
|
|
|
StringRef identifier;
|
2011-05-25 01:33:42 +00:00
|
|
|
if (getLexer().isNot(AsmToken::At))
|
|
|
|
return TokError("a handler attribute must begin with '@'");
|
2011-05-22 21:12:15 +00:00
|
|
|
SMLoc startLoc = getLexer().getLoc();
|
2011-05-25 01:33:42 +00:00
|
|
|
Lex();
|
2013-02-20 22:21:35 +00:00
|
|
|
if (getParser().parseIdentifier(identifier))
|
2011-05-22 21:12:15 +00:00
|
|
|
return Error(startLoc, "expected @unwind or @except");
|
2011-05-25 01:33:42 +00:00
|
|
|
if (identifier == "unwind")
|
2011-05-22 21:12:15 +00:00
|
|
|
unwind = true;
|
2011-05-25 01:33:42 +00:00
|
|
|
else if (identifier == "except")
|
2011-05-22 21:12:15 +00:00
|
|
|
except = true;
|
|
|
|
else
|
|
|
|
return Error(startLoc, "expected @unwind or @except");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-24 20:06:30 +00:00
|
|
|
bool COFFAsmParser::ParseSEHRegisterNumber(unsigned &RegNo) {
|
|
|
|
SMLoc startLoc = getLexer().getLoc();
|
2011-05-25 04:51:25 +00:00
|
|
|
if (getLexer().is(AsmToken::Percent)) {
|
2011-07-18 20:57:22 +00:00
|
|
|
const MCRegisterInfo &MRI = getContext().getRegisterInfo();
|
2011-05-24 20:06:30 +00:00
|
|
|
SMLoc endLoc;
|
|
|
|
unsigned LLVMRegNo;
|
|
|
|
if (getParser().getTargetParser().ParseRegister(LLVMRegNo,startLoc,endLoc))
|
2011-05-25 04:51:25 +00:00
|
|
|
return true;
|
2011-05-24 20:06:30 +00:00
|
|
|
|
2011-07-18 20:57:22 +00:00
|
|
|
#if 0
|
|
|
|
// FIXME: TargetAsmInfo::getCalleeSavedRegs() commits a serious layering
|
|
|
|
// violation so this validation code is disabled.
|
|
|
|
|
2011-05-24 20:06:30 +00:00
|
|
|
// Check that this is a non-volatile register.
|
2011-07-15 02:09:41 +00:00
|
|
|
const unsigned *NVRegs = TAI.getCalleeSavedRegs();
|
2011-05-24 20:06:30 +00:00
|
|
|
unsigned i;
|
|
|
|
for (i = 0; NVRegs[i] != 0; ++i)
|
|
|
|
if (NVRegs[i] == LLVMRegNo)
|
|
|
|
break;
|
|
|
|
if (NVRegs[i] == 0)
|
|
|
|
return Error(startLoc, "expected non-volatile register");
|
2011-07-18 20:57:22 +00:00
|
|
|
#endif
|
2011-05-24 20:06:30 +00:00
|
|
|
|
2011-07-18 20:57:22 +00:00
|
|
|
int SEHRegNo = MRI.getSEHRegNum(LLVMRegNo);
|
2011-05-24 20:06:30 +00:00
|
|
|
if (SEHRegNo < 0)
|
|
|
|
return Error(startLoc,"register can't be represented in SEH unwind info");
|
|
|
|
RegNo = SEHRegNo;
|
|
|
|
}
|
2011-05-25 04:51:25 +00:00
|
|
|
else {
|
|
|
|
int64_t n;
|
2013-02-20 22:21:35 +00:00
|
|
|
if (getParser().parseAbsoluteExpression(n))
|
2011-05-25 04:51:25 +00:00
|
|
|
return true;
|
|
|
|
if (n > 15)
|
|
|
|
return Error(startLoc, "register number is too high");
|
2011-05-24 20:06:30 +00:00
|
|
|
RegNo = n;
|
2011-05-25 04:51:25 +00:00
|
|
|
}
|
2011-05-24 20:06:30 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-09 11:01:07 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
MCAsmParserExtension *createCOFFAsmParser() {
|
|
|
|
return new COFFAsmParser;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|