[PATCH] D84900: [X86] Parse and ignore .arch directivesWe parse .arch so that some `.arch i386; .code32` code can assemble. It seemsthat X86AsmParser does not do a good job tracking what features are needed toassemble instructions. So we simply ignore .arch...
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 29 17:34:47 PDT 2020
MaskRay created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
MaskRay requested review of this revision.
...for now.
craig.topper, echristo, RKSimon
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D84900
Files:
llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
llvm/test/MC/X86/directive-arch.s
Index: llvm/test/MC/X86/directive-arch.s
===================================================================
--- /dev/null
+++ llvm/test/MC/X86/directive-arch.s
@@ -0,0 +1,11 @@
+## We currently parse but ignore .arch directives.
+# RUN: llvm-mc -triple=x86_64 %s | FileCheck /dev/null --implicit-check-not=.arch
+# RUN: not llvm-mc -triple=x86_64 --defsym=ERR=1 %s 2>&1 | FileCheck %s --check-prefix=ERR
+
+.arch i386
+retq
+
+.ifdef ERR
+# ERR: {{.*}}.s:[[#@LINE+1]]:7: error: unknown arch name
+.arch unknown
+.endif
Index: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
===================================================================
--- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -34,6 +34,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetRegistry.h"
+#include "llvm/Support/X86TargetParser.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <memory>
@@ -939,6 +940,7 @@
SMLoc End, unsigned Size, StringRef Identifier,
const InlineAsmIdentifierInfo &Info);
+ bool parseDirectiveArch();
bool parseDirectiveEven(SMLoc L);
bool ParseDirectiveCode(StringRef IDVal, SMLoc L);
@@ -3973,6 +3975,8 @@
bool X86AsmParser::ParseDirective(AsmToken DirectiveID) {
MCAsmParser &Parser = getParser();
StringRef IDVal = DirectiveID.getIdentifier();
+ if (IDVal.startswith(".arch"))
+ return parseDirectiveArch();
if (IDVal.startswith(".code"))
return ParseDirectiveCode(IDVal, DirectiveID.getLoc());
else if (IDVal.startswith(".att_syntax")) {
@@ -4027,6 +4031,15 @@
return true;
}
+bool X86AsmParser::parseDirectiveArch() {
+ SMLoc Loc = getTok().getLoc();
+ StringRef CPU = getParser().parseStringToEndOfStatement().trim();
+ X86::CPUKind Kind = X86::parseArchX86(CPU);
+ if (Kind == X86::CK_None)
+ return Error(Loc, "unknown arch name");
+ return false;
+}
+
/// parseDirectiveEven
/// ::= .even
bool X86AsmParser::parseDirectiveEven(SMLoc L) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84900.281771.patch
Type: text/x-patch
Size: 2090 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200730/6a2ad1be/attachment.bin>
More information about the llvm-commits
mailing list