@@ -725,58 +725,65 @@ int CISA_IR_Builder::WriteVISAHeader()
725725 return CM_FAILURE;
726726}
727727
728+ typedef struct yy_buffer_state * YY_BUFFER_STATE;
728729extern int CISAparse ();
730+ extern YY_BUFFER_STATE CISA_scan_string (const char * yy_str);
731+ extern void CISA_delete_buffer (YY_BUFFER_STATE buf);
732+
729733int CISA_IR_Builder::ParseVISAText (const std::string& visaHeader, const std::string& visaText, const std::string& visaTextFile)
730734{
731735#if defined(__linux__) || defined(_WIN64) || defined(_WIN32)
736+ // Direct output of parser to null
737+ #if defined(_WIN64) || defined(_WIN32)
738+ CISAout = fopen (" nul" , " w" );
739+ #else
740+ CISAout = fopen (" /dev/null" , " w" );
741+ #endif
742+
743+ // Dump the visa text
732744 if (m_options.getOption (vISA_GenerateISAASM) && !visaTextFile.empty ())
733745 {
734- CISAin = fopen (visaTextFile.c_str (), " wb+" );
735- }
736- else
737- {
738- // Create a temp file in memory for parsing
739- CISAin = std::tmpfile ();
746+ FILE* dumpFile = fopen (visaTextFile.c_str (), " wb+" );
747+ if (dumpFile)
748+ {
749+ // Write the header
750+ if (std::fputs (visaHeader.c_str (), dumpFile) == EOF)
751+ {
752+ assert (0 && " Failed to write visa text to file" );
753+ return CM_FAILURE;
754+ }
755+ // Write the declarations and instructions
756+ if (std::fputs (visaText.c_str (), dumpFile) == EOF)
757+ {
758+ assert (0 && " Failed to write visa text to file" );
759+ return CM_FAILURE;
760+ }
761+ fclose (dumpFile);
762+ }
740763 }
741764
742- if (CISAin == NULL )
743- {
744- assert (0 && " Cannot open file for visa parsing" );
745- return CM_FAILURE;
746- }
747- // Write the header
748- if (std::fputs (visaHeader.c_str (), CISAin) == EOF)
765+ // Parse the header string
766+ YY_BUFFER_STATE headerBuf = CISA_scan_string (visaHeader.c_str ());
767+ if (CISAparse () != 0 )
749768 {
750- assert (0 && " Failed to write visa text to file " );
769+ assert (0 && " Parsing header message failed " );
751770 return CM_FAILURE;
752771 }
753- // Write the declarations and instructions
754- if (std::fputs (visaText.c_str (), CISAin) == EOF)
772+ CISA_delete_buffer (headerBuf);
773+
774+ // Parse the visa body
775+ YY_BUFFER_STATE visaBuf = CISA_scan_string (visaText.c_str ());
776+ if (CISAparse () != 0 )
755777 {
756- assert (0 && " Failed to write visa text to file " );
778+ assert (0 && " Parsing visa text failed " );
757779 return CM_FAILURE;
758780 }
759- std::rewind (CISAin);
760-
761- // Direct output of parser to null
762- #if defined(_WIN64) || defined(_WIN32)
763- CISAout = fopen (" nul" , " w" );
764- #else
765- CISAout = fopen (" /dev/null" , " w" );
766- #endif
767-
768- int fail = CISAparse ();
781+ CISA_delete_buffer (visaBuf);
769782
770783 if (CISAout)
771784 {
772785 fclose (CISAout);
773786 }
774- fclose (CISAin);
775- if (fail)
776- {
777- assert (0 && " Parsing generated visa text failed" );
778- return CM_FAILURE;
779- }
780787
781788 return CM_SUCCESS;
782789#else
0 commit comments