commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r4863 - in gnuradio/branches/developers/eb/ibu: mblock


From: eb
Subject: [Commit-gnuradio] r4863 - in gnuradio/branches/developers/eb/ibu: mblock/src/lib mblock/src/scheme/gnuradio pmt/src/lib pmt/src/scheme/gnuradio
Date: Tue, 3 Apr 2007 16:39:02 -0600 (MDT)

Author: eb
Date: 2007-04-03 16:39:02 -0600 (Tue, 03 Apr 2007)
New Revision: 4863

Added:
   gnuradio/branches/developers/eb/ibu/pmt/src/scheme/gnuradio/macros-etc.scm
Modified:
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_protocol_class.cc
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_protocol_class.h
   
gnuradio/branches/developers/eb/ibu/mblock/src/scheme/gnuradio/compile-mbh.scm
   gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.cc
   gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.h
   gnuradio/branches/developers/eb/ibu/pmt/src/scheme/gnuradio/pmt-serialize.scm
Log:
work-in-progress

Modified: 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_protocol_class.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_protocol_class.cc     
2007-04-03 22:38:44 UTC (rev 4862)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_protocol_class.cc     
2007-04-03 22:39:02 UTC (rev 4863)
@@ -80,3 +80,21 @@
 
   return PMT_NIL;
 }
+
+mb_protocol_class_init::mb_protocol_class_init(const char *data, size_t len)
+{
+  std::stringbuf sb;
+  sb.str(std::string(data, len));
+
+  while (1){
+    pmt_t obj = pmt_deserialize(sb);
+
+    pmt_write(obj, std::cout);
+    std::cout << std::endl;
+
+    if (pmt_is_eof_object(obj))
+      return;
+
+    mb_make_protocol_class(pmt_car(obj), pmt_cadr(obj), pmt_caddr(obj));
+  }
+}

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_protocol_class.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_protocol_class.h      
2007-04-03 22:38:44 UTC (rev 4862)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_protocol_class.h      
2007-04-03 22:39:02 UTC (rev 4863)
@@ -39,4 +39,14 @@
 
 pmt_t mb_protocol_class_lookup(pmt_t name);    //< lookup an existing protocol 
class by name
 
+
+/*!
+ * \brief Initialize one or more protocol class from a serialized description.
+ * Used by machine generated code.
+ */
+class mb_protocol_class_init {
+public:
+  mb_protocol_class_init(const char *data, size_t len);
+};
+
 #endif /* INCLUDED_MB_PROTOCOL_CLASS_H */

Modified: 
gnuradio/branches/developers/eb/ibu/mblock/src/scheme/gnuradio/compile-mbh.scm
===================================================================
--- 
gnuradio/branches/developers/eb/ibu/mblock/src/scheme/gnuradio/compile-mbh.scm  
    2007-04-03 22:38:44 UTC (rev 4862)
+++ 
gnuradio/branches/developers/eb/ibu/mblock/src/scheme/gnuradio/compile-mbh.scm  
    2007-04-03 22:39:02 UTC (rev 4863)
@@ -28,18 +28,11 @@
 (use-modules (ice-9 format))
 (use-modules (ice-9 pretty-print))
 ;(use-modules (ice-9 slib))
+(use-modules (gnuradio pmt-serialize))
+(use-modules (gnuradio macros-etc))
 
 (debug-enable 'backtrace)
 
-(define (atom? obj)
-  (not (pair? obj)))
-
-(defmacro when (pred . body)
-  `(if ,pred (begin ,@body) #f))
-
-(defmacro unless (pred . body)
-  `(if (not ,pred) (begin ,@body) #f))
-
 ;; ----------------------------------------------------------------
 
 (define (main args)
@@ -176,25 +169,58 @@
       (for-each-in-file i-port parse-top-level-form)
 
       ;; generate the output here...
-        
-      (pretty-print (map cdr protocol-classes) o-port)
 
-      #t)))
+      (letrec ((classes (map cdr protocol-classes))
+              (so-stream (make-serial-output-stream))
+              (format-output-for-c++
+               (lambda (output)
+                 (format o-port "//~%")
+                 (format o-port "// Machine generated by compile-mbh from 
~a~%" input-filename)
+                 (format o-port "//~%")
+                 (format o-port "// protocol-classes: ~{~a ~}~%" (map car 
protocol-classes))
+                 (format o-port "//~%")
 
+                 (format o-port "#include <mb_protocol_class.h>~%")
+                 (format o-port "#include <unistd.h>~%")
+                 (format o-port
+                         "static const char~%protocol_class_init_data[~d] = 
{~%  "
+                         (length output))
 
-(define (for-each-in-file file f)
-  (let ((port (if (port? file)
-                 file
-                 (open-input-file file))))
-    (letrec
-     ((loop
-       (lambda (port form)
-        (cond ((eof-object? form)
-               (when (not (eq? port file))
-                     (close-input-port port))
-               #t)
-              (else
-               (f form)
-               (set! form #f)          ; for GC
-               (loop port (read port)))))))
-     (loop port (read port)))))
+                 (do ((lst output (cdr lst))
+                      (i 0 (+ i 1)))
+                     ((null? lst) #t)
+                   (format o-port "~a, " (car lst))
+                   (when (= 15 (modulo i 16))
+                         (format o-port "~%  ")))
+
+                 (format o-port "~&};~%")
+                 (format o-port "static mb_protocol_class_init 
_init_(protocol_class_init_data, sizeof(protocol_class_init_data));~%")
+                 )))
+                 
+                 
+       (map (lambda (pc)
+              (let ((obj-to-dump (list (protocol-class-name pc)
+                                       (protocol-class-incoming pc)
+                                       (protocol-class-outgoing pc))))
+                (pmt-serialize obj-to-dump (so-stream 'put-byte))))
+            classes)
+
+       (format-output-for-c++ ((so-stream 'get-output)))
+
+       #t))))
+
+
+(define (make-serial-output-stream)
+  (letrec ((output '())
+          (put-byte
+           (lambda (byte)
+             (set! output (cons byte output))))
+          (get-output
+           (lambda ()
+             (reverse output))))
+    (lambda (key)
+      (case key
+       ((put-byte) put-byte)
+       ((get-output) get-output)
+       (else (error "Unknown key" key))))))
+

Modified: gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.cc      2007-04-03 
22:38:44 UTC (rev 4862)
+++ gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.cc      2007-04-03 
22:39:02 UTC (rev 4863)
@@ -869,3 +869,45 @@
 {
   return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, pmt_cons(x4, PMT_NIL))));
 }
+
+pmt_t
+pmt_caar(pmt_t pair)
+{
+  return (pmt_car(pmt_car(pair)));
+}
+
+pmt_t
+pmt_cadr(pmt_t pair)
+{
+  return pmt_car(pmt_cdr(pair));
+}
+
+pmt_t
+pmt_cdar(pmt_t pair)
+{
+  return pmt_cdr(pmt_car(pair));
+}
+
+pmt_t
+pmt_cddr(pmt_t pair)
+{
+  return pmt_cdr(pmt_cdr(pair));
+}
+
+pmt_t
+pmt_caddr(pmt_t pair)
+{
+  return pmt_car(pmt_cdr(pmt_cdr(pair)));
+}
+
+pmt_t
+pmt_cadddr(pmt_t pair)
+{
+  return pmt_car(pmt_cdr(pmt_cdr(pmt_cdr(pair))));
+}
+  
+bool
+pmt_is_eof_object(pmt_t obj)
+{
+  return pmt_eq(obj, PMT_EOF);
+}

Modified: gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.h       2007-04-03 
22:38:44 UTC (rev 4862)
+++ gnuradio/branches/developers/eb/ibu/pmt/src/lib/pmt.h       2007-04-03 
22:39:02 UTC (rev 4863)
@@ -225,6 +225,13 @@
 //! Stores \p value in the cdr field of \p pair.
 void pmt_set_cdr(pmt_t pair, pmt_t value);
 
+pmt_t pmt_caar(pmt_t pair);
+pmt_t pmt_cadr(pmt_t pair);
+pmt_t pmt_cdar(pmt_t pair);
+pmt_t pmt_cddr(pmt_t pair);
+pmt_t pmt_caddr(pmt_t pair);
+pmt_t pmt_cadddr(pmt_t pair);
+
 /*
  * ------------------------------------------------------------------------
  *                            Vectors

Added: 
gnuradio/branches/developers/eb/ibu/pmt/src/scheme/gnuradio/macros-etc.scm
===================================================================
--- gnuradio/branches/developers/eb/ibu/pmt/src/scheme/gnuradio/macros-etc.scm  
                        (rev 0)
+++ gnuradio/branches/developers/eb/ibu/pmt/src/scheme/gnuradio/macros-etc.scm  
2007-04-03 22:39:02 UTC (rev 4863)
@@ -0,0 +1,50 @@
+;;; -*- scheme -*-
+;;;
+;;; Copyright 2007 Free Software Foundation, Inc.
+;;; 
+;;; This file is part of GNU Radio
+;;; 
+;;; GNU Radio is free software; you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 2, or (at your option)
+;;; any later version.
+;;; 
+;;; GNU Radio is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;; 
+;;; You should have received a copy of the GNU General Public License along
+;;; with this program; if not, write to the Free Software Foundation, Inc.,
+;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+;;;
+
+(define-module (gnuradio macros-etc)
+  :export (atom? when unless for-each-in-file))
+
+(define (atom? obj)
+  (not (pair? obj)))
+
+(defmacro when (pred . body)
+  `(if ,pred (begin ,@body) #f))
+
+(defmacro unless (pred . body)
+  `(if (not ,pred) (begin ,@body) #f))
+
+
+(define (for-each-in-file file f)
+  (let ((port (if (port? file)
+                 file
+                 (open-input-file file))))
+    (letrec
+     ((loop
+       (lambda (port form)
+        (cond ((eof-object? form)
+               (when (not (eq? port file))
+                     (close-input-port port))
+               #t)
+              (else
+               (f form)
+               (set! form #f)          ; for GC
+               (loop port (read port)))))))
+     (loop port (read port)))))

Modified: 
gnuradio/branches/developers/eb/ibu/pmt/src/scheme/gnuradio/pmt-serialize.scm
===================================================================
--- 
gnuradio/branches/developers/eb/ibu/pmt/src/scheme/gnuradio/pmt-serialize.scm   
    2007-04-03 22:38:44 UTC (rev 4862)
+++ 
gnuradio/branches/developers/eb/ibu/pmt/src/scheme/gnuradio/pmt-serialize.scm   
    2007-04-03 22:39:02 UTC (rev 4863)
@@ -21,8 +21,11 @@
 ;;; An implementation of pmt_serialize in scheme.
 ;;; Currently handles only symbols and pairs.  They're all we need for now.
 
-(load "pmt-serial-tags.scm")
+(define-module (gnuradio pmt-serialize)
+  :export (pmt-serialize))
 
+(load-from-path "gnuradio/pmt-serial-tags")
+
 (define (pmt-serialize obj put-byte)
   (define (put-u16 x)
     (put-byte (logand (ash x -8) #xff))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]