InstLib.hpp

This file maintains information about instructions availabel in virtual hardware.

Enums

enum class ScopeType

ScopeType is used for scopes that we need to do something special at the end. Eg: LOOP needs to go back to beginning of loop; FUNCTION needs to return to call.

Values:

enumerator NONE
enumerator ROOT
enumerator BASIC
enumerator LOOP
enumerator FUNCTION
template<typename HARDWARE_T, typename ARG_T = size_t, size_t ARG_COUNT = 3>
class InstLib
#include <InstLib.hpp>

InstLib maintains a set of instructions for use in virtual hardware.

Template Parameters:
  • HARDWARE_T – Type of the virtual hardware class to track instructions.

  • ARG_T – What types of arguments are associated with instructions.

  • ARG_COUNT – Max number of arguments on an instruction.

Public Types

using hardware_t = HARDWARE_T
using inst_t = typename hardware_t::inst_t
using genome_t = vector<inst_t>
using arg_t = ARG_T
using fun_t = std::function<void(hardware_t&, const inst_t&)>
using inst_properties_t = std::unordered_set<std::string>

Public Functions

inline InstLib()

Default Constructor.

InstLib(const InstLib&) = delete

Copy Constructor.

InstLib(InstLib&&) = delete

Move Constructor.

inline virtual ~InstLib()

Destructor.

InstLib &operator=(const InstLib&) = default

Copy Operator.

InstLib &operator=(InstLib&&) = default

Move Operator.

inline const std::string &GetName(size_t idx) const

Return the name associated with the specified instruction ID.

inline const fun_t &GetFunction(size_t idx) const

Return the function associated with the specified instruction ID.

inline size_t GetNumArgs(size_t idx) const

Return the number of arguments expected for the specified instruction ID.

inline const std::string &GetDesc(size_t idx) const

Return the provided description for the providxed instruction ID.

inline ScopeType GetScopeType(size_t idx) const

What type of scope does this instruction state? ScopeType::NONE is default.

inline size_t GetScopeArg(size_t idx) const

If this instruction alters scope, idxentify which argument does so.

inline const inst_properties_t &GetProperties(size_t idx) const

Return the set of properties for the providxed instruction ID.

inline char GetSymbol(size_t idx) const
inline bool HasProperty(size_t idx, std::string property) const

Does the given instruction ID have the given property value?

inline size_t GetSize() const

Get the number of instructions in this set.

inline bool IsInst(const std::string name) const

Returns boolean indicating whether the given string is a valid instruction.

inline size_t GetID(const size_t idx) const
inline size_t GetID(const std::string &name) const

Return the ID of the instruction that has the specified name.

inline size_t GetIDFromSymbol(char symbol) const

Return the ID of the instruction associated with the specified symbol.

inline size_t GetIndex(const std::string &name) const

Return the ID of the instruction that has the specified name.

inline size_t GetIndex(const size_t id) const

Return the ID of the instruction that has the specified id.

inline size_t GetIndexFromSymbol(char symbol) const
inline arg_t GetArg(const std::string &name)

Return the argument value associated with the provided keyword.

inline void AddInst(const std::string &name, const fun_t &fun_call, size_t num_args = 0, const std::string &desc = "", ScopeType scope_type = ScopeType::NONE, size_t scope_arg = (size_t)-1, const inst_properties_t &inst_properties = inst_properties_t(), int _id = -1)

Add a new instruction to the set.

Parameters:
  • name – A unique string name for this instruction.

  • fun_call – The function that should be called when this instruction is executed.

  • num_args – How many arguments does this function require? (default=0)

  • desc – A description of how this function operates. (default=””)

  • scope_type – Type of scope does this instruction creates. (default=ScopeType::NONE)

  • scope_arg – If instruction changes scope, which argument specifies new scope? (default=-1)

  • inst_properties – Strings representing arbitrary properties associated with instruction

inline void AddArg(const std::string &name, arg_t value)

Specify a keyword and arg value.

inline virtual void ProcessInst(hardware_t &hw, const inst_t &inst) const

Process a specified instruction in the provided hardware.

template<typename IN_HW>
inline void ProcessInst(Ptr<IN_HW> hw, const inst_t &inst) const

Process a specified instruction on hardware that can be converted to the correct type.

inline void WriteGenome(const genome_t &genome, std::ostream &os = std::cout) const

Write out a full genome to the provided ostream.

inline void ReadInst(genome_t &genome, std::string info) const

Read the instruction in the provided info and append it to the provided genome.

inline void PrintManifest(std::ostream &os = std::cout) const

Print out summary of instruction library.

Protected Attributes

vector<InstDef> inst_lib

Full definitions for instructions.

vector<fun_t> inst_funs

Map of instruction IDs to their functions.

std::map<std::string, size_t> name_map

How do names link to instructions?

std::map<size_t, size_t> id_map

How do identifiers link to instructions?

std::map<std::string, arg_t> arg_map

How are different arguments named?

std::string symbol_defaults = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*~_=,.|/\\><"

Symbols to use when representing individual instructions (80).

char extra_symbol = '+'

Symbol for more instructions than fit above.

array<size_t, 128> symbol_map

Map of symbols back to instruction IDs.

struct InstDef
#include <InstLib.hpp>

Public Functions

inline InstDef(size_t _idx, size_t _id, const std::string &_n, fun_t _fun, size_t _args, const std::string &_d, ScopeType _s_type, size_t _s_arg, const inst_properties_t &_properties = inst_properties_t(), char _sym = '?')
InstDef(const InstDef&) = default

Public Members

size_t index
size_t id
std::string name

Name of this instruction.

fun_t fun_call

Function to call when executing.

size_t num_args

Number of args needed by function.

std::string desc

Description of function.

ScopeType scope_type

How does this instruction affect scoping?

size_t scope_arg

Which arg indicates new scope (if any).

inst_properties_t properties

Are there any generic properties associated with this inst def?

char symbol

Unique symbol for this instruction.

struct InstructionBase
#include <InstLib.hpp>

Public Functions

inline virtual ~InstructionBase()
virtual size_t GetIndex() const = 0