forked from OSchip/llvm-project
llvm-mc: Accept relocatable expressions for .org, assignments, .byte, etc.
llvm-svn: 74498
This commit is contained in:
parent
19f847fa68
commit
75630b355a
|
@ -3,7 +3,13 @@
|
||||||
// greps).
|
// greps).
|
||||||
|
|
||||||
// RUN: llvm-mc %s > %t
|
// RUN: llvm-mc %s > %t
|
||||||
|
|
||||||
|
.text
|
||||||
|
g:
|
||||||
|
h:
|
||||||
|
j:
|
||||||
|
k:
|
||||||
|
.data
|
||||||
.byte !1 + 2
|
.byte !1 + 2
|
||||||
.byte !0
|
.byte !0
|
||||||
.byte ~0
|
.byte ~0
|
||||||
|
@ -36,4 +42,14 @@
|
||||||
|
|
||||||
.set c, 10
|
.set c, 10
|
||||||
.byte c + 1
|
.byte c + 1
|
||||||
|
|
||||||
|
d = e + 10
|
||||||
|
.long d
|
||||||
|
|
||||||
|
f = g - h + 5
|
||||||
|
.long f
|
||||||
|
|
||||||
|
i = (j + 10) - (k + 2)
|
||||||
|
.long i
|
||||||
|
|
||||||
|
|
|
@ -144,11 +144,12 @@ bool AsmParser::ParseExpression(AsmExpr *&Res) {
|
||||||
bool AsmParser::ParseAbsoluteExpression(int64_t &Res) {
|
bool AsmParser::ParseAbsoluteExpression(int64_t &Res) {
|
||||||
AsmExpr *Expr;
|
AsmExpr *Expr;
|
||||||
|
|
||||||
|
SMLoc StartLoc = Lexer.getLoc();
|
||||||
if (ParseExpression(Expr))
|
if (ParseExpression(Expr))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!Expr->EvaluateAsAbsolute(Ctx, Res))
|
if (!Expr->EvaluateAsAbsolute(Ctx, Res))
|
||||||
return TokError("expected absolute expression");
|
return Error(StartLoc, "expected absolute expression");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -156,11 +157,12 @@ bool AsmParser::ParseAbsoluteExpression(int64_t &Res) {
|
||||||
bool AsmParser::ParseRelocatableExpression(MCValue &Res) {
|
bool AsmParser::ParseRelocatableExpression(MCValue &Res) {
|
||||||
AsmExpr *Expr;
|
AsmExpr *Expr;
|
||||||
|
|
||||||
|
SMLoc StartLoc = Lexer.getLoc();
|
||||||
if (ParseExpression(Expr))
|
if (ParseExpression(Expr))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!Expr->EvaluateAsRelocatable(Ctx, Res))
|
if (!Expr->EvaluateAsRelocatable(Ctx, Res))
|
||||||
return TokError("expected relocatable expression");
|
return Error(StartLoc, "expected relocatable expression");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -525,8 +527,8 @@ bool AsmParser::ParseAssignment(const char *Name, bool IsDotSet) {
|
||||||
// FIXME: Use better location, we should use proper tokens.
|
// FIXME: Use better location, we should use proper tokens.
|
||||||
SMLoc EqualLoc = Lexer.getLoc();
|
SMLoc EqualLoc = Lexer.getLoc();
|
||||||
|
|
||||||
int64_t Value;
|
MCValue Value;
|
||||||
if (ParseAbsoluteExpression(Value))
|
if (ParseRelocatableExpression(Value))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (Lexer.isNot(asmtok::EndOfStatement))
|
if (Lexer.isNot(asmtok::EndOfStatement))
|
||||||
|
@ -549,7 +551,7 @@ bool AsmParser::ParseAssignment(const char *Name, bool IsDotSet) {
|
||||||
return Error(EqualLoc, "invalid assignment to external symbol");
|
return Error(EqualLoc, "invalid assignment to external symbol");
|
||||||
|
|
||||||
// Do the assignment.
|
// Do the assignment.
|
||||||
Out.EmitAssignment(Sym, MCValue::get(Value), IsDotSet);
|
Out.EmitAssignment(Sym, Value, IsDotSet);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -651,11 +653,11 @@ bool AsmParser::ParseDirectiveAscii(bool ZeroTerminated) {
|
||||||
bool AsmParser::ParseDirectiveValue(unsigned Size) {
|
bool AsmParser::ParseDirectiveValue(unsigned Size) {
|
||||||
if (Lexer.isNot(asmtok::EndOfStatement)) {
|
if (Lexer.isNot(asmtok::EndOfStatement)) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int64_t Expr;
|
MCValue Expr;
|
||||||
if (ParseAbsoluteExpression(Expr))
|
if (ParseRelocatableExpression(Expr))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Out.EmitValue(MCValue::get(Expr), Size);
|
Out.EmitValue(Expr, Size);
|
||||||
|
|
||||||
if (Lexer.is(asmtok::EndOfStatement))
|
if (Lexer.is(asmtok::EndOfStatement))
|
||||||
break;
|
break;
|
||||||
|
@ -746,8 +748,8 @@ bool AsmParser::ParseDirectiveFill() {
|
||||||
/// ParseDirectiveOrg
|
/// ParseDirectiveOrg
|
||||||
/// ::= .org expression [ , expression ]
|
/// ::= .org expression [ , expression ]
|
||||||
bool AsmParser::ParseDirectiveOrg() {
|
bool AsmParser::ParseDirectiveOrg() {
|
||||||
int64_t Offset;
|
MCValue Offset;
|
||||||
if (ParseAbsoluteExpression(Offset))
|
if (ParseRelocatableExpression(Offset))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Parse optional fill expression.
|
// Parse optional fill expression.
|
||||||
|
@ -765,8 +767,10 @@ bool AsmParser::ParseDirectiveOrg() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Lexer.Lex();
|
Lexer.Lex();
|
||||||
|
|
||||||
Out.EmitValueToOffset(MCValue::get(Offset), FillExpr);
|
// FIXME: Only limited forms of relocatable expressions are accepted here, it
|
||||||
|
// has to be relative to the current section.
|
||||||
|
Out.EmitValueToOffset(Offset, FillExpr);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue