feat(compiler): Add !HLFHE.ciphertext

This commit is contained in:
Quentin Bourgerie
2021-05-25 14:42:29 +02:00
parent ce69aab756
commit 0b41018ade
3 changed files with 44 additions and 0 deletions

View File

@@ -1,6 +1,8 @@
#ifndef ZAMALANG_DIALECT_MidLFHE_IR_MidLFHE_TYPES
#define ZAMALANG_DIALECT_MidLFHE_IR_MidLFHE_TYPES
// TODO: MLWE / GSW
include "zamalang/Dialect/MidLFHE/IR/MidLFHEDialect.td"
class MidLFHE_Type<string name> : TypeDef<MidLFHE_Dialect, name> { }
@@ -112,4 +114,31 @@ def GGSWCipherTextType : MidLFHE_Type<"GGSWCipherText"> {
}];
}
def AnyCipherTextType : MidLFHE_Type<"AnyCipherText"> {
let mnemonic = "ciphertext";
let summary = "Any cipher text";
let description = [{
Any cipher text
}];
// We define the printer inline.
let printer = [{
$_printer << "ciphertext";
}];
// The parser is defined here also.
let parser = [{
return get($_ctxt);
}];
}
def CipherTextType: TypeConstraint<Or<[
LWECipherTextType.predicate,
GLWECipherTextType.predicate,
GGSWCipherTextType.predicate,
AnyCipherTextType.predicate,
]>, "ciphertext-like">;
#endif

View File

@@ -27,6 +27,9 @@ void MidLFHEDialect::initialize() {
return GLWECipherTextType::parse(this->getContext(), parser);
if(parser.parseOptionalKeyword("ggsw").succeeded())
return GGSWCipherTextType::parse(this->getContext(), parser);
if(parser.parseOptionalKeyword("ciphertext").succeeded())
return AnyCipherTextType::parse(this->getContext(), parser);
parser.emitError(parser.getCurrentLocation(), "Unknown MidLFHE type");
return ::mlir::Type();
}
@@ -48,6 +51,11 @@ void MidLFHEDialect::printType(::mlir::Type type,
ggsw.print(printer);
return;
}
mlir::zamalang::MidLFHE::AnyCipherTextType any = type.dyn_cast_or_null<mlir::zamalang::MidLFHE::AnyCipherTextType>();
if (any != nullptr) {
any.print(printer);
return;
}
// TODO - What should be done here?
printer << "unknwontype";
}

View File

@@ -0,0 +1,7 @@
// RUN: zamacompiler %s 2>&1| FileCheck %s
// CHECK-LABEL: func @ciphertext(%arg0: !MidLFHE.ciphertext) -> !MidLFHE.ciphertext
func @ciphertext(%arg0: !MidLFHE.ciphertext) -> !MidLFHE.ciphertext {
// CHECK-LABEL: return %arg0 : !MidLFHE.ciphertext
return %arg0: !MidLFHE.ciphertext
}