Example #1
0
void EmitChar(char c)
{
	if (G_PREV_OP != 0) {
		EmitByte(G_PREV_OP);
		G_PREV_OP = 0;
	}

	if (c == '-' || c == '+') {
		G_PREV_OP = c;
	} else {
		EmitByte(c);
	}
}
Example #2
0
void Ia32Codegen::Emit(Ia32Instr instr, const Ia32Op& op, const Ia32Op& op2) {
	switch (instr) {
		case Ia32Instr::INSTR_MOV:
			{
				if (op.Type == Ia32Op::OP_REG && op.BaseReg==REG_A_CX && op2.Type == Ia32Op::OP_OFFSET) {
					EmitByte(0xB9);
					EmitInt32(op2.Offset);
				} else
					Throw(E_NOTIMPL);
			}
			break;
		case Ia32Instr::INSTR_CALL:
			switch (op.BaseReg & ~REG_MASK) {
				case REG_GP:
					EmitByte(0xFF);
					EmitByte(0xD0 | (op.BaseReg & REG_MASK));
					break;
			}
			break;
		case Ia32Instr::INSTR_RET:
			if (op.Type == Ia32Op::OP_NONE)
				EmitByte(0xC3);
			else {
				EmitByte(0xC2);
				EmitInt16((int16_t)op.Offset);
			}
			break;
		case Ia32Instr::INSTR_IRET:	EmitByte(0xCF); break;
		case Ia32Instr::INSTR_PUSH:
			if ((op.BaseReg & ~REG_MASK) != REG_GP)
				Throw(E_FAIL);
			EmitByte(0x50 |  (op.BaseReg & REG_MASK));
			break;
	}
}
Example #3
0
void EmitStrConst(char * str)
/*
Purpose:
	Emit string constant.
	This code is currently MADS specific to handle emit of single quotes.
	Quotes are emitted like:  'ahaha', 39, 'sksksks'
*/
{
	char * s, c;
	Bool in_quotes = false;
	Bool empty = true;

	if (str != NULL) {
		s = str;	
		while(c = *s++) {		
			if (c == '\'') {
				if (in_quotes) {
					EmitStr("\'");
					in_quotes = false;
				}
				if (!empty) EmitStr(",");
				EmitStr("39");
				empty = false;
			} else {
				if (!in_quotes) {
					if (!empty) EmitStr(",");
					EmitStr("c\'");
					in_quotes = true;
				}
				EmitByte(c);
				empty = false;
			}
		}
		if (in_quotes) {
			EmitStr("\'");
		}
	}
}
Example #4
0
void Emit1 (unsigned char OPC, ExprNode* Value)
/* Emit an instruction with an one byte argument */
{
    Emit0 (OPC);
    EmitByte (Value);
}