Commit fe2eaebf authored by Peter's avatar Peter
Browse files

dev

parent a0c5a3a2
Loading
Loading
Loading
Loading
Loading
+1 −1
Changes for aaaa.v: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ alusel_o = 0;

branch_flag = 11; 
        branch_target_address = 777; 
        link_address = 777;
        link_address = 0;

end

+5
Changes for pom.xml: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -144,5 +144,10 @@
			<artifactId>quantr-java-library</artifactId>
			<version>1.0</version>
		</dependency>
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
			<version>3.12.0</version>
		</dependency>
	</dependencies>
</project>
 No newline at end of file
+12 −19
Changes for src/main/java/hk/quantr/verilogcompiler/VerilogHelper.java: 12 added lines, 19 removed lines.
Original line number Diff line number Diff line
@@ -40,8 +40,13 @@ public class VerilogHelper {
	private static final Logger logger = Logger.getLogger(VerilogHelper.class.getName());

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

	public static VerilogMacroDefinitionListener scanMacroDefinitions(File preferFile, File folder) throws FileNotFoundException, IOException {
		// scan all verilog for macro definitions
		Collection<File> files = FileUtils.listFiles(folder, new String[]{"v"}, true);
		ArrayList<File> files = (ArrayList<File>) FileUtils.listFiles(folder, new String[]{"v"}, true);
		files.add(0, preferFile);
		VerilogMacroDefinitionListener listener = new VerilogMacroDefinitionListener();
		for (File file : files) {
			VerilogLexer lexer = new VerilogLexer(CharStreams.fromString(IOUtils.toString(new FileInputStream(file), "utf-8")));
@@ -97,14 +102,8 @@ public class VerilogHelper {
								String callingParamter = callingParameters[x];
								macroBody = macroBody.replaceAll("\\b" + parameter + "\\b", callingParamter);
							}
//							int macroLineNo = macroListing.get(currentLineNo).secondLineNo;
//							for (String temp : macroBody.split("\r?\n")) {
//								macroListing.add(new MacroListing(token.getLine() - 1, macroLineNo + r, temp, Type.MACRO, uuid));
//								r++;
//							}

							int lineNo = token.getLine() - 1;
							MacroListing parentMacro = ps.get(lineNo, parseNo);
							MacroListing parentMacro = ps.get(lineNo, parseNo - 1);

							if (parentMacro.lineNo == 194) {
								System.out.println("");
@@ -115,7 +114,7 @@ public class VerilogHelper {
							}
							int delta = 0;
							for (String temp : macroBody.split("\r?\n")) {
								parentMacro.children.add(new MacroListing(parseNo, parentMacro.lineNo, token.getLine() - 1 + delta, temp, Type.MACRO));
								parentMacro.children.add(new MacroListing(parseNo, parentMacro.originalLineNo, token.getLine() - 1, temp, Type.MACRO));
								delta++;
							}
							// end add to macroListing
@@ -134,22 +133,16 @@ public class VerilogHelper {
						System.exit(123);
					}
				} else {
//				logger.info("\treplacing " + macroName);
					int lineNo = token.getLine() - 1;
					MacroListing parentMacro = ps.get(lineNo, parseNo);
					MacroListing parentMacro = ps.get(lineNo, parseNo - 1);
					if (parentMacro == null) {
						System.err.println("ERROR");
						System.exit(129);
					}
					parentMacro.children.add(new MacroListing(parseNo, parentMacro.lineNo, token.getLine() - 1, macroBody, Type.MACRO));
					parentMacro.children.add(new MacroListing(parseNo, parentMacro.originalLineNo, token.getLine() - 1, macroBody, Type.MACRO));

					rewriter.replace(token, macroBody);
//					rewriter.delete(token.getTokenIndex() - 1);
//					if (verilogPreListener.macroUsageTypes.get(macroName)) {
//						rewriter.delete(token.getTokenIndex() + 1); // remove last ';'
//					}

//						logger.info(token + " \t = \t" + verilogPreListener.macroDefinitions.get(macroName));
					rewriter.delete(token.getTokenIndex() - 1); // delete `
				}
			}
		}
@@ -295,7 +288,7 @@ public class VerilogHelper {
	public static String preProcess(File file) throws FileNotFoundException, FileNotFoundException, IOException {
		ParseStructure ps = new ParseStructure();
		String content = IOUtils.toString(new FileInputStream(file), "utf-8");
		String sourceContent = VerilogHelper.getContentReplacedWithMacro(0, content, VerilogHelper.scanMacroDefinitions(file.getParentFile()), ps);
		String sourceContent = VerilogHelper.getContentReplacedWithMacro(1, content, VerilogHelper.scanMacroDefinitions(file, file.getParentFile()), ps);
		FileUtils.writeStringToFile(new File("aaaa.v"), sourceContent, "utf-8");
//		CommonLib.printWithLineNumber(sourceContent);
		System.out.println(ps);
+15 −8
Changes for src/main/java/hk/quantr/verilogcompiler/macro/ParseStructure.java: 15 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -5,7 +5,9 @@ package hk.quantr.verilogcompiler.macro;

import java.util.ArrayList;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;

/**
 *
@@ -15,23 +17,26 @@ public class ParseStructure {

	public ArrayList<MacroListing> macroListing = new ArrayList<>();

	public Pair<String, Integer> macroListingToString(ArrayList<MacroListing> temp, int index) {
	public Triple<String, Integer, Integer> macroListingToString(ArrayList<MacroListing> temp, int index, int lastContentLineNo) {
		String s = "";
		for (MacroListing macroListing : temp) {
			s += index + "\t(" + macroListing.parseNo + ")" + "    ".repeat(macroListing.parseNo + 1) + macroListing + "\n";
			s += index + "\t[" + lastContentLineNo + "]\t(" + macroListing.parseNo + ")" + "    ".repeat(macroListing.parseNo + 1) + macroListing + "\n";
			index++;
			if (!macroListing.children.isEmpty()) {
				Pair<String, Integer> temp2 = macroListingToString(macroListing.children, index);
			if (macroListing.children.isEmpty()) {
				lastContentLineNo++;
			} else {
				Triple<String, Integer, Integer> temp2 = macroListingToString(macroListing.children, index, lastContentLineNo);
				s += temp2.getLeft();
				index = temp2.getRight();
				index = temp2.getMiddle();
				lastContentLineNo = temp2.getRight();
			}
		}
		return new ImmutablePair(s, index);
		return new ImmutableTriple(s, index, lastContentLineNo);
	}

	@Override
	public String toString() {
		return macroListingToString(macroListing, 0).getLeft();
		return macroListingToString(macroListing, 0, 0).getLeft();
	}

//	public MacroListing get(int lineNo, int parseNo) {
@@ -40,7 +45,7 @@ public class ParseStructure {
//
//	public MacroListing get(ArrayList<MacroListing> temp, int lineNo, int parseNo) {
//		for (int x = temp.size() - 1; x >= 0; x--) {
//			System.out.println(">>>>>>> " + temp.get(x).lineNo + " = " + temp.get(x).parseNo + " : " + temp.get(x).line);
////			System.out.println(">>>>>>> " + temp.get(x).lineNo + " = " + temp.get(x).parseNo + " : " + temp.get(x).line);
//			if (temp.get(x).lineNo == lineNo && temp.get(x).parseNo == parseNo) {
//				return temp.get(x);
//			}
@@ -70,9 +75,11 @@ public class ParseStructure {
					return new ImmutablePair(t, current);
				}
			} else {
				if (m.children.isEmpty()) {
					current++;
				}
			}
		}
		return new ImmutablePair(null, current);
	}
}