blob: 93606931868814019299e2c888d1115480d85afa [file] [log] [blame]
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +00001//===-- llvm/CodeGen/MachineBasicBlock.cpp ----------------------*- 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// Collect the sequence of machine instructions for a basic block.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/CodeGen/MachineBasicBlock.h"
15
16#include "llvm/BasicBlock.h"
17#include "llvm/CodeGen/MachineFunction.h"
18#include "llvm/CodeGen/MachineInstr.h"
19#include "Support/LeakDetector.h"
20#include <iostream>
21
22using namespace llvm;
23
24MachineInstr* ilist_traits<MachineInstr>::createNode()
25{
26 MachineInstr* dummy = new MachineInstr(0, 0);
27 LeakDetector::removeGarbageObject(dummy);
28 return dummy;
29}
30
31void ilist_traits<MachineInstr>::addNodeToList(MachineInstr* N)
32{
33 assert(N->parent == 0 && "machine instruction already in a basic block");
34 N->parent = parent;
35 LeakDetector::removeGarbageObject(N);
36}
37
38void ilist_traits<MachineInstr>::removeNodeFromList(MachineInstr* N)
39{
40 assert(N->parent != 0 && "machine instruction not in a basic block");
41 N->parent = 0;
42 LeakDetector::addGarbageObject(N);
43}
44
45void ilist_traits<MachineInstr>::transferNodesFromList(
46 iplist<MachineInstr, ilist_traits<MachineInstr> >& toList,
47 ilist_iterator<MachineInstr> first,
48 ilist_iterator<MachineInstr> last)
49{
50 if (parent != toList.parent)
51 for (; first != last; ++first)
52 first->parent = toList.parent;
53}
54
55void MachineBasicBlock::dump() const
56{
57 print(std::cerr);
58}
59
60void MachineBasicBlock::print(std::ostream &OS) const
61{
62 const BasicBlock *LBB = getBasicBlock();
63 OS << "\n" << LBB->getName() << " (" << (const void*)LBB << "):\n";
64 for (const_iterator I = begin(); I != end(); ++I) {
65 OS << "\t";
66 I->print(OS, MachineFunction::get(LBB->getParent()).getTarget());
67 }
68}