void bc_disasm(PycRef<PycCode> code, PycModule* mod, int indent) { PycBuffer source(code->code()->value(), code->code()->length()); int opcode, operand; int pos = 0; while (!source.atEof()) { for (int i=0; i<indent; i++) fprintf(pyc_output, " "); fprintf(pyc_output, "[%7X] ", pos); // Current bytecode position bc_next(source, mod, opcode, operand, pos); fprintf(pyc_output, "%-24s", Pyc::OpcodeName(opcode)); if (opcode >= Pyc::PYC_HAVE_ARG) { if (Pyc::IsConstArg(opcode)) { fprintf(pyc_output, "%d: ", operand); print_const(code->getConst(operand), mod); } else if (Pyc::IsNameArg(opcode)) { fprintf(pyc_output, "%d: %s", operand, code->getName(operand)->value()); } else if (Pyc::IsVarNameArg(opcode)) { fprintf(pyc_output, "%d: %s", operand, code->getVarName(operand)->value()); } else if (Pyc::IsCellArg(opcode)) { fprintf(pyc_output, "%d: ", operand); print_const(code->getCellVar(operand), mod); } else if (Pyc::IsJumpOffsetArg(opcode)) { fprintf(pyc_output, "%d (to %d)", operand, pos+operand); } else { fprintf(pyc_output, "%d", operand); } } fprintf(pyc_output, "\n"); } }
bc_error_t boolchain_init( bc_t *p_boolchain, const bool *p_buffer, uint8_t p_buffer_size, bc_read_t p_read_function, bc_write_t p_write_function) { // Initialize the structure if (!p_buffer) return BOOLCHAIN_NULL_BUFFER; p_boolchain->size = p_buffer_size; p_boolchain->buffer = (bool *)p_buffer; p_boolchain->writer = p_write_function; p_boolchain->reader = p_read_function; p_boolchain->count = 1; // Initialize the needed signals to a known state SET_SHIFT(p_boolchain); // Find how many there are in the chain by zeroing everything, writing a 1, and // seeing how many pulses it takes to get it back. zero_bc(p_boolchain); p_boolchain->writer(BOOLSIG_OUT, true); while(!bc_next(p_boolchain)) { p_boolchain->writer(BOOLSIG_OUT, false); p_boolchain->count++; if (p_boolchain->count > p_buffer_size) return BOOLCHAIN_TOO_MANY_NODES; } return BOOLCHAIN_OK; }
void boolchain_capture(bc_t *p_boolchain) { uint8_t i; SET_LOAD(p_boolchain); PULSE_CLOCK(p_boolchain); SET_SHIFT(p_boolchain); for(i = 0; i < p_boolchain->count; i++) p_boolchain->buffer[p_boolchain->count - 1 - i] = bc_next(p_boolchain); }
void dump_program( struct ajj* a , const char* src , const struct program* prg , struct ajj_io* output ) { size_t i = 0; int a1,a2; int cnt = 0; dump_program_ctable(a,prg,output); ajj_io_printf(output,"Code=======================================\n\n"); while(1) { int sref = prg->spos[i]; int c1 = bc_next(prg,&i); instructions instr = bc_instr(c1); if( instr == VM_HALT ) break; switch(instr) { VM_INSTRUCTIONS(DO) default: UNREACHABLE(); return; } ++cnt; } }