#include "LumeLib.h" #include #include #include #include #include #include #include #include #include #include #include #include #include namespace { llvm::cl::opt inputFilename( llvm::cl::Positional, llvm::cl::desc(""), llvm::cl::init("-")); llvm::cl::opt outputFilename( "o", llvm::cl::desc("Output file (default: stdout)"), llvm::cl::value_desc("filename"), llvm::cl::init("-")); llvm::cl::opt dumpMLIR( "dump-mlir", llvm::cl::desc("Dump the SPIR-V MLIR dialect"), llvm::cl::init(false)); llvm::cl::opt dumpAll( "dump-all", llvm::cl::desc("Dump all dialects and LLVM IR"), llvm::cl::init(false)); } int main(int argc, char **argv) { llvm::InitLLVM initLLVM(argc, argv); llvm::cl::ParseCommandLineOptions(argc, argv, "Lume Compiler - SPIR-V to LLVM"); mlir::registerFromSPIRVTranslation(); std::string errorMessage; auto input = mlir::openInputFile(inputFilename, &errorMessage); if (!input) { llvm::errs() << "Error: " << errorMessage << '\n'; return 1; } mlir::MLIRContext context; context.loadDialect(); context.loadDialect(); mlir::spirv::DeserializationOptions options; auto spvModule = lume::CompileSPVToMLIR(std::move(input), context, options); if (!spvModule) { llvm::errs() << "Error: Failed to deserialize SPIR-V binary\n"; return 1; } mlir::OpBuilder builder(&context); auto topModule = mlir::ModuleOp::create(builder.getUnknownLoc()); topModule.getBody()->push_back(spvModule.release()); if (dumpMLIR || dumpAll) { llvm::errs() << "=== MLIR SPIR-V Dialect ===\n"; topModule.dump(); llvm::errs() << "\n"; } if (llvm::failed(lume::ConvertSPVDialectToLLVMDialect(context, &topModule))) { llvm::errs() << "Error: Failed to convert SPIR-V dialect to LLVM dialect\n"; return 1; } if (dumpMLIR || dumpAll) { llvm::errs() << "=== MLIR LLVM Dialect ===\n"; topModule.dump(); llvm::errs() << "\n"; } if (outputFilename != "-") { auto output = mlir::openOutputFile(outputFilename, &errorMessage); if (!output) { llvm::errs() << "Error: " << errorMessage << '\n'; return 1; } topModule.print(output->os()); output->keep(); } else if (!dumpMLIR && !dumpAll) { topModule.print(llvm::outs()); } return 0; }