mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-21 18:22:53 +01:00
[AsmParser][SystemZ][z/OS] Support for emitting labels in upper case
- Currently, the emitting of labels in the parsePrimaryExpr function is case independent. It just takes the identifier and emits it. - However, for HLASM the emitting of labels is case independent. We are emitting them in the upper case only, to enforce case independency. So we need to ensure that at the time of parsing the label we are emitting the upper case (in `parseAsHLASMLabel`), but also, when we are processing a PC-relative relocatable expression, we need to ensure we emit it in upper case (in `parsePrimaryExpr`) - To achieve this a new MCAsmInfo attribute has been introduced which corresponding targets can override if needed. Reviewed By: abhina.sreeskantharajan, uweigand Differential Revision: https://reviews.llvm.org/D104715
This commit is contained in:
parent
d12ae1eaf8
commit
6fc759537e
@ -153,6 +153,9 @@ protected:
|
||||
/// This is appended to emitted labels. Defaults to ":"
|
||||
const char *LabelSuffix;
|
||||
|
||||
/// Emit labels in purely upper case. Defaults to false.
|
||||
bool EmitLabelsInUpperCase = false;
|
||||
|
||||
// Print the EH begin symbol with an assignment. Defaults to false.
|
||||
bool UseAssignmentForEHBegin = false;
|
||||
|
||||
@ -637,6 +640,7 @@ public:
|
||||
return EmitGNUAsmStartIndentationMarker;
|
||||
}
|
||||
const char *getLabelSuffix() const { return LabelSuffix; }
|
||||
bool shouldEmitLabelsInUpperCase() const { return EmitLabelsInUpperCase; }
|
||||
|
||||
bool useAssignmentForEHBegin() const { return UseAssignmentForEHBegin; }
|
||||
bool needsLocalForSize() const { return NeedsLocalForSize; }
|
||||
|
@ -1231,7 +1231,8 @@ bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc,
|
||||
|
||||
MCSymbol *Sym = getContext().getInlineAsmLabel(SymbolName);
|
||||
if (!Sym)
|
||||
Sym = getContext().getOrCreateSymbol(SymbolName);
|
||||
Sym = getContext().getOrCreateSymbol(
|
||||
MAI.shouldEmitLabelsInUpperCase() ? SymbolName.upper() : SymbolName);
|
||||
|
||||
// If this is an absolute variable reference, substitute it now to preserve
|
||||
// semantics in the face of reassignment.
|
||||
@ -6212,8 +6213,10 @@ bool HLASMAsmParser::parseAsHLASMLabel(ParseStatementInfo &Info,
|
||||
return Error(LabelLoc,
|
||||
"Cannot have just a label for an HLASM inline asm statement");
|
||||
|
||||
// FIXME: Later on, ensure emitted labels are case-insensitive.
|
||||
MCSymbol *Sym = getContext().getOrCreateSymbol(LabelVal);
|
||||
MCSymbol *Sym = getContext().getOrCreateSymbol(
|
||||
getContext().getAsmInfo()->shouldEmitLabelsInUpperCase()
|
||||
? LabelVal.upper()
|
||||
: LabelVal);
|
||||
|
||||
getTargetParser().doBeforeLabelEmit(Sym);
|
||||
|
||||
|
@ -31,6 +31,7 @@ SystemZMCAsmInfo::SystemZMCAsmInfo(const Triple &TT) {
|
||||
StarIsPC = (AssemblerDialect == AD_HLASM);
|
||||
EmitGNUAsmStartIndentationMarker = (AssemblerDialect == AD_ATT);
|
||||
AllowAtInName = (AssemblerDialect == AD_HLASM);
|
||||
EmitLabelsInUpperCase = (AssemblerDialect == AD_HLASM);
|
||||
|
||||
ZeroDirective = "\t.space\t";
|
||||
Data64bitsDirective = "\t.quad\t";
|
||||
|
@ -49,6 +49,7 @@ public:
|
||||
}
|
||||
void setAllowDotIsPC(bool Value) { DotIsPC = Value; }
|
||||
void setAssemblerDialect(unsigned Value) { AssemblerDialect = Value; }
|
||||
void setEmitLabelsInUpperCase(bool Value) { EmitLabelsInUpperCase = Value; }
|
||||
};
|
||||
|
||||
// Setup a testing class that the GTest framework can call.
|
||||
@ -750,4 +751,36 @@ TEST_F(SystemZAsmLexerTest, CheckPrintAcceptableSymbol2) {
|
||||
AsmStr += "#";
|
||||
EXPECT_EQ(true, MUPMAI->isValidUnquotedName(AsmStr));
|
||||
}
|
||||
|
||||
TEST_F(SystemZAsmLexerTest, CheckLabelCaseUpperCase2) {
|
||||
StringRef AsmStr = "label\nlabel";
|
||||
|
||||
// Setup.
|
||||
setupCallToAsmParser(AsmStr);
|
||||
|
||||
// Lex initially to get the string.
|
||||
Parser->getLexer().Lex();
|
||||
|
||||
const MCExpr *Expr;
|
||||
bool ParsePrimaryExpr = Parser->parseExpression(Expr);
|
||||
EXPECT_EQ(ParsePrimaryExpr, false);
|
||||
|
||||
const MCSymbolRefExpr *SymbolExpr = dyn_cast<MCSymbolRefExpr>(Expr);
|
||||
EXPECT_NE(SymbolExpr, nullptr);
|
||||
EXPECT_NE(&SymbolExpr->getSymbol(), nullptr);
|
||||
EXPECT_EQ((&SymbolExpr->getSymbol())->getName(), StringRef("label"));
|
||||
|
||||
// Lex the end of statement token.
|
||||
Parser->getLexer().Lex();
|
||||
|
||||
MUPMAI->setEmitLabelsInUpperCase(true);
|
||||
|
||||
ParsePrimaryExpr = Parser->parseExpression(Expr);
|
||||
EXPECT_EQ(ParsePrimaryExpr, false);
|
||||
|
||||
SymbolExpr = dyn_cast<MCSymbolRefExpr>(Expr);
|
||||
EXPECT_NE(SymbolExpr, nullptr);
|
||||
EXPECT_NE(&SymbolExpr->getSymbol(), nullptr);
|
||||
EXPECT_EQ((&SymbolExpr->getSymbol())->getName(), StringRef("LABEL"));
|
||||
}
|
||||
} // end anonymous namespace
|
||||
|
Loading…
Reference in New Issue
Block a user