Beispiel #1
0
int main(int argc, char* argv[])
{
	cout << "\n\t\tLC-3 Assembler Converter 1.0, Ashley Wise\n\n";

	if(!ProcessArgs(argc, argv))
	{
		PrintUsage();
		return 0;
	}

	char sMessageBuffer[65 + MAX_FILENAME_CHAR];
	LocationVector LocationStack;
	bool fRetVal = true;

	for(unsigned int i = 0; i < InputList.size(); i++)
	{
		ifstream AsmFile(InputList[i].c_str());
		if(!AsmFile.good())
		{
			sprintf(sMessageBuffer, "Unable to open file %.255s", InputList[i].c_str());
			AsmCallBack(Fatal, sMessageBuffer, LocationVector());
			fRetVal = false;
			continue;
		}

		string sAsm3FileName = InputList[i]+"3";
		ofstream Asm3File(sAsm3FileName.c_str());
		if(!Asm3File.good())
		{
			sprintf(sMessageBuffer, "Unable to open file %.255s", sAsm3FileName.c_str());
			AsmCallBack(Fatal, sMessageBuffer, LocationVector());
			fRetVal = false;
			continue;
		}

		LocationStack.push_back( LocationVector::value_type(i, 1) );
		cout << "Translating " << InputList[i].c_str() << endl;
		if(!AsmConvertLC3(AsmFile, Asm3File, LocationStack, AsmCallBack))
		{
			fRetVal = false;
			continue;
		}
	}
	cout << endl;

	return 0;
}
Beispiel #2
0
bool AssemblerUI(vector<Program *> &AsmPrograms, RamVector &MemoryImage)
{
	bool fRetVal = true;
	char sMessageBuffer[65 + MAX_FILENAME_CHAR];
	unsigned int i;
	ofstream VHDLFile;

	AsmCallBack(Info, "", LocationVector());
	sprintf(sMessageBuffer, "\t\tLC-3b Assembler %.15s, Ashley Wise", ASM_VER);
	AsmCallBack(Info, sMessageBuffer, LocationVector());
	AsmCallBack(Info, "", LocationVector());

#ifdef BIG_ENDIAN_BUILD
	if(EndianCheck())
	{
		AsmCallBack(Fatal, "Platform is little endian; assembler built for big endian! Aborting...", LocationVector());
		return false;
	}
#else
	if(!EndianCheck())
	{
		AsmCallBack(Fatal, "Platform is big endian; assembler built for little endian! Aborting...", LocationVector());
		return false;
	}
#endif

	//Initialize program list
	for(i = 0; i < InputList.size(); i++)
	{
		LocationVector LocationStack;
		LocationStack.push_back( LocationVector::value_type(i, 0) );
		AsmPrograms.push_back(new Program(LocationStack, InputList[i], LC3bISA::Addressability));
	}

	//*** Perform Compilation ***

	//Lex, parse, and optimize each input asm file
	AsmCallBack(Info, "Compiling...", LocationVector());
	for(i = 0; i < AsmPrograms.size(); i++)
	{
		//Open the assembly file
		if(ToLower(AsmPrograms[i]->sFileName.Ext) == "obj" || ToLower(AsmPrograms[i]->sFileName.Ext) == "bin")
		{
			ifstream AsmFile(InputList[i].c_str(), ios::in | ios::binary);
			if(!AsmFile.good())
			{
				sprintf(sMessageBuffer, "Unable to open file %.255s", InputList[i].c_str());
				AsmCallBack(Fatal, sMessageBuffer, LocationVector());
				fRetVal = false;
				continue;
			}
			if(!Assemble<LC3bISA>::Disassemble(AsmFile, *AsmPrograms[i], AsmCallBack))
				fRetVal = false;
		}
		else
		{
			ifstream AsmFile(InputList[i].c_str());
			if(!AsmFile.good())
			{
				sprintf(sMessageBuffer, "Unable to open file %.255s", InputList[i].c_str());
				AsmCallBack(Fatal, sMessageBuffer, LocationVector());
				fRetVal = false;
				continue;
			}
			if(!Assemble<LC3bISA>::Compile(AsmFile, *AsmPrograms[i], AsmCallBack))
				fRetVal = false;
		}
	}
	if(!fRetVal)
		goto CleanUp;

	//*** Perform Linking ***

	//Convert the symbolic assembly program into a memory image
	AsmCallBack(Info, "Linking...", LocationVector());
	fRetVal = Assemble<LC3bISA>::Link(AsmPrograms, MemoryImage, AsmCallBack);
	if(!fRetVal)
		goto CleanUp;

	if(Flags.fOutputVHDL)
	{
		//Create output file name. If none is specified, the filename will be the same as
		//the first input file except the extention is replaced with ".vhd"
		if(sOutputFileName == "")
			sOutputFileName = AsmPrograms[0]->sFileName.Path + AsmPrograms[0]->sFileName.Bare + ".vhd";
		//Open the output file.
		VHDLFile.open(sOutputFileName.c_str());
		if(!VHDLFile.good())
		{
			sprintf(sMessageBuffer, "Unable to create file %.255s...", sOutputFileName.c_str());
			AsmCallBack(Fatal, sMessageBuffer, LocationVector());
			goto CleanUp;
		}
		//write the memory image into a VHDL Ram vectors file
		sprintf(sMessageBuffer, "Writing VHDL to %.255s...", sOutputFileName.c_str());
		AsmCallBack(Info, sMessageBuffer, LocationVector());
		Assemble<LC3bISA>::VHDLWrite(VHDLFile, MemoryImage, AsmCallBack);
	}
	else
		sOutputFileName = AsmPrograms[0]->sFileName.Path + AsmPrograms[0]->sFileName.Bare;
	//Print VHDL to stdout
	if(Flags.fStdout)
	{
		cout << endl;
		Assemble<LC3bISA>::VHDLWrite(cout, MemoryImage, AsmCallBack);
		cout << endl;
	}

CleanUp:
	AsmCallBack(Info, "", LocationVector());
	sprintf(sMessageBuffer, "%.255s:   %u Error%.1s, %u Warning%.1s", sOutputFileName.c_str(), Errors, (Errors != 1 ? "s" : ""), Warnings, (Warnings != 1 ? "s" : ""));
	AsmCallBack(Info, sMessageBuffer, LocationVector());
	AsmCallBack(Info, "", LocationVector());

	return fRetVal;
}