From 0e4778c4f6608b0b34ce63c41aeb289f1f451ea0 Mon Sep 17 00:00:00 2001 From: Alex Cameron Date: Wed, 19 Aug 2026 00:54:19 +0000 Subject: [PATCH] feat(compiler): expose source locations in IR dumps --- test/CMakeLists.txt | 2 +- test/Conversion/ForthToGPU/invalid-intrinsic.mlir | 4 ++-- test/Pipeline/source-locations.forth | 12 ++++++++++++ test/lit.cfg.py | 3 +++ tools/warpforthc/warpforthc.cpp | 6 +++++- 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 test/Pipeline/source-locations.forth diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a4ba6f2..e9b0e92 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,6 +6,6 @@ configure_file( add_custom_target(check-warpforth COMMAND ${LIT_COMMAND} ${CMAKE_CURRENT_BINARY_DIR} -v - DEPENDS warpforth-translate warpforth-opt + DEPENDS warpforth-translate warpforth-opt warpforthc COMMENT "Running WarpForth lit tests" ) diff --git a/test/Conversion/ForthToGPU/invalid-intrinsic.mlir b/test/Conversion/ForthToGPU/invalid-intrinsic.mlir index c32e0e6..f961e94 100644 --- a/test/Conversion/ForthToGPU/invalid-intrinsic.mlir +++ b/test/Conversion/ForthToGPU/invalid-intrinsic.mlir @@ -2,11 +2,11 @@ // RUN: %FileCheck %s < %t.err // RUN: test ! -s %t.out -// CHECK: failed to legalize operation 'forth.intrinsic' +// CHECK: invalid-intrinsic.forth:12:7: error: failed to legalize operation 'forth.intrinsic' module { func.func private @main() attributes {forth.kernel} { - %0 = forth.intrinsic "unknown" : index + %0 = forth.intrinsic "unknown" : index loc("invalid-intrinsic.forth":12:7) return } } diff --git a/test/Pipeline/source-locations.forth b/test/Pipeline/source-locations.forth new file mode 100644 index 0000000..1df9860 --- /dev/null +++ b/test/Pipeline/source-locations.forth @@ -0,0 +1,12 @@ +\ RUN: %warpforth-translate --forth-to-mlir --mlir-print-debuginfo %s | %FileCheck %s --check-prefix=FORTH +\ RUN: %warpforthc --mlir-print-ir-after=convert-forth-to-memref --mlir-print-debuginfo --mlir-disable-threading %s -o %t.ptx 2>&1 | %FileCheck %s --check-prefix=LOWERED + +\! kernel main +42 + +\ FORTH: forth.constant %{{.*}}(42 : i64) {{.*}} loc([[FORTH_LOC:#loc[0-9]+]]) +\ FORTH: [[FORTH_LOC]] = loc("{{.*}}source-locations.forth":5:1) + +\ LOWERED: IR Dump After ConvertForthToMemRef (convert-forth-to-memref) +\ LOWERED: arith.constant 42 : i64 loc([[LOWERED_LOC:#loc[0-9]+]]) +\ LOWERED: [[LOWERED_LOC]] = loc("{{.*}}source-locations.forth":5:1) diff --git a/test/lit.cfg.py b/test/lit.cfg.py index e07b302..4e78141 100644 --- a/test/lit.cfg.py +++ b/test/lit.cfg.py @@ -13,6 +13,9 @@ config.substitutions.append( ("%warpforth-opt", os.path.join(config.warpforth_bin_root, "bin", "warpforth-opt")) ) +config.substitutions.append( + ("%warpforthc", os.path.join(config.warpforth_bin_root, "bin", "warpforthc")) +) config.substitutions.append( ("%FileCheck", config.filecheck_path) ) diff --git a/tools/warpforthc/warpforthc.cpp b/tools/warpforthc/warpforthc.cpp index aaf3c1b..5313871 100644 --- a/tools/warpforthc/warpforthc.cpp +++ b/tools/warpforthc/warpforthc.cpp @@ -12,6 +12,7 @@ #include "mlir/Dialect/ControlFlow/IR/ControlFlow.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" +#include "mlir/IR/AsmState.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/Diagnostics.h" #include "mlir/IR/MLIRContext.h" @@ -44,7 +45,9 @@ static llvm::cl::opt int main(int argc, char **argv) { llvm::InitLLVM y(argc, argv); + warpforth::registerConversionPasses(); registerMLIRContextCLOptions(); + registerAsmPrinterCLOptions(); registerPassManagerCLOptions(); llvm::cl::ParseCommandLineOptions(argc, argv, "WarpForth compiler: Forth to PTX\n"); @@ -88,7 +91,8 @@ int main(int argc, char **argv) { // Run the compilation pipeline PassManager pm(&context); - (void)applyPassManagerCLOptions(pm); + if (failed(applyPassManagerCLOptions(pm))) + return 1; warpforth::buildWarpForthPipeline(pm); if (failed(pm.run(*module))) { llvm::errs() << "error: compilation pipeline failed\n";