transformer.cpp revision 4df77d18bf57187f8e7142c6f7a70a9cdd3d581e
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 "transformer.h" 18 19#include "module.h" 20 21namespace android { 22namespace spirit { 23 24Module *Transformer::applyTo(Module *m) { 25 // TODO fix Module::accept() to have the header serialization code there 26 m->SerializeHeader(*mStream); 27 m->accept(this); 28 std::unique_ptr<InputWordStream> IS( 29 InputWordStream::Create(mStream->getWords())); 30 return Deserialize<Module>(*IS); 31} 32 33std::vector<uint32_t> Transformer::transformSerialize(Module *m) { 34 m->SerializeHeader(*mStream); 35 m->accept(this); 36 return mStream->getWords(); 37} 38 39void Transformer::insert(Instruction *inst) { 40 // TODO: warn on nullptr inst 41 inst->Serialize(*mStream); 42} 43 44} // namespace spirit 45} // namespace android 46