Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Aug 2014 23:03:11 GMT
From:      dpl@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r272310 - soc2014/dpl/llvm_examples
Message-ID:  <201408122303.s7CN3BRY073093@socsvn.freebsd.org>

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

Log:
  Added necessary boilerplate to get it working without includes.

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

Modified: soc2014/dpl/llvm_examples/structs.c
==============================================================================
--- soc2014/dpl/llvm_examples/structs.c	Tue Aug 12 22:38:52 2014	(r272309)
+++ soc2014/dpl/llvm_examples/structs.c	Tue Aug 12 23:03:11 2014	(r272310)
@@ -1,11 +1,34 @@
-#include <sys/socket.h>
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/mbuf.h>
+#include <sys/queue.h>
 
 #include <stdio.h>
 
+struct mbuf {
+	struct mbuf *m_next;
+	struct mbuf *m_nextpkt;
+	void *m_data;
+	int m_len;	/* length in this mbuf */
+	int m_flags;
+	struct {
+		struct ifnet *rcvif;
+		int len;	/* total packet len */
+		SLIST_HEAD (packet_tags, m_tag) tags;
+	} m_pkthdr;
+	struct skbuf *m_skb;
+
+	/*
+	 * in-stack mbuffers point to an external buffer,
+	 * the two variables below contain base and size,
+	 * and have M_STACK set in m_flags.
+	 * Buffers from the heap have __m_extbuf = (char *)m + MSIZE
+	 */
+	void *__m_extbuf;	/* external buffer base */
+	int  __m_extlen;	/* data in ext buffer */
+	void (*__m_callback)(struct mbuf *, int);
+	void *__m_peer;		/* argument attached to the mbuf */
+};
+
 struct mbuf gmbuf;
+#define	mtod(m, t)	((t)((m)->m_data))
 
 int
 main()
@@ -15,7 +38,7 @@
 	struct ip *ip = mtod(m, struct ip *);
 
 	m = &gmbuf;
-	pktlen = m->pkthdr.len;
+	pktlen = m->m_pkthdr.len;
 	
 	return (0);
 }

Added: soc2014/dpl/llvm_examples/structs.ll
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2014/dpl/llvm_examples/structs.ll	Tue Aug 12 23:03:11 2014	(r272310)
@@ -0,0 +1,41 @@
+; ModuleID = 'structs.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"
+
+%struct.mbuf = type { %struct.mbuf*, %struct.mbuf*, i8*, i32, i32, %struct.anon, %struct.skbuf*, i8*, i32, void (%struct.mbuf*, i32)*, i8* }
+%struct.anon = type { %struct.ifnet*, i32, %struct.packet_tags }
+%struct.ifnet = type opaque
+%struct.packet_tags = type { %struct.m_tag* }
+%struct.m_tag = type opaque
+%struct.skbuf = type opaque
+%struct.ip = type opaque
+
+@gmbuf = common global %struct.mbuf zeroinitializer, align 8
+
+; Function Attrs: nounwind uwtable
+define i32 @main() #0 {
+entry:
+  %retval = alloca i32, align 4
+  %m = alloca %struct.mbuf*, align 8
+  %pktlen = alloca i32, align 4
+  %ip = alloca %struct.ip*, align 8
+  store i32 0, i32* %retval
+  %0 = load %struct.mbuf** %m, align 8
+  %m_data = getelementptr inbounds %struct.mbuf* %0, i32 0, i32 2
+  %1 = load i8** %m_data, align 8
+  %2 = bitcast i8* %1 to %struct.ip*
+  store %struct.ip* %2, %struct.ip** %ip, align 8
+  store %struct.mbuf* @gmbuf, %struct.mbuf** %m, align 8
+  %3 = load %struct.mbuf** %m, align 8
+  %m_pkthdr = getelementptr inbounds %struct.mbuf* %3, i32 0, i32 5
+  %len = getelementptr inbounds %struct.anon* %m_pkthdr, i32 0, i32 1
+  %4 = load i32* %len, align 4
+  store i32 %4, i32* %pktlen, align 4
+  ret i32 0
+}
+
+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" }
+
+!llvm.ident = !{!0}
+
+!0 = metadata !{metadata !"FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512"}



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