ack/util/misc/convert.c

92 lines
1.9 KiB
C
Raw Normal View History

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".
*/
1987-02-05 14:47:47 +00:00
#ifndef NORCSID
1994-06-24 11:31:16 +00:00
static char rcsid[] = "$Id$";
1987-02-05 14:47:47 +00:00
#endif
/* This program converts either human-readable or compact EM
assembly code to calls of the procedure-interface.
It must be linked with two libraries:
- a library to read EM code, according to read_em(3)
- a library implementing the em_code(3) interface.
Thus, this program could serve as an EM_encoder, an
EM_decoder, or some code generator, depending on how it is
linked.
*/
1987-03-29 13:00:40 +00:00
#include <system.h>
1987-02-05 14:47:47 +00:00
#include <em_pseu.h>
#include <em_mnem.h>
#include <em_spec.h>
#include <em_flag.h>
#include <em_ptyp.h>
#include <em.h>
#include <em_comp.h>
char *filename; /* Name of input file */
int errors; /* Number of errors */
1990-04-23 13:43:05 +00:00
extern char *C_error;
1987-02-05 14:47:47 +00:00
main(argc,argv)
char **argv;
{
struct e_instr buf;
register struct e_instr *p = &buf;
1987-02-05 14:47:47 +00:00
if (argc >= 2) {
filename = argv[1];
}
else filename = 0;
if (!EM_open(filename)) {
fatal(EM_error);
}
EM_getinstr(p);
1987-02-05 14:47:47 +00:00
C_init((arith) EM_wordsize, (arith) EM_pointersize);
if (argc >= 3) {
if (!C_open(argv[2])) {
fatal("C_open failed");
}
}
else if (!C_open( (char *) 0)) fatal("C_open failed");
C_magic();
while (p->em_type != EM_EOF) {
1987-02-05 14:47:47 +00:00
if (p->em_type == EM_FATAL) {
1987-03-09 12:52:10 +00:00
fatal("%s", EM_error);
1987-02-05 14:47:47 +00:00
}
1987-03-31 08:15:22 +00:00
if (EM_error) {
1987-03-09 12:52:10 +00:00
error("%s", EM_error);
1987-02-05 14:47:47 +00:00
}
1990-04-23 13:43:05 +00:00
if (p->em_type != EM_ERROR && !C_out(p)) {
error("%s", C_error);
1987-02-05 14:47:47 +00:00
}
EM_getinstr(p);
1987-02-05 14:47:47 +00:00
}
C_close();
EM_close();
1987-03-09 12:52:10 +00:00
exit(errors);
1987-02-05 14:47:47 +00:00
}
/* VARARGS */
error(s,a1,a2,a3,a4)
char *s;
{
1987-03-29 13:00:40 +00:00
fprint(STDERR,
1987-02-05 14:47:47 +00:00
"%s, line %d: ",
filename ? filename : "standard input",
EM_lineno);
1987-03-29 13:00:40 +00:00
fprint(STDERR,s,a1,a2,a3,a4);
fprint(STDERR, "\n");
1987-02-05 14:47:47 +00:00
errors++;
}
/* VARARGS */
fatal(s,a1,a2,a3,a4)
char *s;
{
if (C_busy()) C_close();
1987-02-05 14:47:47 +00:00
error(s,a1,a2,a3,a4);
exit(1);
}