<commit_before>/*
 *  yosys -- Yosys Open SYnthesis Suite
 *
 *  Copyright (C) 2012  Aki "lethalbit" <NAME> <<EMAIL>> <<EMAIL>>
 *
 *  Permission to use, copy, modify, and/or distribute this software for any
 *  purpose with or without fee is hereby granted, provided that the above
 *  copyright notice and this permission notice appear in all copies.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 *  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 *  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 *  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 *  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 *  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

#include "kernel/rtlil.h"
#include "kernel/register.h"
#include "kernel/sigtools.h"
#include "kernel/celltypes.h"
#include "kernel/cellaigs.h"
#include "kernel/log.h"
#include <string>
#include <algorithm>
#include <unordered_map>
#include <vector>

USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN


struct JnyWriter
{
    private:
        std::ostream &f;
        bool _use_selection;

        // XXX(aki): TODO: this needs to be updated to us
        // dict<T, V> and then coalesce_cells needs to be updated
        // but for now for the PoC this looks to be sufficient
        std::unordered_map<std::string, std::vector<Cell*>> _cells{};

        bool _include_connections;
        bool _include_attributes;
        bool _include_properties;

        string escape_string(string str) {
            std::string newstr;

            auto itr = str.begin();

            for(; itr != str.end(); ++itr) {
                switch (*itr) {
                    case '\\': {
                        newstr += *itr++;
                        newstr += *itr;
                        break;
                    } case '\n': {
                        newstr += "\\n";
                        break;
                    } case '\f': {
                        newstr += "\\f";
                        break;
                    } case '\v': {
                        newstr += "\\v";
                        break;
                    } case '\t': {
                        newstr += "\\t";
                        break;
                    } case '\a': {
                        newstr += "\\a";
                        break;
                    } case '\r': {
                        newstr += "\\r";
                        break;
                    } case '\"': {
                        newstr += "\\\"";
                        break;
                    } case '\'': {
                        newstr += "\\\'";
                        break;
                    } case '\b': {
                        newstr += "\\b";
                        break;
                    } case '\?': {
                        newstr += "\\?";
                        break;
                    } default: {
                        newstr += *itr;
                    }
                }
            }

            return newstr;
        }

        // XXX(aki): I know this is far from ideal but i'm out of spoons and cant focus so
        // it'll have to do for now,
        void coalesce_cells(Module* mod)
        {
            for (auto cell : mod->cells()) {<commit_msg>pass jny: removed the invalid json escapes<commit_after>/*
 *  yosys -- Yosys Open SYnthesis Suite
 *
 *  Copyright (C) 2012  Aki "lethalbit" <NAME> <<EMAIL>> <<EMAIL>>
 *
 *  Permission to use, copy, modify, and/or distribute this software for any
 *  purpose with or without fee is hereby granted, provided that the above
 *  copyright notice and this permission notice appear in all copies.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 *  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 *  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 *  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 *  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 *  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

#include "kernel/rtlil.h"
#include "kernel/register.h"
#include "kernel/sigtools.h"
#include "kernel/celltypes.h"
#include "kernel/cellaigs.h"
#include "kernel/log.h"
#include <string>
#include <algorithm>
#include <unordered_map>
#include <vector>

USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN


struct JnyWriter
{
    private:
        std::ostream &f;
        bool _use_selection;

        // XXX(aki): TODO: this needs to be updated to us
        // dict<T, V> and then coalesce_cells needs to be updated
        // but for now for the PoC this looks to be sufficient
        std::unordered_map<std::string, std::vector<Cell*>> _cells{};

        bool _include_connections;
        bool _include_attributes;
        bool _include_properties;

        string escape_string(string str) {
            std::string newstr;

            auto itr = str.begin();

            for(; itr != str.end(); ++itr) {
                switch (*itr) {
                    case '\\': {
                        newstr += *itr++;
                        newstr += *itr;
                        break;
                    } case '\n': {
                        newstr += "\\n";
                        break;
                    } case '\f': {
                        newstr += "\\f";
                        break;
                    } case '\t': {
                        newstr += "\\t";
                        break;
                    } case '\r': {
                        newstr += "\\r";
                        break;
                    } case '\"': {
                        newstr += "\\\"";
                        break;
                    } case '\b': {
                        newstr += "\\b";
                        break;
                    } default: {
                        newstr += *itr;
                    }
                }
            }

            return newstr;
        }

        // XXX(aki): I know this is far from ideal but i'm out of spoons and cant focus so
        // it'll have to do for now,
        void coalesce_cells(Module* mod)
        {
            for (auto cell : mod->cells()) {
{'fraction_non_alphanumeric': 0.10265924551638837, 'fraction_numerical': 0.0012368583797155227, 'mean_word_length': 1.3336940836940836, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2533762', 'n_tokens_mistral': 1790, 'n_tokens_neox': 1632, 'n_words': 572}