int DisAssembler::hxStrConv(string x)
{
	for (int i = 0; i < 16; ++i)
	{
		if (hx[i] == x)
			return i;
		else
			continue;
	}

	errorMessages(1);
} //Works
Exemple #2
0
void LogSQLite::createSchema() {
	static const char *schema = "\
		CREATE TABLE IF NOT EXISTS log_names \
			( timestamp INTEGER DEFAULT(strftime('%s', 'now')) \
			, channel TEXT NOT NULL \
			, namesList TEXT NOT NULL \
			); \
		CREATE TABLE IF NOT EXISTS log_nick \
			( timestamp INTEGER DEFAULT(strftime('%s', 'now')) \
			, channel TEXT NOT NULL \
			, oldNick TEXT NOT NULL \
			, newNick TEXT NOT NULL \
			); \
		CREATE TABLE IF NOT EXISTS log_quit \
			( timestamp INTEGER DEFAULT(strftime('%s', 'now')) \
			, channel TEXT NOT NULL \
			, nick TEXT NOT NULL \
			, quitMessage TEXT NOT NULL \
			); \
		CREATE TABLE IF NOT EXISTS log_join \
			( timestamp INTEGER DEFAULT(strftime('%s', 'now')) \
			, channel TEXT NOT NULL \
			, nick TEXT NOT NULL \
			); \
		CREATE TABLE IF NOT EXISTS log_privmsg \
			( timestamp INTEGER DEFAULT(strftime('%s', 'now')) \
			, channel TEXT NOT NULL \
			, nick TEXT NOT NULL \
			, message TEXT NOT NULL \
			); \
		CREATE VIEW IF NOT EXISTS log AS SELECT type, datetime || ' ' || line FROM \
			( \
				SELECT 'privmsg' AS type, datetime(timestamp, 'unixepoch') AS datetime, '|' || channel || '| <' || nick || '> ' || message AS line FROM log_privmsg \
			UNION ALL \
				SELECT 'names' AS type, datetime(timestamp, 'unixepoch') AS datetime, '|' || channel || '| Users in channel: ' || namesList AS line FROM log_names \
			UNION ALL \
				SELECT 'nick' AS type, datetime(timestamp, 'unixepoch') AS datetime, '|' || channel || '| ' || oldNick || ' changed his nick to ' || newNick AS line FROM log_nick \
			UNION ALL \
				SELECT 'join' AS type, datetime(timestamp, 'unixepoch') AS datetime, '|' || channel || '| ' || nick || ' joined' AS line FROM log_join \
			UNION ALL \
				SELECT 'quit' AS type, datetime(timestamp, 'unixepoch') AS datetime, '|' || channel || '| ' || nick || ' has left (' || quitMessage || ')' AS line FROM log_quit \
			) \
			ORDER BY datetime; \
		";
	char *errorMessagesPtr = NULL;
	if(sqlite3_exec(connection, schema, NULL, NULL, &errorMessagesPtr) != SQLITE_OK) {
		std::string errorMessages(errorMessagesPtr);
		sqlite3_free(errorMessagesPtr);
		throw std::runtime_error("SQLite error: " + errorMessages);
	}
}
void DisAssembler::parseLine(int lineNum)
{
	if (testCC())
	{
		int stringAdd = 0;
		int currentAdd = 0;
		string x = "\0";

		lines[lineNum][0] = line.substr(1, 2);
		lines[lineNum][1] = line.substr(3, 4);
		lines[lineNum][2] = line.substr(7, 2);

		if (!testEOF(lineNum) && !testStart(lineNum))
		{

			bytenum = hxStrConv(lines[lineNum][0].substr(0, 1)) * 16 + hxStrConv(lines[lineNum][0].substr(1, 1));
			lines[lineNum][3] = line.substr(9, bytenum * 2);

			for (int i = 0; i < bytenum * 2; i += 4)
			{
				currentAdd = 0;

				for (int i = 0; i < 4; ++i)
				{
					currentAdd += hxStrConv(lines[lineNum][1].substr(3 - i, 1)) * pow(16, i);
				}

				currentAdd += i / 4;
				lines[lineNum][4] = lines[lineNum][3].substr(i + 2, 2) + lines[lineNum][3].substr(i, 2);
				x = OpCodeHub(lines[lineNum][4]);
				//cout << setw (5) << currentAdd << setw(20) << x << endl;
				program[currentAdd] = x;
			}

		}

		else;

	}

	else
	{
		errorMessages(2);
	}
}
    void cleanup_s()
    {
      // If we're supposed to print out statistics, do so now.
      
      if (printStats())
        statistics_s.print(pinfo, reductionFilter_s);

      // Close the log file, if necessary.

      logMessages(0);

      // Turn off all POOMA streams.

      infoMessages(false);
      warnMessages(false);
      errorMessages(false);
      debugLevel(Inform::off);
    }
string DisAssembler::OpCodeHub(string Opcode)
{
	if (Opcode == "0064") // CLRWDT
	{
		return "CLRWDT";
	}

	else if (Opcode == "1303")
	{
		if (!bankselhelp)
			return "BANKSEL A";
		else
			return "BANKSEL B";
	}

	else if (Opcode == "1703")
	{
		if (!bankselhelp)
			return "BANKSEL C";
		else
			return "BANKSEL D";
	}

	else if (Opcode == "1283")
	{
		bankselhelp = 0;
		return "\0";
	}

	else if (Opcode == "1683")
	{
		bankselhelp = 1;
		return "\0";
	}

	else if (Opcode.substr(0, 2) == "07") // ADDWF
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
		{
			return "ADDWF 0x" + Opcode.substr(2, 2) + ", 0";
		}

		else
		{
			return "ADDWF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 1";
		}
	}

	else if (Opcode.substr(0, 2) == "05") // ANDWF
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
		{
			return "ANDWF 0x" + Opcode.substr(2, 2) + ", 0";
		}

		else
		{
			return "ANDWF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 1";
		}
	}

	else if (Opcode.substr(0, 2) == "01" && hxStrConv(Opcode.substr(2, 1)) > 7) //CLRF
	{
		return "CLRF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1);
	}

	else if (Opcode.substr(0, 2) == "01" && hxStrConv(Opcode.substr(2, 1)) < 8) //CLRW
	{
		return "CLRW";
	}

	else if (Opcode.substr(0, 2) == "09") //COMF
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
		{
			return "COMF 0x" + Opcode.substr(2, 2) + ", 0";
		}

		else
		{
			return "COMF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 1";
		}
	}

	else if (Opcode.substr(0, 2) == "03") //DECF
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
		{
			return "DECF 0x" + Opcode.substr(2, 2) + ", 0";
		}

		else
		{
			return "DECF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 1";
		}
	}

	else if (Opcode.substr(0, 2) == "0B") //DECFSZ
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
		{
			return "DECFSZ 0x" + Opcode.substr(2, 2) + ", 0";
		}

		else
		{
			return "DECFSZ 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 1";
		}
	}

	else if (Opcode.substr(0, 2) == "0A") //INCF
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
		{
			return "INCF 0x" + Opcode.substr(2, 2) + ", 0";
		}

		else
		{
			return "INCF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 1";
		}
	}

	else if (Opcode.substr(0, 2) == "0F") //INCFSZ
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
		{
			return "INCFSZ 0x" + Opcode.substr(2, 2) + ", 0";
		}

		else
		{
			return "INCFSZ 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 1";
		}
	}

	else if (Opcode.substr(0, 2) == "04") //IORWF
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
		{
			return "IORWF 0x" + Opcode.substr(2, 2) + ", 0";
		}

		else
		{
			return "IORWF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 1";
		}
	}

	else if (Opcode.substr(0, 2) == "08") //MOVF
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
		{
			return "MOVF 0x" + Opcode.substr(2, 2) + ", 0";
		}

		else
		{
			return "MOVF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 1";
		}
	}

	else if (Opcode.substr(0, 2) == "00" && hxStrConv(Opcode.substr(2, 1)) > 7) //MOVWF
	{
		return "MOVWF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1);
	}

	else if (Opcode.substr(0, 2) == "00" && hxStrConv(Opcode.substr(2, 1)) > 7) //MOVF
	{
		return "CLRF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1);
	}

	else if (Opcode == "0000") //NOP
	{
		return "NOP";
	}

	else if (Opcode.substr(0, 2) == "0D") //RLF
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
		{
			return "RLF 0x" + Opcode.substr(2, 2) + ", 0";
		}

		else
		{
			return "RLF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 1";
		}
	}

	else if (Opcode.substr(0, 2) == "0C") //RRF
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
		{
			return "RRF 0x" + Opcode.substr(2, 2) + ", 0";
		}

		else
		{
			return "RRF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 1";
		}
	}

	else if (Opcode.substr(0, 2) == "02") //SUBWF
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
		{
			return "SUBWF 0x" + Opcode.substr(2, 2) + ", 0";
		}

		else
		{
			return "SUBWF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 1";
		}
	}

	else if (Opcode.substr(0, 2) == "0E") //SWAPF
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
		{
			return "SWAPF 0x" + Opcode.substr(2, 2) + ", 0";
		}

		else
		{
			return "SWAPF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 1";
		}
	}

	else if (Opcode.substr(0, 2) == "06") //XORWF
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
		{
			return "XORWF 0x" + Opcode.substr(2, 2) + ", 0";
		}

		else
		{
			return "XORWF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 1";
		}
	}

	else if (Opcode == "0009") // RETFIE
	{
		return "RETFIE";
	}


	else if (Opcode == "0008") // RETURN
	{
		return "RETURN";
	}

	else if (Opcode == "0003") // SLEEP
	{
		return "SLEEP";
	}

	else if (Opcode.substr(0, 2) == "3E") //ADDLW
	{
		return "ADDLW 0x" + Opcode.substr(2, 2);
	}

	else if (Opcode.substr(0, 2) == "39") //ANDLW
	{
		return "ANDLW 0x" + Opcode.substr(2, 2);
	}

	else if (Opcode.substr(0, 2) == "38") //IORLW
	{
		return "IORLW 0x" + Opcode.substr(2, 2);
	}

	else if (Opcode.substr(0, 2) == "30") //MOVLW
	{
		return "MOVLW 0x" + Opcode.substr(2, 2);
	}

	else if (Opcode.substr(0, 2) == "34") //RETLW
	{
		return "RETLW 0x" + Opcode.substr(2, 2);
	}

	else if (Opcode.substr(0, 2) == "3C") //SUBLW
	{
		return "SUBLW 0x" + Opcode.substr(2, 2);
	}

	else if (Opcode.substr(0, 2) == "39") //XORLW
	{
		return "XORLW 0x" + Opcode.substr(2, 2);
	}

	else if (Opcode.substr(0, 1) == "2" && hxStrConv(Opcode.substr(1, 1)) < 8) //Call
	{
		return "CALL 0x" + Opcode.substr(1, 3);
	}

	else if (Opcode.substr(0, 1) == "2" && hxStrConv(Opcode.substr(1, 1)) > 7) //GOTO
	{
		return "GOTO 0x" + intStrConv(hxStrConv(Opcode.substr(1, 1)) - 8) + Opcode.substr(2, 2);
	}

	else if (Opcode.substr(0, 1) == "1" && hxStrConv(Opcode.substr(1, 1)) < 4) //BCF
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
			return "BCF 0x" + Opcode.substr(2, 2) + ", 0x" + intStrConv(hxStrConv(Opcode.substr(1, 1)) * 2);

		else
			return "BCF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 0x" + intStrConv((hxStrConv(Opcode.substr(1, 1)) * 2) + 1);
	}

	else if (Opcode.substr(0, 1) == "1" && hxStrConv(Opcode.substr(1, 1)) < 8 && hxStrConv(Opcode.substr(1, 1)) > 3) //BSF
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
			return "BSF 0x" + Opcode.substr(2, 2) + ", 0x" + intStrConv((hxStrConv(Opcode.substr(1, 1)) - 4) * 2);

		else
			return "BSF 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 0x" + intStrConv(((hxStrConv(Opcode.substr(1, 1)) - 4) * 2) + 1);
	}

	else if (Opcode.substr(0, 1) == "1" && hxStrConv(Opcode.substr(1, 1)) < 12 && hxStrConv(Opcode.substr(1, 1)) > 7) //BTFSC
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
			return "BTFSC 0x" + Opcode.substr(2, 2) + ", 0x" + intStrConv((hxStrConv(Opcode.substr(1, 1)) - 8) * 2);

		else
			return "BTFSC 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 0x" + intStrConv(((hxStrConv(Opcode.substr(1, 1)) - 8) * 2) + 1);
	}

	else if (Opcode.substr(0, 1) == "1" && hxStrConv(Opcode.substr(1, 1)) > 11) //BTFSS
	{
		if (hxStrConv(Opcode.substr(2, 1)) < 8)
			return "BTFSS 0x" + Opcode.substr(2, 2) + ", 0x" + intStrConv((hxStrConv(Opcode.substr(1, 1)) - 12) * 2);

		else
			return "BTFSS 0x" + intStrConv(hxStrConv(Opcode.substr(2, 1)) - 8) + Opcode.substr(3, 1) + ", 0x" + intStrConv(((hxStrConv(Opcode.substr(1, 1)) - 12) * 2) + 1);
	}

	else if (Opcode.substr(0, 2) == "3A") //XORLW
	{
		return "XORLW 0x" + Opcode.substr(2, 2);
	}

	else
	{
		errorMessages(3);
		return "\0";
	}
}