3 Commits

Author SHA1 Message Date
David Given
b6ff056a52 Rename branch.
--HG--
branch : unlabeled-1.1.1-branch
2015-06-18 23:39:28 +02:00
bal
39bc2f6d36 Bug fixed for pattern 'sti $1 > 4' (ADDREG -> ADDSCR)
--HG--
branch : unlabeled-1.1.1
1985-04-16 15:12:16 +00:00
cvs2hg
313b739836 fixup commit for branch 'unlabeled-1.1.1'
--HG--
branch : unlabeled-1.1.1
1984-07-19 09:37:25 +00:00
3 changed files with 2891 additions and 339 deletions

2588
mach/m68k2/cg/table Normal file

File diff suppressed because it is too large Load Diff

303
util/ack/rmach.c Normal file
View File

@@ -0,0 +1,303 @@
/*
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
*
* This product is part of the Amsterdam Compiler Kit.
*
* Permission to use, sell, duplicate or disclose this software must be
* obtained in writing. Requests for such permissions may be sent to
*
* Dr. Andrew S. Tanenbaum
* Wiskundig Seminarium
* Vrije Universiteit
* Postbox 7161
* 1007 MC Amsterdam
* The Netherlands
*
*/
#include "ack.h"
#include "../../h/em_path.h"
#include "list.h"
#include "trans.h"
#include "grows.h"
#include "dmach.h"
#include "data.h"
#include <stdio.h>
/************************************************************************/
/* */
/* Read machine definitions and transformations */
/* */
/************************************************************************/
#define COMMENT '#'
#define VAR "var"
#define PASS "name"
#define IN "from"
#define OUT "to"
#define PROG "program"
#define MAPF "mapflag"
#define ARGS "args"
#define PROP "prop"
#define RUNT "rts"
#define NEEDT "need"
#define END "end"
extern growstring scanb();
extern growstring scanvars();
int getline() ;
int getinchar() ;
static char *ty_name ;
static char *bol ;
static char *inname ;
setlist(name) char *name ; {
/* Name is sought in the internal tables,
if not present, the a file of that name is sought
in first the current and then the EM Lib directory
*/
inname=name ;
open_in(name) ;
while ( getline() ) {
if ( strcmp(VAR,ty_name)==0 ) {
doassign(bol,(char *)0,0) ;
} else
if ( strcmp(PASS,ty_name)==0 ) {
intrf() ;
} else
error("unknown keyword %s",ty_name) ;
}
close_in();
#ifdef DEBUG
if ( debug>=3 ) vprint("End %s\n",name) ;
#endif
}
intrf() {
register trf *new ;
register char *ptr ;
growstring bline, vline ;
int twice ;
new= (trf *)getcore(sizeof *new) ;
new->t_name= keeps(bol) ;
for (;;) {
if ( !getline() ) {
fuerror("unexpected EOF on %s",inname) ;
}
twice= NO ;
if ( strcmp(ty_name,IN)==0 ) {
if ( new->t_in ) twice=YES ;
new->t_in= keeps(bol);
} else
if ( strcmp(ty_name,OUT)==0 ) {
if ( new->t_out ) twice=YES ;
new->t_out= keeps(bol);
} else
if ( strcmp(ty_name,PROG)==0 ) {
if ( new->t_prog ) twice=YES ;
bline= scanb(bol); /* Scan for \ */
vline= scanvars(gr_start(bline)); /* Scan for {} */
gr_throw(&bline);
new->t_prog= gr_final(&vline);
clr_noscan(new->t_prog);
} else
if ( strcmp(ty_name,MAPF)==0 ) {
/* First read the mapflags line
and scan for backslashes */
bline= scanb(bol) ;
l_add(&new->t_mapf,gr_final(&bline)) ;
} else
if ( strcmp(ty_name,ARGS)==0 ) {
if ( new->t_argd ) twice=YES ;
bline= scanb(bol) ;
new->t_argd= keeps(gr_start(bline)) ;
gr_throw(&bline) ;
} else
if ( strcmp(ty_name,PROP)==0 ) {
for ( ptr=bol ; *ptr ; ptr++ ) {
switch( *ptr ) {
case C_IN: new->t_stdin= YES ; break ;
case C_OUT: new->t_stdout= YES ; break ;
case 'P': new->t_isprep= YES ; break ;
case 'p': new->t_prep= YES ; break ;
case 'm': new->t_prep= MAYBE ; break ;
case 'O': new->t_optim= YES ; break ;
case 'C': new->t_combine= YES ; break ;
default :
error("Unkown option %c in %s for %s",
*ptr,new->t_name,inname) ;
break ;
}
}
} else
if ( strcmp(ty_name,RUNT)==0 ) {
if ( new->t_rts ) twice=YES ;
new->t_rts= keeps(bol) ;
} else
if ( strcmp(ty_name,NEEDT)==0 ) {
if ( new->t_needed ) twice=YES ;
new->t_needed= keeps(bol) ;
} else
if ( strcmp(ty_name,END)==0 ) {
break ;
} else {
fuerror("illegal keyword %s %s",ty_name,bol);
}
if ( twice ) {
werror("%s: specified twice for %s",
ty_name, new->t_name) ;
}
}
if ( ! ( new->t_name && new->t_out && new->t_prog ) ) {
fuerror("insufficient specification for %s in %s",
new->t_name,inname) ;
}
if ( ! new->t_argd ) new->t_argd="" ;
#ifdef DEBUG
if ( debug>=3 ) {
register list_elem *elem ;
vprint("%s: from %s to %s '%s'\n",
new->t_name,new->t_in,new->t_out,new->t_prog) ;
vprint("\targs: ") ; prns(new->t_argd) ;
scanlist( l_first(new->t_mapf), elem ) {
vprint("\t%s\n",l_content(*elem)) ;
}
if ( new->t_rts ) vprint("\trts: %s\n",new->t_rts) ;
if ( new->t_needed ) vprint("\tneeded: %s\n",new->t_needed) ;
}
#endif
l_add(&tr_list,(char *)new) ;
}
/************************** IO from core or file *******************/
static int incore ;
static growstring rline ;
static FILE *infile ;
static char *inptr ;
open_in(name) register char *name ; {
register dmach *cmac ;
gr_init(&rline) ;
for ( cmac= massoc ; cmac->ma_index!= -1 ; cmac++ ) {
if ( strcmp(name,cmac->ma_name)==0 ) {
incore=YES ;
inptr= &intable[cmac->ma_index] ;
return ;
}
}
/* Not in core */
incore= NO ;
#ifdef NEW
gr_cat(&rline,EM_DIR) ;
gr_cat(&rline,"/lib/n_ack/") ;
#else
gr_cat(&rline,ACK_DIR); gr_cat(&rline,"/") ;
#endif
gr_cat(&rline,name) ;
infile= fopen(gr_start(rline),"r") ;
#ifdef NEW
if ( !infile ) {
/* Try to read EM_DIR/lib/MACH/plan */
gr_throw(&rline) ;
gr_cat(&rline,EM_DIR) ;
gr_cat(&rline,"/lib/") ; gr_cat(&rline,name) ;
gr_cat(&rline,"/plan") ;
infile= fopen(gr_start(rline),"r") ;
}
#endif
if ( !infile ) {
infile= fopen(name,"r") ;
}
if ( infile==NULL ) {
fuerror("Cannot find description for %s",name) ;
}
}
close_in() {
if ( !incore ) fclose(infile) ;
gr_throw(&rline) ;
}
char *readline() {
/* Get a line from the input,
return 0 if at end,
The line is stored in a volatile buffer,
a pointer to the line is returned.
*/
register int nchar ;
enum { BOL, ESCAPE, SKIPPING, MOL } state = BOL ;
gr_throw(&rline) ;
for (;;) {
nchar= getinchar() ;
if ( nchar==EOF ) {
if ( state!=BOL ) {
werror("incomplete line in %s", inname) ;
}
return 0 ;
}
if ( state==SKIPPING ) {
if ( nchar=='\n' ) {
state= MOL ;
} else {
continue ;
}
}
if ( state==ESCAPE ) {
switch( nchar ) {
case '\n' :
break ;
default :
gr_add(&rline,BSLASH) ;
case COMMENT :
case BSLASH :
gr_add(&rline,nchar) ;
break ;
}
state= MOL ;
continue ;
}
switch ( nchar ) {
case '\n' : gr_add(&rline,0) ;
return gr_start(rline) ;
case COMMENT : state= SKIPPING ;
break ;
case BSLASH : state= ESCAPE ;
break ;
default : gr_add(&rline,nchar) ;
state= MOL ;
}
}
}
int getinchar() {
if ( incore ) {
if ( *inptr==0 ) return EOF ;
return *inptr++ ;
}
return getc(infile) ;
}
int getline() {
register char *c_ptr ;
do {
if ( (c_ptr=readline())==(char *)0 ) return 0 ;
ty_name= skipblank(c_ptr) ;
} while ( *ty_name==0 ) ;
c_ptr= firstblank(ty_name) ;
if ( *c_ptr ) {
*c_ptr++ =0 ;
c_ptr= skipblank(c_ptr) ;
}
bol= c_ptr ;
return 1 ;
}

View File

@@ -1,339 +0,0 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/*
chtabgen - character table generator
Author: Erik Baalbergen (..tjalk!erikb)
Many mods by Ceriel Jacobs
*/
#include <stdio.h>
#ifndef NORCSID
static char *RcsId = "$Id$";
#endif
#define MAXBUF 256
#define MAXTAB 10000
#define COMCOM '-'
#define FILECOM '%'
int InputForm = 'c'; /* default input format (and, currently, only one) */
char OutputForm[MAXBUF] = "%s,\n";
/* format for spitting out a string */
char *Table[MAXTAB];
char *ProgCall; /* callname of this program */
int TabSize = 128; /* default size of generated table */
char *InitialValue; /* initial value of all table entries */
extern char *malloc(), *strcpy();
main(argc, argv)
char *argv[];
{
ProgCall = *argv++;
argc--;
while (argc-- > 0) {
if (**argv == COMCOM) {
option(*argv++);
}
else {
if (! process(*argv++, InputForm)) {
exit(1);
}
}
}
exit(0);
/*NOTREACHED*/
}
char *
Salloc(s)
char *s;
{
char *ns = malloc((unsigned)strlen(s) + 1);
if (ns) {
strcpy(ns, s);
}
else {
fprintf(stderr, "%s: out of memory\n", ProgCall);
exit(1);
}
return ns;
}
option(str)
char *str;
{
/* note that *str indicates the source of the option:
either COMCOM (from command line) or FILECOM (from a file).
*/
switch (*++str) {
case ' ': /* command */
case '\t':
case '\0':
break;
case 'I': /* for future extension */
InputForm = *++str;
break;
case 'f': /* input from file ... */
if (*++str == '\0') {
fprintf(stderr, "%s: -f: name expected\n", ProgCall);
exit(1);
}
DoFile(str);
break;
case 'F': /* new output format string */
sprintf(OutputForm, "%s\n", ++str);
break;
case 'T': /* insert text literally */
printf("%s\n", ++str);
break;
case 'p': /* print table */
PrintTable();
break;
case 'C': /* clear table */
InitTable((char *)0);
break;
case 'i': /* initialize table with given value */
if (*++str == '\0') {
InitTable((char *)0);
}
else InitTable(str);
break;
case 'S':
{
int i = atoi(++str);
if (i <= 0 || i > MAXTAB) {
fprintf(stderr, "%s: size would exceed maximum\n",
ProgCall);
}
else {
TabSize = i;
}
break;
}
default:
fprintf(stderr, "%s: bad option -%s\n", ProgCall, str);
}
}
InitTable(ival)
char *ival;
{
int i;
for (i = 0; i < TabSize; i++) {
Table[i] = 0;
}
InitialValue = 0;
if (ival) {
InitialValue = Salloc(ival);
}
}
PrintTable()
{
int i;
for (i = 0; i < TabSize; i++) {
if (Table[i]) {
printf(OutputForm, Table[i]);
}
else if (InitialValue) {
printf(OutputForm, InitialValue);
}
else {
printf(OutputForm, "0");
}
}
}
int
process(str, format)
char *str;
{
char *cstr = str;
char *Name = cstr; /* overwrite original string! */
/* strip of the entry name
*/
while (*str && *str != ':') {
if (*str == '\\') {
++str;
}
*cstr++ = *str++;
}
if (*str != ':') {
fprintf(stderr, "%s: bad specification: \"%s\", ignored\n",
ProgCall, Name);
return 0;
}
*cstr = '\0';
str++;
switch (format) {
case 'c':
return c_proc(str, Name);
default:
fprintf(stderr, "%s: bad input format\n", ProgCall);
}
return 0;
}
c_proc(str, Name)
char *str;
char *Name;
{
int ch, ch2;
int quoted();
char *name = Salloc(Name);
while (*str) {
if (*str == '\\') {
ch = quoted(&str);
}
else {
ch = *str++ & 0377;
}
if (*str == '-') {
if (*++str == '\\') {
ch2 = quoted(&str);
}
else {
if (ch2 = (*str++ & 0377));
else str--;
}
if (ch > ch2) {
fprintf(stderr, "%s: bad range\n", ProgCall);
return 0;
}
while (ch <= ch2) {
if (! setval(ch, name)) return 0;
ch++;
}
}
else {
if (! setval(ch, name)) return 0;
}
}
return 1;
}
int
setval(ch, nm)
char *nm;
{
char **p = &Table[ch];
if (ch < 0 || ch >= TabSize) {
fprintf(stderr, "Illegal index: %d\n", ch);
return 0;
}
if (*(p = &Table[ch])) {
fprintf(stderr, "Warning: redefinition of index %d\n", ch);
}
*p = nm;
return 1;
}
int
quoted(pstr)
char **pstr;
{
int ch;
int i;
char *str = *pstr;
if ((*++str >= '0') && (*str <= '9')) {
ch = 0;
for (i = 0; i < 3; i++) {
ch = 8 * ch + (*str - '0');
if (*++str < '0' || *str > '9')
break;
}
}
else {
switch (*str++) {
case 'n':
ch = '\n';
break;
case 't':
ch = '\t';
break;
case 'b':
ch = '\b';
break;
case 'r':
ch = '\r';
break;
case 'f':
ch = '\f';
break;
case 'v':
ch = 013;
break;
default :
ch = *(str - 1);
break;
}
}
*pstr = str;
return ch & 0377;
}
char *
getline(s, n, fp)
char *s;
FILE *fp;
{
int c = getc(fp);
char *str = s;
while (n--) {
if (c == EOF) {
return NULL;
}
else
if (c == '\n') {
*str++ = '\0';
return s;
}
*str++ = c;
c = getc(fp);
}
s[n - 1] = '\0';
return s;
}
#define BUFSIZE 1024
DoFile(name)
char *name;
{
char text[BUFSIZE];
FILE *fp;
if ((fp = fopen(name, "r")) == NULL) {
fprintf(stderr, "%s: cannot read file %s\n", ProgCall, name);
exit(1);
}
while (getline(text, BUFSIZE, fp) != NULL) {
if (text[0] == FILECOM) {
option(text);
}
else {
if (! process(text, InputForm)) {
exit(1);
}
}
}
}