class MCAsmInfo;
class MCCodeEmitter;
class MCContext;
+ class MCExpr;
class MCInst;
class MCSection;
class MCSymbol;
- class MCValue;
class StringRef;
class raw_ostream;
///
/// @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,
/// @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.
/// @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;
/// @}
#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"
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);
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);
}
/// 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;
}
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) {
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,
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) {
case 8: OS << ".quad"; break;
}
- OS << ' ' << truncateToSize(Value, Size) << '\n';
+ OS << ' ' << *truncateToSize(Value, Size) << '\n';
}
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) {
#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;
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:
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);
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);
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!");
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,
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) {
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCSymbol.h"
-#include "llvm/MC/MCValue.h"
using namespace llvm;
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) {}
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) {}
# 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
// 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
// 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"
#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"
// 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");
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))
// 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;
}
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;
}
/// 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)) {
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");