src/ir/compile.h \
src/ir/rule.h \
src/ir/tag.h \
- src/ir/tagpool.h \
src/ir/skeleton/path.h \
src/ir/skeleton/skeleton.h \
src/globals.h \
src/ir/skeleton/maxpath.cc \
src/ir/skeleton/skeleton.cc \
src/ir/tag.cc \
- src/ir/tagpool.cc \
src/main.cc \
src/parse/code.cc \
src/parse/input.cc \
#include "src/ir/regexp/regexp.h"
#include "src/ir/rule.h"
-#include "src/ir/tagpool.h"
+#include "src/ir/tag.h"
#include "src/util/forbid_copy.h"
namespace re2c
#include "src/ir/regexp/regexp.h"
#include "src/ir/rule.h"
-#include "src/ir/tagpool.h"
+#include "src/ir/tag.h"
#include "src/util/forbid_copy.h"
namespace re2c
#include <vector>
#include "src/ir/tag.h"
-#include "src/ir/tagpool.h"
#include "src/parse/code.h"
#include "src/parse/loc.h"
#include "src/util/forbid_copy.h"
+#include <assert.h>
#include <limits>
+#include <stdlib.h> // malloc
+#include <string.h> // memcpy, memcmp
#include "src/ir/rule.h"
#include "src/ir/tag.h"
+#include "src/util/hash32.h"
namespace re2c
{
+struct eqtag_t
+{
+ size_t ntags;
+
+ explicit eqtag_t(size_t n): ntags(n) {}
+ inline bool operator()(const bool *x, const bool *y)
+ {
+ return memcmp(x, y, ntags * sizeof(bool)) == 0;
+ }
+};
+
const size_t Tag::NONE = std::numeric_limits<size_t>::max();
Tag::Tag()
tag.fix.dist = d;
}
+Tagpool::Tagpool(size_t n)
+ : lookup()
+ , buffer(new bool[n * 3])
+ , ntags(n)
+ , buffer1(&buffer[n * 1])
+ , buffer2(&buffer[n * 2])
+{
+ // all-zero tag configuration must have static number zero
+ std::fill(buffer, buffer + ntags, false);
+ assert(ZERO_TAGS == insert(buffer));
+}
+
+Tagpool::~Tagpool()
+{
+ delete[] buffer;
+ const size_t n = lookup.size();
+ for (size_t i = 0; i < n; ++i) {
+ free(const_cast<bool*>(lookup[i]));
+ }
+}
+
+size_t Tagpool::insert(const bool *tags)
+{
+ const size_t size = ntags * sizeof(bool);
+ const uint32_t hash = hash32(0, tags, size);
+
+ eqtag_t eq(ntags);
+ const size_t idx = lookup.find_with(hash, tags, eq);
+ if (idx != taglookup_t::NIL) {
+ return idx;
+ }
+
+ bool *copy = static_cast<bool*>(malloc(size));
+ memcpy(copy, tags, size);
+ return lookup.push(hash, copy);
+}
+
+const bool *Tagpool::operator[](size_t idx) const
+{
+ return lookup[idx];
+}
+
+size_t Tagpool::orl(size_t t, size_t o)
+{
+ if (t == o || o == 0) {
+ return t;
+ } else if (t == ZERO_TAGS) {
+ return o;
+ }
+
+ const bool *tags = operator[](t);
+ const bool *ortags = operator[](o);
+ for (size_t i = 0; i < ntags; ++i) {
+ buffer[i] = tags[i] | ortags[i];
+ }
+ return insert(buffer);
+}
+
+size_t Tagpool::andl(size_t t, size_t a)
+{
+ if (t == a) {
+ return t;
+ } else if (t == ZERO_TAGS || a == ZERO_TAGS) {
+ return ZERO_TAGS;
+ }
+
+ const bool *tags = operator[](t);
+ const bool *andtags = operator[](a);
+ for (size_t i = 0; i < ntags; ++i) {
+ buffer[i] = tags[i] & andtags[i];
+ }
+ return insert(buffer);
+}
+
+size_t Tagpool::andlinv(size_t t, size_t a)
+{
+ if (a == ZERO_TAGS) {
+ return t;
+ } else if (t == ZERO_TAGS || t == a) {
+ return ZERO_TAGS;
+ }
+
+ const bool *tags = operator[](t);
+ const bool *andinvtags = operator[](a);
+ for (size_t i = 0; i < ntags; ++i) {
+ buffer[i] = tags[i] & ~andinvtags[i];
+ }
+ return insert(buffer);
+}
+
+size_t Tagpool::subst(size_t t, const size_t *represent)
+{
+ const bool *tags = operator[](t);
+ memset(buffer, 0, ntags * sizeof(bool));
+ for (size_t i = 0; i < ntags; ++i) {
+ if (tags[i]) {
+ buffer[represent[i]] = true;
+ }
+ }
+ return insert(buffer);
+}
+
} // namespace re2c
#include <string>
-#include "src/ir/tagpool.h"
+#include "src/util/lookup.h"
#include "src/util/forbid_copy.h"
namespace re2c
void init_var_tag(Tag &tag, size_t r, const std::string *n, size_t o);
void init_fix_tag(Tag &tag, size_t r, const std::string *n, size_t b, size_t d);
+static const size_t ZERO_TAGS = 0;
+
+struct Tagpool
+{
+private:
+ typedef lookup_t<const bool*> taglookup_t;
+ taglookup_t lookup;
+ bool *buffer;
+
+public:
+ const size_t ntags;
+ bool *buffer1;
+ bool *buffer2;
+
+ explicit Tagpool(size_t n);
+ ~Tagpool();
+ size_t insert(const bool *tags);
+ size_t orl(size_t t, size_t o);
+ size_t andl(size_t t, size_t a);
+ size_t andlinv(size_t t, size_t a);
+ size_t subst(size_t t, const size_t *represent);
+ const bool *operator[](size_t idx) const;
+ FORBID_COPY(Tagpool);
+};
+
/* must be packed */
struct tagcmd_t
{
+++ /dev/null
-#include <assert.h>
-
-#include "src/ir/tagpool.h"
-#include "src/util/hash32.h"
-
-namespace re2c
-{
-
-Tagpool::Tagpool(size_t n)
- : lookup()
- , buffer(new bool[n * 3])
- , ntags(n)
- , buffer1(&buffer[n * 1])
- , buffer2(&buffer[n * 2])
-{
- // all-zero tag configuration must have static number zero
- std::fill(buffer, buffer + ntags, false);
- assert(ZERO_TAGS == insert(buffer));
-}
-
-Tagpool::~Tagpool()
-{
- delete[] buffer;
- const size_t n = lookup.size();
- for (size_t i = 0; i < n; ++i) {
- free(const_cast<bool*>(lookup[i]));
- }
-}
-
-size_t Tagpool::insert(const bool *tags)
-{
- const size_t size = ntags * sizeof(bool);
- const uint32_t hash = hash32(0, tags, size);
-
- eqtag_t eq(ntags);
- const size_t idx = lookup.find_with(hash, tags, eq);
- if (idx != taglookup_t::NIL) {
- return idx;
- }
-
- bool *copy = static_cast<bool*>(malloc(size));
- memcpy(copy, tags, size);
- return lookup.push(hash, copy);
-}
-
-const bool *Tagpool::operator[](size_t idx) const
-{
- return lookup[idx];
-}
-
-size_t Tagpool::orl(size_t t, size_t o)
-{
- if (t == o || o == 0) {
- return t;
- } else if (t == ZERO_TAGS) {
- return o;
- }
-
- const bool *tags = operator[](t);
- const bool *ortags = operator[](o);
- for (size_t i = 0; i < ntags; ++i) {
- buffer[i] = tags[i] | ortags[i];
- }
- return insert(buffer);
-}
-
-size_t Tagpool::andl(size_t t, size_t a)
-{
- if (t == a) {
- return t;
- } else if (t == ZERO_TAGS || a == ZERO_TAGS) {
- return ZERO_TAGS;
- }
-
- const bool *tags = operator[](t);
- const bool *andtags = operator[](a);
- for (size_t i = 0; i < ntags; ++i) {
- buffer[i] = tags[i] & andtags[i];
- }
- return insert(buffer);
-}
-
-size_t Tagpool::andlinv(size_t t, size_t a)
-{
- if (a == ZERO_TAGS) {
- return t;
- } else if (t == ZERO_TAGS || t == a) {
- return ZERO_TAGS;
- }
-
- const bool *tags = operator[](t);
- const bool *andinvtags = operator[](a);
- for (size_t i = 0; i < ntags; ++i) {
- buffer[i] = tags[i] & ~andinvtags[i];
- }
- return insert(buffer);
-}
-
-size_t Tagpool::subst(size_t t, const size_t *represent)
-{
- const bool *tags = operator[](t);
- memset(buffer, 0, ntags * sizeof(bool));
- for (size_t i = 0; i < ntags; ++i) {
- if (tags[i]) {
- buffer[represent[i]] = true;
- }
- }
- return insert(buffer);
-}
-
-} // namespace re2c
+++ /dev/null
-#ifndef _RE2C_IR_TAGPOOL_
-#define _RE2C_IR_TAGPOOL_
-
-#include <stdlib.h> // malloc
-#include <string.h> // memcpy, memcmp
-
-#include "src/util/lookup.h"
-#include "src/util/forbid_copy.h"
-
-namespace re2c
-{
-
-static const size_t ZERO_TAGS = 0;
-
-struct eqtag_t
-{
- size_t ntags;
-
- explicit eqtag_t(size_t n): ntags(n) {}
- inline bool operator()(const bool *x, const bool *y)
- {
- return memcmp(x, y, ntags * sizeof(bool)) == 0;
- }
-};
-
-struct Tagpool
-{
-private:
- typedef lookup_t<const bool*> taglookup_t;
- taglookup_t lookup;
- bool *buffer;
-
-public:
- const size_t ntags;
- bool *buffer1;
- bool *buffer2;
-
- explicit Tagpool(size_t n);
- ~Tagpool();
- size_t insert(const bool *tags);
- size_t orl(size_t t, size_t o);
- size_t andl(size_t t, size_t a);
- size_t andlinv(size_t t, size_t a);
- size_t subst(size_t t, const size_t *represent);
- const bool *operator[](size_t idx) const;
- FORBID_COPY(Tagpool);
-};
-
-} // namespace re2c
-
-#endif // _RE2C_IR_TAGPOOL_