@@ -1493,14 +1493,20 @@ def create_named_globals(metadata):
1493
1493
def create_runtime_funcs (exports ):
1494
1494
if shared .Settings .ONLY_MY_CODE :
1495
1495
return []
1496
- return ['''
1496
+
1497
+ if shared .Settings .ASSERTIONS or shared .Settings .STACK_OVERFLOW_CHECK >= 2 :
1498
+ stack_check = ' if ((STACKTOP|0) >= (STACK_MAX|0)) abortStackOverflow(size|0);\n '
1499
+ else :
1500
+ stack_check = ''
1501
+
1502
+ funcs = ['''
1497
1503
function stackAlloc(size) {
1498
1504
size = size|0;
1499
1505
var ret = 0;
1500
1506
ret = STACKTOP;
1501
1507
STACKTOP = (STACKTOP + size)|0;
1502
1508
STACKTOP = (STACKTOP + 15)&-16;
1503
- ''' + ( ' if ((STACKTOP|0) >= (STACK_MAX|0)) abortStackOverflow(size|0); \n ' if ( shared . Settings . ASSERTIONS or shared . Settings . STACK_OVERFLOW_CHECK >= 2 ) else '' ) + '''
1509
+ %s
1504
1510
return ret|0;
1505
1511
}
1506
1512
function stackSave() {
@@ -1516,15 +1522,32 @@ def create_runtime_funcs(exports):
1516
1522
STACKTOP = stackBase;
1517
1523
STACK_MAX = stackMax;
1518
1524
}
1519
- ''' + ('''
1525
+ function setThrew(threw, value) {
1526
+ threw = threw|0;
1527
+ value = value|0;
1528
+ if ((__THREW__|0) == 0) {
1529
+ __THREW__ = threw;
1530
+ threwValue = value;
1531
+ }
1532
+ }
1533
+ ''' % stack_check ]
1534
+
1535
+ if need_asyncify (exports ):
1536
+ funcs .append ('''
1520
1537
function setAsync() {
1521
1538
___async = 1;
1522
- }''' if need_asyncify (exports ) else '' ) + ('''
1539
+ }
1540
+ ''' )
1541
+
1542
+ if shared .Settings .EMTERPRETIFY :
1543
+ funcs .append ('''
1523
1544
function emterpret(pc) { // this will be replaced when the emterpreter code is generated; adding it here allows validation until then
1524
1545
pc = pc | 0;
1525
1546
assert(0);
1526
- }
1527
- ''' if shared .Settings .EMTERPRETIFY else '' ) + ('''
1547
+ }''' )
1548
+
1549
+ if shared .Settings .EMTERPRETIFY_ASYNC :
1550
+ funcs .append ('''
1528
1551
function setAsyncState(x) {
1529
1552
x = x | 0;
1530
1553
asyncState = x;
@@ -1543,21 +1566,18 @@ def create_runtime_funcs(exports):
1543
1566
x = x | 0;
1544
1567
EMT_STACK_MAX = x;
1545
1568
}
1546
- ''' if shared .Settings .EMTERPRETIFY_ASYNC else '' ) + '''
1547
- function setThrew(threw, value) {
1548
- threw = threw|0;
1549
- value = value|0;
1550
- if ((__THREW__|0) == 0) {
1551
- __THREW__ = threw;
1552
- threwValue = value;
1553
- }
1554
- }
1555
- ''' ] + ['' if not shared .Settings .SAFE_HEAP else '''
1569
+ ''' )
1570
+
1571
+ if shared .Settings .SAFE_HEAP :
1572
+ funcs .append ('''
1556
1573
function setDynamicTop(value) {
1557
1574
value = value | 0;
1558
1575
HEAP32[DYNAMICTOP_PTR>>2] = value;
1559
1576
}
1560
- ''' ] + ['' if not asm_safe_heap () else '''
1577
+ ''' )
1578
+
1579
+ if asm_safe_heap ():
1580
+ funcs .append ('''
1561
1581
function SAFE_HEAP_STORE(dest, value, bytes) {
1562
1582
dest = dest | 0;
1563
1583
value = value | 0;
@@ -1628,15 +1648,20 @@ def create_runtime_funcs(exports):
1628
1648
if ((ret|0) != (value|0)) ftfault();
1629
1649
return ret | 0;
1630
1650
}
1631
- ''' ] + ['''
1651
+ ''' )
1652
+
1653
+ if not shared .Settings .RELOCATABLE :
1654
+ funcs .append ('''
1632
1655
function setTempRet0(value) {
1633
1656
value = value|0;
1634
1657
tempRet0 = value;
1635
1658
}
1636
1659
function getTempRet0() {
1637
1660
return tempRet0|0;
1638
1661
}
1639
- ''' if not shared .Settings .RELOCATABLE else '' ]
1662
+ ''' )
1663
+
1664
+ return funcs
1640
1665
1641
1666
1642
1667
def create_asm_start_pre (asm_setup , the_global , sending , metadata ):
0 commit comments