[llvm-commits] [llvm] r81817 - in /llvm/trunk: lib/Target/ARM/AsmParser/ lib/Target/ARM/AsmParser/ARMAsmParser.cpp lib/Target/ARM/AsmParser/CMakeLists.txt lib/Target/ARM/AsmParser/Makefile lib/Target/ARM/Makefile test/MC/AsmParser/arm_word_directive.s test/MC/AsmParser/directive_values.s test/MC/AsmParser/x86_word_directive.s

Kevin Enderby enderby at apple.com
Mon Sep 14 17:27:26 PDT 2009


Author: enderby
Date: Mon Sep 14 19:27:25 2009
New Revision: 81817

URL: http://llvm.org/viewvc/llvm-project?rev=81817&view=rev
Log:
Added the first bits of the ARM target assembler to llvm-mc.  For now it only
parses the .word directive as 4 bytes and ARMAsmParser::ParseInstruction will
give an error is called.  Broke out the test of the .word directive into two
different test cases, one for x86 and one for arm.

Added:
    llvm/trunk/lib/Target/ARM/AsmParser/
    llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
    llvm/trunk/lib/Target/ARM/AsmParser/CMakeLists.txt
    llvm/trunk/lib/Target/ARM/AsmParser/Makefile
    llvm/trunk/test/MC/AsmParser/arm_word_directive.s
    llvm/trunk/test/MC/AsmParser/x86_word_directive.s
Modified:
    llvm/trunk/lib/Target/ARM/Makefile
    llvm/trunk/test/MC/AsmParser/directive_values.s

Added: llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=81817&view=auto

==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (added)
+++ llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp Mon Sep 14 19:27:25 2009
@@ -0,0 +1,93 @@
+//===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ARM.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/MC/MCAsmLexer.h"
+#include "llvm/MC/MCAsmParser.h"
+#include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCInst.h"
+#include "llvm/Support/SourceMgr.h"
+#include "llvm/Target/TargetRegistry.h"
+#include "llvm/Target/TargetAsmParser.h"
+using namespace llvm;
+
+namespace {
+struct ARMOperand;
+
+class ARMAsmParser : public TargetAsmParser {
+  MCAsmParser &Parser;
+
+private:
+  MCAsmParser &getParser() const { return Parser; }
+
+  MCAsmLexer &getLexer() const { return Parser.getLexer(); }
+
+  void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
+
+  bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
+
+  bool ParseDirectiveWord(unsigned Size, SMLoc L);
+
+public:
+  ARMAsmParser(const Target &T, MCAsmParser &_Parser)
+    : TargetAsmParser(T), Parser(_Parser) {}
+
+  virtual bool ParseInstruction(const StringRef &Name, MCInst &Inst);
+
+  virtual bool ParseDirective(AsmToken DirectiveID);
+};
+  
+} // end anonymous namespace
+
+bool ARMAsmParser::ParseInstruction(const StringRef &Name, MCInst &Inst) {
+  SMLoc Loc = getLexer().getTok().getLoc();
+  Error(Loc, "ARMAsmParser::ParseInstruction currently unimplemented");
+  return true;
+}
+
+bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
+  StringRef IDVal = DirectiveID.getIdentifier();
+  if (IDVal == ".word")
+    return ParseDirectiveWord(4, DirectiveID.getLoc());
+  return true;
+}
+
+/// ParseDirectiveWord
+///  ::= .word [ expression (, expression)* ]
+bool ARMAsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
+  if (getLexer().isNot(AsmToken::EndOfStatement)) {
+    for (;;) {
+      const MCExpr *Value;
+      if (getParser().ParseExpression(Value))
+        return true;
+
+      getParser().getStreamer().EmitValue(Value, Size);
+
+      if (getLexer().is(AsmToken::EndOfStatement))
+        break;
+      
+      // FIXME: Improve diagnostic.
+      if (getLexer().isNot(AsmToken::Comma))
+        return Error(L, "unexpected token in directive");
+      getLexer().Lex();
+    }
+  }
+
+  getLexer().Lex();
+  return false;
+}
+
+// Force static initialization.
+extern "C" void LLVMInitializeARMAsmParser() {
+  RegisterAsmParser<ARMAsmParser> X(TheARMTarget);
+  RegisterAsmParser<ARMAsmParser> Y(TheThumbTarget);
+}

Added: llvm/trunk/lib/Target/ARM/AsmParser/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/CMakeLists.txt?rev=81817&view=auto

==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmParser/CMakeLists.txt (added)
+++ llvm/trunk/lib/Target/ARM/AsmParser/CMakeLists.txt Mon Sep 14 19:27:25 2009
@@ -0,0 +1,6 @@
+include_directories( ${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/.. )
+
+add_llvm_library(LLVMARMAsmParser
+  ARMAsmParser.cpp
+  )
+add_dependencies(LLVMARMAsmParser)

Added: llvm/trunk/lib/Target/ARM/AsmParser/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/Makefile?rev=81817&view=auto

==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmParser/Makefile (added)
+++ llvm/trunk/lib/Target/ARM/AsmParser/Makefile Mon Sep 14 19:27:25 2009
@@ -0,0 +1,15 @@
+##===- lib/Target/ARM/AsmParser/Makefile -------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+LEVEL = ../../../..
+LIBRARYNAME = LLVMARMAsmParser
+
+# Hack: we need to include 'main' ARM target directory to grab private headers
+CPPFLAGS = -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
+
+include $(LEVEL)/Makefile.common

Modified: llvm/trunk/lib/Target/ARM/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/Makefile?rev=81817&r1=81816&r2=81817&view=diff

==============================================================================
--- llvm/trunk/lib/Target/ARM/Makefile (original)
+++ llvm/trunk/lib/Target/ARM/Makefile Mon Sep 14 19:27:25 2009
@@ -18,6 +18,6 @@
                 ARMGenDAGISel.inc ARMGenSubtarget.inc \
                 ARMGenCodeEmitter.inc ARMGenCallingConv.inc
 
-DIRS = AsmPrinter TargetInfo
+DIRS = AsmPrinter AsmParser TargetInfo
 
 include $(LEVEL)/Makefile.common

Added: llvm/trunk/test/MC/AsmParser/arm_word_directive.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/arm_word_directive.s?rev=81817&view=auto

==============================================================================
--- llvm/trunk/test/MC/AsmParser/arm_word_directive.s (added)
+++ llvm/trunk/test/MC/AsmParser/arm_word_directive.s Mon Sep 14 19:27:25 2009
@@ -0,0 +1,6 @@
+@ RUN: llvm-mc -triple arm-unknown-unknown %s | FileCheck %s
+
+@ CHECK: TEST0:
+@ CHECK: .long 3
+TEST0:  
+        .word 3

Modified: llvm/trunk/test/MC/AsmParser/directive_values.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_values.s?rev=81817&r1=81816&r2=81817&view=diff

==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_values.s (original)
+++ llvm/trunk/test/MC/AsmParser/directive_values.s Mon Sep 14 19:27:25 2009
@@ -19,8 +19,3 @@
 # CHECK: .quad 9
 TEST3:  
         .quad 9
-
-# CHECK: TEST4:
-# CHECK: .short 3
-TEST4:  
-        .word 3

Added: llvm/trunk/test/MC/AsmParser/x86_word_directive.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/x86_word_directive.s?rev=81817&view=auto

==============================================================================
--- llvm/trunk/test/MC/AsmParser/x86_word_directive.s (added)
+++ llvm/trunk/test/MC/AsmParser/x86_word_directive.s Mon Sep 14 19:27:25 2009
@@ -0,0 +1,6 @@
+# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
+
+# CHECK: TEST0:
+# CHECK: .short 3
+TEST0:  
+        .word 3





More information about the llvm-commits mailing list