Skip to content

Commit

Permalink
Use SymbolName for symbol names instead of std::string
Browse files Browse the repository at this point in the history
  • Loading branch information
mungre committed Jun 2, 2024
1 parent 0a0c3cb commit 6f487d2
Show file tree
Hide file tree
Showing 19 changed files with 349 additions and 62 deletions.
3 changes: 3 additions & 0 deletions src/VS2010/BeebAsm.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<ClCompile Include="..\sourcecode.cpp" />
<ClCompile Include="..\sourcefile.cpp" />
<ClCompile Include="..\stringutils.cpp" />
<ClCompile Include="..\symbolnamecache.cpp" />
<ClCompile Include="..\symboltable.cpp" />
</ItemGroup>
<ItemGroup>
Expand All @@ -112,6 +113,8 @@
<ClInclude Include="..\sourcecode.h" />
<ClInclude Include="..\sourcefile.h" />
<ClInclude Include="..\stringutils.h" />
<ClInclude Include="..\symbolname.h" />
<ClInclude Include="..\symbolnamecache.h" />
<ClInclude Include="..\symboltable.h" />
<ClInclude Include="..\value.h" />
</ItemGroup>
Expand Down
9 changes: 9 additions & 0 deletions src/VS2010/BeebAsm.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<ClCompile Include="..\literals.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\symbolnamecache.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\asmexception.h">
Expand Down Expand Up @@ -119,5 +122,11 @@
<ClInclude Include="..\scopedsymbolname.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\symbolname.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\symbolnamecache.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
11 changes: 6 additions & 5 deletions src/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "discimage.h"
#include "BASIC.h"
#include "random.h"
#include "symbolnamecache.h"


using namespace std;
Expand Down Expand Up @@ -496,7 +497,7 @@ void LineParser::HandleDefineLabel()

// Get the symbol name

string symbolName = GetSymbolName();
SymbolName symbolName = GetSymbolName();

// ...and apply the current scope

Expand Down Expand Up @@ -530,7 +531,7 @@ void LineParser::HandleDefineLabel()

if ( m_sourceCode->ShouldOutputAsm() )
{
cout << "." << symbolName << endl;
cout << "." << SymbolNameCache::Instance().GetString(symbolName) << endl;
}
}
else
Expand Down Expand Up @@ -595,7 +596,7 @@ void LineParser::HandleOrg()
args.CheckComplete();

ObjectCode::Instance().SetPC( newPC );
SymbolTable::Instance().ChangeBuiltInSymbol( "P%", newPC );
SymbolTable::Instance().ChangeBuiltInSymbol( SymbolNameCache::Instance().SymbolPPercent(), newPC );
}


Expand Down Expand Up @@ -1670,7 +1671,7 @@ void LineParser::HandleMacro()
throw AsmException_SyntaxError_EmptyExpression( m_line, m_column );
}

string macroName;
SymbolName macroName;

if ( isalpha( m_line[ m_column ] ) || m_line[ m_column ] == '_' )
{
Expand Down Expand Up @@ -1710,7 +1711,7 @@ void LineParser::HandleMacro()
}
else if ( isalpha( m_line[ m_column ] ) || m_line[ m_column ] == '_' )
{
string param = GetSymbolName();
SymbolName param = GetSymbolName();

if ( GlobalData::Instance().IsFirstPass() )
{
Expand Down
5 changes: 3 additions & 2 deletions src/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "constants.h"
#include "stringutils.h"
#include "literals.h"
#include "symbolnamecache.h"

using namespace std;

Expand Down Expand Up @@ -205,9 +206,9 @@ Value LineParser::GetValue()
// get a symbol

int oldColumn = m_column;
string symbolName = GetSymbolName();
SymbolName symbolName = GetSymbolName();

if (symbolName == "TIME$")
if (symbolName == SymbolNameCache::Instance().SymbolTimeDollar() )
{
// Handle TIME$ with no parameters
value = FormatAssemblyTime("%a,%d %b %Y.%H:%M:%S");
Expand Down
11 changes: 6 additions & 5 deletions src/lineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "symboltable.h"
#include "globaldata.h"
#include "sourcefile.h"
#include "symbolnamecache.h"


using namespace std;
Expand Down Expand Up @@ -218,13 +219,13 @@ void LineParser::Process( string line )

if ( isalpha( m_line[ m_column ] ) || m_line[ m_column ] == '_' )
{
string macroName = GetSymbolName();
SymbolName macroName = GetSymbolName();
const Macro* macro = MacroTable::Instance().Get( macroName );
if ( macro != NULL )
{
if ( m_sourceCode->ShouldOutputAsm() )
{
cout << "Macro " << macroName << ":" << endl;
cout << "Macro " << SymbolNameCache::Instance().GetString(macroName) << ":" << endl;
}

HandleOpenBrace();
Expand Down Expand Up @@ -283,7 +284,7 @@ void LineParser::Process( string line )

if ( m_sourceCode->ShouldOutputAsm() )
{
cout << "End macro " << macroName << endl;
cout << "End macro " << SymbolNameCache::Instance().GetString(macroName) << endl;
}

continue;
Expand Down Expand Up @@ -545,7 +546,7 @@ bool LineParser::AdvanceAndCheckEndOfSubStatement(bool includeComma)
It is assumed that we are already pointing to a valid symbol name.
*/
/*************************************************************************************************/
string LineParser::GetSymbolName()
SymbolName LineParser::GetSymbolName()
{
assert( isalpha( m_line[ m_column ] ) || m_line[ m_column ] == '_' );

Expand All @@ -564,5 +565,5 @@ string LineParser::GetSymbolName()
m_line[ m_column - 1 ] != '%' &&
m_line[ m_column - 1 ] != '$' );

return symbolName;
return SymbolNameCache::Instance().GetSymbol(symbolName);
}
3 changes: 2 additions & 1 deletion src/lineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <string>
#include "value.h"
#include "symbolname.h"

class SourceCode;

Expand Down Expand Up @@ -116,7 +117,7 @@ class LineParser
bool AdvanceAndCheckEndOfSubStatement(bool includeComma);
void SkipStatement();
void SkipExpression( int bracketCount, bool bAllowOneMismatchedCloseBracket );
std::string GetSymbolName();
SymbolName GetSymbolName();

// assembler generating methods

Expand Down
8 changes: 4 additions & 4 deletions src/macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ MacroTable::MacroTable()
/*************************************************************************************************/
MacroTable::~MacroTable()
{
for ( map< std::string, Macro* >::iterator it = m_map.begin(); it != m_map.end(); ++it )
for ( map< SymbolName, Macro* >::iterator it = m_map.begin(); it != m_map.end(); ++it )
{
delete it->second;
}
Expand Down Expand Up @@ -215,7 +215,7 @@ void MacroTable::Add( Macro* macro )
Returns whether or not the named macro yet exists
*/
/*************************************************************************************************/
bool MacroTable::Exists( const string& name ) const
bool MacroTable::Exists( SymbolName name ) const
{
return m_map.find( name ) != m_map.cend();
}
Expand All @@ -228,9 +228,9 @@ bool MacroTable::Exists( const string& name ) const
Returns a reference to the named macro
*/
/*************************************************************************************************/
const Macro* MacroTable::Get( const string& name ) const
const Macro* MacroTable::Get( SymbolName name ) const
{
map<string, Macro*>::const_iterator it = m_map.find( name );
map<SymbolName, Macro*>::const_iterator it = m_map.find( name );
if (it != m_map.cend())
{
return it->second;
Expand Down
18 changes: 9 additions & 9 deletions src/macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class Macro
Macro( const std::string& filename, int lineNumber );


void SetName( const std::string& name )
void SetName( SymbolName name )
{
m_name = name;
}

void AddParameter( const std::string& param )
void AddParameter( SymbolName param )
{
m_parameters.push_back( param );
}
Expand All @@ -54,7 +54,7 @@ class Macro
m_body += line;
}

const std::string& GetName() const
const SymbolName GetName() const
{
return m_name;
}
Expand All @@ -64,7 +64,7 @@ class Macro
return m_parameters.size();
}

const std::string& GetParameter( int i ) const
const SymbolName GetParameter( int i ) const
{
return m_parameters[ i ];
}
Expand All @@ -90,8 +90,8 @@ class Macro
std::string m_filename;
int m_lineNumber;

std::string m_name;
std::vector< std::string > m_parameters;
SymbolName m_name;
std::vector< SymbolName > m_parameters;
std::string m_body;

};
Expand Down Expand Up @@ -129,15 +129,15 @@ class MacroTable
static inline MacroTable& Instance() { assert( m_gInstance != NULL ); return *m_gInstance; }

void Add( Macro* macro );
bool Exists( const std::string& name ) const;
const Macro* Get( const std::string& name ) const;
bool Exists( SymbolName name ) const;
const Macro* Get( SymbolName name ) const;

private:

MacroTable();
~MacroTable();

std::map< std::string, Macro* > m_map;
std::map< SymbolName, Macro* > m_map;

static MacroTable* m_gInstance;
};
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "asmexception.h"
#include "globaldata.h"
#include "objectcode.h"
#include "symbolnamecache.h"
#include "symboltable.h"
#include "discimage.h"
#include "BASIC.h"
Expand Down Expand Up @@ -85,6 +86,7 @@ int main( int argc, char* argv[] )
bool bDumpAllSymbols = false;

GlobalData::Create();
SymbolNameCache::Create();
SymbolTable::Create();

// Parse command line parameters
Expand Down Expand Up @@ -358,6 +360,7 @@ int main( int argc, char* argv[] )
MacroTable::Destroy();
ObjectCode::Destroy();
SymbolTable::Destroy();
SymbolNameCache::Destroy();
GlobalData::Destroy();

return exitCode;
Expand Down
16 changes: 8 additions & 8 deletions src/objectcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "symboltable.h"
#include "asmexception.h"
#include "globaldata.h"

#include "symbolnamecache.h"

ObjectCode* ObjectCode::m_gInstance = NULL;

Expand Down Expand Up @@ -82,7 +82,7 @@ ObjectCode::ObjectCode()
{
memset( m_aMemory, 0, sizeof m_aMemory );
memset( m_aFlags, 0, sizeof m_aFlags );
SymbolTable::Instance().AddBuiltInSymbol( "CPU", m_CPU );
SymbolTable::Instance().AddBuiltInSymbol( SymbolNameCache::Instance().SymbolCpu(), m_CPU );
}


Expand Down Expand Up @@ -110,7 +110,7 @@ ObjectCode::~ObjectCode()
void ObjectCode::SetCPU( int i )
{
m_CPU = i;
SymbolTable::Instance().ChangeBuiltInSymbol( "CPU", m_CPU );
SymbolTable::Instance().ChangeBuiltInSymbol( SymbolNameCache::Instance().SymbolCpu(), m_CPU );
}


Expand All @@ -128,7 +128,7 @@ void ObjectCode::InitialisePass()

SetCPU( 0 );
SetPC( 0 );
SymbolTable::Instance().ChangeBuiltInSymbol( "P%", m_PC );
SymbolTable::Instance().ChangeBuiltInSymbol( SymbolNameCache::Instance().SymbolPPercent(), m_PC );

// Clear flags between passes

Expand Down Expand Up @@ -173,7 +173,7 @@ void ObjectCode::PutByte( unsigned int byte )
m_aFlags[ m_PC ] |= USED;
m_aMemory[ m_PC++ ] = byte;

SymbolTable::Instance().ChangeBuiltInSymbol( "P%", m_PC );
SymbolTable::Instance().ChangeBuiltInSymbol( SymbolNameCache::Instance().SymbolPPercent(), m_PC );
}


Expand Down Expand Up @@ -216,7 +216,7 @@ void ObjectCode::Assemble1( unsigned int opcode )
m_aFlags[ m_PC ] |= ( USED | CHECK );
m_aMemory[ m_PC++ ] = opcode;

SymbolTable::Instance().ChangeBuiltInSymbol( "P%", m_PC );
SymbolTable::Instance().ChangeBuiltInSymbol( SymbolNameCache::Instance().SymbolPPercent(), m_PC );
}


Expand Down Expand Up @@ -264,7 +264,7 @@ void ObjectCode::Assemble2( unsigned int opcode, unsigned int val )
m_aFlags[ m_PC ] |= USED;
m_aMemory[ m_PC++ ] = val;

SymbolTable::Instance().ChangeBuiltInSymbol( "P%", m_PC );
SymbolTable::Instance().ChangeBuiltInSymbol( SymbolNameCache::Instance().SymbolPPercent(), m_PC );
}


Expand Down Expand Up @@ -316,7 +316,7 @@ void ObjectCode::Assemble3( unsigned int opcode, unsigned int addr )
m_aFlags[ m_PC ] |= USED;
m_aMemory[ m_PC++ ] = ( addr & 0xFF00 ) >> 8;

SymbolTable::Instance().ChangeBuiltInSymbol( "P%", m_PC );
SymbolTable::Instance().ChangeBuiltInSymbol( SymbolNameCache::Instance().SymbolPPercent(), m_PC );
}


Expand Down
Loading

0 comments on commit 6f487d2

Please sign in to comment.