| 223 | } |
| 224 | |
| 225 | class AssemblyLine { |
| 226 | constructor(address, parts) { |
| 227 | this.address = address; |
| 228 | this.outgoing = []; |
| 229 | this.incoming = []; |
| 230 | parts.forEach(part => { |
| 231 | const fullMatch = part.match(kFullAddressRegexp); |
| 232 | if (fullMatch) { |
| 233 | let inlineAddress = parseInt(fullMatch[0]); |
| 234 | if (inlineAddress != this.address) this.outgoing.push(inlineAddress); |
| 235 | if (Number.isNaN(inlineAddress)) throw 'invalid address'; |
| 236 | } else if (kRelativeAddressRegexp.test(part)) { |
| 237 | this.outgoing.push(this._toAbsoluteAddress(part)); |
| 238 | } |
| 239 | }); |
| 240 | this.line = parts.join(' '); |
| 241 | } |
| 242 | |
| 243 | get isBlockStart() { |
| 244 | return this.incoming.length > 0; |
| 245 | } |
| 246 | |
| 247 | addIncoming(address) { |
| 248 | this.incoming.push(address); |
| 249 | } |
| 250 | |
| 251 | format() { |
| 252 | const content = DOM.span({textContent: this.line + '\n'}); |
| 253 | let formattedCode = content.innerHTML.split(kRegisterSplitRegexp) |
| 254 | .map(part => this._formatRegisterPart(part)) |
| 255 | .join(''); |
| 256 | formattedCode = |
| 257 | formattedCode.split(kAnyAddressRegexp) |
| 258 | .map((part, index) => this._formatAddressPart(part, index)) |
| 259 | .join(''); |
| 260 | // Let's replace the base-address since it doesn't add any value. |
| 261 | // TODO |
| 262 | content.innerHTML = formattedCode; |
| 263 | return content; |
| 264 | } |
| 265 | |
| 266 | _formatRegisterPart(part) { |
| 267 | if (!kIsRegisterRegexp.test(part)) return part; |
| 268 | return `<span class="reg ${part}">${part}</span>` |
| 269 | } |
| 270 | |
| 271 | _formatAddressPart(part, index) { |
| 272 | if (kFullAddressRegexp.test(part)) { |
| 273 | // The first or second address must be the line address |
| 274 | if (index <= 1) { |
| 275 | return `<span class="addr line" data-addr="${part}">${part}</span>`; |
| 276 | } |
| 277 | return `<span class=addr data-addr="${part}">${part}</span>`; |
| 278 | } else if (kRelativeAddressRegexp.test(part)) { |
| 279 | return `<span class=addr data-addr="0x${ |
| 280 | this._toAbsoluteAddress(part).toString(16)}">${part}</span>`; |
| 281 | } else { |
| 282 | return part; |
nothing calls this directly
no outgoing calls
no test coverage detected