mirror of
https://github.com/RPCS3/llvm.git
synced 2025-02-23 04:01:16 +00:00
llvm-mc: Pass values to MCStreamer as MCExprs, not MCValues.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80578 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e2ace509fc
commit
821e3334ed
@ -21,10 +21,10 @@ namespace llvm {
|
||||
class MCAsmInfo;
|
||||
class MCCodeEmitter;
|
||||
class MCContext;
|
||||
class MCExpr;
|
||||
class MCInst;
|
||||
class MCSection;
|
||||
class MCSymbol;
|
||||
class MCValue;
|
||||
class StringRef;
|
||||
class raw_ostream;
|
||||
|
||||
@ -116,7 +116,7 @@ namespace llvm {
|
||||
///
|
||||
/// @param Symbol - The symbol being assigned to.
|
||||
/// @param Value - The value for the symbol.
|
||||
virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value) = 0;
|
||||
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0;
|
||||
|
||||
/// EmitSymbolAttribute - Add the given @param Attribute to @param Symbol.
|
||||
virtual void EmitSymbolAttribute(MCSymbol *Symbol,
|
||||
@ -166,7 +166,7 @@ namespace llvm {
|
||||
/// @param Value - The value to emit.
|
||||
/// @param Size - The size of the integer (in bytes) to emit. This must
|
||||
/// match a native machine width.
|
||||
virtual void EmitValue(const MCValue &Value, unsigned Size) = 0;
|
||||
virtual void EmitValue(const MCExpr *Value, unsigned Size) = 0;
|
||||
|
||||
/// EmitValueToAlignment - Emit some number of copies of @param Value until
|
||||
/// the byte alignment @param ByteAlignment is reached.
|
||||
@ -197,7 +197,7 @@ namespace llvm {
|
||||
/// @param Offset - The offset to reach. This may be an expression, but the
|
||||
/// expression must be associated with the current section.
|
||||
/// @param Value - The value to use when filling bytes.
|
||||
virtual void EmitValueToOffset(const MCValue &Offset,
|
||||
virtual void EmitValueToOffset(const MCExpr *Offset,
|
||||
unsigned char Value = 0) = 0;
|
||||
|
||||
/// @}
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "llvm/MC/MCInst.h"
|
||||
#include "llvm/MC/MCSectionMachO.h"
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
#include "llvm/MC/MCValue.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
@ -47,7 +46,7 @@ public:
|
||||
|
||||
virtual void EmitAssemblerFlag(AssemblerFlag Flag);
|
||||
|
||||
virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value);
|
||||
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
|
||||
|
||||
virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute);
|
||||
|
||||
@ -61,13 +60,13 @@ public:
|
||||
|
||||
virtual void EmitBytes(const StringRef &Data);
|
||||
|
||||
virtual void EmitValue(const MCValue &Value, unsigned Size);
|
||||
virtual void EmitValue(const MCExpr *Value, unsigned Size);
|
||||
|
||||
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
|
||||
unsigned ValueSize = 1,
|
||||
unsigned MaxBytesToEmit = 0);
|
||||
|
||||
virtual void EmitValueToOffset(const MCValue &Offset,
|
||||
virtual void EmitValueToOffset(const MCExpr *Offset,
|
||||
unsigned char Value = 0);
|
||||
|
||||
virtual void EmitInstruction(const MCInst &Inst);
|
||||
@ -86,7 +85,7 @@ static inline raw_ostream &operator<<(raw_ostream &os, const MCSymbol *S) {
|
||||
}
|
||||
|
||||
/// Allow printing values directly to a raw_ostream.
|
||||
static inline raw_ostream &operator<<(raw_ostream &os, const MCValue &Value) {
|
||||
static inline raw_ostream &operator<<(raw_ostream &os, const MCExpr &Value) {
|
||||
Value.print(os);
|
||||
return os;
|
||||
}
|
||||
@ -96,9 +95,10 @@ static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
|
||||
return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
|
||||
}
|
||||
|
||||
static inline MCValue truncateToSize(const MCValue &Value, unsigned Bytes) {
|
||||
return MCValue::get(Value.getSymA(), Value.getSymB(),
|
||||
truncateToSize(Value.getConstant(), Bytes));
|
||||
static inline const MCExpr *truncateToSize(const MCExpr *Value,
|
||||
unsigned Bytes) {
|
||||
// FIXME: Do we really need this routine?
|
||||
return Value;
|
||||
}
|
||||
|
||||
void MCAsmStreamer::SwitchSection(const MCSection *Section) {
|
||||
@ -125,12 +125,12 @@ void MCAsmStreamer::EmitAssemblerFlag(AssemblerFlag Flag) {
|
||||
OS << '\n';
|
||||
}
|
||||
|
||||
void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCValue &Value) {
|
||||
void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
|
||||
// Only absolute symbols can be redefined.
|
||||
assert((Symbol->isUndefined() || Symbol->isAbsolute()) &&
|
||||
"Cannot define a symbol twice!");
|
||||
|
||||
OS << Symbol << " = " << Value << '\n';
|
||||
OS << Symbol << " = " << *Value << '\n';
|
||||
}
|
||||
|
||||
void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
|
||||
@ -189,7 +189,7 @@ void MCAsmStreamer::EmitBytes(const StringRef &Data) {
|
||||
OS << ".byte " << (unsigned) (unsigned char) Data[i] << '\n';
|
||||
}
|
||||
|
||||
void MCAsmStreamer::EmitValue(const MCValue &Value, unsigned Size) {
|
||||
void MCAsmStreamer::EmitValue(const MCExpr *Value, unsigned Size) {
|
||||
assert(CurSection && "Cannot emit contents before setting section!");
|
||||
// Need target hooks to know how to print this.
|
||||
switch (Size) {
|
||||
@ -201,7 +201,7 @@ void MCAsmStreamer::EmitValue(const MCValue &Value, unsigned Size) {
|
||||
case 8: OS << ".quad"; break;
|
||||
}
|
||||
|
||||
OS << ' ' << truncateToSize(Value, Size) << '\n';
|
||||
OS << ' ' << *truncateToSize(Value, Size) << '\n';
|
||||
}
|
||||
|
||||
void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
|
||||
@ -251,10 +251,10 @@ void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
|
||||
OS << '\n';
|
||||
}
|
||||
|
||||
void MCAsmStreamer::EmitValueToOffset(const MCValue &Offset,
|
||||
void MCAsmStreamer::EmitValueToOffset(const MCExpr *Offset,
|
||||
unsigned char Value) {
|
||||
// FIXME: Verify that Offset is associated with the current section.
|
||||
OS << ".org " << Offset << ", " << (unsigned) Value << '\n';
|
||||
OS << ".org " << *Offset << ", " << (unsigned) Value << '\n';
|
||||
}
|
||||
|
||||
void MCAsmStreamer::EmitInstruction(const MCInst &Inst) {
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "llvm/MC/MCInst.h"
|
||||
#include "llvm/MC/MCSection.h"
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
#include "llvm/MC/MCValue.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
using namespace llvm;
|
||||
@ -88,14 +89,6 @@ public:
|
||||
CurSectionData(0) {}
|
||||
~MCMachOStreamer() {}
|
||||
|
||||
const MCValue &AddValueSymbols(const MCValue &Value) {
|
||||
if (Value.getSymA())
|
||||
getSymbolData(*const_cast<MCSymbol*>(Value.getSymA()));
|
||||
if (Value.getSymB())
|
||||
getSymbolData(*const_cast<MCSymbol*>(Value.getSymB()));
|
||||
return Value;
|
||||
}
|
||||
|
||||
const MCExpr *AddValueSymbols(const MCExpr *Value) {
|
||||
switch (Value->getKind()) {
|
||||
case MCExpr::Constant:
|
||||
@ -129,7 +122,7 @@ public:
|
||||
|
||||
virtual void EmitAssemblerFlag(AssemblerFlag Flag);
|
||||
|
||||
virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value);
|
||||
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
|
||||
|
||||
virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute);
|
||||
|
||||
@ -143,13 +136,13 @@ public:
|
||||
|
||||
virtual void EmitBytes(const StringRef &Data);
|
||||
|
||||
virtual void EmitValue(const MCValue &Value, unsigned Size);
|
||||
virtual void EmitValue(const MCExpr *Value, unsigned Size);
|
||||
|
||||
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
|
||||
unsigned ValueSize = 1,
|
||||
unsigned MaxBytesToEmit = 0);
|
||||
|
||||
virtual void EmitValueToOffset(const MCValue &Offset,
|
||||
virtual void EmitValueToOffset(const MCExpr *Offset,
|
||||
unsigned char Value = 0);
|
||||
|
||||
virtual void EmitInstruction(const MCInst &Inst);
|
||||
@ -200,7 +193,7 @@ void MCMachOStreamer::EmitAssemblerFlag(AssemblerFlag Flag) {
|
||||
assert(0 && "invalid assembler flag!");
|
||||
}
|
||||
|
||||
void MCMachOStreamer::EmitAssignment(MCSymbol *Symbol, const MCValue &Value) {
|
||||
void MCMachOStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
|
||||
// Only absolute symbols can be redefined.
|
||||
assert((Symbol->isUndefined() || Symbol->isAbsolute()) &&
|
||||
"Cannot define a symbol twice!");
|
||||
@ -327,8 +320,13 @@ void MCMachOStreamer::EmitBytes(const StringRef &Data) {
|
||||
DF->getContents().append(Data.begin(), Data.end());
|
||||
}
|
||||
|
||||
void MCMachOStreamer::EmitValue(const MCValue &Value, unsigned Size) {
|
||||
new MCFillFragment(AddValueSymbols(Value), Size, 1, CurSectionData);
|
||||
void MCMachOStreamer::EmitValue(const MCExpr *Value, unsigned Size) {
|
||||
MCValue RelocValue;
|
||||
|
||||
if (!AddValueSymbols(Value)->EvaluateAsRelocatable(getContext(), RelocValue))
|
||||
return llvm_report_error("expected relocatable expression");
|
||||
|
||||
new MCFillFragment(RelocValue, Size, 1, CurSectionData);
|
||||
}
|
||||
|
||||
void MCMachOStreamer::EmitValueToAlignment(unsigned ByteAlignment,
|
||||
@ -344,9 +342,15 @@ void MCMachOStreamer::EmitValueToAlignment(unsigned ByteAlignment,
|
||||
CurSectionData->setAlignment(ByteAlignment);
|
||||
}
|
||||
|
||||
void MCMachOStreamer::EmitValueToOffset(const MCValue &Offset,
|
||||
void MCMachOStreamer::EmitValueToOffset(const MCExpr *Offset,
|
||||
unsigned char Value) {
|
||||
new MCOrgFragment(AddValueSymbols(Offset), Value, CurSectionData);
|
||||
MCValue RelocOffset;
|
||||
|
||||
if (!AddValueSymbols(Offset)->EvaluateAsRelocatable(getContext(),
|
||||
RelocOffset))
|
||||
return llvm_report_error("expected relocatable expression");
|
||||
|
||||
new MCOrgFragment(RelocOffset, Value, CurSectionData);
|
||||
}
|
||||
|
||||
void MCMachOStreamer::EmitInstruction(const MCInst &Inst) {
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "llvm/MC/MCInst.h"
|
||||
#include "llvm/MC/MCSectionMachO.h"
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
#include "llvm/MC/MCValue.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
@ -34,7 +33,7 @@ namespace {
|
||||
|
||||
virtual void EmitAssemblerFlag(AssemblerFlag Flag) {}
|
||||
|
||||
virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value) {}
|
||||
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {}
|
||||
|
||||
virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute) {}
|
||||
|
||||
@ -48,13 +47,13 @@ namespace {
|
||||
|
||||
virtual void EmitBytes(const StringRef &Data) {}
|
||||
|
||||
virtual void EmitValue(const MCValue &Value, unsigned Size) {}
|
||||
virtual void EmitValue(const MCExpr *Value, unsigned Size) {}
|
||||
|
||||
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
|
||||
unsigned ValueSize = 1,
|
||||
unsigned MaxBytesToEmit = 0) {}
|
||||
|
||||
virtual void EmitValueToOffset(const MCValue &Offset,
|
||||
virtual void EmitValueToOffset(const MCExpr *Offset,
|
||||
unsigned char Value = 0) {}
|
||||
|
||||
virtual void EmitInstruction(const MCInst &Inst) {}
|
||||
|
@ -1,6 +1,6 @@
|
||||
# RUN: llvm-mc -triple i386-unknown-unknown %s -I %p | FileCheck %s
|
||||
|
||||
# CHECK: .byte 2
|
||||
# CHECK: .byte (1 + 1)
|
||||
.if 1+2
|
||||
.if 1-1
|
||||
.byte 1
|
||||
|
@ -1,6 +1,11 @@
|
||||
// RUN: not llvm-mc -triple i386-unknown-unknown %s 2> %t
|
||||
// RUN: FileCheck -input-file %t %s
|
||||
|
||||
// Currently XFAIL'ed, since the front-end isn't validating this. Figure out the
|
||||
// right resolution.
|
||||
//
|
||||
// XFAIL: *
|
||||
|
||||
.text
|
||||
a:
|
||||
.data
|
||||
|
@ -52,7 +52,7 @@ foo:
|
||||
// CHECX: .lsym "a 8",1
|
||||
// .lsym "a 8", 1
|
||||
|
||||
// CHECK: "a 9" = a - b
|
||||
// CHECK: "a 9" = (a - b)
|
||||
.set "a 9", a - b
|
||||
|
||||
// CHECK: .long "a 9"
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "llvm/MC/MCSectionMachO.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
#include "llvm/MC/MCValue.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Target/TargetAsmParser.h"
|
||||
@ -712,15 +711,11 @@ bool AsmParser::ParseAssignment(const StringRef &Name) {
|
||||
// FIXME: Use better location, we should use proper tokens.
|
||||
SMLoc EqualLoc = Lexer.getLoc();
|
||||
|
||||
MCValue Value;
|
||||
const MCExpr *Expr;
|
||||
const MCExpr *Value;
|
||||
SMLoc StartLoc = Lexer.getLoc();
|
||||
if (ParseExpression(Expr))
|
||||
if (ParseExpression(Value))
|
||||
return true;
|
||||
|
||||
if (!Expr->EvaluateAsRelocatable(Ctx, Value))
|
||||
return Error(StartLoc, "expected relocatable expression");
|
||||
|
||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||
return TokError("unexpected token in assignment");
|
||||
|
||||
@ -937,15 +932,11 @@ bool AsmParser::ParseDirectiveAscii(bool ZeroTerminated) {
|
||||
bool AsmParser::ParseDirectiveValue(unsigned Size) {
|
||||
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
||||
for (;;) {
|
||||
MCValue Value;
|
||||
const MCExpr *Expr;
|
||||
const MCExpr *Value;
|
||||
SMLoc StartLoc = Lexer.getLoc();
|
||||
if (ParseExpression(Expr))
|
||||
if (ParseExpression(Value))
|
||||
return true;
|
||||
|
||||
if (!Expr->EvaluateAsRelocatable(Ctx, Value))
|
||||
return Error(StartLoc, "expected relocatable expression");
|
||||
|
||||
Out.EmitValue(Value, Size);
|
||||
|
||||
if (Lexer.is(AsmToken::EndOfStatement))
|
||||
@ -992,7 +983,7 @@ bool AsmParser::ParseDirectiveSpace() {
|
||||
|
||||
// FIXME: Sometimes the fill expr is 'nop' if it isn't supplied, instead of 0.
|
||||
for (uint64_t i = 0, e = NumBytes; i != e; ++i)
|
||||
Out.EmitValue(MCValue::get(FillExpr), 1);
|
||||
Out.EmitValue(MCConstantExpr::Create(FillExpr, getContext()), 1);
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1029,7 +1020,7 @@ bool AsmParser::ParseDirectiveFill() {
|
||||
return TokError("invalid '.fill' size, expected 1, 2, 4, or 8");
|
||||
|
||||
for (uint64_t i = 0, e = NumValues; i != e; ++i)
|
||||
Out.EmitValue(MCValue::get(FillExpr), FillSize);
|
||||
Out.EmitValue(MCConstantExpr::Create(FillExpr, getContext()), FillSize);
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1037,15 +1028,11 @@ bool AsmParser::ParseDirectiveFill() {
|
||||
/// ParseDirectiveOrg
|
||||
/// ::= .org expression [ , expression ]
|
||||
bool AsmParser::ParseDirectiveOrg() {
|
||||
MCValue Offset;
|
||||
const MCExpr *Expr;
|
||||
const MCExpr *Offset;
|
||||
SMLoc StartLoc = Lexer.getLoc();
|
||||
if (ParseExpression(Expr))
|
||||
if (ParseExpression(Offset))
|
||||
return true;
|
||||
|
||||
if (!Expr->EvaluateAsRelocatable(Ctx, Offset))
|
||||
return Error(StartLoc, "expected relocatable expression");
|
||||
|
||||
// Parse optional fill expression.
|
||||
int64_t FillExpr = 0;
|
||||
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
||||
@ -1417,15 +1404,11 @@ bool AsmParser::ParseDirectiveDarwinLsym() {
|
||||
return TokError("unexpected token in '.lsym' directive");
|
||||
Lexer.Lex();
|
||||
|
||||
MCValue Value;
|
||||
const MCExpr *Expr;
|
||||
const MCExpr *Value;
|
||||
SMLoc StartLoc = Lexer.getLoc();
|
||||
if (ParseExpression(Expr))
|
||||
if (ParseExpression(Value))
|
||||
return true;
|
||||
|
||||
if (!Expr->EvaluateAsRelocatable(Ctx, Value))
|
||||
return Error(StartLoc, "expected relocatable expression");
|
||||
|
||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||
return TokError("unexpected token in '.lsym' directive");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user