init basic
This commit is contained in:
8
ccompiler/middleend/tests/Makefile
Normal file
8
ccompiler/middleend/tests/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
all: test_ir
|
||||
|
||||
|
||||
test_ir: frontend
|
||||
gcc -g ../ir.c test_ir.c -L../../frontend -lfrontend -o test_ir
|
||||
|
||||
frontend:
|
||||
make -C ../../frontend
|
5
ccompiler/middleend/tests/test_file.c
Normal file
5
ccompiler/middleend/tests/test_file.c
Normal file
@ -0,0 +1,5 @@
|
||||
int main(void) {
|
||||
int a;
|
||||
a = 1 + 2 * 3;
|
||||
return a;
|
||||
}
|
18
ccompiler/middleend/tests/test_ir.c
Normal file
18
ccompiler/middleend/tests/test_ir.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include "../ir.h"
|
||||
#include "../../frontend/frontend.h"
|
||||
|
||||
int main(int argc, const char** argv) {
|
||||
const char* file_name = "test_file.c";
|
||||
if (argc == 2) {
|
||||
file_name = argv[1];
|
||||
}
|
||||
FILE* fp = fopen(file_name, "r");
|
||||
if (fp == NULL) {
|
||||
perror("open file failed");
|
||||
return 1;
|
||||
}
|
||||
printf("open file success\n");
|
||||
struct ASTNode* root = frontend("test.c", fp, (sread_fn)fread_s);
|
||||
gen_ir_from_ast(root);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user