LLVM  13.0.0git
Public Types | Public Member Functions | Protected Member Functions | List of all members
llvm::MCExpr Class Reference

Base class for the full range of assembler expressions which are needed for parsing. More...

#include "llvm/MC/MCExpr.h"

Inheritance diagram for llvm::MCExpr:
Inheritance graph
[legend]

Public Types

enum  ExprKind : uint8_t {
  Binary, Constant, SymbolRef, Unary,
  Target
}
 

Public Member Functions

 MCExpr (const MCExpr &)=delete
 
MCExproperator= (const MCExpr &)=delete
 
Accessors
ExprKind getKind () const
 
SMLoc getLoc () const
 
Utility Methods
void print (raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
 
void dump () const
 
Expression Evaluation
bool evaluateAsAbsolute (int64_t &Res, const MCAsmLayout &Layout, const SectionAddrMap &Addrs) const
 Try to evaluate the expression to an absolute value. More...
 
bool evaluateAsAbsolute (int64_t &Res) const
 
bool evaluateAsAbsolute (int64_t &Res, const MCAssembler &Asm) const
 
bool evaluateAsAbsolute (int64_t &Res, const MCAssembler *Asm) const
 
bool evaluateAsAbsolute (int64_t &Res, const MCAsmLayout &Layout) const
 
bool evaluateKnownAbsolute (int64_t &Res, const MCAsmLayout &Layout) const
 
bool evaluateAsRelocatable (MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
 Try to evaluate the expression to a relocatable value, i.e. More...
 
bool evaluateAsValue (MCValue &Res, const MCAsmLayout &Layout) const
 Try to evaluate the expression to the form (a - b + constant) where neither a nor b are variables. More...
 
MCFragmentfindAssociatedFragment () const
 Find the "associated section" for this expression, which is currently defined as the absolute section for constants, or otherwise the section associated with the first defined symbol in the expression. More...
 

Protected Member Functions

 MCExpr (ExprKind Kind, SMLoc Loc, unsigned SubclassData=0)
 
bool evaluateAsRelocatableImpl (MCValue &Res, const MCAssembler *Asm, const MCAsmLayout *Layout, const MCFixup *Fixup, const SectionAddrMap *Addrs, bool InSet) const
 
unsigned getSubclassData () const
 

Detailed Description

Base class for the full range of assembler expressions which are needed for parsing.

Definition at line 35 of file MCExpr.h.

Member Enumeration Documentation

◆ ExprKind

enum llvm::MCExpr::ExprKind : uint8_t
Enumerator
Binary 

Binary expressions.

Constant 

Constant expressions.

SymbolRef 

References to labels and assigned expressions.

Unary 

Unary expressions.

Target 

Target specific expression.

Definition at line 37 of file MCExpr.h.

Constructor & Destructor Documentation

◆ MCExpr() [1/2]

llvm::MCExpr::MCExpr ( ExprKind  Kind,
SMLoc  Loc,
unsigned  SubclassData = 0 
)
inlineexplicitprotected

Definition at line 61 of file MCExpr.h.

References assert().

◆ MCExpr() [2/2]

llvm::MCExpr::MCExpr ( const MCExpr )
delete

Member Function Documentation

◆ dump()

LLVM_DUMP_METHOD void MCExpr::dump ( ) const

Definition at line 175 of file MCExpr.cpp.

◆ evaluateAsAbsolute() [1/5]

bool MCExpr::evaluateAsAbsolute ( int64_t &  Res) const

Definition at line 532 of file MCExpr.cpp.

◆ evaluateAsAbsolute() [2/5]

bool MCExpr::evaluateAsAbsolute ( int64_t &  Res,
const MCAsmLayout Layout 
) const

Definition at line 536 of file MCExpr.cpp.

◆ evaluateAsAbsolute() [3/5]

bool MCExpr::evaluateAsAbsolute ( int64_t &  Res,
const MCAsmLayout Layout,
const SectionAddrMap Addrs 
) const

Try to evaluate the expression to an absolute value.

Parameters
Res- The absolute value, if evaluation succeeds.
Layout- The assembler layout object to use for evaluating symbol values. If not given, then only non-symbolic expressions will be evaluated.
Returns
- True on success.

Definition at line 541 of file MCExpr.cpp.

◆ evaluateAsAbsolute() [4/5]

bool MCExpr::evaluateAsAbsolute ( int64_t &  Res,
const MCAssembler Asm 
) const

Definition at line 549 of file MCExpr.cpp.

◆ evaluateAsAbsolute() [5/5]

bool MCExpr::evaluateAsAbsolute ( int64_t &  Res,
const MCAssembler Asm 
) const

Definition at line 553 of file MCExpr.cpp.

◆ evaluateAsRelocatable()

bool MCExpr::evaluateAsRelocatable ( MCValue Res,
const MCAsmLayout Layout,
const MCFixup Fixup 
) const

◆ evaluateAsRelocatableImpl()

bool MCExpr::evaluateAsRelocatableImpl ( MCValue Res,
const MCAssembler Asm,
const MCAsmLayout Layout,
const MCFixup Fixup,
const SectionAddrMap Addrs,
bool  InSet 
) const
protected

-(a - b + const) ==> (b - a - const)

Definition at line 793 of file MCExpr.cpp.

References llvm::MCBinaryExpr::Add, llvm::MCBinaryExpr::And, llvm::MCBinaryExpr::AShr, llvm::HexStyle::Asm, B, Binary, canExpand(), Constant, llvm::MCSymbolRefExpr::create(), llvm::MCBinaryExpr::Div, llvm::MCBinaryExpr::EQ, evaluateAsRelocatableImpl(), EvaluateSymbolicAdd(), Fixup, llvm::MCValue::get(), llvm::MCValue::getConstant(), getKind(), llvm::MCSymbolRefExpr::getKind(), llvm::MCBinaryExpr::getLHS(), llvm::MCUnaryExpr::getOpcode(), llvm::MCBinaryExpr::getOpcode(), llvm::MCValue::getRefKind(), llvm::MCBinaryExpr::getRHS(), llvm::MCUnaryExpr::getSubExpr(), llvm::MCValue::getSymA(), llvm::MCValue::getSymB(), llvm::MCSymbolRefExpr::getSymbol(), llvm::MCSymbol::getVariableValue(), llvm::MCBinaryExpr::GT, llvm::MCBinaryExpr::GTE, llvm::MCSymbolRefExpr::hasSubsectionsViaSymbols(), llvm::MCValue::isAbsolute(), llvm::MCSymbol::isVariable(), llvm::MCBinaryExpr::LAnd, llvm_unreachable, llvm::MCUnaryExpr::LNot, llvm::MCBinaryExpr::LOr, llvm::MCBinaryExpr::LShr, llvm::MCBinaryExpr::LT, llvm::MCBinaryExpr::LTE, llvm::MCUnaryExpr::Minus, llvm::MCBinaryExpr::Mod, llvm::MCBinaryExpr::Mul, llvm::MCBinaryExpr::NE, llvm::MCUnaryExpr::Not, llvm::MCBinaryExpr::Or, llvm::MCBinaryExpr::OrNot, llvm::MCUnaryExpr::Plus, llvm::MCBinaryExpr::Shl, llvm::MCBinaryExpr::Sub, SymbolRef, Target, Unary, llvm::MCSymbolRefExpr::VK_None, and llvm::MCBinaryExpr::Xor.

Referenced by evaluateAsRelocatable(), evaluateAsRelocatableImpl(), and evaluateAsValue().

◆ evaluateAsValue()

bool MCExpr::evaluateAsValue ( MCValue Res,
const MCAsmLayout Layout 
) const

Try to evaluate the expression to the form (a - b + constant) where neither a nor b are variables.

This is a more aggressive variant of evaluateAsRelocatable. The intended use is for when relocations are not available, like the .size directive.

Definition at line 774 of file MCExpr.cpp.

References evaluateAsRelocatableImpl(), and llvm::MCAsmLayout::getAssembler().

Referenced by llvm::MCAssembler::computeFragmentSize(), and llvm::MCAsmLayout::getBaseSymbol().

◆ evaluateKnownAbsolute()

bool MCExpr::evaluateKnownAbsolute ( int64_t &  Res,
const MCAsmLayout Layout 
) const

Definition at line 557 of file MCExpr.cpp.

◆ findAssociatedFragment()

MCFragment * MCExpr::findAssociatedFragment ( ) const

◆ getKind()

ExprKind llvm::MCExpr::getKind ( ) const
inline

◆ getLoc()

SMLoc llvm::MCExpr::getLoc ( ) const
inline

◆ getSubclassData()

unsigned llvm::MCExpr::getSubclassData ( ) const
inlineprotected

◆ operator=()

MCExpr& llvm::MCExpr::operator= ( const MCExpr )
delete

◆ print()

void MCExpr::print ( raw_ostream OS,
const MCAsmInfo MAI,
bool  InParens = false 
) const

Definition at line 42 of file MCExpr.cpp.

References llvm::MCBinaryExpr::Add, llvm::MCBinaryExpr::And, llvm::MCBinaryExpr::AShr, Binary, Constant, llvm::MCBinaryExpr::Div, llvm::StringRef::empty(), llvm::MCBinaryExpr::EQ, llvm::format(), getKind(), llvm::MCSymbolRefExpr::getKind(), llvm::MCBinaryExpr::getLHS(), llvm::MCSymbol::getName(), llvm::MCUnaryExpr::getOpcode(), llvm::MCBinaryExpr::getOpcode(), llvm::MCBinaryExpr::getRHS(), llvm::MCUnaryExpr::getSubExpr(), llvm::MCSymbolRefExpr::getSymbol(), llvm::MCSymbolRefExpr::getVariantKindName(), llvm::MCBinaryExpr::GT, llvm::MCUnaryExpr::LNot, llvm::MCUnaryExpr::Minus, llvm::MCUnaryExpr::Not, llvm::MCUnaryExpr::Plus, print(), llvm::MCSymbol::print(), SymbolRef, Target, Unary, llvm::MCAsmInfo::useParensForSymbolVariant(), llvm::Twine::utohexstr(), and llvm::MCSymbolRefExpr::VK_None.

Referenced by print(), llvm::AArch64InstPrinter::printAddSubImm(), llvm::ARMInstPrinter::printAdrLabelOperand(), llvm::AArch64InstPrinter::printAMIndexedWB(), llvm::HexagonMCExpr::printImpl(), llvm::LanaiMCExpr::printImpl(), llvm::CSKYMCExpr::printImpl(), llvm::ARMMCExpr::printImpl(), llvm::AVRMCExpr::printImpl(), llvm::RISCVMCExpr::printImpl(), llvm::MipsMCExpr::printImpl(), llvm::VEMCExpr::printImpl(), llvm::PPCMCExpr::printImpl(), llvm::SparcMCExpr::printImpl(), llvm::NVPTXGenericMCSymbolRefExpr::printImpl(), llvm::AArch64MCExpr::printImpl(), llvm::X86ATTInstPrinter::printMemOffset(), llvm::X86IntelInstPrinter::printMemOffset(), printMemoryImmediateOffset(), llvm::X86ATTInstPrinter::printMemReference(), llvm::X86IntelInstPrinter::printMemReference(), llvm::RISCVInstPrinter::printOperand(), llvm::CSKYInstPrinter::printOperand(), llvm::VEInstPrinter::printOperand(), llvm::SystemZInstPrinter::printOperand(), llvm::SparcInstPrinter::printOperand(), llvm::ARMInstPrinter::printOperand(), llvm::MCSectionWasm::PrintSwitchToSection(), llvm::MCSectionELF::PrintSwitchToSection(), llvm::ARMInstPrinter::printThumbLdrLabelOperand(), and llvm::AArch64InstPrinter::printUImm12Offset().


The documentation for this class was generated from the following files: