94 lines
2.4 KiB
C++
94 lines
2.4 KiB
C++
|
#include "externals.hh"
|
||
|
#include "control.hh"
|
||
|
#include "globals.hh"
|
||
|
#include "sync.hh"
|
||
|
|
||
|
using namespace ops;
|
||
|
using namespace ebcl;
|
||
|
|
||
|
|
||
|
/*= OPCODE INFORMATIONS ========================================================*/
|
||
|
|
||
|
namespace {
|
||
|
|
||
|
struct T_OpInfo
|
||
|
{
|
||
|
char const* name;
|
||
|
int nArgs;
|
||
|
|
||
|
T_OpInfo( char const* name ,
|
||
|
int nArgs = 0 )
|
||
|
: name( name ) , nArgs( nArgs )
|
||
|
{ }
|
||
|
};
|
||
|
|
||
|
static T_KeyValueTable< E_OpType , T_OpInfo > OpInfoTable_{ ([]() {
|
||
|
T_KeyValueTable< E_OpType , T_OpInfo > infos;
|
||
|
|
||
|
infos.add( E_OpType::OP_END , T_OpInfo{ "end" } );
|
||
|
//
|
||
|
infos.add( E_OpType::OP_CALL , T_OpInfo{ "call" , 1 } );
|
||
|
infos.add( E_OpType::OP_RET , T_OpInfo{ "ret" , 1 } );
|
||
|
infos.add( E_OpType::OP_COND_JUMP , T_OpInfo{ "cond-jump" , 2 } );
|
||
|
//
|
||
|
infos.add( E_OpType::OP_RES_STACK , T_OpInfo{ "res-stack" , 1 } );
|
||
|
infos.add( E_OpType::OP_PUSH , T_OpInfo{ "push" } );
|
||
|
infos.add( E_OpType::OP_POP , T_OpInfo{ "pop" , 1 } );
|
||
|
//
|
||
|
infos.add( E_OpType::OP_LOAD , T_OpInfo{ "load" , 1 } );
|
||
|
infos.add( E_OpType::OP_SLOAD , T_OpInfo{ "load-stack" , 1 } );
|
||
|
//
|
||
|
infos.add( E_OpType::OP_FP_LOAD , T_OpInfo{ "fp-load" , 1 } );
|
||
|
infos.add( E_OpType::OP_FP_SLOAD , T_OpInfo{ "fp-load-stack" , 1 } );
|
||
|
infos.add( E_OpType::OP_FP_STORE , T_OpInfo{ "fp-store" , 1 } );
|
||
|
infos.add( E_OpType::OP_FP_SSTORE , T_OpInfo{ "fp-store-stack" , 1 } );
|
||
|
infos.add( E_OpType::OP_FP_SSTORE_INT , T_OpInfo{ "fp-store-stack-int" , 1 } );
|
||
|
//
|
||
|
infos.add( E_OpType::OP_FP_CMP , T_OpInfo{ "fp-cmp" , 1 } );
|
||
|
infos.add( E_OpType::OP_FP_ADD , T_OpInfo{ "fp-add" } );
|
||
|
infos.add( E_OpType::OP_FP_SUB , T_OpInfo{ "fp-sub" } );
|
||
|
infos.add( E_OpType::OP_FP_MUL , T_OpInfo{ "fp-mul" } );
|
||
|
infos.add( E_OpType::OP_FP_DIV , T_OpInfo{ "fp-div" } );
|
||
|
infos.add( E_OpType::OP_FP_MUL , T_OpInfo{ "fp-neg" } );
|
||
|
infos.add( E_OpType::OP_FP_DIV , T_OpInfo{ "fp-inv" } );
|
||
|
|
||
|
return infos;
|
||
|
})( ) };
|
||
|
|
||
|
} // namespace
|
||
|
|
||
|
uint32_t ops::ArgumentsFor(
|
||
|
const E_OpType op ) noexcept
|
||
|
{
|
||
|
assert( OpInfoTable_.contains( op ) );
|
||
|
return OpInfoTable_.get( op )->nArgs;
|
||
|
}
|
||
|
|
||
|
|
||
|
/*= STRING FORMATTING ==========================================================*/
|
||
|
|
||
|
T_StringBuilder& ops::operator<<(
|
||
|
T_StringBuilder& sb ,
|
||
|
const E_OpType et )
|
||
|
{
|
||
|
assert( OpInfoTable_.contains( et ) );
|
||
|
sb << OpInfoTable_.get( et )->name;
|
||
|
return sb;
|
||
|
}
|
||
|
|
||
|
T_StringBuilder& ops::operator<<(
|
||
|
T_StringBuilder& sb ,
|
||
|
T_Op const& op )
|
||
|
{
|
||
|
sb << op.op;
|
||
|
|
||
|
const auto args{ OpInfoTable_.get( op.op )->nArgs };
|
||
|
if ( args ) {
|
||
|
sb << ' ' << op.arg0;
|
||
|
if ( args == 2 ) {
|
||
|
sb << ' ' << op.arg1;
|
||
|
}
|
||
|
}
|
||
|
return sb;
|
||
|
}
|