llvm.org GIT mirror llvm / ca9c42c
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81817 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 11 years ago
7 changed file(s) with 127 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
0 //===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "ARM.h"
10 #include "llvm/ADT/SmallVector.h"
11 #include "llvm/ADT/Twine.h"
12 #include "llvm/MC/MCAsmLexer.h"
13 #include "llvm/MC/MCAsmParser.h"
14 #include "llvm/MC/MCStreamer.h"
15 #include "llvm/MC/MCExpr.h"
16 #include "llvm/MC/MCInst.h"
17 #include "llvm/Support/SourceMgr.h"
18 #include "llvm/Target/TargetRegistry.h"
19 #include "llvm/Target/TargetAsmParser.h"
20 using namespace llvm;
21
22 namespace {
23 struct ARMOperand;
24
25 class ARMAsmParser : public TargetAsmParser {
26 MCAsmParser &Parser;
27
28 private:
29 MCAsmParser &getParser() const { return Parser; }
30
31 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
32
33 void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
34
35 bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
36
37 bool ParseDirectiveWord(unsigned Size, SMLoc L);
38
39 public:
40 ARMAsmParser(const Target &T, MCAsmParser &_Parser)
41 : TargetAsmParser(T), Parser(_Parser) {}
42
43 virtual bool ParseInstruction(const StringRef &Name, MCInst &Inst);
44
45 virtual bool ParseDirective(AsmToken DirectiveID);
46 };
47
48 } // end anonymous namespace
49
50 bool ARMAsmParser::ParseInstruction(const StringRef &Name, MCInst &Inst) {
51 SMLoc Loc = getLexer().getTok().getLoc();
52 Error(Loc, "ARMAsmParser::ParseInstruction currently unimplemented");
53 return true;
54 }
55
56 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
57 StringRef IDVal = DirectiveID.getIdentifier();
58 if (IDVal == ".word")
59 return ParseDirectiveWord(4, DirectiveID.getLoc());
60 return true;
61 }
62
63 /// ParseDirectiveWord
64 /// ::= .word [ expression (, expression)* ]
65 bool ARMAsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
66 if (getLexer().isNot(AsmToken::EndOfStatement)) {
67 for (;;) {
68 const MCExpr *Value;
69 if (getParser().ParseExpression(Value))
70 return true;
71
72 getParser().getStreamer().EmitValue(Value, Size);
73
74 if (getLexer().is(AsmToken::EndOfStatement))
75 break;
76
77 // FIXME: Improve diagnostic.
78 if (getLexer().isNot(AsmToken::Comma))
79 return Error(L, "unexpected token in directive");
80 getLexer().Lex();
81 }
82 }
83
84 getLexer().Lex();
85 return false;
86 }
87
88 // Force static initialization.
89 extern "C" void LLVMInitializeARMAsmParser() {
90 RegisterAsmParser X(TheARMTarget);
91 RegisterAsmParser Y(TheThumbTarget);
92 }
0 include_directories( ${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/.. )
1
2 add_llvm_library(LLVMARMAsmParser
3 ARMAsmParser.cpp
4 )
5 add_dependencies(LLVMARMAsmParser)
0 ##===- lib/Target/ARM/AsmParser/Makefile -------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8 LEVEL = ../../../..
9 LIBRARYNAME = LLVMARMAsmParser
10
11 # Hack: we need to include 'main' ARM target directory to grab private headers
12 CPPFLAGS = -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
13
14 include $(LEVEL)/Makefile.common
1717 ARMGenDAGISel.inc ARMGenSubtarget.inc \
1818 ARMGenCodeEmitter.inc ARMGenCallingConv.inc
1919
20 DIRS = AsmPrinter TargetInfo
20 DIRS = AsmPrinter AsmParser TargetInfo
2121
2222 include $(LEVEL)/Makefile.common
0 @ RUN: llvm-mc -triple arm-unknown-unknown %s | FileCheck %s
1
2 @ CHECK: TEST0:
3 @ CHECK: .long 3
4 TEST0:
5 .word 3
1818 # CHECK: .quad 9
1919 TEST3:
2020 .quad 9
21
22 # CHECK: TEST4:
23 # CHECK: .short 3
24 TEST4:
25 .word 3
0 # RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
1
2 # CHECK: TEST0:
3 # CHECK: .short 3
4 TEST0:
5 .word 3