Skip to content

Commit

Permalink
Made ramSubroutine creation more standardised.
Browse files Browse the repository at this point in the history
  • Loading branch information
azreika committed Nov 13, 2020
1 parent d085d04 commit 3a14794
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/ast2ram/AstToRamTranslator.cpp
Expand Up @@ -754,6 +754,11 @@ void AstToRamTranslator::finaliseAstTypes() {
});
}

void AstToRamTranslator::addRamSubroutine(std::string subroutineID, Own<ram::Statement> subroutine) {
assert(!contains(ramSubroutines, subroutineID) && "subroutine ID should not already exist");
ramSubroutines[subroutineID] = std::move(subroutine);
}

Own<ram::Sequence> AstToRamTranslator::translateProgram(const ast::TranslationUnit& translationUnit) {
// keep track of relevant analyses
ioType = translationUnit.getAnalysis<ast::analysis::IOTypeAnalysis>();
Expand Down Expand Up @@ -782,7 +787,7 @@ Own<ram::Sequence> AstToRamTranslator::translateProgram(const ast::TranslationUn
// handle the case of an empty SCC graph
if (sccGraph->getNumberOfSCCs() == 0) return mk<ram::Sequence>();

// create all RAM relations in ramRelations
// create all RAM relations
const auto& sccOrdering =
translationUnit.getAnalysis<ast::analysis::TopologicallySortedSCCGraphAnalysis>()->order();
for (const auto& scc : sccOrdering) {
Expand All @@ -791,7 +796,9 @@ Own<ram::Sequence> AstToRamTranslator::translateProgram(const ast::TranslationUn

// create subroutine for each SCC according to topological order
for (size_t i = 0; i < sccOrdering.size(); i++) {
ramSubroutines["stratum_" + toString(i)] = translateSCC(sccOrdering.at(i), i);
auto sccCode = translateSCC(sccOrdering.at(i), i);
std::string stratumID = "stratum_" + toString(i);
addRamSubroutine(stratumID, std::move(sccCode));
}

// invoke all strata
Expand Down
7 changes: 5 additions & 2 deletions src/ast2ram/AstToRamTranslator.h
Expand Up @@ -107,8 +107,6 @@ class AstToRamTranslator {
/** AST program */
const ast::Program* program = nullptr;

std::map<std::string, Own<ram::Statement>> ramSubroutines;
std::map<std::string, Own<ram::Relation>> ramRelations;
Own<ast::SipsMetric> sipsMetric;

/** Analyses needed */
Expand All @@ -129,7 +127,12 @@ class AstToRamTranslator {
virtual void clearExpiredRelations(
VecOwn<ram::Statement>& stmts, const std::set<const ast::Relation*>& expiredRelations);

void addRamSubroutine(std::string subroutineID, Own<ram::Statement> subroutine);

private:
std::map<std::string, Own<ram::Statement>> ramSubroutines;
std::map<std::string, Own<ram::Relation>> ramRelations;

/** replace ADTs with special records */
static bool removeADTs(const ast::TranslationUnit& translationUnit);

Expand Down
4 changes: 2 additions & 2 deletions src/ast2ram/ProvenanceTranslator.cpp
Expand Up @@ -69,11 +69,11 @@ void ProvenanceTranslator::addProvenanceClauseSubroutines(const ast::Program* pr

std::string subroutineLabel =
relName.str() + "_" + std::to_string(getClauseNum(program, &clause)) + "_subproof";
ramSubroutines[subroutineLabel] = makeSubproofSubroutine(clause);
addRamSubroutine(subroutineLabel, makeSubproofSubroutine(clause));

std::string negationSubroutineLabel =
relName.str() + "_" + std::to_string(getClauseNum(program, &clause)) + "_negation_subproof";
ramSubroutines[negationSubroutineLabel] = makeNegationSubproofSubroutine(clause);
addRamSubroutine(negationSubroutineLabel, makeNegationSubproofSubroutine(clause));
});
}

Expand Down

0 comments on commit 3a14794

Please sign in to comment.