Skip to content
This repository was archived by the owner on Sep 2, 2018. It is now read-only.

Commit 320f35f

Browse files
author
Dylan McKay
committed
Merge pull request #105 from agnat/feature/assembler_directives
Implement assembler directives
2 parents dc4079d + bbe7e64 commit 320f35f

File tree

1 file changed

+90
-28
lines changed

1 file changed

+90
-28
lines changed

lib/Target/AVR/AsmParser/AVRAsmParser.cpp

+90-28
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ using namespace llvm;
3232

3333
#define DEBUG_TYPE "avr-asm-parser"
3434

35-
3635
namespace {
36+
3737
class AVRAsmParser : public MCTargetAsmParser {
3838
MCSubtargetInfo &STI;
3939
MCAsmParser &Parser;
@@ -54,7 +54,7 @@ class AVRAsmParser : public MCTargetAsmParser {
5454
SMLoc NameLoc,
5555
OperandVector &Operands) override;
5656

57-
bool ParseDirective(AsmToken directiveID) override { return true; }
57+
bool ParseDirective(AsmToken directiveID) override;
5858

5959

6060
bool parseOperand(OperandVector &Operands, StringRef Mnemonic);
@@ -63,6 +63,19 @@ class AVRAsmParser : public MCTargetAsmParser {
6363
bool tryParseExpression(OperandVector & Operands);
6464
void appendToken(OperandVector & Operands);
6565

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+
6679
// Handles target specific special cases. See definition for notes.
6780
unsigned validateTargetOperandClass(MCParsedAsmOperand &Op, unsigned Kind);
6881

@@ -86,9 +99,6 @@ class AVRAsmParser : public MCTargetAsmParser {
8699

87100
};
88101

89-
/*!
90-
* Represents a parsed AVR machine instruction.
91-
*/
92102
class AVROperand : public MCParsedAsmOperand {
93103

94104
enum KindTy {
@@ -160,8 +170,7 @@ class AVROperand : public MCParsedAsmOperand {
160170
return Op;
161171
}
162172

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,
165174
SMLoc E) {
166175
auto Op = make_unique<AVROperand>(RegNum);
167176
Op->StartLoc = S;
@@ -205,30 +214,26 @@ MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
205214
unsigned MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
206215
MatchingInlineAsm);
207216
switch (MatchResult) {
208-
default: break;
209-
case Match_Success: {
217+
case Match_Success:
210218
Inst.setLoc(IDLoc);
211219
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+
}
227232

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");
232237
}
233238
return true;
234239
}
@@ -378,6 +383,63 @@ ParseInstruction(ParseInstructionInfo &Info, StringRef Mnemonic, SMLoc NameLoc,
378383
return false;
379384
}
380385

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+
381443
extern "C" void LLVMInitializeAVRAsmParser() {
382444
RegisterMCAsmParser<AVRAsmParser> X(TheAVRTarget);
383445
}

0 commit comments

Comments
 (0)