1 #include <../../nrnconf.h> 2 #if HAVE_IV // to end of file 110 static struct HocInst {
112 const char* signature;
209 static InstTable* inst_table_;
217 class PortablePointer {
220 PortablePointer(
void* address,
int type,
unsigned long size = 1);
221 virtual ~PortablePointer();
222 void set(
void* address,
int type,
unsigned long size = 1);
223 void size(
unsigned long s) { size_ =
s;}
224 unsigned long size() {
return size_;}
225 void* address() {
return address_;}
226 int type() {
return type_;}
233 PortablePointer::PortablePointer() {
238 PortablePointer::PortablePointer(
void* address,
int type,
unsigned long s) {
239 set(address,
type,
s);
241 void PortablePointer::set(
void* address,
int type,
unsigned long s) {
246 PortablePointer::~PortablePointer() {
255 virtual ~OcCheckpoint();
257 bool write(
const char*);
262 bool make_sym_table();
264 PortablePointer*
find(
void*);
269 bool sym_table_install(
Symbol*);
271 bool sym_instructions(
Symbol*);
278 bool instlist(
unsigned long,
Inst*);
286 bool xdr(
char*&,
int);
288 bool xdr(
unsigned int&);
289 bool xdr(
unsigned long&);
297 bool (OcCheckpoint::* func_)(
Symbol*);
308 virtual ~OcReadChkPnt();
341 static OcCheckpoint* cp_;
342 static OcReadChkPnt* rdckpt_;
363 return rdckpt_->get(i);
370 return rdckpt_->get(o);
383 #endif //from top of file 388 cp_ =
new OcCheckpoint();
402 f_ =
fopen(fname,
"r");
407 if (fgets(buf, 256, f_) == 0) {
408 printf(
"checkpoint read from file %s failed.\n", fname);
411 if (strcmp(buf,
"NEURON Checkpoint\n") != 0) {
415 rdckpt_ =
new OcReadChkPnt();
420 printf(
"checkpoint read from file %s failed.\n", fname);
432 OcCheckpoint::OcCheckpoint() {
439 for(i=1; hoc_inst_[
i].pi; ++
i) {
442 inst_table_ =
new InstTable(2*i);
443 for (i = 1; hoc_inst_[
i].pi; ++
i) {
444 inst_table_->insert((VPfri)hoc_inst_[i].pi, i);
449 OcCheckpoint::~OcCheckpoint() {
470 #define DEBUG if(0) fprintf 472 #define DEBUG fprintf 475 bool OcCheckpoint::write(
const char* fname) {
479 f_ =
fopen(fname,
"w");
483 fprintf(f_,
"NEURON Checkpoint\n");
485 xdrstdio_create(&xdrs_, f_, XDR_ENCODE);
487 b = make_sym_table();
488 func_ = &OcCheckpoint::sym_out;
490 func_ = &OcCheckpoint::sym_instructions;
492 i = -1; b = (b &&
xdr(i));
497 func_ = &OcCheckpoint::sym_values;
501 i = 0; b = b &&
xdr(i);
503 i = -1; b = (b &&
xdr(i));
511 bool OcCheckpoint::make_sym_table() {
515 func_ = &OcCheckpoint::sym_count;
518 printf(
"make_sym_table failed on first pass1\n");
520 DEBUG(f_,
"#symbols=%d\n", cnt_);
521 b = (b &&
xdr(cnt_));
525 stable_ =
new Symbols(2*cnt_);
527 func_ = &OcCheckpoint::sym_table_install;
529 printf(
"make_sym_table failed before second pass1\n");
533 printf(
"make_sym_table failed on second pass1\n");
539 bool OcCheckpoint::sym_count(
Symbol*
s) {
541 if (s->
type == TEMPLATE) {
547 bool OcCheckpoint::sym_table_install(
Symbol* s) {
548 stable_->insert(s, cnt_);
552 bool OcCheckpoint::sym_out(
Symbol* s) {
554 stable_->find(val, s);
556 int l1 = strlen(s->
name);
595 printf(
"failed in sym_table_install\n");
600 bool OcCheckpoint::pass1() {
603 bool OcCheckpoint::pass2() {
606 bool OcCheckpoint::build_map() {
609 PortablePointer*
find(
void*) {
614 return (this->*func_)(
s);
619 if (func_ == &OcCheckpoint::sym_out) {
624 DEBUG(f_,
"symboltable size %d\n", i);
632 printf(
"symlist failed\n");
638 bool OcCheckpoint::symbol(
Symbol* s) {
652 if (!b)
printf(
"symbol failed\n");
655 bool OcCheckpoint::sym_instructions(
Symbol* s) {
659 if (!stable_->find(val, s)) {
660 printf(
"couldn't find %s in table\n", s->
name);
664 DEBUG(f_,
"instructions for %d |%s|\n", val, s->
name);
669 printf(
"failed in sym_intructions\n");
681 bool OcCheckpoint::instlist(
unsigned long size,
Inst* in) {
682 for (
unsigned long i = 0; i < size; ++
i) {
685 if (in[i].in ==
STOP) {
686 DEBUG(f_,
" STOP\n");
689 printf(
"instlist failed 1\n");
694 if (inst_table_->find(val, (VPfri)in[i].
pf)) {
695 DEBUG(f_,
" %d\n", val);
697 printf(
"instlist failed 2\n");
700 const char* s = hoc_inst_[
val].signature;
701 for (
int j=0; s && s[
j]; ++
j) {
706 if (!stable_->find(sval, in[i].
sym)) {
707 printf(
"couldn't find |%s| in table at instruction index %ld\n",
713 printf(
"instlist failed 3\n");
717 DEBUG(f_,
" 0 SYMBOL0\n");
720 printf(
"instlist failed 4\n");
726 DEBUG(f_,
" %i\n", in[i].i);
728 printf(
"instlist failed 5\n");
735 printf(
"OcCheckpoint::instlist failed at i = %lu\n", i);
741 bool OcCheckpoint::datum(
Datum*) {
744 bool OcCheckpoint::ctemplate(
Symbol* s) {
746 if (func_ == &OcCheckpoint::sym_values) {
750 b = stable_->find(ti, s);
758 b = b && otable_->find(oid, ob);
775 objectdata_ = saveod;
781 bool OcCheckpoint::object() {
788 otable_ =
new Objects(2*nobj_ + 1);
790 func_ = &OcCheckpoint::objects;
796 bool OcCheckpoint::objects(
Symbol* s) {
798 if (s->
type == TEMPLATE) {
800 b = b && stable_->find(sid, s);
805 b = b && stable_->find(sid, t->
init);
817 otable_->insert(ob, nobj_);
846 }
else if (od && as == ao) {
854 printf(
"checkpoint of equation array vars not implemented: %s\n", s->
name);
860 for (
int i = 0; i < ao->
nsub; ++
i) {
869 bool OcCheckpoint::proc(
Proc*) {
873 bool OcCheckpoint::sym_values(
Symbol* s) {
876 stable_->find(sp, s);
881 long n = arrayinfo(s, objectdata_);
887 for (
long i = 0; i <
n; ++
i) {
889 if (s->
type == VAR) {
890 double d = od.
pval[
i];
891 DEBUG(f_,
" %g\n", d);
893 }
else if (s->
type == OBJECTVAR) {
902 stable_->find(t, ob->ctemplate->sym);
904 ob->ctemplate->sym->name);
909 b = b && otable_->find(oid, ob);
915 DEBUG(f_,
" |%s|\n", cp);
916 b = b &&
xdr(cp, strlen(cp));
925 bool OcCheckpoint::xdr(
int& i) {
926 return xdr_int(&xdrs_, &i);
928 bool OcCheckpoint::xdr(
char*& i,
int size){
929 return xdr_string(&xdrs_, &i, size);
931 bool OcCheckpoint::xdr(
short& i){
932 return xdr_short(&xdrs_, &i);
934 bool OcCheckpoint::xdr(
unsigned int& i){
935 return xdr_u_int(&xdrs_, &i);
937 bool OcCheckpoint::xdr(
unsigned long& i){
938 return xdr_u_long(&xdrs_, &i);
941 bool OcCheckpoint::xdr(
int& i) {
945 bool OcCheckpoint::xdr(
long& i) {
949 bool OcCheckpoint::xdr(
char*& s,
int){
953 bool OcCheckpoint::xdr(
short& i){
958 bool OcCheckpoint::xdr(
unsigned int& i){
963 bool OcCheckpoint::xdr(
unsigned long& i){
968 bool OcCheckpoint::xdr(
double& i){
973 bool OcCheckpoint::xdr(
Object*& o) {
976 b = otable_->find(i, o);
982 #define Chk(arg1,arg2) if (!(arg1)) { printf("%s line %d\n", arg2, lineno_); return false;} 984 #define Get(arg) if (!get(arg)) { return false; } 986 OcReadChkPnt::OcReadChkPnt() {
990 OcReadChkPnt::~OcReadChkPnt() {
1000 Chk(
symbols(),
"OcReadChkPnt::symbols() read failure");
1001 printf(
"finished with symbols at lineno = %d\n", lineno_);
1002 Chk(instructions(),
"OcReadChkPnt::instructions() read failure");
1003 printf(
"finished with instructions at lineno = %d\n", lineno_);
1004 Chk(objects(),
"OcReadChkPnt::objects() read failure");
1005 printf(
"finished with objects at lineno = %d\n", lineno_);
1008 printf(
"top_level_data not right size\n");
1011 Chk(objectdata(),
"OcReadChkPnt::objectdata() read failure");
1012 printf(
"finished with objectdata at lineno = %d\n", lineno_);
1018 psym_ =
new Symbol*[nsym_];
1019 for (
int i=0; i < nsym_; ++
i) {
1024 Chk(symtable(),
"built_in_symlist failure");
1027 if (symtable_->first !=
NULL) {
1028 printf(
"Some user symbols are already defined at the top level\n");
1031 Chk(symtable(),
"top_level_symlist failure");
1034 bool OcReadChkPnt::symtable() {
1037 for (
int i = 0; i < size; ++
i) {
1038 Chk(symbol(),
"symbol read failure");
1042 bool OcReadChkPnt::symbol() {
1048 printf(
"expected symbol id = %d but file id was %d\n",
id_,
id);
1059 if (!sym || sym->
type != type || sym->
subtype != subtype) {
1060 printf(
"%s not a built-in\n", name);
1064 sym =
hoc_install(name, (type == VAR)? UNDEF : type, 0.0, &symtable_);
1078 if (lookup_ && i != sym->
u.
oboff) {
1079 printf(
"bad u.oboff field for built-in VAR\n");
1085 arrayinfo(sym,
NULL);
1092 arrayinfo(sym,
NULL);
1099 sym->
u.
pnum =
new double;
1119 Chk(symtable(),
"");
1125 Chk(symtable(),
"");
1135 Chk(symtable(),
"");
1143 bool OcReadChkPnt::instructions() {
1144 int sid, size,
i, iid;
1146 const char* signature;
1154 printf(
"not a PROC or FUNC\n");
1161 for (i=0; i < size;) {
1163 lin[i++].
pf = hoc_inst_[iid].pi;
1164 signature = hoc_inst_[iid].signature;
1165 if (signature)
for(
const char* cp = signature; *cp; ++cp) {
1169 lin[i++].
sym = psym_[iid];
1181 bool OcReadChkPnt::objects() {
1186 pobj_ =
new Object*[nobj_ + 1];
1194 if (sym->
type != TEMPLATE) {
1195 printf(
"not a template\n");
1201 t->
init = psym_[sid];
1206 printf(
"Objects for a built-in template without checkpoint: %s\n", sym->
name);
1211 for (i=0; i <
n; ++
i) {
1217 printf(
"object indexes out of sync\n");
1232 printf(
"objects read != objects expected\n");
1237 bool OcReadChkPnt::objectdata() {
1247 }
else if (oid == -1) {
1250 od = pobj_[oid]->u.dataspace;
1258 switch (sym->
type) {
1260 n = arrayinfo(sym, od);
1264 printf(
"inconsistent array size %d %d\n", i, n);
1270 odp->
pval =
new double[
n];
1272 for (i = 0; i <
n; ++
i) {
1278 n = arrayinfo(sym, od);
1281 for (i = 0; i <
n; ++
i) {
1284 odp->
pobj[
i] = pobj_[iob];
1288 n = arrayinfo(sym, od);
1290 for (i=0; i <
n; ++
i) {
1299 for (
long j = 0; j < t->
count; ++
j) {
1310 for (
long j = 0; j < t->
count; ++
j) {
1327 for (i=0; i < nsub; ++
i) {
1358 for (
int i = 0; i < nsub; ++
i) {
1369 if (!fgets(buf, 200, f_)
1370 ||(sscanf(buf,
"%d", &i) != 1)) {
1371 printf(
"error reading integer at line %d\n", lineno_);
1380 if (!fgets(buf, 200, f_)
1381 ||(sscanf(buf,
"%lf", &i) != 1)) {
1382 printf(
"error reading double at line %d\n", lineno_);
1398 if (!fgets(s, 2048, f_)) {
1399 printf(
"error reading string at line %d\n", lineno_);
1402 s[strlen(s)-1] =
'\0';
1405 if (!fgets(buf, 256, f_)) {
1406 printf(
"error reading string at line %d\n", lineno_);
1409 buf[strlen(buf)-1] =
'\0';
1410 s =
new char[strlen(buf) + 1];
void sec_access_pop(void)
size_t hoc_total_array_data(Symbol *s, Objectdata *obd)
hoc_List * hoc_l_newlist()
void sec_access_object(void)
int hoc_resize_toplevel(int more)
#define ITERATE(itm, lst)
char * hoc_object_name(Object *ob)
Objectdata * hoc_top_level_data
#define implementList(List, T)
void forall_sectionlist(void)
void hoc_known_type(void)
void hoc_object_component()
void forall_section(void)
void sec_access_push(void)
hoc_Item * hoc_l_lappendobj(hoc_List *, struct Object *)
std::vector< Point_process * > PPList
Symbol * hoc_install(const char *, int, double, Symlist **)
void hoc_asgn_obj_to_str(void)
#define implementTable(Table, Key, Value)
#define declareTable(Table, Key, Value)
Symlist * hoc_top_level_symlist
void hoc_objvardecl(void)
void connectsection(void)
void simpleconnectsection(void)
int const size_t const size_t n
int(* checkpoint)(void **)
HocStruct hoc_Item * itm_me
void hoc_arayinstal(void)
int read(int, void *, unsigned int)
static const char * fname(const char *name)
void connectpointer(void)
void *(* constructor)(struct Object *)
int hoc_readcheckpoint(char *)
fprintf(stderr, "Don't know the location of params at %p\, pp)
static Checkpoint * instance()
double * hoc_evalpointer()
void range_interpolate(void)
Symlist * hoc_built_in_symlist
void hoc_delete_symbol(void)
struct cTemplate cTemplate
void hoc_parallel_end(void)
short cpublic
Note: public is a reserved keyword.
void hoc_parallel_begin(void)
void rangevarevalpointer(void)
void connect_point_process_pointer(void)
void hoc_object_eval(void)
HocStruct cTemplate * ctemplate
void hoc_ob_pointer(void)
Symbol * hoc_table_lookup(const char *, Symlist *)
void range_interpolate_single(void)
void hoc_object_asgn(void)
#define declareList(List, T)
int find(const int, const int, const int, const int, const int)
void(* destructor)(void *)
void * hoc_Emalloc(size_t size)