Optimized compilational algorithm: reduced output binary
This commit is contained in:
parent
12a7db912f
commit
fc6e8e50fe
@ -1,9 +1,5 @@
|
|||||||
#include <regexis024_build_system.h>
|
#include <regexis024_build_system.h>
|
||||||
|
|
||||||
/*
|
|
||||||
* LIBREGEXIS024 SPECIFIC BUILD COMMANDS BEGIN
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct Libregexis024BuildSystem {
|
struct Libregexis024BuildSystem {
|
||||||
/* Building runlevel */
|
/* Building runlevel */
|
||||||
BuildUnitsArray runlevel_1;
|
BuildUnitsArray runlevel_1;
|
||||||
|
@ -44,11 +44,17 @@ namespace regexis024 {
|
|||||||
FA_NodeOfOneCharRead* ocr = dynamic_cast<FA_NodeOfOneCharRead*>(node);
|
FA_NodeOfOneCharRead* ocr = dynamic_cast<FA_NodeOfOneCharRead*>(node);
|
||||||
nonthrowing_assert(read_ss_ns < UINT32_MAX);
|
nonthrowing_assert(read_ss_ns < UINT32_MAX);
|
||||||
cmd_READ(result, read_ss_ns++);
|
cmd_READ(result, read_ss_ns++);
|
||||||
write_filter(result, bookmark_manager, {ocr->filter},{nodesBookmark(ocr->nxt_node)});
|
addBranching(ocr->nxt_node);
|
||||||
|
bool can_spill = write_filter(result, bookmark_manager, {ocr->filter},{nodesBookmark(ocr->nxt_node)});
|
||||||
|
if (!can_spill)
|
||||||
|
break;
|
||||||
node = ocr->nxt_node;
|
node = ocr->nxt_node;
|
||||||
} else if (node->type == look_one_behind) {
|
} else if (node->type == look_one_behind) {
|
||||||
FA_NodeOfLookOneBehind* lob = dynamic_cast<FA_NodeOfLookOneBehind*>(node);
|
FA_NodeOfLookOneBehind* lob = dynamic_cast<FA_NodeOfLookOneBehind*>(node);
|
||||||
write_filter(result, bookmark_manager, {lob->filter}, {nodesBookmark(lob->nxt_node)});
|
addBranching(lob->nxt_node);
|
||||||
|
bool can_spill = write_filter(result, bookmark_manager, {lob->filter}, {nodesBookmark(lob->nxt_node)});
|
||||||
|
if (!can_spill)
|
||||||
|
break;
|
||||||
node = lob->nxt_node;
|
node = lob->nxt_node;
|
||||||
} else if (node->type == forking) {
|
} else if (node->type == forking) {
|
||||||
FA_NodeOfForking* fn = dynamic_cast<FA_NodeOfForking*>(node);
|
FA_NodeOfForking* fn = dynamic_cast<FA_NodeOfForking*>(node);
|
||||||
@ -90,7 +96,9 @@ namespace regexis024 {
|
|||||||
branches.push_back(nodesBookmark(p.nxt_node));
|
branches.push_back(nodesBookmark(p.nxt_node));
|
||||||
addBranching(p.nxt_node);
|
addBranching(p.nxt_node);
|
||||||
}
|
}
|
||||||
write_filter(result, bookmark_manager, codesets, branches);
|
bool can_spill = write_filter(result, bookmark_manager, codesets, branches);
|
||||||
|
if (!can_spill)
|
||||||
|
break;
|
||||||
if (dcc->crossroads.empty())
|
if (dcc->crossroads.empty())
|
||||||
break;
|
break;
|
||||||
node = dcc->crossroads[0].nxt_node;
|
node = dcc->crossroads[0].nxt_node;
|
||||||
|
@ -5,6 +5,12 @@
|
|||||||
#include <libregexis024fa/graph_to_bytecode/writing_commands.h>
|
#include <libregexis024fa/graph_to_bytecode/writing_commands.h>
|
||||||
|
|
||||||
namespace regexis024 {
|
namespace regexis024 {
|
||||||
|
struct FilterSegment {
|
||||||
|
ssize_t color;
|
||||||
|
uint32_t L;
|
||||||
|
uint32_t R;
|
||||||
|
};
|
||||||
|
|
||||||
std::vector<FilterSegment> convert_to_compSeg(const std::vector<codeset_t>& crossroad_codesets)
|
std::vector<FilterSegment> convert_to_compSeg(const std::vector<codeset_t>& crossroad_codesets)
|
||||||
{
|
{
|
||||||
std::vector<FilterSegment> compSeg;
|
std::vector<FilterSegment> compSeg;
|
||||||
@ -63,11 +69,9 @@ namespace regexis024 {
|
|||||||
size_t Ri;
|
size_t Ri;
|
||||||
bool second_part = false;
|
bool second_part = false;
|
||||||
bookmark_id_t to_the_right_part;
|
bookmark_id_t to_the_right_part;
|
||||||
|
|
||||||
RecFrame(size_t li, size_t ri): Li(li),Ri(ri) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<RecFrame> call_stack = {RecFrame(0, N - 1)};
|
std::vector<RecFrame> call_stack = {RecFrame{0, N - 1}};
|
||||||
|
|
||||||
auto is_sandwich = [&](size_t Li, size_t Ri) -> bool {
|
auto is_sandwich = [&](size_t Li, size_t Ri) -> bool {
|
||||||
return Li + 2 == Ri && compSeg[Li].color == compSeg[Ri].color && compSeg[Li + 1].L == compSeg[Li + 1].R;
|
return Li + 2 == Ri && compSeg[Li].color == compSeg[Ri].color && compSeg[Li + 1].L == compSeg[Li + 1].R;
|
||||||
@ -105,12 +109,12 @@ namespace regexis024 {
|
|||||||
cmd_JCGRTR(result, bookmark_manager, compSeg[m].R, cur_frame.to_the_right_part);
|
cmd_JCGRTR(result, bookmark_manager, compSeg[m].R, cur_frame.to_the_right_part);
|
||||||
cur_frame.second_part = true;
|
cur_frame.second_part = true;
|
||||||
/* cur_frame was just invalidated */
|
/* cur_frame was just invalidated */
|
||||||
call_stack.emplace_back(Li, m);
|
call_stack.push_back({Li, m});
|
||||||
} else {
|
} else {
|
||||||
bookmark_manager.land_bookmark(result, cur_frame.to_the_right_part);
|
bookmark_manager.land_bookmark(result, cur_frame.to_the_right_part);
|
||||||
/* cur_frame was invalidated */
|
/* cur_frame was invalidated */
|
||||||
call_stack.pop_back();
|
call_stack.pop_back();
|
||||||
call_stack.emplace_back(m + 1, Ri);
|
call_stack.push_back({m + 1, Ri});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,6 @@
|
|||||||
#include <libregexis024fa/graph_to_bytecode/natural_compiler_utils.h>
|
#include <libregexis024fa/graph_to_bytecode/natural_compiler_utils.h>
|
||||||
|
|
||||||
namespace regexis024 {
|
namespace regexis024 {
|
||||||
struct FilterSegment {
|
|
||||||
ssize_t color;
|
|
||||||
uint32_t L;
|
|
||||||
uint32_t R;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Return whether user of function must place [0]'th option after the filter
|
/* Return whether user of function must place [0]'th option after the filter
|
||||||
* The filter can end up being written in such a way that the end will never be reached */
|
* The filter can end up being written in such a way that the end will never be reached */
|
||||||
bool write_filter(std::vector<uint8_t>& result, explicit_bookmarks& bookmark_manager,
|
bool write_filter(std::vector<uint8_t>& result, explicit_bookmarks& bookmark_manager,
|
||||||
|
Loading…
Reference in New Issue
Block a user