1 #include <../../nrnconf.h>
110 static struct HocInst {
112 const char* signature;
295 declareTable(InstTable, VPfri,
short)
296 implementTable(InstTable, VPfri,
short)
static InstTable* inst_table_;
298 declareTable(Symbols,
Symbol*,
int) implementTable(Symbols,
Symbol*,
int)
300 declareTable(Objects,
Object*,
int) implementTable(Objects,
Object*,
int)
302 class PortablePointer {
305 PortablePointer(
void* address,
int type,
unsigned long size = 1);
306 virtual ~PortablePointer();
307 void set(
void* address,
int type,
unsigned long size = 1);
308 void size(
unsigned long s) {
311 unsigned long size() {
327 PortablePointer::PortablePointer() {
332 PortablePointer::PortablePointer(
void* address,
int type,
unsigned long s) {
333 set(address,
type, s);
335 void PortablePointer::set(
void* address,
int type,
unsigned long s) {
340 PortablePointer::~PortablePointer() {}
348 virtual ~OcCheckpoint();
350 bool write(
const char*);
356 bool make_sym_table();
358 PortablePointer*
find(
void*);
363 bool sym_table_install(
Symbol*);
365 bool sym_instructions(
Symbol*);
372 bool instlist(
unsigned long,
Inst*);
380 bool xdr(
char*&,
int);
382 bool xdr(
unsigned int&);
383 bool xdr(
unsigned long&);
392 bool (OcCheckpoint::*func_)(
Symbol*);
403 virtual ~OcReadChkPnt();
438 static OcCheckpoint* cp_;
439 static OcReadChkPnt* rdckpt_;
458 return rdckpt_->get(
i);
465 return rdckpt_->get(
o);
482 cp_ =
new OcCheckpoint();
501 if (fgets(
buf, 256, f_) == 0) {
502 printf(
"checkpoint read from file %s failed.\n",
fname);
505 if (strcmp(
buf,
"NEURON Checkpoint\n") != 0) {
509 rdckpt_ =
new OcReadChkPnt();
514 printf(
"checkpoint read from file %s failed.\n",
fname);
526 OcCheckpoint::OcCheckpoint() {
533 for (
i = 1; hoc_inst_[
i].pi; ++
i) {
536 inst_table_ =
new InstTable(2 *
i);
537 for (
i = 1; hoc_inst_[
i].pi; ++
i) {
538 inst_table_->insert((VPfri) hoc_inst_[
i].pi,
i);
543 OcCheckpoint::~OcCheckpoint() {
568 #define DEBUG fprintf
571 bool OcCheckpoint::write(
const char*
fname) {
579 fprintf(f_,
"NEURON Checkpoint\n");
581 xdrstdio_create(&xdrs_, f_, XDR_ENCODE);
583 b = make_sym_table();
584 func_ = &OcCheckpoint::sym_out;
586 func_ = &OcCheckpoint::sym_instructions;
594 func_ = &OcCheckpoint::sym_values;
610 bool OcCheckpoint::make_sym_table() {
614 func_ = &OcCheckpoint::sym_count;
617 printf(
"make_sym_table failed on first pass1\n");
619 DEBUG(f_,
"#symbols=%d\n", cnt_);
620 b = (b &&
xdr(cnt_));
624 stable_ =
new Symbols(2 * cnt_);
626 func_ = &OcCheckpoint::sym_table_install;
628 printf(
"make_sym_table failed before second pass1\n");
632 printf(
"make_sym_table failed on second pass1\n");
638 bool OcCheckpoint::sym_count(
Symbol* s) {
640 if (s->
type == TEMPLATE) {
646 bool OcCheckpoint::sym_table_install(
Symbol* s) {
647 stable_->insert(s, cnt_);
651 bool OcCheckpoint::sym_out(
Symbol* s) {
653 stable_->find(val, s);
655 int l1 = strlen(s->
name);
672 if (!
t->constructor) {
673 b = b &&
xdr(
t->dataspace_size) &&
xdr(
t->id);
685 printf(
"failed in sym_table_install\n");
690 bool OcCheckpoint::pass1() {
693 bool OcCheckpoint::pass2() {
696 bool OcCheckpoint::build_map() {
699 PortablePointer*
find(
void*) {
704 return (this->*func_)(s);
709 if (func_ == &OcCheckpoint::sym_out) {
715 DEBUG(f_,
"symboltable size %d\n",
i);
723 printf(
"symlist failed\n");
729 bool OcCheckpoint::symbol(
Symbol* s) {
744 printf(
"symbol failed\n");
747 bool OcCheckpoint::sym_instructions(
Symbol* s) {
751 if (!stable_->find(val, s)) {
752 printf(
"couldn't find %s in table\n", s->
name);
756 DEBUG(f_,
"instructions for %d |%s|\n", val, s->
name);
757 DEBUG(f_,
"size %lu\n",
p->size);
758 bool b =
xdr(val) &&
xdr(
p->size);
760 printf(
"failed in sym_intructions\n");
763 b = instlist(
p->size,
p->defn.in);
772 bool OcCheckpoint::instlist(
unsigned long size,
Inst* in) {
773 for (
unsigned long i = 0;
i < size; ++
i) {
776 if (in[
i].in ==
STOP) {
777 DEBUG(f_,
" STOP\n");
780 printf(
"instlist failed 1\n");
785 if (inst_table_->find(val, (VPfri) in[
i].pf)) {
786 DEBUG(f_,
" %d\n", val);
788 printf(
"instlist failed 2\n");
791 const char* s = hoc_inst_[val].signature;
792 for (
int j = 0; s && s[
j]; ++
j) {
797 if (!stable_->find(sval, in[
i].sym)) {
798 printf(
"couldn't find |%s| in table at instruction index %ld\n",
805 printf(
"instlist failed 3\n");
809 DEBUG(f_,
" 0 SYMBOL0\n");
812 printf(
"instlist failed 4\n");
820 printf(
"instlist failed 5\n");
827 printf(
"OcCheckpoint::instlist failed at i = %lu\n",
i);
833 bool OcCheckpoint::datum(
Datum*) {
836 bool OcCheckpoint::ctemplate(
Symbol* s) {
838 if (func_ == &OcCheckpoint::sym_values) {
842 b = stable_->find(ti, s);
843 DEBUG(f_,
"%d %d %s\n", ti,
t->count, s->
name);
850 b = b && otable_->find(oid, ob);
852 if (
t->constructor) {
867 objectdata_ = saveod;
873 bool OcCheckpoint::object() {
880 otable_ =
new Objects(2 * nobj_ + 1);
882 func_ = &OcCheckpoint::objects;
888 bool OcCheckpoint::objects(
Symbol* s) {
890 if (s->
type == TEMPLATE) {
892 b = b && stable_->find(sid, s);
897 b = b && stable_->find(sid,
t->init);
907 otable_->insert(ob, nobj_);
933 }
else if (od && as == ao) {
941 printf(
"checkpoint of equation array vars not implemented: %s\n", s->
name);
947 for (
int i = 0;
i < ao->
nsub; ++
i) {
956 bool OcCheckpoint::proc(
Proc*) {
960 bool OcCheckpoint::sym_values(
Symbol* s) {
963 stable_->find(sp, s);
965 s->
type == SECTION) {
968 long n = arrayinfo(s, objectdata_);
974 for (
long i = 0;
i <
n; ++
i) {
976 if (s->
type == VAR) {
977 double d = od.
pval[
i];
978 DEBUG(f_,
" %g\n", d);
980 }
else if (s->
type == OBJECTVAR) {
989 stable_->find(
t, ob->ctemplate->sym);
991 ob->ctemplate->sym->name);
996 b = b && otable_->find(oid, ob);
1002 DEBUG(f_,
" |%s|\n", cp);
1003 b = b &&
xdr(cp, strlen(cp));
1012 bool OcCheckpoint::xdr(
int&
i) {
1013 return xdr_int(&xdrs_, &
i);
1015 bool OcCheckpoint::xdr(
char*&
i,
int size) {
1016 return xdr_string(&xdrs_, &
i, size);
1018 bool OcCheckpoint::xdr(
short&
i) {
1019 return xdr_short(&xdrs_, &
i);
1021 bool OcCheckpoint::xdr(
unsigned int&
i) {
1022 return xdr_u_int(&xdrs_, &
i);
1024 bool OcCheckpoint::xdr(
unsigned long&
i) {
1025 return xdr_u_long(&xdrs_, &
i);
1028 bool OcCheckpoint::xdr(
int&
i) {
1032 bool OcCheckpoint::xdr(
long&
i) {
1036 bool OcCheckpoint::xdr(
char*& s,
int) {
1040 bool OcCheckpoint::xdr(
short&
i) {
1045 bool OcCheckpoint::xdr(
unsigned int&
i) {
1050 bool OcCheckpoint::xdr(
unsigned long&
i) {
1055 bool OcCheckpoint::xdr(
double&
i) {
1060 bool OcCheckpoint::xdr(
Object*&
o) {
1063 b = otable_->find(
i,
o);
1069 #define Chk(arg1, arg2) \
1071 printf("%s line %d\n", arg2, lineno_); \
1080 OcReadChkPnt::OcReadChkPnt() {
1084 OcReadChkPnt::~OcReadChkPnt() {
1089 bool OcReadChkPnt::read() {
1094 Chk(
symbols(),
"OcReadChkPnt::symbols() read failure");
1095 printf(
"finished with symbols at lineno = %d\n", lineno_);
1096 Chk(instructions(),
"OcReadChkPnt::instructions() read failure");
1097 printf(
"finished with instructions at lineno = %d\n", lineno_);
1098 Chk(objects(),
"OcReadChkPnt::objects() read failure");
1099 printf(
"finished with objects at lineno = %d\n", lineno_);
1102 printf(
"top_level_data not right size\n");
1105 Chk(objectdata(),
"OcReadChkPnt::objectdata() read failure");
1106 printf(
"finished with objectdata at lineno = %d\n", lineno_);
1112 psym_ =
new Symbol*[nsym_];
1113 for (
int i = 0;
i < nsym_; ++
i) {
1118 Chk(symtable(),
"built_in_symlist failure");
1121 if (symtable_->first !=
NULL) {
1122 printf(
"Some user symbols are already defined at the top level\n");
1125 Chk(symtable(),
"top_level_symlist failure");
1128 bool OcReadChkPnt::symtable() {
1131 for (
int i = 0;
i < size; ++
i) {
1132 Chk(symbol(),
"symbol read failure");
1136 bool OcReadChkPnt::symbol() {
1142 printf(
"expected symbol id = %d but file id was %d\n",
id_,
id);
1174 if (lookup_ &&
i != sym->
u.
oboff) {
1175 printf(
"bad u.oboff field for built-in VAR\n");
1181 arrayinfo(sym,
NULL);
1187 arrayinfo(sym,
NULL);
1194 sym->
u.
pnum =
new double;
1207 t->dataspace_size = dsize;
1213 Chk(symtable(),
"");
1214 t->symtable = symtable_;
1218 symtable_ =
t->symtable;
1219 Chk(symtable(),
"");
1227 Chk(symtable(),
"");
1234 bool OcReadChkPnt::instructions() {
1235 int sid, size,
i, iid;
1237 const char* signature;
1245 printf(
"not a PROC or FUNC\n");
1252 for (
i = 0;
i < size;) {
1254 lin[
i++].
pf = hoc_inst_[iid].pi;
1255 signature = hoc_inst_[iid].signature;
1257 for (
const char* cp = signature; *cp; ++cp) {
1261 lin[
i++].
sym = psym_[iid];
1273 bool OcReadChkPnt::objects() {
1278 pobj_ =
new Object*[nobj_ + 1];
1286 if (sym->
type != TEMPLATE) {
1287 printf(
"not a template\n");
1293 t->init = psym_[sid];
1297 if (
t->constructor && !
t->checkpoint &&
t->count > 0) {
1298 printf(
"Objects for a built-in template without checkpoint: %s\n", sym->
name);
1303 for (
i = 0;
i <
n; ++
i) {
1309 printf(
"object indexes out of sync\n");
1315 if (
t->constructor) {
1324 printf(
"objects read != objects expected\n");
1329 bool OcReadChkPnt::objectdata() {
1339 }
else if (oid == -1) {
1342 od = pobj_[oid]->u.dataspace;
1350 switch (sym->
type) {
1352 n = arrayinfo(sym, od);
1356 printf(
"inconsistent array size %d %d\n",
i,
n);
1362 odp->
pval =
new double[
n];
1364 for (
i = 0;
i <
n; ++
i) {
1370 n = arrayinfo(sym, od);
1373 for (
i = 0;
i <
n; ++
i) {
1376 odp->
pobj[
i] = pobj_[iob];
1380 n = arrayinfo(sym, od);
1382 for (
i = 0;
i <
n; ++
i) {
1384 Get(od[sym->
u.
oboff].ppstr[
i]);
1389 if (
t->constructor) {
1390 for (
long j = 0;
j <
t->count; ++
j) {
1401 for (
long j = 0;
j <
t->count; ++
j) {
1417 for (
i = 0;
i < nsub; ++
i) {
1448 for (
int i = 0;
i < nsub; ++
i) {
1459 if (!fgets(
buf, 200, f_) || (sscanf(
buf,
"%d", &
i) != 1)) {
1460 printf(
"error reading integer at line %d\n", lineno_);
1469 if (!fgets(
buf, 200, f_) || (sscanf(
buf,
"%lf", &
i) != 1)) {
1470 printf(
"error reading double at line %d\n", lineno_);
1486 if (!fgets(s, 2048, f_)) {
1487 printf(
"error reading string at line %d\n", lineno_);
1490 s[strlen(s) - 1] =
'\0';
1493 if (!fgets(
buf, 256, f_)) {
1494 printf(
"error reading string at line %d\n", lineno_);
1497 buf[strlen(
buf) - 1] =
'\0';
1498 s =
new char[strlen(
buf) + 1];
void sec_access_pop(void)
void simpleconnectsection(void)
void range_interpolate(void)
void forall_section(void)
void connectsection(void)
void range_interpolate_single(void)
void connectpointer(void)
void sec_access_push(void)
void sec_access_object(void)
void rangevarevalpointer(void)
static Checkpoint * instance()
Symbol * hoc_table_lookup(const char *, Symlist *)
void hoc_delete_symbol(void)
void hoc_object_asgn(void)
void hoc_asgn_obj_to_str(void)
void hoc_arayinstal(void)
void hoc_parallel_end(void)
void hoc_object_eval(void)
void hoc_parallel_begin(void)
void hoc_objvardecl(void)
void hoc_ob_pointer(void)
void hoc_known_type(void)
size_t hoc_total_array_data(Symbol *s, Objectdata *obd)
Symbol * hoc_install(const char *, int, double, Symlist **)
char * hoc_object_name(Object *ob)
int hoc_resize_toplevel(int more)
struct cTemplate cTemplate
hoc_List * hoc_l_newlist()
hoc_Item * hoc_l_lappendobj(hoc_List *, struct Object *)
Symlist * hoc_top_level_symlist
Objectdata * hoc_top_level_data
Symlist * hoc_built_in_symlist
#define declareList(List, T)
implementList(__AnyPtrList, __AnyPtr) static long ListImpl_best_new_sizes[]
#define ITERATE(itm, lst)
int const size_t const size_t n
void * hoc_Emalloc(size_t size)
double * hoc_evalpointer()
void hoc_object_component()
int hoc_readcheckpoint(char *)
std::vector< Point_process * > PPList
void connect_point_process_pointer(void)
int find(const int, const int, const int, const int, const int)
void forall_sectionlist(void)
HocStruct hoc_Item * itm_me
short cpublic
Note: public is a reserved keyword.
HocStruct cTemplate * ctemplate
static const char * fname(const char *name)