1 /* 2 * Copyright 2017, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "pass.h" 18 19 #include "module.h" 20 21 namespace android { 22 namespace spirit { 23 24 Module *Pass::run(Module *module, int *error) { 25 int intermediateError; 26 auto words = runAndSerialize(module, &intermediateError); 27 if (intermediateError) { 28 if (error) { 29 *error = intermediateError; 30 } 31 return nullptr; 32 } 33 return Deserialize<Module>(words); 34 } 35 36 std::vector<uint32_t> Pass::runAndSerialize(Module *module, int *error) { 37 int intermediateError; 38 auto m1 = run(module, &intermediateError); 39 if (intermediateError) { 40 if (error) { 41 *error = intermediateError; 42 } 43 return std::vector<uint32_t>(); 44 } 45 return Serialize<Module>(m1); 46 } 47 48 } // namespace spirit 49 } // namespace android 50 51