DSPAssembler: Migrate VerifyParams over to an OpcodeType param instead of bool

This commit is contained in:
Lioncash 2017-01-25 23:55:49 -05:00
parent 6cb6707a4e
commit 8f5ce50a25
2 changed files with 17 additions and 14 deletions

View File

@ -462,7 +462,7 @@ static u16 get_mask_shifted_down(u16 mask)
return mask; return mask;
} }
bool DSPAssembler::VerifyParams(const opc_t* opc, param_t* par, size_t count, bool ext) bool DSPAssembler::VerifyParams(const opc_t* opc, param_t* par, size_t count, OpcodeType type)
{ {
for (size_t i = 0; i < count; i++) for (size_t i = 0; i < count; i++)
{ {
@ -491,7 +491,7 @@ bool DSPAssembler::VerifyParams(const opc_t* opc, param_t* par, size_t count, bo
if ((int)par[i].val < value || if ((int)par[i].val < value ||
(int)par[i].val > value + get_mask_shifted_down(opc->params[i].mask)) (int)par[i].val > value + get_mask_shifted_down(opc->params[i].mask))
{ {
if (ext) if (type == OpcodeType::Extension)
fprintf(stderr, "(ext) "); fprintf(stderr, "(ext) ");
fprintf(stderr, "%s (param %zu)", cur_line.c_str(), current_param); fprintf(stderr, "%s (param %zu)", cur_line.c_str(), current_param);
@ -501,7 +501,7 @@ bool DSPAssembler::VerifyParams(const opc_t* opc, param_t* par, size_t count, bo
case P_PRG: case P_PRG:
if ((int)par[i].val < 0 || (int)par[i].val > 0x3) if ((int)par[i].val < 0 || (int)par[i].val > 0x3)
{ {
if (ext) if (type == OpcodeType::Extension)
fprintf(stderr, "(ext) "); fprintf(stderr, "(ext) ");
fprintf(stderr, "%s (param %zu)", cur_line.c_str(), current_param); fprintf(stderr, "%s (param %zu)", cur_line.c_str(), current_param);
@ -511,7 +511,7 @@ bool DSPAssembler::VerifyParams(const opc_t* opc, param_t* par, size_t count, bo
case P_ACC: case P_ACC:
if ((int)par[i].val < 0x20 || (int)par[i].val > 0x21) if ((int)par[i].val < 0x20 || (int)par[i].val > 0x21)
{ {
if (ext) if (type == OpcodeType::Extension)
fprintf(stderr, "(ext) "); fprintf(stderr, "(ext) ");
if (par[i].val >= 0x1e && par[i].val <= 0x1f) if (par[i].val >= 0x1e && par[i].val <= 0x1f)
@ -519,7 +519,8 @@ bool DSPAssembler::VerifyParams(const opc_t* opc, param_t* par, size_t count, bo
fprintf(stderr, "%i : %s ", code_line, cur_line.c_str()); fprintf(stderr, "%i : %s ", code_line, cur_line.c_str());
fprintf(stderr, "WARNING: $ACM%d register used instead of $ACC%d register Line: %d " fprintf(stderr, "WARNING: $ACM%d register used instead of $ACC%d register Line: %d "
"Param: %zu Ext: %d\n", "Param: %zu Ext: %d\n",
(par[i].val & 1), (par[i].val & 1), code_line, current_param, ext); (par[i].val & 1), (par[i].val & 1), code_line, current_param,
static_cast<int>(type));
} }
else if (par[i].val >= 0x1c && par[i].val <= 0x1d) else if (par[i].val >= 0x1c && par[i].val <= 0x1d)
{ {
@ -537,7 +538,7 @@ bool DSPAssembler::VerifyParams(const opc_t* opc, param_t* par, size_t count, bo
case P_ACCM: case P_ACCM:
if ((int)par[i].val < 0x1e || (int)par[i].val > 0x1f) if ((int)par[i].val < 0x1e || (int)par[i].val > 0x1f)
{ {
if (ext) if (type == OpcodeType::Extension)
fprintf(stderr, "(ext) "); fprintf(stderr, "(ext) ");
if (par[i].val >= 0x1c && par[i].val <= 0x1d) if (par[i].val >= 0x1c && par[i].val <= 0x1d)
@ -564,7 +565,7 @@ bool DSPAssembler::VerifyParams(const opc_t* opc, param_t* par, size_t count, bo
case P_ACCL: case P_ACCL:
if ((int)par[i].val < 0x1c || (int)par[i].val > 0x1d) if ((int)par[i].val < 0x1c || (int)par[i].val > 0x1d)
{ {
if (ext) if (type == OpcodeType::Extension)
fprintf(stderr, "(ext) "); fprintf(stderr, "(ext) ");
if (par[i].val >= 0x1e && par[i].val <= 0x1f) if (par[i].val >= 0x1e && par[i].val <= 0x1f)
@ -602,22 +603,22 @@ bool DSPAssembler::VerifyParams(const opc_t* opc, param_t* par, size_t count, bo
switch (par[i].type & (P_REG | 7)) switch (par[i].type & (P_REG | 7))
{ {
case P_REG: case P_REG:
if (ext) if (type == OpcodeType::Extension)
fprintf(stderr, "(ext) "); fprintf(stderr, "(ext) ");
ShowError(ERR_EXPECTED_PARAM_REG); ShowError(ERR_EXPECTED_PARAM_REG);
break; break;
case P_MEM: case P_MEM:
if (ext) if (type == OpcodeType::Extension)
fprintf(stderr, "(ext) "); fprintf(stderr, "(ext) ");
ShowError(ERR_EXPECTED_PARAM_MEM); ShowError(ERR_EXPECTED_PARAM_MEM);
break; break;
case P_VAL: case P_VAL:
if (ext) if (type == OpcodeType::Extension)
fprintf(stderr, "(ext) "); fprintf(stderr, "(ext) ");
ShowError(ERR_EXPECTED_PARAM_VAL); ShowError(ERR_EXPECTED_PARAM_VAL);
break; break;
case P_IMM: case P_IMM:
if (ext) if (type == OpcodeType::Extension)
fprintf(stderr, "(ext) "); fprintf(stderr, "(ext) ");
ShowError(ERR_EXPECTED_PARAM_IMM); ShowError(ERR_EXPECTED_PARAM_IMM);
break; break;
@ -975,7 +976,7 @@ bool DSPAssembler::AssembleFile(const std::string& file_path, int pass)
opcode_size = opc->size; opcode_size = opc->size;
VerifyParams(opc, params, params_count); VerifyParams(opc, params, params_count, OpcodeType::Primary);
const opc_t* opc_ext = nullptr; const opc_t* opc_ext = nullptr;
// Check for opcode extensions. // Check for opcode extensions.
@ -984,10 +985,12 @@ bool DSPAssembler::AssembleFile(const std::string& file_path, int pass)
if (opcode_ext) if (opcode_ext)
{ {
opc_ext = FindOpcode(opcode_ext, params_count_ext, OpcodeType::Extension); opc_ext = FindOpcode(opcode_ext, params_count_ext, OpcodeType::Extension);
VerifyParams(opc_ext, params_ext, params_count_ext, true); VerifyParams(opc_ext, params_ext, params_count_ext, OpcodeType::Extension);
} }
else if (params_count_ext) else if (params_count_ext)
{
ShowError(ERR_EXT_PAR_NOT_EXT); ShowError(ERR_EXT_PAR_NOT_EXT);
}
} }
else else
{ {

View File

@ -98,7 +98,7 @@ private:
char* FindBrackets(char* src, char* dst); char* FindBrackets(char* src, char* dst);
const opc_t* FindOpcode(std::string name, size_t par_count, OpcodeType type); const opc_t* FindOpcode(std::string name, size_t par_count, OpcodeType type);
bool VerifyParams(const opc_t* opc, param_t* par, size_t count, bool ext = false); bool VerifyParams(const opc_t* opc, param_t* par, size_t count, OpcodeType type);
void BuildCode(const opc_t* opc, param_t* par, u32 par_count, u16* outbuf); void BuildCode(const opc_t* opc, param_t* par, u32 par_count, u16* outbuf);
std::vector<u16> m_output_buffer; std::vector<u16> m_output_buffer;