1.1 --- a/lplc Thu Feb 09 15:36:02 2017 +0100
1.2 +++ b/lplc Thu Feb 09 21:44:14 2017 +0100
1.3 @@ -1,8 +1,29 @@
1.4 #!/usr/bin/env python
1.5
1.6 +"""
1.7 +Lichen Python-like compiler tool.
1.8 +
1.9 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This program is free software; you can redistribute it and/or modify it under
1.12 +the terms of the GNU General Public License as published by the Free Software
1.13 +Foundation; either version 3 of the License, or (at your option) any later
1.14 +version.
1.15 +
1.16 +This program is distributed in the hope that it will be useful, but WITHOUT
1.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 +details.
1.20 +
1.21 +You should have received a copy of the GNU General Public License along with
1.22 +this program. If not, see <http://www.gnu.org/licenses/>.
1.23 +"""
1.24 +
1.25 +VERSION = "0.1"
1.26 +
1.27 from errors import *
1.28 from os import rename
1.29 -from os.path import abspath, exists, join, split
1.30 +from os.path import abspath, exists, isfile, join, split
1.31 from pyparser import error
1.32 from subprocess import Popen, PIPE
1.33 from time import time
1.34 @@ -67,6 +88,8 @@
1.35 args = sys.argv[1:]
1.36 path = libdirs
1.37
1.38 + # Show help text if requested or if no arguments are given.
1.39 +
1.40 if "--help" in args or not args:
1.41 print >>sys.stderr, """\
1.42 Usage: %s [ <options> ] <filename>
1.43 @@ -78,6 +101,7 @@
1.44 -g Generate debugging information for the built executable
1.45 -q Silence messages produced when building an executable
1.46 -r Reset (discard) cached program information; inspect the whole program again
1.47 +-t Silence timing messages
1.48 -tb Provide a traceback for any internal errors (development only)
1.49 -v Report compiler activities in a verbose fashion (development only)
1.50
1.51 @@ -89,19 +113,39 @@
1.52
1.53 Currently, the following warnings are supported:
1.54
1.55 -all Show all possible warnings
1.56 +all Show all possible warnings
1.57 +
1.58 +args Show invocations where a callable may be involved that cannot accept
1.59 + the arguments provided
1.60 +
1.61 +The following informational options can be specified to produce output instead
1.62 +of compiling a program:
1.63
1.64 -args Show invocations where a callable may be involved that cannot accept the
1.65 - arguments provided
1.66 +--help Show a summary of the command syntax and options
1.67 +--version Show version information for this tool
1.68 """ % basename
1.69 sys.exit(1)
1.70
1.71 + # Show the version information if requested.
1.72 +
1.73 + elif "--version" in args:
1.74 + print >>sys.stderr, """\
1.75 +lplc %s
1.76 +Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013,
1.77 + 2014, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
1.78 +This program is free software; you may redistribute it under the terms of
1.79 +the GNU General Public License version 3 or (at your option) a later version.
1.80 +This program has absolutely no warranty.
1.81 +""" % VERSION
1.82 + sys.exit(1)
1.83 +
1.84 # Determine the options and arguments.
1.85
1.86 debug = False
1.87 make = True
1.88 make_verbose = True
1.89 reset = False
1.90 + timings = True
1.91 traceback = False
1.92 verbose = False
1.93 warnings = []
1.94 @@ -119,6 +163,7 @@
1.95 elif arg == "-g": debug = True
1.96 elif arg == "-q": make_verbose = False
1.97 elif arg == "-r": reset = True
1.98 + elif arg == "-t": timings = False
1.99 elif arg == "-tb": traceback = True
1.100 elif arg.startswith("-o"): l, needed = start_arg_list(outputs, arg, "-o", 1)
1.101 elif arg == "-v": verbose = True
1.102 @@ -138,6 +183,11 @@
1.103 sys.exit(1)
1.104
1.105 filename = abspath(filenames[0])
1.106 +
1.107 + if not isfile(filename):
1.108 + print >>sys.stderr, "Filename %s is not a valid input." % filenames[0]
1.109 + sys.exit(1)
1.110 +
1.111 path.append(split(filename)[0])
1.112
1.113 # Obtain the output filename.
1.114 @@ -158,13 +208,13 @@
1.115 # Load the program.
1.116
1.117 try:
1.118 - start = now = time()
1.119 + if timings: now = time()
1.120
1.121 i = importer.Importer(path, cache_dir, verbose, warnings)
1.122 m = i.initialise(filename, reset)
1.123 success = i.finalise()
1.124
1.125 - now = stopwatch("Inspection", now)
1.126 + if timings: now = stopwatch("Inspection", now)
1.127
1.128 # Check for success, indicating missing references otherwise.
1.129
1.130 @@ -175,22 +225,22 @@
1.131 d = deducer.Deducer(i, deduced_dir)
1.132 d.to_output()
1.133
1.134 - now = stopwatch("Deduction", now)
1.135 + if timings: now = stopwatch("Deduction", now)
1.136
1.137 o = optimiser.Optimiser(i, d, output_dir)
1.138 o.to_output()
1.139
1.140 - now = stopwatch("Optimisation", now)
1.141 + if timings: now = stopwatch("Optimisation", now)
1.142
1.143 g = generator.Generator(i, o, generated_dir)
1.144 g.to_output(debug)
1.145
1.146 - now = stopwatch("Generation", now)
1.147 + if timings: now = stopwatch("Generation", now)
1.148
1.149 t = translator.Translator(i, d, o, generated_dir)
1.150 t.to_output()
1.151
1.152 - now = stopwatch("Translation", now)
1.153 + if timings: now = stopwatch("Translation", now)
1.154
1.155 # Compile the program unless otherwise indicated.
1.156
1.157 @@ -203,7 +253,7 @@
1.158 retval = call(make_cmd, make_verbose)
1.159
1.160 if not retval:
1.161 - stopwatch("Compilation", now)
1.162 + if timings: stopwatch("Compilation", now)
1.163 else:
1.164 sys.exit(retval)
1.165