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