From 9e1138d56665d13641f8805cd72ae81adc255f79 Mon Sep 17 00:00:00 2001 From: Ethan Nicholas Date: Mon, 21 Nov 2016 10:39:35 -0500 Subject: re-land of switched skslc from std::string to SkString BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5084 Change-Id: Ib21c30afc0d8483392b417e660b7fecfcc30e617 Reviewed-on: https://skia-review.googlesource.com/5084 Reviewed-by: Ethan Nicholas Reviewed-by: Brian Salomon Commit-Queue: Ethan Nicholas --- src/gpu/gl/builders/GrGLShaderStringBuilder.cpp | 28 +- src/gpu/vk/GrVkUtil.cpp | 4 +- src/sksl/SkSLCodeGenerator.h | 4 +- src/sksl/SkSLCompiler.cpp | 53 +- src/sksl/SkSLCompiler.h | 24 +- src/sksl/SkSLContext.h | 210 +++--- src/sksl/SkSLErrorReporter.h | 6 +- src/sksl/SkSLGLSLCodeGenerator.cpp | 45 +- src/sksl/SkSLGLSLCodeGenerator.h | 13 +- src/sksl/SkSLIRGenerator.cpp | 34 +- src/sksl/SkSLIRGenerator.h | 4 +- src/sksl/SkSLMain.cpp | 34 +- src/sksl/SkSLParser.cpp | 37 +- src/sksl/SkSLParser.h | 15 +- src/sksl/SkSLPosition.h | 2 +- src/sksl/SkSLSPIRVCodeGenerator.cpp | 923 ++++++++++++------------ src/sksl/SkSLSPIRVCodeGenerator.h | 130 ++-- src/sksl/SkSLToken.h | 80 +- src/sksl/SkSLUtil.cpp | 92 ++- src/sksl/SkSLUtil.h | 52 +- src/sksl/ast/SkSLASTBinaryExpression.h | 3 +- src/sksl/ast/SkSLASTBlock.h | 4 +- src/sksl/ast/SkSLASTBoolLiteral.h | 4 +- src/sksl/ast/SkSLASTBreakStatement.h | 4 +- src/sksl/ast/SkSLASTCallSuffix.h | 7 +- src/sksl/ast/SkSLASTContinueStatement.h | 4 +- src/sksl/ast/SkSLASTDiscardStatement.h | 4 +- src/sksl/ast/SkSLASTDoStatement.h | 2 +- src/sksl/ast/SkSLASTExpressionStatement.h | 2 +- src/sksl/ast/SkSLASTExtension.h | 6 +- src/sksl/ast/SkSLASTFieldSuffix.h | 6 +- src/sksl/ast/SkSLASTFloatLiteral.h | 2 +- src/sksl/ast/SkSLASTForStatement.h | 4 +- src/sksl/ast/SkSLASTFunction.h | 8 +- src/sksl/ast/SkSLASTIdentifier.h | 6 +- src/sksl/ast/SkSLASTIfStatement.h | 4 +- src/sksl/ast/SkSLASTIndexSuffix.h | 4 +- src/sksl/ast/SkSLASTIntLiteral.h | 2 +- src/sksl/ast/SkSLASTInterfaceBlock.h | 14 +- src/sksl/ast/SkSLASTLayout.h | 10 +- src/sksl/ast/SkSLASTModifiers.h | 4 +- src/sksl/ast/SkSLASTModifiersDeclaration.h | 2 +- src/sksl/ast/SkSLASTNode.h | 5 +- src/sksl/ast/SkSLASTParameter.h | 8 +- src/sksl/ast/SkSLASTPrecision.h | 12 +- src/sksl/ast/SkSLASTPrefixExpression.h | 2 +- src/sksl/ast/SkSLASTReturnStatement.h | 4 +- src/sksl/ast/SkSLASTSuffix.h | 6 +- src/sksl/ast/SkSLASTSuffixExpression.h | 2 +- src/sksl/ast/SkSLASTTernaryExpression.h | 2 +- src/sksl/ast/SkSLASTType.h | 6 +- src/sksl/ast/SkSLASTVarDeclaration.h | 14 +- src/sksl/ast/SkSLASTVarDeclarationStatement.h | 2 +- src/sksl/ast/SkSLASTWhileStatement.h | 2 +- src/sksl/ir/SkSLBinaryExpression.h | 2 +- src/sksl/ir/SkSLBlock.h | 8 +- src/sksl/ir/SkSLBoolLiteral.h | 4 +- src/sksl/ir/SkSLBreakStatement.h | 4 +- src/sksl/ir/SkSLConstructor.h | 6 +- src/sksl/ir/SkSLContinueStatement.h | 4 +- src/sksl/ir/SkSLDiscardStatement.h | 4 +- src/sksl/ir/SkSLDoStatement.h | 2 +- src/sksl/ir/SkSLExpressionStatement.h | 2 +- src/sksl/ir/SkSLExtension.h | 6 +- src/sksl/ir/SkSLField.h | 2 +- src/sksl/ir/SkSLFieldAccess.h | 2 +- src/sksl/ir/SkSLFloatLiteral.h | 2 +- src/sksl/ir/SkSLForStatement.h | 4 +- src/sksl/ir/SkSLFunctionCall.h | 6 +- src/sksl/ir/SkSLFunctionDeclaration.h | 8 +- src/sksl/ir/SkSLFunctionDefinition.h | 2 +- src/sksl/ir/SkSLFunctionReference.h | 4 +- src/sksl/ir/SkSLIRNode.h | 2 +- src/sksl/ir/SkSLIfStatement.h | 4 +- src/sksl/ir/SkSLIndexExpression.h | 2 +- src/sksl/ir/SkSLIntLiteral.h | 2 +- src/sksl/ir/SkSLInterfaceBlock.h | 4 +- src/sksl/ir/SkSLLayout.h | 8 +- src/sksl/ir/SkSLModifiers.h | 4 +- src/sksl/ir/SkSLModifiersDeclaration.h | 2 +- src/sksl/ir/SkSLPostfixExpression.h | 2 +- src/sksl/ir/SkSLPrefixExpression.h | 2 +- src/sksl/ir/SkSLReturnStatement.h | 4 +- src/sksl/ir/SkSLSwizzle.h | 4 +- src/sksl/ir/SkSLSymbol.h | 4 +- src/sksl/ir/SkSLSymbolTable.cpp | 6 +- src/sksl/ir/SkSLSymbolTable.h | 8 +- src/sksl/ir/SkSLTernaryExpression.h | 2 +- src/sksl/ir/SkSLType.h | 28 +- src/sksl/ir/SkSLTypeReference.h | 2 +- src/sksl/ir/SkSLUnresolvedFunction.h | 2 +- src/sksl/ir/SkSLVarDeclarations.h | 13 +- src/sksl/ir/SkSLVarDeclarationsStatement.h | 2 +- src/sksl/ir/SkSLVariable.h | 4 +- src/sksl/ir/SkSLVariableReference.h | 2 +- src/sksl/ir/SkSLWhileStatement.h | 2 +- 96 files changed, 1107 insertions(+), 1041 deletions(-) (limited to 'src') diff --git a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp index 1e42259128..86df089d82 100644 --- a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp +++ b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp @@ -21,18 +21,19 @@ static const bool c_PrintShaders{false}; static void print_shader_source(const char** strings, int* lengths, int count); -static void dump_string(std::string s) { +static void dump_string(SkString s) { // on Android, SkDebugf only displays the first 1K characters of output, which results in // incomplete shader source code. Print each line individually to avoid this problem. - size_t index = 0; + const char* chars = s.c_str(); for (;;) { - size_t next = s.find("\n", index); - if (next == std::string::npos) { - SkDebugf("%s", s.substr(index).c_str()); - break; + const char* next = strchr(chars, '\n'); + if (next) { + next++; + SkDebugf("%s", SkString(chars, next - chars).c_str()); + chars = next; } else { - SkDebugf("%s", s.substr(index, next - index + 1).c_str()); - index = next + 1; + SkDebugf("%s", chars); + break; } } } @@ -52,23 +53,22 @@ GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx, return 0; } - std::string sksl; + SkString sksl; #ifdef SK_DEBUG - SkString prettySource = GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths, count, false); - sksl = std::string(prettySource.c_str()); + sksl = GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths, count, false); #else for (int i = 0; i < count; i++) { sksl.append(strings[i], lengths[i]); } #endif - std::string glsl; + SkString glsl; SkSL::Compiler& compiler = *glCtx.compiler(); SkASSERT(type == GR_GL_VERTEX_SHADER || type == GR_GL_FRAGMENT_SHADER); SkDEBUGCODE(bool result = )compiler.toGLSL(type == GR_GL_VERTEX_SHADER ? SkSL::Program::kVertex_Kind : SkSL::Program::kFragment_Kind, - std::string(sksl.c_str()), + sksl, *glCtx.caps()->glslCaps(), &glsl); #ifdef SK_DEBUG @@ -82,7 +82,7 @@ GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx, #endif const char* glslChars = glsl.c_str(); - GrGLint glslLength = (GrGLint) glsl.length(); + GrGLint glslLength = (GrGLint) glsl.size(); GR_GL_CALL(gli, ShaderSource(shaderId, 1, &glslChars, &glslLength)); // If tracing is enabled in chrome then we pretty print diff --git a/src/gpu/vk/GrVkUtil.cpp b/src/gpu/vk/GrVkUtil.cpp index 1d93e8d4e5..4446dfe6c2 100644 --- a/src/gpu/vk/GrVkUtil.cpp +++ b/src/gpu/vk/GrVkUtil.cpp @@ -292,7 +292,7 @@ bool GrCompileVkShaderModule(const GrVkGpu* gpu, moduleCreateInfo.flags = 0; #if USE_SKSL - std::string code; + SkString code; #else shaderc_compilation_result_t result = nullptr; #endif @@ -304,7 +304,7 @@ bool GrCompileVkShaderModule(const GrVkGpu* gpu, #if USE_SKSL bool result = gpu->shaderCompiler()->toSPIRV(vk_shader_stage_to_skiasl_kind(stage), - std::string(shaderString), + SkString(shaderString), &code); if (!result) { SkDebugf("%s\n", gpu->shaderCompiler()->errorText().c_str()); diff --git a/src/sksl/SkSLCodeGenerator.h b/src/sksl/SkSLCodeGenerator.h index 7bf857d0ba..211cf0aadf 100644 --- a/src/sksl/SkSLCodeGenerator.h +++ b/src/sksl/SkSLCodeGenerator.h @@ -9,8 +9,6 @@ #define SKSL_CODEGENERATOR #include "ir/SkSLProgram.h" -#include -#include namespace SkSL { @@ -22,7 +20,7 @@ class CodeGenerator { public: virtual ~CodeGenerator() {} - virtual void generateCode(const Program& program, std::ostream& out) = 0; + virtual void generateCode(const Program& program, SkWStream& out) = 0; }; } // namespace diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp index 510d610a6e..905eff4e28 100644 --- a/src/sksl/SkSLCompiler.cpp +++ b/src/sksl/SkSLCompiler.cpp @@ -7,9 +7,6 @@ #include "SkSLCompiler.h" -#include -#include - #include "ast/SkSLASTPrecision.h" #include "SkSLCFGGenerator.h" #include "SkSLIRGenerator.h" @@ -71,17 +68,17 @@ Compiler::Compiler() ADD_TYPE(BVec3); ADD_TYPE(BVec4); ADD_TYPE(Mat2x2); - types->addWithoutOwnership("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("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("mat4x4", fContext.fMat4x4_Type.get()); + types->addWithoutOwnership(SkString("mat4x4"), fContext.fMat4x4_Type.get()); ADD_TYPE(GenType); ADD_TYPE(GenDType); ADD_TYPE(GenIType); @@ -140,7 +137,7 @@ Compiler::Compiler() Modifiers::Flag ignored1; std::vector> ignored2; - this->internalConvertProgram(SKSL_INCLUDE, &ignored1, &ignored2); + this->internalConvertProgram(SkString(SKSL_INCLUDE), &ignored1, &ignored2); fIRGenerator->fSymbolTable->markAllFunctionsBuiltin(); ASSERT(!fErrorCount); } @@ -289,7 +286,7 @@ void Compiler::scanCFG(const FunctionDefinition& f) { for (size_t i = 0; i < cfg.fBlocks.size(); i++) { if (i != cfg.fStart && !cfg.fBlocks[i].fEntrances.size() && cfg.fBlocks[i].fNodes.size()) { - this->error(cfg.fBlocks[i].fNodes[0].fNode->fPosition, "unreachable"); + this->error(cfg.fBlocks[i].fNodes[0].fNode->fPosition, SkString("unreachable")); } } if (fErrorCount) { @@ -318,12 +315,12 @@ void Compiler::scanCFG(const FunctionDefinition& f) { // check for missing return if (f.fDeclaration.fReturnType != *fContext.fVoid_Type) { if (cfg.fBlocks[cfg.fExit].fEntrances.size()) { - this->error(f.fPosition, "function can exit without returning a value"); + this->error(f.fPosition, SkString("function can exit without returning a value")); } } } -void Compiler::internalConvertProgram(std::string text, +void Compiler::internalConvertProgram(SkString text, Modifiers::Flag* defaultPrecision, std::vector>* result) { Parser parser(text, *fTypes, *this); @@ -386,7 +383,7 @@ void Compiler::internalConvertProgram(std::string text, } } -std::unique_ptr Compiler::convertProgram(Program::Kind kind, std::string text) { +std::unique_ptr Compiler::convertProgram(Program::Kind kind, SkString text) { fErrorText = ""; fErrorCount = 0; fIRGenerator->pushSymbolTable(); @@ -394,10 +391,10 @@ std::unique_ptr Compiler::convertProgram(Program::Kind kind, std::strin Modifiers::Flag ignored; switch (kind) { case Program::kVertex_Kind: - this->internalConvertProgram(SKSL_VERT_INCLUDE, &ignored, &elements); + this->internalConvertProgram(SkString(SKSL_VERT_INCLUDE), &ignored, &elements); break; case Program::kFragment_Kind: - this->internalConvertProgram(SKSL_FRAG_INCLUDE, &ignored, &elements); + this->internalConvertProgram(SkString(SKSL_FRAG_INCLUDE), &ignored, &elements); break; } fIRGenerator->fSymbolTable->markAllFunctionsBuiltin(); @@ -410,13 +407,13 @@ std::unique_ptr Compiler::convertProgram(Program::Kind kind, std::strin return result; } -void Compiler::error(Position position, std::string msg) { +void Compiler::error(Position position, SkString msg) { fErrorCount++; fErrorText += "error: " + position.description() + ": " + msg.c_str() + "\n"; } -std::string Compiler::errorText() { - std::string result = fErrorText; +SkString Compiler::errorText() { + SkString result = fErrorText; return result; } @@ -430,42 +427,42 @@ void Compiler::writeErrorCount() { } } -bool Compiler::toSPIRV(Program::Kind kind, const std::string& text, std::ostream& out) { +bool Compiler::toSPIRV(Program::Kind kind, const SkString& text, SkWStream& out) { auto program = this->convertProgram(kind, text); if (fErrorCount == 0) { SkSL::SPIRVCodeGenerator cg(&fContext); cg.generateCode(*program.get(), out); - ASSERT(!out.rdstate()); } return fErrorCount == 0; } -bool Compiler::toSPIRV(Program::Kind kind, const std::string& text, std::string* out) { - std::stringstream buffer; +bool Compiler::toSPIRV(Program::Kind kind, const SkString& text, SkString* out) { + SkDynamicMemoryWStream buffer; bool result = this->toSPIRV(kind, text, buffer); if (result) { - *out = buffer.str(); + sk_sp data(buffer.detachAsData()); + *out = SkString((const char*) data->data(), data->size()); } return result; } -bool Compiler::toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps, - std::ostream& out) { +bool Compiler::toGLSL(Program::Kind kind, const SkString& text, const GrGLSLCaps& caps, + SkWStream& out) { auto program = this->convertProgram(kind, text); if (fErrorCount == 0) { SkSL::GLSLCodeGenerator cg(&fContext, &caps); cg.generateCode(*program.get(), out); - ASSERT(!out.rdstate()); } return fErrorCount == 0; } -bool Compiler::toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps, - std::string* out) { - std::stringstream buffer; +bool Compiler::toGLSL(Program::Kind kind, const SkString& text, const GrGLSLCaps& caps, + SkString* out) { + SkDynamicMemoryWStream buffer; bool result = this->toGLSL(kind, text, caps, buffer); if (result) { - *out = buffer.str(); + sk_sp data(buffer.detachAsData()); + *out = SkString((const char*) data->data(), data->size()); } return result; } diff --git a/src/sksl/SkSLCompiler.h b/src/sksl/SkSLCompiler.h index e69db5997d..e1bc052fef 100644 --- a/src/sksl/SkSLCompiler.h +++ b/src/sksl/SkSLCompiler.h @@ -37,21 +37,21 @@ public: ~Compiler(); - std::unique_ptr convertProgram(Program::Kind kind, std::string text); + std::unique_ptr convertProgram(Program::Kind kind, SkString text); - bool toSPIRV(Program::Kind kind, const std::string& text, std::ostream& out); + bool toSPIRV(Program::Kind kind, const SkString& text, SkWStream& out); - bool toSPIRV(Program::Kind kind, const std::string& text, std::string* out); + bool toSPIRV(Program::Kind kind, const SkString& text, SkString* out); - bool toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps, - std::ostream& out); + bool toGLSL(Program::Kind kind, const SkString& text, const GrGLSLCaps& caps, + SkWStream& out); - bool toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps, - std::string* out); + bool toGLSL(Program::Kind kind, const SkString& text, const GrGLSLCaps& caps, + SkString* out); - void error(Position position, std::string msg) override; + void error(Position position, SkString msg) override; - std::string errorText(); + SkString errorText(); void writeErrorCount(); @@ -66,17 +66,17 @@ private: void scanCFG(const FunctionDefinition& f); - void internalConvertProgram(std::string text, + void internalConvertProgram(SkString text, Modifiers::Flag* defaultPrecision, std::vector>* result); std::shared_ptr fTypes; IRGenerator* fIRGenerator; - std::string fSkiaVertText; // FIXME store parsed version instead + SkString fSkiaVertText; // FIXME store parsed version instead Context fContext; int fErrorCount; - std::string fErrorText; + SkString fErrorText; }; } // namespace diff --git a/src/sksl/SkSLContext.h b/src/sksl/SkSLContext.h index a42a4cc855..05e08f24cb 100644 --- a/src/sksl/SkSLContext.h +++ b/src/sksl/SkSLContext.h @@ -19,114 +19,120 @@ namespace SkSL { class Context { public: Context() - : fInvalid_Type(new Type("")) - , fVoid_Type(new Type("void")) - , fDouble_Type(new Type("double", true)) - , fDVec2_Type(new Type("dvec2", *fDouble_Type, 2)) - , fDVec3_Type(new Type("dvec3", *fDouble_Type, 3)) - , fDVec4_Type(new Type("dvec4", *fDouble_Type, 4)) - , fFloat_Type(new Type("float", true, { fDouble_Type.get() })) - , fVec2_Type(new Type("vec2", *fFloat_Type, 2)) - , fVec3_Type(new Type("vec3", *fFloat_Type, 3)) - , fVec4_Type(new Type("vec4", *fFloat_Type, 4)) - , fUInt_Type(new Type("uint", true, { fFloat_Type.get(), fDouble_Type.get() })) - , fUVec2_Type(new Type("uvec2", *fUInt_Type, 2)) - , fUVec3_Type(new Type("uvec3", *fUInt_Type, 3)) - , fUVec4_Type(new Type("uvec4", *fUInt_Type, 4)) - , fInt_Type(new Type("int", true, { fUInt_Type.get(), fFloat_Type.get(), fDouble_Type.get() })) - , fIVec2_Type(new Type("ivec2", *fInt_Type, 2)) - , fIVec3_Type(new Type("ivec3", *fInt_Type, 3)) - , fIVec4_Type(new Type("ivec4", *fInt_Type, 4)) - , fBool_Type(new Type("bool", false)) - , fBVec2_Type(new Type("bvec2", *fBool_Type, 2)) - , fBVec3_Type(new Type("bvec3", *fBool_Type, 3)) - , fBVec4_Type(new Type("bvec4", *fBool_Type, 4)) - , fMat2x2_Type(new Type("mat2", *fFloat_Type, 2, 2)) - , fMat2x3_Type(new Type("mat2x3", *fFloat_Type, 2, 3)) - , fMat2x4_Type(new Type("mat2x4", *fFloat_Type, 2, 4)) - , fMat3x2_Type(new Type("mat3x2", *fFloat_Type, 3, 2)) - , fMat3x3_Type(new Type("mat3", *fFloat_Type, 3, 3)) - , fMat3x4_Type(new Type("mat3x4", *fFloat_Type, 3, 4)) - , fMat4x2_Type(new Type("mat4x2", *fFloat_Type, 4, 2)) - , fMat4x3_Type(new Type("mat4x3", *fFloat_Type, 4, 3)) - , fMat4x4_Type(new Type("mat4", *fFloat_Type, 4, 4)) - , fDMat2x2_Type(new Type("dmat2", *fFloat_Type, 2, 2)) - , fDMat2x3_Type(new Type("dmat2x3", *fFloat_Type, 2, 3)) - , fDMat2x4_Type(new Type("dmat2x4", *fFloat_Type, 2, 4)) - , fDMat3x2_Type(new Type("dmat3x2", *fFloat_Type, 3, 2)) - , fDMat3x3_Type(new Type("dmat3", *fFloat_Type, 3, 3)) - , fDMat3x4_Type(new Type("dmat3x4", *fFloat_Type, 3, 4)) - , fDMat4x2_Type(new Type("dmat4x2", *fFloat_Type, 4, 2)) - , fDMat4x3_Type(new Type("dmat4x3", *fFloat_Type, 4, 3)) - , fDMat4x4_Type(new Type("dmat4", *fFloat_Type, 4, 4)) - , fSampler1D_Type(new Type("sampler1D", SpvDim1D, false, false, false, true)) - , fSampler2D_Type(new Type("sampler2D", SpvDim2D, false, false, false, true)) - , fSampler3D_Type(new Type("sampler3D", SpvDim3D, false, false, false, true)) - , fSamplerExternalOES_Type(new Type("samplerExternalOES", SpvDim2D, false, false, false, true)) - , fSamplerCube_Type(new Type("samplerCube")) - , fSampler2DRect_Type(new Type("sampler2DRect")) - , fSampler1DArray_Type(new Type("sampler1DArray")) - , fSampler2DArray_Type(new Type("sampler2DArray")) - , fSamplerCubeArray_Type(new Type("samplerCubeArray")) - , fSamplerBuffer_Type(new Type("samplerBuffer")) - , fSampler2DMS_Type(new Type("sampler2DMS")) - , fSampler2DMSArray_Type(new Type("sampler2DMSArray")) - , fSampler1DShadow_Type(new Type("sampler1DShadow")) - , fSampler2DShadow_Type(new Type("sampler2DShadow")) - , fSamplerCubeShadow_Type(new Type("samplerCubeShadow")) - , fSampler2DRectShadow_Type(new Type("sampler2DRectShadow")) - , fSampler1DArrayShadow_Type(new Type("sampler1DArrayShadow")) - , fSampler2DArrayShadow_Type(new Type("sampler2DArrayShadow")) - , fSamplerCubeArrayShadow_Type(new Type("samplerCubeArrayShadow")) + : fInvalid_Type(new Type(SkString(""))) + , 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(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(SkString("samplerCube"))) + , fSampler2DRect_Type(new Type(SkString("sampler2DRect"))) + , 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("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("image2D", SpvDim2D, false, false, false, true)) - , fIImage2D_Type(new Type("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 figure out what we're supposed to do with the gsampler et al. types) - , fGSampler1D_Type(new Type("$gsampler1D", static_type(*fSampler1D_Type))) - , fGSampler2D_Type(new Type("$gsampler2D", static_type(*fSampler2D_Type))) - , fGSampler3D_Type(new Type("$gsampler3D", static_type(*fSampler3D_Type))) - , fGSamplerCube_Type(new Type("$gsamplerCube", static_type(*fSamplerCube_Type))) - , fGSampler2DRect_Type(new Type("$gsampler2DRect", static_type(*fSampler2DRect_Type))) - , fGSampler1DArray_Type(new Type("$gsampler1DArray", static_type(*fSampler1DArray_Type))) - , fGSampler2DArray_Type(new Type("$gsampler2DArray", static_type(*fSampler2DArray_Type))) - , fGSamplerCubeArray_Type(new Type("$gsamplerCubeArray", static_type(*fSamplerCubeArray_Type))) - , fGSamplerBuffer_Type(new Type("$gsamplerBuffer", static_type(*fSamplerBuffer_Type))) - , fGSampler2DMS_Type(new Type("$gsampler2DMS", static_type(*fSampler2DMS_Type))) - , fGSampler2DMSArray_Type(new Type("$gsampler2DMSArray", static_type(*fSampler2DMSArray_Type))) - , fGSampler2DArrayShadow_Type(new Type("$gsampler2DArrayShadow", + , 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(SkString("$gsampler2DArray"), + static_type(*fSampler2DArray_Type))) + , fGSamplerCubeArray_Type(new Type(SkString("$gsamplerCubeArray"), + static_type(*fSamplerCubeArray_Type))) + , 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(SkString("$gsampler2DArrayShadow"), static_type(*fSampler2DArrayShadow_Type))) - , fGSamplerCubeArrayShadow_Type(new Type("$gsamplerCubeArrayShadow", + , fGSamplerCubeArrayShadow_Type(new Type(SkString("$gsamplerCubeArrayShadow"), static_type(*fSamplerCubeArrayShadow_Type))) - , fGenType_Type(new Type("$genType", { fFloat_Type.get(), fVec2_Type.get(), fVec3_Type.get(), - fVec4_Type.get() })) - , fGenDType_Type(new Type("$genDType", { fDouble_Type.get(), fDVec2_Type.get(), - fDVec3_Type.get(), fDVec4_Type.get() })) - , fGenIType_Type(new Type("$genIType", { fInt_Type.get(), fIVec2_Type.get(), fIVec3_Type.get(), - fIVec4_Type.get() })) - , fGenUType_Type(new Type("$genUType", { fUInt_Type.get(), fUVec2_Type.get(), fUVec3_Type.get(), - fUVec4_Type.get() })) - , fGenBType_Type(new Type("$genBType", { fBool_Type.get(), fBVec2_Type.get(), fBVec3_Type.get(), - fBVec4_Type.get() })) - , fMat_Type(new Type("$mat")) - , fVec_Type(new Type("$vec", { fInvalid_Type.get(), fVec2_Type.get(), fVec3_Type.get(), - fVec4_Type.get() })) - , fGVec_Type(new Type("$gvec")) - , fGVec2_Type(new Type("$gvec2")) - , fGVec3_Type(new Type("$gvec3")) - , fGVec4_Type(new Type("$gvec4", static_type(*fVec4_Type))) - , fDVec_Type(new Type("$dvec", { fInvalid_Type.get(), fDVec2_Type.get(), fDVec3_Type.get(), - fDVec4_Type.get() })) - , fIVec_Type(new Type("$ivec", { fInvalid_Type.get(), fIVec2_Type.get(), fIVec3_Type.get(), - fIVec4_Type.get() })) - , fUVec_Type(new Type("$uvec", { fInvalid_Type.get(), fUVec2_Type.get(), fUVec3_Type.get(), - fUVec4_Type.get() })) - , fBVec_Type(new Type("$bvec", { fInvalid_Type.get(), fBVec2_Type.get(), fBVec3_Type.get(), - fBVec4_Type.get() })) + , fGenType_Type(new Type(SkString("$genType"), { fFloat_Type.get(), fVec2_Type.get(), + fVec3_Type.get(), fVec4_Type.get() })) + , fGenDType_Type(new Type(SkString("$genDType"), { fDouble_Type.get(), fDVec2_Type.get(), + fDVec3_Type.get(), fDVec4_Type.get() })) + , fGenIType_Type(new Type(SkString("$genIType"), { fInt_Type.get(), fIVec2_Type.get(), + fIVec3_Type.get(), fIVec4_Type.get() })) + , fGenUType_Type(new Type(SkString("$genUType"), { fUInt_Type.get(), fUVec2_Type.get(), + fUVec3_Type.get(), fUVec4_Type.get() })) + , fGenBType_Type(new Type(SkString("$genBType"), { fBool_Type.get(), fBVec2_Type.get(), + fBVec3_Type.get(), fBVec4_Type.get() })) + , fMat_Type(new Type(SkString("$mat"))) + , fVec_Type(new Type(SkString("$vec"), { fInvalid_Type.get(), fVec2_Type.get(), + fVec3_Type.get(), fVec4_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(SkString("$ivec"), { fInvalid_Type.get(), fIVec2_Type.get(), + fIVec3_Type.get(), fIVec4_Type.get() })) + , fUVec_Type(new Type(SkString("$uvec"), { fInvalid_Type.get(), fUVec2_Type.get(), + fUVec3_Type.get(), fUVec4_Type.get() })) + , fBVec_Type(new Type(SkString("$bvec"), { fInvalid_Type.get(), fBVec2_Type.get(), + fBVec3_Type.get(), fBVec4_Type.get() })) , fDefined_Expression(new Defined(*fInvalid_Type)) {} static std::vector static_type(const Type& t) { @@ -252,8 +258,8 @@ private: Defined(const Type& type) : INHERITED(Position(), kDefined_Kind, type) {} - virtual std::string description() const override { - return ""; + virtual SkString description() const override { + return SkString(""); } typedef Expression INHERITED; diff --git a/src/sksl/SkSLErrorReporter.h b/src/sksl/SkSLErrorReporter.h index 26b44711c3..585a97cc51 100644 --- a/src/sksl/SkSLErrorReporter.h +++ b/src/sksl/SkSLErrorReporter.h @@ -19,7 +19,11 @@ class ErrorReporter { public: virtual ~ErrorReporter() {} - virtual void error(Position position, std::string msg) = 0; + void error(Position position, const char* msg) { + this->error(position, SkString(msg)); + } + + virtual void error(Position position, SkString msg) = 0; }; } // namespace diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp index 1252f86466..553626127b 100644 --- a/src/sksl/SkSLGLSLCodeGenerator.cpp +++ b/src/sksl/SkSLGLSLCodeGenerator.cpp @@ -27,24 +27,24 @@ void GLSLCodeGenerator::write(const char* s) { } if (fAtLineStart) { for (int i = 0; i < fIndentation; i++) { - *fOut << " "; + fOut->writeText(" "); } } - *fOut << s; + fOut->writeText(s); fAtLineStart = false; } void GLSLCodeGenerator::writeLine(const char* s) { this->write(s); - *fOut << "\n"; + fOut->writeText("\n"); fAtLineStart = true; } -void GLSLCodeGenerator::write(const std::string& s) { +void GLSLCodeGenerator::write(const SkString& s) { this->write(s.c_str()); } -void GLSLCodeGenerator::writeLine(const std::string& s) { +void GLSLCodeGenerator::writeLine(const SkString& s) { this->writeLine(s.c_str()); } @@ -138,8 +138,8 @@ static bool is_abs(Expression& expr) { // Tegra3 compiler bug. void GLSLCodeGenerator::writeMinAbsHack(Expression& absExpr, Expression& otherExpr) { ASSERT(!fCaps.canUseMinAndAbsTogether()); - std::string tmpVar1 = "minAbsHackVar" + to_string(fVarCount++); - std::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 + " = "); @@ -179,7 +179,9 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) { if (!fFoundDerivatives && (c.fFunction.fName == "dFdx" || c.fFunction.fName == "dFdy") && c.fFunction.fBuiltin && fCaps.shaderDerivativeExtensionString()) { ASSERT(fCaps.shaderDerivativeSupport()); - fHeader << "#extension " << fCaps.shaderDerivativeExtensionString() << " : require\n"; + fHeader.writeText("#extension "); + fHeader.writeText(fCaps.shaderDerivativeExtensionString()); + fHeader.writeText(" : require\n"); fFoundDerivatives = true; } this->write(c.fFunction.fName + "("); @@ -373,8 +375,8 @@ void GLSLCodeGenerator::writeFunction(const FunctionDefinition& f) { this->writeLine(") {"); fFunctionHeader = ""; - std::ostream* oldOut = fOut; - std::stringstream buffer; + SkWStream* oldOut = fOut; + SkDynamicMemoryWStream buffer; fOut = &buffer; fIndentation++; for (const auto& s : f.fBody->fStatements) { @@ -386,7 +388,8 @@ void GLSLCodeGenerator::writeFunction(const FunctionDefinition& f) { fOut = oldOut; this->write(fFunctionHeader); - this->write(buffer.str()); + sk_sp data(buffer.detachAsData()); + this->write(SkString((const char*) data->data(), data->size())); } void GLSLCodeGenerator::writeModifiers(const Modifiers& modifiers, @@ -397,8 +400,8 @@ void GLSLCodeGenerator::writeModifiers(const Modifiers& modifiers, if (modifiers.fFlags & Modifiers::kFlat_Flag) { this->write("flat "); } - std::string layout = modifiers.fLayout.description(); - if (layout.length()) { + SkString layout = modifiers.fLayout.description(); + if (layout.size()) { this->write(layout + " "); } if ((modifiers.fFlags & Modifiers::kIn_Flag) && @@ -457,11 +460,11 @@ void GLSLCodeGenerator::writeVarDeclarations(const VarDeclarations& decl, bool g ASSERT(decl.fVars.size() > 0); this->writeModifiers(decl.fVars[0].fVar->fModifiers, global); this->writeType(decl.fBaseType); - std::string separator = " "; + SkString separator(" "); for (const auto& var : decl.fVars) { ASSERT(var.fVar->fModifiers == decl.fVars[0].fVar->fModifiers); this->write(separator); - separator = ", "; + separator = SkString(", "); this->write(var.fVar->fName); for (const auto& size : var.fSizes) { this->write("["); @@ -476,7 +479,9 @@ void GLSLCodeGenerator::writeVarDeclarations(const VarDeclarations& decl, bool g } if (!fFoundImageDecl && var.fVar->fType == *fContext.fImage2D_Type) { if (fCaps.imageLoadStoreExtensionString()) { - fHeader << "#extension " << fCaps.imageLoadStoreExtensionString() << " : require\n"; + fHeader.writeText("#extension "); + fHeader.writeText(fCaps.imageLoadStoreExtensionString()); + fHeader.writeText(" : require\n"); } fFoundImageDecl = true; } @@ -589,7 +594,7 @@ void GLSLCodeGenerator::writeReturnStatement(const ReturnStatement& r) { this->write(";"); } -void GLSLCodeGenerator::generateCode(const Program& program, std::ostream& out) { +void GLSLCodeGenerator::generateCode(const Program& program, SkWStream& out) { ASSERT(fOut == nullptr); fOut = &fHeader; fProgramKind = program.fKind; @@ -600,7 +605,7 @@ void GLSLCodeGenerator::generateCode(const Program& program, std::ostream& out) this->writeExtension((Extension&) *e); } } - std::stringstream body; + SkDynamicMemoryWStream body; fOut = &body; if (fCaps.usesPrecisionModifiers()) { this->write("precision "); @@ -660,8 +665,8 @@ void GLSLCodeGenerator::generateCode(const Program& program, std::ostream& out) } fOut = nullptr; - out << fHeader.str(); - out << body.str(); + write_data(*fHeader.detachAsData(), out); + write_data(*body.detachAsData(), out); } } diff --git a/src/sksl/SkSLGLSLCodeGenerator.h b/src/sksl/SkSLGLSLCodeGenerator.h index 16d6192a71..b8cb34e84f 100644 --- a/src/sksl/SkSLGLSLCodeGenerator.h +++ b/src/sksl/SkSLGLSLCodeGenerator.h @@ -12,6 +12,7 @@ #include #include +#include "SkStream.h" #include "glsl/GrGLSLCaps.h" #include "SkSLCodeGenerator.h" #include "ir/SkSLBinaryExpression.h" @@ -75,7 +76,7 @@ public: : fContext(*context) , fCaps(*caps) {} - void generateCode(const Program& program, std::ostream& out) override; + void generateCode(const Program& program, SkWStream& out) override; private: void write(const char* s); @@ -84,9 +85,9 @@ private: void writeLine(const char* s); - void write(const std::string& s); + void write(const SkString& s); - void writeLine(const std::string& s); + void writeLine(const SkString& s); void writeType(const Type& type); @@ -156,9 +157,9 @@ private: const Context& fContext; const GrGLSLCaps& fCaps; - std::ostream* fOut = nullptr; - std::stringstream fHeader; - std::string fFunctionHeader; + SkWStream* fOut = nullptr; + SkDynamicMemoryWStream fHeader; + SkString fFunctionHeader; Program::Kind fProgramKind; int fVarCount = 0; int fIndentation = 0; diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index 1a4c775998..245c72f5db 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -173,7 +173,7 @@ std::unique_ptr IRGenerator::convertVarDeclarations(const ASTVa if (!size) { return nullptr; } - std::string name = type->fName; + SkString name = type->fName; uint64_t count; if (size->fKind == Expression::kIntLiteral_Kind) { count = ((IntLiteral&) *size).fValue; @@ -204,7 +204,7 @@ std::unique_ptr IRGenerator::convertVarDeclarations(const ASTVa } value = this->coerce(std::move(value), *type); } - if (storage == Variable::kGlobal_Storage && "sk_FragColor" == varDecl.fName && + 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] && @@ -397,12 +397,12 @@ std::unique_ptr IRGenerator::convertFunction(const ASTFuncti } for (int j = (int) param->fSizes.size() - 1; j >= 0; j--) { int size = param->fSizes[j]; - std::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; } - std::string name = param->fName; + SkString name = param->fName; Modifiers modifiers = this->convertModifiers(param->fModifiers); Position pos = param->fPosition; Variable* var = new Variable(pos, modifiers, std::move(name), *type, @@ -523,10 +523,10 @@ std::unique_ptr IRGenerator::convertInterfaceBlock(const ASTInte } Type* type = new Type(intf.fInterfaceName, fields); fSymbolTable->takeOwnership(type); - std::string name = intf.fValueName.length() > 0 ? intf.fValueName : intf.fInterfaceName; + SkString name = intf.fValueName.size() > 0 ? intf.fValueName : intf.fInterfaceName; Variable* var = new Variable(intf.fPosition, mods, name, *type, Variable::kGlobal_Storage); fSymbolTable->takeOwnership(var); - if (intf.fValueName.length()) { + if (intf.fValueName.size()) { old->addWithoutOwnership(intf.fValueName, var); } else { for (size_t i = 0; i < fields.size(); i++) { @@ -966,7 +966,7 @@ std::unique_ptr IRGenerator::call(Position position, const FunctionDeclaration& function, std::vector> arguments) { if (function.fParameters.size() != arguments.size()) { - std::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) { @@ -979,8 +979,8 @@ std::unique_ptr IRGenerator::call(Position position, std::vector types; const Type* returnType; if (!function.determineFinalTypes(arguments, &types, &returnType)) { - std::string msg = "no match for " + function.fName + "("; - std::string separator = ""; + SkString msg = "no match for " + function.fName + "("; + SkString separator; for (size_t i = 0; i < arguments.size(); i++) { msg += separator; separator = ", "; @@ -1058,8 +1058,8 @@ std::unique_ptr IRGenerator::call(Position position, if (best) { return this->call(position, *best, std::move(arguments)); } - std::string msg = "no match for " + ref->fFunctions[0]->fName + "("; - std::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 = ", "; @@ -1267,7 +1267,7 @@ std::unique_ptr IRGenerator::convertIndex(std::unique_ptr IRGenerator::convertField(std::unique_ptr base, - const std::string& field) { + const SkString& field) { auto fields = base->fType.fields(); for (size_t i = 0; i < fields.size(); i++) { if (fields[i].fName == field) { @@ -1280,14 +1280,14 @@ std::unique_ptr IRGenerator::convertField(std::unique_ptr IRGenerator::convertSwizzle(std::unique_ptr base, - const std::string& fields) { + const SkString& fields) { if (base->fType.kind() != Type::kVector_Kind) { fErrors.error(base->fPosition, "cannot swizzle type '" + base->fType.description() + "'"); return nullptr; } std::vector swizzleComponents; - for (char c : fields) { - switch (c) { + for (size_t i = 0; i < fields.size(); i++) { + switch (fields[i]) { case 'x': // fall through case 'r': // fall through case 's': @@ -1318,8 +1318,8 @@ std::unique_ptr IRGenerator::convertSwizzle(std::unique_ptrfPosition, "invalid swizzle component '" + std::string(1, c) + - "'"); + fErrors.error(base->fPosition, SkStringPrintf("invalid swizzle component '%c'", + fields[i])); return nullptr; } } diff --git a/src/sksl/SkSLIRGenerator.h b/src/sksl/SkSLIRGenerator.h index 036f24253b..d7bd59ad02 100644 --- a/src/sksl/SkSLIRGenerator.h +++ b/src/sksl/SkSLIRGenerator.h @@ -107,9 +107,9 @@ private: std::unique_ptr convertReturn(const ASTReturnStatement& r); std::unique_ptr convertSuffixExpression(const ASTSuffixExpression& expression); std::unique_ptr convertField(std::unique_ptr base, - const std::string& field); + const SkString& field); std::unique_ptr convertSwizzle(std::unique_ptr base, - const std::string& fields); + const SkString& fields); std::unique_ptr convertTernaryExpression(const ASTTernaryExpression& expression); std::unique_ptr convertVarDeclarationStatement(const ASTVarDeclarationStatement& s); std::unique_ptr convertWhile(const ASTWhileStatement& w); diff --git a/src/sksl/SkSLMain.cpp b/src/sksl/SkSLMain.cpp index 3658992412..d9fc81470e 100644 --- a/src/sksl/SkSLMain.cpp +++ b/src/sksl/SkSLMain.cpp @@ -10,13 +10,6 @@ #include "SkSLCompiler.h" #include "GrContextOptions.h" -bool endsWith(const std::string& s, const std::string& ending) { - if (s.length() >= ending.length()) { - return (0 == s.compare(s.length() - ending.length(), ending.length(), ending)); - } - return false; -} - /** * Very simple standalone executable to facilitate testing. */ @@ -37,35 +30,36 @@ int main(int argc, const char** argv) { } std::ifstream in(argv[1]); - std::string text((std::istreambuf_iterator(in)), - std::istreambuf_iterator()); + std::string stdText((std::istreambuf_iterator(in)), + std::istreambuf_iterator()); + SkString text(stdText.c_str()); if (in.rdstate()) { printf("error reading '%s'\n", argv[1]); exit(2); } - std::string name(argv[2]); - if (endsWith(name, ".spirv")) { - std::ofstream out(argv[2], std::ofstream::binary); + SkString name(argv[2]); + if (name.endsWith(".spirv")) { + SkFILEWStream out(argv[2]); SkSL::Compiler compiler; + if (!out.isValid()) { + printf("error writing '%s'\n", argv[2]); + exit(4); + } if (!compiler.toSPIRV(kind, text, out)) { printf("%s", compiler.errorText().c_str()); exit(3); } - if (out.rdstate()) { + } else if (name.endsWith(".glsl")) { + SkFILEWStream out(argv[2]); + SkSL::Compiler compiler; + if (!out.isValid()) { printf("error writing '%s'\n", argv[2]); exit(4); } - } else if (endsWith(name, ".glsl")) { - std::ofstream out(argv[2], std::ofstream::binary); - SkSL::Compiler compiler; if (!compiler.toGLSL(kind, text, *SkSL::GLSLCapsFactory::Default(), out)) { printf("%s", compiler.errorText().c_str()); exit(3); } - if (out.rdstate()) { - printf("error writing '%s'\n", argv[2]); - exit(4); - } } else { printf("expected output filename to end with '.spirv' or '.glsl'"); } diff --git a/src/sksl/SkSLParser.cpp b/src/sksl/SkSLParser.cpp index 2be664dbd8..03d0d337a8 100644 --- a/src/sksl/SkSLParser.cpp +++ b/src/sksl/SkSLParser.cpp @@ -88,7 +88,7 @@ public: bool checkValid() { if (fParser->fDepth > MAX_PARSE_DEPTH) { - fParser->error(fParser->peek().fPosition, "exceeded max parse depth"); + fParser->error(fParser->peek().fPosition, SkString("exceeded max parse depth")); return false; } return true; @@ -98,8 +98,8 @@ private: Parser* fParser; }; -Parser::Parser(std::string text, SymbolTable& types, ErrorReporter& errors) -: fPushback(Position(-1, -1), Token::INVALID_TOKEN, "") +Parser::Parser(SkString text, SymbolTable& types, ErrorReporter& errors) +: fPushback(Position(-1, -1), Token::INVALID_TOKEN, SkString()) , fTypes(types) , fErrors(errors) { sksllex_init(&fScanner); @@ -157,13 +157,13 @@ Token Parser::nextToken() { return result; } int token = sksllex(fScanner); - std::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 = std::string(skslget_text(fScanner)); + text = SkString(skslget_text(fScanner)); break; default: break; @@ -181,7 +181,12 @@ Token Parser::peek() { return fPushback; } -bool Parser::expect(Token::Kind kind, std::string expected, Token* result) { + +bool Parser::expect(Token::Kind kind, const char* expected, Token* result) { + return this->expect(kind, SkString(expected), result); +} + +bool Parser::expect(Token::Kind kind, SkString expected, Token* result) { Token next = this->nextToken(); if (next.fKind == kind) { if (result) { @@ -194,11 +199,15 @@ bool Parser::expect(Token::Kind kind, std::string expected, Token* result) { } } -void Parser::error(Position p, std::string msg) { +void Parser::error(Position p, const char* msg) { + this->error(p, SkString(msg)); +} + +void Parser::error(Position p, SkString msg) { fErrors.error(p, msg); } -bool Parser::isType(std::string name) { +bool Parser::isType(SkString name) { return nullptr != fTypes[name]; } @@ -370,7 +379,7 @@ std::unique_ptr Parser::structDeclaration() { return nullptr; } uint64_t columns = ((ASTIntLiteral&) *var.fSizes[i]).fValue; - std::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); } @@ -417,7 +426,7 @@ std::unique_ptr Parser::structVarDeclaration(ASTModifiers mo (LBRACKET expression? RBRACKET)* (EQ expression)?)* SEMICOLON */ std::unique_ptr Parser::varDeclarationEnd(ASTModifiers mods, std::unique_ptr type, - std::string name) { + SkString name) { std::vector vars; std::vector> currentVarSizes; while (this->peek().fKind == Token::LBRACKET) { @@ -731,7 +740,7 @@ std::unique_ptr Parser::interfaceBlock(ASTModifiers mods) { decls.push_back(std::move(decl)); } this->nextToken(); - std::string valueName; + SkString valueName; if (this->peek().fKind == Token::IDENTIFIER) { valueName = this->nextToken().fText; } @@ -1361,7 +1370,7 @@ std::unique_ptr Parser::suffix() { } case Token::DOT: { Position pos = this->peek().fPosition; - std::string text; + SkString text; if (this->identifier(&text)) { return std::unique_ptr(new ASTFieldSuffix(pos, std::move(text))); } @@ -1406,7 +1415,7 @@ std::unique_ptr Parser::term() { Token t = this->peek(); switch (t.fKind) { case Token::IDENTIFIER: { - std::string text; + SkString text; if (this->identifier(&text)) { result.reset(new ASTIdentifier(t.fPosition, std::move(text))); } @@ -1487,7 +1496,7 @@ bool Parser::boolLiteral(bool* dest) { } /* IDENTIFIER */ -bool Parser::identifier(std::string* dest) { +bool Parser::identifier(SkString* dest) { Token t; if (this->expect(Token::IDENTIFIER, "identifier", &t)) { *dest = t.fText; diff --git a/src/sksl/SkSLParser.h b/src/sksl/SkSLParser.h index f9dcde244f..f2b6fb87bb 100644 --- a/src/sksl/SkSLParser.h +++ b/src/sksl/SkSLParser.h @@ -8,7 +8,6 @@ #ifndef SKSL_PARSER #define SKSL_PARSER -#include #include #include #include @@ -49,7 +48,7 @@ class SymbolTable; */ class Parser { public: - Parser(std::string text, SymbolTable& types, ErrorReporter& errors); + Parser(SkString text, SymbolTable& types, ErrorReporter& errors); ~Parser(); @@ -87,15 +86,17 @@ private: * If 'result' is non-null, it is set to point to the token that was read. * Returns true if the read token was as expected, false otherwise. */ - bool expect(Token::Kind kind, std::string expected, Token* result = nullptr); + bool expect(Token::Kind kind, const char* expected, Token* result = nullptr); + bool expect(Token::Kind kind, SkString expected, Token* result = nullptr); - void error(Position p, std::string msg); + void error(Position p, const char* 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(std::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 @@ -115,7 +116,7 @@ private: std::unique_ptr varDeclarationEnd(ASTModifiers modifiers, std::unique_ptr type, - std::string name); + SkString name); std::unique_ptr parameter(); @@ -195,7 +196,7 @@ private: bool boolLiteral(bool* dest); - bool identifier(std::string* dest); + bool identifier(SkString* dest); void* fScanner; YY_BUFFER_STATE fBuffer; diff --git a/src/sksl/SkSLPosition.h b/src/sksl/SkSLPosition.h index 979f630ae7..b1841c5a59 100644 --- a/src/sksl/SkSLPosition.h +++ b/src/sksl/SkSLPosition.h @@ -25,7 +25,7 @@ struct Position { : fLine(line) , fColumn(column) {} - std::string description() const { + SkString description() const { return to_string(fLine); } diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp index a491968674..b5cd54abae 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.cpp +++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp @@ -34,107 +34,112 @@ void SPIRVCodeGenerator::setupIntrinsics() { #define SPECIAL(x) std::make_tuple(kSpecial_IntrinsicKind, k ## x ## _SpecialIntrinsic, \ k ## x ## _SpecialIntrinsic, k ## x ## _SpecialIntrinsic, \ k ## x ## _SpecialIntrinsic) - fIntrinsicMap["round"] = ALL_GLSL(Round); - fIntrinsicMap["roundEven"] = ALL_GLSL(RoundEven); - fIntrinsicMap["trunc"] = ALL_GLSL(Trunc); - fIntrinsicMap["abs"] = BY_TYPE_GLSL(FAbs, SAbs, SAbs); - fIntrinsicMap["sign"] = BY_TYPE_GLSL(FSign, SSign, SSign); - fIntrinsicMap["floor"] = ALL_GLSL(Floor); - fIntrinsicMap["ceil"] = ALL_GLSL(Ceil); - fIntrinsicMap["fract"] = ALL_GLSL(Fract); - fIntrinsicMap["radians"] = ALL_GLSL(Radians); - fIntrinsicMap["degrees"] = ALL_GLSL(Degrees); - fIntrinsicMap["sin"] = ALL_GLSL(Sin); - fIntrinsicMap["cos"] = ALL_GLSL(Cos); - fIntrinsicMap["tan"] = ALL_GLSL(Tan); - fIntrinsicMap["asin"] = ALL_GLSL(Asin); - fIntrinsicMap["acos"] = ALL_GLSL(Acos); - fIntrinsicMap["atan"] = SPECIAL(Atan); - fIntrinsicMap["sinh"] = ALL_GLSL(Sinh); - fIntrinsicMap["cosh"] = ALL_GLSL(Cosh); - fIntrinsicMap["tanh"] = ALL_GLSL(Tanh); - fIntrinsicMap["asinh"] = ALL_GLSL(Asinh); - fIntrinsicMap["acosh"] = ALL_GLSL(Acosh); - fIntrinsicMap["atanh"] = ALL_GLSL(Atanh); - fIntrinsicMap["pow"] = ALL_GLSL(Pow); - fIntrinsicMap["exp"] = ALL_GLSL(Exp); - fIntrinsicMap["log"] = ALL_GLSL(Log); - fIntrinsicMap["exp2"] = ALL_GLSL(Exp2); - fIntrinsicMap["log2"] = ALL_GLSL(Log2); - fIntrinsicMap["sqrt"] = ALL_GLSL(Sqrt); - fIntrinsicMap["inversesqrt"] = ALL_GLSL(InverseSqrt); - fIntrinsicMap["determinant"] = ALL_GLSL(Determinant); - fIntrinsicMap["matrixInverse"] = ALL_GLSL(MatrixInverse); - fIntrinsicMap["mod"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpFMod, SpvOpSMod, - SpvOpUMod, SpvOpUndef); - fIntrinsicMap["min"] = BY_TYPE_GLSL(FMin, SMin, UMin); - fIntrinsicMap["max"] = BY_TYPE_GLSL(FMax, SMax, UMax); - fIntrinsicMap["clamp"] = BY_TYPE_GLSL(FClamp, SClamp, UClamp); - fIntrinsicMap["dot"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDot, SpvOpUndef, - SpvOpUndef, SpvOpUndef); - fIntrinsicMap["mix"] = ALL_GLSL(FMix); - fIntrinsicMap["step"] = ALL_GLSL(Step); - fIntrinsicMap["smoothstep"] = ALL_GLSL(SmoothStep); - fIntrinsicMap["fma"] = ALL_GLSL(Fma); - fIntrinsicMap["frexp"] = ALL_GLSL(Frexp); - fIntrinsicMap["ldexp"] = ALL_GLSL(Ldexp); - -#define PACK(type) fIntrinsicMap["pack" #type] = ALL_GLSL(Pack ## type); \ - fIntrinsicMap["unpack" #type] = ALL_GLSL(Unpack ## type) + 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[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[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["length"] = ALL_GLSL(Length); - fIntrinsicMap["distance"] = ALL_GLSL(Distance); - fIntrinsicMap["cross"] = ALL_GLSL(Cross); - fIntrinsicMap["normalize"] = ALL_GLSL(Normalize); - fIntrinsicMap["faceForward"] = ALL_GLSL(FaceForward); - fIntrinsicMap["reflect"] = ALL_GLSL(Reflect); - fIntrinsicMap["refract"] = ALL_GLSL(Refract); - fIntrinsicMap["findLSB"] = ALL_GLSL(FindILsb); - fIntrinsicMap["findMSB"] = BY_TYPE_GLSL(FindSMsb, FindSMsb, FindUMsb); - fIntrinsicMap["dFdx"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdx, SpvOpUndef, - SpvOpUndef, SpvOpUndef); - fIntrinsicMap["dFdy"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy, SpvOpUndef, - SpvOpUndef, SpvOpUndef); - fIntrinsicMap["dFdy"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy, SpvOpUndef, - SpvOpUndef, SpvOpUndef); - fIntrinsicMap["texture"] = SPECIAL(Texture); - fIntrinsicMap["texture2D"] = SPECIAL(Texture2D); - fIntrinsicMap["textureProj"] = SPECIAL(TextureProj); - - fIntrinsicMap["any"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef, - SpvOpUndef, SpvOpUndef, SpvOpAny); - fIntrinsicMap["all"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef, - SpvOpUndef, SpvOpUndef, SpvOpAll); - fIntrinsicMap["equal"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpFOrdEqual, - SpvOpIEqual, SpvOpIEqual, - SpvOpLogicalEqual); - fIntrinsicMap["notEqual"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpFOrdNotEqual, - SpvOpINotEqual, SpvOpINotEqual, - SpvOpLogicalNotEqual); - fIntrinsicMap["lessThan"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpSLessThan, - SpvOpULessThan, SpvOpFOrdLessThan, - SpvOpUndef); - fIntrinsicMap["lessThanEqual"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpSLessThanEqual, - SpvOpULessThanEqual, SpvOpFOrdLessThanEqual, - SpvOpUndef); - fIntrinsicMap["greaterThan"] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpSGreaterThan, - SpvOpUGreaterThan, SpvOpFOrdGreaterThan, - SpvOpUndef); - fIntrinsicMap["greaterThanEqual"] = std::make_tuple(kSPIRV_IntrinsicKind, - SpvOpSGreaterThanEqual, - SpvOpUGreaterThanEqual, - SpvOpFOrdGreaterThanEqual, - SpvOpUndef); + 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[SkString("dFdy")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy, + SpvOpUndef, SpvOpUndef, SpvOpUndef); + fIntrinsicMap[SkString("dFdy")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy, + SpvOpUndef, SpvOpUndef, SpvOpUndef); + fIntrinsicMap[SkString("texture")] = SPECIAL(Texture); + fIntrinsicMap[SkString("texture2D")] = SPECIAL(Texture2D); + fIntrinsicMap[SkString("textureProj")] = SPECIAL(TextureProj); + + fIntrinsicMap[SkString("any")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef, + SpvOpUndef, SpvOpUndef, SpvOpAny); + fIntrinsicMap[SkString("all")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef, + SpvOpUndef, SpvOpUndef, SpvOpAll); + fIntrinsicMap[SkString("equal")] = std::make_tuple(kSPIRV_IntrinsicKind, + SpvOpFOrdEqual, SpvOpIEqual, + SpvOpIEqual, SpvOpLogicalEqual); + fIntrinsicMap[SkString("notEqual")] = std::make_tuple(kSPIRV_IntrinsicKind, + SpvOpFOrdNotEqual, SpvOpINotEqual, + SpvOpINotEqual, + SpvOpLogicalNotEqual); + fIntrinsicMap[SkString("lessThan")] = std::make_tuple(kSPIRV_IntrinsicKind, + SpvOpSLessThan, SpvOpULessThan, + SpvOpFOrdLessThan, SpvOpUndef); + fIntrinsicMap[SkString("lessThanEqual")] = std::make_tuple(kSPIRV_IntrinsicKind, + SpvOpSLessThanEqual, + SpvOpULessThanEqual, + SpvOpFOrdLessThanEqual, + SpvOpUndef); + fIntrinsicMap[SkString("greaterThan")] = std::make_tuple(kSPIRV_IntrinsicKind, + SpvOpSGreaterThan, + SpvOpUGreaterThan, + SpvOpFOrdGreaterThan, + SpvOpUndef); + fIntrinsicMap[SkString("greaterThanEqual")] = std::make_tuple(kSPIRV_IntrinsicKind, + SpvOpSGreaterThanEqual, + SpvOpUGreaterThanEqual, + SpvOpFOrdGreaterThanEqual, + SpvOpUndef); // interpolateAt* not yet supported... } -void SPIRVCodeGenerator::writeWord(int32_t word, std::ostream& out) { +void SPIRVCodeGenerator::writeWord(int32_t word, SkWStream& out) { #if SPIRV_DEBUG out << "(" << word << ") "; #else @@ -175,603 +180,603 @@ static bool is_out(const Variable& var) { } #if SPIRV_DEBUG -static std::string opcode_text(SpvOp_ opCode) { +static SkString opcode_text(SpvOp_ opCode) { switch (opCode) { case SpvOpNop: - return "Nop"; + return SkString("Nop"); case SpvOpUndef: - return "Undef"; + return SkString("Undef"); case SpvOpSourceContinued: - return "SourceContinued"; + return SkString("SourceContinued"); case SpvOpSource: - return "Source"; + return SkString("Source"); case SpvOpSourceExtension: - return "SourceExtension"; + return SkString("SourceExtension"); case SpvOpName: - return "Name"; + return SkString("Name"); case SpvOpMemberName: - return "MemberName"; + return SkString("MemberName"); case SpvOpString: - return "String"; + return SkString("String"); case SpvOpLine: - return "Line"; + return SkString("Line"); case SpvOpExtension: - return "Extension"; + return SkString("Extension"); case SpvOpExtInstImport: - return "ExtInstImport"; + return SkString("ExtInstImport"); case SpvOpExtInst: - return "ExtInst"; + return SkString("ExtInst"); case SpvOpMemoryModel: - return "MemoryModel"; + return SkString("MemoryModel"); case SpvOpEntryPoint: - return "EntryPoint"; + return SkString("EntryPoint"); case SpvOpExecutionMode: - return "ExecutionMode"; + return SkString("ExecutionMode"); case SpvOpCapability: - return "Capability"; + return SkString("Capability"); case SpvOpTypeVoid: - return "TypeVoid"; + return SkString("TypeVoid"); case SpvOpTypeBool: - return "TypeBool"; + return SkString("TypeBool"); case SpvOpTypeInt: - return "TypeInt"; + return SkString("TypeInt"); case SpvOpTypeFloat: - return "TypeFloat"; + return SkString("TypeFloat"); case SpvOpTypeVector: - return "TypeVector"; + return SkString("TypeVector"); case SpvOpTypeMatrix: - return "TypeMatrix"; + return SkString("TypeMatrix"); case SpvOpTypeImage: - return "TypeImage"; + return SkString("TypeImage"); case SpvOpTypeSampler: - return "TypeSampler"; + return SkString("TypeSampler"); case SpvOpTypeSampledImage: - return "TypeSampledImage"; + return SkString("TypeSampledImage"); case SpvOpTypeArray: - return "TypeArray"; + return SkString("TypeArray"); case SpvOpTypeRuntimeArray: - return "TypeRuntimeArray"; + return SkString("TypeRuntimeArray"); case SpvOpTypeStruct: - return "TypeStruct"; + return SkString("TypeStruct"); case SpvOpTypeOpaque: - return "TypeOpaque"; + return SkString("TypeOpaque"); case SpvOpTypePointer: - return "TypePointer"; + return SkString("TypePointer"); case SpvOpTypeFunction: - return "TypeFunction"; + return SkString("TypeFunction"); case SpvOpTypeEvent: - return "TypeEvent"; + return SkString("TypeEvent"); case SpvOpTypeDeviceEvent: - return "TypeDeviceEvent"; + return SkString("TypeDeviceEvent"); case SpvOpTypeReserveId: - return "TypeReserveId"; + return SkString("TypeReserveId"); case SpvOpTypeQueue: - return "TypeQueue"; + return SkString("TypeQueue"); case SpvOpTypePipe: - return "TypePipe"; + return SkString("TypePipe"); case SpvOpTypeForwardPointer: - return "TypeForwardPointer"; + return SkString("TypeForwardPointer"); case SpvOpConstantTrue: - return "ConstantTrue"; + return SkString("ConstantTrue"); case SpvOpConstantFalse: - return "ConstantFalse"; + return SkString("ConstantFalse"); case SpvOpConstant: - return "Constant"; + return SkString("Constant"); case SpvOpConstantComposite: - return "ConstantComposite"; + return SkString("ConstantComposite"); case SpvOpConstantSampler: - return "ConstantSampler"; + return SkString("ConstantSampler"); case SpvOpConstantNull: - return "ConstantNull"; + return SkString("ConstantNull"); case SpvOpSpecConstantTrue: - return "SpecConstantTrue"; + return SkString("SpecConstantTrue"); case SpvOpSpecConstantFalse: - return "SpecConstantFalse"; + return SkString("SpecConstantFalse"); case SpvOpSpecConstant: - return "SpecConstant"; + return SkString("SpecConstant"); case SpvOpSpecConstantComposite: - return "SpecConstantComposite"; + return SkString("SpecConstantComposite"); case SpvOpSpecConstantOp: - return "SpecConstantOp"; + return SkString("SpecConstantOp"); case SpvOpFunction: - return "Function"; + return SkString("Function"); case SpvOpFunctionParameter: - return "FunctionParameter"; + return SkString("FunctionParameter"); case SpvOpFunctionEnd: - return "FunctionEnd"; + return SkString("FunctionEnd"); case SpvOpFunctionCall: - return "FunctionCall"; + return SkString("FunctionCall"); case SpvOpVariable: - return "Variable"; + return SkString("Variable"); case SpvOpImageTexelPointer: - return "ImageTexelPointer"; + return SkString("ImageTexelPointer"); case SpvOpLoad: - return "Load"; + return SkString("Load"); case SpvOpStore: - return "Store"; + return SkString("Store"); case SpvOpCopyMemory: - return "CopyMemory"; + return SkString("CopyMemory"); case SpvOpCopyMemorySized: - return "CopyMemorySized"; + return SkString("CopyMemorySized"); case SpvOpAccessChain: - return "AccessChain"; + return SkString("AccessChain"); case SpvOpInBoundsAccessChain: - return "InBoundsAccessChain"; + return SkString("InBoundsAccessChain"); case SpvOpPtrAccessChain: - return "PtrAccessChain"; + return SkString("PtrAccessChain"); case SpvOpArrayLength: - return "ArrayLength"; + return SkString("ArrayLength"); case SpvOpGenericPtrMemSemantics: - return "GenericPtrMemSemantics"; + return SkString("GenericPtrMemSemantics"); case SpvOpInBoundsPtrAccessChain: - return "InBoundsPtrAccessChain"; + return SkString("InBoundsPtrAccessChain"); case SpvOpDecorate: - return "Decorate"; + return SkString("Decorate"); case SpvOpMemberDecorate: - return "MemberDecorate"; + return SkString("MemberDecorate"); case SpvOpDecorationGroup: - return "DecorationGroup"; + return SkString("DecorationGroup"); case SpvOpGroupDecorate: - return "GroupDecorate"; + return SkString("GroupDecorate"); case SpvOpGroupMemberDecorate: - return "GroupMemberDecorate"; + return SkString("GroupMemberDecorate"); case SpvOpVectorExtractDynamic: - return "VectorExtractDynamic"; + return SkString("VectorExtractDynamic"); case SpvOpVectorInsertDynamic: - return "VectorInsertDynamic"; + return SkString("VectorInsertDynamic"); case SpvOpVectorShuffle: - return "VectorShuffle"; + return SkString("VectorShuffle"); case SpvOpCompositeConstruct: - return "CompositeConstruct"; + return SkString("CompositeConstruct"); case SpvOpCompositeExtract: - return "CompositeExtract"; + return SkString("CompositeExtract"); case SpvOpCompositeInsert: - return "CompositeInsert"; + return SkString("CompositeInsert"); case SpvOpCopyObject: - return "CopyObject"; + return SkString("CopyObject"); case SpvOpTranspose: - return "Transpose"; + return SkString("Transpose"); case SpvOpSampledImage: - return "SampledImage"; + return SkString("SampledImage"); case SpvOpImageSampleImplicitLod: - return "ImageSampleImplicitLod"; + return SkString("ImageSampleImplicitLod"); case SpvOpImageSampleExplicitLod: - return "ImageSampleExplicitLod"; + return SkString("ImageSampleExplicitLod"); case SpvOpImageSampleDrefImplicitLod: - return "ImageSampleDrefImplicitLod"; + return SkString("ImageSampleDrefImplicitLod"); case SpvOpImageSampleDrefExplicitLod: - return "ImageSampleDrefExplicitLod"; + return SkString("ImageSampleDrefExplicitLod"); case SpvOpImageSampleProjImplicitLod: - return "ImageSampleProjImplicitLod"; + return SkString("ImageSampleProjImplicitLod"); case SpvOpImageSampleProjExplicitLod: - return "ImageSampleProjExplicitLod"; + return SkString("ImageSampleProjExplicitLod"); case SpvOpImageSampleProjDrefImplicitLod: - return "ImageSampleProjDrefImplicitLod"; + return SkString("ImageSampleProjDrefImplicitLod"); case SpvOpImageSampleProjDrefExplicitLod: - return "ImageSampleProjDrefExplicitLod"; + return SkString("ImageSampleProjDrefExplicitLod"); case SpvOpImageFetch: - return "ImageFetch"; + return SkString("ImageFetch"); case SpvOpImageGather: - return "ImageGather"; + return SkString("ImageGather"); case SpvOpImageDrefGather: - return "ImageDrefGather"; + return SkString("ImageDrefGather"); case SpvOpImageRead: - return "ImageRead"; + return SkString("ImageRead"); case SpvOpImageWrite: - return "ImageWrite"; + return SkString("ImageWrite"); case SpvOpImage: - return "Image"; + return SkString("Image"); case SpvOpImageQueryFormat: - return "ImageQueryFormat"; + return SkString("ImageQueryFormat"); case SpvOpImageQueryOrder: - return "ImageQueryOrder"; + return SkString("ImageQueryOrder"); case SpvOpImageQuerySizeLod: - return "ImageQuerySizeLod"; + return SkString("ImageQuerySizeLod"); case SpvOpImageQuerySize: - return "ImageQuerySize"; + return SkString("ImageQuerySize"); case SpvOpImageQueryLod: - return "ImageQueryLod"; + return SkString("ImageQueryLod"); case SpvOpImageQueryLevels: - return "ImageQueryLevels"; + return SkString("ImageQueryLevels"); case SpvOpImageQuerySamples: - return "ImageQuerySamples"; + return SkString("ImageQuerySamples"); case SpvOpConvertFToU: - return "ConvertFToU"; + return SkString("ConvertFToU"); case SpvOpConvertFToS: - return "ConvertFToS"; + return SkString("ConvertFToS"); case SpvOpConvertSToF: - return "ConvertSToF"; + return SkString("ConvertSToF"); case SpvOpConvertUToF: - return "ConvertUToF"; + return SkString("ConvertUToF"); case SpvOpUConvert: - return "UConvert"; + return SkString("UConvert"); case SpvOpSConvert: - return "SConvert"; + return SkString("SConvert"); case SpvOpFConvert: - return "FConvert"; + return SkString("FConvert"); case SpvOpQuantizeToF16: - return "QuantizeToF16"; + return SkString("QuantizeToF16"); case SpvOpConvertPtrToU: - return "ConvertPtrToU"; + return SkString("ConvertPtrToU"); case SpvOpSatConvertSToU: - return "SatConvertSToU"; + return SkString("SatConvertSToU"); case SpvOpSatConvertUToS: - return "SatConvertUToS"; + return SkString("SatConvertUToS"); case SpvOpConvertUToPtr: - return "ConvertUToPtr"; + return SkString("ConvertUToPtr"); case SpvOpPtrCastToGeneric: - return "PtrCastToGeneric"; + return SkString("PtrCastToGeneric"); case SpvOpGenericCastToPtr: - return "GenericCastToPtr"; + return SkString("GenericCastToPtr"); case SpvOpGenericCastToPtrExplicit: - return "GenericCastToPtrExplicit"; + return SkString("GenericCastToPtrExplicit"); case SpvOpBitcast: - return "Bitcast"; + return SkString("Bitcast"); case SpvOpSNegate: - return "SNegate"; + return SkString("SNegate"); case SpvOpFNegate: - return "FNegate"; + return SkString("FNegate"); case SpvOpIAdd: - return "IAdd"; + return SkString("IAdd"); case SpvOpFAdd: - return "FAdd"; + return SkString("FAdd"); case SpvOpISub: - return "ISub"; + return SkString("ISub"); case SpvOpFSub: - return "FSub"; + return SkString("FSub"); case SpvOpIMul: - return "IMul"; + return SkString("IMul"); case SpvOpFMul: - return "FMul"; + return SkString("FMul"); case SpvOpUDiv: - return "UDiv"; + return SkString("UDiv"); case SpvOpSDiv: - return "SDiv"; + return SkString("SDiv"); case SpvOpFDiv: - return "FDiv"; + return SkString("FDiv"); case SpvOpUMod: - return "UMod"; + return SkString("UMod"); case SpvOpSRem: - return "SRem"; + return SkString("SRem"); case SpvOpSMod: - return "SMod"; + return SkString("SMod"); case SpvOpFRem: - return "FRem"; + return SkString("FRem"); case SpvOpFMod: - return "FMod"; + return SkString("FMod"); case SpvOpVectorTimesScalar: - return "VectorTimesScalar"; + return SkString("VectorTimesScalar"); case SpvOpMatrixTimesScalar: - return "MatrixTimesScalar"; + return SkString("MatrixTimesScalar"); case SpvOpVectorTimesMatrix: - return "VectorTimesMatrix"; + return SkString("VectorTimesMatrix"); case SpvOpMatrixTimesVector: - return "MatrixTimesVector"; + return SkString("MatrixTimesVector"); case SpvOpMatrixTimesMatrix: - return "MatrixTimesMatrix"; + return SkString("MatrixTimesMatrix"); case SpvOpOuterProduct: - return "OuterProduct"; + return SkString("OuterProduct"); case SpvOpDot: - return "Dot"; + return SkString("Dot"); case SpvOpIAddCarry: - return "IAddCarry"; + return SkString("IAddCarry"); case SpvOpISubBorrow: - return "ISubBorrow"; + return SkString("ISubBorrow"); case SpvOpUMulExtended: - return "UMulExtended"; + return SkString("UMulExtended"); case SpvOpSMulExtended: - return "SMulExtended"; + return SkString("SMulExtended"); case SpvOpAny: - return "Any"; + return SkString("Any"); case SpvOpAll: - return "All"; + return SkString("All"); case SpvOpIsNan: - return "IsNan"; + return SkString("IsNan"); case SpvOpIsInf: - return "IsInf"; + return SkString("IsInf"); case SpvOpIsFinite: - return "IsFinite"; + return SkString("IsFinite"); case SpvOpIsNormal: - return "IsNormal"; + return SkString("IsNormal"); case SpvOpSignBitSet: - return "SignBitSet"; + return SkString("SignBitSet"); case SpvOpLessOrGreater: - return "LessOrGreater"; + return SkString("LessOrGreater"); case SpvOpOrdered: - return "Ordered"; + return SkString("Ordered"); case SpvOpUnordered: - return "Unordered"; + return SkString("Unordered"); case SpvOpLogicalEqual: - return "LogicalEqual"; + return SkString("LogicalEqual"); case SpvOpLogicalNotEqual: - return "LogicalNotEqual"; + return SkString("LogicalNotEqual"); case SpvOpLogicalOr: - return "LogicalOr"; + return SkString("LogicalOr"); case SpvOpLogicalAnd: - return "LogicalAnd"; + return SkString("LogicalAnd"); case SpvOpLogicalNot: - return "LogicalNot"; + return SkString("LogicalNot"); case SpvOpSelect: - return "Select"; + return SkString("Select"); case SpvOpIEqual: - return "IEqual"; + return SkString("IEqual"); case SpvOpINotEqual: - return "INotEqual"; + return SkString("INotEqual"); case SpvOpUGreaterThan: - return "UGreaterThan"; + return SkString("UGreaterThan"); case SpvOpSGreaterThan: - return "SGreaterThan"; + return SkString("SGreaterThan"); case SpvOpUGreaterThanEqual: - return "UGreaterThanEqual"; + return SkString("UGreaterThanEqual"); case SpvOpSGreaterThanEqual: - return "SGreaterThanEqual"; + return SkString("SGreaterThanEqual"); case SpvOpULessThan: - return "ULessThan"; + return SkString("ULessThan"); case SpvOpSLessThan: - return "SLessThan"; + return SkString("SLessThan"); case SpvOpULessThanEqual: - return "ULessThanEqual"; + return SkString("ULessThanEqual"); case SpvOpSLessThanEqual: - return "SLessThanEqual"; + return SkString("SLessThanEqual"); case SpvOpFOrdEqual: - return "FOrdEqual"; + return SkString("FOrdEqual"); case SpvOpFUnordEqual: - return "FUnordEqual"; + return SkString("FUnordEqual"); case SpvOpFOrdNotEqual: - return "FOrdNotEqual"; + return SkString("FOrdNotEqual"); case SpvOpFUnordNotEqual: - return "FUnordNotEqual"; + return SkString("FUnordNotEqual"); case SpvOpFOrdLessThan: - return "FOrdLessThan"; + return SkString("FOrdLessThan"); case SpvOpFUnordLessThan: - return "FUnordLessThan"; + return SkString("FUnordLessThan"); case SpvOpFOrdGreaterThan: - return "FOrdGreaterThan"; + return SkString("FOrdGreaterThan"); case SpvOpFUnordGreaterThan: - return "FUnordGreaterThan"; + return SkString("FUnordGreaterThan"); case SpvOpFOrdLessThanEqual: - return "FOrdLessThanEqual"; + return SkString("FOrdLessThanEqual"); case SpvOpFUnordLessThanEqual: - return "FUnordLessThanEqual"; + return SkString("FUnordLessThanEqual"); case SpvOpFOrdGreaterThanEqual: - return "FOrdGreaterThanEqual"; + return SkString("FOrdGreaterThanEqual"); case SpvOpFUnordGreaterThanEqual: - return "FUnordGreaterThanEqual"; + return SkString("FUnordGreaterThanEqual"); case SpvOpShiftRightLogical: - return "ShiftRightLogical"; + return SkString("ShiftRightLogical"); case SpvOpShiftRightArithmetic: - return "ShiftRightArithmetic"; + return SkString("ShiftRightArithmetic"); case SpvOpShiftLeftLogical: - return "ShiftLeftLogical"; + return SkString("ShiftLeftLogical"); case SpvOpBitwiseOr: - return "BitwiseOr"; + return SkString("BitwiseOr"); case SpvOpBitwiseXor: - return "BitwiseXor"; + return SkString("BitwiseXor"); case SpvOpBitwiseAnd: - return "BitwiseAnd"; + return SkString("BitwiseAnd"); case SpvOpNot: - return "Not"; + return SkString("Not"); case SpvOpBitFieldInsert: - return "BitFieldInsert"; + return SkString("BitFieldInsert"); case SpvOpBitFieldSExtract: - return "BitFieldSExtract"; + return SkString("BitFieldSExtract"); case SpvOpBitFieldUExtract: - return "BitFieldUExtract"; + return SkString("BitFieldUExtract"); case SpvOpBitReverse: - return "BitReverse"; + return SkString("BitReverse"); case SpvOpBitCount: - return "BitCount"; + return SkString("BitCount"); case SpvOpDPdx: - return "DPdx"; + return SkString("DPdx"); case SpvOpDPdy: - return "DPdy"; + return SkString("DPdy"); case SpvOpFwidth: - return "Fwidth"; + return SkString("Fwidth"); case SpvOpDPdxFine: - return "DPdxFine"; + return SkString("DPdxFine"); case SpvOpDPdyFine: - return "DPdyFine"; + return SkString("DPdyFine"); case SpvOpFwidthFine: - return "FwidthFine"; + return SkString("FwidthFine"); case SpvOpDPdxCoarse: - return "DPdxCoarse"; + return SkString("DPdxCoarse"); case SpvOpDPdyCoarse: - return "DPdyCoarse"; + return SkString("DPdyCoarse"); case SpvOpFwidthCoarse: - return "FwidthCoarse"; + return SkString("FwidthCoarse"); case SpvOpEmitVertex: - return "EmitVertex"; + return SkString("EmitVertex"); case SpvOpEndPrimitive: - return "EndPrimitive"; + return SkString("EndPrimitive"); case SpvOpEmitStreamVertex: - return "EmitStreamVertex"; + return SkString("EmitStreamVertex"); case SpvOpEndStreamPrimitive: - return "EndStreamPrimitive"; + return SkString("EndStreamPrimitive"); case SpvOpControlBarrier: - return "ControlBarrier"; + return SkString("ControlBarrier"); case SpvOpMemoryBarrier: - return "MemoryBarrier"; + return SkString("MemoryBarrier"); case SpvOpAtomicLoad: - return "AtomicLoad"; + return SkString("AtomicLoad"); case SpvOpAtomicStore: - return "AtomicStore"; + return SkString("AtomicStore"); case SpvOpAtomicExchange: - return "AtomicExchange"; + return SkString("AtomicExchange"); case SpvOpAtomicCompareExchange: - return "AtomicCompareExchange"; + return SkString("AtomicCompareExchange"); case SpvOpAtomicCompareExchangeWeak: - return "AtomicCompareExchangeWeak"; + return SkString("AtomicCompareExchangeWeak"); case SpvOpAtomicIIncrement: - return "AtomicIIncrement"; + return SkString("AtomicIIncrement"); case SpvOpAtomicIDecrement: - return "AtomicIDecrement"; + return SkString("AtomicIDecrement"); case SpvOpAtomicIAdd: - return "AtomicIAdd"; + return SkString("AtomicIAdd"); case SpvOpAtomicISub: - return "AtomicISub"; + return SkString("AtomicISub"); case SpvOpAtomicSMin: - return "AtomicSMin"; + return SkString("AtomicSMin"); case SpvOpAtomicUMin: - return "AtomicUMin"; + return SkString("AtomicUMin"); case SpvOpAtomicSMax: - return "AtomicSMax"; + return SkString("AtomicSMax"); case SpvOpAtomicUMax: - return "AtomicUMax"; + return SkString("AtomicUMax"); case SpvOpAtomicAnd: - return "AtomicAnd"; + return SkString("AtomicAnd"); case SpvOpAtomicOr: - return "AtomicOr"; + return SkString("AtomicOr"); case SpvOpAtomicXor: - return "AtomicXor"; + return SkString("AtomicXor"); case SpvOpPhi: - return "Phi"; + return SkString("Phi"); case SpvOpLoopMerge: - return "LoopMerge"; + return SkString("LoopMerge"); case SpvOpSelectionMerge: - return "SelectionMerge"; + return SkString("SelectionMerge"); case SpvOpLabel: - return "Label"; + return SkString("Label"); case SpvOpBranch: - return "Branch"; + return SkString("Branch"); case SpvOpBranchConditional: - return "BranchConditional"; + return SkString("BranchConditional"); case SpvOpSwitch: - return "Switch"; + return SkString("Switch"); case SpvOpKill: - return "Kill"; + return SkString("Kill"); case SpvOpReturn: - return "Return"; + return SkString("Return"); case SpvOpReturnValue: - return "ReturnValue"; + return SkString("ReturnValue"); case SpvOpUnreachable: - return "Unreachable"; + return SkString("Unreachable"); case SpvOpLifetimeStart: - return "LifetimeStart"; + return SkString("LifetimeStart"); case SpvOpLifetimeStop: - return "LifetimeStop"; + return SkString("LifetimeStop"); case SpvOpGroupAsyncCopy: - return "GroupAsyncCopy"; + return SkString("GroupAsyncCopy"); case SpvOpGroupWaitEvents: - return "GroupWaitEvents"; + return SkString("GroupWaitEvents"); case SpvOpGroupAll: - return "GroupAll"; + return SkString("GroupAll"); case SpvOpGroupAny: - return "GroupAny"; + return SkString("GroupAny"); case SpvOpGroupBroadcast: - return "GroupBroadcast"; + return SkString("GroupBroadcast"); case SpvOpGroupIAdd: - return "GroupIAdd"; + return SkString("GroupIAdd"); case SpvOpGroupFAdd: - return "GroupFAdd"; + return SkString("GroupFAdd"); case SpvOpGroupFMin: - return "GroupFMin"; + return SkString("GroupFMin"); case SpvOpGroupUMin: - return "GroupUMin"; + return SkString("GroupUMin"); case SpvOpGroupSMin: - return "GroupSMin"; + return SkString("GroupSMin"); case SpvOpGroupFMax: - return "GroupFMax"; + return SkString("GroupFMax"); case SpvOpGroupUMax: - return "GroupUMax"; + return SkString("GroupUMax"); case SpvOpGroupSMax: - return "GroupSMax"; + return SkString("GroupSMax"); case SpvOpReadPipe: - return "ReadPipe"; + return SkString("ReadPipe"); case SpvOpWritePipe: - return "WritePipe"; + return SkString("WritePipe"); case SpvOpReservedReadPipe: - return "ReservedReadPipe"; + return SkString("ReservedReadPipe"); case SpvOpReservedWritePipe: - return "ReservedWritePipe"; + return SkString("ReservedWritePipe"); case SpvOpReserveReadPipePackets: - return "ReserveReadPipePackets"; + return SkString("ReserveReadPipePackets"); case SpvOpReserveWritePipePackets: - return "ReserveWritePipePackets"; + return SkString("ReserveWritePipePackets"); case SpvOpCommitReadPipe: - return "CommitReadPipe"; + return SkString("CommitReadPipe"); case SpvOpCommitWritePipe: - return "CommitWritePipe"; + return SkString("CommitWritePipe"); case SpvOpIsValidReserveId: - return "IsValidReserveId"; + return SkString("IsValidReserveId"); case SpvOpGetNumPipePackets: - return "GetNumPipePackets"; + return SkString("GetNumPipePackets"); case SpvOpGetMaxPipePackets: - return "GetMaxPipePackets"; + return SkString("GetMaxPipePackets"); case SpvOpGroupReserveReadPipePackets: - return "GroupReserveReadPipePackets"; + return SkString("GroupReserveReadPipePackets"); case SpvOpGroupReserveWritePipePackets: - return "GroupReserveWritePipePackets"; + return SkString("GroupReserveWritePipePackets"); case SpvOpGroupCommitReadPipe: - return "GroupCommitReadPipe"; + return SkString("GroupCommitReadPipe"); case SpvOpGroupCommitWritePipe: - return "GroupCommitWritePipe"; + return SkString("GroupCommitWritePipe"); case SpvOpEnqueueMarker: - return "EnqueueMarker"; + return SkString("EnqueueMarker"); case SpvOpEnqueueKernel: - return "EnqueueKernel"; + return SkString("EnqueueKernel"); case SpvOpGetKernelNDrangeSubGroupCount: - return "GetKernelNDrangeSubGroupCount"; + return SkString("GetKernelNDrangeSubGroupCount"); case SpvOpGetKernelNDrangeMaxSubGroupSize: - return "GetKernelNDrangeMaxSubGroupSize"; + return SkString("GetKernelNDrangeMaxSubGroupSize"); case SpvOpGetKernelWorkGroupSize: - return "GetKernelWorkGroupSize"; + return SkString("GetKernelWorkGroupSize"); case SpvOpGetKernelPreferredWorkGroupSizeMultiple: - return "GetKernelPreferredWorkGroupSizeMultiple"; + return SkString("GetKernelPreferredWorkGroupSizeMultiple"); case SpvOpRetainEvent: - return "RetainEvent"; + return SkString("RetainEvent"); case SpvOpReleaseEvent: - return "ReleaseEvent"; + return SkString("ReleaseEvent"); case SpvOpCreateUserEvent: - return "CreateUserEvent"; + return SkString("CreateUserEvent"); case SpvOpIsValidEvent: - return "IsValidEvent"; + return SkString("IsValidEvent"); case SpvOpSetUserEventStatus: - return "SetUserEventStatus"; + return SkString("SetUserEventStatus"); case SpvOpCaptureEventProfilingInfo: - return "CaptureEventProfilingInfo"; + return SkString("CaptureEventProfilingInfo"); case SpvOpGetDefaultQueue: - return "GetDefaultQueue"; + return SkString("GetDefaultQueue"); case SpvOpBuildNDRange: - return "BuildNDRange"; + return SkString("BuildNDRange"); case SpvOpImageSparseSampleImplicitLod: - return "ImageSparseSampleImplicitLod"; + return SkString("ImageSparseSampleImplicitLod"); case SpvOpImageSparseSampleExplicitLod: - return "ImageSparseSampleExplicitLod"; + return SkString("ImageSparseSampleExplicitLod"); case SpvOpImageSparseSampleDrefImplicitLod: - return "ImageSparseSampleDrefImplicitLod"; + return SkString("ImageSparseSampleDrefImplicitLod"); case SpvOpImageSparseSampleDrefExplicitLod: - return "ImageSparseSampleDrefExplicitLod"; + return SkString("ImageSparseSampleDrefExplicitLod"); case SpvOpImageSparseSampleProjImplicitLod: - return "ImageSparseSampleProjImplicitLod"; + return SkString("ImageSparseSampleProjImplicitLod"); case SpvOpImageSparseSampleProjExplicitLod: - return "ImageSparseSampleProjExplicitLod"; + return SkString("ImageSparseSampleProjExplicitLod"); case SpvOpImageSparseSampleProjDrefImplicitLod: - return "ImageSparseSampleProjDrefImplicitLod"; + return SkString("ImageSparseSampleProjDrefImplicitLod"); case SpvOpImageSparseSampleProjDrefExplicitLod: - return "ImageSparseSampleProjDrefExplicitLod"; + return SkString("ImageSparseSampleProjDrefExplicitLod"); case SpvOpImageSparseFetch: - return "ImageSparseFetch"; + return SkString("ImageSparseFetch"); case SpvOpImageSparseGather: - return "ImageSparseGather"; + return SkString("ImageSparseGather"); case SpvOpImageSparseDrefGather: - return "ImageSparseDrefGather"; + return SkString("ImageSparseDrefGather"); case SpvOpImageSparseTexelsResident: - return "ImageSparseTexelsResident"; + return SkString("ImageSparseTexelsResident"); case SpvOpNoLine: - return "NoLine"; + return SkString("NoLine"); case SpvOpAtomicFlagTestAndSet: - return "AtomicFlagTestAndSet"; + return SkString("AtomicFlagTestAndSet"); case SpvOpAtomicFlagClear: - return "AtomicFlagClear"; + return SkString("AtomicFlagClear"); case SpvOpImageSparseRead: - return "ImageSparseRead"; + return SkString("ImageSparseRead"); default: ABORT("unsupported SPIR-V op"); } } #endif -void SPIRVCodeGenerator::writeOpCode(SpvOp_ opCode, int length, std::ostream& out) { +void SPIRVCodeGenerator::writeOpCode(SpvOp_ opCode, int length, SkWStream& out) { ASSERT(opCode != SpvOpUndef); switch (opCode) { case SpvOpReturn: // fall through @@ -825,39 +830,39 @@ void SPIRVCodeGenerator::writeOpCode(SpvOp_ opCode, int length, std::ostream& ou #endif } -void SPIRVCodeGenerator::writeLabel(SpvId label, std::ostream& out) { +void SPIRVCodeGenerator::writeLabel(SpvId label, SkWStream& out) { fCurrentBlock = label; this->writeInstruction(SpvOpLabel, label, out); } -void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, std::ostream& out) { +void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, SkWStream& out) { this->writeOpCode(opCode, 1, out); } -void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, std::ostream& 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, std::ostream& out) { +void SPIRVCodeGenerator::writeString(const char* string, SkWStream& out) { size_t length = strlen(string); - out << string; + out.writeText(string); switch (length % 4) { case 1: - out << (char) 0; + out.write8(0); // fall through case 2: - out << (char) 0; + out.write8(0); // fall through case 3: - out << (char) 0; + out.write8(0); break; default: this->writeWord(0, out); } } -void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, const char* string, std::ostream& 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); @@ -865,7 +870,7 @@ void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, const char* string, std void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, const char* string, - std::ostream& out) { + SkWStream& out) { int32_t length = (int32_t) strlen(string); this->writeOpCode(opCode, 2 + (length + 4) / 4, out); this->writeWord(word1, out); @@ -873,7 +878,7 @@ void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, const ch } void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, - const char* string, std::ostream& 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); @@ -882,14 +887,14 @@ void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t } void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, - std::ostream& 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, std::ostream& out) { + int32_t word3, SkWStream& out) { this->writeOpCode(opCode, 4, out); this->writeWord(word1, out); this->writeWord(word2, out); @@ -897,7 +902,7 @@ void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t } void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, - int32_t word3, int32_t word4, std::ostream& out) { + int32_t word3, int32_t word4, SkWStream& out) { this->writeOpCode(opCode, 5, out); this->writeWord(word1, out); this->writeWord(word2, out); @@ -907,7 +912,7 @@ void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, int32_t word5, - std::ostream& out) { + SkWStream& out) { this->writeOpCode(opCode, 6, out); this->writeWord(word1, out); this->writeWord(word2, out); @@ -918,7 +923,7 @@ void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, int32_t word5, - int32_t word6, std::ostream& out) { + int32_t word6, SkWStream& out) { this->writeOpCode(opCode, 7, out); this->writeWord(word1, out); this->writeWord(word2, out); @@ -930,7 +935,7 @@ void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t 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, std::ostream& out) { + int32_t word6, int32_t word7, SkWStream& out) { this->writeOpCode(opCode, 8, out); this->writeWord(word1, out); this->writeWord(word2, out); @@ -944,7 +949,7 @@ void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t 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, - std::ostream& out) { + SkWStream& out) { this->writeOpCode(opCode, 9, out); this->writeWord(word1, out); this->writeWord(word2, out); @@ -956,7 +961,7 @@ void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t this->writeWord(word8, out); } -void SPIRVCodeGenerator::writeCapabilities(std::ostream& 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); @@ -1007,7 +1012,6 @@ void SPIRVCodeGenerator::writeStruct(const Type& type, SpvId resultId) { if ((kind == Type::kArray_Kind || kind == Type::kStruct_Kind) && offset % alignment != 0) { offset += alignment - offset % alignment; } - ASSERT(offset % alignment == 0); } } @@ -1082,8 +1086,8 @@ SpvId SPIRVCodeGenerator::getType(const Type& type) { } SpvId SPIRVCodeGenerator::getFunctionType(const FunctionDeclaration& function) { - std::string key = function.fReturnType.description() + "("; - std::string separator = ""; + SkString key = function.fReturnType.description() + "("; + SkString separator; for (size_t i = 0; i < function.fParameters.size(); i++) { key += separator; separator = ", "; @@ -1140,7 +1144,7 @@ SpvId SPIRVCodeGenerator::getFunctionType(const FunctionDeclaration& function) { SpvId SPIRVCodeGenerator::getPointerType(const Type& type, SpvStorageClass_ storageClass) { - std::string key = type.description() + "*" + to_string(storageClass); + SkString key = type.description() + "*" + to_string(storageClass); auto entry = fTypeMap.find(key); if (entry == fTypeMap.end()) { SpvId result = this->nextId(); @@ -1152,7 +1156,7 @@ SpvId SPIRVCodeGenerator::getPointerType(const Type& type, return entry->second; } -SpvId SPIRVCodeGenerator::writeExpression(const Expression& expr, std::ostream& out) { +SpvId SPIRVCodeGenerator::writeExpression(const Expression& expr, SkWStream& out) { switch (expr.fKind) { case Expression::kBinary_Kind: return this->writeBinaryExpression((BinaryExpression&) expr, out); @@ -1186,7 +1190,7 @@ SpvId SPIRVCodeGenerator::writeExpression(const Expression& expr, std::ostream& return -1; } -SpvId SPIRVCodeGenerator::writeIntrinsicCall(const FunctionCall& c, std::ostream& 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; @@ -1242,7 +1246,7 @@ SpvId SPIRVCodeGenerator::writeIntrinsicCall(const FunctionCall& c, std::ostream } SpvId SPIRVCodeGenerator::writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, - std::ostream& out) { + SkWStream& out) { SpvId result = this->nextId(); switch (kind) { case kAtan_SpecialIntrinsic: { @@ -1306,7 +1310,7 @@ SpvId SPIRVCodeGenerator::writeSpecialIntrinsic(const FunctionCall& c, SpecialIn return result; } -SpvId SPIRVCodeGenerator::writeFunctionCall(const FunctionCall& c, std::ostream& 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); @@ -1395,7 +1399,7 @@ SpvId SPIRVCodeGenerator::writeConstantVector(const Constructor& c) { return result; } -SpvId SPIRVCodeGenerator::writeFloatConstructor(const Constructor& c, std::ostream& 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()); @@ -1413,7 +1417,7 @@ SpvId SPIRVCodeGenerator::writeFloatConstructor(const Constructor& c, std::ostre return result; } -SpvId SPIRVCodeGenerator::writeIntConstructor(const Constructor& c, std::ostream& 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()); @@ -1431,7 +1435,7 @@ SpvId SPIRVCodeGenerator::writeIntConstructor(const Constructor& c, std::ostream return result; } -SpvId SPIRVCodeGenerator::writeMatrixConstructor(const Constructor& c, std::ostream& 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 @@ -1503,7 +1507,7 @@ SpvId SPIRVCodeGenerator::writeMatrixConstructor(const Constructor& c, std::ostr return result; } -SpvId SPIRVCodeGenerator::writeVectorConstructor(const Constructor& c, std::ostream& out) { +SpvId SPIRVCodeGenerator::writeVectorConstructor(const Constructor& c, SkWStream& out) { ASSERT(c.fType.kind() == Type::kVector_Kind); if (c.isConstant()) { return this->writeConstantVector(c); @@ -1533,7 +1537,7 @@ SpvId SPIRVCodeGenerator::writeVectorConstructor(const Constructor& c, std::ostr return result; } -SpvId SPIRVCodeGenerator::writeConstructor(const Constructor& c, std::ostream& 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) { @@ -1574,7 +1578,7 @@ SpvStorageClass_ get_storage_class(const Expression& expr) { } } -std::vector SPIRVCodeGenerator::getAccessChain(const Expression& expr, std::ostream& out) { +std::vector SPIRVCodeGenerator::getAccessChain(const Expression& expr, SkWStream& out) { std::vector chain; switch (expr.fKind) { case Expression::kIndex_Kind: { @@ -1607,13 +1611,13 @@ public: return fPointer; } - virtual SpvId load(std::ostream& 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, std::ostream& out) override { + virtual void store(SpvId value, SkWStream& out) override { fGen.writeInstruction(SpvOpStore, fPointer, value, out); } @@ -1637,7 +1641,7 @@ public: return 0; } - virtual SpvId load(std::ostream& 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(); @@ -1652,7 +1656,7 @@ public: return result; } - virtual void store(SpvId value, std::ostream& 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 @@ -1699,7 +1703,7 @@ private: }; std::unique_ptr SPIRVCodeGenerator::getLValue(const Expression& expr, - std::ostream& out) { + SkWStream& out) { switch (expr.fKind) { case Expression::kVariableReference_Kind: { const Variable& var = ((VariableReference&) expr).fVariable; @@ -1772,7 +1776,7 @@ std::unique_ptr SPIRVCodeGenerator::getLValue(const } } -SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, std::ostream& out) { +SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, SkWStream& out) { auto entry = fVariableMap.find(&ref.fVariable); ASSERT(entry != fVariableMap.end()); SpvId var = entry->second; @@ -1781,15 +1785,15 @@ SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, s return result; } -SpvId SPIRVCodeGenerator::writeIndexExpression(const IndexExpression& expr, std::ostream& out) { +SpvId SPIRVCodeGenerator::writeIndexExpression(const IndexExpression& expr, SkWStream& out) { return getLValue(expr, out)->load(out); } -SpvId SPIRVCodeGenerator::writeFieldAccess(const FieldAccess& f, std::ostream& out) { +SpvId SPIRVCodeGenerator::writeFieldAccess(const FieldAccess& f, SkWStream& out) { return getLValue(f, out)->load(out); } -SpvId SPIRVCodeGenerator::writeSwizzle(const Swizzle& swizzle, std::ostream& 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(); @@ -1812,7 +1816,7 @@ SpvId SPIRVCodeGenerator::writeSwizzle(const Swizzle& swizzle, std::ostream& out SpvId SPIRVCodeGenerator::writeBinaryOperation(const Type& resultType, const Type& operandType, SpvId lhs, SpvId rhs, SpvOp_ ifFloat, SpvOp_ ifInt, - SpvOp_ ifUInt, SpvOp_ ifBool, std::ostream& 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); @@ -1850,7 +1854,7 @@ bool is_assignment(Token::Kind op) { } } -SpvId SPIRVCodeGenerator::writeBinaryExpression(const BinaryExpression& b, std::ostream& 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: { @@ -2042,7 +2046,7 @@ SpvId SPIRVCodeGenerator::writeBinaryExpression(const BinaryExpression& b, std:: } } -SpvId SPIRVCodeGenerator::writeLogicalAnd(const BinaryExpression& a, std::ostream& out) { +SpvId SPIRVCodeGenerator::writeLogicalAnd(const BinaryExpression& a, SkWStream& out) { ASSERT(a.fOperator == Token::LOGICALAND); BoolLiteral falseLiteral(fContext, Position(), false); SpvId falseConstant = this->writeBoolLiteral(falseLiteral); @@ -2063,7 +2067,7 @@ SpvId SPIRVCodeGenerator::writeLogicalAnd(const BinaryExpression& a, std::ostrea return result; } -SpvId SPIRVCodeGenerator::writeLogicalOr(const BinaryExpression& o, std::ostream& out) { +SpvId SPIRVCodeGenerator::writeLogicalOr(const BinaryExpression& o, SkWStream& out) { ASSERT(o.fOperator == Token::LOGICALOR); BoolLiteral trueLiteral(fContext, Position(), true); SpvId trueConstant = this->writeBoolLiteral(trueLiteral); @@ -2084,7 +2088,7 @@ SpvId SPIRVCodeGenerator::writeLogicalOr(const BinaryExpression& o, std::ostream return result; } -SpvId SPIRVCodeGenerator::writeTernaryExpression(const TernaryExpression& t, std::ostream& 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 @@ -2128,7 +2132,7 @@ std::unique_ptr create_literal_1(const Context& context, const Type& } } -SpvId SPIRVCodeGenerator::writePrefixExpression(const PrefixExpression& p, std::ostream& out) { +SpvId SPIRVCodeGenerator::writePrefixExpression(const PrefixExpression& p, SkWStream& out) { if (p.fOperator == Token::MINUS) { SpvId result = this->nextId(); SpvId typeId = this->getType(p.fType); @@ -2181,7 +2185,7 @@ SpvId SPIRVCodeGenerator::writePrefixExpression(const PrefixExpression& p, std:: } } -SpvId SPIRVCodeGenerator::writePostfixExpression(const PostfixExpression& p, std::ostream& out) { +SpvId SPIRVCodeGenerator::writePostfixExpression(const PostfixExpression& p, SkWStream& out) { std::unique_ptr lv = this->getLValue(*p.fOperand, out); SpvId result = lv->load(out); SpvId one = this->writeExpression(*create_literal_1(fContext, p.fType), out); @@ -2278,7 +2282,7 @@ SpvId SPIRVCodeGenerator::writeFloatLiteral(const FloatLiteral& f) { } } -SpvId SPIRVCodeGenerator::writeFunctionStart(const FunctionDeclaration& f, std::ostream& 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); @@ -2293,17 +2297,16 @@ SpvId SPIRVCodeGenerator::writeFunctionStart(const FunctionDeclaration& f, std:: return result; } -SpvId SPIRVCodeGenerator::writeFunction(const FunctionDefinition& f, std::ostream& out) { +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") { - out << fGlobalInitializersBuffer.str(); + write_data(*fGlobalInitializersBuffer.detachAsData(), out); } - std::stringstream bodyBuffer; + SkDynamicMemoryWStream bodyBuffer; this->writeBlock(*f.fBody, bodyBuffer); - out << fVariableBuffer.str(); - fVariableBuffer.str(""); - out << bodyBuffer.str(); + write_data(*fVariableBuffer.detachAsData(), out); + write_data(*bodyBuffer.detachAsData(), out); if (fCurrentBlock) { this->writeInstruction(SpvOpReturn, out); } @@ -2372,7 +2375,7 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) { #define BUILTIN_IGNORE 9999 void SPIRVCodeGenerator::writeGlobalVars(Program::Kind kind, const VarDeclarations& decl, - std::ostream& out) { + SkWStream& out) { for (size_t i = 0; i < decl.fVars.size(); i++) { const VarDeclaration& varDecl = decl.fVars[i]; const Variable* var = varDecl.fVar; @@ -2427,7 +2430,7 @@ void SPIRVCodeGenerator::writeGlobalVars(Program::Kind kind, const VarDeclaratio } } -void SPIRVCodeGenerator::writeVarDeclarations(const VarDeclarations& decl, std::ostream& out) { +void SPIRVCodeGenerator::writeVarDeclarations(const VarDeclarations& decl, SkWStream& out) { for (const auto& varDecl : decl.fVars) { const Variable* var = varDecl.fVar; SpvId id = this->nextId(); @@ -2442,7 +2445,7 @@ void SPIRVCodeGenerator::writeVarDeclarations(const VarDeclarations& decl, std:: } } -void SPIRVCodeGenerator::writeStatement(const Statement& s, std::ostream& out) { +void SPIRVCodeGenerator::writeStatement(const Statement& s, SkWStream& out) { switch (s.fKind) { case Statement::kBlock_Kind: this->writeBlock((Block&) s, out); @@ -2476,13 +2479,13 @@ void SPIRVCodeGenerator::writeStatement(const Statement& s, std::ostream& out) { } } -void SPIRVCodeGenerator::writeBlock(const Block& b, std::ostream& 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, std::ostream& out) { +void SPIRVCodeGenerator::writeIfStatement(const IfStatement& stmt, SkWStream& out) { SpvId test = this->writeExpression(*stmt.fTest, out); SpvId ifTrue = this->nextId(); SpvId ifFalse = this->nextId(); @@ -2513,7 +2516,7 @@ void SPIRVCodeGenerator::writeIfStatement(const IfStatement& stmt, std::ostream& } } -void SPIRVCodeGenerator::writeForStatement(const ForStatement& f, std::ostream& out) { +void SPIRVCodeGenerator::writeForStatement(const ForStatement& f, SkWStream& out) { if (f.fInitializer) { this->writeStatement(*f.fInitializer, out); } @@ -2548,7 +2551,7 @@ void SPIRVCodeGenerator::writeForStatement(const ForStatement& f, std::ostream& fContinueTarget.pop(); } -void SPIRVCodeGenerator::writeReturnStatement(const ReturnStatement& r, std::ostream& out) { +void SPIRVCodeGenerator::writeReturnStatement(const ReturnStatement& r, SkWStream& out) { if (r.fExpression) { this->writeInstruction(SpvOpReturnValue, this->writeExpression(*r.fExpression, out), out); @@ -2557,9 +2560,9 @@ void SPIRVCodeGenerator::writeReturnStatement(const ReturnStatement& r, std::ost } } -void SPIRVCodeGenerator::writeInstructions(const Program& program, std::ostream& out) { +void SPIRVCodeGenerator::writeInstructions(const Program& program, SkWStream& out) { fGLSLExtendedInstructions = this->nextId(); - std::stringstream body; + SkDynamicMemoryWStream body; std::vector interfaceVars; // assign IDs to functions for (size_t i = 0; i < program.fElements.size(); i++) { @@ -2636,22 +2639,22 @@ void SPIRVCodeGenerator::writeInstructions(const Program& program, std::ostream& } } - out << fNameBuffer.str(); - out << fDecorationBuffer.str(); - out << fConstantBuffer.str(); - out << fExternalFunctionsBuffer.str(); - out << body.str(); + 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); } -void SPIRVCodeGenerator::generateCode(const Program& program, std::ostream& out) { +void SPIRVCodeGenerator::generateCode(const Program& program, SkWStream& out) { this->writeWord(SpvMagicNumber, out); this->writeWord(SpvVersion, out); this->writeWord(SKSL_MAGIC, out); - std::stringstream buffer; + SkDynamicMemoryWStream buffer; this->writeInstructions(program, buffer); this->writeWord(fIdCount, out); this->writeWord(0, out); // reserved, always zero - out << buffer.str(); + write_data(*buffer.detachAsData(), out); } } diff --git a/src/sksl/SkSLSPIRVCodeGenerator.h b/src/sksl/SkSLSPIRVCodeGenerator.h index e6fc28ee0c..84c582e53e 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.h +++ b/src/sksl/SkSLSPIRVCodeGenerator.h @@ -8,11 +8,11 @@ #ifndef SKSL_SPIRVCODEGENERATOR #define SKSL_SPIRVCODEGENERATOR -#include #include #include #include +#include "SkStream.h" #include "SkSLCodeGenerator.h" #include "ir/SkSLBinaryExpression.h" #include "ir/SkSLBoolLiteral.h" @@ -56,9 +56,9 @@ public: // by a pointer (e.g. vector swizzles), returns 0. virtual SpvId getPointer() = 0; - virtual SpvId load(std::ostream& out) = 0; + virtual SpvId load(SkWStream& out) = 0; - virtual void store(SpvId value, std::ostream& out) = 0; + virtual void store(SpvId value, SkWStream& out) = 0; }; SPIRVCodeGenerator(const Context* context) @@ -71,7 +71,7 @@ public: this->setupIntrinsics(); } - void generateCode(const Program& program, std::ostream& out) override; + void generateCode(const Program& program, SkWStream& out) override; private: enum IntrinsicKind { @@ -97,7 +97,7 @@ private: SpvId getPointerType(const Type& type, SpvStorageClass_ storageClass); - std::vector getAccessChain(const Expression& expr, std::ostream& out); + std::vector getAccessChain(const Expression& expr, SkWStream& out); void writeLayout(const Layout& layout, SpvId target); @@ -105,68 +105,68 @@ private: void writeStruct(const Type& type, SpvId resultId); - void writeProgramElement(const ProgramElement& pe, std::ostream& out); + void writeProgramElement(const ProgramElement& pe, SkWStream& out); SpvId writeInterfaceBlock(const InterfaceBlock& intf); - SpvId writeFunctionStart(const FunctionDeclaration& f, std::ostream& out); + SpvId writeFunctionStart(const FunctionDeclaration& f, SkWStream& out); - SpvId writeFunctionDeclaration(const FunctionDeclaration& f, std::ostream& out); + SpvId writeFunctionDeclaration(const FunctionDeclaration& f, SkWStream& out); - SpvId writeFunction(const FunctionDefinition& f, std::ostream& out); + SpvId writeFunction(const FunctionDefinition& f, SkWStream& out); - void writeGlobalVars(Program::Kind kind, const VarDeclarations& v, std::ostream& out); + void writeGlobalVars(Program::Kind kind, const VarDeclarations& v, SkWStream& out); - void writeVarDeclarations(const VarDeclarations& decl, std::ostream& out); + void writeVarDeclarations(const VarDeclarations& decl, SkWStream& out); - SpvId writeVariableReference(const VariableReference& ref, std::ostream& out); + SpvId writeVariableReference(const VariableReference& ref, SkWStream& out); - std::unique_ptr getLValue(const Expression& value, std::ostream& out); + std::unique_ptr getLValue(const Expression& value, SkWStream& out); - SpvId writeExpression(const Expression& expr, std::ostream& out); + SpvId writeExpression(const Expression& expr, SkWStream& out); - SpvId writeIntrinsicCall(const FunctionCall& c, std::ostream& out); + SpvId writeIntrinsicCall(const FunctionCall& c, SkWStream& out); - SpvId writeFunctionCall(const FunctionCall& c, std::ostream& out); + SpvId writeFunctionCall(const FunctionCall& c, SkWStream& out); - SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, std::ostream& out); + SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, SkWStream& out); SpvId writeConstantVector(const Constructor& c); - SpvId writeFloatConstructor(const Constructor& c, std::ostream& out); + SpvId writeFloatConstructor(const Constructor& c, SkWStream& out); - SpvId writeIntConstructor(const Constructor& c, std::ostream& out); + SpvId writeIntConstructor(const Constructor& c, SkWStream& out); - SpvId writeMatrixConstructor(const Constructor& c, std::ostream& out); + SpvId writeMatrixConstructor(const Constructor& c, SkWStream& out); - SpvId writeVectorConstructor(const Constructor& c, std::ostream& out); + SpvId writeVectorConstructor(const Constructor& c, SkWStream& out); - SpvId writeConstructor(const Constructor& c, std::ostream& out); + SpvId writeConstructor(const Constructor& c, SkWStream& out); - SpvId writeFieldAccess(const FieldAccess& f, std::ostream& out); + SpvId writeFieldAccess(const FieldAccess& f, SkWStream& out); - SpvId writeSwizzle(const Swizzle& swizzle, std::ostream& out); + SpvId writeSwizzle(const Swizzle& swizzle, SkWStream& out); SpvId writeBinaryOperation(const Type& resultType, const Type& operandType, SpvId lhs, SpvId rhs, SpvOp_ ifFloat, SpvOp_ ifInt, SpvOp_ ifUInt, - SpvOp_ ifBool, std::ostream& out); + SpvOp_ ifBool, SkWStream& out); SpvId writeBinaryOperation(const BinaryExpression& expr, SpvOp_ ifFloat, SpvOp_ ifInt, - SpvOp_ ifUInt, std::ostream& out); + SpvOp_ ifUInt, SkWStream& out); - SpvId writeBinaryExpression(const BinaryExpression& b, std::ostream& out); + SpvId writeBinaryExpression(const BinaryExpression& b, SkWStream& out); - SpvId writeTernaryExpression(const TernaryExpression& t, std::ostream& out); + SpvId writeTernaryExpression(const TernaryExpression& t, SkWStream& out); - SpvId writeIndexExpression(const IndexExpression& expr, std::ostream& out); + SpvId writeIndexExpression(const IndexExpression& expr, SkWStream& out); - SpvId writeLogicalAnd(const BinaryExpression& b, std::ostream& out); + SpvId writeLogicalAnd(const BinaryExpression& b, SkWStream& out); - SpvId writeLogicalOr(const BinaryExpression& o, std::ostream& out); + SpvId writeLogicalOr(const BinaryExpression& o, SkWStream& out); - SpvId writePrefixExpression(const PrefixExpression& p, std::ostream& out); + SpvId writePrefixExpression(const PrefixExpression& p, SkWStream& out); - SpvId writePostfixExpression(const PostfixExpression& p, std::ostream& out); + SpvId writePostfixExpression(const PostfixExpression& p, SkWStream& out); SpvId writeBoolLiteral(const BoolLiteral& b); @@ -174,59 +174,59 @@ private: SpvId writeFloatLiteral(const FloatLiteral& f); - void writeStatement(const Statement& s, std::ostream& out); + void writeStatement(const Statement& s, SkWStream& out); - void writeBlock(const Block& b, std::ostream& out); + void writeBlock(const Block& b, SkWStream& out); - void writeIfStatement(const IfStatement& stmt, std::ostream& out); + void writeIfStatement(const IfStatement& stmt, SkWStream& out); - void writeForStatement(const ForStatement& f, std::ostream& out); + void writeForStatement(const ForStatement& f, SkWStream& out); - void writeReturnStatement(const ReturnStatement& r, std::ostream& out); + void writeReturnStatement(const ReturnStatement& r, SkWStream& out); - void writeCapabilities(std::ostream& out); + void writeCapabilities(SkWStream& out); - void writeInstructions(const Program& program, std::ostream& out); + void writeInstructions(const Program& program, SkWStream& out); - void writeOpCode(SpvOp_ opCode, int length, std::ostream& out); + void writeOpCode(SpvOp_ opCode, int length, SkWStream& out); - void writeWord(int32_t word, std::ostream& out); + void writeWord(int32_t word, SkWStream& out); - void writeString(const char* string, std::ostream& out); + void writeString(const char* string, SkWStream& out); - void writeLabel(SpvId id, std::ostream& out); + void writeLabel(SpvId id, SkWStream& out); - void writeInstruction(SpvOp_ opCode, std::ostream& out); + void writeInstruction(SpvOp_ opCode, SkWStream& out); - void writeInstruction(SpvOp_ opCode, const char* string, std::ostream& out); + void writeInstruction(SpvOp_ opCode, const char* string, SkWStream& out); - void writeInstruction(SpvOp_ opCode, int32_t word1, std::ostream& out); + void writeInstruction(SpvOp_ opCode, int32_t word1, SkWStream& out); - void writeInstruction(SpvOp_ opCode, int32_t word1, const char* string, std::ostream& 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, - std::ostream& out); + SkWStream& out); - void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, std::ostream& 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, - std::ostream& out); + SkWStream& out); void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, - std::ostream& out); + SkWStream& out); void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4, - int32_t word5, std::ostream& 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, std::ostream& 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, std::ostream& 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, - std::ostream& out); + SkWStream& out); const Context& fContext; @@ -234,18 +234,18 @@ private: SpvId fIdCount; SpvId fGLSLExtendedInstructions; typedef std::tuple Intrinsic; - std::unordered_map fIntrinsicMap; + std::unordered_map fIntrinsicMap; std::unordered_map fFunctionMap; std::unordered_map fVariableMap; std::unordered_map fInterfaceBlockMap; - std::unordered_map fTypeMap; - std::stringstream fCapabilitiesBuffer; - std::stringstream fGlobalInitializersBuffer; - std::stringstream fConstantBuffer; - std::stringstream fExternalFunctionsBuffer; - std::stringstream fVariableBuffer; - std::stringstream fNameBuffer; - std::stringstream fDecorationBuffer; + std::unordered_map fTypeMap; + SkDynamicMemoryWStream fCapabilitiesBuffer; + SkDynamicMemoryWStream fGlobalInitializersBuffer; + SkDynamicMemoryWStream fConstantBuffer; + SkDynamicMemoryWStream fExternalFunctionsBuffer; + SkDynamicMemoryWStream fVariableBuffer; + SkDynamicMemoryWStream fNameBuffer; + SkDynamicMemoryWStream fDecorationBuffer; SpvId fBoolTrue; SpvId fBoolFalse; diff --git a/src/sksl/SkSLToken.h b/src/sksl/SkSLToken.h index 76a1df7f66..6fe130fe4a 100644 --- a/src/sksl/SkSLToken.h +++ b/src/sksl/SkSLToken.h @@ -103,45 +103,45 @@ struct Token { INVALID_TOKEN }; - static std::string OperatorName(Kind kind) { + static SkString OperatorName(Kind kind) { switch (kind) { - case Token::PLUS: return "+"; - case Token::MINUS: return "-"; - case Token::STAR: return "*"; - case Token::SLASH: return "/"; - case Token::PERCENT: return "%"; - case Token::SHL: return "<<"; - case Token::SHR: return ">>"; - case Token::LOGICALNOT: return "!"; - case Token::LOGICALAND: return "&&"; - case Token::LOGICALOR: return "||"; - case Token::LOGICALXOR: return "^^"; - case Token::BITWISENOT: return "~"; - case Token::BITWISEAND: return "&"; - case Token::BITWISEOR: return "|"; - case Token::BITWISEXOR: return "^"; - case Token::EQ: return "="; - case Token::EQEQ: return "=="; - case Token::NEQ: return "!="; - case Token::LT: return "<"; - case Token::GT: return ">"; - case Token::LTEQ: return "<="; - case Token::GTEQ: return ">="; - case Token::PLUSEQ: return "+="; - case Token::MINUSEQ: return "-="; - case Token::STAREQ: return "*="; - case Token::SLASHEQ: return "/="; - case Token::PERCENTEQ: return "%="; - case Token::SHLEQ: return "<<="; - case Token::SHREQ: return ">>="; - case Token::LOGICALANDEQ: return "&&="; - case Token::LOGICALOREQ: return "||="; - case Token::LOGICALXOREQ: return "^^="; - case Token::BITWISEANDEQ: return "&="; - case Token::BITWISEOREQ: return "|="; - case Token::BITWISEXOREQ: return "^="; - case Token::PLUSPLUS: return "++"; - case Token::MINUSMINUS: return "--"; + 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); } @@ -150,7 +150,7 @@ struct Token { Token() { } - Token(Position position, Kind kind, std::string text) + Token(Position position, Kind kind, SkString text) : fPosition(position) , fKind(kind) , fText(std::move(text)) {} @@ -159,7 +159,7 @@ struct Token { Kind fKind; // will be the empty string unless the token has variable text content (identifiers, numeric // literals, and directives) - std::string fText; + SkString fText; }; } // namespace diff --git a/src/sksl/SkSLUtil.cpp b/src/sksl/SkSLUtil.cpp index 51ad9fe808..98e5fa4599 100644 --- a/src/sksl/SkSLUtil.cpp +++ b/src/sksl/SkSLUtil.cpp @@ -7,61 +7,66 @@ #include "SkSLUtil.h" +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif +#include + namespace SkSL { -std::string to_string(double value) { - std::stringstream buffer; - buffer << std::setprecision(std::numeric_limits::digits10) << value; - std::string result = buffer.str(); - if (result.find_last_of(".") == std::string::npos && - result.find_last_of("e") == std::string::npos) { +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 } -std::string to_string(int32_t value) { - std::stringstream buffer; - buffer << value; - return buffer.str(); +SkString to_string(int32_t value) { + return SkStringPrintf("%d", value); } -std::string to_string(uint32_t value) { - std::stringstream buffer; - buffer << value; - return buffer.str(); +SkString to_string(uint32_t value) { + return SkStringPrintf("%u", value); } -std::string to_string(int64_t value) { - std::stringstream buffer; - buffer << value; - return buffer.str(); +SkString to_string(int64_t value) { + return SkStringPrintf("%" PRId64, value); } -std::string to_string(uint64_t value) { - std::stringstream buffer; - buffer << value; - return buffer.str(); +SkString to_string(uint64_t value) { + return SkStringPrintf("%" PRIu64, value); } -int stoi(std::string s) { +int stoi(SkString s) { if (s.size() > 2 && s[0] == '0' && s[1] == 'x') { char* p; - int result = strtoul(s.substr(2).c_str(), &p, 16); + int result = strtoul(s.c_str() + 2, &p, 16); ASSERT(*p == 0); return result; } return atoi(s.c_str()); } -double stod(std::string s) { +double stod(SkString s) { return atof(s.c_str()); } -long stol(std::string s) { +long stol(SkString s) { if (s.size() > 2 && s[0] == '0' && s[1] == 'x') { char* p; - long result = strtoul(s.substr(2).c_str(), &p, 16); + long result = strtoul(s.c_str() + 2, &p, 16); ASSERT(*p == 0); return result; } @@ -77,4 +82,37 @@ void sksl_abort() { #endif } +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 diff --git a/src/sksl/SkSLUtil.h b/src/sksl/SkSLUtil.h index ede21830e5..ad8287e39f 100644 --- a/src/sksl/SkSLUtil.h +++ b/src/sksl/SkSLUtil.h @@ -8,12 +8,12 @@ #ifndef SKSL_UTIL #define SKSL_UTIL -#include -#include -#include #include "stdlib.h" #include "assert.h" +#include "SkOpts.h" #include "SkRefCnt.h" +#include "SkStream.h" +#include "SkString.h" #include "SkTypes.h" #include "glsl/GrGLSLCaps.h" #include "GrContextOptions.h" @@ -73,40 +73,47 @@ public: } }; -// our own definitions of certain std:: functions, because they are not always present on Android +void write_data(const SkData& d, SkWStream& out); -std::string to_string(double value); +SkString operator+(const SkString& s, const char* c); -std::string to_string(int32_t value); +SkString operator+(const char* c, const SkString& s); -std::string to_string(uint32_t value); +SkString operator+(const SkString& s1, const SkString& s2); -std::string to_string(int64_t value); +bool operator==(const SkString& s1, const char* s2); -std::string to_string(uint64_t value); +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(std::string s); +int stoi(SkString s); -double stod(std::string s); +double stod(SkString s); -long stol(std::string s); +long stol(SkString s); NORETURN void sksl_abort(); } // namespace -#ifdef DEBUG -#define ASSERT(x) assert(x) -#define ASSERT_RESULT(x) ASSERT(x); -#else -#define ASSERT(x) -#define ASSERT_RESULT(x) x -#endif +#define ASSERT(x) SkASSERT(x) +#define ASSERT_RESULT(x) SkAssertResult(x); #ifdef SKIA #define ABORT(...) { SkDebugf(__VA_ARGS__); sksl_abort(); } @@ -114,4 +121,11 @@ NORETURN void sksl_abort(); #define ABORT(...) { sksl_abort(); } #endif +namespace std { + template<> struct hash { + size_t operator()(const SkString& s) const { + return SkOpts::hash_fn(s.c_str(), s.size(), 0); + } + }; +} #endif diff --git a/src/sksl/ast/SkSLASTBinaryExpression.h b/src/sksl/ast/SkSLASTBinaryExpression.h index 88feba66a7..c4b6e3a45b 100644 --- a/src/sksl/ast/SkSLASTBinaryExpression.h +++ b/src/sksl/ast/SkSLASTBinaryExpression.h @@ -10,7 +10,6 @@ #include "SkSLASTExpression.h" #include "../SkSLToken.h" -#include namespace SkSL { @@ -25,7 +24,7 @@ struct ASTBinaryExpression : public ASTExpression { , fOperator(op.fKind) , fRight(std::move(right)) {} - std::string description() const override { + SkString description() const override { return "(" + fLeft->description() + " " + Token::OperatorName(fOperator) + " " + fRight->description() + ")"; } diff --git a/src/sksl/ast/SkSLASTBlock.h b/src/sksl/ast/SkSLASTBlock.h index 09450a3db8..6b1e9c5551 100644 --- a/src/sksl/ast/SkSLASTBlock.h +++ b/src/sksl/ast/SkSLASTBlock.h @@ -20,8 +20,8 @@ struct ASTBlock : public ASTStatement { : INHERITED(position, kBlock_Kind) , fStatements(std::move(statements)) {} - std::string description() const override { - std::string result("{"); + SkString description() const override { + SkString result("{"); for (size_t i = 0; i < fStatements.size(); i++) { result += "\n"; result += fStatements[i]->description(); diff --git a/src/sksl/ast/SkSLASTBoolLiteral.h b/src/sksl/ast/SkSLASTBoolLiteral.h index ff58822952..02f4bac0da 100644 --- a/src/sksl/ast/SkSLASTBoolLiteral.h +++ b/src/sksl/ast/SkSLASTBoolLiteral.h @@ -20,8 +20,8 @@ struct ASTBoolLiteral : public ASTExpression { : INHERITED(position, kBool_Kind) , fValue(value) {} - std::string description() const override { - return fValue ? "true" : "false"; + SkString description() const override { + return SkString(fValue ? "true" : "false"); } const bool fValue; diff --git a/src/sksl/ast/SkSLASTBreakStatement.h b/src/sksl/ast/SkSLASTBreakStatement.h index ede548cc24..dad2a85c0a 100644 --- a/src/sksl/ast/SkSLASTBreakStatement.h +++ b/src/sksl/ast/SkSLASTBreakStatement.h @@ -19,8 +19,8 @@ struct ASTBreakStatement : public ASTStatement { ASTBreakStatement(Position position) : INHERITED(position, kBreak_Kind) {} - std::string description() const override { - return "break;"; + SkString description() const override { + return SkString("break;"); } typedef ASTStatement INHERITED; diff --git a/src/sksl/ast/SkSLASTCallSuffix.h b/src/sksl/ast/SkSLASTCallSuffix.h index 5cff6f6c93..356ac850f9 100644 --- a/src/sksl/ast/SkSLASTCallSuffix.h +++ b/src/sksl/ast/SkSLASTCallSuffix.h @@ -8,7 +8,6 @@ #ifndef SKSL_ASTCALLSUFFIX #define SKSL_ASTCALLSUFFIX -#include #include #include "SkSLASTSuffix.h" @@ -22,9 +21,9 @@ struct ASTCallSuffix : public ASTSuffix { : INHERITED(position, ASTSuffix::kCall_Kind) , fArguments(std::move(arguments)) {} - std::string description() const override { - std::string result("("); - std::string separator = ""; + SkString description() const override { + SkString result("("); + SkString separator; for (size_t i = 0; i < fArguments.size(); ++i) { result += separator; separator = ", "; diff --git a/src/sksl/ast/SkSLASTContinueStatement.h b/src/sksl/ast/SkSLASTContinueStatement.h index d5ab7a5c74..4cded3b16b 100644 --- a/src/sksl/ast/SkSLASTContinueStatement.h +++ b/src/sksl/ast/SkSLASTContinueStatement.h @@ -19,8 +19,8 @@ struct ASTContinueStatement : public ASTStatement { ASTContinueStatement(Position position) : INHERITED(position, kContinue_Kind) {} - std::string description() const override { - return "continue;"; + SkString description() const override { + return SkString("continue;"); } typedef ASTStatement INHERITED; diff --git a/src/sksl/ast/SkSLASTDiscardStatement.h b/src/sksl/ast/SkSLASTDiscardStatement.h index 4eaeec9ea4..754bf95efe 100644 --- a/src/sksl/ast/SkSLASTDiscardStatement.h +++ b/src/sksl/ast/SkSLASTDiscardStatement.h @@ -19,8 +19,8 @@ struct ASTDiscardStatement : public ASTStatement { ASTDiscardStatement(Position position) : INHERITED(position, kDiscard_Kind) {} - std::string description() const override { - return "discard;"; + SkString description() const override { + return SkString("discard;"); } typedef ASTStatement INHERITED; diff --git a/src/sksl/ast/SkSLASTDoStatement.h b/src/sksl/ast/SkSLASTDoStatement.h index a952d62eb5..9a0caced1c 100644 --- a/src/sksl/ast/SkSLASTDoStatement.h +++ b/src/sksl/ast/SkSLASTDoStatement.h @@ -22,7 +22,7 @@ struct ASTDoStatement : public ASTStatement { , fStatement(std::move(statement)) , fTest(std::move(test)) {} - std::string description() const override { + SkString description() const override { return "do " + fStatement->description() + " while (" + fTest->description() + ");"; } diff --git a/src/sksl/ast/SkSLASTExpressionStatement.h b/src/sksl/ast/SkSLASTExpressionStatement.h index 450cca29fc..2dbd20940d 100644 --- a/src/sksl/ast/SkSLASTExpressionStatement.h +++ b/src/sksl/ast/SkSLASTExpressionStatement.h @@ -20,7 +20,7 @@ struct ASTExpressionStatement : public ASTStatement { : INHERITED(expression->fPosition, kExpression_Kind) , fExpression(std::move(expression)) {} - std::string description() const override { + SkString description() const override { return fExpression->description() + ";"; } diff --git a/src/sksl/ast/SkSLASTExtension.h b/src/sksl/ast/SkSLASTExtension.h index 896ac46c58..b9df3c52e9 100644 --- a/src/sksl/ast/SkSLASTExtension.h +++ b/src/sksl/ast/SkSLASTExtension.h @@ -16,15 +16,15 @@ namespace SkSL { * An extension declaration. */ struct ASTExtension : public ASTDeclaration { - ASTExtension(Position position, std::string name) + ASTExtension(Position position, SkString name) : INHERITED(position, kExtension_Kind) , fName(std::move(name)) {} - std::string description() const override { + SkString description() const override { return "#extension " + fName + " : enable"; } - const std::string fName; + const SkString fName; typedef ASTDeclaration INHERITED; }; diff --git a/src/sksl/ast/SkSLASTFieldSuffix.h b/src/sksl/ast/SkSLASTFieldSuffix.h index cf141d822f..9ee8531bf1 100644 --- a/src/sksl/ast/SkSLASTFieldSuffix.h +++ b/src/sksl/ast/SkSLASTFieldSuffix.h @@ -17,15 +17,15 @@ namespace SkSL { * actually vector swizzle (which looks the same to the parser). */ struct ASTFieldSuffix : public ASTSuffix { - ASTFieldSuffix(Position position, std::string field) + ASTFieldSuffix(Position position, SkString field) : INHERITED(position, ASTSuffix::kField_Kind) , fField(std::move(field)) {} - std::string description() const override { + SkString description() const override { return "." + fField; } - std::string fField; + SkString fField; typedef ASTSuffix INHERITED; }; diff --git a/src/sksl/ast/SkSLASTFloatLiteral.h b/src/sksl/ast/SkSLASTFloatLiteral.h index 89d43cc003..ea0f595abc 100644 --- a/src/sksl/ast/SkSLASTFloatLiteral.h +++ b/src/sksl/ast/SkSLASTFloatLiteral.h @@ -20,7 +20,7 @@ struct ASTFloatLiteral : public ASTExpression { : INHERITED(position, kFloat_Kind) , fValue(value) {} - std::string description() const override { + SkString description() const override { return to_string(fValue); } diff --git a/src/sksl/ast/SkSLASTForStatement.h b/src/sksl/ast/SkSLASTForStatement.h index f4f68c8f40..2706a39954 100644 --- a/src/sksl/ast/SkSLASTForStatement.h +++ b/src/sksl/ast/SkSLASTForStatement.h @@ -25,8 +25,8 @@ struct ASTForStatement : public ASTStatement { , fNext(std::move(next)) , fStatement(std::move(statement)) {} - std::string description() const override { - std::string result = "for ("; + SkString description() const override { + SkString result("for ("); if (fInitializer) { result.append(fInitializer->description()); } diff --git a/src/sksl/ast/SkSLASTFunction.h b/src/sksl/ast/SkSLASTFunction.h index c5c3b9ad83..32f4da71f2 100644 --- a/src/sksl/ast/SkSLASTFunction.h +++ b/src/sksl/ast/SkSLASTFunction.h @@ -19,7 +19,7 @@ namespace SkSL { * A function declaration or definition. The fBody field will be null for declarations. */ struct ASTFunction : public ASTDeclaration { - ASTFunction(Position position, std::unique_ptr returnType, std::string name, + ASTFunction(Position position, std::unique_ptr returnType, SkString name, std::vector> parameters, std::unique_ptr body) : INHERITED(position, kFunction_Kind) @@ -28,8 +28,8 @@ struct ASTFunction : public ASTDeclaration { , fParameters(std::move(parameters)) , fBody(std::move(body)) {} - std::string description() const override { - std::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 += ", "; @@ -45,7 +45,7 @@ struct ASTFunction : public ASTDeclaration { } const std::unique_ptr fReturnType; - const std::string fName; + const SkString fName; const std::vector> fParameters; const std::unique_ptr fBody; diff --git a/src/sksl/ast/SkSLASTIdentifier.h b/src/sksl/ast/SkSLASTIdentifier.h index d67f64d39b..aa0179a18f 100644 --- a/src/sksl/ast/SkSLASTIdentifier.h +++ b/src/sksl/ast/SkSLASTIdentifier.h @@ -16,15 +16,15 @@ namespace SkSL { * An identifier in an expression context. */ struct ASTIdentifier : public ASTExpression { - ASTIdentifier(Position position, std::string text) + ASTIdentifier(Position position, SkString text) : INHERITED(position, kIdentifier_Kind) , fText(std::move(text)) {} - std::string description() const override { + SkString description() const override { return fText; } - const std::string fText; + const SkString fText; typedef ASTExpression INHERITED; }; diff --git a/src/sksl/ast/SkSLASTIfStatement.h b/src/sksl/ast/SkSLASTIfStatement.h index 06f663d5fb..d169702710 100644 --- a/src/sksl/ast/SkSLASTIfStatement.h +++ b/src/sksl/ast/SkSLASTIfStatement.h @@ -23,8 +23,8 @@ struct ASTIfStatement : public ASTStatement { , fIfTrue(std::move(ifTrue)) , fIfFalse(std::move(ifFalse)) {} - std::string description() const override { - std::string result("if ("); + SkString description() const override { + SkString result("if ("); result += fTest->description(); result += ") "; result += fIfTrue->description(); diff --git a/src/sksl/ast/SkSLASTIndexSuffix.h b/src/sksl/ast/SkSLASTIndexSuffix.h index 755029b0a2..2b7cd48417 100644 --- a/src/sksl/ast/SkSLASTIndexSuffix.h +++ b/src/sksl/ast/SkSLASTIndexSuffix.h @@ -26,11 +26,11 @@ struct ASTIndexSuffix : public ASTSuffix { : INHERITED(expression ? expression->fPosition : Position(), ASTSuffix::kIndex_Kind) , fExpression(std::move(expression)) {} - std::string description() const override { + SkString description() const override { if (fExpression) { return "[" + fExpression->description() + "]"; } else { - return "[]"; + return SkString("[]"); } } diff --git a/src/sksl/ast/SkSLASTIntLiteral.h b/src/sksl/ast/SkSLASTIntLiteral.h index 2598847534..f524bc04ad 100644 --- a/src/sksl/ast/SkSLASTIntLiteral.h +++ b/src/sksl/ast/SkSLASTIntLiteral.h @@ -21,7 +21,7 @@ struct ASTIntLiteral : public ASTExpression { : INHERITED(position, kInt_Kind) , fValue(value) {} - std::string description() const override { + SkString description() const override { return to_string(fValue); } diff --git a/src/sksl/ast/SkSLASTInterfaceBlock.h b/src/sksl/ast/SkSLASTInterfaceBlock.h index c271362071..8d86c7c4f1 100644 --- a/src/sksl/ast/SkSLASTInterfaceBlock.h +++ b/src/sksl/ast/SkSLASTInterfaceBlock.h @@ -24,8 +24,8 @@ struct ASTInterfaceBlock : public ASTDeclaration { // valueName is empty when it was not present in the source ASTInterfaceBlock(Position position, ASTModifiers modifiers, - std::string interfaceName, - std::string valueName, + SkString interfaceName, + SkString valueName, std::vector> declarations) : INHERITED(position, kInterfaceBlock_Kind) , fModifiers(modifiers) @@ -33,21 +33,21 @@ struct ASTInterfaceBlock : public ASTDeclaration { , fValueName(std::move(valueName)) , fDeclarations(std::move(declarations)) {} - std::string description() const override { - std::string result = fModifiers.description() + fInterfaceName + " {\n"; + SkString description() const override { + SkString result = fModifiers.description() + fInterfaceName + " {\n"; for (size_t i = 0; i < fDeclarations.size(); i++) { result += fDeclarations[i]->description() + "\n"; } result += "}"; - if (fValueName.length()) { + if (fValueName.size()) { result += " " + fValueName; } return result + ";"; } const ASTModifiers fModifiers; - const std::string fInterfaceName; - const std::string fValueName; + const SkString fInterfaceName; + const SkString fValueName; const std::vector> fDeclarations; typedef ASTDeclaration INHERITED; diff --git a/src/sksl/ast/SkSLASTLayout.h b/src/sksl/ast/SkSLASTLayout.h index ae3c3b6168..cb7f3c175c 100644 --- a/src/sksl/ast/SkSLASTLayout.h +++ b/src/sksl/ast/SkSLASTLayout.h @@ -48,7 +48,7 @@ struct ASTLayout : public ASTNode { return ""; } - static bool ReadFormat(std::string str, Format* format) { + static bool ReadFormat(SkString str, Format* format) { if (str == "rgba32f") { *format = Format::kRGBA32F; return true; @@ -90,9 +90,9 @@ struct ASTLayout : public ASTNode { , fBlendSupportAllEquations(blendSupportAllEquations) , fFormat(format) {} - std::string description() const { - std::string result; - std::string separator; + SkString description() const { + SkString result; + SkString separator; if (fLocation >= 0) { result += separator + "location = " + to_string(fLocation); separator = ", "; @@ -129,7 +129,7 @@ struct ASTLayout : public ASTNode { result += separator + FormatToStr(fFormat); separator = ", "; } - if (result.length() > 0) { + if (result.size() > 0) { result = "layout (" + result + ")"; } return result; diff --git a/src/sksl/ast/SkSLASTModifiers.h b/src/sksl/ast/SkSLASTModifiers.h index 61d2e9f25d..734169267c 100644 --- a/src/sksl/ast/SkSLASTModifiers.h +++ b/src/sksl/ast/SkSLASTModifiers.h @@ -34,8 +34,8 @@ struct ASTModifiers : public ASTNode { : fLayout(layout) , fFlags(flags) {} - std::string description() const override { - std::string result = fLayout.description(); + SkString description() const override { + SkString result = fLayout.description(); if (fFlags & kUniform_Flag) { result += "uniform "; } diff --git a/src/sksl/ast/SkSLASTModifiersDeclaration.h b/src/sksl/ast/SkSLASTModifiersDeclaration.h index f5cc620899..07efdf6024 100644 --- a/src/sksl/ast/SkSLASTModifiersDeclaration.h +++ b/src/sksl/ast/SkSLASTModifiersDeclaration.h @@ -23,7 +23,7 @@ struct ASTModifiersDeclaration : public ASTDeclaration { : INHERITED(Position(), kModifiers_Kind) , fModifiers(modifiers) {} - std::string description() const { + SkString description() const { return fModifiers.description() + ";"; } diff --git a/src/sksl/ast/SkSLASTNode.h b/src/sksl/ast/SkSLASTNode.h index 4305011fa5..af065955f8 100644 --- a/src/sksl/ast/SkSLASTNode.h +++ b/src/sksl/ast/SkSLASTNode.h @@ -8,8 +8,7 @@ #ifndef SKSL_ASTNODE #define SKSL_ASTNODE -#include -#include +#include "SkString.h" namespace SkSL { @@ -20,7 +19,7 @@ namespace SkSL { struct ASTNode { virtual ~ASTNode() {} - virtual std::string description() const = 0; + virtual SkString description() const = 0; }; } // namespace diff --git a/src/sksl/ast/SkSLASTParameter.h b/src/sksl/ast/SkSLASTParameter.h index 8f1b4535f2..b1fd658434 100644 --- a/src/sksl/ast/SkSLASTParameter.h +++ b/src/sksl/ast/SkSLASTParameter.h @@ -20,15 +20,15 @@ struct ASTParameter : public ASTPositionNode { // '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, ASTModifiers modifiers, std::unique_ptr type, - std::string name, std::vector sizes) + SkString name, std::vector sizes) : INHERITED(position) , fModifiers(modifiers) , fType(std::move(type)) , fName(std::move(name)) , fSizes(std::move(sizes)) {} - std::string description() const override { - std::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) + "]"; } @@ -37,7 +37,7 @@ struct ASTParameter : public ASTPositionNode { const ASTModifiers fModifiers; const std::unique_ptr fType; - const std::string fName; + const SkString fName; const std::vector fSizes; typedef ASTPositionNode INHERITED; diff --git a/src/sksl/ast/SkSLASTPrecision.h b/src/sksl/ast/SkSLASTPrecision.h index a7df57948e..a2f427c9ce 100644 --- a/src/sksl/ast/SkSLASTPrecision.h +++ b/src/sksl/ast/SkSLASTPrecision.h @@ -22,17 +22,17 @@ struct ASTPrecision : public ASTDeclaration { : INHERITED(position, kPrecision_Kind) , fPrecision(precision) {} - std::string description() const { + SkString description() const { switch (fPrecision) { - case Modifiers::kLowp_Flag: return "precision lowp float;"; - case Modifiers::kMediump_Flag: return "precision mediump float;"; - case Modifiers::kHighp_Flag: return "precision highp float;"; + 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 ""; + return SkString(""); } ASSERT(false); - return ""; + return SkString(""); } const Modifiers::Flag fPrecision; diff --git a/src/sksl/ast/SkSLASTPrefixExpression.h b/src/sksl/ast/SkSLASTPrefixExpression.h index 0d326e2aab..e06ec41f9e 100644 --- a/src/sksl/ast/SkSLASTPrefixExpression.h +++ b/src/sksl/ast/SkSLASTPrefixExpression.h @@ -22,7 +22,7 @@ struct ASTPrefixExpression : public ASTExpression { , fOperator(op.fKind) , fOperand(std::move(operand)) {} - std::string description() const override { + SkString description() const override { return Token::OperatorName(fOperator) + fOperand->description(); } diff --git a/src/sksl/ast/SkSLASTReturnStatement.h b/src/sksl/ast/SkSLASTReturnStatement.h index 3aac783a8c..ed24d4a153 100644 --- a/src/sksl/ast/SkSLASTReturnStatement.h +++ b/src/sksl/ast/SkSLASTReturnStatement.h @@ -21,8 +21,8 @@ struct ASTReturnStatement : public ASTStatement { : INHERITED(position, kReturn_Kind) , fExpression(std::move(expression)) {} - std::string description() const override { - std::string result("return"); + SkString description() const override { + SkString result("return"); if (fExpression) { result += " " + fExpression->description(); } diff --git a/src/sksl/ast/SkSLASTSuffix.h b/src/sksl/ast/SkSLASTSuffix.h index 18f79f01ea..64178c7682 100644 --- a/src/sksl/ast/SkSLASTSuffix.h +++ b/src/sksl/ast/SkSLASTSuffix.h @@ -30,12 +30,12 @@ struct ASTSuffix : public ASTPositionNode { : INHERITED(position) , fKind(kind) {} - std::string description() const override { + SkString description() const override { switch (fKind) { case kPostIncrement_Kind: - return "++"; + return SkString("++"); case kPostDecrement_Kind: - return "--"; + return SkString("--"); default: ABORT("unsupported suffix operator"); } diff --git a/src/sksl/ast/SkSLASTSuffixExpression.h b/src/sksl/ast/SkSLASTSuffixExpression.h index c0fda294b9..7ee200fd43 100644 --- a/src/sksl/ast/SkSLASTSuffixExpression.h +++ b/src/sksl/ast/SkSLASTSuffixExpression.h @@ -22,7 +22,7 @@ struct ASTSuffixExpression : public ASTExpression { , fBase(std::move(base)) , fSuffix(std::move(suffix)) {} - std::string description() const override { + SkString description() const override { return fBase->description() + fSuffix->description(); } diff --git a/src/sksl/ast/SkSLASTTernaryExpression.h b/src/sksl/ast/SkSLASTTernaryExpression.h index 20b827a049..ddf8e3d120 100644 --- a/src/sksl/ast/SkSLASTTernaryExpression.h +++ b/src/sksl/ast/SkSLASTTernaryExpression.h @@ -24,7 +24,7 @@ struct ASTTernaryExpression : public ASTExpression { , fIfTrue(std::move(ifTrue)) , fIfFalse(std::move(ifFalse)) {} - std::string description() const override { + SkString description() const override { return "(" + fTest->description() + " ? " + fIfTrue->description() + " : " + fIfFalse->description() + ")"; } diff --git a/src/sksl/ast/SkSLASTType.h b/src/sksl/ast/SkSLASTType.h index b8fdedb214..81594000e5 100644 --- a/src/sksl/ast/SkSLASTType.h +++ b/src/sksl/ast/SkSLASTType.h @@ -19,16 +19,16 @@ struct ASTType : public ASTPositionNode { kStruct_Kind }; - ASTType(Position position, std::string name, Kind kind) + ASTType(Position position, SkString name, Kind kind) : INHERITED(position) , fName(std::move(name)) , fKind(kind) {} - std::string description() const override { + SkString description() const override { return fName; } - const std::string fName; + const SkString fName; const Kind fKind; diff --git a/src/sksl/ast/SkSLASTVarDeclaration.h b/src/sksl/ast/SkSLASTVarDeclaration.h index 066922fb85..9de4cf55b9 100644 --- a/src/sksl/ast/SkSLASTVarDeclaration.h +++ b/src/sksl/ast/SkSLASTVarDeclaration.h @@ -22,15 +22,15 @@ namespace SkSL { * instances. */ struct ASTVarDeclaration { - ASTVarDeclaration(const std::string name, + ASTVarDeclaration(const SkString name, std::vector> sizes, std::unique_ptr value) : fName(name) , fSizes(std::move(sizes)) , fValue(std::move(value)) {} - std::string description() const { - std::string result = fName; + SkString description() const { + SkString result = fName; for (const auto& size : fSizes) { if (size) { result += "[" + size->description() + "]"; @@ -44,7 +44,7 @@ struct ASTVarDeclaration { return result; } - std::string fName; + SkString fName; // array sizes, if any. e.g. 'foo[3][]' has sizes [3, null] std::vector> fSizes; @@ -65,9 +65,9 @@ struct ASTVarDeclarations : public ASTDeclaration { , fType(std::move(type)) , fVars(std::move(vars)) {} - std::string description() const override { - std::string result = fModifiers.description() + fType->description() + " "; - std::string separator = ""; + SkString description() const override { + SkString result = fModifiers.description() + fType->description() + " "; + SkString separator; for (const auto& var : fVars) { result += separator; separator = ", "; diff --git a/src/sksl/ast/SkSLASTVarDeclarationStatement.h b/src/sksl/ast/SkSLASTVarDeclarationStatement.h index 8bae389146..d71639d797 100644 --- a/src/sksl/ast/SkSLASTVarDeclarationStatement.h +++ b/src/sksl/ast/SkSLASTVarDeclarationStatement.h @@ -21,7 +21,7 @@ struct ASTVarDeclarationStatement : public ASTStatement { : INHERITED(decl->fPosition, kVarDeclaration_Kind) , fDeclarations(std::move(decl)) {} - std::string description() const override { + SkString description() const override { return fDeclarations->description() + ";"; } diff --git a/src/sksl/ast/SkSLASTWhileStatement.h b/src/sksl/ast/SkSLASTWhileStatement.h index e29aa23e4a..853ac8028d 100644 --- a/src/sksl/ast/SkSLASTWhileStatement.h +++ b/src/sksl/ast/SkSLASTWhileStatement.h @@ -22,7 +22,7 @@ struct ASTWhileStatement : public ASTStatement { , fTest(std::move(test)) , fStatement(std::move(statement)) {} - std::string description() const override { + SkString description() const override { return "while (" + fTest->description() + ") " + fStatement->description(); } diff --git a/src/sksl/ir/SkSLBinaryExpression.h b/src/sksl/ir/SkSLBinaryExpression.h index 9ecdbc717c..132513e7f7 100644 --- a/src/sksl/ir/SkSLBinaryExpression.h +++ b/src/sksl/ir/SkSLBinaryExpression.h @@ -24,7 +24,7 @@ struct BinaryExpression : public Expression { , fOperator(op) , fRight(std::move(right)) {} - virtual std::string description() const override { + virtual SkString description() const override { return "(" + fLeft->description() + " " + Token::OperatorName(fOperator) + " " + fRight->description() + ")"; } diff --git a/src/sksl/ir/SkSLBlock.h b/src/sksl/ir/SkSLBlock.h index a53d13d169..f975d160a0 100644 --- a/src/sksl/ir/SkSLBlock.h +++ b/src/sksl/ir/SkSLBlock.h @@ -4,7 +4,7 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ - + #ifndef SKSL_BLOCK #define SKSL_BLOCK @@ -23,14 +23,14 @@ struct Block : public Statement { , fStatements(std::move(statements)) , fSymbols(std::move(symbols)) {} - std::string description() const override { - std::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> fStatements; diff --git a/src/sksl/ir/SkSLBoolLiteral.h b/src/sksl/ir/SkSLBoolLiteral.h index ba054e4181..b372f2f3ff 100644 --- a/src/sksl/ir/SkSLBoolLiteral.h +++ b/src/sksl/ir/SkSLBoolLiteral.h @@ -21,8 +21,8 @@ struct BoolLiteral : public Expression { : INHERITED(position, kBoolLiteral_Kind, *context.fBool_Type) , fValue(value) {} - std::string description() const override { - return fValue ? "true" : "false"; + SkString description() const override { + return SkString(fValue ? "true" : "false"); } bool isConstant() const override { diff --git a/src/sksl/ir/SkSLBreakStatement.h b/src/sksl/ir/SkSLBreakStatement.h index 8aa17b096b..cd633c7a91 100644 --- a/src/sksl/ir/SkSLBreakStatement.h +++ b/src/sksl/ir/SkSLBreakStatement.h @@ -20,8 +20,8 @@ struct BreakStatement : public Statement { BreakStatement(Position position) : INHERITED(position, kBreak_Kind) {} - std::string description() const override { - return "break;"; + SkString description() const override { + return SkString("break;"); } typedef Statement INHERITED; diff --git a/src/sksl/ir/SkSLConstructor.h b/src/sksl/ir/SkSLConstructor.h index 0501b651ea..92f758032b 100644 --- a/src/sksl/ir/SkSLConstructor.h +++ b/src/sksl/ir/SkSLConstructor.h @@ -21,9 +21,9 @@ struct Constructor : public Expression { : INHERITED(position, kConstructor_Kind, type) , fArguments(std::move(arguments)) {} - std::string description() const override { - std::string result = fType.description() + "("; - std::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(); diff --git a/src/sksl/ir/SkSLContinueStatement.h b/src/sksl/ir/SkSLContinueStatement.h index 1951bd990a..b4446940cf 100644 --- a/src/sksl/ir/SkSLContinueStatement.h +++ b/src/sksl/ir/SkSLContinueStatement.h @@ -20,8 +20,8 @@ struct ContinueStatement : public Statement { ContinueStatement(Position position) : INHERITED(position, kContinue_Kind) {} - std::string description() const override { - return "continue;"; + SkString description() const override { + return SkString("continue;"); } typedef Statement INHERITED; diff --git a/src/sksl/ir/SkSLDiscardStatement.h b/src/sksl/ir/SkSLDiscardStatement.h index b39712ebd1..3ab6b27047 100644 --- a/src/sksl/ir/SkSLDiscardStatement.h +++ b/src/sksl/ir/SkSLDiscardStatement.h @@ -20,8 +20,8 @@ struct DiscardStatement : public Statement { DiscardStatement(Position position) : INHERITED(position, kDiscard_Kind) {} - std::string description() const override { - return "discard;"; + SkString description() const override { + return SkString("discard;"); } typedef Statement INHERITED; diff --git a/src/sksl/ir/SkSLDoStatement.h b/src/sksl/ir/SkSLDoStatement.h index 6012453277..78c0a1b768 100644 --- a/src/sksl/ir/SkSLDoStatement.h +++ b/src/sksl/ir/SkSLDoStatement.h @@ -23,7 +23,7 @@ struct DoStatement : public Statement { , fStatement(std::move(statement)) , fTest(std::move(test)) {} - std::string description() const override { + SkString description() const override { return "do " + fStatement->description() + " while (" + fTest->description() + ");"; } diff --git a/src/sksl/ir/SkSLExpressionStatement.h b/src/sksl/ir/SkSLExpressionStatement.h index e975ccf2ac..677c647587 100644 --- a/src/sksl/ir/SkSLExpressionStatement.h +++ b/src/sksl/ir/SkSLExpressionStatement.h @@ -21,7 +21,7 @@ struct ExpressionStatement : public Statement { : INHERITED(expression->fPosition, kExpression_Kind) , fExpression(std::move(expression)) {} - std::string description() const override { + SkString description() const override { return fExpression->description() + ";"; } diff --git a/src/sksl/ir/SkSLExtension.h b/src/sksl/ir/SkSLExtension.h index d7f83fad8a..ea5e0445e3 100644 --- a/src/sksl/ir/SkSLExtension.h +++ b/src/sksl/ir/SkSLExtension.h @@ -16,15 +16,15 @@ namespace SkSL { * An extension declaration. */ struct Extension : public ProgramElement { - Extension(Position position, std::string name) + Extension(Position position, SkString name) : INHERITED(position, kExtension_Kind) , fName(std::move(name)) {} - std::string description() const override { + SkString description() const override { return "#extension " + fName + " : enable"; } - const std::string fName; + const SkString fName; typedef ProgramElement INHERITED; }; diff --git a/src/sksl/ir/SkSLField.h b/src/sksl/ir/SkSLField.h index a01df2943d..f73b6025ec 100644 --- a/src/sksl/ir/SkSLField.h +++ b/src/sksl/ir/SkSLField.h @@ -26,7 +26,7 @@ struct Field : public Symbol { , fOwner(owner) , fFieldIndex(fieldIndex) {} - virtual std::string description() const override { + virtual SkString description() const override { return fOwner.description() + "." + fOwner.fType.fields()[fFieldIndex].fName; } diff --git a/src/sksl/ir/SkSLFieldAccess.h b/src/sksl/ir/SkSLFieldAccess.h index 4be4e9e84c..fb727e017e 100644 --- a/src/sksl/ir/SkSLFieldAccess.h +++ b/src/sksl/ir/SkSLFieldAccess.h @@ -31,7 +31,7 @@ struct FieldAccess : public Expression { , fFieldIndex(fieldIndex) , fOwnerKind(ownerKind) {} - virtual std::string description() const override { + virtual SkString description() const override { return fBase->description() + "." + fBase->fType.fields()[fFieldIndex].fName; } diff --git a/src/sksl/ir/SkSLFloatLiteral.h b/src/sksl/ir/SkSLFloatLiteral.h index a8fcfcf644..8a1a5ad63a 100644 --- a/src/sksl/ir/SkSLFloatLiteral.h +++ b/src/sksl/ir/SkSLFloatLiteral.h @@ -21,7 +21,7 @@ struct FloatLiteral : public Expression { : INHERITED(position, kFloatLiteral_Kind, *context.fFloat_Type) , fValue(value) {} - virtual std::string description() const override { + virtual SkString description() const override { return to_string(fValue); } diff --git a/src/sksl/ir/SkSLForStatement.h b/src/sksl/ir/SkSLForStatement.h index 642d15125e..ff03d0d7f9 100644 --- a/src/sksl/ir/SkSLForStatement.h +++ b/src/sksl/ir/SkSLForStatement.h @@ -28,8 +28,8 @@ struct ForStatement : public Statement { , fStatement(std::move(statement)) , fSymbols(symbols) {} - std::string description() const override { - std::string result = "for ("; + SkString description() const override { + SkString result("for ("); if (fInitializer) { result += fInitializer->description(); } diff --git a/src/sksl/ir/SkSLFunctionCall.h b/src/sksl/ir/SkSLFunctionCall.h index 5c67a2873c..971af366b9 100644 --- a/src/sksl/ir/SkSLFunctionCall.h +++ b/src/sksl/ir/SkSLFunctionCall.h @@ -23,9 +23,9 @@ struct FunctionCall : public Expression { , fFunction(std::move(function)) , fArguments(std::move(arguments)) {} - std::string description() const override { - std::string result = fFunction.fName + "("; - std::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(); diff --git a/src/sksl/ir/SkSLFunctionDeclaration.h b/src/sksl/ir/SkSLFunctionDeclaration.h index 52a579a89b..c15d2b96dc 100644 --- a/src/sksl/ir/SkSLFunctionDeclaration.h +++ b/src/sksl/ir/SkSLFunctionDeclaration.h @@ -21,7 +21,7 @@ namespace SkSL { * A function declaration (not a definition -- does not contain a body). */ struct FunctionDeclaration : public Symbol { - FunctionDeclaration(Position position, std::string name, + FunctionDeclaration(Position position, SkString name, std::vector parameters, const Type& returnType) : INHERITED(position, kFunctionDeclaration_Kind, std::move(name)) , fDefined(false) @@ -29,9 +29,9 @@ struct FunctionDeclaration : public Symbol { , fParameters(std::move(parameters)) , fReturnType(returnType) {} - std::string description() const override { - std::string result = fReturnType.description() + " " + fName + "("; - std::string separator = ""; + SkString description() const override { + SkString result = fReturnType.description() + " " + fName + "("; + SkString separator; for (auto p : fParameters) { result += separator; separator = ", "; diff --git a/src/sksl/ir/SkSLFunctionDefinition.h b/src/sksl/ir/SkSLFunctionDefinition.h index ace27a3ed8..bae882525a 100644 --- a/src/sksl/ir/SkSLFunctionDefinition.h +++ b/src/sksl/ir/SkSLFunctionDefinition.h @@ -24,7 +24,7 @@ struct FunctionDefinition : public ProgramElement { , fDeclaration(declaration) , fBody(std::move(body)) {} - std::string description() const override { + SkString description() const override { return fDeclaration.description() + " " + fBody->description(); } diff --git a/src/sksl/ir/SkSLFunctionReference.h b/src/sksl/ir/SkSLFunctionReference.h index f3f8fb71da..ec1fc3804c 100644 --- a/src/sksl/ir/SkSLFunctionReference.h +++ b/src/sksl/ir/SkSLFunctionReference.h @@ -23,9 +23,9 @@ struct FunctionReference : public Expression { : INHERITED(position, kFunctionReference_Kind, *context.fInvalid_Type) , fFunctions(function) {} - virtual std::string description() const override { + virtual SkString description() const override { ASSERT(false); - return ""; + return SkString(""); } const std::vector fFunctions; diff --git a/src/sksl/ir/SkSLIRNode.h b/src/sksl/ir/SkSLIRNode.h index 8c433cfc6b..9a04cddec5 100644 --- a/src/sksl/ir/SkSLIRNode.h +++ b/src/sksl/ir/SkSLIRNode.h @@ -22,7 +22,7 @@ struct IRNode { virtual ~IRNode() {} - virtual std::string description() const = 0; + virtual SkString description() const = 0; const Position fPosition; }; diff --git a/src/sksl/ir/SkSLIfStatement.h b/src/sksl/ir/SkSLIfStatement.h index 8ab5c00fd7..f8beded9e8 100644 --- a/src/sksl/ir/SkSLIfStatement.h +++ b/src/sksl/ir/SkSLIfStatement.h @@ -24,8 +24,8 @@ struct IfStatement : public Statement { , fIfTrue(std::move(ifTrue)) , fIfFalse(std::move(ifFalse)) {} - std::string description() const override { - std::string result = "if (" + fTest->description() + ") " + fIfTrue->description(); + SkString description() const override { + SkString result = "if (" + fTest->description() + ") " + fIfTrue->description(); if (fIfFalse) { result += " else " + fIfFalse->description(); } diff --git a/src/sksl/ir/SkSLIndexExpression.h b/src/sksl/ir/SkSLIndexExpression.h index abd8a03fa4..079dde5e53 100644 --- a/src/sksl/ir/SkSLIndexExpression.h +++ b/src/sksl/ir/SkSLIndexExpression.h @@ -51,7 +51,7 @@ struct IndexExpression : public Expression { ASSERT(fIndex->fType == *context.fInt_Type || fIndex->fType == *context.fUInt_Type); } - std::string description() const override { + SkString description() const override { return fBase->description() + "[" + fIndex->description() + "]"; } diff --git a/src/sksl/ir/SkSLIntLiteral.h b/src/sksl/ir/SkSLIntLiteral.h index 8921c283b5..23325e65fb 100644 --- a/src/sksl/ir/SkSLIntLiteral.h +++ b/src/sksl/ir/SkSLIntLiteral.h @@ -22,7 +22,7 @@ struct IntLiteral : public Expression { : INHERITED(position, kIntLiteral_Kind, type ? *type : *context.fInt_Type) , fValue(value) {} - virtual std::string description() const override { + virtual SkString description() const override { return to_string(fValue); } diff --git a/src/sksl/ir/SkSLInterfaceBlock.h b/src/sksl/ir/SkSLInterfaceBlock.h index debde207a1..bc84396b2d 100644 --- a/src/sksl/ir/SkSLInterfaceBlock.h +++ b/src/sksl/ir/SkSLInterfaceBlock.h @@ -31,8 +31,8 @@ struct InterfaceBlock : public ProgramElement { ASSERT(fVariable.fType.kind() == Type::kStruct_Kind); } - std::string description() const override { - std::string result = fVariable.fModifiers.description() + fVariable.fName + " {\n"; + SkString description() const override { + SkString result = fVariable.fModifiers.description() + fVariable.fName + " {\n"; for (size_t i = 0; i < fVariable.fType.fields().size(); i++) { result += fVariable.fType.fields()[i].description() + "\n"; } diff --git a/src/sksl/ir/SkSLLayout.h b/src/sksl/ir/SkSLLayout.h index 4cfd1a2771..7359262c96 100644 --- a/src/sksl/ir/SkSLLayout.h +++ b/src/sksl/ir/SkSLLayout.h @@ -50,9 +50,9 @@ struct Layout { , fBlendSupportAllEquations(false) , fFormat(ASTLayout::Format::kUnspecified) {} - std::string description() const { - std::string result; - std::string separator; + SkString description() const { + SkString result; + SkString separator; if (fLocation >= 0) { result += separator + "location = " + to_string(fLocation); separator = ", "; @@ -89,7 +89,7 @@ struct Layout { result += separator + ASTLayout::FormatToStr(fFormat); separator = ", "; } - if (result.length() > 0) { + if (result.size() > 0) { result = "layout (" + result + ")"; } return result; diff --git a/src/sksl/ir/SkSLModifiers.h b/src/sksl/ir/SkSLModifiers.h index f39e92959f..2c9b3b39c9 100644 --- a/src/sksl/ir/SkSLModifiers.h +++ b/src/sksl/ir/SkSLModifiers.h @@ -38,8 +38,8 @@ struct Modifiers { : fLayout(layout) , fFlags(flags) {} - std::string description() const { - std::string result = fLayout.description(); + SkString description() const { + SkString result = fLayout.description(); if (fFlags & kUniform_Flag) { result += "uniform "; } diff --git a/src/sksl/ir/SkSLModifiersDeclaration.h b/src/sksl/ir/SkSLModifiersDeclaration.h index 0066fab877..625954d7c7 100644 --- a/src/sksl/ir/SkSLModifiersDeclaration.h +++ b/src/sksl/ir/SkSLModifiersDeclaration.h @@ -23,7 +23,7 @@ struct ModifiersDeclaration : public ProgramElement { : INHERITED(Position(), kModifiers_Kind) , fModifiers(modifiers) {} - std::string description() const { + SkString description() const { return fModifiers.description() + ";"; } diff --git a/src/sksl/ir/SkSLPostfixExpression.h b/src/sksl/ir/SkSLPostfixExpression.h index de146ac43c..01671b5b88 100644 --- a/src/sksl/ir/SkSLPostfixExpression.h +++ b/src/sksl/ir/SkSLPostfixExpression.h @@ -21,7 +21,7 @@ struct PostfixExpression : public Expression { , fOperand(std::move(operand)) , fOperator(op) {} - virtual std::string description() const override { + virtual SkString description() const override { return fOperand->description() + Token::OperatorName(fOperator); } diff --git a/src/sksl/ir/SkSLPrefixExpression.h b/src/sksl/ir/SkSLPrefixExpression.h index 53c3849b38..790c5ab47a 100644 --- a/src/sksl/ir/SkSLPrefixExpression.h +++ b/src/sksl/ir/SkSLPrefixExpression.h @@ -21,7 +21,7 @@ struct PrefixExpression : public Expression { , fOperand(std::move(operand)) , fOperator(op) {} - virtual std::string description() const override { + virtual SkString description() const override { return Token::OperatorName(fOperator) + fOperand->description(); } diff --git a/src/sksl/ir/SkSLReturnStatement.h b/src/sksl/ir/SkSLReturnStatement.h index ec2226cc56..c83b45066e 100644 --- a/src/sksl/ir/SkSLReturnStatement.h +++ b/src/sksl/ir/SkSLReturnStatement.h @@ -24,11 +24,11 @@ struct ReturnStatement : public Statement { : INHERITED(expression->fPosition, kReturn_Kind) , fExpression(std::move(expression)) {} - std::string description() const override { + SkString description() const override { if (fExpression) { return "return " + fExpression->description() + ";"; } else { - return "return;"; + return SkString("return;"); } } diff --git a/src/sksl/ir/SkSLSwizzle.h b/src/sksl/ir/SkSLSwizzle.h index 0eb4a00dca..c9397aec7f 100644 --- a/src/sksl/ir/SkSLSwizzle.h +++ b/src/sksl/ir/SkSLSwizzle.h @@ -68,8 +68,8 @@ struct Swizzle : public Expression { ASSERT(fComponents.size() >= 1 && fComponents.size() <= 4); } - std::string description() const override { - std::string result = fBase->description() + "."; + SkString description() const override { + SkString result = fBase->description() + "."; for (int x : fComponents) { result += "xyzw"[x]; } diff --git a/src/sksl/ir/SkSLSymbol.h b/src/sksl/ir/SkSLSymbol.h index d736516bc4..10dcaf9344 100644 --- a/src/sksl/ir/SkSLSymbol.h +++ b/src/sksl/ir/SkSLSymbol.h @@ -24,13 +24,13 @@ struct Symbol : public IRNode { kField_Kind }; - Symbol(Position position, Kind kind, std::string name) + Symbol(Position position, Kind kind, SkString name) : INHERITED(position) , fKind(kind) , fName(std::move(name)) {} const Kind fKind; - const std::string fName; + const SkString fName; typedef IRNode INHERITED; }; diff --git a/src/sksl/ir/SkSLSymbolTable.cpp b/src/sksl/ir/SkSLSymbolTable.cpp index 6d8e9a7ea6..3ceeab91b0 100644 --- a/src/sksl/ir/SkSLSymbolTable.cpp +++ b/src/sksl/ir/SkSLSymbolTable.cpp @@ -21,7 +21,7 @@ std::vector SymbolTable::GetFunctions(const Symbol& } } -const Symbol* SymbolTable::operator[](const std::string& name) { +const Symbol* SymbolTable::operator[](const SkString& name) { const auto& entry = fSymbols.find(name); if (entry == fSymbols.end()) { if (fParent) { @@ -64,12 +64,12 @@ Symbol* SymbolTable::takeOwnership(Symbol* s) { return s; } -void SymbolTable::add(const std::string& name, std::unique_ptr symbol) { +void SymbolTable::add(const SkString& name, std::unique_ptr symbol) { this->addWithoutOwnership(name, symbol.get()); fOwnedPointers.push_back(std::move(symbol)); } -void SymbolTable::addWithoutOwnership(const std::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; diff --git a/src/sksl/ir/SkSLSymbolTable.h b/src/sksl/ir/SkSLSymbolTable.h index be2b49c48d..df8dc713ae 100644 --- a/src/sksl/ir/SkSLSymbolTable.h +++ b/src/sksl/ir/SkSLSymbolTable.h @@ -31,11 +31,11 @@ public: : fParent(parent) , fErrorReporter(errorReporter) {} - const Symbol* operator[](const std::string& name); + const Symbol* operator[](const SkString& name); - void add(const std::string& name, std::unique_ptr symbol); + void add(const SkString& name, std::unique_ptr symbol); - void addWithoutOwnership(const std::string& name, const Symbol* symbol); + void addWithoutOwnership(const SkString& name, const Symbol* symbol); Symbol* takeOwnership(Symbol* s); @@ -48,7 +48,7 @@ private: std::vector> fOwnedPointers; - std::unordered_map fSymbols; + std::unordered_map fSymbols; ErrorReporter& fErrorReporter; }; diff --git a/src/sksl/ir/SkSLTernaryExpression.h b/src/sksl/ir/SkSLTernaryExpression.h index bfaf304e55..4a352536e3 100644 --- a/src/sksl/ir/SkSLTernaryExpression.h +++ b/src/sksl/ir/SkSLTernaryExpression.h @@ -26,7 +26,7 @@ struct TernaryExpression : public Expression { ASSERT(fIfTrue->fType == fIfFalse->fType); } - std::string description() const override { + SkString description() const override { return "(" + fTest->description() + " ? " + fIfTrue->description() + " : " + fIfFalse->description() + ")"; } diff --git a/src/sksl/ir/SkSLType.h b/src/sksl/ir/SkSLType.h index afd00d8b2a..4174c72a33 100644 --- a/src/sksl/ir/SkSLType.h +++ b/src/sksl/ir/SkSLType.h @@ -26,17 +26,17 @@ class Context; class Type : public Symbol { public: struct Field { - Field(Modifiers modifiers, std::string name, const Type* type) + Field(Modifiers modifiers, SkString name, const Type* type) : fModifiers(modifiers) , fName(std::move(name)) , fType(std::move(type)) {} - const std::string description() const { + const SkString description() const { return fType->description() + " " + fName + ";"; } Modifiers fModifiers; - std::string fName; + SkString fName; const Type* fType; }; @@ -53,14 +53,14 @@ public: // Create an "other" (special) type with the given name. These types cannot be directly // referenced from user code. - Type(std::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. As currently implemented, there are // always exactly four coercion targets, mapping to the scalar, vec2, vec3, and vec4 versions of // a type. - Type(std::string name, std::vector types) + Type(SkString name, std::vector types) : INHERITED(Position(), kType_Kind, std::move(name)) , fTypeKind(kGeneric_Kind) , fCoercibleTypes(std::move(types)) { @@ -68,13 +68,13 @@ public: } // Create a struct type with the given fields. - Type(std::string name, std::vector fields) + Type(SkString name, std::vector fields) : INHERITED(Position(), kType_Kind, std::move(name)) , fTypeKind(kStruct_Kind) , fFields(std::move(fields)) {} // Create a scalar type. - Type(std::string name, bool isNumber) + Type(SkString name, bool isNumber) : INHERITED(Position(), kType_Kind, std::move(name)) , fTypeKind(kScalar_Kind) , fIsNumber(isNumber) @@ -82,7 +82,7 @@ public: , fRows(1) {} // Create a scalar type which can be coerced to the listed types. - Type(std::string name, bool isNumber, std::vector coercibleTypes) + Type(SkString name, bool isNumber, std::vector coercibleTypes) : INHERITED(Position(), kType_Kind, std::move(name)) , fTypeKind(kScalar_Kind) , fIsNumber(isNumber) @@ -91,11 +91,11 @@ public: , fRows(1) {} // Create a vector type. - Type(std::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(std::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) @@ -104,7 +104,7 @@ public: , fDimensions(SpvDim1D) {} // Create a matrix type. - Type(std::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) @@ -113,7 +113,7 @@ public: , fDimensions(SpvDim1D) {} // Create a sampler type. - Type(std::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) @@ -123,11 +123,11 @@ public: , fIsMultisampled(isMultisampled) , fIsSampled(isSampled) {} - std::string name() const { + SkString name() const { return fName; } - std::string description() const override { + SkString description() const override { return fName; } diff --git a/src/sksl/ir/SkSLTypeReference.h b/src/sksl/ir/SkSLTypeReference.h index 67e0466763..1c6f16ce58 100644 --- a/src/sksl/ir/SkSLTypeReference.h +++ b/src/sksl/ir/SkSLTypeReference.h @@ -22,7 +22,7 @@ struct TypeReference : public Expression { : INHERITED(position, kTypeReference_Kind, *context.fInvalid_Type) , fValue(type) {} - std::string description() const override { + SkString description() const override { return fValue.name(); } diff --git a/src/sksl/ir/SkSLUnresolvedFunction.h b/src/sksl/ir/SkSLUnresolvedFunction.h index 7e8a3601e8..76741cfca8 100644 --- a/src/sksl/ir/SkSLUnresolvedFunction.h +++ b/src/sksl/ir/SkSLUnresolvedFunction.h @@ -26,7 +26,7 @@ struct UnresolvedFunction : public Symbol { #endif } - virtual std::string description() const override { + virtual SkString description() const override { return fName; } diff --git a/src/sksl/ir/SkSLVarDeclarations.h b/src/sksl/ir/SkSLVarDeclarations.h index e64a874d69..295c0b6997 100644 --- a/src/sksl/ir/SkSLVarDeclarations.h +++ b/src/sksl/ir/SkSLVarDeclarations.h @@ -27,8 +27,8 @@ struct VarDeclaration { , fSizes(std::move(sizes)) , fValue(std::move(value)) {} - std::string description() const { - std::string result = fVar->fName; + SkString description() const { + SkString result = fVar->fName; for (const auto& size : fSizes) { if (size) { result += "[" + size->description() + "]"; @@ -57,13 +57,12 @@ struct VarDeclarations : public ProgramElement { , fBaseType(*baseType) , fVars(std::move(vars)) {} - std::string description() const override { + SkString description() const override { if (!fVars.size()) { - return ""; + return SkString(); } - std::string result = fVars[0].fVar->fModifiers.description() + fBaseType.description() + - " "; - std::string separator = ""; + SkString result = fVars[0].fVar->fModifiers.description() + fBaseType.description() + " "; + SkString separator; for (const auto& var : fVars) { result += separator; separator = ", "; diff --git a/src/sksl/ir/SkSLVarDeclarationsStatement.h b/src/sksl/ir/SkSLVarDeclarationsStatement.h index 0b62edb866..7a29656593 100644 --- a/src/sksl/ir/SkSLVarDeclarationsStatement.h +++ b/src/sksl/ir/SkSLVarDeclarationsStatement.h @@ -21,7 +21,7 @@ struct VarDeclarationsStatement : public Statement { : INHERITED(decl->fPosition, kVarDeclarations_Kind) , fDeclaration(std::move(decl)) {} - std::string description() const override { + SkString description() const override { return fDeclaration->description(); } diff --git a/src/sksl/ir/SkSLVariable.h b/src/sksl/ir/SkSLVariable.h index 217b1006b6..39b8482a7b 100644 --- a/src/sksl/ir/SkSLVariable.h +++ b/src/sksl/ir/SkSLVariable.h @@ -27,7 +27,7 @@ struct Variable : public Symbol { kParameter_Storage }; - Variable(Position position, Modifiers modifiers, std::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) @@ -36,7 +36,7 @@ struct Variable : public Symbol { , fIsReadFrom(false) , fIsWrittenTo(false) {} - virtual std::string description() const override { + virtual SkString description() const override { return fModifiers.description() + fType.fName + " " + fName; } diff --git a/src/sksl/ir/SkSLVariableReference.h b/src/sksl/ir/SkSLVariableReference.h index b443da1f22..c6a2ea0511 100644 --- a/src/sksl/ir/SkSLVariableReference.h +++ b/src/sksl/ir/SkSLVariableReference.h @@ -24,7 +24,7 @@ struct VariableReference : public Expression { : INHERITED(position, kVariableReference_Kind, variable.fType) , fVariable(variable) {} - std::string description() const override { + SkString description() const override { return fVariable.fName; } diff --git a/src/sksl/ir/SkSLWhileStatement.h b/src/sksl/ir/SkSLWhileStatement.h index 1acb572583..7c6a2907c4 100644 --- a/src/sksl/ir/SkSLWhileStatement.h +++ b/src/sksl/ir/SkSLWhileStatement.h @@ -23,7 +23,7 @@ struct WhileStatement : public Statement { , fTest(std::move(test)) , fStatement(std::move(statement)) {} - std::string description() const override { + SkString description() const override { return "while (" + fTest->description() + ") " + fStatement->description(); } -- cgit v1.2.3