-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_generator.h
49 lines (41 loc) · 1.38 KB
/
code_generator.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
/*
* Project 3
* Author: B10630221 Chang-Ting Kao
* Date: 2019/06/05
*/
#ifndef CODE_GENERATOR_H
#define CODE_GENERATOR_H
#include <fstream>
#include <map>
#include <string>
#include "token_node.h"
#define JASM_MAX_STACK 15
class CodeGenerator
{
public:
CodeGenerator(std::ofstream* output, std::map<std::string, SymbolTable*> &symbolTableMap, std::vector<std::string> &sourceLines, bool outputComment, bool outputOperatorType);
// Generate jasm file using specific TokneNode
void GenerateJasm(TokenNode* programNode);
private:
std::ofstream* output;
std::map<std::string, SymbolTable*> &symbolTableMap;
std::vector<std::string> sourceLines;
std::string className;
int labelCounter;
int currentLine = 0;
bool outputComment;
bool outputOperatorType;
// Value type to java string
std::string ValueTypeToString(yy::ValueType valueType);
// Get unique label
std::string GetNewLabel();
// Value to local const command
std::string ValueToLocalConstCommand(ValueType valueType, Value value);
// Value to local variable command
std::string ValueToLocalVariableCommand(ValueType valueType, int id);
// Value to local variable command
std::string ArrayValueToLocalVariableCommand(ValueType valueType, int id);
// Symbol table entry to assign command
std::string EntryToAssignCommand(SymbolTableEntry* entry);
};
#endif