diff --git a/.github/workflows/conformance.yml b/.github/workflows/conformance.yml new file mode 100644 index 000000000..7de041162 --- /dev/null +++ b/.github/workflows/conformance.yml @@ -0,0 +1,18 @@ +name: Conformance + +on: + push: + branches: [master] + pull_request: + types: [opened, synchronize, reopened] + +jobs: + Formatting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - name: Format with clang-format + run: .github/workflows/scripts/format_cpp.sh + diff --git a/.github/workflows/scripts/format_cpp.sh b/.github/workflows/scripts/format_cpp.sh new file mode 100755 index 000000000..2026e47c9 --- /dev/null +++ b/.github/workflows/scripts/format_cpp.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -o pipefail + +find ./compiler/{include,lib,src} \( -iname "*.h" -o -iname "*.cpp" -o -iname "*.cc" \) | xargs clang-format -i -style='file' +if [ $? -ne 0 ] +then + exit 1 +fi + +# show changes if any +git diff +# fail if there is a diff, success otherwise +! ( git diff | grep -q ^ ) || exit 1 diff --git a/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.h b/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.h index f5f6f9d50..59657148d 100644 --- a/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.h +++ b/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.h @@ -3,8 +3,8 @@ #include #include -#include #include +#include #include "zamalang/Dialect/HLFHE/IR/HLFHETypes.h" diff --git a/compiler/include/zamalang/Dialect/MidLFHE/IR/MidLFHEOps.h b/compiler/include/zamalang/Dialect/MidLFHE/IR/MidLFHEOps.h index d03ac9704..8affb8457 100644 --- a/compiler/include/zamalang/Dialect/MidLFHE/IR/MidLFHEOps.h +++ b/compiler/include/zamalang/Dialect/MidLFHE/IR/MidLFHEOps.h @@ -1,12 +1,11 @@ #ifndef ZAMALANG_DIALECT_MidLFHE_MidLFHE_OPS_H #define ZAMALANG_DIALECT_MidLFHE_MidLFHE_OPS_H +#include #include #include -#include #include -#include - +#include #include "zamalang/Dialect/MidLFHE/IR/MidLFHETypes.h" diff --git a/compiler/lib/Dialect/HLFHE/IR/HLFHEDialect.cpp b/compiler/lib/Dialect/HLFHE/IR/HLFHEDialect.cpp index d02b15743..9804e05b8 100644 --- a/compiler/lib/Dialect/HLFHE/IR/HLFHEDialect.cpp +++ b/compiler/lib/Dialect/HLFHE/IR/HLFHEDialect.cpp @@ -14,23 +14,22 @@ void HLFHEDialect::initialize() { >(); addTypes< - #define GET_TYPEDEF_LIST - #include "zamalang/Dialect/HLFHE/IR/HLFHEOpsTypes.cpp.inc" - >(); +#define GET_TYPEDEF_LIST +#include "zamalang/Dialect/HLFHE/IR/HLFHEOpsTypes.cpp.inc" + >(); } -::mlir::Type HLFHEDialect::parseType(::mlir::DialectAsmParser &parser) const -{ - if(parser.parseKeyword("eint").failed()) +::mlir::Type HLFHEDialect::parseType(::mlir::DialectAsmParser &parser) const { + if (parser.parseKeyword("eint").failed()) return ::mlir::Type(); return EncryptedIntegerType::parse(this->getContext(), parser); } void HLFHEDialect::printType(::mlir::Type type, - ::mlir::DialectAsmPrinter &printer) const -{ - mlir::zamalang::HLFHE::EncryptedIntegerType eint = type.dyn_cast_or_null(); + ::mlir::DialectAsmPrinter &printer) const { + mlir::zamalang::HLFHE::EncryptedIntegerType eint = + type.dyn_cast_or_null(); if (eint != nullptr) { eint.print(printer); return; diff --git a/compiler/lib/Dialect/HLFHE/IR/HLFHEOps.cpp b/compiler/lib/Dialect/HLFHE/IR/HLFHEOps.cpp index 13c487a60..9576dbeae 100644 --- a/compiler/lib/Dialect/HLFHE/IR/HLFHEOps.cpp +++ b/compiler/lib/Dialect/HLFHE/IR/HLFHEOps.cpp @@ -3,26 +3,26 @@ #include "zamalang/Dialect/HLFHE/IR/HLFHEOps.h" #include "zamalang/Dialect/HLFHE/IR/HLFHETypes.h" - -namespace mlir{ -namespace zamalang{ - bool predApplyUnivariateRegion(::mlir::Region ®ion){ - if (region.getBlocks().size() != 1) { - return false; - } - auto args = region.getBlocks().front().getArguments(); - if (args.size() != 1) { - return false; - } - if (! args.front().getType().isa()){ - return false; - } - //TODO: need to handle when there is no terminator - auto terminator = region.getBlocks().front().getTerminator(); - return terminator->getName().getStringRef().equals("HLFHE.apply_univariate_return"); - } -} +namespace mlir { +namespace zamalang { +bool predApplyUnivariateRegion(::mlir::Region ®ion) { + if (region.getBlocks().size() != 1) { + return false; + } + auto args = region.getBlocks().front().getArguments(); + if (args.size() != 1) { + return false; + } + if (!args.front().getType().isa()) { + return false; + } + // TODO: need to handle when there is no terminator + auto terminator = region.getBlocks().front().getTerminator(); + return terminator->getName().getStringRef().equals( + "HLFHE.apply_univariate_return"); } +} // namespace zamalang +} // namespace mlir #define GET_OP_CLASSES #include "zamalang/Dialect/HLFHE/IR/HLFHEOps.cpp.inc" diff --git a/compiler/lib/Dialect/MidLFHE/IR/MidLFHEDialect.cpp b/compiler/lib/Dialect/MidLFHE/IR/MidLFHEDialect.cpp index 554b9aa1c..1373d779d 100644 --- a/compiler/lib/Dialect/MidLFHE/IR/MidLFHEDialect.cpp +++ b/compiler/lib/Dialect/MidLFHE/IR/MidLFHEDialect.cpp @@ -9,56 +9,59 @@ using namespace mlir::zamalang::MidLFHE; void MidLFHEDialect::initialize() { addOperations< - #define GET_OP_LIST - #include "zamalang/Dialect/MidLFHE/IR/MidLFHEOps.cpp.inc" - >(); +#define GET_OP_LIST +#include "zamalang/Dialect/MidLFHE/IR/MidLFHEOps.cpp.inc" + >(); addTypes< - #define GET_TYPEDEF_LIST - #include "zamalang/Dialect/MidLFHE/IR/MidLFHEOpsTypes.cpp.inc" - >(); +#define GET_TYPEDEF_LIST +#include "zamalang/Dialect/MidLFHE/IR/MidLFHEOpsTypes.cpp.inc" + >(); } -::mlir::Type MidLFHEDialect::parseType(::mlir::DialectAsmParser &parser) const -{ - if(parser.parseOptionalKeyword("lwe").succeeded()) +::mlir::Type MidLFHEDialect::parseType(::mlir::DialectAsmParser &parser) const { + if (parser.parseOptionalKeyword("lwe").succeeded()) return LWECipherTextType::parse(this->getContext(), parser); - if(parser.parseOptionalKeyword("glwe").succeeded()) + if (parser.parseOptionalKeyword("glwe").succeeded()) return GLWECipherTextType::parse(this->getContext(), parser); - if(parser.parseOptionalKeyword("ggsw").succeeded()) + if (parser.parseOptionalKeyword("ggsw").succeeded()) return GGSWCipherTextType::parse(this->getContext(), parser); - if(parser.parseOptionalKeyword("ciphertext").succeeded()) + if (parser.parseOptionalKeyword("ciphertext").succeeded()) return AnyCipherTextType::parse(this->getContext(), parser); - if(parser.parseOptionalKeyword("ksk").succeeded()) + if (parser.parseOptionalKeyword("ksk").succeeded()) return KeySwitchingKeyType::parse(this->getContext(), parser); parser.emitError(parser.getCurrentLocation(), "Unknown MidLFHE type"); return ::mlir::Type(); } void MidLFHEDialect::printType(::mlir::Type type, - ::mlir::DialectAsmPrinter &printer) const -{ - mlir::zamalang::MidLFHE::LWECipherTextType lwe = type.dyn_cast_or_null(); + ::mlir::DialectAsmPrinter &printer) const { + mlir::zamalang::MidLFHE::LWECipherTextType lwe = + type.dyn_cast_or_null(); if (lwe != nullptr) { lwe.print(printer); return; } - mlir::zamalang::MidLFHE::GLWECipherTextType glwe = type.dyn_cast_or_null(); + mlir::zamalang::MidLFHE::GLWECipherTextType glwe = + type.dyn_cast_or_null(); if (glwe != nullptr) { glwe.print(printer); return; } - mlir::zamalang::MidLFHE::GGSWCipherTextType ggsw = type.dyn_cast_or_null(); + mlir::zamalang::MidLFHE::GGSWCipherTextType ggsw = + type.dyn_cast_or_null(); if (ggsw != nullptr) { ggsw.print(printer); return; } - mlir::zamalang::MidLFHE::KeySwitchingKeyType ksk = type.dyn_cast_or_null(); + mlir::zamalang::MidLFHE::KeySwitchingKeyType ksk = + type.dyn_cast_or_null(); if (ksk != nullptr) { ksk.print(printer); return; } - mlir::zamalang::MidLFHE::AnyCipherTextType any = type.dyn_cast_or_null(); + mlir::zamalang::MidLFHE::AnyCipherTextType any = + type.dyn_cast_or_null(); if (any != nullptr) { any.print(printer); return; diff --git a/compiler/lib/Dialect/MidLFHE/IR/MidLFHEOps.cpp b/compiler/lib/Dialect/MidLFHE/IR/MidLFHEOps.cpp index a1f823fff..f733d9c8d 100644 --- a/compiler/lib/Dialect/MidLFHE/IR/MidLFHEOps.cpp +++ b/compiler/lib/Dialect/MidLFHE/IR/MidLFHEOps.cpp @@ -3,20 +3,20 @@ #include "zamalang/Dialect/MidLFHE/IR/MidLFHEOps.h" #include "zamalang/Dialect/MidLFHE/IR/MidLFHETypes.h" -namespace mlir{ -namespace zamalang{ - bool predPBSRegion(::mlir::Region ®ion){ - if (region.getBlocks().size() != 1) { - return false; - } - auto args = region.getBlocks().front().getArguments(); - if (args.size() != 1) { - return false; - } - return args.front().getType().isa(); - } -} +namespace mlir { +namespace zamalang { +bool predPBSRegion(::mlir::Region ®ion) { + if (region.getBlocks().size() != 1) { + return false; + } + auto args = region.getBlocks().front().getArguments(); + if (args.size() != 1) { + return false; + } + return args.front().getType().isa(); } +} // namespace zamalang +} // namespace mlir #define GET_OP_CLASSES #include "zamalang/Dialect/MidLFHE/IR/MidLFHEOps.cpp.inc" diff --git a/compiler/src/main.cpp b/compiler/src/main.cpp index 708d5c4d0..2d29f5ec0 100644 --- a/compiler/src/main.cpp +++ b/compiler/src/main.cpp @@ -11,52 +11,54 @@ #include "zamalang/Dialect/MidLFHE/IR/MidLFHETypes.h" struct CommandLineArgs { - std::vector inputs; - std::string output; + std::vector inputs; + std::string output; }; -void parseCommandLine(int argc, char** argv, CommandLineArgs* args) -{ - try { - TCLAP::CmdLine cmd("zamacompiler", ' ', "0.0.1"); - // Input file names - TCLAP::UnlabeledMultiArg fileNames("file", "The input files", false, "file"); - cmd.add(fileNames); +void parseCommandLine(int argc, char **argv, CommandLineArgs *args) { + try { + TCLAP::CmdLine cmd("zamacompiler", ' ', "0.0.1"); + // Input file names + TCLAP::UnlabeledMultiArg fileNames("file", "The input files", + false, "file"); + cmd.add(fileNames); - // Output - TCLAP::ValueArg output("o","out","Place the output into the ",false, "","string"); - cmd.add(output); + // Output + TCLAP::ValueArg output( + "o", "out", "Place the output into the ", false, "", "string"); + cmd.add(output); - cmd.parse( argc, argv ); - args->output = output.getValue(); - args->inputs = fileNames.getValue(); + cmd.parse(argc, argv); + args->output = output.getValue(); + args->inputs = fileNames.getValue(); - } catch (TCLAP::ArgException &e) // catch exceptions - { - std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; - std::exit(1); - } + } catch (TCLAP::ArgException &e) // catch exceptions + { + std::cerr << "error: " << e.error() << " for arg " << e.argId() + << std::endl; + std::exit(1); + } } int main(int argc, char **argv) { - // Parse command line arguments - CommandLineArgs cmdLineArgs; - parseCommandLine(argc, argv, &cmdLineArgs); + // Parse command line arguments + CommandLineArgs cmdLineArgs; + parseCommandLine(argc, argv, &cmdLineArgs); - // Initialize the MLIR context - mlir::MLIRContext context; - // Load our Dialect in this MLIR Context. - context.getOrLoadDialect(); - context.getOrLoadDialect(); - context.getOrLoadDialect(); + // Initialize the MLIR context + mlir::MLIRContext context; + // Load our Dialect in this MLIR Context. + context.getOrLoadDialect(); + context.getOrLoadDialect(); + context.getOrLoadDialect(); - // For all input file, parse and dump - for (const auto& fileName: cmdLineArgs.inputs) { - auto module = mlir::parseSourceFile(fileName, &context); - if(!module) { - exit(1); - } - module->dump(); + // For all input file, parse and dump + for (const auto &fileName : cmdLineArgs.inputs) { + auto module = mlir::parseSourceFile(fileName, &context); + if (!module) { + exit(1); } - return 0; + module->dump(); + } + return 0; }