GnuCOBOL  2.0
A free COBOL compiler
codegen.c File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <limits.h>
#include "tarstamp.h"
#include "cobc.h"
#include "tree.h"
#include "libcob/system.def"
Include dependency graph for codegen.c:

Go to the source code of this file.

Data Structures

struct  sort_list
 
struct  system_table
 
struct  label_list
 
struct  string_list
 
struct  attr_list
 
struct  literal_list
 
struct  field_list
 
struct  call_list
 
struct  base_list
 

Macros

#define COB_ALIGN   ""
 
#define COB_MAX_SUBSCRIPTS   16
 
#define COB_MALLOC_ALIGN   15
 
#define COB_INSIDE_SIZE   64
 
#define INITIALIZE_NONE   0
 
#define INITIALIZE_ONE   1
 
#define INITIALIZE_DEFAULT   2
 
#define INITIALIZE_COMPOUND   3
 
#define CB_NEED_HIGH   (1U << 0)
 
#define CB_NEED_LOW   (1U << 1)
 
#define CB_NEED_QUOTE   (1U << 2)
 
#define CB_NEED_SPACE   (1U << 3)
 
#define CB_NEED_ZERO   (1U << 4)
 
#define COB_SYSTEM_GEN(x, y, z)   { x, #z },
 

Functions

static void output (const char *,...)
 
static int lookup_string (const char *p)
 
static void lookup_call (const char *p)
 
static void lookup_func_call (const char *p)
 
static struct attr_listattr_list_reverse (struct attr_list *p)
 
static struct string_liststring_list_reverse (struct string_list *p)
 
static struct literal_listliteral_list_reverse (struct literal_list *p)
 
static int field_cache_cmp (const void *mp1, const void *mp2)
 
static int base_cache_cmp (const void *mp1, const void *mp2)
 
static void * list_cache_sort (void *inlist, int(*cmpfunc)(const void *mp1, const void *mp2))
 
static void output_newline (void)
 
static void output_prefix (void)
 
static void output_line (const char *fmt,...)
 
static void output_indent (const char *str)
 
static void output_string (const unsigned char *s, const int size, const cob_u32_t llit)
 
static void output_storage (const char *fmt,...)
 
static void output_local (const char *fmt,...)
 
static struct cb_fieldreal_field_founder (const struct cb_field *f)
 
static struct cb_fieldchk_field_variable_size (struct cb_field *f)
 
static unsigned int chk_field_variable_address (struct cb_field *fld)
 
static void output_base (struct cb_field *f, const cob_u32_t no_output)
 
static void output_data (cb_tree x)
 
static void output_size (const cb_tree x)
 
static int lookup_attr (const int type, const cob_u32_t digits, const int scale, const cob_u32_t flags, unsigned char *pic, const int lenstr)
 
static char * user_func_upper (const char *func)
 
static void output_attr (const cb_tree x)
 
static void output_field (cb_tree x)
 
static int lookup_literal (cb_tree x)
 
static void output_integer (cb_tree x)
 
static void output_long_integer (cb_tree x)
 
static void output_index (cb_tree x)
 
static void output_param (cb_tree x, int id)
 
static void output_funcall (cb_tree x)
 
static void output_func_1 (const char *name, cb_tree x)
 
static void output_cond (cb_tree x, const int save_flag)
 
static void output_move (cb_tree src, cb_tree dst)
 
static int initialize_type (struct cb_initialize *p, struct cb_field *f, const int topfield)
 
static int initialize_uniform_char (const struct cb_field *f, const struct cb_initialize *p)
 
static void output_figurative (cb_tree x, const struct cb_field *f, const int value, const int init_occurs)
 
static void output_initialize_literal (cb_tree x, struct cb_field *f, struct cb_literal *l, const int init_occurs)
 
static void output_initialize_fp_bindec (cb_tree x, struct cb_field *f)
 
static void output_initialize_fp (cb_tree x, struct cb_field *f)
 
static void output_initialize_uniform (cb_tree x, const int c, const int size)
 
static void output_initialize_one (struct cb_initialize *p, cb_tree x)
 
static void output_initialize_compound (struct cb_initialize *p, cb_tree x)
 
static void output_initialize (struct cb_initialize *p)
 
static void output_occurs (struct cb_field *p)
 
static void output_search_whens (cb_tree table, cb_tree var, cb_tree stmt, cb_tree whens)
 
static void output_search_all (cb_tree table, cb_tree stmt, cb_tree cond, cb_tree when)
 
static void output_search (struct cb_search *p)
 
static void output_call_by_value_args (cb_tree x, cb_tree l)
 
static void output_bin_field (const cb_tree x, const cob_u32_t id)
 
static void output_call (struct cb_call *p)
 
static void output_set_attribute (const struct cb_field *f, int val_on, int val_off)
 
static void output_cancel (struct cb_cancel *p)
 
static void output_perform_call (struct cb_label *lb, struct cb_label *le)
 
static void output_perform_exit (struct cb_label *l)
 
static void output_funcall_debug (cb_tree x)
 
static void output_cond_debug (cb_tree x)
 
static void output_perform_once (struct cb_perform *p)
 
static void output_perform_until (struct cb_perform *p, cb_tree l)
 
static void output_perform (struct cb_perform *p)
 
static void output_file_error (struct cb_file *pfile)
 
static void output_goto_1 (cb_tree x)
 
static void output_goto (struct cb_goto *p)
 
static void output_alter (struct cb_alter *p)
 
static void output_ferror_stmt (struct cb_statement *p, const int code)
 
static void output_section_info (struct cb_label *lp)
 
static void output_trace_info (cb_tree x, struct cb_statement *p)
 
static void output_label_info (cb_tree x, struct cb_label *lp)
 
static void output_alter_check (struct cb_label *lp)
 
static void output_stmt (cb_tree x)
 
static int output_file_allocation (struct cb_file *f)
 
static void output_file_initialization (struct cb_file *f)
 
static void output_screen_definition (struct cb_field *p)
 
static void output_screen_init (struct cb_field *p, struct cb_field *previous)
 
static int literal_value (cb_tree x)
 
static void output_alphabet_name_definition (struct cb_alphabet_name *p)
 
static void output_class_name_definition (struct cb_class_name *p)
 
static void output_initial_values (struct cb_field *f)
 
static void output_error_handler (struct cb_program *prog)
 
static void output_module_init (struct cb_program *prog)
 
static void output_internal_function (struct cb_program *prog, cb_tree parameter_list)
 
static void output_entry_function (struct cb_program *prog, cb_tree entry, cb_tree parameter_list, const int gencode)
 
static void output_main_function (struct cb_program *prog)
 
static void output_header (FILE *fp, const char *locbuff, const struct cb_program *cp)
 
void codegen (struct cb_program *prog, const int nested)
 

Variables

static struct attr_listattr_cache = ((void*)0)
 
static struct literal_listliteral_cache = ((void*)0)
 
static struct field_listfield_cache = ((void*)0)
 
static struct field_listlocal_field_cache = ((void*)0)
 
static struct call_listcall_cache = ((void*)0)
 
static struct call_listfunc_call_cache = ((void*)0)
 
static struct base_listbase_cache = ((void*)0)
 
static struct base_listglobext_cache = ((void*)0)
 
static struct base_listlocal_base_cache = ((void*)0)
 
static struct string_liststring_cache = ((void*)0)
 
static char * string_buffer = ((void*)0)
 
static struct label_listlabel_cache = ((void*)0)
 
static FILE * output_target = ((void*)0)
 
static FILE * cb_local_file = ((void*)0)
 
static const char * excp_current_program_id = ((void*)0)
 
static const char * excp_current_section = ((void*)0)
 
static const char * excp_current_paragraph = ((void*)0)
 
static struct cb_programcurrent_prog = ((void*)0)
 
static struct cb_labellast_section = ((void*)0)
 
static unsigned char * litbuff = ((void*)0)
 
static int litsize = 0
 
static unsigned int needs_exit_prog = 0
 
static unsigned int needs_unifunc = 0
 
static unsigned int need_save_exception = 0
 
static unsigned int gen_nested_tab = 0
 
static unsigned int gen_alt_ebcdic = 0
 
static unsigned int gen_ebcdic_ascii = 0
 
static unsigned int gen_full_ebcdic = 0
 
static unsigned int gen_native = 0
 
static unsigned int gen_custom = 0
 
static unsigned int gen_figurative = 0
 
static unsigned int gen_dynamic = 0
 
static int param_id = 0
 
static int stack_id = 0
 
static int string_id
 
static int num_cob_fields = 0
 
static int non_nested_count = 0
 
static int loop_counter = 0
 
static int progid = 0
 
static int last_line = 0
 
static cob_u32_t field_iteration = 0
 
static int screenptr = 0
 
static int local_mem = 0
 
static int working_mem = 0
 
static int local_working_mem = 0
 
static int output_indent_level = 0
 
static int last_segment = 0
 
static int gen_if_level = 0
 
static unsigned int nolitcast = 0
 
static unsigned int inside_check = 0
 
static unsigned int inside_stack [64]
 
static unsigned int i_counters [16]
 
static const struct system_table system_tab []
 

Macro Definition Documentation

#define CB_NEED_HIGH   (1U << 0)

Definition at line 55 of file codegen.c.

Referenced by codegen(), and output_param().

#define CB_NEED_LOW   (1U << 1)

Definition at line 56 of file codegen.c.

Referenced by codegen(), and output_param().

#define CB_NEED_QUOTE   (1U << 2)

Definition at line 57 of file codegen.c.

Referenced by codegen(), and output_param().

#define CB_NEED_SPACE   (1U << 3)

Definition at line 58 of file codegen.c.

Referenced by codegen(), and output_param().

#define CB_NEED_ZERO   (1U << 4)

Definition at line 59 of file codegen.c.

Referenced by codegen(), and output_param().

#define COB_ALIGN   ""

Definition at line 41 of file codegen.c.

Referenced by codegen().

#define COB_INSIDE_SIZE   64

Definition at line 48 of file codegen.c.

Referenced by codegen(), output_cond(), and output_param().

#define COB_MALLOC_ALIGN   15

Definition at line 46 of file codegen.c.

Referenced by output_internal_function().

#define COB_MAX_SUBSCRIPTS   16

Definition at line 44 of file codegen.c.

Referenced by cb_init_constants(), codegen(), and yyparse().

#define COB_SYSTEM_GEN (   x,
  y,
 
)    { x, #z },

Definition at line 182 of file codegen.c.

#define INITIALIZE_COMPOUND   3

Definition at line 53 of file codegen.c.

Referenced by initialize_type(), and output_initialize().

#define INITIALIZE_DEFAULT   2

Definition at line 52 of file codegen.c.

Referenced by initialize_type(), output_initialize(), and output_initialize_compound().

#define INITIALIZE_NONE   0

Definition at line 50 of file codegen.c.

Referenced by initialize_type(), output_initialize(), and output_initialize_compound().

#define INITIALIZE_ONE   1

Definition at line 51 of file codegen.c.

Referenced by initialize_type(), output_initialize(), and output_initialize_compound().

Function Documentation

static struct attr_list* attr_list_reverse ( struct attr_list p)
static

Definition at line 269 of file codegen.c.

References attr_list::next, and NULL.

Referenced by codegen().

270 {
271  struct attr_list *next;
272  struct attr_list *last;
273 
274  last = NULL;
275  for (; p; p = next) {
276  next = p->next;
277  p->next = last;
278  last = p;
279  }
280  return last;
281 }
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
struct attr_list * next
Definition: codegen.c:83

Here is the caller graph for this function:

static int base_cache_cmp ( const void *  mp1,
const void *  mp2 
)
static

Definition at line 327 of file codegen.c.

References base_list::f, and cb_field::id.

Referenced by codegen().

327  {
328  const struct base_list *fl1;
329  const struct base_list *fl2;
330 
331  fl1 = (const struct base_list *)mp1;
332  fl2 = (const struct base_list *)mp2;
333  return fl1->f->id - fl2->f->id;
334 }
struct cb_field * f
Definition: codegen.c:114
int id
Definition: tree.h:671

Here is the caller graph for this function:

static unsigned int chk_field_variable_address ( struct cb_field fld)
static

Definition at line 582 of file codegen.c.

References cb_field::children, chk_field_variable_size(), cb_field::depending, cb_field::flag_vaddr_done, cb_field::parent, cb_field::sister, and cb_field::vaddr.

Referenced by output_base(), and output_param().

583 {
584  struct cb_field *p;
585  struct cb_field *f;
586 
587  if (fld->flag_vaddr_done) {
588  return fld->vaddr;
589  }
590  f = fld;
591  for (p = f->parent; p; f = f->parent, p = f->parent) {
592  for (p = p->children; p != f; p = p->sister) {
593  if (p->depending || chk_field_variable_size (p)) {
594  fld->vaddr = 1;
595  fld->flag_vaddr_done = 1;
596  return 1;
597  }
598  }
599  }
600  fld->vaddr = 0;
601  fld->flag_vaddr_done = 1;
602  return 0;
603 }
static struct cb_field * chk_field_variable_size(struct cb_field *f)
Definition: codegen.c:556
struct cb_field * sister
Definition: tree.h:653
struct cb_field * children
Definition: tree.h:652
cb_tree depending
Definition: tree.h:647
Definition: tree.h:643
unsigned int vaddr
Definition: tree.h:686
struct cb_field * parent
Definition: tree.h:651
unsigned int flag_vaddr_done
Definition: tree.h:730

Here is the call graph for this function:

Here is the caller graph for this function:

static struct cb_field* chk_field_variable_size ( struct cb_field f)
static

Definition at line 556 of file codegen.c.

References cb_field::children, cb_field::depending, cb_field::flag_vsize_done, NULL, cb_field::sister, and cb_field::vsize.

Referenced by chk_field_variable_address(), output_base(), output_param(), and output_size().

557 {
558  struct cb_field *p;
559  struct cb_field *fc;
560 
561  if (f->flag_vsize_done) {
562  return f->vsize;
563  }
564  for (fc = f->children; fc; fc = fc->sister) {
565  if (fc->depending) {
566  f->vsize = fc;
567  f->flag_vsize_done = 1;
568  return fc;
569  } else if ((p = chk_field_variable_size (fc)) != NULL) {
570  f->vsize = p;
571  f->flag_vsize_done = 1;
572  return p;
573  }
574  }
575  f->vsize = NULL;
576  f->flag_vsize_done = 1;
577  return NULL;
578 }
static struct cb_field * chk_field_variable_size(struct cb_field *f)
Definition: codegen.c:556
struct cb_field * sister
Definition: tree.h:653
struct cb_field * children
Definition: tree.h:652
unsigned int flag_vsize_done
Definition: tree.h:729
struct cb_field * vsize
Definition: tree.h:660
cb_tree depending
Definition: tree.h:647
Definition: tree.h:643
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95

Here is the caller graph for this function:

void codegen ( struct cb_program prog,
const int  nested 
)

Definition at line 7448 of file codegen.c.

References _, cb_program::alphabet_name_list, attr_list_reverse(), base_cache_cmp(), call_list::callname, CB_CHAIN, CB_CLASS_NAME, CB_CLASS_NUMERIC, CB_FUNCTION_TYPE, cb_list_add(), CB_LITERAL, cb_local_file, CB_NEED_HIGH, CB_NEED_LOW, CB_NEED_QUOTE, CB_NEED_SPACE, CB_NEED_ZERO, CB_PREFIX_ATTR, CB_PREFIX_BASE, CB_PREFIX_CONST, CB_PREFIX_FIELD, CB_PREFIX_STRING, CB_PROGRAM_TYPE, cb_source_file, cb_storage_file, cb_storage_file_name, CB_TREE_CLASS, CB_VALUE, CB_XSTRINGIFY, cb_program::class_name_list, COB_ALIGN, cob_gen_optim(), COB_INSIDE_SIZE, COB_KEYWORD_INLINE, COB_MAX_SUBSCRIPTS, COB_MINI_BUFF, COB_MINI_MAX, COB_OPTIM_MAX, COB_OPTIM_MIN, COB_TYPE_ALPHANUMERIC, COB_TYPE_ALPHANUMERIC_ALL, cob_u32_t, cobc_flag_main, cobc_main_malloc(), codegen(), field_list::curr_prog, base_list::curr_prog, cb_literal::data, attr_list::digits, cb_program::entry_list, excp_current_paragraph, excp_current_program_id, excp_current_section, field_list::f, base_list::f, field_cache_cmp(), cb_program::flag_chained, cb_program::flag_debugging, cb_field::flag_filler, cb_program::flag_global_use, cb_field::flag_local, cb_program::flag_main, cb_program::flag_recursive, attr_list::flags, gen_alt_ebcdic, gen_custom, gen_dynamic, gen_ebcdic_ascii, gen_figurative, gen_full_ebcdic, gen_if_level, gen_native, gen_nested_tab, i_counters, string_list::id, attr_list::id, literal_list::id, cb_field::id, inside_check, inside_stack, last_line, last_segment, list_cache_sort(), literal_list_reverse(), cb_literal::llit, local_filename::local_fp, cb_program::local_include, local_mem, cb_program::local_storage, local_working_mem, lookup_attr(), loop_counter, cb_program::max_call_param, cb_field::memory_size, cb_field::name, need_save_exception, needs_exit_prog, needs_unifunc, cb_program::nested_level, nested_list::nested_prog, cb_program::nested_prog_list, string_list::next, attr_list::next, literal_list::next, field_list::next, call_list::next, base_list::next, nested_list::next, cb_program::next_program, non_nested_count, NULL, num_cob_fields, optimize_defs, cb_program::orig_program_id, output(), output_attr(), output_class_name_definition(), output_entry_function(), output_field(), output_header(), output_indent_level, output_internal_function(), output_local(), output_main_function(), output_newline(), output_size(), output_storage(), output_string(), output_target, PACKAGE_VERSION, param_id, cb_program::parameter_list, PATCH_LEVEL, attr_list::pic, cb_program::prog_type, progid, cb_program::program_id, attr_list::scale, cb_literal::sign, cb_literal::size, cb_field::special_index, stack_id, string_buffer, string_id, string_list_reverse(), string_list::text, cb_program::toplev_count, attr_list::type, working_mem, literal_list::x, field_list::x, and yyout.

Referenced by codegen(), and process_translate().

7449 {
7450  cb_tree l;
7451  struct attr_list *j;
7452  struct literal_list *m;
7453  struct field_list *k;
7454  struct string_list *stp;
7455  struct call_list *clp;
7456  struct base_list *blp;
7457  unsigned char *s;
7458  struct nested_list *nlp;
7459  struct cb_program *cp;
7460 #if 0 /* RXWRXW - Const */
7461  struct cb_literal *lp;
7462 #endif
7463  cb_tree l1;
7464  cb_tree l2;
7465  const char *prevprog;
7466  struct tm *loctime;
7467  cob_u32_t inc;
7468 #if 0 /* RXWRXW - Sticky */
7469  int save_sticky;
7470 #endif
7471  int i;
7472  int found;
7473  enum cb_optim optidx;
7474  time_t sectime;
7475 
7476  /* Clear local program stuff */
7477  current_prog = prog;
7478  param_id = 0;
7479  stack_id = 0;
7480  num_cob_fields = 0;
7481  progid = 0;
7482  loop_counter = 0;
7483  output_indent_level = 0;
7484  last_line = 0;
7485  needs_exit_prog = 0;
7486  gen_custom = 0;
7487  gen_nested_tab = 0;
7488  gen_dynamic = 0;
7489  gen_if_level = 0;
7490  local_mem = 0;
7491  local_working_mem = 0;
7492  need_save_exception = 0;
7493  last_segment = 0;
7494  last_section = NULL;
7495  call_cache = NULL;
7497  label_cache = NULL;
7500  inside_check = 0;
7501  for (i = 0; i < COB_INSIDE_SIZE; ++i) {
7502  inside_stack[i] = 0;
7503  }
7507  memset ((void *)i_counters, 0, sizeof (i_counters));
7508 #if 0 /* RXWRXW - Sticky */
7509  save_sticky = cb_sticky_linkage;
7510 #endif
7511 
7512  output_target = yyout;
7514 
7515  if (!nested) {
7516  /* First iteration */
7517  gen_alt_ebcdic = 0;
7518  gen_ebcdic_ascii = 0;
7519  gen_full_ebcdic = 0;
7520  gen_native = 0;
7521  gen_figurative = 0;
7522  non_nested_count = 0;
7523  working_mem = 0;
7524  attr_cache = NULL;
7525  base_cache = NULL;
7526  globext_cache = NULL;
7527  literal_cache = NULL;
7528  field_cache = NULL;
7529  string_cache = NULL;
7530  string_id = 1;
7531  if (!string_buffer) {
7533  }
7534 
7535  sectime = time (NULL);
7536  loctime = localtime (&sectime);
7537  /* Leap seconds ? */
7538  if (loctime->tm_sec >= 60) {
7539  loctime->tm_sec = 59;
7540  }
7541  if (loctime) {
7542  strftime (string_buffer, (size_t)COB_MINI_MAX,
7543  "%b %d %Y %H:%M:%S", loctime);
7544  } else {
7545  strcpy (string_buffer, _("Unknown"));
7546  }
7549  for (cp = prog; cp; cp = cp->next_program) {
7551  string_buffer, cp);
7552  }
7553 
7554 #ifndef _GNU_SOURCE
7555 #ifdef _XOPEN_SOURCE_EXTENDED
7556  output ("#ifndef\t_XOPEN_SOURCE_EXTENDED\n");
7557  output ("#define\t_XOPEN_SOURCE_EXTENDED 1\n");
7558  output ("#endif\n");
7559 #endif
7560 #endif
7561  output ("#include <stdio.h>\n");
7562  output ("#include <stdlib.h>\n");
7563  output ("#include <stddef.h>\n");
7564  output ("#include <string.h>\n");
7565  output ("#include <math.h>\n");
7566 #ifdef WORDS_BIGENDIAN
7567  output ("#define WORDS_BIGENDIAN 1\n");
7568 #endif
7569 #ifdef COB_KEYWORD_INLINE
7570  output ("#define COB_KEYWORD_INLINE %s\n",
7572 #endif
7573  output ("#include <libcob.h>\n\n");
7574 
7575  output ("#define COB_SOURCE_FILE\t\t\"%s\"\n",
7576  cb_source_file);
7577  output ("#define COB_PACKAGE_VERSION\t\t\"%s\"\n",
7578  PACKAGE_VERSION);
7579  output ("#define COB_PATCH_LEVEL\t\t%d\n",
7580  PATCH_LEVEL);
7581  /* string_buffer has formatted date from above */
7582  output ("#define COB_MODULE_FORMATTED_DATE\t\"%s\"\n",
7583  string_buffer);
7584  if (loctime) {
7585  i = ((loctime->tm_year + 1900) * 10000) +
7586  ((loctime->tm_mon + 1) * 100) +
7587  loctime->tm_mday;
7588  output ("#define COB_MODULE_DATE\t\t%d\n", i);
7589  i = (loctime->tm_hour * 10000) +
7590  (loctime->tm_min * 100) +
7591  loctime->tm_sec;
7592  output ("#define COB_MODULE_TIME\t\t%d\n", i);
7593  } else {
7594  output ("#define COB_MODULE_DATE\t\t0\n");
7595  output ("#define COB_MODULE_TIME\t\t0\n");
7596  }
7597 
7598  output_newline ();
7599  output ("/* Global variables */\n");
7600  output ("#include \"%s\"\n\n", cb_storage_file_name);
7601 
7602  output ("/* Function prototypes */\n\n");
7603  for (cp = prog; cp; cp = cp->next_program) {
7604  /* Build parameter list */
7605  for (l = cp->entry_list; l; l = CB_CHAIN (l)) {
7606  for (l1 = CB_VALUE (l); l1; l1 = CB_CHAIN (l1)) {
7607  for (l2 = cp->parameter_list; l2; l2 = CB_CHAIN (l2)) {
7608  if (strcasecmp (cb_code_field (CB_VALUE (l1))->name,
7609  cb_code_field (CB_VALUE (l2))->name) == 0) {
7610  break;
7611  }
7612  }
7613  if (l2 == NULL) {
7615  }
7616  }
7617  }
7618  if (cp->flag_main) {
7619  if (!cp->flag_recursive) {
7620  output ("static int\t\t%s ();\n",
7621  cp->program_id);
7622  } else {
7623  output ("int\t\t\t%s ();\n",
7624  cp->program_id);
7625  }
7626  } else {
7627  for (l = cp->entry_list; l; l = CB_CHAIN (l)) {
7628  output_entry_function (cp, l, cp->parameter_list, 0);
7629  }
7630  }
7631  if (cp->prog_type == CB_FUNCTION_TYPE) {
7632  non_nested_count++;
7633 #if 0 /* RXWRXW USERFUNC */
7634  output ("static cob_field\t*%s_ (const int, cob_field **",
7635 #else
7636  output ("static cob_field\t*%s_ (const int",
7637 #endif
7638  cp->program_id);
7639  } else if (!cp->nested_level) {
7640  non_nested_count++;
7641  output ("static int\t\t%s_ (const int",
7642  cp->program_id);
7643  } else {
7644  output ("static int\t\t%s_%d_ (const int",
7645  cp->program_id, cp->toplev_count);
7646  }
7647 #if 0 /* RXWRXW USERFUNC */
7648  if (!cp->flag_chained && cp->prog_type != CB_FUNCTION_TYPE) {
7649 #else
7650  if (!cp->flag_chained) {
7651 #endif
7652  for (l = cp->parameter_list; l; l = CB_CHAIN (l)) {
7653  output (", cob_u8_t *");
7654  if (cb_sticky_linkage) {
7655  output_storage ("static cob_u8_t\t\t\t*cob_parm_%d = NULL;\n",
7656  cb_code_field (CB_VALUE (l))->id);
7657  }
7658  }
7659  }
7660 #if 0 /* RXWRXW - NOINLINE */
7661  if (cb_flag_stack_check) {
7662  output (") COB_NOINLINE;\n");
7663  } else {
7664 #endif
7665  output (");\n");
7666 #if 0 /* RXWRXW - NOINLINE */
7667  }
7668 #endif
7669  }
7670  output ("\n");
7671  }
7672 
7673  /* Class-names */
7674  if (!prog->nested_level && prog->class_name_list) {
7675  output ("/* Class names */\n");
7676  for (l = prog->class_name_list; l; l = CB_CHAIN (l)) {
7678  }
7679  }
7680 
7681  /* Main function */
7682  if (prog->flag_main) {
7683  output_main_function (prog);
7684  }
7685 
7686  /* Functions */
7687  if (!nested) {
7688  output ("/* Functions */\n\n");
7689  }
7690 
7691  if (prog->prog_type == CB_FUNCTION_TYPE) {
7692  output ("/* FUNCTION-ID '%s' */\n\n", prog->orig_program_id);
7693  } else {
7694  output ("/* PROGRAM-ID '%s' */\n\n", prog->orig_program_id);
7695  }
7696 
7697  for (l = prog->entry_list; l; l = CB_CHAIN (l)) {
7698  output_entry_function (prog, l, prog->parameter_list, 1);
7699  }
7700 
7702 
7703  if (!prog->next_program) {
7704  output ("/* End functions */\n\n");
7705  }
7706 
7707  if (gen_native || gen_full_ebcdic ||
7709  (void)lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
7710  }
7711 
7713 
7714  /* Program local stuff */
7715 
7716  /* CALL cache */
7718  output_local ("\n/* Call pointers */\n");
7719  }
7720  if (needs_unifunc) {
7721  output_local ("cob_call_union\t\tcob_unifunc;\n");
7722  }
7723  for (clp = call_cache; clp; clp = clp->next) {
7724  output_local ("static cob_call_union\tcall_%s;\n",
7725  clp->callname);
7726  }
7727  for (clp = func_call_cache; clp; clp = clp->next) {
7728  output_local ("static cob_call_union\tfunc_%s;\n",
7729  clp->callname);
7730  }
7731  needs_unifunc = 0;
7732 
7733  /* Nested / contained list */
7734  if (prog->nested_prog_list && gen_nested_tab) {
7735  /* Generate contained program list */
7736  output_local ("\n/* Nested call table */\n");
7737  output_local ("static struct cob_call_struct\tcob_nest_tab[] = {\n");
7738  nlp = prog->nested_prog_list;
7739  for (; nlp; nlp = nlp->next) {
7740  if (nlp->nested_prog == prog) {
7741 #if 0 /* RXWRXW Fix recursive */
7742  if (!prog->flag_recursive) {
7743  continue;
7744  }
7745 #endif
7746  output_local ("\t{ \"%s\", { (void *(*)())%s_%d__ }, { NULL } },\n",
7748  nlp->nested_prog->program_id,
7749  nlp->nested_prog->toplev_count);
7750  } else {
7751  output_local ("\t{ \"%s\", { (void *(*)())%s_%d__ }, { (void *(*)())%s_%d_ } },\n",
7753  nlp->nested_prog->program_id,
7754  nlp->nested_prog->toplev_count,
7755  nlp->nested_prog->program_id,
7756  nlp->nested_prog->toplev_count);
7757  }
7758  }
7759  output_local ("\t{ NULL, { NULL }, { NULL } }\n");
7760  output_local ("};\n");
7761  }
7762 
7763  /* Local indexes */
7764  found = 0;
7765  for (i = 0; i < COB_MAX_SUBSCRIPTS; i++) {
7766  if (i_counters[i]) {
7767  if (!found) {
7768  found = 1;
7769  output_local ("\n/* Subscripts */\n");
7770  }
7771  output_local ("int\t\ti%d;\n", i);
7772  }
7773  }
7774 
7775  /* PERFORM TIMES counters */
7776  if (loop_counter) {
7777  output_local ("\n/* Loop counters */\n");
7778  for (i = 0; i < loop_counter; i++) {
7779  output_local ("cob_s64_t\tn%d = 0;\n", i);
7780  }
7781  output_local ("\n");
7782  }
7783 
7784  /* Local implicit fields */
7785  if (num_cob_fields) {
7786  output_local ("\n/* Local cob_field items */\n");
7787  for (i = 0; i < num_cob_fields; i++) {
7788  output_local ("cob_field\t\tf%d;\n", i);
7789  }
7790  output_local ("\n");
7791  }
7792 
7793  /* Debugging fields */
7794  if (prog->flag_debugging) {
7795  output_local ("\n/* DEBUG runtime switch */\n");
7796  output_local ("static int\tcob_debugging_mode = 0;\n");
7797  }
7798  if (need_save_exception) {
7799  output_local ("\n/* DEBUG exception code save */\n");
7800  output_local ("int\t\tsave_exception_code = 0;\n");
7801  }
7802 
7803  /* LOCAL storage pointer */
7804  if (prog->local_storage && local_mem) {
7805  output_local ("\n/* LOCAL storage pointer */\n");
7806  output_local ("unsigned char\t\t*cob_local_ptr = NULL;\n");
7808  output_local ("static unsigned char\t*cob_local_save = NULL;\n");
7809  }
7810  }
7811 
7812  /* Call parameter stack */
7813  output_local ("\n/* Call parameters */\n");
7814  if (cb_flag_stack_on_heap || prog->flag_recursive) {
7815  output_local ("cob_field\t\t**cob_procedure_params;\n");
7816  } else {
7817  if (prog->max_call_param) {
7818  i = prog->max_call_param;
7819  } else {
7820  i = 1;
7821  }
7822  output_local ("cob_field\t\t*cob_procedure_params[%d];\n", i);
7823  }
7824 
7825  /* Frame stack */
7826  output_local ("\n/* Perform frame stack */\n");
7827  if (cb_perform_osvs && current_prog->prog_type == CB_PROGRAM_TYPE) {
7828  output_local ("struct cob_frame\t*temp_index;\n");
7829  }
7830  if (cb_flag_stack_check) {
7831  output_local ("struct cob_frame\t*frame_overflow;\n");
7832  }
7833  output_local ("struct cob_frame\t*frame_ptr;\n");
7834  if (cb_flag_stack_on_heap || prog->flag_recursive) {
7835  output_local ("struct cob_frame\t*frame_stack;\n\n");
7836  } else {
7837  output_local ("struct cob_frame\tframe_stack[%d];\n\n",
7838  cb_stack_size);
7839  }
7840 
7841  if (gen_dynamic) {
7842  output_local ("\n/* Dynamic field FUNCTION-ID pointers */\n");
7843  for (inc = 0; inc < gen_dynamic; inc++) {
7844  output_local ("cob_field\t*cob_dyn_%u = NULL;\n",
7845  inc);
7846  }
7847  }
7848 
7849  if (local_base_cache) {
7850  output_local ("\n/* Data storage */\n");
7852  &base_cache_cmp);
7853  for (blp = local_base_cache; blp; blp = blp->next) {
7854  if (blp->f->special_index > 1) {
7855  output_local ("int %s%d;",
7856  CB_PREFIX_BASE, blp->f->id);
7857  } else if (blp->f->special_index) {
7858  output_local ("static int %s%d;",
7859  CB_PREFIX_BASE, blp->f->id);
7860  } else {
7861  output_local ("static cob_u8_t %s%d[%d]%s;",
7862  CB_PREFIX_BASE, blp->f->id,
7863  blp->f->memory_size, COB_ALIGN);
7864  }
7865  output_local ("\t/* %s */\n", blp->f->name);
7866  }
7867  output_local ("\n/* End of data storage */\n\n");
7868  }
7869 
7870  if (local_field_cache) {
7871  /* Switch to local storage file */
7873  output_local ("\n/* Fields */\n");
7875  &field_cache_cmp);
7876  for (k = local_field_cache; k; k = k->next) {
7877  output ("static cob_field %s%d\t= ", CB_PREFIX_FIELD,
7878  k->f->id);
7879  if (!k->f->flag_local) {
7880  output_field (k->x);
7881  } else {
7882  output ("{");
7883  output_size (k->x);
7884  output (", NULL, ");
7885  output_attr (k->x);
7886  output ("}");
7887  }
7888  if (k->f->flag_filler) {
7889  output (";\t/* Implicit FILLER */\n");
7890  } else {
7891  output (";\t/* %s */\n", k->f->name);
7892  }
7893  }
7894  output_local ("\n/* End of fields */\n\n");
7895  /* Switch to main storage file */
7897  }
7898 
7899  /* Skip to next nested program */
7900 
7901  if (prog->next_program) {
7902  codegen (prog->next_program, 1);
7903  return;
7904  }
7905 
7906  /* Finalize the main include file */
7907 
7908 #if 0 /* RXWRXW - GLOBPTR */
7909  output_storage ("\n/* Global variable pointer */\n");
7910  output_storage ("static cob_global\t\t*cob_glob_ptr = NULL;\n");
7911 #endif
7912 
7913  if (!cobc_flag_main && non_nested_count > 1) {
7914  output_storage ("\n/* Module reference count */\n");
7915  output_storage ("static unsigned int\t\tcob_reference_count = 0;\n");
7916  }
7917 
7918  output_storage ("\n/* Module path */\n");
7919  output_storage ("static const char\t\t*cob_module_path = NULL;\n");
7920 
7921  if (globext_cache) {
7922  output_storage ("\n/* GLOBAL EXTERNAL pointers */\n");
7924  for (blp = globext_cache; blp; blp = blp->next) {
7925  output_storage ("static unsigned char\t\t*%s%d = NULL;",
7926  CB_PREFIX_BASE, blp->f->id);
7927  output_storage ("\t/* %s */\n", blp->f->name);
7928  }
7929  }
7930 
7931  if (base_cache) {
7932  output_storage ("\n/* Data storage */\n");
7934  prevprog = NULL;
7935  for (blp = base_cache; blp; blp = blp->next) {
7936  if (blp->curr_prog != prevprog) {
7937  prevprog = blp->curr_prog;
7938  output_storage ("\n/* PROGRAM-ID : %s */\n",
7939  prevprog);
7940  }
7941  if (blp->f->special_index) {
7942  output_storage ("static int %s%d;",
7943  CB_PREFIX_BASE, blp->f->id);
7944  } else {
7945  output_storage ("static cob_u8_t %s%d[%d]%s;",
7946  CB_PREFIX_BASE, blp->f->id,
7947  blp->f->memory_size, COB_ALIGN);
7948  }
7949  output_storage ("\t/* %s */\n", blp->f->name);
7950  }
7951  output_storage ("\n/* End of data storage */\n\n");
7952  }
7953 
7954  /* Attributes */
7955  if (attr_cache || gen_figurative) {
7956  output_storage ("\n/* Attributes */\n\n");
7958  for (j = attr_cache; j; j = j->next) {
7959  output_storage ("static const cob_field_attr %s%d =\t",
7960  CB_PREFIX_ATTR, j->id);
7961  output_storage ("{0x%02x, %3u, %3d, 0x%04x, ",
7962  j->type, j->digits,
7963  j->scale, j->flags);
7964  if (j->pic) {
7965  output_storage ("\"");
7966  for (s = j->pic; *s; s += 5) {
7967  output_storage ("%c\\%03o\\%03o\\%03o\\%03o",
7968  s[0], s[1], s[2], s[3], s[4]);
7969  }
7970  output_storage ("\"");
7971  } else {
7972  output_storage ("NULL");
7973  }
7974  output_storage ("};\n");
7975  }
7976  if (gen_figurative) {
7977  output_storage ("\nstatic const cob_field_attr cob_all_attr = ");
7978  output_storage ("{0x%02x, 0, 0, 0, NULL};\n",
7980  }
7981  output_storage ("\n");
7982  }
7983 
7984  if (field_cache) {
7985  output_storage ("\n/* Fields */\n");
7987  prevprog = NULL;
7988  for (k = field_cache; k; k = k->next) {
7989  if (k->curr_prog != prevprog) {
7990  prevprog = k->curr_prog;
7991  output_storage ("\n/* PROGRAM-ID : %s */\n",
7992  prevprog);
7993  }
7994  output ("static cob_field %s%d\t= ", CB_PREFIX_FIELD,
7995  k->f->id);
7996  if (!k->f->flag_local) {
7997  output_field (k->x);
7998  } else {
7999  output ("{");
8000  output_size (k->x);
8001  output (", NULL, ");
8002  output_attr (k->x);
8003  output ("}");
8004  }
8005  if (k->f->flag_filler) {
8006  output (";\t/* Implicit FILLER */\n");
8007  } else {
8008  output (";\t/* %s */\n", k->f->name);
8009  }
8010  }
8011  output_storage ("\n/* End of fields */\n\n");
8012  }
8013 
8014  /* Literals, figuratives, constants */
8015  if (literal_cache || gen_figurative) {
8016  output_storage ("\n/* Constants */\n");
8018  for (m = literal_cache; m; m = m->next) {
8019 #if 0 /* RXWRXW - Const */
8020  output ("static const cob_fld_union %s%d\t= ",
8021  CB_PREFIX_CONST, m->id);
8022  output ("{");
8023  output_size (m->x);
8024  output (", ");
8025  lp = CB_LITERAL (m->x);
8026  if (CB_TREE_CLASS (m->x) == CB_CLASS_NUMERIC) {
8027  output ("\"%s%s\"", (char *)lp->data,
8028  (lp->sign < 0) ? "-" : (lp->sign > 0) ? "+" : "");
8029  } else {
8030  output_string (lp->data, (int) lp->size, lp->llit);
8031  }
8032  output (", ");
8033  output_attr (m->x);
8034  output ("}");
8035 #else
8036  output ("static const cob_field %s%d\t= ",
8037  CB_PREFIX_CONST, m->id);
8038  output_field (m->x);
8039 #endif
8040  output (";\n");
8041  }
8042  if (gen_figurative) {
8043  output ("\n");
8044  if (gen_figurative & CB_NEED_LOW) {
8045  output ("static cob_field cob_all_low\t= ");
8046  output ("{1, ");
8047  output ("(cob_u8_ptr)\"\\0\", ");
8048  output ("&cob_all_attr};\n");
8049  }
8050  if (gen_figurative & CB_NEED_HIGH) {
8051  output ("static cob_field cob_all_high\t= ");
8052  output ("{1, ");
8053  output ("(cob_u8_ptr)\"\\xff\", ");
8054  output ("&cob_all_attr};\n");
8055  }
8056  if (gen_figurative & CB_NEED_QUOTE) {
8057  output ("static cob_field cob_all_quote\t= ");
8058  output ("{1, ");
8059  if (cb_flag_apostrophe) {
8060  output ("(cob_u8_ptr)\"'\", ");
8061  } else {
8062  output ("(cob_u8_ptr)\"\\\"\", ");
8063  }
8064  output ("&cob_all_attr};\n");
8065  }
8066  if (gen_figurative & CB_NEED_SPACE) {
8067  output ("static cob_field cob_all_space\t= ");
8068  output ("{1, ");
8069  output ("(cob_u8_ptr)\" \", ");
8070  output ("&cob_all_attr};\n");
8071  }
8072  if (gen_figurative & CB_NEED_ZERO) {
8073  output ("static cob_field cob_all_zero\t= ");
8074  output ("{1, ");
8075  output ("(cob_u8_ptr)\"0\", ");
8076  output ("&cob_all_attr};\n");
8077  }
8078  }
8079  output ("\n");
8080  }
8081 
8082  /* Collating tables */
8083  if (gen_alt_ebcdic) {
8084  output_storage ("\n/* ASCII to EBCDIC translate table (restricted) */\n");
8085  output ("static const unsigned char\tcob_a2e[256] = {\n");
8086  /* Restricted table */
8087  output ("\t0x00, 0x01, 0x02, 0x03, 0x1D, 0x19, 0x1A, 0x1B,\n");
8088  output ("\t0x0F, 0x04, 0x16, 0x06, 0x07, 0x08, 0x09, 0x0A,\n");
8089  output ("\t0x0B, 0x0C, 0x0D, 0x0E, 0x1E, 0x1F, 0x1C, 0x17,\n");
8090  output ("\t0x10, 0x11, 0x20, 0x18, 0x12, 0x13, 0x14, 0x15,\n");
8091  output ("\t0x21, 0x27, 0x3A, 0x36, 0x28, 0x30, 0x26, 0x38,\n");
8092  output ("\t0x24, 0x2A, 0x29, 0x25, 0x2F, 0x2C, 0x22, 0x2D,\n");
8093  output ("\t0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A,\n");
8094  output ("\t0x7B, 0x7C, 0x35, 0x2B, 0x23, 0x39, 0x32, 0x33,\n");
8095  output ("\t0x37, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D,\n");
8096  output ("\t0x5E, 0x5F, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,\n");
8097  output ("\t0x67, 0x68, 0x69, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,\n");
8098  output ("\t0x70, 0x71, 0x72, 0x7D, 0x6A, 0x7E, 0x7F, 0x31,\n");
8099  output ("\t0x34, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41,\n");
8100  output ("\t0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,\n");
8101  output ("\t0x4A, 0x4B, 0x4C, 0x4E, 0x4F, 0x50, 0x51, 0x52,\n");
8102  output ("\t0x53, 0x54, 0x55, 0x56, 0x2E, 0x60, 0x4D, 0x05,\n");
8103  output ("\t0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n");
8104  output ("\t0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,\n");
8105  output ("\t0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n");
8106  output ("\t0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,\n");
8107  output ("\t0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,\n");
8108  output ("\t0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,\n");
8109  output ("\t0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,\n");
8110  output ("\t0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,\n");
8111  output ("\t0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,\n");
8112  output ("\t0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,\n");
8113  output ("\t0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,\n");
8114  output ("\t0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,\n");
8115  output ("\t0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,\n");
8116  output ("\t0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,\n");
8117  output ("\t0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,\n");
8118  output ("\t0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF\n");
8119  output ("};\n");
8120  output_storage ("\n");
8121  }
8122  if (gen_full_ebcdic) {
8123  output_storage ("\n/* ASCII to EBCDIC table */\n");
8124  output ("static const unsigned char\tcob_ascii_ebcdic[256] = {\n");
8125  output ("\t0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F,\n");
8126  output ("\t0x16, 0x05, 0x25, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,\n");
8127  output ("\t0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26,\n");
8128  output ("\t0x18, 0x19, 0x3F, 0x27, 0x1C, 0x1D, 0x1E, 0x1F,\n");
8129  output ("\t0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D,\n");
8130  output ("\t0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61,\n");
8131  output ("\t0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,\n");
8132  output ("\t0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F,\n");
8133  output ("\t0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,\n");
8134  output ("\t0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,\n");
8135  output ("\t0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6,\n");
8136  output ("\t0xE7, 0xE8, 0xE9, 0xAD, 0xE0, 0xBD, 0x5F, 0x6D,\n");
8137  output ("\t0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n");
8138  output ("\t0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,\n");
8139  output ("\t0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,\n");
8140  output ("\t0xA7, 0xA8, 0xA9, 0xC0, 0x6A, 0xD0, 0xA1, 0x07,\n");
8141  output ("\t0x68, 0xDC, 0x51, 0x42, 0x43, 0x44, 0x47, 0x48,\n");
8142  output ("\t0x52, 0x53, 0x54, 0x57, 0x56, 0x58, 0x63, 0x67,\n");
8143  output ("\t0x71, 0x9C, 0x9E, 0xCB, 0xCC, 0xCD, 0xDB, 0xDD,\n");
8144  output ("\t0xDF, 0xEC, 0xFC, 0xB0, 0xB1, 0xB2, 0x3E, 0xB4,\n");
8145  output ("\t0x45, 0x55, 0xCE, 0xDE, 0x49, 0x69, 0x9A, 0x9B,\n");
8146  output ("\t0xAB, 0x9F, 0xBA, 0xB8, 0xB7, 0xAA, 0x8A, 0x8B,\n");
8147  output ("\t0xB6, 0xB5, 0x62, 0x4F, 0x64, 0x65, 0x66, 0x20,\n");
8148  output ("\t0x21, 0x22, 0x70, 0x23, 0x72, 0x73, 0x74, 0xBE,\n");
8149  output ("\t0x76, 0x77, 0x78, 0x80, 0x24, 0x15, 0x8C, 0x8D,\n");
8150  output ("\t0x8E, 0x41, 0x06, 0x17, 0x28, 0x29, 0x9D, 0x2A,\n");
8151  output ("\t0x2B, 0x2C, 0x09, 0x0A, 0xAC, 0x4A, 0xAE, 0xAF,\n");
8152  output ("\t0x1B, 0x30, 0x31, 0xFA, 0x1A, 0x33, 0x34, 0x35,\n");
8153  output ("\t0x36, 0x59, 0x08, 0x38, 0xBC, 0x39, 0xA0, 0xBF,\n");
8154  output ("\t0xCA, 0x3A, 0xFE, 0x3B, 0x04, 0xCF, 0xDA, 0x14,\n");
8155  output ("\t0xE1, 0x8F, 0x46, 0x75, 0xFD, 0xEB, 0xEE, 0xED,\n");
8156  output ("\t0x90, 0xEF, 0xB3, 0xFB, 0xB9, 0xEA, 0xBB, 0xFF\n");
8157  output ("};\n");
8158  if (gen_full_ebcdic > 1) {
8159  i = lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
8160  output
8161  ("static cob_field f_ascii_ebcdic = { 256, (cob_u8_ptr)cob_ascii_ebcdic, &%s%d };\n",
8162  CB_PREFIX_ATTR, i);
8163  }
8164  output_storage ("\n");
8165  }
8166  if (gen_ebcdic_ascii) {
8167  output_storage ("\n/* EBCDIC to ASCII table */\n");
8168  output ("static const unsigned char\tcob_ebcdic_ascii[256] = {\n");
8169  output ("\t0x00, 0x01, 0x02, 0x03, 0xEC, 0x09, 0xCA, 0x7F,\n");
8170  output ("\t0xE2, 0xD2, 0xD3, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,\n");
8171  output ("\t0x10, 0x11, 0x12, 0x13, 0xEF, 0xC5, 0x08, 0xCB,\n");
8172  output ("\t0x18, 0x19, 0xDC, 0xD8, 0x1C, 0x1D, 0x1E, 0x1F,\n");
8173  output ("\t0xB7, 0xB8, 0xB9, 0xBB, 0xC4, 0x0A, 0x17, 0x1B,\n");
8174  output ("\t0xCC, 0xCD, 0xCF, 0xD0, 0xD1, 0x05, 0x06, 0x07,\n");
8175  output ("\t0xD9, 0xDA, 0x16, 0xDD, 0xDE, 0xDF, 0xE0, 0x04,\n");
8176  output ("\t0xE3, 0xE5, 0xE9, 0xEB, 0x14, 0x15, 0x9E, 0x1A,\n");
8177  output ("\t0x20, 0xC9, 0x83, 0x84, 0x85, 0xA0, 0xF2, 0x86,\n");
8178  output ("\t0x87, 0xA4, 0xD5, 0x2E, 0x3C, 0x28, 0x2B, 0xB3,\n");
8179  output ("\t0x26, 0x82, 0x88, 0x89, 0x8A, 0xA1, 0x8C, 0x8B,\n");
8180  output ("\t0x8D, 0xE1, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E,\n");
8181  output ("\t0x2D, 0x2F, 0xB2, 0x8E, 0xB4, 0xB5, 0xB6, 0x8F,\n");
8182  output ("\t0x80, 0xA5, 0x7C, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,\n");
8183  output ("\t0xBA, 0x90, 0xBC, 0xBD, 0xBE, 0xF3, 0xC0, 0xC1,\n");
8184  output ("\t0xC2, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22,\n");
8185  output ("\t0xC3, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,\n");
8186  output ("\t0x68, 0x69, 0xAE, 0xAF, 0xC6, 0xC7, 0xC8, 0xF1,\n");
8187  output ("\t0xF8, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70,\n");
8188  output ("\t0x71, 0x72, 0xA6, 0xA7, 0x91, 0xCE, 0x92, 0xA9,\n");
8189  output ("\t0xE6, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,\n");
8190  output ("\t0x79, 0x7A, 0xAD, 0xA8, 0xD4, 0x5B, 0xD6, 0xD7,\n");
8191  output ("\t0x9B, 0x9C, 0x9D, 0xFA, 0x9F, 0xB1, 0xB0, 0xAC,\n");
8192  output ("\t0xAB, 0xFC, 0xAA, 0xFE, 0xE4, 0x5D, 0xBF, 0xE7,\n");
8193  output ("\t0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,\n");
8194  output ("\t0x48, 0x49, 0xE8, 0x93, 0x94, 0x95, 0xA2, 0xED,\n");
8195  output ("\t0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,\n");
8196  output ("\t0x51, 0x52, 0xEE, 0x96, 0x81, 0x97, 0xA3, 0x98,\n");
8197  output ("\t0x5C, 0xF0, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,\n");
8198  output ("\t0x59, 0x5A, 0xFD, 0xF5, 0x99, 0xF7, 0xF6, 0xF9,\n");
8199  output ("\t0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,\n");
8200  output ("\t0x38, 0x39, 0xDB, 0xFB, 0x9A, 0xF4, 0xEA, 0xFF\n");
8201  output ("};\n");
8202  if (gen_ebcdic_ascii > 1) {
8203  i = lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
8204  output
8205  ("static cob_field f_ebcdic_ascii = { 256, (cob_u8_ptr)cob_ebcdic_ascii, &%s%d };\n",
8206  CB_PREFIX_ATTR, i);
8207  }
8208  output_storage ("\n");
8209  }
8210  if (gen_native) {
8211  output_storage ("\n/* NATIVE table */\n");
8212  output ("static const unsigned char\tcob_native[256] = {\n");
8213  output ("\t0, 1, 2, 3, 4, 5, 6, 7,\n");
8214  output ("\t8, 9, 10, 11, 12, 13, 14, 15,\n");
8215  output ("\t16, 17, 18, 19, 20, 21, 22, 23,\n");
8216  output ("\t24, 25, 26, 27, 28, 29, 30, 31,\n");
8217  output ("\t32, 33, 34, 35, 36, 37, 38, 39,\n");
8218  output ("\t40, 41, 42, 43, 44, 45, 46, 47,\n");
8219  output ("\t48, 49, 50, 51, 52, 53, 54, 55,\n");
8220  output ("\t56, 57, 58, 59, 60, 61, 62, 63,\n");
8221  output ("\t64, 65, 66, 67, 68, 69, 70, 71,\n");
8222  output ("\t72, 73, 74, 75, 76, 77, 78, 79,\n");
8223  output ("\t80, 81, 82, 83, 84, 85, 86, 87,\n");
8224  output ("\t88, 89, 90, 91, 92, 93, 94, 95,\n");
8225  output ("\t96, 97, 98, 99, 100, 101, 102, 103,\n");
8226  output ("\t104, 105, 106, 107, 108, 109, 110, 111,\n");
8227  output ("\t112, 113, 114, 115, 116, 117, 118, 119,\n");
8228  output ("\t120, 121, 122, 123, 124, 125, 126, 127,\n");
8229  output ("\t128, 129, 130, 131, 132, 133, 134, 135,\n");
8230  output ("\t136, 137, 138, 139, 140, 141, 142, 143,\n");
8231  output ("\t144, 145, 146, 147, 148, 149, 150, 151,\n");
8232  output ("\t152, 153, 154, 155, 156, 157, 158, 159,\n");
8233  output ("\t160, 161, 162, 163, 164, 165, 166, 167,\n");
8234  output ("\t168, 169, 170, 171, 172, 173, 174, 175,\n");
8235  output ("\t176, 177, 178, 179, 180, 181, 182, 183,\n");
8236  output ("\t184, 185, 186, 187, 188, 189, 190, 191,\n");
8237  output ("\t192, 193, 194, 195, 196, 197, 198, 199,\n");
8238  output ("\t200, 201, 202, 203, 204, 205, 206, 207,\n");
8239  output ("\t208, 209, 210, 211, 212, 213, 214, 215,\n");
8240  output ("\t216, 217, 218, 219, 220, 221, 222, 223,\n");
8241  output ("\t224, 225, 226, 227, 228, 229, 230, 231,\n");
8242  output ("\t232, 233, 234, 235, 236, 237, 238, 239,\n");
8243  output ("\t240, 241, 242, 243, 244, 245, 246, 247,\n");
8244  output ("\t248, 249, 250, 251, 252, 253, 254, 255\n");
8245  output ("};\n");
8246  if (gen_native > 1) {
8247  i = lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
8248  output
8249  ("static cob_field f_native = { 256, (cob_u8_ptr)cob_native, &%s%d };\n",
8250  CB_PREFIX_ATTR, i);
8251  }
8252  output_storage ("\n");
8253  }
8254 
8255  /* Strings */
8256  if (string_cache) {
8257  output_storage ("\n/* Strings */\n");
8259  for (stp = string_cache; stp; stp = stp->next) {
8260  output ("static const char %s%d[]\t= \"%s\";\n",
8261  CB_PREFIX_STRING, stp->id, stp->text);
8262  }
8263  output_storage ("\n");
8264  }
8265 
8266  /* Optimizer output */
8267  for (optidx = COB_OPTIM_MIN; optidx < COB_OPTIM_MAX; ++optidx) {
8268  if (optimize_defs[optidx]) {
8269  cob_gen_optim (optidx);
8270  output_storage ("\n");
8271  }
8272  }
8273 }
static int field_cache_cmp(const void *mp1, const void *mp2)
Definition: codegen.c:313
int scale
Definition: codegen.c:88
const char * name
Definition: tree.h:645
unsigned char * pic
Definition: codegen.c:84
static unsigned int needs_unifunc
Definition: codegen.c:147
#define CB_NEED_QUOTE
Definition: codegen.c:57
void * cobc_main_malloc(const size_t size)
Definition: cobc.c:702
struct cb_field * local_storage
Definition: tree.h:1277
short sign
Definition: tree.h:597
static void output_newline(void)
Definition: codegen.c:433
static unsigned int gen_alt_ebcdic
Definition: codegen.c:150
#define cob_u32_t
Definition: common.h:31
#define CB_PREFIX_STRING
Definition: tree.h:39
unsigned int flag_filler
Definition: tree.h:714
struct cb_field * f
Definition: codegen.c:114
const char * cb_source_file
Definition: cobc.c:145
static FILE * output_target
Definition: codegen.c:135
cob_u32_t digits
Definition: codegen.c:87
cb_tree x
Definition: codegen.c:96
int toplev_count
Definition: tree.h:1297
FILE * cb_storage_file
Definition: cobc.c:156
static unsigned int gen_custom
Definition: codegen.c:154
static int local_working_mem
Definition: codegen.c:170
unsigned int flag_global_use
Definition: tree.h:1312
static void output(const char *,...)
Definition: codegen.c:192
#define CB_LITERAL(x)
Definition: tree.h:601
void codegen(struct cb_program *prog, const int nested)
Definition: codegen.c:7448
#define COB_TYPE_ALPHANUMERIC
Definition: common.h:621
const char * callname
Definition: codegen.c:109
static int loop_counter
Definition: codegen.c:163
static int lookup_attr(const int type, const cob_u32_t digits, const int scale, const cob_u32_t flags, unsigned char *pic, const int lenstr)
Definition: codegen.c:880
static unsigned int i_counters[16]
Definition: codegen.c:179
static unsigned int gen_ebcdic_ascii
Definition: codegen.c:151
static const char * excp_current_paragraph
Definition: codegen.c:139
char * text
Definition: codegen.c:78
static struct attr_list * attr_list_reverse(struct attr_list *p)
Definition: codegen.c:269
static struct string_list * string_cache
Definition: codegen.c:130
static void output_entry_function(struct cb_program *prog, cb_tree entry, cb_tree parameter_list, const int gencode)
Definition: codegen.c:6866
static void output_local(const char *fmt,...)
Definition: codegen.c:527
const char * cb_storage_file_name
Definition: cobc.c:148
int nested_level
Definition: tree.h:1295
struct field_list * next
Definition: codegen.c:101
int max_call_param
Definition: tree.h:1298
static int working_mem
Definition: codegen.c:169
static void output_string(const unsigned char *s, const int size, const cob_u32_t llit)
Definition: codegen.c:489
unsigned int flag_main
Definition: tree.h:1305
#define COB_INSIDE_SIZE
Definition: codegen.c:48
struct nested_list * next
Definition: tree.h:1234
#define COB_MINI_BUFF
Definition: common.h:539
static void output_class_name_definition(struct cb_class_name *p)
Definition: codegen.c:5544
struct local_filename * local_include
Definition: tree.h:1248
static unsigned int gen_dynamic
Definition: codegen.c:156
cob_u32_t special_index
Definition: tree.h:690
#define CB_PREFIX_BASE
Definition: tree.h:31
static void output_storage(const char *fmt,...)
Definition: codegen.c:515
unsigned int flag_debugging
Definition: tree.h:1320
static struct label_list * label_cache
Definition: codegen.c:132
#define CB_NEED_SPACE
Definition: codegen.c:58
struct call_list * next
Definition: codegen.c:108
static unsigned int gen_native
Definition: codegen.c:153
static struct literal_list * literal_cache
Definition: codegen.c:122
#define CB_VALUE(x)
Definition: tree.h:1193
#define CB_PREFIX_ATTR
Definition: tree.h:30
#define CB_TREE_CLASS(x)
Definition: tree.h:442
#define yyout
Definition: pplex.c:20
static struct cb_program * current_prog
Definition: codegen.c:140
int id
Definition: tree.h:671
static struct literal_list * literal_list_reverse(struct literal_list *p)
Definition: codegen.c:299
static void * list_cache_sort(void *inlist, int(*cmpfunc)(const void *mp1, const void *mp2))
Definition: codegen.c:340
static int last_line
Definition: codegen.c:165
struct cb_program * nested_prog
Definition: tree.h:1235
static void output_size(const cb_tree x)
Definition: codegen.c:793
static void output_field(cb_tree x)
Definition: codegen.c:1045
static void output_internal_function(struct cb_program *prog, cb_tree parameter_list)
Definition: codegen.c:5793
static void output_main_function(struct cb_program *prog)
Definition: codegen.c:7412
#define _(s)
Definition: cobcrun.c:59
static struct field_list * local_field_cache
Definition: codegen.c:124
static int string_id
Definition: codegen.c:160
#define CB_CHAIN(x)
Definition: tree.h:1194
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static int non_nested_count
Definition: codegen.c:162
cob_u32_t llit
Definition: tree.h:596
static const char * excp_current_section
Definition: codegen.c:138
cb_optim
Definition: cobc.h:266
struct cb_field * f
Definition: codegen.c:102
struct cb_program * next_program
Definition: tree.h:1242
unsigned char prog_type
Definition: tree.h:1303
cob_u32_t flags
Definition: codegen.c:89
static struct field_list * field_cache
Definition: codegen.c:123
cb_tree alphabet_name_list
Definition: tree.h:1256
struct base_list * next
Definition: codegen.c:113
static const char * excp_current_program_id
Definition: codegen.c:137
#define CB_PROGRAM_TYPE
Definition: tree.h:41
#define COB_KEYWORD_INLINE
Definition: cobxref.c:13
static int gen_if_level
Definition: codegen.c:173
cb_tree entry_list
Definition: tree.h:1251
#define COB_TYPE_ALPHANUMERIC_ALL
Definition: common.h:622
unsigned char * data
Definition: tree.h:593
#define CB_NEED_LOW
Definition: codegen.c:56
static unsigned int inside_check
Definition: codegen.c:176
static struct base_list * local_base_cache
Definition: codegen.c:129
static void output_header(FILE *fp, const char *locbuff, const struct cb_program *cp)
Definition: codegen.c:7424
static struct call_list * call_cache
Definition: codegen.c:125
static unsigned int gen_nested_tab
Definition: codegen.c:149
static unsigned int gen_figurative
Definition: codegen.c:155
cb_tree x
Definition: codegen.c:103
static unsigned int needs_exit_prog
Definition: codegen.c:146
const char * program_id
Definition: tree.h:1244
cb_tree class_name_list
Definition: tree.h:1258
static int param_id
Definition: codegen.c:158
struct literal_list * next
Definition: codegen.c:94
unsigned int flag_recursive
Definition: tree.h:1308
int type
Definition: codegen.c:86
unsigned int flag_chained
Definition: tree.h:1311
static int base_cache_cmp(const void *mp1, const void *mp2)
Definition: codegen.c:327
#define CB_FUNCTION_TYPE
Definition: tree.h:42
const char * curr_prog
Definition: codegen.c:115
static struct attr_list * attr_cache
Definition: codegen.c:121
static struct cb_label * last_section
Definition: codegen.c:142
cb_tree parameter_list
Definition: tree.h:1259
#define CB_PREFIX_CONST
Definition: tree.h:32
#define COB_ALIGN
Definition: codegen.c:41
struct string_list * next
Definition: codegen.c:77
static struct string_list * string_list_reverse(struct string_list *p)
Definition: codegen.c:284
static unsigned int inside_stack[64]
Definition: codegen.c:177
void cob_gen_optim(const enum cb_optim)
Definition: codeoptim.c:48
#define CB_NEED_HIGH
Definition: codegen.c:55
static struct base_list * base_cache
Definition: codegen.c:127
#define COB_MAX_SUBSCRIPTS
Definition: codegen.c:44
struct nested_list * nested_prog_list
Definition: tree.h:1249
static FILE * cb_local_file
Definition: codegen.c:136
static int output_indent_level
Definition: codegen.c:171
static unsigned int gen_full_ebcdic
Definition: codegen.c:152
int memory_size
Definition: tree.h:674
static void output_attr(const cb_tree x)
Definition: codegen.c:929
int id
Definition: codegen.c:79
static int num_cob_fields
Definition: codegen.c:161
const char * curr_prog
Definition: codegen.c:104
#define CB_CLASS_NAME(x)
Definition: tree.h:562
unsigned int flag_local
Definition: tree.h:701
int id
Definition: codegen.c:85
cob_u32_t optimize_defs[COB_OPTIM_MAX]
Definition: cobc.c:182
#define PACKAGE_VERSION
Definition: config.h:312
struct attr_list * next
Definition: codegen.c:83
static struct base_list * globext_cache
Definition: codegen.c:128
static unsigned int need_save_exception
Definition: codegen.c:148
static int progid
Definition: codegen.c:164
cob_u32_t size
Definition: tree.h:594
static int local_mem
Definition: codegen.c:168
#define CB_PREFIX_FIELD
Definition: tree.h:34
int cobc_flag_main
Definition: cobc.c:167
static int stack_id
Definition: codegen.c:159
FILE * local_fp
Definition: cobc.h:191
static char * string_buffer
Definition: codegen.c:131
#define PATCH_LEVEL
Definition: config.h:315
#define CB_NEED_ZERO
Definition: codegen.c:59
static int last_segment
Definition: codegen.c:172
char * orig_program_id
Definition: tree.h:1246
static struct call_list * func_call_cache
Definition: codegen.c:126
#define COB_MINI_MAX
Definition: common.h:545
#define CB_XSTRINGIFY(s)
Definition: cobc.h:74
cb_tree cb_list_add(cb_tree l, cb_tree x)
Definition: tree.c:1315

Here is the call graph for this function:

Here is the caller graph for this function:

static int field_cache_cmp ( const void *  mp1,
const void *  mp2 
)
static

Definition at line 313 of file codegen.c.

References field_list::curr_prog, field_list::f, and cb_field::id.

Referenced by codegen().

313  {
314  const struct field_list *fl1;
315  const struct field_list *fl2;
316  int ret;
317 
318  fl1 = (const struct field_list *)mp1;
319  fl2 = (const struct field_list *)mp2;
320  ret = strcasecmp (fl1->curr_prog, fl2->curr_prog);
321  if (ret) {
322  return ret;
323  }
324  return fl1->f->id - fl2->f->id;
325 }
int id
Definition: tree.h:671
struct cb_field * f
Definition: codegen.c:102
const char * curr_prog
Definition: codegen.c:104

Here is the caller graph for this function:

static int initialize_type ( struct cb_initialize p,
struct cb_field f,
const int  topfield 
)
static

Definition at line 2251 of file codegen.c.

References _, CB_CATEGORY_ALPHANUMERIC_EDITED, CB_CATEGORY_NATIONAL_EDITED, CB_CATEGORY_NUMERIC_EDITED, CB_CHAIN, CB_PURPOSE_INT, CB_TREE, CB_TREE_CATEGORY, cb_tree_type(), CB_USAGE_DOUBLE, CB_USAGE_FLOAT, CB_USAGE_FP_BIN128, CB_USAGE_FP_BIN32, CB_USAGE_FP_BIN64, CB_USAGE_FP_DEC128, CB_USAGE_FP_DEC64, CB_USAGE_LONG_DOUBLE, cb_field::children, COB_TYPE_NUMERIC_PACKED, COBC_ABORT, cobc_abort_pr(), cb_field::flag_chained, cb_initialize::flag_default, cb_field::flag_external, cb_field::flag_filler, cb_initialize::flag_init_statement, cb_field::flag_item_78, cb_initialize::flag_no_filler_init, INITIALIZE_COMPOUND, INITIALIZE_DEFAULT, INITIALIZE_NONE, INITIALIZE_ONE, cb_field::redefines, cb_initialize::rep, cb_field::sister, cb_field::usage, cb_initialize::val, and cb_field::values.

Referenced by output_initialize(), and output_initialize_compound().

2252 {
2253  cb_tree l;
2254  int type;
2255 
2256  if (f->flag_item_78) {
2257  cobc_abort_pr (_("Unexpected CONSTANT item"));
2258  COBC_ABORT ();
2259  }
2260 
2261  if (f->flag_chained) {
2262  return INITIALIZE_ONE;
2263  }
2264 
2265  if (f->flag_external && !p->flag_init_statement) {
2266  return INITIALIZE_NONE;
2267  }
2268 
2269  if (f->redefines && (!topfield || !p->flag_init_statement)) {
2270  return INITIALIZE_NONE;
2271  }
2272 
2273  if (f->flag_filler && p->flag_no_filler_init && !f->children) {
2274  return INITIALIZE_NONE;
2275  }
2276 
2277  if (p->val && f->values) {
2278  return INITIALIZE_ONE;
2279  }
2280 
2281  if (f->children) {
2282  type = initialize_type (p, f->children, 0);
2283  if (type == INITIALIZE_ONE) {
2284  return INITIALIZE_COMPOUND;
2285  }
2286  for (f = f->children->sister; f; f = f->sister) {
2287  if (type != initialize_type (p, f, 0)) {
2288  return INITIALIZE_COMPOUND;
2289  }
2290  }
2291  return type;
2292  } else {
2293  for (l = p->rep; l; l = CB_CHAIN (l)) {
2294  if ((int)CB_PURPOSE_INT (l) == (int)CB_TREE_CATEGORY (f)) {
2295  return INITIALIZE_ONE;
2296  }
2297  }
2298  }
2299 
2300  if (p->flag_default) {
2301  if (cb_default_byte >= 0 && !p->flag_init_statement) {
2302  return INITIALIZE_DEFAULT;
2303  }
2304  switch (f->usage) {
2305  case CB_USAGE_FLOAT:
2306  case CB_USAGE_DOUBLE:
2307  case CB_USAGE_LONG_DOUBLE:
2308  case CB_USAGE_FP_BIN32:
2309  case CB_USAGE_FP_BIN64:
2310  case CB_USAGE_FP_BIN128:
2311  case CB_USAGE_FP_DEC64:
2312  case CB_USAGE_FP_DEC128:
2313  return INITIALIZE_ONE;
2314  default:
2315  break;
2316  }
2317  switch (CB_TREE_CATEGORY (f)) {
2321  return INITIALIZE_ONE;
2322  default:
2323  if (cb_tree_type (CB_TREE (f), f) == COB_TYPE_NUMERIC_PACKED) {
2324  return INITIALIZE_ONE;
2325  } else {
2326  return INITIALIZE_DEFAULT;
2327  }
2328  }
2329  }
2330 
2331  return INITIALIZE_NONE;
2332 }
#define CB_TREE(x)
Definition: tree.h:440
#define CB_TREE_CATEGORY(x)
Definition: tree.h:443
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
unsigned int flag_filler
Definition: tree.h:714
#define COB_TYPE_NUMERIC_PACKED
Definition: common.h:609
struct cb_field * sister
Definition: tree.h:653
struct cb_field * children
Definition: tree.h:652
#define INITIALIZE_COMPOUND
Definition: codegen.c:53
#define CB_PURPOSE_INT(x)
Definition: tree.h:1197
#define INITIALIZE_DEFAULT
Definition: codegen.c:52
unsigned char flag_default
Definition: tree.h:1011
#define INITIALIZE_NONE
Definition: codegen.c:50
unsigned char flag_init_statement
Definition: tree.h:1012
unsigned int flag_item_78
Definition: tree.h:711
#define INITIALIZE_ONE
Definition: codegen.c:51
#define _(s)
Definition: cobcrun.c:59
static int initialize_type(struct cb_initialize *p, struct cb_field *f, const int topfield)
Definition: codegen.c:2251
#define CB_CHAIN(x)
Definition: tree.h:1194
#define COBC_ABORT()
Definition: cobc.h:61
unsigned char flag_no_filler_init
Definition: tree.h:1013
cb_tree val
Definition: tree.h:1009
struct cb_field * redefines
Definition: tree.h:654
cb_tree values
Definition: tree.h:648
cb_tree rep
Definition: tree.h:1010
unsigned int flag_chained
Definition: tree.h:719
int cb_tree_type(const cb_tree x, const struct cb_field *f)
Definition: tree.c:849
enum cb_usage usage
Definition: tree.h:693
unsigned char flag_external
Definition: tree.h:697

Here is the call graph for this function:

Here is the caller graph for this function:

static int initialize_uniform_char ( const struct cb_field f,
const struct cb_initialize p 
)
static

Definition at line 2335 of file codegen.c.

References CB_TREE, cb_tree_type(), cb_field::children, COB_TYPE_ALPHANUMERIC, COB_TYPE_NUMERIC_BINARY, COB_TYPE_NUMERIC_DISPLAY, cb_initialize::flag_init_statement, cb_field::redefines, and cb_field::sister.

Referenced by output_initialize(), and output_initialize_compound().

2337 {
2338  int c;
2339 
2340  if (f->children) {
2341  c = initialize_uniform_char (f->children, p);
2342  for (f = f->children->sister; f; f = f->sister) {
2343  if (!f->redefines) {
2344  if (c != initialize_uniform_char (f, p)) {
2345  return -1;
2346  }
2347  }
2348  }
2349  return c;
2350  } else {
2351  if (cb_default_byte >= 0 && !p->flag_init_statement) {
2352  return cb_default_byte;
2353  }
2354  switch (cb_tree_type (CB_TREE (f), f)) {
2356  return 0;
2358  return '0';
2359  case COB_TYPE_ALPHANUMERIC:
2360  return ' ';
2361  default:
2362  return -1;
2363  }
2364  }
2365 }
#define CB_TREE(x)
Definition: tree.h:440
struct cb_field * sister
Definition: tree.h:653
struct cb_field * children
Definition: tree.h:652
#define COB_TYPE_ALPHANUMERIC
Definition: common.h:621
unsigned char flag_init_statement
Definition: tree.h:1012
#define COB_TYPE_NUMERIC_BINARY
Definition: common.h:608
#define COB_TYPE_NUMERIC_DISPLAY
Definition: common.h:607
struct cb_field * redefines
Definition: tree.h:654
int cb_tree_type(const cb_tree x, const struct cb_field *f)
Definition: tree.c:849
static int initialize_uniform_char(const struct cb_field *f, const struct cb_initialize *p)
Definition: codegen.c:2335

Here is the call graph for this function:

Here is the caller graph for this function:

static void* list_cache_sort ( void *  inlist,
int(*)(const void *mp1, const void *mp2)  cmpfunc 
)
static

Definition at line 340 of file codegen.c.

References sort_list::next, and NULL.

Referenced by codegen().

341 {
342  struct sort_list *p;
343  struct sort_list *q;
344  struct sort_list *e;
345  struct sort_list *tail;
346  struct sort_list *list;
347  size_t insize;
348  size_t nmerges;
349  size_t psize;
350  size_t qsize;
351  size_t i;
352 
353  if (!inlist) {
354  return NULL;
355  }
356  list = (struct sort_list *)inlist;
357  insize = 1;
358  for (;;) {
359  p = list;
360  list = NULL;
361  tail = NULL;
362  nmerges = 0;
363  while (p) {
364  nmerges++;
365  q = p;
366  psize = 0;
367  for (i = 0; i < insize; i++) {
368  psize++;
369  q = q->next;
370  if (!q) {
371  break;
372  }
373  }
374  qsize = insize;
375  while (psize > 0 || (qsize > 0 && q)) {
376  if (psize == 0) {
377  e = q;
378  q = q->next;
379  if (qsize) {
380  qsize--;
381  }
382  } else if (qsize == 0 || !q) {
383  e = p;
384  p = p->next;
385  if (psize) {
386  psize--;
387  }
388  } else if ((*cmpfunc) (p, q) <= 0) {
389  e = p;
390  p = p->next;
391  if (psize) {
392  psize--;
393  }
394  } else {
395  e = q;
396  q = q->next;
397  if (qsize) {
398  qsize--;
399  }
400  }
401  if (tail) {
402  tail->next = e;
403  } else {
404  list = e;
405  }
406  tail = e;
407  }
408  p = q;
409  }
410  tail->next = NULL;
411  if (nmerges <= 1) {
412  return (void *)list;
413  }
414  insize *= 2;
415  }
416 }
struct sort_list * next
Definition: codegen.c:62
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95

Here is the caller graph for this function:

static struct literal_list* literal_list_reverse ( struct literal_list p)
static

Definition at line 299 of file codegen.c.

References literal_list::next, and NULL.

Referenced by codegen().

300 {
301  struct literal_list *next;
302  struct literal_list *last;
303 
304  last = NULL;
305  for (; p; p = next) {
306  next = p->next;
307  p->next = last;
308  last = p;
309  }
310  return last;
311 }
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
struct literal_list * next
Definition: codegen.c:94

Here is the caller graph for this function:

static int literal_value ( cb_tree  x)
static

Definition at line 5489 of file codegen.c.

References CB_CLASS_NUMERIC, cb_get_int(), CB_LITERAL, cb_norm_high, cb_norm_low, cb_null, cb_quote, cb_space, CB_TREE_CLASS, and cb_zero.

Referenced by output_class_name_definition().

5490 {
5491  if (x == cb_space) {
5492  return ' ';
5493  } else if (x == cb_zero) {
5494  return '0';
5495  } else if (x == cb_quote) {
5496  return cb_flag_apostrophe ? '\'' : '"';
5497  } else if (x == cb_norm_low) {
5498  return 0;
5499  } else if (x == cb_norm_high) {
5500  return 255;
5501  } else if (x == cb_null) {
5502  return 0;
5503  } else if (CB_TREE_CLASS (x) == CB_CLASS_NUMERIC) {
5504  return cb_get_int (x) - 1;
5505  } else {
5506  return CB_LITERAL (x)->data[0];
5507  }
5508 }
cb_tree cb_norm_high
Definition: tree.c:131
#define CB_LITERAL(x)
Definition: tree.h:601
int cb_get_int(const cb_tree x)
Definition: tree.c:1101
cb_tree cb_norm_low
Definition: tree.c:130
cb_tree cb_zero
Definition: tree.c:125
cb_tree cb_quote
Definition: tree.c:132
cb_tree cb_space
Definition: tree.c:127
#define CB_TREE_CLASS(x)
Definition: tree.h:442
cb_tree cb_null
Definition: tree.c:124

Here is the call graph for this function:

Here is the caller graph for this function:

static int lookup_attr ( const int  type,
const cob_u32_t  digits,
const int  scale,
const cob_u32_t  flags,
unsigned char *  pic,
const int  lenstr 
)
static

Definition at line 880 of file codegen.c.

References attr_cache, cb_attr_id, cobc_parse_malloc(), attr_list::digits, attr_list::flags, attr_list::id, attr_list::lenstr, attr_list::next, attr_list::pic, attr_list::scale, and attr_list::type.

Referenced by codegen(), output_alphabet_name_definition(), output_attr(), and output_bin_field().

882 {
883  struct attr_list *l;
884 
885  /* Search attribute cache */
886  for (l = attr_cache; l; l = l->next) {
887  if (type == l->type &&
888  digits == l->digits &&
889  scale == l->scale &&
890  flags == l->flags &&
891  ((pic == l->pic) || (pic && l->pic && lenstr == l->lenstr &&
892  memcmp ((char *)pic, (char *)(l->pic), (size_t)lenstr) == 0))) {
893  return l->id;
894  }
895  }
896 
897  /* Cache new attribute */
898 
899  l = cobc_parse_malloc (sizeof (struct attr_list));
900  l->id = cb_attr_id;
901  l->type = type;
902  l->digits = digits;
903  l->scale = scale;
904  l->flags = flags;
905  l->pic = pic;
906  l->lenstr = lenstr;
907  l->next = attr_cache;
908  attr_cache = l;
909 
910  return cb_attr_id++;
911 }
int scale
Definition: codegen.c:88
unsigned char * pic
Definition: codegen.c:84
cob_u32_t digits
Definition: codegen.c:87
void * cobc_parse_malloc(const size_t size)
Definition: cobc.c:809
int lenstr
Definition: codegen.c:90
cob_u32_t flags
Definition: codegen.c:89
int type
Definition: codegen.c:86
static struct attr_list * attr_cache
Definition: codegen.c:121
int cb_attr_id
Definition: cobc.c:164
int id
Definition: codegen.c:85
struct attr_list * next
Definition: codegen.c:83

Here is the call graph for this function:

Here is the caller graph for this function:

static void lookup_call ( const char *  p)
static

Definition at line 237 of file codegen.c.

References call_cache, call_list::callname, cobc_parse_malloc(), and call_list::next.

Referenced by output_call().

238 {
239  struct call_list *clp;
240 
241  for (clp = call_cache; clp; clp = clp->next) {
242  if (strcmp (p, clp->callname) == 0) {
243  return;
244  }
245  }
246  clp = cobc_parse_malloc (sizeof (struct call_list));
247  clp->callname = p;
248  clp->next = call_cache;
249  call_cache = clp;
250 }
void * cobc_parse_malloc(const size_t size)
Definition: cobc.c:809
const char * callname
Definition: codegen.c:109
struct call_list * next
Definition: codegen.c:108
static struct call_list * call_cache
Definition: codegen.c:125

Here is the call graph for this function:

Here is the caller graph for this function:

static void lookup_func_call ( const char *  p)
static

Definition at line 253 of file codegen.c.

References call_list::callname, cobc_parse_malloc(), func_call_cache, and call_list::next.

Referenced by output_param().

254 {
255  struct call_list *clp;
256 
257  for (clp = func_call_cache; clp; clp = clp->next) {
258  if (strcmp (p, clp->callname) == 0) {
259  return;
260  }
261  }
262  clp = cobc_parse_malloc (sizeof (struct call_list));
263  clp->callname = p;
264  clp->next = func_call_cache;
265  func_call_cache = clp;
266 }
void * cobc_parse_malloc(const size_t size)
Definition: cobc.c:809
const char * callname
Definition: codegen.c:109
struct call_list * next
Definition: codegen.c:108
static struct call_list * func_call_cache
Definition: codegen.c:126

Here is the call graph for this function:

Here is the caller graph for this function:

static int lookup_literal ( cb_tree  x)
static

Definition at line 1059 of file codegen.c.

References cb_literal::all, CB_LITERAL, cb_literal_id, CB_TREE_CLASS, cobc_parse_malloc(), cb_literal::data, literal_list::id, literal_list::literal, literal_cache, literal_list::next, NULL, output_field(), output_target, cb_literal::scale, cb_literal::sign, cb_literal::size, and literal_list::x.

Referenced by output_param().

1060 {
1061 
1062  struct cb_literal *literal;
1063  struct literal_list *l;
1064  FILE *savetarget;
1065 
1066  literal = CB_LITERAL (x);
1067  /* Search literal cache */
1068  for (l = literal_cache; l; l = l->next) {
1069  if (CB_TREE_CLASS (literal) == CB_TREE_CLASS (l->literal) &&
1070  literal->size == l->literal->size &&
1071  literal->all == l->literal->all &&
1072  literal->sign == l->literal->sign &&
1073  literal->scale == l->literal->scale &&
1074  memcmp (literal->data, l->literal->data,
1075  (size_t)literal->size) == 0) {
1076  return l->id;
1077  }
1078  }
1079 
1080  /* Output new literal */
1081  savetarget = output_target;
1082  output_target = NULL;
1083  output_field (x);
1084 
1085  output_target = savetarget;
1086 
1087  /* Cache it */
1088  l = cobc_parse_malloc (sizeof (struct literal_list));
1089  l->id = cb_literal_id;
1090  l->literal = literal;
1091  l->x = x;
1092  l->next = literal_cache;
1093  literal_cache = l;
1094 
1095  return cb_literal_id++;
1096 }
struct cb_literal * literal
Definition: codegen.c:95
short sign
Definition: tree.h:597
static FILE * output_target
Definition: codegen.c:135
cb_tree x
Definition: codegen.c:96
void * cobc_parse_malloc(const size_t size)
Definition: cobc.c:809
#define CB_LITERAL(x)
Definition: tree.h:601
short all
Definition: tree.h:598
static struct literal_list * literal_cache
Definition: codegen.c:122
#define CB_TREE_CLASS(x)
Definition: tree.h:442
static void output_field(cb_tree x)
Definition: codegen.c:1045
int scale
Definition: tree.h:595
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
unsigned char * data
Definition: tree.h:593
struct literal_list * next
Definition: codegen.c:94
int cb_literal_id
Definition: cobc.c:165
cob_u32_t size
Definition: tree.h:594

Here is the call graph for this function:

Here is the caller graph for this function:

static int lookup_string ( const char *  p)
static

Definition at line 219 of file codegen.c.

References cobc_parse_malloc(), cobc_parse_strdup(), string_list::id, string_list::next, string_cache, string_id, and string_list::text.

Referenced by output_internal_function(), output_section_info(), output_stmt(), and output_trace_info().

220 {
221  struct string_list *stp;
222 
223  for (stp = string_cache; stp; stp = stp->next) {
224  if (strcmp (p, stp->text) == 0) {
225  return stp->id;
226  }
227  }
228  stp = cobc_parse_malloc (sizeof (struct string_list));
229  stp->text = cobc_parse_strdup (p);
230  stp->id = string_id;
231  stp->next = string_cache;
232  string_cache = stp;
233  return string_id++;
234 }
void * cobc_parse_malloc(const size_t size)
Definition: cobc.c:809
char * text
Definition: codegen.c:78
static struct string_list * string_cache
Definition: codegen.c:130
void * cobc_parse_strdup(const char *dupstr)
Definition: cobc.c:827
static int string_id
Definition: codegen.c:160
struct string_list * next
Definition: codegen.c:77
int id
Definition: codegen.c:79

Here is the call graph for this function:

Here is the caller graph for this function:

static void output ( const char *  fmt,
  ... 
)
static

Definition at line 192 of file codegen.c.

References CB_FIELD, cb_ref(), CB_REFERENCE, CB_REFERENCE_P, likely, unlikely, and value.

Referenced by codegen(), output_attr(), output_base(), output_call(), output_call_by_value_args(), output_cancel(), output_cond(), output_data(), output_entry_function(), output_error_handler(), output_field(), output_figurative(), output_file_initialization(), output_func_1(), output_funcall(), output_goto(), output_index(), output_initialize_fp(), output_initialize_fp_bindec(), output_initialize_literal(), output_initialize_one(), output_initialize_uniform(), output_integer(), output_internal_function(), output_label_info(), output_long_integer(), output_module_init(), output_occurs(), output_param(), output_perform(), output_perform_until(), output_screen_init(), output_search_all(), output_search_whens(), output_size(), output_stmt(), output_string(), and output_trace_info().

208 {
209  if (likely(CB_REFERENCE_P (x))) {
210  if (unlikely(!CB_REFERENCE (x)->value)) {
211  return CB_FIELD (cb_ref (x));
212  }
213  return CB_FIELD (CB_REFERENCE (x)->value);
214  }
215  return CB_FIELD (x);
216 }
#define CB_REFERENCE_P(x)
Definition: tree.h:902
cb_tree cb_ref(cb_tree x)
Definition: tree.c:2653
strict implicit external value
Definition: warning.def:54
#define unlikely(x)
Definition: common.h:437
#define CB_REFERENCE(x)
Definition: tree.h:901
#define likely(x)
Definition: common.h:436
#define CB_FIELD(x)
Definition: tree.h:740

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_alphabet_name_definition ( struct cb_alphabet_name p)
static

Definition at line 5511 of file codegen.c.

References cb_alphabet_name::alphabet_type, CB_ALPHABET_CUSTOM, CB_PREFIX_ATTR, CB_PREFIX_FIELD, CB_PREFIX_SEQUENCE, cb_alphabet_name::cname, COB_TYPE_ALPHANUMERIC, lookup_attr(), NULL, output_local(), and cb_alphabet_name::values.

Referenced by output_internal_function().

5512 {
5513  int i;
5514 
5515  if (p->alphabet_type != CB_ALPHABET_CUSTOM) {
5516  return;
5517  }
5518 
5519  /* Output the table */
5520  output_local ("static const unsigned char %s%s[256] = {\n",
5522  for (i = 0; i < 256; i++) {
5523  if (i == 255) {
5524  output_local (" %d", p->values[i]);
5525  } else {
5526  output_local (" %d,", p->values[i]);
5527  }
5528  if (i % 16 == 15) {
5529  output_local ("\n");
5530  }
5531  }
5532  output_local ("};\n");
5533  i = lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
5534  output_local ("static cob_field %s%s = { 256, (cob_u8_ptr)%s%s, &%s%d };\n",
5535  CB_PREFIX_FIELD, p->cname,
5537  CB_PREFIX_ATTR, i);
5538  output_local ("\n");
5539 }
#define COB_TYPE_ALPHANUMERIC
Definition: common.h:621
static int lookup_attr(const int type, const cob_u32_t digits, const int scale, const cob_u32_t flags, unsigned char *pic, const int lenstr)
Definition: codegen.c:880
static void output_local(const char *fmt,...)
Definition: codegen.c:527
char * cname
Definition: tree.h:541
#define CB_PREFIX_ATTR
Definition: tree.h:30
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
int values[256]
Definition: tree.h:546
#define CB_ALPHABET_CUSTOM
Definition: tree.h:110
#define CB_PREFIX_SEQUENCE
Definition: tree.h:38
#define CB_PREFIX_FIELD
Definition: tree.h:34
unsigned int alphabet_type
Definition: tree.h:543

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_alter ( struct cb_alter p)
static

Definition at line 4460 of file codegen.c.

References cb_program::all_procedure, cb_build_debug(), cb_debug_contents, cb_debug_name, CB_LABEL, CB_PREFIX_LABEL, CB_REFERENCE, cb_label::debug_section, cb_label::flag_debugging_mode, cb_program::flag_gen_debug, cb_label::flag_real_label, cb_label::id, cb_label::name, NULL, output_line(), output_perform_call(), output_stmt(), cb_alter::source, and cb_alter::target.

Referenced by output_stmt().

4461 {
4462  struct cb_label *l1;
4463  struct cb_label *l2;
4464 
4465  l1 = CB_LABEL (CB_REFERENCE(p->source)->value);
4466  l2 = CB_LABEL (CB_REFERENCE(p->target)->value);
4467  output_line ("label_%s%d = %d;", CB_PREFIX_LABEL, l1->id, l2->id);
4468 
4469  /* Check for debugging on procedure name */
4473  (const char *)l1->name, NULL));
4475  (const char *)l2->name, NULL));
4476  if (current_prog->all_procedure) {
4479  } else if (l1->flag_debugging_mode) {
4481  l1->debug_section);
4482  }
4483  }
4484 }
#define CB_LABEL(x)
Definition: tree.h:801
const char * name
Definition: tree.h:766
unsigned int flag_gen_debug
Definition: tree.h:1321
#define CB_PREFIX_LABEL
Definition: tree.h:37
static void output_line(const char *fmt,...)
Definition: codegen.c:453
unsigned int flag_real_label
Definition: tree.h:781
static struct cb_program * current_prog
Definition: codegen.c:140
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
cb_tree cb_debug_name
Definition: typeck.c:84
unsigned int flag_debugging_mode
Definition: tree.h:796
#define CB_REFERENCE(x)
Definition: tree.h:901
static void output_perform_call(struct cb_label *lb, struct cb_label *le)
Definition: codegen.c:3905
cb_tree source
Definition: tree.h:1064
Definition: tree.h:764
struct cb_label * all_procedure
Definition: tree.h:1289
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
cb_tree cb_build_debug(const cb_tree target, const char *str, const cb_tree fld)
Definition: tree.c:1566
int id
Definition: tree.h:773
cb_tree cb_debug_contents
Definition: typeck.c:88
cb_tree target
Definition: tree.h:1065
struct cb_label * debug_section
Definition: tree.h:769

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_alter_check ( struct cb_label lp)
static

Definition at line 4636 of file codegen.c.

References cb_label::alter_gotos, CB_PREFIX_LABEL, cb_program::flag_segments, cb_alter_id::goto_id, cb_label::id, cb_alter_id::next, output_indent(), output_line(), output_local(), and output_newline().

Referenced by output_stmt().

4637 {
4638  struct cb_alter_id *aid;
4639 
4640  output_local ("static int\tlabel_%s%d = 0;\n",
4641  CB_PREFIX_LABEL, lp->id);
4642  if (current_prog->flag_segments) {
4643  output_local ("static int\tsave_label_%s%d = 0;\n",
4644  CB_PREFIX_LABEL, lp->id);
4645  }
4646  output_newline ();
4647  output_line ("/* ALTER processing */");
4648  output_line ("switch (label_%s%d)",
4649  CB_PREFIX_LABEL, lp->id);
4650  output_indent ("{");
4651  for (aid = lp->alter_gotos; aid; aid = aid->next) {
4652  output_line ("case %d:", aid->goto_id);
4653  output_line ("goto %s%d;", CB_PREFIX_LABEL, aid->goto_id);
4654  }
4655  output_indent ("}");
4656  output_newline ();
4657 }
static void output_newline(void)
Definition: codegen.c:433
#define CB_PREFIX_LABEL
Definition: tree.h:37
static void output_line(const char *fmt,...)
Definition: codegen.c:453
static void output_local(const char *fmt,...)
Definition: codegen.c:527
static struct cb_program * current_prog
Definition: codegen.c:140
struct cb_alter_id * next
Definition: tree.h:760
unsigned int flag_segments
Definition: tree.h:1317
struct cb_alter_id * alter_gotos
Definition: tree.h:772
int goto_id
Definition: tree.h:761
int id
Definition: tree.h:773
static void output_indent(const char *str)
Definition: codegen.c:467

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_attr ( const cb_tree  x)
static

Definition at line 929 of file codegen.c.

References _, cb_literal::all, CB_CLASS_NUMERIC, CB_FIELD, CB_LITERAL, CB_PREFIX_ATTR, CB_REFERENCE, CB_TAG_ALPHABET_NAME, CB_TAG_LITERAL, CB_TAG_REFERENCE, CB_TREE_CLASS, CB_TREE_TAG, cb_tree_type(), CB_USAGE_BINARY, CB_USAGE_COMP_6, CB_USAGE_DOUBLE, CB_USAGE_FLOAT, CB_USAGE_FP_BIN128, CB_USAGE_FP_BIN32, CB_USAGE_FP_BIN64, CB_USAGE_FP_DEC128, CB_USAGE_FP_DEC64, CB_USAGE_LONG_DOUBLE, COB_FLAG_BINARY_SWAP, COB_FLAG_BINARY_TRUNC, COB_FLAG_BLANK_ZERO, COB_FLAG_HAVE_SIGN, COB_FLAG_IS_FP, COB_FLAG_IS_POINTER, COB_FLAG_JUSTIFIED, COB_FLAG_NO_SIGN_NIBBLE, COB_FLAG_REAL_BINARY, COB_FLAG_SIGN_LEADING, COB_FLAG_SIGN_SEPARATE, COB_TYPE_ALPHANUMERIC, COB_TYPE_ALPHANUMERIC_ALL, COB_TYPE_GROUP, COB_TYPE_NUMERIC_DISPLAY, cob_u32_t, cob_u8_ptr, COBC_ABORT, cobc_abort_pr(), cb_picture::digits, cb_field::flag_binary_swap, cb_field::flag_blank_zero, cb_field::flag_is_pointer, cb_field::flag_justified, cb_field::flag_real_binary, cb_field::flag_sign_leading, cb_field::flag_sign_separate, cb_picture::have_sign, cb_field::id, cb_picture::lenstr, lookup_attr(), NULL, cb_reference::offset, output(), cb_field::pic, cb_literal::scale, cb_picture::scale, cb_literal::sign, cb_literal::size, cb_picture::str, cb_field::usage, and cb_reference::value.

Referenced by codegen(), output_field(), and output_param().

930 {
931  struct cb_literal *l;
932  struct cb_reference *r;
933  struct cb_field *f;
934  int id;
935  int type;
936  cob_u32_t flags;
937 
938  id = 0;
939  switch (CB_TREE_TAG (x)) {
940  case CB_TAG_LITERAL:
941  l = CB_LITERAL (x);
942  if (CB_TREE_CLASS (x) == CB_CLASS_NUMERIC) {
943  flags = 0;
944  if (l->sign != 0) {
946  }
948  l->size, l->scale, flags, NULL, 0);
949  } else {
950  if (l->all) {
951  id = lookup_attr (COB_TYPE_ALPHANUMERIC_ALL, 0, 0, 0, NULL, 0);
952  } else {
953  id = lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
954  }
955  }
956  break;
957  case CB_TAG_REFERENCE:
958  r = CB_REFERENCE (x);
959  f = CB_FIELD (r->value);
960  flags = 0;
961  if (r->offset) {
962  id = lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
963  } else {
964  type = cb_tree_type (x, f);
965  switch (type) {
966  case COB_TYPE_GROUP:
968  if (f->flag_justified) {
969  id = lookup_attr (type, 0, 0, COB_FLAG_JUSTIFIED, NULL, 0);
970  } else {
971  id = lookup_attr (type, 0, 0, 0, NULL, 0);
972  }
973  break;
974  default:
975  if (f->pic->have_sign) {
976  flags |= COB_FLAG_HAVE_SIGN;
977  if (f->flag_sign_separate) {
978  flags |= COB_FLAG_SIGN_SEPARATE;
979  }
980  if (f->flag_sign_leading) {
981  flags |= COB_FLAG_SIGN_LEADING;
982  }
983  }
984  if (f->flag_blank_zero) {
985  flags |= COB_FLAG_BLANK_ZERO;
986  }
987  if (f->flag_justified) {
988  flags |= COB_FLAG_JUSTIFIED;
989  }
990  if (f->flag_binary_swap) {
991  flags |= COB_FLAG_BINARY_SWAP;
992  }
993  if (f->flag_real_binary) {
994  flags |= COB_FLAG_REAL_BINARY;
995  }
996  if (f->flag_is_pointer) {
997  flags |= COB_FLAG_IS_POINTER;
998  }
999  if (cb_binary_truncate &&
1000  f->usage == CB_USAGE_BINARY &&
1001  !f->flag_real_binary) {
1002  flags |= COB_FLAG_BINARY_TRUNC;
1003  }
1004 
1005  switch (f->usage) {
1006  case CB_USAGE_COMP_6:
1007  flags |= COB_FLAG_NO_SIGN_NIBBLE;
1008  break;
1009  case CB_USAGE_DOUBLE:
1010  case CB_USAGE_FLOAT:
1011  case CB_USAGE_LONG_DOUBLE:
1012 #if 0 /* RXWRXW - Floating ind */
1013  case CB_USAGE_FP_BIN32:
1014  case CB_USAGE_FP_BIN64:
1015  case CB_USAGE_FP_BIN128:
1016  case CB_USAGE_FP_DEC64:
1017  case CB_USAGE_FP_DEC128:
1018 #endif
1019  flags |= COB_FLAG_IS_FP;
1020  break;
1021  default:
1022  break;
1023  }
1024 
1025  id = lookup_attr (type, f->pic->digits,
1026  f->pic->scale, flags,
1027  (cob_u8_ptr) f->pic->str,
1028  f->pic->lenstr);
1029  break;
1030  }
1031  }
1032  break;
1033  case CB_TAG_ALPHABET_NAME:
1034  id = lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
1035  break;
1036  default:
1037  cobc_abort_pr (_("Unexpected tree tag %d"), (int)CB_TREE_TAG (x));
1038  COBC_ABORT ();
1039  }
1040 
1041  output ("&%s%d", CB_PREFIX_ATTR, id);
1042 }
unsigned int flag_justified
Definition: tree.h:706
unsigned int flag_is_pointer
Definition: tree.h:710
unsigned int flag_real_binary
Definition: tree.h:708
short sign
Definition: tree.h:597
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
#define cob_u32_t
Definition: common.h:31
int scale
Definition: tree.h:626
int lenstr
Definition: tree.h:623
static void output(const char *,...)
Definition: codegen.c:192
#define CB_LITERAL(x)
Definition: tree.h:601
#define COB_TYPE_ALPHANUMERIC
Definition: common.h:621
char * str
Definition: tree.h:621
static int lookup_attr(const int type, const cob_u32_t digits, const int scale, const cob_u32_t flags, unsigned char *pic, const int lenstr)
Definition: codegen.c:880
cb_tree value
Definition: tree.h:876
struct cb_picture * pic
Definition: tree.h:659
cob_u32_t digits
Definition: tree.h:625
#define COB_TYPE_GROUP
Definition: common.h:603
#define COB_FLAG_REAL_BINARY
Definition: common.h:636
short all
Definition: tree.h:598
#define COB_FLAG_IS_FP
Definition: common.h:639
#define COB_FLAG_HAVE_SIGN
Definition: common.h:630
#define CB_PREFIX_ATTR
Definition: tree.h:30
#define CB_TREE_CLASS(x)
Definition: tree.h:442
#define COB_FLAG_BINARY_SWAP
Definition: common.h:635
int id
Definition: tree.h:671
#define COB_FLAG_BINARY_TRUNC
Definition: common.h:641
unsigned int flag_sign_leading
Definition: tree.h:704
#define cob_u8_ptr
Definition: common.h:66
#define _(s)
Definition: cobcrun.c:59
Definition: tree.h:643
int scale
Definition: tree.h:595
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define CB_TREE_TAG(x)
Definition: tree.h:441
#define COB_FLAG_IS_POINTER
Definition: common.h:637
cb_tree offset
Definition: tree.h:878
#define COBC_ABORT()
Definition: cobc.h:61
#define COB_FLAG_BLANK_ZERO
Definition: common.h:633
#define COB_FLAG_SIGN_LEADING
Definition: common.h:632
#define CB_REFERENCE(x)
Definition: tree.h:901
unsigned int flag_binary_swap
Definition: tree.h:707
#define COB_FLAG_SIGN_SEPARATE
Definition: common.h:631
#define COB_TYPE_NUMERIC_DISPLAY
Definition: common.h:607
#define COB_TYPE_ALPHANUMERIC_ALL
Definition: common.h:622
unsigned int flag_blank_zero
Definition: tree.h:705
cob_u32_t have_sign
Definition: tree.h:627
unsigned int flag_sign_separate
Definition: tree.h:703
cob_u32_t size
Definition: tree.h:594
int cb_tree_type(const cb_tree x, const struct cb_field *f)
Definition: tree.c:849
#define COB_FLAG_JUSTIFIED
Definition: common.h:634
enum cb_usage usage
Definition: tree.h:693
#define CB_FIELD(x)
Definition: tree.h:740
#define COB_FLAG_NO_SIGN_NIBBLE
Definition: common.h:638

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_base ( struct cb_field f,
const cob_u32_t  no_output 
)
static

Definition at line 606 of file codegen.c.

References _, base_cache, CB_PREFIX_BASE, cb_field::children, chk_field_variable_address(), chk_field_variable_size(), COBC_ABORT, cobc_abort_pr(), cobc_parse_malloc(), base_list::curr_prog, cb_field::depending, excp_current_program_id, base_list::f, cb_field::flag_base, cb_field::flag_external, cb_program::flag_file_global, cb_program::flag_global_use, cb_field::flag_is_global, cb_field::flag_item_78, cb_field::flag_local, cb_field::flag_local_storage, cb_field::id, local_base_cache, cb_field::mem_offset, cb_field::name, base_list::next, cb_field::occurs_max, cb_field::offset, output(), output_integer(), output_local(), cb_field::parent, real_field_founder(), cb_field::sister, cb_field::size, cb_field::special_index, and unlikely.

Referenced by output_data(), output_integer(), output_internal_function(), and output_long_integer().

607 {
608  struct cb_field *f01;
609  struct cb_field *p;
610  struct cb_field *v;
611  struct base_list *bl;
612 
613  if (unlikely(f->flag_item_78)) {
614  cobc_abort_pr (_("Unexpected CONSTANT item"));
615  COBC_ABORT ();
616  }
617 
618  f01 = real_field_founder (f);
619 
620  /* Base storage */
621 
622  if (!f01->flag_base) {
623  if (f01->special_index > 1U) {
624  bl = cobc_parse_malloc (sizeof (struct base_list));
625  bl->f = f01;
627  bl->next = local_base_cache;
628  local_base_cache = bl;
629  } else if (!f01->flag_external && !f01->flag_local_storage) {
630 /* RXWRXW
631  if (!f01->flag_external && !f01->flag_local_storage) {
632 */
633  if (!f01->flag_local || f01->flag_is_global) {
634  bl = cobc_parse_malloc (sizeof (struct base_list));
635  bl->f = f01;
637  if (f01->flag_is_global ||
639  bl->next = base_cache;
640  base_cache = bl;
641  } else {
642  bl->next = local_base_cache;
643  local_base_cache = bl;
644  }
645  } else {
647  output_local ("unsigned char\t\t*%s%d = NULL;",
648  CB_PREFIX_BASE, f01->id);
649  output_local ("\t/* %s */\n", f01->name);
650  output_local ("static unsigned char\t*save_%s%d;\n",
651  CB_PREFIX_BASE, f01->id);
652  } else {
653  output_local ("unsigned char\t*%s%d = NULL;",
654  CB_PREFIX_BASE, f01->id);
655  output_local ("\t/* %s */\n", f01->name);
656  }
657  }
658  }
659  f01->flag_base = 1;
660  }
661  if (no_output) {
662  return;
663  }
664 
665  if (f01->special_index) {
666  output ("(cob_u8_t *)&%s%d", CB_PREFIX_BASE, f01->id);
667  return;
668  } else if (f01->flag_local_storage) {
669  if (f01->mem_offset) {
670  output ("cob_local_ptr + %d", f01->mem_offset);
671  } else {
672  output ("cob_local_ptr");
673  }
674  } else {
675  output ("%s%d", CB_PREFIX_BASE, f01->id);
676  }
677 
678  if (chk_field_variable_address (f)) {
679  for (p = f->parent; p; f = f->parent, p = f->parent) {
680  for (p = p->children; p != f; p = p->sister) {
681  v = chk_field_variable_size (p);
682  if (v) {
683  output (" + %d + ", v->offset - p->offset);
684  if (v->size != 1) {
685  output ("%d * ", v->size);
686  }
688  } else if (p->depending && cb_flag_odoslide) {
689  output (" + ");
690  if (p->size != 1) {
691  output ("%d * ", p->size);
692  }
694  } else {
695  output (" + %d", p->size * p->occurs_max);
696  }
697  }
698  }
699  } else if (f->offset > 0) {
700  output (" + %d", f->offset);
701  }
702 }
const char * name
Definition: tree.h:645
static struct cb_field * chk_field_variable_size(struct cb_field *f)
Definition: codegen.c:556
int occurs_max
Definition: tree.h:677
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
struct cb_field * f
Definition: codegen.c:114
void * cobc_parse_malloc(const size_t size)
Definition: cobc.c:809
static unsigned int chk_field_variable_address(struct cb_field *fld)
Definition: codegen.c:582
struct cb_field * sister
Definition: tree.h:653
unsigned int flag_global_use
Definition: tree.h:1312
static void output(const char *,...)
Definition: codegen.c:192
struct cb_field * children
Definition: tree.h:652
static void output_local(const char *fmt,...)
Definition: codegen.c:527
cob_u32_t special_index
Definition: tree.h:690
unsigned char flag_is_global
Definition: tree.h:699
unsigned char flag_base
Definition: tree.h:696
#define CB_PREFIX_BASE
Definition: tree.h:31
unsigned char flag_local_storage
Definition: tree.h:698
unsigned int flag_file_global
Definition: tree.h:1315
unsigned int flag_item_78
Definition: tree.h:711
static struct cb_program * current_prog
Definition: codegen.c:140
int id
Definition: tree.h:671
cb_tree depending
Definition: tree.h:647
int offset
Definition: tree.h:675
#define _(s)
Definition: cobcrun.c:59
Definition: tree.h:643
#define unlikely(x)
Definition: common.h:437
#define COBC_ABORT()
Definition: cobc.h:61
struct base_list * next
Definition: codegen.c:113
static const char * excp_current_program_id
Definition: codegen.c:137
int size
Definition: tree.h:672
static struct base_list * local_base_cache
Definition: codegen.c:129
struct cb_field * parent
Definition: tree.h:651
const char * curr_prog
Definition: codegen.c:115
static struct base_list * base_cache
Definition: codegen.c:127
int mem_offset
Definition: tree.h:681
static void output_integer(cb_tree x)
Definition: codegen.c:1101
unsigned int flag_local
Definition: tree.h:701
static struct cb_field * real_field_founder(const struct cb_field *f)
Definition: codegen.c:541
unsigned char flag_external
Definition: tree.h:697

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_bin_field ( const cb_tree  x,
const cob_u32_t  id 
)
static

Definition at line 3279 of file codegen.c.

References cb_fits_int(), CB_LITERAL, CB_NUMERIC_LITERAL_P, CB_PREFIX_ATTR, COB_FLAG_HAVE_SIGN, COB_FLAG_REAL_BINARY, COB_TYPE_NUMERIC_BINARY, cob_u32_t, lookup_attr(), NULL, output_line(), sign, and cb_field::size.

Referenced by output_call().

3280 {
3281  int i;
3282  cob_u32_t size;
3283  cob_u32_t aflags;
3284  cob_u32_t digits;
3285 
3286  if (!CB_NUMERIC_LITERAL_P (x)) {
3287  return;
3288  }
3289  aflags = 0;
3290  if (cb_fits_int (x)) {
3291  size = 4;
3292  aflags = COB_FLAG_HAVE_SIGN;
3293  } else {
3294  size = 8;
3295  if (CB_LITERAL (x)->sign < 0) {
3296  aflags = COB_FLAG_HAVE_SIGN;
3297  }
3298  }
3299  if (size == 8) {
3300  digits = 18;
3301  } else {
3302  digits = 9;
3303  }
3304  aflags |= COB_FLAG_REAL_BINARY;
3305  i = lookup_attr (COB_TYPE_NUMERIC_BINARY, digits, 0, aflags, NULL, 0);
3306  output_line ("cob_field\tcontent_fb_%u = { %u, content_%u.data, &%s%d };",
3307  id, size, id, CB_PREFIX_ATTR, i);
3308 }
#define CB_NUMERIC_LITERAL_P(x)
Definition: tree.h:603
#define cob_u32_t
Definition: common.h:31
#define CB_LITERAL(x)
Definition: tree.h:601
static void output_line(const char *fmt,...)
Definition: codegen.c:453
static int lookup_attr(const int type, const cob_u32_t digits, const int scale, const cob_u32_t flags, unsigned char *pic, const int lenstr)
Definition: codegen.c:880
#define COB_FLAG_REAL_BINARY
Definition: common.h:636
#define COB_FLAG_HAVE_SIGN
Definition: common.h:630
#define CB_PREFIX_ATTR
Definition: tree.h:30
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
if sign
Definition: flag.def:42
#define COB_TYPE_NUMERIC_BINARY
Definition: common.h:608
int cb_fits_int(const cb_tree x)
Definition: tree.c:914

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_call ( struct cb_call p)
static

Definition at line 3311 of file codegen.c.

References cb_call::args, cb_call::call_returning, CB_BINARY_OP_P, CB_CALL_BY_CONTENT, CB_CALL_BY_REFERENCE, CB_CALL_BY_VALUE, CB_CAST_P, CB_CATEGORY_NUMERIC, CB_CHAIN, CB_CLASS_POINTER, CB_CONV_NO_RET_UPD, CB_CONV_STATIC_LINK, CB_CONV_STDCALL, cb_early_exit_list, cb_encode_program_id(), CB_FIELD, CB_FIELD_P, CB_FILE_P, cb_fits_int(), CB_FMT_LLD_F, CB_FMT_LLU_F, cb_get_int(), cb_get_long_long(), cb_get_u_long_long(), CB_LITERAL, CB_LITERAL_P, cb_null, CB_NUMERIC_LITERAL_P, CB_PURPOSE_INT, cb_ref(), CB_REF_OR_FIELD_P, CB_REFERENCE, CB_REFERENCE_P, cb_program::cb_return_code, cb_static_call_list, CB_TAG_FIELD, CB_TAG_INTRINSIC, CB_TAG_LITERAL, CB_TAG_REFERENCE, CB_TREE_CATEGORY, CB_TREE_CLASS, CB_TREE_TAG, CB_USAGE_LENGTH, CB_USAGE_PROGRAM_POINTER, CB_VALUE, COB_MAX_FIELD_PARAMS, cob_u32_t, cb_call::convention, cb_literal::data, field_iteration, gen_nested_tab, cb_call::is_system, lookup_call(), cb_call::name, needs_exit_prog, needs_unifunc, nested_list::nested_prog, cb_program::nested_prog_list, cb_text_list::next, nested_list::next, NULL, output(), output_bin_field(), output_call_by_value_args(), output_data(), output_indent(), output_indent_level, output_integer(), output_line(), output_move(), output_newline(), output_param(), output_prefix(), output_size(), output_stmt(), output_string(), cb_program::program_id, sign, cb_call::stmt1, cb_call::stmt2, system_table::syst_call, system_table::syst_name, cb_text_list::text, cb_program::toplev_count, and value.

Referenced by output_stmt().

3312 {
3313  cb_tree x;
3314  cb_tree l;
3315  struct cb_literal *lp;
3316  struct nested_list *nlp;
3317  char *callp;
3318  char *system_call;
3319  const struct system_table *psyst;
3320  const char *convention;
3321  struct cb_text_list *ctl;
3322  char *s;
3323  cob_u32_t n;
3324  size_t retptr;
3325  size_t gen_exit_program;
3326  size_t dynamic_link;
3327  size_t need_brace;
3328 #if 0 /* RXWRXW - Clear params */
3329  cob_u32_t parmnum;
3330 #endif
3331 
3332  system_call = NULL;
3333  retptr = 0;
3334  gen_exit_program = 0;
3335  dynamic_link = 1;
3336  if (p->call_returning && p->call_returning != cb_null &&
3338  retptr = 1;
3339  }
3340 
3341 #ifdef _WIN32
3342  if (p->convention & CB_CONV_STDCALL) {
3343  convention = "_std";
3344  } else {
3345  convention = "";
3346  }
3347 #else
3348  convention = "";
3349 #endif
3350 
3351  /* System routine entry points */
3352  if (p->is_system) {
3353 #if 0 /* RXWRXW - system */
3354  lp = CB_LITERAL (p->name);
3355  for (psyst = system_tab; psyst->syst_name; psyst++) {
3356  if (!strcmp((const char *)lp->data,
3357  (const char *)psyst->syst_name)) {
3358  system_call = (char *)psyst->syst_call;
3359  dynamic_link = 0;
3360  break;
3361  }
3362  }
3363 #else
3364  n = p->is_system - 1U;
3365  psyst = &system_tab[n];
3366  system_call = (char *)psyst->syst_call;
3367  dynamic_link = 0;
3368 #endif
3369  }
3370 
3371  if (dynamic_link && CB_LITERAL_P (p->name)) {
3372  if (cb_flag_static_call || (p->convention & CB_CONV_STATIC_LINK)) {
3373  dynamic_link = 0;
3374  }
3375  lp = CB_LITERAL (p->name);
3376  for (ctl = cb_static_call_list; ctl; ctl = ctl->next) {
3377  if (!strcmp((const char *)lp->data, ctl->text)) {
3378  dynamic_link = 0;
3379  break;
3380  }
3381  }
3382  for (ctl = cb_early_exit_list; ctl; ctl = ctl->next) {
3383  if (!strcmp((const char *)lp->data, ctl->text)) {
3384  gen_exit_program = 1;
3385  break;
3386  }
3387  }
3388  }
3389  need_brace = 0;
3390 
3391 #ifdef COB_NON_ALIGNED
3392  if (dynamic_link && retptr) {
3393  if (!need_brace) {
3394  need_brace = 1;
3395  output_indent ("{");
3396  }
3397  output_line ("void *temptr;");
3398  }
3399 #endif
3400 
3401  if (CB_REFERENCE_P (p->name) &&
3402  CB_FIELD_P (CB_REFERENCE (p->name)->value) &&
3403  CB_FIELD (CB_REFERENCE (p->name)->value)->usage == CB_USAGE_PROGRAM_POINTER) {
3404  dynamic_link = 0;
3405  }
3406 
3407  /* Set up arguments */
3408  for (l = p->args, n = 1; l; l = CB_CHAIN (l), n++) {
3409  x = CB_VALUE (l);
3410  switch (CB_PURPOSE_INT (l)) {
3411  case CB_CALL_BY_REFERENCE:
3412  if (CB_NUMERIC_LITERAL_P (x) || CB_BINARY_OP_P (x)) {
3413  if (!need_brace) {
3414  need_brace = 1;
3415  output_indent ("{");
3416  }
3417  output_line ("cob_content\tcontent_%u;", n);
3418  output_bin_field (x, n);
3419  } else if (CB_CAST_P (x)) {
3420  if (!need_brace) {
3421  need_brace = 1;
3422  output_indent ("{");
3423  }
3424  output_line ("void *ptr_%u;", n);
3425  }
3426  break;
3427  case CB_CALL_BY_CONTENT:
3428  if (CB_CAST_P (x)) {
3429  if (!need_brace) {
3430  need_brace = 1;
3431  output_indent ("{");
3432  }
3433  output_line ("void *ptr_%u;", n);
3434  } else if (CB_TREE_TAG (x) != CB_TAG_INTRINSIC &&
3435  x != cb_null && !(CB_CAST_P (x))) {
3436  if (!need_brace) {
3437  need_brace = 1;
3438  output_indent ("{");
3439  }
3440  output_line ("union {");
3441  output_prefix ();
3442  output ("\tunsigned char data[");
3443  if (CB_NUMERIC_LITERAL_P (x) ||
3444  CB_BINARY_OP_P (x) || CB_CAST_P(x)) {
3445  output ("8");
3446  } else {
3447  if (CB_REF_OR_FIELD_P (x)) {
3448  output ("%u", (cob_u32_t)cb_code_field (x)->size);
3449  } else {
3450  output_size (x);
3451  }
3452  }
3453  output ("];\n");
3454  output_line ("\tcob_s64_t datall;");
3455  output_line ("\tcob_u64_t dataull;");
3456  output_line ("\tint dataint;");
3457  output_line ("} content_%u;", n);
3458  output_bin_field (x, n);
3459  }
3460  break;
3461  default:
3462  break;
3463  }
3464  }
3465 
3466  if (need_brace) {
3467  output_newline ();
3468  }
3469 
3470  for (l = p->args, n = 1; l; l = CB_CHAIN (l), n++) {
3471  x = CB_VALUE (l);
3472  switch (CB_PURPOSE_INT (l)) {
3473  case CB_CALL_BY_REFERENCE:
3474  if (CB_NUMERIC_LITERAL_P (x)) {
3475  output_prefix ();
3476  if (cb_fits_int (x)) {
3477  output ("content_%u.dataint = ", n);
3478  output ("%d", cb_get_int (x));
3479  } else {
3480  if (CB_LITERAL (x)->sign >= 0) {
3481  output ("content_%u.dataull = ", n);
3483  cb_get_u_long_long (x));
3484  } else {
3485  output ("content_%u.datall = ", n);
3487  cb_get_long_long (x));
3488  }
3489  }
3490  output (";\n");
3491  } else if (CB_BINARY_OP_P (x)) {
3492  output_prefix ();
3493  output ("content_%u.dataint = ", n);
3494  output_integer (x);
3495  output (";\n");
3496  } else if (CB_CAST_P (x)) {
3497  output_prefix ();
3498  output ("ptr_%u = ", n);
3499  output_integer (x);
3500  output (";\n");
3501  }
3502  break;
3503  case CB_CALL_BY_CONTENT:
3504  if (CB_CAST_P (x)) {
3505  output_prefix ();
3506  output ("ptr_%u = ", n);
3507  output_integer (x);
3508  output (";\n");
3509  } else if (CB_TREE_TAG (x) != CB_TAG_INTRINSIC) {
3510  if (CB_NUMERIC_LITERAL_P (x)) {
3511  output_prefix ();
3512  if (cb_fits_int (x)) {
3513  output ("content_%u.dataint = ", n);
3514  output ("%d", cb_get_int (x));
3515  } else {
3516  if (CB_LITERAL (x)->sign >= 0) {
3517  output ("content_%u.dataull = ", n);
3519  cb_get_u_long_long (x));
3520  } else {
3521  output ("content_%u.datall = ", n);
3523  cb_get_long_long (x));
3524  }
3525  }
3526  output (";\n");
3527  } else if (CB_REF_OR_FIELD_P (x) &&
3529  cb_code_field (x)->usage == CB_USAGE_LENGTH) {
3530  output_prefix ();
3531  output ("content_%u.dataint = ", n);
3532  output_integer (x);
3533  output (";\n");
3534  } else if (x != cb_null && !(CB_CAST_P (x))) {
3535  output_prefix ();
3536  output ("memcpy (content_%u.data, ", n);
3537  output_data (x);
3538  output (", ");
3539  output_size (x);
3540  output (");\n");
3541  }
3542  }
3543  break;
3544  default:
3545  break;
3546  }
3547  }
3548 
3549  /* Set up parameter types */
3550  n = 0;
3551  for (l = p->args; l; l = CB_CHAIN (l), n++) {
3552  x = CB_VALUE (l);
3553  field_iteration = n;
3554  output_prefix ();
3555  output ("cob_procedure_params[%u] = ", n);
3556  switch (CB_TREE_TAG (x)) {
3557  case CB_TAG_LITERAL:
3558  if (CB_NUMERIC_LITERAL_P (x) &&
3560  output ("&content_fb_%u", n + 1);
3561  break;
3562  }
3563  /* Fall through */
3564  case CB_TAG_FIELD:
3565  case CB_TAG_INTRINSIC:
3566  output_param (x, -1);
3567  break;
3568  case CB_TAG_REFERENCE:
3569  switch (CB_TREE_TAG (CB_REFERENCE(x)->value)) {
3570  case CB_TAG_LITERAL:
3571  case CB_TAG_FIELD:
3572  case CB_TAG_INTRINSIC:
3573  output_param (x, -1);
3574  break;
3575  default:
3576  output ("NULL");
3577  break;
3578  }
3579  break;
3580  default:
3581  output ("NULL");
3582  break;
3583  }
3584  output (";\n");
3585  }
3586 
3587 #if 0 /* RXWRXW - Clear params */
3588  /* Clear extra parameters */
3589  if (n > COB_MAX_FIELD_PARAMS - 4) {
3590  parmnum = COB_MAX_FIELD_PARAMS - n;
3591  } else {
3592  parmnum = 4;
3593  }
3594  parmnum *= sizeof(cob_field *);
3595  output_line ("memset (&(cob_procedure_params[%u]), 0, %u);",
3596  n, parmnum);
3597 #endif
3598 
3599  /* Set number of parameters */
3600  output_prefix ();
3601  output ("cob_glob_ptr->cob_call_params = %u;\n", n);
3602 
3603  /* Function name */
3604  output_prefix ();
3605  /* Special for program pointers */
3606  if (CB_REFERENCE_P (p->name) &&
3607  CB_FIELD_P (CB_REFERENCE (p->name)->value) &&
3608  CB_FIELD (CB_REFERENCE (p->name)->value)->usage ==
3610  needs_unifunc = 1;
3611  output ("cob_unifunc.funcvoid = ");
3612  output_integer (p->name);
3613  output (";\n");
3614  output_prefix ();
3615  if (p->call_returning == cb_null) {
3616  output ("cob_unifunc.funcnull");
3617  } else if (retptr) {
3618 #ifdef COB_NON_ALIGNED
3619  output ("temptr");
3620 #else
3622 #endif
3623  output (" = cob_unifunc.funcptr");
3624  } else {
3625  if (p->convention & CB_CONV_NO_RET_UPD) {
3626  output ("(void)cob_unifunc.funcint");
3627  } else {
3629  output (" = cob_unifunc.funcint");
3630  }
3631  }
3632  } else if (!dynamic_link) {
3633  /* Static link */
3634  if (p->call_returning != cb_null) {
3635  if (retptr) {
3636 #ifdef COB_NON_ALIGNED
3637  output ("temptr");
3638 #else
3640 #endif
3641  output (" = (void *)");
3642  } else if (!(p->convention & CB_CONV_NO_RET_UPD)) {
3644  output (" = ");
3645  } else {
3646  output ("(void)");
3647  }
3648  }
3649  if (system_call) {
3650  output ("%s", system_call);
3651  } else {
3652  callp = cb_encode_program_id ((char *)(CB_LITERAL (p->name)->data));
3653  /* Check contained programs */
3655  for (; nlp; nlp = nlp->next) {
3656  if (!strcmp (callp, nlp->nested_prog->program_id)) {
3657  break;
3658  }
3659  }
3660  if (nlp) {
3661  output ("%s_%d__", callp,
3662  nlp->nested_prog->toplev_count);
3663  } else {
3664  output ("%s", callp);
3665  }
3666  }
3667  } else {
3668  /* Dynamic link */
3669  if (CB_LITERAL_P (p->name)) {
3670  s = (char *)(CB_LITERAL (p->name)->data);
3671  callp = cb_encode_program_id (s);
3672  lookup_call (callp);
3673  /* Check contained programs */
3675  for (; nlp; nlp = nlp->next) {
3676  if (!strcmp (callp, nlp->nested_prog->program_id)) {
3677  break;
3678  }
3679  }
3680  output ("if (unlikely(call_%s.funcvoid == NULL || cob_glob_ptr->cob_physical_cancel)) {\n", callp);
3681  output_prefix ();
3682  if (nlp) {
3683  output (" call_%s.funcint = %s_%d__;\n",
3684  callp, callp,
3685  nlp->nested_prog->toplev_count);
3686  } else {
3687  output (" call_%s.funcvoid = ", callp);
3688  output ("cob_resolve_cobol (");
3689  output_string ((const unsigned char *)s,
3690  (int)strlen (s), 0);
3691  output (", %d, %d);\n", cb_fold_call, !p->stmt1);
3692  }
3693  output_prefix ();
3694  output ("}\n");
3695  } else {
3696  callp = NULL;
3697  needs_unifunc = 1;
3698  output ("cob_unifunc.funcvoid = cob_call_field (");
3699  output_param (p->name, -1);
3701  gen_nested_tab = 1;
3702  output (", cob_nest_tab, %d, %d);\n",
3703  !p->stmt1, cb_fold_call);
3704  } else {
3705  output (", NULL, %d, %d);\n",
3706  !p->stmt1, cb_fold_call);
3707  }
3708  }
3709  if (p->stmt1) {
3710  if (callp) {
3711  output_line ("if (unlikely(call_%s.funcvoid == NULL))", callp);
3712  } else {
3713  output_line ("if (unlikely(cob_unifunc.funcvoid == NULL))");
3714  }
3715  output_line ("{");
3716  output_indent_level += 2;
3717  output_stmt (p->stmt1);
3718  output_indent_level -= 2;
3719  output_line ("}");
3720  output_line ("else");
3721  output_indent ("{");
3722  }
3723  output_prefix ();
3724  if (p->call_returning == cb_null) {
3725  if (callp) {
3726  output ("call_%s.funcnull%s", callp, convention);
3727  } else {
3728  output ("cob_unifunc.funcnull%s", convention);
3729  }
3730  } else if (retptr) {
3731 #ifdef COB_NON_ALIGNED
3732  output ("temptr");
3733 #else
3735 #endif
3736  if (callp) {
3737  output (" = call_%s.funcptr%s", callp, convention);
3738  } else {
3739  output (" = cob_unifunc.funcptr%s", convention);
3740  }
3741  } else {
3742  if (!(p->convention & CB_CONV_NO_RET_UPD)) {
3744  output (" = ");
3745  } else {
3746  output ("(void)");
3747  }
3748  if (callp) {
3749  output ("call_%s.funcint%s", callp, convention);
3750  } else {
3751  output ("cob_unifunc.funcint%s", convention);
3752  }
3753  }
3754  }
3755 
3756  /* Arguments */
3757  output (" (");
3758  for (l = p->args, n = 1; l; l = CB_CHAIN (l), n++) {
3759  x = CB_VALUE (l);
3760  field_iteration = n - 1U;
3761  switch (CB_PURPOSE_INT (l)) {
3762  case CB_CALL_BY_REFERENCE:
3763  if (CB_NUMERIC_LITERAL_P (x) || CB_BINARY_OP_P (x)) {
3764  output ("content_%u.data", n);
3765  } else if (CB_REFERENCE_P (x) && CB_FILE_P (cb_ref (x))) {
3766  output_param (cb_ref (x), -1);
3767  } else if (CB_CAST_P (x)) {
3768  output ("&ptr_%u", n);
3769  } else {
3770  output_data (x);
3771  }
3772  break;
3773  case CB_CALL_BY_CONTENT:
3774  if (CB_TREE_TAG (x) != CB_TAG_INTRINSIC && x != cb_null) {
3775  if (CB_CAST_P (x)) {
3776  output ("&ptr_%u", n);
3777  } else {
3778  output ("content_%u.data", n);
3779  }
3780  } else {
3781  output_data (x);
3782  }
3783  break;
3784  case CB_CALL_BY_VALUE:
3786  break;
3787  default:
3788  break;
3789  }
3790  if (CB_CHAIN (l)) {
3791  output (", ");
3792  }
3793  }
3794 
3795  output (");\n");
3796 
3797  if (p->call_returning && (!(p->convention & CB_CONV_NO_RET_UPD))) {
3798  if (p->call_returning == cb_null) {
3799  output_prefix ();
3801  output (" = 0;\n");
3802  } else if (!retptr) {
3804  p->call_returning);
3805 #ifdef COB_NON_ALIGNED
3806  } else {
3807  output_prefix ();
3808  output ("memcpy (");
3810  output (", &temptr, %u);\n", (cob_u32_t)sizeof (void *));
3811 #endif
3812  }
3813  }
3814  if (gen_exit_program) {
3815  needs_exit_prog = 1;
3816  output_line ("if (unlikely(module->flag_exit_program)) {");
3817  output_line ("\tmodule->flag_exit_program = 0;");
3818  output_line ("\tgoto exit_program;");
3819  output_line ("}");
3820  }
3821  if (p->stmt2) {
3822  output_stmt (p->stmt2);
3823  }
3824 
3825  if (dynamic_link && p->stmt1) {
3826  output_indent ("}");
3827  }
3828 
3829  if (need_brace) {
3830  output_indent ("}");
3831  }
3832 }
#define CB_NUMERIC_LITERAL_P(x)
Definition: tree.h:603
struct cb_text_list * next
Definition: cobc.h:160
int convention
Definition: tree.h:1044
static unsigned int needs_unifunc
Definition: codegen.c:147
#define CB_REFERENCE_P(x)
Definition: tree.h:902
cob_u64_t cb_get_u_long_long(const cb_tree x)
Definition: tree.c:1223
#define CB_TREE_CATEGORY(x)
Definition: tree.h:443
static void output_newline(void)
Definition: codegen.c:433
cb_tree stmt2
Definition: tree.h:1041
#define cob_u32_t
Definition: common.h:31
#define CB_CALL_BY_REFERENCE
Definition: tree.h:44
#define CB_CAST_P(x)
Definition: tree.h:963
int toplev_count
Definition: tree.h:1297
const char * text
Definition: cobc.h:162
static void output(const char *,...)
Definition: codegen.c:192
#define CB_CALL_BY_CONTENT
Definition: tree.h:45
#define CB_LITERAL(x)
Definition: tree.h:601
static void output_line(const char *fmt,...)
Definition: codegen.c:453
#define CB_CONV_STDCALL
Definition: tree.h:135
#define CB_FMT_LLD_F
Definition: common.h:60
int cb_get_int(const cb_tree x)
Definition: tree.c:1101
cob_u32_t is_system
Definition: tree.h:1043
#define CB_PURPOSE_INT(x)
Definition: tree.h:1197
cb_tree cb_ref(cb_tree x)
Definition: tree.c:2653
static void output_string(const unsigned char *s, const int size, const cob_u32_t llit)
Definition: codegen.c:489
struct nested_list * next
Definition: tree.h:1234
cb_tree call_returning
Definition: tree.h:1042
static void output_data(cb_tree x)
Definition: codegen.c:705
#define CB_LITERAL_P(x)
Definition: tree.h:602
static void output_prefix(void)
Definition: codegen.c:441
#define CB_VALUE(x)
Definition: tree.h:1193
#define CB_TREE_CLASS(x)
Definition: tree.h:442
static struct cb_program * current_prog
Definition: codegen.c:140
#define CB_BINARY_OP_P(x)
Definition: tree.h:937
struct cb_program * nested_prog
Definition: tree.h:1235
static void output_size(const cb_tree x)
Definition: codegen.c:793
strict implicit external value
Definition: warning.def:54
struct cb_text_list * cb_early_exit_list
Definition: cobc.c:153
#define CB_FIELD_P(x)
Definition: tree.h:741
cb_tree name
Definition: tree.h:1038
#define CB_FMT_LLU_F
Definition: common.h:61
cb_tree stmt1
Definition: tree.h:1040
#define CB_CALL_BY_VALUE
Definition: tree.h:46
#define CB_CHAIN(x)
Definition: tree.h:1194
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define CB_TREE_TAG(x)
Definition: tree.h:441
if sign
Definition: flag.def:42
cb_tree cb_return_code
Definition: tree.h:1265
#define CB_REFERENCE(x)
Definition: tree.h:901
int cb_fits_int(const cb_tree x)
Definition: tree.c:914
static void output_bin_field(const cb_tree x, const cob_u32_t id)
Definition: codegen.c:3279
#define CB_CONV_STATIC_LINK
Definition: tree.h:132
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
#define CB_FILE_P(x)
Definition: tree.h:859
static cob_u32_t field_iteration
Definition: codegen.c:166
unsigned char * data
Definition: tree.h:593
cb_tree args
Definition: tree.h:1039
static const struct system_table system_tab[]
Definition: codegen.c:184
static unsigned int gen_nested_tab
Definition: codegen.c:149
static unsigned int needs_exit_prog
Definition: codegen.c:146
const char * program_id
Definition: tree.h:1244
static void lookup_call(const char *p)
Definition: codegen.c:237
char * cb_encode_program_id(const char *)
Definition: typeck.c:1132
cb_tree cb_null
Definition: tree.c:124
struct nested_list * nested_prog_list
Definition: tree.h:1249
static void output_integer(cb_tree x)
Definition: codegen.c:1101
static int output_indent_level
Definition: codegen.c:171
const char * syst_call
Definition: codegen.c:67
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
const char * syst_name
Definition: codegen.c:66
#define COB_MAX_FIELD_PARAMS
Definition: common.h:559
cob_s64_t cb_get_long_long(const cb_tree x)
Definition: tree.c:1175
#define CB_REF_OR_FIELD_P(x)
Definition: tree.h:743
static void output_move(cb_tree src, cb_tree dst)
Definition: codegen.c:2235
#define CB_CONV_NO_RET_UPD
Definition: tree.h:131
struct cb_text_list * cb_static_call_list
Definition: cobc.c:152
#define CB_FIELD(x)
Definition: tree.h:740
static void output_call_by_value_args(cb_tree x, cb_tree l)
Definition: codegen.c:3046
static void output_indent(const char *str)
Definition: codegen.c:467

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_call_by_value_args ( cb_tree  x,
cb_tree  l 
)
static

Definition at line 3046 of file codegen.c.

References _, CB_CATEGORY_NUMERIC, CB_CLASS_NUMERIC, CB_FMT_LLD_F, CB_FMT_LLU_F, cb_get_long_long(), cb_get_u_long_long(), CB_INTRINSIC, CB_LITERAL, CB_SIZE_1, CB_SIZE_2, CB_SIZE_4, CB_SIZE_8, CB_SIZE_AUTO, CB_SIZES_INT, CB_SIZES_INT_UNSIGNED, CB_TAG_CAST, CB_TAG_INTRINSIC, CB_TAG_LITERAL, CB_TREE_CLASS, CB_TREE_TAG, CB_USAGE_BINARY, CB_USAGE_COMP_5, CB_USAGE_COMP_6, CB_USAGE_COMP_X, CB_USAGE_DISPLAY, CB_USAGE_DOUBLE, CB_USAGE_FLOAT, CB_USAGE_FP_BIN128, CB_USAGE_FP_BIN32, CB_USAGE_FP_BIN64, CB_USAGE_FP_DEC128, CB_USAGE_FP_DEC64, CB_USAGE_INDEX, CB_USAGE_LENGTH, CB_USAGE_LONG_DOUBLE, CB_USAGE_PACKED, CB_USAGE_POINTER, CB_USAGE_PROGRAM_POINTER, cob_s64_t, cob_u64_t, COBC_ABORT, cobc_abort_pr(), cb_picture::digits, cb_picture::have_sign, output(), output_data(), output_integer(), output_param(), cb_field::pic, cb_picture::scale, sign, cb_field::size, and cb_field::usage.

Referenced by output_call().

3047 {
3048  struct cb_field *f;
3049  const char *s;
3050  cob_s64_t val;
3051  cob_u64_t uval;
3052  int sizes;
3053  int sign;
3054 
3055  switch (CB_TREE_TAG (x)) {
3056  case CB_TAG_CAST:
3057  output_integer (x);
3058  return;
3059  case CB_TAG_INTRINSIC:
3060  if (CB_INTRINSIC(x)->intr_tab->category == CB_CATEGORY_NUMERIC) {
3061  output ("cob_get_int (");
3062  output_param (x, -1);
3063  output (")");
3064  } else {
3065  output_data (x);
3066  }
3067  return;
3068  case CB_TAG_LITERAL:
3069  if (CB_TREE_CLASS (x) != CB_CLASS_NUMERIC) {
3070  output ("%d", CB_LITERAL (x)->data[0]);
3071  return;
3072  }
3073  if (CB_SIZES_INT_UNSIGNED(l)) {
3074  uval = cb_get_u_long_long (x);
3075  switch (CB_SIZES_INT (l)) {
3076  case CB_SIZE_AUTO:
3077  if (uval > UINT_MAX) {
3078  output ("(cob_u64_t)");
3079  output (CB_FMT_LLU_F, uval);
3080  return;
3081  }
3082  /* Fall through to case 4 */
3083  case CB_SIZE_4:
3084  output ("(cob_u32_t)");
3085  output (CB_FMT_LLU_F, uval);
3086  return;
3087  case CB_SIZE_1:
3088  output ("(cob_u8_t)");
3089  output (CB_FMT_LLU_F, uval);
3090  return;
3091  case CB_SIZE_2:
3092  output ("(cob_u16_t)");
3093  output (CB_FMT_LLU_F, uval);
3094  return;
3095  case CB_SIZE_8:
3096  output ("(cob_u64_t)");
3097  output (CB_FMT_LLU_F, uval);
3098  return;
3099  default:
3100  cobc_abort_pr (_("Unexpected size"));
3101  COBC_ABORT ();
3102  }
3103  }
3104  val = cb_get_long_long (x);
3105  switch (CB_SIZES_INT (l)) {
3106  case CB_SIZE_AUTO:
3107  if (val > INT_MAX) {
3108  output ("(cob_s64_t)");
3109  output (CB_FMT_LLD_F, val);
3110  return;
3111  }
3112  /* Fall through to case 4 */
3113  case CB_SIZE_4:
3114  output ("(cob_s32_t)");
3115  output (CB_FMT_LLD_F, val);
3116  return;
3117  case CB_SIZE_1:
3118  output ("(cob_s8_t)");
3119  output (CB_FMT_LLD_F, val);
3120  return;
3121  case CB_SIZE_2:
3122  output ("(cob_s16_t)");
3123  output (CB_FMT_LLD_F, val);
3124  return;
3125  case CB_SIZE_8:
3126  output ("(cob_s64_t)");
3127  output (CB_FMT_LLD_F, val);
3128  return;
3129  default:
3130  cobc_abort_pr (_("Unexpected size"));
3131  COBC_ABORT ();
3132  }
3133  return;
3134  default:
3135  f = cb_code_field (x);
3136  switch (f->usage) {
3137  case CB_USAGE_BINARY:
3138  case CB_USAGE_COMP_5:
3139  case CB_USAGE_COMP_X:
3140  case CB_USAGE_PACKED:
3141  case CB_USAGE_DISPLAY:
3142  case CB_USAGE_COMP_6:
3143  sizes = CB_SIZES_INT (l);
3144  sign = 0;
3145  if (sizes == CB_SIZE_AUTO) {
3146  if (f->pic->have_sign) {
3147  sign = 1;
3148  }
3149  if (f->usage == CB_USAGE_PACKED ||
3150  f->usage == CB_USAGE_DISPLAY ||
3151  f->usage == CB_USAGE_COMP_6) {
3152  sizes = f->pic->digits - f->pic->scale;
3153  } else {
3154  sizes = f->size;
3155  }
3156  switch (sizes) {
3157  case 0:
3158  sizes = CB_SIZE_4;
3159  break;
3160  case 1:
3161  sizes = CB_SIZE_1;
3162  break;
3163  case 2:
3164  sizes = CB_SIZE_2;
3165  break;
3166  case 3:
3167  sizes = CB_SIZE_4;
3168  break;
3169  case 4:
3170  sizes = CB_SIZE_4;
3171  break;
3172  case 5:
3173  sizes = CB_SIZE_8;
3174  break;
3175  case 6:
3176  sizes = CB_SIZE_8;
3177  break;
3178  case 7:
3179  sizes = CB_SIZE_8;
3180  break;
3181  default:
3182  sizes = CB_SIZE_8;
3183  break;
3184  }
3185  } else {
3186  if (!CB_SIZES_INT_UNSIGNED(l)) {
3187  sign = 1;
3188  }
3189  }
3190  switch (sizes) {
3191  case CB_SIZE_1:
3192  if (sign) {
3193  s = "cob_c8_t";
3194  } else {
3195  s = "cob_u8_t";
3196  }
3197  break;
3198  case CB_SIZE_2:
3199  if (sign) {
3200  s = "cob_s16_t";
3201  } else {
3202  s = "cob_u16_t";
3203  }
3204  break;
3205  case CB_SIZE_4:
3206  if (sign) {
3207  s = "cob_s32_t";
3208  } else {
3209  s = "cob_u32_t";
3210  }
3211  break;
3212  case CB_SIZE_8:
3213  if (sign) {
3214  s = "cob_s64_t";
3215  } else {
3216  s = "cob_u64_t";
3217  }
3218  break;
3219  default:
3220  if (sign) {
3221  s = "cob_s32_t";
3222  } else {
3223  s = "cob_u32_t";
3224  }
3225  break;
3226  }
3227  output ("(%s)(", s);
3228  output_integer (x);
3229  output (")");
3230  return;
3231  case CB_USAGE_INDEX:
3232  case CB_USAGE_LENGTH:
3233  case CB_USAGE_POINTER:
3235  output_integer (x);
3236  return;
3237  case CB_USAGE_FLOAT:
3238  output ("*(float *)(");
3239  output_data (x);
3240  output (")");
3241  return;
3242  case CB_USAGE_DOUBLE:
3243  output ("*(double *)(");
3244  output_data (x);
3245  output (")");
3246  return;
3247  case CB_USAGE_LONG_DOUBLE:
3248  output ("*(long double *)(");
3249  output_data (x);
3250  output (")");
3251  return;
3252  case CB_USAGE_FP_BIN32:
3253  output ("*(cob_u32_t *)(");
3254  output_data (x);
3255  output (")");
3256  return;
3257  case CB_USAGE_FP_BIN64:
3258  case CB_USAGE_FP_DEC64:
3259  output ("*(cob_u64_t *)(");
3260  output_data (x);
3261  output (")");
3262  return;
3263  case CB_USAGE_FP_BIN128:
3264  case CB_USAGE_FP_DEC128:
3265  output ("*(cob_fp_128 *)(");
3266  output_data (x);
3267  output (")");
3268  return;
3269  default:
3270  output ("*(");
3271  output_data (x);
3272  output (")");
3273  return;
3274  }
3275  }
3276 }
cob_u64_t cb_get_u_long_long(const cb_tree x)
Definition: tree.c:1223
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
int scale
Definition: tree.h:626
static void output(const char *,...)
Definition: codegen.c:192
#define CB_LITERAL(x)
Definition: tree.h:601
#define CB_INTRINSIC(x)
Definition: tree.h:1001
#define CB_SIZE_8
Definition: tree.h:52
#define CB_FMT_LLD_F
Definition: common.h:60
#define CB_SIZE_2
Definition: tree.h:50
struct cb_picture * pic
Definition: tree.h:659
cob_u32_t digits
Definition: tree.h:625
#define CB_SIZES_INT(x)
Definition: tree.h:1199
static void output_data(cb_tree x)
Definition: codegen.c:705
#define cob_s64_t
Definition: common.h:51
#define CB_SIZE_4
Definition: tree.h:51
#define CB_TREE_CLASS(x)
Definition: tree.h:442
#define CB_SIZE_AUTO
Definition: tree.h:48
#define CB_FMT_LLU_F
Definition: common.h:61
#define CB_SIZE_1
Definition: tree.h:49
#define _(s)
Definition: cobcrun.c:59
Definition: tree.h:643
#define CB_TREE_TAG(x)
Definition: tree.h:441
if sign
Definition: flag.def:42
#define COBC_ABORT()
Definition: cobc.h:61
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
int size
Definition: tree.h:672
cob_u32_t have_sign
Definition: tree.h:627
static void output_integer(cb_tree x)
Definition: codegen.c:1101
#define CB_SIZES_INT_UNSIGNED(x)
Definition: tree.h:1200
#define cob_u64_t
Definition: common.h:52
cob_s64_t cb_get_long_long(const cb_tree x)
Definition: tree.c:1175
enum cb_usage usage
Definition: tree.h:693

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_cancel ( struct cb_cancel p)
static

Definition at line 3858 of file codegen.c.

References cb_encode_program_id(), CB_LITERAL, CB_LITERAL_P, gen_nested_tab, nested_list::nested_prog, cb_program::nested_prog_list, nested_list::next, cb_program::num_proc_params, output(), output_param(), output_prefix(), output_string(), cb_program::program_id, cb_cancel::target, and cb_program::toplev_count.

Referenced by output_stmt().

3859 {
3860  struct nested_list *nlp;
3861  char *callp;
3862  char *s;
3863  int i;
3864 
3865  if (CB_LITERAL_P (p->target)) {
3866  s = (char *)(CB_LITERAL (p->target)->data);
3867  callp = cb_encode_program_id (s);
3869  for (; nlp; nlp = nlp->next) {
3870  if (!strcmp (callp, nlp->nested_prog->program_id)) {
3871  break;
3872  }
3873  }
3874  if (nlp) {
3875  output_prefix ();
3876  output ("(void)%s_%d_ (-1", callp,
3877  nlp->nested_prog->toplev_count);
3878  for (i = 0; i < nlp->nested_prog->num_proc_params; ++i) {
3879  output (", NULL");
3880  }
3881  output (");\n");
3882  } else {
3883  output ("cob_cancel (");
3884  output_string ((const unsigned char *)s,
3885  (int)strlen (s), 0);
3886  output (");\n");
3887  }
3888  return;
3889  }
3890  output_prefix ();
3891  output ("cob_cancel_field (");
3892  output_param (p->target, -1);
3894  gen_nested_tab = 1;
3895  output (", cob_nest_tab");
3896  } else {
3897  output (", NULL");
3898  }
3899  output (");\n");
3900 }
int toplev_count
Definition: tree.h:1297
static void output(const char *,...)
Definition: codegen.c:192
#define CB_LITERAL(x)
Definition: tree.h:601
static void output_string(const unsigned char *s, const int size, const cob_u32_t llit)
Definition: codegen.c:489
struct nested_list * next
Definition: tree.h:1234
#define CB_LITERAL_P(x)
Definition: tree.h:602
static void output_prefix(void)
Definition: codegen.c:441
static struct cb_program * current_prog
Definition: codegen.c:140
struct cb_program * nested_prog
Definition: tree.h:1235
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
static unsigned int gen_nested_tab
Definition: codegen.c:149
const char * program_id
Definition: tree.h:1244
char * cb_encode_program_id(const char *)
Definition: typeck.c:1132
struct nested_list * nested_prog_list
Definition: tree.h:1249
int num_proc_params
Definition: tree.h:1296
cb_tree target
Definition: tree.h:1054

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_class_name_definition ( struct cb_class_name p)
static

Definition at line 5544 of file codegen.c.

References CB_CHAIN, cb_high, CB_LITERAL, cb_low, cb_null, CB_NUMERIC_LITERAL_P, CB_PAIR_P, CB_PAIR_X, CB_PAIR_Y, cb_quote, cb_space, CB_VALUE, cb_zero, cb_class_name::cname, cb_class_name::list, literal_value(), output_indent(), output_line(), and output_newline().

Referenced by codegen().

5545 {
5546  cb_tree l;
5547  cb_tree x;
5548  unsigned char *data;
5549  size_t i;
5550  size_t size;
5551  int n;
5552  int lower;
5553  int upper;
5554  int vals[256];
5555 
5556  output_line ("static int");
5557  output_line ("%s (cob_field *f)", p->cname);
5558  output_indent ("{");
5559  output_line ("size_t\ti;\n");
5560  output_line ("for (i = 0; i < f->size; i++)");
5561  output_indent ("{");
5562  output_line ("switch (f->data[i]) {");
5563  memset (vals, 0, sizeof(vals));
5564  for (l = p->list; l; l = CB_CHAIN (l)) {
5565  x = CB_VALUE (l);
5566  if (CB_PAIR_P (x)) {
5567  lower = literal_value (CB_PAIR_X (x));
5568  upper = literal_value (CB_PAIR_Y (x));
5569  for (n = lower; n <= upper; ++n) {
5570  vals[n] = 1;
5571  }
5572  } else {
5573  if (CB_NUMERIC_LITERAL_P (x)) {
5574  vals[literal_value (x)] = 1;
5575  } else if (x == cb_space) {
5576  vals[' '] = 1;
5577  } else if (x == cb_zero) {
5578  vals['0'] = 1;
5579  } else if (x == cb_quote) {
5580  if (cb_flag_apostrophe) {
5581  vals['\''] = 1;
5582  } else {
5583  vals['"'] = 1;
5584  }
5585  } else if (x == cb_null) {
5586  vals[0] = 1;
5587  } else if (x == cb_low) {
5588  vals[0] = 1;
5589  } else if (x == cb_high) {
5590  vals[255] = 1;
5591  } else {
5592  size = CB_LITERAL (x)->size;
5593  data = CB_LITERAL (x)->data;
5594  for (i = 0; i < size; i++) {
5595  vals[data[i]] = 1;
5596  }
5597  }
5598  }
5599  }
5600  for (i = 0; i < 256; ++i) {
5601  if (vals[i]) {
5602  output_line ("case %d:", (int)i);
5603  }
5604  }
5605  output_line (" break;");
5606  output_line ("default:");
5607  output_line (" return 0;");
5608  output_line ("}");
5609  output_indent ("}");
5610  output_line ("return 1;");
5611  output_indent ("}");
5612  output_newline ();
5613 }
#define CB_NUMERIC_LITERAL_P(x)
Definition: tree.h:603
#define CB_PAIR_X(x)
Definition: tree.h:1205
#define CB_PAIR_P(x)
Definition: tree.h:1204
static void output_newline(void)
Definition: codegen.c:433
#define CB_LITERAL(x)
Definition: tree.h:601
static void output_line(const char *fmt,...)
Definition: codegen.c:453
#define CB_PAIR_Y(x)
Definition: tree.h:1206
cb_tree cb_zero
Definition: tree.c:125
cb_tree cb_quote
Definition: tree.c:132
cb_tree cb_space
Definition: tree.c:127
char * cname
Definition: tree.h:558
#define CB_VALUE(x)
Definition: tree.h:1193
#define CB_CHAIN(x)
Definition: tree.h:1194
cb_tree cb_null
Definition: tree.c:124
cb_tree cb_high
Definition: tree.c:129
static int literal_value(cb_tree x)
Definition: codegen.c:5489
cb_tree cb_low
Definition: tree.c:128
static void output_indent(const char *str)
Definition: codegen.c:467
cb_tree list
Definition: tree.h:559

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_cond ( cb_tree  x,
const int  save_flag 
)
static

Definition at line 2121 of file codegen.c.

References _, CB_BINARY_OP, CB_CHAIN, cb_false, CB_TAG_BINARY_OP, CB_TAG_CONST, CB_TAG_FUNCALL, CB_TAG_LIST, CB_TREE_TAG, cb_true, CB_VALUE, COB_INSIDE_SIZE, COBC_ABORT, cobc_abort_pr(), inside_check, inside_stack, cb_binary_op::op, output(), output_funcall(), output_integer(), output_newline(), output_prefix(), output_stmt(), cb_binary_op::x, and cb_binary_op::y.

Referenced by output_perform_until(), output_search_all(), and output_stmt().

2122 {
2123  struct cb_binary_op *p;
2124 
2125  switch (CB_TREE_TAG (x)) {
2126  case CB_TAG_CONST:
2127  if (x == cb_true) {
2128  output ("1");
2129  } else if (x == cb_false) {
2130  output ("0");
2131  } else {
2132  cobc_abort_pr (_("Unexpected constant"));
2133  COBC_ABORT ();
2134  }
2135  break;
2136  case CB_TAG_BINARY_OP:
2137  p = CB_BINARY_OP (x);
2138  switch (p->op) {
2139  case '!':
2140  output ("!");
2141  output_cond (p->x, save_flag);
2142  break;
2143 
2144  case '&':
2145  case '|':
2146  output ("(");
2147  output_cond (p->x, save_flag);
2148  output (p->op == '&' ? " && " : " || ");
2149  output_newline ();
2150  output_prefix ();
2151  output (" ");
2152  output_cond (p->y, save_flag);
2153  output (")");
2154  break;
2155 
2156  case '=':
2157  case '<':
2158  case '[':
2159  case '>':
2160  case ']':
2161  case '~':
2162  output ("((int)");
2163  output_cond (p->x, save_flag);
2164  switch (p->op) {
2165  case '=':
2166  output (" == 0");
2167  break;
2168  case '<':
2169  output (" < 0");
2170  break;
2171  case '[':
2172  output (" <= 0");
2173  break;
2174  case '>':
2175  output (" > 0");
2176  break;
2177  case ']':
2178  output (" >= 0");
2179  break;
2180  case '~':
2181  output (" != 0");
2182  break;
2183  default:
2184  /* FIXME - Check */
2185  break;
2186  }
2187  output (")");
2188  break;
2189 
2190  default:
2191  output_integer (x);
2192  break;
2193  }
2194  break;
2195  case CB_TAG_FUNCALL:
2196  if (save_flag) {
2197  output ("(ret = ");
2198  }
2199  output_funcall (x);
2200  if (save_flag) {
2201  output (")");
2202  }
2203  break;
2204  case CB_TAG_LIST:
2205  if (save_flag) {
2206  output ("(ret = ");
2207  }
2208  inside_stack[inside_check++] = 0;
2209  if (inside_check >= COB_INSIDE_SIZE) {
2210  cobc_abort_pr (_("Internal statement stack depth exceeded -> %d"),
2211  COB_INSIDE_SIZE);
2212  COBC_ABORT ();
2213  }
2214  output ("(\n");
2215  for (; x; x = CB_CHAIN (x)) {
2216  output_stmt (CB_VALUE (x));
2217  }
2218  if (inside_check) {
2219  --inside_check;
2220  }
2221  output (")");
2222  if (save_flag) {
2223  output (")");
2224  }
2225  break;
2226  default:
2227  cobc_abort_pr (_("Unexpected tree tag %d"), (int)CB_TREE_TAG (x));
2228  COBC_ABORT ();
2229  }
2230 }
cb_tree cb_true
Definition: tree.c:122
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
static void output_newline(void)
Definition: codegen.c:433
static void output(const char *,...)
Definition: codegen.c:192
#define COB_INSIDE_SIZE
Definition: codegen.c:48
cb_tree cb_false
Definition: tree.c:123
static void output_funcall(cb_tree x)
Definition: codegen.c:2028
static void output_prefix(void)
Definition: codegen.c:441
#define CB_VALUE(x)
Definition: tree.h:1193
static void output_cond(cb_tree x, const int save_flag)
Definition: codegen.c:2121
#define _(s)
Definition: cobcrun.c:59
#define CB_CHAIN(x)
Definition: tree.h:1194
int op
Definition: tree.h:932
#define CB_TREE_TAG(x)
Definition: tree.h:441
#define COBC_ABORT()
Definition: cobc.h:61
static unsigned int inside_check
Definition: codegen.c:176
cb_tree y
Definition: tree.h:931
static unsigned int inside_stack[64]
Definition: codegen.c:177
static void output_integer(cb_tree x)
Definition: codegen.c:1101
cb_tree x
Definition: tree.h:930
#define CB_BINARY_OP(x)
Definition: tree.h:936
static void output_stmt(cb_tree x)
Definition: codegen.c:4660

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_cond_debug ( cb_tree  x)
static

Definition at line 4138 of file codegen.c.

References CB_BINARY_OP, cb_build_debug(), cb_debug_contents, cb_debug_name, CB_REF_OR_FIELD_P, CB_TAG_BINARY_OP, CB_TAG_FUNCALL, CB_TAG_LIST, CB_TREE_TAG, NULL, cb_binary_op::op, output_funcall_debug(), output_perform_call(), output_stmt(), cb_binary_op::x, and cb_binary_op::y.

Referenced by output_perform_until().

4139 {
4140  struct cb_binary_op *p;
4141 
4142  switch (CB_TREE_TAG (x)) {
4143  case CB_TAG_FUNCALL:
4145  break;
4146  case CB_TAG_LIST:
4147  break;
4148  case CB_TAG_BINARY_OP:
4149  p = CB_BINARY_OP (x);
4150  switch (p->op) {
4151  case '!':
4152  output_cond_debug (p->x);
4153  break;
4154 
4155  case '&':
4156  case '|':
4157  output_cond_debug (p->x);
4158  output_cond_debug (p->y);
4159  break;
4160 
4161  case '=':
4162  case '<':
4163  case '[':
4164  case '>':
4165  case ']':
4166  case '~':
4167  output_cond_debug (p->x);
4168  break;
4169 
4170  default:
4171  if (CB_REF_OR_FIELD_P (x) &&
4172  cb_code_field (x)->flag_field_debug) {
4174  (const char *)cb_code_field (x)->name, NULL));
4176  NULL, x));
4177  output_perform_call (cb_code_field (x)->debug_section,
4178  cb_code_field (x)->debug_section);
4179  }
4180  break;
4181  }
4182  break;
4183  default:
4184  break;
4185  }
4186 }
int op
Definition: tree.h:932
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define CB_TREE_TAG(x)
Definition: tree.h:441
cb_tree cb_debug_name
Definition: typeck.c:84
static void output_perform_call(struct cb_label *lb, struct cb_label *le)
Definition: codegen.c:3905
cb_tree y
Definition: tree.h:931
static void output_funcall_debug(cb_tree x)
Definition: codegen.c:4071
cb_tree x
Definition: tree.h:930
#define CB_BINARY_OP(x)
Definition: tree.h:936
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
cb_tree cb_build_debug(const cb_tree target, const char *str, const cb_tree fld)
Definition: tree.c:1566
#define CB_REF_OR_FIELD_P(x)
Definition: tree.h:743
cb_tree cb_debug_contents
Definition: typeck.c:88
static void output_cond_debug(cb_tree x)
Definition: codegen.c:4138

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_data ( cb_tree  x)
static

Definition at line 705 of file codegen.c.

References _, CB_CHAIN, CB_CLASS_NUMERIC, CB_FIELD, CB_LITERAL, cb_null, CB_REFERENCE, CB_TAG_CAST, CB_TAG_CONST, CB_TAG_INTRINSIC, CB_TAG_LITERAL, CB_TAG_REFERENCE, CB_TREE_CLASS, CB_TREE_TAG, CB_VALUE, cb_field::children, COBC_ABORT, cobc_abort_pr(), cb_literal::data, cb_field::depending, field_iteration, cb_field::flag_occurs, cb_literal::llit, NULL, cb_reference::offset, output(), output_base(), output_index(), output_integer(), output_param(), output_string(), cb_field::parent, cb_literal::sign, cb_literal::size, cb_field::size, cb_reference::subs, unlikely, and cb_reference::value.

Referenced by output_call(), output_call_by_value_args(), output_field(), output_figurative(), output_funcall(), output_initialize_fp(), output_initialize_fp_bindec(), output_initialize_literal(), output_initialize_one(), output_initialize_uniform(), output_integer(), output_internal_function(), output_long_integer(), output_param(), and output_stmt().

706 {
707  struct cb_literal *l;
708  struct cb_reference *r;
709  struct cb_field *f;
710  struct cb_field *o_slide;
711  struct cb_field *o;
712  cb_tree lsub;
713 
714  switch (CB_TREE_TAG (x)) {
715  case CB_TAG_LITERAL:
716  l = CB_LITERAL (x);
717  if (CB_TREE_CLASS (x) == CB_CLASS_NUMERIC) {
718  output ("(cob_u8_ptr)\"%s%s\"", (char *)l->data,
719  (l->sign < 0) ? "-" : (l->sign > 0) ? "+" : "");
720  } else {
721  output ("(cob_u8_ptr)");
722  output_string (l->data, (int) l->size, l->llit);
723  }
724  break;
725  case CB_TAG_REFERENCE:
726  r = CB_REFERENCE (x);
727  f = CB_FIELD (r->value);
728 
729  /* Base address */
730  output_base (f, 0);
731 
732  /* Subscripts */
733  if (r->subs) {
734  lsub = r->subs;
735  o_slide = NULL;
736  for (; f && lsub; f = f->parent) {
737  /* add current field size for OCCURS */
738  if (f->flag_occurs) {
739  /* recalculate size for nested ODO ... */
740  if (unlikely(o_slide)) {
741  for (o = o_slide; o; o = o->children) {
742  if (o->depending) {
743  output (" + (%d * ", o->size);
745  output (")");
746  }
747  }
748  output (" * ");
749  } else {
750  /* ... use field size otherwise */
751  output (" + ");
752  if (f->size != 1) {
753  output ("%d * ", f->size);
754  }
755  }
756  if (cb_flag_odoslide && f->depending) {
757  o_slide = f;
758  }
759 
760  output_index (CB_VALUE (lsub));
761  lsub = CB_CHAIN (lsub);
762  }
763  }
764  }
765 
766  /* Offset */
767  if (r->offset) {
768  output (" + ");
769  output_index (r->offset);
770  }
771  break;
772  case CB_TAG_CAST:
773  output ("&");
774  output_param (x, 0);
775  break;
776  case CB_TAG_INTRINSIC:
777  output ("cob_procedure_params[%u]->data",
779  break;
780  case CB_TAG_CONST:
781  if (x == cb_null) {
782  output ("NULL");
783  return;
784  }
785  /* Fall through */
786  default:
787  cobc_abort_pr (_("Unexpected tree tag %d"), (int)CB_TREE_TAG (x));
788  COBC_ABORT ();
789  }
790 }
short sign
Definition: tree.h:597
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
static void output(const char *,...)
Definition: codegen.c:192
struct cb_field * children
Definition: tree.h:652
#define CB_LITERAL(x)
Definition: tree.h:601
cb_tree value
Definition: tree.h:876
static void output_string(const unsigned char *s, const int size, const cob_u32_t llit)
Definition: codegen.c:489
static void output_index(cb_tree x)
Definition: codegen.c:1608
#define CB_VALUE(x)
Definition: tree.h:1193
#define CB_TREE_CLASS(x)
Definition: tree.h:442
cb_tree depending
Definition: tree.h:647
#define _(s)
Definition: cobcrun.c:59
Definition: tree.h:643
#define unlikely(x)
Definition: common.h:437
#define CB_CHAIN(x)
Definition: tree.h:1194
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define CB_TREE_TAG(x)
Definition: tree.h:441
cob_u32_t llit
Definition: tree.h:596
cb_tree offset
Definition: tree.h:878
#define COBC_ABORT()
Definition: cobc.h:61
unsigned int flag_occurs
Definition: tree.h:702
#define CB_REFERENCE(x)
Definition: tree.h:901
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
int size
Definition: tree.h:672
static cob_u32_t field_iteration
Definition: codegen.c:166
unsigned char * data
Definition: tree.h:593
struct cb_field * parent
Definition: tree.h:651
cb_tree cb_null
Definition: tree.c:124
static void output_integer(cb_tree x)
Definition: codegen.c:1101
cb_tree subs
Definition: tree.h:877
static void output_base(struct cb_field *f, const cob_u32_t no_output)
Definition: codegen.c:606
cob_u32_t size
Definition: tree.h:594
#define CB_FIELD(x)
Definition: tree.h:740

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_entry_function ( struct cb_program prog,
cb_tree  entry,
cb_tree  parameter_list,
const int  gencode 
)
static

Definition at line 6866 of file codegen.c.

References CB_CALL_BY_CONTENT, CB_CALL_BY_REFERENCE, CB_CALL_BY_VALUE, CB_CHAIN, CB_CLASS_NUMERIC, CB_FUNCTION_TYPE, CB_LABEL, CB_PREFIX_BASE, CB_PURPOSE, CB_PURPOSE_INT, CB_SIZE_1, CB_SIZE_2, CB_SIZE_4, CB_SIZE_8, CB_SIZE_UNSIGNED, CB_SIZES, CB_SIZES_INT, CB_TREE_CLASS, CB_USAGE_DOUBLE, CB_USAGE_FLOAT, CB_USAGE_FP_BIN128, CB_USAGE_FP_BIN32, CB_USAGE_FP_BIN64, CB_USAGE_FP_DEC128, CB_USAGE_FP_DEC64, CB_USAGE_LONG_DOUBLE, CB_USAGE_POINTER, CB_USAGE_PROGRAM_POINTER, CB_VALUE, COB_MAX_FIELD_PARAMS, cob_u32_t, f1, f2, cb_program::flag_chained, cb_program::flag_main, cb_program::flag_recursive, cb_program::flag_void, cb_field::id, n2, cb_field::name, cb_program::nested_level, NULL, output(), cb_program::prog_type, progid, cb_program::program_id, cb_program::toplev_count, unlikely, and cb_field::usage.

Referenced by codegen().

6868 {
6869  const char *entry_name;
6870  cb_tree using_list;
6871  cb_tree l;
6872  cb_tree l1;
6873  cb_tree l2;
6874  struct cb_field *f;
6875  struct cb_field *f1;
6876  struct cb_field *f2;
6877  const char *s;
6878  const char *s2;
6879  const char *s_prefix;
6880  const char *s_type[COB_MAX_FIELD_PARAMS];
6881  cob_u32_t parmnum;
6882  cob_u32_t n;
6883 #if 0 /* RXWRXW - UFUNC */
6884  cob_u32_t n2;
6885 #endif
6886  int sticky_ids[COB_MAX_FIELD_PARAMS];
6887  int sticky_nonp[COB_MAX_FIELD_PARAMS];
6888 
6889  entry_name = CB_LABEL (CB_PURPOSE (entry))->name;
6890  using_list = CB_VALUE (entry);
6891 
6892  if (gencode) {
6893  output ("/* ENTRY '%s' */\n\n", entry_name);
6894  }
6895 
6896 #if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(__clang__)
6897  if (!gencode && !prog->nested_level) {
6898  output ("__declspec(dllexport) ");
6899  }
6900 #endif
6901 
6902  if (unlikely(prog->prog_type == CB_FUNCTION_TYPE)) {
6903  if (gencode) {
6904  output ("cob_field *\n");
6905  } else {
6906  output ("cob_field\t\t*");
6907  }
6908  output ("%s (", entry_name);
6909  if (!gencode) {
6910  output ("cob_field **, const int");
6911  } else {
6912  output ("cob_field **cob_fret, const int cob_pam");
6913  }
6914  parmnum = 0;
6915  if (using_list) {
6916  output (", ");
6917  n = 0;
6918  for (l = using_list; l; l = CB_CHAIN (l), ++n, ++parmnum) {
6919  if (!gencode) {
6920  output ("cob_field *");
6921  } else {
6922  output ("cob_field *f%u", n);
6923  }
6924  if (CB_CHAIN (l)) {
6925  output (", ");
6926  }
6927  }
6928  }
6929  if (gencode) {
6930  output (")\n");
6931  } else {
6932  /* Finish prototype and return */
6933  output (");\n");
6934  return;
6935  }
6936  output ("{\n");
6937  output (" struct cob_func_loc\t*floc;\n\n");
6938  output (" /* Save environment */\n");
6939  output (" floc = cob_save_func (cob_fret, cob_pam, %u",
6940  parmnum);
6941 #if 0 /* RXWRXW - UFUNC */
6942  if (!using_list) {
6943  output (" floc->ret_fld = %s_ (0);\n", prog->program_id);
6944  output (" **cob_fret = *floc->ret_fld;\n");
6945  output (" cob_restore_func (floc);\n");
6946  output (" return *cob_fret;\n}\n\n");
6947  return;
6948  }
6949  output (" switch (cob_pam) {\n");
6950  for (n = 0; n <= parmnum; ++n) {
6951  if (!n) {
6952  output (" case 0:\n");
6953  output (" break;\n");
6954  continue;
6955  }
6956  output (" case %u:\n", n);
6957  if (n == parmnum) {
6958  output (" default:\n");
6959  }
6960  for (n2 = 0; n2 < n; ++n2) {
6961  output (" if (f%u) {\n", n2);
6962  output (" floc->func_params[%u] = f%u;\n",
6963  n2, n2);
6964  output (" floc->data[%u] = f%u->data;\n",
6965  n2, n2);
6966  output (" }\n");
6967  output (" break;\n");
6968  }
6969  }
6970 #else
6971  for (n = 0; n < parmnum; ++n) {
6972  output (", f%u", n);
6973  }
6974 #endif
6975  output (");\n");
6976 
6977  output (" floc->ret_fld = %s_ (0", prog->program_id);
6978  if (parmnum != 0) {
6979  output (", ");
6980  for (n = 0; n < parmnum; ++n) {
6981  output ("floc->data[%u]", n);
6982  if (n != parmnum - 1) {
6983  output (", ");
6984  }
6985  }
6986  }
6987  output (");\n");
6988  output (" **cob_fret = *floc->ret_fld;\n");
6989  output (" /* Restore environment */\n");
6990  output (" cob_restore_func (floc);\n");
6991  output (" return *cob_fret;\n}\n\n");
6992  return;
6993  }
6994  if (prog->nested_level) {
6995  if (gencode) {
6996  if (prog->flag_void) {
6997  output("void\n");
6998  } else {
6999  output ("static int\n");
7000  }
7001  } else {
7002  if (prog->flag_void) {
7003  output("void\t\t");
7004  } else {
7005  output ("static int\t\t");
7006  }
7007  }
7008  } else {
7009  if (prog->flag_main && !prog->flag_recursive) {
7010  output ("static ");
7011  }
7012  if (gencode) {
7013  if (prog->flag_void) {
7014  output ("void\n");
7015  } else {
7016  output ("int\n");
7017  }
7018  } else {
7019  if (prog->flag_void) {
7020  output ("void\t\t\t");
7021  } else {
7022  output ("int\t\t\t");
7023  }
7024  }
7025  }
7026 
7027  if (prog->nested_level) {
7028  output ("%s_%d__ (", entry_name, prog->toplev_count);
7029  } else {
7030  output ("%s (", entry_name);
7031  }
7032  if (prog->flag_chained) {
7033  using_list = NULL;
7034  parameter_list = NULL;
7035  }
7036  if (!gencode && !using_list) {
7037  output ("void);\n");
7038  return;
7039  }
7040 
7041  memset (sticky_ids, 0, sizeof(sticky_ids));
7042  memset (sticky_nonp, 0, sizeof(sticky_ids));
7043 
7044  n = 0;
7045  for (l = using_list; l; l = CB_CHAIN (l), ++n) {
7046  f = cb_code_field (CB_VALUE (l));
7047  switch (CB_PURPOSE_INT (l)) {
7048  case CB_CALL_BY_VALUE:
7049  if (f->usage == CB_USAGE_FLOAT) {
7050  if (gencode) {
7051  output ("float %s%d",
7052  CB_PREFIX_BASE, f->id);
7053  } else {
7054  output ("float");
7055  }
7056  if (cb_sticky_linkage) {
7057  s_type[n] = "";
7058  } else {
7059  s_type[n] = "(cob_u8_ptr)&";
7060  }
7061  break;
7062  } else if (f->usage == CB_USAGE_DOUBLE) {
7063  if (gencode) {
7064  output ("double %s%d",
7065  CB_PREFIX_BASE, f->id);
7066  } else {
7067  output ("double");
7068  }
7069  if (cb_sticky_linkage) {
7070  s_type[n] = "";
7071  } else {
7072  s_type[n] = "(cob_u8_ptr)&";
7073  }
7074  break;
7075  } else if (f->usage == CB_USAGE_LONG_DOUBLE) {
7076  if (gencode) {
7077  output ("long double %s%d",
7078  CB_PREFIX_BASE, f->id);
7079  } else {
7080  output ("long double");
7081  }
7082  if (cb_sticky_linkage) {
7083  s_type[n] = "";
7084  } else {
7085  s_type[n] = "(cob_u8_ptr)&";
7086  }
7087  break;
7088  } else if (f->usage == CB_USAGE_FP_BIN32) {
7089  if (gencode) {
7090  output ("cob_u32_t %s%d",
7091  CB_PREFIX_BASE, f->id);
7092  } else {
7093  output ("cob_u32_t");
7094  }
7095  if (cb_sticky_linkage) {
7096  s_type[n] = "";
7097  } else {
7098  s_type[n] = "(cob_u8_ptr)&";
7099  }
7100  break;
7101  } else if (f->usage == CB_USAGE_FP_BIN64 ||
7102  f->usage == CB_USAGE_FP_DEC64) {
7103  if (gencode) {
7104  output ("cob_u64_t %s%d",
7105  CB_PREFIX_BASE, f->id);
7106  } else {
7107  output ("cob_u64_t");
7108  }
7109  if (cb_sticky_linkage) {
7110  s_type[n] = "";
7111  } else {
7112  s_type[n] = "(cob_u8_ptr)&";
7113  }
7114  break;
7115  } else if (f->usage == CB_USAGE_FP_BIN128 ||
7116  f->usage == CB_USAGE_FP_DEC128) {
7117  if (gencode) {
7118  output ("cob_fp_128 %s%d",
7119  CB_PREFIX_BASE, f->id);
7120  } else {
7121  output ("cob_fp_128");
7122  }
7123  if (cb_sticky_linkage) {
7124  s_type[n] = "";
7125  } else {
7126  s_type[n] = "(cob_u8_ptr)&";
7127  }
7128  break;
7129  } else if (CB_TREE_CLASS (CB_VALUE (l)) == CB_CLASS_NUMERIC) {
7130  s = "";
7131  switch (CB_SIZES_INT (l)) {
7132  case CB_SIZE_1:
7133  if (CB_SIZES(l) & CB_SIZE_UNSIGNED) {
7134  s = "cob_u8_t";
7135  } else {
7136  s = "cob_c8_t";
7137  }
7138  break;
7139  case CB_SIZE_2:
7140  if (CB_SIZES(l) & CB_SIZE_UNSIGNED) {
7141  s = "cob_u16_t";
7142  } else {
7143  s = "cob_s16_t";
7144  }
7145  break;
7146  case CB_SIZE_4:
7147  if (CB_SIZES(l) & CB_SIZE_UNSIGNED) {
7148  s = "cob_u32_t";
7149  } else {
7150  s = "cob_s32_t";
7151  }
7152  break;
7153  case CB_SIZE_8:
7154  if (CB_SIZES(l) & CB_SIZE_UNSIGNED) {
7155  s = "cob_u64_t";
7156  } else {
7157  s = "cob_s64_t";
7158  }
7159  break;
7160  default:
7161  break;
7162  }
7163  if (gencode) {
7164  output ("%s %s%d",
7165  s, CB_PREFIX_BASE, f->id);
7166  } else {
7167  output ("%s", s);
7168  }
7169  if (cb_sticky_linkage) {
7170  s_type[n] = "";
7171  } else {
7172  s_type[n] = "(cob_u8_ptr)&";
7173  }
7174  break;
7175  }
7176  /* Fall through */
7177  case CB_CALL_BY_REFERENCE:
7178  case CB_CALL_BY_CONTENT:
7179  if (gencode) {
7180  output ("cob_u8_t *%s%d",
7181  CB_PREFIX_BASE, f->id);
7182  } else {
7183  output ("cob_u8_t *");
7184  }
7185  s_type[n] = "";
7186  break;
7187  default:
7188  break;
7189  }
7190  if (CB_CHAIN (l)) {
7191  output (", ");
7192  }
7193  }
7194 
7195  if (gencode) {
7196  output (")\n");
7197  } else {
7198  /* Finish prototype and return */
7199  output (");\n");
7200  return;
7201  }
7202 
7203  output ("{\n");
7204 
7205  /* We have to cater for sticky-linkage here at the entry point site */
7206  /* Doing it in the internal function is too late as we */
7207  /* then do not have the information as to possible ENTRY clauses */
7208 
7209  parmnum = 0;
7210  /* Sticky linkage parameters */
7211  if (cb_sticky_linkage && using_list) {
7212  for (l = using_list; l; l = CB_CHAIN (l), parmnum++) {
7213  f = cb_code_field (CB_VALUE (l));
7214  sticky_ids[parmnum] = f->id;
7215  switch (CB_PURPOSE_INT (l)) {
7216  case CB_CALL_BY_VALUE:
7217  s = NULL;
7218  s2 = "0";
7219  if (f->usage == CB_USAGE_FLOAT) {
7220  s = "float";
7221  } else if (f->usage == CB_USAGE_DOUBLE) {
7222  s = "double";
7223  } else if (f->usage == CB_USAGE_LONG_DOUBLE) {
7224  s = "long double";
7225  } else if (f->usage == CB_USAGE_FP_BIN32) {
7226  s = "cob_u32_t";
7227  } else if (f->usage == CB_USAGE_FP_BIN64 ||
7228  f->usage == CB_USAGE_FP_DEC64) {
7229  s = "cob_u64_t";
7230  } else if (f->usage == CB_USAGE_FP_BIN128 ||
7231  f->usage == CB_USAGE_FP_DEC128) {
7232  s = "cob_fp_128";
7233  s2 = "{{0, 0}}";
7234  } else if (CB_TREE_CLASS (CB_VALUE (l)) == CB_CLASS_NUMERIC) {
7235  switch (CB_SIZES_INT (l)) {
7236  case CB_SIZE_1:
7237  if (CB_SIZES(l) & CB_SIZE_UNSIGNED) {
7238  s = "cob_u8_t";
7239  } else {
7240  s = "cob_c8_t";
7241  }
7242  break;
7243  case CB_SIZE_2:
7244  if (CB_SIZES(l) & CB_SIZE_UNSIGNED) {
7245  s = "cob_u16_t";
7246  } else {
7247  s = "cob_s16_t";
7248  }
7249  break;
7250  case CB_SIZE_4:
7251  if (CB_SIZES(l) & CB_SIZE_UNSIGNED) {
7252  s = "cob_u32_t";
7253  } else {
7254  s = "cob_s32_t";
7255  }
7256  break;
7257  case CB_SIZE_8:
7258  if (CB_SIZES(l) & CB_SIZE_UNSIGNED) {
7259  s = "cob_u64_t";
7260  } else {
7261  s = "cob_s64_t";
7262  }
7263  break;
7264  default:
7265  break;
7266  }
7267  }
7268  if (s) {
7269  output (" static %s\tcob_parm_l_%d = %s;\n",
7270  s, f->id, s2);
7271  sticky_nonp[parmnum] = 1;
7272  break;
7273  }
7274  /* Fall through */
7275  case CB_CALL_BY_REFERENCE:
7276  case CB_CALL_BY_CONTENT:
7277  break;
7278  default:
7279  break;
7280  }
7281  }
7282  }
7283 
7284  /* By value pointer fields */
7285  for (l2 = using_list; l2; l2 = CB_CHAIN (l2)) {
7286  f2 = cb_code_field (CB_VALUE (l2));
7287  if (CB_PURPOSE_INT (l2) == CB_CALL_BY_VALUE &&
7288  (f2->usage == CB_USAGE_POINTER ||
7289  f2->usage == CB_USAGE_PROGRAM_POINTER)) {
7290  output (" unsigned char\t\t*ptr_%d;\n", f2->id);
7291  }
7292  }
7293 
7294  /* Sticky linkage set up */
7295  if (cb_sticky_linkage && using_list) {
7296  parmnum = 0;
7297  output (" switch (cob_get_global_ptr ()->cob_call_params) {\n");
7298  for (l = using_list; l; l = CB_CHAIN (l), parmnum++) {
7299  output (" case %u:\n", parmnum);
7300  for (n = 0; n < parmnum; ++n) {
7301  if (sticky_nonp[n]) {
7302  output ("\tcob_parm_l_%d = %s%d;\n",
7303  sticky_ids[n], CB_PREFIX_BASE,
7304  sticky_ids[n]);
7305  output ("\tcob_parm_%d = (cob_u8_ptr)&cob_parm_l_%d;\n",
7306  sticky_ids[n],
7307  sticky_ids[n]);
7308  } else {
7309  output ("\tcob_parm_%d = %s%d;\n",
7310  sticky_ids[n], CB_PREFIX_BASE,
7311  sticky_ids[n]);
7312  }
7313  }
7314  output ("\tbreak;\n");
7315  }
7316  output (" default:\n");
7317  for (n = 0; n < parmnum; ++n) {
7318  if (sticky_nonp[n]) {
7319  output ("\tcob_parm_l_%d = %s%d;\n",
7320  sticky_ids[n], CB_PREFIX_BASE,
7321  sticky_ids[n]);
7322  output ("\tcob_parm_%d = (cob_u8_ptr)&cob_parm_l_%d;\n",
7323  sticky_ids[n],
7324  sticky_ids[n]);
7325  } else {
7326  output ("\tcob_parm_%d = %s%d;\n",
7327  sticky_ids[n], CB_PREFIX_BASE,
7328  sticky_ids[n]);
7329  }
7330  }
7331  output ("\tbreak;\n");
7332  output (" }\n");
7333  }
7334 
7335  if (cb_sticky_linkage) {
7336  s_prefix = "cob_parm_";
7337  } else {
7338  s_prefix = CB_PREFIX_BASE;
7339  }
7340 
7341  for (l2 = using_list; l2; l2 = CB_CHAIN (l2)) {
7342  f2 = cb_code_field (CB_VALUE (l2));
7343  if (CB_PURPOSE_INT (l2) == CB_CALL_BY_VALUE &&
7344  (f2->usage == CB_USAGE_POINTER ||
7345  f2->usage == CB_USAGE_PROGRAM_POINTER)) {
7346  output (" ptr_%d = %s%d;\n",
7347  f2->id, s_prefix, f2->id);
7348  }
7349  }
7350 
7351  if (!prog->nested_level) {
7352  if (prog->flag_void) {
7353  output (" return (void)%s_ (%d", prog->program_id, progid++);
7354  } else {
7355  output (" return %s_ (%d", prog->program_id, progid++);
7356  }
7357  } else {
7358  if (prog->flag_void) {
7359  output (" return (void)%s_%d_ (%d", prog->program_id,
7360  prog->toplev_count, progid++);
7361  } else {
7362  output (" return %s_%d_ (%d", prog->program_id,
7363  prog->toplev_count, progid++);
7364  }
7365  }
7366 
7367  if (!using_list && !parameter_list) {
7368  output (");\n");
7369  output ("}\n\n");
7370  return;
7371  }
7372 
7373  for (l1 = parameter_list; l1; l1 = CB_CHAIN (l1)) {
7374  f1 = cb_code_field (CB_VALUE (l1));
7375  n = 0;
7376  for (l2 = using_list; l2; l2 = CB_CHAIN (l2), ++n) {
7377  f2 = cb_code_field (CB_VALUE (l2));
7378  if (strcasecmp (f1->name, f2->name) == 0) {
7379  switch (CB_PURPOSE_INT (l2)) {
7380  case CB_CALL_BY_VALUE:
7381  if (f2->usage == CB_USAGE_POINTER ||
7383  output (", (cob_u8_ptr)&ptr_%d", f2->id);
7384  break;
7385  }
7386  /* Fall through */
7387  case CB_CALL_BY_REFERENCE:
7388  case CB_CALL_BY_CONTENT:
7389  output (", %s%s%d",
7390  s_type[n], s_prefix, f2->id);
7391  break;
7392  default:
7393  break;
7394  }
7395  break;
7396  }
7397  }
7398  if (l2 == NULL) {
7399  if (cb_sticky_linkage) {
7400  output (", %s%d",
7401  s_prefix, f1->id);
7402  } else {
7403  output (", NULL");
7404  }
7405  }
7406  }
7407  output (");\n");
7408  output ("}\n\n");
7409 }
const char * name
Definition: tree.h:645
#define CB_SIZES(x)
Definition: tree.h:1195
#define CB_LABEL(x)
Definition: tree.h:801
#define cob_u32_t
Definition: common.h:31
#define CB_CALL_BY_REFERENCE
Definition: tree.h:44
int toplev_count
Definition: tree.h:1297
static void output(const char *,...)
Definition: codegen.c:192
#define CB_CALL_BY_CONTENT
Definition: tree.h:45
#define CB_SIZE_8
Definition: tree.h:52
#define CB_PURPOSE_INT(x)
Definition: tree.h:1197
#define CB_SIZE_2
Definition: tree.h:50
int nested_level
Definition: tree.h:1295
cob_field f2
Definition: cobxref.c.l.h:55
unsigned int flag_main
Definition: tree.h:1305
#define CB_PURPOSE(x)
Definition: tree.h:1192
#define CB_PREFIX_BASE
Definition: tree.h:31
#define CB_SIZES_INT(x)
Definition: tree.h:1199
#define CB_SIZE_4
Definition: tree.h:51
#define CB_VALUE(x)
Definition: tree.h:1193
#define CB_TREE_CLASS(x)
Definition: tree.h:442
int id
Definition: tree.h:671
#define CB_SIZE_1
Definition: tree.h:49
Definition: tree.h:643
#define unlikely(x)
Definition: common.h:437
#define CB_CALL_BY_VALUE
Definition: tree.h:46
#define CB_SIZE_UNSIGNED
Definition: tree.h:53
#define CB_CHAIN(x)
Definition: tree.h:1194
cob_s64_t n2
Definition: GCic.c.l3.h:46
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
unsigned char prog_type
Definition: tree.h:1303
cob_field f1
Definition: cobxref.c.l.h:54
const char * program_id
Definition: tree.h:1244
unsigned int flag_recursive
Definition: tree.h:1308
unsigned int flag_chained
Definition: tree.h:1311
#define CB_FUNCTION_TYPE
Definition: tree.h:42
unsigned int flag_void
Definition: tree.h:1325
#define COB_MAX_FIELD_PARAMS
Definition: common.h:559
static int progid
Definition: codegen.c:164
enum cb_usage usage
Definition: tree.h:693

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_error_handler ( struct cb_program prog)
static

Definition at line 5635 of file codegen.c.

References CB_LABEL, cb_list_length(), cb_standard_error_handler, COB_OPEN_EXTEND, COB_OPEN_INPUT, cb_program::global_handler, handler_struct::handler_label, handler_struct::handler_prog, cb_label::id, cb_program::nested_level, output(), output_indent(), output_line(), output_newline(), output_perform_call(), output_perform_exit(), output_prefix(), output_stmt(), cb_program::parameter_list, cb_program::program_id, and cb_program::toplev_count.

Referenced by output_internal_function().

5636 {
5637  struct handler_struct *hstr;
5638  size_t seen;
5639  int i;
5640  int n;
5641  int parmnum;
5642 
5643  output_newline ();
5644  seen = 0;
5645  for (i = COB_OPEN_INPUT; i <= COB_OPEN_EXTEND; i++) {
5646  if (prog->global_handler[i].handler_label) {
5647  seen = 1;
5648  break;
5649  }
5650  }
5652  output_newline ();
5653  if (seen) {
5654  output_line ("switch (cob_glob_ptr->cob_error_file->last_open_mode)");
5655  output_indent ("{");
5656  for (i = COB_OPEN_INPUT; i <= COB_OPEN_EXTEND; i++) {
5657  hstr = &prog->global_handler[i];
5658  if (hstr->handler_label) {
5659  output_line ("case %d:", i);
5660  output_indent ("{");
5661  if (prog == hstr->handler_prog) {
5663  hstr->handler_label);
5664  } else {
5665  output_prefix ();
5666  if (hstr->handler_prog->nested_level) {
5667  output ("%s_%d_ (%d",
5668  hstr->handler_prog->program_id,
5669  hstr->handler_prog->toplev_count,
5670  hstr->handler_label->id);
5671  } else {
5672  output ("%s_ (%d",
5673  hstr->handler_prog->program_id,
5674  hstr->handler_label->id);
5675  }
5676  parmnum = cb_list_length (hstr->handler_prog->parameter_list);
5677  for (n = 0; n < parmnum; n++) {
5678  output (", NULL");
5679  }
5680  output (");\n");
5681  }
5682  output_line ("break;");
5683  output_indent ("}");
5684  }
5685  }
5686  output_line ("default:");
5687  output_indent ("{");
5688  }
5689  output_line ("if (!(cob_glob_ptr->cob_error_file->flag_select_features & COB_SELECT_FILE_STATUS)) {");
5690  output_line ("\tcob_fatal_error (COB_FERROR_FILE);");
5691  output_line ("}");
5692  if (seen) {
5693  output_line ("break;");
5694  output_indent ("}");
5695  output_indent ("}");
5696  }
5698  output_newline ();
5699  output_line ("/* Fatal error if reached */");
5700  output_line ("cob_fatal_error (COB_FERROR_CODEGEN);");
5701  output_newline ();
5702 }
struct cb_label * handler_label
Definition: tree.h:805
#define CB_LABEL(x)
Definition: tree.h:801
static void output_newline(void)
Definition: codegen.c:433
int toplev_count
Definition: tree.h:1297
static void output(const char *,...)
Definition: codegen.c:192
static void output_line(const char *fmt,...)
Definition: codegen.c:453
int nested_level
Definition: tree.h:1295
static void output_prefix(void)
Definition: codegen.c:441
int cb_list_length(cb_tree l)
Definition: tree.c:1342
static void output_perform_exit(struct cb_label *l)
Definition: codegen.c:4017
#define COB_OPEN_EXTEND
Definition: common.h:787
#define COB_OPEN_INPUT
Definition: common.h:784
cb_tree cb_standard_error_handler
Definition: tree.c:144
struct cb_program * handler_prog
Definition: tree.h:806
static void output_perform_call(struct cb_label *lb, struct cb_label *le)
Definition: codegen.c:3905
const char * program_id
Definition: tree.h:1244
cb_tree parameter_list
Definition: tree.h:1259
struct handler_struct global_handler[5]
Definition: tree.h:1283
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
int id
Definition: tree.h:773
static void output_indent(const char *str)
Definition: codegen.c:467

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_ferror_stmt ( struct cb_statement p,
const int  code 
)
static

Definition at line 4489 of file codegen.c.

References CB_FILE, cb_statement::file, cb_statement::handler1, cb_statement::handler2, cb_statement::handler3, output_file_error(), output_indent(), output_line(), and output_stmt().

Referenced by output_stmt().

4490 {
4491  output_line ("if (unlikely(cob_glob_ptr->cob_exception_code != 0))");
4492  output_indent ("{");
4493  if (p->handler1) {
4494  if ((code & 0x00ff) == 0) {
4495  output_line ("if ((cob_glob_ptr->cob_exception_code & 0xff00) == 0x%04x)",
4496  code);
4497  } else {
4498  output_line ("if (cob_glob_ptr->cob_exception_code == 0x%04x)", code);
4499  }
4500  output_indent ("{");
4501  output_stmt (p->handler1);
4502  output_indent ("}");
4503  output_line ("else");
4504  output_indent ("{");
4505  }
4507  output_indent ("}");
4508  if (p->handler1) {
4509  output_indent ("}");
4510  }
4511  if (p->handler2 || p->handler3) {
4512  output_line ("else");
4513  output_indent ("{");
4514  if (p->handler3) {
4515  output_stmt (p->handler3);
4516  }
4517  if (p->handler2) {
4518  output_stmt (p->handler2);
4519  }
4520  output_indent ("}");
4521  }
4522 }
static void output_line(const char *fmt,...)
Definition: codegen.c:453
#define CB_FILE(x)
Definition: tree.h:858
cb_tree file
Definition: tree.h:1140
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
cb_tree handler3
Definition: tree.h:1143
static void output_file_error(struct cb_file *pfile)
Definition: codegen.c:4326
cb_tree handler1
Definition: tree.h:1141
static void output_indent(const char *str)
Definition: codegen.c:467
cb_tree handler2
Definition: tree.h:1142

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_field ( cb_tree  x)
static

Definition at line 1045 of file codegen.c.

References output(), output_attr(), output_data(), and output_size().

Referenced by codegen(), lookup_literal(), and output_param().

1046 {
1047  output ("{");
1048  output_size (x);
1049  output (", ");
1050  output_data (x);
1051  output (", ");
1052  output_attr (x);
1053  output ("}");
1054 }
static void output(const char *,...)
Definition: codegen.c:192
static void output_data(cb_tree x)
Definition: codegen.c:705
static void output_size(const cb_tree x)
Definition: codegen.c:793
static void output_attr(const cb_tree x)
Definition: codegen.c:929

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_figurative ( cb_tree  x,
const struct cb_field f,
const int  value,
const int  init_occurs 
)
static

Definition at line 2368 of file codegen.c.

References CB_REFERENCE, CB_REFERENCE_P, cb_field::occurs_max, output(), output_data(), output_prefix(), output_size(), and cb_field::size.

Referenced by output_initialize_one().

2370 {
2371  output_prefix ();
2372  /* Check for non-standard 01 OCCURS */
2373  if (init_occurs) {
2374  output ("memset (");
2375  output_data (x);
2376  output (", %d, %d);\n", value, f->occurs_max);
2377  } else if (f->size == 1) {
2378  output ("*(cob_u8_ptr)(");
2379  output_data (x);
2380  output (") = %d;\n", value);
2381  } else {
2382  output ("memset (");
2383  output_data (x);
2384  if (CB_REFERENCE_P(x) && CB_REFERENCE(x)->length) {
2385  output (", %d, ", value);
2386  output_size (x);
2387  output (");\n");
2388  } else {
2389  output (", %d, %d);\n", value, f->size);
2390  }
2391  }
2392 }
int occurs_max
Definition: tree.h:677
#define CB_REFERENCE_P(x)
Definition: tree.h:902
static void output(const char *,...)
Definition: codegen.c:192
static void output_data(cb_tree x)
Definition: codegen.c:705
static void output_prefix(void)
Definition: codegen.c:441
static void output_size(const cb_tree x)
Definition: codegen.c:793
strict implicit external value
Definition: warning.def:54
#define CB_REFERENCE(x)
Definition: tree.h:901
int size
Definition: tree.h:672

Here is the call graph for this function:

Here is the caller graph for this function:

static int output_file_allocation ( struct cb_file f)
static

Definition at line 5099 of file codegen.c.

References cb_alphabet_name::alphabet_type, CB_ALPHABET_ASCII, CB_ALPHABET_CUSTOM, CB_ALPHABET_EBCDIC, CB_FIELD_PTR, CB_PREFIX_FILE, CB_PREFIX_KEYS, cb_file::cname, COB_ORG_INDEXED, COB_ORG_RELATIVE, cb_file::code_set, cb_file::file_status, cb_file::flag_global, gen_custom, gen_ebcdic_ascii, gen_full_ebcdic, gen_native, cb_file::linage, cb_file::name, cb_file::organization, output_local(), and output_storage().

Referenced by output_internal_function().

5100 {
5101 
5102  if (f->flag_global) {
5103 #if 0 /* RXWRXW - Global status */
5104  if (f->file_status) {
5105  /* Force status into main storage file */
5106  CB_FIELD_PTR (f->file_status)->flag_is_global = 1;
5107  }
5108 #endif
5109  output_storage ("\n/* Global file %s */\n", f->name);
5110  } else {
5111  output_local ("\n/* File %s */\n", f->name);
5112  }
5113  /* Output RELATIVE/RECORD KEY's */
5114  if (f->organization == COB_ORG_RELATIVE ||
5115  f->organization == COB_ORG_INDEXED) {
5116  if (f->flag_global) {
5117  output_storage ("static cob_file_key\t*%s%s = NULL;\n",
5118  CB_PREFIX_KEYS, f->cname);
5119  } else {
5120  output_local ("static cob_file_key\t*%s%s = NULL;\n",
5121  CB_PREFIX_KEYS, f->cname);
5122  }
5123  }
5124  if (f->flag_global) {
5125  output_storage ("static cob_file\t\t*%s%s = NULL;\n",
5126  CB_PREFIX_FILE, f->cname);
5127  output_storage ("static unsigned char\t%s%s_status[4];\n",
5128  CB_PREFIX_FILE, f->cname);
5129  } else {
5130  output_local ("static cob_file\t\t*%s%s = NULL;\n",
5131  CB_PREFIX_FILE, f->cname);
5132  output_local ("static unsigned char\t%s%s_status[4];\n",
5133  CB_PREFIX_FILE, f->cname);
5134  }
5135 
5136  if (f->code_set) {
5137  gen_native = 1;
5138  switch (f->code_set->alphabet_type) {
5139  case CB_ALPHABET_ASCII:
5140  gen_ebcdic_ascii = 1;
5141  break;
5142  case CB_ALPHABET_EBCDIC:
5143  gen_full_ebcdic = 1;
5144  break;
5145  case CB_ALPHABET_CUSTOM:
5146  gen_custom = 1;
5147  break;
5148  default:
5149  break;
5150  }
5151  }
5152 
5153  if (f->linage) {
5154  return 1;
5155  }
5156  return 0;
5157 }
const char * name
Definition: tree.h:820
unsigned int flag_global
Definition: tree.h:853
static unsigned int gen_custom
Definition: codegen.c:154
#define CB_FIELD_PTR(x)
Definition: tree.h:745
static unsigned int gen_ebcdic_ascii
Definition: codegen.c:151
#define CB_PREFIX_FILE
Definition: tree.h:35
static void output_local(const char *fmt,...)
Definition: codegen.c:527
#define CB_ALPHABET_ASCII
Definition: tree.h:108
#define COB_ORG_INDEXED
Definition: common.h:745
cb_tree linage
Definition: tree.h:832
static void output_storage(const char *fmt,...)
Definition: codegen.c:515
static unsigned int gen_native
Definition: codegen.c:153
struct cb_alphabet_name * code_set
Definition: tree.h:840
#define CB_PREFIX_KEYS
Definition: tree.h:36
#define COB_ORG_RELATIVE
Definition: common.h:744
#define CB_ALPHABET_CUSTOM
Definition: tree.h:110
cb_tree file_status
Definition: tree.h:824
char * cname
Definition: tree.h:821
int organization
Definition: tree.h:844
static unsigned int gen_full_ebcdic
Definition: codegen.c:152
unsigned int alphabet_type
Definition: tree.h:543
#define CB_ALPHABET_EBCDIC
Definition: tree.h:109

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_file_error ( struct cb_file pfile)
static

Definition at line 4326 of file codegen.c.

References cb_build_debug(), CB_CHAIN, cb_debug_contents, CB_FILE, CB_VALUE, cb_program::flag_gen_debug, cb_program::global_file_list, cb_file::handler, cb_file::handler_prog, cb_label::id, cb_program::local_file_list, cb_file::name, cb_program::nested_level, NULL, output_line(), output_perform_call(), output_stmt(), cb_program::program_id, and cb_program::toplev_count.

Referenced by output_ferror_stmt().

4327 {
4328  struct cb_file *fl;
4329  cb_tree l;
4330 
4333  "USE PROCEDURE", NULL));
4334  }
4335  for (l = current_prog->local_file_list; l; l = CB_CHAIN (l)) {
4336  fl = CB_FILE(CB_VALUE (l));
4337  if (!strcmp (pfile->name, fl->name)) {
4339  fl->handler);
4340  return;
4341  }
4342  }
4343  for (l = current_prog->global_file_list; l; l = CB_CHAIN (l)) {
4344  fl = CB_FILE(CB_VALUE (l));
4345  if (!strcmp (pfile->name, fl->name)) {
4346  if (fl->handler_prog == current_prog) {
4348  fl->handler);
4349  } else {
4350  if (fl->handler_prog->nested_level) {
4351  output_line ("%s_%d_ (%d);",
4352  fl->handler_prog->program_id,
4354  fl->handler->id);
4355  } else {
4356  output_line ("%s_ (%d);",
4357  fl->handler_prog->program_id,
4358  fl->handler->id);
4359  }
4360  }
4361  return;
4362  }
4363  }
4364  output_perform_call (pfile->handler, pfile->handler);
4365 }
unsigned int flag_gen_debug
Definition: tree.h:1321
const char * name
Definition: tree.h:820
int toplev_count
Definition: tree.h:1297
static void output_line(const char *fmt,...)
Definition: codegen.c:453
cb_tree global_file_list
Definition: tree.h:1282
int nested_level
Definition: tree.h:1295
cb_tree local_file_list
Definition: tree.h:1281
#define CB_FILE(x)
Definition: tree.h:858
#define CB_VALUE(x)
Definition: tree.h:1193
static struct cb_program * current_prog
Definition: codegen.c:140
struct cb_program * handler_prog
Definition: tree.h:838
#define CB_CHAIN(x)
Definition: tree.h:1194
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
struct cb_label * handler
Definition: tree.h:837
Definition: tree.h:818
static void output_perform_call(struct cb_label *lb, struct cb_label *le)
Definition: codegen.c:3905
const char * program_id
Definition: tree.h:1244
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
cb_tree cb_build_debug(const cb_tree target, const char *str, const cb_tree fld)
Definition: tree.c:1566
int id
Definition: tree.h:773
cb_tree cb_debug_contents
Definition: typeck.c:88

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_file_initialization ( struct cb_file f)
static

Definition at line 5160 of file codegen.c.

References cb_file::access_mode, cb_file::alt_key_list, cb_file::assign, CB_PREFIX_FILE, CB_PREFIX_KEYS, CB_TREE, cb_file::cname, COB_FILE_VERSION, COB_ORG_INDEXED, COB_ORG_RELATIVE, COB_SELECT_EXTERNAL, COB_SELECT_FILE_STATUS, COB_SELECT_LINAGE, cb_alt_key::duplicates, cb_file::file_status, cb_file::flag_ext_assign, cb_file::flag_external, cb_alt_key::key, cb_file::key, cb_file::latbot, cb_file::latfoot, cb_file::lattop, cb_file::linage, cb_file::linage_ctr, cb_file::lock_mode, cb_file::name, cb_alt_key::next, cb_file::optional, cb_file::organization, output(), output_indent(), output_line(), output_param(), output_prefix(), cb_file::record, cb_file::record_depending, cb_file::record_max, cb_file::record_min, and cb_file::special.

Referenced by output_internal_function().

5161 {
5162  struct cb_alt_key *l;
5163  int nkeys;
5164  int features;
5165 
5166  nkeys = 1;
5167  if (f->flag_external) {
5168  output_line ("%s%s = cob_external_addr (\"%s\", sizeof(cob_file));",
5169  CB_PREFIX_FILE, f->cname, f->cname);
5170  output_line ("if (cob_glob_ptr->cob_initial_external)");
5171  output_indent ("{");
5172  if (f->linage) {
5173  output_line ("%s%s->linorkeyptr = cob_cache_malloc (sizeof(cob_linage));", CB_PREFIX_FILE, f->cname);
5174  }
5175  } else {
5176  output_line ("if (!%s%s)", CB_PREFIX_FILE, f->cname);
5177  output_indent ("{");
5178  output_line ("%s%s = cob_cache_malloc (sizeof(cob_file));", CB_PREFIX_FILE, f->cname);
5179  if (f->linage) {
5180  output_line ("%s%s->linorkeyptr = cob_cache_malloc (sizeof(cob_linage));", CB_PREFIX_FILE, f->cname);
5181  }
5182  output_indent ("}");
5183  }
5184  /* Output RELATIVE/RECORD KEY's */
5185  if (f->organization == COB_ORG_RELATIVE
5186  || f->organization == COB_ORG_INDEXED) {
5187  for (l = f->alt_key_list; l; l = l->next) {
5188  nkeys++;
5189  }
5190  output_line ("if (!%s%s)", CB_PREFIX_KEYS, f->cname);
5191  output_indent ("{");
5192  output_line ("%s%s = cob_cache_malloc (sizeof (cob_file_key) * %d);",
5193  CB_PREFIX_KEYS, f->cname, nkeys);
5194  output_indent ("}");
5195  nkeys = 1;
5196  output_prefix ();
5197  output ("%s%s->field = ", CB_PREFIX_KEYS, f->cname);
5198  output_param (f->key, -1);
5199  output (";\n");
5200  output_prefix ();
5201  output ("%s%s->flag = 0;\n", CB_PREFIX_KEYS, f->cname);
5202  output_prefix ();
5203  if (f->key) {
5204  output ("%s%s->offset = %d;\n", CB_PREFIX_KEYS, f->cname,
5205  cb_code_field (f->key)->offset);
5206  } else {
5207  output ("%s%s->offset = 0;\n", CB_PREFIX_KEYS, f->cname);
5208  }
5209  for (l = f->alt_key_list; l; l = l->next) {
5210  output_prefix ();
5211  output ("(%s%s + %d)->field = ", CB_PREFIX_KEYS, f->cname,
5212  nkeys);
5213  output_param (l->key, -1);
5214  output (";\n");
5215  output_prefix ();
5216  output ("(%s%s + %d)->flag = %d;\n", CB_PREFIX_KEYS,
5217  f->cname, nkeys, l->duplicates);
5218  output_prefix ();
5219  output ("(%s%s + %d)->offset = %d;\n", CB_PREFIX_KEYS,
5220  f->cname, nkeys, cb_code_field (l->key)->offset);
5221  nkeys++;
5222  }
5223  }
5224 
5225  output_line ("%s%s->select_name = (const char *)\"%s\";", CB_PREFIX_FILE,
5226  f->cname, f->name);
5227  if (f->flag_external && !f->file_status) {
5228  output_line ("%s%s->file_status = cob_external_addr (\"%s%s_status\", 4);",
5230  } else {
5231  output_line ("%s%s->file_status = %s%s_status;", CB_PREFIX_FILE,
5232  f->cname, CB_PREFIX_FILE, f->cname);
5233  output_line ("memset (%s%s_status, '0', 2);", CB_PREFIX_FILE,
5234  f->cname);
5235  }
5236  output_prefix ();
5237  output ("%s%s->assign = ", CB_PREFIX_FILE, f->cname);
5238  output_param (f->assign, -1);
5239  output (";\n");
5240  output_prefix ();
5241  output ("%s%s->record = ", CB_PREFIX_FILE, f->cname);
5242  output_param (CB_TREE (f->record), -1);
5243  output (";\n");
5244  output_prefix ();
5245  output ("%s%s->variable_record = ", CB_PREFIX_FILE, f->cname);
5246  if (f->record_depending) {
5247  output_param (f->record_depending, -1);
5248  } else {
5249  output ("NULL");
5250  }
5251  output (";\n");
5252  output_line ("%s%s->record_min = %d;", CB_PREFIX_FILE,
5253  f->cname, f->record_min);
5254  output_line ("%s%s->record_max = %d;", CB_PREFIX_FILE,
5255  f->cname, f->record_max);
5256  if (f->organization == COB_ORG_RELATIVE
5257  || f->organization == COB_ORG_INDEXED) {
5258  output_line ("%s%s->nkeys = %d;", CB_PREFIX_FILE,
5259  f->cname, nkeys);
5260  output_line ("%s%s->keys = %s%s;", CB_PREFIX_FILE,
5261  f->cname, CB_PREFIX_KEYS, f->cname);
5262  } else {
5263  output_line ("%s%s->nkeys = 0;", CB_PREFIX_FILE, f->cname);
5264  output_line ("%s%s->keys = NULL;", CB_PREFIX_FILE, f->cname);
5265  }
5266  output_line ("%s%s->file = NULL;", CB_PREFIX_FILE, f->cname);
5267 
5268  if (f->linage) {
5269  output_line ("lingptr = %s%s->linorkeyptr;",
5270  CB_PREFIX_FILE, f->cname);
5271  output_prefix ();
5272  output ("lingptr->linage = ");
5273  output_param (f->linage, -1);
5274  output (";\n");
5275  output_prefix ();
5276  output ("lingptr->linage_ctr = ");
5277  output_param (f->linage_ctr, -1);
5278  output (";\n");
5279  if (f->latfoot) {
5280  output_prefix ();
5281  output ("lingptr->latfoot = ");
5282  output_param (f->latfoot, -1);
5283  output (";\n");
5284  } else {
5285  output_line ("lingptr->latfoot = NULL;");
5286  }
5287  if (f->lattop) {
5288  output_prefix ();
5289  output ("lingptr->lattop = ");
5290  output_param (f->lattop, -1);
5291  output (";\n");
5292  } else {
5293  output_line ("lingptr->lattop = NULL;");
5294  }
5295  if (f->latbot) {
5296  output_prefix ();
5297  output ("lingptr->latbot = ");
5298  output_param (f->latbot, -1);
5299  output (";\n");
5300  } else {
5301  output_line ("lingptr->latbot = NULL;");
5302  }
5303  output_line ("lingptr->lin_lines = 0;");
5304  output_line ("lingptr->lin_foot = 0;");
5305  output_line ("lingptr->lin_top = 0;");
5306  output_line ("lingptr->lin_bot = 0;");
5307  }
5308 
5309  output_line ("%s%s->fd = -1;", CB_PREFIX_FILE, f->cname);
5310  output_line ("%s%s->organization = %d;", CB_PREFIX_FILE, f->cname,
5311  f->organization);
5312  output_line ("%s%s->access_mode = %d;", CB_PREFIX_FILE, f->cname,
5313  f->access_mode);
5314  output_line ("%s%s->lock_mode = %d;", CB_PREFIX_FILE, f->cname,
5315  f->lock_mode);
5316  output_line ("%s%s->open_mode = 0;", CB_PREFIX_FILE, f->cname);
5317  output_line ("%s%s->flag_optional = %d;", CB_PREFIX_FILE, f->cname,
5318  f->optional);
5319  output_line ("%s%s->last_open_mode = 0;", CB_PREFIX_FILE, f->cname);
5320  output_line ("%s%s->flag_operation = 0;", CB_PREFIX_FILE, f->cname);
5321  output_line ("%s%s->flag_nonexistent = 0;", CB_PREFIX_FILE, f->cname);
5322  output_line ("%s%s->flag_end_of_file = 0;", CB_PREFIX_FILE, f->cname);
5323  output_line ("%s%s->flag_begin_of_file = 0;", CB_PREFIX_FILE, f->cname);
5324  output_line ("%s%s->flag_first_read = 0;", CB_PREFIX_FILE, f->cname);
5325  output_line ("%s%s->flag_read_done = 0;", CB_PREFIX_FILE, f->cname);
5326  features = 0;
5327  if (f->file_status) {
5328  features |= COB_SELECT_FILE_STATUS;
5329  }
5330  if (f->linage) {
5331  features |= COB_SELECT_LINAGE;
5332  }
5333  if (f->flag_ext_assign) {
5334  features |= COB_SELECT_EXTERNAL;
5335  }
5336  if (f->special) {
5337  /* Special assignment */
5338  features |= f->special;
5339  }
5340  output_line ("%s%s->flag_select_features = %d;", CB_PREFIX_FILE, f->cname,
5341  features);
5342  output_line ("%s%s->flag_needs_nl = 0;", CB_PREFIX_FILE, f->cname);
5343  output_line ("%s%s->flag_needs_top = 0;", CB_PREFIX_FILE, f->cname);
5344  output_line ("%s%s->file_version = %d;", CB_PREFIX_FILE, f->cname,
5346  if (f->flag_external) {
5347  output_indent ("}");
5348  }
5349 }
int optional
Definition: tree.h:843
#define CB_TREE(x)
Definition: tree.h:440
int record_max
Definition: tree.h:842
const char * name
Definition: tree.h:820
static void output(const char *,...)
Definition: codegen.c:192
int lock_mode
Definition: tree.h:846
static void output_line(const char *fmt,...)
Definition: codegen.c:453
#define CB_PREFIX_FILE
Definition: tree.h:35
cb_tree lattop
Definition: tree.h:835
#define COB_ORG_INDEXED
Definition: common.h:745
struct cb_alt_key * next
Definition: tree.h:812
cb_tree linage
Definition: tree.h:832
unsigned int flag_ext_assign
Definition: tree.h:851
#define COB_SELECT_LINAGE
Definition: common.h:759
static void output_prefix(void)
Definition: codegen.c:441
int record_min
Definition: tree.h:841
unsigned int flag_external
Definition: tree.h:850
#define CB_PREFIX_KEYS
Definition: tree.h:36
cb_tree latbot
Definition: tree.h:836
#define COB_ORG_RELATIVE
Definition: common.h:744
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
cb_tree linage_ctr
Definition: tree.h:833
cb_tree latfoot
Definition: tree.h:834
int duplicates
Definition: tree.h:814
int access_mode
Definition: tree.h:845
#define COB_SELECT_FILE_STATUS
Definition: common.h:757
#define COB_SELECT_EXTERNAL
Definition: common.h:758
cb_tree file_status
Definition: tree.h:824
int special
Definition: tree.h:847
cb_tree assign
Definition: tree.h:823
char * cname
Definition: tree.h:821
cb_tree key
Definition: tree.h:813
struct cb_field * record
Definition: tree.h:829
int organization
Definition: tree.h:844
#define COB_FILE_VERSION
Definition: common.h:722
cb_tree key
Definition: tree.h:826
struct cb_alt_key * alt_key_list
Definition: tree.h:827
cb_tree record_depending
Definition: tree.h:830
static void output_indent(const char *str)
Definition: codegen.c:467

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_func_1 ( const char *  name,
cb_tree  x 
)
static

Definition at line 2111 of file codegen.c.

References output(), output_param(), and param_id.

Referenced by output_integer(), and output_long_integer().

2112 {
2113  output ("%s (", name);
2114  output_param (x, param_id);
2115  output (")");
2116 }
static void output(const char *,...)
Definition: codegen.c:192
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
static int param_id
Definition: codegen.c:158

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_funcall ( cb_tree  x)
static

Definition at line 2028 of file codegen.c.

References _, cb_funcall::argc, cb_funcall::argv, CB_CHAIN, CB_FUNCALL, cb_high, CB_LITERAL, CB_LITERAL_P, cb_low, cb_space, CB_VALUE, cb_zero, COBC_ABORT, cobc_abort_pr(), cb_funcall::name, nolitcast, cb_funcall::nolitcast, output(), output_data(), output_param(), screenptr, cb_funcall::screenptr, and cb_funcall::varcnt.

Referenced by output_cond(), output_param(), and output_stmt().

2029 {
2030  struct cb_funcall *p;
2031  cb_tree l;
2032  int i;
2033 
2034  p = CB_FUNCALL (x);
2035  if (p->name[0] == '$') {
2036  switch (p->name[1]) {
2037  case 'E':
2038  /* Set of one character */
2039  output ("*(");
2040  output_data (p->argv[0]);
2041  output (") = ");
2042  output_param (p->argv[1], 1);
2043  break;
2044  case 'F':
2045  /* Move of one character */
2046  output ("*(");
2047  output_data (p->argv[0]);
2048  output (") = *(");
2049  output_data (p->argv[1]);
2050  output (")");
2051  break;
2052  case 'G':
2053  /* Test of one character */
2054  output ("(int)(*(");
2055  output_data (p->argv[0]);
2056  if (p->argv[1] == cb_space) {
2057  output (") - ' ')");
2058  } else if (p->argv[1] == cb_zero) {
2059  output (") - '0')");
2060  } else if (p->argv[1] == cb_low) {
2061  output ("))");
2062  } else if (p->argv[1] == cb_high) {
2063  output (") - 255)");
2064  } else if (CB_LITERAL_P (p->argv[1])) {
2065  output (") - %d)", *(CB_LITERAL (p->argv[1])->data));
2066  } else {
2067  output (") - *(");
2068  output_data (p->argv[1]);
2069  output ("))");
2070  }
2071  break;
2072  default:
2073  cobc_abort_pr (_("Unexpected function %s"), p->name);
2074  COBC_ABORT ();
2075  }
2076  return;
2077  }
2078  screenptr = p->screenptr;
2079  output ("%s (", p->name);
2080  for (i = 0; i < p->argc; i++) {
2081  if (p->varcnt && i + 1 == p->argc) {
2082  output ("%d, ", p->varcnt);
2083  for (l = p->argv[i]; l; l = CB_CHAIN (l)) {
2084  if (CB_VALUE (l) && CB_LITERAL_P (CB_VALUE (l))) {
2085  nolitcast = p->nolitcast;
2086  }
2087  output_param (CB_VALUE (l), i);
2088  nolitcast = 0;
2089  i++;
2090  if (CB_CHAIN (l)) {
2091  output (", ");
2092  }
2093  }
2094  } else {
2095  if (p->argv[i] && CB_LITERAL_P (p->argv[i])) {
2096  nolitcast = p->nolitcast;
2097  }
2098  output_param (p->argv[i], i);
2099  nolitcast = 0;
2100  if (i + 1 < p->argc) {
2101  output (", ");
2102  }
2103  }
2104  }
2105  output (")");
2106  nolitcast = 0;
2107  screenptr = 0;
2108 }
unsigned int nolitcast
Definition: tree.h:948
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
static void output(const char *,...)
Definition: codegen.c:192
#define CB_LITERAL(x)
Definition: tree.h:601
const char * name
Definition: tree.h:943
int argc
Definition: tree.h:945
cb_tree cb_zero
Definition: tree.c:125
cb_tree cb_space
Definition: tree.c:127
#define CB_FUNCALL(x)
Definition: tree.h:951
static void output_data(cb_tree x)
Definition: codegen.c:705
#define CB_LITERAL_P(x)
Definition: tree.h:602
#define CB_VALUE(x)
Definition: tree.h:1193
unsigned int screenptr
Definition: tree.h:947
#define _(s)
Definition: cobcrun.c:59
#define CB_CHAIN(x)
Definition: tree.h:1194
#define COBC_ABORT()
Definition: cobc.h:61
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
static int screenptr
Definition: codegen.c:167
static unsigned int nolitcast
Definition: codegen.c:174
cb_tree cb_high
Definition: tree.c:129
cb_tree argv[11]
Definition: tree.h:944
cb_tree cb_low
Definition: tree.c:128
int varcnt
Definition: tree.h:946

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_funcall_debug ( cb_tree  x)
static

Definition at line 4071 of file codegen.c.

References cb_funcall::argc, cb_funcall::argv, cb_build_debug(), CB_CHAIN, cb_debug_contents, cb_debug_name, CB_FUNCALL, CB_REF_OR_FIELD_P, CB_VALUE, cb_funcall::name, NULL, output_param(), output_perform_call(), output_stmt(), and cb_funcall::varcnt.

Referenced by output_cond_debug().

4072 {
4073  struct cb_funcall *p;
4074  cb_tree l;
4075  cb_tree z;
4076  int i;
4077 
4078  p = CB_FUNCALL (x);
4079  if (p->name[0] == '$') {
4080  z = p->argv[0];
4081  if (CB_REF_OR_FIELD_P (z) &&
4082  cb_code_field (z)->flag_field_debug) {
4083  /* DEBUG */
4085  (const char *)cb_code_field (z)->name, NULL));
4087  NULL, z));
4088  output_perform_call (cb_code_field (z)->debug_section,
4089  cb_code_field (z)->debug_section);
4090  }
4091  z = p->argv[1];
4092  if (CB_REF_OR_FIELD_P (z) &&
4093  cb_code_field (z)->flag_field_debug) {
4094  /* DEBUG */
4096  (const char *)cb_code_field (z)->name, NULL));
4098  NULL, z));
4099  output_perform_call (cb_code_field (z)->debug_section,
4100  cb_code_field (z)->debug_section);
4101  }
4102  return;
4103  }
4104  for (i = 0; i < p->argc; i++) {
4105  if (p->varcnt && i + 1 == p->argc) {
4106  for (l = p->argv[i]; l; l = CB_CHAIN (l)) {
4107  output_param (CB_VALUE (l), i);
4108  z = CB_VALUE (l);
4109  if (CB_REF_OR_FIELD_P (z) &&
4110  cb_code_field (z)->flag_field_debug) {
4111  /* DEBUG */
4113  (const char *)cb_code_field (z)->name, NULL));
4115  NULL, z));
4116  output_perform_call (cb_code_field (z)->debug_section,
4117  cb_code_field (z)->debug_section);
4118  }
4119  i++;
4120  }
4121  } else {
4122  z = p->argv[i];
4123  if (CB_REF_OR_FIELD_P (z) &&
4124  cb_code_field (z)->flag_field_debug) {
4125  /* DEBUG */
4127  (const char *)cb_code_field (z)->name, NULL));
4129  NULL, z));
4130  output_perform_call (cb_code_field (z)->debug_section,
4131  cb_code_field (z)->debug_section);
4132  }
4133  }
4134  }
4135 }
const char * name
Definition: tree.h:943
int argc
Definition: tree.h:945
#define CB_FUNCALL(x)
Definition: tree.h:951
#define CB_VALUE(x)
Definition: tree.h:1193
#define CB_CHAIN(x)
Definition: tree.h:1194
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
cb_tree cb_debug_name
Definition: typeck.c:84
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
static void output_perform_call(struct cb_label *lb, struct cb_label *le)
Definition: codegen.c:3905
cb_tree argv[11]
Definition: tree.h:944
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
cb_tree cb_build_debug(const cb_tree target, const char *str, const cb_tree fld)
Definition: tree.c:1566
#define CB_REF_OR_FIELD_P(x)
Definition: tree.h:743
cb_tree cb_debug_contents
Definition: typeck.c:88
int varcnt
Definition: tree.h:946

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_goto ( struct cb_goto p)
static

Definition at line 4406 of file codegen.c.

References cb_build_cast_int(), cb_build_debug(), CB_CHAIN, cb_debug_contents, cb_debug_name, CB_FIELD, CB_FUNCTION_TYPE, cb_int1, cb_ref(), CB_VALUE, cb_field::debug_section, cb_goto::depending, cb_field::flag_all_debug, cb_program::flag_gen_debug, cb_field::name, needs_exit_prog, cb_program::nested_level, NULL, output(), output_goto_1(), output_indent(), output_indent_level, output_line(), output_param(), output_perform_call(), output_prefix(), output_stmt(), cb_program::prog_type, and cb_goto::target.

Referenced by output_stmt().

4407 {
4408  cb_tree l;
4409  struct cb_field *f;
4410  int i;
4411 
4412  i = 1;
4413  if (p->depending) {
4414  /* Check for debugging on the DEPENDING item */
4416  f = CB_FIELD (cb_ref (p->depending));
4417  if (f->flag_all_debug) {
4419  (const char *)f->name, NULL));
4421  NULL, p->depending));
4423  f->debug_section);
4424  }
4425  }
4426  output_prefix ();
4427  output ("switch (");
4429  output (")\n");
4430  output_indent ("{");
4431  for (l = p->target; l; l = CB_CHAIN (l)) {
4432  output_indent_level -= 2;
4433  output_line ("case %d:", i++);
4434  output_indent_level += 2;
4435  output_goto_1 (CB_VALUE (l));
4436  }
4437  output_indent ("}");
4438  } else if (p->target == NULL) {
4439  /* EXIT PROGRAM/FUNCTION */
4440  needs_exit_prog = 1;
4441  if (cb_flag_implicit_init || current_prog->nested_level ||
4443  output_line ("goto exit_program;");
4444  } else {
4445  /* Ignore if not a callee */
4446  output_line ("if (module->next)");
4447  output_line (" goto exit_program;");
4448  }
4449  } else if (p->target == cb_int1) {
4450  needs_exit_prog = 1;
4451  output_line ("goto exit_program;");
4452  } else {
4453  output_goto_1 (p->target);
4454  }
4455 }
const char * name
Definition: tree.h:645
cb_tree cb_int1
Definition: tree.c:134
unsigned int flag_gen_debug
Definition: tree.h:1321
struct cb_label * debug_section
Definition: tree.h:661
static void output(const char *,...)
Definition: codegen.c:192
static void output_line(const char *fmt,...)
Definition: codegen.c:453
cb_tree cb_ref(cb_tree x)
Definition: tree.c:2653
int nested_level
Definition: tree.h:1295
static void output_prefix(void)
Definition: codegen.c:441
#define CB_VALUE(x)
Definition: tree.h:1193
static struct cb_program * current_prog
Definition: codegen.c:140
unsigned int flag_all_debug
Definition: tree.h:734
Definition: tree.h:643
#define CB_CHAIN(x)
Definition: tree.h:1194
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
cb_tree cb_debug_name
Definition: typeck.c:84
unsigned char prog_type
Definition: tree.h:1303
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
static void output_perform_call(struct cb_label *lb, struct cb_label *le)
Definition: codegen.c:3905
static void output_goto_1(cb_tree x)
Definition: codegen.c:4370
static unsigned int needs_exit_prog
Definition: codegen.c:146
#define CB_FUNCTION_TYPE
Definition: tree.h:42
cb_tree depending
Definition: tree.h:1076
static int output_indent_level
Definition: codegen.c:171
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
cb_tree cb_build_debug(const cb_tree target, const char *str, const cb_tree fld)
Definition: tree.c:1566
cb_tree cb_build_cast_int(const cb_tree val)
Definition: tree.c:2964
cb_tree target
Definition: tree.h:1075
cb_tree cb_debug_contents
Definition: typeck.c:88
#define CB_FIELD(x)
Definition: tree.h:740
static void output_indent(const char *str)
Definition: codegen.c:467

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_goto_1 ( cb_tree  x)
static

Definition at line 4370 of file codegen.c.

References cb_program::all_procedure, cb_build_debug(), cb_debug_contents, cb_debug_name, CB_LABEL, CB_PREFIX_LABEL, cb_ref(), cb_space, cb_label::flag_alter, cb_label::flag_debugging_mode, cb_program::flag_gen_debug, cb_label::flag_real_label, cb_label::flag_section, cb_program::flag_segments, cb_label::id, last_segment, cb_label::name, cb_para_label::next, NULL, output_line(), output_move(), output_stmt(), cb_para_label::para, cb_label::para_label, cb_label::section, and cb_label::segment.

Referenced by output_goto().

4371 {
4372  struct cb_label *lb;
4373  struct cb_para_label *p;
4374 
4375  lb = CB_LABEL (cb_ref (x));
4377  /* Zap independent labels */
4378  if (lb->flag_section) {
4379  p = lb->para_label;
4380  } else if (lb->section) {
4381  p = lb->section->para_label;
4382  } else {
4383  p = NULL;
4384  }
4385  for (; p; p = p->next) {
4386  if (p->para->segment > 49 &&
4387  p->para->flag_alter) {
4388  output_line ("label_%s%d = 0;",
4389  CB_PREFIX_LABEL, p->para->id);
4390  }
4391  }
4392  }
4393 
4394  /* Check for debugging on procedure */
4398  (const char *)lb->name, NULL));
4400  }
4401 
4402  output_line ("goto %s%d;", CB_PREFIX_LABEL, lb->id);
4403 }
#define CB_LABEL(x)
Definition: tree.h:801
const char * name
Definition: tree.h:766
unsigned int flag_gen_debug
Definition: tree.h:1321
#define CB_PREFIX_LABEL
Definition: tree.h:37
static void output_line(const char *fmt,...)
Definition: codegen.c:453
unsigned int flag_real_label
Definition: tree.h:781
cb_tree cb_ref(cb_tree x)
Definition: tree.c:2653
struct cb_para_label * para_label
Definition: tree.h:770
cb_tree cb_space
Definition: tree.c:127
static struct cb_program * current_prog
Definition: codegen.c:140
unsigned int flag_section
Definition: tree.h:777
struct cb_label * section
Definition: tree.h:768
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
cb_tree cb_debug_name
Definition: typeck.c:84
unsigned int flag_debugging_mode
Definition: tree.h:796
int segment
Definition: tree.h:775
unsigned int flag_segments
Definition: tree.h:1317
struct cb_para_label * next
Definition: tree.h:755
unsigned int flag_alter
Definition: tree.h:795
Definition: tree.h:764
struct cb_label * all_procedure
Definition: tree.h:1289
struct cb_label * para
Definition: tree.h:756
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
cb_tree cb_build_debug(const cb_tree target, const char *str, const cb_tree fld)
Definition: tree.c:1566
int id
Definition: tree.h:773
static void output_move(cb_tree src, cb_tree dst)
Definition: codegen.c:2235
static int last_segment
Definition: codegen.c:172
cb_tree cb_debug_contents
Definition: typeck.c:88

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_header ( FILE *  fp,
const char *  locbuff,
const struct cb_program cp 
)
static

Definition at line 7424 of file codegen.c.

References cb_oc_build_stamp, cb_saveargc, cb_saveargv, cb_source_file, COB_TAR_DATE, cb_program::orig_program_id, PACKAGE_VERSION, and PATCH_LEVEL.

Referenced by codegen().

7425 {
7426  int i;
7427 
7428  if (fp) {
7429  fprintf (fp, "/* Generated by cobc %s.%d */\n",
7431  fprintf (fp, "/* Generated from %s */\n", cb_source_file);
7432  fprintf (fp, "/* Generated at %s */\n", locbuff);
7433  fprintf (fp, "/* GnuCOBOL build date %s */\n", cb_oc_build_stamp);
7434  fprintf (fp, "/* GnuCOBOL package date %s */\n", COB_TAR_DATE);
7435  fprintf (fp, "/* Compile command ");
7436  for (i = 0; i < cb_saveargc; i++) {
7437  fprintf (fp, "%s ", cb_saveargv[i]);
7438  }
7439  fprintf (fp, "*/\n\n");
7440  if (cp) {
7441  fprintf (fp, "/* Program local variables for '%s' */\n\n",
7442  cp->orig_program_id);
7443  }
7444  }
7445 }
const char * cb_source_file
Definition: cobc.c:145
char * cb_oc_build_stamp
Definition: cobc.c:146
char ** cb_saveargv
Definition: cobc.c:154
int cb_saveargc
Definition: cobc.c:179
#define COB_TAR_DATE
Definition: tarstamp.h:1
#define PACKAGE_VERSION
Definition: config.h:312
#define PATCH_LEVEL
Definition: config.h:315
char * orig_program_id
Definition: tree.h:1246

Here is the caller graph for this function:

static void output_indent ( const char *  str)
static

Definition at line 467 of file codegen.c.

References output_indent_level, and output_line().

Referenced by output_alter_check(), output_call(), output_class_name_definition(), output_error_handler(), output_ferror_stmt(), output_file_initialization(), output_goto(), output_initialize(), output_initialize_compound(), output_initialize_literal(), output_initialize_one(), output_internal_function(), output_main_function(), output_perform(), output_perform_until(), output_search_all(), output_search_whens(), and output_stmt().

468 {
469  const char *p;
470  int level;
471 
472  level = 2;
473  for (p = str; *p == ' '; p++) {
474  level++;
475  }
476 
477  if (*p == '}' && strcmp (str, "})") != 0) {
478  output_indent_level -= level;
479  }
480 
481  output_line (str);
482 
483  if (*p == '{' && strcmp (str, ")}") != 0) {
484  output_indent_level += level;
485  }
486 }
static void output_line(const char *fmt,...)
Definition: codegen.c:453
static int output_indent_level
Definition: codegen.c:171

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_index ( cb_tree  x)
static

Definition at line 1608 of file codegen.c.

References cb_get_int(), CB_INTEGER, CB_TAG_INTEGER, CB_TAG_LITERAL, CB_TREE_TAG, output(), and output_integer().

Referenced by output_data(), and output_size().

1609 {
1610  switch (CB_TREE_TAG (x)) {
1611  case CB_TAG_INTEGER:
1612  output ("%d", CB_INTEGER (x)->val - 1);
1613  break;
1614  case CB_TAG_LITERAL:
1615  output ("%d", cb_get_int (x) - 1);
1616  break;
1617  default:
1618  output ("(");
1619  output_integer (x);
1620  output (" - 1)");
1621  break;
1622  }
1623 }
#define CB_INTEGER(x)
Definition: tree.h:522
static void output(const char *,...)
Definition: codegen.c:192
int cb_get_int(const cb_tree x)
Definition: tree.c:1101
#define CB_TREE_TAG(x)
Definition: tree.h:441
static void output_integer(cb_tree x)
Definition: codegen.c:1101

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_initial_values ( struct cb_field f)
static

Definition at line 5616 of file codegen.c.

References cb_build_field_reference(), cb_build_initialize(), cb_true, cb_field::count, cb_field::flag_item_based, cb_field::flag_no_init, NULL, output_stmt(), and cb_field::sister.

Referenced by output_internal_function().

5617 {
5618  struct cb_field *p;
5619  cb_tree x;
5620 
5621  for (p = f; p; p = p->sister) {
5622  x = cb_build_field_reference (p, NULL);
5623  if (p->flag_item_based) {
5624  continue;
5625  }
5626  /* For special registers */
5627  if (p->flag_no_init && !p->count) {
5628  continue;
5629  }
5630  output_stmt (cb_build_initialize (x, cb_true, NULL, 1, 0, 0));
5631  }
5632 }
cb_tree cb_true
Definition: tree.c:122
struct cb_field * sister
Definition: tree.h:653
cb_tree cb_build_field_reference(struct cb_field *f, cb_tree ref)
Definition: tree.c:2604
Definition: tree.h:643
unsigned int flag_no_init
Definition: tree.h:727
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
int count
Definition: tree.h:680
cb_tree cb_build_initialize(const cb_tree var, const cb_tree val, const cb_tree rep, const unsigned int def, const unsigned int is_statement, const unsigned int no_filler_init)
Definition: tree.c:3028
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
unsigned int flag_item_based
Definition: tree.h:713

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_initialize ( struct cb_initialize p)
static

Definition at line 2831 of file codegen.c.

References CB_BUILD_CHAIN, cb_build_field_reference(), CB_CHAIN, cb_i, CB_REFERENCE, cb_initialize::flag_init_statement, cb_field::flag_occurs, i_counters, INITIALIZE_COMPOUND, INITIALIZE_DEFAULT, INITIALIZE_NONE, INITIALIZE_ONE, initialize_type(), initialize_uniform_char(), cb_field::level, NULL, cb_field::occurs_max, output_indent(), output_initialize_compound(), output_initialize_one(), output_initialize_uniform(), output_line(), cb_field::size, and cb_initialize::var.

Referenced by output_stmt().

2832 {
2833  struct cb_field *f;
2834  cb_tree x;
2835  int c;
2836  int type;
2837 
2838  f = cb_code_field (p->var);
2839  type = initialize_type (p, f, 1);
2840  /* Check for non-standard OCCURS */
2841  if ((f->level == 1 || f->level == 77) &&
2842  f->flag_occurs && !p->flag_init_statement) {
2843  switch (type) {
2844  case INITIALIZE_NONE:
2845  return;
2846  case INITIALIZE_ONE:
2847  output_initialize_one (p, p->var);
2848  return;
2849  case INITIALIZE_DEFAULT:
2850  c = initialize_uniform_char (f, p);
2851  if (c != -1) {
2853  return;
2854  }
2855  /* Fall through */
2856  case INITIALIZE_COMPOUND:
2857  i_counters[0] = 1;
2858  output_line ("for (i0 = 1; i0 <= %d; i0++)", f->occurs_max);
2859  output_indent ("{");
2860  x = cb_build_field_reference (f, NULL);
2861  CB_REFERENCE (x)->subs =
2862  CB_BUILD_CHAIN (cb_i[0], CB_REFERENCE (x)->subs);
2864  CB_REFERENCE (x)->subs =
2865  CB_CHAIN (CB_REFERENCE (x)->subs);
2866  output_indent ("}");
2867  return;
2868  default:
2869  break;
2870  }
2871  }
2872  switch (type) {
2873  case INITIALIZE_NONE:
2874  return;
2875  case INITIALIZE_ONE:
2876  output_initialize_one (p, p->var);
2877  return;
2878  case INITIALIZE_DEFAULT:
2879  c = initialize_uniform_char (f, p);
2880  if (c != -1) {
2881  output_initialize_uniform (p->var, c, f->size);
2882  return;
2883  }
2884  /* Fall through */
2885  case INITIALIZE_COMPOUND:
2887  return;
2888  default:
2889  break;
2890  }
2891 }
int occurs_max
Definition: tree.h:677
static void output_initialize_compound(struct cb_initialize *p, cb_tree x)
Definition: codegen.c:2754
#define INITIALIZE_COMPOUND
Definition: codegen.c:53
static void output_line(const char *fmt,...)
Definition: codegen.c:453
static unsigned int i_counters[16]
Definition: codegen.c:179
cb_tree cb_build_field_reference(struct cb_field *f, cb_tree ref)
Definition: tree.c:2604
#define INITIALIZE_DEFAULT
Definition: codegen.c:52
cb_tree cb_i[16]
Definition: tree.c:139
#define INITIALIZE_NONE
Definition: codegen.c:50
unsigned char flag_init_statement
Definition: tree.h:1012
int level
Definition: tree.h:673
static void output_initialize_one(struct cb_initialize *p, cb_tree x)
Definition: codegen.c:2504
static void output_initialize_uniform(cb_tree x, const int c, const int size)
Definition: codegen.c:2483
#define INITIALIZE_ONE
Definition: codegen.c:51
static int initialize_type(struct cb_initialize *p, struct cb_field *f, const int topfield)
Definition: codegen.c:2251
Definition: tree.h:643
#define CB_CHAIN(x)
Definition: tree.h:1194
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
unsigned int flag_occurs
Definition: tree.h:702
#define CB_REFERENCE(x)
Definition: tree.h:901
int size
Definition: tree.h:672
#define CB_BUILD_CHAIN(x, y)
Definition: tree.h:1852
cb_tree var
Definition: tree.h:1008
static int initialize_uniform_char(const struct cb_field *f, const struct cb_initialize *p)
Definition: codegen.c:2335
static void output_indent(const char *str)
Definition: codegen.c:467

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_initialize_compound ( struct cb_initialize p,
cb_tree  x 
)
static

Definition at line 2754 of file codegen.c.

References CB_BUILD_CHAIN, cb_build_field_reference(), CB_CHAIN, cb_i, cb_int1, CB_REFERENCE, cb_field::children, cb_field::flag_occurs, i_counters, cb_field::indexes, INITIALIZE_DEFAULT, INITIALIZE_NONE, INITIALIZE_ONE, initialize_type(), initialize_uniform_char(), cb_field::occurs_max, cb_field::offset, output_indent(), output_initialize_one(), output_initialize_uniform(), output_line(), cb_field::redefines, cb_field::sister, and cb_field::size.

Referenced by output_initialize().

2755 {
2756  struct cb_field *ff;
2757  struct cb_field *f;
2758  struct cb_field *last_field;
2759  cb_tree c;
2760  size_t size;
2761  int type;
2762  int last_char;
2763  int i;
2764 
2765  ff = cb_code_field (x);
2766  for (f = ff->children; f; f = f->sister) {
2767  type = initialize_type (p, f, 0);
2768  c = cb_build_field_reference (f, x);
2769 
2770  switch (type) {
2771  case INITIALIZE_NONE:
2772  break;
2773  case INITIALIZE_DEFAULT:
2774  last_field = f;
2775  last_char = initialize_uniform_char (f, p);
2776 
2777  if (last_char != -1) {
2778  if (f->flag_occurs) {
2779  CB_REFERENCE (c)->subs =
2781  CB_REFERENCE (c)->subs);
2782  }
2783 
2784  for (; f->sister; f = f->sister) {
2785  if (!f->sister->redefines) {
2786  if (initialize_type (p, f->sister, 0) != INITIALIZE_DEFAULT ||
2787  initialize_uniform_char (f->sister, p) != last_char) {
2788  break;
2789  }
2790  }
2791  }
2792 
2793  if (f->sister) {
2794  size = f->sister->offset - last_field->offset;
2795  } else {
2796  size = ff->offset + ff->size - last_field->offset;
2797  }
2798 
2799  output_initialize_uniform (c, last_char, (int) size);
2800  break;
2801  }
2802  /* Fall through */
2803  default:
2804  if (f->flag_occurs) {
2805  /* Begin occurs loop */
2806  i = f->indexes;
2807  i_counters[i] = 1;
2808  output_line ("for (i%d = 1; i%d <= %d; i%d++)",
2809  i, i, f->occurs_max, i);
2810  output_indent ("{");
2811  CB_REFERENCE (c)->subs =
2812  CB_BUILD_CHAIN (cb_i[i], CB_REFERENCE (c)->subs);
2813  }
2814 
2815  if (type == INITIALIZE_ONE) {
2816  output_initialize_one (p, c);
2817  } else {
2819  }
2820 
2821  if (f->flag_occurs) {
2822  /* Close loop */
2823  CB_REFERENCE (c)->subs = CB_CHAIN (CB_REFERENCE (c)->subs);
2824  output_indent ("}");
2825  }
2826  }
2827  }
2828 }
int indexes
Definition: tree.h:678
int occurs_max
Definition: tree.h:677
static void output_initialize_compound(struct cb_initialize *p, cb_tree x)
Definition: codegen.c:2754
cb_tree cb_int1
Definition: tree.c:134
struct cb_field * sister
Definition: tree.h:653
struct cb_field * children
Definition: tree.h:652
static void output_line(const char *fmt,...)
Definition: codegen.c:453
static unsigned int i_counters[16]
Definition: codegen.c:179
cb_tree cb_build_field_reference(struct cb_field *f, cb_tree ref)
Definition: tree.c:2604
#define INITIALIZE_DEFAULT
Definition: codegen.c:52
cb_tree cb_i[16]
Definition: tree.c:139
#define INITIALIZE_NONE
Definition: codegen.c:50
static void output_initialize_one(struct cb_initialize *p, cb_tree x)
Definition: codegen.c:2504
static void output_initialize_uniform(cb_tree x, const int c, const int size)
Definition: codegen.c:2483
#define INITIALIZE_ONE
Definition: codegen.c:51
int offset
Definition: tree.h:675
static int initialize_type(struct cb_initialize *p, struct cb_field *f, const int topfield)
Definition: codegen.c:2251
Definition: tree.h:643
#define CB_CHAIN(x)
Definition: tree.h:1194
unsigned int flag_occurs
Definition: tree.h:702
#define CB_REFERENCE(x)
Definition: tree.h:901
int size
Definition: tree.h:672
#define CB_BUILD_CHAIN(x, y)
Definition: tree.h:1852
struct cb_field * redefines
Definition: tree.h:654
static int initialize_uniform_char(const struct cb_field *f, const struct cb_initialize *p)
Definition: codegen.c:2335
static void output_indent(const char *str)
Definition: codegen.c:467

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_initialize_fp ( cb_tree  x,
struct cb_field f 
)
static

Definition at line 2469 of file codegen.c.

References CB_USAGE_FLOAT, output(), output_data(), output_prefix(), and cb_field::usage.

Referenced by output_initialize_one().

2470 {
2471  output_prefix ();
2472  if (f->usage == CB_USAGE_FLOAT) {
2473  output ("{float temp = 0.0;");
2474  } else {
2475  output ("{double temp = 0.0;");
2476  }
2477  output (" memcpy (");
2478  output_data (x);
2479  output (", (void *)&temp, sizeof(temp));}\n");
2480 }
static void output(const char *,...)
Definition: codegen.c:192
static void output_data(cb_tree x)
Definition: codegen.c:705
static void output_prefix(void)
Definition: codegen.c:441
enum cb_usage usage
Definition: tree.h:693

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_initialize_fp_bindec ( cb_tree  x,
struct cb_field f 
)
static

Definition at line 2460 of file codegen.c.

References output(), output_data(), output_prefix(), and cb_field::size.

Referenced by output_initialize_one().

2461 {
2462  output_prefix ();
2463  output ("memset (");
2464  output_data (x);
2465  output (", 0, %d);\n", (int)f->size);
2466 }
static void output(const char *,...)
Definition: codegen.c:192
static void output_data(cb_tree x)
Definition: codegen.c:705
static void output_prefix(void)
Definition: codegen.c:441
int size
Definition: tree.h:672

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_initialize_literal ( cb_tree  x,
struct cb_field f,
struct cb_literal l,
const int  init_occurs 
)
static

Definition at line 2395 of file codegen.c.

References CB_REFERENCE, CB_REFERENCE_P, cb_literal::data, i_counters, cb_literal::llit, cb_field::occurs_max, output(), output_data(), output_indent(), output_line(), output_prefix(), output_size(), output_string(), cb_literal::size, and cb_field::size.

Referenced by output_initialize_one().

2397 {
2398  int i;
2399  int n;
2400  int size;
2401  int lsize;
2402 
2403  /* Check for non-standard 01 OCCURS */
2404  if (init_occurs) {
2405  size = f->occurs_max;
2406  lsize = (int)l->size;
2407  /* Check truncated literal */
2408  if (lsize > f->size) {
2409  lsize = f->size;
2410  }
2411  } else {
2412  size = f->size;
2413  lsize = (int)l->size;
2414  }
2415  if (lsize == 1) {
2416  output_prefix ();
2417  output ("memset (");
2418  output_data (x);
2419  if (CB_REFERENCE_P(x) && CB_REFERENCE(x)->length) {
2420  output (", %d, ", l->data[0]);
2421  output_size (x);
2422  output (");\n");
2423  } else {
2424  output (", %d, %d);\n", l->data[0], size);
2425  }
2426  return;
2427  }
2428  if (lsize >= size) {
2429  output_prefix ();
2430  output ("memcpy (");
2431  output_data (x);
2432  output (", ");
2433  output_string (l->data, size, l->llit);
2434  output (", %d);\n", size);
2435  return;
2436  }
2437  i = size / lsize;
2438  i_counters[0] = 1;
2439  output_line ("for (i0 = 0; i0 < %d; i0++)", i);
2440  output_indent ("{");
2441  output_prefix ();
2442  output ("memcpy (");
2443  output_data (x);
2444  output (" + (i0 * %d), ", lsize);
2445  output_string (l->data, lsize, l->llit);
2446  output (", %d);\n", lsize);
2447  output_indent ("}");
2448  n = size % lsize;
2449  if (n) {
2450  output_prefix ();
2451  output ("memcpy (");
2452  output_data (x);
2453  output (" + (i0 * %d), ", lsize);
2454  output_string (l->data, n, l->llit);
2455  output (", %d);\n", n);
2456  }
2457 }
int occurs_max
Definition: tree.h:677
#define CB_REFERENCE_P(x)
Definition: tree.h:902
static void output(const char *,...)
Definition: codegen.c:192
static void output_line(const char *fmt,...)
Definition: codegen.c:453
static unsigned int i_counters[16]
Definition: codegen.c:179
static void output_string(const unsigned char *s, const int size, const cob_u32_t llit)
Definition: codegen.c:489
static void output_data(cb_tree x)
Definition: codegen.c:705
static void output_prefix(void)
Definition: codegen.c:441
static void output_size(const cb_tree x)
Definition: codegen.c:793
cob_u32_t llit
Definition: tree.h:596
#define CB_REFERENCE(x)
Definition: tree.h:901
int size
Definition: tree.h:672
unsigned char * data
Definition: tree.h:593
cob_u32_t size
Definition: tree.h:594
static void output_indent(const char *str)
Definition: codegen.c:467

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_initialize_one ( struct cb_initialize p,
cb_tree  x 
)
static

Definition at line 2504 of file codegen.c.

References _, cb_literal::all, CB_BUILD_CHAIN, CB_CATEGORY_ALPHANUMERIC_EDITED, CB_CATEGORY_NATIONAL, CB_CATEGORY_NATIONAL_EDITED, CB_CATEGORY_NUMERIC, CB_CATEGORY_NUMERIC_EDITED, CB_CHAIN, CB_CLASS_NUMERIC, CB_CONST_P, cb_high, cb_i, CB_LITERAL, CB_LITERAL_P, cb_low, cb_null, CB_PURPOSE_INT, cb_quote, CB_REFERENCE, cb_space, CB_TREE_CATEGORY, CB_TREE_CLASS, CB_USAGE_DISPLAY, CB_USAGE_DOUBLE, CB_USAGE_FLOAT, CB_USAGE_FP_BIN128, CB_USAGE_FP_BIN32, CB_USAGE_FP_BIN64, CB_USAGE_FP_DEC128, CB_USAGE_FP_DEC64, CB_USAGE_LONG_DOUBLE, CB_VALUE, cb_zero, cb_field::children, cob_u32_t, COBC_ABORT, cobc_abort_pr(), cobc_main_malloc(), cobc_main_realloc(), cb_literal::data, cb_field::flag_blank_zero, cb_field::flag_chained, cb_initialize::flag_default, cb_initialize::flag_init_statement, cb_field::flag_occurs, cb_field::flag_sign_separate, i_counters, cb_field::level, litbuff, litsize, cb_literal::llit, cb_field::occurs_max, output(), output_data(), output_figurative(), output_indent(), output_initialize_fp(), output_initialize_fp_bindec(), output_initialize_literal(), output_line(), output_move(), output_prefix(), output_string(), cb_field::param_num, cb_initialize::rep, cb_literal::size, cb_field::size, cb_field::usage, cb_initialize::val, value, and cb_field::values.

Referenced by output_initialize(), and output_initialize_compound().

2505 {
2506  struct cb_field *f;
2507  cb_tree value;
2508  cb_tree lrp;
2509  struct cb_literal *l;
2510  size_t lsize;
2511  cob_u32_t inci;
2512  int i;
2513  int n;
2514  int size;
2515  int offset;
2516  int init_occurs;
2517  unsigned char buffchar;
2518 
2519  f = cb_code_field (x);
2520 
2521  /* CHAINING */
2522  if (f->flag_chained) {
2523  output_prefix ();
2524  output ("cob_chain_setup (");
2525  output_data (x);
2526  output (", %d, %d);\n", f->param_num, f->size);
2527  return;
2528  }
2529  /* Initialize by value */
2530  if (p->val && f->values) {
2531  value = CB_VALUE (f->values);
2532  /* Check for non-standard OCCURS */
2533  if ((f->level == 1 || f->level == 77) &&
2534  f->flag_occurs && !p->flag_init_statement) {
2535  init_occurs = 1;
2536  } else {
2537  init_occurs = 0;
2538  }
2539  if (value == cb_space) {
2540  output_figurative (x, f, ' ', init_occurs);
2541  return;
2542  } else if (value == cb_low) {
2543  output_figurative (x, f, 0, init_occurs);
2544  return;
2545  } else if (value == cb_high) {
2546  output_figurative (x, f, 255, init_occurs);
2547  return;
2548  } else if (value == cb_quote) {
2549  if (cb_flag_apostrophe) {
2550  output_figurative (x, f, '\'', init_occurs);
2551  } else {
2552  output_figurative (x, f, '"', init_occurs);
2553  }
2554  return;
2555  } else if (value == cb_zero && f->usage == CB_USAGE_DISPLAY) {
2556  if (!f->flag_sign_separate && !f->flag_blank_zero) {
2557  output_figurative (x, f, '0', init_occurs);
2558  } else {
2559  output_move (cb_zero, x);
2560  }
2561  return;
2562  } else if (value == cb_null && f->usage == CB_USAGE_DISPLAY) {
2563  output_figurative (x, f, 0, init_occurs);
2564  return;
2565  } else if (CB_LITERAL_P (value) && CB_LITERAL (value)->all) {
2566  /* ALL literal */
2568  CB_LITERAL (value), init_occurs);
2569  return;
2570  } else if (CB_CONST_P (value) ||
2571  CB_TREE_CLASS (value) == CB_CLASS_NUMERIC) {
2572  /* Figurative literal, numeric literal */
2573  /* Check for non-standard 01 OCCURS */
2574  if (init_occurs) {
2575  i_counters[0] = 1;
2576  output_line ("for (i0 = 1; i0 <= %d; i0++)",
2577  f->occurs_max);
2578  output_indent ("{");
2579  CB_REFERENCE (x)->subs =
2580  CB_BUILD_CHAIN (cb_i[0], CB_REFERENCE (x)->subs);
2581  output_move (value, x);
2582  CB_REFERENCE (x)->subs =
2583  CB_CHAIN (CB_REFERENCE (x)->subs);
2584  output_indent ("}");
2585  } else {
2586  output_move (value, x);
2587  }
2588  return;
2589  }
2590  /* Alphanumeric literal */
2591  /* We do not use output_move here because
2592  we do not want to have the value be edited. */
2593 
2594  l = CB_LITERAL (value);
2595 
2596  /* Check for non-standard 01 OCCURS */
2597  if (init_occurs) {
2598  output_initialize_literal (x, f, l, 1);
2599  return;
2600  }
2601 
2602  size = f->size;
2603 
2604  if (size == 1) {
2605  output_prefix ();
2606  output ("*(cob_u8_ptr)(");
2607  output_data (x);
2608  output (") = %u;\n", l->data[0]);
2609  return;
2610  }
2611 
2612  buffchar = l->data[0];
2613  for (lsize = 0; lsize < l->size; lsize++) {
2614  if (l->data[lsize] != buffchar) {
2615  break;
2616  }
2617  }
2618  if (lsize == l->size) {
2619  output_prefix ();
2620  output ("memset (");
2621  output_data (x);
2622  output (", %u, %d);\n", (unsigned int)buffchar,
2623  (int)lsize);
2624  if ((int)l->size < (int)size) {
2625  output_prefix ();
2626  output ("memset (");
2627  output_data (x);
2628  output (" + %d, ' ', %d);\n",
2629  (int)lsize, (int)(size - lsize));
2630  }
2631  return;
2632  }
2633 
2634  if (size > litsize) {
2635  litsize = size + 128;
2636  if (litbuff) {
2638  } else {
2639  litbuff = cobc_main_malloc ((size_t)litsize);
2640  }
2641  }
2642 
2643  if ((int)l->size >= (int)size) {
2644  memcpy (litbuff, l->data, (size_t)size);
2645  } else {
2646  memcpy (litbuff, l->data, (size_t)l->size);
2647  memset (litbuff + l->size, ' ', (size_t)(size - l->size));
2648  }
2649 
2650  buffchar = *(litbuff + size - 1);
2651  n = 0;
2652  for (i = size - 1; i >= 0; i--, n++) {
2653  if (*(litbuff + i) != buffchar) {
2654  break;
2655  }
2656  }
2657  if (i < 0) {
2658  output_prefix ();
2659  output ("memset (");
2660  output_data (x);
2661  output (", %u, %d);\n", (unsigned int)buffchar, size);
2662  return;
2663  }
2664 
2665  if (n > 2) {
2666  offset = size - n;
2667  size -= n;
2668  } else {
2669  offset = 0;
2670  }
2671 
2672  inci = 0;
2673  for (; size > 509; size -= 509, inci += 509) {
2674  output_prefix ();
2675  output ("memcpy (");
2676  output_data (x);
2677  if (!inci) {
2678  output (", ");
2679  } else {
2680  output (" + %u, ", inci);
2681  }
2682  output_string (litbuff + inci, 509, l->llit);
2683  output (", 509);\n");
2684  }
2685 
2686  output_prefix ();
2687  output ("memcpy (");
2688  output_data (x);
2689  if (!inci) {
2690  output (", ");
2691  } else {
2692  output (" + %u, ", inci);
2693  }
2694  output_string (litbuff + inci, size, l->llit);
2695  output (", %d);\n", size);
2696 
2697  if (offset) {
2698  output_prefix ();
2699  output ("memset (");
2700  output_data (x);
2701  output (" + %d, %u, %d);\n",
2702  offset, (unsigned int)buffchar, n);
2703  }
2704  return;
2705  }
2706 
2707  /* Initialize replacing */
2708  if (!f->children) {
2709  for (lrp = p->rep; lrp; lrp = CB_CHAIN (lrp)) {
2710  if ((int)CB_PURPOSE_INT (lrp) == (int)CB_TREE_CATEGORY (x)) {
2711  output_move (CB_VALUE (lrp), x);
2712  return;
2713  }
2714  }
2715  }
2716 
2717  /* Initialize by default */
2718  if (p->flag_default) {
2719  switch (f->usage) {
2720  case CB_USAGE_FLOAT:
2721  case CB_USAGE_DOUBLE:
2722  case CB_USAGE_LONG_DOUBLE:
2723  output_initialize_fp (x, f);
2724  return;
2725  case CB_USAGE_FP_BIN32:
2726  case CB_USAGE_FP_BIN64:
2727  case CB_USAGE_FP_BIN128:
2728  case CB_USAGE_FP_DEC64:
2729  case CB_USAGE_FP_DEC128:
2731  return;
2732  default:
2733  break;
2734  }
2735  switch (CB_TREE_CATEGORY (x)) {
2736  case CB_CATEGORY_NUMERIC:
2738  output_move (cb_zero, x);
2739  break;
2741  case CB_CATEGORY_NATIONAL:
2743  output_move (cb_space, x);
2744  break;
2745  default:
2746  cobc_abort_pr (_("Unexpected tree category %d"),
2747  (int)CB_TREE_CATEGORY (x));
2748  COBC_ABORT ();
2749  }
2750  }
2751 }
int occurs_max
Definition: tree.h:677
void * cobc_main_malloc(const size_t size)
Definition: cobc.c:702
#define CB_TREE_CATEGORY(x)
Definition: tree.h:443
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
#define cob_u32_t
Definition: common.h:31
#define CB_CONST_P(x)
Definition: tree.h:477
static void output(const char *,...)
Definition: codegen.c:192
struct cb_field * children
Definition: tree.h:652
#define CB_LITERAL(x)
Definition: tree.h:601
static void output_line(const char *fmt,...)
Definition: codegen.c:453
static unsigned int i_counters[16]
Definition: codegen.c:179
#define CB_PURPOSE_INT(x)
Definition: tree.h:1197
unsigned char flag_default
Definition: tree.h:1011
cb_tree cb_zero
Definition: tree.c:125
static void output_string(const unsigned char *s, const int size, const cob_u32_t llit)
Definition: codegen.c:489
cb_tree cb_i[16]
Definition: tree.c:139
unsigned char flag_init_statement
Definition: tree.h:1012
int level
Definition: tree.h:673
cb_tree cb_quote
Definition: tree.c:132
cb_tree cb_space
Definition: tree.c:127
static void output_data(cb_tree x)
Definition: codegen.c:705
#define CB_LITERAL_P(x)
Definition: tree.h:602
static void output_prefix(void)
Definition: codegen.c:441
short all
Definition: tree.h:598
void * cobc_main_realloc(void *prevptr, const size_t size)
Definition: cobc.c:738
#define CB_VALUE(x)
Definition: tree.h:1193
#define CB_TREE_CLASS(x)
Definition: tree.h:442
strict implicit external value
Definition: warning.def:54
#define _(s)
Definition: cobcrun.c:59
static int litsize
Definition: codegen.c:144
Definition: tree.h:643
#define CB_CHAIN(x)
Definition: tree.h:1194
static void output_initialize_fp(cb_tree x, struct cb_field *f)
Definition: codegen.c:2469
cob_u32_t llit
Definition: tree.h:596
#define COBC_ABORT()
Definition: cobc.h:61
unsigned int flag_occurs
Definition: tree.h:702
#define CB_REFERENCE(x)
Definition: tree.h:901
int size
Definition: tree.h:672
unsigned char * data
Definition: tree.h:593
static void output_initialize_fp_bindec(cb_tree x, struct cb_field *f)
Definition: codegen.c:2460
static void output_figurative(cb_tree x, const struct cb_field *f, const int value, const int init_occurs)
Definition: codegen.c:2368
static void output_initialize_literal(cb_tree x, struct cb_field *f, struct cb_literal *l, const int init_occurs)
Definition: codegen.c:2395
int param_num
Definition: tree.h:683
unsigned int flag_blank_zero
Definition: tree.h:705
#define CB_BUILD_CHAIN(x, y)
Definition: tree.h:1852
cb_tree cb_null
Definition: tree.c:124
unsigned int flag_sign_separate
Definition: tree.h:703
cb_tree cb_high
Definition: tree.c:129
cb_tree val
Definition: tree.h:1009
cb_tree values
Definition: tree.h:648
cb_tree rep
Definition: tree.h:1010
unsigned int flag_chained
Definition: tree.h:719
cob_u32_t size
Definition: tree.h:594
static unsigned char * litbuff
Definition: codegen.c:143
static void output_move(cb_tree src, cb_tree dst)
Definition: codegen.c:2235
enum cb_usage usage
Definition: tree.h:693
cb_tree cb_low
Definition: tree.c:128
static void output_indent(const char *str)
Definition: codegen.c:467

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_initialize_uniform ( cb_tree  x,
const int  c,
const int  size 
)
static

Definition at line 2483 of file codegen.c.

References CB_REFERENCE, CB_REFERENCE_P, output(), output_data(), output_prefix(), and output_size().

Referenced by output_initialize(), and output_initialize_compound().

2484 {
2485  output_prefix ();
2486  if (size == 1) {
2487  output ("*(cob_u8_ptr)(");
2488  output_data (x);
2489  output (") = %d;\n", c);
2490  } else {
2491  output ("memset (");
2492  output_data (x);
2493  if (CB_REFERENCE_P(x) && CB_REFERENCE(x)->length) {
2494  output (", %d, ", c);
2495  output_size (x);
2496  output (");\n");
2497  } else {
2498  output (", %d, %d);\n", c, size);
2499  }
2500  }
2501 }
#define CB_REFERENCE_P(x)
Definition: tree.h:902
static void output(const char *,...)
Definition: codegen.c:192
static void output_data(cb_tree x)
Definition: codegen.c:705
static void output_prefix(void)
Definition: codegen.c:441
static void output_size(const cb_tree x)
Definition: codegen.c:793
#define CB_REFERENCE(x)
Definition: tree.h:901
cob_u32_t size
Definition: tree.h:594

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_integer ( cb_tree  x)
static

Definition at line 1101 of file codegen.c.

References _, cb_cast::cast_type, CB_BINARY_OP, CB_CAST, CB_CAST_ADDRESS, CB_CAST_PROGRAM_POINTER, CB_CONST, cb_fits_int(), cb_get_int(), CB_INTEGER, cb_null, CB_PREFIX_BASE, CB_STORAGE_LINKAGE, CB_TAG_BINARY_OP, CB_TAG_CAST, CB_TAG_CONST, CB_TAG_INTEGER, CB_TAG_INTRINSIC, CB_TAG_LITERAL, CB_TAG_REFERENCE, CB_TREE_TAG, CB_USAGE_BINARY, CB_USAGE_COMP_5, CB_USAGE_COMP_X, CB_USAGE_DISPLAY, CB_USAGE_INDEX, CB_USAGE_LENGTH, CB_USAGE_PACKED, CB_USAGE_POINTER, CB_USAGE_PROGRAM_POINTER, cb_zero, COB_GET_NUMDISP, COB_GET_PACKED_INT, COBC_ABORT, cobc_abort_pr(), cb_picture::digits, cb_binary_op::flag, cb_field::flag_binary_swap, gen_nested_tab, cb_picture::have_sign, hexval, cb_field::id, cb_field::indexes, cb_program::nested_prog_list, cb_field::offset, cb_binary_op::op, optimize_defs, output(), output_base(), output_data(), output_func_1(), output_param(), cb_field::pic, cb_picture::scale, cb_field::size, cb_field::special_index, cb_field::storage, cb_field::usage, cb_cast::val, cb_binary_op::x, and cb_binary_op::y.

Referenced by output_base(), output_call(), output_call_by_value_args(), output_cond(), output_data(), output_index(), output_internal_function(), output_occurs(), output_param(), output_search_all(), output_search_whens(), output_size(), and output_stmt().

1102 {
1103  struct cb_binary_op *p;
1104  struct cb_cast *cp;
1105  struct cb_field *f;
1106 
1107  switch (CB_TREE_TAG (x)) {
1108  case CB_TAG_CONST:
1109  if (x == cb_zero) {
1110  output ("0");
1111  } else if (x == cb_null) {
1112  output ("(cob_u8_ptr)NULL");
1113  } else {
1114  output ("%s", CB_CONST (x)->val);
1115  }
1116  break;
1117  case CB_TAG_INTEGER:
1118  if (CB_INTEGER (x)->hexval) {
1119  output ("0x%X", CB_INTEGER (x)->val);
1120  } else {
1121  output ("%d", CB_INTEGER (x)->val);
1122  }
1123  break;
1124  case CB_TAG_LITERAL:
1125  output ("%d", cb_get_int (x));
1126  break;
1127  case CB_TAG_BINARY_OP:
1128  p = CB_BINARY_OP (x);
1129  if (p->flag) {
1130  if (!cb_fits_int (p->x) || !cb_fits_int (p->y)) {
1131  output ("cob_get_int (");
1132  output_param (x, -1);
1133  output (")");
1134  break;
1135  }
1136  }
1137  if (p->op == '^') {
1138  output ("(int) pow (");
1139  output_integer (p->x);
1140  output (", ");
1141  output_integer (p->y);
1142  output (")");
1143  } else {
1144  output ("(");
1145  output_integer (p->x);
1146  output (" %c ", p->op);
1147  output_integer (p->y);
1148  output (")");
1149  }
1150  break;
1151  case CB_TAG_CAST:
1152  cp = CB_CAST (x);
1153  switch (cp->cast_type) {
1154  case CB_CAST_ADDRESS:
1155  output ("(");
1156  output_data (cp->val);
1157  output (")");
1158  break;
1160  output ("cob_call_field (");
1161  output_param (x, -1);
1163  gen_nested_tab = 1;
1164  output (", cob_nest_tab, 0, %d)", cb_fold_call);
1165  } else {
1166  output (", NULL, 0, %d)", cb_fold_call);
1167  }
1168  break;
1169  default:
1170  cobc_abort_pr (_("Unexpected cast type %d"),
1171  (int)cp->cast_type);
1172  COBC_ABORT ();
1173  }
1174  break;
1175  case CB_TAG_REFERENCE:
1176  f = cb_code_field (x);
1177  switch (f->usage) {
1178  case CB_USAGE_INDEX:
1179  if (f->special_index) {
1180  output_base (f, 1U);
1181  output ("%s%d", CB_PREFIX_BASE, f->id);
1182  return;
1183  }
1184  /* Fall through */
1185  case CB_USAGE_LENGTH:
1186  output ("(*(int *) (");
1187  output_data (x);
1188  output ("))");
1189  return;
1190 
1191  case CB_USAGE_POINTER:
1192 #ifdef COB_NON_ALIGNED
1193  output ("(cob_get_pointer (");
1194  output_data (x);
1195  output ("))");
1196 #else
1197  output ("(*(unsigned char **) (");
1198  output_data (x);
1199  output ("))");
1200 #endif
1201  return;
1202 
1204 #ifdef COB_NON_ALIGNED
1205  output ("(cob_get_prog_pointer (");
1206  output_data (x);
1207  output ("))");
1208 #else
1209  output ("(*(unsigned char **) (");
1210  output_data (x);
1211  output ("))");
1212 #endif
1213  return;
1214 
1215  case CB_USAGE_DISPLAY:
1216  if (f->pic && f->pic->scale >= 0 &&
1217  f->size - f->pic->scale > 0 &&
1218  f->size - f->pic->scale <= 9 &&
1219  f->pic->have_sign == 0 &&
1220  !cb_ebcdic_sign) {
1222  output ("cob_get_numdisp (");
1223  output_data (x);
1224  output (", %d)", f->size - f->pic->scale);
1225  return;
1226  }
1227  break;
1228 
1229  case CB_USAGE_PACKED:
1230  if (f->pic->scale == 0 && f->pic->digits < 10) {
1232  output_func_1 ("cob_get_packed_int", x);
1233  return;
1234  }
1235  break;
1236 
1237  case CB_USAGE_BINARY:
1238  case CB_USAGE_COMP_5:
1239  case CB_USAGE_COMP_X:
1240  if (f->size == 1) {
1241  output ("(*(");
1242  if (!f->pic->have_sign) {
1243  output ("cob_u8_ptr) (");
1244  } else {
1245  output ("cob_s8_ptr) (");
1246  }
1247  output_data (x);
1248  output ("))");
1249  return;
1250  }
1251 #ifdef COB_NON_ALIGNED
1252  if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && (
1253 #ifdef COB_SHORT_BORK
1254  (f->size == 2 && (f->offset % 4 == 0)) ||
1255 #else
1256  (f->size == 2 && (f->offset % 2 == 0)) ||
1257 #endif
1258  (f->size == 4 && (f->offset % 4 == 0)) ||
1259  (f->size == 8 && (f->offset % 8 == 0)))) {
1260 #else
1261  if (f->size == 2 || f->size == 4 || f->size == 8) {
1262 #endif
1263  if (f->flag_binary_swap) {
1264  output ("((");
1265  switch (f->size) {
1266  case 2:
1267  if (!f->pic->have_sign) {
1268  output ("unsigned short)COB_BSWAP_16(");
1269  } else {
1270  output ("short)COB_BSWAP_16(");
1271  }
1272  break;
1273  case 4:
1274  if (!f->pic->have_sign) {
1275  output ("unsigned int)COB_BSWAP_32(");
1276  } else {
1277  output ("int)COB_BSWAP_32(");
1278  }
1279  break;
1280  case 8:
1281  if (!f->pic->have_sign) {
1282  output ("cob_u64_t)COB_BSWAP_64(");
1283  } else {
1284  output ("cob_s64_t)COB_BSWAP_64(");
1285  }
1286  break;
1287  default:
1288  break;
1289  }
1290  output ("*(");
1291  switch (f->size) {
1292  case 2:
1293  output ("short *)(");
1294  break;
1295  case 4:
1296  output ("int *)(");
1297  break;
1298  case 8:
1299  output ("cob_s64_t *)(");
1300  break;
1301  default:
1302  break;
1303  }
1304  output_data (x);
1305  output (")))");
1306  return;
1307  } else {
1308  output ("(*(");
1309  switch (f->size) {
1310  case 2:
1311  if (!f->pic->have_sign) {
1312  output ("unsigned short *)(");
1313  } else {
1314  output ("short *)(");
1315  }
1316  break;
1317  case 4:
1318  if (!f->pic->have_sign) {
1319  output ("unsigned int *)(");
1320  } else {
1321  output ("int *)(");
1322  }
1323  break;
1324  case 8:
1325  if (!f->pic->have_sign) {
1326  output ("cob_u64_ptr)(");
1327  } else {
1328  output ("cob_s64_ptr)(");
1329  }
1330  break;
1331  default:
1332  break;
1333  }
1334  output_data (x);
1335  output ("))");
1336  return;
1337  }
1338  }
1339  if (f->pic->have_sign == 0) {
1340  output ("(unsigned int)");
1341  }
1342  break;
1343 
1344  default:
1345  break;
1346  }
1347 
1348  output_func_1 ("cob_get_int", x);
1349  break;
1350  case CB_TAG_INTRINSIC:
1351  output ("cob_get_int (");
1352  output_param (x, -1);
1353  output (")");
1354  break;
1355  default:
1356  cobc_abort_pr (_("Unexpected tree tag %d"), (int)CB_TREE_TAG (x));
1357  COBC_ABORT ();
1358  }
1359 }
int indexes
Definition: tree.h:678
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
#define CB_INTEGER(x)
Definition: tree.h:522
int scale
Definition: tree.h:626
static void output(const char *,...)
Definition: codegen.c:192
int cb_get_int(const cb_tree x)
Definition: tree.c:1101
#define CB_CAST(x)
Definition: tree.h:962
static void output_func_1(const char *name, cb_tree x)
Definition: codegen.c:2111
struct cb_picture * pic
Definition: tree.h:659
cob_u32_t digits
Definition: tree.h:625
cb_tree cb_zero
Definition: tree.c:125
cob_u32_t special_index
Definition: tree.h:690
#define CB_PREFIX_BASE
Definition: tree.h:31
static void output_data(cb_tree x)
Definition: codegen.c:705
static struct cb_program * current_prog
Definition: codegen.c:140
int id
Definition: tree.h:671
int offset
Definition: tree.h:675
#define _(s)
Definition: cobcrun.c:59
Definition: tree.h:643
int op
Definition: tree.h:932
#define CB_TREE_TAG(x)
Definition: tree.h:441
#define COBC_ABORT()
Definition: cobc.h:61
static const unsigned char hexval[]
Definition: typeck.c:109
unsigned int flag_binary_swap
Definition: tree.h:707
Definition: tree.h:956
int cb_fits_int(const cb_tree x)
Definition: tree.c:914
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
int size
Definition: tree.h:672
static unsigned int gen_nested_tab
Definition: codegen.c:149
cb_tree y
Definition: tree.h:931
#define CB_CONST(x)
Definition: tree.h:476
enum cb_cast_type cast_type
Definition: tree.h:959
cb_tree cb_null
Definition: tree.c:124
cob_u32_t have_sign
Definition: tree.h:627
struct nested_list * nested_prog_list
Definition: tree.h:1249
static void output_integer(cb_tree x)
Definition: codegen.c:1101
cb_tree x
Definition: tree.h:930
#define CB_BINARY_OP(x)
Definition: tree.h:936
cb_tree val
Definition: tree.h:958
cob_u32_t optimize_defs[COB_OPTIM_MAX]
Definition: cobc.c:182
static void output_base(struct cb_field *f, const cob_u32_t no_output)
Definition: codegen.c:606
unsigned int flag
Definition: tree.h:933
enum cb_usage usage
Definition: tree.h:693
enum cb_storage storage
Definition: tree.h:692

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_internal_function ( struct cb_program prog,
cb_tree  parameter_list 
)
static

Definition at line 5793 of file codegen.c.

References _, cb_program::alphabet_name_list, cb_program::alter_gotos, label_list::call_num, call_list::callname, CB_ALPHABET_NAME, cb_program::cb_call_params, CB_CHAIN, CB_EXCEPTION_ENABLE, CB_FILE, CB_FUNCTION_TYPE, cb_int1, CB_LABEL, cb_list_length(), CB_PREFIX_BASE, CB_PREFIX_FIELD, CB_PREFIX_FILE, CB_PREFIX_KEYS, CB_PREFIX_LABEL, CB_PREFIX_STRING, CB_PROGRAM_TYPE, CB_PURPOSE, cb_program::cb_return_code, CB_USAGE_COMP_6, CB_USAGE_DISPLAY, CB_USAGE_PACKED, CB_VALUE, cb_program::classification, cb_file::cname, COB_EC_DATA_INCOMPATIBLE, COB_EC_PROGRAM_RECURSIVE_CALL, COB_MALLOC_ALIGN, COB_ORG_INDEXED, COB_ORG_RELATIVE, COB_ORG_SORT, COB_SET_SCREEN, cob_u32_t, COBC_ABORT, cobc_abort_pr(), cobc_flag_main, cobc_parse_malloc(), cb_field::count, base_list::curr_prog, cb_program::decimal_index_max, cb_field::ename, cb_program::entry_list, excp_current_program_id, cb_program::exec_list, base_list::f, cb_program::file_list, cb_field::flag_any_length, cb_field::flag_any_numeric, cb_program::flag_chained, cb_program::flag_debugging, cb_field::flag_external, cb_file::flag_external, cb_program::flag_gen_error, cb_program::flag_global_use, cb_program::flag_initial, cb_field::flag_is_global, cb_field::flag_is_returning, cb_field::flag_item_78, cb_field::flag_item_based, cb_field::flag_local_alloced, cb_field::flag_local_storage, cb_program::flag_main, cb_field::flag_no_init, cb_program::flag_recursive, cb_program::flag_segments, gen_dynamic, cb_program::global_list, globext_cache, cb_alter_id::goto_id, label_list::id, cb_field::id, cb_file::linage, cb_program::linkage_storage, cb_program::local_include, local_mem, local_filename::local_name, cb_program::local_storage, local_working_mem, lookup_string(), cb_program::max_call_param, cb_field::mem_offset, cb_field::memory_size, cb_field::name, needs_exit_prog, cb_program::nested_level, label_list::next, call_list::next, base_list::next, cb_alter_id::next, cb_program::next_program, non_nested_count, NULL, cb_program::num_proc_params, optimize_defs, cb_file::organization, cb_program::orig_program_id, output(), output_alphabet_name_definition(), output_base(), output_data(), output_error_handler(), output_file_allocation(), output_file_initialization(), output_indent(), output_initial_values(), output_integer(), output_line(), output_local(), output_module_init(), output_move(), output_newline(), output_param(), output_prefix(), output_screen_definition(), output_screen_init(), output_size(), output_stmt(), output_target, cb_program::parameter_list, cb_program::prog_type, cb_program::program_id, cb_field::redefines, cb_program::returning, cb_program::screen_storage, cb_field::sister, cb_field::size, string_buffer, cb_program::toplev_count, cb_field::usage, working_mem, and cb_program::working_storage.

Referenced by codegen().

5794 {
5795  cb_tree l;
5796  cb_tree l2;
5797  struct cb_field *f;
5798  struct cb_program *next_prog;
5799  struct cb_file *fl;
5800  char *p;
5801  struct label_list *pl;
5802  struct cb_alter_id *cpl;
5803  struct call_list *clp;
5804  struct base_list *bl;
5805  FILE *savetarget;
5806  const char *s;
5807  int i;
5808  cob_u32_t inc;
5809  int parmnum;
5810  int seen;
5811  int anyseen;
5812 
5813  /* Program function */
5814 #if 0 /* RXWRXW USERFUNC */
5815  if (prog->prog_type == CB_FUNCTION_TYPE) {
5816  output ("static cob_field *\n%s_ (const int entry, cob_field **cob_parms",
5817  prog->program_id);
5818 #else
5819  if (prog->prog_type == CB_FUNCTION_TYPE) {
5820  output ("static cob_field *\n%s_ (const int entry",
5821  prog->program_id);
5822 #endif
5823  } else if (!prog->nested_level) {
5824  output ("static int\n%s_ (const int entry",
5825  prog->program_id);
5826  } else {
5827  output ("static int\n%s_%d_ (const int entry",
5828  prog->program_id, prog->toplev_count);
5829  }
5830  parmnum = 0;
5831 #if 0 /* RXWRXW USERFUNC */
5832  if (!prog->flag_chained && prog->prog_type != CB_FUNCTION_TYPE) {
5833 #else
5834  if (!prog->flag_chained) {
5835 #endif
5836  for (l = parameter_list; l; l = CB_CHAIN (l)) {
5837  if (l == parameter_list) {
5838  output (", ");
5839  }
5840  if (parmnum && !(parmnum % 2)) {
5841  output ("\n\t");
5842  }
5843  output ("cob_u8_t *%s%d",
5844  CB_PREFIX_BASE, cb_code_field (CB_VALUE (l))->id);
5845  if (CB_CHAIN (l)) {
5846  output (", ");
5847  }
5848  parmnum++;
5849  }
5850  }
5851  output (")\n");
5852  output_indent ("{");
5853 
5854  /* Program local variables */
5855  output_line ("/* Program local variables */");
5856  output_line ("#include \"%s\"", prog->local_include->local_name);
5857  output_newline ();
5858 
5859  /* Alphabet-names */
5860  if (prog->alphabet_name_list) {
5861  for (l = prog->alphabet_name_list; l; l = CB_CHAIN (l)) {
5863  }
5864  }
5865 
5866  /* Module initialization indicator */
5867  output_local ("/* Module initialization indicator */\n");
5868  output_local ("static unsigned int\tinitialized = 0;\n\n");
5869 
5870  output_local ("/* Module structure pointer */\n");
5871 #if 0 /* RXWRXW - MODULE */
5872  if (prog->flag_recursive) {
5873  output_local ("cob_module\t\t*module;\n\n");
5874  } else {
5875  output_local ("static cob_module\tmodule_data;\n");
5876  output_local ("static cob_module\t*module = &module_data;\n\n");
5877  }
5878 #else
5879  if (prog->flag_recursive) {
5880  output_local ("cob_module\t\t*module = NULL;\n\n");
5881  } else {
5882  output_local ("static cob_module\t*module = NULL;\n\n");
5883  }
5884 #endif
5885 
5886 #if 1 /* RXWRXW - GLOBPTR */
5887  output_local ("/* Global variable pointer */\n");
5888  output_local ("cob_global\t\t*cob_glob_ptr;\n\n");
5889 #endif
5890 
5891  /* Decimal structures */
5892  if (prog->decimal_index_max) {
5893  output_local ("/* Decimal structures */\n");
5894  for (i = 0; i < prog->decimal_index_max; i++) {
5895  output_local ("cob_decimal\t*d%d;\n", i);
5896  }
5897  output_local ("\n");
5898  }
5899 
5900  /* External items */
5901  seen = 0;
5902  for (f = prog->working_storage; f; f = f->sister) {
5903  if (f->flag_external) {
5904  if (f->flag_is_global) {
5905  bl = cobc_parse_malloc (sizeof (struct base_list));
5906  bl->f = f;
5908  bl->next = globext_cache;
5909  globext_cache = bl;
5910  continue;
5911  }
5912  if (!seen) {
5913  seen = 1;
5914  output_local ("/* EXTERNAL items */\n");
5915  }
5916  output_local ("static unsigned char\t*%s%d = NULL;",
5917  CB_PREFIX_BASE, f->id);
5918  output_local (" /* %s */\n", f->name);
5919  }
5920  }
5921  if (seen) {
5922  output_local ("\n");
5923  }
5924  for (l = prog->file_list; l; l = CB_CHAIN (l)) {
5925  f = CB_FILE (CB_VALUE (l))->record;
5926  if (f->flag_external) {
5927  if (f->flag_is_global) {
5928  bl = cobc_parse_malloc (sizeof (struct base_list));
5929  bl->f = f;
5931  bl->next = globext_cache;
5932  globext_cache = bl;
5933  continue;
5934  }
5935  output_local ("static unsigned char\t*%s%d = NULL;",
5936  CB_PREFIX_BASE, f->id);
5937  output_local (" /* %s */\n", f->name);
5938  }
5939  }
5940 
5941  /* Allocate files */
5942  if (prog->file_list) {
5943  i = 0;
5944  for (l = prog->file_list; l; l = CB_CHAIN (l)) {
5946  }
5947  if (i) {
5948  output_local ("\n/* LINAGE pointer */\n");
5949  output_local ("static cob_linage\t\t*lingptr;\n");
5950  }
5951  }
5952 
5953  /* BASED working-storage */
5954  i = 0;
5955  for (f = prog->working_storage; f; f = f->sister) {
5956  if (f->redefines) {
5957  continue;
5958  }
5959  if (f->flag_item_based) {
5960  if (!i) {
5961  i = 1;
5962  output_local("\n/* BASED WORKING-STORAGE SECTION */\n");
5963  }
5964  output_local ("static unsigned char\t*%s%d = NULL; /* %s */\n",
5965  CB_PREFIX_BASE, f->id, f->name);
5966  }
5967  }
5968  if (i) {
5969  output_local ("\n");
5970  }
5971 
5972  /* BASED local-storage */
5973  i = 0;
5974  for (f = prog->local_storage; f; f = f->sister) {
5975  if (f->redefines) {
5976  continue;
5977  }
5978  if (f->flag_item_based) {
5979  if (!i) {
5980  i = 1;
5981  output_local("\n/* BASED LOCAL-STORAGE */\n");
5982  }
5983  output_local ("static unsigned char\t*%s%d = NULL; /* %s */\n",
5984  CB_PREFIX_BASE, f->id, f->name);
5985  }
5986  }
5987  if (i) {
5988  output_local ("\n");
5989  }
5990 
5991 #if 0 /* RXWRXW USERFUNC */
5992  if (prog->prog_type == CB_FUNCTION_TYPE) {
5993  /* USING parameters for user FUNCTION */
5994  seen = 0;
5995  for (l = parameter_list; l; l = CB_CHAIN (l)) {
5996  f = cb_code_field (CB_VALUE (l));
5997  if (!seen) {
5998  seen = 1;
5999  output_local ("\n/* USING parameters */\n");
6000  }
6001  output_local ("unsigned char\t*%s%d = NULL; /* %s */\n",
6002  CB_PREFIX_BASE, f->id, f->name);
6003  }
6004  if (seen) {
6005  output_local ("\n");
6006  }
6007  }
6008 #endif
6009 
6010  /* Dangling linkage section items */
6011  seen = 0;
6012  for (f = prog->linkage_storage; f; f = f->sister) {
6013  if (f->redefines) {
6014  continue;
6015  }
6016  for (l = parameter_list; l; l = CB_CHAIN (l)) {
6017  if (f == cb_code_field (CB_VALUE (l))) {
6018  break;
6019  }
6020  }
6021  if (l == NULL) {
6022  if (!seen) {
6023  seen = 1;
6024  output_local ("\n/* LINKAGE SECTION (Items not referenced by USING clause) */\n");
6025  }
6026  if (!f->flag_is_returning) {
6027  output_local ("static ");
6028  }
6029  output_local ("unsigned char\t*%s%d = NULL; /* %s */\n",
6030  CB_PREFIX_BASE, f->id, f->name);
6031  }
6032  }
6033  if (seen) {
6034  output_local ("\n");
6035  }
6036 
6037  /* Screens */
6038  if (prog->screen_storage) {
6040  output_local ("\n/* Screens */\n\n");
6042  output_local ("\n");
6043  }
6044 
6045  /* ANY LENGTH items */
6046  i = 0;
6047  anyseen = 0;
6048  for (l = parameter_list; l; l = CB_CHAIN (l), i++) {
6049  f = cb_code_field (CB_VALUE (l));
6050  if (f->flag_any_length) {
6051  anyseen = 1;
6052 #if 0 /* RXWRXW - Any */
6053  output_local ("/* ANY LENGTH variable */\n");
6054  output_local ("cob_field\t\t*cob_anylen;\n\n");
6055 #endif
6056  break;
6057  }
6058  }
6059 
6060  /* Save variables for global callback */
6061  if (prog->flag_global_use && parameter_list) {
6062  output_local ("/* Parameter save */\n");
6063  for (l = parameter_list; l; l = CB_CHAIN (l)) {
6064  f = cb_code_field (CB_VALUE (l));
6065  output_local ("static unsigned char\t*save_%s%d;\n",
6066  CB_PREFIX_BASE, f->id);
6067  }
6068  output_local ("\n");
6069  }
6070 
6071  /* Runtime DEBUGGING MODE variable */
6072  if (prog->flag_debugging) {
6073  output_line ("char\t\t*s;");
6074  output_newline ();
6075  }
6076 
6077  /* Start of function proper */
6078  output_line ("/* Start of function code */");
6079  output_newline ();
6080 
6081  /* CANCEL callback */
6082  if (prog->prog_type == CB_PROGRAM_TYPE) {
6083  output_line ("/* CANCEL callback */");
6084  output_line ("if (unlikely(entry < 0)) {");
6085  output_line ("\tgoto P_cancel;");
6086  output_line ("}");
6087  output_newline ();
6088  }
6089 
6090 #if 0 /* RXWRXW - MODULEALL */
6091  /* Recursive module initialization */
6092  if (prog->flag_recursive) {
6093  output_line ("/* Allocate cob_module structure */");
6094  output_line ("module = cob_malloc (sizeof(cob_module));");
6095  output_newline ();
6096  }
6097 #endif
6098 
6099 
6100  output_line ("/* Check initialized, check module allocated, */");
6101  output_line ("/* set global pointer, */");
6102  output_line ("/* push module stack, save call parameter count */");
6103 #if 0 /* RXWRXW - MODULEALL */
6104  output_line ("cob_module_enter (module, &cob_glob_ptr, %d);",
6105  cb_flag_implicit_init);
6106 #else
6107  output_line ("cob_module_enter (&module, &cob_glob_ptr, %d);",
6108  cb_flag_implicit_init);
6109 #endif
6110  output_newline ();
6111 
6112  /* Check INITIAL programms being non-recursive */
6114  && prog->flag_initial) {
6115  output_line ("/* Check active count */");
6116  output_line ("if (unlikely(module->module_active)) {");
6117  /* FIXME: Should raise COB_EC_PROGRAM_RECURSIVE_CALL instead */
6118  output_line ("\tcob_fatal_error (COB_FERROR_RECURSIVE);");
6119  output_line ("}");
6120  }
6121 
6122  /* Recursive module initialization */
6123  if (prog->flag_recursive) {
6124  output_module_init (prog);
6125  }
6126 
6127  output_line ("/* Set address of module parameter list */");
6128  if (cb_flag_stack_on_heap || prog->flag_recursive) {
6129  if (prog->max_call_param) {
6130  i = prog->max_call_param;
6131  } else {
6132  i = 1;
6133  }
6134  output_line ("cob_procedure_params = cob_malloc (%dU * sizeof(void *));",
6135  i);
6136  }
6137  output_line ("module->cob_procedure_params = cob_procedure_params;");
6138  output_newline ();
6139 
6140 #if 0 /* RXWRXW USERFUNC */
6141  if (prog->prog_type == CB_FUNCTION_TYPE) {
6142  parmnum = 0;
6143  for (l = parameter_list; l; l = CB_CHAIN (l), parmnum++) {
6144  f = cb_code_field (CB_VALUE (l));
6145  output_line ("if (cob_parms[%d])", parmnum);
6146  output_line (" %s%d = cob_parms[%d]->data;",
6147  CB_PREFIX_BASE, f->id, parmnum);
6148  output_line ("else");
6149  output_line (" %s%d = NULL;",
6150  CB_PREFIX_BASE, f->id);
6151  }
6152  output_newline ();
6153  }
6154 #endif
6155 
6156  output_line ("/* Set frame stack pointer */");
6157  if (cb_flag_stack_on_heap || prog->flag_recursive) {
6158  if (prog->flag_recursive && cb_stack_size == 255) {
6159  i = 63;
6160  } else {
6161  i = cb_stack_size;
6162  }
6163  output_line ("frame_stack = cob_malloc (%dU * sizeof(struct cob_frame));",
6164  i);
6165  output_line ("frame_ptr = frame_stack;");
6166  if (cb_flag_stack_check) {
6167  output_line ("frame_overflow = frame_ptr + %d - 1;",
6168  i);
6169  }
6170  } else {
6171  output_line ("frame_ptr = frame_stack;");
6172  output_line ("frame_ptr->perform_through = 0;");
6173  if (cb_flag_stack_check) {
6174  output_line ("frame_overflow = frame_ptr + %d - 1;",
6175  cb_stack_size);
6176  }
6177  }
6178  output_newline ();
6179 
6180  /* Set up LOCAL-STORAGE size */
6181  if (prog->local_storage) {
6182  for (f = prog->local_storage; f; f = f->sister) {
6183  if (f->flag_item_based || f->flag_local_alloced) {
6184  continue;
6185  }
6186  if (f->redefines) {
6187  continue;
6188  }
6189  if (f->flag_item_78) {
6190  cobc_abort_pr (_("Unexpected CONSTANT item"));
6191  COBC_ABORT ();
6192  }
6193  f->flag_local_storage = 1;
6194  f->flag_local_alloced = 1;
6195  f->mem_offset = local_mem;
6196  /* Round up to COB_MALLOC_ALIGN + 1 bytes */
6197  /* Caters for current types */
6199  ~COB_MALLOC_ALIGN);
6200  }
6201  }
6202 
6203  /* Initialization */
6204 
6205  /* Allocate and initialize LOCAL storage */
6206  if (prog->local_storage) {
6207  if (local_mem) {
6208  output_line ("/* Allocate LOCAL storage */");
6209  output_line ("cob_local_ptr = cob_malloc (%dU);",
6210  local_mem);
6211  if (prog->flag_global_use) {
6212  output_line ("cob_local_save = cob_local_ptr;");
6213  }
6214  }
6215  output_newline ();
6216  output_line ("/* Initialize LOCAL storage */");
6218  output_newline ();
6219  }
6220 
6221  output_line ("/* Initialize rest of program */");
6222  output_line ("if (unlikely(initialized == 0)) {");
6223  output_line ("\tgoto P_initialize;");
6224  if (prog->flag_chained) {
6225  output_line ("} else {");
6226  output_line ("\tcob_fatal_error (COB_FERROR_CHAINING);");
6227  }
6228  output_line ("}");
6229  output_line ("P_ret_initialize:");
6230  output_newline ();
6231 
6232  if (prog->decimal_index_max) {
6233  output_line ("/* Allocate decimal numbers */");
6234  output_prefix ();
6235  if (prog->flag_recursive) {
6236  output ("cob_decimal_push (%d", prog->decimal_index_max);
6237  } else {
6238  output ("cob_decimal_alloc (%d", prog->decimal_index_max);
6239  }
6240  for (i = 0; i < prog->decimal_index_max; i++) {
6241  output (", &d%d", i);
6242  }
6243  output (");\n");
6244  output_newline ();
6245  }
6246 
6247  /* Global entry dispatch */
6248  if (prog->global_list) {
6249  output_line ("/* Global entry dispatch */");
6250  output_newline ();
6251  for (l = prog->global_list; l; l = CB_CHAIN (l)) {
6252  output_line ("if (unlikely(entry == %d)) {",
6253  CB_LABEL (CB_VALUE (l))->id);
6254  i = 0;
6255  if (local_mem) {
6256  output_line ("\tcob_local_ptr = cob_local_save;");
6257  }
6258  for (l2 = parameter_list; l2; l2 = CB_CHAIN (l2), i++) {
6259  f = cb_code_field (CB_VALUE (l2));
6260  output_line ("\t%s%d = save_%s%d;",
6261  CB_PREFIX_BASE, f->id,
6262  CB_PREFIX_BASE, f->id);
6263  }
6264  output_line ("\tgoto %s%d;",
6266  CB_LABEL (CB_VALUE (l))->id);
6267  output_line ("}");
6268  }
6269  output_newline ();
6270  }
6271 
6272  if (cb_flag_recursive && !prog->flag_recursive) {
6273  output_line ("/* Check active count */");
6274  output_line ("if (unlikely(module->module_active)) {");
6275  output_line ("\tcob_fatal_error (COB_FERROR_RECURSIVE);");
6276  output_line ("}");
6277  }
6278  if (!prog->flag_recursive) {
6279  output_line ("/* Increment module active */");
6280  output_line ("module->module_active++;");
6281  output_newline ();
6282  }
6283 
6284  if (!cobc_flag_main && non_nested_count > 1) {
6285  output_line ("/* Increment module reference count */");
6286  output_line ("cob_reference_count++;");
6287  output_newline ();
6288  }
6289 
6290  /* Initialize W/S and files unconditionally when INITIAL program */
6291  if (prog->flag_initial) {
6292  output_line ("/* Initialize INITIAL program WORKING-STORAGE */");
6294  output_newline ();
6295  for (l = prog->file_list; l; l = CB_CHAIN (l)) {
6297  }
6298  output_newline ();
6299  }
6300 
6301  /* Call parameters */
6302  if (cb_code_field (prog->cb_call_params)->count) {
6303  output_line ("/* Set NUMBER-OF-CALL-PARAMETERS */");
6304  output_prefix ();
6306  output (" = cob_glob_ptr->cob_call_params;\n");
6307  output_newline ();
6308  }
6309 
6310 #if 1 /* RXWRXW - Save call params */
6311  output_line ("/* Save number of call params */");
6312  output_line ("module->module_num_params = cob_glob_ptr->cob_call_params;");
6313  output_newline ();
6314 #endif
6315 
6316  /* Set up ANY length items */
6317  i = 0;
6318  if (anyseen) {
6319  output_line ("/* Initialize ANY LENGTH parameters */");
6320  }
6321  for (l = parameter_list; l; l = CB_CHAIN (l), i++) {
6322  f = cb_code_field (CB_VALUE (l));
6323  if (f->flag_any_length) {
6324  /* Force field cache */
6325  savetarget = output_target;
6326  output_target = NULL;
6327  output_param (CB_VALUE (l), i);
6328  output_target = savetarget;
6329 
6330  output_line ("if (cob_glob_ptr->cob_call_params > %d && %s%d%s)",
6331  i, "module->next->cob_procedure_params[",
6332  i, "]");
6333  if (f->flag_any_numeric) {
6334  /* Copy complete structure */
6335  output_line (" %s%d = *(%s%d%s);",
6336  CB_PREFIX_FIELD, f->id,
6337  "module->next->cob_procedure_params[",
6338  i, "]");
6339  } else {
6340  /* Copy size */
6341  output_line (" %s%d.size = %s%d%s;",
6342  CB_PREFIX_FIELD, f->id,
6343  "module->next->cob_procedure_params[",
6344  i, "]->size");
6345  }
6346  output_prefix ();
6347  output ("%s%d.data = ", CB_PREFIX_FIELD, f->id);
6348  output_data (CB_VALUE (l));
6349  output (";\n");
6350 #if 0 /* RXWRXW - Num check */
6352  f->flag_any_numeric &&
6353  (f->usage == CB_USAGE_DISPLAY ||
6354  f->usage == CB_USAGE_PACKED ||
6355  f->usage == CB_USAGE_COMP_6)) {
6356  output_line ("cob_check_numeric (&%s%d, %s%d);",
6358  f->id,
6360  lookup_string (f->name));
6361  }
6362 #endif
6363  }
6364  }
6365  if (anyseen) {
6366  output_newline ();
6367  }
6368 
6369  if (prog->prog_type == CB_FUNCTION_TYPE) {
6370  output_prefix ();
6371  output_data (prog->returning);
6372  output (" = cob_malloc (");
6373  output_size (prog->returning);
6374  output ("U);\n\n");
6375  }
6376 
6377  if (prog->flag_global_use && parameter_list) {
6378  output_line ("/* Parameter save */");
6379  for (l = parameter_list; l; l = CB_CHAIN (l)) {
6380  f = cb_code_field (CB_VALUE (l));
6381  output_line ("save_%s%d = %s%d;",
6382  CB_PREFIX_BASE, f->id,
6383  CB_PREFIX_BASE, f->id);
6384  }
6385  output_newline ();
6386  }
6387 
6388  /* Classification */
6389  if (prog->classification) {
6390  if (prog->classification == cb_int1) {
6391  output_line ("cob_set_locale (NULL, COB_LC_CLASS);");
6392  } else {
6393  output_prefix ();
6394  output ("cob_set_locale (");
6395  output_param (prog->classification, -1);
6396  output (", COB_LC_CTYPE);");
6397  }
6398  output_newline ();
6399  }
6400 
6401  /* Entry dispatch */
6402  output_line ("/* Entry dispatch */");
6403  if (cb_list_length (prog->entry_list) > 1) {
6404  output_newline ();
6405  output_line ("switch (entry)");
6406  output_line (" {");
6407  for (i = 0, l = prog->entry_list; l; l = CB_CHAIN (l)) {
6408  output_line (" case %d:", i++);
6409  output_line (" goto %s%d;", CB_PREFIX_LABEL,
6410  CB_LABEL (CB_PURPOSE (l))->id);
6411  }
6412  output_line (" }");
6413  output_line ("/* This should never be reached */");
6414  output_line ("cob_fatal_error (COB_FERROR_MODULE);");
6415  output_newline ();
6416  } else {
6417  l = prog->entry_list;
6418  output_line ("goto %s%d;", CB_PREFIX_LABEL,
6419  CB_LABEL (CB_PURPOSE (l))->id);
6420  output_newline ();
6421  }
6422 
6423  /* PROCEDURE DIVISION */
6424  output_line ("/* PROCEDURE DIVISION */");
6425  for (l = prog->exec_list; l; l = CB_CHAIN (l)) {
6426  output_stmt (CB_VALUE (l));
6427  }
6428  output_newline ();
6429 
6430  /* End of program */
6431  output_line ("/* Program exit */");
6432  output_newline ();
6433 
6434  if (needs_exit_prog) {
6435  output_line ("exit_program:");
6436  output_newline ();
6437  }
6438 
6439  if (!prog->flag_recursive) {
6440  output_line ("/* Decrement module active count */");
6441  output_line ("if (module->module_active) {");
6442  output_line ("\tmodule->module_active--;");
6443  output_line ("}");
6444  output_newline ();
6445  }
6446 
6447  if (!cobc_flag_main && non_nested_count > 1) {
6448  output_line ("/* Decrement module reference count */");
6449  output_line ("if (cob_reference_count) {");
6450  output_line ("\tcob_reference_count--;");
6451  output_line ("}");
6452  output_newline ();
6453  }
6454 
6455  if (gen_dynamic) {
6456  output_line ("/* Deallocate dynamic FUNCTION-ID fields */");
6457  for (inc = 0; inc < gen_dynamic; inc++) {
6458  output_line ("if (cob_dyn_%u) {", inc);
6459  output_line (" if (cob_dyn_%u->data) {", inc);
6460  output_line (" cob_free (cob_dyn_%u->data);", inc);
6461  output_line (" }");
6462  output_line (" cob_free (cob_dyn_%u);", inc);
6463  output_line (" cob_dyn_%u = NULL;", inc);
6464  output_line ("}");
6465  }
6466  output_newline ();
6467  }
6468 
6469  if (prog->local_storage) {
6470  output_line ("/* Deallocate LOCAL storage */");
6471  if (local_mem) {
6472  output_line ("if (cob_local_ptr) {");
6473  output_line ("\tfree (cob_local_ptr);");
6474  output_line ("\tcob_local_ptr = NULL;");
6476  output_line ("\tcob_local_save = NULL;");
6477  }
6478  output_line ("}");
6479  }
6480  for (f = prog->local_storage; f; f = f->sister) {
6481  if (f->flag_item_based) {
6482  output_line ("if (%s%d) {", CB_PREFIX_BASE, f->id);
6483  output_line ("\tcob_free_alloc (&%s%d, NULL);",
6484  CB_PREFIX_BASE, f->id);
6485  output_line ("\t%s%d = NULL;",
6486  CB_PREFIX_BASE, f->id);
6487  output_line ("}");
6488  }
6489  }
6490  output_newline ();
6491  }
6492 
6493  if (prog->decimal_index_max && prog->flag_recursive) {
6494  output_line ("/* Free decimal structures */");
6495  output_prefix ();
6496  output ("cob_decimal_pop (%d", prog->decimal_index_max);
6497  for (i = 0; i < prog->decimal_index_max; i++) {
6498  output (", d%d", i);
6499  }
6500  output (");\n");
6501  output_newline ();
6502  }
6503 
6504  if (cb_flag_stack_on_heap || prog->flag_recursive) {
6505  output_line ("/* Free frame stack / call parameters */");
6506  output_line ("cob_free (frame_stack);");
6507  output_line ("cob_free (cob_procedure_params);");
6508  output_newline ();
6509  }
6510 
6511  if (cb_flag_trace) {
6512  output_line ("/* Trace program exit */");
6513  sprintf (string_buffer, "Exit: %s", excp_current_program_id);
6514  output_line ("cob_trace_section (%s%d, NULL, 0);",
6517  output_newline ();
6518  }
6519 
6520  output_line ("/* Pop module stack */");
6521  output_line ("cob_module_leave (module);");
6522  output_newline ();
6523 
6524  if (prog->flag_recursive) {
6525  output_line ("/* Free cob_module structure */");
6526  output_line ("cob_cache_free (module);");
6527  output_newline ();
6528  }
6529 
6530  /* Implicit CANCEL for INITIAL program */
6531  if (prog->flag_initial) {
6532  output_line ("/* CANCEL for INITIAL program */");
6533  output_prefix ();
6534  if (!prog->nested_level) {
6535  output ("%s_ (-1", prog->program_id);
6536  } else {
6537  output ("%s_%d_ (-1", prog->program_id,
6538  prog->toplev_count);
6539  }
6540  if (!prog->flag_chained) {
6541  for (l = parameter_list; l; l = CB_CHAIN (l)) {
6542  output (", NULL");
6543  }
6544  }
6545  output (");\n");
6546  output_newline ();
6547  }
6548 
6549  output_line ("/* Program return */");
6550 #if 1 /* RXWRXW - PROCRET */
6551  if (prog->returning) {
6552  output_move (prog->returning, prog->cb_return_code);
6553  }
6554 #endif
6555  output_prefix ();
6556  output ("return ");
6557  if (prog->prog_type == CB_FUNCTION_TYPE) {
6558  output_param (prog->returning, -1);
6559  } else {
6561  }
6562  output (";\n");
6563 
6564  /* Error handlers */
6565  if (prog->file_list || prog->flag_gen_error) {
6566  output_error_handler (prog);
6567  }
6568 
6569  /* Frame stack jump table for compiler without computed goto */
6570  if (!cb_flag_computed_goto) {
6571  output_newline ();
6572  output_line ("/* Frame stack jump table */");
6573  output_line ("P_switch:");
6574  if (label_cache) {
6575  output_line (" switch (frame_ptr->return_address_num) {");
6576  for (pl = label_cache; pl; pl = pl->next) {
6577  output_line (" case %d:", pl->call_num);
6578  output_line (" goto %s%d;", CB_PREFIX_LABEL,
6579  pl->id);
6580  }
6581  output_line (" }");
6582  }
6583  output_line (" cob_fatal_error (COB_FERROR_CODEGEN);");
6584  output_newline ();
6585  }
6586 
6587  /* Program initialization */
6588 
6589 #if 0 /* RXWRXW WS */
6590  if (prog->working_storage) {
6591  for (f = prog->working_storage; f; f = f->sister) {
6592  if (f->flag_item_based || f->flag_local_alloced) {
6593  continue;
6594  }
6595  if (f->redefines || f->flag_external) {
6596  continue;
6597  }
6598 #if 0 /* RXWRXW - Check global */
6599  if (f->flag_is_global) {
6600  continue;
6601  }
6602 #endif
6603  if (f->flag_no_init && !f->count) {
6604  continue;
6605  }
6606  if (f->flag_item_78) {
6607  cobc_abort_pr (_("Unexpected CONSTANT item"));
6608  COBC_ABORT ();
6609  }
6610  if (f->flag_is_global) {
6611  f->mem_offset = working_mem;
6613  ~COB_MALLOC_ALIGN);
6614  } else {
6617  ~COB_MALLOC_ALIGN);
6618  }
6619  }
6620  }
6621 #endif
6622 
6623  output_newline ();
6624  output_line ("/* Program initialization */");
6625  output_line ("P_initialize:");
6626  output_newline ();
6627 
6628  /* Check matching version */
6629  if (!prog->nested_level) {
6630  output_line ("cob_check_version (COB_SOURCE_FILE, COB_PACKAGE_VERSION, COB_PATCH_LEVEL);");
6631  output_newline ();
6632  }
6633 
6634  /* Resolve user functions */
6635  for (clp = func_call_cache; clp; clp = clp->next) {
6636  output_line ("func_%s.funcvoid = cob_resolve_func (\"%s\");",
6637  clp->callname, clp->callname);
6638  }
6639 
6640  if (cobc_flag_main && !prog->nested_level) {
6641  output_line ("cob_module_path = cob_glob_ptr->cob_main_argv0;");
6642  output_newline ();
6643  }
6644 
6645  /* Module initialization */
6646  if (!prog->flag_recursive) {
6647  output_module_init (prog);
6648  }
6649 
6650 
6651  /* Check runtime DEBUGGING MODE variable */
6652  if (prog->flag_debugging) {
6653  output_line ("if ((s = getenv (\"COB_SET_DEBUG\")) && (*s == 'Y' || *s == 'y' || *s == '1'))");
6654  output_line ("\tcob_debugging_mode = 1;");
6655  output_newline ();
6656  }
6657 
6658  /* Setup up CANCEL callback */
6659  if (!prog->nested_level && prog->prog_type == CB_PROGRAM_TYPE) {
6660  output_line ("/* Initialize cancel callback */");
6661 #if 0 /* RXWRXW CA */
6662  if (!cb_flag_implicit_init) {
6663  output_line ("if (module->next)");
6664  }
6665 #endif
6666  output_line ("cob_set_cancel (module);");
6667  output_newline ();
6668  }
6669 
6670  /* Initialize EXTERNAL files */
6671  for (l = prog->file_list; l; l = CB_CHAIN (l)) {
6672  f = CB_FILE (CB_VALUE (l))->record;
6673  if (f->flag_external) {
6674  strcpy (string_buffer, f->name);
6675  for (p = string_buffer; *p; p++) {
6676  if (*p == '-' || *p == ' ') {
6677  *p = '_';
6678  }
6679  }
6680  output_line ("%s%d = cob_external_addr (\"%s\", %d);",
6682  CB_FILE (CB_VALUE (l))->record_max);
6683  }
6684  }
6685 
6686  /* Initialize WORKING-STORAGE EXTERNAL items */
6687  for (f = prog->working_storage; f; f = f->sister) {
6688  if (f->redefines) {
6689  continue;
6690  }
6691  if (!f->flag_external) {
6692  continue;
6693  }
6694  output_prefix ();
6695  output_base (f, 0);
6696  output (" = cob_external_addr (\"%s\", %d);\n",
6697  f->ename, f->size);
6698  }
6699 
6700  /* Initialize WORKING-STORAGE/files if not INITIAL program */
6701  if (!prog->flag_initial) {
6702  if (prog->working_storage) {
6703  output_line ("/* Initialize WORKING-STORAGE */");
6705  output_newline ();
6706  }
6707  if (prog->file_list) {
6708  output_newline ();
6709  for (l = prog->file_list; l; l = CB_CHAIN (l)) {
6711  }
6712  output_newline ();
6713  }
6714  }
6715 
6716  if (prog->screen_storage) {
6717  output_line ("/* Initialize SCREEN items */");
6718  /* Initialize items with VALUE */
6721  output_newline ();
6722  }
6723 
6724  output_line ("initialized = 1;");
6725  output_line ("goto P_ret_initialize;");
6726 
6727  /* Set up CANCEL callback code */
6728 
6729  if (prog->prog_type != CB_PROGRAM_TYPE) {
6730  goto prog_cancel_end;
6731  }
6732 
6733  output_newline ();
6734  output_line ("/* CANCEL callback handling */");
6735  output_line ("P_cancel:");
6736  output_newline ();
6737  output_line ("if (!initialized) {");
6738  output_line ("\treturn 0;");
6739  output_line ("}");
6740  output_line ("if (module->module_active) {");
6741  output_line ("\tcob_fatal_error (COB_FERROR_CANCEL);");
6742  output_line ("}");
6743  output_newline ();
6744 
6745  if (prog->flag_main) {
6746  goto cancel_end;
6747  }
6748 
6749  next_prog = prog->next_program;
6750 
6751  /* Check for implicit cancel of contained programs */
6752  for (; next_prog; next_prog = next_prog->next_program) {
6753  if (next_prog->nested_level == prog->nested_level + 1) {
6754  output_prefix ();
6755  output ("(void)%s_%d_ (-1", next_prog->program_id,
6756  next_prog->toplev_count);
6757  for (i = 0; i < next_prog->num_proc_params; ++i) {
6758  output (", NULL");
6759  }
6760  output (");\n");
6761  }
6762  }
6763 
6764  /* Close files on cancel */
6765  for (l = prog->file_list; l; l = CB_CHAIN (l)) {
6766  fl = CB_FILE (CB_VALUE (l));
6767  if (fl->organization != COB_ORG_SORT) {
6768  output_line ("cob_close (%s%s, NULL, COB_CLOSE_NORMAL, 1);",
6769  CB_PREFIX_FILE, fl->cname);
6770  if (!fl->flag_external) {
6771  if (fl->linage) {
6772  output_line ("cob_cache_free (%s%s->linorkeyptr);",
6773  CB_PREFIX_FILE, fl->cname);
6774  }
6775  if (fl->organization == COB_ORG_RELATIVE ||
6776  fl->organization == COB_ORG_INDEXED) {
6777  output_line ("cob_cache_free (%s%s);",
6778  CB_PREFIX_KEYS, fl->cname);
6779  output_line ("%s%s = NULL;",
6780  CB_PREFIX_KEYS, fl->cname);
6781  }
6782  output_line ("cob_cache_free (%s%s);",
6783  CB_PREFIX_FILE, fl->cname);
6784  output_line ("%s%s = NULL;",
6785  CB_PREFIX_FILE, fl->cname);
6786  }
6787  } else {
6788  output_line ("cob_cache_free (%s%s);",
6789  CB_PREFIX_FILE, fl->cname);
6790  output_line ("%s%s = NULL;",
6791  CB_PREFIX_FILE, fl->cname);
6792  }
6793  }
6794 
6795  /* Clear alter indicators */
6796  for (cpl = prog->alter_gotos; cpl; cpl = cpl->next) {
6797  output_line ("label_%s%d = 0;",
6798  CB_PREFIX_LABEL, cpl->goto_id);
6799  if (prog->flag_segments) {
6800  output_line ("save_label_%s%d = 0;",
6801  CB_PREFIX_LABEL, cpl->goto_id);
6802  }
6803  }
6804 
6805  /* Release based storage */
6806  for (f = prog->working_storage; f; f = f->sister) {
6807  if (f->flag_item_based) {
6808  output_line ("if (%s%d) {", CB_PREFIX_BASE, f->id);
6809  output_line ("\tcob_free_alloc (&%s%d, NULL);",
6810  CB_PREFIX_BASE, f->id);
6811  output_line ("}");
6812  }
6813  }
6814 
6815  /* Reset DEBUGGING mode */
6816  if (prog->flag_debugging) {
6817  output_line ("cob_debugging_mode = 0;");
6818  }
6819 
6820  /* Clear CALL pointers */
6821  for (clp = call_cache; clp; clp = clp->next) {
6822  output_line ("call_%s.funcvoid = NULL;", clp->callname);
6823  }
6824  for (clp = func_call_cache; clp; clp = clp->next) {
6825  output_line ("func_%s.funcvoid = NULL;", clp->callname);
6826  }
6827 
6828  /* Clear sticky-linkage pointers */
6829  if (cb_sticky_linkage) {
6830  for (l = prog->parameter_list; l; l = CB_CHAIN (l)) {
6831  output_line ("cob_parm_%d = NULL;",
6832  cb_code_field (CB_VALUE (l))->id);
6833  }
6834  }
6835 
6836  /* Clear RETURN-CODE */
6837  if (!prog->nested_level) {
6838  output_prefix ();
6840  output (" = 0;\n");
6841  }
6842 
6843  output_line ("cob_cache_free (module);");
6844  output_line ("module = NULL;");
6845  output_newline ();
6846 
6847 cancel_end:
6848  output_line ("initialized = 0;");
6849  output_line ("return 0;");
6850  output_newline ();
6851  /* End of CANCEL callback code */
6852 
6853 prog_cancel_end:
6854  output_indent ("}");
6855  output_newline ();
6856  if (prog->prog_type == CB_FUNCTION_TYPE) {
6857  s = "FUNCTION-ID";
6858  } else {
6859  s = "PROGRAM-ID";
6860  }
6861  output_line ("/* End %s '%s' */", s, prog->orig_program_id);
6862  output_newline ();
6863 }
const char * name
Definition: tree.h:645
cb_tree returning
Definition: tree.h:1288
#define CB_LABEL(x)
Definition: tree.h:801
cb_tree cb_int1
Definition: tree.c:134
struct cb_field * local_storage
Definition: tree.h:1277
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
static void output_newline(void)
Definition: codegen.c:433
#define cob_u32_t
Definition: common.h:31
#define CB_PREFIX_STRING
Definition: tree.h:39
struct cb_field * f
Definition: codegen.c:114
static void output_error_handler(struct cb_program *prog)
Definition: codegen.c:5635
static int lookup_string(const char *p)
Definition: codegen.c:219
static FILE * output_target
Definition: codegen.c:135
static void output_file_initialization(struct cb_file *f)
Definition: codegen.c:5160
int toplev_count
Definition: tree.h:1297
unsigned int flag_any_length
Definition: tree.h:712
void * cobc_parse_malloc(const size_t size)
Definition: cobc.c:809
unsigned int flag_initial
Definition: tree.h:1307
static int local_working_mem
Definition: codegen.c:170
struct cb_field * sister
Definition: tree.h:653
unsigned int flag_local_alloced
Definition: tree.h:726
unsigned int flag_global_use
Definition: tree.h:1312
static void output(const char *,...)
Definition: codegen.c:192
#define CB_PREFIX_LABEL
Definition: tree.h:37
const char * callname
Definition: codegen.c:109
static void output_line(const char *fmt,...)
Definition: codegen.c:453
#define CB_PREFIX_FILE
Definition: tree.h:35
unsigned int flag_is_returning
Definition: tree.h:737
static void output_local(const char *fmt,...)
Definition: codegen.c:527
int nested_level
Definition: tree.h:1295
struct label_list * next
Definition: codegen.c:71
static void output_module_init(struct cb_program *prog)
Definition: codegen.c:5705
int max_call_param
Definition: tree.h:1298
static int working_mem
Definition: codegen.c:169
unsigned int flag_main
Definition: tree.h:1305
#define COB_ORG_INDEXED
Definition: common.h:745
#define CB_PURPOSE(x)
Definition: tree.h:1192
struct local_filename * local_include
Definition: tree.h:1248
static unsigned int gen_dynamic
Definition: codegen.c:156
cb_tree linage
Definition: tree.h:832
cb_tree file_list
Definition: tree.h:1252
unsigned char flag_is_global
Definition: tree.h:699
#define CB_PREFIX_BASE
Definition: tree.h:31
#define CB_FILE(x)
Definition: tree.h:858
unsigned char flag_local_storage
Definition: tree.h:698
unsigned int flag_debugging
Definition: tree.h:1320
static void output_data(cb_tree x)
Definition: codegen.c:705
static struct label_list * label_cache
Definition: codegen.c:132
struct call_list * next
Definition: codegen.c:108
static void output_prefix(void)
Definition: codegen.c:441
#define CB_VALUE(x)
Definition: tree.h:1193
struct cb_alter_id * alter_gotos
Definition: tree.h:1275
static void output_screen_definition(struct cb_field *p)
Definition: codegen.c:5354
unsigned int flag_item_78
Definition: tree.h:711
static struct cb_program * current_prog
Definition: codegen.c:140
int id
Definition: tree.h:671
int cb_list_length(cb_tree l)
Definition: tree.c:1342
static void output_size(const cb_tree x)
Definition: codegen.c:793
int decimal_index_max
Definition: tree.h:1294
#define CB_ALPHABET_NAME(x)
Definition: tree.h:550
#define _(s)
Definition: cobcrun.c:59
Definition: tree.h:643
cb_tree cb_call_params
Definition: tree.h:1267
unsigned int flag_no_init
Definition: tree.h:727
#define CB_CHAIN(x)
Definition: tree.h:1194
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
unsigned int flag_external
Definition: tree.h:850
static int non_nested_count
Definition: codegen.c:162
#define COBC_ABORT()
Definition: cobc.h:61
cb_tree cb_return_code
Definition: tree.h:1265
#define CB_PREFIX_KEYS
Definition: tree.h:36
struct cb_program * next_program
Definition: tree.h:1242
static void output_initial_values(struct cb_field *f)
Definition: codegen.c:5616
unsigned char prog_type
Definition: tree.h:1303
int count
Definition: tree.h:680
cb_tree alphabet_name_list
Definition: tree.h:1256
struct base_list * next
Definition: codegen.c:113
#define COB_ORG_RELATIVE
Definition: common.h:744
static const char * excp_current_program_id
Definition: codegen.c:137
#define CB_PROGRAM_TYPE
Definition: tree.h:41
cb_tree global_list
Definition: tree.h:1261
struct cb_alter_id * next
Definition: tree.h:760
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
int size
Definition: tree.h:672
Definition: tree.h:818
cb_tree entry_list
Definition: tree.h:1251
unsigned int flag_any_numeric
Definition: tree.h:736
static struct call_list * call_cache
Definition: codegen.c:125
static unsigned int needs_exit_prog
Definition: codegen.c:146
const char * program_id
Definition: tree.h:1244
unsigned int flag_segments
Definition: tree.h:1317
int id
Definition: codegen.c:72
unsigned int flag_recursive
Definition: tree.h:1308
int call_num
Definition: codegen.c:73
unsigned int flag_chained
Definition: tree.h:1311
#define CB_FUNCTION_TYPE
Definition: tree.h:42
const char * curr_prog
Definition: codegen.c:115
cb_tree parameter_list
Definition: tree.h:1259
char * cname
Definition: tree.h:821
const char * ename
Definition: tree.h:646
cb_tree classification
Definition: tree.h:1285
#define CB_EXCEPTION_ENABLE(id)
Definition: cobc.h:243
static void output_alphabet_name_definition(struct cb_alphabet_name *p)
Definition: codegen.c:5511
int mem_offset
Definition: tree.h:681
int organization
Definition: tree.h:844
static void output_integer(cb_tree x)
Definition: codegen.c:1101
#define COB_MALLOC_ALIGN
Definition: codegen.c:46
#define COB_ORG_SORT
Definition: common.h:746
struct cb_field * linkage_storage
Definition: tree.h:1278
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
cb_tree exec_list
Definition: tree.h:1253
struct cb_field * working_storage
Definition: tree.h:1276
int memory_size
Definition: tree.h:674
int goto_id
Definition: tree.h:761
static void output_screen_init(struct cb_field *p, struct cb_field *previous)
Definition: codegen.c:5376
cob_u32_t optimize_defs[COB_OPTIM_MAX]
Definition: cobc.c:182
static struct base_list * globext_cache
Definition: codegen.c:128
static void output_base(struct cb_field *f, const cob_u32_t no_output)
Definition: codegen.c:606
struct cb_field * redefines
Definition: tree.h:654
static int local_mem
Definition: codegen.c:168
#define CB_PREFIX_FIELD
Definition: tree.h:34
static int output_file_allocation(struct cb_file *f)
Definition: codegen.c:5099
int cobc_flag_main
Definition: cobc.c:167
static char * string_buffer
Definition: codegen.c:131
static void output_move(cb_tree src, cb_tree dst)
Definition: codegen.c:2235
enum cb_usage usage
Definition: tree.h:693
unsigned int flag_gen_error
Definition: tree.h:1314
char * local_name
Definition: cobc.h:190
struct cb_field * screen_storage
Definition: tree.h:1279
char * orig_program_id
Definition: tree.h:1246
static struct call_list * func_call_cache
Definition: codegen.c:126
static void output_indent(const char *str)
Definition: codegen.c:467
int num_proc_params
Definition: tree.h:1296
unsigned char flag_external
Definition: tree.h:697
unsigned int flag_item_based
Definition: tree.h:713

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_label_info ( cb_tree  x,
struct cb_label lp 
)
static

Definition at line 4592 of file codegen.c.

References excp_current_paragraph, excp_current_section, cb_label::flag_dummy_exit, cb_label::flag_dummy_paragraph, cb_label::flag_dummy_section, cb_label::flag_entry, cb_label::flag_next_sentence, cb_label::flag_section, cb_label::name, NULL, cb_label::orig_name, output(), output_line(), output_newline(), output_prefix(), cb_tree_common::source_file, and cb_tree_common::source_line.

Referenced by output_stmt().

4593 {
4594  if (lp->flag_dummy_section || lp->flag_dummy_paragraph) {
4595  return;
4596  }
4597 
4598  output_newline ();
4599 
4600  if (lp->flag_dummy_exit) {
4601  output_line ("/* Implicit EXIT label */");
4602  return;
4603  } else if (lp->flag_next_sentence) {
4604  output_line ("/* Implicit NEXT SENTENCE label */");
4605  return;
4606  }
4607 
4608  output_prefix ();
4609  if (x->source_file) {
4610  output ("/* Line: %-10d: ", x->source_line);
4611  } else {
4612  output ("/* ");
4613  }
4614  if (lp->flag_section) {
4615  output ("Section %-24s", (const char *)lp->name);
4616  excp_current_section = (const char *)lp->name;
4618  } else {
4619  if (lp->flag_entry) {
4620  output ("Entry %-24s", lp->orig_name);
4623  } else {
4624  output ("Paragraph %-24s", (const char *)lp->name);
4625  excp_current_paragraph = (const char *)lp->name;
4626  }
4627  }
4628  if (x->source_file) {
4629  output (": %s */\n", x->source_file);
4630  } else {
4631  output ("*/\n");
4632  }
4633 }
const char * orig_name
Definition: tree.h:767
const char * name
Definition: tree.h:766
static void output_newline(void)
Definition: codegen.c:433
static void output(const char *,...)
Definition: codegen.c:192
static void output_line(const char *fmt,...)
Definition: codegen.c:453
static const char * excp_current_paragraph
Definition: codegen.c:139
const char * source_file
Definition: tree.h:431
unsigned int flag_next_sentence
Definition: tree.h:790
unsigned int flag_dummy_paragraph
Definition: tree.h:788
static void output_prefix(void)
Definition: codegen.c:441
unsigned int flag_section
Definition: tree.h:777
int source_line
Definition: tree.h:432
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static const char * excp_current_section
Definition: codegen.c:138
unsigned int flag_entry
Definition: tree.h:778
unsigned int flag_dummy_exit
Definition: tree.h:789
unsigned int flag_dummy_section
Definition: tree.h:787

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_line ( const char *  fmt,
  ... 
)
static
static void output_local ( const char *  fmt,
  ... 
)
static

Definition at line 527 of file codegen.c.

References cb_local_file.

Referenced by codegen(), output_alphabet_name_definition(), output_alter_check(), output_base(), output_file_allocation(), output_internal_function(), and output_screen_definition().

528 {
529  va_list ap;
530 
531  if (cb_local_file) {
532  va_start (ap, fmt);
533  vfprintf (cb_local_file, fmt, ap);
534  va_end (ap);
535  }
536 }
static FILE * cb_local_file
Definition: codegen.c:136

Here is the caller graph for this function:

static void output_long_integer ( cb_tree  x)
static

Definition at line 1366 of file codegen.c.

References _, cb_cast::cast_type, CB_BINARY_OP, CB_CAST, CB_CAST_ADDRESS, CB_CAST_PROGRAM_POINTER, CB_CONST, cb_fits_long_long(), CB_FMT_LLD_F, cb_get_long_long(), CB_INTEGER, cb_null, CB_PREFIX_BASE, CB_STORAGE_LINKAGE, CB_TAG_BINARY_OP, CB_TAG_CAST, CB_TAG_CONST, CB_TAG_INTEGER, CB_TAG_INTRINSIC, CB_TAG_LITERAL, CB_TAG_REFERENCE, CB_TREE_TAG, CB_USAGE_BINARY, CB_USAGE_COMP_5, CB_USAGE_COMP_X, CB_USAGE_INDEX, CB_USAGE_LENGTH, CB_USAGE_POINTER, CB_USAGE_PROGRAM_POINTER, cb_zero, COBC_ABORT, cobc_abort_pr(), cb_binary_op::flag, cb_field::flag_binary_swap, gen_nested_tab, cb_picture::have_sign, hexval, cb_field::id, cb_field::indexes, cb_program::nested_prog_list, cb_field::offset, cb_binary_op::op, output(), output_base(), output_data(), output_func_1(), output_param(), cb_field::pic, cb_field::size, cb_field::special_index, cb_field::storage, cb_field::usage, cb_cast::val, cb_binary_op::x, and cb_binary_op::y.

Referenced by output_param().

1367 {
1368  struct cb_binary_op *p;
1369  struct cb_cast *cp;
1370  struct cb_field *f;
1371 
1372  switch (CB_TREE_TAG (x)) {
1373  case CB_TAG_CONST:
1374  if (x == cb_zero) {
1375  output ("0");
1376  } else if (x == cb_null) {
1377  output ("(cob_u8_ptr)NULL");
1378  } else {
1379  output ("%s", CB_CONST (x)->val);
1380  }
1381  break;
1382  case CB_TAG_INTEGER:
1383  if (CB_INTEGER (x)->hexval) {
1384  output ("0x%X", CB_INTEGER (x)->val);
1385  } else {
1386  output ("%d", CB_INTEGER (x)->val);
1387  }
1388  break;
1389  case CB_TAG_LITERAL:
1391  break;
1392  case CB_TAG_BINARY_OP:
1393  p = CB_BINARY_OP (x);
1394  if (p->flag) {
1395  if (!cb_fits_long_long (p->x) ||
1396  !cb_fits_long_long (p->y)) {
1397  output ("cob_get_llint (");
1398  output_param (x, -1);
1399  output (")");
1400  break;
1401  }
1402  }
1403  if (p->op == '^') {
1404  output ("(cob_s64_t) pow (");
1405  output_long_integer (p->x);
1406  output (", ");
1407  output_long_integer (p->y);
1408  output (")");
1409  } else {
1410  output ("(");
1411  output_long_integer (p->x);
1412  output (" %c ", p->op);
1413  output_long_integer (p->y);
1414  output (")");
1415  }
1416  break;
1417  case CB_TAG_CAST:
1418  cp = CB_CAST (x);
1419  switch (cp->cast_type) {
1420  case CB_CAST_ADDRESS:
1421  output ("(");
1422  output_data (cp->val);
1423  output (")");
1424  break;
1426  output ("cob_call_field (");
1427  output_param (x, -1);
1429  gen_nested_tab = 1;
1430  output (", cob_nest_tab, 0, %d)", cb_fold_call);
1431  } else {
1432  output (", NULL, 0, %d)", cb_fold_call);
1433  }
1434  break;
1435  default:
1436  cobc_abort_pr (_("Unexpected cast type %d"),
1437  (int)cp->cast_type);
1438  COBC_ABORT ();
1439  }
1440  break;
1441  case CB_TAG_REFERENCE:
1442  f = cb_code_field (x);
1443  switch (f->usage) {
1444  case CB_USAGE_INDEX:
1445  if (f->special_index) {
1446  output_base (f, 1U);
1447  output ("(cob_s64_t)%s%d", CB_PREFIX_BASE, f->id);
1448  return;
1449  }
1450  /* Fall through */
1451  case CB_USAGE_LENGTH:
1452  output ("(cob_s64_t)(*(int *) (");
1453  output_data (x);
1454  output ("))");
1455  return;
1456 
1457  case CB_USAGE_POINTER:
1458 #ifdef COB_NON_ALIGNED
1459  output ("(cob_get_pointer (");
1460  output_data (x);
1461  output ("))");
1462 #else
1463  output ("(*(unsigned char **) (");
1464  output_data (x);
1465  output ("))");
1466 #endif
1467  return;
1468 
1470 #ifdef COB_NON_ALIGNED
1471  output ("(cob_get_prog_pointer (");
1472  output_data (x);
1473  output ("))");
1474 #else
1475  output ("(*(void **) (");
1476  output_data (x);
1477  output ("))");
1478 #endif
1479  return;
1480 
1481  case CB_USAGE_BINARY:
1482  case CB_USAGE_COMP_5:
1483  case CB_USAGE_COMP_X:
1484  if (f->size == 1) {
1485  output ("(*(");
1486  if (!f->pic->have_sign) {
1487  output ("cob_u8_ptr) (");
1488  } else {
1489  output ("cob_s8_ptr) (");
1490  }
1491  output_data (x);
1492  output ("))");
1493  return;
1494  }
1495 #ifdef COB_NON_ALIGNED
1496  if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && (
1497 #ifdef COB_SHORT_BORK
1498  (f->size == 2 && (f->offset % 4 == 0)) ||
1499 #else
1500  (f->size == 2 && (f->offset % 2 == 0)) ||
1501 #endif
1502  (f->size == 4 && (f->offset % 4 == 0)) ||
1503  (f->size == 8 && (f->offset % 8 == 0)))) {
1504 #else
1505  if (f->size == 2 || f->size == 4 || f->size == 8) {
1506 #endif
1507  if (f->flag_binary_swap) {
1508  output ("((");
1509  switch (f->size) {
1510  case 2:
1511  if (!f->pic->have_sign) {
1512  output ("unsigned short)COB_BSWAP_16(");
1513  } else {
1514  output ("short)COB_BSWAP_16(");
1515  }
1516  break;
1517  case 4:
1518  if (!f->pic->have_sign) {
1519  output ("unsigned int)COB_BSWAP_32(");
1520  } else {
1521  output ("int)COB_BSWAP_32(");
1522  }
1523  break;
1524  case 8:
1525  if (!f->pic->have_sign) {
1526  output ("cob_u64_t)COB_BSWAP_64(");
1527  } else {
1528  output ("cob_s64_t)COB_BSWAP_64(");
1529  }
1530  break;
1531  default:
1532  break;
1533  }
1534  output ("*(");
1535  switch (f->size) {
1536  case 2:
1537  output ("short *)(");
1538  break;
1539  case 4:
1540  output ("int *)(");
1541  break;
1542  case 8:
1543  output ("cob_s64_t *)(");
1544  break;
1545  default:
1546  break;
1547  }
1548  output_data (x);
1549  output (")))");
1550  return;
1551  } else {
1552  output ("(*(");
1553  switch (f->size) {
1554  case 2:
1555  if (!f->pic->have_sign) {
1556  output ("unsigned short *)(");
1557  } else {
1558  output ("short *)(");
1559  }
1560  break;
1561  case 4:
1562  if (!f->pic->have_sign) {
1563  output ("unsigned int *)(");
1564  } else {
1565  output ("int *)(");
1566  }
1567  break;
1568  case 8:
1569  if (!f->pic->have_sign) {
1570  output ("cob_u64_ptr)(");
1571  } else {
1572  output ("cob_s64_ptr)(");
1573  }
1574  break;
1575  default:
1576  break;
1577  }
1578  output_data (x);
1579  output ("))");
1580  return;
1581  }
1582  }
1583 #if 0 /* RXWRXW - unsigned */
1584  if (f->pic->have_sign == 0) {
1585  output ("(unsigned int)");
1586  }
1587 #endif
1588  break;
1589 
1590  default:
1591  break;
1592  }
1593 
1594  output_func_1 ("cob_get_llint", x);
1595  break;
1596  case CB_TAG_INTRINSIC:
1597  output ("cob_get_llint (");
1598  output_param (x, -1);
1599  output (")");
1600  break;
1601  default:
1602  cobc_abort_pr (_("Unexpected tree tag %d"), (int)CB_TREE_TAG (x));
1603  COBC_ABORT ();
1604  }
1605 }
int indexes
Definition: tree.h:678
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
#define CB_INTEGER(x)
Definition: tree.h:522
static void output(const char *,...)
Definition: codegen.c:192
static void output_long_integer(cb_tree x)
Definition: codegen.c:1366
#define CB_FMT_LLD_F
Definition: common.h:60
#define CB_CAST(x)
Definition: tree.h:962
static void output_func_1(const char *name, cb_tree x)
Definition: codegen.c:2111
struct cb_picture * pic
Definition: tree.h:659
cb_tree cb_zero
Definition: tree.c:125
cob_u32_t special_index
Definition: tree.h:690
int cb_fits_long_long(const cb_tree x)
Definition: tree.c:991
#define CB_PREFIX_BASE
Definition: tree.h:31
static void output_data(cb_tree x)
Definition: codegen.c:705
static struct cb_program * current_prog
Definition: codegen.c:140
int id
Definition: tree.h:671
int offset
Definition: tree.h:675
#define _(s)
Definition: cobcrun.c:59
Definition: tree.h:643
int op
Definition: tree.h:932
#define CB_TREE_TAG(x)
Definition: tree.h:441
#define COBC_ABORT()
Definition: cobc.h:61
static const unsigned char hexval[]
Definition: typeck.c:109
unsigned int flag_binary_swap
Definition: tree.h:707
Definition: tree.h:956
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
int size
Definition: tree.h:672
static unsigned int gen_nested_tab
Definition: codegen.c:149
cb_tree y
Definition: tree.h:931
#define CB_CONST(x)
Definition: tree.h:476
enum cb_cast_type cast_type
Definition: tree.h:959
cb_tree cb_null
Definition: tree.c:124
cob_u32_t have_sign
Definition: tree.h:627
struct nested_list * nested_prog_list
Definition: tree.h:1249
cb_tree x
Definition: tree.h:930
#define CB_BINARY_OP(x)
Definition: tree.h:936
cb_tree val
Definition: tree.h:958
static void output_base(struct cb_field *f, const cob_u32_t no_output)
Definition: codegen.c:606
unsigned int flag
Definition: tree.h:933
cob_s64_t cb_get_long_long(const cb_tree x)
Definition: tree.c:1175
enum cb_usage usage
Definition: tree.h:693
enum cb_storage storage
Definition: tree.h:692

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_main_function ( struct cb_program prog)
static

Definition at line 7412 of file codegen.c.

References output_indent(), output_line(), and cb_program::program_id.

Referenced by codegen().

7413 {
7414  output_line ("/* Main function */");
7415  output_line ("int");
7416  output_line ("main (int argc, char **argv)");
7417  output_indent ("{");
7418  output_line ("cob_init (argc, argv);");
7419  output_line ("cob_stop_run (%s ());", prog->program_id);
7420  output_indent ("}\n");
7421 }
static void output_line(const char *fmt,...)
Definition: codegen.c:453
const char * program_id
Definition: tree.h:1244
static void output_indent(const char *str)
Definition: codegen.c:467

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_module_init ( struct cb_program prog)
static

Definition at line 5705 of file codegen.c.

References CB_FUNCTION_TYPE, cb_ref(), cobc_flag_main, cb_program::collating_sequence, cb_program::crt_status, cb_program::currency_symbol, cb_program::cursor_pos, cb_program::decimal_point, cb_program::nested_level, no_physical_cancel, non_nested_count, cb_program::num_proc_params, cb_program::numeric_separator, cb_program::orig_program_id, output(), output_line(), output_newline(), output_param(), output_prefix(), cb_program::prog_type, and cb_program::program_id.

Referenced by output_internal_function().

5706 {
5707 #if 0 /* Module comments */
5708  output ("/* Next pointer, Parameter list pointer, Module name, */\n");
5709  output ("/* Module formatted date, Module source, */\n");
5710  output ("/* Module entry, Module cancel, */\n");
5711  output ("/* Collating, CRT status, CURSOR, */\n");
5712  output ("/* Module reference count, Module path, Module active, */\n");
5713  output ("/* Module date, Module time, */\n");
5714  output ("/* Module type, Number of USING parameters, Return type */\n");
5715  output ("/* Current parameter count */\n");
5716  output ("/* Display sign, Decimal point, Currency symbol, */\n");
5717  output ("/* Numeric separator, File name mapping, Binary truncate, */\n");
5718  output ("/* Alternate numeric display, Host sign, No physical cancel */\n");
5719  output ("/* Flag main program, Fold call, Exit after CALL */\n\n");
5720 #endif
5721 
5722  /* Do not initialize next pointer, parameter list pointer + count */
5723  output_line ("/* Initialize module structure */");
5724  output_line ("module->module_name = \"%s\";", prog->orig_program_id);
5725  output_line ("module->module_formatted_date = COB_MODULE_FORMATTED_DATE;");
5726  output_line ("module->module_source = COB_SOURCE_FILE;");
5727  if (!prog->nested_level) {
5728  output_line ("module->module_entry.funcptr = (void *(*)())%s;",
5729  prog->program_id);
5730  if (prog->prog_type == CB_FUNCTION_TYPE) {
5731  output_line ("module->module_cancel.funcptr = NULL;");
5732  } else {
5733  output_line ("module->module_cancel.funcptr = (void *(*)())%s_;",
5734  prog->program_id);
5735  }
5736  } else {
5737  output_line ("module->module_entry.funcvoid = NULL;");
5738  output_line ("module->module_cancel.funcvoid = NULL;");
5739  }
5740 
5741  if (prog->collating_sequence) {
5742  output_prefix ();
5743  output ("module->collating_sequence = ");
5744  output_param (cb_ref (prog->collating_sequence), -1);
5745  output (";\n");
5746  } else {
5747  output_line ("module->collating_sequence = NULL;");
5748  }
5749  if (prog->crt_status && cb_code_field (prog->crt_status)->count) {
5750  output_prefix ();
5751  output ("module->crt_status = ");
5752  output_param (cb_ref (prog->crt_status), -1);
5753  output (";\n");
5754  } else {
5755  output_line ("module->crt_status = NULL;");
5756  }
5757  if (prog->cursor_pos) {
5758  output_prefix ();
5759  output ("module->cursor_pos = ");
5760  output_param (cb_ref (prog->cursor_pos), -1);
5761  output (";\n");
5762  } else {
5763  output_line ("module->cursor_pos = NULL;");
5764  }
5765  if (!cobc_flag_main && non_nested_count > 1) {
5766  output_line ("module->module_ref_count = &cob_reference_count;");
5767  } else {
5768  output_line ("module->module_ref_count = NULL;");
5769  }
5770  output_line ("module->module_path = &cob_module_path;");
5771  output_line ("module->module_active = 0;");
5772  output_line ("module->module_date = COB_MODULE_DATE;");
5773  output_line ("module->module_time = COB_MODULE_TIME;");
5774  output_line ("module->module_type = %d;", (int)prog->prog_type);
5775  output_line ("module->module_param_cnt = %d;", prog->num_proc_params);
5776  output_line ("module->module_returning = 0;");
5777  output_line ("module->ebcdic_sign = %d;", cb_ebcdic_sign);
5778  output_line ("module->decimal_point = '%c';", prog->decimal_point);
5779  output_line ("module->currency_symbol = '%c';", prog->currency_symbol);
5780  output_line ("module->numeric_separator = '%c';", prog->numeric_separator);
5781  output_line ("module->flag_filename_mapping = %d;", cb_filename_mapping);
5782  output_line ("module->flag_binary_truncate = %d;", cb_binary_truncate);
5783  output_line ("module->flag_pretty_display = %d;", cb_pretty_display);
5784  output_line ("module->flag_host_sign = %d;", cb_host_sign);
5785  output_line ("module->flag_no_phys_canc = %d;", no_physical_cancel);
5786  output_line ("module->flag_main = %d;", cobc_flag_main);
5787  output_line ("module->flag_fold_call = %d;", cb_fold_call);
5788  output_line ("module->flag_exit_program = 0;");
5789  output_newline ();
5790 }
static void output_newline(void)
Definition: codegen.c:433
static void output(const char *,...)
Definition: codegen.c:192
static void output_line(const char *fmt,...)
Definition: codegen.c:453
cb_tree cb_ref(cb_tree x)
Definition: tree.c:2653
int nested_level
Definition: tree.h:1295
cb_tree crt_status
Definition: tree.h:1287
static void output_prefix(void)
Definition: codegen.c:441
int no_physical_cancel
Definition: cobc.c:177
static int non_nested_count
Definition: codegen.c:162
unsigned char prog_type
Definition: tree.h:1303
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
unsigned char currency_symbol
Definition: tree.h:1301
const char * program_id
Definition: tree.h:1244
#define CB_FUNCTION_TYPE
Definition: tree.h:42
cb_tree collating_sequence
Definition: tree.h:1284
cb_tree cursor_pos
Definition: tree.h:1286
unsigned char numeric_separator
Definition: tree.h:1302
int cobc_flag_main
Definition: cobc.c:167
unsigned char decimal_point
Definition: tree.h:1300
char * orig_program_id
Definition: tree.h:1246
int num_proc_params
Definition: tree.h:1296

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_move ( cb_tree  src,
cb_tree  dst 
)
static

Definition at line 2235 of file codegen.c.

References cb_build_move(), cb_error_node, output_stmt(), suppress_warn, and cb_binary_op::x.

Referenced by output_call(), output_goto_1(), output_initialize_one(), output_internal_function(), output_perform(), output_perform_until(), output_search_whens(), and output_stmt().

2236 {
2237  cb_tree x;
2238 
2239  /* Suppress warnings */
2240  suppress_warn = 1;
2241  x = cb_build_move (src, dst);
2242  if (x != cb_error_node) {
2243  output_stmt (x);
2244  }
2245  suppress_warn = 0;
2246 }
size_t suppress_warn
Definition: typeck.c:90
cb_tree cb_error_node
Definition: tree.c:140
cb_tree cb_build_move(cb_tree, cb_tree)
Definition: typeck.c:7333
static void output_stmt(cb_tree x)
Definition: codegen.c:4660

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_newline ( void  )
static

Definition at line 433 of file codegen.c.

References output_target.

Referenced by codegen(), output_alter_check(), output_call(), output_class_name_definition(), output_cond(), output_error_handler(), output_internal_function(), output_label_info(), output_module_init(), output_perform_exit(), output_screen_init(), output_search_all(), output_search_whens(), and output_stmt().

434 {
435  if (output_target) {
436  fputs ("\n", output_target);
437  }
438 }
static FILE * output_target
Definition: codegen.c:135

Here is the caller graph for this function:

static void output_occurs ( struct cb_field p)
static

Definition at line 2896 of file codegen.c.

References cb_field::depending, cb_field::occurs_max, output(), and output_integer().

Referenced by output_search_all(), and output_search_whens().

2897 {
2898  if (p->depending) {
2900  } else {
2901  output ("%d", p->occurs_max);
2902  }
2903 }
int occurs_max
Definition: tree.h:677
static void output(const char *,...)
Definition: codegen.c:192
cb_tree depending
Definition: tree.h:647
static void output_integer(cb_tree x)
Definition: codegen.c:1101

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_param ( cb_tree  x,
int  id 
)
static

Definition at line 1628 of file codegen.c.

References _, cb_alphabet_name::alphabet_type, cb_intrinsic::args, cb_cast::cast_type, CB_ALPHABET_ASCII, CB_ALPHABET_CUSTOM, CB_ALPHABET_EBCDIC, CB_ALPHABET_NAME, CB_ALPHABET_NAME_P, CB_ALPHABET_NATIVE, CB_BINARY_OP, cb_build_field_reference(), CB_CAST, CB_CAST_ADDR_OF_ADDR, CB_CAST_ADDRESS, CB_CAST_INTEGER, CB_CAST_LENGTH, CB_CAST_LONG_INT, CB_CAST_PROGRAM_POINTER, CB_CHAIN, CB_CONST, CB_DECIMAL, CB_FIELD, CB_FILE, CB_FILE_P, CB_FUNC_PROTOTYPE, cb_int0, cb_int1, CB_INTRINSIC, cb_list_length(), CB_LOCALE_NAME, CB_LOCALE_NAME_P, CB_NEED_HIGH, CB_NEED_LOW, CB_NEED_QUOTE, CB_NEED_SPACE, CB_NEED_ZERO, cb_norm_high, cb_norm_low, CB_PREFIX_CONST, CB_PREFIX_FIELD, CB_PREFIX_FILE, CB_PREFIX_SEQUENCE, cb_quote, cb_ref(), CB_REFERENCE, cb_space, CB_STORAGE_SCREEN, CB_STRING, CB_TAG_ALPHABET_NAME, CB_TAG_BINARY_OP, CB_TAG_CAST, CB_TAG_CONST, CB_TAG_DECIMAL, CB_TAG_FIELD, CB_TAG_FILE, CB_TAG_FUNCALL, CB_TAG_INTEGER, CB_TAG_INTRINSIC, CB_TAG_LITERAL, CB_TAG_LOCALE_NAME, CB_TAG_REFERENCE, CB_TAG_STRING, CB_TREE_TAG, CB_VALUE, cb_zero, cb_reference::check, chk_field_variable_address(), chk_field_variable_size(), cb_alphabet_name::cname, COB_INSIDE_SIZE, COBC_ABORT, cobc_abort_pr(), cobc_parse_malloc(), cb_program::collating_sequence, cb_field::count, field_list::curr_prog, excp_current_program_id, field_list::f, field_cache, cb_field::flag_any_length, cb_field::flag_anylen_done, cb_field::flag_external, cb_field::flag_field, cb_program::flag_file_global, cb_field::flag_is_global, cb_field::flag_item_based, cb_field::flag_local, gen_alt_ebcdic, gen_custom, gen_dynamic, gen_ebcdic_ascii, gen_figurative, gen_full_ebcdic, gen_native, cb_field::id, inside_check, inside_stack, cb_intrinsic::intr_field, cb_intrinsic_table::intr_routine, cb_intrinsic::intr_tab, cb_intrinsic::isuser, cb_intrinsic::length, local_field_cache, lookup_func_call(), lookup_literal(), cb_intrinsic::name, field_list::next, nolitcast, NULL, num_cob_fields, cb_reference::offset, cb_intrinsic::offset, cb_binary_op::op, output(), output_attr(), output_data(), output_field(), output_funcall(), output_indent_level, output_integer(), output_long_integer(), output_prefix(), output_size(), output_stmt(), output_string(), output_target, param_id, real_field_founder(), cb_intrinsic_table::refmod, screenptr, cb_field::special_index, stack_id, cb_field::storage, cb_reference::subs, user_func_upper(), cb_cast::val, cb_reference::value, field_list::x, cb_binary_op::x, and cb_binary_op::y.

Referenced by output_call(), output_call_by_value_args(), output_cancel(), output_data(), output_file_initialization(), output_func_1(), output_funcall(), output_funcall_debug(), output_goto(), output_integer(), output_internal_function(), output_long_integer(), output_module_init(), output_perform(), output_screen_init(), and output_stmt().

1629 {
1630  struct cb_reference *r;
1631  struct cb_field *f;
1632  struct cb_field *ff;
1633  struct cb_cast *cp;
1634  struct cb_binary_op *bp;
1635  struct field_list *fl;
1636  FILE *savetarget;
1637  struct cb_intrinsic *ip;
1638  struct cb_alphabet_name *abp;
1639  struct cb_alphabet_name *rbp;
1640  cb_tree l;
1641  char *func;
1642  int n;
1643  int sav_stack_id;
1644  char fname[12];
1645 
1646  param_id = id;
1647 
1648  if (x == NULL) {
1649  output ("NULL");
1650  return;
1651  }
1652 
1653  switch (CB_TREE_TAG (x)) {
1654  case CB_TAG_CONST:
1655  if (x == cb_quote) {
1657  } else if (x == cb_norm_low) {
1659  } else if (x == cb_norm_high) {
1661  } else if (x == cb_space) {
1663  } else if (x == cb_zero) {
1665  }
1666  output ("%s", CB_CONST (x)->val);
1667  break;
1668  case CB_TAG_INTEGER:
1669  output_integer (x);
1670  break;
1671  case CB_TAG_STRING:
1672  output_string (CB_STRING (x)->data, (int) CB_STRING (x)->size, 0);
1673  break;
1674  case CB_TAG_LOCALE_NAME:
1675  output_param (CB_LOCALE_NAME(x)->list, id);
1676  break;
1677  case CB_TAG_ALPHABET_NAME:
1678  abp = CB_ALPHABET_NAME (x);
1679  switch (abp->alphabet_type) {
1680  case CB_ALPHABET_ASCII:
1681 #ifdef COB_EBCDIC_MACHINE
1682  gen_ebcdic_ascii = 1;
1683  output ("cob_ebcdic_ascii");
1684  break;
1685 #endif
1686  /* Fall through for ASCII */
1687  case CB_ALPHABET_NATIVE:
1689  gen_native = 1;
1690  output ("cob_native");
1691  } else {
1692  output ("NULL");
1693  }
1694  break;
1695  case CB_ALPHABET_EBCDIC:
1696 #ifdef COB_EBCDIC_MACHINE
1698  gen_native = 1;
1699  output ("cob_native");
1700  } else {
1701  output ("NULL");
1702  }
1703 #else
1704  if (cb_flag_alt_ebcdic) {
1705  gen_alt_ebcdic = 1;
1706  output ("cob_a2e");
1707  } else {
1708  gen_full_ebcdic = 1;
1709  output ("cob_ascii_ebcdic");
1710  }
1711 #endif
1712  break;
1713  case CB_ALPHABET_CUSTOM:
1714  gen_custom = 1;
1715  output ("%s%s", CB_PREFIX_SEQUENCE, abp->cname);
1716  break;
1717  default:
1718  break;
1719  }
1720  break;
1721  case CB_TAG_CAST:
1722  cp = CB_CAST (x);
1723  switch (cp->cast_type) {
1724  case CB_CAST_INTEGER:
1725  output_integer (cp->val);
1726  break;
1727  case CB_CAST_LONG_INT:
1728  output_long_integer (cp->val);
1729  break;
1730  case CB_CAST_ADDRESS:
1731  output_data (cp->val);
1732  break;
1733  case CB_CAST_ADDR_OF_ADDR:
1734  output ("&");
1735  output_data (cp->val);
1736  break;
1737  case CB_CAST_LENGTH:
1738  output_size (cp->val);
1739  break;
1741  output_param (cp->val, id);
1742  break;
1743  default:
1744  break;
1745  }
1746  break;
1747  case CB_TAG_DECIMAL:
1748  output ("d%d", CB_DECIMAL (x)->id);
1749  break;
1750  case CB_TAG_FILE:
1751  output ("%s%s", CB_PREFIX_FILE, CB_FILE (x)->cname);
1752  break;
1753  case CB_TAG_LITERAL:
1754 #if 0 /* RXWRXW - Const */
1755  output ("&%s%d.vf", CB_PREFIX_CONST, lookup_literal (x));
1756 #else
1757  if (nolitcast) {
1758  output ("&%s%d", CB_PREFIX_CONST, lookup_literal (x));
1759  } else {
1760  output ("(cob_field *)&%s%d", CB_PREFIX_CONST,
1761  lookup_literal (x));
1762  }
1763 #endif
1764  break;
1765  case CB_TAG_FIELD:
1766  /* TODO: remove me */
1768  break;
1769  case CB_TAG_REFERENCE:
1770  r = CB_REFERENCE (x);
1771  if (CB_LOCALE_NAME_P (r->value)) {
1772  output_param (CB_LOCALE_NAME(r->value)->list, id);
1773  break;
1774  }
1775  if (r->check) {
1776  inside_stack[inside_check++] = 0;
1777  if (inside_check >= COB_INSIDE_SIZE) {
1778  cobc_abort_pr (_("Internal statement stack depth exceeded -> %d"),
1779  COB_INSIDE_SIZE);
1780  COBC_ABORT ();
1781  }
1782  output ("\n");
1783  output_prefix ();
1784  output ("(");
1785  n = output_indent_level;
1786  output_indent_level = 0;
1787  for (l = r->check; l; l = CB_CHAIN (l)) {
1788  sav_stack_id = stack_id;
1789  output_stmt (CB_VALUE (l));
1790  stack_id = sav_stack_id;
1791  if (l == r->check) {
1792  output_indent_level = n;
1793  }
1794  }
1795  }
1796 
1797  if (CB_FILE_P (r->value)) {
1798  output ("%s%s", CB_PREFIX_FILE, CB_FILE (r->value)->cname);
1799  if (r->check) {
1800  if (inside_check) {
1801  --inside_check;
1802  }
1803  output (" )");
1804  }
1805  break;
1806  }
1807  if (CB_ALPHABET_NAME_P (r->value)) {
1808  rbp = CB_ALPHABET_NAME (r->value);
1809  switch (rbp->alphabet_type) {
1810  case CB_ALPHABET_ASCII:
1811 #ifdef COB_EBCDIC_MACHINE
1812  gen_ebcdic_ascii = 2;
1813  output ("&f_ebcdic_ascii");
1814  break;
1815 #endif
1816  /* Fall through for ASCII */
1817  case CB_ALPHABET_NATIVE:
1818  gen_native = 2;
1819  output ("&f_native");
1820  break;
1821  case CB_ALPHABET_EBCDIC:
1822 #ifdef COB_EBCDIC_MACHINE
1823  gen_native = 2;
1824  output ("&f_native");
1825 #else
1826  gen_full_ebcdic = 2;
1827  output ("&f_ascii_ebcdic");
1828 #endif
1829  break;
1830  case CB_ALPHABET_CUSTOM:
1831  gen_custom = 1;
1832  output ("&%s%s", CB_PREFIX_FIELD, rbp->cname);
1833  break;
1834  default:
1835  break;
1836  }
1837  if (r->check) {
1838  if (inside_check) {
1839  --inside_check;
1840  }
1841  output (" )");
1842  }
1843  break;
1844  }
1845 
1846  f = CB_FIELD (r->value);
1847 
1848  ff = real_field_founder (f);
1849 
1850  if (ff->flag_external) {
1851  f->flag_external = 1;
1852  f->flag_local = 1;
1853  } else if (ff->flag_item_based) {
1854  f->flag_local = 1;
1855  }
1856 
1857  if (!r->subs && !r->offset && f->count > 0 &&
1858  !chk_field_variable_size (f) &&
1860  if (!f->flag_field) {
1861  savetarget = output_target;
1862  output_target = NULL;
1863  output_field (x);
1864 
1865  fl = cobc_parse_malloc (sizeof (struct field_list));
1866  fl->x = x;
1867  fl->f = f;
1869  if (f->special_index != 2 && (f->flag_is_global ||
1871  fl->next = field_cache;
1872  field_cache = fl;
1873  } else {
1874  fl->next = local_field_cache;
1875  local_field_cache = fl;
1876  }
1877 
1878  f->flag_field = 1;
1879  output_target = savetarget;
1880  }
1881  if (f->flag_local) {
1882 #if 0 /* RXWRXW - Any data pointer */
1883  if (f->flag_any_length && f->flag_anylen_done) {
1884  output ("&%s%d",
1885  CB_PREFIX_FIELD, f->id);
1886  } else {
1887 #endif
1888  output ("COB_SET_DATA (%s%d, ",
1889  CB_PREFIX_FIELD, f->id);
1890  output_data (x);
1891  output (")");
1892 #if 0 /* RXWRXW - Any data pointer */
1893  f->flag_anylen_done = 1;
1894  }
1895 #endif
1896  } else {
1897  if (screenptr && f->storage == CB_STORAGE_SCREEN) {
1898  output ("&s_%d", f->id);
1899  } else {
1900  output ("&%s%d", CB_PREFIX_FIELD, f->id);
1901  }
1902  }
1903  } else {
1904  if (stack_id >= num_cob_fields) {
1905  num_cob_fields = stack_id + 1;
1906  }
1907  sprintf (fname, "f%d", stack_id++);
1908  if (inside_check != 0) {
1909  if (inside_stack[inside_check - 1] != 0) {
1910  inside_stack[inside_check - 1] = 0;
1911  output (",\n");
1912  output_prefix ();
1913  }
1914  }
1915  output ("COB_SET_FLD(%s, ", fname);
1916  output_size (x);
1917  output (", ");
1918  output_data (x);
1919  output (", ");
1920  output_attr (x);
1921  output (")");
1922  }
1923 
1924  if (r->check) {
1925  if (inside_check) {
1926  --inside_check;
1927  }
1928  output (" )");
1929  }
1930  break;
1931  case CB_TAG_BINARY_OP:
1932  bp = CB_BINARY_OP (x);
1933  output ("cob_intr_binop (");
1934  output_param (bp->x, id);
1935  output (", ");
1936  output ("%d", bp->op);
1937  output (", ");
1938  output_param (bp->y, id);
1939  output (")");
1940  break;
1941  case CB_TAG_INTRINSIC:
1942  ip = CB_INTRINSIC (x);
1943  if (ip->isuser) {
1944  func = user_func_upper (CB_FUNC_PROTOTYPE (cb_ref (ip->name))->ext_name);
1945  lookup_func_call (func);
1946 #if 0 /* RXWRXW Func */
1947  output ("cob_user_function (func_%s, &cob_dyn_%u, ",
1948  func, gen_dynamic);
1949 #else
1950  output ("func_%s.funcfld (&cob_dyn_%u",
1951  func, gen_dynamic);
1952 #endif
1953  gen_dynamic++;
1954  if (ip->intr_field || ip->args) {
1955  output (", ");
1956  }
1957 #if 0 /* RXWRXW Func */
1958  if (ip->intr_tab->refmod) {
1959  if (ip->offset) {
1960  output_integer (ip->offset);
1961  output (", ");
1962  } else {
1963  output ("0, ");
1964  }
1965  if (ip->length) {
1966  output_integer (ip->length);
1967  } else {
1968  output ("0");
1969  }
1970  if (ip->intr_field || ip->args) {
1971  output (", ");
1972  }
1973  }
1974 #endif
1975  } else {
1976  output ("%s (", ip->intr_tab->intr_routine);
1977  if (ip->intr_tab->refmod) {
1978  if (ip->offset) {
1979  output_integer (ip->offset);
1980  output (", ");
1981  } else {
1982  output ("0, ");
1983  }
1984  if (ip->length) {
1985  output_integer (ip->length);
1986  } else {
1987  output ("0");
1988  }
1989  if (ip->intr_field || ip->args) {
1990  output (", ");
1991  }
1992  }
1993  }
1994  if (ip->intr_field) {
1995  if (ip->intr_field == cb_int0) {
1996  output ("NULL");
1997  } else if (ip->intr_field == cb_int1) {
1998  output ("%d", cb_list_length (ip->args));
1999  } else {
2000  output_param (ip->intr_field, id);
2001  }
2002  if (ip->args) {
2003  output (", ");
2004  }
2005  }
2006  for (l = ip->args; l; l = CB_CHAIN (l)) {
2007  output_param (CB_VALUE (l), id);
2008  id++;
2009  param_id++;
2010  if (CB_CHAIN (l)) {
2011  output (", ");
2012  }
2013  }
2014  output (")");
2015  break;
2016  case CB_TAG_FUNCALL:
2017  output_funcall (x);
2018  break;
2019  default:
2020  cobc_abort_pr (_("Unexpected tree tag %d"), (int)CB_TREE_TAG (x));
2021  COBC_ABORT ();
2022  }
2023 }
cb_tree check
Definition: tree.h:880
static struct cb_field * chk_field_variable_size(struct cb_field *f)
Definition: codegen.c:556
cb_tree intr_field
Definition: tree.h:994
#define CB_NEED_QUOTE
Definition: codegen.c:57
cb_tree cb_int1
Definition: tree.c:134
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
static unsigned int gen_alt_ebcdic
Definition: codegen.c:150
static FILE * output_target
Definition: codegen.c:135
unsigned int flag_any_length
Definition: tree.h:712
void * cobc_parse_malloc(const size_t size)
Definition: cobc.c:809
static unsigned int chk_field_variable_address(struct cb_field *fld)
Definition: codegen.c:582
#define CB_DECIMAL(x)
Definition: tree.h:613
static unsigned int gen_custom
Definition: codegen.c:154
cb_tree cb_norm_high
Definition: tree.c:131
static char * user_func_upper(const char *func)
Definition: codegen.c:914
static void output(const char *,...)
Definition: codegen.c:192
int isuser
Definition: tree.h:998
static void output_long_integer(cb_tree x)
Definition: codegen.c:1366
#define CB_INTRINSIC(x)
Definition: tree.h:1001
unsigned int flag_anylen_done
Definition: tree.h:720
cb_tree value
Definition: tree.h:876
static unsigned int gen_ebcdic_ascii
Definition: codegen.c:151
cb_tree cb_norm_low
Definition: tree.c:130
#define CB_PREFIX_FILE
Definition: tree.h:35
cb_tree cb_build_field_reference(struct cb_field *f, cb_tree ref)
Definition: tree.c:2604
#define CB_CAST(x)
Definition: tree.h:962
cb_tree cb_ref(cb_tree x)
Definition: tree.c:2653
#define CB_ALPHABET_ASCII
Definition: tree.h:108
struct field_list * next
Definition: codegen.c:101
cb_tree cb_zero
Definition: tree.c:125
static void output_string(const unsigned char *s, const int size, const cob_u32_t llit)
Definition: codegen.c:489
#define CB_ALPHABET_NATIVE
Definition: tree.h:107
#define COB_INSIDE_SIZE
Definition: codegen.c:48
static unsigned int gen_dynamic
Definition: codegen.c:156
cob_u32_t special_index
Definition: tree.h:690
char * cname
Definition: tree.h:541
unsigned char flag_is_global
Definition: tree.h:699
cb_tree cb_quote
Definition: tree.c:132
cb_tree cb_space
Definition: tree.c:127
#define CB_FILE(x)
Definition: tree.h:858
static void output_funcall(cb_tree x)
Definition: codegen.c:2028
static void output_data(cb_tree x)
Definition: codegen.c:705
#define CB_NEED_SPACE
Definition: codegen.c:58
static unsigned int gen_native
Definition: codegen.c:153
unsigned int flag_file_global
Definition: tree.h:1315
static void output_prefix(void)
Definition: codegen.c:441
#define CB_VALUE(x)
Definition: tree.h:1193
static struct cb_program * current_prog
Definition: codegen.c:140
int id
Definition: tree.h:671
struct cb_intrinsic_table * intr_tab
Definition: tree.h:995
int cb_list_length(cb_tree l)
Definition: tree.c:1342
static void output_size(const cb_tree x)
Definition: codegen.c:793
cb_tree args
Definition: tree.h:993
const unsigned int refmod
Definition: tree.h:987
static void output_field(cb_tree x)
Definition: codegen.c:1045
#define CB_ALPHABET_NAME(x)
Definition: tree.h:550
#define _(s)
Definition: cobcrun.c:59
#define CB_LOCALE_NAME(x)
Definition: tree.h:574
Definition: tree.h:643
static struct field_list * local_field_cache
Definition: codegen.c:124
#define CB_CHAIN(x)
Definition: tree.h:1194
int op
Definition: tree.h:932
cb_tree length
Definition: tree.h:997
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define CB_TREE_TAG(x)
Definition: tree.h:441
cb_tree offset
Definition: tree.h:878
#define COBC_ABORT()
Definition: cobc.h:61
struct cb_field * f
Definition: codegen.c:102
cb_tree cb_int0
Definition: tree.c:133
static void lookup_func_call(const char *p)
Definition: codegen.c:253
int count
Definition: tree.h:680
static struct field_list * field_cache
Definition: codegen.c:123
#define CB_REFERENCE(x)
Definition: tree.h:901
static const char * excp_current_program_id
Definition: codegen.c:137
Definition: tree.h:956
#define CB_LOCALE_NAME_P(x)
Definition: tree.h:575
#define CB_FUNC_PROTOTYPE(x)
Definition: tree.h:1339
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
#define CB_FILE_P(x)
Definition: tree.h:859
static int screenptr
Definition: codegen.c:167
#define CB_ALPHABET_CUSTOM
Definition: tree.h:110
#define CB_NEED_LOW
Definition: codegen.c:56
static unsigned int inside_check
Definition: codegen.c:176
static unsigned int nolitcast
Definition: codegen.c:174
static int lookup_literal(cb_tree x)
Definition: codegen.c:1059
static unsigned int gen_figurative
Definition: codegen.c:155
cb_tree x
Definition: codegen.c:103
cb_tree y
Definition: tree.h:931
static int param_id
Definition: codegen.c:158
#define CB_CONST(x)
Definition: tree.h:476
enum cb_cast_type cast_type
Definition: tree.h:959
cb_tree offset
Definition: tree.h:996
unsigned int flag_field
Definition: tree.h:717
#define CB_PREFIX_CONST
Definition: tree.h:32
cb_tree collating_sequence
Definition: tree.h:1284
static unsigned int inside_stack[64]
Definition: codegen.c:177
#define CB_NEED_HIGH
Definition: codegen.c:55
static void output_integer(cb_tree x)
Definition: codegen.c:1101
cb_tree x
Definition: tree.h:930
#define CB_BINARY_OP(x)
Definition: tree.h:936
static int output_indent_level
Definition: codegen.c:171
#define CB_ALPHABET_NAME_P(x)
Definition: tree.h:551
cb_tree subs
Definition: tree.h:877
const char * intr_routine
Definition: tree.h:980
static unsigned int gen_full_ebcdic
Definition: codegen.c:152
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
static void output_attr(const cb_tree x)
Definition: codegen.c:929
static int num_cob_fields
Definition: codegen.c:161
const char * curr_prog
Definition: codegen.c:104
unsigned int flag_local
Definition: tree.h:701
cb_tree val
Definition: tree.h:958
#define CB_PREFIX_SEQUENCE
Definition: tree.h:38
#define CB_PREFIX_FIELD
Definition: tree.h:34
cb_tree name
Definition: tree.h:992
static int stack_id
Definition: codegen.c:159
#define CB_NEED_ZERO
Definition: codegen.c:59
unsigned int alphabet_type
Definition: tree.h:543
static struct cb_field * real_field_founder(const struct cb_field *f)
Definition: codegen.c:541
#define CB_ALPHABET_EBCDIC
Definition: tree.h:109
enum cb_storage storage
Definition: tree.h:692
#define CB_FIELD(x)
Definition: tree.h:740
unsigned char flag_external
Definition: tree.h:697
unsigned int flag_item_based
Definition: tree.h:713

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_perform ( struct cb_perform p)
static

Definition at line 4266 of file codegen.c.

References cb_build_cast_llint(), cb_build_debug(), cb_debug_contents, cb_debug_name, CB_FIELD, CB_LABEL, CB_PERFORM_EXIT, CB_PERFORM_FOREVER, CB_PERFORM_ONCE, CB_PERFORM_TIMES, CB_PERFORM_UNTIL, CB_PERFORM_VARYING, cb_ref(), CB_VALUE, cb_perform::data, cb_field::debug_section, cb_perform::exit_label, cb_field::flag_field_debug, cb_program::flag_gen_debug, cb_perform_varying::from, loop_counter, cb_field::name, cb_perform_varying::name, NULL, output(), output_indent(), output_move(), output_param(), output_perform_call(), output_perform_exit(), output_perform_once(), output_perform_until(), output_prefix(), output_stmt(), cb_perform::perform_type, and cb_perform::varying.

Referenced by output_stmt().

4267 {
4268  struct cb_perform_varying *v;
4269  struct cb_field *f;
4270 
4271  switch (p->perform_type) {
4272  case CB_PERFORM_EXIT:
4273  if (CB_LABEL (p->data)->flag_return) {
4275  }
4276  break;
4277  case CB_PERFORM_ONCE:
4278  output_perform_once (p);
4279  break;
4280  case CB_PERFORM_TIMES:
4281  output_prefix ();
4282  output ("for (n%d = ", loop_counter);
4284  output ("; n%d > 0; n%d--)\n", loop_counter, loop_counter);
4285  loop_counter++;
4286  output_indent ("{");
4287  output_perform_once (p);
4288  output_indent ("}");
4289  break;
4290  case CB_PERFORM_UNTIL:
4291  v = CB_PERFORM_VARYING (CB_VALUE (p->varying));
4292  if (v->name) {
4293  output_move (v->from, v->name);
4294  /* DEBUG */
4296  f = CB_FIELD (cb_ref (v->name));
4297  if (f->flag_field_debug) {
4299  (const char *)f->name, NULL));
4301  NULL, v->name));
4303  f->debug_section);
4304  }
4305  }
4306 
4307  }
4308  output_perform_until (p, p->varying);
4309  break;
4310  case CB_PERFORM_FOREVER:
4311  output_prefix ();
4312  output ("for (;;)\n");
4313  output_indent ("{");
4314  output_perform_once (p);
4315  output_indent ("}");
4316  break;
4317  default:
4318  break;
4319  }
4320  if (p->exit_label) {
4321  output_stmt (cb_ref (p->exit_label));
4322  }
4323 }
const char * name
Definition: tree.h:645
enum cb_perform_type perform_type
Definition: tree.h:1113
#define CB_LABEL(x)
Definition: tree.h:801
static void output_perform_once(struct cb_perform *p)
Definition: codegen.c:4189
unsigned int flag_gen_debug
Definition: tree.h:1321
struct cb_label * debug_section
Definition: tree.h:661
static void output(const char *,...)
Definition: codegen.c:192
static int loop_counter
Definition: codegen.c:163
cb_tree cb_ref(cb_tree x)
Definition: tree.c:2653
unsigned int flag_field_debug
Definition: tree.h:733
cb_tree data
Definition: tree.h:1109
#define CB_PERFORM_VARYING(x)
Definition: tree.h:1116
static void output_prefix(void)
Definition: codegen.c:441
#define CB_VALUE(x)
Definition: tree.h:1193
static struct cb_program * current_prog
Definition: codegen.c:140
static void output_perform_exit(struct cb_label *l)
Definition: codegen.c:4017
Definition: tree.h:643
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
cb_tree cb_debug_name
Definition: typeck.c:84
cb_tree cb_build_cast_llint(const cb_tree val)
Definition: tree.c:2975
cb_tree from
Definition: tree.h:1100
cb_tree exit_label
Definition: tree.h:1111
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
static void output_perform_call(struct cb_label *lb, struct cb_label *le)
Definition: codegen.c:3905
cb_tree name
Definition: tree.h:1099
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
cb_tree cb_build_debug(const cb_tree target, const char *str, const cb_tree fld)
Definition: tree.c:1566
static void output_perform_until(struct cb_perform *p, cb_tree l)
Definition: codegen.c:4203
static void output_move(cb_tree src, cb_tree dst)
Definition: codegen.c:2235
cb_tree cb_debug_contents
Definition: typeck.c:88
#define CB_FIELD(x)
Definition: tree.h:740
cb_tree varying
Definition: tree.h:1110
static void output_indent(const char *str)
Definition: codegen.c:467

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_perform_call ( struct cb_label lb,
struct cb_label le 
)
static

Definition at line 3905 of file codegen.c.

References cb_program::all_procedure, label_list::call_num, cb_build_debug(), cb_debug_name, cb_id, CB_PREFIX_LABEL, cobc_parse_malloc(), cb_label::flag_alter, cb_label::flag_debugging_mode, cb_program::flag_gen_debug, cb_label::flag_is_debug_sect, cb_label::flag_real_label, cb_label::flag_section, cb_program::flag_segments, label_list::id, cb_label::id, label_cache, last_segment, cb_label::name, label_list::next, cb_para_label::next, NULL, output_line(), output_stmt(), cb_para_label::para, cb_label::para_label, cb_label::section, cb_label::section_id, and cb_label::segment.

Referenced by output_alter(), output_cond_debug(), output_error_handler(), output_file_error(), output_funcall_debug(), output_goto(), output_perform(), output_perform_once(), output_perform_until(), and output_stmt().

3906 {
3907  struct cb_para_label *p;
3908  struct label_list *l;
3909 
3910  if (lb == current_prog->all_procedure || lb->flag_is_debug_sect) {
3911  output_line ("/* DEBUGGING Callback PERFORM %s */",
3912  (const char *)lb->name);
3913  } else if (lb == le) {
3914  output_line ("/* PERFORM %s */", (const char *)lb->name);
3915  } else {
3916  output_line ("/* PERFORM %s THRU %s */", (const char *)lb->name,
3917  (const char *)le->name);
3918  }
3919 
3920  /* Save current independent segment pointers */
3923  p = last_section->para_label;
3924  for (; p; p = p->next) {
3925  if (p->para->segment > 49 &&
3926  p->para->flag_alter) {
3927  output_line ("save_label_%s%d = label_%s%d;",
3928  CB_PREFIX_LABEL, p->para->id,
3929  CB_PREFIX_LABEL, p->para->id);
3930  }
3931  }
3932  }
3933  /* Zap target independent labels */
3935  if (lb->flag_section) {
3936  p = lb->para_label;
3937  } else if (lb->section) {
3938  p = lb->section->para_label;
3939  } else {
3940  p = NULL;
3941  }
3942  for (; p; p = p->next) {
3943  if (p->para->segment > 49 &&
3944  p->para->flag_alter) {
3945  output_line ("label_%s%d = 0;",
3946  CB_PREFIX_LABEL, p->para->id);
3947  }
3948  }
3949  }
3950 
3951  /* Update debugging name */
3955  (const char *)lb->name, NULL));
3956  }
3957 
3958  output_line ("frame_ptr++;");
3959  if (cb_flag_stack_check) {
3960  output_line ("if (unlikely(frame_ptr == frame_overflow))");
3961  output_line (" cob_fatal_error (COB_FERROR_STACK);");
3962  }
3963  output_line ("frame_ptr->perform_through = %d;", le->id);
3964  if (!cb_flag_computed_goto) {
3965  l = cobc_parse_malloc (sizeof (struct label_list));
3966  l->next = label_cache;
3967  l->id = cb_id;
3968  if (label_cache == NULL) {
3969  l->call_num = 0;
3970  } else {
3971  l->call_num = label_cache->call_num + 1;
3972  }
3973  label_cache = l;
3974  output_line ("frame_ptr->return_address_num = %d;", l->call_num);
3975  output_line ("goto %s%d;", CB_PREFIX_LABEL, lb->id);
3976  output_line ("%s%d:", CB_PREFIX_LABEL, cb_id);
3977  } else {
3978  output_line ("frame_ptr->return_address_ptr = &&%s%d;",
3980  output_line ("goto %s%d;", CB_PREFIX_LABEL, lb->id);
3981  output_line ("%s%d:", CB_PREFIX_LABEL, cb_id);
3982  }
3983  output_line ("frame_ptr--;");
3984  cb_id++;
3985 
3988  /* Restore current independent segment pointers */
3989  p = last_section->para_label;
3990  for (; p; p = p->next) {
3991  if (p->para->segment > 49 &&
3992  p->para->flag_alter) {
3993  output_line ("label_%s%d = save_label_%s%d;",
3994  CB_PREFIX_LABEL, p->para->id,
3995  CB_PREFIX_LABEL, p->para->id);
3996  }
3997  }
3998  /* Zap target independent labels */
3999  if (lb->flag_section) {
4000  p = lb->para_label;
4001  } else if (lb->section) {
4002  p = lb->section->para_label;
4003  } else {
4004  p = NULL;
4005  }
4006  for (; p; p = p->next) {
4007  if (p->para->segment > 49 &&
4008  p->para->flag_alter) {
4009  output_line ("label_%s%d = 0;",
4010  CB_PREFIX_LABEL, p->para->id);
4011  }
4012  }
4013  }
4014 }
unsigned int flag_is_debug_sect
Definition: tree.h:797
const char * name
Definition: tree.h:766
unsigned int flag_gen_debug
Definition: tree.h:1321
void * cobc_parse_malloc(const size_t size)
Definition: cobc.c:809
#define CB_PREFIX_LABEL
Definition: tree.h:37
static void output_line(const char *fmt,...)
Definition: codegen.c:453
int cb_id
Definition: cobc.c:163
unsigned int flag_real_label
Definition: tree.h:781
struct label_list * next
Definition: codegen.c:71
struct cb_para_label * para_label
Definition: tree.h:770
static struct label_list * label_cache
Definition: codegen.c:132
static struct cb_program * current_prog
Definition: codegen.c:140
unsigned int flag_section
Definition: tree.h:777
struct cb_label * section
Definition: tree.h:768
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
cb_tree cb_debug_name
Definition: typeck.c:84
unsigned int flag_debugging_mode
Definition: tree.h:796
int segment
Definition: tree.h:775
unsigned int flag_segments
Definition: tree.h:1317
int id
Definition: codegen.c:72
struct cb_para_label * next
Definition: tree.h:755
int call_num
Definition: codegen.c:73
unsigned int flag_alter
Definition: tree.h:795
static struct cb_label * last_section
Definition: codegen.c:142
struct cb_label * all_procedure
Definition: tree.h:1289
struct cb_label * para
Definition: tree.h:756
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
cb_tree cb_build_debug(const cb_tree target, const char *str, const cb_tree fld)
Definition: tree.c:1566
int section_id
Definition: tree.h:774
int id
Definition: tree.h:773
static int last_segment
Definition: codegen.c:172

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_perform_exit ( struct cb_label l)
static

Definition at line 4017 of file codegen.c.

References CB_PROGRAM_TYPE, cb_label::flag_declarative_exit, cb_label::flag_default_handler, cb_label::flag_fatal_check, cb_label::flag_global, cb_program::flag_recursive, cb_label::id, output_line(), output_newline(), and cb_program::prog_type.

Referenced by output_error_handler(), and output_perform().

4018 {
4019  if (l->flag_global) {
4020  output_newline ();
4021  output_line ("/* Implicit GLOBAL DECLARATIVE return */");
4022  output_line ("if (entry == %d) {", l->id);
4023  output_line (" cob_module_leave (module);");
4024  if (cb_flag_stack_on_heap || current_prog->flag_recursive) {
4025  output_line (" cob_free (frame_stack);");
4026  output_line (" cob_free (cob_procedure_params);");
4027  output_line (" cob_cache_free (module);");
4028  }
4029  output_line (" return 0;");
4030  output_line ("}");
4031  }
4032  output_newline ();
4033 
4034  if (l->flag_declarative_exit) {
4035  output_line ("/* Implicit DECLARATIVE return */");
4036  } else if (l->flag_default_handler) {
4037  output_line ("/* Implicit Default Error Handler return */");
4038  } else {
4039  output_line ("/* Implicit PERFORM return */");
4040  }
4041 
4042  if (cb_perform_osvs && current_prog->prog_type == CB_PROGRAM_TYPE) {
4043  output_line
4044  ("for (temp_index = frame_ptr; temp_index->perform_through; temp_index--) {");
4045  output_line (" if (temp_index->perform_through == %d) {", l->id);
4046  output_line (" frame_ptr = temp_index;");
4047  if (!cb_flag_computed_goto) {
4048  output_line (" goto P_switch;");
4049  } else {
4050  output_line (" goto *frame_ptr->return_address_ptr;");
4051  }
4052  output_line (" }");
4053  output_line ("}");
4054  } else {
4055  output_line ("if (frame_ptr->perform_through == %d)", l->id);
4056  if (!cb_flag_computed_goto) {
4057  output_line (" goto P_switch;");
4058  } else {
4059  output_line (" goto *frame_ptr->return_address_ptr;");
4060  }
4061  }
4062 
4063  if (l->flag_fatal_check) {
4064  output_newline ();
4065  output_line ("/* Fatal error if reached */");
4066  output_line ("cob_fatal_error (COB_FERROR_GLOBAL);");
4067  }
4068 }
static void output_newline(void)
Definition: codegen.c:433
unsigned int flag_global
Definition: tree.h:782
static void output_line(const char *fmt,...)
Definition: codegen.c:453
unsigned int flag_fatal_check
Definition: tree.h:786
static struct cb_program * current_prog
Definition: codegen.c:140
unsigned int flag_default_handler
Definition: tree.h:791
unsigned char prog_type
Definition: tree.h:1303
#define CB_PROGRAM_TYPE
Definition: tree.h:41
unsigned int flag_recursive
Definition: tree.h:1308
unsigned int flag_declarative_exit
Definition: tree.h:783
int id
Definition: tree.h:773

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_perform_once ( struct cb_perform p)
static

Definition at line 4189 of file codegen.c.

References cb_perform::body, CB_LABEL, CB_PAIR_P, CB_PAIR_X, CB_PAIR_Y, cb_ref(), cb_perform::cycle_label, output_perform_call(), and output_stmt().

Referenced by output_perform(), and output_perform_until().

4190 {
4191  if (p->body && CB_PAIR_P (p->body)) {
4193  CB_LABEL (cb_ref (CB_PAIR_Y (p->body))));
4194  } else {
4195  output_stmt (p->body);
4196  }
4197  if (p->cycle_label) {
4199  }
4200 }
#define CB_PAIR_X(x)
Definition: tree.h:1205
#define CB_LABEL(x)
Definition: tree.h:801
#define CB_PAIR_P(x)
Definition: tree.h:1204
cb_tree body
Definition: tree.h:1108
cb_tree cb_ref(cb_tree x)
Definition: tree.c:2653
#define CB_PAIR_Y(x)
Definition: tree.h:1206
static void output_perform_call(struct cb_label *lb, struct cb_label *le)
Definition: codegen.c:3905
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
cb_tree cycle_label
Definition: tree.h:1112

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_perform_until ( struct cb_perform p,
cb_tree  l 
)
static

Definition at line 4203 of file codegen.c.

References CB_AFTER, CB_BEFORE, cb_build_debug(), CB_CHAIN, cb_debug_contents, cb_debug_name, CB_FIELD, CB_PERFORM_VARYING, cb_ref(), CB_VALUE, cb_field::debug_section, cb_field::flag_field_debug, cb_program::flag_gen_debug, cb_field::name, NULL, output(), output_cond(), output_cond_debug(), output_indent(), output_line(), output_move(), output_perform_call(), output_perform_once(), output_prefix(), output_stmt(), cb_perform_varying::step, cb_perform::test, and cb_perform_varying::until.

Referenced by output_perform().

4204 {
4205  struct cb_perform_varying *v;
4206  struct cb_field *f;
4207  cb_tree next;
4208 
4209  if (l == NULL) {
4210  /* Perform body at the end */
4211  output_perform_once (p);
4212  return;
4213  }
4214 
4215  v = CB_PERFORM_VARYING (CB_VALUE (l));
4216  next = CB_CHAIN (l);
4217 
4218  output_line ("for (;;)");
4219  output_indent ("{");
4220 
4221  if (next && CB_PERFORM_VARYING (CB_VALUE (next))->name) {
4222  output_move (CB_PERFORM_VARYING (CB_VALUE (next))->from,
4223  CB_PERFORM_VARYING (CB_VALUE (next))->name);
4224  /* DEBUG */
4226  f = CB_FIELD (cb_ref (CB_PERFORM_VARYING (CB_VALUE (next))->name));
4227  if (f->flag_field_debug) {
4229  (const char *)f->name, NULL));
4231  NULL, CB_PERFORM_VARYING (CB_VALUE (next))->name));
4233  f->debug_section);
4234  }
4235  }
4236 
4237  }
4238 
4239  if (p->test == CB_AFTER) {
4240  output_perform_until (p, next);
4241  }
4242 
4243  /* DEBUG */
4245  output_cond_debug (v->until);
4246  }
4247 
4248  output_prefix ();
4249  output ("if (");
4250  output_cond (v->until, 0);
4251  output (")\n");
4252  output_line (" break;");
4253 
4254  if (p->test == CB_BEFORE) {
4255  output_perform_until (p, next);
4256  }
4257 
4258  if (v->step) {
4259  output_stmt (v->step);
4260  }
4261 
4262  output_indent ("}");
4263 }
const char * name
Definition: tree.h:645
static void output_perform_once(struct cb_perform *p)
Definition: codegen.c:4189
unsigned int flag_gen_debug
Definition: tree.h:1321
struct cb_label * debug_section
Definition: tree.h:661
cb_tree step
Definition: tree.h:1101
static void output(const char *,...)
Definition: codegen.c:192
static void output_line(const char *fmt,...)
Definition: codegen.c:453
cb_tree cb_ref(cb_tree x)
Definition: tree.c:2653
unsigned int flag_field_debug
Definition: tree.h:733
#define CB_PERFORM_VARYING(x)
Definition: tree.h:1116
static void output_prefix(void)
Definition: codegen.c:441
#define CB_VALUE(x)
Definition: tree.h:1193
static struct cb_program * current_prog
Definition: codegen.c:140
static void output_cond(cb_tree x, const int save_flag)
Definition: codegen.c:2121
Definition: tree.h:643
#define CB_CHAIN(x)
Definition: tree.h:1194
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
cb_tree cb_debug_name
Definition: typeck.c:84
#define CB_BEFORE
Definition: tree.h:25
static void output_perform_call(struct cb_label *lb, struct cb_label *le)
Definition: codegen.c:3905
cb_tree test
Definition: tree.h:1107
#define CB_AFTER
Definition: tree.h:26
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
cb_tree cb_build_debug(const cb_tree target, const char *str, const cb_tree fld)
Definition: tree.c:1566
static void output_perform_until(struct cb_perform *p, cb_tree l)
Definition: codegen.c:4203
static void output_move(cb_tree src, cb_tree dst)
Definition: codegen.c:2235
cb_tree until
Definition: tree.h:1102
cb_tree cb_debug_contents
Definition: typeck.c:88
static void output_cond_debug(cb_tree x)
Definition: codegen.c:4138
#define CB_FIELD(x)
Definition: tree.h:740
static void output_indent(const char *str)
Definition: codegen.c:467

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_screen_definition ( struct cb_field p)
static

Definition at line 5354 of file codegen.c.

References cb_field::children, COB_SCREEN_TYPE_ATTRIBUTE, COB_SCREEN_TYPE_FIELD, COB_SCREEN_TYPE_GROUP, COB_SCREEN_TYPE_VALUE, cb_field::count, cb_field::id, output_local(), cb_field::sister, cb_field::size, and cb_field::values.

Referenced by output_internal_function().

5355 {
5356  int type;
5357 
5358  if (p->sister) {
5360  }
5361  if (p->children) {
5363  }
5364 
5365  type = (p->children ? COB_SCREEN_TYPE_GROUP :
5368  if (type == COB_SCREEN_TYPE_FIELD || type == COB_SCREEN_TYPE_VALUE) {
5369  p->count++;
5370  }
5371 
5372  output_local ("static cob_screen\ts_%d;\n", p->id);
5373 }
#define COB_SCREEN_TYPE_VALUE
Definition: common.h:929
#define COB_SCREEN_TYPE_FIELD
Definition: common.h:928
struct cb_field * sister
Definition: tree.h:653
struct cb_field * children
Definition: tree.h:652
static void output_local(const char *fmt,...)
Definition: codegen.c:527
static void output_screen_definition(struct cb_field *p)
Definition: codegen.c:5354
int id
Definition: tree.h:671
int count
Definition: tree.h:680
#define COB_SCREEN_TYPE_ATTRIBUTE
Definition: common.h:930
int size
Definition: tree.h:672
#define COB_SCREEN_TYPE_GROUP
Definition: common.h:927
cb_tree values
Definition: tree.h:648

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_screen_init ( struct cb_field p,
struct cb_field previous 
)
static

Definition at line 5376 of file codegen.c.

References cb_build_field_reference(), cb_field::children, COB_SCREEN_TYPE_ATTRIBUTE, COB_SCREEN_TYPE_FIELD, COB_SCREEN_TYPE_GROUP, COB_SCREEN_TYPE_VALUE, cb_field::id, cb_field::level, NULL, cb_field::occurs_min, output(), output_newline(), output_param(), output_prefix(), cb_field::parent, cb_field::screen_backg, cb_field::screen_column, cb_field::screen_flag, cb_field::screen_foreg, cb_field::screen_line, cb_field::screen_prompt, cb_field::sister, cb_field::size, and cb_field::values.

Referenced by output_internal_function().

5377 {
5378  int type;
5379 
5380  type = (p->children ? COB_SCREEN_TYPE_GROUP :
5383  output_prefix ();
5384  output ("cob_set_screen (&s_%d, ", p->id);
5385 
5386  if (p->sister && p->sister->level != 1) {
5387  output ("&s_%d, ", p->sister->id);
5388  } else {
5389  output ("NULL, ");
5390  }
5391 
5392  if (previous && previous->level != 1) {
5393  output ("&s_%d, ", previous->id);
5394  } else {
5395  output ("NULL, ");
5396  }
5397 
5398  output_newline ();
5399  output_prefix ();
5400  output ("\t\t ");
5401 
5402  if (type == COB_SCREEN_TYPE_GROUP) {
5403  output ("&s_%d, ", p->children->id);
5404  } else {
5405  output ("NULL, ");
5406  }
5407 
5408  if (p->parent) {
5409  output ("&s_%d, ", p->parent->id);
5410  } else {
5411  output ("NULL, ");
5412  }
5413 
5414  if (type == COB_SCREEN_TYPE_FIELD) {
5416  output (", ");
5417  } else {
5418  output ("NULL, ");
5419  }
5420 
5421  output_newline ();
5422  output_prefix ();
5423  output ("\t\t ");
5424 
5425  if (type == COB_SCREEN_TYPE_VALUE) {
5426  /* Need a field reference here */
5428  output (", ");
5429  } else {
5430  output ("NULL, ");
5431  }
5432 
5433  if (p->screen_line) {
5434  output_param (p->screen_line, 0);
5435  output (", ");
5436  } else {
5437  output ("NULL, ");
5438  }
5439 
5440  if (p->screen_column) {
5441  output_param (p->screen_column, 0);
5442  output (", ");
5443  } else {
5444  output ("NULL, ");
5445  }
5446 
5447  output_newline ();
5448  output_prefix ();
5449  output ("\t\t ");
5450 
5451  if (p->screen_foreg) {
5452  output_param (p->screen_foreg, 0);
5453  output (", ");
5454  } else {
5455  output ("NULL, ");
5456  }
5457 
5458  if (p->screen_backg) {
5459  output_param (p->screen_backg, 0);
5460  output (", ");
5461  } else {
5462  output ("NULL, ");
5463  }
5464 
5465  if (p->screen_prompt) {
5466  output_param (p->screen_prompt, 0);
5467  output (", ");
5468  } else {
5469  output ("NULL, ");
5470  }
5471 
5472  output_newline ();
5473  output_prefix ();
5474  output ("\t\t ");
5475 
5476  output ("%d, %d, 0x%x);\n", type, p->occurs_min, p->screen_flag);
5477 
5478  if (p->children) {
5480  }
5481  if (p->sister) {
5482  output_screen_init (p->sister, p);
5483  }
5484 }
static void output_newline(void)
Definition: codegen.c:433
#define COB_SCREEN_TYPE_VALUE
Definition: common.h:929
#define COB_SCREEN_TYPE_FIELD
Definition: common.h:928
struct cb_field * sister
Definition: tree.h:653
static void output(const char *,...)
Definition: codegen.c:192
cb_tree screen_backg
Definition: tree.h:668
struct cb_field * children
Definition: tree.h:652
int occurs_min
Definition: tree.h:676
cb_tree cb_build_field_reference(struct cb_field *f, cb_tree ref)
Definition: tree.c:2604
int level
Definition: tree.h:673
static void output_prefix(void)
Definition: codegen.c:441
int id
Definition: tree.h:671
cb_tree screen_column
Definition: tree.h:664
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
int screen_flag
Definition: tree.h:684
#define COB_SCREEN_TYPE_ATTRIBUTE
Definition: common.h:930
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
int size
Definition: tree.h:672
struct cb_field * parent
Definition: tree.h:651
cb_tree screen_prompt
Definition: tree.h:669
cb_tree screen_line
Definition: tree.h:663
static void output_screen_init(struct cb_field *p, struct cb_field *previous)
Definition: codegen.c:5376
#define COB_SCREEN_TYPE_GROUP
Definition: common.h:927
cb_tree values
Definition: tree.h:648
cb_tree screen_foreg
Definition: tree.h:667

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_search ( struct cb_search p)
static

Definition at line 3033 of file codegen.c.

References CB_IF, cb_search::end_stmt, cb_search::flag_all, output_search_all(), output_search_whens(), cb_search::table, cb_search::var, and cb_search::whens.

Referenced by output_stmt().

3034 {
3035  if (p->flag_all) {
3037  CB_IF (p->whens)->test, CB_IF (p->whens)->stmt1);
3038  } else {
3039  output_search_whens (p->table, p->var, p->end_stmt, p->whens);
3040  }
3041 }
cb_tree end_stmt
Definition: tree.h:1026
int flag_all
Definition: tree.h:1028
static void output_search_whens(cb_tree table, cb_tree var, cb_tree stmt, cb_tree whens)
Definition: codegen.c:2906
cb_tree table
Definition: tree.h:1024
cb_tree var
Definition: tree.h:1025
cb_tree whens
Definition: tree.h:1027
#define CB_IF(x)
Definition: tree.h:1092
static void output_search_all(cb_tree table, cb_tree stmt, cb_tree cond, cb_tree when)
Definition: codegen.c:2971

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_search_all ( cb_tree  table,
cb_tree  stmt,
cb_tree  cond,
cb_tree  when 
)
static

Definition at line 2971 of file codegen.c.

References CB_VALUE, cb_field::index_list, cb_field::occurs_min, output(), output_cond(), output_indent(), output_integer(), output_line(), output_newline(), output_occurs(), output_prefix(), and output_stmt().

Referenced by output_search().

2972 {
2973  struct cb_field *p;
2974  cb_tree idx;
2975 
2976  p = cb_code_field (table);
2977  idx = CB_VALUE (p->index_list);
2978  /* Header */
2979  output_indent ("{");
2980  output_line ("int ret;");
2981  output_line ("int head = %d - 1;", p->occurs_min);
2982  output_prefix ();
2983  output ("int tail = ");
2984  output_occurs (p);
2985  output (" + 1;\n");
2986 
2987  /* Start loop */
2988  output_line ("for (;;)");
2989  output_indent ("{");
2990 
2991  /* End test */
2992  output_line ("if (head >= tail - 1)");
2993  output_indent ("{");
2994  output_line ("/* Table end */");
2995  if (stmt) {
2996  output_stmt (stmt);
2997  } else {
2998  output_line ("break;");
2999  }
3000  output_indent ("}");
3001 
3002  /* Next index */
3003  output_prefix ();
3004  output_integer (idx);
3005  output (" = (head + tail) / 2;\n");
3006  output_newline ();
3007 
3008  /* WHEN test */
3009  output_line ("/* WHEN */");
3010  output_prefix ();
3011  output ("if (");
3012  output_cond (cond, 1);
3013  output (")\n");
3014  output_indent ("{");
3015  output_stmt (when);
3016  output_indent ("}");
3017 
3018  output_line ("if (ret < 0)");
3019  output_prefix ();
3020  output (" head = ");
3021  output_integer (idx);
3022  output (";\n");
3023  output_line ("else");
3024  output_prefix ();
3025  output (" tail = ");
3026  output_integer (idx);
3027  output (";\n");
3028  output_indent ("}");
3029  output_indent ("}");
3030 }
static void output_newline(void)
Definition: codegen.c:433
static void output(const char *,...)
Definition: codegen.c:192
int occurs_min
Definition: tree.h:676
static void output_line(const char *fmt,...)
Definition: codegen.c:453
static void output_prefix(void)
Definition: codegen.c:441
#define CB_VALUE(x)
Definition: tree.h:1193
static void output_cond(cb_tree x, const int save_flag)
Definition: codegen.c:2121
Definition: tree.h:643
static void output_occurs(struct cb_field *p)
Definition: codegen.c:2896
cb_tree index_list
Definition: tree.h:650
static void output_integer(cb_tree x)
Definition: codegen.c:1101
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
static void output_indent(const char *str)
Definition: codegen.c:467

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_search_whens ( cb_tree  table,
cb_tree  var,
cb_tree  stmt,
cb_tree  whens 
)
static

Definition at line 2906 of file codegen.c.

References _, CB_CHAIN, cb_ref(), CB_VALUE, COBC_ABORT, cobc_abort_pr(), cb_field::index_list, NULL, output(), output_indent(), output_indent_level, output_integer(), output_line(), output_move(), output_newline(), output_occurs(), output_prefix(), and output_stmt().

Referenced by output_search().

2907 {
2908  cb_tree l;
2909  struct cb_field *p;
2910  cb_tree idx;
2911 
2912  idx = NULL;
2913  p = cb_code_field (table);
2914 
2915  if (!p->index_list) {
2916  cobc_abort_pr (_("Call to '%s' with invalid parameter '%s'"),
2917  "output_search", "table");
2918  COBC_ABORT ();
2919  }
2920 
2921  /* Determine the index to use */
2922  if (var) {
2923  for (l = p->index_list; l; l = CB_CHAIN (l)) {
2924  if (cb_ref (CB_VALUE (l)) == cb_ref (var)) {
2925  idx = var;
2926  }
2927  }
2928  }
2929  if (!idx) {
2930  idx = CB_VALUE (p->index_list);
2931  }
2932 
2933  /* Start loop */
2934  output_line ("for (;;) {");
2935  output_indent_level += 2;
2936 
2937  /* End test */
2938  output_prefix ();
2939  output ("if (");
2940  output_integer (idx);
2941  output (" > ");
2942  output_occurs (p);
2943  output (")\n");
2944  output_indent ("{");
2945  output_line ("/* Table end */");
2946  if (stmt) {
2947  output_stmt (stmt);
2948  } else {
2949  output_line ("break;");
2950  }
2951  output_indent ("}");
2952 
2953  /* WHEN test */
2954  output_stmt (whens);
2955 
2956  /* Iteration */
2957  output_newline ();
2958  output_prefix ();
2959  output_integer (idx);
2960  output ("++;\n");
2961  if (var && var != idx) {
2962  output_move (idx, var);
2963  }
2964  output_line ("/* Iterate */");
2965  /* End loop */
2966  output_indent_level -= 2;
2967  output_line ("}");
2968 }
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
static void output_newline(void)
Definition: codegen.c:433
static void output(const char *,...)
Definition: codegen.c:192
static void output_line(const char *fmt,...)
Definition: codegen.c:453
cb_tree cb_ref(cb_tree x)
Definition: tree.c:2653
static void output_prefix(void)
Definition: codegen.c:441
#define CB_VALUE(x)
Definition: tree.h:1193
#define _(s)
Definition: cobcrun.c:59
Definition: tree.h:643
#define CB_CHAIN(x)
Definition: tree.h:1194
static void output_occurs(struct cb_field *p)
Definition: codegen.c:2896
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define COBC_ABORT()
Definition: cobc.h:61
cb_tree index_list
Definition: tree.h:650
static void output_integer(cb_tree x)
Definition: codegen.c:1101
static int output_indent_level
Definition: codegen.c:171
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
static void output_move(cb_tree src, cb_tree dst)
Definition: codegen.c:2235
static void output_indent(const char *str)
Definition: codegen.c:467

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_section_info ( struct cb_label lp)
static

Definition at line 4525 of file codegen.c.

References CB_PREFIX_STRING, cb_standard_error_handler, CB_TREE, cb_label::flag_dummy_exit, cb_label::flag_dummy_paragraph, cb_label::flag_dummy_section, cb_label::flag_entry, cb_label::flag_section, lookup_string(), cb_label::orig_name, output_line(), and string_buffer.

Referenced by output_stmt().

4526 {
4527  if (CB_TREE (lp) == cb_standard_error_handler) {
4528  return;
4529  }
4530  if (lp->flag_dummy_exit) {
4531  return;
4532  }
4533  if (lp->flag_section) {
4534  if (!lp->flag_dummy_section) {
4535  sprintf (string_buffer, "Section: %s", lp->orig_name);
4536  } else {
4537  sprintf (string_buffer, "Section: (None)");
4538  }
4539  } else if (lp->flag_entry) {
4540  sprintf (string_buffer, "Entry: %s", lp->orig_name);
4541  } else {
4542  if (!lp->flag_dummy_paragraph) {
4543  sprintf (string_buffer, "Paragraph: %s", lp->orig_name);
4544  } else {
4545  sprintf (string_buffer, "Paragraph: (None)");
4546  }
4547  }
4548  if (CB_TREE (lp)->source_file) {
4549  output_line ("cob_trace_section (%s%d, %s%d, %d);",
4553  lookup_string (CB_TREE (lp)->source_file),
4554  CB_TREE (lp)->source_line);
4555  } else {
4556  output_line ("cob_trace_section (%s%d, NULL, %d);",
4559  CB_TREE (lp)->source_line);
4560  }
4561 }
const char * orig_name
Definition: tree.h:767
#define CB_TREE(x)
Definition: tree.h:440
#define CB_PREFIX_STRING
Definition: tree.h:39
static int lookup_string(const char *p)
Definition: codegen.c:219
static void output_line(const char *fmt,...)
Definition: codegen.c:453
unsigned int flag_dummy_paragraph
Definition: tree.h:788
unsigned int flag_section
Definition: tree.h:777
cb_tree cb_standard_error_handler
Definition: tree.c:144
unsigned int flag_entry
Definition: tree.h:778
unsigned int flag_dummy_exit
Definition: tree.h:789
unsigned int flag_dummy_section
Definition: tree.h:787
static char * string_buffer
Definition: codegen.c:131

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_set_attribute ( const struct cb_field f,
int  val_on,
int  val_off 
)
static

Definition at line 3837 of file codegen.c.

References COB_SCREEN_HIGHLIGHT, COB_SCREEN_LOWLIGHT, cb_field::id, and output_line().

Referenced by output_stmt().

3838 {
3839  /* Extension */
3840  /* Prevent specifying HIGHLIGHT and LOWLIGHT simultaneously. */
3841  if (val_on & COB_SCREEN_HIGHLIGHT) {
3842  val_off |= COB_SCREEN_LOWLIGHT;
3843  } else if (val_on & COB_SCREEN_LOWLIGHT) {
3844  val_off |= COB_SCREEN_HIGHLIGHT;
3845  }
3846 
3847  if (val_on) {
3848  output_line ("s_%d.attr |= 0x%x;", f->id, val_on);
3849  }
3850  if (val_off) {
3851  output_line ("s_%d.attr &= ~0x%x;", f->id, val_off);
3852  }
3853 }
static void output_line(const char *fmt,...)
Definition: codegen.c:453
int id
Definition: tree.h:671
#define COB_SCREEN_LOWLIGHT
Definition: common.h:908
#define COB_SCREEN_HIGHLIGHT
Definition: common.h:907

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_size ( const cb_tree  x)
static

Definition at line 793 of file codegen.c.

References _, CB_FIELD, cb_field_subordinate(), CB_LITERAL, CB_PREFIX_FIELD, CB_REFERENCE, CB_TAG_CONST, CB_TAG_FIELD, CB_TAG_LITERAL, CB_TAG_REFERENCE, CB_TREE_TAG, chk_field_variable_size(), COBC_ABORT, cobc_abort_pr(), cb_field::depending, cb_field::flag_any_length, cb_field::flag_no_field, cb_field::flag_odo_relative, cb_reference::flag_receiving, cb_field::id, cb_reference::length, cb_field::occurs_max, cb_field::odo_level, cb_field::offset, cb_reference::offset, output(), output_index(), output_integer(), cb_field::parent, cb_field::redefines, cb_literal::sign, cb_field::sister, cb_literal::size, cb_field::size, and cb_reference::value.

Referenced by codegen(), output_call(), output_field(), output_figurative(), output_initialize_literal(), output_initialize_uniform(), output_internal_function(), and output_param().

794 {
795  struct cb_literal *l;
796  struct cb_reference *r;
797  struct cb_field *f;
798  struct cb_field *p;
799  struct cb_field *q;
800 
801  switch (CB_TREE_TAG (x)) {
802  case CB_TAG_CONST:
803  output ("1");
804  break;
805  case CB_TAG_LITERAL:
806  l = CB_LITERAL (x);
807  output ("%d", (int)(l->size + ((l->sign != 0) ? 1 : 0)));
808  break;
809  case CB_TAG_REFERENCE:
810  r = CB_REFERENCE (x);
811  f = CB_FIELD (r->value);
812  if (f->flag_no_field) {
813  output ("0");
814  break;
815  }
816  if (r->length) {
817  output_integer (r->length);
818  } else if (r->offset && f->flag_any_length) {
819  output ("%s%d.size - ", CB_PREFIX_FIELD, f->id);
820  output_index (r->offset);
821  } else {
822  p = chk_field_variable_size (f);
823  q = f;
824 again:
825  if (!cb_flag_odoslide && p && p->flag_odo_relative) {
826  q = p;
827  output ("%d", p->size * p->occurs_max);
828  } else if (p && (!r->flag_receiving ||
829  !cb_field_subordinate (cb_code_field (p->depending),
830  q))) {
831  if (p->offset - q->offset > 0) {
832  output ("%d + ", p->offset - q->offset);
833  }
834  if (p->size != 1) {
835 #if 0 /* draft from Simon -
836  works only if the ODOs are directly nested and
837  have no "sister" elements,
838  the content would only be correct if -fodoslide
839  is active as we need a temporary field otherwise */
840  /* size for nested ODO */
841  if (p->odo_level > 1) {
843  output (" * ");
844  p = q;
845  goto again;
846  }
847 #endif
848  output ("%d * ", p->size);
849  }
851  q = p;
852  } else {
853  output ("%d", q->size);
854  }
855 
856  for (; q != f; q = q->parent) {
857  if (q->sister && !q->sister->redefines) {
858  q = q->sister;
859  p = q->depending ? q : chk_field_variable_size (q);
860  output (" + ");
861  goto again;
862  }
863  }
864  if (r->offset) {
865  output (" - ");
866  output_index (r->offset);
867  }
868  }
869  break;
870  case CB_TAG_FIELD:
871  output ("(int)%s%d.size", CB_PREFIX_FIELD, CB_FIELD (x)->id);
872  break;
873  default:
874  cobc_abort_pr (_("Unexpected tree tag %d"), (int)CB_TREE_TAG (x));
875  COBC_ABORT ();
876  }
877 }
int cb_field_subordinate(const struct cb_field *pfld, const struct cb_field *f)
Definition: tree.c:2274
static struct cb_field * chk_field_variable_size(struct cb_field *f)
Definition: codegen.c:556
int occurs_max
Definition: tree.h:677
short sign
Definition: tree.h:597
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
unsigned int odo_level
Definition: tree.h:687
unsigned int flag_any_length
Definition: tree.h:712
struct cb_field * sister
Definition: tree.h:653
static void output(const char *,...)
Definition: codegen.c:192
#define CB_LITERAL(x)
Definition: tree.h:601
unsigned int flag_odo_relative
Definition: tree.h:731
cb_tree value
Definition: tree.h:876
static void output_index(cb_tree x)
Definition: codegen.c:1608
unsigned int flag_no_field
Definition: tree.h:735
int id
Definition: tree.h:671
cb_tree depending
Definition: tree.h:647
int offset
Definition: tree.h:675
#define _(s)
Definition: cobcrun.c:59
Definition: tree.h:643
#define CB_TREE_TAG(x)
Definition: tree.h:441
cb_tree offset
Definition: tree.h:878
#define COBC_ABORT()
Definition: cobc.h:61
#define CB_REFERENCE(x)
Definition: tree.h:901
int size
Definition: tree.h:672
struct cb_field * parent
Definition: tree.h:651
unsigned int flag_receiving
Definition: tree.h:887
static void output_integer(cb_tree x)
Definition: codegen.c:1101
cb_tree length
Definition: tree.h:879
struct cb_field * redefines
Definition: tree.h:654
cob_u32_t size
Definition: tree.h:594
#define CB_PREFIX_FIELD
Definition: tree.h:34
#define CB_FIELD(x)
Definition: tree.h:740

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_stmt ( cb_tree  x)
static

Definition at line 4660 of file codegen.c.

References _, cb_program::all_procedure, cb_statement::body, cb_cast::cast_type, CB_ALTER, CB_ASSIGN, cb_build_debug(), CB_CALL, CB_CANCEL, CB_CAST, CB_CAST_ADDRESS, CB_CAST_PROGRAM_POINTER, CB_CHAIN, CB_CLASS_POINTER, CB_DEBUG, CB_DEBUG_CALL, cb_debug_contents, cb_debug_line, cb_debug_name, CB_DIRECT, cb_error_node, CB_EXCEPTION_CODE, CB_EXCEPTION_ENABLE, CB_FILE, CB_GOTO, cb_id, CB_IF, CB_INITIALIZE, CB_LABEL, cb_null, CB_PERFORM, CB_PREFIX_LABEL, CB_PREFIX_STRING, CB_REFERENCE, CB_SEARCH, CB_SET_ATTR, cb_space, CB_STATEMENT, CB_TAG_ALTER, CB_TAG_ASSIGN, CB_TAG_CALL, CB_TAG_CANCEL, CB_TAG_CAST, CB_TAG_CONTINUE, CB_TAG_DEBUG, CB_TAG_DEBUG_CALL, CB_TAG_DIRECT, CB_TAG_FUNCALL, CB_TAG_GOTO, CB_TAG_IF, CB_TAG_INITIALIZE, CB_TAG_LABEL, CB_TAG_LIST, CB_TAG_PERFORM, CB_TAG_REFERENCE, CB_TAG_SEARCH, CB_TAG_SET_ATTR, CB_TAG_STATEMENT, CB_TREE_CLASS, CB_TREE_TAG, CB_VALUE, cb_zero, COB_EC_I_O, COBC_ABORT, cobc_abort_pr(), cb_statement::debug_check, cb_label::debug_section, cb_label::exit_label, cb_statement::file, cb_label::flag_alter, cb_label::flag_begin, cb_statement::flag_callback, cb_program::flag_debugging, cb_label::flag_debugging_mode, cb_program::flag_gen_debug, cb_statement::flag_in_debug, cb_label::flag_is_debug_sect, cb_label::flag_real_label, cb_label::flag_section, cb_label::flag_skip_label, cb_set_attr::fld, gen_if_level, gen_nested_tab, cb_statement::handler1, cb_statement::handler2, cb_statement::handler_id, cb_label::id, inside_check, inside_stack, cb_if::is_if, last_line, last_segment, line, lookup_string(), cb_label::name, cb_statement::name, need_save_exception, cb_program::nested_prog_list, cb_para_label::next, NULL, cb_statement::null_check, output(), output_alter(), output_alter_check(), output_call(), output_cancel(), output_cond(), output_data(), output_ferror_stmt(), output_funcall(), output_goto(), output_indent(), output_indent_level, output_initialize(), output_integer(), output_label_info(), output_line(), output_move(), output_newline(), output_param(), output_perform(), output_perform_call(), output_prefix(), output_search(), output_section_info(), output_set_attribute(), output_trace_info(), cb_para_label::para, cb_label::para_label, cb_label::segment, cb_tree_common::source_file, cb_tree_common::source_line, stack_id, cb_if::stmt1, cb_if::stmt2, cb_if::test, unlikely, cb_cast::val, cb_assign::val, cb_set_attr::val_off, cb_set_attr::val_on, value, and cb_assign::var.

Referenced by output_alter(), output_call(), output_cond(), output_cond_debug(), output_error_handler(), output_ferror_stmt(), output_file_error(), output_funcall_debug(), output_goto(), output_goto_1(), output_initial_values(), output_internal_function(), output_move(), output_param(), output_perform(), output_perform_call(), output_perform_once(), output_perform_until(), output_search_all(), and output_search_whens().

4661 {
4662  struct cb_statement *p;
4663  struct cb_label *lp;
4664  struct cb_assign *ap;
4665  struct cb_if *ip;
4666  struct cb_para_label *pal;
4667  struct cb_set_attr *sap;
4668 #ifdef COB_NON_ALIGNED
4669  struct cb_cast *cp;
4670 #endif
4671  size_t size;
4672  int code;
4673 
4674  stack_id = 0;
4675  if (x == NULL) {
4676  output_line (";");
4677  return;
4678  }
4679  if (unlikely(x == cb_error_node)) {
4680  cobc_abort_pr (_("Unexpected error_node parameter"));
4681  COBC_ABORT ();
4682  }
4683 
4684  if (inside_check != 0) {
4685  if (inside_stack[inside_check - 1] != 0) {
4686  inside_stack[inside_check - 1] = 0;
4687  output (",\n");
4688  }
4689  }
4690 
4691  switch (CB_TREE_TAG (x)) {
4692  case CB_TAG_STATEMENT:
4693  p = CB_STATEMENT (x);
4694  /* Output source location as a comment */
4695  if (p->name) {
4696  output_newline ();
4697  output_line ("/* Line: %-10d: %-19.19s: %s */",
4698  x->source_line, p->name, x->source_file);
4699  }
4700  if (x->source_file) {
4701  if (cb_flag_source_location) {
4702  /* Output source location as code */
4703  output_trace_info (x, p);
4704  }
4706  !p->flag_in_debug) {
4707  output_prefix ();
4708  output ("memcpy (");
4710  output (", \"%6d\", 6);\n", x->source_line);
4711  }
4712  last_line = x->source_line;
4713  }
4714 
4715 #if 0 /* RXWRXW - Exception */
4716  if (p->handler1 || p->handler2 ||
4717  (p->file && CB_EXCEPTION_ENABLE (COB_EC_I_O))) {
4718 #else
4719  if (!p->file && (p->handler1 || p->handler2)) {
4720 #endif
4721  output_line ("cob_glob_ptr->cob_exception_code = 0;");
4722  }
4723 
4724  if (p->null_check) {
4725  output_stmt (p->null_check);
4726  }
4727 
4728  if (p->body) {
4729  output_stmt (p->body);
4730  }
4731 
4732  /* Output field debugging statements */
4734  output_stmt (p->debug_check);
4735  }
4736 
4737  /* Special debugging callback for START / DELETE */
4738  /* Must be done immediately after I/O and before */
4739  /* status check */
4740  if (current_prog->flag_gen_debug && p->file && p->flag_callback) {
4741  output_line ("save_exception_code = cob_glob_ptr->cob_exception_code;");
4743  CB_FILE(p->file)->name, NULL));
4745  output_perform_call (CB_FILE(p->file)->debug_section,
4746  CB_FILE(p->file)->debug_section);
4747  output_line ("cob_glob_ptr->cob_exception_code = save_exception_code;");
4748  need_save_exception = 1;
4749  }
4750 
4751  if (p->handler1 || p->handler2 ||
4752  (p->file && CB_EXCEPTION_ENABLE (COB_EC_I_O))) {
4753  code = CB_EXCEPTION_CODE (p->handler_id);
4754  if (p->file) {
4755  output_ferror_stmt (p, code);
4756  } else {
4757  if (p->handler1) {
4758  if ((code & 0x00ff) == 0) {
4759  output_line ("if (unlikely((cob_glob_ptr->cob_exception_code & 0xff00) == 0x%04x))",
4760  code);
4761  } else {
4762  output_line ("if (unlikely(cob_glob_ptr->cob_exception_code == 0x%04x))", code);
4763  }
4764  output_indent ("{");
4765  output_stmt (p->handler1);
4766  output_indent ("}");
4767  if (p->handler2) {
4768  output_line ("else");
4769  }
4770  }
4771  if (p->handler2) {
4772  if (p->handler1 == NULL) {
4773  output_line ("if (!cob_glob_ptr->cob_exception_code)");
4774  }
4775  output_indent ("{");
4776  output_stmt (p->handler2);
4777  output_indent ("}");
4778  }
4779  }
4780  }
4781  break;
4782  case CB_TAG_LABEL:
4783  lp = CB_LABEL (x);
4784  if (lp->flag_skip_label) {
4785  break;
4786  }
4787  output_label_info (x, lp);
4788  if (lp->flag_section) {
4789  for (pal = lp->para_label; pal; pal = pal->next) {
4790  if (pal->para->segment > 49 &&
4791  pal->para->flag_alter) {
4792  output_line ("label_%s%d = 0;",
4793  CB_PREFIX_LABEL, pal->para->id);
4794  }
4795  }
4796  last_segment = lp->segment;
4797  last_section = lp;
4798  }
4799  if (lp->flag_begin) {
4800  output_line ("%s%d:;", CB_PREFIX_LABEL, lp->id);
4801  }
4802 
4803  /* Check for runtime debug flag */
4805  output_line ("if (!cob_debugging_mode)");
4806  output_line ("\tgoto %s%d;",
4807  CB_PREFIX_LABEL, CB_LABEL (lp->exit_label)->id);
4808  }
4809 
4810  if (cb_flag_trace) {
4811  output_section_info (lp);
4812  }
4813 
4814  /* Check procedure debugging */
4817  (const char *)lp->name, NULL));
4818  if (current_prog->all_procedure) {
4821  } else if (lp->flag_debugging_mode) {
4823  lp->debug_section);
4824  }
4825  }
4826 
4827  /* Check ALTER processing */
4828  if (lp->flag_alter) {
4829  output_alter_check (lp);
4830  }
4831 
4832  break;
4833  case CB_TAG_FUNCALL:
4834  output_prefix ();
4835  output_funcall (x);
4836  if (inside_check == 0) {
4837  output (";\n");
4838  } else {
4839  inside_stack[inside_check - 1] = 1;
4840  }
4841  break;
4842  case CB_TAG_ASSIGN:
4843  ap = CB_ASSIGN (x);
4844 #ifdef COB_NON_ALIGNED
4845  /* Nonaligned */
4846  if (CB_TREE_CLASS (ap->var) == CB_CLASS_POINTER ||
4847  CB_TREE_CLASS (ap->val) == CB_CLASS_POINTER) {
4848  /* Pointer assignment */
4849  output_indent ("{");
4850  output_line ("void *temp_ptr;");
4851 
4852  /* temp_ptr = source address; */
4853  output_prefix ();
4854  if (ap->val == cb_null || ap->val == cb_zero) {
4855  /* MOVE NULL ... */
4856  output ("temp_ptr = 0;\n");
4857  } else if (CB_TREE_TAG (ap->val) == CB_TAG_CAST) {
4858  /* MOVE ADDRESS OF val ... */
4859  cp = CB_CAST (ap->val);
4860  output ("temp_ptr = ");
4861  switch (cp->cast_type) {
4862  case CB_CAST_ADDRESS:
4863  output_data (cp->val);
4864  break;
4866  output ("cob_call_field (");
4867  output_param (ap->val, -1);
4869  gen_nested_tab = 1;
4870  output (", cob_nest_tab, 0, %d)",
4871  cb_fold_call);
4872  } else {
4873  output (", NULL, 0, %d)",
4874  cb_fold_call);
4875  }
4876  break;
4877  default:
4878  cobc_abort_pr (_("Unexpected cast type %d"),
4879  cp->cast_type);
4880  COBC_ABORT ();
4881  }
4882  output (";\n");
4883  } else {
4884  /* MOVE val ... */
4885  output ("memcpy(&temp_ptr, ");
4886  output_data (ap->val);
4887  output (", sizeof(temp_ptr));\n");
4888  }
4889 
4890  /* Destination address = temp_ptr; */
4891  output_prefix ();
4892  if (CB_TREE_TAG (ap->var) == CB_TAG_CAST) {
4893  /* SET ADDRESS OF var ... */
4894  cp = CB_CAST (ap->var);
4895  if (cp->cast_type != CB_CAST_ADDRESS) {
4896  cobc_abort_pr (_("Unexpected tree type %d"),
4897  cp->cast_type);
4898  COBC_ABORT ();
4899  }
4900  output_data (cp->val);
4901  output (" = temp_ptr;\n");
4902  } else {
4903  /* MOVE ... TO var */
4904  output ("memcpy(");
4905  output_data (ap->var);
4906  output (", &temp_ptr, sizeof(temp_ptr));\n");
4907  }
4908 
4909  output_indent ("}");
4910  } else {
4911  /* Numeric assignment */
4912  output_prefix ();
4913  output_integer (ap->var);
4914  output (" = ");
4915  output_integer (ap->val);
4916  if (inside_check == 0) {
4917  output (";\n");
4918  } else {
4919  inside_stack[inside_check - 1] = 1;
4920  }
4921  }
4922 #else /* Nonaligned */
4923  output_prefix ();
4924  output_integer (ap->var);
4925  output (" = ");
4926  output_integer (ap->val);
4927  if (inside_check == 0) {
4928  output (";\n");
4929  } else {
4930  inside_stack[inside_check - 1] = 1;
4931  }
4932 #endif /* Nonaligned */
4933  break;
4934  case CB_TAG_INITIALIZE:
4936  break;
4937  case CB_TAG_SEARCH:
4938  output_search (CB_SEARCH (x));
4939  break;
4940  case CB_TAG_CALL:
4941  output_call (CB_CALL (x));
4942  break;
4943  case CB_TAG_GOTO:
4944  output_goto (CB_GOTO (x));
4945  break;
4946  case CB_TAG_CANCEL:
4947  output_cancel (CB_CANCEL (x));
4948  break;
4949  case CB_TAG_SET_ATTR:
4950  sap = CB_SET_ATTR (x);
4951  output_set_attribute (sap->fld, sap->val_on, sap->val_off);
4952  break;
4953  case CB_TAG_ALTER:
4954  output_alter (CB_ALTER (x));
4955  break;
4956  case CB_TAG_IF:
4957  ip = CB_IF (x);
4958  if (!ip->is_if) {
4959  output_newline ();
4960  output_line ("/* WHEN */");
4961  output_newline ();
4962  }
4963  gen_if_level++;
4964  code = 0;
4965  output_prefix ();
4966  output ("if (");
4967  output_cond (ip->test, 0);
4968  output (")\n");
4969  output_line ("{");
4970  output_indent_level += 2;
4971  if (ip->stmt1) {
4972  output_stmt (ip->stmt1);
4973  } else {
4974  output_line ("; /* Nothing */");
4975  }
4976  if (gen_if_level > cb_if_cutoff) {
4977  if (ip->stmt2) {
4978  code = cb_id++;
4979  output_line ("goto l_%d;", code);
4980  }
4981  }
4982  output_indent_level -= 2;
4983  output_line ("}");
4984  if (ip->stmt2) {
4985  if (gen_if_level <= cb_if_cutoff) {
4986  output_line ("else");
4987  output_line ("{");
4988  output_indent_level += 2;
4989  }
4990  if (ip->is_if) {
4991  output_line ("/* ELSE */");
4992  } else {
4993  output_line ("/* WHEN */");
4994  }
4995  output_stmt (ip->stmt2);
4996  if (gen_if_level <= cb_if_cutoff) {
4997  output_indent_level -= 2;
4998  output_line ("}");
4999  } else {
5000  output_line ("l_%d:;", code);
5001  }
5002  }
5003  gen_if_level--;
5004  break;
5005  case CB_TAG_PERFORM:
5006  output_perform (CB_PERFORM (x));
5007  break;
5008  case CB_TAG_CONTINUE:
5009  output_prefix ();
5010  output (";\n");
5011  break;
5012  case CB_TAG_LIST:
5013  if (cb_flag_extra_brace) {
5014  output_indent ("{");
5015  }
5016  for (; x; x = CB_CHAIN (x)) {
5017  output_stmt (CB_VALUE (x));
5018  }
5019  if (cb_flag_extra_brace) {
5020  output_indent ("}");
5021  }
5022  break;
5023  case CB_TAG_REFERENCE:
5025  break;
5026  case CB_TAG_DIRECT:
5027  if (CB_DIRECT (x)->flag_is_direct) {
5028  if (CB_DIRECT (x)->flag_new_line) {
5029  output_newline ();
5030  }
5031  output_line ("%s", (const char *)(CB_DIRECT (x)->line));
5032  } else {
5033  output_newline ();
5034  output_line ("/* %s */", (const char *)(CB_DIRECT (x)->line));
5035  }
5036  break;
5037  case CB_TAG_DEBUG:
5038  if (!current_prog->flag_gen_debug) {
5039  break;
5040  }
5041  output_prefix ();
5042  size = cb_code_field (CB_DEBUG(x)->target)->size;
5043  if (CB_DEBUG(x)->value) {
5044  if (size <= CB_DEBUG(x)->size) {
5045  output ("memcpy (");
5046  output_data (CB_DEBUG(x)->target);
5047  output (", %s%d, %d);\n", CB_PREFIX_STRING,
5049  (int)size);
5050  } else {
5051  output ("memcpy (");
5052  output_data (CB_DEBUG(x)->target);
5053  output (", %s%d, %d);\n", CB_PREFIX_STRING,
5055  (int)CB_DEBUG(x)->size);
5056  output_prefix ();
5057  output ("memset (");
5058  output_data (CB_DEBUG(x)->target);
5059  code = (int)(size - CB_DEBUG(x)->size);
5060  output (" + %d, ' ', %d);\n",
5061  (int)CB_DEBUG(x)->size, code);
5062 
5063  }
5064  } else {
5065  if (size <= CB_DEBUG(x)->size) {
5066  output ("memcpy (");
5067  output_data (CB_DEBUG(x)->target);
5068  output (", ");
5069  output_data (CB_DEBUG(x)->fld);
5070  output (", %d);\n", (int)size);
5071  } else {
5072  output ("memcpy (");
5073  output_data (CB_DEBUG(x)->target);
5074  output (", ");
5075  output_data (CB_DEBUG(x)->fld);
5076  output (", %d);\n", (int)CB_DEBUG(x)->size);
5077  output_prefix ();
5078  output ("memset (");
5079  output_data (CB_DEBUG(x)->target);
5080  code = (int)(size - CB_DEBUG(x)->size);
5081  output (" + %d, ' ', %d);\n",
5082  (int)CB_DEBUG(x)->size, code);
5083  }
5084  }
5085  break;
5086  case CB_TAG_DEBUG_CALL:
5087  output_perform_call (CB_DEBUG_CALL(x)->target,
5088  CB_DEBUG_CALL(x)->target);
5089  break;
5090  default:
5091  cobc_abort_pr (_("Unexpected tree tag %d"), (int)CB_TREE_TAG (x));
5092  COBC_ABORT ();
5093  }
5094 }
unsigned int flag_is_debug_sect
Definition: tree.h:797
#define CB_DEBUG_CALL(x)
Definition: tree.h:511
#define CB_LABEL(x)
Definition: tree.h:801
void cobc_abort_pr(const char *fmt,...)
Definition: cobc.c:587
const char * name
Definition: tree.h:766
static void output_newline(void)
Definition: codegen.c:433
cb_tree debug_check
Definition: tree.h:1145
#define CB_PREFIX_STRING
Definition: tree.h:39
static int lookup_string(const char *p)
Definition: codegen.c:219
unsigned int flag_gen_debug
Definition: tree.h:1321
#define CB_SEARCH(x)
Definition: tree.h:1031
static void output(const char *,...)
Definition: codegen.c:192
#define CB_INITIALIZE(x)
Definition: tree.h:1017
#define CB_PREFIX_LABEL
Definition: tree.h:37
static void output_perform(struct cb_perform *p)
Definition: codegen.c:4266
Definition: tree.h:88
static void output_line(const char *fmt,...)
Definition: codegen.c:453
int cb_id
Definition: cobc.c:163
int val_off
Definition: tree.h:1173
#define CB_CAST(x)
Definition: tree.h:962
unsigned int flag_real_label
Definition: tree.h:781
cb_tree exit_label
Definition: tree.h:771
#define CB_ALTER(x)
Definition: tree.h:1068
const char * source_file
Definition: tree.h:431
#define CB_CANCEL(x)
Definition: tree.h:1057
unsigned int is_if
Definition: tree.h:1089
static void output_ferror_stmt(struct cb_statement *p, const int code)
Definition: codegen.c:4489
cb_tree test
Definition: tree.h:1086
cb_tree stmt1
Definition: tree.h:1087
cb_tree cb_zero
Definition: tree.c:125
static void output_section_info(struct cb_label *lp)
Definition: codegen.c:4525
int handler_id
Definition: tree.h:1148
struct cb_para_label * para_label
Definition: tree.h:770
#define CB_SET_ATTR(x)
Definition: tree.h:1176
#define CB_GOTO(x)
Definition: tree.h:1079
static void output_label_info(cb_tree x, struct cb_label *lp)
Definition: codegen.c:4592
cb_tree cb_space
Definition: tree.c:127
#define CB_FILE(x)
Definition: tree.h:858
static void output_funcall(cb_tree x)
Definition: codegen.c:2028
unsigned int flag_debugging
Definition: tree.h:1320
static void output_data(cb_tree x)
Definition: codegen.c:705
static void output_initialize(struct cb_initialize *p)
Definition: codegen.c:2831
static void output_prefix(void)
Definition: codegen.c:441
const char * name
Definition: tree.h:1137
#define CB_VALUE(x)
Definition: tree.h:1193
#define CB_TREE_CLASS(x)
Definition: tree.h:442
static struct cb_program * current_prog
Definition: codegen.c:140
static void output_call(struct cb_call *p)
Definition: codegen.c:3311
#define CB_PERFORM(x)
Definition: tree.h:1118
static int last_line
Definition: codegen.c:165
unsigned int flag_section
Definition: tree.h:777
strict implicit external value
Definition: warning.def:54
unsigned int flag_in_debug
Definition: tree.h:1150
static void output_cond(cb_tree x, const int save_flag)
Definition: codegen.c:2121
int source_line
Definition: tree.h:432
cb_tree val
Definition: tree.h:970
#define _(s)
Definition: cobcrun.c:59
#define unlikely(x)
Definition: common.h:437
#define CB_CHAIN(x)
Definition: tree.h:1194
Definition: tree.h:1084
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define CB_TREE_TAG(x)
Definition: tree.h:441
struct cb_field * fld
Definition: tree.h:1171
#define COBC_ABORT()
Definition: cobc.h:61
cb_tree stmt2
Definition: tree.h:1088
cb_tree cb_debug_name
Definition: typeck.c:84
unsigned int flag_debugging_mode
Definition: tree.h:796
#define CB_STATEMENT(x)
Definition: tree.h:1155
cb_tree cb_debug_line
Definition: typeck.c:83
static void output_trace_info(cb_tree x, struct cb_statement *p)
Definition: codegen.c:4564
#define CB_EXCEPTION_CODE(id)
Definition: cobc.h:242
#define CB_ASSIGN(x)
Definition: tree.h:973
#define CB_REFERENCE(x)
Definition: tree.h:901
Definition: tree.h:956
int val_on
Definition: tree.h:1172
int segment
Definition: tree.h:775
cb_tree file
Definition: tree.h:1140
static int gen_if_level
Definition: codegen.c:173
static void output_param(cb_tree x, int id)
Definition: codegen.c:1628
static void output_goto(struct cb_goto *p)
Definition: codegen.c:4406
static void output_alter(struct cb_alter *p)
Definition: codegen.c:4460
static void output_perform_call(struct cb_label *lb, struct cb_label *le)
Definition: codegen.c:3905
static void output_alter_check(struct cb_label *lp)
Definition: codegen.c:4636
static unsigned int inside_check
Definition: codegen.c:176
cb_tree cb_error_node
Definition: tree.c:140
static unsigned int gen_nested_tab
Definition: codegen.c:149
enum cb_cast_type cast_type
Definition: tree.h:959
struct cb_para_label * next
Definition: tree.h:755
static void output_search(struct cb_search *p)
Definition: codegen.c:3033
if fold fold static computed alternate extra correct stack on syntax debugging line
Definition: flag.def:90
unsigned int flag_alter
Definition: tree.h:795
static struct cb_label * last_section
Definition: codegen.c:142
cb_tree cb_null
Definition: tree.c:124
static unsigned int inside_stack[64]
Definition: codegen.c:177
#define CB_EXCEPTION_ENABLE(id)
Definition: cobc.h:243
#define CB_DIRECT(x)
Definition: tree.h:488
struct nested_list * nested_prog_list
Definition: tree.h:1249
static void output_integer(cb_tree x)
Definition: codegen.c:1101
#define CB_DEBUG(x)
Definition: tree.h:501
static int output_indent_level
Definition: codegen.c:171
static void output_set_attribute(const struct cb_field *f, int val_on, int val_off)
Definition: codegen.c:3837
Definition: tree.h:764
struct cb_label * all_procedure
Definition: tree.h:1289
struct cb_label * para
Definition: tree.h:756
unsigned int flag_callback
Definition: tree.h:1152
static void output_stmt(cb_tree x)
Definition: codegen.c:4660
cb_tree null_check
Definition: tree.h:1144
cb_tree val
Definition: tree.h:958
unsigned int flag_begin
Definition: tree.h:779
cb_tree cb_build_debug(const cb_tree target, const char *str, const cb_tree fld)
Definition: tree.c:1566
unsigned int flag_skip_label
Definition: tree.h:798
cb_tree handler1
Definition: tree.h:1141
static unsigned int need_save_exception
Definition: codegen.c:148
cb_tree var
Definition: tree.h:969
static void output_cancel(struct cb_cancel *p)
Definition: codegen.c:3858
static int stack_id
Definition: codegen.c:159
int id
Definition: tree.h:773
static void output_move(cb_tree src, cb_tree dst)
Definition: codegen.c:2235
#define CB_IF(x)
Definition: tree.h:1092
static int last_segment
Definition: codegen.c:172
cb_tree cb_debug_contents
Definition: typeck.c:88
struct cb_label * debug_section
Definition: tree.h:769
cb_tree body
Definition: tree.h:1139
#define CB_CALL(x)
Definition: tree.h:1047
static void output_indent(const char *str)
Definition: codegen.c:467
cb_tree handler2
Definition: tree.h:1142

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_storage ( const char *  fmt,
  ... 
)
static

Definition at line 515 of file codegen.c.

References cb_storage_file.

Referenced by codegen(), and output_file_allocation().

516 {
517  va_list ap;
518 
519  if (cb_storage_file) {
520  va_start (ap, fmt);
521  vfprintf (cb_storage_file, fmt, ap);
522  va_end (ap);
523  }
524 }
FILE * cb_storage_file
Definition: cobc.c:156

Here is the caller graph for this function:

static void output_string ( const unsigned char *  s,
const int  size,
const cob_u32_t  llit 
)
static

Definition at line 489 of file codegen.c.

References output().

Referenced by codegen(), output_call(), output_cancel(), output_data(), output_initialize_literal(), output_initialize_one(), and output_param().

490 {
491  int i;
492  int c;
493 
494  if (!s) {
495  output ("NULL");
496  return;
497  }
498  output ("\"");
499  for (i = 0; i < size; i++) {
500  c = s[i];
501  if (!isprint (c)) {
502  output ("\\%03o", c);
503  } else if (c == '\"') {
504  output ("\\%c", c);
505  } else if ((c == '\\' || c == '?') && !llit) {
506  output ("\\%c", c);
507  } else {
508  output ("%c", c);
509  }
510  }
511  output ("\"");
512 }
static void output(const char *,...)
Definition: codegen.c:192

Here is the call graph for this function:

Here is the caller graph for this function:

static void output_trace_info ( cb_tree  x,
struct cb_statement p 
)
static

Definition at line 4564 of file codegen.c.

References CB_PREFIX_STRING, excp_current_paragraph, excp_current_section, lookup_string(), cb_statement::name, output(), output_prefix(), cb_tree_common::source_file, and cb_tree_common::source_line.

Referenced by output_stmt().

4565 {
4566  output_prefix ();
4567  output ("cob_set_location (%s%d, %d, ",
4570  x->source_line);
4571  if (excp_current_section) {
4572  output ("%s%d, ",
4574  } else {
4575  output ("NULL, ");
4576  }
4577  if (excp_current_paragraph) {
4578  output ("%s%d, ",
4580  } else {
4581  output ("NULL, ");
4582  }
4583  if (p->name) {
4584  output ("%s%d);\n",
4586  } else {
4587  output ("NULL);\n");
4588  }
4589 }
#define CB_PREFIX_STRING
Definition: tree.h:39
static int lookup_string(const char *p)
Definition: codegen.c:219
static void output(const char *,...)
Definition: codegen.c:192
static const char * excp_current_paragraph
Definition: codegen.c:139
const char * source_file
Definition: tree.h:431
static void output_prefix(void)
Definition: codegen.c:441
const char * name
Definition: tree.h:1137
int source_line
Definition: tree.h:432
static const char * excp_current_section
Definition: codegen.c:138

Here is the call graph for this function:

Here is the caller graph for this function:

static struct cb_field* real_field_founder ( const struct cb_field f)
static

Definition at line 541 of file codegen.c.

References cb_field::parent, and cb_field::redefines.

Referenced by output_base(), and output_param().

542 {
543  const struct cb_field *ff;
544 
545  ff = f;
546  while (ff->parent) {
547  ff = ff->parent;
548  }
549  if (ff->redefines) {
550  return ff->redefines;
551  }
552  return (struct cb_field *)ff;
553 }
Definition: tree.h:643
struct cb_field * parent
Definition: tree.h:651
struct cb_field * redefines
Definition: tree.h:654

Here is the caller graph for this function:

static struct string_list* string_list_reverse ( struct string_list p)
static

Definition at line 284 of file codegen.c.

References string_list::next, and NULL.

Referenced by codegen().

285 {
286  struct string_list *next;
287  struct string_list *last;
288 
289  last = NULL;
290  for (; p; p = next) {
291  next = p->next;
292  p->next = last;
293  last = p;
294  }
295  return last;
296 }
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
struct string_list * next
Definition: codegen.c:77

Here is the caller graph for this function:

static char* user_func_upper ( const char *  func)
static

Definition at line 914 of file codegen.c.

References cb_encode_program_id(), and cob_u8_t.

Referenced by output_param().

915 {
916  unsigned char *s;
917  char *rets;
918 
919  rets = cb_encode_program_id (func);
920  for (s = (unsigned char *)rets; *s; s++) {
921  if (islower ((int)*s)) {
922  *s = (cob_u8_t)toupper ((int)*s);
923  }
924  }
925  return rets;
926 }
#define cob_u8_t
Definition: common.h:27
char * cb_encode_program_id(const char *)
Definition: typeck.c:1132

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

struct attr_list* attr_cache = ((void*)0)
static

Definition at line 121 of file codegen.c.

Referenced by lookup_attr().

struct base_list* base_cache = ((void*)0)
static

Definition at line 127 of file codegen.c.

Referenced by output_base().

struct call_list* call_cache = ((void*)0)
static

Definition at line 125 of file codegen.c.

Referenced by lookup_call().

FILE* cb_local_file = ((void*)0)
static

Definition at line 136 of file codegen.c.

Referenced by codegen(), and output_local().

struct cb_program* current_prog = ((void*)0)
static

Definition at line 140 of file codegen.c.

const char* excp_current_paragraph = ((void*)0)
static

Definition at line 139 of file codegen.c.

Referenced by codegen(), output_label_info(), and output_trace_info().

const char* excp_current_program_id = ((void*)0)
static

Definition at line 137 of file codegen.c.

Referenced by codegen(), output_base(), output_internal_function(), and output_param().

const char* excp_current_section = ((void*)0)
static

Definition at line 138 of file codegen.c.

Referenced by codegen(), output_label_info(), and output_trace_info().

struct field_list* field_cache = ((void*)0)
static

Definition at line 123 of file codegen.c.

Referenced by output_param().

cob_u32_t field_iteration = 0
static

Definition at line 166 of file codegen.c.

Referenced by output_call(), and output_data().

struct call_list* func_call_cache = ((void*)0)
static

Definition at line 126 of file codegen.c.

Referenced by lookup_func_call().

unsigned int gen_alt_ebcdic = 0
static

Definition at line 150 of file codegen.c.

Referenced by codegen(), and output_param().

unsigned int gen_custom = 0
static

Definition at line 154 of file codegen.c.

Referenced by codegen(), output_file_allocation(), and output_param().

unsigned int gen_dynamic = 0
static

Definition at line 156 of file codegen.c.

Referenced by codegen(), output_internal_function(), and output_param().

unsigned int gen_ebcdic_ascii = 0
static

Definition at line 151 of file codegen.c.

Referenced by codegen(), output_file_allocation(), and output_param().

unsigned int gen_figurative = 0
static

Definition at line 155 of file codegen.c.

Referenced by codegen(), and output_param().

unsigned int gen_full_ebcdic = 0
static

Definition at line 152 of file codegen.c.

Referenced by codegen(), output_file_allocation(), and output_param().

int gen_if_level = 0
static

Definition at line 173 of file codegen.c.

Referenced by codegen(), and output_stmt().

unsigned int gen_native = 0
static

Definition at line 153 of file codegen.c.

Referenced by codegen(), output_file_allocation(), and output_param().

unsigned int gen_nested_tab = 0
static
struct base_list* globext_cache = ((void*)0)
static

Definition at line 128 of file codegen.c.

Referenced by output_internal_function().

unsigned int i_counters[16]
static
unsigned int inside_check = 0
static

Definition at line 176 of file codegen.c.

Referenced by codegen(), output_cond(), output_param(), and output_stmt().

unsigned int inside_stack[64]
static

Definition at line 177 of file codegen.c.

Referenced by codegen(), output_cond(), output_param(), and output_stmt().

struct label_list* label_cache = ((void*)0)
static

Definition at line 132 of file codegen.c.

Referenced by output_perform_call().

int last_line = 0
static

Definition at line 165 of file codegen.c.

Referenced by codegen(), and output_stmt().

struct cb_label* last_section = ((void*)0)
static

Definition at line 142 of file codegen.c.

int last_segment = 0
static

Definition at line 172 of file codegen.c.

Referenced by codegen(), output_goto_1(), output_perform_call(), and output_stmt().

unsigned char* litbuff = ((void*)0)
static

Definition at line 143 of file codegen.c.

Referenced by output_initialize_one().

struct literal_list* literal_cache = ((void*)0)
static

Definition at line 122 of file codegen.c.

Referenced by lookup_literal().

int litsize = 0
static

Definition at line 144 of file codegen.c.

Referenced by output_initialize_one().

struct base_list* local_base_cache = ((void*)0)
static

Definition at line 129 of file codegen.c.

Referenced by output_base().

struct field_list* local_field_cache = ((void*)0)
static

Definition at line 124 of file codegen.c.

Referenced by output_param().

int local_mem = 0
static

Definition at line 168 of file codegen.c.

Referenced by codegen(), and output_internal_function().

int local_working_mem = 0
static

Definition at line 170 of file codegen.c.

Referenced by codegen(), and output_internal_function().

int loop_counter = 0
static

Definition at line 163 of file codegen.c.

Referenced by codegen(), and output_perform().

unsigned int need_save_exception = 0
static

Definition at line 148 of file codegen.c.

Referenced by codegen(), and output_stmt().

unsigned int needs_exit_prog = 0
static

Definition at line 146 of file codegen.c.

Referenced by codegen(), output_call(), output_goto(), and output_internal_function().

unsigned int needs_unifunc = 0
static

Definition at line 147 of file codegen.c.

Referenced by codegen(), and output_call().

unsigned int nolitcast = 0
static

Definition at line 174 of file codegen.c.

Referenced by output_funcall(), and output_param().

int non_nested_count = 0
static

Definition at line 162 of file codegen.c.

Referenced by codegen(), output_internal_function(), and output_module_init().

int num_cob_fields = 0
static

Definition at line 161 of file codegen.c.

Referenced by codegen(), and output_param().

int output_indent_level = 0
static
FILE* output_target = ((void*)0)
static
int param_id = 0
static

Definition at line 158 of file codegen.c.

Referenced by codegen(), output_func_1(), and output_param().

int progid = 0
static

Definition at line 164 of file codegen.c.

Referenced by codegen(), and output_entry_function().

int screenptr = 0
static

Definition at line 167 of file codegen.c.

Referenced by output_funcall(), and output_param().

int stack_id = 0
static

Definition at line 159 of file codegen.c.

Referenced by codegen(), output_param(), and output_stmt().

char* string_buffer = ((void*)0)
static

Definition at line 131 of file codegen.c.

Referenced by codegen(), output_internal_function(), and output_section_info().

struct string_list* string_cache = ((void*)0)
static

Definition at line 130 of file codegen.c.

Referenced by lookup_string().

int string_id
static

Definition at line 160 of file codegen.c.

Referenced by codegen(), and lookup_string().

const struct system_table system_tab[]
static

Definition at line 184 of file codegen.c.

int working_mem = 0
static

Definition at line 169 of file codegen.c.

Referenced by codegen(), and output_internal_function().