Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Aug 2014 14:00:36 GMT
From:      dpl@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r272288 - soc2014/dpl/llvm_examples
Message-ID:  <201408121400.s7CE0a57090605@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dpl
Date: Tue Aug 12 14:00:35 2014
New Revision: 272288
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272288

Log:
  Created a dir with llvm examples to be taken for compiling.

Added:
  soc2014/dpl/llvm_examples/
  soc2014/dpl/llvm_examples/general.c
  soc2014/dpl/llvm_examples/general.ll
  soc2014/dpl/llvm_examples/structs.c

Added: soc2014/dpl/llvm_examples/general.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2014/dpl/llvm_examples/general.c	Tue Aug 12 14:00:35 2014	(r272288)
@@ -0,0 +1,37 @@
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+addone(int n)
+{
+	return (n+1);
+}
+
+int
+main(int argc, char *argv[])
+{
+	int num;
+
+	if (argc != 2)
+		err(1, "Usage: %s number", argv[0]);
+	
+	if (addone(1) != 2)
+		printf("what!");
+
+	num = atoi(argv[1]);
+
+	switch (num) {
+	case 42:
+	case 1:
+		num = addone(num);
+		break;
+	case 10:
+		printf("Ten!\n");
+		break;
+	default:
+		printf("Waaaat\n");
+	}
+
+	return (num);
+}

Added: soc2014/dpl/llvm_examples/general.ll
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2014/dpl/llvm_examples/general.ll	Tue Aug 12 14:00:35 2014	(r272288)
@@ -0,0 +1,96 @@
+; ModuleID = 'test.c'
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-freebsd11.0"
+
+@.str = private unnamed_addr constant [17 x i8] c"Usage: %s number\00", align 1
+@.str1 = private unnamed_addr constant [6 x i8] c"what!\00", align 1
+@.str2 = private unnamed_addr constant [6 x i8] c"Ten!\0A\00", align 1
+@.str3 = private unnamed_addr constant [8 x i8] c"Waaaat\0A\00", align 1
+
+; Function Attrs: nounwind uwtable
+define i32 @addone(i32 %n) #0 {
+entry:
+  %n.addr = alloca i32, align 4
+  store i32 %n, i32* %n.addr, align 4
+  %0 = load i32* %n.addr, align 4
+  %add = add nsw i32 %0, 1
+  ret i32 %add
+}
+
+; Function Attrs: nounwind uwtable
+define i32 @main(i32 %argc, i8** %argv) #0 {
+entry:
+  %retval = alloca i32, align 4
+  %argc.addr = alloca i32, align 4
+  %argv.addr = alloca i8**, align 8
+  %num = alloca i32, align 4
+  store i32 0, i32* %retval
+  store i32 %argc, i32* %argc.addr, align 4
+  store i8** %argv, i8*** %argv.addr, align 8
+  %0 = load i32* %argc.addr, align 4
+  %cmp = icmp ne i32 %0, 2
+  br i1 %cmp, label %if.then, label %if.end
+
+if.then:                                          ; preds = %entry
+  %1 = load i8*** %argv.addr, align 8
+  %arrayidx = getelementptr inbounds i8** %1, i64 0
+  %2 = load i8** %arrayidx, align 8
+  call void (i32, i8*, ...)* @err(i32 1, i8* getelementptr inbounds ([17 x i8]* @.str, i32 0, i32 0), i8* %2) #3
+  unreachable
+
+if.end:                                           ; preds = %entry
+  %call = call i32 @addone(i32 1)
+  %cmp1 = icmp ne i32 %call, 2
+  br i1 %cmp1, label %if.then2, label %if.end4
+
+if.then2:                                         ; preds = %if.end
+  %call3 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str1, i32 0, i32 0))
+  br label %if.end4
+
+if.end4:                                          ; preds = %if.then2, %if.end
+  %3 = load i8*** %argv.addr, align 8
+  %arrayidx5 = getelementptr inbounds i8** %3, i64 1
+  %4 = load i8** %arrayidx5, align 8
+  %call6 = call i32 @atoi(i8* %4)
+  store i32 %call6, i32* %num, align 4
+  %5 = load i32* %num, align 4
+  switch i32 %5, label %sw.default [
+    i32 42, label %sw.bb
+    i32 1, label %sw.bb
+    i32 10, label %sw.bb8
+  ]
+
+sw.bb:                                            ; preds = %if.end4, %if.end4
+  %6 = load i32* %num, align 4
+  %call7 = call i32 @addone(i32 %6)
+  store i32 %call7, i32* %num, align 4
+  br label %sw.epilog
+
+sw.bb8:                                           ; preds = %if.end4
+  %call9 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str2, i32 0, i32 0))
+  br label %sw.epilog
+
+sw.default:                                       ; preds = %if.end4
+  %call10 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([8 x i8]* @.str3, i32 0, i32 0))
+  br label %sw.epilog
+
+sw.epilog:                                        ; preds = %sw.default, %sw.bb8, %sw.bb
+  %7 = load i32* %num, align 4
+  ret i32 %7
+}
+
+; Function Attrs: noreturn
+declare void @err(i32, i8*, ...) #1
+
+declare i32 @printf(i8*, ...) #2
+
+declare i32 @atoi(i8*) #2
+
+attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { noreturn "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #3 = { noreturn }
+
+!llvm.ident = !{!0}
+
+!0 = metadata !{metadata !"FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512"}

Added: soc2014/dpl/llvm_examples/structs.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2014/dpl/llvm_examples/structs.c	Tue Aug 12 14:00:35 2014	(r272288)
@@ -0,0 +1,21 @@
+#include <sys/socket.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+
+#include <stdio.h>
+
+struct mbuf gmbuf;
+
+int
+main()
+{
+	struct mbuf *m;
+	int pktlen;
+	struct ip *ip = mtod(m, struct ip *);
+
+	m = &gmbuf;
+	pktlen = m->pkthdr.len;
+	
+	return (0);
+}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408121400.s7CE0a57090605>