summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorGordon Henriksen <gordonhenriksen@mac.com>2008-12-19 18:39:45 +0000
committerGordon Henriksen <gordonhenriksen@mac.com>2008-12-19 18:39:45 +0000
commit29e3894e7dfc416accb3c5469d90eabaed20e4c1 (patch)
tree3220521e7e24fa80078972f3cb7e75c34701ba68 /llvm
parentaf4c0bf44f76f0902e90ebf36a7072754f0b414f (diff)
downloadbcm5719-llvm-29e3894e7dfc416accb3c5469d90eabaed20e4c1.tar.gz
bcm5719-llvm-29e3894e7dfc416accb3c5469d90eabaed20e4c1.zip
C bindings for dyn_cast_or_null.
This operation can be used to build dyn_cast, isa, and cast. llvm-svn: 61252
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm-c/Core.h75
-rw-r--r--llvm/lib/VMCore/Core.cpp12
2 files changed, 77 insertions, 10 deletions
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 8cb2ef584d7..2516c72f1fb 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/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/llvm/lib/VMCore/Core.cpp b/llvm/lib/VMCore/Core.cpp
index fb24dc2bca3..962f7694927 100644
--- a/llvm/lib/VMCore/Core.cpp
+++ b/llvm/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 <cassert>
@@ -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<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
+ }
+
+LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST)
+
+
/*--.. Operations on constants of any type .................................--*/
LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) {
OpenPOWER on IntegriCloud