X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Fparser.c;h=795b3f96f4ba0d5a8be7be6ab666c293c5b2c16b;hb=bf33dd5091178cd0ad175b1914d74056db60e7af;hp=2851188f34ddd6e961ba078f113091e2144b892c;hpb=6cd62ccfe338056a2a7571addbb63e0e16354e86;p=lttv.git diff --git a/ltt/branches/poly/ltt/parser.c b/ltt/branches/poly/ltt/parser.c index 2851188f..795b3f96 100644 --- a/ltt/branches/poly/ltt/parser.c +++ b/ltt/branches/poly/ltt/parser.c @@ -19,9 +19,8 @@ This program is distributed in the hope that it will be useful, Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* This program reads the ".event" event definitions input files - specified as command line arguments and generates corresponding - ".c" and ".h" files required to trace such events in the kernel. +/* 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. @@ -31,18 +30,61 @@ This program is distributed in the hope that it will be useful, 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 ".event" file is finished. */ + information when the processing of an ".xml" file is finished. */ #include #include #include #include #include - +#include +#include #include "parser.h" +static char *intOutputTypes[] = { + "int8_t", "int16_t", "int32_t", "int64_t", "short int", "int", "long int" }; + +static char *uintOutputTypes[] = { + "uint8_t", "uint16_t", "uint32_t", "uint64_t", "unsigned short int", + "unsigned int", "unsigned long int" }; + +static char *floatOutputTypes[] = { + "undef", "undef", "float", "double", "undef", "float", "double" }; + + + + +/* helper function */ +void strupper(char *string) +{ + char *ptr = string; + + while(*ptr != '\0') { + *ptr = toupper(*ptr); + ptr++; + } +} + + +int getSizeindex(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 @@ -52,7 +94,7 @@ This program is distributed in the hope that it will be useful, * size *****************************************************************************/ -int getSize(parse_file *in) +int getSize(parse_file_t *in) { char *token; @@ -80,12 +122,13 @@ int getSize(parse_file *in) * msg : message to be printed ****************************************************************************/ -void error_callback(parse_file *in, char *msg) +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); } @@ -100,7 +143,9 @@ void error_callback(parse_file *in, char *msg) void * memAlloc(int size) { - void *addr = malloc(size); + void * addr; + if(size == 0) return NULL; + addr = malloc(size); if(!addr){ printf("Failed to allocate memory"); exit(1); @@ -119,11 +164,302 @@ void * memAlloc(int size) char *allocAndCopy(char *str) { - char *addr = (char *)memAlloc(strlen(str)+1); + 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) +{ + char * token; + + t->fmt = NULL; + t->size = -1; + t->alignment = 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); + } else if(!strcmp("align",token)) { + getEqual(in); + t->alignment = getNumber(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