X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=tests%2Fnet.mograsim.logic.model.verilog.tests%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fverilog%2Fexamples%2FExportAm2900.java;h=3e0f33d9cab40f930b75a3721a8fe7701ae5c6b8;hb=2e8be4681cb856e99697df230fa453b30794e201;hp=6e9decdb07f477cfb0baa5690da630f78e7cc764;hpb=7908fec28b61e5911bf6523a3c10cd3a31dc95e6;p=Mograsim.git diff --git a/tests/net.mograsim.logic.model.verilog.tests/src/net/mograsim/logic/model/verilog/examples/ExportAm2900.java b/tests/net.mograsim.logic.model.verilog.tests/src/net/mograsim/logic/model/verilog/examples/ExportAm2900.java index 6e9decdb..3e0f33d9 100644 --- a/tests/net.mograsim.logic.model.verilog.tests/src/net/mograsim/logic/model/verilog/examples/ExportAm2900.java +++ b/tests/net.mograsim.logic.model.verilog.tests/src/net/mograsim/logic/model/verilog/examples/ExportAm2900.java @@ -24,8 +24,6 @@ import net.mograsim.logic.model.model.components.atomic.ModelClock; import net.mograsim.logic.model.model.components.atomic.ModelClock.ModelClockParams; import net.mograsim.logic.model.model.components.atomic.ModelFixedOutput; import net.mograsim.logic.model.model.components.atomic.ModelNandGate; -import net.mograsim.logic.model.model.components.atomic.ModelSplitter; -import net.mograsim.logic.model.model.components.atomic.ModelSplitter.SplitterParams; import net.mograsim.logic.model.model.components.atomic.ModelTextComponent; import net.mograsim.logic.model.model.components.atomic.ModelTriStateBuffer; import net.mograsim.logic.model.model.components.atomic.ModelTriStateBuffer.ModelTriStateBufferParams; @@ -34,6 +32,7 @@ import net.mograsim.logic.model.serializing.IdentifyParams; import net.mograsim.logic.model.serializing.IndirectModelComponentCreator; import net.mograsim.logic.model.verilog.converter.ModelComponentToVerilogComponentDeclarationMapping; import net.mograsim.logic.model.verilog.converter.ModelComponentToVerilogConverter; +import net.mograsim.logic.model.verilog.helper.UnionFind; import net.mograsim.logic.model.verilog.model.VerilogComponentImplementation; public class ExportAm2900 @@ -41,108 +40,69 @@ public class ExportAm2900 public static void main(String[] args) throws IOException { Am2900Loader.setup(); + Path target; + String rootComponentID; try (Scanner sysin = new Scanner(System.in)) { System.out.print("Directory to export Verilog into >"); - Path target = Paths.get(sysin.nextLine()); + target = Paths.get(sysin.nextLine()); if (!Files.exists(target)) Files.createDirectories(target); else if (!Files.isDirectory(target)) throw new IllegalArgumentException("Target exists and is not a directory"); System.out.print("Component ID to serialize recursively >"); - String rootComponentID = sysin.nextLine(); - { - if (!Files.exists(target)) - Files.createDirectories(target); - else if (!Files.isDirectory(target)) - throw new IllegalArgumentException("Target exists and is not a directory"); + rootComponentID = sysin.nextLine(); + } - LogicModelModifiable model = new LogicModelModifiable(); + if (!Files.exists(target)) + Files.createDirectories(target); + else if (!Files.isDirectory(target)) + throw new IllegalArgumentException("Target exists and is not a directory"); - Set atomicComponentMappings = Stream.of(// - new ModelNandGate(model, 1), // - new ModelFixedOutput(model, BitVector.SINGLE_0, null), // - new ModelFixedOutput(model, BitVector.SINGLE_1, null), // - new ModelTriStateBuffer(model, new ModelTriStateBufferParams(1, Orientation.RIGHT)), // - new ModelTriStateBuffer(model, new ModelTriStateBufferParams(1, Orientation.RIGHT_ALT)), // - new ModelTriStateBuffer(model, new ModelTriStateBufferParams(1, Orientation.DOWN)), // - new ModelTriStateBuffer(model, new ModelTriStateBufferParams(4, Orientation.RIGHT)), // - new ModelTriStateBuffer(model, new ModelTriStateBufferParams(12, Orientation.RIGHT_ALT)), // - new ModelTriStateBuffer(model, new ModelTriStateBufferParams(12, Orientation.DOWN)), // - new ModelTriStateBuffer(model, new ModelTriStateBufferParams(16, Orientation.LEFT)), // - new ModelTriStateBuffer(model, new ModelTriStateBufferParams(16, Orientation.RIGHT_ALT)), // - new ModelWireCrossPoint(model, 1), // - new ModelWireCrossPoint(model, 2), // - new ModelWireCrossPoint(model, 4), // - new ModelWireCrossPoint(model, 9), // - new ModelWireCrossPoint(model, 12), // - new ModelWireCrossPoint(model, 16), // - new ModelSplitter(model, new SplitterParams(2, Orientation.LEFT)), // - new ModelSplitter(model, new SplitterParams(2, Orientation.RIGHT)), // - new ModelSplitter(model, new SplitterParams(2, Orientation.UP)), // - new ModelSplitter(model, new SplitterParams(2, Orientation.DOWN_ALT)), // - new ModelSplitter(model, new SplitterParams(3, Orientation.LEFT)), // - new ModelSplitter(model, new SplitterParams(3, Orientation.RIGHT)), // - new ModelSplitter(model, new SplitterParams(3, Orientation.UP)), // - new ModelSplitter(model, new SplitterParams(3, Orientation.DOWN)), // - new ModelSplitter(model, new SplitterParams(3, Orientation.DOWN_ALT)), // - new ModelSplitter(model, new SplitterParams(4, Orientation.LEFT)), // - new ModelSplitter(model, new SplitterParams(4, Orientation.RIGHT)), // - new ModelSplitter(model, new SplitterParams(4, Orientation.UP)), // - new ModelSplitter(model, new SplitterParams(4, Orientation.DOWN)), // - new ModelSplitter(model, new SplitterParams(4, Orientation.DOWN_ALT)), // - new ModelSplitter(model, new SplitterParams(5, Orientation.LEFT)), // - new ModelSplitter(model, new SplitterParams(5, Orientation.RIGHT)), // - new ModelSplitter(model, new SplitterParams(6, Orientation.LEFT)), // - new ModelSplitter(model, new SplitterParams(6, Orientation.RIGHT)), // - new ModelSplitter(model, new SplitterParams(6, Orientation.DOWN)), // - new ModelSplitter(model, new SplitterParams(6, Orientation.UP)), // - new ModelSplitter(model, new SplitterParams(6, Orientation.DOWN_ALT)), // - new ModelSplitter(model, new SplitterParams(8, Orientation.LEFT)), // - new ModelSplitter(model, new SplitterParams(8, Orientation.RIGHT)), // - new ModelSplitter(model, new SplitterParams(9, Orientation.LEFT)), // - new ModelSplitter(model, new SplitterParams(9, Orientation.DOWN)), // - new ModelSplitter(model, new SplitterParams(12, Orientation.LEFT)), // - new ModelSplitter(model, new SplitterParams(12, Orientation.RIGHT)), // - new ModelSplitter(model, new SplitterParams(12, Orientation.DOWN)), // - new ModelSplitter(model, new SplitterParams(12, Orientation.DOWN_ALT)), // - new ModelSplitter(model, new SplitterParams(13, Orientation.RIGHT)), // - new ModelSplitter(model, new SplitterParams(13, Orientation.DOWN)), // - new ModelSplitter(model, new SplitterParams(16, Orientation.LEFT)), // - new ModelSplitter(model, new SplitterParams(16, Orientation.RIGHT)), // - new ModelSplitter(model, new SplitterParams(16, Orientation.UP)), // - new ModelSplitter(model, new SplitterParams(16, Orientation.DOWN)), // - new ModelSplitter(model, new SplitterParams(16, Orientation.DOWN_ALT)), // - new ModelSplitter(model, new SplitterParams(80, Orientation.LEFT)), // - new ModelSplitter(model, new SplitterParams(80, Orientation.RIGHT)), // - new ModelSplitter(model, new SplitterParams(80, Orientation.UP_ALT)), // - new ModelClock(model, new ModelClockParams(7000, Orientation.RIGHT)), // - new ModelTextComponent(model, "A bus"), // - new ModelTextComponent(model, "MPM addr"), // - new ModelTextComponent(model, "D bus"), // - new ModelAm2900MainMemory(model, null), // - new ModelAm2900MPROM(model, null), // - new ModelAm2900MicroInstructionMemory(model, null), // - new ModelBitDisplay(model, 12), // - new ModelBitDisplay(model, 16)// - ).map(c -> - { - String id = c.getIDForSerializing(new IdentifyParams()); - JsonElement params = c.getParamsForSerializingJSON(new IdentifyParams()); - ModelComponentToVerilogComponentDeclarationMapping generateCanonicalDeclarationMapping = ModelComponentToVerilogConverter - .generateCanonicalDeclarationMapping(c, id, params, ModelComponentToVerilogConverter - .sanitizeVerilogID("mgs_" + id + (params.isJsonNull() ? "" : "_" + params))); - return generateCanonicalDeclarationMapping; - }).collect(Collectors.toSet()); + LogicModelModifiable model = new LogicModelModifiable(); - ModelComponent root = IndirectModelComponentCreator.createComponent(model, rootComponentID); - Set convertResult = ModelComponentToVerilogConverter.convert(atomicComponentMappings, - Set.of(root), "mgs_conv_"); - for (VerilogComponentImplementation convertedComponent : convertResult) - Files.writeString(target.resolve(convertedComponent.getDeclaration().getID() + ".v"), - convertedComponent.toVerilogCode()); - } - } + Set atomicComponentMappings = Stream.of(// + new ModelNandGate(model, 1), // + new ModelFixedOutput(model, BitVector.SINGLE_0, null), // + new ModelFixedOutput(model, BitVector.SINGLE_1, null), // + new ModelTriStateBuffer(model, new ModelTriStateBufferParams(1, Orientation.RIGHT)), // + new ModelTriStateBuffer(model, new ModelTriStateBufferParams(1, Orientation.RIGHT_ALT)), // + new ModelTriStateBuffer(model, new ModelTriStateBufferParams(1, Orientation.DOWN)), // + new ModelTriStateBuffer(model, new ModelTriStateBufferParams(4, Orientation.RIGHT)), // + new ModelTriStateBuffer(model, new ModelTriStateBufferParams(12, Orientation.RIGHT_ALT)), // + new ModelTriStateBuffer(model, new ModelTriStateBufferParams(12, Orientation.DOWN)), // + new ModelTriStateBuffer(model, new ModelTriStateBufferParams(16, Orientation.LEFT)), // + new ModelTriStateBuffer(model, new ModelTriStateBufferParams(16, Orientation.RIGHT_ALT)), // + new ModelWireCrossPoint(model, 1), // + new ModelWireCrossPoint(model, 2), // + new ModelWireCrossPoint(model, 4), // + new ModelWireCrossPoint(model, 9), // + new ModelWireCrossPoint(model, 12), // + new ModelWireCrossPoint(model, 16), // + new ModelClock(model, new ModelClockParams(7000, Orientation.RIGHT)), // + new ModelTextComponent(model, "A bus"), // + new ModelTextComponent(model, "MPM addr"), // + new ModelTextComponent(model, "D bus"), // + new ModelAm2900MainMemory(model, null), // + new ModelAm2900MPROM(model, null), // + new ModelAm2900MicroInstructionMemory(model, null), // + new ModelBitDisplay(model, 12), // + new ModelBitDisplay(model, 16)// + ).map(c -> + { + String id = c.getIDForSerializing(new IdentifyParams()); + JsonElement params = c.getParamsForSerializingJSON(new IdentifyParams()); + ModelComponentToVerilogComponentDeclarationMapping generateCanonicalDeclarationMapping = ModelComponentToVerilogConverter + .generateCanonicalDeclarationMapping(c, new UnionFind<>(), id, params, + ModelComponentToVerilogConverter.sanitizeVerilogID("mgs_" + id + (params.isJsonNull() ? "" : "_" + params))); + return generateCanonicalDeclarationMapping; + }).collect(Collectors.toSet()); + + ModelComponent root = IndirectModelComponentCreator.createComponent(model, rootComponentID); + Set convertResult = ModelComponentToVerilogConverter.convert(atomicComponentMappings, Set.of(root), + "mgs_conv_"); + for (VerilogComponentImplementation convertedComponent : convertResult) + Files.writeString(target.resolve(convertedComponent.getDeclaration().getID() + ".v"), convertedComponent.toVerilogCode()); } }