LOCALS and GLOBALS are now generated by misc/buildlocalglobal.

This commit is contained in:
Joao
2011-05-11 18:22:58 +01:00
parent d6fc76faf1
commit ab63cd190b
17 changed files with 1051 additions and 714 deletions

View File

@@ -7,10 +7,9 @@
// - they must be initialised somewhere
// - they may be of interest to restore
//
// The defs include 4+ components:
// The defs include 3+ components:
// Type
// name in structured
// global name
// name in structured / global name
// init code (optional)
// restore code (optional)
//
@@ -19,47 +18,43 @@
START_GLOBAL_DATA
// initialization: tell whether the system has been initialised and by whom.
int initialised GLOBAL_Initialised =FALSE
int initialised_from_pl GLOBAL_InitialisedFromPL =FALSE
int pl_argc GLOBAL_PL_Argc =0
char **pl_argv GLOBAL_PL_Argv =NULL
int Initialised =FALSE
int InitialisedFromPL =FALSE
int PL_Argc =0
char** PL_Argv =NULL
// halt hooks
struct halt_hook *yap_halt_hook GLOBAL_HaltHooks =NULL
struct halt_hook* HaltHooks =NULL
// stack overflow expansion/gc control
int allow_local_expansion GLOBAL_AllowLocalExpansion =TRUE
int allow_global_expansion GLOBAL_AllowGlobalExpansion =TRUE
int allow_trail_expansion GLOBAL_AllowTrailExpansion =TRUE
UInt size_of_overflow GLOBAL_SizeOfOverflow =0
int AllowLocalExpansion =TRUE
int AllowGlobalExpansion =TRUE
int AllowTrailExpansion =TRUE
UInt SizeOfOverflow =0
// amount of space recovered in all garbage collections
UInt agc_threshold GLOBAL_AGcThreshold =10000
Agc_hook agc_hook GLOBAL_AGCHook =NULL
UInt AGcThreshold =10000
Agc_hook AGCHook =NULL
/* multi-thread support */
#if THREADS
/* number of threads and processes in system */
UInt n_of_threads GLOBAL_NOfThreads =1
UInt NOfThreads =1
/* number of threads created since start */
UInt n_of_threads_created GLOBAL_NOfThreadsCreated =1
UInt NOfThreadsCreated =1
/* total run time for dead threads */
UInt threads_total_time GLOBAL_ThreadsTotalTime =0L
UInt ThreadsTotalTime =0L
// Threads Array
lockvar ThreadHandlesLock MkLock
#endif
// multi-thread/ORP support
#if defined(YAPOR) || defined(THREADS)
// protect long critical regions
lockvar bgl GLOBAL_BGL MkLock
lockvar BGL MkLock
#endif
// Threads Array
#ifdef THREADS
lockvar thread_handles_lock GLOBAL_ThreadHandlesLock MkLock
#endif
#if defined(YAPOR) || defined(TABLING)
struct global_optyap_data optyap_data Yap_optyap_data void
struct global_optyap_data optyap_data void
#endif /* YAPOR || TABLING */
END_GLOBAL_DATA

View File

@@ -2,159 +2,148 @@
START_WORKER_LOCAL
// Streams
int c_input_stream LOCAL_c_input_stream =0
int c_output_stream LOCAL_c_output_stream =1
int c_error_stream LOCAL_c_error_stream =2
int c_input_stream =0
int c_output_stream =1
int c_error_stream =2
/* shifts and restore: per local data-structure */
restoreinfo rinfo
. rinfo.old_ASP LOCAL_OldASP =NULL
. rinfo.old_LCL0 LOCAL_OldLCL0 =NULL
. rinfo.old_TR LOCAL_OldTR =NULL
. rinfo.old_GlobalBase LOCAL_OldGlobalBase =NULL
. rinfo.old_H LOCAL_OldH =NULL
. rinfo.old_H0 LOCAL_OldH0 =NULL
. rinfo.old_TrailBase LOCAL_OldTrailBase =NULL
. rinfo.old_TrailTop LOCAL_OldTrailTop =NULL
. rinfo.old_HeapBase LOCAL_OldHeapBase =NULL
. rinfo.old_HeapTop LOCAL_OldHeapTop =NULL
. rinfo.cl_diff LOCAL_ClDiff =0L
. rinfo.g_diff LOCAL_GDiff =0L
. rinfo.h_diff LOCAL_HDiff =0L
. rinfo.g_diff0 LOCAL_GDiff0 =0L
. rinfo.g_split LOCAL_GSplit =NULL
. rinfo.l_diff LOCAL_LDiff =0L
. rinfo.tr_diff LOCAL_TrDiff =0L
. rinfo.x_diff LOCAL_XDiff =0L
. rinfo.delay_diff LOCAL_DelayDiff =0L
. rinfo.base_diff LOCAL_BaseDiff =0L
// Restore info
CELL* OldASP =NULL
CELL* OldLCL0 =NULL
tr_fr_ptr OldTR =NULL
CELL* OldGlobalBase =NULL
CELL* OldH =NULL
CELL* OldH0 =NULL
ADDR OldTrailBase =NULL
ADDR OldTrailTop =NULL
ADDR OldHeapBase =NULL
ADDR OldHeapTop =NULL
Int ClDiff =0L
Int GDiff =0L
Int HDiff =0L
Int GDiff0 =0L
Int GSplit =NULL
Int LDiff =0L
Int TrDiff =0L
Int XDiff =0L
Int DelayDiff =0L
Int BaseDiff =0L
struct reduction_counters call_counters
. call_counters.reductions LOCAL_ReductionsCounter =0L
. call_counters.reductions_retries LOCAL_PredEntriesCounter =0L
. call_counters.retries LOCAL_RetriesCounter =0L
. call_counters.reductions_on LOCAL_ReductionsCounterOn =0L
. call_counters.reductions_retries_on LOCAL_PredEntriesCounterOn =0L
. call_counters.retries_on LOCAL_RetriesCounterOn =0L
int interrupts_disabled LOCAL_InterruptsDisabled =FALSE
// Reduction counters
YAP_ULONG_LONG ReductionsCounter =0L
YAP_ULONG_LONG PredEntriesCounter =0L
YAP_ULONG_LONG RetriesCounter =0L
int ReductionsCounterOn =0L
int PredEntriesCounterOn =0L
int RetriesCounterOn =0L
// support for consulting files
/* current consult stack */
union CONSULT_OBJ* consultsp LOCAL_ConsultSp =NULL
union CONSULT_OBJ* ConsultSp =NULL
/* current maximum number of cells in consult stack */
UInt consultcapacity LOCAL_ConsultCapacity void
UInt ConsultCapacity void
/* top of consult stack */
union CONSULT_OBJ* consultbase LOCAL_ConsultBase =NULL
union CONSULT_OBJ* ConsultBase =NULL
/* low-water mark for consult */
union CONSULT_OBJ* consultlow LOCAL_ConsultLow =NULL
union CONSULT_OBJ* ConsultLow =NULL
//global variables
Term global_arena LOCAL_GlobalArena =0L TermToGlobalOrAtomAdjust
UInt global_arena_overflows LOCAL_GlobalArenaOverflows =0L
Int arena_overflows LOCAL_ArenaOverflows =0L
Int depth_arenas LOCAL_DepthArenas =0
Term GlobalArena =0L TermToGlobalOrAtomAdjust
UInt GlobalArenaOverflows =0L
Int ArenaOverflows =0L
Int DepthArenas =0
int arith_error LOCAL_ArithError =FALSE
struct pred_entry* last_asserted_pred LOCAL_LastAssertedPred =NULL
int debug_on LOCAL_DebugOn =FALSE
char* scanner_stack LOCAL_ScannerStack =NULL
struct scanner_extra_alloc* scanner_extra_blocks LOCAL_ScannerExtraBlocks =NULL
struct DB_TERM* ball_term LOCAL_BallTerm =NULL RestoreBallTerm(wid)
UInt active_signals LOCAL_ActiveSignals =0L
UInt i_pred_arity LOCAL_IPredArity =0L
yamop* prof_end LOCAL_ProfEnd =NULL
int uncaught_throw LOCAL_UncaughtThrow =FALSE
int doing_undefp LOCAL_DoingUndefp =FALSE
Int start_line LOCAL_StartLine =0L
scratch_block scratchpad LOCAL_ScratchPad InitScratchPad(wid)
int ArithError =FALSE
struct pred_entry* LastAssertedPred =NULL
int DebugOn =FALSE
char* ScannerStack =NULL
struct scanner_extra_alloc* ScannerExtraBlocks =NULL
struct DB_TERM* BallTerm =NULL RestoreBallTerm(wid)
UInt ActiveSignals =0L
UInt IPredArity =0L
yamop* ProfEnd =NULL
int UncaughtThrow =FALSE
int DoingUndefp =FALSE
Int StartLine =0L
scratch_block ScratchPad InitScratchPad(wid)
#ifdef COROUTINING
Term woken_goals LOCAL_WokenGoals =0L TermToGlobalAdjust
Term atts_mutable_list LOCAL_AttsMutableList =0L TermToGlobalAdjust
Term WokenGoals =0L TermToGlobalAdjust
Term AttsMutableList =0L TermToGlobalAdjust
#endif
// gc_stuff
Term gc_generation LOCAL_GcGeneration =0L TermToGlobalAdjust
Term gc_phase LOCAL_GcPhase =0L TermToGlobalAdjust
UInt gc_current_phase LOCAL_GcCurrentPhase =0L
UInt gc_calls LOCAL_GcCalls =0L
Int tot_gc_time LOCAL_TotGcTime =0L
YAP_ULONG_LONG tot_gc_recovered LOCAL_TotGcRecovered =0L
Int last_gc_time LOCAL_LastGcTime =0L
Int last_ss_time LOCAL_LastSSTime =0L
Term GcGeneration =0L TermToGlobalAdjust
Term GcPhase =0L TermToGlobalAdjust
UInt GcCurrentPhase =0L
UInt GcCalls =0L
Int TotGcTime =0L
YAP_ULONG_LONG TotGcRecovered =0L
Int LastGcTime =0L
Int LastSSTime =0L
#if LOW_LEVEL_TRACER
Int total_cps LOCAL_total_choicepoints =0
#endif
int consult_level_ LOCAL_consult_level =0
#if defined(YAPOR) || defined(THREADS)
lockvar signal_lock LOCAL_SignalLock MkLock
#endif
/* in a single gc */
Int tot_marked LOCAL_total_marked =0L
Int tot_oldies LOCAL_total_oldies =0L
struct choicept* wl_current_B LOCAL_current_B =NULL
CELL* wl_prev_HB LOCAL_prev_HB =NULL
CELL* hgen LOCAL_HGEN =NULL
CELL** ip_top LOCAL_iptop =NULL
//#endif
Int total_marked =0L
Int total_oldies =0L
struct choicept* current_B =NULL
CELL* prev_HB =NULL
CELL* HGEN =NULL
CELL** iptop =NULL
#if defined(GC_NO_TAGS)
char* b_p LOCAL_bp =NULL
char* bp =NULL
#endif
tr_fr_ptr wl_sTR LOCAL_sTR =NULL
tr_fr_ptr wl_sTR0 LOCAL_sTR0 =NULL
tr_fr_ptr new_tr LOCAL_new_TR =NULL
struct gc_mark_continuation* conttop0 LOCAL_cont_top0 =NULL
struct gc_mark_continuation* conttop LOCAL_cont_top =NULL
int disc_trail_entries LOCAL_discard_trail_entries =0
gc_ma_hash_entry Gc_ma_hash_table[GC_MAVARS_HASH_SIZE] LOCAL_gc_ma_hash_table void
gc_ma_hash_entry* Gc_ma_h_top LOCAL_gc_ma_h_top =NULL
gc_ma_hash_entry* Gc_ma_h_list LOCAL_gc_ma_h_list =NULL
UInt Gc_timestamp LOCAL_gc_timestamp =0L
ADDR DB_vec LOCAL_db_vec =NULL
ADDR DB_vec0 LOCAL_db_vec0 =NULL
struct RB_red_blk_node* DB_root LOCAL_db_root =NULL
struct RB_red_blk_node* DB_nil LOCAL_db_nil =NULL
tr_fr_ptr sTR =NULL
tr_fr_ptr sTR0 =NULL
tr_fr_ptr new_TR =NULL
struct gc_mark_continuation* cont_top0 =NULL
struct gc_mark_continuation* cont_top =NULL
int discard_trail_entries =0
gc_ma_hash_entry gc_ma_hash_table[GC_MAVARS_HASH_SIZE] void
gc_ma_hash_entry* gc_ma_h_top =NULL
gc_ma_hash_entry* gc_ma_h_list =NULL
UInt gc_timestamp =0L
ADDR db_vec =NULL
ADDR db_vec0 =NULL
struct RB_red_blk_node* db_root =NULL
struct RB_red_blk_node* db_nil =NULL
sigjmp_buf gc_restore LOCAL_gc_restore void
struct array_entry* dynamic_arrays LOCAL_DynamicArrays =NULL PtoArrayEAdjust
struct static_array_entry* static_arrays LOCAL_StaticArrays =NULL PtoArraySAdjust
struct global_entry* global_variables LOCAL_GlobalVariables =NULL PtoGlobalEAdjust
int allow_restart LOCAL_AllowRestart =FALSE
sigjmp_buf gc_restore void
struct array_entry* DynamicArrays =NULL PtoArrayEAdjust
struct static_array_entry* StaticArrays =NULL PtoArraySAdjust
struct global_entry* GlobalVariables =NULL PtoGlobalEAdjust
int AllowRestart =FALSE
// Thread Local Area for Fast Storage of Intermediate Compiled Code.
struct mem_blk* cmem_first_block LOCAL_CMemFirstBlock =NULL
UInt cmem_first_block_sz LOCAL_CMemFirstBlockSz =0L
// Thread Local Area for Fast Storage of Intermediate Compiled Code
struct mem_blk* CMemFirstBlock =NULL
UInt CMemFirstBlockSz =0L
// Thread Local Area for Labels.
Int* label_first_array LOCAL_LabelFirstArray =NULL
UInt label_first_array_sz LOCAL_LabelFirstArraySz =0L
// Thread Local Area for Labels
Int* LabelFirstArray =NULL
UInt LabelFirstArraySz =0L
// Thread Local Area for SWI-Prolog emulation routines.
struct PL_local_data* Yap_ld_ LOCAL_PL_local_data_p =Yap_InitThreadIO(wid)
struct open_query_struct* _execution LOCAL_execution =NULL
struct PL_local_data* PL_local_data_p =Yap_InitThreadIO(wid)
#ifdef THREADS
struct thandle thread_handle LOCAL_ThreadHandle InitThreadHandle(wid)
struct thandle ThreadHandle InitThreadHandle(wid)
#endif /* THREADS */
#if defined(YAPOR) || defined(TABLING)
struct local_optyap_data optyap_data LOCAL_optyap_data Yap_init_local_optyap_data(wid)
struct local_optyap_data optyap_data Yap_init_local_optyap_data(wid)
#endif /* YAPOR || TABLING */
int InterruptsDisabled =FALSE
// defines
#define REMOTE_ThreadHandle(wid) (REMOTE(wid)->thread_handle)
#define REMOTE_c_input_stream(wid) (REMOTE(wid)->c_input_stream)
#define REMOTE_c_output_stream(wid) (REMOTE(wid)->c_output_stream)
#define REMOTE_c_error_stream(wid) (REMOTE(wid)->c_error_stream)
#define REMOTE_ActiveSignals(wid) (REMOTE(wid)->active_signals)
#define REMOTE_SignalLock(wid) (REMOTE(wid)->signal_lock)
#define REMOTE_ScratchPad(wid) (REMOTE(wid)->scratchpad)
struct open_query_struct* execution =NULL
#if LOW_LEVEL_TRACER
Int total_choicepoints =0
#endif
int consult_level =0
#if defined(YAPOR) || defined(THREADS)
lockvar SignalLock MkLock
#endif
// END WORKER LOCAL STUFF
END_WORKER_LOCAL

View File

@@ -21,15 +21,15 @@ main :-
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']).
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').

345
misc/buildlocalglobal Normal file
View File

@@ -0,0 +1,345 @@
:- 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/buildlocalglobal\"~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_GLOBAL_DATA", !,
Out = "typedef struct global_data {".
gen_struct(Inp,Out) :-
Inp = "END_GLOBAL_DATA", !,
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|_]),
split(Field,"[",[RField,VECField]), !,
append([" ",Type," ",RField,"_","[",VECField,";"], Out).
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_GLOBAL_DATA", !,
assert(globals(all)).
gen_dstruct(Inp,"") :-
Inp = "END_GLOBAL_DATA", !,
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,_|_]), !,
cut_c_stuff(Field, RField),
split(RField,".",[_,MField]),
fetch_name(Global,Global2,RField,MField),
append(["#define ",Global," ",Global2], Out).
gen_dstruct(Inp,Out) :-
split(Inp," ",[_, Field,_|_]), !,
cut_c_stuff(Field, RField),
fetch_name(Global,Global2,RField," "),
append(["#define ",Global," ",Global2], Out).
gen_dstruct(Inp,_) :-
split(Inp," ",[_, _, _| _]),
format(user_error,"OOPS: could not gen_dstruct for ~s~n",[Inp]).
fetch_name(Global,Global2,RField," ") :-
globals(all), !,
append(["GLOBAL_", RField],Global),
append(["Yap_global->", RField,"_"],Global2).
fetch_name(Global,Global2,RField," ") :-
globals(worker),
append(["LOCAL_", RField],Global),
append(["LOCAL->", RField,"_"],Global2).
fetch_name(Global,Global2,RField," ") :-
globals(worker), !,
append(["REMOTE_", RField,"(wid)"],Global),
append(["REMOTE(wid)->", RField,"_"],Global2).
fetch_name(Global,Global2,RField,MField) :-
globals(worker),
append(["REMOTE_", MField,"(wid)"],Global),
append(["REMOTE(wid)->", RField],Global2).
fetch_name(Global,Global2,RField,MField) :-
globals(worker),!,
append(["LOCAL_", MField],Global),
append(["LOCAL->", RField],Global2).
fetch_name(Global, RField) :-
globals(worker_init), !,
append(["REMOTE_", RField,"(wid)"],Global).
fetch_name(Global, RField) :-
globals(all), !,
append(["GLOBAL_", RField],Global).
% 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_GLOBAL_DATA", !,
Out = "static void RestoreGlobal(void) {",
assert(globals(all)).
gen_hstruct(Inp,Out) :-
Inp = "END_GLOBAL_DATA", !,
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,Field),
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,RField),
append([" ",Global,RField," = PtoPredAdjust(Yap_heap_regs->",RField,");"], Out).
gen_hstruct(Inp,Out) :-
split(Inp," ",[_, Field, "MkOp", Name]), !,
fetch_name(Global,Field),
append([" ",Global,Field," = Yap_opcode(",Name,");"], Out).
gen_hstruct(Inp,Out) :-
split(Inp," ",[_, Field, "MkLock"]), !,
fetch_name(Global,Field),
append([" REINIT_LOCK(",Global,");"], Out).
gen_hstruct(Inp,Out) :-
split(Inp," ",[_, Field,"MkRWLock"]), !,
fetch_name(Global,Field),
append([" REINIT_RWLOCK(",Global,Field,");"], Out).
gen_hstruct(Inp,Out) :-
split(Inp," ",[_, Field,"MkInstE",OP]), !,
cut_c_stuff(Field, RField),
fetch_name(Global,RField),
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,RField),
append([" ",Global," = ",Adjust,"(",Global,");"], 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_GLOBAL_DATA", !,
Out = "static void InitGlobal(void) {",
assert(globals(all)).
gen_init(Inp,Out) :-
Inp = "END_GLOBAL_DATA", !,
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,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,RField),
append([" ",Global," = MkAtomTerm(",AtomName,");"], Out).
gen_init(Inp,Out) :-
split(Inp," ",[_, Field, "MkOp", Name]), !,
fetch_name(Global,Field),
append([" ",Global," = Yap_opcode(",Name,");"], Out).
gen_init(Inp,Out) :-
split(Inp," ",[_, Field, "MkLock"]), !,
fetch_name(Global,Field),
append([" INIT_LOCK(",Global,");"], Out).
gen_init(Inp,Out) :-
split(Inp," ",[_, Field, "MkRWLock"]), !,
fetch_name(Global,Field),
append([" INIT_RWLOCK(",Global,");"], Out).
gen_init(Inp,Out) :-
split(Inp," ",[_, Field, "MkInstE",OP]), !,
cut_c_stuff(Field, RField),
fetch_name(Global,RField),
append([" ",Global,"->opc = Yap_opcode(",OP,");"], Out).
gen_init(Inp,Out) :-
split(Inp," ",[_, Field, "MkPred", Atom, "0", Module]), !,
cut_c_stuff(Field, RField),
fetch_name(Global,RField),
append([" ",Global," = RepPredProp(PredPropByAtom(",Atom,",",Module,"));"], Out).
gen_init(Inp,Out) :-
split(Inp," ",[_, Field, "MkPred", Atom, Arity, Module]), !,
cut_c_stuff(Field, RField),
fetch_name(Global,RField),
append([" ",Global," = 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,RField),
append([" ",Global," = RepPredProp(PredPropByFunc(",Fun,",",Module,"));"], Out).
gen_init(Inp,Out) :-
split(Inp," ",[".", Field,F0|_]), !,
cut_c_stuff(Field, RField),
split(RField,".",[_,MField]),
append("=",F,F0), !,
fetch_name(Global,MField),
append([" ",Global," = ",F,";"], Out).
gen_init(Inp,Out) :-
split(Inp," ",[_, Field, F0|_]),
append("=",F,F0), !,
cut_c_stuff(Field, RField),
fetch_name(Global,RField),
append([" ",Global," = ",F,";"], Out).
gen_init(Inp,_) :-
split(Inp," ",[_, _, _| _]),
format(user_error,"OOPS: could not gen_init for ~s~n",[Inp]).