-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomp.c
More file actions
74 lines (74 loc) · 1.31 KB
/
comp.c
File metadata and controls
74 lines (74 loc) · 1.31 KB
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
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "main.h"
#include "comp.h"
int level = 0;
void iprintfln(const char* fmt,...) {
va_list ap;
for (int i = 0; i < level; i++) {
fprintf(outfile, "\t");
}
va_start(ap, fmt);
vfprintf(outfile, fmt, ap);
fprintf(outfile, "\n");
}
void iprintf(const char* fmt,...) {
va_list ap;
for (int i = 0; i < level; i++) {
fprintf(outfile, "\t");
}
va_start(ap, fmt);
vfprintf(outfile, fmt, ap);
}
void iprintAdd(int x) {
if (x == 0) {
return;
}
if (x > 0) {
fprintf(outfile, "+");
}
fprintf(outfile, "%d", x);
}
void iprintCoeff(int x) {
if (x == 1) {
return;
}
fprintf(outfile, "%d*", x);
}
void iprintDiv(int x) {
if (x == 1) {
return;
}
fprintf(outfile, "/%d", x);
}
void comp(char* outname) {
int i = 0;
for (int x = 0; outname[x]; x++) {
if (outname[x] == '.') {
i = x;
}
}
outname += i+1;
if (target == NULL) {
if (strcmp(outname, "go") == 0) {
compGo();
} else if (strcmp(outname, "s") == 0) {
//TODO target native assembly
compMips();
} else {
compC();
}
} else {
if (strcmp(target, "c") == 0) {
compC();
} else if (strcmp(target, "go") == 0) {
compGo();
} else if (strcmp(target, "mips") == 0) {
compMips();
} else if (strcmp(target, "spim") == 0) {
compSpim();
}
}
}