refactor(compiler): Use LLVM command line parser instead of tclap

LLVM already provides a command line parser, covering the use of tclap
in the sources. This patch uses the LLVM command line parser instead
of tclap and thus reduces the number of external dependencies.
This commit is contained in:
Andi Drebes
2021-06-07 15:48:35 +02:00
committed by Quentin Bourgerie
parent eef82a4713
commit 2c4748b414

View File

@@ -1,7 +1,8 @@
#include <iostream>
#include <tclap/CmdLine.h>
#include <llvm/Support/CommandLine.h>
#include <memory>
#include <mlir/Dialect/StandardOps/IR/Ops.h>
#include <mlir/Parser.h>
@@ -10,50 +11,30 @@
#include "zamalang/Dialect/MidLFHE/IR/MidLFHEDialect.h"
#include "zamalang/Dialect/MidLFHE/IR/MidLFHETypes.h"
struct CommandLineArgs {
std::vector<std::string> inputs;
std::string output;
};
namespace cmdline {
llvm::cl::list<std::string> inputs(llvm::cl::Positional,
llvm::cl::desc("<Input files>"),
llvm::cl::OneOrMore);
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);
// Output
TCLAP::ValueArg<std::string> output(
"o", "out", "Place the output into the <file>", false, "", "string");
cmd.add(output);
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);
}
}
llvm::cl::opt<std::string> output("o",
llvm::cl::desc("Specify output filename"),
llvm::cl::value_desc("filename"));
}; // namespace cmdline
int main(int argc, char **argv) {
// Parse command line arguments
CommandLineArgs cmdLineArgs;
parseCommandLine(argc, argv, &cmdLineArgs);
llvm::cl::ParseCommandLineOptions(argc, argv);
// Initialize the MLIR context
mlir::MLIRContext context;
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::zamalang::HLFHE::HLFHEDialect>();
context.getOrLoadDialect<mlir::zamalang::MidLFHE::MidLFHEDialect>();
context.getOrLoadDialect<mlir::StandardOpsDialect>();
// For all input file, parse and dump
for (const auto &fileName : cmdLineArgs.inputs) {
for (const auto &fileName : cmdline::inputs) {
auto module = mlir::parseSourceFile<mlir::ModuleOp>(fileName, &context);
if (!module) {
exit(1);