|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #ifndef lint
8: static char sccsid[] = "@(#)asm.c 5.1 (Berkeley) 5/31/85";
9: #endif not lint
10:
11: static char rcsid[] = "$Header: asm.c,v 1.5 84/12/26 10:38:19 linton Exp $";
12:
13: /*
14: * Assembly language dependent symbol routines.
15: */
16:
17: #include "defs.h"
18: #include "symbols.h"
19: #include "asm.h"
20: #include "languages.h"
21: #include "tree.h"
22: #include "eval.h"
23: #include "operators.h"
24: #include "mappings.h"
25: #include "process.h"
26: #include "runtime.h"
27: #include "machine.h"
28:
29: #define isdouble(range) ( \
30: range->symvalue.rangev.upper == 0 and range->symvalue.rangev.lower > 0 \
31: )
32:
33: /*
34: * Initialize assembly language information.
35: */
36:
37: public asm_init()
38: {
39: Language lang;
40:
41: lang = language_define("assembler", ".s");
42: language_setop(lang, L_PRINTDECL, asm_printdecl);
43: language_setop(lang, L_PRINTVAL, asm_printval);
44: language_setop(lang, L_TYPEMATCH, asm_typematch);
45: language_setop(lang, L_BUILDAREF, asm_buildaref);
46: language_setop(lang, L_EVALAREF, asm_evalaref);
47: language_setop(lang, L_HASMODULES, asm_hasmodules);
48: language_setop(lang, L_PASSADDR, asm_passaddr);
49: }
50:
51: /*
52: * Test if two types are compatible.
53: */
54:
55: public Boolean asm_typematch(type1, type2)
56: Symbol type1, type2;
57: {
58: Boolean b;
59:
60: b = false;
61: return b;
62: }
63:
64: public asm_printdecl(s)
65: Symbol s;
66: {
67: switch (s->class) {
68: case CONST:
69: printf("%s = %d", symname(s), s->symvalue.constval->value.lcon);
70: break;
71:
72: case VAR:
73: case REF:
74: printf("&%s = 0x%x", symname(s), s->symvalue.offset);
75: break;
76:
77: case PROC:
78: case FUNC:
79: printf("%s (0x%x):", symname(s), codeloc(s));
80: break;
81:
82: case TYPE:
83: printf("%s", symname(s));
84: break;
85:
86: case ARRAY:
87: printf("$string");
88: break;
89:
90: default:
91: printf("[%s]", classname(s));
92: break;
93: }
94: putchar('\n');
95: }
96:
97: /*
98: * Print out the value on the top of the expression stack
99: * in the format for the type of the given symbol.
100: */
101:
102: public asm_printval(s)
103: register Symbol s;
104: {
105: register Symbol t;
106: register Integer len;
107:
108: switch (s->class) {
109: case ARRAY:
110: t = rtype(s->type);
111: if (t->class == RANGE and istypename(t->type, "$char")) {
112: len = size(s);
113: sp -= len;
114: printf("\"%.*s\"", len, sp);
115: } else {
116: printarray(s);
117: }
118: break;
119:
120: default:
121: printf("0x%x", pop(Integer));
122: break;
123: }
124: }
125:
126: /*
127: * Treat subscripting as indirection through pointer to integer.
128: */
129:
130: public Node asm_buildaref(a, slist)
131: Node a, slist;
132: {
133: Symbol t, eltype;
134: Node p, r;
135:
136: t = rtype(a->nodetype);
137: eltype = t->type;
138: p = slist->value.arg[0];
139: r = build(O_MUL, p, build(O_LCON, (long) size(eltype)));
140: r = build(O_ADD, build(O_RVAL, a), r);
141: r->nodetype = eltype;
142: return r;
143: }
144:
145: /*
146: * Evaluate a subscript index. Assumes dimension is [0..n].
147: */
148:
149: public asm_evalaref(s, base, i)
150: Symbol s;
151: Address base;
152: long i;
153: {
154: Symbol t;
155:
156: t = rtype(s);
157: push(long, base + i * size(t->type));
158: }
159:
160: public boolean asm_hasmodules ()
161: {
162: return false;
163: }
164:
165: public boolean asm_passaddr (param, exprtype)
166: Symbol param, exprtype;
167: {
168: return false;
169: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.