コード例 #1
0
        public void SetUp()
        {
            Configuration cfg = new Configuration();
            cfg.AddType(typeof(AttributedUserDTO));
            m_assembler = cfg.GetAssembler<AttributedUserDTO, User>();
            m_source = new List<User>(3);
            m_source.Add(new User());
            m_source[0].FirstName = "Zdeslav";
            m_source[0].LastName = "Vojkovic";
            m_source[0].Age = 33;
            m_source[0].Id = 1;
            m_source[0].UserName = "******";

            m_source.Add(Helpers.CreateComplexUser());
            m_source.Add(m_source[1].Boss);
        }
コード例 #2
0
        public bool Build(IProject project)
        {
            IAssembler assembler = _assemblerFactory.CreateAssembler();

            AssemblerHelper.SetupAssembler(assembler, _inputFile, _outputFile, project.ProjectDirectory, project.IncludeDirs);

            AssemblerOutput output;
            string          outputString;

            switch (_stepType)
            {
            case BuildStepType.All:
                outputString = assembler.Assemble(AssemblyFlags.Normal | AssemblyFlags.SymbolTable | AssemblyFlags.List);
                output       = new AssemblerOutput(outputString, !outputString.Contains("error") && !outputString.Contains("Couldn't"));
                project.BuildSystem.ProjectOutput = _outputFile;
                project.BuildSystem.ListOutput    = _outputFile.ChangeExtension("lst");
                project.BuildSystem.LabelOutput   = _outputFile.ChangeExtension("lab");
                break;

            case BuildStepType.Assemble:
                outputString = assembler.Assemble(AssemblyFlags.Normal);
                output       = new AssemblerOutput(outputString, !outputString.Contains("error") && !outputString.Contains("Couldn't"));
                project.BuildSystem.ProjectOutput = _outputFile;
                break;

            case BuildStepType.Listing:
                outputString = assembler.Assemble(AssemblyFlags.Normal | AssemblyFlags.List);
                output       = new AssemblerOutput(outputString, !outputString.Contains("error") && !outputString.Contains("Couldn't"));
                project.BuildSystem.ListOutput = _outputFile.ChangeExtension("lst");
                break;

            case BuildStepType.SymbolTable:
                outputString = assembler.Assemble(AssemblyFlags.Normal | AssemblyFlags.SymbolTable);
                output       = new AssemblerOutput(outputString, !outputString.Contains("error") && !outputString.Contains("Couldn't"));
                project.BuildSystem.LabelOutput = _outputFile.ChangeExtension("lab");
                break;

            default:
                throw new InvalidOperationException("Unknown step type");
            }

            _outputText = output.OutputText;
            return(output.Succeeded);
        }
コード例 #3
0
ファイル: Loader.cs プロジェクト: erenes/reko
        public Program AssembleExecutable(string fileName, byte[] image, IAssembler asm, IPlatform platform, Address addrLoad)
        {
            var program = asm.Assemble(addrLoad, new StreamReader(new MemoryStream(image), Encoding.UTF8));

            program.Name     = Path.GetFileName(fileName);
            program.Platform = platform;
            foreach (var sym in asm.ImageSymbols)
            {
                program.ImageSymbols[sym.Address] = sym;
            }
            foreach (var ep in asm.EntryPoints)
            {
                program.EntryPoints[ep.Address] = ep;
            }
            program.EntryPoints[asm.StartAddress] =
                ImageSymbol.Procedure(program.Architecture, asm.StartAddress);
            CopyImportReferences(asm.ImportReferences, program);
            return(program);
        }
コード例 #4
0
        private IMessage Update(DataMessage dataMessage)
        {
            IList body  = dataMessage.body as IList;
            IList list2 = body[0] as IList;

            if ((list2 != null) && (list2.Count != 0))
            {
                IAssembler assembler = this.GetAssembler();
                if (assembler != null)
                {
                    if ((log != null) && log.get_IsDebugEnabled())
                    {
                        log.Debug(assembler.GetType().FullName + " Update");
                    }
                    assembler.UpdateItem(body[2], body[1], body[0] as IList);
                }
            }
            return(dataMessage);
        }
コード例 #5
0
        public static void SetupAssembler(IAssembler assembler, FilePath inputFile, FilePath outputFile,
                                          FilePath currentDirectory, IEnumerable <FilePath> includeDirs)
        {
            assembler.SetWorkingDirectory(currentDirectory);

            // include dirs
            assembler.AddIncludeDir(Application.StartupPath);
            foreach (string dir in includeDirs)
            {
                assembler.AddIncludeDir(dir);
            }

            // setup files
            assembler.SetInputFile(inputFile);
            assembler.SetOutputFile(outputFile);

            // set flags
            assembler.SetCaseSensitive(Settings.Default.CaseSensitive);
        }
コード例 #6
0
        public AssemblerOutput AssembleFile(FilePath inputFile, FilePath outputFile, FilePath originalDir,
                                            IEnumerable <FilePath> includeDirs, AssemblyFlags flags = AssemblyFlags.Normal)
        {
            string rawOutput;

            using (IAssembler assembler = _assemblerFactory.CreateAssembler())
            {
                AssemblerHelper.SetupAssembler(assembler, inputFile, outputFile, originalDir, includeDirs);
                rawOutput = assembler.Assemble(flags);
            }

            // lets write it to the output window so the user knows whats happening
            string outputText = string.Format(OutputFormatting, Path.GetFileName(inputFile), inputFile, rawOutput);

            bool errors = outputText.Contains("error");

            OnAssemblerFileFinished(this, new AssemblyFinishFileEventArgs(inputFile, outputFile, outputText, !errors));

            // tell if the assembly was successful
            return(new AssemblerOutput(outputText, !errors));
        }
コード例 #7
0
        public IVehicle CreateVehicle(string vehicleType, string model, double weight, decimal price, int attack, int defense, int hitPoints)
        {
            string assembler     = "VehicleAssembler";
            Type   typeAssembler = Assembly.GetCallingAssembly().GetTypes()
                                   .FirstOrDefault(t => t.Name == assembler);
            IAssembler assemblerClass = (IAssembler)Activator.CreateInstance(typeAssembler);

            Type types = Assembly.GetCallingAssembly().GetTypes()
                         .FirstOrDefault(t => t.Name == vehicleType);
            IVehicle vehicle = (IVehicle)Activator.CreateInstance(types, new object[] {
                model,
                weight,
                price,
                attack,
                defense,
                hitPoints,
                assemblerClass
            });

            return(vehicle);
        }
コード例 #8
0
        private IMessage Update(DataMessage dataMessage)
        {
            IList parameters   = dataMessage.body as IList;
            IList changeObject = parameters[0] as IList;

            if (changeObject == null || changeObject.Count == 0)
            {
                return(dataMessage);
            }

            IAssembler assembler = GetAssembler();

            if (assembler != null)
            {
                if (log != null && log.IsDebugEnabled)
                {
                    log.Debug(assembler.GetType().FullName + " Update");
                }
                assembler.UpdateItem(parameters[2], parameters[1], parameters[0] as IList);
            }
            return(dataMessage);
        }
コード例 #9
0
        public bool Assemble(string file, IAssembler asm, IPlatform platform)
        {
            var ldr = Services.RequireService <ILoader>();

            this.Decompiler = CreateDecompiler(ldr);
            var svc = Services.RequireService <IWorkerDialogService>();

            svc.StartBackgroundWork("Loading program", delegate()
            {
                Decompiler.Assemble(file, asm, platform);
            });
            if (Decompiler.Project == null)
            {
                return(false);
            }
            var browserSvc = Services.RequireService <IProjectBrowserService>();

            browserSvc.Load(Decompiler.Project);
            browserSvc.Show();
            ShowLowLevelWindow();
            return(false);
        }
コード例 #10
0
        public CodeCountInfo CountCode(string lines)
        {
            int size;
            int min;
            int max;

            string outputLines = null;

            using (IAssembler assembler = _assemblerFactory.CreateAssembler())
            {
                if (!string.IsNullOrEmpty(lines))
                {
                    outputLines = assembler.Assemble(lines, AssemblyFlags.CodeCounter | AssemblyFlags.Commandline);
                }
            }

            if (string.IsNullOrEmpty(outputLines))
            {
                return(new CodeCountInfo(0, 0, 0));
            }

            Match match = Regex.Match(outputLines, @"Size: (?<size>\d+)\s*Min. execution time: (?<min>\d+)\s*Max. execution time: (?<max>\d+)");

            if (!int.TryParse(match.Groups["size"].Value, out size))
            {
                size = 0;
            }

            if (!int.TryParse(match.Groups["min"].Value, out min))
            {
                min = 0;
            }

            if (!int.TryParse(match.Groups["max"].Value, out max))
            {
                max = 0;
            }
            return(new CodeCountInfo(size, min, max));
        }
コード例 #11
0
        private void CheckType <T>(string msg)
        {
            m_cfg.AddType(typeof(T));

            try
            {
                IAssembler <T, User> asm = m_cfg.GetAssembler <T, User>();
            }
            catch (OtisException e)
            {
                if (e.Message.EndsWith(msg))
                {
                    return;
                }
                Assert.Fail("Tested method threw an OtisException with incorrect message:"
                            + Environment.NewLine
                            + "Expected to end with: "
                            + msg
                            + Environment.NewLine
                            + "Instead was:          "
                            + e.Message);
            }
            Assert.Fail("Tested method didn't throw an OtisException!");
        }
コード例 #12
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="AssemblyFactory" /> class.
 /// </summary>
 /// <param name="process">The process.</param>
 /// <param name="assembler">The assembler.</param>
 public AssemblyFactory(IProcess process, IAssembler assembler)
 {
     Process   = process;
     Assembler = assembler;
 }
コード例 #13
0
 public Service(IAssembler <TDto, TEntity> assembler,
                IRepository <TEntity> repository)
 {
     this.assembler  = assembler;
     this.repository = repository;
 }
コード例 #14
0
 protected BaseVehicle(string model, double weight, decimal price, int attack, int defense, int hitPoints, IAssembler assembler)
 {
     this.Model        = model;
     this.Weight       = weight;
     this.Price        = price;
     this.Attack       = attack;
     this.Defense      = defense;
     this.HitPoints    = hitPoints;
     this.assembler    = assembler;
     this.orderedParts = new List <string>();
 }
コード例 #15
0
ファイル: Loader.cs プロジェクト: fengjixuchui/reko
        public Program AssembleExecutable(ImageLocation asmFileLocation, IAssembler asm, IPlatform platform, Address addrLoad)
        {
            var bytes = LoadFileBytes(asmFileLocation.FilesystemPath);

            return(AssembleExecutable(asmFileLocation, bytes, asm, platform, addrLoad));
        }
コード例 #16
0
ファイル: Loader.cs プロジェクト: fengjixuchui/reko
        public Program AssembleExecutable(ImageLocation asmFileLocation, byte[] image, IAssembler asm, IPlatform platform, Address addrLoad)
        {
            var program = asm.Assemble(addrLoad, new StreamReader(new MemoryStream(image), Encoding.UTF8));

            program.Name     = asmFileLocation.GetFilename();
            program.Location = asmFileLocation;
            program.Platform = platform;
            foreach (var sym in asm.ImageSymbols)
            {
                program.ImageSymbols[sym.Address !] = sym;
コード例 #17
0
 public Vanguard(string model, double weight, decimal price, int attack, int defense, int hitPoints, IAssembler assembler)
     : base(model, weight, price, attack, defense, hitPoints, new VehicleAssembler())
 {
 }
コード例 #18
0
 public DefaultProcessor(IAssembler <T> assembler)
 {
 }
コード例 #19
0
 public void SetUpDefaults()
 {
     Configuration cfg = new Configuration();
     cfg.AddType<AttributedUserDTO>();
     m_asm = cfg.GetAssembler<AttributedUserDTO, User>();
     m_user = Helpers.CreateComplexUser();
 }
コード例 #20
0
 public static T AssembleItem <T>(this IAssembler <T> assembler, MappedData data) where T : class
 {
     return(assembler.Assemble(data).FirstOrDefault());
 }
コード例 #21
0
 public bool Assemble(string file, IAssembler asm, IPlatform platform)
 {
     throw new NotImplementedException();
 }
コード例 #22
0
 public Mapper(Action <TTgt, TSrc> mappingAction, IAssembler <TTgt, TSrc> assembler)
 {
     _mappingAction = mappingAction;
     _assembler     = assembler;
 }
コード例 #23
0
 public Revenger(string model, double weight, decimal price, int attack, int defense, int hitPoints, IAssembler assembler)
     : base(model, weight, price, attack, defense, hitPoints, assembler)
 {
 }
コード例 #24
0
 public void SetUp()
 {
     assembler = new VehicleAssembler();
     vehicle   = new Revenger(VehicleModel, Weight, Price, Attack, Defense, HitPoints, assembler);
 }
コード例 #25
0
ファイル: GenTest.cs プロジェクト: dmarlowe69/6502bench
        /// <summary>
        /// Generates source code for the specified test case, assembles it, and compares
        /// the output of both steps to expected values.  The process is repeated for every
        /// known assembler.
        ///
        /// If an assembler is known but not configured, the assembly step is skipped, and
        /// does not count as a failure.
        /// </summary>
        /// <param name="pathName">Full path to test case.</param>
        /// <returns>True if all assemblers worked as expected.</returns>
        private bool GenerateAndAssemble(string pathName)
        {
            ReportProgress(Path.GetFileName(pathName) + "...\r\n");

            // Create DisasmProject object, either as a new project for a plain data file,
            // or from a project file.
            DisasmProject project = InstantiateProject(pathName,
                                                       out FileLoadReport projectLoadReport);

            if (project == null)
            {
                ReportFailure();
                return(false);
            }

            int testNum = GetTestNum(pathName);

            // Create a temporary directory to work in.
            string workDir = CreateWorkDirectory(pathName);

            if (string.IsNullOrEmpty(workDir))
            {
                ReportFailure();
                project.Cleanup();
                return(false);
            }

            AppSettings settings = CreateNormalizedSettings();

            ApplyProjectSettings(settings, project);

            // Iterate through all known assemblers.
            bool didFail = false;

            foreach (AssemblerInfo.Id asmId in
                     (AssemblerInfo.Id[])Enum.GetValues(typeof(AssemblerInfo.Id)))
            {
                if (asmId == AssemblerInfo.Id.Unknown)
                {
                    continue;
                }

                string    fileName = Path.GetFileName(pathName);
                TaskTimer timer    = new TaskTimer();
                timer.StartTask("Full Test Duration");

                // Create results object and add it to the list.  We'll add stuff to it for
                // as far as we get.
                GenTestResults results = new GenTestResults(pathName, asmId);
                mResults.Add(results);
                results.ProjectLoadReport = projectLoadReport;

                // Generate source code.
                ReportProgress("  " + asmId.ToString() + " generate...");
                IGenerator gen = AssemblerInfo.GetGenerator(asmId);
                if (gen == null)
                {
                    ReportErrMsg("generator unavailable");
                    ReportProgress("\r\n");
                    //didFail = true;
                    continue;
                }
                timer.StartTask("Generate Source");
                gen.Configure(project, workDir, fileName,
                              AssemblerVersionCache.GetVersion(asmId), settings);
                List <string> genPathNames = gen.GenerateSource(mWorker);
                timer.EndTask("Generate Source");
                if (mWorker.CancellationPending)
                {
                    // The generator will stop early if a cancellation is requested.  If we
                    // don't break here, the compare function will report a failure, which
                    // isn't too problematic but looks funny.
                    break;
                }

                ReportProgress(" verify...");
                timer.StartTask("Compare Source to Expected");
                bool match = CompareGeneratedToExpected(pathName, genPathNames);
                timer.EndTask("Compare Source to Expected");
                if (match)
                {
                    ReportSuccess();
                    results.GenerateOkay = true;
                }
                else
                {
                    ReportFailure();
                    didFail = true;

                    // The fact that it doesn't match the expected sources doesn't mean it's
                    // invalid.  Go ahead and try to build it.
                    //continue;
                }

                // Assemble code.
                ReportProgress("  " + asmId.ToString() + " assemble...");
                IAssembler asm = AssemblerInfo.GetAssembler(asmId);
                if (asm == null)
                {
                    ReportErrMsg("assembler unavailable");
                    ReportProgress("\r\n");
                    continue;
                }

                timer.StartTask("Assemble Source");
                asm.Configure(genPathNames, workDir);
                AssemblerResults asmResults = asm.RunAssembler(mWorker);
                timer.EndTask("Assemble Source");
                if (asmResults == null)
                {
                    ReportErrMsg("unable to run assembler");
                    ReportFailure();
                    didFail = true;
                    continue;
                }
                if (asmResults.ExitCode != 0)
                {
                    ReportErrMsg("assembler returned code=" + asmResults.ExitCode);
                    ReportFailure();
                    didFail = true;
                    continue;
                }

                results.AsmResults = asmResults;

                ReportProgress(" verify...");
                timer.StartTask("Compare Binary to Expected");
                FileInfo fi = new FileInfo(asmResults.OutputPathName);
                if (!fi.Exists)
                {
                    // This can happen if the assembler fails to generate output but doesn't
                    // report an error code (e.g. Merlin 32 in certain situations).
                    ReportErrMsg("asm output missing");
                    ReportFailure();
                    didFail = true;
                    continue;
                }
                else if (fi.Length != project.FileData.Length)
                {
                    ReportErrMsg("asm output mismatch: length is " + fi.Length + ", expected " +
                                 project.FileData.Length);
                    ReportFailure();
                    didFail = true;
                    continue;
                }
                else if (!FileUtil.CompareBinaryFile(project.FileData, asmResults.OutputPathName,
                                                     out int badOffset, out byte badFileVal))
                {
                    ReportErrMsg("asm output mismatch: offset +" + badOffset.ToString("x6") +
                                 " has value $" + badFileVal.ToString("x2") + ", expected $" +
                                 project.FileData[badOffset].ToString("x2"));
                    ReportFailure();
                    didFail = true;
                    continue;
                }
                timer.EndTask("Compare Binary to Expected");

                // Victory!
                results.AssembleOkay = true;
                ReportSuccess();

                timer.EndTask("Full Test Duration");
                results.Timer = timer;

                // We don't scrub the directory on success at this point.  We could, but we'd
                // need to remove only those files associated with the currently assembler.
                // Otherwise, a failure followed by a success would wipe out the unsuccessful
                // temporaries.
            }

            // If something failed, leave the bits around for examination.  Otherwise, try to
            // remove the directory and all its contents.
            if (!didFail && !RetainOutput)
            {
                ScrubWorkDirectory(workDir, testNum);
                RemoveWorkDirectory(workDir);
            }

            project.Cleanup();
            return(!didFail);
        }
コード例 #26
0
ファイル: GenAndAsm.xaml.cs プロジェクト: retroric/6502bench
 public AsmWorker(IAssembler asm)
 {
     mAssembler = asm;
 }
コード例 #27
0
 public void CheckModelOnCreation()
 {
     assembler = new VehicleAssembler();
     IVehicle vehicle = new Revenger("AAAAA", 50, 200.00m, 100, 200, 60, assembler);
 }
コード例 #28
0
ファイル: GenAndAsm.xaml.cs プロジェクト: retroric/6502bench
        private void RunAssemblerButton_Click(object sender, RoutedEventArgs e)
        {
            IAssembler asm = AssemblerInfo.GetAssembler(mSelectedAssemblerId);

            if (asm == null)
            {
                Debug.WriteLine("Unable to get assembler for " + mSelectedAssemblerId);
                return;
            }

            asm.Configure(mGenerationResults, mWorkDirectory);

            AsmWorker    aw  = new AsmWorker(asm);
            WorkProgress dlg = new WorkProgress(this, aw, true);

            dlg.ShowDialog();
            //Debug.WriteLine("Dialog returned: " + dlg.DialogResult);
            if (dlg.DialogResult != true)
            {
                // Canceled, or failed to even run the assembler.
                return;
            }

            AssemblerResults results = aw.Results;

            if (results == null)
            {
                Debug.WriteLine("Dialog returned OK, but no assembler results found");
                Debug.Assert(false);
                return;
            }

            StringBuilder sb =
                new StringBuilder(results.Stdout.Length + results.Stderr.Length + 200);

            sb.Append(results.CommandLine);
            sb.Append("\r\n");
            sb.AppendFormat("ExitCode={0} - ", results.ExitCode);
            if (results.ExitCode == 0)
            {
                FileInfo fi = new FileInfo(results.OutputPathName);
                if (!fi.Exists)
                {
                    MessageBox.Show(this, Res.Strings.ASM_OUTPUT_NOT_FOUND,
                                    Res.Strings.ASM_MISMATCH_CAPTION,
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    sb.Append(Res.Strings.ASM_MATCH_FAILURE);
                }
                else if (!CommonUtil.FileUtil.CompareBinaryFile(mProject.FileData,
                                                                results.OutputPathName, out int offset, out byte fileVal))
                {
                    if (fi.Length != mProject.FileData.Length &&
                        offset == fi.Length || offset == mProject.FileData.Length)
                    {
                        // The files matched up to the point where one ended.
                        string msg = string.Format(Res.Strings.ASM_MISMATCH_LENGTH_FMT,
                                                   fi.Length, mProject.FileData.Length);
                        MessageBox.Show(msg, Res.Strings.ASM_MISMATCH_CAPTION,
                                        MessageBoxButton.OK, MessageBoxImage.Error);
                        sb.Append(msg);
                    }
                    else
                    {
                        string msg = string.Format(Res.Strings.ASM_MISMATCH_DATA_FMT,
                                                   offset, fileVal, mProject.FileData[offset]);
                        MessageBox.Show(msg, Res.Strings.ASM_MISMATCH_CAPTION,
                                        MessageBoxButton.OK, MessageBoxImage.Error);
                        sb.Append(msg);
                    }
                }
                else
                {
                    sb.Append(Res.Strings.ASM_MATCH_SUCCESS);
                }
            }
コード例 #29
0
 private void OnCancelStream(IAssembler contentStreamAssembler)
 {
     Background.Run(() => _sendOperations.SendCancelStreamAsync(contentStreamAssembler.Id));
 }
コード例 #30
0
        public void Setup()
        {
            Configuration cfg;
            cfg = new Configuration();
            cfg.AddType<UserDTO>();
            cfg.AddType<ProjectDTO>(); // todo: should this be automatically detected
            cfg.AddType<DocumentDTO>(); // todo: should this be automatically detected
            cfg.AddType<TaskDTO>(); // todo: should this be automatically detected

            cfg.BuildAssemblers();

            m_assembler = cfg.GetAssembler<UserDTO, User>();

            m_user = Helpers.CreateComplexUser();
        }
コード例 #31
0
 public ProductController(IReadOnlyRepository <Product> repository, IAssembler <DTO.Product, Product> assembler)
 {
     _repository = repository;
     _assembler  = assembler;
 }
コード例 #32
0
        public Program AssembleExecutable(string fileName, IAssembler asm, IPlatform platform, Address addrLoad)
        {
            var bytes = LoadImageBytes(fileName, 0);

            return(AssembleExecutable(fileName, bytes, asm, platform, addrLoad));
        }
コード例 #33
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="gen">Fully-configured source generator.</param>
        public AssemblerProgress(IAssembler asm)
        {
            InitializeComponent();

            mAssembler = asm;
        }