view tools/binding/llvm-typemonitor.cpp @ 1650:40bd4a0d4870

Update to work with LLVM 2.7. Removed use of dyn_cast, llvm no compiles without exceptions and rtti by default. We do need exceptions for the libconfig stuff, but rtti isn't necessary (anymore). Debug info needs to be rewritten, as in LLVM 2.7 the format has completely changed. To have something to look at while rewriting, the old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means that you have to define this to compile at the moment. Updated tango 0.99.9 patch to include updated EH runtime code, which is needed for LLVM 2.7 as well.
author Tomas Lindquist Olsen
date Wed, 19 May 2010 12:42:32 +0200
parents 4ff9ab0d472c
children
line wrap: on
line source

/// Support for callbacks when an abstract type becomes more concrete.

#include "llvm/Support/Streams.h"
#include "llvm/Type.h"
#include "llvm-c/Core.h"

using namespace llvm;

extern "C" typedef int (*RefineCallback)(void *handle, LLVMTypeRef newT);

class TypeMonitor : AbstractTypeUser {
    void *handle_;
    RefineCallback callback_;
    
    void onRefineType(const Type* oldT, const Type* newT) {
        callback_(handle_, wrap(newT));
        oldT->removeAbstractTypeUser(this);
        delete this;
    }
    
    public:
    
    TypeMonitor(Type* T, void *handle, RefineCallback callback)
    : handle_(handle), callback_(callback) {
        T->addAbstractTypeUser(this);
    }
    
    virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
        onRefineType(OldTy, NewTy);
    }
    
    virtual void typeBecameConcrete(const DerivedType *AbsTy) {
        onRefineType(AbsTy, AbsTy);
    }
    
    virtual void dump() const {
        cerr << "<TypeMonitor>";
    }
};

extern "C" void LLVMRegisterAbstractTypeCallback(LLVMTypeRef T,
                                                 void *handle,
                                                 RefineCallback callback)
{
    new TypeMonitor(unwrap(T), handle, callback);
}