-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcode.c
More file actions
57 lines (47 loc) · 1.67 KB
/
code.c
File metadata and controls
57 lines (47 loc) · 1.67 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
/****************************************************/
/* File: code.c */
/* Code emitting utilities implementation for the */
/* C- compiler and interface to the TM machine */
/* tallate */
/****************************************************/
#include "globals.h"
#include "code.h"
static int emitLoc = 0;
static int highEmitLoc = 0;
void emitComment(char *c) {
if(TraceCode) { fprintf(code, "* %s\n", c); }
}
void emitRO(char *op, int r, int s, int t, char *c) {
fprintf(code, "%3d: %5s %d,%d,%d ",
emitLoc++, op, r, s, t);
if(TraceCode) { fprintf(code, " %s", c); }
fprintf(code, "\n");
if(highEmitLoc < emitLoc) { highEmitLoc = emitLoc; }
} /* emitRO */
void emitRM(char *op, int r, int d, int s, char *c) {
fprintf(code, "%3d: %5s %d,%d(%d) ", emitLoc++, op, r, d, s);
if(TraceCode) { fprintf(code, " %s", c); }
fprintf(code, "\n");
if(highEmitLoc < emitLoc) { highEmitLoc = emitLoc; }
} /* emitRM */
int emitSkip(int howMany) {
int i = emitLoc;
emitLoc += howMany;
if(highEmitLoc < emitLoc) { highEmitLoc = emitLoc; }
return i;
} /* emitSkip */
void emitBackup(int loc) {
if(loc > highEmitLoc) { emitComment("BUG in emitBackup"); }
emitLoc = loc;
} /* emitBackup */
void emitRestore(void) {
emitLoc = highEmitLoc;
}
void emitRM_Abs(char *op, int r, int a, char *c) {
fprintf(code, "%3d: %5s %d,%d(%d) ",
emitLoc, op, r, a - (emitLoc + 1), pc);
emitLoc++;
if(TraceCode) { fprintf(code, " %s", c); }
fprintf(code, "\n");
if(highEmitLoc < emitLoc) { highEmitLoc = emitLoc; }
} /* emitRM_Abs */