Mercurial > projects > ldc
comparison tools/binding/llvmsample3.d @ 1651:cb960b882ca3 default tip
bindings were moved to dsource.org/projects/bindings/
author | Moritz Warning <moritzwarning@web.de> |
---|---|
date | Thu, 20 May 2010 20:05:03 +0200 |
parents | 40bd4a0d4870 |
children |
comparison
equal
deleted
inserted
replaced
1650:40bd4a0d4870 | 1651:cb960b882ca3 |
---|---|
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 } |