From 5ecce280b86061c5b3a6c1f547d3ec270c5483cd Mon Sep 17 00:00:00 2001 From: emteere <47253321+emteere@users.noreply.github.com> Date: Mon, 10 Jun 2019 18:38:20 -0400 Subject: [PATCH] GT-2905_emteere Putting out correct constructor line-number for nop sleigh compiler argument '-n' --- .../antlr/ghidra/sleigh/grammar/SleighCompiler.g | 16 ++++++++++------ .../pcodeCPort/slgh_compile/PcodeParser.java | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Ghidra/Framework/SoftwareModeling/src/main/antlr/ghidra/sleigh/grammar/SleighCompiler.g b/Ghidra/Framework/SoftwareModeling/src/main/antlr/ghidra/sleigh/grammar/SleighCompiler.g index 7170783b57..c0f328249e 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/antlr/ghidra/sleigh/grammar/SleighCompiler.g +++ b/Ghidra/Framework/SoftwareModeling/src/main/antlr/ghidra/sleigh/grammar/SleighCompiler.g @@ -563,7 +563,7 @@ macrodef } : ^(t=OP_MACRO n=unbound_identifier["macro"] a=arguments { symbol = sc.createMacro(find(n), n.getText(), a.first, a.second); - } s=semantic[env, sc.pcode, $t, false, true]) { + } s=semantic[env, null, sc.pcode, $t, false, true]) { if (symbol != null) { sc.buildMacro(symbol, $macrodef::macrobody); } @@ -612,13 +612,13 @@ constructorlikelist ; constructor - : ^(OP_CONSTRUCTOR c=ctorstart e=bitpattern b=contextblock r=ctorsemantic) { + : ^(OP_CONSTRUCTOR c=ctorstart e=bitpattern b=contextblock r=ctorsemantic[c]) { sc.buildConstructor(c, e, b, r); } ; -ctorsemantic returns [SectionVector value] - : ^(t=OP_PCODE p=semantic[env, sc.pcode, $t, true, false]) { $value = p; } +ctorsemantic[Constructor ctor] returns [SectionVector value] + : ^(t=OP_PCODE p=semantic[env, ctor.location, sc.pcode, $t, true, false]) { $value = p; } | ^(OP_PCODE OP_UNIMPL) { /*unimpl unimplemented ; */ $value = null; } ; @@ -941,7 +941,7 @@ cstatement[VectorSTL r] } ; -semantic[ParsingEnvironment pe, PcodeCompile pcode, Tree where, boolean sectionsAllowed, boolean isMacroParse] returns [SectionVector rtl] +semantic[ParsingEnvironment pe, Location containerLoc, PcodeCompile pcode, Tree where, boolean sectionsAllowed, boolean isMacroParse] returns [SectionVector rtl] scope { SectionVector sections; boolean containsMultipleSections; @@ -966,7 +966,11 @@ semantic[ParsingEnvironment pe, PcodeCompile pcode, Tree where, boolean sections : ^(x=OP_SEMANTIC c=code_block[find($x)] { if (c != null) { if (c.getOpvec().empty() && c.getResult() == null) { - pcode.recordNop(find(where)); + Location loc = find(where); + if (loc == null) { + loc = containerLoc; + } + pcode.recordNop(loc); } if ($semantic::containsMultipleSections) { $semantic::sections = pcode.finalNamedSection($semantic::sections, c); diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/PcodeParser.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/PcodeParser.java index 3ee936ae3d..647d858467 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/PcodeParser.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/PcodeParser.java @@ -312,7 +312,7 @@ public class PcodeParser extends PcodeCompile { // ANTLRUtil.debugNodeStream(nodes, System.out); SleighCompiler walker = new SleighCompiler(nodes); - SectionVector rtl = walker.semantic(env, this, semantic.getTree(), false, false); + SectionVector rtl = walker.semantic(env, null, this, semantic.getTree(), false, false); if (getErrors() != 0) { return null;