feat: Split common module from compiler

This commit is contained in:
overflowerror 2024-02-23 23:07:01 +01:00
parent a4faf552be
commit c61076b835
24 changed files with 136 additions and 21 deletions

59
common/.gitignore vendored Normal file
View file

@ -0,0 +1,59 @@
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
#*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
obj/ast.o
gen/**
build/**
common.a
*.swp

42
common/Makefile Normal file
View file

@ -0,0 +1,42 @@
CC = gcc
CFLAGS = -std=c11 -D_POSIX_C_SOURCE=200809L -Wall -Wpedantic -g
LD = gcc
LDFLAGS =
AR = ar
ARFLAGS = rcs
OBJS = obj/alloc.o obj/dict.o obj/error.o obj/list.o
DEPS = $(OBJS:%.o=%.d)
-include $(DEPS)
all: common.a test
gen/lex.yy.c: src/lexer.l gen/y.tab.c
$(LEX) $(LEXFLAGS) -o $@ $<
gen/y.tab.c: src/parser.y src/ast.h ../common/src/error.h
$(YACC) $(YFLAGS) -o $@ $<
obj/lex.yy.o: gen/lex.yy.c
$(CC) $(CFLAGS) -c -o $@ $<
obj/y.tab.o: gen/y.tab.c
$(CC) $(CFLAGS) -c -o $@ $<
obj/%.o: src/%.c obj
$(CC) $(CFLAGS) -c -o $@ $<
common.a: CFLAGS += -fPIC
common.a: $(OBJS)
$(AR) $(ARFLAGS) $@ $^
test: common.a
@echo "no tests for common yet"
FORCE: ;
clean:
@echo "Cleaning up"
@rm -f obj/*.o
@rm -f obj/*.d
@rm common.a

0
common/obj/.gitignore vendored Normal file
View file

View file

@ -1,16 +1,16 @@
CC = gcc
CFLAGS = -std=c11 -D_POSIX_C_SOURCE=200809L -Wall -Wpedantic -g -I./src -I./gen
CFLAGS = -std=c11 -D_POSIX_C_SOURCE=200809L -Wall -Wpedantic -g -I./src/ -I../common/src/ -I./gen
LD = gcc
LDFLAGS =
YACC = bison
YFLAGS = -d
LEX = lex
LEXFLAGS =
MAKE = make
PLUGINS = obj/macros/numbers.o
OBJS = obj/lex.yy.o obj/y.tab.o obj/codegen.o obj/error.o \
obj/ast.o obj/alloc.o obj/dict.o obj/list.o obj/band.o \
OBJS = obj/lex.yy.o obj/y.tab.o obj/codegen.o obj/ast.o obj/band.o \
obj/plugins.o obj/scope.o $(PLUGINS) obj/main.o
DEPS = $(OBJS:%.o=%.d)
@ -21,7 +21,7 @@ all: macrofuck test
gen/lex.yy.c: src/lexer.l gen/y.tab.c
$(LEX) $(LEXFLAGS) -o $@ $<
gen/y.tab.c: src/parser.y src/ast.h src/error.h
gen/y.tab.c: src/parser.y src/ast.h ../common/src/error.h
$(YACC) $(YFLAGS) -o $@ $<
obj/lex.yy.o: gen/lex.yy.c
@ -31,9 +31,12 @@ obj/y.tab.o: gen/y.tab.c
obj/%.o: src/%.c obj
$(CC) $(CFLAGS) -c -o $@ $<
macrofuck: $(OBJS)
macrofuck: $(OBJS) ../common/common.a
$(LD) $(LDFLAGS) -o $@ $^
../common/common.a: FORCE
cd ../common/ && $(MAKE) common.a
test: macrofuck FORCE
./test/tests.sh "./macrofuck"
@ -41,6 +44,7 @@ FORCE: ;
clean:
@echo "Cleaning up"
@cd ../common/ && $(MAKE) clean
@rm -f obj/*.o
@rm -f obj/*.d
@rm -f gen/*.c

View file

@ -1,8 +1,9 @@
#include <stdlib.h>
#include <error.h>
#include <alloc.h>
#include "ast.h"
#include "error.h"
#include "alloc.h"
#define _new(n, t) struct t* n = safe_malloc(sizeof(struct t))

View file

@ -2,9 +2,9 @@
#include <stdlib.h>
#include <stdint.h>
#include <alloc.h>
#include "band.h"
#include "list.h"
#include "alloc.h"
band_t* band_init(void) {
band_t* band = safe_malloc(sizeof(band_t));

View file

@ -4,7 +4,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include "list.h"
#include <list.h>
typedef size_t band_addr_t;

View file

@ -2,11 +2,12 @@
#include <stdlib.h>
#include <string.h>
#include <error.h>
#include "codegen.h"
#include "ast.h"
#include "band.h"
#include "scope.h"
#include "error.h"
#include "plugins.h"

View file

@ -30,10 +30,10 @@ id [a-zA-Z_][a-zA-Z0-9_]*
#include <stdbool.h>
#include <string.h>
#include "y.tab.h"
#include <strbuf.h>
#include <error.h>
#include "strbuf.h"
#include "error.h"
#include "y.tab.h"
%}

View file

@ -1,5 +1,8 @@
#include <stdio.h>
#include <error.h>
#include "../scope.h"
#include "../error.h"
#include "../codegen.h"
extern region_t* to_str(FILE* out, scope_t* scope, const char* _arg) {

View file

@ -2,7 +2,8 @@
#include <stdlib.h>
#include <getopt.h>
#include "error.h"
#include <error.h>
#include "ast.h"
#include "codegen.h"
#include "plugins.h"

View file

@ -8,7 +8,8 @@
#include <string.h>
#include <errno.h>
#include "error.h"
#include <error.h>
#include "ast.h"
int yylex(void);

View file

@ -2,8 +2,9 @@
#include <dlfcn.h>
#include <error.h>
#include "plugins.h"
#include "error.h"
struct plugin {
const char* name;

View file

@ -1,10 +1,11 @@
#include <stdlib.h>
#include <stdbool.h>
#include <alloc.h>
#include <dict.h>
#include "scope.h"
#include "band.h"
#include "alloc.h"
#include "dict.h"
scope_t* scope_init(band_t* band) {
scope_t* root = scope_new(NULL);

View file

@ -1,7 +1,8 @@
#ifndef SCOPE_H
#define SCOPE_H
#include "dict.h"
#include <dict.h>
#include "band.h"
typedef struct scope {