llvm-mc: Pass values to MCStreamer as MCExprs, not MCValues.
authorDaniel Dunbar <daniel@zuster.org>
Mon, 31 Aug 2009 08:09:28 +0000 (08:09 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 31 Aug 2009 08:09:28 +0000 (08:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80578 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCStreamer.h
lib/MC/MCAsmStreamer.cpp
lib/MC/MCMachOStreamer.cpp
lib/MC/MCNullStreamer.cpp
test/MC/AsmParser/conditional_asm.s
test/MC/AsmParser/exprs-invalid.s
test/MC/AsmParser/labels.s
tools/llvm-mc/AsmParser.cpp

index 8183722fea1c30e298ecd40a8444ff304ec42c53..224fbf4ff867110dc35c8050dd9688631af7f7a5 100644 (file)
@@ -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;
     
     /// @}
index c220b8a9024adbfbf07c483af607424c7ecbae95..d97602830cb243a26873402bd44adee3b945a2a7 100644 (file)
@@ -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) {
index c92d8a85ea7f48b2a5a07d19d71a063254f85d52..e04bd1fd1cb89c9f2b4ad90112050ab633e7f33e 100644 (file)
@@ -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) {
index 9ccea040e750901c46fd8da50025ed1390e5049d..3cd22ca6f009cf4d827392af4890588367789a53 100644 (file)
@@ -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) {}
index f619ef9bb428a4fe53958d961a8a8f6020375dfe..b9ff6705900bb2829aa75ebe708027dfca992728 100644 (file)
@@ -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
index 4accc39087c3dca0e2b9ea3202e3abde5324d10e..5358fc5d7535db71b5d827f2d9fe9a917944a80d 100644 (file)
@@ -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
index 603d050b6c34589e4988a2ace2d4d4a9753d8f21..ac8025f8bd660648785e76d8d69910364107beef 100644 (file)
@@ -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"
index dbceb6b98a2426955a49965a1e569444b8969eb7..a7825615001ef7c4498c286574c8ad8c90a0b06a 100644 (file)
@@ -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");