bool ErrorHandler(AssemblerBase assembler, SourceLine line, AssemblyErrorReason reason, Exception ex) { if (reason == AssemblyErrorReason.ExceptionRaised) { if (_services.CurrentPass > 0) { _services.Log.LogEntry(line.Instruction, ex.Message); return(false); } return(true); } if (reason == AssemblyErrorReason.NotFound) { _services.Log.LogEntry(line.Instruction, $"Directive \"{line.Instruction}\" not allowed inside a function block."); } return(false); }
bool AssemblyErrorHandler(AssemblerBase assembler, SourceLine line, AssemblyErrorReason reason, Exception ex) { switch (reason) { case AssemblyErrorReason.NotFound: _services.Log.LogEntry(line.Instruction, $"Unknown instruction \"{line.Instruction.Name}\"."); return(true); case AssemblyErrorReason.ReturnNotAllowed: _services.Log.LogEntry(line.Instruction, "Directive \".return\" not valid outside of function block."); return(true); case AssemblyErrorReason.ExceptionRaised: { if (ex is SymbolException symbEx) { if (symbEx.SymbolToken != null) { _services.Log.LogEntry(symbEx.SymbolToken, symbEx.Message); } else { _services.Log.LogEntry(line, symbEx.Position, symbEx.Message); } } else if (ex is SyntaxException synEx) { if (synEx.Token != null) { _services.Log.LogEntry(synEx.Token, synEx.Message); } else if (line != null) { _services.Log.LogEntry(line, synEx.Position, synEx.Message); } else { _services.Log.LogEntrySimple(synEx.Message); } } else if (ex is InvalidCpuException cpuEx) { _services.Log.LogEntry(line, line.Instruction.Position, cpuEx.Message); } else if (ex is FormatException || ex is ReturnException || ex is BlockAssemblerException || ex is SectionException) { if (ex is FormatException) { _services.Log.LogEntry(line.Operands[0], $"There was a problem with the format string.", true); } else if (ex is ReturnException retEx) { _services.Log.LogEntry(line, retEx.Position, retEx.Message); } else { _services.Log.LogEntry(line.Instruction, ex.Message); } } else { if (_services.CurrentPass <= 0 || _services.PassNeeded) { if (assembler != null) { var instructionSize = assembler.GetInstructionSize(line); if (_services.Output.AddressIsValid(instructionSize + _services.Output.LogicalPC)) { _services.Output.AddUninitialized(instructionSize); } } _services.PassNeeded = true; return(true); } else { if (ex is ExpressionException expEx) { if (ex is IllegalQuantityException illegalExp) { _services.Log.LogEntry(line, illegalExp.Position, $"Illegal quantity for \"{line.Instruction.Name}\" ({illegalExp.Quantity})."); } else { _services.Log.LogEntry(line.Filename, line.LineNumber, expEx.Position, ex.Message); } } else if (ex is ProgramOverflowException) { _services.Log.LogEntry(line.Instruction, ex.Message); } else if (ex is InvalidPCAssignmentException pcEx) { if (pcEx.SectionNotUsedError) { _services.Log.LogEntry(line.Instruction, pcEx.Message); } else { _services.Log.LogEntry(line.Instruction, $"Invalid Program Counter assignment {pcEx.Message} in expression."); } } else { _services.Log.LogEntry(line.Operands[0], ex.Message); } } } } return(false); default: return(true); } }
/// <summary> /// Adds an <see cref="AssemblerBase"/> to the collection of assemblers that control /// assembly. /// </summary> /// <param name="lineAssembler">An <see cref="AssemblerBase"/> responsible for assembling /// directives not in the base assembler package.</param> public void AddAssembler(AssemblerBase lineAssembler) => _assemblers.Add(lineAssembler);