Commit d3c000ac authored by Peter's avatar Peter
Browse files

dev

parent 7173129e
Loading
Loading
Loading
Loading
Loading
+1 −1
Changes for src/main/java/hk/quantr/verilogcompiler/VerilogCompiler.java: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -171,7 +171,7 @@ public class VerilogCompiler {
			File file = new File(temp);
			String content = IOUtils.toString(new FileInputStream(file), "utf-8");
			ParseStructure ps = new ParseStructure();
			String sourceContent = VerilogHelper.getContentReplacedWithMacro(0, content, VerilogHelper.scanMacroDefinitions(file.getParentFile()), ps);
			String sourceContent = VerilogHelper.getContentReplacedWithMacro(0, content, VerilogHelper.scanMacroDefinitions(file, file.getParentFile()), ps);
			System.out.println(sourceContent);
		}
	}
+8 −6
Changes for src/main/java/hk/quantr/verilogcompiler/VerilogHelper.java: 8 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -43,14 +43,16 @@ public class VerilogHelper {

	private static final Logger logger = Logger.getLogger(VerilogHelper.class.getName());

	public static VerilogMacroDefinitionListener scanMacroDefinitions(File folder) throws FileNotFoundException, IOException {
	private static VerilogMacroDefinitionListener scanMacroDefinitions(File folder) throws FileNotFoundException, IOException {
		VerilogMacroDefinitionListener listener = scanMacroDefinitions(null, folder);
		return listener;
	}

	public static VerilogMacroDefinitionListener scanMacroDefinitions(File preferFile, File folder) throws FileNotFoundException, IOException {
		// scan all verilog for macro definitions
		ArrayList<File> files = (ArrayList<File>) FileUtils.listFiles(folder, new String[]{"v"}, true);
		Collection<File> temp = FileUtils.listFiles(folder, new String[]{"v"}, true);
		ArrayList<File> files = new ArrayList<>();
		files.addAll(temp);
		if (preferFile != null) {
			files.add(0, preferFile);
		}
@@ -114,7 +116,7 @@ public class VerilogHelper {
							MacroListing parentMacro = ps.get(lineNo, parseNo - 1);

							if (parentMacro == null) {
								System.err.println("ERROR");
								System.err.println("ERROR 1: " + macroText);
								System.exit(125);
							}
							for (String temp : macroBody.split("\r?\n")) {
@@ -129,18 +131,18 @@ public class VerilogHelper {
//								rewriter.delete(token.getTokenIndex() + 1); // remove last ';'
//							}
						} else {
							System.err.println("ERROR");
							System.err.println("ERROR 2: " + macroText);
							System.exit(124);
						}
					} else {
						System.err.println("ERROR");
						System.err.println("ERROR 3: " + macroText);
						System.exit(123);
					}
				} else {
					int lineNo = token.getLine() - 1;
					MacroListing parentMacro = ps.get(lineNo, parseNo - 1);
					if (parentMacro == null) {
						System.err.println("ERROR");
						System.err.println("ERROR 4: " + macroText);
						System.exit(129);
					}
					parentMacro.children.add(new MacroListing(parentMacro, parseNo, parentMacro.originalLineNo, token.getLine() - 1 + delta, macroBody, Type.MACRO));
+18 −2
Changes for src/test/java/TestNetbeansVerilog.java: 18 added lines, 2 removed lines.
Original line number Diff line number Diff line

import hk.quantr.verilogcompiler.VerilogHelper;
import hk.quantr.verilogcompiler.macro.ParseStructure;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.junit.Test;

/*
@@ -15,7 +17,21 @@ public class TestNetbeansVerilog {

	@Test
	public void test() throws IOException {
		String newContent = VerilogHelper.preProcess(new File("../quantr-i/src/ctrl.v"), "", null);
		System.out.println(newContent);
//		String newContent = VerilogHelper.preProcess(new File("../quantr-i/src/ctrl.v"), "", null);
//		System.out.println(newContent);

		File file = new File("../quantr-i/src/ctrl.v");
		String content = FileUtils.readFileToString(file, "utf-8");
		File folder = new File("../quantr-i/src");
		System.out.println("folder=" + folder.getAbsolutePath());
		ParseStructure ps = new ParseStructure();
//		VerilogMacroDefinitionListener listener = VerilogHelper.scanMacroDefinitions(folder);
//		for (String key : listener.macroDefinitions.keySet()) {
//			System.out.println(key + " = " + listener.macroDefinitions.get(key));
//		}
//		String sourceContent = VerilogHelper.getContentReplacedWithMacro(0, content, listener, ps);
		String sourceContent = VerilogHelper.getContentReplacedWithMacro(1, content, VerilogHelper.scanMacroDefinitions(file, file.getParentFile()), ps);

		System.out.println(sourceContent);
	}
}
+1 −3
Changes for src/test/java/TestSingleModuleParser.java: 1 added line, 3 removed lines.
Original line number Diff line number Diff line
@@ -4,11 +4,9 @@ import hk.quantr.verilogcompiler.antlr.VerilogLexer;
import hk.quantr.verilogcompiler.antlr.VerilogParser;
import hk.quantr.verilogcompiler.VerilogHelper;
import hk.quantr.verilogcompiler.listener.SingleModuleListener;
import hk.quantr.verilogcompiler.macro.MacroListing;
import hk.quantr.verilogcompiler.macro.ParseStructure;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.apache.commons.io.IOUtils;
@@ -27,7 +25,7 @@ public class TestSingleModuleParser {
		File file = new File("../quantr-i/src/ex_mem.v");
		String content = IOUtils.toString(new FileInputStream(file), "utf-8");
		ParseStructure ps = new ParseStructure();
		String sourceContent = VerilogHelper.getContentReplacedWithMacro(0, content, VerilogHelper.scanMacroDefinitions(folder), ps);
		String sourceContent = VerilogHelper.getContentReplacedWithMacro(0, content, VerilogHelper.scanMacroDefinitions(file, folder), ps);
		CommonLib.printWithLineNumber(sourceContent);

		// end replace source code with marco