summaryrefslogtreecommitdiff
path: root/examples/nq/gglue.ll
diff options
context:
space:
mode:
authorTom Harley2020-01-11 19:46:15 +0000
committerTom Harley2020-01-11 19:46:15 +0000
commit9e87372371794bc3e7d46698141966c00acaad0e (patch)
tree068da13d97cefed2e49ab06843e1dd9d97c32f6a /examples/nq/gglue.ll
parentAdded int width specifiers (diff)
downloadsinter-9e87372371794bc3e7d46698141966c00acaad0e.tar.gz
sinter-9e87372371794bc3e7d46698141966c00acaad0e.zip

Tidying up

  • Removed unused example files
  • Removed redundant common.c
  • Added extra files to make sure the current version compiles the nqueens solution correctly
  • Added extensionless files to .gitignore
  • Added a way to install sinter
Diffstat (limited to 'examples/nq/gglue.ll')
-rw-r--r--examples/nq/gglue.ll41
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/nq/gglue.ll b/examples/nq/gglue.ll
new file mode 100644
index 0000000..f78a603
--- /dev/null
+++ b/examples/nq/gglue.ll
@@ -0,0 +1,41 @@
+target triple = "x86_64-unknown-linux-gnu"
+
+declare fastcc i8* @gen(i8*, i8*)
+
+declare fastcc i8* @length (i8*)
+
+define fastcc i32 @inc(i32) {
+ %res = add i32 1, %0
+ ret i32 %res
+}
+
+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
+}