-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodegen.h
More file actions
33 lines (25 loc) · 847 Bytes
/
codegen.h
File metadata and controls
33 lines (25 loc) · 847 Bytes
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
#ifndef CODEGEN_H
#define CODEGEN_H
#include "ast.h"
#include "symtab.h"
#include <stdio.h>
/* Code generator context */
typedef struct {
FILE *output;
SymbolTable *symtab;
int64_t current_line;
int64_t temp_base; /* Base address for reserved temporaries */
int64_t temp_top; /* Stack pointer for nested temporaries */
} CodeGen;
/* Initialize/finalize code generator */
CodeGen *codegen_create(FILE *output, SymbolTable *symtab);
void codegen_destroy(CodeGen *gen);
/* Generate code for entire program */
void codegen_program(CodeGen *gen, ASTNode *root);
/* Emit single instruction */
void emit(CodeGen *gen, const char *fmt, ...);
/* Get current instruction address */
int64_t codegen_current_addr(CodeGen *gen);
/* Patch jump address */
void codegen_patch(CodeGen *gen, int64_t addr, int64_t target);
#endif /* CODEGEN_H */