compress type info of zeroinitializers in ta2
This commit is contained in:
Родитель
2c815155ae
Коммит
91ae9b1233
|
@ -1265,6 +1265,9 @@ function makePointer(slab, pos, allocator, type) {
|
|||
de = dedup(evaled);
|
||||
if (de.length === 1 && de[0] === 0) {
|
||||
slab = types.length;
|
||||
if (USE_TYPED_ARRAYS == 2) {
|
||||
types = ['i8']; // if data is zeros, we don't need type info
|
||||
}
|
||||
}
|
||||
// TODO: if not all zeros, at least filter out items with type === 0. requires cleverness to know how to skip at runtime though. also
|
||||
// be careful of structure padding
|
||||
|
|
|
@ -2466,6 +2466,30 @@ c5,de,15,8a
|
|||
'''
|
||||
self.do_run(src, '*70,97,15,3,3029,90*')
|
||||
|
||||
def test_bigarray(self):
|
||||
if self.emcc_args is None: return self.skip('need ta2 to compress type data on zeroinitializers')
|
||||
|
||||
# avoid "array initializer too large" errors
|
||||
src = r'''
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define SIZE (1024*100)
|
||||
struct Struct {
|
||||
char x;
|
||||
int y;
|
||||
};
|
||||
Struct buffy[SIZE];
|
||||
|
||||
int main() {
|
||||
for (int i = 0; i < SIZE; i++) { assert(buffy[i].x == 0 && buffy[i].y == 0); } // we were zeroinitialized
|
||||
for (int i = 0; i < SIZE; i++) { buffy[i].x = i*i; buffy[i].y = i*i*i; } // we can save data
|
||||
printf("*%d*\n", buffy[SIZE/3].x);
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
self.do_run(src, '*57*')
|
||||
|
||||
def test_mod_globalstruct(self):
|
||||
src = '''
|
||||
#include <stdio.h>
|
||||
|
|
Загрузка…
Ссылка в новой задаче