Ejemplo 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;
}
Ejemplo n.º 2
0
/*
 * Prepare for pass #1
 */
void 
sym_PrepPass1(void)
{
	sym_Init();
}