<commit_before>#include "pch.h"
#include "GameMenuLayer.h"
#include "ResourceManager.h"
#include "ButtonLayer.h"

GameMenuLayer::GameMenuLayer()
{

}

GameMenuLayer::~GameMenuLayer()
{

}

bool GameMenuLayer::init()
{
	if (!Layer::init())
	{
		return false;
	}
	auto winSize = cocos2d::Director::getInstance()->getWinSize();
	m_WinWidth = winSize.width;
	m_WinHeight = winSize.height;

	m_GameMenuBackGround = GET_RESOURCE_MANAGER()->createSprite(ST_GAMEMENU_BACKGROUND);
	m_GameMenuFrame = GET_RESOURCE_MANAGER()->createSprite(ST_GAMEMENU_FRAME);

	setUIProperties(m_GameMenuBackGround, cocos2d::Point(0.5, 0.5), cocos2d::Point(m_WinWidth / 2, m_WinHeight / 2), 0.75f, false, 50);
	setUIProperties(m_GameMenuFrame, cocos2d::Point(0.5, 0.5), cocos2d::Point(m_WinWidth / 2, m_WinHeight / 2), 0.75f, false, 51);

	m_Button1 = ButtonLayer::create();
	m_Button2 = ButtonLayer::create();
	m_Button1->setButtonProperties(BUTTON_GAMEMENU, cocos2d::Point(m_GameMenuFrame->getBoundingBox().getMinX(), m_GameMenuFrame->getBoundingBox().getMinY()),
									cocos2d::Point(m_GameMenuFrame->getContentSize().width / 2, m_GameMenuFrame->getContentSize().height / 2), "Resume");
	m_Button2->setButtonProperties(BUTTON_GAMEMENU, cocos2d::Point(m_GameMenuFrame->getBoundingBox().getMinX(), m_GameMenuFrame->getBoundingBox().getMinY()),
									cocos2d::Point(m_GameMenuFrame->getContentSize().width / 2, m_GameMenuFrame->getContentSize().height / 2 - 55), "Save and Quit");

	//temporary buttons
	m_Button1->setButtonFunc(std::bind(&GameMenuLayer::quitGame, this));
	m_Button2->setButtonFunc(std::bind(&GameMenuLayer::quitGame, this));

	//add Children
	m_GameMenuFrame->addChild(m_Button1);
	m_GameMenuFrame->addChild(m_Button2);
	this->addChild(m_GameMenuBackGround);
	this->addChild(m_GameMenuFrame);
	return true;
}

void GameMenuLayer::update(float dTime)
{
	m_Button1->update(dTime);
	m_Button2->update(dTime);

}

void GameMenuLayer::resumeGame()
{

}

void GameMenuLayer::quitGame()
{
	exit(0);
}

void GameMenuLayer::showGameMenu()
{
	m_GameMenuBackGround->setVisible(true);
	m_GameMenuFrame->setVisible(true);
	m_Button1->setButtonRect(cocos2d::Point(m_GameMenuFrame->getBoundingBox().getMinX(), m_GameMenuFrame->getBoundingBox().getMinY()));
	m_Button2->setButtonRect(cocos2d::Point(m_GameMenuFrame->getBoundingBox().getMinX(), m_GameMenuFrame->getBoundingBox().getMinY()));
}

void GameMenuLayer::hideGameMenu()
{
	m_GameMenuBackGround->setVisible(false);
	m_GameMenuFrame->setVisible(false);
	m_Button1->setButtonRect(cocos2d::Point(m_WinWidth, m_WinHeight));
	m_Button2->setButtonRect(cocos2d::Point(m_WinWidth, m_WinHeight));

}
<commit_msg>game 중 클릭 종료 버그 수정<commit_after>#include "pch.h"
#include "GameMenuLayer.h"
#include "ResourceManager.h"
#include "ButtonLayer.h"

GameMenuLayer::GameMenuLayer()
{

}

GameMenuLayer::~GameMenuLayer()
{

}

bool GameMenuLayer::init()
{
	if (!Layer::init())
	{
		return false;
	}
	auto winSize = cocos2d::Director::getInstance()->getWinSize();
	m_WinWidth = winSize.width;
	m_WinHeight = winSize.height;

	m_GameMenuBackGround = GET_RESOURCE_MANAGER()->createSprite(ST_GAMEMENU_BACKGROUND);
	m_GameMenuFrame = GET_RESOURCE_MANAGER()->createSprite(ST_GAMEMENU_FRAME);

	setUIProperties(m_GameMenuBackGround, cocos2d::Point(0.5, 0.5), cocos2d::Point(m_WinWidth / 2, m_WinHeight / 2), 0.75f, false, 50);
	setUIProperties(m_GameMenuFrame, cocos2d::Point(0.5, 0.5), cocos2d::Point(m_WinWidth / 2, m_WinHeight / 2), 0.75f, false, 51);

	m_Button1 = ButtonLayer::create();
	m_Button2 = ButtonLayer::create();
	m_Button1->setButtonProperties(BUTTON_GAMEMENU, cocos2d::Point(m_GameMenuFrame->getBoundingBox().getMinX(), m_GameMenuFrame->getBoundingBox().getMinY()),
									cocos2d::Point(m_GameMenuFrame->getContentSize().width / 2, m_GameMenuFrame->getContentSize().height / 2), "Resume");
	m_Button2->setButtonProperties(BUTTON_GAMEMENU, cocos2d::Point(m_GameMenuFrame->getBoundingBox().getMinX(), m_GameMenuFrame->getBoundingBox().getMinY()),
									cocos2d::Point(m_GameMenuFrame->getContentSize().width / 2, m_GameMenuFrame->getContentSize().height / 2 - 55), "Save and Quit");

	//temporary buttons
	m_Button1->setButtonFunc(std::bind(&GameMenuLayer::quitGame, this));
	m_Button2->setButtonFunc(std::bind(&GameMenuLayer::quitGame, this));
	hideGameMenu();
	//add Children
	m_GameMenuFrame->addChild(m_Button1);
	m_GameMenuFrame->addChild(m_Button2);
	this->addChild(m_GameMenuBackGround);
	this->addChild(m_GameMenuFrame);
	return true;
}

void GameMenuLayer::update(float dTime)
{
	m_Button1->update(dTime);
	m_Button2->update(dTime);

}

void GameMenuLayer::resumeGame()
{

}

void GameMenuLayer::quitGame()
{
	exit(0);
}

void GameMenuLayer::showGameMenu()
{
	m_GameMenuBackGround->setVisible(true);
	m_GameMenuFrame->setVisible(true);
	m_Button1->setButtonRect(cocos2d::Point(m_GameMenuFrame->getBoundingBox().getMinX(), m_GameMenuFrame->getBoundingBox().getMinY()));
	m_Button2->setButtonRect(cocos2d::Point(m_GameMenuFrame->getBoundingBox().getMinX(), m_GameMenuFrame->getBoundingBox().getMinY()));
}

void GameMenuLayer::hideGameMenu()
{
	m_GameMenuBackGround->setVisible(false);
	m_GameMenuFrame->setVisible(false);
	m_Button1->setButtonRect(cocos2d::Point(m_WinWidth, m_WinHeight));
	m_Button2->setButtonRect(cocos2d::Point(m_WinWidth, m_WinHeight));

}
<|endoftext|>


<commit_before>/* The MIT License (MIT)
 *
 * Copyright (c) 2016 Ștefan-Gabriel Mirea, Adrian Dobrică
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include "elf_file.hpp"
#include "elf_header_container.hpp"
#include "program_header_table_container.hpp"
#include "section_header_table_container.hpp"
#include "segment_contents_container.hpp"
#include "section_contents_container.hpp"
#include <utility>

using namespace elf;

ELFFile::ELFFile(const std::string &filename) : FileUnit(filename), formatName("ELF")
{
    loadFile(filename);
}

const std::string &ELFFile::getFormatName()
{
    return formatName;
}

ELFFile::~ELFFile()
{
    delete file;
}

bool ELFFile::getOpenStatus()
{
    return open;
}

bool ELFFile::save(std::string &filename)
{
    return file->save(filename);
}

void ELFFile::modifyHex(size_t offset, std::string &newContent) {}

ELFIO::elfio *ELFFile::getELFIO()
{
    return file;
}

bool ELFFile::loadFile(const std::string &filename)
{
    file = new ELFIO::elfio();
    open = file->load(filename);
    if (open && file->get_type() != ET_EXEC)
        open = false;

    std::vector<Container *> &topLevelContainers = getTopLevelContainers();
    topLevelContainers.clear();

    if (open)
    {
        topLevelContainers.push_back(new ELFHeaderContainer(this, std::make_pair(0, file->get_header_size())));
        topLevelContainers.push_back(new ProgramHeaderTableContainer(this, std::make_pair(10, 20)));
        topLevelContainers.push_back(new SectionHeaderTableContainer(this, std::make_pair(20, 30)));
        topLevelContainers.push_back(new SegmentContentsContainer(this));
        topLevelContainers.push_back(new SectionContentsContainer(this));
    }

    return open;
}
<commit_msg>Handle ELFIO crash for 64-bit executable with corrupted e_ehsize<commit_after>/* The MIT License (MIT)
 *
 * Copyright (c) 2016 Ștefan-Gabriel Mirea, Adrian Dobrică
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include "elf_file.hpp"
#include "elf_header_container.hpp"
#include "program_header_table_container.hpp"
#include "section_header_table_container.hpp"
#include "segment_contents_container.hpp"
#include "section_contents_container.hpp"
#include <utility>

using namespace elf;

ELFFile::ELFFile(const std::string &filename) : FileUnit(filename), formatName("ELF")
{
    loadFile(filename);
}

const std::string &ELFFile::getFormatName()
{
    return formatName;
}

ELFFile::~ELFFile()
{
    delete file;
}

bool ELFFile::getOpenStatus()
{
    return open;
}

bool ELFFile::save(std::string &filename)
{
    return file->save(filename);
}

void ELFFile::modifyHex(size_t offset, std::string &newContent) {}

ELFIO::elfio *ELFFile::getELFIO()
{
    return file;
}

bool ELFFile::loadFile(const std::string &filename)
{
    file = new ELFIO::elfio();
    try
    {
        open = file->load(filename);
    }
    catch (std::exception &e)
    {
#ifdef DEBUG
        std::cerr << "Caught " << e.what() << " in LEFIO::load.\n";
#endif
        open = false;
    }

    if (open && file->get_type() != ET_EXEC)
        open = false;

    std::vector<Container *> &topLevelContainers = getTopLevelContainers();
    topLevelContainers.clear();

    if (open)
    {
        topLevelContainers.push_back(new ELFHeaderContainer(this, std::make_pair(0, file->get_header_size())));
        topLevelContainers.push_back(new ProgramHeaderTableContainer(this, std::make_pair(10, 20)));
        topLevelContainers.push_back(new SectionHeaderTableContainer(this, std::make_pair(20, 30)));
        topLevelContainers.push_back(new SegmentContentsContainer(this));
        topLevelContainers.push_back(new SectionContentsContainer(this));
    }

    return open;
}
<|endoftext|>


<commit_before>// Copyright (C) 2015 Elviss Strazdins
// This file is part of the Ouzel engine.

#include "Engine.h"
#include "CompileConfig.h"

#ifdef OUZEL_PLATFORM_OSX
#include "RendererOGL.h"
#endif

#ifdef OUZEL_PLATFORM_WINDOWS
#include "RendererD3D11.h"
#endif

#include "Utils.h"
#include "Renderer.h"
#include "Scene.h"
#include "SoundManager.h"
#include "FileSystem.h"

void OuzelInit(ouzel::Settings&);
void OuzelBegin(ouzel::Engine*);
void OuzelEnd();

namespace ouzel
{
    Engine::Engine()
    {
        Settings settings;

        OuzelInit(settings);

        switch (settings.driver)
        {
            case Renderer::Driver::OPENGL:
#ifdef OUZEL_PLATFORM_OSX
                _renderer = new RendererOGL(settings.size, settings.fullscreen, this);
#endif
				break;
            case Renderer::Driver::DIRECT3D11:
#ifdef OUZEL_PLATFORM_WINDOWS
                _renderer = new RendererD3D11(settings.size, settings.fullscreen, this);
#endif
                break;
            default:
                _renderer = new Renderer(settings.size, settings.fullscreen, this);
                break;
        }

        _scene = new Scene(this);
        _scene->init();

        _soundManager = new SoundManager(this);

        _fileSystem = new FileSystem();

        _previousFrameTime = getCurrentMicroSeconds();
    }

    Engine::~Engine()
    {
        OuzelEnd();

        if (_renderer) _renderer->release();
        if (_scene) _scene->release();
        if (_fileSystem) _fileSystem->release();
    }

    void Engine::begin()
    {
        OuzelBegin(this);
    }

    void Engine::run()
    {
        _renderer->begin();
        _renderer->clear();
        _scene->drawAll();
        _renderer->flush();

        for (EventHandler* eventHandler : _eventHandlers)
        {
            uint64_t currentTime = getCurrentMicroSeconds();
            uint64_t delta = currentTime - _previousFrameTime;
            _previousFrameTime = currentTime;

            eventHandler->update(static_cast<float>(delta));
        }
    }

    void Engine::addEventHandler(EventHandler* eventHandler)
    {
        std::vector<EventHandler*>::iterator i = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler);

        if (i == _eventHandlers.end())
        {
            _eventHandlers.push_back(eventHandler);
        }
    }

    void Engine::removeEventHandler(EventHandler* eventHandler)
    {
        std::vector<EventHandler*>::iterator i = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler);

        if (i != _eventHandlers.end())
        {
            _eventHandlers.erase(i);
        }
    }

    void Engine::handleEvent(const Event& event)
    {
        for (EventHandler* eventHandler : _eventHandlers)
        {
            if (!eventHandler->handleEvent(event))
            {
                break;
            }
        }
    }
}
<commit_msg>Create a default Renderer if none is available<commit_after>// Copyright (C) 2015 Elviss Strazdins
// This file is part of the Ouzel engine.

#include "Engine.h"
#include "CompileConfig.h"

#if defined(OUZEL_PLATFORM_OSX) || defined(OUZEL_PLATFORM_IOS)
#include "RendererOGL.h"
#endif

#ifdef OUZEL_PLATFORM_WINDOWS
#include "RendererD3D11.h"
#endif

#include "Utils.h"
#include "Renderer.h"
#include "Scene.h"
#include "SoundManager.h"
#include "FileSystem.h"

void OuzelInit(ouzel::Settings&);
void OuzelBegin(ouzel::Engine*);
void OuzelEnd();

namespace ouzel
{
    Engine::Engine()
    {
        Settings settings;

        OuzelInit(settings);

        switch (settings.driver)
        {
#if defined(OUZEL_PLATFORM_OSX) || defined(OUZEL_PLATFORM_IOS)
            case Renderer::Driver::OPENGL:
                _renderer = new RendererOGL(settings.size, settings.fullscreen, this);
				break;
#endif
#ifdef OUZEL_PLATFORM_WINDOWS
            case Renderer::Driver::DIRECT3D11:

                _renderer = new RendererD3D11(settings.size, settings.fullscreen, this);
                break;
#endif
            default:
                _renderer = new Renderer(settings.size, settings.fullscreen, this);
                break;
        }

        _scene = new Scene(this);
        _scene->init();

        _soundManager = new SoundManager(this);

        _fileSystem = new FileSystem();

        _previousFrameTime = getCurrentMicroSeconds();
    }

    Engine::~Engine()
    {
        OuzelEnd();

        if (_renderer) _renderer->release();
        if (_scene) _scene->release();
        if (_fileSystem) _fileSystem->release();
    }

    void Engine::begin()
    {
        OuzelBegin(this);
    }

    void Engine::run()
    {
        _renderer->begin();
        _renderer->clear();
        _scene->drawAll();
        _renderer->flush();

        for (EventHandler* eventHandler : _eventHandlers)
        {
            uint64_t currentTime = getCurrentMicroSeconds();
            uint64_t delta = currentTime - _previousFrameTime;
            _previousFrameTime = currentTime;

            eventHandler->update(static_cast<float>(delta));
        }
    }

    void Engine::addEventHandler(EventHandler* eventHandler)
    {
        std::vector<EventHandler*>::iterator i = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler);

        if (i == _eventHandlers.end())
        {
            _eventHandlers.push_back(eventHandler);
        }
    }

    void Engine::removeEventHandler(EventHandler* eventHandler)
    {
        std::vector<EventHandler*>::iterator i = std::find(_eventHandlers.begin(), _eventHandlers.end(), eventHandler);

        if (i != _eventHandlers.end())
        {
            _eventHandlers.erase(i);
        }
    }

    void Engine::handleEvent(const Event& event)
    {
        for (EventHandler* eventHandler : _eventHandlers)
        {
            if (!eventHandler->handleEvent(event))
            {
                break;
            }
        }
    }
}
<|endoftext|>


<commit_before>//
//  CRTMachine.hpp
//  Clock Signal
//
//  Created by Thomas Harte on 31/05/2016.
//  Copyright 2016 Thomas Harte. All rights reserved.
//

#ifndef CRTMachine_hpp
#define CRTMachine_hpp

#include "../Outputs/ScanTarget.hpp"
#include "../Outputs/Speaker/Speaker.hpp"
#include "../ClockReceiver/ClockReceiver.hpp"
#include "../ClockReceiver/TimeTypes.hpp"
#include "ROMMachine.hpp"

#include "../Configurable/StandardOptions.hpp"

#include <cmath>

// TODO: rename.
namespace CRTMachine {

/*!
	A CRTMachine::Machine is a mostly-abstract base class for machines that connect to a CRT,
	that optionally provide a speaker, and that nominate a clock rate and can announce to a delegate
	should that clock rate change.
*/
class Machine {
	public:
		/*!
			Causes the machine to set up its display and, if it has one, speaker.

			The @c scan_target will receive all video output; the caller guarantees
			that it is non-null.
		*/
		virtual void set_scan_target(Outputs::Display::ScanTarget *scan_target) = 0;

		/// @returns The speaker that receives this machine's output, or @c nullptr if this machine is mute.
		virtual Outputs::Speaker::Speaker *get_speaker() = 0;

		/// @returns The confidence that this machine is running content it understands.
		virtual float get_confidence() { return 0.5f; }
		virtual std::string debug_type() { return ""; }

		/// Runs the machine for @c duration seconds.
		virtual void run_for(Time::Seconds duration) {
			const double cycles = (duration * clock_rate_) + clock_conversion_error_;
			clock_conversion_error_ = std::fmod(cycles, 1.0);
			run_for(Cycles(static_cast<int>(cycles)));
		}

	protected:
		/// Runs the machine for @c cycles.
		virtual void run_for(const Cycles cycles) = 0;
		void set_clock_rate(double clock_rate) {
			clock_rate_ = clock_rate;
		}
		double get_clock_rate() {
			return clock_rate_;
		}

		/*!
			Maps from Configurable::Display to Outputs::Display::VideoSignal and calls
			@c set_display_type with the result.
		*/
		void set_video_signal_configurable(Configurable::Display type) {
			Outputs::Display::DisplayType display_type;
			switch(type) {
				default:
				case Configurable::Display::RGB:
					display_type = Outputs::Display::DisplayType::RGB;
				break;
				case Configurable::Display::SVideo:
					display_type = Outputs::Display::DisplayType::SVideo;
				break;
				case Configurable::Display::CompositeColour:
					display_type = Outputs::Display::DisplayType::CompositeColour;
				break;
				case Configurable::Display::CompositeMonochrome:
					display_type = Outputs::Display::DisplayType::CompositeMonochrome;
				break;
			}
			set_display_type(display_type);
		}

		/*!
			Forwards the video signal to the target returned by get_crt().
		*/
		virtual void set_display_type(Outputs::Display::DisplayType display_type) {}

	private:
		double clock_rate_ = 1.0;
		double clock_conversion_error_ = 0.0;
};

}

#endif /* CRTMachine_hpp */
<commit_msg>Adds CRTMachine::run_until, which will run until a condition is true.<commit_after>//
//  CRTMachine.hpp
//  Clock Signal
//
//  Created by Thomas Harte on 31/05/2016.
//  Copyright 2016 Thomas Harte. All rights reserved.
//

#ifndef CRTMachine_hpp
#define CRTMachine_hpp

#include "../Outputs/ScanTarget.hpp"
#include "../Outputs/Speaker/Speaker.hpp"
#include "../ClockReceiver/ClockReceiver.hpp"
#include "../ClockReceiver/TimeTypes.hpp"
#include "ROMMachine.hpp"

#include "../Configurable/StandardOptions.hpp"

#include <cmath>

// TODO: rename.
namespace CRTMachine {

/*!
	A CRTMachine::Machine is a mostly-abstract base class for machines that connect to a CRT,
	that optionally provide a speaker, and that nominate a clock rate and can announce to a delegate
	should that clock rate change.
*/
class Machine {
	public:
		/*!
			Causes the machine to set up its display and, if it has one, speaker.

			The @c scan_target will receive all video output; the caller guarantees
			that it is non-null.
		*/
		virtual void set_scan_target(Outputs::Display::ScanTarget *scan_target) = 0;

		/// @returns The speaker that receives this machine's output, or @c nullptr if this machine is mute.
		virtual Outputs::Speaker::Speaker *get_speaker() = 0;

		/// @returns The confidence that this machine is running content it understands.
		virtual float get_confidence() { return 0.5f; }
		virtual std::string debug_type() { return ""; }

		/// Runs the machine for @c duration seconds.
		void run_for(Time::Seconds duration) {
			const double cycles = (duration * clock_rate_) + clock_conversion_error_;
			clock_conversion_error_ = std::fmod(cycles, 1.0);
			run_for(Cycles(static_cast<int>(cycles)));
		}

		/// Runs for the machine for at least @c duration seconds, and then until @c condition is true.
		void run_until(Time::Seconds minimum_duration, std::function<bool()> condition) {
			run_for(minimum_duration);
			while(!condition()) {
				run_for(0.002);
			}
		}

	protected:
		/// Runs the machine for @c cycles.
		virtual void run_for(const Cycles cycles) = 0;
		void set_clock_rate(double clock_rate) {
			clock_rate_ = clock_rate;
		}
		double get_clock_rate() {
			return clock_rate_;
		}

		/*!
			Maps from Configurable::Display to Outputs::Display::VideoSignal and calls
			@c set_display_type with the result.
		*/
		void set_video_signal_configurable(Configurable::Display type) {
			Outputs::Display::DisplayType display_type;
			switch(type) {
				default:
				case Configurable::Display::RGB:
					display_type = Outputs::Display::DisplayType::RGB;
				break;
				case Configurable::Display::SVideo:
					display_type = Outputs::Display::DisplayType::SVideo;
				break;
				case Configurable::Display::CompositeColour:
					display_type = Outputs::Display::DisplayType::CompositeColour;
				break;
				case Configurable::Display::CompositeMonochrome:
					display_type = Outputs::Display::DisplayType::CompositeMonochrome;
				break;
			}
			set_display_type(display_type);
		}

		/*!
			Forwards the video signal to the target returned by get_crt().
		*/
		virtual void set_display_type(Outputs::Display::DisplayType display_type) {}

	private:
		double clock_rate_ = 1.0;
		double clock_conversion_error_ = 0.0;
};

}

#endif /* CRTMachine_hpp */
<|endoftext|>


<commit_before>// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/external_cookie_handler.h"

#include <set>
#include <vector>

#include "base/basictypes.h"
#include "base/time.h"
#include "googleurl/src/gurl.h"
#include "net/base/cookie_options.h"
#include "net/base/cookie_store.h"
#include "testing/gtest/include/gtest/gtest.h"

typedef testing::Test ExternalCookieHandlerTest;

static const std::string cookie1 = "coookie1\n";
static const std::string cookie2 = "coookie2\n";
static const std::string cookie3 = "coookie3";

class MockCookieStore : public net::CookieStore {
 public:
  MockCookieStore() : expected_url_(ExternalCookieHandler::kGoogleAccountsUrl) {
    cookies_.insert(cookie1);
    cookies_.insert(cookie2);
    cookies_.insert(cookie3);
  }
  virtual ~MockCookieStore() {}

  virtual bool SetCookie(const GURL& url, const std::string& cookie_line) {
    EXPECT_TRUE(false);
    return true;
  }
  virtual bool SetCookieWithOptions(const GURL& url,
                                    const std::string& cookie_line,
                                    const net::CookieOptions& options) {
    EXPECT_FALSE(options.exclude_httponly());
    EXPECT_EQ(expected_url_, url);
    std::set<std::string>::iterator it;
    it = cookies_.find(cookie_line);
    bool has_cookie = cookies_.end() != it;
    if (has_cookie)
      cookies_.erase(it);
    return has_cookie;
  }

  virtual bool SetCookieWithCreationTime(const GURL& url,
                                         const std::string& cookie_line,
                                         const base::Time& creation_time) {
    EXPECT_TRUE(false);
    return true;
  }
  virtual bool SetCookieWithCreationTimeWithOptions(
                                         const GURL& url,
                                         const std::string& cookie_line,
                                         const base::Time& creation_time,
                                         const net::CookieOptions& options) {
    EXPECT_TRUE(false);
    return true;
  }

  virtual void SetCookies(const GURL& url,
                          const std::vector<std::string>& cookies) {
    EXPECT_TRUE(false);
  }
  virtual void SetCookiesWithOptions(const GURL& url,
                                     const std::vector<std::string>& cookies,
                                     const net::CookieOptions& options) {
    EXPECT_TRUE(false);
  }

  virtual std::string GetCookies(const GURL& url) {
    EXPECT_TRUE(false);
    return std::string();
  }
  virtual std::string GetCookiesWithOptions(const GURL& url,
                                            const net::CookieOptions& options) {
    EXPECT_TRUE(false);
    return std::string();
  }

 private:
  std::set<std::string> cookies_;
  const GURL expected_url_;

  DISALLOW_EVIL_CONSTRUCTORS(MockCookieStore);
};

TEST_F(ExternalCookieHandlerTest, MockCookieStoreSanityTest) {
  GURL url(ExternalCookieHandler::kGoogleAccountsUrl);
  MockCookieStore cookie_store;
  net::CookieOptions options;
  options.set_include_httponly();
  EXPECT_TRUE(cookie_store.SetCookieWithOptions(url, cookie1, options));
  EXPECT_TRUE(cookie_store.SetCookieWithOptions(url, cookie2, options));
  EXPECT_TRUE(cookie_store.SetCookieWithOptions(url, cookie3, options));
  EXPECT_FALSE(cookie_store.SetCookieWithOptions(url, cookie1, options));
  EXPECT_FALSE(cookie_store.SetCookieWithOptions(url, cookie2, options));
  EXPECT_FALSE(cookie_store.SetCookieWithOptions(url, cookie3, options));
}

class MockReader : public PipeReader {
 public:
  explicit MockReader(const std::vector<std::string>& cookies)
      : data_(cookies) {
  }

  std::string Read(const uint32 bytes_to_read) {
    std::string to_return;
    if (!data_.empty()) {
      to_return = data_.back();
      data_.pop_back();
    }
    return to_return;
  }
 private:
  std::vector<std::string> data_;
};

TEST_F(ExternalCookieHandlerTest, SuccessfulReadTest) {
  GURL url(ExternalCookieHandler::kGoogleAccountsUrl);

  MockCookieStore cookie_store;

  std::vector<std::string> cookies;
  cookies.push_back(cookie3);
  cookies.push_back(cookie2);
  cookies.push_back(cookie1);
  MockReader *reader = new MockReader(cookies);

  ExternalCookieHandler handler(reader);  // takes ownership.
  EXPECT_TRUE(handler.HandleCookies(&cookie_store));
}

TEST_F(ExternalCookieHandlerTest, SuccessfulSlowReadTest) {
  GURL url(ExternalCookieHandler::kGoogleAccountsUrl);

  MockCookieStore cookie_store;

  std::vector<std::string> cookies;
  cookies.push_back(cookie3);
  cookies.push_back(cookie2.substr(2));
  cookies.push_back(cookie2.substr(0, 2));
  cookies.push_back(cookie1);
  MockReader *reader = new MockReader(cookies);

  ExternalCookieHandler handler(reader);  // takes ownership.
  EXPECT_TRUE(handler.HandleCookies(&cookie_store));
}
<commit_msg>Disabling failing ExternalCookieHandlerTest tests<commit_after>// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/external_cookie_handler.h"

#include <set>
#include <vector>

#include "base/basictypes.h"
#include "base/time.h"
#include "googleurl/src/gurl.h"
#include "net/base/cookie_options.h"
#include "net/base/cookie_store.h"
#include "testing/gtest/include/gtest/gtest.h"

typedef testing::Test ExternalCookieHandlerTest;

static const std::string cookie1 = "coookie1\n";
static const std::string cookie2 = "coookie2\n";
static const std::string cookie3 = "coookie3";

class MockCookieStore : public net::CookieStore {
 public:
  MockCookieStore() : expected_url_(ExternalCookieHandler::kGoogleAccountsUrl) {
    cookies_.insert(cookie1);
    cookies_.insert(cookie2);
    cookies_.insert(cookie3);
  }
  virtual ~MockCookieStore() {}

  virtual bool SetCookie(const GURL& url, const std::string& cookie_line) {
    EXPECT_TRUE(false);
    return true;
  }
  virtual bool SetCookieWithOptions(const GURL& url,
                                    const std::string& cookie_line,
                                    const net::CookieOptions& options) {
    EXPECT_FALSE(options.exclude_httponly());
    EXPECT_EQ(expected_url_, url);
    std::set<std::string>::iterator it;
    it = cookies_.find(cookie_line);
    bool has_cookie = cookies_.end() != it;
    if (has_cookie)
      cookies_.erase(it);
    return has_cookie;
  }

  virtual bool SetCookieWithCreationTime(const GURL& url,
                                         const std::string& cookie_line,
                                         const base::Time& creation_time) {
    EXPECT_TRUE(false);
    return true;
  }
  virtual bool SetCookieWithCreationTimeWithOptions(
                                         const GURL& url,
                                         const std::string& cookie_line,
                                         const base::Time& creation_time,
                                         const net::CookieOptions& options) {
    EXPECT_TRUE(false);
    return true;
  }

  virtual void SetCookies(const GURL& url,
                          const std::vector<std::string>& cookies) {
    EXPECT_TRUE(false);
  }
  virtual void SetCookiesWithOptions(const GURL& url,
                                     const std::vector<std::string>& cookies,
                                     const net::CookieOptions& options) {
    EXPECT_TRUE(false);
  }

  virtual std::string GetCookies(const GURL& url) {
    EXPECT_TRUE(false);
    return std::string();
  }
  virtual std::string GetCookiesWithOptions(const GURL& url,
                                            const net::CookieOptions& options) {
    EXPECT_TRUE(false);
    return std::string();
  }

 private:
  std::set<std::string> cookies_;
  const GURL expected_url_;

  DISALLOW_EVIL_CONSTRUCTORS(MockCookieStore);
};

TEST_F(ExternalCookieHandlerTest, DISABLED_MockCookieStoreSanityTest) {
  GURL url(ExternalCookieHandler::kGoogleAccountsUrl);
  MockCookieStore cookie_store;
  net::CookieOptions options;
  options.set_include_httponly();
  EXPECT_TRUE(cookie_store.SetCookieWithOptions(url, cookie1, options));
  EXPECT_TRUE(cookie_store.SetCookieWithOptions(url, cookie2, options));
  EXPECT_TRUE(cookie_store.SetCookieWithOptions(url, cookie3, options));
  EXPECT_FALSE(cookie_store.SetCookieWithOptions(url, cookie1, options));
  EXPECT_FALSE(cookie_store.SetCookieWithOptions(url, cookie2, options));
  EXPECT_FALSE(cookie_store.SetCookieWithOptions(url, cookie3, options));
}

class MockReader : public PipeReader {
 public:
  explicit MockReader(const std::vector<std::string>& cookies)
      : data_(cookies) {
  }

  std::string Read(const uint32 bytes_to_read) {
    std::string to_return;
    if (!data_.empty()) {
      to_return = data_.back();
      data_.pop_back();
    }
    return to_return;
  }
 private:
  std::vector<std::string> data_;
};

TEST_F(ExternalCookieHandlerTest, DISABLED_SuccessfulReadTest) {
  GURL url(ExternalCookieHandler::kGoogleAccountsUrl);

  MockCookieStore cookie_store;

  std::vector<std::string> cookies;
  cookies.push_back(cookie3);
  cookies.push_back(cookie2);
  cookies.push_back(cookie1);
  MockReader *reader = new MockReader(cookies);

  ExternalCookieHandler handler(reader);  // takes ownership.
  EXPECT_TRUE(handler.HandleCookies(&cookie_store));
}

TEST_F(ExternalCookieHandlerTest, DISABLED_SuccessfulSlowReadTest) {
  GURL url(ExternalCookieHandler::kGoogleAccountsUrl);

  MockCookieStore cookie_store;

  std::vector<std::string> cookies;
  cookies.push_back(cookie3);
  cookies.push_back(cookie2.substr(2));
  cookies.push_back(cookie2.substr(0, 2));
  cookies.push_back(cookie1);
  MockReader *reader = new MockReader(cookies);

  ExternalCookieHandler handler(reader);  // takes ownership.
  EXPECT_TRUE(handler.HandleCookies(&cookie_store));
}
<|endoftext|>


<commit_before>// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "chrome/browser/media/webrtc_browsertest_base.h"
#include "chrome/browser/media/webrtc_browsertest_common.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/test/browser_test_utils.h"
#include "media/base/media_switches.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/perf/perf_test.h"
#include "ui/gl/gl_switches.h"

static const char kSimulcastTestPage[] = "/webrtc/webrtc-simulcast.html";

// Simulcast integration test. This test ensures 'a=x-google-flag:conference'
// is working and that Chrome is capable of sending simulcast streams.
class WebRtcSimulcastBrowserTest : public WebRtcTestBase {
 public:
  // TODO(phoglund): Make it possible to enable DetectErrorsInJavaScript() here.

  void SetUpCommandLine(base::CommandLine* command_line) override {
    // Just answer 'allow' to GetUserMedia invocations.
    command_line->AppendSwitch(switches::kUseFakeUIForMediaStream);

    // The video playback will not work without a GPU, so force its use here.
    command_line->AppendSwitch(switches::kUseGpuInTests);

    // Use fake devices in order to run on VMs.
    command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
  }
};

// Fails/times out on Win only.  http://crbug.com/452623
#if defined(OS_WIN)
#define MAYBE_TestVgaReturnsTwoSimulcastStreams DISABLED_TestVgaReturnsTwoSimulcastStreams
#else
#define MAYBE_TestVgaReturnsTwoSimulcastStreams TestVgaReturnsTwoSimulcastStreams
#endif
IN_PROC_BROWSER_TEST_F(WebRtcSimulcastBrowserTest,
                       MAYBE_TestVgaReturnsTwoSimulcastStreams) {
  ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());

  ui_test_utils::NavigateToURL(
      browser(), embedded_test_server()->GetURL(kSimulcastTestPage));

  content::WebContents* tab_contents =
      browser()->tab_strip_model()->GetActiveWebContents();

  ASSERT_EQ("OK", ExecuteJavascript("testVgaReturnsTwoSimulcastStreams()",
                                    tab_contents));
}
<commit_msg>Disable WebRtcSimulcastBrowserTest.TestVgaReturnsTwoSimulcastStreams under MSan<commit_after>// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "chrome/browser/media/webrtc_browsertest_base.h"
#include "chrome/browser/media/webrtc_browsertest_common.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/test/browser_test_utils.h"
#include "media/base/media_switches.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/perf/perf_test.h"
#include "ui/gl/gl_switches.h"

static const char kSimulcastTestPage[] = "/webrtc/webrtc-simulcast.html";

// Simulcast integration test. This test ensures 'a=x-google-flag:conference'
// is working and that Chrome is capable of sending simulcast streams.
class WebRtcSimulcastBrowserTest : public WebRtcTestBase {
 public:
  // TODO(phoglund): Make it possible to enable DetectErrorsInJavaScript() here.

  void SetUpCommandLine(base::CommandLine* command_line) override {
    // Just answer 'allow' to GetUserMedia invocations.
    command_line->AppendSwitch(switches::kUseFakeUIForMediaStream);

    // The video playback will not work without a GPU, so force its use here.
    command_line->AppendSwitch(switches::kUseGpuInTests);

    // Use fake devices in order to run on VMs.
    command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
  }
};

// Fails/times out on Win only.  http://crbug.com/452623
// MSan reports errors. http://crbug.com/452892
#if defined(OS_WIN) || defined(MEMORY_SANITIZER)
#define MAYBE_TestVgaReturnsTwoSimulcastStreams DISABLED_TestVgaReturnsTwoSimulcastStreams
#else
#define MAYBE_TestVgaReturnsTwoSimulcastStreams TestVgaReturnsTwoSimulcastStreams
#endif
IN_PROC_BROWSER_TEST_F(WebRtcSimulcastBrowserTest,
                       MAYBE_TestVgaReturnsTwoSimulcastStreams) {
  ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());

  ui_test_utils::NavigateToURL(
      browser(), embedded_test_server()->GetURL(kSimulcastTestPage));

  content::WebContents* tab_contents =
      browser()->tab_strip_model()->GetActiveWebContents();

  ASSERT_EQ("OK", ExecuteJavascript("testVgaReturnsTwoSimulcastStreams()",
                                    tab_contents));
}
<|endoftext|>


<commit_before>//
//  riscv-format.cc
//

#include <map>
#include <vector>
#include <string>

#include "riscv-opcodes.h"
#include "riscv-types.h"
#include "riscv-imm.h"
#include "riscv-regs.h"
#include "riscv-decode.h"
#include "riscv-regs.h"
#include "riscv-csr.h"
#include "riscv-processor.h"
#include "riscv-compression.h"
#include "riscv-util.h"
#include "riscv-format.h"

const rvf fmt_none[] =               { rvf_z };
const rvf fmt_ipc[] =                { rvf_ipc, rvf_z };
const rvf fmt_rs1_rs2[] =            { rvf_rs1, rvf_c, rvf_rs2, rvf_z };
const rvf fmt_rd_imm[] =             { rvf_rd, rvf_c, rvf_imm, rvf_z };
const rvf fmt_rd_ipc[] =             { rvf_rd, rvf_c, rvf_ipc, rvf_z };
const rvf fmt_rd_rs1_rs2[] =         { rvf_rd, rvf_c, rvf_rs1, rvf_c, rvf_rs2, rvf_z };
const rvf fmt_frd_frs1_frs2[] =      { rvf_frd, rvf_c, rvf_frs1, rvf_c, rvf_frs2, rvf_z };
const rvf fmt_rd_frs1_frs2[] =       { rvf_frd, rvf_c, rvf_rs1, rvf_c, rvf_frs2, rvf_z };
const rvf fmt_frd_frs1_frs2_frs3[] = { rvf_frd, rvf_c, rvf_frs1, rvf_c, rvf_frs2, rvf_c, rvf_frs3, rvf_z };
const rvf fmt_frd_rs1[] =            { rvf_frd, rvf_c, rvf_rs1, rvf_z };
const rvf fmt_frd_frs1[] =           { rvf_frd, rvf_c, rvf_frs1, rvf_z };
const rvf fmt_rd_frs1[] =            { rvf_rd, rvf_c, rvf_frs1, rvf_z };
const rvf fmt_rd_rs1_imm[] =         { rvf_rd, rvf_c, rvf_rs1, rvf_c, rvf_imm, rvf_z };
const rvf fmt_rd_bimm_rs1[] =        { rvf_rd, rvf_c, rvf_imm, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf fmt_frd_bimm_rs1[] =       { rvf_frd, rvf_c, rvf_imm, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf fmt_rd_csr_rs1[] =         { rvf_rd, rvf_c, rvf_csr, rvf_c, rvf_rs1, rvf_z };
const rvf fmt_rd_csr_irs1[] =        { rvf_rd, rvf_c, rvf_csr, rvf_c, rvf_irs1, rvf_z };
const rvf fmt_rs2_bimm_rs1[] =       { rvf_rs2, rvf_c, rvf_imm, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf fmt_frs2_bimm_rs1[] =      { rvf_frs2, rvf_c, rvf_imm, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf fmt_rs1_rs2_ipc[] =        { rvf_rs1, rvf_c, rvf_rs2, rvf_c, rvf_ipc, rvf_z };
const rvf fmt_rd_rs2_b_rs1[] =       { rvf_rd, rvf_c, rvf_rs2, rvf_c, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf fmt_rd_b_rs1[] =           { rvf_rd, rvf_c, rvf_b, rvf_rs1, rvf_d, rvf_z };

const riscv_inst_type_metadata riscv_inst_type_table[] = {
	{ riscv_inst_type_unknown,      fmt_none },
	{ riscv_inst_type_c_none,       fmt_none },
	{ riscv_inst_type_cb,           fmt_ipc },
	{ riscv_inst_type_ci,           fmt_rd_imm },
	{ riscv_inst_type_ci_16sp,      fmt_rd_rs1_imm },
	{ riscv_inst_type_ci_fldsp,     fmt_frd_bimm_rs1 },
	{ riscv_inst_type_ci_flwsp,     fmt_frd_bimm_rs1 },
	{ riscv_inst_type_ci_ldsp,      fmt_rd_bimm_rs1 },
	{ riscv_inst_type_ci_li,        fmt_rd_imm },
	{ riscv_inst_type_ci_lui,       fmt_rd_imm },
	{ riscv_inst_type_ci_lwsp,      fmt_rd_imm },
	{ riscv_inst_type_ciw_4spn,     fmt_rd_rs1_imm },
	{ riscv_inst_type_cj,           fmt_ipc },
	{ riscv_inst_type_cl_fld,       fmt_frd_bimm_rs1 },
	{ riscv_inst_type_cl_flw,       fmt_frd_bimm_rs1 },
	{ riscv_inst_type_cl_ld,        fmt_rd_bimm_rs1 },
	{ riscv_inst_type_cl_lw,        fmt_rd_bimm_rs1 },
	{ riscv_inst_type_cr,           fmt_rs1_rs2 },
	{ riscv_inst_type_cr_jalr,      fmt_rs1_rs2 },
	{ riscv_inst_type_cr_jr,        fmt_rs1_rs2 },
	{ riscv_inst_type_cs,           fmt_rs1_rs2 },
	{ riscv_inst_type_cs_fsd,       fmt_frs2_bimm_rs1 },
	{ riscv_inst_type_cs_fsw,       fmt_frs2_bimm_rs1 },
	{ riscv_inst_type_cs_sd,        fmt_rs2_bimm_rs1 },
	{ riscv_inst_type_cs_sw,        fmt_rs2_bimm_rs1 },
	{ riscv_inst_type_css_fswsp,    fmt_frs2_bimm_rs1 },
	{ riscv_inst_type_css_fsdsp,    fmt_frs2_bimm_rs1 },
	{ riscv_inst_type_css_swsp,     fmt_rs2_bimm_rs1 },
	{ riscv_inst_type_css_sdsp,     fmt_rs2_bimm_rs1 },
	{ riscv_inst_type_i,            fmt_rd_rs1_imm },
	{ riscv_inst_type_i_csr,        fmt_rd_csr_rs1 },
	{ riscv_inst_type_i_csri,       fmt_rd_csr_irs1 },
	{ riscv_inst_type_i_l,          fmt_rd_bimm_rs1 },
	{ riscv_inst_type_i_lf,         fmt_frd_bimm_rs1 },
	{ riscv_inst_type_i_none,       fmt_none },
	{ riscv_inst_type_i_sh5,        fmt_rd_rs1_imm },
	{ riscv_inst_type_i_sh6,        fmt_rd_rs1_imm },
	{ riscv_inst_type_r,            fmt_rd_rs1_rs2 },
	{ riscv_inst_type_r_3f,         fmt_frd_frs1_frs2 },
	{ riscv_inst_type_r_4f,         fmt_frd_frs1_frs2_frs3 },
	{ riscv_inst_type_r_a,          fmt_rd_rs2_b_rs1 },
	{ riscv_inst_type_r_ff,         fmt_frd_frs1 },
	{ riscv_inst_type_r_fr,         fmt_frd_rs1 },
	{ riscv_inst_type_r_l,          fmt_rd_b_rs1 },
	{ riscv_inst_type_r_rf,         fmt_rd_frs1 },
	{ riscv_inst_type_r_rff,        fmt_rd_frs1_frs2 },
	{ riscv_inst_type_s,            fmt_rs2_bimm_rs1 },
	{ riscv_inst_type_s_f,          fmt_frs2_bimm_rs1 },
	{ riscv_inst_type_sb,           fmt_rs1_rs2_ipc },
	{ riscv_inst_type_u,            fmt_rd_imm },
	{ riscv_inst_type_uj,           fmt_rd_ipc },
	{ riscv_inst_type_unknown,      nullptr }
};

/* Metadata Tables */

struct riscv_inst_type_map : std::map<riscv_inst_type,const riscv_inst_type_metadata*>
{
	riscv_inst_type_map() {
		for (const auto *ent = riscv_inst_type_table; ent->fmt; ent++)
			(*this)[ent->type] = ent;
	}
};

struct riscv_inst_comp_map : std::map<riscv_op,const riscv_inst_comp_metadata*>
{
	riscv_inst_comp_map() {
		for (const auto *ent = riscv_comp_table; ent->cop; ent++)
			(*this)[ent->cop] = ent;
	}
};

struct riscv_csr_map : std::map<riscv_hu,const riscv_csr_metadata*>
{
	riscv_csr_map() {
		for (const auto *ent = riscv_csr_table; ent->csr_value; ent++)
			(*this)[ent->csr_value] = ent;
	}
};

const riscv_inst_type_metadata* riscv_lookup_inst_metadata(riscv_inst_type type)
{
	static riscv_inst_type_map type_map;
	return type_map[type];
}

const riscv_inst_comp_metadata* riscv_lookup_comp_metadata(riscv_op op)
{
	static riscv_inst_comp_map comp_map;
	return comp_map[op];
}

const riscv_csr_metadata* riscv_lookup_csr_metadata(riscv_hu csr_value)
{
	static riscv_csr_map csr_map;
	return csr_map[csr_value];
}

void riscv_print_instruction(riscv_decode &dec, riscv_proc_state *proc, riscv_ptr pc, riscv_ptr pc_offset)
{
#if 1
	const riscv_inst_comp_metadata *comp = riscv_lookup_comp_metadata((riscv_op)dec.op);
	if (comp) {
		dec.op = comp->op;
		dec.type = comp->type;
	}
#endif
	const riscv_inst_type_metadata *inst_meta = riscv_lookup_inst_metadata((riscv_inst_type)dec.type);
	const rvf *fmt = inst_meta ? inst_meta->fmt : fmt_none;

	printf("%s", format_string("%016tx: \t", pc - pc_offset).c_str());
	switch (dec.sz) {
		case 2: printf("%s", format_string("%04x\t\t", *(riscv_hu*)pc).c_str()); break;
		case 4: printf("%s", format_string("%08x\t", *(riscv_wu*)pc).c_str()); break;
	}
	printf("%s\t", riscv_instructions[dec.op].opcode);

	while (*fmt != rvf_z) {
		switch (*fmt) {
			case rvf_b: printf("("); break;
			case rvf_c: printf(","); break;
			case rvf_d: printf(")"); break;
			case rvf_rd: printf("%s", riscv_i_registers[dec.rd]); break;
			case rvf_rs1: printf("%s", riscv_i_registers[dec.rs1]); break;
			case rvf_rs2: printf("%s", riscv_i_registers[dec.rs2]); break;
			case rvf_frd: printf("%s", riscv_f_registers[dec.rd]); break;
			case rvf_frs1: printf("%s", riscv_f_registers[dec.rs1]); break;
			case rvf_frs2: printf("%s", riscv_f_registers[dec.rs2]); break;
			case rvf_frs3: printf("%s", riscv_f_registers[dec.rs3]); break;
			case rvf_irs1: printf("%s", format_string("%d", dec.rs1).c_str()); break;
			case rvf_imm: printf("%s", format_string("%lld", dec.imm, dec.imm).c_str()); break;
			case rvf_ipc: printf("%s", format_string("%lld \t# 0x%016tx", dec.imm, pc - pc_offset + dec.imm).c_str()); break;
			case rvf_csr:
			{
				const riscv_csr_metadata *csr = riscv_lookup_csr_metadata(dec.imm);
				printf("%s", (csr ? csr->csr_name : format_string("%llu", dec.imm)).c_str());
				break;
			}
			case rvf_z: break;
		}
		fmt++;
	}
	printf("\n");
}
<commit_msg>Remove ifdef around opcode decompression<commit_after>//
//  riscv-format.cc
//

#include <map>
#include <vector>
#include <string>

#include "riscv-opcodes.h"
#include "riscv-types.h"
#include "riscv-imm.h"
#include "riscv-regs.h"
#include "riscv-decode.h"
#include "riscv-regs.h"
#include "riscv-csr.h"
#include "riscv-processor.h"
#include "riscv-compression.h"
#include "riscv-util.h"
#include "riscv-format.h"

const rvf fmt_none[] =               { rvf_z };
const rvf fmt_ipc[] =                { rvf_ipc, rvf_z };
const rvf fmt_rs1_rs2[] =            { rvf_rs1, rvf_c, rvf_rs2, rvf_z };
const rvf fmt_rd_imm[] =             { rvf_rd, rvf_c, rvf_imm, rvf_z };
const rvf fmt_rd_ipc[] =             { rvf_rd, rvf_c, rvf_ipc, rvf_z };
const rvf fmt_rd_rs1_rs2[] =         { rvf_rd, rvf_c, rvf_rs1, rvf_c, rvf_rs2, rvf_z };
const rvf fmt_frd_frs1_frs2[] =      { rvf_frd, rvf_c, rvf_frs1, rvf_c, rvf_frs2, rvf_z };
const rvf fmt_rd_frs1_frs2[] =       { rvf_frd, rvf_c, rvf_rs1, rvf_c, rvf_frs2, rvf_z };
const rvf fmt_frd_frs1_frs2_frs3[] = { rvf_frd, rvf_c, rvf_frs1, rvf_c, rvf_frs2, rvf_c, rvf_frs3, rvf_z };
const rvf fmt_frd_rs1[] =            { rvf_frd, rvf_c, rvf_rs1, rvf_z };
const rvf fmt_frd_frs1[] =           { rvf_frd, rvf_c, rvf_frs1, rvf_z };
const rvf fmt_rd_frs1[] =            { rvf_rd, rvf_c, rvf_frs1, rvf_z };
const rvf fmt_rd_rs1_imm[] =         { rvf_rd, rvf_c, rvf_rs1, rvf_c, rvf_imm, rvf_z };
const rvf fmt_rd_bimm_rs1[] =        { rvf_rd, rvf_c, rvf_imm, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf fmt_frd_bimm_rs1[] =       { rvf_frd, rvf_c, rvf_imm, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf fmt_rd_csr_rs1[] =         { rvf_rd, rvf_c, rvf_csr, rvf_c, rvf_rs1, rvf_z };
const rvf fmt_rd_csr_irs1[] =        { rvf_rd, rvf_c, rvf_csr, rvf_c, rvf_irs1, rvf_z };
const rvf fmt_rs2_bimm_rs1[] =       { rvf_rs2, rvf_c, rvf_imm, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf fmt_frs2_bimm_rs1[] =      { rvf_frs2, rvf_c, rvf_imm, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf fmt_rs1_rs2_ipc[] =        { rvf_rs1, rvf_c, rvf_rs2, rvf_c, rvf_ipc, rvf_z };
const rvf fmt_rd_rs2_b_rs1[] =       { rvf_rd, rvf_c, rvf_rs2, rvf_c, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf fmt_rd_b_rs1[] =           { rvf_rd, rvf_c, rvf_b, rvf_rs1, rvf_d, rvf_z };

const riscv_inst_type_metadata riscv_inst_type_table[] = {
	{ riscv_inst_type_unknown,      fmt_none },
	{ riscv_inst_type_c_none,       fmt_none },
	{ riscv_inst_type_cb,           fmt_ipc },
	{ riscv_inst_type_ci,           fmt_rd_imm },
	{ riscv_inst_type_ci_16sp,      fmt_rd_rs1_imm },
	{ riscv_inst_type_ci_fldsp,     fmt_frd_bimm_rs1 },
	{ riscv_inst_type_ci_flwsp,     fmt_frd_bimm_rs1 },
	{ riscv_inst_type_ci_ldsp,      fmt_rd_bimm_rs1 },
	{ riscv_inst_type_ci_li,        fmt_rd_imm },
	{ riscv_inst_type_ci_lui,       fmt_rd_imm },
	{ riscv_inst_type_ci_lwsp,      fmt_rd_imm },
	{ riscv_inst_type_ciw_4spn,     fmt_rd_rs1_imm },
	{ riscv_inst_type_cj,           fmt_ipc },
	{ riscv_inst_type_cl_fld,       fmt_frd_bimm_rs1 },
	{ riscv_inst_type_cl_flw,       fmt_frd_bimm_rs1 },
	{ riscv_inst_type_cl_ld,        fmt_rd_bimm_rs1 },
	{ riscv_inst_type_cl_lw,        fmt_rd_bimm_rs1 },
	{ riscv_inst_type_cr,           fmt_rs1_rs2 },
	{ riscv_inst_type_cr_jalr,      fmt_rs1_rs2 },
	{ riscv_inst_type_cr_jr,        fmt_rs1_rs2 },
	{ riscv_inst_type_cs,           fmt_rs1_rs2 },
	{ riscv_inst_type_cs_fsd,       fmt_frs2_bimm_rs1 },
	{ riscv_inst_type_cs_fsw,       fmt_frs2_bimm_rs1 },
	{ riscv_inst_type_cs_sd,        fmt_rs2_bimm_rs1 },
	{ riscv_inst_type_cs_sw,        fmt_rs2_bimm_rs1 },
	{ riscv_inst_type_css_fswsp,    fmt_frs2_bimm_rs1 },
	{ riscv_inst_type_css_fsdsp,    fmt_frs2_bimm_rs1 },
	{ riscv_inst_type_css_swsp,     fmt_rs2_bimm_rs1 },
	{ riscv_inst_type_css_sdsp,     fmt_rs2_bimm_rs1 },
	{ riscv_inst_type_i,            fmt_rd_rs1_imm },
	{ riscv_inst_type_i_csr,        fmt_rd_csr_rs1 },
	{ riscv_inst_type_i_csri,       fmt_rd_csr_irs1 },
	{ riscv_inst_type_i_l,          fmt_rd_bimm_rs1 },
	{ riscv_inst_type_i_lf,         fmt_frd_bimm_rs1 },
	{ riscv_inst_type_i_none,       fmt_none },
	{ riscv_inst_type_i_sh5,        fmt_rd_rs1_imm },
	{ riscv_inst_type_i_sh6,        fmt_rd_rs1_imm },
	{ riscv_inst_type_r,            fmt_rd_rs1_rs2 },
	{ riscv_inst_type_r_3f,         fmt_frd_frs1_frs2 },
	{ riscv_inst_type_r_4f,         fmt_frd_frs1_frs2_frs3 },
	{ riscv_inst_type_r_a,          fmt_rd_rs2_b_rs1 },
	{ riscv_inst_type_r_ff,         fmt_frd_frs1 },
	{ riscv_inst_type_r_fr,         fmt_frd_rs1 },
	{ riscv_inst_type_r_l,          fmt_rd_b_rs1 },
	{ riscv_inst_type_r_rf,         fmt_rd_frs1 },
	{ riscv_inst_type_r_rff,        fmt_rd_frs1_frs2 },
	{ riscv_inst_type_s,            fmt_rs2_bimm_rs1 },
	{ riscv_inst_type_s_f,          fmt_frs2_bimm_rs1 },
	{ riscv_inst_type_sb,           fmt_rs1_rs2_ipc },
	{ riscv_inst_type_u,            fmt_rd_imm },
	{ riscv_inst_type_uj,           fmt_rd_ipc },
	{ riscv_inst_type_unknown,      nullptr }
};

/* Metadata Tables */

struct riscv_inst_type_map : std::map<riscv_inst_type,const riscv_inst_type_metadata*>
{
	riscv_inst_type_map() {
		for (const auto *ent = riscv_inst_type_table; ent->fmt; ent++)
			(*this)[ent->type] = ent;
	}
};

struct riscv_inst_comp_map : std::map<riscv_op,const riscv_inst_comp_metadata*>
{
	riscv_inst_comp_map() {
		for (const auto *ent = riscv_comp_table; ent->cop; ent++)
			(*this)[ent->cop] = ent;
	}
};

struct riscv_csr_map : std::map<riscv_hu,const riscv_csr_metadata*>
{
	riscv_csr_map() {
		for (const auto *ent = riscv_csr_table; ent->csr_value; ent++)
			(*this)[ent->csr_value] = ent;
	}
};

const riscv_inst_type_metadata* riscv_lookup_inst_metadata(riscv_inst_type type)
{
	static riscv_inst_type_map type_map;
	return type_map[type];
}

const riscv_inst_comp_metadata* riscv_lookup_comp_metadata(riscv_op op)
{
	static riscv_inst_comp_map comp_map;
	return comp_map[op];
}

const riscv_csr_metadata* riscv_lookup_csr_metadata(riscv_hu csr_value)
{
	static riscv_csr_map csr_map;
	return csr_map[csr_value];
}

void riscv_print_instruction(riscv_decode &dec, riscv_proc_state *proc, riscv_ptr pc, riscv_ptr pc_offset)
{
	const riscv_inst_comp_metadata *comp = riscv_lookup_comp_metadata((riscv_op)dec.op);
	if (comp) {
		dec.op = comp->op;
		dec.type = comp->type;
	}
	const riscv_inst_type_metadata *inst_meta = riscv_lookup_inst_metadata((riscv_inst_type)dec.type);
	const rvf *fmt = inst_meta ? inst_meta->fmt : fmt_none;

	printf("%s", format_string("%016tx: \t", pc - pc_offset).c_str());
	switch (dec.sz) {
		case 2: printf("%s", format_string("%04x\t\t", *(riscv_hu*)pc).c_str()); break;
		case 4: printf("%s", format_string("%08x\t", *(riscv_wu*)pc).c_str()); break;
	}
	printf("%s\t", riscv_instructions[dec.op].opcode);

	while (*fmt != rvf_z) {
		switch (*fmt) {
			case rvf_b: printf("("); break;
			case rvf_c: printf(","); break;
			case rvf_d: printf(")"); break;
			case rvf_rd: printf("%s", riscv_i_registers[dec.rd]); break;
			case rvf_rs1: printf("%s", riscv_i_registers[dec.rs1]); break;
			case rvf_rs2: printf("%s", riscv_i_registers[dec.rs2]); break;
			case rvf_frd: printf("%s", riscv_f_registers[dec.rd]); break;
			case rvf_frs1: printf("%s", riscv_f_registers[dec.rs1]); break;
			case rvf_frs2: printf("%s", riscv_f_registers[dec.rs2]); break;
			case rvf_frs3: printf("%s", riscv_f_registers[dec.rs3]); break;
			case rvf_irs1: printf("%s", format_string("%d", dec.rs1).c_str()); break;
			case rvf_imm: printf("%s", format_string("%lld", dec.imm, dec.imm).c_str()); break;
			case rvf_ipc: printf("%s", format_string("%lld \t# 0x%016tx", dec.imm, pc - pc_offset + dec.imm).c_str()); break;
			case rvf_csr:
			{
				const riscv_csr_metadata *csr = riscv_lookup_csr_metadata(dec.imm);
				printf("%s", (csr ? csr->csr_name : format_string("%llu", dec.imm)).c_str());
				break;
			}
			case rvf_z: break;
		}
		fmt++;
	}
	printf("\n");
}
<|endoftext|>


<commit_before>//
//  riscv-format.cc
//

#include <map>
#include <vector>
#include <string>

#include "riscv-opcodes.h"
#include "riscv-types.h"
#include "riscv-imm.h"
#include "riscv-decode.h"
#include "riscv-regs.h"
#include "riscv-csr.h"
#include "riscv-processor.h"
#include "riscv-compression.h"
#include "riscv-util.h"
#include "riscv-format.h"

const rvf rvf_none[] =               { rvf_z };
const rvf rvf_imm_pc[] =             { rvf_ipc, rvf_z };
const rvf rvf_rs1_rs2[] =            { rvf_rs1, rvf_c, rvf_rs2, rvf_z };
const rvf rvf_rs2_imm[] =            { rvf_rs2, rvf_c, rvf_i, rvf_z };
const rvf rvf_rd_imm[] =             { rvf_rd, rvf_c, rvf_i, rvf_z };
const rvf rvf_rd_imm_pc[] =          { rvf_rd, rvf_c, rvf_ipc, rvf_z };
const rvf rvf_rd_rs1_rs2[] =         { rvf_rd, rvf_c, rvf_rs1, rvf_c, rvf_rs2, rvf_z };
const rvf rvf_frd_frs1_frs2[] =      { rvf_frd, rvf_c, rvf_frs1, rvf_c, rvf_frs2, rvf_z };
const rvf rvf_rd_frs1_frs2[] =       { rvf_frd, rvf_c, rvf_rs1, rvf_c, rvf_frs2, rvf_z };
const rvf rvf_frd_frs1_frs2_frs3[] = { rvf_frd, rvf_c, rvf_frs1, rvf_c, rvf_frs2, rvf_c, rvf_frs3, rvf_z };
const rvf rvf_frd_rs1[] =            { rvf_frd, rvf_c, rvf_rs1, rvf_z };
const rvf rvf_frd_frs1[] =           { rvf_frd, rvf_c, rvf_frs1, rvf_z };
const rvf rvf_rd_frs1[] =            { rvf_rd, rvf_c, rvf_frs1, rvf_z };
const rvf rvf_rd_rs1_imm[] =         { rvf_rd, rvf_c, rvf_rs1, rvf_c, rvf_i, rvf_z };
const rvf rvf_rd_bimm_rs1[] =        { rvf_rd, rvf_c, rvf_i, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf rvf_frd_bimm_rs1[] =       { rvf_frd, rvf_c, rvf_i, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf rvf_rd_csr_rs1[] =         { rvf_rd, rvf_c, rvf_icsr, rvf_c, rvf_rs1, rvf_z };
const rvf rvf_rd_csr_srs1[] =        { rvf_rd, rvf_c, rvf_icsr, rvf_c, rvf_srs1, rvf_z };
const rvf rvf_rs1_rs2_imm[] =        { rvf_rs1, rvf_c, rvf_rs2, rvf_c, rvf_i, rvf_z };
const rvf rvf_rs2_bimm_rs1[] =       { rvf_rs2, rvf_c, rvf_i, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf rvf_frs2_bimm_rs1[] =      { rvf_frs2, rvf_c, rvf_i, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf rvf_rs1_rs2_imm_pc[] =     { rvf_rs1, rvf_c, rvf_rs2, rvf_c, rvf_ipc, rvf_z };

const riscv_inst_type_metadata riscv_inst_type_table[] = {
	{ riscv_inst_type_unknown,      rvf_none },
	{ riscv_inst_type_cr,           rvf_rs1_rs2 },
	{ riscv_inst_type_ci,           rvf_rd_imm },
	{ riscv_inst_type_ci_lui,       rvf_rd_imm },
	{ riscv_inst_type_ci_lwsp,      rvf_rd_imm },
	{ riscv_inst_type_ci_ldsp,      rvf_rd_imm },
	{ riscv_inst_type_ci_addi16sp,  rvf_rd_imm },
	{ riscv_inst_type_css_swsp,     rvf_rs2_imm },
	{ riscv_inst_type_css_sdsp,     rvf_rs2_imm },
	{ riscv_inst_type_ciw_addi4spn, rvf_rd_imm },
	{ riscv_inst_type_cl_lw,        rvf_rd_imm },
	{ riscv_inst_type_cl_ld,        rvf_rd_imm },
	{ riscv_inst_type_cs_x,         rvf_rs1_rs2 },
	{ riscv_inst_type_cs_sw,        rvf_rs1_rs2_imm },
	{ riscv_inst_type_cs_sd,        rvf_rs1_rs2_imm },
	{ riscv_inst_type_cb,           rvf_imm_pc },
	{ riscv_inst_type_cj,           rvf_imm_pc },
	{ riscv_inst_type_r,            rvf_rd_rs1_rs2 },
	{ riscv_inst_type_r_ff,         rvf_frd_frs1},
	{ riscv_inst_type_r_rf,         rvf_rd_frs1},
	{ riscv_inst_type_r_fr,         rvf_frd_rs1 },
	{ riscv_inst_type_r_fff,        rvf_frd_frs1_frs2},
	{ riscv_inst_type_r_rff,        rvf_rd_frs1_frs2},
	{ riscv_inst_type_r_ffff,       rvf_frd_frs1_frs2_frs3},
	{ riscv_inst_type_i,            rvf_rd_rs1_imm },
	{ riscv_inst_type_i_s,          rvf_none },
	{ riscv_inst_type_i_l,          rvf_rd_bimm_rs1 },
	{ riscv_inst_type_i_lf,         rvf_frd_bimm_rs1 },
	{ riscv_inst_type_i_csr,        rvf_rd_csr_rs1 },
	{ riscv_inst_type_i_csri,       rvf_rd_csr_srs1 },
	{ riscv_inst_type_s,            rvf_rs2_bimm_rs1 },
	{ riscv_inst_type_sf,           rvf_frs2_bimm_rs1 },
	{ riscv_inst_type_sb,           rvf_rs1_rs2_imm_pc },
	{ riscv_inst_type_u,            rvf_rd_imm },
	{ riscv_inst_type_uj,           rvf_rd_imm_pc },
	{ riscv_inst_type_unknown,      nullptr }
};

/* Metadata Tables */

const riscv_inst_type_metadata* riscv_lookup_inst_metadata(riscv_inst_type type)
{
	static std::map<riscv_inst_type,const riscv_inst_type_metadata*> type_map;
	if (type_map.size() == 0) {
		const riscv_inst_type_metadata *ent = riscv_inst_type_table;
		while (ent->fmt) {
			type_map[ent->type] = ent;
			ent++;
		}
	}
	std::map<riscv_inst_type,const riscv_inst_type_metadata*>::iterator type_i = type_map.find(type);
	return (type_i != type_map.end()) ? type_i->second : nullptr;
}

const riscv_inst_comp_metadata* riscv_lookup_comp_metadata(riscv_op op)
{
	static std::map<riscv_op,const riscv_inst_comp_metadata*> comp_map;
	if (comp_map.size() == 0) {
		const riscv_inst_comp_metadata *ent = riscv_comp_table;
		while (ent->cop) {
			comp_map[ent->cop] = ent;
			ent++;
		}
	}
	std::map<riscv_op,const riscv_inst_comp_metadata*>::iterator type_i = comp_map.find(op);
	return (type_i != comp_map.end()) ? type_i->second : nullptr;
}

const riscv_csr_metadata* riscv_lookup_csr_metadata(riscv_hu csr_value)
{
	static std::map<riscv_hu,const riscv_csr_metadata*> csr_map;
	if (csr_map.size() == 0) {
		const riscv_csr_metadata *ent = riscv_csr_table;
		while (ent->csr_value) {
			csr_map[ent->csr_value] = ent;
			ent++;
		}
	}
	std::map<riscv_hu,const riscv_csr_metadata*>::iterator csr_i = csr_map.find(csr_value);
	return (csr_i != csr_map.end()) ? csr_i->second : nullptr;
}

void riscv_print_instruction(riscv_decode &dec, riscv_proc_state *proc, riscv_ptr pc, riscv_ptr pc_offset)
{
#if 1
	const riscv_inst_comp_metadata *comp = riscv_lookup_comp_metadata((riscv_op)dec.op);
	if (comp) {
		dec.op = comp->op;
		dec.type = comp->type;
	}
#endif
	const riscv_inst_type_metadata *inst_meta = riscv_lookup_inst_metadata((riscv_inst_type)dec.type);
	const rvf *fmt = inst_meta ? inst_meta->fmt : rvf_none;

	printf("%s", format_string("%016tx: \t", pc - pc_offset).c_str());
	switch (dec.sz) {
		case 2: printf("%s", format_string("%04x\t\t", *(riscv_hu*)pc).c_str()); break;
		case 4: printf("%s", format_string("%08x\t", *(riscv_wu*)pc).c_str()); break;
	}
	printf("%s\t", riscv_instructions[dec.op]);

	while (*fmt != rvf_z) {
		switch (*fmt) {
			case rvf_b: printf("("); break;
			case rvf_c: printf(","); break;
			case rvf_d: printf(")"); break;
			case rvf_rd: printf("%s", riscv_i_registers[dec.rd]); break;
			case rvf_rs1: printf("%s", riscv_i_registers[dec.rs1]); break;
			case rvf_rs2: printf("%s", riscv_i_registers[dec.rs2]); break;
			case rvf_frd: printf("%s", riscv_f_registers[dec.rd]); break;
			case rvf_frs1: printf("%s", riscv_f_registers[dec.rs1]); break;
			case rvf_frs2: printf("%s", riscv_f_registers[dec.rs2]); break;
			case rvf_frs3: printf("%s", riscv_f_registers[dec.rs3]); break;
			case rvf_srs1: printf("%s", format_string("%d", dec.rs1).c_str()); break;
			case rvf_i: printf("%s", format_string("%lld", dec.imm, dec.imm).c_str()); break;
			case rvf_ipc: printf("%s", format_string("%lld \t# 0x%016tx", dec.imm, pc - pc_offset + dec.imm).c_str()); break;
			case rvf_icsr:
			{
				const riscv_csr_metadata *csr = riscv_lookup_csr_metadata(dec.imm);
				printf("%s", (csr ? csr->csr_name : format_string("%llu", dec.imm)).c_str());
				break;
			}
			case rvf_z: break;
		}
		fmt++;
	}
	printf("\n");
}
<commit_msg>Use thread safe static initializers for metadata tables<commit_after>//
//  riscv-format.cc
//

#include <map>
#include <vector>
#include <string>

#include "riscv-opcodes.h"
#include "riscv-types.h"
#include "riscv-imm.h"
#include "riscv-decode.h"
#include "riscv-regs.h"
#include "riscv-csr.h"
#include "riscv-processor.h"
#include "riscv-compression.h"
#include "riscv-util.h"
#include "riscv-format.h"

const rvf rvf_none[] =               { rvf_z };
const rvf rvf_imm_pc[] =             { rvf_ipc, rvf_z };
const rvf rvf_rs1_rs2[] =            { rvf_rs1, rvf_c, rvf_rs2, rvf_z };
const rvf rvf_rs2_imm[] =            { rvf_rs2, rvf_c, rvf_i, rvf_z };
const rvf rvf_rd_imm[] =             { rvf_rd, rvf_c, rvf_i, rvf_z };
const rvf rvf_rd_imm_pc[] =          { rvf_rd, rvf_c, rvf_ipc, rvf_z };
const rvf rvf_rd_rs1_rs2[] =         { rvf_rd, rvf_c, rvf_rs1, rvf_c, rvf_rs2, rvf_z };
const rvf rvf_frd_frs1_frs2[] =      { rvf_frd, rvf_c, rvf_frs1, rvf_c, rvf_frs2, rvf_z };
const rvf rvf_rd_frs1_frs2[] =       { rvf_frd, rvf_c, rvf_rs1, rvf_c, rvf_frs2, rvf_z };
const rvf rvf_frd_frs1_frs2_frs3[] = { rvf_frd, rvf_c, rvf_frs1, rvf_c, rvf_frs2, rvf_c, rvf_frs3, rvf_z };
const rvf rvf_frd_rs1[] =            { rvf_frd, rvf_c, rvf_rs1, rvf_z };
const rvf rvf_frd_frs1[] =           { rvf_frd, rvf_c, rvf_frs1, rvf_z };
const rvf rvf_rd_frs1[] =            { rvf_rd, rvf_c, rvf_frs1, rvf_z };
const rvf rvf_rd_rs1_imm[] =         { rvf_rd, rvf_c, rvf_rs1, rvf_c, rvf_i, rvf_z };
const rvf rvf_rd_bimm_rs1[] =        { rvf_rd, rvf_c, rvf_i, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf rvf_frd_bimm_rs1[] =       { rvf_frd, rvf_c, rvf_i, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf rvf_rd_csr_rs1[] =         { rvf_rd, rvf_c, rvf_icsr, rvf_c, rvf_rs1, rvf_z };
const rvf rvf_rd_csr_srs1[] =        { rvf_rd, rvf_c, rvf_icsr, rvf_c, rvf_srs1, rvf_z };
const rvf rvf_rs1_rs2_imm[] =        { rvf_rs1, rvf_c, rvf_rs2, rvf_c, rvf_i, rvf_z };
const rvf rvf_rs2_bimm_rs1[] =       { rvf_rs2, rvf_c, rvf_i, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf rvf_frs2_bimm_rs1[] =      { rvf_frs2, rvf_c, rvf_i, rvf_b, rvf_rs1, rvf_d, rvf_z };
const rvf rvf_rs1_rs2_imm_pc[] =     { rvf_rs1, rvf_c, rvf_rs2, rvf_c, rvf_ipc, rvf_z };

const riscv_inst_type_metadata riscv_inst_type_table[] = {
	{ riscv_inst_type_unknown,      rvf_none },
	{ riscv_inst_type_cr,           rvf_rs1_rs2 },
	{ riscv_inst_type_ci,           rvf_rd_imm },
	{ riscv_inst_type_ci_lui,       rvf_rd_imm },
	{ riscv_inst_type_ci_lwsp,      rvf_rd_imm },
	{ riscv_inst_type_ci_ldsp,      rvf_rd_imm },
	{ riscv_inst_type_ci_addi16sp,  rvf_rd_imm },
	{ riscv_inst_type_css_swsp,     rvf_rs2_imm },
	{ riscv_inst_type_css_sdsp,     rvf_rs2_imm },
	{ riscv_inst_type_ciw_addi4spn, rvf_rd_imm },
	{ riscv_inst_type_cl_lw,        rvf_rd_imm },
	{ riscv_inst_type_cl_ld,        rvf_rd_imm },
	{ riscv_inst_type_cs_x,         rvf_rs1_rs2 },
	{ riscv_inst_type_cs_sw,        rvf_rs1_rs2_imm },
	{ riscv_inst_type_cs_sd,        rvf_rs1_rs2_imm },
	{ riscv_inst_type_cb,           rvf_imm_pc },
	{ riscv_inst_type_cj,           rvf_imm_pc },
	{ riscv_inst_type_r,            rvf_rd_rs1_rs2 },
	{ riscv_inst_type_r_ff,         rvf_frd_frs1},
	{ riscv_inst_type_r_rf,         rvf_rd_frs1},
	{ riscv_inst_type_r_fr,         rvf_frd_rs1 },
	{ riscv_inst_type_r_fff,        rvf_frd_frs1_frs2},
	{ riscv_inst_type_r_rff,        rvf_rd_frs1_frs2},
	{ riscv_inst_type_r_ffff,       rvf_frd_frs1_frs2_frs3},
	{ riscv_inst_type_i,            rvf_rd_rs1_imm },
	{ riscv_inst_type_i_s,          rvf_none },
	{ riscv_inst_type_i_l,          rvf_rd_bimm_rs1 },
	{ riscv_inst_type_i_lf,         rvf_frd_bimm_rs1 },
	{ riscv_inst_type_i_csr,        rvf_rd_csr_rs1 },
	{ riscv_inst_type_i_csri,       rvf_rd_csr_srs1 },
	{ riscv_inst_type_s,            rvf_rs2_bimm_rs1 },
	{ riscv_inst_type_sf,           rvf_frs2_bimm_rs1 },
	{ riscv_inst_type_sb,           rvf_rs1_rs2_imm_pc },
	{ riscv_inst_type_u,            rvf_rd_imm },
	{ riscv_inst_type_uj,           rvf_rd_imm_pc },
	{ riscv_inst_type_unknown,      nullptr }
};

/* Metadata Tables */

struct riscv_inst_type_map : std::map<riscv_inst_type,const riscv_inst_type_metadata*>
{
	riscv_inst_type_map() {
		for (const auto *ent = riscv_inst_type_table; ent->fmt; ent++)
			(*this)[ent->type] = ent;
	}
};

struct riscv_inst_comp_map : std::map<riscv_op,const riscv_inst_comp_metadata*>
{
	riscv_inst_comp_map() {
		for (const auto *ent = riscv_comp_table; ent->cop; ent++)
			(*this)[ent->cop] = ent;
	}
};

struct riscv_csr_map : std::map<riscv_hu,const riscv_csr_metadata*>
{
	riscv_csr_map() {
		for (const auto *ent = riscv_csr_table; ent->csr_value; ent++)
			(*this)[ent->csr_value] = ent;
	}
};

const riscv_inst_type_metadata* riscv_lookup_inst_metadata(riscv_inst_type type)
{
	static riscv_inst_type_map type_map;
	return type_map[type];
}

const riscv_inst_comp_metadata* riscv_lookup_comp_metadata(riscv_op op)
{
	static riscv_inst_comp_map comp_map;
	return comp_map[op];
}

const riscv_csr_metadata* riscv_lookup_csr_metadata(riscv_hu csr_value)
{
	static riscv_csr_map csr_map;
	return csr_map[csr_value];
}

void riscv_print_instruction(riscv_decode &dec, riscv_proc_state *proc, riscv_ptr pc, riscv_ptr pc_offset)
{
#if 1
	const riscv_inst_comp_metadata *comp = riscv_lookup_comp_metadata((riscv_op)dec.op);
	if (comp) {
		dec.op = comp->op;
		dec.type = comp->type;
	}
#endif
	const riscv_inst_type_metadata *inst_meta = riscv_lookup_inst_metadata((riscv_inst_type)dec.type);
	const rvf *fmt = inst_meta ? inst_meta->fmt : rvf_none;

	printf("%s", format_string("%016tx: \t", pc - pc_offset).c_str());
	switch (dec.sz) {
		case 2: printf("%s", format_string("%04x\t\t", *(riscv_hu*)pc).c_str()); break;
		case 4: printf("%s", format_string("%08x\t", *(riscv_wu*)pc).c_str()); break;
	}
	printf("%s\t", riscv_instructions[dec.op]);

	while (*fmt != rvf_z) {
		switch (*fmt) {
			case rvf_b: printf("("); break;
			case rvf_c: printf(","); break;
			case rvf_d: printf(")"); break;
			case rvf_rd: printf("%s", riscv_i_registers[dec.rd]); break;
			case rvf_rs1: printf("%s", riscv_i_registers[dec.rs1]); break;
			case rvf_rs2: printf("%s", riscv_i_registers[dec.rs2]); break;
			case rvf_frd: printf("%s", riscv_f_registers[dec.rd]); break;
			case rvf_frs1: printf("%s", riscv_f_registers[dec.rs1]); break;
			case rvf_frs2: printf("%s", riscv_f_registers[dec.rs2]); break;
			case rvf_frs3: printf("%s", riscv_f_registers[dec.rs3]); break;
			case rvf_srs1: printf("%s", format_string("%d", dec.rs1).c_str()); break;
			case rvf_i: printf("%s", format_string("%lld", dec.imm, dec.imm).c_str()); break;
			case rvf_ipc: printf("%s", format_string("%lld \t# 0x%016tx", dec.imm, pc - pc_offset + dec.imm).c_str()); break;
			case rvf_icsr:
			{
				const riscv_csr_metadata *csr = riscv_lookup_csr_metadata(dec.imm);
				printf("%s", (csr ? csr->csr_name : format_string("%llu", dec.imm)).c_str());
				break;
			}
			case rvf_z: break;
		}
		fmt++;
	}
	printf("\n");
}
<|endoftext|>


<commit_before>/*
 * ModSecurity, http://www.modsecurity.org/
 * Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
 *
 * 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
 *
 * If any of the files related to licensing are missing or if you have any
 * other questions related to licensing please contact Trustwave Holdings, Inc.
 * directly using the email address security@modsecurity.org.
 *
 */

#include "modsecurity/rules.h"

#include "modsecurity/rule_message.h"

#include "modsecurity/modsecurity.h"
#include "modsecurity/transaction.h"
#include "src/utils/string.h"

namespace modsecurity {

std::string RuleMessage::_details(const RuleMessage *rm) {
    std::string msg;

    msg.append(" [file \"" + std::string(rm->m_ruleFile) + "\"]");
    msg.append(" [line \"" + std::to_string(rm->m_ruleLine) + "\"]");
    msg.append(" [id \"" + std::to_string(rm->m_ruleId) + "\"]");
    msg.append(" [rev \"" + rm->m_rev + "\"]");
    msg.append(" [msg \"" + rm->m_message + "\"]");
    msg.append(" [data \"" + rm->m_data + "\"]");
    msg.append(" [severity \"" +
        std::to_string(rm->m_severity) + "\"]");
    msg.append(" [ver \"" + rm->m_ver + "\"]");
    msg.append(" [maturity \"" + std::to_string(rm->m_maturity) + "\"]");
    msg.append(" [accuracy \"" + std::to_string(rm->m_accuracy) + "\"]");
    for (auto &a : rm->m_tags) {
        msg.append(" [tag \"" + a + "\"]");
    }
    msg.append(" [hostname \"" + std::string(rm->m_serverIpAddress) \
        + "\"]");
    msg.append(" [uri \"" + rm->m_uriNoQueryStringDecoded + "\"]");
    msg.append(" [unique_id \"" + rm->m_id + "\"]");
    msg.append(" [ref \"" + rm->m_reference + "\"]");

    return msg;
}

std::string RuleMessage::_errorLogTail(const RuleMessage *rm) {
    std::string msg;

    msg.append("[hostname \"" + std::string(rm->m_serverIpAddress) + "\"]");
    msg.append(" [uri \"" + rm->m_uriNoQueryStringDecoded + "\"]");
    msg.append(" [unique_id \"" + rm->m_id + "\"]");

    return msg;
}

std::string RuleMessage::log(const RuleMessage *rm, int props, int code) {
    std::string msg("");

    if (props & ClientLogMessageInfo) {
        msg.append("[client " + std::string(rm->m_clientIpAddress) + "] ");
    }

    if (rm->m_isDisruptive) {
        msg.append("ModSecurity: Access denied with code ");
        if (code == -1) {
            msg.append("%d");
        } else {
            msg.append(std::to_string(code));
        }
        msg.append(" (phase ");
        msg.append(std::to_string(rm->m_rule->m_phase - 1) + "). ");
    } else {
        msg.append("ModSecurity: Warning. ");
    }

    msg.append(rm->m_match);
    msg.append(_details(rm));

    if (props & ErrorLogTailLogMessageInfo) {
        msg.append(" " + _errorLogTail(rm));
    }

    return modsecurity::utils::string::toHexIfNeeded(msg);
}

}  // namespace modsecurity
<commit_msg>Limit log variables to 200 characters<commit_after>/*
 * ModSecurity, http://www.modsecurity.org/
 * Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
 *
 * 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
 *
 * If any of the files related to licensing are missing or if you have any
 * other questions related to licensing please contact Trustwave Holdings, Inc.
 * directly using the email address security@modsecurity.org.
 *
 */

#include "modsecurity/rules.h"

#include "modsecurity/rule_message.h"

#include "modsecurity/modsecurity.h"
#include "modsecurity/transaction.h"
#include "src/utils/string.h"

namespace modsecurity {

std::string RuleMessage::_details(const RuleMessage *rm) {
    std::string msg;

    msg.append(" [file \"" + std::string(rm->m_ruleFile) + "\"]");
    msg.append(" [line \"" + std::to_string(rm->m_ruleLine) + "\"]");
    msg.append(" [id \"" + std::to_string(rm->m_ruleId) + "\"]");
    msg.append(" [rev \"" + rm->m_rev + "\"]");
    msg.append(" [msg \"" + rm->m_message + "\"]");
    msg.append(" [data \"" + utils::string::limitTo(200, rm->m_data) + "\"]");
    msg.append(" [severity \"" +
        std::to_string(rm->m_severity) + "\"]");
    msg.append(" [ver \"" + rm->m_ver + "\"]");
    msg.append(" [maturity \"" + std::to_string(rm->m_maturity) + "\"]");
    msg.append(" [accuracy \"" + std::to_string(rm->m_accuracy) + "\"]");
    for (auto &a : rm->m_tags) {
        msg.append(" [tag \"" + a + "\"]");
    }
    msg.append(" [hostname \"" + std::string(rm->m_serverIpAddress) \
        + "\"]");
    msg.append(" [uri \"" + utils::string::limitTo(200, rm->m_uriNoQueryStringDecoded) + "\"]");
    msg.append(" [unique_id \"" + rm->m_id + "\"]");
    msg.append(" [ref \"" + utils::string::limitTo(200, rm->m_reference) + "\"]");

    return msg;
}

std::string RuleMessage::_errorLogTail(const RuleMessage *rm) {
    std::string msg;

    msg.append("[hostname \"" + std::string(rm->m_serverIpAddress) + "\"]");
    msg.append(" [uri \"" + utils::string::limitTo(200, rm->m_uriNoQueryStringDecoded) + "\"]");
    msg.append(" [unique_id \"" + rm->m_id + "\"]");

    return msg;
}

std::string RuleMessage::log(const RuleMessage *rm, int props, int code) {
    std::string msg("");

    if (props & ClientLogMessageInfo) {
        msg.append("[client " + std::string(rm->m_clientIpAddress) + "] ");
    }

    if (rm->m_isDisruptive) {
        msg.append("ModSecurity: Access denied with code ");
        if (code == -1) {
            msg.append("%d");
        } else {
            msg.append(std::to_string(code));
        }
        msg.append(" (phase ");
        msg.append(std::to_string(rm->m_rule->m_phase - 1) + "). ");
    } else {
        msg.append("ModSecurity: Warning. ");
    }

    msg.append(rm->m_match);
    msg.append(_details(rm));

    if (props & ErrorLogTailLogMessageInfo) {
        msg.append(" " + _errorLogTail(rm));
    }

    return modsecurity::utils::string::toHexIfNeeded(msg);
}

}  // namespace modsecurity
<|endoftext|>


<commit_before>#include "sift.hpp"
#include "internal.hpp"
#include <opencv2/imgproc/imgproc.hpp>
#include <vector>
#include <utility>
#include <iterator>
#include <algorithm>

namespace sift {

void buildGaussianPyramid(Mat& image, vector<vector<Mat>>& pyr, int nOctaves) {
    Mat image_ds = image.clone();
    pyr.resize(nOctaves);
    for (int o = 0; o < nOctaves; o++) {
        auto sigma = GAUSSIAN_PYR_SIGMA0;
        for (auto s = 0; s < GAUSSIAN_PYR_OCTAVE_SIZE; s++) {
            Mat image_ds_blur(image_ds.rows, image_ds.cols, image_ds.type());
            cv::GaussianBlur(
                    image_ds, image_ds_blur,
                    cv::Size(GAUSSIAN_PYR_KERNEL_SIZE, GAUSSIAN_PYR_KERNEL_SIZE),
                    sigma);
            pyr[o].push_back(image_ds_blur);

            sigma *= GAUSSIAN_PYR_K;
        }

        image_ds = downSample(pyr[o][GAUSSIAN_PYR_OCTAVE_SIZE-3]);
    }
}

/**
 * @brief Builds a difference of gaussian for each octave
 *
 * @param gauss_pyr 2D vector representing pyramids of all octaves.
 * @remark order of dogs is identical to gauss_pyr
 * @return 2D vector of DoGs
 */
vector<vector<Mat>> buildDogPyr(vector<vector<Mat>> gauss_pyr) {
    vector<vector<Mat>> dogs(gauss_pyr.size());
    auto dog_iterator  = std::begin(dogs);
    for (const auto &octave : gauss_pyr) {
        auto start = std::begin(octave);
        auto end = --std::end(octave);
        std::transform(start, end, start + 1,
            std::back_inserter(*dog_iterator),
            [](const Mat & lower, const Mat &upper) {
                return upper - lower;
            } );
        dog_iterator++;
    }
    return dogs;
}

/**
 * @brief Detects keypoints from DoG
 * @details Finds extremas in a 3x3x3 window
 *
 * @param dog_pyr DoGs for each octave
 * @param keypoints vector to be populated
 */
void getScaleSpaceExtrema(vector<vector<Mat>> &dog_pyr,
vector<KeyPoint> &keypoints) {
    for (std::size_t octave = 0; octave < dog_pyr.size(); octave++) {
        auto &octave_dog = dog_pyr[octave];
        auto octave_sigma = internal::compute_octave_sigma(octave);
        for (std::size_t image = 1; image < octave_dog.size() - 1; image++) {
            vector<internal::point> points = internal::find_local_extremas(
                octave_dog[image - 1], octave_dog[image], octave_dog[image + 1]);
            // Now we have x, y coordinates of extremas, we need to create keypoints
            /***********************************************************************************************
             *                            References                                                       *
             *- http://answers.opencv.org/question/7337/keypoint-size/                                     *
             *- http://www.aishack.in/tutorials/sift-scale-invariant-feature-transform-keypoints/          *
             *- http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_feature_detectors.html  *
             ***********************************************************************************************/
            for (const auto &p : points) {
                // FIXME: need to compute response value
                // found abs(interpolated_DoG_val   ue), what does that mean?
                // FIXME: Use subpixel values
                // Compute subpixel values
                // using taylor expansion
                keypoints.emplace_back(p.first, p.second, octave_sigma, -1,
                    octave_dog[image].at<image_t>(p.first, p.second), octave);
            }
        }
    }
}

}

<commit_msg>Document buildGaussianPyramid<commit_after>#include "sift.hpp"
#include "internal.hpp"
#include <opencv2/imgproc/imgproc.hpp>
#include <vector>
#include <utility>
#include <iterator>
#include <algorithm>

namespace sift {

/**
 * @brief Builds the gaussian pyramid
 *
 * @param image cv::Mat representing the input image
 * @param pyr reference to a 2D vector representing pyramids of all octaves.
 * @param nOctaves total number of octaves that should be built
 * @remark pyr[0] is octave 0, pyr[0][0] is the least blurred image of octave 0
 * @return void
 */
void buildGaussianPyramid(Mat& image, vector<vector<Mat>>& pyr, int nOctaves) {
    Mat image_ds = image.clone();
    pyr.resize(nOctaves);
    for (int o = 0; o < nOctaves; o++) {
        auto sigma = GAUSSIAN_PYR_SIGMA0;
        for (auto s = 0; s < GAUSSIAN_PYR_OCTAVE_SIZE; s++) {
            Mat image_ds_blur(image_ds.rows, image_ds.cols, image_ds.type());
            cv::GaussianBlur(
                    image_ds, image_ds_blur,
                    cv::Size(GAUSSIAN_PYR_KERNEL_SIZE, GAUSSIAN_PYR_KERNEL_SIZE),
                    sigma);
            pyr[o].push_back(image_ds_blur);

            sigma *= GAUSSIAN_PYR_K;
        }

        image_ds = downSample(pyr[o][GAUSSIAN_PYR_OCTAVE_SIZE-3]);
    }
}

/**
 * @brief Builds a difference of gaussian for each octave
 *
 * @param gauss_pyr 2D vector representing pyramids of all octaves.
 * @remark order of dogs is identical to gauss_pyr
 * @return 2D vector of DoGs
 */
vector<vector<Mat>> buildDogPyr(vector<vector<Mat>> gauss_pyr) {
    vector<vector<Mat>> dogs(gauss_pyr.size());
    auto dog_iterator  = std::begin(dogs);
    for (const auto &octave : gauss_pyr) {
        auto start = std::begin(octave);
        auto end = --std::end(octave);
        std::transform(start, end, start + 1,
            std::back_inserter(*dog_iterator),
            [](const Mat & lower, const Mat &upper) {
                return upper - lower;
            } );
        dog_iterator++;
    }
    return dogs;
}

/**
 * @brief Detects keypoints from DoG
 * @details Finds extremas in a 3x3x3 window
 *
 * @param dog_pyr DoGs for each octave
 * @param keypoints vector to be populated
 */
void getScaleSpaceExtrema(vector<vector<Mat>> &dog_pyr,
vector<KeyPoint> &keypoints) {
    for (std::size_t octave = 0; octave < dog_pyr.size(); octave++) {
        auto &octave_dog = dog_pyr[octave];
        auto octave_sigma = internal::compute_octave_sigma(octave);
        for (std::size_t image = 1; image < octave_dog.size() - 1; image++) {
            vector<internal::point> points = internal::find_local_extremas(
                octave_dog[image - 1], octave_dog[image], octave_dog[image + 1]);
            // Now we have x, y coordinates of extremas, we need to create keypoints
            /***********************************************************************************************
             *                            References                                                       *
             *- http://answers.opencv.org/question/7337/keypoint-size/                                     *
             *- http://www.aishack.in/tutorials/sift-scale-invariant-feature-transform-keypoints/          *
             *- http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_feature_detectors.html  *
             ***********************************************************************************************/
            for (const auto &p : points) {
                // FIXME: need to compute response value
                // found abs(interpolated_DoG_val   ue), what does that mean?
                // FIXME: Use subpixel values
                // Compute subpixel values
                // using taylor expansion
                keypoints.emplace_back(p.first, p.second, octave_sigma, -1,
                    octave_dog[image].at<image_t>(p.first, p.second), octave);
            }
        }
    }
}

}

<|endoftext|>


<commit_before>/*
 * Copyright (C) 2015 deipi.com LLC and contributors. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#include "http.h"

#include "manager.h"

#include <assert.h>

Http::Http(const std::shared_ptr<XapiandManager>& manager_, ev::loop_ref *loop_, int port_)
	: BaseTCP(manager_, loop_, port_, "Http", port_ == XAPIAND_HTTP_SERVERPORT ? 10 : 1, CONN_TCP_NODELAY | CONN_TCP_DEFER_ACCEPT)
{
	local_node.http_port = port;

	L_OBJ(this, "CREATED CONFIGURATION FOR HTTP");
}

Http::~Http()
{
	L_OBJ(this, "DELETED CONFIGURATION FOR HTTP");
}

std::string
Http::getDescription() const noexcept
{
	return "TCP:" + std::to_string(port) + " (" + description + ")";
}
<commit_msg>HTTP protocol and version in description<commit_after>/*
 * Copyright (C) 2015 deipi.com LLC and contributors. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#include "http.h"

#include "manager.h"

#include <assert.h>

Http::Http(const std::shared_ptr<XapiandManager>& manager_, ev::loop_ref *loop_, int port_)
	: BaseTCP(manager_, loop_, port_, "HTTP", port_ == XAPIAND_HTTP_SERVERPORT ? 10 : 1, CONN_TCP_NODELAY | CONN_TCP_DEFER_ACCEPT)
{
	local_node.http_port = port;

	L_OBJ(this, "CREATED CONFIGURATION FOR HTTP");
}

Http::~Http()
{
	L_OBJ(this, "DELETED CONFIGURATION FOR HTTP");
}

std::string
Http::getDescription() const noexcept
{
	return "TCP:" + std::to_string(port) + " (" + description + " v1.1)";
}
<|endoftext|>