MCPcopy Create free account
hub / github.com/Genivia/RE-flex / write_predictor

Method write_predictor

lib/pattern.cpp:4840–4961  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4838
4839#ifndef WITH_NO_CODEGEN
4840void Pattern::write_predictor(FILE *file) const
4841{
4842 const char *nl = "\"\n \"";
4843 ::fprintf(file, "// reflex::Pattern FSM C++ code or opcode constructor also takes a search pattern prediction table:\nextern const char reflex_pred_%s[] = {", opt_.n.empty() ? "FSM" : opt_.n.c_str());
4844 ::fprintf(file, "\n \"%02x%02x", static_cast<uint8_t>(len_), (static_cast<uint8_t>(min_ | (one_ << 4) | ((lbk_ > 0) << 5) | (bol_ << 6))));
4845 // save match characters chr_[0..len_-1]
4846 for (size_t i = 0; i < len_; ++i)
4847 ::fprintf(file, "%s%02x", ((i + 2) % 32) ? "" : nl, static_cast<uint8_t>(chr_[i]));
4848 int span = 0, k = 0;
4849 if (len_ == 0)
4850 {
4851 // save bit_[] parameters
4852 for (int i = 0; i < 256; ++i)
4853 ::fprintf(file, "%s%02x", (i % 32) ? "" : nl, static_cast<uint8_t>(~bit_[i]));
4854 if (min_ > 7)
4855 {
4856 // save tap_[] parameters uncompressed
4857 for (int i = 0; i < Const::BTAP; ++i)
4858 ::fprintf(file, "%s%02x", (i % 32) ? "" : nl, static_cast<uint8_t>(tap_[i]));
4859 }
4860 else
4861 {
4862 // save tap_[] parameters compressed
4863 for (int i = 0; i <= Const::BTAP; ++i)
4864 {
4865 int byte = i < Const::BTAP ? static_cast<uint8_t>(tap_[i]) : -1;
4866 if (byte != 0xff)
4867 {
4868 if (--span >= 0)
4869 {
4870 while (span >= 128)
4871 {
4872 ::fprintf(file, "%sff", (k++ % 32) ? "" : nl);
4873 span -= 128;
4874 }
4875 ::fprintf(file, "%s%02x", (k++ % 32) ? "" : nl, static_cast<uint8_t>(span | 128));
4876 }
4877 if (byte >= 0)
4878 ::fprintf(file, "%s%02x", (k++ % 32) ? "" : nl, byte & 0x7f);
4879 span = 0;
4880 }
4881 else
4882 {
4883 ++span;
4884 }
4885 }
4886 }
4887 }
4888 if (len_ == 0 || min_ > 0)
4889 {
4890 // save predict match array pma_[] parameters compressed using "free" bits to mark and count 0xff sequences
4891 span = 0;
4892 for (int i = 0; i <= Const::HASH; ++i)
4893 {
4894 int hi_byte = i < Const::HASH ? static_cast<uint8_t>(pma_[i] >> 8) : -1;
4895 if (hi_byte != 0xff)
4896 {
4897 if (--span >= 0)

Callers

nothing calls this directly

Calls 1

emptyMethod · 0.45

Tested by

no test coverage detected