/** * Initialize the buffer event workspace. * @param setup :: Information on the data to be sent. */ void ISISLiveEventDataListener::initEventBuffer( const TCPStreamEventDataSetup &setup) { // Create an event workspace for the output auto workspace = API::WorkspaceFactory::Instance().create( "EventWorkspace", m_numberOfSpectra, 2, 1); m_eventBuffer.resize(m_numberOfPeriods); // save this workspace as the event buffer m_eventBuffer[0] = boost::dynamic_pointer_cast<DataObjects::EventWorkspace>(workspace); if (!m_eventBuffer[0]) { throw std::runtime_error("Failed to create an event workspace"); } // Set the units m_eventBuffer[0]->getAxis(0)->unit() = Kernel::UnitFactory::Instance().create("TOF"); m_eventBuffer[0]->setYUnit("Counts"); // Set the spectra-detector maping loadSpectraMap(); // Load the instrument std::string instrName(setup.head_setup.inst_name); loadInstrument(instrName); // Set the run number m_runNumber = setup.head_setup.run_number; std::string run_num = boost::lexical_cast<std::string>(m_runNumber); m_eventBuffer[0]->mutableRun().addLogData( new Mantid::Kernel::PropertyWithValue<std::string>(RUN_NUMBER_PROPERTY, run_num)); // Add the proton charge property m_eventBuffer[0]->mutableRun().addLogData( new Mantid::Kernel::TimeSeriesProperty<double>(PROTON_CHARGE_PROPERTY)); if (m_numberOfPeriods > 1) { for (size_t i = 1; i < static_cast<size_t>(m_numberOfPeriods); ++i) { // create an event workspace for each period m_eventBuffer[i] = boost::dynamic_pointer_cast<DataObjects::EventWorkspace>( API::WorkspaceFactory::Instance().create( "EventWorkspace", m_eventBuffer[0]->getNumberHistograms(), 2, 1)); // Copy geometry over. API::WorkspaceFactory::Instance().initializeFromParent( m_eventBuffer[0], m_eventBuffer[i], false); } } }
void testReplacement(const string& input, const string& expected, InstrCode initial, InstrCode replacement, InstrCode next1 = InstrCodeCount, InstrCode next2 = InstrCodeCount) { Stack<Value> result; Stack<Env*> globals; bool ok = CompileModule(input, globals, result); testTrue(ok); Stack<Block*> block(result.as<CodeObject>()->block()); InstrThunk* instrp = block->findInstr(Instr_Lambda); assert(instrp); Instr* instr = instrp->data; assert(instr->code() == Instr_Lambda); LambdaInstr* lambda = static_cast<LambdaInstr*>(instr); instrp = lambda->block()->findInstr(initial); assert(instrp); ok = interp->exec(block, result); if (!ok) cerr << "Error: " << result.asObject()->as<Exception>()->message() << endl; testTrue(ok); testEqual(repr(result.get()), expected); instr = instrp->data; testEqual(instrName(instr->code()), instrName(replacement)); if (next1 < InstrCodeCount) { instr = getNextInstr(instr); assert(instr); testEqual(instrName(instr->code()), instrName(next1)); if (next2 < InstrCodeCount) { instr = getNextInstr(instr); assert(instr); testEqual(instrName(instr->code()), instrName(next2)); } } }
// generate code for a captured BB void generate(Rewriter* r, CBB* cbb) { uint8_t* buf; uint64_t buf0; int used, i, usedTotal; if (cbb == 0) return; if (r->cs == 0) return; if (r->showEmuSteps) printf("Generating code for BB %s (%d instructions)\n", cbb_prettyName(cbb), cbb->count); usedTotal = 0; buf0 = (uint64_t) reserveCodeStorage(r->cs, 0); // remember start address for(i = 0; i < cbb->count; i++) { Instr* instr = cbb->instr + i; buf = reserveCodeStorage(r->cs, 15); if (instr->ptLen > 0) { used = genPassThrough(buf, instr); } else { switch(instr->type) { case IT_ADD: used = genAdd(buf, &(instr->src), &(instr->dst)); break; case IT_CLTQ: used = genCltq(buf, instr->vtype); break; case IT_CQTO: used = genCqto(buf, instr->vtype); break; case IT_CMP: used = genCmp(buf, &(instr->src), &(instr->dst)); break; case IT_DEC: used = genDec(buf, &(instr->dst)); break; case IT_IMUL: used = genIMul(buf, &(instr->src), &(instr->dst)); break; case IT_IDIV1: used = genIDiv1(buf, &(instr->dst)); break; case IT_INC: used = genInc(buf, &(instr->dst)); break; case IT_XOR: used = genXor(buf, &(instr->src), &(instr->dst)); break; case IT_OR: used = genOr(buf, &(instr->src), &(instr->dst)); break; case IT_AND: used = genAnd(buf, &(instr->src), &(instr->dst)); break; case IT_SHL: used = genShl(buf, &(instr->src), &(instr->dst)); break; case IT_SHR: used = genShr(buf, &(instr->src), &(instr->dst)); break; case IT_SAR: used = genSar(buf, &(instr->src), &(instr->dst)); break; case IT_LEA: used = genLea(buf, &(instr->src), &(instr->dst)); break; case IT_MOV: case IT_MOVSX: // converting move used = genMov(buf, &(instr->src), &(instr->dst)); break; case IT_CMOVO: case IT_CMOVNO: case IT_CMOVC: case IT_CMOVNC: case IT_CMOVZ: case IT_CMOVNZ: case IT_CMOVBE: case IT_CMOVA: case IT_CMOVS: case IT_CMOVNS: case IT_CMOVP: case IT_CMOVNP: case IT_CMOVL: case IT_CMOVGE: case IT_CMOVLE: case IT_CMOVG: used = genCMov(buf, instr->type, &(instr->src), &(instr->dst)); break; case IT_POP: used = genPop(buf, &(instr->dst)); break; case IT_PUSH: used = genPush(buf, &(instr->dst)); break; case IT_RET: used = genRet(buf); break; case IT_SUB: used = genSub(buf, &(instr->src), &(instr->dst)); break; case IT_TEST: used = genTest(buf, &(instr->src), &(instr->dst)); break; case IT_HINT_CALL: case IT_HINT_RET: used = 0; break; default: assert(0); } } assert(used < 15); instr->addr = (uint64_t) buf; instr->len = used; usedTotal += used; if (r->showEmuSteps) { printf(" I%2d : %-32s", i, instr2string(instr, 1, 0)); printf(" (%s)+%lx %s\n", cbb_prettyName(cbb), instr->addr - buf0, bytes2string(instr, 0, used)); } useCodeStorage(r->cs, used); } if (r->showEmuSteps) { if (instrIsJcc(cbb->endType)) { assert(cbb->nextBranch != 0); assert(cbb->nextFallThrough != 0); printf(" I%2d : %s (%s),", i, instrName(cbb->endType, 0), cbb_prettyName(cbb->nextBranch)); printf(" fall-through to (%s)\n", cbb_prettyName(cbb->nextFallThrough)); } } // add padding space after generated code for jump instruction buf = useCodeStorage(r->cs, 10); cbb->size = usedTotal; // start address of generated code. // if CBB had no instruction, this points to the padding buffer cbb->addr1 = (cbb->count == 0) ? ((uint64_t)buf) : cbb->instr[0].addr; }
char* instr2string(Instr* instr, int align, FunctionConfig* fc) { static char buf[100]; const char* n; int oc = 0, off = 0; n = instrName(instr->type, &oc); if (align) off += sprintf(buf, "%-7s", n); else off += sprintf(buf, "%s", n); // print value type if needed bool typeVisible = false; ValType vt = instr->vtype; // do operands show type? if (instr->form == OF_1) { if (opTypeVisible(&(instr->dst))) typeVisible = true; } if (instr->form == OF_2) { if (opTypeVisible(&(instr->dst))) typeVisible = true; if (opTypeVisible(&(instr->src))) typeVisible = true; // special case: conversions (MOVSX/MOVZX) // if source type not visible, make it so if (((instr->type == IT_MOVSX) || (instr->type == IT_MOVZX)) && !opTypeVisible(&(instr->src))) { typeVisible = false; vt = opValType(&(instr->src)); } } if (instr->form == OF_3) { if (opTypeVisible(&(instr->dst))) typeVisible = true; if (opTypeVisible(&(instr->src))) typeVisible = true; if (opTypeVisible(&(instr->src2))) typeVisible = true; } // is type implicitly known via instruction name? if (instr->vtype == VT_Implicit) typeVisible = true; if (vt == VT_None) { if ((instr->form >= OF_1) && (instr->form <= OF_3)) vt = opValType(&(instr->dst)); } if (typeVisible) vt = VT_None; // suppress type as already shown if (vt != VT_None) { char vtc = ' '; switch(vt) { case VT_8: vtc = 'b'; break; case VT_16: vtc = 'w'; break; case VT_32: vtc = 'l'; break; case VT_64: vtc = 'q'; break; case VT_Implicit: break; default: assert(0); } if (vtc != ' ') { int nlen = strlen(n); if (buf[nlen] == ' ') buf[nlen] = vtc; else { buf[nlen] = vtc; buf[nlen+1] = 0; off++; } } } switch(instr->form) { case OF_0: assert(instr->dst.type == OT_None); assert(instr->src.type == OT_None); assert(instr->src2.type == OT_None); break; case OF_1: assert(instr->dst.type != OT_None); assert(instr->src.type == OT_None); assert(instr->src2.type == OT_None); off += sprintf(buf+off, " %s", op2string(&(instr->dst), instr->vtype, fc)); break; case OF_2: assert(instr->dst.type != OT_None); assert(instr->src.type != OT_None); assert(instr->src2.type == OT_None); off += sprintf(buf+off, " %s", op2string(&(instr->src), instr->vtype, fc)); off += sprintf(buf+off, ",%s", op2string(&(instr->dst), instr->vtype, fc)); break; case OF_3: assert(instr->dst.type != OT_None); assert(instr->src.type != OT_None); assert(instr->src2.type != OT_None); off += sprintf(buf+off, " %s", op2string(&(instr->src2), instr->vtype, fc)); off += sprintf(buf+off, ",%s", op2string(&(instr->src), instr->vtype, fc)); off += sprintf(buf+off, ",%s", op2string(&(instr->dst), instr->vtype, fc)); break; default: assert(0); } return buf; }