remove c logic and data from network, more work on compiled gate funcs
This commit is contained in:
parent
1eba4bb2fa
commit
bcebfed077
Binary file not shown.
@ -1,17 +1,21 @@
|
||||
|
||||
GATEFUNC(Diode) { setport(2, getport(1)); }
|
||||
GATEFUNC(Not) { setport(2, !getport(1)); }
|
||||
|
||||
////
|
||||
// Auto-generated by gencfuncs.lua
|
||||
|
||||
enum GateFuncs {
|
||||
GateFunc_None,
|
||||
GateFunc_Diode = 1,
|
||||
GateFunc_Not = 2,
|
||||
GateFunc_Diode,
|
||||
GateFunc_Not,
|
||||
};
|
||||
|
||||
GATEFUNC(Diode) {
|
||||
setport(2, getport(1));
|
||||
}
|
||||
GATEFUNC(Not) {
|
||||
setport(2, !getport(1));
|
||||
}
|
||||
|
||||
GateFunc sim_logic_functions[] = {
|
||||
0,
|
||||
GATEFUNCID(Diode),
|
||||
GATEFUNCID(Not),
|
||||
};
|
||||
|
||||
|
13
sim/compiled_sim_gates.lua
Normal file
13
sim/compiled_sim_gates.lua
Normal file
@ -0,0 +1,13 @@
|
||||
-- Auto-generated by gencfuncs.lua
|
||||
|
||||
local cFuncsByName = {
|
||||
["diode"] = 1,
|
||||
["not"] = 2,
|
||||
}
|
||||
|
||||
local cDataSizeByName = {
|
||||
["diode"] = 0,
|
||||
["not"] = 0,
|
||||
}
|
||||
|
||||
return cFuncsByName, cDataSizeByName
|
@ -7,7 +7,9 @@ GateDefinition = {
|
||||
input = function(gate, argv) end
|
||||
}
|
||||
|
||||
function GateDefinition.new(objref, name, description, init, logic, input, global, ports, datasize, logicfuncc)
|
||||
local cFuncsByName, cDataSizeByName = require("compiled_sim_gates")
|
||||
|
||||
function GateDefinition.new(objref, name, description, init, logic, input, global, ports)
|
||||
|
||||
name = collapseescape(name)
|
||||
init = collapseescape(init)
|
||||
@ -23,8 +25,8 @@ function GateDefinition.new(objref, name, description, init, logic, input, globa
|
||||
ports = ports or {},
|
||||
num_in_ports = 0,
|
||||
num_out_ports = 0,
|
||||
data_size_c = datasize,
|
||||
logic_function_c = logicfuncc,
|
||||
data_size_c = cDataSizeByName[name:lower()] or 0,
|
||||
logic_function_c = cFuncsByName[name:lower()] or 0,
|
||||
}
|
||||
|
||||
local initfunc = loadstring(tostring(init))
|
||||
|
@ -1,24 +1,63 @@
|
||||
local c_code = [[
|
||||
// Auto-generated by gencfuncs.lua
|
||||
|
||||
local luatoc_subs = {
|
||||
{"Gate%.setportstate%(gate, *", "setport%("},
|
||||
{"Gate%.getportstate%(gate, *", "getport%("},
|
||||
{"~=", "!="},
|
||||
{"!= *0", ""},
|
||||
{"elseif", "els2 if"},
|
||||
{"if", "if("},
|
||||
{"else", "} else {"},
|
||||
{"els2", "else"},
|
||||
{"end", "}"},
|
||||
{"then", ") {"},
|
||||
{"return function(gate)", "GATEFUNC"},
|
||||
enum GateFuncs {
|
||||
GateFunc_None,
|
||||
%s
|
||||
};
|
||||
|
||||
%s
|
||||
|
||||
GateFunc sim_logic_functions[] = {
|
||||
0,
|
||||
%s
|
||||
};
|
||||
|
||||
]]
|
||||
|
||||
local lua_code = [[
|
||||
-- Auto-generated by gencfuncs.lua
|
||||
|
||||
local cFuncsByName = {
|
||||
%s
|
||||
}
|
||||
local function luatoc(f)
|
||||
for i, sub in ipairs(luatoc_subs) do
|
||||
f = f:gsub(sub[1], sub[2])
|
||||
end
|
||||
return f
|
||||
|
||||
local cDataSizeByName = {
|
||||
%s
|
||||
}
|
||||
|
||||
return cFuncsByName, cDataSizeByName
|
||||
]]
|
||||
local function writeFile(fn, data)
|
||||
local f = io.open(fn, "wb") or error("Could not open file for writing: "..fn)
|
||||
f:write(data)
|
||||
f:close()
|
||||
end
|
||||
|
||||
local function tstogatedata(ts)
|
||||
local function exportGates(gates)
|
||||
local gateList = {}
|
||||
local gateFuncList = {}
|
||||
local gateSizeList = {}
|
||||
for k, gate in pairs(gates) do
|
||||
table.insert(gateList, gate.name or error("gate "..k.." has no name"))
|
||||
table.insert(gateFuncList, gate.func or error("gate "..gate.name.." has no c function"))
|
||||
table.insert(gateSizeList, gate.size or 0)
|
||||
end
|
||||
|
||||
local function map(t, f) local u = {}; for i, v in ipairs(t) do table.insert(u, f(v, i)) end; return u; end
|
||||
writeFile("compiled_sim_gates.c", string.format(c_code,
|
||||
table.concat(map(gateList, function(v, i) return string.format("\tGateFunc_%s,", v) end), "\n"),
|
||||
table.concat(map(gateList, function(v, i) return string.format("GATEFUNC(%s) {\n\t%s\n}", v, gateFuncList[i]:gsub("\n", "\n\t"):gsub("\n+$", ""):gsub("^\n+", "")) end), "\n"),
|
||||
table.concat(map(gateList, function(v, i) return string.format("\tGATEFUNCID(%s),", v) end), "\n")
|
||||
))
|
||||
writeFile("compiled_sim_gates.lua", string.format(lua_code,
|
||||
table.concat(map(gateList, function(v, i) return string.format("\t[\"%s\"] = %i,", v:lower(), i) end), "\n"),
|
||||
table.concat(map(gateList, function(v, i) return string.format("\t[\"%s\"] = %i,", v:lower(), gateSizeList[i]) end), "\n")
|
||||
))
|
||||
end
|
||||
|
||||
local gates = {
|
||||
{ name = "Diode", func = "setport(2, getport(1));" },
|
||||
{ name = "Not" , func = "setport(2, !getport(1));" },
|
||||
}
|
||||
exportGates(gates)
|
||||
|
@ -75,12 +75,10 @@ function network_update()
|
||||
local logic = data[i+5]
|
||||
local input = data[i+6]
|
||||
local global = data[i+7]
|
||||
local datasize = tonumber(data[i+8])
|
||||
local logicfuncc = tonumber(data[i+9])
|
||||
local numports = tonumber(data[i+10])
|
||||
local ports = {}
|
||||
i = i + 10
|
||||
local numports = tonumber(data[i+8])
|
||||
i = i + 8
|
||||
|
||||
local ports = {}
|
||||
for a = i+1, numports*5+i, 5 do
|
||||
local portd = {
|
||||
type = tonumber(data[a]),
|
||||
@ -94,7 +92,7 @@ function network_update()
|
||||
if not portd.direction then print(line) end
|
||||
end
|
||||
|
||||
local definition = GateDefinition.new(objref, name, desc, init, logic, input, global, ports, datasize, logicfuncc)
|
||||
local definition = GateDefinition.new(objref, name, desc, init, logic, input, global, ports)
|
||||
Simulation.addgatedefinition(sim, definition)
|
||||
|
||||
i = i + numports*5
|
||||
|
Loading…
x
Reference in New Issue
Block a user