<commit_before>#include "binary.h"
#include "fake.h"

const char * OpCodeStr(int opcode)
{
    switch (opcode)
    {
#define OPCODE_DEF(op)\
    case OPCODE_##op:\
        return #op;
        
    OPCODE_DEF(ASSIGN)

    OPCODE_DEF(PLUS)
    OPCODE_DEF(MINUS)
    OPCODE_DEF(MULTIPLY)
	OPCODE_DEF(DIVIDE)
	OPCODE_DEF(DIVIDE_MOD)

    OPCODE_DEF(PLUS_ASSIGN)
    OPCODE_DEF(MINUS_ASSIGN)
    OPCODE_DEF(MULTIPLY_ASSIGN)
	OPCODE_DEF(DIVIDE_ASSIGN)
	OPCODE_DEF(DIVIDE_MOD_ASSIGN)

	OPCODE_DEF(RETURN)
	
	OPCODE_DEF(JNE)
	OPCODE_DEF(JMP)
	
    OPCODE_DEF(AND)
    OPCODE_DEF(OR)
    OPCODE_DEF(LESS)
	OPCODE_DEF(MORE)
	OPCODE_DEF(EQUAL)
	OPCODE_DEF(MOREEQUAL)
	OPCODE_DEF(LESSEQUAL)
	OPCODE_DEF(NOTEQUAL)
	
	OPCODE_DEF(CALL)
	
#undef OPCODE_DEF
    }
    return "unknow";
}

String func_binary::dump() const
{
    String ret;

    // 
    ret += "\n[";
    ret += m_name;
    ret += "]\n";

    // ջ
    ret += "\tmaxstack:\t";
    ret += fkitoa(m_maxstack);
    ret += "\n\n";
    
    // 
    ret += "\t////// const define ";
    ret += fkitoa(m_const_list_num);
    ret += " //////\n";
    for (int i = 0; i < (int)m_const_list_num; i++)
    {  
        ret += "\t[";
        ret += fkitoa(i);
        ret += "]\t";
        switch (m_const_list[i].type)
        {
        case variant::REAL:
            ret += "REAL";
            break;
        case variant::STRING:
            ret += "STRING";
            break;
        case variant::POINTER:
            ret += "POINTER";
            break;
        default:
            ret += "unknow";
            break;
        }
        ret += "\t";
        ret += vartostring(&m_const_list[i]);
        ret += "\n";
    }
    
    ret += "\n\t////// byte code ";
    ret += fkitoa(m_size);
    ret += " //////\n";
    // ֽ
    for (int i = 0; i < (int)m_size; i++)
    {    
        command cmd = m_buff[i];
        int type = COMMAND_TYPE(cmd);
        int code = COMMAND_CODE(cmd);
        ret += "\t[";
        ret += fkitoa(i);
        ret += "]\t";
        ret += fkxtoa(cmd);
        ret += "\t";
        switch (type)
        {
        case COMMAND_OPCODE:
            {
                ret += "[";
                ret += OpCodeStr(code);
                ret += "]\t";
            }
            break;
        case COMMAND_ADDR:
            {
                ret += "[ ADDR ]\t";
                int addrtype = HIINT16(code);
                int pos = LOINT16(code);
                switch (addrtype)
                {
                case ADDR_STACK:
                    ret += "STACK";
                    break;
                case ADDR_CONST:
                    ret += "CONST";
                    break;
                default:
                    ret += "unknow ";
                    ret += fkitoa(addrtype);
                }
                ret += "\t";
                ret += fkitoa(pos);
            }
            break;
        case COMMAND_POS:
            {
                ret += "[ POS  ]\t";
                ret += fkitoa(code);
            }
            break;
        default:
            {
                ret += "[unknow]\t";
            }
            break;
        }
        ret += "\n";
    }
    ret += "\n";
    return ret;
}

String binary::dump() const
{
    String ret;
    for (const stringhashmap<func_binary>::ele * p = m_shh.first(); p != 0; p = m_shh.next())
    {
        const func_binary & bin = p->t;
        ret += bin.dump();
    }
    return ret;
}
    
void binary::move()
{
    for (const stringhashmap<func_binary>::ele * p = m_fk->bbin.m_shh.first(); p != 0; p = m_fk->bbin.m_shh.next())
    {
        const func_binary & bin = p->t;<commit_msg>asfasf<commit_after>#include "binary.h"
#include "fake.h"

const char * OpCodeStr(int opcode)
{
    switch (opcode)
    {
#define OPCODE_DEF(op)\
    case OPCODE_##op:\
        return #op;
        
    OPCODE_DEF(ASSIGN)

    OPCODE_DEF(PLUS)
    OPCODE_DEF(MINUS)
    OPCODE_DEF(MULTIPLY)
	OPCODE_DEF(DIVIDE)
	OPCODE_DEF(DIVIDE_MOD)

    OPCODE_DEF(PLUS_ASSIGN)
    OPCODE_DEF(MINUS_ASSIGN)
    OPCODE_DEF(MULTIPLY_ASSIGN)
	OPCODE_DEF(DIVIDE_ASSIGN)
	OPCODE_DEF(DIVIDE_MOD_ASSIGN)

	OPCODE_DEF(RETURN)
	
	OPCODE_DEF(JNE)
	OPCODE_DEF(JMP)
	
    OPCODE_DEF(AND)
    OPCODE_DEF(OR)
    OPCODE_DEF(LESS)
	OPCODE_DEF(MORE)
	OPCODE_DEF(EQUAL)
	OPCODE_DEF(MOREEQUAL)
	OPCODE_DEF(LESSEQUAL)
	OPCODE_DEF(NOTEQUAL)
	
	OPCODE_DEF(CALL)
	
#undef OPCODE_DEF
    }
    return "unknow";
}

String func_binary::dump() const
{
    String ret;

    // 
    ret += "\n[";
    ret += m_name;
    ret += "]\n";

    // ջ
    ret += "\tmaxstack:\t";
    ret += fkitoa(m_maxstack);
    ret += "\n\n";
    
    // 
    ret += "\t////// const define ";
    ret += fkitoa(m_const_list_num);
    ret += " //////\n";
    for (int i = 0; i < (int)m_const_list_num; i++)
    {  
        ret += "\t[";
        ret += fkitoa(i);
        ret += "]\t";
        switch (m_const_list[i].type)
        {
        case variant::REAL:
            ret += "REAL";
            break;
        case variant::STRING:
            ret += "STRING";
            break;
        case variant::POINTER:
            ret += "POINTER";
            break;
        default:
            ret += "unknow";
            break;
        }
        ret += "\t";
        ret += vartostring(&m_const_list[i]);
        ret += "\n";
    }
    
    ret += "\n\t////// byte code ";
    ret += fkitoa(m_size);
    ret += " //////\n";
    // ֽ
    for (int i = 0; i < (int)m_size; i++)
    {    
        command cmd = m_buff[i];
        int type = COMMAND_TYPE(cmd);
        int code = COMMAND_CODE(cmd);
        ret += "\t[";
        ret += fkitoa(i);
        ret += "]\t";
        ret += fkxtoa(cmd);
        ret += "\t";
        switch (type)
        {
        case COMMAND_OPCODE:
            {
                ret += "[";
                ret += OpCodeStr(code);
                ret += "]\t";
            }
            break;
        case COMMAND_ADDR:
            {
                ret += "[ ADDR ]\t";
                int addrtype = HIINT16(code);
                int pos = LOINT16(code);
                switch (addrtype)
                {
                case ADDR_STACK:
                    ret += "STACK";
                    break;
                case ADDR_CONST:
                    ret += "CONST";
                    break;
                default:
                    ret += "unknow ";
                    ret += fkitoa(addrtype);
                }
                ret += "\t";
                ret += fkitoa(pos);
            }
            break;
        case COMMAND_POS:
            {
                ret += "[ POS  ]\t";
                ret += fkitoa(code);
            }
            break;
        default:
            {
                ret += "[unknow]\t";
            }
            break;
        }
        ret += "\n";
    }
    ret += "\n";
    return ret;
}

String binary::dump() const
{
    String ret;
    for (const stringhashmap<func_binary>::ele * p = m_shh.first(); p != 0; p = m_shh.next())
    {
        const func_binary & bin = p->t;
        ret += bin.dump();
    }
    return ret;
}
    
void binary::move()
{
	if (m_fk->bbin.m_shh.empty())
	{
		return;
	}

    for (const stringhashmap<func_binary>::ele * p = m_fk->bbin.m_shh.first(); p != 0; p = m_fk->bbin.m_shh.next())
    {
        const func_binary & bin = p->t;
{'fraction_non_alphanumeric': 0.14948805460750852, 'fraction_numerical': 0.0021843003412969283, 'mean_word_length': 1.3264528421721182, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3657299', 'n_tokens_mistral': 2656, 'n_tokens_neox': 2541, 'n_words': 486}