private static void WarnCallback(SSLCompiler compiler, ErrorSource source, uint line, string msg) { if (NoWarn) { return; } if ((source == ErrorSource.Parser) || (source == ErrorSource.Translator)) { CConsole.Warn($"'{compiler.SourceFile}'[line {line}] - {msg}"); } else { CConsole.Warn($"'{compiler.SourceFile}' - {msg}"); } }
static void Main(string[] args) { if (args.Length == 0) { CConsole.Error("Please pass arguments to the program, or use '/?' to get the help text."); return; } ArgParser.Load(args); if (ArgParser.Help) { PrintHelp(); return; } if (ArgParser.InputFile == null) { CConsole.Error("No input file specified. Make sure the input file is the last argument."); return; } NoWarn = ArgParser.NoWarn; // Try to get the paths string oPath = null; if (!ArgParser.TryLoadValueArg(out oPath, "output", "o") && oPath != null) { CConsole.Error("Output path invalid, or not specified."); return; } string iPath = null; if (!ArgParser.TryLoadValueArg(out iPath, "ipath", "ip") && iPath != null) { CConsole.Error("GLSL path invalid, or not specified."); return; } string rPath = null; if (!ArgParser.TryLoadValueArg(out rPath, "rpath", "rp") && rPath != null) { CConsole.Error("Reflection path invalid, or not specified."); return; } // Load other arguments if (!LoadIntegerArg(out var timeout, CompileOptions.DEFAULT_TIMEOUT, "timeout", "to")) { return; } if (!LoadIntegerArg(out var limAttr, CompileOptions.DEFAULT_LIMIT_ATTRIBUTES, "rla")) { return; } if (!LoadIntegerArg(out var limOut, CompileOptions.DEFAULT_LIMIT_OUTPUTS, "rlo")) { return; } if (!LoadIntegerArg(out var limInt, CompileOptions.DEFAULT_LIMIT_INTERNALS, "rli")) { return; } if (!LoadIntegerArg(out var limUni, CompileOptions.DEFUALT_LIMIT_UNIFORMS, "rlu")) { return; } if (!LoadIntegerArg(out var limSI, CompileOptions.DEFAULT_LIMIT_SUBPASS_INPUTS, "rlsi")) { return; } try { using (var compiler = SSLCompiler.FromFile(ArgParser.InputFile)) { var fileName = Path.GetFileName(compiler.SourceFile); var options = new CompileOptions { WarnCallback = WarnCallback, OutputPath = oPath, GLSLPath = iPath, ReflectionPath = rPath, Compile = !ArgParser.NoCompile, OutputGLSL = ArgParser.OutputGLSL, OptimizeBytecode = !ArgParser.NoOptimize, OutputReflection = ArgParser.OutputReflection || ArgParser.UseBinaryReflection, UseBinaryReflection = ArgParser.UseBinaryReflection, ForceContiguousUniforms = ArgParser.ForceContiguousUniforms, CompilerTimeout = timeout, LimitAttributes = limAttr, LimitOutputs = limOut, LimitInternals = limInt, LimitUniforms = limUni, LimitSubpassInputs = limSI }; if (!compiler.Compile(options, out var error)) { if (error.Source == ErrorSource.Translator || error.Source == ErrorSource.Parser) { CConsole.Error($"'{fileName}'[{error.Line}:{error.CharIndex}] - " + error.Message); if (error.RuleStack != null) { CConsole.Error($" Rule Stack: {String.Join(" -> ", error.RuleStack)}"); } } else { foreach (var err in error.Message.Split('\n')) { CConsole.Error($"'{fileName}' - " + err); } } return; } } } catch (ArgumentException e) // Bad filename { CConsole.Error(e); } catch (CompileOptionException e) // Bad compiler option { CConsole.Error(e.Message); } catch (FileNotFoundException e) // Input file does not exist { CConsole.Error(e); } catch (IOException e) // Error with writing one of the output files { CConsole.Error(e.Message); } catch (Exception e) // Unknown error { CConsole.Error($"({e.GetType()}) {e.Message}"); CConsole.Error('\n' + e.StackTrace); } }