|
|
1.1 root 1: /*
2: * The routines in this file
3: * completely dominate the execution time
4: * of the assembler. If you write tuned
5: * versions of them in assembly code, the
6: * performance of the assembler will be
7: * much better.
8: */
9: #include "asm.h"
10:
11: /*
12: * Read in an identifier.
13: * Pack the name, null filled, into
14: * the buffer `id'. The character `c'
15: * is the first character of the name;
16: * if < 0 then a character must be
17: * read.
18: */
19: getid(id, c)
20: register c;
21: char *id;
22: {
23: register char *e, *p;
24:
25: if (c < 0) {
26: do {
27: if ((c = *ip) != 0)
28: ++ip;
29: } while (c==' ' || c=='\t');
30: if (ctype[c] >= 0) /* Not LETTER */
31: qerr("invalid identifier");
32: }
33: p = id;
34: e = p + NCPLN;
35: do {
36: if (p < e)
37: *p++ = c;
38: if ((c = *ip) != 0)
39: ++ip;
40: } while (ctype[c] <= 0); /* LETTER or DIGIT */
41: if (c != 0)
42: --ip;
43: while (p < e)
44: *p++ = 0;
45: }
46:
47: /*
48: * Read a line from the standard I/O
49: * stream `sfp' into the buffer `ib' and
50: * return true if a line was obtained.
51: */
52: getline()
53: {
54: register char *p;
55: register c;
56:
57: p = ib;
58: while ((c=getc(sfp))!=EOF && c!='\n')
59: if (p < &ib[NINPUT-1])
60: *p++ = c;
61: *p = '\0';
62: return (c != EOF);
63: }
64:
65: /*
66: * Lookup the name `id' in the hashtable.
67: * If it is not found either return a
68: * `NULL' (`f' is false) or a
69: * pointer to a newly created hash table
70: * entry (`f' is true).
71: */
72: struct sym *
73: lookup(id, f)
74: char *id;
75: {
76: register struct sym *sp;
77: int ht;
78:
79: {
80: register char *p1;
81: register nc;
82:
83: ht = 0;
84: nc = NCPLN;
85: p1 = id;
86: do {
87: ht += *p1++;
88: } while (--nc);
89: }
90: if ((sp = symhash[ht&HMASK]) != NULL) {
91: do {
92: if (sp->s_total==ht && symeq(id, sp->s_id))
93: return (sp);
94: } while ((sp = sp->s_sp) != NULL);
95: }
96: if (f == 0)
97: return (NULL);
98: sp = (struct sym *) new(sizeof(struct sym));
99: sp->s_total = ht;
100: ht &= HMASK;
101: sp->s_sp = symhash[ht];
102: symhash[ht] = sp;
103: sp->s_kind = S_NEW;
104: sp->s_type = E_ACON;
105: sp->s_flag = S_SYMT;
106: sp->s_addr = 0;
107: symcopy(sp->s_id, id);
108: return (sp);
109: }
110:
111: /*
112: * Compare two symbol names.
113: */
114: symeq(p1, p2)
115: register char *p1, *p2;
116: {
117: register n;
118:
119: n = NCPLN;
120: do {
121: if (*p1++ != *p2++)
122: return (0);
123: } while (--n);
124: return (1);
125: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.