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

@@ -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")

8
compiler/Makefile Normal file
View File

@@ -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/

View File

@@ -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

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;
}

15
compiler/tests/lit.cfg.py Normal file
View File

@@ -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'])