summaryrefslogtreecommitdiff
path: root/volk/python
diff options
context:
space:
mode:
Diffstat (limited to 'volk/python')
-rw-r--r--volk/python/volk_modtool/CMakeLists.txt39
-rw-r--r--volk/python/volk_modtool/README110
-rw-r--r--volk/python/volk_modtool/__init__.py24
-rw-r--r--volk/python/volk_modtool/cfg.py82
-rwxr-xr-xvolk/python/volk_modtool/volk_modtool127
-rw-r--r--volk/python/volk_modtool/volk_modtool_generate.py310
6 files changed, 692 insertions, 0 deletions
diff --git a/volk/python/volk_modtool/CMakeLists.txt b/volk/python/volk_modtool/CMakeLists.txt
new file mode 100644
index 0000000000..6fb87f2668
--- /dev/null
+++ b/volk/python/volk_modtool/CMakeLists.txt
@@ -0,0 +1,39 @@
+# Copyright 2013 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.
+
+########################################################################
+# Install python files and apps
+########################################################################
+include(GrPython)
+
+GR_PYTHON_INSTALL(
+ FILES
+ __init__.py
+ cfg.py
+ volk_modtool_generate.py
+ DESTINATION ${GR_PYTHON_DIR}/volk_modtool
+ COMPONENT "volk"
+)
+
+GR_PYTHON_INSTALL(
+ PROGRAMS
+ volk_modtool
+ DESTINATION ${GR_RUNTIME_DIR}
+ COMPONENT "volk"
+)
diff --git a/volk/python/volk_modtool/README b/volk/python/volk_modtool/README
new file mode 100644
index 0000000000..2532e1a86a
--- /dev/null
+++ b/volk/python/volk_modtool/README
@@ -0,0 +1,110 @@
+The volk_modtool tool is installed along with VOLK as a way of helping
+to construct, add to, and interogate the VOLK library or companion
+libraries.
+
+volk_modtool is installed into $prefix/bin.
+
+VOLK modtool enables creating standalone (out-of-tree) VOLK modules
+and provides a few tools for sharing VOLK kernels between VOLK
+modules. If you need to design or work with VOLK kernels away from
+the canonical VOLK library, this is the tool. If you need to tailor
+your own VOLK library for whatever reason, this is the tool.
+
+The canonical VOLK library installs a volk.h and a libvolk.so. Your
+own library will install volk_$name.h and libvolk_$name.so. Ya Gronk?
+Good.
+
+There isn't a substantial difference between the canonical VOLK
+module and any other VOLK module. They're all peers. Any module
+created via VOLK modtool will come complete with a default
+volk_modtool.cfg file associating the module with the base from which
+it came, its distinctive $name and its destination (or path). These
+values (created from user input if VOLK modtool runs without a
+user-supplied config file or a default config file) serve as default
+values for some VOLK modtool actions. It's more or less intended for
+the user to change directories to the top level of a created VOLK
+module and then run volk_modtool to take advantage of the values
+stored in the default volk_modtool.cfg file.
+
+Apart from creating new VOLK modules, VOLK modtool allows you to list
+the names of kernels in other modules, list the names of kernels in
+the current module, add kernels from another module into the current
+module, and remove kernels from the current module. When moving
+kernels between modules, VOLK modtool does its best to keep the qa
+and profiling code for those kernels intact. If the base has a test
+or a profiling call for some kernel, those calls will follow the
+kernel when VOLK modtool adds that kernel. If QA or profiling
+requires a puppet kernel, the puppet kernel will follow the original
+kernel when VOLK modtool adds that original kernel. VOLK modtool
+respects puppets.
+
+======================================================================
+
+Installing a new VOLK Library:
+
+Run the command "volk_modtool -i". This will ask you three questions:
+
+ name: // the name to give your VOLK library: volk_<name>
+ destination: // directory new source tree is built under -- must exists.
+ // It will create <directory>/volk_<name>
+ base: // the directory containing the original VOLK source code
+
+This will build a new skeleton directory in the destination provided
+with the name volk_<name>. It will contain the necessary structure to
+build:
+
+ mkdir build
+ cd build
+ cmake -DCMAKE_INSTALL_PREFIX=/opt/volk ../
+ make
+ sudo make install
+
+Right now, the library is empty and contains no kernels. Kernels can
+be added from another VOLK library using the '-a' option. If not
+specified, the kernel will be extracted from the base VOLK
+directory. Using the '-b' allows us to specify another VOLK library to
+use for this purpose.
+
+ volk_modtool -a -n 32fc_x2_conjugate_dot_prod_32fc
+
+This will put the code for the new kernel into
+<destination>/volk_<name>/kernels/volk_<name>/
+
+Other kernels must be added by hand. See the following webpages for
+more information about creating VOLK kernels:
+ http://gnuradio.org/doc/doxygen/volk_guide.html
+ http://gnuradio.org/redmine/projects/gnuradio/wiki/Volk
+
+
+======================================================================
+
+OPTIONS
+
+Options for Adding and Removing Kernels:
+ -a, --add_kernel
+ Add kernel from existing VOLK module. Uses the base VOLK module
+ unless -b is used. Use -n to specify the kernel name.
+ Requires: -n.
+ Optional: -b
+
+ -A, --add_all_kernels
+ Add all kernels from existing VOLK module. Uses the base VOLK
+ module unless -b is used.
+ Optional: -b
+
+ -x, --remove_kernel
+ Remove kernel from module.
+ Required: -n.
+ Optional: -b
+
+Options for Listing Kernels:
+ -l, --list
+ Lists all kernels available in the base VOLK module.
+
+ -k, --kernels
+ Lists all kernels in this VOLK module.
+
+ -r, --remote-list
+ Lists all kernels in another VOLK module that is specified
+ using the -b option.
+
diff --git a/volk/python/volk_modtool/__init__.py b/volk/python/volk_modtool/__init__.py
new file mode 100644
index 0000000000..6ddf48da05
--- /dev/null
+++ b/volk/python/volk_modtool/__init__.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+#
+# Copyright 2013 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.
+#
+
+from cfg import volk_modtool_config
+from volk_modtool_generate import volk_modtool
diff --git a/volk/python/volk_modtool/cfg.py b/volk/python/volk_modtool/cfg.py
new file mode 100644
index 0000000000..c5cfb919c0
--- /dev/null
+++ b/volk/python/volk_modtool/cfg.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+#
+# Copyright 2013 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 ConfigParser
+import sys
+import os
+import exceptions
+import re
+
+
+class volk_modtool_config:
+ def verify(self):
+ for i in self.verification:
+ self.verify_section(i)
+
+ def verify_section(self, section):
+ stuff = self.cfg.items(section[0])
+ for i in range(len(section[1])):
+ if not eval(re.sub('\$' + str(i), stuff[i][1], section[1][i])):
+ raise exceptions.IOError('bad configuration... key:%s, val:%s'%(stuff[i][0], stuff[i][1]))
+
+ def __init__(self, cfg=None):
+ self.config_name = 'config'
+ self.config_defaults = ['name', 'destination', 'base']
+ self.config_defaults_verify = ['re.match(\'[a-zA-Z0-9]+$\', \'$0\')',
+ 'os.path.exists(\'$1\')', 'os.path.exists(\'$2\')']
+ self.verification = [(self.config_name, self.config_defaults_verify)]
+ default = os.path.join(os.getcwd(), 'volk_modtool.cfg')
+ icfg = ConfigParser.RawConfigParser()
+ if cfg:
+ icfg.read(cfg)
+ elif os.path.exists(default):
+ icfg.read(default)
+ else:
+ print "Initializing config file..."
+ icfg.add_section(self.config_name)
+ for kn in self.config_defaults:
+ rv = raw_input("%s: "%(kn))
+ icfg.set(self.config_name, kn, rv)
+ self.cfg = icfg
+ self.verify()
+
+
+ def read_map(self, name, inp):
+ if self.cfg.has_section(name):
+ self.cfg.remove_section(name)
+ self.cfg.add_section(name)
+ for i in inp:
+ self.cfg.set(name, i, inp[i])
+
+ def get_map(self, name):
+ retval = {}
+ stuff = self.cfg.items(name)
+ for i in stuff:
+ retval[i[0]] = i[1]
+ return retval
+
+
+
+
+
+
+
diff --git a/volk/python/volk_modtool/volk_modtool b/volk/python/volk_modtool/volk_modtool
new file mode 100755
index 0000000000..fbacc7139b
--- /dev/null
+++ b/volk/python/volk_modtool/volk_modtool
@@ -0,0 +1,127 @@
+#!/usr/bin/env python
+#
+# Copyright 2013 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.
+#
+
+from volk_modtool import volk_modtool, volk_modtool_config
+from optparse import OptionParser, OptionGroup
+
+import exceptions
+import os
+
+if __name__ == '__main__':
+ parser = OptionParser();
+ actions = OptionGroup(parser, 'Actions');
+ actions.add_option('-i', '--install', action='store_true',
+ help='Create a new volk module.')
+ parser.add_option('-b', '--base_path', action='store', default=None,
+ help='Base path for action. By default, volk_modtool.cfg loads this value.')
+ parser.add_option('-n', '--kernel_name', action='store', default=None,
+ help='Kernel name for action. No default')
+ parser.add_option('-c', '--config', action='store', dest='config_file', default=None,
+ help='Config file for volk_modtool. By default, volk_modtool.cfg in the local directory will be used/created.')
+ actions.add_option('-a', '--add_kernel', action='store_true',
+ help='Add kernel from existing volk module. Requires: -n. Optional: -b')
+ actions.add_option('-A', '--add_all_kernels', action='store_true',
+ help='Add all kernels from existing volk module. Optional: -b')
+ actions.add_option('-x', '--remove_kernel', action='store_true',
+ help='Remove kernel from module. Required: -n. Optional: -b')
+ actions.add_option('-l', '--list', action='store_true',
+ help='List all kernels in the base.')
+ actions.add_option('-k', '--kernels', action='store_true',
+ help='List all kernels in the module.')
+ actions.add_option('-r', '--remote_list', action='store_true',
+ help='List all available kernels in remote volk module. Requires: -b.')
+ actions.add_option('-m', '--moo', action='store_true',
+ help='Have you mooed today?')
+ parser.add_option_group(actions)
+
+ (options, args) = parser.parse_args();
+
+ if options.moo:
+ print " (__) "
+ print " (oo) "
+ print " /------\/ "
+ print " / | || "
+ print " * /\---/\ "
+ print " ~~ ~~ "
+
+ else:
+ my_cfg = volk_modtool_config(options.config_file);
+
+ my_modtool = volk_modtool(my_cfg.get_map(my_cfg.config_name));
+
+
+ if options.install:
+ my_modtool.make_module_skeleton();
+ my_modtool.write_default_cfg(my_cfg.cfg);
+
+
+ if options.add_kernel:
+ if not options.kernel_name:
+ raise exceptions.IOError("This action requires the -n option.");
+ else:
+ name = options.kernel_name;
+ if options.base_path:
+ base = options.base_path;
+ else:
+ base = my_cfg.cfg.get(my_cfg.config_name, 'base');
+ my_modtool.import_kernel(name, base);
+
+ if options.remove_kernel:
+ if not options.kernel_name:
+ raise exceptions.IOError("This action requires the -n option.");
+ else:
+ name = options.kernel_name;
+ my_modtool.remove_kernel(name);
+
+ if options.add_all_kernels:
+
+ if options.base_path:
+ base = options.base_path;
+ else:
+ base = my_cfg.cfg.get(my_cfg.config_name, 'base');
+ kernelset = my_modtool.get_current_kernels(base);
+ for i in kernelset:
+ my_modtool.import_kernel(i, base);
+
+ if options.remote_list:
+ if not options.base_path:
+ raise exceptions.IOError("This action requires the -b option. Try -l or -k for listing kernels in the base or the module.")
+ else:
+ base = options.base_path;
+ kernelset = my_modtool.get_current_kernels(base);
+ for i in kernelset:
+ print i;
+
+ if options.list:
+ kernelset = my_modtool.get_current_kernels();
+ for i in kernelset:
+ print i;
+
+ if options.kernels:
+ dest = my_cfg.cfg.get(my_cfg.config_name, 'destination');
+ name = my_cfg.cfg.get(my_cfg.config_name, 'name');
+ base = os.path.join(dest, 'volk_' + name);
+ kernelset = my_modtool.get_current_kernels(base);
+ for i in kernelset:
+ print i;
+
+
diff --git a/volk/python/volk_modtool/volk_modtool_generate.py b/volk/python/volk_modtool/volk_modtool_generate.py
new file mode 100644
index 0000000000..2e10e7b00c
--- /dev/null
+++ b/volk/python/volk_modtool/volk_modtool_generate.py
@@ -0,0 +1,310 @@
+#
+# Copyright 2013 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 sys
+import re
+import glob
+import shutil
+import exceptions
+from sets import Set
+
+class volk_modtool:
+ def __init__(self, cfg):
+ self.volk = re.compile('volk');
+ self.remove_after_underscore = re.compile("_.*");
+ self.volk_run_tests = re.compile('^\s*VOLK_RUN_TESTS.*\n', re.MULTILINE);
+ self.volk_profile = re.compile('^\s*(VOLK_PROFILE|VOLK_PUPPET_PROFILE).*\n', re.MULTILINE);
+ self.my_dict = cfg;
+ self.lastline = re.compile('\s*char path\[1024\];.*');
+ self.badassert = re.compile('^\s*assert\(toked\[0\] == "volk_.*\n', re.MULTILINE);
+ self.goodassert = ' assert(toked[0] == "volk");\n'
+ self.baderase = re.compile('^\s*toked.erase\(toked.begin\(\)\);.*\n', re.MULTILINE);
+ self.gooderase = ' toked.erase(toked.begin());\n toked.erase(toked.begin());\n';
+
+ def get_basename(self, base=None):
+ if not base:
+ base = self.my_dict['base']
+ candidate = base.split('/')[-1];
+ if len(candidate.split('_')) == 1:
+ return '';
+ else:
+ return candidate.split('_')[-1];
+
+ def get_current_kernels(self, base=None):
+ if not base:
+ base = self.my_dict['base']
+ name = self.get_basename();
+ else:
+ name = self.get_basename(base);
+ if name == '':
+ hdr_files = glob.glob(os.path.join(base, "kernels/volk/*.h"));
+ begins = re.compile("(?<=volk_).*")
+ else:
+ hdr_files = glob.glob(os.path.join(base, "kernels/volk_" + name + "/*.h"));
+ begins = re.compile("(?<=volk_" + name + "_).*")
+
+ datatypes = [];
+ functions = [];
+
+
+ for line in hdr_files:
+
+ subline = re.search(".*\.h.*", os.path.basename(line))
+ if subline:
+ subsubline = begins.search(subline.group(0));
+ if subsubline:
+ dtype = self.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 + ".*(?=\.h)", line);
+ subline = re.search(begins.pattern[:-2] + dt + ".*(?=\.h)", line);
+ if subline:
+ functions.append(subline.group(0));
+
+ return set(functions);
+
+ def make_module_skeleton(self):
+
+ dest = os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name'])
+ if os.path.exists(dest):
+ shutil.rmtree(dest)
+
+ if not os.path.exists(os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name'], 'kernels/volk_' + self.my_dict['name'])):
+ os.makedirs(os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name'], 'kernels/volk_' + self.my_dict['name']))
+
+ current_kernel_names = self.get_current_kernels();
+
+ for root, dirnames, filenames in os.walk(self.my_dict['base']):
+ for name in filenames:
+ t_table = map(lambda a: re.search(a, name), current_kernel_names);
+ t_table = set(t_table);
+ if t_table == set([None]):
+ infile = os.path.join(root, name);
+ instring = open(infile, 'r').read();
+ outstring = re.sub(self.volk, 'volk_' + self.my_dict['name'], instring);
+ newname = re.sub(self.volk, 'volk_' + self.my_dict['name'], name);
+ relpath = os.path.relpath(infile, self.my_dict['base']);
+ newrelpath = re.sub(self.volk, 'volk_' + self.my_dict['name'], relpath);
+ dest = os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name'], os.path.dirname(newrelpath), newname);
+
+ if not os.path.exists(os.path.dirname(dest)):
+ os.makedirs(os.path.dirname(dest))
+ open(dest, 'w+').write(outstring);
+
+
+ infile = os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name'], 'lib/testqa.cc');
+ instring = open(infile, 'r').read();
+ outstring = re.sub(self.volk_run_tests, '', instring);
+ open(infile, 'w+').write(outstring);
+
+ infile = os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name'], 'apps/volk_' + self.my_dict['name'] + '_profile.cc');
+ instring = open(infile, 'r').read();
+ outstring = re.sub(self.volk_profile, '', instring);
+ open(infile, 'w+').write(outstring);
+
+ infile = os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name'], 'lib/qa_utils.cc');
+ instring = open(infile, 'r').read();
+ outstring = re.sub(self.badassert, self.goodassert, instring);
+ outstring = re.sub(self.baderase, self.gooderase, outstring);
+ open(infile, 'w+').write(outstring);
+
+ def write_default_cfg(self, cfg):
+ outfile = open(os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name'], 'volk_modtool.cfg'), 'wb');
+ cfg.write(outfile);
+ outfile.close();
+
+
+ def convert_kernel(self, oldvolk, name, base, inpath, top):
+ infile = os.path.join(inpath, 'kernels/' + top[:-1] + '/' + top + name + '.h');
+ instring = open(infile, 'r').read();
+ outstring = re.sub(oldvolk, 'volk_' + self.my_dict['name'], instring);
+ newname = 'volk_' + self.my_dict['name'] + '_' + name + '.h';
+ relpath = os.path.relpath(infile, base);
+ newrelpath = re.sub(oldvolk, 'volk_' + self.my_dict['name'], relpath);
+ dest = os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name'], os.path.dirname(newrelpath), newname);
+
+
+
+ if not os.path.exists(os.path.dirname(dest)):
+ os.makedirs(os.path.dirname(dest))
+ open(dest, 'w+').write(outstring);
+
+ def remove_kernel(self, name):
+ basename = self.my_dict['name'];
+ if len(basename) > 0:
+ top = 'volk_' + basename + '_';
+ else:
+ top = 'volk_'
+ base = os.path.join(self.my_dict['destination'], top[:-1]) ;
+
+ if not name in self.get_current_kernels():
+
+ raise exceptions.IOError("Requested kernel %s is not in module %s"%(name,base));
+
+
+
+ inpath = os.path.abspath(base);
+
+
+ kernel = re.compile(name)
+ search_kernels = Set([kernel])
+ profile = re.compile('^\s*VOLK_PROFILE')
+ puppet = re.compile('^\s*VOLK_PUPPET')
+ src_dest = os.path.join(inpath, 'apps/', top[:-1] + '_profile.cc');
+ infile = open(src_dest);
+ otherlines = infile.readlines();
+ open(src_dest, 'w+').write('');
+
+ for otherline in otherlines:
+ write_okay = True;
+ if kernel.search(otherline):
+ write_okay = False;
+ if puppet.match(otherline):
+ args = re.search("(?<=VOLK_PUPPET_PROFILE).*", otherline)
+ m_func = args.group(0).split(',')[0];
+ func = re.search('(?<=' + top + ').*', m_func);
+ search_kernels.add(re.compile(func.group(0)));
+ if write_okay:
+ open(src_dest, 'a').write(otherline);
+
+
+ src_dest = os.path.join(inpath, 'lib/testqa.cc')
+ infile = open(src_dest);
+ otherlines = infile.readlines();
+ open(src_dest, 'w+').write('');
+
+ for otherline in otherlines:
+ write_okay = True;
+
+ for kernel in search_kernels:
+ if kernel.search(otherline):
+ write_okay = False;
+
+ if write_okay:
+ open(src_dest, 'a').write(otherline);
+
+ for kernel in search_kernels:
+ infile = os.path.join(inpath, 'kernels/' + top[:-1] + '/' + top + kernel.pattern + '.h');
+ print "Removing kernel %s"%(kernel.pattern)
+ if os.path.exists(infile):
+ os.remove(infile);
+
+ def import_kernel(self, name, base):
+ if not (base):
+ base = self.my_dict['base'];
+ basename = self.getbasename();
+ else:
+ basename = self.get_basename(base);
+ if not name in self.get_current_kernels(base):
+ raise exceptions.IOError("Requested kernel %s is not in module %s"%(name,base));
+
+ inpath = os.path.abspath(base);
+ if len(basename) > 0:
+ top = 'volk_' + basename + '_';
+ else:
+ top = 'volk_'
+ oldvolk = re.compile(top[:-1]);
+
+ self.convert_kernel(oldvolk, name, base, inpath, top);
+
+ kernel = re.compile(name)
+ search_kernels = Set([kernel])
+
+ profile = re.compile('^\s*VOLK_PROFILE')
+ puppet = re.compile('^\s*VOLK_PUPPET')
+ infile = open(os.path.join(inpath, 'apps/', oldvolk.pattern + '_profile.cc'));
+ otherinfile = open(os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name'], 'apps/volk_' + self.my_dict['name'] + '_profile.cc'));
+ dest = os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name'], 'apps/volk_' + self.my_dict['name'] + '_profile.cc');
+ lines = infile.readlines();
+ otherlines = otherinfile.readlines();
+ open(dest, 'w+').write('');
+ insert = False;
+ inserted = False
+ for otherline in otherlines:
+
+ if self.lastline.match(otherline):
+ insert = True;
+ if insert and not inserted:
+ inserted = True;
+ for line in lines:
+ if kernel.search(line):
+ if profile.match(line):
+ outline = re.sub(oldvolk, 'volk_' + self.my_dict['name'], line);
+ open(dest, 'a').write(outline);
+ elif puppet.match(line):
+ outline = re.sub(oldvolk, 'volk_' + self.my_dict['name'], line);
+ open(dest, 'a').write(outline);
+ args = re.search("(?<=VOLK_PUPPET_PROFILE).*", line)
+ m_func = args.group(0).split(',')[0];
+ func = re.search('(?<=' + top + ').*', m_func);
+ search_kernels.add(re.compile(func.group(0)));
+ self.convert_kernel(oldvolk, func.group(0), base, inpath, top);
+ write_okay = True;
+ for kernel in search_kernels:
+ if kernel.search(otherline):
+ write_okay = False
+ if write_okay:
+ open(dest, 'a').write(otherline);
+
+ for kernel in search_kernels:
+ print "Adding kernel %s from module %s"%(kernel.pattern,base)
+
+ infile = open(os.path.join(inpath, 'lib/testqa.cc'));
+ otherinfile = open(os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name'], 'lib/testqa.cc'));
+ dest = os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name'], 'lib/testqa.cc');
+ lines = infile.readlines();
+ otherlines = otherinfile.readlines();
+ open(dest, 'w+').write('');
+ inserted = False;
+ insert = False
+ for otherline in otherlines:
+
+ if (re.match('\s*', otherline) == None or re.match('\s*#.*', otherline) == None):
+
+ insert = True;
+ if insert and not inserted:
+ inserted = True;
+ for line in lines:
+ for kernel in search_kernels:
+ if kernel.search(line):
+ if self.volk_run_tests.match(line):
+ outline = re.sub(oldvolk, 'volk_' + self.my_dict['name'], line);
+ open(dest, 'a').write(outline);
+ write_okay = True;
+ for kernel in search_kernels:
+ if kernel.search(otherline):
+ write_okay = False
+ if write_okay:
+ open(dest, 'a').write(otherline);
+
+
+
+
+