skslc can now be compiled with no Skia dependencies, in preparation for its eventual

role in Skia's build process.

This reverts commit bcf35f86d5.

BUG=skia:

Change-Id: Id0a12dfc4d804d69a3c6bf60fed37e89ee130f02
Reviewed-on: https://skia-review.googlesource.com/10802
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ben Wagner <benjaminwagner@google.com>
This commit is contained in:
Ethan Nicholas 2017-03-31 09:33:41 -04:00 committed by Skia Commit-Bot
parent 66b09abdb1
commit f3333c89bf
121 changed files with 1801 additions and 1294 deletions

View File

@ -1484,13 +1484,12 @@ if (skia_enable_tools) {
if (skia_enable_gpu) {
test_app("skslc") {
defines = [ "SKSL_STANDALONE" ]
sources = [
"src/sksl/SkSLMain.cpp",
]
deps = [
":flags",
":skia",
]
sources += skia_sksl_sources
include_dirs = [ "src/sksl" ]
}
}
}

View File

@ -67,7 +67,7 @@ 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;
SkSL::String glsl;
SkSL::Program::Settings settings;
settings.fCaps = context->caps()->shaderCaps();
std::unique_ptr<SkSL::Program> program = context->compiler()->convertProgram(

View File

@ -558,7 +558,7 @@ static void fuzz_filter_fuzz(sk_sp<SkData> bytes) {
#if SK_SUPPORT_GPU
static void fuzz_sksl2glsl(sk_sp<SkData> bytes) {
SkSL::Compiler compiler;
SkString output;
SkSL::String output;
SkSL::Program::Settings settings;
sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
settings.fCaps = caps.get();

View File

@ -13,6 +13,7 @@ skia_sksl_sources = [
"$_src/sksl/SkSLParser.cpp",
"$_src/sksl/SkSLGLSLCodeGenerator.cpp",
"$_src/sksl/SkSLSPIRVCodeGenerator.cpp",
"$_src/sksl/SkSLString.cpp",
"$_src/sksl/SkSLUtil.cpp",
"$_src/sksl/lex.layout.cpp",
"$_src/sksl/ir/SkSLSymbolTable.cpp",

View File

@ -48,7 +48,7 @@ GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
}
#endif
SkString glsl;
SkSL::String glsl;
if (type == GR_GL_VERTEX_SHADER || type == GR_GL_FRAGMENT_SHADER) {
SkSL::Compiler& compiler = *glCtx.compiler();
std::unique_ptr<SkSL::Program> program;

View File

@ -283,7 +283,7 @@ bool GrCompileVkShaderModule(const GrVkGpu* gpu,
SkASSERT(false);
}
*outInputs = program->fInputs;
SkString code;
SkSL::String code;
if (!gpu->shaderCompiler()->toSPIRV(*program, &code)) {
SkDebugf("%s\n", gpu->shaderCompiler()->errorText().c_str());
return false;

View File

@ -1,7 +1,7 @@
Overview
========
SkSL ("Skia Shading Language") is a variant of GLSL which is used as Skia's
SkSL ("Skia Shading Language") is a variant of GLSL which is used as Skia's
internal shading language. SkSL is, at its heart, a single standardized version
of GLSL which avoids all of the various version and dialect differences found
in GLSL "in the wild", but it does bring a few of its own changes to the table.
@ -15,7 +15,7 @@ Differences from GLSL
SkSL is based on GLSL 4.5. For the most part, write SkSL exactly as you would
desktop GLSL, and the SkSL compiler will take care of version and dialect
differences (for instance, you always use "in" and "out", and skslc will handle
translating them to "varying" and "attribute" as appropriate). Be aware of the
translating them to "varying" and "attribute" as appropriate). Be aware of the
following differences between SkSL and GLSL:
* GLSL caps can be referenced via the syntax 'sk_Caps.<name>', e.g.
@ -36,11 +36,11 @@ following differences between SkSL and GLSL:
* use sk_VertexID instead of gl_VertexID
* the fragment coordinate is sk_FragCoord, and is always relative to the upper
left.
* lowp, mediump, and highp are always permitted (but will only be respected if
* lowp, mediump, and highp are always permitted (but will only be respected if
you run on a device which supports them)
* you do not need to include ".0" to make a number a float (meaning that
"vec2(x, y) * 4" is perfectly legal in SkSL, unlike GLSL where it would often
have to be expressed "vec2(x, y) * 4.0". There is no performance penalty for
have to be expressed "vec2(x, y) * 4.0". There is no performance penalty for
this, as the number is converted to a float at compile time)
* type suffixes on numbers (1.0f, 0xFFu) are both unnecessary and unsupported
* creating a smaller vector from a larger vector (e.g. vec2(vec3(1))) is

View File

@ -4,7 +4,7 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkSLCFGGenerator.h"
#include "ir/SkSLConstructor.h"

View File

@ -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_CFGGENERATOR
#define SKSL_CFGGENERATOR

View File

@ -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_CODEGENERATOR
#define SKSL_CODEGENERATOR
@ -18,7 +18,7 @@ namespace SkSL {
*/
class CodeGenerator {
public:
CodeGenerator(const Program* program, ErrorReporter* errors, SkWStream* out)
CodeGenerator(const Program* program, ErrorReporter* errors, OutputStream* out)
: fProgram(*program)
, fErrors(*errors)
, fOut(out) {}
@ -31,7 +31,7 @@ protected:
const Program& fProgram;
ErrorReporter& fErrors;
SkWStream* fOut;
OutputStream* fOut;
};
} // namespace

View File

@ -19,7 +19,6 @@
#include "ir/SkSLSymbolTable.h"
#include "ir/SkSLUnresolvedFunction.h"
#include "ir/SkSLVarDeclarations.h"
#include "SkMutex.h"
#ifdef SK_ENABLE_SPIRV_VALIDATION
#include "spirv-tools/libspirv.hpp"
@ -77,17 +76,17 @@ Compiler::Compiler()
ADD_TYPE(BVec3);
ADD_TYPE(BVec4);
ADD_TYPE(Mat2x2);
types->addWithoutOwnership(SkString("mat2x2"), fContext.fMat2x2_Type.get());
types->addWithoutOwnership(String("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(String("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(String("mat4x4"), fContext.fMat4x4_Type.get());
ADD_TYPE(GenType);
ADD_TYPE(GenDType);
ADD_TYPE(GenIType);
@ -147,14 +146,14 @@ Compiler::Compiler()
ADD_TYPE(GSampler2DArrayShadow);
ADD_TYPE(GSamplerCubeArrayShadow);
SkString skCapsName("sk_Caps");
Variable* skCaps = new Variable(Position(), Modifiers(), skCapsName,
String skCapsName("sk_Caps");
Variable* skCaps = new Variable(Position(), Modifiers(), skCapsName,
*fContext.fSkCaps_Type, Variable::kGlobal_Storage);
fIRGenerator->fSymbolTable->add(skCapsName, std::unique_ptr<Symbol>(skCaps));
Modifiers::Flag ignored1;
std::vector<std::unique_ptr<ProgramElement>> ignored2;
this->internalConvertProgram(SkString(SKSL_INCLUDE), &ignored1, &ignored2);
this->internalConvertProgram(String(SKSL_INCLUDE), &ignored1, &ignored2);
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
ASSERT(!fErrorCount);
}
@ -351,7 +350,7 @@ void Compiler::scanCFG(const FunctionDefinition& f) {
p = (*cfg.fBlocks[i].fNodes[0].fExpression)->fPosition;
break;
}
this->error(p, SkString("unreachable"));
this->error(p, String("unreachable"));
}
}
if (fErrorCount) {
@ -389,12 +388,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, String("function can exit without returning a value"));
}
}
}
void Compiler::internalConvertProgram(SkString text,
void Compiler::internalConvertProgram(String text,
Modifiers::Flag* defaultPrecision,
std::vector<std::unique_ptr<ProgramElement>>* result) {
Parser parser(text, *fTypes, *this);
@ -457,7 +456,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, String text,
const Program::Settings& settings) {
fErrorText = "";
fErrorCount = 0;
@ -466,13 +465,13 @@ 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(String(SKSL_VERT_INCLUDE), &ignored, &elements);
break;
case Program::kFragment_Kind:
this->internalConvertProgram(SkString(SKSL_FRAG_INCLUDE), &ignored, &elements);
this->internalConvertProgram(String(SKSL_FRAG_INCLUDE), &ignored, &elements);
break;
case Program::kGeometry_Kind:
this->internalConvertProgram(SkString(SKSL_GEOM_INCLUDE), &ignored, &elements);
this->internalConvertProgram(String(SKSL_GEOM_INCLUDE), &ignored, &elements);
break;
}
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
@ -490,23 +489,22 @@ std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, SkString t
return result;
}
bool Compiler::toSPIRV(const Program& program, SkWStream& out) {
bool Compiler::toSPIRV(const Program& program, OutputStream& out) {
#ifdef SK_ENABLE_SPIRV_VALIDATION
SkDynamicMemoryWStream buffer;
StringStream buffer;
SPIRVCodeGenerator cg(&fContext, &program, this, &buffer);
bool result = cg.generateCode();
if (result) {
sk_sp<SkData> data(buffer.detachAsData());
spvtools::SpirvTools tools(SPV_ENV_VULKAN_1_0);
SkASSERT(0 == data->size() % 4);
ASSERT(0 == buffer.size() % 4);
auto dumpmsg = [](spv_message_level_t, const char*, const spv_position_t&, const char* m) {
SkDebugf("SPIR-V validation error: %s\n", m);
};
tools.SetMessageConsumer(dumpmsg);
// Verify that the SPIR-V we produced is valid. If this assert fails, check the logs prior
// to the failure to see the validation errors.
SkAssertResult(tools.Validate((const uint32_t*) data->data(), data->size() / 4));
out.write(data->data(), data->size());
ASSERT_RESULT(tools.Validate((const uint32_t*) buffer.data(), buffer.size() / 4));
out.write(buffer.data(), buffer.size());
}
#else
SPIRVCodeGenerator cg(&fContext, &program, this, &out);
@ -516,41 +514,39 @@ bool Compiler::toSPIRV(const Program& program, SkWStream& out) {
return result;
}
bool Compiler::toSPIRV(const Program& program, SkString* out) {
SkDynamicMemoryWStream buffer;
bool Compiler::toSPIRV(const Program& program, String* out) {
StringStream buffer;
bool result = this->toSPIRV(program, buffer);
if (result) {
sk_sp<SkData> data(buffer.detachAsData());
*out = SkString((const char*) data->data(), data->size());
*out = String(buffer.data(), buffer.size());
}
return result;
}
bool Compiler::toGLSL(const Program& program, SkWStream& out) {
bool Compiler::toGLSL(const Program& program, OutputStream& out) {
GLSLCodeGenerator cg(&fContext, &program, this, &out);
bool result = cg.generateCode();
this->writeErrorCount();
return result;
}
bool Compiler::toGLSL(const Program& program, SkString* out) {
SkDynamicMemoryWStream buffer;
bool Compiler::toGLSL(const Program& program, String* out) {
StringStream buffer;
bool result = this->toGLSL(program, buffer);
if (result) {
sk_sp<SkData> data(buffer.detachAsData());
*out = SkString((const char*) data->data(), data->size());
*out = String(buffer.data(), buffer.size());
}
return result;
}
void Compiler::error(Position position, SkString msg) {
void Compiler::error(Position position, String msg) {
fErrorCount++;
fErrorText += "error: " + position.description() + ": " + msg.c_str() + "\n";
}
SkString Compiler::errorText() {
SkString result = fErrorText;
String Compiler::errorText() {
String result = fErrorText;
return result;
}

View File

@ -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_COMPILER
#define SKSL_COMPILER
@ -42,20 +42,20 @@ public:
~Compiler() override;
std::unique_ptr<Program> convertProgram(Program::Kind kind, SkString text,
std::unique_ptr<Program> convertProgram(Program::Kind kind, String text,
const Program::Settings& settings);
bool toSPIRV(const Program& program, SkWStream& out);
bool toSPIRV(const Program& program, OutputStream& out);
bool toSPIRV(const Program& program, SkString* out);
bool toSPIRV(const Program& program, String* out);
bool toGLSL(const Program& program, SkWStream& out);
bool toGLSL(const Program& program, OutputStream& out);
bool toGLSL(const Program& program, SkString* out);
bool toGLSL(const Program& program, String* out);
void error(Position position, SkString msg) override;
void error(Position position, String msg) override;
SkString errorText();
String errorText();
void writeErrorCount();
@ -73,17 +73,17 @@ private:
void scanCFG(const FunctionDefinition& f);
void internalConvertProgram(SkString text,
void internalConvertProgram(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
String fSkiaVertText; // FIXME store parsed version instead
Context fContext;
int fErrorCount;
SkString fErrorText;
String fErrorText;
};
} // namespace

View File

@ -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_CONTEXT
#define SKSL_CONTEXT
@ -19,114 +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(),
: fInvalid_Type(new Type(String("<INVALID>")))
, fVoid_Type(new Type(String("void")))
, fDouble_Type(new Type(String("double"), true))
, fDVec2_Type(new Type(String("dvec2"), *fDouble_Type, 2))
, fDVec3_Type(new Type(String("dvec3"), *fDouble_Type, 3))
, fDVec4_Type(new Type(String("dvec4"), *fDouble_Type, 4))
, fFloat_Type(new Type(String("float"), true, { fDouble_Type.get() }))
, fVec2_Type(new Type(String("vec2"), *fFloat_Type, 2))
, fVec3_Type(new Type(String("vec3"), *fFloat_Type, 3))
, fVec4_Type(new Type(String("vec4"), *fFloat_Type, 4))
, fUInt_Type(new Type(String("uint"), true, { fFloat_Type.get(), fDouble_Type.get() }))
, fUVec2_Type(new Type(String("uvec2"), *fUInt_Type, 2))
, fUVec3_Type(new Type(String("uvec3"), *fUInt_Type, 3))
, fUVec4_Type(new Type(String("uvec4"), *fUInt_Type, 4))
, fInt_Type(new Type(String("int"), true, { fUInt_Type.get(), fFloat_Type.get(),
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,
, fIVec2_Type(new Type(String("ivec2"), *fInt_Type, 2))
, fIVec3_Type(new Type(String("ivec3"), *fInt_Type, 3))
, fIVec4_Type(new Type(String("ivec4"), *fInt_Type, 4))
, fBool_Type(new Type(String("bool"), false))
, fBVec2_Type(new Type(String("bvec2"), *fBool_Type, 2))
, fBVec3_Type(new Type(String("bvec3"), *fBool_Type, 3))
, fBVec4_Type(new Type(String("bvec4"), *fBool_Type, 4))
, fMat2x2_Type(new Type(String("mat2"), *fFloat_Type, 2, 2))
, fMat2x3_Type(new Type(String("mat2x3"), *fFloat_Type, 2, 3))
, fMat2x4_Type(new Type(String("mat2x4"), *fFloat_Type, 2, 4))
, fMat3x2_Type(new Type(String("mat3x2"), *fFloat_Type, 3, 2))
, fMat3x3_Type(new Type(String("mat3"), *fFloat_Type, 3, 3))
, fMat3x4_Type(new Type(String("mat3x4"), *fFloat_Type, 3, 4))
, fMat4x2_Type(new Type(String("mat4x2"), *fFloat_Type, 4, 2))
, fMat4x3_Type(new Type(String("mat4x3"), *fFloat_Type, 4, 3))
, fMat4x4_Type(new Type(String("mat4"), *fFloat_Type, 4, 4))
, fDMat2x2_Type(new Type(String("dmat2"), *fFloat_Type, 2, 2))
, fDMat2x3_Type(new Type(String("dmat2x3"), *fFloat_Type, 2, 3))
, fDMat2x4_Type(new Type(String("dmat2x4"), *fFloat_Type, 2, 4))
, fDMat3x2_Type(new Type(String("dmat3x2"), *fFloat_Type, 3, 2))
, fDMat3x3_Type(new Type(String("dmat3"), *fFloat_Type, 3, 3))
, fDMat3x4_Type(new Type(String("dmat3x4"), *fFloat_Type, 3, 4))
, fDMat4x2_Type(new Type(String("dmat4x2"), *fFloat_Type, 4, 2))
, fDMat4x3_Type(new Type(String("dmat4x3"), *fFloat_Type, 4, 3))
, fDMat4x4_Type(new Type(String("dmat4"), *fFloat_Type, 4, 4))
, fSampler1D_Type(new Type(String("sampler1D"), SpvDim1D, false, false, false, true))
, fSampler2D_Type(new Type(String("sampler2D"), SpvDim2D, false, false, false, true))
, fSampler3D_Type(new Type(String("sampler3D"), SpvDim3D, false, false, false, true))
, fSamplerExternalOES_Type(new Type(String("samplerExternalOES"), SpvDim2D, false, false,
false, true))
, fSamplerCube_Type(new Type(SkString("samplerCube"), SpvDimCube, false, false, false, true))
, fSampler2DRect_Type(new Type(SkString("sampler2DRect"), SpvDimRect, false, false, false,
, fSamplerCube_Type(new Type(String("samplerCube"), SpvDimCube, false, false, false, true))
, fSampler2DRect_Type(new Type(String("sampler2DRect"), SpvDimRect, false, false, false,
true))
, 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")))
, fSampler1DArray_Type(new Type(String("sampler1DArray")))
, fSampler2DArray_Type(new Type(String("sampler2DArray")))
, fSamplerCubeArray_Type(new Type(String("samplerCubeArray")))
, fSamplerBuffer_Type(new Type(String("samplerBuffer")))
, fSampler2DMS_Type(new Type(String("sampler2DMS")))
, fSampler2DMSArray_Type(new Type(String("sampler2DMSArray")))
, fSampler1DShadow_Type(new Type(String("sampler1DShadow")))
, fSampler2DShadow_Type(new Type(String("sampler2DShadow")))
, fSamplerCubeShadow_Type(new Type(String("samplerCubeShadow")))
, fSampler2DRectShadow_Type(new Type(String("sampler2DRectShadow")))
, fSampler1DArrayShadow_Type(new Type(String("sampler1DArrayShadow")))
, fSampler2DArrayShadow_Type(new Type(String("sampler2DArrayShadow")))
, fSamplerCubeArrayShadow_Type(new Type(String("samplerCubeArrayShadow")))
// 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(String("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(String("image2D"), SpvDim2D, false, false, false, true))
, fIImage2D_Type(new Type(String("iimage2D"), SpvDim2D, false, false, false, true))
// FIXME express these as "gsubpassInput" that expand to subpassInput, isubpassInput,
// and usubpassInput.
, fSubpassInput_Type(new Type(SkString("subpassInput"), SpvDimSubpassData, false, false,
, fSubpassInput_Type(new Type(String("subpassInput"), SpvDimSubpassData, false, false,
false, false))
, fSubpassInputMS_Type(new Type(SkString("subpassInputMS"), SpvDimSubpassData, false, false,
, fSubpassInputMS_Type(new Type(String("subpassInputMS"), SpvDimSubpassData, false, false,
true, false))
// FIXME figure out what we're supposed to do with the gsampler et al. types)
, fGSampler1D_Type(new Type(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"),
, fGSampler1D_Type(new Type(String("$gsampler1D"), static_type(*fSampler1D_Type)))
, fGSampler2D_Type(new Type(String("$gsampler2D"), static_type(*fSampler2D_Type)))
, fGSampler3D_Type(new Type(String("$gsampler3D"), static_type(*fSampler3D_Type)))
, fGSamplerCube_Type(new Type(String("$gsamplerCube"), static_type(*fSamplerCube_Type)))
, fGSampler2DRect_Type(new Type(String("$gsampler2DRect"), static_type(*fSampler2DRect_Type)))
, fGSampler1DArray_Type(new Type(String("$gsampler1DArray"),
static_type(*fSampler1DArray_Type)))
, fGSampler2DArray_Type(new Type(SkString("$gsampler2DArray"),
, fGSampler2DArray_Type(new Type(String("$gsampler2DArray"),
static_type(*fSampler2DArray_Type)))
, fGSamplerCubeArray_Type(new Type(SkString("$gsamplerCubeArray"),
, fGSamplerCubeArray_Type(new Type(String("$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"),
, fGSamplerBuffer_Type(new Type(String("$gsamplerBuffer"), static_type(*fSamplerBuffer_Type)))
, fGSampler2DMS_Type(new Type(String("$gsampler2DMS"), static_type(*fSampler2DMS_Type)))
, fGSampler2DMSArray_Type(new Type(String("$gsampler2DMSArray"),
static_type(*fSampler2DMSArray_Type)))
, fGSampler2DArrayShadow_Type(new Type(SkString("$gsampler2DArrayShadow"),
, fGSampler2DArrayShadow_Type(new Type(String("$gsampler2DArrayShadow"),
static_type(*fSampler2DArrayShadow_Type)))
, fGSamplerCubeArrayShadow_Type(new Type(SkString("$gsamplerCubeArrayShadow"),
, fGSamplerCubeArrayShadow_Type(new Type(String("$gsamplerCubeArrayShadow"),
static_type(*fSamplerCubeArrayShadow_Type)))
, fGenType_Type(new Type(SkString("$genType"), { fFloat_Type.get(), fVec2_Type.get(),
, fGenType_Type(new Type(String("$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(),
, fGenDType_Type(new Type(String("$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(),
, fGenIType_Type(new Type(String("$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(),
, fGenUType_Type(new Type(String("$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(),
, fGenBType_Type(new Type(String("$genBType"), { fBool_Type.get(), fBVec2_Type.get(),
fBVec3_Type.get(), fBVec4_Type.get() }))
, fMat_Type(new Type(SkString("$mat"), { fMat2x2_Type.get(), fMat2x3_Type.get(),
, fMat_Type(new Type(String("$mat"), { fMat2x2_Type.get(), fMat2x3_Type.get(),
fMat2x4_Type.get(), fMat3x2_Type.get(),
fMat3x3_Type.get(), fMat3x4_Type.get(),
fMat4x2_Type.get(), fMat4x3_Type.get(),
@ -135,21 +135,21 @@ public:
fDMat3x2_Type.get(), fDMat3x3_Type.get(),
fDMat3x4_Type.get(), fDMat4x2_Type.get(),
fDMat4x3_Type.get(), fDMat4x4_Type.get() }))
, fVec_Type(new Type(SkString("$vec"), { fInvalid_Type.get(), fVec2_Type.get(),
, fVec_Type(new Type(String("$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(),
, fGVec_Type(new Type(String("$gvec")))
, fGVec2_Type(new Type(String("$gvec2")))
, fGVec3_Type(new Type(String("$gvec3")))
, fGVec4_Type(new Type(String("$gvec4"), static_type(*fVec4_Type)))
, fDVec_Type(new Type(String("$dvec"), { fInvalid_Type.get(), fDVec2_Type.get(),
fDVec3_Type.get(), fDVec4_Type.get() }))
, fIVec_Type(new Type(SkString("$ivec"), { fInvalid_Type.get(), fIVec2_Type.get(),
, fIVec_Type(new Type(String("$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(),
, fUVec_Type(new Type(String("$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(),
, fBVec_Type(new Type(String("$bvec"), { fInvalid_Type.get(), fBVec2_Type.get(),
fBVec3_Type.get(), fBVec4_Type.get() }))
, fSkCaps_Type(new Type(SkString("$sk_Caps")))
, fSkCaps_Type(new Type(String("$sk_Caps")))
, fDefined_Expression(new Defined(*fInvalid_Type)) {}
static std::vector<const Type*> static_type(const Type& t) {
@ -269,19 +269,19 @@ public:
const std::unique_ptr<Type> fSkCaps_Type;
// dummy expression used to mark that a variable has a value during dataflow analysis (when it
// dummy expression used to mark that a variable has a value during dataflow analysis (when it
// could have several different values, or the analyzer is otherwise unable to assign it a
// specific expression)
const std::unique_ptr<Expression> fDefined_Expression;
private:
private:
class Defined : public Expression {
public:
Defined(const Type& type)
: INHERITED(Position(), kDefined_Kind, type) {}
virtual SkString description() const override {
return SkString("<defined>");
virtual String description() const override {
return String("<defined>");
}
typedef Expression INHERITED;

View File

@ -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_ERRORREPORTER
#define SKSL_ERRORREPORTER
@ -20,10 +20,10 @@ public:
virtual ~ErrorReporter() {}
void error(Position position, const char* msg) {
this->error(position, SkString(msg));
this->error(position, String(msg));
}
virtual void error(Position position, SkString msg) = 0;
virtual void error(Position position, String msg) = 0;
virtual int errorCount() = 0;
};

View File

@ -0,0 +1,75 @@
/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKSL_FILEOUTPUTSTREAM
#define SKSL_FILEOUTPUTSTREAM
#include "SkSLOutputStream.h"
#include <stdio.h>
namespace SkSL {
class FileOutputStream : public OutputStream {
public:
FileOutputStream(const char* name) {
fFile = fopen(name, "w");
}
~FileOutputStream() {
ASSERT(!fOpen);
}
bool isValid() const override {
return nullptr != fFile;
}
void write8(uint8_t b) override {
ASSERT(fOpen);
if (isValid()) {
if (EOF == fputc(b, fFile)) {
fFile = nullptr;
}
}
}
void writeText(const char* s) override {
ASSERT(fOpen);
if (isValid()) {
if (EOF == fputs(s, fFile)) {
fFile = nullptr;
}
}
}
void write(const void* s, size_t size) override {
if (isValid()) {
size_t written = fwrite(s, 1, size, fFile);
if (written != size) {
fFile = nullptr;
}
}
}
bool close() {
fOpen = false;
if (isValid() && fclose(fFile)) {
fFile = nullptr;
return false;
}
return true;
}
private:
bool fOpen = true;
FILE *fFile;
typedef OutputStream INHERITED;
};
} // namespace
#endif

View File

@ -7,8 +7,6 @@
#include "SkSLGLSLCodeGenerator.h"
#include "string.h"
#include "GLSL.std.450.h"
#include "SkSLCompiler.h"
@ -35,15 +33,15 @@ void GLSLCodeGenerator::write(const char* s) {
void GLSLCodeGenerator::writeLine(const char* s) {
this->write(s);
fOut->writeText("\n");
fOut->write8('\n');
fAtLineStart = true;
}
void GLSLCodeGenerator::write(const SkString& s) {
void GLSLCodeGenerator::write(const String& s) {
this->write(s.c_str());
}
void GLSLCodeGenerator::writeLine(const SkString& s) {
void GLSLCodeGenerator::writeLine(const String& s) {
this->writeLine(s.c_str());
}
@ -137,8 +135,8 @@ static bool is_abs(Expression& expr) {
// Tegra3 compiler bug.
void GLSLCodeGenerator::writeMinAbsHack(Expression& absExpr, Expression& otherExpr) {
ASSERT(!fProgram.fSettings.fCaps->canUseMinAndAbsTogether());
SkString tmpVar1 = "minAbsHackVar" + to_string(fVarCount++);
SkString tmpVar2 = "minAbsHackVar" + to_string(fVarCount++);
String tmpVar1 = "minAbsHackVar" + to_string(fVarCount++);
String tmpVar2 = "minAbsHackVar" + to_string(fVarCount++);
this->fFunctionHeader += " " + absExpr.fType.name() + " " + tmpVar1 + ";\n";
this->fFunctionHeader += " " + otherExpr.fType.name() + " " + tmpVar2 + ";\n";
this->write("((" + tmpVar1 + " = ");
@ -411,7 +409,7 @@ static GLSLCodeGenerator::Precedence get_binary_precedence(Token::Kind op) {
}
}
void GLSLCodeGenerator::writeBinaryExpression(const BinaryExpression& b,
void GLSLCodeGenerator::writeBinaryExpression(const BinaryExpression& b,
Precedence parentPrecedence) {
Precedence precedence = get_binary_precedence(b.fOperator);
if (precedence >= parentPrecedence) {
@ -425,7 +423,7 @@ void GLSLCodeGenerator::writeBinaryExpression(const BinaryExpression& b,
}
}
void GLSLCodeGenerator::writeTernaryExpression(const TernaryExpression& t,
void GLSLCodeGenerator::writeTernaryExpression(const TernaryExpression& t,
Precedence parentPrecedence) {
if (kTernary_Precedence >= parentPrecedence) {
this->write("(");
@ -440,7 +438,7 @@ void GLSLCodeGenerator::writeTernaryExpression(const TernaryExpression& t,
}
}
void GLSLCodeGenerator::writePrefixExpression(const PrefixExpression& p,
void GLSLCodeGenerator::writePrefixExpression(const PrefixExpression& p,
Precedence parentPrecedence) {
if (kPrefix_Precedence >= parentPrecedence) {
this->write("(");
@ -452,7 +450,7 @@ void GLSLCodeGenerator::writePrefixExpression(const PrefixExpression& p,
}
}
void GLSLCodeGenerator::writePostfixExpression(const PostfixExpression& p,
void GLSLCodeGenerator::writePostfixExpression(const PostfixExpression& p,
Precedence parentPrecedence) {
if (kPostfix_Precedence >= parentPrecedence) {
this->write("(");
@ -507,8 +505,8 @@ void GLSLCodeGenerator::writeFunction(const FunctionDefinition& f) {
this->writeLine(") {");
fFunctionHeader = "";
SkWStream* oldOut = fOut;
SkDynamicMemoryWStream buffer;
OutputStream* oldOut = fOut;
StringStream buffer;
fOut = &buffer;
fIndentation++;
for (const auto& s : f.fBody->fStatements) {
@ -520,8 +518,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(String(buffer.data(), buffer.size()));
}
void GLSLCodeGenerator::writeModifiers(const Modifiers& modifiers,
@ -532,7 +529,7 @@ void GLSLCodeGenerator::writeModifiers(const Modifiers& modifiers,
if (modifiers.fFlags & Modifiers::kNoPerspective_Flag) {
this->write("noperspective ");
}
SkString layout = modifiers.fLayout.description();
String layout = modifiers.fLayout.description();
if (layout.size()) {
this->write(layout + " ");
}
@ -625,11 +622,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(" ");
String separator(" ");
for (const auto& var : decl.fVars) {
ASSERT(var.fVar->fModifiers == decl.fVars[0].fVar->fModifiers);
this->write(separator);
separator = SkString(", ");
separator = String(", ");
this->write(var.fVar->fName);
for (const auto& size : var.fSizes) {
this->write("[");
@ -663,7 +660,7 @@ void GLSLCodeGenerator::writeStatement(const Statement& s) {
this->writeExpression(*((ExpressionStatement&) s).fExpression, kTopLevel_Precedence);
this->write(";");
break;
case Statement::kReturn_Kind:
case Statement::kReturn_Kind:
this->writeReturnStatement((ReturnStatement&) s);
break;
case Statement::kVarDeclarations_Kind:
@ -787,7 +784,7 @@ void GLSLCodeGenerator::writeReturnStatement(const ReturnStatement& r) {
}
bool GLSLCodeGenerator::generateCode() {
SkWStream* rawOut = fOut;
OutputStream* rawOut = fOut;
fOut = &fHeader;
fProgramKind = fProgram.fKind;
this->write(fProgram.fSettings.fCaps->versionDeclString());
@ -797,7 +794,7 @@ bool GLSLCodeGenerator::generateCode() {
this->writeExtension((Extension&) *e);
}
}
SkDynamicMemoryWStream body;
StringStream body;
fOut = &body;
if (fProgram.fSettings.fCaps->usesPrecisionModifiers()) {
this->write("precision ");
@ -857,8 +854,8 @@ bool GLSLCodeGenerator::generateCode() {
}
fOut = nullptr;
write_data(*fHeader.detachAsData(), *rawOut);
write_data(*body.detachAsData(), *rawOut);
write_stringstream(fHeader, *rawOut);
write_stringstream(body, *rawOut);
return true;
}

View File

@ -12,7 +12,6 @@
#include <tuple>
#include <unordered_map>
#include "SkStream.h"
#include "SkSLCodeGenerator.h"
#include "ir/SkSLBinaryExpression.h"
#include "ir/SkSLBoolLiteral.h"
@ -73,7 +72,7 @@ public:
};
GLSLCodeGenerator(const Context* context, const Program* program, ErrorReporter* errors,
SkWStream* out)
OutputStream* out)
: INHERITED(program, errors, out)
, fContext(*context) {}
@ -86,9 +85,9 @@ private:
void writeLine(const char* s);
void write(const SkString& s);
void write(const String& s);
void writeLine(const SkString& s);
void writeLine(const String& s);
void writeType(const Type& type);
@ -97,7 +96,7 @@ private:
void writeInterfaceBlock(const InterfaceBlock& intf);
void writeFunctionStart(const FunctionDeclaration& f);
void writeFunctionDeclaration(const FunctionDeclaration& f);
void writeFunction(const FunctionDefinition& f);
@ -161,8 +160,8 @@ private:
void writeReturnStatement(const ReturnStatement& r);
const Context& fContext;
SkDynamicMemoryWStream fHeader;
SkString fFunctionHeader;
StringStream fHeader;
String fFunctionHeader;
Program::Kind fProgramKind;
int fVarCount = 0;
int fIndentation = 0;

View File

@ -115,8 +115,8 @@ void IRGenerator::popSymbolTable() {
fSymbolTable = fSymbolTable->fParent;
}
static void fill_caps(const GrShaderCaps& caps, std::unordered_map<SkString, CapValue>* capsMap) {
#define CAP(name) capsMap->insert(std::make_pair(SkString(#name), CapValue(caps.name())));
static void fill_caps(const SKSL_CAPS_CLASS& caps, std::unordered_map<String, CapValue>* capsMap) {
#define CAP(name) capsMap->insert(std::make_pair(String(#name), CapValue(caps.name())));
CAP(fbFetchSupport);
CAP(fbFetchNeedsCustomOutput);
CAP(bindlessTextureSupport);
@ -224,7 +224,7 @@ std::unique_ptr<VarDeclarations> IRGenerator::convertVarDeclarations(const ASTVa
if (!size) {
return nullptr;
}
SkString name = type->fName;
String name = type->fName;
int64_t count;
if (size->fKind == Expression::kIntLiteral_Kind) {
count = ((IntLiteral&) *size).fValue;
@ -255,7 +255,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 && varDecl.fName == String("sk_FragColor") &&
(*fSymbolTable)[varDecl.fName]) {
// already defined, ignore
} else if (storage == Variable::kGlobal_Storage && (*fSymbolTable)[varDecl.fName] &&
@ -501,12 +501,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) + "]";
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;
String name = param->fName;
Position pos = param->fPosition;
Variable* var = new Variable(pos, param->fModifiers, std::move(name), *type,
Variable::kParameter_Storage);
@ -632,7 +632,7 @@ std::unique_ptr<InterfaceBlock> IRGenerator::convertInterfaceBlock(const ASTInte
if (!converted) {
return nullptr;
}
SkString name = type->fName;
String name = type->fName;
int64_t count;
if (converted->fKind == Expression::kIntLiteral_Kind) {
count = ((IntLiteral&) *converted).fValue;
@ -677,7 +677,7 @@ const Type* IRGenerator::convertType(const ASTType& type) {
const Symbol* result = (*fSymbolTable)[type.fName];
if (result && result->fKind == Symbol::kType_Kind) {
for (int size : type.fSizes) {
SkString name = result->fName + "[";
String name = result->fName + "[";
if (size != -1) {
name += to_string(size);
}
@ -1116,7 +1116,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 " +
String msg = "call to '" + function.fName + "' expected " +
to_string((uint64_t) function.fParameters.size()) +
" argument";
if (function.fParameters.size() != 1) {
@ -1129,8 +1129,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;
String msg = "no match for " + function.fName + "(";
String separator;
for (size_t i = 0; i < arguments.size(); i++) {
msg += separator;
separator = ", ";
@ -1208,8 +1208,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;
String msg = "no match for " + ref->fFunctions[0]->fName + "(";
String separator;
for (size_t i = 0; i < arguments.size(); i++) {
msg += separator;
separator = ", ";
@ -1466,7 +1466,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 String& field) {
auto fields = base->fType.fields();
for (size_t i = 0; i < fields.size(); i++) {
if (fields[i].fName == field) {
@ -1479,7 +1479,7 @@ 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 String& fields) {
if (base->fType.kind() != Type::kVector_Kind) {
fErrors.error(base->fPosition, "cannot swizzle type '" + base->fType.description() + "'");
return nullptr;
@ -1517,7 +1517,7 @@ std::unique_ptr<Expression> IRGenerator::convertSwizzle(std::unique_ptr<Expressi
}
// fall through
default:
fErrors.error(base->fPosition, SkStringPrintf("invalid swizzle component '%c'",
fErrors.error(base->fPosition, String::printf("invalid swizzle component '%c'",
fields[i]));
return nullptr;
}
@ -1530,7 +1530,7 @@ std::unique_ptr<Expression> IRGenerator::convertSwizzle(std::unique_ptr<Expressi
return std::unique_ptr<Expression>(new Swizzle(fContext, std::move(base), swizzleComponents));
}
std::unique_ptr<Expression> IRGenerator::getCap(Position position, SkString name) {
std::unique_ptr<Expression> IRGenerator::getCap(Position position, String name) {
auto found = fCapsMap.find(name);
if (found == fCapsMap.end()) {
fErrors.error(position, "unknown capability flag '" + name + "'");

View File

@ -154,12 +154,12 @@ private:
Modifiers convertModifiers(const Modifiers& m);
std::unique_ptr<Expression> convertPrefixExpression(const ASTPrefixExpression& expression);
std::unique_ptr<Statement> convertReturn(const ASTReturnStatement& r);
std::unique_ptr<Expression> getCap(Position position, SkString name);
std::unique_ptr<Expression> getCap(Position position, String name);
std::unique_ptr<Expression> convertSuffixExpression(const ASTSuffixExpression& expression);
std::unique_ptr<Expression> convertField(std::unique_ptr<Expression> base,
const SkString& field);
const String& field);
std::unique_ptr<Expression> convertSwizzle(std::unique_ptr<Expression> base,
const SkString& fields);
const 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);
@ -169,7 +169,7 @@ private:
const FunctionDeclaration* fCurrentFunction;
const Program::Settings* fSettings;
std::unordered_map<SkString, CapValue> fCapsMap;
std::unordered_map<String, CapValue> fCapsMap;
std::shared_ptr<SymbolTable> fSymbolTable;
int fLoopLevel;
int fSwitchLevel;

View File

@ -8,7 +8,7 @@
#include "stdio.h"
#include <fstream>
#include "SkSLCompiler.h"
#include "GrContextOptions.h"
#include "SkSLFileOutputStream.h"
/**
* Very simple standalone executable to facilitate testing.
@ -34,17 +34,15 @@ 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());
SkSL::String text(stdText.c_str());
if (in.rdstate()) {
printf("error reading '%s'\n", argv[1]);
exit(2);
}
SkSL::Program::Settings settings;
sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
settings.fCaps = caps.get();
SkString name(argv[2]);
SkSL::String name(argv[2]);
if (name.endsWith(".spirv")) {
SkFILEWStream out(argv[2]);
SkSL::FileOutputStream out(argv[2]);
SkSL::Compiler compiler;
if (!out.isValid()) {
printf("error writing '%s'\n", argv[2]);
@ -55,8 +53,12 @@ int main(int argc, const char** argv) {
printf("%s", compiler.errorText().c_str());
exit(3);
}
if (!out.close()) {
printf("error writing '%s'\n", argv[2]);
exit(4);
}
} else if (name.endsWith(".glsl")) {
SkFILEWStream out(argv[2]);
SkSL::FileOutputStream out(argv[2]);
SkSL::Compiler compiler;
if (!out.isValid()) {
printf("error writing '%s'\n", argv[2]);
@ -67,6 +69,10 @@ int main(int argc, const char** argv) {
printf("%s", compiler.errorText().c_str());
exit(3);
}
if (!out.close()) {
printf("error writing '%s'\n", argv[2]);
exit(4);
}
} else {
printf("expected output filename to end with '.spirv' or '.glsl'");
}

View File

@ -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 SKIASL_MEMORYLAYOUT
#define SKIASL_MEMORYLAYOUT
@ -19,14 +19,14 @@ public:
k430_Standard
};
MemoryLayout(Standard std)
MemoryLayout(Standard std)
: fStd(std) {}
static size_t vector_alignment(size_t componentSize, int columns) {
return componentSize * (columns + columns % 2);
}
/**
/**
* Rounds up to the nearest multiple of 16 if in std140, otherwise returns the parameter
* unchanged (std140 requires various things to be rounded up to the nearest multiple of 16,
* std430 does not).
@ -50,7 +50,7 @@ public:
case Type::kVector_Kind:
return vector_alignment(this->size(type.componentType()), type.columns());
case Type::kMatrix_Kind:
return this->roundUpIfNeeded(vector_alignment(this->size(type.componentType()),
return this->roundUpIfNeeded(vector_alignment(this->size(type.componentType()),
type.rows()));
case Type::kArray_Kind:
return this->roundUpIfNeeded(this->alignment(type.componentType()));
@ -65,7 +65,7 @@ public:
return this->roundUpIfNeeded(result);
}
default:
ABORT(("cannot determine size of type " + type.name()).c_str());
ABORT("cannot determine size of type %s", type.name().c_str());
}
}
@ -111,12 +111,12 @@ public:
total += this->size(*f.fType);
}
size_t alignment = this->alignment(type);
ASSERT(!type.fields().size() ||
ASSERT(!type.fields().size() ||
(0 == alignment % this->alignment(*type.fields()[0].fType)));
return (total + alignment - 1) & ~(alignment - 1);
}
default:
ABORT(("cannot determine size of type " + type.name()).c_str());
ABORT("cannot determine size of type %s", type.name().c_str());
}
}

View File

@ -0,0 +1,36 @@
/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKSL_OUTPUTSTREAM
#define SKSL_OUTPUTSTREAM
#include "SkSLString.h"
namespace SkSL {
class OutputStream {
public:
virtual bool isValid() const {
return true;
}
virtual void write8(uint8_t b) = 0;
virtual void writeText(const char* s) = 0;
virtual void write(const void* s, size_t size) = 0;
void writeString(String s) {
this->write(s.c_str(), s.size());
}
virtual ~OutputStream() {}
};
} // namespace
#endif

View File

@ -79,7 +79,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, String("exceeded max parse depth"));
return false;
}
return true;
@ -89,8 +89,8 @@ private:
Parser* fParser;
};
Parser::Parser(SkString text, SymbolTable& types, ErrorReporter& errors)
: fPushback(Position(-1, -1), Token::INVALID_TOKEN, SkString())
Parser::Parser(String text, SymbolTable& types, ErrorReporter& errors)
: fPushback(Position(-1, -1), Token::INVALID_TOKEN, String())
, fTypes(types)
, fErrors(errors) {
sksllex_init(&fScanner);
@ -150,17 +150,17 @@ Token Parser::nextToken() {
return result;
}
int token = sksllex(fScanner);
SkString text;
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 = String(skslget_text(fScanner));
break;
default:
#ifdef SK_DEBUG
text = SkString(skslget_text(fScanner));
text = String(skslget_text(fScanner));
#endif
break;
}
@ -179,10 +179,10 @@ Token Parser::peek() {
bool Parser::expect(Token::Kind kind, const char* expected, Token* result) {
return this->expect(kind, SkString(expected), result);
return this->expect(kind, String(expected), result);
}
bool Parser::expect(Token::Kind kind, SkString expected, Token* result) {
bool Parser::expect(Token::Kind kind, String expected, Token* result) {
Token next = this->nextToken();
if (next.fKind == kind) {
if (result) {
@ -201,14 +201,14 @@ bool Parser::expect(Token::Kind kind, SkString expected, Token* result) {
}
void Parser::error(Position p, const char* msg) {
this->error(p, SkString(msg));
this->error(p, String(msg));
}
void Parser::error(Position p, SkString msg) {
void Parser::error(Position p, String msg) {
fErrors.error(p, msg);
}
bool Parser::isType(SkString name) {
bool Parser::isType(String name) {
return nullptr != fTypes[name];
}
@ -380,7 +380,7 @@ std::unique_ptr<ASTType> Parser::structDeclaration() {
return nullptr;
}
uint64_t columns = ((ASTIntLiteral&) *var.fSizes[i]).fValue;
SkString name = type->name() + "[" + to_string(columns) + "]";
String name = type->name() + "[" + to_string(columns) + "]";
type = new Type(name, Type::kArray_Kind, *type, (int) columns);
fTypes.takeOwnership((Type*) type);
}
@ -427,7 +427,7 @@ std::unique_ptr<ASTVarDeclarations> Parser::structVarDeclaration(Modifiers modif
(LBRACKET expression? RBRACKET)* (EQ expression)?)* SEMICOLON */
std::unique_ptr<ASTVarDeclarations> Parser::varDeclarationEnd(Modifiers mods,
std::unique_ptr<ASTType> type,
SkString name) {
String name) {
std::vector<ASTVarDeclaration> vars;
std::vector<std::unique_ptr<ASTExpression>> currentVarSizes;
while (this->peek().fKind == Token::LBRACKET) {
@ -837,7 +837,7 @@ std::unique_ptr<ASTDeclaration> Parser::interfaceBlock(Modifiers mods) {
decls.push_back(std::move(decl));
}
this->nextToken();
SkString instanceName;
String instanceName;
std::vector<std::unique_ptr<ASTExpression>> sizes;
if (this->peek().fKind == Token::IDENTIFIER) {
instanceName = this->nextToken().fText;
@ -1008,7 +1008,7 @@ std::unique_ptr<ASTStatement> Parser::switchStatement() {
// parts of the compiler may rely upon this assumption.
if (this->peek().fKind == Token::DEFAULT) {
Token defaultStart;
SkAssertResult(this->expect(Token::DEFAULT, "'default'", &defaultStart));
ASSERT_RESULT(this->expect(Token::DEFAULT, "'default'", &defaultStart));
if (!this->expect(Token::COLON, "':'")) {
return nullptr;
}
@ -1562,7 +1562,7 @@ std::unique_ptr<ASTSuffix> Parser::suffix() {
}
case Token::DOT: {
Position pos = this->peek().fPosition;
SkString text;
String text;
if (this->identifier(&text)) {
return std::unique_ptr<ASTSuffix>(new ASTFieldSuffix(pos, std::move(text)));
}
@ -1607,7 +1607,7 @@ std::unique_ptr<ASTExpression> Parser::term() {
Token t = this->peek();
switch (t.fKind) {
case Token::IDENTIFIER: {
SkString text;
String text;
if (this->identifier(&text)) {
result.reset(new ASTIdentifier(t.fPosition, std::move(text)));
}
@ -1688,7 +1688,7 @@ bool Parser::boolLiteral(bool* dest) {
}
/* IDENTIFIER */
bool Parser::identifier(SkString* dest) {
bool Parser::identifier(String* dest) {
Token t;
if (this->expect(Token::IDENTIFIER, "identifier", &t)) {
*dest = t.fText;

View File

@ -51,7 +51,7 @@ class SymbolTable;
*/
class Parser {
public:
Parser(SkString text, SymbolTable& types, ErrorReporter& errors);
Parser(String text, SymbolTable& types, ErrorReporter& errors);
~Parser();
@ -90,16 +90,16 @@ private:
* 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, String expected, Token* result = nullptr);
void error(Position p, const char* msg);
void error(Position p, SkString msg);
void error(Position p, 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(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
@ -119,12 +119,12 @@ private:
std::unique_ptr<ASTVarDeclarations> varDeclarationEnd(Modifiers modifiers,
std::unique_ptr<ASTType> type,
SkString name);
String name);
std::unique_ptr<ASTParameter> parameter();
int layoutInt();
Layout layout();
Modifiers modifiers();
@ -164,7 +164,7 @@ private:
std::unique_ptr<ASTExpression> expression();
std::unique_ptr<ASTExpression> assignmentExpression();
std::unique_ptr<ASTExpression> ternaryExpression();
std::unique_ptr<ASTExpression> logicalOrExpression();
@ -203,7 +203,7 @@ private:
bool boolLiteral(bool* dest);
bool identifier(SkString* dest);
bool identifier(String* dest);
void* fScanner;
void* fLayoutScanner;

View File

@ -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_POSITION
#define SKSL_POSITION
@ -17,15 +17,15 @@ namespace SkSL {
* ignored.
*/
struct Position {
Position()
Position()
: fLine(-1)
, fColumn(-1) {}
Position(int line, int column)
: fLine(line)
, fColumn(column) {}
SkString description() const {
String description() const {
return to_string(fLine);
}

File diff suppressed because it is too large Load Diff

View File

@ -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_SPIRVCODEGENERATOR
#define SKSL_SPIRVCODEGENERATOR
@ -12,7 +12,6 @@
#include <tuple>
#include <unordered_map>
#include "SkStream.h"
#include "SkSLCodeGenerator.h"
#include "SkSLMemoryLayout.h"
#include "ir/SkSLBinaryExpression.h"
@ -59,13 +58,13 @@ public:
// by a pointer (e.g. vector swizzles), returns 0.
virtual SpvId getPointer() = 0;
virtual SpvId load(SkWStream& out) = 0;
virtual SpvId load(OutputStream& out) = 0;
virtual void store(SpvId value, SkWStream& out) = 0;
virtual void store(SpvId value, OutputStream& out) = 0;
};
SPIRVCodeGenerator(const Context* context, const Program* program, ErrorReporter* errors,
SkWStream* out)
OutputStream* out)
: INHERITED(program, errors, out)
, fContext(*context)
, fDefaultLayout(MemoryLayout::k140_Standard)
@ -109,7 +108,7 @@ private:
SpvId getPointerType(const Type& type, const MemoryLayout& layout,
SpvStorageClass_ storageClass);
std::vector<SpvId> getAccessChain(const Expression& expr, SkWStream& out);
std::vector<SpvId> getAccessChain(const Expression& expr, OutputStream& out);
void writeLayout(const Layout& layout, SpvId target);
@ -117,43 +116,43 @@ private:
void writeStruct(const Type& type, const MemoryLayout& layout, SpvId resultId);
void writeProgramElement(const ProgramElement& pe, SkWStream& out);
void writeProgramElement(const ProgramElement& pe, OutputStream& out);
SpvId writeInterfaceBlock(const InterfaceBlock& intf);
SpvId writeFunctionStart(const FunctionDeclaration& f, SkWStream& out);
SpvId writeFunctionDeclaration(const FunctionDeclaration& f, SkWStream& out);
SpvId writeFunctionStart(const FunctionDeclaration& f, OutputStream& out);
SpvId writeFunction(const FunctionDefinition& f, SkWStream& out);
SpvId writeFunctionDeclaration(const FunctionDeclaration& f, OutputStream& out);
void writeGlobalVars(Program::Kind kind, const VarDeclarations& v, SkWStream& out);
SpvId writeFunction(const FunctionDefinition& f, OutputStream& out);
void writeVarDeclarations(const VarDeclarations& decl, SkWStream& out);
void writeGlobalVars(Program::Kind kind, const VarDeclarations& v, OutputStream& out);
SpvId writeVariableReference(const VariableReference& ref, SkWStream& out);
void writeVarDeclarations(const VarDeclarations& decl, OutputStream& out);
std::unique_ptr<LValue> getLValue(const Expression& value, SkWStream& out);
SpvId writeVariableReference(const VariableReference& ref, OutputStream& out);
SpvId writeExpression(const Expression& expr, SkWStream& out);
SpvId writeIntrinsicCall(const FunctionCall& c, SkWStream& out);
std::unique_ptr<LValue> getLValue(const Expression& value, OutputStream& out);
SpvId writeFunctionCall(const FunctionCall& c, SkWStream& out);
SpvId writeExpression(const Expression& expr, OutputStream& out);
SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, SkWStream& out);
SpvId writeIntrinsicCall(const FunctionCall& c, OutputStream& out);
SpvId writeFunctionCall(const FunctionCall& c, OutputStream& out);
SpvId writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind, OutputStream& out);
SpvId writeConstantVector(const Constructor& c);
SpvId writeFloatConstructor(const Constructor& c, SkWStream& out);
SpvId writeFloatConstructor(const Constructor& c, OutputStream& out);
SpvId writeIntConstructor(const Constructor& c, SkWStream& out);
SpvId writeIntConstructor(const Constructor& c, OutputStream& out);
/**
* Writes a matrix with the diagonal entries all equal to the provided expression, and all other
* entries equal to zero.
*/
void writeUniformScaleMatrix(SpvId id, SpvId diagonal, const Type& type, SkWStream& out);
void writeUniformScaleMatrix(SpvId id, SpvId diagonal, const Type& type, OutputStream& out);
/**
* Writes a potentially-different-sized copy of a matrix. Entries which do not exist in the
@ -161,17 +160,17 @@ private:
* ignored.
*/
void writeMatrixCopy(SpvId id, SpvId src, const Type& srcType, const Type& dstType,
SkWStream& out);
OutputStream& out);
SpvId writeMatrixConstructor(const Constructor& c, SkWStream& out);
SpvId writeMatrixConstructor(const Constructor& c, OutputStream& out);
SpvId writeVectorConstructor(const Constructor& c, SkWStream& out);
SpvId writeVectorConstructor(const Constructor& c, OutputStream& out);
SpvId writeConstructor(const Constructor& c, SkWStream& out);
SpvId writeConstructor(const Constructor& c, OutputStream& out);
SpvId writeFieldAccess(const FieldAccess& f, SkWStream& out);
SpvId writeFieldAccess(const FieldAccess& f, OutputStream& out);
SpvId writeSwizzle(const Swizzle& swizzle, SkWStream& out);
SpvId writeSwizzle(const Swizzle& swizzle, OutputStream& out);
/**
* Folds the potentially-vector result of a logical operation down to a single bool. If
@ -179,28 +178,28 @@ private:
* same dimensions, and applys all() to it to fold it down to a single bool value. Otherwise,
* returns the original id value.
*/
SpvId foldToBool(SpvId id, const Type& operandType, SkWStream& out);
SpvId foldToBool(SpvId id, const Type& operandType, OutputStream& 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, OutputStream& out);
SpvId writeBinaryOperation(const BinaryExpression& expr, SpvOp_ ifFloat, SpvOp_ ifInt,
SpvOp_ ifUInt, SkWStream& out);
SpvOp_ ifUInt, OutputStream& out);
SpvId writeBinaryExpression(const BinaryExpression& b, SkWStream& out);
SpvId writeBinaryExpression(const BinaryExpression& b, OutputStream& out);
SpvId writeTernaryExpression(const TernaryExpression& t, SkWStream& out);
SpvId writeTernaryExpression(const TernaryExpression& t, OutputStream& out);
SpvId writeIndexExpression(const IndexExpression& expr, SkWStream& out);
SpvId writeIndexExpression(const IndexExpression& expr, OutputStream& out);
SpvId writeLogicalAnd(const BinaryExpression& b, SkWStream& out);
SpvId writeLogicalAnd(const BinaryExpression& b, OutputStream& out);
SpvId writeLogicalOr(const BinaryExpression& o, SkWStream& out);
SpvId writeLogicalOr(const BinaryExpression& o, OutputStream& out);
SpvId writePrefixExpression(const PrefixExpression& p, SkWStream& out);
SpvId writePrefixExpression(const PrefixExpression& p, OutputStream& out);
SpvId writePostfixExpression(const PostfixExpression& p, SkWStream& out);
SpvId writePostfixExpression(const PostfixExpression& p, OutputStream& out);
SpvId writeBoolLiteral(const BoolLiteral& b);
@ -208,63 +207,63 @@ private:
SpvId writeFloatLiteral(const FloatLiteral& f);
void writeStatement(const Statement& s, SkWStream& out);
void writeStatement(const Statement& s, OutputStream& out);
void writeBlock(const Block& b, SkWStream& out);
void writeBlock(const Block& b, OutputStream& out);
void writeIfStatement(const IfStatement& stmt, SkWStream& out);
void writeIfStatement(const IfStatement& stmt, OutputStream& out);
void writeForStatement(const ForStatement& f, SkWStream& out);
void writeForStatement(const ForStatement& f, OutputStream& out);
void writeWhileStatement(const WhileStatement& w, SkWStream& out);
void writeWhileStatement(const WhileStatement& w, OutputStream& out);
void writeDoStatement(const DoStatement& d, SkWStream& out);
void writeDoStatement(const DoStatement& d, OutputStream& out);
void writeReturnStatement(const ReturnStatement& r, SkWStream& out);
void writeReturnStatement(const ReturnStatement& r, OutputStream& out);
void writeCapabilities(SkWStream& out);
void writeCapabilities(OutputStream& out);
void writeInstructions(const Program& program, SkWStream& out);
void writeInstructions(const Program& program, OutputStream& out);
void writeOpCode(SpvOp_ opCode, int length, SkWStream& out);
void writeOpCode(SpvOp_ opCode, int length, OutputStream& out);
void writeWord(int32_t word, SkWStream& out);
void writeWord(int32_t word, OutputStream& out);
void writeString(const char* string, SkWStream& out);
void writeString(const char* string, OutputStream& out);
void writeLabel(SpvId id, SkWStream& out);
void writeLabel(SpvId id, OutputStream& out);
void writeInstruction(SpvOp_ opCode, SkWStream& out);
void writeInstruction(SpvOp_ opCode, OutputStream& out);
void writeInstruction(SpvOp_ opCode, const char* string, SkWStream& out);
void writeInstruction(SpvOp_ opCode, const char* string, OutputStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, OutputStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, const char* string, SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, const char* string, OutputStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, const char* string,
SkWStream& out);
OutputStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, SkWStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, OutputStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3,
SkWStream& out);
OutputStream& out);
void writeInstruction(SpvOp_ opCode, int32_t word1, int32_t word2, int32_t word3, int32_t word4,
SkWStream& out);
OutputStream& 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, OutputStream& 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, OutputStream& 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, OutputStream& 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);
OutputStream& out);
const Context& fContext;
const MemoryLayout fDefaultLayout;
@ -273,19 +272,19 @@ 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<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 fExtraGlobalsBuffer;
SkDynamicMemoryWStream fExternalFunctionsBuffer;
SkDynamicMemoryWStream fVariableBuffer;
SkDynamicMemoryWStream fNameBuffer;
SkDynamicMemoryWStream fDecorationBuffer;
std::unordered_map<String, SpvId> fTypeMap;
StringStream fCapabilitiesBuffer;
StringStream fGlobalInitializersBuffer;
StringStream fConstantBuffer;
StringStream fExtraGlobalsBuffer;
StringStream fExternalFunctionsBuffer;
StringStream fVariableBuffer;
StringStream fNameBuffer;
StringStream fDecorationBuffer;
SpvId fBoolTrue;
SpvId fBoolFalse;

173
src/sksl/SkSLString.cpp Normal file
View File

@ -0,0 +1,173 @@
/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkSLString.h"
#include "SkSLUtil.h"
#include <cinttypes>
#include <errno.h>
#include <limits.h>
#include <locale>
#include <sstream>
#include <string>
namespace SkSL {
String String::printf(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
String result;
result.vappendf(fmt, args);
return result;
}
#ifdef SKSL_STANDALONE
void String::appendf(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
this->vappendf(fmt, args);
}
#endif
void String::vappendf(const char* fmt, va_list args) {
#ifdef SKSL_BUILD_FOR_WIN
#define VSNPRINTF _vsnprintf
#else
#define VSNPRINTF vsnprintf
#endif
#define BUFFER_SIZE 256
char buffer[BUFFER_SIZE];
size_t size = VSNPRINTF(buffer, BUFFER_SIZE, fmt, args);
if (BUFFER_SIZE >= size) {
this->append(buffer, size);
} else {
auto newBuffer = std::unique_ptr<char[]>(new char[size]);
VSNPRINTF(newBuffer.get(), size, fmt, args);
this->append(newBuffer.get(), size);
}
va_end(args);
}
bool String::startsWith(const char* s) const {
return strncmp(c_str(), s, strlen(s));
}
bool String::endsWith(const char* s) const {
size_t len = strlen(s);
if (size() < len) {
return false;
}
return strncmp(c_str() + size() - len, s, len);
}
String String::operator+(const char* s) const {
String result(*this);
result.append(s);
return result;
}
String String::operator+(const String& s) const {
String result(*this);
result.append(s);
return result;
}
bool String::operator==(const String& s) const {
return this->size() == s.size() && !memcmp(c_str(), s.c_str(), this->size());
}
bool String::operator!=(const String& s) const {
return !(*this == s);
}
bool String::operator==(const char* s) const {
return this->size() == strlen(s) && !memcmp(c_str(), s, this->size());
}
bool String::operator!=(const char* s) const {
return !(*this == s);
}
String operator+(const char* s1, const String& s2) {
String result(s1);
result.append(s2);
return result;
}
bool operator==(const char* s1, const String& s2) {
return s2 == s1;
}
bool operator!=(const char* s1, const String& s2) {
return s2 != s1;
}
String to_string(int32_t value) {
return SkSL::String::printf("%d", value);
}
String to_string(uint32_t value) {
return SkSL::String::printf("%u", value);
}
String to_string(int64_t value) {
return SkSL::String::printf("%" PRId64, value);
}
String to_string(uint64_t value) {
return SkSL::String::printf("%" PRIu64, value);
}
String to_string(double value) {
#ifdef SKSL_BUILD_FOR_WIN
#define SNPRINTF _snprintf
#else
#define SNPRINTF snprintf
#endif
#define MAX_DOUBLE_CHARS 25
char buffer[MAX_DOUBLE_CHARS];
SKSL_DEBUGCODE(int len = )SNPRINTF(buffer, sizeof(buffer), "%.17g", value);
ASSERT(len < MAX_DOUBLE_CHARS);
String result(buffer);
if (!strchr(buffer, '.') && !strchr(buffer, 'e')) {
result += ".0";
}
return result;
#undef SNPRINTF
#undef MAX_DOUBLE_CHARS
}
int stoi(String s) {
char* p;
SKSL_DEBUGCODE(errno = 0;)
long result = strtol(s.c_str(), &p, 0);
ASSERT(*p == 0);
ASSERT(!errno && INT_MAX >= result && INT_MIN <= result);
return (int) result;
}
double stod(String s) {
double result;
std::string str(s.c_str(), s.size());
std::stringstream buffer(str);
buffer.imbue(std::locale::classic());
buffer >> result;
ASSERT(!buffer.fail());
return result;
}
long stol(String s) {
char* p;
SKSL_DEBUGCODE(errno = 0;)
long result = strtol(s.c_str(), &p, 0);
ASSERT(*p == 0);
ASSERT(!errno);
return result;
}
} // namespace

105
src/sksl/SkSLString.h Normal file
View File

@ -0,0 +1,105 @@
/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKSL_STRING
#define SKSL_STRING
#ifdef SKSL_STANDALONE
#define SKSL_STRING_BASE std::string
#include <string>
#else
#define SKSL_STRING_BASE SkString
#include "SkString.h"
#endif
namespace SkSL {
class String : public SKSL_STRING_BASE {
public:
String() = default;
String(const String&) = default;
String(String&&) = default;
String& operator=(const String&) = default;
String& operator=(String&&) = default;
#ifndef SKSL_STANDALONE
String(const SkString& s)
: INHERITED(s) {}
#endif
String(const char* s)
: INHERITED(s) {}
String(const char* s, size_t size)
: INHERITED(s, size) {}
static String printf(const char* fmt, ...);
#ifdef SKSL_STANDALONE
void appendf(const char* fmt, ...);
#endif
void vappendf(const char* fmt, va_list va);
bool startsWith(const char* s) const;
bool endsWith(const char* s) const;
String operator+(const char* s) const;
String operator+(const String& s) const;
bool operator==(const char* s) const;
bool operator!=(const char* s) const;
bool operator==(const String& s) const;
bool operator!=(const String& s) const;
friend String operator+(const char* s1, const String& s2);
friend bool operator==(const char* s1, const String& s2);
friend bool operator!=(const char* s1, const String& s2);
private:
typedef SKSL_STRING_BASE INHERITED;
};
String operator+(const char* s1, const String& s2);
bool operator!=(const char* s1, const String& s2);
String to_string(double value);
String to_string(int32_t value);
String to_string(uint32_t value);
String to_string(int64_t value);
String to_string(uint64_t value);
int stoi(String s);
double stod(String s);
long stol(String s);
} // namespace
#ifdef SKSL_STANDALONE
namespace std {
template<> struct hash<SkSL::String> {
size_t operator()(const SkSL::String& s) const {
return hash<std::string>{}(s);
}
};
} // namespace
#else
#include "SkOpts.h"
namespace std {
template<> struct hash<SkSL::String> {
size_t operator()(const SkSL::String& s) const {
return SkOpts::hash_fn(s.c_str(), s.size(), 0);
}
};
} // namespace
#endif // SKIA_STANDALONE
#endif

View File

@ -0,0 +1,99 @@
/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKSL_STRINGSTREAM
#define SKSL_STRINGSTREAM
#include "SkSLOutputStream.h"
#ifdef SKSL_STANDALONE
namespace SkSL {
class StringStream : public OutputStream {
public:
void write8(uint8_t b) override {
fBuffer += (char) b;
}
void writeText(const char* s) override {
fBuffer += s;
}
void write(const void* s, size_t size) override {
fBuffer.append((const char*) s, size);
}
const char* data() const {
return fBuffer.c_str();
}
size_t size() const {
return fBuffer.size();
}
void reset() {
fBuffer = "";
}
private:
String fBuffer;
};
#else
#include "SkData.h"
#include "SkStream.h"
namespace SkSL {
class StringStream : public OutputStream {
public:
void write8(uint8_t b) override {
SkASSERT(!fData);
fStream.write8(b);
}
void writeText(const char* s) override {
SkASSERT(!fData);
fStream.writeText(s);
}
void write(const void* s, size_t size) override {
SkASSERT(!fData);
fStream.write(s, size);
}
const char* data() const {
if (!fData) {
fData = fStream.detachAsData();
}
return (const char*) fData->data();
}
size_t size() const {
if (!fData) {
fData = fStream.detachAsData();
}
return fData->size();
}
void reset() {
fStream.reset();
fData = nullptr;
}
private:
mutable SkDynamicMemoryWStream fStream;
mutable sk_sp<SkData> fData;
};
#endif // SKSL_STANDALONE
} // namespace
#endif

View File

@ -4,13 +4,13 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKSL_TOKEN
#define SKSL_TOKEN
#include "SkSLPosition.h"
#include "SkSLUtil.h"
namespace SkSL {
#undef IN
@ -131,54 +131,54 @@ struct Token {
INVALID_TOKEN
};
static SkString OperatorName(Kind kind) {
static 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 String("+");
case Token::MINUS: return String("-");
case Token::STAR: return String("*");
case Token::SLASH: return String("/");
case Token::PERCENT: return String("%");
case Token::SHL: return String("<<");
case Token::SHR: return String(">>");
case Token::LOGICALNOT: return String("!");
case Token::LOGICALAND: return String("&&");
case Token::LOGICALOR: return String("||");
case Token::LOGICALXOR: return String("^^");
case Token::BITWISENOT: return String("~");
case Token::BITWISEAND: return String("&");
case Token::BITWISEOR: return String("|");
case Token::BITWISEXOR: return String("^");
case Token::EQ: return String("=");
case Token::EQEQ: return String("==");
case Token::NEQ: return String("!=");
case Token::LT: return String("<");
case Token::GT: return String(">");
case Token::LTEQ: return String("<=");
case Token::GTEQ: return String(">=");
case Token::PLUSEQ: return String("+=");
case Token::MINUSEQ: return String("-=");
case Token::STAREQ: return String("*=");
case Token::SLASHEQ: return String("/=");
case Token::PERCENTEQ: return String("%=");
case Token::SHLEQ: return String("<<=");
case Token::SHREQ: return String(">>=");
case Token::LOGICALANDEQ: return String("&&=");
case Token::LOGICALOREQ: return String("||=");
case Token::LOGICALXOREQ: return String("^^=");
case Token::BITWISEANDEQ: return String("&=");
case Token::BITWISEOREQ: return String("|=");
case Token::BITWISEXOREQ: return String("^=");
case Token::PLUSPLUS: return String("++");
case Token::MINUSMINUS: return String("--");
default:
ABORT("unsupported operator: %d\n", kind);
}
ABORT("unsupported operator: %d\n", kind);
}
}
Token() {
}
Token(Position position, Kind kind, SkString text)
Token(Position position, Kind kind, String text)
: fPosition(position)
, fKind(kind)
, fText(std::move(text)) {}
@ -209,7 +209,7 @@ struct Token {
Kind fKind;
// will be the empty string unless the token has variable text content (identifiers, numeric
// literals, and directives)
SkString fText;
String fText;
};
} // namespace

View File

@ -10,117 +10,24 @@
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#include <cinttypes>
#include <locale>
#include <sstream>
#include <string>
namespace SkSL {
SkString to_string(double value) {
#ifdef SK_BUILD_FOR_WIN
#define SNPRINTF _snprintf
#else
#define SNPRINTF snprintf
#ifdef SKSL_STANDALONE
StandaloneShaderCaps standaloneCaps;
#endif
#define MAX_DOUBLE_CHARS 25
char buffer[MAX_DOUBLE_CHARS];
SkDEBUGCODE(int len = )SNPRINTF(buffer, sizeof(buffer), "%.17g", value);
ASSERT(len < MAX_DOUBLE_CHARS);
SkString result(buffer);
if (!strchr(buffer, '.') && !strchr(buffer, 'e')) {
result += ".0";
}
return result;
#undef SNPRINTF
#undef MAX_DOUBLE_CHARS
}
SkString to_string(int32_t value) {
return SkStringPrintf("%d", value);
}
SkString to_string(uint32_t value) {
return SkStringPrintf("%u", value);
}
SkString to_string(int64_t value) {
return SkStringPrintf("%" PRId64, value);
}
SkString to_string(uint64_t value) {
return SkStringPrintf("%" PRIu64, value);
}
int stoi(SkString s) {
if (s.size() > 2 && s[0] == '0' && s[1] == 'x') {
char* p;
int result = strtoul(s.c_str() + 2, &p, 16);
ASSERT(*p == 0);
return result;
}
return atoi(s.c_str());
}
double stod(SkString s) {
double result;
std::string str(s.c_str(), s.size());
std::stringstream buffer(str);
buffer.imbue(std::locale::classic());
buffer >> result;
return result;
}
long stol(SkString s) {
if (s.size() > 2 && s[0] == '0' && s[1] == 'x') {
char* p;
long result = strtoul(s.c_str() + 2, &p, 16);
ASSERT(*p == 0);
return result;
}
return atol(s.c_str());
}
void sksl_abort() {
#ifdef SKIA
#ifdef SKSL_STANDALONE
abort();
#else
sk_abort_no_print();
exit(1);
#else
abort();
#endif
}
void write_data(const SkData& data, SkWStream& out) {
out.write(data.data(), data.size());
void write_stringstream(const StringStream& s, OutputStream& out) {
out.write(s.data(), s.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

View File

@ -4,22 +4,159 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKSL_UTIL
#define SKSL_UTIL
#include <cstdarg>
#include <memory>
#include "stdlib.h"
#include "string.h"
#include "assert.h"
#include "SkOpts.h"
#include "SkRefCnt.h"
#include "SkStream.h"
#include "SkString.h"
#include "SkTypes.h"
#include "SkSLString.h"
#include "SkSLStringStream.h"
#ifndef SKSL_STANDALONE
#include "GrContextOptions.h"
#include "GrShaderCaps.h"
#endif
#ifdef SKSL_STANDALONE
#if defined(_WIN32) || defined(__SYMBIAN32__)
#define SKSL_BUILD_FOR_WIN
#endif
#else
#ifdef SK_BUILD_FOR_WIN
#define SKSL_BUILD_FOR_WIN
#endif // SK_BUILD_FOR_WIN
#endif // SKSL_STANDALONE
namespace SkSL {
#ifdef SKSL_STANDALONE
// we're being compiled standalone, so we don't have access to caps...
enum GrGLSLGeneration {
k110_GrGLSLGeneration,
k130_GrGLSLGeneration,
k140_GrGLSLGeneration,
k150_GrGLSLGeneration,
k330_GrGLSLGeneration,
k400_GrGLSLGeneration,
k420_GrGLSLGeneration,
k310es_GrGLSLGeneration,
k320es_GrGLSLGeneration,
};
#define SKSL_CAPS_CLASS StandaloneShaderCaps
class StandaloneShaderCaps {
public:
GrGLSLGeneration generation() const {
return k400_GrGLSLGeneration;
}
bool canUseMinAndAbsTogether() const {
return true;
}
bool mustForceNegatedAtanParamToFloat() const {
return false;
}
bool shaderDerivativeSupport() const {
return true;
}
bool usesPrecisionModifiers() const {
return true;
}
bool mustDeclareFragmentShaderOutput() const {
return true;
}
bool fbFetchSupport() const {
return true;
}
bool fbFetchNeedsCustomOutput() const {
return false;
}
bool bindlessTextureSupport() const {
return false;
}
bool dropsTileOnZeroDivide() const {
return false;
}
bool flatInterpolationSupport() const {
return true;
}
bool noperspectiveInterpolationSupport() const {
return true;
}
bool multisampleInterpolationSupport() const {
return true;
}
bool sampleVariablesSupport() const {
return true;
}
bool sampleMaskOverrideCoverageSupport() const {
return true;
}
bool externalTextureSupport() const {
return true;
}
bool texelFetchSupport() const {
return true;
}
bool imageLoadStoreSupport() const {
return true;
}
bool mustEnableAdvBlendEqs() const {
return false;
}
bool mustEnableSpecificAdvBlendEqs() const {
return false;
}
bool canUseAnyFunctionInShader() const {
return false;
}
const char* shaderDerivativeExtensionString() const {
return nullptr;
}
const char* fragCoordConventionsExtensionString() const {
return nullptr;
}
const char* imageLoadStoreExtensionString() const {
return nullptr;
}
const char* versionDeclString() const {
return "";
}
};
extern StandaloneShaderCaps standaloneCaps;
#else
#define SKSL_CAPS_CLASS GrShaderCaps
// Various sets of caps for use in tests
class ShaderCapsFactory {
public:
@ -98,60 +235,38 @@ public:
return result;
}
};
#endif
void write_data(const SkData& d, SkWStream& out);
SkString operator+(const SkString& s, const char* c);
SkString operator+(const char* c, const SkString& s);
SkString operator+(const SkString& s1, const SkString& s2);
bool operator==(const SkString& s1, const char* s2);
bool operator!=(const SkString& s1, const char* s2);
bool operator!=(const char* s1, const SkString& s2);
SkString to_string(double value);
SkString to_string(int32_t value);
SkString to_string(uint32_t value);
SkString to_string(int64_t value);
SkString to_string(uint64_t value);
void write_stringstream(const StringStream& d, OutputStream& out);
#if _MSC_VER
#define NORETURN __declspec(noreturn)
#else
#define NORETURN __attribute__((__noreturn__))
#endif
int stoi(SkString s);
double stod(SkString s);
long stol(SkString s);
NORETURN void sksl_abort();
} // namespace
#define ASSERT(x) SkASSERT(x)
#define ASSERT_RESULT(x) SkAssertResult(x);
#ifdef SKIA
#define ABORT(...) { SkDebugf(__VA_ARGS__); sksl_abort(); }
#ifdef SKSL_STANDALONE
#define ASSERT(x) (void)((x) || (ABORT("failed assert(%s): %s:%d\n", #x, __FILE__, __LINE__), 0))
#define ASSERT_RESULT(x) ASSERT(x)
#define SKSL_DEBUGCODE(x) x
#else
#define ABORT(...) { sksl_abort(); }
#define ASSERT SkASSERT
#define ASSERT_RESULT(x) SkAssertResult(x)
#define SKSL_DEBUGCODE(x) SkDEBUGCODE(x)
#endif
namespace std {
template<> struct hash<SkString> {
size_t operator()(const SkString& s) const {
return SkOpts::hash_fn(s.c_str(), s.size(), 0);
}
};
}
#define SKSL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#if defined(__clang__) || defined(__GNUC__)
#define SKSL_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B))))
#else
#define SKSL_PRINTF_LIKE(A, B)
#endif
#define ABORT(...) (printf(__VA_ARGS__), sksl_abort())
#endif

View File

@ -14,7 +14,7 @@
namespace SkSL {
/**
* Represents a binary operation, with the operator represented by the token's type.
* Represents a binary operation, with the operator represented by the token's type.
*/
struct ASTBinaryExpression : public ASTExpression {
ASTBinaryExpression(std::unique_ptr<ASTExpression> left, Token op,
@ -24,7 +24,7 @@ struct ASTBinaryExpression : public ASTExpression {
, fOperator(op.fKind)
, fRight(std::move(right)) {}
SkString description() const override {
String description() const override {
return "(" + fLeft->description() + " " + Token::OperatorName(fOperator) + " " +
fRight->description() + ")";
}

View File

@ -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_ASTBLOCK
#define SKSL_ASTBLOCK
@ -13,21 +13,21 @@
namespace SkSL {
/**
* Represents a curly-braced block of statements.
* Represents a curly-braced block of statements.
*/
struct ASTBlock : public ASTStatement {
ASTBlock(Position position, std::vector<std::unique_ptr<ASTStatement>> statements)
: INHERITED(position, kBlock_Kind)
, fStatements(std::move(statements)) {}
SkString description() const override {
SkString result("{");
String description() const override {
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<ASTStatement>> fStatements;

View File

@ -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_ASTBOOLLITERAL
#define SKSL_ASTBOOLLITERAL
@ -13,15 +13,15 @@
namespace SkSL {
/**
* Represents "true" or "false".
* Represents "true" or "false".
*/
struct ASTBoolLiteral : public ASTExpression {
ASTBoolLiteral(Position position, bool value)
: INHERITED(position, kBool_Kind)
, fValue(value) {}
SkString description() const override {
return SkString(fValue ? "true" : "false");
String description() const override {
return String(fValue ? "true" : "false");
}
const bool fValue;

View File

@ -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_ASTBREAKSTATEMENT
#define SKSL_ASTBREAKSTATEMENT
@ -13,14 +13,14 @@
namespace SkSL {
/**
* A 'break' statement.
* A 'break' statement.
*/
struct ASTBreakStatement : public ASTStatement {
ASTBreakStatement(Position position)
: INHERITED(position, kBreak_Kind) {}
SkString description() const override {
return SkString("break;");
String description() const override {
return String("break;");
}
typedef ASTStatement INHERITED;

View File

@ -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_ASTCALLSUFFIX
#define SKSL_ASTCALLSUFFIX
@ -14,16 +14,16 @@
namespace SkSL {
/**
* A parenthesized list of arguments following an expression, indicating a function call.
* A parenthesized list of arguments following an expression, indicating a function call.
*/
struct ASTCallSuffix : public ASTSuffix {
ASTCallSuffix(Position position, std::vector<std::unique_ptr<ASTExpression>> arguments)
ASTCallSuffix(Position position, std::vector<std::unique_ptr<ASTExpression>> arguments)
: INHERITED(position, ASTSuffix::kCall_Kind)
, fArguments(std::move(arguments)) {}
SkString description() const override {
SkString result("(");
SkString separator;
String description() const override {
String result("(");
String separator;
for (size_t i = 0; i < fArguments.size(); ++i) {
result += separator;
separator = ", ";

View File

@ -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_ASTCONTINUESTATEMENT
#define SKSL_ASTCONTINUESTATEMENT
@ -13,14 +13,14 @@
namespace SkSL {
/**
* A 'continue' statement.
* A 'continue' statement.
*/
struct ASTContinueStatement : public ASTStatement {
ASTContinueStatement(Position position)
: INHERITED(position, kContinue_Kind) {}
SkString description() const override {
return SkString("continue;");
String description() const override {
return String("continue;");
}
typedef ASTStatement INHERITED;

View File

@ -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_ASTDECLARATION
#define SKSL_ASTDECLARATION
@ -13,7 +13,7 @@
namespace SkSL {
/**
* Abstract supertype of declarations such as variables and functions.
* Abstract supertype of declarations such as variables and functions.
*/
struct ASTDeclaration : public ASTPositionNode {
enum Kind {

View File

@ -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_ASTDISCARDSTATEMENT
#define SKSL_ASTDISCARDSTATEMENT
@ -13,14 +13,14 @@
namespace SkSL {
/**
* A 'discard' statement.
* A 'discard' statement.
*/
struct ASTDiscardStatement : public ASTStatement {
ASTDiscardStatement(Position position)
: INHERITED(position, kDiscard_Kind) {}
SkString description() const override {
return SkString("discard;");
String description() const override {
return String("discard;");
}
typedef ASTStatement INHERITED;

View File

@ -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_ASTDOSTATEMENT
#define SKSL_ASTDOSTATEMENT
@ -13,7 +13,7 @@
namespace SkSL {
/**
* A 'do' loop.
* A 'do' loop.
*/
struct ASTDoStatement : public ASTStatement {
ASTDoStatement(Position position, std::unique_ptr<ASTStatement> statement,
@ -22,7 +22,7 @@ struct ASTDoStatement : public ASTStatement {
, fStatement(std::move(statement))
, fTest(std::move(test)) {}
SkString description() const override {
String description() const override {
return "do " + fStatement->description() + " while (" + fTest->description() + ");";
}

View File

@ -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_ASTEXPRESSION
#define SKSL_ASTEXPRESSION
@ -13,7 +13,7 @@
namespace SkSL {
/**
* Abstract supertype of all expressions.
* Abstract supertype of all expressions.
*/
struct ASTExpression : public ASTPositionNode {
enum Kind {

View File

@ -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_ASTEXPRESSIONSTATEMENT
#define SKSL_ASTEXPRESSIONSTATEMENT
@ -13,14 +13,14 @@
namespace SkSL {
/**
* A lone expression being used as a statement.
* A lone expression being used as a statement.
*/
struct ASTExpressionStatement : public ASTStatement {
ASTExpressionStatement(std::unique_ptr<ASTExpression> expression)
: INHERITED(expression->fPosition, kExpression_Kind)
, fExpression(std::move(expression)) {}
SkString description() const override {
String description() const override {
return fExpression->description() + ";";
}

View File

@ -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_ASTEXTENSION
#define SKSL_ASTEXTENSION
@ -12,19 +12,19 @@
namespace SkSL {
/**
* An extension declaration.
/**
* An extension declaration.
*/
struct ASTExtension : public ASTDeclaration {
ASTExtension(Position position, SkString name)
ASTExtension(Position position, String name)
: INHERITED(position, kExtension_Kind)
, fName(std::move(name)) {}
SkString description() const override {
String description() const override {
return "#extension " + fName + " : enable";
}
const SkString fName;
const String fName;
typedef ASTDeclaration INHERITED;
};

View File

@ -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_ASTFIELDSUFFIX
#define SKSL_ASTFIELDSUFFIX
@ -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, String field)
: INHERITED(position, ASTSuffix::kField_Kind)
, fField(std::move(field)) {}
SkString description() const override {
String description() const override {
return "." + fField;
}
SkString fField;
String fField;
typedef ASTSuffix INHERITED;
};

View File

@ -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_ASTFLOATLITERAL
#define SKSL_ASTFLOATLITERAL
@ -13,14 +13,14 @@
namespace SkSL {
/**
* A literal floating point number.
* A literal floating point number.
*/
struct ASTFloatLiteral : public ASTExpression {
ASTFloatLiteral(Position position, double value)
: INHERITED(position, kFloat_Kind)
, fValue(value) {}
SkString description() const override {
String description() const override {
return to_string(fValue);
}

View File

@ -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_ASTFORSTATEMENT
#define SKSL_ASTFORSTATEMENT
@ -13,10 +13,10 @@
namespace SkSL {
/**
* A 'for' loop.
* A 'for' loop.
*/
struct ASTForStatement : public ASTStatement {
ASTForStatement(Position position, std::unique_ptr<ASTStatement> initializer,
ASTForStatement(Position position, std::unique_ptr<ASTStatement> initializer,
std::unique_ptr<ASTExpression> test, std::unique_ptr<ASTExpression> next,
std::unique_ptr<ASTStatement> statement)
: INHERITED(position, kFor_Kind)
@ -25,8 +25,8 @@ struct ASTForStatement : public ASTStatement {
, fNext(std::move(next))
, fStatement(std::move(statement)) {}
SkString description() const override {
SkString result("for (");
String description() const override {
String result("for (");
if (fInitializer) {
result.append(fInitializer->description());
}

View File

@ -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_ASTFUNCTION
#define SKSL_ASTFUNCTION
@ -16,11 +16,11 @@
namespace SkSL {
/**
* A function declaration or definition. The fBody field will be null for declarations.
* A function declaration or definition. The fBody field will be null for declarations.
*/
struct ASTFunction : public ASTDeclaration {
ASTFunction(Position position, std::unique_ptr<ASTType> returnType, SkString name,
std::vector<std::unique_ptr<ASTParameter>> parameters,
ASTFunction(Position position, std::unique_ptr<ASTType> returnType, String name,
std::vector<std::unique_ptr<ASTParameter>> parameters,
std::unique_ptr<ASTBlock> body)
: INHERITED(position, kFunction_Kind)
, fReturnType(std::move(returnType))
@ -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 + "(";
String description() const override {
String result = fReturnType->description() + " " + fName + "(";
for (size_t i = 0; i < fParameters.size(); i++) {
if (i > 0) {
result += ", ";
@ -41,11 +41,11 @@ struct ASTFunction : public ASTDeclaration {
} else {
result += ");";
}
return result;
return result;
}
const std::unique_ptr<ASTType> fReturnType;
const SkString fName;
const String fName;
const std::vector<std::unique_ptr<ASTParameter>> fParameters;
const std::unique_ptr<ASTBlock> fBody;

View File

@ -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_ASTIDENTIFIER
#define SKSL_ASTIDENTIFIER
@ -13,18 +13,18 @@
namespace SkSL {
/**
* An identifier in an expression context.
* An identifier in an expression context.
*/
struct ASTIdentifier : public ASTExpression {
ASTIdentifier(Position position, SkString text)
ASTIdentifier(Position position, String text)
: INHERITED(position, kIdentifier_Kind)
, fText(std::move(text)) {}
SkString description() const override {
String description() const override {
return fText;
}
const SkString fText;
const String fText;
typedef ASTExpression INHERITED;
};

View File

@ -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_ASTIFSTATEMENT
#define SKSL_ASTIFSTATEMENT
@ -13,18 +13,18 @@
namespace SkSL {
/**
* An 'if' statement.
* An 'if' statement.
*/
struct ASTIfStatement : public ASTStatement {
ASTIfStatement(Position position, std::unique_ptr<ASTExpression> test,
ASTIfStatement(Position position, std::unique_ptr<ASTExpression> test,
std::unique_ptr<ASTStatement> ifTrue, std::unique_ptr<ASTStatement> ifFalse)
: INHERITED(position, kIf_Kind)
, fTest(std::move(test))
, fIfTrue(std::move(ifTrue))
, fIfFalse(std::move(ifFalse)) {}
SkString description() const override {
SkString result("if (");
String description() const override {
String result("if (");
result += fTest->description();
result += ") ";
result += fIfTrue->description();
@ -32,7 +32,7 @@ struct ASTIfStatement : public ASTStatement {
result += " else ";
result += fIfFalse->description();
}
return result;
return result;
}
const std::unique_ptr<ASTExpression> fTest;

View File

@ -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_ASTINDEXSUFFIX
#define SKSL_ASTINDEXSUFFIX
@ -18,19 +18,19 @@ namespace SkSL {
* 'float[](5, 6)' are represented with a null fExpression.
*/
struct ASTIndexSuffix : public ASTSuffix {
ASTIndexSuffix(Position position)
ASTIndexSuffix(Position position)
: INHERITED(position, ASTSuffix::kIndex_Kind)
, fExpression(nullptr) {}
ASTIndexSuffix(std::unique_ptr<ASTExpression> expression)
ASTIndexSuffix(std::unique_ptr<ASTExpression> expression)
: INHERITED(expression ? expression->fPosition : Position(), ASTSuffix::kIndex_Kind)
, fExpression(std::move(expression)) {}
SkString description() const override {
String description() const override {
if (fExpression) {
return "[" + fExpression->description() + "]";
} else {
return SkString("[]");
return String("[]");
}
}

View File

@ -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_ASTINTLITERAL
#define SKSL_ASTINTLITERAL
@ -21,7 +21,7 @@ struct ASTIntLiteral : public ASTExpression {
: INHERITED(position, kInt_Kind)
, fValue(value) {}
SkString description() const override {
String description() const override {
return to_string(fValue);
}

View File

@ -25,9 +25,9 @@ struct ASTInterfaceBlock : public ASTDeclaration {
// valueName is empty when it was not present in the source
ASTInterfaceBlock(Position position,
Modifiers modifiers,
SkString typeName,
String typeName,
std::vector<std::unique_ptr<ASTVarDeclarations>> declarations,
SkString instanceName,
String instanceName,
std::vector<std::unique_ptr<ASTExpression>> sizes)
: INHERITED(position, kInterfaceBlock_Kind)
, fModifiers(modifiers)
@ -36,8 +36,8 @@ struct ASTInterfaceBlock : public ASTDeclaration {
, fInstanceName(std::move(instanceName))
, fSizes(std::move(sizes)) {}
SkString description() const override {
SkString result = fModifiers.description() + fTypeName + " {\n";
String description() const override {
String result = fModifiers.description() + fTypeName + " {\n";
for (size_t i = 0; i < fDeclarations.size(); i++) {
result += fDeclarations[i]->description() + "\n";
}
@ -56,9 +56,9 @@ struct ASTInterfaceBlock : public ASTDeclaration {
}
const Modifiers fModifiers;
const SkString fTypeName;
const String fTypeName;
const std::vector<std::unique_ptr<ASTVarDeclarations>> fDeclarations;
const SkString fInstanceName;
const String fInstanceName;
const std::vector<std::unique_ptr<ASTExpression>> fSizes;
typedef ASTDeclaration INHERITED;

View File

@ -23,7 +23,7 @@ struct ASTModifiersDeclaration : public ASTDeclaration {
: INHERITED(Position(), kModifiers_Kind)
, fModifiers(modifiers) {}
SkString description() const {
String description() const {
return fModifiers.description() + ";";
}

View File

@ -4,11 +4,11 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKSL_ASTNODE
#define SKSL_ASTNODE
#include "SkString.h"
#include "SkSLString.h"
namespace SkSL {
@ -18,8 +18,8 @@ namespace SkSL {
*/
struct ASTNode {
virtual ~ASTNode() {}
virtual SkString description() const = 0;
virtual String description() const = 0;
};
} // namespace

View File

@ -21,15 +21,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, Modifiers modifiers, std::unique_ptr<ASTType> type,
SkString name, std::vector<int> sizes)
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;
String description() const override {
String result = fModifiers.description() + fType->description() + " " + fName;
for (int size : fSizes) {
result += "[" + to_string(size) + "]";
}
@ -38,7 +38,7 @@ struct ASTParameter : public ASTPositionNode {
const Modifiers fModifiers;
const std::unique_ptr<ASTType> fType;
const SkString fName;
const String fName;
const std::vector<int> fSizes;
typedef ASTPositionNode INHERITED;

View File

@ -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_ASTPOSITIONNODE
#define SKSL_ASTPOSITIONNODE

View File

@ -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_ASTPRECISION
#define SKSL_ASTPRECISION
@ -22,17 +22,17 @@ struct ASTPrecision : public ASTDeclaration {
: INHERITED(position, kPrecision_Kind)
, fPrecision(precision) {}
SkString description() const {
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;");
default:
ASSERT(false);
return SkString("<error>");
case Modifiers::kLowp_Flag: return String("precision lowp float;");
case Modifiers::kMediump_Flag: return String("precision mediump float;");
case Modifiers::kHighp_Flag: return String("precision highp float;");
default:
ASSERT(false);
return String("<error>");
}
ASSERT(false);
return SkString("<error>");
return String("<error>");
}
const Modifiers::Flag fPrecision;

View File

@ -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_ASTPREFIXEXPRESSION
#define SKSL_ASTPREFIXEXPRESSION
@ -22,7 +22,7 @@ struct ASTPrefixExpression : public ASTExpression {
, fOperator(op.fKind)
, fOperand(std::move(operand)) {}
SkString description() const override {
String description() const override {
return Token::OperatorName(fOperator) + fOperand->description();
}

View File

@ -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_ASTRETURNSTATEMENT
#define SKSL_ASTRETURNSTATEMENT
@ -21,12 +21,12 @@ struct ASTReturnStatement : public ASTStatement {
: INHERITED(position, kReturn_Kind)
, fExpression(std::move(expression)) {}
SkString description() const override {
SkString result("return");
String description() const override {
String result("return");
if (fExpression) {
result += " " + fExpression->description();
}
return result + ";";
return result + ";";
}
const std::unique_ptr<ASTExpression> fExpression;

View File

@ -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_ASTSTATEMENT
#define SKSL_ASTSTATEMENT

View File

@ -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_ASTSUFFIX
#define SKSL_ASTSUFFIX
@ -30,15 +30,15 @@ struct ASTSuffix : public ASTPositionNode {
: INHERITED(position)
, fKind(kind) {}
SkString description() const override {
String description() const override {
switch (fKind) {
case kPostIncrement_Kind:
return SkString("++");
return String("++");
case kPostDecrement_Kind:
return SkString("--");
return String("--");
default:
ABORT("unsupported suffix operator");
}
}
}
Kind fKind;

View File

@ -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_ASTSUFFIXEXPRESSION
#define SKSL_ASTSUFFIXEXPRESSION
@ -22,7 +22,7 @@ struct ASTSuffixExpression : public ASTExpression {
, fBase(std::move(base))
, fSuffix(std::move(suffix)) {}
SkString description() const override {
String description() const override {
return fBase->description() + fSuffix->description();
}

View File

@ -23,8 +23,8 @@ struct ASTSwitchCase : public ASTStatement {
, fValue(std::move(value))
, fStatements(std::move(statements)) {}
SkString description() const override {
SkString result;
String description() const override {
String result;
if (fValue) {
result.appendf("case %s:\n", fValue->description().c_str());
} else {

View File

@ -23,8 +23,8 @@ struct ASTSwitchStatement : public ASTStatement {
, fValue(std::move(value))
, fCases(std::move(cases)) {}
SkString description() const override {
SkString result = SkStringPrintf("switch (%s) {\n", + fValue->description().c_str());
String description() const override {
String result = String::printf("switch (%s) {\n", + fValue->description().c_str());
for (const auto& c : fCases) {
result += c->description();
}

View File

@ -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_ASTTERNARYEXPRESSION
#define SKSL_ASTTERNARYEXPRESSION
@ -24,9 +24,9 @@ struct ASTTernaryExpression : public ASTExpression {
, fIfTrue(std::move(ifTrue))
, fIfFalse(std::move(ifFalse)) {}
SkString description() const override {
String description() const override {
return "(" + fTest->description() + " ? " + fIfTrue->description() + " : " +
fIfFalse->description() + ")";
fIfFalse->description() + ")";
}
const std::unique_ptr<ASTExpression> fTest;

View File

@ -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_ASTTYPE
#define SKSL_ASTTYPE
@ -21,17 +21,17 @@ struct ASTType : public ASTPositionNode {
kStruct_Kind
};
ASTType(Position position, SkString name, Kind kind, std::vector<int> sizes)
ASTType(Position position, String name, Kind kind, std::vector<int> sizes)
: INHERITED(position)
, fName(std::move(name))
, fKind(kind)
, fSizes(std::move(sizes)) {}
SkString description() const override {
String description() const override {
return fName;
}
const SkString fName;
const String fName;
const Kind fKind;

View File

@ -22,15 +22,15 @@ namespace SkSL {
* instances.
*/
struct ASTVarDeclaration {
ASTVarDeclaration(const SkString name,
ASTVarDeclaration(const 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;
String description() const {
String result = fName;
for (const auto& size : fSizes) {
if (size) {
result += "[" + size->description() + "]";
@ -44,7 +44,7 @@ struct ASTVarDeclaration {
return result;
}
SkString fName;
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;
String description() const override {
String result = fModifiers.description() + fType->description() + " ";
String separator;
for (const auto& var : fVars) {
result += separator;
separator = ", ";

View File

@ -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_ASTVARDECLARATIONSTATEMENT
#define SKSL_ASTVARDECLARATIONSTATEMENT
@ -21,7 +21,7 @@ struct ASTVarDeclarationStatement : public ASTStatement {
: INHERITED(decl->fPosition, kVarDeclaration_Kind)
, fDeclarations(std::move(decl)) {}
SkString description() const override {
String description() const override {
return fDeclarations->description() + ";";
}

View File

@ -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_ASTWHILESTATEMENT
#define SKSL_ASTWHILESTATEMENT
@ -16,13 +16,13 @@ namespace SkSL {
* A 'while' statement.
*/
struct ASTWhileStatement : public ASTStatement {
ASTWhileStatement(Position position, std::unique_ptr<ASTExpression> test,
ASTWhileStatement(Position position, std::unique_ptr<ASTExpression> test,
std::unique_ptr<ASTStatement> statement)
: INHERITED(position, kWhile_Kind)
, fTest(std::move(test))
, fStatement(std::move(statement)) {}
SkString description() const override {
String description() const override {
return "while (" + fTest->description() + ") " + fStatement->description();
}

View File

@ -34,7 +34,7 @@ struct BinaryExpression : public Expression {
*fRight);
}
virtual SkString description() const override {
virtual String description() const override {
return "(" + fLeft->description() + " " + Token::OperatorName(fOperator) + " " +
fRight->description() + ")";
}

View File

@ -23,8 +23,8 @@ struct Block : public Statement {
, fSymbols(std::move(symbols))
, fStatements(std::move(statements)) {}
SkString description() const override {
SkString result("{");
String description() const override {
String result("{");
for (size_t i = 0; i < fStatements.size(); i++) {
result += "\n";
result += fStatements[i]->description();

View File

@ -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_BOOLLITERAL
#define SKSL_BOOLLITERAL
@ -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");
String description() const override {
return String(fValue ? "true" : "false");
}
bool isConstant() const override {

View File

@ -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_BREAKSTATEMENT
#define SKSL_BREAKSTATEMENT
@ -14,14 +14,14 @@
namespace SkSL {
/**
* A 'break' statement.
* A 'break' statement.
*/
struct BreakStatement : public Statement {
BreakStatement(Position position)
: INHERITED(position, kBreak_Kind) {}
SkString description() const override {
return SkString("break;");
String description() const override {
return String("break;");
}
typedef Statement INHERITED;

View File

@ -44,9 +44,9 @@ struct Constructor : public Expression {
return nullptr;
}
SkString description() const override {
SkString result = fType.description() + "(";
SkString separator;
String description() const override {
String result = fType.description() + "(";
String separator;
for (size_t i = 0; i < fArguments.size(); i++) {
result += separator;
result += fArguments[i]->description();

View File

@ -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_CONTINUESTATEMENT
#define SKSL_CONTINUESTATEMENT
@ -14,14 +14,14 @@
namespace SkSL {
/**
* A 'continue' statement.
* A 'continue' statement.
*/
struct ContinueStatement : public Statement {
ContinueStatement(Position position)
: INHERITED(position, kContinue_Kind) {}
SkString description() const override {
return SkString("continue;");
String description() const override {
return String("continue;");
}
typedef Statement INHERITED;

View File

@ -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_DISCARDSTATEMENT
#define SKSL_DISCARDSTATEMENT
@ -14,14 +14,14 @@
namespace SkSL {
/**
* A 'discard' statement.
* A 'discard' statement.
*/
struct DiscardStatement : public Statement {
DiscardStatement(Position position)
: INHERITED(position, kDiscard_Kind) {}
SkString description() const override {
return SkString("discard;");
String description() const override {
return String("discard;");
}
typedef Statement INHERITED;

View File

@ -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_DOSTATEMENT
#define SKSL_DOSTATEMENT
@ -23,7 +23,7 @@ struct DoStatement : public Statement {
, fStatement(std::move(statement))
, fTest(std::move(test)) {}
SkString description() const override {
String description() const override {
return "do " + fStatement->description() + " while (" + fTest->description() + ");";
}

View File

@ -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_EXPRESSIONSTATEMENT
#define SKSL_EXPRESSIONSTATEMENT
@ -14,14 +14,14 @@
namespace SkSL {
/**
* A lone expression being used as a statement.
* A lone expression being used as a statement.
*/
struct ExpressionStatement : public Statement {
ExpressionStatement(std::unique_ptr<Expression> expression)
: INHERITED(expression->fPosition, kExpression_Kind)
, fExpression(std::move(expression)) {}
SkString description() const override {
String description() const override {
return fExpression->description() + ";";
}

View File

@ -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_EXTENSION
#define SKSL_EXTENSION
@ -12,19 +12,19 @@
namespace SkSL {
/**
* An extension declaration.
/**
* An extension declaration.
*/
struct Extension : public ProgramElement {
Extension(Position position, SkString name)
: INHERITED(position, kExtension_Kind)
Extension(Position position, String name)
: INHERITED(position, kExtension_Kind)
, fName(std::move(name)) {}
SkString description() const override {
String description() const override {
return "#extension " + fName + " : enable";
}
const SkString fName;
const String fName;
typedef ProgramElement INHERITED;
};

View File

@ -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_FIELD
#define SKSL_FIELD
@ -16,9 +16,9 @@
namespace SkSL {
/**
* A symbol which should be interpreted as a field access. Fields are added to the symboltable
* whenever a bare reference to an identifier should refer to a struct field; in GLSL, this is the
/**
* A symbol which should be interpreted as a field access. Fields are added to the symboltable
* whenever a bare reference to an identifier should refer to a struct field; in GLSL, this is the
* result of declaring anonymous interface blocks.
*/
struct Field : public Symbol {
@ -27,7 +27,7 @@ struct Field : public Symbol {
, fOwner(owner)
, fFieldIndex(fieldIndex) {}
virtual SkString description() const override {
virtual String description() const override {
return fOwner.description() + "." + fOwner.fType.fields()[fFieldIndex].fName;
}

View File

@ -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_FIELDACCESS
#define SKSL_FIELDACCESS
@ -24,14 +24,14 @@ struct FieldAccess : public Expression {
kAnonymousInterfaceBlock_OwnerKind
};
FieldAccess(std::unique_ptr<Expression> base, int fieldIndex,
FieldAccess(std::unique_ptr<Expression> base, int fieldIndex,
OwnerKind ownerKind = kDefault_OwnerKind)
: INHERITED(base->fPosition, kFieldAccess_Kind, *base->fType.fields()[fieldIndex].fType)
, fBase(std::move(base))
, fFieldIndex(fieldIndex)
, fOwnerKind(ownerKind) {}
virtual SkString description() const override {
virtual String description() const override {
return fBase->description() + "." + fBase->fType.fields()[fFieldIndex].fName;
}

View File

@ -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_FLOATLITERAL
#define SKSL_FLOATLITERAL
@ -21,7 +21,7 @@ struct FloatLiteral : public Expression {
: INHERITED(position, kFloatLiteral_Kind, *context.fFloat_Type)
, fValue(value) {}
virtual SkString description() const override {
virtual String description() const override {
return to_string(fValue);
}

View File

@ -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_FORSTATEMENT
#define SKSL_FORSTATEMENT
@ -18,8 +18,8 @@ namespace SkSL {
* A 'for' statement.
*/
struct ForStatement : public Statement {
ForStatement(Position position, std::unique_ptr<Statement> initializer,
std::unique_ptr<Expression> test, std::unique_ptr<Expression> next,
ForStatement(Position position, std::unique_ptr<Statement> initializer,
std::unique_ptr<Expression> test, std::unique_ptr<Expression> next,
std::unique_ptr<Statement> statement, std::shared_ptr<SymbolTable> symbols)
: INHERITED(position, kFor_Kind)
, fSymbols(symbols)
@ -28,15 +28,15 @@ struct ForStatement : public Statement {
, fNext(std::move(next))
, fStatement(std::move(statement)) {}
SkString description() const override {
SkString result("for (");
String description() const override {
String result("for (");
if (fInitializer) {
result += fInitializer->description();
}
}
result += " ";
if (fTest) {
result += fTest->description();
}
}
result += "; ";
if (fNext) {
result += fNext->description();

View File

@ -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_FUNCTIONCALL
#define SKSL_FUNCTIONCALL
@ -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;
String description() const override {
String result = fFunction.fName + "(";
String separator;
for (size_t i = 0; i < fArguments.size(); i++) {
result += separator;
result += fArguments[i]->description();

View File

@ -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_FUNCTIONDECLARATION
#define SKSL_FUNCTIONDECLARATION
@ -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, 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;
String description() const override {
String result = fReturnType.description() + " " + fName + "(";
String separator;
for (auto p : fParameters) {
result += separator;
separator = ", ";
@ -58,7 +58,7 @@ struct FunctionDeclaration : public Symbol {
/**
* Determine the effective types of this function's parameters and return value when called with
* the given arguments. This is relevant for functions with generic parameter types, where this
* the given arguments. This is relevant for functions with generic parameter types, where this
* will collapse the generic types down into specific concrete types.
*
* Returns true if it was able to select a concrete set of types for the generic function, false

View File

@ -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_FUNCTIONDEFINITION
#define SKSL_FUNCTIONDEFINITION
@ -18,13 +18,13 @@ namespace SkSL {
* A function definition (a declaration plus an associated block of code).
*/
struct FunctionDefinition : public ProgramElement {
FunctionDefinition(Position position, const FunctionDeclaration& declaration,
FunctionDefinition(Position position, const FunctionDeclaration& declaration,
std::unique_ptr<Block> body)
: INHERITED(position, kFunction_Kind)
, fDeclaration(declaration)
, fBody(std::move(body)) {}
SkString description() const override {
String description() const override {
return fDeclaration.description() + " " + fBody->description();
}

View File

@ -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_FUNCTIONREFERENCE
#define SKSL_FUNCTIONREFERENCE
@ -15,18 +15,18 @@
namespace SkSL {
/**
* An identifier referring to a function name. This is an intermediate value: FunctionReferences are
* An identifier referring to a function name. This is an intermediate value: FunctionReferences are
* always eventually replaced by FunctionCalls in valid programs.
*/
struct FunctionReference : public Expression {
FunctionReference(const Context& context, Position position,
FunctionReference(const Context& context, Position position,
std::vector<const FunctionDeclaration*> function)
: INHERITED(position, kFunctionReference_Kind, *context.fInvalid_Type)
, fFunctions(function) {}
virtual SkString description() const override {
virtual String description() const override {
ASSERT(false);
return SkString("<function>");
return String("<function>");
}
const std::vector<const FunctionDeclaration*> fFunctions;

View File

@ -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_IRNODE
#define SKSL_IRNODE
@ -13,7 +13,7 @@
namespace SkSL {
/**
* Represents a node in the intermediate representation (IR) tree. The IR is a fully-resolved
* Represents a node in the intermediate representation (IR) tree. The IR is a fully-resolved
* version of the program (all types determined, everything validated), ready for code generation.
*/
struct IRNode {
@ -22,7 +22,7 @@ struct IRNode {
virtual ~IRNode() {}
virtual SkString description() const = 0;
virtual String description() const = 0;
const Position fPosition;
};

View File

@ -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_IFSTATEMENT
#define SKSL_IFSTATEMENT
@ -17,15 +17,15 @@ namespace SkSL {
* An 'if' statement.
*/
struct IfStatement : public Statement {
IfStatement(Position position, std::unique_ptr<Expression> test,
IfStatement(Position position, std::unique_ptr<Expression> test,
std::unique_ptr<Statement> ifTrue, std::unique_ptr<Statement> ifFalse)
: INHERITED(position, kIf_Kind)
, fTest(std::move(test))
, fIfTrue(std::move(ifTrue))
, fIfFalse(std::move(ifFalse)) {}
SkString description() const override {
SkString result = "if (" + fTest->description() + ") " + fIfTrue->description();
String description() const override {
String result = "if (" + fTest->description() + ") " + fIfTrue->description();
if (fIfFalse) {
result += " else " + fIfFalse->description();
}

View File

@ -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_INDEX
#define SKSL_INDEX
@ -43,7 +43,7 @@ static const Type& index_type(const Context& context, const Type& type) {
* An expression which extracts a value from an array or matrix, as in 'm[2]'.
*/
struct IndexExpression : public Expression {
IndexExpression(const Context& context, std::unique_ptr<Expression> base,
IndexExpression(const Context& context, std::unique_ptr<Expression> base,
std::unique_ptr<Expression> index)
: INHERITED(base->fPosition, kIndex_Kind, index_type(context, base->fType))
, fBase(std::move(base))
@ -51,7 +51,7 @@ struct IndexExpression : public Expression {
ASSERT(fIndex->fType == *context.fInt_Type || fIndex->fType == *context.fUInt_Type);
}
SkString description() const override {
String description() const override {
return fBase->description() + "[" + fIndex->description() + "]";
}

View File

@ -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_INTLITERAL
#define SKSL_INTLITERAL
@ -23,7 +23,7 @@ struct IntLiteral : public Expression {
: INHERITED(position, kIntLiteral_Kind, type ? *type : *context.fInt_Type)
, fValue(value) {}
virtual SkString description() const override {
virtual String description() const override {
return to_string(fValue);
}

View File

@ -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_INTERFACEBLOCK
#define SKSL_INTERFACEBLOCK
@ -25,7 +25,7 @@ namespace SkSL {
* At the IR level, this is represented by a single variable of struct type.
*/
struct InterfaceBlock : public ProgramElement {
InterfaceBlock(Position position, const Variable* var, SkString typeName, SkString instanceName,
InterfaceBlock(Position position, const Variable* var, String typeName, String instanceName,
std::vector<std::unique_ptr<Expression>> sizes,
std::shared_ptr<SymbolTable> typeOwner)
: INHERITED(position, kInterfaceBlock_Kind)
@ -35,8 +35,8 @@ struct InterfaceBlock : public ProgramElement {
, fSizes(std::move(sizes))
, fTypeOwner(typeOwner) {}
SkString description() const override {
SkString result = fVariable.fModifiers.description() + fTypeName + " {\n";
String description() const override {
String result = fVariable.fModifiers.description() + fTypeName + " {\n";
const Type* structType = &fVariable.fType;
while (structType->kind() == Type::kArray_Kind) {
structType = &structType->componentType();
@ -59,8 +59,8 @@ struct InterfaceBlock : public ProgramElement {
}
const Variable& fVariable;
const SkString fTypeName;
const SkString fInstanceName;
const String fTypeName;
const String fInstanceName;
const std::vector<std::unique_ptr<Expression>> fSizes;
const std::shared_ptr<SymbolTable> fTypeOwner;

View File

@ -8,7 +8,6 @@
#ifndef SKSL_LAYOUT
#define SKSL_LAYOUT
#include "SkString.h"
#include "SkSLUtil.h"
namespace SkSL {
@ -55,11 +54,11 @@ struct Layout {
case Format::kRGBA8I: return "rgba8i";
case Format::kR8I: return "r8i";
}
SkFAIL("Unexpected format");
ABORT("Unexpected format");
return "";
}
static bool ReadFormat(SkString str, Format* format) {
static bool ReadFormat(String str, Format* format) {
if (str == "rgba32f") {
*format = Format::kRGBA32F;
return true;
@ -125,9 +124,9 @@ struct Layout {
, fMaxVertices(-1)
, fInvocations(-1) {}
SkString description() const {
SkString result;
SkString separator;
String description() const {
String result;
String separator;
if (fLocation >= 0) {
result += separator + "location = " + to_string(fLocation);
separator = ", ";

View File

@ -42,8 +42,8 @@ struct Modifiers {
: fLayout(layout)
, fFlags(flags) {}
SkString description() const {
SkString result = fLayout.description();
String description() const {
String result = fLayout.description();
if (fFlags & kUniform_Flag) {
result += "uniform ";
}

View File

@ -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_MODIFIERDECLARATION
#define SKSL_MODIFIERDECLARATION
@ -23,7 +23,7 @@ struct ModifiersDeclaration : public ProgramElement {
: INHERITED(Position(), kModifiers_Kind)
, fModifiers(modifiers) {}
SkString description() const {
String description() const {
return fModifiers.description() + ";";
}

View File

@ -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_POSTFIXEXPRESSION
#define SKSL_POSTFIXEXPRESSION
@ -22,7 +22,7 @@ struct PostfixExpression : public Expression {
, fOperand(std::move(operand))
, fOperator(op) {}
virtual SkString description() const override {
virtual String description() const override {
return fOperand->description() + Token::OperatorName(fOperator);
}

View File

@ -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_PREFIXEXPRESSION
#define SKSL_PREFIXEXPRESSION
@ -22,7 +22,7 @@ struct PrefixExpression : public Expression {
, fOperand(std::move(operand))
, fOperator(op) {}
virtual SkString description() const override {
virtual String description() const override {
return Token::OperatorName(fOperator) + fOperand->description();
}

View File

@ -26,7 +26,11 @@ namespace SkSL {
*/
struct Program {
struct Settings {
#ifdef SKSL_STANDALONE
const StandaloneShaderCaps* fCaps = &standaloneCaps;
#else
const GrShaderCaps* fCaps = nullptr;
#endif
// if false, sk_FragCoord is exactly the same as gl_FragCoord. If true, the y coordinate
// must be flipped.
bool fFlipY = false;

Some files were not shown because too many files have changed in this diff Show More