1994-06-24 11:31:16 +00:00
|
|
|
/* $Id$ */
|
1987-03-09 19:15:41 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1984-11-26 13:43:22 +00:00
|
|
|
/* I N T E R M E D I A T E C O D E
|
|
|
|
*
|
|
|
|
* I C _ I O . C
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
1991-03-05 12:16:17 +00:00
|
|
|
#include <em_pseu.h>
|
|
|
|
#include <em_spec.h>
|
|
|
|
#include <arch.h>
|
1984-11-26 13:43:22 +00:00
|
|
|
#include "../share/types.h"
|
|
|
|
#include "../share/debug.h"
|
|
|
|
#include "ic.h"
|
|
|
|
#include "ic_lookup.h"
|
|
|
|
#include "../share/alloc.h"
|
|
|
|
#include "ic_io.h"
|
|
|
|
|
|
|
|
|
|
|
|
STATIC short libstate;
|
|
|
|
STATIC long bytecnt;
|
|
|
|
|
|
|
|
STATIC FILE *infile; /* The current EM input file */
|
|
|
|
|
|
|
|
STATIC int readbyte()
|
|
|
|
{
|
|
|
|
if (libstate == ARCHIVE && bytecnt-- == 0L) {
|
|
|
|
/* If we're reading from an archive file, we'll
|
|
|
|
* have to count the number of characters read,
|
|
|
|
* to know where the current module ends.
|
|
|
|
*/
|
|
|
|
return EOF;
|
|
|
|
}
|
|
|
|
return getc(infile);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
short readshort() {
|
|
|
|
register int l_byte, h_byte;
|
|
|
|
|
|
|
|
l_byte = readbyte();
|
|
|
|
h_byte = readbyte();
|
|
|
|
if ( h_byte>=128 ) h_byte -= 256 ;
|
|
|
|
return l_byte | (h_byte*256) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef LONGOFF
|
|
|
|
offset readoffset() {
|
|
|
|
register long l;
|
|
|
|
register int h_byte;
|
|
|
|
|
|
|
|
l = readbyte();
|
|
|
|
l |= ((unsigned) readbyte())*256 ;
|
|
|
|
l |= readbyte()*256L*256L ;
|
|
|
|
h_byte = readbyte() ;
|
|
|
|
if ( h_byte>=128 ) h_byte -= 256 ;
|
|
|
|
return l | (h_byte*256L*256*256L) ;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
short get_int() {
|
|
|
|
|
|
|
|
switch(table2()) {
|
|
|
|
default: error("int expected");
|
|
|
|
case CSTX1:
|
|
|
|
return(tabval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char readchar()
|
|
|
|
{
|
|
|
|
return(readbyte());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
offset get_off() {
|
|
|
|
|
|
|
|
switch (table2()) {
|
|
|
|
default: error("offset expected");
|
|
|
|
case CSTX1:
|
|
|
|
return((offset) tabval);
|
|
|
|
#ifdef LONGOFF
|
|
|
|
case CSTX2:
|
|
|
|
return(tabval2);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 22:05:22 +00:00
|
|
|
STATIC void make_string(n) int n; {
|
1984-11-26 13:43:22 +00:00
|
|
|
|
1985-09-06 11:39:06 +00:00
|
|
|
sprintf(string,".%u",n);
|
1984-11-26 13:43:22 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 22:05:22 +00:00
|
|
|
STATIC void inident() {
|
|
|
|
register int n;
|
1984-11-26 13:43:22 +00:00
|
|
|
register char *p = string;
|
2019-10-31 22:05:22 +00:00
|
|
|
register int c;
|
1984-11-26 13:43:22 +00:00
|
|
|
|
|
|
|
n = get_int();
|
|
|
|
while (n--) {
|
|
|
|
c = readbyte();
|
|
|
|
if (p<&string[IDL])
|
|
|
|
*p++ = c;
|
|
|
|
}
|
|
|
|
*p++ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int table3(n) int n; {
|
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
case sp_ilb1: tabval = readbyte(); return(ILBX);
|
|
|
|
case sp_ilb2: tabval = readshort(); return(ILBX);
|
|
|
|
case sp_dlb1: make_string(readbyte()); return(DLBX);
|
|
|
|
case sp_dlb2: make_string(readshort()); return(DLBX);
|
|
|
|
case sp_dnam: inident(); return(DLBX);
|
|
|
|
case sp_pnam: inident(); return(n);
|
|
|
|
case sp_cst2: tabval = readshort(); return(CSTX1);
|
|
|
|
#ifdef LONGOFF
|
|
|
|
case sp_cst4: tabval2 = readoffset(); return(CSTX2);
|
|
|
|
#endif
|
|
|
|
case sp_doff: if (table2()!=DLBX) error("symbol expected");
|
|
|
|
switch(table2()) {
|
|
|
|
default: error("offset expected");
|
|
|
|
case CSTX1: return(VALX1);
|
|
|
|
#ifdef LONGOFF
|
|
|
|
case CSTX2: return(VALX2);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
default: return(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int table1() {
|
2019-10-31 22:05:22 +00:00
|
|
|
register int n;
|
1984-11-26 13:43:22 +00:00
|
|
|
|
|
|
|
n = readbyte();
|
|
|
|
if (n == EOF)
|
|
|
|
return(ATEOF);
|
|
|
|
if ((n <= sp_lmnem) && (n >= sp_fmnem)) {
|
|
|
|
tabval = n;
|
|
|
|
return(INST);
|
|
|
|
}
|
|
|
|
if ((n <= sp_lpseu) && (n >= sp_fpseu)) {
|
|
|
|
tabval = n;
|
|
|
|
return(PSEU);
|
|
|
|
}
|
|
|
|
if ((n < sp_filb0 + sp_nilb0) && (n >= sp_filb0)) {
|
|
|
|
tabval = n - sp_filb0;
|
|
|
|
return(ILBX);
|
|
|
|
}
|
|
|
|
return(table3(n));
|
|
|
|
}
|
|
|
|
|
|
|
|
int table2() {
|
2019-10-31 22:05:22 +00:00
|
|
|
register int n;
|
1984-11-26 13:43:22 +00:00
|
|
|
|
|
|
|
n = readbyte();
|
|
|
|
if ((n < sp_fcst0 + sp_ncst0) && (n >= sp_fcst0)) {
|
|
|
|
tabval = n - sp_zcst0;
|
|
|
|
return(CSTX1);
|
|
|
|
}
|
|
|
|
return(table3(n));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-31 22:05:22 +00:00
|
|
|
void file_init(FILE *f, short state, long length)
|
1984-11-26 13:43:22 +00:00
|
|
|
{
|
|
|
|
short n;
|
|
|
|
|
|
|
|
infile = f;
|
|
|
|
libstate = state;
|
|
|
|
bytecnt = length;
|
|
|
|
linecount = 0;
|
|
|
|
n = readshort();
|
|
|
|
if (n != (short) sp_magic) {
|
|
|
|
error("wrong magic number: %d", n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-31 22:05:22 +00:00
|
|
|
void arch_init(arch)
|
1984-11-26 13:43:22 +00:00
|
|
|
FILE *arch;
|
|
|
|
{
|
|
|
|
short n;
|
|
|
|
|
|
|
|
infile = arch;
|
|
|
|
n = readshort();
|
1991-03-20 16:24:50 +00:00
|
|
|
if (n != (short)ARMAG && n != (short)AALMAG) {
|
1984-11-26 13:43:22 +00:00
|
|
|
error("wrong archive magic number: %d",n);
|
|
|
|
}
|
|
|
|
}
|