llvm.org GIT mirror llvm / 30c729b
[ms-inline asm] Add support for parsing variables with namespace alias qualifiers. This patch only adds support for parsing these identifiers in the X86AsmParser. The front-end interface isn't capable of looking up these identifiers at this point in time. The end result is the compiler now errors during object file emission, rather than at parse time. Test case coming shortly. Part of rdar://13499009 and PR13340 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178566 91177308-0d34-0410-b5e6-96231b3b80d8 Chad Rosier 7 years ago
1 changed file(s) with 54 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1212 #include "llvm/ADT/SmallVector.h"
1313 #include "llvm/ADT/StringSwitch.h"
1414 #include "llvm/ADT/Twine.h"
15 #include "llvm/MC/MCContext.h"
1516 #include "llvm/MC/MCExpr.h"
1617 #include "llvm/MC/MCInst.h"
1718 #include "llvm/MC/MCParser/MCAsmLexer.h"
6162 SMLoc StartLoc);
6263 X86Operand *ParseIntelBracExpression(unsigned SegReg, uint64_t ImmDisp,
6364 unsigned Size);
65 X86Operand *ParseIntelVarWithQualifier(const MCExpr *&Disp,
66 SMLoc &IdentStart);
6467 X86Operand *ParseMemOperand(unsigned SegReg, SMLoc StartLoc);
6568
6669 X86Operand *CreateMemForInlineAsm(const MCExpr *Disp, SMLoc Start, SMLoc End,
934937 if (getLexer().is(AsmToken::Identifier)) {
935938 if (ParseRegister(TmpReg, Start, End)) {
936939 const MCExpr *Disp;
940 SMLoc IdentStart = Tok.getLoc();
937941 if (getParser().parseExpression(Disp, End))
938942 return 0;
943
944 if (X86Operand *Err = ParseIntelVarWithQualifier(Disp, IdentStart))
945 return Err;
939946
940947 if (getLexer().isNot(AsmToken::RBrac))
941948 return ErrorOperand(Parser.getTok().getLoc(), "Expected ']' token!");
10451052 Start, End, Size);
10461053 }
10471054
1055 // Inline assembly may use variable names with namespace alias qualifiers.
1056 X86Operand *X86AsmParser::ParseIntelVarWithQualifier(const MCExpr *&Disp,
1057 SMLoc &IdentStart) {
1058 // We should only see Foo::Bar if we're parsing inline assembly.
1059 if (!isParsingInlineAsm())
1060 return 0;
1061
1062 // If we don't see a ':' then there can't be a qualifier.
1063 if (getLexer().isNot(AsmToken::Colon))
1064 return 0;
1065
1066
1067 bool Done = false;
1068 const AsmToken &Tok = Parser.getTok();
1069 SMLoc IdentEnd = Tok.getEndLoc();
1070 while (!Done) {
1071 switch (getLexer().getKind()) {
1072 default:
1073 Done = true;
1074 break;
1075 case AsmToken::Colon:
1076 getLexer().Lex(); // Consume ':'.
1077 if (getLexer().isNot(AsmToken::Colon))
1078 return ErrorOperand(Tok.getLoc(), "Expected ':' token!");
1079 getLexer().Lex(); // Consume second ':'.
1080 if (getLexer().isNot(AsmToken::Identifier))
1081 return ErrorOperand(Tok.getLoc(), "Expected an identifier token!");
1082 break;
1083 case AsmToken::Identifier:
1084 IdentEnd = Tok.getEndLoc();
1085 getLexer().Lex(); // Consume the identifier.
1086 break;
1087 }
1088 }
1089 size_t Len = IdentEnd.getPointer() - IdentStart.getPointer();
1090 StringRef Identifier(IdentStart.getPointer(), Len);
1091 MCSymbol *Sym = getContext().GetOrCreateSymbol(Identifier);
1092 MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
1093 Disp = MCSymbolRefExpr::Create(Sym, Variant, getParser().getContext());
1094 return 0;
1095 }
1096
10481097 /// ParseIntelMemOperand - Parse intel style memory operand.
10491098 X86Operand *X86AsmParser::ParseIntelMemOperand(unsigned SegReg,
10501099 uint64_t ImmDisp,
10871136 }
10881137
10891138 const MCExpr *Disp = MCConstantExpr::Create(0, getParser().getContext());
1139 SMLoc IdentStart = Tok.getLoc();
10901140 if (getParser().parseExpression(Disp, End))
10911141 return 0;
10921142
10931143 if (!isParsingInlineAsm())
10941144 return X86Operand::CreateMem(Disp, Start, End, Size);
1145
1146 if (X86Operand *Err = ParseIntelVarWithQualifier(Disp, IdentStart))
1147 return Err;
1148
10951149 return CreateMemForInlineAsm(Disp, Start, End, Start, Size);
10961150 }
10971151