Mano pdp8 ProgramLine.cc
ProgramLine.cc
// LineNumber Class #ifndef PROGRAMLINE_CC #define PROGRAMLINE_CC #ifndef MANO_H #include "mano.h" #endif #ifndef CHAR_STRING_CC #include "charString.cc" #endif #ifndef LIST_CC #include "list.cc" #endif class ProgramLine { charString Label_charString_m; // Label, if any. charString Instruction_charString_m; // Instruction charString Operand_charString_m; // Operand charString Indirection_charString_m; // Indirection short LineNumber_short_m; // Code Line short FileLine_short_m; // Absolute line number short InstWord_short_m; // Decoded Instruction short Pointer_short_m; // What it points to. short Pointee_short_m; // What points to this. // Parse for Label Program Line void ParseLabel( charString CodeLine ) { cout << "ProgramLine: ParseLabel" << endl; list<charString> c_List; charString cS_Temp; CodeLine.remove( ',' ); // remove the label comma c_List = CodeLine.Tokenize( ' ' ); c_List.getfirst(); c_List.returnlast( cS_Temp ); if( cS_Temp == "I" ) ParseLabelIndirection( c_List ); // parse Program Line with Label switch( c_List.census() ) { case 2: // Label and Instruction c_List.returnfirst( Label_charString_m ); c_List.returnlast( Instruction_charString_m ); break; case 3: // Label and Instruction c_List.returnfirst( Label_charString_m ); c_List.getnext(); c_List.returncurrent( Instruction_charString_m ); c_List.returnlast( Operand_charString_m ); break; default: ; } } // ParseLabel void ParseCommand( charString CodeLine ) { cout << "ProgramLine: ParseCommand" << endl; list<charString> c_List; charString cS_Temp; cout << "ProgramLine: ParseCommand 1" << endl; c_List = CodeLine.Tokenize( ' ' ); c_List.getfirst(); c_List.returnlast( cS_Temp ); cout << "ProgramLine: ParseCommand 2" << endl; // parse Program Line switch( c_List.census() ) { case 1: // ORG, END cout << "ProgramLine: ParseCommand 3" << endl; c_List.returnfirst( Instruction_charString_m ); break; case 2: // Instruction and Operand cout << "ProgramLine: ParseCommand 4" << endl; c_List.returnfirst( Instruction_charString_m ); c_List.returnlast( Operand_charString_m ); break; case 3: // Label and Instruction cout << "ProgramLine: ParseCommand 5" << endl; c_List.returnfirst( Instruction_charString_m ); c_List.getnext(); c_List.returncurrent( Operand_charString_m ); c_List.returnlast( Indirection_charString_m ); break; default: ; } } // ParseCommand void ParseLabelIndirection( list<charString> c_List ) { cout << "ProgramLine: ParseLabelIndirection" << endl; // parse Program Line with Indirection switch( c_List.census() ) { case 3: // Label and Instruction c_List.returnfirst( Label_charString_m ); c_List.getnext(); c_List.returncurrent( Instruction_charString_m ); c_List.returnlast( Indirection_charString_m ); break; case 4: c_List.returnfirst( Label_charString_m ); c_List.getnext(); c_List.returncurrent( Instruction_charString_m ); c_List.getnext(); c_List.returncurrent( Operand_charString_m ); c_List.returnlast( Indirection_charString_m ); break; default: ; } } // ParseIndirection public: ProgramLine() { cout << "ProgramLine: ParseLine()" << endl; LineNumber_short_m = -1; FileLine_short_m = -1; InstWord_short_m = -1; Pointer_short_m = -1; Pointee_short_m = -1; } ProgramLine( const ProgramLine& B ) { cout << "ProgramLine: ProgramLine( const ProgramLine& )" << endl; Instruction_charString_m = B.Instruction_charString_m; Label_charString_m = B.Label_charString_m; Operand_charString_m = B.Operand_charString_m; Indirection_charString_m = B.Indirection_charString_m; LineNumber_short_m = B.LineNumber_short_m; FileLine_short_m = B.FileLine_short_m; InstWord_short_m = B.InstWord_short_m; Pointer_short_m = B.Pointer_short_m; Pointee_short_m = B.Pointer_short_m; } ProgramLine( charString CodeLine, short s, short f ) { LineNumber_short_m = s; FileLine_short_m = f; InstWord_short_m = -1; Pointer_short_m = -1; Pointee_short_m = -1; cout << "ProgramLine: ProgramLine(,,,) 1 " << CodeLine << endl; if( CodeLine.Search( "," ) ) { cout << "ProgramLine: ProgramLine(,,,) 2 " << endl; ParseLabel( CodeLine ); } else { cout << "ProgramLine: ProgramLine(,,,) 3 " << endl; ParseCommand( CodeLine ); } } // ProgramLine( charString CodeLine, short s, short f ) ~ProgramLine(){} int operator != ( const ProgramLine &B ) { if( DEBUG ) cout << "LineNumber: != 0" << endl; return ( FileLine_short_m != B.FileLine_short_m ); } int operator < ( const ProgramLine &B ) { if( DEBUG ) cout << "LineNumber: < 0" << endl; return ( FileLine_short_m < B.FileLine_short_m ); } int operator > ( const ProgramLine &B ) { if( DEBUG ) cout << "LineNumber: > 0" << endl; return ( FileLine_short_m > B.FileLine_short_m ); } ProgramLine operator = ( const ProgramLine &B ) { if( DEBUG ) cout << "LineNumber: = 0" << endl; Instruction_charString_m = B.Instruction_charString_m; Label_charString_m = B.Label_charString_m; LineNumber_short_m = B.LineNumber_short_m; FileLine_short_m = B.FileLine_short_m; Operand_charString_m = B.Operand_charString_m; Indirection_charString_m = B.Indirection_charString_m; return *this; } int operator == ( const ProgramLine &B ) { if( DEBUG ) cout << "LineNumber: == 0" << endl; return ( FileLine_short_m == B.FileLine_short_m ); } void SetLabel( charString charString_A) { if( DEBUG ) cout << "LineNumber: SetLabel 0" << endl; Label_charString_m = charString_A; } void SetInstruction( charString charString_B ) { Instruction_charString_m = charString_B; } void SetOperand( charString charString_B ) { Operand_charString_m = charString_B; } void SetLocation( short short_Location ) { LineNumber_short_m = short_Location; } void SetFileLine( short short_linenumber ) { FileLine_short_m = short_linenumber; } charString GetInstruction() { if( DEBUG ) cout << "LineNumber: returnInstruction 0" << endl; return Instruction_charString_m; } charString GetLabel() { if( DEBUG ) cout << "LineNumber: returnLabel 0" << endl; return Label_charString_m; } short GetLineNumber() { if( DEBUG ) cout << "LineNumber: returnLocation 0" << endl; return LineNumber_short_m; } short GetFileLine() { if( DEBUG ) cout << "LineNumber: returnFileLine 0" << endl; return FileLine_short_m; } charString GetOperand() { if( DEBUG ) cout << "LineNumber: returnFileLine 0" << endl; return Operand_charString_m; } short GetInstWord() { return InstWord_short_m; } void SetInstWord( short s ) { InstWord_short_m = s; } void SetPointer( short s ) { Pointer_short_m = s; } short GetPointerTo() { return Pointer_short_m; } void SetPointee( short s ) { Pointee_short_m = s; } short GetPointeeFrom() { return Pointee_short_m; } int MultipleIndirection() { return ( Pointer_short_m && Pointee_short_m ); } charString GetIndirection() { return Indirection_charString_m; } }; #endif // LineNumber
Internal Links
Parent Article: Mano PDP-8 Simulation Project Source Code