[llvm-commits] [llvm] r83821 - in /llvm/trunk: include/llvm-c/Core.h lib/VMCore/Core.cpp
Chris Lattner
sabre at nondot.org
Sun Oct 11 21:01:03 PDT 2009
Author: lattner
Date: Sun Oct 11 23:01:02 2009
New Revision: 83821
URL: http://llvm.org/viewvc/llvm-project?rev=83821&view=rev
Log:
add some more hooks to the C bindings, patch by Kenneth Uildriks!
Modified:
llvm/trunk/include/llvm-c/Core.h
llvm/trunk/lib/VMCore/Core.cpp
Modified: llvm/trunk/include/llvm-c/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=83821&r1=83820&r2=83821&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/Core.h (original)
+++ llvm/trunk/include/llvm-c/Core.h Sun Oct 11 23:01:02 2009
@@ -89,6 +89,12 @@
/** See the llvm::PassManagerBase class. */
typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
+/**
+ * Used to iterate through the uses of a Value, allowing access to all Values
+ * that use this Value. See the llvm::Use and llvm::value_use_iterator classes.
+ */
+typedef struct LLVMOpaqueUseIterator *LLVMUseIteratorRef;
+
typedef enum {
LLVMZExtAttribute = 1<<0,
LLVMSExtAttribute = 1<<1,
@@ -114,6 +120,62 @@
} LLVMAttribute;
typedef enum {
+ LLVMRet = 1,
+ LLVMBr = 2,
+ LLVMSwitch = 3,
+ LLVMInvoke = 4,
+ LLVMUnwind = 5,
+ LLVMUnreachable = 6,
+ LLVMAdd = 7,
+ LLVMFAdd = 8,
+ LLVMSub = 9,
+ LLVMFSub = 10,
+ LLVMMul = 11,
+ LLVMFMul = 12,
+ LLVMUDiv = 13,
+ LLVMSDiv = 14,
+ LLVMFDiv = 15,
+ LLVMURem = 16,
+ LLVMSRem = 17,
+ LLVMFRem = 18,
+ LLVMShl = 19,
+ LLVMLShr = 20,
+ LLVMAShr = 21,
+ LLVMAnd = 22,
+ LLVMOr = 23,
+ LLVMXor = 24,
+ LLVMMalloc = 25,
+ LLVMFree = 26,
+ LLVMAlloca = 27,
+ LLVMLoad = 28,
+ LLVMStore = 29,
+ LLVMGetElementPtr = 30,
+ LLVMTrunk = 31,
+ LLVMZExt = 32,
+ LLVMSExt = 33,
+ LLVMFPToUI = 34,
+ LLVMFPToSI = 35,
+ LLVMUIToFP = 36,
+ LLVMSIToFP = 37,
+ LLVMFPTrunc = 38,
+ LLVMFPExt = 39,
+ LLVMPtrToInt = 40,
+ LLVMIntToPtr = 41,
+ LLVMBitCast = 42,
+ LLVMICmp = 43,
+ LLVMFCmp = 44,
+ LLVMPHI = 45,
+ LLVMCall = 46,
+ LLVMSelect = 47,
+ LLVMVAArg = 50,
+ LLVMExtractElement = 51,
+ LLVMInsertElement = 52,
+ LLVMShuffleVector = 53,
+ LLVMExtractValue = 54,
+ LLVMInsertValue = 55
+} LLVMOpcode;
+
+typedef enum {
LLVMVoidTypeKind, /**< type with no size */
LLVMFloatTypeKind, /**< 32 bit floating point type */
LLVMDoubleTypeKind, /**< 64 bit floating point type */
@@ -419,6 +481,7 @@
const char *LLVMGetValueName(LLVMValueRef Val);
void LLVMSetValueName(LLVMValueRef Val, const char *Name);
void LLVMDumpValue(LLVMValueRef Val);
+void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
/* Conversion functions. Return the input value if it is an instance of the
specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
@@ -426,6 +489,15 @@
LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
+/* Operations on Uses */
+LLVMUseIteratorRef LLVMGetFirstUse(LLVMValueRef Val);
+LLVMUseIteratorRef LLVMGetNextUse(LLVMUseIteratorRef U);
+LLVMValueRef LLVMGetUser(LLVMUseIteratorRef U);
+LLVMValueRef LLVMGetUsedValue(LLVMUseIteratorRef U);
+
+/* Operations on Users */
+LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
+
/* Operations on constants of any type */
LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
@@ -446,6 +518,8 @@
LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
unsigned SLen);
+unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
+long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
/* Operations on composite constants */
@@ -464,6 +538,7 @@
LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
/* Constant expressions */
+LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
@@ -587,6 +662,7 @@
const char *LLVMGetGC(LLVMValueRef Fn);
void LLVMSetGC(LLVMValueRef Fn, const char *Name);
void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
+LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
/* Operations on parameters */
@@ -600,6 +676,7 @@
LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
+LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
/* Operations on basic blocks */
@@ -950,6 +1027,7 @@
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
+ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseIteratorRef )
DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
#undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
Modified: llvm/trunk/lib/VMCore/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=83821&r1=83820&r2=83821&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Core.cpp (original)
+++ llvm/trunk/lib/VMCore/Core.cpp Sun Oct 11 23:01:02 2009
@@ -389,6 +389,9 @@
unwrap(Val)->dump();
}
+void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
+ unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal));
+}
/*--.. Conversion functions ................................................--*/
@@ -399,6 +402,31 @@
LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST)
+/*--.. Operations on Uses ..................................................--*/
+LLVMUseIteratorRef LLVMGetFirstUse(LLVMValueRef Val) {
+ Value *V = unwrap(Val);
+ Value::use_iterator I = V->use_begin();
+ if (I == V->use_end())
+ return 0;
+ return wrap(&(I.getUse()));
+}
+
+LLVMUseIteratorRef LLVMGetNextUse(LLVMUseIteratorRef UR) {
+ return wrap(unwrap(UR)->getNext());
+}
+
+LLVMValueRef LLVMGetUser(LLVMUseIteratorRef UR) {
+ return wrap(unwrap(UR)->getUser());
+}
+
+LLVMValueRef LLVMGetUsedValue(LLVMUseIteratorRef UR) {
+ return wrap(unwrap(UR)->get());
+}
+
+/*--.. Operations on Users .................................................--*/
+LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index) {
+ return wrap(unwrap<User>(Val)->getOperand(Index));
+}
/*--.. Operations on constants of any type .................................--*/
@@ -465,6 +493,14 @@
return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen)));
}
+unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) {
+ return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
+}
+
+long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) {
+ return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
+}
+
/*--.. Operations on composite constants ...................................--*/
LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
@@ -506,6 +542,10 @@
/*--.. Constant expressions ................................................--*/
+LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal) {
+ return (LLVMOpcode)unwrap<ConstantExpr>(ConstantVal)->getOpcode();
+}
+
LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty) {
return wrap(ConstantExpr::getAlignOf(unwrap(Ty)));
}
@@ -1027,7 +1067,10 @@
}
LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar) {
- return wrap(unwrap<GlobalVariable>(GlobalVar)->getInitializer());
+ GlobalVariable* GV = unwrap<GlobalVariable>(GlobalVar);
+ if ( !GV->hasInitializer() )
+ return 0;
+ return wrap(GV->getInitializer());
}
void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal) {
@@ -1149,6 +1192,13 @@
Func->setAttributes(PALnew);
}
+LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn) {
+ Function *Func = unwrap<Function>(Fn);
+ const AttrListPtr PAL = Func->getAttributes();
+ Attributes attr = PAL.getFnAttributes();
+ return (LLVMAttribute)attr;
+}
+
/*--.. Operations on parameters ............................................--*/
unsigned LLVMCountParams(LLVMValueRef FnRef) {
@@ -1215,6 +1265,14 @@
unwrap<Argument>(Arg)->removeAttr(PA);
}
+LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg) {
+ Argument *A = unwrap<Argument>(Arg);
+ Attributes attr = A->getParent()->getAttributes().getParamAttributes(
+ A->getArgNo()+1);
+ return (LLVMAttribute)attr;
+}
+
+
void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
unwrap<Argument>(Arg)->addAttr(
Attribute::constructAlignmentFromInt(align));
More information about the llvm-commits
mailing list