blob: b8eb6b67142b63017e3bbfa2f940ed55f85ee4d7 [file] [log] [blame]
Misha Brukman3d9a6c22004-08-11 00:09:42 +00001//===-- PPC32CodeEmitter.cpp - JIT Code Emitter for PowerPC32 -----*- C++ -*-=//
Misha Brukman5dfe3a92004-06-21 16:55:25 +00002//
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
Misha Brukman3d9a6c22004-08-11 00:09:42 +000013#include "PPC32JITInfo.h"
14#include "PPC32TargetMachine.h"
Misha Brukmanb05daff2004-08-09 23:03:59 +000015#include "llvm/CodeGen/MachineCodeEmitter.h"
16#include "llvm/CodeGen/MachineFunctionPass.h"
17#include "llvm/CodeGen/Passes.h"
18#include "Support/Debug.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000019
20namespace llvm {
21
Misha Brukmanb05daff2004-08-09 23:03:59 +000022namespace {
Misha Brukman3d9a6c22004-08-11 00:09:42 +000023 class PPC32CodeEmitter : public MachineFunctionPass {
Misha Brukmanb05daff2004-08-09 23:03:59 +000024 TargetMachine &TM;
25 MachineCodeEmitter &MCE;
26
27 public:
Misha Brukman3d9a6c22004-08-11 00:09:42 +000028 PPC32CodeEmitter(TargetMachine &T, MachineCodeEmitter &M)
Misha Brukmanb05daff2004-08-09 23:03:59 +000029 : TM(T), MCE(M) {}
30
31 const char *getPassName() const { return "PowerPC Machine Code Emitter"; }
32
33 /// runOnMachineFunction - emits the given MachineFunction to memory
34 ///
35 bool runOnMachineFunction(MachineFunction &MF);
36
37 /// emitBasicBlock - emits the given MachineBasicBlock to memory
38 ///
39 void emitBasicBlock(MachineBasicBlock &MBB);
40
41 /// emitWord - write a 32-bit word to memory at the current PC
42 ///
43 void emitWord(unsigned w) { MCE.emitWord(w); }
44
45 unsigned getValueBit(int64_t Val, unsigned bit);
46
47 /// getBinaryCodeForInstr - returns the assembled code for an instruction
48 ///
49 unsigned getBinaryCodeForInstr(MachineInstr &MI) { return 0; }
50 };
51}
52
Misha Brukman5dfe3a92004-06-21 16:55:25 +000053/// addPassesToEmitMachineCode - Add passes to the specified pass manager to get
54/// machine code emitted. This uses a MachineCodeEmitter object to handle
55/// actually outputting the machine code and resolving things like the address
56/// of functions. This method should returns true if machine code emission is
57/// not supported.
58///
Misha Brukman3d9a6c22004-08-11 00:09:42 +000059bool PPC32TargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
60 MachineCodeEmitter &MCE) {
Misha Brukmanb05daff2004-08-09 23:03:59 +000061 // Machine code emitter pass for PowerPC
Misha Brukman3d9a6c22004-08-11 00:09:42 +000062 PM.add(new PPC32CodeEmitter(*this, MCE));
Misha Brukman5dfe3a92004-06-21 16:55:25 +000063 // Delete machine code for this function after emitting it:
Misha Brukmanb05daff2004-08-09 23:03:59 +000064 PM.add(createMachineCodeDeleter());
65 // We don't yet support machine code emission
66 return true;
67}
68
Misha Brukman3d9a6c22004-08-11 00:09:42 +000069bool PPC32CodeEmitter::runOnMachineFunction(MachineFunction &MF) {
Misha Brukmanb05daff2004-08-09 23:03:59 +000070 MCE.startFunction(MF);
71 MCE.emitConstantPool(MF.getConstantPool());
72 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
73 emitBasicBlock(*I);
74 MCE.finishFunction(MF);
75 return false;
76}
77
Misha Brukman3d9a6c22004-08-11 00:09:42 +000078void PPC32CodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) {
Misha Brukmanb05daff2004-08-09 23:03:59 +000079 for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I)
80 emitWord(getBinaryCodeForInstr(*I));
81}
82
Misha Brukman3d9a6c22004-08-11 00:09:42 +000083unsigned PPC32CodeEmitter::getValueBit(int64_t Val, unsigned bit) {
Misha Brukmanb05daff2004-08-09 23:03:59 +000084 Val >>= bit;
85 return (Val & 1);
Misha Brukman5dfe3a92004-06-21 16:55:25 +000086}
87
Misha Brukman3d9a6c22004-08-11 00:09:42 +000088void *PPC32JITInfo::getJITStubForFunction(Function *F,
89 MachineCodeEmitter &MCE) {
90 assert (0 && "PPC32JITInfo::getJITStubForFunction not implemented");
Misha Brukman5dfe3a92004-06-21 16:55:25 +000091 return 0;
92}
93
Misha Brukman3d9a6c22004-08-11 00:09:42 +000094void PPC32JITInfo::replaceMachineCodeForFunction (void *Old, void *New) {
95 assert (0 && "PPC32JITInfo::replaceMachineCodeForFunction not implemented");
Misha Brukman5dfe3a92004-06-21 16:55:25 +000096}
97
Misha Brukmanb05daff2004-08-09 23:03:59 +000098//#include "PowerPCGenCodeEmitter.inc"
99
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000100} // end llvm namespace
101