Question regarding stack size before each instruction #756
-
Hi there, I need to compute the stack size at each CIL instruction while assuming it is legal bytecode. To do it, I'm reading how the CodeWriter computes the max stack size of a method. Having read it, I wonder about this behavior:
My understanding is that if the bytecode were legal, then the above calculation would be redundant. In the sense that every instruction that may jump to the current one should have the same stack size. I am not implying that there is a bug in the implementation, I guess Cecil tries to aid the user to generate a legal output even if the input is illegal. Do you think that I am comprehending how things work? Am I missing a case? Kind regards, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I believe so. Here's what ECMA-335 says in I.12.3.2.1:
If you're interested, I wrote a simple stack depth checker based on Cecil's code here. It basically computes the stack size for each instruction, and fails if there's a mismatch. It's not pretty (I just wanted to check if another part of my code was based on correct assumptions), but it verifies code from all loaded assemblies at that point, and here are the results:
|
Beta Was this translation helpful? Give feedback.
I believe so. Here's what ECMA-335 says in I.12.3.2.1:
If you're interested, I wrote a simple stack depth checker based on Cecil's code here. It basically computes the stack size for each instruction, and fails if there's a mismatch. It's not pretty (I just wanted to check if another part…