:- use_module(library(lineutils), [file_filter_with_init/5, split/3, glue/3]). :- use_module(library(lists), [append/2, append/3]). :- initialization(main). :- dynamic globals/1. :- yap_flag(write_strings,on). :- style_check(all). main :- warning(Warning), file_filter_with_init('misc/HEAPFIELDS','H/hstruct.h',gen_struct,Warning,['hstruct.h','HEAPFIELDS']), file_filter_with_init('misc/HEAPFIELDS','H/dhstruct.h',gen_dstruct,Warning,['dhstruct.h','HEAPFIELDS']), file_filter_with_init('misc/HEAPFIELDS','H/rhstruct.h',gen_hstruct,Warning,['rhstruct.h','HEAPFIELDS']), file_filter_with_init('misc/HEAPFIELDS','H/ihstruct.h',gen_init,Warning,['ihstruct.h','HEAPFIELDS']), file_filter_with_init('misc/GLOBALS','H/hglobals.h',gen_struct,Warning,['hglobals.h','GLOBALS']), file_filter_with_init('misc/GLOBALS','H/dglobals.h',gen_dstruct,Warning,['dglobals.h','GLOBALS']), file_filter_with_init('misc/GLOBALS','H/rglobals.h',gen_hstruct,Warning,['rglobals.h','GLOBALS']), file_filter_with_init('misc/GLOBALS','H/iglobals.h',gen_init,Warning,['iglobals.h','GLOBALS']), file_filter_with_init('misc/LOCALS','H/hlocals.h',gen_struct,Warning,['hlocals.h','LOCALS']), file_filter_with_init('misc/LOCALS','H/dlocals.h',gen_dstruct,Warning,['dlocals.h','LOCALS']), file_filter_with_init('misc/LOCALS','H/rlocals.h',gen_hstruct,Warning,['rlocals.h','LOCALS']), file_filter_with_init('misc/LOCALS','H/ilocals.h',gen_init,Warning,['ilocals.h','LOCALS']). warning('~n /* This file, ~a, was generated automatically by \"yap -L misc/buildheap\"~n please do not update, update misc/~a instead */~n~n'). /* define the field */ gen_struct(Inp,"") :- Inp = [0'/,0'/|_], !. gen_struct(Inp,"") :- Inp = [0'/,0'*|_], !. gen_struct(Inp, Out) :- Inp = [0'#|_], !, Out = Inp. % ' gen_struct(Inp,"") :- Inp = [0'.|_], !. %' gen_struct(Inp,Out) :- Inp = "START_WORKER_LOCAL", !, Out = "typedef struct worker_local {". gen_struct(Inp,Out) :- Inp = "END_WORKER_LOCAL", !, Out = "} w_local;". gen_struct(Inp,Out) :- Inp = "START_WORKER_SHARED", !, Out = "typedef struct worker_shared {". gen_struct(Inp,Out) :- Inp = "END_WORKER_SHARED", !, Out = "} w_shared;". gen_struct(Inp,Out) :- Inp = "ATOMS", !, Out = "#include \"tatoms.h\"". gen_struct(Inp,Out) :- split(Inp," ",["struct",Type, Field|_]), !, append([" struct ",Type," ",Field,";"], Out). gen_struct(Inp,Out) :- split(Inp," ",["union",Type, Field|_]), !, append([" union ",Type," ",Field,";"], Out). gen_struct(Inp,"") :- split(Inp," ",["void","void"|_]), !. gen_struct(Inp,Out) :- split(Inp," ",[Type, Field|_]), !, append([" ",Type," ",Field,";"], Out). gen_struct(Inp,_) :- split(Inp," ",[_, _, _| _]), format(user_error,"OOPS: could not gen_struct for ~s~n",[Inp]). gen_dstruct(Inp,"") :- Inp = [0'/,0'/|_], !. gen_dstruct(Inp,"") :- Inp = [0'/,0'*|_], !. gen_dstruct(Inp, Out) :- Inp = [0'#|_], !, Out = Inp. % ' gen_dstruct(Inp,"") :- Inp = "START_WORKER_LOCAL", !, assert(globals(worker)). gen_dstruct(Inp,"") :- Inp = "END_WORKER_LOCAL", !, retract(globals(worker)). gen_dstruct(Inp,"") :- Inp = "START_WORKER_SHARED", !, assert(globals(all)). gen_dstruct(Inp,"") :- Inp = "END_WORKER_SHARED", !, retract(globals(all)). gen_dstruct(Inp,Out) :- Inp = "ATOMS", !, Out = "". gen_dstruct(Inp,"") :- split(Inp," ",["void","void"|_]), !. gen_dstruct(Inp,Out) :- split(Inp," ",["struct"|Inp2]), !, glue(Inp2, " ", Inp3), gen_dstruct(Inp3, Out). gen_dstruct(Inp,Out) :- split(Inp," ",["union"|Inp2]), !, glue(Inp2, " ", Inp3), gen_dstruct(Inp3, Out). gen_dstruct(Inp,Out) :- split(Inp," ",[_, Field, Name|_]), !, cut_c_stuff(Field, RField), fetch_name(Global), append(["#define ",Name," ",Global,RField], Out). gen_dstruct(Inp,_) :- split(Inp," ",[_, _, _| _]), format(user_error,"OOPS: could not gen_dstruct for ~s~n",[Inp]). fetch_name(Global) :- globals(all), !, Global = "Yap_global->". fetch_name(Global) :- globals(worker), !, Global = "WL->". fetch_name(Global) :- globals(worker_init), !, Global = "FOREIGN(wid)->". fetch_name(Global) :- Global = "Yap_heap_regs->". % handle *field[4] cut_c_stuff([0'*|Name], RName) :- !, % 'cut * cut_c_stuff(Name, RName). cut_c_stuff(Name, RName) :- cut_mat(Name, RName). cut_mat([], []). cut_mat([0'[|_], []) :- !. %' cut_mat(H.Name, H.RName) :- cut_mat(Name, RName). gen_hstruct(Inp,"") :- Inp = [0'/,0'/|_], !. gen_hstruct(Inp,"") :- Inp = [0'.|_], !. %' gen_hstruct(Inp,"") :- Inp = [0'/,0'*|_], !. gen_hstruct(Inp,Out) :- Inp = "ATOMS", !, Out = "#include \"ratoms.h\"". gen_hstruct(Inp,Out) :- Inp = "START_WORKER_LOCAL", !, Out = "static void RestoreWorker(int wid USES_REGS) {", assert(globals(worker_init)). gen_hstruct(Inp,Out) :- Inp = "END_WORKER_LOCAL", !, Out = "}", retract(globals(worker_init)). gen_hstruct(Inp,Out) :- Inp = "START_WORKER_SHARED", !, Out = "static void RestoreGlobal(void) {", assert(globals(all)). gen_hstruct(Inp,Out) :- Inp = "END_WORKER_SHARED", !, Out = "}", retract(globals(all)). gen_hstruct(Inp, Out) :- Inp = [0'#|_], !, Out = Inp. % ' gen_hstruct(Inp,Out) :- split(Inp," ",["struct"|Inp2]), !, glue(Inp2, " ", Inp3), gen_hstruct(Inp3,Out). gen_hstruct(Inp,Out) :- split(Inp," ",["union"|Inp2]), !, glue(Inp2, " ", Inp3), gen_hstruct(Inp3,Out). gen_hstruct(Inp,Out) :- split(Inp," ",[_, Field, _, "MkAT", _]), !, fetch_name(Global), append([" ",Global,Field," = AtomTermAdjust(Yap_heap_regs->",Field,");"], Out). gen_hstruct(Inp,Out) :- split(Inp," ",[_, Field, _, "MkPred"| _]), !, cut_c_stuff(Field, RField), fetch_name(Global), append([" ",Global,RField," = PtoPredAdjust(Yap_heap_regs->",RField,");"], Out). gen_hstruct(Inp,Out) :- split(Inp," ",[_, Field, _, "MkOp", Name]), !, fetch_name(Global), append([" ",Global,Field," = Yap_opcode(",Name,");"], Out). gen_hstruct(Inp,Out) :- split(Inp," ",[_, Field, _, "MkLock"]), !, fetch_name(Global), append([" REINIT_LOCK(",Global,Field,");"], Out). gen_hstruct(Inp,Out) :- split(Inp," ",[_, Field, _, "MkRWLock"]), !, fetch_name(Global), append([" REINIT_RWLOCK(",Global,Field,");"], Out). gen_hstruct(Inp,Out) :- split(Inp," ",[_, Field, _, "MkInstE",OP]), !, cut_c_stuff(Field, RField), fetch_name(Global), append([" ",Global,RField,"->opc = Yap_opcode(",OP,");"], Out). gen_hstruct(Inp,"") :- split(Inp," ",[_, _, _, _]), !. gen_hstruct(Inp,"") :- split(Inp," ",[_, _, _, _, "void"]), !. gen_hstruct(Inp,Restore) :- split(Inp," ",[_, _, _, _, Restore0]), append("Restore",_,Restore0), !, append([" ",Restore0,";"],Restore). %' gen_hstruct(Inp,Out) :- split(Inp," ",[_, Field, _, _, Adjust]), append(Adjust,"Adjust",_), !, cut_c_stuff(Field, RField), fetch_name(Global), append([" ",Global,RField," = ",Adjust,"(",Global,RField,");"], Out). gen_hstruct(Inp,_) :- split(Inp," ",[_, _, _| _]), format(user_error,"OOPS: could not gen_hstruct for ~s~n",[Inp]). gen_init(Inp,"") :- Inp = [0'/,0'*|_], !. gen_init(Inp,"") :- Inp = [0'/,0'/|_], !. gen_init(Inp, Out) :- Inp = [0'#|_], !, Out = Inp. % ' gen_init(Inp,Out) :- Inp = "ATOMS", !, Out = "#include \"iatoms.h\"". gen_init(Inp,Out) :- Inp = "START_WORKER_LOCAL", !, Out = "static void InitWorker(int wid) {", assert(globals(worker_init)). gen_init(Inp,Out) :- Inp = "END_WORKER_LOCAL", !, Out = "}", retract(globals(worker_init)). gen_init(Inp,Out) :- Inp = "START_WORKER_SHARED", !, Out = "static void InitGlobal(void) {", assert(globals(all)). gen_init(Inp,Out) :- Inp = "END_WORKER_SHARED", !, Out = "}", retract(globals(all)). gen_init(Inp,Out) :- split(Inp," ",["struct"|Inp2]), !, glue(Inp2, " ", Inp3), gen_init(Inp3, Out). gen_init(Inp,Out) :- split(Inp," ",["union"|Inp2]), !, glue(Inp2, " ", Inp3), gen_init(Inp3, Out). gen_init(Inp,"") :- split(Inp," ",[_, _, _, "void"|_]), !. gen_init(Inp,Init) :- split(Inp," ",[_, _, _, Init0| _]), append("Init",_,Init0), !, append([" ",Init0,";"],Init). gen_init(Inp,Init) :- split(Inp," ",[_, _, _, Init0| _]), append("Yap_Init",_,Init0), !, append([" ",Init0,";"],Init). gen_init(Inp,Out) :- split(Inp," ",[_, Field, _, "MkAT", AtomName]), !, cut_c_stuff(Field, RField), fetch_name(Global), append([" ",Global,RField," = MkAtomTerm(",AtomName,");"], Out). gen_init(Inp,Out) :- split(Inp," ",[_, Field, _, "MkOp", Name]), !, fetch_name(Global), append([" ",Global,Field," = Yap_opcode(",Name,");"], Out). gen_init(Inp,Out) :- split(Inp," ",[_, Field, _, "MkLock"]), !, fetch_name(Global), append([" INIT_LOCK(",Global,Field,");"], Out). gen_init(Inp,Out) :- split(Inp," ",[_, Field, _, "MkRWLock"]), !, fetch_name(Global), append([" INIT_RWLOCK(",Global,Field,");"], Out). gen_init(Inp,Out) :- split(Inp," ",[_, Field, _, "MkInstE",OP]), !, cut_c_stuff(Field, RField), fetch_name(Global), append([" ",Global,RField,"->opc = Yap_opcode(",OP,");"], Out). gen_init(Inp,Out) :- split(Inp," ",[_, Field, _, "MkPred", Atom, "0", Module]), !, cut_c_stuff(Field, RField), fetch_name(Global), append([" ",Global,RField," = RepPredProp(PredPropByAtom(",Atom,",",Module,"));"], Out). gen_init(Inp,Out) :- split(Inp," ",[_, Field, _, "MkPred", Atom, Arity, Module]), !, cut_c_stuff(Field, RField), fetch_name(Global), append([" ",Global,RField," = RepPredProp(PredPropByFunc(Yap_MkFunctor(",Atom,",",Arity,"),",Module,"));"], Out). gen_init(Inp,Out) :- split(Inp," ",[_, Field, _, "MkPred", Fun, Module]), !, cut_c_stuff(Field, RField), fetch_name(Global), append([" ",Global,RField," = RepPredProp(PredPropByFunc(",Fun,",",Module,"));"], Out). gen_init(Inp,Out) :- split(Inp," ",[_, Field, _, F0|_]), append("=",F,F0), !, cut_c_stuff(Field, RField), fetch_name(Global), append([" ",Global,RField," = ",F,";"], Out). gen_init(Inp,_) :- split(Inp," ",[_, _, _| _]), format(user_error,"OOPS: could not gen_init for ~s~n",[Inp]).