• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SamboyCoding / Cpp2IL / 11023494789

24 Sep 2024 11:30PM UTC coverage: 28.383% (-0.1%) from 28.517%
11023494789

push

github

SamboyCoding
Core: A bunch of changes to WASM sig calculation.

This still doesn't work properly. Make it make sense. Please.

1238 of 6094 branches covered (20.32%)

Branch coverage included in aggregate %.

15 of 86 new or added lines in 13 files covered. (17.44%)

2 existing lines in 2 files now uncovered.

3341 of 10039 relevant lines covered (33.28%)

102017.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/WasmDisassembler/Disassembler.cs
1
namespace WasmDisassembler;
2

3
public static class Disassembler
4
{
5
    public static List<WasmInstruction> Disassemble(byte[] body, uint virtualAddress)
6
    {
7
        var ret = new List<WasmInstruction>();
×
8

9
        using var s = new MemoryStream(body);
×
10
        using var reader = new BinaryReader(s);
×
11
        while (s.Position < s.Length)
×
12
        {
13
            var ip = virtualAddress + (uint)s.Position;
×
14
            var mnemonic = (WasmMnemonic)reader.ReadByte();
×
15

16
            if (mnemonic > WasmMnemonic.LastValid)
×
17
                throw new($"Encountered invalid mnemonic {mnemonic} at ip 0x{ip:X}, byte array position {s.Position}.");
×
18

19
            var instruction = reader.ReadInstruction(mnemonic);
×
20
            instruction.Ip = ip;
×
21
            instruction.NextIp = virtualAddress + (uint)s.Position; //Next ip is position we go into the next instruction with
×
22
            ret.Add(instruction);
×
23
        }
24

25
        return ret;
×
26
    }
×
27

28
    private static WasmInstruction ReadInstruction(this BinaryReader reader, WasmMnemonic mnemonic)
29
    {
30
        var ret = new WasmInstruction { Mnemonic = mnemonic, };
×
31

32
        var opTypes = mnemonic.GetOperandTypes();
×
33
        if (opTypes.Length == 0)
×
34
        {
35
            ret.Operands = [];
×
36
            return ret;
×
37
        }
38

39
        ret.Operands = opTypes.Select(reader.ReadPrimitive).ToArray();
×
40

41
        return ret;
×
42
    }
43

44
    private static Type[] GetOperandTypes(this WasmMnemonic mnemonic)
45
    {
46
        if (mnemonic is >= WasmMnemonic.I32Load and <= WasmMnemonic.I64Store32)
×
47
            //Align, offset
48
            return [typeof(LEB128), typeof(LEB128)];
×
49

50
        switch (mnemonic)
51
        {
52
            case WasmMnemonic.If:
53
            case WasmMnemonic.Block:
54
            case WasmMnemonic.Loop:
55
            case WasmMnemonic.LocalGet:
56
            case WasmMnemonic.LocalSet:
57
            case WasmMnemonic.GlobalGet:
58
            case WasmMnemonic.GlobalSet:
59
            case WasmMnemonic.LocalTee:
60
            case WasmMnemonic.BrIf:
61
            case WasmMnemonic.Br:
62
                return [typeof(byte)];
×
63
            case WasmMnemonic.I32Const:
64
            case WasmMnemonic.I64Const:
65
            case WasmMnemonic.Call:
66
                return [typeof(LEB128)];
×
67
            case WasmMnemonic.F32Const:
68
                return [typeof(float)];
×
69
            case WasmMnemonic.F64Const:
70
                return [typeof(double)];
×
71
            case WasmMnemonic.CallIndirect:
72
                //Type, table
73
                return [typeof(LEB128), typeof(byte)];
×
74
            default:
75
                return [];
×
76
        }
77
    }
78

79
    internal static object ReadPrimitive(this BinaryReader reader, Type type)
80
    {
81
        if (type == typeof(bool))
×
82
            return reader.ReadBoolean();
×
83

84
        if (type == typeof(char))
×
85
            return reader.ReadChar();
×
86

87
        if (type == typeof(int))
×
88
            return reader.ReadInt32();
×
89

90
        if (type == typeof(uint))
×
91
            return reader.ReadUInt32();
×
92

93
        if (type == typeof(short))
×
94
            return reader.ReadInt16();
×
95

96
        if (type == typeof(ushort))
×
97
            return reader.ReadUInt16();
×
98

99
        if (type == typeof(sbyte))
×
100
            return reader.ReadSByte();
×
101

102
        if (type == typeof(byte))
×
103
            return reader.ReadByte();
×
104

105
        if (type == typeof(long))
×
106
            return reader.ReadInt64();
×
107

108
        if (type == typeof(ulong))
×
109
            return reader.ReadUInt64();
×
110

111
        if (type == typeof(float))
×
112
            return reader.ReadSingle();
×
113

114
        if (type == typeof(double))
×
115
            return reader.ReadDouble();
×
116

117
        if (type == typeof(LEB128))
×
NEW
118
            return reader.BaseStream.ReadLEB128Signed();
×
119

120
        throw new($"Bad primitive type: {type}");
×
121
    }
122
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc