Commit a8e7d1f8 authored by Peter's avatar Peter
Browse files

making the debugger hook to file quantr.profiling

parent 1eed9ce5
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, file.getParentFile()), ps);
			String sourceContent = VerilogHelper.getContentReplacedWithMacro(0, file, content, VerilogHelper.scanMacroDefinitions(file, file.getParentFile()), ps);
			System.out.println(sourceContent);
		}
	}
+8 −8
Changes for src/main/java/hk/quantr/verilogcompiler/VerilogHelper.java: 8 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -80,11 +80,11 @@ public class VerilogHelper {
		return verilogPreListener;
	}

	public static String getContentReplacedWithMacro(int parseNo, String content, VerilogMacroDefinitionListener verilogPreListener, ParseStructure ps) throws FileNotFoundException, IOException {
	public static String getContentReplacedWithMacro(int parseNo, File file, String content, VerilogMacroDefinitionListener verilogPreListener, ParseStructure ps) throws FileNotFoundException, IOException {
		String lines[] = content.split("\r?\n");
		if (ps.macroListing.isEmpty()) {
			for (int x = 0; x < lines.length; x++) {
				ps.macroListing.add(new MacroListing(null, 0, x, x, lines[x], Type.ORIGINAL));
				ps.macroListing.add(new MacroListing(null, file, 0, x, x, lines[x], Type.ORIGINAL));
			}
		}

@@ -122,7 +122,7 @@ public class VerilogHelper {
								System.exit(125);
							}
							for (String temp : macroBody.split("\r?\n")) {
								parentMacro.children.add(new MacroListing(parentMacro, parseNo, parentMacro.originalLineNo, token.getLine() - 1 + delta, temp, Type.MACRO));
								parentMacro.children.add(new MacroListing(parentMacro, file, parseNo, parentMacro.originalLineNo, token.getLine() - 1 + delta, temp, Type.MACRO));
								delta++;
							}
							delta--;
@@ -147,7 +147,7 @@ public class VerilogHelper {
						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));
					parentMacro.children.add(new MacroListing(parentMacro, file, parseNo, parentMacro.originalLineNo, token.getLine() - 1 + delta, macroBody, Type.MACRO));

					rewriter.replace(token, macroBody);
					rewriter.delete(token.getTokenIndex() - 1); // delete `
@@ -161,7 +161,7 @@ public class VerilogHelper {
//			System.out.println("+".repeat(100));
//			CommonLib.printWithLineNumber(result);
//			System.out.println("+".repeat(100));
			result = getContentReplacedWithMacro(parseNo + 1, result, verilogPreListener, ps);
			result = getContentReplacedWithMacro(parseNo + 1, file, result, verilogPreListener, ps);
		}
		return result;
	}
@@ -187,7 +187,7 @@ public class VerilogHelper {
	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();
		String sourceContent = VerilogHelper.getContentReplacedWithMacro(1, content, VerilogHelper.scanMacroDefinitions(file, file.getParentFile()), ps);
		String sourceContent = VerilogHelper.getContentReplacedWithMacro(1, file, content, VerilogHelper.scanMacroDefinitions(file, file.getParentFile()), ps);
		VerilogLexer lexer = new VerilogLexer(CharStreams.fromString(sourceContent));
		CommonTokenStream tokenStream = new CommonTokenStream(lexer);
		SingleModuleListener listener = new SingleModuleListener();
@@ -205,7 +205,7 @@ public class VerilogHelper {
		ParseStructure ps = new ParseStructure();
		String content = IOUtils.toString(new FileInputStream(file), "utf-8");
		System.out.println(" fuck " + file.getAbsolutePath());
		String sourceContent = VerilogHelper.getContentReplacedWithMacro(1, content, VerilogHelper.scanMacroDefinitions(file, file.getParentFile()), ps);
		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);
		System.out.println(ps);
@@ -217,7 +217,7 @@ public class VerilogHelper {
//		System.out.println("-".repeat(100));

		// add our own macro
		VerilogPreProcessorListener listener = new VerilogPreProcessorListener(tokenStream, sourceContent, ps);
		VerilogPreProcessorListener listener = new VerilogPreProcessorListener(tokenStream, file, sourceContent, ps);
		ParseTreeWalker walker = new ParseTreeWalker();
		walker.walk(listener, tree);
//		System.out.println(ps);
+6 −3
Changes for src/main/java/hk/quantr/verilogcompiler/listener/preprocess/VerilogPreProcessorListener.java: 6 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import hk.quantr.verilogcompiler.antlr.VerilogParser;
import hk.quantr.verilogcompiler.antlr.VerilogParserBaseListener;
import hk.quantr.verilogcompiler.macro.MacroListing;
import hk.quantr.verilogcompiler.macro.ParseStructure;
import java.io.File;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.TokenStreamRewriter;

@@ -17,11 +18,13 @@ import org.antlr.v4.runtime.TokenStreamRewriter;
public class VerilogPreProcessorListener extends VerilogParserBaseListener {

	public TokenStreamRewriter rewriter;
	File file;
	String sourceContent;
	ParseStructure ps;

	public VerilogPreProcessorListener(TokenStream tokens, String sourceContent, ParseStructure ps) {
	public VerilogPreProcessorListener(TokenStream tokens, File file, String sourceContent, ParseStructure ps) {
		rewriter = new TokenStreamRewriter(tokens);
		this.file = file;
		this.sourceContent = sourceContent;
		this.ps = ps;
	}
@@ -46,9 +49,9 @@ public class VerilogPreProcessorListener extends VerilogParserBaseListener {
//		verilogStatements += "$display(\"%x\", add(1,2));\n";
//		verilogStatements += "profile(\"" + ctx.variable_lvalue().getText() + "\");\n";
		verilogStatements += "/* verilator lint_off WIDTH */\n";
		verilogStatements += "profile(" + (parentMacro.originalLineNo + 1) + ", \"" + ctx.variable_lvalue().getText() + "\", " + ctx.variable_lvalue().getText() + ");\n";
		verilogStatements += "profile(\"" + parentMacro.file.getAbsolutePath() + "\", " + (parentMacro.originalLineNo + 1) + ", \"" + ctx.variable_lvalue().getText() + "\", " + ctx.variable_lvalue().getText() + ");\n";
		verilogStatements += "/* verilator lint_on WIDTH */\n";
		parentMacro.children.add(new MacroListing(parentMacro, parentMacro.parseNo + 1, lineNo, parentMacro.originalLineNo, verilogStatements, MacroListing.Type.PROFILING));
		parentMacro.children.add(new MacroListing(parentMacro, file, parentMacro.parseNo + 1, lineNo, parentMacro.originalLineNo, verilogStatements, MacroListing.Type.PROFILING));
	}

	@Override
+4 −1
Changes for src/main/java/hk/quantr/verilogcompiler/macro/MacroListing.java: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
 */
package hk.quantr.verilogcompiler.macro;

import java.io.File;
import java.util.ArrayList;

/**
@@ -15,6 +16,7 @@ public class MacroListing {
		ORIGINAL, MACRO, PROFILING
	};

	public File file;
	public int parseNo;
	public Type type;
	public int originalLineNo;
@@ -23,8 +25,9 @@ public class MacroListing {
	public ArrayList<MacroListing> children = new ArrayList<>();
	public MacroListing parent;

	public MacroListing(MacroListing parent, int parseNo, int originalLineNo, int lineNo, String line, Type type) {
	public MacroListing(MacroListing parent, File file, int parseNo, int originalLineNo, int lineNo, String line, Type type) {
		this.parent = parent;
		this.file = file;
		this.parseNo = parseNo;
		this.originalLineNo = originalLineNo;
		this.lineNo = lineNo;
+1 −1
Changes for src/test/java/TestNetbeansVerilog.java: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ public class TestNetbeansVerilog {
//			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);
		String sourceContent = VerilogHelper.getContentReplacedWithMacro(1, file, content, VerilogHelper.scanMacroDefinitions(file, file.getParentFile()), ps);

		System.out.println(sourceContent);
	}
Loading