summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile10
-rw-r--r--src/compiler/ast-tree.c2
-rw-r--r--src/compiler/ast-tree.h2
-rw-r--r--src/compiler/lexer.c2
-rw-r--r--src/compiler/lexer.h2
-rw-r--r--src/compiler/parser.c2
-rw-r--r--src/compiler/parser.h2
-rw-r--r--src/main.c6
8 files changed, 23 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index a1af4d8..ae30991 100644
--- a/Makefile
+++ b/Makefile
@@ -19,9 +19,13 @@ NC := \033[0m
INC_DIRS := $(SRC_DIR)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
-# CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 -O3
-# CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 -Oz
-CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 -g
+OP_FLAG := -O3
+# OP_FLAG := -Oz
+# OP_FLAG := -g
+
+# CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 -DPRINT_STATISTICS -DPRINT_COMPILE_TREE $(OP_FLAG)
+CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 -DPRINT_STATISTICS $(OP_FLAG)
+# CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 $(OP_FLAG)
EXEC_FILE := $(BUILD_DIR)/$(PROJECT_NAME)
diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c
index b770098..2201b4a 100644
--- a/src/compiler/ast-tree.c
+++ b/src/compiler/ast-tree.c
@@ -195,6 +195,7 @@ AstTreeRoots AST_TREE_ROOTS_ERROR = {
.size = -1ULL,
};
+#ifdef PRINT_COMPILE_TREE
void astTreePrint(const AstTree *tree, int indent) {
for (int i = 0; i < indent; ++i)
printf(" ");
@@ -600,6 +601,7 @@ void astTreeRootPrint(const AstTreeRoot *root) {
printf("\n");
}
}
+#endif
void astTreeDestroy(AstTree tree) {
if (tree.type != NULL) {
diff --git a/src/compiler/ast-tree.h b/src/compiler/ast-tree.h
index d60088d..68b8ec6 100644
--- a/src/compiler/ast-tree.h
+++ b/src/compiler/ast-tree.h
@@ -259,9 +259,11 @@ typedef struct AstTreeBuiltin {
AstTreeBuiltinToken token;
} AstTreeBuiltin;
+#ifdef PRINT_COMPILE_TREE
void astTreePrint(const AstTree *tree, int indent);
void astTreeVariablePrint(const AstTreeVariable *variable, int indent);
void astTreeRootPrint(const AstTreeRoot *root);
+#endif
void astTreeDestroy(AstTree tree);
void astTreeVariableDestroy(AstTreeVariable variable);
diff --git a/src/compiler/lexer.c b/src/compiler/lexer.c
index fa96203..8cf0cc3 100644
--- a/src/compiler/lexer.c
+++ b/src/compiler/lexer.c
@@ -180,6 +180,7 @@ bool lexerNodeArrayIsError(LexerNodeArray array) {
return LEXER_NODE_ARRAY_ERROR.size == array.size;
}
+#ifdef PRINT_COMPILE_TREE
void lexerNodeArrayPrint(LexerNodeArray array) {
for (size_t i = 0; i < array.size; ++i) {
LexerNode node = array.data[i];
@@ -187,6 +188,7 @@ void lexerNodeArrayPrint(LexerNodeArray array) {
node.str_begin, LEXER_TOKEN_STRINGS[node.token]);
}
}
+#endif
void lexerNodeArrayDestroy(LexerNodeArray array) { free(array.data); }
diff --git a/src/compiler/lexer.h b/src/compiler/lexer.h
index 71d9640..862efe7 100644
--- a/src/compiler/lexer.h
+++ b/src/compiler/lexer.h
@@ -138,7 +138,9 @@ typedef struct LexerNodeArray {
extern const LexerNodeArray LEXER_NODE_ARRAY_ERROR;
extern bool lexerNodeArrayIsError(LexerNodeArray array);
+#ifdef PRINT_COMPILE_TREE
extern void lexerNodeArrayPrint(LexerNodeArray array);
+#endif
extern void lexerNodeArrayDestroy(LexerNodeArray array);
extern LexerNodeArray lexer(char *str);
diff --git a/src/compiler/parser.c b/src/compiler/parser.c
index 956b834..7265c60 100644
--- a/src/compiler/parser.c
+++ b/src/compiler/parser.c
@@ -171,6 +171,7 @@ static const ParserOrder PARSER_ORDER[] = {
static const size_t PARSER_ORDER_SIZE =
sizeof(PARSER_ORDER) / sizeof(*PARSER_ORDER);
+#ifdef PRINT_COMPILE_TREE
void parserNodePrint(const ParserNode *node, int indent) {
for (int i = 0; i < indent; ++i)
printf(" ");
@@ -475,6 +476,7 @@ void parserNodePrint(const ParserNode *node, int indent) {
RETURN_SUCCESS:
printf("}");
}
+#endif
void parserNodeDelete(ParserNode *node) {
if (node == NULL) {
diff --git a/src/compiler/parser.h b/src/compiler/parser.h
index 25e9a21..0ee59a6 100644
--- a/src/compiler/parser.h
+++ b/src/compiler/parser.h
@@ -173,7 +173,9 @@ typedef struct ParserNodeBracketMetadata {
ParserNodeArray *params;
} ParserNodeBracketMetadata;
+#ifdef PRINT_COMPILE_TREE
void parserNodePrint(const ParserNode *node, int indent);
+#endif
void parserNodeDelete(ParserNode *node);
ParserNode *parserFromPath(const char *filePath);
diff --git a/src/main.c b/src/main.c
index fad415b..323b04b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,7 +6,7 @@
#include <time.h>
// #define PRINT_COMPILE_TREE
-#define PRINT_STATISTICS
+// #define PRINT_STATISTICS
#ifdef PRINT_STATISTICS
static struct timespec diff(struct timespec end, struct timespec start) {
@@ -53,7 +53,9 @@ static int run(const char *filePath) {
totalTime = add(totalTime, astTime);
#endif
#ifdef PRINT_COMPILE_TREE
- astTreeRootPrint(astTree);
+ for (size_t i = 0; i < astTrees.size; ++i) {
+ astTreeRootPrint(astTrees.data[i]);
+ }
#endif
#ifdef PRINT_STATISTICS
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);