#include "parser.h"
#include "genevent.h"
-
/* Named types may be referenced from anywhere */
facility * fac;
* name : name of event definition file
****************************************************************************/
void generateFile(char *name){
- char *cName, *hName, *tmp;
- FILE * cFp, *hFp;
+ char *loadName, *hName, *tmp, *tmp2;
+ FILE * lFp, *hFp;
int nbEvent;
unsigned long checksum=0;
}else{
tmp = name;
}
-
- cName = appendString(tmp,".c");
- hName = appendString(tmp,".h");
- cFp = fopen(cName,"w");
- if(!cFp){
- printf("Cannot open the file : %s\n",cName);
+
+ loadName = appendString("ltt-facility-loader-", tmp);
+ tmp2 = appendString(loadName,".h");
+ free(loadName);
+ loadName = tmp2;
+ hName = appendString("ltt-facility-", tmp);
+ tmp2 = appendString(hName,".h");
+ free(hName);
+ hName = tmp2;
+ lFp = fopen(loadName,"w");
+ if(!lFp){
+ printf("Cannot open the file : %s\n",loadName);
exit(1);
}
exit(1);
}
- free(cName);
+ free(loadName);
free(hName);
generateChecksum(fac->name, &checksum, &(fac->events));
generateStructFunc(hFp, fac->name,checksum);
fprintf(hFp, "#endif //_LTT_FACILITY_%s_H_\n",fac->capname);
- /* generate .c file, calls to register the facility at init time */
- generateCfile(cFp,fac->name,nbEvent,checksum);
+ /* generate .h file, calls to register the facility at init time */
+ generateLoaderfile(lFp,fac->name,nbEvent,checksum,fac->capname);
fclose(hFp);
- fclose(cFp);
+ fclose(lFp);
}
* hasStrSeq : string or sequence present?
* structCount : struct postfix
****************************************************************************/
+
static void
printStruct(FILE * fp, int len, void ** array, char * name, char * facName,
int * whichTypeFirst, int * hasStrSeq, int * structCount)
fld = (field *)array[pos];
td = fld->type;
if( td->type != STRING && td->type != SEQUENCE &&
- td->type != ARRAY) {
+ td->type != ARRAY) {
if (*whichTypeFirst == 0) {
*whichTypeFirst = 1; //struct first
}
if (flag == 0) {
flag = 1;
- fprintf(fp,"struct %s_%s",
- name, facName);
- if (structCount) {
- fprintf(fp, "_%d {\n",
- ++*structCount);
- } else {
- fprintf(fp, " {\n");
- }
+ fprintf(fp,"struct %s_%s",name, facName);
+ if (structCount) {
+ fprintf(fp, "_%d {\n",++*structCount);
+ } else {
+ fprintf(fp, " {\n");
+ }
}
- fprintf(fp, "\t%s %s; /* %s */\n",
- getTypeStr(td),fld->name,fld->description );
+ fprintf(fp, "\t%s %s; /* %s */\n",
+ getTypeStr(td),fld->name,fld->description );
} else {
- if (*whichTypeFirst == 0) {
+ if (*whichTypeFirst == 0) {
//string or sequence or array first
- *whichTypeFirst = 2;
- }
- (*hasStrSeq)++;
- if(flag) {
- fprintf(fp,"} __attribute__ ((packed));\n\n");
- }
- flag = 0;
+ *whichTypeFirst = 2;
+ }
+ (*hasStrSeq)++;
+ if(flag) {
+ fprintf(fp,"} __attribute__ ((packed));\n\n");
+ }
+ flag = 0;
}
}
fprintf(fp,"enum {\n");
for(pos = 0; pos < type->labels.position; pos++){
fprintf(fp,"\t%s", type->labels.array[pos]);
- if (pos != type->labels.position - 1) fprintf(fp,",\n");
+ if (pos != type->labels.position - 1) fprintf(fp,",");
+ if(type->labels_description.array[pos] != NULL)
+ fprintf(fp,"\t/* %s */\n",type->labels_description.array[pos]);
+ else
+ fprintf(fp,"\n");
}
- fprintf(fp,"\n};\n\n\n");
+ fprintf(fp,"};\n\n\n");
}
/*****************************************************************************
/*****************************************************************************
*Function name
- * generateCfile : generate a .c file
+ * generateLoaderfile: generate a facility loaded .h file
*Input Params
* fp : file to be written to
* facName : name of facility
* nbEvent : number of events in the facility
* checksum : checksum for the facility
****************************************************************************/
-void generateCfile(FILE * fp, char * facName, int nbEvent, unsigned long checksum){
- //will be removed later
- fprintf(fp,"typedef unsigned int trace_facility_t;\n\n");
-
- fprintf(fp,"static unsigned long checksum = %lu;\n\n",checksum);
- fprintf(fp,"/* facility handle */\n");
- fprintf(fp,"trace_facility_t facility_%s;\n\n",facName);
-
- fprintf(fp,"static void __init facility_%s_init(){\n",facName);
- fprintf(fp,"\tfacility_%s = trace_register_facility_by_checksum(\"%s\", checksum,%d);\n",facName,facName,nbEvent);
- fprintf(fp,"}\n\n");
-
- fprintf(fp,"static void __exit facility_%s_exit(){\n",facName);
- fprintf(fp,"}\n\n");
-
- fprintf(fp,"module_init(facility_%s_init);\n",facName);
- fprintf(fp,"module_exit(facility_%s_exit);\n",facName);
+void generateLoaderfile(FILE * fp, char * facName, int nbEvent, unsigned long checksum, char *capname){
+ fprintf(fp, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n",capname);
+ fprintf(fp, "#define _LTT_FACILITY_LOADER_%s_H_\n\n",capname);
+ fprintf(fp,"#include <linux/ltt-facilities.h>\n", facName, checksum);
+ fprintf(fp,"#include <linux/module.h>\n\n", facName, checksum);
+ fprintf(fp,"ltt_facility_t\tltt_facility_%s_%X;\n\n", facName, checksum);
+
+ fprintf(fp,"EXPORT_SYMBOL(ltt_facility_%s_%X);\n\n",facName, checksum);
+ fprintf(fp,"#define LTT_FACILITY_SYMBOL\t\t\t\tltt_facility_%s_%X\n",
+ facName, checksum);
+ fprintf(fp,"#define LTT_FACILITY_CHECKSUM\t\t\t0x%X\n", checksum);
+ fprintf(fp,"#define LTT_FACILITY_NAME\t\t\t\t\t\"%s\"\n", facName);
+ fprintf(fp,"#define LTT_FACILITY_NUM_EVENTS\t\t%d\n\n", nbEvent);
+ fprintf(fp, "#endif //_LTT_FACILITY_LOADER_%s_H_\n",capname);
}