diff --git a/Makefile b/Makefile index 8a832d3..ba71b9b 100644 --- a/Makefile +++ b/Makefile @@ -1,42 +1,40 @@ -#Makefile for yab2cpp -#by Samuel D. Crow +CC := clang++ +CFLAGS := -Wall +CFLAGS += -std=c++11 +CFLAGS += -O0 +LFLAGS := -#presently architecture-neutral +ODIR := build -CC=g++ -LD=g++ +YABCODESTRUCTURES_SOURCE_DEPS := yabCodeStructures.cpp yab2cpp.h yab2cpp.cpp +YAB2CPP_SOURCE_DEPS := yab2cpp.cpp yab2cpp.h +YABDATASTRUCTURES_SOURCE_DEPS := yabDataStructures.cpp yab2cpp.h yab2cpp.cpp +YABFUNCTIONS_SOURCE_DEPS := yabFunctions.cpp yab2cpp.h yab2cpp.cpp -#release build -#FLAGS=-c -Os -std=c++11 -#LDFLAGS=LDFLAGS=-std=c++11 +all: binaries -#debug build -FLAGS=-c -g -Og -std=c++11 -LDFLAGS=-std=c++11 +$(ODIR): + @mkdir $(ODIR) -AR=ar r +binaries: bin_yab2cpp -default: yab2cpp +YAB2CPP_OBJECT_DEPS := $(ODIR)/yab2cpp.o $(ODIR)/yabCodeStructures.o $(ODIR)/yabDataStructures.o $(ODIR)/yabFunctions.o -yabDataStructures.o: yabDataStructures.cpp yab2cpp.h - $(CC) $(FLAGS) -o yabDataStructures.o yabDataStructures.cpp +bin_yab2cpp: $(ODIR) $(YAB2CPP_OBJECT_DEPS) + clang++ -v -o yab2cpp $(ODIR)/yabCodeStructures.o $(ODIR)/yabFunctions.o $(ODIR)/yabDataStructures.o $(ODIR)/yab2cpp.o -yabCodeStructures.o: yabCodeStructures.cpp yab2cpp.h - $(CC) $(FLAGS) -o yabCodeStructures.o yabCodeStructures.cpp +$(ODIR)/yabCodeStructures.o: $(ODIR) $(YABCODESTRUCTURES_SOURCE_DEPS) + $(CC) -c $(CFLAGS) yabCodeStructures.cpp -o $(ODIR)/yabCodeStructures.o -yabFunctions.o: yabFunctions.cpp yab2cpp.h - $(CC) $(FLAGS) -o yabFunctions.o yabFunctions.cpp +$(ODIR)/yab2cpp.o: $(ODIR) $(YAB2CPP_SOURCE_DEPS) + $(CC) -c $(CFLAGS) yab2cpp.cpp -o $(ODIR)/yab2cpp.o -yab2cpp.o: yab2cpp.cpp yab2cpp.h - $(CC) $(FLAGS) -o yab2cpp.o yab2cpp.cpp +$(ODIR)/yabDataStructures.o: $(ODIR) $(YABDATASTRUCTURES_SOURCE_DEPS) + $(CC) -c $(CFLAGS) yabDataStructures.cpp -o $(ODIR)/yabDataStructures.o -#BASIC_framework.a: yabDataStructures.o yabCodeStructures.o yabFunctions.o -# $(AR) BASIC_framework.a yabDataStructures.o yabCodeStructures.o yabFunctions.o - -#yab2cpp: BASIC_framework.a yab2cpp.o -yab2cpp: yab2cpp.o yabCodeStructures.o yabDataStructures.o yabFunctions.o - $(LD) $(LDFLAGS) -o yab2cpp yab2cpp.o yabCodeStructures.o yabDataStructures.o yabFunctions.o -#BASIC_framework.a +$(ODIR)/yabFunctions.o: $(ODIR) $(YABFUNCTIONS_SOURCE_DEPS) + $(CC) -c $(CFLAGS) yabFunctions.cpp -o $(ODIR)/yabFunctions.o +.PHONY: clean clean: - rm -f *.o yab2cpp BASIC_framework.a + rm -rf build/* yab2cpp diff --git a/yab2cpp.cpp b/yab2cpp.cpp index cf83516..5009831 100644 --- a/yab2cpp.cpp +++ b/yab2cpp.cpp @@ -76,7 +76,7 @@ ofstream logfile; ofstream varNames; /* private prototypes */ -void helpText(string); +void helpText(const string); void setup(); void compile(); void shutDown(); @@ -135,7 +135,7 @@ int main(int argc, char *argv[]) } /* print the help text to stdout */ -void helpText(string &commandname) +void helpText(const string commandname) { cout << commandname << "[-d|D|V|v|G] < filename.mb\n" << "Compiles filename.mb by default unless a flag is specified.\n" << @@ -174,7 +174,7 @@ void setUp() } } -void error(enum COMPILE_ERRORS e) +[[noreturn]] void error(enum COMPILE_ERRORS e) { errorLevel=e; exit(1); diff --git a/yab2cpp.h b/yab2cpp.h index 34a9be4..86b790a 100644 --- a/yab2cpp.h +++ b/yab2cpp.h @@ -149,7 +149,7 @@ enum OPERATORS }; /* global prototype */ -void error(enum COMPILE_ERRORS err); +[[noreturn]] void error(enum COMPILE_ERRORS err); void logger(string s); /* internal states used by the parser */ diff --git a/yabCodeStructures.cpp b/yabCodeStructures.cpp index eeb77d6..b7c4e36 100644 --- a/yabCodeStructures.cpp +++ b/yabCodeStructures.cpp @@ -50,11 +50,7 @@ void label::generateJumpTo() /* pass this as second parameter to generateOnNTo or generateOnNSub */ unsigned int label::generateOnNSkip(list >&dest) { - if (dest.size()<2) - { - errorLevel=E_BAD_SYNTAX; - exit(1); - } + if (dest.size()<2)error(E_BAD_SYNTAX); auto iter=dest.begin(); consts_h << "j" << this->getID() << "[]={" << *iter; ++iter; @@ -130,12 +126,8 @@ void ifStatement::alternative(shared_ptre) void ifStatement::close() { - if(this->chain) - { - /* elsif ended without else in between */ - errorLevel=E_BAD_SYNTAX; - exit(1); - } + /* elsif ended without else in between */ + if(this->chain)error(E_BAD_SYNTAX); this->done->generate(); } diff --git a/yabFunctions.cpp b/yabFunctions.cpp index 356adc8..e154b22 100644 --- a/yabFunctions.cpp +++ b/yabFunctions.cpp @@ -125,8 +125,7 @@ void fn::generateReturn() fn::callStack.pop_back(); break; default: - errorLevel=E_TYPE_MISMATCH; - exit(1); + error(E_TYPE_MISMATCH); } }