private void test(Func <AifFile> getFile) { TestLogger.Setup(); var file = getFile(); var schedule = new IlpScheduler(file, file.MinCycles.Values.Max()); schedule.BuildSchedule(); var funcUnitAllocator = new FunctionalUnitAllocator(schedule); Assert.IsNotNull(funcUnitAllocator.Units); //The IP scheduler has determined the optimal resources needed. //Compare the results of functional allocator to the resources results from the IP scheduler. foreach (var resource in schedule.Resources) { Assert.AreEqual(funcUnitAllocator.Units.Count(unit => unit.Op == resource.Key), resource.Value, $"The unit count for {resource.Key} is wrong."); } foreach (var unit in funcUnitAllocator.Units) { //operations that share the same functional unit cannot share the same cycle index Assert.AreEqual(unit.Operations.Length, unit.Operations.Select(op => op.CycleIndex).Distinct().Count(), "Two operations with the same cycle index are sharing the same function unit."); } }
public static void Main(string[] args) { StreamWriter controller = null, dataPath = null, design = null, testBench = null; try { string fileName; var file = GetAifFile(out fileName); if (file == null) { return; } //1. Operation Scheduling: var schedule = GetSchedule(file); if (schedule == null) { return; } //2. Functional Unit Allocation and Binding: var functionalUnits = new FunctionalUnitAllocator(schedule); //3. Register Allocation and Binding var registers = new RegisterAllocator(functionalUnits); //4. Multiplexer Generation: var multiplexorGenerator = new MultiplexerGenerator(registers); //5. Datapath Generation in VHDL: var dataPathGenerator = new DataPathGenerator(multiplexorGenerator); //6. Get test cases Console.ForegroundColor = ConsoleColor.Green; foreach (var expression in file.AsExpressions) { Console.WriteLine(expression); } var testCases = GetTestCases(dataPathGenerator).ToArray(); var saveFolder = GetSaveTo(); if (saveFolder == null) { return; } //save generation dataPath = GetSaveStream(Path.Combine(saveFolder, fileName + "_dp.vhd")); if (dataPath == null) { return; } controller = GetSaveStream(Path.Combine(saveFolder, fileName + "_con.vhd")); if (controller == null) { return; } design = GetSaveStream(Path.Combine(saveFolder, fileName + "_des.vhd")); if (design == null) { return; } if (testCases.Length > 0) { testBench = GetSaveStream(Path.Combine(saveFolder, fileName + "_tb.vhd")); if (testBench == null) { return; } } using (controller) { dataPathGenerator.SaveController(controller); } foreach (var codeFile in functionalUnits.Units .Select(unit => unit.VhdlCodeFile) .Concat(new [] { "c_multiplexer", "c_register" }) .Distinct(StringComparer.OrdinalIgnoreCase)) { var savePath = Path.Combine(saveFolder, codeFile + ".vhd"); if (!File.Exists(savePath)) { using (var stream = File.CreateText(savePath)) { stream.WriteVhdlFile(codeFile); } } } using (dataPath) { dataPathGenerator.SaveDataPath(dataPath); } using (design) { dataPathGenerator.SaveDesign(design); } if (testCases.Length > 0) { using (testBench) { dataPathGenerator.SaveTestBench(testBench, testCases); } } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Press enter to exit."); Console.ReadLine(); } catch (Exception error) { Log.Error(error); dataPath?.Dispose(); design?.Dispose(); controller?.Dispose(); testBench?.Dispose(); } }