MC: Sketch initial MCAsmLayout class, which encapsulates the current layout of an...
authorDaniel Dunbar <daniel@zuster.org>
Thu, 11 Mar 2010 02:28:59 +0000 (02:28 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 11 Mar 2010 02:28:59 +0000 (02:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98227 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAsmLayout.h [new file with mode: 0644]
include/llvm/MC/MCAssembler.h
include/llvm/MC/MCExpr.h
lib/MC/MCExpr.cpp
lib/Target/X86/X86MCTargetExpr.cpp
lib/Target/X86/X86MCTargetExpr.h

diff --git a/include/llvm/MC/MCAsmLayout.h b/include/llvm/MC/MCAsmLayout.h
new file mode 100644 (file)
index 0000000..d2b5e4a
--- /dev/null
@@ -0,0 +1,49 @@
+//===- MCAsmLayout.h - Assembly Layout Object -------------------*- 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_MCASMLAYOUT_H
+#define LLVM_MC_MCASMLAYOUT_H
+
+namespace llvm {
+class MCAssembler;
+
+/// Encapsulates the layout of an assembly file at a particular point in time.
+///
+/// Assembly may requiring compute multiple layouts for a particular assembly
+/// file as part of the relaxation process. This class encapsulates the layout
+/// at a single point in time in such a way that it is always possible to
+/// efficiently compute the exact addresses of any symbol in the assembly file,
+/// even during the relaxation process.
+class MCAsmLayout {
+private:
+  uint64_t CurrentLocation;
+
+  MCAssembler &Assembler;
+
+public:
+  MCAsmLayout(MCAssembler &_Assembler)
+    : CurrentLocation(0), Assembler(_Assember) {}
+
+  /// Get the assembler object this is a layout for.
+  MCAssembler &getAssembler() { return Assembler; }
+
+  /// Get the current location value, i.e. that value of the '.' expression.
+  uin64_t getCurrentLocation() {
+    return CurrentLocation;
+  }
+
+  /// Set the current location.
+  void setCurrentLocation(uint64_t Value) {
+    CurrentLocation = Value;
+  }
+};
+
+} // end namespace llvm
+
+#endif
index ffd77c51eb4298d5f0b8a458760d794fa391c98a..8210db61fca8c6b98c70b8eecee3db91718be157 100644 (file)
@@ -625,6 +625,8 @@ public:
 
   MCContext &getContext() const { return Context; }
 
+  TargetAsmBackend &getBackend() const { return Backend; }
+
   /// Finish - Do final processing and write the object to the output stream.
   void Finish();
 
index 3f17492c6b47dfe10618dce8e4338a1a0cdaaf02..9daddb2923d5806f351fafcfd9fa5be3c2557378 100644 (file)
@@ -15,6 +15,7 @@
 
 namespace llvm {
 class MCAsmInfo;
+class MCAsmLayout;
 class MCContext;
 class MCSymbol;
 class MCValue;
@@ -62,15 +63,19 @@ public:
   /// EvaluateAsAbsolute - Try to evaluate the expression to an absolute value.
   ///
   /// @param Res - The absolute value, if evaluation succeeds.
+  /// @param Layout - The assembler layout object to use for evaluating symbol
+  /// values. If not given, then only non-symbolic expressions will be
+  /// evaluated.
   /// @result - True on success.
-  bool EvaluateAsAbsolute(int64_t &Res) const;
+  bool EvaluateAsAbsolute(int64_t &Res, MCAsmLayout *Layout = 0) const;
 
   /// EvaluateAsRelocatable - Try to evaluate the expression to a relocatable
   /// value, i.e. an expression of the fixed form (a - b + constant).
   ///
   /// @param Res - The relocatable value, if evaluation succeeds.
+  /// @param Layout - The assembler layout object to use for evaluating values.
   /// @result - True on success.
-  bool EvaluateAsRelocatable(MCValue &Res) const;
+  bool EvaluateAsRelocatable(MCValue &Res, MCAsmLayout *Layout = 0) const;
 
   /// @}
 
@@ -348,7 +353,8 @@ protected:
 public:
   
   virtual void PrintImpl(raw_ostream &OS) const = 0;
-  virtual bool EvaluateAsRelocatableImpl(MCValue &Res) const = 0;
+  virtual bool EvaluateAsRelocatableImpl(MCValue &Res,
+                                         MCAsmLayout *Layout) const = 0;
 
   
   static bool classof(const MCExpr *E) {
index 4439eba5d475ab44cd9f30f5907056e4698d8671..e364069151419b13e084435485db63a050eccdee 100644 (file)
@@ -142,10 +142,10 @@ void MCTargetExpr::Anchor() {}
 
 /* *** */
 
-bool MCExpr::EvaluateAsAbsolute(int64_t &Res) const {
+bool MCExpr::EvaluateAsAbsolute(int64_t &Res, MCAsmLayout *Layout) const {
   MCValue Value;
   
-  if (!EvaluateAsRelocatable(Value) || !Value.isAbsolute())
+  if (!EvaluateAsRelocatable(Value, Layout) || !Value.isAbsolute())
     return false;
 
   Res = Value.getConstant();
@@ -174,10 +174,10 @@ static bool EvaluateSymbolicAdd(const MCValue &LHS, const MCSymbol *RHS_A,
   return true;
 }
 
-bool MCExpr::EvaluateAsRelocatable(MCValue &Res) const {
+bool MCExpr::EvaluateAsRelocatable(MCValue &Res, MCAsmLayout *Layout) const {
   switch (getKind()) {
   case Target:
-    return cast<MCTargetExpr>(this)->EvaluateAsRelocatableImpl(Res);
+    return cast<MCTargetExpr>(this)->EvaluateAsRelocatableImpl(Res, Layout);
       
   case Constant:
     Res = MCValue::get(cast<MCConstantExpr>(this)->getValue());
@@ -188,7 +188,7 @@ bool MCExpr::EvaluateAsRelocatable(MCValue &Res) const {
 
     // Evaluate recursively if this is a variable.
     if (Sym.isVariable())
-      return Sym.getValue()->EvaluateAsRelocatable(Res);
+      return Sym.getValue()->EvaluateAsRelocatable(Res, Layout);
 
     Res = MCValue::get(&Sym, 0, 0);
     return true;
@@ -198,7 +198,7 @@ bool MCExpr::EvaluateAsRelocatable(MCValue &Res) const {
     const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this);
     MCValue Value;
 
-    if (!AUE->getSubExpr()->EvaluateAsRelocatable(Value))
+    if (!AUE->getSubExpr()->EvaluateAsRelocatable(Value, Layout))
       return false;
 
     switch (AUE->getOpcode()) {
@@ -231,8 +231,8 @@ bool MCExpr::EvaluateAsRelocatable(MCValue &Res) const {
     const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
     MCValue LHSValue, RHSValue;
     
-    if (!ABE->getLHS()->EvaluateAsRelocatable(LHSValue) ||
-        !ABE->getRHS()->EvaluateAsRelocatable(RHSValue))
+    if (!ABE->getLHS()->EvaluateAsRelocatable(LHSValue, Layout) ||
+        !ABE->getRHS()->EvaluateAsRelocatable(RHSValue, Layout))
       return false;
 
     // We only support a few operations on non-constant expressions, handle
index 17b4fe88c7528e2ec63c6cb1f85ed0d935319654..de56d3130766e4bf085150a86baa5f15a184b9ac 100644 (file)
@@ -36,12 +36,13 @@ void X86MCTargetExpr::PrintImpl(raw_ostream &OS) const {
   }
 }
 
-bool X86MCTargetExpr::EvaluateAsRelocatableImpl(MCValue &Res) const {
+bool X86MCTargetExpr::EvaluateAsRelocatableImpl(MCValue &Res,
+                                                MCAsmLayout *Layout) const {
   // FIXME: I don't know if this is right, it followed MCSymbolRefExpr.
   
   // Evaluate recursively if this is a variable.
   if (Sym->isVariable())
-    return Sym->getValue()->EvaluateAsRelocatable(Res);
+    return Sym->getValue()->EvaluateAsRelocatable(Res, Layout);
   
   Res = MCValue::get(Sym, 0, 0);
   return true;
index 7de8a5c57380e8b1ff074aded9027c0879520de8..56011eb053f7619498d469fd732718789d7179f1 100644 (file)
@@ -41,7 +41,7 @@ public:
                                  MCContext &Ctx);
   
   void PrintImpl(raw_ostream &OS) const;
-  bool EvaluateAsRelocatableImpl(MCValue &Res) const;
+  bool EvaluateAsRelocatableImpl(MCValue &Res, MCAsmLayout *Layout) const;
 };
   
 } // end namespace llvm