remove gate ffi struct
This commit is contained in:
25
sim/gate.lua
25
sim/gate.lua
@@ -3,21 +3,11 @@ local ffi = FFI or require("ffi")
|
||||
|
||||
Gate = {}
|
||||
|
||||
ffi.cdef [[
|
||||
struct OutPort {
|
||||
struct Net* net;
|
||||
int state;
|
||||
};
|
||||
struct Gate {
|
||||
int in_queue;
|
||||
struct OutPort ports[0];
|
||||
};
|
||||
]]
|
||||
|
||||
function Gate.new(objref, definition)
|
||||
local gate = {
|
||||
-- Logic Critical
|
||||
c = nil,
|
||||
in_queue = ffi.new("int"),
|
||||
port_states = ffi.new("int["..(#definition.ports+1).."]"),
|
||||
logic = definition.logic,
|
||||
ports = {},
|
||||
port_nets = {},
|
||||
@@ -25,23 +15,20 @@ function Gate.new(objref, definition)
|
||||
objref = objref,
|
||||
definition = definition,
|
||||
}
|
||||
local cdata = ffi.new("char["..(ffi.sizeof("struct Gate") + ffi.sizeof("struct OutPort")*(#definition.ports+1)).."]")
|
||||
gate.c = ffi.cast("struct Gate*", cdata)
|
||||
gate.c.in_queue = 0
|
||||
return gate
|
||||
end
|
||||
|
||||
-- Logic Critical
|
||||
function Gate.getportstate(gate, index)
|
||||
return gate.c.ports[index].state
|
||||
return gate.port_states[index]
|
||||
end
|
||||
|
||||
-- Logic Critical
|
||||
function Gate.setportstate(gate, index, state)
|
||||
if state ~= gate.c.ports[index].state then
|
||||
if state ~= gate.port_states[index] then
|
||||
local group = gate.port_nets[index]
|
||||
group.state_num = group.state_num - gate.c.ports[index].state + state
|
||||
gate.c.ports[index].state = state
|
||||
group.state_num = group.state_num - gate.port_states[index] + state
|
||||
gate.ports_states[index] = state
|
||||
|
||||
if ((group.state_num>0) ~= (group.state==1)) and (group.in_queue==0) then
|
||||
Simulation.queuegroup(GSim, group)
|
||||
|
||||
Reference in New Issue
Block a user