Skip to content

Commit

Permalink
Merge pull request #2494 from quentin/manyfixes
Browse files Browse the repository at this point in the history
several fixes
  • Loading branch information
quentin committed Jun 11, 2024
2 parents 01f7c00 + 56b69fa commit b7a5354
Show file tree
Hide file tree
Showing 28 changed files with 256 additions and 123 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if (SOUFFLE_GIT)
else()
string(REGEX REPLACE "\n$" "" PACKAGE_VERSION "${GIT_PACKAGE_VERSION}")
message(STATUS "Building souffle version ${PACKAGE_VERSION}")

# SOUFFLE_VERSION only includes the major/minor triplet
string(REGEX REPLACE "-.*$" "" SOUFFLE_VERSION "${PACKAGE_VERSION}")

Expand Down Expand Up @@ -319,7 +319,7 @@ if (SOUFFLE_GENERATE_DOXYGEN)

add_custom_target(doxygen
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_CFG}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen")
endif()

Expand Down Expand Up @@ -391,7 +391,7 @@ IF (SOUFFLE_BASH_COMPLETION)
endif()

install(
FILES "${CMAKE_SOURCE_DIR}/debian/souffle.bash-completion"
FILES "${PROJECT_SOURCE_DIR}/debian/souffle.bash-completion"
DESTINATION ${BASH_COMPLETION_COMPLETIONSDIR}
RENAME "souffle"
)
Expand All @@ -402,7 +402,7 @@ if (NOT WIN32)
# --------------------------------------------------
# CPack configuration
# --------------------------------------------------
execute_process(COMMAND bash "${CMAKE_SOURCE_DIR}/sh/check_os.sh"
execute_process(COMMAND bash "${PROJECT_SOURCE_DIR}/sh/check_os.sh"
RESULT_VARIABLE CHECK_OS_RESULT
OUTPUT_VARIABLE CHECK_OS_OUTPUT)

Expand All @@ -414,7 +414,7 @@ SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A Datalog Compiler")
SET(CPACK_THREADS 0)

# Make sure changelog, bash-completion and other important files in debian directory also packaged
SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/debian/changelog" "${CMAKE_SOURCE_DIR}/debian/souffle.bash-completion" "${CMAKE_SOURCE_DIR}/debian/copyright")
SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${PROJECT_SOURCE_DIR}/debian/changelog" "${PROJECT_SOURCE_DIR}/debian/souffle.bash-completion" "${PROJECT_SOURCE_DIR}/debian/copyright")

# --------------------------------------------------
# CPack configuration
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
set(SOUFFLE_SOURCES
FunctorOps.cpp
Global.cpp
GraphUtils.cpp
MainDriver.cpp
ast/Annotation.cpp
ast/Aggregator.cpp
Expand Down Expand Up @@ -197,6 +198,8 @@ else ()
# OSX compiler doesn't recognise `(void)var;` ideom
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/parser/scanner.cc PROPERTIES
COMPILE_FLAGS "-Wno-error=unused-parameter")
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/parser/parser.cc PROPERTIES
COMPILE_FLAGS "-Wno-error=unused-but-set-variable")
endif ()

# --------------------------------------------------
Expand Down
87 changes: 87 additions & 0 deletions src/GraphUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Souffle - A Datalog Compiler
* Copyright (c) 2024, 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
*/
#include "GraphUtils.h"
#include "souffle/utility/FileUtil.h"

#include <iostream>
#include <string>
#include <vector>

namespace souffle {

std::string toBase64(const std::string& data) {
static const std::vector<char> table = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};
std::string result;
std::string tmp = data;
unsigned int padding = 0;
if (data.size() % 3 == 2) {
padding = 1;
} else if (data.size() % 3 == 1) {
padding = 2;
}

for (unsigned int i = 0; i < padding; i++) {
tmp.push_back(0);
}
for (unsigned int i = 0; i < tmp.size(); i += 3) {
auto c1 = static_cast<unsigned char>(tmp[i]);
auto c2 = static_cast<unsigned char>(tmp[i + 1]);
auto c3 = static_cast<unsigned char>(tmp[i + 2]);
unsigned char index1 = c1 >> 2;
unsigned char index2 = ((c1 & 0x03) << 4) | (c2 >> 4);
unsigned char index3 = ((c2 & 0x0F) << 2) | (c3 >> 6);
unsigned char index4 = c3 & 0x3F;

result.push_back(table[index1]);
result.push_back(table[index2]);
result.push_back(table[index3]);
result.push_back(table[index4]);
}
if (padding == 1) {
result[result.size() - 1] = '=';
} else if (padding == 2) {
result[result.size() - 1] = '=';
result[result.size() - 2] = '=';
}
return result;
}

std::string convertDotToSVG(const std::string& dotSpec) {
// Check if dot is present
std::string cmd = which("dot");
if (!isExecutable(cmd)) {
return "";
}

if (dotSpec.size() > 50000) {
std::cerr << "skip graph with DOT spec length: " << dotSpec.size() << "\n";
return "";
}

TempFileStream dotFile;
dotFile << dotSpec;
dotFile.flush();
return execStdOut("dot -Tsvg < " + dotFile.getFileName()).str();
}

void printHTMLGraph(std::ostream& out, const std::string& dotSpec, const std::string& id) {
std::string data = convertDotToSVG(dotSpec);

if (data.find("<svg") != std::string::npos) {
out << "<img alt='graph image' src='data:image/svg+xml;base64," << toBase64(data) << "'><br/>\n";
} else {
out << "<div class='" << id << "-source"
<< "'>\n<pre>" << dotSpec << "</pre>\n";
out << "</div>\n";
}
}

} // namespace souffle
76 changes: 3 additions & 73 deletions src/GraphUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,84 +13,14 @@
* A simple utility graph for conducting simple, graph-based operations.
*
***********************************************************************/

#pragma once

#include "souffle/datastructure/Graph.h"
#include "souffle/utility/FileUtil.h"
#include <functional>
#include <map>
#include <ostream>
#include <set>
#include <string>
#include <utility>
#include <vector>

namespace souffle {

inline std::string toBase64(const std::string& data) {
static const std::vector<char> table = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};
std::string result;
std::string tmp = data;
unsigned int padding = 0;
if (data.size() % 3 == 2) {
padding = 1;
} else if (data.size() % 3 == 1) {
padding = 2;
}

for (unsigned int i = 0; i < padding; i++) {
tmp.push_back(0);
}
for (unsigned int i = 0; i < tmp.size(); i += 3) {
auto c1 = static_cast<unsigned char>(tmp[i]);
auto c2 = static_cast<unsigned char>(tmp[i + 1]);
auto c3 = static_cast<unsigned char>(tmp[i + 2]);
unsigned char index1 = c1 >> 2;
unsigned char index2 = ((c1 & 0x03) << 4) | (c2 >> 4);
unsigned char index3 = ((c2 & 0x0F) << 2) | (c3 >> 6);
unsigned char index4 = c3 & 0x3F;

result.push_back(table[index1]);
result.push_back(table[index2]);
result.push_back(table[index3]);
result.push_back(table[index4]);
}
if (padding == 1) {
result[result.size() - 1] = '=';
} else if (padding == 2) {
result[result.size() - 1] = '=';
result[result.size() - 2] = '=';
}
return result;
}

inline std::string convertDotToSVG(const std::string& dotSpec) {
// Check if dot is present
std::string cmd = which("dot");
if (!isExecutable(cmd)) {
return "";
}

TempFileStream dotFile;
dotFile << dotSpec;
dotFile.flush();
return execStdOut("dot -Tsvg < " + dotFile.getFileName()).str();
}

inline void printHTMLGraph(std::ostream& out, const std::string& dotSpec, const std::string& id) {
std::string data = convertDotToSVG(dotSpec);

if (data.find("<svg") != std::string::npos) {
out << "<img alt='graph image' src='data:image/svg+xml;base64," << toBase64(data) << "'><br/>\n";
} else {
out << "<div class='" << id << "-source"
<< "'>\n<pre>" << dotSpec << "</pre>\n";
out << "</div>\n";
}
}

std::string toBase64(const std::string& data);
std::string convertDotToSVG(const std::string& dotSpec);
void printHTMLGraph(std::ostream& out, const std::string& dotSpec, const std::string& id);
} // end of namespace souffle
2 changes: 2 additions & 0 deletions src/ast/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* - <souffle root>/licenses/SOUFFLE-UPL.txt
*/
#include "ast/Node.h"

#include <algorithm>
#include <utility>

namespace souffle::ast {
Expand Down
4 changes: 3 additions & 1 deletion src/ast/analysis/PrecedenceGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include "GraphUtils.h"
#include "ast/Relation.h"
#include "ast/TranslationUnit.h"
#include <string>
#include "souffle/datastructure/Graph.h"
#include <ostream>
#include <sstream>

namespace souffle::ast {

Expand Down
9 changes: 4 additions & 5 deletions src/ast/analysis/typesystem/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ Own<Clause> TypeAnalysis::createAnnotatedClause(
Own<Node> operator()(Own<Node> node) const override {
if (auto* var = as<ast::Variable>(node)) {
std::stringstream newVarName;
newVarName << var->getName() << "&isin;" << types.find(var)->second;
newVarName << var->getName() << "" << types.find(var)->second;
return mk<ast::Variable>(newVarName.str());
} else if (auto* var = as<UnnamedVariable>(node)) {
std::stringstream newVarName;
newVarName << "_"
<< "&isin;" << types.find(var)->second;
<< "" << types.find(var)->second;
return mk<ast::Variable>(newVarName.str());
}
node->apply(*this);
Expand Down Expand Up @@ -707,8 +707,7 @@ void TypeAnnotationPrinter::print_(type_identity<UserDefinedFunctor>, const User
auto arguments = fun.getArguments();
os << "@" << fun.getName() << "(";
for (std::size_t i = 0; i < arguments.size(); ++i) {
TypeAttribute argType = typeAnalysis.getFunctorParamTypeAttribute(fun, i);
auto& ty = typeEnv.getConstantType(argType);
const auto& ty = typeAnalysis.getFunctorParamType(fun, i);
branchOnArgument(arguments[i], ty);
if (i + 1 < arguments.size()) {
os << ",";
Expand Down Expand Up @@ -736,7 +735,7 @@ void TypeAnnotationPrinter::print_(type_identity<TypeCast>, const ast::TypeCast&
void TypeAnnotationPrinter::print_(
type_identity<RecordInit>, const RecordInit& record, const RecordType& type) {
auto arguments = record.getArguments();
auto& ftypes = type.getFields();
const auto& ftypes = type.getFields();
os << "[";
for (std::size_t i = 0; i < arguments.size(); ++i) {
branchOnArgument(arguments[i], *ftypes[i]);
Expand Down
2 changes: 1 addition & 1 deletion src/ast/analysis/typesystem/TypeEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
***********************************************************************/

#include "ast/analysis/typesystem/TypeEnvironment.h"
#include "GraphUtils.h"
#include "ast/AlgebraicDataType.h"
#include "ast/AliasType.h"
#include "ast/Attribute.h"
Expand All @@ -27,6 +26,7 @@
#include "ast/Type.h"
#include "ast/UnionType.h"
#include "ast/analysis/typesystem/TypeSystem.h"
#include "souffle/datastructure/Graph.h"
#include "souffle/utility/MiscUtil.h"
#include "souffle/utility/tinyformat.h"
#include <algorithm>
Expand Down
2 changes: 2 additions & 0 deletions src/ast/transform/InlineRelations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
#include "ast/UnnamedVariable.h"
#include "ast/UserDefinedFunctor.h"
#include "ast/Variable.h"
#include "ast/analysis/Ground.h"
#include "ast/analysis/typesystem/PolymorphicObjects.h"
#include "ast/analysis/typesystem/TypeEnvironment.h"
#include "ast/utility/Utils.h"
#include "ast/utility/Visitor.h"
#include "souffle/BinaryConstraintOps.h"
Expand Down
2 changes: 1 addition & 1 deletion src/ast/transform/PartitionBodyLiterals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
***********************************************************************/

#include "ast/transform/PartitionBodyLiterals.h"
#include "GraphUtils.h"
#include "ast/Atom.h"
#include "ast/Clause.h"
#include "ast/Literal.h"
Expand All @@ -23,6 +22,7 @@
#include "ast/TranslationUnit.h"
#include "ast/Variable.h"
#include "ast/utility/Visitor.h"
#include "souffle/datastructure/Graph.h"
#include "souffle/utility/MiscUtil.h"
#include <algorithm>
#include <functional>
Expand Down
2 changes: 1 addition & 1 deletion src/ast/transform/ReduceExistentials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
***********************************************************************/

#include "ast/transform/ReduceExistentials.h"
#include "GraphUtils.h"
#include "RelationTag.h"
#include "ast/Aggregator.h"
#include "ast/Argument.h"
Expand All @@ -30,6 +29,7 @@
#include "ast/analysis/IOType.h"
#include "ast/utility/Utils.h"
#include "ast/utility/Visitor.h"
#include "souffle/datastructure/Graph.h"
#include "souffle/utility/MiscUtil.h"
#include <functional>
#include <memory>
Expand Down
6 changes: 6 additions & 0 deletions src/include/souffle/RecordTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include "souffle/RamTypes.h"
#include "souffle/utility/span.h"

#include <functional>
#include <initializer_list>

namespace souffle {
Expand All @@ -35,6 +37,10 @@ class RecordTable {
virtual RamDomain pack(const std::initializer_list<RamDomain>& List) = 0;

virtual const RamDomain* unpack(const RamDomain Ref, const std::size_t Arity) const = 0;

/// Enumerate each record.
virtual void enumerate(const std::function<void(const RamDomain* /*tuple*/, std::size_t /* arity*/,
RamDomain /* key */)>& Callback) const = 0;
};

/** @brief helper to convert tuple to record reference for the synthesiser */
Expand Down
Loading

0 comments on commit b7a5354

Please sign in to comment.