root/trunk/llvm-2.6/llvm-typemonitor.cpp

Revision 340, 1.2 kB (checked in by mwarning, 2 years ago)

move llvm 2.7 bindings and added llvm 2.6 bindings from ldc project repo

Line 
1 /// Support for callbacks when an abstract type becomes more concrete.
2
3 #include "llvm/Support/Streams.h"
4 #include "llvm/Type.h"
5 #include "llvm-c/Core.h"
6
7 using namespace llvm;
8
9 extern "C" typedef int (*RefineCallback)(void *handle, LLVMTypeRef newT);
10
11 class TypeMonitor : AbstractTypeUser {
12     void *handle_;
13     RefineCallback callback_;
14    
15     void onRefineType(const Type* oldT, const Type* newT) {
16         callback_(handle_, wrap(newT));
17         oldT->removeAbstractTypeUser(this);
18         delete this;
19     }
20    
21     public:
22    
23     TypeMonitor(Type* T, void *handle, RefineCallback callback)
24     : handle_(handle), callback_(callback) {
25         T->addAbstractTypeUser(this);
26     }
27    
28     virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
29         onRefineType(OldTy, NewTy);
30     }
31    
32     virtual void typeBecameConcrete(const DerivedType *AbsTy) {
33         onRefineType(AbsTy, AbsTy);
34     }
35    
36     virtual void dump() const {
37         cerr << "<TypeMonitor>";
38     }
39 };
40
41 extern "C" void LLVMRegisterAbstractTypeCallback(LLVMTypeRef T,
42                                                  void *handle,
43                                                  RefineCallback callback)
44 {
45     new TypeMonitor(unwrap(T), handle, callback);
46 }
Note: See TracBrowser for help on using the browser.