Debian Codegraph @

gcc/cobol/genutil.h

raw
1 /*
2 * Copyright (c) 2021-2025 Symas Corporation
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of the Symas Corporation nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 #ifndef _GENUTIL_H_
31 #define _GENUTIL_H_
32
33 #define EBCDIC_MINUS (0x60)
34 #define EBCDIC_PLUS (0x4E)
35 #define EBCDIC_ZERO (0xF0)
36 #define EBCDIC_NINE (0xF9)
37
38 bool internal_codeset_is_ebcdic();
39
40 extern bool exception_location_active;
41 extern bool skip_exception_processing;
42
43 extern bool suppress_dest_depends;
44
45 extern std::vector<std::string>current_filename;
46
47 extern tree var_decl_exception_code; // int __gg__exception_code;
48 extern tree var_decl_exception_file_status; // int __gg__exception_file_status;
49 extern tree var_decl_exception_file_name; // const char *__gg__exception_file_name;
50 extern tree var_decl_exception_statement; // const char *__gg__exception_statement;
51 extern tree var_decl_exception_source_file; // const char *__gg__exception_source_file;
52 extern tree var_decl_exception_line_number; // int __gg__exception_line_number;
53 extern tree var_decl_exception_program_id; // const char *__gg__exception_program_id;
54 extern tree var_decl_exception_section; // const char *__gg__exception_section;
55 extern tree var_decl_exception_paragraph; // const char *__gg__exception_paragraph;
56
57 extern tree var_decl_default_compute_error; // int __gg__default_compute_error;
58 extern tree var_decl_rdigits; // int __gg__rdigits;
59 extern tree var_decl_unique_prog_id; // size_t __gg__unique_prog_id;
60
61 extern tree var_decl_entry_location; // This is for managing ENTRY statements
62 extern tree var_decl_exit_address; // This is for implementing pseudo_return_pop
63
64 extern tree var_decl_call_parameter_signature; // char *__gg__call_parameter_signature
65 extern tree var_decl_call_parameter_count; // int __gg__call_parameter_count
66 extern tree var_decl_call_parameter_lengths; // size_t *var_decl_call_parameter_lengths
67
68 extern tree var_decl_return_code; // short __gg__data_return_code
69
70 extern tree var_decl_arithmetic_rounds_size; // size_t __gg__arithmetic_rounds_size;
71 extern tree var_decl_arithmetic_rounds; // int* __gg__arithmetic_rounds;
72 extern tree var_decl_fourplet_flags_size; // size_t __gg__fourplet_flags_size;
73 extern tree var_decl_fourplet_flags; // int* __gg__fourplet_flags;
74
75 extern tree var_decl_treeplet_1f; // cblc_field_pp_type_node , "__gg__treeplet_1f"
76 extern tree var_decl_treeplet_1o; // SIZE_T_P , "__gg__treeplet_1o"
77 extern tree var_decl_treeplet_1s; // SIZE_T_P , "__gg__treeplet_1s"
78 extern tree var_decl_treeplet_2f; // cblc_field_pp_type_node , "__gg__treeplet_2f"
79 extern tree var_decl_treeplet_2o; // SIZE_T_P , "__gg__treeplet_2o"
80 extern tree var_decl_treeplet_2s; // SIZE_T_P , "__gg__treeplet_2s"
81 extern tree var_decl_treeplet_3f; // cblc_field_pp_type_node , "__gg__treeplet_3f"
82 extern tree var_decl_treeplet_3o; // SIZE_T_P , "__gg__treeplet_3o"
83 extern tree var_decl_treeplet_3s; // SIZE_T_P , "__gg__treeplet_3s"
84 extern tree var_decl_treeplet_4f; // cblc_field_pp_type_node , "__gg__treeplet_4f"
85 extern tree var_decl_treeplet_4o; // SIZE_T_P , "__gg__treeplet_4o"
86 extern tree var_decl_treeplet_4s; // SIZE_T_P , "__gg__treeplet_4s"
87
88 extern tree var_decl_nop; // int __gg__nop
89 extern tree var_decl_main_called; // int __gg__main_called
90
91 int get_scaled_rdigits(cbl_field_t *field);
92 int get_scaled_digits(cbl_field_t *field);
93 tree tree_type_from_digits(size_t digits, int signable);
94 tree tree_type_from_size(size_t bytes, int signable);
95
96 void get_binary_value( tree value,
97 tree rdigits,
98 cbl_field_t *field,
99 tree field_offset,
100 tree hilo = NULL);
101 tree get_data_address( cbl_field_t *field,
102 tree offset);
103
104 FIXED_WIDE_INT(128) get_power_of_ten(int n);
105 void scale_by_power_of_ten_N(tree value,
106 int N,
107 bool check_for_fractional = false);
108 tree scale_by_power_of_ten(tree value,
109 tree N,
110 bool check_for_fractional = false);
111 void scale_and_round(tree value,
112 int value_rdigits,
113 bool target_is_signable,
114 int target_rdigits,
115 cbl_round_t rounded);
116 void hex_dump(tree data, size_t bytes);
117 void set_exception_code_func(ec_type_t ec,
118 int line,
119 int from_raise_statement=0);
120 #define set_exception_code(ec) set_exception_code_func(ec, __LINE__)
121 bool process_this_exception(const ec_type_t ec);
122 #define CHECK_FOR_FRACTIONAL_DIGITS true
123 void get_integer_value(tree value, // This is always a LONG
124 cbl_field_t *field,
125 tree offset=NULL, // size_t
126 bool check_for_fractional_digits=false);
127 void rt_error(const char *msg);
128 void copy_little_endian_into_place(cbl_field_t *dest,
129 tree dest_offset,
130 tree value,
131 int rhs_rdigits,
132 bool check_for_error,
133 const tree &size_error);
134 tree build_array_of_size_t( size_t N,
135 const size_t *values);
136 void parser_display_internal_field(tree file_descriptor,
137 cbl_field_t *field,
138 bool advance=DISPLAY_NO_ADVANCE);
139 char *get_literal_string(cbl_field_t *field);
140
141 bool refer_is_clean(const cbl_refer_t &refer);
142
143 tree refer_offset(const cbl_refer_t &refer,
144 int *pflags=NULL);
145 tree refer_size_source(const cbl_refer_t &refer);
146 tree refer_size_dest(const cbl_refer_t &refer);
147
148 tree qualified_data_location(const cbl_refer_t &refer);
149
150 void build_array_of_treeplets( int ngroup,
151 size_t N,
152 cbl_refer_t *refers);
153
154 void build_array_of_fourplets( int ngroup,
155 size_t N,
156 cbl_refer_t *refers);
157 void get_depending_on_value_from_odo(tree retval, cbl_field_t *odo);
158 uint64_t get_time_nanoseconds();
159
160
161 #endif