MCPcopy Create free account
hub / github.com/Marus/cortex-debug / tryMerge

Method tryMerge

src/backend/disasm.ts:117–158  ·  view source on GitHub ↗
(other: InstructionRange)

Source from the content-addressed store, hash-verified

115 }
116
117 public tryMerge(other: InstructionRange): boolean {
118 if (!this.isOverlappingRange(other.startAddress, other.endAddress)) {
119 return false;
120 }
121
122 // See if totally overlapping or adjacent
123 if ((this.span === other.span) && (this.startAddress === other.startAddress)) {
124 return true; // They are identical
125 } else if (this.endAddress === other.startAddress) { // adjacent at end of this
126 this.instructions = this.instructions.concat(other.instructions);
127 this.adjustBoundaries();
128 return true;
129 } else if (other.endAddress === this.startAddress) { // adjacent at end of other
130 this.instructions = other.instructions.concat(this.instructions);
131 this.adjustBoundaries();
132 return true;
133 }
134
135 // They partially overlap
136 const left = (this.startAddress <= other.startAddress) ? this : other;
137 const right = (this.startAddress <= other.startAddress) ? other : this;
138 const lx = left.instructions.length - 1;
139 const leftEnd = left.instructions[lx].pvtAddress;
140 const numRight = right.instructions.length;
141 for (let ix = 0; ix < numRight; ix++) {
142 if (right.instructions[ix].pvtAddress === leftEnd) {
143 const rInstrs = right.instructions.slice(ix + 1);
144 left.instructions = left.instructions.concat(rInstrs);
145
146 // Almost like a new item but modify in place
147 this.instructions = left.instructions;
148 this.adjustBoundaries();
149 if (GdbDisassembler.debug) {
150 console.log('Merge @', this.instructions[lx - 1], this.instructions[lx], this.instructions[lx + 1]);
151 }
152 return true;
153 }
154 }
155 // start/end addresses are original search ranges. According to that, the ranges overlap. But
156 // the actual instructions may not overlap or even abut
157 return false;
158 }
159
160 public shallowCopy(): InstructionRange {
161 return new InstructionRange(this.instructions);

Callers 2

forceMergeMethod · 0.95
addToCacheMethod · 0.80

Calls 3

isOverlappingRangeMethod · 0.95
adjustBoundariesMethod · 0.95
logMethod · 0.80

Tested by

no test coverage detected