Commit 598e9753 authored by Peter's avatar Peter
Browse files

done, can parse the whole quantr-i/src, verilator compile ok

parent fe2eaebf
Loading
Loading
Loading
Loading
Loading
+3 −3
Changes for nbactions.xml: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
		<properties>
			<exec.vmArgs></exec.vmArgs>
			<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
			<exec.appArgs>-t ../quantr-i/src/test1.v -o ../quantr-i/src-output</exec.appArgs>
			<exec.appArgs>-t ../quantr-i/src -o ../quantr-i/src-output</exec.appArgs>
			<exec.mainClass>hk.quantr.verilogcompiler.VerilogCompiler</exec.mainClass>
			<exec.executable>java</exec.executable>
		</properties>
@@ -29,7 +29,7 @@
		<properties>
			<exec.vmArgs>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</exec.vmArgs>
			<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
			<exec.appArgs>-t ../quantr-i/src/test1.v -o ../quantr-i/src-output</exec.appArgs>
			<exec.appArgs>-t ../quantr-i/src -o ../quantr-i/src-output</exec.appArgs>
			<exec.mainClass>hk.quantr.verilogcompiler.VerilogCompiler</exec.mainClass>
			<exec.executable>java</exec.executable>
			<jpda.listen>true</jpda.listen>
@@ -49,7 +49,7 @@
			<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
			<exec.mainClass>${packageClassName}</exec.mainClass>
			<exec.executable>java</exec.executable>
			<exec.appArgs>-t ../quantr-i/src/test1.v -o ../quantr-i/src-output</exec.appArgs>
			<exec.appArgs>-t ../quantr-i/src -o ../quantr-i/src-output</exec.appArgs>
		</properties>
	</action>
	<action>
+6 −6
Changes for src/main/java/hk/quantr/verilogcompiler/VerilogHelper.java: 6 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ public class VerilogHelper {
		TokenStreamRewriter rewriter = new TokenStreamRewriter(tokenStream);
		VerilogMacroDefinitionListener preListener = getPreListener(content);
		CommonLib.printWithLineNumber(content);
		int delta = 0;
		for (Token token : preListener.macroUsageTokens) {
			String macroText = token.getText();
			System.out.println(">> " + parseNo + " " + macroText);
@@ -112,11 +113,11 @@ public class VerilogHelper {
								System.err.println("ERROR");
								System.exit(125);
							}
							int delta = 0;
							for (String temp : macroBody.split("\r?\n")) {
								parentMacro.children.add(new MacroListing(parseNo, parentMacro.originalLineNo, token.getLine() - 1, temp, Type.MACRO));
								parentMacro.children.add(new MacroListing(parseNo, parentMacro.originalLineNo, token.getLine() - 1 + delta, temp, Type.MACRO));
								delta++;
							}
							delta--;
							// end add to macroListing

							rewriter.replace(token, macroBody);
@@ -139,7 +140,7 @@ public class VerilogHelper {
						System.err.println("ERROR");
						System.exit(129);
					}
					parentMacro.children.add(new MacroListing(parseNo, parentMacro.originalLineNo, token.getLine() - 1, macroBody, Type.MACRO));
					parentMacro.children.add(new MacroListing(parseNo, parentMacro.originalLineNo, token.getLine() - 1 + delta, macroBody, Type.MACRO));

					rewriter.replace(token, macroBody);
					rewriter.delete(token.getTokenIndex() - 1); // delete `
@@ -304,8 +305,7 @@ public class VerilogHelper {
		ParseTreeWalker walker = new ParseTreeWalker();
		walker.walk(listener, tree);

		StringBuilder sb = new StringBuilder();

//		StringBuilder sb = new StringBuilder();
//		for (MacroListing m : macroListing) {
//			System.out.println(m);
//			if (m.type == Type.ORIGINAL || m.type == Type.PROFILING) {
@@ -314,6 +314,6 @@ public class VerilogHelper {
//			}
//		}
//		return listener.rewriter.getText();
		return sb.toString();
		return sourceContent;
	}
}
+16 −26
Changes for src/main/java/hk/quantr/verilogcompiler/macro/ParseStructure.java: 16 added lines, 26 removed lines.
Original line number Diff line number Diff line
@@ -5,9 +5,7 @@ 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;

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

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

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

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

//	public MacroListing get(int lineNo, int parseNo) {
@@ -58,28 +54,22 @@ public class ParseStructure {
//		}
//		return null;
//	}
	public MacroListing get(int lineNo, int maxDeep) {
		return get(lineNo, 0, macroListing, 0, maxDeep).getLeft();
	public MacroListing get(int lineNo, int parseNo) {
		return get(lineNo, parseNo, macroListing);
	}

	public Pair<MacroListing, Integer> get(int lineNo, int current, ArrayList<MacroListing> temp, int deep, int maxDeep) {
	public MacroListing get(int lineNo, int parseNo, ArrayList<MacroListing> temp) {
		for (MacroListing m : temp) {
			if (lineNo == current) {
				return new ImmutablePair(m, current);
			if (m.lineNo == lineNo && m.parseNo == parseNo) {
				return m;
			}
			if (!m.children.isEmpty() & deep < maxDeep) {
				Pair<MacroListing, Integer> p = get(lineNo, current, m.children, deep + 1, maxDeep);
				MacroListing t = p.getLeft();
				current = p.getRight();
				if (t != null) {
					return new ImmutablePair(t, current);
				}
			} else {
				if (m.children.isEmpty()) {
					current++;
			if (!m.children.isEmpty()) {
				MacroListing p = get(lineNo, parseNo, m.children);
				if (p != null) {
					return p;
				}
			}
		}
		return new ImmutablePair(null, current);
		return null;
	}
}