double ResSolid(struct fe1d *p, matrix *guess, Elem1D *elem, double x, int f1, int f2) { double T = TINIT, C = 0, Ci, Ea, value; int i; basis *b; b = p->b; solution *s; s = CreateSolution(p->t, p->dt, guess); for(i=0; i<b->n; i++) { Ci = EvalSoln1D(p, CVAR, elem, s, valV(elem->points, i)); Ci = uscaleTemp(p->chardiff, Ci); C += C * b->phi[i](x); } Ea = EA(C, T); value = Ea * b->phi[f1](x)*b->phi[f2](x) / IMap1D(p, elem, x); free(s); return value; }
double ResDtSolid(struct fe1d *p, matrix *guess, Elem1D *elem, double x, int f1, int f2) { double T = TINIT, C = 0, Ci, Ea, E, lambda, sigma, term1; int i; basis *b; b = p->b; solution *s; s = CreateSolution(p->t, p->dt, guess); for(i=0; i<b->n; i++) { Ci = EvalSoln1D(p, CVAR, elem, s, valV(elem->points, i)); Ci = uscaleTemp(p->chardiff, Ci); C += Ci; } Ea += EA(C, T); E += E1(C, T); lambda += LAMBDA(C, T); sigma += STRESS(C, T); term1 = lambda*(Ea+E) * b->phi[f1](x)*b->phi[f2](x) / IMap1D(p, elem, x); free(s); return term1; }
void OCamlFGotoCodeGen::writeData() { if ( redFsm->anyToStateActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() ); TO_STATE_ACTIONS(); CLOSE_ARRAY() << "\n"; } if ( redFsm->anyFromStateActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() ); FROM_STATE_ACTIONS(); CLOSE_ARRAY() << "\n"; } if ( redFsm->anyEofActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() ); EOF_ACTIONS(); CLOSE_ARRAY() << "\n"; } STATE_IDS(); out << "exception Goto_again" << TOP_SEP(); }
void FGotoCodeGen::writeData() { if ( redFsm->anyToStateActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() ); TO_STATE_ACTIONS(); CLOSE_ARRAY() << L"\n"; } if ( redFsm->anyFromStateActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() ); FROM_STATE_ACTIONS(); CLOSE_ARRAY() << L"\n"; } if ( redFsm->anyEofActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() ); EOF_ACTIONS(); CLOSE_ARRAY() << L"\n"; } STATE_IDS(); }
int main (int argc, char ** argv) { int i, j; pid_t child; int status; int test; struct test_result r; cu_enabledebug("all"); EA((argc > 1),("Specify tests to run.")); for (i = 1; i < argc; i++) { if (strcmp(argv[i], "all") == 0) { for (j = 0; j < copper_tests_count; j++) { child = fork(); if (child > 0) { wait(&status); if (WIFEXITED(status)) { D(("Child exited with status %i", WEXITSTATUS(status))); if (WEXITSTATUS(status)) { return WEXITSTATUS(status); } } else if (WIFSIGNALED(status)) { D(("Child exited with signal %i", WTERMSIG(status) )); return WTERMSIG(status); } else { D(("Child exited with %i", status)); return status; } } else { r = (*tests[j])(); return (!r.pass); } } } else if (sscanf(argv[i], "%i", &test) && test < copper_tests_count) { D(("Trying test %s", argv[i])); cu_set_handlers(cu_testdriver_exit, cu_testdriver_vprintf); r = (*tests[test])(); cu_set_handlers(NULL, NULL); if (r.pass) { D(("Test passed: %s", r.name)); } else { D(("Test failed: %s", r.name)); D((" %s", r.text)); } return (!r.pass); } else { E(("Unknown test specification.")); return 1; } } return 1; }
struct ug_Corpus ug_createCorpus(char * path, ug_AttributeID nAttributes, size_t gramOrder) { struct ug_Corpus corpus = { .nAttributes = 0, .open = 0, .gramOrder = 0 }; ug_AttributeID ia; A(( ug_createDB(path, &corpus) == 0 )); ug_beginRW(&corpus); A(( ug_storeSettingsInDB(&corpus, nAttributes) == 0 )); A(( ug_setHsuGlass(&corpus, gramOrder) == gramOrder )); for (ia = 0; ia < nAttributes; ia++) { ug_initVocab(&corpus, ia); } ug_commit(&corpus); corpus.open = 1; return corpus; } TEST({ struct ug_Corpus c; char * tmpDir; char removeCmd[] = "rm -rvf ugtest-XXXXXX"; char path[] = "ugtest-XXXXXX/corpus"; tmpDir = &(removeCmd[8]); ASYS(( tmpDir == mkdtemp(tmpDir) )); memcpy(path, tmpDir, strlen(tmpDir)); c = ug_createCorpus(path, 1, 10); EA((c.open), ("Didn't open.")); A((c.nAttributes == 1)); A((c.gramOrder == 10)); ug_closeCorpus(&c); A((!c.open)); c = ug_openCorpus(path); A((c.nAttributes == 1)); A((c.gramOrder == 10)); ug_closeCorpus(&c); A((!c.open)); system(removeCmd); });
struct ug_Corpus ug_openCorpus(char * path) { struct ug_Corpus corpus = { .nAttributes = 0, .open = 0, .gramOrder = 0 }; A(( ug_openDB(path, &corpus) == 0 )); corpus.open = 1; ug_beginRO(&corpus); corpus.nAttributes = ug_readUInt64ByC(&corpus, "nAttributes"); ug_initHsuGlass(&corpus); ug_commit(&corpus); return corpus; } void ug_closeCorpus(struct ug_Corpus * corpus) { EA(( corpus->open ), ("DB already closed")); A(( ug_closeDB(corpus) == 0 )); corpus->open = 0; }
void garmin_usb_start(struct usb_device *dev, libusb_unit_data *lud) { int i; if (udev) return; udev = usb_open(dev); atexit(gusb_atexit_teardown); if (!udev) { fatal("usb_open failed: %s\n", usb_strerror()); } /* * Hrmph. No iManufacturer or iProduct headers.... */ #if 0 if (usb_set_configuration(udev, 1) < 0) { #if __linux__ char drvnm[128]; drvnm[0] = 0; /* * Most Linux distributions ship a slightly broken * kernel driver that bonds with the hardware. */ usb_get_driver_np(udev, 0, drvnm, sizeof(drvnm)-1); fatal("usb_set_configuration failed, probably because kernel driver '%s'\n is blocking our access to the USB device.\n" "For more information see http://www.gpsbabel.org/os/Linux_Hotplug.html\n", drvnm); #else fatal("usb_set_configuration failed: %s\n", usb_strerror()); #endif } #endif if (usb_claim_interface(udev, 0) < 0) { fatal("Claim interfaced failed: %s\n", usb_strerror()); } libusb_llops.max_tx_size = dev->descriptor.bMaxPacketSize0; /* * About 5% of the time on OS/X (Observed on 10.5.4 on Intel Imac * with Venture HC) we get a dev with a valid vendor ID, but no * associated configuration. I was unable to see a single instance * of this on a 276, a 60CS, a 60CSx, an SP310, or an Edge 305, leading * me to think this is some kind of bug in the Venture HC. * * Rather than crash, we at least print * a nastygram. Experiments with retrying various USB ops brought * no joy, so just call fatal and move on. */ if (!dev->config) { fatal("Found USB device with no configuration.\n"); } for (i = 0; i < dev->config->interface->altsetting->bNumEndpoints; i++) { struct usb_endpoint_descriptor * ep; ep = &dev->config->interface->altsetting->endpoint[i]; switch (ep->bmAttributes & USB_ENDPOINT_TYPE_MASK) { #define EA(x) x & USB_ENDPOINT_ADDRESS_MASK case USB_ENDPOINT_TYPE_BULK: if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) gusb_bulk_in_ep = EA(ep->bEndpointAddress); else gusb_bulk_out_ep = EA(ep->bEndpointAddress); break; case USB_ENDPOINT_TYPE_INTERRUPT: if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) gusb_intr_in_ep = EA(ep->bEndpointAddress); break; } } /* * Zero is the configuration endpoint, so if we made it through * that loop without non-zero values for all three, we're hosed. */ if (gusb_intr_in_ep && gusb_bulk_in_ep && gusb_bulk_out_ep) { lud->product_id = gusb_reset_toggles(); switch (lud->product_id) { // Search for "Venture HC" for more on this siliness.. // It's a case instead of an 'if' becuase I have a // feeling there are more affected models either // on the market or on the way. case 695: break; default: gusb_syncup(); } return; } fatal("Could not identify endpoints on USB device.\n" "Found endpoints Intr In 0x%x Bulk Out 0x%x Bulk In %0xx\n", gusb_intr_in_ep, gusb_bulk_out_ep, gusb_bulk_in_ep); }
void FFlatCodeGen::writeData() { if ( redFsm->anyConditions() ) { OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() ); COND_KEYS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpan), CSP() ); COND_KEY_SPANS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCond), C() ); CONDS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondIndexOffset), CO() ); COND_INDEX_OFFSET(); CLOSE_ARRAY() << L"\n"; } OPEN_ARRAY( WIDE_ALPH_TYPE(), K() ); KEYS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSpan), SP() ); KEY_SPANS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxFlatIndexOffset), IO() ); FLAT_INDEX_OFFSET(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() ); INDICIES(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() ); TRANS_TARGS(); CLOSE_ARRAY() << L"\n"; if ( redFsm->anyActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), TA() ); TRANS_ACTIONS(); CLOSE_ARRAY() << L"\n"; } if ( redFsm->anyToStateActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() ); TO_STATE_ACTIONS(); CLOSE_ARRAY() << L"\n"; } if ( redFsm->anyFromStateActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() ); FROM_STATE_ACTIONS(); CLOSE_ARRAY() << L"\n"; } if ( redFsm->anyEofActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), EA() ); EOF_ACTIONS(); CLOSE_ARRAY() << L"\n"; } if ( redFsm->anyEofTrans() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset+1), ET() ); EOF_TRANS(); CLOSE_ARRAY() << L"\n"; } STATE_IDS(); }
void FFlatCodeGen::writeExec() { testEofUsed = false; outLabelUsed = false; out << L" {\n" L" int _slen"; if ( redFsm->anyRegCurStateRef() ) out << L", _ps"; out << L";\n"; out << L" int _trans"; if ( redFsm->anyConditions() ) out << L", _cond"; out << L";\n"; out << L" " << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << L"_keys;\n" L" " << PTR_CONST() << ARRAY_TYPE(redFsm->maxIndex) << PTR_CONST_END() << POINTER() << L"_inds;\n"; if ( redFsm->anyConditions() ) { out << L" " << PTR_CONST() << ARRAY_TYPE(redFsm->maxCond) << PTR_CONST_END() << POINTER() << L"_conds;\n" L" " << WIDE_ALPH_TYPE() << L" _widec;\n"; } if ( !noEnd ) { testEofUsed = true; out << L" if ( " << P() << L" == " << PE() << L" )\n" L" goto _test_eof;\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << L" if ( " << vCS() << L" == " << redFsm->errState->id << L" )\n" L" goto _out;\n"; } out << L"_resume:\n"; if ( redFsm->anyFromStateActions() ) { out << L" switch ( " << FSA() << L"[" << vCS() << L"] ) {\n"; FROM_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << L" }\n" L"\n"; } if ( redFsm->anyConditions() ) COND_TRANSLATE(); LOCATE_TRANS(); if ( redFsm->anyEofTrans() ) out << L"_eof_trans:\n"; if ( redFsm->anyRegCurStateRef() ) out << L" _ps = " << vCS() << L";\n"; out << L" " << vCS() << L" = " << TT() << L"[_trans];\n\n"; if ( redFsm->anyRegActions() ) { out << L" if ( " << TA() << L"[_trans] == 0 )\n" L" goto _again;\n" L"\n" L" switch ( " << TA() << L"[_trans] ) {\n"; ACTION_SWITCH(); SWITCH_DEFAULT() << L" }\n" L"\n"; } if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || redFsm->anyActionCalls() || redFsm->anyActionRets() ) out << L"_again:\n"; if ( redFsm->anyToStateActions() ) { out << L" switch ( " << TSA() << L"[" << vCS() << L"] ) {\n"; TO_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << L" }\n" L"\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << L" if ( " << vCS() << L" == " << redFsm->errState->id << L" )\n" L" goto _out;\n"; } if ( !noEnd ) { out << L" if ( ++" << P() << L" != " << PE() << L" )\n" L" goto _resume;\n"; } else { out << L" " << P() << L" += 1;\n" L" goto _resume;\n"; } if ( testEofUsed ) out << L" _test_eof: {}\n"; if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) { out << L" if ( " << P() << L" == " << vEOF() << L" )\n" L" {\n"; if ( redFsm->anyEofTrans() ) { out << L" if ( " << ET() << L"[" << vCS() << L"] > 0 ) {\n" L" _trans = " << ET() << L"[" << vCS() << L"] - 1;\n" L" goto _eof_trans;\n" L" }\n"; } if ( redFsm->anyEofActions() ) { out << L" switch ( " << EA() << L"[" << vCS() << L"] ) {\n"; EOF_ACTION_SWITCH(); SWITCH_DEFAULT() << L" }\n"; } out << L" }\n" L"\n"; } if ( outLabelUsed ) out << L" _out: {}\n"; out << L" }\n"; }
void CSharpFlatCodeGen::writeData() { /* If there are any transtion functions then output the array. If there * are none, don't bother emitting an empty array that won't be used. */ if ( redFsm->anyActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActArrItem), A() ); ACTIONS_ARRAY(); CLOSE_ARRAY() << "\n"; } if ( redFsm->anyConditions() ) { OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() ); COND_KEYS(); CLOSE_ARRAY() << "\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpan), CSP() ); COND_KEY_SPANS(); CLOSE_ARRAY() << "\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCond), C() ); CONDS(); CLOSE_ARRAY() << "\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondIndexOffset), CO() ); COND_INDEX_OFFSET(); CLOSE_ARRAY() << "\n"; } OPEN_ARRAY( WIDE_ALPH_TYPE(), K() ); KEYS(); CLOSE_ARRAY() << "\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSpan), SP() ); KEY_SPANS(); CLOSE_ARRAY() << "\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxFlatIndexOffset), IO() ); FLAT_INDEX_OFFSET(); CLOSE_ARRAY() << "\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() ); INDICIES(); CLOSE_ARRAY() << "\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() ); TRANS_TARGS(); CLOSE_ARRAY() << "\n"; if ( redFsm->anyActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() ); TRANS_ACTIONS(); CLOSE_ARRAY() << "\n"; } if ( redFsm->anyToStateActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() ); TO_STATE_ACTIONS(); CLOSE_ARRAY() << "\n"; } if ( redFsm->anyFromStateActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() ); FROM_STATE_ACTIONS(); CLOSE_ARRAY() << "\n"; } if ( redFsm->anyEofActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() ); EOF_ACTIONS(); CLOSE_ARRAY() << "\n"; } if ( redFsm->anyEofTrans() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset+1), ET() ); EOF_TRANS(); CLOSE_ARRAY() << "\n"; } STATE_IDS(); }
void CSharpFlatCodeGen::writeExec() { testEofUsed = false; outLabelUsed = false; initVarTypes(); out << " {\n" " " << slenType << " _slen"; if ( redFsm->anyRegCurStateRef() ) out << ", _ps"; out << ";\n" " " << transType << " _trans"; if ( redFsm->anyConditions() ) out << ", _cond"; out << ";\n"; if ( redFsm->anyToStateActions() || redFsm->anyRegActions() || redFsm->anyFromStateActions() ) { out << " " << actsType << " _acts;\n" " " << nactsType << " _nacts;\n"; } out << " " << "int _keys;\n" " " << indsType << " _inds;\n"; /* " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n" " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxIndex) << POINTER() << "_inds;\n";*/ if ( redFsm->anyConditions() ) { out << " " << condsType << " _conds;\n" " " << WIDE_ALPH_TYPE() << " _widec;\n"; } out << "\n"; if ( !noEnd ) { testEofUsed = true; out << " if ( " << P() << " == " << PE() << " )\n" " goto _test_eof;\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << " if ( " << vCS() << " == " << redFsm->errState->id << " )\n" " goto _out;\n"; } out << "_resume:\n"; if ( redFsm->anyFromStateActions() ) { out << " _acts = " << FSA() << "[" << vCS() << "];\n" " _nacts = " << A() << "[_acts++];\n" " while ( _nacts-- > 0 ) {\n" " switch ( " << A() << "[_acts++] ) {\n"; FROM_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << " }\n" " }\n" "\n"; } if ( redFsm->anyConditions() ) COND_TRANSLATE(); LOCATE_TRANS(); if ( redFsm->anyEofTrans() ) out << "_eof_trans:\n"; if ( redFsm->anyRegCurStateRef() ) out << " _ps = " << vCS() << ";\n"; out << " " << vCS() << " = " << TT() << "[_trans];\n" "\n"; if ( redFsm->anyRegActions() ) { out << " if ( " << TA() << "[_trans] == 0 )\n" " goto _again;\n" "\n" " _acts = " << TA() << "[_trans];\n" " _nacts = " << A() << "[_acts++];\n" " while ( _nacts-- > 0 ) {\n" " switch ( " << A() << "[_acts++] )\n {\n"; ACTION_SWITCH(); SWITCH_DEFAULT() << " }\n" " }\n" "\n"; } if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || redFsm->anyActionCalls() || redFsm->anyActionRets() ) out << "_again:\n"; if ( redFsm->anyToStateActions() ) { out << " _acts = " << TSA() << "[" << vCS() << "];\n" " _nacts = " << A() << "[_acts++];\n" " while ( _nacts-- > 0 ) {\n" " switch ( " << A() << "[_acts++] ) {\n"; TO_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << " }\n" " }\n" "\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << " if ( " << vCS() << " == " << redFsm->errState->id << " )\n" " goto _out;\n"; } if ( !noEnd ) { out << " if ( ++" << P() << " != " << PE() << " )\n" " goto _resume;\n"; } else { out << " " << P() << " += 1;\n" " goto _resume;\n"; } if ( testEofUsed ) out << " _test_eof: {}\n"; if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) { out << " if ( " << P() << " == " << vEOF() << " )\n" " {\n"; if ( redFsm->anyEofTrans() ) { out << " if ( " << ET() << "[" << vCS() << "] > 0 ) {\n" " _trans = " << CAST(transType) << " (" << ET() << "[" << vCS() << "] - 1);\n" " goto _eof_trans;\n" " }\n"; } if ( redFsm->anyEofActions() ) { out << " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "__acts = " << EA() << "[" << vCS() << "];\n" " " << UINT() << " __nacts = " << CAST(UINT()) << " " << A() << "[__acts++];\n" " while ( __nacts-- > 0 ) {\n" " switch ( " << A() << "[__acts++] ) {\n"; EOF_ACTION_SWITCH(); SWITCH_DEFAULT() << " }\n" " }\n"; } out << " }\n" "\n"; } if ( outLabelUsed ) out << " _out: {}\n"; out << " }\n"; }
void TabCodeGen::writeData() { /* If there are any transtion functions then output the array. If there * are none, don't bother emitting an empty array that won't be used. */ if ( redFsm->anyActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActArrItem), A() ); ACTIONS_ARRAY(); CLOSE_ARRAY() << "\n"; } if ( redFsm->anyConditions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondOffset), CO() ); COND_OFFSETS(); CLOSE_ARRAY() << "\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondLen), CL() ); COND_LENS(); CLOSE_ARRAY() << "\n"; OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() ); COND_KEYS(); CLOSE_ARRAY() << "\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpaceId), C() ); COND_SPACES(); CLOSE_ARRAY() << "\n"; } OPEN_ARRAY( ARRAY_TYPE(redFsm->maxKeyOffset), KO() ); KEY_OFFSETS(); CLOSE_ARRAY() << "\n"; OPEN_ARRAY( WIDE_ALPH_TYPE(), K() ); KEYS(); CLOSE_ARRAY() << "\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSingleLen), SL() ); SINGLE_LENS(); CLOSE_ARRAY() << "\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxRangeLen), RL() ); RANGE_LENS(); CLOSE_ARRAY() << "\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset), IO() ); INDEX_OFFSETS(); CLOSE_ARRAY() << "\n"; if ( useIndicies ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() ); INDICIES(); CLOSE_ARRAY() << "\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() ); TRANS_TARGS_WI(); CLOSE_ARRAY() << "\n"; if ( redFsm->anyActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() ); TRANS_ACTIONS_WI(); CLOSE_ARRAY() << "\n"; } } else { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() ); TRANS_TARGS(); CLOSE_ARRAY() << "\n"; if ( redFsm->anyActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() ); TRANS_ACTIONS(); CLOSE_ARRAY() << "\n"; } } if ( redFsm->anyToStateActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() ); TO_STATE_ACTIONS(); CLOSE_ARRAY() << "\n"; } if ( redFsm->anyFromStateActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() ); FROM_STATE_ACTIONS(); CLOSE_ARRAY() << "\n"; } if ( redFsm->anyEofActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() ); EOF_ACTIONS(); CLOSE_ARRAY() << "\n"; } if ( redFsm->anyEofTrans() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset+1), ET() ); EOF_TRANS(); CLOSE_ARRAY() << "\n"; } STATE_IDS(); }
void CSharpTabCodeGen::writeExec() { testEofUsed = false; outLabelUsed = false; initVarTypes(); out << L" {\n" L" " << klenType << L" _klen"; if ( redFsm->anyRegCurStateRef() ) out << L", _ps"; out << L";\n" L" " << transType << L" _trans;\n"; if ( redFsm->anyConditions() ) out << L" " << WIDE_ALPH_TYPE() << L" _widec;\n"; if ( redFsm->anyToStateActions() || redFsm->anyRegActions() || redFsm->anyFromStateActions() ) { out << L" int _acts;\n" L" int _nacts;\n"; } out << L" " << keysType << L" _keys;\n" L"\n"; // L" " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << L"_keys;\n" if ( !noEnd ) { testEofUsed = true; out << L" if ( " << P() << L" == " << PE() << L" )\n" L" goto _test_eof;\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << L" if ( " << vCS() << L" == " << redFsm->errState->id << L" )\n" L" goto _out;\n"; } out << L"_resume:\n"; if ( redFsm->anyFromStateActions() ) { out << L" _acts = " << FSA() << L"[" + vCS() + L"]" << L";\n" L" _nacts = " << A() << L"[_acts++];\n" L" while ( _nacts-- > 0 ) {\n" L" switch ( " << A() << L"[_acts++] ) {\n"; FROM_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << L" }\n" L" }\n" L"\n"; } if ( redFsm->anyConditions() ) COND_TRANSLATE(); LOCATE_TRANS(); out << L"_match:\n"; if ( useIndicies ) out << L" _trans = " << CAST(transType) << I() << L"[_trans];\n"; if ( redFsm->anyEofTrans() ) out << L"_eof_trans:\n"; if ( redFsm->anyRegCurStateRef() ) out << L" _ps = " << vCS() << L";\n"; out << L" " << vCS() << L" = " << TT() << L"[_trans];\n" L"\n"; if ( redFsm->anyRegActions() ) { out << L" if ( " << TA() << L"[_trans] == 0 )\n" L" goto _again;\n" L"\n" L" _acts = " << TA() << L"[_trans]" << L";\n" L" _nacts = " << A() << L"[_acts++];\n" L" while ( _nacts-- > 0 )\n {\n" L" switch ( " << A() << L"[_acts++] )\n {\n"; ACTION_SWITCH(); SWITCH_DEFAULT() << L" }\n" L" }\n" L"\n"; } if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || redFsm->anyActionCalls() || redFsm->anyActionRets() ) out << L"_again:\n"; if ( redFsm->anyToStateActions() ) { out << L" _acts = " << TSA() << L"[" << vCS() << L"]" << L";\n" L" _nacts = " << A() << L"[_acts++];\n" L" while ( _nacts-- > 0 ) {\n" L" switch ( " << A() << L"[_acts++] ) {\n"; TO_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << L" }\n" L" }\n" L"\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << L" if ( " << vCS() << L" == " << redFsm->errState->id << L" )\n" L" goto _out;\n"; } if ( !noEnd ) { out << L" if ( ++" << P() << L" != " << PE() << L" )\n" L" goto _resume;\n"; } else { out << L" " << P() << L" += 1;\n" L" goto _resume;\n"; } if ( testEofUsed ) out << L" _test_eof: {}\n"; if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) { out << L" if ( " << P() << L" == " << vEOF() << L" )\n" L" {\n"; if ( redFsm->anyEofTrans() ) { out << L" if ( " << ET() << L"[" << vCS() << L"] > 0 ) {\n" L" _trans = " << CAST(transType) << L" (" << ET() << L"[" << vCS() << L"] - 1);\n" L" goto _eof_trans;\n" L" }\n"; } if ( redFsm->anyEofActions() ) { out << L" int __acts = " << EA() << L"[" << vCS() << L"]" << L";\n" L" int __nacts = " << A() << L"[__acts++];\n" L" while ( __nacts-- > 0 ) {\n" L" switch ( " << A() << L"[__acts++] ) {\n"; EOF_ACTION_SWITCH(); SWITCH_DEFAULT() << L" }\n" L" }\n"; } out << L" }\n" L"\n"; } if ( outLabelUsed ) out << L" _out: {}\n"; out << L" }\n"; }
/***************************************************************************** ** ** OptimizedStrassenMultiply ** ** For large matrices A, B, and C of size MatrixSize * MatrixSize this ** function performs the operation C = A x B efficiently. ** ** INPUT: ** C = (*C WRITE) Address of top left element of matrix C. ** A = (*A IS READ ONLY) Address of top left element of matrix A. ** B = (*B IS READ ONLY) Address of top left element of matrix B. ** MatrixSize = Size of matrices (for n*n matrix, MatrixSize = n) ** RowWidthA = Number of elements in memory between A[x,y] and A[x,y+1] ** RowWidthB = Number of elements in memory between B[x,y] and B[x,y+1] ** RowWidthC = Number of elements in memory between C[x,y] and C[x,y+1] ** ** OUTPUT: ** C = (*C WRITE) Matrix C contains A x B. (Initial value of *C undefined.) ** *****************************************************************************/ VOID_TASK_7(OptimizedStrassenMultiply, REAL *, C, REAL *, A, REAL *, B, unsigned, MatrixSize, unsigned, RowWidthC, unsigned, RowWidthA, unsigned, RowWidthB ) { unsigned QuadrantSize = MatrixSize >> 1; /* MatixSize / 2 */ unsigned QuadrantSizeInBytes = sizeof(REAL) * QuadrantSize * QuadrantSize + 32; unsigned Column, Row; /************************************************************************ ** For each matrix A, B, and C, we'll want pointers to each quandrant ** in the matrix. These quandrants will be addressed as follows: ** -- -- ** | A11 A12 | ** | | ** | A21 A22 | ** -- -- ************************************************************************/ REAL /* *A11, *B11, *C11, */ *A12, *B12, *C12, *A21, *B21, *C21, *A22, *B22, *C22; REAL *S1,*S2,*S3,*S4,*S5,*S6,*S7,*S8,*M2,*M5,*T1sMULT; #define T2sMULT C22 #define NumberOfVariables 11 PTR TempMatrixOffset = 0; PTR MatrixOffsetA = 0; PTR MatrixOffsetB = 0; char *Heap; void *StartHeap; /* Distance between the end of a matrix row and the start of the next row */ PTR RowIncrementA = ( RowWidthA - QuadrantSize ) << 3; PTR RowIncrementB = ( RowWidthB - QuadrantSize ) << 3; PTR RowIncrementC = ( RowWidthC - QuadrantSize ) << 3; if (MatrixSize <= SizeAtWhichDivideAndConquerIsMoreEfficient) { MultiplyByDivideAndConquer(C, A, B, MatrixSize, RowWidthC, RowWidthA, RowWidthB, 0); return; } /* Initialize quandrant matrices */ #define A11 A #define B11 B #define C11 C A12 = A11 + QuadrantSize; B12 = B11 + QuadrantSize; C12 = C11 + QuadrantSize; A21 = A + (RowWidthA * QuadrantSize); B21 = B + (RowWidthB * QuadrantSize); C21 = C + (RowWidthC * QuadrantSize); A22 = A21 + QuadrantSize; B22 = B21 + QuadrantSize; C22 = C21 + QuadrantSize; /* Allocate Heap Space Here */ StartHeap = Heap = malloc(QuadrantSizeInBytes * NumberOfVariables); /* ensure that heap is on cache boundary */ if ( ((PTR) Heap) & 31) Heap = (char*) ( ((PTR) Heap) + 32 - ( ((PTR) Heap) & 31) ); /* Distribute the heap space over the variables */ S1 = (REAL*) Heap; Heap += QuadrantSizeInBytes; S2 = (REAL*) Heap; Heap += QuadrantSizeInBytes; S3 = (REAL*) Heap; Heap += QuadrantSizeInBytes; S4 = (REAL*) Heap; Heap += QuadrantSizeInBytes; S5 = (REAL*) Heap; Heap += QuadrantSizeInBytes; S6 = (REAL*) Heap; Heap += QuadrantSizeInBytes; S7 = (REAL*) Heap; Heap += QuadrantSizeInBytes; S8 = (REAL*) Heap; Heap += QuadrantSizeInBytes; M2 = (REAL*) Heap; Heap += QuadrantSizeInBytes; M5 = (REAL*) Heap; Heap += QuadrantSizeInBytes; T1sMULT = (REAL*) Heap; Heap += QuadrantSizeInBytes; /*************************************************************************** ** Step through all columns row by row (vertically) ** (jumps in memory by RowWidth => bad locality) ** (but we want the best locality on the innermost loop) ***************************************************************************/ for (Row = 0; Row < QuadrantSize; Row++) { /************************************************************************* ** Step through each row horizontally (addressing elements in each column) ** (jumps linearly througn memory => good locality) *************************************************************************/ for (Column = 0; Column < QuadrantSize; Column++) { /*********************************************************** ** Within this loop, the following holds for MatrixOffset: ** MatrixOffset = (Row * RowWidth) + Column ** (note: that the unit of the offset is number of reals) ***********************************************************/ /* Element of Global Matrix, such as A, B, C */ #define E(Matrix) (* (REAL*) ( ((PTR) Matrix) + TempMatrixOffset ) ) #define EA(Matrix) (* (REAL*) ( ((PTR) Matrix) + MatrixOffsetA ) ) #define EB(Matrix) (* (REAL*) ( ((PTR) Matrix) + MatrixOffsetB ) ) /* FIXME - may pay to expand these out - got higher speed-ups below */ /* S4 = A12 - ( S2 = ( S1 = A21 + A22 ) - A11 ) */ E(S4) = EA(A12) - ( E(S2) = ( E(S1) = EA(A21) + EA(A22) ) - EA(A11) ); /* S8 = (S6 = B22 - ( S5 = B12 - B11 ) ) - B21 */ E(S8) = ( E(S6) = EB(B22) - ( E(S5) = EB(B12) - EB(B11) ) ) - EB(B21); /* S3 = A11 - A21 */ E(S3) = EA(A11) - EA(A21); /* S7 = B22 - B12 */ E(S7) = EB(B22) - EB(B12); TempMatrixOffset += sizeof(REAL); MatrixOffsetA += sizeof(REAL); MatrixOffsetB += sizeof(REAL); } /* end row loop*/ MatrixOffsetA += RowIncrementA; MatrixOffsetB += RowIncrementB; } /* end column loop */ /* M2 = A11 x B11 */ SPAWN(OptimizedStrassenMultiply, M2, A11, B11, QuadrantSize, QuadrantSize, RowWidthA, RowWidthB); /* M5 = S1 * S5 */ SPAWN(OptimizedStrassenMultiply, M5, S1, S5, QuadrantSize, QuadrantSize, QuadrantSize, QuadrantSize); /* Step 1 of T1 = S2 x S6 + M2 */ SPAWN(OptimizedStrassenMultiply, T1sMULT, S2, S6, QuadrantSize, QuadrantSize, QuadrantSize, QuadrantSize); /* Step 1 of T2 = T1 + S3 x S7 */ SPAWN(OptimizedStrassenMultiply, C22, S3, S7, QuadrantSize, RowWidthC /*FIXME*/, QuadrantSize, QuadrantSize); /* Step 1 of C11 = M2 + A12 * B21 */ SPAWN(OptimizedStrassenMultiply, C11, A12, B21, QuadrantSize, RowWidthC, RowWidthA, RowWidthB); /* Step 1 of C12 = S4 x B22 + T1 + M5 */ SPAWN(OptimizedStrassenMultiply, C12, S4, B22, QuadrantSize, RowWidthC, QuadrantSize, RowWidthB); /* Step 1 of C21 = T2 - A22 * S8 */ SPAWN(OptimizedStrassenMultiply, C21, A22, S8, QuadrantSize, RowWidthC, RowWidthA, QuadrantSize); /********************************************** ** Synchronization Point **********************************************/ SYNC(OptimizedStrassenMultiply); SYNC(OptimizedStrassenMultiply); SYNC(OptimizedStrassenMultiply); SYNC(OptimizedStrassenMultiply); SYNC(OptimizedStrassenMultiply); SYNC(OptimizedStrassenMultiply); SYNC(OptimizedStrassenMultiply); /*************************************************************************** ** Step through all columns row by row (vertically) ** (jumps in memory by RowWidth => bad locality) ** (but we want the best locality on the innermost loop) ***************************************************************************/ for (Row = 0; Row < QuadrantSize; Row++) { /************************************************************************* ** Step through each row horizontally (addressing elements in each column) ** (jumps linearly througn memory => good locality) *************************************************************************/ for (Column = 0; Column < QuadrantSize; Column += 4) { REAL LocalM5_0 = *(M5); REAL LocalM5_1 = *(M5+1); REAL LocalM5_2 = *(M5+2); REAL LocalM5_3 = *(M5+3); REAL LocalM2_0 = *(M2); REAL LocalM2_1 = *(M2+1); REAL LocalM2_2 = *(M2+2); REAL LocalM2_3 = *(M2+3); REAL T1_0 = *(T1sMULT) + LocalM2_0; REAL T1_1 = *(T1sMULT+1) + LocalM2_1; REAL T1_2 = *(T1sMULT+2) + LocalM2_2; REAL T1_3 = *(T1sMULT+3) + LocalM2_3; REAL T2_0 = *(C22) + T1_0; REAL T2_1 = *(C22+1) + T1_1; REAL T2_2 = *(C22+2) + T1_2; REAL T2_3 = *(C22+3) + T1_3; (*(C11)) += LocalM2_0; (*(C11+1)) += LocalM2_1; (*(C11+2)) += LocalM2_2; (*(C11+3)) += LocalM2_3; (*(C12)) += LocalM5_0 + T1_0; (*(C12+1)) += LocalM5_1 + T1_1; (*(C12+2)) += LocalM5_2 + T1_2; (*(C12+3)) += LocalM5_3 + T1_3; (*(C22)) = LocalM5_0 + T2_0; (*(C22+1)) = LocalM5_1 + T2_1; (*(C22+2)) = LocalM5_2 + T2_2; (*(C22+3)) = LocalM5_3 + T2_3; (*(C21 )) = (- *(C21 )) + T2_0; (*(C21+1)) = (- *(C21+1)) + T2_1; (*(C21+2)) = (- *(C21+2)) + T2_2; (*(C21+3)) = (- *(C21+3)) + T2_3; M5 += 4; M2 += 4; T1sMULT += 4; C11 += 4; C12 += 4; C21 += 4; C22 += 4; } C11 = (REAL*) ( ((PTR) C11 ) + RowIncrementC); C12 = (REAL*) ( ((PTR) C12 ) + RowIncrementC); C21 = (REAL*) ( ((PTR) C21 ) + RowIncrementC); C22 = (REAL*) ( ((PTR) C22 ) + RowIncrementC); } free(StartHeap); }
void OCamlFGotoCodeGen::writeExec() { testEofUsed = false; outLabelUsed = false; out << " begin\n"; if ( redFsm->anyRegCurStateRef() ) out << " let _ps = ref 0 in\n"; if ( redFsm->anyConditions() ) out << " let _widec : " << WIDE_ALPH_TYPE() << " = ref 0 in\n"; out << "\n"; out << "\tlet rec do_start () =\n"; if ( !noEnd ) { testEofUsed = true; out << " if " << P() << " = " << PE() << " then\n" " do_test_eof ()\n" "\telse\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << " if " << vCS() << " = " << redFsm->errState->id << " then\n" " do_out ()\n" "\telse\n"; } out << "\tdo_resume ()\n"; out << "and do_resume () =\n"; if ( redFsm->anyFromStateActions() ) { out << " begin match " << AT(FSA(),vCS()) << " with\n"; FROM_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << " end;\n" "\n"; } out << " begin match " << vCS() << " with\n"; STATE_GOTOS(); SWITCH_DEFAULT() << " end\n" "\n"; TRANSITIONS() << "\n"; if ( redFsm->anyRegActions() ) EXEC_ACTIONS() << "\n"; out << "\tand do_again () =\n"; if ( redFsm->anyToStateActions() ) { out << " begin match " << AT(TSA(), vCS()) << " with\n"; TO_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << " end;\n" "\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << " match " << vCS() << " with\n" << " | " << redFsm->errState->id << " -> do_out ()\n" " | _ ->\n"; } out << "\t" << P() << " <- " << P() << " + 1;\n"; if ( !noEnd ) { out << " if " << P() << " <> " << PE() << " then\n" " do_resume ()\n" "\telse do_test_eof ()\n"; } else { out << " do_resume ()\n"; } // if ( testEofUsed ) out << "and do_test_eof () =\n"; if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) { out << " if " << P() << " = " << vEOF() << " then\n" " begin\n"; if ( redFsm->anyEofTrans() ) { out << " match " << vCS() << " with\n"; for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) { if ( st->eofTrans != 0 ) out << " | " << st->id << " -> tr" << st->eofTrans->id << " ()\n"; } SWITCH_DEFAULT() << ";\n"; // fall through } if ( redFsm->anyEofActions() ) { out << " try match " << AT(EA(), vCS()) << " with\n"; EOF_ACTION_SWITCH(); SWITCH_DEFAULT() << " \n" " with Goto_again -> do_again () \n"; } out << " end\n" "\n"; } else out << "\t()\n"; if ( outLabelUsed ) out << "\tand do_out () = ()\n"; out << "\tin do_start ()\n"; out << " end;\n"; }
void FTabCodeGen::writeData() { if ( redFsm->anyConditions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondOffset), CO() ); COND_OFFSETS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondLen), CL() ); COND_LENS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() ); COND_KEYS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpaceId), C() ); COND_SPACES(); CLOSE_ARRAY() << L"\n"; } OPEN_ARRAY( ARRAY_TYPE(redFsm->maxKeyOffset), KO() ); KEY_OFFSETS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( WIDE_ALPH_TYPE(), K() ); KEYS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSingleLen), SL() ); SINGLE_LENS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxRangeLen), RL() ); RANGE_LENS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset), IO() ); INDEX_OFFSETS(); CLOSE_ARRAY() << L"\n"; if ( useIndicies ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() ); INDICIES(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() ); TRANS_TARGS_WI(); CLOSE_ARRAY() << L"\n"; if ( redFsm->anyActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), TA() ); TRANS_ACTIONS_WI(); CLOSE_ARRAY() << L"\n"; } } else { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() ); TRANS_TARGS(); CLOSE_ARRAY() << L"\n"; if ( redFsm->anyActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), TA() ); TRANS_ACTIONS(); CLOSE_ARRAY() << L"\n"; } } if ( redFsm->anyToStateActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() ); TO_STATE_ACTIONS(); CLOSE_ARRAY() << L"\n"; } if ( redFsm->anyFromStateActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() ); FROM_STATE_ACTIONS(); CLOSE_ARRAY() << L"\n"; } if ( redFsm->anyEofActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), EA() ); EOF_ACTIONS(); CLOSE_ARRAY() << L"\n"; } if ( redFsm->anyEofTrans() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset+1), ET() ); EOF_TRANS(); CLOSE_ARRAY() << L"\n"; } STATE_IDS(); }
void OCamlFFlatCodeGen::writeExec() { testEofUsed = false; outLabelUsed = false; initVarTypes(); out << L" begin\n"; // L" " << slenType << L" _slen"; // if ( redFsm->anyRegCurStateRef() ) // out << L", _ps"; // out << L";\n"; // out << L" " << transType << L" _trans"; // if ( redFsm->anyConditions() ) // out << L", _cond"; // out << L";\n"; // out << // L" " << L"int _keys;\n" // L" " << indsType << L" _inds;\n"; /* L" " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << L"_keys;\n" L" " << PTR_CONST() << ARRAY_TYPE(redFsm->maxIndex) << POINTER() << L"_inds;\n";*/ out << L" let state = { keys = 0; trans = 0; } in\n" L" let rec do_start () =\n"; // if ( redFsm->anyConditions() ) { // out << // L" " << condsType << L" _conds;\n" // L" " << WIDE_ALPH_TYPE() << L" _widec;\n"; // } if ( !noEnd ) { testEofUsed = true; out << L" if " << P() << L" = " << PE() << L" then\n" L" do_test_eof ()\n" L"\telse\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << L" if " << vCS() << L" = " << redFsm->errState->id << L" then\n" L" do_out ()\n" L"\telse\n"; } out << L"\tdo_resume ()\n"; out << L"and do_resume () =\n"; if ( redFsm->anyFromStateActions() ) { out << L" begin match " << AT( FSA(), vCS() ) << L" with\n"; FROM_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << L" end;\n" L"\n"; } if ( redFsm->anyConditions() ) COND_TRANSLATE(); out << L"\tbegin try\n"; LOCATE_TRANS(); out << L"\twith Goto_match -> () end;\n"; out << L"\tdo_eof_trans ()\n"; // if ( redFsm->anyEofTrans() ) out << L"and do_eof_trans () =\n"; if ( redFsm->anyRegCurStateRef() ) out << L" let ps = " << vCS() << L" in\n"; out << L" " << vCS() << L" <- " << AT( TT() ,L"state.trans" ) << L";\n" L"\n"; if ( redFsm->anyRegActions() ) { out << L" begin try if " << AT( TA() , L"state.trans" ) << L" = 0 then\n" L" raise Goto_again;\n" L"\n" L" match " << AT( TA(), L"state.trans" ) << L" with\n"; ACTION_SWITCH(); SWITCH_DEFAULT() << L" with Goto_again -> () end;\n" L"\n"; } out << L"\tdo_again ()\n"; // if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || // redFsm->anyActionCalls() || redFsm->anyActionRets() ) out << L"\tand do_again () =\n"; if ( redFsm->anyToStateActions() ) { out << L" begin match " << AT( TSA(), vCS() ) << L" with\n"; TO_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << L" end;\n" L"\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << L" match " << vCS() << L" with\n" L"\t| " << redFsm->errState->id << L" -> do_out ()\n" L"\t| _ ->\n"; } out << L"\t" << P() << L" <- " << P() << L" + 1;\n"; if ( !noEnd ) { out << L" if " << P() << L" <> " << PE() << L" then\n" L" do_resume ()\n" L"\telse do_test_eof ()\n"; } else { out << L" do_resume ()\n"; } // if ( testEofUsed ) out << L"and do_test_eof () =\n"; if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) { out << L" if " << P() << L" = " << vEOF() << L" then\n" L" begin try\n"; if ( redFsm->anyEofTrans() ) { out << L" if " << AT( ET(), vCS() ) << L" > 0 then\n" L" begin\n" L" state.trans <- " << CAST(transType) << L"(" << AT( ET(), vCS() ) << L" - 1);\n" L" raise Goto_eof_trans;\n" L" end;\n"; } if ( redFsm->anyEofActions() ) { out << L" begin match " << AT( EA(), vCS() ) << L" with\n"; EOF_ACTION_SWITCH(); SWITCH_DEFAULT() << L" end\n"; } out << L" with Goto_again -> do_again ()\n" L" | Goto_eof_trans -> do_eof_trans () end\n" L"\n"; } else { out << L"\t()\n"; } if ( outLabelUsed ) out << L" and do_out () = ()\n"; out << L"\tin do_start ()\n"; out << L" end;\n"; }
void OCamlFFlatCodeGen::writeData() { if ( redFsm->anyConditions() ) { OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() ); COND_KEYS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpan), CSP() ); COND_KEY_SPANS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCond), C() ); CONDS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondIndexOffset), CO() ); COND_INDEX_OFFSET(); CLOSE_ARRAY() << L"\n"; } OPEN_ARRAY( WIDE_ALPH_TYPE(), K() ); KEYS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSpan), SP() ); KEY_SPANS(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxFlatIndexOffset), IO() ); FLAT_INDEX_OFFSET(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() ); INDICIES(); CLOSE_ARRAY() << L"\n"; OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() ); TRANS_TARGS(); CLOSE_ARRAY() << L"\n"; if ( redFsm->anyActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), TA() ); TRANS_ACTIONS(); CLOSE_ARRAY() << L"\n"; } if ( redFsm->anyToStateActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() ); TO_STATE_ACTIONS(); CLOSE_ARRAY() << L"\n"; } if ( redFsm->anyFromStateActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() ); FROM_STATE_ACTIONS(); CLOSE_ARRAY() << L"\n"; } if ( redFsm->anyEofActions() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), EA() ); EOF_ACTIONS(); CLOSE_ARRAY() << L"\n"; } if ( redFsm->anyEofTrans() ) { OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset+1), ET() ); EOF_TRANS(); CLOSE_ARRAY() << L"\n"; } STATE_IDS(); out << L"type " << TYPE_STATE() << L" = { mutable keys : int; mutable trans : int; }" << TOP_SEP(); out << L"exception Goto_match" << TOP_SEP(); out << L"exception Goto_again" << TOP_SEP(); out << L"exception Goto_eof_trans" << TOP_SEP(); }
void TabCodeGen::writeExec() { testEofUsed = false; outLabelUsed = false; out << " {\n" " int _klen"; if ( redFsm->anyRegCurStateRef() ) out << ", _ps"; out << ";\n" " " << UINT() << " _trans;\n"; if ( redFsm->anyConditions() ) out << " " << WIDE_ALPH_TYPE() << " _widec;\n"; if ( redFsm->anyToStateActions() || redFsm->anyRegActions() || redFsm->anyFromStateActions() ) { out << " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << PTR_CONST_END() << POINTER() << "_acts;\n" " " << UINT() << " _nacts;\n"; } out << " " << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_keys;\n" "\n"; if ( !noEnd ) { testEofUsed = true; out << " if ( " << P() << " == " << PE() << " )\n" " goto _test_eof;\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << " if ( " << vCS() << " == " << redFsm->errState->id << " )\n" " goto _out;\n"; } out << "_resume:\n"; if ( redFsm->anyFromStateActions() ) { out << " _acts = " << ARR_OFF( A(), FSA() + "[" + vCS() + "]" ) << ";\n" " _nacts = " << CAST(UINT()) << " *_acts++;\n" " while ( _nacts-- > 0 ) {\n" " switch ( *_acts++ ) {\n"; FROM_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << " }\n" " }\n" "\n"; } if ( redFsm->anyConditions() ) COND_TRANSLATE(); LOCATE_TRANS(); out << "_match:\n"; if ( useIndicies ) out << " _trans = " << I() << "[_trans];\n"; if ( redFsm->anyEofTrans() ) out << "_eof_trans:\n"; if ( redFsm->anyRegCurStateRef() ) out << " _ps = " << vCS() << ";\n"; out << " " << vCS() << " = " << TT() << "[_trans];\n" "\n"; if ( redFsm->anyRegActions() ) { out << " if ( " << TA() << "[_trans] == 0 )\n" " goto _again;\n" "\n" " _acts = " << ARR_OFF( A(), TA() + "[_trans]" ) << ";\n" " _nacts = " << CAST(UINT()) << " *_acts++;\n" " while ( _nacts-- > 0 )\n {\n" " switch ( *_acts++ )\n {\n"; ACTION_SWITCH(); SWITCH_DEFAULT() << " }\n" " }\n" "\n"; } if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || redFsm->anyActionCalls() || redFsm->anyActionRets() ) out << "_again:\n"; if ( redFsm->anyToStateActions() ) { out << " _acts = " << ARR_OFF( A(), TSA() + "[" + vCS() + "]" ) << ";\n" " _nacts = " << CAST(UINT()) << " *_acts++;\n" " while ( _nacts-- > 0 ) {\n" " switch ( *_acts++ ) {\n"; TO_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << " }\n" " }\n" "\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << " if ( " << vCS() << " == " << redFsm->errState->id << " )\n" " goto _out;\n"; } if ( !noEnd ) { out << " if ( ++" << P() << " != " << PE() << " )\n" " goto _resume;\n"; } else { out << " " << P() << " += 1;\n" " goto _resume;\n"; } if ( testEofUsed ) out << " _test_eof: {}\n"; if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) { out << " if ( " << P() << " == " << vEOF() << " )\n" " {\n"; if ( redFsm->anyEofTrans() ) { out << " if ( " << ET() << "[" << vCS() << "] > 0 ) {\n" " _trans = " << ET() << "[" << vCS() << "] - 1;\n" " goto _eof_trans;\n" " }\n"; } if ( redFsm->anyEofActions() ) { out << " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << PTR_CONST_END() << POINTER() << "__acts = " << ARR_OFF( A(), EA() + "[" + vCS() + "]" ) << ";\n" " " << UINT() << " __nacts = " << CAST(UINT()) << " *__acts++;\n" " while ( __nacts-- > 0 ) {\n" " switch ( *__acts++ ) {\n"; EOF_ACTION_SWITCH(); SWITCH_DEFAULT() << " }\n" " }\n"; } out << " }\n" "\n"; } if ( outLabelUsed ) out << " _out: {}\n"; out << " }\n"; }
void EncodingEDSRSA(char *M_fname, char *nA_fname, char *eA_fname, char *dA_fname, char *nB_fname, char *eB_fname, char *dB_fname) { std::ifstream in(M_fname); int *M_hash = (int*)md5(&in), i; BigInt M(intToChar(M_hash[3])), NA(nA_fname, false), EA(eA_fname, false), DA(dA_fname, false); M *= BigInt("10000000000"); M += BigInt(intToChar(M_hash[2])); M *= BigInt("10000000000"); M += BigInt(intToChar(M_hash[1])); M *= BigInt("10000000000"); M += BigInt(intToChar(M_hash[0])); BigInt NB(nB_fname, false), EB(eB_fname, false), DB(dB_fname, false); BigInt Signature("1"), Code("1"), Encode("1"), CheckSign("1"); BigInt DegreeNet[RNet]; DegreeNet[0] = M; DegreeNet[0] %= NA; for(i = 1; i < RNet; i++) { DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1]; DegreeNet[i] %= NA; } BigInt degreeNum[RNet]; degreeNum[0] = BigInt("1"); for(int i = 1; i < RNet; i++) degreeNum[i] = degreeNum[i-1] * BigInt("2"); BigInt I("0"); for(int j = RNet-1; j >= 0;) { if(DA >= I + degreeNum[j]) { Signature *= DegreeNet[j]; Signature %= NA; I += degreeNum[j]; } else j--; } ////////////////////////////// DegreeNet[0] = Signature; DegreeNet[0] %= NB; for(i = 1; i < RNet; i++) { DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1]; DegreeNet[i] %= NB; } I = BigInt("0"); for(int j = RNet-1; j >= 0;) { if(EB >= I + degreeNum[j]) { Code *= DegreeNet[j]; Code %= NB; I += degreeNum[j]; } else j--; } ////////////////////////////// DegreeNet[0] = Code; DegreeNet[0] %= NB; for(i = 1; i < RNet; i++) { DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1]; DegreeNet[i] %= NB; } I = BigInt("0"); for(int j = RNet-1; j >= 0;) { if(DB >= I + degreeNum[j]) { Encode *= DegreeNet[j]; Encode %= NB; I += degreeNum[j]; } else j--; } ////////////////////////////// DegreeNet[0] = Encode; DegreeNet[0] %= NA; for(i = 1; i < RNet; i++) { DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1]; DegreeNet[i] %= NA; } I = BigInt("0"); for(int j = RNet - 1; j >= 0;) { if(EA >= I + degreeNum[j]) { CheckSign *= DegreeNet[j]; CheckSign %= NA; I += degreeNum[j]; } else j--; } ////////////////////////////// M.TextWrite("hash.txt"); Code.TextWrite("code.txt"); Encode.TextWrite("encode.txt"); CheckSign.TextWrite("checksign.txt"); if( M % NA == CheckSign) std::cout<<"OK\n"; else std::cout<<"NOT OK\n"; }
void FGotoCodeGen::writeExec() { testEofUsed = false; outLabelUsed = false; out << L" {\n"; if ( redFsm->anyRegCurStateRef() ) out << L" int _ps = 0;\n"; if ( redFsm->anyConditions() ) out << L" " << WIDE_ALPH_TYPE() << L" _widec;\n"; if ( !noEnd ) { testEofUsed = true; out << L" if ( " << P() << L" == " << PE() << L" )\n" L" goto _test_eof;\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << L" if ( " << vCS() << L" == " << redFsm->errState->id << L" )\n" L" goto _out;\n"; } out << L"_resume:\n"; if ( redFsm->anyFromStateActions() ) { out << L" switch ( " << FSA() << L"[" << vCS() << L"] ) {\n"; FROM_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << L" }\n" L"\n"; } out << L" switch ( " << vCS() << L" ) {\n"; STATE_GOTOS(); SWITCH_DEFAULT() << L" }\n" L"\n"; TRANSITIONS() << L"\n"; if ( redFsm->anyRegActions() ) EXEC_ACTIONS() << L"\n"; out << L"_again:\n"; if ( redFsm->anyToStateActions() ) { out << L" switch ( " << TSA() << L"[" << vCS() << L"] ) {\n"; TO_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << L" }\n" L"\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << L" if ( " << vCS() << L" == " << redFsm->errState->id << L" )\n" L" goto _out;\n"; } if ( !noEnd ) { out << L" if ( ++" << P() << L" != " << PE() << L" )\n" L" goto _resume;\n"; } else { out << L" " << P() << L" += 1;\n" L" goto _resume;\n"; } if ( testEofUsed ) out << L" _test_eof: {}\n"; if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) { out << L" if ( " << P() << L" == " << vEOF() << L" )\n" L" {\n"; if ( redFsm->anyEofTrans() ) { out << L" switch ( " << vCS() << L" ) {\n"; for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) { if ( st->eofTrans != 0 ) out << L" case " << st->id << L": goto tr" << st->eofTrans->id << L";\n"; } SWITCH_DEFAULT() << L" }\n"; } if ( redFsm->anyEofActions() ) { out << L" switch ( " << EA() << L"[" << vCS() << L"] ) {\n"; EOF_ACTION_SWITCH(); SWITCH_DEFAULT() << L" }\n"; } out << L" }\n" L"\n"; } if ( outLabelUsed ) out << L" _out: {}\n"; out << L" }\n"; }
void OCamlTabCodeGen::writeExec() { testEofUsed = false; outLabelUsed = false; initVarTypes(); out << " begin\n"; // " " << klenType << " _klen"; // if ( redFsm->anyRegCurStateRef() ) // out << ", _ps"; /* out << " " << transType << " _trans;\n"; if ( redFsm->anyConditions() ) out << " " << WIDE_ALPH_TYPE() << " _widec;\n"; if ( redFsm->anyToStateActions() || redFsm->anyRegActions() || redFsm->anyFromStateActions() ) { out << " int _acts;\n" " int _nacts;\n"; } out << " " << keysType << " _keys;\n" "\n"; // " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n" */ out << " let state = { keys = 0; trans = 0; acts = 0; nacts = 0; } in\n" " let rec do_start () =\n"; if ( !noEnd ) { testEofUsed = true; out << " if " << P() << " = " << PE() << " then\n" " do_test_eof ()\n" "\telse\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << " if " << vCS() << " = " << redFsm->errState->id << " then\n" " do_out ()\n" "\telse\n"; } out << "\tdo_resume ()\n"; out << "and do_resume () =\n"; if ( redFsm->anyFromStateActions() ) { out << " state.acts <- " << AT( FSA(), vCS() ) << ";\n" " state.nacts <- " << AT( A(), POST_INCR("state.acts") ) << ";\n" " while " << POST_DECR("state.nacts") << " > 0 do\n" " begin match " << AT( A(), POST_INCR("state.acts") ) << " with\n"; FROM_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << " end\n" " done;\n" "\n"; } if ( redFsm->anyConditions() ) COND_TRANSLATE(); out << "\tbegin try\n"; LOCATE_TRANS(); out << "\twith Goto_match -> () end;\n"; out << "\tdo_match ()\n"; out << "and do_match () =\n"; if ( useIndicies ) out << " state.trans <- " << CAST(transType) << AT( I(), "state.trans" ) << ";\n"; out << "\tdo_eof_trans ()\n"; // if ( redFsm->anyEofTrans() ) out << "and do_eof_trans () =\n"; if ( redFsm->anyRegCurStateRef() ) out << " let ps = " << vCS() << " in\n"; out << " " << vCS() << " <- " << AT( TT() ,"state.trans" ) << ";\n" "\n"; if ( redFsm->anyRegActions() ) { out << "\tbegin try\n" " match " << AT( TA(), "state.trans" ) << " with\n" "\t| 0 -> raise Goto_again\n" "\t| _ ->\n" " state.acts <- " << AT( TA(), "state.trans" ) << ";\n" " state.nacts <- " << AT( A(), POST_INCR("state.acts") ) << ";\n" " while " << POST_DECR("state.nacts") << " > 0 do\n" " begin match " << AT( A(), POST_INCR("state.acts") ) << " with\n"; ACTION_SWITCH(); SWITCH_DEFAULT() << " end;\n" " done\n" "\twith Goto_again -> () end;\n"; } out << "\tdo_again ()\n"; // if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || // redFsm->anyActionCalls() || redFsm->anyActionRets() ) out << "\tand do_again () =\n"; if ( redFsm->anyToStateActions() ) { out << " state.acts <- " << AT( TSA(), vCS() ) << ";\n" " state.nacts <- " << AT( A(), POST_INCR("state.acts") ) << ";\n" " while " << POST_DECR("state.nacts") << " > 0 do\n" " begin match " << AT( A(), POST_INCR("state.acts") ) << " with\n"; TO_STATE_ACTION_SWITCH(); SWITCH_DEFAULT() << " end\n" " done;\n" "\n"; } if ( redFsm->errState != 0 ) { outLabelUsed = true; out << " match " << vCS() << " with\n" "\t| " << redFsm->errState->id << " -> do_out ()\n" "\t| _ ->\n"; } out << "\t" << P() << " <- " << P() << " + 1;\n"; if ( !noEnd ) { out << " if " << P() << " <> " << PE() << " then\n" " do_resume ()\n" "\telse do_test_eof ()\n"; } else { out << " do_resume ()\n"; } // if ( testEofUsed ) out << "and do_test_eof () =\n"; if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) { out << " if " << P() << " = " << vEOF() << " then\n" " begin try\n"; if ( redFsm->anyEofTrans() ) { out << " if " << AT( ET(), vCS() ) << " > 0 then\n" " begin\n" " state.trans <- " << CAST(transType) << "(" << AT( ET(), vCS() ) << " - 1);\n" " raise Goto_eof_trans;\n" " end\n"; } if ( redFsm->anyEofActions() ) { out << " let __acts = ref " << AT( EA(), vCS() ) << " in\n" " let __nacts = ref " << AT( A(), "!__acts" ) << " in\n" " incr __acts;\n" " while !__nacts > 0 do\n" " decr __nacts;\n" " begin match " << AT( A(), POST_INCR("__acts.contents") ) << " with\n"; EOF_ACTION_SWITCH(); SWITCH_DEFAULT() << " end;\n" " done\n"; } out << " with Goto_again -> do_again ()\n" " | Goto_eof_trans -> do_eof_trans () end\n" "\n"; } else { out << "\t()\n"; } if ( outLabelUsed ) out << " and do_out () = ()\n"; out << "\tin do_start ()\n"; out << " end;\n"; }