Skip to content

Commit

Permalink
fix according to review
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Chen committed Apr 23, 2023
1 parent 4e5863d commit 05c63d0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ import {
PropertyPrototype,
IndexSignature,
File,
mangleInternalName
mangleInternalName,
DebugLocation
} from "./program";

import {
Expand Down Expand Up @@ -9830,8 +9831,7 @@ export class Compiler extends DiagnosticEmitter {
let targetFunction = this.currentFlow.targetFunction;
let source = range.source;
if (source.debugInfoIndex < 0) source.debugInfoIndex = this.module.addDebugInfoFile(source.normalizedPath);
range.debugInfo.set(targetFunction.internalName, expr);
targetFunction.debugLocations.push(range);
targetFunction.debugLocations.push(new DebugLocation(expr, range));
}

/** Checks whether a particular function signature is supported. */
Expand Down
2 changes: 0 additions & 2 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
DiagnosticCode,
diagnosticCodeToString
} from "./diagnosticMessages.generated";
import { ExpressionRef } from "./module";

import {
isLineBreak,
Expand Down Expand Up @@ -46,7 +45,6 @@ export const enum DiagnosticCategory {
export class Range {

source!: Source;
debugInfo: Map<string, ExpressionRef> = new Map<string, ExpressionRef>();

constructor(public start: i32, public end: i32) {}

Expand Down
22 changes: 14 additions & 8 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ export namespace OperatorKind {
return OperatorKind.Invalid;
}
}
/** DebugLocation for debug info generation */
export class DebugLocation {
/** Constructs a new Debug Location*/
constructor(
public expressionRef: ExpressionRef,
public range: Range) {}
}

/** Represents an AssemblyScript program. */
export class Program extends DiagnosticEmitter {
Expand Down Expand Up @@ -3746,7 +3753,7 @@ export class Function extends TypedElement {
/** Default control flow. */
flow!: Flow;
/** Remembered debug locations. */
debugLocations: Range[] = [];
debugLocations: DebugLocation[] = [];
/** Function reference, if compiled. */
ref: FunctionRef = 0;
/** Varargs stub for calling with omitted arguments. */
Expand Down Expand Up @@ -3913,15 +3920,14 @@ export class Function extends TypedElement {

addDebugInfo(module: Module, ref: FunctionRef): void {
if (this.program.options.sourceMap) {
let debugLocations = this.debugLocations;
for (let i = 0, k = debugLocations.length; i < k; ++i) {
let range = debugLocations[i];
let source = range.source;
const debugInfo = range.debugInfo.get(this.internalName);
assert(debugInfo);
const debugLocations = this.debugLocations;
for (let i = 0; i < debugLocations.length; ++i) {
const debugLocation = debugLocations[i];
const range = debugLocation.range;
const source = range.source;
module.setDebugLocation(
ref,
debugInfo as ExpressionRef,
debugLocation.expressionRef,
source.debugInfoIndex,
source.lineAt(range.start),
source.columnAt() - 1 // source maps are 0-based
Expand Down
31 changes: 29 additions & 2 deletions tests/compiler/template-debuginfo.debug.sourcemap.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1277,17 +1277,24 @@
(local.set $block|3
(local.get $block)
)
;;@ ~lib/rt/tlsf.ts:97:2
(br $label$3
;;@ ~lib/rt/tlsf.ts:97:9
(i32.add
;;@ ~lib/rt/tlsf.ts:97:27
(i32.add
(local.get $block|3)
;;@ ~lib/rt/tlsf.ts:97:54
(i32.const 4)
)
;;@ ~lib/rt/tlsf.ts:97:72
(i32.and
(call $~lib/rt/common/BLOCK#get:mmInfo
(local.get $block|3)
)
;;@ ~lib/rt/tlsf.ts:97:87
(i32.xor
;;@ ~lib/rt/tlsf.ts:97:88
(i32.const 3)
(i32.const -1)
)
Expand Down Expand Up @@ -3480,12 +3487,17 @@
(local.set $fl|6
(local.get $fl)
)
;;@ ~lib/rt/tlsf.ts:145:2
(br $label$8
;;@ ~lib/rt/tlsf.ts:145:9
(i32.load offset=4
;;@ ~lib/rt/tlsf.ts:146:4
(i32.add
(local.get $root|5)
;;@ ~lib/rt/tlsf.ts:146:31
(i32.shl
(local.get $fl|6)
;;@ ~lib/rt/tlsf.ts:146:37
(i32.const 2)
)
)
Expand Down Expand Up @@ -3631,19 +3643,27 @@
(local.get $slMap)
)
)
;;@ ~lib/rt/tlsf.ts:344:31
;;@ ~lib/rt/tlsf.ts:164:2
(br $label$14
;;@ ~lib/rt/tlsf.ts:164:9
(i32.load offset=96
;;@ ~lib/rt/tlsf.ts:165:4
(i32.add
(local.get $root|12)
;;@ ~lib/rt/tlsf.ts:165:31
(i32.shl
;;@ ~lib/rt/tlsf.ts:165:32
(i32.add
;;@ ~lib/rt/tlsf.ts:165:33
(i32.shl
(local.get $fl|13)
;;@ ~lib/rt/tlsf.ts:165:39
(i32.const 4)
)
;;@ ~lib/rt/tlsf.ts:165:50
(local.get $sl|14)
)
;;@ ~lib/rt/tlsf.ts:165:64
(i32.const 2)
)
)
Expand Down Expand Up @@ -4076,22 +4096,29 @@
(i32.and
;;@ ~lib/rt/tlsf.ts:371:4
(call $~lib/rt/common/BLOCK#get:mmInfo
;;@ ~lib/rt/tlsf.ts:97:2
(block $label$5 (result i32)
;;@ ~lib/rt/tlsf.ts:371:13
(local.set $block|6
(local.get $block)
)
;;@ ~lib/rt/tlsf.ts:97:2
(br $label$5
;;@ ~lib/rt/tlsf.ts:97:9
(i32.add
;;@ ~lib/rt/tlsf.ts:97:27
(i32.add
(local.get $block|6)
;;@ ~lib/rt/tlsf.ts:97:54
(i32.const 4)
)
;;@ ~lib/rt/tlsf.ts:97:72
(i32.and
(call $~lib/rt/common/BLOCK#get:mmInfo
(local.get $block|6)
)
;;@ ~lib/rt/tlsf.ts:97:87
(i32.xor
;;@ ~lib/rt/tlsf.ts:97:88
(i32.const 3)
(i32.const -1)
)
Expand Down

0 comments on commit 05c63d0

Please sign in to comment.