@@ -1674,6 +1674,18 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
1674
1674
if (ParseIntelDotOperator (SM, End))
1675
1675
return true ;
1676
1676
break ;
1677
+ case AsmToken::Dot:
1678
+ if (!Parser.isParsingMasm ()) {
1679
+ if ((Done = SM.isValidEndState ()))
1680
+ break ;
1681
+ return Error (Tok.getLoc (), " unknown token in expression" );
1682
+ }
1683
+ // MASM allows spaces around the dot operator (e.g., "var . x")
1684
+ Lex ();
1685
+ UpdateLocLex = false ;
1686
+ if (ParseIntelDotOperator (SM, End))
1687
+ return true ;
1688
+ break ;
1677
1689
case AsmToken::Dollar:
1678
1690
if (!Parser.isParsingMasm ()) {
1679
1691
if ((Done = SM.isValidEndState ()))
@@ -1687,6 +1699,23 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
1687
1699
SMLoc IdentLoc = Tok.getLoc ();
1688
1700
StringRef Identifier = Tok.getString ();
1689
1701
UpdateLocLex = false ;
1702
+ if (Parser.isParsingMasm ()) {
1703
+ size_t DotOffset = Identifier.find_first_of (' .' );
1704
+ if (DotOffset != StringRef::npos) {
1705
+ consumeToken ();
1706
+ StringRef LHS = Identifier.slice (0 , DotOffset);
1707
+ StringRef Dot = Identifier.slice (DotOffset, DotOffset + 1 );
1708
+ StringRef RHS = Identifier.slice (DotOffset + 1 , StringRef::npos);
1709
+ if (!RHS.empty ()) {
1710
+ getLexer ().UnLex (AsmToken (AsmToken::Identifier, RHS));
1711
+ }
1712
+ getLexer ().UnLex (AsmToken (AsmToken::Dot, Dot));
1713
+ if (!LHS.empty ()) {
1714
+ getLexer ().UnLex (AsmToken (AsmToken::Identifier, LHS));
1715
+ }
1716
+ break ;
1717
+ }
1718
+ }
1690
1719
// (MASM only) <TYPE> PTR operator
1691
1720
if (Parser.isParsingMasm ()) {
1692
1721
const AsmToken &NextTok = getLexer ().peekTok ();
@@ -1744,7 +1773,7 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
1744
1773
}
1745
1774
// Symbol reference, when parsing assembly content
1746
1775
InlineAsmIdentifierInfo Info;
1747
- AsmTypeInfo Type ;
1776
+ AsmFieldInfo FieldInfo ;
1748
1777
const MCExpr *Val;
1749
1778
if (isParsingMSInlineAsm () || Parser.isParsingMasm ()) {
1750
1779
// MS Dot Operator expression
@@ -1761,8 +1790,9 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
1761
1790
if (int64_t Val = ParseIntelInlineAsmOperator (OpKind)) {
1762
1791
if (SM.onInteger (Val, ErrMsg))
1763
1792
return Error (IdentLoc, ErrMsg);
1764
- } else
1793
+ } else {
1765
1794
return true ;
1795
+ }
1766
1796
break ;
1767
1797
}
1768
1798
// MS InlineAsm identifier
@@ -1771,7 +1801,8 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
1771
1801
return Error (IdentLoc, " expected identifier" );
1772
1802
if (ParseIntelInlineAsmIdentifier (Val, Identifier, Info, false , End))
1773
1803
return true ;
1774
- else if (SM.onIdentifierExpr (Val, Identifier, Info, Type, true , ErrMsg))
1804
+ else if (SM.onIdentifierExpr (Val, Identifier, Info, FieldInfo.Type ,
1805
+ true , ErrMsg))
1775
1806
return Error (IdentLoc, ErrMsg);
1776
1807
break ;
1777
1808
}
@@ -1784,11 +1815,35 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
1784
1815
return Error (IdentLoc, ErrMsg);
1785
1816
break ;
1786
1817
}
1818
+ if (!getParser ().lookUpType (Identifier, FieldInfo.Type )) {
1819
+ // Field offset immediate; <TYPE>.<field specification>
1820
+ Lex (); // eat type
1821
+ bool EndDot = parseOptionalToken (AsmToken::Dot);
1822
+ while (EndDot || (getTok ().is (AsmToken::Identifier) &&
1823
+ getTok ().getString ().startswith (" ." ))) {
1824
+ getParser ().parseIdentifier (Identifier);
1825
+ if (!EndDot)
1826
+ Identifier.consume_front (" ." );
1827
+ EndDot = Identifier.consume_back (" ." );
1828
+ if (getParser ().lookUpField (FieldInfo.Type .Name , Identifier,
1829
+ FieldInfo)) {
1830
+ SMLoc IDEnd =
1831
+ SMLoc::getFromPointer (Identifier.data () + Identifier.size ());
1832
+ return Error (IdentLoc, " Unable to lookup field reference!" ,
1833
+ SMRange (IdentLoc, IDEnd));
1834
+ }
1835
+ if (!EndDot)
1836
+ EndDot = parseOptionalToken (AsmToken::Dot);
1837
+ }
1838
+ if (SM.onInteger (FieldInfo.Offset , ErrMsg))
1839
+ return Error (IdentLoc, ErrMsg);
1840
+ break ;
1841
+ }
1787
1842
}
1788
- if (getParser ().parsePrimaryExpr (Val, End, &Type)) {
1843
+ if (getParser ().parsePrimaryExpr (Val, End, &FieldInfo. Type )) {
1789
1844
return Error (Tok.getLoc (), " Unexpected identifier!" );
1790
- } else if (SM.onIdentifierExpr (Val, Identifier, Info, Type, false ,
1791
- ErrMsg)) {
1845
+ } else if (SM.onIdentifierExpr (Val, Identifier, Info, FieldInfo. Type ,
1846
+ false , ErrMsg)) {
1792
1847
return Error (IdentLoc, ErrMsg);
1793
1848
}
1794
1849
break ;
@@ -2006,6 +2061,7 @@ bool X86AsmParser::ParseIntelDotOperator(IntelExprStateMachine &SM,
2006
2061
StringRef DotDispStr = Tok.getString ();
2007
2062
if (DotDispStr.startswith (" ." ))
2008
2063
DotDispStr = DotDispStr.drop_front (1 );
2064
+ StringRef TrailingDot;
2009
2065
2010
2066
// .Imm gets lexed as a real.
2011
2067
if (Tok.is (AsmToken::Real)) {
@@ -2014,6 +2070,10 @@ bool X86AsmParser::ParseIntelDotOperator(IntelExprStateMachine &SM,
2014
2070
Info.Offset = DotDisp.getZExtValue ();
2015
2071
} else if ((isParsingMSInlineAsm () || getParser ().isParsingMasm ()) &&
2016
2072
Tok.is (AsmToken::Identifier)) {
2073
+ if (DotDispStr.endswith (" ." )) {
2074
+ TrailingDot = DotDispStr.substr (DotDispStr.size () - 1 );
2075
+ DotDispStr = DotDispStr.drop_back (1 );
2076
+ }
2017
2077
const std::pair<StringRef, StringRef> BaseMember = DotDispStr.split (' .' );
2018
2078
const StringRef Base = BaseMember.first , Member = BaseMember.second ;
2019
2079
if (getParser ().lookUpField (SM.getType (), DotDispStr, Info) &&
@@ -2031,6 +2091,8 @@ bool X86AsmParser::ParseIntelDotOperator(IntelExprStateMachine &SM,
2031
2091
const char *DotExprEndLoc = DotDispStr.data () + DotDispStr.size ();
2032
2092
while (Tok.getLoc ().getPointer () < DotExprEndLoc)
2033
2093
Lex ();
2094
+ if (!TrailingDot.empty ())
2095
+ getLexer ().UnLex (AsmToken (AsmToken::Dot, TrailingDot));
2034
2096
SM.addImm (Info.Offset );
2035
2097
SM.setTypeInfo (Info.Type );
2036
2098
return false ;
0 commit comments