23 template <
typename cunit_t,
typename key_t>
55 template <
typename cunit_t,
typename key_t>
65 size = size + cover_one<cunit_t, key_t> (input, keys, prefix);
70 for (arcs_t::iterator i =
arcs.begin ();
73 path_t new_prefix = prefix;
74 new_prefix.
extend (i->first->rule, i->first->ctx, &i->second);
75 i->first->cover<cunit_t, key_t> (new_prefix, input, keys, size);
76 if (i->first->suffix != NULL &&
suffix == NULL)
79 suffix->
extend (i->first->rule, i->first->ctx, &i->second);
86 template <
typename cunit_t,
typename key_t>
87 void Skeleton::generate_paths_cunit_key (FILE * input, FILE * keys)
92 nodes->
cover<cunit_t, key_t> (prefix, input, keys, size);
100 ,
"DFA %sis too large: can only generate partial path cover"
106 template <
typename cunit_t>
107 void Skeleton::generate_paths_cunit (FILE * input, FILE * keys)
111 case 4: generate_paths_cunit_key<cunit_t, uint32_t> (input, keys);
break;
112 case 2: generate_paths_cunit_key<cunit_t, uint16_t> (input, keys);
break;
113 case 1: generate_paths_cunit_key<cunit_t, uint8_t> (input, keys);
break;
117 void Skeleton::generate_paths (FILE * input, FILE * keys)
121 case 4: generate_paths_cunit<uint32_t> (input, keys);
break;
122 case 2: generate_paths_cunit<uint16_t> (input, keys);
break;
123 case 1: generate_paths_cunit<uint8_t> (input, keys);
break;
129 const std::string input_name = std::string (fname) +
"." +
name +
".input";
130 FILE * input = fopen (input_name.c_str (),
"wb");
133 error (
"cannot open file: %s", input_name.c_str ());
136 const std::string keys_name = std::string (fname) +
"." +
name +
".keys";
137 FILE * keys = fopen (keys_name.c_str (),
"wb");
140 error (
"cannot open file: %s", keys_name.c_str ());
144 generate_paths (input, keys);
150 template <
typename u
intn_t>
static uintn_t
to_le(uintn_t n)
153 uint8_t *p =
reinterpret_cast<uint8_t*
>(&m);
154 for (
size_t i = 0; i <
sizeof(uintn_t); ++i)
156 p[i] =
static_cast<uint8_t
>(n >> (i * 8));
161 template <
typename key_t>
164 const key_t m = Skeleton::rule2key<key_t> (match);
166 const size_t keys_size = 3 * count;
167 key_t * keys =
new key_t [keys_size];
168 for (uint32_t i = 0; i < keys_size;)
170 keys[i++] = to_le<key_t>(
static_cast<key_t
> (len));
171 keys[i++] = to_le<key_t>(
static_cast<key_t
> (len_match));
172 keys[i++] = to_le<key_t>(m);
174 fwrite (keys,
sizeof (key_t), keys_size, f);
178 template <
typename cunit_t,
typename key_t>
181 const size_t len = path.
len ();
184 for (
size_t i = 0; i < len; ++i)
186 count = std::max (count, path[i]->size ());
193 const size_t buffer_size = size.
uint32 ();
194 cunit_t * buffer =
new cunit_t [buffer_size];
195 for (
size_t i = 0; i < len; ++i)
197 const std::vector<uint32_t> & arc = *path[i];
198 const size_t width = arc.size ();
199 for (
size_t j = 0; j < count; ++j)
201 const size_t k = j % width;
202 buffer[j * len + i] = to_le<cunit_t>(
static_cast<cunit_t
> (arc[k]));
205 fwrite (buffer,
sizeof (cunit_t), buffer_size, input);
void append(const path_t *p)
void error(const char *fmt,...)
rule_rank_t match() const
static u32lim_t from32(uint32_t x)
static uintn_t to_le(uintn_t n)
void cover(path_t &prefix, FILE *input, FILE *keys, covers_t &size)
static Node::covers_t cover_one(FILE *input, FILE *keys, const path_t &path)
static void keygen(FILE *f, size_t count, size_t len, size_t len_match, rule_rank_t match)
static u32lim_t from64(uint64_t x)
size_t len_matching() const
uint32_t szCodeUnit() const
void extend(rule_t r, bool c, const arc_t *a)
void warning(const char *type, uint32_t line, bool error, const char *fmt,...)
u32lim_t< 1024 *1024 *1024 > covers_t
void emit_data(const char *fname)
std::string incond(const std::string &cond)