diff options
author | Gordon Henriksen <gordonhenriksen@mac.com> | 2008-03-19 03:47:18 +0000 |
---|---|---|
committer | Gordon Henriksen <gordonhenriksen@mac.com> | 2008-03-19 03:47:18 +0000 |
commit | 34000979662d9ae9b22e4d05272b77d944871d1c (patch) | |
tree | a0a4000c80e6536358b67cd18236a24c5a75dbac /lib/VMCore | |
parent | 3a4c8563231f7cf690acc0ac799da54fc8f38bd1 (diff) | |
download | external_llvm-34000979662d9ae9b22e4d05272b77d944871d1c.zip external_llvm-34000979662d9ae9b22e4d05272b77d944871d1c.tar.gz external_llvm-34000979662d9ae9b22e4d05272b77d944871d1c.tar.bz2 |
C bindings for Module-, Function-, and BasicBlock::iterator.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48528 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Core.cpp | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index a44f96d..ac7738b 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -601,6 +601,38 @@ LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) { return wrap(unwrap(M)->getNamedGlobal(Name)); } +LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M) { + Module *Mod = unwrap(M); + Module::global_iterator I = Mod->global_begin(); + if (I == Mod->global_end()) + return 0; + return wrap(I); +} + +LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M) { + Module *Mod = unwrap(M); + Module::global_iterator I = Mod->global_end(); + if (I == Mod->global_begin()) + return 0; + return wrap(--I); +} + +LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar) { + GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar); + Module::global_iterator I = GV; + if (++I == GV->getParent()->global_end()) + return 0; + return wrap(I); +} + +LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar) { + GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar); + Module::global_iterator I = GV; + if (I == GV->getParent()->global_end()) + return 0; + return wrap(--I); +} + void LLVMDeleteGlobal(LLVMValueRef GlobalVar) { unwrap<GlobalVariable>(GlobalVar)->eraseFromParent(); } @@ -646,6 +678,38 @@ LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) { return wrap(unwrap(M)->getFunction(Name)); } +LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M) { + Module *Mod = unwrap(M); + Module::iterator I = Mod->begin(); + if (I == Mod->end()) + return 0; + return wrap(I); +} + +LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M) { + Module *Mod = unwrap(M); + Module::iterator I = Mod->end(); + if (I == Mod->begin()) + return 0; + return wrap(--I); +} + +LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn) { + Function *Func = unwrap<Function>(Fn); + Module::iterator I = Func; + if (++I == Func->getParent()->end()) + return 0; + return wrap(I); +} + +LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn) { + Function *Func = unwrap<Function>(Fn); + Module::iterator I = Func; + if (I == Func->getParent()->end()) + return 0; + return wrap(--I); +} + void LLVMDeleteFunction(LLVMValueRef Fn) { unwrap<Function>(Fn)->eraseFromParent(); } @@ -735,6 +799,38 @@ LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn) { return wrap(&unwrap<Function>(Fn)->getEntryBlock()); } +LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn) { + Function *Func = unwrap<Function>(Fn); + Function::iterator I = Func->begin(); + if (I == Func->end()) + return 0; + return wrap(I); +} + +LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn) { + Function *Func = unwrap<Function>(Fn); + Function::iterator I = Func->end(); + if (I == Func->begin()) + return 0; + return wrap(--I); +} + +LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB) { + BasicBlock *Block = unwrap(BB); + Function::iterator I = Block; + if (++I == Block->getParent()->end()) + return 0; + return wrap(I); +} + +LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) { + BasicBlock *Block = unwrap(BB); + Function::iterator I = Block; + if (I == Block->getParent()->begin()) + return 0; + return wrap(--I); +} + LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) { return wrap(new BasicBlock(Name, unwrap<Function>(FnRef))); } @@ -756,6 +852,38 @@ LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst) { return wrap(unwrap<Instruction>(Inst)->getParent()); } +LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB) { + BasicBlock *Block = unwrap(BB); + BasicBlock::iterator I = Block->begin(); + if (I == Block->end()) + return 0; + return wrap(I); +} + +LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB) { + BasicBlock *Block = unwrap(BB); + BasicBlock::iterator I = Block->end(); + if (I == Block->begin()) + return 0; + return wrap(--I); +} + +LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst) { + Instruction *Instr = unwrap<Instruction>(Inst); + BasicBlock::iterator I = Instr; + if (++I == Instr->getParent()->end()) + return 0; + return wrap(I); +} + +LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst) { + Instruction *Instr = unwrap<Instruction>(Inst); + BasicBlock::iterator I = Instr; + if (I == Instr->getParent()->begin()) + return 0; + return wrap(--I); +} + /*--.. Call and invoke instructions ........................................--*/ unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) { @@ -805,6 +933,13 @@ LLVMBuilderRef LLVMCreateBuilder() { return wrap(new LLVMFoldingBuilder()); } +void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block, + LLVMValueRef Instr) { + BasicBlock *BB = unwrap(Block); + Instruction *I = Instr? unwrap<Instruction>(Instr) : (Instruction*) BB->end(); + unwrap(Builder)->SetInsertPoint(BB, I); +} + void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) { Instruction *I = unwrap<Instruction>(Instr); unwrap(Builder)->SetInsertPoint(I->getParent(), I); |