Debian Codegraph @

third_party/spirv-tools/tools/sva/src/sva.js

raw
1 // Copyright 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 import Parser from "./parser.js";
16 import Lexer from "./lexer.js";
17 import Assembler from "./assembler.js";
18
19 import grammar from "./spirv.data.js";
20
21 export default class SVA {
22 /**
23 * Attempts to convert |input| SPIR-V assembly into SPIR-V binary.
24 *
25 * @param {String} the input string containing the assembly
26 * @return {Uint32Array|string} returns a Uint32Array containing the binary
27 * SPIR-V or a string on error.
28 */
29 static assemble(input) {
30 let l = new Lexer(input);
31 let p = new Parser(grammar, l);
32
33 let ast = p.parse();
34 if (ast === undefined)
35 return p.error;
36
37 let a = new Assembler(ast);
38 return a.assemble();
39 }
40 }