Skip to content

Commit e21c600

Browse files
authored
Cleanup create_runtime_funcs. NFC. (#7272)
1 parent 58ddfa9 commit e21c600

File tree

1 file changed

+44
-19
lines changed

1 file changed

+44
-19
lines changed

emscripten.py

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,14 +1493,20 @@ def create_named_globals(metadata):
14931493
def create_runtime_funcs(exports):
14941494
if shared.Settings.ONLY_MY_CODE:
14951495
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 = ['''
14971503
function stackAlloc(size) {
14981504
size = size|0;
14991505
var ret = 0;
15001506
ret = STACKTOP;
15011507
STACKTOP = (STACKTOP + size)|0;
15021508
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
15041510
return ret|0;
15051511
}
15061512
function stackSave() {
@@ -1516,15 +1522,32 @@ def create_runtime_funcs(exports):
15161522
STACKTOP = stackBase;
15171523
STACK_MAX = stackMax;
15181524
}
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('''
15201537
function setAsync() {
15211538
___async = 1;
1522-
}''' if need_asyncify(exports) else '') + ('''
1539+
}
1540+
''')
1541+
1542+
if shared.Settings.EMTERPRETIFY:
1543+
funcs.append('''
15231544
function emterpret(pc) { // this will be replaced when the emterpreter code is generated; adding it here allows validation until then
15241545
pc = pc | 0;
15251546
assert(0);
1526-
}
1527-
''' if shared.Settings.EMTERPRETIFY else '') + ('''
1547+
}''')
1548+
1549+
if shared.Settings.EMTERPRETIFY_ASYNC:
1550+
funcs.append('''
15281551
function setAsyncState(x) {
15291552
x = x | 0;
15301553
asyncState = x;
@@ -1543,21 +1566,18 @@ def create_runtime_funcs(exports):
15431566
x = x | 0;
15441567
EMT_STACK_MAX = x;
15451568
}
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('''
15561573
function setDynamicTop(value) {
15571574
value = value | 0;
15581575
HEAP32[DYNAMICTOP_PTR>>2] = value;
15591576
}
1560-
'''] + ['' if not asm_safe_heap() else '''
1577+
''')
1578+
1579+
if asm_safe_heap():
1580+
funcs.append('''
15611581
function SAFE_HEAP_STORE(dest, value, bytes) {
15621582
dest = dest | 0;
15631583
value = value | 0;
@@ -1628,15 +1648,20 @@ def create_runtime_funcs(exports):
16281648
if ((ret|0) != (value|0)) ftfault();
16291649
return ret | 0;
16301650
}
1631-
'''] + ['''
1651+
''')
1652+
1653+
if not shared.Settings.RELOCATABLE:
1654+
funcs.append('''
16321655
function setTempRet0(value) {
16331656
value = value|0;
16341657
tempRet0 = value;
16351658
}
16361659
function getTempRet0() {
16371660
return tempRet0|0;
16381661
}
1639-
''' if not shared.Settings.RELOCATABLE else '']
1662+
''')
1663+
1664+
return funcs
16401665

16411666

16421667
def create_asm_start_pre(asm_setup, the_global, sending, metadata):

0 commit comments

Comments
 (0)