问题标签 [ilasm]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
111 浏览

compiler-construction - 哪个更快:ldc.i4/ldstr 或 ldloc?

我正在为 .NET 平台编写一个非常基本的编译器,并且想了解一些关于我的常量实现的信息。

在我的编译器中,常量的使用有望取代 ldloc 操作。

如果常量 theAge(18) 和 theName(Barry) 实际上是变量,则 IL 可能类似于:

但是如果我实现了常量:

哪个更快:ldc.i4/ldstr 或 ldloc?还是将常量存储为变量更好?

0 投票
1 回答
395 浏览

c# - ILASM.exe process gets stuck during build

I'm building a WPF library in Visual Studio 2015, and build never completes. In build output diagnostic level I can see the last task launched by msbuild is

I can see the ilasm process is hanging around, not crashed, but nothing happens. If I forcefully stop the build by killing the msbuild and launch the same command in a console, it works, fast, outputs Operation completed successfully

I've used Process Monitor to get a handle on what's happening, and I found something weird-ish, when ilasm is successful (run from console), the process is named ilasm.exe and when it's a failure it's named ILAsm.exe (notice the case change), I don't see why, especially that the path to the exe are the same? There is something in the Process event log that mentions prefetch of the binary to be run:

Success: "IRP_MJ_READ","C:\Windows\Prefetch\ILASM.EXE-FD82B157.pf","SUCCESS","Offset: 0, Length: 82 642, Priority: Normal"

Failure: "IRP_MJ_READ","C:\Windows\Prefetch\ILASM.EXE-FD82B157.pf","SUCCESS","Offset: 0, Length: 82 844, Priority: Normal"

Same file but different sizes all of a sudden ?

0 投票
2 回答
4308 浏览

c# - c# 导出DLL时隐藏类成员

当我将 DLL 发布到第三方应用程序时,我是否只能让最终用户看到某些方法?

我的代码建立在 7-8 个相互调用的不同项目之上,它们具有不同的命名空间,例如“ Company.ProjectName ”,我认为与“ Company ”命名空间相关,我只想要其中一个项目(定义了一个接口顺便说一句)对外部世界可见。

解决方案中的每个项目都编译成 DLL,然后我使用 ILASM 将它们组合起来。

顺便说一句,在解决方案中还有其他项目使用这些与此 dll 无关。

编辑:internal即使命名空间的构造类似于“ CompanyName.Project1 ”、“ CompanyName.Project2 ”,关键字也会起作用吗?他们会见面吗?

0 投票
1 回答
43 浏览

.net - 存储弱类型变量的方法

在我的编译器的开发阶段,我遇到了一个非常复杂的问题:如何在我的语言中存储弱类型变量。

由于我允许在不明确指定其类型的情况下声明变量,并允许函数返回任一类型(例如函数可以返回标量 OR 数组),我现在面临着以何种形式存储这些变量的困难。

以下是我考虑过的可能性,但它们都有很大的开销:

  • 将所有变量视为双精度列表 ( List<double>) 并让第一个元素指定它是标量还是数组(01例如)。
  • 将所有变量视为object实例。
  • 将所有变量视为TVar(自定义类),可以是 adoubleList<double>.

要牢记:

  • 我打算拥有的唯一两种类型的变量是双精度和双精度数组,因为所有其他变量都可以从中派生(例如 char 是双精度的情况,字符串是字符数组等)
  • 我正在使用ILAsm它是更高级别的汇编风格(基本上是.NET中间语言)
0 投票
1 回答
97 浏览

.net - MSIL assembly: Unexpected OutOfMemoryException in class constructor

I'm writing a compiler that outputs .NET assemblies (using Mono.Cecil, although I don't believe Cecil is relevant to this problem). One of the compiler features requires that a class will have a compiler-generated nested class with some support methods; the outer class has a static field so each class effectively has a singleton referencing an object of the nested class. To initialise this, any such class has a class constructor to create an instance of the nested class and store it in the field.

Problem: When my outer class is a generic class, I make the nested class generic too (since it needs to create objects of the outer class). The generated IL passes through peverify fine, and looks fine to my eye, but the class constructor creating an instance of the nested class throws OutOfMemoryException at runtime.

I've disassembled the assembly with ildasm, slimmed it down to a minimal reproduction (unfortunately still ~180 lines of IL), and verifying that compiling the IL with ilasm produces an exe that still exhibits the problem.

Debugging with Visual Studio or MDbg hasn't enlightened me - I just get OutOfMemoryException without indication why. I'm willing to believe my IL is invalid somehow, but peverify doesn't indicate a problem. Can anyone suggest what the issue is?

0 投票
4 回答
6979 浏览

linux - .net-core:相当于 ILDASM / ILASM

.net-core 有相当于 ILDASM / ILASM 的吗?

具体来说,我正在寻找在 Linux 上运行的东西(因此为什么要使用 .net-core)。

0 投票
0 回答
527 浏览

c# - MSIL:简单的自定义代码说无效的 IL 代码 - System.InvalidProgramException

我正在尝试了解有关 .NET MSIL 的更多信息,因此我想编写我的自定义 IL 程序集。我被下面的例子困住了。

首先,我在 OSX 上,使用 Mono“Mono JIT 编译器版本 4.8.1(mono-4.8.0-branch/22a39d7 Fri Apr 7 12:00:08 EDT 2017)”,我的 il 程序集看起来像。完整文件:

有趣或“有问题”的部分在这里:

我得到的错误如下:

并且“IL_0056:ret”指向该行(当我反汇编生成的可执行文件时):

一些重要的注意事项: * 当存储和分配给数组时,我似乎总是做一些不必要的“舞蹈”。我这样做是因为最后我想创建一个堆栈机器,它只适用于堆栈中的值。这也是代码看起来像这样的原因。在写它之前,我想看看我如何在 MSIL 中做到这一点。

如果有人能告诉我这里出了什么问题,我将不胜感激。非常感谢。

这是我在这里的第一个问题,我希望我已经提供了所有必要的信息以帮助我:-)

PS:我也尝试将 MonoDevelop 与“调试应用程序”一起使用,但我无法真正从中获得任何有意义的数据,gdb 也没有为我工作。

PPS:我在想我的堆栈上仍然有值,但是当我在末尾添加一个弹出(或更多)时,它只是告诉我“弹出”无效。

编辑:

我试图打印某种输出以查看出了什么问题,我发现在“循环”标签之间它没有正确地从堆栈中弹出值。我还不知道为什么,但这里有一个示例输出,它清楚地显示了它:

即使我进一步修改 il 代码,它也会打印更多值:

它不会从堆栈中弹出。由于某些奇怪的原因,“调用 WriteLine”不会弹出值,或者看起来它确实备份和恢复堆栈,但这只是我的假设。这与以下内容有什么关系:.NET CIL 操作评估堆栈 (“向后分支约束”,链接:http: //jilc.sourceforge.net/ecma_p3_cil.shtml

0 投票
1 回答
328 浏览

.net - 为什么 ILGenerator.Emit() 在动态程序集中插入 nop 操作码?

我正在用 C# 构建一个小型编译器,因此不可避免地我不得不干预动态程序集和发出操作码。现在,奇怪的是我的 Emit() 调用在生成的模块中创建了额外的 nop 操作码。在我的情况下,它并不是那么重要,因为性能并不是真的很重要,但它确实让我感到困惑为什么会发生这种情况。它似乎是在加载或存储到本地或参数之后发生的。任何可以指出我可以检查的东西的 C#/动态程序集专家吗?我附上了生成代码的示例,如果需要更多信息,请告诉我。谢谢。

根据要求,这里概述了我的代码的外观。缺少一些东西,并且由于代码被分成单独的模块,这些是按照它们执行的顺序最相关的部分。

对于我的抽象语法树上的每个节点(用三个地址代码装饰),我只是这样做:

这是此函数产生的一系列调用:

我不知道这是否有帮助,如果您想查看我的完整项目,它位于:

http://github.com/yannikab/grc

与目标代码生成相关的所有内容都在 Cil 命名空间下。将所有东西放在一起用于代码生成的类名为 CilVisitor。

0 投票
1 回答
531 浏览

.net-core - Ilasm.exe 在 .NET Standard 2.0 dll 中注入 mscorlib 依赖项

我正在从 IL 构建一个 .NET Core 2.0 库。我之前对 .NET Core 1.0/1.1 做了完全相同的操作,没有任何问题。但是,同样的事情不适用于 .NET Core 2.0 dll。

运行后:

我收到这个警告:

warning : Reference to undeclared extern assembly 'mscorlib'. Attempting autodetect

结果,mscorlib确实在 output.dll 中显示为依赖项(我不希望它在那里)。

在 input.dll.il (以及 res 文件)中,根本没有提到 mscorlib (mscorlib字符串从未出现在文件中,我仔细检查了这一点):

我试图将 netstandard.dll 复制到工作文件夹中,但没有任何效果。也许使用 .NET Core 2.0 需要特殊版本的 ilasm.exe?我正在使用 .NET Framework 4.5 中的那个,因为我在 .NET Core 2.0 SDK 中没有找到任何 ilasm(也许我在错误的地方搜索)。或者还有什么可能的原因?

.NET Core 1.0(运行良好)的唯一区别.assembly extern 'netstandard'.assembly extern 'System.Runtime'.

0 投票
1 回答
934 浏览

.net-core - Microsoft.NETCore.ILAsm 中的 ilasm.exe 在哪里?

我需要最新的 ilasm.exe。我认为这将是来自https://www.nuget.org/packages/Microsoft.NETCore.ILAsm/的那个

但是,下载的 microsoft.netcore.ilasm.2.0.0.nupkg 存档不包含任何 .exe 或 .dll 文件。

我不知道如何使用这个包。