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