# HG changeset patch # User Paul Boddie # Date 1479246957 -3600 # Node ID 2ce83f67d8d330c17f814c193116efe97f9c8b3b # Parent 27ac1971cb382b785f8e21dc14fa9af397c343a5 Added a debugging switch that causes a different Makefile to be used. diff -r 27ac1971cb38 -r 2ce83f67d8d3 generator.py --- a/generator.py Tue Nov 15 19:12:12 2016 +0100 +++ b/generator.py Tue Nov 15 22:55:57 2016 +0100 @@ -30,7 +30,7 @@ encode_symbol, encode_tablename, \ encode_type_attribute from os import listdir -from os.path import isdir, join, split +from os.path import exists, isdir, join, split from referencing import Reference def copy(source, target): @@ -73,22 +73,37 @@ self.optimiser = optimiser self.output = output - def to_output(self): + def to_output(self, debug=False): "Write the generated code." self.check_output() self.write_structures() - self.copy_templates() + self.copy_templates(debug) - def copy_templates(self): + def copy_templates(self, debug=False): "Copy template files to the generated output directory." templates = join(split(__file__)[0], "templates") for filename in listdir(templates): - copy(join(templates, filename), self.output) + target = self.output + + # Handle debug resources. + + if filename.endswith("-debug"): + if debug: + target = join(self.output, filename[:-len("-debug")]) + else: + continue + + # Handle non-debug resources. + + if debug and exists(join(templates, "%s-debug" % filename)): + continue + + copy(join(templates, filename), target) def write_structures(self): diff -r 27ac1971cb38 -r 2ce83f67d8d3 lplc --- a/lplc Tue Nov 15 19:12:12 2016 +0100 +++ b/lplc Tue Nov 15 22:55:57 2016 +0100 @@ -39,6 +39,7 @@ verbose = "-v" in args reset = "-r" in args + debug = "-g" in args # Load the program. @@ -71,7 +72,7 @@ now = stopwatch("Optimisation", now) g = generator.Generator(i, o, "_generated") - g.to_output() + g.to_output(debug) now = stopwatch("Generation", now) diff -r 27ac1971cb38 -r 2ce83f67d8d3 templates/Makefile-debug --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/Makefile-debug Tue Nov 15 22:55:57 2016 +0100 @@ -0,0 +1,14 @@ +SRC = exceptions.c main.c native.c ops.c progops.c progtypes.c $(wildcard src/*.c) +OBJ = $(SRC:.c=.o) +CFLAGS = -I. -g + +all: main + +clean: + rm -f main $(OBJ) + +main: $(OBJ) + $(CC) $(LDFLAGS) $(OBJ) -o $@ + +.c.o: + $(CC) -c $(CFLAGS) $< -o $@