Mercurial > projects > ldc
comparison tools/binding/llvm-ext.cpp @ 1273:1ba61de8796b
Committing LLVM binding for D as it currently exists in the SVN repository.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Mon, 27 Apr 2009 22:33:17 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1272:dd4766851b37 | 1273:1ba61de8796b |
---|---|
1 // Extension of the LLVM C interface for use with D, some things in the | |
2 // LLVM 2.2 release are kind sparse or even broken... | |
3 // | |
4 // This file is distributed under the University of Illinois Open Source | |
5 // License. See LICENSE.TXT for details. | |
6 // | |
7 #ifndef D11_LLVMCEXT_H | |
8 #define D11_LLVMCEXT_H | |
9 | |
10 #include "llvm/Type.h" | |
11 #include "llvm/Constants.h" | |
12 #include "llvm/Support/CFG.h" | |
13 #include "llvm/Target/TargetData.h" | |
14 #include "llvm-c/Core.h" | |
15 | |
16 #include <sstream> | |
17 #include <cstring> | |
18 | |
19 using namespace llvm; | |
20 using namespace std; | |
21 | |
22 extern "C" | |
23 { | |
24 | |
25 // we need to be able to erase an instruction from its parent | |
26 void LLVMEraseFromParent(LLVMValueRef I) { | |
27 unwrap<Instruction>(I)->eraseFromParent(); | |
28 } | |
29 | |
30 // we need to be able to check if a basic block is terminated | |
31 int LLVMIsTerminated(LLVMBasicBlockRef BB) { | |
32 return (unwrap(BB)->getTerminator() != NULL); | |
33 } | |
34 | |
35 // we need to be able to check if a basic block has any predecessors | |
36 int LLVMHasPredecessors(LLVMBasicBlockRef BB) { | |
37 BasicBlock* B = unwrap(BB); | |
38 return (pred_begin(B) != pred_end(B)); | |
39 } | |
40 | |
41 // we need to be able to check if a basic block is empty | |
42 int LLVMIsBasicBlockEmpty(LLVMBasicBlockRef BB) { | |
43 return unwrap(BB)->empty(); | |
44 } | |
45 | |
46 // we need to be able to replace all uses of V with W | |
47 void LLVMReplaceAllUsesWith(LLVMValueRef V, LLVMValueRef W) { | |
48 unwrap<Value>(V)->replaceAllUsesWith(unwrap<Value>(W)); | |
49 } | |
50 | |
51 // sometimes it's nice to be able to dump a type, not only values... | |
52 void LLVMDumpType(LLVMTypeRef T) { | |
53 unwrap(T)->dump(); | |
54 } | |
55 | |
56 LLVMValueRef LLVMGetOrInsertFunction(LLVMModuleRef M, char* Name, LLVMTypeRef Type) { | |
57 return wrap(unwrap(M)->getOrInsertFunction(Name, unwrap<FunctionType>(Type))); | |
58 } | |
59 | |
60 // being able to determine the "kind" of a value is really useful | |
61 unsigned LLVMGetValueKind(LLVMValueRef Value) { | |
62 return unwrap(Value)->getValueID(); | |
63 } | |
64 | |
65 char* LLVMValueToString(LLVMValueRef v) { | |
66 stringstream ss; | |
67 unwrap(v)->print(ss); | |
68 return strdup(ss.str().c_str()); | |
69 } | |
70 | |
71 char* LLVMTypeToString(LLVMTypeRef ty) { | |
72 stringstream ss; | |
73 unwrap(ty)->print(ss); | |
74 return strdup(ss.str().c_str()); | |
75 } | |
76 | |
77 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, char* Name) { | |
78 return wrap(unwrap(M)->getTypeByName(Name)); | |
79 } | |
80 | |
81 int LLVMIsTypeAbstract(LLVMTypeRef T) { | |
82 return unwrap(T)->isAbstract(); | |
83 } | |
84 | |
85 } // extern "C" | |
86 | |
87 #endif |