#include "Compiler.h" #include #include using namespace std; Compiler::Compiler(const string & out_filename) { m_outfile = fopen(out_filename.c_str(), "w"); m_file_open = (m_outfile != NULL); /* standard header information */ writeHeader("#include \n"); } Compiler::~Compiler() { close(); } void Compiler::close() { if (m_file_open) { fputs(m_header.c_str(), m_outfile); fputs("\n", m_outfile); for (map::const_iterator it = m_functions.begin(); it != m_functions.end(); it++) { fputs(it->second.c_str(), m_outfile); fputs("\n", m_outfile); } fclose(m_outfile); m_file_open = false; } } void Compiler::writeHeader(const string & str) { m_header += str; } void Compiler::writeFunction(const string & str) { if (m_functions.find(m_current_function) == m_functions.end()) { m_functions[m_current_function] = ""; } m_functions[m_current_function] += str; } void Compiler::beginFunction(const string & name) { m_current_function = name; }