Merge pull request #4706 from lioncash/dspasm

DSPAssembler: Minor cleanup
This commit is contained in:
Markus Wick 2017-01-23 12:12:01 +01:00 committed by GitHub
commit c0e8280240
2 changed files with 17 additions and 19 deletions

View File

@ -63,11 +63,11 @@ bool DSPAssembler::Assemble(const std::string& text, std::vector<u16>& code,
{ {
if (line_numbers) if (line_numbers)
line_numbers->clear(); line_numbers->clear();
const char* fname = "tmp.asm"; const std::string file_name = "tmp.asm";
if (!File::WriteStringToFile(text, fname)) if (!File::WriteStringToFile(text, file_name))
return false; return false;
InitPass(1); InitPass(1);
if (!AssembleFile(fname, 1)) if (!AssembleFile(file_name, 1))
return false; return false;
// We now have the size of the output buffer // We now have the size of the output buffer
@ -83,7 +83,7 @@ bool DSPAssembler::Assemble(const std::string& text, std::vector<u16>& code,
return false; return false;
InitPass(2); InitPass(2);
if (!AssembleFile(fname, 2)) if (!AssembleFile(file_name, 2))
return false; return false;
code.resize(m_totalSize); code.resize(m_totalSize);
@ -764,16 +764,16 @@ void DSPAssembler::InitPass(int pass)
segment_addr[SEGMENT_OVERLAY] = 0; segment_addr[SEGMENT_OVERLAY] = 0;
} }
bool DSPAssembler::AssembleFile(const char* fname, int pass) bool DSPAssembler::AssembleFile(const std::string& file_path, int pass)
{ {
int disable_text = 0; // modified by Hermes int disable_text = 0; // modified by Hermes
std::ifstream fsrc; std::ifstream fsrc;
OpenFStream(fsrc, fname, std::ios_base::in); OpenFStream(fsrc, file_path, std::ios_base::in);
if (fsrc.fail()) if (fsrc.fail())
{ {
std::cerr << "Cannot open file " << fname << std::endl; std::cerr << "Cannot open file " << file_path << std::endl;
return false; return false;
} }
@ -929,28 +929,26 @@ bool DSPAssembler::AssembleFile(const char* fname, int pass)
{ {
if (params[0].type == P_STR) if (params[0].type == P_STR)
{ {
char* tmpstr; std::string include_file_path;
u32 thisCodeline = code_line; const u32 this_code_line = code_line;
if (include_dir.size()) if (include_dir.empty())
{ {
tmpstr = (char*)malloc(include_dir.size() + strlen(params[0].str) + 2); include_file_path = params[0].str;
sprintf(tmpstr, "%s/%s", include_dir.c_str(), params[0].str);
} }
else else
{ {
tmpstr = (char*)malloc(strlen(params[0].str) + 1); include_file_path = include_dir + '/' + params[0].str;
strcpy(tmpstr, params[0].str);
} }
AssembleFile(tmpstr, pass); AssembleFile(include_file_path, pass);
code_line = thisCodeline; code_line = this_code_line;
free(tmpstr);
} }
else else
{
ShowError(ERR_EXPECTED_PARAM_STR); ShowError(ERR_EXPECTED_PARAM_STR);
}
continue; continue;
} }

View File

@ -84,7 +84,7 @@ private:
u32 GetParams(char* parstr, param_t* par); u32 GetParams(char* parstr, param_t* par);
void InitPass(int pass); void InitPass(int pass);
bool AssembleFile(const char* fname, int pass); bool AssembleFile(const std::string& file_path, int pass);
void ShowError(err_t err_code, const char* extra_info = nullptr); void ShowError(err_t err_code, const char* extra_info = nullptr);
// void ShowWarning(err_t err_code, const char *extra_info = nullptr); // void ShowWarning(err_t err_code, const char *extra_info = nullptr);