[llvm] bf64210 - [AIX] Add dummy XCOFF MCAsmParserExtension
Jinsong Ji via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 2 09:12:33 PDT 2021
Author: Jinsong Ji
Date: 2021-07-02T16:12:21Z
New Revision: bf64210fd88f4f3fe920376861b418be1834add6
URL: https://github.com/llvm/llvm-project/commit/bf64210fd88f4f3fe920376861b418be1834add6
DIFF: https://github.com/llvm/llvm-project/commit/bf64210fd88f4f3fe920376861b418be1834add6.diff
LOG: [AIX] Add dummy XCOFF MCAsmParserExtension
Implement XCOFFMCAsmParser so that we can use MC to parse inline asm.
The directives and storage mapping classes will be added later
iteratively.
Reviewed By: xgupta
Differential Revision: https://reviews.llvm.org/D105259
Added:
llvm/lib/MC/MCParser/XCOFFAsmParser.cpp
llvm/test/MC/XCOFF/inlineasm.s
llvm/test/MC/XCOFF/lit.local.cfg
Modified:
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/lib/MC/MCParser/CMakeLists.txt
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 1adde169c0a16..3bc668e699cbc 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -749,6 +749,7 @@ namespace llvm {
extern MCAsmParserExtension *createDarwinAsmParser();
extern MCAsmParserExtension *createELFAsmParser();
extern MCAsmParserExtension *createCOFFAsmParser();
+extern MCAsmParserExtension *createXCOFFAsmParser();
extern MCAsmParserExtension *createWasmAsmParser();
} // end namespace llvm
@@ -785,8 +786,7 @@ AsmParser::AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
PlatformParser.reset(createWasmAsmParser());
break;
case MCContext::IsXCOFF:
- report_fatal_error(
- "Need to implement createXCOFFAsmParser for XCOFF format.");
+ PlatformParser.reset(createXCOFFAsmParser());
break;
}
diff --git a/llvm/lib/MC/MCParser/CMakeLists.txt b/llvm/lib/MC/MCParser/CMakeLists.txt
index 6f76f368a9699..f70787ad9d20e 100644
--- a/llvm/lib/MC/MCParser/CMakeLists.txt
+++ b/llvm/lib/MC/MCParser/CMakeLists.txt
@@ -11,6 +11,7 @@ add_llvm_component_library(LLVMMCParser
MCTargetAsmParser.cpp
MasmParser.cpp
WasmAsmParser.cpp
+ XCOFFAsmParser.cpp
ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/MC/MCParser
diff --git a/llvm/lib/MC/MCParser/XCOFFAsmParser.cpp b/llvm/lib/MC/MCParser/XCOFFAsmParser.cpp
new file mode 100644
index 0000000000000..7494fe07734c4
--- /dev/null
+++ b/llvm/lib/MC/MCParser/XCOFFAsmParser.cpp
@@ -0,0 +1,63 @@
+//===- XCOFFAsmParser.cpp - XCOFF Assembly Parser
+//-----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/BinaryFormat/XCOFF.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCParser/MCAsmLexer.h"
+#include "llvm/MC/MCParser/MCAsmParser.h"
+#include "llvm/MC/MCParser/MCAsmParserExtension.h"
+#include "llvm/MC/MCSectionXCOFF.h"
+#include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolXCOFF.h"
+#include "llvm/Support/MachineValueType.h"
+
+using namespace llvm;
+
+namespace {
+
+class XCOFFAsmParser : public MCAsmParserExtension {
+ MCAsmParser *Parser = nullptr;
+ MCAsmLexer *Lexer = nullptr;
+
+ template <bool (XCOFFAsmParser::*HandlerMethod)(StringRef, SMLoc)>
+ void addDirectiveHandler(StringRef Directive) {
+ MCAsmParser::ExtensionDirectiveHandler Handler =
+ std::make_pair(this, HandleDirective<XCOFFAsmParser, HandlerMethod>);
+
+ getParser().addDirectiveHandler(Directive, Handler);
+ }
+
+public:
+ XCOFFAsmParser() {}
+
+ void Initialize(MCAsmParser &P) override {
+ Parser = &P;
+ Lexer = &Parser->getLexer();
+ // Call the base implementation.
+ MCAsmParserExtension::Initialize(*Parser);
+
+ addDirectiveHandler<&XCOFFAsmParser::ParseDirectiveCSect>(".csect");
+ }
+ bool ParseDirectiveCSect(StringRef, SMLoc);
+};
+
+} // end anonymous namespace
+
+namespace llvm {
+
+MCAsmParserExtension *createXCOFFAsmParser() { return new XCOFFAsmParser; }
+
+} // end namespace llvm
+
+// .csect QualName [, Number ]
+bool XCOFFAsmParser::ParseDirectiveCSect(StringRef, SMLoc) {
+ report_fatal_error("XCOFFAsmParser directive not yet supported!");
+ return false;
+}
diff --git a/llvm/test/MC/XCOFF/inlineasm.s b/llvm/test/MC/XCOFF/inlineasm.s
new file mode 100644
index 0000000000000..85a40024711a1
--- /dev/null
+++ b/llvm/test/MC/XCOFF/inlineasm.s
@@ -0,0 +1,23 @@
+// RUN: llvm-mc -filetype=asm -triple powerpc-ibm-aix-xcoff %s | FileCheck %s
+
+// CHECK-label: .csect .text[PR],2
+// CHECK:L..tmp0:
+// CHECK-NEXT: lwarx 3, 0, 4
+// CHECK-NEXT: cmpw 5, 3
+// CHECK-NEXT: bne- 0, L..tmp1
+// CHECK-NEXT: stwcx. 6, 0, 4
+// CHECK-NEXT: bne- 0, L..tmp0
+// CHECK-NEXT:L..tmp1:
+
+
+ #APP
+1:
+ lwarx 3, 0, 4
+ cmpw 5, 3
+ bne- 2f
+ stwcx. 6, 0, 4
+ bne- 1b
+2:
+
+ #NO_APP
+
diff --git a/llvm/test/MC/XCOFF/lit.local.cfg b/llvm/test/MC/XCOFF/lit.local.cfg
new file mode 100644
index 0000000000000..091332439b186
--- /dev/null
+++ b/llvm/test/MC/XCOFF/lit.local.cfg
@@ -0,0 +1,2 @@
+if not 'PowerPC' in config.root.targets:
+ config.unsupported = True
More information about the llvm-commits
mailing list