1 /* 2 * Copyright (c) 1983 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)asm.c 5.4 (Berkeley) 06/01/90"; 10 #endif /* not lint */ 11 12 /* 13 * Assembly language dependent symbol routines. 14 */ 15 16 #include "defs.h" 17 #include "symbols.h" 18 #include "asm.h" 19 #include "languages.h" 20 #include "tree.h" 21 #include "eval.h" 22 #include "operators.h" 23 #include "mappings.h" 24 #include "process.h" 25 #include "runtime.h" 26 #include "machine.h" 27 28 #define isdouble(range) ( \ 29 range->symvalue.rangev.upper == 0 and range->symvalue.rangev.lower > 0 \ 30 ) 31 32 /* 33 * Initialize assembly language information. 34 */ 35 36 public asm_init() 37 { 38 Language lang; 39 40 lang = language_define("assembler", ".s"); 41 language_setop(lang, L_PRINTDECL, asm_printdecl); 42 language_setop(lang, L_PRINTVAL, asm_printval); 43 language_setop(lang, L_TYPEMATCH, asm_typematch); 44 language_setop(lang, L_BUILDAREF, asm_buildaref); 45 language_setop(lang, L_EVALAREF, asm_evalaref); 46 language_setop(lang, L_MODINIT, asm_modinit); 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 asm_modinit (typetable) 161 Symbol typetable[]; 162 { 163 /* nothing for right now */ 164 } 165 166 public boolean asm_hasmodules () 167 { 168 return false; 169 } 170 171 public boolean asm_passaddr (param, exprtype) 172 Symbol param, exprtype; 173 { 174 return false; 175 } 176