/
AsmSource.cs
77 lines (74 loc) · 2.59 KB
/
AsmSource.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Cosmos.VS.DebugEngine
{
public static class AsmSource
{
// Extract out the relevant lines from the .asm file.
public static StringBuilder GetSourceForLabels(string aAsmFile, List<string> aLabels)
{
var xCode = new StringBuilder();
// Find line in ASM that starts the code block.
using (var xSR = new StreamReader(aAsmFile, Encoding.ASCII))
{
string xLine;
while (true)
{
xLine = xSR.ReadLine();
if (xLine == null)
{
break;
}
var xParts = xLine.Trim().Split(' ');
if (xParts.Length > 0 && xParts[0].EndsWith(":"))
{
if (aLabels.Contains(xParts[0]))
{
// Found the first match, break.
break;
}
}
}
var lineCount = 0;
// Extract the pertinent lines
while (xLine != null)
{
if (lineCount > 100)
{
break;
}
var xParts = xLine.Trim().Split(' ');
if (xParts.Length > 0 && xParts[0].EndsWith(":"))
{
// Its a label, lets check it
if (xParts.Length > 1 && xParts[1] == ";Asm")
{
// ASM label
xCode.AppendLine(xLine);
lineCount ++;
}
else if (aLabels.Contains(xParts[0]))
{
// Normal label
xCode.AppendLine(xLine);
lineCount ++;
}
else
{
// Label with unrecognized comment, or IL label that doesn't match.
// We are done.
break;
}
}
else
{ // Not a label, just output it
xCode.AppendLine(xLine);
}
xLine = xSR.ReadLine();
}
}
return xCode;
}
}
}