llvm.org GIT mirror llvm / 0086358
MC: AsmLexer: handle multi-character CommentStrings correctly As X86MCAsmInfoDarwin uses '##' as CommentString although a single '#' starts a comment a workaround for this special case is added. Fixes divisions in constant expressions for the AArch64 assembler and other targets which use '//' as CommentString. Patch by Janne Grunau! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215615 91177308-0d34-0410-b5e6-96231b3b80d8 Saleem Abdulrasool 6 years ago
4 changed file(s) with 34 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
4848
4949 const AsmToken peekTok(bool ShouldSkipSpace = true) override;
5050
51 bool isAtStartOfComment(char Char);
51 bool isAtStartOfComment(const char *Ptr);
5252 bool isAtStatementSeparator(const char *Ptr);
5353
5454 const MCAsmInfo &getMAI() const { return MAI; }
416416 StringRef AsmLexer::LexUntilEndOfStatement() {
417417 TokStart = CurPtr;
418418
419 while (!isAtStartOfComment(*CurPtr) && // Start of line comment.
419 while (!isAtStartOfComment(CurPtr) && // Start of line comment.
420420 !isAtStatementSeparator(CurPtr) && // End of statement marker.
421421 *CurPtr != '\n' && *CurPtr != '\r' &&
422422 (*CurPtr != 0 || CurPtr != CurBuf.end())) {
457457 return Token;
458458 }
459459
460 bool AsmLexer::isAtStartOfComment(char Char) {
461 // FIXME: This won't work for multi-character comment indicators like "//".
462 return Char == *MAI.getCommentString();
460 bool AsmLexer::isAtStartOfComment(const char *Ptr) {
461 const char *CommentString = MAI.getCommentString();
462
463 if (CommentString[1] == '\0')
464 return CommentString[0] == Ptr[0];
465
466 // FIXME: special case for the bogus "##" comment string in X86MCAsmInfoDarwin
467 if (CommentString[1] == '#')
468 return CommentString[0] == Ptr[0];
469
470 return strncmp(Ptr, CommentString, strlen(CommentString)) == 0;
463471 }
464472
465473 bool AsmLexer::isAtStatementSeparator(const char *Ptr) {
472480 // This always consumes at least one character.
473481 int CurChar = getNextChar();
474482
475 if (isAtStartOfComment(CurChar)) {
483 if (isAtStartOfComment(TokStart)) {
476484 // If this comment starts with a '#', then return the Hash token and let
477485 // the assembler parser see if it can be parsed as a cpp line filename
478486 // comment. We do this only if we are at the start of a line.
0 // RUN: llvm-mc -triple aarch64-none-linux-gnu < %s | FileCheck %s
1
2 // Test that a single slash is not mistaken as the start of comment.
3
4 //CHECK: movz x0, #0x10
5 movz x0, #(32 / 2)
0 // RUN: llvm-mc -triple x86_64-apple-darwin %s 2>&1 | FileCheck %s
1 # ensure that single '#' comments are worink as expected on x86 darwin
2 .align 3 # test single hash after align
3 // CHECK: .align 3
4 foo: # single hash should be ignored as comment
5 // CHECK-LABEL: foo:
6 movl %esp, %ebp # same after an instruction
7 // CHECK: movl %esp, %ebp
8 # movl %esp, %ebp ## start of the line
9 // CHECK-NOT: movl %esp, %ebp
10 # movl %esp, %ebp ## not quite start of the line
11 // CHECK-NOT: movl %esp, %ebp
12 bar:
13 // CHECK-LABEL: bar: