Skip to content

Commit 02ecd43

Browse files
committedDec 13, 2015
[X86][inline asm] support even directive
The .even directive aligns content to an evan-numbered address. In at&t syntax .even In Microsoft syntax even (without the dot). Differential Revision: http://reviews.llvm.org/D15413 llvm-svn: 255462
1 parent c00e65a commit 02ecd43

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed
 

‎llvm/include/llvm/MC/MCTargetAsmParser.h

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef SmallVectorImpl<std::unique_ptr<MCParsedAsmOperand>> OperandVector;
3030
enum AsmRewriteKind {
3131
AOK_Delete = 0, // Rewrite should be ignored.
3232
AOK_Align, // Rewrite align as .align.
33+
AOK_EVEN, // Rewrite even as .even.
3334
AOK_DotOperator, // Rewrite a dot operator expression as an immediate.
3435
// E.g., [eax].foo.bar -> [eax].8
3536
AOK_Emit, // Rewrite _emit as .byte.
@@ -45,6 +46,7 @@ enum AsmRewriteKind {
4546
const char AsmRewritePrecedence [] = {
4647
0, // AOK_Delete
4748
2, // AOK_Align
49+
2, // AOK_EVEN
4850
2, // AOK_DotOperator
4951
2, // AOK_Emit
5052
4, // AOK_Imm

‎llvm/lib/MC/MCParser/AsmParser.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,8 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
17141714
if (ParsingInlineAsm && (IDVal == "align" || IDVal == "ALIGN"))
17151715
return parseDirectiveMSAlign(IDLoc, Info);
17161716

1717+
if (ParsingInlineAsm && (IDVal == "even"))
1718+
Info.AsmRewrites->emplace_back(AOK_EVEN, IDLoc, 4);
17171719
checkForValidSection();
17181720

17191721
// Canonicalize the opcode to lower case.
@@ -4863,6 +4865,9 @@ bool AsmParser::parseMSInlineAsm(
48634865
AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
48644866
break;
48654867
}
4868+
case AOK_EVEN:
4869+
OS << ".even";
4870+
break;
48664871
case AOK_DotOperator:
48674872
// Insert the dot if the user omitted it.
48684873
OS.flush();

‎llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/MC/MCParser/MCAsmParser.h"
2727
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
2828
#include "llvm/MC/MCRegisterInfo.h"
29+
#include "llvm/MC/MCSection.h"
2930
#include "llvm/MC/MCStreamer.h"
3031
#include "llvm/MC/MCSubtargetInfo.h"
3132
#include "llvm/MC/MCSymbol.h"
@@ -714,6 +715,7 @@ class X86AsmParser : public MCTargetAsmParser {
714715
SMLoc End, unsigned Size, StringRef Identifier,
715716
InlineAsmIdentifierInfo &Info);
716717

718+
bool parseDirectiveEven(SMLoc L);
717719
bool ParseDirectiveWord(unsigned Size, SMLoc L);
718720
bool ParseDirectiveCode(StringRef IDVal, SMLoc L);
719721

@@ -2844,10 +2846,29 @@ bool X86AsmParser::ParseDirective(AsmToken DirectiveID) {
28442846
"a '%' prefix in .intel_syntax");
28452847
}
28462848
return false;
2847-
}
2849+
} else if (IDVal == ".even")
2850+
return parseDirectiveEven(DirectiveID.getLoc());
28482851
return true;
28492852
}
28502853

2854+
/// parseDirectiveEven
2855+
/// ::= .even
2856+
bool X86AsmParser::parseDirectiveEven(SMLoc L) {
2857+
const MCSection *Section = getStreamer().getCurrentSection().first;
2858+
if (getLexer().isNot(AsmToken::EndOfStatement)) {
2859+
TokError("unexpected token in directive");
2860+
return false;
2861+
}
2862+
if (!Section) {
2863+
getStreamer().InitSections(false);
2864+
Section = getStreamer().getCurrentSection().first;
2865+
}
2866+
if (Section->UseCodeAlign())
2867+
getStreamer().EmitCodeAlignment(2, 0);
2868+
else
2869+
getStreamer().EmitValueToAlignment(2, 0, 1, 0);
2870+
return false;
2871+
}
28512872
/// ParseDirectiveWord
28522873
/// ::= .word [ expression (, expression)* ]
28532874
bool X86AsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {

‎llvm/test/MC/X86/x86-evenDirective.s

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# RUN: llvm-mc -filetype obj -o - %s | llvm-readobj -s -sd \
2+
# RUN: | FileCheck %s
3+
4+
.text
5+
even_check:
6+
.byte 0x00
7+
.byte 0x01
8+
.byte 0x02
9+
.byte 0x03
10+
.byte 0x04
11+
.byte 0x05
12+
.byte 0x06
13+
.byte 0x07
14+
.byte 0x08
15+
.byte 0x09
16+
.byte 0x10
17+
.even
18+
.byte 0x11
19+
.byte 0x12
20+
.even
21+
.byte 0x13
22+
.even
23+
.byte 0x00
24+
.byte 0x01
25+
.byte 0x02
26+
.byte 0x03
27+
.byte 0x04
28+
.byte 0x05
29+
.byte 0x06
30+
.byte 0x07
31+
.byte 0x08
32+
.byte 0x09
33+
.byte 0x10
34+
.byte 0x11
35+
.byte 0x12
36+
.byte 0x13
37+
.byte 0x14
38+
.byte 0x15
39+
40+
# CHECK: Section {
41+
# CHECK: Name: .text
42+
# CHECK: SectionData (
43+
# CHECK: 0000: 00010203 04050607 08091090 11121390
44+
# CHECK: 0010: 00010203 04050607 08091011 12131415
45+
# CHECK: )
46+
# CHECK: }
47+

0 commit comments

Comments
 (0)
Please sign in to comment.