rename compiler to codegen + handle file not found

generics
cosmonaut 2021-04-28 16:10:17 -07:00
parent 49183bf1d3
commit 9a97b73c7c
6 changed files with 24 additions and 16 deletions

View File

@ -40,11 +40,11 @@ add_executable(
lib/dropt/dropt_handlers.c
# Source
src/ast.h
src/compiler.h
src/codegen.h
src/parser.h
src/stack.h
src/ast.c
src/compiler.c
src/codegen.c
src/parser.c
src/stack.c
src/main.c

View File

@ -813,7 +813,7 @@ static void Compile(LLVMModuleRef module, LLVMContextRef context, Node *node)
}
}
int Build(Node *node, uint32_t optimizationLevel)
int Codegen(Node *node, uint32_t optimizationLevel)
{
scope = CreateScope();

8
src/codegen.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef WRAITH_CODEGEN_H
#define WRAITH_CODEGEN_H
#include "ast.h"
int Codegen(Node *node, uint32_t optimizationLevel);
#endif /* WRAITH_CODEGEN_H */

View File

@ -1,8 +0,0 @@
#ifndef WRAITH_COMPILER_H
#define WRAITH_COMPILER_H
#include "ast.h"
int Build(Node *node, uint32_t optimizationLevel);
#endif /* WRAITH_COMPILER_H */

View File

@ -2,7 +2,7 @@
#include "../lib/dropt/dropt.h"
#include "parser.h"
#include "compiler.h"
#include "codegen.h"
int main(int argc, char *argv[])
{
@ -64,7 +64,7 @@ int main(int argc, char *argv[])
}
else
{
exitCode = Build(rootNode, optimizationLevel);
exitCode = Codegen(rootNode, optimizationLevel);
}
}
}

View File

@ -14,9 +14,17 @@ int Parse(char *inputFilename, Node **pRootNode, uint8_t parseVerbose)
yydebug = parseVerbose;
FILE *fp = fopen(inputFilename, "r");
yyin = fp;
result = yyparse(fp, stack, pRootNode);
fclose(fp);
if (fp != NULL)
{
yyin = fp;
result = yyparse(fp, stack, pRootNode);
fclose(fp);
}
else
{
fprintf(stderr, "File not found.\n");
return 3;
}
/* TODO: free stack */
/* TODO: free AST on error */