We decided to not worry about Atoms for now, it should be straightforward to
authorDaniel Dunbar <daniel@zuster.org>
Wed, 24 Jun 2009 17:00:42 +0000 (17:00 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 24 Jun 2009 17:00:42 +0000 (17:00 +0000)
reintroduce them later.

Also, don't require MCSection* when creating a symbol.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74081 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAtom.h [deleted file]
include/llvm/MC/MCContext.h
include/llvm/MC/MCStreamer.h
include/llvm/MC/MCSymbol.h
lib/MC/MCAsmStreamer.cpp
lib/MC/MCContext.cpp
unittests/MC/AsmStreamerTest.cpp

diff --git a/include/llvm/MC/MCAtom.h b/include/llvm/MC/MCAtom.h
deleted file mode 100644 (file)
index f91a96f..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-//===- MCAtom.h - Machine Code Atoms ----------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_MC_MCATOM_H
-#define LLVM_MC_MCATOM_H
-
-namespace llvm {
-
-  class MCAtom {
-    MCSection *Section;
-
-  public:
-    MCAtom(MCSection *_Section) : Section(_Section) {}
-
-    MCSection *getSection() { return Section; }
-  };
-
-} // end namespace llvm
-
-#endif
index 8dabb45e9aba71e0e48a8af0b8bde7555bf1ff6b..13180e87caf42088f91a8f61934a1efb79bfafe5 100644 (file)
@@ -15,7 +15,6 @@
 #include "llvm/Support/Allocator.h"
 
 namespace llvm {
-  class MCAtom;
   class MCValue;
   class MCSection;
   class MCSymbol;
@@ -47,14 +46,10 @@ namespace llvm {
     /// GetSection - Get or create a new section with the given @param Name.
     MCSection *GetSection(const char *Name);
     
-    /// CreateAtom - Create a new atom inside @param Section.
-    MCAtom *CreateAtom(MCSection *Section);
-
-    /// CreateSymbol - Create a new symbol inside @param Atom with the specified
-    /// @param Name.
+    /// CreateSymbol - Create a new symbol with the specified @param Name.
     ///
     /// @param Name - The symbol name, which must be unique across all symbols.
-    MCSymbol *CreateSymbol(MCAtom *Atom, const char *Name);
+    MCSymbol *CreateSymbol(const char *Name);
 
     /// GetOrCreateSymbol - Lookup the symbol inside with the specified
     /// @param Name.  If it exists, return it.  If not, create a forward
@@ -63,13 +58,13 @@ namespace llvm {
     /// @param Name - The symbol name, which must be unique across all symbols.
     MCSymbol *GetOrCreateSymbol(const char *Name);
     
-    /// CreateTemporarySymbol - Create a new temporary symbol inside @param Atom
-    /// with the specified @param Name.
+    /// CreateTemporarySymbol - Create a new temporary symbol with the specified
+    /// @param Name.
     ///
     /// @param Name - The symbol name, for debugging purposes only, temporary
     /// symbols do not surive assembly. If non-empty the name must be unique
     /// across all symbols.
-    MCSymbol *CreateTemporarySymbol(MCAtom *Atom, const char *Name = "");
+    MCSymbol *CreateTemporarySymbol(const char *Name = "");
 
     /// LookupSymbol - Get the symbol for @param Name, or null.
     MCSymbol *LookupSymbol(const char *Name) const;
index 76374160e8046d75de6c1097e84874b27eeb6714..0ce8113d06b8e96a8b1b6c669d2c11204c71aae0 100644 (file)
@@ -11,7 +11,6 @@
 #define LLVM_MC_MCSTREAMER_H
 
 namespace llvm {
-  class MCAtom;
   class MCContext;
   class MCValue;
   class MCInst;
index 085f765caf8566f56c1037db3e694196fda33afe..06f50aebedc93e0b50d1c45b32391fb790f5a81f 100644 (file)
 #include <string>
 
 namespace llvm {
-  class MCAtom;
-
   class MCSymbol {
-    MCAtom *Atom;
+    MCSection *Section;
     std::string Name;
     unsigned IsTemporary : 1;
 
   public:
-    MCSymbol(MCAtom *_Atom, const char *_Name, bool _IsTemporary) 
-      : Atom(_Atom), Name(_Name), IsTemporary(_IsTemporary) {}
+    MCSymbol(const char *_Name, bool _IsTemporary) 
+      : Section(0), Name(_Name), IsTemporary(_IsTemporary) {}
 
-    MCAtom *getAtom() { return Atom; }
+    MCSection *getSection() const { return Section; }
+    void setSection(MCSection *Value) { Section = Value; }
 
-    const std::string &getName() { return Name; }
+    const std::string &getName() const { return Name; }
   };
 
 } // end namespace llvm
index 33d72e29f918624f52209b5be4444e9a9f7ed0ac..73d6f046dc24a2c52d5db819432db2b566a206f8 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "llvm/MC/MCStreamer.h"
 
-#include "llvm/MC/MCAtom.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCSection.h"
 #include "llvm/MC/MCSymbol.h"
@@ -82,20 +81,26 @@ void MCAsmStreamer::SwitchSection(MCSection *Section) {
 }
 
 void MCAsmStreamer::EmitLabel(MCSymbol *Symbol) {
-  // FIXME: We need to enforce that we aren't printing atoms which are more
-  // complicated than the assembler understands.
-  //assert(Symbol->getAtom()->getSection() == CurSection && 
-  //       "The label for a symbol must match its section!");
+  assert(Symbol->getSection() == 0 && "Cannot emit a symbol twice!");
+  assert(CurSection && "Cannot emit before setting section!");
+  assert(!getContext().GetSymbolValue(Symbol) && 
+         "Cannot emit symbol which was directly assigned to!");
+
   OS << Symbol->getName() << ":\n";
+  Symbol->setSection(CurSection);
 }
 
 void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCValue &Value,
                                    bool MakeAbsolute) {
+  assert(!Symbol->getSection() && "Cannot assign to a label!");
+
   if (MakeAbsolute) {
     OS << ".set " << Symbol->getName() << ", " << Value << '\n';
   } else {
     OS << Symbol->getName() << " = " << Value << '\n';
   }
+
+  getContext().SetSymbolValue(Symbol, Value);
 }
 
 void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol, 
@@ -119,12 +124,13 @@ void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
 }
 
 void MCAsmStreamer::EmitBytes(const char *Data, unsigned Length) {
-  for (unsigned i = 0; i != Length; ++i) {
+  assert(CurSection && "Cannot emit contents before setting section!");
+  for (unsigned i = 0; i != Length; ++i)
     OS << ".byte " << (unsigned) Data[i] << '\n';
-  }
 }
 
 void MCAsmStreamer::EmitValue(const MCValue &Value, unsigned Size) {
+  assert(CurSection && "Cannot emit contents before setting section!");
   // Need target hooks to know how to print this.
   switch (Size) {
   default:
@@ -139,6 +145,7 @@ void MCAsmStreamer::EmitValue(const MCValue &Value, unsigned Size) {
 }
 
 void MCAsmStreamer::EmitInstruction(const MCInst &Inst) {
+  assert(CurSection && "Cannot emit contents before setting section!");
   // FIXME: Implement.
   OS << "# FIXME: Implement instruction printing!\n";
 }
index f7793b918ca520c5fb920228c9a61faca3b01f92..6c6019c76ffdf19099ae60f2f8782f0e60b77187 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "llvm/MC/MCContext.h"
 
-#include "llvm/MC/MCAtom.h"
 #include "llvm/MC/MCSection.h"
 #include "llvm/MC/MCSymbol.h"
 #include "llvm/MC/MCValue.h"
@@ -30,43 +29,33 @@ MCSection *MCContext::GetSection(const char *Name) {
 
   return Entry;
 }
-    
-MCAtom *MCContext::CreateAtom(MCSection *Section) {
-  return new (*this) MCAtom(Section);
-}
 
-MCSymbol *MCContext::CreateSymbol(MCAtom *Atom, const char *Name) {
+MCSymbol *MCContext::CreateSymbol(const char *Name) {
   assert(Name[0] != '\0' && "Normal symbols cannot be unnamed!");
 
   // Create and bind the symbol, and ensure that names are unique.
   MCSymbol *&Entry = Symbols[Name];
   assert(!Entry && "Duplicate symbol definition!");
-  return Entry = new (*this) MCSymbol(Atom, Name, false);
+  return Entry = new (*this) MCSymbol(Name, false);
 }
 
-/// GetOrCreateSymbol - Lookup the symbol inside with the specified
-/// @param Name.  If it exists, return it.  If not, create a forward
-/// reference and return it.
-///
-/// @param Name - The symbol name, which must be unique across all symbols.
 MCSymbol *MCContext::GetOrCreateSymbol(const char *Name) {
   MCSymbol *&Entry = Symbols[Name];
   if (Entry) return Entry;
 
-  // FIXME: is a null atom the right way to make a forward ref?
-  return Entry = new (*this) MCSymbol(0, Name, false);
+  return Entry = new (*this) MCSymbol(Name, false);
 }
 
 
-MCSymbol *MCContext::CreateTemporarySymbol(MCAtom *Atom, const char *Name) {
+MCSymbol *MCContext::CreateTemporarySymbol(const char *Name) {
   // If unnamed, just create a symbol.
   if (Name[0] == '\0')
-    new (*this) MCSymbol(Atom, "", true);
+    new (*this) MCSymbol("", true);
     
   // Otherwise create as usual.
   MCSymbol *&Entry = Symbols[Name];
   assert(!Entry && "Duplicate symbol definition!");
-  return Entry = new (*this) MCSymbol(Atom, Name, true);
+  return Entry = new (*this) MCSymbol(Name, true);
 }
 
 MCSymbol *MCContext::LookupSymbol(const char *Name) const {
index d97330107438af826bf3a70fd43f95d2d731b54c..76da23ba54406400828d4c28d60f52e7ff94004f 100644 (file)
@@ -53,10 +53,8 @@ TEST(AsmStreamer, Sections) {
 TEST(AsmStreamer, Values) {
   StringAsmStreamer S;
   MCSection *Sec0 = S.getContext().GetSection("foo");
-  MCSymbol *A = S.getContext().CreateSymbol(S.getContext().CreateAtom(Sec0),
-                                         "a");
-  MCSymbol *B = S.getContext().CreateSymbol(S.getContext().CreateAtom(Sec0),
-                                            "b");
+  MCSymbol *A = S.getContext().CreateSymbol("a");
+  MCSymbol *B = S.getContext().CreateSymbol("b");
   S.getStreamer().SwitchSection(Sec0);
   S.getStreamer().EmitLabel(A);
   S.getStreamer().EmitLabel(B);