From d4b7d61f99dd25e4ea13504f262158f8c33aeea4 Mon Sep 17 00:00:00 2001 From: Quentin Bourgerie Date: Mon, 24 May 2021 09:50:27 +0200 Subject: [PATCH] chore(compiler): Add configuration of test and introduce command line options --- compiler/CMakeLists.txt | 2 ++ compiler/Makefile | 8 +++++ compiler/src/CMakeLists.txt | 2 +- compiler/src/main.cpp | 61 ++++++++++++++++++++++++++----------- compiler/tests/lit.cfg.py | 15 +++++++++ 5 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 compiler/Makefile create mode 100644 compiler/tests/lit.cfg.py diff --git a/compiler/CMakeLists.txt b/compiler/CMakeLists.txt index db1a936fa..08d668e31 100644 --- a/compiler/CMakeLists.txt +++ b/compiler/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.13) project(zamacompiler LANGUAGES CXX) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + set(CMAKE_CXX_STANDARD 14) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") diff --git a/compiler/Makefile b/compiler/Makefile new file mode 100644 index 000000000..2f95b8096 --- /dev/null +++ b/compiler/Makefile @@ -0,0 +1,8 @@ +build: + cmake -B build . -DLLVM_DIR=${LLVM_PROJECT}/build/lib/cmake/llvm -DMLIR_DIR=${LLVM_PROJECT}/build/lib/cmake/mlir + +zamacompiler: + make -C build/ zamacompiler + +test: + ${LLVM_PROJECT}/build/bin/llvm-lit -v tests/ \ No newline at end of file diff --git a/compiler/src/CMakeLists.txt b/compiler/src/CMakeLists.txt index eebc241da..a5aeece26 100644 --- a/compiler/src/CMakeLists.txt +++ b/compiler/src/CMakeLists.txt @@ -1,5 +1,5 @@ add_llvm_tool(zamacompiler main.cpp) - +target_compile_options(zamacompiler PRIVATE -fexceptions) llvm_update_compile_flags(zamacompiler) target_link_libraries(zamacompiler PRIVATE diff --git a/compiler/src/main.cpp b/compiler/src/main.cpp index a9cebca23..af02ee933 100644 --- a/compiler/src/main.cpp +++ b/compiler/src/main.cpp @@ -1,31 +1,56 @@ #include +#include + #include #include #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 inputs; + std::string output; +}; - // Load our Dialect in this MLIR Context. - context.getOrLoadDialect(); - context.getOrLoadDialect(); +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); - if(argc != 2) { - std::cerr << "Usage: " << argv[0] << " filename" << std::endl; - return 1; - } + // Output + TCLAP::ValueArg output("o","out","Place the output into the ",false, "","string"); + cmd.add(output); - auto module = mlir::parseSourceFile(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(); + context.getOrLoadDialect(); + + // For all input file, parse and dump + for (const auto& fileName: cmdLineArgs.inputs) { + auto module = mlir::parseSourceFile(fileName, &context); + module->dump(); + } + return 0; } diff --git a/compiler/tests/lit.cfg.py b/compiler/tests/lit.cfg.py new file mode 100644 index 000000000..7dfb379b9 --- /dev/null +++ b/compiler/tests/lit.cfg.py @@ -0,0 +1,15 @@ +import lit.formats + +# Lit configuration +config.name = "zamalang" +config.test_format = lit.formats.ShTest("0") +config.suffixes = {".mlir"} +config.target_triple = "" + +# Set the llvm +config.environment['PATH'] = os.pathsep.join([ + os.path.join(os.path.dirname(os.path.dirname(__file__)), "build", "bin"), + os.path.join(os.environ['LLVM_PROJECT'], "build", "bin"), + config.environment['PATH']] +) +print(config.environment['PATH']) \ No newline at end of file