mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 03:55:04 -05:00
feat(compiler): Let zamacompiler parse an MLIR source file and dump the in-memory representation
This commit is contained in:
committed by
Quentin Bourgerie
parent
32340d3ec0
commit
788adcbbae
@@ -1,54 +1,31 @@
|
||||
#include <mlir/Dialect/StandardOps/IR/Ops.h>
|
||||
#include <mlir/IR/Builders.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <mlir/Dialect/StandardOps/IR/Ops.h>
|
||||
#include <mlir/Parser.h>
|
||||
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "zamalang/Dialect/HLFHE/IR/HLFHEDialect.h"
|
||||
#include "zamalang/Dialect/HLFHE/IR/HLFHEOps.h"
|
||||
#include "zamalang/Dialect/HLFHE/IR/HLFHETypes.h"
|
||||
|
||||
mlir::FuncOp buildFunction(mlir::OpBuilder &builder) {
|
||||
mlir::FunctionType func_type = builder.getFunctionType({ mlir::zamalang::HLFHE::EncryptedIntegerType::get(builder.getContext(), 32) }, llvm::None);
|
||||
|
||||
mlir::FuncOp funcOp =
|
||||
mlir::FuncOp::create(builder.getUnknownLoc(), "hlfhe", func_type);
|
||||
|
||||
mlir::FuncOp function(funcOp);
|
||||
mlir::Block &entryBlock = *function.addEntryBlock();
|
||||
builder.setInsertionPointToStart(&entryBlock);
|
||||
|
||||
mlir::Value v1 = builder.create<mlir::ConstantFloatOp>(
|
||||
builder.getUnknownLoc(),
|
||||
llvm::APFloat(llvm::APFloat::IEEEsingle(), "1.0"),
|
||||
builder.getF32Type());
|
||||
|
||||
// TODO: create v2 as EncryptedInteger and add it with v1
|
||||
|
||||
// mlir::Value v2 =
|
||||
// builder.create<mlir::zamalang::HLFHE::EncryptedIntegerType>(
|
||||
// builder.getUnknownLoc());
|
||||
|
||||
mlir::Value c1 = builder.create<mlir::zamalang::HLFHE::AddEintIntOp>(
|
||||
builder.getUnknownLoc(), v1, v1);
|
||||
|
||||
builder.create<mlir::ReturnOp>(builder.getUnknownLoc());
|
||||
|
||||
return funcOp;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
mlir::MLIRContext context;
|
||||
mlir::MLIRContext context;
|
||||
|
||||
// Load our Dialect in this MLIR Context.
|
||||
context.getOrLoadDialect<mlir::zamalang::HLFHE::HLFHEDialect>();
|
||||
context.getOrLoadDialect<mlir::StandardOpsDialect>();
|
||||
// Load our Dialect in this MLIR Context.
|
||||
context.getOrLoadDialect<mlir::zamalang::HLFHE::HLFHEDialect>();
|
||||
context.getOrLoadDialect<mlir::StandardOpsDialect>();
|
||||
|
||||
mlir::OpBuilder builder(&context);
|
||||
if(argc != 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " filename" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
mlir::ModuleOp module = mlir::ModuleOp::create(builder.getUnknownLoc());
|
||||
auto module = mlir::parseSourceFile<mlir::ModuleOp>(argv[1], &context);
|
||||
|
||||
module.push_back(buildFunction(builder));
|
||||
if (!module) {
|
||||
std::cerr << "Could not parse module" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
module.dump();
|
||||
module->dump();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user