~ubuntu-branches/ubuntu/feisty/clamav/feisty

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/VMCore/LLVMContextImpl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-20 10:33:44 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20070220103344-zgcu2psnx9d98fpa
Tags: upstream-0.90
ImportĀ upstreamĀ versionĀ 0.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//===-- LLVMContextImpl.cpp - Implement LLVMContextImpl -------------------===//
2
 
//
3
 
//                     The LLVM Compiler Infrastructure
4
 
//
5
 
// This file is distributed under the University of Illinois Open Source
6
 
// License. See LICENSE.TXT for details.
7
 
//
8
 
//===----------------------------------------------------------------------===//
9
 
//
10
 
//  This file implements the opaque LLVMContextImpl.
11
 
//
12
 
//===----------------------------------------------------------------------===//
13
 
 
14
 
#include "LLVMContextImpl.h"
15
 
#include <algorithm>
16
 
using namespace llvm;
17
 
 
18
 
LLVMContextImpl::LLVMContextImpl(LLVMContext &C)
19
 
  : TheTrueVal(0), TheFalseVal(0),
20
 
    VoidTy(C, Type::VoidTyID),
21
 
    LabelTy(C, Type::LabelTyID),
22
 
    FloatTy(C, Type::FloatTyID),
23
 
    DoubleTy(C, Type::DoubleTyID),
24
 
    MetadataTy(C, Type::MetadataTyID),
25
 
    X86_FP80Ty(C, Type::X86_FP80TyID),
26
 
    FP128Ty(C, Type::FP128TyID),
27
 
    PPC_FP128Ty(C, Type::PPC_FP128TyID),
28
 
    Int1Ty(C, 1),
29
 
    Int8Ty(C, 8),
30
 
    Int16Ty(C, 16),
31
 
    Int32Ty(C, 32),
32
 
    Int64Ty(C, 64),
33
 
    AlwaysOpaqueTy(new OpaqueType(C)) {
34
 
  InlineAsmDiagHandler = 0;
35
 
  InlineAsmDiagContext = 0;
36
 
      
37
 
  // Make sure the AlwaysOpaqueTy stays alive as long as the Context.
38
 
  AlwaysOpaqueTy->addRef();
39
 
  OpaqueTypes.insert(AlwaysOpaqueTy);
40
 
}
41
 
 
42
 
namespace {
43
 
struct DropReferences {
44
 
  // Takes the value_type of a ConstantUniqueMap's internal map, whose 'second'
45
 
  // is a Constant*.
46
 
  template<typename PairT>
47
 
  void operator()(const PairT &P) {
48
 
    P.second->dropAllReferences();
49
 
  }
50
 
};
51
 
}
52
 
 
53
 
LLVMContextImpl::~LLVMContextImpl() {
54
 
  std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(),
55
 
                DropReferences());
56
 
  std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(),
57
 
                DropReferences());
58
 
  std::for_each(StructConstants.map_begin(), StructConstants.map_end(),
59
 
                DropReferences());
60
 
  std::for_each(VectorConstants.map_begin(), VectorConstants.map_end(),
61
 
                DropReferences());
62
 
  ExprConstants.freeConstants();
63
 
  ArrayConstants.freeConstants();
64
 
  StructConstants.freeConstants();
65
 
  VectorConstants.freeConstants();
66
 
  AggZeroConstants.freeConstants();
67
 
  NullPtrConstants.freeConstants();
68
 
  UndefValueConstants.freeConstants();
69
 
  InlineAsms.freeConstants();
70
 
  for (IntMapTy::iterator I = IntConstants.begin(), E = IntConstants.end(); 
71
 
       I != E; ++I) {
72
 
    delete I->second;
73
 
  }
74
 
  for (FPMapTy::iterator I = FPConstants.begin(), E = FPConstants.end(); 
75
 
       I != E; ++I) {
76
 
    delete I->second;
77
 
  }
78
 
  AlwaysOpaqueTy->dropRef();
79
 
  for (OpaqueTypesTy::iterator I = OpaqueTypes.begin(), E = OpaqueTypes.end();
80
 
       I != E; ++I) {
81
 
    (*I)->AbstractTypeUsers.clear();
82
 
    delete *I;
83
 
  }
84
 
  // Destroy MDNodes.  ~MDNode can move and remove nodes between the MDNodeSet
85
 
  // and the NonUniquedMDNodes sets, so copy the values out first.
86
 
  SmallVector<MDNode*, 8> MDNodes;
87
 
  MDNodes.reserve(MDNodeSet.size() + NonUniquedMDNodes.size());
88
 
  for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end();
89
 
       I != E; ++I) {
90
 
    MDNodes.push_back(&*I);
91
 
  }
92
 
  MDNodes.append(NonUniquedMDNodes.begin(), NonUniquedMDNodes.end());
93
 
  for (SmallVector<MDNode*, 8>::iterator I = MDNodes.begin(),
94
 
         E = MDNodes.end(); I != E; ++I) {
95
 
    (*I)->destroy();
96
 
  }
97
 
  assert(MDNodeSet.empty() && NonUniquedMDNodes.empty() &&
98
 
         "Destroying all MDNodes didn't empty the Context's sets.");
99
 
  // Destroy MDStrings.
100
 
  for (StringMap<MDString*>::iterator I = MDStringCache.begin(),
101
 
         E = MDStringCache.end(); I != E; ++I) {
102
 
    delete I->second;
103
 
  }
104
 
}