1 // -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 // vi:tw=80:et:ts=2:sts=2 3 // 4 // ----------------------------------------------------------------------- 5 // 6 // This file is part of RLVM, a RealLive virtual machine clone. 7 // 8 // ----------------------------------------------------------------------- 9 // 10 // Copyright (C) 2007 Elliot Glaysher 11 // 12 // This program is free software; you can redistribute it and/or modify 13 // it under the terms of the GNU General Public License as published by 14 // the Free Software Foundation; either version 3 of the License, or 15 // (at your option) any later version. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of the GNU General Public License 23 // along with this program; if not, write to the Free Software 24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 25 // 26 // ----------------------------------------------------------------------- 27 28 #ifndef SRC_MACHINE_MAPPED_RLMODULE_H_ 29 #define SRC_MACHINE_MAPPED_RLMODULE_H_ 30 31 #include <functional> 32 #include <string> 33 34 #include "machine/rlmodule.h" 35 36 // Special case RLModule where each opcode added is transformed with a 37 // mapping function. 38 class MappedRLModule : public RLModule { 39 public: 40 typedef std::function<RLOperation*(RLOperation* op)> MappingFunction; 41 42 protected: 43 MappedRLModule(const MappingFunction& fun, 44 const std::string& in_module_name, 45 int in_module_type, 46 int in_module_number); 47 virtual ~MappedRLModule(); 48 49 // Adds a map_function_(op) to this modules set of opcodes. Takes ownership 50 // of |op|. 51 virtual void AddOpcode(int opcode, 52 unsigned char overload, 53 const std::string& name, 54 RLOperation* op) override; 55 56 private: 57 // Function which takes an RLOperation and returns an RLOperation. Takes 58 // ownership of the incoming RLOperation. 59 MappingFunction map_function_; 60 }; 61 62 #endif // SRC_MACHINE_MAPPED_RLMODULE_H_ 63