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
|
CC=gcc
|
||||||
CFLAGS=-Wall -Wextra -Wpedantic -ggdb -fsanitize=address -std=c11
|
|
||||||
LIBS=
|
|
||||||
OBJECTS=lib.o parser.o main.o
|
|
||||||
OUT=obf.out
|
OUT=obf.out
|
||||||
|
LIBS=
|
||||||
ARGS=
|
ARGS=
|
||||||
|
|
||||||
%.o: %.c
|
RELEASE=0
|
||||||
$(CC) $(CFLAGS) -c $^ -o $@ $(LIBS)
|
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)
|
$(CC) $(CFLAGS) $^ -o $@ $(LIBS)
|
||||||
|
|
||||||
.PHONY:
|
|
||||||
clean:
|
|
||||||
rm -rfv $(OUT) $(OBJECTS)
|
|
||||||
|
|
||||||
.PHONY: run
|
.PHONY: run
|
||||||
run: $(OUT)
|
run: $(OUT)
|
||||||
./$^ $(ARGS)
|
./$^ $(ARGS)
|
||||||
|
|
||||||
|
.PHONY:
|
||||||
|
clean:
|
||||||
|
rm -v $(OUT)
|
||||||
|
|||||||
23
main.c
23
main.c
@@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
#define MEMORY_DEFAULT 30000
|
#define MEMORY_DEFAULT 30000
|
||||||
|
|
||||||
#define DEBUG 0
|
|
||||||
#define MIN_MEM_DUMP 64
|
#define MIN_MEM_DUMP 64
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -23,7 +22,7 @@ typedef struct
|
|||||||
size_t dp;
|
size_t dp;
|
||||||
uint8_t memory[MEMORY_DEFAULT];
|
uint8_t memory[MEMORY_DEFAULT];
|
||||||
|
|
||||||
#if DEBUG
|
#ifdef DEBUG
|
||||||
size_t dp_max;
|
size_t dp_max;
|
||||||
#endif
|
#endif
|
||||||
} machine_t;
|
} machine_t;
|
||||||
@@ -62,13 +61,13 @@ void interpret(machine_t *cpu, node_t *ast, size_t num)
|
|||||||
i = node.loop_ref;
|
i = node.loop_ref;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#if DEBUG
|
#ifdef DEBUG
|
||||||
if (cpu->dp > cpu->dp_max)
|
if (cpu->dp > cpu->dp_max)
|
||||||
cpu->dp_max = cpu->dp + 1;
|
cpu->dp_max = cpu->dp + 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#ifdef DEBUG
|
||||||
if (cpu->dp_max < MIN_MEM_DUMP)
|
if (cpu->dp_max < MIN_MEM_DUMP)
|
||||||
cpu->dp_max = MIN_MEM_DUMP;
|
cpu->dp_max = MIN_MEM_DUMP;
|
||||||
#endif
|
#endif
|
||||||
@@ -90,9 +89,9 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *filepath, *file_data;
|
char *filepath = NULL, *file_data = NULL;
|
||||||
buffer_t *buffer;
|
buffer_t *buffer = NULL;
|
||||||
struct PResult res;
|
struct PResult res = {0};
|
||||||
|
|
||||||
machine_t machine = {0};
|
machine_t machine = {0};
|
||||||
|
|
||||||
@@ -101,7 +100,7 @@ int main(int argc, char *argv[])
|
|||||||
filepath = argv[i];
|
filepath = argv[i];
|
||||||
|
|
||||||
FILE *handle = fopen(filepath, "r");
|
FILE *handle = fopen(filepath, "r");
|
||||||
#if DEBUG
|
#ifdef DEBUG
|
||||||
printf("[DEBUG]: Attempting to open file handle to %s\n", filepath);
|
printf("[DEBUG]: Attempting to open file handle to %s\n", filepath);
|
||||||
#endif
|
#endif
|
||||||
if (!handle)
|
if (!handle)
|
||||||
@@ -111,12 +110,12 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
file_data = fread_all(handle);
|
file_data = fread_all(handle);
|
||||||
fclose(handle);
|
fclose(handle);
|
||||||
#if DEBUG
|
#ifdef DEBUG
|
||||||
printf("[DEBUG]: Read data from file %s\n", filepath);
|
printf("[DEBUG]: Read data from file %s\n", filepath);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
buffer = buffer_init_str(filepath, file_data, strlen(file_data));
|
buffer = buffer_init_str(filepath, file_data, strlen(file_data));
|
||||||
#if DEBUG
|
#ifdef DEBUG
|
||||||
puts("[DEBUG]: Initialised buffer");
|
puts("[DEBUG]: Initialised buffer");
|
||||||
#endif
|
#endif
|
||||||
res = parse_buffer(buffer);
|
res = parse_buffer(buffer);
|
||||||
@@ -126,7 +125,7 @@ int main(int argc, char *argv[])
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#ifdef DEBUG
|
||||||
char *str = ast_to_str(res.nodes, res.size);
|
char *str = ast_to_str(res.nodes, res.size);
|
||||||
printf("[DEBUG]: Parsed buffer (%lu nodes parsed)\n\t[DEBUG]: Out=%s\n",
|
printf("[DEBUG]: Parsed buffer (%lu nodes parsed)\n\t[DEBUG]: Out=%s\n",
|
||||||
res.size, str);
|
res.size, str);
|
||||||
@@ -135,7 +134,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
interpret(&machine, res.nodes, res.size);
|
interpret(&machine, res.nodes, res.size);
|
||||||
|
|
||||||
#if DEBUG
|
#ifdef DEBUG
|
||||||
printf("[DEBUG]: Finished interpreting, memory:");
|
printf("[DEBUG]: Finished interpreting, memory:");
|
||||||
for (size_t i = 0; i < machine.dp_max; ++i)
|
for (size_t i = 0; i < machine.dp_max; ++i)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user