mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-03 15:36:21 +00:00
add an x86 implementation of MCTargetExpr for
representing @GOT and friends. Use it for personality references as a first use. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95588 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
df9c4380ee
commit
25ceb5f317
@ -26,6 +26,7 @@ set(sources
|
|||||||
X86JITInfo.cpp
|
X86JITInfo.cpp
|
||||||
X86MCAsmInfo.cpp
|
X86MCAsmInfo.cpp
|
||||||
X86MCCodeEmitter.cpp
|
X86MCCodeEmitter.cpp
|
||||||
|
X86MCTargetExpr.cpp
|
||||||
X86RegisterInfo.cpp
|
X86RegisterInfo.cpp
|
||||||
X86Subtarget.cpp
|
X86Subtarget.cpp
|
||||||
X86TargetMachine.cpp
|
X86TargetMachine.cpp
|
||||||
|
43
lib/Target/X86/X86MCTargetExpr.cpp
Normal file
43
lib/Target/X86/X86MCTargetExpr.cpp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
//===- X86MCTargetExpr.cpp - X86 Target Specific MCExpr Implementation ----===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "X86MCTargetExpr.h"
|
||||||
|
#include "llvm/MC/MCContext.h"
|
||||||
|
#include "llvm/MC/MCSymbol.h"
|
||||||
|
#include "llvm/MC/MCValue.h"
|
||||||
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
|
X86MCTargetExpr *X86MCTargetExpr::Create(const MCSymbol *Sym, VariantKind K,
|
||||||
|
MCContext &Ctx) {
|
||||||
|
return new (Ctx) X86MCTargetExpr(Sym, K);
|
||||||
|
}
|
||||||
|
|
||||||
|
void X86MCTargetExpr::PrintImpl(raw_ostream &OS) const {
|
||||||
|
OS << *Sym;
|
||||||
|
|
||||||
|
switch (Kind) {
|
||||||
|
case GOT: OS << "@GOT"; break;
|
||||||
|
case PLT: OS << "@PLT"; break;
|
||||||
|
case GOTPCREL: OS << "@GOTPCREL"; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool X86MCTargetExpr::EvaluateAsRelocatableImpl(MCValue &Res) 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);
|
||||||
|
|
||||||
|
Res = MCValue::get(Sym, 0, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
X86MCTargetExpr *foo(MCExpr *A) { return (X86MCTargetExpr*)A; }
|
42
lib/Target/X86/X86MCTargetExpr.h
Normal file
42
lib/Target/X86/X86MCTargetExpr.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
//===- X86MCTargetExpr.h - X86 Target Specific MCExpr -----------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef X86_MCTARGETEXPR_H
|
||||||
|
#define X86_MCTARGETEXPR_H
|
||||||
|
|
||||||
|
#include "llvm/MC/MCExpr.h"
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
|
||||||
|
/// X86MCTargetExpr - This class represents symbol variants, like foo@GOT.
|
||||||
|
class X86MCTargetExpr : public MCTargetExpr {
|
||||||
|
public:
|
||||||
|
enum VariantKind {
|
||||||
|
GOT,
|
||||||
|
PLT,
|
||||||
|
GOTPCREL
|
||||||
|
};
|
||||||
|
private:
|
||||||
|
/// Sym - The symbol being referenced.
|
||||||
|
const MCSymbol * const Sym;
|
||||||
|
/// Kind - The modifier.
|
||||||
|
const VariantKind Kind;
|
||||||
|
|
||||||
|
X86MCTargetExpr(const MCSymbol *S, VariantKind K) : Sym(S), Kind(K) {}
|
||||||
|
public:
|
||||||
|
static X86MCTargetExpr *Create(const MCSymbol *Sym, VariantKind K,
|
||||||
|
MCContext &Ctx);
|
||||||
|
|
||||||
|
void PrintImpl(raw_ostream &OS) const;
|
||||||
|
bool EvaluateAsRelocatableImpl(MCValue &Res) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace llvm
|
||||||
|
|
||||||
|
#endif
|
@ -8,9 +8,9 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "X86TargetObjectFile.h"
|
#include "X86TargetObjectFile.h"
|
||||||
|
#include "X86MCTargetExpr.h"
|
||||||
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
|
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
|
||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
#include "llvm/MC/MCExpr.h"
|
|
||||||
#include "llvm/Target/Mangler.h"
|
#include "llvm/Target/Mangler.h"
|
||||||
#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@ -57,9 +57,9 @@ getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
|
|||||||
|
|
||||||
SmallString<128> Name;
|
SmallString<128> Name;
|
||||||
Mang->getNameWithPrefix(Name, GV, false);
|
Mang->getNameWithPrefix(Name, GV, false);
|
||||||
Name += "@GOTPCREL";
|
const MCSymbol *Sym = getContext().CreateSymbol(Name);
|
||||||
const MCExpr *Res =
|
const MCExpr *Res =
|
||||||
MCSymbolRefExpr::Create(Name.str(), getContext());
|
X86MCTargetExpr::Create(Sym, X86MCTargetExpr::GOTPCREL, getContext());
|
||||||
const MCExpr *Four = MCConstantExpr::Create(4, getContext());
|
const MCExpr *Four = MCConstantExpr::Create(4, getContext());
|
||||||
return MCBinaryExpr::CreateAdd(Res, Four, getContext());
|
return MCBinaryExpr::CreateAdd(Res, Four, getContext());
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ declare void @__gxx_personality_v0()
|
|||||||
declare void @__cxa_end_catch()
|
declare void @__cxa_end_catch()
|
||||||
|
|
||||||
; X64: Leh_frame_common_begin:
|
; X64: Leh_frame_common_begin:
|
||||||
; X64: .long ___gxx_personality_v0@GOTPCREL+4
|
; X64: .long (___gxx_personality_v0@GOTPCREL)+4
|
||||||
|
|
||||||
; X32: Leh_frame_common_begin:
|
; X32: Leh_frame_common_begin:
|
||||||
; X32: .long L___gxx_personality_v0$non_lazy_ptr-
|
; X32: .long L___gxx_personality_v0$non_lazy_ptr-
|
||||||
|
Loading…
x
Reference in New Issue
Block a user