DSPAssembler: remove temporary file

This commit is contained in:
Michael Maltese 2017-05-19 16:45:52 -07:00
parent b47d44ab15
commit f3c8291c26
2 changed files with 8 additions and 19 deletions

View File

@ -61,11 +61,8 @@ bool DSPAssembler::Assemble(const std::string& text, std::vector<u16>& code,
{ {
if (line_numbers) if (line_numbers)
line_numbers->clear(); line_numbers->clear();
const std::string file_name = "tmp.asm";
if (!File::WriteStringToFile(text, file_name))
return false;
InitPass(1); InitPass(1);
if (!AssembleFile(file_name, 1)) if (!AssemblePass(text, 1))
return false; return false;
// We now have the size of the output buffer // We now have the size of the output buffer
@ -75,7 +72,7 @@ bool DSPAssembler::Assemble(const std::string& text, std::vector<u16>& code,
m_output_buffer.resize(m_totalSize); m_output_buffer.resize(m_totalSize);
InitPass(2); InitPass(2);
if (!AssembleFile(file_name, 2)) if (!AssemblePass(text, 2))
return false; return false;
code = std::move(m_output_buffer); code = std::move(m_output_buffer);
@ -752,18 +749,11 @@ void DSPAssembler::InitPass(int pass)
segment_addr[SEGMENT_OVERLAY] = 0; segment_addr[SEGMENT_OVERLAY] = 0;
} }
bool DSPAssembler::AssembleFile(const std::string& file_path, int pass) bool DSPAssembler::AssemblePass(const std::string& text, int pass)
{ {
int disable_text = 0; // modified by Hermes int disable_text = 0; // modified by Hermes
std::ifstream fsrc; std::istringstream fsrc(text);
OpenFStream(fsrc, file_path, std::ios_base::in);
if (fsrc.fail())
{
std::cerr << "Cannot open file " << file_path << std::endl;
return false;
}
// printf("%s: Pass %d\n", fname, pass); // printf("%s: Pass %d\n", fname, pass);
code_line = 0; code_line = 0;
@ -929,7 +919,9 @@ bool DSPAssembler::AssembleFile(const std::string& file_path, int pass)
include_file_path = include_dir + '/' + params[0].str; include_file_path = include_dir + '/' + params[0].str;
} }
AssembleFile(include_file_path, pass); std::string included_text;
File::ReadFileToString(include_file_path, included_text);
AssemblePass(included_text, pass);
code_line = this_code_line; code_line = this_code_line;
} }
@ -1017,9 +1009,6 @@ bool DSPAssembler::AssembleFile(const std::string& file_path, int pass)
m_totalSize += opcode_size; m_totalSize += opcode_size;
}; };
if (!failed)
fsrc.close();
return !failed; return !failed;
} }
} // namespace DSP } // namespace DSP

View File

@ -91,7 +91,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 std::string& file_path, int pass); bool AssemblePass(const std::string& text, 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);