Beispiel #1
0
CDirectiveData::CDirectiveData(ArgumentList& Args, int SizePerUnit, bool asc)
{
	TotalAmount = Args.size();
	StrAmount = 0;
	ExpAmount = 0;
	for (int i = 0; i < TotalAmount; i++)
	{
		if (Args[i].isString == true)
		{
			StrAmount++;
		} else {
			ExpAmount++;
		}
	}

	Entries = (tDirectiveDataEntry*) malloc(TotalAmount*sizeof(tDirectiveDataEntry));
	ExpData = new CExpressionCommandList[ExpAmount];
	
	switch (SizePerUnit)
	{
	case 1: case 2: case 4:
		UnitSize = SizePerUnit;
		ascii = asc;
		break;
	default:
		Logger::printError(Logger::Error,L"Invalid data unit size %d",SizePerUnit);
		return;
	}

	int ExpNum = 0;
	SpaceNeeded = 0;
	for (int i = 0; i < TotalAmount; i++)
	{
		if (Args[i].isString == true)
		{
			std::string tt = convertWStringToUtf8(Args[i].text);
			char* t = (char*) tt.c_str();

			int len = strlen(t);
			Entries[i].String = true;
			Entries[i].num = StrData.GetCount();
			StrData.AddEntry((unsigned char*)t,len);
			SpaceNeeded += len*UnitSize;
		} else {
			Entries[i].String = false;
			Entries[i].num = ExpNum;

			if (initExpression(ExpData[ExpNum++],Args[i].text) == false)
				return;

			SpaceNeeded += UnitSize;
		}
	}
	g_fileManager->advanceMemory(SpaceNeeded);
}
Beispiel #2
0
void SymbolData::addLabel(int memoryAddress, const std::wstring& name)
{
    if (!enabled)
        return;
    addAddress(memoryAddress);

    SymDataSymbol sym;
    sym.address = memoryAddress;
    sym.name = convertWStringToUtf8(name);
    modules[currentModule].symbols.push_back(sym);
}
Beispiel #3
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();
}