1.1 --- a/lplc Wed Feb 08 16:20:27 2017 +0100
1.2 +++ b/lplc Wed Feb 08 17:24:31 2017 +0100
1.3 @@ -43,12 +43,59 @@
1.4 stdout, stderr = cmd.communicate()
1.5 return cmd.wait()
1.6
1.7 +def start_arg_list(l, arg, prefix, needed):
1.8 +
1.9 + """
1.10 + Add to 'l' any value given as part of 'arg' having the given option
1.11 + 'prefix'. The 'needed' number of values is provided in case no value is
1.12 + found.
1.13 +
1.14 + Return 'l' and 'needed' decremented by 1 together in a tuple.
1.15 + """
1.16 +
1.17 + s = arg[len(prefix):].strip()
1.18 + if s:
1.19 + l.append(s)
1.20 + return l, needed - 1
1.21 + else:
1.22 + return l, needed
1.23 +
1.24 # Main program.
1.25
1.26 if __name__ == "__main__":
1.27 + basename = split(sys.argv[0])[-1]
1.28 args = sys.argv[1:]
1.29 path = libdirs
1.30
1.31 + if "--help" in args or not args:
1.32 + print >>sys.stderr, """\
1.33 +Usage: %s [ <options> ] <filename>
1.34 +
1.35 +Compile the program whose principal file is given in place of <filename>.
1.36 +The following options may be specified:
1.37 +
1.38 +-c Only partially compile the program; do not attempt to build or link it
1.39 +-g Generate debugging information for the built executable
1.40 +-q Silence messages produced when building an executable
1.41 +-r Reset (discard) cached program information; inspect the whole program again
1.42 +-tb Provide a traceback for any internal errors (development only)
1.43 +-v Report compiler activities in a verbose fashion (development only)
1.44 +
1.45 +Some options may be followed by values, either immediately after the option
1.46 +(without any space between) or in the arguments that follow them:
1.47 +
1.48 +-o Indicate the output executable name
1.49 +-W Show warnings on the topics indicated
1.50 +
1.51 +Currently, the following warnings are supported:
1.52 +
1.53 +all Show all possible warnings
1.54 +
1.55 +args Show invocations where a callable may be involved that cannot accept the
1.56 + arguments provided
1.57 +""" % basename
1.58 + sys.exit(1)
1.59 +
1.60 # Determine the options and arguments.
1.61
1.62 debug = False
1.63 @@ -57,6 +104,7 @@
1.64 reset = False
1.65 traceback = False
1.66 verbose = False
1.67 + warnings = []
1.68
1.69 filenames = []
1.70 outputs = []
1.71 @@ -64,6 +112,7 @@
1.72 # Obtain program filenames by default.
1.73
1.74 l = filenames
1.75 + needed = None
1.76
1.77 for arg in args:
1.78 if arg == "-c": make = False
1.79 @@ -71,20 +120,21 @@
1.80 elif arg == "-q": make_verbose = False
1.81 elif arg == "-r": reset = True
1.82 elif arg == "-tb": traceback = True
1.83 - elif arg == "-o": l = outputs
1.84 + elif arg.startswith("-o"): l, needed = start_arg_list(outputs, arg, "-o", 1)
1.85 elif arg == "-v": verbose = True
1.86 + elif arg.startswith("-W"): l, needed = start_arg_list(warnings, arg, "-W", 1)
1.87 else:
1.88 l.append(arg)
1.89 + if needed:
1.90 + needed -= 1
1.91
1.92 - # Revert to collecting program filenames after obtaining the output
1.93 - # executable filename.
1.94 -
1.95 - if l is outputs: l = filenames
1.96 + if needed == 0:
1.97 + l = filenames
1.98
1.99 # Obtain the program filename.
1.100
1.101 - if len(filenames) > 1:
1.102 - print >>sys.stderr, "Only one main program file can be specified."
1.103 + if len(filenames) != 1:
1.104 + print >>sys.stderr, "One main program file must be specified."
1.105 sys.exit(1)
1.106
1.107 filename = abspath(filenames[0])
1.108 @@ -92,6 +142,9 @@
1.109
1.110 # Obtain the output filename.
1.111
1.112 + if outputs and not make:
1.113 + print >>sys.stderr, "Output specified but building disabled."
1.114 +
1.115 output = outputs and outputs[0] or "_main"
1.116
1.117 # Define the output data directories.
1.118 @@ -107,7 +160,7 @@
1.119 try:
1.120 start = now = time()
1.121
1.122 - i = importer.Importer(path, cache_dir, verbose)
1.123 + i = importer.Importer(path, cache_dir, verbose, warnings)
1.124 m = i.initialise(filename, reset)
1.125 success = i.finalise()
1.126