public void Run()
        {
            _logStream.WriteLine(DirectoryLogging.Summary, $"Post run called from code");

            foreach (var fileName in _virtualFS.RecursiveFileNames.Where(f => Path.GetFileNameWithoutExtension(f) != "Quokka"))
            {
                _logStream.WriteLine(DirectoryLogging.Summary, $"Generated file: {fileName}");
            }
            _logStream.WriteLine(DirectoryLogging.Summary, $"======================================");
        }
Exemplo n.º 2
0
        public FSWatcher(ILogStream logStream, string path)
        {
            _logStream = logStream;

            _logStream.WriteLine(eContentDomain.Public, $"Watching {path}");

            _watcher = new FileSystemWatcher(path);
            _watcher.IncludeSubdirectories = true;

            _watcher.Renamed += (s, a) =>
            {
                _stream.OnNext(new FSChange(path, a.FullPath));
            };

            _watcher.Changed += (s, a) =>
            {
                _stream.OnNext(new FSChange(path, a.FullPath));
            };

            _watcher.Deleted += (s, a) =>
            {
                _stream.OnNext(new FSDelete(path, a.FullPath));
            };

            _watcher.EnableRaisingEvents = true;
        }
Exemplo n.º 3
0
        void EventHandler(IEnumerable <FSEvent> list)
        {
            var sourceFiles = list.Where(e => FileTools.IsFileMatched(e.FullPath, CSharpProject.SupportedSourceFileTypes));

            if (!sourceFiles.Any())
            {
                return;
            }

            foreach (var e in sourceFiles)
            {
                if (e is FSDelete)
                {
                    _files.Remove(e.FullPath);
                }

                if (e is FSChange)
                {
                    string content;
                    if (FileTools.TryReadAllText(e.FullPath, out content))
                    {
                        _files[e.FullPath] = new SourceFileSnapshot()
                        {
                            ProjectName = mapFolderToProject[e.WatchPath],
                            FullPath    = e.FullPath,
                            Content     = content
                        };
                    }
                }
            }

            _logStream.WriteLine(eContentDomain.Public, "Codebase was changed");

            _stream.OnNext(new SourceCodeSnapshot(_files.Values));
        }
Exemplo n.º 4
0
        public void SaveCodeSnapshot(
            SourceCodeSnapshot codeSnapshot,
            string project,
            string projectLocation,
            HashSet <string> configurations)
        {
            var generatedFilesLocation = Path.Combine(projectLocation, "generated", project);
            var data = new Dictionary <string, string>();

            FileTools.CreateDirectoryRecursive(generatedFilesLocation);

            var stage = new CarryUserCode(_logStream);

            foreach (var pair in codeSnapshot)
            {
                var fileName     = Path.GetFileName(pair.FullPath);
                var existingFile = Path.Combine(generatedFilesLocation, fileName);

                if (File.Exists(existingFile))
                {
                    data[pair.FullPath] = stage.Transform(pair.Content, File.ReadAllText(existingFile));
                }
                else
                {
                    data[pair.FullPath] = pair.Content;
                }
            }

            foreach (var file in Directory.EnumerateFiles(generatedFilesLocation, "*.*"))
            {
                _logStream.WriteLine(eContentDomain.Public, ConsoleColor.DarkYellow, $"Deleting {Path.GetFileName(file)}");
                FileTools.DeleteFile(_logStream, file);
            }

            foreach (var pair in data.OrderBy(p => p.Key))
            {
                _logStream.WriteLine(eContentDomain.Public, ConsoleColor.Green, $"Writing {Path.GetFileName(pair.Key)}");
                File.WriteAllText(Path.Combine(generatedFilesLocation, pair.Key), pair.Value);
            }

            _logStream.WriteLine(eContentDomain.Public, $"Extracted {data.Count} files");

            SetupQSF(project, projectLocation, configurations);
        }
        void EventHandler(IEnumerable <FSEvent> list)
        {
            var projectFiles = list.Where(e => Path.GetExtension(e.FullPath) == CSharpProject.CSharpProjectExtension);

            if (projectFiles.Any())
            {
                DisposeWatchers();

                var projectReferences = CSharpProject.RecursiveCollectProjectReferences(ProjectPath);
                var projectFolders    = projectReferences.Select(r => Path.GetDirectoryName(r));

                watchers = projectFolders.Select(p => new FSWatcher(_logStream, p)).ToList();
                watchers.ForEach(w => w.Subscribe(e => _fsStream.OnNext(e)));

                _logStream.WriteLine(eContentDomain.Public, "Projects were changed");

                _stream.OnNext(new ProjectFoldersSnapshot(projectFolders));
            }
        }
Exemplo n.º 6
0
        public void Run()
        {
            _logStream.WriteLine(DirectoryLogging.Summary, $"QRV32 translation completed");
            _logStream.WriteLine(DirectoryLogging.Summary, $"Source location: {_runtimeConfiguration.SourceLocation}");
            _logStream.WriteLine(DirectoryLogging.Summary, $"Config name: {Path.GetFileName(_runtimeConfiguration.ConfigPath)}");

            var config = _runtimeConfiguration.Config;
            var generatedFilesLocation = FileTools.ToAbsolutePath(_runtimeConfiguration.SourceLocation, config.ProjectLocation);

            _logStream.WriteLine(DirectoryLogging.Summary, $"Generated files location: {generatedFilesLocation}");

            var hdlLocation = Path.Combine(Path.GetDirectoryName(_runtimeConfiguration.SourceLocation), "QRV32.HDL");
            var qsfPath     = Path.Combine(hdlLocation, "Verilog.qsf");

            _logStream.WriteLine(DirectoryLogging.Summary, $"Updating quartus files: {qsfPath}");

            if (File.Exists(qsfPath))
            {
                var generatedFiles = _virtualFS
                                     .RecursiveFileNames
                                     .Where(f => Path.GetFileNameWithoutExtension(f) != "Quokka")
                                     .Select(f => Path.Combine(generatedFilesLocation, f))
                                     .OrderBy(f => f)
                                     .ToList();

                foreach (var fileName in generatedFiles)
                {
                    _logStream.WriteLine(DirectoryLogging.Summary, $"Generated file: {fileName}");
                }

                _quartusTools.RemoveGeneratedFiles(qsfPath);
                _quartusTools.AddFiles(qsfPath, generatedFiles);
            }
            else
            {
                _logStream.WriteLine(DirectoryLogging.Summary, $"Project not found");
            }

            _logStream.WriteLine(DirectoryLogging.Summary, $"======================================");
        }
Exemplo n.º 7
0
        public static void DeleteFile(ILogStream logStream, string filePath)
        {
            int counter = 3;

            while (counter-- > 0)
            {
                try
                {
                    File.Delete(filePath);
                    break;
                }
                catch (Exception ex)
                {
                    logStream.WriteLine(eContentDomain.Public, "Caught exception: ", ex.GetType().Name);

                    if (counter == 0)
                    {
                        throw;
                    }

                    Task.Delay(TimeSpan.FromSeconds(1)).Wait();
                }
            }
        }
Exemplo n.º 8
0
        void Log(string text)
        {
            var indentationString = GenerateIndentationString();

            stream.WriteLine($"{indentationString}{text}");
        }
Exemplo n.º 9
0
 public static void WriteLine(this ILogStream stream, eContentDomain domain, string format = null, params object[] args)
 {
     stream.WriteLine(domain, ConsoleColor.White, format, args);
 }
Exemplo n.º 10
0
        public void WatchDirectory(string projectDirectory)
        {
            var projectPath = CSharpProject.GetSingleProjectFromFolder(projectDirectory);

            _logStream.WriteLine(eContentDomain.Public, $"Watching {projectPath}");

            QuokkaConfigLoader.Validate(projectDirectory);

            _logStream.WriteLine(eContentDomain.Public, $"Configration validated");

            Subject <string> fileSteam = new Subject <string>();

            using (var sourceCodeWatcher = new SourceCodeWatcher(_logStream))
            {
                sourceCodeWatcher.SnaphostsStream
                .Throttle(TimeSpan.FromMilliseconds(500))
                .Subscribe(codeSnapshot =>
                {
                    try
                    {
                        using (var scope = _containerFactory.CreateScope())
                        {
                            var logStream             = scope.Resolve <ILogStream>();
                            var projectTransformation = scope.Resolve <IQuokkaProjectTransformation>();

                            codeSnapshot.SourceFiles.ForEach(p => logStream.WriteLine(eContentDomain.Public, p.FullPath));

                            var config = QuokkaConfigLoader.Load(projectDirectory);

                            logStream.WriteLine(eContentDomain.Public, $"{DateTime.Now}, Transforming");

                            var result = projectTransformation.Transform(new TransformationRequest()
                            {
                                Sources        = codeSnapshot.SourceFiles.ToList(),
                                Configurations = config.Configurations
                            }).Result;

                            if (result.Result.Any())
                            {
                                new QuartusProjectTools(logStream)
                                .SaveCodeSnapshot(
                                    new SourceCodeSnapshot(result.Result),
                                    config.Project,
                                    config.ProjectLocation,
                                    config.Configurations.Select(c => c.Name).ToHashSet());
                            }
                            else
                            {
                                logStream.WriteLine(eContentDomain.Public, $"Transformation failed");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Exceptions.RethrowSystemException(ex);

                        _logStream.Log(ex);
                    }
                });

                using (var projectWatcher = new CSharpProjectWatcher(_logStream))
                {
                    projectWatcher.FoldersStream.Subscribe(s =>
                    {
                        s.ForEach(f => _logStream.WriteLine(eContentDomain.Public, f));

                        sourceCodeWatcher.WatchProjectFolders(s);
                    });

                    projectWatcher.WatchProject(projectPath);

                    Console.ReadLine();
                }
            }
        }
Exemplo n.º 11
0
        public void Run()
        {
            _logStream.WriteLine(DirectoryLogging.Summary, $"QuSoC translation completed");
            _logStream.WriteLine(DirectoryLogging.Summary, $"Source location: {_runtimeConfiguration.SourceLocation}");
            _logStream.WriteLine(DirectoryLogging.Summary, $"Config name: {Path.GetFileName(_runtimeConfiguration.ConfigPath)}");
            _logStream.WriteLine(DirectoryLogging.Summary, $"Generated files location: {generatedFilesLocation}");
            _logStream.WriteLine(DirectoryLogging.Summary, $"Updating quartus files: {qsfPath}");

            ModifyVerilogQSF();
            ModifyQuokkaBoardQSF();
            CopyTinyFPGAFiles();
        }
Exemplo n.º 12
0
        public bool CanTranslate()
        {
            var socTypes     = _componentsLibrary.ProjectAssembly.ExportedTypes.Where(t => t.Name == "SOC").ToList();
            var qusocModules = _componentsLibrary.ProjectAssembly.ExportedTypes.Where(t => typeof(QuSoCModule).IsAssignableFrom(t)).ToList();

            // create partial declaration for each app base of SoC configuration
            var wasModified = false;
            var appsPath    = Path.Combine(PathTools.ProjectPath, "apps");
            var apps        = Directory.EnumerateDirectories(appsPath);

            foreach (var appPath in apps)
            {
                var app     = Path.GetFileName(appPath);
                var socType = socTypes.SingleOrDefault(t => t.Namespace == app);
                var qusoc   = qusocModules.SingleOrDefault(t => t.Name == app);

                if (socType != null && qusoc != null)
                {
                    var           socTypeInstance   = Activator.CreateInstance(socType);
                    var           deviceAddress     = 0x80000000;
                    Func <string> nextDeviceAddress = () =>
                    {
                        var address = deviceAddress;
                        deviceAddress += 0x100000;
                        return(address.ToString("X8"));
                    };

                    List <string> moduleDeclarations = new List <string>();
                    List <string> moduleInitializers = new List <string>();
                    List <string> moduleSchedule     = new List <string>();
                    List <string> moduleNames        = new List <string>();
                    foreach (var member in socType.GetMembers(BindingFlags.Public | BindingFlags.Instance))
                    {
                        switch (member)
                        {
                        case PropertyInfo pi:
                        case FieldInfo fi:
                            var value      = member.GetValue(socTypeInstance);
                            var moduleName = $"{member.Name}Module";
                            moduleNames.Add(moduleName);
                            var memberType = member.GetMemberType();
                            if (memberType.IsArray)
                            {
                                var arraySize   = (value as IEnumerable).OfType <object>().Count();
                                var elementType = memberType.GetElementType();
                                if (elementType == typeof(uint))
                                {
                                    moduleDeclarations.Add($"SoCBlockRAMModule {moduleName}");
                                    moduleInitializers.Add($"{moduleName} = new SoCBlockRAMModule({arraySize});");
                                    moduleSchedule.Add($"{moduleName}.Schedule(() => new SoCBlockRAMModuleInputs() {{ Common = ModuleCommon, DeviceAddress = 0x{nextDeviceAddress()} }});");
                                }
                                else
                                {
                                    throw new Exception($"ElementType is not supported: {member}");
                                }
                            }
                            else
                            {
                                if (memberType == typeof(uint))
                                {
                                    moduleDeclarations.Add($"SoCRegisterModule {moduleName}");
                                    moduleInitializers.Add($"{moduleName} = new SoCRegisterModule();");
                                    moduleSchedule.Add($"{moduleName}.Schedule(() => new SoCRegisterModuleInputs() {{ Common = ModuleCommon, DeviceAddress = 0x{nextDeviceAddress()} }});");
                                }
                                else
                                {
                                    throw new Exception($"MemberType is not supported: {member}");
                                }
                            }
                            break;
                        }
                    }

                    _logStream.WriteLine(DirectoryLogging.Summary, $"Found SoC Type: {socType}");
                    var content = new StringBuilder();
                    content.AppendLine($"// partial declaration for {app} SoC. Generated by {GetType().Name}");
                    content.AppendLine($"using QuSoC;");
                    content.AppendLine($"namespace {socType.Namespace}");
                    content.AppendLine("{");
                    content.AppendLine($"\tpublic partial class {qusoc.Name}");
                    content.AppendLine("\t{");
                    foreach (var decl in moduleDeclarations)
                    {
                        content.AppendLine($"\t\tinternal {decl};");
                    }
                    content.AppendLine($"\t\tprotected override ISoCComponentModule[] GeneratedModules => new ISoCComponentModule[] {{ {moduleNames.ToCSV()} }};");

                    content.AppendLine($"\t\tprotected override void CreateGeneratedModules()");
                    content.AppendLine("\t\t{");
                    foreach (var init in moduleInitializers)
                    {
                        content.AppendLine($"\t\t\t{init}");
                    }
                    content.AppendLine("\t\t} // CreateGeneratedModules");

                    content.AppendLine($"\t\tprotected override void ScheduleGeneratedModules()");
                    content.AppendLine("\t\t{");
                    foreach (var schedule in moduleSchedule)
                    {
                        content.AppendLine($"\t\t\t{schedule}");
                    }
                    content.AppendLine("\t\t} // ScheduleGeneratedModules");

                    content.AppendLine("\t}");
                    content.AppendLine("}");

                    var socFileName = Path.Combine(appPath, "soc", $"{app}.generated.cs");
                    wasModified |= WriteFileIfChanged(socFileName, content.ToString());
                }
            }

            return(!wasModified);
        }
Exemplo n.º 13
0
        public void Run()
        {
            _logStream.WriteLine(DirectoryLogging.Summary, $"QuSoC translation completed");
            _logStream.WriteLine(DirectoryLogging.Summary, $"Source location: {_runtimeConfiguration.SourceLocation}");
            _logStream.WriteLine(DirectoryLogging.Summary, $"Config name: {_runtimeConfiguration.ConfigName}");

            var config = QuokkaConfigLoader.Load(Path.Combine(_runtimeConfiguration.SourceLocation, _runtimeConfiguration.ConfigName));
            var generatedFilesLocation = FileTools.ToAbsolutePath(Path.Combine(_runtimeConfiguration.SourceLocation, config.ProjectLocation));

            _logStream.WriteLine(DirectoryLogging.Summary, $"Generated files location: {generatedFilesLocation}");

            var hdlLocation = Path.Combine(Path.GetDirectoryName(_runtimeConfiguration.SourceLocation), "QuSoC.HDL");
            var qsfPath     = Path.Combine(hdlLocation, "Verilog.qsf");

            _logStream.WriteLine(DirectoryLogging.Summary, $"Updating quartus files: {qsfPath}");

            if (File.Exists(qsfPath))
            {
                var generatedFiles = _virtualFS
                                     .RecursiveFileNames
                                     .Where(f => Path.GetFileNameWithoutExtension(f) != "Quokka")
                                     .Select(f => Path.Combine(generatedFilesLocation, f))
                                     .OrderBy(f => f)
                                     .ToList();

                foreach (var fileName in generatedFiles)
                {
                    _logStream.WriteLine(DirectoryLogging.Summary, $"Generated file: {fileName}");
                }

                _quartusTools.RemoveGeneratedFiles(qsfPath);
                _quartusTools.AddFiles(qsfPath, generatedFiles);
            }
            else
            {
                _logStream.WriteLine(DirectoryLogging.Summary, $"Project not found");
            }


            var quokkaPath = Path.Combine(hdlLocation, "Quokka.qsf");

            _logStream.WriteLine(DirectoryLogging.Summary, $"Updating quokka files: {quokkaPath}");

            if (File.Exists(qsfPath))
            {
                var quokkaProjects = new[]
                {
                    "BlinkerInf",
                    "Counter"
                };

                var generatedFiles = _virtualFS
                                     .RecursiveFileNames
                                     .Where(f => Path.GetFileNameWithoutExtension(f) != "Quokka")
                                     .Where(f => quokkaProjects.Any(p => f.Contains(p)))
                                     .Select(f => Path.Combine(generatedFilesLocation, f))
                                     .OrderBy(f => f)
                                     .ToList();

                foreach (var fileName in generatedFiles)
                {
                    _logStream.WriteLine(DirectoryLogging.Summary, $"Generated file: {fileName}");
                }

                _quartusTools.RemoveGeneratedFiles(quokkaPath);
                _quartusTools.AddFiles(quokkaPath, generatedFiles);
            }
            else
            {
                _logStream.WriteLine(DirectoryLogging.Summary, $"Project not found");
            }

            _logStream.WriteLine(DirectoryLogging.Summary, $"====================================== {DateTime.Now}");
        }