Skip to content

Commit

Permalink
Building the validator foundations
Browse files Browse the repository at this point in the history
  • Loading branch information
fedi-nabli committed Apr 8, 2024
1 parent 8b0c0e7 commit 2150d52
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
OBJECTS = ./build/compiler.o ./build/cprocess.o ./build/lexer.o ./build/lex_process.o ./build/token.o ./build/parser.o ./build/node.o ./build/expressionable.o ./build/datatype.o ./build/scope.o ./build/symresolver.o ./build/array.o ./build/fixup.o ./build/codegen.o ./build/stackframe.o ./build/resolver.o ./build/rdefault.o ./build/helper.o ./build/preprocessor/preprocessor.o ./build/preprocessor/native.o ./build/preprocessor/static-include.o ./build/preprocessor/static-includes/stdarg.o ./build/preprocessor/static-includes/stddef.o ./build/helpers/buffer.o ./build/helpers/vector.o
OBJECTS = ./build/compiler.o ./build/cprocess.o ./build/lexer.o ./build/lex_process.o ./build/token.o ./build/parser.o ./build/node.o ./build/expressionable.o ./build/datatype.o ./build/scope.o ./build/symresolver.o ./build/array.o ./build/fixup.o ./build/validator.o ./build/codegen.o ./build/stackframe.o ./build/resolver.o ./build/rdefault.o ./build/helper.o ./build/preprocessor/preprocessor.o ./build/preprocessor/native.o ./build/preprocessor/static-include.o ./build/preprocessor/static-includes/stdarg.o ./build/preprocessor/static-includes/stddef.o ./build/helpers/buffer.o ./build/helpers/vector.o
INCLUDES = -I./

all: ${OBJECTS}
Expand Down Expand Up @@ -43,6 +43,9 @@ all: ${OBJECTS}
./build/fixup.o: ./fixup.h ./fixup.c
gcc ./fixup.c ${INCLUDES} -g -c -o ./build/fixup.o

./build/validator.o: ./validator.c
gcc ./validator.c ${INCLUDES} -g -c -o ./build/validator.o

./build/codegen.o: ./codegen.c
gcc ./codegen.c ${INCLUDES} -g -c -o ./build/codegen.o

Expand Down
5 changes: 5 additions & 0 deletions compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ int compile_file(const char* filename, const char* out_filename, int flags)
return PARSE_GENERAL_ERROR;
}

if (validate(process) != VALIDATOR_ALL_OK)
{
return VALIDATOR_GENERAL_ERROR;
}

// Perform code generation
if (codegen(process) != CODEGEN_ALL_OK)
{
Expand Down
9 changes: 9 additions & 0 deletions compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ enum
PARSE_GENERAL_ERROR
};

// Validator enums
enum
{
VALIDATOR_ALL_OK,
VALIDATOR_GENERAL_ERROR
};

// Codegen enums
enum
{
Expand Down Expand Up @@ -1227,6 +1234,8 @@ void compile_process_push_char(struct lex_process* lex_process, char c);
int lex(struct lex_process* process);
// Parse function
int parse(struct compile_process* process);
// Validator function
int validate(struct compile_process* process);
// Codegen funciton
int codegen(struct compile_process* process);
// Codegen register function
Expand Down
23 changes: 23 additions & 0 deletions validator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "compiler.h"

void validator_initialize(struct compile_process* process)
{
}

void validator_destruct(struct compile_process* process)
{
}

int validate_tree()
{
return VALIDATOR_ALL_OK;
}

int validate(struct compile_process* process)
{
int res = 0;
validator_initialize(process);
res = validate_tree();
validator_destruct(process);
return res;
}

0 comments on commit 2150d52

Please sign in to comment.