cgen_doc_texinfo.lua 4.53 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#!/usr/bin/lua

-- wbgen2, (c) 2010 Tomasz Wlostowski/CERN BE-Co-HT
-- LICENSED UNDER GPL v2

-- File: cgen_c_headers.lua
--
-- Texinfo documentation generator.
--

--function has_any_ports(reg)
--   local has = false;
--   if(reg.ports ~= nil) then return true; end
--   foreach_subfield(reg, function(field) if (field.ports ~= nil) then has = true; end end);
--   return has;
--end

function format_tex_string(s)
   s=string.gsub(s, " +", " ");
   s=string.gsub(s, "^%-", "@bullet{} ");
   s=string.gsub(s, "\n%-", "@*@bullet{} ");
   s=string.gsub(s, "\n", "@*");
   s=string.gsub(s, "<b>", "@b{");
   s=string.gsub(s, "</b>", "}");
   s=string.gsub(s, "<i>", "@b{");
   s=string.gsub(s, "</i>", "}");
   s=string.gsub(s, "<code>", "@code{");
   s=string.gsub(s, "</code>", "}");
   return s
end

function cgen_tex_memmap()
	local evenodd=0;
	local n = 2;
35
	emit("@regsection Memory map summary");
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

	emit("@multitable  @columnfractions .10 .15 .15 .55")
	emit("@headitem Address @tab Type @tab Prefix @tab Name")

	foreach_reg({TYPE_REG}, function(reg)
		if(reg.full_hdl_prefix ~= nil) then
			
			emit(string.format("@item @code{0x%x} @tab", reg.base * 4));

			if(reg.doc_is_fiforeg == nil) then
			   emit("REG @tab");
			else
			   emit("FIFOREG @tab");
			end

			emit("@code{"..reg.c_prefix.."} @tab");
			emit(reg.name);

		end
	end);

	foreach_reg({TYPE_RAM}, function(reg)
		if(reg.full_hdl_prefix ~= nil) then
                   emit(string.format("@item @code{0x%x - 0x%x}",reg.base, reg.base+math.pow(2, reg.wrap_bits)*reg.size-1));
                   emit("@tab MEM @tab @code{"..reg.c_prefix.."} @tab "..reg.name);
		end
	end);

	emit("@end multitable ")
     end

function cgen_tex_access(acc)
	if(acc == READ_ONLY) then
		return "R/O";
	elseif(acc == READ_WRITE) then
		return "R/W";
	elseif(acc == WRITE_ONLY) then
		return "W/O";
	else
		return "FIXME!";
	end
end


function cgen_texinfo_reg(reg)

82
	emit("@regsection @code{"..reg.c_prefix.."} - "..reg.name);
83 84 85 86 87 88 89 90 91

	cur_reg_no = cur_reg_no + 1;

	local tbl = htable_new(4, 2);

-- fixme: FIFO regs 
--        emit("Address: @code{"..string.format("0x%x", reg.base * (DATA_BUS_WIDTH/8)).."}");
	
	if(reg.description ~= nil) then
92 93
           emit(format_tex_string(reg.description));
 	end
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

	emit("@multitable @columnfractions .10 .10 .15 .10 .55")
	emit("@headitem Bits @tab Access @tab Prefix @tab Default @tab Name")

	foreach_subfield(reg, function(field)
        --  emit("@columnfractions .10 .10 .15 .10 .55")

          if(field.size == 1) then
              emit(string.format("@item @code{%d}", field.offset));
           else              emit(string.format("@item @code{%d...%d}", field.offset + field.size-1, field.offset));
           end
          emit("@tab "..cgen_tex_access(field.access_bus).." @tab");
	
	if(field.c_prefix == nil) then -- anonymous field?
           emit("@code{"..string.upper(reg.c_prefix).."}");
        else
           emit("@code{"..string.upper(field.c_prefix).."}");
        end
	
113 114 115 116 117 118 119 120
				val = 'X';
				if(field.reset_value ~= nil) then
					val = field.reset_value;
				elseif ((field.access_bus == READ_WRITE and field.access_dev == READ_ONLY) or field.type == MONOSTABLE or field.access_bus == WRITE_ONLY) then
					val = '0'
				end
				
        emit("@tab @code{"..val.."} @tab ");
121 122 123 124 125 126 127 128 129 130 131
        emit(field.name);

       -- emit("@columnfractions 1")
       -- emit("@item dupa")
        --if(field.description ~= nil) then
        --   emit("<br>"..string.gsub(field.description, "\n", "<br>"));
        --end

	end);
	emit("@end multitable");		

132
	local	got_any_descriptions = false
133
	foreach_subfield(reg, function(field)
134 135 136 137 138 139 140 141 142 143
                                 if(field.description ~= nil) then
                                 		got_any_descriptions = true
                                 end 
                              end);


	if(got_any_descriptions) then
	  emit("@multitable @columnfractions 0.15 0.85")
  	emit("@headitem Field @tab Description")
		foreach_subfield(reg, function(field)
144 145 146 147 148
                                 if(field.description ~= nil) then
                                    pfx = csel(field.c_prefix == nil, reg.c_prefix, field.c_prefix)
                                    emit("@item @code{"..pfx.."} @tab "..format_tex_string(field.description));
                                 end 
                              end);
149 150
    emit("@end multitable");		
  end
151 152 153 154 155 156 157 158 159 160 161 162


end

function cgen_generate_texinfo_documentation()
	cgen_new_snippet();
	cgen_tex_memmap(); 

	foreach_reg({TYPE_REG}, function(reg) if(reg.no_docu == nil or reg.no_docu == false)then cgen_texinfo_reg(reg);end end);

	cgen_write_current_snippet();
end