aboutsummaryrefslogtreecommitdiff
path: root/mesalib
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib')
-rw-r--r--mesalib/scons/crossmingw.py399
-rw-r--r--mesalib/src/glsl/ast_function.cpp2
-rw-r--r--mesalib/src/glsl/glcpp/glcpp-parse.y7
-rw-r--r--mesalib/src/glsl/ir_constant_expression.cpp36
4 files changed, 237 insertions, 207 deletions
diff --git a/mesalib/scons/crossmingw.py b/mesalib/scons/crossmingw.py
index bac51de07..cc046229e 100644
--- a/mesalib/scons/crossmingw.py
+++ b/mesalib/scons/crossmingw.py
@@ -1,198 +1,201 @@
-"""SCons.Tool.gcc
-
-Tool-specific initialization for MinGW (http://www.mingw.org/)
-
-There normally shouldn't be any need to import this module directly.
-It will usually be imported through the generic SCons.Tool.Tool()
-selection method.
-
-See also http://www.scons.org/wiki/CrossCompilingMingw
-"""
-
-#
-# Copyright (c) 2001, 2002, 2003, 2004 The SCons Foundation
-#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be included
-# in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
-# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
-# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-
-import os
-import os.path
-import string
-
-import SCons.Action
-import SCons.Builder
-import SCons.Tool
-import SCons.Util
-
-# This is what we search for to find mingw:
-prefixes32 = SCons.Util.Split("""
- mingw32-
- mingw32msvc-
- i386-mingw32-
- i486-mingw32-
- i586-mingw32-
- i686-mingw32-
- i386-mingw32msvc-
- i486-mingw32msvc-
- i586-mingw32msvc-
- i686-mingw32msvc-
- i686-pc-mingw32-
- i686-w64-mingw32-
-""")
-prefixes64 = SCons.Util.Split("""
- amd64-mingw32-
- amd64-mingw32msvc-
- amd64-pc-mingw32-
- x86_64-w64-mingw32-
-""")
-
-def find(env):
- if env['machine'] == 'x86_64':
- prefixes = prefixes64
- else:
- prefixes = prefixes32
- for prefix in prefixes:
- # First search in the SCons path and then the OS path:
- if env.WhereIs(prefix + 'gcc') or SCons.Util.WhereIs(prefix + 'gcc'):
- return prefix
-
- return ''
-
-def shlib_generator(target, source, env, for_signature):
- cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS'])
-
- dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
- if dll: cmd.extend(['-o', dll])
-
- cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
-
- implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
- if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature))
-
- def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
- if def_target: cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature))
-
- return [cmd]
-
-def shlib_emitter(target, source, env):
- dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
- no_import_lib = env.get('no_import_lib', 0)
-
- if not dll:
- raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX")
-
- if not no_import_lib and \
- not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'):
-
- # Append an import library to the list of targets.
- target.append(env.ReplaceIxes(dll,
- 'SHLIBPREFIX', 'SHLIBSUFFIX',
- 'LIBPREFIX', 'LIBSUFFIX'))
-
- # Append a def file target if there isn't already a def file target
- # or a def file source. There is no option to disable def file
- # target emitting, because I can't figure out why someone would ever
- # want to turn it off.
- def_source = env.FindIxes(source, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
- def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
- if not def_source and not def_target:
- target.append(env.ReplaceIxes(dll,
- 'SHLIBPREFIX', 'SHLIBSUFFIX',
- 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX'))
-
- return (target, source)
-
-
-shlib_action = SCons.Action.Action(shlib_generator, '$SHLINKCOMSTR', generator=1)
-
-res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
-
-res_builder = SCons.Builder.Builder(action=res_action, suffix='.o',
- source_scanner=SCons.Tool.SourceFileScanner)
-SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
-
-def generate(env):
- mingw_prefix = find(env)
-
- if mingw_prefix:
- dir = os.path.dirname(env.WhereIs(mingw_prefix + 'gcc') or SCons.Util.WhereIs(mingw_prefix + 'gcc'))
-
- # The mingw bin directory must be added to the path:
- path = env['ENV'].get('PATH', [])
- if not path:
- path = []
- if SCons.Util.is_String(path):
- path = string.split(path, os.pathsep)
-
- env['ENV']['PATH'] = string.join([dir] + path, os.pathsep)
-
- # Most of mingw is the same as gcc and friends...
- gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas']
- for tool in gnu_tools:
- SCons.Tool.Tool(tool)(env)
-
- #... but a few things differ:
- env['CC'] = mingw_prefix + 'gcc'
- env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
- env['CXX'] = mingw_prefix + 'g++'
- env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
- env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
- env['SHLINKCOM'] = shlib_action
- env.Append(SHLIBEMITTER = [shlib_emitter])
- env['LINK'] = mingw_prefix + 'g++'
- env['AR'] = mingw_prefix + 'ar'
- env['RANLIB'] = mingw_prefix + 'ranlib'
- env['LINK'] = mingw_prefix + 'g++'
- env['AS'] = mingw_prefix + 'as'
- env['WIN32DEFPREFIX'] = ''
- env['WIN32DEFSUFFIX'] = '.def'
- env['SHOBJSUFFIX'] = '.o'
- env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
-
- env['RC'] = mingw_prefix + 'windres'
- env['RCFLAGS'] = SCons.Util.CLVar('')
- env['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS ${INCPREFIX}${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET'
- env['BUILDERS']['RES'] = res_builder
-
- # Some setting from the platform also have to be overridden:
- env['OBJPREFIX'] = ''
- env['OBJSUFFIX'] = '.o'
- env['SHOBJPREFIX'] = '$OBJPREFIX'
- env['SHOBJSUFFIX'] = '$OBJSUFFIX'
- env['PROGPREFIX'] = ''
- env['PROGSUFFIX'] = '.exe'
- env['LIBPREFIX'] = 'lib'
- env['LIBSUFFIX'] = '.a'
- env['SHLIBPREFIX'] = ''
- env['SHLIBSUFFIX'] = '.dll'
- env['LIBPREFIXES'] = [ 'lib', '' ]
- env['LIBSUFFIXES'] = [ '.a', '.lib' ]
-
- # MinGW port of gdb does not handle well dwarf debug info which is the
- # default in recent gcc versions
- env.AppendUnique(CCFLAGS = ['-gstabs'])
-
- env.AppendUnique(CPPDEFINES = [('__MSVCRT_VERSION__', '0x0700')])
- #env.AppendUnique(LIBS = ['iberty'])
- env.AppendUnique(SHLINKFLAGS = ['-Wl,--enable-stdcall-fixup'])
- #env.AppendUnique(SHLINKFLAGS = ['-Wl,--kill-at'])
-
-def exists(env):
- return find(env)
+"""SCons.Tool.gcc
+
+Tool-specific initialization for MinGW (http://www.mingw.org/)
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+See also http://www.scons.org/wiki/CrossCompilingMingw
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+import os
+import os.path
+import string
+
+import SCons.Action
+import SCons.Builder
+import SCons.Tool
+import SCons.Util
+
+# This is what we search for to find mingw:
+prefixes32 = SCons.Util.Split("""
+ mingw32-
+ mingw32msvc-
+ i386-mingw32-
+ i486-mingw32-
+ i586-mingw32-
+ i686-mingw32-
+ i386-mingw32msvc-
+ i486-mingw32msvc-
+ i586-mingw32msvc-
+ i686-mingw32msvc-
+ i686-pc-mingw32-
+ i686-w64-mingw32-
+""")
+prefixes64 = SCons.Util.Split("""
+ amd64-mingw32-
+ amd64-mingw32msvc-
+ amd64-pc-mingw32-
+ x86_64-w64-mingw32-
+""")
+
+def find(env):
+ if env['machine'] == 'x86_64':
+ prefixes = prefixes64
+ else:
+ prefixes = prefixes32
+ for prefix in prefixes:
+ # First search in the SCons path and then the OS path:
+ if env.WhereIs(prefix + 'gcc') or SCons.Util.WhereIs(prefix + 'gcc'):
+ return prefix
+
+ return ''
+
+def shlib_generator(target, source, env, for_signature):
+ cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS'])
+
+ dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
+ if dll: cmd.extend(['-o', dll])
+
+ cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
+
+ implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
+ if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature))
+
+ def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
+ if def_target: cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature))
+
+ return [cmd]
+
+def shlib_emitter(target, source, env):
+ dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
+ no_import_lib = env.get('no_import_lib', 0)
+
+ if not dll:
+ raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX")
+
+ if not no_import_lib and \
+ not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'):
+
+ # Append an import library to the list of targets.
+ target.append(env.ReplaceIxes(dll,
+ 'SHLIBPREFIX', 'SHLIBSUFFIX',
+ 'LIBPREFIX', 'LIBSUFFIX'))
+
+ # Append a def file target if there isn't already a def file target
+ # or a def file source. There is no option to disable def file
+ # target emitting, because I can't figure out why someone would ever
+ # want to turn it off.
+ def_source = env.FindIxes(source, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
+ def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
+ if not def_source and not def_target:
+ target.append(env.ReplaceIxes(dll,
+ 'SHLIBPREFIX', 'SHLIBSUFFIX',
+ 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX'))
+
+ return (target, source)
+
+
+shlib_action = SCons.Action.Action(shlib_generator, '$SHLINKCOMSTR', generator=1)
+
+res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
+
+res_builder = SCons.Builder.Builder(action=res_action, suffix='.o',
+ source_scanner=SCons.Tool.SourceFileScanner)
+SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
+
+def generate(env):
+ mingw_prefix = find(env)
+
+ if mingw_prefix:
+ dir = os.path.dirname(env.WhereIs(mingw_prefix + 'gcc') or SCons.Util.WhereIs(mingw_prefix + 'gcc'))
+
+ # The mingw bin directory must be added to the path:
+ path = env['ENV'].get('PATH', [])
+ if not path:
+ path = []
+ if SCons.Util.is_String(path):
+ path = string.split(path, os.pathsep)
+
+ env['ENV']['PATH'] = string.join([dir] + path, os.pathsep)
+
+ # Most of mingw is the same as gcc and friends...
+ gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas']
+ for tool in gnu_tools:
+ SCons.Tool.Tool(tool)(env)
+
+ #... but a few things differ:
+ env['CC'] = mingw_prefix + 'gcc'
+ env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
+ env['CXX'] = mingw_prefix + 'g++'
+ env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
+ env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
+ env['SHLINKCOM'] = shlib_action
+ env.Append(SHLIBEMITTER = [shlib_emitter])
+ env['LINK'] = mingw_prefix + 'g++'
+ env['AR'] = mingw_prefix + 'ar'
+ env['RANLIB'] = mingw_prefix + 'ranlib'
+ env['LINK'] = mingw_prefix + 'g++'
+ env['AS'] = mingw_prefix + 'as'
+ env['WIN32DEFPREFIX'] = ''
+ env['WIN32DEFSUFFIX'] = '.def'
+ env['SHOBJSUFFIX'] = '.o'
+ env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
+
+ env['RC'] = mingw_prefix + 'windres'
+ env['RCFLAGS'] = SCons.Util.CLVar('')
+ env['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS ${INCPREFIX}${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET'
+ env['BUILDERS']['RES'] = res_builder
+
+ # Some setting from the platform also have to be overridden:
+ env['OBJPREFIX'] = ''
+ env['OBJSUFFIX'] = '.o'
+ env['SHOBJPREFIX'] = '$OBJPREFIX'
+ env['SHOBJSUFFIX'] = '$OBJSUFFIX'
+ env['PROGPREFIX'] = ''
+ env['PROGSUFFIX'] = '.exe'
+ env['LIBPREFIX'] = 'lib'
+ env['LIBSUFFIX'] = '.a'
+ env['SHLIBPREFIX'] = ''
+ env['SHLIBSUFFIX'] = '.dll'
+ env['LIBPREFIXES'] = [ 'lib', '' ]
+ env['LIBSUFFIXES'] = [ '.a', '.lib' ]
+
+ # MinGW port of gdb does not handle well dwarf debug info which is the
+ # default in recent gcc versions
+ env.AppendUnique(CCFLAGS = ['-gstabs'])
+
+ env.AppendUnique(CPPDEFINES = [('__MSVCRT_VERSION__', '0x0700')])
+ #env.AppendUnique(LIBS = ['iberty'])
+ env.AppendUnique(SHLINKFLAGS = ['-Wl,--enable-stdcall-fixup'])
+ #env.AppendUnique(SHLINKFLAGS = ['-Wl,--kill-at'])
+
+ # Avoid depending on gcc runtime DLLs
+ env.AppendUnique(LINKFLAGS = ['-static-libgcc'])
+
+def exists(env):
+ return find(env)
diff --git a/mesalib/src/glsl/ast_function.cpp b/mesalib/src/glsl/ast_function.cpp
index 28d49ee0d..7611617df 100644
--- a/mesalib/src/glsl/ast_function.cpp
+++ b/mesalib/src/glsl/ast_function.cpp
@@ -75,7 +75,7 @@ prototype_string(const glsl_type *return_type, const char *name,
char *str = NULL;
if (return_type != NULL)
- ralloc_asprintf(&str, "%s ", return_type->name);
+ str = ralloc_asprintf(NULL, "%s ", return_type->name);
ralloc_asprintf_append(&str, "%s(", name);
diff --git a/mesalib/src/glsl/glcpp/glcpp-parse.y b/mesalib/src/glsl/glcpp/glcpp-parse.y
index aa5a0c4f2..1f6e67fa0 100644
--- a/mesalib/src/glsl/glcpp/glcpp-parse.y
+++ b/mesalib/src/glsl/glcpp/glcpp-parse.y
@@ -388,7 +388,12 @@ expression:
$$ = $1 + $3;
}
| expression '%' expression {
- $$ = $1 % $3;
+ if ($3 == 0) {
+ yyerror (& @1, parser,
+ "zero modulus in preprocessor directive");
+ } else {
+ $$ = $1 % $3;
+ }
}
| expression '/' expression {
if ($3 == 0) {
diff --git a/mesalib/src/glsl/ir_constant_expression.cpp b/mesalib/src/glsl/ir_constant_expression.cpp
index cf958aa7a..2841fb350 100644
--- a/mesalib/src/glsl/ir_constant_expression.cpp
+++ b/mesalib/src/glsl/ir_constant_expression.cpp
@@ -288,20 +288,24 @@ ir_expression::constant_expression_value()
break;
case ir_unop_rcp:
+ /* FINISHME: Emit warning when division-by-zero is detected. */
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
for (unsigned c = 0; c < op[0]->type->components(); c++) {
switch (this->type->base_type) {
case GLSL_TYPE_UINT:
- if (op[0]->value.u[c] != 0.0)
- data.u[c] = 1 / op[0]->value.u[c];
+ if (op[0]->value.u[c] == 0.0)
+ return NULL;
+ data.u[c] = 1 / op[0]->value.u[c];
break;
case GLSL_TYPE_INT:
- if (op[0]->value.i[c] != 0.0)
- data.i[c] = 1 / op[0]->value.i[c];
+ if (op[0]->value.i[c] == 0.0)
+ return NULL;
+ data.i[c] = 1 / op[0]->value.i[c];
break;
case GLSL_TYPE_FLOAT:
- if (op[0]->value.f[c] != 0.0)
- data.f[c] = 1.0F / op[0]->value.f[c];
+ if (op[0]->value.f[c] == 0.0)
+ return NULL;
+ data.f[c] = 1.0F / op[0]->value.f[c];
break;
default:
assert(0);
@@ -310,9 +314,13 @@ ir_expression::constant_expression_value()
break;
case ir_unop_rsq:
+ /* FINISHME: Emit warning when division-by-zero is detected. */
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = 1.0F / sqrtf(op[0]->value.f[c]);
+ float s = sqrtf(op[0]->value.f[c]);
+ if (s == 0)
+ return NULL;
+ data.f[c] = 1.0F / s;
}
break;
@@ -507,6 +515,7 @@ ir_expression::constant_expression_value()
break;
case ir_binop_div:
+ /* FINISHME: Emit warning when division-by-zero is detected. */
assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
for (unsigned c = 0, c0 = 0, c1 = 0;
c < components;
@@ -514,12 +523,18 @@ ir_expression::constant_expression_value()
switch (op[0]->type->base_type) {
case GLSL_TYPE_UINT:
+ if (op[1]->value.u[c1] == 0)
+ return NULL;
data.u[c] = op[0]->value.u[c0] / op[1]->value.u[c1];
break;
case GLSL_TYPE_INT:
+ if (op[1]->value.i[c1] == 0)
+ return NULL;
data.i[c] = op[0]->value.i[c0] / op[1]->value.i[c1];
break;
case GLSL_TYPE_FLOAT:
+ if (op[1]->value.f[c1] == 0)
+ return NULL;
data.f[c] = op[0]->value.f[c0] / op[1]->value.f[c1];
break;
default:
@@ -529,6 +544,7 @@ ir_expression::constant_expression_value()
break;
case ir_binop_mod:
+ /* FINISHME: Emit warning when division-by-zero is detected. */
assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
for (unsigned c = 0, c0 = 0, c1 = 0;
c < components;
@@ -536,12 +552,18 @@ ir_expression::constant_expression_value()
switch (op[0]->type->base_type) {
case GLSL_TYPE_UINT:
+ if (op[1]->value.u[c1] == 0)
+ return NULL;
data.u[c] = op[0]->value.u[c0] % op[1]->value.u[c1];
break;
case GLSL_TYPE_INT:
+ if (op[1]->value.i[c1] == 0)
+ return NULL;
data.i[c] = op[0]->value.i[c0] % op[1]->value.i[c1];
break;
case GLSL_TYPE_FLOAT:
+ if (op[1]->value.f[c1] == 0)
+ return NULL;
/* We don't use fmod because it rounds toward zero; GLSL specifies
* the use of floor.
*/