Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: src/sksl/SkSLIRGenerator.cpp

Issue 2288033003: Turned on SkSL->GLSL compiler (Closed)
Patch Set: wording cleanup Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkSLIRGenerator.h" 8 #include "SkSLIRGenerator.h"
9 9
10 #include "limits.h" 10 #include "limits.h"
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 FunctionDeclaration newDecl(f.fPosition, f.fName, parame ters, *returnType); 412 FunctionDeclaration newDecl(f.fPosition, f.fName, parame ters, *returnType);
413 fErrors.error(f.fPosition, "functions '" + newDecl.descr iption() + 413 fErrors.error(f.fPosition, "functions '" + newDecl.descr iption() +
414 "' and '" + other->descriptio n() + 414 "' and '" + other->descriptio n() +
415 "' differ only in return type "); 415 "' differ only in return type ");
416 return nullptr; 416 return nullptr;
417 } 417 }
418 decl = other; 418 decl = other;
419 for (size_t i = 0; i < parameters.size(); i++) { 419 for (size_t i = 0; i < parameters.size(); i++) {
420 if (parameters[i]->fModifiers != other->fParameters[i]-> fModifiers) { 420 if (parameters[i]->fModifiers != other->fParameters[i]-> fModifiers) {
421 fErrors.error(f.fPosition, "modifiers on parameter " + 421 fErrors.error(f.fPosition, "modifiers on parameter " +
422 to_string(i + 1) + " diff er between " + 422 to_string((uint64_t) i + 1) +
423 "declaration and definiti on"); 423 " differ between declarat ion and "
424 "definition");
424 return nullptr; 425 return nullptr;
425 } 426 }
426 } 427 }
427 if (other->fDefined) { 428 if (other->fDefined) {
428 fErrors.error(f.fPosition, "duplicate definition of " + 429 fErrors.error(f.fPosition, "duplicate definition of " +
429 other->description()); 430 other->description());
430 } 431 }
431 break; 432 break;
432 } 433 }
433 } 434 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 return nullptr; 610 return nullptr;
610 } 611 }
611 if (type.kind() == Type::kScalar_Kind) { 612 if (type.kind() == Type::kScalar_Kind) {
612 std::vector<std::unique_ptr<Expression>> args; 613 std::vector<std::unique_ptr<Expression>> args;
613 args.push_back(std::move(expr)); 614 args.push_back(std::move(expr));
614 ASTIdentifier id(Position(), type.description()); 615 ASTIdentifier id(Position(), type.description());
615 std::unique_ptr<Expression> ctor = this->convertIdentifier(id); 616 std::unique_ptr<Expression> ctor = this->convertIdentifier(id);
616 ASSERT(ctor); 617 ASSERT(ctor);
617 return this->call(Position(), std::move(ctor), std::move(args)); 618 return this->call(Position(), std::move(ctor), std::move(args));
618 } 619 }
619 ABORT("cannot coerce %s to %s", expr->fType.description().c_str(), 620 std::vector<std::unique_ptr<Expression>> args;
620 type.description().c_str()); 621 args.push_back(std::move(expr));
622 return std::unique_ptr<Expression>(new Constructor(Position(), type, std::mo ve(args)));
621 } 623 }
622 624
623 static bool is_matrix_multiply(const Type& left, const Type& right) { 625 static bool is_matrix_multiply(const Type& left, const Type& right) {
624 if (left.kind() == Type::kMatrix_Kind) { 626 if (left.kind() == Type::kMatrix_Kind) {
625 return right.kind() == Type::kMatrix_Kind || right.kind() == Type::kVect or_Kind; 627 return right.kind() == Type::kMatrix_Kind || right.kind() == Type::kVect or_Kind;
626 } 628 }
627 return left.kind() == Type::kVector_Kind && right.kind() == Type::kMatrix_Ki nd; 629 return left.kind() == Type::kVector_Kind && right.kind() == Type::kMatrix_Ki nd;
628 } 630 }
629 /** 631 /**
630 * Determines the operand and result types of a binary expression. Returns true if the expression is 632 * Determines the operand and result types of a binary expression. Returns true if the expression is
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 std::move(test), 827 std::move(test),
826 std::move(ifTrue), 828 std::move(ifTrue),
827 std::move(ifFalse)) ); 829 std::move(ifFalse)) );
828 } 830 }
829 831
830 std::unique_ptr<Expression> IRGenerator::call(Position position, 832 std::unique_ptr<Expression> IRGenerator::call(Position position,
831 const FunctionDeclaration& functio n, 833 const FunctionDeclaration& functio n,
832 std::vector<std::unique_ptr<Expres sion>> arguments) { 834 std::vector<std::unique_ptr<Expres sion>> arguments) {
833 if (function.fParameters.size() != arguments.size()) { 835 if (function.fParameters.size() != arguments.size()) {
834 std::string msg = "call to '" + function.fName + "' expected " + 836 std::string msg = "call to '" + function.fName + "' expected " +
835 to_string(function.fParameters.size()) + 837 to_string((uint64_t) function.fParameters.size( )) +
836 " argument"; 838 " argument";
837 if (function.fParameters.size() != 1) { 839 if (function.fParameters.size() != 1) {
838 msg += "s"; 840 msg += "s";
839 } 841 }
840 msg += ", but found " + to_string(arguments.size()); 842 msg += ", but found " + to_string((uint64_t) arguments.size());
841 fErrors.error(position, msg); 843 fErrors.error(position, msg);
842 return nullptr; 844 return nullptr;
843 } 845 }
844 for (size_t i = 0; i < arguments.size(); i++) { 846 for (size_t i = 0; i < arguments.size(); i++) {
845 arguments[i] = this->coerce(std::move(arguments[i]), function.fParameter s[i]->fType); 847 arguments[i] = this->coerce(std::move(arguments[i]), function.fParameter s[i]->fType);
846 if (arguments[i] && (function.fParameters[i]->fModifiers.fFlags & Modifi ers::kOut_Flag)) { 848 if (arguments[i] && (function.fParameters[i]->fModifiers.fFlags & Modifi ers::kOut_Flag)) {
847 this->markWrittenTo(*arguments[i]); 849 this->markWrittenTo(*arguments[i]);
848 } 850 }
849 } 851 }
850 return std::unique_ptr<FunctionCall>(new FunctionCall(position, function, 852 return std::unique_ptr<FunctionCall>(new FunctionCall(position, function,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 return std::unique_ptr<Expression>(new FloatLiteral(fContext, position, (double) value)); 933 return std::unique_ptr<Expression>(new FloatLiteral(fContext, position, (double) value));
932 } 934 }
933 if (args.size() == 1 && args[0]->fType == type) { 935 if (args.size() == 1 && args[0]->fType == type) {
934 // argument is already the right type, just return it 936 // argument is already the right type, just return it
935 return std::move(args[0]); 937 return std::move(args[0]);
936 } 938 }
937 if (type.isNumber()) { 939 if (type.isNumber()) {
938 if (args.size() != 1) { 940 if (args.size() != 1) {
939 fErrors.error(position, "invalid arguments to '" + type.description( ) + 941 fErrors.error(position, "invalid arguments to '" + type.description( ) +
940 "' constructor, (expected exactly 1 argument , but found " + 942 "' constructor, (expected exactly 1 argument , but found " +
941 to_string(args.size()) + ")"); 943 to_string((uint64_t) args.size()) + ")");
942 } 944 }
943 if (args[0]->fType == *fContext.fBool_Type) { 945 if (args[0]->fType == *fContext.fBool_Type) {
944 std::unique_ptr<IntLiteral> zero(new IntLiteral(fContext, position, 0)); 946 std::unique_ptr<IntLiteral> zero(new IntLiteral(fContext, position, 0));
945 std::unique_ptr<IntLiteral> one(new IntLiteral(fContext, position, 1 )); 947 std::unique_ptr<IntLiteral> one(new IntLiteral(fContext, position, 1 ));
946 return std::unique_ptr<Expression>( 948 return std::unique_ptr<Expression>(
947 new TernaryExpression(position, std::mo ve(args[0]), 949 new TernaryExpression(position, std::mo ve(args[0]),
948 this->coerce(std: :move(one), type), 950 this->coerce(std: :move(one), type),
949 this->coerce(std: :move(zero), 951 this->coerce(std: :move(zero),
950 type ))); 952 type )));
951 } else if (!args[0]->fType.isNumber()) { 953 } else if (!args[0]->fType.isNumber()) {
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 case Expression::kIndex_Kind: 1253 case Expression::kIndex_Kind:
1252 this->markWrittenTo(*((IndexExpression&) expr).fBase); 1254 this->markWrittenTo(*((IndexExpression&) expr).fBase);
1253 break; 1255 break;
1254 default: 1256 default:
1255 fErrors.error(expr.fPosition, "cannot assign to '" + expr.descriptio n() + "'"); 1257 fErrors.error(expr.fPosition, "cannot assign to '" + expr.descriptio n() + "'");
1256 break; 1258 break;
1257 } 1259 }
1258 } 1260 }
1259 1261
1260 } 1262 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698