-
Notifications
You must be signed in to change notification settings - Fork 0
/
translator.hpp
66 lines (61 loc) · 2.54 KB
/
translator.hpp
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
64
65
66
#ifndef TRANSLATOR_HPP
#define TRANSLATOR_HPP
#include <string>
#include "parser.hpp"
class Translator
{
public:
enum EQUALITY_CHECK_TYPE
{
EQ_CHECK,
GT_CHECK,
LT_CHECK
};
Translator();
void setSymbolPrefix(const std::string &prefix);
std::string initializeStackPointer(const int stackAddress);
std::string generatePushInstruction(const std::string &segmentStackPointer,
const int index);
std::string generatePushConstantInstruction(const int value);
std::string generatePushZeroToStackInstruction();
std::string generatePushTempInstruction(const int index);
std::string generatePushPointerInstruction(const int index);
std::string generatePushStaticInstruction(const int index);
std::string generatePopInstruction(const std::string &segmentStackPointer,
const int index);
std::string generatePopTempInstruction(const int index);
std::string generatePopPointerInstruction(const int index);
std::string generatePopStaticInstruction(const int index);
std::string generateArithmeticInstruction(const std::string &op);
std::string generateLabelInstruction(const std::string &symbol);
std::string generateConditionalGotoInstruction(const std::string &symbol);
std::string generateGotoInstruction(const std::string &symbol);
std::string generateFnDeclInstruction(const std::string &symbol,
const int localVars);
std::string generateCallInstruction(const std::string &symbol,
const int pushedVars = 0);
std::string generateReturnInstruction();
int getCurrentInstructionNumber();
private:
int equalitySymbolId;
int callSymbolId;
int instructionCount;
std::string symbolPrefix;
std::string currentFunctionName;
std::string makeLine(const std::string &string,
bool dontIncreaseInstructionNumber = false);
std::string getNextEqualitySymbolId();
std::string generateStaticSymbol(const int index);
std::string selectStackPointer();
std::string incrementStackPointer();
std::string decrementStackPointer();
std::string selectStack();
std::string addLabel(const std::string &string);
std::string equalityCheck(const Translator::EQUALITY_CHECK_TYPE checkType,
const std::string &symbolName);
std::string selectRegister(const std::string &string);
std::string selectRegister(const int r);
std::string pushRegisterToStack(const std::string &string);
void setCurrentFunctionName(const std::string &string);
};
#endif