if (skia_enable_gpu) {
test_app("skslc") {
- defines = [ "SKSL_STANDALONE" ]
sources = [
"src/sksl/SkSLMain.cpp",
]
- sources += skia_sksl_sources
- include_dirs = [ "src/sksl" ]
+ deps = [
+ ":flags",
+ ":skia",
+ ]
}
}
}
GrGLuint GLBench::CompileShader(const GrGLContext* context, const char* sksl, GrGLenum type) {
const GrGLInterface* gl = context->interface();
- SkSL::String glsl;
+ SkString glsl;
SkSL::Program::Settings settings;
settings.fCaps = context->caps()->shaderCaps();
std::unique_ptr<SkSL::Program> program = context->compiler()->convertProgram(
#if SK_SUPPORT_GPU
static void fuzz_sksl2glsl(sk_sp<SkData> bytes) {
SkSL::Compiler compiler;
- SkSL::String output;
+ SkString output;
SkSL::Program::Settings settings;
sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
settings.fCaps = caps.get();
"$_src/sksl/SkSLParser.cpp",
"$_src/sksl/SkSLGLSLCodeGenerator.cpp",
"$_src/sksl/SkSLSPIRVCodeGenerator.cpp",
- "$_src/sksl/SkSLString.cpp",
"$_src/sksl/SkSLUtil.cpp",
"$_src/sksl/lex.layout.cpp",
"$_src/sksl/ir/SkSLSymbolTable.cpp",
}
#endif
- SkSL::String glsl;
+ SkString glsl;
if (type == GR_GL_VERTEX_SHADER || type == GR_GL_FRAGMENT_SHADER) {
SkSL::Compiler& compiler = *glCtx.compiler();
std::unique_ptr<SkSL::Program> program;
SkASSERT(false);
}
*outInputs = program->fInputs;
- SkSL::String code;
+ SkString code;
if (!gpu->shaderCompiler()->toSPIRV(*program, &code)) {
SkDebugf("%s\n", gpu->shaderCompiler()->errorText().c_str());
return false;
Overview
========
-SkSL ("Skia Shading Language") is a variant of GLSL which is used as Skia's
+SkSL ("Skia Shading Language") is a variant of GLSL which is used as Skia's
internal shading language. SkSL is, at its heart, a single standardized version
of GLSL which avoids all of the various version and dialect differences found
in GLSL "in the wild", but it does bring a few of its own changes to the table.
SkSL is based on GLSL 4.5. For the most part, write SkSL exactly as you would
desktop GLSL, and the SkSL compiler will take care of version and dialect
differences (for instance, you always use "in" and "out", and skslc will handle
-translating them to "varying" and "attribute" as appropriate). Be aware of the
+translating them to "varying" and "attribute" as appropriate). Be aware of the
following differences between SkSL and GLSL:
* GLSL caps can be referenced via the syntax 'sk_Caps.<name>', e.g.
* use sk_VertexID instead of gl_VertexID
* the fragment coordinate is sk_FragCoord, and is always relative to the upper
left.
-* lowp, mediump, and highp are always permitted (but will only be respected if
+* lowp, mediump, and highp are always permitted (but will only be respected if
you run on a device which supports them)
* you do not need to include ".0" to make a number a float (meaning that
"vec2(x, y) * 4" is perfectly legal in SkSL, unlike GLSL where it would often
- have to be expressed "vec2(x, y) * 4.0". There is no performance penalty for
+ have to be expressed "vec2(x, y) * 4.0". There is no performance penalty for
this, as the number is converted to a float at compile time)
* type suffixes on numbers (1.0f, 0xFFu) are both unnecessary and unsupported
* creating a smaller vector from a larger vector (e.g. vec2(vec3(1))) is
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#include "SkSLCFGGenerator.h"
#include "ir/SkSLConstructor.h"
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_CFGGENERATOR
#define SKSL_CFGGENERATOR
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_CODEGENERATOR
#define SKSL_CODEGENERATOR
*/
class CodeGenerator {
public:
- CodeGenerator(const Program* program, ErrorReporter* errors, OutputStream* out)
+ CodeGenerator(const Program* program, ErrorReporter* errors, SkWStream* out)
: fProgram(*program)
, fErrors(*errors)
, fOut(out) {}
const Program& fProgram;
ErrorReporter& fErrors;
- OutputStream* fOut;
+ SkWStream* fOut;
};
} // namespace
#include "ir/SkSLSymbolTable.h"
#include "ir/SkSLUnresolvedFunction.h"
#include "ir/SkSLVarDeclarations.h"
+#include "SkMutex.h"
#ifdef SK_ENABLE_SPIRV_VALIDATION
#include "spirv-tools/libspirv.hpp"
ADD_TYPE(BVec3);
ADD_TYPE(BVec4);
ADD_TYPE(Mat2x2);
- types->addWithoutOwnership(String("mat2x2"), fContext.fMat2x2_Type.get());
+ types->addWithoutOwnership(SkString("mat2x2"), fContext.fMat2x2_Type.get());
ADD_TYPE(Mat2x3);
ADD_TYPE(Mat2x4);
ADD_TYPE(Mat3x2);
ADD_TYPE(Mat3x3);
- types->addWithoutOwnership(String("mat3x3"), fContext.fMat3x3_Type.get());
+ types->addWithoutOwnership(SkString("mat3x3"), fContext.fMat3x3_Type.get());
ADD_TYPE(Mat3x4);
ADD_TYPE(Mat4x2);
ADD_TYPE(Mat4x3);
ADD_TYPE(Mat4x4);
- types->addWithoutOwnership(String("mat4x4"), fContext.fMat4x4_Type.get());
+ types->addWithoutOwnership(SkString("mat4x4"), fContext.fMat4x4_Type.get());
ADD_TYPE(GenType);
ADD_TYPE(GenDType);
ADD_TYPE(GenIType);
ADD_TYPE(GSampler2DArrayShadow);
ADD_TYPE(GSamplerCubeArrayShadow);
- String skCapsName("sk_Caps");
- Variable* skCaps = new Variable(Position(), Modifiers(), skCapsName,
+ SkString skCapsName("sk_Caps");
+ Variable* skCaps = new Variable(Position(), Modifiers(), skCapsName,
*fContext.fSkCaps_Type, Variable::kGlobal_Storage);
fIRGenerator->fSymbolTable->add(skCapsName, std::unique_ptr<Symbol>(skCaps));
Modifiers::Flag ignored1;
std::vector<std::unique_ptr<ProgramElement>> ignored2;
- this->internalConvertProgram(String(SKSL_INCLUDE), &ignored1, &ignored2);
+ this->internalConvertProgram(SkString(SKSL_INCLUDE), &ignored1, &ignored2);
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
ASSERT(!fErrorCount);
}
p = (*cfg.fBlocks[i].fNodes[0].fExpression)->fPosition;
break;
}
- this->error(p, String("unreachable"));
+ this->error(p, SkString("unreachable"));
}
}
if (fErrorCount) {
// check for missing return
if (f.fDeclaration.fReturnType != *fContext.fVoid_Type) {
if (cfg.fBlocks[cfg.fExit].fEntrances.size()) {
- this->error(f.fPosition, String("function can exit without returning a value"));
+ this->error(f.fPosition, SkString("function can exit without returning a value"));
}
}
}
-void Compiler::internalConvertProgram(String text,
+void Compiler::internalConvertProgram(SkString text,
Modifiers::Flag* defaultPrecision,
std::vector<std::unique_ptr<ProgramElement>>* result) {
Parser parser(text, *fTypes, *this);
}
}
-std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, String text,
+std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, SkString text,
const Program::Settings& settings) {
fErrorText = "";
fErrorCount = 0;
Modifiers::Flag ignored;
switch (kind) {
case Program::kVertex_Kind:
- this->internalConvertProgram(String(SKSL_VERT_INCLUDE), &ignored, &elements);
+ this->internalConvertProgram(SkString(SKSL_VERT_INCLUDE), &ignored, &elements);
break;
case Program::kFragment_Kind:
- this->internalConvertProgram(String(SKSL_FRAG_INCLUDE), &ignored, &elements);
+ this->internalConvertProgram(SkString(SKSL_FRAG_INCLUDE), &ignored, &elements);
break;
case Program::kGeometry_Kind:
- this->internalConvertProgram(String(SKSL_GEOM_INCLUDE), &ignored, &elements);
+ this->internalConvertProgram(SkString(SKSL_GEOM_INCLUDE), &ignored, &elements);
break;
}
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
return result;
}
-bool Compiler::toSPIRV(const Program& program, OutputStream& out) {
+bool Compiler::toSPIRV(const Program& program, SkWStream& out) {
#ifdef SK_ENABLE_SPIRV_VALIDATION
- StringStream buffer;
+ SkDynamicMemoryWStream buffer;
SPIRVCodeGenerator cg(&fContext, &program, this, &buffer);
bool result = cg.generateCode();
if (result) {
+ sk_sp<SkData> data(buffer.detachAsData());
spvtools::SpirvTools tools(SPV_ENV_VULKAN_1_0);
- ASSERT(0 == buffer.size() % 4);
+ SkASSERT(0 == data->size() % 4);
auto dumpmsg = [](spv_message_level_t, const char*, const spv_position_t&, const char* m) {
SkDebugf("SPIR-V validation error: %s\n", m);
};
tools.SetMessageConsumer(dumpmsg);
// Verify that the SPIR-V we produced is valid. If this assert fails, check the logs prior
// to the failure to see the validation errors.
- ASSERT_RESULT(tools.Validate((const uint32_t*) buffer.data(), buffer.size() / 4));
- out.write(buffer.data(), buffer.size());
+ SkAssertResult(tools.Validate((const uint32_t*) data->data(), data->size() / 4));
+ out.write(data->data(), data->size());
}
#else
SPIRVCodeGenerator cg(&fContext, &program, this, &out);
return result;
}
-bool Compiler::toSPIRV(const Program& program, String* out) {
- StringStream buffer;
+bool Compiler::toSPIRV(const Program& program, SkString* out) {
+ SkDynamicMemoryWStream buffer;
bool result = this->toSPIRV(program, buffer);
if (result) {
- *out = String(buffer.data(), buffer.size());
+ sk_sp<SkData> data(buffer.detachAsData());
+ *out = SkString((const char*) data->data(), data->size());
}
return result;
}
-bool Compiler::toGLSL(const Program& program, OutputStream& out) {
+bool Compiler::toGLSL(const Program& program, SkWStream& out) {
GLSLCodeGenerator cg(&fContext, &program, this, &out);
bool result = cg.generateCode();
this->writeErrorCount();
return result;
}
-bool Compiler::toGLSL(const Program& program, String* out) {
- StringStream buffer;
+bool Compiler::toGLSL(const Program& program, SkString* out) {
+ SkDynamicMemoryWStream buffer;
bool result = this->toGLSL(program, buffer);
if (result) {
- *out = String(buffer.data(), buffer.size());
+ sk_sp<SkData> data(buffer.detachAsData());
+ *out = SkString((const char*) data->data(), data->size());
}
return result;
}
-void Compiler::error(Position position, String msg) {
+void Compiler::error(Position position, SkString msg) {
fErrorCount++;
fErrorText += "error: " + position.description() + ": " + msg.c_str() + "\n";
}
-String Compiler::errorText() {
- String result = fErrorText;
+SkString Compiler::errorText() {
+ SkString result = fErrorText;
return result;
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_COMPILER
#define SKSL_COMPILER
~Compiler() override;
- std::unique_ptr<Program> convertProgram(Program::Kind kind, String text,
+ std::unique_ptr<Program> convertProgram(Program::Kind kind, SkString text,
const Program::Settings& settings);
- bool toSPIRV(const Program& program, OutputStream& out);
+ bool toSPIRV(const Program& program, SkWStream& out);
- bool toSPIRV(const Program& program, String* out);
+ bool toSPIRV(const Program& program, SkString* out);
- bool toGLSL(const Program& program, OutputStream& out);
+ bool toGLSL(const Program& program, SkWStream& out);
- bool toGLSL(const Program& program, String* out);
+ bool toGLSL(const Program& program, SkString* out);
- void error(Position position, String msg) override;
+ void error(Position position, SkString msg) override;
- String errorText();
+ SkString errorText();
void writeErrorCount();
void scanCFG(const FunctionDefinition& f);
- void internalConvertProgram(String text,
+ void internalConvertProgram(SkString text,
Modifiers::Flag* defaultPrecision,
std::vector<std::unique_ptr<ProgramElement>>* result);
std::shared_ptr<SymbolTable> fTypes;
IRGenerator* fIRGenerator;
- String fSkiaVertText; // FIXME store parsed version instead
+ SkString fSkiaVertText; // FIXME store parsed version instead
Context fContext;
int fErrorCount;
- String fErrorText;
+ SkString fErrorText;
};
} // namespace
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_CONTEXT
#define SKSL_CONTEXT
class Context {
public:
Context()
- : fInvalid_Type(new Type(String("<INVALID>")))
- , fVoid_Type(new Type(String("void")))
- , fDouble_Type(new Type(String("double"), true))
- , fDVec2_Type(new Type(String("dvec2"), *fDouble_Type, 2))
- , fDVec3_Type(new Type(String("dvec3"), *fDouble_Type, 3))
- , fDVec4_Type(new Type(String("dvec4"), *fDouble_Type, 4))
- , fFloat_Type(new Type(String("float"), true, { fDouble_Type.get() }))
- , fVec2_Type(new Type(String("vec2"), *fFloat_Type, 2))
- , fVec3_Type(new Type(String("vec3"), *fFloat_Type, 3))
- , fVec4_Type(new Type(String("vec4"), *fFloat_Type, 4))
- , fUInt_Type(new Type(String("uint"), true, { fFloat_Type.get(), fDouble_Type.get() }))
- , fUVec2_Type(new Type(String("uvec2"), *fUInt_Type, 2))
- , fUVec3_Type(new Type(String("uvec3"), *fUInt_Type, 3))
- , fUVec4_Type(new Type(String("uvec4"), *fUInt_Type, 4))
- , fInt_Type(new Type(String("int"), true, { fUInt_Type.get(), fFloat_Type.get(),
+ : fInvalid_Type(new Type(SkString("<INVALID>")))
+ , fVoid_Type(new Type(SkString("void")))
+ , fDouble_Type(new Type(SkString("double"), true))
+ , fDVec2_Type(new Type(SkString("dvec2"), *fDouble_Type, 2))
+ , fDVec3_Type(new Type(SkString("dvec3"), *fDouble_Type, 3))
+ , fDVec4_Type(new Type(SkString("dvec4"), *fDouble_Type, 4))
+ , fFloat_Type(new Type(SkString("float"), true, { fDouble_Type.get() }))
+ , fVec2_Type(new Type(SkString("vec2"), *fFloat_Type, 2))
+ , fVec3_Type(new Type(SkString("vec3"), *fFloat_Type, 3))
+ , fVec4_Type(new Type(SkString("vec4"), *fFloat_Type, 4))
+ , fUInt_Type(new Type(SkString("uint"), true, { fFloat_Type.get(), fDouble_Type.get() }))
+ , fUVec2_Type(new Type(SkString("uvec2"), *fUInt_Type, 2))
+ , fUVec3_Type(new Type(SkString("uvec3"), *fUInt_Type, 3))
+ , fUVec4_Type(new Type(SkString("uvec4"), *fUInt_Type, 4))
+ , fInt_Type(new Type(SkString("int"), true, { fUInt_Type.get(), fFloat_Type.get(),
fDouble_Type.get() }))
- , fIVec2_Type(new Type(String("ivec2"), *fInt_Type, 2))
- , fIVec3_Type(new Type(String("ivec3"), *fInt_Type, 3))
- , fIVec4_Type(new Type(String("ivec4"), *fInt_Type, 4))
- , fBool_Type(new Type(String("bool"), false))
- , fBVec2_Type(new Type(String("bvec2"), *fBool_Type, 2))
- , fBVec3_Type(new Type(String("bvec3"), *fBool_Type, 3))
- , fBVec4_Type(new Type(String("bvec4"), *fBool_Type, 4))
- , fMat2x2_Type(new Type(String("mat2"), *fFloat_Type, 2, 2))
- , fMat2x3_Type(new Type(String("mat2x3"), *fFloat_Type, 2, 3))
- , fMat2x4_Type(new Type(String("mat2x4"), *fFloat_Type, 2, 4))
- , fMat3x2_Type(new Type(String("mat3x2"), *fFloat_Type, 3, 2))
- , fMat3x3_Type(new Type(String("mat3"), *fFloat_Type, 3, 3))
- , fMat3x4_Type(new Type(String("mat3x4"), *fFloat_Type, 3, 4))
- , fMat4x2_Type(new Type(String("mat4x2"), *fFloat_Type, 4, 2))
- , fMat4x3_Type(new Type(String("mat4x3"), *fFloat_Type, 4, 3))
- , fMat4x4_Type(new Type(String("mat4"), *fFloat_Type, 4, 4))
- , fDMat2x2_Type(new Type(String("dmat2"), *fFloat_Type, 2, 2))
- , fDMat2x3_Type(new Type(String("dmat2x3"), *fFloat_Type, 2, 3))
- , fDMat2x4_Type(new Type(String("dmat2x4"), *fFloat_Type, 2, 4))
- , fDMat3x2_Type(new Type(String("dmat3x2"), *fFloat_Type, 3, 2))
- , fDMat3x3_Type(new Type(String("dmat3"), *fFloat_Type, 3, 3))
- , fDMat3x4_Type(new Type(String("dmat3x4"), *fFloat_Type, 3, 4))
- , fDMat4x2_Type(new Type(String("dmat4x2"), *fFloat_Type, 4, 2))
- , fDMat4x3_Type(new Type(String("dmat4x3"), *fFloat_Type, 4, 3))
- , fDMat4x4_Type(new Type(String("dmat4"), *fFloat_Type, 4, 4))
- , fSampler1D_Type(new Type(String("sampler1D"), SpvDim1D, false, false, false, true))
- , fSampler2D_Type(new Type(String("sampler2D"), SpvDim2D, false, false, false, true))
- , fSampler3D_Type(new Type(String("sampler3D"), SpvDim3D, false, false, false, true))
- , fSamplerExternalOES_Type(new Type(String("samplerExternalOES"), SpvDim2D, false, false,
+ , fIVec2_Type(new Type(SkString("ivec2"), *fInt_Type, 2))
+ , fIVec3_Type(new Type(SkString("ivec3"), *fInt_Type, 3))
+ , fIVec4_Type(new Type(SkString("ivec4"), *fInt_Type, 4))
+ , fBool_Type(new Type(SkString("bool"), false))
+ , fBVec2_Type(new Type(SkString("bvec2"), *fBool_Type, 2))
+ , fBVec3_Type(new Type(SkString("bvec3"), *fBool_Type, 3))
+ , fBVec4_Type(new Type(SkString("bvec4"), *fBool_Type, 4))
+ , fMat2x2_Type(new Type(SkString("mat2"), *fFloat_Type, 2, 2))
+ , fMat2x3_Type(new Type(SkString("mat2x3"), *fFloat_Type, 2, 3))
+ , fMat2x4_Type(new Type(SkString("mat2x4"), *fFloat_Type, 2, 4))
+ , fMat3x2_Type(new Type(SkString("mat3x2"), *fFloat_Type, 3, 2))
+ , fMat3x3_Type(new Type(SkString("mat3"), *fFloat_Type, 3, 3))
+ , fMat3x4_Type(new Type(SkString("mat3x4"), *fFloat_Type, 3, 4))
+ , fMat4x2_Type(new Type(SkString("mat4x2"), *fFloat_Type, 4, 2))
+ , fMat4x3_Type(new Type(SkString("mat4x3"), *fFloat_Type, 4, 3))
+ , fMat4x4_Type(new Type(SkString("mat4"), *fFloat_Type, 4, 4))
+ , fDMat2x2_Type(new Type(SkString("dmat2"), *fFloat_Type, 2, 2))
+ , fDMat2x3_Type(new Type(SkString("dmat2x3"), *fFloat_Type, 2, 3))
+ , fDMat2x4_Type(new Type(SkString("dmat2x4"), *fFloat_Type, 2, 4))
+ , fDMat3x2_Type(new Type(SkString("dmat3x2"), *fFloat_Type, 3, 2))
+ , fDMat3x3_Type(new Type(SkString("dmat3"), *fFloat_Type, 3, 3))
+ , fDMat3x4_Type(new Type(SkString("dmat3x4"), *fFloat_Type, 3, 4))
+ , fDMat4x2_Type(new Type(SkString("dmat4x2"), *fFloat_Type, 4, 2))
+ , fDMat4x3_Type(new Type(SkString("dmat4x3"), *fFloat_Type, 4, 3))
+ , fDMat4x4_Type(new Type(SkString("dmat4"), *fFloat_Type, 4, 4))
+ , fSampler1D_Type(new Type(SkString("sampler1D"), SpvDim1D, false, false, false, true))
+ , fSampler2D_Type(new Type(SkString("sampler2D"), SpvDim2D, false, false, false, true))
+ , fSampler3D_Type(new Type(SkString("sampler3D"), SpvDim3D, false, false, false, true))
+ , fSamplerExternalOES_Type(new Type(SkString("samplerExternalOES"), SpvDim2D, false, false,
false, true))
- , fSamplerCube_Type(new Type(String("samplerCube"), SpvDimCube, false, false, false, true))
- , fSampler2DRect_Type(new Type(String("sampler2DRect"), SpvDimRect, false, false, false,
+ , fSamplerCube_Type(new Type(SkString("samplerCube"), SpvDimCube, false, false, false, true))
+ , fSampler2DRect_Type(new Type(SkString("sampler2DRect"), SpvDimRect, false, false, false,
true))
- , fSampler1DArray_Type(new Type(String("sampler1DArray")))
- , fSampler2DArray_Type(new Type(String("sampler2DArray")))
- , fSamplerCubeArray_Type(new Type(String("samplerCubeArray")))
- , fSamplerBuffer_Type(new Type(String("samplerBuffer")))
- , fSampler2DMS_Type(new Type(String("sampler2DMS")))
- , fSampler2DMSArray_Type(new Type(String("sampler2DMSArray")))
- , fSampler1DShadow_Type(new Type(String("sampler1DShadow")))
- , fSampler2DShadow_Type(new Type(String("sampler2DShadow")))
- , fSamplerCubeShadow_Type(new Type(String("samplerCubeShadow")))
- , fSampler2DRectShadow_Type(new Type(String("sampler2DRectShadow")))
- , fSampler1DArrayShadow_Type(new Type(String("sampler1DArrayShadow")))
- , fSampler2DArrayShadow_Type(new Type(String("sampler2DArrayShadow")))
- , fSamplerCubeArrayShadow_Type(new Type(String("samplerCubeArrayShadow")))
+ , fSampler1DArray_Type(new Type(SkString("sampler1DArray")))
+ , fSampler2DArray_Type(new Type(SkString("sampler2DArray")))
+ , fSamplerCubeArray_Type(new Type(SkString("samplerCubeArray")))
+ , fSamplerBuffer_Type(new Type(SkString("samplerBuffer")))
+ , fSampler2DMS_Type(new Type(SkString("sampler2DMS")))
+ , fSampler2DMSArray_Type(new Type(SkString("sampler2DMSArray")))
+ , fSampler1DShadow_Type(new Type(SkString("sampler1DShadow")))
+ , fSampler2DShadow_Type(new Type(SkString("sampler2DShadow")))
+ , fSamplerCubeShadow_Type(new Type(SkString("samplerCubeShadow")))
+ , fSampler2DRectShadow_Type(new Type(SkString("sampler2DRectShadow")))
+ , fSampler1DArrayShadow_Type(new Type(SkString("sampler1DArrayShadow")))
+ , fSampler2DArrayShadow_Type(new Type(SkString("sampler2DArrayShadow")))
+ , fSamplerCubeArrayShadow_Type(new Type(SkString("samplerCubeArrayShadow")))
// Related to below FIXME, gsampler*s don't currently expand to cover integer case.
- , fISampler2D_Type(new Type(String("isampler2D"), SpvDim2D, false, false, false, true))
+ , fISampler2D_Type(new Type(SkString("isampler2D"), SpvDim2D, false, false, false, true))
// FIXME express these as "gimage2D" that expand to image2D, iimage2D, and uimage2D.
- , fImage2D_Type(new Type(String("image2D"), SpvDim2D, false, false, false, true))
- , fIImage2D_Type(new Type(String("iimage2D"), SpvDim2D, false, false, false, true))
+ , fImage2D_Type(new Type(SkString("image2D"), SpvDim2D, false, false, false, true))
+ , fIImage2D_Type(new Type(SkString("iimage2D"), SpvDim2D, false, false, false, true))
// FIXME express these as "gsubpassInput" that expand to subpassInput, isubpassInput,
// and usubpassInput.
- , fSubpassInput_Type(new Type(String("subpassInput"), SpvDimSubpassData, false, false,
+ , fSubpassInput_Type(new Type(SkString("subpassInput"), SpvDimSubpassData, false, false,
false, false))
- , fSubpassInputMS_Type(new Type(String("subpassInputMS"), SpvDimSubpassData, false, false,
+ , fSubpassInputMS_Type(new Type(SkString("subpassInputMS"), SpvDimSubpassData, false, false,
true, false))
// FIXME figure out what we're supposed to do with the gsampler et al. types)
- , fGSampler1D_Type(new Type(String("$gsampler1D"), static_type(*fSampler1D_Type)))
- , fGSampler2D_Type(new Type(String("$gsampler2D"), static_type(*fSampler2D_Type)))
- , fGSampler3D_Type(new Type(String("$gsampler3D"), static_type(*fSampler3D_Type)))
- , fGSamplerCube_Type(new Type(String("$gsamplerCube"), static_type(*fSamplerCube_Type)))
- , fGSampler2DRect_Type(new Type(String("$gsampler2DRect"), static_type(*fSampler2DRect_Type)))
- , fGSampler1DArray_Type(new Type(String("$gsampler1DArray"),
+ , fGSampler1D_Type(new Type(SkString("$gsampler1D"), static_type(*fSampler1D_Type)))
+ , fGSampler2D_Type(new Type(SkString("$gsampler2D"), static_type(*fSampler2D_Type)))
+ , fGSampler3D_Type(new Type(SkString("$gsampler3D"), static_type(*fSampler3D_Type)))
+ , fGSamplerCube_Type(new Type(SkString("$gsamplerCube"), static_type(*fSamplerCube_Type)))
+ , fGSampler2DRect_Type(new Type(SkString("$gsampler2DRect"), static_type(*fSampler2DRect_Type)))
+ , fGSampler1DArray_Type(new Type(SkString("$gsampler1DArray"),
static_type(*fSampler1DArray_Type)))
- , fGSampler2DArray_Type(new Type(String("$gsampler2DArray"),
+ , fGSampler2DArray_Type(new Type(SkString("$gsampler2DArray"),
static_type(*fSampler2DArray_Type)))
- , fGSamplerCubeArray_Type(new Type(String("$gsamplerCubeArray"),
+ , fGSamplerCubeArray_Type(new Type(SkString("$gsamplerCubeArray"),
static_type(*fSamplerCubeArray_Type)))
- , fGSamplerBuffer_Type(new Type(String("$gsamplerBuffer"), static_type(*fSamplerBuffer_Type)))
- , fGSampler2DMS_Type(new Type(String("$gsampler2DMS"), static_type(*fSampler2DMS_Type)))
- , fGSampler2DMSArray_Type(new Type(String("$gsampler2DMSArray"),
+ , fGSamplerBuffer_Type(new Type(SkString("$gsamplerBuffer"), static_type(*fSamplerBuffer_Type)))
+ , fGSampler2DMS_Type(new Type(SkString("$gsampler2DMS"), static_type(*fSampler2DMS_Type)))
+ , fGSampler2DMSArray_Type(new Type(SkString("$gsampler2DMSArray"),
static_type(*fSampler2DMSArray_Type)))
- , fGSampler2DArrayShadow_Type(new Type(String("$gsampler2DArrayShadow"),
+ , fGSampler2DArrayShadow_Type(new Type(SkString("$gsampler2DArrayShadow"),
static_type(*fSampler2DArrayShadow_Type)))
- , fGSamplerCubeArrayShadow_Type(new Type(String("$gsamplerCubeArrayShadow"),
+ , fGSamplerCubeArrayShadow_Type(new Type(SkString("$gsamplerCubeArrayShadow"),
static_type(*fSamplerCubeArrayShadow_Type)))
- , fGenType_Type(new Type(String("$genType"), { fFloat_Type.get(), fVec2_Type.get(),
+ , fGenType_Type(new Type(SkString("$genType"), { fFloat_Type.get(), fVec2_Type.get(),
fVec3_Type.get(), fVec4_Type.get() }))
- , fGenDType_Type(new Type(String("$genDType"), { fDouble_Type.get(), fDVec2_Type.get(),
+ , fGenDType_Type(new Type(SkString("$genDType"), { fDouble_Type.get(), fDVec2_Type.get(),
fDVec3_Type.get(), fDVec4_Type.get() }))
- , fGenIType_Type(new Type(String("$genIType"), { fInt_Type.get(), fIVec2_Type.get(),
+ , fGenIType_Type(new Type(SkString("$genIType"), { fInt_Type.get(), fIVec2_Type.get(),
fIVec3_Type.get(), fIVec4_Type.get() }))
- , fGenUType_Type(new Type(String("$genUType"), { fUInt_Type.get(), fUVec2_Type.get(),
+ , fGenUType_Type(new Type(SkString("$genUType"), { fUInt_Type.get(), fUVec2_Type.get(),
fUVec3_Type.get(), fUVec4_Type.get() }))
- , fGenBType_Type(new Type(String("$genBType"), { fBool_Type.get(), fBVec2_Type.get(),
+ , fGenBType_Type(new Type(SkString("$genBType"), { fBool_Type.get(), fBVec2_Type.get(),
fBVec3_Type.get(), fBVec4_Type.get() }))
- , fMat_Type(new Type(String("$mat"), { fMat2x2_Type.get(), fMat2x3_Type.get(),
+ , fMat_Type(new Type(SkString("$mat"), { fMat2x2_Type.get(), fMat2x3_Type.get(),
fMat2x4_Type.get(), fMat3x2_Type.get(),
fMat3x3_Type.get(), fMat3x4_Type.get(),
fMat4x2_Type.get(), fMat4x3_Type.get(),
fDMat3x2_Type.get(), fDMat3x3_Type.get(),
fDMat3x4_Type.get(), fDMat4x2_Type.get(),
fDMat4x3_Type.get(), fDMat4x4_Type.get() }))
- , fVec_Type(new Type(String("$vec"), { fInvalid_Type.get(), fVec2_Type.get(),
+ , fVec_Type(new Type(SkString("$vec"), { fInvalid_Type.get(), fVec2_Type.get(),
fVec3_Type.get(), fVec4_Type.get() }))
- , fGVec_Type(new Type(String("$gvec")))
- , fGVec2_Type(new Type(String("$gvec2")))
- , fGVec3_Type(new Type(String("$gvec3")))
- , fGVec4_Type(new Type(String("$gvec4"), static_type(*fVec4_Type)))
- , fDVec_Type(new Type(String("$dvec"), { fInvalid_Type.get(), fDVec2_Type.get(),
+ , fGVec_Type(new Type(SkString("$gvec")))
+ , fGVec2_Type(new Type(SkString("$gvec2")))
+ , fGVec3_Type(new Type(SkString("$gvec3")))
+ , fGVec4_Type(new Type(SkString("$gvec4"), static_type(*fVec4_Type)))
+ , fDVec_Type(new Type(SkString("$dvec"), { fInvalid_Type.get(), fDVec2_Type.get(),
fDVec3_Type.get(), fDVec4_Type.get() }))
- , fIVec_Type(new Type(String("$ivec"), { fInvalid_Type.get(), fIVec2_Type.get(),
+ , fIVec_Type(new Type(SkString("$ivec"), { fInvalid_Type.get(), fIVec2_Type.get(),
fIVec3_Type.get(), fIVec4_Type.get() }))
- , fUVec_Type(new Type(String("$uvec"), { fInvalid_Type.get(), fUVec2_Type.get(),
+ , fUVec_Type(new Type(SkString("$uvec"), { fInvalid_Type.get(), fUVec2_Type.get(),
fUVec3_Type.get(), fUVec4_Type.get() }))
- , fBVec_Type(new Type(String("$bvec"), { fInvalid_Type.get(), fBVec2_Type.get(),
+ , fBVec_Type(new Type(SkString("$bvec"), { fInvalid_Type.get(), fBVec2_Type.get(),
fBVec3_Type.get(), fBVec4_Type.get() }))
- , fSkCaps_Type(new Type(String("$sk_Caps")))
+ , fSkCaps_Type(new Type(SkString("$sk_Caps")))
, fDefined_Expression(new Defined(*fInvalid_Type)) {}
static std::vector<const Type*> static_type(const Type& t) {
const std::unique_ptr<Type> fSkCaps_Type;
- // dummy expression used to mark that a variable has a value during dataflow analysis (when it
+ // dummy expression used to mark that a variable has a value during dataflow analysis (when it
// could have several different values, or the analyzer is otherwise unable to assign it a
// specific expression)
const std::unique_ptr<Expression> fDefined_Expression;
-private:
+private:
class Defined : public Expression {
public:
Defined(const Type& type)
: INHERITED(Position(), kDefined_Kind, type) {}
- virtual String description() const override {
- return String("<defined>");
+ virtual SkString description() const override {
+ return SkString("<defined>");
}
typedef Expression INHERITED;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ERRORREPORTER
#define SKSL_ERRORREPORTER
virtual ~ErrorReporter() {}
void error(Position position, const char* msg) {
- this->error(position, String(msg));
+ this->error(position, SkString(msg));
}
- virtual void error(Position position, String msg) = 0;
+ virtual void error(Position position, SkString msg) = 0;
virtual int errorCount() = 0;
};
+++ /dev/null
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SKSL_FILEOUTPUTSTREAM
-#define SKSL_FILEOUTPUTSTREAM
-
-#include "SkSLOutputStream.h"
-#include <stdio.h>
-
-namespace SkSL {
-
-class FileOutputStream : public OutputStream {
-public:
- FileOutputStream(const char* name) {
- fFile = fopen(name, "w");
- }
-
- ~FileOutputStream() {
- ASSERT(!fOpen);
- }
-
- bool isValid() const override {
- return nullptr != fFile;
- }
-
- void write8(uint8_t b) override {
- ASSERT(fOpen);
- if (isValid()) {
- if (EOF == fputc(b, fFile)) {
- fFile = nullptr;
- }
- }
- }
-
- void writeText(const char* s) override {
- ASSERT(fOpen);
- if (isValid()) {
- if (EOF == fputs(s, fFile)) {
- fFile = nullptr;
- }
- }
- }
-
- void write(const void* s, size_t size) override {
- if (isValid()) {
- size_t written = fwrite(s, 1, size, fFile);
- if (written != size) {
- fFile = nullptr;
- }
- }
- }
-
- bool close() {
- fOpen = false;
- if (isValid() && fclose(fFile)) {
- fFile = nullptr;
- return false;
- }
- return true;
- }
-
-private:
- bool fOpen = true;
- FILE *fFile;
-
- typedef OutputStream INHERITED;
-};
-
-} // namespace
-
-#endif
#include "SkSLGLSLCodeGenerator.h"
+#include "string.h"
+
#include "GLSL.std.450.h"
#include "SkSLCompiler.h"
void GLSLCodeGenerator::writeLine(const char* s) {
this->write(s);
- fOut->write8('\n');
+ fOut->writeText("\n");
fAtLineStart = true;
}
-void GLSLCodeGenerator::write(const String& s) {
+void GLSLCodeGenerator::write(const SkString& s) {
this->write(s.c_str());
}
-void GLSLCodeGenerator::writeLine(const String& s) {
+void GLSLCodeGenerator::writeLine(const SkString& s) {
this->writeLine(s.c_str());
}
// Tegra3 compiler bug.
void GLSLCodeGenerator::writeMinAbsHack(Expression& absExpr, Expression& otherExpr) {
ASSERT(!fProgram.fSettings.fCaps->canUseMinAndAbsTogether());
- String tmpVar1 = "minAbsHackVar" + to_string(fVarCount++);
- String tmpVar2 = "minAbsHackVar" + to_string(fVarCount++);
+ SkString tmpVar1 = "minAbsHackVar" + to_string(fVarCount++);
+ SkString tmpVar2 = "minAbsHackVar" + to_string(fVarCount++);
this->fFunctionHeader += " " + absExpr.fType.name() + " " + tmpVar1 + ";\n";
this->fFunctionHeader += " " + otherExpr.fType.name() + " " + tmpVar2 + ";\n";
this->write("((" + tmpVar1 + " = ");
}
}
-void GLSLCodeGenerator::writeBinaryExpression(const BinaryExpression& b,
+void GLSLCodeGenerator::writeBinaryExpression(const BinaryExpression& b,
Precedence parentPrecedence) {
Precedence precedence = get_binary_precedence(b.fOperator);
if (precedence >= parentPrecedence) {
}
}
-void GLSLCodeGenerator::writeTernaryExpression(const TernaryExpression& t,
+void GLSLCodeGenerator::writeTernaryExpression(const TernaryExpression& t,
Precedence parentPrecedence) {
if (kTernary_Precedence >= parentPrecedence) {
this->write("(");
}
}
-void GLSLCodeGenerator::writePrefixExpression(const PrefixExpression& p,
+void GLSLCodeGenerator::writePrefixExpression(const PrefixExpression& p,
Precedence parentPrecedence) {
if (kPrefix_Precedence >= parentPrecedence) {
this->write("(");
}
}
-void GLSLCodeGenerator::writePostfixExpression(const PostfixExpression& p,
+void GLSLCodeGenerator::writePostfixExpression(const PostfixExpression& p,
Precedence parentPrecedence) {
if (kPostfix_Precedence >= parentPrecedence) {
this->write("(");
this->writeLine(") {");
fFunctionHeader = "";
- OutputStream* oldOut = fOut;
- StringStream buffer;
+ SkWStream* oldOut = fOut;
+ SkDynamicMemoryWStream buffer;
fOut = &buffer;
fIndentation++;
for (const auto& s : f.fBody->fStatements) {
fOut = oldOut;
this->write(fFunctionHeader);
- this->write(String(buffer.data(), buffer.size()));
+ sk_sp<SkData> data(buffer.detachAsData());
+ this->write(SkString((const char*) data->data(), data->size()));
}
void GLSLCodeGenerator::writeModifiers(const Modifiers& modifiers,
if (modifiers.fFlags & Modifiers::kNoPerspective_Flag) {
this->write("noperspective ");
}
- String layout = modifiers.fLayout.description();
+ SkString layout = modifiers.fLayout.description();
if (layout.size()) {
this->write(layout + " ");
}
ASSERT(decl.fVars.size() > 0);
this->writeModifiers(decl.fVars[0].fVar->fModifiers, global);
this->writeType(decl.fBaseType);
- String separator(" ");
+ SkString separator(" ");
for (const auto& var : decl.fVars) {
ASSERT(var.fVar->fModifiers == decl.fVars[0].fVar->fModifiers);
this->write(separator);
- separator = String(", ");
+ separator = SkString(", ");
this->write(var.fVar->fName);
for (const auto& size : var.fSizes) {
this->write("[");
this->writeExpression(*((ExpressionStatement&) s).fExpression, kTopLevel_Precedence);
this->write(";");
break;
- case Statement::kReturn_Kind:
+ case Statement::kReturn_Kind:
this->writeReturnStatement((ReturnStatement&) s);
break;
case Statement::kVarDeclarations_Kind:
}
bool GLSLCodeGenerator::generateCode() {
- OutputStream* rawOut = fOut;
+ SkWStream* rawOut = fOut;
fOut = &fHeader;
fProgramKind = fProgram.fKind;
this->write(fProgram.fSettings.fCaps->versionDeclString());
this->writeExtension((Extension&) *e);
}
}
- StringStream body;
+ SkDynamicMemoryWStream body;
fOut = &body;
if (fProgram.fSettings.fCaps->usesPrecisionModifiers()) {
this->write("precision ");
}
fOut = nullptr;
- write_stringstream(fHeader, *rawOut);
- write_stringstream(body, *rawOut);
+ write_data(*fHeader.detachAsData(), *rawOut);
+ write_data(*body.detachAsData(), *rawOut);
return true;
}
#include <tuple>
#include <unordered_map>
+#include "SkStream.h"
#include "SkSLCodeGenerator.h"
#include "ir/SkSLBinaryExpression.h"
#include "ir/SkSLBoolLiteral.h"
};
GLSLCodeGenerator(const Context* context, const Program* program, ErrorReporter* errors,
- OutputStream* out)
+ SkWStream* out)
: INHERITED(program, errors, out)
, fContext(*context) {}
void writeLine(const char* s);
- void write(const String& s);
+ void write(const SkString& s);
- void writeLine(const String& s);
+ void writeLine(const SkString& s);
void writeType(const Type& type);
void writeInterfaceBlock(const InterfaceBlock& intf);
void writeFunctionStart(const FunctionDeclaration& f);
-
+
void writeFunctionDeclaration(const FunctionDeclaration& f);
void writeFunction(const FunctionDefinition& f);
void writeReturnStatement(const ReturnStatement& r);
const Context& fContext;
- StringStream fHeader;
- String fFunctionHeader;
+ SkDynamicMemoryWStream fHeader;
+ SkString fFunctionHeader;
Program::Kind fProgramKind;
int fVarCount = 0;
int fIndentation = 0;
fSymbolTable = fSymbolTable->fParent;
}
-static void fill_caps(const SKSL_CAPS_CLASS& caps, std::unordered_map<String, CapValue>* capsMap) {
-#define CAP(name) capsMap->insert(std::make_pair(String(#name), CapValue(caps.name())));
+static void fill_caps(const GrShaderCaps& caps, std::unordered_map<SkString, CapValue>* capsMap) {
+#define CAP(name) capsMap->insert(std::make_pair(SkString(#name), CapValue(caps.name())));
CAP(fbFetchSupport);
CAP(fbFetchNeedsCustomOutput);
CAP(bindlessTextureSupport);
if (!size) {
return nullptr;
}
- String name = type->fName;
+ SkString name = type->fName;
int64_t count;
if (size->fKind == Expression::kIntLiteral_Kind) {
count = ((IntLiteral&) *size).fValue;
}
value = this->coerce(std::move(value), *type);
}
- if (storage == Variable::kGlobal_Storage && varDecl.fName == String("sk_FragColor") &&
+ if (storage == Variable::kGlobal_Storage && varDecl.fName == SkString("sk_FragColor") &&
(*fSymbolTable)[varDecl.fName]) {
// already defined, ignore
} else if (storage == Variable::kGlobal_Storage && (*fSymbolTable)[varDecl.fName] &&
}
for (int j = (int) param->fSizes.size() - 1; j >= 0; j--) {
int size = param->fSizes[j];
- String name = type->name() + "[" + to_string(size) + "]";
+ SkString name = type->name() + "[" + to_string(size) + "]";
Type* newType = new Type(std::move(name), Type::kArray_Kind, *type, size);
fSymbolTable->takeOwnership(newType);
type = newType;
}
- String name = param->fName;
+ SkString name = param->fName;
Position pos = param->fPosition;
Variable* var = new Variable(pos, param->fModifiers, std::move(name), *type,
Variable::kParameter_Storage);
if (!converted) {
return nullptr;
}
- String name = type->fName;
+ SkString name = type->fName;
int64_t count;
if (converted->fKind == Expression::kIntLiteral_Kind) {
count = ((IntLiteral&) *converted).fValue;
const Symbol* result = (*fSymbolTable)[type.fName];
if (result && result->fKind == Symbol::kType_Kind) {
for (int size : type.fSizes) {
- String name = result->fName + "[";
+ SkString name = result->fName + "[";
if (size != -1) {
name += to_string(size);
}
const FunctionDeclaration& function,
std::vector<std::unique_ptr<Expression>> arguments) {
if (function.fParameters.size() != arguments.size()) {
- String msg = "call to '" + function.fName + "' expected " +
+ SkString msg = "call to '" + function.fName + "' expected " +
to_string((uint64_t) function.fParameters.size()) +
" argument";
if (function.fParameters.size() != 1) {
std::vector<const Type*> types;
const Type* returnType;
if (!function.determineFinalTypes(arguments, &types, &returnType)) {
- String msg = "no match for " + function.fName + "(";
- String separator;
+ SkString msg = "no match for " + function.fName + "(";
+ SkString separator;
for (size_t i = 0; i < arguments.size(); i++) {
msg += separator;
separator = ", ";
if (best) {
return this->call(position, *best, std::move(arguments));
}
- String msg = "no match for " + ref->fFunctions[0]->fName + "(";
- String separator;
+ SkString msg = "no match for " + ref->fFunctions[0]->fName + "(";
+ SkString separator;
for (size_t i = 0; i < arguments.size(); i++) {
msg += separator;
separator = ", ";
}
std::unique_ptr<Expression> IRGenerator::convertField(std::unique_ptr<Expression> base,
- const String& field) {
+ const SkString& field) {
auto fields = base->fType.fields();
for (size_t i = 0; i < fields.size(); i++) {
if (fields[i].fName == field) {
}
std::unique_ptr<Expression> IRGenerator::convertSwizzle(std::unique_ptr<Expression> base,
- const String& fields) {
+ const SkString& fields) {
if (base->fType.kind() != Type::kVector_Kind) {
fErrors.error(base->fPosition, "cannot swizzle type '" + base->fType.description() + "'");
return nullptr;
}
// fall through
default:
- fErrors.error(base->fPosition, String::printf("invalid swizzle component '%c'",
+ fErrors.error(base->fPosition, SkStringPrintf("invalid swizzle component '%c'",
fields[i]));
return nullptr;
}
return std::unique_ptr<Expression>(new Swizzle(fContext, std::move(base), swizzleComponents));
}
-std::unique_ptr<Expression> IRGenerator::getCap(Position position, String name) {
+std::unique_ptr<Expression> IRGenerator::getCap(Position position, SkString name) {
auto found = fCapsMap.find(name);
if (found == fCapsMap.end()) {
fErrors.error(position, "unknown capability flag '" + name + "'");
Modifiers convertModifiers(const Modifiers& m);
std::unique_ptr<Expression> convertPrefixExpression(const ASTPrefixExpression& expression);
std::unique_ptr<Statement> convertReturn(const ASTReturnStatement& r);
- std::unique_ptr<Expression> getCap(Position position, String name);
+ std::unique_ptr<Expression> getCap(Position position, SkString name);
std::unique_ptr<Expression> convertSuffixExpression(const ASTSuffixExpression& expression);
std::unique_ptr<Expression> convertField(std::unique_ptr<Expression> base,
- const String& field);
+ const SkString& field);
std::unique_ptr<Expression> convertSwizzle(std::unique_ptr<Expression> base,
- const String& fields);
+ const SkString& fields);
std::unique_ptr<Expression> convertTernaryExpression(const ASTTernaryExpression& expression);
std::unique_ptr<Statement> convertVarDeclarationStatement(const ASTVarDeclarationStatement& s);
std::unique_ptr<Statement> convertWhile(const ASTWhileStatement& w);
const FunctionDeclaration* fCurrentFunction;
const Program::Settings* fSettings;
- std::unordered_map<String, CapValue> fCapsMap;
+ std::unordered_map<SkString, CapValue> fCapsMap;
std::shared_ptr<SymbolTable> fSymbolTable;
int fLoopLevel;
int fSwitchLevel;
#include "stdio.h"
#include <fstream>
#include "SkSLCompiler.h"
-#include "SkSLFileOutputStream.h"
+#include "GrContextOptions.h"
/**
* Very simple standalone executable to facilitate testing.
std::ifstream in(argv[1]);
std::string stdText((std::istreambuf_iterator<char>(in)),
std::istreambuf_iterator<char>());
- SkSL::String text(stdText.c_str());
+ SkString text(stdText.c_str());
if (in.rdstate()) {
printf("error reading '%s'\n", argv[1]);
exit(2);
}
SkSL::Program::Settings settings;
- SkSL::String name(argv[2]);
+ sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
+ settings.fCaps = caps.get();
+ SkString name(argv[2]);
if (name.endsWith(".spirv")) {
- SkSL::FileOutputStream out(argv[2]);
+ SkFILEWStream out(argv[2]);
SkSL::Compiler compiler;
if (!out.isValid()) {
printf("error writing '%s'\n", argv[2]);
printf("%s", compiler.errorText().c_str());
exit(3);
}
- if (!out.close()) {
- printf("error writing '%s'\n", argv[2]);
- exit(4);
- }
} else if (name.endsWith(".glsl")) {
- SkSL::FileOutputStream out(argv[2]);
+ SkFILEWStream out(argv[2]);
SkSL::Compiler compiler;
if (!out.isValid()) {
printf("error writing '%s'\n", argv[2]);
printf("%s", compiler.errorText().c_str());
exit(3);
}
- if (!out.close()) {
- printf("error writing '%s'\n", argv[2]);
- exit(4);
- }
} else {
printf("expected output filename to end with '.spirv' or '.glsl'");
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKIASL_MEMORYLAYOUT
#define SKIASL_MEMORYLAYOUT
k430_Standard
};
- MemoryLayout(Standard std)
+ MemoryLayout(Standard std)
: fStd(std) {}
static size_t vector_alignment(size_t componentSize, int columns) {
return componentSize * (columns + columns % 2);
}
- /**
+ /**
* Rounds up to the nearest multiple of 16 if in std140, otherwise returns the parameter
* unchanged (std140 requires various things to be rounded up to the nearest multiple of 16,
* std430 does not).
case Type::kVector_Kind:
return vector_alignment(this->size(type.componentType()), type.columns());
case Type::kMatrix_Kind:
- return this->roundUpIfNeeded(vector_alignment(this->size(type.componentType()),
+ return this->roundUpIfNeeded(vector_alignment(this->size(type.componentType()),
type.rows()));
case Type::kArray_Kind:
return this->roundUpIfNeeded(this->alignment(type.componentType()));
return this->roundUpIfNeeded(result);
}
default:
- ABORT("cannot determine size of type %s", type.name().c_str());
+ ABORT(("cannot determine size of type " + type.name()).c_str());
}
}
total += this->size(*f.fType);
}
size_t alignment = this->alignment(type);
- ASSERT(!type.fields().size() ||
+ ASSERT(!type.fields().size() ||
(0 == alignment % this->alignment(*type.fields()[0].fType)));
return (total + alignment - 1) & ~(alignment - 1);
}
default:
- ABORT("cannot determine size of type %s", type.name().c_str());
+ ABORT(("cannot determine size of type " + type.name()).c_str());
}
}
+++ /dev/null
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SKSL_OUTPUTSTREAM
-#define SKSL_OUTPUTSTREAM
-
-#include "SkSLString.h"
-
-namespace SkSL {
-
-class OutputStream {
-public:
- virtual bool isValid() const {
- return true;
- }
-
- virtual void write8(uint8_t b) = 0;
-
- virtual void writeText(const char* s) = 0;
-
- virtual void write(const void* s, size_t size) = 0;
-
- void writeString(String s) {
- this->write(s.c_str(), s.size());
- }
-
- virtual ~OutputStream() {}
-};
-
-} // namespace
-
-#endif
bool checkValid() {
if (fParser->fDepth > MAX_PARSE_DEPTH) {
- fParser->error(fParser->peek().fPosition, String("exceeded max parse depth"));
+ fParser->error(fParser->peek().fPosition, SkString("exceeded max parse depth"));
return false;
}
return true;
Parser* fParser;
};
-Parser::Parser(String text, SymbolTable& types, ErrorReporter& errors)
-: fPushback(Position(-1, -1), Token::INVALID_TOKEN, String())
+Parser::Parser(SkString text, SymbolTable& types, ErrorReporter& errors)
+: fPushback(Position(-1, -1), Token::INVALID_TOKEN, SkString())
, fTypes(types)
, fErrors(errors) {
sksllex_init(&fScanner);
return result;
}
int token = sksllex(fScanner);
- String text;
+ SkString text;
switch ((Token::Kind) token) {
case Token::IDENTIFIER: // fall through
case Token::INT_LITERAL: // fall through
case Token::FLOAT_LITERAL: // fall through
case Token::DIRECTIVE:
- text = String(skslget_text(fScanner));
+ text = SkString(skslget_text(fScanner));
break;
default:
#ifdef SK_DEBUG
- text = String(skslget_text(fScanner));
+ text = SkString(skslget_text(fScanner));
#endif
break;
}
bool Parser::expect(Token::Kind kind, const char* expected, Token* result) {
- return this->expect(kind, String(expected), result);
+ return this->expect(kind, SkString(expected), result);
}
-bool Parser::expect(Token::Kind kind, String expected, Token* result) {
+bool Parser::expect(Token::Kind kind, SkString expected, Token* result) {
Token next = this->nextToken();
if (next.fKind == kind) {
if (result) {
}
void Parser::error(Position p, const char* msg) {
- this->error(p, String(msg));
+ this->error(p, SkString(msg));
}
-void Parser::error(Position p, String msg) {
+void Parser::error(Position p, SkString msg) {
fErrors.error(p, msg);
}
-bool Parser::isType(String name) {
+bool Parser::isType(SkString name) {
return nullptr != fTypes[name];
}
return nullptr;
}
uint64_t columns = ((ASTIntLiteral&) *var.fSizes[i]).fValue;
- String name = type->name() + "[" + to_string(columns) + "]";
+ SkString name = type->name() + "[" + to_string(columns) + "]";
type = new Type(name, Type::kArray_Kind, *type, (int) columns);
fTypes.takeOwnership((Type*) type);
}
(LBRACKET expression? RBRACKET)* (EQ expression)?)* SEMICOLON */
std::unique_ptr<ASTVarDeclarations> Parser::varDeclarationEnd(Modifiers mods,
std::unique_ptr<ASTType> type,
- String name) {
+ SkString name) {
std::vector<ASTVarDeclaration> vars;
std::vector<std::unique_ptr<ASTExpression>> currentVarSizes;
while (this->peek().fKind == Token::LBRACKET) {
decls.push_back(std::move(decl));
}
this->nextToken();
- String instanceName;
+ SkString instanceName;
std::vector<std::unique_ptr<ASTExpression>> sizes;
if (this->peek().fKind == Token::IDENTIFIER) {
instanceName = this->nextToken().fText;
// parts of the compiler may rely upon this assumption.
if (this->peek().fKind == Token::DEFAULT) {
Token defaultStart;
- ASSERT_RESULT(this->expect(Token::DEFAULT, "'default'", &defaultStart));
+ SkAssertResult(this->expect(Token::DEFAULT, "'default'", &defaultStart));
if (!this->expect(Token::COLON, "':'")) {
return nullptr;
}
}
case Token::DOT: {
Position pos = this->peek().fPosition;
- String text;
+ SkString text;
if (this->identifier(&text)) {
return std::unique_ptr<ASTSuffix>(new ASTFieldSuffix(pos, std::move(text)));
}
Token t = this->peek();
switch (t.fKind) {
case Token::IDENTIFIER: {
- String text;
+ SkString text;
if (this->identifier(&text)) {
result.reset(new ASTIdentifier(t.fPosition, std::move(text)));
}
}
/* IDENTIFIER */
-bool Parser::identifier(String* dest) {
+bool Parser::identifier(SkString* dest) {
Token t;
if (this->expect(Token::IDENTIFIER, "identifier", &t)) {
*dest = t.fText;
*/
class Parser {
public:
- Parser(String text, SymbolTable& types, ErrorReporter& errors);
+ Parser(SkString text, SymbolTable& types, ErrorReporter& errors);
~Parser();
* Returns true if the read token was as expected, false otherwise.
*/
bool expect(Token::Kind kind, const char* expected, Token* result = nullptr);
- bool expect(Token::Kind kind, String expected, Token* result = nullptr);
+ bool expect(Token::Kind kind, SkString expected, Token* result = nullptr);
void error(Position p, const char* msg);
- void error(Position p, String msg);
-
+ void error(Position p, SkString msg);
+
/**
* Returns true if the 'name' identifier refers to a type name. For instance, isType("int") will
* always return true.
*/
- bool isType(String name);
+ bool isType(SkString name);
// these functions parse individual grammar rules from the current parse position; you probably
// don't need to call any of these outside of the parser. The function declarations in the .cpp
std::unique_ptr<ASTVarDeclarations> varDeclarationEnd(Modifiers modifiers,
std::unique_ptr<ASTType> type,
- String name);
+ SkString name);
std::unique_ptr<ASTParameter> parameter();
int layoutInt();
-
+
Layout layout();
Modifiers modifiers();
std::unique_ptr<ASTExpression> expression();
std::unique_ptr<ASTExpression> assignmentExpression();
-
+
std::unique_ptr<ASTExpression> ternaryExpression();
std::unique_ptr<ASTExpression> logicalOrExpression();
bool boolLiteral(bool* dest);
- bool identifier(String* dest);
+ bool identifier(SkString* dest);
void* fScanner;
void* fLayoutScanner;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_POSITION
#define SKSL_POSITION
* ignored.
*/
struct Position {
- Position()
+ Position()
: fLine(-1)
, fColumn(-1) {}
-
+
Position(int line, int column)
: fLine(line)
, fColumn(column) {}
- String description() const {
+ SkString description() const {
return to_string(fLine);
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#include "SkSLSPIRVCodeGenerator.h"
+#include "string.h"
+
#include "GLSL.std.450.h"
#include "ir/SkSLExpressionStatement.h"
#define SPECIAL(x) std::make_tuple(kSpecial_IntrinsicKind, k ## x ## _SpecialIntrinsic, \
k ## x ## _SpecialIntrinsic, k ## x ## _SpecialIntrinsic, \
k ## x ## _SpecialIntrinsic)
- fIntrinsicMap[String("round")] = ALL_GLSL(Round);
- fIntrinsicMap[String("roundEven")] = ALL_GLSL(RoundEven);
- fIntrinsicMap[String("trunc")] = ALL_GLSL(Trunc);
- fIntrinsicMap[String("abs")] = BY_TYPE_GLSL(FAbs, SAbs, SAbs);
- fIntrinsicMap[String("sign")] = BY_TYPE_GLSL(FSign, SSign, SSign);
- fIntrinsicMap[String("floor")] = ALL_GLSL(Floor);
- fIntrinsicMap[String("ceil")] = ALL_GLSL(Ceil);
- fIntrinsicMap[String("fract")] = ALL_GLSL(Fract);
- fIntrinsicMap[String("radians")] = ALL_GLSL(Radians);
- fIntrinsicMap[String("degrees")] = ALL_GLSL(Degrees);
- fIntrinsicMap[String("sin")] = ALL_GLSL(Sin);
- fIntrinsicMap[String("cos")] = ALL_GLSL(Cos);
- fIntrinsicMap[String("tan")] = ALL_GLSL(Tan);
- fIntrinsicMap[String("asin")] = ALL_GLSL(Asin);
- fIntrinsicMap[String("acos")] = ALL_GLSL(Acos);
- fIntrinsicMap[String("atan")] = SPECIAL(Atan);
- fIntrinsicMap[String("sinh")] = ALL_GLSL(Sinh);
- fIntrinsicMap[String("cosh")] = ALL_GLSL(Cosh);
- fIntrinsicMap[String("tanh")] = ALL_GLSL(Tanh);
- fIntrinsicMap[String("asinh")] = ALL_GLSL(Asinh);
- fIntrinsicMap[String("acosh")] = ALL_GLSL(Acosh);
- fIntrinsicMap[String("atanh")] = ALL_GLSL(Atanh);
- fIntrinsicMap[String("pow")] = ALL_GLSL(Pow);
- fIntrinsicMap[String("exp")] = ALL_GLSL(Exp);
- fIntrinsicMap[String("log")] = ALL_GLSL(Log);
- fIntrinsicMap[String("exp2")] = ALL_GLSL(Exp2);
- fIntrinsicMap[String("log2")] = ALL_GLSL(Log2);
- fIntrinsicMap[String("sqrt")] = ALL_GLSL(Sqrt);
- fIntrinsicMap[String("inversesqrt")] = ALL_GLSL(InverseSqrt);
- fIntrinsicMap[String("determinant")] = ALL_GLSL(Determinant);
- fIntrinsicMap[String("matrixInverse")] = ALL_GLSL(MatrixInverse);
- fIntrinsicMap[String("mod")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpFMod,
+ fIntrinsicMap[SkString("round")] = ALL_GLSL(Round);
+ fIntrinsicMap[SkString("roundEven")] = ALL_GLSL(RoundEven);
+ fIntrinsicMap[SkString("trunc")] = ALL_GLSL(Trunc);
+ fIntrinsicMap[SkString("abs")] = BY_TYPE_GLSL(FAbs, SAbs, SAbs);
+ fIntrinsicMap[SkString("sign")] = BY_TYPE_GLSL(FSign, SSign, SSign);
+ fIntrinsicMap[SkString("floor")] = ALL_GLSL(Floor);
+ fIntrinsicMap[SkString("ceil")] = ALL_GLSL(Ceil);
+ fIntrinsicMap[SkString("fract")] = ALL_GLSL(Fract);
+ fIntrinsicMap[SkString("radians")] = ALL_GLSL(Radians);
+ fIntrinsicMap[SkString("degrees")] = ALL_GLSL(Degrees);
+ fIntrinsicMap[SkString("sin")] = ALL_GLSL(Sin);
+ fIntrinsicMap[SkString("cos")] = ALL_GLSL(Cos);
+ fIntrinsicMap[SkString("tan")] = ALL_GLSL(Tan);
+ fIntrinsicMap[SkString("asin")] = ALL_GLSL(Asin);
+ fIntrinsicMap[SkString("acos")] = ALL_GLSL(Acos);
+ fIntrinsicMap[SkString("atan")] = SPECIAL(Atan);
+ fIntrinsicMap[SkString("sinh")] = ALL_GLSL(Sinh);
+ fIntrinsicMap[SkString("cosh")] = ALL_GLSL(Cosh);
+ fIntrinsicMap[SkString("tanh")] = ALL_GLSL(Tanh);
+ fIntrinsicMap[SkString("asinh")] = ALL_GLSL(Asinh);
+ fIntrinsicMap[SkString("acosh")] = ALL_GLSL(Acosh);
+ fIntrinsicMap[SkString("atanh")] = ALL_GLSL(Atanh);
+ fIntrinsicMap[SkString("pow")] = ALL_GLSL(Pow);
+ fIntrinsicMap[SkString("exp")] = ALL_GLSL(Exp);
+ fIntrinsicMap[SkString("log")] = ALL_GLSL(Log);
+ fIntrinsicMap[SkString("exp2")] = ALL_GLSL(Exp2);
+ fIntrinsicMap[SkString("log2")] = ALL_GLSL(Log2);
+ fIntrinsicMap[SkString("sqrt")] = ALL_GLSL(Sqrt);
+ fIntrinsicMap[SkString("inversesqrt")] = ALL_GLSL(InverseSqrt);
+ fIntrinsicMap[SkString("determinant")] = ALL_GLSL(Determinant);
+ fIntrinsicMap[SkString("matrixInverse")] = ALL_GLSL(MatrixInverse);
+ fIntrinsicMap[SkString("mod")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpFMod,
SpvOpSMod, SpvOpUMod, SpvOpUndef);
- fIntrinsicMap[String("min")] = BY_TYPE_GLSL(FMin, SMin, UMin);
- fIntrinsicMap[String("max")] = BY_TYPE_GLSL(FMax, SMax, UMax);
- fIntrinsicMap[String("clamp")] = BY_TYPE_GLSL(FClamp, SClamp, UClamp);
- fIntrinsicMap[String("dot")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDot,
+ fIntrinsicMap[SkString("min")] = BY_TYPE_GLSL(FMin, SMin, UMin);
+ fIntrinsicMap[SkString("max")] = BY_TYPE_GLSL(FMax, SMax, UMax);
+ fIntrinsicMap[SkString("clamp")] = BY_TYPE_GLSL(FClamp, SClamp, UClamp);
+ fIntrinsicMap[SkString("dot")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDot,
SpvOpUndef, SpvOpUndef, SpvOpUndef);
- fIntrinsicMap[String("mix")] = ALL_GLSL(FMix);
- fIntrinsicMap[String("step")] = ALL_GLSL(Step);
- fIntrinsicMap[String("smoothstep")] = ALL_GLSL(SmoothStep);
- fIntrinsicMap[String("fma")] = ALL_GLSL(Fma);
- fIntrinsicMap[String("frexp")] = ALL_GLSL(Frexp);
- fIntrinsicMap[String("ldexp")] = ALL_GLSL(Ldexp);
-
-#define PACK(type) fIntrinsicMap[String("pack" #type)] = ALL_GLSL(Pack ## type); \
- fIntrinsicMap[String("unpack" #type)] = ALL_GLSL(Unpack ## type)
+ fIntrinsicMap[SkString("mix")] = ALL_GLSL(FMix);
+ fIntrinsicMap[SkString("step")] = ALL_GLSL(Step);
+ fIntrinsicMap[SkString("smoothstep")] = ALL_GLSL(SmoothStep);
+ fIntrinsicMap[SkString("fma")] = ALL_GLSL(Fma);
+ fIntrinsicMap[SkString("frexp")] = ALL_GLSL(Frexp);
+ fIntrinsicMap[SkString("ldexp")] = ALL_GLSL(Ldexp);
+
+#define PACK(type) fIntrinsicMap[SkString("pack" #type)] = ALL_GLSL(Pack ## type); \
+ fIntrinsicMap[SkString("unpack" #type)] = ALL_GLSL(Unpack ## type)
PACK(Snorm4x8);
PACK(Unorm4x8);
PACK(Snorm2x16);
PACK(Unorm2x16);
PACK(Half2x16);
PACK(Double2x32);
- fIntrinsicMap[String("length")] = ALL_GLSL(Length);
- fIntrinsicMap[String("distance")] = ALL_GLSL(Distance);
- fIntrinsicMap[String("cross")] = ALL_GLSL(Cross);
- fIntrinsicMap[String("normalize")] = ALL_GLSL(Normalize);
- fIntrinsicMap[String("faceForward")] = ALL_GLSL(FaceForward);
- fIntrinsicMap[String("reflect")] = ALL_GLSL(Reflect);
- fIntrinsicMap[String("refract")] = ALL_GLSL(Refract);
- fIntrinsicMap[String("findLSB")] = ALL_GLSL(FindILsb);
- fIntrinsicMap[String("findMSB")] = BY_TYPE_GLSL(FindSMsb, FindSMsb, FindUMsb);
- fIntrinsicMap[String("dFdx")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdx,
+ fIntrinsicMap[SkString("length")] = ALL_GLSL(Length);
+ fIntrinsicMap[SkString("distance")] = ALL_GLSL(Distance);
+ fIntrinsicMap[SkString("cross")] = ALL_GLSL(Cross);
+ fIntrinsicMap[SkString("normalize")] = ALL_GLSL(Normalize);
+ fIntrinsicMap[SkString("faceForward")] = ALL_GLSL(FaceForward);
+ fIntrinsicMap[SkString("reflect")] = ALL_GLSL(Reflect);
+ fIntrinsicMap[SkString("refract")] = ALL_GLSL(Refract);
+ fIntrinsicMap[SkString("findLSB")] = ALL_GLSL(FindILsb);
+ fIntrinsicMap[SkString("findMSB")] = BY_TYPE_GLSL(FindSMsb, FindSMsb, FindUMsb);
+ fIntrinsicMap[SkString("dFdx")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdx,
SpvOpUndef, SpvOpUndef, SpvOpUndef);
- fIntrinsicMap[String("dFdy")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy,
+ fIntrinsicMap[SkString("dFdy")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy,
SpvOpUndef, SpvOpUndef, SpvOpUndef);
- fIntrinsicMap[String("dFdy")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy,
+ fIntrinsicMap[SkString("dFdy")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy,
SpvOpUndef, SpvOpUndef, SpvOpUndef);
- fIntrinsicMap[String("texture")] = SPECIAL(Texture);
+ fIntrinsicMap[SkString("texture")] = SPECIAL(Texture);
- fIntrinsicMap[String("subpassLoad")] = SPECIAL(SubpassLoad);
+ fIntrinsicMap[SkString("subpassLoad")] = SPECIAL(SubpassLoad);
- fIntrinsicMap[String("any")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef,
+ fIntrinsicMap[SkString("any")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef,
SpvOpUndef, SpvOpUndef, SpvOpAny);
- fIntrinsicMap[String("all")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef,
+ fIntrinsicMap[SkString("all")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef,
SpvOpUndef, SpvOpUndef, SpvOpAll);
- fIntrinsicMap[String("equal")] = std::make_tuple(kSPIRV_IntrinsicKind,
+ fIntrinsicMap[SkString("equal")] = std::make_tuple(kSPIRV_IntrinsicKind,
SpvOpFOrdEqual, SpvOpIEqual,
SpvOpIEqual, SpvOpLogicalEqual);
- fIntrinsicMap[String("notEqual")] = std::make_tuple(kSPIRV_IntrinsicKind,
+ fIntrinsicMap[SkString("notEqual")] = std::make_tuple(kSPIRV_IntrinsicKind,
SpvOpFOrdNotEqual, SpvOpINotEqual,
SpvOpINotEqual,
SpvOpLogicalNotEqual);
- fIntrinsicMap[String("lessThan")] = std::make_tuple(kSPIRV_IntrinsicKind,
+ fIntrinsicMap[SkString("lessThan")] = std::make_tuple(kSPIRV_IntrinsicKind,
SpvOpSLessThan, SpvOpULessThan,
SpvOpFOrdLessThan, SpvOpUndef);
- fIntrinsicMap[String("lessThanEqual")] = std::make_tuple(kSPIRV_IntrinsicKind,
+ fIntrinsicMap[SkString("lessThanEqual")] = std::make_tuple(kSPIRV_IntrinsicKind,
SpvOpSLessThanEqual,
SpvOpULessThanEqual,
SpvOpFOrdLessThanEqual,
SpvOpUndef);
- fIntrinsicMap[String("greaterThan")] = std::make_tuple(kSPIRV_IntrinsicKind,
+ fIntrinsicMap[SkString("greaterThan")] = std::make_tuple(kSPIRV_IntrinsicKind,
SpvOpSGreaterThan,
SpvOpUGreaterThan,
SpvOpFOrdGreaterThan,
SpvOpUndef);
- fIntrinsicMap[String("greaterThanEqual")] = std::make_tuple(kSPIRV_IntrinsicKind,
+ fIntrinsicMap[SkString("greaterThanEqual")] = std::make_tuple(kSPIRV_IntrinsicKind,
SpvOpSGreaterThanEqual,
SpvOpUGreaterThanEqual,
SpvOpFOrdGreaterThanEqual,
SpvOpUndef);
+
// interpolateAt* not yet supported...
}
-void SPIRVCodeGenerator::writeWord(int32_t word, OutputStream& out) {
+void SPIRVCodeGenerator::writeWord(int32_t word, SkWStream& out) {
#if SPIRV_DEBUG
out << "(" << word << ") ";
#else
}
#if SPIRV_DEBUG
-static String opcode_text(SpvOp_ opCode) {
+static SkString opcode_text(SpvOp_ opCode) {
switch (opCode) {
case SpvOpNop:
- return String("Nop");
+ return SkString("Nop");
case SpvOpUndef:
- return String("Undef");
+ return SkString("Undef");
case SpvOpSourceContinued:
- return String("SourceContinued");
+ return SkString("SourceContinued");
case SpvOpSource:
- return String("Source");
+ return SkString("Source");
case SpvOpSourceExtension:
- return String("SourceExtension");
+ return SkString("SourceExtension");
case SpvOpName:
- return String("Name");
+ return SkString("Name");
case SpvOpMemberName:
- return String("MemberName");
+ return SkString("MemberName");
case SpvOpString:
- return String("String");
+ return SkString("String");
case SpvOpLine:
- return String("Line");
+ return SkString("Line");
case SpvOpExtension:
- return String("Extension");
+ return SkString("Extension");
case SpvOpExtInstImport:
- return String("ExtInstImport");
+ return SkString("ExtInstImport");
case SpvOpExtInst:
- return String("ExtInst");
+ return SkString("ExtInst");
case SpvOpMemoryModel:
- return String("MemoryModel");
+ return SkString("MemoryModel");
case SpvOpEntryPoint:
- return String("EntryPoint");
+ return SkString("EntryPoint");
case SpvOpExecutionMode:
- return String("ExecutionMode");
+ return SkString("ExecutionMode");
case SpvOpCapability:
- return String("Capability");
+ return SkString("Capability");
case SpvOpTypeVoid:
- return String("TypeVoid");
+ return SkString("TypeVoid");
case SpvOpTypeBool:
- return String("TypeBool");
+ return SkString("TypeBool");
case SpvOpTypeInt:
- return String("TypeInt");
+ return SkString("TypeInt");
case SpvOpTypeFloat:
- return String("TypeFloat");
+ return SkString("TypeFloat");
case SpvOpTypeVector:
- return String("TypeVector");
+ return SkString("TypeVector");
case SpvOpTypeMatrix:
- return String("TypeMatrix");
+ return SkString("TypeMatrix");
case SpvOpTypeImage:
- return String("TypeImage");
+ return SkString("TypeImage");
case SpvOpTypeSampler:
- return String("TypeSampler");
+ return SkString("TypeSampler");
case SpvOpTypeSampledImage:
- return String("TypeSampledImage");
+ return SkString("TypeSampledImage");
case SpvOpTypeArray:
- return String("TypeArray");
+ return SkString("TypeArray");
case SpvOpTypeRuntimeArray:
- return String("TypeRuntimeArray");
+ return SkString("TypeRuntimeArray");
case SpvOpTypeStruct:
- return String("TypeStruct");
+ return SkString("TypeStruct");
case SpvOpTypeOpaque:
- return String("TypeOpaque");
+ return SkString("TypeOpaque");
case SpvOpTypePointer:
- return String("TypePointer");
+ return SkString("TypePointer");
case SpvOpTypeFunction:
- return String("TypeFunction");
+ return SkString("TypeFunction");
case SpvOpTypeEvent:
- return String("TypeEvent");
+ return SkString("TypeEvent");
case SpvOpTypeDeviceEvent:
- return String("TypeDeviceEvent");
+ return SkString("TypeDeviceEvent");
case SpvOpTypeReserveId:
- return String("TypeReserveId");
+ return SkString("TypeReserveId");
case SpvOpTypeQueue:
- return String("TypeQueue");
+ return SkString("TypeQueue");
case SpvOpTypePipe:
- return String("TypePipe");
+ return SkString("TypePipe");
case SpvOpTypeForwardPointer:
- return String("TypeForwardPointer");
+ return SkString("TypeForwardPointer");
case SpvOpConstantTrue:
- return String("ConstantTrue");
+ return SkString("ConstantTrue");
case SpvOpConstantFalse:
- return String("ConstantFalse");
+ return SkString("ConstantFalse");
case SpvOpConstant:
- return String("Constant");
+ return SkString("Constant");
case SpvOpConstantComposite:
- return String("ConstantComposite");
+ return SkString("ConstantComposite");
case SpvOpConstantSampler:
- return String("ConstantSampler");
+ return SkString("ConstantSampler");
case SpvOpConstantNull:
- return String("ConstantNull");
+ return SkString("ConstantNull");
case SpvOpSpecConstantTrue:
- return String("SpecConstantTrue");
+ return SkString("SpecConstantTrue");
case SpvOpSpecConstantFalse:
- return String("SpecConstantFalse");
+ return SkString("SpecConstantFalse");
case SpvOpSpecConstant:
- return String("SpecConstant");
+ return SkString("SpecConstant");
case SpvOpSpecConstantComposite:
- return String("SpecConstantComposite");
+ return SkString("SpecConstantComposite");
case SpvOpSpecConstantOp:
- return String("SpecConstantOp");
+ return SkString("SpecConstantOp");
case SpvOpFunction:
- return String("Function");
+ return SkString("Function");
case SpvOpFunctionParameter:
- return String("FunctionParameter");
+ return SkString("FunctionParameter");
case SpvOpFunctionEnd:
- return String("FunctionEnd");
+ return SkString("FunctionEnd");
case SpvOpFunctionCall:
- return String("FunctionCall");
+ return SkString("FunctionCall");
case SpvOpVariable:
- return String("Variable");
+ return SkString("Variable");
case SpvOpImageTexelPointer:
- return String("ImageTexelPointer");
+ return SkString("ImageTexelPointer");
case SpvOpLoad:
- return String("Load");
+ return SkString("Load");
case SpvOpStore:
- return String("Store");
+ return SkString("Store");
case SpvOpCopyMemory:
- return String("CopyMemory");
+ return SkString("CopyMemory");
case SpvOpCopyMemorySized:
- return String("CopyMemorySized");
+ return SkString("CopyMemorySized");
case SpvOpAccessChain:
- return String("AccessChain");
+ return SkString("AccessChain");
case SpvOpInBoundsAccessChain:
- return String("InBoundsAccessChain");
+ return SkString("InBoundsAccessChain");
case SpvOpPtrAccessChain:
- return String("PtrAccessChain");
+ return SkString("PtrAccessChain");
case SpvOpArrayLength:
- return String("ArrayLength");
+ return SkString("ArrayLength");
case SpvOpGenericPtrMemSemantics:
- return String("GenericPtrMemSemantics");
+ return SkString("GenericPtrMemSemantics");
case SpvOpInBoundsPtrAccessChain:
- return String("InBoundsPtrAccessChain");
+ return SkString("InBoundsPtrAccessChain");
case SpvOpDecorate:
- return String("Decorate");
+ return SkString("Decorate");
case SpvOpMemberDecorate:
- return String("MemberDecorate");
+ return SkString("MemberDecorate");
case SpvOpDecorationGroup:
- return String("DecorationGroup");
+ return SkString("DecorationGroup");
case SpvOpGroupDecorate:
- return String("GroupDecorate");
+ return SkString("GroupDecorate");
case SpvOpGroupMemberDecorate:
- return String("GroupMemberDecorate");
+ return SkString("GroupMemberDecorate");
case SpvOpVectorExtractDynamic:
- return String("VectorExtractDynamic");
+ return SkString("VectorExtractDynamic");
case SpvOpVectorInsertDynamic:
- return String("VectorInsertDynamic");
+ return SkString("VectorInsertDynamic");
case SpvOpVectorShuffle:
- return String("VectorShuffle");
+ return SkString("VectorShuffle");
case SpvOpCompositeConstruct:
- return String("CompositeConstruct");
+ return SkString("CompositeConstruct");
case SpvOpCompositeExtract:
- return String("CompositeExtract");
+ return SkString("CompositeExtract");
case SpvOpCompositeInsert:
- return String("CompositeInsert");
+ return SkString("CompositeInsert");
case SpvOpCopyObject:
- return String("CopyObject");
+ return SkString("CopyObject");
case SpvOpTranspose:
- return String("Transpose");
+ return SkString("Transpose");
case SpvOpSampledImage:
- return String("SampledImage");
+ return SkString("SampledImage");
case SpvOpImageSampleImplicitLod:
- return String("ImageSampleImplicitLod");
+ return SkString("ImageSampleImplicitLod");
case SpvOpImageSampleExplicitLod:
- return String("ImageSampleExplicitLod");
+ return SkString("ImageSampleExplicitLod");
case SpvOpImageSampleDrefImplicitLod:
- return String("ImageSampleDrefImplicitLod");
+ return SkString("ImageSampleDrefImplicitLod");
case SpvOpImageSampleDrefExplicitLod:
- return String("ImageSampleDrefExplicitLod");
+ return SkString("ImageSampleDrefExplicitLod");
case SpvOpImageSampleProjImplicitLod:
- return String("ImageSampleProjImplicitLod");
+ return SkString("ImageSampleProjImplicitLod");
case SpvOpImageSampleProjExplicitLod:
- return String("ImageSampleProjExplicitLod");
+ return SkString("ImageSampleProjExplicitLod");
case SpvOpImageSampleProjDrefImplicitLod:
- return String("ImageSampleProjDrefImplicitLod");
+ return SkString("ImageSampleProjDrefImplicitLod");
case SpvOpImageSampleProjDrefExplicitLod:
- return String("ImageSampleProjDrefExplicitLod");
+ return SkString("ImageSampleProjDrefExplicitLod");
case SpvOpImageFetch:
- return String("ImageFetch");
+ return SkString("ImageFetch");
case SpvOpImageGather:
- return String("ImageGather");
+ return SkString("ImageGather");
case SpvOpImageDrefGather:
- return String("ImageDrefGather");
+ return SkString("ImageDrefGather");
case SpvOpImageRead:
- return String("ImageRead");
+ return SkString("ImageRead");
case SpvOpImageWrite:
- return String("ImageWrite");
+ return SkString("ImageWrite");
case SpvOpImage:
- return String("Image");
+ return SkString("Image");
case SpvOpImageQueryFormat:
- return String("ImageQueryFormat");
+ return SkString("ImageQueryFormat");
case SpvOpImageQueryOrder:
- return String("ImageQueryOrder");
+ return SkString("ImageQueryOrder");
case SpvOpImageQuerySizeLod:
- return String("ImageQuerySizeLod");
+ return SkString("ImageQuerySizeLod");
case SpvOpImageQuerySize:
- return String("ImageQuerySize");
+ return SkString("ImageQuerySize");
case SpvOpImageQueryLod:
- return String("ImageQueryLod");
+ return SkString("ImageQueryLod");
case SpvOpImageQueryLevels:
- return String("ImageQueryLevels");
+ return SkString("ImageQueryLevels");
case SpvOpImageQuerySamples:
- return String("ImageQuerySamples");
+ return SkString("ImageQuerySamples");
case SpvOpConvertFToU:
- return String("ConvertFToU");
+ return SkString("ConvertFToU");
case SpvOpConvertFToS:
- return String("ConvertFToS");
+ return SkString("ConvertFToS");
case SpvOpConvertSToF:
- return String("ConvertSToF");
+ return SkString("ConvertSToF");
case SpvOpConvertUToF:
- return String("ConvertUToF");
+ return SkString("ConvertUToF");
case SpvOpUConvert:
- return String("UConvert");
+ return SkString("UConvert");
case SpvOpSConvert:
- return String("SConvert");
+ return SkString("SConvert");
case SpvOpFConvert:
- return String("FConvert");
+ return SkString("FConvert");
case SpvOpQuantizeToF16:
- return String("QuantizeToF16");
+ return SkString("QuantizeToF16");
case SpvOpConvertPtrToU:
- return String("ConvertPtrToU");
+ return SkString("ConvertPtrToU");
case SpvOpSatConvertSToU:
- return String("SatConvertSToU");
+ return SkString("SatConvertSToU");
case SpvOpSatConvertUToS:
- return String("SatConvertUToS");
+ return SkString("SatConvertUToS");
case SpvOpConvertUToPtr:
- return String("ConvertUToPtr");
+ return SkString("ConvertUToPtr");
case SpvOpPtrCastToGeneric:
- return String("PtrCastToGeneric");
+ return SkString("PtrCastToGeneric");
case SpvOpGenericCastToPtr:
- return String("GenericCastToPtr");
+ return SkString("GenericCastToPtr");
case SpvOpGenericCastToPtrExplicit:
- return String("GenericCastToPtrExplicit");
+ return SkString("GenericCastToPtrExplicit");
case SpvOpBitcast:
- return String("Bitcast");
+ return SkString("Bitcast");
case SpvOpSNegate:
- return String("SNegate");
+ return SkString("SNegate");
case SpvOpFNegate:
- return String("FNegate");
+ return SkString("FNegate");
case SpvOpIAdd:
- return String("IAdd");
+ return SkString("IAdd");
case SpvOpFAdd:
- return String("FAdd");
+ return SkString("FAdd");
case SpvOpISub:
- return String("ISub");
+ return SkString("ISub");
case SpvOpFSub:
- return String("FSub");
+ return SkString("FSub");
case SpvOpIMul:
- return String("IMul");
+ return SkString("IMul");
case SpvOpFMul:
- return String("FMul");
+ return SkString("FMul");
case SpvOpUDiv:
- return String("UDiv");
+ return SkString("UDiv");
case SpvOpSDiv:
- return String("SDiv");
+ return SkString("SDiv");
case SpvOpFDiv:
- return String("FDiv");
+ return SkString("FDiv");
case SpvOpUMod:
- return String("UMod");
+ return SkString("UMod");
case SpvOpSRem:
- return String("SRem");
+ return SkString("SRem");
case SpvOpSMod:
- return String("SMod");
+ return SkString("SMod");
case SpvOpFRem:
- return String("FRem");
+ return SkString("FRem");
case SpvOpFMod:
- return String("FMod");
+ return SkString("FMod");
case SpvOpVectorTimesScalar:
- return String("VectorTimesScalar");
+ return SkString("VectorTimesScalar");
case SpvOpMatrixTimesScalar:
- return String("MatrixTimesScalar");
+ return SkString("MatrixTimesScalar");
case SpvOpVectorTimesMatrix:
- return String("VectorTimesMatrix");
+ return SkString("VectorTimesMatrix");
case SpvOpMatrixTimesVector:
- return String("MatrixTimesVector");
+ return SkString("MatrixTimesVector");
case SpvOpMatrixTimesMatrix:
- return String("MatrixTimesMatrix");
+ return SkString("MatrixTimesMatrix");
case SpvOpOuterProduct:
- return String("OuterProduct");
+ return SkString("OuterProduct");
case SpvOpDot:
- return String("Dot");
+ return SkString("Dot");
case SpvOpIAddCarry:
- return String("IAddCarry");
+ return SkString("IAddCarry");
case SpvOpISubBorrow:
- return String("ISubBorrow");
+ return SkString("ISubBorrow");
case SpvOpUMulExtended:
- return String("UMulExtended");
+ return SkString("UMulExtended");
case SpvOpSMulExtended:
- return String("SMulExtended");
+ return SkString("SMulExtended");
case SpvOpAny:
- return String("Any");
+ return SkString("Any");
case SpvOpAll:
- return String("All");
+ return SkString("All");
case SpvOpIsNan:
- return String("IsNan");
+ return SkString("IsNan");
case SpvOpIsInf:
- return String("IsInf");
+ return SkString("IsInf");
case SpvOpIsFinite:
- return String("IsFinite");
+ return SkString("IsFinite");
case SpvOpIsNormal:
- return String("IsNormal");
+ return SkString("IsNormal");
case SpvOpSignBitSet:
- return String("SignBitSet");
+ return SkString("SignBitSet");
case SpvOpLessOrGreater:
- return String("LessOrGreater");
+ return SkString("LessOrGreater");
case SpvOpOrdered:
- return String("Ordered");
+ return SkString("Ordered");
case SpvOpUnordered:
- return String("Unordered");
+ return SkString("Unordered");
case SpvOpLogicalEqual:
- return String("LogicalEqual");
+ return SkString("LogicalEqual");
case SpvOpLogicalNotEqual:
- return String("LogicalNotEqual");
+ return SkString("LogicalNotEqual");
case SpvOpLogicalOr:
- return String("LogicalOr");
+ return SkString("LogicalOr");
case SpvOpLogicalAnd:
- return String("LogicalAnd");
+ return SkString("LogicalAnd");
case SpvOpLogicalNot:
- return String("LogicalNot");
+ return SkString("LogicalNot");
case SpvOpSelect:
- return String("Select");
+ return SkString("Select");
case SpvOpIEqual:
- return String("IEqual");
+ return SkString("IEqual");
case SpvOpINotEqual:
- return String("INotEqual");
+ return SkString("INotEqual");
case SpvOpUGreaterThan:
- return String("UGreaterThan");
+ return SkString("UGreaterThan");
case SpvOpSGreaterThan:
- return String("SGreaterThan");
+ return SkString("SGreaterThan");
case SpvOpUGreaterThanEqual:
- return String("UGreaterThanEqual");
+ return SkString("UGreaterThanEqual");
case SpvOpSGreaterThanEqual:
- return String("SGreaterThanEqual");
+ return SkString("SGreaterThanEqual");
case SpvOpULessThan:
- return String("ULessThan");
+ return SkString("ULessThan");
case SpvOpSLessThan:
- return String("SLessThan");
+ return SkString("SLessThan");
case SpvOpULessThanEqual:
- return String("ULessThanEqual");
+ return SkString("ULessThanEqual");
case SpvOpSLessThanEqual:
- return String("SLessThanEqual");
+ return SkString("SLessThanEqual");
case SpvOpFOrdEqual:
- return String("FOrdEqual");
+ return SkString("FOrdEqual");
case SpvOpFUnordEqual:
- return String("FUnordEqual");
+ return SkString("FUnordEqual");
case SpvOpFOrdNotEqual:
- return String("FOrdNotEqual");
+ return SkString("FOrdNotEqual");
case SpvOpFUnordNotEqual:
- return String("FUnordNotEqual");
+ return SkString("FUnordNotEqual");
case SpvOpFOrdLessThan:
- return String("FOrdLessThan");
+ return SkString("FOrdLessThan");
case SpvOpFUnordLessThan:
- return String("FUnordLessThan");
+ return SkString("FUnordLessThan");
case SpvOpFOrdGreaterThan:
- return String("FOrdGreaterThan");
+ return SkString("FOrdGreaterThan");
case SpvOpFUnordGreaterThan:
- return String("FUnordGreaterThan");
+ return SkString("FUnordGreaterThan");
case SpvOpFOrdLessThanEqual:
- return String("FOrdLessThanEqual");
+ return SkString("FOrdLessThanEqual");
case SpvOpFUnordLessThanEqual:
- return String("FUnordLessThanEqual");
+ return SkString("FUnordLessThanEqual");
case SpvOpFOrdGreaterThanEqual:
- return String("FOrdGreaterThanEqual");
+ return SkString("FOrdGreaterThanEqual");
case SpvOpFUnordGreaterThanEqual:
- return String("FUnordGreaterThanEqual");
+ return SkString("FUnordGreaterThanEqual");
case SpvOpShiftRightLogical:
- return String("ShiftRightLogical");
+ return SkString("ShiftRightLogical");
case SpvOpShiftRightArithmetic:
- return String("ShiftRightArithmetic");
+ return SkString("ShiftRightArithmetic");
case SpvOpShiftLeftLogical:
- return String("ShiftLeftLogical");
+ return SkString("ShiftLeftLogical");
case SpvOpBitwiseOr:
- return String("BitwiseOr");
+ return SkString("BitwiseOr");
case SpvOpBitwiseXor:
- return String("BitwiseXor");
+ return SkString("BitwiseXor");
case SpvOpBitwiseAnd:
- return String("BitwiseAnd");
+ return SkString("BitwiseAnd");
case SpvOpNot:
- return String("Not");
+ return SkString("Not");
case SpvOpBitFieldInsert:
- return String("BitFieldInsert");
+ return SkString("BitFieldInsert");
case SpvOpBitFieldSExtract:
- return String("BitFieldSExtract");
+ return SkString("BitFieldSExtract");
case SpvOpBitFieldUExtract:
- return String("BitFieldUExtract");
+ return SkString("BitFieldUExtract");
case SpvOpBitReverse:
- return String("BitReverse");
+ return SkString("BitReverse");
case SpvOpBitCount:
- return String("BitCount");
+ return SkString("BitCount");
case SpvOpDPdx:
- return String("DPdx");
+ return SkString("DPdx");
case SpvOpDPdy:
- return String("DPdy");
+ return SkString("DPdy");
case SpvOpFwidth:
- return String("Fwidth");
+ return SkString("Fwidth");
case SpvOpDPdxFine:
- return String("DPdxFine");
+ return SkString("DPdxFine");
case SpvOpDPdyFine:
- return String("DPdyFine");
+ return SkString("DPdyFine");
case SpvOpFwidthFine:
- return String("FwidthFine");
+ return SkString("FwidthFine");
case SpvOpDPdxCoarse:
- return String("DPdxCoarse");
+ return SkString("DPdxCoarse");
case SpvOpDPdyCoarse:
- return String("DPdyCoarse");
+ return SkString("DPdyCoarse");
case SpvOpFwidthCoarse:
- return String("FwidthCoarse");
+ return SkString("FwidthCoarse");
case SpvOpEmitVertex:
- return String("EmitVertex");
+ return SkString("EmitVertex");
case SpvOpEndPrimitive:
- return String("EndPrimitive");
+ return SkString("EndPrimitive");
case SpvOpEmitStreamVertex:
- return String("EmitStreamVertex");
+ return SkString("EmitStreamVertex");
case SpvOpEndStreamPrimitive:
- return String("EndStreamPrimitive");
+ return SkString("EndStreamPrimitive");
case SpvOpControlBarrier:
- return String("ControlBarrier");
+ return SkString("ControlBarrier");
case SpvOpMemoryBarrier:
- return String("MemoryBarrier");
+ return SkString("MemoryBarrier");
case SpvOpAtomicLoad:
- return String("AtomicLoad");
+ return SkString("AtomicLoad");
case SpvOpAtomicStore:
- return String("AtomicStore");
+ return SkString("AtomicStore");
case SpvOpAtomicExchange:
- return String("AtomicExchange");
+ return SkString("AtomicExchange");
case SpvOpAtomicCompareExchange:
- return String("AtomicCompareExchange");
+ return SkString("AtomicCompareExchange");
case SpvOpAtomicCompareExchangeWeak:
- return String("AtomicCompareExchangeWeak");
+ return SkString("AtomicCompareExchangeWeak");
case SpvOpAtomicIIncrement:
- return String("AtomicIIncrement");
+ return SkString("AtomicIIncrement");
case SpvOpAtomicIDecrement:
- return String("AtomicIDecrement");
+ return SkString("AtomicIDecrement");
case SpvOpAtomicIAdd:
- return String("AtomicIAdd");
+ return SkString("AtomicIAdd");
case SpvOpAtomicISub:
- return String("AtomicISub");
+ return SkString("AtomicISub");
case SpvOpAtomicSMin:
- return String("AtomicSMin");
+ return SkString("AtomicSMin");
case SpvOpAtomicUMin:
- return String("AtomicUMin");
+ return SkString("AtomicUMin");
case SpvOpAtomicSMax:
- return String("AtomicSMax");
+ return SkString("AtomicSMax");
case SpvOpAtomicUMax:
- return String("AtomicUMax");
+ return SkString("AtomicUMax");
case SpvOpAtomicAnd:
- return String("AtomicAnd");
+ return SkString("AtomicAnd");
case SpvOpAtomicOr:
- return String("AtomicOr");
+ return SkString("AtomicOr");
case SpvOpAtomicXor:
- return String("AtomicXor");
+ return SkString("AtomicXor");
case SpvOpPhi:
- return String("Phi");
+ return SkString("Phi");
case SpvOpLoopMerge:
- return String("LoopMerge");
+ return SkString("LoopMerge");
case SpvOpSelectionMerge:
- return String("SelectionMerge");
+ return SkString("SelectionMerge");
case SpvOpLabel:
- return String("Label");
+ return SkString("Label");
case SpvOpBranch:
- return String("Branch");
+ return SkString("Branch");
case SpvOpBranchConditional:
- return String("BranchConditional");
+ return SkString("BranchConditional");
case SpvOpSwitch:
- return String("Switch");
+ return SkString("Switch");
case SpvOpKill:
- return String("Kill");
+ return SkString("Kill");
case SpvOpReturn:
- return String("Return");
+ return SkString("Return");
case SpvOpReturnValue:
- return String("ReturnValue");
+ return SkString("ReturnValue");
case SpvOpUnreachable:
- return String("Unreachable");
+ return SkString("Unreachable");
case SpvOpLifetimeStart:
- return String("LifetimeStart");
+ return SkString("LifetimeStart");
case SpvOpLifetimeStop:
- return String("LifetimeStop");
+ return SkString("LifetimeStop");
case SpvOpGroupAsyncCopy:
- return String("GroupAsyncCopy");
+ return SkString("GroupAsyncCopy");
case SpvOpGroupWaitEvents:
- return String("GroupWaitEvents");
+ return SkString("GroupWaitEvents");
case SpvOpGroupAll:
- return String("GroupAll");
+ return SkString("GroupAll");
case SpvOpGroupAny:
- return String("GroupAny");
+ return SkString("GroupAny");
case SpvOpGroupBroadcast:
- return String("GroupBroadcast");
+ return SkString("GroupBroadcast");
case SpvOpGroupIAdd:
- return String("GroupIAdd");
+ return SkString("GroupIAdd");
case SpvOpGroupFAdd:
- return String("GroupFAdd");
+ return SkString("GroupFAdd");
case SpvOpGroupFMin:
- return String("GroupFMin");
+ return SkString("GroupFMin");
case SpvOpGroupUMin:
- return String("GroupUMin");
+ return SkString("GroupUMin");
case SpvOpGroupSMin:
- return String("GroupSMin");
+ return SkString("GroupSMin");
case SpvOpGroupFMax:
- return String("GroupFMax");
+ return SkString("GroupFMax");
case SpvOpGroupUMax:
- return String("GroupUMax");
+ return SkString("GroupUMax");
case SpvOpGroupSMax:
- return String("GroupSMax");
+ return SkString("GroupSMax");
case SpvOpReadPipe:
- return String("ReadPipe");
+ return SkString("ReadPipe");
case SpvOpWritePipe:
- return String("WritePipe");
+ return SkString("WritePipe");
case SpvOpReservedReadPipe:
- return String("ReservedReadPipe");
+ return SkString("ReservedReadPipe");
case SpvOpReservedWritePipe:
- return String("ReservedWritePipe");
+ return SkString("ReservedWritePipe");
case SpvOpReserveReadPipePackets:
- return String("ReserveReadPipePackets");
+ return SkString("ReserveReadPipePackets");
case SpvOpReserveWritePipePackets:
- return String("ReserveWritePipePackets");
+ return SkString("ReserveWritePipePackets");
case SpvOpCommitReadPipe:
- return String("CommitReadPipe");
+ return SkString("CommitReadPipe");
case SpvOpCommitWritePipe:
- return String("CommitWritePipe");
+ return SkString("CommitWritePipe");
case SpvOpIsValidReserveId:
- return String("IsValidReserveId");
+ return SkString("IsValidReserveId");
case SpvOpGetNumPipePackets:
- return String("GetNumPipePackets");
+ return SkString("GetNumPipePackets");
case SpvOpGetMaxPipePackets:
- return String("GetMaxPipePackets");
+ return SkString("GetMaxPipePackets");
case SpvOpGroupReserveReadPipePackets:
- return String("GroupReserveReadPipePackets");
+ return SkString("GroupReserveReadPipePackets");
case SpvOpGroupReserveWritePipePackets:
- return String("GroupReserveWritePipePackets");
+ return SkString("GroupReserveWritePipePackets");
case SpvOpGroupCommitReadPipe:
- return String("GroupCommitReadPipe");
+ return SkString("GroupCommitReadPipe");
case SpvOpGroupCommitWritePipe:
- return String("GroupCommitWritePipe");
+ return SkString("GroupCommitWritePipe");
case SpvOpEnqueueMarker:
- return String("EnqueueMarker");
+ return SkString("EnqueueMarker");
case SpvOpEnqueueKernel:
- return String("EnqueueKernel");
+ return SkString("EnqueueKernel");
case SpvOpGetKernelNDrangeSubGroupCount:
- return String("GetKernelNDrangeSubGroupCount");
+ return SkString("GetKernelNDrangeSubGroupCount");
case SpvOpGetKernelNDrangeMaxSubGroupSize:
- return String("GetKernelNDrangeMaxSubGroupSize");
+ return SkString("GetKernelNDrangeMaxSubGroupSize");
case SpvOpGetKernelWorkGroupSize:
- return String("GetKernelWorkGroupSize");
+ return SkString("GetKernelWorkGroupSize");
case SpvOpGetKernelPreferredWorkGroupSizeMultiple:
- return String("GetKernelPreferredWorkGroupSizeMultiple");
+ return SkString("GetKernelPreferredWorkGroupSizeMultiple");
case SpvOpRetainEvent:
- return String("RetainEvent");
+ return SkString("RetainEvent");
case SpvOpReleaseEvent:
- return String("ReleaseEvent");
+ return SkString("ReleaseEvent");
case SpvOpCreateUserEvent:
- return String("CreateUserEvent");
+ return SkString("CreateUserEvent");
case SpvOpIsValidEvent:
- return String("IsValidEvent");
+ return SkString("IsValidEvent");
case SpvOpSetUserEventStatus:
- return String("SetUserEventStatus");
+ return SkString("SetUserEventStatus");
case SpvOpCaptureEventProfilingInfo:
- return String("CaptureEventProfilingInfo");
+ return SkString("CaptureEventProfilingInfo");
case SpvOpGetDefaultQueue:
- return String("GetDefaultQueue");
+ return SkString("GetDefaultQueue");
case SpvOpBuildNDRange:
- return String("BuildNDRange");
+ return SkString("BuildNDRange");
case SpvOpImageSparseSampleImplicitLod:
- return String("ImageSparseSampleImplicitLod");
+ return SkString("ImageSparseSampleImplicitLod");
case SpvOpImageSparseSampleExplicitLod:
- return String("ImageSparseSampleExplicitLod");
+ return SkString("ImageSparseSampleExplicitLod");
case SpvOpImageSparseSampleDrefImplicitLod:
- return String("ImageSparseSampleDrefImplicitLod");
+ return SkString("ImageSparseSampleDrefImplicitLod");
case SpvOpImageSparseSampleDrefExplicitLod:
- return String("ImageSparseSampleDrefExplicitLod");
+ return SkString("ImageSparseSampleDrefExplicitLod");
case SpvOpImageSparseSampleProjImplicitLod:
- return String("ImageSparseSampleProjImplicitLod");
+ return SkString("ImageSparseSampleProjImplicitLod");
case SpvOpImageSparseSampleProjExplicitLod:
- return String("ImageSparseSampleProjExplicitLod");
+ return SkString("ImageSparseSampleProjExplicitLod");
case SpvOpImageSparseSampleProjDrefImplicitLod:
- return String("ImageSparseSampleProjDrefImplicitLod");
+ return SkString("ImageSparseSampleProjDrefImplicitLod");
case SpvOpImageSparseSampleProjDrefExplicitLod:
- return String("ImageSparseSampleProjDrefExplicitLod");
+ return SkString("ImageSparseSampleProjDrefExplicitLod");
case SpvOpImageSparseFetch:
- return String("ImageSparseFetch");
+ return SkString("ImageSparseFetch");
case SpvOpImageSparseGather:
- return String("ImageSparseGather");
+ return SkString("ImageSparseGather");
case SpvOpImageSparseDrefGather:
- return String("ImageSparseDrefGather");
+ return SkString("ImageSparseDrefGather");
case SpvOpImageSparseTexelsResident:
- return String("ImageSparseTexelsResident");
+ return SkString("ImageSparseTexelsResident");
case SpvOpNoLine:
- return String("NoLine");
+ return SkString("NoLine");
case SpvOpAtomicFlagTestAndSet:
- return String("AtomicFlagTestAndSet");
+ return SkString("AtomicFlagTestAndSet");
case SpvOpAtomicFlagClear:
- return String("AtomicFlagClear");
+ return SkString("AtomicFlagClear");
case SpvOpImageSparseRead:
- return String("ImageSparseRead");
+ return SkString("ImageSparseRead");
default:
- ABORT("unsupported SPIR-V op");
+ ABORT("unsupported SPIR-V op");
}
}
#endif
-void SPIRVCodeGenerator::writeOpCode(SpvOp_ opCode, int length, OutputStream& out) {
+void SPIRVCodeGenerator::writeOpCode(SpvOp_ opCode, int length, SkWStream& out) {
ASSERT(opCode != SpvOpUndef);
switch (opCode) {
case SpvOpReturn: // fall through
#endif
}
-void SPIRVCodeGenerator::writeLabel(SpvId label, OutputStream& out) {
+void SPIRVCodeGenerator::writeLabel(SpvId label, SkWStream& out) {
fCurrentBlock = label;
this->writeInstruction(SpvOpLabel, label, out);
}
-void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, OutputStream& out) {
+void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, SkWStream& out) {
this->writeOpCode(opCode, 1, out);
}
-void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, OutputStream& out) {
+void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, SkWStream& out) {
this->writeOpCode(opCode, 2, out);
this->writeWord(word1, out);
}
-void SPIRVCodeGenerator::writeString(const char* string, OutputStream& out) {
+void SPIRVCodeGenerator::writeString(const char* string, SkWStream& out) {
size_t length = strlen(string);
- out.write(string, length);
+ out.writeText(string);
switch (length % 4) {
case 1:
out.write8(0);
}
}
-void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, const char* string, OutputStream& out) {
+void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, const char* string, SkWStream& out) {
int32_t length = (int32_t) strlen(string);
this->writeOpCode(opCode, 1 + (length + 4) / 4, out);
this->writeString(string, out);
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, const char* string,
- OutputStream& out) {
+ SkWStream& out) {
int32_t length = (int32_t) strlen(string);
this->writeOpCode(opCode, 2 + (length + 4) / 4, out);
this->writeWord(word1, out);
}
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
- const char* string, OutputStream& out) {
+ const char* string, SkWStream& out) {
int32_t length = (int32_t) strlen(string);
this->writeOpCode(opCode, 3 + (length + 4) / 4, out);
this->writeWord(word1, out);
}
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
- OutputStream& out) {
+ SkWStream& out) {
this->writeOpCode(opCode, 3, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
}
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
- int32_t word3, OutputStream& out) {
+ int32_t word3, SkWStream& out) {
this->writeOpCode(opCode, 4, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
}
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
- int32_t word3, int32_t word4, OutputStream& out) {
+ int32_t word3, int32_t word4, SkWStream& out) {
this->writeOpCode(opCode, 5, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
int32_t word3, int32_t word4, int32_t word5,
- OutputStream& out) {
+ SkWStream& out) {
this->writeOpCode(opCode, 6, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
int32_t word3, int32_t word4, int32_t word5,
- int32_t word6, OutputStream& out) {
+ int32_t word6, SkWStream& out) {
this->writeOpCode(opCode, 7, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
int32_t word3, int32_t word4, int32_t word5,
- int32_t word6, int32_t word7, OutputStream& out) {
+ int32_t word6, int32_t word7, SkWStream& out) {
this->writeOpCode(opCode, 8, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
int32_t word3, int32_t word4, int32_t word5,
int32_t word6, int32_t word7, int32_t word8,
- OutputStream& out) {
+ SkWStream& out) {
this->writeOpCode(opCode, 9, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
this->writeWord(word8, out);
}
-void SPIRVCodeGenerator::writeCapabilities(OutputStream& out) {
+void SPIRVCodeGenerator::writeCapabilities(SkWStream& out) {
for (uint64_t i = 0, bit = 1; i <= kLast_Capability; i++, bit <<= 1) {
if (fCapabilities & bit) {
this->writeInstruction(SpvOpCapability, (SpvId) i, out);
}
SpvId SPIRVCodeGenerator::getType(const Type& type, const MemoryLayout& layout) {
- String key = type.name() + to_string((int) layout.fStd);
+ SkString key = type.name() + to_string((int) layout.fStd);
auto entry = fTypeMap.find(key);
if (entry == fTypeMap.end()) {
SpvId result = this->nextId();
this->getType(type.componentType(), layout),
this->writeIntLiteral(count), fConstantBuffer);
this->writeInstruction(SpvOpDecorate, result, SpvDecorationArrayStride,
- (int32_t) layout.stride(type),
+ (int32_t) layout.stride(type),
fDecorationBuffer);
} else {
ABORT("runtime-sized arrays are not yet supported");
}
SpvId SPIRVCodeGenerator::getFunctionType(const FunctionDeclaration& function) {
- String key = function.fReturnType.description() + "(";
- String separator;
+ SkString key = function.fReturnType.description() + "(";
+ SkString separator;
for (size_t i = 0; i < function.fParameters.size(); i++) {
key += separator;
separator = ", ";
SpvId SPIRVCodeGenerator::getPointerType(const Type& type, const MemoryLayout& layout,
SpvStorageClass_ storageClass) {
- String key = type.description() + "*" + to_string(layout.fStd) + to_string(storageClass);
+ SkString key = type.description() + "*" + to_string(layout.fStd) + to_string(storageClass);
auto entry = fTypeMap.find(key);
if (entry == fTypeMap.end()) {
SpvId result = this->nextId();
return entry->second;
}
-SpvId SPIRVCodeGenerator::writeExpression(const Expression& expr, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeExpression(const Expression& expr, SkWStream& out) {
switch (expr.fKind) {
case Expression::kBinary_Kind:
return this->writeBinaryExpression((BinaryExpression&) expr, out);
return -1;
}
-SpvId SPIRVCodeGenerator::writeIntrinsicCall(const FunctionCall& c, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeIntrinsicCall(const FunctionCall& c, SkWStream& out) {
auto intrinsic = fIntrinsicMap.find(c.fFunction.fName);
ASSERT(intrinsic != fIntrinsicMap.end());
const Type& type = c.fArguments[0]->fType;
}
SpvId SPIRVCodeGenerator::writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind,
- OutputStream& out) {
+ SkWStream& out) {
SpvId result = this->nextId();
switch (kind) {
case kAtan_SpecialIntrinsic: {
coords,
out);
} else {
- ASSERT(2 == c.fArguments.size());
+ SkASSERT(2 == c.fArguments.size());
SpvId sample = this->writeExpression(*c.fArguments[1], out);
this->writeInstruction(SpvOpImageRead,
this->getType(c.fType),
return result;
}
-SpvId SPIRVCodeGenerator::writeFunctionCall(const FunctionCall& c, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeFunctionCall(const FunctionCall& c, SkWStream& out) {
const auto& entry = fFunctionMap.find(&c.fFunction);
if (entry == fFunctionMap.end()) {
return this->writeIntrinsicCall(c, out);
return result;
}
-SpvId SPIRVCodeGenerator::writeFloatConstructor(const Constructor& c, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeFloatConstructor(const Constructor& c, SkWStream& out) {
ASSERT(c.fType == *fContext.fFloat_Type);
ASSERT(c.fArguments.size() == 1);
ASSERT(c.fArguments[0]->fType.isNumber());
return result;
}
-SpvId SPIRVCodeGenerator::writeIntConstructor(const Constructor& c, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeIntConstructor(const Constructor& c, SkWStream& out) {
ASSERT(c.fType == *fContext.fInt_Type);
ASSERT(c.fArguments.size() == 1);
ASSERT(c.fArguments[0]->fType.isNumber());
}
void SPIRVCodeGenerator::writeUniformScaleMatrix(SpvId id, SpvId diagonal, const Type& type,
- OutputStream& out) {
+ SkWStream& out) {
FloatLiteral zero(fContext, Position(), 0);
SpvId zeroId = this->writeFloatLiteral(zero);
std::vector<SpvId> columnIds;
}
void SPIRVCodeGenerator::writeMatrixCopy(SpvId id, SpvId src, const Type& srcType,
- const Type& dstType, OutputStream& out) {
+ const Type& dstType, SkWStream& out) {
ABORT("unimplemented");
}
-SpvId SPIRVCodeGenerator::writeMatrixConstructor(const Constructor& c, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeMatrixConstructor(const Constructor& c, SkWStream& out) {
ASSERT(c.fType.kind() == Type::kMatrix_Kind);
// go ahead and write the arguments so we don't try to write new instructions in the middle of
// an instruction
return result;
}
-SpvId SPIRVCodeGenerator::writeVectorConstructor(const Constructor& c, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeVectorConstructor(const Constructor& c, SkWStream& out) {
ASSERT(c.fType.kind() == Type::kVector_Kind);
if (c.isConstant()) {
return this->writeConstantVector(c);
return result;
}
-SpvId SPIRVCodeGenerator::writeConstructor(const Constructor& c, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeConstructor(const Constructor& c, SkWStream& out) {
if (c.fType == *fContext.fFloat_Type) {
return this->writeFloatConstructor(c, out);
} else if (c.fType == *fContext.fInt_Type) {
}
}
-std::vector<SpvId> SPIRVCodeGenerator::getAccessChain(const Expression& expr, OutputStream& out) {
+std::vector<SpvId> SPIRVCodeGenerator::getAccessChain(const Expression& expr, SkWStream& out) {
std::vector<SpvId> chain;
switch (expr.fKind) {
case Expression::kIndex_Kind: {
return fPointer;
}
- virtual SpvId load(OutputStream& out) override {
+ virtual SpvId load(SkWStream& out) override {
SpvId result = fGen.nextId();
fGen.writeInstruction(SpvOpLoad, fType, result, fPointer, out);
return result;
}
- virtual void store(SpvId value, OutputStream& out) override {
+ virtual void store(SpvId value, SkWStream& out) override {
fGen.writeInstruction(SpvOpStore, fPointer, value, out);
}
return 0;
}
- virtual SpvId load(OutputStream& out) override {
+ virtual SpvId load(SkWStream& out) override {
SpvId base = fGen.nextId();
fGen.writeInstruction(SpvOpLoad, fGen.getType(fBaseType), base, fVecPointer, out);
SpvId result = fGen.nextId();
return result;
}
- virtual void store(SpvId value, OutputStream& out) override {
+ virtual void store(SpvId value, SkWStream& out) override {
// use OpVectorShuffle to mix and match the vector components. We effectively create
// a virtual vector out of the concatenation of the left and right vectors, and then
// select components from this virtual vector to make the result vector. For
};
std::unique_ptr<SPIRVCodeGenerator::LValue> SPIRVCodeGenerator::getLValue(const Expression& expr,
- OutputStream& out) {
+ SkWStream& out) {
switch (expr.fKind) {
case Expression::kVariableReference_Kind: {
const Variable& var = ((VariableReference&) expr).fVariable;
}
}
-SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, SkWStream& out) {
SpvId result = this->nextId();
auto entry = fVariableMap.find(&ref.fVariable);
ASSERT(entry != fVariableMap.end());
std::shared_ptr<SymbolTable> st(new SymbolTable(&fErrors));
ASSERT(fRTHeightFieldIndex == (SpvId) -1);
std::vector<Type::Field> fields;
- fields.emplace_back(Modifiers(), String(SKSL_RTHEIGHT_NAME),
+ fields.emplace_back(Modifiers(), SkString(SKSL_RTHEIGHT_NAME),
fContext.fFloat_Type.get());
- String name("sksl_synthetic_uniforms");
+ SkString name("sksl_synthetic_uniforms");
Type intfStruct(Position(), name, fields);
- Layout layout(-1, -1, 1, -1, -1, -1, -1, false, false, false,
- Layout::Format::kUnspecified, false, Layout::kUnspecified_Primitive, -1,
- -1);
+ Layout layout(-1, -1, 1, -1, -1, -1, -1, false, false, false, Layout::Format::kUnspecified,
+ false, Layout::kUnspecified_Primitive, -1, -1);
Variable* intfVar = new Variable(Position(),
Modifiers(layout, Modifiers::kUniform_Flag),
name,
intfStruct,
Variable::kGlobal_Storage);
fSynthetics.takeOwnership(intfVar);
- InterfaceBlock intf(Position(), intfVar, name, String(""),
+ InterfaceBlock intf(Position(), intfVar, name, SkString(""),
std::vector<std::unique_ptr<Expression>>(), st);
fRTHeightStructId = this->writeInterfaceBlock(intf);
fRTHeightFieldIndex = 0;
return result;
}
-SpvId SPIRVCodeGenerator::writeIndexExpression(const IndexExpression& expr, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeIndexExpression(const IndexExpression& expr, SkWStream& out) {
return getLValue(expr, out)->load(out);
}
-SpvId SPIRVCodeGenerator::writeFieldAccess(const FieldAccess& f, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeFieldAccess(const FieldAccess& f, SkWStream& out) {
return getLValue(f, out)->load(out);
}
-SpvId SPIRVCodeGenerator::writeSwizzle(const Swizzle& swizzle, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeSwizzle(const Swizzle& swizzle, SkWStream& out) {
SpvId base = this->writeExpression(*swizzle.fBase, out);
SpvId result = this->nextId();
size_t count = swizzle.fComponents.size();
SpvId SPIRVCodeGenerator::writeBinaryOperation(const Type& resultType,
const Type& operandType, SpvId lhs,
SpvId rhs, SpvOp_ ifFloat, SpvOp_ ifInt,
- SpvOp_ ifUInt, SpvOp_ ifBool, OutputStream& out) {
+ SpvOp_ ifUInt, SpvOp_ ifBool, SkWStream& out) {
SpvId result = this->nextId();
if (is_float(fContext, operandType)) {
this->writeInstruction(ifFloat, this->getType(resultType), result, lhs, rhs, out);
}
}
-SpvId SPIRVCodeGenerator::foldToBool(SpvId id, const Type& operandType, OutputStream& out) {
+SpvId SPIRVCodeGenerator::foldToBool(SpvId id, const Type& operandType, SkWStream& out) {
if (operandType.kind() == Type::kVector_Kind) {
SpvId result = this->nextId();
this->writeInstruction(SpvOpAll, this->getType(*fContext.fBool_Type), result, id, out);
return id;
}
-SpvId SPIRVCodeGenerator::writeBinaryExpression(const BinaryExpression& b, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeBinaryExpression(const BinaryExpression& b, SkWStream& out) {
// handle cases where we don't necessarily evaluate both LHS and RHS
switch (b.fOperator) {
case Token::EQ: {
}
}
-SpvId SPIRVCodeGenerator::writeLogicalAnd(const BinaryExpression& a, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeLogicalAnd(const BinaryExpression& a, SkWStream& out) {
ASSERT(a.fOperator == Token::LOGICALAND);
BoolLiteral falseLiteral(fContext, Position(), false);
SpvId falseConstant = this->writeBoolLiteral(falseLiteral);
return result;
}
-SpvId SPIRVCodeGenerator::writeLogicalOr(const BinaryExpression& o, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeLogicalOr(const BinaryExpression& o, SkWStream& out) {
ASSERT(o.fOperator == Token::LOGICALOR);
BoolLiteral trueLiteral(fContext, Position(), true);
SpvId trueConstant = this->writeBoolLiteral(trueLiteral);
return result;
}
-SpvId SPIRVCodeGenerator::writeTernaryExpression(const TernaryExpression& t, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeTernaryExpression(const TernaryExpression& t, SkWStream& out) {
SpvId test = this->writeExpression(*t.fTest, out);
if (t.fIfTrue->isConstant() && t.fIfFalse->isConstant()) {
// both true and false are constants, can just use OpSelect
else if (type == *context.fFloat_Type) {
return std::unique_ptr<Expression>(new FloatLiteral(context, Position(), 1.0));
} else {
- ABORT("math is unsupported on type '%s'", type.name().c_str());
+ ABORT("math is unsupported on type '%s'")
}
}
-SpvId SPIRVCodeGenerator::writePrefixExpression(const PrefixExpression& p, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writePrefixExpression(const PrefixExpression& p, SkWStream& out) {
if (p.fOperator == Token::MINUS) {
SpvId result = this->nextId();
SpvId typeId = this->getType(p.fType);
}
}
-SpvId SPIRVCodeGenerator::writePostfixExpression(const PostfixExpression& p, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writePostfixExpression(const PostfixExpression& p, SkWStream& out) {
std::unique_ptr<LValue> lv = this->getLValue(*p.fOperand, out);
SpvId result = lv->load(out);
SpvId one = this->writeExpression(*create_literal_1(fContext, p.fType), out);
}
}
-SpvId SPIRVCodeGenerator::writeFunctionStart(const FunctionDeclaration& f, OutputStream& out) {
+SpvId SPIRVCodeGenerator::writeFunctionStart(const FunctionDeclaration& f, SkWStream& out) {
SpvId result = fFunctionMap[&f];
this->writeInstruction(SpvOpFunction, this->getType(f.fReturnType), result,
SpvFunctionControlMaskNone, this->getFunctionType(f), out);
return result;
}
-SpvId SPIRVCodeGenerator::writeFunction(const FunctionDefinition& f, OutputStream& out) {
- fVariableBuffer.reset();
+SpvId SPIRVCodeGenerator::writeFunction(const FunctionDefinition& f, SkWStream& out) {
SpvId result = this->writeFunctionStart(f.fDeclaration, out);
this->writeLabel(this->nextId(), out);
if (f.fDeclaration.fName == "main") {
- write_stringstream(fGlobalInitializersBuffer, out);
+ write_data(*fGlobalInitializersBuffer.detachAsData(), out);
}
- StringStream bodyBuffer;
+ SkDynamicMemoryWStream bodyBuffer;
this->writeBlock(*f.fBody, bodyBuffer);
- write_stringstream(fVariableBuffer, out);
- write_stringstream(bodyBuffer, out);
+ write_data(*fVariableBuffer.detachAsData(), out);
+ write_data(*bodyBuffer.detachAsData(), out);
if (fCurrentBlock) {
this->writeInstruction(SpvOpReturn, out);
}
std::vector<Type::Field> fields = type->fields();
fRTHeightStructId = result;
fRTHeightFieldIndex = fields.size();
- fields.emplace_back(Modifiers(), String(SKSL_RTHEIGHT_NAME), fContext.fFloat_Type.get());
+ fields.emplace_back(Modifiers(), SkString(SKSL_RTHEIGHT_NAME), fContext.fFloat_Type.get());
type = new Type(type->fPosition, type->name(), fields);
}
SpvId typeId = this->getType(*type, layout);
#define BUILTIN_IGNORE 9999
void SPIRVCodeGenerator::writeGlobalVars(Program::Kind kind, const VarDeclarations& decl,
- OutputStream& out) {
+ SkWStream& out) {
for (size_t i = 0; i < decl.fVars.size(); i++) {
const VarDeclaration& varDecl = decl.fVars[i];
const Variable* var = varDecl.fVar;
}
}
-void SPIRVCodeGenerator::writeVarDeclarations(const VarDeclarations& decl, OutputStream& out) {
+void SPIRVCodeGenerator::writeVarDeclarations(const VarDeclarations& decl, SkWStream& out) {
for (const auto& varDecl : decl.fVars) {
const Variable* var = varDecl.fVar;
// These haven't been implemented in our SPIR-V generator yet and we only currently use them
}
}
-void SPIRVCodeGenerator::writeStatement(const Statement& s, OutputStream& out) {
+void SPIRVCodeGenerator::writeStatement(const Statement& s, SkWStream& out) {
switch (s.fKind) {
case Statement::kBlock_Kind:
this->writeBlock((Block&) s, out);
}
}
-void SPIRVCodeGenerator::writeBlock(const Block& b, OutputStream& out) {
+void SPIRVCodeGenerator::writeBlock(const Block& b, SkWStream& out) {
for (size_t i = 0; i < b.fStatements.size(); i++) {
this->writeStatement(*b.fStatements[i], out);
}
}
-void SPIRVCodeGenerator::writeIfStatement(const IfStatement& stmt, OutputStream& out) {
+void SPIRVCodeGenerator::writeIfStatement(const IfStatement& stmt, SkWStream& out) {
SpvId test = this->writeExpression(*stmt.fTest, out);
SpvId ifTrue = this->nextId();
SpvId ifFalse = this->nextId();
}
}
-void SPIRVCodeGenerator::writeForStatement(const ForStatement& f, OutputStream& out) {
+void SPIRVCodeGenerator::writeForStatement(const ForStatement& f, SkWStream& out) {
if (f.fInitializer) {
this->writeStatement(*f.fInitializer, out);
}
fContinueTarget.pop();
}
-void SPIRVCodeGenerator::writeWhileStatement(const WhileStatement& w, OutputStream& out) {
+void SPIRVCodeGenerator::writeWhileStatement(const WhileStatement& w, SkWStream& out) {
// We believe the while loop code below will work, but Skia doesn't actually use them and
// adequately testing this code in the absence of Skia exercising it isn't straightforward. For
// the time being, we just fail with an error due to the lack of testing. If you encounter this
fContinueTarget.pop();
}
-void SPIRVCodeGenerator::writeDoStatement(const DoStatement& d, OutputStream& out) {
+void SPIRVCodeGenerator::writeDoStatement(const DoStatement& d, SkWStream& out) {
// We believe the do loop code below will work, but Skia doesn't actually use them and
// adequately testing this code in the absence of Skia exercising it isn't straightforward. For
// the time being, we just fail with an error due to the lack of testing. If you encounter this
fContinueTarget.pop();
}
-void SPIRVCodeGenerator::writeReturnStatement(const ReturnStatement& r, OutputStream& out) {
+void SPIRVCodeGenerator::writeReturnStatement(const ReturnStatement& r, SkWStream& out) {
if (r.fExpression) {
this->writeInstruction(SpvOpReturnValue, this->writeExpression(*r.fExpression, out),
out);
}
}
-void SPIRVCodeGenerator::writeInstructions(const Program& program, OutputStream& out) {
+void SPIRVCodeGenerator::writeInstructions(const Program& program, SkWStream& out) {
fGLSLExtendedInstructions = this->nextId();
- StringStream body;
+ SkDynamicMemoryWStream body;
std::set<SpvId> interfaceVars;
// assign IDs to functions
for (size_t i = 0; i < program.fElements.size(); i++) {
}
}
- write_stringstream(fExtraGlobalsBuffer, out);
- write_stringstream(fNameBuffer, out);
- write_stringstream(fDecorationBuffer, out);
- write_stringstream(fConstantBuffer, out);
- write_stringstream(fExternalFunctionsBuffer, out);
- write_stringstream(body, out);
+ write_data(*fExtraGlobalsBuffer.detachAsData(), out);
+ write_data(*fNameBuffer.detachAsData(), out);
+ write_data(*fDecorationBuffer.detachAsData(), out);
+ write_data(*fConstantBuffer.detachAsData(), out);
+ write_data(*fExternalFunctionsBuffer.detachAsData(), out);
+ write_data(*body.detachAsData(), out);
}
bool SPIRVCodeGenerator::generateCode() {
this->writeWord(SpvMagicNumber, *fOut);
this->writeWord(SpvVersion, *fOut);
this->writeWord(SKSL_MAGIC, *fOut);
- StringStream buffer;
+ SkDynamicMemoryWStream buffer;
this->writeInstructions(fProgram, buffer);
this->writeWord(fIdCount, *fOut);
this->writeWord(0, *fOut); // reserved, always zero
- write_stringstream(buffer, *fOut);
+ write_data(*buffer.detachAsData(), *fOut);
return 0 == fErrors.errorCount();
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_SPIRVCODEGENERATOR
#define SKSL_SPIRVCODEGENERATOR
#include <tuple>
#include <unordered_map>
+#include "SkStream.h"
#include "SkSLCodeGenerator.h"
#include "SkSLMemoryLayout.h"
#include "ir/SkSLBinaryExpression.h"
// by a pointer (e.g. vector swizzles), returns 0.
virtual SpvId getPointer() = 0;
- virtual SpvId load(OutputStream& out) = 0;
+ virtual SpvId load(SkWStream& out) = 0;
- virtual void store(SpvId value, OutputStream& out) = 0;
+ virtual void store(SpvId value, SkWStream& out) = 0;
};
SPIRVCodeGenerator(const Context* context, const Program* program, ErrorReporter* errors,
- OutputStream* out)
+ SkWStream* out)
: INHERITED(program, errors, out)
, fContext(*context)
, fDefaultLayout(MemoryLayout::k140_Standard)
SpvId getPointerType(const Type& type, const MemoryLayout& layout,
SpvStorageClass_ storageClass);
- std::vector<SpvId> getAccessChain(const Expression& expr, OutputStream& out);
+ std::vector<SpvId> getAccessChain(const Expression& expr, SkWStream& out);
void writeLayout(const Layout& layout, SpvId target);
void writeStruct(const Type& type, const MemoryLayout& layout, SpvId resultId);
- void writeProgramElement(const ProgramElement& pe, OutputStream& out);
+ void writeProgramElement(const ProgramElement& pe, SkWStream& out);
SpvId writeInterfaceBlock(const InterfaceBlock& intf);
- SpvId writeFunctionStart(const FunctionDeclaration& f, OutputStream& out);
-
- SpvId writeFunctionDeclaration(const FunctionDeclaration& f, OutputStream& out);
-
- SpvId writeFunction(const FunctionDefinition& f, OutputStream& out);
+ SpvId writeFunctionStart(const FunctionDeclaration& f, SkWStream& out);
+
+ SpvId writeFunctionDeclaration(const FunctionDeclaration& f, SkWStream& out);
- void writeGlobalVars(Program::Kind kind, const VarDeclarations& v, OutputStream& out);
+ SpvId writeFunction(const FunctionDefinition& f, SkWStream& out);
- void writeVarDeclarations(const VarDeclarations& decl, OutputStream& out);
+ void writeGlobalVars(Program::Kind kind, const VarDeclarations& v, SkWStream& out);
- SpvId writeVariableReference(const VariableReference& ref, OutputStream& out);
+ void writeVarDeclarations(const VarDeclarations& decl, SkWStream& out);
- std::unique_ptr<LValue> getLValue(const Expression& value, OutputStream& out);
+ SpvId writeVariableReference(const VariableReference& ref, SkWStream& out);
- SpvId writeExpression(const Expression& expr, OutputStream& out);
+ std::unique_ptr<LValue> getLValue(const Expression& value, SkWStream& out);
- SpvId writeIntrinsicCall(const FunctionCall& c, OutputStream& out);
+ SpvId writeExpression(const Expression& expr, SkWStream& out);
+
+ SpvId writeIntrinsicCall(const FunctionCall& c, SkWStream& out);
- SpvId writeFunctionCall(const FunctionCall& c, OutputStream& out);
+ SpvId writeFunctionCall(const FunctionCall& c, SkWStream& out);
- SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, OutputStream& out);
+ SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, SkWStream& out);
SpvId writeConstantVector(const Constructor& c);
- SpvId writeFloatConstructor(const Constructor& c, OutputStream& out);
+ SpvId writeFloatConstructor(const Constructor& c, SkWStream& out);
- SpvId writeIntConstructor(const Constructor& c, OutputStream& out);
+ SpvId writeIntConstructor(const Constructor& c, SkWStream& out);
/**
* Writes a matrix with the diagonal entries all equal to the provided expression, and all other
* entries equal to zero.
*/
- void writeUniformScaleMatrix(SpvId id, SpvId diagonal, const Type& type, OutputStream& out);
+ void writeUniformScaleMatrix(SpvId id, SpvId diagonal, const Type& type, SkWStream& out);
/**
* Writes a potentially-different-sized copy of a matrix. Entries which do not exist in the
* ignored.
*/
void writeMatrixCopy(SpvId id, SpvId src, const Type& srcType, const Type& dstType,
- OutputStream& out);
+ SkWStream& out);
- SpvId writeMatrixConstructor(const Constructor& c, OutputStream& out);
+ SpvId writeMatrixConstructor(const Constructor& c, SkWStream& out);
- SpvId writeVectorConstructor(const Constructor& c, OutputStream& out);
+ SpvId writeVectorConstructor(const Constructor& c, SkWStream& out);
- SpvId writeConstructor(const Constructor& c, OutputStream& out);
+ SpvId writeConstructor(const Constructor& c, SkWStream& out);
- SpvId writeFieldAccess(const FieldAccess& f, OutputStream& out);
+ SpvId writeFieldAccess(const FieldAccess& f, SkWStream& out);
- SpvId writeSwizzle(const Swizzle& swizzle, OutputStream& out);
+ SpvId writeSwizzle(const Swizzle& swizzle, SkWStream& out);
/**
* Folds the potentially-vector result of a logical operation down to a single bool. If
* same dimensions, and applys all() to it to fold it down to a single bool value. Otherwise,
* returns the original id value.
*/
- SpvId foldToBool(SpvId id, const Type& operandType, OutputStream& out);
+ SpvId foldToBool(SpvId id, const Type& operandType, SkWStream& out);
SpvId writeBinaryOperation(const Type& resultType, const Type& operandType, SpvId lhs,
SpvId rhs, SpvOp_ ifFloat, SpvOp_ ifInt, SpvOp_ ifUInt,
- SpvOp_ ifBool, OutputStream& out);
+ SpvOp_ ifBool, SkWStream& out);
SpvId writeBinaryOperation(const BinaryExpression& expr, SpvOp_ ifFloat, SpvOp_ ifInt,
- SpvOp_ ifUInt, OutputStream& out);
+ SpvOp_ ifUInt, SkWStream& out);
- SpvId writeBinaryExpression(const BinaryExpression& b, OutputStream& out);
+ SpvId writeBinaryExpression(const BinaryExpression& b, SkWStream& out);
- SpvId writeTernaryExpression(const TernaryExpression& t, OutputStream& out);
+ SpvId writeTernaryExpression(const TernaryExpression& t, SkWStream& out);
- SpvId writeIndexExpression(const IndexExpression& expr, OutputStream& out);
+ SpvId writeIndexExpression(const IndexExpression& expr, SkWStream& out);
- SpvId writeLogicalAnd(const BinaryExpression& b, OutputStream& out);
+ SpvId writeLogicalAnd(const BinaryExpression& b, SkWStream& out);
- SpvId writeLogicalOr(const BinaryExpression& o, OutputStream& out);
+ SpvId writeLogicalOr(const BinaryExpression& o, SkWStream& out);
- SpvId writePrefixExpression(const PrefixExpression& p, OutputStream& out);
+ SpvId writePrefixExpression(const PrefixExpression& p, SkWStream& out);
- SpvId writePostfixExpression(const PostfixExpression& p, OutputStream& out);
+ SpvId writePostfixExpression(const PostfixExpression& p, SkWStream& out);
SpvId writeBoolLiteral(const BoolLiteral& b);
SpvId writeFloatLiteral(const FloatLiteral& f);
- void writeStatement(const Statement& s, OutputStream& out);
+ void writeStatement(const Statement& s, SkWStream& out);
- void writeBlock(const Block& b, OutputStream& out);
+ void writeBlock(const Block& b, SkWStream& out);
- void writeIfStatement(const IfStatement& stmt, OutputStream& out);
+ void writeIfStatement(const IfStatement& stmt, SkWStream& out);
- void writeForStatement(const ForStatement& f, OutputStream& out);
+ void writeForStatement(const ForStatement& f, SkWStream& out);
- void writeWhileStatement(const WhileStatement& w, OutputStream& out);
+ void writeWhileStatement(const WhileStatement& w, SkWStream& out);
- void writeDoStatement(const DoStatement& d, OutputStream& out);
+ void writeDoStatement(const DoStatement& d, SkWStream& out);
- void writeReturnStatement(const ReturnStatement& r, OutputStream& out);
+ void writeReturnStatement(const ReturnStatement& r, SkWStream& out);
- void writeCapabilities(OutputStream& out);
+ void writeCapabilities(SkWStream& out);
- void writeInstructions(const Program& program, OutputStream& out);
+ void writeInstructions(const Program& program, SkWStream& out);
- void writeOpCode(SpvOp_ opCode, int length, OutputStream& out);
+ void writeOpCode(SpvOp_ opCode, int length, SkWStream& out);
- void writeWord(int32_t word, OutputStream& out);
+ void writeWord(int32_t word, SkWStream& out);
- void writeString(const char* string, OutputStream& out);
+ void writeString(const char* string, SkWStream& out);
- void writeLabel(SpvId id, OutputStream& out);
+ void writeLabel(SpvId id, SkWStream& out);
- void writeInstruction(SpvOp_ opCode, OutputStream& out);
+ void writeInstruction(SpvOp_ opCode, SkWStream& out);
- void writeInstruction(SpvOp_ opCode, const char* string, OutputStream& out);
+ void writeInstruction(SpvOp_ opCode, const char* string, SkWStream& out);
- void writeInstruction(SpvOp_ opCode, int32_t word1, OutputStream& out);
+ void writeInstruction(SpvOp_ opCode, int32_t word1, SkWStream& out);
- void writeInstruction(SpvOp_ opCode, int32_t word1, const char* string, OutputStream& out);
+ void writeInstruction(SpvOp_ opCode, int32_t word1, const char* string, SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, const char* string,
- OutputStream& out);
+ SkWStream& out);
- void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, OutputStream& out);
+ void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3,
- OutputStream& out);
+ SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4,
- OutputStream& out);
+ SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4,
- int32_t word5, OutputStream& out);
+ int32_t word5, SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4,
- int32_t word5, int32_t word6, OutputStream& out);
+ int32_t word5, int32_t word6, SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4,
- int32_t word5, int32_t word6, int32_t word7, OutputStream& out);
+ int32_t word5, int32_t word6, int32_t word7, SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4,
int32_t word5, int32_t word6, int32_t word7, int32_t word8,
- OutputStream& out);
+ SkWStream& out);
const Context& fContext;
const MemoryLayout fDefaultLayout;
SpvId fIdCount;
SpvId fGLSLExtendedInstructions;
typedef std::tuple<IntrinsicKind, int32_t, int32_t, int32_t, int32_t> Intrinsic;
- std::unordered_map<String, Intrinsic> fIntrinsicMap;
+ std::unordered_map<SkString, Intrinsic> fIntrinsicMap;
std::unordered_map<const FunctionDeclaration*, SpvId> fFunctionMap;
std::unordered_map<const Variable*, SpvId> fVariableMap;
std::unordered_map<const Variable*, int32_t> fInterfaceBlockMap;
- std::unordered_map<String, SpvId> fTypeMap;
- StringStream fCapabilitiesBuffer;
- StringStream fGlobalInitializersBuffer;
- StringStream fConstantBuffer;
- StringStream fExtraGlobalsBuffer;
- StringStream fExternalFunctionsBuffer;
- StringStream fVariableBuffer;
- StringStream fNameBuffer;
- StringStream fDecorationBuffer;
+ std::unordered_map<SkString, SpvId> fTypeMap;
+ SkDynamicMemoryWStream fCapabilitiesBuffer;
+ SkDynamicMemoryWStream fGlobalInitializersBuffer;
+ SkDynamicMemoryWStream fConstantBuffer;
+ SkDynamicMemoryWStream fExtraGlobalsBuffer;
+ SkDynamicMemoryWStream fExternalFunctionsBuffer;
+ SkDynamicMemoryWStream fVariableBuffer;
+ SkDynamicMemoryWStream fNameBuffer;
+ SkDynamicMemoryWStream fDecorationBuffer;
SpvId fBoolTrue;
SpvId fBoolFalse;
+++ /dev/null
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkSLString.h"
-
-#include "SkSLUtil.h"
-#include <cinttypes>
-#include <errno.h>
-#include <limits.h>
-#include <locale>
-#include <sstream>
-#include <string>
-
-namespace SkSL {
-
-String String::printf(const char* fmt, ...) {
- va_list args;
- va_start(args, fmt);
- String result;
- result.vappendf(fmt, args);
- return result;
-}
-
-#ifdef SKSL_STANDALONE
-void String::appendf(const char* fmt, ...) {
- va_list args;
- va_start(args, fmt);
- this->vappendf(fmt, args);
-}
-#endif
-
-void String::vappendf(const char* fmt, va_list args) {
-#ifdef SKSL_BUILD_FOR_WIN
- #define VSNPRINTF _vsnprintf
-#else
- #define VSNPRINTF vsnprintf
-#endif
- #define BUFFER_SIZE 256
- char buffer[BUFFER_SIZE];
- size_t size = VSNPRINTF(buffer, BUFFER_SIZE, fmt, args);
- if (BUFFER_SIZE >= size) {
- this->append(buffer, size);
- } else {
- auto newBuffer = std::unique_ptr<char[]>(new char[size]);
- VSNPRINTF(newBuffer.get(), size, fmt, args);
- this->append(newBuffer.get(), size);
- }
- va_end(args);
-}
-
-
-bool String::startsWith(const char* s) const {
- return strncmp(c_str(), s, strlen(s));
-}
-
-bool String::endsWith(const char* s) const {
- size_t len = strlen(s);
- if (size() < len) {
- return false;
- }
- return strncmp(c_str() + size() - len, s, len);
-}
-
-String String::operator+(const char* s) const {
- String result(*this);
- result.append(s);
- return result;
-}
-
-String String::operator+(const String& s) const {
- String result(*this);
- result.append(s);
- return result;
-}
-
-bool String::operator==(const String& s) const {
- return this->size() == s.size() && !memcmp(c_str(), s.c_str(), this->size());
-}
-
-bool String::operator!=(const String& s) const {
- return !(*this == s);
-}
-
-bool String::operator==(const char* s) const {
- return this->size() == strlen(s) && !memcmp(c_str(), s, this->size());
-}
-
-bool String::operator!=(const char* s) const {
- return !(*this == s);
-}
-
-String operator+(const char* s1, const String& s2) {
- String result(s1);
- result.append(s2);
- return result;
-}
-
-bool operator==(const char* s1, const String& s2) {
- return s2 == s1;
-}
-
-bool operator!=(const char* s1, const String& s2) {
- return s2 != s1;
-}
-
-String to_string(int32_t value) {
- return SkSL::String::printf("%d", value);
-}
-
-String to_string(uint32_t value) {
- return SkSL::String::printf("%u", value);
-}
-
-String to_string(int64_t value) {
- return SkSL::String::printf("%" PRId64, value);
-}
-
-String to_string(uint64_t value) {
- return SkSL::String::printf("%" PRIu64, value);
-}
-
-String to_string(double value) {
-#ifdef SKSL_BUILD_FOR_WIN
- #define SNPRINTF _snprintf
-#else
- #define SNPRINTF snprintf
-#endif
-#define MAX_DOUBLE_CHARS 25
- char buffer[MAX_DOUBLE_CHARS];
- SKSL_DEBUGCODE(int len = )SNPRINTF(buffer, sizeof(buffer), "%.17g", value);
- ASSERT(len < MAX_DOUBLE_CHARS);
- String result(buffer);
- if (!strchr(buffer, '.') && !strchr(buffer, 'e')) {
- result += ".0";
- }
- return result;
-#undef SNPRINTF
-#undef MAX_DOUBLE_CHARS
-}
-
-int stoi(String s) {
- char* p;
- SKSL_DEBUGCODE(errno = 0;)
- long result = strtol(s.c_str(), &p, 0);
- ASSERT(*p == 0);
- ASSERT(!errno && INT_MAX >= result && INT_MIN <= result);
- return (int) result;
-}
-
-double stod(String s) {
- double result;
- std::string str(s.c_str(), s.size());
- std::stringstream buffer(str);
- buffer.imbue(std::locale::classic());
- buffer >> result;
- ASSERT(!buffer.fail());
- return result;
-}
-
-long stol(String s) {
- char* p;
- SKSL_DEBUGCODE(errno = 0;)
- long result = strtol(s.c_str(), &p, 0);
- ASSERT(*p == 0);
- ASSERT(!errno);
- return result;
-}
-
-} // namespace
+++ /dev/null
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SKSL_STRING
-#define SKSL_STRING
-
-
-#ifdef SKSL_STANDALONE
- #define SKSL_STRING_BASE std::string
- #include <string>
-#else
- #define SKSL_STRING_BASE SkString
- #include "SkString.h"
-#endif
-
-namespace SkSL {
-
-class String : public SKSL_STRING_BASE {
-public:
- String() = default;
- String(const String&) = default;
- String(String&&) = default;
- String& operator=(const String&) = default;
- String& operator=(String&&) = default;
-
-#ifndef SKSL_STANDALONE
- String(const SkString& s)
- : INHERITED(s) {}
-#endif
-
- String(const char* s)
- : INHERITED(s) {}
-
- String(const char* s, size_t size)
- : INHERITED(s, size) {}
-
- static String printf(const char* fmt, ...);
-
-#ifdef SKSL_STANDALONE
- void appendf(const char* fmt, ...);
-#endif
- void vappendf(const char* fmt, va_list va);
-
- bool startsWith(const char* s) const;
- bool endsWith(const char* s) const;
-
- String operator+(const char* s) const;
- String operator+(const String& s) const;
- bool operator==(const char* s) const;
- bool operator!=(const char* s) const;
- bool operator==(const String& s) const;
- bool operator!=(const String& s) const;
- friend String operator+(const char* s1, const String& s2);
- friend bool operator==(const char* s1, const String& s2);
- friend bool operator!=(const char* s1, const String& s2);
-
-private:
- typedef SKSL_STRING_BASE INHERITED;
-};
-
-String operator+(const char* s1, const String& s2);
-bool operator!=(const char* s1, const String& s2);
-
-String to_string(double value);
-
-String to_string(int32_t value);
-
-String to_string(uint32_t value);
-
-String to_string(int64_t value);
-
-String to_string(uint64_t value);
-
-int stoi(String s);
-
-double stod(String s);
-
-long stol(String s);
-
-} // namespace
-
-#ifdef SKSL_STANDALONE
-namespace std {
- template<> struct hash<SkSL::String> {
- size_t operator()(const SkSL::String& s) const {
- return hash<std::string>{}(s);
- }
- };
-} // namespace
-#else
-#include "SkOpts.h"
-namespace std {
- template<> struct hash<SkSL::String> {
- size_t operator()(const SkSL::String& s) const {
- return SkOpts::hash_fn(s.c_str(), s.size(), 0);
- }
- };
-} // namespace
-#endif // SKIA_STANDALONE
-
-#endif
+++ /dev/null
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SKSL_STRINGSTREAM
-#define SKSL_STRINGSTREAM
-
-#include "SkSLOutputStream.h"
-
-#ifdef SKSL_STANDALONE
-
-namespace SkSL {
-
-class StringStream : public OutputStream {
-public:
- void write8(uint8_t b) override {
- fBuffer += (char) b;
- }
-
- void writeText(const char* s) override {
- fBuffer += s;
- }
-
- void write(const void* s, size_t size) override {
- fBuffer.append((const char*) s, size);
- }
-
- const char* data() const {
- return fBuffer.c_str();
- }
-
- size_t size() const {
- return fBuffer.size();
- }
-
- void reset() {
- fBuffer = "";
- }
-
-private:
- String fBuffer;
-};
-
-#else
-
-#include "SkData.h"
-#include "SkStream.h"
-
-namespace SkSL {
-
-class StringStream : public OutputStream {
-public:
- void write8(uint8_t b) override {
- SkASSERT(!fData);
- fStream.write8(b);
- }
-
- void writeText(const char* s) override {
- SkASSERT(!fData);
- fStream.writeText(s);
- }
-
- void write(const void* s, size_t size) override {
- SkASSERT(!fData);
- fStream.write(s, size);
- }
-
- const char* data() const {
- if (!fData) {
- fData = fStream.detachAsData();
- }
- return (const char*) fData->data();
- }
-
- size_t size() const {
- if (!fData) {
- fData = fStream.detachAsData();
- }
- return fData->size();
- }
-
- void reset() {
- fStream.reset();
- fData = nullptr;
- }
-
-private:
- mutable SkDynamicMemoryWStream fStream;
- mutable sk_sp<SkData> fData;
-};
-
-#endif // SKSL_STANDALONE
-
-} // namespace
-
-#endif
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_TOKEN
#define SKSL_TOKEN
#include "SkSLPosition.h"
#include "SkSLUtil.h"
-
+
namespace SkSL {
#undef IN
INVALID_TOKEN
};
- static String OperatorName(Kind kind) {
+ static SkString OperatorName(Kind kind) {
switch (kind) {
- case Token::PLUS: return String("+");
- case Token::MINUS: return String("-");
- case Token::STAR: return String("*");
- case Token::SLASH: return String("/");
- case Token::PERCENT: return String("%");
- case Token::SHL: return String("<<");
- case Token::SHR: return String(">>");
- case Token::LOGICALNOT: return String("!");
- case Token::LOGICALAND: return String("&&");
- case Token::LOGICALOR: return String("||");
- case Token::LOGICALXOR: return String("^^");
- case Token::BITWISENOT: return String("~");
- case Token::BITWISEAND: return String("&");
- case Token::BITWISEOR: return String("|");
- case Token::BITWISEXOR: return String("^");
- case Token::EQ: return String("=");
- case Token::EQEQ: return String("==");
- case Token::NEQ: return String("!=");
- case Token::LT: return String("<");
- case Token::GT: return String(">");
- case Token::LTEQ: return String("<=");
- case Token::GTEQ: return String(">=");
- case Token::PLUSEQ: return String("+=");
- case Token::MINUSEQ: return String("-=");
- case Token::STAREQ: return String("*=");
- case Token::SLASHEQ: return String("/=");
- case Token::PERCENTEQ: return String("%=");
- case Token::SHLEQ: return String("<<=");
- case Token::SHREQ: return String(">>=");
- case Token::LOGICALANDEQ: return String("&&=");
- case Token::LOGICALOREQ: return String("||=");
- case Token::LOGICALXOREQ: return String("^^=");
- case Token::BITWISEANDEQ: return String("&=");
- case Token::BITWISEOREQ: return String("|=");
- case Token::BITWISEXOREQ: return String("^=");
- case Token::PLUSPLUS: return String("++");
- case Token::MINUSMINUS: return String("--");
+ case Token::PLUS: return SkString("+");
+ case Token::MINUS: return SkString("-");
+ case Token::STAR: return SkString("*");
+ case Token::SLASH: return SkString("/");
+ case Token::PERCENT: return SkString("%");
+ case Token::SHL: return SkString("<<");
+ case Token::SHR: return SkString(">>");
+ case Token::LOGICALNOT: return SkString("!");
+ case Token::LOGICALAND: return SkString("&&");
+ case Token::LOGICALOR: return SkString("||");
+ case Token::LOGICALXOR: return SkString("^^");
+ case Token::BITWISENOT: return SkString("~");
+ case Token::BITWISEAND: return SkString("&");
+ case Token::BITWISEOR: return SkString("|");
+ case Token::BITWISEXOR: return SkString("^");
+ case Token::EQ: return SkString("=");
+ case Token::EQEQ: return SkString("==");
+ case Token::NEQ: return SkString("!=");
+ case Token::LT: return SkString("<");
+ case Token::GT: return SkString(">");
+ case Token::LTEQ: return SkString("<=");
+ case Token::GTEQ: return SkString(">=");
+ case Token::PLUSEQ: return SkString("+=");
+ case Token::MINUSEQ: return SkString("-=");
+ case Token::STAREQ: return SkString("*=");
+ case Token::SLASHEQ: return SkString("/=");
+ case Token::PERCENTEQ: return SkString("%=");
+ case Token::SHLEQ: return SkString("<<=");
+ case Token::SHREQ: return SkString(">>=");
+ case Token::LOGICALANDEQ: return SkString("&&=");
+ case Token::LOGICALOREQ: return SkString("||=");
+ case Token::LOGICALXOREQ: return SkString("^^=");
+ case Token::BITWISEANDEQ: return SkString("&=");
+ case Token::BITWISEOREQ: return SkString("|=");
+ case Token::BITWISEXOREQ: return SkString("^=");
+ case Token::PLUSPLUS: return SkString("++");
+ case Token::MINUSMINUS: return SkString("--");
default:
- ABORT("unsupported operator: %d\n", kind);
- }
+ ABORT("unsupported operator: %d\n", kind);
+ }
}
Token() {
}
- Token(Position position, Kind kind, String text)
+ Token(Position position, Kind kind, SkString text)
: fPosition(position)
, fKind(kind)
, fText(std::move(text)) {}
Kind fKind;
// will be the empty string unless the token has variable text content (identifiers, numeric
// literals, and directives)
- String fText;
+ SkString fText;
};
} // namespace
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
+#include <cinttypes>
+#include <locale>
+#include <sstream>
+#include <string>
namespace SkSL {
-#ifdef SKSL_STANDALONE
-StandaloneShaderCaps standaloneCaps;
+SkString to_string(double value) {
+#ifdef SK_BUILD_FOR_WIN
+ #define SNPRINTF _snprintf
+#else
+ #define SNPRINTF snprintf
#endif
+#define MAX_DOUBLE_CHARS 25
+ char buffer[MAX_DOUBLE_CHARS];
+ SkDEBUGCODE(int len = )SNPRINTF(buffer, sizeof(buffer), "%.17g", value);
+ ASSERT(len < MAX_DOUBLE_CHARS);
+ SkString result(buffer);
+ if (!strchr(buffer, '.') && !strchr(buffer, 'e')) {
+ result += ".0";
+ }
+ return result;
+#undef SNPRINTF
+#undef MAX_DOUBLE_CHARS
+}
+
+SkString to_string(int32_t value) {
+ return SkStringPrintf("%d", value);
+}
+
+SkString to_string(uint32_t value) {
+ return SkStringPrintf("%u", value);
+}
+
+SkString to_string(int64_t value) {
+ return SkStringPrintf("%" PRId64, value);
+}
+
+SkString to_string(uint64_t value) {
+ return SkStringPrintf("%" PRIu64, value);
+}
+
+int stoi(SkString s) {
+ if (s.size() > 2 && s[0] == '0' && s[1] == 'x') {
+ char* p;
+ int result = strtoul(s.c_str() + 2, &p, 16);
+ ASSERT(*p == 0);
+ return result;
+ }
+ return atoi(s.c_str());
+}
+
+double stod(SkString s) {
+ double result;
+ std::string str(s.c_str(), s.size());
+ std::stringstream buffer(str);
+ buffer.imbue(std::locale::classic());
+ buffer >> result;
+ return result;
+}
+
+long stol(SkString s) {
+ if (s.size() > 2 && s[0] == '0' && s[1] == 'x') {
+ char* p;
+ long result = strtoul(s.c_str() + 2, &p, 16);
+ ASSERT(*p == 0);
+ return result;
+ }
+ return atol(s.c_str());
+}
void sksl_abort() {
-#ifdef SKSL_STANDALONE
- abort();
-#else
+#ifdef SKIA
sk_abort_no_print();
exit(1);
+#else
+ abort();
#endif
}
-void write_stringstream(const StringStream& s, OutputStream& out) {
- out.write(s.data(), s.size());
+void write_data(const SkData& data, SkWStream& out) {
+ out.write(data.data(), data.size());
+}
+
+SkString operator+(const SkString& s, const char* c) {
+ SkString result(s);
+ result += c;
+ return result;
+}
+
+SkString operator+(const char* c, const SkString& s) {
+ SkString result(c);
+ result += s;
+ return result;
}
+SkString operator+(const SkString& s1, const SkString& s2) {
+ SkString result(s1);
+ result += s2;
+ return result;
+}
+
+bool operator==(const SkString& s1, const char* s2) {
+ return !strcmp(s1.c_str(), s2);
+}
+
+bool operator!=(const SkString& s1, const char* s2) {
+ return strcmp(s1.c_str(), s2);
+}
+
+bool operator!=(const char* s1, const SkString& s2) {
+ return strcmp(s1, s2.c_str());
+}
} // namespace
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_UTIL
#define SKSL_UTIL
-#include <cstdarg>
-#include <memory>
#include "stdlib.h"
-#include "string.h"
#include "assert.h"
-#include "SkSLString.h"
-#include "SkSLStringStream.h"
-
-#ifndef SKSL_STANDALONE
+#include "SkOpts.h"
+#include "SkRefCnt.h"
+#include "SkStream.h"
+#include "SkString.h"
+#include "SkTypes.h"
#include "GrContextOptions.h"
#include "GrShaderCaps.h"
-#endif
-
-#ifdef SKSL_STANDALONE
-#if defined(_WIN32) || defined(__SYMBIAN32__)
-#define SKSL_BUILD_FOR_WIN
-#endif
-#else
-#ifdef SK_BUILD_FOR_WIN
-#define SKSL_BUILD_FOR_WIN
-#endif // SK_BUILD_FOR_WIN
-#endif // SKSL_STANDALONE
namespace SkSL {
-#ifdef SKSL_STANDALONE
-
-// we're being compiled standalone, so we don't have access to caps...
-enum GrGLSLGeneration {
- k110_GrGLSLGeneration,
- k130_GrGLSLGeneration,
- k140_GrGLSLGeneration,
- k150_GrGLSLGeneration,
- k330_GrGLSLGeneration,
- k400_GrGLSLGeneration,
- k420_GrGLSLGeneration,
- k310es_GrGLSLGeneration,
- k320es_GrGLSLGeneration,
-};
-
-#define SKSL_CAPS_CLASS StandaloneShaderCaps
-class StandaloneShaderCaps {
-public:
- GrGLSLGeneration generation() const {
- return k400_GrGLSLGeneration;
- }
-
- bool canUseMinAndAbsTogether() const {
- return true;
- }
-
- bool mustForceNegatedAtanParamToFloat() const {
- return false;
- }
-
- bool shaderDerivativeSupport() const {
- return true;
- }
-
- bool usesPrecisionModifiers() const {
- return true;
- }
-
- bool mustDeclareFragmentShaderOutput() const {
- return true;
- }
-
- bool fbFetchSupport() const {
- return true;
- }
-
- bool fbFetchNeedsCustomOutput() const {
- return false;
- }
-
- bool bindlessTextureSupport() const {
- return false;
- }
-
- bool dropsTileOnZeroDivide() const {
- return false;
- }
-
- bool flatInterpolationSupport() const {
- return true;
- }
-
- bool noperspectiveInterpolationSupport() const {
- return true;
- }
-
- bool multisampleInterpolationSupport() const {
- return true;
- }
-
- bool sampleVariablesSupport() const {
- return true;
- }
-
- bool sampleMaskOverrideCoverageSupport() const {
- return true;
- }
-
- bool externalTextureSupport() const {
- return true;
- }
-
- bool texelFetchSupport() const {
- return true;
- }
-
- bool imageLoadStoreSupport() const {
- return true;
- }
-
- bool mustEnableAdvBlendEqs() const {
- return false;
- }
-
- bool mustEnableSpecificAdvBlendEqs() const {
- return false;
- }
-
- bool canUseAnyFunctionInShader() const {
- return false;
- }
-
- const char* shaderDerivativeExtensionString() const {
- return nullptr;
- }
-
- const char* fragCoordConventionsExtensionString() const {
- return nullptr;
- }
-
- const char* imageLoadStoreExtensionString() const {
- return nullptr;
- }
-
- const char* versionDeclString() const {
- return "";
- }
-};
-
-extern StandaloneShaderCaps standaloneCaps;
-
-#else
-
-#define SKSL_CAPS_CLASS GrShaderCaps
// Various sets of caps for use in tests
class ShaderCapsFactory {
public:
return result;
}
};
-#endif
-void write_stringstream(const StringStream& d, OutputStream& out);
+void write_data(const SkData& d, SkWStream& out);
+
+SkString operator+(const SkString& s, const char* c);
+
+SkString operator+(const char* c, const SkString& s);
+
+SkString operator+(const SkString& s1, const SkString& s2);
+
+bool operator==(const SkString& s1, const char* s2);
+
+bool operator!=(const SkString& s1, const char* s2);
+
+bool operator!=(const char* s1, const SkString& s2);
+
+SkString to_string(double value);
+
+SkString to_string(int32_t value);
+
+SkString to_string(uint32_t value);
+
+SkString to_string(int64_t value);
+
+SkString to_string(uint64_t value);
#if _MSC_VER
#define NORETURN __declspec(noreturn)
#else
#define NORETURN __attribute__((__noreturn__))
#endif
+int stoi(SkString s);
+
+double stod(SkString s);
+
+long stol(SkString s);
NORETURN void sksl_abort();
} // namespace
-#ifdef SKSL_STANDALONE
-#define ASSERT(x) (void)((x) || (ABORT("failed assert(%s): %s:%d\n", #x, __FILE__, __LINE__), 0))
-#define ASSERT_RESULT(x) ASSERT(x)
-#define SKSL_DEBUGCODE(x) x
-#else
-#define ASSERT SkASSERT
-#define ASSERT_RESULT(x) SkAssertResult(x)
-#define SKSL_DEBUGCODE(x) SkDEBUGCODE(x)
-#endif
+#define ASSERT(x) SkASSERT(x)
+#define ASSERT_RESULT(x) SkAssertResult(x);
-#define SKSL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
-
-#if defined(__clang__) || defined(__GNUC__)
-#define SKSL_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B))))
+#ifdef SKIA
+#define ABORT(...) { SkDebugf(__VA_ARGS__); sksl_abort(); }
#else
-#define SKSL_PRINTF_LIKE(A, B)
+#define ABORT(...) { sksl_abort(); }
#endif
-#define ABORT(...) (printf(__VA_ARGS__), sksl_abort())
-
+namespace std {
+ template<> struct hash<SkString> {
+ size_t operator()(const SkString& s) const {
+ return SkOpts::hash_fn(s.c_str(), s.size(), 0);
+ }
+ };
+}
#endif
namespace SkSL {
/**
- * Represents a binary operation, with the operator represented by the token's type.
+ * Represents a binary operation, with the operator represented by the token's type.
*/
struct ASTBinaryExpression : public ASTExpression {
ASTBinaryExpression(std::unique_ptr<ASTExpression> left, Token op,
, fOperator(op.fKind)
, fRight(std::move(right)) {}
- String description() const override {
+ SkString description() const override {
return "(" + fLeft->description() + " " + Token::OperatorName(fOperator) + " " +
fRight->description() + ")";
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTBLOCK
#define SKSL_ASTBLOCK
namespace SkSL {
/**
- * Represents a curly-braced block of statements.
+ * Represents a curly-braced block of statements.
*/
struct ASTBlock : public ASTStatement {
ASTBlock(Position position, std::vector<std::unique_ptr<ASTStatement>> statements)
: INHERITED(position, kBlock_Kind)
, fStatements(std::move(statements)) {}
- String description() const override {
- String result("{");
+ SkString description() const override {
+ SkString result("{");
for (size_t i = 0; i < fStatements.size(); i++) {
result += "\n";
result += fStatements[i]->description();
}
result += "\n}\n";
- return result;
+ return result;
}
const std::vector<std::unique_ptr<ASTStatement>> fStatements;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTBOOLLITERAL
#define SKSL_ASTBOOLLITERAL
namespace SkSL {
/**
- * Represents "true" or "false".
+ * Represents "true" or "false".
*/
struct ASTBoolLiteral : public ASTExpression {
ASTBoolLiteral(Position position, bool value)
: INHERITED(position, kBool_Kind)
, fValue(value) {}
- String description() const override {
- return String(fValue ? "true" : "false");
+ SkString description() const override {
+ return SkString(fValue ? "true" : "false");
}
const bool fValue;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTBREAKSTATEMENT
#define SKSL_ASTBREAKSTATEMENT
namespace SkSL {
/**
- * A 'break' statement.
+ * A 'break' statement.
*/
struct ASTBreakStatement : public ASTStatement {
ASTBreakStatement(Position position)
: INHERITED(position, kBreak_Kind) {}
- String description() const override {
- return String("break;");
+ SkString description() const override {
+ return SkString("break;");
}
typedef ASTStatement INHERITED;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTCALLSUFFIX
#define SKSL_ASTCALLSUFFIX
namespace SkSL {
/**
- * A parenthesized list of arguments following an expression, indicating a function call.
+ * A parenthesized list of arguments following an expression, indicating a function call.
*/
struct ASTCallSuffix : public ASTSuffix {
- ASTCallSuffix(Position position, std::vector<std::unique_ptr<ASTExpression>> arguments)
+ ASTCallSuffix(Position position, std::vector<std::unique_ptr<ASTExpression>> arguments)
: INHERITED(position, ASTSuffix::kCall_Kind)
, fArguments(std::move(arguments)) {}
- String description() const override {
- String result("(");
- String separator;
+ SkString description() const override {
+ SkString result("(");
+ SkString separator;
for (size_t i = 0; i < fArguments.size(); ++i) {
result += separator;
separator = ", ";
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTCONTINUESTATEMENT
#define SKSL_ASTCONTINUESTATEMENT
namespace SkSL {
/**
- * A 'continue' statement.
+ * A 'continue' statement.
*/
struct ASTContinueStatement : public ASTStatement {
ASTContinueStatement(Position position)
: INHERITED(position, kContinue_Kind) {}
- String description() const override {
- return String("continue;");
+ SkString description() const override {
+ return SkString("continue;");
}
typedef ASTStatement INHERITED;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTDECLARATION
#define SKSL_ASTDECLARATION
namespace SkSL {
/**
- * Abstract supertype of declarations such as variables and functions.
+ * Abstract supertype of declarations such as variables and functions.
*/
struct ASTDeclaration : public ASTPositionNode {
enum Kind {
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTDISCARDSTATEMENT
#define SKSL_ASTDISCARDSTATEMENT
namespace SkSL {
/**
- * A 'discard' statement.
+ * A 'discard' statement.
*/
struct ASTDiscardStatement : public ASTStatement {
ASTDiscardStatement(Position position)
: INHERITED(position, kDiscard_Kind) {}
- String description() const override {
- return String("discard;");
+ SkString description() const override {
+ return SkString("discard;");
}
typedef ASTStatement INHERITED;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTDOSTATEMENT
#define SKSL_ASTDOSTATEMENT
namespace SkSL {
/**
- * A 'do' loop.
+ * A 'do' loop.
*/
struct ASTDoStatement : public ASTStatement {
ASTDoStatement(Position position, std::unique_ptr<ASTStatement> statement,
, fStatement(std::move(statement))
, fTest(std::move(test)) {}
- String description() const override {
+ SkString description() const override {
return "do " + fStatement->description() + " while (" + fTest->description() + ");";
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTEXPRESSION
#define SKSL_ASTEXPRESSION
namespace SkSL {
/**
- * Abstract supertype of all expressions.
+ * Abstract supertype of all expressions.
*/
struct ASTExpression : public ASTPositionNode {
enum Kind {
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTEXPRESSIONSTATEMENT
#define SKSL_ASTEXPRESSIONSTATEMENT
namespace SkSL {
/**
- * A lone expression being used as a statement.
+ * A lone expression being used as a statement.
*/
struct ASTExpressionStatement : public ASTStatement {
ASTExpressionStatement(std::unique_ptr<ASTExpression> expression)
: INHERITED(expression->fPosition, kExpression_Kind)
, fExpression(std::move(expression)) {}
- String description() const override {
+ SkString description() const override {
return fExpression->description() + ";";
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTEXTENSION
#define SKSL_ASTEXTENSION
namespace SkSL {
-/**
- * An extension declaration.
+/**
+ * An extension declaration.
*/
struct ASTExtension : public ASTDeclaration {
- ASTExtension(Position position, String name)
+ ASTExtension(Position position, SkString name)
: INHERITED(position, kExtension_Kind)
, fName(std::move(name)) {}
- String description() const override {
+ SkString description() const override {
return "#extension " + fName + " : enable";
}
- const String fName;
+ const SkString fName;
typedef ASTDeclaration INHERITED;
};
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTFIELDSUFFIX
#define SKSL_ASTFIELDSUFFIX
* actually vector swizzle (which looks the same to the parser).
*/
struct ASTFieldSuffix : public ASTSuffix {
- ASTFieldSuffix(Position position, String field)
+ ASTFieldSuffix(Position position, SkString field)
: INHERITED(position, ASTSuffix::kField_Kind)
, fField(std::move(field)) {}
- String description() const override {
+ SkString description() const override {
return "." + fField;
}
- String fField;
+ SkString fField;
typedef ASTSuffix INHERITED;
};
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTFLOATLITERAL
#define SKSL_ASTFLOATLITERAL
namespace SkSL {
/**
- * A literal floating point number.
+ * A literal floating point number.
*/
struct ASTFloatLiteral : public ASTExpression {
ASTFloatLiteral(Position position, double value)
: INHERITED(position, kFloat_Kind)
, fValue(value) {}
- String description() const override {
+ SkString description() const override {
return to_string(fValue);
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTFORSTATEMENT
#define SKSL_ASTFORSTATEMENT
namespace SkSL {
/**
- * A 'for' loop.
+ * A 'for' loop.
*/
struct ASTForStatement : public ASTStatement {
- ASTForStatement(Position position, std::unique_ptr<ASTStatement> initializer,
+ ASTForStatement(Position position, std::unique_ptr<ASTStatement> initializer,
std::unique_ptr<ASTExpression> test, std::unique_ptr<ASTExpression> next,
std::unique_ptr<ASTStatement> statement)
: INHERITED(position, kFor_Kind)
, fNext(std::move(next))
, fStatement(std::move(statement)) {}
- String description() const override {
- String result("for (");
+ SkString description() const override {
+ SkString result("for (");
if (fInitializer) {
result.append(fInitializer->description());
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTFUNCTION
#define SKSL_ASTFUNCTION
namespace SkSL {
/**
- * A function declaration or definition. The fBody field will be null for declarations.
+ * A function declaration or definition. The fBody field will be null for declarations.
*/
struct ASTFunction : public ASTDeclaration {
- ASTFunction(Position position, std::unique_ptr<ASTType> returnType, String name,
- std::vector<std::unique_ptr<ASTParameter>> parameters,
+ ASTFunction(Position position, std::unique_ptr<ASTType> returnType, SkString name,
+ std::vector<std::unique_ptr<ASTParameter>> parameters,
std::unique_ptr<ASTBlock> body)
: INHERITED(position, kFunction_Kind)
, fReturnType(std::move(returnType))
, fParameters(std::move(parameters))
, fBody(std::move(body)) {}
- String description() const override {
- String result = fReturnType->description() + " " + fName + "(";
+ SkString description() const override {
+ SkString result = fReturnType->description() + " " + fName + "(";
for (size_t i = 0; i < fParameters.size(); i++) {
if (i > 0) {
result += ", ";
} else {
result += ");";
}
- return result;
+ return result;
}
const std::unique_ptr<ASTType> fReturnType;
- const String fName;
+ const SkString fName;
const std::vector<std::unique_ptr<ASTParameter>> fParameters;
const std::unique_ptr<ASTBlock> fBody;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTIDENTIFIER
#define SKSL_ASTIDENTIFIER
namespace SkSL {
/**
- * An identifier in an expression context.
+ * An identifier in an expression context.
*/
struct ASTIdentifier : public ASTExpression {
- ASTIdentifier(Position position, String text)
+ ASTIdentifier(Position position, SkString text)
: INHERITED(position, kIdentifier_Kind)
, fText(std::move(text)) {}
- String description() const override {
+ SkString description() const override {
return fText;
}
- const String fText;
+ const SkString fText;
typedef ASTExpression INHERITED;
};
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTIFSTATEMENT
#define SKSL_ASTIFSTATEMENT
namespace SkSL {
/**
- * An 'if' statement.
+ * An 'if' statement.
*/
struct ASTIfStatement : public ASTStatement {
- ASTIfStatement(Position position, std::unique_ptr<ASTExpression> test,
+ ASTIfStatement(Position position, std::unique_ptr<ASTExpression> test,
std::unique_ptr<ASTStatement> ifTrue, std::unique_ptr<ASTStatement> ifFalse)
: INHERITED(position, kIf_Kind)
, fTest(std::move(test))
, fIfTrue(std::move(ifTrue))
, fIfFalse(std::move(ifFalse)) {}
- String description() const override {
- String result("if (");
+ SkString description() const override {
+ SkString result("if (");
result += fTest->description();
result += ") ";
result += fIfTrue->description();
result += " else ";
result += fIfFalse->description();
}
- return result;
+ return result;
}
const std::unique_ptr<ASTExpression> fTest;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTINDEXSUFFIX
#define SKSL_ASTINDEXSUFFIX
* 'float[](5, 6)' are represented with a null fExpression.
*/
struct ASTIndexSuffix : public ASTSuffix {
- ASTIndexSuffix(Position position)
+ ASTIndexSuffix(Position position)
: INHERITED(position, ASTSuffix::kIndex_Kind)
, fExpression(nullptr) {}
- ASTIndexSuffix(std::unique_ptr<ASTExpression> expression)
+ ASTIndexSuffix(std::unique_ptr<ASTExpression> expression)
: INHERITED(expression ? expression->fPosition : Position(), ASTSuffix::kIndex_Kind)
, fExpression(std::move(expression)) {}
- String description() const override {
+ SkString description() const override {
if (fExpression) {
return "[" + fExpression->description() + "]";
} else {
- return String("[]");
+ return SkString("[]");
}
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTINTLITERAL
#define SKSL_ASTINTLITERAL
: INHERITED(position, kInt_Kind)
, fValue(value) {}
- String description() const override {
+ SkString description() const override {
return to_string(fValue);
}
// valueName is empty when it was not present in the source
ASTInterfaceBlock(Position position,
Modifiers modifiers,
- String typeName,
+ SkString typeName,
std::vector<std::unique_ptr<ASTVarDeclarations>> declarations,
- String instanceName,
+ SkString instanceName,
std::vector<std::unique_ptr<ASTExpression>> sizes)
: INHERITED(position, kInterfaceBlock_Kind)
, fModifiers(modifiers)
, fInstanceName(std::move(instanceName))
, fSizes(std::move(sizes)) {}
- String description() const override {
- String result = fModifiers.description() + fTypeName + " {\n";
+ SkString description() const override {
+ SkString result = fModifiers.description() + fTypeName + " {\n";
for (size_t i = 0; i < fDeclarations.size(); i++) {
result += fDeclarations[i]->description() + "\n";
}
}
const Modifiers fModifiers;
- const String fTypeName;
+ const SkString fTypeName;
const std::vector<std::unique_ptr<ASTVarDeclarations>> fDeclarations;
- const String fInstanceName;
+ const SkString fInstanceName;
const std::vector<std::unique_ptr<ASTExpression>> fSizes;
typedef ASTDeclaration INHERITED;
: INHERITED(Position(), kModifiers_Kind)
, fModifiers(modifiers) {}
- String description() const {
+ SkString description() const {
return fModifiers.description() + ";";
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTNODE
#define SKSL_ASTNODE
-#include "SkSLString.h"
+#include "SkString.h"
namespace SkSL {
*/
struct ASTNode {
virtual ~ASTNode() {}
-
- virtual String description() const = 0;
+
+ virtual SkString description() const = 0;
};
} // namespace
// 'sizes' is a list of the array sizes appearing on a parameter, in source order.
// e.g. int x[3][1] would have sizes [3, 1].
ASTParameter(Position position, Modifiers modifiers, std::unique_ptr<ASTType> type,
- String name, std::vector<int> sizes)
+ SkString name, std::vector<int> sizes)
: INHERITED(position)
, fModifiers(modifiers)
, fType(std::move(type))
, fName(std::move(name))
, fSizes(std::move(sizes)) {}
- String description() const override {
- String result = fModifiers.description() + fType->description() + " " + fName;
+ SkString description() const override {
+ SkString result = fModifiers.description() + fType->description() + " " + fName;
for (int size : fSizes) {
result += "[" + to_string(size) + "]";
}
const Modifiers fModifiers;
const std::unique_ptr<ASTType> fType;
- const String fName;
+ const SkString fName;
const std::vector<int> fSizes;
typedef ASTPositionNode INHERITED;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTPOSITIONNODE
#define SKSL_ASTPOSITIONNODE
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTPRECISION
#define SKSL_ASTPRECISION
: INHERITED(position, kPrecision_Kind)
, fPrecision(precision) {}
- String description() const {
+ SkString description() const {
switch (fPrecision) {
- case Modifiers::kLowp_Flag: return String("precision lowp float;");
- case Modifiers::kMediump_Flag: return String("precision mediump float;");
- case Modifiers::kHighp_Flag: return String("precision highp float;");
- default:
- ASSERT(false);
- return String("<error>");
+ case Modifiers::kLowp_Flag: return SkString("precision lowp float;");
+ case Modifiers::kMediump_Flag: return SkString("precision mediump float;");
+ case Modifiers::kHighp_Flag: return SkString("precision highp float;");
+ default:
+ ASSERT(false);
+ return SkString("<error>");
}
ASSERT(false);
- return String("<error>");
+ return SkString("<error>");
}
const Modifiers::Flag fPrecision;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTPREFIXEXPRESSION
#define SKSL_ASTPREFIXEXPRESSION
, fOperator(op.fKind)
, fOperand(std::move(operand)) {}
- String description() const override {
+ SkString description() const override {
return Token::OperatorName(fOperator) + fOperand->description();
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTRETURNSTATEMENT
#define SKSL_ASTRETURNSTATEMENT
: INHERITED(position, kReturn_Kind)
, fExpression(std::move(expression)) {}
- String description() const override {
- String result("return");
+ SkString description() const override {
+ SkString result("return");
if (fExpression) {
result += " " + fExpression->description();
}
- return result + ";";
+ return result + ";";
}
const std::unique_ptr<ASTExpression> fExpression;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTSTATEMENT
#define SKSL_ASTSTATEMENT
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTSUFFIX
#define SKSL_ASTSUFFIX
: INHERITED(position)
, fKind(kind) {}
- String description() const override {
+ SkString description() const override {
switch (fKind) {
case kPostIncrement_Kind:
- return String("++");
+ return SkString("++");
case kPostDecrement_Kind:
- return String("--");
+ return SkString("--");
default:
ABORT("unsupported suffix operator");
- }
+ }
}
Kind fKind;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTSUFFIXEXPRESSION
#define SKSL_ASTSUFFIXEXPRESSION
, fBase(std::move(base))
, fSuffix(std::move(suffix)) {}
- String description() const override {
+ SkString description() const override {
return fBase->description() + fSuffix->description();
}
, fValue(std::move(value))
, fStatements(std::move(statements)) {}
- String description() const override {
- String result;
+ SkString description() const override {
+ SkString result;
if (fValue) {
result.appendf("case %s:\n", fValue->description().c_str());
} else {
, fValue(std::move(value))
, fCases(std::move(cases)) {}
- String description() const override {
- String result = String::printf("switch (%s) {\n", + fValue->description().c_str());
+ SkString description() const override {
+ SkString result = SkStringPrintf("switch (%s) {\n", + fValue->description().c_str());
for (const auto& c : fCases) {
result += c->description();
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTTERNARYEXPRESSION
#define SKSL_ASTTERNARYEXPRESSION
, fIfTrue(std::move(ifTrue))
, fIfFalse(std::move(ifFalse)) {}
- String description() const override {
+ SkString description() const override {
return "(" + fTest->description() + " ? " + fIfTrue->description() + " : " +
- fIfFalse->description() + ")";
+ fIfFalse->description() + ")";
}
const std::unique_ptr<ASTExpression> fTest;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTTYPE
#define SKSL_ASTTYPE
kStruct_Kind
};
- ASTType(Position position, String name, Kind kind, std::vector<int> sizes)
+ ASTType(Position position, SkString name, Kind kind, std::vector<int> sizes)
: INHERITED(position)
, fName(std::move(name))
, fKind(kind)
, fSizes(std::move(sizes)) {}
- String description() const override {
+ SkString description() const override {
return fName;
}
- const String fName;
+ const SkString fName;
const Kind fKind;
* instances.
*/
struct ASTVarDeclaration {
- ASTVarDeclaration(const String name,
+ ASTVarDeclaration(const SkString name,
std::vector<std::unique_ptr<ASTExpression>> sizes,
std::unique_ptr<ASTExpression> value)
: fName(name)
, fSizes(std::move(sizes))
, fValue(std::move(value)) {}
- String description() const {
- String result = fName;
+ SkString description() const {
+ SkString result = fName;
for (const auto& size : fSizes) {
if (size) {
result += "[" + size->description() + "]";
return result;
}
- String fName;
+ SkString fName;
// array sizes, if any. e.g. 'foo[3][]' has sizes [3, null]
std::vector<std::unique_ptr<ASTExpression>> fSizes;
, fType(std::move(type))
, fVars(std::move(vars)) {}
- String description() const override {
- String result = fModifiers.description() + fType->description() + " ";
- String separator;
+ SkString description() const override {
+ SkString result = fModifiers.description() + fType->description() + " ";
+ SkString separator;
for (const auto& var : fVars) {
result += separator;
separator = ", ";
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTVARDECLARATIONSTATEMENT
#define SKSL_ASTVARDECLARATIONSTATEMENT
: INHERITED(decl->fPosition, kVarDeclaration_Kind)
, fDeclarations(std::move(decl)) {}
- String description() const override {
+ SkString description() const override {
return fDeclarations->description() + ";";
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_ASTWHILESTATEMENT
#define SKSL_ASTWHILESTATEMENT
* A 'while' statement.
*/
struct ASTWhileStatement : public ASTStatement {
- ASTWhileStatement(Position position, std::unique_ptr<ASTExpression> test,
+ ASTWhileStatement(Position position, std::unique_ptr<ASTExpression> test,
std::unique_ptr<ASTStatement> statement)
: INHERITED(position, kWhile_Kind)
, fTest(std::move(test))
, fStatement(std::move(statement)) {}
- String description() const override {
+ SkString description() const override {
return "while (" + fTest->description() + ") " + fStatement->description();
}
*fRight);
}
- virtual String description() const override {
+ virtual SkString description() const override {
return "(" + fLeft->description() + " " + Token::OperatorName(fOperator) + " " +
fRight->description() + ")";
}
, fSymbols(std::move(symbols))
, fStatements(std::move(statements)) {}
- String description() const override {
- String result("{");
+ SkString description() const override {
+ SkString result("{");
for (size_t i = 0; i < fStatements.size(); i++) {
result += "\n";
result += fStatements[i]->description();
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_BOOLLITERAL
#define SKSL_BOOLLITERAL
: INHERITED(position, kBoolLiteral_Kind, *context.fBool_Type)
, fValue(value) {}
- String description() const override {
- return String(fValue ? "true" : "false");
+ SkString description() const override {
+ return SkString(fValue ? "true" : "false");
}
bool isConstant() const override {
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_BREAKSTATEMENT
#define SKSL_BREAKSTATEMENT
namespace SkSL {
/**
- * A 'break' statement.
+ * A 'break' statement.
*/
struct BreakStatement : public Statement {
BreakStatement(Position position)
: INHERITED(position, kBreak_Kind) {}
- String description() const override {
- return String("break;");
+ SkString description() const override {
+ return SkString("break;");
}
typedef Statement INHERITED;
return nullptr;
}
- String description() const override {
- String result = fType.description() + "(";
- String separator;
+ SkString description() const override {
+ SkString result = fType.description() + "(";
+ SkString separator;
for (size_t i = 0; i < fArguments.size(); i++) {
result += separator;
result += fArguments[i]->description();
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_CONTINUESTATEMENT
#define SKSL_CONTINUESTATEMENT
namespace SkSL {
/**
- * A 'continue' statement.
+ * A 'continue' statement.
*/
struct ContinueStatement : public Statement {
ContinueStatement(Position position)
: INHERITED(position, kContinue_Kind) {}
- String description() const override {
- return String("continue;");
+ SkString description() const override {
+ return SkString("continue;");
}
typedef Statement INHERITED;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_DISCARDSTATEMENT
#define SKSL_DISCARDSTATEMENT
namespace SkSL {
/**
- * A 'discard' statement.
+ * A 'discard' statement.
*/
struct DiscardStatement : public Statement {
DiscardStatement(Position position)
: INHERITED(position, kDiscard_Kind) {}
- String description() const override {
- return String("discard;");
+ SkString description() const override {
+ return SkString("discard;");
}
typedef Statement INHERITED;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_DOSTATEMENT
#define SKSL_DOSTATEMENT
, fStatement(std::move(statement))
, fTest(std::move(test)) {}
- String description() const override {
+ SkString description() const override {
return "do " + fStatement->description() + " while (" + fTest->description() + ");";
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_EXPRESSIONSTATEMENT
#define SKSL_EXPRESSIONSTATEMENT
namespace SkSL {
/**
- * A lone expression being used as a statement.
+ * A lone expression being used as a statement.
*/
struct ExpressionStatement : public Statement {
ExpressionStatement(std::unique_ptr<Expression> expression)
: INHERITED(expression->fPosition, kExpression_Kind)
, fExpression(std::move(expression)) {}
- String description() const override {
+ SkString description() const override {
return fExpression->description() + ";";
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_EXTENSION
#define SKSL_EXTENSION
namespace SkSL {
-/**
- * An extension declaration.
+/**
+ * An extension declaration.
*/
struct Extension : public ProgramElement {
- Extension(Position position, String name)
- : INHERITED(position, kExtension_Kind)
+ Extension(Position position, SkString name)
+ : INHERITED(position, kExtension_Kind)
, fName(std::move(name)) {}
- String description() const override {
+ SkString description() const override {
return "#extension " + fName + " : enable";
}
- const String fName;
+ const SkString fName;
typedef ProgramElement INHERITED;
};
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_FIELD
#define SKSL_FIELD
namespace SkSL {
-/**
- * A symbol which should be interpreted as a field access. Fields are added to the symboltable
- * whenever a bare reference to an identifier should refer to a struct field; in GLSL, this is the
+/**
+ * A symbol which should be interpreted as a field access. Fields are added to the symboltable
+ * whenever a bare reference to an identifier should refer to a struct field; in GLSL, this is the
* result of declaring anonymous interface blocks.
*/
struct Field : public Symbol {
, fOwner(owner)
, fFieldIndex(fieldIndex) {}
- virtual String description() const override {
+ virtual SkString description() const override {
return fOwner.description() + "." + fOwner.fType.fields()[fFieldIndex].fName;
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_FIELDACCESS
#define SKSL_FIELDACCESS
kAnonymousInterfaceBlock_OwnerKind
};
- FieldAccess(std::unique_ptr<Expression> base, int fieldIndex,
+ FieldAccess(std::unique_ptr<Expression> base, int fieldIndex,
OwnerKind ownerKind = kDefault_OwnerKind)
: INHERITED(base->fPosition, kFieldAccess_Kind, *base->fType.fields()[fieldIndex].fType)
, fBase(std::move(base))
, fFieldIndex(fieldIndex)
, fOwnerKind(ownerKind) {}
- virtual String description() const override {
+ virtual SkString description() const override {
return fBase->description() + "." + fBase->fType.fields()[fFieldIndex].fName;
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_FLOATLITERAL
#define SKSL_FLOATLITERAL
: INHERITED(position, kFloatLiteral_Kind, *context.fFloat_Type)
, fValue(value) {}
- virtual String description() const override {
+ virtual SkString description() const override {
return to_string(fValue);
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_FORSTATEMENT
#define SKSL_FORSTATEMENT
* A 'for' statement.
*/
struct ForStatement : public Statement {
- ForStatement(Position position, std::unique_ptr<Statement> initializer,
- std::unique_ptr<Expression> test, std::unique_ptr<Expression> next,
+ ForStatement(Position position, std::unique_ptr<Statement> initializer,
+ std::unique_ptr<Expression> test, std::unique_ptr<Expression> next,
std::unique_ptr<Statement> statement, std::shared_ptr<SymbolTable> symbols)
: INHERITED(position, kFor_Kind)
, fSymbols(symbols)
, fNext(std::move(next))
, fStatement(std::move(statement)) {}
- String description() const override {
- String result("for (");
+ SkString description() const override {
+ SkString result("for (");
if (fInitializer) {
result += fInitializer->description();
- }
+ }
result += " ";
if (fTest) {
result += fTest->description();
- }
+ }
result += "; ";
if (fNext) {
result += fNext->description();
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_FUNCTIONCALL
#define SKSL_FUNCTIONCALL
, fFunction(std::move(function))
, fArguments(std::move(arguments)) {}
- String description() const override {
- String result = fFunction.fName + "(";
- String separator;
+ SkString description() const override {
+ SkString result = fFunction.fName + "(";
+ SkString separator;
for (size_t i = 0; i < fArguments.size(); i++) {
result += separator;
result += fArguments[i]->description();
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_FUNCTIONDECLARATION
#define SKSL_FUNCTIONDECLARATION
* A function declaration (not a definition -- does not contain a body).
*/
struct FunctionDeclaration : public Symbol {
- FunctionDeclaration(Position position, String name,
+ FunctionDeclaration(Position position, SkString name,
std::vector<const Variable*> parameters, const Type& returnType)
: INHERITED(position, kFunctionDeclaration_Kind, std::move(name))
, fDefined(false)
, fParameters(std::move(parameters))
, fReturnType(returnType) {}
- String description() const override {
- String result = fReturnType.description() + " " + fName + "(";
- String separator;
+ SkString description() const override {
+ SkString result = fReturnType.description() + " " + fName + "(";
+ SkString separator;
for (auto p : fParameters) {
result += separator;
separator = ", ";
/**
* Determine the effective types of this function's parameters and return value when called with
- * the given arguments. This is relevant for functions with generic parameter types, where this
+ * the given arguments. This is relevant for functions with generic parameter types, where this
* will collapse the generic types down into specific concrete types.
*
* Returns true if it was able to select a concrete set of types for the generic function, false
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_FUNCTIONDEFINITION
#define SKSL_FUNCTIONDEFINITION
* A function definition (a declaration plus an associated block of code).
*/
struct FunctionDefinition : public ProgramElement {
- FunctionDefinition(Position position, const FunctionDeclaration& declaration,
+ FunctionDefinition(Position position, const FunctionDeclaration& declaration,
std::unique_ptr<Block> body)
: INHERITED(position, kFunction_Kind)
, fDeclaration(declaration)
, fBody(std::move(body)) {}
- String description() const override {
+ SkString description() const override {
return fDeclaration.description() + " " + fBody->description();
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_FUNCTIONREFERENCE
#define SKSL_FUNCTIONREFERENCE
namespace SkSL {
/**
- * An identifier referring to a function name. This is an intermediate value: FunctionReferences are
+ * An identifier referring to a function name. This is an intermediate value: FunctionReferences are
* always eventually replaced by FunctionCalls in valid programs.
*/
struct FunctionReference : public Expression {
- FunctionReference(const Context& context, Position position,
+ FunctionReference(const Context& context, Position position,
std::vector<const FunctionDeclaration*> function)
: INHERITED(position, kFunctionReference_Kind, *context.fInvalid_Type)
, fFunctions(function) {}
- virtual String description() const override {
+ virtual SkString description() const override {
ASSERT(false);
- return String("<function>");
+ return SkString("<function>");
}
const std::vector<const FunctionDeclaration*> fFunctions;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_IRNODE
#define SKSL_IRNODE
namespace SkSL {
/**
- * Represents a node in the intermediate representation (IR) tree. The IR is a fully-resolved
+ * Represents a node in the intermediate representation (IR) tree. The IR is a fully-resolved
* version of the program (all types determined, everything validated), ready for code generation.
*/
struct IRNode {
virtual ~IRNode() {}
- virtual String description() const = 0;
+ virtual SkString description() const = 0;
const Position fPosition;
};
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_IFSTATEMENT
#define SKSL_IFSTATEMENT
* An 'if' statement.
*/
struct IfStatement : public Statement {
- IfStatement(Position position, std::unique_ptr<Expression> test,
+ IfStatement(Position position, std::unique_ptr<Expression> test,
std::unique_ptr<Statement> ifTrue, std::unique_ptr<Statement> ifFalse)
: INHERITED(position, kIf_Kind)
, fTest(std::move(test))
, fIfTrue(std::move(ifTrue))
, fIfFalse(std::move(ifFalse)) {}
- String description() const override {
- String result = "if (" + fTest->description() + ") " + fIfTrue->description();
+ SkString description() const override {
+ SkString result = "if (" + fTest->description() + ") " + fIfTrue->description();
if (fIfFalse) {
result += " else " + fIfFalse->description();
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_INDEX
#define SKSL_INDEX
* An expression which extracts a value from an array or matrix, as in 'm[2]'.
*/
struct IndexExpression : public Expression {
- IndexExpression(const Context& context, std::unique_ptr<Expression> base,
+ IndexExpression(const Context& context, std::unique_ptr<Expression> base,
std::unique_ptr<Expression> index)
: INHERITED(base->fPosition, kIndex_Kind, index_type(context, base->fType))
, fBase(std::move(base))
ASSERT(fIndex->fType == *context.fInt_Type || fIndex->fType == *context.fUInt_Type);
}
- String description() const override {
+ SkString description() const override {
return fBase->description() + "[" + fIndex->description() + "]";
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_INTLITERAL
#define SKSL_INTLITERAL
: INHERITED(position, kIntLiteral_Kind, type ? *type : *context.fInt_Type)
, fValue(value) {}
- virtual String description() const override {
+ virtual SkString description() const override {
return to_string(fValue);
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_INTERFACEBLOCK
#define SKSL_INTERFACEBLOCK
* At the IR level, this is represented by a single variable of struct type.
*/
struct InterfaceBlock : public ProgramElement {
- InterfaceBlock(Position position, const Variable* var, String typeName, String instanceName,
+ InterfaceBlock(Position position, const Variable* var, SkString typeName, SkString instanceName,
std::vector<std::unique_ptr<Expression>> sizes,
std::shared_ptr<SymbolTable> typeOwner)
: INHERITED(position, kInterfaceBlock_Kind)
, fSizes(std::move(sizes))
, fTypeOwner(typeOwner) {}
- String description() const override {
- String result = fVariable.fModifiers.description() + fTypeName + " {\n";
+ SkString description() const override {
+ SkString result = fVariable.fModifiers.description() + fTypeName + " {\n";
const Type* structType = &fVariable.fType;
while (structType->kind() == Type::kArray_Kind) {
structType = &structType->componentType();
}
const Variable& fVariable;
- const String fTypeName;
- const String fInstanceName;
+ const SkString fTypeName;
+ const SkString fInstanceName;
const std::vector<std::unique_ptr<Expression>> fSizes;
const std::shared_ptr<SymbolTable> fTypeOwner;
#ifndef SKSL_LAYOUT
#define SKSL_LAYOUT
+#include "SkString.h"
#include "SkSLUtil.h"
namespace SkSL {
case Format::kRGBA8I: return "rgba8i";
case Format::kR8I: return "r8i";
}
- ABORT("Unexpected format");
+ SkFAIL("Unexpected format");
return "";
}
- static bool ReadFormat(String str, Format* format) {
+ static bool ReadFormat(SkString str, Format* format) {
if (str == "rgba32f") {
*format = Format::kRGBA32F;
return true;
, fMaxVertices(-1)
, fInvocations(-1) {}
- String description() const {
- String result;
- String separator;
+ SkString description() const {
+ SkString result;
+ SkString separator;
if (fLocation >= 0) {
result += separator + "location = " + to_string(fLocation);
separator = ", ";
: fLayout(layout)
, fFlags(flags) {}
- String description() const {
- String result = fLayout.description();
+ SkString description() const {
+ SkString result = fLayout.description();
if (fFlags & kUniform_Flag) {
result += "uniform ";
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_MODIFIERDECLARATION
#define SKSL_MODIFIERDECLARATION
: INHERITED(Position(), kModifiers_Kind)
, fModifiers(modifiers) {}
- String description() const {
+ SkString description() const {
return fModifiers.description() + ";";
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_POSTFIXEXPRESSION
#define SKSL_POSTFIXEXPRESSION
, fOperand(std::move(operand))
, fOperator(op) {}
- virtual String description() const override {
+ virtual SkString description() const override {
return fOperand->description() + Token::OperatorName(fOperator);
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_PREFIXEXPRESSION
#define SKSL_PREFIXEXPRESSION
, fOperand(std::move(operand))
, fOperator(op) {}
- virtual String description() const override {
+ virtual SkString description() const override {
return Token::OperatorName(fOperator) + fOperand->description();
}
*/
struct Program {
struct Settings {
-#ifdef SKSL_STANDALONE
- const StandaloneShaderCaps* fCaps = &standaloneCaps;
-#else
const GrShaderCaps* fCaps = nullptr;
-#endif
// if false, sk_FragCoord is exactly the same as gl_FragCoord. If true, the y coordinate
// must be flipped.
bool fFlipY = false;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_PROGRAMELEMENT
#define SKSL_PROGRAMELEMENT
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_RETURNSTATEMENT
#define SKSL_RETURNSTATEMENT
: INHERITED(position, kReturn_Kind) {}
ReturnStatement(std::unique_ptr<Expression> expression)
- : INHERITED(expression->fPosition, kReturn_Kind)
+ : INHERITED(expression->fPosition, kReturn_Kind)
, fExpression(std::move(expression)) {}
- String description() const override {
+ SkString description() const override {
if (fExpression) {
return "return " + fExpression->description() + ";";
} else {
- return String("return;");
+ return SkString("return;");
}
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_STATEMENT
#define SKSL_STATEMENT
, fValue(std::move(value))
, fStatements(std::move(statements)) {}
- String description() const override {
- String result;
+ SkString description() const override {
+ SkString result;
if (fValue) {
result.appendf("case %s:\n", fValue->description().c_str());
} else {
, fValue(std::move(value))
, fCases(std::move(cases)) {}
- String description() const override {
- String result = String::printf("switch (%s) {\n", + fValue->description().c_str());
+ SkString description() const override {
+ SkString result = SkStringPrintf("switch (%s) {\n", + fValue->description().c_str());
for (const auto& c : fCases) {
result += c->description();
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_SWIZZLE
#define SKSL_SWIZZLE
namespace SkSL {
/**
- * Given a type and a swizzle component count, returns the type that will result from swizzling. For
+ * Given a type and a swizzle component count, returns the type that will result from swizzling. For
* instance, swizzling a vec3 with two components will result in a vec2. It is possible to swizzle
* with more components than the source vector, as in 'vec2(1).xxxx'.
*/
ASSERT(fComponents.size() >= 1 && fComponents.size() <= 4);
}
- String description() const override {
- String result = fBase->description() + ".";
+ SkString description() const override {
+ SkString result = fBase->description() + ".";
for (int x : fComponents) {
result += "xyzw"[x];
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_SYMBOL
#define SKSL_SYMBOL
kField_Kind
};
- Symbol(Position position, Kind kind, String name)
+ Symbol(Position position, Kind kind, SkString name)
: INHERITED(position)
, fKind(kind)
, fName(std::move(name)) {}
const Kind fKind;
- const String fName;
+ const SkString fName;
typedef IRNode INHERITED;
};
}
}
-const Symbol* SymbolTable::operator[](const String& name) {
+const Symbol* SymbolTable::operator[](const SkString& name) {
const auto& entry = fSymbols.find(name);
if (entry == fSymbols.end()) {
if (fParent) {
return s;
}
-void SymbolTable::add(const String& name, std::unique_ptr<Symbol> symbol) {
+void SymbolTable::add(const SkString& name, std::unique_ptr<Symbol> symbol) {
this->addWithoutOwnership(name, symbol.get());
fOwnedPointers.push_back(std::move(symbol));
}
-void SymbolTable::addWithoutOwnership(const String& name, const Symbol* symbol) {
+void SymbolTable::addWithoutOwnership(const SkString& name, const Symbol* symbol) {
const auto& existing = fSymbols.find(name);
if (existing == fSymbols.end()) {
fSymbols[name] = symbol;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_SYMBOLTABLE
#define SKSL_SYMBOLTABLE
: fParent(parent)
, fErrorReporter(*errorReporter) {}
- const Symbol* operator[](const String& name);
+ const Symbol* operator[](const SkString& name);
- void add(const String& name, std::unique_ptr<Symbol> symbol);
+ void add(const SkString& name, std::unique_ptr<Symbol> symbol);
- void addWithoutOwnership(const String& name, const Symbol* symbol);
+ void addWithoutOwnership(const SkString& name, const Symbol* symbol);
Symbol* takeOwnership(Symbol* s);
std::vector<std::unique_ptr<Symbol>> fOwnedPointers;
- std::unordered_map<String, const Symbol*> fSymbols;
+ std::unordered_map<SkString, const Symbol*> fSymbols;
ErrorReporter& fErrorReporter;
};
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_TERNARYEXPRESSION
#define SKSL_TERNARYEXPRESSION
ASSERT(fIfTrue->fType == fIfFalse->fType);
}
- String description() const override {
- return "(" + fTest->description() + " ? " + fIfTrue->description() + " : " +
+ SkString description() const override {
+ return "(" + fTest->description() + " ? " + fIfTrue->description() + " : " +
fIfFalse->description() + ")";
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#include "SkSLType.h"
#include "SkSLContext.h"
return false;
}
if (this->kind() == kMatrix_Kind) {
- if (this->columns() == other.columns() &&
+ if (this->columns() == other.columns() &&
this->rows() == other.rows()) {
return this->componentType().determineCoercionCost(other.componentType(), outCost);
}
class Type : public Symbol {
public:
struct Field {
- Field(Modifiers modifiers, String name, const Type* type)
+ Field(Modifiers modifiers, SkString name, const Type* type)
: fModifiers(modifiers)
, fName(std::move(name))
, fType(std::move(type)) {}
- const String description() const {
+ const SkString description() const {
return fType->description() + " " + fName + ";";
}
Modifiers fModifiers;
- String fName;
+ SkString fName;
const Type* fType;
};
// Create an "other" (special) type with the given name. These types cannot be directly
// referenced from user code.
- Type(String name)
+ Type(SkString name)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kOther_Kind) {}
// Create a generic type which maps to the listed types.
- Type(String name, std::vector<const Type*> types)
+ Type(SkString name, std::vector<const Type*> types)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kGeneric_Kind)
, fCoercibleTypes(std::move(types)) {}
// Create a struct type with the given fields.
- Type(Position position, String name, std::vector<Field> fields)
+ Type(Position position, SkString name, std::vector<Field> fields)
: INHERITED(position, kType_Kind, std::move(name))
, fTypeKind(kStruct_Kind)
, fFields(std::move(fields)) {}
// Create a scalar type.
- Type(String name, bool isNumber)
+ Type(SkString name, bool isNumber)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kScalar_Kind)
, fIsNumber(isNumber)
, fRows(1) {}
// Create a scalar type which can be coerced to the listed types.
- Type(String name, bool isNumber, std::vector<const Type*> coercibleTypes)
+ Type(SkString name, bool isNumber, std::vector<const Type*> coercibleTypes)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kScalar_Kind)
, fIsNumber(isNumber)
, fRows(1) {}
// Create a vector type.
- Type(String name, const Type& componentType, int columns)
+ Type(SkString name, const Type& componentType, int columns)
: Type(name, kVector_Kind, componentType, columns) {}
// Create a vector or array type.
- Type(String name, Kind kind, const Type& componentType, int columns)
+ Type(SkString name, Kind kind, const Type& componentType, int columns)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kind)
, fComponentType(&componentType)
, fDimensions(SpvDim1D) {}
// Create a matrix type.
- Type(String name, const Type& componentType, int columns, int rows)
+ Type(SkString name, const Type& componentType, int columns, int rows)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kMatrix_Kind)
, fComponentType(&componentType)
, fDimensions(SpvDim1D) {}
// Create a sampler type.
- Type(String name, SpvDim_ dimensions, bool isDepth, bool isArrayed, bool isMultisampled,
+ Type(SkString name, SpvDim_ dimensions, bool isDepth, bool isArrayed, bool isMultisampled,
bool isSampled)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kSampler_Kind)
, fIsMultisampled(isMultisampled)
, fIsSampled(isSampled) {}
- String name() const {
+ SkString name() const {
return fName;
}
- String description() const override {
+ SkString description() const override {
return fName;
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_TYPEREFERENCE
#define SKSL_TYPEREFERENCE
namespace SkSL {
/**
- * Represents an identifier referring to a type. This is an intermediate value: TypeReferences are
+ * Represents an identifier referring to a type. This is an intermediate value: TypeReferences are
* always eventually replaced by Constructors in valid programs.
*/
struct TypeReference : public Expression {
: INHERITED(position, kTypeReference_Kind, *context.fInvalid_Type)
, fValue(type) {}
- String description() const override {
+ SkString description() const override {
return fValue.name();
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_UNRESOLVEDFUNCTION
#define SKSL_UNRESOLVEDFUNCTION
#endif
}
- virtual String description() const override {
+ virtual SkString description() const override {
return fName;
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_VARDECLARATIONS
#define SKSL_VARDECLARATIONS
/**
* A single variable declaration within a var declaration statement. For instance, the statement
- * 'int x = 2, y[3];' is a VarDeclarations statement containing two individual VarDeclaration
+ * 'int x = 2, y[3];' is a VarDeclarations statement containing two individual VarDeclaration
* instances.
*/
struct VarDeclaration {
, fSizes(std::move(sizes))
, fValue(std::move(value)) {}
- String description() const {
- String result = fVar->fName;
+ SkString description() const {
+ SkString result = fVar->fName;
for (const auto& size : fSizes) {
if (size) {
result += "[" + size->description() + "]";
if (fValue) {
result += " = " + fValue->description();
}
- return result;
+ return result;
}
const Variable* fVar;
* A variable declaration statement, which may consist of one or more individual variables.
*/
struct VarDeclarations : public ProgramElement {
- VarDeclarations(Position position, const Type* baseType,
+ VarDeclarations(Position position, const Type* baseType,
std::vector<VarDeclaration> vars)
: INHERITED(position, kVar_Kind)
, fBaseType(*baseType)
, fVars(std::move(vars)) {}
- String description() const override {
+ SkString description() const override {
if (!fVars.size()) {
- return String();
+ return SkString();
}
- String result = fVars[0].fVar->fModifiers.description() + fBaseType.description() + " ";
- String separator;
+ SkString result = fVars[0].fVar->fModifiers.description() + fBaseType.description() + " ";
+ SkString separator;
for (const auto& var : fVars) {
result += separator;
separator = ", ";
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_VARDECLARATIONSSTATEMENT
#define SKSL_VARDECLARATIONSSTATEMENT
: INHERITED(decl->fPosition, kVarDeclarations_Kind)
, fDeclaration(std::move(decl)) {}
- String description() const override {
+ SkString description() const override {
return fDeclaration->description();
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_VARIABLE
#define SKSL_VARIABLE
kParameter_Storage
};
- Variable(Position position, Modifiers modifiers, String name, const Type& type,
+ Variable(Position position, Modifiers modifiers, SkString name, const Type& type,
Storage storage)
: INHERITED(position, kVariable_Kind, std::move(name))
, fModifiers(modifiers)
, fReadCount(0)
, fWriteCount(0) {}
- virtual String description() const override {
+ virtual SkString description() const override {
return fModifiers.description() + fType.fName + " " + fName;
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_VARIABLEREFERENCE
#define SKSL_VARIABLEREFERENCE
fRefKind = refKind;
}
- String description() const override {
+ SkString description() const override {
return fVariable.fName;
}
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-
+
#ifndef SKSL_WHILESTATEMENT
#define SKSL_WHILESTATEMENT
* A 'while' loop.
*/
struct WhileStatement : public Statement {
- WhileStatement(Position position, std::unique_ptr<Expression> test,
+ WhileStatement(Position position, std::unique_ptr<Expression> test,
std::unique_ptr<Statement> statement)
: INHERITED(position, kWhile_Kind)
, fTest(std::move(test))
, fStatement(std::move(statement)) {}
- String description() const override {
+ SkString description() const override {
return "while (" + fTest->description() + ") " + fStatement->description();
}
static void test_failure(skiatest::Reporter* r, const char* src, const char* error) {
SkSL::Compiler compiler;
+ SkDynamicMemoryWStream out;
SkSL::Program::Settings settings;
sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
settings.fCaps = caps.get();
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(SkSL::Program::kFragment_Kind,
SkString(src), settings);
if (program) {
- SkSL::String ignored;
+ SkString ignored;
compiler.toSPIRV(*program, &ignored);
}
- SkSL::String skError(error);
+ SkString skError(error);
if (compiler.errorText() != skError) {
SkDebugf("SKSL ERROR:\n source: %s\n expected: %s received: %s", src, error,
compiler.errorText().c_str());
static void test_success(skiatest::Reporter* r, const char* src) {
SkSL::Compiler compiler;
+ SkDynamicMemoryWStream out;
SkSL::Program::Settings settings;
sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
settings.fCaps = caps.get();
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(SkSL::Program::kFragment_Kind,
SkString(src), settings);
REPORTER_ASSERT(r, program);
- SkSL::String ignored;
+ SkString ignored;
REPORTER_ASSERT(r, compiler.toSPIRV(*program, &ignored));
}
const char* expected, SkSL::Program::Inputs* inputs,
SkSL::Program::Kind kind = SkSL::Program::kFragment_Kind) {
SkSL::Compiler compiler;
- SkSL::String output;
+ SkString output;
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(kind, SkString(src), settings);
if (!program) {
SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str());
*inputs = program->fInputs;
REPORTER_ASSERT(r, compiler.toGLSL(*program, &output));
if (program) {
- SkSL::String skExpected(expected);
+ SkString skExpected(expected);
if (output != skExpected) {
SkDebugf("GLSL MISMATCH:\nsource:\n%s\n\nexpected:\n'%s'\n\nreceived:\n'%s'", src,
expected, output.c_str());