From 447e26d53ed283cb2b18a24d7b0d7e447d03a27e Mon Sep 17 00:00:00 2001 From: Gordon Henriksen Date: Fri, 19 Dec 2008 18:39:45 +0000 Subject: [PATCH] C bindings for dyn_cast_or_null. This operation can be used to build dyn_cast, isa, and cast. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61252 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm-c/Core.h | 75 ++++++++++++++++++++++++++++++++++++++++++++------- lib/VMCore/Core.cpp | 12 +++++++++ 2 files changed, 77 insertions(+), 10 deletions(-) diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index 8cb2ef584d7..2516c72f1fb 100644 --- a/include/llvm-c/Core.h +++ b/include/llvm-c/Core.h @@ -282,24 +282,79 @@ void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle); /* The bulk of LLVM's object model consists of values, which comprise a very * rich type hierarchy. - * - * values: - * constants: - * scalar constants - * composite contants - * globals: - * global variable - * function - * alias - * basic blocks */ +#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \ + macro(Argument) \ + macro(BasicBlock) \ + macro(InlineAsm) \ + macro(User) \ + macro(Constant) \ + macro(ConstantAggregateZero) \ + macro(ConstantArray) \ + macro(ConstantExpr) \ + macro(ConstantFP) \ + macro(ConstantInt) \ + macro(ConstantPointerNull) \ + macro(ConstantStruct) \ + macro(ConstantVector) \ + macro(GlobalValue) \ + macro(Function) \ + macro(GlobalAlias) \ + macro(GlobalVariable) \ + macro(UndefValue) \ + macro(Instruction) \ + macro(BinaryOperator) \ + macro(CallInst) \ + macro(IntrinsicInst) \ + macro(DbgInfoIntrinsic) \ + macro(DbgDeclareInst) \ + macro(DbgFuncStartInst) \ + macro(DbgRegionEndInst) \ + macro(DbgRegionStartInst) \ + macro(DbgStopPointInst) \ + macro(EHSelectorInst) \ + macro(MemIntrinsic) \ + macro(MemCpyInst) \ + macro(MemMoveInst) \ + macro(MemSetInst) \ + macro(CmpInst) \ + macro(FCmpInst) \ + macro(ICmpInst) \ + macro(VFCmpInst) \ + macro(VICmpInst) \ + macro(ExtractElementInst) \ + macro(GetElementPtrInst) \ + macro(InsertElementInst) \ + macro(InsertValueInst) \ + macro(PHINode) \ + macro(SelectInst) \ + macro(ShuffleVectorInst) \ + macro(StoreInst) \ + macro(TerminatorInst) \ + macro(BranchInst) \ + macro(InvokeInst) \ + macro(ReturnInst) \ + macro(SwitchInst) \ + macro(UnreachableInst) \ + macro(UnwindInst) \ + macro(UnaryInstruction) \ + macro(AllocationInst) \ + macro(CastInst) \ + macro(ExtractValueInst) + /* Operations on all values */ LLVMTypeRef LLVMTypeOf(LLVMValueRef Val); const char *LLVMGetValueName(LLVMValueRef Val); void LLVMSetValueName(LLVMValueRef Val, const char *Name); void LLVMDumpValue(LLVMValueRef Val); +/* Conversion functions. Return the input value if it is an instance of the + specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */ +#define LLVM_DECLARE_VALUE_CAST(name) \ + LLVMValueRef LLVMIsA##name(LLVMValueRef Val); +LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST) + /* Operations on constants of any type */ LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */ LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */ diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index fb24dc2bca3..962f7694927 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -21,6 +21,7 @@ #include "llvm/TypeSymbolTable.h" #include "llvm/ModuleProvider.h" #include "llvm/InlineAsm.h" +#include "llvm/IntrinsicInst.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/CallSite.h" #include @@ -252,6 +253,17 @@ void LLVMDumpValue(LLVMValueRef Val) { unwrap(Val)->dump(); } + +/*--.. Conversion functions ................................................--*/ + +#define LLVM_DEFINE_VALUE_CAST(name) \ + LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \ + return wrap(static_cast(dyn_cast_or_null(unwrap(Val)))); \ + } + +LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST) + + /*--.. Operations on constants of any type .................................--*/ LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) { -- 2.11.0