aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/GLBench.cpp5
-rw-r--r--fuzz/fuzz.cpp4
-rw-r--r--src/gpu/gl/builders/GrGLShaderStringBuilder.cpp28
-rw-r--r--src/gpu/vk/GrVkUtil.cpp4
-rw-r--r--src/sksl/SkSLCodeGenerator.h4
-rw-r--r--src/sksl/SkSLCompiler.cpp53
-rw-r--r--src/sksl/SkSLCompiler.h24
-rw-r--r--src/sksl/SkSLContext.h210
-rw-r--r--src/sksl/SkSLErrorReporter.h6
-rw-r--r--src/sksl/SkSLGLSLCodeGenerator.cpp45
-rw-r--r--src/sksl/SkSLGLSLCodeGenerator.h13
-rw-r--r--src/sksl/SkSLIRGenerator.cpp34
-rw-r--r--src/sksl/SkSLIRGenerator.h4
-rw-r--r--src/sksl/SkSLMain.cpp34
-rw-r--r--src/sksl/SkSLParser.cpp37
-rw-r--r--src/sksl/SkSLParser.h15
-rw-r--r--src/sksl/SkSLPosition.h2
-rw-r--r--src/sksl/SkSLSPIRVCodeGenerator.cpp923
-rw-r--r--src/sksl/SkSLSPIRVCodeGenerator.h130
-rw-r--r--src/sksl/SkSLToken.h80
-rw-r--r--src/sksl/SkSLUtil.cpp89
-rw-r--r--src/sksl/SkSLUtil.h52
-rw-r--r--src/sksl/ast/SkSLASTBinaryExpression.h3
-rw-r--r--src/sksl/ast/SkSLASTBlock.h4
-rw-r--r--src/sksl/ast/SkSLASTBoolLiteral.h4
-rw-r--r--src/sksl/ast/SkSLASTBreakStatement.h4
-rw-r--r--src/sksl/ast/SkSLASTCallSuffix.h7
-rw-r--r--src/sksl/ast/SkSLASTContinueStatement.h4
-rw-r--r--src/sksl/ast/SkSLASTDiscardStatement.h4
-rw-r--r--src/sksl/ast/SkSLASTDoStatement.h2
-rw-r--r--src/sksl/ast/SkSLASTExpressionStatement.h2
-rw-r--r--src/sksl/ast/SkSLASTExtension.h6
-rw-r--r--src/sksl/ast/SkSLASTFieldSuffix.h6
-rw-r--r--src/sksl/ast/SkSLASTFloatLiteral.h2
-rw-r--r--src/sksl/ast/SkSLASTForStatement.h4
-rw-r--r--src/sksl/ast/SkSLASTFunction.h8
-rw-r--r--src/sksl/ast/SkSLASTIdentifier.h6
-rw-r--r--src/sksl/ast/SkSLASTIfStatement.h4
-rw-r--r--src/sksl/ast/SkSLASTIndexSuffix.h4
-rw-r--r--src/sksl/ast/SkSLASTIntLiteral.h2
-rw-r--r--src/sksl/ast/SkSLASTInterfaceBlock.h14
-rw-r--r--src/sksl/ast/SkSLASTLayout.h10
-rw-r--r--src/sksl/ast/SkSLASTModifiers.h4
-rw-r--r--src/sksl/ast/SkSLASTModifiersDeclaration.h2
-rw-r--r--src/sksl/ast/SkSLASTNode.h5
-rw-r--r--src/sksl/ast/SkSLASTParameter.h8
-rw-r--r--src/sksl/ast/SkSLASTPrecision.h12
-rw-r--r--src/sksl/ast/SkSLASTPrefixExpression.h2
-rw-r--r--src/sksl/ast/SkSLASTReturnStatement.h4
-rw-r--r--src/sksl/ast/SkSLASTSuffix.h6
-rw-r--r--src/sksl/ast/SkSLASTSuffixExpression.h2
-rw-r--r--src/sksl/ast/SkSLASTTernaryExpression.h2
-rw-r--r--src/sksl/ast/SkSLASTType.h6
-rw-r--r--src/sksl/ast/SkSLASTVarDeclaration.h14
-rw-r--r--src/sksl/ast/SkSLASTVarDeclarationStatement.h2
-rw-r--r--src/sksl/ast/SkSLASTWhileStatement.h2
-rw-r--r--src/sksl/ir/SkSLBinaryExpression.h2
-rw-r--r--src/sksl/ir/SkSLBlock.h8
-rw-r--r--src/sksl/ir/SkSLBoolLiteral.h4
-rw-r--r--src/sksl/ir/SkSLBreakStatement.h4
-rw-r--r--src/sksl/ir/SkSLConstructor.h6
-rw-r--r--src/sksl/ir/SkSLContinueStatement.h4
-rw-r--r--src/sksl/ir/SkSLDiscardStatement.h4
-rw-r--r--src/sksl/ir/SkSLDoStatement.h2
-rw-r--r--src/sksl/ir/SkSLExpressionStatement.h2
-rw-r--r--src/sksl/ir/SkSLExtension.h6
-rw-r--r--src/sksl/ir/SkSLField.h2
-rw-r--r--src/sksl/ir/SkSLFieldAccess.h2
-rw-r--r--src/sksl/ir/SkSLFloatLiteral.h2
-rw-r--r--src/sksl/ir/SkSLForStatement.h4
-rw-r--r--src/sksl/ir/SkSLFunctionCall.h6
-rw-r--r--src/sksl/ir/SkSLFunctionDeclaration.h8
-rw-r--r--src/sksl/ir/SkSLFunctionDefinition.h2
-rw-r--r--src/sksl/ir/SkSLFunctionReference.h4
-rw-r--r--src/sksl/ir/SkSLIRNode.h2
-rw-r--r--src/sksl/ir/SkSLIfStatement.h4
-rw-r--r--src/sksl/ir/SkSLIndexExpression.h2
-rw-r--r--src/sksl/ir/SkSLIntLiteral.h2
-rw-r--r--src/sksl/ir/SkSLInterfaceBlock.h4
-rw-r--r--src/sksl/ir/SkSLLayout.h8
-rw-r--r--src/sksl/ir/SkSLModifiers.h4
-rw-r--r--src/sksl/ir/SkSLModifiersDeclaration.h2
-rw-r--r--src/sksl/ir/SkSLPostfixExpression.h2
-rw-r--r--src/sksl/ir/SkSLPrefixExpression.h2
-rw-r--r--src/sksl/ir/SkSLReturnStatement.h4
-rw-r--r--src/sksl/ir/SkSLSwizzle.h4
-rw-r--r--src/sksl/ir/SkSLSymbol.h4
-rw-r--r--src/sksl/ir/SkSLSymbolTable.cpp6
-rw-r--r--src/sksl/ir/SkSLSymbolTable.h8
-rw-r--r--src/sksl/ir/SkSLTernaryExpression.h2
-rw-r--r--src/sksl/ir/SkSLType.h28
-rw-r--r--src/sksl/ir/SkSLTypeReference.h2
-rw-r--r--src/sksl/ir/SkSLUnresolvedFunction.h2
-rw-r--r--src/sksl/ir/SkSLVarDeclarations.h13
-rw-r--r--src/sksl/ir/SkSLVarDeclarationsStatement.h2
-rw-r--r--src/sksl/ir/SkSLVariable.h4
-rw-r--r--src/sksl/ir/SkSLVariableReference.h2
-rw-r--r--src/sksl/ir/SkSLWhileStatement.h2
-rw-r--r--tests/SkSLErrorTest.cpp15
-rw-r--r--tests/SkSLGLSLTest.cpp15
100 files changed, 1060 insertions, 1124 deletions
diff --git a/bench/GLBench.cpp b/bench/GLBench.cpp
index a39edeee7f..df9ee9bb0d 100644
--- a/bench/GLBench.cpp
+++ b/bench/GLBench.cpp
@@ -14,6 +14,7 @@
#include "gl/builders/GrGLShaderStringBuilder.h"
#include "SkSLCompiler.h"
#include <stdio.h>
+#include <string>
const GrGLContext* GLBench::getGLContext(SkCanvas* canvas) {
// This bench exclusively tests GL calls directly
@@ -65,11 +66,11 @@ void GLBench::onDraw(int loops, SkCanvas* canvas) {
GrGLuint GLBench::CompileShader(const GrGLContext* context, const char* sksl, GrGLenum type) {
const GrGLInterface* gl = context->interface();
- SkString glsl;
+ std::string glsl;
bool result = context->compiler()->toGLSL(type == GR_GL_VERTEX_SHADER
? SkSL::Program::kVertex_Kind
: SkSL::Program::kFragment_Kind,
- SkString(sksl),
+ std::string(sksl),
*context->caps()->glslCaps(),
&glsl);
if (!result) {
diff --git a/fuzz/fuzz.cpp b/fuzz/fuzz.cpp
index 377e53f656..d146a2f519 100644
--- a/fuzz/fuzz.cpp
+++ b/fuzz/fuzz.cpp
@@ -402,9 +402,9 @@ int fuzz_color_deserialize(sk_sp<SkData> bytes) {
#if SK_SUPPORT_GPU
int fuzz_sksl2glsl(sk_sp<SkData> bytes) {
SkSL::Compiler compiler;
- SkString output;
+ std::string output;
bool result = compiler.toGLSL(SkSL::Program::kFragment_Kind,
- SkString((const char*)bytes->data()), *SkSL::GLSLCapsFactory::Default(), &output);
+ (const char*)bytes->data(), *SkSL::GLSLCapsFactory::Default(), &output);
if (!result) {
SkDebugf("[terminated] Couldn't compile input.\n");
diff --git a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
index 86df089d82..1e42259128 100644
--- a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
@@ -21,19 +21,18 @@ static const bool c_PrintShaders{false};
static void print_shader_source(const char** strings, int* lengths, int count);
-static void dump_string(SkString s) {
+static void dump_string(std::string 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.
- const char* chars = s.c_str();
+ size_t index = 0;
for (;;) {
- const char* next = strchr(chars, '\n');
- if (next) {
- next++;
- SkDebugf("%s", SkString(chars, next - chars).c_str());
- chars = next;
- } else {
- SkDebugf("%s", chars);
+ size_t next = s.find("\n", index);
+ if (next == std::string::npos) {
+ SkDebugf("%s", s.substr(index).c_str());
break;
+ } else {
+ SkDebugf("%s", s.substr(index, next - index + 1).c_str());
+ index = next + 1;
}
}
}
@@ -53,22 +52,23 @@ GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
return 0;
}
- SkString sksl;
+ std::string sksl;
#ifdef SK_DEBUG
- sksl = GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths, count, false);
+ SkString prettySource = GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths, count, false);
+ sksl = std::string(prettySource.c_str());
#else
for (int i = 0; i < count; i++) {
sksl.append(strings[i], lengths[i]);
}
#endif
- SkString glsl;
+ std::string 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,
- sksl,
+ std::string(sksl.c_str()),
*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.size();
+ GrGLint glslLength = (GrGLint) glsl.length();
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 4446dfe6c2..1d93e8d4e5 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
- SkString code;
+ std::string 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),
- SkString(shaderString),
+ std::string(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 211cf0aadf..7bf857d0ba 100644
--- a/src/sksl/SkSLCodeGenerator.h
+++ b/src/sksl/SkSLCodeGenerator.h
@@ -9,6 +9,8 @@
#define SKSL_CODEGENERATOR
#include "ir/SkSLProgram.h"
+#include <vector>
+#include <ostream>
namespace SkSL {
@@ -20,7 +22,7 @@ class CodeGenerator {
public:
virtual ~CodeGenerator() {}
- virtual void generateCode(const Program& program, SkWStream& out) = 0;
+ virtual void generateCode(const Program& program, std::ostream& out) = 0;
};
} // namespace
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp
index 905eff4e28..510d610a6e 100644
--- a/src/sksl/SkSLCompiler.cpp
+++ b/src/sksl/SkSLCompiler.cpp
@@ -7,6 +7,9 @@
#include "SkSLCompiler.h"
+#include <fstream>
+#include <streambuf>
+
#include "ast/SkSLASTPrecision.h"
#include "SkSLCFGGenerator.h"
#include "SkSLIRGenerator.h"
@@ -68,17 +71,17 @@ Compiler::Compiler()
ADD_TYPE(BVec3);
ADD_TYPE(BVec4);
ADD_TYPE(Mat2x2);
- types->addWithoutOwnership(SkString("mat2x2"), fContext.fMat2x2_Type.get());
+ types->addWithoutOwnership("mat2x2", fContext.fMat2x2_Type.get());
ADD_TYPE(Mat2x3);
ADD_TYPE(Mat2x4);
ADD_TYPE(Mat3x2);
ADD_TYPE(Mat3x3);
- types->addWithoutOwnership(SkString("mat3x3"), fContext.fMat3x3_Type.get());
+ types->addWithoutOwnership("mat3x3", fContext.fMat3x3_Type.get());
ADD_TYPE(Mat3x4);
ADD_TYPE(Mat4x2);
ADD_TYPE(Mat4x3);
ADD_TYPE(Mat4x4);
- types->addWithoutOwnership(SkString("mat4x4"), fContext.fMat4x4_Type.get());
+ types->addWithoutOwnership("mat4x4", fContext.fMat4x4_Type.get());
ADD_TYPE(GenType);
ADD_TYPE(GenDType);
ADD_TYPE(GenIType);
@@ -137,7 +140,7 @@ Compiler::Compiler()
Modifiers::Flag ignored1;
std::vector<std::unique_ptr<ProgramElement>> ignored2;
- this->internalConvertProgram(SkString(SKSL_INCLUDE), &ignored1, &ignored2);
+ this->internalConvertProgram(SKSL_INCLUDE, &ignored1, &ignored2);
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
ASSERT(!fErrorCount);
}
@@ -286,7 +289,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, SkString("unreachable"));
+ this->error(cfg.fBlocks[i].fNodes[0].fNode->fPosition, "unreachable");
}
}
if (fErrorCount) {
@@ -315,12 +318,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, SkString("function can exit without returning a value"));
+ this->error(f.fPosition, "function can exit without returning a value");
}
}
}
-void Compiler::internalConvertProgram(SkString text,
+void Compiler::internalConvertProgram(std::string text,
Modifiers::Flag* defaultPrecision,
std::vector<std::unique_ptr<ProgramElement>>* result) {
Parser parser(text, *fTypes, *this);
@@ -383,7 +386,7 @@ void Compiler::internalConvertProgram(SkString text,
}
}
-std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, SkString text) {
+std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, std::string text) {
fErrorText = "";
fErrorCount = 0;
fIRGenerator->pushSymbolTable();
@@ -391,10 +394,10 @@ std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, SkString t
Modifiers::Flag ignored;
switch (kind) {
case Program::kVertex_Kind:
- this->internalConvertProgram(SkString(SKSL_VERT_INCLUDE), &ignored, &elements);
+ this->internalConvertProgram(SKSL_VERT_INCLUDE, &ignored, &elements);
break;
case Program::kFragment_Kind:
- this->internalConvertProgram(SkString(SKSL_FRAG_INCLUDE), &ignored, &elements);
+ this->internalConvertProgram(SKSL_FRAG_INCLUDE, &ignored, &elements);
break;
}
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
@@ -407,13 +410,13 @@ std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, SkString t
return result;
}
-void Compiler::error(Position position, SkString msg) {
+void Compiler::error(Position position, std::string msg) {
fErrorCount++;
fErrorText += "error: " + position.description() + ": " + msg.c_str() + "\n";
}
-SkString Compiler::errorText() {
- SkString result = fErrorText;
+std::string Compiler::errorText() {
+ std::string result = fErrorText;
return result;
}
@@ -427,42 +430,42 @@ void Compiler::writeErrorCount() {
}
}
-bool Compiler::toSPIRV(Program::Kind kind, const SkString& text, SkWStream& out) {
+bool Compiler::toSPIRV(Program::Kind kind, const std::string& text, std::ostream& 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 SkString& text, SkString* out) {
- SkDynamicMemoryWStream buffer;
+bool Compiler::toSPIRV(Program::Kind kind, const std::string& text, std::string* out) {
+ std::stringstream buffer;
bool result = this->toSPIRV(kind, text, buffer);
if (result) {
- sk_sp<SkData> data(buffer.detachAsData());
- *out = SkString((const char*) data->data(), data->size());
+ *out = buffer.str();
}
return result;
}
-bool Compiler::toGLSL(Program::Kind kind, const SkString& text, const GrGLSLCaps& caps,
- SkWStream& out) {
+bool Compiler::toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps,
+ std::ostream& 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 SkString& text, const GrGLSLCaps& caps,
- SkString* out) {
- SkDynamicMemoryWStream buffer;
+bool Compiler::toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps,
+ std::string* out) {
+ std::stringstream buffer;
bool result = this->toGLSL(kind, text, caps, buffer);
if (result) {
- sk_sp<SkData> data(buffer.detachAsData());
- *out = SkString((const char*) data->data(), data->size());
+ *out = buffer.str();
}
return result;
}
diff --git a/src/sksl/SkSLCompiler.h b/src/sksl/SkSLCompiler.h
index e1bc052fef..e69db5997d 100644
--- a/src/sksl/SkSLCompiler.h
+++ b/src/sksl/SkSLCompiler.h
@@ -37,21 +37,21 @@ public:
~Compiler();
- std::unique_ptr<Program> convertProgram(Program::Kind kind, SkString text);
+ std::unique_ptr<Program> convertProgram(Program::Kind kind, std::string text);
- bool toSPIRV(Program::Kind kind, const SkString& text, SkWStream& out);
+ bool toSPIRV(Program::Kind kind, const std::string& text, std::ostream& out);
- bool toSPIRV(Program::Kind kind, const SkString& text, SkString* out);
+ bool toSPIRV(Program::Kind kind, const std::string& text, std::string* 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::ostream& out);
- bool toGLSL(Program::Kind kind, const SkString& text, const GrGLSLCaps& caps,
- SkString* out);
+ bool toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps,
+ std::string* out);
- void error(Position position, SkString msg) override;
+ void error(Position position, std::string msg) override;
- SkString errorText();
+ std::string errorText();
void writeErrorCount();
@@ -66,17 +66,17 @@ private:
void scanCFG(const FunctionDefinition& f);
- void internalConvertProgram(SkString text,
+ void internalConvertProgram(std::string text,
Modifiers::Flag* defaultPrecision,
std::vector<std::unique_ptr<ProgramElement>>* result);
std::shared_ptr<SymbolTable> fTypes;
IRGenerator* fIRGenerator;
- SkString fSkiaVertText; // FIXME store parsed version instead
+ std::string fSkiaVertText; // FIXME store parsed version instead
Context fContext;
int fErrorCount;
- SkString fErrorText;
+ std::string fErrorText;
};
} // namespace
diff --git a/src/sksl/SkSLContext.h b/src/sksl/SkSLContext.h
index 05e08f24cb..a42a4cc855 100644
--- a/src/sksl/SkSLContext.h
+++ b/src/sksl/SkSLContext.h
@@ -19,120 +19,114 @@ namespace SkSL {
class Context {
public:
Context()
- : fInvalid_Type(new Type(SkString("<INVALID>")))
- , fVoid_Type(new Type(SkString("void")))
- , fDouble_Type(new Type(SkString("double"), true))
- , fDVec2_Type(new Type(SkString("dvec2"), *fDouble_Type, 2))
- , fDVec3_Type(new Type(SkString("dvec3"), *fDouble_Type, 3))
- , fDVec4_Type(new Type(SkString("dvec4"), *fDouble_Type, 4))
- , fFloat_Type(new Type(SkString("float"), true, { fDouble_Type.get() }))
- , fVec2_Type(new Type(SkString("vec2"), *fFloat_Type, 2))
- , fVec3_Type(new Type(SkString("vec3"), *fFloat_Type, 3))
- , fVec4_Type(new Type(SkString("vec4"), *fFloat_Type, 4))
- , fUInt_Type(new Type(SkString("uint"), true, { fFloat_Type.get(), fDouble_Type.get() }))
- , fUVec2_Type(new Type(SkString("uvec2"), *fUInt_Type, 2))
- , fUVec3_Type(new Type(SkString("uvec3"), *fUInt_Type, 3))
- , fUVec4_Type(new Type(SkString("uvec4"), *fUInt_Type, 4))
- , fInt_Type(new Type(SkString("int"), true, { fUInt_Type.get(), fFloat_Type.get(),
- fDouble_Type.get() }))
- , fIVec2_Type(new Type(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")))
+ : fInvalid_Type(new Type("<INVALID>"))
+ , 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"))
// Related to below FIXME, gsampler*s don't currently expand to cover integer case.
- , fISampler2D_Type(new Type(SkString("isampler2D"), SpvDim2D, false, false, false, true))
+ , fISampler2D_Type(new Type("isampler2D", SpvDim2D, false, false, false, true))
// FIXME express these as "gimage2D" that expand to image2D, iimage2D, and uimage2D.
- , fImage2D_Type(new Type(SkString("image2D"), SpvDim2D, false, false, false, true))
- , fIImage2D_Type(new Type(SkString("iimage2D"), SpvDim2D, false, false, false, true))
+ , fImage2D_Type(new Type("image2D", SpvDim2D, false, false, false, true))
+ , fIImage2D_Type(new Type("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(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"),
+ , 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",
static_type(*fSampler2DArrayShadow_Type)))
- , fGSamplerCubeArrayShadow_Type(new Type(SkString("$gsamplerCubeArrayShadow"),
+ , fGSamplerCubeArrayShadow_Type(new Type("$gsamplerCubeArrayShadow",
static_type(*fSamplerCubeArrayShadow_Type)))
- , 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() }))
+ , 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() }))
, fDefined_Expression(new Defined(*fInvalid_Type)) {}
static std::vector<const Type*> static_type(const Type& t) {
@@ -258,8 +252,8 @@ private:
Defined(const Type& type)
: INHERITED(Position(), kDefined_Kind, type) {}
- virtual SkString description() const override {
- return SkString("<defined>");
+ virtual std::string description() const override {
+ return "<defined>";
}
typedef Expression INHERITED;
diff --git a/src/sksl/SkSLErrorReporter.h b/src/sksl/SkSLErrorReporter.h
index 585a97cc51..26b44711c3 100644
--- a/src/sksl/SkSLErrorReporter.h
+++ b/src/sksl/SkSLErrorReporter.h
@@ -19,11 +19,7 @@ class ErrorReporter {
public:
virtual ~ErrorReporter() {}
- void error(Position position, const char* msg) {
- this->error(position, SkString(msg));
- }
-
- virtual void error(Position position, SkString msg) = 0;
+ virtual void error(Position position, std::string msg) = 0;
};
} // namespace
diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp
index 553626127b..1252f86466 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->writeText(" ");
+ *fOut << " ";
}
}
- fOut->writeText(s);
+ *fOut << s;
fAtLineStart = false;
}
void GLSLCodeGenerator::writeLine(const char* s) {
this->write(s);
- fOut->writeText("\n");
+ *fOut << "\n";
fAtLineStart = true;
}
-void GLSLCodeGenerator::write(const SkString& s) {
+void GLSLCodeGenerator::write(const std::string& s) {
this->write(s.c_str());
}
-void GLSLCodeGenerator::writeLine(const SkString& s) {
+void GLSLCodeGenerator::writeLine(const std::string& 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());
- SkString tmpVar1 = "minAbsHackVar" + to_string(fVarCount++);
- SkString tmpVar2 = "minAbsHackVar" + to_string(fVarCount++);
+ std::string tmpVar1 = "minAbsHackVar" + to_string(fVarCount++);
+ std::string tmpVar2 = "minAbsHackVar" + to_string(fVarCount++);
this->fFunctionHeader += " " + absExpr.fType.name() + " " + tmpVar1 + ";\n";
this->fFunctionHeader += " " + otherExpr.fType.name() + " " + tmpVar2 + ";\n";
this->write("((" + tmpVar1 + " = ");
@@ -179,9 +179,7 @@ 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.writeText("#extension ");
- fHeader.writeText(fCaps.shaderDerivativeExtensionString());
- fHeader.writeText(" : require\n");
+ fHeader << "#extension " << fCaps.shaderDerivativeExtensionString() << " : require\n";
fFoundDerivatives = true;
}
this->write(c.fFunction.fName + "(");
@@ -375,8 +373,8 @@ void GLSLCodeGenerator::writeFunction(const FunctionDefinition& f) {
this->writeLine(") {");
fFunctionHeader = "";
- SkWStream* oldOut = fOut;
- SkDynamicMemoryWStream buffer;
+ std::ostream* oldOut = fOut;
+ std::stringstream buffer;
fOut = &buffer;
fIndentation++;
for (const auto& s : f.fBody->fStatements) {
@@ -388,8 +386,7 @@ void GLSLCodeGenerator::writeFunction(const FunctionDefinition& f) {
fOut = oldOut;
this->write(fFunctionHeader);
- sk_sp<SkData> data(buffer.detachAsData());
- this->write(SkString((const char*) data->data(), data->size()));
+ this->write(buffer.str());
}
void GLSLCodeGenerator::writeModifiers(const Modifiers& modifiers,
@@ -400,8 +397,8 @@ void GLSLCodeGenerator::writeModifiers(const Modifiers& modifiers,
if (modifiers.fFlags & Modifiers::kFlat_Flag) {
this->write("flat ");
}
- SkString layout = modifiers.fLayout.description();
- if (layout.size()) {
+ std::string layout = modifiers.fLayout.description();
+ if (layout.length()) {
this->write(layout + " ");
}
if ((modifiers.fFlags & Modifiers::kIn_Flag) &&
@@ -460,11 +457,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);
- SkString separator(" ");
+ std::string separator = " ";
for (const auto& var : decl.fVars) {
ASSERT(var.fVar->fModifiers == decl.fVars[0].fVar->fModifiers);
this->write(separator);
- separator = SkString(", ");
+ separator = ", ";
this->write(var.fVar->fName);
for (const auto& size : var.fSizes) {
this->write("[");
@@ -479,9 +476,7 @@ void GLSLCodeGenerator::writeVarDeclarations(const VarDeclarations& decl, bool g
}
if (!fFoundImageDecl && var.fVar->fType == *fContext.fImage2D_Type) {
if (fCaps.imageLoadStoreExtensionString()) {
- fHeader.writeText("#extension ");
- fHeader.writeText(fCaps.imageLoadStoreExtensionString());
- fHeader.writeText(" : require\n");
+ fHeader << "#extension " << fCaps.imageLoadStoreExtensionString() << " : require\n";
}
fFoundImageDecl = true;
}
@@ -594,7 +589,7 @@ void GLSLCodeGenerator::writeReturnStatement(const ReturnStatement& r) {
this->write(";");
}
-void GLSLCodeGenerator::generateCode(const Program& program, SkWStream& out) {
+void GLSLCodeGenerator::generateCode(const Program& program, std::ostream& out) {
ASSERT(fOut == nullptr);
fOut = &fHeader;
fProgramKind = program.fKind;
@@ -605,7 +600,7 @@ void GLSLCodeGenerator::generateCode(const Program& program, SkWStream& out) {
this->writeExtension((Extension&) *e);
}
}
- SkDynamicMemoryWStream body;
+ std::stringstream body;
fOut = &body;
if (fCaps.usesPrecisionModifiers()) {
this->write("precision ");
@@ -665,8 +660,8 @@ void GLSLCodeGenerator::generateCode(const Program& program, SkWStream& out) {
}
fOut = nullptr;
- write_data(*fHeader.detachAsData(), out);
- write_data(*body.detachAsData(), out);
+ out << fHeader.str();
+ out << body.str();
}
}
diff --git a/src/sksl/SkSLGLSLCodeGenerator.h b/src/sksl/SkSLGLSLCodeGenerator.h
index b8cb34e84f..16d6192a71 100644
--- a/src/sksl/SkSLGLSLCodeGenerator.h
+++ b/src/sksl/SkSLGLSLCodeGenerator.h
@@ -12,7 +12,6 @@
#include <tuple>
#include <unordered_map>
-#include "SkStream.h"
#include "glsl/GrGLSLCaps.h"
#include "SkSLCodeGenerator.h"
#include "ir/SkSLBinaryExpression.h"
@@ -76,7 +75,7 @@ public:
: fContext(*context)
, fCaps(*caps) {}
- void generateCode(const Program& program, SkWStream& out) override;
+ void generateCode(const Program& program, std::ostream& out) override;
private:
void write(const char* s);
@@ -85,9 +84,9 @@ private:
void writeLine(const char* s);
- void write(const SkString& s);
+ void write(const std::string& s);
- void writeLine(const SkString& s);
+ void writeLine(const std::string& s);
void writeType(const Type& type);
@@ -157,9 +156,9 @@ private:
const Context& fContext;
const GrGLSLCaps& fCaps;
- SkWStream* fOut = nullptr;
- SkDynamicMemoryWStream fHeader;
- SkString fFunctionHeader;
+ std::ostream* fOut = nullptr;
+ std::stringstream fHeader;
+ std::string fFunctionHeader;
Program::Kind fProgramKind;
int fVarCount = 0;
int fIndentation = 0;
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp
index 245c72f5db..1a4c775998 100644
--- a/src/sksl/SkSLIRGenerator.cpp
+++ b/src/sksl/SkSLIRGenerator.cpp
@@ -173,7 +173,7 @@ std::unique_ptr<VarDeclarations> IRGenerator::convertVarDeclarations(const ASTVa
if (!size) {
return nullptr;
}
- SkString name = type->fName;
+ std::string name = type->fName;
uint64_t count;
if (size->fKind == Expression::kIntLiteral_Kind) {
count = ((IntLiteral&) *size).fValue;
@@ -204,7 +204,7 @@ std::unique_ptr<VarDeclarations> IRGenerator::convertVarDeclarations(const ASTVa
}
value = this->coerce(std::move(value), *type);
}
- if (storage == Variable::kGlobal_Storage && varDecl.fName == SkString("sk_FragColor") &&
+ if (storage == Variable::kGlobal_Storage && "sk_FragColor" == varDecl.fName &&
(*fSymbolTable)[varDecl.fName]) {
// already defined, ignore
} else if (storage == Variable::kGlobal_Storage && (*fSymbolTable)[varDecl.fName] &&
@@ -397,12 +397,12 @@ std::unique_ptr<FunctionDefinition> IRGenerator::convertFunction(const ASTFuncti
}
for (int j = (int) param->fSizes.size() - 1; j >= 0; j--) {
int size = param->fSizes[j];
- SkString name = type->name() + "[" + to_string(size) + "]";
+ std::string name = type->name() + "[" + to_string(size) + "]";
Type* newType = new Type(std::move(name), Type::kArray_Kind, *type, size);
fSymbolTable->takeOwnership(newType);
type = newType;
}
- SkString name = param->fName;
+ std::string 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<InterfaceBlock> IRGenerator::convertInterfaceBlock(const ASTInte
}
Type* type = new Type(intf.fInterfaceName, fields);
fSymbolTable->takeOwnership(type);
- SkString name = intf.fValueName.size() > 0 ? intf.fValueName : intf.fInterfaceName;
+ std::string name = intf.fValueName.length() > 0 ? intf.fValueName : intf.fInterfaceName;
Variable* var = new Variable(intf.fPosition, mods, name, *type, Variable::kGlobal_Storage);
fSymbolTable->takeOwnership(var);
- if (intf.fValueName.size()) {
+ if (intf.fValueName.length()) {
old->addWithoutOwnership(intf.fValueName, var);
} else {
for (size_t i = 0; i < fields.size(); i++) {
@@ -966,7 +966,7 @@ std::unique_ptr<Expression> IRGenerator::call(Position position,
const FunctionDeclaration& function,
std::vector<std::unique_ptr<Expression>> arguments) {
if (function.fParameters.size() != arguments.size()) {
- SkString msg = "call to '" + function.fName + "' expected " +
+ std::string 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<Expression> IRGenerator::call(Position position,
std::vector<const Type*> types;
const Type* returnType;
if (!function.determineFinalTypes(arguments, &types, &returnType)) {
- SkString msg = "no match for " + function.fName + "(";
- SkString separator;
+ std::string msg = "no match for " + function.fName + "(";
+ std::string separator = "";
for (size_t i = 0; i < arguments.size(); i++) {
msg += separator;
separator = ", ";
@@ -1058,8 +1058,8 @@ std::unique_ptr<Expression> IRGenerator::call(Position position,
if (best) {
return this->call(position, *best, std::move(arguments));
}
- SkString msg = "no match for " + ref->fFunctions[0]->fName + "(";
- SkString separator;
+ std::string msg = "no match for " + ref->fFunctions[0]->fName + "(";
+ std::string separator = "";
for (size_t i = 0; i < arguments.size(); i++) {
msg += separator;
separator = ", ";
@@ -1267,7 +1267,7 @@ std::unique_ptr<Expression> IRGenerator::convertIndex(std::unique_ptr<Expression
}
std::unique_ptr<Expression> IRGenerator::convertField(std::unique_ptr<Expression> base,
- const SkString& field) {
+ const std::string& 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<Expression> IRGenerator::convertField(std::unique_ptr<Expression
}
std::unique_ptr<Expression> IRGenerator::convertSwizzle(std::unique_ptr<Expression> base,
- const SkString& fields) {
+ const std::string& fields) {
if (base->fType.kind() != Type::kVector_Kind) {
fErrors.error(base->fPosition, "cannot swizzle type '" + base->fType.description() + "'");
return nullptr;
}
std::vector<int> swizzleComponents;
- for (size_t i = 0; i < fields.size(); i++) {
- switch (fields[i]) {
+ for (char c : fields) {
+ switch (c) {
case 'x': // fall through
case 'r': // fall through
case 's':
@@ -1318,8 +1318,8 @@ std::unique_ptr<Expression> IRGenerator::convertSwizzle(std::unique_ptr<Expressi
}
// fall through
default:
- fErrors.error(base->fPosition, SkStringPrintf("invalid swizzle component '%c'",
- fields[i]));
+ fErrors.error(base->fPosition, "invalid swizzle component '" + std::string(1, c) +
+ "'");
return nullptr;
}
}
diff --git a/src/sksl/SkSLIRGenerator.h b/src/sksl/SkSLIRGenerator.h
index d7bd59ad02..036f24253b 100644
--- a/src/sksl/SkSLIRGenerator.h
+++ b/src/sksl/SkSLIRGenerator.h
@@ -107,9 +107,9 @@ private:
std::unique_ptr<Statement> convertReturn(const ASTReturnStatement& r);
std::unique_ptr<Expression> convertSuffixExpression(const ASTSuffixExpression& expression);
std::unique_ptr<Expression> convertField(std::unique_ptr<Expression> base,
- const SkString& field);
+ const std::string& field);
std::unique_ptr<Expression> convertSwizzle(std::unique_ptr<Expression> base,
- const SkString& fields);
+ const std::string& fields);
std::unique_ptr<Expression> convertTernaryExpression(const ASTTernaryExpression& expression);
std::unique_ptr<Statement> convertVarDeclarationStatement(const ASTVarDeclarationStatement& s);
std::unique_ptr<Statement> convertWhile(const ASTWhileStatement& w);
diff --git a/src/sksl/SkSLMain.cpp b/src/sksl/SkSLMain.cpp
index d9fc81470e..3658992412 100644
--- a/src/sksl/SkSLMain.cpp
+++ b/src/sksl/SkSLMain.cpp
@@ -10,6 +10,13 @@
#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.
*/
@@ -30,36 +37,35 @@ int main(int argc, const char** argv) {
}
std::ifstream in(argv[1]);
- std::string stdText((std::istreambuf_iterator<char>(in)),
- std::istreambuf_iterator<char>());
- SkString text(stdText.c_str());
+ std::string text((std::istreambuf_iterator<char>(in)),
+ std::istreambuf_iterator<char>());
if (in.rdstate()) {
printf("error reading '%s'\n", argv[1]);
exit(2);
}
- SkString name(argv[2]);
- if (name.endsWith(".spirv")) {
- SkFILEWStream out(argv[2]);
+ std::string name(argv[2]);
+ if (endsWith(name, ".spirv")) {
+ std::ofstream out(argv[2], std::ofstream::binary);
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);
}
- } else if (name.endsWith(".glsl")) {
- SkFILEWStream out(argv[2]);
- SkSL::Compiler compiler;
- if (!out.isValid()) {
+ if (out.rdstate()) {
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 03d0d337a8..2be664dbd8 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, SkString("exceeded max parse depth"));
+ fParser->error(fParser->peek().fPosition, "exceeded max parse depth");
return false;
}
return true;
@@ -98,8 +98,8 @@ private:
Parser* fParser;
};
-Parser::Parser(SkString text, SymbolTable& types, ErrorReporter& errors)
-: fPushback(Position(-1, -1), Token::INVALID_TOKEN, SkString())
+Parser::Parser(std::string text, SymbolTable& types, ErrorReporter& errors)
+: fPushback(Position(-1, -1), Token::INVALID_TOKEN, "")
, fTypes(types)
, fErrors(errors) {
sksllex_init(&fScanner);
@@ -157,13 +157,13 @@ Token Parser::nextToken() {
return result;
}
int token = sksllex(fScanner);
- SkString text;
+ std::string 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 = SkString(skslget_text(fScanner));
+ text = std::string(skslget_text(fScanner));
break;
default:
break;
@@ -181,12 +181,7 @@ Token Parser::peek() {
return fPushback;
}
-
-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) {
+bool Parser::expect(Token::Kind kind, std::string expected, Token* result) {
Token next = this->nextToken();
if (next.fKind == kind) {
if (result) {
@@ -199,15 +194,11 @@ bool Parser::expect(Token::Kind kind, SkString expected, Token* result) {
}
}
-void Parser::error(Position p, const char* msg) {
- this->error(p, SkString(msg));
-}
-
-void Parser::error(Position p, SkString msg) {
+void Parser::error(Position p, std::string msg) {
fErrors.error(p, msg);
}
-bool Parser::isType(SkString name) {
+bool Parser::isType(std::string name) {
return nullptr != fTypes[name];
}
@@ -379,7 +370,7 @@ std::unique_ptr<ASTType> Parser::structDeclaration() {
return nullptr;
}
uint64_t columns = ((ASTIntLiteral&) *var.fSizes[i]).fValue;
- SkString name = type->name() + "[" + to_string(columns) + "]";
+ std::string name = type->name() + "[" + to_string(columns) + "]";
type = new Type(name, Type::kArray_Kind, *type, (int) columns);
fTypes.takeOwnership((Type*) type);
}
@@ -426,7 +417,7 @@ std::unique_ptr<ASTVarDeclarations> Parser::structVarDeclaration(ASTModifiers mo
(LBRACKET expression? RBRACKET)* (EQ expression)?)* SEMICOLON */
std::unique_ptr<ASTVarDeclarations> Parser::varDeclarationEnd(ASTModifiers mods,
std::unique_ptr<ASTType> type,
- SkString name) {
+ std::string name) {
std::vector<ASTVarDeclaration> vars;
std::vector<std::unique_ptr<ASTExpression>> currentVarSizes;
while (this->peek().fKind == Token::LBRACKET) {
@@ -740,7 +731,7 @@ std::unique_ptr<ASTDeclaration> Parser::interfaceBlock(ASTModifiers mods) {
decls.push_back(std::move(decl));
}
this->nextToken();
- SkString valueName;
+ std::string valueName;
if (this->peek().fKind == Token::IDENTIFIER) {
valueName = this->nextToken().fText;
}
@@ -1370,7 +1361,7 @@ std::unique_ptr<ASTSuffix> Parser::suffix() {
}
case Token::DOT: {
Position pos = this->peek().fPosition;
- SkString text;
+ std::string text;
if (this->identifier(&text)) {
return std::unique_ptr<ASTSuffix>(new ASTFieldSuffix(pos, std::move(text)));
}
@@ -1415,7 +1406,7 @@ std::unique_ptr<ASTExpression> Parser::term() {
Token t = this->peek();
switch (t.fKind) {
case Token::IDENTIFIER: {
- SkString text;
+ std::string text;
if (this->identifier(&text)) {
result.reset(new ASTIdentifier(t.fPosition, std::move(text)));
}
@@ -1496,7 +1487,7 @@ bool Parser::boolLiteral(bool* dest) {
}
/* IDENTIFIER */
-bool Parser::identifier(SkString* dest) {
+bool Parser::identifier(std::string* 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 f2b6fb87bb..f9dcde244f 100644
--- a/src/sksl/SkSLParser.h
+++ b/src/sksl/SkSLParser.h
@@ -8,6 +8,7 @@
#ifndef SKSL_PARSER
#define SKSL_PARSER
+#include <string>
#include <vector>
#include <memory>
#include <unordered_set>
@@ -48,7 +49,7 @@ class SymbolTable;
*/
class Parser {
public:
- Parser(SkString text, SymbolTable& types, ErrorReporter& errors);
+ Parser(std::string text, SymbolTable& types, ErrorReporter& errors);
~Parser();
@@ -86,17 +87,15 @@ 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, const char* expected, Token* result = nullptr);
- bool expect(Token::Kind kind, SkString expected, Token* result = nullptr);
+ bool expect(Token::Kind kind, std::string expected, Token* result = nullptr);
- void error(Position p, const char* msg);
- void error(Position p, SkString msg);
+ void error(Position p, std::string msg);
/**
* Returns true if the 'name' identifier refers to a type name. For instance, isType("int") will
* always return true.
*/
- bool isType(SkString name);
+ bool isType(std::string 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
@@ -116,7 +115,7 @@ private:
std::unique_ptr<ASTVarDeclarations> varDeclarationEnd(ASTModifiers modifiers,
std::unique_ptr<ASTType> type,
- SkString name);
+ std::string name);
std::unique_ptr<ASTParameter> parameter();
@@ -196,7 +195,7 @@ private:
bool boolLiteral(bool* dest);
- bool identifier(SkString* dest);
+ bool identifier(std::string* dest);
void* fScanner;
YY_BUFFER_STATE fBuffer;
diff --git a/src/sksl/SkSLPosition.h b/src/sksl/SkSLPosition.h
index b1841c5a59..979f630ae7 100644
--- a/src/sksl/SkSLPosition.h
+++ b/src/sksl/SkSLPosition.h
@@ -25,7 +25,7 @@ struct Position {
: fLine(line)
, fColumn(column) {}
- SkString description() const {
+ std::string description() const {
return to_string(fLine);
}
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp
index b5cd54abae..a491968674 100644
--- a/src/sksl/SkSLSPIRVCodeGenerator.cpp
+++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp
@@ -34,112 +34,107 @@ void SPIRVCodeGenerator::setupIntrinsics() {
#define SPECIAL(x) std::make_tuple(kSpecial_IntrinsicKind, k ## x ## _SpecialIntrinsic, \
k ## x ## _SpecialIntrinsic, k ## x ## _SpecialIntrinsic, \
k ## x ## _SpecialIntrinsic)
- 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)
+ 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)
PACK(Snorm4x8);
PACK(Unorm4x8);
PACK(Snorm2x16);
PACK(Unorm2x16);
PACK(Half2x16);
PACK(Double2x32);
- 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);
+ 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);
// interpolateAt* not yet supported...
}
-void SPIRVCodeGenerator::writeWord(int32_t word, SkWStream& out) {
+void SPIRVCodeGenerator::writeWord(int32_t word, std::ostream& out) {
#if SPIRV_DEBUG
out << "(" << word << ") ";
#else
@@ -180,603 +175,603 @@ static bool is_out(const Variable& var) {
}
#if SPIRV_DEBUG
-static SkString opcode_text(SpvOp_ opCode) {
+static std::string opcode_text(SpvOp_ opCode) {
switch (opCode) {
case SpvOpNop:
- return SkString("Nop");
+ return "Nop";
case SpvOpUndef:
- return SkString("Undef");
+ return "Undef";
case SpvOpSourceContinued:
- return SkString("SourceContinued");
+ return "SourceContinued";
case SpvOpSource:
- return SkString("Source");
+ return "Source";
case SpvOpSourceExtension:
- return SkString("SourceExtension");
+ return "SourceExtension";
case SpvOpName:
- return SkString("Name");
+ return "Name";
case SpvOpMemberName:
- return SkString("MemberName");
+ return "MemberName";
case SpvOpString:
- return SkString("String");
+ return "String";
case SpvOpLine:
- return SkString("Line");
+ return "Line";
case SpvOpExtension:
- return SkString("Extension");
+ return "Extension";
case SpvOpExtInstImport:
- return SkString("ExtInstImport");
+ return "ExtInstImport";
case SpvOpExtInst:
- return SkString("ExtInst");
+ return "ExtInst";
case SpvOpMemoryModel:
- return SkString("MemoryModel");
+ return "MemoryModel";
case SpvOpEntryPoint:
- return SkString("EntryPoint");
+ return "EntryPoint";
case SpvOpExecutionMode:
- return SkString("ExecutionMode");
+ return "ExecutionMode";
case SpvOpCapability:
- return SkString("Capability");
+ return "Capability";
case SpvOpTypeVoid:
- return SkString("TypeVoid");
+ return "TypeVoid";
case SpvOpTypeBool:
- return SkString("TypeBool");
+ return "TypeBool";
case SpvOpTypeInt:
- return SkString("TypeInt");
+ return "TypeInt";
case SpvOpTypeFloat:
- return SkString("TypeFloat");
+ return "TypeFloat";
case SpvOpTypeVector:
- return SkString("TypeVector");
+ return "TypeVector";
case SpvOpTypeMatrix:
- return SkString("TypeMatrix");
+ return "TypeMatrix";
case SpvOpTypeImage:
- return SkString("TypeImage");
+ return "TypeImage";
case SpvOpTypeSampler:
- return SkString("TypeSampler");
+ return "TypeSampler";
case SpvOpTypeSampledImage:
- return SkString("TypeSampledImage");
+ return "TypeSampledImage";
case SpvOpTypeArray:
- return SkString("TypeArray");
+ return "TypeArray";
case SpvOpTypeRuntimeArray:
- return SkString("TypeRuntimeArray");
+ return "TypeRuntimeArray";
case SpvOpTypeStruct:
- return SkString("TypeStruct");
+ return "TypeStruct";
case SpvOpTypeOpaque:
- return SkString("TypeOpaque");
+ return "TypeOpaque";
case SpvOpTypePointer:
- return SkString("TypePointer");
+ return "TypePointer";
case SpvOpTypeFunction:
- return SkString("TypeFunction");
+ return "TypeFunction";
case SpvOpTypeEvent:
- return SkString("TypeEvent");
+ return "TypeEvent";
case SpvOpTypeDeviceEvent:
- return SkString("TypeDeviceEvent");
+ return "TypeDeviceEvent";
case SpvOpTypeReserveId:
- return SkString("TypeReserveId");
+ return "TypeReserveId";
case SpvOpTypeQueue:
- return SkString("TypeQueue");
+ return "TypeQueue";
case SpvOpTypePipe:
- return SkString("TypePipe");
+ return "TypePipe";
case SpvOpTypeForwardPointer:
- return SkString("TypeForwardPointer");
+ return "TypeForwardPointer";
case SpvOpConstantTrue:
- return SkString("ConstantTrue");
+ return "ConstantTrue";
case SpvOpConstantFalse:
- return SkString("ConstantFalse");
+ return "ConstantFalse";
case SpvOpConstant:
- return SkString("Constant");
+ return "Constant";
case SpvOpConstantComposite:
- return SkString("ConstantComposite");
+ return "ConstantComposite";
case SpvOpConstantSampler:
- return SkString("ConstantSampler");
+ return "ConstantSampler";
case SpvOpConstantNull:
- return SkString("ConstantNull");
+ return "ConstantNull";
case SpvOpSpecConstantTrue:
- return SkString("SpecConstantTrue");
+ return "SpecConstantTrue";
case SpvOpSpecConstantFalse:
- return SkString("SpecConstantFalse");
+ return "SpecConstantFalse";
case SpvOpSpecConstant:
- return SkString("SpecConstant");
+ return "SpecConstant";
case SpvOpSpecConstantComposite:
- return SkString("SpecConstantComposite");
+ return "SpecConstantComposite";
case SpvOpSpecConstantOp:
- return SkString("SpecConstantOp");
+ return "SpecConstantOp";
case SpvOpFunction:
- return SkString("Function");
+ return "Function";
case SpvOpFunctionParameter:
- return SkString("FunctionParameter");
+ return "FunctionParameter";
case SpvOpFunctionEnd:
- return SkString("FunctionEnd");
+ return "FunctionEnd";
case SpvOpFunctionCall:
- return SkString("FunctionCall");
+ return "FunctionCall";
case SpvOpVariable:
- return SkString("Variable");
+ return "Variable";
case SpvOpImageTexelPointer:
- return SkString("ImageTexelPointer");
+ return "ImageTexelPointer";
case SpvOpLoad:
- return SkString("Load");
+ return "Load";
case SpvOpStore:
- return SkString("Store");
+ return "Store";
case SpvOpCopyMemory:
- return SkString("CopyMemory");
+ return "CopyMemory";
case SpvOpCopyMemorySized:
- return SkString("CopyMemorySized");
+ return "CopyMemorySized";
case SpvOpAccessChain:
- return SkString("AccessChain");
+ return "AccessChain";
case SpvOpInBoundsAccessChain:
- return SkString("InBoundsAccessChain");
+ return "InBoundsAccessChain";
case SpvOpPtrAccessChain:
- return SkString("PtrAccessChain");
+ return "PtrAccessChain";
case SpvOpArrayLength:
- return SkString("ArrayLength");
+ return "ArrayLength";
case SpvOpGenericPtrMemSemantics:
- return SkString("GenericPtrMemSemantics");
+ return "GenericPtrMemSemantics";
case SpvOpInBoundsPtrAccessChain:
- return SkString("InBoundsPtrAccessChain");
+ return "InBoundsPtrAccessChain";
case SpvOpDecorate:
- return SkString("Decorate");
+ return "Decorate";
case SpvOpMemberDecorate:
- return SkString("MemberDecorate");
+ return "MemberDecorate";
case SpvOpDecorationGroup:
- return SkString("DecorationGroup");
+ return "DecorationGroup";
case SpvOpGroupDecorate:
- return SkString("GroupDecorate");
+ return "GroupDecorate";
case SpvOpGroupMemberDecorate:
- return SkString("GroupMemberDecorate");
+ return "GroupMemberDecorate";
case SpvOpVectorExtractDynamic:
- return SkString("VectorExtractDynamic");
+ return "VectorExtractDynamic";
case SpvOpVectorInsertDynamic:
- return SkString("VectorInsertDynamic");
+ return "VectorInsertDynamic";
case SpvOpVectorShuffle:
- return SkString("VectorShuffle");
+ return "VectorShuffle";
case SpvOpCompositeConstruct:
- return SkString("CompositeConstruct");
+ return "CompositeConstruct";
case SpvOpCompositeExtract:
- return SkString("CompositeExtract");
+ return "CompositeExtract";
case SpvOpCompositeInsert:
- return SkString("CompositeInsert");
+ return "CompositeInsert";
case SpvOpCopyObject:
- return SkString("CopyObject");
+ return "CopyObject";
case SpvOpTranspose:
- return SkString("Transpose");
+ return "Transpose";
case SpvOpSampledImage:
- return SkString("SampledImage");
+ return "SampledImage";
case SpvOpImageSampleImplicitLod:
- return SkString("ImageSampleImplicitLod");
+ return "ImageSampleImplicitLod";
case SpvOpImageSampleExplicitLod:
- return SkString("ImageSampleExplicitLod");
+ return "ImageSampleExplicitLod";
case SpvOpImageSampleDrefImplicitLod:
- return SkString("ImageSampleDrefImplicitLod");
+ return "ImageSampleDrefImplicitLod";
case SpvOpImageSampleDrefExplicitLod:
- return SkString("ImageSampleDrefExplicitLod");
+ return "ImageSampleDrefExplicitLod";
case SpvOpImageSampleProjImplicitLod:
- return SkString("ImageSampleProjImplicitLod");
+ return "ImageSampleProjImplicitLod";
case SpvOpImageSampleProjExplicitLod:
- return SkString("ImageSampleProjExplicitLod");
+ return "ImageSampleProjExplicitLod";
case SpvOpImageSampleProjDrefImplicitLod:
- return SkString("ImageSampleProjDrefImplicitLod");
+ return "ImageSampleProjDrefImplicitLod";
case SpvOpImageSampleProjDrefExplicitLod:
- return SkString("ImageSampleProjDrefExplicitLod");
+ return "ImageSampleProjDrefExplicitLod";
case SpvOpImageFetch:
- return SkString("ImageFetch");
+ return "ImageFetch";
case SpvOpImageGather:
- return SkString("ImageGather");
+ return "ImageGather";
case SpvOpImageDrefGather:
- return SkString("ImageDrefGather");
+ return "ImageDrefGather";
case SpvOpImageRead:
- return SkString("ImageRead");
+ return "ImageRead";
case SpvOpImageWrite:
- return SkString("ImageWrite");
+ return "ImageWrite";
case SpvOpImage:
- return SkString("Image");
+ return "Image";
case SpvOpImageQueryFormat:
- return SkString("ImageQueryFormat");
+ return "ImageQueryFormat";
case SpvOpImageQueryOrder:
- return SkString("ImageQueryOrder");
+ return "ImageQueryOrder";
case SpvOpImageQuerySizeLod:
- return SkString("ImageQuerySizeLod");
+ return "ImageQuerySizeLod";
case SpvOpImageQuerySize:
- return SkString("ImageQuerySize");
+ return "ImageQuerySize";
case SpvOpImageQueryLod:
- return SkString("ImageQueryLod");
+ return "ImageQueryLod";
case SpvOpImageQueryLevels:
- return SkString("ImageQueryLevels");
+ return "ImageQueryLevels";
case SpvOpImageQuerySamples:
- return SkString("ImageQuerySamples");
+ return "ImageQuerySamples";
case SpvOpConvertFToU:
- return SkString("ConvertFToU");
+ return "ConvertFToU";
case SpvOpConvertFToS:
- return SkString("ConvertFToS");
+ return "ConvertFToS";
case SpvOpConvertSToF:
- return SkString("ConvertSToF");
+ return "ConvertSToF";
case SpvOpConvertUToF:
- return SkString("ConvertUToF");
+ return "ConvertUToF";
case SpvOpUConvert:
- return SkString("UConvert");
+ return "UConvert";
case SpvOpSConvert:
- return SkString("SConvert");
+ return "SConvert";
case SpvOpFConvert:
- return SkString("FConvert");
+ return "FConvert";
case SpvOpQuantizeToF16:
- return SkString("QuantizeToF16");
+ return "QuantizeToF16";
case SpvOpConvertPtrToU:
- return SkString("ConvertPtrToU");
+ return "ConvertPtrToU";
case SpvOpSatConvertSToU:
- return SkString("SatConvertSToU");
+ return "SatConvertSToU";
case SpvOpSatConvertUToS:
- return SkString("SatConvertUToS");
+ return "SatConvertUToS";
case SpvOpConvertUToPtr:
- return SkString("ConvertUToPtr");
+ return "ConvertUToPtr";
case SpvOpPtrCastToGeneric:
- return SkString("PtrCastToGeneric");
+ return "PtrCastToGeneric";
case SpvOpGenericCastToPtr:
- return SkString("GenericCastToPtr");
+ return "GenericCastToPtr";
case SpvOpGenericCastToPtrExplicit:
- return SkString("GenericCastToPtrExplicit");
+ return "GenericCastToPtrExplicit";
case SpvOpBitcast:
- return SkString("Bitcast");
+ return "Bitcast";
case SpvOpSNegate:
- return SkString("SNegate");
+ return "SNegate";
case SpvOpFNegate:
- return SkString("FNegate");
+ return "FNegate";
case SpvOpIAdd:
- return SkString("IAdd");
+ return "IAdd";
case SpvOpFAdd:
- return SkString("FAdd");
+ return "FAdd";
case SpvOpISub:
- return SkString("ISub");
+ return "ISub";
case SpvOpFSub:
- return SkString("FSub");
+ return "FSub";
case SpvOpIMul:
- return SkString("IMul");
+ return "IMul";
case SpvOpFMul:
- return SkString("FMul");
+ return "FMul";
case SpvOpUDiv:
- return SkString("UDiv");
+ return "UDiv";
case SpvOpSDiv:
- return SkString("SDiv");
+ return "SDiv";
case SpvOpFDiv:
- return SkString("FDiv");
+ return "FDiv";
case SpvOpUMod:
- return SkString("UMod");
+ return "UMod";
case SpvOpSRem:
- return SkString("SRem");
+ return "SRem";
case SpvOpSMod:
- return SkString("SMod");
+ return "SMod";
case SpvOpFRem:
- return SkString("FRem");
+ return "FRem";
case SpvOpFMod:
- return SkString("FMod");
+ return "FMod";
case SpvOpVectorTimesScalar:
- return SkString("VectorTimesScalar");
+ return "VectorTimesScalar";
case SpvOpMatrixTimesScalar:
- return SkString("MatrixTimesScalar");
+ return "MatrixTimesScalar";
case SpvOpVectorTimesMatrix:
- return SkString("VectorTimesMatrix");
+ return "VectorTimesMatrix";
case SpvOpMatrixTimesVector:
- return SkString("MatrixTimesVector");
+ return "MatrixTimesVector";
case SpvOpMatrixTimesMatrix:
- return SkString("MatrixTimesMatrix");
+ return "MatrixTimesMatrix";
case SpvOpOuterProduct:
- return SkString("OuterProduct");
+ return "OuterProduct";
case SpvOpDot:
- return SkString("Dot");
+ return "Dot";
case SpvOpIAddCarry:
- return SkString("IAddCarry");
+ return "IAddCarry";
case SpvOpISubBorrow:
- return SkString("ISubBorrow");
+ return "ISubBorrow";
case SpvOpUMulExtended:
- return SkString("UMulExtended");
+ return "UMulExtended";
case SpvOpSMulExtended:
- return SkString("SMulExtended");
+ return "SMulExtended";
case SpvOpAny:
- return SkString("Any");
+ return "Any";
case SpvOpAll:
- return SkString("All");
+ return "All";
case SpvOpIsNan:
- return SkString("IsNan");
+ return "IsNan";
case SpvOpIsInf:
- return SkString("IsInf");
+ return "IsInf";
case SpvOpIsFinite:
- return SkString("IsFinite");
+ return "IsFinite";
case SpvOpIsNormal:
- return SkString("IsNormal");
+ return "IsNormal";
case SpvOpSignBitSet:
- return SkString("SignBitSet");
+ return "SignBitSet";
case SpvOpLessOrGreater:
- return SkString("LessOrGreater");
+ return "LessOrGreater";
case SpvOpOrdered:
- return SkString("Ordered");
+ return "Ordered";
case SpvOpUnordered:
- return SkString("Unordered");
+ return "Unordered";
case SpvOpLogicalEqual:
- return SkString("LogicalEqual");
+ return "LogicalEqual";
case SpvOpLogicalNotEqual:
- return SkString("LogicalNotEqual");
+ return "LogicalNotEqual";
case SpvOpLogicalOr:
- return SkString("LogicalOr");
+ return "LogicalOr";
case SpvOpLogicalAnd:
- return SkString("LogicalAnd");
+ return "LogicalAnd";
case SpvOpLogicalNot:
- return SkString("LogicalNot");
+ return "LogicalNot";
case SpvOpSelect:
- return SkString("Select");
+ return "Select";
case SpvOpIEqual:
- return SkString("IEqual");
+ return "IEqual";
case SpvOpINotEqual:
- return SkString("INotEqual");
+ return "INotEqual";
case SpvOpUGreaterThan:
- return SkString("UGreaterThan");
+ return "UGreaterThan";
case SpvOpSGreaterThan:
- return SkString("SGreaterThan");
+ return "SGreaterThan";
case SpvOpUGreaterThanEqual:
- return SkString("UGreaterThanEqual");
+ return "UGreaterThanEqual";
case SpvOpSGreaterThanEqual:
- return SkString("SGreaterThanEqual");
+ return "SGreaterThanEqual";
case SpvOpULessThan:
- return SkString("ULessThan");
+ return "ULessThan";
case SpvOpSLessThan:
- return SkString("SLessThan");
+ return "SLessThan";
case SpvOpULessThanEqual:
- return SkString("ULessThanEqual");
+ return "ULessThanEqual";
case SpvOpSLessThanEqual:
- return SkString("SLessThanEqual");
+ return "SLessThanEqual";
case SpvOpFOrdEqual:
- return SkString("FOrdEqual");
+ return "FOrdEqual";
case SpvOpFUnordEqual:
- return SkString("FUnordEqual");
+ return "FUnordEqual";
case SpvOpFOrdNotEqual:
- return SkString("FOrdNotEqual");
+ return "FOrdNotEqual";
case SpvOpFUnordNotEqual:
- return SkString("FUnordNotEqual");
+ return "FUnordNotEqual";
case SpvOpFOrdLessThan:
- return SkString("FOrdLessThan");
+ return "FOrdLessThan";
case SpvOpFUnordLessThan:
- return SkString("FUnordLessThan");
+ return "FUnordLessThan";
case SpvOpFOrdGreaterThan:
- return SkString("FOrdGreaterThan");
+ return "FOrdGreaterThan";
case SpvOpFUnordGreaterThan:
- return SkString("FUnordGreaterThan");
+ return "FUnordGreaterThan";
case SpvOpFOrdLessThanEqual:
- return SkString("FOrdLessThanEqual");
+ return "FOrdLessThanEqual";
case SpvOpFUnordLessThanEqual:
- return SkString("FUnordLessThanEqual");
+ return "FUnordLessThanEqual";
case SpvOpFOrdGreaterThanEqual:
- return SkString("FOrdGreaterThanEqual");
+ return "FOrdGreaterThanEqual";
case SpvOpFUnordGreaterThanEqual:
- return SkString("FUnordGreaterThanEqual");
+ return "FUnordGreaterThanEqual";
case SpvOpShiftRightLogical:
- return SkString("ShiftRightLogical");
+ return "ShiftRightLogical";
case SpvOpShiftRightArithmetic:
- return SkString("ShiftRightArithmetic");
+ return "ShiftRightArithmetic";
case SpvOpShiftLeftLogical:
- return SkString("ShiftLeftLogical");
+ return "ShiftLeftLogical";
case SpvOpBitwiseOr:
- return SkString("BitwiseOr");
+ return "BitwiseOr";
case SpvOpBitwiseXor:
- return SkString("BitwiseXor");
+ return "BitwiseXor";
case SpvOpBitwiseAnd:
- return SkString("BitwiseAnd");
+ return "BitwiseAnd";
case SpvOpNot:
- return SkString("Not");
+ return "Not";
case SpvOpBitFieldInsert:
- return SkString("BitFieldInsert");
+ return "BitFieldInsert";
case SpvOpBitFieldSExtract:
- return SkString("BitFieldSExtract");
+ return "BitFieldSExtract";
case SpvOpBitFieldUExtract:
- return SkString("BitFieldUExtract");
+ return "BitFieldUExtract";
case SpvOpBitReverse:
- return SkString("BitReverse");
+ return "BitReverse";
case SpvOpBitCount:
- return SkString("BitCount");
+ return "BitCount";
case SpvOpDPdx:
- return SkString("DPdx");
+ return "DPdx";
case SpvOpDPdy:
- return SkString("DPdy");
+ return "DPdy";
case SpvOpFwidth:
- return SkString("Fwidth");
+ return "Fwidth";
case SpvOpDPdxFine:
- return SkString("DPdxFine");
+ return "DPdxFine";
case SpvOpDPdyFine:
- return SkString("DPdyFine");
+ return "DPdyFine";
case SpvOpFwidthFine:
- return SkString("FwidthFine");
+ return "FwidthFine";
case SpvOpDPdxCoarse:
- return SkString("DPdxCoarse");
+ return "DPdxCoarse";
case SpvOpDPdyCoarse:
- return SkString("DPdyCoarse");
+ return "DPdyCoarse";
case SpvOpFwidthCoarse:
- return SkString("FwidthCoarse");
+ return "FwidthCoarse";
case SpvOpEmitVertex:
- return SkString("EmitVertex");
+ return "EmitVertex";
case SpvOpEndPrimitive:
- return SkString("EndPrimitive");
+ return "EndPrimitive";
case SpvOpEmitStreamVertex:
- return SkString("EmitStreamVertex");
+ return "EmitStreamVertex";
case SpvOpEndStreamPrimitive:
- return SkString("EndStreamPrimitive");
+ return "EndStreamPrimitive";
case SpvOpControlBarrier:
- return SkString("ControlBarrier");
+ return "ControlBarrier";
case SpvOpMemoryBarrier:
- return SkString("MemoryBarrier");
+ return "MemoryBarrier";
case SpvOpAtomicLoad:
- return SkString("AtomicLoad");
+ return "AtomicLoad";
case SpvOpAtomicStore:
- return SkString("AtomicStore");
+ return "AtomicStore";
case SpvOpAtomicExchange:
- return SkString("AtomicExchange");
+ return "AtomicExchange";
case SpvOpAtomicCompareExchange:
- return SkString("AtomicCompareExchange");
+ return "AtomicCompareExchange";
case SpvOpAtomicCompareExchangeWeak:
- return SkString("AtomicCompareExchangeWeak");
+ return "AtomicCompareExchangeWeak";
case SpvOpAtomicIIncrement:
- return SkString("AtomicIIncrement");
+ return "AtomicIIncrement";
case SpvOpAtomicIDecrement:
- return SkString("AtomicIDecrement");
+ return "AtomicIDecrement";
case SpvOpAtomicIAdd:
- return SkString("AtomicIAdd");
+ return "AtomicIAdd";
case SpvOpAtomicISub:
- return SkString("AtomicISub");
+ return "AtomicISub";
case SpvOpAtomicSMin:
- return SkString("AtomicSMin");
+ return "AtomicSMin";
case SpvOpAtomicUMin:
- return SkString("AtomicUMin");
+ return "AtomicUMin";
case SpvOpAtomicSMax:
- return SkString("AtomicSMax");
+ return "AtomicSMax";
case SpvOpAtomicUMax:
- return SkString("AtomicUMax");
+ return "AtomicUMax";
case SpvOpAtomicAnd:
- return SkString("AtomicAnd");
+ return "AtomicAnd";
case SpvOpAtomicOr:
- return SkString("AtomicOr");
+ return "AtomicOr";
case SpvOpAtomicXor:
- return SkString("AtomicXor");
+ return "AtomicXor";
case SpvOpPhi:
- return SkString("Phi");
+ return "Phi";
case SpvOpLoopMerge:
- return SkString("LoopMerge");
+ return "LoopMerge";
case SpvOpSelectionMerge:
- return SkString("SelectionMerge");
+ return "SelectionMerge";
case SpvOpLabel:
- return SkString("Label");
+ return "Label";
case SpvOpBranch:
- return SkString("Branch");
+ return "Branch";
case SpvOpBranchConditional:
- return SkString("BranchConditional");
+ return "BranchConditional";
case SpvOpSwitch:
- return SkString("Switch");
+ return "Switch";
case SpvOpKill:
- return SkString("Kill");
+ return "Kill";
case SpvOpReturn:
- return SkString("Return");
+ return "Return";
case SpvOpReturnValue:
- return SkString("ReturnValue");
+ return "ReturnValue";
case SpvOpUnreachable:
- return SkString("Unreachable");
+ return "Unreachable";
case SpvOpLifetimeStart:
- return SkString("LifetimeStart");
+ return "LifetimeStart";
case SpvOpLifetimeStop:
- return SkString("LifetimeStop");
+ return "LifetimeStop";
case SpvOpGroupAsyncCopy:
- return SkString("GroupAsyncCopy");
+ return "GroupAsyncCopy";
case SpvOpGroupWaitEvents:
- return SkString("GroupWaitEvents");
+ return "GroupWaitEvents";
case SpvOpGroupAll:
- return SkString("GroupAll");
+ return "GroupAll";
case SpvOpGroupAny:
- return SkString("GroupAny");
+ return "GroupAny";
case SpvOpGroupBroadcast:
- return SkString("GroupBroadcast");
+ return "GroupBroadcast";
case SpvOpGroupIAdd:
- return SkString("GroupIAdd");
+ return "GroupIAdd";
case SpvOpGroupFAdd:
- return SkString("GroupFAdd");
+ return "GroupFAdd";
case SpvOpGroupFMin:
- return SkString("GroupFMin");
+ return "GroupFMin";
case SpvOpGroupUMin:
- return SkString("GroupUMin");
+ return "GroupUMin";
case SpvOpGroupSMin:
- return SkString("GroupSMin");
+ return "GroupSMin";
case SpvOpGroupFMax:
- return SkString("GroupFMax");
+ return "GroupFMax";
case SpvOpGroupUMax:
- return SkString("GroupUMax");
+ return "GroupUMax";
case SpvOpGroupSMax:
- return SkString("GroupSMax");
+ return "GroupSMax";
case SpvOpReadPipe:
- return SkString("ReadPipe");
+ return "ReadPipe";
case SpvOpWritePipe:
- return SkString("WritePipe");
+ return "WritePipe";
case SpvOpReservedReadPipe:
- return SkString("ReservedReadPipe");
+ return "ReservedReadPipe";
case SpvOpReservedWritePipe:
- return SkString("ReservedWritePipe");
+ return "ReservedWritePipe";
case SpvOpReserveReadPipePackets:
- return SkString("ReserveReadPipePackets");
+ return "ReserveReadPipePackets";
case SpvOpReserveWritePipePackets:
- return SkString("ReserveWritePipePackets");
+ return "ReserveWritePipePackets";
case SpvOpCommitReadPipe:
- return SkString("CommitReadPipe");
+ return "CommitReadPipe";
case SpvOpCommitWritePipe:
- return SkString("CommitWritePipe");
+ return "CommitWritePipe";
case SpvOpIsValidReserveId:
- return SkString("IsValidReserveId");
+ return "IsValidReserveId";
case SpvOpGetNumPipePackets:
- return SkString("GetNumPipePackets");
+ return "GetNumPipePackets";
case SpvOpGetMaxPipePackets:
- return SkString("GetMaxPipePackets");
+ return "GetMaxPipePackets";
case SpvOpGroupReserveReadPipePackets:
- return SkString("GroupReserveReadPipePackets");
+ return "GroupReserveReadPipePackets";
case SpvOpGroupReserveWritePipePackets:
- return SkString("GroupReserveWritePipePackets");
+ return "GroupReserveWritePipePackets";
case SpvOpGroupCommitReadPipe:
- return SkString("GroupCommitReadPipe");
+ return "GroupCommitReadPipe";
case SpvOpGroupCommitWritePipe:
- return SkString("GroupCommitWritePipe");
+ return "GroupCommitWritePipe";
case SpvOpEnqueueMarker:
- return SkString("EnqueueMarker");
+ return "EnqueueMarker";
case SpvOpEnqueueKernel:
- return SkString("EnqueueKernel");
+ return "EnqueueKernel";
case SpvOpGetKernelNDrangeSubGroupCount:
- return SkString("GetKernelNDrangeSubGroupCount");
+ return "GetKernelNDrangeSubGroupCount";
case SpvOpGetKernelNDrangeMaxSubGroupSize:
- return SkString("GetKernelNDrangeMaxSubGroupSize");
+ return "GetKernelNDrangeMaxSubGroupSize";
case SpvOpGetKernelWorkGroupSize:
- return SkString("GetKernelWorkGroupSize");
+ return "GetKernelWorkGroupSize";
case SpvOpGetKernelPreferredWorkGroupSizeMultiple:
- return SkString("GetKernelPreferredWorkGroupSizeMultiple");
+ return "GetKernelPreferredWorkGroupSizeMultiple";
case SpvOpRetainEvent:
- return SkString("RetainEvent");
+ return "RetainEvent";
case SpvOpReleaseEvent:
- return SkString("ReleaseEvent");
+ return "ReleaseEvent";
case SpvOpCreateUserEvent:
- return SkString("CreateUserEvent");
+ return "CreateUserEvent";
case SpvOpIsValidEvent:
- return SkString("IsValidEvent");
+ return "IsValidEvent";
case SpvOpSetUserEventStatus:
- return SkString("SetUserEventStatus");
+ return "SetUserEventStatus";
case SpvOpCaptureEventProfilingInfo:
- return SkString("CaptureEventProfilingInfo");
+ return "CaptureEventProfilingInfo";
case SpvOpGetDefaultQueue:
- return SkString("GetDefaultQueue");
+ return "GetDefaultQueue";
case SpvOpBuildNDRange:
- return SkString("BuildNDRange");
+ return "BuildNDRange";
case SpvOpImageSparseSampleImplicitLod:
- return SkString("ImageSparseSampleImplicitLod");
+ return "ImageSparseSampleImplicitLod";
case SpvOpImageSparseSampleExplicitLod:
- return SkString("ImageSparseSampleExplicitLod");
+ return "ImageSparseSampleExplicitLod";
case SpvOpImageSparseSampleDrefImplicitLod:
- return SkString("ImageSparseSampleDrefImplicitLod");
+ return "ImageSparseSampleDrefImplicitLod";
case SpvOpImageSparseSampleDrefExplicitLod:
- return SkString("ImageSparseSampleDrefExplicitLod");
+ return "ImageSparseSampleDrefExplicitLod";
case SpvOpImageSparseSampleProjImplicitLod:
- return SkString("ImageSparseSampleProjImplicitLod");
+ return "ImageSparseSampleProjImplicitLod";
case SpvOpImageSparseSampleProjExplicitLod:
- return SkString("ImageSparseSampleProjExplicitLod");
+ return "ImageSparseSampleProjExplicitLod";
case SpvOpImageSparseSampleProjDrefImplicitLod:
- return SkString("ImageSparseSampleProjDrefImplicitLod");
+ return "ImageSparseSampleProjDrefImplicitLod";
case SpvOpImageSparseSampleProjDrefExplicitLod:
- return SkString("ImageSparseSampleProjDrefExplicitLod");
+ return "ImageSparseSampleProjDrefExplicitLod";
case SpvOpImageSparseFetch:
- return SkString("ImageSparseFetch");
+ return "ImageSparseFetch";
case SpvOpImageSparseGather:
- return SkString("ImageSparseGather");
+ return "ImageSparseGather";
case SpvOpImageSparseDrefGather:
- return SkString("ImageSparseDrefGather");
+ return "ImageSparseDrefGather";
case SpvOpImageSparseTexelsResident:
- return SkString("ImageSparseTexelsResident");
+ return "ImageSparseTexelsResident";
case SpvOpNoLine:
- return SkString("NoLine");
+ return "NoLine";
case SpvOpAtomicFlagTestAndSet:
- return SkString("AtomicFlagTestAndSet");
+ return "AtomicFlagTestAndSet";
case SpvOpAtomicFlagClear:
- return SkString("AtomicFlagClear");
+ return "AtomicFlagClear";
case SpvOpImageSparseRead:
- return SkString("ImageSparseRead");
+ return "ImageSparseRead";
default:
ABORT("unsupported SPIR-V op");
}
}
#endif
-void SPIRVCodeGenerator::writeOpCode(SpvOp_ opCode, int length, SkWStream& out) {
+void SPIRVCodeGenerator::writeOpCode(SpvOp_ opCode, int length, std::ostream& out) {
ASSERT(opCode != SpvOpUndef);
switch (opCode) {
case SpvOpReturn: // fall through
@@ -830,39 +825,39 @@ void SPIRVCodeGenerator::writeOpCode(SpvOp_ opCode, int length, SkWStream& out)
#endif
}
-void SPIRVCodeGenerator::writeLabel(SpvId label, SkWStream& out) {
+void SPIRVCodeGenerator::writeLabel(SpvId label, std::ostream& out) {
fCurrentBlock = label;
this->writeInstruction(SpvOpLabel, label, out);
}
-void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, SkWStream& out) {
+void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, std::ostream& out) {
this->writeOpCode(opCode, 1, out);
}
-void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, SkWStream& out) {
+void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, std::ostream& out) {
this->writeOpCode(opCode, 2, out);
this->writeWord(word1, out);
}
-void SPIRVCodeGenerator::writeString(const char* string, SkWStream& out) {
+void SPIRVCodeGenerator::writeString(const char* string, std::ostream& out) {
size_t length = strlen(string);
- out.writeText(string);
+ out << string;
switch (length % 4) {
case 1:
- out.write8(0);
+ out << (char) 0;
// fall through
case 2:
- out.write8(0);
+ out << (char) 0;
// fall through
case 3:
- out.write8(0);
+ out << (char) 0;
break;
default:
this->writeWord(0, out);
}
}
-void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, const char* string, SkWStream& out) {
+void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, const char* string, std::ostream& out) {
int32_t length = (int32_t) strlen(string);
this->writeOpCode(opCode, 1 + (length + 4) / 4, out);
this->writeString(string, out);
@@ -870,7 +865,7 @@ void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, const char* string, SkW
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, const char* string,
- SkWStream& out) {
+ std::ostream& out) {
int32_t length = (int32_t) strlen(string);
this->writeOpCode(opCode, 2 + (length + 4) / 4, out);
this->writeWord(word1, out);
@@ -878,7 +873,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, SkWStream& out) {
+ const char* string, std::ostream& out) {
int32_t length = (int32_t) strlen(string);
this->writeOpCode(opCode, 3 + (length + 4) / 4, out);
this->writeWord(word1, out);
@@ -887,14 +882,14 @@ void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t
}
void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2,
- SkWStream& out) {
+ std::ostream& 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, SkWStream& out) {
+ int32_t word3, std::ostream& out) {
this->writeOpCode(opCode, 4, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
@@ -902,7 +897,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, SkWStream& out) {
+ int32_t word3, int32_t word4, std::ostream& out) {
this->writeOpCode(opCode, 5, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
@@ -912,7 +907,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,
- SkWStream& out) {
+ std::ostream& out) {
this->writeOpCode(opCode, 6, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
@@ -923,7 +918,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, SkWStream& out) {
+ int32_t word6, std::ostream& out) {
this->writeOpCode(opCode, 7, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
@@ -935,7 +930,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, SkWStream& out) {
+ int32_t word6, int32_t word7, std::ostream& out) {
this->writeOpCode(opCode, 8, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
@@ -949,7 +944,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,
- SkWStream& out) {
+ std::ostream& out) {
this->writeOpCode(opCode, 9, out);
this->writeWord(word1, out);
this->writeWord(word2, out);
@@ -961,7 +956,7 @@ void SPIRVCodeGenerator::writeInstruction(SpvOp_ opCode, int32_t word1, int32_t
this->writeWord(word8, out);
}
-void SPIRVCodeGenerator::writeCapabilities(SkWStream& out) {
+void SPIRVCodeGenerator::writeCapabilities(std::ostream& out) {
for (uint64_t i = 0, bit = 1; i <= kLast_Capability; i++, bit <<= 1) {
if (fCapabilities & bit) {
this->writeInstruction(SpvOpCapability, (SpvId) i, out);
@@ -1012,6 +1007,7 @@ 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);
}
}
@@ -1086,8 +1082,8 @@ SpvId SPIRVCodeGenerator::getType(const Type& type) {
}
SpvId SPIRVCodeGenerator::getFunctionType(const FunctionDeclaration& function) {
- SkString key = function.fReturnType.description() + "(";
- SkString separator;
+ std::string key = function.fReturnType.description() + "(";
+ std::string separator = "";
for (size_t i = 0; i < function.fParameters.size(); i++) {
key += separator;
separator = ", ";
@@ -1144,7 +1140,7 @@ SpvId SPIRVCodeGenerator::getFunctionType(const FunctionDeclaration& function) {
SpvId SPIRVCodeGenerator::getPointerType(const Type& type,
SpvStorageClass_ storageClass) {
- SkString key = type.description() + "*" + to_string(storageClass);
+ std::string key = type.description() + "*" + to_string(storageClass);
auto entry = fTypeMap.find(key);
if (entry == fTypeMap.end()) {
SpvId result = this->nextId();
@@ -1156,7 +1152,7 @@ SpvId SPIRVCodeGenerator::getPointerType(const Type& type,
return entry->second;
}
-SpvId SPIRVCodeGenerator::writeExpression(const Expression& expr, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeExpression(const Expression& expr, std::ostream& out) {
switch (expr.fKind) {
case Expression::kBinary_Kind:
return this->writeBinaryExpression((BinaryExpression&) expr, out);
@@ -1190,7 +1186,7 @@ SpvId SPIRVCodeGenerator::writeExpression(const Expression& expr, SkWStream& out
return -1;
}
-SpvId SPIRVCodeGenerator::writeIntrinsicCall(const FunctionCall& c, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeIntrinsicCall(const FunctionCall& c, std::ostream& out) {
auto intrinsic = fIntrinsicMap.find(c.fFunction.fName);
ASSERT(intrinsic != fIntrinsicMap.end());
const Type& type = c.fArguments[0]->fType;
@@ -1246,7 +1242,7 @@ SpvId SPIRVCodeGenerator::writeIntrinsicCall(const FunctionCall& c, SkWStream& o
}
SpvId SPIRVCodeGenerator::writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind,
- SkWStream& out) {
+ std::ostream& out) {
SpvId result = this->nextId();
switch (kind) {
case kAtan_SpecialIntrinsic: {
@@ -1310,7 +1306,7 @@ SpvId SPIRVCodeGenerator::writeSpecialIntrinsic(const FunctionCall& c, SpecialIn
return result;
}
-SpvId SPIRVCodeGenerator::writeFunctionCall(const FunctionCall& c, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeFunctionCall(const FunctionCall& c, std::ostream& out) {
const auto& entry = fFunctionMap.find(&c.fFunction);
if (entry == fFunctionMap.end()) {
return this->writeIntrinsicCall(c, out);
@@ -1399,7 +1395,7 @@ SpvId SPIRVCodeGenerator::writeConstantVector(const Constructor& c) {
return result;
}
-SpvId SPIRVCodeGenerator::writeFloatConstructor(const Constructor& c, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeFloatConstructor(const Constructor& c, std::ostream& out) {
ASSERT(c.fType == *fContext.fFloat_Type);
ASSERT(c.fArguments.size() == 1);
ASSERT(c.fArguments[0]->fType.isNumber());
@@ -1417,7 +1413,7 @@ SpvId SPIRVCodeGenerator::writeFloatConstructor(const Constructor& c, SkWStream&
return result;
}
-SpvId SPIRVCodeGenerator::writeIntConstructor(const Constructor& c, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeIntConstructor(const Constructor& c, std::ostream& out) {
ASSERT(c.fType == *fContext.fInt_Type);
ASSERT(c.fArguments.size() == 1);
ASSERT(c.fArguments[0]->fType.isNumber());
@@ -1435,7 +1431,7 @@ SpvId SPIRVCodeGenerator::writeIntConstructor(const Constructor& c, SkWStream& o
return result;
}
-SpvId SPIRVCodeGenerator::writeMatrixConstructor(const Constructor& c, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeMatrixConstructor(const Constructor& c, std::ostream& 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
@@ -1507,7 +1503,7 @@ SpvId SPIRVCodeGenerator::writeMatrixConstructor(const Constructor& c, SkWStream
return result;
}
-SpvId SPIRVCodeGenerator::writeVectorConstructor(const Constructor& c, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeVectorConstructor(const Constructor& c, std::ostream& out) {
ASSERT(c.fType.kind() == Type::kVector_Kind);
if (c.isConstant()) {
return this->writeConstantVector(c);
@@ -1537,7 +1533,7 @@ SpvId SPIRVCodeGenerator::writeVectorConstructor(const Constructor& c, SkWStream
return result;
}
-SpvId SPIRVCodeGenerator::writeConstructor(const Constructor& c, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeConstructor(const Constructor& c, std::ostream& out) {
if (c.fType == *fContext.fFloat_Type) {
return this->writeFloatConstructor(c, out);
} else if (c.fType == *fContext.fInt_Type) {
@@ -1578,7 +1574,7 @@ SpvStorageClass_ get_storage_class(const Expression& expr) {
}
}
-std::vector<SpvId> SPIRVCodeGenerator::getAccessChain(const Expression& expr, SkWStream& out) {
+std::vector<SpvId> SPIRVCodeGenerator::getAccessChain(const Expression& expr, std::ostream& out) {
std::vector<SpvId> chain;
switch (expr.fKind) {
case Expression::kIndex_Kind: {
@@ -1611,13 +1607,13 @@ public:
return fPointer;
}
- virtual SpvId load(SkWStream& out) override {
+ virtual SpvId load(std::ostream& out) override {
SpvId result = fGen.nextId();
fGen.writeInstruction(SpvOpLoad, fType, result, fPointer, out);
return result;
}
- virtual void store(SpvId value, SkWStream& out) override {
+ virtual void store(SpvId value, std::ostream& out) override {
fGen.writeInstruction(SpvOpStore, fPointer, value, out);
}
@@ -1641,7 +1637,7 @@ public:
return 0;
}
- virtual SpvId load(SkWStream& out) override {
+ virtual SpvId load(std::ostream& out) override {
SpvId base = fGen.nextId();
fGen.writeInstruction(SpvOpLoad, fGen.getType(fBaseType), base, fVecPointer, out);
SpvId result = fGen.nextId();
@@ -1656,7 +1652,7 @@ public:
return result;
}
- virtual void store(SpvId value, SkWStream& out) override {
+ virtual void store(SpvId value, std::ostream& 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
@@ -1703,7 +1699,7 @@ private:
};
std::unique_ptr<SPIRVCodeGenerator::LValue> SPIRVCodeGenerator::getLValue(const Expression& expr,
- SkWStream& out) {
+ std::ostream& out) {
switch (expr.fKind) {
case Expression::kVariableReference_Kind: {
const Variable& var = ((VariableReference&) expr).fVariable;
@@ -1776,7 +1772,7 @@ std::unique_ptr<SPIRVCodeGenerator::LValue> SPIRVCodeGenerator::getLValue(const
}
}
-SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, std::ostream& out) {
auto entry = fVariableMap.find(&ref.fVariable);
ASSERT(entry != fVariableMap.end());
SpvId var = entry->second;
@@ -1785,15 +1781,15 @@ SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, S
return result;
}
-SpvId SPIRVCodeGenerator::writeIndexExpression(const IndexExpression& expr, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeIndexExpression(const IndexExpression& expr, std::ostream& out) {
return getLValue(expr, out)->load(out);
}
-SpvId SPIRVCodeGenerator::writeFieldAccess(const FieldAccess& f, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeFieldAccess(const FieldAccess& f, std::ostream& out) {
return getLValue(f, out)->load(out);
}
-SpvId SPIRVCodeGenerator::writeSwizzle(const Swizzle& swizzle, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeSwizzle(const Swizzle& swizzle, std::ostream& out) {
SpvId base = this->writeExpression(*swizzle.fBase, out);
SpvId result = this->nextId();
size_t count = swizzle.fComponents.size();
@@ -1816,7 +1812,7 @@ SpvId SPIRVCodeGenerator::writeSwizzle(const Swizzle& swizzle, SkWStream& out) {
SpvId SPIRVCodeGenerator::writeBinaryOperation(const Type& resultType,
const Type& operandType, SpvId lhs,
SpvId rhs, SpvOp_ ifFloat, SpvOp_ ifInt,
- SpvOp_ ifUInt, SpvOp_ ifBool, SkWStream& out) {
+ SpvOp_ ifUInt, SpvOp_ ifBool, std::ostream& out) {
SpvId result = this->nextId();
if (is_float(fContext, operandType)) {
this->writeInstruction(ifFloat, this->getType(resultType), result, lhs, rhs, out);
@@ -1854,7 +1850,7 @@ bool is_assignment(Token::Kind op) {
}
}
-SpvId SPIRVCodeGenerator::writeBinaryExpression(const BinaryExpression& b, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeBinaryExpression(const BinaryExpression& b, std::ostream& out) {
// handle cases where we don't necessarily evaluate both LHS and RHS
switch (b.fOperator) {
case Token::EQ: {
@@ -2046,7 +2042,7 @@ SpvId SPIRVCodeGenerator::writeBinaryExpression(const BinaryExpression& b, SkWSt
}
}
-SpvId SPIRVCodeGenerator::writeLogicalAnd(const BinaryExpression& a, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeLogicalAnd(const BinaryExpression& a, std::ostream& out) {
ASSERT(a.fOperator == Token::LOGICALAND);
BoolLiteral falseLiteral(fContext, Position(), false);
SpvId falseConstant = this->writeBoolLiteral(falseLiteral);
@@ -2067,7 +2063,7 @@ SpvId SPIRVCodeGenerator::writeLogicalAnd(const BinaryExpression& a, SkWStream&
return result;
}
-SpvId SPIRVCodeGenerator::writeLogicalOr(const BinaryExpression& o, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeLogicalOr(const BinaryExpression& o, std::ostream& out) {
ASSERT(o.fOperator == Token::LOGICALOR);
BoolLiteral trueLiteral(fContext, Position(), true);
SpvId trueConstant = this->writeBoolLiteral(trueLiteral);
@@ -2088,7 +2084,7 @@ SpvId SPIRVCodeGenerator::writeLogicalOr(const BinaryExpression& o, SkWStream& o
return result;
}
-SpvId SPIRVCodeGenerator::writeTernaryExpression(const TernaryExpression& t, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeTernaryExpression(const TernaryExpression& t, std::ostream& 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
@@ -2132,7 +2128,7 @@ std::unique_ptr<Expression> create_literal_1(const Context& context, const Type&
}
}
-SpvId SPIRVCodeGenerator::writePrefixExpression(const PrefixExpression& p, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writePrefixExpression(const PrefixExpression& p, std::ostream& out) {
if (p.fOperator == Token::MINUS) {
SpvId result = this->nextId();
SpvId typeId = this->getType(p.fType);
@@ -2185,7 +2181,7 @@ SpvId SPIRVCodeGenerator::writePrefixExpression(const PrefixExpression& p, SkWSt
}
}
-SpvId SPIRVCodeGenerator::writePostfixExpression(const PostfixExpression& p, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writePostfixExpression(const PostfixExpression& p, std::ostream& out) {
std::unique_ptr<LValue> lv = this->getLValue(*p.fOperand, out);
SpvId result = lv->load(out);
SpvId one = this->writeExpression(*create_literal_1(fContext, p.fType), out);
@@ -2282,7 +2278,7 @@ SpvId SPIRVCodeGenerator::writeFloatLiteral(const FloatLiteral& f) {
}
}
-SpvId SPIRVCodeGenerator::writeFunctionStart(const FunctionDeclaration& f, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeFunctionStart(const FunctionDeclaration& f, std::ostream& out) {
SpvId result = fFunctionMap[&f];
this->writeInstruction(SpvOpFunction, this->getType(f.fReturnType), result,
SpvFunctionControlMaskNone, this->getFunctionType(f), out);
@@ -2297,16 +2293,17 @@ SpvId SPIRVCodeGenerator::writeFunctionStart(const FunctionDeclaration& f, SkWSt
return result;
}
-SpvId SPIRVCodeGenerator::writeFunction(const FunctionDefinition& f, SkWStream& out) {
+SpvId SPIRVCodeGenerator::writeFunction(const FunctionDefinition& f, std::ostream& out) {
SpvId result = this->writeFunctionStart(f.fDeclaration, out);
this->writeLabel(this->nextId(), out);
if (f.fDeclaration.fName == "main") {
- write_data(*fGlobalInitializersBuffer.detachAsData(), out);
+ out << fGlobalInitializersBuffer.str();
}
- SkDynamicMemoryWStream bodyBuffer;
+ std::stringstream bodyBuffer;
this->writeBlock(*f.fBody, bodyBuffer);
- write_data(*fVariableBuffer.detachAsData(), out);
- write_data(*bodyBuffer.detachAsData(), out);
+ out << fVariableBuffer.str();
+ fVariableBuffer.str("");
+ out << bodyBuffer.str();
if (fCurrentBlock) {
this->writeInstruction(SpvOpReturn, out);
}
@@ -2375,7 +2372,7 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) {
#define BUILTIN_IGNORE 9999
void SPIRVCodeGenerator::writeGlobalVars(Program::Kind kind, const VarDeclarations& decl,
- SkWStream& out) {
+ std::ostream& out) {
for (size_t i = 0; i < decl.fVars.size(); i++) {
const VarDeclaration& varDecl = decl.fVars[i];
const Variable* var = varDecl.fVar;
@@ -2430,7 +2427,7 @@ void SPIRVCodeGenerator::writeGlobalVars(Program::Kind kind, const VarDeclaratio
}
}
-void SPIRVCodeGenerator::writeVarDeclarations(const VarDeclarations& decl, SkWStream& out) {
+void SPIRVCodeGenerator::writeVarDeclarations(const VarDeclarations& decl, std::ostream& out) {
for (const auto& varDecl : decl.fVars) {
const Variable* var = varDecl.fVar;
SpvId id = this->nextId();
@@ -2445,7 +2442,7 @@ void SPIRVCodeGenerator::writeVarDeclarations(const VarDeclarations& decl, SkWSt
}
}
-void SPIRVCodeGenerator::writeStatement(const Statement& s, SkWStream& out) {
+void SPIRVCodeGenerator::writeStatement(const Statement& s, std::ostream& out) {
switch (s.fKind) {
case Statement::kBlock_Kind:
this->writeBlock((Block&) s, out);
@@ -2479,13 +2476,13 @@ void SPIRVCodeGenerator::writeStatement(const Statement& s, SkWStream& out) {
}
}
-void SPIRVCodeGenerator::writeBlock(const Block& b, SkWStream& out) {
+void SPIRVCodeGenerator::writeBlock(const Block& b, std::ostream& out) {
for (size_t i = 0; i < b.fStatements.size(); i++) {
this->writeStatement(*b.fStatements[i], out);
}
}
-void SPIRVCodeGenerator::writeIfStatement(const IfStatement& stmt, SkWStream& out) {
+void SPIRVCodeGenerator::writeIfStatement(const IfStatement& stmt, std::ostream& out) {
SpvId test = this->writeExpression(*stmt.fTest, out);
SpvId ifTrue = this->nextId();
SpvId ifFalse = this->nextId();
@@ -2516,7 +2513,7 @@ void SPIRVCodeGenerator::writeIfStatement(const IfStatement& stmt, SkWStream& ou
}
}
-void SPIRVCodeGenerator::writeForStatement(const ForStatement& f, SkWStream& out) {
+void SPIRVCodeGenerator::writeForStatement(const ForStatement& f, std::ostream& out) {
if (f.fInitializer) {
this->writeStatement(*f.fInitializer, out);
}
@@ -2551,7 +2548,7 @@ void SPIRVCodeGenerator::writeForStatement(const ForStatement& f, SkWStream& out
fContinueTarget.pop();
}
-void SPIRVCodeGenerator::writeReturnStatement(const ReturnStatement& r, SkWStream& out) {
+void SPIRVCodeGenerator::writeReturnStatement(const ReturnStatement& r, std::ostream& out) {
if (r.fExpression) {
this->writeInstruction(SpvOpReturnValue, this->writeExpression(*r.fExpression, out),
out);
@@ -2560,9 +2557,9 @@ void SPIRVCodeGenerator::writeReturnStatement(const ReturnStatement& r, SkWStrea
}
}
-void SPIRVCodeGenerator::writeInstructions(const Program& program, SkWStream& out) {
+void SPIRVCodeGenerator::writeInstructions(const Program& program, std::ostream& out) {
fGLSLExtendedInstructions = this->nextId();
- SkDynamicMemoryWStream body;
+ std::stringstream body;
std::vector<SpvId> interfaceVars;
// assign IDs to functions
for (size_t i = 0; i < program.fElements.size(); i++) {
@@ -2639,22 +2636,22 @@ void SPIRVCodeGenerator::writeInstructions(const Program& program, SkWStream& ou
}
}
- 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);
+ out << fNameBuffer.str();
+ out << fDecorationBuffer.str();
+ out << fConstantBuffer.str();
+ out << fExternalFunctionsBuffer.str();
+ out << body.str();
}
-void SPIRVCodeGenerator::generateCode(const Program& program, SkWStream& out) {
+void SPIRVCodeGenerator::generateCode(const Program& program, std::ostream& out) {
this->writeWord(SpvMagicNumber, out);
this->writeWord(SpvVersion, out);
this->writeWord(SKSL_MAGIC, out);
- SkDynamicMemoryWStream buffer;
+ std::stringstream buffer;
this->writeInstructions(program, buffer);
this->writeWord(fIdCount, out);
this->writeWord(0, out); // reserved, always zero
- write_data(*buffer.detachAsData(), out);
+ out << buffer.str();
}
}
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.h b/src/sksl/SkSLSPIRVCodeGenerator.h
index 84c582e53e..e6fc28ee0c 100644
--- a/src/sksl/SkSLSPIRVCodeGenerator.h
+++ b/src/sksl/SkSLSPIRVCodeGenerator.h
@@ -8,11 +8,11 @@
#ifndef SKSL_SPIRVCODEGENERATOR
#define SKSL_SPIRVCODEGENERATOR
+#include <sstream>
#include <stack>
#include <tuple>
#include <unordered_map>
-#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(SkWStream& out) = 0;
+ virtual SpvId load(std::ostream& out) = 0;
- virtual void store(SpvId value, SkWStream& out) = 0;
+ virtual void store(SpvId value, std::ostream& out) = 0;
};
SPIRVCodeGenerator(const Context* context)
@@ -71,7 +71,7 @@ public:
this->setupIntrinsics();
}
- void generateCode(const Program& program, SkWStream& out) override;
+ void generateCode(const Program& program, std::ostream& out) override;
private:
enum IntrinsicKind {
@@ -97,7 +97,7 @@ private:
SpvId getPointerType(const Type& type, SpvStorageClass_ storageClass);
- std::vector<SpvId> getAccessChain(const Expression& expr, SkWStream& out);
+ std::vector<SpvId> getAccessChain(const Expression& expr, std::ostream& 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, SkWStream& out);
+ void writeProgramElement(const ProgramElement& pe, std::ostream& out);
SpvId writeInterfaceBlock(const InterfaceBlock& intf);
- SpvId writeFunctionStart(const FunctionDeclaration& f, SkWStream& out);
+ SpvId writeFunctionStart(const FunctionDeclaration& f, std::ostream& out);
- SpvId writeFunctionDeclaration(const FunctionDeclaration& f, SkWStream& out);
+ SpvId writeFunctionDeclaration(const FunctionDeclaration& f, std::ostream& out);
- SpvId writeFunction(const FunctionDefinition& f, SkWStream& out);
+ SpvId writeFunction(const FunctionDefinition& f, std::ostream& out);
- void writeGlobalVars(Program::Kind kind, const VarDeclarations& v, SkWStream& out);
+ void writeGlobalVars(Program::Kind kind, const VarDeclarations& v, std::ostream& out);
- void writeVarDeclarations(const VarDeclarations& decl, SkWStream& out);
+ void writeVarDeclarations(const VarDeclarations& decl, std::ostream& out);
- SpvId writeVariableReference(const VariableReference& ref, SkWStream& out);
+ SpvId writeVariableReference(const VariableReference& ref, std::ostream& out);
- std::unique_ptr<LValue> getLValue(const Expression& value, SkWStream& out);
+ std::unique_ptr<LValue> getLValue(const Expression& value, std::ostream& out);
- SpvId writeExpression(const Expression& expr, SkWStream& out);
+ SpvId writeExpression(const Expression& expr, std::ostream& out);
- SpvId writeIntrinsicCall(const FunctionCall& c, SkWStream& out);
+ SpvId writeIntrinsicCall(const FunctionCall& c, std::ostream& out);
- SpvId writeFunctionCall(const FunctionCall& c, SkWStream& out);
+ SpvId writeFunctionCall(const FunctionCall& c, std::ostream& out);
- SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, SkWStream& out);
+ SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, std::ostream& out);
SpvId writeConstantVector(const Constructor& c);
- SpvId writeFloatConstructor(const Constructor& c, SkWStream& out);
+ SpvId writeFloatConstructor(const Constructor& c, std::ostream& out);
- SpvId writeIntConstructor(const Constructor& c, SkWStream& out);
+ SpvId writeIntConstructor(const Constructor& c, std::ostream& out);
- SpvId writeMatrixConstructor(const Constructor& c, SkWStream& out);
+ SpvId writeMatrixConstructor(const Constructor& c, std::ostream& out);
- SpvId writeVectorConstructor(const Constructor& c, SkWStream& out);
+ SpvId writeVectorConstructor(const Constructor& c, std::ostream& out);
- SpvId writeConstructor(const Constructor& c, SkWStream& out);
+ SpvId writeConstructor(const Constructor& c, std::ostream& out);
- SpvId writeFieldAccess(const FieldAccess& f, SkWStream& out);
+ SpvId writeFieldAccess(const FieldAccess& f, std::ostream& out);
- SpvId writeSwizzle(const Swizzle& swizzle, SkWStream& out);
+ SpvId writeSwizzle(const Swizzle& swizzle, std::ostream& out);
SpvId writeBinaryOperation(const Type& resultType, const Type& operandType, SpvId lhs,
SpvId rhs, SpvOp_ ifFloat, SpvOp_ ifInt, SpvOp_ ifUInt,
- SpvOp_ ifBool, SkWStream& out);
+ SpvOp_ ifBool, std::ostream& out);
SpvId writeBinaryOperation(const BinaryExpression& expr, SpvOp_ ifFloat, SpvOp_ ifInt,
- SpvOp_ ifUInt, SkWStream& out);
+ SpvOp_ ifUInt, std::ostream& out);
- SpvId writeBinaryExpression(const BinaryExpression& b, SkWStream& out);
+ SpvId writeBinaryExpression(const BinaryExpression& b, std::ostream& out);
- SpvId writeTernaryExpression(const TernaryExpression& t, SkWStream& out);
+ SpvId writeTernaryExpression(const TernaryExpression& t, std::ostream& out);
- SpvId writeIndexExpression(const IndexExpression& expr, SkWStream& out);
+ SpvId writeIndexExpression(const IndexExpression& expr, std::ostream& out);
- SpvId writeLogicalAnd(const BinaryExpression& b, SkWStream& out);
+ SpvId writeLogicalAnd(const BinaryExpression& b, std::ostream& out);
- SpvId writeLogicalOr(const BinaryExpression& o, SkWStream& out);
+ SpvId writeLogicalOr(const BinaryExpression& o, std::ostream& out);
- SpvId writePrefixExpression(const PrefixExpression& p, SkWStream& out);
+ SpvId writePrefixExpression(const PrefixExpression& p, std::ostream& out);
- SpvId writePostfixExpression(const PostfixExpression& p, SkWStream& out);
+ SpvId writePostfixExpression(const PostfixExpression& p, std::ostream& out);
SpvId writeBoolLiteral(const BoolLiteral& b);
@@ -174,59 +174,59 @@ private:
SpvId writeFloatLiteral(const FloatLiteral& f);
- void writeStatement(const Statement& s, SkWStream& out);
+ void writeStatement(const Statement& s, std::ostream& out);
- void writeBlock(const Block& b, SkWStream& out);
+ void writeBlock(const Block& b, std::ostream& out);
- void writeIfStatement(const IfStatement& stmt, SkWStream& out);
+ void writeIfStatement(const IfStatement& stmt, std::ostream& out);
- void writeForStatement(const ForStatement& f, SkWStream& out);
+ void writeForStatement(const ForStatement& f, std::ostream& out);
- void writeReturnStatement(const ReturnStatement& r, SkWStream& out);
+ void writeReturnStatement(const ReturnStatement& r, std::ostream& out);
- void writeCapabilities(SkWStream& out);
+ void writeCapabilities(std::ostream& out);
- void writeInstructions(const Program& program, SkWStream& out);
+ void writeInstructions(const Program& program, std::ostream& out);
- void writeOpCode(SpvOp_ opCode, int length, SkWStream& out);
+ void writeOpCode(SpvOp_ opCode, int length, std::ostream& out);
- void writeWord(int32_t word, SkWStream& out);
+ void writeWord(int32_t word, std::ostream& out);
- void writeString(const char* string, SkWStream& out);
+ void writeString(const char* string, std::ostream& out);
- void writeLabel(SpvId id, SkWStream& out);
+ void writeLabel(SpvId id, std::ostream& out);
- void writeInstruction(SpvOp_ opCode, SkWStream& out);
+ void writeInstruction(SpvOp_ opCode, std::ostream& out);
- void writeInstruction(SpvOp_ opCode, const char* string, SkWStream& out);
+ void writeInstruction(SpvOp_ opCode, const char* string, std::ostream& out);
- void writeInstruction(SpvOp_ opCode, int32_t word1, SkWStream& out);
+ void writeInstruction(SpvOp_ opCode, int32_t word1, std::ostream& out);
- void writeInstruction(SpvOp_ opCode, int32_t word1, const char* string, SkWStream& out);
+ void writeInstruction(SpvOp_ opCode, int32_t word1, const char* string, std::ostream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, const char* string,
- SkWStream& out);
+ 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, std::ostream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3,
- SkWStream& out);
+ std::ostream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4,
- SkWStream& out);
+ std::ostream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4,
- int32_t word5, SkWStream& out);
+ int32_t word5, std::ostream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4,
- int32_t word5, int32_t word6, SkWStream& out);
+ int32_t word5, int32_t word6, std::ostream& 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, SkWStream& out);
+ int32_t word5, int32_t word6, int32_t word7, std::ostream& 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,
- SkWStream& out);
+ std::ostream& out);
const Context& fContext;
@@ -234,18 +234,18 @@ private:
SpvId fIdCount;
SpvId fGLSLExtendedInstructions;
typedef std::tuple<IntrinsicKind, int32_t, int32_t, int32_t, int32_t> Intrinsic;
- std::unordered_map<SkString, Intrinsic> fIntrinsicMap;
+ std::unordered_map<std::string, Intrinsic> fIntrinsicMap;
std::unordered_map<const FunctionDeclaration*, SpvId> fFunctionMap;
std::unordered_map<const Variable*, SpvId> fVariableMap;
std::unordered_map<const Variable*, int32_t> fInterfaceBlockMap;
- std::unordered_map<SkString, SpvId> fTypeMap;
- SkDynamicMemoryWStream fCapabilitiesBuffer;
- SkDynamicMemoryWStream fGlobalInitializersBuffer;
- SkDynamicMemoryWStream fConstantBuffer;
- SkDynamicMemoryWStream fExternalFunctionsBuffer;
- SkDynamicMemoryWStream fVariableBuffer;
- SkDynamicMemoryWStream fNameBuffer;
- SkDynamicMemoryWStream fDecorationBuffer;
+ std::unordered_map<std::string, SpvId> fTypeMap;
+ std::stringstream fCapabilitiesBuffer;
+ std::stringstream fGlobalInitializersBuffer;
+ std::stringstream fConstantBuffer;
+ std::stringstream fExternalFunctionsBuffer;
+ std::stringstream fVariableBuffer;
+ std::stringstream fNameBuffer;
+ std::stringstream fDecorationBuffer;
SpvId fBoolTrue;
SpvId fBoolFalse;
diff --git a/src/sksl/SkSLToken.h b/src/sksl/SkSLToken.h
index 6fe130fe4a..76a1df7f66 100644
--- a/src/sksl/SkSLToken.h
+++ b/src/sksl/SkSLToken.h
@@ -103,45 +103,45 @@ struct Token {
INVALID_TOKEN
};
- static SkString OperatorName(Kind kind) {
+ static std::string OperatorName(Kind kind) {
switch (kind) {
- 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("--");
+ 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 "--";
default:
ABORT("unsupported operator: %d\n", kind);
}
@@ -150,7 +150,7 @@ struct Token {
Token() {
}
- Token(Position position, Kind kind, SkString text)
+ Token(Position position, Kind kind, std::string 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)
- SkString fText;
+ std::string fText;
};
} // namespace
diff --git a/src/sksl/SkSLUtil.cpp b/src/sksl/SkSLUtil.cpp
index 97b5179994..51ad9fe808 100644
--- a/src/sksl/SkSLUtil.cpp
+++ b/src/sksl/SkSLUtil.cpp
@@ -7,63 +7,61 @@
#include "SkSLUtil.h"
-#include <cinttypes>
-
namespace SkSL {
-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')) {
+std::string to_string(double value) {
+ std::stringstream buffer;
+ buffer << std::setprecision(std::numeric_limits<double>::digits10) << value;
+ std::string result = buffer.str();
+ if (result.find_last_of(".") == std::string::npos &&
+ result.find_last_of("e") == std::string::npos) {
result += ".0";
}
return result;
-#undef SNPRINTF
-#undef MAX_DOUBLE_CHARS
}
-SkString to_string(int32_t value) {
- return SkStringPrintf("%d", value);
+std::string to_string(int32_t value) {
+ std::stringstream buffer;
+ buffer << value;
+ return buffer.str();
}
-SkString to_string(uint32_t value) {
- return SkStringPrintf("%u", value);
+std::string to_string(uint32_t value) {
+ std::stringstream buffer;
+ buffer << value;
+ return buffer.str();
}
-SkString to_string(int64_t value) {
- return SkStringPrintf("%" PRId64, value);
+std::string to_string(int64_t value) {
+ std::stringstream buffer;
+ buffer << value;
+ return buffer.str();
}
-SkString to_string(uint64_t value) {
- return SkStringPrintf("%" PRIu64, value);
+std::string to_string(uint64_t value) {
+ std::stringstream buffer;
+ buffer << value;
+ return buffer.str();
}
-int stoi(SkString s) {
+int stoi(std::string s) {
if (s.size() > 2 && s[0] == '0' && s[1] == 'x') {
char* p;
- int result = strtoul(s.c_str() + 2, &p, 16);
+ int result = strtoul(s.substr(2).c_str(), &p, 16);
ASSERT(*p == 0);
return result;
}
return atoi(s.c_str());
}
-double stod(SkString s) {
+double stod(std::string s) {
return atof(s.c_str());
}
-long stol(SkString s) {
+long stol(std::string s) {
if (s.size() > 2 && s[0] == '0' && s[1] == 'x') {
char* p;
- long result = strtoul(s.c_str() + 2, &p, 16);
+ long result = strtoul(s.substr(2).c_str(), &p, 16);
ASSERT(*p == 0);
return result;
}
@@ -79,37 +77,4 @@ 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 ad8287e39f..ede21830e5 100644
--- a/src/sksl/SkSLUtil.h
+++ b/src/sksl/SkSLUtil.h
@@ -8,12 +8,12 @@
#ifndef SKSL_UTIL
#define SKSL_UTIL
+#include <iomanip>
+#include <string>
+#include <sstream>
#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,47 +73,40 @@ public:
}
};
-void write_data(const SkData& d, SkWStream& out);
+// our own definitions of certain std:: functions, because they are not always present on Android
-SkString operator+(const SkString& s, const char* c);
+std::string to_string(double value);
-SkString operator+(const char* c, const SkString& s);
+std::string to_string(int32_t value);
-SkString operator+(const SkString& s1, const SkString& s2);
+std::string to_string(uint32_t value);
-bool operator==(const SkString& s1, const char* s2);
+std::string to_string(int64_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);
+std::string to_string(uint64_t value);
#if _MSC_VER
#define NORETURN __declspec(noreturn)
#else
#define NORETURN __attribute__((__noreturn__))
#endif
-int stoi(SkString s);
+int stoi(std::string s);
-double stod(SkString s);
+double stod(std::string s);
-long stol(SkString s);
+long stol(std::string s);
NORETURN void sksl_abort();
} // namespace
-#define ASSERT(x) SkASSERT(x)
-#define ASSERT_RESULT(x) SkAssertResult(x);
+#ifdef DEBUG
+#define ASSERT(x) assert(x)
+#define ASSERT_RESULT(x) ASSERT(x);
+#else
+#define ASSERT(x)
+#define ASSERT_RESULT(x) x
+#endif
#ifdef SKIA
#define ABORT(...) { SkDebugf(__VA_ARGS__); sksl_abort(); }
@@ -121,11 +114,4 @@ NORETURN void sksl_abort();
#define ABORT(...) { sksl_abort(); }
#endif
-namespace std {
- template<> struct hash<SkString> {
- 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 c4b6e3a45b..88feba66a7 100644
--- a/src/sksl/ast/SkSLASTBinaryExpression.h
+++ b/src/sksl/ast/SkSLASTBinaryExpression.h
@@ -10,6 +10,7 @@
#include "SkSLASTExpression.h"
#include "../SkSLToken.h"
+#include <sstream>
namespace SkSL {
@@ -24,7 +25,7 @@ struct ASTBinaryExpression : public ASTExpression {
, fOperator(op.fKind)
, fRight(std::move(right)) {}
- SkString description() const override {
+ std::string 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 6b1e9c5551..09450a3db8 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)) {}
- SkString description() const override {
- SkString result("{");
+ std::string description() const override {
+ std::string 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 02f4bac0da..ff58822952 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) {}
- SkString description() const override {
- return SkString(fValue ? "true" : "false");
+ std::string description() const override {
+ return fValue ? "true" : "false";
}
const bool fValue;
diff --git a/src/sksl/ast/SkSLASTBreakStatement.h b/src/sksl/ast/SkSLASTBreakStatement.h
index dad2a85c0a..ede548cc24 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) {}
- SkString description() const override {
- return SkString("break;");
+ std::string description() const override {
+ return "break;";
}
typedef ASTStatement INHERITED;
diff --git a/src/sksl/ast/SkSLASTCallSuffix.h b/src/sksl/ast/SkSLASTCallSuffix.h
index 356ac850f9..5cff6f6c93 100644
--- a/src/sksl/ast/SkSLASTCallSuffix.h
+++ b/src/sksl/ast/SkSLASTCallSuffix.h
@@ -8,6 +8,7 @@
#ifndef SKSL_ASTCALLSUFFIX
#define SKSL_ASTCALLSUFFIX
+#include <sstream>
#include <vector>
#include "SkSLASTSuffix.h"
@@ -21,9 +22,9 @@ struct ASTCallSuffix : public ASTSuffix {
: INHERITED(position, ASTSuffix::kCall_Kind)
, fArguments(std::move(arguments)) {}
- SkString description() const override {
- SkString result("(");
- SkString separator;
+ std::string description() const override {
+ std::string result("(");
+ std::string 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 4cded3b16b..d5ab7a5c74 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) {}
- SkString description() const override {
- return SkString("continue;");
+ std::string description() const override {
+ return "continue;";
}
typedef ASTStatement INHERITED;
diff --git a/src/sksl/ast/SkSLASTDiscardStatement.h b/src/sksl/ast/SkSLASTDiscardStatement.h
index 754bf95efe..4eaeec9ea4 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) {}
- SkString description() const override {
- return SkString("discard;");
+ std::string description() const override {
+ return "discard;";
}
typedef ASTStatement INHERITED;
diff --git a/src/sksl/ast/SkSLASTDoStatement.h b/src/sksl/ast/SkSLASTDoStatement.h
index 9a0caced1c..a952d62eb5 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)) {}
- SkString description() const override {
+ std::string 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 2dbd20940d..450cca29fc 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)) {}
- SkString description() const override {
+ std::string description() const override {
return fExpression->description() + ";";
}
diff --git a/src/sksl/ast/SkSLASTExtension.h b/src/sksl/ast/SkSLASTExtension.h
index b9df3c52e9..896ac46c58 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, SkString name)
+ ASTExtension(Position position, std::string name)
: INHERITED(position, kExtension_Kind)
, fName(std::move(name)) {}
- SkString description() const override {
+ std::string description() const override {
return "#extension " + fName + " : enable";
}
- const SkString fName;
+ const std::string fName;
typedef ASTDeclaration INHERITED;
};
diff --git a/src/sksl/ast/SkSLASTFieldSuffix.h b/src/sksl/ast/SkSLASTFieldSuffix.h
index 9ee8531bf1..cf141d822f 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, SkString field)
+ ASTFieldSuffix(Position position, std::string field)
: INHERITED(position, ASTSuffix::kField_Kind)
, fField(std::move(field)) {}
- SkString description() const override {
+ std::string description() const override {
return "." + fField;
}
- SkString fField;
+ std::string fField;
typedef ASTSuffix INHERITED;
};
diff --git a/src/sksl/ast/SkSLASTFloatLiteral.h b/src/sksl/ast/SkSLASTFloatLiteral.h
index ea0f595abc..89d43cc003 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) {}
- SkString description() const override {
+ std::string description() const override {
return to_string(fValue);
}
diff --git a/src/sksl/ast/SkSLASTForStatement.h b/src/sksl/ast/SkSLASTForStatement.h
index 2706a39954..f4f68c8f40 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)) {}
- SkString description() const override {
- SkString result("for (");
+ std::string description() const override {
+ std::string result = "for (";
if (fInitializer) {
result.append(fInitializer->description());
}
diff --git a/src/sksl/ast/SkSLASTFunction.h b/src/sksl/ast/SkSLASTFunction.h
index 32f4da71f2..c5c3b9ad83 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<ASTType> returnType, SkString name,
+ ASTFunction(Position position, std::unique_ptr<ASTType> returnType, std::string name,
std::vector<std::unique_ptr<ASTParameter>> parameters,
std::unique_ptr<ASTBlock> body)
: INHERITED(position, kFunction_Kind)
@@ -28,8 +28,8 @@ struct ASTFunction : public ASTDeclaration {
, fParameters(std::move(parameters))
, fBody(std::move(body)) {}
- SkString description() const override {
- SkString result = fReturnType->description() + " " + fName + "(";
+ std::string description() const override {
+ std::string 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<ASTType> fReturnType;
- const SkString fName;
+ const std::string fName;
const std::vector<std::unique_ptr<ASTParameter>> fParameters;
const std::unique_ptr<ASTBlock> fBody;
diff --git a/src/sksl/ast/SkSLASTIdentifier.h b/src/sksl/ast/SkSLASTIdentifier.h
index aa0179a18f..d67f64d39b 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, SkString text)
+ ASTIdentifier(Position position, std::string text)
: INHERITED(position, kIdentifier_Kind)
, fText(std::move(text)) {}
- SkString description() const override {
+ std::string description() const override {
return fText;
}
- const SkString fText;
+ const std::string fText;
typedef ASTExpression INHERITED;
};
diff --git a/src/sksl/ast/SkSLASTIfStatement.h b/src/sksl/ast/SkSLASTIfStatement.h
index d169702710..06f663d5fb 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)) {}
- SkString description() const override {
- SkString result("if (");
+ std::string description() const override {
+ std::string result("if (");
result += fTest->description();
result += ") ";
result += fIfTrue->description();
diff --git a/src/sksl/ast/SkSLASTIndexSuffix.h b/src/sksl/ast/SkSLASTIndexSuffix.h
index 2b7cd48417..755029b0a2 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)) {}
- SkString description() const override {
+ std::string description() const override {
if (fExpression) {
return "[" + fExpression->description() + "]";
} else {
- return SkString("[]");
+ return "[]";
}
}
diff --git a/src/sksl/ast/SkSLASTIntLiteral.h b/src/sksl/ast/SkSLASTIntLiteral.h
index f524bc04ad..2598847534 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) {}
- SkString description() const override {
+ std::string description() const override {
return to_string(fValue);
}
diff --git a/src/sksl/ast/SkSLASTInterfaceBlock.h b/src/sksl/ast/SkSLASTInterfaceBlock.h
index 8d86c7c4f1..c271362071 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,
- SkString interfaceName,
- SkString valueName,
+ std::string interfaceName,
+ std::string valueName,
std::vector<std::unique_ptr<ASTVarDeclarations>> declarations)
: INHERITED(position, kInterfaceBlock_Kind)
, fModifiers(modifiers)
@@ -33,21 +33,21 @@ struct ASTInterfaceBlock : public ASTDeclaration {
, fValueName(std::move(valueName))
, fDeclarations(std::move(declarations)) {}
- SkString description() const override {
- SkString result = fModifiers.description() + fInterfaceName + " {\n";
+ std::string description() const override {
+ std::string result = fModifiers.description() + fInterfaceName + " {\n";
for (size_t i = 0; i < fDeclarations.size(); i++) {
result += fDeclarations[i]->description() + "\n";
}
result += "}";
- if (fValueName.size()) {
+ if (fValueName.length()) {
result += " " + fValueName;
}
return result + ";";
}
const ASTModifiers fModifiers;
- const SkString fInterfaceName;
- const SkString fValueName;
+ const std::string fInterfaceName;
+ const std::string fValueName;
const std::vector<std::unique_ptr<ASTVarDeclarations>> fDeclarations;
typedef ASTDeclaration INHERITED;
diff --git a/src/sksl/ast/SkSLASTLayout.h b/src/sksl/ast/SkSLASTLayout.h
index cb7f3c175c..ae3c3b6168 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(SkString str, Format* format) {
+ static bool ReadFormat(std::string str, Format* format) {
if (str == "rgba32f") {
*format = Format::kRGBA32F;
return true;
@@ -90,9 +90,9 @@ struct ASTLayout : public ASTNode {
, fBlendSupportAllEquations(blendSupportAllEquations)
, fFormat(format) {}
- SkString description() const {
- SkString result;
- SkString separator;
+ std::string description() const {
+ std::string result;
+ std::string 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.size() > 0) {
+ if (result.length() > 0) {
result = "layout (" + result + ")";
}
return result;
diff --git a/src/sksl/ast/SkSLASTModifiers.h b/src/sksl/ast/SkSLASTModifiers.h
index 734169267c..61d2e9f25d 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) {}
- SkString description() const override {
- SkString result = fLayout.description();
+ std::string description() const override {
+ std::string result = fLayout.description();
if (fFlags & kUniform_Flag) {
result += "uniform ";
}
diff --git a/src/sksl/ast/SkSLASTModifiersDeclaration.h b/src/sksl/ast/SkSLASTModifiersDeclaration.h
index 07efdf6024..f5cc620899 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) {}
- SkString description() const {
+ std::string description() const {
return fModifiers.description() + ";";
}
diff --git a/src/sksl/ast/SkSLASTNode.h b/src/sksl/ast/SkSLASTNode.h
index af065955f8..4305011fa5 100644
--- a/src/sksl/ast/SkSLASTNode.h
+++ b/src/sksl/ast/SkSLASTNode.h
@@ -8,7 +8,8 @@
#ifndef SKSL_ASTNODE
#define SKSL_ASTNODE
-#include "SkString.h"
+#include <memory>
+#include <string>
namespace SkSL {
@@ -19,7 +20,7 @@ namespace SkSL {
struct ASTNode {
virtual ~ASTNode() {}
- virtual SkString description() const = 0;
+ virtual std::string description() const = 0;
};
} // namespace
diff --git a/src/sksl/ast/SkSLASTParameter.h b/src/sksl/ast/SkSLASTParameter.h
index b1fd658434..8f1b4535f2 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<ASTType> type,
- SkString name, std::vector<int> sizes)
+ std::string name, std::vector<int> sizes)
: INHERITED(position)
, fModifiers(modifiers)
, fType(std::move(type))
, fName(std::move(name))
, fSizes(std::move(sizes)) {}
- SkString description() const override {
- SkString result = fModifiers.description() + fType->description() + " " + fName;
+ std::string description() const override {
+ std::string 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<ASTType> fType;
- const SkString fName;
+ const std::string fName;
const std::vector<int> fSizes;
typedef ASTPositionNode INHERITED;
diff --git a/src/sksl/ast/SkSLASTPrecision.h b/src/sksl/ast/SkSLASTPrecision.h
index a2f427c9ce..a7df57948e 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) {}
- SkString description() const {
+ std::string description() const {
switch (fPrecision) {
- 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;");
+ case Modifiers::kLowp_Flag: return "precision lowp float;";
+ case Modifiers::kMediump_Flag: return "precision mediump float;";
+ case Modifiers::kHighp_Flag: return "precision highp float;";
default:
ASSERT(false);
- return SkString("<error>");
+ return "<error>";
}
ASSERT(false);
- return SkString("<error>");
+ return "<error>";
}
const Modifiers::Flag fPrecision;
diff --git a/src/sksl/ast/SkSLASTPrefixExpression.h b/src/sksl/ast/SkSLASTPrefixExpression.h
index e06ec41f9e..0d326e2aab 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)) {}
- SkString description() const override {
+ std::string description() const override {
return Token::OperatorName(fOperator) + fOperand->description();
}
diff --git a/src/sksl/ast/SkSLASTReturnStatement.h b/src/sksl/ast/SkSLASTReturnStatement.h
index ed24d4a153..3aac783a8c 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)) {}
- SkString description() const override {
- SkString result("return");
+ std::string description() const override {
+ std::string result("return");
if (fExpression) {
result += " " + fExpression->description();
}
diff --git a/src/sksl/ast/SkSLASTSuffix.h b/src/sksl/ast/SkSLASTSuffix.h
index 64178c7682..18f79f01ea 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) {}
- SkString description() const override {
+ std::string description() const override {
switch (fKind) {
case kPostIncrement_Kind:
- return SkString("++");
+ return "++";
case kPostDecrement_Kind:
- return SkString("--");
+ return "--";
default:
ABORT("unsupported suffix operator");
}
diff --git a/src/sksl/ast/SkSLASTSuffixExpression.h b/src/sksl/ast/SkSLASTSuffixExpression.h
index 7ee200fd43..c0fda294b9 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)) {}
- SkString description() const override {
+ std::string description() const override {
return fBase->description() + fSuffix->description();
}
diff --git a/src/sksl/ast/SkSLASTTernaryExpression.h b/src/sksl/ast/SkSLASTTernaryExpression.h
index ddf8e3d120..20b827a049 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)) {}
- SkString description() const override {
+ std::string 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 81594000e5..b8fdedb214 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, SkString name, Kind kind)
+ ASTType(Position position, std::string name, Kind kind)
: INHERITED(position)
, fName(std::move(name))
, fKind(kind) {}
- SkString description() const override {
+ std::string description() const override {
return fName;
}
- const SkString fName;
+ const std::string fName;
const Kind fKind;
diff --git a/src/sksl/ast/SkSLASTVarDeclaration.h b/src/sksl/ast/SkSLASTVarDeclaration.h
index 9de4cf55b9..066922fb85 100644
--- a/src/sksl/ast/SkSLASTVarDeclaration.h
+++ b/src/sksl/ast/SkSLASTVarDeclaration.h
@@ -22,15 +22,15 @@ namespace SkSL {
* instances.
*/
struct ASTVarDeclaration {
- ASTVarDeclaration(const SkString name,
+ ASTVarDeclaration(const std::string name,
std::vector<std::unique_ptr<ASTExpression>> sizes,
std::unique_ptr<ASTExpression> value)
: fName(name)
, fSizes(std::move(sizes))
, fValue(std::move(value)) {}
- SkString description() const {
- SkString result = fName;
+ std::string description() const {
+ std::string result = fName;
for (const auto& size : fSizes) {
if (size) {
result += "[" + size->description() + "]";
@@ -44,7 +44,7 @@ struct ASTVarDeclaration {
return result;
}
- SkString fName;
+ std::string fName;
// array sizes, if any. e.g. 'foo[3][]' has sizes [3, null]
std::vector<std::unique_ptr<ASTExpression>> fSizes;
@@ -65,9 +65,9 @@ struct ASTVarDeclarations : public ASTDeclaration {
, fType(std::move(type))
, fVars(std::move(vars)) {}
- SkString description() const override {
- SkString result = fModifiers.description() + fType->description() + " ";
- SkString separator;
+ std::string description() const override {
+ std::string result = fModifiers.description() + fType->description() + " ";
+ std::string separator = "";
for (const auto& var : fVars) {
result += separator;
separator = ", ";
diff --git a/src/sksl/ast/SkSLASTVarDeclarationStatement.h b/src/sksl/ast/SkSLASTVarDeclarationStatement.h
index d71639d797..8bae389146 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)) {}
- SkString description() const override {
+ std::string description() const override {
return fDeclarations->description() + ";";
}
diff --git a/src/sksl/ast/SkSLASTWhileStatement.h b/src/sksl/ast/SkSLASTWhileStatement.h
index 853ac8028d..e29aa23e4a 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)) {}
- SkString description() const override {
+ std::string description() const override {
return "while (" + fTest->description() + ") " + fStatement->description();
}
diff --git a/src/sksl/ir/SkSLBinaryExpression.h b/src/sksl/ir/SkSLBinaryExpression.h
index 132513e7f7..9ecdbc717c 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 SkString description() const override {
+ virtual std::string 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 f975d160a0..a53d13d169 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)) {}
- SkString description() const override {
- SkString result("{");
+ std::string description() const override {
+ std::string result = "{";
for (size_t i = 0; i < fStatements.size(); i++) {
result += "\n";
result += fStatements[i]->description();
}
result += "\n}\n";
- return result;
+ return result;
}
const std::vector<std::unique_ptr<Statement>> fStatements;
diff --git a/src/sksl/ir/SkSLBoolLiteral.h b/src/sksl/ir/SkSLBoolLiteral.h
index b372f2f3ff..ba054e4181 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) {}
- SkString description() const override {
- return SkString(fValue ? "true" : "false");
+ std::string description() const override {
+ return fValue ? "true" : "false";
}
bool isConstant() const override {
diff --git a/src/sksl/ir/SkSLBreakStatement.h b/src/sksl/ir/SkSLBreakStatement.h
index cd633c7a91..8aa17b096b 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) {}
- SkString description() const override {
- return SkString("break;");
+ std::string description() const override {
+ return "break;";
}
typedef Statement INHERITED;
diff --git a/src/sksl/ir/SkSLConstructor.h b/src/sksl/ir/SkSLConstructor.h
index 92f758032b..0501b651ea 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)) {}
- SkString description() const override {
- SkString result = fType.description() + "(";
- SkString separator;
+ std::string description() const override {
+ std::string result = fType.description() + "(";
+ std::string 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 b4446940cf..1951bd990a 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) {}
- SkString description() const override {
- return SkString("continue;");
+ std::string description() const override {
+ return "continue;";
}
typedef Statement INHERITED;
diff --git a/src/sksl/ir/SkSLDiscardStatement.h b/src/sksl/ir/SkSLDiscardStatement.h
index 3ab6b27047..b39712ebd1 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) {}
- SkString description() const override {
- return SkString("discard;");
+ std::string description() const override {
+ return "discard;";
}
typedef Statement INHERITED;
diff --git a/src/sksl/ir/SkSLDoStatement.h b/src/sksl/ir/SkSLDoStatement.h
index 78c0a1b768..6012453277 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)) {}
- SkString description() const override {
+ std::string 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 677c647587..e975ccf2ac 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)) {}
- SkString description() const override {
+ std::string description() const override {
return fExpression->description() + ";";
}
diff --git a/src/sksl/ir/SkSLExtension.h b/src/sksl/ir/SkSLExtension.h
index ea5e0445e3..d7f83fad8a 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, SkString name)
+ Extension(Position position, std::string name)
: INHERITED(position, kExtension_Kind)
, fName(std::move(name)) {}
- SkString description() const override {
+ std::string description() const override {
return "#extension " + fName + " : enable";
}
- const SkString fName;
+ const std::string fName;
typedef ProgramElement INHERITED;
};
diff --git a/src/sksl/ir/SkSLField.h b/src/sksl/ir/SkSLField.h
index f73b6025ec..a01df2943d 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 SkString description() const override {
+ virtual std::string 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 fb727e017e..4be4e9e84c 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 SkString description() const override {
+ virtual std::string 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 8a1a5ad63a..a8fcfcf644 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 SkString description() const override {
+ virtual std::string description() const override {
return to_string(fValue);
}
diff --git a/src/sksl/ir/SkSLForStatement.h b/src/sksl/ir/SkSLForStatement.h
index ff03d0d7f9..642d15125e 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) {}
- SkString description() const override {
- SkString result("for (");
+ std::string description() const override {
+ std::string result = "for (";
if (fInitializer) {
result += fInitializer->description();
}
diff --git a/src/sksl/ir/SkSLFunctionCall.h b/src/sksl/ir/SkSLFunctionCall.h
index 971af366b9..5c67a2873c 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)) {}
- SkString description() const override {
- SkString result = fFunction.fName + "(";
- SkString separator;
+ std::string description() const override {
+ std::string result = fFunction.fName + "(";
+ std::string 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 c15d2b96dc..52a579a89b 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, SkString name,
+ FunctionDeclaration(Position position, std::string name,
std::vector<const Variable*> 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) {}
- SkString description() const override {
- SkString result = fReturnType.description() + " " + fName + "(";
- SkString separator;
+ std::string description() const override {
+ std::string result = fReturnType.description() + " " + fName + "(";
+ std::string separator = "";
for (auto p : fParameters) {
result += separator;
separator = ", ";
diff --git a/src/sksl/ir/SkSLFunctionDefinition.h b/src/sksl/ir/SkSLFunctionDefinition.h
index bae882525a..ace27a3ed8 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)) {}
- SkString description() const override {
+ std::string description() const override {
return fDeclaration.description() + " " + fBody->description();
}
diff --git a/src/sksl/ir/SkSLFunctionReference.h b/src/sksl/ir/SkSLFunctionReference.h
index ec1fc3804c..f3f8fb71da 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 SkString description() const override {
+ virtual std::string description() const override {
ASSERT(false);
- return SkString("<function>");
+ return "<function>";
}
const std::vector<const FunctionDeclaration*> fFunctions;
diff --git a/src/sksl/ir/SkSLIRNode.h b/src/sksl/ir/SkSLIRNode.h
index 9a04cddec5..8c433cfc6b 100644
--- a/src/sksl/ir/SkSLIRNode.h
+++ b/src/sksl/ir/SkSLIRNode.h
@@ -22,7 +22,7 @@ struct IRNode {
virtual ~IRNode() {}
- virtual SkString description() const = 0;
+ virtual std::string description() const = 0;
const Position fPosition;
};
diff --git a/src/sksl/ir/SkSLIfStatement.h b/src/sksl/ir/SkSLIfStatement.h
index f8beded9e8..8ab5c00fd7 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)) {}
- SkString description() const override {
- SkString result = "if (" + fTest->description() + ") " + fIfTrue->description();
+ std::string description() const override {
+ std::string 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 079dde5e53..abd8a03fa4 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);
}
- SkString description() const override {
+ std::string description() const override {
return fBase->description() + "[" + fIndex->description() + "]";
}
diff --git a/src/sksl/ir/SkSLIntLiteral.h b/src/sksl/ir/SkSLIntLiteral.h
index 23325e65fb..8921c283b5 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 SkString description() const override {
+ virtual std::string description() const override {
return to_string(fValue);
}
diff --git a/src/sksl/ir/SkSLInterfaceBlock.h b/src/sksl/ir/SkSLInterfaceBlock.h
index bc84396b2d..debde207a1 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);
}
- SkString description() const override {
- SkString result = fVariable.fModifiers.description() + fVariable.fName + " {\n";
+ std::string description() const override {
+ std::string 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 7359262c96..4cfd1a2771 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) {}
- SkString description() const {
- SkString result;
- SkString separator;
+ std::string description() const {
+ std::string result;
+ std::string 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.size() > 0) {
+ if (result.length() > 0) {
result = "layout (" + result + ")";
}
return result;
diff --git a/src/sksl/ir/SkSLModifiers.h b/src/sksl/ir/SkSLModifiers.h
index 2c9b3b39c9..f39e92959f 100644
--- a/src/sksl/ir/SkSLModifiers.h
+++ b/src/sksl/ir/SkSLModifiers.h
@@ -38,8 +38,8 @@ struct Modifiers {
: fLayout(layout)
, fFlags(flags) {}
- SkString description() const {
- SkString result = fLayout.description();
+ std::string description() const {
+ std::string result = fLayout.description();
if (fFlags & kUniform_Flag) {
result += "uniform ";
}
diff --git a/src/sksl/ir/SkSLModifiersDeclaration.h b/src/sksl/ir/SkSLModifiersDeclaration.h
index 625954d7c7..0066fab877 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) {}
- SkString description() const {
+ std::string description() const {
return fModifiers.description() + ";";
}
diff --git a/src/sksl/ir/SkSLPostfixExpression.h b/src/sksl/ir/SkSLPostfixExpression.h
index 01671b5b88..de146ac43c 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 SkString description() const override {
+ virtual std::string description() const override {
return fOperand->description() + Token::OperatorName(fOperator);
}
diff --git a/src/sksl/ir/SkSLPrefixExpression.h b/src/sksl/ir/SkSLPrefixExpression.h
index 790c5ab47a..53c3849b38 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 SkString description() const override {
+ virtual std::string description() const override {
return Token::OperatorName(fOperator) + fOperand->description();
}
diff --git a/src/sksl/ir/SkSLReturnStatement.h b/src/sksl/ir/SkSLReturnStatement.h
index c83b45066e..ec2226cc56 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)) {}
- SkString description() const override {
+ std::string description() const override {
if (fExpression) {
return "return " + fExpression->description() + ";";
} else {
- return SkString("return;");
+ return "return;";
}
}
diff --git a/src/sksl/ir/SkSLSwizzle.h b/src/sksl/ir/SkSLSwizzle.h
index c9397aec7f..0eb4a00dca 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);
}
- SkString description() const override {
- SkString result = fBase->description() + ".";
+ std::string description() const override {
+ std::string 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 10dcaf9344..d736516bc4 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, SkString name)
+ Symbol(Position position, Kind kind, std::string name)
: INHERITED(position)
, fKind(kind)
, fName(std::move(name)) {}
const Kind fKind;
- const SkString fName;
+ const std::string fName;
typedef IRNode INHERITED;
};
diff --git a/src/sksl/ir/SkSLSymbolTable.cpp b/src/sksl/ir/SkSLSymbolTable.cpp
index 3ceeab91b0..6d8e9a7ea6 100644
--- a/src/sksl/ir/SkSLSymbolTable.cpp
+++ b/src/sksl/ir/SkSLSymbolTable.cpp
@@ -21,7 +21,7 @@ std::vector<const FunctionDeclaration*> SymbolTable::GetFunctions(const Symbol&
}
}
-const Symbol* SymbolTable::operator[](const SkString& name) {
+const Symbol* SymbolTable::operator[](const std::string& 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 SkString& name, std::unique_ptr<Symbol> symbol) {
+void SymbolTable::add(const std::string& name, std::unique_ptr<Symbol> symbol) {
this->addWithoutOwnership(name, symbol.get());
fOwnedPointers.push_back(std::move(symbol));
}
-void SymbolTable::addWithoutOwnership(const SkString& name, const Symbol* symbol) {
+void SymbolTable::addWithoutOwnership(const std::string& 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 df8dc713ae..be2b49c48d 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 SkString& name);
+ const Symbol* operator[](const std::string& name);
- void add(const SkString& name, std::unique_ptr<Symbol> symbol);
+ void add(const std::string& name, std::unique_ptr<Symbol> symbol);
- void addWithoutOwnership(const SkString& name, const Symbol* symbol);
+ void addWithoutOwnership(const std::string& name, const Symbol* symbol);
Symbol* takeOwnership(Symbol* s);
@@ -48,7 +48,7 @@ private:
std::vector<std::unique_ptr<Symbol>> fOwnedPointers;
- std::unordered_map<SkString, const Symbol*> fSymbols;
+ std::unordered_map<std::string, const Symbol*> fSymbols;
ErrorReporter& fErrorReporter;
};
diff --git a/src/sksl/ir/SkSLTernaryExpression.h b/src/sksl/ir/SkSLTernaryExpression.h
index 4a352536e3..bfaf304e55 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);
}
- SkString description() const override {
+ std::string 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 4174c72a33..afd00d8b2a 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, SkString name, const Type* type)
+ Field(Modifiers modifiers, std::string name, const Type* type)
: fModifiers(modifiers)
, fName(std::move(name))
, fType(std::move(type)) {}
- const SkString description() const {
+ const std::string description() const {
return fType->description() + " " + fName + ";";
}
Modifiers fModifiers;
- SkString fName;
+ std::string 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(SkString name)
+ Type(std::string 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(SkString name, std::vector<const Type*> types)
+ Type(std::string name, std::vector<const Type*> 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(SkString name, std::vector<Field> fields)
+ Type(std::string name, std::vector<Field> fields)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kStruct_Kind)
, fFields(std::move(fields)) {}
// Create a scalar type.
- Type(SkString name, bool isNumber)
+ Type(std::string 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(SkString name, bool isNumber, std::vector<const Type*> coercibleTypes)
+ Type(std::string name, bool isNumber, std::vector<const Type*> 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(SkString name, const Type& componentType, int columns)
+ Type(std::string name, const Type& componentType, int columns)
: Type(name, kVector_Kind, componentType, columns) {}
// Create a vector or array type.
- Type(SkString name, Kind kind, const Type& componentType, int columns)
+ Type(std::string 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(SkString name, const Type& componentType, int columns, int rows)
+ Type(std::string 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(SkString name, SpvDim_ dimensions, bool isDepth, bool isArrayed, bool isMultisampled,
+ Type(std::string 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) {}
- SkString name() const {
+ std::string name() const {
return fName;
}
- SkString description() const override {
+ std::string description() const override {
return fName;
}
diff --git a/src/sksl/ir/SkSLTypeReference.h b/src/sksl/ir/SkSLTypeReference.h
index 1c6f16ce58..67e0466763 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) {}
- SkString description() const override {
+ std::string description() const override {
return fValue.name();
}
diff --git a/src/sksl/ir/SkSLUnresolvedFunction.h b/src/sksl/ir/SkSLUnresolvedFunction.h
index 76741cfca8..7e8a3601e8 100644
--- a/src/sksl/ir/SkSLUnresolvedFunction.h
+++ b/src/sksl/ir/SkSLUnresolvedFunction.h
@@ -26,7 +26,7 @@ struct UnresolvedFunction : public Symbol {
#endif
}
- virtual SkString description() const override {
+ virtual std::string description() const override {
return fName;
}
diff --git a/src/sksl/ir/SkSLVarDeclarations.h b/src/sksl/ir/SkSLVarDeclarations.h
index 295c0b6997..e64a874d69 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)) {}
- SkString description() const {
- SkString result = fVar->fName;
+ std::string description() const {
+ std::string result = fVar->fName;
for (const auto& size : fSizes) {
if (size) {
result += "[" + size->description() + "]";
@@ -57,12 +57,13 @@ struct VarDeclarations : public ProgramElement {
, fBaseType(*baseType)
, fVars(std::move(vars)) {}
- SkString description() const override {
+ std::string description() const override {
if (!fVars.size()) {
- return SkString();
+ return "";
}
- SkString result = fVars[0].fVar->fModifiers.description() + fBaseType.description() + " ";
- SkString separator;
+ std::string result = fVars[0].fVar->fModifiers.description() + fBaseType.description() +
+ " ";
+ std::string separator = "";
for (const auto& var : fVars) {
result += separator;
separator = ", ";
diff --git a/src/sksl/ir/SkSLVarDeclarationsStatement.h b/src/sksl/ir/SkSLVarDeclarationsStatement.h
index 7a29656593..0b62edb866 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)) {}
- SkString description() const override {
+ std::string description() const override {
return fDeclaration->description();
}
diff --git a/src/sksl/ir/SkSLVariable.h b/src/sksl/ir/SkSLVariable.h
index 39b8482a7b..217b1006b6 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, SkString name, const Type& type,
+ Variable(Position position, Modifiers modifiers, std::string 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 SkString description() const override {
+ virtual std::string description() const override {
return fModifiers.description() + fType.fName + " " + fName;
}
diff --git a/src/sksl/ir/SkSLVariableReference.h b/src/sksl/ir/SkSLVariableReference.h
index c6a2ea0511..b443da1f22 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) {}
- SkString description() const override {
+ std::string description() const override {
return fVariable.fName;
}
diff --git a/src/sksl/ir/SkSLWhileStatement.h b/src/sksl/ir/SkSLWhileStatement.h
index 7c6a2907c4..1acb572583 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)) {}
- SkString description() const override {
+ std::string description() const override {
return "while (" + fTest->description() + ") " + fStatement->description();
}
diff --git a/tests/SkSLErrorTest.cpp b/tests/SkSLErrorTest.cpp
index c9e342c6d5..e9e05c18d2 100644
--- a/tests/SkSLErrorTest.cpp
+++ b/tests/SkSLErrorTest.cpp
@@ -9,25 +9,24 @@
#include "Test.h"
-#if SK_SUPPORT_GPU
+#if SKIA_SUPPORT_GPU
static void test_failure(skiatest::Reporter* r, const char* src, const char* error) {
SkSL::Compiler compiler;
- SkDynamicMemoryWStream out;
- bool result = compiler.toSPIRV(SkSL::Program::kFragment_Kind, SkString(src), out);
- SkString skError(error);
- if (compiler.errorText() != skError) {
+ std::stringstream out;
+ bool result = compiler.toSPIRV(SkSL::Program::kFragment_Kind, src, out);
+ if (compiler.errorText() != error) {
SkDebugf("SKSL ERROR:\n source: %s\n expected: %s received: %s", src, error,
compiler.errorText().c_str());
}
REPORTER_ASSERT(r, !result);
- REPORTER_ASSERT(r, compiler.errorText() == skError);
+ REPORTER_ASSERT(r, compiler.errorText() == error);
}
static void test_success(skiatest::Reporter* r, const char* src) {
SkSL::Compiler compiler;
- SkDynamicMemoryWStream out;
- bool result = compiler.toSPIRV(SkSL::Program::kFragment_Kind, SkString(src), out);
+ std::stringstream out;
+ bool result = compiler.toSPIRV(SkSL::Program::kFragment_Kind, src, out);
REPORTER_ASSERT(r, result);
}
diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp
index 7af32bef6f..b01aad83d6 100644
--- a/tests/SkSLGLSLTest.cpp
+++ b/tests/SkSLGLSLTest.cpp
@@ -9,24 +9,23 @@
#include "Test.h"
-#if SK_SUPPORT_GPU
+#if SKIA_SUPPORT_GPU
static void test(skiatest::Reporter* r, const char* src, const GrGLSLCaps& caps,
const char* expected) {
SkSL::Compiler compiler;
- SkString output;
- bool result = compiler.toGLSL(SkSL::Program::kFragment_Kind, SkString(src), caps, &output);
+ std::string output;
+ bool result = compiler.toGLSL(SkSL::Program::kFragment_Kind, src, caps, &output);
if (!result) {
SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str());
}
REPORTER_ASSERT(r, result);
if (result) {
- SkString skExpected(expected);
- if (output != skExpected) {
+ if (output != expected) {
SkDebugf("GLSL MISMATCH:\nsource:\n%s\n\nexpected:\n'%s'\n\nreceived:\n'%s'", src,
expected, output.c_str());
}
- REPORTER_ASSERT(r, output == skExpected);
+ REPORTER_ASSERT(r, output == expected);
}
}
@@ -47,7 +46,7 @@ DEF_TEST(SkSLControl, r) {
"if (sqrt(2) > 5) { sk_FragColor = vec4(0.75); } else { discard; }"
"int i = 0;"
"while (i < 10) sk_FragColor *= 0.5;"
- "do { sk_FragColor += 0.01; } while (sk_FragColor.x < 0.75);"
+ "do { sk_FragColor += 0.01; } while (sk_FragColor.x < 0.7);"
"for (int i = 0; i < 10; i++) {"
"if (i % 0 == 1) break; else continue;"
"}"
@@ -66,7 +65,7 @@ DEF_TEST(SkSLControl, r) {
" while (i < 10) sk_FragColor *= 0.5;\n"
" do {\n"
" sk_FragColor += 0.01;\n"
- " } while (sk_FragColor.x < 0.75);\n"
+ " } while (sk_FragColor.x < 0.7);\n"
" for (int i = 0;i < 10; i++) {\n"
" if (i % 0 == 1) break; else continue;\n"
" }\n"