Closed adi-lb-phoenix closed 4 months ago
@GlowingScrewdriver: this seems to happen when only thing in a function body is a for loop. break label in for
will not have any instructions then.
This is related to #31. The easiest way to work around this is by inserting a return statement outside the for loop, at the end of the function
I don't think is really about implicit returns. It's about having empty label when there's no statement following a for. We can very much have return inside the for and still have this error.
Alright, perhaps implicit returns is not the correct word. The main problem here is an unterminated basic block.
The issue here is an unterminated basic block. My solution would be to use LLVM's unreachable
instruction to mark an empty BB as terminated.
Look at how C's LLVM code generator deals with this and adopt that solution.
Okay, Clang's approach is pretty smart. There is one variable dedicated to holding the return value of a function. When a C return statement appears, the return variable is assigned, and control jumps to the last basic block. The last basic block contains an LLVM ret
instruction that returns the return variable.
Makes a lot of sense. I'll refactor C-Lisp to do it this way.
When the output from
$ guile ../../utils/sexp-json.scm < matrix_multiplication.sexp | python3 ../../c-lisp.py | python3 ../../brilisp.py | python ../../llvm.py
was fed intobash ../brilisp/run.sh
, the below shown error was thrown.This is the code that was written in c-lisp (matrix_multiplication.sexp) which was given as an input to guile ../../utils/sexp-json.scm
This was the input given to
bash ../brilisp/run.sh