matthewbdwyer / tipc

A compiler from TIP to llvm bitcode
MIT License
65 stars 39 forks source link

`llc`-style bitcode validation #72

Closed joek13 closed 3 months ago

joek13 commented 1 year ago

This issue is a continuation of a discussion started in class on Tue, Nov 22.

While extending codegen for the class project, I sometimes make mistakes and my compiler erroneously emits invalid bitcode. In these situations tipc exits successfully, but linking the malformed .bc fails with the enigmatic error: Invalid record (Producer: 'LLVM14.0.6' Reader: 'LLVM 14.0.6').

In these cases I can often get a more descriptive error message by running ./bin/build.sh --asm problem.tip && llc problem.tip.ll.

Would it be possible to integrate llc-style bitcode validation in tipc? That way invalid bitcode is caught by tipc and we can emit a more informative error message instead of waiting for linking to fail.

matthewbdwyer commented 1 year ago

There is a call to LLVM::verifyModule at the end of ASTProgram::codegen(), but it does not have the functionality described above. I'll have to look at how "llc" initiates its analysis to see if we can run that process just before returning.

matthewbdwyer commented 3 months ago

We have a new version of the verifyModule logic that reports more granular error messages. Hopefully this resolves the issue, but we did not inject a codegen error to test it.