benchmarks /unladen_swallow/lib/spitfire/scripts/spitfire-compile

Language Python Lines 85
MD5 Hash 8c184fca20771ef6f8815280698208f9 Estimated Cost $1,581 (why?)
Repository https://bitbucket.org/csenger/benchmarks View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python

import logging
import os
import os.path
import sys

import spitfire
import spitfire.compiler.util

from spitfire.compiler import analyzer
from spitfire.compiler.util import Compiler


def process_file(compiler, filename, options):
  def print_output(*args):
    if options.verbose:
      print >> sys.stderr, ' '.join(args)

  try:
    if options.output_file:
      compiler.write_file = False
      if options.output_file == '-':
        f = sys.stdout
      else:
        f = open(options.output_file, 'w')
    else:
      compiler.write_file = True
    src_code = compiler.compile_file(filename)
    if options.output_file:
      f.write(src_code)
      f.close()
  except Exception, e:
    error_msg = 'Failed processing file: %s' % filename
    if options.verbose:
      logging.exception(error_msg)
    else:
      print >> sys.stderr, error_msg
      print >> sys.stderr, e
    sys.exit(1)

# selectively enable psyco on import methods
def init_psyco(options):
  if options.x_psyco:
    try:
      import psyco
    except ImportError:
      print >> sys.stderr, 'WARNING: unable to import psyco'
      return
    
    import re
    psyco.cannotcompile(re.compile)

    if options.x_psyco_profile:
      psyco.log()
      psyco.profile()
    else:
      import spitfire.compiler.scanner
      psyco.bind(spitfire.compiler.scanner.SpitfireScanner.scan)
      import copy
      psyco.bind(copy.deepcopy)
      import yappsrt
      psyco.bind(yappsrt.Scanner.token)
      import spitfire.compiler.ast
      psyco.bind(spitfire.compiler.ast.NodeList.__iter__)
  

if __name__ == '__main__':
  from optparse import OptionParser
  op = OptionParser()
  spitfire.compiler.util.add_common_options(op)
  (options, args) = op.parse_args()

  if options.version:
    print >> sys.stderr, 'spitfire %s' % spitfire.__version__
    sys.exit(0)
  
  init_psyco(options)

  compiler_args = Compiler.args_from_optparse(options)
  compiler = Compiler(**compiler_args)
  
  for filename in args:
    process_file(compiler, filename, options)
Back to Top