Simplify build system
RELEASE and DEBUG builds have differing build flags, triggered by setting RELEASE variable. No longer doing object based compilation because: + gcc is fast enough without it + stale code compilation bugs are annoying + having one output binary to clean-up is just easier when switching build-types
This commit is contained in:
28
Makefile
28
Makefile
@@ -1,20 +1,28 @@
|
||||
CC=gcc
|
||||
CFLAGS=-Wall -Wextra -Wpedantic -ggdb -fsanitize=address -std=c11
|
||||
LIBS=
|
||||
OBJECTS=lib.o parser.o main.o
|
||||
OUT=obf.out
|
||||
LIBS=
|
||||
ARGS=
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $^ -o $@ $(LIBS)
|
||||
RELEASE=0
|
||||
GFLAGS=-Wall -Wextra -Werror -Wswitch-enum -std=c11
|
||||
DFLAGS=-ggdb -fsanitize=address -fsanitize=undefined -DDEBUG
|
||||
RFLAGS=-O3
|
||||
ifeq ($(RELEASE), 1)
|
||||
CFLAGS=$(GFLAGS) $(RFLAGS)
|
||||
else
|
||||
CFLAGS=$(GFLAGS) $(DFLAGS)
|
||||
endif
|
||||
|
||||
$(OUT): $(OBJECTS)
|
||||
.PHONY: all
|
||||
all: $(OUT)
|
||||
|
||||
$(OUT): lib.c parser.c main.c
|
||||
$(CC) $(CFLAGS) $^ -o $@ $(LIBS)
|
||||
|
||||
.PHONY:
|
||||
clean:
|
||||
rm -rfv $(OUT) $(OBJECTS)
|
||||
|
||||
.PHONY: run
|
||||
run: $(OUT)
|
||||
./$^ $(ARGS)
|
||||
|
||||
.PHONY:
|
||||
clean:
|
||||
rm -v $(OUT)
|
||||
|
||||
23
main.c
23
main.c
@@ -15,7 +15,6 @@
|
||||
|
||||
#define MEMORY_DEFAULT 30000
|
||||
|
||||
#define DEBUG 0
|
||||
#define MIN_MEM_DUMP 64
|
||||
|
||||
typedef struct
|
||||
@@ -23,7 +22,7 @@ typedef struct
|
||||
size_t dp;
|
||||
uint8_t memory[MEMORY_DEFAULT];
|
||||
|
||||
#if DEBUG
|
||||
#ifdef DEBUG
|
||||
size_t dp_max;
|
||||
#endif
|
||||
} machine_t;
|
||||
@@ -62,13 +61,13 @@ void interpret(machine_t *cpu, node_t *ast, size_t num)
|
||||
i = node.loop_ref;
|
||||
break;
|
||||
}
|
||||
#if DEBUG
|
||||
#ifdef DEBUG
|
||||
if (cpu->dp > cpu->dp_max)
|
||||
cpu->dp_max = cpu->dp + 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
#ifdef DEBUG
|
||||
if (cpu->dp_max < MIN_MEM_DUMP)
|
||||
cpu->dp_max = MIN_MEM_DUMP;
|
||||
#endif
|
||||
@@ -90,9 +89,9 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *filepath, *file_data;
|
||||
buffer_t *buffer;
|
||||
struct PResult res;
|
||||
char *filepath = NULL, *file_data = NULL;
|
||||
buffer_t *buffer = NULL;
|
||||
struct PResult res = {0};
|
||||
|
||||
machine_t machine = {0};
|
||||
|
||||
@@ -101,7 +100,7 @@ int main(int argc, char *argv[])
|
||||
filepath = argv[i];
|
||||
|
||||
FILE *handle = fopen(filepath, "r");
|
||||
#if DEBUG
|
||||
#ifdef DEBUG
|
||||
printf("[DEBUG]: Attempting to open file handle to %s\n", filepath);
|
||||
#endif
|
||||
if (!handle)
|
||||
@@ -111,12 +110,12 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
file_data = fread_all(handle);
|
||||
fclose(handle);
|
||||
#if DEBUG
|
||||
#ifdef DEBUG
|
||||
printf("[DEBUG]: Read data from file %s\n", filepath);
|
||||
#endif
|
||||
|
||||
buffer = buffer_init_str(filepath, file_data, strlen(file_data));
|
||||
#if DEBUG
|
||||
#ifdef DEBUG
|
||||
puts("[DEBUG]: Initialised buffer");
|
||||
#endif
|
||||
res = parse_buffer(buffer);
|
||||
@@ -126,7 +125,7 @@ int main(int argc, char *argv[])
|
||||
goto error;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
#ifdef DEBUG
|
||||
char *str = ast_to_str(res.nodes, res.size);
|
||||
printf("[DEBUG]: Parsed buffer (%lu nodes parsed)\n\t[DEBUG]: Out=%s\n",
|
||||
res.size, str);
|
||||
@@ -135,7 +134,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
interpret(&machine, res.nodes, res.size);
|
||||
|
||||
#if DEBUG
|
||||
#ifdef DEBUG
|
||||
printf("[DEBUG]: Finished interpreting, memory:");
|
||||
for (size_t i = 0; i < machine.dp_max; ++i)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user