Annotation of 43BSDReno/pgrm/dbx/asm.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.