-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcprocess.c
62 lines (50 loc) · 1.54 KB
/
cprocess.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <stdlib.h>
#include "compiler.h"
#include "helpers/vector.h"
struct compile_process *compile_process_create(const char *filename,
const char *filename_out,
int flags) {
FILE *file = fopen(filename, "r");
if (!file) {
return NULL;
}
FILE *out_file = NULL;
if (filename_out) {
out_file = fopen(filename_out, "w");
if (!out_file) {
return NULL;
}
}
struct compile_process *process = calloc(1, sizeof(struct compile_process));
process->node_vec = vector_create(sizeof(struct node *));
process->node_tree_vec = vector_create(sizeof(struct node *));
process->flags = flags;
process->cfile.fp = file;
process->ofile = out_file;
process->generator = codegenerator_new(process);
process->resolver = resolver_default_new_process(process);
symresolver_initialize(process);
symresolver_new_table(process);
return process;
}
char compile_process_next_char(struct lex_process *lex_process) {
struct compile_process *compiler = lex_process->compiler;
compiler->pos.col += 1;
char c = getc(compiler->cfile.fp);
if (c == '\n') {
compiler->pos.line += 1;
compiler->pos.col = 1;
}
return c;
}
char compile_process_peek_char(struct lex_process *lex_process) {
struct compile_process *compiler = lex_process->compiler;
char c = getc(compiler->cfile.fp);
ungetc(c, compiler->cfile.fp);
return c;
}
void compile_process_push_char(struct lex_process *lex_process, char c) {
struct compile_process *compiler = lex_process->compiler;
ungetc(c, compiler->cfile.fp);
}