summaryrefslogtreecommitdiff
path: root/lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h
diff options
context:
space:
mode:
authorAkira Hatanaka <ahatanaka@mips.com>2012-03-27 02:04:18 +0000
committerAkira Hatanaka <ahatanaka@mips.com>2012-03-27 02:04:18 +0000
commitd7edf7edd4bdd372a6fc2582632ffe6fa935f980 (patch)
treecfbd7f231fdb1f9903942b6d34cf6ff1e2dae717 /lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h
parentd6c23557898b1fe9b21b28023f4133cab84a8b83 (diff)
downloadllvm-d7edf7edd4bdd372a6fc2582632ffe6fa935f980.tar.gz
llvm-d7edf7edd4bdd372a6fc2582632ffe6fa935f980.tar.bz2
llvm-d7edf7edd4bdd372a6fc2582632ffe6fa935f980.tar.xz
Define function MipsGetSymAndOffset which returns a fixup's symbol and the
offset applied to it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153493 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h')
-rw-r--r--lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h b/lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h
index 34e3a6e267..fb1c5ce6b6 100644
--- a/lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h
+++ b/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