1.1 --- a/generator.py Tue Nov 15 19:12:12 2016 +0100
1.2 +++ b/generator.py Tue Nov 15 22:55:57 2016 +0100
1.3 @@ -30,7 +30,7 @@
1.4 encode_symbol, encode_tablename, \
1.5 encode_type_attribute
1.6 from os import listdir
1.7 -from os.path import isdir, join, split
1.8 +from os.path import exists, isdir, join, split
1.9 from referencing import Reference
1.10
1.11 def copy(source, target):
1.12 @@ -73,22 +73,37 @@
1.13 self.optimiser = optimiser
1.14 self.output = output
1.15
1.16 - def to_output(self):
1.17 + def to_output(self, debug=False):
1.18
1.19 "Write the generated code."
1.20
1.21 self.check_output()
1.22 self.write_structures()
1.23 - self.copy_templates()
1.24 + self.copy_templates(debug)
1.25
1.26 - def copy_templates(self):
1.27 + def copy_templates(self, debug=False):
1.28
1.29 "Copy template files to the generated output directory."
1.30
1.31 templates = join(split(__file__)[0], "templates")
1.32
1.33 for filename in listdir(templates):
1.34 - copy(join(templates, filename), self.output)
1.35 + target = self.output
1.36 +
1.37 + # Handle debug resources.
1.38 +
1.39 + if filename.endswith("-debug"):
1.40 + if debug:
1.41 + target = join(self.output, filename[:-len("-debug")])
1.42 + else:
1.43 + continue
1.44 +
1.45 + # Handle non-debug resources.
1.46 +
1.47 + if debug and exists(join(templates, "%s-debug" % filename)):
1.48 + continue
1.49 +
1.50 + copy(join(templates, filename), target)
1.51
1.52 def write_structures(self):
1.53
2.1 --- a/lplc Tue Nov 15 19:12:12 2016 +0100
2.2 +++ b/lplc Tue Nov 15 22:55:57 2016 +0100
2.3 @@ -39,6 +39,7 @@
2.4
2.5 verbose = "-v" in args
2.6 reset = "-r" in args
2.7 + debug = "-g" in args
2.8
2.9 # Load the program.
2.10
2.11 @@ -71,7 +72,7 @@
2.12 now = stopwatch("Optimisation", now)
2.13
2.14 g = generator.Generator(i, o, "_generated")
2.15 - g.to_output()
2.16 + g.to_output(debug)
2.17
2.18 now = stopwatch("Generation", now)
2.19
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/templates/Makefile-debug Tue Nov 15 22:55:57 2016 +0100
3.3 @@ -0,0 +1,14 @@
3.4 +SRC = exceptions.c main.c native.c ops.c progops.c progtypes.c $(wildcard src/*.c)
3.5 +OBJ = $(SRC:.c=.o)
3.6 +CFLAGS = -I. -g
3.7 +
3.8 +all: main
3.9 +
3.10 +clean:
3.11 + rm -f main $(OBJ)
3.12 +
3.13 +main: $(OBJ)
3.14 + $(CC) $(LDFLAGS) $(OBJ) -o $@
3.15 +
3.16 +.c.o:
3.17 + $(CC) -c $(CFLAGS) $< -o $@