Esempio n. 1
0
/*
============
main
============
*/
int main (int argc, char **argv)
{
	char    *src2;
	int      p, crc;
	double   start, stop;
	int	   i;
	FILE    *input;

	start = I_FloatTime ();

	myargc = argc;
	myargv = argv;

	for (i=1;i<argc;i++)
	{
		if (!strcmp(argv[i],"-h"))
   	{
   		printf ("%s [-o destfile] file\n",argv[0]);
   		return 0;
   	}
		if (!strcmp(argv[i],"-o"))
		{
			strcpy(destfile,argv[++i]);
			continue;
		}
		if (!strcmp(argv[i],"-p"))
		{
			strcpy(defsfile,argv[++i]);
			continue;
		}
		if (!strcmp(argv[i],"-asm"))
		{
			i++;
			continue;
		}
		break;
	}

	InitData ();

	if (!destfile[0])
		strcpy(destfile,"progs.dat");
	if (!defsfile[0])
		strcpy(defsfile,"progdefs.h");
		
	printf ("outputfile: %s\n", destfile);
	
	pr_dumpasm = false;

	PR_BeginCompilation (malloc (0x100000), 0x100000);


// compile all the files
	if (i==argc || !strcmp(argv[i],"-"))
		input=stdin;
	else
	{
		char buf[1024];
		char *cc;

		cc=getenv("CC");
		if (!cc) cc="gcc";
		sprintf(buf,"%s -x c -E %s",cc,argv[i]);
		input=popen(buf,"r");
		if (!input)
			Error("failed to open pipe to cpp ('%s')",buf);
	}
	
	{
		int size=0;
		src2=NULL;
		while (!feof(input))
		{
			src2=Q_realloc(src2,size+1024);
			size+=fread(&src2[size],1,1024,input);
		}
		src2=Q_realloc(src2,size+1);
		src2[size]=0;
	}

	if (input!=stdin)
		pclose(input);

	if (!PR_CompileFile (src2))
		return 1;

	if (!PR_FinishCompilation ())
		Error ("compilation errors");

	p = CheckParm ("-asm");
	if (p)
		PrintFunction (argv[++p]);

// write progdefs.h
	crc = PR_WriteProgdefs (defsfile);

// write data file
	WriteData (crc);

// write files.dat
#ifdef FILES_DAT
	WriteFiles ();
#endif

	stop = I_FloatTime ();
	printf ("%i seconds elapsed.\n", (int)(stop-start));
	return 0;
}
Esempio n. 2
0
/*
============
main
============
*/
int main (int argc, char **argv)
{
	const char	*psrc;
	void		*src, *src2;
	char	filename[1024];
	int		p, c;
	unsigned short		crc;
	double	start, stop;
	FILE	*f;

	myargc = argc;
	myargv = argv;

	if (CheckParm("-?") || CheckParm("-h") || CheckParm("-help") || CheckParm("--help"))
	{
		printf(" Compiles progs.dat using progs.src in the current directory\n");
		printf(" -src <directory> : Specify source directory\n");
		printf(" -dcc : decompile the progs.dat in the current directory\n");
		printf(" -dcc -fix : fixes mangled names during decompilation\n");
		printf(" -dcc -asm <functionname> : decompile filename to the console\n");
		printf(" -dcc -dump -asm <functionname> : same as above but will show\n\t\tinstructions (opcodes and parms) as well\n");
		exit(0);
	}

	ValidateByteorder ();

	start = GetTime ();

	p = CheckParm("-src");
	if (p && p < argc-1)
	{
		strcpy(sourcedir, argv[p+1]);
		strcat(sourcedir, "/");
		printf("Source directory: %s\n", sourcedir);
	}
	else
	{
		sourcedir[0] = '\0';
	}

	InitData ();

	PR_FILE = stdout;

	p = CheckParm("-dump");
	if (p)
		pr_dumpasm = true;

	// do a crc of the file
	p = CheckParm("-crc");
	if (p)
	{
		CRC_Init (&crc);
		f = fopen ("progdefs.h", "r");
		while ((c = fgetc(f)) != EOF)
			CRC_ProcessByte (&crc, (byte)c);

		printf ("#define PROGHEADER_CRC %i %d\n", crc, (int)crc);
		fclose (f);
		exit (0);
	}

	p = CheckParm("-dcc");
	if (p)
	{
		DEC_ReadData ("progs.dat");
		//fix mangled names if asked
		p = CheckParm ("-fix");
		if (p)
			FILE_NUM_FOR_NAME = 1;

		memset(func_headers, 0, MAX_FUNCTIONS * sizeof(char *));
		memset(temp_val, 0, MAX_REGS * sizeof(char *));

		p = CheckParm("-bbb");
		if (p)
		{
		/*	i= -999;
			for (p = 0; p < numstatements; p++)
				if ((statements+p)->op > i)
					i = (statements+p)->op;
			printf("largest op %d\n", i); */
			FindBuiltinParameters(1);

			exit (0);
		}

		p = CheckParm("-ddd");
		if (p)
		{
			for (p++ ; p < argc ; p++)
			{
				if (argv[p][0] == '-')
					break;
				DccFunctionOP (atoi(argv[p]));
			}
			exit (0);
		}

		p = CheckParm("-info2");
		if (p)
		{
			printf("\n=======================\n");
			printf("fields\n");
			printf("=======================\n");
			PrintFields ();
			printf("\n=======================\n");
			printf("globals\n");
			printf("=======================\n");
			PrintGlobals ();
			exit (0);
		}

		p = CheckParm("-info");
		if (p)
		{
			printf("\n=======================\n");
			printf("strings\n");
			printf("=======================\n");
			PrintStrings ();
			printf("\n=======================\n");
			printf("functions");
			printf("\n=======================\n");
			PrintFunctions ();
			printf("\n=======================\n");
			printf("fields\n");
			printf("=======================\n");
			PrintFields ();
			printf("\n=======================\n");
			printf("globals\n");
			printf("=======================\n");
			PrintGlobals ();
			printf("\n=======================\n");
			printf("pr_globals\n");
			printf("=======================\n");
			PrintPRGlobals ();
			printf("\n=======================\n");
			printf("statements\n");
			printf("=======================\n");
			Printstatements();
			exit (0);
		}

		p = CheckParm("-asm");
		if (p)
		{
			for (p++; p < argc; p++)
			{
				if (argv[p][0] == '-')
					break;
				PR_PrintFunction(argv[p]);
			}
		}
		else
		{
			Dcc_Functions ();
			stop = GetTime ();
			printf("\n%d seconds elapsed.\n", (int)(stop-start));
		}

		exit (0);
	}

	sprintf(filename, "%sprogs.src", sourcedir);
	LoadFile(filename, &src);
	psrc = (char *) src;

	psrc = COM_Parse(psrc);
	if (!psrc)
	{
		Error("No destination filename.  HCC -help for info.\n");
	}

	strcpy(destfile, com_token);
	printf("outputfile: %s\n", destfile);

	pr_dumpasm = false;

	PR_BeginCompilation();

	// compile all the files
	do
	{
		psrc = COM_Parse(psrc);
		if (!psrc)
			break;

		sprintf (filename, "%s%s", sourcedir, com_token);
		printf ("compiling %s\n", filename);
		LoadFile (filename, &src2);

		if (!PR_CompileFile((char *)src2, filename))
			exit (1);

	} while (1);

	if (!PR_FinishCompilation())
	{
		Error ("compilation errors");
	}

	p = CheckParm("-asm");
	if (p)
	{
		for (p++; p < argc; p++)
		{
			if (argv[p][0] == '-')
			{
				break;
			}
			PrintFunction(argv[p]);
		}
	}

	// write progdefs.h
	crc = PR_WriteProgdefs("progdefs.h");
//	crc = 14046;	// FIXME: cheap hack for now!!!!!!!!!!!!!

	// write data file
	WriteData(crc);

	// write files.dat
	WriteFiles();

	stop = GetTime ();
	printf("\n%d seconds elapsed.\n", (int)(stop-start));

	exit (0);
}
Esempio n. 3
0
/*
============
main
============
*/
int main (int argc, char **argv)
{
	const char	*psrc;
	void		*src, *src2;
	char	filename[1024];
	char	*nameptr; /* filename[] without the parent sourcedir */
	int		p, crc;
	double	start, stop;
	int		registerCount, registerSize;
	int		statementCount, statementSize;
	int		functionCount, functionSize;
	int		fileInfo;
	int		quiet;

	myargc = argc;
	myargv = argv;

	if (CheckParm("-?") || CheckParm("-h") || CheckParm("-help") || CheckParm("--help"))
	{
		printf(" -oi              : Optimize Immediates\n");
		printf(" -on              : Optimize Name Table\n");
		printf(" -os              : Optimize String Heap\n");
		printf(" -quiet           : Quiet mode\n");
		printf(" -fileinfo        : Show object sizes per file\n");
		printf(" -pf              : precache_file() calls go into progs (old HCC compat)\n");
		printf(" -sc              : STR_ constants can be saved globals (old HCC compat)\n");
		printf(" -old             : Combined -pf and -sc (as above) for old HCC behavior\n");
		printf(" -src <directory> : Specify source directory\n");
		printf(" -name <source>   : Specify the name of the .src file\n");
		printf(" -version <n>     : Output progs as version n (either 6 or 7)\n");
		printf(" -v6              : Output progs as version 6\n");
		printf(" -v7              : Output progs as version 7\n");
		exit(0);
	}

	ValidateByteorder ();

	start = COM_GetTime ();

	hcc_version_req = -1;	/* output as v6 if possible, otherwise as v7 */
	p = CheckParm("-version");
	if (p != 0)
	{
		if (p >= argc - 1)
			COM_Error ("No num specified for -version");
		p = atoi(argv[p+1]);
		switch (p)
		{
		case 6:
			hcc_version_req = PROG_VERSION_V6;
			break;
		case 7:
			hcc_version_req = PROG_VERSION_V7;
			break;
		default:
			COM_Error ("Version must be either 6 or 7");
			break;
		}
	}

	if (CheckParm("-v6"))	hcc_version_req = PROG_VERSION_V6;
	if (CheckParm("-v7"))	hcc_version_req = PROG_VERSION_V7;

	p = CheckParm("-src");
	if (p != 0)
	{
	/* everything will now be relative to sourcedir: */
		if (p >= argc - 1)
			COM_Error ("No source dirname specified with -src");
		strcpy(sourcedir, argv[p+1]);
		p = strlen (sourcedir);
		if (p && !IS_DIR_SEPARATOR(sourcedir[p - 1]))
		{
			sourcedir[p] = DIR_SEPARATOR_CHAR;
			sourcedir[p + 1] = '\0';
		}
		printf("Source directory: %s\n", sourcedir);
		strcpy(filename, sourcedir);
		nameptr = strchr(filename, '\0');
	}
	else
	{
		sourcedir[0] = '\0';
		nameptr = filename;
	}

	p = CheckParm("-name");
	if (p != 0)
	{
		if (p >= argc - 1)
			COM_Error ("No input filename specified with -name");
		strcpy(nameptr, argv[p+1]);
		printf("Input file: %s\n", nameptr);
	}
	else
	{
		strcpy(nameptr, "progs.src");
	}
	LoadFile(filename, &src);
	psrc = (char *) src;

	psrc = COM_Parse(psrc);
	if (!psrc)
		COM_Error("No destination filename. hcc -help for info.");
	q_snprintf(destfile, sizeof(destfile), "%s%s", sourcedir, com_token);

	hcc_Compat_precache_file = CheckParm("-pf");
	hcc_Compat_STR_SAVEGLOBL = CheckParm("-sc");
	if (CheckParm("-old"))
	{
		hcc_Compat_precache_file = 1;
		hcc_Compat_STR_SAVEGLOBL = 1;
	}
	hcc_OptimizeImmediates = CheckParm("-oi");
	hcc_OptimizeNameTable = CheckParm("-on");
	hcc_OptimizeStringHeap = CheckParm("-os");
	hcc_WarningsActive = CheckParm("-nowarnings") ? false : true;
	hcc_ShowUnrefFuncs = CheckParm("-urfunc") ? true : false;

	fileInfo = CheckParm("-fileinfo");
	quiet = CheckParm("-quiet");

	InitData ();
	LX_Init ();
	CO_Init ();
	EX_Init ();

	PR_BeginCompilation();

	// compile all the files
	do
	{
		psrc = COM_Parse(psrc);
		if (!psrc)
			break;

		registerCount = numpr_globals;
		statementCount = numstatements;
		functionCount = numfunctions;
		strcpy (nameptr, com_token);
		if (!quiet)
			printf("compiling %s\n", nameptr);
		LoadFile (filename, &src2);

		if (!CO_CompileFile((char *)src2, nameptr))
			exit (1);
		if (!quiet && fileInfo)
		{
			registerCount = numpr_globals-registerCount;
			registerSize = registerCount*sizeof(float);
			statementCount = numstatements-statementCount;
			statementSize = statementCount*sizeof(dstatement_t);
			functionCount = numfunctions-functionCount;
			functionSize = functionCount*sizeof(dfunction_t);
			printf("      registers: %10d (%10d bytes)\n", registerCount, registerSize);
			printf("     statements: %10d (%10d bytes)\n", statementCount, statementSize);
			printf("      functions: %10d (%10d bytes)\n", functionCount, functionSize);
			printf("     total size: %10d bytes\n", registerSize+statementSize+functionSize);
		}
	} while (1);

	if (!PR_FinishCompilation())
		COM_Error ("compilation errors");

	p = CheckParm("-asm");
	if (p != 0)
	{
		for (p++; p < argc; p++)
		{
			if (argv[p][0] == '-')
				break;
			PrintFunction(argv[p]);
		}
	}

	// write progdefs.h
	strcpy(nameptr, "progdefs.h");
	crc = PR_WriteProgdefs(filename);

	// write data file
	WriteData(crc);

	// write files.dat
	WriteFiles();
	printf(" precache_sound: %10d / %10d\n", numsounds, MAX_SOUNDS);
	printf(" precache_model: %10d / %10d\n", nummodels, MAX_MODELS);
	printf("  precache_file: %10d / %10d\n", numfiles, MAX_FILES);

	stop = COM_GetTime ();
	printf("\n%d seconds elapsed.\n", (int)(stop - start));

	return 0;
}
Esempio n. 4
0
/*
============
main
============
*/
int main (int argc, char **argv)
{
	const char	*psrc;
	void		*src, *src2;
	char	filename[1024];
	char	*nameptr; /* filename[] without the parent sourcedir */
	int		p, crc;
	double	start, stop;

	myargc = argc;
	myargv = argv;

	if (CheckParm("-?") || CheckParm("-h") || CheckParm("-help") || CheckParm("--help"))
	{
		printf(" Compiles progs.dat using progs.src in the current directory\n");
		printf(" -src <directory> : Specify source directory\n");
		printf(" -name <source>   : Specify the name of the .src file\n");
		printf(" -version <n>     : Output progs as version n (either 6 or 7)\n");
		printf(" -v6              : Output progs as version 6\n");
		printf(" -v7              : Output progs as version 7\n");
		printf(" -dcc (or -dec)   : decompile progs.dat in current directory\n");
		printf(" -dcc -name <progsname> : specify name of progs to decompile\n");
		printf(" -dcc -info : only print brief info about the progs and exit\n");
		printf(" -dcc -fix : fixes mangled names during decompile\n");
		printf(" -dcc -fields     : dumps all fielddefs to stdout\n");
		printf(" -dcc -functions  : dumps all functions to stdout\n");
		printf(" -dcc -globaldefs : dumps all globaldefs to stdout\n");
		printf(" -dcc -prglobals  : dumps all pr_globals to stdout\n");
		printf(" -dcc -statements : dumps all statements to stdout\n");
		printf(" -dcc -strings    : dumps all pr_strings to stdout\n");
		printf(" -dcc -asm <functionname> : decompile filename to the console\n");
		printf(" -dcc -dump -asm <functionname> : same as above but will show\n\t\tinstructions (opcodes and parms) as well\n");
		exit(0);
	}

	ValidateByteorder ();

	if (CheckParm("-dcc") || CheckParm("-dec"))
	{
		Dcc_main (argc, argv);
		exit (0);
	}

	start = COM_GetTime ();

	hcc_version_req = -1;	/* output as v6 if possible, otherwise as v7 */
	p = CheckParm("-version");
	if (p != 0)
	{
		if (p >= argc - 1)
			COM_Error ("No num specified for -version");
		p = atoi(argv[p+1]);
		switch (p)
		{
		case 6:
			hcc_version_req = PROG_VERSION_V6;
			break;
		case 7:
			hcc_version_req = PROG_VERSION_V7;
			break;
		default:
			COM_Error ("Version must be either 6 or 7");
			break;
		}
	}

	if (CheckParm("-v6"))	hcc_version_req = PROG_VERSION_V6;
	if (CheckParm("-v7"))	hcc_version_req = PROG_VERSION_V7;

	p = CheckParm("-src");
	if (p != 0)
	{
	/* everything will now be relative to sourcedir: */
		if (p >= argc - 1)
			COM_Error ("No source dirname specified with -src");
		strcpy(sourcedir, argv[p+1]);
		p = strlen (sourcedir);
		if (p && !IS_DIR_SEPARATOR(sourcedir[p - 1]))
		{
			sourcedir[p] = DIR_SEPARATOR_CHAR;
			sourcedir[p + 1] = '\0';
		}
		printf("Source directory: %s\n", sourcedir);
		strcpy(filename, sourcedir);
		nameptr = strchr(filename, '\0');
	}
	else
	{
		sourcedir[0] = '\0';
		nameptr = filename;
	}

	p = CheckParm("-name");
	if (p != 0)
	{
		if (p >= argc - 1)
			COM_Error ("No input filename specified with -name");
		strcpy(nameptr, argv[p+1]);
		printf("Input file: %s\n", nameptr);
	}
	else
	{
		strcpy(nameptr, "progs.src");
	}
	LoadFile(filename, &src);
	psrc = (char *) src;

	psrc = COM_Parse(psrc);
	if (!psrc)
		COM_Error("No destination filename. dhcc -help for info.");
	q_snprintf(destfile, sizeof(destfile), "%s%s", sourcedir, com_token);
	printf("outputfile: %s\n", destfile);

	hcc_OptimizeStringHeap = 1;

	InitData ();

	PR_BeginCompilation();

	// compile all the files
	do
	{
		psrc = COM_Parse(psrc);
		if (!psrc)
			break;

		strcpy (nameptr, com_token);
		printf ("compiling %s\n", nameptr);
		LoadFile (filename, &src2);

		if (!PR_CompileFile((char *)src2, nameptr))
			exit (1);
	} while (1);

	if (!PR_FinishCompilation())
		COM_Error ("compilation errors");

	p = CheckParm("-asm");
	if (p != 0)
	{
		for (p++; p < argc; p++)
		{
			if (argv[p][0] == '-')
				break;
			PrintFunction(argv[p]);
		}
	}

	// write progdefs.h
	strcpy(nameptr, "progdefs.h");
	crc = PR_WriteProgdefs(filename);

	// write data file
	WriteData(crc);

	// write files.dat
	WriteFiles();
	printf(" precache_sound: %10d / %10d\n", numsounds, MAX_SOUNDS);
	printf(" precache_model: %10d / %10d\n", nummodels, MAX_MODELS);
	printf("  precache_file: %10d / %10d\n", numfiles, MAX_FILES);

	stop = COM_GetTime ();
	printf("\n%d seconds elapsed.\n", (int)(stop - start));

	return 0;
}