Пример #1
0
bool EncodingTable::load(const std::wstring& fileName, TextFile::Encoding encoding)
{
	unsigned char hexBuffer[MAXHEXLENGTH];

	TextFile input;
	if (input.open(fileName,TextFile::Read,encoding) == false)
		return false;

	hexData.clear();
	valueData.clear();
	entries.clear();
	setTerminationEntry((unsigned char*)"\0",1);

	while (!input.atEnd())
	{
		std::wstring line = input.readLine();
		if (line.empty() || line[0] == '*') continue;
		
		if (line[0] == '/')
		{
			std::wstring hex = line.substr(1);
			if (hex.empty() || hex.length() > 2*MAXHEXLENGTH)
			{
				// error
				continue;
			}

			int length = parseHexString(hex,hexBuffer);
			if (length == -1)
			{
				// error
				continue;
			}

			setTerminationEntry(hexBuffer,length);
		} else {
			size_t pos = line.find(L'=');
			std::wstring hex = line.substr(0,pos);
			std::wstring value = line.substr(pos+1);

			if (hex.empty() || value.empty() || hex.length() > 2*MAXHEXLENGTH)
			{
				// error
				continue;
			}
			
			int length = parseHexString(hex,hexBuffer);
			if (length == -1)
			{
				// error
				continue;
			}

			addEntry(hexBuffer,length,value);
		}
	}

	return true;
}
Пример #2
0
void LoadAssemblyFile(const std::wstring& fileName, TextFile::Encoding encoding)
{
	tTextData Text;
	int num = 0;

	AddFileName((char*)convertWStringToUtf8(fileName).c_str());
	Global.IncludeNestingLevel++;

	if (Global.IncludeNestingLevel == ASSEMBLER_INCLUDE_NESTING_LEVEL)
	{
		Logger::printError(Logger::Error,L"Maximum include nesting level reached");
		return;
	}

	TextFile input;
	if (input.open(fileName,TextFile::Read,encoding) == false)
	{
		Logger::printError(Logger::Error,L"Could not open file");
		return;
	}

	while (!input.atEnd())
	{
		Global.FileInfo.LineNumber++;
		Global.FileInfo.TotalLineCount++;

		if (GetLine(input,Text.buffer) == false) continue;
		if (Text.buffer.size() == 0) continue;
		
		Text.buffer = Global.symbolTable.insertEquations(Text.buffer,Global.FileInfo.FileNum,Global.Section);

		if (CheckEquLabel(Text.buffer) == false)
		{
			Text.buffer = checkLabel(Text.buffer,false);
			splitLine(Text.buffer,Text.name,Text.params);
			if (Text.name.empty()) continue;

			if (ParseMacro(input,Text.name,Text.params) == true) continue;
			if (Arch->AssembleDirective(Text.name,Text.params) == false)
			{
				Arch->AssembleOpcode(Text.name,Text.params);
			}
		}

		if (Logger::hasFatalError())
			return;
	}
	
	Logger::printQueue();
	Global.IncludeNestingLevel--;
	input.close();
}
Пример #3
0
void parseMacroDefinition(TextFile& Input, std::wstring& Args)
{
	tTextData Text;
	ArgumentList Arguments;

	splitArguments(Arguments,Args);

	CMacro* Macro = new CMacro();
	Macro->loadArguments(Arguments);

	while (true)
	{
		if (Input.atEnd())
		{
			Logger::printError(Logger::Error,L"Unexpected end of line in macro definition");
			return;
		}
		Global.FileInfo.LineNumber++;
		if (GetLine(Input,Text.buffer) == false) continue;
		if (Text.buffer.empty()) continue;
		splitLine(Text.buffer,Text.name,Text.params);
		if (Text.name.compare(L".endmacro") == 0) break;
		Macro->addLine(Text.buffer);
	}

	for (size_t i = 0; i < Global.Macros.size(); i++)
	{
		if (Macro->getName().compare(Global.Macros[i]->getName()) == 0)
		{
			Logger::printError(Logger::Error,L"Macro \"%s\" already defined",Macro->getName());
			delete Macro;
			return;
		}
	}

	Global.Macros.push_back(Macro);
}