Skip to content

Commit 05c63d0

Browse files
author
Jesse Chen
committed
fix according to review
1 parent 4e5863d commit 05c63d0

File tree

4 files changed

+46
-15
lines changed

4 files changed

+46
-15
lines changed

src/compiler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ import {
9393
PropertyPrototype,
9494
IndexSignature,
9595
File,
96-
mangleInternalName
96+
mangleInternalName,
97+
DebugLocation
9798
} from "./program";
9899

99100
import {
@@ -9830,8 +9831,7 @@ export class Compiler extends DiagnosticEmitter {
98309831
let targetFunction = this.currentFlow.targetFunction;
98319832
let source = range.source;
98329833
if (source.debugInfoIndex < 0) source.debugInfoIndex = this.module.addDebugInfoFile(source.normalizedPath);
9833-
range.debugInfo.set(targetFunction.internalName, expr);
9834-
targetFunction.debugLocations.push(range);
9834+
targetFunction.debugLocations.push(new DebugLocation(expr, range));
98359835
}
98369836

98379837
/** Checks whether a particular function signature is supported. */

src/diagnostics.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
DiagnosticCode,
1212
diagnosticCodeToString
1313
} from "./diagnosticMessages.generated";
14-
import { ExpressionRef } from "./module";
1514

1615
import {
1716
isLineBreak,
@@ -46,7 +45,6 @@ export const enum DiagnosticCategory {
4645
export class Range {
4746

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

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

src/program.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,13 @@ export namespace OperatorKind {
422422
return OperatorKind.Invalid;
423423
}
424424
}
425+
/** DebugLocation for debug info generation */
426+
export class DebugLocation {
427+
/** Constructs a new Debug Location*/
428+
constructor(
429+
public expressionRef: ExpressionRef,
430+
public range: Range) {}
431+
}
425432

426433
/** Represents an AssemblyScript program. */
427434
export class Program extends DiagnosticEmitter {
@@ -3746,7 +3753,7 @@ export class Function extends TypedElement {
37463753
/** Default control flow. */
37473754
flow!: Flow;
37483755
/** Remembered debug locations. */
3749-
debugLocations: Range[] = [];
3756+
debugLocations: DebugLocation[] = [];
37503757
/** Function reference, if compiled. */
37513758
ref: FunctionRef = 0;
37523759
/** Varargs stub for calling with omitted arguments. */
@@ -3913,15 +3920,14 @@ export class Function extends TypedElement {
39133920

39143921
addDebugInfo(module: Module, ref: FunctionRef): void {
39153922
if (this.program.options.sourceMap) {
3916-
let debugLocations = this.debugLocations;
3917-
for (let i = 0, k = debugLocations.length; i < k; ++i) {
3918-
let range = debugLocations[i];
3919-
let source = range.source;
3920-
const debugInfo = range.debugInfo.get(this.internalName);
3921-
assert(debugInfo);
3923+
const debugLocations = this.debugLocations;
3924+
for (let i = 0; i < debugLocations.length; ++i) {
3925+
const debugLocation = debugLocations[i];
3926+
const range = debugLocation.range;
3927+
const source = range.source;
39223928
module.setDebugLocation(
39233929
ref,
3924-
debugInfo as ExpressionRef,
3930+
debugLocation.expressionRef,
39253931
source.debugInfoIndex,
39263932
source.lineAt(range.start),
39273933
source.columnAt() - 1 // source maps are 0-based

tests/compiler/template-debuginfo.debug.sourcemap.wat

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,17 +1277,24 @@
12771277
(local.set $block|3
12781278
(local.get $block)
12791279
)
1280+
;;@ ~lib/rt/tlsf.ts:97:2
12801281
(br $label$3
1282+
;;@ ~lib/rt/tlsf.ts:97:9
12811283
(i32.add
1284+
;;@ ~lib/rt/tlsf.ts:97:27
12821285
(i32.add
12831286
(local.get $block|3)
1287+
;;@ ~lib/rt/tlsf.ts:97:54
12841288
(i32.const 4)
12851289
)
1290+
;;@ ~lib/rt/tlsf.ts:97:72
12861291
(i32.and
12871292
(call $~lib/rt/common/BLOCK#get:mmInfo
12881293
(local.get $block|3)
12891294
)
1295+
;;@ ~lib/rt/tlsf.ts:97:87
12901296
(i32.xor
1297+
;;@ ~lib/rt/tlsf.ts:97:88
12911298
(i32.const 3)
12921299
(i32.const -1)
12931300
)
@@ -3480,12 +3487,17 @@
34803487
(local.set $fl|6
34813488
(local.get $fl)
34823489
)
3490+
;;@ ~lib/rt/tlsf.ts:145:2
34833491
(br $label$8
3492+
;;@ ~lib/rt/tlsf.ts:145:9
34843493
(i32.load offset=4
3494+
;;@ ~lib/rt/tlsf.ts:146:4
34853495
(i32.add
34863496
(local.get $root|5)
3497+
;;@ ~lib/rt/tlsf.ts:146:31
34873498
(i32.shl
34883499
(local.get $fl|6)
3500+
;;@ ~lib/rt/tlsf.ts:146:37
34893501
(i32.const 2)
34903502
)
34913503
)
@@ -3631,19 +3643,27 @@
36313643
(local.get $slMap)
36323644
)
36333645
)
3634-
;;@ ~lib/rt/tlsf.ts:344:31
3646+
;;@ ~lib/rt/tlsf.ts:164:2
36353647
(br $label$14
3648+
;;@ ~lib/rt/tlsf.ts:164:9
36363649
(i32.load offset=96
3650+
;;@ ~lib/rt/tlsf.ts:165:4
36373651
(i32.add
36383652
(local.get $root|12)
3653+
;;@ ~lib/rt/tlsf.ts:165:31
36393654
(i32.shl
3655+
;;@ ~lib/rt/tlsf.ts:165:32
36403656
(i32.add
3657+
;;@ ~lib/rt/tlsf.ts:165:33
36413658
(i32.shl
36423659
(local.get $fl|13)
3660+
;;@ ~lib/rt/tlsf.ts:165:39
36433661
(i32.const 4)
36443662
)
3663+
;;@ ~lib/rt/tlsf.ts:165:50
36453664
(local.get $sl|14)
36463665
)
3666+
;;@ ~lib/rt/tlsf.ts:165:64
36473667
(i32.const 2)
36483668
)
36493669
)
@@ -4076,22 +4096,29 @@
40764096
(i32.and
40774097
;;@ ~lib/rt/tlsf.ts:371:4
40784098
(call $~lib/rt/common/BLOCK#get:mmInfo
4079-
;;@ ~lib/rt/tlsf.ts:97:2
40804099
(block $label$5 (result i32)
4100+
;;@ ~lib/rt/tlsf.ts:371:13
40814101
(local.set $block|6
40824102
(local.get $block)
40834103
)
4104+
;;@ ~lib/rt/tlsf.ts:97:2
40844105
(br $label$5
4106+
;;@ ~lib/rt/tlsf.ts:97:9
40854107
(i32.add
4108+
;;@ ~lib/rt/tlsf.ts:97:27
40864109
(i32.add
40874110
(local.get $block|6)
4111+
;;@ ~lib/rt/tlsf.ts:97:54
40884112
(i32.const 4)
40894113
)
4114+
;;@ ~lib/rt/tlsf.ts:97:72
40904115
(i32.and
40914116
(call $~lib/rt/common/BLOCK#get:mmInfo
40924117
(local.get $block|6)
40934118
)
4119+
;;@ ~lib/rt/tlsf.ts:97:87
40944120
(i32.xor
4121+
;;@ ~lib/rt/tlsf.ts:97:88
40954122
(i32.const 3)
40964123
(i32.const -1)
40974124
)

0 commit comments

Comments
 (0)