diff --git a/tests/hellocobol/.gitignore b/tests/hellocobol/.gitignore new file mode 100644 index 0000000..e35ebf5 --- /dev/null +++ b/tests/hellocobol/.gitignore @@ -0,0 +1,2 @@ +helloworld +*.i diff --git a/tests/hellocobol/Makefile b/tests/hellocobol/Makefile new file mode 100644 index 0000000..cd1c3a8 --- /dev/null +++ b/tests/hellocobol/Makefile @@ -0,0 +1,16 @@ +.PHONY: all +all: hellocobol hellocobol_variables hellocobol_if + +hellocobol: hellocobol.cob + cobc -x -g -o hellocobol hellocobol.cob + +hellocobol_variables: hellocobol_variables.cob + cobc -x -g -o hellocobol_variables hellocobol_variables.cob + +hellocobol_if: hellocobol_if.cob + cobc -x -g -o hellocobol_if hellocobol_if.cob + +.PHONY: clean +clean: + rm -f hellocobol hellocobol.o *.i + diff --git a/tests/hellocobol/hellocobol b/tests/hellocobol/hellocobol new file mode 100755 index 0000000..456632c Binary files /dev/null and b/tests/hellocobol/hellocobol differ diff --git a/tests/hellocobol/hellocobol.c b/tests/hellocobol/hellocobol.c new file mode 100644 index 0000000..5a314c1 --- /dev/null +++ b/tests/hellocobol/hellocobol.c @@ -0,0 +1,215 @@ +/* Generated by cobc 3.1.2.0 */ +/* Generated from hellocobol.cob */ +/* Generated at Aug 04 2025 19:08:23 */ +/* GnuCOBOL build date Jul 15 2023 12:00:00 */ +/* GnuCOBOL package date Dec 23 2020 12:04:58 UTC */ +/* Compile command cobc -x -g -o hellocobol hellocobol.cob */ + +#include +#include +#define COB_KEYWORD_INLINE __inline +#include + +#define COB_SOURCE_FILE "hellocobol.cob" +#define COB_PACKAGE_VERSION "3.1.2" +#define COB_PATCH_LEVEL 0 +#define COB_MODULE_FORMATTED_DATE "Aug 04 2025 19:08:23" +#define COB_MODULE_DATE 20250804 +#define COB_MODULE_TIME 190823 + +/* Global variables */ +#include "hellocobol.c.h" + +/* Function prototypes */ + +static int hello (); +static int hello_ (const int); +static void hello_module_init (cob_module *module); + +/* Main function */ +int +main (int argc, char **argv) +{ + cob_init (argc, argv); + cob_stop_run (hello ()); +} + +/* Functions */ + +/* PROGRAM-ID 'hello' */ + +/* ENTRY 'hello' */ + +static int +hello () +{ + return hello_ (0); +} + +static int +hello_ (const int entry) +{ + /* Program local variables */ + #include "hellocobol.c.l.h" + + /* Start of function code */ + + /* CANCEL callback */ + if (unlikely(entry < 0)) { + if (entry == -10) + goto P_dump; + if (entry == -20) + goto P_clear_decimal; + goto P_cancel; + } + + /* Check initialized, check module allocated, */ + /* set global pointer, */ + /* push module stack, save call parameter count */ + if (cob_module_global_enter (&module, &cob_glob_ptr, 0, entry, 0)) + return -1; + + /* Set address of module parameter list */ + module->cob_procedure_params = cob_procedure_params; + + /* Set frame stack pointer */ + frame_ptr = frame_stack; + frame_ptr->perform_through = 0; + frame_ptr->return_address_ptr = &&P_cgerror; + frame_overflow = frame_ptr + 255 - 1; + + /* Initialize rest of program */ + if (unlikely(initialized == 0)) { + goto P_initialize; + } + P_ret_initialize: + + /* Increment module active */ + module->module_active++; + + /* Entry dispatch */ + goto l_2; + + /* PROCEDURE DIVISION */ + + /* Line: 4 : Entry hello : hellocobol.cob */ + l_2:; +#line 4 "hellocobol.cob" + ENTRY_HELLO:; +#line 100 "hellocobol.c" +#line 5 "hellocobol.cob" + SECTION_MAIN_20SECTION:; +#line 103 "hellocobol.c" +#line 5 "hellocobol.cob" + cob_nop (); +#line 106 "hellocobol.c" + + /* Line: 5 : DISPLAY : hellocobol.cob */ + module->module_stmt = 0x00100005; +#line 5 "hellocobol.cob" + cob_trace_stmt (st_1); +#line 112 "hellocobol.c" + cob_display (0, 1, 1, &c_1); + + /* Line: 6 : STOP RUN : hellocobol.cob */ + module->module_stmt = 0x00100006; +#line 6 "hellocobol.cob" + cob_trace_stmt (st_2); +#line 119 "hellocobol.c" + cob_stop_run (b_2); + + module->module_stmt = 0x00100007; + + /* Program exit */ + + /* Decrement module active count */ + if (module->module_active) { + module->module_active--; + } + + /* Pop module stack */ + cob_module_leave (module); + + /* Program return */ + return b_2; + P_cgerror: + cob_fatal_error (COB_FERROR_CODEGEN); + + + /* Program initialization */ + P_initialize: + + cob_check_version (COB_SOURCE_FILE, COB_PACKAGE_VERSION, COB_PATCH_LEVEL); + + cob_module_path = cob_glob_ptr->cob_main_argv0; + + hello_module_init (module); + + module->crt_status = NULL; + + /* Initialize cancel callback */ + cob_set_cancel (module); + + /* Initialize WORKING-STORAGE */ + b_2 = 0; + + if (0 == 1) goto P_cgerror; + initialized = 1; + goto P_ret_initialize; + + P_dump: + return 0; + + + /* CANCEL callback handling */ + P_cancel: + + if (!initialized) + return 0; + if (module && module->module_active) + cob_fatal_error (COB_FERROR_CANCEL); + + initialized = 0; + + P_clear_decimal: + return 0; + +} + +/* End PROGRAM-ID 'hello' */ + +/* Initialize module structure for hello */ +static void hello_module_init (cob_module *module) +{ + module->module_name = "hello"; + module->module_formatted_date = COB_MODULE_FORMATTED_DATE; + module->module_source = COB_SOURCE_FILE; + module->module_entry.funcptr = (void *(*)())hello; + module->module_cancel.funcptr = (void *(*)())hello_; + module->module_ref_count = NULL; + module->module_path = &cob_module_path; + module->module_active = 0; + module->module_date = COB_MODULE_DATE; + module->module_time = COB_MODULE_TIME; + module->module_type = 0; + module->module_param_cnt = 0; + module->ebcdic_sign = 0; + module->decimal_point = '.'; + module->currency_symbol = '$'; + module->numeric_separator = ','; + module->flag_filename_mapping = 1; + module->flag_binary_truncate = 1; + module->flag_pretty_display = 1; + module->flag_host_sign = 0; + module->flag_no_phys_canc = 1; + module->flag_main = 1; + module->flag_fold_call = 0; + module->flag_exit_program = 0; + module->flag_debug_trace = 0; + module->flag_dump_ready = 0; + module->module_stmt = 0; + module->module_sources = st_source_files; +} + +/* End functions */ + diff --git a/tests/hellocobol/hellocobol.c.h b/tests/hellocobol/hellocobol.c.h new file mode 100644 index 0000000..592aaf8 --- /dev/null +++ b/tests/hellocobol/hellocobol.c.h @@ -0,0 +1,31 @@ +/* Generated by cobc 3.1.2.0 */ +/* Generated from hellocobol.cob */ +/* Generated at Aug 04 2025 19:08:23 */ +/* GnuCOBOL build date Jul 15 2023 12:00:00 */ +/* GnuCOBOL package date Dec 23 2020 12:04:58 UTC */ +/* Compile command cobc -x -g -o hellocobol hellocobol.cob */ + + +/* Module path */ +static const char *cob_module_path = NULL; + +/* Number of call parameters */ +static int cob_call_params = 0; + +/* Attributes */ + +static const cob_field_attr a_1 = {0x21, 0, 0, 0x1000, NULL}; + + +/* Constants */ +static const cob_field c_1 = {13, (cob_u8_ptr)"Hello, world!", &a_1}; + + +/* Strings */ +static const char st_1[] = "DISPLAY"; +static const char st_2[] = "STOP RUN"; + + +/* Source file names */ +static const char *st_source_files[] = { "" + ,"hellocobol.cob"}; diff --git a/tests/hellocobol/hellocobol.c.l.h b/tests/hellocobol/hellocobol.c.l.h new file mode 100644 index 0000000..98b62c5 --- /dev/null +++ b/tests/hellocobol/hellocobol.c.l.h @@ -0,0 +1,33 @@ +/* Generated by cobc 3.1.2.0 */ +/* Generated from hellocobol.cob */ +/* Generated at Aug 04 2025 19:08:23 */ +/* GnuCOBOL build date Jul 15 2023 12:00:00 */ +/* GnuCOBOL package date Dec 23 2020 12:04:58 UTC */ +/* Compile command cobc -x -g -o hellocobol hellocobol.cob */ + +/* Program local variables for 'hello' */ + +/* Module initialization indicator */ +static unsigned int initialized = 0; + +/* Module structure pointer */ +static cob_module *module = NULL; + +/* Global variable pointer */ +cob_global *cob_glob_ptr; + + +/* Call parameters */ +cob_field *cob_procedure_params[1]; + +/* Perform frame stack */ +struct cob_frame *frame_overflow; +struct cob_frame *frame_ptr; +struct cob_frame frame_stack[255]; + + +/* Data storage */ +static int b_2; /* RETURN-CODE */ + +/* End of local data storage */ + diff --git a/tests/hellocobol/hellocobol.cob b/tests/hellocobol/hellocobol.cob new file mode 100644 index 0000000..94d0e7a --- /dev/null +++ b/tests/hellocobol/hellocobol.cob @@ -0,0 +1,6 @@ + * Sample COBOL program + IDENTIFICATION DIVISION. + PROGRAM-ID. hello. + PROCEDURE DIVISION. + DISPLAY "Hello, world!". + STOP RUN. diff --git a/tests/hellocobol/hellocobol_if b/tests/hellocobol/hellocobol_if new file mode 100755 index 0000000..5d4554e Binary files /dev/null and b/tests/hellocobol/hellocobol_if differ diff --git a/tests/hellocobol/hellocobol_if.c b/tests/hellocobol/hellocobol_if.c new file mode 100644 index 0000000..12d6eec --- /dev/null +++ b/tests/hellocobol/hellocobol_if.c @@ -0,0 +1,452 @@ +/* Generated by cobc 3.1.2.0 */ +/* Generated from hellocobol_if.cob */ +/* Generated at Aug 04 2025 19:27:10 */ +/* GnuCOBOL build date Jul 15 2023 12:00:00 */ +/* GnuCOBOL package date Dec 23 2020 12:04:58 UTC */ +/* Compile command cobc -x -g -o hellocobol_if hellocobol_if.cob */ + +#include +#include +#define COB_KEYWORD_INLINE __inline +#include + +#define COB_SOURCE_FILE "hellocobol_if.cob" +#define COB_PACKAGE_VERSION "3.1.2" +#define COB_PATCH_LEVEL 0 +#define COB_MODULE_FORMATTED_DATE "Aug 04 2025 19:27:10" +#define COB_MODULE_DATE 20250804 +#define COB_MODULE_TIME 192710 + +/* Global variables */ +#include "hellocobol_if.c.h" + +/* Function prototypes */ + +static int _01_IF (); +static int _01_IF_ (const int); +static void _01_IF_module_init (cob_module *module); + +/* Main function */ +int +main (int argc, char **argv) +{ + cob_init (argc, argv); + cob_stop_run (_01_IF ()); +} + +/* Functions */ + +/* PROGRAM-ID '01_IF' */ + +/* ENTRY '_01_IF' */ + +static int +_01_IF () +{ + return _01_IF_ (0); +} + +static int +_01_IF_ (const int entry) +{ + /* Program local variables */ + #include "hellocobol_if.c.l.h" + + /* Start of function code */ + + /* CANCEL callback */ + if (unlikely(entry < 0)) { + if (entry == -10) + goto P_dump; + if (entry == -20) + goto P_clear_decimal; + goto P_cancel; + } + + /* Check initialized, check module allocated, */ + /* set global pointer, */ + /* push module stack, save call parameter count */ + if (cob_module_global_enter (&module, &cob_glob_ptr, 0, entry, 0)) + return -1; + + /* Set address of module parameter list */ + module->cob_procedure_params = cob_procedure_params; + + /* Set frame stack pointer */ + frame_ptr = frame_stack; + frame_ptr->perform_through = 0; + frame_ptr->return_address_ptr = &&P_cgerror; + frame_overflow = frame_ptr + 255 - 1; + + /* Initialize rest of program */ + if (unlikely(initialized == 0)) { + goto P_initialize; + } + P_ret_initialize: + + /* Increment module active */ + module->module_active++; + + /* Entry dispatch */ + goto l_2; + + /* PROCEDURE DIVISION */ + + /* Line: 13 : Entry 01_IF : hellocobol_if.cob */ + l_2:; +#line 13 "hellocobol_if.cob" + ENTRY_01_IF:; +#line 100 "hellocobol_if.c" +#line 15 "hellocobol_if.cob" + SECTION_MAIN_20SECTION:; +#line 103 "hellocobol_if.c" +#line 15 "hellocobol_if.cob" + cob_nop (); +#line 106 "hellocobol_if.c" + + /* Line: 15 : DISPLAY : hellocobol_if.cob */ + module->module_stmt = 0x0010000F; +#line 15 "hellocobol_if.cob" + cob_trace_stmt (st_1); +#line 112 "hellocobol_if.c" + cob_display (0, 1, 1, &c_1); + + /* Line: 16 : ACCEPT : hellocobol_if.cob */ + module->module_stmt = 0x00100010; +#line 16 "hellocobol_if.cob" + cob_trace_stmt (st_2); +#line 119 "hellocobol_if.c" + cob_accept (&f_8); + + /* Line: 18 : DISPLAY : hellocobol_if.cob */ + module->module_stmt = 0x00100012; +#line 18 "hellocobol_if.cob" + cob_trace_stmt (st_1); +#line 126 "hellocobol_if.c" + cob_display (0, 1, 1, &c_2); + + /* Line: 19 : ACCEPT : hellocobol_if.cob */ + module->module_stmt = 0x00100013; +#line 19 "hellocobol_if.cob" + cob_trace_stmt (st_2); +#line 133 "hellocobol_if.c" + cob_accept (&f_10); + + /* Line: 21 : DISPLAY : hellocobol_if.cob */ + module->module_stmt = 0x00100015; +#line 21 "hellocobol_if.cob" + cob_trace_stmt (st_1); +#line 140 "hellocobol_if.c" + cob_display (0, 1, 1, &c_3); + + /* Line: 22 : ACCEPT : hellocobol_if.cob */ + module->module_stmt = 0x00100016; +#line 22 "hellocobol_if.cob" + cob_trace_stmt (st_2); +#line 147 "hellocobol_if.c" + cob_accept (&f_12); + + /* Line: 24 : IF : hellocobol_if.cob */ + module->module_stmt = 0x00100018; +#line 24 "hellocobol_if.cob" + cob_trace_stmt (st_3); +#line 154 "hellocobol_if.c" + if (((int)cob_cmp_numdisp (b_8, 9, cob_get_llint (&f_10), 1) > 0)) + { + + /* Line: 25 : DISPLAY : hellocobol_if.cob */ + module->module_stmt = 0x00100019; +#line 25 "hellocobol_if.cob" + cob_trace_stmt (st_1); +#line 162 "hellocobol_if.c" + cob_display (0, 1, 1, &c_4); + } + else + { + /* ELSE */ + + /* Line: 27 : IF : hellocobol_if.cob */ + module->module_stmt = 0x0010001B; +#line 27 "hellocobol_if.cob" + cob_trace_stmt (st_3); +#line 173 "hellocobol_if.c" + if (((int)cob_cmp_numdisp (b_8, 9, cob_get_llint (&f_10), 1) == 0)) + { + + /* Line: 28 : DISPLAY : hellocobol_if.cob */ + module->module_stmt = 0x0010001C; +#line 28 "hellocobol_if.cob" + cob_trace_stmt (st_1); +#line 181 "hellocobol_if.c" + cob_display (0, 1, 1, &c_5); + } + else + { + /* ELSE */ + + /* Line: 30 : DISPLAY : hellocobol_if.cob */ + module->module_stmt = 0x0010001E; +#line 30 "hellocobol_if.cob" + cob_trace_stmt (st_1); +#line 192 "hellocobol_if.c" + cob_display (0, 1, 1, &c_6); + } + } + + /* Line: 35 : IF : hellocobol_if.cob */ + module->module_stmt = 0x00100023; +#line 35 "hellocobol_if.cob" + cob_trace_stmt (st_3); +#line 201 "hellocobol_if.c" + if (((int)cob_cmp_numdisp (b_8, 9, 0, 1) > 0)) + { + + /* Line: 36 : DISPLAY : hellocobol_if.cob */ + module->module_stmt = 0x00100024; +#line 36 "hellocobol_if.cob" + cob_trace_stmt (st_1); +#line 209 "hellocobol_if.c" + cob_display (0, 1, 1, &c_7); + } + + /* Line: 39 : IF : hellocobol_if.cob */ + module->module_stmt = 0x00100027; +#line 39 "hellocobol_if.cob" + cob_trace_stmt (st_3); +#line 217 "hellocobol_if.c" + if (((int)cob_cmp_numdisp (b_8, 9, 0, 1) < 0)) + { + + /* Line: 40 : DISPLAY : hellocobol_if.cob */ + module->module_stmt = 0x00100028; +#line 40 "hellocobol_if.cob" + cob_trace_stmt (st_1); +#line 225 "hellocobol_if.c" + cob_display (0, 1, 1, &c_8); + } + + /* Line: 44 : IF : hellocobol_if.cob */ + module->module_stmt = 0x0010002C; +#line 44 "hellocobol_if.cob" + cob_trace_stmt (st_3); +#line 233 "hellocobol_if.c" + if (cob_is_numeric (&f_12)) + { + + /* Line: 46 : DISPLAY : hellocobol_if.cob */ + module->module_stmt = 0x0010002E; +#line 46 "hellocobol_if.cob" + cob_trace_stmt (st_1); +#line 241 "hellocobol_if.c" + cob_display (0, 1, 1, &c_9); + } + + /* Line: 49 : IF : hellocobol_if.cob */ + module->module_stmt = 0x00100031; +#line 49 "hellocobol_if.cob" + cob_trace_stmt (st_3); +#line 249 "hellocobol_if.c" + if (cob_is_alpha (&f_12)) + { + + /* Line: 50 : DISPLAY : hellocobol_if.cob */ + module->module_stmt = 0x00100032; +#line 50 "hellocobol_if.cob" + cob_trace_stmt (st_1); +#line 257 "hellocobol_if.c" + cob_display (0, 1, 1, &c_10); + } + + /* Line: 55 : IF : hellocobol_if.cob */ + module->module_stmt = 0x00100037; +#line 55 "hellocobol_if.cob" + cob_trace_stmt (st_3); +#line 265 "hellocobol_if.c" + if ((((int)cob_cmp_numdisp (b_8, 9, 100LL, 1) >= 0) && + ((int)cob_cmp_numdisp (b_8, 9, 9999LL, 1) <= 0))) + { + + /* Line: 56 : DISPLAY : hellocobol_if.cob */ + module->module_stmt = 0x00100038; +#line 56 "hellocobol_if.cob" + cob_trace_stmt (st_1); +#line 274 "hellocobol_if.c" + cob_display (0, 1, 1, &c_11); + } + + /* Line: 59 : IF : hellocobol_if.cob */ + module->module_stmt = 0x0010003B; +#line 59 "hellocobol_if.cob" + cob_trace_stmt (st_3); +#line 282 "hellocobol_if.c" + if (!(((int)cob_cmp_numdisp (b_8, 9, 100LL, 1) >= 0) && + ((int)cob_cmp_numdisp (b_8, 9, 9999LL, 1) <= 0))) + { + + /* Line: 60 : DISPLAY : hellocobol_if.cob */ + module->module_stmt = 0x0010003C; +#line 60 "hellocobol_if.cob" + cob_trace_stmt (st_1); +#line 291 "hellocobol_if.c" + cob_display (0, 1, 1, &c_12); + } + + /* Line: 63 : IF : hellocobol_if.cob */ + module->module_stmt = 0x0010003F; +#line 63 "hellocobol_if.cob" + cob_trace_stmt (st_3); +#line 299 "hellocobol_if.c" + if ((((int)cob_cmp_numdisp (b_10, 9, 100LL, 1) >= 0) && + ((int)cob_cmp_numdisp (b_10, 9, 9999LL, 1) <= 0))) + { + + /* Line: 64 : DISPLAY : hellocobol_if.cob */ + module->module_stmt = 0x00100040; +#line 64 "hellocobol_if.cob" + cob_trace_stmt (st_1); +#line 308 "hellocobol_if.c" + cob_display (0, 1, 1, &c_13); + } + + /* Line: 67 : IF : hellocobol_if.cob */ + module->module_stmt = 0x00100043; +#line 67 "hellocobol_if.cob" + cob_trace_stmt (st_3); +#line 316 "hellocobol_if.c" + if (!(((int)cob_cmp_numdisp (b_10, 9, 100LL, 1) >= 0) && + ((int)cob_cmp_numdisp (b_10, 9, 9999LL, 1) <= 0))) + { + + /* Line: 68 : DISPLAY : hellocobol_if.cob */ + module->module_stmt = 0x00100044; +#line 68 "hellocobol_if.cob" + cob_trace_stmt (st_1); +#line 325 "hellocobol_if.c" + cob_display (0, 1, 1, &c_14); + } + + /* Line: 72 : IF : hellocobol_if.cob */ + module->module_stmt = 0x00100048; +#line 72 "hellocobol_if.cob" + cob_trace_stmt (st_3); +#line 333 "hellocobol_if.c" + if (((((int)cob_cmp_numdisp (b_8, 9, 100LL, 1) >= 0) && + ((int)cob_cmp_numdisp (b_8, 9, 9999LL, 1) <= 0)) && + (((int)cob_cmp_numdisp (b_10, 9, 100LL, 1) >= 0) && + ((int)cob_cmp_numdisp (b_10, 9, 9999LL, 1) <= 0)))) + { + + /* Line: 73 : DISPLAY : hellocobol_if.cob */ + module->module_stmt = 0x00100049; +#line 73 "hellocobol_if.cob" + cob_trace_stmt (st_1); +#line 344 "hellocobol_if.c" + cob_display (0, 1, 1, &c_15); + } + + /* Line: 76 : STOP RUN : hellocobol_if.cob */ + module->module_stmt = 0x0010004C; +#line 76 "hellocobol_if.cob" + cob_trace_stmt (st_4); +#line 352 "hellocobol_if.c" + cob_stop_run (b_2); + + module->module_stmt = 0x00100050; + + /* Program exit */ + + /* Decrement module active count */ + if (module->module_active) { + module->module_active--; + } + + /* Pop module stack */ + cob_module_leave (module); + + /* Program return */ + return b_2; + P_cgerror: + cob_fatal_error (COB_FERROR_CODEGEN); + + + /* Program initialization */ + P_initialize: + + cob_check_version (COB_SOURCE_FILE, COB_PACKAGE_VERSION, COB_PATCH_LEVEL); + + cob_module_path = cob_glob_ptr->cob_main_argv0; + + _01_IF_module_init (module); + + module->crt_status = NULL; + + /* Initialize cancel callback */ + cob_set_cancel (module); + + /* Initialize WORKING-STORAGE */ + b_2 = 0; + memset (b_8, 48, 9); + memcpy (b_10, "000000001", 9); + memset (b_12, 32, 1); + memset (b_12 + 1, ' ', 8); + + if (0 == 1) goto P_cgerror; + initialized = 1; + goto P_ret_initialize; + + P_dump: + return 0; + + + /* CANCEL callback handling */ + P_cancel: + + if (!initialized) + return 0; + if (module && module->module_active) + cob_fatal_error (COB_FERROR_CANCEL); + + initialized = 0; + + P_clear_decimal: + return 0; + +} + +/* End PROGRAM-ID '01_IF' */ + +/* Initialize module structure for 01_IF */ +static void _01_IF_module_init (cob_module *module) +{ + module->module_name = "01_IF"; + module->module_formatted_date = COB_MODULE_FORMATTED_DATE; + module->module_source = COB_SOURCE_FILE; + module->module_entry.funcptr = (void *(*)())_01_IF; + module->module_cancel.funcptr = (void *(*)())_01_IF_; + module->module_ref_count = NULL; + module->module_path = &cob_module_path; + module->module_active = 0; + module->module_date = COB_MODULE_DATE; + module->module_time = COB_MODULE_TIME; + module->module_type = 0; + module->module_param_cnt = 0; + module->ebcdic_sign = 0; + module->decimal_point = '.'; + module->currency_symbol = '$'; + module->numeric_separator = ','; + module->flag_filename_mapping = 1; + module->flag_binary_truncate = 1; + module->flag_pretty_display = 1; + module->flag_host_sign = 0; + module->flag_no_phys_canc = 1; + module->flag_main = 1; + module->flag_fold_call = 0; + module->flag_exit_program = 0; + module->flag_debug_trace = 0; + module->flag_dump_ready = 0; + module->module_stmt = 0; + module->module_sources = st_source_files; +} + +/* End functions */ + diff --git a/tests/hellocobol/hellocobol_if.c.h b/tests/hellocobol/hellocobol_if.c.h new file mode 100644 index 0000000..99fdf08 --- /dev/null +++ b/tests/hellocobol/hellocobol_if.c.h @@ -0,0 +1,49 @@ +/* Generated by cobc 3.1.2.0 */ +/* Generated from hellocobol_if.cob */ +/* Generated at Aug 04 2025 19:27:10 */ +/* GnuCOBOL build date Jul 15 2023 12:00:00 */ +/* GnuCOBOL package date Dec 23 2020 12:04:58 UTC */ +/* Compile command cobc -x -g -o hellocobol_if hellocobol_if.cob */ + + +/* Module path */ +static const char *cob_module_path = NULL; + +/* Number of call parameters */ +static int cob_call_params = 0; + +/* Attributes */ + +static const cob_field_attr a_1 = {0x21, 0, 0, 0x1000, NULL}; +static const cob_field_attr a_2 = {0x10, 9, 0, 0x0001, NULL}; +static const cob_field_attr a_3 = {0x21, 0, 0, 0x0000, NULL}; + + +/* Constants */ +static const cob_field c_1 = {16, (cob_u8_ptr)"ENTER number 1: ", &a_1}; +static const cob_field c_2 = {16, (cob_u8_ptr)"ENTER number 2: ", &a_1}; +static const cob_field c_3 = {17, (cob_u8_ptr)"ENTER some data: ", &a_1}; +static const cob_field c_4 = {31, (cob_u8_ptr)"Number1 is greater than Number2", &a_1}; +static const cob_field c_5 = {22, (cob_u8_ptr)"Number1 equals Number2", &a_1}; +static const cob_field c_6 = {28, (cob_u8_ptr)"Number1 is less than Number2", &a_1}; +static const cob_field c_7 = {19, (cob_u8_ptr)"Number1 is positive", &a_1}; +static const cob_field c_8 = {19, (cob_u8_ptr)"Number1 is negative", &a_1}; +static const cob_field c_9 = {12, (cob_u8_ptr)"Numeric data", &a_1}; +static const cob_field c_10 = {15, (cob_u8_ptr)"Alphabetic data", &a_1}; +static const cob_field c_11 = {27, (cob_u8_ptr)"Number1 is greater than 100", &a_1}; +static const cob_field c_12 = {24, (cob_u8_ptr)"Number1 is less than 100", &a_1}; +static const cob_field c_13 = {27, (cob_u8_ptr)"Number2 is greater than 100", &a_1}; +static const cob_field c_14 = {24, (cob_u8_ptr)"Number2 is less than 100", &a_1}; +static const cob_field c_15 = {36, (cob_u8_ptr)"Both of numbers are greater than 100", &a_1}; + + +/* Strings */ +static const char st_1[] = "DISPLAY"; +static const char st_2[] = "ACCEPT"; +static const char st_3[] = "IF"; +static const char st_4[] = "STOP RUN"; + + +/* Source file names */ +static const char *st_source_files[] = { "" + ,"hellocobol_if.cob"}; diff --git a/tests/hellocobol/hellocobol_if.c.l.h b/tests/hellocobol/hellocobol_if.c.l.h new file mode 100644 index 0000000..3198747 --- /dev/null +++ b/tests/hellocobol/hellocobol_if.c.l.h @@ -0,0 +1,44 @@ +/* Generated by cobc 3.1.2.0 */ +/* Generated from hellocobol_if.cob */ +/* Generated at Aug 04 2025 19:27:10 */ +/* GnuCOBOL build date Jul 15 2023 12:00:00 */ +/* GnuCOBOL package date Dec 23 2020 12:04:58 UTC */ +/* Compile command cobc -x -g -o hellocobol_if hellocobol_if.cob */ + +/* Program local variables for '01_IF' */ + +/* Module initialization indicator */ +static unsigned int initialized = 0; + +/* Module structure pointer */ +static cob_module *module = NULL; + +/* Global variable pointer */ +cob_global *cob_glob_ptr; + + +/* Call parameters */ +cob_field *cob_procedure_params[1]; + +/* Perform frame stack */ +struct cob_frame *frame_overflow; +struct cob_frame *frame_ptr; +struct cob_frame frame_stack[255]; + + +/* Data storage */ +static int b_2; /* RETURN-CODE */ +static cob_u8_t b_8[9] __attribute__((aligned)); /* var-num1 */ +static cob_u8_t b_10[9] __attribute__((aligned)); /* var-num2 */ +static cob_u8_t b_12[9] __attribute__((aligned)); /* var-data */ + +/* End of local data storage */ + + +/* Fields (local) */ +static cob_field f_8 = {9, b_8, &a_2}; /* var-num1 */ +static cob_field f_10 = {9, b_10, &a_2}; /* var-num2 */ +static cob_field f_12 = {9, b_12, &a_3}; /* var-data */ + +/* End of fields */ + diff --git a/tests/hellocobol/hellocobol_if.cob b/tests/hellocobol/hellocobol_if.cob new file mode 100644 index 0000000..b9d6eda --- /dev/null +++ b/tests/hellocobol/hellocobol_if.cob @@ -0,0 +1,79 @@ + IDENTIFICATION DIVISION. + PROGRAM-ID. 01_IF. + + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 var-num1 PIC S9(9) VALUE 0. + 88 var-pass1 VALUES ARE 100 THRU 9999. + 01 var-num2 PIC S9(9) VALUE 1. + 88 var-pass2 VALUES ARE 100 THRU 9999. + 01 var-data PIC X(9) VALUE ' '. + + + PROCEDURE DIVISION. + + DISPLAY 'ENTER number 1: ' + ACCEPT var-num1. + + DISPLAY 'ENTER number 2: ' + ACCEPT var-num2. + + DISPLAY 'ENTER some data: ' + ACCEPT var-data. + + IF var-num1>var-num2 THEN + DISPLAY 'Number1 is greater than Number2' + ELSE + IF var-num1 = var-num2 THEN + DISPLAY 'Number1 equals Number2' + ELSE + DISPLAY 'Number1 is less than Number2' + END-IF + END-IF. + + + IF var-num1 IS POSITIVE then + DISPLAY 'Number1 is positive' + END-IF. + + IF var-num1 IS NEGATIVE then + DISPLAY 'Number1 is negative' + END-IF. + + + IF var-data IS NUMERIC THEN + * It's false because var-data is X(9). + DISPLAY 'Numeric data' + END-IF. + + IF var-data IS ALPHABETIC THEN + DISPLAY 'Alphabetic data' + END-IF. + + + + IF var-pass1 THEN + DISPLAY 'Number1 is greater than 100' + END-IF. + + IF NOT var-pass1 THEN + DISPLAY 'Number1 is less than 100' + END-IF. + + IF var-pass2 THEN + DISPLAY 'Number2 is greater than 100' + END-IF. + + IF NOT var-pass2 THEN + DISPLAY 'Number2 is less than 100' + END-IF. + + + IF var-pass1 AND var-pass2 THEN + DISPLAY 'Both of numbers are greater than 100' + END-IF. + + STOP RUN. + + + diff --git a/tests/hellocobol/hellocobol_variables b/tests/hellocobol/hellocobol_variables new file mode 100755 index 0000000..e83f5eb Binary files /dev/null and b/tests/hellocobol/hellocobol_variables differ diff --git a/tests/hellocobol/hellocobol_variables.c b/tests/hellocobol/hellocobol_variables.c new file mode 100644 index 0000000..75408c0 --- /dev/null +++ b/tests/hellocobol/hellocobol_variables.c @@ -0,0 +1,258 @@ +/* Generated by cobc 3.1.2.0 */ +/* Generated from hellocobol_variables.cob */ +/* Generated at Aug 04 2025 19:18:38 */ +/* GnuCOBOL build date Jul 15 2023 12:00:00 */ +/* GnuCOBOL package date Dec 23 2020 12:04:58 UTC */ +/* Compile command cobc -x -g -o hellocobol_variables hellocobol_variables.cob */ + +#include +#include +#define COB_KEYWORD_INLINE __inline +#include + +#define COB_SOURCE_FILE "hellocobol_variables.cob" +#define COB_PACKAGE_VERSION "3.1.2" +#define COB_PATCH_LEVEL 0 +#define COB_MODULE_FORMATTED_DATE "Aug 04 2025 19:18:38" +#define COB_MODULE_DATE 20250804 +#define COB_MODULE_TIME 191838 + +/* Global variables */ +#include "hellocobol_variables.c.h" + +/* Function prototypes */ + +static int _02_VARIABLES (); +static int _02_VARIABLES_ (const int); +static void _02_VARIABLES_module_init (cob_module *module); + +/* Main function */ +int +main (int argc, char **argv) +{ + cob_init (argc, argv); + cob_stop_run (_02_VARIABLES ()); +} + +/* Functions */ + +/* PROGRAM-ID '02_VARIABLES' */ + +/* ENTRY '_02_VARIABLES' */ + +static int +_02_VARIABLES () +{ + return _02_VARIABLES_ (0); +} + +static int +_02_VARIABLES_ (const int entry) +{ + /* Program local variables */ + #include "hellocobol_variables.c.l.h" + + /* Start of function code */ + + /* CANCEL callback */ + if (unlikely(entry < 0)) { + if (entry == -10) + goto P_dump; + if (entry == -20) + goto P_clear_decimal; + goto P_cancel; + } + + /* Check initialized, check module allocated, */ + /* set global pointer, */ + /* push module stack, save call parameter count */ + if (cob_module_global_enter (&module, &cob_glob_ptr, 0, entry, 0)) + return -1; + + /* Set address of module parameter list */ + module->cob_procedure_params = cob_procedure_params; + + /* Set frame stack pointer */ + frame_ptr = frame_stack; + frame_ptr->perform_through = 0; + frame_ptr->return_address_ptr = &&P_cgerror; + frame_overflow = frame_ptr + 255 - 1; + + /* Initialize rest of program */ + if (unlikely(initialized == 0)) { + goto P_initialize; + } + P_ret_initialize: + + /* Increment module active */ + module->module_active++; + + /* Entry dispatch */ + goto l_2; + + /* PROCEDURE DIVISION */ + + /* Line: 28 : Entry 02_VARIABLES : hellocobol_variables.cob */ + l_2:; +#line 28 "hellocobol_variables.cob" + ENTRY_02_VARIABLES:; +#line 100 "hellocobol_variables.c" +#line 29 "hellocobol_variables.cob" + SECTION_MAIN_20SECTION:; +#line 103 "hellocobol_variables.c" +#line 29 "hellocobol_variables.cob" + cob_nop (); +#line 106 "hellocobol_variables.c" + + /* Line: 29 : DISPLAY : hellocobol_variables.cob */ + module->module_stmt = 0x0010001D; +#line 29 "hellocobol_variables.cob" + cob_trace_stmt (st_1); +#line 112 "hellocobol_variables.c" + cob_display (0, 1, 1, &f_8); + + /* Line: 30 : DISPLAY : hellocobol_variables.cob */ + module->module_stmt = 0x0010001E; +#line 30 "hellocobol_variables.cob" + cob_trace_stmt (st_1); +#line 119 "hellocobol_variables.c" + cob_display (0, 1, 1, &f_16); + + /* Line: 32 : MOVE : hellocobol_variables.cob */ + module->module_stmt = 0x00100020; +#line 32 "hellocobol_variables.cob" + cob_trace_stmt (st_2); +#line 126 "hellocobol_variables.c" + memcpy (b_17, "01", 2); + + /* Line: 33 : MOVE : hellocobol_variables.cob */ + module->module_stmt = 0x00100021; +#line 33 "hellocobol_variables.cob" + cob_trace_stmt (st_2); +#line 133 "hellocobol_variables.c" + cob_move ((cob_field *)&c_1, &f_20); + + /* Line: 35 : DISPLAY : hellocobol_variables.cob */ + module->module_stmt = 0x00100023; +#line 35 "hellocobol_variables.cob" + cob_trace_stmt (st_1); +#line 140 "hellocobol_variables.c" + cob_display (0, 1, 1, &f_17); + + /* Line: 36 : STOP RUN : hellocobol_variables.cob */ + module->module_stmt = 0x00100024; +#line 36 "hellocobol_variables.cob" + cob_trace_stmt (st_3); +#line 147 "hellocobol_variables.c" + cob_stop_run (b_2); + + module->module_stmt = 0x00100026; + + /* Program exit */ + + /* Decrement module active count */ + if (module->module_active) { + module->module_active--; + } + + /* Pop module stack */ + cob_module_leave (module); + + /* Program return */ + return b_2; + P_cgerror: + cob_fatal_error (COB_FERROR_CODEGEN); + + + /* Program initialization */ + P_initialize: + + cob_check_version (COB_SOURCE_FILE, COB_PACKAGE_VERSION, COB_PATCH_LEVEL); + + cob_module_path = cob_glob_ptr->cob_main_argv0; + + _02_VARIABLES_module_init (module); + + module->crt_status = NULL; + + /* Initialize cancel callback */ + cob_set_cancel (module); + + /* Initialize WORKING-STORAGE */ + b_2 = 0; + memcpy (b_8, "lp", 2); + *(cob_u8_ptr)(b_8 + 2) = 124; + memcpy (b_8 + 3, " number", 10); + *(cob_u8_ptr)(b_8 + 13) = 124; + memcpy (b_8 + 14, " decimal", 10); + *(cob_u8_ptr)(b_8 + 24) = 124; + memcpy (b_8 + 25, " currency", 10); + memset (b_16, 45, 80); + memset (b_17, 48, 2); + *(cob_u8_ptr)(b_17 + 2) = 124; + cob_move ((cob_field *)&c_2, &f_20); + *(cob_u8_ptr)(b_17 + 13) = 124; + cob_move ((cob_field *)&c_3, COB_SET_FLD(f0, 11, b_17 + 14, &a_7)); + *(cob_u8_ptr)(b_17 + 25) = 124; + cob_move ((cob_field *)&c_4, COB_SET_FLD(f0, 11, b_17 + 26, &a_9)); + + if (0 == 1) goto P_cgerror; + initialized = 1; + goto P_ret_initialize; + + P_dump: + return 0; + + + /* CANCEL callback handling */ + P_cancel: + + if (!initialized) + return 0; + if (module && module->module_active) + cob_fatal_error (COB_FERROR_CANCEL); + + initialized = 0; + + P_clear_decimal: + return 0; + +} + +/* End PROGRAM-ID '02_VARIABLES' */ + +/* Initialize module structure for 02_VARIABLES */ +static void _02_VARIABLES_module_init (cob_module *module) +{ + module->module_name = "02_VARIABLES"; + module->module_formatted_date = COB_MODULE_FORMATTED_DATE; + module->module_source = COB_SOURCE_FILE; + module->module_entry.funcptr = (void *(*)())_02_VARIABLES; + module->module_cancel.funcptr = (void *(*)())_02_VARIABLES_; + module->module_ref_count = NULL; + module->module_path = &cob_module_path; + module->module_active = 0; + module->module_date = COB_MODULE_DATE; + module->module_time = COB_MODULE_TIME; + module->module_type = 0; + module->module_param_cnt = 0; + module->ebcdic_sign = 0; + module->decimal_point = '.'; + module->currency_symbol = '$'; + module->numeric_separator = ','; + module->flag_filename_mapping = 1; + module->flag_binary_truncate = 1; + module->flag_pretty_display = 1; + module->flag_host_sign = 0; + module->flag_no_phys_canc = 1; + module->flag_main = 1; + module->flag_fold_call = 0; + module->flag_exit_program = 0; + module->flag_debug_trace = 0; + module->flag_dump_ready = 0; + module->module_stmt = 0; + module->module_sources = st_source_files; +} + +/* End functions */ + diff --git a/tests/hellocobol/hellocobol_variables.c.h b/tests/hellocobol/hellocobol_variables.c.h new file mode 100644 index 0000000..1b34a70 --- /dev/null +++ b/tests/hellocobol/hellocobol_variables.c.h @@ -0,0 +1,65 @@ +/* Generated by cobc 3.1.2.0 */ +/* Generated from hellocobol_variables.cob */ +/* Generated at Aug 04 2025 19:18:38 */ +/* GnuCOBOL build date Jul 15 2023 12:00:00 */ +/* GnuCOBOL package date Dec 23 2020 12:04:58 UTC */ +/* Compile command cobc -x -g -o hellocobol_variables hellocobol_variables.cob */ + + +/* Module path */ +static const char *cob_module_path = NULL; + +/* Number of call parameters */ +static int cob_call_params = 0; + +/* Picture strings */ + +static const cob_pic_symbol p_1[] = { + {'Z', 10}, + {'\0', 1} +}; +static const cob_pic_symbol p_2[] = { + {'+', 1}, + {'Z', 7}, + {'.', 1}, + {'Z', 2}, + {'\0', 1} +}; +static const cob_pic_symbol p_3[] = { + {'$', 1}, + {'Z', 7}, + {'.', 1}, + {'Z', 2}, + {'\0', 1} +}; + + +/* Attributes */ + +static const cob_field_attr a_1 = {0x01, 0, 0, 0x0000, NULL}; +static const cob_field_attr a_2 = {0x21, 0, 0, 0x0000, NULL}; +static const cob_field_attr a_3 = {0x10, 4, 0, 0x1000, NULL}; +static const cob_field_attr a_4 = {0x24, 10, 0, 0x0000, p_1}; +static const cob_field_attr a_5 = {0x10, 1, 0, 0x1000, NULL}; +static const cob_field_attr a_6 = {0x10, 5, 2, 0x0007, NULL}; +static const cob_field_attr a_7 = {0x24, 9, 2, 0x0001, p_2}; +static const cob_field_attr a_8 = {0x10, 5, 2, 0x1000, NULL}; +static const cob_field_attr a_9 = {0x24, 9, 2, 0x0000, p_3}; + + +/* Constants */ +static const cob_field c_1 = {4, (cob_u8_ptr)"3721", &a_3}; +static const cob_field c_2 = {1, (cob_u8_ptr)"0", &a_5}; +static const cob_field c_3 = {6, (cob_u8_ptr)"-31721", &a_6}; +static const cob_field c_4 = {5, (cob_u8_ptr)"31721", &a_8}; + + +/* Strings */ +static const char st_1[] = "DISPLAY"; +static const char st_2[] = "MOVE"; +static const char st_3[] = "STOP RUN"; + + +/* Source file names */ +static const char *st_source_files[] = { "" + ,"hellocobol_variables.cob"}; diff --git a/tests/hellocobol/hellocobol_variables.c.l.h b/tests/hellocobol/hellocobol_variables.c.l.h new file mode 100644 index 0000000..16da3d1 --- /dev/null +++ b/tests/hellocobol/hellocobol_variables.c.l.h @@ -0,0 +1,49 @@ +/* Generated by cobc 3.1.2.0 */ +/* Generated from hellocobol_variables.cob */ +/* Generated at Aug 04 2025 19:18:38 */ +/* GnuCOBOL build date Jul 15 2023 12:00:00 */ +/* GnuCOBOL package date Dec 23 2020 12:04:58 UTC */ +/* Compile command cobc -x -g -o hellocobol_variables hellocobol_variables.cob */ + +/* Program local variables for '02_VARIABLES' */ + +/* Module initialization indicator */ +static unsigned int initialized = 0; + +/* Module structure pointer */ +static cob_module *module = NULL; + +/* Global variable pointer */ +cob_global *cob_glob_ptr; + + +/* Local cob_field items */ +cob_field f0; + + +/* Call parameters */ +cob_field *cob_procedure_params[1]; + +/* Perform frame stack */ +struct cob_frame *frame_overflow; +struct cob_frame *frame_ptr; +struct cob_frame frame_stack[255]; + + +/* Data storage */ +static int b_2; /* RETURN-CODE */ +static cob_u8_t b_8[35] __attribute__((aligned)); /* struct-headers */ +static cob_u8_t b_16[80] __attribute__((aligned)); /* var-line */ +static cob_u8_t b_17[37] __attribute__((aligned)); /* struct-row */ + +/* End of local data storage */ + + +/* Fields (local) */ +static cob_field f_8 = {35, b_8, &a_1}; /* struct-headers */ +static cob_field f_16 = {80, b_16, &a_2}; /* var-line */ +static cob_field f_17 = {37, b_17, &a_1}; /* struct-row */ +static cob_field f_20 = {10, b_17 + 3, &a_4}; /* var-number */ + +/* End of fields */ + diff --git a/tests/hellocobol/hellocobol_variables.cob b/tests/hellocobol/hellocobol_variables.cob new file mode 100644 index 0000000..a3cad0f --- /dev/null +++ b/tests/hellocobol/hellocobol_variables.cob @@ -0,0 +1,37 @@ + IDENTIFICATION DIVISION. + PROGRAM-ID. 02_VARIABLES. + + DATA DIVISION. + WORKING-STORAGE SECTION. + + 01 struct-headers. + 02 filler PIC x(2) VALUE "lp". + 02 filler PIC x VALUE "|". + 02 filler PIC x(10) VALUE " number". + 02 filler PIC x VALUE "|". + 02 filler PIC x(10) VALUE " decimal". + 02 filler PIC x VALUE "|". + 02 filler PIC x(10) VALUE " currency". + + + 01 var-line PIC x(80) VALUE ALL "-". + + 01 struct-row. + 02 var-lp PIC 9(2) VALUE 00. + 02 filler PIC x VALUE "|". + 02 var-number PIC z(10) VALUE 0. + 02 filler PIC x VALUE "|". + 02 var-decimal PIC +z(7).zz VALUE -317.21. + 02 filler PIC x VALUE "|". + 02 var-currency PIC $z(7).zz VALUE 317.21. + + PROCEDURE DIVISION. + DISPLAY struct-headers. + DISPLAY var-line. + + MOVE 01 TO var-lp. + MOVE 3721 TO var-number. + + DISPLAY struct-row. + STOP RUN. +