1 /* 2 * Copyright (c) 1983 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 static char sccsid[] = "@(#)asm.c 5.3 (Berkeley) 05/23/89"; 20 #endif /* not lint */ 21 22 /* 23 * Assembly language dependent symbol routines. 24 */ 25 26 #include "defs.h" 27 #include "symbols.h" 28 #include "asm.h" 29 #include "languages.h" 30 #include "tree.h" 31 #include "eval.h" 32 #include "operators.h" 33 #include "mappings.h" 34 #include "process.h" 35 #include "runtime.h" 36 #include "machine.h" 37 38 #define isdouble(range) ( \ 39 range->symvalue.rangev.upper == 0 and range->symvalue.rangev.lower > 0 \ 40 ) 41 42 /* 43 * Initialize assembly language information. 44 */ 45 46 public asm_init() 47 { 48 Language lang; 49 50 lang = language_define("assembler", ".s"); 51 language_setop(lang, L_PRINTDECL, asm_printdecl); 52 language_setop(lang, L_PRINTVAL, asm_printval); 53 language_setop(lang, L_TYPEMATCH, asm_typematch); 54 language_setop(lang, L_BUILDAREF, asm_buildaref); 55 language_setop(lang, L_EVALAREF, asm_evalaref); 56 language_setop(lang, L_MODINIT, asm_modinit); 57 language_setop(lang, L_HASMODULES, asm_hasmodules); 58 language_setop(lang, L_PASSADDR, asm_passaddr); 59 } 60 61 /* 62 * Test if two types are compatible. 63 */ 64 65 public Boolean asm_typematch(type1, type2) 66 Symbol type1, type2; 67 { 68 Boolean b; 69 70 b = false; 71 return b; 72 } 73 74 public asm_printdecl(s) 75 Symbol s; 76 { 77 switch (s->class) { 78 case CONST: 79 printf("%s = %d", symname(s), s->symvalue.constval->value.lcon); 80 break; 81 82 case VAR: 83 case REF: 84 printf("&%s = 0x%x", symname(s), s->symvalue.offset); 85 break; 86 87 case PROC: 88 case FUNC: 89 printf("%s (0x%x):", symname(s), codeloc(s)); 90 break; 91 92 case TYPE: 93 printf("%s", symname(s)); 94 break; 95 96 case ARRAY: 97 printf("$string"); 98 break; 99 100 default: 101 printf("[%s]", classname(s)); 102 break; 103 } 104 putchar('\n'); 105 } 106 107 /* 108 * Print out the value on the top of the expression stack 109 * in the format for the type of the given symbol. 110 */ 111 112 public asm_printval(s) 113 register Symbol s; 114 { 115 register Symbol t; 116 register Integer len; 117 118 switch (s->class) { 119 case ARRAY: 120 t = rtype(s->type); 121 if (t->class == RANGE and istypename(t->type, "$char")) { 122 len = size(s); 123 sp -= len; 124 printf("\"%.*s\"", len, sp); 125 } else { 126 printarray(s); 127 } 128 break; 129 130 default: 131 printf("0x%x", pop(Integer)); 132 break; 133 } 134 } 135 136 /* 137 * Treat subscripting as indirection through pointer to integer. 138 */ 139 140 public Node asm_buildaref(a, slist) 141 Node a, slist; 142 { 143 Symbol t, eltype; 144 Node p, r; 145 146 t = rtype(a->nodetype); 147 eltype = t->type; 148 p = slist->value.arg[0]; 149 r = build(O_MUL, p, build(O_LCON, (long) size(eltype))); 150 r = build(O_ADD, build(O_RVAL, a), r); 151 r->nodetype = eltype; 152 return r; 153 } 154 155 /* 156 * Evaluate a subscript index. Assumes dimension is [0..n]. 157 */ 158 159 public asm_evalaref(s, base, i) 160 Symbol s; 161 Address base; 162 long i; 163 { 164 Symbol t; 165 166 t = rtype(s); 167 push(long, base + i * size(t->type)); 168 } 169 170 public asm_modinit (typetable) 171 Symbol typetable[]; 172 { 173 /* nothing for right now */ 174 } 175 176 public boolean asm_hasmodules () 177 { 178 return false; 179 } 180 181 public boolean asm_passaddr (param, exprtype) 182 Symbol param, exprtype; 183 { 184 return false; 185 } 186