首页 > 解决方案 > 无法在 VS2019 中构建 CSCORE - 后期构建中的 ilasm 失败

问题描述

下列的

重定向到 .NET 4.7.2 后无法编译 CSCORE

使用 ilasm 失败,但没有给出原因

尝试在 VS2019 中构建 CSCore。最初 postbuild 脚本的路径与我的环境不兼容,所以我修复了它们。现在它有点工作,除了它在调用它的 InlineILCompiler 以在库中注入 CLR 代码时在 postbuild 脚本中中断。

更准确地说,它在 InlineILCompiler\Program.cs 的大约第 350 行处中断,在它调用外部 ilasm.exe 以使用“disasm.il”作为输入重新组装所有内容的步骤中。

我设法在 disasm.il 被删除之前获得了它的副本,并且我尝试自己重新发出 ilasm 命令,使用的参数与 InlineILCompiler 提供的参数相同......但它失败了,如下所示:

[...looong output here]
Assembled method CSCore.Codecs.AIFF.AiffBinaryReader::ReadUInt32
Assembled method CSCore.Codecs.AIFF.AiffBinaryReader::ReadInt16
Assembled method CSCore.Codecs.AIFF.AiffBinaryReader::ReadUInt16
Assembled method CSCore.Codecs.AIFF.AiffBinaryReader::Skip
Assembled method CSCore.Codecs.AIFF.AiffBinaryReader::ReadBytes
D:\cscore-master\CSCore\Codecs\AIFF\AiffBinaryReader.cs(97) : error : syntax error at token '-' in:     IL_00ad:  ldc.r8     -nan(ind)

我对 IL 了解不多,但我仍然进行了调查,发现违规行似乎处于阻塞状态:

  .method private hidebysig instance float64 
          ConvertFromIeeeExtended(uint8[] bytes) cil managed
  {
    // Code size       275 (0x113)
.maxstack 8
    .locals init ([0] float64 f,
             [1] int32 expon,
             [2] uint64 hiMant,
             [3] uint64 loMant,
             [4] bool V_4,
             [5] bool V_5,
             [6] bool V_6,
             [7] float64 V_7)
    .line 75,75 : 9,10 ''
    IL_0000:  nop
    .line 80,80 : 13,66 ''
    IL_0001:  ldarg.1
    IL_0002:  ldc.i4.0
    IL_0003:  ldelem.u1
    IL_0004:  ldc.i4.s   127
    IL_0006:  and
    IL_0007:  ldc.i4.8
    IL_0008:  shl
    IL_0009:  ldarg.1
    IL_000a:  ldc.i4.1
    IL_000b:  ldelem.u1
    IL_000c:  ldc.i4     0xff
    IL_0011:  and
    IL_0012:  or
    IL_0013:  stloc.1
    .line 81,84 : 13,50 ''
    IL_0014:  ldarg.1
    IL_0015:  ldc.i4.2
    IL_0016:  ldelem.u1
    IL_0017:  ldc.i4     0xff
    IL_001c:  and
    IL_001d:  conv.i8
    IL_001e:  ldc.i4.s   24
    IL_0020:  shl
    IL_0021:  ldarg.1
    IL_0022:  ldc.i4.3
    IL_0023:  ldelem.u1
    IL_0024:  ldc.i4     0xff
    IL_0029:  and
    IL_002a:  conv.i8
    IL_002b:  ldc.i4.s   16
    IL_002d:  shl
    IL_002e:  or
    IL_002f:  ldarg.1
    IL_0030:  ldc.i4.4
    IL_0031:  ldelem.u1
    IL_0032:  ldc.i4     0xff
    IL_0037:  and
    IL_0038:  conv.i8
    IL_0039:  ldc.i4.8
    IL_003a:  shl
    IL_003b:  or
    IL_003c:  ldarg.1
    IL_003d:  ldc.i4.5
    IL_003e:  ldelem.u1
    IL_003f:  ldc.i4     0xff
    IL_0044:  and
    IL_0045:  conv.i8
    IL_0046:  or
    IL_0047:  stloc.2
    .line 85,88 : 13,50 ''
    IL_0048:  ldarg.1
    IL_0049:  ldc.i4.6
    IL_004a:  ldelem.u1
    IL_004b:  ldc.i4     0xff
    IL_0050:  and
    IL_0051:  conv.i8
    IL_0052:  ldc.i4.s   24
    IL_0054:  shl
    IL_0055:  ldarg.1
    IL_0056:  ldc.i4.7
    IL_0057:  ldelem.u1
    IL_0058:  ldc.i4     0xff
    IL_005d:  and
    IL_005e:  conv.i8
    IL_005f:  ldc.i4.s   16
    IL_0061:  shl
    IL_0062:  or
    IL_0063:  ldarg.1
    IL_0064:  ldc.i4.8
    IL_0065:  ldelem.u1
    IL_0066:  ldc.i4     0xff
    IL_006b:  and
    IL_006c:  conv.i8
    IL_006d:  ldc.i4.8
    IL_006e:  shl
    IL_006f:  or
    IL_0070:  ldarg.1
    IL_0071:  ldc.i4.s   9
    IL_0073:  ldelem.u1
    IL_0074:  ldc.i4     0xff
    IL_0079:  and
    IL_007a:  conv.i8
    IL_007b:  or
    IL_007c:  stloc.3
    .line 90,90 : 13,58 ''
    IL_007d:  ldloc.1
    IL_007e:  brtrue.s   IL_008a

    IL_0080:  ldloc.2
    IL_0081:  brtrue.s   IL_008a

    IL_0083:  ldloc.3
    IL_0084:  ldc.i4.0
    IL_0085:  conv.i8
    IL_0086:  ceq
    IL_0088:  br.s       IL_008b

    IL_008a:  ldc.i4.0
    IL_008b:  stloc.s    V_4
    .line 16707566,16707566 : 0,0 ''
    IL_008d:  ldloc.s    V_4
    IL_008f:  brfalse.s  IL_009d

    .line 91,91 : 17,23 ''
    IL_0091:  ldc.r8     0.0
    IL_009a:  stloc.0
    IL_009b:  br.s       IL_00ef

    .line 93,93 : 13,14 ''
    IL_009d:  nop
    .line 94,94 : 17,37 ''
    IL_009e:  ldloc.1
    IL_009f:  ldc.i4     0x7fff
    IL_00a4:  ceq
    IL_00a6:  stloc.s    V_5
    .line 16707566,16707566 : 0,0 ''
    IL_00a8:  ldloc.s    V_5
    IL_00aa:  brfalse.s  IL_00ba

    .line 95,95 : 17,18 ''
    IL_00ac:  nop
    .line 97,97 : 21,36 ''
    IL_00ad:  ldc.r8     -nan(ind)
    IL_00b6:  stloc.0
    .line 98,98 : 17,18 ''
    IL_00b7:  nop
    IL_00b8:  br.s       IL_00ee

    .line 100,100 : 17,18 ''
    IL_00ba:  nop
    .line 101,101 : 21,36 ''
    IL_00bb:  ldloc.1
    IL_00bc:  ldc.i4     0x3fff
    IL_00c1:  sub
    IL_00c2:  stloc.1
    .line 102,102 : 21,69 ''
    IL_00c3:  ldarg.0
    IL_00c4:  ldarg.0
    IL_00c5:  ldloc.2
    IL_00c6:  call       instance float64 CSCore.Codecs.AIFF.AiffBinaryReader::UnsignedToFloat(uint64)
    IL_00cb:  ldloc.1
    IL_00cc:  ldc.i4.s   31
    IL_00ce:  sub
    IL_00cf:  dup
    IL_00d0:  stloc.1
    IL_00d1:  call       instance float64 CSCore.Codecs.AIFF.AiffBinaryReader::ldexp(float64,
                                                                                     int32)
    IL_00d6:  stloc.0
    .line 103,103 : 21,70 ''
    IL_00d7:  ldloc.0
    IL_00d8:  ldarg.0
    IL_00d9:  ldarg.0
    IL_00da:  ldloc.3
    IL_00db:  call       instance float64 CSCore.Codecs.AIFF.AiffBinaryReader::UnsignedToFloat(uint64)
    IL_00e0:  ldloc.1
    IL_00e1:  ldc.i4.s   32
    IL_00e3:  sub
    IL_00e4:  dup
    IL_00e5:  stloc.1
    IL_00e6:  call       instance float64 CSCore.Codecs.AIFF.AiffBinaryReader::ldexp(float64,
                                                                                     int32)
    IL_00eb:  add
    IL_00ec:  stloc.0
    .line 104,104 : 17,18 ''
    IL_00ed:  nop
    .line 105,105 : 13,14 ''
    IL_00ee:  nop
    .line 107,107 : 13,43 ''
    IL_00ef:  ldarg.1
    IL_00f0:  ldc.i4.0
    IL_00f1:  ldelem.u1
    IL_00f2:  ldc.i4     0x80
    IL_00f7:  and
    IL_00f8:  ldc.i4     0x80
    IL_00fd:  ceq
    IL_00ff:  stloc.s    V_6
    .line 16707566,16707566 : 0,0 ''
    IL_0101:  ldloc.s    V_6
    IL_0103:  brfalse.s  IL_010b

    .line 108,108 : 17,27 ''
    IL_0105:  ldloc.0
    IL_0106:  neg
    IL_0107:  stloc.s    V_7
    IL_0109:  br.s       IL_0110

    .line 109,109 : 13,22 ''
    IL_010b:  ldloc.0
    IL_010c:  stloc.s    V_7
    IL_010e:  br.s       IL_0110

    .line 110,110 : 9,10 ''
    IL_0110:  ldloc.s    V_7
    IL_0112:  ret
  } // end of method AiffBinaryReader::ConvertFromIeeeExtended

更准确地说,带有 -nan(ind) 的行:

 .line 95,95 : 17,18 ''
    IL_00ac:  nop
    .line 97,97 : 21,36 ''
    IL_00ad:  ldc.r8     -nan(ind)
    IL_00b6:  stloc.0
    .line 98,98 : 17,18 ''
    IL_00b7:  nop
    IL_00b8:  br.s       IL_00ee

不知道现在该怎么办,有什么想法吗?谢谢你。

标签: .netcilcscoreilasm

解决方案


这是 Visual Studio 中的错误,已报告但未解决。为了克服它,我在 Codecs.AIFF 中更改了 AiffBinaryReader 的来源。

            if (expon == 0x7FFF)
            {
                /* Infinity or NaN */
                f = double.NaN;
            }

变成

            if (expon == 0x7FFF)
            {
                /* Infinity or NaN */
                f =   1000;                 
                f = f * 1000;
                f = f * 1000;
                f = f * 1000;
                f = f * 1000;
                f = f * 1000;
                f = f * 1000;
                f = f * 1000;
                f = f * 1000;
                f = f * 1000;
                f = f * 1000;
                f = f * 1000;
                f = f * 1000;
                f = f * 1000;
                f = f * 1000;
                f = f * 1000;
            }

不完全是 INFINITY 但肯定是一个很大的数字,足以让 CsCore 工作和 VS 编译它!成功。


推荐阅读