OLD | NEW |
1 //===- NaClAsmParser.cpp - NaCl Assembly Parser ---------------------------===// | 1 //===- NaClAsmParser.cpp - NaCl Assembly Parser ---------------------------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 | 9 |
10 #include "llvm/MC/MCParser/MCAsmParserExtension.h" | 10 #include "llvm/MC/MCParser/MCAsmParserExtension.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 getParser().addDirectiveHandler(Directive, Handler); | 26 getParser().addDirectiveHandler(Directive, Handler); |
27 } | 27 } |
28 | 28 |
29 public: | 29 public: |
30 NaClAsmParser(MCNaClExpander *Exp) : Expander(Exp) {} | 30 NaClAsmParser(MCNaClExpander *Exp) : Expander(Exp) {} |
31 void Initialize(MCAsmParser &Parser) override { | 31 void Initialize(MCAsmParser &Parser) override { |
32 // Call the base implementation. | 32 // Call the base implementation. |
33 MCAsmParserExtension::Initialize(Parser); | 33 MCAsmParserExtension::Initialize(Parser); |
34 addDirectiveHandler<&NaClAsmParser::ParseScratch>(".scratch"); | 34 addDirectiveHandler<&NaClAsmParser::ParseScratch>(".scratch"); |
35 addDirectiveHandler<&NaClAsmParser::ParseUnscratch>(".unscratch"); | 35 addDirectiveHandler<&NaClAsmParser::ParseUnscratch>(".scratch_clear"); |
36 } | 36 } |
37 | 37 |
38 /// ::= {.scratch} reg | 38 /// ::= {.scratch} reg |
39 bool ParseScratch(StringRef Directive, SMLoc Loc) { | 39 bool ParseScratch(StringRef Directive, SMLoc Loc) { |
40 getParser().checkForValidSection(); | 40 getParser().checkForValidSection(); |
41 unsigned RegNo; | 41 unsigned RegNo; |
42 const char *kInvalidOptionError = | 42 const char *kInvalidOptionError = |
43 "expected register name after '.scratch' directive"; | 43 "expected register name after '.scratch' directive"; |
44 | 44 |
45 if (getLexer().isNot(AsmToken::EndOfStatement)) { | 45 if (getLexer().isNot(AsmToken::EndOfStatement)) { |
46 if (getParser().getTargetParser().ParseRegister(RegNo, Loc, Loc)) | 46 if (getParser().getTargetParser().ParseRegister(RegNo, Loc, Loc)) |
47 return Error(Loc, kInvalidOptionError); | 47 return Error(Loc, kInvalidOptionError); |
48 | 48 |
49 else if (getLexer().isNot(AsmToken::EndOfStatement)) | 49 else if (getLexer().isNot(AsmToken::EndOfStatement)) |
50 return Error(Loc, kInvalidOptionError); | 50 return Error(Loc, kInvalidOptionError); |
51 } | 51 } |
52 else { | 52 else { |
53 return Error(Loc, kInvalidOptionError); | 53 return Error(Loc, kInvalidOptionError); |
54 } | 54 } |
55 Lex(); | 55 Lex(); |
56 | 56 |
57 Expander->pushScratchReg(RegNo); | 57 if(Expander->addScratchReg(RegNo)) |
| 58 return Error(Loc, "Register can't be used as a scratch register"); |
58 return false; | 59 return false; |
59 } | 60 } |
60 | 61 |
61 /// ::= {.unscratch} | 62 /// ::= {.unscratch} |
62 bool ParseUnscratch(StringRef Directive, SMLoc Loc) { | 63 bool ParseUnscratch(StringRef Directive, SMLoc Loc) { |
63 getParser().checkForValidSection(); | 64 getParser().checkForValidSection(); |
64 if (getLexer().isNot(AsmToken::EndOfStatement)) | 65 if (getLexer().isNot(AsmToken::EndOfStatement)) |
65 return TokError("unexpected token in '.unscratch' directive"); | 66 return TokError("unexpected token in '.scratch_clear' directive"); |
66 Lex(); | 67 Lex(); |
67 | 68 |
68 if (Expander->numScratchRegs() == 0) | 69 Expander->clearScratchRegs(); |
69 return Error(Loc, "No scratch registers specified"); | |
70 Expander->popScratchReg(); | |
71 | 70 |
72 return false; | 71 return false; |
73 } | 72 } |
74 }; | 73 }; |
75 | 74 |
76 namespace llvm { | 75 namespace llvm { |
77 MCAsmParserExtension *createNaClAsmParser(MCNaClExpander *Exp) { | 76 MCAsmParserExtension *createNaClAsmParser(MCNaClExpander *Exp) { |
78 return new NaClAsmParser(Exp); | 77 return new NaClAsmParser(Exp); |
79 } | 78 } |
80 } | 79 } |
OLD | NEW |