[llvm-commits] [llvm] r98227 - in /llvm/trunk: include/llvm/MC/MCAsmLayout.h include/llvm/MC/MCAssembler.h include/llvm/MC/MCExpr.h lib/MC/MCExpr.cpp lib/Target/X86/X86MCTargetExpr.cpp lib/Target/X86/X86MCTargetExpr.h

Daniel Dunbar daniel at zuster.org
Wed Mar 10 18:28:59 PST 2010


Author: ddunbar
Date: Wed Mar 10 20:28:59 2010
New Revision: 98227

URL: http://llvm.org/viewvc/llvm-project?rev=98227&view=rev
Log:
MC: Sketch initial MCAsmLayout class, which encapsulates the current layout of an assembly file. The MCAsmLayout is also available for use by MCExpr::EvaluateAs{Absolute,Relocatable}, to allow target specific hooks and "absolutizing" of symbols.

Added:
    llvm/trunk/include/llvm/MC/MCAsmLayout.h
Modified:
    llvm/trunk/include/llvm/MC/MCAssembler.h
    llvm/trunk/include/llvm/MC/MCExpr.h
    llvm/trunk/lib/MC/MCExpr.cpp
    llvm/trunk/lib/Target/X86/X86MCTargetExpr.cpp
    llvm/trunk/lib/Target/X86/X86MCTargetExpr.h

Added: llvm/trunk/include/llvm/MC/MCAsmLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmLayout.h?rev=98227&view=auto
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmLayout.h (added)
+++ llvm/trunk/include/llvm/MC/MCAsmLayout.h Wed Mar 10 20:28:59 2010
@@ -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

Modified: llvm/trunk/include/llvm/MC/MCAssembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAssembler.h?rev=98227&r1=98226&r2=98227&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAssembler.h (original)
+++ llvm/trunk/include/llvm/MC/MCAssembler.h Wed Mar 10 20:28:59 2010
@@ -625,6 +625,8 @@
 
   MCContext &getContext() const { return Context; }
 
+  TargetAsmBackend &getBackend() const { return Backend; }
+
   /// Finish - Do final processing and write the object to the output stream.
   void Finish();
 

Modified: llvm/trunk/include/llvm/MC/MCExpr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCExpr.h?rev=98227&r1=98226&r2=98227&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCExpr.h (original)
+++ llvm/trunk/include/llvm/MC/MCExpr.h Wed Mar 10 20:28:59 2010
@@ -15,6 +15,7 @@
 
 namespace llvm {
 class MCAsmInfo;
+class MCAsmLayout;
 class MCContext;
 class MCSymbol;
 class MCValue;
@@ -62,15 +63,19 @@
   /// 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 @@
 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) {

Modified: llvm/trunk/lib/MC/MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?rev=98227&r1=98226&r2=98227&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Wed Mar 10 20:28:59 2010
@@ -142,10 +142,10 @@
 
 /* *** */
 
-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 @@
   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 @@
 
     // 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 @@
     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 @@
     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

Modified: llvm/trunk/lib/Target/X86/X86MCTargetExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCTargetExpr.cpp?rev=98227&r1=98226&r2=98227&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86MCTargetExpr.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86MCTargetExpr.cpp Wed Mar 10 20:28:59 2010
@@ -36,12 +36,13 @@
   }
 }
 
-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;

Modified: llvm/trunk/lib/Target/X86/X86MCTargetExpr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCTargetExpr.h?rev=98227&r1=98226&r2=98227&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86MCTargetExpr.h (original)
+++ llvm/trunk/lib/Target/X86/X86MCTargetExpr.h Wed Mar 10 20:28:59 2010
@@ -41,7 +41,7 @@
                                  MCContext &Ctx);
   
   void PrintImpl(raw_ostream &OS) const;
-  bool EvaluateAsRelocatableImpl(MCValue &Res) const;
+  bool EvaluateAsRelocatableImpl(MCValue &Res, MCAsmLayout *Layout) const;
 };
   
 } // end namespace llvm





More information about the llvm-commits mailing list