From 9774b764394b743972738bb2a4dcabe1278d5b20 Mon Sep 17 00:00:00 2001 From: compudj Date: Wed, 27 Jul 2005 22:52:19 +0000 Subject: [PATCH 1/1] genevent with align support git-svn-id: http://ltt.polymtl.ca/svn@987 04897980-b3bd-0310-b5e0-8ef037075253 --- genevent/genevent.c | 19 +++- genevent/parser.c | 249 +++++++++++++++++++++++++++++++++----------- genevent/parser.h | 1 + 3 files changed, 203 insertions(+), 66 deletions(-) diff --git a/genevent/genevent.c b/genevent/genevent.c index 739eee2b..6dfe2431 100644 --- a/genevent/genevent.c +++ b/genevent/genevent.c @@ -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 \n\n", facName); fprintf(fp,"#include \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. diff --git a/genevent/parser.c b/genevent/parser.c index d998c813..7a8a6593 100644 --- a/genevent/parser.c +++ b/genevent/parser.c @@ -37,6 +37,7 @@ This program is distributed in the hope that it will be useful, #include #include #include +#include #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