Project

General

Profile

[logo] 
 
Home
News
Activity
About/Contact
Major Tools
  Dinotrace
  Verilator
  Verilog-mode
  Verilog-Perl
Other Tools
  BugVise
  CovVise
  Force-Gate-Sim
  Gspice
  IPC::Locker
  Rsvn
  SVN::S4
  Voneline
  WFH
General Info
  Papers

0001-Fix-for-issue-1444.patch

Kanad Kanhere, 05/17/2019 06:54 PM

Download (6.78 KB)

View differences:

src/V3EmitXml.cpp
59 59
	// Don't use to quote a filename for #include - #include doesn't \ escape.
60 60
	// Duplicate in V3File - here so we can print to string
61 61
	putsNoTracking("\"");
62
	putsNoTracking(V3OutFormatter::quoteNameControls(str));
62
	putsNoTracking(V3OutFormatter::quoteNameControls(str, V3OutFormatter::LA_XML));
63 63
	putsNoTracking("\"");
64 64
    }
65 65

  
src/V3File.cpp
843 843
    putcOutput(chr);
844 844
}
845 845

  
846
string V3OutFormatter::quoteNameControls(const string& namein, V3OutFormatter::Language) {
847
    // Encode control chars into C style escapes
846
string V3OutFormatter::quoteNameControls(const string& namein, V3OutFormatter::Language lang) {
848 847
    // Reverse is V3Parse::deQuote
849 848
    string out;
850
    for (string::const_iterator pos=namein.begin(); pos!=namein.end(); ++pos) {
851
	if (pos[0]=='\\' || pos[0]=='"') {
852
	    out += string("\\")+pos[0];
853
	} else if (pos[0]=='\n') {
854
	    out += "\\n";
855
	} else if (pos[0]=='\r') {
856
	    out += "\\r";
857
	} else if (pos[0]=='\t') {
858
	    out += "\\t";
859
	} else if (isprint(pos[0])) {
860
	    out += pos[0];
861
	} else {
862
	    // This will also cover \a etc
863
	    // Can't use %03o as messes up when signed
864
	    char octal[10]; sprintf(octal,"\\%o%o%o",(pos[0]>>6)&3, (pos[0]>>3)&7, pos[0]&7);
865
	    out += octal;
866
	}
849
    if (lang==LA_XML) {
850
        // Encode chars into XML string
851
        for (string::const_iterator pos=namein.begin(); pos!=namein.end(); ++pos) {
852
        if (pos[0]=='"') {
853
            out += string(""");
854
        } else if (pos[0]=='\'') {
855
            out += string("'");
856
        } else if (pos[0]=='<') {
857
            out += string("&lt;");
858
        } else if (pos[0]=='>') {
859
            out += string("&gt;");
860
        } else if (pos[0]=='&') {
861
            out += string("&amp;");
862
        } else {
863
            out += pos[0];
864
        }
865
        }
866
    } else {
867
        // Encode control chars into C style escapes
868
        for (string::const_iterator pos=namein.begin(); pos!=namein.end(); ++pos) {
869
        if (pos[0]=='\\' || pos[0]=='"') {
870
            out += string("\\")+pos[0];
871
        } else if (pos[0]=='\n') {
872
            out += "\\n";
873
        } else if (pos[0]=='\r') {
874
            out += "\\r";
875
        } else if (pos[0]=='\t') {
876
            out += "\\t";
877
        } else if (isprint(pos[0])) {
878
            out += pos[0];
879
        } else {
880
            // This will also cover \a etc
881
            // Can't use %03o as messes up when signed
882
            char octal[10]; sprintf(octal,"\\%o%o%o",(pos[0]>>6)&3, (pos[0]>>3)&7, pos[0]&7);
883
            out += octal;
884
        }
885
        }
867 886
    }
868 887
    return out;
869 888
}
test_regress/t/t_xml_tag.out
31 31
        <varxref fl="f32" name="value" dtype_id="6" dotted="itop"/>
32 32
        <varref fl="f32" name="dotted" dtype_id="5"/>
33 33
      </contassign>
34
      <func fl="f34" name="f" dtype_id="1">
35
        <var fl="f34" name="f" dtype_id="1" dir="output" vartype="logic" origName="f"/>
36
        <var fl="f34" name="m" dtype_id="7" dir="input" vartype="string" origName="m"/>
37
        <display fl="f35" displaytype="$display">
38
          <sformatf fl="f35" name="%@" dtype_id="7">
39
            <varref fl="f35" name="m" dtype_id="7"/>
40
          </sformatf>
41
        </display>
42
      </func>
43
      <initial fl="f38">
44
        <taskref fl="f39" name="f">
45
          <arg fl="f39">
46
            <const fl="f39" name="&quot;&apos;a &amp; b&apos; = &lt;c | d&gt;&quot;" dtype_id="7"/>
47
          </arg>
48
        </taskref>
49
      </initial>
34 50
    </module>
35 51
    <iface fl="f6" name="ifc" origName="ifc">
36 52
      <var fl="f7" name="value" dtype_id="6" vartype="integer" origName="value"/>
......
43 59
      <basicdtype  fl="f7" id="6" name="integer" left="31" right="0"/>
44 60
      <basicdtype  fl="f13" id="1" name="logic"/>
45 61
      <structdtype fl="f19" id="2" name="m.my_struct">
46
        <memberdtype fl="f20" id="7" name="clk" tag="this is clk" sub_dtype_id="8"/>
47
        <memberdtype fl="f21" id="9" name="k" sub_dtype_id="10"/>
48
        <memberdtype fl="f22" id="11" name="enable" tag="enable" sub_dtype_id="12"/>
49
        <memberdtype fl="f23" id="13" name="data" tag="data" sub_dtype_id="14"/>
62
        <memberdtype fl="f20" id="8" name="clk" tag="this is clk" sub_dtype_id="9"/>
63
        <memberdtype fl="f21" id="10" name="k" sub_dtype_id="11"/>
64
        <memberdtype fl="f22" id="12" name="enable" tag="enable" sub_dtype_id="13"/>
65
        <memberdtype fl="f23" id="14" name="data" tag="data" sub_dtype_id="15"/>
50 66
      </structdtype>
51
      <basicdtype  fl="f20" id="8" name="logic"/>
52
      <basicdtype  fl="f21" id="10" name="logic"/>
53
      <basicdtype  fl="f22" id="12" name="logic"/>
54
      <basicdtype  fl="f23" id="14" name="logic"/>
67
      <basicdtype  fl="f20" id="9" name="logic"/>
68
      <basicdtype  fl="f21" id="11" name="logic"/>
69
      <basicdtype  fl="f22" id="13" name="logic"/>
70
      <basicdtype  fl="f23" id="15" name="logic"/>
55 71
      <ifacerefdtype fl="f28" id="3" modportname=""/>
56 72
      <unpackarraydtype fl="f30" id="4" sub_dtype_id="2">
57 73
        <range fl="f30">
58
          <const fl="f30" name="32'h1" dtype_id="5"/>
59
          <const fl="f30" name="32'h0" dtype_id="5"/>
74
          <const fl="f30" name="32&apos;h1" dtype_id="5"/>
75
          <const fl="f30" name="32&apos;h0" dtype_id="5"/>
60 76
        </range>
61 77
      </unpackarraydtype>
62
      <refdtype fl="f30" id="15" name="my_struct" sub_dtype_id="2"/>
78
      <refdtype fl="f30" id="16" name="my_struct" sub_dtype_id="2"/>
79
      <basicdtype  fl="f34" id="7" name="string"/>
63 80
    </typetable>
64 81
  </netlist>
65 82
</verilator_xml>
test_regress/t/t_xml_tag.v
31 31

  
32 32
   wire [31:0] dotted = itop.value;
33 33

  
34
   function f(input string m);
35
       $display("%s", m);
36
   endfunction
37

  
38
   initial
39
       f("'a & b' = <c | d>"); // contains all xml special characters
40

  
34 41
endmodule
35
-