comparison tools/binding/llvmsample3.d @ 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 // 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 }