mirror of
https://github.com/sigmasternchen/macrofuck
synced 2025-03-15 23:28:55 +00:00
feat: Split common module from compiler
This commit is contained in:
parent
a4faf552be
commit
c61076b835
24 changed files with 136 additions and 21 deletions
59
common/.gitignore
vendored
Normal file
59
common/.gitignore
vendored
Normal 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
42
common/Makefile
Normal 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
0
common/obj/.gitignore
vendored
Normal 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
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "list.h"
|
||||
#include <list.h>
|
||||
|
||||
typedef size_t band_addr_t;
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
%}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "error.h"
|
||||
#include <error.h>
|
||||
|
||||
#include "ast.h"
|
||||
|
||||
int yylex(void);
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <error.h>
|
||||
|
||||
#include "plugins.h"
|
||||
#include "error.h"
|
||||
|
||||
struct plugin {
|
||||
const char* name;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef SCOPE_H
|
||||
#define SCOPE_H
|
||||
|
||||
#include "dict.h"
|
||||
#include <dict.h>
|
||||
|
||||
#include "band.h"
|
||||
|
||||
typedef struct scope {
|
||||
|
|
Loading…
Reference in a new issue