This is an archive of the discontinued LLVM Phabricator instance.

[LLVM][inline-asm][Altmacor] Altmacro string delimiter '<..>'
ClosedPublic

Authored by m_zuckerman on May 1 2017, 8:38 AM.

Details

Summary

In this patch, I introduce a new altmacro string delimiter.
This review is the second review in a series of four reviews.
(one for each altmacro feature: LOCAL, string delimiter, string '!' escape sign and absolute expression as a string '%' ).

In the alternate macro mode, you can delimit strings with matching angle brackets <..>
when using it as a part of calling macro arguments.

As described in the https://sourceware.org/binutils/docs-2.27/as/Altmacro.html
"<string>
You can delimit strings with matching angle brackets."

assumptions:

  1. If an argument begins with '<' and ends with '>'. The argument is considered as a string.
  2. Except adding new string mark '<..>', a regular macro behavior is expected.
  3. The altmacro cannot affect the regular less/greater behavior.
  4. If a comma is present inside an angle brackets it considered as a character and not as a separator.

Diff Detail

Repository
rL LLVM

Event Timeline

m_zuckerman created this revision.May 1 2017, 8:38 AM
m_zuckerman edited the summary of this revision. (Show Details)
m_zuckerman retitled this revision from [LLVM][inline-asm] Altmacro string delimiter '<..>' to [LLVM][inline-asm][Altmacor] Altmacro string delimiter '<..>'.May 1 2017, 8:49 AM
m_zuckerman edited the summary of this revision. (Show Details)
m_zuckerman added reviewers: rengolin, rnk, grosbach.
m_zuckerman added a subscriber: llvm-commits.
m_zuckerman edited the summary of this revision. (Show Details)May 1 2017, 8:53 AM
rengolin added inline comments.May 2 2017, 4:25 AM
lib/MC/MCParser/AsmParser.cpp
1201 ↗(On Diff #97400)

I'd add single quotes at the same time.

This seems like a simple addition, as you can pass the expected "ending char" as an argument, in addition to \r\n\0.

2501 ↗(On Diff #97400)

Format else in the same line, like } else {

m_zuckerman marked an inline comment as done.
rengolin added inline comments.May 3 2017, 4:07 AM
lib/MC/MCParser/AsmParser.cpp
1201 ↗(On Diff #97400)

The problem here, IIUC, is that you could start with '<' and end with single-quote (or vice-versa) and this code would accept. Also, if you start with '<', single-quote isn't actually a terminator.

To make sure this works, you have to test four overall patterns:

  • <foo,bar>
  • <foo'bar>
  • 'foo,bar'
  • 'foo>bar'

They all have to produce a single string "foo?bar".

What I meant was something like:

bool AsmParser::isAltmacroString(SMLoc &StrLoc, SMLoc &EndLoc, const char Term) {
  ...
  while ((*CharPtr != Term) && (*CharPtr != '\n') && (*CharPtr != '\r') && (*CharPtr != '\0')) {
    CharPtr++;
}

And then down there, something like:

} else if (Lexer.IsaAltMacroMode() && Lexer.is(AsmToken::Less) && Lexer.is(AsmToken::SingleQuote) &&
           isAltmacroString(StrLoc, EndLoc, Lex()) {

or something.

m_zuckerman added inline comments.May 3 2017, 7:07 AM
lib/MC/MCParser/AsmParser.cpp
1201 ↗(On Diff #97400)
  1. The code will not accept it because the last character that I check is '>'. So if the code ends with "\ '". The function returns false since it does not equal to '>' as required by the second if.
  1. regard the <foo'bar>: I don't really sure what is the usage of it.

GAS doesn't really support the "\'" delimiter and the only full support that I found using https://godbolt.org/ was for the "<...>".

  1. I prefer only to support '<..>' as in GCC. And I don't mind to define single quote as a string in altmacro, but it must end with a single quote.
rengolin edited edge metadata.May 3 2017, 7:14 AM

With that in mind, I think you should then go back to your original implementation (ignore quotes) and let the expression evaluation crash if there's any single quote in between (or whatever is the expected behaviour).

Maybe we should, then, add a comment on that function, saying the docs mention single-quotes but GCC doesn't support, so we won't either.

Sorry for the confusion.

cheers,
--renato

lib/MC/MCParser/AsmParser.cpp
1201 ↗(On Diff #97400)

Oh, I was not aware the single quotes were unsupported in GCC. That's what I get for trusting their docs... :)

m_zuckerman updated this revision to Diff 97639.May 3 2017, 7:19 AM

The behaviors are very strange when working with single quotes, so I prefer only to do partial support (strings) or not at all.

No worry :) we love to play with the code

You seem to have lost the negative test.

lib/MC/MCParser/AsmLexer.cpp
464 ↗(On Diff #97639)

Delimiter

test/MC/AsmParser/altmacro_string.s
28 ↗(On Diff #97639)

Shouldn't this be $1?

m_zuckerman updated this revision to Diff 97794.May 4 2017, 2:02 AM

As discussed, I have returned to the <...> implementation without the single quote and I added a negative test.

rengolin accepted this revision.May 4 2017, 2:09 AM

LGTM. Thanks!

This revision is now accepted and ready to land.May 4 2017, 2:09 AM
This revision was automatically updated to reflect the committed changes.