aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLCompiler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sksl/SkSLCompiler.cpp')
-rw-r--r--src/sksl/SkSLCompiler.cpp53
1 files changed, 25 insertions, 28 deletions
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp
index 510d610a6e..905eff4e28 100644
--- a/src/sksl/SkSLCompiler.cpp
+++ b/src/sksl/SkSLCompiler.cpp
@@ -7,9 +7,6 @@
#include "SkSLCompiler.h"
-#include <fstream>
-#include <streambuf>
-
#include "ast/SkSLASTPrecision.h"
#include "SkSLCFGGenerator.h"
#include "SkSLIRGenerator.h"
@@ -71,17 +68,17 @@ Compiler::Compiler()
ADD_TYPE(BVec3);
ADD_TYPE(BVec4);
ADD_TYPE(Mat2x2);
- types->addWithoutOwnership("mat2x2", fContext.fMat2x2_Type.get());
+ types->addWithoutOwnership(SkString("mat2x2"), fContext.fMat2x2_Type.get());
ADD_TYPE(Mat2x3);
ADD_TYPE(Mat2x4);
ADD_TYPE(Mat3x2);
ADD_TYPE(Mat3x3);
- types->addWithoutOwnership("mat3x3", fContext.fMat3x3_Type.get());
+ types->addWithoutOwnership(SkString("mat3x3"), fContext.fMat3x3_Type.get());
ADD_TYPE(Mat3x4);
ADD_TYPE(Mat4x2);
ADD_TYPE(Mat4x3);
ADD_TYPE(Mat4x4);
- types->addWithoutOwnership("mat4x4", fContext.fMat4x4_Type.get());
+ types->addWithoutOwnership(SkString("mat4x4"), fContext.fMat4x4_Type.get());
ADD_TYPE(GenType);
ADD_TYPE(GenDType);
ADD_TYPE(GenIType);
@@ -140,7 +137,7 @@ Compiler::Compiler()
Modifiers::Flag ignored1;
std::vector<std::unique_ptr<ProgramElement>> ignored2;
- this->internalConvertProgram(SKSL_INCLUDE, &ignored1, &ignored2);
+ this->internalConvertProgram(SkString(SKSL_INCLUDE), &ignored1, &ignored2);
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
ASSERT(!fErrorCount);
}
@@ -289,7 +286,7 @@ void Compiler::scanCFG(const FunctionDefinition& f) {
for (size_t i = 0; i < cfg.fBlocks.size(); i++) {
if (i != cfg.fStart && !cfg.fBlocks[i].fEntrances.size() &&
cfg.fBlocks[i].fNodes.size()) {
- this->error(cfg.fBlocks[i].fNodes[0].fNode->fPosition, "unreachable");
+ this->error(cfg.fBlocks[i].fNodes[0].fNode->fPosition, SkString("unreachable"));
}
}
if (fErrorCount) {
@@ -318,12 +315,12 @@ void Compiler::scanCFG(const FunctionDefinition& f) {
// check for missing return
if (f.fDeclaration.fReturnType != *fContext.fVoid_Type) {
if (cfg.fBlocks[cfg.fExit].fEntrances.size()) {
- this->error(f.fPosition, "function can exit without returning a value");
+ this->error(f.fPosition, SkString("function can exit without returning a value"));
}
}
}
-void Compiler::internalConvertProgram(std::string text,
+void Compiler::internalConvertProgram(SkString text,
Modifiers::Flag* defaultPrecision,
std::vector<std::unique_ptr<ProgramElement>>* result) {
Parser parser(text, *fTypes, *this);
@@ -386,7 +383,7 @@ void Compiler::internalConvertProgram(std::string text,
}
}
-std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, std::string text) {
+std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, SkString text) {
fErrorText = "";
fErrorCount = 0;
fIRGenerator->pushSymbolTable();
@@ -394,10 +391,10 @@ std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, std::strin
Modifiers::Flag ignored;
switch (kind) {
case Program::kVertex_Kind:
- this->internalConvertProgram(SKSL_VERT_INCLUDE, &ignored, &elements);
+ this->internalConvertProgram(SkString(SKSL_VERT_INCLUDE), &ignored, &elements);
break;
case Program::kFragment_Kind:
- this->internalConvertProgram(SKSL_FRAG_INCLUDE, &ignored, &elements);
+ this->internalConvertProgram(SkString(SKSL_FRAG_INCLUDE), &ignored, &elements);
break;
}
fIRGenerator->fSymbolTable->markAllFunctionsBuiltin();
@@ -410,13 +407,13 @@ std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, std::strin
return result;
}
-void Compiler::error(Position position, std::string msg) {
+void Compiler::error(Position position, SkString msg) {
fErrorCount++;
fErrorText += "error: " + position.description() + ": " + msg.c_str() + "\n";
}
-std::string Compiler::errorText() {
- std::string result = fErrorText;
+SkString Compiler::errorText() {
+ SkString result = fErrorText;
return result;
}
@@ -430,42 +427,42 @@ void Compiler::writeErrorCount() {
}
}
-bool Compiler::toSPIRV(Program::Kind kind, const std::string& text, std::ostream& out) {
+bool Compiler::toSPIRV(Program::Kind kind, const SkString& text, SkWStream& out) {
auto program = this->convertProgram(kind, text);
if (fErrorCount == 0) {
SkSL::SPIRVCodeGenerator cg(&fContext);
cg.generateCode(*program.get(), out);
- ASSERT(!out.rdstate());
}
return fErrorCount == 0;
}
-bool Compiler::toSPIRV(Program::Kind kind, const std::string& text, std::string* out) {
- std::stringstream buffer;
+bool Compiler::toSPIRV(Program::Kind kind, const SkString& text, SkString* out) {
+ SkDynamicMemoryWStream buffer;
bool result = this->toSPIRV(kind, text, buffer);
if (result) {
- *out = buffer.str();
+ sk_sp<SkData> data(buffer.detachAsData());
+ *out = SkString((const char*) data->data(), data->size());
}
return result;
}
-bool Compiler::toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps,
- std::ostream& out) {
+bool Compiler::toGLSL(Program::Kind kind, const SkString& text, const GrGLSLCaps& caps,
+ SkWStream& out) {
auto program = this->convertProgram(kind, text);
if (fErrorCount == 0) {
SkSL::GLSLCodeGenerator cg(&fContext, &caps);
cg.generateCode(*program.get(), out);
- ASSERT(!out.rdstate());
}
return fErrorCount == 0;
}
-bool Compiler::toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps,
- std::string* out) {
- std::stringstream buffer;
+bool Compiler::toGLSL(Program::Kind kind, const SkString& text, const GrGLSLCaps& caps,
+ SkString* out) {
+ SkDynamicMemoryWStream buffer;
bool result = this->toGLSL(kind, text, caps, buffer);
if (result) {
- *out = buffer.str();
+ sk_sp<SkData> data(buffer.detachAsData());
+ *out = SkString((const char*) data->data(), data->size());
}
return result;
}