diff options
author | Akira Hatanaka <ahatanaka@mips.com> | 2012-03-27 02:04:18 +0000 |
---|---|---|
committer | Akira Hatanaka <ahatanaka@mips.com> | 2012-03-27 02:04:18 +0000 |
commit | a06bc1c6e31e37451dfcbc0a67618ad4168ead9a (patch) | |
tree | 3a47ac9a3a68043b09a8c09589e4ca75b3083e13 /llvm/lib/Target | |
parent | 7fede873498ff13bc17d7049aab15a8662e8e184 (diff) | |
download | bcm5719-llvm-a06bc1c6e31e37451dfcbc0a67618ad4168ead9a.tar.gz bcm5719-llvm-a06bc1c6e31e37451dfcbc0a67618ad4168ead9a.zip |
Define function MipsGetSymAndOffset which returns a fixup's symbol and the
offset applied to it.
llvm-svn: 153493
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r-- | llvm/lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h b/llvm/lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h index 34e3a6e267c..fb1c5ce6b6c 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h @@ -14,7 +14,9 @@ #ifndef MIPSBASEINFO_H #define MIPSBASEINFO_H +#include "MipsFixupKinds.h" #include "MipsMCTargetDesc.h" +#include "llvm/MC/MCExpr.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/ErrorHandling.h" @@ -198,6 +200,34 @@ inline static unsigned getMipsRegisterNumbering(unsigned RegEnum) default: llvm_unreachable("Unknown register number!"); } } + +inline static std::pair<const MCSymbolRefExpr*, int64_t> +MipsGetSymAndOffset(const MCFixup &Fixup) { + MCFixupKind FixupKind = Fixup.getKind(); + + if ((FixupKind < FirstTargetFixupKind) || + (FixupKind >= MCFixupKind(Mips::LastTargetFixupKind))) + return std::make_pair((const MCSymbolRefExpr*)0, (int64_t)0); + + const MCExpr *Expr = Fixup.getValue(); + MCExpr::ExprKind Kind = Expr->getKind(); + + if (Kind == MCExpr::Binary) { + const MCBinaryExpr *BE = static_cast<const MCBinaryExpr*>(Expr); + const MCExpr *LHS = BE->getLHS(); + const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(BE->getRHS()); + + if ((LHS->getKind() != MCExpr::SymbolRef) || !CE) + return std::make_pair((const MCSymbolRefExpr*)0, (int64_t)0); + + return std::make_pair(cast<MCSymbolRefExpr>(LHS), CE->getValue()); + } + + if (Kind != MCExpr::SymbolRef) + return std::make_pair((const MCSymbolRefExpr*)0, (int64_t)0); + + return std::make_pair(cast<MCSymbolRefExpr>(Expr), 0); +} } #endif |