summaryrefslogtreecommitdiff
path: root/tools/trace/tcreator
diff options
context:
space:
mode:
Diffstat (limited to 'tools/trace/tcreator')
-rw-r--r--tools/trace/tcreator/tcreator.py20
-rw-r--r--tools/trace/tcreator/template.c29
-rw-r--r--tools/trace/tcreator/template.h16
-rw-r--r--tools/trace/tcreator/writer.py78
4 files changed, 101 insertions, 42 deletions
diff --git a/tools/trace/tcreator/tcreator.py b/tools/trace/tcreator/tcreator.py
index d0d8807c..45778ace 100644
--- a/tools/trace/tcreator/tcreator.py
+++ b/tools/trace/tcreator/tcreator.py
@@ -7,20 +7,18 @@ except:
print "--> You should run yapps on lib/parser.g"
class TCreator:
- def __init__(self, infile, outfile, enum_name = "trace_id_t"):
+ def __init__(self, infile):
self.__infile = infile
- self.__outfile = outfile
- self.__enum_name = enum_name
- def create (self):
+ def create (self, outfile):
infile = open (self.__infile, 'r')
data = parse ('parser', infile.read())
infile.close()
-
- w = Writer (self.__outfile, self.__enum_name)
- outstring = w.parse_list (data)
-
- if self.__outfile != None:
- w.write_file (outstring)
+ w = Writer ()
+ id_table = w.parse_event_identifiers (data)
+ string_table = w.parse_event_string (data)
+ string_table_nb = str (len (data))
+ if outfile:
+ w.write_file (id_table, string_table, string_table_nb)
else:
- w.print_file (outstring)
+ w.print_file (id_table, string_table, string_table_nb)
diff --git a/tools/trace/tcreator/template.c b/tools/trace/tcreator/template.c
new file mode 100644
index 00000000..d3f4eaec
--- /dev/null
+++ b/tools/trace/tcreator/template.c
@@ -0,0 +1,29 @@
+/* events.c */
+/* avr.trace - AVR TRACE use. {{{
+ *
+ * Copyright (C) 2010 APBTeam
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ *
+ * }}} */
+#include "modules/trace/events.h"
+
+char *trace_table[%%NB%%] = {
+%%DATA%%
+};
diff --git a/tools/trace/tcreator/template.h b/tools/trace/tcreator/template.h
index 3e83692e..aa62d8eb 100644
--- a/tools/trace/tcreator/template.h
+++ b/tools/trace/tcreator/template.h
@@ -1,6 +1,6 @@
-#ifndef %%template%%
-#define %%template%%
-/* %%template%% */
+#ifndef events_h
+#define events_h
+/* trace_events_h */
/* {{{
*
* Copyright (C) %%year%% APBTeam
@@ -25,9 +25,13 @@
*
* }}} */
-enum %%enum_name%%
+enum trace_id_t
{
-%%data%%
+%%ids%%
};
-#endif /* %%template%% */
+#ifndef HOST
+extern char *trace_table[%%NB%%];
+#endif /* !HOST */
+
+#endif /* events_h */
diff --git a/tools/trace/tcreator/writer.py b/tools/trace/tcreator/writer.py
index 8e6d70b3..db5fc21e 100644
--- a/tools/trace/tcreator/writer.py
+++ b/tools/trace/tcreator/writer.py
@@ -9,45 +9,73 @@ templatedir = os.path.split (__file__)[0]
class Writer:
"""Template writer"""
- def __init__ (self, name, enum_name):
- self.__name = name
- self.__enum_name = enum_name
+ def __init__ (self):
+ self.__header_name = "events.h"
+ self.__file_name = "events.host.c"
- def parse_list (self, event_list = None):
+ def parse_event_identifiers (self, event_list = None):
+ """Parse the event list and construct a string to embedded in a
+ header file."""
if event_list != None:
string = ""
+ prefix = " "
for i in range (0, len (event_list)):
- string += " TRACE_" + event_list[i].name() + ",\n"
- string += " TRACE_NB"
+ string += prefix + "TRACE_" + event_list[i].name() + ",\n"
+ string += prefix + "TRACE_NB"
return string.upper()
- def __read_template__ (self, string):
+ def __parse_event_string_cb (self, event):
+ """Create a default string interpretation for callbacks events."""
+ assert event.callback
+ string = "\"" + event.name ()
+ for i in range (event.param_nb ()):
+ string += " %d"
+ string += "\\n\","
+ return string
+
+ def parse_event_string (self, event_list = None):
+ """Parse the event list and construct a string containing on each line
+ the string interpretation for a human."""
+ if event_list != None:
+ string = ""
+ prefix = " "
+ for i in event_list:
+ if i.callback:
+ string += prefix + self.__parse_event_string_cb (i)
+ else:
+ string += prefix + i.string_get () + ",\n"
+ return string
+
+ def __read_template_header (self, string, string_nb):
f = open (templatedir + '/template.h', 'r')
template = f.read()
f.close()
-
- if self.__name != None:
- define = self.__name.replace('.', '_')
- else:
- define = "trace.h"
- template = template.replace('%%template%%', define)
-
- if self.__enum_name == None:
- template = template.replace('%%enum_name%%', "trace_id_t")
- else:
- template = template.replace('%%enum_name%%', self.__enum_name)
-
- template = template.replace('%%data%%', string)
+ template = template.replace('%%ids%%', string)
template = template.replace('%%year%%', time.strftime ('%Y'))
+ template = template.replace('%%NB%%', string_nb);
return template
+ def __read_template_file (self, string_table, string_nb):
+ f = open (templatedir + '/template.c', 'r')
+ template = f.read()
+ f.close()
+ template = template.replace('%%NB%%', string_nb);
+ template = template.replace('%%DATA%%', string_table)
+ return template
- def write_file (self, string):
- template = self.__read_template__(string)
- f = open (self.__name, 'w')
+ def __write (self, template, outfile):
+ f = open (outfile, 'w')
f.write (template)
f.close()
- def print_file (self, string):
- template = self.__read_template__(string)
+ def write_file (self, id_table, string_table, string_table_nb):
+ template = self.__read_template_header (id_table, string_table_nb)
+ self.__write (template, self.__header_name)
+ template = self.__read_template_file (string_table, string_table_nb)
+ self.__write (template, self.__file_name)
+
+ def print_file (self, id_table, string_table, string_table_nb):
+ template = self.__read_template_header (id_table, string_table_nb)
+ print template
+ template = self.__read_template_file (string_table, string_table_nb)
print template