Esempio n. 1
0
QString AsmFormatter::tidyEqu( const QString & oldLine )
{
	QString comment = extractComment( oldLine );
	QString code = oldLine;
	code.remove( comment );
	code = code.simplified();

    QStringList parts = code.split(' ', QString::SkipEmptyParts); // QStringList::split( ' ', code ); // 2018.12.01

	QString pad0, pad1, pad2;
	pad0.fill( ' ', m_indentEqu - (parts.at(0)).length() );
	pad1.fill( ' ', m_indentEquValue - m_indentEqu - (parts.at(1)).length() );
	pad2.fill( ' ', m_indentEquComment - m_indentEquValue - m_indentEqu - (parts.at(2)).length() );

	code = parts.at(0) + pad0;
	code += parts.at(1) + pad1;
	code += parts.at(2);
	if ( !comment.isEmpty() )
	{
		code += pad2;
		code += comment;
	}
	
	return code;
}
Esempio n. 2
0
QString AsmFormatter::tidyEqu( const QString & oldLine )
{
	QString comment = extractComment( oldLine );
	QString code = oldLine;
	code.remove( comment );
	code = code.simplifyWhiteSpace();

    QStringList parts = QStringList::split( ' ', code );

	QString pad0, pad1, pad2;
	pad0.fill( ' ', m_indentEqu - (*parts.at(0)).length() );
	pad1.fill( ' ', m_indentEquValue - m_indentEqu - (*parts.at(1)).length() );
	pad2.fill( ' ', m_indentEquComment - m_indentEquValue - m_indentEqu - (*parts.at(2)).length() );

	code = *parts.at(0) + pad0;
	code += *parts.at(1) + pad1;
	code += *parts.at(2);
	if ( !comment.isEmpty() )
	{
		code += pad2;
		code += comment;
	}
	
	return code;
}
Esempio n. 3
0
AsmFormatter::LineType AsmFormatter::lineType( QString line )
{
	line = line.simplified();
	
	line.remove( extractComment( line ) );
	
	QStringList parts = line.split(' ', QString::SkipEmptyParts); // QStringList::split( ' ', line ); // 2018.12.01
	QStringList::iterator end = parts.end();
	for ( QStringList::iterator it = parts.begin(); it != end; ++it )
	{
		if ( (*it).toLower() == "equ" )
			return Equ;
	}
	
	InstructionParts instructionParts( line );
	if ( !instructionParts.operand().isEmpty() )
		return Instruction;
	
	return Other;
}
Esempio n. 4
0
//BEGIN class InstructionParts
InstructionParts::InstructionParts( QString line )
{
	m_comment = extractComment( line );
	line.remove( m_comment );
	
	line = line.simplified();
	QStringList parts = line.split(' ', QString::SkipEmptyParts); // QStringList::split( ' ', line ); // 2018.12.01
	
	bool foundOperand = false;
	QStringList::iterator end = parts.end();
	for ( QStringList::iterator it = parts.begin(); it != end; ++it )
	{
		if ( foundOperand )
		{
			// Already found the operand, so anything else must be the operand
			// data.
			
			if ( m_operandData.isEmpty() )
				m_operandData = *it;
			else
				m_operandData += ' ' + *it;
			
			continue;
		}
		
		if ( PicAsm12bit::self()->operandList().contains( (*it).toUpper() )
				   || PicAsm14bit::self()->operandList().contains( (*it).toUpper() )
				   || PicAsm16bit::self()->operandList().contains( (*it).toUpper() ) )
		{
			m_operand = *it;
			foundOperand = true;
		}
		else
		{
			// Must be a label
			m_label = *it;
		}
	}
}
Esempio n. 5
0
void parse(const char * filename, SSUStruct& ssus)
{
	void * parser = ssuParserAlloc(malloc);
	FILE * f = fopen(filename, "rt");
	ssus.fileName.push_back(filename);
	ssus.row.push_back(0);
	ssus.col.push_back(0);
	int lineNo = 0;
	while(!feof(f))
	{
		char s[4096];
		++ lineNo;
		if(fgets(s, 4096, f) == NULL)
			continue;
		++ ssus.row.back();
		size_t len = strlen(s);
		if(len == 0)
			continue;
		int i = (int)len - 1;
		while(i >= 0 && typeFromChar(s[i]) == 9)
			-- i;
		if(i < 0)
			continue;
		s[i + 1] = 0;
		int err = 0;
		char * cmt = extractComment(s, err);
		if(err)
		{
			fprintf(stderr, "[%s] %d:1  Unpaired quotes!", filename, lineNo);
			exit(0);
		}
		if(cmt != NULL)
			ssuParser(parser, TK_COMMENT, strdup(cmt), &ssus);
		char * sstart = s;
		char * scurrent = s;
		bool nextLine = false;
		int currentCharId = -1;
		while(!nextLine)
		{
			int charId = typeFromChar(*scurrent);
			switch(charId)
			{
			case 9:
				if(scurrent != sstart)
				{
					PUSH_LASTTOKEN;
				}
				nextLine = true;
				break;
			case 8:
				{
					PUSH_LASTTOKEN;
					do
					{
						++ scurrent;
					}
					while(typeFromChar(*scurrent) == 8);
					sstart = scurrent;
					currentCharId = -1;
					continue;
				}
			case 7:
				{
					PUSH_LASTTOKEN;
					sstart = scurrent + 1;
					scurrent = strchr(sstart, *scurrent);
					std::string tmpStr2(sstart, scurrent);
					ssuParser(parser, TK_CUSTOM, strdup(tmpStr2.c_str()), &ssus);
					sstart = scurrent + 1;
				}
				break;
			case 1:
			case 0:
				if(charId != currentCharId)
				{
					PUSH_LASTTOKEN
					currentCharId = charId;
					sstart = scurrent;
				}
				if(charId == 0)
				{
					ssus.col.back() = scurrent - s + 1;
					ssus.word = *scurrent;
					push(parser, &ssus);
					sstart = scurrent + 1;
				}
				break;
			}
			if(nextLine)
				break;
			++ scurrent;
		}
	}
	fclose(f);

	ssuParser(parser, 0, NULL, &ssus);
	ssuParserFree(parser, free);
	ssus.fileName.erase(ssus.fileName.end() - 1);
	ssus.row.erase(ssus.row.end() - 1);
	ssus.col.erase(ssus.col.end() - 1);
}