def ParseLine(): """ We've got our source line. Now it's time to parse it all. However if we're defining a macro, we take a detour. First we look if it's an empty line or a comment line Then we extract the label field, if any. Then the mnemonic field, and act on its contents. It can be one of three things: A directive, a macro call or a mnemonic. Before executing the lot we also prepare the operand field. """ global Asm, Flags, Label dec.Asm.Parse_Pointer = 0 dec.Asm.New_Label = "" dec.Asm.Mnemonic = "" dec.Asm.List_Line = "" dec.Asm.Timing = "" dec.Asm.List_Byte_Cnt = 0 macrolevel = dec.Asm.Local_Index if dec.Asm.Parse_Line == chr(26) + " ": # Ctrl-Z, end mark for DOS files, ignore it return if dec.Asm.Macro_Def != '': # Defining a Macro, add this line to macro macros.DefineMacro() return if dec.Asm.Cond_False == 0: # Conditional assembly is true. Have to assemble this line # Select memory mode # May have changed by previous line if dec.Asm.Memory == 0: dec.Asm.BOL_Address = dec.Asm.PH_Address dec.Asm.List_Address = dec.Asm.PH_Address elif dec.Asm.Memory == 1: dec.Asm.BOL_Address = dec.Asm.RM_Address dec.Asm.List_Address = dec.Asm.RM_Address else: dec.Asm.BOL_Address = dec.Asm.EM_Address dec.Asm.List_Address = dec.Asm.EM_Address if IsComment(): # Do nothing if this line is empty or a comment line return newlabel = GetLabelName() globlab = string.ascii_uppercase + '_' # Legal begin chars of label if len(newlabel) > 0 and (newlabel[0] in globlab): # New global label defined newglobal = True else: # No new global lable defined newglobal = False if NowChar() == ":": # It's a macro label IncParsePointer() if NowChar() != " ": # Can't be a bare : errors.DoError('illlabel', False) return # Dont' bother to continue dec.Asm.New_Label = newlabel if len(newlabel) > 0: # Do a boundary sync if a label is given target.BoundarySync() dec.Asm.Mnemonic = GetMnemonic() if dec.Asm.Mnemonic == "": # No mnemonic means no operand either dec.Asm.Parse_Pointer = 0 else: # Parse the operand field dec.Asm.Parse_Pointer = FindOperandField() if newglobal and dec.Asm.Mnemonic[:3] != '.SE': # Set last assigned global label name, only when not .SE directive dec.Asm.Last_Global = newlabel # Reset macro indexes dec.Asm.Macro_Number = 0 dec.Asm.Local_Index = 0 DoAssemble() # Got all the ingredients, now put them all together if dec.Asm.New_Label != "": AssignLabel(dec.Asm.New_Label, macrolevel) else: # Conditional assembly is false, accept only .DO, .EL and # .FI directives if IsComment(): # Nothing to do in this line, it's a comment return if NowChar() != " ": # A label is declared here, get it but don't bother about syntax dec.Asm.New_Label = GetWord("", "", " ") dec.Asm.Mnemonic = GetMnemonic() if dec.Asm.Mnemonic != "": if dec.Asm.Mnemonic[:3] in (".DO", ".EL", ".FI"): # These are the only directives of interest now dec.Asm.Parse_Pointer = FindOperandField() DoAssemble()
def ParseLine(): """ We've got our source line. Now it's time to parse it all. However if we're defining a macro, we take a detour. First we look if it's an empty line or a comment line Then we extract the label field, if any. Then the mnemonic field, and act on its contents. It can be one of three things: A directive, a macro call or a mnemonic. Before executing the lot we also prepare the operand field. """ global Asm, Flags, Label global current_aid_pointer global array_aid, ending_address # JKL dec.Asm.Parse_Pointer = 0 dec.Asm.New_Label = "" dec.Asm.Mnemonic = "" dec.Asm.List_Line = "" dec.Asm.Timing = "" dec.Asm.List_Byte_Cnt = 0 macrolevel = dec.Asm.Local_Index if dec.Asm.Parse_Line == chr(26) + " ": # Ctrl-Z, end mark for DOS files, ignore it return if dec.Asm.Macro_Def != '': # Defining a Macro macros.DefineMacro() return if dec.Asm.Cond_False == 0: # Conditional assembly is ture. Have to assemble this line # Select memory mode # May have changed by previous line if dec.Asm.Memory == 0: dec.Asm.BOL_Address = dec.Asm.PH_Address dec.Asm.List_Address = dec.Asm.PH_Address elif dec.Asm.Memory == 1: dec.Asm.BOL_Address = dec.Asm.RM_Address dec.Asm.List_Address = dec.Asm.RM_Address else: dec.Asm.BOL_Address = dec.Asm.EM_Address dec.Asm.List_Address = dec.Asm.EM_Address if IsComment(): # Do nothing if this line is empty or a comment line return newlabel = GetLabelName() globlab = string.ascii_uppercase + '_' if len(newlabel) > 0 and (newlabel[0] in globlab): # Clear these in case we have to expand a macro on this line dec.Asm.Macro_Number = 0 dec.Asm.Local_Index = 0 dec.Asm.Last_Global = newlabel if NowChar() == ":": IncParsePointer() if NowChar() != " ": errors.DoError('illlabel', False) return # Dont' bother to continue dec.Asm.New_Label = newlabel if len(newlabel) > 0: # Do a boundary sync if a label is given target.BoundarySync() dec.Asm.Mnemonic = GetMnemonic() if dec.Asm.Mnemonic == "": dec.Asm.Parse_Pointer = 0 # No mnemonic means no operand either else: dec.Asm.Parse_Pointer = FindOperandField() DoAssemble() # Got all the ingredients, now put them all together if dec.Asm.New_Label != "": AssignLabel(dec.Asm.New_Label, macrolevel) else: # Conditional assembly is false, accept only .DO, .EL and .FI directives if IsComment(): # Nothing to do in this line, it's a comment return if NowChar() != " ": # A label is declared here, get it but don't bother about syntax dec.Asm.New_Label = GetWord("", "", " ") dec.Asm.Mnemonic = GetMnemonic() #jkl #sys.stdout = sys.__stdout__ if dec.Asm.Mnemonic != "": if dec.Asm.Mnemonic[:3] in (".DO", ".EL", ".FI"): # These are the only directives of interest now dec.Asm.Parse_Pointer = FindOperandField() DoAssemble() #JKL NOX if (len(dec.Asm.List_Line) > 0): #print(str(hex(dec.Asm.BOL_Address)) + " " +dec.Asm.Mnemonic + " " + dec.Asm.List_Line[8:14] + " " + str(dec.Asm.List_Byte_Cnt) + " ") # TODO ADD LABEL HERE, LINK BACK IN TO NEW ADDITIONAL SYMBOL TABLE array_aid[dec.Asm.BOL_Address] = { 'address': dec.Asm.BOL_Address, 'operator': dec.Asm.Mnemonic, 'operand': dec.Asm.List_Line[8:14], 'byte_cnt': dec.Asm.List_Byte_Cnt } print((array_aid[dec.Asm.BOL_Address])) ending_address = dec.Asm.BOL_Address