mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-02 07:11:49 +00:00
llvm-mc/Mach-O: Add MCCodeEmitter support, for encoding instructions.
- No relocations yet, of course. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80235 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7168a7dc6d
commit
4fac74950a
@ -251,7 +251,8 @@ namespace llvm {
|
||||
|
||||
/// createMachOStream - Create a machine code streamer which will generative
|
||||
/// Mach-O format object files.
|
||||
MCStreamer *createMachOStreamer(MCContext &Ctx, raw_ostream &OS);
|
||||
MCStreamer *createMachOStreamer(MCContext &Ctx, raw_ostream &OS,
|
||||
MCCodeEmitter *CE = 0);
|
||||
|
||||
/// createELFStreamer - Create a machine code streamer which will generative
|
||||
/// ELF format object files.
|
||||
|
@ -11,9 +11,12 @@
|
||||
|
||||
#include "llvm/MC/MCAssembler.h"
|
||||
#include "llvm/MC/MCContext.h"
|
||||
#include "llvm/MC/MCCodeEmitter.h"
|
||||
#include "llvm/MC/MCInst.h"
|
||||
#include "llvm/MC/MCSection.h"
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
@ -42,6 +45,8 @@ class MCMachOStreamer : public MCStreamer {
|
||||
private:
|
||||
MCAssembler Assembler;
|
||||
|
||||
MCCodeEmitter *Emitter;
|
||||
|
||||
MCSectionData *CurSectionData;
|
||||
|
||||
DenseMap<const MCSection*, MCSectionData*> SectionMap;
|
||||
@ -68,8 +73,9 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
MCMachOStreamer(MCContext &Context, raw_ostream &_OS)
|
||||
: MCStreamer(Context), Assembler(_OS), CurSectionData(0) {}
|
||||
MCMachOStreamer(MCContext &Context, raw_ostream &_OS, MCCodeEmitter *_Emitter)
|
||||
: MCStreamer(Context), Assembler(_OS), Emitter(_Emitter),
|
||||
CurSectionData(0) {}
|
||||
~MCMachOStreamer() {}
|
||||
|
||||
const MCValue &AddValueSymbols(const MCValue &Value) {
|
||||
@ -302,13 +308,26 @@ void MCMachOStreamer::EmitValueToOffset(const MCValue &Offset,
|
||||
}
|
||||
|
||||
void MCMachOStreamer::EmitInstruction(const MCInst &Inst) {
|
||||
llvm_unreachable("FIXME: Not yet implemented!");
|
||||
// Scan for values.
|
||||
for (unsigned i = 0; i != Inst.getNumOperands(); ++i)
|
||||
if (Inst.getOperand(i).isMCValue())
|
||||
AddValueSymbols(Inst.getOperand(i).getMCValue());
|
||||
|
||||
if (!Emitter)
|
||||
llvm_unreachable("no code emitter available!");
|
||||
|
||||
// FIXME: Relocations!
|
||||
SmallString<256> Code;
|
||||
raw_svector_ostream VecOS(Code);
|
||||
Emitter->EncodeInstruction(Inst, VecOS);
|
||||
EmitBytes(VecOS.str());
|
||||
}
|
||||
|
||||
void MCMachOStreamer::Finish() {
|
||||
Assembler.Finish();
|
||||
}
|
||||
|
||||
MCStreamer *llvm::createMachOStreamer(MCContext &Context, raw_ostream &OS) {
|
||||
return new MCMachOStreamer(Context, OS);
|
||||
MCStreamer *llvm::createMachOStreamer(MCContext &Context, raw_ostream &OS,
|
||||
MCCodeEmitter *CE) {
|
||||
return new MCMachOStreamer(Context, OS, CE);
|
||||
}
|
||||
|
@ -252,7 +252,8 @@ static int AssembleInput(const char *ProgName) {
|
||||
Str.reset(createAsmStreamer(Ctx, *Out, *TAI, AP.get(), CE.get()));
|
||||
} else {
|
||||
assert(FileType == OFT_ObjectFile && "Invalid file type!");
|
||||
Str.reset(createMachOStreamer(Ctx, *Out));
|
||||
CE.reset(TheTarget->createCodeEmitter(*TM));
|
||||
Str.reset(createMachOStreamer(Ctx, *Out, CE.get()));
|
||||
}
|
||||
|
||||
AsmParser Parser(SrcMgr, Ctx, *Str.get());
|
||||
|
Loading…
Reference in New Issue
Block a user