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
|
|
|
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1987-04-29 10:22:07 +00:00
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
#include "parameters.h"
|
1986-05-01 19:06:53 +00:00
|
|
|
#include "debug.h"
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1988-03-21 17:22:26 +00:00
|
|
|
#include <assert.h>
|
2019-03-01 17:39:25 +00:00
|
|
|
#include "system.h"
|
|
|
|
#include "em_arith.h"
|
|
|
|
#include "em_label.h"
|
|
|
|
#include "em_code.h"
|
|
|
|
#include "print.h"
|
|
|
|
#include "alloc.h"
|
|
|
|
|
1990-07-30 15:56:25 +00:00
|
|
|
#include <stb.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"
|
2019-03-01 17:39:25 +00:00
|
|
|
#include "walk.h"
|
|
|
|
#include "cstoper.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "options.h"
|
1986-11-05 14:33:00 +00:00
|
|
|
#include "warning.h"
|
2019-03-01 17:39:25 +00:00
|
|
|
#include "SYSTEMM2.h"
|
1986-03-26 15:11:02 +00:00
|
|
|
|
1986-06-06 02:22:09 +00:00
|
|
|
int state; /* either IMPLEMENTATION or PROGRAM */
|
2019-03-01 17:39:25 +00:00
|
|
|
char options[128];
|
1986-06-06 02:22:09 +00:00
|
|
|
int DefinitionModule;
|
2019-03-01 17:39:25 +00:00
|
|
|
char *ProgName;
|
|
|
|
char **DEFPATH;
|
1992-02-26 13:35:06 +00:00
|
|
|
int nDEF = 2, mDEF = 10;
|
1988-07-05 19:06:40 +00:00
|
|
|
int pass_1 = 1;
|
2019-03-01 17:39:25 +00:00
|
|
|
t_def *Defined;
|
1986-06-06 02:22:09 +00:00
|
|
|
extern int err_occurred;
|
|
|
|
extern int fp_used; /* set if floating point used */
|
1991-03-12 16:52:00 +00:00
|
|
|
static t_node _emptystat = { Stat, 0, NULLTYPE, { ';' }};
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node *EmptyStatement = &_emptystat;
|
1986-03-20 14:52:03 +00:00
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
|
|
|
|
/* Forward declarations. */
|
|
|
|
struct stdproc;
|
|
|
|
int Compile(char *, char *);
|
|
|
|
static void AddProcs(register struct stdproc *);
|
|
|
|
static void AddStandards(void);
|
|
|
|
/* External function declarations */
|
|
|
|
extern void CompUnit(void);
|
|
|
|
extern void DefModule(void); /* Lpars */
|
|
|
|
extern void reserve(register struct tokenname *); /* tokenname */
|
|
|
|
char* getwdir(register char *); /* defmodule */
|
|
|
|
|
|
|
|
int main(int argc, 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++;
|
1989-03-20 13:32:06 +00:00
|
|
|
DEFPATH = (char **) Malloc((unsigned)mDEF * sizeof(char *));
|
1992-02-26 13:35:06 +00:00
|
|
|
DEFPATH[1] = 0;
|
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);
|
1991-03-12 16:52:00 +00:00
|
|
|
sys_stop(S_EXIT);
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
sys_stop(Compile(Nargv[1], Nargv[2]) ? S_END : S_EXIT);
|
1991-02-19 15:28:48 +00:00
|
|
|
/*NOTREACHED*/
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
int Compile(char *src, char *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;
|
1987-05-27 10:16:03 +00:00
|
|
|
WorkingDir = getwdir(src);
|
1990-07-30 15:56:25 +00:00
|
|
|
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);
|
1991-02-18 17:18:36 +00:00
|
|
|
#ifdef DBSYMTAB
|
1990-07-30 15:56:25 +00:00
|
|
|
if (options['g']) {
|
|
|
|
C_ms_std(FileName, N_SO, 0);
|
|
|
|
}
|
1991-02-18 17:18:36 +00:00
|
|
|
#endif /* DBSYMTAB */
|
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-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
|
1989-03-03 16:13:45 +00:00
|
|
|
if (options['t']) {
|
1986-04-21 17:27:06 +00:00
|
|
|
LexScan();
|
|
|
|
return 1;
|
|
|
|
}
|
1991-12-17 14:36:35 +00:00
|
|
|
#endif /* DEBUG */
|
1986-12-01 10:06:53 +00:00
|
|
|
open_scope(OPENSCOPE);
|
|
|
|
GlobalVis = CurrVis;
|
|
|
|
close_scope(0);
|
1987-04-29 10:22:07 +00:00
|
|
|
CheckForLineDirective();
|
1986-04-21 17:27:06 +00:00
|
|
|
CompUnit();
|
1987-05-18 15:57:33 +00:00
|
|
|
C_ms_src((int)LineNumber - 1, FileName);
|
1986-06-06 09:35:11 +00:00
|
|
|
if (!err_occurred) {
|
1987-07-30 13:37:39 +00:00
|
|
|
pass_1 = 0;
|
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
|
2019-03-01 17:39:25 +00:00
|
|
|
void LexScan(void)
|
1986-03-20 14:52:03 +00:00
|
|
|
{
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_token *tkp = ˙
|
1986-06-04 09:01:48 +00:00
|
|
|
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:
|
1991-03-06 10:52:34 +00:00
|
|
|
print("%s\n", tkp->TOK_RSTR);
|
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
|
|
|
|
|
1987-05-21 09:37:28 +00:00
|
|
|
static struct stdproc {
|
|
|
|
char *st_nam;
|
|
|
|
int st_con;
|
1988-03-22 17:54:01 +00:00
|
|
|
} stdprocs[] = {
|
1987-05-21 09:37:28 +00:00
|
|
|
{ "ABS", S_ABS },
|
|
|
|
{ "CAP", S_CAP },
|
|
|
|
{ "CHR", S_CHR },
|
|
|
|
{ "FLOAT", S_FLOAT },
|
|
|
|
{ "HIGH", S_HIGH },
|
|
|
|
{ "HALT", S_HALT },
|
|
|
|
{ "EXCL", S_EXCL },
|
|
|
|
{ "DEC", S_DEC },
|
|
|
|
{ "INC", S_INC },
|
|
|
|
{ "VAL", S_VAL },
|
1987-10-21 11:29:52 +00:00
|
|
|
#ifndef STRICT_3RD_ED
|
1987-05-21 09:37:28 +00:00
|
|
|
{ "NEW", S_NEW },
|
|
|
|
{ "DISPOSE", S_DISPOSE },
|
1987-10-21 11:29:52 +00:00
|
|
|
#endif
|
1987-05-21 09:37:28 +00:00
|
|
|
{ "TRUNC", S_TRUNC },
|
|
|
|
{ "SIZE", S_SIZE },
|
|
|
|
{ "ORD", S_ORD },
|
|
|
|
{ "ODD", S_ODD },
|
|
|
|
{ "MAX", S_MAX },
|
|
|
|
{ "MIN", S_MIN },
|
|
|
|
{ "INCL", S_INCL },
|
1987-05-27 10:16:03 +00:00
|
|
|
{ "LONG", S_LONG },
|
|
|
|
{ "SHORT", S_SHORT },
|
|
|
|
{ "TRUNCD", S_TRUNCD },
|
|
|
|
{ "FLOATD", S_FLOATD },
|
1987-05-21 09:37:28 +00:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
1988-03-22 17:54:01 +00:00
|
|
|
static struct stdproc sysprocs[] = {
|
|
|
|
{ "TSIZE", S_TSIZE },
|
|
|
|
{ "ADR", S_ADR },
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
1991-02-19 15:28:48 +00:00
|
|
|
extern t_def *Enter(), *EnterType();
|
1987-05-21 09:37:28 +00:00
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
static void AddProcs(register struct stdproc *p)
|
1988-03-22 17:54:01 +00:00
|
|
|
{
|
|
|
|
for (; p->st_nam != 0; p++) {
|
1988-03-21 17:22:26 +00:00
|
|
|
if (! Enter(p->st_nam, D_PROCEDURE, std_type, p->st_con)) {
|
|
|
|
assert(0);
|
|
|
|
}
|
1987-05-21 09:37:28 +00:00
|
|
|
}
|
1988-03-22 17:54:01 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
static void AddStandards(void)
|
1988-03-22 17:54:01 +00:00
|
|
|
{
|
|
|
|
register t_def *df;
|
|
|
|
static t_token nilconst = { INTEGER, 0};
|
1987-05-21 09:37:28 +00:00
|
|
|
|
1988-03-22 17:54:01 +00:00
|
|
|
AddProcs(stdprocs);
|
1987-05-21 09:37:28 +00:00
|
|
|
EnterType("CHAR", char_type);
|
|
|
|
EnterType("INTEGER", int_type);
|
|
|
|
EnterType("LONGINT", longint_type);
|
|
|
|
EnterType("REAL", real_type);
|
|
|
|
EnterType("LONGREAL", longreal_type);
|
|
|
|
EnterType("CARDINAL", card_type);
|
1996-08-14 07:42:40 +00:00
|
|
|
if (options['l']) {
|
|
|
|
/* local extension: LONGCARD. */
|
|
|
|
EnterType("LONGCARD", longcard_type);
|
|
|
|
}
|
1990-07-30 15:56:25 +00:00
|
|
|
EnterType("(void)", void_type);
|
1986-04-22 22:36:16 +00:00
|
|
|
df = Enter("NIL", D_CONST, address_type, 0);
|
1987-07-30 13:37:39 +00:00
|
|
|
df->con_const = nilconst;
|
1986-04-22 22:36:16 +00:00
|
|
|
|
1987-05-21 09:37:28 +00:00
|
|
|
EnterType("PROC", construct_type(T_PROCEDURE, NULLTYPE));
|
|
|
|
EnterType("BITSET", bitset_type);
|
1990-07-30 15:56:25 +00:00
|
|
|
df = Enter("FALSE", D_ENUM, bool_type, 0);
|
|
|
|
bool_type->enm_enums = df;
|
|
|
|
df->enm_next = Enter("TRUE", D_ENUM, bool_type, 0);
|
|
|
|
df->enm_next->enm_val = 1;
|
|
|
|
assert(df->enm_val == 0 && df->enm_next->enm_next == 0);
|
|
|
|
EnterType("BOOLEAN", bool_type);
|
1986-03-26 17:53:13 +00:00
|
|
|
}
|
1986-04-03 00:44:39 +00:00
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
void do_SYSTEM(void)
|
1986-10-06 20:36:30 +00:00
|
|
|
{
|
|
|
|
/* Simulate the reading of the SYSTEM definition module
|
|
|
|
*/
|
1987-04-29 10:22:07 +00:00
|
|
|
static char systemtext[] = SYSTEMTEXT;
|
|
|
|
|
1987-05-21 09:37:28 +00:00
|
|
|
EnterType("WORD", word_type);
|
|
|
|
EnterType("BYTE", byte_type);
|
|
|
|
EnterType("ADDRESS",address_type);
|
1988-03-22 17:54:01 +00:00
|
|
|
AddProcs(sysprocs);
|
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-05-30 18:48:00 +00:00
|
|
|
#ifdef DEBUG
|
1986-06-06 09:35:11 +00:00
|
|
|
|
|
|
|
int cntlines;
|
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
void Info(void)
|
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
|
1987-05-27 10:16:03 +00:00
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
void No_Mem(void)
|
1987-05-27 10:16:03 +00:00
|
|
|
{
|
|
|
|
fatal("out of memory");
|
|
|
|
}
|
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
void C_failed(void)
|
1987-05-27 10:16:03 +00:00
|
|
|
{
|
|
|
|
fatal("write failed");
|
|
|
|
}
|