Пример #1
0
void Disassemble(GlobalData* globalData, const std::vector<Bytecode>* buffer)
{
    static BytecodeMetaData bytecodeList[op_last];
    static bool initialized = false;
    if (!initialized)
    {
        #define INITBYTECODE(_opcode, _structure, _length) \
            bytecodeList[_opcode].name= #_opcode; \
            bytecodeList[_opcode].structure = _structure; \
            bytecodeList[_opcode].length = _length; \

        OPCODES(INITBYTECODE)
        #undef INITBYTECODE
        
        initialized = true;
    }
    for(unsigned i=0; i<buffer->size(); ++i)
    {
        assert(buffer->at(i).Code < op_last);
        BytecodeMetaData* meta = &bytecodeList[buffer->at(i).Code];
        printf("%d:\t%s", i, meta->name);
        
        const char* structure = meta->structure; 
        while(*structure)
        {
            i++;
            Bytecode byte = buffer->at(i);
            switch(*structure)
            {
                case 'r':
                    printf("\n\tregister %d", byte.RegisterNumber);
                break;
                case 's':
                    printf("\n\tconstant string index %d \"%s\"", byte.ConstantStringIndex, globalData->GetConstantString(byte.ConstantStringIndex).c_str());
                break;
                case 'i':
                    printf("\n\tconstant int %d", byte.ConstantInt);
                break;
                case 'f':
                    printf("\n\tconstant float index %d %lf", byte.ConstantFloatIndex, globalData->GetConstantFloat(byte.ConstantFloatIndex));
                break;
            }
            ++ structure;
        }
        printf("\n");
    }
}
Пример #2
0
  int in_assert;
  int block_depth;
  uint32_t function_num_exprs_offset;
  int assert_return_count;
  int assert_return_nan_count;
  int assert_trap_count;
  int invoke_count;
} Context;

extern const char* g_outfile;
extern int g_dump_module;
extern int g_verbose;

static const char* s_opcode_names[] = {
#define OPCODE(name, code) [code] = "OPCODE_" #name,
    OPCODES(OPCODE)
#undef OPCODE
};

static uint32_t log_two_u32(uint32_t x) {
  if (!x)
    return 0;
  return sizeof(unsigned int) * 8 - __builtin_clz(x - 1);
}

static WasmTypeV8 wasm_type_to_v8_type(WasmType type) {
  switch (type) {
    case WASM_TYPE_VOID:
      return WASM_TYPE_V8_VOID;
    case WASM_TYPE_I32:
      return WASM_TYPE_V8_I32;