While Loop
I can't see from the (rather long) snippet if the code would be synthesizable at all, I guess it isn't.
A frequent misunderstanding of iteration constructs in HDL code is, that they would create a sequential processing order as an iteration in a microprocessor program. But they don't!
They are a direction to generate parallel logic, one instance of the logic within the block for each iteration. To be synthesisable, the number of iterations must be finite and predictable for the HDL compiler. Otherwise the compiler would be stuck in an endless loop (resulting in a compilation error after reaching a predefined iteration limit).
In most cases, the only suitable solution is to code a really sequential program flow, using a clock.