-
Notifications
You must be signed in to change notification settings - Fork 192
/
IOType.cpp
56 lines (50 loc) · 1.88 KB
/
IOType.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Souffle - A Datalog Compiler
* Copyright (c) 2019, The Souffle Developers. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at:
* - https://opensource.org/licenses/UPL
* - <souffle root>/licenses/SOUFFLE-UPL.txt
*/
/************************************************************************
*
* @file IOTypeAnalysis.cpp
*
* Implements methods to identify a relation as input, output, or printsize.
*
***********************************************************************/
#include "ast/analysis/IOType.h"
#include "ast/IO.h"
#include "ast/Program.h"
#include "ast/QualifiedName.h"
#include "ast/Relation.h"
#include "ast/TranslationUnit.h"
#include "ast/Utils.h"
#include "ast/Visitor.h"
#include "utility/StreamUtil.h"
#include <ostream>
#include <vector>
namespace souffle {
void IOType::run(const AstTranslationUnit& translationUnit) {
const AstProgram& program = *translationUnit.getProgram();
visitDepthFirst(program, [&](const AstIO& io) {
auto* relation = getRelation(program, io.getQualifiedName());
if (relation == nullptr) {
return;
}
switch (io.getType()) {
case AstIoType::input: inputRelations.insert(relation); break;
case AstIoType::output: outputRelations.insert(relation); break;
case AstIoType::printsize:
printSizeRelations.insert(relation);
outputRelations.insert(relation);
break;
}
});
}
void IOType::print(std::ostream& os) const {
auto show = [](std::ostream& os, const AstRelation* r) { os << r->getQualifiedName(); };
os << "input relations: {" << join(inputRelations, ", ", show) << "}\n";
os << "output relations: {" << join(outputRelations, ", ", show) << "}\n";
os << "printsize relations: {" << join(printSizeRelations, ", ", show) << "}\n";
}
} // end of namespace souffle