diff options
| author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-04-24 19:37:45 +0330 | 
|---|---|---|
| committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-04-24 19:37:45 +0330 | 
| commit | caf6ecd9344b13c443435f94c3c5b8ccf717e853 (patch) | |
| tree | 881708e5e0b49067fa8e43ee0c76df5a29431602 | |
| parent | cfc289f11c09aad28482204255934742e0f3f87f (diff) | |
some clean ups
| -rw-r--r-- | Makefile | 10 | ||||
| -rw-r--r-- | src/compiler/ast-tree.c | 2 | ||||
| -rw-r--r-- | src/compiler/ast-tree.h | 2 | ||||
| -rw-r--r-- | src/compiler/lexer.c | 2 | ||||
| -rw-r--r-- | src/compiler/lexer.h | 2 | ||||
| -rw-r--r-- | src/compiler/parser.c | 2 | ||||
| -rw-r--r-- | src/compiler/parser.h | 2 | ||||
| -rw-r--r-- | src/main.c | 6 | 
8 files changed, 23 insertions, 5 deletions
@@ -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); @@ -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);  |