xref: /llvm-project/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp (revision 682fe17e08c52bbdd2c2894ed08a3f9445660cbe)
1 //===- llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp ----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===--------------------------------------------------------------------===//
8 #include "llvm/MC/MCAsmInfo.h"
9 #include "llvm/MC/MCContext.h"
10 #include "llvm/MC/MCInstrInfo.h"
11 #include "llvm/MC/MCObjectFileInfo.h"
12 #include "llvm/MC/MCParser/MCAsmLexer.h"
13 #include "llvm/MC/MCParser/MCTargetAsmParser.h"
14 #include "llvm/MC/MCRegisterInfo.h"
15 #include "llvm/MC/MCStreamer.h"
16 #include "llvm/MC/MCSubtargetInfo.h"
17 #include "llvm/MC/MCSymbol.h"
18 #include "llvm/MC/TargetRegistry.h"
19 #include "llvm/Support/MemoryBuffer.h"
20 #include "llvm/Support/SourceMgr.h"
21 #include "llvm/Support/TargetSelect.h"
22 
23 #include "gtest/gtest.h"
24 
25 using namespace llvm;
26 
27 namespace {
28 
29 // Setup a testing class that the GTest framework can call.
30 class SystemZAsmLexerTest : public ::testing::Test {
31 protected:
SetUpTestCase()32   static void SetUpTestCase() {
33     LLVMInitializeSystemZTargetInfo();
34     LLVMInitializeSystemZTargetMC();
35     LLVMInitializeSystemZAsmParser();
36   }
37 
38   std::unique_ptr<MCRegisterInfo> MRI;
39   std::unique_ptr<MCAsmInfo> MAI;
40   std::unique_ptr<const MCInstrInfo> MII;
41   std::unique_ptr<MCObjectFileInfo> MOFI;
42   std::unique_ptr<MCStreamer> Str;
43   std::unique_ptr<MCAsmParser> Parser;
44   std::unique_ptr<MCContext> Ctx;
45   std::unique_ptr<MCSubtargetInfo> STI;
46   std::unique_ptr<MCTargetAsmParser> TargetAsmParser;
47 
48   SourceMgr SrcMgr;
49   std::string TripleName;
50   llvm::Triple Triple;
51   const Target *TheTarget;
52 
53   const MCTargetOptions MCOptions;
54 
55   SystemZAsmLexerTest() = delete;
56 
SystemZAsmLexerTest(std::string SystemZTriple)57   SystemZAsmLexerTest(std::string SystemZTriple) {
58     // We will use the SystemZ triple, because of missing
59     // Object File and Streamer support for the z/OS target.
60     TripleName = SystemZTriple;
61     Triple = llvm::Triple(TripleName);
62 
63     std::string Error;
64     TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
65     EXPECT_NE(TheTarget, nullptr);
66 
67     MRI.reset(TheTarget->createMCRegInfo(TripleName));
68     EXPECT_NE(MRI, nullptr);
69 
70     MII.reset(TheTarget->createMCInstrInfo());
71     EXPECT_NE(MII, nullptr);
72 
73     STI.reset(TheTarget->createMCSubtargetInfo(TripleName, "z10", ""));
74     EXPECT_NE(STI, nullptr);
75 
76     MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
77     EXPECT_NE(MAI, nullptr);
78   }
79 
setupCallToAsmParser(StringRef AsmStr)80   void setupCallToAsmParser(StringRef AsmStr) {
81     std::unique_ptr<MemoryBuffer> Buffer(MemoryBuffer::getMemBuffer(AsmStr));
82     SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc());
83     EXPECT_EQ(Buffer, nullptr);
84 
85     Ctx.reset(new MCContext(Triple, MAI.get(), MRI.get(), STI.get(), &SrcMgr,
86                             &MCOptions));
87     MOFI.reset(TheTarget->createMCObjectFileInfo(*Ctx, /*PIC=*/false,
88                                                  /*LargeCodeModel=*/false));
89     Ctx->setObjectFileInfo(MOFI.get());
90 
91     Str.reset(TheTarget->createNullStreamer(*Ctx));
92 
93     Parser.reset(createMCAsmParser(SrcMgr, *Ctx, *Str, *MAI));
94 
95     TargetAsmParser.reset(
96         TheTarget->createMCAsmParser(*STI, *Parser, *MII, MCOptions));
97     Parser->setTargetParser(*TargetAsmParser);
98   }
99 
lexAndCheckTokens(StringRef AsmStr,SmallVector<AsmToken::TokenKind> ExpectedTokens)100   void lexAndCheckTokens(StringRef AsmStr,
101                          SmallVector<AsmToken::TokenKind> ExpectedTokens) {
102     // Get reference to AsmLexer.
103     MCAsmLexer &Lexer = Parser->getLexer();
104     // Loop through all expected tokens checking one by one.
105     for (size_t I = 0; I < ExpectedTokens.size(); ++I) {
106       EXPECT_EQ(Lexer.getTok().getKind(), ExpectedTokens[I]);
107       Lexer.Lex();
108     }
109   }
110 
lexAndCheckIntegerTokensAndValues(StringRef AsmStr,SmallVector<int64_t> ExpectedValues)111   void lexAndCheckIntegerTokensAndValues(StringRef AsmStr,
112                                          SmallVector<int64_t> ExpectedValues) {
113     // Get reference to AsmLexer.
114     MCAsmLexer &Lexer = Parser->getLexer();
115     // Loop through all expected tokens and expected values.
116     for (size_t I = 0; I < ExpectedValues.size(); ++I) {
117       // Skip any EndOfStatement tokens, we're not concerned with them.
118       if (Lexer.getTok().getKind() == AsmToken::EndOfStatement)
119         continue;
120       EXPECT_EQ(Lexer.getTok().getKind(), AsmToken::Integer);
121       EXPECT_EQ(Lexer.getTok().getIntVal(), ExpectedValues[I]);
122       Lexer.Lex();
123     }
124   }
125 };
126 
127 class SystemZAsmLexerLinux : public SystemZAsmLexerTest {
128 protected:
SystemZAsmLexerLinux()129   SystemZAsmLexerLinux() : SystemZAsmLexerTest("s390x-ibm-linux") {}
130 };
131 
132 class SystemZAsmLexerZOS : public SystemZAsmLexerTest {
133 protected:
SystemZAsmLexerZOS()134   SystemZAsmLexerZOS() : SystemZAsmLexerTest("s390x-ibm-zos") {}
135 };
136 
TEST_F(SystemZAsmLexerLinux,CheckDontRestrictCommentStringToStartOfStatement)137 TEST_F(SystemZAsmLexerLinux, CheckDontRestrictCommentStringToStartOfStatement) {
138   StringRef AsmStr = "jne #-4";
139 
140   // Setup.
141   setupCallToAsmParser(AsmStr);
142 
143   // Lex initially to get the string.
144   Parser->getLexer().Lex();
145 
146   SmallVector<AsmToken::TokenKind> ExpectedTokens(
147       {AsmToken::Identifier, AsmToken::EndOfStatement});
148   lexAndCheckTokens(AsmStr /* "jne #-4" */, ExpectedTokens);
149 }
150 
TEST_F(SystemZAsmLexerZOS,CheckRestrictCommentStringToStartOfStatement)151 TEST_F(SystemZAsmLexerZOS, CheckRestrictCommentStringToStartOfStatement) {
152   StringRef AsmStr = "jne #-4";
153 
154   // Setup.
155   setupCallToAsmParser(AsmStr);
156 
157   // Lex initially to get the string.
158   Parser->getLexer().Lex();
159 
160   // When we are restricting the comment string to only the start of the
161   // statement, The sequence of tokens we are expecting are: Identifier - "jne"
162   // Hash - '#'
163   // Minus - '-'
164   // Integer - '4'
165   SmallVector<AsmToken::TokenKind> ExpectedTokens(
166       {AsmToken::Identifier, AsmToken::Space, AsmToken::Identifier});
167   lexAndCheckTokens(AsmStr /* "jne #-4" */, ExpectedTokens);
168 }
169 
170 // Test HLASM Comment Syntax ('*')
TEST_F(SystemZAsmLexerZOS,CheckHLASMComment)171 TEST_F(SystemZAsmLexerZOS, CheckHLASMComment) {
172   StringRef AsmStr = "* lhi 1,10";
173 
174   // Setup.
175   setupCallToAsmParser(AsmStr);
176 
177   // Lex initially to get the string.
178   Parser->getLexer().Lex();
179 
180   SmallVector<AsmToken::TokenKind> ExpectedTokens(
181       {AsmToken::EndOfStatement, AsmToken::Eof});
182   lexAndCheckTokens(AsmStr /* "* lhi 1,10" */, ExpectedTokens);
183 }
184 
TEST_F(SystemZAsmLexerLinux,CheckHashDefault)185 TEST_F(SystemZAsmLexerLinux, CheckHashDefault) {
186   StringRef AsmStr = "lh#123";
187 
188   // Setup.
189   setupCallToAsmParser(AsmStr);
190 
191   // Lex initially to get the string.
192   Parser->getLexer().Lex();
193 
194   // "lh" -> Identifier
195   // "#123" -> EndOfStatement (Lexed as a comment since CommentString is "#")
196   SmallVector<AsmToken::TokenKind> ExpectedTokens(
197       {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
198   lexAndCheckTokens(AsmStr, ExpectedTokens);
199 }
200 
201 // Test if "#" is accepted as an Identifier
TEST_F(SystemZAsmLexerZOS,CheckAllowHashInIdentifier)202 TEST_F(SystemZAsmLexerZOS, CheckAllowHashInIdentifier) {
203   StringRef AsmStr = "lh#123";
204 
205   // Setup.
206   setupCallToAsmParser(AsmStr);
207 
208   // Lex initially to get the string.
209   Parser->getLexer().Lex();
210 
211   // "lh123" -> Identifier
212   SmallVector<AsmToken::TokenKind> ExpectedTokens(
213       {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
214   lexAndCheckTokens(AsmStr, ExpectedTokens);
215 }
216 
TEST_F(SystemZAsmLexerZOS,CheckAllowHashInIdentifier2)217 TEST_F(SystemZAsmLexerZOS, CheckAllowHashInIdentifier2) {
218   StringRef AsmStr = "lh#12*3";
219 
220   // Setup.
221   setupCallToAsmParser(AsmStr);
222 
223   // Lex initially to get the string.
224   Parser->getLexer().Lex();
225 
226   // "lh#12" -> Identifier
227   // "*" -> Star
228   // "3" -> Integer
229   SmallVector<AsmToken::TokenKind> ExpectedTokens(
230       {AsmToken::Identifier, AsmToken::Star, AsmToken::Integer,
231        AsmToken::EndOfStatement, AsmToken::Eof});
232   lexAndCheckTokens(AsmStr, ExpectedTokens);
233 }
234 
TEST_F(SystemZAsmLexerLinux,DontCheckStrictCommentString)235 TEST_F(SystemZAsmLexerLinux, DontCheckStrictCommentString) {
236   StringRef AsmStr = "# abc\n/* def *///  xyz";
237 
238   // Setup.
239   setupCallToAsmParser(AsmStr);
240 
241   // Lex initially to get the string.
242   Parser->getLexer().Lex();
243 
244   SmallVector<AsmToken::TokenKind> ExpectedTokens(
245       {AsmToken::EndOfStatement, AsmToken::Comment, AsmToken::EndOfStatement,
246        AsmToken::Eof});
247   lexAndCheckTokens(AsmStr, ExpectedTokens);
248 }
249 
TEST_F(SystemZAsmLexerZOS,CheckStrictCommentString)250 TEST_F(SystemZAsmLexerZOS, CheckStrictCommentString) {
251   StringRef AsmStr = "# abc\n/* def *///  xyz";
252 
253   // Setup.
254   setupCallToAsmParser(AsmStr);
255 
256   // Lex initially to get the string.
257   Parser->getLexer().Lex();
258 
259   SmallVector<AsmToken::TokenKind> ExpectedTokens;
260   ExpectedTokens.push_back(AsmToken::Identifier);     // "#"
261   ExpectedTokens.push_back(AsmToken::Space);          // " "
262   ExpectedTokens.push_back(AsmToken::Identifier);     // "abc"
263   ExpectedTokens.push_back(AsmToken::EndOfStatement); // "\n"
264   ExpectedTokens.push_back(AsmToken::Slash);          // "/"
265   ExpectedTokens.push_back(AsmToken::Star);           // "*"
266   ExpectedTokens.push_back(AsmToken::Space);          // " "
267   ExpectedTokens.push_back(AsmToken::Identifier);     // "def"
268   ExpectedTokens.push_back(AsmToken::Space);          // " "
269   ExpectedTokens.push_back(AsmToken::Star);           // "*"
270   ExpectedTokens.push_back(AsmToken::Slash);          // "/"
271   ExpectedTokens.push_back(AsmToken::Slash);          // "/"
272   ExpectedTokens.push_back(AsmToken::Slash);          // "/"
273   ExpectedTokens.push_back(AsmToken::Space);          // " "
274   ExpectedTokens.push_back(AsmToken::Identifier);     // "xyz"
275   ExpectedTokens.push_back(AsmToken::EndOfStatement);
276   ExpectedTokens.push_back(AsmToken::Eof);
277 
278   lexAndCheckTokens(AsmStr, ExpectedTokens);
279 }
280 
TEST_F(SystemZAsmLexerZOS,CheckValidHLASMIntegers)281 TEST_F(SystemZAsmLexerZOS, CheckValidHLASMIntegers) {
282   StringRef AsmStr = "123\n000123\n1999\n007\n12300\n12021\n";
283   // StringRef AsmStr = "123";
284   // Setup.
285   setupCallToAsmParser(AsmStr);
286 
287   // Lex initially to get the string.
288   Parser->getLexer().Lex();
289 
290   // SmallVector<int64_t> ExpectedValues({123});
291   SmallVector<int64_t> ExpectedValues({123, 123, 1999, 7, 12300, 12021});
292   lexAndCheckIntegerTokensAndValues(AsmStr, ExpectedValues);
293 }
294 
TEST_F(SystemZAsmLexerZOS,CheckInvalidHLASMIntegers)295 TEST_F(SystemZAsmLexerZOS, CheckInvalidHLASMIntegers) {
296   StringRef AsmStr = "0b0101\n0xDEADBEEF\nfffh\n.133\n";
297 
298   // Setup.
299   setupCallToAsmParser(AsmStr);
300 
301   // Lex initially to get the string.
302   Parser->getLexer().Lex();
303 
304   SmallVector<AsmToken::TokenKind> ExpectedTokens;
305   ExpectedTokens.push_back(AsmToken::Integer);        // "0"
306   ExpectedTokens.push_back(AsmToken::Identifier);     // "b0101"
307   ExpectedTokens.push_back(AsmToken::EndOfStatement); // "\n"
308   ExpectedTokens.push_back(AsmToken::Integer);        // "0"
309   ExpectedTokens.push_back(AsmToken::Identifier);     // "xDEADBEEF"
310   ExpectedTokens.push_back(AsmToken::EndOfStatement); // "\n"
311   ExpectedTokens.push_back(AsmToken::Identifier);     // "fffh"
312   ExpectedTokens.push_back(AsmToken::EndOfStatement); // "\n"
313   ExpectedTokens.push_back(AsmToken::Real);           // ".133"
314   ExpectedTokens.push_back(AsmToken::EndOfStatement); // "\n"
315   ExpectedTokens.push_back(AsmToken::Eof);
316   lexAndCheckTokens(AsmStr, ExpectedTokens);
317 }
318 
TEST_F(SystemZAsmLexerLinux,CheckDefaultIntegers)319 TEST_F(SystemZAsmLexerLinux, CheckDefaultIntegers) {
320   StringRef AsmStr = "0b0101\n0xDEADBEEF\nfffh\n";
321 
322   // Setup.
323   setupCallToAsmParser(AsmStr);
324 
325   // Lex initially to get the string.
326   Parser->getLexer().Lex();
327 
328   SmallVector<int64_t> ExpectedValues({5, 0xDEADBEEF, 0xFFF});
329   lexAndCheckIntegerTokensAndValues(AsmStr, ExpectedValues);
330 }
331 
TEST_F(SystemZAsmLexerLinux,CheckDefaultFloats)332 TEST_F(SystemZAsmLexerLinux, CheckDefaultFloats) {
333   StringRef AsmStr = "0.333\n1.3\n2.5\n3.0\n";
334 
335   // Setup.
336   setupCallToAsmParser(AsmStr);
337 
338   // Lex initially to get the string.
339   Parser->getLexer().Lex();
340 
341   SmallVector<AsmToken::TokenKind> ExpectedTokens;
342 
343   for (int I = 0; I < 4; ++I)
344     ExpectedTokens.insert(ExpectedTokens.begin(),
345                           {AsmToken::Real, AsmToken::EndOfStatement});
346 
347   ExpectedTokens.push_back(AsmToken::Eof);
348   lexAndCheckTokens(AsmStr, ExpectedTokens);
349 }
350 
TEST_F(SystemZAsmLexerLinux,CheckDefaultQuestionAtStartOfIdentifier)351 TEST_F(SystemZAsmLexerLinux, CheckDefaultQuestionAtStartOfIdentifier) {
352   StringRef AsmStr = "?lh1?23";
353 
354   // Setup.
355   setupCallToAsmParser(AsmStr);
356 
357   // Lex initially to get the string.
358   Parser->getLexer().Lex();
359 
360   SmallVector<AsmToken::TokenKind> ExpectedTokens(
361       {AsmToken::Question, AsmToken::Identifier, AsmToken::EndOfStatement,
362        AsmToken::Eof});
363   lexAndCheckTokens(AsmStr, ExpectedTokens);
364 }
365 
TEST_F(SystemZAsmLexerLinux,CheckDefaultAtAtStartOfIdentifier)366 TEST_F(SystemZAsmLexerLinux, CheckDefaultAtAtStartOfIdentifier) {
367   StringRef AsmStr = "@@lh1?23";
368 
369   // Setup.
370   setupCallToAsmParser(AsmStr);
371 
372   // Lex initially to get the string.
373   Parser->getLexer().Lex();
374 
375   SmallVector<AsmToken::TokenKind> ExpectedTokens(
376       {AsmToken::At, AsmToken::At, AsmToken::Identifier,
377        AsmToken::EndOfStatement, AsmToken::Eof});
378   lexAndCheckTokens(AsmStr, ExpectedTokens);
379 }
380 
TEST_F(SystemZAsmLexerZOS,CheckAcceptAtAtStartOfIdentifier)381 TEST_F(SystemZAsmLexerZOS, CheckAcceptAtAtStartOfIdentifier) {
382   StringRef AsmStr = "@@lh1?23";
383 
384   // Setup.
385   setupCallToAsmParser(AsmStr);
386 
387   // Lex initially to get the string.
388   Parser->getLexer().Lex();
389 
390   SmallVector<AsmToken::TokenKind> ExpectedTokens(
391       {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
392   lexAndCheckTokens(AsmStr, ExpectedTokens);
393 }
394 
TEST_F(SystemZAsmLexerLinux,CheckDefaultDollarAtStartOfIdentifier)395 TEST_F(SystemZAsmLexerLinux, CheckDefaultDollarAtStartOfIdentifier) {
396   StringRef AsmStr = "$$ac$c";
397 
398   // Setup.
399   setupCallToAsmParser(AsmStr);
400 
401   // Lex initially to get the string.
402   Parser->getLexer().Lex();
403 
404   SmallVector<AsmToken::TokenKind> ExpectedTokens(
405       {AsmToken::Dollar, AsmToken::Dollar, AsmToken::Identifier,
406        AsmToken::EndOfStatement, AsmToken::Eof});
407   lexAndCheckTokens(AsmStr, ExpectedTokens);
408 }
409 
TEST_F(SystemZAsmLexerZOS,CheckAcceptDollarAtStartOfIdentifier)410 TEST_F(SystemZAsmLexerZOS, CheckAcceptDollarAtStartOfIdentifier) {
411   StringRef AsmStr = "$$ab$c";
412 
413   // Setup.
414   setupCallToAsmParser(AsmStr);
415 
416   // Lex initially to get the string.
417   Parser->getLexer().Lex();
418 
419   SmallVector<AsmToken::TokenKind> ExpectedTokens(
420       {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
421   lexAndCheckTokens(AsmStr, ExpectedTokens);
422 }
423 
TEST_F(SystemZAsmLexerZOS,CheckAcceptHashAtStartOfIdentifier)424 TEST_F(SystemZAsmLexerZOS, CheckAcceptHashAtStartOfIdentifier) {
425   StringRef AsmStr = "##a#b$c";
426 
427   // Setup.
428   setupCallToAsmParser(AsmStr);
429 
430   // Lex initially to get the string.
431   Parser->getLexer().Lex();
432 
433   SmallVector<AsmToken::TokenKind> ExpectedTokens(
434       {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
435   lexAndCheckTokens(AsmStr, ExpectedTokens);
436 }
437 
TEST_F(SystemZAsmLexerLinux,CheckAcceptHashAtStartOfIdentifier2)438 TEST_F(SystemZAsmLexerLinux, CheckAcceptHashAtStartOfIdentifier2) {
439   StringRef AsmStr = "##a#b$c";
440 
441   // Setup.
442   setupCallToAsmParser(AsmStr);
443 
444   // Lex initially to get the string.
445   Parser->getLexer().Lex();
446 
447   // By default, the CommentString attribute is set to "#".
448   // Hence, "##a#b$c" is lexed as a line comment irrespective
449   // of whether the AllowHashAtStartOfIdentifier attribute is set to true.
450   SmallVector<AsmToken::TokenKind> ExpectedTokens(
451       {AsmToken::EndOfStatement, AsmToken::Eof});
452   lexAndCheckTokens(AsmStr, ExpectedTokens);
453 }
454 
TEST_F(SystemZAsmLexerZOS,CheckAcceptHashAtStartOfIdentifier3)455 TEST_F(SystemZAsmLexerZOS, CheckAcceptHashAtStartOfIdentifier3) {
456   StringRef AsmStr = "##a#b$c";
457 
458   // Setup.
459   setupCallToAsmParser(AsmStr);
460 
461   // Lex initially to get the string.
462   Parser->getLexer().Lex();
463 
464   SmallVector<AsmToken::TokenKind> ExpectedTokens(
465       {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
466   lexAndCheckTokens(AsmStr, ExpectedTokens);
467 }
468 
TEST_F(SystemZAsmLexerZOS,CheckAcceptHashAtStartOfIdentifier4)469 TEST_F(SystemZAsmLexerZOS, CheckAcceptHashAtStartOfIdentifier4) {
470   StringRef AsmStr = "##a#b$c";
471 
472   // Setup.
473   setupCallToAsmParser(AsmStr);
474 
475   // Lex initially to get the string.
476   Parser->getLexer().Lex();
477 
478   // Since, the AllowAdditionalComments attribute is set to false,
479   // only strings starting with the CommentString attribute are
480   // lexed as possible comments.
481   // Hence, "##a$b$c" is lexed as an Identifier because the
482   // AllowHashAtStartOfIdentifier attribute is set to true.
483   SmallVector<AsmToken::TokenKind> ExpectedTokens(
484       {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
485   lexAndCheckTokens(AsmStr, ExpectedTokens);
486 }
487 
TEST_F(SystemZAsmLexerZOS,CheckRejectDotAsCurrentPC)488 TEST_F(SystemZAsmLexerZOS, CheckRejectDotAsCurrentPC) {
489   StringRef AsmStr = ".-4";
490 
491   // Setup.
492   setupCallToAsmParser(AsmStr);
493 
494   // Lex initially to get the string.
495   Parser->getLexer().Lex();
496 
497   const MCExpr *Expr;
498   bool ParsePrimaryExpr = Parser->parseExpression(Expr);
499   EXPECT_EQ(ParsePrimaryExpr, true);
500   EXPECT_EQ(Parser->hasPendingError(), true);
501 }
502 
TEST_F(SystemZAsmLexerLinux,CheckRejectStarAsCurrentPC)503 TEST_F(SystemZAsmLexerLinux, CheckRejectStarAsCurrentPC) {
504   StringRef AsmStr = "*-4";
505 
506   // Setup.
507   setupCallToAsmParser(AsmStr);
508 
509   // Lex initially to get the string.
510   Parser->getLexer().Lex();
511 
512   const MCExpr *Expr;
513   bool ParsePrimaryExpr = Parser->parseExpression(Expr);
514   EXPECT_EQ(ParsePrimaryExpr, true);
515   EXPECT_EQ(Parser->hasPendingError(), true);
516 }
517 
TEST_F(SystemZAsmLexerZOS,CheckRejectCharLiterals)518 TEST_F(SystemZAsmLexerZOS, CheckRejectCharLiterals) {
519   StringRef AsmStr = "abc 'd'";
520 
521   // Setup.
522   setupCallToAsmParser(AsmStr);
523 
524   // Lex initially to get the string.
525   Parser->getLexer().Lex();
526 
527   SmallVector<AsmToken::TokenKind> ExpectedTokens(
528       {AsmToken::Identifier, AsmToken::Space, AsmToken::Error, AsmToken::Error,
529        AsmToken::EndOfStatement, AsmToken::Eof});
530   lexAndCheckTokens(AsmStr, ExpectedTokens);
531 }
532 
TEST_F(SystemZAsmLexerZOS,CheckRejectStringLiterals)533 TEST_F(SystemZAsmLexerZOS, CheckRejectStringLiterals) {
534   StringRef AsmStr = "abc \"ef\"";
535 
536   // Setup.
537   setupCallToAsmParser(AsmStr);
538 
539   // Lex initially to get the string.
540   Parser->getLexer().Lex();
541 
542   SmallVector<AsmToken::TokenKind> ExpectedTokens(
543       {AsmToken::Identifier, AsmToken::Space, AsmToken::Error,
544        AsmToken::Identifier, AsmToken::Error, AsmToken::EndOfStatement,
545        AsmToken::Eof});
546   lexAndCheckTokens(AsmStr, ExpectedTokens);
547 }
548 
TEST_F(SystemZAsmLexerZOS,CheckPrintAcceptableSymbol)549 TEST_F(SystemZAsmLexerZOS, CheckPrintAcceptableSymbol) {
550   std::string AsmStr = "ab13_$.@";
551   EXPECT_EQ(true, MAI->isValidUnquotedName(AsmStr));
552   AsmStr += "#";
553   EXPECT_EQ(true, MAI->isValidUnquotedName(AsmStr));
554 }
555 
TEST_F(SystemZAsmLexerLinux,CheckPrintAcceptableSymbol)556 TEST_F(SystemZAsmLexerLinux, CheckPrintAcceptableSymbol) {
557   std::string AsmStr = "ab13_$.";
558   EXPECT_EQ(true, MAI->isValidUnquotedName(AsmStr));
559   AsmStr = "ab13_$.@";
560   EXPECT_EQ(false, MAI->isValidUnquotedName(AsmStr));
561   AsmStr = "ab13_$.#";
562   EXPECT_EQ(false, MAI->isValidUnquotedName(AsmStr));
563 }
564 
TEST_F(SystemZAsmLexerZOS,CheckLabelCaseUpperCase)565 TEST_F(SystemZAsmLexerZOS, CheckLabelCaseUpperCase) {
566   StringRef AsmStr = "label";
567 
568   // Setup.
569   setupCallToAsmParser(AsmStr);
570 
571   // Lex initially to get the string.
572   Parser->getLexer().Lex();
573 
574   const MCExpr *Expr;
575   bool ParsePrimaryExpr = Parser->parseExpression(Expr);
576   EXPECT_EQ(ParsePrimaryExpr, false);
577 
578   const MCSymbolRefExpr *SymbolExpr = dyn_cast<MCSymbolRefExpr>(Expr);
579   EXPECT_NE(SymbolExpr, nullptr);
580   EXPECT_NE(&SymbolExpr->getSymbol(), nullptr);
581   EXPECT_EQ((&SymbolExpr->getSymbol())->getName(), StringRef("LABEL"));
582 }
583 
TEST_F(SystemZAsmLexerLinux,CheckLabelUpperCase2)584 TEST_F(SystemZAsmLexerLinux, CheckLabelUpperCase2) {
585   StringRef AsmStr = "label";
586 
587   // Setup.
588   setupCallToAsmParser(AsmStr);
589 
590   // Lex initially to get the string.
591   Parser->getLexer().Lex();
592 
593   const MCExpr *Expr;
594   bool ParsePrimaryExpr = Parser->parseExpression(Expr);
595   EXPECT_EQ(ParsePrimaryExpr, false);
596 
597   const MCSymbolRefExpr *SymbolExpr = dyn_cast<MCSymbolRefExpr>(Expr);
598   EXPECT_NE(SymbolExpr, nullptr);
599   EXPECT_NE(&SymbolExpr->getSymbol(), nullptr);
600   EXPECT_EQ((&SymbolExpr->getSymbol())->getName(), StringRef("label"));
601 }
602 } // end anonymous namespace
603