private EmitValHLSL EmitExpImpl(MidBuiltinApp app, Span span)
{
var template = app.Decl.GetTemplate("hlsl");
switch (template)
{
case "__ConstantRef":
return EmitConstantRef(app.Args.First(), span);
case "__UniformRef":
return EmitUniformRef(app.Args.First(), span);
default:
break;
}
var args = (from a in app.Args
select EmitBuiltinAppArg(a, span)).ToArray();
switch (template)
{
case "__GetElem":
return GetElem(
args[0],
args[1]);
default:
break;
}
var resultType = EmitType(app.Type);
var resultString = string.Format(template, args);
if (resultType is VoidTypeHLSL)
{
span.WriteLine("{0};", resultString);
return VoidVal;
}
if (!(resultType is RealTypeHLSL))
{
Diagnostics.Add(
Severity.Error,
new SourceRange(),
"Invalid return type for HLSL builtin function '{0}'", app.Decl.Name);
return new ErrorValHLSL();
}
return new SimpleValHLSL(
resultString,
(RealTypeHLSL) resultType);
}