blob: e7a36009cb1a4e7f8725c43aa09bb3769cf692aa [file] [log] [blame]
Misha Brukman5dfe3a92004-06-21 16:55:25 +00001//===-- PowerPCCodeEmitter.cpp - JIT Code Emitter for PowerPC -----*- C++ -*-=//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//
11//===----------------------------------------------------------------------===//
12
13#include "PowerPCTargetMachine.h"
Misha Brukmanb05daff2004-08-09 23:03:59 +000014#include "llvm/CodeGen/MachineCodeEmitter.h"
15#include "llvm/CodeGen/MachineFunctionPass.h"
16#include "llvm/CodeGen/Passes.h"
17#include "Support/Debug.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000018
19namespace llvm {
20
Misha Brukmanb05daff2004-08-09 23:03:59 +000021namespace {
22 class PowerPCCodeEmitter : public MachineFunctionPass {
23 TargetMachine &TM;
24 MachineCodeEmitter &MCE;
25
26 public:
27 PowerPCCodeEmitter(TargetMachine &T, MachineCodeEmitter &M)
28 : TM(T), MCE(M) {}
29
30 const char *getPassName() const { return "PowerPC Machine Code Emitter"; }
31
32 /// runOnMachineFunction - emits the given MachineFunction to memory
33 ///
34 bool runOnMachineFunction(MachineFunction &MF);
35
36 /// emitBasicBlock - emits the given MachineBasicBlock to memory
37 ///
38 void emitBasicBlock(MachineBasicBlock &MBB);
39
40 /// emitWord - write a 32-bit word to memory at the current PC
41 ///
42 void emitWord(unsigned w) { MCE.emitWord(w); }
43
44 unsigned getValueBit(int64_t Val, unsigned bit);
45
46 /// getBinaryCodeForInstr - returns the assembled code for an instruction
47 ///
48 unsigned getBinaryCodeForInstr(MachineInstr &MI) { return 0; }
49 };
50}
51
Misha Brukman5dfe3a92004-06-21 16:55:25 +000052/// addPassesToEmitMachineCode - Add passes to the specified pass manager to get
53/// machine code emitted. This uses a MachineCodeEmitter object to handle
54/// actually outputting the machine code and resolving things like the address
55/// of functions. This method should returns true if machine code emission is
56/// not supported.
57///
58bool PowerPCTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
59 MachineCodeEmitter &MCE) {
Misha Brukmanb05daff2004-08-09 23:03:59 +000060 // Machine code emitter pass for PowerPC
61 PM.add(new PowerPCCodeEmitter(*this, MCE));
Misha Brukman5dfe3a92004-06-21 16:55:25 +000062 // Delete machine code for this function after emitting it:
Misha Brukmanb05daff2004-08-09 23:03:59 +000063 PM.add(createMachineCodeDeleter());
64 // We don't yet support machine code emission
65 return true;
66}
67
68bool PowerPCCodeEmitter::runOnMachineFunction(MachineFunction &MF) {
69 MCE.startFunction(MF);
70 MCE.emitConstantPool(MF.getConstantPool());
71 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
72 emitBasicBlock(*I);
73 MCE.finishFunction(MF);
74 return false;
75}
76
77void PowerPCCodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) {
78 for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I)
79 emitWord(getBinaryCodeForInstr(*I));
80}
81
82unsigned PowerPCCodeEmitter::getValueBit(int64_t Val, unsigned bit) {
83 Val >>= bit;
84 return (Val & 1);
Misha Brukman5dfe3a92004-06-21 16:55:25 +000085}
86
87void *PowerPCJITInfo::getJITStubForFunction(Function *F,
88 MachineCodeEmitter &MCE) {
89 assert (0 && "PowerPCJITInfo::getJITStubForFunction not implemented");
90 return 0;
91}
92
93void PowerPCJITInfo::replaceMachineCodeForFunction (void *Old, void *New) {
94 assert (0 && "PowerPCJITInfo::replaceMachineCodeForFunction not implemented");
95}
96
Misha Brukmanb05daff2004-08-09 23:03:59 +000097//#include "PowerPCGenCodeEmitter.inc"
98
Misha Brukman5dfe3a92004-06-21 16:55:25 +000099} // end llvm namespace
100