summaryrefslogtreecommitdiff
path: root/tools/trace/lib
diff options
context:
space:
mode:
authorNélio Laranjeiro2008-11-23 19:35:46 +0100
committerNélio Laranjeiro2008-11-23 19:35:46 +0100
commit7cb8c5f7096be04cd65ec41a5b8f98d0ae3e890a (patch)
tree55fdb7a143ec50712bc9cfd2c9baed9cc57f6e40 /tools/trace/lib
parentf5f92965f6e0df104686875b82d329a65efedd2a (diff)
tools/trace: First version of the trace creator parser source file.
Diffstat (limited to 'tools/trace/lib')
-rw-r--r--tools/trace/lib/__init__.py0
-rw-r--r--tools/trace/lib/parser.g32
-rw-r--r--tools/trace/lib/traceclass.py43
3 files changed, 75 insertions, 0 deletions
diff --git a/tools/trace/lib/__init__.py b/tools/trace/lib/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tools/trace/lib/__init__.py
diff --git a/tools/trace/lib/parser.g b/tools/trace/lib/parser.g
new file mode 100644
index 00000000..2cee66b5
--- /dev/null
+++ b/tools/trace/lib/parser.g
@@ -0,0 +1,32 @@
+import sys
+
+from traceclass import *
+
+%%
+
+parser TraceParser:
+ ignore: "(#.*?)?\n"
+ token START: "^"
+ token EOF: "$"
+ token EVENT: "[a-zA-Z_]+"
+ token PARAM: "[a-zA-Z_1-9]+"
+ token LENGTH: "[1-2-4]"
+ token STRING: "\".*\""
+ token SPACE: " "
+
+ rule parser: START {{ my_list = list() }}
+ (event {{ my_list.append (event) }}
+ )*
+ EOF {{ return my_list }}
+
+ rule event: "EVENT " EVENT {{ e = TraceEvent(EVENT.strip()) }}
+ SPACE
+ ( param SPACE {{ e.param_add (param[0], param[1]) }}
+ )*
+ ( string {{ e.string_set (string) }}
+ )*
+ "\n" {{ return e }}
+
+ rule param: PARAM SPACE LENGTH {{ return [PARAM.strip(), int(LENGTH.strip())] }}
+
+ rule string: STRING {{ return (STRING.strip()) }}
diff --git a/tools/trace/lib/traceclass.py b/tools/trace/lib/traceclass.py
new file mode 100644
index 00000000..3dd07142
--- /dev/null
+++ b/tools/trace/lib/traceclass.py
@@ -0,0 +1,43 @@
+# Define the trace Param.
+class TraceParam:
+ def __init__ (self, name, length):
+ self.__name = name
+
+ if (length == 0) or (length == 3) or (length > 4):
+ self.__length = 0
+ raise Exception ("Length not permitted")
+ else:
+ self.__length = length
+
+ def name (self):
+ return self.__name
+
+ def length (self):
+ return self.__length
+
+# Defines the Events of the trace module.
+class TraceEvent:
+ def __init__(self, name = ''):
+ self.__name = name
+ self.__param_list = list()
+ self.__string = ""
+
+ def name (self):
+ return self.__name
+
+ def param_add (self, name, length):
+ param = TraceParam (name, length)
+ self.__param_list.append(param)
+
+ def param_get (self, pos):
+ if pos <= len (self.__param_list):
+ return self.__param_list[pos]
+
+ def param_nb (self):
+ return len(self.__param_list)
+
+ def string_set (self, string = ""):
+ self.__string = string
+
+ def string_get (self):
+ return self.__string