Check-in [fcf295dc4d]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Bi-column printing of instructions.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:fcf295dc4ddf211d62786a75fbebe6ba948b818a
User & Date: stephanie.gawroriski 2019-06-12 19:43:31
Context
2019-06-12
19:45
Add arrows in splitter. check-in: b1bf7bee98 user: stephanie.gawroriski tags: trunk
19:43
Bi-column printing of instructions. check-in: fcf295dc4d user: stephanie.gawroriski tags: trunk
19:00
Add line population change count to show when a line has gone back (such as for loops). check-in: 37e31228d6 user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to bldt/mids/sxs/dev/shadowtail/sxs/Main.java.

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
..
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
..
73
74
75
76
77
78
79



80
81
82
83
84
85
86
...
103
104
105
106
107
108
109
110
111

112
113
114
115
116





























































117

118
119
120
121
122
123
124
import dev.shadowtail.classfile.nncc.NativeCode;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;

import java.util.List;
import java.util.Map;

import net.multiphasicapps.classfile.ByteCode;
import net.multiphasicapps.classfile.ClassFile;
import net.multiphasicapps.classfile.Method;
import net.multiphasicapps.javac.CompilerPathSet;
import net.multiphasicapps.javac.NoSuchInputException;

/**
 * Main entry point and dumber for the class code side by side
 *
 * @since 2019/06/12
 */
public class Main
{




	/**
	 * Dumps the given method.
	 *
	 * @param __ps The stream to write to.
	 * @param __srclines The source lines.
	 * @param __m The method to dump.
	 * @throws NullPointerException On null arguments.
................................................................................
		List<String> __srclines, Method __m)
		throws NullPointerException
	{
		if (__ps == null || __srclines == null || __m == null)
			throw new NullPointerException("NARG");
		
		// Note what is being dumped
		__ps.printf("****** %s ******%n", __m.nameAndType());

		
		// Line population count, to track how many times it changed to them
		Map<Integer, Integer> lnpopcount = new HashMap<>();
		
		// Get byte code and native code
		ByteCode bc = __m.byteCode();
		NativeCode nc = __m.nativeCode();
................................................................................
			nijpc = -1;
		
		// Last position information, to detect changes
		int lljln = nijln,
			lljop = nijop,
			lljpc = nijpc;
		



		// Major order is the native code
		for (int nidx = 0, numni = nc.length(); nidx < numni; nidx++)
		{
			// Get native instruction details
			NativeInstruction ni = nc.get(nidx);
			int niop = ni.operation();
			
................................................................................
				
				// Get the line, turn tabs to spaces to save room
				String ln = (nijln > 0 && nijln <= __srclines.size() ?
					__srclines.get(nijln - 1) : "<INVALID LINE?>").
					replace('\t', ' ');
				
				// Print the line text
				__ps.printf("    L%4d%3s: %s%n", nijln, (popcount > 1 ?
					String.format("+%-2d", popcount) : "   "), ln);

				
				// Set new last line
				lljln = nijln;
			}
			





























































			//__ps.println(ni);

		}
		
		// Spacing
		__ps.println();
	}
	
	/**







>


>













>
>
>
>







 







|
>







 







>
>
>







 







|

>





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>







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
..
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import dev.shadowtail.classfile.nncc.NativeCode;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.multiphasicapps.classfile.ByteCode;
import net.multiphasicapps.classfile.ClassFile;
import net.multiphasicapps.classfile.Method;
import net.multiphasicapps.javac.CompilerPathSet;
import net.multiphasicapps.javac.NoSuchInputException;

/**
 * Main entry point and dumber for the class code side by side
 *
 * @since 2019/06/12
 */
public class Main
{
	/** The maximum column size. */
	public static final int COLUMN_SIZE =
		44;
	
	/**
	 * Dumps the given method.
	 *
	 * @param __ps The stream to write to.
	 * @param __srclines The source lines.
	 * @param __m The method to dump.
	 * @throws NullPointerException On null arguments.
................................................................................
		List<String> __srclines, Method __m)
		throws NullPointerException
	{
		if (__ps == null || __srclines == null || __m == null)
			throw new NullPointerException("NARG");
		
		// Note what is being dumped
		__ps.printf("****** %s ******", __m.nameAndType());
		__ps.println();
		
		// Line population count, to track how many times it changed to them
		Map<Integer, Integer> lnpopcount = new HashMap<>();
		
		// Get byte code and native code
		ByteCode bc = __m.byteCode();
		NativeCode nc = __m.nativeCode();
................................................................................
			nijpc = -1;
		
		// Last position information, to detect changes
		int lljln = nijln,
			lljop = nijop,
			lljpc = nijpc;
		
		// Fragment part builder
		StringBuilder sb = new StringBuilder();
		
		// Major order is the native code
		for (int nidx = 0, numni = nc.length(); nidx < numni; nidx++)
		{
			// Get native instruction details
			NativeInstruction ni = nc.get(nidx);
			int niop = ni.operation();
			
................................................................................
				
				// Get the line, turn tabs to spaces to save room
				String ln = (nijln > 0 && nijln <= __srclines.size() ?
					__srclines.get(nijln - 1) : "<INVALID LINE?>").
					replace('\t', ' ');
				
				// Print the line text
				__ps.printf("    L%4d%3s: %s", nijln, (popcount > 1 ?
					String.format("+%-2d", popcount) : "   "), ln);
				__ps.println();
				
				// Set new last line
				lljln = nijln;
			}
			
			// Change of Java instruction? Get its string form
			String jis = "...";
			if (nijpc != lljpc)
			{
				// Get form
				jis = String.format("J@%3d: %s",
					nijpc, bc.getByAddress(nijpc));
				
				// Set new last address
				lljpc = nijpc;
			}
			
			// Get native instruction form
			String nis = String.format("N@%3d: %s",
				nidx, ni);
			
			// Get string lengths
			int nisl = nis.length(),
				jisl = jis.length();
			
			// Determine row count
			int nirl = Math.max(1, (nisl + COLUMN_SIZE) / COLUMN_SIZE),
				jirl = Math.max(1, (jisl + COLUMN_SIZE) / COLUMN_SIZE),
				mxrl = Math.max(nirl, jirl);
			
			// Print all rows
			for (int i = 0; i < mxrl; i++)
			{
				// Print indent space
				__ps.print("    ");
				
				// New line or continuation?
				__ps.print((i == 0 ? '>' : ' '));
				
				// Determine fragment start and ends
				int nfs = Math.min(nisl, COLUMN_SIZE * i),
					nfe = Math.min(nisl, nfs + COLUMN_SIZE),
					jfs = Math.min(jisl, COLUMN_SIZE * i),
					jfe = Math.min(jisl, jfs + COLUMN_SIZE);
				
				// Print native fragment
				sb.setLength(0);
				sb.append(nis.substring(nfs, nfe));
				while (sb.length() < COLUMN_SIZE)
					sb.append(' ');
				__ps.print(sb);
				
				// Print splitter
				__ps.print(" | ");
				
				// Print Java fragment
				sb.setLength(0);
				sb.append(jis.substring(jfs, jfe));
				while (sb.length() < COLUMN_SIZE)
					sb.append(' ');
				__ps.print(sb);
				
				// New line or continuation?
				__ps.print((i == 0 ? '<' : ' '));
				
				// End line
				__ps.println();
			}
		}
		
		// Spacing
		__ps.println();
	}
	
	/**