Skip to content

Commit

Permalink
Misc. small cleanups of ast2ram while going through it.
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdul Zreika committed Oct 16, 2020
1 parent 0d617a0 commit 360bd5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
33 changes: 16 additions & 17 deletions src/ast2ram/AstToRamTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ std::string AstToRamTranslator::getNewRelationName(const ast::Relation* rel) {
}

Own<ram::Expression> AstToRamTranslator::translateValue(const ast::Argument* arg, const ValueIndex& index) {
if (arg == nullptr) {
return nullptr;
}
if (arg == nullptr) return nullptr;

class ValueTranslator : public ast::Visitor<Own<ram::Expression>> {
AstToRamTranslator& translator;
Expand Down Expand Up @@ -616,15 +614,13 @@ Own<ram::Statement> AstToRamTranslator::translateRecursiveRelation(const std::se
}

// modify the processed rule to use delta relation and write to new relation
Own<ast::Clause> r1(cl->clone());
auto r1 = souffle::clone(cl);
r1->getHead()->setQualifiedName(getNewRelationName(rel));
ast::getBodyLiterals<ast::Atom>(*r1)[j]->setQualifiedName(getDeltaRelationName(atomRelation));
if (Global::config().has("provenance")) {
r1->addToBody(mk<ast::ProvenanceNegation>(souffle::clone(cl->getHead())));
} else {
if (r1->getHead()->getArity() > 0) {
r1->addToBody(mk<ast::Negation>(souffle::clone(cl->getHead())));
}
} else if (r1->getHead()->getArity() > 0) {
r1->addToBody(mk<ast::Negation>(souffle::clone(cl->getHead())));
}

// replace wildcards with variables (reduces indices when wildcards are used in recursive
Expand Down Expand Up @@ -679,7 +675,7 @@ Own<ram::Statement> AstToRamTranslator::translateRecursiveRelation(const std::se
}

// if there was no rule, continue
if (loopRelSeq.size() == 0) {
if (loopRelSeq.empty()) {
continue;
}

Expand Down Expand Up @@ -1197,27 +1193,30 @@ Own<ram::TranslationUnit> AstToRamTranslator::translateUnit(ast::TranslationUnit
program = &tu.getProgram();

translateProgram(tu);

SymbolTable& symTab = getSymbolTable();
ErrorReport& errReport = tu.getErrorReport();
DebugReport& debugReport = tu.getDebugReport();
VecOwn<ram::Relation> rels;
for (auto& cur : ramRels) {
rels.push_back(std::move(cur.second));
}

if (ramMain == nullptr) {
ramMain = mk<ram::Sequence>();
}
auto ramProg = mk<ram::Program>(std::move(rels), std::move(ramMain), std::move(ramSubs));

// add the translated program to the debug report
if (!Global::config().get("debug-report").empty()) {
if (ramProg) {
auto ram_end = std::chrono::high_resolution_clock::now();
std::string runtimeStr =
"(" + std::to_string(std::chrono::duration<double>(ram_end - ram_start).count()) + "s)";
std::stringstream ramProgStr;
ramProgStr << *ramProg;
debugReport.addSection("ram-program", "RAM Program " + runtimeStr, ramProgStr.str());
}
auto ram_end = std::chrono::high_resolution_clock::now();
std::string runtimeStr =
"(" + std::to_string(std::chrono::duration<double>(ram_end - ram_start).count()) + "s)";
std::stringstream ramProgStr;
ramProgStr << *ramProg;
debugReport.addSection("ram-program", "RAM Program " + runtimeStr, ramProgStr.str());
}

return mk<ram::TranslationUnit>(std::move(ramProg), std::move(symTab), errReport, debugReport);
}

Expand Down
3 changes: 0 additions & 3 deletions src/ast2ram/AstToRamTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ namespace souffle::ast2ram {
struct Location;
class ValueIndex;

/**
* Main class for the AST->RAM translator
*/
class AstToRamTranslator {
public:
AstToRamTranslator();
Expand Down

0 comments on commit 360bd5f

Please sign in to comment.