beebasm

changeset 38:c2cd2f187a7f

Added default SAVE filename facility (takes filename from the command line instead of the SAVE command) Removed some debugging aids from the code completely.
author RichTW <richtw1@gmail.com>
date Mon Apr 25 04:33:59 2011 +0200
parents bc0355ba8a53
children 0e5eb702df24
files beebasm.exe src/Makefile src/asmexception.h src/commands.cpp src/globaldata.cpp src/globaldata.h src/lineparser.cpp src/sourcecode.cpp
diffstat 8 files changed, 70 insertions(+), 56 deletions(-) [+]
line diff
     1.1 Binary file beebasm.exe has changed
     2.1 --- a/src/Makefile	Mon Apr 25 03:53:44 2011 +0200
     2.2 +++ b/src/Makefile	Mon Apr 25 04:33:59 2011 +0200
     2.3 @@ -52,7 +52,7 @@
     2.4  # Parameters to the executable
     2.5  
     2.6  PARAMS			:=		-i ../demo.6502 -do ../demo.ssd -boot Code -v
     2.7 -#PARAMS			:=		-i ../test.6502 -v
     2.8 +#PARAMS			:=		-i ../test.6502 -v -do ../test.ssd
     2.9  
    2.10  
    2.11  
     3.1 --- a/src/asmexception.h	Mon Apr 25 03:53:44 2011 +0200
     3.2 +++ b/src/asmexception.h	Mon Apr 25 04:33:59 2011 +0200
     3.3 @@ -222,6 +222,8 @@
     3.4  DEFINE_SYNTAX_EXCEPTION( BadAlignment, "Bad alignment." );
     3.5  DEFINE_SYNTAX_EXCEPTION( OutOfRange, "Out of range." );
     3.6  DEFINE_SYNTAX_EXCEPTION( BackwardsSkip, "Attempted to skip backwards to an address." );
     3.7 +DEFINE_SYNTAX_EXCEPTION( NoAnonSave, "Cannot specify SAVE without a filename if no default output filename has been specified." );
     3.8 +DEFINE_SYNTAX_EXCEPTION( OnlyOneAnonSave, "Can only use SAVE without a filename once per project." );
     3.9  
    3.10  
    3.11  
     4.1 --- a/src/commands.cpp	Mon Apr 25 03:53:44 2011 +0200
     4.2 +++ b/src/commands.cpp	Mon Apr 25 04:33:59 2011 +0200
     4.3 @@ -935,6 +935,8 @@
     4.4  	int exec = 0;
     4.5  	int reload = 0;
     4.6  
     4.7 +	int oldColumn = m_column;
     4.8 +
     4.9  	// syntax is SAVE "filename", start, end [, exec [, reload] ]
    4.10  
    4.11  	if ( !AdvanceAndCheckEndOfStatement() )
    4.12 @@ -943,47 +945,41 @@
    4.13  		throw AsmException_SyntaxError_EmptyExpression( m_line, m_column );
    4.14  	}
    4.15  
    4.16 -	if ( m_line[ m_column ] != '\"' )
    4.17 +	string saveFile;
    4.18 +
    4.19 +	if ( m_line[ m_column ] == '\"' )
    4.20  	{
    4.21 -		// did not find a string
    4.22 -		throw AsmException_SyntaxError_InvalidCharacter( m_line, m_column );
    4.23 +		// get filename
    4.24 +
    4.25 +		size_t endQuotePos = m_line.find_first_of( '\"', m_column + 1 );
    4.26 +
    4.27 +		if ( endQuotePos == string::npos )
    4.28 +		{
    4.29 +			// did not find the end of the string
    4.30 +			throw AsmException_SyntaxError_MissingQuote( m_line, m_line.length() );
    4.31 +		}
    4.32 +
    4.33 +		saveFile = m_line.substr( m_column + 1, endQuotePos - m_column - 1 );
    4.34 +
    4.35 +		m_column = endQuotePos + 1;
    4.36 +
    4.37 +		if ( !AdvanceAndCheckEndOfStatement() )
    4.38 +		{
    4.39 +			// found nothing
    4.40 +			throw AsmException_SyntaxError_EmptyExpression( m_line, m_column );
    4.41 +		}
    4.42 +
    4.43 +		if ( m_line[ m_column ] != ',' )
    4.44 +		{
    4.45 +			// did not find a comma
    4.46 +			throw AsmException_SyntaxError_InvalidCharacter( m_line, m_column );
    4.47 +		}
    4.48 +
    4.49 +		m_column++;
    4.50  	}
    4.51  
    4.52 -	// get filename
    4.53 -
    4.54 -	size_t endQuotePos = m_line.find_first_of( '\"', m_column + 1 );
    4.55 -
    4.56 -	if ( endQuotePos == string::npos )
    4.57 -	{
    4.58 -		// did not find the end of the string
    4.59 -		throw AsmException_SyntaxError_MissingQuote( m_line, m_line.length() );
    4.60 -	}
    4.61 -
    4.62 -	string saveFile( m_line.substr( m_column + 1, endQuotePos - m_column - 1 ) );
    4.63 -
    4.64 -	if ( GlobalData::Instance().ShouldOutputAsm() )
    4.65 -	{
    4.66 -		cout << "Saving file '" << saveFile << "'" << endl;
    4.67 -	}
    4.68 -
    4.69 -	m_column = endQuotePos + 1;
    4.70 -
    4.71  	// get start address
    4.72  
    4.73 -	if ( !AdvanceAndCheckEndOfStatement() )
    4.74 -	{
    4.75 -		// found nothing
    4.76 -		throw AsmException_SyntaxError_EmptyExpression( m_line, m_column );
    4.77 -	}
    4.78 -
    4.79 -	if ( m_line[ m_column ] != ',' )
    4.80 -	{
    4.81 -		// did not find a comma
    4.82 -		throw AsmException_SyntaxError_InvalidCharacter( m_line, m_column );
    4.83 -	}
    4.84 -
    4.85 -	m_column++;
    4.86 -
    4.87  	start = EvaluateExpressionAsInt();
    4.88  	exec = start;
    4.89  	reload = start;
    4.90 @@ -1057,6 +1053,35 @@
    4.91  		throw AsmException_SyntaxError_UnexpectedComma( m_line, m_column );
    4.92  	}
    4.93  
    4.94 +	if ( saveFile == "" )
    4.95 +	{
    4.96 +		if ( GlobalData::Instance().GetOutputFile() != NULL )
    4.97 +		{
    4.98 +			saveFile = GlobalData::Instance().GetOutputFile();
    4.99 +
   4.100 +			if ( GlobalData::Instance().IsSecondPass() )
   4.101 +			{
   4.102 +				if ( GlobalData::Instance().GetNumAnonSaves() > 0 )
   4.103 +				{
   4.104 +					throw AsmException_SyntaxError_OnlyOneAnonSave( m_line, oldColumn );
   4.105 +				}
   4.106 +				else
   4.107 +				{
   4.108 +					GlobalData::Instance().IncNumAnonSaves();
   4.109 +				}
   4.110 +			}
   4.111 +		}
   4.112 +		else
   4.113 +		{
   4.114 +			throw AsmException_SyntaxError_NoAnonSave( m_line, oldColumn );
   4.115 +		}
   4.116 +	}
   4.117 +
   4.118 +	if ( GlobalData::Instance().ShouldOutputAsm() )
   4.119 +	{
   4.120 +		cout << "Saving file '" << saveFile << "'" << endl;
   4.121 +	}
   4.122 +
   4.123  	// OK - do it
   4.124  
   4.125  	if ( GlobalData::Instance().IsSecondPass() )
   4.126 @@ -1683,7 +1708,6 @@
   4.127  			}
   4.128  
   4.129  			m_sourceCode->GetCurrentMacro()->SetName( macroName );
   4.130 -//			cout << "MACRO '" << macroName << "'" << endl;
   4.131  		}
   4.132  	}
   4.133  	else
   4.134 @@ -1715,7 +1739,6 @@
   4.135  			if ( GlobalData::Instance().IsFirstPass() )
   4.136  			{
   4.137  				m_sourceCode->GetCurrentMacro()->AddParameter( param );
   4.138 -//				cout << "  param: '" << param << "'" << endl;
   4.139  			}
   4.140  			bExpectComma = true;
   4.141  			bHasParameters = true;
     5.1 --- a/src/globaldata.cpp	Mon Apr 25 03:53:44 2011 +0200
     5.2 +++ b/src/globaldata.cpp	Mon Apr 25 04:33:59 2011 +0200
     5.3 @@ -72,7 +72,8 @@
     5.4  		m_bUseDiscImage( false ),
     5.5  		m_pDiscImage( NULL ),
     5.6  		m_bSaved( false ),
     5.7 -		m_pOutputFile( NULL )
     5.8 +		m_pOutputFile( NULL ),
     5.9 +		m_numAnonSaves( 0 )
    5.10  {
    5.11  }
    5.12  
     6.1 --- a/src/globaldata.h	Mon Apr 25 03:53:44 2011 +0200
     6.2 +++ b/src/globaldata.h	Mon Apr 25 04:33:59 2011 +0200
     6.3 @@ -45,6 +45,7 @@
     6.4  	inline void ResetForId()					{ m_forId = 0; }
     6.5  	inline void SetSaved()						{ m_bSaved = true; }
     6.6  	inline void SetOutputFile( const char* p )	{ m_pOutputFile = p; }
     6.7 +	inline void IncNumAnonSaves()				{ m_numAnonSaves++; }
     6.8  
     6.9  	inline int GetPass() const					{ return m_pass; }
    6.10  	inline bool IsFirstPass() const				{ return ( m_pass == 0 ); }
    6.11 @@ -56,6 +57,7 @@
    6.12  	inline int GetNextForId()					{ return m_forId++; }
    6.13  	inline bool IsSaved() const					{ return m_bSaved; }
    6.14  	inline const char* GetOutputFile() const	{ return m_pOutputFile; }
    6.15 +	inline int GetNumAnonSaves() const			{ return m_numAnonSaves; }
    6.16  
    6.17  
    6.18  private:
    6.19 @@ -74,6 +76,7 @@
    6.20  	int							m_randomSeed;
    6.21  	bool						m_bSaved;
    6.22  	const char*					m_pOutputFile;
    6.23 +	int							m_numAnonSaves;
    6.24  };
    6.25  
    6.26  
     7.1 --- a/src/lineparser.cpp	Mon Apr 25 03:53:44 2011 +0200
     7.2 +++ b/src/lineparser.cpp	Mon Apr 25 04:33:59 2011 +0200
     7.3 @@ -217,14 +217,12 @@
     7.4  
     7.5  						if ( !SymbolTable::Instance().IsSymbolDefined( paramName ) )
     7.6  						{
     7.7 -//							cout << "   (symbol '" << paramName << "' = " << value << ")" << endl;
     7.8  							SymbolTable::Instance().AddSymbol( paramName, value );
     7.9  						}
    7.10  
    7.11  					}
    7.12  					catch ( AsmException_SyntaxError_SymbolNotDefined& )
    7.13  					{
    7.14 -//						cout << "   (symbol '" << paramName << "' not yet known)" << endl;
    7.15  						if ( GlobalData::Instance().IsSecondPass() )
    7.16  						{
    7.17  							throw;
    7.18 @@ -250,13 +248,6 @@
    7.19  				MacroInstance macroInstance( macro, m_sourceCode );
    7.20  				macroInstance.Process();
    7.21  
    7.22 -//				for ( int i = 0; i < macro->GetNumberOfLines(); i++ )
    7.23 -//				{
    7.24 -//					LineParser macroLine( m_sourceCode, macro->GetLine( i ) );
    7.25 -//					cout << "   macro: " << macro->GetLine( i ) << endl;
    7.26 -//					macroLine.Process();
    7.27 -//				}
    7.28 -
    7.29  				HandleCloseBrace();
    7.30  
    7.31  				if ( GlobalData::Instance().ShouldOutputAsm() )
    7.32 @@ -323,10 +314,7 @@
    7.33  		}
    7.34  	}
    7.35  
    7.36 -	if ( m_sourceCode->GetCurrentMacro() != NULL )//&&
    7.37 -//		 m_line[ oldColumn ] != ':' &&
    7.38 -//		 m_line[ oldColumn ] != '\\' &&
    7.39 -//		 m_line[ oldColumn ] != ';' )
    7.40 +	if ( m_sourceCode->GetCurrentMacro() != NULL )
    7.41  	{
    7.42  		string command = m_line.substr( oldColumn, m_column - oldColumn );
    7.43  
    7.44 @@ -336,7 +324,6 @@
    7.45  		}
    7.46  
    7.47  		m_sourceCode->GetCurrentMacro()->AddLine( command );
    7.48 -//		cout << "   '" << command << "'" << endl;
    7.49  	}
    7.50  }
    7.51  
     8.1 --- a/src/sourcecode.cpp	Mon Apr 25 03:53:44 2011 +0200
     8.2 +++ b/src/sourcecode.cpp	Mon Apr 25 04:33:59 2011 +0200
     8.3 @@ -94,7 +94,6 @@
     8.4  
     8.5  	string lineFromFile;
     8.6  
     8.7 -//	while ( getline( m_file, lineFromFile ) )
     8.8  	while ( GetLine( lineFromFile ) )
     8.9  	{
    8.10  		// Convert tabs to spaces
    8.11 @@ -532,7 +531,6 @@
    8.12  
    8.13  	if ( GlobalData::Instance().IsFirstPass() )
    8.14  	{
    8.15 -//		cout << "Macro: '" << m_currentMacro->GetBody() << "'" << endl;
    8.16  		MacroTable::Instance().Add( m_currentMacro );
    8.17  		m_currentMacro = NULL;
    8.18  	}