Add #ifndef, #ifdef to netlist preprocessor and implemented == operator

Fix more -Wextra warnings, mostly int==>std::size_t and signed
comparisons. (nw)
This commit is contained in:
couriersud 2015-05-26 19:29:43 +02:00
parent b2af252a36
commit e5d3af5c01
18 changed files with 146 additions and 103 deletions

View File

@ -25,9 +25,6 @@
#pragma GCC optimize "-fivopts"
#endif
#define SOLVER_VERBOSE_OUT(x) do {} while (0)
//#define SOLVER_VERBOSE_OUT(x) printf x
#include <algorithm>
#include "nld_solver.h"
#include "nld_ms_direct.h"
@ -88,12 +85,12 @@ ATTR_COLD void netlist_matrix_solver_t::setup(netlist_analog_net_t::list_t &nets
m_nets.clear();
for (int k = 0; k < nets.size(); k++)
for (std::size_t k = 0; k < nets.size(); k++)
{
m_nets.add(nets[k]);
}
for (int k = 0; k < nets.size(); k++)
for (std::size_t k = 0; k < nets.size(); k++)
{
NL_VERBOSE_OUT(("setting up net\n"));
@ -101,7 +98,7 @@ ATTR_COLD void netlist_matrix_solver_t::setup(netlist_analog_net_t::list_t &nets
net->m_solver = this;
for (int i = 0; i < net->m_core_terms.size(); i++)
for (std::size_t i = 0; i < net->m_core_terms.size(); i++)
{
netlist_core_terminal_t *p = net->m_core_terms[i];
NL_VERBOSE_OUT(("%s %s %d\n", p->name().cstr(), net->name().cstr(), (int) net->isRailNet()));
@ -134,7 +131,7 @@ ATTR_COLD void netlist_matrix_solver_t::setup(netlist_analog_net_t::list_t &nets
case netlist_terminal_t::INPUT:
{
netlist_analog_output_t *net_proxy_output = NULL;
for (int i = 0; i < m_inps.size(); i++)
for (std::size_t i = 0; i < m_inps.size(); i++)
if (m_inps[i]->m_proxied_net == &p->net().as_analog())
{
net_proxy_output = m_inps[i];
@ -167,7 +164,7 @@ ATTR_COLD void netlist_matrix_solver_t::setup(netlist_analog_net_t::list_t &nets
ATTR_HOT void netlist_matrix_solver_t::update_inputs()
{
// avoid recursive calls. Inputs are updated outside this call
for (int i=0; i<m_inps.size(); i++)
for (std::size_t i=0; i<m_inps.size(); i++)
m_inps[i]->set_Q(m_inps[i]->m_proxied_net->m_cur_Analog);
}
@ -175,7 +172,7 @@ ATTR_HOT void netlist_matrix_solver_t::update_inputs()
ATTR_HOT void netlist_matrix_solver_t::update_dynamic()
{
/* update all non-linear devices */
for (int i=0; i < m_dynamic_devices.size(); i++)
for (std::size_t i=0; i < m_dynamic_devices.size(); i++)
switch (m_dynamic_devices[i]->family())
{
case netlist_device_t::DIODE:
@ -218,7 +215,7 @@ ATTR_COLD void netlist_matrix_solver_t::update_forced()
ATTR_HOT void netlist_matrix_solver_t::step(const netlist_time delta)
{
const nl_double dd = delta.as_double();
for (int k=0; k < m_step_devices.size(); k++)
for (std::size_t k=0; k < m_step_devices.size(); k++)
m_step_devices[k]->step_time(dd);
}
@ -281,7 +278,7 @@ ATTR_HOT nl_double netlist_matrix_solver_t::solve()
ATTR_COLD int netlist_matrix_solver_t::get_net_idx(netlist_net_t *net)
{
for (int k = 0; k < m_nets.size(); k++)
for (std::size_t k = 0; k < m_nets.size(); k++)
if (m_nets[k] == net)
return k;
return -1;
@ -329,7 +326,7 @@ NETLIB_START(solver)
NETLIB_RESET(solver)
{
for (int i = 0; i < m_mat_solvers.size(); i++)
for (std::size_t i = 0; i < m_mat_solvers.size(); i++)
m_mat_solvers[i]->reset();
}
@ -341,7 +338,7 @@ NETLIB_UPDATE_PARAM(solver)
NETLIB_STOP(solver)
{
for (int i = 0; i < m_mat_solvers.size(); i++)
for (std::size_t i = 0; i < m_mat_solvers.size(); i++)
m_mat_solvers[i]->log_stats();
}
@ -355,7 +352,7 @@ NETLIB_UPDATE(solver)
if (m_params.m_dynamic)
return;
const int t_cnt = m_mat_solvers.size();
const std::size_t t_cnt = m_mat_solvers.size();
#if HAS_OPENMP && USE_OPENMP
if (m_parallel.Value())
@ -381,7 +378,7 @@ NETLIB_UPDATE(solver)
ATTR_UNUSED const nl_double ts = m_mat_solvers[i]->solve();
}
#else
for (int i = 0; i < t_cnt; i++)
for (std::size_t i = 0; i < t_cnt; i++)
{
if (m_mat_solvers[i]->is_timestep())
{
@ -464,7 +461,7 @@ ATTR_COLD void NETLIB_NAME(solver)::post_start()
netlist().log("Scanning net groups ...");
// determine net groups
for (int i=0; i<netlist().m_nets.size(); i++)
for (std::size_t i=0; i<netlist().m_nets.size(); i++)
{
SOLVER_VERBOSE_OUT(("processing %s\n", netlist().m_nets[i]->name().cstr()));
if (!netlist().m_nets[i]->isRailNet())
@ -484,7 +481,7 @@ ATTR_COLD void NETLIB_NAME(solver)::post_start()
for (int i = 0; i <= cur_group; i++)
{
netlist_matrix_solver_t *ms;
int net_count = groups[i].size();
std::size_t net_count = groups[i].size();
switch (net_count)
{
@ -547,11 +544,11 @@ ATTR_COLD void NETLIB_NAME(solver)::post_start()
netlist().log(" # %d ==> %" SIZETFMT " nets", i, groups[i].size()); //, (*(*groups[i].first())->m_core_terms.first())->name().cstr());
netlist().log(" has %s elements", ms->is_dynamic() ? "dynamic" : "no dynamic");
netlist().log(" has %s elements", ms->is_timestep() ? "timestep" : "no timestep");
for (int j=0; j<groups[i].size(); j++)
for (std::size_t j=0; j<groups[i].size(); j++)
{
netlist().log("Net %d: %s", j, groups[i][j]->name().cstr());
netlist().log("Net %" SIZETFMT ": %s", j, groups[i][j]->name().cstr());
netlist_net_t *n = groups[i][j];
for (int k = 0; k < n->m_core_terms.size(); k++)
for (std::size_t k = 0; k < n->m_core_terms.size(); k++)
{
const netlist_core_terminal_t *p = n->m_core_terms[k];
netlist().log(" %s", p->name().cstr());

View File

@ -14,6 +14,9 @@
//#define ATTR_ALIGNED(N) __attribute__((aligned(N)))
#define ATTR_ALIGNED(N) ATTR_ALIGN
#define SOLVER_VERBOSE_OUT(x) do {} while (0)
//#define SOLVER_VERBOSE_OUT(x) printf x
// ----------------------------------------------------------------------------------------
// Macros
// ----------------------------------------------------------------------------------------

View File

@ -8,9 +8,9 @@
#include "nld_truthtable.h"
#include "../plists.h"
int truthtable_desc_t::count_bits(UINT32 v)
unsigned truthtable_desc_t::count_bits(UINT32 v)
{
int ret = 0;
unsigned ret = 0;
for (; v != 0; v = v >> 1)
{
if (v & 1)
@ -52,7 +52,7 @@ UINT32 truthtable_desc_t::get_ignored_extended(UINT32 i)
{
// Determine all inputs which may be ignored ...
UINT32 nign = 0;
for (int j=0; j<m_NI; j++)
for (unsigned j=0; j<m_NI; j++)
{
if (m_outs[i] == m_outs[i ^ (1 << j)])
nign |= (1<<j);
@ -61,14 +61,14 @@ UINT32 truthtable_desc_t::get_ignored_extended(UINT32 i)
* We have to remove those where the ignored inputs
* may change the output
*/
int bits = (1<<count_bits(nign));
UINT32 bits = (1<<count_bits(nign));
parray_t<int> t(bits);
for (UINT32 j=1; j<bits; j++)
{
UINT32 tign = set_bits(nign, j);
t[j] = 0;
int bitsk=(1<<count_bits(tign));
UINT32 bitsk=(1<<count_bits(tign));
for (UINT32 k=0; k<bitsk; k++)
{
UINT32 b=set_bits(tign, k);
@ -83,7 +83,7 @@ UINT32 truthtable_desc_t::get_ignored_extended(UINT32 i)
UINT32 jm=0;
for (UINT32 j=1; j<bits; j++)
{
int nb = count_bits(j);
unsigned nb = count_bits(j);
if ((t[j] == 0)&& (nb>jb))
{
jb = nb;
@ -97,7 +97,7 @@ UINT32 truthtable_desc_t::get_ignored_extended(UINT32 i)
// desc
// ----------------------------------------------------------------------------------------
ATTR_COLD void truthtable_desc_t::help(int cur, nl_util::pstring_list list,
ATTR_COLD void truthtable_desc_t::help(unsigned cur, nl_util::pstring_list list,
UINT64 state,UINT16 val, UINT8 *timing_index)
{
pstring elem = list[cur].trim();
@ -132,11 +132,11 @@ ATTR_COLD void truthtable_desc_t::help(int cur, nl_util::pstring_list list,
else
{
// cutoff previous inputs and outputs for ignore
if (m_outs[nstate] != -1 && m_outs[nstate] != val)
if (m_outs[nstate] != ~0U && m_outs[nstate] != val)
nl_fatalerror("Error in truthtable: State %04x already set, %d != %d\n",
(UINT32) nstate, m_outs[nstate], val);
m_outs[nstate] = val;
for (int j=0; j<m_NO; j++)
for (unsigned j=0; j<m_NO; j++)
m_timing[nstate * m_NO + j] = timing_index[j];
}
}
@ -152,8 +152,8 @@ ATTR_COLD void truthtable_desc_t::setup(const char **truthtable, UINT32 disabled
ttline = pstring(truthtable[0]);
truthtable++;
for (int j=0; j < m_size; j++)
m_outs[j] = -1;
for (unsigned j=0; j < m_size; j++)
m_outs[j] = ~0L;
for (int j=0; j < 16; j++)
m_timing_nt[j] = netlist_time::zero;
@ -173,7 +173,7 @@ ATTR_COLD void truthtable_desc_t::setup(const char **truthtable, UINT32 disabled
UINT16 val = 0;
parray_t<UINT8> tindex(m_NO);
for (int j=0; j<m_NO; j++)
for (unsigned j=0; j<m_NO; j++)
{
pstring outs = out[j].trim();
if (outs.equals("1"))
@ -196,12 +196,12 @@ ATTR_COLD void truthtable_desc_t::setup(const char **truthtable, UINT32 disabled
// determine ignore
parray_t<UINT32> ign(m_size);
for (int j=0; j < m_size; j++)
ign[j] = -1;
for (UINT32 j=0; j < m_size; j++)
ign[j] = ~0U;
for (UINT32 i=0; i<m_size; i++)
{
if (ign[i] == -1)
if (ign[i] == ~0U)
{
int tign;
if (0)
@ -215,7 +215,7 @@ ATTR_COLD void truthtable_desc_t::setup(const char **truthtable, UINT32 disabled
ign[i] = tign;
/* don't need to recalculate similar ones */
int bitsk=(1<<count_bits(tign));
UINT32 bitsk=(1<<count_bits(tign));
for (UINT32 k=0; k<bitsk; k++)
{
UINT32 b=set_bits(tign, k);
@ -224,9 +224,9 @@ ATTR_COLD void truthtable_desc_t::setup(const char **truthtable, UINT32 disabled
}
}
}
for (int i=0; i<m_size; i++)
for (UINT32 i=0; i<m_size; i++)
{
if (m_outs[i] == -1)
if (m_outs[i] == ~0U)
nl_fatalerror("truthtable: found element not set %04x\n", i);
m_outs[i] |= ((ign[i] & ~disabled_ignore) << m_NO);
}

View File

@ -47,15 +47,15 @@ struct truthtable_desc_t
ATTR_COLD void setup(const char **truthtable, UINT32 disabled_ignore);
private:
ATTR_COLD void help(int cur, nl_util::pstring_list list,
ATTR_COLD void help(unsigned cur, nl_util::pstring_list list,
UINT64 state,UINT16 val, UINT8 *timing_index);
static int count_bits(UINT32 v);
static unsigned count_bits(UINT32 v);
static UINT32 set_bits(UINT32 v, UINT32 b);
UINT32 get_ignored_simple(UINT32 i);
UINT32 get_ignored_extended(UINT32 i);
int m_NO;
int m_NI;
unsigned m_NO;
unsigned m_NI;
//int m_has_state;
bool *m_initialized;
UINT32 *m_outs;
@ -69,7 +69,7 @@ private:
};
template<int m_NI, int m_NO, int has_state>
template<unsigned m_NI, unsigned m_NO, int has_state>
class nld_truthtable_t : public netlist_device_t
{
public:
@ -166,12 +166,12 @@ public:
netlist_time mt = netlist_time::zero;
UINT32 state = 0;
for (int i = 0; i < m_NI; i++)
for (unsigned i = 0; i < m_NI; i++)
{
if (!doOUT || (m_ign & (1<<i)) != 0)
m_i[i].activate();
}
for (int i = 0; i < m_NI; i++)
for (unsigned i = 0; i < m_NI; i++)
{
state |= (INPLOGIC(m_i[i]) << i);
if (!doOUT)

View File

@ -197,7 +197,7 @@ netlist_base_t::netlist_base_t()
netlist_base_t::~netlist_base_t()
{
for (int i=0; i < m_nets.size(); i++)
for (std::size_t i=0; i < m_nets.size(); i++)
{
if (!m_nets[i]->isRailNet())
{
@ -248,7 +248,7 @@ ATTR_COLD void netlist_base_t::start()
m_use_deactivate = (m_params->m_use_deactivate.Value() ? true : false);
NL_VERBOSE_OUT(("Initializing devices ...\n"));
for (int i = 0; i < m_devices.size(); i++)
for (std::size_t i = 0; i < m_devices.size(); i++)
{
netlist_device_t *dev = m_devices[i];
if (dev != m_solver && dev != m_params)
@ -264,7 +264,7 @@ ATTR_COLD void netlist_base_t::stop()
NL_VERBOSE_OUT(("Stopping all devices ...\n"));
// Step all devices once !
for (int i = 0; i < m_devices.size(); i++)
for (std::size_t i = 0; i < m_devices.size(); i++)
{
m_devices[i]->stop_dev();
}
@ -272,7 +272,7 @@ ATTR_COLD void netlist_base_t::stop()
ATTR_COLD netlist_net_t *netlist_base_t::find_net(const pstring &name)
{
for (int i = 0; i < m_nets.size(); i++)
for (std::size_t i = 0; i < m_nets.size(); i++)
{
if (m_nets[i]->name() == name)
return m_nets[i];
@ -282,7 +282,7 @@ ATTR_COLD netlist_net_t *netlist_base_t::find_net(const pstring &name)
ATTR_COLD void netlist_base_t::rebuild_lists()
{
for (int i = 0; i < m_nets.size(); i++)
for (std::size_t i = 0; i < m_nets.size(); i++)
m_nets[i]->rebuild_list();
}
@ -297,24 +297,24 @@ ATTR_COLD void netlist_base_t::reset()
m_solver->do_reset();
// Reset all nets once !
for (int i = 0; i < m_nets.size(); i++)
for (std::size_t i = 0; i < m_nets.size(); i++)
m_nets[i]->do_reset();
// Reset all devices once !
for (int i = 0; i < m_devices.size(); i++)
for (std::size_t i = 0; i < m_devices.size(); i++)
{
m_devices[i]->do_reset();
}
// Step all devices once !
for (int i = 0; i < m_devices.size(); i++)
for (std::size_t i = 0; i < m_devices.size(); i++)
{
m_devices[i]->update_dev();
}
// FIXME: some const devices rely on this
/* make sure params are set now .. */
for (int i = 0; i < m_devices.size(); i++)
for (std::size_t i = 0; i < m_devices.size(); i++)
{
m_devices[i]->update_param();
}
@ -650,7 +650,7 @@ ATTR_COLD void netlist_net_t::rebuild_list()
/* rebuild m_list */
m_list_active.clear();
for (int i=0; i < m_core_terms.size(); i++)
for (std::size_t i=0; i < m_core_terms.size(); i++)
if (m_core_terms[i]->state() != netlist_logic_t::STATE_INP_PASSIVE)
m_list_active.add(*m_core_terms[i]);
}
@ -708,13 +708,13 @@ ATTR_COLD void netlist_net_t::reset()
/* rebuild m_list */
m_list_active.clear();
for (int i=0; i < m_core_terms.size(); i++)
for (std::size_t i=0; i < m_core_terms.size(); i++)
m_list_active.add(*m_core_terms[i]);
for (int i=0; i < m_core_terms.size(); i++)
for (std::size_t i=0; i < m_core_terms.size(); i++)
m_core_terms[i]->do_reset();
for (int i=0; i < m_core_terms.size(); i++)
for (std::size_t i=0; i < m_core_terms.size(); i++)
if (m_core_terms[i]->state() != netlist_logic_t::STATE_INP_PASSIVE)
m_active++;
}
@ -731,7 +731,7 @@ ATTR_COLD void netlist_net_t::register_con(netlist_core_terminal_t &terminal)
ATTR_COLD void netlist_net_t::move_connections(netlist_net_t *dest_net)
{
for (int i = 0; i < m_core_terms.size(); i++)
for (std::size_t i = 0; i < m_core_terms.size(); i++)
{
netlist_core_terminal_t *p = m_core_terms[i];
dest_net->register_con(*p);
@ -829,7 +829,7 @@ ATTR_COLD void netlist_analog_net_t::process_net(list_t *groups, int &cur_group)
/* add the net */
//SOLVER_VERBOSE_OUT(("add %d - %s\n", cur_group, name().cstr()));
groups[cur_group].add(this);
for (int i = 0; i < m_core_terms.size(); i++)
for (std::size_t i = 0; i < m_core_terms.size(); i++)
{
netlist_core_terminal_t *p = m_core_terms[i];
//SOLVER_VERBOSE_OUT(("terminal %s\n", p->name().cstr()));

View File

@ -25,8 +25,8 @@ sed -e 's/#define \(.*\)"\(.*\)"[ \t]*,[ \t]*\(.*\)/NET_ALIAS(\1,\2.\3)/' src/ma
#define NL_DICE_COMPAT_H_
#ifndef NL_CONVERT_CPP
#include "netlist/devices/net_lib.h"
#include "netlist/analog/nld_twoterm.h"
#include "devices/net_lib.h"
#include "analog/nld_twoterm.h"
#endif
/* --------------------------------------------------------------------

View File

@ -38,7 +38,7 @@ netlist_factory_t::netlist_factory_t()
netlist_factory_t::~netlist_factory_t()
{
for (int i=0; i < m_list.size(); i++)
for (std::size_t i=0; i < m_list.size(); i++)
{
net_device_t_base_factory *p = m_list[i];
pfree(p);
@ -48,7 +48,7 @@ netlist_factory_t::~netlist_factory_t()
netlist_device_t *netlist_factory_t::new_device_by_classname(const pstring &classname) const
{
for (int i=0; i < m_list.size(); i++)
for (std::size_t i=0; i < m_list.size(); i++)
{
net_device_t_base_factory *p = m_list[i];
if (p->classname() == classname)
@ -69,7 +69,7 @@ netlist_device_t *netlist_factory_t::new_device_by_name(const pstring &name, net
net_device_t_base_factory * netlist_factory_t::factory_by_name(const pstring &name, netlist_setup_t &setup) const
{
for (int i=0; i < m_list.size(); i++)
for (std::size_t i=0; i < m_list.size(); i++)
{
net_device_t_base_factory *p = m_list[i];
if (p->name() == name)

View File

@ -228,7 +228,7 @@ void netlist_parser::device(const pstring &dev_type)
nl_util::pstring_list termlist = f->term_param_list();
nl_util::pstring_list def_params = f->def_params();
int cnt;
std::size_t cnt;
devname = get_identifier();
@ -269,7 +269,7 @@ void netlist_parser::device(const pstring &dev_type)
tok = get_token();
}
if (cnt != termlist.size())
m_setup.netlist().error("netlist: input count mismatch for %s - expected %" SIZETFMT " found %d\n", devname.cstr(), termlist.size(), cnt);
m_setup.netlist().error("netlist: input count mismatch for %s - expected %" SIZETFMT " found %" SIZETFMT "\n", devname.cstr(), termlist.size(), cnt);
require_token(tok, m_tok_param_right);
}

View File

@ -144,7 +144,7 @@ public:
void parse(netlist_setup_t &setup, const pstring name)
{
for (int i=0; i < m_list.size(); i++)
for (std::size_t i=0; i < m_list.size(); i++)
{
if (m_list[i].parse(setup, name))
return;

View File

@ -107,7 +107,7 @@ netlist_device_t *netlist_setup_t::register_dev(const pstring &classname, const
template <class T>
static void remove_start_with(T &hm, pstring &sw)
{
for (int i = hm.size() - 1; i >= 0; i--)
for (std::size_t i = hm.size() - 1; i >= 0; i--)
{
pstring x = hm[i]->name();
if (sw.equals(x.substr(0, sw.len())))
@ -248,7 +248,7 @@ void netlist_setup_t::register_object(netlist_device_t &dev, const pstring &name
{
pstring search = (".model " + val + " ").ucase();
bool found = false;
for (int i=0; i < m_models.size(); i++)
for (std::size_t i=0; i < m_models.size(); i++)
{
if (m_models[i].ucase().startsWith(search))
{
@ -289,7 +289,7 @@ void netlist_setup_t::register_link_arr(const pstring &terms)
nl_util::pstring_list list = nl_util::split(terms,", ");
if (list.size() < 2)
netlist().error("You must pass at least 2 terminals to NET_C");
for (int i = 1; i < list.size(); i++)
for (std::size_t i = 1; i < list.size(); i++)
{
register_link(list[0], list[i]);
}
@ -418,7 +418,7 @@ nld_base_proxy *netlist_setup_t::get_d_a_proxy(netlist_core_terminal_t &out)
#if 1
/* connect all existing terminals to new net */
for (int i = 0; i < out.net().m_core_terms.size(); i++)
for (std::size_t i = 0; i < out.net().m_core_terms.size(); i++)
{
netlist_core_terminal_t *p = out.net().m_core_terms[i];
p->clear_net(); // de-link from all nets ...
@ -577,7 +577,7 @@ bool netlist_setup_t::connect_input_input(netlist_core_terminal_t &t1, netlist_c
ret = connect(t2, t1.net().railterminal());
if (!ret)
{
for (int i=0; i<t1.net().m_core_terms.size(); i++)
for (std::size_t i=0; i<t1.net().m_core_terms.size(); i++)
{
if (t1.net().m_core_terms[i]->isType(netlist_core_terminal_t::TERMINAL)
/*|| t1.net().m_core_terms[i]->isType(netlist_core_terminal_t::OUTPUT)*/)
@ -595,7 +595,7 @@ bool netlist_setup_t::connect_input_input(netlist_core_terminal_t &t1, netlist_c
ret = connect(t1, t2.net().railterminal());
if (!ret)
{
for (int i=0; i<t2.net().m_core_terms.size(); i++)
for (std::size_t i=0; i<t2.net().m_core_terms.size(); i++)
{
if (t2.net().m_core_terms[i]->isType(netlist_core_terminal_t::TERMINAL)
/*|| t2.net().m_core_terms[i]->isType(netlist_core_terminal_t::OUTPUT)*/)
@ -674,7 +674,7 @@ void netlist_setup_t::resolve_inputs()
int tries = 100;
while (m_links.size() > 0 && tries > 0) // FIXME: convert into constant
{
int li = 0;
unsigned li = 0;
while (li < m_links.size())
{
const pstring t1s = m_links[li].e1;
@ -695,7 +695,7 @@ void netlist_setup_t::resolve_inputs()
}
if (tries == 0)
{
for (int i = 0; i < m_links.size(); i++ )
for (std::size_t i = 0; i < m_links.size(); i++ )
netlist().warning("Error connecting %s to %s\n", m_links[i].e1.cstr(), m_links[i].e2.cstr());
netlist().error("Error connecting -- bailing out\n");
@ -707,7 +707,7 @@ void netlist_setup_t::resolve_inputs()
netlist_net_t::list_t todelete;
for (int i = 0; i<netlist().m_nets.size(); i++)
for (std::size_t i = 0; i<netlist().m_nets.size(); i++)
{
if (netlist().m_nets[i]->num_cons() == 0)
{
@ -719,7 +719,7 @@ void netlist_setup_t::resolve_inputs()
}
}
for (int i=0; i < todelete.size(); i++)
for (std::size_t i=0; i < todelete.size(); i++)
{
netlist().log("Deleting net %s ...", todelete[i]->name().cstr());
netlist().m_nets.remove(todelete[i]);
@ -730,7 +730,7 @@ void netlist_setup_t::resolve_inputs()
pstring errstr("");
netlist().log("looking for terminals not connected ...");
for (int i = 0; i < m_terminals.size(); i++)
for (std::size_t i = 0; i < m_terminals.size(); i++)
{
if (!m_terminals[i]->has_net())
errstr += pstring::sprintf("Found terminal %s without a net\n",
@ -745,7 +745,7 @@ void netlist_setup_t::resolve_inputs()
netlist().log("looking for two terms connected to rail nets ...\n");
// FIXME: doesn't find internal devices. This needs to be more clever
for (int i=0; i < netlist().m_devices.size(); i++)
for (std::size_t i=0; i < netlist().m_devices.size(); i++)
{
NETLIB_NAME(twoterm) *t = dynamic_cast<NETLIB_NAME(twoterm) *>(netlist().m_devices[i]);
if (t != NULL)
@ -777,7 +777,7 @@ void netlist_setup_t::start_devices()
{
NL_VERBOSE_OUT(("Creating dynamic logs ...\n"));
nl_util::pstring_list ll = nl_util::split(env, ":");
for (int i=0; i < ll.size(); i++)
for (std::size_t i=0; i < ll.size(); i++)
{
NL_VERBOSE_OUT(("%d: <%s>\n",i, ll[i].cstr()));
NL_VERBOSE_OUT(("%d: <%s>\n",i, ll[i].cstr()));

View File

@ -7,6 +7,7 @@
#ifndef NLTIME_H_
#define NLTIME_H_
#include "nl_config.h"
#include "pstate.h"
//============================================================

View File

@ -56,7 +56,7 @@ public:
while (i<str.len())
{
int p = -1;
for (int j=0; j < onstrl.size(); j++)
for (std::size_t j=0; j < onstrl.size(); j++)
{
if (std::strncmp(onstrl[j].cstr(), &(str.cstr()[i]), onstrl[j].len())==0)
{

View File

@ -194,7 +194,7 @@ public:
~plist_t()
{
if (m_list != NULL)
this->dealloc(m_list, m_capacity);
this->dealloc(m_list);
m_list = NULL;
}
@ -299,14 +299,14 @@ private:
for (_ListClass *ps = m_list; ps < m_list + cnt; ps++, pd++)
*pd = *ps;
if (m_list != NULL)
this->dealloc(m_list, m_capacity);
this->dealloc(m_list);
m_list = m_new;
m_count = cnt;
}
else
{
if (m_list != NULL)
this->dealloc(m_list, m_capacity);
this->dealloc(m_list);
m_list = NULL;
m_count = 0;
}
@ -318,7 +318,7 @@ private:
return palloc_array(_ListClass, n);
}
void dealloc(_ListClass *p, std::size_t n)
void dealloc(_ListClass *p)
{
pfree_array(p);
}

View File

@ -156,7 +156,7 @@ public:
{
pstring ret;
for (int i=0; i<m_opts.size(); i++ )
for (std::size_t i=0; i<m_opts.size(); i++ )
{
poption *opt = m_opts[i];
pstring line = "";
@ -181,7 +181,7 @@ private:
poption *getopt_short(pstring arg)
{
for (int i=0; i < m_opts.size(); i++)
for (std::size_t i=0; i < m_opts.size(); i++)
{
if (m_opts[i]->m_short == arg)
return m_opts[i];
@ -190,7 +190,7 @@ private:
}
poption *getopt_long(pstring arg)
{
for (int i=0; i < m_opts.size(); i++)
for (std::size_t i=0; i < m_opts.size(); i++)
{
if (m_opts[i]->m_long == arg)
return m_opts[i];

View File

@ -227,7 +227,7 @@ void ppreprocessor::error(const pstring &err)
double ppreprocessor::expr(const nl_util::pstring_list &sexpr, int &start, int prio)
double ppreprocessor::expr(const nl_util::pstring_list &sexpr, std::size_t &start, int prio)
{
double val;
pstring tok=sexpr[start];
@ -255,14 +255,14 @@ double ppreprocessor::expr(const nl_util::pstring_list &sexpr, int &start, int p
}
else if (tok == "+")
{
if (prio >= 20)
if (prio > 10)
return val;
start++;
val = val + expr(sexpr, start, 10);
}
else if (tok == "-")
{
if (prio >= 20)
if (prio > 10)
return val;
start++;
val = val - expr(sexpr, start, 10);
@ -272,13 +272,25 @@ double ppreprocessor::expr(const nl_util::pstring_list &sexpr, int &start, int p
start++;
val = val * expr(sexpr, start, 20);
}
else if (tok == "/")
{
start++;
val = val / expr(sexpr, start, 20);
}
else if (tok == "==")
{
if (prio > 5)
return val;
start++;
val = (val == expr(sexpr, start, 5)) ? 1.0 : 0.0;
}
}
return val;
}
ppreprocessor::define_t *ppreprocessor::get_define(const pstring &name)
{
for (int i = 0; i<m_defines.size(); i++)
for (std::size_t i = 0; i<m_defines.size(); i++)
{
if (m_defines[i].m_name == name)
return &m_defines[i];
@ -290,7 +302,7 @@ pstring ppreprocessor::replace_macros(const pstring &line)
{
nl_util::pstring_list elems = nl_util::splitexpr(line, m_expr_sep);
pstringbuffer ret = "";
for (int i=0; i<elems.size(); i++)
for (std::size_t i=0; i<elems.size(); i++)
{
define_t *def = get_define(elems[i]);
if (def != NULL)
@ -301,6 +313,16 @@ pstring ppreprocessor::replace_macros(const pstring &line)
return pstring(ret.cstr());
}
static pstring catremainder(const nl_util::pstring_list &elems, std::size_t start, pstring sep)
{
pstringbuffer ret = "";
for (std::size_t i=start; i<elems.size(); i++)
{
ret.cat(elems[i]);
ret.cat(sep);
}
return pstring(ret.cstr());
}
pstring ppreprocessor::process(const pstring &contents)
{
@ -309,7 +331,7 @@ pstring ppreprocessor::process(const pstring &contents)
UINT32 ifflag = 0; // 31 if levels
int level = 0;
int i=0;
std::size_t i=0;
while (i<lines.size())
{
pstring line = lines[i];
@ -321,12 +343,24 @@ pstring ppreprocessor::process(const pstring &contents)
if (lti[0].equals("#if"))
{
level++;
int start = 0;
std::size_t start = 0;
nl_util::pstring_list t = nl_util::splitexpr(lt.substr(3).replace(" ",""), m_expr_sep);
int val = expr(t, start, 0);
if (val == 0)
ifflag |= (1 << level);
}
else if (lti[0].equals("#ifdef"))
{
level++;
if (get_define(lti[1]) == NULL)
ifflag |= (1 << level);
}
else if (lti[0].equals("#ifndef"))
{
level++;
if (get_define(lti[1]) != NULL)
ifflag |= (1 << level);
}
else if (lti[0].equals("#else"))
{
ifflag ^= (1 << level);
@ -340,6 +374,14 @@ pstring ppreprocessor::process(const pstring &contents)
{
// ignore
}
else if (lti[0].equals("#pragma"))
{
if (lti.size() > 3 && lti[1].equals("NETLIST"))
{
if (lti[2].equals("warning"))
error("NETLIST: " + catremainder(lti, 3, " "));
}
}
else if (lti[0].equals("#define"))
{
if (lti.size() != 3)
@ -347,7 +389,7 @@ pstring ppreprocessor::process(const pstring &contents)
m_defines.add(define_t(lti[1], lti[2]));
}
else
error(pstring::sprintf("unknown directive on line %d: %s\n", i, line.cstr()));
error(pstring::sprintf("unknown directive on line %" SIZETFMT ": %s\n", i, line.cstr()));
}
else
{

View File

@ -161,7 +161,7 @@ public:
protected:
double expr(const nl_util::pstring_list &sexpr, int &start, int prio);
double expr(const nl_util::pstring_list &sexpr, std::size_t &start, int prio);
define_t *get_define(const pstring &name);

View File

@ -41,12 +41,12 @@ ATTR_COLD void pstate_manager_t::remove_save_items(const void *owner)
{
pstate_entry_t::list_t todelete;
for (int i=0; i < m_save.size(); i++)
for (std::size_t i=0; i < m_save.size(); i++)
{
if (m_save[i]->m_owner == owner)
todelete.add(m_save[i]);
}
for (int i=0; i < todelete.size(); i++)
for (std::size_t i=0; i < todelete.size(); i++)
{
m_save.remove(todelete[i]);
}
@ -55,14 +55,14 @@ ATTR_COLD void pstate_manager_t::remove_save_items(const void *owner)
ATTR_COLD void pstate_manager_t::pre_save()
{
for (int i=0; i < m_save.size(); i++)
for (std::size_t i=0; i < m_save.size(); i++)
if (m_save[i]->m_dt == DT_CUSTOM)
m_save[i]->m_callback->on_pre_save();
}
ATTR_COLD void pstate_manager_t::post_load()
{
for (int i=0; i < m_save.size(); i++)
for (std::size_t i=0; i < m_save.size(); i++)
if (m_save[i]->m_dt == DT_CUSTOM)
m_save[i]->m_callback->on_post_load();
}

View File

@ -76,7 +76,7 @@ void pstring::pcopy(const char *from, int size)
pstring pstring::substr(unsigned int start, int count) const
{
pstring ret;
int alen = len();
unsigned alen = len();
if (start >= alen)
return ret;
if (count <0 || start + count > alen)