generate separate function table wrappers for a single library function aliased with different signatures

This commit is contained in:
Alon Zakai 2013-08-16 11:39:04 -07:00
Родитель 52f2d45d07
Коммит ab64522963
3 изменённых файлов: 19 добавлений и 6 удалений

Просмотреть файл

@ -321,7 +321,7 @@ var Functions = {
tables[sig][index] = ident;
}
var generated = false;
var wrapped = {};
var wrapped = {}; // whether we wrapped a lib func
var maxTable = 0;
for (var t in tables) {
if (t == 'pre') continue;
@ -344,10 +344,11 @@ var Functions = {
if (ASM_JS) {
var curr = table[i];
if (curr && curr != '0' && !Functions.implementedFunctions[curr]) {
curr = toNiceIdent(curr); // fix Math.* to Math_*
var short = toNiceIdent(curr); // fix Math.* to Math_*
curr = t + '_' + short; // libfuncs can alias with different sigs, wrap each separately
// This is a library function, we can't just put it in the function table, need a wrapper
if (!wrapped[curr]) {
var args = '', arg_coercions = '', call = curr + '(', retPre = '', retPost = '';
var args = '', arg_coercions = '', call = short + '(', retPre = '', retPost = '';
if (t[0] != 'v') {
if (t[0] == 'i') {
retPre = 'return ';
@ -362,7 +363,7 @@ var Functions = {
call += (j > 1 ? ',' : '') + asmCoercion('a' + j, t[j] != 'i' ? 'float' : 'i32');
}
call += ')';
if (curr == '_setjmp') printErr('WARNING: setjmp used via a function pointer. If this is for libc setjmp (not something of your own with the same name), it will break things');
if (short == '_setjmp') printErr('WARNING: setjmp used via a function pointer. If this is for libc setjmp (not something of your own with the same name), it will break things');
tables.pre += 'function ' + curr + '__wrapper(' + args + ') { ' + arg_coercions + ' ; ' + retPre + call + retPost + ' }\n';
wrapped[curr] = 1;
}

Просмотреть файл

@ -161,7 +161,7 @@ int main(int argc, char *argv[])
for (int x = 0; x < n; x++) {
int start = x*w*2;
glBegin( GL_TRIANGLES );
glTexCoord2i( 1, 0 ); glVertex3f( start , 0, 0 );
glTexCoord2i( 1, 0 ); glVertex2i( start , 0 );
glTexCoord2i( 0, 0 ); glVertex3f( start+w, 300, 0 );
glTexCoord2i( 1, 1 ); glVertex3f( start-w, 300, 0 );
glEnd();
@ -209,5 +209,11 @@ int main(int argc, char *argv[])
SDL_Quit();
return 0;
// check for asm compilation bug with aliased functions with different sigs
void (*f)(int, int) = glVertex2i;
if ((int)f % 16 == 4) f(5, 7);
void (*g)(int, int) = glVertex3f;
if ((int)g % 16 == 4) g(5, 7);
return (int)f + (int)g;
}

Просмотреть файл

@ -1323,6 +1323,12 @@ Press any key to continue.'''
self.btest('s3tc_crunch.c', reference='s3tc_crunch.png', reference_slack=11, args=['--pre-js', 'asset_a.js', '--pre-js', 'asset_b.js', '-s', 'LEGACY_GL_EMULATION=1'])
def test_aniso(self):
if SPIDERMONKEY_ENGINE in JS_ENGINES:
# asm.js-ification check
Popen([PYTHON, EMCC, path_from_root('tests', 'aniso.c'), '-O2', '-g2', '-s', 'LEGACY_GL_EMULATION=1']).communicate()
Settings.ASM_JS = 1
self.run_generated_code(SPIDERMONKEY_ENGINE, 'a.out.js')
shutil.copyfile(path_from_root('tests', 'water.dds'), 'water.dds')
self.btest('aniso.c', reference='aniso.png', reference_slack=2, args=['--preload-file', 'water.dds', '-s', 'LEGACY_GL_EMULATION=1'])