mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-06 19:31:13 +00:00
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.
llvm-svn: 98227
This commit is contained in:
parent
fe8914f6b6
commit
285a34c8c8
49
include/llvm/MC/MCAsmLayout.h
Normal file
49
include/llvm/MC/MCAsmLayout.h
Normal file
@ -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
|
@ -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();
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user