diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-03-11 02:28:59 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-03-11 02:28:59 +0000 |
commit | f82f4490b130eca55b08d605456a4ceacccf288a (patch) | |
tree | b348af7f061536684320c64b1b6e68adccda707b | |
parent | 18e2c021a937f78b8d16619cd377f0c72c542470 (diff) | |
download | external_llvm-f82f4490b130eca55b08d605456a4ceacccf288a.zip external_llvm-f82f4490b130eca55b08d605456a4ceacccf288a.tar.gz external_llvm-f82f4490b130eca55b08d605456a4ceacccf288a.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98227 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/MC/MCAsmLayout.h | 49 | ||||
-rw-r--r-- | include/llvm/MC/MCAssembler.h | 2 | ||||
-rw-r--r-- | include/llvm/MC/MCExpr.h | 12 | ||||
-rw-r--r-- | lib/MC/MCExpr.cpp | 16 | ||||
-rw-r--r-- | lib/Target/X86/X86MCTargetExpr.cpp | 5 | ||||
-rw-r--r-- | lib/Target/X86/X86MCTargetExpr.h | 2 |
6 files changed, 72 insertions, 14 deletions
diff --git a/include/llvm/MC/MCAsmLayout.h b/include/llvm/MC/MCAsmLayout.h new file mode 100644 index 0000000..d2b5e4a --- /dev/null +++ b/include/llvm/MC/MCAsmLayout.h @@ -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 diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h index ffd77c5..8210db6 100644 --- a/include/llvm/MC/MCAssembler.h +++ b/include/llvm/MC/MCAssembler.h @@ -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(); diff --git a/include/llvm/MC/MCExpr.h b/include/llvm/MC/MCExpr.h index 3f17492..9daddb2 100644 --- a/include/llvm/MC/MCExpr.h +++ b/include/llvm/MC/MCExpr.h @@ -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) { diff --git a/lib/MC/MCExpr.cpp b/lib/MC/MCExpr.cpp index 4439eba..e364069 100644 --- a/lib/MC/MCExpr.cpp +++ b/lib/MC/MCExpr.cpp @@ -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 diff --git a/lib/Target/X86/X86MCTargetExpr.cpp b/lib/Target/X86/X86MCTargetExpr.cpp index 17b4fe8..de56d31 100644 --- a/lib/Target/X86/X86MCTargetExpr.cpp +++ b/lib/Target/X86/X86MCTargetExpr.cpp @@ -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; diff --git a/lib/Target/X86/X86MCTargetExpr.h b/lib/Target/X86/X86MCTargetExpr.h index 7de8a5c..56011eb 100644 --- a/lib/Target/X86/X86MCTargetExpr.h +++ b/lib/Target/X86/X86MCTargetExpr.h @@ -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 |