Beispiel #1
0
void
newproc()
{
	if(parstate != OUTSIDE) {
		execerr("missing end statement");
		endproc();
	}

	parstate = INSIDE;
	procclass = CLMAIN;	/* default */
}
Beispiel #2
0
startproc(Extsym *progname, int Class)
#endif
{
	register struct Entrypoint *p;

	p = ALLOC(Entrypoint);
	if(Class == CLMAIN) {
		puthead(CNULL, CLMAIN);
		if (progname)
		    strcpy (main_alias, progname->cextname);
	} else {
		if (progname) {
			/* Construct an empty subroutine with this name */
			/* in case the name is needed to force loading */
			/* of this block-data subprogram: the name can */
			/* appear elsewhere in an external statement. */
			entrypt(CLPROC, TYSUBR, (ftnint)0, progname, (chainp)0);
			endproc();
			newproc();
			}
		puthead(CNULL, CLBLOCK);
		}
	if(Class == CLMAIN)
		newentry( mkname(" MAIN"), 0 )->extinit = 1;
	p->entryname = progname;
	entries = p;

	procclass = Class;
	fprintf(diagfile, "   %s", (Class==CLMAIN ? "MAIN" : "BLOCK DATA") );
	if(progname) {
		fprintf(diagfile, " %s", progname->fextname);
		procname = progname->cextname;
		}
	fprintf(diagfile, ":\n");
	fflush(diagfile);
}
Beispiel #3
0
int
main(int argc, char **argv)
{
	int ch;
	int k, retcode;

	infile = stdin;
	diagfile = stderr;
#if 1 /* RAGGE */
	char file[] = "/tmp/initfile.XXXXXX";
	char buf[100];
	close(mkstemp(file));
	sprintf(buf, "sort > %s", file);
	initfile = popen(buf, "w");
#endif


#define DONE(c)	{ retcode = c; goto finis; }

	while ((ch = getopt(argc, argv, "qw:UuOdpC1I:Z:X:")) != -1)
		switch (ch) {
		case 'q':
			quietflag = YES;
			break;

		case 'w':
			if(optarg[0]=='6' && optarg[1]=='6') {
				ftn66flag = YES;
			} else
				nowarnflag = YES;
			break;

		case 'U':
			shiftcase = NO;
			break;

		case 'u':
			undeftype = YES;
			break;

		case 'O':
			optimflag = YES;
#ifdef notyet
			xdeljumps = 1;
			xtemps = 1;
#endif
			break;

		case 'd':
			debugflag = YES;
			break;

		case 'p':
			profileflag = YES;
			break;

		case 'C':
			checksubs = YES;
			break;

		case '1':
			onetripflag = YES;
			break;

		case 'I':
			if(*optarg == '2')
				tyint = TYSHORT;
			else if(*optarg == '4') {
				shortsubs = NO;
				tyint = TYLONG;
			} else if(*optarg == 's')
				shortsubs = YES;
			else
				fatal1("invalid flag -I%c\n", *optarg);
			tylogical = tyint;
			break;

		case 'Z':	/* pass2 debugging */
			while (*optarg)
				switch (*optarg++) {
				case 'b': /* basic block and SSA building */
					++b2debug;
					break;
				case 'c': /* code printout */
					++c2debug;
					break;
				case 'e': /* print tree upon pass2 enter */
					++e2debug;
					break;
				case 'f': /* instruction matching */
					++f2debug;
					break;
				case 'g':
					++g2debug;
					break;
				case 'n':
					++ndebug;
					break;
				case 'o':
					++o2debug;
					break;
				case 'r': /* register alloc/graph coloring */
					++r2debug;
					break;
				case 's': /* shape matching */
					++s2debug;
					break;
				case 't':
					++t2debug;
					break;
				case 'u': /* Sethi-Ullman debugging */
					++u2debug;
					break;
				case 'x':
					++x2debug;
					break;
				default:
					fprintf(stderr, "unknown Z flag '%c'\n",
					    optarg[-1]);
					exit(1);
				}
			break;

		case 'X':	/* pass1 debugging */
			while (*optarg)
				switch (*optarg++) {
				case 'm': /* memory allocation */
					++mflag;
					break;
				case 't': /* tree debugging */
					tflag++;
					break;
				default:
					usage();
				}
			break;

		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	mkdope();
	initkey();
	if (argc > 0) {
		if (inilex(copys(argv[0])))
			DONE(1);
		if (!quietflag)
			fprintf(diagfile, "%s:\n", argv[0]);
		if (argc != 1)
			if (freopen(argv[1], "w", stdout) == NULL) {
				fprintf(stderr, "open output file '%s':",
				    argv[1]);
				perror(NULL);
				exit(1);
			}
	} else {
		inilex(copys(""));
	}
	fileinit();
	procinit();
	if((k = yyparse())) {
		fprintf(diagfile, "Bad parse, return code %d\n", k);
		DONE(1);
	}
	if(nerr > 0)
		DONE(1);
	if(parstate != OUTSIDE) {
		warn("missing END statement");
		endproc();
	}
	doext();
	preven(ALIDOUBLE);
	prtail();
	puteof();
	DONE(0);


finis:
	pclose(initfile);
	retcode |= dodata(file);
	unlink(file);
	done(retcode);
	return(retcode);
}
Beispiel #4
0
int main(int argc, char* argv[])
{
	if (argc != 2) {
		fprintf(stderr, "[-] Error: usage: %s config_file\n", argv[0]);
		return EXIT_FAILURE;
	}

	char* filename = argv[1];

	FILE* fp = fopen(filename, "r");
	if (!fp) {
		fprintf(stderr, "[-] Error: failed to open file %s\n", filename);
		return EXIT_FAILURE;
	}

	/* File buffer */
	char* buffer;
	int nbytes = 128;

	buffer = (char*)malloc(2048*sizeof(char));

	/* Parsing vars */
	int m_size;
	int p_id;
	int p_size;
	int r_page;
	int r_id;
	int w_page;
	int w_id;
	int e_id;

	init_process_table();

	/* Main loop */
	while ((getline(&buffer, (size_t*)&nbytes, fp) != -1)) {

		/* Todas as operações começam com letras diferentes */
		switch(buffer[0]) {
			case 'M': /* MEMSIZE SIZE */
			case 'm':
				parse_memsize(buffer, &m_size);
				printf("[+] MEMSIZE %d\n", m_size);
				memsize(m_size);
				break;

			case 'P': /* PROCSIZE ID SIZE */
			case 'p':
				parse_procsize(buffer, &p_id, &p_size);
				printf("[+] PROCSIZE %d %d\n", p_id, p_size);
				procsize(p_id, p_size);
				break;

			case 'R': /* READ PAGE ID */
			case 'r':
				parse_read(buffer, &r_page, &r_id);
				printf("[+] READ %d %d\n", r_page, r_id);
				read_p(r_page, r_id);
				break;

			case 'W': /* WRITE PAGE ID */
			case 'w':
				parse_write(buffer, &w_page, &w_id);
				printf("[+] WRITE %d %d\n", w_page, w_id);
				write_p(w_page, w_id);
				break;

			case 'E': /* ENDPROC ID */
			case 'e':
				parse_endproc(buffer, &e_id);
				printf("[+] ENDPROC %d\n", e_id);
				endproc(e_id);
				break;

			default:
				printf("[-] Invalid Operation!\n");
		}
	}

	/* Write stats here */
	write_stats();

	fclose(fp);
	return EXIT_SUCCESS;
}