blob: 24fbb6c260fa7921dd9502173cf1f263f3d4d800 [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "stdio.h"
9#include <fstream>
10#include "SkSLCompiler.h"
11
12/**
13 * Very simple standalone executable to facilitate testing.
14 */
15int main(int argc, const char** argv) {
16 if (argc != 3) {
17 printf("usage: skslc <input> <output>\n");
18 exit(1);
19 }
20 SkSL::Program::Kind kind;
21 size_t len = strlen(argv[1]);
22 if (len > 5 && !strcmp(argv[1] + strlen(argv[1]) - 5, ".vert")) {
23 kind = SkSL::Program::kVertex_Kind;
24 } else if (len > 5 && !strcmp(argv[1] + strlen(argv[1]) - 5, ".frag")) {
25 kind = SkSL::Program::kFragment_Kind;
26 } else {
27 printf("input filename must end in '.vert' or '.frag'\n");
28 exit(1);
29 }
30
31 std::ifstream in(argv[1]);
32 std::string text((std::istreambuf_iterator<char>(in)),
33 std::istreambuf_iterator<char>());
34 if (in.rdstate()) {
35 printf("error reading '%s'\n", argv[1]);
36 exit(2);
37 }
fmalitad214d6a2016-09-30 08:05:24 -070038 std::ofstream out(argv[2], std::ofstream::binary);
39 SkSL::Compiler compiler;
40 if (!compiler.toSPIRV(kind, text, out)) {
41 printf("%s", compiler.errorText().c_str());
42 exit(3);
43 }
44 if (out.rdstate()) {
45 printf("error writing '%s'\n", argv[2]);
46 exit(4);
ethannicholasb3058bd2016-07-01 08:22:01 -070047 }
48}