|
|
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.2 (Berkeley) 1/11/88";
9: #endif not lint
10:
11: static char rcsid[] = "$Header: asm.c,v 1.2 87/03/25 19:24:09 donn 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_MODINIT, asm_modinit);
48: language_setop(lang, L_HASMODULES, asm_hasmodules);
49: language_setop(lang, L_PASSADDR, asm_passaddr);
50: }
51:
52: /*
53: * Test if two types are compatible.
54: */
55:
56: public Boolean asm_typematch(type1, type2)
57: Symbol type1, type2;
58: {
59: Boolean b;
60:
61: b = false;
62: return b;
63: }
64:
65: public asm_printdecl(s)
66: Symbol s;
67: {
68: switch (s->class) {
69: case CONST:
70: printf("%s = %d", symname(s), s->symvalue.constval->value.lcon);
71: break;
72:
73: case VAR:
74: case REF:
75: printf("&%s = 0x%x", symname(s), s->symvalue.offset);
76: break;
77:
78: case PROC:
79: case FUNC:
80: printf("%s (0x%x):", symname(s), codeloc(s));
81: break;
82:
83: case TYPE:
84: printf("%s", symname(s));
85: break;
86:
87: case ARRAY:
88: printf("$string");
89: break;
90:
91: default:
92: printf("[%s]", classname(s));
93: break;
94: }
95: putchar('\n');
96: }
97:
98: /*
99: * Print out the value on the top of the expression stack
100: * in the format for the type of the given symbol.
101: */
102:
103: public asm_printval(s)
104: register Symbol s;
105: {
106: register Symbol t;
107: register Integer len;
108:
109: switch (s->class) {
110: case ARRAY:
111: t = rtype(s->type);
112: if (t->class == RANGE and istypename(t->type, "$char")) {
113: len = size(s);
114: sp -= len;
115: printf("\"%.*s\"", len, sp);
116: } else {
117: printarray(s);
118: }
119: break;
120:
121: default:
122: printf("0x%x", pop(Integer));
123: break;
124: }
125: }
126:
127: /*
128: * Treat subscripting as indirection through pointer to integer.
129: */
130:
131: public Node asm_buildaref(a, slist)
132: Node a, slist;
133: {
134: Symbol t, eltype;
135: Node p, r;
136:
137: t = rtype(a->nodetype);
138: eltype = t->type;
139: p = slist->value.arg[0];
140: r = build(O_MUL, p, build(O_LCON, (long) size(eltype)));
141: r = build(O_ADD, build(O_RVAL, a), r);
142: r->nodetype = eltype;
143: return r;
144: }
145:
146: /*
147: * Evaluate a subscript index. Assumes dimension is [0..n].
148: */
149:
150: public asm_evalaref(s, base, i)
151: Symbol s;
152: Address base;
153: long i;
154: {
155: Symbol t;
156:
157: t = rtype(s);
158: push(long, base + i * size(t->type));
159: }
160:
161: public asm_modinit (typetable)
162: Symbol typetable[];
163: {
164: /* nothing for right now */
165: }
166:
167: public boolean asm_hasmodules ()
168: {
169: return false;
170: }
171:
172: public boolean asm_passaddr (param, exprtype)
173: Symbol param, exprtype;
174: {
175: return false;
176: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.