mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
minor clean up of rose_build_bytecode.cpp
- consistently name functions creating programs as makeFoo() - replace writeLiteralProgram() with makeFragmentProgram() - make applyFinalSpecialisation() part of writeProgram(bc, prog) - seperate users who want to make a program for a single literal and fragments
This commit is contained in:
parent
0626a30a6a
commit
cd424bdb45
@ -2551,6 +2551,8 @@ u32 writeProgram(build_context &bc, RoseProgram &&program) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyFinalSpecialisation(program);
|
||||||
|
|
||||||
auto it = bc.program_cache.find(program);
|
auto it = bc.program_cache.find(program);
|
||||||
if (it != end(bc.program_cache)) {
|
if (it != end(bc.program_cache)) {
|
||||||
DEBUG_PRINTF("reusing cached program at %u\n", it->second);
|
DEBUG_PRINTF("reusing cached program at %u\n", it->second);
|
||||||
@ -4248,7 +4250,6 @@ u32 writeBoundaryProgram(const RoseBuildImpl &build, build_context &bc,
|
|||||||
for (const auto &id : reports) {
|
for (const auto &id : reports) {
|
||||||
makeReport(build, id, has_som, program);
|
makeReport(build, id, has_som, program);
|
||||||
}
|
}
|
||||||
applyFinalSpecialisation(program);
|
|
||||||
return writeProgram(bc, move(program));
|
return writeProgram(bc, move(program));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4758,10 +4759,10 @@ bool hasDelayedLiteral(const RoseBuildImpl &build,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
RoseProgram buildLitInitialProgram(const RoseBuildImpl &build,
|
RoseProgram makeLitInitialProgram(const RoseBuildImpl &build,
|
||||||
build_context &bc, ProgramBuild &prog_build,
|
build_context &bc, ProgramBuild &prog_build,
|
||||||
u32 lit_id,
|
u32 lit_id,
|
||||||
const vector<RoseEdge> &lit_edges) {
|
const vector<RoseEdge> &lit_edges) {
|
||||||
RoseProgram program;
|
RoseProgram program;
|
||||||
|
|
||||||
// Check long literal info.
|
// Check long literal info.
|
||||||
@ -4790,10 +4791,10 @@ RoseProgram buildLitInitialProgram(const RoseBuildImpl &build,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
RoseProgram buildLiteralProgram(const RoseBuildImpl &build, build_context &bc,
|
RoseProgram makeLiteralProgram(const RoseBuildImpl &build, build_context &bc,
|
||||||
ProgramBuild &prog_build, u32 lit_id,
|
ProgramBuild &prog_build, u32 lit_id,
|
||||||
const vector<RoseEdge> &lit_edges,
|
const vector<RoseEdge> &lit_edges,
|
||||||
bool is_anchored_program) {
|
bool is_anchored_program) {
|
||||||
const auto &g = build.g;
|
const auto &g = build.g;
|
||||||
|
|
||||||
DEBUG_PRINTF("lit id=%u, %zu lit edges\n", lit_id, lit_edges.size());
|
DEBUG_PRINTF("lit id=%u, %zu lit edges\n", lit_id, lit_edges.size());
|
||||||
@ -4851,13 +4852,32 @@ RoseProgram buildLiteralProgram(const RoseBuildImpl &build, build_context &bc,
|
|||||||
|
|
||||||
// Construct initial program up front, as its early checks must be able
|
// Construct initial program up front, as its early checks must be able
|
||||||
// to jump to end and terminate processing for this literal.
|
// to jump to end and terminate processing for this literal.
|
||||||
auto lit_program =
|
auto lit_program = makeLitInitialProgram(build, bc, prog_build, lit_id,
|
||||||
buildLitInitialProgram(build, bc, prog_build, lit_id, lit_edges);
|
lit_edges);
|
||||||
lit_program.add_before_end(move(program));
|
lit_program.add_before_end(move(program));
|
||||||
|
|
||||||
return lit_program;
|
return lit_program;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
RoseProgram makeLiteralProgram(const RoseBuildImpl &build, build_context &bc,
|
||||||
|
ProgramBuild &prog_build, u32 lit_id,
|
||||||
|
const map<u32, vector<RoseEdge>> &lit_edge_map,
|
||||||
|
bool is_anchored_program) {
|
||||||
|
const vector<RoseEdge> no_edges;
|
||||||
|
|
||||||
|
DEBUG_PRINTF("lit_id=%u\n", lit_id);
|
||||||
|
const vector<RoseEdge> *edges_ptr;
|
||||||
|
if (contains(lit_edge_map, lit_id)) {
|
||||||
|
edges_ptr = &lit_edge_map.at(lit_id);
|
||||||
|
} else {
|
||||||
|
edges_ptr = &no_edges;
|
||||||
|
}
|
||||||
|
|
||||||
|
return makeLiteralProgram(build, bc, prog_build, lit_id, *edges_ptr,
|
||||||
|
is_anchored_program);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Consumes list of program blocks, checks them for duplicates and then
|
* \brief Consumes list of program blocks, checks them for duplicates and then
|
||||||
* concatenates them into one program.
|
* concatenates them into one program.
|
||||||
@ -4887,10 +4907,10 @@ RoseProgram assembleProgramBlocks(vector<RoseProgram> &&blocks) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
u32 writeLiteralProgram(const RoseBuildImpl &build, build_context &bc,
|
RoseProgram makeFragmentProgram(const RoseBuildImpl &build, build_context &bc,
|
||||||
ProgramBuild &prog_build, const vector<u32> &lit_ids,
|
ProgramBuild &prog_build,
|
||||||
const map<u32, vector<RoseEdge>> &lit_edge_map,
|
const vector<u32> &lit_ids,
|
||||||
bool is_anchored_program) {
|
const map<u32, vector<RoseEdge>> &lit_edge_map) {
|
||||||
assert(!lit_ids.empty());
|
assert(!lit_ids.empty());
|
||||||
|
|
||||||
// If we have multiple literals and any of them squash groups, we will have
|
// If we have multiple literals and any of them squash groups, we will have
|
||||||
@ -4907,18 +4927,9 @@ u32 writeLiteralProgram(const RoseBuildImpl &build, build_context &bc,
|
|||||||
|
|
||||||
vector<RoseProgram> blocks;
|
vector<RoseProgram> blocks;
|
||||||
|
|
||||||
const vector<RoseEdge> no_edges;
|
|
||||||
|
|
||||||
for (const auto &lit_id : lit_ids) {
|
for (const auto &lit_id : lit_ids) {
|
||||||
DEBUG_PRINTF("lit_id=%u\n", lit_id);
|
auto prog = makeLiteralProgram(build, bc, prog_build, lit_id,
|
||||||
const vector<RoseEdge> *edges_ptr;
|
lit_edge_map, false);
|
||||||
if (contains(lit_edge_map, lit_id)) {
|
|
||||||
edges_ptr = &lit_edge_map.at(lit_id);
|
|
||||||
} else {
|
|
||||||
edges_ptr = &no_edges;
|
|
||||||
}
|
|
||||||
auto prog = buildLiteralProgram(build, bc, prog_build, lit_id,
|
|
||||||
*edges_ptr, is_anchored_program);
|
|
||||||
if (needs_clear_work) {
|
if (needs_clear_work) {
|
||||||
RoseProgram clear_block;
|
RoseProgram clear_block;
|
||||||
clear_block.add_before_end(make_unique<RoseInstrClearWorkDone>());
|
clear_block.add_before_end(make_unique<RoseInstrClearWorkDone>());
|
||||||
@ -4927,13 +4938,7 @@ u32 writeLiteralProgram(const RoseBuildImpl &build, build_context &bc,
|
|||||||
blocks.push_back(move(prog));
|
blocks.push_back(move(prog));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto program = assembleProgramBlocks(move(blocks));
|
return assembleProgramBlocks(move(blocks));
|
||||||
|
|
||||||
if (program.empty()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
applyFinalSpecialisation(program);
|
|
||||||
return writeProgram(bc, move(program));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -4965,10 +4970,6 @@ u32 writeDelayRebuildProgram(const RoseBuildImpl &build, build_context &bc,
|
|||||||
|
|
||||||
auto program = assembleProgramBlocks(move(blocks));
|
auto program = assembleProgramBlocks(move(blocks));
|
||||||
|
|
||||||
if (program.empty()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
applyFinalSpecialisation(program);
|
|
||||||
return writeProgram(bc, move(program));
|
return writeProgram(bc, move(program));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5107,9 +5108,10 @@ void buildLiteralPrograms(const RoseBuildImpl &build,
|
|||||||
DEBUG_PRINTF("frag_id=%u, lit_ids=[%s]\n", frag.fragment_id,
|
DEBUG_PRINTF("frag_id=%u, lit_ids=[%s]\n", frag.fragment_id,
|
||||||
as_string_list(frag.lit_ids).c_str());
|
as_string_list(frag.lit_ids).c_str());
|
||||||
|
|
||||||
frag.lit_program_offset
|
auto lit_prog = makeFragmentProgram(build, bc, prog_build, frag.lit_ids,
|
||||||
= writeLiteralProgram(build, bc, prog_build, frag.lit_ids,
|
lit_edge_map);
|
||||||
lit_edge_map, false);
|
frag.lit_program_offset = writeProgram(bc, move(lit_prog));
|
||||||
|
|
||||||
frag.delay_program_offset
|
frag.delay_program_offset
|
||||||
= writeDelayRebuildProgram(build, bc, prog_build, frag.lit_ids);
|
= writeDelayRebuildProgram(build, bc, prog_build, frag.lit_ids);
|
||||||
}
|
}
|
||||||
@ -5137,9 +5139,10 @@ pair<u32, u32> writeDelayPrograms(const RoseBuildImpl &build,
|
|||||||
|
|
||||||
for (const auto &delayed_lit_id : info.delayed_ids) {
|
for (const auto &delayed_lit_id : info.delayed_ids) {
|
||||||
DEBUG_PRINTF("lit id %u delay id %u\n", lit_id, delayed_lit_id);
|
DEBUG_PRINTF("lit id %u delay id %u\n", lit_id, delayed_lit_id);
|
||||||
u32 offset = writeLiteralProgram(build, bc, prog_build,
|
auto prog = makeLiteralProgram(build, bc, prog_build,
|
||||||
{delayed_lit_id}, lit_edge_map,
|
delayed_lit_id, lit_edge_map,
|
||||||
false);
|
false);
|
||||||
|
u32 offset = writeProgram(bc, move(prog));
|
||||||
|
|
||||||
u32 delay_id;
|
u32 delay_id;
|
||||||
auto it = cache.find(offset);
|
auto it = cache.find(offset);
|
||||||
@ -5197,8 +5200,9 @@ pair<u32, u32> writeAnchoredPrograms(const RoseBuildImpl &build,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 offset = writeLiteralProgram(build, bc, prog_build, {lit_id},
|
auto prog = makeLiteralProgram(build, bc, prog_build, lit_id,
|
||||||
lit_edge_map, true);
|
lit_edge_map, true);
|
||||||
|
u32 offset = writeProgram(bc, move(prog));
|
||||||
DEBUG_PRINTF("lit_id=%u -> anch prog at %u\n", lit_id, offset);
|
DEBUG_PRINTF("lit_id=%u -> anch prog at %u\n", lit_id, offset);
|
||||||
|
|
||||||
u32 anch_id;
|
u32 anch_id;
|
||||||
@ -5260,7 +5264,6 @@ pair<u32, u32> buildReportPrograms(const RoseBuildImpl &build,
|
|||||||
const bool has_som = false;
|
const bool has_som = false;
|
||||||
makeCatchupMpv(build, bc.needs_mpv_catchup, id, program);
|
makeCatchupMpv(build, bc.needs_mpv_catchup, id, program);
|
||||||
makeReport(build, id, has_som, program);
|
makeReport(build, id, has_som, program);
|
||||||
applyFinalSpecialisation(program);
|
|
||||||
u32 offset = writeProgram(bc, move(program));
|
u32 offset = writeProgram(bc, move(program));
|
||||||
programs.push_back(offset);
|
programs.push_back(offset);
|
||||||
build.rm.setProgramOffset(id, offset);
|
build.rm.setProgramOffset(id, offset);
|
||||||
@ -5404,8 +5407,10 @@ void addEodEventProgram(const RoseBuildImpl &build, build_context &bc,
|
|||||||
tie(g[source(b, g)].index, g[target(b, g)].index);
|
tie(g[source(b, g)].index, g[target(b, g)].index);
|
||||||
});
|
});
|
||||||
|
|
||||||
program.add_block(buildLiteralProgram(
|
auto block = makeLiteralProgram(build, bc, prog_build,
|
||||||
build, bc, prog_build, build.eod_event_literal_id, edge_list, false));
|
build.eod_event_literal_id, edge_list,
|
||||||
|
false);
|
||||||
|
program.add_block(move(block));
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -5453,11 +5458,6 @@ u32 writeEodProgram(const RoseBuildImpl &build, build_context &bc,
|
|||||||
addEodAnchorProgram(build, bc, prog_build, true, program);
|
addEodAnchorProgram(build, bc, prog_build, true, program);
|
||||||
addSuffixesEodProgram(build, program);
|
addSuffixesEodProgram(build, program);
|
||||||
|
|
||||||
if (program.empty()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
applyFinalSpecialisation(program);
|
|
||||||
return writeProgram(bc, move(program));
|
return writeProgram(bc, move(program));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user