-
Notifications
You must be signed in to change notification settings - Fork 0
/
IntermediaryCode.h
55 lines (48 loc) · 1.17 KB
/
IntermediaryCode.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
// Ernesto Vaz de Oliveira - 00302470
// Ricco Vasconcellos Constante Soares - 00307968
#pragma once
#include "Symbol.h"
#include "AbstractSyntaxTree.h"
#include "SymbolTable.h"
typedef enum three_address_code_type{
TACSymbol,
TACMove,
TACAccess,
TACAdd,
TACSub,
TACMul,
TACDiv,
TACNeg,
TACLess,
TACGreater,
TACAnd,
TACOr,
TACLeq,
TACGeq,
TACEq,
TACDif,
TACLabel,
TACBeginFun,
TACEndFun,
TACJump,
TACJumpF,
TACCall,
TACArg,
TACRet,
TACPrint,
TACRead
} ThreeAddressCodeType;
typedef struct three_address_code{
ThreeAddressCodeType type;
Symbol* operator1;
Symbol* operator2;
Symbol* result;
struct three_address_code* previous;
struct three_address_code* next;
} ThreeAddressCode;
ThreeAddressCode* createCode(ThreeAddressCodeType type, Symbol* op1, Symbol* op2, Symbol* res);
ThreeAddressCode* joinCodes(ThreeAddressCode* c1, ThreeAddressCode* c2);
ThreeAddressCode* generateCode(SyntaxTreeNode* node, SymbolTable* table);
ThreeAddressCode* reverseCode(ThreeAddressCode* code);
void printCode(ThreeAddressCode* code);
void printCodeList(ThreeAddressCode* code);