-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodeWriter.h
27 lines (24 loc) · 883 Bytes
/
codeWriter.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
#ifndef CODEWRITER_H
#define CODEWRITER_H
#include <fstream>
#include "parser.h"
class CodeWriter {
public:
CodeWriter(std::ofstream& output);
void setFileName(const std::string& inputName);
void writeArithmetic(const std::string& command);
void writePushPop(CommandType commandType, const std::string& segment, const std::string& index);
void writeLabel(const std::string& label);
void writeGoto(const std::string& label);
void writeIf(const std::string& label);
void writeCall(const std::string& functionName, int numArgs);
void writeFunction(const std::string& functionName, int numLocals);
void writeReturn();
void close();
private:
std::ofstream& output;
int counter;
int currentCall;
std::string currentFunction; // swap to the function when writing it, and revert to empty once the return is reached.
};
#endif