genevent 0.3
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Sat, 17 Dec 2005 06:31:26 +0000 (06:31 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Sat, 17 Dec 2005 06:31:26 +0000 (06:31 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@1422 04897980-b3bd-0310-b5e0-8ef037075253

genevent-0.3/Makefile [new file with mode: 0644]
genevent-0.3/README [new file with mode: 0644]
genevent-0.3/crc32.tab [new file with mode: 0644]
genevent-0.3/genevent.c [new file with mode: 0644]
genevent-0.3/genevent.h [new file with mode: 0644]
genevent-0.3/gentest.c [new file with mode: 0644]
genevent-0.3/ltt-facility-test-template.h [new file with mode: 0644]
genevent-0.3/parser.c [new file with mode: 0644]
genevent-0.3/parser.h [new file with mode: 0644]
genevent-0.3/test.xml [new file with mode: 0644]

diff --git a/genevent-0.3/Makefile b/genevent-0.3/Makefile
new file mode 100644 (file)
index 0000000..5947dc2
--- /dev/null
@@ -0,0 +1,27 @@
+SHELL = /bin/sh
+
+CC = gcc
+
+#CFLAGS = -std=c99 -Wall -g -DDEBUG
+CFLAGS = -std=c99 -Wall -g
+
+all: genevent
+
+install: genevent
+       cp -f genevent /usr/local/bin
+
+genevent: genevent.o parser.o 
+       $(CC) $(CFLAGS) -o $@ $^
+
+genevent.o: genevent.c genevent.h parser.h
+       $(CC) $(CFLAGS) -c -o $@ $<
+
+parser.o: parser.c parser.h
+       $(CC) $(CFLAGS) -c -o $@ $<
+
+.PHONY: clean
+
+clean:
+       rm -rf *.o *~ *# genevent
+
+
diff --git a/genevent-0.3/README b/genevent-0.3/README
new file mode 100644 (file)
index 0000000..7b16fcd
--- /dev/null
@@ -0,0 +1,95 @@
+
+Mathieu Desnoyers -- November 2005
+
+This is a complete rework of genevent.
+
+The 'genevent' program parses event descriptions and generates 
+the inline functions to record events in the kernel.
+
+There are several files in the directory:
+ genevent.c, genevent.h, crc32.tab, parser.c and parser.h
+
+In fact, crc32.tab, parser.c and parser.h are the same files as  
+those in LTT library.
+
+Note about strings :
+There are three methods to write strings in genevent, each suitable and
+efficient for a particular case. They are explained here from the fastest
+to the slowest.
+1 - The C code presents a fixed size string.
+       For example, you find :
+               char mystring[10];
+       as string definition.
+
+       you must then define it as an array of char :
+       <array size=10/><char></array>
+
+       Note, however, that you might not want to declare a fixed size for trace size
+       and unnecessary copy matters.
+       
+       For instance, on a 32 bits architecture, copying a n bytes array takes
+       approximately* n/4 memory read and write, for n/2 memory operations.
+       
+       Using the       slower method described in (3), with a strlen and memcpy, where
+       "u" is the number of used caracters, takes u+1 reads for the strlen, and
+       approximately* (u+1)/4 read and write for the memcpy, for a total of :
+       (3/2)*(u+1) memory access.
+
+       So, if (n/2) > (3/2)*(u+1), or : n > 3*u+3
+               where n is the size of the array
+                                       u is the average number of used caracters (excluding the \0)
+                               it becomes faster to use the method number 3 with strlen.
+
+2 - The C code presents a variable size string together with its
+               size.
+
+       A typical use for this case is filenames in the Linux kernel. The
+       dentry strucure has a d_name member, which is a struct qstr containing
+       a unsigned int len and const unsigned char *name.
+
+       you must use a sequence to declare this efficiently :
+       <sequence><uint><char></sequence>
+               
+3 - The C code presents a \0 terminated string.
+       
+       This is the slowest, but most convenient way to declare a string. You are
+       discouraged to use it when options 1 or 2 are available. It will dynamically
+       calculate the string length (byte by byte read) and only afterward do a
+       memcpy.
+
+       Note that, as explained in 1, if n > 3*u+3, it becomes faster to use this
+       method instead of copying the whole fixed size array.
+
+       Declare like this :
+       <string>
+
+Here is a brief description of how to use genevent.
+
+make
+make install
+
+
+* Add new events to the kernel with genevent
+
+su -
+cd /usr/local/share/LinuxTraceToolkitViewer/facilities
+cp process.xml yourfacility.xml
+  * edit yourfacility.xml to fit your needs.
+cd /tmp
+/usr/local/bin/genevent /usr/local/share/LinuxTraceToolkitViewer/yourfacility.xml
+cp ltt-facility-yourfacility.h ltt-facility-id-yourfacility.h \
+         /usr/src/linux-2.6.12-rc4-mm2-lttng-0.2/include/linux/ltt
+cp ltt-facility-loader-yourfacility.c ltt-facility-loader-yourfacility.h \
+         /usr/src/linux-2.6.12-rc4-mm2-lttng-0.2/ltt
+  * edit the kernel file you want to instrument
+    - Add #include <linux/ltt/ltt-facility-yourfacility.h> at the beginning
+      of the file.
+    - Add a call to the tracing functions. See their names and parameters in
+      /usr/src/linux-2.6.12-rc4-mm2-lttng-0.2/include/linux/ltt/ltt-facility-yourfacility.h
+
+
+
+* The approximation comes from the fact that copies of number of caracters non
+  multiple of the architecture size takes more operations (maximum of :
+       (architecture size (in bytes) - 1) operations).
+
diff --git a/genevent-0.3/crc32.tab b/genevent-0.3/crc32.tab
new file mode 100644 (file)
index 0000000..d0174ad
--- /dev/null
@@ -0,0 +1,52 @@
+  0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U,
+  0x706af48fU, 0xe963a535U, 0x9e6495a3U, 0x0edb8832U, 0x79dcb8a4U,
+  0xe0d5e91eU, 0x97d2d988U, 0x09b64c2bU, 0x7eb17cbdU, 0xe7b82d07U,
+  0x90bf1d91U, 0x1db71064U, 0x6ab020f2U, 0xf3b97148U, 0x84be41deU,
+  0x1adad47dU, 0x6ddde4ebU, 0xf4d4b551U, 0x83d385c7U, 0x136c9856U,
+  0x646ba8c0U, 0xfd62f97aU, 0x8a65c9ecU, 0x14015c4fU, 0x63066cd9U,
+  0xfa0f3d63U, 0x8d080df5U, 0x3b6e20c8U, 0x4c69105eU, 0xd56041e4U,
+  0xa2677172U, 0x3c03e4d1U, 0x4b04d447U, 0xd20d85fdU, 0xa50ab56bU,
+  0x35b5a8faU, 0x42b2986cU, 0xdbbbc9d6U, 0xacbcf940U, 0x32d86ce3U,
+  0x45df5c75U, 0xdcd60dcfU, 0xabd13d59U, 0x26d930acU, 0x51de003aU,
+  0xc8d75180U, 0xbfd06116U, 0x21b4f4b5U, 0x56b3c423U, 0xcfba9599U,
+  0xb8bda50fU, 0x2802b89eU, 0x5f058808U, 0xc60cd9b2U, 0xb10be924U,
+  0x2f6f7c87U, 0x58684c11U, 0xc1611dabU, 0xb6662d3dU, 0x76dc4190U,
+  0x01db7106U, 0x98d220bcU, 0xefd5102aU, 0x71b18589U, 0x06b6b51fU,
+  0x9fbfe4a5U, 0xe8b8d433U, 0x7807c9a2U, 0x0f00f934U, 0x9609a88eU,
+  0xe10e9818U, 0x7f6a0dbbU, 0x086d3d2dU, 0x91646c97U, 0xe6635c01U,
+  0x6b6b51f4U, 0x1c6c6162U, 0x856530d8U, 0xf262004eU, 0x6c0695edU,
+  0x1b01a57bU, 0x8208f4c1U, 0xf50fc457U, 0x65b0d9c6U, 0x12b7e950U,
+  0x8bbeb8eaU, 0xfcb9887cU, 0x62dd1ddfU, 0x15da2d49U, 0x8cd37cf3U,
+  0xfbd44c65U, 0x4db26158U, 0x3ab551ceU, 0xa3bc0074U, 0xd4bb30e2U,
+  0x4adfa541U, 0x3dd895d7U, 0xa4d1c46dU, 0xd3d6f4fbU, 0x4369e96aU,
+  0x346ed9fcU, 0xad678846U, 0xda60b8d0U, 0x44042d73U, 0x33031de5U,
+  0xaa0a4c5fU, 0xdd0d7cc9U, 0x5005713cU, 0x270241aaU, 0xbe0b1010U,
+  0xc90c2086U, 0x5768b525U, 0x206f85b3U, 0xb966d409U, 0xce61e49fU,
+  0x5edef90eU, 0x29d9c998U, 0xb0d09822U, 0xc7d7a8b4U, 0x59b33d17U,
+  0x2eb40d81U, 0xb7bd5c3bU, 0xc0ba6cadU, 0xedb88320U, 0x9abfb3b6U,
+  0x03b6e20cU, 0x74b1d29aU, 0xead54739U, 0x9dd277afU, 0x04db2615U,
+  0x73dc1683U, 0xe3630b12U, 0x94643b84U, 0x0d6d6a3eU, 0x7a6a5aa8U,
+  0xe40ecf0bU, 0x9309ff9dU, 0x0a00ae27U, 0x7d079eb1U, 0xf00f9344U,
+  0x8708a3d2U, 0x1e01f268U, 0x6906c2feU, 0xf762575dU, 0x806567cbU,
+  0x196c3671U, 0x6e6b06e7U, 0xfed41b76U, 0x89d32be0U, 0x10da7a5aU,
+  0x67dd4accU, 0xf9b9df6fU, 0x8ebeeff9U, 0x17b7be43U, 0x60b08ed5U,
+  0xd6d6a3e8U, 0xa1d1937eU, 0x38d8c2c4U, 0x4fdff252U, 0xd1bb67f1U,
+  0xa6bc5767U, 0x3fb506ddU, 0x48b2364bU, 0xd80d2bdaU, 0xaf0a1b4cU,
+  0x36034af6U, 0x41047a60U, 0xdf60efc3U, 0xa867df55U, 0x316e8eefU,
+  0x4669be79U, 0xcb61b38cU, 0xbc66831aU, 0x256fd2a0U, 0x5268e236U,
+  0xcc0c7795U, 0xbb0b4703U, 0x220216b9U, 0x5505262fU, 0xc5ba3bbeU,
+  0xb2bd0b28U, 0x2bb45a92U, 0x5cb36a04U, 0xc2d7ffa7U, 0xb5d0cf31U,
+  0x2cd99e8bU, 0x5bdeae1dU, 0x9b64c2b0U, 0xec63f226U, 0x756aa39cU,
+  0x026d930aU, 0x9c0906a9U, 0xeb0e363fU, 0x72076785U, 0x05005713U,
+  0x95bf4a82U, 0xe2b87a14U, 0x7bb12baeU, 0x0cb61b38U, 0x92d28e9bU,
+  0xe5d5be0dU, 0x7cdcefb7U, 0x0bdbdf21U, 0x86d3d2d4U, 0xf1d4e242U,
+  0x68ddb3f8U, 0x1fda836eU, 0x81be16cdU, 0xf6b9265bU, 0x6fb077e1U,
+  0x18b74777U, 0x88085ae6U, 0xff0f6a70U, 0x66063bcaU, 0x11010b5cU,
+  0x8f659effU, 0xf862ae69U, 0x616bffd3U, 0x166ccf45U, 0xa00ae278U,
+  0xd70dd2eeU, 0x4e048354U, 0x3903b3c2U, 0xa7672661U, 0xd06016f7U,
+  0x4969474dU, 0x3e6e77dbU, 0xaed16a4aU, 0xd9d65adcU, 0x40df0b66U,
+  0x37d83bf0U, 0xa9bcae53U, 0xdebb9ec5U, 0x47b2cf7fU, 0x30b5ffe9U,
+  0xbdbdf21cU, 0xcabac28aU, 0x53b39330U, 0x24b4a3a6U, 0xbad03605U,
+  0xcdd70693U, 0x54de5729U, 0x23d967bfU, 0xb3667a2eU, 0xc4614ab8U,
+  0x5d681b02U, 0x2a6f2b94U, 0xb40bbe37U, 0xc30c8ea1U, 0x5a05df1bU,
+  0x2d02ef8dU
diff --git a/genevent-0.3/genevent.c b/genevent-0.3/genevent.c
new file mode 100644 (file)
index 0000000..9113a11
--- /dev/null
@@ -0,0 +1,2121 @@
+/******************************************************************************
+ * Genevent
+ *
+ * Event generator. XML to logging C code converter.
+ *
+ * Program parameters :
+ * ./genevent name.xml
+ *
+ * Will generate ltt-facility-name.h, ltt-facility-id-name.h
+ * ltt-facility-loader-name.c, ltt-facility-loader-name.h
+ * in the current directory.
+ * 
+ * Supports : 
+ *     - C Alignment
+ *     - C types : struct, union, enum, basic types.
+ *     - Architectures : LP32, ILP32, ILP64, LLP64, LP64.
+ *
+ * Additionnal structures supported :
+ *     - embedded variable size strings
+ *     - embedded variable size arrays
+ *     - embedded variable size sequences
+ * 
+ * Notes :
+ * (1)
+ * enums are limited to integer type, as this is what is used in C. Note,
+ * however, that ISO/IEC 9899:TC2 specify that the type of enum can be char,
+ * unsigned int or int. This is implementation defined (compiler). That's why we
+ * add a check for sizeof enum.
+ *
+ * (2)
+ * Because of archtecture defined type sizes, we need to ask for ltt_align
+ * (which gives the alignment) by passing basic types, not their actual sizes.
+ * It's up to ltt_align to determine sizes of types.
+ *
+ * Note that, from
+ * http://www.usenix.org/publications/login/standards/10.data.html
+ * (Andrew Josey <a.josey@opengroup.org>) :
+ *
+ *     Data Type       LP32    ILP32   ILP64   LLP64   LP64
+ *     char    8       8       8       8       8
+ *     short   16      16      16      16      16
+ *     int32                   32
+ *     int     16      32      64      32      32
+ *     long    32      32      64      32      64
+ *     long long (int64)                                       64
+ *     pointer 32      32      64      64      64
+ *
+ * With these constraints :
+ * sizeof(char) <= sizeof(short) <= sizeof(int)
+ *                                     <= sizeof(long) = sizeof(size_t)
+ * 
+ * and therefore sizeof(long) <= sizeof(pointer) <= sizeof(size_t)
+ *
+ * Which means we only have to remember which is the biggest type in a structure
+ * to know the structure's alignment.
+ */
+
+#define _GNU_SOURCE
+#include <limits.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <assert.h>
+
+#include "genevent.h"
+#include "parser.h"
+
+
+#define TRUE 1
+#define FALSE (!TRUE)
+
+/* Debugging printf */
+#ifdef DEBUG
+#define dprintf(...) \
+       do {\
+               printf(__FILE__ ",%u,%s: ",\
+                               __LINE__, __func__);\
+               printf(__VA_ARGS__);\
+       } while(0)
+#else
+#define dprintf(...)
+#endif
+
+/* Code printing */
+
+void print_tabs(unsigned int tabs, FILE *fd)
+{
+       for(unsigned int i = 0; i<tabs;i++)
+               fprintf(fd, "\t");
+}
+
+/* print type.
+ *
+ * Copied from construct_types_and_fields in LTTV facility.c */
+
+int print_type(type_descriptor_t * td, FILE *fd, unsigned int tabs,
+               char *nest_name, char *field_name)
+{
+       char basename[PATH_MAX];
+       unsigned int basename_len = 0;
+
+       strcpy(basename, nest_name);
+       basename_len = strlen(basename);
+       
+       /* For a named type, we use the type_name directly */
+       if(td->type_name != NULL) {
+               strncpy(basename, td->type_name, PATH_MAX);
+               basename_len = strlen(basename);
+       } else {
+               /* For a unnamed type, there must be a field name */
+               if((basename_len != 0)
+                               && (basename[basename_len-1] != '_')
+                               && (field_name[0] != '\0')) {
+                       strncat(basename, "_", PATH_MAX - basename_len);
+                       basename_len = strlen(basename);
+               }
+               strncat(basename, field_name, PATH_MAX - basename_len);
+       }
+
+       switch(td->type) {
+               case INT_FIXED:
+                       fprintf(fd, "%s", intOutputTypes[getSizeindex(td->size)]);
+                       break;
+               case UINT_FIXED:
+                       fprintf(fd, "%s", uintOutputTypes[getSizeindex(td->size)]);
+                       break;
+               case CHAR:
+                       fprintf(fd, "signed char");
+                       break;
+               case UCHAR:
+                       fprintf(fd, "unsigned char");
+                       break;
+               case SHORT:
+                       fprintf(fd, "short");
+                       break;
+               case USHORT:
+                       fprintf(fd, "unsigned short");
+                       break;
+               case INT:
+                       fprintf(fd, "int");
+                       break;
+               case UINT:
+                       fprintf(fd, "unsigned int");
+                       break;
+               case FLOAT:
+                       fprintf(fd, "%s", floatOutputTypes[getSizeindex(td->size)]);
+                       break;
+               case POINTER:
+                       fprintf(fd, "const void *");
+                       break;
+               case LONG:
+                       fprintf(fd, "long");
+                       break;
+               case ULONG:
+                       fprintf(fd, "unsigned long");
+                       break;
+               case SIZE_T:
+                       fprintf(fd, "size_t");
+                       break;
+               case SSIZE_T:
+                       fprintf(fd, "ssize_t");
+                       break;
+               case OFF_T:
+                       fprintf(fd, "off_t");
+                       break;
+               case STRING:
+                       fprintf(fd, "const char *");
+                       break;
+               case ENUM:
+                       fprintf(fd, "enum lttng_%s", basename);
+                       break;
+               case ARRAY:
+                       fprintf(fd, "lttng_array_%s", basename);
+                       break;
+               case SEQUENCE:
+                       fprintf(fd, "lttng_sequence_%s", basename);
+                       break;
+       case STRUCT:
+                       fprintf(fd, "struct lttng_%s", basename);
+                       break;
+       case UNION:
+                       fprintf(fd, "union lttng_%s", basename);
+                       break;
+       default:
+                       printf("print_type : unknown type\n");
+                       return 1;
+       }
+
+       return 0;
+}
+
+/* Print logging function argument */
+int print_arg(type_descriptor_t * td, FILE *fd, unsigned int tabs,
+               char *nest_name, char *field_name)
+{
+       char basename[PATH_MAX];
+       unsigned int basename_len = 0;
+
+       strcpy(basename, nest_name);
+       basename_len = strlen(basename);
+       
+       /* For a named type, we use the type_name directly */
+       if(td->type_name != NULL) {
+               strncpy(basename, td->type_name, PATH_MAX);
+               basename_len = strlen(basename);
+       } else {
+               /* For a unnamed type, there must be a field name */
+               if((basename_len != 0)
+                               && (basename[basename_len-1] != '_')
+                               && (field_name[0] != '\0')) {
+                       strncat(basename, "_", PATH_MAX - basename_len);
+                       basename_len = strlen(basename);
+               }
+               strncat(basename, field_name, PATH_MAX - basename_len);
+       }
+
+       print_tabs(tabs, fd);
+
+       switch(td->type) {
+               case INT_FIXED:
+                       fprintf(fd, "%s", intOutputTypes[getSizeindex(td->size)]);
+                       fprintf(fd, "lttng_param_%s", field_name);
+                       break;
+               case UINT_FIXED:
+                       fprintf(fd, "%s", uintOutputTypes[getSizeindex(td->size)]);
+                       fprintf(fd, "lttng_param_%s", field_name);
+                       break;
+               case CHAR:
+                       fprintf(fd, "signed char");
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case UCHAR:
+                       fprintf(fd, "unsigned char");
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case SHORT:
+                       fprintf(fd, "short");
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case USHORT:
+                       fprintf(fd, "unsigned short");
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case INT:
+                       fprintf(fd, "int");
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case UINT:
+                       fprintf(fd, "unsigned int");
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case FLOAT:
+                       fprintf(fd, "%s", floatOutputTypes[getSizeindex(td->size)]);
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case POINTER:
+                       fprintf(fd, "const void *");
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case LONG:
+                       fprintf(fd, "long");
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case ULONG:
+                       fprintf(fd, "unsigned long");
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case SIZE_T:
+                       fprintf(fd, "size_t");
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case SSIZE_T:
+                       fprintf(fd, "ssize_t");
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case OFF_T:
+                       fprintf(fd, "off_t");
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case STRING:
+                       fprintf(fd, "const char *");
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case ENUM:
+                       fprintf(fd, "enum lttng_%s", basename);
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case ARRAY:
+                       fprintf(fd, "lttng_array_%s", basename);
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+               case SEQUENCE:
+                       fprintf(fd, "lttng_sequence_%s *", basename);
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+       case STRUCT:
+                       fprintf(fd, "struct lttng_%s *", basename);
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+       case UNION:
+                       fprintf(fd, "union lttng_%s *", basename);
+                       fprintf(fd, " lttng_param_%s", field_name);
+                       break;
+       default:
+                       printf("print_type : unknown type\n");
+                       return 1;
+       }
+
+       return 0;
+}
+
+
+/* Does the type has a fixed size ? (as know from the compiler)
+ *
+ * 1 : fixed size
+ * 0 : variable length
+ */
+int has_type_fixed_size(type_descriptor_t *td)
+{
+       switch(td->type) {
+               case INT_FIXED:
+               case UINT_FIXED:
+               case CHAR:
+               case UCHAR:
+               case SHORT:
+               case USHORT:
+               case INT:
+               case UINT:
+               case FLOAT:
+               case POINTER:
+               case LONG:
+               case ULONG:
+               case SIZE_T:
+               case SSIZE_T:
+               case OFF_T:
+               case ENUM:
+               case UNION: /* The union must have fixed size children. Must be checked by
+                                                                        the parser */
+                       return 1;
+                       break;
+               case STRING:
+               case SEQUENCE:
+                       return 0;
+                       break;
+               case STRUCT:
+                       {
+                               int has_type_fixed = 0;
+                               for(unsigned int i=0;i<td->fields.position;i++){
+                                       field_t *field = (field_t*)(td->fields.array[i]);
+                                       type_descriptor_t *type = field->type;
+                                       
+                                       has_type_fixed = has_type_fixed_size(type);
+                                       if(!has_type_fixed) return 0;
+                               }
+                               return 1;
+                       }
+                       break;
+               case ARRAY:
+                       assert(td->size >= 0);
+                       return has_type_fixed_size(((field_t*)td->fields.array[0])->type);
+                       break;
+               case NONE:
+                       printf("There is a type defined to NONE : bad.\n");
+                       assert(0);
+                       break;
+       }
+       return 0; //make gcc happy.
+}
+
+
+
+
+
+/* print type declaration.
+ *
+ * Copied from construct_types_and_fields in LTTV facility.c */
+
+int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs,
+               char *nest_name, char *field_name)
+{
+       char basename[PATH_MAX];
+       unsigned int basename_len = 0;
+       
+       strncpy(basename, nest_name, PATH_MAX);
+       basename_len = strlen(basename);
+       
+       /* For a named type, we use the type_name directly */
+       if(td->type_name != NULL) {
+               strncpy(basename, td->type_name, PATH_MAX);
+               basename_len = strlen(basename);
+       } else {
+               /* For a unnamed type, there must be a field name, except for
+                * the array. */
+               if((basename_len != 0)
+                               && (basename[basename_len-1] != '_'
+                               && (field_name[0] != '\0'))) {
+                       strncat(basename, "_", PATH_MAX - basename_len);
+                       basename_len = strlen(basename);
+               }
+               strncat(basename, field_name, PATH_MAX - basename_len);
+       }
+
+       switch(td->type) {
+               case ENUM:
+                       fprintf(fd, "enum lttng_%s", basename);
+                       fprintf(fd, " {\n");
+                       for(unsigned int i=0;i<td->labels.position;i++){
+                               print_tabs(1, fd);
+                               fprintf(fd, "LTTNG_%s = %d", ((char*)td->labels.array[i]),
+            (*(int*)td->labels_values.array[i]));
+                               fprintf(fd, ",\n");
+                       }
+                       fprintf(fd, "};\n");
+                       fprintf(fd, "\n");
+                       break;
+
+               case ARRAY:
+                       dprintf("%s\n", basename);
+                       assert(td->size >= 0);
+                       if(((field_t*)td->fields.array[0])->type->type_name == NULL) {
+                               /* Not a named nested type : we must print its declaration first */
+                               if(print_type_declaration(((field_t*)td->fields.array[0])->type,
+                                                                                                                                       fd,     0, basename, "")) return 1;
+                       }
+                       fprintf(fd, "#define LTTNG_ARRAY_SIZE_%s %zu\n", basename,
+                                       td->size);
+                       fprintf(fd, "typedef ");
+                       if(print_type(((field_t*)td->fields.array[0])->type,
+                                               fd, tabs, basename, "")) return 1;
+                       fprintf(fd, " lttng_array_%s[LTTNG_ARRAY_SIZE_%s];\n", basename,
+                                       basename);
+                       fprintf(fd, "\n");
+                       break;
+               case SEQUENCE:
+                       /* We assume that the sequence length type does not need to be declared.
+                        */
+                       if(((field_t*)td->fields.array[1])->type->type_name == NULL) {
+                               /* Not a named nested type : we must print its declaration first */
+                               if(print_type_declaration(((field_t*)td->fields.array[1])->type,
+                                                                                                                                       fd,     0, basename, "")) return 1;
+                       }
+                       fprintf(fd, "typedef struct lttng_sequence_%s lttng_sequence_%s;\n",
+                                       basename,
+                                       basename);
+                       fprintf(fd, "struct lttng_sequence_%s", basename);
+                       fprintf(fd, " {\n");
+                       print_tabs(1, fd);
+                       if(print_type(((field_t*)td->fields.array[0])->type,
+                                               fd, tabs, basename, "")) return 1;
+                       fprintf(fd, " len;\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "const ");
+                       if(print_type(((field_t*)td->fields.array[1])->type,
+                                               fd, tabs, basename, "")) return 1;
+                       fprintf(fd, " *array;\n");
+                       fprintf(fd, "};\n");    /* We do not LTT_ALIGN, because we never copy
+                                                                                                                        it to the buffer directly. */
+                       fprintf(fd, "\n");
+               break;
+
+       case STRUCT:
+                       for(unsigned int i=0;i<td->fields.position;i++){
+                               field_t *field = (field_t*)(td->fields.array[i]);
+                               type_descriptor_t *type = field->type;
+                               if(type->type_name == NULL) {
+                                       /* Not a named nested type : we must print its declaration first */
+                                       if(print_type_declaration(type,
+                                                                                                                                               fd,     0, basename, field->name)) return 1;
+                               }
+                       }
+                       fprintf(fd, "struct lttng_%s", basename);
+                       fprintf(fd, " {\n");
+                       for(unsigned int i=0;i<td->fields.position;i++){
+                               field_t *field = (field_t*)(td->fields.array[i]);
+                               type_descriptor_t *type = field->type;
+                               print_tabs(1, fd);
+                               if(print_type(type, fd, tabs, basename, field->name)) return 1;
+                               fprintf(fd, " ");
+                               fprintf(fd, "%s", field->name);
+                               fprintf(fd, ";\n");
+                       }
+                       fprintf(fd, "} LTT_ALIGN;\n");
+                       fprintf(fd, "\n");
+                       break;
+       case UNION:
+                       for(unsigned int i=0;i<td->fields.position;i++){
+                               field_t *field = (field_t*)(td->fields.array[i]);
+                               type_descriptor_t *type = field->type;
+                               if(type->type_name == NULL) {
+                                       /* Not a named nested type : we must print its declaration first */
+                                       if(print_type_declaration(type,
+                                                                                                                                               fd,     0, basename, field->name)) return 1;
+                               }
+                       }
+                       fprintf(fd, "union lttng_%s", basename);
+                       fprintf(fd, " {\n");
+                       for(unsigned i=0;i<td->fields.position;i++){
+                               field_t *field = (field_t*)(td->fields.array[i]);
+                               type_descriptor_t *type = field->type;
+                               print_tabs(1, fd);
+                               if(print_type(type, fd, tabs, basename, field->name)) return 1;
+                               fprintf(fd, " ");
+                               fprintf(fd, "%s", field->name);
+                               fprintf(fd, ";\n");
+                       }
+                       fprintf(fd, "} LTT_ALIGN;\n");
+                       fprintf(fd, "\n");
+                       break;
+       default:
+               dprintf("print_type_declaration : unknown type or nothing to declare.\n");
+               break;
+       }
+
+       return 0;
+}
+
+
+/* print type alignment.
+ *
+ * Copied from construct_types_and_fields in LTTV facility.c
+ *
+ * basename is the name which identifies the type (along with a prefix
+ * (possibly)). */
+
+int print_type_alignment(type_descriptor_t * td, FILE *fd, unsigned int tabs,
+               char *nest_name, char *field_name, char *obj_prefix)
+{
+       char basename[PATH_MAX];
+       unsigned int basename_len = 0;
+       
+       strncpy(basename, nest_name, PATH_MAX);
+       basename_len = strlen(basename);
+       
+       /* For a named type, we use the type_name directly */
+       if(td->type_name != NULL) {
+               strncpy(basename, td->type_name, PATH_MAX);
+               basename_len = strlen(basename);
+       } else {
+               /* For a unnamed type, there must be a field name, except for
+                * the array. */
+               if((basename_len != 0)
+                               && (basename[basename_len-1] != '_'
+                               && field_name != NULL
+                               && (field_name[0] != '\0'))) {
+                       strncat(basename, "_", PATH_MAX - basename_len);
+                       basename_len = strlen(basename);
+               }
+               if(field_name != NULL)
+                       strncat(basename, field_name, PATH_MAX - basename_len);
+       }
+       
+       if(field_name[0] == '\0') {
+               /* We are in a write function : it's the obj that we must align. */
+               switch(td->type) {
+                       case SEQUENCE:
+                               fprintf(fd, "lttng_get_alignment_sequence_%s(%s)", basename,
+                                               obj_prefix);
+                               break;
+                       case STRUCT:
+                               fprintf(fd, "lttng_get_alignment_struct_%s(%s)", basename,
+                                               obj_prefix);
+                               break;
+                       case UNION:
+                               fprintf(fd, "lttng_get_alignment_union_%s(%s)", basename,
+                                               obj_prefix);
+                               break;
+                       case ARRAY:
+                               fprintf(fd, "lttng_get_alignment_array_%s(%s)", basename,
+                                               obj_prefix);
+                       case STRING:
+                               fprintf(fd, "sizeof(char)");
+                               break;
+                       case INT_FIXED:
+                       case UINT_FIXED:
+                       case CHAR:
+                       case UCHAR:
+                       case SHORT:
+                       case USHORT:
+                       case INT:
+                       case UINT:
+                       case FLOAT:
+                       case POINTER:
+                       case LONG:
+                       case ULONG:
+                       case SIZE_T:
+                       case SSIZE_T:
+                       case OFF_T:
+                       case ENUM:
+                               fprintf(fd, "sizeof(");
+                               if(print_type(td, fd, 0, basename, "")) return 1;
+                               fprintf(fd, ")");
+                               break;
+
+                       default:
+                               printf("error : type unexpected\n");
+                               return 1;
+                               break;
+               }
+       } else {
+               
+               switch(td->type) {
+                       case INT_FIXED:
+                       case UINT_FIXED:
+                       case CHAR:
+                       case UCHAR:
+                       case SHORT:
+                       case USHORT:
+                       case INT:
+                       case UINT:
+                       case FLOAT:
+                       case POINTER:
+                       case LONG:
+                       case ULONG:
+                       case SIZE_T:
+                       case SSIZE_T:
+                       case OFF_T:
+                       case ENUM:
+                               fprintf(fd, "sizeof(");
+                               if(print_type(td, fd, 0, basename, "")) return 1;
+                               fprintf(fd, ")");
+                               break;
+                       case STRING:
+                               fprintf(fd, "sizeof(char)");
+                               break;
+                       case SEQUENCE:
+                               fprintf(fd, "lttng_get_alignment_sequence_%s(&%s%s)", basename,
+                                               obj_prefix, field_name);
+                               break;
+                       case STRUCT:
+                               fprintf(fd, "lttng_get_alignment_struct_%s(&%s%s)", basename,
+                                               obj_prefix, field_name);
+                               break;
+                       case UNION:
+                               fprintf(fd, "lttng_get_alignment_union_%s(&%s%s)", basename,
+                                               obj_prefix, field_name);
+                               break;
+                       case ARRAY:
+                               fprintf(fd, "lttng_get_alignment_array_%s(%s%s)", basename,
+                                               obj_prefix, field_name);
+                               break;
+                       case NONE:
+                               printf("error : type NONE unexpected\n");
+                               return 1;
+                               break;
+               }
+       }
+       
+       return 0;
+}
+
+/* print type write.
+ *
+ * Copied from construct_types_and_fields in LTTV facility.c
+ *
+ * basename is the name which identifies the type (along with a prefix
+ * (possibly)). */
+
+int print_type_write(type_descriptor_t * td, FILE *fd, unsigned int tabs,
+               char *nest_name, char *field_name, char *obj_prefix, int get_ptr)
+{
+       char basename[PATH_MAX];
+       unsigned int basename_len = 0;
+       char get_ptr_char[2] = "";
+       
+       strncpy(basename, nest_name, PATH_MAX);
+       basename_len = strlen(basename);
+       
+       /* For a named type, we use the type_name directly */
+       if(td->type_name != NULL) {
+               strncpy(basename, td->type_name, PATH_MAX);
+               basename_len = strlen(basename);
+       } else {
+               /* For a unnamed type, there must be a field name, except for
+                * the array. */
+               if((basename_len != 0)
+                               && (basename[basename_len-1] != '_'
+                               && (field_name[0] != '\0'))) {
+                       strncat(basename, "_", PATH_MAX - basename_len);
+                       basename_len = strlen(basename);
+               }
+               strncat(basename, field_name, PATH_MAX - basename_len);
+       }
+       
+       if(get_ptr) {
+               strcpy(get_ptr_char, "&");
+       }
+
+       switch(td->type) {
+               case INT_FIXED:
+               case UINT_FIXED:
+               case CHAR:
+               case UCHAR:
+               case SHORT:
+               case USHORT:
+               case INT:
+               case UINT:
+               case FLOAT:
+               case POINTER:
+               case LONG:
+               case ULONG:
+               case SIZE_T:
+               case SSIZE_T:
+               case OFF_T:
+               case ENUM:
+                       print_tabs(tabs, fd);
+                       fprintf(fd, "align = ");
+                       if(print_type_alignment(td, fd, 0, basename, "", "obj")) return 1;
+                       fprintf(fd, ";\n");
+                       fprintf(fd, "\n");
+                       print_tabs(tabs, fd);
+                       fprintf(fd, "if(*len == 0) {\n");
+                       print_tabs(tabs+1, fd);
+                       fprintf(fd, "*to += ltt_align(*to, align); /* align output */\n");
+                       print_tabs(tabs, fd);
+                       fprintf(fd, "} else {\n");
+                       print_tabs(tabs+1, fd);
+                       fprintf(fd, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
+                       print_tabs(tabs, fd);
+                       fprintf(fd, "}\n");
+                       fprintf(fd, "\n");
+
+                       print_tabs(tabs, fd);
+                       fprintf(fd, "*len += ");
+                       fprintf(fd, "sizeof(");
+                       if(print_type(td, fd, 0, basename, "")) return 1;
+                       fprintf(fd, ");\n");
+
+                       break;
+               case STRING:
+                       print_tabs(tabs, fd);
+                       fprintf(fd,
+                                       "lttng_write_string_%s(buffer, to_base, to, from, len, %s%s);\n",
+                                       basename, obj_prefix, field_name);
+                       break;
+               case SEQUENCE:
+                       print_tabs(tabs, fd);
+                       fprintf(fd,
+                                       "lttng_write_sequence_%s(buffer, to_base, to, from, len, %s%s%s);",
+                                       basename, get_ptr_char, obj_prefix, field_name);
+                       break;
+               case STRUCT:
+                       print_tabs(tabs, fd);
+                       fprintf(fd,
+                                       "lttng_write_struct_%s(buffer, to_base, to, from, len, %s%s%s);",
+                                       basename, get_ptr_char, obj_prefix, field_name);
+                       break;
+               case UNION:
+                       print_tabs(tabs, fd);
+                       fprintf(fd,
+                                       "lttng_write_union_%s(buffer, to_base, to, from, len, %s%s%s);",
+                                       basename, get_ptr_char, obj_prefix, field_name);
+                       break;
+               case ARRAY:
+                       print_tabs(tabs, fd);
+                       fprintf(fd,
+                                       "lttng_write_array_%s(buffer, to_base, to, from, len, %s%s);",
+                                       basename, obj_prefix, field_name);
+                       break;
+               case NONE:
+                       printf("Error : type NONE unexpected\n");
+                       return 1;
+                       break;
+       }
+
+       return 0;
+}
+
+/* print need local vars ?.
+ *
+ * Copied from print_type_write
+ *
+ * Does the type_write call needs local size and from variables ?
+ * return value : 1 yes, 0 no.
+ */
+
+int has_type_local(type_descriptor_t * td)
+{
+       switch(td->type) {
+               case INT_FIXED:
+               case UINT_FIXED:
+               case CHAR:
+               case UCHAR:
+               case SHORT:
+               case USHORT:
+               case INT:
+               case UINT:
+               case FLOAT:
+               case POINTER:
+               case LONG:
+               case ULONG:
+               case SIZE_T:
+               case SSIZE_T:
+               case OFF_T:
+               case ENUM:
+                       return 1;
+                       break;
+               case STRING:
+               case SEQUENCE:
+               case STRUCT:
+               case UNION:
+               case ARRAY:
+                       return 0;
+                       break;
+               case NONE:
+                       printf("Error : type NONE unexpected\n");
+                       return 1;
+                       break;
+       }
+
+       return 0;
+}
+
+
+
+/* print type alignment function.
+ *
+ * Copied from construct_types_and_fields in LTTV facility.c
+ *
+ * basename is the name which identifies the type (along with a prefix
+ * (possibly)). */
+
+int print_type_alignment_fct(type_descriptor_t * td, FILE *fd,
+               unsigned int tabs,
+               char *nest_name, char *field_name)
+{
+       char basename[PATH_MAX];
+       unsigned int basename_len = 0;
+       
+       strncpy(basename, nest_name, PATH_MAX);
+       basename_len = strlen(basename);
+       
+       /* For a named type, we use the type_name directly */
+       if(td->type_name != NULL) {
+               strncpy(basename, td->type_name, PATH_MAX);
+               basename_len = strlen(basename);
+       } else {
+               /* For a unnamed type, there must be a field name, except for
+                * the array. */
+               if((basename_len != 0)
+                               && (basename[basename_len-1] != '_'
+                               && (field_name[0] != '\0'))) {
+                       strncat(basename, "_", PATH_MAX - basename_len);
+                       basename_len = strlen(basename);
+               }
+               strncat(basename, field_name, PATH_MAX - basename_len);
+       }
+       
+       switch(td->type) {
+               case SEQUENCE:
+                       /* Function header */
+                       fprintf(fd, "static inline size_t lttng_get_alignment_sequence_%s(\n",
+                                       basename);
+                       print_tabs(2, fd);
+                       if(print_type(td,       fd, 0, basename, "")) return 1;
+                       fprintf(fd, " *obj)\n");
+                       fprintf(fd, "{\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "size_t align=0, localign;");
+                       fprintf(fd, "\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "localign = ");
+                       if(print_type_alignment(((field_t*)td->fields.array[0])->type,
+                                               fd, 0, basename, "len", "obj->")) return 1;
+                       fprintf(fd, ";\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "align = max(align, localign);\n");
+                       fprintf(fd, "\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "localign = ");
+                       if(print_type_alignment(((field_t*)td->fields.array[1])->type,
+                                               fd, 0, basename, "array[0]", "obj->")) return 1;
+                       fprintf(fd, ";\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "align = max(align, localign);\n");
+                       fprintf(fd, "\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "return align;\n");
+                       break;
+               case STRUCT:
+                       /* Function header */
+                       fprintf(fd, "static inline size_t lttng_get_alignment_struct_%s(\n",
+                                       basename);
+                       print_tabs(2, fd);
+                       if(print_type(td,       fd, 0, basename, "")) return 1;
+                       fprintf(fd, " *obj)\n");
+                       fprintf(fd, "{\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "size_t align=0, localign;");
+                       fprintf(fd, "\n");
+                       for(unsigned int i=0;i<td->fields.position;i++){
+                               field_t *field = (field_t*)(td->fields.array[i]);
+                               type_descriptor_t *type = field->type;
+                               print_tabs(1, fd);
+                               fprintf(fd, "localign = ");
+                               if(print_type_alignment(type, fd, 0, basename, field->name, "obj->"))
+                                       return 1;
+                               fprintf(fd, ";\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "align = max(align, localign);\n");
+                               fprintf(fd, "\n");
+                       }
+                       print_tabs(1, fd);
+                       fprintf(fd, "return align;\n");
+
+                       break;
+               case UNION:
+                       /* Function header */
+                       fprintf(fd, "static inline size_t lttng_get_alignment_union_%s(\n",
+                                       basename);
+                       print_tabs(2, fd);
+                       if(print_type(td,       fd, 0, basename, "")) return 1;
+                       fprintf(fd, " *obj)\n");
+                       fprintf(fd, "{\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "size_t align=0, localign;");
+                       fprintf(fd, "\n");
+                       for(unsigned int i=0;i<td->fields.position;i++){
+                               field_t *field = (field_t*)(td->fields.array[i]);
+                               type_descriptor_t *type = field->type;
+                               print_tabs(1, fd);
+                               fprintf(fd, "localign = ");
+                               if(print_type_alignment(type, fd, 0, basename, field->name, "obj->"))
+                                       return 1;
+                               fprintf(fd, ";\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "align = max(align, localign);\n");
+                               fprintf(fd, "\n");
+                       }
+                       print_tabs(1, fd);
+                       fprintf(fd, "return align;\n");
+
+                       break;
+               case ARRAY:
+                       /* Function header */
+                       fprintf(fd, "static inline size_t lttng_get_alignment_array_%s(\n",
+                                       basename);
+                       print_tabs(2, fd);
+                       if(print_type(td,       fd, 0, basename, "")) return 1;
+                       fprintf(fd, " obj)\n");
+                       fprintf(fd, "{\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "return \n");
+                       if(print_type_alignment(((field_t*)td->fields.array[0])->type,
+                                               fd, 0, basename, "", "obj[0]"))
+                               return 1;
+                       fprintf(fd, ";\n");
+                       break;
+               default:
+                       dprintf("print_type_alignment_fct : type has no alignment function.\n");
+                       return 0;
+                       break;
+       }
+
+
+       /* Function footer */
+       fprintf(fd, "}\n");
+       fprintf(fd, "\n");
+
+       return 0;
+}
+
+/* print type write function.
+ *
+ * Copied from construct_types_and_fields in LTTV facility.c
+ *
+ * basename is the name which identifies the type (along with a prefix
+ * (possibly)). */
+
+int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs,
+               char *nest_name, char *field_name)
+{
+       char basename[PATH_MAX];
+       unsigned int basename_len = 0;
+       
+       strncpy(basename, nest_name, PATH_MAX);
+       basename_len = strlen(basename);
+       
+       /* For a named type, we use the type_name directly */
+       if(td->type_name != NULL) {
+               strncpy(basename, td->type_name, PATH_MAX);
+               basename_len = strlen(basename);
+       } else {
+               /* For a unnamed type, there must be a field name, except for
+                * the array. */
+               if((basename_len != 0)
+                               && (basename[basename_len-1] != '_'
+                               && (field_name[0] != '\0'))) {
+                       strncat(basename, "_", PATH_MAX - basename_len);
+                       basename_len = strlen(basename);
+               }
+               strncat(basename, field_name, PATH_MAX - basename_len);
+       }
+       
+       switch(td->type) {
+               case SEQUENCE:
+               case STRUCT:
+               case UNION:
+               case ARRAY:
+               case STRING:
+                       break;
+               default:
+                       dprintf("print_type_write_fct : type has no write function.\n");
+                       return 0;
+                       break;
+       }
+       
+       /* Print header */
+       switch(td->type) {
+               case SEQUENCE:
+                       fprintf(fd, "static inline void lttng_write_sequence_%s(\n",
+                                       basename);
+                       break;
+               case STRUCT:
+                       fprintf(fd, "static inline void lttng_write_struct_%s(\n", basename);
+                       break;
+               case UNION:
+                       fprintf(fd, "static inline void lttng_write_union_%s(\n", basename);
+                       break;
+               case ARRAY:
+                       fprintf(fd, "static inline void lttng_write_array_%s(\n", basename);
+                       break;
+               case STRING:
+                       fprintf(fd, "static inline void lttng_write_string_%s(\n", basename);
+                       break;
+               default:
+                       printf("print_type_write_fct : type has no write function.\n");
+                       break;
+       }
+
+       print_tabs(2, fd);
+       fprintf(fd, "void *buffer,\n");
+       print_tabs(2, fd);
+       fprintf(fd, "size_t *to_base,\n");
+       print_tabs(2, fd);
+       fprintf(fd, "size_t *to,\n");
+       print_tabs(2, fd);
+       fprintf(fd, "const void **from,\n");
+       print_tabs(2, fd);
+       fprintf(fd, "size_t *len,\n");
+       print_tabs(2, fd);
+       if(print_type(td,       fd, 0, basename, "")) return 1;
+
+       switch(td->type) {
+               case SEQUENCE:
+                       fprintf(fd, " *obj)\n");
+                       break;
+               case STRUCT:
+                       fprintf(fd, " *obj)\n");
+                       break;
+               case UNION:
+                       fprintf(fd, " *obj)\n");
+                       break;
+               case ARRAY:
+                       fprintf(fd, " obj)\n");
+                       break;
+               case STRING:
+                       fprintf(fd, " obj)\n");
+                       break;
+               default:
+                       printf("print_type_write_fct : type has no write function.\n");
+                       break;
+       }
+
+       fprintf(fd, "{\n");
+
+       print_tabs(1, fd);
+       fprintf(fd, "size_t size;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t align;\n");
+       fprintf(fd, "\n");
+
+       switch(td->type) {
+               case SEQUENCE:
+               case STRING:
+                       print_tabs(1, fd);
+                       fprintf(fd, "/* Flush pending memcpy */\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "if(*len != 0) {\n");
+                       print_tabs(2, fd);
+                       fprintf(fd, "if(buffer != NULL)\n");
+                       print_tabs(3, fd);
+                       fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "}\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "*to += *len;\n");
+                       print_tabs(1, fd);
+                       fprintf(fd, "*len = 0;\n");
+                       fprintf(fd, "\n");
+                       break;
+               case STRUCT:
+               case UNION:
+               case ARRAY:
+                       break;
+               default:
+                       printf("print_type_write_fct : type has no write function.\n");
+                       break;
+       }
+       
+       print_tabs(1, fd);
+       fprintf(fd, "align = ");
+       if(print_type_alignment(td, fd, 0, basename, "", "obj")) return 1;
+       fprintf(fd, ";\n");
+       fprintf(fd, "\n");
+       print_tabs(1, fd);
+       fprintf(fd, "if(*len == 0) {\n");
+       print_tabs(2, fd);
+       fprintf(fd, "*to += ltt_align(*to, align); /* align output */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "} else {\n");
+       print_tabs(2, fd);
+       fprintf(fd, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "}\n");
+       fprintf(fd, "\n");
+
+       /* First, check if the type has a fixed size. If it is the case, then the size
+        * to write is know by the compiler : simply use a sizeof() */
+       if(has_type_fixed_size(td)) {
+               print_tabs(1, fd);
+               fprintf(fd, "/* Contains only fixed size fields : use compiler sizeof() */\n");
+               fprintf(fd, "\n");
+               print_tabs(1, fd);
+               fprintf(fd, "size = sizeof(");
+               if(print_type(td, fd, 0, basename, field_name)) return 1;
+               fprintf(fd, ");\n");
+               print_tabs(1, fd);
+               fprintf(fd, "*len += size;\n");
+       } else {
+               /* The type contains nested variable size subtypes :
+                * we must write field by field. */
+               print_tabs(1, fd);
+               fprintf(fd, "/* Contains variable sized fields : must explode the structure */\n");
+               fprintf(fd, "\n");
+
+               switch(td->type) {
+                       case SEQUENCE:
+                               print_tabs(1, fd);
+                               fprintf(fd, "/* Copy members */\n");
+//                             print_tabs(1, fd);
+//                             fprintf(fd, "size = sizeof(\n");
+                               if(print_type_write(((field_t*)td->fields.array[0])->type,
+                                               fd, 1, basename, "len", "obj->", 1)) return 1;
+                               fprintf(fd, "\n");
+//                             fprintf(fd, ");\n");
+//                             print_tabs(1, fd);
+//                             fprintf(fd, "*to += ltt_align(*to, size);\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "if(buffer != NULL)\n");
+                               print_tabs(2, fd);
+                               fprintf(fd, "memcpy(buffer+*to_base+*to, &obj->len, *len);\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to += *len;\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*len = 0;\n");
+                               fprintf(fd, "\n");
+
+                               /* Write the child : varlen child or not ? */
+                               if(has_type_fixed_size(((field_t*)td->fields.array[1])->type)) {
+                                       /* Fixed size len child : use a multiplication of its size */
+//                                     print_tabs(1, fd);
+//                                     fprintf(fd, "size = sizeof(\n");
+
+                                       //print_tabs(1, fd);
+                                       /* We know that *len does not contain alignment because of the
+                                        * previous align output. len is always 0 here. */
+                                       if(print_type_write(((field_t*)td->fields.array[1])->type,
+                                                       fd, 1, basename, "array[0]", "obj->", 1))
+                                               return 1;
+//                                     fprintf(fd, ");\n");
+                                       fprintf(fd, "\n");
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "*len = obj->len * (*len);\n");
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "if(buffer != NULL)\n");
+                                       print_tabs(2, fd);
+                                       fprintf(fd, "memcpy(buffer+*to_base+*to, obj->array, *len);\n");
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "*to += *len;\n");
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "*len = 0;\n");
+                                       fprintf(fd, "\n");
+                               } else {
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "/* Variable length child : iter. */\n");
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "for(unsigned int i=0; i<obj->len; i++) {\n");
+                                       if(print_type_write(((field_t*)td->fields.array[1])->type,
+                                                       fd, 2, basename, "array[i]", "obj->", 1)) return 1;
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "}\n");
+                               }
+                               fprintf(fd, "\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "/* Realign the *to_base on arch size, set *to to 0 */\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to += ltt_align(*to, sizeof(void *));\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to_base = *to_base+*to;\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to = 0;\n");
+                               fprintf(fd, "\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "/* Put source *from just after the C sequence */\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*from = obj+1;\n");
+                               break;
+                       case STRING:
+                               print_tabs(1, fd);
+                               fprintf(fd, "size = strlen(obj) + 1; /* Include final NULL char. */\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "if(buffer != NULL)\n");
+                               print_tabs(2, fd);
+                               fprintf(fd, "memcpy(buffer+*to_base+*to, obj, size);\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to += size;\n");
+                               fprintf(fd, "\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "/* Realign the *to_base on arch size, set *to to 0 */\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to += ltt_align(*to, sizeof(void *));\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to_base = *to_base+*to;\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*to = 0;\n");
+                               fprintf(fd, "\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "/* Put source *from just after the C string */\n");
+                               print_tabs(1, fd);
+                               fprintf(fd, "*from += size;\n");
+                               break;
+                       case STRUCT:
+                               for(unsigned int i=0;i<td->fields.position;i++){
+                                       field_t *field = (field_t*)(td->fields.array[i]);
+                                       type_descriptor_t *type = field->type;
+                                       if(print_type_write(type,
+                                                       fd, 1, basename, field->name, "obj->", 1)) return 1;
+                                       fprintf(fd, "\n");
+                               }
+                               break;
+                       case UNION:
+                               printf("ERROR : A union CANNOT contain a variable size child.\n");
+                               return 1;
+                               break;
+                       case ARRAY:
+                               /* Write the child : varlen child or not ? */
+                               if(has_type_fixed_size(((field_t*)td->fields.array[0])->type)) {
+                                       /* Error : if an array has a variable size, then its child must also
+                                        * have a variable size. */
+                                       assert(0);
+                               } else {
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "/* Variable length child : iter. */\n");
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "for(unsigned int i=0; i<LTTNG_ARRAY_SIZE_%s; i++) {\n", basename);
+                                       if(print_type_write(((field_t*)td->fields.array[0])->type,
+                                                       fd, 2, basename, "", "obj->array[i]", 1)) return 1;
+                                       print_tabs(1, fd);
+                                       fprintf(fd, "}\n");
+                               }
+                               break;
+                       default:
+                               printf("print_type_write_fct : type has no write function.\n");
+                               break;
+               }
+
+
+       }
+
+
+       /* Function footer */
+       fprintf(fd, "}\n");
+       fprintf(fd, "\n");
+       return 0;
+}
+
+
+
+/* Print the logging function of an event. This is the core of genevent */
+int print_event_logging_function(char *basename, facility_t *fac,
+               event_t *event, FILE *fd)
+{
+       fprintf(fd, "static inline void trace_%s(\n", basename);
+       int     has_argument = 0;
+       int has_type_fixed = 0;
+
+  /* Does it support per trace tracing ? */
+  if(event->per_trace) {
+               print_tabs(2, fd);
+    fprintf(fd, "struct ltt_trace_struct *dest_trace");
+               has_argument = 1;
+  }
+  
+  /* Does it support per tracefile tracing ? */
+  if(event->per_tracefile) {
+               if(has_argument) {
+                       fprintf(fd, ",");
+                       fprintf(fd, "\n");
+               }
+    fprintf(fd, "unsigned int tracefile_index");
+               has_argument = 1;
+  }
+
+       for(unsigned int j = 0; j < event->fields.position; j++) {
+               /* For each field, print the function argument */
+               field_t *f = (field_t*)event->fields.array[j];
+               type_descriptor_t *t = f->type;
+               if(has_argument) {
+                       fprintf(fd, ",");
+                       fprintf(fd, "\n");
+               }
+               if(print_arg(t, fd, 2, basename, f->name)) return 1;
+               has_argument = 1;
+       }
+       if(!has_argument) {
+               print_tabs(2, fd);
+               fprintf(fd, "void");
+       }
+       fprintf(fd,")\n");
+       fprintf(fd, 
+                       "#if (!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n",
+                       fac->capname);
+       fprintf(fd, "{\n");
+       fprintf(fd, "}\n");
+       fprintf(fd,"#else\n");
+       fprintf(fd, "{\n");
+       /* Print the function variables */
+       print_tabs(1, fd);
+       fprintf(fd, "unsigned int index;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "struct ltt_channel_struct *channel;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "struct ltt_trace_struct *trace;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "struct rchan_buf *relayfs_buf;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "void *buffer = NULL;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t *to_base = &real_to_base;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t real_to = 0;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t *to = &real_to;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t real_len = 0;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t *len = &real_len;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t reserve_size;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t slot_size;\n");
+       print_tabs(1, fd);
+
+       if(event->fields.position > 0) {
+               for(unsigned int i=0;i<event->fields.position;i++){
+                       /* Search for at least one child with fixed size. It means
+                        * we need local variables.*/
+                       field_t *field = (field_t*)(event->fields.array[i]);
+                       type_descriptor_t *type = field->type;
+                       has_type_fixed = has_type_local(type);
+                       if(has_type_fixed) break;
+               }
+               
+               if(has_type_fixed) {
+                       fprintf(fd, "size_t align;\n");
+                       print_tabs(1, fd);
+               }
+
+               fprintf(fd, "const void *real_from;\n");
+               print_tabs(1, fd);
+               fprintf(fd, "const void **from = &real_from;\n");
+               print_tabs(1, fd);
+       }
+       fprintf(fd, "cycles_t tsc;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "size_t before_hdr_pad, after_hdr_pad, header_size;\n");
+       fprintf(fd, "\n");
+       
+       print_tabs(1, fd);
+       fprintf(fd, "if(ltt_traces.num_active_traces == 0) return;\n");
+       fprintf(fd, "\n");
+
+       /* Calculate event variable len + event data alignment offset.
+        * Assume that the padding for alignment starts at a void*
+        * address.
+        * This excludes the header size and alignment. */
+
+       print_tabs(1, fd);
+       fprintf(fd, "/* For each field, calculate the field size. */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "/* size = *to_base + *to + *len */\n");
+       print_tabs(1, fd);
+       fprintf(fd, "/* Assume that the padding for alignment starts at a\n");
+       print_tabs(1, fd);
+       fprintf(fd, " * sizeof(void *) address. */\n");
+       fprintf(fd, "\n");
+
+       for(unsigned int i=0;i<event->fields.position;i++){
+               field_t *field = (field_t*)(event->fields.array[i]);
+               type_descriptor_t *type = field->type;
+               /* Set from */
+               print_tabs(1, fd);
+               switch(type->type) {
+                       case SEQUENCE:
+                       case UNION:
+                       case ARRAY:
+                       case STRUCT:
+                       case STRING:
+                               fprintf(fd, "*from = lttng_param_%s;\n", field->name);
+                               break;
+                       default:
+                               fprintf(fd, "*from = &lttng_param_%s;\n", field->name);
+                               break;
+               }
+
+               if(print_type_write(type,
+                               fd, 1, basename, field->name, "lttng_param_", 0)) return 1;
+               fprintf(fd, "\n");
+       }
+       print_tabs(1, fd);
+       fprintf(fd, "reserve_size = *to_base + *to + *len;\n");
+
+       /* Take locks : make sure the trace does not vanish while we write on
+        * it. A simple preemption disabling is enough (using rcu traces). */
+       print_tabs(1, fd);
+       fprintf(fd, "preempt_disable();\n");
+       print_tabs(1, fd);
+       fprintf(fd, "ltt_nesting[smp_processor_id()]++;\n");
+
+       /* Get facility index */
+
+       if(event->per_tracefile) {
+               print_tabs(1, fd);
+               fprintf(fd, "index = tracefile_index;\n");
+       } else {
+               print_tabs(1, fd);
+               fprintf(fd, 
+                       "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
+                                       "\t\t\t\t\t\tevent_%s_%s);\n",
+                               fac->name, fac->checksum, fac->name, event->name);
+       }
+       fprintf(fd,"\n");
+
+       
+       /* For each trace */
+       print_tabs(1, fd);
+       fprintf(fd, "list_for_each_entry_rcu(trace, &ltt_traces.head, list) {\n");
+       print_tabs(2, fd);
+       fprintf(fd, "if(!trace->active) continue;\n\n");
+
+       if(event->per_trace) {
+               print_tabs(2, fd);
+               fprintf(fd, "if(dest_trace != trace) continue;\n\n");
+       }
+       print_tabs(2, fd);
+       fprintf(fd, "channel = ltt_get_channel_from_index(trace, index);\n");
+       print_tabs(2, fd);
+       fprintf(fd, "relayfs_buf = channel->rchan->buf[smp_processor_id()];\n");
+       fprintf(fd, "\n");
+
+       
+       /* Relay reserve */
+       /* If error, increment event lost counter (done by ltt_reserve_slot) and 
+        * return */
+       print_tabs(2, fd);
+       fprintf(fd, "slot_size = 0;\n");
+       print_tabs(2, fd);
+       fprintf(fd, "buffer = ltt_reserve_slot(trace, relayfs_buf,\n");
+       print_tabs(3, fd);
+       fprintf(fd, "reserve_size, &slot_size, &tsc,\n");
+       print_tabs(3, fd);
+       fprintf(fd, "&before_hdr_pad, &after_hdr_pad, &header_size);\n");
+       /* If error, return */
+       print_tabs(2, fd);
+       fprintf(fd, "if(!buffer) continue; /* buffer full */\n\n");
+       //print_tabs(2, fd);
+       // for DEBUG only 
+       // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
+       print_tabs(2, fd);
+       fprintf(fd, "*to_base = *to = *len = 0;\n");
+       fprintf(fd, "\n");
+
+       /* Write event header */
+       print_tabs(2, fd);
+       fprintf(fd, "ltt_write_event_header(trace, channel, buffer,\n");
+       print_tabs(3, fd);
+       fprintf(fd, "ltt_facility_%s_%X, event_%s_%s,\n", fac->name, fac->checksum,
+                                                                       fac->name, event->name);
+       print_tabs(3, fd);
+       fprintf(fd, "reserve_size, before_hdr_pad, tsc);\n");
+       print_tabs(2, fd);
+       fprintf(fd, "*to_base += before_hdr_pad + after_hdr_pad + header_size;\n");
+       fprintf(fd, "\n");
+       
+       /* write data. */
+
+       for(unsigned int i=0;i<event->fields.position;i++){
+               field_t *field = (field_t*)(event->fields.array[i]);
+               type_descriptor_t *type = field->type;
+       
+               /* Set from */
+               print_tabs(2, fd);
+               switch(type->type) {
+                       case SEQUENCE:
+                       case UNION:
+                       case ARRAY:
+                       case STRUCT:
+                       case STRING:
+                               fprintf(fd, "*from = lttng_param_%s;\n", field->name);
+                               break;
+                       default:
+                               fprintf(fd, "*from = &lttng_param_%s;\n", field->name);
+                               break;
+               }
+
+
+               if(print_type_write(type,
+                               fd, 2, basename, field->name, "lttng_param_", 0)) return 1;
+               fprintf(fd, "\n");
+               
+               /* Don't forget to flush pending memcpy */
+               print_tabs(2, fd);
+               fprintf(fd, "/* Flush pending memcpy */\n");
+               print_tabs(2, fd);
+               fprintf(fd, "if(*len != 0) {\n");
+               print_tabs(3, fd);
+               fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n");
+               print_tabs(3, fd);
+               fprintf(fd, "*to += *len;\n");
+               //print_tabs(3, fd);
+               //fprintf(fd, "from += len;\n");
+               print_tabs(3, fd);
+               fprintf(fd, "*len = 0;\n");
+               print_tabs(2, fd);
+               fprintf(fd, "}\n");
+               fprintf(fd, "\n");
+       }
+
+       
+       /* commit */
+       // for DEBUG only.
+       //fprintf(fd, "commit:\n"); /* DEBUG! */
+       print_tabs(2, fd);
+       fprintf(fd, "ltt_commit_slot(relayfs_buf, buffer, slot_size);\n\n");
+       
+       print_tabs(1, fd);
+       fprintf(fd, "}\n\n");
+
+       /* Release locks */
+       print_tabs(1, fd);
+       fprintf(fd, "ltt_nesting[smp_processor_id()]--;\n");
+       print_tabs(1, fd);
+       fprintf(fd, "preempt_enable_no_resched();\n");
+
+       fprintf(fd, "}\n");
+       fprintf(fd, "#endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n\n",
+                       fac->capname);
+       return 0;
+}
+
+
+/* ltt-facility-name.h : main logging header.
+ * log_header */
+
+void print_log_header_head(facility_t *fac, FILE *fd)
+{
+       fprintf(fd, "#ifndef _LTT_FACILITY_%s_H_\n", fac->capname);
+       fprintf(fd, "#define _LTT_FACILITY_%s_H_\n\n", fac->capname);
+  fprintf(fd, "#include <linux/types.h>\n");
+  fprintf(fd, "#include <linux/ltt/ltt-facility-id-%s.h>\n", fac->name);
+  fprintf(fd, "#include <linux/ltt-core.h>\n");
+       fprintf(fd, "\n");
+}
+
+
+
+int print_log_header_types(facility_t *fac, FILE *fd)
+{
+       sequence_t *types = &fac->named_types.values;
+       fprintf(fd, "/* Named types */\n");
+       fprintf(fd, "\n");
+       
+       for(unsigned int i = 0; i < types->position; i++) {
+               /* For each named type, print the definition */
+               if(print_type_declaration(types->array[i], fd,
+                                               0, "", "")) return 1;
+               /* Print also the align function */
+               if(print_type_alignment_fct(types->array[i], fd,
+                                               0, "", "")) return 1;
+               /* Print also the write function */
+               if(print_type_write_fct(types->array[i], fd,
+                                               0, "", "")) return 1;
+       }
+       return 0;
+}
+
+int print_log_header_events(facility_t *fac, FILE *fd)
+{
+       sequence_t *events = &fac->events;
+       char basename[PATH_MAX];
+       unsigned int facname_len;
+       
+       strncpy(basename, fac->name, PATH_MAX);
+       facname_len = strlen(basename);
+       strncat(basename, "_", PATH_MAX-facname_len);
+       facname_len = strlen(basename);
+
+       for(unsigned int i = 0; i < events->position; i++) {
+               event_t *event = (event_t*)events->array[i];
+               strncpy(&basename[facname_len], event->name, PATH_MAX-facname_len);
+               
+               /* For each event, print structure, and then logging function */
+               fprintf(fd, "/* Event %s structures */\n",
+                               event->name);
+               for(unsigned int j = 0; j < event->fields.position; j++) {
+                       /* For each unnamed type, print the definition */
+                       field_t *f = (field_t*)event->fields.array[j];
+                       type_descriptor_t *t = f->type;
+                       if(t->type_name == NULL) {
+                               if((print_type_declaration(t, fd, 0, basename, f->name))) return 1;
+                               /* Print also the align function */
+                               if((print_type_alignment_fct(t, fd, 0, basename, f->name))) return 1;
+                               /* Print also the write function */
+                               if((print_type_write_fct(t, fd, 0, basename, f->name))) return 1;
+                       }
+               }
+
+               fprintf(fd, "\n");
+
+               fprintf(fd, "/* Event %s logging function */\n",
+                               event->name);
+
+               if(print_event_logging_function(basename, fac, event, fd)) return 1;
+
+               fprintf(fd, "\n");
+       }
+       
+       return 0;
+}
+
+
+void print_log_header_tail(facility_t *fac, FILE *fd)
+{
+       fprintf(fd, "#endif //_LTT_FACILITY_%s_H_\n",fac->capname);
+}
+       
+int print_log_header(facility_t *fac)
+{
+       char filename[PATH_MAX];
+       unsigned int filename_size = 0;
+       FILE *fd;
+       dprintf("%s\n", fac->name);
+
+       strcpy(filename, "ltt-facility-");
+       filename_size = strlen(filename);
+       
+       strncat(filename, fac->name, PATH_MAX - filename_size);
+       filename_size = strlen(filename);
+
+       strncat(filename, ".h", PATH_MAX - filename_size);
+       filename_size = strlen(filename);
+       
+
+       fd = fopen(filename, "w");
+       if(fd == NULL) {
+               printf("Error opening file %s for writing : %s\n",
+                               filename, strerror(errno));
+               return errno;
+       }
+
+       /* Print file head */
+       print_log_header_head(fac, fd);
+
+       /* print named types in declaration order */
+       if(print_log_header_types(fac, fd)) return 1;
+
+       /* Print events */
+       if(print_log_header_events(fac, fd)) return 1;
+       
+       /* Print file tail */
+       print_log_header_tail(fac, fd);
+
+       
+       fclose(fd);
+       
+       return 0;
+}
+
+
+/* ltt-facility-id-name.h : facility id.
+ * log_id_header */
+int print_id_header(facility_t *fac)
+{
+       char filename[PATH_MAX];
+       unsigned int filename_size = 0;
+       FILE *fd;
+       char basename[PATH_MAX];
+       char basename_len = 0;
+
+       dprintf("%s\n", fac->name);
+
+       strcpy(filename, "ltt-facility-id-");
+       filename_size = strlen(filename);
+       
+       strncat(filename, fac->name, PATH_MAX - filename_size);
+       filename_size = strlen(filename);
+
+       strncat(filename, ".h", PATH_MAX - filename_size);
+       filename_size = strlen(filename);
+       
+
+       fd = fopen(filename, "w");
+       if(fd == NULL) {
+               printf("Error opening file %s for writing : %s\n",
+                               filename, strerror(errno));
+               return errno;
+       }
+
+  fprintf(fd, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac->capname);
+  fprintf(fd, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac->capname);
+  fprintf(fd, "#ifdef CONFIG_LTT\n");
+
+  fprintf(fd,"#include <linux/ltt-facilities.h>\n\n");
+
+  fprintf(fd,"/****  facility handle  ****/\n\n");
+  fprintf(fd,"extern ltt_facility_t ltt_facility_%s_%X;\n",
+                       fac->name, fac->checksum);
+  fprintf(fd,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac->name);
+
+       strncpy(basename, fac->name, PATH_MAX);
+       basename_len = strlen(basename);
+       strncat(basename, "_", PATH_MAX - basename_len);
+       basename_len++;
+       
+       fprintf(fd,"/****  event index  ****/\n\n");
+       fprintf(fd,"enum %s_event {\n",fac->name);
+       
+       for(unsigned int i = 0; i < fac->events.position; i++) {
+               event_t *event = (event_t*)fac->events.array[i];
+               strncpy(basename+basename_len, event->name, PATH_MAX-basename_len);
+               print_tabs(1, fd);
+               fprintf(fd, "event_%s,\n", basename);
+       }
+       print_tabs(1, fd);
+       fprintf(fd, "facility_%s_num_events\n", fac->name);
+       fprintf(fd, "};\n");
+       fprintf(fd, "\n");
+
+
+  fprintf(fd, "#endif //CONFIG_LTT\n");
+  fprintf(fd, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac->capname);
+
+
+       fclose(fd);
+
+       return 0;
+}
+
+
+/* ltt-facility-loader-name.h : facility specific loader info.
+ * loader_header */
+int print_loader_header(facility_t *fac)
+{
+       char filename[PATH_MAX];
+       unsigned int filename_size = 0;
+       FILE *fd;
+       dprintf("%s\n", fac->name);
+
+       strcpy(filename, "ltt-facility-loader-");
+       filename_size = strlen(filename);
+       
+       strncat(filename, fac->name, PATH_MAX - filename_size);
+       filename_size = strlen(filename);
+
+       strncat(filename, ".h", PATH_MAX - filename_size);
+       filename_size = strlen(filename);
+       
+
+       fd = fopen(filename, "w");
+       if(fd == NULL) {
+               printf("Error opening file %s for writing : %s\n",
+                               filename, strerror(errno));
+               return errno;
+       }
+
+  fprintf(fd, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac->capname);
+  fprintf(fd, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac->capname);
+  fprintf(fd, "#ifdef CONFIG_LTT\n\n");
+  fprintf(fd,"#include <linux/ltt-facilities.h>\n");
+  fprintf(fd,"#include <linux/ltt/ltt-facility-id-%s.h>\n\n",
+                       fac->name);
+  fprintf(fd,"ltt_facility_t\tltt_facility_%s;\n", fac->name);
+  fprintf(fd,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
+                       fac->name, fac->checksum);
+
+  fprintf(fd,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n",
+      fac->name);
+  fprintf(fd,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n",
+      fac->name, fac->checksum);
+  fprintf(fd,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac->checksum);
+  fprintf(fd,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac->name);
+  fprintf(fd,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n",
+                       fac->name);
+  fprintf(fd, "#endif //CONFIG_LTT\n\n");
+  fprintf(fd, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac->capname);
+
+       fclose(fd);
+
+       return 0;
+}
+
+/* ltt-facility-loader-name.c : generic faciilty loader
+ * loader_c */
+int print_loader_c(facility_t *fac)
+{
+       char filename[PATH_MAX];
+       unsigned int filename_size = 0;
+       FILE *fd;
+       dprintf("%s\n", fac->name);
+
+       strcpy(filename, "ltt-facility-loader-");
+       filename_size = strlen(filename);
+       
+       strncat(filename, fac->name, PATH_MAX - filename_size);
+       filename_size = strlen(filename);
+
+       strncat(filename, ".c", PATH_MAX - filename_size);
+       filename_size = strlen(filename);
+       
+
+       fd = fopen(filename, "w");
+       if(fd == NULL) {
+               printf("Error opening file %s for writing : %s\n",
+                               filename, strerror(errno));
+               return errno;
+       }
+
+  fprintf(fd, "/*\n");
+  fprintf(fd, " * ltt-facility-loader-%s.c\n", fac->name);
+  fprintf(fd, " *\n");
+  fprintf(fd, " * (C) Copyright  2005 - \n");
+  fprintf(fd, " *          Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
+  fprintf(fd, " *\n");
+  fprintf(fd, " * Contains the LTT facility loader.\n");
+  fprintf(fd, " *\n");
+  fprintf(fd, " */\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "#include <linux/ltt-facilities.h>\n");
+  fprintf(fd, "#include <linux/module.h>\n");
+  fprintf(fd, "#include <linux/init.h>\n");
+  fprintf(fd, "#include <linux/config.h>\n");
+  fprintf(fd, "#include \"ltt-facility-loader-%s.h\"\n", fac->name);
+  fprintf(fd, "\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "#ifdef CONFIG_LTT\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);\n");
+  fprintf(fd, "EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "static const char ltt_facility_name[] = LTT_FACILITY_NAME;\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "#define SYMBOL_STRING(sym) #sym\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "static struct ltt_facility facility = {\n");
+  fprintf(fd, "\t.name = ltt_facility_name,\n");
+  fprintf(fd, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
+  fprintf(fd, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
+  fprintf(fd, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),\n");
+  fprintf(fd, "};\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "#ifndef MODULE\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "/* Built-in facility. */\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "static int __init facility_init(void)\n");
+  fprintf(fd, "{\n");
+  fprintf(fd, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init in kernel\\n\");\n", fac->name);
+  fprintf(fd, "\n");
+  fprintf(fd, "\tLTT_FACILITY_SYMBOL = ltt_facility_builtin_register(&facility);\n");
+  fprintf(fd, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
+  fprintf(fd, "\t\n");
+  fprintf(fd, "\treturn LTT_FACILITY_SYMBOL;\n");
+  fprintf(fd, "}\n");
+  fprintf(fd, "__initcall(facility_init);\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "#else \n");
+  fprintf(fd, "\n");
+  fprintf(fd, "/* Dynamic facility. */\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "static int __init facility_init(void)\n");
+  fprintf(fd, "{\n");
+  fprintf(fd, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init dynamic\\n\");\n", fac->name);
+  fprintf(fd, "\n");
+  fprintf(fd, "\tLTT_FACILITY_SYMBOL = ltt_facility_dynamic_register(&facility);\n");
+  fprintf(fd, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "\treturn LTT_FACILITY_SYMBOL;\n");
+  fprintf(fd, "}\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "static void __exit facility_exit(void)\n");
+  fprintf(fd, "{\n");
+  fprintf(fd, "\tint err;\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "\terr = ltt_facility_dynamic_unregister(LTT_FACILITY_SYMBOL);\n");
+  fprintf(fd, "\tif(err != 0)\n");
+  fprintf(fd, "\t\tprintk(KERN_ERR \"LTT : Error in unregistering facility.\\n\");\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "}\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "module_init(facility_init)\n");
+  fprintf(fd, "module_exit(facility_exit)\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "MODULE_LICENSE(\"GPL\");\n");
+  fprintf(fd, "MODULE_AUTHOR(\"Mathieu Desnoyers\");\n");
+  fprintf(fd, "MODULE_DESCRIPTION(\"Linux Trace Toolkit Facility\");\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "#endif //MODULE\n");
+  fprintf(fd, "\n");
+  fprintf(fd, "#endif //CONFIG_LTT\n");
+
+       fclose(fd);
+
+       return 0;
+}
+
+
+
+/* open facility */
+/* code taken from ltt_facility_open in ltt/facility.c in lttv */
+
+/*****************************************************************************
+ *Function name
+ *             ltt_facility_open                        : open facilities
+ *Input params
+ *             pathname                                                                : the path name of the facility  
+ *
+ *     Open the facility corresponding to the right checksum.
+ * 
+ *returns the facility on success, NULL on error.
+ ****************************************************************************/
+facility_t *ltt_facility_open(char * pathname)
+{
+       int ret = 0;
+       char *token;
+       parse_file_t in;
+       facility_t * fac = NULL;
+       char buffer[BUFFER_SIZE];
+       int generated = FALSE;
+
+       in.buffer = &(buffer[0]);
+       in.lineno = 0;
+       in.error = error_callback;
+       in.name = pathname;
+       in.unget = 0;
+
+       in.fp = fopen(in.name, "r");
+       if(in.fp == NULL) {
+               ret = 1;
+               goto open_error;
+       }
+
+       while(1){
+               token = getToken(&in);
+               if(in.type == ENDFILE) break;
+
+               if(generated) {
+                       printf("More than one facility in the file. Only using the first one.\n");
+                       break;
+               }
+               
+               if(strcmp(token, "<")) in.error(&in,"not a facility file");
+               token = getName(&in);
+
+               if(strcmp("facility",token) == 0) {
+                       fac = malloc(sizeof(facility_t));
+                       fac->name = NULL;
+                       fac->description = NULL;
+                       sequence_init(&(fac->events));
+                       table_init(&(fac->named_types));
+                       sequence_init(&(fac->unnamed_types));
+                       
+                       parseFacility(&in, fac);
+
+                       //check if any namedType is not defined
+                       checkNamedTypesImplemented(&fac->named_types);
+               
+                       generateChecksum(fac->name, &fac->checksum, &fac->events);
+                       
+                       generated = TRUE;
+               }
+               else {
+                       printf("facility token was expected in file %s\n", in.name);
+                       ret = 1;
+                       goto parse_error;
+               }
+       }
+       
+ parse_error:
+       fclose(in.fp);
+open_error:
+
+       if(!generated) {
+               printf("Cannot find facility %s\n", pathname);
+               fac = NULL;
+       }
+
+       return fac;
+}
+
+/* Close the facility */
+void ltt_facility_close(facility_t *fac)
+{
+       free(fac->name);
+       free(fac->capname);
+       free(fac->description);
+       freeEvents(&fac->events);
+       sequence_dispose(&fac->events);
+       freeNamedType(&fac->named_types);
+       table_dispose(&fac->named_types);
+       freeTypes(&fac->unnamed_types);
+       sequence_dispose(&fac->unnamed_types);                  
+       free(fac);
+}
+
+
+/* Show help */
+void show_help(int argc, char ** argv)
+{
+       printf("Genevent help : \n");
+       printf("\n");
+       printf("Use %s name.xml\n", argv[0]);
+       printf("to create :\n");
+       printf("ltt-facility-name.h\n");
+       printf("ltt-facility-id-name.h\n");
+       printf("ltt-facility-loader-name.h\n");
+       printf("ltt-facility-loader-name.c\n");
+       printf("In the current directory.\n");
+       printf("\n");
+}
+
+/* Parse program arguments */
+/* Return values :
+ * 0 : continue program
+ * -1 : stop program, return 0
+ * > 0 : stop program, return value as exit.
+ */
+int check_args(int argc, char **argv)
+{
+       if(argc < 2) {
+               printf("Not enough arguments\n");
+               show_help(argc, argv);
+               return EINVAL;
+       }
+       
+       if(strcmp(argv[1], "-h") == 0) {
+               show_help(argc, argv);
+               return -1;
+       }
+
+       return 0;
+}
+
+int main(int argc, char **argv)
+{
+       int err = 0;
+       facility_t *fac;
+       
+       err = check_args(argc, argv);
+       if(err > 0) return err;
+       else if(err < 0) return 0;
+
+       /* open the facility */
+       fac = ltt_facility_open(argv[1]);
+       if(fac == NULL) {
+               printf("Error opening file %s for reading : %s\n",
+                               argv[1], strerror(errno));
+               return errno;
+       }
+
+       /* generate the output C files */
+
+
+       /* ltt-facility-name.h : main logging header.
+        * log_header */
+       err = print_log_header(fac);
+       if(err) return err;
+
+       /* ltt-facility-id-name.h : facility id.
+        * log_id_header */
+       err = print_id_header(fac);
+       if(err) return err;
+       
+       /* ltt-facility-loader-name.h : facility specific loader info.
+        * loader_header */
+       err = print_loader_header(fac);
+       if(err) return err;
+
+       /* ltt-facility-loader-name.c : generic faciilty loader
+        * loader_c */
+       err = print_loader_c(fac);
+       if(err) return err;
+
+       /* close the facility */
+       ltt_facility_close(fac);
+       
+       return 0;
+}
+
+
diff --git a/genevent-0.3/genevent.h b/genevent-0.3/genevent.h
new file mode 100644 (file)
index 0000000..4515c75
--- /dev/null
@@ -0,0 +1,66 @@
+/******************************************************************************
+ * Genevent
+ *
+ * Event generator. XML to logging C code converter.
+ *
+ * Supports : 
+ *     - C Alignment
+ *     - C types : struct, union, enum, basic types.
+ *     - Architectures : LP32, ILP32, ILP64, LLP64, LP64.
+ *
+ * Additionnal structures supported :
+ *     - embedded variable size strings
+ *     - embedded variable size arrays
+ *     - embedded variable size sequences
+ * 
+ * Notes :
+ * (1)
+ * enums are limited to integer type, as this is what is used in C. Note,
+ * however, that ISO/IEC 9899:TC2 specify that the type of enum can be char,
+ * unsigned int or int. This is implementation defined (compiler). That's why we
+ * add a check for sizeof enum.
+ *
+ * (2)
+ * Because of archtecture defined type sizes, we need to ask for ltt_align
+ * (which gives the alignment) by passing basic types, not their actual sizes.
+ * It's up to ltt_align to determine sizes of types.
+ *
+ * Note that, from
+ * http://www.usenix.org/publications/login/standards/10.data.html
+ * (Andrew Josey <a.josey@opengroup.org>) :
+ *
+ *     Data Type       LP32    ILP32   ILP64   LLP64   LP64
+ *     char    8       8       8       8       8
+ *     short   16      16      16      16      16
+ *     int32                   32
+ *     int     16      32      64      32      32
+ *     long    32      32      64      32      64
+ *     long long (int64)                                       64
+ *     pointer 32      32      64      64      64
+ *
+ * With these constraints :
+ * sizeof(char) <= sizeof(short) <= sizeof(int)
+ *          <= sizeof(long) = sizeof(size_t)
+ * 
+ * and therefore sizeof(long) <= sizeof(pointer) <= sizeof(size_t)
+ *
+ * Which means we only have to remember which is the biggest type in a structure
+ * to know the structure's alignment.
+ */
+
+
+
+/* Code printing */
+
+/* Type size checking */
+int print_check(int fd);
+
+
+/* Print types */
+int print_types(int fd);
+
+/* Print events */
+int print_events(int fd);
+
+
+
diff --git a/genevent-0.3/gentest.c b/genevent-0.3/gentest.c
new file mode 100644 (file)
index 0000000..753ac4d
--- /dev/null
@@ -0,0 +1,485 @@
+
+#define __KERNEL__
+
+#include <assert.h>
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <linux/compiler.h>
+
+#define min(a,b) (((a)<(b))?a:b)
+#define max(a,b) (((a)>(b))?a:b)
+#define BUG_ON(a) assert(!(a))
+
+// Useful outside __KERNEL__. Not used here because inline is already redefined.
+#define force_inline inline __attribute__((always_inline))
+
+/* Calculate the offset needed to align the type */
+static inline unsigned int ltt_align(size_t align_drift,
+                                                                                                                                                size_t size_of_type)
+{
+       size_t alignment = min(sizeof(void*), size_of_type);
+
+       return ((alignment - align_drift) & (alignment-1));
+}
+
+
+/* TEMPLATE */
+
+enum lttng_tasklet_priority {
+       LTTNG_LOW,
+       LTTNG_HIGH,
+};
+
+enum lttng_irq_mode {
+       LTTNG_user,
+       LTTNG_kernel,
+};
+
+struct lttng_mystruct2 {
+       unsigned int irq_id;
+       enum lttng_irq_mode mode;
+       //struct lttng_mystruct teststr1;
+};
+
+#if 0
+static inline size_t lttng_get_size_mystruct2(
+               struct lttng_mystruct2 * obj)
+{
+       size_t size=0, locsize;
+       
+       locsize = sizeof(unsigned int);
+       size += ltt_align(size, locsize) + locsize;
+       
+       locsize = sizeof(enum lttng_irq_mode);
+       size += ltt_align(size, locsize) + locsize;
+
+       BUG_ON(sizeof(struct lttng_mystruct2) != size);
+
+       return sizeof(struct lttng_mystruct2);
+}
+#endif //0
+
+static inline size_t lttng_get_alignment_mystruct2(
+               struct lttng_mystruct2 *obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(unsigned int);
+       align = max(align, localign);
+       
+       localign = sizeof(enum lttng_irq_mode);
+       align = max(align, localign);
+
+       return align;
+}
+
+static inline void lttng_write_mystruct2(
+               void *buffer,
+               size_t *to_base,
+               size_t *to,
+               void **from,
+               size_t *len,
+               struct lttng_mystruct2 *obj)
+{
+       size_t align, size;
+
+       align = lttng_get_alignment_mystruct2(obj);
+       //size = lttng_get_size_mystruct2(obj);
+       size = sizeof(struct lttng_mystruct2);
+
+       if(*len == 0) {
+               *to += ltt_align(*to, align);   /* align output */
+       } else {
+               *len += ltt_align(*to+*len, align);     /* C alignment, ok to do a memcpy of it */
+       }
+       
+       *len += size;
+}
+
+
+
+#define LTTNG_ARRAY_SIZE_mystruct_myarray 10
+typedef uint64_t lttng_array_mystruct_myarray[LTTNG_ARRAY_SIZE_mystruct_myarray];
+
+#if 0
+static inline size_t lttng_get_size_array_mystruct_myarray(
+               lttng_array_mystruct_myarray obj)
+{
+       size_t size=0, locsize;
+       
+       locsize = sizeof(uint64_t);
+       /* ltt_align == 0 always*/
+       //size += ltt_align(size, locsize) + (LTTNG_ARRAY_SIZE_mystruct_myarray * locsize);
+       BUG_ON(ltt_align(size, locsize) != 0);
+       size += LTTNG_ARRAY_SIZE_mystruct_myarray * locsize;
+
+       BUG_ON(sizeof(lttng_array_mystruct_myarray) != size);
+
+       return sizeof(lttng_array_mystruct_myarray);
+}
+#endif //0
+
+static inline size_t lttng_get_alignment_array_mystruct_myarray(
+               lttng_array_mystruct_myarray obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(uint64_t);
+       align = max(align, localign);
+
+       return align;
+}
+
+
+static inline void lttng_write_array_mystruct_myarray(
+               void *buffer,
+               size_t *to_base,
+               size_t *to,
+               void **from,
+               size_t *len,
+               lttng_array_mystruct_myarray obj)
+{
+       size_t align, size;
+       
+       align = lttng_get_alignment_array_mystruct_myarray(obj);
+       //size = lttng_get_size_array_mystruct_myarray(obj);
+       size = sizeof(lttng_array_mystruct_myarray);
+
+       if(*len == 0) {
+               *to += ltt_align(*to, align);   /* align output */
+       } else {
+               *len += ltt_align(*to+*len, align);     /* C alignment, ok to do a memcpy of it */
+       }
+       
+       *len += size;
+#if 0
+       /* For varlen child : let the child align itself. */
+       for(unsigned int i=0; i<LTTNG_ARRAY_SIZE_mystruct_myarray; i++) {
+               lttng_write_child(buffer, to_base, to, from, len, obj[i]);
+       }
+#endif //0
+
+}
+
+
+typedef struct lttng_sequence_mystruct_mysequence lttng_sequence_mystruct_mysequence;
+struct lttng_sequence_mystruct_mysequence {
+       unsigned int len;
+       double *array;
+};
+
+#if 0
+static inline size_t lttng_get_size_sequence_mystruct_mysequence(
+                                                                                                                                lttng_sequence_mystruct_mysequence *obj)
+{
+       size_t size=0, locsize;
+       
+       locsize = sizeof(unsigned int);
+       size += ltt_align(size, locsize) + locsize;
+
+       locsize = sizeof(double);
+       size += ltt_align(size, locsize) + (obj->len * locsize);
+
+       /* Realign on arch size */
+       locsize = sizeof(void *);
+       size += ltt_align(size, locsize);
+
+       return size;
+}
+#endif //0
+
+static inline size_t lttng_get_alignment_sequence_mystruct_mysequence(
+                                                                                                                                lttng_sequence_mystruct_mysequence *obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(unsigned int);
+       align = max(align, localign);
+
+       localign = sizeof(double);
+       align = max(align, localign);
+
+       return align;
+}
+
+
+static inline void lttng_write_sequence_mystruct_mysequence(
+               void *buffer,
+               size_t *to_base,
+               size_t *to,
+               void **from,
+               size_t *len,
+               lttng_sequence_mystruct_mysequence *obj)
+{
+       size_t align;
+       size_t size;
+       
+       /* Flush pending memcpy */
+       if(*len != 0) {
+               if(buffer != NULL)
+                       memcpy(buffer+*to_base+*to, *from, *len);
+       }
+       *to += *len;
+       *len = 0;
+
+       align = lttng_get_alignment_sequence_mystruct_mysequence(obj);
+       //no need size = lttng_get_size_sequence_mystruct_mysequence(obj);
+
+       /* Align output */
+       *to += ltt_align(*to, align);   /* *len = 0 in this function */
+       
+       /* Copy members */
+       size = sizeof(unsigned int);
+       *to += ltt_align(*to, size);
+       if(buffer != NULL)
+               memcpy(buffer+*to_base+*to, &obj->len, size);
+       *to += size;
+
+       size =  sizeof(double);
+       *to += ltt_align(*to, size);
+       size = obj->len * sizeof(double);
+       if(buffer != NULL)
+               memcpy(buffer+*to_base+*to, obj->array, size);
+       *to += size;
+#if 0
+       /* If varlen child : let child align itself */
+       for(unsigned int i=0; i<obj->len; i++) {
+               lttng_write_child(buffer, to_base, to, from, len, obj->array[i]);
+       }
+#endif //0
+       
+
+       /* Realign the *to_base on arch size, set *to to 0 */
+       *to = ltt_align(*to, sizeof(void *));
+       *to_base = *to_base+*to;
+       *to = 0;
+
+       /* Put source *from just after the C sequence */
+       *from = obj+1;
+}
+
+
+
+union lttng_mystruct_myunion {
+       double myfloat;
+       unsigned long myulong;
+};
+
+#if 0
+static inline size_t lttng_get_size_mystruct_myunion(
+                                                                                                                                union lttng_mystruct_myunion *obj)
+{
+       size_t size=0, locsize;
+       
+       locsize = sizeof(double);
+       size = max(size, locsize);
+
+       locsize = sizeof(unsigned long);
+       size = max(size, locsize);
+
+       BUG_ON(size != sizeof(union lttng_mystruct_myunion));
+
+       return sizeof(union lttng_mystruct_myunion);
+}
+#endif //0
+
+static inline size_t lttng_get_alignment_mystruct_myunion(
+                                                                                                                                union lttng_mystruct_myunion *obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(double);
+       align = max(align, localign);
+
+       localign = sizeof(unsigned long);
+       align = max(align, localign);
+
+       return align;
+}
+
+
+static inline void lttng_write_mystruct_myunion(
+               void *buffer,
+               size_t *to_base,
+               size_t *to,
+               void **from,
+               size_t *len,
+               union lttng_mystruct_myunion *obj)
+{
+       size_t align, size;
+       
+       align = lttng_get_alignment_mystruct_myunion(obj);
+       //size = lttng_get_size_mystruct_myunion(obj);
+       size = sizeof(union lttng_mystruct_myunion);
+
+       if(*len == 0) {
+               *to += ltt_align(*to, align);   /* align output */
+       } else {
+               *len += ltt_align(*to+*len, align);     /* C alignment, ok to do a memcpy of it */
+       }
+       
+       *len += size;
+
+       /* Assert : no varlen child. */
+}
+
+
+struct lttng_mystruct {
+       unsigned int irq_id;
+       enum lttng_irq_mode mode;
+       struct lttng_mystruct2 teststr;
+       lttng_array_mystruct_myarray myarray;
+       lttng_sequence_mystruct_mysequence mysequence;
+       union lttng_mystruct_myunion myunion;
+};
+
+#if 0
+static inline size_t lttng_get_size_mystruct(
+               struct lttng_mystruct *obj)
+{
+       size_t size=0, locsize, localign;
+       
+       locsize = sizeof(unsigned int);
+       size += ltt_align(size, locsize) + locsize;
+       
+       locsize = sizeof(enum lttng_irq_mode);
+       size += ltt_align(size, locsize) + locsize;
+
+       localign = lttng_get_alignment_mystruct2(&obj->teststr);
+       locsize = lttng_get_size_mystruct2(&obj->teststr);
+       size += ltt_align(size, localign) + locsize;
+       
+       localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
+       locsize = lttng_get_size_array_mystruct_myarray(obj->myarray);
+       size += ltt_align(size, localign) + locsize;
+       
+       localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
+       locsize = lttng_get_size_sequence_mystruct_mysequence(&obj->mysequence);
+       size += ltt_align(size, localign) + locsize;
+       
+       localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
+       locsize = lttng_get_size_mystruct_myunion(&obj->myunion);
+       size += ltt_align(size, localign) + locsize;
+
+       return size;
+}
+#endif //0
+
+static inline size_t lttng_get_alignment_mystruct(
+               struct lttng_mystruct *obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(unsigned int);
+       align = max(align, localign);
+       
+       localign = sizeof(enum lttng_irq_mode);
+       align = max(align, localign);
+
+       localign = lttng_get_alignment_mystruct2(&obj->teststr);
+       align = max(align, localign);
+       
+       localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
+       align = max(align, localign);
+       
+       localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
+       align = max(align, localign);
+       
+       localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
+       align = max(align, localign);
+
+       return align;
+}
+
+static inline void lttng_write_mystruct(
+               void *buffer,
+               size_t *to_base,
+               size_t *to,
+               void **from,
+               size_t *len,
+               struct lttng_mystruct *obj)
+{
+       size_t align, size;
+       
+       align = lttng_get_alignment_mystruct(obj);
+       // no need : contains variable size fields.
+       // locsize = lttng_get_size_mystruct(obj);
+
+       if(*len == 0) {
+               *to += ltt_align(*to, align);   /* align output */
+       } else {
+               *len += ltt_align(*to+*len, align);     /* C alignment, ok to do a memcpy of it */
+       }
+       
+       /* Contains variable sized fields : must explode the structure */
+       
+       size = sizeof(unsigned int);
+       size += ltt_align(*to+*len, size) + size;
+       *len += size;
+       
+       size = sizeof(enum lttng_irq_mode);
+       size += ltt_align(*to+*len, size) + size;
+       *len += size;
+
+       lttng_write_mystruct2(buffer, to_base, to, from, len, &obj->teststr);
+
+       lttng_write_array_mystruct_myarray(buffer, to_base, to, from, len, obj->myarray);
+
+       /* Variable length field */
+       lttng_write_sequence_mystruct_mysequence(buffer, to_base, to, from, len, &obj->mysequence);
+       /* After this previous write, we are sure that *to is 0, *len is 0 and 
+        * *to_base is aligned on the architecture size : to rest of alignment will
+        * be calculated statically. */
+
+       lttng_write_mystruct_myunion(buffer, to_base, to, from, len, &obj->myunion);
+
+       /* Don't forget to flush last write..... */
+}
+
+
+
+
+
+
+//void main()
+void test()
+{
+       struct lttng_mystruct test;
+       test.mysequence.len = 20;
+       test.mysequence.array = malloc(20);
+
+       //size_t size = lttng_get_size_mystruct(&test);
+       //size_t align = lttng_get_alignment_mystruct(&test);
+       //
+       size_t to_base = 0;     /* the buffer is allocated on arch_size alignment */
+       size_t to = 0;
+       void *from = &test;
+       size_t len = 0;
+
+       /* Get size */
+       lttng_write_mystruct(NULL, &to_base, &to, &from, &len, &test);
+       /* Size = to_base + to + len */
+       
+       void *buffer = malloc(to_base + to + len);
+       to_base = 0;    /* the buffer is allocated on arch_size alignment */
+       to = 0;
+       from = &test;
+       len = 0;
+
+       lttng_write_mystruct(buffer, &to_base, &to, &from, &len, &test);
+       /* Final flush */
+       /* Flush pending memcpy */
+       if(len != 0) {
+               // Assert buffer != NULL */
+               memcpy(buffer+to_base+to, from, len);
+               to += len;
+               from += len;
+               len = 0;
+       }
+       
+       free(test.mysequence.array);
+       free(buffer);
+}
diff --git a/genevent-0.3/ltt-facility-test-template.h b/genevent-0.3/ltt-facility-test-template.h
new file mode 100644 (file)
index 0000000..b5efa41
--- /dev/null
@@ -0,0 +1,551 @@
+#ifndef _LTT_FACILITY_TEST_H_
+#define _LTT_FACILITY_TEST_H_
+
+
+/* Facility activation at compile time. */
+#ifdef CONFIG_LTT_FACILITY_TEST
+
+/* Named types */
+
+
+enum lttng_tasklet_priority {
+       LTTNG_LOW,
+       LTTNG_HIGH,
+};
+
+enum lttng_irq_mode {
+       LTTNG_user,
+       LTTNG_kernel,
+};
+
+struct lttng_mystruct2 {
+       unsigned int irq_id;
+       enum lttng_irq_mode mode;
+       //struct lttng_mystruct teststr1;
+};
+
+
+size_t lttng_get_size_mystruct2(
+               struct lttng_mystruct2 *obj)
+{
+       size_t size=0, locsize;
+       
+       locsize = sizeof(unsigned int);
+       size += ltt_align(size, locsize) + locsize;
+       
+       locsize = sizeof(enum lttng_irq_mode);
+       size += ltt_align(size, locsize) + locsize;
+
+       BUG_ON(sizeof(struct lttng_mystruct2) != size);
+
+       return sizeof(struct lttng_mystruct2);
+}
+
+size_t lttng_get_alignment_mystruct2(
+               struct lttng_mystruct2 *obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(unsigned int);
+       align = max(align, localign);
+       
+       localign = sizeof(enum lttng_irq_mode);
+       align = max(align, localign);
+
+       return align;
+}
+
+void lttng_write_mystruct2(void **to,
+               void **from,
+               size_t *len,
+               struct lttng_mystruct2 *obj)
+{
+       size_t align, size;
+
+       align = lttng_get_alignment_mystruct2(obj);
+       size = lttng_get_size_mystruct2(obj);
+
+       if(*len == 0) {
+               *to += ltt_align((size_t)(*to), align); /* align output */
+       } else {
+               *len += ltt_align((size_t)(*to+*len), align);   /* C alignment, ok to do a memcpy of it */
+       }
+       
+       *len += size;
+}
+
+
+
+#define LTTNG_ARRAY_SIZE_mystruct_myarray 10
+typedef uint64_t lttng_array_mystruct_myarray[LTTNG_ARRAY_SIZE_mystruct_myarray];
+
+size_t lttng_get_size_array_mystruct_myarray(
+               lttng_array_mystruct_myarray obj)
+{
+       size_t size=0, locsize;
+       
+       locsize = sizeof(uint64_t);
+       /* ltt_align == 0 always*/
+       //size += ltt_align(size, locsize) + (LTTNG_ARRAY_SIZE_mystruct_myarray * locsize);
+       BUG_ON(ltt_align(size, locsize) != 0);
+       size += LTTNG_ARRAY_SIZE_mystruct_myarray * locsize;
+
+       BUG_ON(size != LTTNG_ARRAY_SIZE_mystruct_myarray * sizeof(uint64_t));
+
+       return size;
+}
+
+size_t lttng_get_alignment_array_mystruct_myarray(
+               lttng_array_mystruct_myarray obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(uint64_t);
+       align = max(align, localign);
+
+       return align;
+}
+
+
+void lttng_write_array_mystruct_myarray(void **to,
+               void **from,
+               size_t *len,
+               lttng_array_mystruct_myarray obj)
+{
+       size_t align, size;
+       
+       align = lttng_get_alignment_array_mystruct_myarray(obj);
+       size = lttng_get_size_array_mystruct_myarray(obj);
+
+       if(*len == 0) {
+               *to += ltt_align((size_t)(*to), align); /* align output */
+       } else {
+               *len += ltt_align((size_t)(*to+*len), align);   /* C alignment, ok to do a memcpy of it */
+       }
+       
+       *len += size;
+}
+
+
+typedef struct lttng_sequence_mystruct_mysequence lttng_sequence_mystruct_mysequence;
+struct lttng_sequence_mystruct_mysequence {
+       unsigned int len;
+       double *array;
+};
+
+
+size_t lttng_get_size_sequence_mystruct_mysequence(
+                                                                                                                                lttng_sequence_mystruct_mysequence *obj)
+{
+       size_t size=0, locsize;
+       
+       locsize = sizeof(unsigned int);
+       size += ltt_align(size, locsize) + locsize;
+
+       locsize = sizeof(double);
+       size += ltt_align(size, locsize) + (obj->len * locsize);
+
+       return size;
+}
+
+size_t lttng_get_alignment_sequence_mystruct_mysequence(
+                                                                                                                                lttng_sequence_mystruct_mysequence *obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(unsigned int);
+       align = max(align, localign);
+
+       localign = sizeof(double);
+       align = max(align, localign);
+
+       return align;
+}
+
+
+void lttng_write_sequence_mystruct_mysequence(void **to,
+               void **from,
+               size_t *len,
+               lttng_sequence_mystruct_mysequence *obj)
+{
+       size_t align, size;
+       void *varfrom;
+       size_t varlen=0;
+       
+       /* Flush pending memcpy */
+       if(*len != 0) {
+               memcpy(*to, *from, *len);
+               *to += *len;
+               *len = 0;
+       }
+
+       align = lttng_get_alignment_sequence_mystruct_mysequence(obj);
+       //no need size = lttng_get_size_sequence_mystruct_mysequence(obj);
+
+       /* Align output */
+       *to += ltt_align((size_t)(*to), align);
+       
+       /* Copy members */
+       *to += ltt_align((size_t)*to, sizeof(unsigned int));
+       varfrom = &obj->len;
+       varlen += sizeof(unsigned int);
+       memcpy(*to, varfrom, varlen);
+       *to += varlen;
+       varlen = 0;
+
+       *to += ltt_align((size_t)*to, sizeof(double));
+       varfrom = obj->array;
+       varlen += obj->len * sizeof(double);
+       memcpy(*to, varfrom, varlen);
+       *to += varlen;
+       varlen = 0;
+
+       /* Put source *from just after the C sequence */
+       *from = obj+1;
+}
+
+
+
+union lttng_mystruct_myunion {
+       double myfloat;
+       unsigned long myulong;
+};
+
+
+size_t lttng_get_size_mystruct_myunion(
+                                                                                                                                union lttng_mystruct_myunion *obj)
+{
+       size_t size=0, locsize;
+       
+       locsize = sizeof(double);
+       size = max(size, locsize);
+
+       locsize = sizeof(unsigned long);
+       size = max(size, locsize);
+
+       BUG_ON(size != sizeof(union lttng_mystruct_myunion));
+
+       return size;
+}
+
+
+size_t lttng_get_alignment_mystruct_myunion(
+                                                                                                                                union lttng_mystruct_myunion *obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(double);
+       align = max(align, localign);
+
+       localign = sizeof(unsigned long);
+       align = max(align, localign);
+
+       return align;
+}
+
+
+void lttng_write_mystruct_myunion(void **to,
+               void **from,
+               size_t *len,
+               union lttng_mystruct_myunion *obj)
+{
+       size_t align, size;
+       
+       align = lttng_get_alignment_mystruct_myunion(obj);
+       size = lttng_get_size_mystruct_myunion(obj);
+
+       if(*len == 0) {
+               *to += ltt_align((size_t)(*to), align); /* align output */
+       } else {
+               *len += ltt_align((size_t)(*to+*len), align);   /* C alignment, ok to do a memcpy of it */
+       }
+       
+       *len += size;
+}
+
+
+struct lttng_mystruct {
+       unsigned int irq_id;
+       enum lttng_irq_mode mode;
+       struct lttng_mystruct2 teststr;
+       lttng_array_mystruct_myarray myarray;
+       lttng_sequence_mystruct_mysequence mysequence;
+       union lttng_mystruct_myunion myunion;
+};
+
+size_t lttng_get_size_mystruct(
+               struct lttng_mystruct *obj)
+{
+       size_t size=0, locsize, localign;
+       
+       locsize = sizeof(unsigned int);
+       size += ltt_align(size, locsize) + locsize;
+       
+       locsize = sizeof(enum lttng_irq_mode);
+       size += ltt_align(size, locsize) + locsize;
+
+       localign = lttng_get_alignment_mystruct2(&obj->teststr);
+       locsize = lttng_get_size_mystruct2(&obj->teststr);
+       size += ltt_align(size, localign) + locsize;
+       
+       localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
+       locsize = lttng_get_size_array_mystruct_myarray(obj->myarray);
+       size += ltt_align(size, localign) + locsize;
+       
+       localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
+       locsize = lttng_get_size_sequence_mystruct_mysequence(&obj->mysequence);
+       size += ltt_align(size, localign) + locsize;
+       
+       localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
+       locsize = lttng_get_size_mystruct_myunion(&obj->myunion);
+       size += ltt_align(size, localign) + locsize;
+
+       return size;
+}
+
+
+size_t lttng_get_alignment_mystruct(
+               struct lttng_mystruct *obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(unsigned int);
+       align = max(align, localign);
+       
+       localign = sizeof(enum lttng_irq_mode);
+       align = max(align, localign);
+
+       localign = lttng_get_alignment_mystruct2(&obj->teststr);
+       align = max(align, localign);
+       
+       localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
+       align = max(align, localign);
+       
+       localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
+       align = max(align, localign);
+       
+       localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
+       align = max(align, localign);
+
+       return align;
+}
+
+void lttng_write_mystruct(void **to,
+               void **from,
+               size_t *len,
+               struct lttng_mystruct *obj)
+{
+       size_t align, size;
+       
+       align = lttng_get_alignment_mystruct(obj);
+       // no need : contains variable size fields.
+       // locsize = lttng_get_size_mystruct(obj);
+
+       if(*len == 0) {
+               *to += ltt_align((size_t)(*to), align); /* align output */
+       } else {
+               *len += ltt_align((size_t)(*to+*len), align);   /* C alignment, ok to do a memcpy of it */
+       }
+       
+       /* Contains variable sized fields : must explode the structure */
+       
+       size = sizeof(unsigned int);
+       *len += ltt_align((size_t)(*to+*len), size) + size;
+       
+       size = sizeof(enum lttng_irq_mode);
+       *len += ltt_align((size_t)(*to+*len), size) + size;
+
+       lttng_write_mystruct2(to, from, len, &obj->teststr);
+
+       lttng_write_array_mystruct_myarray(to, from, len, obj->myarray);
+
+       /* Variable length field */
+       lttng_write_sequence_mystruct_mysequence(to, from, len, &obj->mysequence);
+       
+       lttng_write_mystruct_myunion(to, from, len, &obj->myunion);
+
+       /* Don't forget to flush last write..... */
+}
+
+
+
+
+/* Event syscall_entry structures */
+
+/* Event syscall_entry logging function */
+static inline void trace_test_syscall_entry(
+               unsigned int syscall_id,
+               void * address)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event syscall_exit structures */
+
+/* Event syscall_exit logging function */
+static inline void trace_test_syscall_exit(
+               void)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event trap_entry structures */
+
+/* Event trap_entry logging function */
+static inline void trace_test_trap_entry(
+               unsigned int trap_id,
+               void * address)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event trap_exit structures */
+
+/* Event trap_exit logging function */
+static inline void trace_test_trap_exit(
+               void)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event soft_irq_entry structures */
+
+/* Event soft_irq_entry logging function */
+static inline void trace_test_soft_irq_entry(
+               void * softirq_id)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event soft_irq_exit structures */
+
+/* Event soft_irq_exit logging function */
+static inline void trace_test_soft_irq_exit(
+               void * softirq_id)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event tasklet_entry structures */
+
+/* Event tasklet_entry logging function */
+static inline void trace_test_tasklet_entry(
+               enum lttng_tasklet_priority priority,
+               void * address,
+               unsigned long data)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event tasklet_exit structures */
+
+/* Event tasklet_exit logging function */
+static inline void trace_test_tasklet_exit(
+               enum lttng_tasklet_priority priority,
+               void * address,
+               unsigned long data)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event irq_entry structures */
+
+/* Event irq_entry logging function */
+static inline void trace_test_irq_entry(
+               unsigned int irq_id,
+               enum lttng_irq_mode mode)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event irq_exit structures */
+
+/* Event irq_exit logging function */
+static inline void trace_test_irq_exit(
+               void)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+/* Event big_array structures */
+union lttng_test_big_array_myarray_b {
+       void * c;
+};
+
+struct lttng_test_big_array_myarray {
+       void * a;
+       union lttng_test_big_array_myarray_b b;
+};
+
+#define LTTNG_ARRAY_SIZE_test_big_array_myarray 2
+typedef struct lttng_test_big_array_myarray lttng_array_test_big_array_myarray[LTTNG_ARRAY_SIZE_test_big_array_myarray];
+
+#define LTTNG_ARRAY_SIZE_test_big_array_myarray 10000
+typedef lttng_array_test_big_array_myarray lttng_array_test_big_array_myarray[LTTNG_ARRAY_SIZE_test_big_array_myarray];
+
+
+/* Event big_array logging function */
+static inline void trace_test_big_array(
+               lttng_array_test_big_array_myarray myarray)
+#ifndef CONFIG_LTT
+{
+}
+#else
+{
+}
+#endif //CONFIG_LTT
+
+
+#endif //CONFIG_LTT_FACILITY_TEST
+
+#endif //_LTT_FACILITY_TEST_H_
diff --git a/genevent-0.3/parser.c b/genevent-0.3/parser.c
new file mode 100644 (file)
index 0000000..921c559
--- /dev/null
@@ -0,0 +1,1554 @@
+/*
+
+parser.c: Generate helper declarations and functions to trace events
+  from an event description file.
+
+           Copyright (C) 2005, Mathieu Desnoyers
+      Copyright (C) 2002, Xianxiu Yang
+      Copyright (C) 2002, Michel Dagenais 
+   This program 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; version 2 of the License.
+
+   This program 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+*/
+
+/* This program reads the ".xml" event definitions input files 
+   and constructs structure for each event.
+   The program uses a very simple tokenizer, called from a hand written
+   recursive descent parser to fill a data structure describing the events.
+   The result is a sequence of events definitions which refer to type
+   definitions.
+
+   A table of named types is maintained to allow refering to types by name
+   when the same type is used at several places. Finally a sequence of
+   all types is maintained to facilitate the freeing of all type 
+   information when the processing of an ".xml" file is finished. */
+
+#include <stdlib.h> 
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <linux/errno.h>  
+#include <assert.h>
+#include <ctype.h>
+
+#include "parser.h"
+
+
+char *intOutputTypes[] = {
+  "int8_t", "int16_t", "int32_t", "int64_t" };
+
+char *uintOutputTypes[] = {
+  "uint8_t", "uint16_t", "uint32_t", "uint64_t" };
+
+char *floatOutputTypes[] = {
+  "undef", "undef", "float", "double" };
+
+
+
+
+/* helper function  */
+void strupper(char *string)
+{
+  char *ptr = string;
+  
+  while(*ptr != '\0') {
+    *ptr = toupper(*ptr);
+               ptr++;
+  }
+}
+
+
+int getSizeindex(unsigned int value)
+{ 
+  switch(value) {
+    case 1:
+      return 0;
+    case 2:
+      return 1;
+    case 4:
+      return 2;
+    case 8:
+      return 3;
+    default:
+      printf("Error : unknown value size %d\n", value);
+      exit(-1);
+  }
+}
+
+/*****************************************************************************
+ *Function name
+ *    getSize    : translate from string to integer
+ *Input params 
+ *    in         : input file handle
+ *Return values  
+ *    size                           
+ *****************************************************************************/
+
+unsigned long long int getSize(parse_file_t *in)
+{
+  char *token;
+
+  token = getToken(in);
+  if(in->type == NUMBER) {
+               return strtoull(token, NULL, 0);
+  }
+  in->error(in,"incorrect size specification");
+  return -1;
+}
+
+/*****************************************************************************
+ *Function name
+ *    error_callback  : print out error info
+ *Input params
+ *    in              : input file handle
+ *    msg             : message to be printed                  
+ ****************************************************************************/
+
+void error_callback(parse_file_t *in, char *msg)
+{
+  if(in)
+    printf("Error in file %s, line %d: %s\n", in->name, in->lineno, msg);
+  else
+    printf("%s\n",msg);
+  assert(0);
+  exit(1);
+}
+
+/*****************************************************************************
+ *Function name
+ *    memAlloc  : allocate memory                    
+ *Input params 
+ *    size      : required memory size               
+ *return value 
+ *    void *    : pointer to allocate memory or NULL 
+ ****************************************************************************/
+
+void * memAlloc(int size)
+{
+  void * addr;
+  if(size == 0) return NULL;
+  addr = malloc(size);
+  if(!addr){
+    printf("Failed to allocate memory");    
+    exit(1);
+  }
+  return addr;   
+}
+
+/*****************************************************************************
+ *Function name
+ *    allocAndCopy : allocate memory and initialize it  
+ *Input params 
+ *    str          : string to be put in memory         
+ *return value 
+ *    char *       : pointer to allocate memory or NULL
+ ****************************************************************************/
+
+char *allocAndCopy(char *str)
+{
+  char * addr;
+  if(str == NULL) return NULL;
+  addr = (char *)memAlloc(strlen(str)+1);
+  strcpy(addr,str);
+  return addr;
+}
+
+/**************************************************************************
+ * Function :
+ *    getTypeAttributes
+ * Description :
+ *    Read the attribute from the input file.
+ *
+ * Parameters :
+ *    in , input file handle.
+ *    t , the type descriptor to fill.
+ *
+ **************************************************************************/
+
+void getTypeAttributes(parse_file_t *in, type_descriptor_t *t,
+                          sequence_t * unnamed_types, table_t * named_types) 
+{
+  char * token;
+
+  t->fmt = NULL;
+  t->size = 0;
+  
+  while(1) {
+    token = getToken(in); 
+    if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+      ungetToken(in);
+      break;
+    }
+    
+    if(!strcmp("format",token)) {
+      getEqual(in);
+      t->fmt = allocAndCopy(getQuotedString(in));
+    //} else if(!strcmp("name",token)) {
+     // getEqual(in);
+     // car = seekNextChar(in);
+     // if(car == EOF) in->error(in,"name was expected");
+     // else if(car == '\"') t->type_name = allocAndCopy(getQuotedString(in));
+     // else t->type_name = allocAndCopy(getName(in));
+    } else if(!strcmp("size",token)) {
+      getEqual(in);
+      t->size = getSize(in);
+    }
+  }
+}
+
+/**************************************************************************
+ * Function :
+ *    getEventAttributes
+ * Description :
+ *    Read the attribute from the input file.
+ *
+ * Parameters :
+ *    in , input file handle.
+ *    ev , the event to fill.
+ *
+ **************************************************************************/
+
+void getEventAttributes(parse_file_t *in, event_t *ev)
+{
+  char * token;
+  char car;
+  
+  ev->name = NULL;
+  ev->per_trace = 0;
+  ev->per_tracefile = 0;
+
+  while(1) {
+    token = getToken(in); 
+    if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+      ungetToken(in);
+      break;
+    }
+
+    if(!strcmp("name",token)) {
+      getEqual(in);
+      car = seekNextChar(in);
+      if(car == EOF) in->error(in,"name was expected");
+      else if(car == '\"') ev->name = allocAndCopy(getQuotedString(in));
+      else ev->name = allocAndCopy(getName(in));
+    } else if(!strcmp("per_trace", token)) {
+      ev->per_trace = 1;
+    } else if(!strcmp("per_tracefile", token)) {
+      ev->per_tracefile = 1;
+    }
+
+  }
+}
+
+/**************************************************************************
+ * Function :
+ *    getFacilityAttributes
+ * Description :
+ *    Read the attribute from the input file.
+ *
+ * Parameters :
+ *    in , input file handle.
+ *    fac , the facility to fill.
+ *
+ **************************************************************************/
+
+void getFacilityAttributes(parse_file_t *in, facility_t *fac)
+{
+  char * token;
+  char car;
+  
+  fac->name = NULL;
+
+  while(1) {
+    token = getToken(in); 
+    if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+      ungetToken(in);
+      break;
+    }
+
+    if(!strcmp("name",token)) {
+      getEqual(in);
+      car = seekNextChar(in);
+      if(car == EOF) in->error(in,"name was expected");
+      else if(car == '\"') fac->name = allocAndCopy(getQuotedString(in));
+      else fac->name = allocAndCopy(getName(in));
+    }
+  }
+}
+
+/**************************************************************************
+ * Function :
+ *    getFieldAttributes
+ * Description :
+ *    Read the attribute from the input file.
+ *
+ * Parameters :
+ *    in , input file handle.
+ *    f , the field to fill.
+ *
+ **************************************************************************/
+
+void getFieldAttributes(parse_file_t *in, field_t *f)
+{
+  char * token;
+  char car;
+
+  f->name = NULL;
+
+  while(1) {
+    token = getToken(in); 
+    if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+      ungetToken(in);
+      break;
+    }
+
+    if(!strcmp("name",token)) {
+      getEqual(in);
+      car = seekNextChar(in);
+      if(car == EOF) in->error(in,"name was expected");
+      else if(car == '\"') f->name = allocAndCopy(getQuotedString(in));
+      else f->name = allocAndCopy(getName(in));
+    }
+  }
+}
+
+char *getNameAttribute(parse_file_t *in)
+{
+  char * token;
+  char *name = NULL;
+  char car;
+  
+  while(1) {
+    token = getToken(in); 
+    if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+      ungetToken(in);
+      break;
+    }
+
+    if(!strcmp("name",token)) {
+      getEqual(in);
+      car = seekNextChar(in);
+      if(car == EOF) in->error(in,"name was expected");
+      else if(car == '\"') name = allocAndCopy(getQuotedString(in));
+      else name = allocAndCopy(getName(in));
+    }
+  }
+  if(name == NULL) in->error(in, "Name was expected");
+  return name;
+  
+}
+
+
+
+//for <label name=label_name value=n format="..."/>, value is an option
+char * getValueStrAttribute(parse_file_t *in)
+{
+  char * token;
+
+  token = getToken(in); 
+  if(strcmp("/",token) == 0){
+    ungetToken(in);
+    return NULL;
+  }
+  
+  if(strcmp("value",token))in->error(in,"value was expected");
+  getEqual(in);
+  token = getToken(in);
+  if(in->type != NUMBER) in->error(in,"number was expected");
+  return token;  
+}
+
+char * getDescription(parse_file_t *in)
+{
+  long int pos;
+  char * token, car, *str;
+
+  pos = ftell(in->fp);
+
+  getLAnglebracket(in);
+  token = getName(in);
+  if(strcmp("description",token)){
+    fseek(in->fp, pos, SEEK_SET);
+    return NULL;
+  }
+  
+  getRAnglebracket(in);
+
+  pos = 0;
+  while((car = getc(in->fp)) != EOF) {
+    if(car == '<') break;
+    if(car == '\0') continue;
+    in->buffer[pos] = car;
+    pos++;
+  }
+  if(car == EOF)in->error(in,"not a valid description");
+  in->buffer[pos] = '\0';
+
+  str = allocAndCopy(in->buffer);
+
+  getForwardslash(in);
+  token = getName(in);
+  if(strcmp("description", token))in->error(in,"not a valid description");
+  getRAnglebracket(in);
+
+  return str;
+}
+
+/*****************************************************************************
+ *Function name
+ *    parseFacility : generate event list  
+ *Input params 
+ *    in            : input file handle          
+ *    fac           : empty facility
+ *Output params
+ *    fac           : facility filled with event list
+ ****************************************************************************/
+
+void parseFacility(parse_file_t *in, facility_t * fac)
+{
+  char * token;
+  event_t *ev;
+  
+  getFacilityAttributes(in, fac);
+  if(fac->name == NULL) in->error(in, "Attribute not named");
+
+  fac->capname = allocAndCopy(fac->name);
+       strupper(fac->capname);
+  getRAnglebracket(in);    
+  
+  fac->description = getDescription(in);
+  
+  while(1){
+    getLAnglebracket(in);    
+
+    token = getToken(in);
+    if(in->type == ENDFILE)
+      in->error(in,"the definition of the facility is not finished");
+
+    if(strcmp("event",token) == 0){
+      ev = (event_t*) memAlloc(sizeof(event_t));
+      sequence_push(&(fac->events),ev);
+      parseEvent(in,ev, &(fac->unnamed_types), &(fac->named_types));    
+    }else if(strcmp("type",token) == 0){
+      parseTypeDefinition(in, &(fac->unnamed_types), &(fac->named_types));
+    }else if(in->type == FORWARDSLASH){
+      break;
+    }else in->error(in,"event or type token expected\n");
+  }
+
+  token = getName(in);
+  if(strcmp("facility",token)) in->error(in,"not the end of the facility");
+  getRAnglebracket(in); //</facility>
+}
+
+/*****************************************************************************
+ *Function name
+ *    parseEvent    : generate event from event definition 
+ *Input params 
+ *    in            : input file handle          
+ *    ev            : new event                              
+ *    unnamed_types : array of unamed types
+ *    named_types   : array of named types
+ *Output params    
+ *    ev            : new event (parameters are passed to it)   
+ ****************************************************************************/
+
+void parseEvent(parse_file_t *in, event_t * ev, sequence_t * unnamed_types, 
+               table_t * named_types) 
+{
+  char *token;
+       field_t *f;
+
+       sequence_init(&(ev->fields));
+  //<event name=eventtype_name>
+  getEventAttributes(in, ev);
+  if(ev->name == NULL) in->error(in, "Event not named");
+  getRAnglebracket(in);  
+
+  //<description>...</description>
+  ev->description = getDescription(in); 
+  
+       int got_end = 0;
+       /* Events can have multiple fields. each field form at least a function
+        * parameter of the logging function. */
+       while(!got_end) {
+               getLAnglebracket(in);
+               token = getToken(in);
+               
+               switch(in->type) {
+               case FORWARDSLASH:      /* </event> */
+                       token = getName(in);
+                       if(strcmp("event",token))in->error(in,"not an event definition");
+                       getRAnglebracket(in);  //</event>
+                       got_end = 1;
+                       break;
+               case NAME: /* a field */
+                       if(strcmp("field",token))in->error(in,"expecting a field");
+                       f = (field_t *)memAlloc(sizeof(field_t));
+                       sequence_push(&(ev->fields),f);
+                       parseFields(in, f, unnamed_types, named_types, 1);
+                       break;
+               default:
+                       in->error(in, "expecting </event> or <field >");
+                       break;
+               }
+       }
+#if 0
+               if(in->type == FORWARDSLASH){ //</event> NOTHING
+                       ev->type = NULL;
+               }else if(in->type == NAME){
+                       if(strcmp("struct",token)==0 || strcmp("typeref",token)==0){
+                               ungetToken(in);
+                               ev->type = parseType(in,NULL, unnamed_types, named_types);
+                               if(ev->type->type != STRUCT && ev->type->type != NONE) 
+               in->error(in,"type must be a struct");     
+                       }else in->error(in, "not a valid type");
+
+                       getLAnglebracket(in);
+                       getForwardslash(in);    
+               }else in->error(in,"not a struct type");
+               getLAnglebracket(in);
+               getForwardslash(in);    
+               token = getName(in);
+               if(strcmp("event",token))in->error(in,"not an event definition");
+               getRAnglebracket(in);  //</event>
+#endif //0
+}
+
+/*****************************************************************************
+ *Function name
+ *    parseField    : get field infomation from buffer 
+ *Input params 
+ *    in            : input file handle
+ *    f             : field
+ *    unnamed_types : array of unamed types
+ *    named_types   : array of named types
+ *    tag                                              : is field surrounded by a <field> </field> tag ?
+ ****************************************************************************/
+
+void parseFields(parse_file_t *in, field_t *f,
+    sequence_t * unnamed_types,
+               table_t * named_types,
+               int tag) 
+{
+  char * token;
+       if(tag) {
+               //<field name=field_name> <description> <type> </field>
+               getFieldAttributes(in, f);
+               if(f->name == NULL) in->error(in, "Field not named");
+               getRAnglebracket(in);
+
+               f->description = getDescription(in);
+       }
+
+  //<int size=...>
+  getLAnglebracket(in);
+  f->type = parseType(in,NULL, unnamed_types, named_types);
+
+       if(tag) {
+               getLAnglebracket(in);
+               getForwardslash(in);
+               token = getName(in);
+               if(strcmp("field",token))in->error(in,"not a valid field definition");
+               getRAnglebracket(in); //</field>
+       }
+}
+
+
+/*****************************************************************************
+ *Function name
+ *    parseType      : get type information, type can be : 
+ *                     Primitive:
+ *                        int(size,fmt); uint(size,fmt); float(size,fmt); 
+ *                        string(fmt); enum(size,fmt,(label1,label2...))
+ *                     Compound:
+ *                        array(arraySize, type); sequence(lengthSize,type)
+ *                       struct(field(name,type,description)...)
+ *                     type name:
+ *                        type(name,type)
+ *Input params 
+ *    in               : input file handle
+ *    inType           : a type descriptor          
+ *    unnamed_types    : array of unamed types
+ *    named_types      : array of named types
+ *Return values  
+ *    type_descriptor* : a type descriptor             
+ ****************************************************************************/
+
+type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, 
+                          sequence_t * unnamed_types, table_t * named_types) 
+{
+  char *token;
+  type_descriptor_t *t;
+       field_t *f;
+
+  if(inType == NULL) {
+    t = (type_descriptor_t *) memAlloc(sizeof(type_descriptor_t));
+    t->type_name = NULL;
+    t->type = NONE;
+    t->fmt = NULL;
+    sequence_push(unnamed_types,t);
+  }
+  else t = inType;
+
+  token = getName(in);
+
+  if(strcmp(token,"struct") == 0) {
+    t->type = STRUCT;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    getRAnglebracket(in); //<struct>
+    getLAnglebracket(in); //<field name=..>
+    token = getToken(in);
+    sequence_init(&(t->fields));
+    while(strcmp("field",token) == 0){
+                       f = (field_t *)memAlloc(sizeof(field_t));
+                       sequence_push(&(t->fields),f);
+
+      parseFields(in, f, unnamed_types, named_types, 1);
+      
+      //next field
+      getLAnglebracket(in);
+      token = getToken(in);    
+    }
+    if(strcmp("/",token))in->error(in,"not a valid structure definition");
+    token = getName(in);
+    if(strcmp("struct",token)!=0)
+      in->error(in,"not a valid structure definition");
+    getRAnglebracket(in); //</struct>
+  }
+  else if(strcmp(token,"union") == 0) {
+    t->type = UNION;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    getRAnglebracket(in); //<union>
+
+    getLAnglebracket(in); //<field name=..>
+    token = getToken(in);
+    sequence_init(&(t->fields));
+    while(strcmp("field",token) == 0){
+                       f = (field_t *)memAlloc(sizeof(field_t));
+                       sequence_push(&(t->fields),f);
+      parseFields(in, f, unnamed_types, named_types, 1);
+      
+      //next field
+      getLAnglebracket(in);
+      token = getToken(in);    
+    }
+    if(strcmp("/",token))in->error(in,"not a valid union definition");
+    token = getName(in);
+    if(strcmp("union",token)!=0)
+      in->error(in,"not a valid union definition");        
+    getRAnglebracket(in); //</union>
+  }
+  else if(strcmp(token,"array") == 0) {
+    t->type = ARRAY;
+    sequence_init(&(t->fields));
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    if(t->size == 0) in->error(in, "Array has empty size");
+    getForwardslash(in);
+    getRAnglebracket(in); //<array size=n>
+
+    //getLAnglebracket(in); //<subtype> 
+               /* subfield */
+               f = (field_t *)memAlloc(sizeof(field_t));
+               sequence_push(&(t->fields),f);
+    parseFields(in, f, unnamed_types, named_types, 0);
+
+    //getLAnglebracket(in); //<type struct> 
+    //t->nested_type = parseType(in, NULL, unnamed_types, named_types);
+
+    getLAnglebracket(in); //</array>
+    getForwardslash(in);
+    token = getName(in);
+    if(strcmp("array",token))in->error(in,"not a valid array definition");
+    getRAnglebracket(in);  //</array>
+  }
+  else if(strcmp(token,"sequence") == 0) {
+    t->type = SEQUENCE;
+    sequence_init(&(t->fields));
+    //getTypeAttributes(in, t, unnamed_types, named_types);
+    //getForwardslash(in);
+    getRAnglebracket(in); //<sequence>
+
+    //getLAnglebracket(in); //<sequence size type> 
+               /* subfield */
+               f = (field_t *)memAlloc(sizeof(field_t));
+               sequence_push(&(t->fields),f);
+    parseFields(in, f, unnamed_types, named_types, 0);
+
+    //getLAnglebracket(in); //<subtype> 
+               /* subfield */
+               f = (field_t *)memAlloc(sizeof(field_t));
+               sequence_push(&(t->fields),f);
+    parseFields(in, f, unnamed_types, named_types, 0);
+
+    //getLAnglebracket(in); //<type sequence> 
+    //t->length_type = parseType(in, NULL, unnamed_types, named_types);
+
+    //getLAnglebracket(in); //<type sequence> 
+
+    //t->nested_type = parseType(in, NULL, unnamed_types, named_types);
+
+    if(t->fields.position < 1) in->error(in, "Sequence has no length type");
+    if(t->fields.position < 2) in->error(in, "Sequence has no subtype");
+               switch(((field_t*)t->fields.array[0])->type->type) {
+                       case UINT_FIXED :
+                       case UCHAR :
+                       case USHORT :
+                       case UINT :
+                       case ULONG :
+                       case SIZE_T :
+                       case OFF_T :
+                               break;
+                       default:
+                               in->error(in, "Wrong length type for sequence");
+               }
+
+    getLAnglebracket(in); //</sequence>
+    getForwardslash(in);
+    token = getName(in);
+    if(strcmp("sequence",token))in->error(in,"not a valid sequence definition");
+    getRAnglebracket(in); //</sequence>
+  }
+  else if(strcmp(token,"enum") == 0) {
+    char * str;
+    int value = -1;
+
+    t->type = ENUM;
+    sequence_init(&(t->labels));
+    sequence_init(&(t->labels_values));
+    sequence_init(&(t->labels_description));
+               t->already_printed = 0;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    //if(t->size == 0) in->error(in, "Sequence has empty size");
+               //Mathieu : we fix enum size to target int size. GCC is always like this.
+               //fox copy optimisation.
+    if(t->size != 0) in->error(in, "Enum has fixed size of target int.");
+               t->size = 0;
+    getRAnglebracket(in);
+
+    //<label name=label1 value=n/>
+    getLAnglebracket(in);
+    token = getToken(in); //"label" or "/"
+    while(strcmp("label",token) == 0){
+      int *label_value = malloc(sizeof(int));
+      
+      str   = allocAndCopy(getNameAttribute(in));      
+      token = getValueStrAttribute(in);
+      
+       sequence_push(&(t->labels),str);
+
+      if(token) value = strtol(token, NULL, 0);
+      else value++;
+
+      *label_value = value;
+      sequence_push(&(t->labels_values), label_value);
+
+      getForwardslash(in);
+      getRAnglebracket(in);
+      
+      //read description if any. May be NULL.
+      str = allocAndCopy(getDescription(in));
+                       sequence_push(&(t->labels_description),str);
+                             
+      //next label definition
+      getLAnglebracket(in);
+      token = getToken(in); //"label" or "/"      
+    }
+    if(strcmp("/",token))in->error(in, "not a valid enum definition");
+    token = getName(in);
+    if(strcmp("enum",token))in->error(in, "not a valid enum definition");
+      getRAnglebracket(in); //</label>
+  }
+  else if(strcmp(token,"int_fixed") == 0) {
+    t->type = INT_FIXED;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    if(t->size == 0) in->error(in, "int has empty size");
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"uint_fixed") == 0) {
+    t->type = UINT_FIXED;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    if(t->size == 0) in->error(in, "uint has empty size");
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"char") == 0) {
+    t->type = CHAR;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+               t->size = 1;
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"uchar") == 0) {
+    t->type = UCHAR;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+               t->size = 1;
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"short") == 0) {
+    t->type = SHORT;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+               t->size = 2;
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"ushort") == 0) {
+    t->type = USHORT;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+               t->size = 2;
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"int") == 0) {
+    t->type = INT;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"uint") == 0) {
+    t->type = UINT;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+
+  else if(strcmp(token,"pointer") == 0) {
+    t->type = POINTER;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"long") == 0) {
+    t->type = LONG;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"ulong") == 0) {
+    t->type = ULONG;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"size_t") == 0) {
+    t->type = SIZE_T;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"ssize_t") == 0) {
+    t->type = SSIZE_T;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"off_t") == 0) {
+    t->type = OFF_T;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"float") == 0) {
+    t->type = FLOAT;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"string") == 0) {
+    t->type = STRING;
+    getTypeAttributes(in, t, unnamed_types, named_types);
+    getForwardslash(in);
+    getRAnglebracket(in); 
+  }
+  else if(strcmp(token,"typeref") == 0){
+    // Must be a named type
+               free(t);
+               sequence_pop(unnamed_types);
+               token = getNameAttribute(in);
+               t = find_named_type(token, named_types);
+               if(t == NULL) in->error(in,"Named referred to must be pre-declared.");
+               getForwardslash(in);  //<typeref name=type_name/>
+               getRAnglebracket(in);
+               return t;
+  }else in->error(in,"not a valid type");
+
+  return t;
+}    
+
+/*****************************************************************************
+ *Function name
+ *    find_named_type     : find a named type from hash table 
+ *Input params 
+ *    name                : type name          
+ *    named_types         : array of named types
+ *Return values  
+ *    type_descriptor *   : a type descriptor                       
+ *****************************************************************************/
+
+type_descriptor_t * find_named_type(char *name, table_t * named_types)
+{ 
+  type_descriptor_t *t;
+
+  t = table_find(named_types,name);
+
+  return t;
+}
+
+type_descriptor_t * create_named_type(char *name, table_t * named_types)
+{
+  type_descriptor_t *t;
+
+       t = (type_descriptor_t *)memAlloc(sizeof(type_descriptor_t));
+       t->type_name = allocAndCopy(name);
+       t->type = NONE;
+       t->fmt = NULL;
+       table_insert(named_types,t->type_name,t);
+       //    table_insert(named_types,allocAndCopy(name),t);
+       return t;
+}
+
+/*****************************************************************************
+ *Function name
+ *    parseTypeDefinition : get type information from type definition 
+ *Input params 
+ *    in                  : input file handle          
+ *    unnamed_types       : array of unamed types
+ *    named_types         : array of named types
+ *****************************************************************************/
+
+void parseTypeDefinition(parse_file_t * in, sequence_t * unnamed_types,
+                        table_t * named_types)
+{
+  char *token;
+  type_descriptor_t *t;
+
+  token = getNameAttribute(in);
+  if(token == NULL) in->error(in, "Type has empty name");
+  t = create_named_type(token, named_types);
+
+  if(t->type != NONE) in->error(in,"redefinition of named type");
+  getRAnglebracket(in); //<type name=type_name>
+  getLAnglebracket(in); //<
+  token = getName(in);
+  //MD ??if(strcmp("struct",token))in->error(in,"not a valid type definition");
+  ungetToken(in);
+  parseType(in,t, unnamed_types, named_types);
+  
+  //</type>
+  getLAnglebracket(in);
+  getForwardslash(in);
+  token = getName(in);
+  if(strcmp("type",token))in->error(in,"not a valid type definition");  
+  getRAnglebracket(in); //</type>
+}
+
+/**************************************************************************
+ * Function :
+ *    getComa, getName, getNumber, getEqual
+ * Description :
+ *    Read a token from the input file, check its type, return it scontent.
+ *
+ * Parameters :
+ *    in , input file handle.
+ *
+ * Return values :
+ *    address of token content.
+ *
+ **************************************************************************/
+
+char *getName(parse_file_t * in) 
+{
+  char *token;
+
+  token = getToken(in);
+  if(in->type != NAME) in->error(in,"Name token was expected");
+  return token;
+}
+
+int getNumber(parse_file_t * in) 
+{
+  char *token;
+
+  token = getToken(in);
+  if(in->type != NUMBER) in->error(in, "Number token was expected");
+  return atoi(token);
+}
+
+char *getForwardslash(parse_file_t * in) 
+{
+  char *token;
+
+  token = getToken(in);
+  //if(in->type != FORWARDSLASH) in->error(in, "forward slash token was expected");
+       /* Mathieu : final / is optional now. */
+  if(in->type != FORWARDSLASH) ungetToken(in);
+
+  return token;
+}
+
+char *getLAnglebracket(parse_file_t * in) 
+{
+  char *token;
+
+  token = getToken(in);
+  if(in->type != LANGLEBRACKET) in->error(in, "Left angle bracket was expected");
+  return token;
+}
+
+char *getRAnglebracket(parse_file_t * in) 
+{
+  char *token;
+
+  token = getToken(in);
+  if(in->type != RANGLEBRACKET) in->error(in, "Right angle bracket was expected");
+  return token;
+}
+
+char *getQuotedString(parse_file_t * in) 
+{
+  char *token;
+
+  token = getToken(in);
+  if(in->type != QUOTEDSTRING) in->error(in, "quoted string was expected");
+  return token;
+}
+
+char * getEqual(parse_file_t *in)
+{
+  char *token;
+
+  token = getToken(in);
+  if(in->type != EQUAL) in->error(in, "equal was expected");
+  return token;
+}
+
+char seekNextChar(parse_file_t *in)
+{
+  char car;
+  while((car = getc(in->fp)) != EOF) {
+    if(!isspace(car)){
+      ungetc(car,in->fp);
+      return car;
+    }
+  }  
+  return EOF;
+}
+
+/******************************************************************
+ * Function :
+ *    getToken, ungetToken
+ * Description :
+ *    Read a token from the input file and return its type and content.
+ *    Line numbers are accounted for and whitespace/comments are skipped.
+ *
+ * Parameters :
+ *    in, input file handle.
+ *
+ * Return values :
+ *    address of token content.
+ *
+ ******************************************************************/
+
+void ungetToken(parse_file_t * in)
+{
+  in->unget = 1;
+}
+
+char *getToken(parse_file_t * in)
+{
+  FILE *fp = in->fp;
+  char car, car1;
+  int pos = 0, escaped;
+
+  if(in->unget == 1) {
+    in->unget = 0;
+    return in->buffer;
+  }
+
+  /* skip whitespace and comments */
+
+  while((car = getc(fp)) != EOF) {
+    if(car == '/') {
+      car1 = getc(fp); 
+      if(car1 == '*') skipComment(in);
+      else if(car1 == '/') skipEOL(in);
+      else { 
+        car1 = ungetc(car1,fp);
+        break;
+      }
+    }
+    else if(car == '\n') in->lineno++;
+    else if(!isspace(car)) break;
+  }
+
+  switch(car) {
+    case EOF:
+      in->type = ENDFILE;
+      break;
+    case '/':
+      in->type = FORWARDSLASH;
+      in->buffer[pos] = car;
+      pos++;
+      break;
+    case '<':
+      in->type = LANGLEBRACKET;
+      in->buffer[pos] = car;
+      pos++;
+      break;
+    case '>':
+      in->type = RANGLEBRACKET;
+      in->buffer[pos] = car;
+      pos++;
+      break;
+    case '=':
+      in->type = EQUAL;
+      in->buffer[pos] = car;
+      pos++;
+      break;
+    case '"':
+      escaped = 0;
+      while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
+        if(car == '\\' && escaped == 0) {
+         in->buffer[pos] = car;
+         pos++;
+          escaped = 1;
+          continue;
+        }
+        if(car == '"' && escaped == 0) break;
+        if(car == '\n' && escaped == 0) {
+          in->error(in, "non escaped newline inside quoted string");
+        }
+        if(car == '\n') in->lineno++;
+        in->buffer[pos] = car;
+        pos++;
+        escaped = 0;
+      }
+      if(car == EOF) in->error(in,"no ending quotemark");
+      if(pos == BUFFER_SIZE) in->error(in, "quoted string token too large");
+      in->type = QUOTEDSTRING;
+      break;
+    default:
+      if(isdigit(car)) {
+        in->buffer[pos] = car;
+        pos++;
+        while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
+          if(!isdigit(car)) {
+            ungetc(car,fp);
+            break;
+          }
+          in->buffer[pos] = car;
+          pos++;
+        }
+       if(car == EOF) ungetc(car,fp);
+        if(pos == BUFFER_SIZE) in->error(in, "number token too large");
+        in->type = NUMBER;
+      }    
+      else if(isalpha(car)) {
+        in->buffer[0] = car;
+        pos = 1;
+        while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
+          if(!(isalnum(car) || car == '_')) {
+            ungetc(car,fp);
+            break;
+          }
+          in->buffer[pos] = car;
+          pos++;
+        }
+       if(car == EOF) ungetc(car,fp);
+        if(pos == BUFFER_SIZE) in->error(in, "name token too large");
+        in->type = NAME;
+      }
+      else in->error(in, "invalid character, unrecognized token");
+  }
+  in->buffer[pos] = 0;
+  return in->buffer;
+}
+
+void skipComment(parse_file_t * in)
+{
+  char car;
+  while((car = getc(in->fp)) != EOF) {
+    if(car == '\n') in->lineno++;
+    else if(car == '*') {
+      car = getc(in->fp);
+      if(car ==EOF) break;
+      if(car == '/') return;
+      ungetc(car,in->fp);
+    }
+  }
+  if(car == EOF) in->error(in,"comment begining with '/*' has no ending '*/'");
+}
+
+void skipEOL(parse_file_t * in)
+{
+  char car;
+  while((car = getc(in->fp)) != EOF) {
+    if(car == '\n') {
+      ungetc(car,in->fp);
+      break;
+    }
+  }
+  if(car == EOF)ungetc(car, in->fp);
+}
+
+/*****************************************************************************
+ *Function name
+ *    checkNamedTypesImplemented : check if all named types have definition
+ ****************************************************************************/
+
+void checkNamedTypesImplemented(table_t * named_types)
+{
+  type_descriptor_t *t;
+  int pos;
+  char str[256];
+
+  for(pos = 0 ; pos < named_types->values.position; pos++) {
+    t = (type_descriptor_t *) named_types->values.array[pos];
+    if(t->type == NONE){
+      sprintf(str,"named type '%s' has no definition",
+          (char*)named_types->keys.array[pos]);
+      error_callback(NULL,str);   
+    }
+  }
+}
+
+
+/*****************************************************************************
+ *Function name
+ *    generateChecksum  : generate checksum for the facility
+ *Input Params
+ *    facName           : name of facility
+ *Output Params
+ *    checksum          : checksum for the facility
+ ****************************************************************************/
+
+void generateChecksum(char* facName,
+    unsigned int * checksum, sequence_t * events)
+{
+  unsigned long crc ;
+  int pos;
+  event_t * ev;
+  unsigned int i;
+
+  crc = crc32(facName);
+  for(pos = 0; pos < events->position; pos++){
+    ev = (event_t *)(events->array[pos]);
+    crc = partial_crc32(ev->name, crc);
+               for(i = 0; i < ev->fields.position; i++) {
+                       field_t *f = (field_t*)ev->fields.array[i];
+      crc = partial_crc32(f->name, crc);
+      crc = getTypeChecksum(crc, f->type);
+               }
+  }
+  *checksum = crc;
+}
+
+/*****************************************************************************
+ *Function name
+ *   getTypeChecksum    : generate checksum by type info
+ *Input Params
+ *    crc               : checksum generated so far
+ *    type              : type descriptor containing type info
+ *Return value          
+ *    unsigned long     : checksum 
+ *****************************************************************************/
+
+unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type)
+{
+  unsigned long crc = aCrc;
+  char * str = NULL, buf[16];
+  int flag = 0, pos;
+  field_t * fld;
+
+  switch(type->type){
+    case INT_FIXED:
+      str = intOutputTypes[getSizeindex(type->size)];
+      break;
+    case UINT_FIXED:
+      str = uintOutputTypes[getSizeindex(type->size)];
+      break;
+    case POINTER:
+      str = allocAndCopy("void *");
+                       flag = 1;
+      break;
+    case CHAR:
+      str = allocAndCopy("signed char");
+                       flag = 1;
+      break;
+    case UCHAR:
+      str = allocAndCopy("unsigned char");
+                       flag = 1;
+      break;
+    case SHORT:
+      str = allocAndCopy("short");
+                       flag = 1;
+      break;
+    case USHORT:
+      str = allocAndCopy("unsigned short");
+                       flag = 1;
+      break;
+    case INT:
+      str = allocAndCopy("int");
+                       flag = 1;
+      break;
+    case UINT:
+      str = allocAndCopy("uint");
+                       flag = 1;
+      break;
+    case LONG:
+      str = allocAndCopy("long");
+                       flag = 1;
+      break;
+    case ULONG:
+      str = allocAndCopy("unsigned long");
+                       flag = 1;
+      break;
+    case SIZE_T:
+      str = allocAndCopy("size_t");
+                       flag = 1;
+      break;
+    case SSIZE_T:
+      str = allocAndCopy("ssize_t");
+                       flag = 1;
+      break;
+    case OFF_T:
+      str = allocAndCopy("off_t");
+                       flag = 1;
+      break;
+    case FLOAT:
+      str = floatOutputTypes[getSizeindex(type->size)];
+      break;
+    case STRING:
+      str = allocAndCopy("string");
+      flag = 1;
+      break;
+    case ENUM:
+      //str = appendString("enum ", uintOutputTypes[getSizeindex(type->size)]);
+      str = allocAndCopy("enum");
+      flag = 1;
+      break;
+    case ARRAY:
+      sprintf(buf,"%zu", type->size);
+      str = appendString("array ",buf);
+      flag = 1;
+      break;
+    case SEQUENCE:
+      str = allocAndCopy("sequence ");
+      flag = 1;
+      break;
+    case STRUCT:
+      str = allocAndCopy("struct");
+      flag = 1;
+      break;
+    case UNION:
+      str = allocAndCopy("union");
+      flag = 1;
+      break;
+    default:
+      error_callback(NULL, "named type has no definition");
+      break;
+  }
+
+  crc = partial_crc32(str,crc);
+  if(flag) free(str);
+
+  if(type->fmt) crc = partial_crc32(type->fmt,crc);
+    
+  if(type->type == ARRAY){
+    crc = getTypeChecksum(crc,((field_t*)type->fields.array[0])->type);
+  } else if(type->type ==SEQUENCE) {
+    crc = getTypeChecksum(crc,((field_t*)type->fields.array[0])->type);
+    crc = getTypeChecksum(crc,((field_t*)type->fields.array[1])->type);
+       } else if(type->type == STRUCT || type->type == UNION){
+    for(pos =0; pos < type->fields.position; pos++){
+      fld = (field_t *) type->fields.array[pos];
+      crc = partial_crc32(fld->name,crc);
+      crc = getTypeChecksum(crc, fld->type);
+    }    
+  }else if(type->type == ENUM){
+    for(pos = 0; pos < type->labels.position; pos++)
+      crc = partial_crc32((char*)type->labels.array[pos],crc);
+  }
+
+  return crc;
+}
+
+
+/* Event type descriptors */
+void freeType(type_descriptor_t * tp)
+{
+  int pos2;
+  field_t *f;
+
+  if(tp->fmt != NULL) free(tp->fmt);
+  if(tp->type == ENUM) {
+    for(pos2 = 0; pos2 < tp->labels.position; pos2++) {
+      free(tp->labels.array[pos2]);
+    }
+    sequence_dispose(&(tp->labels));
+    for(pos2 = 0; pos2 < tp->labels_values.position; pos2++) {
+      free(tp->labels_values.array[pos2]);
+    }
+    sequence_dispose(&(tp->labels_values));
+  }
+  if(tp->type == STRUCT) {
+    for(pos2 = 0; pos2 < tp->fields.position; pos2++) {
+      f = (field_t *) tp->fields.array[pos2];
+      free(f->name);
+      free(f->description);
+      free(f);
+    }
+    sequence_dispose(&(tp->fields));
+  }
+}
+
+void freeNamedType(table_t * t)
+{
+  int pos;
+  type_descriptor_t * td;
+
+  for(pos = 0 ; pos < t->keys.position; pos++) {
+    free((char *)t->keys.array[pos]);
+    td = (type_descriptor_t*)t->values.array[pos];
+    freeType(td);
+    free(td);
+  }
+}
+
+void freeTypes(sequence_t *t) 
+{
+  int pos;
+  type_descriptor_t *tp;
+
+  for(pos = 0 ; pos < t->position; pos++) {
+    tp = (type_descriptor_t *)t->array[pos];
+    freeType(tp);
+    free(tp);
+  }
+}
+
+void freeEvents(sequence_t *t) 
+{
+  int pos;
+  event_t *ev;
+
+  for(pos = 0 ; pos < t->position; pos++) {
+    ev = (event_t *) t->array[pos];
+    free(ev->name);
+    free(ev->description);
+               sequence_dispose(&ev->fields);
+    free(ev);
+  }
+
+}
+
+
+/* Extensible array */
+
+void sequence_init(sequence_t *t) 
+{
+  t->size = 10;
+  t->position = 0;
+  t->array = (void **)memAlloc(t->size * sizeof(void *));
+}
+
+void sequence_dispose(sequence_t *t) 
+{
+  t->size = 0;
+  free(t->array);
+  t->array = NULL;
+}
+
+void sequence_push(sequence_t *t, void *elem) 
+{
+  void **tmp;
+
+  if(t->position >= t->size) {
+    tmp = t->array;
+    t->array = (void **)memAlloc(t->size * 2 * sizeof(void *));
+    memcpy(t->array, tmp, t->size * sizeof(void *));
+    t->size = t->size * 2;
+    free(tmp);
+  }
+  t->array[t->position] = elem;
+  t->position++;
+}
+
+void *sequence_pop(sequence_t *t) 
+{
+  return t->array[t->position--];
+}
+
+
+/* Hash table API, implementation is just linear search for now */
+
+void table_init(table_t *t) 
+{
+  sequence_init(&(t->keys));
+  sequence_init(&(t->values));
+}
+
+void table_dispose(table_t *t) 
+{
+  sequence_dispose(&(t->keys));
+  sequence_dispose(&(t->values));
+}
+
+void table_insert(table_t *t, char *key, void *value) 
+{
+  sequence_push(&(t->keys),key);
+  sequence_push(&(t->values),value);
+}
+
+void *table_find(table_t *t, char *key) 
+{
+  int pos;
+  for(pos = 0 ; pos < t->keys.position; pos++) {
+    if(strcmp((char *)key,(char *)t->keys.array[pos]) == 0)
+      return(t->values.array[pos]);
+  }
+  return NULL;
+}
+
+void table_insert_int(table_t *t, int *key, void *value)
+{
+  sequence_push(&(t->keys),key);
+  sequence_push(&(t->values),value);
+}
+
+void *table_find_int(table_t *t, int *key)
+{
+  int pos;
+  for(pos = 0 ; pos < t->keys.position; pos++) {
+    if(*key == *(int *)t->keys.array[pos])
+      return(t->values.array[pos]);
+  }
+  return NULL;
+}
+
+
+/* Concatenate strings */
+
+char *appendString(char *s, char *suffix) 
+{
+  char *tmp;
+  if(suffix == NULL) return s;
+
+  tmp = (char *)memAlloc(strlen(s) + strlen(suffix) + 1);
+  strcpy(tmp,s);
+  strcat(tmp,suffix);  
+  return tmp;
+}
+
+
diff --git a/genevent-0.3/parser.h b/genevent-0.3/parser.h
new file mode 100644 (file)
index 0000000..21884fb
--- /dev/null
@@ -0,0 +1,226 @@
+#ifndef PARSER_H
+#define PARSER_H
+
+/* Extensible array container */
+
+typedef struct _sequence {
+  int size;
+  int position;
+  void **array;
+} sequence_t;
+
+void sequence_init(sequence_t *t);
+void sequence_dispose(sequence_t *t);
+void sequence_push(sequence_t *t, void *elem);
+void *sequence_pop(sequence_t *t);
+
+
+/* Hash table */
+
+typedef struct _table {
+  sequence_t keys;
+  sequence_t values;
+} table_t;
+
+void table_init(table_t *t);
+void table_dispose(table_t *t);
+void table_insert(table_t *t, char *key, void *value);
+void *table_find(table_t *t, char *key);
+void table_insert_int(table_t *t, int *key, void *value);
+void *table_find_int(table_t *t, int *key);
+
+
+/* Token types */
+
+typedef enum _token_type {
+  ENDFILE,
+  FORWARDSLASH,
+  LANGLEBRACKET,
+  RANGLEBRACKET,
+  EQUAL,
+  QUOTEDSTRING,
+  NUMBER,
+  NAME
+} token_type_t;
+
+
+/* State associated with a file being parsed */
+typedef struct _parse_file {
+  char *name;
+  FILE * fp;
+  int lineno;
+  char *buffer;
+  token_type_t type; 
+  int unget;
+  void (*error) (struct _parse_file *, char *);
+} parse_file_t;
+
+void ungetToken(parse_file_t * in);
+char *getToken(parse_file_t *in);
+char *getForwardslash(parse_file_t *in);
+char *getLAnglebracket(parse_file_t *in);
+char *getRAnglebracket(parse_file_t *in);
+char *getQuotedString(parse_file_t *in);
+char *getName(parse_file_t *in);
+int   getNumber(parse_file_t *in);
+char *getEqual(parse_file_t *in);
+char  seekNextChar(parse_file_t *in);
+
+void skipComment(parse_file_t * in);
+void skipEOL(parse_file_t * in);
+
+/* Some constants */
+
+static const int BUFFER_SIZE = 1024;
+
+
+/* Events data types */
+
+typedef enum _data_type {
+  INT_FIXED,
+  UINT_FIXED,
+       POINTER,
+       CHAR,
+       UCHAR,
+       SHORT,
+       USHORT,
+  INT,
+  UINT,
+       LONG,
+       ULONG,
+       SIZE_T,
+       SSIZE_T,
+       OFF_T,
+  FLOAT,
+  STRING,
+  ENUM,
+  ARRAY,
+  SEQUENCE,
+  STRUCT,
+  UNION,
+  NONE
+} data_type_t;
+
+typedef struct _type_descriptor {
+  char * type_name; //used for named type
+  data_type_t type;
+  char *fmt;
+  size_t size;
+  sequence_t labels; // for enumeration
+  sequence_t labels_values; // for enumeration
+       sequence_t labels_description;
+       int     already_printed;
+  sequence_t fields; // for structure, array and sequence (field_t type)
+} type_descriptor_t;
+
+
+
+/* Fields within types or events */
+typedef struct _field{
+  char *name;
+  char *description;
+  type_descriptor_t *type;
+} field_t;
+
+
+/* Events definitions */
+
+typedef struct _event {  
+  char *name;
+  char *description;
+  //type_descriptor_t *type; 
+       sequence_t fields;      /* event fields */
+  int  per_trace;   /* Is the event able to be logged to a specific trace ? */
+  int  per_tracefile;  /* Must we log this event in a specific tracefile ? */
+} event_t;
+
+typedef struct _facility {
+  char * name;
+       char * capname;
+  char * description;
+  sequence_t events;
+  sequence_t unnamed_types; //FIXME : remove
+  table_t named_types;
+       unsigned int checksum;
+} facility_t;
+
+int getSizeindex(unsigned int value);
+unsigned long long int getSize(parse_file_t *in);
+unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type);
+
+void parseFacility(parse_file_t *in, facility_t * fac);
+void parseEvent(parse_file_t *in, event_t *ev, sequence_t * unnamed_types,
+    table_t * named_types);
+void parseTypeDefinition(parse_file_t *in,
+    sequence_t * unnamed_types, table_t * named_types);
+type_descriptor_t *parseType(parse_file_t *in,
+    type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types);
+void parseFields(parse_file_t *in, field_t *f,
+    sequence_t * unnamed_types,
+               table_t * named_types,
+               int tag);
+void checkNamedTypesImplemented(table_t * namedTypes);
+type_descriptor_t * find_named_type(char *name, table_t * named_types);
+void generateChecksum(char * facName,
+    unsigned int * checksum, sequence_t * events);
+
+
+/* get attributes */
+char * getNameAttribute(parse_file_t *in);
+char * getFormatAttribute(parse_file_t *in);
+int    getSizeAttribute(parse_file_t *in);
+int    getValueAttribute(parse_file_t *in);
+char * getValueStrAttribute(parse_file_t *in);
+
+char * getDescription(parse_file_t *in);
+
+
+/* Dynamic memory allocation and freeing */
+
+void * memAlloc(int size);
+char *allocAndCopy(char * str);
+char *appendString(char *s, char *suffix);
+void freeTypes(sequence_t *t);
+void freeType(type_descriptor_t * td);
+void freeEvents(sequence_t *t);
+void freeNamedType(table_t * t);
+void error_callback(parse_file_t *in, char *msg);
+
+
+//checksum part
+static const unsigned int crctab32[] =
+{
+#include "crc32.tab"
+};
+
+static inline unsigned long
+partial_crc32_one(unsigned char c, unsigned long crc)
+{
+  return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
+}
+
+static inline unsigned long
+partial_crc32(const char *s, unsigned long crc)
+{
+  while (*s)
+    crc = partial_crc32_one(*s++, crc);
+  return crc;
+}
+
+static inline unsigned long
+crc32(const char *s)
+{
+  return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
+}
+
+
+extern char *intOutputTypes[];
+
+extern char *uintOutputTypes[];
+
+extern char *floatOutputTypes[];
+
+
+
+
+#endif // PARSER_H
diff --git a/genevent-0.3/test.xml b/genevent-0.3/test.xml
new file mode 100644 (file)
index 0000000..c6c2f02
--- /dev/null
@@ -0,0 +1,125 @@
+<facility name=test>
+  <description>The kernel facility has events related to kernel execution status.</description>
+
+
+  <type name=tasklet_priority>
+    <enum>
+      <label name=LOW value=0/> <description>Low priority tasklet</description>
+      <label name=HIGH value=1/> <description>High priority tasklet</description>
+    </enum>
+  </type>
+
+  <type name=irq_mode>
+    <enum>
+      <label name=user value=0/> <description>User context</description>
+      <label name=kernel value=1/> <description>Kernel context</description>
+    </enum>
+  </type>
+       
+       <type name=mystruct2>
+               <struct>
+      <field name="irq_id"> <description>IRQ number</description> <uint size=4/> </field>
+      <field name="mode"> <description>Are we executing kernel code</description> <typeref name=irq_mode/> </field>
+               </struct>
+       </type>
+
+       <type name=mystruct>
+               <struct>
+      <field name="irq_id"> <description>IRQ number</description> <uint size=4/> </field>
+      <field name="mode"> <description>Are we executing kernel code</description> <typeref name=irq_mode/> </field>
+                       
+                       <field name="teststr"><typeref name=mystruct2/></field>
+                       <field name="myarray">
+                               <array size=10/>
+                                       <uint_fixed size=8/>
+                               </array>
+                       </field>
+                       <field name="mysequence">
+                               <sequence>
+                                       <uint>
+                                       <float size=8/>
+                               </sequence>
+                       </field>
+                       <field name="myunion">
+                               <union>
+                                       <field name="myfloat"><float size=8/></field>
+                                       <field name="myulong"><ulong></field>
+                               </union>
+                       </field>
+               </struct>
+       </type>
+
+
+
+
+  <event name=syscall_entry>
+    <description>System call entry</description>
+    <field name="syscall_id"> <description>Syscall entry number in entry.S</description> <uint size=1/> </field>
+    <field name="address"> <description>Address from which call was made</description> <pointer/> </field>
+  </event>
+       
+       <event name=syscall_exit>
+    <description>System call exit</description>
+  </event>
+       
+  <event name=trap_entry>
+    <description>Entry in a trap</description>
+    <field name="trap_id"> <description>Trap number</description> <uint size=2/> </field>
+    <field name="address"> <description>Address where trap occured</description> <pointer/> </field>
+  </event>
+
+  <event name=trap_exit>
+  <description>Exit from a trap</description>
+  </event>
+
+  <event name=soft_irq_entry>
+  <description>Soft IRQ entry</description>
+  <field name="softirq_id"> <description>Soft IRQ number</description> <pointer/> </field>
+  </event>
+
+  <event name=soft_irq_exit>
+  <description>Soft IRQ exit</description>
+   <field name="softirq_id"> <description>Soft IRQ number</description> <pointer/> </field>
+  </event>
+
+  <event name=tasklet_entry>
+  <description>Tasklet entry</description>
+  <field name="priority"> <description>Tasklet priority</description> <typeref name=tasklet_priority/> </field>
+  <field name="address"> <description>Tasklet function address</description> <pointer/> </field>
+  <field name="data"> <description>Tasklet data address</description> <ulong/> </field>
+  </event>
+
+  <event name=tasklet_exit>
+  <description>Tasklet exit</description>
+  <field name="priority"> <description>Tasklet priority</description> <typeref name=tasklet_priority/> </field>
+  <field name="address"> <description>Tasklet function address</description> <pointer/> </field>
+  <field name="data"> <description>Tasklet data address</description> <ulong/> </field>
+  </event>
+
+  <event name=irq_entry>
+  <description>Entry in an irq</description>
+  <field name="irq_id"> <description>IRQ number</description> <uint size=4/> </field>
+  <field name="mode"> <description>Are we executing kernel code</description> <typeref name=irq_mode/> </field>
+  </event>
+
+  <event name=irq_exit>
+  <description>Exit from an IRQ</description>
+  </event>
+
+       <event name=big_array>
+       <field name="myarray">
+               <array size=10000>
+                       <array size=2>
+                               <struct>
+                                       <field name=a><pointer></field>
+                                       <field name=b><union>
+                                                                                                       <field name=c><pointer></field>
+                                                                                               </union>
+                                       </field>
+                               </struct>
+                       </array>
+               </array>
+       </field>
+       </event>
+
+</facility>
This page took 0.075319 seconds and 4 git commands to generate.