comparison tools/binding/llvm-typemonitor.cpp @ 1651:cb960b882ca3 default tip

bindings were moved to dsource.org/projects/bindings/
author Moritz Warning <moritzwarning@web.de>
date Thu, 20 May 2010 20:05:03 +0200
parents 40bd4a0d4870
children
comparison
equal deleted inserted replaced
1650:40bd4a0d4870 1651:cb960b882ca3
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 }