Пример #1
0
void Assembler::replaceLabels(){
	for(int i=0; i<alignedProgram.size(); i++){
		ProgramAtom atom = alignedProgram[i];
		if(atom.type == DIRECTIVE_INSTRUCTION){
		//Modified replacement
			string mnemonic = parser.extractFirstToken(atom.token);
			mnemonic = parser.toLower(mnemonic);
			bool isBranch = parser.tokenIsBranchInstructionName(mnemonic);
			bool isJump = parser.tokenIsJumpInstructionName(mnemonic);
			vector<string> instructionTokens = parser.tokenizeInstruction(atom.token);
			if(isBranch || isJump){
				string lastToken = instructionTokens[instructionTokens.size() - 1];
				if(!tokenIsInLabelDB(lastToken)){
					//EXCEPTION
					string error = ERROR_UNRECOGNIZED_LABEL;
					string offendingToken = lastToken;
					addException(AssemblerException(*atom.programLine, error, offendingToken));
					continue;
				}
				virtualAddr labelAddr = getLabelAddress(lastToken);
				virtualAddr instructionAddr = atom.addr;
				virtualAddr immediateVal = 0;
				if(isBranch){
					int32_t offset = labelAddr - instructionAddr - 4;	//pc still increments by 4 on branches
					offset >>= 2;
					immediateVal = (virtualAddr)offset;
				}else if(isJump){
					immediateVal = (labelAddr & 0x0FFFFFFF) >> 2;
				}
				string immediateString = parser.literals.getHexLiteralString(immediateVal);
				instructionTokens[instructionTokens.size() - 1] = immediateString;
				string newInstructionString = parser.combineInstructionTokens(instructionTokens);
				alignedProgram[i].token = newInstructionString;
			}else{
Пример #2
0
void Assembler::extractMacroDefinitions(){
	for(int lineNum=0; lineNum<program.size(); lineNum++){
		vector<ProgramLine> macroLines;
		ProgramLine programLine = program[lineNum];
		string token = parser.extractFirstToken(programLine.text);
		if(token == ".macro"){
			macroLines.push_back(programLine);
			program.erase(program.begin() + lineNum);
			while(lineNum < program.size()){
                if(parser.extractFirstToken(program[lineNum].text) == ".end_macro"){
					break;
				}
				macroLines.push_back(program[lineNum]);
				program.erase(program.begin() + lineNum);
			}
            if(program.size() == 0){
                //EXCEPTION
				string error = "Macro not matched with .end_macro directive before EOF";
				string offendingToken = programLine.text;
				addException(AssemblerException(programLine, error, offendingToken));
                return;
            }
			macroLines.push_back(program[lineNum]);
			program.erase(program.begin() + lineNum);
			MacroAtom atom = MacroAtom(macroLines);
			macroDB.push_back(atom);
			lineNum--;
		}else{

		}
	}
}
Пример #3
0
void MGHPCCPod::checkExceptions()
{
    std::map<std::string, RackAndIRC*>::iterator it;
    // Check temperature exceptions:
    for (it=m_coupled.begin(); it!=m_coupled.end(); ++it){
        RackAndIRC *rackIrc = it->second;
        std::map<std::string, Rack>::iterator it2;
        for (it2=rackIrc->m_rack.begin(); it2!=rackIrc->m_rack.end(); ++it2){
            Rack &rack = it2->second;
            std::map<std::string, Server*>::iterator it3;
            for (it3=rack.m_servers.begin(); it3!=rack.m_servers.end(); ++it3){
                Server *server = it3->second;
                bool high = server->checkMaxCPUTemp();
                if (high){
                    std::string msg = "Server " + it3->first + " reached "
                        + std::to_string(server->getCPUTemperature()[0])
                        + " degrees.";
                    std::string ex = std::string(MAX_TEMP_EX); 
                    addException(ex, msg);
                    return ;
                }
            }
        }
    }
}
Пример #4
0
Exception::Exception(ErrorType error_type, const QString &method, const QString &file, int line, Exception *exception, const QString &extra_info)
{
	/* Because the Exception class is not derived from QObject the function tr() is inefficient to translate messages
		so the translation method is called  directly from the application specifying the
		context (Exception) in the ts file and the text to be translated */
	configureException(QApplication::translate("Exception",messages[error_type][ERROR_MESSAGE].toStdString().c_str(),"", -1),
										 error_type, method, file, line, extra_info);

	if(exception) addException(*exception);
}
Пример #5
0
Exception::Exception(const QString &msg, ErrorType error_type, const QString &method, const QString &file, int line, vector<Exception> &exceptions, const QString &extra_info)
{
	vector<Exception>::iterator itr=exceptions.begin();

	configureException(msg,error_type, method, file, line, extra_info);

	while(itr!=exceptions.end())
	{
		addException((*itr));
		itr++;
	}
}
Пример #6
0
Exception::Exception(const QString &msg, const QString &method, const QString &file, int line, vector<Exception> &exceptions, const QString &extra_info)
{
	vector<Exception>::iterator itr, itr_end;

	configureException(msg,ERR_CUSTOM, method, file, line, extra_info);

	itr=exceptions.begin();
	itr_end=exceptions.end();
	while(itr!=itr_end)
	{
		addException((*itr));
		itr++;
	}
}
Пример #7
0
CoolingParams* MGHPCCPod::computePower(double tempWaterCold)
{
    //Clear previous exceptions
    clearExceptions();
    
    //Compute power for each Rack-IRC pair
    std::map<std::string, RackAndIRC*>::iterator it;
    double totalGallons = 0;
    double accumWaterHeat = 0;
    m_powerSummary.serverITPower = 0;
    m_powerSummary.serverFSPower = 0;
    m_powerSummary.ircPower = 0;
    
    for (it=m_coupled.begin(); it!=m_coupled.end(); ++it){
        VLOG_2 << "Computing power for Rack-IRC couple " << it->first;

        // Compute Rack parameters struct
        RackParams *rpars = computeRackPower(it->second, -1);
       
        //Compute IRC power, amount of gallons needed and temperature of hot water
        VLOG_2 << "Computing IRC parameters" ;
        double gallons = it->second->getIRC()->
            computeGallons(rpars->airflow, rpars->serverITPower,
            rpars->avgTout, tempWaterCold);

        if (gallons < 0){
            std::string ex = std::string(PERF_EX);
            std::string msg = "";
            addException(ex, msg);
            return NULL;
        }
        double hotWaterTemp = it->second->getIRC()->computeHotWaterTemp(gallons,
                                                                        rpars->serverITPower);
        accumWaterHeat += gallons*hotWaterTemp;
        totalGallons+=gallons;

        // Save power values
        m_powerSummary.serverITPower += rpars->serverITPower;
        m_powerSummary.serverFSPower += rpars->serverFSPower;
        m_powerSummary.ircPower += rpars->ircPower;
    }

    CoolingParams *cooling = new CoolingParams{};
    cooling->waterFlow=totalGallons;
    cooling->waterTemp=accumWaterHeat/totalGallons;
    VLOG_1 << "Cooling params: waterFlow=" << cooling->waterFlow
           << " waterHotTemp=" << cooling->waterTemp ;
    
    return cooling;
}
Пример #8
0
void EventWinRecurrence::initExceptions()
{
    exceptionDateEdit = new KDateEdit(exceptionGroupBox);
    addExceptionButton = new QPushButton(i18n("Add"), exceptionGroupBox);
    changeExceptionButton = new QPushButton(i18n("Change"), exceptionGroupBox);
    deleteExceptionButton = new QPushButton(i18n("Delete"), exceptionGroupBox);
    exceptionList = new QListBox(exceptionGroupBox);

    exceptionDateEdit->move(15,22);
    exceptionDateEdit->adjustSize();

    addExceptionButton->adjustSize();
    addExceptionButton->setFixedHeight(20);
    addExceptionButton->setFixedWidth(80);
    addExceptionButton->move(exceptionDateEdit->geometry().topLeft().x(),
                             exceptionDateEdit->geometry().bottomLeft().y()+10);

    changeExceptionButton->adjustSize();
    changeExceptionButton->setFixedHeight(20);
    changeExceptionButton->setFixedWidth(80);
    changeExceptionButton->move(addExceptionButton->geometry().topLeft().x(),
                                addExceptionButton->geometry().bottomLeft().y()+5);

    deleteExceptionButton->adjustSize();
    deleteExceptionButton->setFixedHeight(20);
    deleteExceptionButton->setFixedWidth(80);
    deleteExceptionButton->move(changeExceptionButton->geometry().topLeft().x(),
                                changeExceptionButton->geometry().bottomLeft().y()+5);

    exceptionList->move(exceptionDateEdit->geometry().topRight().x()+10,
                        exceptionDateEdit->geometry().topRight().y());

    exceptionList->adjustSize();
    exceptionList->setFixedWidth(110);
    exceptionList->setFixedHeight(100);

    exceptionGroupBox->adjustSize();
    exceptionGroupBox->setFixedWidth((width()/2)-25);
    exceptionGroupBox->setFixedHeight(exceptionGroupBox->height()-10);

    connect(addExceptionButton, SIGNAL(clicked()),
            this, SLOT(addException()));
    connect(changeExceptionButton, SIGNAL(clicked()),
            this, SLOT(changeException()));
    connect(deleteExceptionButton, SIGNAL(clicked()),
            this, SLOT(deleteException()));

}
Пример #9
0
Exception::Exception(ErrorType error_type, const QString &method, const QString &file, int line, vector<Exception> &exceptions, const QString &extra_info)
{
	vector<Exception>::iterator itr, itr_end;

	/* Because the Exception class is not derived from QObject the function tr() is inefficient to translate messages
		so the translation method is called  directly from the application specifying the
		context (Exception) in the ts file and the text to be translated */
	configureException(QApplication::translate("Exception",messages[error_type][ERROR_MESSAGE].toStdString().c_str(),"",-1),
										 error_type, method, file, line, extra_info);

	itr=exceptions.begin();
	itr_end=exceptions.end();
	while(itr!=itr_end)
	{
		addException((*itr));
		itr++;
	}
}
Пример #10
0
void Assembler::flushLabelBuffer(){
	for(int i=0; i<labelsToAssign.size(); i++){
		virtualAddr addr = memorySegmentTopArray[currentMemorySegment];
		try{
			addLabelAddress(parser.getLabelName(labelsToAssign[i]->text), addr);
		}catch(InvalidTokenException &e){
			//EXCEPTION
			string error = ERROR_INVALID_LABEL;
			string offendingToken = labelsToAssign[i]->text;
			addException(AssemblerException(*labelsToAssign[i], error, offendingToken));
			continue;
		}

		ProgramAtom atom;
		atom.addr = addr;
		atom.token = parser.getLabelName(labelsToAssign[i]->text);
		atom.type = DIRECTIVE_LABEL;
		atom.programLine = labelsToAssign[i];
		alignedProgram.push_back(atom);
	}
	labelsToAssign.clear();
}
Пример #11
0
void UmlOperation::importExceptions(File & f)
{
    QByteArray s;
    unsigned rank = 0;

    if (f.read(s) != STRING)
        f.syntaxError(s, "the exceptions");

    int index = 0;

    while (!(s = s.mid(index).trimmed()).isEmpty()) {
        if ((index = s.indexOf(' ')) == -1)
            index = s.length();

        UmlTypeSpec t;
        int index2;

        t.explicit_type = s.left(index);

        if (((index2 = t.explicit_type.indexOf("[")) != -1) &&
            (((const char *) t.explicit_type)[t.explicit_type.length() - 1]
             == ']')) {
            QByteArray target_id =
                t.explicit_type.mid(index2 + 1,
                                    t.explicit_type.length() - index2 - 2);
            UmlClass * cl = (UmlClass *) UmlItem::findItem(target_id, aClass);

            if (cl != 0) {
                t.explicit_type = 0;
                t.type = cl;
            }
            else
                t.explicit_type.truncate(index2);
        }

        addException(rank++, t);
    }
}
Пример #12
0
void Assembler::alignRawProgram(){
	for(int lineNum=0; lineNum<program.size(); lineNum++){
		ProgramLine programLine = program[lineNum];

		string token = parser.extractFirstToken(programLine.text);
		if(parser.tokenIsLabel(token)){
			string labelName = parser.getLabelName(token);
			programLine.text = labelName;
			labelsToAssign.push_back(&program[lineNum]);
			continue;
		}else if(parser.tokenIsDirective(token)){
			parser.extractAndRemoveFirstToken(programLine.text, token);
			applyDirective(token, &programLine);
			token = parser.extractFirstToken(programLine.text);
		}
		
		if(programLine.text == "" && currentAction != ACTION_DECLARE_SEGMENT && currentAction != ACTION_MEMWRITE_INTEGRAL){
			continue; //if programLine is all consumed, skip to next line unless you need to declare segment in following actions
		}
		//consume literal token
		ProgramAtom atom;
		string mappedProgramString;
		switch(currentAction){
			case ACTION_INIT:
				{
					string error = ERROR_UNRECOGNIZED_TOKEN;
					string offendingToken = programLine.text;
					addException(AssemblerException(program[lineNum], error, offendingToken));
					continue;
				}
				break;
			case ACTION_DECLARE_SEGMENT:
				{
					virtualAddr addr = getCurrentMemoryLocation();
					mappedProgramString = parser.getDirectiveName(currentMemorySegment);
					atom.addr = addr;
					atom.token = mappedProgramString;
					atom.type = currentMemorySegment;
					atom.programLine = &program[lineNum];
					alignedProgram.push_back(atom);
					switch(currentMemorySegment){
						case DIRECTIVE_DATA:
							currentAction = ACTION_INIT;
							break;
						case DIRECTIVE_TEXT:
							currentAction = ACTION_INSTRUCTION_ENCODE;
							break;
						case DIRECTIVE_KDATA:
							currentAction = ACTION_INIT;
							break;
						case DIRECTIVE_KTEXT:
							currentAction = ACTION_INSTRUCTION_ENCODE;
							break;
					}
				}
				break;
			case ACTION_MEMWRITE_INTEGRAL:
				{
					alignSegmentTop();
					flushLabelBuffer();

					vector<string> literalTokens = parser.commaSeparatedLiteralListExplode(programLine.text);
					alignLiteralTokenList(literalTokens, programLine.text, &program[lineNum]);
					currentAction = ACTION_INIT;
				}
				break;
			case ACTION_MEMWRITE_STRING:
				{
					flushLabelBuffer();
					int i=0;
					while(programLine.text[i] != '"'){i++;}

					string stringLiteral = programLine.text.substr(i);
					string rawString;
					try{
						rawString = parser.literals.getStringLiteralValue(stringLiteral);
					}catch(InvalidTokenException &e){
						//EXCEPTION
						string error = ERROR_INVALID_STRING_LITERAL;
						string offendingToken = programLine.text;
						addException(AssemblerException(program[lineNum], error, offendingToken));
						continue;
					}

					mappedProgramString = parser.literals.getRawStringLiteralValue(rawString);
					atom.addr = getCurrentMemoryLocation();
					atom.token = mappedProgramString;
					atom.type = currentValueTypeSpecifier;
					atom.programLine = &program[lineNum];
					alignedProgram.push_back(atom);
					
					virtualAddr segmentIncrementSize = rawString.length() * SIZE_BYTES_BYTE;
					if(currentValueTypeSpecifier == DIRECTIVE_ASCIIZ){
						segmentIncrementSize+=2;
					}

					incrementSegmentTop(segmentIncrementSize);
					currentAction = ACTION_INIT;
				}
				break;
			case ACTION_ALIGN:
				{
					try{
						currentByteAlignment = parser.literals.getFixedPointLiteralValue(token);
					}catch(InvalidTokenException &e){
						string error = ERROR_INVALID_ALIGNMENT_VALUE;
						string offendingToken = token;
						addException(AssemblerException(program[lineNum], error, token));
						continue;
					}
					alignSegmentTop();
					currentAction = ACTION_INIT;
				}
				break;
			case ACTION_SPACE:
				{
					currentByteAlignment = SIZE_BYTES_BYTE;
					alignSegmentTop();
					flushLabelBuffer();

					parser.extractAndRemoveFirstToken(programLine.text, token);
					uint32_t spaceSize = 0;
					try{
						spaceSize = parser.literals.getFixedPointLiteralValue(token);
					}catch(InvalidTokenException &e){
						//EXCEPTION
						string error = ERROR_INVALID_SPACE_VALUE;
						string offendingToken = token;
						addException(AssemblerException(program[lineNum], error, offendingToken));
						continue;
					}

					atom.token = parser.literals.getDecimalLiteralString(spaceSize);
					atom.addr = getCurrentMemoryLocation();
					atom.type = DIRECTIVE_SPACE;
					atom.programLine = &program[lineNum];
					alignedProgram.push_back(atom);

					incrementSegmentTop(spaceSize);
					currentAction = ACTION_INIT;
				}
				break;
			case ACTION_INSTRUCTION_ENCODE:
				{
					currentByteAlignment = SIZE_BYTES_WORD;
					alignSegmentTop();
					flushLabelBuffer();

					atom.addr = getCurrentMemoryLocation();
					atom.token = programLine.text;	//instruction full line
					atom.type = DIRECTIVE_INSTRUCTION;
					atom.programLine = &program[lineNum];
					alignedProgram.push_back(atom);

					incrementSegmentTop(SIZE_BYTES_WORD);
				}
				break;
			default:
				
				break;
		}
	}
}
Пример #13
0
void Assembler::applyDirective(string directive, ProgramLine* programLine){
	uint32_t directiveNumber = parser.getDirectiveNumber(directive);
	switch(directiveNumber){
		//Primary memory segments
		case DIRECTIVE_DATA:
			currentMemorySegment = DIRECTIVE_DATA;
			currentAction = ACTION_DECLARE_SEGMENT;
			break;
		case DIRECTIVE_TEXT:
			currentMemorySegment = DIRECTIVE_TEXT;
			currentAction = ACTION_DECLARE_SEGMENT;
			break;
		case DIRECTIVE_KDATA:
			currentMemorySegment = DIRECTIVE_KDATA;
			currentAction = ACTION_DECLARE_SEGMENT;
			break;
		case DIRECTIVE_KTEXT:
			currentMemorySegment = DIRECTIVE_KTEXT;
			currentAction = ACTION_DECLARE_SEGMENT;
			break;

		//Memory value type specifiers (integral)
		case DIRECTIVE_BYTE:
			currentValueTypeSpecifier = DIRECTIVE_BYTE;
			currentByteAlignment = SIZE_BYTES_BYTE;
			currentAction = ACTION_MEMWRITE_INTEGRAL;
			break;
		case DIRECTIVE_HALF:
			currentValueTypeSpecifier = DIRECTIVE_HALF;
			currentByteAlignment = SIZE_BYTES_HWORD;
			currentAction = ACTION_MEMWRITE_INTEGRAL;
			break;
		case DIRECTIVE_WORD:
			currentValueTypeSpecifier = DIRECTIVE_WORD;
			currentByteAlignment = SIZE_BYTES_WORD;
			currentAction = ACTION_MEMWRITE_INTEGRAL;
			break;
		case DIRECTIVE_FLOAT:
			currentValueTypeSpecifier = DIRECTIVE_FLOAT;
			currentByteAlignment = SIZE_BYTES_FLOAT;
			currentAction = ACTION_MEMWRITE_INTEGRAL;
			break;
		case DIRECTIVE_DOUBLE:
			currentValueTypeSpecifier = DIRECTIVE_DOUBLE;
			currentByteAlignment = SIZE_BYTES_DOUBLE;
			currentAction = ACTION_MEMWRITE_INTEGRAL;
			break;

		//Memory value type specifiers (string)
		case DIRECTIVE_ASCII:
			currentValueTypeSpecifier = DIRECTIVE_ASCII;
			currentByteAlignment = SIZE_BYTES_BYTE;
			currentAction = ACTION_MEMWRITE_STRING;
			break;
		case DIRECTIVE_ASCIIZ:
			currentValueTypeSpecifier = DIRECTIVE_ASCIIZ;
			currentByteAlignment = SIZE_BYTES_BYTE;
			currentAction = ACTION_MEMWRITE_STRING;
			break;

		//Memory alignment specifiers
		case DIRECTIVE_ALIGN:
			currentAction = ACTION_ALIGN;
			break;
		case DIRECTIVE_SPACE:
			currentByteAlignment = SIZE_BYTES_BYTE;
			currentAction = ACTION_SPACE;
			break;
		case DIRECTIVE_INCLUDE:

			break;
		case DIRECTIVE_EXTERN:

			break;
		case DIRECTIVE_GLOBL:

			break;
		case DIRECTIVE_SET:

			break;
		case DIRECTIVE_MACRO:
            currentAction = ACTION_INSTRUCTION_ENCODE;
			break;
		case DIRECTIVE_END_MACRO:
            currentAction = ACTION_INIT;
			break;
		case DIRECTIVE_EQV:

			break;
		default:
			//EXCEPTION
			string error = ERROR_UNRECOGNIZED_DIRECTIVE;
			string offendingToken = directive;
			addException(AssemblerException(*programLine, error, offendingToken));
			break;
	}
}
Пример #14
0
bool Recurrence::removeOccurrence(const QDate &date) {
	addException(date);
	return true;
}
Пример #15
0
Exception::Exception(const QString &msg, ErrorType error_type, const QString &method, const QString &file, int line, Exception *exception, const QString &extra_info)
{
	configureException(msg,error_type, method, file, line, extra_info);
	if(exception) addException(*exception);
}
Пример #16
0
//Post-processing
void Assembler::pseudoInstructionReplace(){
	for(int i=0; i<alignedProgram.size(); i++){
		ProgramAtom atom = alignedProgram[i];
		string line = atom.token;
		if(atom.type == DIRECTIVE_INSTRUCTION){
			string mnemonic = parser.extractFirstToken(atom.token);
			mnemonic = parser.toLower(mnemonic);
			if(parser.tokenIsPseudoInstructionName(mnemonic)){
				int pseudoInstructionNumber = parser.getPseudoInstructionNameNumber(mnemonic);
				int numInsertedLines = parser.getPseudoInstructionNumberOfLinesToInsert(mnemonic);
				vector<string> tokenizedInstruction = parser.tokenizeInstruction(line);
				switch(pseudoInstructionNumber){
					//TODO: add exceptions for incorrect number of instruction arguments
					case 0:
						{
							//bge	$reg1, $reg2, label
							if(tokenizedInstruction.size() != 4){addException(AssemblerException(*atom.programLine, ERROR_INVALID_PSEUDOINSTRUCTION, atom.programLine->text));continue;}
							string registerName1 = tokenizedInstruction[1];
							string registerName2 = tokenizedInstruction[2];
							string labelName = tokenizedInstruction[3];
							string line1 = "slt\t$at, " + registerName1 + ", " + registerName2;
							string line2 = "beq\t$at, $zero, " + labelName;
							alignedProgram[i].token = line1;
							alignedProgram[i+1].token = line2;
						}
						break;
					case 1:
						{
							//bgt	$reg1, $reg2, label
							if(tokenizedInstruction.size() != 4){addException(AssemblerException(*atom.programLine, ERROR_INVALID_PSEUDOINSTRUCTION, atom.programLine->text));continue;}
							string registerName1 = tokenizedInstruction[1];
							string registerName2 = tokenizedInstruction[2];
							string labelName = tokenizedInstruction[3];
							string line1 = "slt\t$at, " + registerName2 + ", " + registerName1;
							string line2 = "bne\t$at, $zero, " + labelName;
							alignedProgram[i].token = line1;
							alignedProgram[i+1].token = line2;
						}
						break;
					case 2:
						{
							//ble	$reg1, $reg2, label
							if(tokenizedInstruction.size() != 4){addException(AssemblerException(*atom.programLine, ERROR_INVALID_PSEUDOINSTRUCTION, atom.programLine->text));continue;}
							string registerName1 = tokenizedInstruction[1];
							string registerName2 = tokenizedInstruction[2];
							string labelName = tokenizedInstruction[3];
							string line1 = "slt\t$at, " + registerName2 + ", " + registerName1;
							string line2 = "beq\t$at, $zero, " + labelName;
							alignedProgram[i].token = line1;
							alignedProgram[i+1].token = line2;

						}
						break;
					case 3:
						{
							//blt	$reg1, $reg2, label
							if(tokenizedInstruction.size() != 4){addException(AssemblerException(*atom.programLine, ERROR_INVALID_PSEUDOINSTRUCTION, atom.programLine->text));continue;}
							string registerName1 = tokenizedInstruction[1];
							string registerName2 = tokenizedInstruction[2];
							string labelName = tokenizedInstruction[3];
							string line1 = "slt\t$at, " + registerName1 + ", " + registerName2;
							string line2 = "bne\t$at, $zero, " + labelName;
							alignedProgram[i].token = line1;
							alignedProgram[i+1].token = line2;
						}
						break;
					case 4:
						{
							//clear	$reg
							if(tokenizedInstruction.size() != 2){addException(AssemblerException(*atom.programLine, ERROR_INVALID_PSEUDOINSTRUCTION, atom.programLine->text));continue;}
							string registerName1 = tokenizedInstruction[1];
							string line1 = "add\t" + registerName1 + ", $zero, $zero";
							alignedProgram[i].token = line1;
						}
						break;
					case 5:
						{
							//la	$reg, label
							if(tokenizedInstruction.size() != 3){addException(AssemblerException(*atom.programLine, ERROR_INVALID_PSEUDOINSTRUCTION, atom.programLine->text));continue;}
							string labelName = tokenizedInstruction[2];
							if(!tokenIsInLabelDB(labelName)){
								//EXCEPTION
								string error = ERROR_UNRECOGNIZED_LABEL;
								string offendingToken = labelName;
								addException(AssemblerException(*atom.programLine, error, offendingToken));
								continue;
							}
							virtualAddr labelAddr = getLabelAddress(labelName);
							virtualAddr msb = labelAddr >> (SIZE_BITS_VIRTUAL_ADDR / 2);
							virtualAddr lsb = labelAddr & 0x0000FFFF;
							string msbHex = parser.literals.getHexLiteralString(msb);
							string lsbHex = parser.literals.getHexLiteralString(lsb);
							string registerName = tokenizedInstruction[1];
							string line1 = "lui\t" + registerName + ", " + msbHex;
							string line2 = "ori\t" + registerName + ", " + registerName + ", " + lsbHex;
							alignedProgram[i].token = line1;
							alignedProgram[i+1].token = line2;
						}
						break;
					case 6:
						{
							//li	$reg, imm
							if(tokenizedInstruction.size() != 3){addException(AssemblerException(*atom.programLine, ERROR_INVALID_PSEUDOINSTRUCTION, atom.programLine->text));continue;}
							string immediateString = tokenizedInstruction[2];

							//EXCEPTION
							//TODO
							uint32_t immediateVal;
							try{
								immediateVal = parser.literals.getLiteralValue(immediateString);
							}catch(InvalidTokenException &e){
								string error = ERROR_INVALID_IMMEDIATE_LI;
								string offendingToken = immediateString;
								addException(AssemblerException(*atom.programLine, error, offendingToken));
								continue;
							}
							virtualAddr msb = immediateVal >> (SIZE_BITS_WORD / 2);
							virtualAddr lsb = immediateVal & 0x0000FFFF;
							string msbHex = parser.literals.getHexLiteralString(msb);
							string lsbHex = parser.literals.getHexLiteralString(lsb);
							string registerName = tokenizedInstruction[1];
							string line1 = "lui\t" + registerName + ", " + msbHex;
							string line2 = "ori\t" + registerName + ", " + registerName + ", " + lsbHex;
							alignedProgram[i].token = line1;
							alignedProgram[i+1].token = line2;

						}
						break;
					case 7:
						{
							//move	$reg1, $reg2
							if(tokenizedInstruction.size() != 3){addException(AssemblerException(*atom.programLine, ERROR_INVALID_PSEUDOINSTRUCTION, atom.programLine->text));continue;}
							string registerName1 = tokenizedInstruction[1];
							string registerName2 = tokenizedInstruction[2];
							string line1 = "add\t" + registerName1 + ", " + registerName2 + ", $zero";
							alignedProgram[i].token = line1;
						}
						break;
					case 8:
						{
							//neg	$reg1, $reg2
							if(tokenizedInstruction.size() != 3){addException(AssemblerException(*atom.programLine, ERROR_INVALID_PSEUDOINSTRUCTION, atom.programLine->text));continue;}
							string registerName1 = tokenizedInstruction[1];
							string registerName2 = tokenizedInstruction[2];
							string line1 = "sub\t" + registerName1 + ", $zero, " + registerName2;
							alignedProgram[i].token = line1;
						}
						break;
					case 9:
						{
							//not	$reg1, $reg2
							if(tokenizedInstruction.size() != 3){addException(AssemblerException(*atom.programLine, ERROR_INVALID_PSEUDOINSTRUCTION, atom.programLine->text));continue;}
							string registerName1 = tokenizedInstruction[1];
							string registerName2 = tokenizedInstruction[2];
							string line1 = "addi\t" + registerName1 + ", $zero, -1";
							string line2 = "xor\t" + registerName1 + ", " + registerName1 + "," + registerName2;
							alignedProgram[i].token = line1;
							alignedProgram[i+1].token = line2;
						}
						break;
						/*
						PUSH:
						sub $sp,$sp,4
						sw $t2,($sp)

						POP:
						lw $t2,($sp)
						addiu $sp,$sp,4
						*/
					case 10:
						{
							//push	$reg
							if(tokenizedInstruction.size() != 2){addException(AssemblerException(*atom.programLine, ERROR_INVALID_PSEUDOINSTRUCTION, atom.programLine->text));continue;}
							string registerName1 = tokenizedInstruction[1];
							string line1 = "sub\t$sp, $sp, 4";
							string line2 = "sw\t" + registerName1 + ", 0($sp)";
							alignedProgram[i].token = line1;
							alignedProgram[i+1].token = line2;
						}
						break;
					case 11:
						{
							//pop	$reg
							if(tokenizedInstruction.size() != 2){addException(AssemblerException(*atom.programLine, ERROR_INVALID_PSEUDOINSTRUCTION, atom.programLine->text));continue;}
							string registerName1 = tokenizedInstruction[1];
							string line1 = "lw\t" + registerName1 + ", 0($sp)";
							string line2 = "addi\t$sp, $sp, 4";
							alignedProgram[i].token = line1;
							alignedProgram[i+1].token = line2;
						}
						break;
					case 12:
						{
							//peak	$reg
							if(tokenizedInstruction.size() != 2){addException(AssemblerException(*atom.programLine, ERROR_INVALID_PSEUDOINSTRUCTION, atom.programLine->text));continue;}
							string registerName = tokenizedInstruction[1];
							string line = "lw\t" + registerName + ", 0($sp)";
							alignedProgram[i].token = line;
						}
						break;
					case 13:
						{
							//rem

						}
						break;
					case 14:
						{
							//sge

						}
						break;
					case 15:
						{
							//sgt

						}
						break;
					default:

						break;
				}
				i += numInsertedLines;
			}else{

			}
		}else{

		}
	}
}
Пример #17
0
Exception::Exception(const QString &msg, const QString &method, const QString &file, int line, Exception *exception, const QString &extra_info)
{
	configureException(msg,ERR_CUSTOM, method, file, line, extra_info);
	if(exception) addException(*exception);
}