genevent with align support
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Wed, 27 Jul 2005 22:52:19 +0000 (22:52 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Wed, 27 Jul 2005 22:52:19 +0000 (22:52 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@987 04897980-b3bd-0310-b5e0-8ef037075253

genevent/genevent.c
genevent/parser.c
genevent/parser.h

index 739eee2b6ea2ba6024c1bebd28ee4017efec81d3..6dfe2431741ab211a3ca7a6a4900279fcd5a108f 100644 (file)
@@ -268,7 +268,8 @@ void generateEnumEvent(FILE *fp, char *facName, int * nbEvent, unsigned long che
 
 static void
 printStruct(FILE * fp, int len, void ** array, char * name, char * facName,
-       int * whichTypeFirst, int * hasStrSeq, int * structCount)
+       int * whichTypeFirst, int * hasStrSeq, int * structCount,
+       type_descriptor *type)
 {
   int flag = 0;
   int pos;
@@ -313,7 +314,16 @@ printStruct(FILE * fp, int len, void ** array, char * name, char * facName,
   }
 
   if(flag) {
-    fprintf(fp,"} __attribute__ ((packed));\n\n");
+    if(type->alignment == 0)
+      fprintf(fp,"} __attribute__ ((packed));\n\n");
+    else {
+      if(type->alignment != 1 && type->alignment != 2
+          && type->alignment != 4 && type->alignment != 8) {
+        printf("Wrong alignment %i, using packed.\n", type->alignment);
+        fprintf(fp,"} __attribute__ ((packed));\n\n");
+      } else
+        fprintf(fp,"} __attribute__ ((aligned(%i)));\n\n", type->alignment);
+    }
   }
 }
 
@@ -334,6 +344,7 @@ generateTypeDefs(FILE * fp, char *facName)
   fprintf(fp,"#include <linux/ltt/ltt-facility-id-%s.h>\n\n", facName);
   fprintf(fp,"#include <linux/ltt-core.h>\n");
 
+#if 0 //broken
   fprintf(fp, "/****  Basic Type Definitions  ****/\n\n");
 
   for (pos = 0; pos < fac->named_types.values.position; pos++) {
@@ -344,6 +355,7 @@ generateTypeDefs(FILE * fp, char *facName)
     fprintf(fp, "typedef struct _%s %s;\n\n",
             type->type_name, type->type_name);
   }
+#endif //0
 }
 
 
@@ -417,7 +429,8 @@ void generateStructFunc(FILE * fp, char * facName, unsigned long checksum){
     //structure for kernel
     if(ev->type != 0)
       printStruct(fp, ev->type->fields.position, ev->type->fields.array,
-        ev->name, facName, &whichTypeFirst, &hasStrSeq, &structCount);
+        ev->name, facName, &whichTypeFirst, &hasStrSeq, &structCount,
+        ev->type);
 
 
     //trace function : function name and parameters : stub function.
index d998c81381b17672b4bf0caf8de0fd45d03abaa7..7a8a65937b6f47e77adf691cd97d32936e855f77 100644 (file)
@@ -37,6 +37,7 @@ This program is distributed in the hope that it will be useful,
 #include <stdio.h>
 #include <stdarg.h>
 #include <linux/errno.h>  
+#include <assert.h>
 
 
 #include "parser.h"
@@ -114,6 +115,7 @@ void error_callback(parse_file *in, char *msg)
     printf("Error in file %s, line %d: %s\n", in->name, in->lineno, msg);
   else
     printf("%s\n",msg);
+  assert(0);
   exit(1);
 }
 
@@ -158,69 +160,188 @@ char *allocAndCopy(char *str)
 
 /**************************************************************************
  * Function :
- *    getNameAttribute,getFormatAttribute,getSizeAttribute,getValueAttribute 
- *    getValueStrAttribute
+ *    getTypeAttributes
  * Description :
  *    Read the attribute from the input file.
  *
  * Parameters :
  *    in , input file handle.
- *
- * Return values :
- *    address of the attribute.
+ *    t , the type descriptor to fill.
  *
  **************************************************************************/
 
-char * getNameAttribute(parse_file *in)
+void getTypeAttributes(parse_file *in, type_descriptor *t)
 {
-  char * token, car;
-  token = getName(in);
-  if(strcmp("name",token))in->error(in,"name was expected");
-  getEqual(in);
+  char * token;
+  char car;
+
+  t->fmt = NULL;
+  t->size = -1;
+  t->alignment = 0;
   
-  car = seekNextChar(in);
-  if(car == EOF)in->error(in,"name was expected");
-  else if(car == '\"')token = getQuotedString(in);
-  else token = getName(in);
-  return token;
+  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);
+    } else if(!strcmp("align",token)) {
+      getEqual(in);
+      t->alignment = getNumber(in);
+    }
+  }
 }
 
-char * getFormatAttribute(parse_file *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 *in, event *ev)
 {
   char * token;
+  char car;
+  
+  ev->name = NULL;
 
-  //format is an option
-  token = getToken(in); 
-  if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
-    ungetToken(in);
-    return 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 == '\"') ev->name = allocAndCopy(getQuotedString(in));
+      else ev->name = allocAndCopy(getName(in));
+    }
   }
+}
 
-  if(strcmp("format",token))in->error(in,"format was expected");
-  getEqual(in);
-  token = getQuotedString(in);
-  return token;
+/**************************************************************************
+ * Function :
+ *    getFacilityAttributes
+ * Description :
+ *    Read the attribute from the input file.
+ *
+ * Parameters :
+ *    in , input file handle.
+ *    fac , the facility to fill.
+ *
+ **************************************************************************/
+
+void getFacilityAttributes(parse_file *in, facility *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));
+    }
+  }
 }
 
-int getSizeAttribute(parse_file *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 *in, field *f)
 {
   char * token;
-  getName(in);
-  getEqual(in);
+  char car;
+
+  f->name = NULL;
 
-  return getSize(in);
+  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));
+    }
+  }
 }
 
-int getValueAttribute(parse_file *in)
+char *getNameAttribute(parse_file *in)
 {
   char * token;
-  getName(in);
-  getEqual(in);
+  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;
   
-  return getNumber(in);
 }
 
-//for <label name=label_name value=n/>, value is an option
+
+
+//for <label name=label_name value=n format="..."/>, value is an option
 char * getValueStrAttribute(parse_file *in)
 {
   char * token;
@@ -289,7 +410,9 @@ void parseFacility(parse_file *in, facility * fac)
   char * token;
   event *ev;
   
-  fac->name = allocAndCopy(getNameAttribute(in));    
+  getFacilityAttributes(in, fac);
+  if(fac->name == NULL) in->error(in, "Attribute not named");
+
   fac->capname = allocAndCopy(fac->name);
        strupper(fac->capname);
   getRAnglebracket(in);    
@@ -338,7 +461,8 @@ void parseEvent(parse_file *in, event * ev, sequence * unnamed_types,
   type_descriptor *t;
 
   //<event name=eventtype_name>
-  ev->name = allocAndCopy(getNameAttribute(in));
+  getEventAttributes(in, ev);
+  if(ev->name == NULL) in->error(in, "Event not named");
   getRAnglebracket(in);  
 
   //<description>...</descriptio>
@@ -387,7 +511,8 @@ void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types,
   sequence_push(&(t->fields),f);
 
   //<field name=field_name> <description> <type> </field>
-  f->name = allocAndCopy(getNameAttribute(in)); 
+  getFieldAttributes(in, f);
+  if(f->name == NULL) in->error(in, "Field not named");
   getRAnglebracket(in);
 
   f->description = getDescription(in);
@@ -443,6 +568,7 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
 
   if(strcmp(token,"struct") == 0) {
     t->type = STRUCT;
+    getTypeAttributes(in, t);
     getRAnglebracket(in); //<struct>
     getLAnglebracket(in); //<field name=..>
     token = getToken(in);
@@ -462,7 +588,8 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
   }
   else if(strcmp(token,"union") == 0) {
     t->type = UNION;
-    t->size = getSizeAttribute(in);
+    getTypeAttributes(in, t);
+    if(t->size == -1) in->error(in, "Union has empty size");
     getRAnglebracket(in); //<union typecodesize=isize>
 
     getLAnglebracket(in); //<field name=..>
@@ -483,11 +610,12 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
   }
   else if(strcmp(token,"array") == 0) {
     t->type = ARRAY;
-    t->size = getValueAttribute(in);
+    getTypeAttributes(in, t);
+    if(t->size == -1) in->error(in, "Array has empty size");
     getRAnglebracket(in); //<array size=n>
 
     getLAnglebracket(in); //<type struct> 
-    t->nested_type = parseType(in,NULL, unnamed_types, named_types);
+    t->nested_type = parseType(in, NULL, unnamed_types, named_types);
 
     getLAnglebracket(in); //</array>
     getForwardslash(in);
@@ -497,7 +625,8 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
   }
   else if(strcmp(token,"sequence") == 0) {
     t->type = SEQUENCE;
-    t->size = getSizeAttribute(in);
+    getTypeAttributes(in, t);
+    if(t->size == -1) in->error(in, "Sequence has empty size");
     getRAnglebracket(in); //<array lengthsize=isize>
 
     getLAnglebracket(in); //<type struct> 
@@ -515,8 +644,8 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
     sequence_init(&(t->labels));
     sequence_init(&(t->labels_description));
                t->already_printed = 0;
-    t->size = getSizeAttribute(in);
-    t->fmt = allocAndCopy(getFormatAttribute(in));
+    getTypeAttributes(in, t);
+    if(t->size == -1) in->error(in, "Sequence has empty size");
     getRAnglebracket(in);
 
     //<label name=label1 value=n/>
@@ -553,70 +682,63 @@ type_descriptor *parseType(parse_file *in, type_descriptor *inType,
   }
   else if(strcmp(token,"int") == 0) {
     t->type = INT;
-    t->size = getSizeAttribute(in);
-    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getTypeAttributes(in, t);
+    if(t->size == -1) in->error(in, "int has empty size");
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"uint") == 0) {
     t->type = UINT;
-    t->size = getSizeAttribute(in);
-    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getTypeAttributes(in, t);
+    if(t->size == -1) in->error(in, "uint has empty size");
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"pointer") == 0) {
     t->type = POINTER;
-    t->size = 0;
-    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getTypeAttributes(in, t);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"long") == 0) {
     t->type = LONG;
-    t->size = 0;
-    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getTypeAttributes(in, t);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"ulong") == 0) {
     t->type = ULONG;
-    t->size = 0;
-    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getTypeAttributes(in, t);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"size_t") == 0) {
     t->type = SIZE_T;
-    t->size = 0;
-    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getTypeAttributes(in, t);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"ssize_t") == 0) {
     t->type = SSIZE_T;
-    t->size = 0;
-    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getTypeAttributes(in, t);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"off_t") == 0) {
     t->type = OFF_T;
-    t->size = 0;
-    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getTypeAttributes(in, t);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"float") == 0) {
     t->type = FLOAT;
-    t->size = getSizeAttribute(in);
-    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getTypeAttributes(in, t);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"string") == 0) {
     t->type = STRING;
-    t->fmt  = allocAndCopy(getFormatAttribute(in));
+    getTypeAttributes(in, t);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
@@ -680,11 +802,12 @@ void parseTypeDefinition(parse_file * in, sequence * unnamed_types,
   type_descriptor *t;
 
   token = getNameAttribute(in);
+  if(token == NULL) in->error(in, "Type has empty name");
   t = find_named_type(token, named_types);
 
   if(t->type != NONE) in->error(in,"redefinition of named type");
   getRAnglebracket(in); //<type name=type_name>
-  getLAnglebracket(in); //<struct>
+  getLAnglebracket(in); //<
   token = getName(in);
   //MD ??if(strcmp("struct",token))in->error(in,"not a valid type definition");
   ungetToken(in);
index 83777c34c0e544a9141cf698945d3827c44c94db..e75f2b5fcd2a5f18ee6a3a90245a1f361048d441 100644 (file)
@@ -107,6 +107,7 @@ typedef struct _type_descriptor {
        int     already_printed;
   sequence fields; // for structure
   struct _type_descriptor *nested_type; // for array and sequence 
+  int alignment;
 } type_descriptor;
 
 
This page took 0.031141 seconds and 4 git commands to generate.