Directive parsing for AsmParser

I’m trying to build a standalone assembler for Mips using AsmParser and I’m facing a problem with assembly directives. Mips assembler has following syntax for .set directive

.set reorder

or

.set noreorder

which allow/disallow assembler to change the order of instructions in the block that follows. As the implemented AsmParser requires .set directive to have the following syntax:

/// ParseDirectiveSet:
/// ::= .set identifier ‘,’ expression

I am getting an error reported when ‘.set reoeder/noreorder’ is met in the code. After some investigation it seems reasonable for me to move the code which handles target specific directive parsing from the end to the beginning of the block, like this (AsmParser::ParseStatement, AsmParser.cpp line 1225):

// Otherwise, we have a normal instruction or directive.
if (IDVal[0] == ‘.’ && IDVal != “.”) {

// Target hook for parsing target specific directives.
if (!getTargetParser().ParseDirective(ID))
return false;
.
.
.
.
}
thus allowing the target specific directives to be handled first rather then at the end.

What is your opinion regarding this change?

Kind regards

Vladimir

Hi Vladimir,

This sounds reasonable to me. Allowing a target to hook into otherwise generic directives seems a good thing. Copious testing to make sure there’s nothing subtle going on would be a good idea, of course. :slight_smile:

-Jim