Exemplo n.º 1
0
extern int xasm_Main(int argc, char* argv[])
{
	char format = 'x';
	int	argn = 1;
	int	rcode;
	clock_t	StartClock;
	clock_t EndClock;
	string* pOutname = NULL;
	bool_t debuginfo = false;
	bool_t verbose = false;

#if defined(_DEBUG)
	atexit(getchar);
#endif

    StartClock = clock();

	argc -= 1;
	if(argc == 0)
		PrintUsage();

	sect_Init();
	sym_Init();
	globlex_Init();
	loclexer_Init();

	opt_Open();

	while(argc && argv[argn][0] == '-')
	{
		switch(argv[argn][1])
		{
			case '?':
			case 'h':
				PrintUsage();
				break;
			case 'g':
				debuginfo = true;
				break;
			case 'v':
				verbose = true;
				break;
			case 'f':
				if(strlen(argv[argn]) > 2)
				{
					switch(argv[argn][2])
					{
						case 'x':
						case 'b':
							format = argv[argn][2];
							break;
						case 'g':
						case 'h':
							if(g_pConfiguration->bSupportAmiga)
							{
								format = argv[argn][2];
								break;
							}
						default:
							prj_Warn(WARN_OPTION, argv[argn]);
							break;
					}
				}
				break;
			case 'o':
				pOutname = str_Create(&argv[argn][2]);
				break;
			case 'i':
			case 'e':
			case 'm':
			case 'b':
			case 'w':
			case 'z':
				opt_Parse(&argv[argn][1]);
				break;
			default:
				prj_Warn(WARN_OPTION, argv[argn]);
				break;
		}
		++argn;
		--argc;
	}

	rcode = EXIT_SUCCESS;

	if(argc == 1)
	{
		string* source = str_Create(argv[argn]);
		if(fstk_Init(source))
		{
			bool_t b = parse_Do();

			if(b)
			{
				patch_OptimizeAll();
				patch_BackPatch();
			}

			if(b && g_nTotalErrors == 0)
			{
				float timespent;
				bool_t wr = false;

				if(verbose)
				{
					EndClock = clock();

					timespent = ((float)(EndClock - StartClock))/CLOCKS_PER_SEC;
					printf("Success! %u lines in %.02f seconds ", g_nTotalLines, timespent);
					if(timespent == 0)
					{
						printf("\n");
					}
					else
					{
						printf("(%d lines/minute)\n", (int)(60/timespent*g_nTotalLines));
					}
					if(g_nTotalWarnings != 0)
					{
						printf("Encountered %u warnings\n", g_nTotalWarnings);
					}
				}

				if(pOutname != NULL)
				{
					switch(format)
					{
						case 'x':
							wr = obj_Write(pOutname);
							break;
						case 'b':
							wr = bin_Write(pOutname);
							break;
						case 'g':
							wr = ami_WriteExecutable(pOutname, debuginfo);
							break;
						case 'h':
							wr = ami_WriteObject(pOutname, source, debuginfo);
							break;
					}
					if(!wr)
					{
						remove(str_String(pOutname));
					}
				}
			}
			else
			{
				if(verbose)
				{
					printf("Encountered %u error%s", g_nTotalErrors, g_nTotalErrors > 1 ? "s" : "");
					if(g_nTotalWarnings != 0)
						printf(" and %u warning%s\n", g_nTotalWarnings, g_nTotalWarnings > 1 ? "s" : "");
					else
						printf("\n");
				}
				rcode = EXIT_FAILURE;
			}
			fstk_Cleanup();
		}
		str_Free(source);
	}

	str_Free(pOutname);
	opt_Close();

	return rcode;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
	char *tzMainfile;
	int argn = 1;

	argc -= 1;

	if (argc == 0)
		PrintUsage();

	/* yydebug=1; */

	DefaultOptions.endian = ASM_DEFAULT_ENDIAN;
	DefaultOptions.gbgfx[0] = '0';
	DefaultOptions.gbgfx[1] = '1';
	DefaultOptions.gbgfx[2] = '2';
	DefaultOptions.gbgfx[3] = '3';
	DefaultOptions.binary[0] = '0';
	DefaultOptions.binary[1] = '1';
	DefaultOptions.fillchar = -1;	//      fill uninitialised data with random values
	opt_SetCurrentOptions(&DefaultOptions);

	while (argv[argn][0] == '-' && argc) {
		switch (argv[argn][1]) {
		case 'h':
			PrintUsage();
			break;
		case 'i':
			fstk_AddIncludePath(&(argv[argn][2]));
			break;
		case 'o':
			out_SetFileName(&(argv[argn][2]));
			break;
		case 'e':
		case 'g':
		case 'b':
		case 'z':
			opt_Parse(&argv[argn][1]);
			break;
		default:
			printf("*ERROR*\t :\n\tUnknown option '%c'\n",
			       argv[argn][1]);
			exit(5);
			break;
		}
		argn += 1;
		argc -= 1;
	}

	DefaultOptions = CurrentOptions;

	/*tzMainfile=argv[argn++];
	 * argc-=1; */
	tzMainfile = argv[argn];

	setuplex();

	printf("Assembling %s\n", tzMainfile);

	nStartClock = clock();

	nLineNo = 1;
	nTotalLines = 0;
	nIFDepth = 0;
	nPC = 0;
	nPass = 1;
	nErrors = 0;
	sym_PrepPass1();
	if (fstk_Init(tzMainfile)) {
		printf("Pass 1...\n");

		yy_set_state(LEX_STATE_NORMAL);
		opt_SetCurrentOptions(&DefaultOptions);

		if (yyparse() == 0 && nErrors == 0) {
			if (nIFDepth == 0) {
				nTotalLines = 0;
				nLineNo = 1;
				nIFDepth = 0;
				nPC = 0;
				nPass = 2;
				nErrors = 0;
				sym_PrepPass2();
				out_PrepPass2();
				fstk_Init(tzMainfile);
				yy_set_state(LEX_STATE_NORMAL);
				opt_SetCurrentOptions(&DefaultOptions);

				printf("Pass 2...\n");

				if (yyparse() == 0 && nErrors == 0) {
					double timespent;

					nEndClock = clock();
					timespent =
					    ((double)(nEndClock - nStartClock))
					    / (double)CLOCKS_PER_SEC;
					printf
					    ("Success! %ld lines in %d.%02d seconds ",
					     nTotalLines, (int)timespent,
					     ((int)(timespent * 100.0)) % 100);
					if (timespent == 0)
						printf
						    ("(INFINITY lines/minute)\n");
					else
						printf("(%d lines/minute)\n",
						       (int)(60 / timespent *
							     nTotalLines));
					out_WriteObject();
				} else {
					printf
					    ("Assembly aborted in pass 2 (%ld errors)!\n",
					     nErrors);
					//sym_PrintSymbolTable();
					exit(5);
				}
			} else {
				printf
				    ("*ERROR*\t:\tUnterminated IF construct (%ld levels)!\n",
				     nIFDepth);
				exit(5);
			}
		} else {
			printf("Assembly aborted in pass 1 (%ld errors)!\n",
			       nErrors);
			exit(5);
		}
	} else {
		printf("File '%s' not found\n", tzMainfile);
		exit(5);
	}
	return (0);
}