]> git.tdb.fi Git - libs/gl.git/commitdiff
Allow AST to be dumped even if compilation fails
authorMikko Rasa <tdb@tdb.fi>
Thu, 4 Mar 2021 23:21:29 +0000 (01:21 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 4 Mar 2021 23:21:29 +0000 (01:21 +0200)
tools/glslcompiler.cpp

index 0ce5f01d722ac424c064d7a7f64d862f72b16390..b7b8097e88768a3d77ca12723fe83ef3e1fd069d 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/core/application.h>
 #include <msp/core/getopt.h>
 #include <msp/gl/glsl/compiler.h>
+#include <msp/gl/glsl/glsl_error.h>
 #include <msp/io/print.h>
 #include <msp/strings/utils.h>
 
@@ -73,7 +74,21 @@ int GlslCompiler::main()
        compiler.load_source(file, source_fn);
        compiler.specialize(spec_values);
        if(!parse_only)
-               compiler.compile(GL::SL::Compiler::PROGRAM);
+       {
+               try
+               {
+                       compiler.compile(GL::SL::Compiler::PROGRAM);
+               }
+               catch(const GL::SL::invalid_shader_source &exc)
+               {
+                       if(!dump_ast)
+                               throw;
+
+                       IO::print("Compilation resulted in errors:\n%s\n", exc.what());
+                       combined = false;
+                       stage = GL::SL::Stage::SHARED;
+               }
+       }
 
        if(dump_ast)
        {