Lhogho  0.0.028
 All Data Structures Files Functions Variables Typedefs Macros Pages
options.h File Reference

Go to the source code of this file.

Data Structures

struct  stats_t
 statistics structure More...
 

Macros

#define EXE_EXT   ""
 default extension for executable files More...
 
#define PATH_SLASH   "/"
 default slash in paths More...
 
#define PATH_DELIM   ":"
 default delimiter in paths in environment variables (like PATH) More...
 
#define EXE_EXT2   ".run"
 alternative extension for executable files used to avoid overwriting the source file More...
 

Functions

void init_options ()
 initializes the Options module More...
 
void finit_options ()
 finalizes the Options module More...
 
void set_options (int argc, char *argv[])
 sets options from command-line parameters More...
 
void output_compiler_name (int show_help)
 outputs the name of the compier More...
 
void dump_statistics ()
 dump statistics More...
 

Variables

int option_turned_on [OPTIONS_COUNT]
 Values for options. More...
 
int option_dump_ast
 
int option_make_executable
 
int option_make_executable_compiler
 
int option_case_insensitive
 
int option_traditional
 
int option_memory_statistics
 
int option_detailed_memory_statistics
 
int option_variables
 
int option_user_variables
 
int option_assembler
 
int option_runtime
 
char * option_compiler_filename
 ASCII name of current compiler. More...
 
chars_t option_compiler_filename_chars
 name of current compiler More...
 
char * option_source_filename
 ASCII name of current source file. More...
 
chars_t option_source_filename_chars
 name of current source file More...
 
int standalone
 indicate using of standalone compiler (i.e. -x option) More...
 
atom_t standalone_arguments
 list of command-line arguments More...
 
int stats_allocs
 statistics for usage of ALLOC and DEALLOC More...
 
stats_t stats [MAX_ID]
 statistics for each type of atoms More...
 

Names of compiler options

#define OPTION_HELP   option_turned_on[0]
 option "-h" and "--help" print this help message More...
 
#define OPTION_MAKE_EXECUTABLE   option_turned_on[1]
 option "-x" and "--executable" create executable file More...
 
#define OPTION_MAKE_EXECUTABLE_COMPILER   option_turned_on[2]
 option "-xc" and "--executable-compiler" generate executable compiler More...
 
#define OPTION_CASE_INSENSITIVE   option_turned_on[3]
 option "-ci" and "--case-insensitive" switch to case-insensitive mode More...
 
#define OPTION_TRADITIONAL   option_turned_on[4]
 option "-t" and "--traditional" switch to traditional mode More...
 
#define OPTION_ASSEMBLER   option_turned_on[5]
 option "-Za" and "--Zassembler" dump assembler code More...
 
#define OPTION_MEMORY_STATISTICS   option_turned_on[6]
 option "-Zm" and "--Zmemory" dump short memory statistics More...
 
#define OPTION_DETAILED_MEMORY_STATISTICS   option_turned_on[7]
 option "-Zmad" and "--Zmemory-all-details" dump detailed memory statistics More...
 
#define OPTION_RUNTIME   option_turned_on[8]
 option "-Zrt" and "--Zrun-time" dump evaluations at runtime More...
 
#define OPTION_DUMP_AST   option_turned_on[9]
 option "-Zt" and "--Ztree" dump abstract syntax trees More...
 
#define OPTION_VARIABLES   option_turned_on[10]
 option "-Zv" and "--Zvariables" dump created variables More...
 
#define OPTION_USER_VARIABLES   option_turned_on[11]
 option "-Zuv" and "--Zuser-variables" dump user variables More...
 
#define FIRST_BASIC_OPTION   0
 
#define LAST_BASIC_OPTION   4
 
#define FIRST_ADVANCED_OPTION   5
 
#define LAST_ADVANCED_OPTION   11
 
#define OPTIONS_COUNT   (LAST_ADVANCED_OPTION-FIRST_BASIC_OPTION+1)
 
#define OPTIONS_SUPPORTED_COUNT   OPTIONS_COUNT
 

Memory tracing

#define ALLOC(size)   alloc(size)
 allocate memory More...
 
#define REALLOC(ptr, size)
 reallocate memory More...
 
#define XALLOC(size)   xalloc(size)
 allocate executable memory More...
 
#define DEALLOC(ptr)   dealloc(ptr)
 deallocate memory More...
 
voidalloc (int size)
 allocates dynamic memory More...
 
voidreallocate (void *ptr, int size)
 
voidxalloc (int size)
 
void dealloc (void *ptr)
 deallocates dynamic memory More...
 

Macro Definition Documentation

#define OPTION_HELP   option_turned_on[0]

Definition at line 56 of file options.h.

#define OPTION_MAKE_EXECUTABLE   option_turned_on[1]

Definition at line 57 of file options.h.

#define OPTION_MAKE_EXECUTABLE_COMPILER   option_turned_on[2]

Definition at line 58 of file options.h.

#define OPTION_CASE_INSENSITIVE   option_turned_on[3]

Definition at line 59 of file options.h.

#define OPTION_TRADITIONAL   option_turned_on[4]

Definition at line 60 of file options.h.

#define OPTION_ASSEMBLER   option_turned_on[5]

Definition at line 62 of file options.h.

#define OPTION_MEMORY_STATISTICS   option_turned_on[6]

Definition at line 63 of file options.h.

#define OPTION_DETAILED_MEMORY_STATISTICS   option_turned_on[7]

Definition at line 64 of file options.h.

#define OPTION_RUNTIME   option_turned_on[8]

Definition at line 65 of file options.h.

#define OPTION_DUMP_AST   option_turned_on[9]

Definition at line 66 of file options.h.

#define OPTION_VARIABLES   option_turned_on[10]

Definition at line 67 of file options.h.

#define OPTION_USER_VARIABLES   option_turned_on[11]

Definition at line 68 of file options.h.

#define FIRST_BASIC_OPTION   0

Definition at line 70 of file options.h.

#define LAST_BASIC_OPTION   4

Definition at line 71 of file options.h.

#define FIRST_ADVANCED_OPTION   5

Definition at line 73 of file options.h.

#define LAST_ADVANCED_OPTION   11

Definition at line 74 of file options.h.

#define OPTIONS_COUNT   (LAST_ADVANCED_OPTION-FIRST_BASIC_OPTION+1)

Definition at line 76 of file options.h.

#define OPTIONS_SUPPORTED_COUNT   OPTIONS_COUNT

Definition at line 79 of file options.h.

#define EXE_EXT   ""

Definition at line 95 of file options.h.

#define PATH_SLASH   "/"

Definition at line 96 of file options.h.

#define PATH_DELIM   ":"

Definition at line 97 of file options.h.

#define EXE_EXT2   ".run"

Definition at line 99 of file options.h.

#define ALLOC (   size)    alloc(size)

Definition at line 188 of file options.h.

#define REALLOC (   ptr,
  size 
)
Value:
reallocate(ptr, \
size)

Definition at line 189 of file options.h.

#define XALLOC (   size)    xalloc(size)

Definition at line 192 of file options.h.

#define DEALLOC (   ptr)    dealloc(ptr)

Definition at line 193 of file options.h.

Function Documentation

void init_options ( )

Initalizes options with their default values.

void finit_options ( )

Dumps statistics if -Zm option was switched on

Definition at line 207 of file options.c.

209  {
210  int j;
211  for( j = 0; j<4; j++ )
212  {
213  DEUSE(option_texts[j][i]);
214  }
215  }
217 
220 
222  {
224  }
225 
226 #ifdef ADVANCED
227  int stats_used=0;
229  {
230  dump_statistics();
231  }
232 
234  {
235  for( i=MIN_ID; i<MAX_ID; i++ )
236  stats_used += stats[i].allocs-stats[i].deallocs;
237  PRINT("{MEM#%d:%d}\n",stats_used,stats_allocs);
238  }
239 #endif //ADVANCED
240 }
241 
242 
void set_options ( int  argc,
char *  argv[] 
)
Parameters
argcargc parameter from the main function
argvargv parameter from the main function

Reads options from the argv array and sets appropriate parameters.

Definition at line 392 of file options.c.

400  {
401  //atom_t error = new_os_error( option_compiler_filename_chars );
402  return;
403  }
404 
405  standalone = (*(int*)(code+ptr-4)==MAGIC_NUMBER);
406  DEALLOC( code );
407 
408  // get options only if not in standalone mode,
409  // otherwise collect them in a list
410  if( standalone )
411  { // standalone mode -- collect arguments in a list
412  for( argc--,argv++; argc--; argv++ )
413  {
414  atom_t word = decode_word( (unsigned char*)*argv, strlen(*argv), 0 );
415  append( word, &standalone_arguments, &last );
416  }
417  }
418  else
419  { // compiler mode -- process options till file name and then collect arguments
420  for( argc--,argv++; argc--; argv++ )
421  {
423  {
424  atom_t word = decode_word( (unsigned char*)*argv, strlen(*argv), 0 );
425  append ( word, &standalone_arguments, &last );
426  }
427  else
428  {
429  int found = 0;
430  chars_t option = UNFILENAME(*argv);
431  int len = STRLEN(option);
432  int i;
433  for( i=0; i<OPTIONS_SUPPORTED_COUNT; i++ )
434  {
435  int j;
436  for( j=0; j<4; j++ )
437  {
438  if( len==LENGTH(option_texts[j][i]) )
439  {
440  if( same_strings(1,option,STRING(option_texts[j][i]),len) )
441  {
442  found = 1;
443  option_turned_on[i] = 1;
444  break;
445  }
446  }
447  }
448  }
449  DEALLOC( option );
450 
451  if( OPTION_HELP )
452  {
454  exit(0);
455  }
456 
457  if( found ) continue;
458 
459  // check for invalid option or second file name
460  if( **argv=='-' )
461  {
462  chars_t name = UNFILENAME(*argv); // has ALLOC inside
463  atom_t word = new_word( name, UNKNOWN );
464  atom_t err = new_error( ERROR_UNKNOWN_OPTION, word );
465  dumpln( err );
466  DEUSE( word );
467  DEALLOC( name );
468  continue;
469  }
470 
471  // set file name
472  option_source_filename = *argv;
474  }
475  } // for
476  }
477 }
478 
479 
void output_compiler_name ( int  show_help)
Parameters
show_helpif set also output commandline options

Outputs the name of the compiler, its language, its platform and build date. If show_help is not zero, output a list of command-line options

Definition at line 255 of file options.c.

264  {
265  dump( CAR(t) ); t = CDR(t); // Usage
266 
267  int i;
268  for( i=0; i<OPTIONS_COUNT; i++ )
269  {
270  int len;
271 
272  if( i==FIRST_ADVANCED_OPTION )
273  {
274  #ifndef ADVANCED
275  t = CDR(t);
276  #endif
277  dumpln( CAR(t) ); t = CDR(t); // options
278  }
279 
280  // show short version
281  len = LENGTH(option_texts[0][i]);
282  outter( TEXT(" "), -1 );
283  dump( option_texts[0][i] );
284  for( ; len<6; len++ ) outter( TEXT(" "), -1 );
285 
286  // show long version
287  len = LENGTH(option_texts[2][i]);
288  if( len )
289  {
290  dump( option_texts[2][i] );
291  }
292  else
293  {
294  len = LENGTH(option_texts[1][i]);
295  dump( option_texts[1][i] );
296  }
297  for( ; len<30; len++ ) outter( TEXT(" "), -1 );
298 
299  // show description
300  dumpln( option_texts[3][i] );
301  }
302  }
303 
304  DEUSE( texts );
305  DEUSE( help_texts );
306 }
307 
308 
void dump_statistics ( )

Dumps statistics of memory usage

Definition at line 173 of file options.c.

179  {
180  stats_used += stats[i].allocs-stats[i].deallocs;
181  if( stats[i].allocs )
182  {
183  PRINT(" %10s %8d %8d %8d %8d\n",
184  id_names[i],
185  stats[i].max,
186  stats[i].allocs,
187  stats[i].deallocs,
188  stats[i].allocs-stats[i].deallocs );
189  }
190  }
191  PRINT(" %39s\n","----------------");
192  PRINT(" %30s %8d\n","Used",stats_used);
193  PRINT(" %30s %8d\n","Free",stats_free);
194  PRINT(" %39s\n","----------------");
195  PRINT(" %30s %8d\n","OS alloc balance",stats_allocs);
196 }
197 #endif
198 
void* alloc ( int  size)
Parameters
sizesize of memory (in bytes) to allocate
Returns
pointer to allocated memory

This function is used to allocate memory. Depending on the existence of DEBUG_HEAP symbol it either just allocates memory or allocates and dump on the screen allocation data.

Definition at line 556 of file options.c.

557  { dumpln(error_texts[ERROR_OUT_OF_MEM]); exit(1); }
558  #ifdef ADVANCED
559  stats_allocs++;
560  #endif
561  return buffer;
562 }
563 
564 void* reallocate(void * mem, int size)
void* reallocate ( void ptr,
int  size 
)

Definition at line 566 of file options.c.

570  { dumpln(error_texts[ERROR_OUT_OF_MEM]); exit(1); }
571  return buffer;
572 }
573 
574 void* xalloc( int size )
void* xalloc ( int  size)

Definition at line 576 of file options.c.

583  { dumpln(error_texts[ERROR_OUT_OF_MEM]); exit(1); }
584 
585  #ifdef ADVANCED
586  stats_allocs++;
587  #endif
588  return buffer;
589 }
590 void dealloc( void* ptr )
591 {
void dealloc ( void ptr)
Parameters
ptrpointer to the memory to deallocate

This function is used to deallocate memory. Depending on the existence of DEBUG_HEAP symbol it either just deallocates memory or deallocates and dumps on the screen deallocation data.

Definition at line 592 of file options.c.

Variable Documentation

int option_turned_on[OPTIONS_COUNT]

Definition at line 86 of file options.c.

int option_dump_ast
int option_make_executable
int option_make_executable_compiler
int option_case_insensitive
int option_traditional
int option_memory_statistics
int option_detailed_memory_statistics
int option_variables
int option_user_variables
int option_assembler
int option_runtime
char* option_compiler_filename

Definition at line 91 of file options.c.

chars_t option_compiler_filename_chars

Definition at line 92 of file options.c.

char* option_source_filename

Definition at line 89 of file options.c.

chars_t option_source_filename_chars

Definition at line 90 of file options.c.

int standalone

Definition at line 94 of file options.c.

atom_t standalone_arguments

Definition at line 95 of file options.c.

int stats_allocs

Definition at line 109 of file options.c.

stats_t stats[MAX_ID]

Definition at line 110 of file options.c.


[ HOME | INDEX | ATOMS | VARS | REFERENCE ]
Lhogho Developer's Documentation
Wed Jul 10 2013