public Program Import(TextReader input, ImportErrorList errors)
        {
            try
            {
                // Do main import
                ProgramBuilder builder = ImportBuilder(input, errors);

                // Exit if there were errors
                if (errors.ErrorCount > 0)
                    return null;
                else if (builder == null)
                    throw new ImportException("Unknown import error");

                // Create program
                Program program = builder.CreateProgram(Processor, KeepDebugInfo);

                // Validate program
                ProgramValidator.Validate(program, errors);
                return (errors.ErrorCount == 0) ? program : null;
            }
            catch (ImportException e)
            {
                // Add to error list
                errors.AddError(e.Message);
                return null;
            }
        }
 protected override ProgramBuilder ImportBuilder(TextReader input, ImportErrorList errors)
 {
     // Create new importer state and forward to that
     var state = new AssemblyImporterState(input, errors);
     state.ParseTopLevel();
     return state.Builder;
 }
Beispiel #3
0
        public FrmViewError(ImportErrorList Err)
        {
            InitializeComponent();
            this.DS = new DataSet("a");
            DataTable T = new DataTable("aa");

            T.Columns.Add("tipo", typeof(string));
            T.Columns.Add("messaggio", typeof(string));

            btnSave.Enabled      = (T.Rows.Count > 0);
            T.Columns[0].Caption = "Errore";
            HelpForm.SetDataGrid(gridCheck, T);
        }
Beispiel #4
0
        protected override ProgramBuilder ImportBuilder(TextReader input, ImportErrorList errors)
        {
            // Create disassembler and builder
            InstructionDisassembler disasm = InstructionDisassembler.Create(Processor);
            ProgramBuilder builder = new ProgramBuilder();

            // Disassemble each instruction and add to the builder
            for (int lineNumber = 1; ; lineNumber++)
            {
                string line = input.ReadLine();

                // Eof?
                if (line == null)
                    break;

                // Parse as hex
                int instructionInt;
                if (!int.TryParse(line, NumberStyles.HexNumber, null, out instructionInt))
                {
                    // Fail fast here
                    errors.AddError("Line is not a valid hex string", lineNumber);
                    return null;
                }

                // Try to disassemble and add instruction
                try
                {
                    builder.Add(disasm.Disassemble(instructionInt));
                }
                catch (ImportException e)
                {
                    // Report error
                    errors.AddError(e.Message, lineNumber);
                }
            }

            return builder;
        }
 public Visitor(Program program, ImportErrorList errors)
 {
     this.program = program;
     this.errors = errors;
 }
 /// <summary>
 /// Validates the given program
 /// </summary>
 /// <param name="program">program to validate</param>
 /// <param name="errors">error list to add any errors to</param>
 public static void Validate(Program program, ImportErrorList errors)
 {
     // Visit all the instructions with the validator
     new Visitor(program, errors).VisitAll();
 }
 /// <summary>
 /// Creates a new AssemblyImporter state
 /// </summary>
 /// <param name="input">input stream</param>
 /// <param name="errors">error list</param>
 public AssemblyImporterState(TextReader input, ImportErrorList errors)
 {
     this.errorList = errors;
     this.tokenizer = new AssemblyTokenizer(input);
 }
 /// <summary>
 /// Imports a program from the given reader
 /// </summary>
 /// <param name="input">input reader</param>
 /// <param name="errors">error list to write any errors to</param>
 /// <returns>the program builder containing the program's data</returns>
 /// <exception cref="ImportException">if thrown will be converted to an ImportError</exception>
 /// <remarks>
 /// An import failiure is marked by returning null or having any errors in the list
 /// </remarks>
 protected abstract ProgramBuilder ImportBuilder(TextReader input, ImportErrorList errors);