|
Revision 340, 0.9 kB
(checked in by mwarning, 2 years ago)
|
move llvm 2.7 bindings and added llvm 2.6 bindings from ldc project repo
|
| Line | |
|---|
| 1 |
// simple example that shows off getting D wrappers from C values. |
|---|
| 2 |
module llvmsample3; |
|---|
| 3 |
|
|---|
| 4 |
import llvm.c.Core; |
|---|
| 5 |
import llvm.llvm; |
|---|
| 6 |
|
|---|
| 7 |
void main() |
|---|
| 8 |
{ |
|---|
| 9 |
auto m = new Module("sample3"); |
|---|
| 10 |
|
|---|
| 11 |
// global int32 |
|---|
| 12 |
auto gi = m.addGlobal(Type.Int32, "myint"); |
|---|
| 13 |
gi.initializer = ConstantInt.GetU(Type.Int32, 42); |
|---|
| 14 |
|
|---|
| 15 |
// this is not a cached value, it's recreated dynamically |
|---|
| 16 |
auto _i = gi.initializer; |
|---|
| 17 |
auto ci = cast(ConstantInt)_i; |
|---|
| 18 |
assert(ci !is null); |
|---|
| 19 |
ci.dump; |
|---|
| 20 |
|
|---|
| 21 |
// global struct |
|---|
| 22 |
auto st = StructType.Get([Type.Double,Type.Double,Type.Double]); |
|---|
| 23 |
auto gs = m.addGlobal(st, "mystruct"); |
|---|
| 24 |
auto elems = new Constant[3]; |
|---|
| 25 |
foreach(i,ref e; elems) |
|---|
| 26 |
e = ConstantReal.Get(Type.Double, i+1); |
|---|
| 27 |
gs.initializer = ConstantStruct.Get(elems); |
|---|
| 28 |
|
|---|
| 29 |
// again this is not a cached value. |
|---|
| 30 |
auto s = gs.initializer; |
|---|
| 31 |
auto cs = cast(ConstantStruct)s; |
|---|
| 32 |
assert(cs !is null); |
|---|
| 33 |
|
|---|
| 34 |
cs.dump; |
|---|
| 35 |
} |
|---|