comparison tools/binding/llvm-typemonitor.cpp @ 1273:1ba61de8796b

Committing LLVM binding for D as it currently exists in the SVN repository.
author Frits van Bommel <fvbommel wxs.nl>
date Mon, 27 Apr 2009 22:33:17 +0200
parents
children 4ff9ab0d472c
comparison
equal deleted inserted replaced
1272:dd4766851b37 1273:1ba61de8796b
1 /// Support for callbacks when an abstract type becomes more concrete.
2
3 #include "llvm/Type.h"
4 #include "llvm-c/Core.h"
5
6 using namespace llvm;
7
8 extern "C" typedef int (*RefineCallback)(void *handle, LLVMTypeRef newT);
9
10 class TypeMonitor : AbstractTypeUser {
11 void *handle_;
12 RefineCallback callback_;
13
14 void onRefineType(const Type* oldT, const Type* newT) {
15 callback_(handle_, wrap(newT));
16 oldT->removeAbstractTypeUser(this);
17 delete this;
18 }
19
20 public:
21
22 TypeMonitor(Type* T, void *handle, RefineCallback callback)
23 : handle_(handle), callback_(callback) {
24 T->addAbstractTypeUser(this);
25 }
26
27 virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
28 onRefineType(OldTy, NewTy);
29 }
30
31 virtual void typeBecameConcrete(const DerivedType *AbsTy) {
32 onRefineType(AbsTy, AbsTy);
33 }
34
35 virtual void dump() const {
36 cerr << "<TypeMonitor>";
37 }
38 };
39
40 extern "C" void LLVMRegisterAbstractTypeCallback(LLVMTypeRef T,
41 void *handle,
42 RefineCallback callback)
43 {
44 new TypeMonitor(unwrap(T), handle, callback);
45 }