From 34702d7b92aaef66d4e7db075308bf011ac59d0b Mon Sep 17 00:00:00 2001 From: Abdul Zreika Date: Wed, 18 Nov 2020 16:09:43 +1100 Subject: [PATCH] Removed unnecessary methods. --- src/ast2ram/AstToRamTranslator.cpp | 92 +++++++++++------------------- src/ast2ram/AstToRamTranslator.h | 7 +-- 2 files changed, 35 insertions(+), 64 deletions(-) diff --git a/src/ast2ram/AstToRamTranslator.cpp b/src/ast2ram/AstToRamTranslator.cpp index 4230902e0e6..5491762949b 100644 --- a/src/ast2ram/AstToRamTranslator.cpp +++ b/src/ast2ram/AstToRamTranslator.cpp @@ -141,55 +141,6 @@ size_t AstToRamTranslator::getEvaluationArity(const ast::Atom* atom) const { return auxArityAnalysis->getArity(originalRelation); } -std::vector> AstToRamTranslator::getInputDirectives( - const ast::Relation* rel) const { - std::vector> inputDirectives; - for (const auto* load : getDirectives(*program, rel->getQualifiedName())) { - // must be a load - if (load->getType() != ast::DirectiveType::input) { - continue; - } - - std::map directives; - for (const auto& [key, value] : load->getParameters()) { - directives.insert(std::make_pair(key, unescape(value))); - } - inputDirectives.push_back(directives); - } - - // add an empty directive if none exist - if (inputDirectives.empty()) { - inputDirectives.emplace_back(); - } - - return inputDirectives; -} - -std::vector> AstToRamTranslator::getOutputDirectives( - const ast::Relation* rel) const { - std::vector> outputDirectives; - for (const auto* store : getDirectives(*program, rel->getQualifiedName())) { - // must be either printsize or output - if (store->getType() != ast::DirectiveType::printsize && - store->getType() != ast::DirectiveType::output) { - continue; - } - - std::map directives; - for (const auto& [key, value] : store->getParameters()) { - directives.insert(std::make_pair(key, unescape(value))); - } - outputDirectives.push_back(directives); - } - - // add an empty directive if none exist - if (outputDirectives.empty()) { - outputDirectives.emplace_back(); - } - - return outputDirectives; -} - Own AstToRamTranslator::translateValue( const ast::Argument* arg, const ValueIndex& index) const { if (arg == nullptr) return nullptr; @@ -660,34 +611,57 @@ bool AstToRamTranslator::removeADTs(const ast::TranslationUnit& translationUnit) Own AstToRamTranslator::generateLoadRelation(const ast::Relation* relation) const { VecOwn loadStmts; - for (auto directives : getInputDirectives(relation)) { - Own statement = mk(getConcreteRelationName(relation), directives); + for (const auto* load : getDirectives(*program, relation->getQualifiedName())) { + // Must be a load + if (load->getType() != ast::DirectiveType::input) { + continue; + } + // Set up the corresponding directive map + std::map directives; + for (const auto& [key, value] : load->getParameters()) { + directives.insert(std::make_pair(key, unescape(value))); + } + + // Create the resultant load statement, with profile information + Own loadStmt = mk(getConcreteRelationName(relation), directives); if (Global::config().has("profile")) { const std::string logTimerStatement = LogStatement::tRelationLoadTime( toString(relation->getQualifiedName()), relation->getSrcLoc()); - statement = mk( - std::move(statement), logTimerStatement, getConcreteRelationName(relation)); + loadStmt = mk( + std::move(loadStmt), logTimerStatement, getConcreteRelationName(relation)); } - appendStmt(loadStmts, std::move(statement)); + appendStmt(loadStmts, std::move(loadStmt)); } return mk(std::move(loadStmts)); } Own AstToRamTranslator::generateStoreRelation(const ast::Relation* relation) const { VecOwn storeStmts; - for (auto directives : getOutputDirectives(relation)) { - Own statement = mk(getConcreteRelationName(relation), directives); + for (const auto* store : getDirectives(*program, relation->getQualifiedName())) { + // Must be a storage relation + if (store->getType() != ast::DirectiveType::printsize && + store->getType() != ast::DirectiveType::output) { + continue; + } + + // Set up the corresponding directive map + std::map directives; + for (const auto& [key, value] : store->getParameters()) { + directives.insert(std::make_pair(key, unescape(value))); + } + // Create the resultant store statement, with profile information + Own storeStmt = mk(getConcreteRelationName(relation), directives); if (Global::config().has("profile")) { const std::string logTimerStatement = LogStatement::tRelationSaveTime( toString(relation->getQualifiedName()), relation->getSrcLoc()); - statement = mk( - std::move(statement), logTimerStatement, getConcreteRelationName(relation)); + storeStmt = mk( + std::move(storeStmt), logTimerStatement, getConcreteRelationName(relation)); } - appendStmt(storeStmts, std::move(statement)); + appendStmt(storeStmts, std::move(storeStmt)); } return mk(std::move(storeStmts)); } diff --git a/src/ast2ram/AstToRamTranslator.h b/src/ast2ram/AstToRamTranslator.h index a2a64957f8b..a53d1e5795a 100644 --- a/src/ast2ram/AstToRamTranslator.h +++ b/src/ast2ram/AstToRamTranslator.h @@ -122,7 +122,7 @@ class AstToRamTranslator { const std::set& expiredRelations) const; RamDomain getConstantRamRepresentation(const ast::Constant& constant) const; - /* Translate RAM code for the non-recursive clauses of the given relation */ + /** Translate RAM code for the non-recursive clauses of the given relation */ Own translateNonRecursiveRelation(const ast::Relation& rel) const; /** Translate RAM code for recursive relations in a strongly-connected component */ @@ -136,10 +136,6 @@ class AstToRamTranslator { std::map> ramRelations; Own symbolTable; - // TODO (b-scholz): revisit / refactor so that only one directive is translated - std::vector> getInputDirectives(const ast::Relation* rel) const; - std::vector> getOutputDirectives(const ast::Relation* rel) const; - /** create RAM relations for a given SCC */ void createRamRelations(size_t scc); @@ -156,6 +152,7 @@ class AstToRamTranslator { VecOwn translateRecursiveClauses( const std::set& scc, const ast::Relation* rel) const; + /** Stratum translation */ Own generateStratumPreamble(const std::set& scc) const; Own generateStratumPostamble(const std::set& scc) const; Own generateStratumTableUpdates(const std::set& scc) const;