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
|
|
|
|
1986-05-01 19:06:53 +00:00
|
|
|
#ifndef NORCSID
|
1986-03-24 17:29:57 +00:00
|
|
|
static char *RcsId = "$Header$";
|
1986-05-01 19:06:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
#include "ndir.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-03-26 15:11:02 +00:00
|
|
|
|
1986-05-28 18:36:51 +00:00
|
|
|
int state; /* either IMPLEMENTATION or PROGRAM */
|
1986-04-03 17:41:26 +00:00
|
|
|
char options[128];
|
|
|
|
int DefinitionModule;
|
|
|
|
int SYSTEMModule = 0;
|
|
|
|
char *ProgName;
|
1986-04-25 10:14:08 +00:00
|
|
|
char *DEFPATH[NDIRS+1];
|
1986-04-21 17:27:06 +00:00
|
|
|
struct def *Defined;
|
1986-05-28 18:36:51 +00:00
|
|
|
extern int err_occurred;
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
|
|
main(argc, argv)
|
|
|
|
char *argv[];
|
|
|
|
{
|
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++;
|
|
|
|
|
|
|
|
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);
|
1986-03-20 14:52:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
1986-04-07 17:40:38 +00:00
|
|
|
DO_DEBUG(1, debug("Debugging level: %d", options['D']));
|
1986-04-18 17:53:47 +00:00
|
|
|
#endif DEBUG
|
|
|
|
return !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-07 17:40:38 +00:00
|
|
|
DO_DEBUG(1, debug("Filename : %s", src));
|
1986-04-18 17:53:47 +00:00
|
|
|
DO_DEBUG(1, (!dst || debug("Targetfile: %s", dst)));
|
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;
|
1986-04-25 10:14:08 +00:00
|
|
|
DEFPATH[0] = "";
|
|
|
|
DEFPATH[NDIRS] = 0;
|
1986-03-20 14:52:03 +00:00
|
|
|
init_idf();
|
1986-05-01 19:06:53 +00:00
|
|
|
InitCst();
|
1986-03-20 14:52:03 +00:00
|
|
|
reserve(tkidf);
|
1986-03-26 15:11:02 +00:00
|
|
|
init_scope();
|
|
|
|
init_types();
|
1986-05-01 19:06:53 +00:00
|
|
|
InitDef();
|
|
|
|
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-05-16 17:15:36 +00:00
|
|
|
open_scope(CLOSEDSCOPE);
|
1986-04-21 17:27:06 +00:00
|
|
|
GlobalScope = CurrentScope;
|
|
|
|
C_init(word_size, pointer_size);
|
|
|
|
if (! C_open(dst)) {
|
|
|
|
fatal("Could not open output file");
|
|
|
|
}
|
|
|
|
C_magic();
|
|
|
|
C_ms_emx(word_size, pointer_size);
|
|
|
|
CompUnit();
|
1986-05-28 18:36:51 +00:00
|
|
|
close_scope(SC_REVERSE);
|
1986-04-21 17:27:06 +00:00
|
|
|
if (err_occurred) {
|
|
|
|
C_close();
|
|
|
|
return 0;
|
1986-04-03 00:44:39 +00:00
|
|
|
}
|
1986-04-21 17:27:06 +00:00
|
|
|
WalkModule(Defined);
|
1986-04-18 17:53:47 +00:00
|
|
|
C_close();
|
1986-05-30 18:48:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (options['m']) MemUse();
|
|
|
|
#endif
|
1986-03-20 14:52:03 +00:00
|
|
|
if (err_occurred) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
LexScan()
|
|
|
|
{
|
|
|
|
register int symb;
|
1986-04-18 17:53:47 +00:00
|
|
|
char *symbol2str();
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-04-07 17:40:38 +00:00
|
|
|
while ((symb = LLlex()) > 0) {
|
1986-04-03 17:41:26 +00:00
|
|
|
print(">>> %s ", symbol2str(symb));
|
1986-03-20 14:52:03 +00:00
|
|
|
switch(symb) {
|
|
|
|
|
|
|
|
case IDENT:
|
1986-04-03 17:41:26 +00:00
|
|
|
print("%s\n", dot.TOK_IDF->id_text);
|
1986-03-20 14:52:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case INTEGER:
|
1986-04-03 17:41:26 +00:00
|
|
|
print("%ld\n", dot.TOK_INT);
|
1986-03-20 14:52:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case REAL:
|
1986-04-03 17:41:26 +00:00
|
|
|
print("%s\n", dot.TOK_REL);
|
1986-03-20 14:52:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STRING:
|
1986-04-03 17:41:26 +00:00
|
|
|
print("\"%s\"\n", dot.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;
|
|
|
|
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
|
|
|
|
1986-04-09 18:14:49 +00:00
|
|
|
(void) Enter("ABS", D_PROCEDURE, std_type, S_ABS);
|
|
|
|
(void) Enter("CAP", D_PROCEDURE, std_type, S_CAP);
|
|
|
|
(void) Enter("CHR", D_PROCEDURE, std_type, S_CHR);
|
|
|
|
(void) Enter("FLOAT", D_PROCEDURE, std_type, S_FLOAT);
|
|
|
|
(void) Enter("HIGH", D_PROCEDURE, std_type, S_HIGH);
|
|
|
|
(void) Enter("HALT", D_PROCEDURE, std_type, S_HALT);
|
|
|
|
(void) Enter("EXCL", D_PROCEDURE, std_type, S_EXCL);
|
|
|
|
(void) Enter("DEC", D_PROCEDURE, std_type, S_DEC);
|
|
|
|
(void) Enter("INC", D_PROCEDURE, std_type, S_INC);
|
|
|
|
(void) Enter("VAL", D_PROCEDURE, std_type, S_VAL);
|
|
|
|
(void) Enter("TRUNC", D_PROCEDURE, std_type, S_TRUNC);
|
|
|
|
(void) Enter("SIZE", D_PROCEDURE, std_type, S_SIZE);
|
|
|
|
(void) Enter("ORD", D_PROCEDURE, std_type, S_ORD);
|
|
|
|
(void) Enter("ODD", D_PROCEDURE, std_type, S_ODD);
|
|
|
|
(void) Enter("MAX", D_PROCEDURE, std_type, S_MAX);
|
|
|
|
(void) Enter("MIN", D_PROCEDURE, std_type, S_MIN);
|
|
|
|
(void) Enter("INCL", D_PROCEDURE, std_type, S_INCL);
|
1986-03-26 17:53:13 +00:00
|
|
|
|
|
|
|
(void) Enter("CHAR", D_TYPE, char_type, 0);
|
|
|
|
(void) Enter("INTEGER", D_TYPE, int_type, 0);
|
|
|
|
(void) Enter("LONGINT", D_TYPE, longint_type, 0);
|
|
|
|
(void) Enter("REAL", D_TYPE, real_type, 0);
|
|
|
|
(void) Enter("LONGREAL", D_TYPE, longreal_type, 0);
|
|
|
|
(void) Enter("BOOLEAN", D_TYPE, bool_type, 0);
|
|
|
|
(void) 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;
|
|
|
|
|
1986-03-26 17:53:13 +00:00
|
|
|
(void) Enter("PROC",
|
|
|
|
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-03-26 17:53:13 +00:00
|
|
|
df = Enter("FALSE", D_ENUM, bool_type, 0);
|
1986-04-08 18:15:46 +00:00
|
|
|
df->enm_val = 0;
|
|
|
|
df->enm_next = Enter("TRUE", D_ENUM, bool_type, 0);
|
|
|
|
df = df->enm_next;
|
|
|
|
df->enm_val = 1;
|
|
|
|
df->enm_next = 0;
|
1986-03-26 17:53:13 +00:00
|
|
|
}
|
1986-04-03 00:44:39 +00:00
|
|
|
|
|
|
|
do_SYSTEM()
|
|
|
|
{
|
|
|
|
/* Simulate the reading of the SYSTEM definition module
|
|
|
|
*/
|
1986-04-03 17:41:26 +00:00
|
|
|
char *SYSTEM = "\
|
|
|
|
DEFINITION MODULE SYSTEM;\n\
|
|
|
|
PROCEDURE NEWPROCESS(P:PROC; A:ADDRESS; n:CARDINAL; VAR p1:ADDRESS);\n\
|
|
|
|
PROCEDURE TRANSFER(VAR p1,p2:ADDRESS);\n\
|
|
|
|
END SYSTEM.\n";
|
1986-04-03 00:44:39 +00:00
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
open_scope(CLOSEDSCOPE);
|
1986-04-03 17:41:26 +00:00
|
|
|
(void) Enter("WORD", D_TYPE, word_type, 0);
|
|
|
|
(void) Enter("ADDRESS", D_TYPE, address_type, 0);
|
1986-04-09 18:14:49 +00:00
|
|
|
(void) Enter("ADR", D_PROCEDURE, std_type, S_ADR);
|
|
|
|
(void) Enter("TSIZE", D_PROCEDURE, std_type, S_TSIZE);
|
1986-04-03 17:41:26 +00:00
|
|
|
if (!InsertText(SYSTEM, strlen(SYSTEM))) {
|
|
|
|
fatal("Could not insert text");
|
|
|
|
}
|
|
|
|
SYSTEMModule = 1;
|
|
|
|
DefModule();
|
1986-04-15 17:51:53 +00:00
|
|
|
close_scope(0);
|
1986-04-03 17:41:26 +00:00
|
|
|
SYSTEMModule = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
AtEoIT()
|
|
|
|
{
|
|
|
|
/* Make the end of the text noticable
|
|
|
|
*/
|
|
|
|
return 1;
|
1986-04-03 00:44:39 +00:00
|
|
|
}
|
1986-05-30 18:48:00 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
MemUse()
|
|
|
|
{
|
|
|
|
extern int cnt_def, cnt_node, cnt_paramlist, cnt_type,
|
|
|
|
cnt_switch_hdr, cnt_case_entry,
|
|
|
|
cnt_scope, cnt_scopelist, cnt_forwards, cnt_tmpvar;
|
|
|
|
|
|
|
|
print("\
|
|
|
|
%6d def\n%6d node\n%6d paramlist\n%6d type\n%6d switch_hdr\n\
|
|
|
|
%6d case_entry\n%6d scope\n%6d scopelist\n%6d forwards\n%6d tmpvar\n",
|
|
|
|
cnt_def, cnt_node, cnt_paramlist, cnt_type,
|
|
|
|
cnt_switch_hdr, cnt_case_entry,
|
|
|
|
cnt_scope, cnt_scopelist, cnt_forwards, cnt_tmpvar);
|
|
|
|
}
|
|
|
|
#endif
|