Skip to content

Commit

Permalink
Merge pull request #59 from stardot/mungre/verbose
Browse files Browse the repository at this point in the history
The VERBOSE symbol controls verbose output
  • Loading branch information
mungre authored Aug 19, 2022
2 parents b001acf + 44a569e commit fd3fdd9
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 58 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ If specified, BeebAsm will use this disc image as a template for the new disc im

`-v`

Verbose output. Assembled code will be output to the screen.
Force verbose output. Assembled code will be output to the screen. The VERBOSE symbol will be ignored.

`-q`

Force quiet (non-verbose) output. The VERBOSE symbol will be ignored. If neither `-v` or `-q` is used then verbose
output can be controlled by setting `VERBOSE=0` or `VERBOSE=1`. The value can be changed only in a new scope.

`-vc`

Expand Down
7 changes: 4 additions & 3 deletions src/assemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "globaldata.h"
#include "objectcode.h"
#include "asmexception.h"
#include "sourcecode.h"


using namespace std;
Expand Down Expand Up @@ -233,7 +234,7 @@ void LineParser::Assemble1( int instructionIndex, ADDRESSING_MODE mode )
{
assert( HasAddressingMode( instructionIndex, mode ) );

if ( GlobalData::Instance().ShouldOutputAsm() )
if ( m_sourceCode->ShouldOutputAsm() )
{
cout << uppercase << hex << setfill( '0' ) << " ";
cout << setw(4) << ObjectCode::Instance().GetPC() << " ";
Expand Down Expand Up @@ -272,7 +273,7 @@ void LineParser::Assemble2( int instructionIndex, ADDRESSING_MODE mode, unsigned
assert( value < 0x100 );
assert( HasAddressingMode( instructionIndex, mode ) );

if ( GlobalData::Instance().ShouldOutputAsm() )
if ( m_sourceCode->ShouldOutputAsm() )
{
cout << uppercase << hex << setfill( '0' ) << " ";
cout << setw(4) << ObjectCode::Instance().GetPC() << " ";
Expand Down Expand Up @@ -346,7 +347,7 @@ void LineParser::Assemble3( int instructionIndex, ADDRESSING_MODE mode, unsigned
assert( value < 0x10000 );
assert( HasAddressingMode( instructionIndex, mode ) );

if ( GlobalData::Instance().ShouldOutputAsm() )
if ( m_sourceCode->ShouldOutputAsm() )
{
cout << uppercase << hex << setfill( '0' ) << " ";
cout << setw(4) << ObjectCode::Instance().GetPC() << " ";
Expand Down
20 changes: 10 additions & 10 deletions src/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ void LineParser::HandleDefineLabel()
SymbolTable::Instance().AddLabel(symbolName);
}

if ( GlobalData::Instance().ShouldOutputAsm() )
if ( m_sourceCode->ShouldOutputAsm() )
{
cout << "." << symbolName << endl;
}
Expand Down Expand Up @@ -747,7 +747,7 @@ void LineParser::HandleSkip()
throw AsmException_SyntaxError_ImmNegative( m_line, oldColumn );
}

if ( GlobalData::Instance().ShouldOutputAsm() )
if ( m_sourceCode->ShouldOutputAsm() )
{
cout << uppercase << hex << setfill( '0' ) << " ";
cout << setw(4) << ObjectCode::Instance().GetPC() << endl;
Expand Down Expand Up @@ -824,7 +824,7 @@ void LineParser::HandleInclude()

string filename = EvaluateExpressionAsString();

if ( GlobalData::Instance().ShouldOutputAsm() )
if ( m_sourceCode->ShouldOutputAsm() )
{
cerr << "Including file " << filename << endl;
}
Expand Down Expand Up @@ -896,7 +896,7 @@ void LineParser::HandleEqub()
throw AsmException_SyntaxError_NumberTooBig( m_line, m_column );
}

if ( GlobalData::Instance().ShouldOutputAsm() )
if ( m_sourceCode->ShouldOutputAsm() )
{
cout << uppercase << hex << setfill( '0' ) << " ";
cout << setw(4) << ObjectCode::Instance().GetPC() << " ";
Expand Down Expand Up @@ -941,7 +941,7 @@ void LineParser::HandleEqub()
/*************************************************************************************************/
void LineParser::HandleEqus( const String& equs )
{
if ( GlobalData::Instance().ShouldOutputAsm() )
if ( m_sourceCode->ShouldOutputAsm() )
{
cout << uppercase << hex << setfill( '0' ) << " ";
cout << setw(4) << ObjectCode::Instance().GetPC() << " ";
Expand All @@ -951,7 +951,7 @@ void LineParser::HandleEqus( const String& equs )
{
int mappedchar = ObjectCode::Instance().GetMapping( equs[ i ] );

if ( GlobalData::Instance().ShouldOutputAsm() )
if ( m_sourceCode->ShouldOutputAsm() )
{
if ( i < 3 )
{
Expand All @@ -976,7 +976,7 @@ void LineParser::HandleEqus( const String& equs )
}
}

if ( GlobalData::Instance().ShouldOutputAsm() )
if ( m_sourceCode->ShouldOutputAsm() )
{
cout << endl << nouppercase << dec << setfill( ' ' );
}
Expand All @@ -997,7 +997,7 @@ void LineParser::HandleEquw()

do
{
if ( GlobalData::Instance().ShouldOutputAsm() )
if ( m_sourceCode->ShouldOutputAsm() )
{
cout << uppercase << hex << setfill( '0' ) << " ";
cout << setw(4) << ObjectCode::Instance().GetPC() << " ";
Expand Down Expand Up @@ -1044,7 +1044,7 @@ void LineParser::HandleEqud()

do
{
if ( GlobalData::Instance().ShouldOutputAsm() )
if ( m_sourceCode->ShouldOutputAsm() )
{
cout << uppercase << hex << setfill( '0' ) << " ";
cout << setw(4) << ObjectCode::Instance().GetPC() << " ";
Expand Down Expand Up @@ -1186,7 +1186,7 @@ void LineParser::HandleSave()

string saveFile = saveParam;

if ( GlobalData::Instance().ShouldOutputAsm() )
if ( m_sourceCode->ShouldOutputAsm() )
{
cout << "Saving file '" << saveFile << "'" << endl;
}
Expand Down
16 changes: 1 addition & 15 deletions src/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,21 +216,7 @@ Value LineParser::GetValue()
{
// Regular symbol

bool bFoundSymbol = false;

for ( int forLevel = m_sourceCode->GetForLevel(); forLevel >= 0; forLevel-- )
{
string fullSymbolName = symbolName + m_sourceCode->GetSymbolNameSuffix( forLevel );

if ( SymbolTable::Instance().IsSymbolDefined( fullSymbolName ) )
{
value = SymbolTable::Instance().GetSymbol( fullSymbolName );
bFoundSymbol = true;
break;
}
}

if ( !bFoundSymbol )
if ( !m_sourceCode->GetSymbolValue(symbolName, value) )
{
// symbol not known
throw AsmException_SyntaxError_SymbolNotDefined( m_line, oldColumn );
Expand Down
1 change: 1 addition & 0 deletions src/globaldata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void GlobalData::Destroy()
/*************************************************************************************************/
GlobalData::GlobalData()
: m_pBootFile( NULL ),
m_bVerboseSet( false ),
m_bVerbose( false ),
m_bUseDiscImage( false ),
m_pDiscImage( NULL ),
Expand Down
6 changes: 4 additions & 2 deletions src/globaldata.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GlobalData

inline void SetPass( int i ) { m_pass = i; }
inline void SetBootFile( const char* p ) { m_pBootFile = p; }
inline void SetVerbose( bool b ) { m_bVerbose = b; }
inline void SetVerbose( bool b ) { m_bVerboseSet = true; m_bVerbose = b; }
inline void SetUseDiscImage( bool b ) { m_bUseDiscImage = b; }
inline void SetDiscImage( DiscImage* d ) { m_pDiscImage = d; }
inline void ResetForId() { m_forId = 0; }
Expand All @@ -60,7 +60,8 @@ class GlobalData
inline int GetPass() const { return m_pass; }
inline bool IsFirstPass() const { return ( m_pass == 0 ); }
inline bool IsSecondPass() const { return ( m_pass == 1 ); }
inline bool ShouldOutputAsm() const { return ( m_pass == 1 && m_bVerbose ); }
inline bool IsVerboseSet() const { return m_bVerboseSet; }
inline bool IsVerbose() const { return m_bVerbose; }
inline const char* GetBootFile() const { return m_pBootFile; }
inline bool UsesDiscImage() const { return m_bUseDiscImage; }
inline DiscImage* GetDiscImage() const { return m_pDiscImage; }
Expand All @@ -85,6 +86,7 @@ class GlobalData

int m_pass;
const char* m_pBootFile;
bool m_bVerboseSet;
bool m_bVerbose;
bool m_bUseDiscImage;
DiscImage* m_pDiscImage;
Expand Down
4 changes: 2 additions & 2 deletions src/lineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void LineParser::Process()
const Macro* macro = MacroTable::Instance().Get( macroName );
if ( macro != NULL )
{
if ( GlobalData::Instance().ShouldOutputAsm() )
if ( m_sourceCode->ShouldOutputAsm() )
{
cout << "Macro " << macroName << ":" << endl;
}
Expand Down Expand Up @@ -273,7 +273,7 @@ void LineParser::Process()

HandleCloseBrace();

if ( GlobalData::Instance().ShouldOutputAsm() )
if ( m_sourceCode->ShouldOutputAsm() )
{
cout << "End macro " << macroName << endl;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ int main( int argc, char* argv[] )
{
GlobalData::Instance().SetVerbose( true );
}
else if ( strcmp( argv[i], "-q" ) == 0 )
{
GlobalData::Instance().SetVerbose( false );
}
else if ( strcmp( argv[i], "-d" ) == 0 )
{
bDumpSymbols = true;
Expand Down
54 changes: 54 additions & 0 deletions src/sourcecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,57 @@ bool SourceCode::IsRealForLevel( int level ) const
assert( level <= m_forStackPtr );
return m_forStack[ level - 1 ].m_step != 0.0;
}



/*************************************************************************************************/
/**
SourceCode::GetSymbolValue()
Search up the stack for a value for a symbol. N.B. This is dynamic scoping.
*/
/*************************************************************************************************/
bool SourceCode::GetSymbolValue(std::string name, Value& value)
{
for ( int forLevel = GetForLevel(); forLevel >= 0; forLevel-- )
{
string fullSymbolName = name + GetSymbolNameSuffix( forLevel );

if ( SymbolTable::Instance().IsSymbolDefined( fullSymbolName ) )
{
value = SymbolTable::Instance().GetSymbol( fullSymbolName );
return true;
}
}
return false;
}



/*************************************************************************************************/
/**
SourceCode::ShouldOutputAsm()
Return true if verbose output is required.
*/
/*************************************************************************************************/
bool SourceCode::ShouldOutputAsm()
{
if (!GlobalData::Instance().IsSecondPass())
return false;

if (GlobalData::Instance().IsVerboseSet())
{
return GlobalData::Instance().IsVerbose();
}

Value value;
if ( GetSymbolValue("VERBOSE", value) )
{
if (value.GetType() != Value::NumberValue)
return false;
return value.GetNumber() != 0;
}

return false;
}
4 changes: 4 additions & 0 deletions src/sourcecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <string>
#include <vector>

#include "value.h"

class Macro;

class SourceCode
Expand Down Expand Up @@ -120,7 +122,9 @@ class SourceCode
inline int GetInitialForStackPtr() const { return m_initialForStackPtr; }
inline Macro* GetCurrentMacro() { return m_currentMacro; }

bool GetSymbolValue(std::string name, Value& value);
std::string GetSymbolNameSuffix( int level = -1 ) const;
bool ShouldOutputAsm();

bool IsIfConditionTrue() const;
void AddIfLevel( const std::string& line, int column );
Expand Down
2 changes: 1 addition & 1 deletion src/sourcefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void SourceFile::Process()

// Display ok message

if ( GlobalData::Instance().ShouldOutputAsm() )
if ( ShouldOutputAsm() )
{
cerr << "Processed file '" << m_filename << "' ok" << endl;
}
Expand Down
2 changes: 2 additions & 0 deletions test/5-errors/filelinecallstackdemo.6502
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
\ beebasm -q

org &2000

macro foo n
Expand Down
26 changes: 4 additions & 22 deletions test/5-errors/filelinecallstackdemo.gold.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
.start
2000 A0 2A LDY #&2A
Current location:filelinecallstackdemo.6502:14
2002 A2 00 LDX #&00
.loop
Macro foo:
Macro bar:
2004 A9 18 LDA #&18
Current call stack:filelinecallstackdemo.6502:9
filelinecallstackdemo.6502:4
filelinecallstackdemo.6502:17 (end)
End macro bar
End macro foo
2006 9D 00 30 STA &3000,X
2009 C8 INY
200A E8 INX
200B E0 04 CPX #&04
200D D0 F5 BNE &2004
200F 60 RTS
.end
Saving file 'test'
Processed file 'filelinecallstackdemo.6502' ok
Current location:filelinecallstackdemo.6502:16
Current call stack:filelinecallstackdemo.6502:11
filelinecallstackdemo.6502:6
filelinecallstackdemo.6502:19 (end)
4 changes: 2 additions & 2 deletions test/testrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def read_beebasm_switches(file_name):
return params[1:]

def beebasm_args(beebasm, file_name, ssd_name):
args = [beebasm] + read_beebasm_switches(file_name)
args = [beebasm, '-v'] + read_beebasm_switches(file_name)
if ssd_name != None:
args += ['-do', ssd_name]
args += ['-v', '-i', file_name]
args += ['-i', file_name]
return args

def execute(args, output):
Expand Down

0 comments on commit fd3fdd9

Please sign in to comment.