summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--volk/gen/volk_arch_defs.py9
-rw-r--r--volk/gen/volk_kernel_defs.py210
-rw-r--r--volk/gen/volk_machine_defs.py70
-rw-r--r--volk/gen/volk_tmpl_utils.py18
-rw-r--r--volk/tmpl/volk_config_fixed.tmpl.h29
-rw-r--r--volk/tmpl/volk_typedefs.tmpl.h32
6 files changed, 361 insertions, 7 deletions
diff --git a/volk/gen/volk_arch_defs.py b/volk/gen/volk_arch_defs.py
index 271fc90c7..6869ef7a9 100644
--- a/volk/gen/volk_arch_defs.py
+++ b/volk/gen/volk_arch_defs.py
@@ -15,10 +15,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import os
-import copy
-
archs = list()
+arch_dict = dict()
class arch_class:
def __init__(self, **kwargs):
@@ -45,6 +43,7 @@ class arch_class:
def register_arch(**kwargs):
arch = arch_class(**kwargs)
archs.append(arch)
+ arch_dict[arch.name] = arch
if arch.alignment > 1:
kwargs['name'] += '_u'
kwargs['alignment'] = 1
@@ -55,6 +54,7 @@ def register_arch(**kwargs):
########################################################################
#TODO skip the XML and put it here
from xml.dom import minidom
+import os
gendir = os.path.dirname(__file__)
archs_xml = minidom.parse(os.path.join(gendir, 'archs.xml')).getElementsByTagName('arch')
for arch_xml in archs_xml:
@@ -68,3 +68,6 @@ for arch_xml in archs_xml:
kwargs[name] = val
except: pass
register_arch(**kwargs)
+
+if __name__ == '__main__':
+ print archs
diff --git a/volk/gen/volk_kernel_defs.py b/volk/gen/volk_kernel_defs.py
new file mode 100644
index 000000000..f598ed3c0
--- /dev/null
+++ b/volk/gen/volk_kernel_defs.py
@@ -0,0 +1,210 @@
+#
+# Copyright 2011-2012 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio 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 3, or (at your option)
+# any later version.
+#
+# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+import os
+import re
+import sys
+import glob
+
+from volk_arch_defs import archs
+
+remove_after_underscore = re.compile("_.*");
+space_remove = re.compile(" ");
+leading_space_remove = re.compile("^ *");
+replace_arch = re.compile(", const char\* arch");
+replace_bracket = re.compile(" {");
+replace_volk = re.compile("volk");
+
+def strip_trailing(tostrip, stripstr):
+ lindex = tostrip.rfind(stripstr)
+ tostrip = tostrip[0:lindex] + tostrip[lindex:len(tostrip)].replace(stripstr, "");
+ return tostrip
+
+srcdir = os.path.dirname(os.path.dirname(__file__))
+hdr_files = glob.glob(os.path.join(srcdir, "include/volk/*.h"))
+
+datatypes = [];
+functions = [];
+
+for line in hdr_files:
+ subline = re.search(".*_(a|u)\.h.*", os.path.basename(line))
+ if subline:
+ subsubline = re.search("(?<=volk_).*", subline.group(0));
+ if subsubline:
+ dtype = remove_after_underscore.sub("", subsubline.group(0));
+ subdtype = re.search("[0-9]+[A-z]+", dtype);
+ if subdtype:
+ datatypes.append(subdtype.group(0));
+
+
+datatypes = set(datatypes);
+
+for line in hdr_files:
+ for dt in datatypes:
+ if dt in line:
+ subline = re.search("(volk_" + dt +"_.*(a|u).*\.h)", line);
+ if subline:
+
+ subsubline = re.search(".+(?=\.h)", subline.group(0));
+ functions.append(subsubline.group(0));
+
+archs_or = "("
+for arch in archs:
+ archs_or = archs_or + arch.name.upper() + "|";
+archs_or = archs_or[0:len(archs_or)-1];
+archs_or = archs_or + ")";
+
+taglist = [];
+fcountlist = [];
+arched_arglist = [];
+retlist = [];
+my_arglist = [];
+my_argtypelist = [];
+for func in functions:
+ tags = [];
+ fcount = [];
+ infile_source = open(os.path.join(srcdir, 'include', 'volk', func + ".h"))
+ begun_name = 0;
+ begun_paren = 0;
+ sourcefile = infile_source.readlines();
+ infile_source.close();
+ for line in sourcefile:
+#FIXME: make it work for multiple #if define()s
+ archline = re.search("^\#if.*?LV_HAVE_" + archs_or + ".*", line);
+ if archline:
+ arch = archline.group(0);
+ archline = re.findall(archs_or + "(?=( |\n|&))", line);
+ if archline:
+ archsublist = [];
+ for tup in archline:
+ archsublist.append(tup[0]);
+ fcount.append(archsublist);
+ testline = re.search("static inline.*?" + func, line);
+ if (not testline):
+ continue
+ tagline = re.search(func + "_.+", line);
+ if tagline:
+ tag = re.search("(?<=" + func + "_)\w+(?= *\()",line);
+ if tag:
+ tag = re.search("\w+", tag.group(0));
+ if tag:
+ tags.append(tag.group(0));
+
+
+ if begun_name == 0:
+ retline = re.search(".+(?=" + func + ")", line);
+ if retline:
+ ret = retline.group(0);
+
+
+
+
+ subline = re.search(func + ".*", line);
+ if subline:
+ subsubline = re.search("\(.*?\)", subline.group(0));
+ if subsubline:
+ args = subsubline.group(0);
+
+ else:
+ begun_name = 1;
+ subsubline = re.search("\(.*", subline.group(0));
+ if subsubline:
+ args = subsubline.group(0);
+ begun_paren = 1;
+ else:
+ if begun_paren == 1:
+ subline = re.search(".*?\)", line);
+ if subline:
+ args = args + subline.group(0);
+ begun_name = 0;
+ begun_paren = 0;
+ else:
+ subline = re.search(".*", line);
+ args = args + subline.group(0);
+ else:
+ subline = re.search("\(.*?\)", line);
+ if subline:
+ args = subline.group(0);
+ begun_name = 0;
+ else:
+ subline = re.search("\(.*", line);
+ if subline:
+ args = subline.group(0);
+ begun_paren = 1;
+
+ replace = re.compile("static ");
+ ret = replace.sub("", ret);
+ replace = re.compile("inline ");
+ ret = replace.sub("", ret);
+ replace = re.compile("\)");
+ arched_args = replace.sub(", const char* arch) {", args);
+
+ remove = re.compile('\)|\(|{');
+ rargs = remove.sub("", args);
+ sargs = rargs.split(',');
+
+
+
+ margs = [];
+ atypes = [];
+ for arg in sargs:
+ temp = arg.split(" ");
+ margs.append(temp[-1]);
+ replace = re.compile(" " + temp[-1]);
+ atypes.append(replace.sub("", arg));
+
+
+ my_args = ""
+ arg_types = ""
+ for arg in range(0, len(margs) - 1):
+ this_arg = leading_space_remove.sub("", margs[arg]);
+ my_args = my_args + this_arg + ", ";
+ this_type = leading_space_remove.sub("", atypes[arg]);
+ arg_types = arg_types + this_type + ", ";
+
+ this_arg = leading_space_remove.sub("", margs[-1]);
+ my_args = my_args + this_arg;
+ this_type = leading_space_remove.sub("", atypes[-1]);
+ arg_types = arg_types + this_type;
+ my_argtypelist.append(arg_types);
+
+ if(ret[-1] != ' '):
+ ret = ret + ' ';
+
+ arched_arglist.append(arched_args); #!!!!!!!!!!!
+ my_arglist.append(my_args) #!!!!!!!!!!!!!!!!!
+ retlist.append(ret);
+ fcountlist.append(fcount);
+ taglist.append(tags);
+
+class kernel_class:
+ def __init__(self, index):
+ self.name = functions[index]
+ self.rettype = retlist[index]
+ self.arglist = my_argtypelist[index]
+
+ def __repr__(self):
+ return self.name
+
+kernels = map(kernel_class, range(len(retlist)))
+
+if __name__ == '__main__':
+ print kernels
diff --git a/volk/gen/volk_machine_defs.py b/volk/gen/volk_machine_defs.py
index e69de29bb..1c879cd50 100644
--- a/volk/gen/volk_machine_defs.py
+++ b/volk/gen/volk_machine_defs.py
@@ -0,0 +1,70 @@
+#
+# Copyright 2012 Free Software Foundation, Inc.
+#
+# 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 3 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, see <http://www.gnu.org/licenses/>.
+#
+
+from volk_arch_defs import arch_dict
+
+machines = list()
+machine_dict = dict()
+
+class machine_class:
+ def __init__(self, name, archs):
+ self.name = name
+ self.archs = list()
+ for arch_name in archs:
+ if not arch_name: continue
+ arch = arch_dict[arch_name]
+ self.archs.append(arch)
+ arch_name += '_u'
+ if arch.alignment > 1 and arch_dict.has_key(arch_name):
+ arch = arch_dict[arch_name]
+ self.archs.append(arch)
+
+ def __repr__(self): return self.name
+
+def register_machine(name, archs):
+ for i, arch_name in enumerate(archs):
+ if '|' in arch_name: #handle special arch names with the '|'
+ for arch_sub in arch_name.split('|'):
+ register_machine(name, archs[:i] + [arch_sub] + archs[i+1:])
+ return
+ machine = machine_class(name=name, archs=archs)
+ machines.append(machine)
+ machine_dict[machine.name] = machine
+
+########################################################################
+# register the machines
+########################################################################
+#TODO skip the XML and put it here
+from xml.dom import minidom
+import os
+gendir = os.path.dirname(__file__)
+machines_xml = minidom.parse(os.path.join(gendir, 'machines.xml')).getElementsByTagName('machine')
+for machine_xml in machines_xml:
+ kwargs = dict()
+ for attr in machine_xml.attributes.keys():
+ kwargs[attr] = machine_xml.attributes[attr].value
+ for node in machine_xml.childNodes:
+ try:
+ name = node.tagName
+ val = machine_xml.getElementsByTagName(name)[0].firstChild.data
+ kwargs[name] = val
+ except: pass
+ kwargs['archs'] = kwargs['archs'].split()
+ register_machine(**kwargs)
+
+if __name__ == '__main__':
+ print machines
diff --git a/volk/gen/volk_tmpl_utils.py b/volk/gen/volk_tmpl_utils.py
index 8b00f2f1f..804cc2f28 100644
--- a/volk/gen/volk_tmpl_utils.py
+++ b/volk/gen/volk_tmpl_utils.py
@@ -22,7 +22,10 @@
import os
import re
+import sys
import volk_arch_defs
+import volk_machine_defs
+import volk_kernel_defs
from Cheetah import Template
def __escape_pre_processor(code):
@@ -31,10 +34,10 @@ def __escape_pre_processor(code):
m = re.match('^(\s*)#(\s*)(\w+)(.*)$', line)
if m:
p0, p1, fcn, stuff = m.groups()
- pponly = fcn in ('include', 'define', 'ifdef', 'ifndef', 'endif', 'elif')
+ conly = fcn in ('include', 'define', 'ifdef', 'ifndef', 'endif', 'elif')
both = fcn in ('if', 'else')
istmpl = '$' in stuff
- if pponly or (both and not istmpl):
+ if conly or (both and not istmpl):
line = '%s\\#%s%s%s'%(p0, p1, fcn, stuff)
out.append(line)
return '\n'.join(out)
@@ -42,10 +45,17 @@ def __escape_pre_processor(code):
def __parse_tmpl(_tmpl, **kwargs):
defs = {
'archs': volk_arch_defs.archs,
+ 'machines': volk_machine_defs.machines,
+ 'kernels': volk_kernel_defs.kernels,
}
defs.update(kwargs)
_tmpl = __escape_pre_processor(_tmpl)
+ _tmpl = """
+
+/* this file was generated by volk template utils, do not edit! */
+
+""" + _tmpl
return str(Template.Template(_tmpl, defs))
-import sys
-print __parse_tmpl(open(sys.argv[1]).read())
+if __name__ == '__main__':
+ print __parse_tmpl(open(sys.argv[1]).read())
diff --git a/volk/tmpl/volk_config_fixed.tmpl.h b/volk/tmpl/volk_config_fixed.tmpl.h
new file mode 100644
index 000000000..e1c01ae77
--- /dev/null
+++ b/volk/tmpl/volk_config_fixed.tmpl.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2011-2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_VOLK_CONFIG_FIXED_H
+#define INCLUDED_VOLK_CONFIG_FIXED_H
+
+#for $i, $arch in enumerate($archs)
+#define LV_$(arch.name.upper()) $i
+#end for
+
+#endif /*INCLUDED_VOLK_CONFIG_FIXED*/
diff --git a/volk/tmpl/volk_typedefs.tmpl.h b/volk/tmpl/volk_typedefs.tmpl.h
new file mode 100644
index 000000000..947cb9ed5
--- /dev/null
+++ b/volk/tmpl/volk_typedefs.tmpl.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2011-2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_VOLK_TYPEDEFS
+#define INCLUDED_VOLK_TYPEDEFS
+
+#include <inttypes.h>
+#include <volk/volk_complex.h>
+
+#for $kern in $kernels
+typedef $kern.rettype (*$(kern.name.replace('volk_', 'p_')))($kern.arglist);
+#end for
+
+#endif /*INCLUDED_VOLK_TYPEDEFS*/