@@ -32,8 +32,8 @@ using namespace llvm;
32
32
33
33
#define DEBUG_TYPE " avr-asm-parser"
34
34
35
-
36
35
namespace {
36
+
37
37
class AVRAsmParser : public MCTargetAsmParser {
38
38
MCSubtargetInfo &STI;
39
39
MCAsmParser &Parser;
@@ -54,7 +54,7 @@ class AVRAsmParser : public MCTargetAsmParser {
54
54
SMLoc NameLoc,
55
55
OperandVector &Operands) override ;
56
56
57
- bool ParseDirective (AsmToken directiveID) override { return true ; }
57
+ bool ParseDirective (AsmToken directiveID) override ;
58
58
59
59
60
60
bool parseOperand (OperandVector &Operands, StringRef Mnemonic);
@@ -63,6 +63,19 @@ class AVRAsmParser : public MCTargetAsmParser {
63
63
bool tryParseExpression (OperandVector & Operands);
64
64
void appendToken (OperandVector & Operands);
65
65
66
+ bool parseDirectiveCodeSegment ();
67
+ bool parseDirectiveCodeSegmentSize ();
68
+ bool parseDirectiveDefineByte ();
69
+ bool parseDirectiveDefineSymbol ();
70
+ bool parseDirectiveDevice ();
71
+ bool parseDirectiveDataSegment ();
72
+ bool parseDirectiveDefineWord ();
73
+ bool parseDirectiveEEPromSegment ();
74
+ bool parseDirectiveExit ();
75
+ bool parseDirectiveList ();
76
+ bool parseDirectiveListMacro ();
77
+ bool parseDirectiveNoList ();
78
+
66
79
// Handles target specific special cases. See definition for notes.
67
80
unsigned validateTargetOperandClass (MCParsedAsmOperand &Op, unsigned Kind);
68
81
@@ -86,9 +99,6 @@ class AVRAsmParser : public MCTargetAsmParser {
86
99
87
100
};
88
101
89
- /* !
90
- * Represents a parsed AVR machine instruction.
91
- */
92
102
class AVROperand : public MCParsedAsmOperand {
93
103
94
104
enum KindTy {
@@ -160,8 +170,7 @@ class AVROperand : public MCParsedAsmOperand {
160
170
return Op;
161
171
}
162
172
163
- // / Internal constructor for register kinds
164
- static std::unique_ptr<AVROperand> CreateReg (unsigned RegNum, SMLoc S,
173
+ static std::unique_ptr<AVROperand> CreateReg (unsigned RegNum, SMLoc S,
165
174
SMLoc E) {
166
175
auto Op = make_unique<AVROperand>(RegNum);
167
176
Op->StartLoc = S;
@@ -205,30 +214,26 @@ MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
205
214
unsigned MatchResult = MatchInstructionImpl (Operands, Inst, ErrorInfo,
206
215
MatchingInlineAsm);
207
216
switch (MatchResult) {
208
- default : break ;
209
- case Match_Success: {
217
+ case Match_Success:
210
218
Inst.setLoc (IDLoc);
211
219
Out.EmitInstruction (Inst, STI);
212
-
213
- return false ;
214
- }
215
- case Match_MissingFeature:
216
- Error (IDLoc, " instruction requires a CPU feature not currently enabled" );
217
- return true ;
218
- case Match_InvalidOperand: {
219
- SMLoc ErrorLoc = IDLoc;
220
- if (ErrorInfo != ~0U ) {
221
- if (ErrorInfo >= Operands.size ())
222
- return Error (IDLoc, " too few operands for instruction" );
223
-
224
- ErrorLoc = ((AVROperand &)*Operands[ErrorInfo]).getStartLoc ();
225
- if (ErrorLoc == SMLoc ()) ErrorLoc = IDLoc;
226
- }
220
+ return false ;
221
+ case Match_MissingFeature:
222
+ return Error (IDLoc, " instruction requires a CPU feature not currently enabled" );
223
+ case Match_InvalidOperand: {
224
+ SMLoc ErrorLoc = IDLoc;
225
+ if (ErrorInfo != ~0U ) {
226
+ if (ErrorInfo >= Operands.size ())
227
+ return Error (IDLoc, " too few operands for instruction" );
228
+
229
+ ErrorLoc = ((AVROperand &)*Operands[ErrorInfo]).getStartLoc ();
230
+ if (ErrorLoc == SMLoc ()) ErrorLoc = IDLoc;
231
+ }
227
232
228
- return Error (ErrorLoc, " invalid operand for instruction" );
229
- }
230
- case Match_MnemonicFail:
231
- return Error (IDLoc, " invalid instruction" );
233
+ return Error (ErrorLoc, " invalid operand for instruction" );
234
+ }
235
+ case Match_MnemonicFail:
236
+ return Error (IDLoc, " invalid instruction" );
232
237
}
233
238
return true ;
234
239
}
@@ -378,6 +383,63 @@ ParseInstruction(ParseInstructionInfo &Info, StringRef Mnemonic, SMLoc NameLoc,
378
383
return false ;
379
384
}
380
385
386
+ bool
387
+ AVRAsmParser::parseDirectiveCodeSegment () { return true ; }
388
+
389
+ bool
390
+ AVRAsmParser::parseDirectiveCodeSegmentSize () { return true ; }
391
+
392
+ bool
393
+ AVRAsmParser::parseDirectiveDefineByte () { return true ; }
394
+
395
+ bool
396
+ AVRAsmParser::parseDirectiveDefineSymbol () { return true ; }
397
+
398
+ bool
399
+ AVRAsmParser::parseDirectiveDevice () { return true ; }
400
+
401
+ bool
402
+ AVRAsmParser::parseDirectiveDataSegment () { return true ; }
403
+
404
+ bool
405
+ AVRAsmParser::parseDirectiveDefineWord () { return true ; }
406
+
407
+ bool
408
+ AVRAsmParser::parseDirectiveEEPromSegment () { return true ; }
409
+
410
+ bool
411
+ AVRAsmParser::parseDirectiveExit () { return true ; }
412
+
413
+ bool
414
+ AVRAsmParser::parseDirectiveList () { return true ; }
415
+
416
+ bool
417
+ AVRAsmParser::parseDirectiveListMacro () { return true ; }
418
+
419
+ bool
420
+ AVRAsmParser::parseDirectiveNoList () { return true ; }
421
+
422
+ bool
423
+ AVRAsmParser::ParseDirective (llvm::AsmToken DirectiveID) {
424
+ StringRef ID = DirectiveID.getIdentifier ();
425
+
426
+ if (ID == " .cseg" ) return parseDirectiveCodeSegment ();
427
+ else if (ID == " .csegsize" ) return parseDirectiveCodeSegmentSize ();
428
+ else if (ID == " .db" ) return parseDirectiveDefineByte ();
429
+ else if (ID == " .def" ) return parseDirectiveDefineSymbol ();
430
+ else if (ID == " .device" ) return parseDirectiveDevice ();
431
+ else if (ID == " .dseg" ) return parseDirectiveDataSegment ();
432
+ else if (ID == " .dw" ) return parseDirectiveDefineWord ();
433
+ else if (ID == " .eseg" ) return parseDirectiveEEPromSegment ();
434
+ else if (ID == " .exit" ) return parseDirectiveExit ();
435
+ else if (ID == " .list" ) return parseDirectiveList ();
436
+ else if (ID == " .listmac" ) return parseDirectiveListMacro ();
437
+ else if (ID == " .nolist" ) return parseDirectiveNoList ();
438
+
439
+ return true ;
440
+ }
441
+
442
+
381
443
extern " C" void LLVMInitializeAVRAsmParser () {
382
444
RegisterMCAsmParser<AVRAsmParser> X (TheAVRTarget);
383
445
}
0 commit comments