ack/lang/m2/comp/main.c

226 lines
4.9 KiB
C
Raw Normal View History

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-03-24 17:29:57 +00:00
static char *RcsId = "$Header$";
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-03-26 15:11:02 +00:00
#include "input.h"
#include "f_info.h"
#include "idf.h"
#include "LLlex.h"
#include "Lpars.h"
#include "main.h"
#include "debug.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-03-26 15:11:02 +00:00
1986-04-03 17:41:26 +00:00
char options[128];
int DefinitionModule;
int SYSTEMModule = 0;
char *ProgName;
1986-03-20 14:52:03 +00:00
extern int err_occurred;
1986-04-03 17:41:26 +00:00
char *DEFPATH[128];
char *getenv();
1986-03-20 14:52:03 +00:00
main(argc, argv)
char *argv[];
{
register Nargc = 1;
register char **Nargv = &argv[0];
ProgName = *argv++;
while (--argc > 0) {
if (**argv == '-')
Option(*argv++);
else
Nargv[Nargc++] = *argv++;
}
Nargv[Nargc] = 0; /* terminate the arg vector */
if (Nargc != 2) {
1986-04-03 17:41:26 +00:00
fprint(STDERR, "%s: Use one file argument\n", ProgName);
1986-03-20 14:52:03 +00:00
return 1;
}
#ifdef DEBUG
1986-04-03 17:41:26 +00:00
print("Mod2 compiler -- Debug version\n");
1986-03-20 14:52:03 +00:00
#endif DEBUG
1986-03-26 15:11:02 +00:00
DO_DEBUG(debug(1,"Debugging level: %d", options['D']));
1986-03-20 14:52:03 +00:00
return !Compile(Nargv[1]);
}
Compile(src)
char *src;
{
extern struct tokenname tkidf[];
1986-03-26 17:53:13 +00:00
DO_DEBUG(debug(1,"Filename : %s", src));
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-03 00:44:39 +00:00
init_DEFPATH();
1986-03-20 14:52:03 +00:00
init_idf();
reserve(tkidf);
1986-03-26 15:11:02 +00:00
init_scope();
init_types();
1986-03-26 17:53:13 +00:00
add_standards();
1986-03-20 14:52:03 +00:00
#ifdef DEBUG
if (options['L'])
LexScan();
else if (options['T'])
TimeScan();
1986-04-03 00:44:39 +00:00
else {
1986-03-20 14:52:03 +00:00
#endif DEBUG
1986-04-03 00:44:39 +00:00
(void) open_scope(CLOSEDSCOPE, 0);
GlobalScope = CurrentScope;
1986-03-20 14:52:03 +00:00
CompUnit();
#ifdef DEBUG
1986-04-03 00:44:39 +00:00
}
1986-03-20 14:52:03 +00:00
if (options['h']) hash_stat();
#endif DEBUG
if (err_occurred) return 0;
return 1;
}
#ifdef DEBUG
LexScan()
{
register int symb;
1986-03-26 15:11:02 +00:00
while ((symb = LLlex()) != EOI) {
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:
putchar('\n');
}
}
}
TimeScan() {
1986-03-26 15:11:02 +00:00
while (LLlex() != -1) /* nothing */;
1986-03-20 14:52:03 +00:00
}
#endif
Option(str)
char *str;
{
options[str[1]]++; /* switch option on */
}
1986-03-26 17:53:13 +00:00
add_standards()
{
register struct def *df;
register struct type *tp;
struct def *Enter();
(void) Enter("ABS", D_STDFUNC, NULLTYPE, S_ABS);
(void) Enter("CAP", D_STDFUNC, NULLTYPE, S_CAP);
(void) Enter("CHR", D_STDFUNC, NULLTYPE, S_CHR);
(void) Enter("FLOAT", D_STDFUNC, NULLTYPE, S_FLOAT);
(void) Enter("HIGH", D_STDFUNC, NULLTYPE, S_HIGH);
(void) Enter("HALT", D_STDPROC, NULLTYPE, S_HALT);
(void) Enter("EXCL", D_STDPROC, NULLTYPE, S_EXCL);
(void) Enter("DEC", D_STDPROC, NULLTYPE, S_DEC);
(void) Enter("INC", D_STDPROC, NULLTYPE, S_INC);
(void) Enter("VAL", D_STDFUNC, NULLTYPE, S_VAL);
(void) Enter("TRUNC", D_STDFUNC, NULLTYPE, S_TRUNC);
(void) Enter("SIZE", D_STDFUNC, NULLTYPE, S_SIZE);
(void) Enter("ORD", D_STDFUNC, NULLTYPE, S_ORD);
(void) Enter("ODD", D_STDFUNC, NULLTYPE, S_ODD);
(void) Enter("MAX", D_STDFUNC, NULLTYPE, S_MAX);
(void) Enter("MIN", D_STDFUNC, NULLTYPE, S_MIN);
(void) Enter("INCL", D_STDPROC, NULLTYPE, S_INCL);
(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-03 17:41:26 +00:00
(void) Enter("NIL", D_CONST, address_type, 0);
1986-03-26 17:53:13 +00:00
(void) Enter("PROC",
D_TYPE,
1986-03-27 17:37:41 +00:00
construct_type(PROCEDURE, NULLTYPE),
1986-03-26 17:53:13 +00:00
0);
1986-03-27 17:37:41 +00:00
tp = construct_type(SUBRANGE, int_type);
1986-03-29 01:04:49 +00:00
tp->sub_lb = 0;
tp->sub_ub = wrd_size * 8 - 1;
1986-03-27 17:37:41 +00:00
df = Enter("BITSET", D_TYPE, construct_type(SET, tp), 0);
df->df_type->tp_size = wrd_size;
1986-03-26 17:53:13 +00:00
df = Enter("FALSE", D_ENUM, bool_type, 0);
df->df_value.df_enum.en_val = 0;
df->df_value.df_enum.en_next = Enter("TRUE", D_ENUM, bool_type, 0);
df = df->df_value.df_enum.en_next;
df->df_value.df_enum.en_val = 1;
df->df_value.df_enum.en_next = 0;
}
1986-04-03 00:44:39 +00:00
init_DEFPATH()
{
register char *p = getenv("M2path");
register int i = 0;
if (p) {
while (*p) {
DEFPATH[i++] = p;
while (*p && *p != ':') p++;
if (*p) *p++ = '\0';
}
}
DEFPATH[i] = 0;
}
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
open_scope(CLOSEDSCOPE, 0);
1986-04-03 17:41:26 +00:00
(void) Enter("WORD", D_TYPE, word_type, 0);
(void) Enter("ADDRESS", D_TYPE, address_type, 0);
(void) Enter("ADR", D_STDFUNC, NULLTYPE, S_ADR);
(void) Enter("TSIZE", D_STDFUNC, NULLTYPE, S_TSIZE);
if (!InsertText(SYSTEM, strlen(SYSTEM))) {
fatal("Could not insert text");
}
SYSTEMModule = 1;
DefModule();
1986-04-03 00:44:39 +00:00
close_scope();
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
}