1987-04-29 10:22:07 +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".
|
|
|
|
*
|
|
|
|
* Author: Ceriel J.H. Jacobs
|
|
|
|
*/
|
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
/* M A I N P R O G R A M */
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1987-04-29 10:22:07 +00:00
|
|
|
/* $Header$ */
|
|
|
|
|
1986-05-01 19:06:53 +00:00
|
|
|
#include "debug.h"
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
#include <system.h>
|
|
|
|
#include <em_arith.h>
|
1986-03-26 17:53:13 +00:00
|
|
|
#include <em_label.h>
|
1986-04-21 17:27:06 +00:00
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
#include "input.h"
|
|
|
|
#include "f_info.h"
|
|
|
|
#include "idf.h"
|
|
|
|
#include "LLlex.h"
|
|
|
|
#include "Lpars.h"
|
1986-03-26 17:53:13 +00:00
|
|
|
#include "type.h"
|
|
|
|
#include "def.h"
|
1986-04-03 00:44:39 +00:00
|
|
|
#include "scope.h"
|
1986-03-26 17:53:13 +00:00
|
|
|
#include "standards.h"
|
1986-04-08 18:15:46 +00:00
|
|
|
#include "tokenname.h"
|
1986-04-22 22:36:16 +00:00
|
|
|
#include "node.h"
|
1986-11-05 14:33:00 +00:00
|
|
|
#include "warning.h"
|
1987-04-29 10:22:07 +00:00
|
|
|
#include "SYSTEM.h"
|
1986-03-26 15:11:02 +00:00
|
|
|
|
1986-06-06 02:22:09 +00:00
|
|
|
int state; /* either IMPLEMENTATION or PROGRAM */
|
|
|
|
char options[128];
|
|
|
|
int DefinitionModule;
|
|
|
|
char *ProgName;
|
1987-05-11 14:38:37 +00:00
|
|
|
char **DEFPATH;
|
|
|
|
int nDEF, mDEF;
|
1986-06-06 02:22:09 +00:00
|
|
|
struct def *Defined;
|
|
|
|
extern int err_occurred;
|
|
|
|
extern int fp_used; /* set if floating point used */
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-11-26 16:40:45 +00:00
|
|
|
extern C_inp(), C_exp();
|
|
|
|
int (*c_inp)() = C_inp;
|
|
|
|
|
1986-03-20 14:52:03 +00:00
|
|
|
main(argc, argv)
|
1986-07-08 14:59:02 +00:00
|
|
|
register char **argv;
|
1986-03-20 14:52:03 +00:00
|
|
|
{
|
1986-04-17 09:28:09 +00:00
|
|
|
register int Nargc = 1;
|
1986-03-20 14:52:03 +00:00
|
|
|
register char **Nargv = &argv[0];
|
|
|
|
|
|
|
|
ProgName = *argv++;
|
1986-11-05 14:33:00 +00:00
|
|
|
warning_classes = W_INITIAL;
|
1987-05-11 14:38:37 +00:00
|
|
|
DEFPATH = (char **) Malloc(10 * sizeof(char *));
|
|
|
|
mDEF = 10;
|
|
|
|
nDEF = 1;
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
|
|
while (--argc > 0) {
|
|
|
|
if (**argv == '-')
|
1986-05-01 19:06:53 +00:00
|
|
|
DoOption((*argv++) + 1);
|
1986-03-20 14:52:03 +00:00
|
|
|
else
|
|
|
|
Nargv[Nargc++] = *argv++;
|
|
|
|
}
|
|
|
|
Nargv[Nargc] = 0; /* terminate the arg vector */
|
1986-04-18 17:53:47 +00:00
|
|
|
if (Nargc < 2) {
|
|
|
|
fprint(STDERR, "%s: Use a file argument\n", ProgName);
|
1987-05-11 14:38:37 +00:00
|
|
|
exit(1);
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
1986-11-26 16:40:45 +00:00
|
|
|
if (options['x']) c_inp = C_exp;
|
1987-05-11 14:38:37 +00:00
|
|
|
exit(!Compile(Nargv[1], Nargv[2]));
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
|
|
|
|
1986-04-18 17:53:47 +00:00
|
|
|
Compile(src, dst)
|
|
|
|
char *src, *dst;
|
1986-03-20 14:52:03 +00:00
|
|
|
{
|
|
|
|
extern struct tokenname tkidf[];
|
|
|
|
|
1986-04-03 00:44:39 +00:00
|
|
|
if (! InsertFile(src, (char **) 0, &src)) {
|
1986-04-03 17:41:26 +00:00
|
|
|
fprint(STDERR,"%s: cannot open %s\n", ProgName, src);
|
1986-03-20 14:52:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LineNumber = 1;
|
|
|
|
FileName = src;
|
|
|
|
init_idf();
|
1986-05-01 19:06:53 +00:00
|
|
|
InitCst();
|
1986-03-20 14:52:03 +00:00
|
|
|
reserve(tkidf);
|
1986-06-06 02:22:09 +00:00
|
|
|
InitScope();
|
|
|
|
InitTypes();
|
1986-05-01 19:06:53 +00:00
|
|
|
AddStandards();
|
1986-03-20 14:52:03 +00:00
|
|
|
#ifdef DEBUG
|
1986-04-21 17:27:06 +00:00
|
|
|
if (options['l']) {
|
|
|
|
LexScan();
|
|
|
|
return 1;
|
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
#endif DEBUG
|
1986-12-01 10:06:53 +00:00
|
|
|
open_scope(OPENSCOPE);
|
|
|
|
GlobalVis = CurrVis;
|
|
|
|
close_scope(0);
|
1986-04-21 17:27:06 +00:00
|
|
|
C_init(word_size, pointer_size);
|
1986-11-05 14:33:00 +00:00
|
|
|
if (! C_open(dst)) fatal("could not open output file");
|
1986-04-21 17:27:06 +00:00
|
|
|
C_magic();
|
|
|
|
C_ms_emx(word_size, pointer_size);
|
1987-04-29 10:22:07 +00:00
|
|
|
CheckForLineDirective();
|
1986-04-21 17:27:06 +00:00
|
|
|
CompUnit();
|
1986-06-06 02:22:09 +00:00
|
|
|
C_ms_src((arith) (LineNumber - 1), FileName);
|
1986-06-06 09:35:11 +00:00
|
|
|
if (!err_occurred) {
|
1986-06-26 09:39:36 +00:00
|
|
|
C_exp(Defined->mod_vis->sc_scope->sc_name);
|
1986-06-06 09:35:11 +00:00
|
|
|
WalkModule(Defined);
|
1986-07-08 14:59:02 +00:00
|
|
|
if (fp_used) C_ms_flt();
|
1986-06-06 02:22:09 +00:00
|
|
|
}
|
1986-04-18 17:53:47 +00:00
|
|
|
C_close();
|
1986-05-30 18:48:00 +00:00
|
|
|
#ifdef DEBUG
|
1986-06-06 09:35:11 +00:00
|
|
|
if (options['i']) Info();
|
1986-05-30 18:48:00 +00:00
|
|
|
#endif
|
1986-06-06 09:35:11 +00:00
|
|
|
return ! err_occurred;
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
LexScan()
|
|
|
|
{
|
1986-06-04 09:01:48 +00:00
|
|
|
register struct token *tkp = ˙
|
|
|
|
extern char *symbol2str();
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-06-04 09:01:48 +00:00
|
|
|
while (LLlex() > 0) {
|
|
|
|
print(">>> %s ", symbol2str(tkp->tk_symb));
|
|
|
|
switch(tkp->tk_symb) {
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
|
|
case IDENT:
|
1986-06-04 09:01:48 +00:00
|
|
|
print("%s\n", tkp->TOK_IDF->id_text);
|
1986-03-20 14:52:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case INTEGER:
|
1986-06-04 09:01:48 +00:00
|
|
|
print("%ld\n", tkp->TOK_INT);
|
1986-03-20 14:52:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case REAL:
|
1986-06-04 09:01:48 +00:00
|
|
|
print("%s\n", tkp->TOK_REL);
|
1986-03-20 14:52:03 +00:00
|
|
|
break;
|
1986-06-04 09:01:48 +00:00
|
|
|
|
1986-03-20 14:52:03 +00:00
|
|
|
case STRING:
|
1986-06-04 09:01:48 +00:00
|
|
|
print("\"%s\"\n", tkp->TOK_STR);
|
1986-03-20 14:52:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1986-04-07 17:40:38 +00:00
|
|
|
print("\n");
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1986-05-01 19:06:53 +00:00
|
|
|
AddStandards()
|
1986-03-26 17:53:13 +00:00
|
|
|
{
|
|
|
|
register struct def *df;
|
1986-06-10 13:18:52 +00:00
|
|
|
extern struct def *Enter();
|
1986-05-23 19:25:21 +00:00
|
|
|
static struct node nilnode = { 0, 0, Value, 0, { INTEGER, 0}};
|
1986-03-26 17:53:13 +00:00
|
|
|
|
1987-04-14 11:11:03 +00:00
|
|
|
Enter("ABS", D_PROCEDURE, std_type, S_ABS);
|
|
|
|
Enter("CAP", D_PROCEDURE, std_type, S_CAP);
|
|
|
|
Enter("CHR", D_PROCEDURE, std_type, S_CHR);
|
|
|
|
Enter("FLOAT", D_PROCEDURE, std_type, S_FLOAT);
|
|
|
|
Enter("HIGH", D_PROCEDURE, std_type, S_HIGH);
|
|
|
|
Enter("HALT", D_PROCEDURE, std_type, S_HALT);
|
|
|
|
Enter("EXCL", D_PROCEDURE, std_type, S_EXCL);
|
|
|
|
Enter("DEC", D_PROCEDURE, std_type, S_DEC);
|
|
|
|
Enter("INC", D_PROCEDURE, std_type, S_INC);
|
|
|
|
Enter("VAL", D_PROCEDURE, std_type, S_VAL);
|
|
|
|
Enter("NEW", D_PROCEDURE, std_type, S_NEW);
|
|
|
|
Enter("DISPOSE", D_PROCEDURE, std_type, S_DISPOSE);
|
|
|
|
Enter("TRUNC", D_PROCEDURE, std_type, S_TRUNC);
|
|
|
|
Enter("SIZE", D_PROCEDURE, std_type, S_SIZE);
|
|
|
|
Enter("ORD", D_PROCEDURE, std_type, S_ORD);
|
|
|
|
Enter("ODD", D_PROCEDURE, std_type, S_ODD);
|
|
|
|
Enter("MAX", D_PROCEDURE, std_type, S_MAX);
|
|
|
|
Enter("MIN", D_PROCEDURE, std_type, S_MIN);
|
|
|
|
Enter("INCL", D_PROCEDURE, std_type, S_INCL);
|
|
|
|
|
|
|
|
Enter("CHAR", D_TYPE, char_type, 0);
|
|
|
|
Enter("INTEGER", D_TYPE, int_type, 0);
|
|
|
|
Enter("LONGINT", D_TYPE, longint_type, 0);
|
|
|
|
Enter("REAL", D_TYPE, real_type, 0);
|
|
|
|
Enter("LONGREAL", D_TYPE, longreal_type, 0);
|
|
|
|
Enter("BOOLEAN", D_TYPE, bool_type, 0);
|
|
|
|
Enter("CARDINAL", D_TYPE, card_type, 0);
|
1986-04-22 22:36:16 +00:00
|
|
|
df = Enter("NIL", D_CONST, address_type, 0);
|
|
|
|
df->con_const = &nilnode;
|
|
|
|
nilnode.nd_INT = 0;
|
|
|
|
nilnode.nd_type = address_type;
|
|
|
|
|
1987-04-14 11:11:03 +00:00
|
|
|
Enter("PROC",
|
1986-03-26 17:53:13 +00:00
|
|
|
D_TYPE,
|
1986-04-10 01:08:49 +00:00
|
|
|
construct_type(T_PROCEDURE, NULLTYPE),
|
1986-03-26 17:53:13 +00:00
|
|
|
0);
|
1986-04-07 17:40:38 +00:00
|
|
|
df = Enter("BITSET", D_TYPE, bitset_type, 0);
|
1986-06-10 13:18:52 +00:00
|
|
|
df = Enter("TRUE", D_ENUM, bool_type, 0);
|
1986-04-08 18:15:46 +00:00
|
|
|
df->enm_val = 1;
|
1986-06-10 13:18:52 +00:00
|
|
|
df->enm_next = Enter("FALSE", D_ENUM, bool_type, 0);
|
|
|
|
df = df->enm_next;
|
|
|
|
df->enm_val = 0;
|
1986-04-08 18:15:46 +00:00
|
|
|
df->enm_next = 0;
|
1986-03-26 17:53:13 +00:00
|
|
|
}
|
1986-04-03 00:44:39 +00:00
|
|
|
|
1986-10-06 20:36:30 +00:00
|
|
|
do_SYSTEM()
|
|
|
|
{
|
|
|
|
/* Simulate the reading of the SYSTEM definition module
|
|
|
|
*/
|
1987-04-29 10:22:07 +00:00
|
|
|
static char systemtext[] = SYSTEMTEXT;
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
open_scope(CLOSEDSCOPE);
|
1987-04-14 11:11:03 +00:00
|
|
|
Enter("WORD", D_TYPE, word_type, 0);
|
|
|
|
Enter("BYTE", D_TYPE, byte_type, 0);
|
|
|
|
Enter("ADDRESS", D_TYPE, address_type, 0);
|
|
|
|
Enter("ADR", D_PROCEDURE, std_type, S_ADR);
|
|
|
|
Enter("TSIZE", D_PROCEDURE, std_type, S_TSIZE);
|
1987-04-29 10:22:07 +00:00
|
|
|
if (!InsertText(systemtext, sizeof(systemtext) - 1)) {
|
1986-11-05 14:33:00 +00:00
|
|
|
fatal("could not insert text");
|
1986-04-03 17:41:26 +00:00
|
|
|
}
|
|
|
|
DefModule();
|
1986-10-06 20:36:30 +00:00
|
|
|
close_scope(SC_CHKFORW);
|
1986-04-03 17:41:26 +00:00
|
|
|
}
|
|
|
|
|
1986-05-30 18:48:00 +00:00
|
|
|
#ifdef DEBUG
|
1986-06-06 09:35:11 +00:00
|
|
|
|
|
|
|
int cntlines;
|
|
|
|
|
|
|
|
Info()
|
1986-05-30 18:48:00 +00:00
|
|
|
{
|
|
|
|
extern int cnt_def, cnt_node, cnt_paramlist, cnt_type,
|
|
|
|
cnt_switch_hdr, cnt_case_entry,
|
1986-11-26 16:40:45 +00:00
|
|
|
cnt_scope, cnt_scopelist, cnt_tmpvar;
|
1986-05-30 18:48:00 +00:00
|
|
|
|
|
|
|
print("\
|
|
|
|
%6d def\n%6d node\n%6d paramlist\n%6d type\n%6d switch_hdr\n\
|
1986-11-26 16:40:45 +00:00
|
|
|
%6d case_entry\n%6d scope\n%6d scopelist\n%6d tmpvar\n",
|
1986-05-30 18:48:00 +00:00
|
|
|
cnt_def, cnt_node, cnt_paramlist, cnt_type,
|
|
|
|
cnt_switch_hdr, cnt_case_entry,
|
1986-11-26 16:40:45 +00:00
|
|
|
cnt_scope, cnt_scopelist, cnt_tmpvar);
|
1986-06-06 09:35:11 +00:00
|
|
|
print("\nNumber of lines read: %d\n", cntlines);
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
|
|
|
#endif
|