summaryrefslogtreecommitdiff
path: root/examples/nq/gglue.ll
blob: 3aa71b6914e205acf6cab1a48d8d5355bfbddc28 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
target triple = "x86_64-unknown-linux-gnu"

declare fastcc i8* @gen(i8*, i8*)

declare fastcc i8* @length (i8*)

define fastcc i32 @"+"(i32, i32) {
  %res = add i32 %0, %1
  ret i32 %res
}

define fastcc i32 @-(i32, i32) {
  %res = sub i32 %0, %1
  ret i32 %res
}

define fastcc i32 @count_solns(i32) {
  %cast = inttoptr i32 %0 to i8*
  %solns = call fastcc i8* @gen(i8* %cast, i8* %cast)
  %n_solns = call fastcc i8* @length(i8* %solns)
  %res = ptrtoint i8* %n_solns to i32
  ret i32 %res
}

define fastcc i32 @_count_solns(i32) {
  %ext = zext i32 %0 to i128
  %alloc = alloca i128
  store i128 %ext, i128* %alloc
  %box = bitcast i128* %alloc to i8*
  %solns = call fastcc i8* @gen(i8* %box, i8* %box)
  %n_solns = call fastcc i8* @length(i8* %solns)
  %uncast = bitcast i8* %n_solns to i128*
  %unboxed = load i128, i128* %uncast
  %res = trunc i128 %unboxed to i32
  ret i32 %res
}