示例#1
0
文件: codegen.cpp 项目: jnewing/MyVm
void output_ins1(char *instruction, char *ra)
{
    OpcodeEntry *opc = LookupOpcodeByString(instruction);
    RegisterEntry *rega = LookupRegisterByName(ra);

    emit8(opc->OpCode);
    emit8(rega->Register);
}
示例#2
0
文件: codegen.cpp 项目: jnewing/MyVm
void output_ins2fconst(char *instruction, char *ra, float fconstant)
{
    OpcodeEntry *opc = LookupOpcodeByString(instruction);
    RegisterEntry *rega = LookupRegisterByName(ra);

    emit8(opc->OpCode);
    emit8(rega->Register);
    emitfloat(fconstant);
}
示例#3
0
文件: codegen.cpp 项目: jnewing/MyVm
void output_ins2label(char *instruction, char *ra, char *label)
{
    OpcodeEntry *opc = LookupOpcodeByString(instruction);
    RegisterEntry *rega = LookupRegisterByName(ra);

    emit8(opc->OpCode);
    emit8(rega->Register);
    AddRelocEntry(label, codeptr);
    emit32(0);
}
示例#4
0
文件: codegen.cpp 项目: jnewing/MyVm
void output_string(char *str)
{
    str[0] = 0; // Remove front "
    str++;
    str[strlen(str) - 1] = 0; // Remove back "

    int length = strlen(str);

    for (int i = 0; i < length; i++)
    {
        switch(str[i])
        {
        case '\\':
            switch(str[++i])
            {
            case 'r':
                emit8('\r');
                break;
            case 'n':
                emit8('\n');
                break;
            case 't':
                emit8('\t');
                break;
            case 'b':
                emit8('\b');
                break;
            case 'f':
                emit8('\f');
                break;
            case 'x':
            {
                char buf[3] = {str[++i], str[++i], 0};

                if (!((buf[0] >= 0x30 && buf[0] <= 0x39) || (buf[0] >= 0x41 && buf[0] <= 0x46) || (buf[0] >= 0x61 && buf[0] <= 0x66)))
                {
                    Error("Invalid hexadecimal character '%c'", buf[0]);
                }

                if (!((buf[1] >= 0x30 && buf[1] <= 0x39) || (buf[1] >= 0x41 && buf[1] <= 0x46) || (buf[1] >= 0x61 && buf[1] <= 0x66)))
                {
                    Error("Invalid hexadecimal character '%c'", buf[1]);
                }

                emit8(strtoul(buf, 0, 16));
                break;
            }
            default:
                Error("Unsupported type '\\%c' in string", str[i]);
                break;
            }
            break;
        default:
            emit8(str[i]);
            break;
        }
    }

    emit8(0); // Null terminated string
}
示例#5
0
void
ByteCodeStream::emitString(brew::string & s)
{
  char * ptr = (char*)s;
  while (*++ptr)
  {
	  if (*ptr == '\'')
	  {
		  if (*(ptr+1) == '\'')
		  {
			  emit8(*ptr++);
		  }
	  } else {
		  emit8(*ptr);
	  }
  }
}
示例#6
0
文件: codegen.cpp 项目: jnewing/MyVm
void output_insb1label(char *instruction, char *label)
{
    OpcodeEntry *opc = LookupOpcodeByString(instruction);

    emit8(opc->OpCode);
    AddRelocEntry(label, codeptr);
    emit32(0);
}
示例#7
0
文件: a_all.cpp 项目: BigEd/Cores
	void Assembler::align()
	{
		long data;

		g_nops = getCpu()->getOp()->get();
		data = ((Operands6502 *)getCpu()->getOp())->op[0].val.value;
		DoingDc = true;
		gSzChar = 'B';
		switch(CurrentArea)
		{
			case CODE_AREA:
				//while(ProgramCounter.byte)
				//	emit8(0xff);
				if (ProgramCounter.val % data)
				{
					while(ProgramCounter.val % data)
					emit8(0xff);
				}
				break;

			case DATA_AREA:
				while(DataCounter.byte)
					emit8(0xff);
				if (DataCounter.val % data)
				{
					while(DataCounter.val % data)
					emit32(0xffffffff);
				}
				break;

			case BSS_AREA:
//				while(BSSCounter.byte)
//					emit8(0xff);
				if (BSSCounter.val % data)
				{
					while(BSSCounter.val % data) {
						emit32(0xffffffff);
					}
				}
				break;
		}
		DoingDc = false;
	}
示例#8
0
文件: codegen.cpp 项目: jnewing/MyVm
void parse_asmdirective(char *dir, char *str, int integer, float fnum)
{
    if (strcmp(dir, ".text") == 0) // deprecated
    {
        Warning("Deprecated assembler directive %s", dir);
    }
    else if (strcmp(dir, ".data") == 0) // deprecated
    {
        Warning("Deprecated assembler directive %s", dir);
    }
    else if (strcmp(dir, ".byte") == 0)
    {
        if (str)
        {
            Error("Unsupported data type for label");
        }

        emit8(integer);
    }
    else if (strcmp(dir, ".word") == 0)
    {
        if (str)
        {
            Error("Unsupported data type for label");
        }

        emit16(integer);
    }
    else if (strcmp(dir, ".dword") == 0)
    {
        if (str)
        {
            AddRelocEntry(str, codeptr);
            emit32(0);
        }
        else
        {
            emit32(integer);
        }
    }
    else if (strcmp(dir, ".float") == 0)
    {
        if (str)
        {
            Error("Unsupported data type for label");
        }

        emitfloat(fnum);
    }
    else if (strcmp(dir, ".string") == 0)
    {
        assert(str != 0);
        output_string(str);
    }
}
示例#9
0
文件: a_all.cpp 项目: BigEd/Cores
	int Assembler::out24(Opa *o)
	{
		emit8(o->oc&0xff);
		emit16(o->oc>>8);
		return (TRUE);
	}
示例#10
0
文件: a_all.cpp 项目: BigEd/Cores
	int Assembler::out8(Opa *o)
	{
		emit8(o->oc);
		return (TRUE);
	}
示例#11
0
文件: codegen.cpp 项目: jnewing/MyVm
void output_ins(char *instruction)
{
    OpcodeEntry *opc = LookupOpcodeByString(instruction);

    emit8(opc->OpCode);
}