121598Sdist /* 2*38105Sbostic * Copyright (c) 1983 The Regents of the University of California. 3*38105Sbostic * All rights reserved. 4*38105Sbostic * 5*38105Sbostic * Redistribution and use in source and binary forms are permitted 6*38105Sbostic * provided that the above copyright notice and this paragraph are 7*38105Sbostic * duplicated in all such forms and that any documentation, 8*38105Sbostic * advertising materials, and other materials related to such 9*38105Sbostic * distribution and use acknowledge that the software was developed 10*38105Sbostic * by the University of California, Berkeley. The name of the 11*38105Sbostic * University may not be used to endorse or promote products derived 12*38105Sbostic * from this software without specific prior written permission. 13*38105Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*38105Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*38105Sbostic * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1621598Sdist */ 179658Slinton 1821598Sdist #ifndef lint 19*38105Sbostic static char sccsid[] = "@(#)asm.c 5.3 (Berkeley) 05/23/89"; 20*38105Sbostic #endif /* not lint */ 219658Slinton 229658Slinton /* 239658Slinton * Assembly language dependent symbol routines. 249658Slinton */ 259658Slinton 269658Slinton #include "defs.h" 279658Slinton #include "symbols.h" 289658Slinton #include "asm.h" 299658Slinton #include "languages.h" 309658Slinton #include "tree.h" 319658Slinton #include "eval.h" 329658Slinton #include "operators.h" 339658Slinton #include "mappings.h" 349658Slinton #include "process.h" 359658Slinton #include "runtime.h" 369658Slinton #include "machine.h" 379658Slinton 389658Slinton #define isdouble(range) ( \ 399658Slinton range->symvalue.rangev.upper == 0 and range->symvalue.rangev.lower > 0 \ 409658Slinton ) 419658Slinton 429658Slinton /* 439658Slinton * Initialize assembly language information. 449658Slinton */ 459658Slinton 469658Slinton public asm_init() 479658Slinton { 489658Slinton Language lang; 499658Slinton 509658Slinton lang = language_define("assembler", ".s"); 519658Slinton language_setop(lang, L_PRINTDECL, asm_printdecl); 529658Slinton language_setop(lang, L_PRINTVAL, asm_printval); 539658Slinton language_setop(lang, L_TYPEMATCH, asm_typematch); 5418213Slinton language_setop(lang, L_BUILDAREF, asm_buildaref); 5518213Slinton language_setop(lang, L_EVALAREF, asm_evalaref); 5633308Sdonn language_setop(lang, L_MODINIT, asm_modinit); 5716606Ssam language_setop(lang, L_HASMODULES, asm_hasmodules); 5816606Ssam language_setop(lang, L_PASSADDR, asm_passaddr); 599658Slinton } 609658Slinton 619658Slinton /* 629658Slinton * Test if two types are compatible. 639658Slinton */ 649658Slinton 659658Slinton public Boolean asm_typematch(type1, type2) 669658Slinton Symbol type1, type2; 679658Slinton { 689658Slinton Boolean b; 699658Slinton 709658Slinton b = false; 719658Slinton return b; 729658Slinton } 739658Slinton 749658Slinton public asm_printdecl(s) 759658Slinton Symbol s; 769658Slinton { 779658Slinton switch (s->class) { 7818213Slinton case CONST: 7918213Slinton printf("%s = %d", symname(s), s->symvalue.constval->value.lcon); 8018213Slinton break; 8118213Slinton 829658Slinton case VAR: 839658Slinton case REF: 849658Slinton printf("&%s = 0x%x", symname(s), s->symvalue.offset); 859658Slinton break; 869658Slinton 879658Slinton case PROC: 889658Slinton case FUNC: 899658Slinton printf("%s (0x%x):", symname(s), codeloc(s)); 909658Slinton break; 919658Slinton 9218213Slinton case TYPE: 9318213Slinton printf("%s", symname(s)); 9418213Slinton break; 9518213Slinton 9618213Slinton case ARRAY: 9718213Slinton printf("$string"); 9818213Slinton break; 9918213Slinton 1009658Slinton default: 10118213Slinton printf("[%s]", classname(s)); 10218213Slinton break; 1039658Slinton } 1049658Slinton putchar('\n'); 1059658Slinton } 1069658Slinton 1079658Slinton /* 1089658Slinton * Print out the value on the top of the expression stack 1099658Slinton * in the format for the type of the given symbol. 1109658Slinton */ 1119658Slinton 1129658Slinton public asm_printval(s) 1139658Slinton register Symbol s; 1149658Slinton { 1159658Slinton register Symbol t; 1169658Slinton register Integer len; 1179658Slinton 1189658Slinton switch (s->class) { 1199658Slinton case ARRAY: 1209658Slinton t = rtype(s->type); 1219658Slinton if (t->class == RANGE and istypename(t->type, "$char")) { 1229658Slinton len = size(s); 1239658Slinton sp -= len; 1249658Slinton printf("\"%.*s\"", len, sp); 1259658Slinton } else { 1269658Slinton printarray(s); 1279658Slinton } 1289658Slinton break; 1299658Slinton 1309658Slinton default: 1319658Slinton printf("0x%x", pop(Integer)); 1329658Slinton break; 1339658Slinton } 1349658Slinton } 13516606Ssam 13618213Slinton /* 13718213Slinton * Treat subscripting as indirection through pointer to integer. 13818213Slinton */ 13918213Slinton 14018213Slinton public Node asm_buildaref(a, slist) 14118213Slinton Node a, slist; 14218213Slinton { 14318213Slinton Symbol t, eltype; 14418213Slinton Node p, r; 14518213Slinton 14618213Slinton t = rtype(a->nodetype); 14718213Slinton eltype = t->type; 14818213Slinton p = slist->value.arg[0]; 14918213Slinton r = build(O_MUL, p, build(O_LCON, (long) size(eltype))); 15018213Slinton r = build(O_ADD, build(O_RVAL, a), r); 15118213Slinton r->nodetype = eltype; 15218213Slinton return r; 15318213Slinton } 15418213Slinton 15518213Slinton /* 15618213Slinton * Evaluate a subscript index. Assumes dimension is [0..n]. 15718213Slinton */ 15818213Slinton 15918213Slinton public asm_evalaref(s, base, i) 16018213Slinton Symbol s; 16118213Slinton Address base; 16218213Slinton long i; 16318213Slinton { 16418213Slinton Symbol t; 16518213Slinton 16618213Slinton t = rtype(s); 16718213Slinton push(long, base + i * size(t->type)); 16818213Slinton } 16918213Slinton 17033308Sdonn public asm_modinit (typetable) 17133308Sdonn Symbol typetable[]; 17233308Sdonn { 17333308Sdonn /* nothing for right now */ 17433308Sdonn } 17533308Sdonn 17616606Ssam public boolean asm_hasmodules () 17716606Ssam { 17816606Ssam return false; 17916606Ssam } 18016606Ssam 18116606Ssam public boolean asm_passaddr (param, exprtype) 18216606Ssam Symbol param, exprtype; 18316606Ssam { 18416606Ssam return false; 18516606Ssam } 186