ILGenerator,对返回值null进行决策

发布于 2024-11-26 04:09:24 字数 347 浏览 2 评论 0原文

il.Emit(OpCodes.Callvirt, _compactBinaryReader_ReadObject);

调用此函数并在特殊条件下提供返回值“null”。

之后决定是否跳转到标签或不

如果该值为空,我必须在方法

il.Emit(OpCodes.Dup);
il.Emit(OpCodes.Brfalse_S, DECISION);

调用给我一个异常“JIT 编译器遇到内部限制” 使用。当我调用该函数时,代码会正确构建。

也尝试过 OpCodes.Brfalse 。

我做错了什么?

il.Emit(OpCodes.Callvirt, _compactBinaryReader_ReadObject);

this function is called and at a special condition a return value of 'null' is provided.

if that value is null i have to take a decision whether to jump on to a label or not

using after the method call

il.Emit(OpCodes.Dup);
il.Emit(OpCodes.Brfalse_S, DECISION);

gives me an exception "JIT Compiler encountered an internal limitation." when i call that function, the code builds correctly though.

tried OpCodes.Brfalse too.

what am i doing wrong ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七禾 2024-12-03 04:09:24

找到了上述问题的原因,

应该理解的一件事是,当出现异常时
“CLR:运行时代码生成验证”
抛出它意味着编写的代码格式不正确,并且当汇编器对其进行评估时,它不接受编写的代码,问题通常是因为堆栈具有额外的值或更少的值。

“JIT 编译器遇到内部限制。”当运行时它期望我们提供其他有价值的东西或者当需要其他东西时堆栈有其他东西时抛出。

简而言之,后面的异常是在运行时抛出的,另一个是在预运行条件不满足时抛出的。

无论如何,我找到了原因,堆栈上仍然存在一些值,如果满足条件,我不会弹出这些值,因此 POP OpCode 解决了问题,顺便说一句,Dup OpCode 从未解决过,它总是推送 null堆栈上的值而不是复制最上面的值。

Found reasonS to the above problem,

one thing which should be understood that when an exception of
'CLR: Verification for Runtime Code Generation'
is thrown it means the code written is not in the correct format and when it is evaluated by the assembler it does not accept the written code, problem is usually because of stacks having extra values or less.

"JIT Compiler encountered an internal limitation." is thrown when at runtime it was expecting something else we provide something else in value or when stack has something else when something else was required.

In short, the later exception is thrown at runtime and the other is thrown when pre Run conditions are not met.

anyways i found the reason, i had some values still present on stack that i did not pop if Condition was met, so the POP OpCode did the trick, and by the way for me the Dup OpCode never worked out, it always pushes a null value on stack rather than duplicating the top most value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文