From WikiChip
Difference between revisions of "Module:microarchitecture"

Line 64: Line 64:
 
          
 
          
 
     -- header
 
     -- header
     if not has_arg('name') then return infobox .. '[[Category:Articles with invalid parameter in template]]ERROR: "name" is missing!' end
+
     if not has_arg('name') then return tostring(infobox) .. '[[Category:Articles with invalid parameter in template]]ERROR: "name" is missing!' end
 
      
 
      
 
     uarch.set_val('name',  arg('name'))
 
     uarch.set_val('name',  arg('name'))

Revision as of 03:39, 26 July 2017

Documentation for this module may be created at Module:microarchitecture/doc

local uarch = {}
local origArgs

function add_header_main(box, str)
      box
        :tag('tr')
          :tag('td')
            :attr('class', 'header-main')
            :attr('colspan', '2')
            :wikitext(str)
end
function add_header(box, str)
      box
        :tag('tr')
          :tag('td')
            :attr('class', 'header')
            :attr('colspan', '2')
            :wikitext(str)
end
function add_entry(box, label, value)
      local tag = box:tag('tr')
      
      tag:tag('td')
        :attr('class', 'label')
        :wikitext(label)
        
      tag:tag('td')
        :attr('class', 'value')
        :wikitext(value)
end

function has_arg(name)
	-- The argument can exist and be empty or not exist at all
	return string.len(origArgs[name] or '') > 0
end

function arg(name)
	return origArgs[name]
end

function uarch.set_val(prop, val)
	uarch.frame:preprocess('{{#set: ' .. prop .. '=' .. val .. '}}')	
end

function uarch.uarch(frame)

	uarch.frame = frame
    if frame == mw.getCurrentFrame() then
        origArgs = frame:getParent().args
    else
        origArgs = frame
    end

    local infobox = mw.html.create('table')

    infobox
        :attr('class', 'infobox')
        
    infobox
    	:tag('tr')
			:tag('td'):attr('colspan', '2')
			:tag('small'):attr('style', 'float: left; font-weight: bold;')
            :wikitext('[[Special:FormEdit/microarchitecture/' .. frame:preprocess('{{FULLPAGENAME}}') .. '|<i class="fa fa-edit"></i>Edit Values]]')
        
    -- header
    if not has_arg('name') then return tostring(infobox) .. '[[Category:Articles with invalid parameter in template]]ERROR: "name" is missing!' end
    
    uarch.set_val('name',  arg('name'))
    uarch.set_val('codename',  arg('name'))
	add_header_main(infobox, arg('name') .. ' µarch')

	add_header(infobox, 'General Info')
	
    if not has_arg('atype') then return '[[Category:Articles with invalid parameter in template]]ERROR: "atype" is missing!' end
    if not has_arg('designer') then return '[[Category:Articles with invalid parameter in template]]ERROR: "designer" is missing!' end

    -- arch type
	add_entry(infobox, 'Arch Type', arg('atype') ..
		'[[microarchitecture type::' .. arg('atype') .. '| ]]' ..
		'[[Category:' .. string.lower(arg('atype')) .. ' microarchitectures by ' .. string.lower(arg('designer')) .. ']]')

	-- designer
    local devs
    
    devs = '[[designer::' .. arg('designer') .. ']]'
    devs = devs .. '[[Category:microarchitectures by ' .. string.lower(arg('designer')) .. ']]'
    
    for i = 2, 10 do
    	if not has_arg('designer ' .. i) then break end
    	devs = devs .. ', [[designer::' .. arg('designer ' .. i) .. '| ]]' ..
    			arg('designer ' .. i) ..
	    		'[[Category:microarchitectures by ' .. string.lower(arg('designer ' .. i)) .. ']]'
	end
	add_entry(infobox, 'Designer', devs)
	
	
	-- manufacturer
    if not has_arg('manufacturer') then return '[[Category:Articles with invalid parameter in template]]ERROR: "manufacturer" is missing!' end
    local devs = '[[manufacturer::' .. arg('manufacturer') .. ']]'
    for i = 2, 10 do
    	if not has_arg('manufacturer ' .. i) then break end
    	devs = devs .. ', [[manufacturer::' .. arg('manufacturer ' .. i) .. ']]'
	end
	add_entry(infobox, 'Manufacturer', devs)
	
    -- intro
    if string.len(origArgs.introduction or '') > 0 then
		add_entry(infobox, 'Introduction', '[[first launched::' .. origArgs.introduction .. ']]')
	end
	
    -- phase-out
    if string.len(origArgs['phase-out'] or '') > 0 then
		add_entry(infobox, 'Phase-out', '[[phase-out::' .. origArgs['phase-out'] .. ']]')
	end
	
	
	
	-- process
    if string.len(origArgs.process or '') > 0 then
	    local proc
	    
	    proc = '[[process::' .. origArgs.process .. '| ]]' ..
	    		'[[' ..  origArgs.process .. ' process|' ..  origArgs.process .. ']]'
	    
	    for i = 2, 10 do
	    	if string.len(origArgs['process ' .. i] or '') == 0 then break end
	    	proc = proc .. ', [[process::' ..origArgs['process ' .. i] .. '| ]]'
	    			.. '[['..  origArgs['process ' .. i] .. ' process|' .. origArgs['process ' .. i] .. ']]'
		end
		add_entry(infobox, 'Process', proc)
	end	
	
	
	-- cores
    if string.len(origArgs.cores or '') > 0 then
	    local core
	    
	    core = '[[core count::' .. origArgs.cores .. '| ]]'
	    	.. '[[' .. origArgs.cores .. ' cores|' .. origArgs.cores .. ']]'
	    
	    for i = 2, 20 do
	    	if string.len(origArgs['cores ' .. i] or '') == 0 then break end
	    	core = core .. ', [[core count::' ..origArgs['cores ' .. i] .. '| ]]'
	    		.. '[[' .. origArgs['cores ' .. i] .. ' cores|' .. origArgs['cores ' .. i] .. ']]'
		end
		add_entry(infobox, 'Core Configs', core)
	end
	
	if has_arg('type') or has_arg('oooe') or has_arg('speculative')
		or has_arg('renaming') or has_arg('stages') or has_arg('stages min')
		or has_arg('decode') then
		add_header(infobox, 'Pipeline')
	end
	
	-- type
    if string.len(origArgs['type'] or '') > 0 then
	    local ptype
	    
	    ptype = origArgs['type']
	    for i = 2, 10 do
	    	if string.len(origArgs['type ' .. i] or '') == 0 then break end
	    	ptype = ptype .. ', ' .. origArgs['type ' .. i]
		end
		add_entry(infobox, 'Type', ptype)
	end
	
    -- oooe
    if string.len(origArgs.oooe or '') > 0 then
		add_entry(infobox, 'OoOE', origArgs.oooe)
	end
	
    -- speculative
    if string.len(origArgs.speculative or '') > 0 then
		add_entry(infobox, 'Speculative', origArgs.speculative)
	end
	
    -- renaming
    if string.len(origArgs.renaming or '') > 0 then
		add_entry(infobox, 'Reg Renaming', origArgs.renaming)
	end
	
    -- stages
    if string.len(origArgs.stages or '') > 0 then
		add_entry(infobox, 'Stages', '[[pipeline stages::' .. origArgs.stages .. ']]')
	end
	
    -- stages min/max
    if string.len(origArgs['stages min'] or '') > 0 then
		add_entry(infobox, 'Stages',
			'[[pipeline stages (min)::' .. origArgs['stages min'] .. ']]'
			.. '-[[pipeline stages (max)::' .. origArgs['stages max'] .. ']]')
	end
	
    -- decode
    if string.len(origArgs.decode or '') > 0 then
		add_entry(infobox, 'Decode', origArgs.decode)
	end
	
	
    if has_arg('isa') or has_arg('features') or has_arg('extension') then
		add_header(infobox, 'Instructions')
	end
	
	-- ISA
    if string.len(origArgs.isa or '') > 0 then
	    local isa
	    
	    isa = '[[instruction set architecture::' .. origArgs.isa .. ']]'
	    for i = 2, 10 do
	    	if string.len(origArgs['isa ' .. i] or '') == 0 then break end
	    	isa = isa .. ', ' .. '[[instruction set architecture::' .. origArgs['isa ' .. i] .. ']]'
		end
		add_entry(infobox, 'ISA', isa)
	end
	
	-- features
    if string.len(origArgs.features or '') > 0 then
	    local features
	    
	    features = origArgs.features
	    for i = 2, 10 do
	    	if string.len(origArgs['features ' .. i] or '') == 0 then break end
	    	features = features .. ', ' .. origArgs['features ' .. i]
		end
		add_entry(infobox, 'Features', features)
	end
	
	-- extensions
    if string.len(origArgs.extension or '') > 0 then
	    local extension
	    
	    extension = origArgs.extension
	    for i = 2, 40 do
	    	if string.len(origArgs['extension ' .. i] or '') == 0 then break end
	    	extension = extension .. ', ' .. origArgs['extension ' .. i]
		end
		add_entry(infobox, 'Extensions', extension)
	end
	
	
	
	
	if has_arg('l1') or has_arg('l1i') or has_arg('l1d') or
		has_arg('l2') or has_arg('l3') or has_arg('l3') or
		has_arg('side cache') then
		add_header(infobox, 'Cache')
	end
	
    -- L1i
    if string.len(origArgs.l1i or '') > 0 then
    	local li = origArgs.l1i
    	if string.len(origArgs['l1i per'] or '') > 0 then
    		li = li .. '/' .. origArgs['l1i per']
		end
    	if string.len(origArgs['l1i desc'] or '') > 0 then
    		li = li .. '<br>' .. origArgs['l1i desc']
		end
		add_entry(infobox, 'L1I Cache',  li)
	end
	
    -- L1d
    if string.len(origArgs.l1d or '') > 0 then
    	local li = origArgs.l1d
    	if string.len(origArgs['l1d per'] or '') > 0 then
    		li = li .. '/' .. origArgs['l1d per']
		end
    	if string.len(origArgs['l1d desc'] or '') > 0 then
    		li = li .. '<br>' .. origArgs['l1d desc']
		end
		add_entry(infobox, 'L1D Cache',  li)
	end
	
    -- L1, Unified
    if string.len(origArgs.l1 or '') > 0 then
    	local li = origArgs.l1
    	if string.len(origArgs['l1 per'] or '') > 0 then
    		li = li .. '/' .. origArgs['l1 per']
		end
    	if string.len(origArgs['l1 desc'] or '') > 0 then
    		li = li .. '<br>' .. origArgs['l1 desc']
		end
		add_entry(infobox, 'L1 Cache',  li)
	end
	
    -- L2
    if string.len(origArgs.l2 or '') > 0 then
    	local l2 = origArgs.l2
    	if string.len(origArgs['l2 per'] or '') > 0 then
    		l2 = l2 .. '/' .. origArgs['l2 per']
		end
    	if string.len(origArgs['l2 desc'] or '') > 0 then
    		l2 = l2 .. '<br>' .. origArgs['l2 desc']
		end
		add_entry(infobox, 'L2 Cache',  l2)
	end
	
    -- L3
    if string.len(origArgs.l3 or '') > 0 then
    	local l3 = origArgs.l3
    	if string.len(origArgs['l3 per'] or '') > 0 then
    		l3 = l3 .. '/' .. origArgs['l3 per']
		end
    	if string.len(origArgs['l3 desc'] or '') > 0 then
    		l3 = l3 .. '<br>' .. origArgs['l3 desc']
		end
		add_entry(infobox, 'L3 Cache',  l3)
	end
	
    -- L4
    if string.len(origArgs.l4 or '') > 0 then
    	local l4 = origArgs.l4
    	if string.len(origArgs['l4 per'] or '') > 0 then
    		l4 = l4 .. '/' .. origArgs['l4 per']
		end
    	if string.len(origArgs['l4 desc'] or '') > 0 then
    		l4 = l4 .. '<br>' .. origArgs['l4 desc']
		end
		add_entry(infobox, 'L4 Cache',  l4)
	end
	
    -- Side $
    if has_arg('side cache') then
    	local sidecache = arg('side cache')
    	if has_arg('side cache per') then
    		sidecache = sidecache .. '/' .. arg('side cache per')
		end
    	if has_arg('side cache desc') then
    		sidecache = sidecache .. '<br>' .. arg('side cache desc')
		end
		add_entry(infobox, 'Size Cache',  sidecache)
	end
	
	
	-- cores
    if has_arg('core name') then
		add_header(infobox, 'Cores')
		
	    local cores = arg('core name')
	    for i = 2, 10 do
	    	if not has_arg('core name ' .. i) then break end
	    	cores = cores .. ', ' .. arg('core name ' .. i)
		end
		add_entry(infobox, 'Core Names', cores)
	end
	
	if has_arg('successor') or has_arg('predecessor') then
		add_header(infobox, 'Succession')
		
		local s = infobox:tag('tr')
		local td = s:tag('td'):attr('colspan', '2')
		local d1 = td:tag('div'):attr('style', 'display: inline-flex;')
		local d2 = td:tag('div'):attr('style', 'display: inline-flex; float: right;')
		if has_arg('predecessor') then
			
		    local list
		    if has_arg('predecessor link') then
				list = '[[' .. arg('predecessor link') .. '|' .. arg('predecessor') .. ']]'
			else
				list = '[[' .. arg('predecessor') .. ']]'
			end
		    for i = 2, 10 do
		    	if not has_arg('predecessor ' .. i) then break end
		    	if has_arg('predecessor ' .. i .. ' link') then
		    		list = list .. '<br>[[' .. arg('predecessor ' .. i .. ' link') .. '|' .. arg('predecessor ' .. i) .. ']]'
	    		else
		    		list = list .. '<br>[[' .. arg('predecessor ' .. i) .. ']]'
    			end
			end
			
			d1:tag('div')
				:attr('style', 'float: left; padding-right: 10px; margin: auto 5px;')
				:wikitext('<i class="fa fa-chevron-left"></i>')
			d1:tag('div')
				:attr('style', 'float: left;')
				:wikitext(list)
		end
		if has_arg('successor') then
			local list
		    if has_arg('successor link') then
				list = '[[' .. arg('successor link') .. '|' .. arg('successor') .. ']]'
			else
				list = '[[' .. arg('successor') .. ']]'
			end
		    for i = 2, 10 do
		    	if not has_arg('successor ' .. i) then break end
		    	if has_arg('successor ' .. i .. ' link') then
		    		list = list .. '<br>[[' .. arg('successor ' .. i .. ' link') .. '|' ..
		    			arg('successor ' .. i) .. ']]'
	    		else
		    		list = list .. '<br>[[' .. arg('successor ' .. i) .. ']]'
    			end
			end
			
			d2:tag('div')
				:attr('style', 'float: left;')
				:wikitext(list)
			d2:tag('div')
				:attr('style', 'float: right; padding-left: 10px; margin: auto 5px;')
				:wikitext('<i class="fa fa-chevron-right"></i>')
		end
	end
    -- Contemporary
	if has_arg('contemporary') then
		add_header(infobox, 'Contemporary')
		
		local s = infobox:tag('tr')
		local td = s:tag('td'):attr('colspan', '2')
		
		td:attr('style', 'text-align: center;')

	    local list
	    if has_arg('contemporary link') then
			list = '[[' .. arg('contemporary link') .. '|' .. arg('contemporary') .. ']]'
		else
			list = '[[' .. arg('contemporary') .. ']]'
		end
	    for i = 2, 10 do
	    	if not has_arg('contemporary ' .. i) then break end
	    	if has_arg('contemporary ' .. i .. ' link') then
	    		list = list .. '<br>[[' .. arg('contemporary ' .. i .. ' link') .. '|' .. arg('contemporary ' .. i) .. ']]'
    		else
	    		list = list .. '<br>[[' .. arg('contemporary ' .. i) .. ']]'
			end
		end
		
		td:wikitext(list)
	end
            
    infobox:wikitext('[[Category:all microarchitectures]]')
    infobox:wikitext('[[full page name::' .. frame:preprocess('{{FULLPAGENAME}}') .. '| ]]')
    infobox:wikitext('[[instance of::microarchitecture| ]]')
	
	return infobox
end

return uarch