Skip to content

Commit 25a1f62

Browse files
committed
Suppress some unnecessary blocks and nops; Fix compilation of always 'break'ing 'do's
1 parent 2f8f477 commit 25a1f62

45 files changed

Lines changed: 1280 additions & 1604 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dist/asc.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/asc.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assemblyscript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assemblyscript.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler.ts

Lines changed: 111 additions & 95 deletions
Large diffs are not rendered by default.

src/program.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,7 +2798,7 @@ export class Function extends Element {
27982798
/** Current control flow. */
27992799
flow: Flow;
28002800
/** Remembered debug locations. */
2801-
debugLocations: Range[] | null = null;
2801+
debugLocations: Range[] = [];
28022802
/** Function reference, if compiled. */
28032803
ref: FunctionRef = 0;
28042804
/** Function table index, if any. */
@@ -2996,11 +2996,8 @@ export class Function extends Element {
29962996
/** Enters a(nother) break context. */
29972997
enterBreakContext(): string {
29982998
var id = this.nextBreakId++;
2999-
if (!this.breakStack) {
3000-
this.breakStack = [ id ];
3001-
} else {
3002-
this.breakStack.push(id);
3003-
}
2999+
if (!this.breakStack) this.breakStack = [ id ];
3000+
else this.breakStack.push(id);
30043001
return this.breakContext = id.toString(10);
30053002
}
30063003

@@ -3027,20 +3024,17 @@ export class Function extends Element {
30273024
this.tempI32s = this.tempI64s = this.tempF32s = this.tempF64s = null;
30283025
if (this.program.options.sourceMap) {
30293026
let debugLocations = this.debugLocations;
3030-
if (debugLocations) {
3031-
for (let i = 0, k = debugLocations.length; i < k; ++i) {
3032-
let debugLocation = debugLocations[i];
3033-
module.setDebugLocation(
3034-
ref,
3035-
debugLocation.debugInfoRef,
3036-
debugLocation.source.debugInfoIndex,
3037-
debugLocation.line,
3038-
debugLocation.column
3039-
);
3040-
}
3027+
for (let i = 0, k = debugLocations.length; i < k; ++i) {
3028+
let debugLocation = debugLocations[i];
3029+
module.setDebugLocation(
3030+
ref,
3031+
debugLocation.debugInfoRef,
3032+
debugLocation.source.debugInfoIndex,
3033+
debugLocation.line,
3034+
debugLocation.column
3035+
);
30413036
}
30423037
}
3043-
this.debugLocations = null;
30443038
}
30453039

30463040
/** Returns the TypeScript representation of this function. */
@@ -3633,6 +3627,8 @@ export class Flow {
36333627

36343628
/** Tests if this flow has the specified flag or flags. */
36353629
is(flag: FlowFlags): bool { return (this.flags & flag) == flag; }
3630+
/** Tests if this flow has one of the specified flags. */
3631+
isAny(flag: CommonFlags): bool { return (this.flags & flag) != 0; }
36363632
/** Sets the specified flag or flags. */
36373633
set(flag: FlowFlags): void { this.flags |= flag; }
36383634
/** Unsets the specified flag or flags. */

std/assembly/polyfills.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ export function bswap<T>(value: T): T {
33

44
if (sizeof<T>() == 2) {
55
return bswap16<T>(value);
6-
} else if (sizeof<T>() == 4) {
6+
}
7+
if (sizeof<T>() == 4) {
78
return <T>(
89
rotl<u32>(<u32>value & 0xFF00FF00, 8) |
910
rotr<u32>(<u32>value & 0x00FF00FF, 8)
1011
);
11-
} else if (sizeof<T>() == 8) {
12+
}
13+
if (sizeof<T>() == 8) {
1214
let a: u64 = (<u64>value >> 8) & 0x00FF00FF00FF00FF;
1315
let b: u64 = (<u64>value & 0x00FF00FF00FF00FF) << 8;
1416
let v: u64 = a | b;

tests/compiler/abi.untouched.wat

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
)
6161
)
6262
(block
63-
(nop)
6463
(set_local $0
6564
(i32.const 256)
6665
)
@@ -88,7 +87,6 @@
8887
)
8988
)
9089
(block
91-
(nop)
9290
(set_local $1
9391
(i32.const 256)
9492
)
@@ -143,7 +141,6 @@
143141
)
144142
)
145143
(block
146-
(nop)
147144
(set_local $2
148145
(i32.const 256)
149146
)
@@ -213,7 +210,6 @@
213210
)
214211
)
215212
(block
216-
(nop)
217213
(set_local $3
218214
(i32.ctz
219215
(i32.const 2)
@@ -258,7 +254,6 @@
258254
(unreachable)
259255
)
260256
)
261-
(nop)
262257
(set_local $4
263258
(i32.ctz
264259
(i32.const 2)

tests/compiler/binary.untouched.wat

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
(start $start)
2222
(func $~lib/math/NativeMath.scalbn (; 0 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64)
2323
(local $2 f64)
24-
(nop)
2524
(set_local $2
2625
(get_local $0)
2726
)
@@ -180,7 +179,6 @@
180179
(local $38 f64)
181180
(local $39 f64)
182181
(local $40 i32)
183-
(nop)
184182
(set_local $2
185183
(i64.reinterpret/f64
186184
(get_local $0)
@@ -652,8 +650,6 @@
652650
)
653651
)
654652
)
655-
(nop)
656-
(nop)
657653
(if
658654
(i32.gt_s
659655
(get_local $8)
@@ -840,7 +836,6 @@
840836
)
841837
)
842838
(block
843-
(nop)
844839
(set_local $27
845840
(i32.const 0)
846841
)
@@ -1829,7 +1824,6 @@
18291824
)
18301825
)
18311826
)
1832-
(nop)
18331827
(if
18341828
(i32.eqz
18351829
(get_local $4)
@@ -2142,7 +2136,6 @@
21422136
)
21432137
(func $~lib/math/NativeMathf.scalbn (; 4 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32)
21442138
(local $2 f32)
2145-
(nop)
21462139
(set_local $2
21472140
(get_local $0)
21482141
)
@@ -2295,7 +2288,6 @@
22952288
(local $34 f32)
22962289
(local $35 f32)
22972290
(local $36 i32)
2298-
(nop)
22992291
(set_local $2
23002292
(i32.reinterpret/f32
23012293
(get_local $0)
@@ -2509,7 +2501,6 @@
25092501
(get_local $0)
25102502
)
25112503
)
2512-
(nop)
25132504
(if
25142505
(if (result i32)
25152506
(tee_local $6
@@ -2633,8 +2624,6 @@
26332624
)
26342625
)
26352626
)
2636-
(nop)
2637-
(nop)
26382627
(if
26392628
(i32.gt_s
26402629
(get_local $5)
@@ -2772,7 +2761,6 @@
27722761
)
27732762
)
27742763
(block
2775-
(nop)
27762764
(set_local $23
27772765
(i32.const 0)
27782766
)
@@ -3710,7 +3698,6 @@
37103698
)
37113699
)
37123700
)
3713-
(nop)
37143701
(if
37153702
(i32.eqz
37163703
(get_local $4)

tests/compiler/builtins.untouched.wat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
)
6565
)
6666
(func $builtins/test (; 5 ;) (type $v)
67+
(nop)
6768
)
6869
(func $start (; 6 ;) (type $v)
6970
(local $0 i32)

0 commit comments

Comments
 (0)