vm-translator/templates.h

331 lines
4.2 KiB
C
Raw Normal View History

2020-10-31 21:53:11 -04:00
#ifndef templates
#define templates
2020-11-19 08:43:25 -05:00
typedef struct {
char** items;
int count;
} TEMPLATE;
char* tpushlns[] = {
2020-10-31 21:53:11 -04:00
"",
"",
"",
"",
"A=D+A",
"D=M",
"@SP",
2020-11-17 12:12:39 -05:00
"A=M",
"M=D",
"@SP",
2020-11-01 10:40:43 -05:00
"M=M+1",
2020-10-31 21:53:11 -04:00
};
2020-11-19 08:43:25 -05:00
TEMPLATE tpush = {
.items = tpushlns,
.count = sizeof(tpushlns) / sizeof(char*)
};
2020-10-31 21:53:11 -04:00
2020-11-19 08:43:25 -05:00
char* tpushconslns[] = {
2020-10-31 21:53:11 -04:00
"",
"",
"D=A",
"@SP",
2020-11-17 12:12:39 -05:00
"A=M",
"M=D",
"@SP",
2020-11-01 10:40:43 -05:00
"M=M+1",
2020-10-31 21:53:11 -04:00
};
2020-11-19 08:43:25 -05:00
TEMPLATE tpushcons = {
.items = tpushconslns,
.count = sizeof(tpushconslns) / sizeof(char*)
};
2020-10-31 21:53:11 -04:00
2020-11-19 08:43:25 -05:00
char* tpushstatlns[] = {
2020-10-31 21:53:11 -04:00
"",
"",
"D=M",
"@SP",
2020-11-17 12:12:39 -05:00
"A=M",
"M=D",
"@SP",
2020-11-01 10:40:43 -05:00
"M=M+1",
2020-10-31 21:53:11 -04:00
};
2020-11-19 08:43:25 -05:00
TEMPLATE tpushstat = {
.items = tpushstatlns,
.count = sizeof(tpushstatlns) / sizeof(char*)
};
2020-10-31 21:53:11 -04:00
2020-11-19 08:43:25 -05:00
TEMPLATE tpushtemp = {
.items = tpushstatlns,
.count = sizeof(tpushstatlns) / sizeof(char*)
};
2020-11-01 10:40:43 -05:00
2020-11-19 08:43:25 -05:00
TEMPLATE tpushpointer = {
.items = tpushstatlns,
.count = sizeof(tpushstatlns) / sizeof(char*)
};
2020-10-31 21:53:11 -04:00
2020-11-19 08:43:25 -05:00
char* tpoplns[] = {
2020-10-31 21:53:11 -04:00
"",
"",
"",
"",
"D=D+A",
"@R13",
"M=D",
"@SP",
2020-11-17 12:12:39 -05:00
"AM=M-1",
2020-10-31 21:53:11 -04:00
"D=M",
"@R13",
"A=M",
"M=D"
};
2020-11-19 08:43:25 -05:00
TEMPLATE tpop = {
.items = tpoplns,
.count = sizeof(tpoplns) / sizeof(char*)
};
2020-10-31 21:53:11 -04:00
2020-11-19 08:43:25 -05:00
char* tpopstatlns[] = {
2020-10-31 21:53:11 -04:00
"",
"@SP",
2020-11-17 12:12:39 -05:00
"AM=M-1",
2020-10-31 21:53:11 -04:00
"D=M",
"",
""
};
2020-11-19 08:43:25 -05:00
TEMPLATE tpopstat = {
.items = tpopstatlns,
.count = sizeof(tpopstatlns) / sizeof(char*)
};
2020-10-31 21:53:11 -04:00
2020-11-19 08:43:25 -05:00
TEMPLATE tpoptemp = {
.items = tpopstatlns,
.count = sizeof(tpopstatlns) / sizeof(char*)
};
2020-11-01 17:39:27 -05:00
2020-11-19 08:43:25 -05:00
TEMPLATE tpoppointer = {
.items = tpopstatlns,
.count = sizeof(tpopstatlns) / sizeof(char*)
};
2020-11-01 10:40:43 -05:00
2020-11-19 08:43:25 -05:00
char* tarithlns[] = {
2020-11-01 16:57:56 -05:00
"",
"@SP",
2020-11-17 12:12:39 -05:00
"AM=M-1",
2020-11-01 16:57:56 -05:00
"D=M",
"A=A-1",
""
};
2020-11-19 08:43:25 -05:00
TEMPLATE tarith = {
.items = tarithlns,
.count = sizeof(tarithlns) / sizeof(char*)
};
2020-11-01 16:57:56 -05:00
2020-11-19 08:43:25 -05:00
char* tneglns[] = {
2020-11-01 16:57:56 -05:00
"",
"@SP",
2020-11-01 17:11:11 -05:00
"A=M-1",
2020-11-01 16:57:56 -05:00
"M=-M",
};
2020-11-19 08:43:25 -05:00
TEMPLATE tneg = {
.items = tneglns,
.count = sizeof(tneglns) / sizeof(char*)
};
2020-11-01 16:57:56 -05:00
2020-11-19 08:43:25 -05:00
char* tnotlns[] = {
2020-11-01 16:57:56 -05:00
"",
"@SP",
2020-11-01 17:11:11 -05:00
"A=M-1",
2020-11-01 16:57:56 -05:00
"M=!M",
};
2020-11-19 08:43:25 -05:00
TEMPLATE tnot = {
.items = tnotlns,
.count = sizeof(tnotlns) / sizeof(char*)
};
2020-11-01 16:57:56 -05:00
2020-11-19 08:43:25 -05:00
char* tcomplns[] = {
2020-11-01 16:57:56 -05:00
"",
"@SP",
2020-11-17 12:12:39 -05:00
"AM=M-1",
2020-11-01 16:57:56 -05:00
"D=M",
"A=A-1",
"D=D-M",
2020-11-01 17:39:27 -05:00
"M=-1",
2020-11-01 16:57:56 -05:00
"",
"",
"@SP",
"A=M-1",
"M=0",
""
};
2020-11-19 08:43:25 -05:00
TEMPLATE tcomp = {
.items = tcomplns,
.count = sizeof(tcomplns) / sizeof(char*)
};
2020-11-14 10:31:57 -05:00
2020-11-19 08:43:25 -05:00
char* tlabellns[] = {
2020-11-14 10:31:57 -05:00
"",
""
};
2020-11-19 08:43:25 -05:00
TEMPLATE tlabel = {
.items = tlabellns,
.count = sizeof(tlabellns) / sizeof(char*)
};
2020-11-14 10:31:57 -05:00
2020-11-19 08:43:25 -05:00
char* tgotolns[] = {
2020-11-14 10:31:57 -05:00
"",
"",
"0;JMP"
};
2020-11-19 08:43:25 -05:00
TEMPLATE tgoto = {
.items = tgotolns,
.count = sizeof(tgotolns) / sizeof(char*)
};
2020-11-14 10:31:57 -05:00
2020-11-19 08:43:25 -05:00
char* tifgotolns[] = {
2020-11-14 10:31:57 -05:00
"",
"@SP",
2020-11-17 12:12:39 -05:00
"AM=M-1",
2020-11-14 10:31:57 -05:00
"D=M",
"",
"D;JNE"
};
2020-11-19 08:43:25 -05:00
TEMPLATE tifgoto = {
.items = tifgotolns,
.count = sizeof(tifgotolns) / sizeof(char*)
};
2020-11-14 10:31:57 -05:00
2020-11-19 08:43:25 -05:00
char* tcallstartlns[] = {
2020-11-17 12:12:39 -05:00
"",
"",
"D=A",
"@SP",
"A=M",
"M=D",
"@SP",
"M=M+1",
};
2020-11-19 08:43:25 -05:00
TEMPLATE tcallstart = {
.items = tcallstartlns,
.count = sizeof(tcallstartlns) / sizeof(char*)
};
2020-11-17 12:12:39 -05:00
2020-11-19 08:43:25 -05:00
char* tcallpushlns[] = {
2020-11-17 12:12:39 -05:00
"",
"D=M",
"@SP",
"A=M",
"M=D",
"@SP",
"M=M+1",
};
2020-11-19 08:43:25 -05:00
TEMPLATE tcallpush = {
.items = tcallpushlns,
.count = sizeof(tcallpushlns) / sizeof(char*)
};
2020-11-17 12:12:39 -05:00
2020-11-19 08:43:25 -05:00
char* tcallsetarglns[] = {
2020-11-17 12:12:39 -05:00
"@SP",
"D=M",
"@LCL",
"M=D",
"",
"D=D-A",
"@ARG",
"M=D"
};
2020-11-19 08:43:25 -05:00
TEMPLATE tcallsetarg = {
.items = tcallsetarglns,
.count = sizeof(tcallsetarglns) / sizeof(char*)
};
2020-11-17 12:12:39 -05:00
2020-11-19 08:43:25 -05:00
char* tcalljmplns[] = {
2020-11-17 12:12:39 -05:00
"",
"0;JMP",
""
};
2020-11-19 08:43:25 -05:00
TEMPLATE tcalljmp = {
.items = tcalljmplns,
.count = sizeof(tcalljmplns) / sizeof(char*)
};
2020-11-17 12:12:39 -05:00
2020-11-19 08:43:25 -05:00
char* tframevarslns[] = {
2020-11-17 12:12:39 -05:00
"@LCL",
"@ARG",
"@THIS",
"@THAT"
};
2020-11-19 08:43:25 -05:00
TEMPLATE tframevars = {
.items = tframevarslns,
.count = sizeof(tframevarslns) / sizeof(char*)
};
2020-11-17 12:12:39 -05:00
2020-11-19 08:43:25 -05:00
char* tfunctionlns[] = {
2020-11-17 12:12:39 -05:00
"",
""
};
2020-11-19 08:43:25 -05:00
TEMPLATE tfunction = {
.items = tfunctionlns,
.count = sizeof(tfunctionlns) / sizeof(char*)
};
2020-11-17 12:12:39 -05:00
2020-11-19 08:43:25 -05:00
char* tfunctionpushlns[] = {
2020-11-17 12:12:39 -05:00
"@SP",
"A=M",
"M=0",
"@SP",
"M=M+1"
};
2020-11-19 08:43:25 -05:00
TEMPLATE tfunctionpush = {
.items = tfunctionpushlns,
.count = sizeof(tfunctionpushlns) / sizeof(char*)
};
2020-11-17 12:12:39 -05:00
2020-11-19 08:43:25 -05:00
char* tstartreturnlns[] = {
2020-11-17 12:12:39 -05:00
"",
"@LCL",
"D=M",
"@5",
"A=D-A",
"D=M",
"@R13",
"M=D",
"@SP",
"A=M-1",
"D=M",
"@ARG",
"A=M",
"M=D",
"@ARG",
"D=M+1",
"@SP",
"M=D"
};
2020-11-19 08:43:25 -05:00
TEMPLATE tstartreturn = {
.items = tstartreturnlns,
.count = sizeof(tstartreturnlns) / sizeof(char*)
};
2020-11-17 12:12:39 -05:00
2020-11-19 08:43:25 -05:00
char* tretpoplns[] = {
2020-11-17 12:12:39 -05:00
"@LCL",
"AM=M-1",
"D=M",
"",
"M=D",
};
2020-11-19 08:43:25 -05:00
TEMPLATE tretpop = {
.items = tretpoplns,
.count = sizeof(tretpoplns) / sizeof(char*)
};
2020-11-17 12:12:39 -05:00
2020-11-19 08:43:25 -05:00
char* tendreturnlns[] = {
2020-11-17 12:12:39 -05:00
"@R13",
"A=M",
"0;JMP"
};
2020-11-19 08:43:25 -05:00
TEMPLATE tendreturn = {
.items = tendreturnlns,
.count = sizeof(tendreturnlns) / sizeof(char*)
};
2020-11-17 12:12:39 -05:00
2020-10-31 21:53:11 -04:00
#endif