I’ve been working for some time on the Eclair compiler (written in Haskell) and I am now at the point where I need to test the LLVM IR my compiler is generating.
How would you approach testing this generated code? I can’t seem to think of a straight-forward way of doing this. The best way I can think of is to:
Generate the LLVM IR
Compile it with clang to object code and link it with a C test harness (yikes)
Invoke that C test program in Haskell via tasty/hspec
… but this seems like an awful lot of setup?
I’m also considering writing a Haskell test harness (using FFI), but I fear that might result in a cabal file with a massive amount of test executables (I need to test a lot of separate things in the runtime)?
I’m wondering how others would solve this problem?
Llvm uses FileCheck for this. The AArch64 had and the Riscv backend has a small test driver that use filecheck to assert the produced output for basic compilation. On a higher level you want to run full compilation pipelines and assert their functionality/output.
This isn’t possible in my case, my whole runtime is generated each compilation, and is more like a library (It requires an external language to call into my language).
FileCheck could help as a part of the puzzle, but I think I’d still need a test harness to call certain functions in the runtime. (Preferably I’d generate a simplified version of some of the runtime data structures, but that requires Haskell code to specifically generate only that part of the code.)