-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathir_buffer.h
63 lines (59 loc) · 1.29 KB
/
ir_buffer.h
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
63
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>
#include "symbols.h"
#ifndef _IR_BUFFER_H_
#define _IR_BUFFER_H_
/* args_count=2:
* GOTO x
* RETURN x
* ARG x
* PARAM x
* READ x
* WRITE x
* args_count=3:
* LABEL x :
* FUNCTION f :
* x := y
* x := &y
* x := *y
* *x := y
* DEC x [size]
* args_count=4:
* x := CALL f
* args_count=5:
* x := y + z
* x := y - z
* x := y * z
* x := y / z
* args_count=6:
* IF x [relop] y GOTO z
*/
//双向循环链表,存储代码在内存中的表示
typedef struct code_node
{
struct code_node* prev; //前一个
struct code_node* next; //后一个
int args_count; //有多少个词。具体见上面注释内的分类。
char args[6][32]; //每个词都是什么
}code_node;
#endif
typedef struct variable_alies
{
char name[32];
char othername;
struct variable_alies* next;
}variable_alies;
char* check_name(char* name);
//生成新的label,名称放在提供好的name里面。
void new_label(char* name);
//生成新的临时变量,名称放在提供好的name里面。
void new_temp(char* name);
//添加一条代码,指明这条代码的词数,然后传入各个词语,各个词语都是char*,即传入多个字符串
void add_code(int args_count,...);
//将内存中的代码打印到文件中,传入新文件路径,并顺便清理内存中的代码存储
void print_code(FILE* name);
//关闭优化
void close_opt();