<commit_before>//=======================================================================
// Copyright <NAME> 2011.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================

#include <iostream>
#include <memory>

#include <boost/variant.hpp>

#include "mtac/Printer.hpp"
#include "mtac/Program.hpp"

#include "VisitorUtils.hpp"
#include "Utils.hpp"

using namespace eddic;

namespace {

struct ArgumentToString : public boost::static_visitor<std::string> {
   std::string operator()(std::shared_ptr<Variable>& variable) const {
        return variable->name();   
   }

   std::string operator()(int& integer) const {
        return toString(integer);
   }
   
   std::string operator()(double& float_) const {
        return toString(float_);
   }

   std::string operator()(std::string& str) const {
        return str;
   }
};

std::string printArg(mtac::Argument& arg){
    return visit(ArgumentToString(), arg);
}

struct DebugVisitor : public boost::static_visitor<> {
    void operator()(std::shared_ptr<mtac::Program> program){
        std::cout << "TAC Program " << std::endl << std::endl; 

        visit_each_non_variant(*this, program->functions);
    }

    void operator()(std::shared_ptr<mtac::Function>& function){
        std::cout << "Function " << function->getName() << std::endl;

        visit_each(*this, function->getStatements());
        visit_each_non_variant(*this, function->getBasicBlocks());

        std::cout << std::endl;
    }

    void operator()(std::shared_ptr<mtac::BasicBlock>& block){
        std::cout << "B" << block->index << "->" << std::endl;
        
        visit_each(*this, block->statements);     
    }

    void operator()(mtac::Statement& statement){
        visit(*this, statement);
    }

    void operator()(std::shared_ptr<mtac::Quadruple>& quadruple){
        if(quadruple->op == mtac::Operator::ASSIGN){
            std::cout << "\t" << quadruple->result->name() << " = (normal) " << printArg(*quadruple->arg1) << std::endl;
        } else if(quadruple->op == mtac::Operator::FASSIGN){
            std::cout << "\t" << quadruple->result->name() << " = (float) " << printArg(*quadruple->arg1) << std::endl;
        } else {
            mtac::Operator op = quadruple->op;

            if(op == mtac::Operator::ADD){
                std::cout << "\t" << quadruple->result->name() << " = " << printArg(*quadruple->arg1) << " + " << printArg(*quadruple->arg2) << std::endl;
            } else if(op == mtac::Operator::FADD){
                std::cout << "\t" << quadruple->result->name() << " = " << printArg(*quadruple->arg1) << " + (float) " << printArg(*quadruple->arg2) << std::endl;
            } else if(op == mtac::Operator::SUB){
                std::cout << "\t" << quadruple->result->name() << " = " << printArg(*quadruple->arg1) << " - " << printArg(*quadruple->arg2) << std::endl;
            } else if(op == mtac::Operator::FSUB){
                std::cout << "\t" << quadruple->result->name() << " = " << printArg(*quadruple->arg1) << " - (float) " << printArg(*quadruple->arg2) << std::endl;
            } else if(op == mtac::Operator::MUL){
                std::cout << "\t" << quadruple->result->name() << " = " << printArg(*quadruple->arg1) << " * " << printArg(*quadruple->arg2) << std::endl;
            } else if(op == mtac::Operator::FMUL){
                std::cout << "\t" << quadruple->result->name() << " = " << printArg(*quadruple->arg1) << " * (float) " << printArg(*quadruple->arg2) << std::endl;
            } else if(op == mtac::Operator::DIV){<commit_msg>Adapt the printer for the new basic blocks types<commit_after>//=======================================================================
// Copyright <NAME> 2011.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================

#include <iostream>
#include <memory>

#include <boost/variant.hpp>

#include "mtac/Printer.hpp"
#include "mtac/Program.hpp"

#include "VisitorUtils.hpp"
#include "Utils.hpp"

using namespace eddic;

namespace {

struct ArgumentToString : public boost::static_visitor<std::string> {
   std::string operator()(std::shared_ptr<Variable>& variable) const {
        return variable->name();   
   }

   std::string operator()(int& integer) const {
        return toString(integer);
   }
   
   std::string operator()(double& float_) const {
        return toString(float_);
   }

   std::string operator()(std::string& str) const {
        return str;
   }
};

std::string printArg(mtac::Argument& arg){
    return visit(ArgumentToString(), arg);
}

struct DebugVisitor : public boost::static_visitor<> {
    void operator()(std::shared_ptr<mtac::Program> program){
        std::cout << "TAC Program " << std::endl << std::endl; 

        visit_each_non_variant(*this, program->functions);
    }

    void operator()(std::shared_ptr<mtac::Function>& function){
        std::cout << "Function " << function->getName() << std::endl;

        visit_each(*this, function->getStatements());
        visit_each_non_variant(*this, function->getBasicBlocks());

        std::cout << std::endl;
    }

    void operator()(std::shared_ptr<mtac::BasicBlock>& block){
        if(block->index == -1){
            std::cout << "ENTRY" << std::endl;
        } else if(block->index == -2){
            std::cout << "EXIT" << std::endl;
        } else {
            std::cout << "B" << block->index << "->" << std::endl;
            visit_each(*this, block->statements);     
        }
    }

    void operator()(mtac::Statement& statement){
        visit(*this, statement);
    }

    void operator()(std::shared_ptr<mtac::Quadruple>& quadruple){
        if(quadruple->op == mtac::Operator::ASSIGN){
            std::cout << "\t" << quadruple->result->name() << " = (normal) " << printArg(*quadruple->arg1) << std::endl;
        } else if(quadruple->op == mtac::Operator::FASSIGN){
            std::cout << "\t" << quadruple->result->name() << " = (float) " << printArg(*quadruple->arg1) << std::endl;
        } else {
            mtac::Operator op = quadruple->op;

            if(op == mtac::Operator::ADD){
                std::cout << "\t" << quadruple->result->name() << " = " << printArg(*quadruple->arg1) << " + " << printArg(*quadruple->arg2) << std::endl;
            } else if(op == mtac::Operator::FADD){
                std::cout << "\t" << quadruple->result->name() << " = " << printArg(*quadruple->arg1) << " + (float) " << printArg(*quadruple->arg2) << std::endl;
            } else if(op == mtac::Operator::SUB){
                std::cout << "\t" << quadruple->result->name() << " = " << printArg(*quadruple->arg1) << " - " << printArg(*quadruple->arg2) << std::endl;
            } else if(op == mtac::Operator::FSUB){
                std::cout << "\t" << quadruple->result->name() << " = " << printArg(*quadruple->arg1) << " - (float) " << printArg(*quadruple->arg2) << std::endl;
            } else if(op == mtac::Operator::MUL){
                std::cout << "\t" << quadruple->result->name() << " = " << printArg(*quadruple->arg1) << " * " << printArg(*quadruple->arg2) << std::endl;
            } else if(op == mtac::Operator::FMUL){
                std::cout << "\t" << quadruple->result->name() << " = " << printArg(*quadruple->arg1) << " * (float) " << printArg(*quadruple->arg2) << std::endl;
            } else if(op == mtac::Operator::DIV){
{'fraction_non_alphanumeric': 0.23618549967341607, 'fraction_numerical': 0.006531678641410843, 'mean_word_length': 3.1518438177874186, 'pattern_counts': {'":': 0, '<': 285, '<?xml version=': 0, '>': 109, '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': '879092', 'n_tokens_mistral': 2418, 'n_tokens_neox': 2334, 'n_words': 411}