Skip to content

Commit eb07986

Browse files
committed
bugc: add source maps for call setup instructions
The call setup sequence (POP cleanup, PUSH return address, MSTORE, push arguments, PUSH function address) was using remark-only debug contexts, leaving these instructions unmapped in tracing output. Now threads the call terminator's operationDebug (which carries the source code range for the call expression) through all setup instructions, matching how other instruction generators use operationDebug.
1 parent da00fb8 commit eb07986

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

packages/bugc/src/evmgen/generation/control-flow/terminator.ts

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -159,24 +159,23 @@ export function generateCallTerminator<S extends Stack>(
159159
return ((state: State<S>): State<Stack> => {
160160
let currentState: State<Stack> = state as State<Stack>;
161161

162+
// All call setup instructions map back to the call
163+
// expression source location via operationDebug.
164+
const debug = term.operationDebug;
165+
162166
// Clean the stack before setting up the call.
163167
// Values produced by block instructions that are only
164168
// used as call arguments will have been DUP'd by
165169
// loadValue, leaving originals behind. Since this is a
166170
// block terminator, all current stack values are dead
167171
// after the call — POP them so the function receives a
168172
// clean stack with only its arguments.
169-
const cleanupDebug = {
170-
context: {
171-
remark: `call-preparation: clean stack for ${funcName}`,
172-
},
173-
};
174173
while (currentState.stack.length > 0) {
175174
currentState = {
176175
...currentState,
177176
instructions: [
178177
...currentState.instructions,
179-
{ mnemonic: "POP", opcode: 0x50, debug: cleanupDebug },
178+
{ mnemonic: "POP", opcode: 0x50, debug },
180179
],
181180
stack: currentState.stack.slice(1),
182181
brands: currentState.brands.slice(1) as Stack,
@@ -186,11 +185,6 @@ export function generateCallTerminator<S extends Stack>(
186185
const returnPcPatchIndex = currentState.instructions.length;
187186

188187
// Store return PC to memory at 0x60
189-
const returnPcDebug = {
190-
context: {
191-
remark: `call-preparation: store return address for ${funcName}`,
192-
},
193-
};
194188
currentState = {
195189
...currentState,
196190
instructions: [
@@ -199,10 +193,15 @@ export function generateCallTerminator<S extends Stack>(
199193
mnemonic: "PUSH2",
200194
opcode: 0x61,
201195
immediates: [0, 0],
202-
debug: returnPcDebug,
196+
debug,
203197
},
204-
{ mnemonic: "PUSH1", opcode: 0x60, immediates: [0x60] },
205-
{ mnemonic: "MSTORE", opcode: 0x52 },
198+
{
199+
mnemonic: "PUSH1",
200+
opcode: 0x60,
201+
immediates: [0x60],
202+
debug,
203+
},
204+
{ mnemonic: "MSTORE", opcode: 0x52, debug },
206205
],
207206
patches: [
208207
...currentState.patches,
@@ -217,24 +216,14 @@ export function generateCallTerminator<S extends Stack>(
217216
// Push arguments using loadValue.
218217
// Stack is clean, so loadValue will reload from memory
219218
// (for temps) or re-push (for consts).
220-
const argsDebug = {
221-
context: {
222-
remark: `call-arguments: push ${args.length} argument(s) for ${funcName}`,
223-
},
224-
};
225219
for (const arg of args) {
226-
currentState = loadValue(arg, { debug: argsDebug })(currentState);
220+
currentState = loadValue(arg, { debug })(currentState);
227221
}
228222

229223
// Push function address and jump.
230224
// The JUMP gets an invoke context: after JUMP executes,
231225
// the function has been entered with args on the stack.
232226
const funcAddrPatchIndex = currentState.instructions.length;
233-
const invocationDebug = {
234-
context: {
235-
remark: `call-invocation: jump to function ${funcName}`,
236-
},
237-
};
238227

239228
// Build argument pointers: after the JUMP, the callee
240229
// sees args on the stack in order (first arg deepest).
@@ -273,7 +262,7 @@ export function generateCallTerminator<S extends Stack>(
273262
mnemonic: "PUSH2",
274263
opcode: 0x61,
275264
immediates: [0, 0],
276-
debug: invocationDebug,
265+
debug,
277266
},
278267
{ mnemonic: "JUMP", opcode: 0x56, debug: invokeContext },
279268
],

0 commit comments

Comments
 (0)