chore(compiler): Add configuration of test and introduce command line options

This commit is contained in:
Quentin Bourgerie
2021-05-24 09:50:27 +02:00
parent 0b86ed0c2c
commit d4b7d61f99
5 changed files with 69 additions and 19 deletions

View File

@@ -1,31 +1,56 @@
#include <iostream>
#include <tclap/CmdLine.h>
#include <mlir/Dialect/StandardOps/IR/Ops.h>
#include <mlir/Parser.h>
#include "zamalang/Dialect/HLFHE/IR/HLFHEDialect.h"
#include "zamalang/Dialect/HLFHE/IR/HLFHETypes.h"
int main(int argc, char **argv) {
mlir::MLIRContext context;
struct CommandLineArgs {
std::vector<std::string> inputs;
std::string output;
};
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::zamalang::HLFHE::HLFHEDialect>();
context.getOrLoadDialect<mlir::StandardOpsDialect>();
void parseCommandLine(int argc, char** argv, CommandLineArgs* args)
{
try {
TCLAP::CmdLine cmd("zamacompiler", ' ', "0.0.1");
// Input file names
TCLAP::UnlabeledMultiArg<std::string> fileNames("file", "The input files", false, "file");
cmd.add(fileNames);
if(argc != 2) {
std::cerr << "Usage: " << argv[0] << " filename" << std::endl;
return 1;
}
// Output
TCLAP::ValueArg<std::string> output("o","out","Place the output into the <file>",false, "","string");
cmd.add(output);
auto module = mlir::parseSourceFile<mlir::ModuleOp>(argv[1], &context);
cmd.parse( argc, argv );
args->output = output.getValue();
args->inputs = fileNames.getValue();
if (!module) {
std::cerr << "Could not parse module" << std::endl;
return 1;
}
module->dump();
return 0;
} 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);
// Initialize the MLIR context
mlir::MLIRContext context;
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::zamalang::HLFHE::HLFHEDialect>();
context.getOrLoadDialect<mlir::StandardOpsDialect>();
// For all input file, parse and dump
for (const auto& fileName: cmdLineArgs.inputs) {
auto module = mlir::parseSourceFile<mlir::ModuleOp>(fileName, &context);
module->dump();
}
return 0;
}