#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCCodeView.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDirectives.h"
#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCParser/AsmCond.h"
#include "llvm/MC/MCParser/AsmLexer.h"
#include "llvm/MC/MCParser/MCAsmLexer.h"
#include "llvm/MC/MCParser/MCAsmParser.h"
#include "llvm/MC/MCParser/MCAsmParserExtension.h"
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
#include "llvm/MC/MCParser/MCTargetAsmParser.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/SMLoc.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstddef>
#include <cstdint>
#include <ctime>
#include <deque>
#include <memory>
#include <optional>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
usingnamespacellvm;
namespace {
MCAsmMacroArgument;
MCAsmMacroArguments;
struct MacroInstantiation { … };
struct ParseStatementInfo { … };
enum FieldType { … };
struct FieldInfo;
struct StructInfo { … };
struct StructInitializer;
struct IntFieldInfo { … };
struct RealFieldInfo { … };
struct StructFieldInfo { … };
class FieldInitializer { … };
struct StructInitializer { … };
struct FieldInfo { … };
StructFieldInfo::StructFieldInfo(std::vector<StructInitializer> V,
StructInfo S) { … }
StructInfo::StructInfo(StringRef StructName, bool Union,
unsigned AlignmentValue)
: … { … }
FieldInfo &StructInfo::addField(StringRef FieldName, FieldType FT,
unsigned FieldAlignmentSize) { … }
FieldInitializer::~FieldInitializer() { … }
FieldInitializer::FieldInitializer(FieldType FT) : … { … }
FieldInitializer::FieldInitializer(SmallVector<const MCExpr *, 1> &&Values)
: … { … }
FieldInitializer::FieldInitializer(SmallVector<APInt, 1> &&AsIntValues)
: … { … }
FieldInitializer::FieldInitializer(
std::vector<StructInitializer> &&Initializers, struct StructInfo Structure)
: … { … }
FieldInitializer::FieldInitializer(const FieldInitializer &Initializer)
: … { … }
FieldInitializer::FieldInitializer(FieldInitializer &&Initializer)
: … { … }
FieldInitializer &
FieldInitializer::operator=(const FieldInitializer &Initializer) { … }
FieldInitializer &FieldInitializer::operator=(FieldInitializer &&Initializer) { … }
class MasmParser : public MCAsmParser { … };
}
namespace llvm {
extern cl::opt<unsigned> AsmMacroMaxNestingDepth;
extern MCAsmParserExtension *createCOFFMasmParser();
}
enum { … };
MasmParser::MasmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
const MCAsmInfo &MAI, struct tm TM, unsigned CB)
: … { … }
MasmParser::~MasmParser() { … }
void MasmParser::printMacroInstantiations() { … }
void MasmParser::Note(SMLoc L, const Twine &Msg, SMRange Range) { … }
bool MasmParser::Warning(SMLoc L, const Twine &Msg, SMRange Range) { … }
bool MasmParser::printError(SMLoc L, const Twine &Msg, SMRange Range) { … }
bool MasmParser::enterIncludeFile(const std::string &Filename) { … }
void MasmParser::jumpToLoc(SMLoc Loc, unsigned InBuffer,
bool EndStatementAtEOF) { … }
bool MasmParser::expandMacros() { … }
const AsmToken &MasmParser::Lex(ExpandKind ExpandNextToken) { … }
const AsmToken MasmParser::peekTok(bool ShouldSkipSpace) { … }
bool MasmParser::enabledGenDwarfForAssembly() { … }
bool MasmParser::Run(bool NoInitialTextSection, bool NoFinalize) { … }
bool MasmParser::checkForValidSection() { … }
void MasmParser::eatToEndOfStatement() { … }
SmallVector<StringRef, 1>
MasmParser::parseStringRefsTo(AsmToken::TokenKind EndTok) { … }
std::string MasmParser::parseStringTo(AsmToken::TokenKind EndTok) { … }
StringRef MasmParser::parseStringToEndOfStatement() { … }
bool MasmParser::parseParenExpr(const MCExpr *&Res, SMLoc &EndLoc) { … }
bool MasmParser::parseBracketExpr(const MCExpr *&Res, SMLoc &EndLoc) { … }
bool MasmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc,
AsmTypeInfo *TypeInfo) { … }
bool MasmParser::parseExpression(const MCExpr *&Res) { … }
static bool isAngleBracketString(SMLoc &StrLoc, SMLoc &EndLoc) { … }
static std::string angleBracketString(StringRef BracketContents) { … }
bool MasmParser::parseExpression(const MCExpr *&Res, SMLoc &EndLoc) { … }
bool MasmParser::parseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) { … }
bool MasmParser::parseParenExprOfDepth(unsigned ParenDepth, const MCExpr *&Res,
SMLoc &EndLoc) { … }
bool MasmParser::parseAbsoluteExpression(int64_t &Res) { … }
static unsigned getGNUBinOpPrecedence(AsmToken::TokenKind K,
MCBinaryExpr::Opcode &Kind,
bool ShouldUseLogicalShr,
bool EndExpressionAtGreater) { … }
unsigned MasmParser::getBinOpPrecedence(AsmToken::TokenKind K,
MCBinaryExpr::Opcode &Kind) { … }
bool MasmParser::parseBinOpRHS(unsigned Precedence, const MCExpr *&Res,
SMLoc &EndLoc) { … }
bool MasmParser::parseStatement(ParseStatementInfo &Info,
MCAsmParserSemaCallback *SI) { … }
bool MasmParser::parseCurlyBlockScope(
SmallVectorImpl<AsmRewrite> &AsmStrRewrites) { … }
bool MasmParser::parseCppHashLineFilenameComment(SMLoc L) { … }
void MasmParser::DiagHandler(const SMDiagnostic &Diag, void *Context) { … }
static bool isMacroParameterChar(char C) { … }
bool MasmParser::expandMacro(raw_svector_ostream &OS, StringRef Body,
ArrayRef<MCAsmMacroParameter> Parameters,
ArrayRef<MCAsmMacroArgument> A,
const std::vector<std::string> &Locals, SMLoc L) { … }
static bool isOperator(AsmToken::TokenKind kind) { … }
namespace {
class AsmLexerSkipSpaceRAII { … };
}
bool MasmParser::parseMacroArgument(const MCAsmMacroParameter *MP,
MCAsmMacroArgument &MA,
AsmToken::TokenKind EndTok) { … }
bool MasmParser::parseMacroArguments(const MCAsmMacro *M,
MCAsmMacroArguments &A,
AsmToken::TokenKind EndTok) { … }
bool MasmParser::handleMacroEntry(const MCAsmMacro *M, SMLoc NameLoc,
AsmToken::TokenKind ArgumentEndTok) { … }
void MasmParser::handleMacroExit() { … }
bool MasmParser::handleMacroInvocation(const MCAsmMacro *M, SMLoc NameLoc) { … }
bool MasmParser::parseIdentifier(StringRef &Res,
IdentifierPositionKind Position) { … }
bool MasmParser::parseDirectiveEquate(StringRef IDVal, StringRef Name,
DirectiveKind DirKind, SMLoc NameLoc) { … }
bool MasmParser::parseEscapedString(std::string &Data) { … }
bool MasmParser::parseAngleBracketString(std::string &Data) { … }
bool MasmParser::parseTextItem(std::string &Data) { … }
bool MasmParser::parseDirectiveAscii(StringRef IDVal, bool ZeroTerminated) { … }
bool MasmParser::emitIntValue(const MCExpr *Value, unsigned Size) { … }
bool MasmParser::parseScalarInitializer(unsigned Size,
SmallVectorImpl<const MCExpr *> &Values,
unsigned StringPadLength) { … }
bool MasmParser::parseScalarInstList(unsigned Size,
SmallVectorImpl<const MCExpr *> &Values,
const AsmToken::TokenKind EndToken) { … }
bool MasmParser::emitIntegralValues(unsigned Size, unsigned *Count) { … }
bool MasmParser::addIntegralField(StringRef Name, unsigned Size) { … }
bool MasmParser::parseDirectiveValue(StringRef IDVal, unsigned Size) { … }
bool MasmParser::parseDirectiveNamedValue(StringRef TypeName, unsigned Size,
StringRef Name, SMLoc NameLoc) { … }
static bool parseHexOcta(MasmParser &Asm, uint64_t &hi, uint64_t &lo) { … }
bool MasmParser::parseRealValue(const fltSemantics &Semantics, APInt &Res) { … }
bool MasmParser::parseRealInstList(const fltSemantics &Semantics,
SmallVectorImpl<APInt> &ValuesAsInt,
const AsmToken::TokenKind EndToken) { … }
bool MasmParser::emitRealValues(const fltSemantics &Semantics,
unsigned *Count) { … }
bool MasmParser::addRealField(StringRef Name, const fltSemantics &Semantics,
size_t Size) { … }
bool MasmParser::parseDirectiveRealValue(StringRef IDVal,
const fltSemantics &Semantics,
size_t Size) { … }
bool MasmParser::parseDirectiveNamedRealValue(StringRef TypeName,
const fltSemantics &Semantics,
unsigned Size, StringRef Name,
SMLoc NameLoc) { … }
bool MasmParser::parseOptionalAngleBracketOpen() { … }
bool MasmParser::parseAngleBracketClose(const Twine &Msg) { … }
bool MasmParser::parseFieldInitializer(const FieldInfo &Field,
const IntFieldInfo &Contents,
FieldInitializer &Initializer) { … }
bool MasmParser::parseFieldInitializer(const FieldInfo &Field,
const RealFieldInfo &Contents,
FieldInitializer &Initializer) { … }
bool MasmParser::parseFieldInitializer(const FieldInfo &Field,
const StructFieldInfo &Contents,
FieldInitializer &Initializer) { … }
bool MasmParser::parseFieldInitializer(const FieldInfo &Field,
FieldInitializer &Initializer) { … }
bool MasmParser::parseStructInitializer(const StructInfo &Structure,
StructInitializer &Initializer) { … }
bool MasmParser::parseStructInstList(
const StructInfo &Structure, std::vector<StructInitializer> &Initializers,
const AsmToken::TokenKind EndToken) { … }
bool MasmParser::emitFieldValue(const FieldInfo &Field,
const IntFieldInfo &Contents) { … }
bool MasmParser::emitFieldValue(const FieldInfo &Field,
const RealFieldInfo &Contents) { … }
bool MasmParser::emitFieldValue(const FieldInfo &Field,
const StructFieldInfo &Contents) { … }
bool MasmParser::emitFieldValue(const FieldInfo &Field) { … }
bool MasmParser::emitFieldInitializer(const FieldInfo &Field,
const IntFieldInfo &Contents,
const IntFieldInfo &Initializer) { … }
bool MasmParser::emitFieldInitializer(const FieldInfo &Field,
const RealFieldInfo &Contents,
const RealFieldInfo &Initializer) { … }
bool MasmParser::emitFieldInitializer(const FieldInfo &Field,
const StructFieldInfo &Contents,
const StructFieldInfo &Initializer) { … }
bool MasmParser::emitFieldInitializer(const FieldInfo &Field,
const FieldInitializer &Initializer) { … }
bool MasmParser::emitStructInitializer(const StructInfo &Structure,
const StructInitializer &Initializer) { … }
bool MasmParser::emitStructValues(const StructInfo &Structure,
unsigned *Count) { … }
bool MasmParser::addStructField(StringRef Name, const StructInfo &Structure) { … }
bool MasmParser::parseDirectiveStructValue(const StructInfo &Structure,
StringRef Directive, SMLoc DirLoc) { … }
bool MasmParser::parseDirectiveNamedStructValue(const StructInfo &Structure,
StringRef Directive,
SMLoc DirLoc, StringRef Name) { … }
bool MasmParser::parseDirectiveStruct(StringRef Directive,
DirectiveKind DirKind, StringRef Name,
SMLoc NameLoc) { … }
bool MasmParser::parseDirectiveNestedStruct(StringRef Directive,
DirectiveKind DirKind) { … }
bool MasmParser::parseDirectiveEnds(StringRef Name, SMLoc NameLoc) { … }
bool MasmParser::parseDirectiveNestedEnds() { … }
bool MasmParser::parseDirectiveOrg() { … }
bool MasmParser::emitAlignTo(int64_t Alignment) { … }
bool MasmParser::parseDirectiveAlign() { … }
bool MasmParser::parseDirectiveEven() { … }
bool MasmParser::parseDirectiveFile(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveLine() { … }
bool MasmParser::parseDirectiveLoc() { … }
bool MasmParser::parseDirectiveStabs() { … }
bool MasmParser::parseDirectiveCVFile() { … }
bool MasmParser::parseCVFunctionId(int64_t &FunctionId,
StringRef DirectiveName) { … }
bool MasmParser::parseCVFileId(int64_t &FileNumber, StringRef DirectiveName) { … }
bool MasmParser::parseDirectiveCVFuncId() { … }
bool MasmParser::parseDirectiveCVInlineSiteId() { … }
bool MasmParser::parseDirectiveCVLoc() { … }
bool MasmParser::parseDirectiveCVLinetable() { … }
bool MasmParser::parseDirectiveCVInlineLinetable() { … }
void MasmParser::initializeCVDefRangeTypeMap() { … }
bool MasmParser::parseDirectiveCVDefRange() { … }
bool MasmParser::parseDirectiveCVString() { … }
bool MasmParser::parseDirectiveCVStringTable() { … }
bool MasmParser::parseDirectiveCVFileChecksums() { … }
bool MasmParser::parseDirectiveCVFileChecksumOffset() { … }
bool MasmParser::parseDirectiveCVFPOData() { … }
bool MasmParser::parseDirectiveCFISections() { … }
bool MasmParser::parseDirectiveCFIStartProc() { … }
bool MasmParser::parseDirectiveCFIEndProc() { … }
bool MasmParser::parseRegisterOrRegisterNumber(int64_t &Register,
SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveCFIDefCfa(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveCFIRegister(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveCFIWindowSave(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveCFIOffset(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveCFIRelOffset(SMLoc DirectiveLoc) { … }
static bool isValidEncoding(int64_t Encoding) { … }
bool MasmParser::parseDirectiveCFIPersonalityOrLsda(bool IsPersonality) { … }
bool MasmParser::parseDirectiveCFIRememberState(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveCFIRestoreState(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveCFISameValue(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveCFIRestore(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveCFIEscape(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveCFISignalFrame() { … }
bool MasmParser::parseDirectiveCFIUndefined(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveMacro(StringRef Name, SMLoc NameLoc) { … }
bool MasmParser::parseDirectiveExitMacro(SMLoc DirectiveLoc,
StringRef Directive,
std::string &Value) { … }
bool MasmParser::parseDirectiveEndMacro(StringRef Directive) { … }
bool MasmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveExtern() { … }
bool MasmParser::parseDirectiveSymbolAttribute(MCSymbolAttr Attr) { … }
bool MasmParser::parseDirectiveComm(bool IsLocal) { … }
bool MasmParser::parseDirectiveComment(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveInclude() { … }
bool MasmParser::parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind) { … }
bool MasmParser::parseDirectiveIfb(SMLoc DirectiveLoc, bool ExpectBlank) { … }
bool MasmParser::parseDirectiveIfidn(SMLoc DirectiveLoc, bool ExpectEqual,
bool CaseInsensitive) { … }
bool MasmParser::parseDirectiveIfdef(SMLoc DirectiveLoc, bool expect_defined) { … }
bool MasmParser::parseDirectiveElseIf(SMLoc DirectiveLoc,
DirectiveKind DirKind) { … }
bool MasmParser::parseDirectiveElseIfb(SMLoc DirectiveLoc, bool ExpectBlank) { … }
bool MasmParser::parseDirectiveElseIfdef(SMLoc DirectiveLoc,
bool expect_defined) { … }
bool MasmParser::parseDirectiveElseIfidn(SMLoc DirectiveLoc, bool ExpectEqual,
bool CaseInsensitive) { … }
bool MasmParser::parseDirectiveElse(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveEnd(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveError(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveErrorIfb(SMLoc DirectiveLoc, bool ExpectBlank) { … }
bool MasmParser::parseDirectiveErrorIfdef(SMLoc DirectiveLoc,
bool ExpectDefined) { … }
bool MasmParser::parseDirectiveErrorIfidn(SMLoc DirectiveLoc, bool ExpectEqual,
bool CaseInsensitive) { … }
bool MasmParser::parseDirectiveErrorIfe(SMLoc DirectiveLoc, bool ExpectZero) { … }
bool MasmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) { … }
void MasmParser::initializeDirectiveKindMap() { … }
bool MasmParser::isMacroLikeDirective() { … }
MCAsmMacro *MasmParser::parseMacroLikeBody(SMLoc DirectiveLoc) { … }
bool MasmParser::expandStatement(SMLoc Loc) { … }
void MasmParser::instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
raw_svector_ostream &OS) { … }
void MasmParser::instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
SMLoc ExitLoc,
raw_svector_ostream &OS) { … }
bool MasmParser::parseDirectiveRepeat(SMLoc DirectiveLoc, StringRef Dir) { … }
bool MasmParser::parseDirectiveWhile(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveFor(SMLoc DirectiveLoc, StringRef Dir) { … }
bool MasmParser::parseDirectiveForc(SMLoc DirectiveLoc, StringRef Directive) { … }
bool MasmParser::parseDirectiveMSEmit(SMLoc IDLoc, ParseStatementInfo &Info,
size_t Len) { … }
bool MasmParser::parseDirectiveMSAlign(SMLoc IDLoc, ParseStatementInfo &Info) { … }
bool MasmParser::parseDirectiveRadix(SMLoc DirectiveLoc) { … }
bool MasmParser::parseDirectiveEcho(SMLoc DirectiveLoc) { … }
static int rewritesSort(const AsmRewrite *AsmRewriteA,
const AsmRewrite *AsmRewriteB) { … }
bool MasmParser::defineMacro(StringRef Name, StringRef Value) { … }
bool MasmParser::lookUpField(StringRef Name, AsmFieldInfo &Info) const { … }
bool MasmParser::lookUpField(StringRef Base, StringRef Member,
AsmFieldInfo &Info) const { … }
bool MasmParser::lookUpField(const StructInfo &Structure, StringRef Member,
AsmFieldInfo &Info) const { … }
bool MasmParser::lookUpType(StringRef Name, AsmTypeInfo &Info) const { … }
bool MasmParser::parseMSInlineAsm(
std::string &AsmString, unsigned &NumOutputs, unsigned &NumInputs,
SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
SmallVectorImpl<std::string> &Constraints,
SmallVectorImpl<std::string> &Clobbers, const MCInstrInfo *MII,
const MCInstPrinter *IP, MCAsmParserSemaCallback &SI) { … }
void MasmParser::initializeBuiltinSymbolMap() { … }
const MCExpr *MasmParser::evaluateBuiltinValue(BuiltinSymbol Symbol,
SMLoc StartLoc) { … }
std::optional<std::string>
MasmParser::evaluateBuiltinTextMacro(BuiltinSymbol Symbol, SMLoc StartLoc) { … }
MCAsmParser *llvm::createMCMasmParser(SourceMgr &SM, MCContext &C,
MCStreamer &Out, const MCAsmInfo &MAI,
struct tm TM, unsigned CB) { … }