<commit_before>/*******************************************************************************
 * Copyright 2016, 2018 MINRES Technologies GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/

#ifndef _SYSC_MEMORY_H_
#define _SYSC_MEMORY_H_

// Needed for the simple_target_socket
#define SC_INCLUDE_DYNAMIC_PROCESSES

#include "report.h"
#include "target_mixin.h"
#include "utilities.h"
#include <tlm.h>
#include <util/sparse_array.h>

namespace scc {

/**
 *  simple memory model
 *
 *  TODO: add some more attributes/parameters to configure access time and type (DMI allowed, read only, etc)
 */
template <unsigned long long SIZE, unsigned BUSWIDTH = 32>
class memory : public sc_core::sc_module {
public:
    //! the target socket to connect to TLM
    scc::target_mixin<tlm::tlm_target_socket<BUSWIDTH>> target;
    /**
     * constructor with explicit instance name
     *
     * @param nm
     */
    memory(const sc_core::sc_module_name &nm);

    constexpr unsigned long long getSize() const {return SIZE;}

    void set_operation_callback(std::function<int(memory<SIZE, BUSWIDTH>&, tlm::tlm_generic_payload&)> cb){
        operation_cb=cb;
    }

    bool set_dmi_callback(std::function<int(memory<SIZE, BUSWIDTH>&, tlm::tlm_generic_payload&, tlm::tlm_dmi&)> cb){
        dmi_cb=cb;
    }
protected:
    //! the real memory structure
    util::sparse_array<uint8_t, SIZE> mem;

public:
    //!! handle the memory operation independent on interface function used
    int handle_operation(tlm::tlm_generic_payload &trans);
    //! handle the dmi functionality
    bool handle_dmi(tlm::tlm_generic_payload &gp, tlm::tlm_dmi &dmi_data);
    std::function<int(memory<SIZE, BUSWIDTH>&, tlm::tlm_generic_payload&)> operation_cb;
    std::function<int(memory<SIZE, BUSWIDTH>&, tlm::tlm_generic_payload&, tlm::tlm_dmi&)> dmi_cb;
};

template <unsigned long long SIZE, unsigned BUSWIDTH>
memory<SIZE, BUSWIDTH>::memory(const sc_core::sc_module_name &nm)
: sc_module(nm)
, NAMED(target) {
    // Register callback for incoming b_transport interface method call
    target.register_b_transport([this](tlm::tlm_generic_payload &gp, sc_core::sc_time &delay) -> void {<commit_msg>Fixed function signature<commit_after>/*******************************************************************************
 * Copyright 2016, 2018 MINRES Technologies GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/

#ifndef _SYSC_MEMORY_H_
#define _SYSC_MEMORY_H_

// Needed for the simple_target_socket
#define SC_INCLUDE_DYNAMIC_PROCESSES

#include "report.h"
#include "target_mixin.h"
#include "utilities.h"
#include <tlm.h>
#include <util/sparse_array.h>

namespace scc {

/**
 *  simple memory model
 *
 *  TODO: add some more attributes/parameters to configure access time and type (DMI allowed, read only, etc)
 */
template <unsigned long long SIZE, unsigned BUSWIDTH = 32>
class memory : public sc_core::sc_module {
public:
    //! the target socket to connect to TLM
    scc::target_mixin<tlm::tlm_target_socket<BUSWIDTH>> target;
    /**
     * constructor with explicit instance name
     *
     * @param nm
     */
    memory(const sc_core::sc_module_name &nm);

    constexpr unsigned long long getSize() const {return SIZE;}

    void set_operation_callback(std::function<int(memory<SIZE, BUSWIDTH>&, tlm::tlm_generic_payload&)> cb){
        operation_cb=cb;
    }

    void set_dmi_callback(std::function<int(memory<SIZE, BUSWIDTH>&, tlm::tlm_generic_payload&, tlm::tlm_dmi&)> cb){
        dmi_cb=cb;
    }
protected:
    //! the real memory structure
    util::sparse_array<uint8_t, SIZE> mem;

public:
    //!! handle the memory operation independent on interface function used
    int handle_operation(tlm::tlm_generic_payload &trans);
    //! handle the dmi functionality
    bool handle_dmi(tlm::tlm_generic_payload &gp, tlm::tlm_dmi &dmi_data);
    std::function<int(memory<SIZE, BUSWIDTH>&, tlm::tlm_generic_payload&)> operation_cb;
    std::function<int(memory<SIZE, BUSWIDTH>&, tlm::tlm_generic_payload&, tlm::tlm_dmi&)> dmi_cb;
};

template <unsigned long long SIZE, unsigned BUSWIDTH>
memory<SIZE, BUSWIDTH>::memory(const sc_core::sc_module_name &nm)
: sc_module(nm)
, NAMED(target) {
    // Register callback for incoming b_transport interface method call
    target.register_b_transport([this](tlm::tlm_generic_payload &gp, sc_core::sc_time &delay) -> void {
{'fraction_non_alphanumeric': 0.1568415359653867, 'fraction_numerical': 0.005408328826392645, 'mean_word_length': 4.8833510074231175, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4777921', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1634, 'n_words': 490}