MAGMA  magma-1.4.0
Matrix Algebra on GPU and Multicore Architectures
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
codegen Namespace Reference

Data Structures

class  Conversion
 

Functions

def check_gen
 
def grep
 
def hidden
 
def valid_extension
 
def relpath
 
def main
 

Variables

string __author__ = "alvaro"
 
string __date__ = "$Sep 2, 2010 10:09:19 AM$"
 
float __version__ = 11.0408
 
string KEYWORD = '@precisions'
 
string DONE_KEYWORD = '@generated'
 
string REGEX = '^.*'
 
list EXTS = ['.c','.h','.f']
 

Function Documentation

def codegen.check_gen (   file,
  work,
  rex 
)
Reads the file and determines if the file needs generation.

Definition at line 35 of file codegen.py.

35 
36 def check_gen(file, work, rex):
37  """Reads the file and determines if the file needs generation."""
38  fd = open(path.realpath(file), 'r');
39  lines = fd.readlines();
40  fd.close();
41  for line in lines:
42  m = rex.match(line);
43  if m is None: continue;
44  work.append((file, m.groups(), ''.join(lines)));
def check_gen
Definition: codegen.py:35

Here is the caller graph for this function:

def codegen.grep (   string,
  list 
)

Definition at line 45 of file codegen.py.

45 
46 def grep(string,list):
47  expr = re.compile(string)
48  return filter(expr.search,list)
def grep
Definition: codegen.py:45
def codegen.hidden (   file)
Exclude hidden files

Definition at line 49 of file codegen.py.

49 
50 def hidden(file):
51  """Exclude hidden files"""
52  return not file.startswith('.');
def hidden
Definition: codegen.py:49
def codegen.main ( )
Create option parser, set static variables of the converter and manage printing options/order.

Definition at line 260 of file codegen.py.

References check_gen().

261 def main():
262  """Create option parser, set static variables of the converter and manage printing options/order."""
263  global REGEX, EXTS;
264  """The compiled regular expression for detecting proper files."""
265  rex = re.compile(REGEX);
266  """Files found to be workable."""
267  work = [];
268 
269  """Create the options parser for detecting options on the command line."""
270  parser = OptionParser(usage="Usage: %prog [options]",version='%prog '+str(__version__));
271  group = OptionGroup(parser,"Printing Options","These options control the printing output.");
272  group.add_option("-i", "--in-files", help='Print the filenames of files for precision generation.', action='store_true', dest='in_print', default=False);
273  group.add_option("-o", "--out-files", help='Print the filenames for the precision generated files.', action='store_true', dest='out_print', default=False);
274  group.add_option("-m", "--make", help='Spew a GNU Make friendly file to standard out.', action='store_true', dest='make', default=False);
275  group.add_option("-d", "--debug", help='Print debugging messages.', action='store_true', dest='debug', default=False);
276  parser.add_option_group(group);
277  group = OptionGroup(parser,"Operating Mode Options","These options alter the way the program operates on the input/output files.");
278  group.add_option("-c", "--clean", help='Remove the files that are the product of generation.', action='store_true', dest='out_clean', default=False);
279  group.add_option("-T", "--test", help='Don\'t actually do any work.', action='store_true', dest='test', default=False);
280  parser.add_option_group(group);
281  group = OptionGroup(parser,"Settings","These options specify how the work should be done.");
282  group.add_option("-P", "--prefix", help='The output directory if different from the input directory.', action='store', dest='prefix', default=None);
283  group.add_option("-f", "--file", help='Specify files on which to operate.', action='store', dest='fileslst', type='string', default=None );
284  group.add_option("-p", "--prec", help='Specify a precision(s) on which to operate.', action='store', dest='precslst', type='string', default="");
285  group.add_option("-e", "--filetypes", help='Specify file extensions on which to operate when walking.', action='store', dest='fileexts', type='string', default="");
286  parser.add_option_group(group);
287 
288  (options, args) = parser.parse_args();
289 
290  """If file extensions are specified, override defaults."""
291  if options.fileexts:
292  EXTS = options.fileexts.split();
293 
294  """Fill the 'work' array with files found to be operable."""
295  if options.fileslst is not None:
296  # Files to examine are specified on the command line
297  # Note fileslst can be "", indicating no files to process
298  for file in options.fileslst.split():
299  check_gen(file, work, rex);
300  else:
301  """Begin directory walking in the current directory."""
302  startDir = '.';
303  for root, dirs, files in os.walk(startDir, True, None):
304  dirs = filter(hidden,dirs);
305  files = filter(hidden,files);
306  files = filter(valid_extension,files);
307  for file in files:
308  check_gen(path.join(root,file), work, rex);
309 
310  """Set static options for conversion."""
311  Conversion.debug = options.debug;
312  Conversion.make = options.make;
313  Conversion.prefix = options.prefix;
314  Conversion.required_precisions = options.precslst.split();
315  if options.out_print or options.out_clean or options.in_print or options.make or options.test:
316  Conversion.test = True;
317 
318  if options.make:
319  """If the program should be GNU Make friendly."""
320  print '## Automatically generated Makefile';
321  print 'PYTHON ?= python';
322 
323  for tuple in work:
324  """For each valid conversion file found."""
325  try:
326  """Try creating and executing a converter."""
327  c = Conversion(tuple[0], tuple[1], tuple[2]);
328  c.run();
329  except Exception, e:
330  print >> sys.stderr, str(e);
331  continue;
332 
333  if options.make:
334  """If the program should be GNU Make friendly."""
335  print 'gen = ',' '+' '.join(Conversion.files_out);
336  print 'cleangen:';
337  print '\trm -f $(gen)';
338  print 'generate: $(gen)';
339  print '.PHONY: cleangen generate';
340  if options.in_print:
341  """Should we print the input files?"""
342  print ' '.join(Conversion.files_in);
343  if options.out_print:
344  """Should we print the output files?"""
345  print ' '.join(Conversion.files_out);
346  if options.out_clean:
347  """Clean generated files"""
348  for file in Conversion.files_out:
349  if not path.exists(file): continue;
350  os.remove(file);
def main
Definition: codegen.py:260
def check_gen
Definition: codegen.py:35

Here is the call graph for this function:

def codegen.relpath (   p)
Get the relative path of a file.

Definition at line 61 of file codegen.py.

61 
62 def relpath(p):
63  """Get the relative path of a file."""
64  p = path.realpath(p);
65  return p.replace(path.realpath('.')+'/','');
def relpath
Definition: codegen.py:61
def codegen.valid_extension (   file)
Exclude non-valid extensions

Definition at line 53 of file codegen.py.

53 
54 def valid_extension(file):
55  """Exclude non-valid extensions"""
56  global EXTS;
57  for ext in EXTS:
58  if file.endswith(ext):
59  return True;
60  return False;
def valid_extension
Definition: codegen.py:53

Variable Documentation

string codegen.__author__ = "alvaro"

Definition at line 13 of file codegen.py.

string codegen.__date__ = "$Sep 2, 2010 10:09:19 AM$"

Definition at line 14 of file codegen.py.

float codegen.__version__ = 11.0408

Definition at line 15 of file codegen.py.

string codegen.DONE_KEYWORD = '@generated'

Definition at line 29 of file codegen.py.

list codegen.EXTS = ['.c','.h','.f']

Definition at line 33 of file codegen.py.

string codegen.KEYWORD = '@precisions'

Definition at line 27 of file codegen.py.

string codegen.REGEX = '^.*'

Definition at line 31 of file codegen.py.