Commit 3b5ea67f authored by Peter's avatar Peter
Browse files

dev

parent a8e7d1f8
Loading
Loading
Loading
Loading
Loading
+59 −1
Changes for src/main/java/hk/quantr/verilogcompiler/VerilogHelper.java: 59 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -184,6 +184,65 @@ public class VerilogHelper {
		return CommonLib.objectToJson(outputs);
	}

//	public static hk.quantr.verilogcompiler.structure.Module parseTopModule(File folder, File topModuleFile) {
////		File topModuleFile = new File(folder.getAbsolutePath() + "/" + topModuleFile.getAbsolutePath());
//
//		Collection<File> files = FileUtils.listFiles(folder, new String[]{"v"}, true);
//		HashMap<String, hk.quantr.verilogcompiler.structure.Module> modules = new HashMap<>();
//		for (File file : files) {
//			try {
//				logger.log(Level.INFO, "parseTopModule(), processing {0}", file.getAbsolutePath());
//				String content = IOUtils.toString(new FileInputStream(file), "utf-8");
//				ParseStructure ps = new ParseStructure();
//				String processedContent = VerilogHelper.preProcess(file, null, null);
//				String sourceContent = VerilogHelper.getContentReplacedWithMacro(0, file, processedContent, VerilogHelper.scanMacroDefinitions(file, folder), ps);
//				VerilogLexer lexer = new VerilogLexer(CharStreams.fromString(sourceContent));
//				CommonTokenStream tokenStream = new CommonTokenStream(lexer);
//				SingleModuleListener listener = new SingleModuleListener();
//				VerilogParser parser = new VerilogParser(tokenStream);
////				parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
//				parser.addParseListener(listener);
//				VerilogParser.Source_textContext context = parser.source_text();
//
//				if (listener.moduleName == null) {
//					continue;
//				}
//
//				modules.put(listener.moduleName, new hk.quantr.verilogcompiler.structure.Module(listener.moduleName, listener.inputs, listener.outputs));
//			} catch (IOException | RecognitionException ex) {
//				ex.printStackTrace();
//			}
//		}
//		logger.info("----");
//
//		// parse top module
//		try {
//			String content = IOUtils.toString(new FileInputStream(topModuleFile), "utf-8");
//			ParseStructure ps = new ParseStructure();
//			String processedContent = VerilogHelper.preProcess(topModuleFile, null, null);
//			String sourceContent = VerilogHelper.getContentReplacedWithMacro(0, topModuleFile, processedContent, VerilogHelper.scanMacroDefinitions(topModuleFile, folder), ps);
//			VerilogLexer lexer = new VerilogLexer(CharStreams.fromString(sourceContent));
//			CommonTokenStream tokenStream = new CommonTokenStream(lexer);
//			AllModuleListener listener = new AllModuleListener(modules);
//			VerilogParser parser = new VerilogParser(tokenStream);
//			parser.addParseListener(listener);
//			VerilogParser.Source_textContext context = parser.source_text();
//
//			hk.quantr.verilogcompiler.structure.Module topModule = new hk.quantr.verilogcompiler.structure.Module();
//			topModule.name = listener.moduleName;
//			topModule.modules = listener.modules;
//			topModule.inputs = listener.inputs;
//			topModule.outputs = listener.outputs;
//			topModule.wires = listener.wires;
//
////			logger.info(topModule);
//			return topModule;
//		} catch (IOException ex) {
//			ex.printStackTrace();
//		}
//		return null;
//	}

	public static hk.quantr.verilogcompiler.structure.Module fileToModule(File file) throws IOException {
		String content = IOUtils.toString(new FileInputStream(file), "utf-8");
		ParseStructure ps = new ParseStructure();
@@ -204,7 +263,6 @@ public class VerilogHelper {
	public static String preProcess(File file, String verilogheadingStatements, String verilogStatements) throws FileNotFoundException, FileNotFoundException, IOException {
		ParseStructure ps = new ParseStructure();
		String content = IOUtils.toString(new FileInputStream(file), "utf-8");
		System.out.println(" fuck " + file.getAbsolutePath());
		String sourceContent = VerilogHelper.getContentReplacedWithMacro(1, file, content, VerilogHelper.scanMacroDefinitions(file, file.getParentFile()), ps);
//		FileUtils.writeStringToFile(new File("aaaa.v"), sourceContent, "utf-8");
//		CommonLib.printWithLineNumber(sourceContent);