ANSI C conversion.

This commit is contained in:
carl 2019-05-11 01:14:54 +08:00
parent fa2859df79
commit 16f89747b1
3 changed files with 282 additions and 279 deletions

View file

@ -1,8 +1,8 @@
/* /*
Defines and externs of general interest Defines and externs of general interest
*/ */
#ifndef GLOBAL_H_
/* $Id$ */ #define GLOBAL_H_
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -157,3 +157,4 @@ extern ptr SL; /* Stack Limit */
#define min(i,j) (((i) < (j)) ? (i) : (j)) #define min(i,j) (((i) < (j)) ? (i) : (j))
#endif /* GLOBAL_H_ */

View file

@ -9,9 +9,11 @@
/* $Id$ */ /* $Id$ */
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
extern FILE *popen();
#include <ip_spec.h> #include <ip_spec.h>
#include <em_spec.h> #include <em_spec.h>
@ -26,7 +28,132 @@ FILE *ifp; /* Input File Pointer */
FILE *ofp; /* Output File Pointer */ FILE *ofp; /* Output File Pointer */
char *Prefix; /* Prefix for function name */ char *Prefix; /* Prefix for function name */
main(argc, argv)
int
in(flgs, c)
char *flgs;
char c;
{
while (*flgs)
if (c == *flgs++)
return 1;
return 0;
}
void OutCase(mnem, base, first, i, argstr)
char *mnem;
char *base;
int first;
int i;
char *argstr;
{
/* Output a case in the switch statement */
fprintf(ofp, "\t\tcase %s+%d:\t%s%s(%s); break;\n",
base, first+i, Prefix, mnem, argstr);
}
void ImplicitArg(argstr)
char *argstr;
{
sprintf(argstr, "uwpop()");
}
void NoArgs(argstr)
char *argstr;
{
sprintf(argstr, "");
}
void Mini(argstr, i, flgs)
char *argstr;
int i;
char *flgs;
{
int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i;
switch (newi) {
case -1:
sprintf(argstr, "%s",
in(flgs, 'w') ? "-wsize" : "-1L");
break;
case 0:
sprintf(argstr, "0L");
break;
case 1:
sprintf(argstr, "%s",
in(flgs, 'w') ? "wsize" : "1L");
break;
default:
sprintf(argstr, "%dL%s",
newi, in(flgs, 'w') ? "*wsize" : "");
break;
}
}
void Shortie(argstr, i, flgs)
char *argstr;
int i;
char *flgs;
{
int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i;
sprintf(argstr, "S_arg(%d)*%s",
newi, in(flgs, 'w') ? "wsize" : "1L");
}
void TwoSgn(argstr, flgs)
char *argstr;
char *flgs;
{
sprintf(argstr, "%s*%s", in(flgs, 'P') ? "P_arg_2()" : in(flgs, 'N') ? "N_arg_2()" : "L_arg_2()",
in(flgs, 'w') ? "wsize" : "1L");
}
void TwoUns(argstr, flgs)
char *argstr;
char *flgs;
{
sprintf(argstr, "%s*%s", "U_arg()",
in(flgs, 'w') ? "wsize" : "((unsigned long) 1)");
}
void FourSgn(argstr, flgs)
char *argstr;
char *flgs;
{
sprintf(argstr, "%s*%s", in(flgs, 'P') ? "P_arg_4()" : in(flgs, 'N') ? "N_arg_4()" : "L_arg_4()",
in(flgs, 'w') ? "wsize" : "1L");
}
void fatal(fmt, str)
char *fmt;
char *str;
{
fprintf(stderr, "%s, (fatal error): ", progname);
fprintf(stderr, fmt, str);
fprintf(stderr, "\n");
exit(1);
}
int getmnem(str) char *str ; {
char (*ptr)[4] ;
for ( ptr = em_mnem ; *ptr<= &em_mnem[sp_lmnem][0] ; ptr++ ) {
if ( strcmp(*ptr,str)==0 ) return (ptr-em_mnem) ;
}
fatal("%s","Illegal mnemonic") ;
return 0 ;
}
int main(argc, argv)
int argc; int argc;
char **argv; char **argv;
{ {
@ -148,128 +275,5 @@ main(argc, argv)
fatal("no opcode flag in ip_spec %s\n", flgs); fatal("no opcode flag in ip_spec %s\n", flgs);
} }
} }
exit(0); return EXIT_SUCCESS;
} }
OutCase(mnem, base, first, i, argstr)
char *mnem;
char *base;
int first;
int i;
char *argstr;
{
/* Output a case in the switch statement */
fprintf(ofp, "\t\tcase %s+%d:\t%s%s(%s); break;\n",
base, first+i, Prefix, mnem, argstr);
}
ImplicitArg(argstr)
char *argstr;
{
sprintf(argstr, "uwpop()");
}
NoArgs(argstr)
char *argstr;
{
sprintf(argstr, "");
}
Mini(argstr, i, flgs)
char *argstr;
int i;
char *flgs;
{
int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i;
switch (newi) {
case -1:
sprintf(argstr, "%s",
in(flgs, 'w') ? "-wsize" : "-1L");
break;
case 0:
sprintf(argstr, "0L");
break;
case 1:
sprintf(argstr, "%s",
in(flgs, 'w') ? "wsize" : "1L");
break;
default:
sprintf(argstr, "%dL%s",
newi, in(flgs, 'w') ? "*wsize" : "");
break;
}
}
Shortie(argstr, i, flgs)
char *argstr;
int i;
char *flgs;
{
int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i;
sprintf(argstr, "S_arg(%d)*%s",
newi, in(flgs, 'w') ? "wsize" : "1L");
}
TwoSgn(argstr, flgs)
char *argstr;
char *flgs;
{
sprintf(argstr, "%s*%s", in(flgs, 'P') ? "P_arg_2()" : in(flgs, 'N') ? "N_arg_2()" : "L_arg_2()",
in(flgs, 'w') ? "wsize" : "1L");
}
TwoUns(argstr, flgs)
char *argstr;
char *flgs;
{
sprintf(argstr, "%s*%s", "U_arg()",
in(flgs, 'w') ? "wsize" : "((unsigned long) 1)");
}
FourSgn(argstr, flgs)
char *argstr;
char *flgs;
{
sprintf(argstr, "%s*%s", in(flgs, 'P') ? "P_arg_4()" : in(flgs, 'N') ? "N_arg_4()" : "L_arg_4()",
in(flgs, 'w') ? "wsize" : "1L");
}
int
in(flgs, c)
char *flgs;
char c;
{
while (*flgs)
if (c == *flgs++)
return 1;
return 0;
}
fatal(fmt, str)
char *fmt;
char *str;
{
fprintf(stderr, "%s, (fatal error): ", progname);
fprintf(stderr, fmt, str);
fprintf(stderr, "\n");
exit(1);
}
int getmnem(str) char *str ; {
char (*ptr)[4] ;
for ( ptr = em_mnem ; *ptr<= &em_mnem[sp_lmnem][0] ; ptr++ ) {
if ( strcmp(*ptr,str)==0 ) return (ptr-em_mnem) ;
}
fatal("Illegal mnemonic") ;
return 0 ;
}

View file

@ -11,6 +11,7 @@
/* $Id$ */ /* $Id$ */
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
extern FILE *popen(); extern FILE *popen();
@ -22,7 +23,154 @@ FILE *ofp; /* Output File Pointer */
FILE *ffp = 0; /* Function File Pointer */ FILE *ffp = 0; /* Function File Pointer */
char *Prefix; /* Prefix for function name */ char *Prefix; /* Prefix for function name */
main(argc, argv) int in(char *flgs, char c)
{
while (*flgs)
if (c == *flgs++)
return 1;
return 0;
}
void NoArgs(base, first, mnem)
char *base;
int first;
char *mnem;
{
fprintf(ofp, "\t\tcase %s+%d:\t%s%sz(); break;\n",
base, first, Prefix, mnem);
if (ffp) {
fprintf(ffp, "%s%sz() {", Prefix, mnem);
fprintf(ffp, "LOG((\"@ %s%sz()\"));}\n", Prefix, mnem);
}
}
void Mini(i, flgs, base, first, mnem)
int i;
char *flgs;
char *base;
int first;
char *mnem;
{
char arg[16];
int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i;
switch (newi) {
case -1:
sprintf(arg, "%s",
in(flgs, 'w') ? "-wsize" : "-1L");
break;
case 0:
sprintf(arg, "0L");
break;
case 1:
sprintf(arg, "%s",
in(flgs, 'w') ? "wsize" : "1L");
break;
default:
sprintf(arg, "%dL%s",
newi, in(flgs, 'w') ? "*wsize" : "");
break;
}
fprintf(ofp, "\t\tcase %s+%d:\t%s%sm(%s); break;\n",
base, first+i, Prefix, mnem, arg);
if (ffp) {
fprintf(ffp, "%s%sm(arg) long arg; {",
Prefix, mnem);
fprintf(ffp, "LOG((\"@ %s%sm(%%d)\", arg));}\n",
Prefix, mnem);
}
}
void Shortie(i, flgs, base, first, mnem)
int i;
char *flgs;
char *base;
int first;
char *mnem;
{
char arg[16];
int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i;
sprintf(arg, "%dL, %s", newi, (in(flgs, 'w') ? "wsize" : "1L"));
fprintf(ofp, "\t\tcase %s+%d:\t%s%ss(%s); break;\n",
base, first+i, Prefix, mnem, arg);
if (ffp) {
fprintf(ffp, "%s%ss(hob, wfac) long hob; size wfac; {",
Prefix, mnem);
fprintf(ffp, "LOG((\"@ %s%ss(%%d)\", hob, wfac));",
Prefix, mnem);
fprintf(ffp, " newPC(PC+1);}\n");
}
}
void TwoSgn(flgs, base, first, mnem)
char *flgs;
char *base;
int first;
char *mnem;
{
char *xy = in(flgs, 'P') ? "p2" : in(flgs, 'N') ? "n2" : "l2";
fprintf(ofp, "\t\tcase %s+%d:\t%s%s%s(%s); break;\n",
base, first, Prefix, mnem, xy,
in(flgs, 'w') ? "wsize" : "1L");
if (ffp) {
fprintf(ffp, "%s%s%s(arg) long arg; {", Prefix, mnem, xy);
fprintf(ffp, "LOG((\"@ %s%s%s(%%d)\", arg));",
Prefix, mnem, xy);
fprintf(ffp, " newPC(PC+2);}\n");
}
}
void TwoUns(flgs, base, first, mnem)
char *flgs;
char *base;
int first;
char *mnem;
{
char *xy = "u";
fprintf(ofp, "\t\tcase %s+%d:\t%s%s%s(%s); break;\n",
base, first, Prefix, mnem, xy,
in(flgs, 'w') ? "wsize" : "1L");
if (ffp) {
fprintf(ffp, "%s%s%s(arg) long arg; {", Prefix, mnem, xy);
fprintf(ffp, "LOG((\"@ %s%s%s(%%d)\", arg));",
Prefix, mnem, xy);
fprintf(ffp, " newPC(PC+2);}\n");
}
}
void FourSgn(flgs, base, first, mnem)
char *flgs;
char *base;
int first;
char *mnem;
{
char *xy = in(flgs, 'P') ? "p4" : in(flgs, 'N') ? "n4" : "l4";
fprintf(ofp, "\t\tcase %s+%d:\t%s%s%s(%s); break;\n",
base, first, Prefix, mnem, xy,
in(flgs, 'w') ? "wsize" : "1L");
if (ffp) {
fprintf(ffp, "%s%s%s(arg) long arg; {", Prefix, mnem, xy);
fprintf(ffp, "LOG((\"@ %s%s%s(%%d)\", arg));",
Prefix, mnem, xy);
fprintf(ffp, " newPC(PC+4);}\n");
}
}
void fatal(char *fmt, char *str)
{
fprintf(stderr, "%s, (fatal error): ", progname);
fprintf(stderr, fmt, str);
fprintf(stderr, "\n");
exit(1);
}
int main(argc, argv)
int argc; int argc;
char **argv; char **argv;
{ {
@ -136,153 +284,3 @@ main(argc, argv)
} }
exit(0); exit(0);
} }
NoArgs(base, first, mnem)
char *base;
int first;
char *mnem;
{
fprintf(ofp, "\t\tcase %s+%d:\t%s%sz(); break;\n",
base, first, Prefix, mnem);
if (ffp) {
fprintf(ffp, "%s%sz() {", Prefix, mnem);
fprintf(ffp, "LOG((\"@ %s%sz()\"));}\n", Prefix, mnem);
}
}
Mini(i, flgs, base, first, mnem)
int i;
char *flgs;
char *base;
int first;
char *mnem;
{
char arg[16];
int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i;
switch (newi) {
case -1:
sprintf(arg, "%s",
in(flgs, 'w') ? "-wsize" : "-1L");
break;
case 0:
sprintf(arg, "0L");
break;
case 1:
sprintf(arg, "%s",
in(flgs, 'w') ? "wsize" : "1L");
break;
default:
sprintf(arg, "%dL%s",
newi, in(flgs, 'w') ? "*wsize" : "");
break;
}
fprintf(ofp, "\t\tcase %s+%d:\t%s%sm(%s); break;\n",
base, first+i, Prefix, mnem, arg);
if (ffp) {
fprintf(ffp, "%s%sm(arg) long arg; {",
Prefix, mnem);
fprintf(ffp, "LOG((\"@ %s%sm(%%d)\", arg));}\n",
Prefix, mnem);
}
}
Shortie(i, flgs, base, first, mnem)
int i;
char *flgs;
char *base;
int first;
char *mnem;
{
char arg[16];
int newi = in(flgs, 'N') ? (-i-1) : in(flgs, 'o') ? (i+1) : i;
sprintf(arg, "%dL, %s", newi, (in(flgs, 'w') ? "wsize" : "1L"));
fprintf(ofp, "\t\tcase %s+%d:\t%s%ss(%s); break;\n",
base, first+i, Prefix, mnem, arg);
if (ffp) {
fprintf(ffp, "%s%ss(hob, wfac) long hob; size wfac; {",
Prefix, mnem);
fprintf(ffp, "LOG((\"@ %s%ss(%%d)\", hob, wfac));",
Prefix, mnem);
fprintf(ffp, " newPC(PC+1);}\n");
}
}
TwoSgn(flgs, base, first, mnem)
char *flgs;
char *base;
int first;
char *mnem;
{
char *xy = in(flgs, 'P') ? "p2" : in(flgs, 'N') ? "n2" : "l2";
fprintf(ofp, "\t\tcase %s+%d:\t%s%s%s(%s); break;\n",
base, first, Prefix, mnem, xy,
in(flgs, 'w') ? "wsize" : "1L");
if (ffp) {
fprintf(ffp, "%s%s%s(arg) long arg; {", Prefix, mnem, xy);
fprintf(ffp, "LOG((\"@ %s%s%s(%%d)\", arg));",
Prefix, mnem, xy);
fprintf(ffp, " newPC(PC+2);}\n");
}
}
TwoUns(flgs, base, first, mnem)
char *flgs;
char *base;
int first;
char *mnem;
{
char *xy = "u";
fprintf(ofp, "\t\tcase %s+%d:\t%s%s%s(%s); break;\n",
base, first, Prefix, mnem, xy,
in(flgs, 'w') ? "wsize" : "1L");
if (ffp) {
fprintf(ffp, "%s%s%s(arg) long arg; {", Prefix, mnem, xy);
fprintf(ffp, "LOG((\"@ %s%s%s(%%d)\", arg));",
Prefix, mnem, xy);
fprintf(ffp, " newPC(PC+2);}\n");
}
}
FourSgn(flgs, base, first, mnem)
char *flgs;
char *base;
int first;
char *mnem;
{
char *xy = in(flgs, 'P') ? "p4" : in(flgs, 'N') ? "n4" : "l4";
fprintf(ofp, "\t\tcase %s+%d:\t%s%s%s(%s); break;\n",
base, first, Prefix, mnem, xy,
in(flgs, 'w') ? "wsize" : "1L");
if (ffp) {
fprintf(ffp, "%s%s%s(arg) long arg; {", Prefix, mnem, xy);
fprintf(ffp, "LOG((\"@ %s%s%s(%%d)\", arg));",
Prefix, mnem, xy);
fprintf(ffp, " newPC(PC+4);}\n");
}
}
int
in(flgs, c)
char *flgs;
char c;
{
while (*flgs)
if (c == *flgs++)
return 1;
return 0;
}
fatal(fmt, str)
char *fmt;
char *str;
{
fprintf(stderr, "%s, (fatal error): ", progname);
fprintf(stderr, fmt, str);
fprintf(stderr, "\n");
exit(1);
}