You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.8 KiB
100 lines
2.8 KiB
4 years ago
|
#pragma once
|
||
|
#include <cstdint>
|
||
|
#include <functional>
|
||
4 years ago
|
#include <iostream>
|
||
|
#include <vector>
|
||
4 years ago
|
|
||
3 years ago
|
/// <summary>
|
||
|
/// raw virtual instruction information extracted using lex and yacc...
|
||
|
/// </summary>
|
||
4 years ago
|
struct _vinstr_meta
|
||
|
{
|
||
3 years ago
|
/// <summary>
|
||
|
/// virtual instruction name...
|
||
|
/// </summary>
|
||
4 years ago
|
std::string name;
|
||
3 years ago
|
|
||
|
/// <summary>
|
||
|
/// if the virtual instruction has a second operand or not (imm)...
|
||
|
/// </summary>
|
||
4 years ago
|
bool has_imm;
|
||
3 years ago
|
|
||
|
/// <summary>
|
||
|
/// the imm if any...
|
||
|
/// </summary>
|
||
4 years ago
|
std::uintptr_t imm;
|
||
4 years ago
|
};
|
||
|
|
||
3 years ago
|
/// <summary>
|
||
|
/// raw label containing raw virtual instruction data extracted using lex and yacc...
|
||
|
/// </summary>
|
||
3 years ago
|
struct _vlabel_meta
|
||
|
{
|
||
3 years ago
|
/// <summary>
|
||
|
/// label name...
|
||
|
/// </summary>
|
||
3 years ago
|
std::string label_name;
|
||
3 years ago
|
|
||
|
/// <summary>
|
||
|
/// vector of raw virtual instruction data...
|
||
|
/// </summary>
|
||
3 years ago
|
std::vector< _vinstr_meta > vinstrs;
|
||
|
};
|
||
|
|
||
3 years ago
|
/// <summary>
|
||
|
/// used for parse_t::for_each...
|
||
|
/// </summary>
|
||
3 years ago
|
using callback_t = std::function< bool( _vlabel_meta * ) >;
|
||
4 years ago
|
|
||
3 years ago
|
/// <summary>
|
||
|
/// this singleton class contains all the information for parsed virtual instructions...
|
||
|
/// </summary>
|
||
4 years ago
|
class parse_t
|
||
|
{
|
||
4 years ago
|
public:
|
||
3 years ago
|
/// <summary>
|
||
|
/// gets the one and only instance of this class...
|
||
|
/// </summary>
|
||
|
/// <returns>returns a pointer to the one and only instance of this class...</returns>
|
||
4 years ago
|
static auto get_instance() -> parse_t *;
|
||
3 years ago
|
|
||
|
/// <summary>
|
||
|
/// used by yacc file to add new labels...
|
||
|
/// </summary>
|
||
|
/// <param name="label_name">label name, no pass by reference since a new std::string object must be
|
||
|
/// created...</param>
|
||
3 years ago
|
void add_label( std::string label_name );
|
||
3 years ago
|
|
||
|
/// <summary>
|
||
|
/// used by yacc file to add new virtual instruction with no imm...
|
||
|
/// </summary>
|
||
|
/// <param name="vinstr_name">virtual instruction name, no pass by reference since a new std::string object must be
|
||
|
/// created...</param>
|
||
4 years ago
|
void add_vinstr( std::string vinstr_name );
|
||
3 years ago
|
|
||
|
/// <summary>
|
||
|
/// used by yacc file to add new virtual instruction with an imm...
|
||
|
/// </summary>
|
||
|
/// <param name="vinstr_name">virtual instruction name, no pass by reference since a new std::string object must
|
||
|
/// be created...</param>
|
||
|
/// <param name="imm_val">imm value...</param>
|
||
4 years ago
|
void add_vinstr( std::string vinstr_name, std::uintptr_t imm_val );
|
||
3 years ago
|
|
||
|
/// <summary>
|
||
|
/// used to loop over every single label...
|
||
|
/// </summary>
|
||
|
/// <param name="callback">lambda to call back given the label structure...</param>
|
||
|
/// <returns>returns true if all labels were looped through...</returns>
|
||
4 years ago
|
bool for_each( callback_t callback );
|
||
3 years ago
|
|
||
4 years ago
|
private:
|
||
3 years ago
|
/// <summary>
|
||
|
/// vector of raw virtual labels...
|
||
|
/// </summary>
|
||
|
std::vector< _vlabel_meta > virt_labels;
|
||
|
|
||
|
/// <summary>
|
||
|
/// default constructor... private...
|
||
|
/// </summary>
|
||
4 years ago
|
parse_t();
|
||
4 years ago
|
};
|