From e0f9dc0e9a5ea683ac44b57e08ce94f6a4990e4b Mon Sep 17 00:00:00 2001 From: enet Upstream Date: Thu, 8 Jun 2023 19:56:59 -0400 Subject: [PATCH 1/7] enet 2023-06-08 (f93beb4e) Code extracted from: https://github.com/GTkorvo/enet.git at commit f93beb4e7d8179e2b38a88a40b595649f2405913 (master). Upstream Shortlog ----------------- --- CMakeLists.txt | 19 +++++++++++++++++++ ChangeLog | 21 +++++++++++++++++++++ LICENSE | 2 +- README | 2 +- include/enet/enet.h | 3 ++- unix.c | 13 +++++++++++-- win32.c | 14 ++++++++++++-- 7 files changed, 67 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b9b78e6a1d..bd32600586 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,24 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE RelWithDebInfo) endif() +if(WIN32) + # Automagic to do the DLL / LIB song and dance + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) + + # Silence MSVC warnings + if(CMAKE_C_COMPILER_ID MATCHES "MSVC" OR + CMAKE_C_SIMULATE_ID MATCHES "MSVC") + add_definitions( + -D_CRT_SECURE_NO_DEPRECATE + -D_CRT_SECURE_NO_WARNINGS + -D_SCL_SECURE_NO_DEPRECATE + -D_WINSOCK_DEPRECATED_NO_WARNINGS + -D_CRT_NONSTDC_NO_DEPRECATE + -DENET_SRC) + set (MSVC_PERL_FLAGS "-msvc-long") + endif() +endif() + include(CMakeDependentOption) # Setup shared library defaults. If explicitly specified somehow, then default @@ -111,6 +129,7 @@ if(UNIX) target_sources(enet PRIVATE unix.c) elseif(WIN32) target_sources(enet PRIVATE win32.c) + target_link_libraries(enet wsock32 ws2_32 winmm) endif() target_include_directories(enet PUBLIC $ diff --git a/ChangeLog b/ChangeLog index 663c7b731c..e182076425 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,25 @@ +ENet 1.3.17 (November 15, 2020): + +* fixes for sender getting too far ahead of receiver that can cause instability with reliable packets + +ENet 1.3.16 (September 8, 2020): + +* fix bug in unreliable fragment queuing +* use single output queue for reliable and unreliable packets for saner ordering +* revert experimental throttle changes that were less stable than prior algorithm + +ENet 1.3.15 (April 20, 2020): + +* quicker RTT initialization +* use fractional precision for RTT calculations +* fixes for packet throttle with low RTT variance +* miscellaneous socket bug fixes + +ENet 1.3.14 (January 27, 2019): + +* bug fix for enet_peer_disconnect_later() * use getaddrinfo and getnameinfo where available +* miscellaneous cleanups ENet 1.3.13 (April 30, 2015): diff --git a/LICENSE b/LICENSE index 39af84a8f6..6906f8eb0b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2002-2016 Lee Salzman +Copyright (c) 2002-2020 Lee Salzman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README b/README index 54b2d21304..3b6318b22a 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -Please visit the ENet homepage at http://enet.bespin.org for installation +Please visit the ENet homepage at http://sauerbraten.org/enet/ for installation and usage instructions. If you obtained this package from github, the quick description on how to build diff --git a/include/enet/enet.h b/include/enet/enet.h index f44ddae9d7..04059b7b5d 100644 --- a/include/enet/enet.h +++ b/include/enet/enet.h @@ -62,7 +62,8 @@ typedef enum _ENetSocketOption ENET_SOCKOPT_RCVTIMEO = 6, ENET_SOCKOPT_SNDTIMEO = 7, ENET_SOCKOPT_ERROR = 8, - ENET_SOCKOPT_NODELAY = 9 + ENET_SOCKOPT_NODELAY = 9, + ENET_SOCKOPT_TTL = 10 } ENetSocketOption; typedef enum _ENetSocketShutdown diff --git a/unix.c b/unix.c index c36a082a89..b54b627dba 100644 --- a/unix.c +++ b/unix.c @@ -149,7 +149,7 @@ enet_address_set_host (ENetAddress * address, const char * name) char buffer [2048]; int errnum; -#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) +#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__GNU__) gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum); #else hostEntry = gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & errnum); @@ -221,7 +221,7 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng in.s_addr = address -> host; -#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) +#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__GNU__) gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum); #else hostEntry = gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & errnum); @@ -349,6 +349,10 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value) result = setsockopt (socket, IPPROTO_TCP, TCP_NODELAY, (char *) & value, sizeof (int)); break; + case ENET_SOCKOPT_TTL: + result = setsockopt (socket, IPPROTO_IP, IP_TTL, (char *) & value, sizeof (int)); + break; + default: break; } @@ -367,6 +371,11 @@ enet_socket_get_option (ENetSocket socket, ENetSocketOption option, int * value) result = getsockopt (socket, SOL_SOCKET, SO_ERROR, value, & len); break; + case ENET_SOCKOPT_TTL: + len = sizeof (int); + result = getsockopt (socket, IPPROTO_IP, IP_TTL, (char *) value, & len); + break; + default: break; } diff --git a/win32.c b/win32.c index 81175a4113..0953466a3d 100644 --- a/win32.c +++ b/win32.c @@ -8,6 +8,7 @@ #include "enet/enet.h" #include #include +#include static enet_uint32 timeBase = 0; @@ -231,6 +232,10 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value) result = setsockopt (socket, IPPROTO_TCP, TCP_NODELAY, (char *) & value, sizeof (int)); break; + case ENET_SOCKOPT_TTL: + result = setsockopt (socket, IPPROTO_IP, IP_TTL, (char *) & value, sizeof (int)); + break; + default: break; } @@ -248,6 +253,11 @@ enet_socket_get_option (ENetSocket socket, ENetSocketOption option, int * value) result = getsockopt (socket, SOL_SOCKET, SO_ERROR, (char *) value, & len); break; + case ENET_SOCKOPT_TTL: + len = sizeof(int); + result = getsockopt (socket, IPPROTO_IP, IP_TTL, (char *) value, & len); + break; + default: break; } @@ -316,7 +326,7 @@ enet_socket_send (ENetSocket socket, size_t bufferCount) { struct sockaddr_in sin; - DWORD sentLength; + DWORD sentLength = 0; if (address != NULL) { @@ -354,7 +364,7 @@ enet_socket_receive (ENetSocket socket, { INT sinLength = sizeof (struct sockaddr_in); DWORD flags = 0, - recvLength; + recvLength = 0; struct sockaddr_in sin; if (WSARecvFrom (socket, From 298e38ad658a1daaf617832f919aaa7c5213b88a Mon Sep 17 00:00:00 2001 From: EVPath Upstream Date: Sat, 10 Jun 2023 07:19:53 -0400 Subject: [PATCH 2/7] EVPath 2023-06-10 (e9be8e63) Code extracted from: https://github.com/GTkorvo/EVPath.git at commit e9be8e635f0e2b578f88957b999601b1fc74dde0 (master). Upstream Shortlog ----------------- --- CMakeLists.txt | 30 +++- chr_time.c | 47 ++++- cm.c | 285 +++++++++++++++-------------- cm_control.c | 8 +- cm_evol.c | 2 +- cm_formats.c | 2 + cm_internal.h | 77 ++++++-- cm_lock.c | 8 +- cm_pbio.c | 8 +- cm_perf.c | 18 +- cm_schedule.h | 3 + cm_threadio.c | 10 +- cm_transport.c | 21 +-- cm_transport.h | 25 ++- cm_util.c | 35 ++-- cmenet.c | 318 +++++++++++++++++++++++++++++---- cmepoll.c | 2 +- cmib.c | 2 +- cmmulticast.c | 63 +++---- cmprobe.c | 7 +- cmselect.c | 197 ++++++++------------ cmsockets.c | 211 +++++++++------------- cmudp.c | 125 +++++-------- config.h.cmake | 4 +- dfg_tests/anon_multi_test.c | 9 + dfg_tests/auto_tree_test.c | 18 +- dfg_tests/delayed_submit.c | 31 +++- dfg_tests/fail_chain_test.c | 20 ++- dfg_tests/metrics_test.c | 4 +- dfg_tests/multi_test.c | 4 +- dfg_tests/router_test.c | 7 + dfg_tests/self_reconfig_test.c | 20 ++- dfg_tests/test_support.c | 12 +- dfg_tests/test_support.h | 4 + dfg_tests/tree_test.c | 18 +- dlloader.c | 77 +++++++- dlloader.h | 9 + ev_dfg.c | 295 +++++++++++++++--------------- ev_internal.h | 8 +- evp.c | 66 +++---- evp_threads.c | 4 +- evpath.h | 12 +- examples/derived_recv.c | 2 +- examples/transform_recv.c | 2 +- examples/transform_recv2.c | 4 +- examples/transform_recv3.c | 4 +- gen_interface.pl | 17 +- ip_config.c | 48 +++-- metrics.c | 97 ++++++---- mtests/bulktest.c | 8 +- mtests/cmconn.c | 13 +- mtests/cmping.c | 11 +- mtests/cmtest.c | 11 +- mtests/support.c | 12 +- mtests/take_test.c | 14 +- mtests/trans_test.c | 49 +++-- qual_hostname.c | 6 +- response.c | 80 +++++---- response.h | 2 +- rtests/evtest.c | 8 +- rtests/extract_test.c | 7 +- rtests/remote_terminal_test.c | 7 +- tests/auto_test.c | 3 +- tests/bulktest.c | 71 ++++---- tests/evtest.c | 7 +- tests/executing_stone_test.c | 10 ++ tests/extract_test.c | 3 +- tests/filter2_test.c | 3 +- tests/filter_test.c | 7 +- tests/http_test.c | 3 +- tests/multi_thread.c | 2 + tests/multiq_test.c | 3 +- tests/no_type_router_test.c | 3 +- tests/rawtest.c | 7 +- tests/rawtest2.c | 5 +- tests/router_test.c | 3 +- tests/router_test2.c | 3 +- tests/split_test.c | 23 +-- tests/submit_test.c | 3 +- tests/support.c | 20 ++- tests/take_test.c | 2 +- tests/testdll/foo.c | 7 +- tests/thin_client.c | 24 ++- tests/thin_test.c | 3 + tests/transform_test.c | 9 +- thin_server.c | 28 ++- 86 files changed, 1728 insertions(+), 1052 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5f8111c06..532494d68e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,23 @@ if(NOT MSVC) set(CMAKE_C_STANDARD_REQUIRED True) endif() +if(WIN32) + # Automagic to do the DLL / LIB song and dance + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) + + # Silence MSVC warnings + if(CMAKE_C_COMPILER_ID MATCHES "MSVC" OR + CMAKE_C_SIMULATE_ID MATCHES "MSVC") + add_definitions( + -D_CRT_SECURE_NO_DEPRECATE + -D_CRT_SECURE_NO_WARNINGS + -D_SCL_SECURE_NO_DEPRECATE + -D_WINSOCK_DEPRECATED_NO_WARNINGS + -D_CRT_NONSTDC_NO_DEPRECATE) + set (MSVC_PERL_FLAGS "-msvc-long") + endif() +endif() + set(CPACK_DEBIAN_PACKAGE_DEPENDS "dill, atl, ffs") set(CPACK_RPM_PACKAGE_REQUIRES "dill, atl, ffs") set(ENABLE_SOMETHING AUTO CACHE STRING "Enable SOMETHING support") # @@ -201,7 +218,7 @@ cmake_dependent_option(EVPATH_TRANSPORT_MODULES list(INSERT CMAKE_PREFIX_PATH 0 ${CMAKE_INSTALL_PREFIX}) find_package(atl 2.2.1 REQUIRED) -find_package(ffs 2.0.0 REQUIRED) +find_package(ffs 3.0.0 REQUIRED) _pkg_get_target_prefix(atl::atl atl_PREFIX) _pkg_get_target_prefix(ffs::ffs ffs_PREFIX) list(APPEND _pkg_config_pfxs "${atl_PREFIX}" "${ffs_PREFIX}") @@ -214,7 +231,7 @@ else() unset(CMAKE_REQUIRED_LIBRARIES) endif() if (HAVE_COD_H) - find_package(dill 2.3.1 REQUIRED) + find_package(dill 3.0.0 REQUIRED) target_link_libraries(EVPath PUBLIC atl::atl ffs::ffs PRIVATE dill::dill) _pkg_get_target_prefix(dill::dill dill_PREFIX) list(APPEND _pkg_config_private_reqs "dill >= ${dill_VERSION}") @@ -354,6 +371,9 @@ else() message(STATUS " - Enet library was not found. This is not a fatal error, just that the Enet transport will not be built.") endif() +if (MSVC) + set(EVPATH_USE_ZPL_ENET FALSE) +endif() if(NOT (DEFINED EVPATH_USE_ZPL_ENET)) option(EVPATH_USE_ZPL_ENET "Build the enet transport" "ON") endif() @@ -486,6 +506,10 @@ if(IBVERBS_FOUND) endif() endif() + if(WIN32) + target_link_libraries(EVPath wsock32 ws2_32) + endif() + if(EVPATH_TRANSPORT_MODULES) add_library(cmib MODULE cmib.c) set_target_properties(cmib PROPERTIES @@ -593,7 +617,7 @@ CHECK_INCLUDE_FILE(sys/uio.h HAVE_SYS_UIO_H) CHECK_INCLUDE_FILE(sys/un.h HAVE_SYS_UN_H) CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H) CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H) -CHECK_INCLUDE_FILE(winsock.h HAVE_WINSOCK_H) +CHECK_INCLUDE_FILE(winsock2.h HAVE_WINSOCK2_H) CHECK_STRUCT_HAS_MEMBER("struct fd_set" "fds_bits" "sys/select.h" HAVE_FDS_BITS) diff --git a/chr_time.c b/chr_time.c index 5daa4e6409..0cbd146b6d 100644 --- a/chr_time.c +++ b/chr_time.c @@ -2,12 +2,30 @@ #include "stdlib.h" #include "chr_time.h" +#ifdef HAVE_SYS_TIME_H #include +#endif +#ifdef _MSC_VER +#include +#include +#include +#endif extern void chr_get_time( chr_time *time) { - gettimeofday((struct timeval *) time, NULL); +#ifdef HAVE_GETTIMEOFDAY + gettimeofday((struct timeval*)time, NULL); +#else + /* GSE... No gettimeofday on windows. + * Must use _ftime, get millisec time, convert to usec. Bleh. + */ + struct _timeb nowb; + _ftime(&nowb); + ((struct timeval*)time)->tv_sec = (long)nowb.time; + ((struct timeval*)time)->tv_usec = nowb.millitm * 1000; +#endif + // gettimeofday((struct timeval *) time, NULL); } extern void @@ -22,7 +40,18 @@ chr_timer_stop( chr_time *time) struct timeval now; struct timeval duration; - gettimeofday(&now, NULL); +#ifndef HAVE_WINDOWS_H + gettimeofday((struct timeval*)&now, NULL); +#else + /* GSE... No gettimeofday on windows. + * Must use _ftime, get millisec time, convert to usec. Bleh. + */ + struct _timeb nowb; + _ftime(&nowb); + ((struct timeval*)&now)->tv_sec = (long)nowb.time; + ((struct timeval*)&now)->tv_usec = nowb.millitm * 1000; +#endif +// gettimeofday(&now, NULL); chr_timer_diff((chr_time*)&duration, (chr_time*)&now, time); *((struct timeval *) time) = duration; } @@ -96,12 +125,24 @@ chr_time_to_nanosecs(chr_time *time) extern double chr_approx_resolution() { - struct timeval start, stop, diff; + struct timeval diff; +#ifndef HAVE_WINDOWS_H + struct timeval start, stop; gettimeofday(&start, NULL); gettimeofday(&stop, NULL); while(start.tv_usec == stop.tv_usec) { gettimeofday(&stop, NULL); } chr_timer_diff((chr_time*)&diff, (chr_time*)&stop, (chr_time*)&start); +#else + struct _timeb start, stop; + _ftime(&start); + _ftime(&stop); + while (start.millitm == stop.millitm) { + _ftime(&stop); + } + diff.tv_sec = 0; + diff.tv_usec = (stop.millitm - start.millitm) * 1000; +#endif return chr_time_to_secs((chr_time*)&diff); } diff --git a/cm.c b/cm.c index 2e50831ca1..9b1d5e45f1 100644 --- a/cm.c +++ b/cm.c @@ -17,13 +17,16 @@ #include #include #ifdef HAVE_WINDOWS_H -#include +#include #define __ANSI_CPP__ #else #include #include #endif +#ifdef HAVE_SYS_TIME_H #include +#endif +#include #include #include #include "evpath.h" @@ -115,7 +118,7 @@ static void INT_CMControlList_close(CMControlList cl, CManager cm); static int CMcontrol_list_poll(CMControlList cl); int CMdo_non_CM_handler(CMConnection conn, int header, char *buffer, size_t length); -void CMdo_performance_response(CMConnection conn, long length, +void CMdo_performance_response(CMConnection conn, size_t length, int func, int byte_swap, char *buffer); @@ -124,11 +127,11 @@ static void CM_init_select(CMControlList cl, CManager cm); static void cond_wait_CM_lock(CManager cm, void *vcond, char *file, int line) { - pthread_cond_t *cond = vcond; + thr_condition_t *cond = vcond; CMtrace_out(cm, CMLowLevelVerbose, "CManager Condition wait at \"%s\" line %d\n", file, line); cm->locked--; - pthread_cond_wait(cond, &cm->exchange_lock); + thr_condition_wait(*cond, cm->exchange_lock); CMtrace_out(cm, CMLowLevelVerbose, "CManager Condition wake at \"%s\" line %d\n", file, line); cm->locked++; @@ -171,7 +174,7 @@ CMpoll_forever(CManager cm) should_exit++; } while(!cl->closed) { - CMtrace_out(cm, CMLowLevelVerbose, "CM Poll Forever - thread %lx doing wait\n", (long)thr_thread_self()); + CMtrace_out(cm, CMLowLevelVerbose, "CM Poll Forever - thread %zx doing wait\n", (size_t)thr_thread_self()); if (CMcontrol_list_wait(cl) == -1) { CMtrace_out(cm, CMLowLevelVerbose, "CM Poll Forever - doing close and exit\n"); /* @@ -210,7 +213,7 @@ INT_CMrun_network(CManager cm) /* What? We're polling, but we're not the server thread? */ fprintf(stderr, "Warning: CMrun_network() called when another thread may already be handling the network\n"); fprintf(stderr, " This situation may result in unexpected I/O blocking.\n"); - fprintf(stderr, " Server thread set to %lx.\n", (long) thr_thread_self()); + fprintf(stderr, " Server thread set to %zx.\n", (size_t) thr_thread_self()); } cm->control_list->server_thread = thr_thread_self(); cm->control_list->has_thread = 1; @@ -225,14 +228,12 @@ CM_test_thread_func() } static thr_thread_t -thr_fork(func, arg) -void*(*func)(void*); -void *arg; +thr_fork(void*(*func)(void*), void *arg) { - pthread_t new_thread = 0; - int err = pthread_create(&new_thread, NULL, (void*(*)(void*))func, arg); + thr_thread_t new_thread = 0; + int err = thr_thread_create(&new_thread, NULL, (void*(*)(void*))func, arg); if (err != 0) { - return (thr_thread_t) NULL; + return (thr_thread_t) (intptr_t)NULL; } else { return (thr_thread_t) new_thread; } @@ -252,15 +253,15 @@ INT_CMfork_comm_thread(CManager cm) thr_fork((void*(*)(void*))server_thread_func, (void*)cm); CMtrace_out(cm, CMLowLevelVerbose, - "CM - Forked comm thread %lx\n", (long)server_thread); - if (server_thread == (thr_thread_t) NULL) { + "CM - Forked comm thread %p\n", (void*)(intptr_t)server_thread); + if (server_thread == (thr_thread_t)(intptr_t) NULL) { return 0; } cm->control_list->server_thread = server_thread; cm->control_list->has_thread = 1; cm->reference_count++; - CMtrace_out(cm, CMFreeVerbose, "Forked - CManager %lx ref count now %d\n", - (long) cm, cm->reference_count); + CMtrace_out(cm, CMFreeVerbose, "Forked - CManager %p ref count now %d\n", + cm, cm->reference_count); cm->control_list->cl_reference_count++; cm->control_list->free_reference_count++; } else { @@ -271,7 +272,7 @@ INT_CMfork_comm_thread(CManager cm) thr_thread_t test_thread = thr_fork((void*(*)(void*))CM_test_thread_func, (void*)cm); - if (test_thread == (thr_thread_t) NULL) { + if (test_thread == (thr_thread_t)(intptr_t) NULL) { /* No. Say we can't. */ CMtrace_out(cm, CMLowLevelVerbose, "CM - Test fork failed, no comm thread\n"); @@ -540,12 +541,12 @@ CMinternal_listen(CManager cm, attr_list listen_info, int try_others) int success = 0; transport_entry *trans_list; char *chosen_transport = NULL; - char *interface = NULL; + char *iface = NULL; if (listen_info) { listen_info = split_transport_attributes(attr_copy_list(listen_info)); get_string_attr(listen_info, CM_TRANSPORT, &chosen_transport); - get_string_attr(listen_info, CM_IP_INTERFACE, &interface); + get_string_attr(listen_info, CM_IP_INTERFACE, &iface); } if (chosen_transport != NULL) { CMtrace_out(cm, CMConnectionVerbose, @@ -573,8 +574,8 @@ CMinternal_listen(CManager cm, attr_list listen_info, int try_others) attrs = (*trans_list)->listen(cm, &CMstatic_trans_svcs, *trans_list, listen_info); - if (interface) { - add_string_attr(attrs, CM_IP_INTERFACE, strdup(interface)); + if (iface) { + add_string_attr(attrs, CM_IP_INTERFACE, strdup(iface)); } add_contact_list(cm, attrs); if (CMtrace_on(cm, CMConnectionVerbose)) { @@ -697,7 +698,7 @@ CMcontrol_list_wait(CMControlList cl) /* What? We're polling, but we're not the server thread? */ fprintf(stderr, "Warning: Multiple threads calling CMnetwork_wait\n"); fprintf(stderr, " This situation may result in unexpected I/O blocking.\n"); - fprintf(stderr, " Server thread set to %lx.\n", (long) thr_thread_self()); + fprintf(stderr, " Server thread set to %zx.\n", (size_t) thr_thread_self()); } cl->server_thread = thr_thread_self(); if (cl->network_blocking_function.func != NULL) { @@ -721,6 +722,16 @@ INT_CManager_create() return INT_CManager_create_control(NULL); } +static void +atl_mutex_lock(void* lock) +{ + thr_mutex_lock(*((thr_mutex_t*)lock)); +} +static void +atl_mutex_unlock(void* lock) +{ + thr_mutex_unlock(*((thr_mutex_t*)lock)); +} extern CManager INT_CManager_create_control(char *control_module) @@ -731,7 +742,7 @@ INT_CManager_create_control(char *control_module) if (!atl_mutex_initialized) { atl_mutex_initialized++; thr_mutex_init(atl_mutex); - atl_install_mutex_funcs((atl_lock_func)pthread_mutex_lock, (atl_lock_func)pthread_mutex_unlock, + atl_install_mutex_funcs((atl_lock_func)atl_mutex_lock, (atl_lock_func)atl_mutex_unlock, &atl_mutex); } if (cm == NULL) @@ -882,7 +893,7 @@ CManager_free(CManager cm) i=0; while (list != NULL) { CMbuffer next = list->next; - CMtrace_out(cm, CMBufferVerbose, "Final buffer disposition buf %d, %p, size %ld, ref_count %d\n", i++, list, list->size, list->ref_count); + CMtrace_out(cm, CMBufferVerbose, "Final buffer disposition buf %d, %p, size %zd, ref_count %d\n", i++, list, list->size, list->ref_count); if (list->return_callback) { (list->return_callback)(list->return_callback_data); } else { @@ -911,10 +922,10 @@ CManager_free(CManager cm) CMtrace_out(cm, CMFreeVerbose, "CManager %p closing, ref count %d\n", cm, cm->reference_count); - CMtrace_out(cm, CMFreeVerbose, "CMControlList close CL=%lx current reference count will be %d, sdp = %p\n", - (long) cl, cl->cl_reference_count - 1, cl->select_data); + CMtrace_out(cm, CMFreeVerbose, "CMControlList close CL=%p current reference count will be %d, sdp = %p\n", + cl, cl->cl_reference_count - 1, cl->select_data); INT_CMControlList_close(cl, cm); - CMtrace_out(cm, CMFreeVerbose, "CMControlList CL=%lx is closed\n", (long) cl); + CMtrace_out(cm, CMFreeVerbose, "CMControlList CL=%p is closed\n", cl); while (cm->connection_count != 0) { /* connections are moved down as they are closed... */ @@ -930,7 +941,7 @@ CManager_free(CManager cm) while (shutdown_functions[i].func != NULL) { if (shutdown_functions[i].task_type == SHUTDOWN_TASK) { - CMtrace_out(cm, CMFreeVerbose, "CManager calling shutdown function SHUTDOWN %d, %lx\n", i, (long)shutdown_functions[i].func); + CMtrace_out(cm, CMFreeVerbose, "CManager calling shutdown function SHUTDOWN %d, %p\n", i, shutdown_functions[i].func); shutdown_functions[i].func(cm, shutdown_functions[i].client_data); shutdown_functions[i].task_type = NO_TASK; } @@ -952,7 +963,7 @@ CManager_free(CManager cm) i--; for ( ; i >= 0; i--) { if (shutdown_functions[i].task_type == FREE_TASK) { - CMtrace_out(cm, CMFreeVerbose, "CManager calling shutdown function FREE %d, %lx\n", i, (long)shutdown_functions[i].func); + CMtrace_out(cm, CMFreeVerbose, "CManager calling shutdown function FREE %d, %p\n", i, shutdown_functions[i].func); shutdown_functions[i].func(cm, shutdown_functions[i].client_data); shutdown_functions[i].func = NULL; } @@ -1041,7 +1052,7 @@ CManager_free(CManager cm) new_list->select_data = NULL; new_list->add_select = NULL; new_list->remove_select = NULL; - new_list->server_thread = (thr_thread_t) NULL; + new_list->server_thread = (thr_thread_t)(intptr_t) NULL; new_list->network_blocking_function.func = NULL; new_list->network_polling_function.func = NULL; new_list->polling_function_list = NULL; @@ -1116,8 +1127,8 @@ CManager_free(CManager cm) conn->do_non_blocking_write = !blocking_on_conn; } add_conn_to_CM(trans->cm, conn); - CMtrace_out(trans->cm, CMFreeVerbose, "CMConnection_create %lx \n", - (long) conn); + CMtrace_out(trans->cm, CMFreeVerbose, "CMConnection_create %p \n", + conn); return conn; } @@ -1172,19 +1183,19 @@ CManager_free(CManager cm) extern int INT_CMConnection_set_character(CMConnection conn, attr_list attrs) { - long interval_value; + ssize_t interval_value; if (attrs == NULL) return 0; if (get_long_attr(attrs, CM_BW_MEASURE_INTERVAL, &interval_value)) { bw_measure_data data; int previous_interval; CMTaskHandle task = NULL; if ((interval_value <= 1) || (interval_value > 60*60*8)) { - printf("Bad CM_BW_MEASURE_INTERVAL, %ld seconds\n", + printf("Bad CM_BW_MEASURE_INTERVAL, %zd seconds\n", interval_value); return 0; } - CMtrace_out(conn->cm, CMLowLevelVerbose,"CM_BW_MEASURE_INTERVAL set, interval is %ld\n", interval_value); + CMtrace_out(conn->cm, CMLowLevelVerbose,"CM_BW_MEASURE_INTERVAL set, interval is %zd\n", interval_value); if (conn->characteristics && (get_int_attr(conn->characteristics, CM_BW_MEASURE_INTERVAL, &previous_interval) != 0)) { @@ -1195,10 +1206,10 @@ CManager_free(CManager cm) } CMtrace_out(conn->cm, CMLowLevelVerbose,"CM_BW_MEASURE_INTERVAL prior interval is %d, killing prior task.\n", previous_interval); get_long_attr(conn->characteristics, CM_BW_MEASURE_TASK, - (long*)(long)&prior_task); + (ssize_t*)(intptr_t)&prior_task); if (prior_task) { INT_CMremove_task(prior_task); - set_long_attr(conn->characteristics, CM_BW_MEASURE_TASK, (long)0); + set_long_attr(conn->characteristics, CM_BW_MEASURE_TASK, (intptr_t)0); } } data = malloc(sizeof(*data)); @@ -1224,14 +1235,14 @@ CManager_free(CManager cm) (void*)data); free(task); /* schedule tasks periodically */ - task = INT_CMadd_periodic_task(conn->cm, interval_value, 0, + task = INT_CMadd_periodic_task(conn->cm, (int)interval_value, 0, do_bw_measure, (void*)data); if (conn->characteristics == NULL) { conn->characteristics = CMcreate_attr_list(conn->cm); } set_int_attr(conn->characteristics, CM_BW_MEASURE_INTERVAL, - interval_value); - set_long_attr(conn->characteristics, CM_BW_MEASURE_TASK, (long)task); + (int)interval_value); + set_long_attr(conn->characteristics, CM_BW_MEASURE_TASK, (intptr_t)task); return 1; } @@ -1300,15 +1311,15 @@ INT_CMConnection_failed(CMConnection conn) transport_wake_any_pending_write(conn); assert(CManager_locked(conn->cm)); - CMtrace_out(conn->cm, CMFreeVerbose, "CMConnection failed conn=%lx\n", - (long) conn); + CMtrace_out(conn->cm, CMFreeVerbose, "CMConnection failed conn=%p\n", + conn); CMconn_fail_conditions(conn); conn->trans->shutdown_conn(&CMstatic_trans_svcs, conn->transport_data); get_long_attr(conn->characteristics, CM_BW_MEASURE_TASK, - (long*)(long)&prior_task); + (ssize_t*)(intptr_t)&prior_task); if (prior_task) { INT_CMremove_task(prior_task); - set_long_attr(conn->characteristics, CM_BW_MEASURE_TASK, (long)0); + set_long_attr(conn->characteristics, CM_BW_MEASURE_TASK, (intptr_t)0); } if (conn->close_list) { CMCloseHandlerList list = conn->close_list; @@ -1334,8 +1345,8 @@ INT_CMConnection_failed(CMConnection conn) void internal_connection_close(CMConnection conn) { - CMtrace_out(conn->cm, CMFreeVerbose, "internal_connection_close conn=%lx ref count is %d\n", - (long) conn, conn->conn_ref_count); + CMtrace_out(conn->cm, CMFreeVerbose, "internal_connection_close conn=%p ref count is %d\n", + conn, conn->conn_ref_count); conn->closed = 1; } @@ -1343,8 +1354,8 @@ INT_CMConnection_failed(CMConnection conn) INT_CMConnection_close(CMConnection conn) { internal_connection_close(conn); - CMtrace_out(conn->cm, CMFreeVerbose, "User CMConnection close conn=%lx ref count will be %d\n", - (long) conn, conn->conn_ref_count - 1); + CMtrace_out(conn->cm, CMFreeVerbose, "User CMConnection close conn=%p ref count will be %d\n", + conn, conn->conn_ref_count - 1); INT_CMConnection_dereference(conn); } @@ -1402,12 +1413,12 @@ INT_CMConnection_failed(CMConnection conn) { cl->free_reference_count--; if (CMtrace_val[CMFreeVerbose]) { - fprintf(cm->CMTrace_file, "CMControlList_free, %lx, ref count now %d\n", (long)cl, + fprintf(cm->CMTrace_file, "CMControlList_free, %p, ref count now %d\n", cl, cl->free_reference_count); } if(cl->free_reference_count == 0) { if (CMtrace_val[CMFreeVerbose]) { - fprintf(cm->CMTrace_file, "CMControlList_free freeing %lx\n", (long)cl); + fprintf(cm->CMTrace_file, "CMControlList_free freeing %p\n", cl); } if (cl->polling_function_list != NULL) { INT_CMfree(cl->polling_function_list); @@ -1512,7 +1523,7 @@ static void timeout_conn(CManager cm, void *client_data) { - INT_CMCondition_fail(cm, (long) client_data); + INT_CMCondition_fail(cm, (int)(intptr_t) client_data); } static @@ -1527,7 +1538,7 @@ timeout_conn(CManager cm, void *client_data) int result; long wait_condition = INT_CMCondition_get(cm, NULL); CMTaskHandle task = INT_CMadd_delayed_task(cm, 5, 0, timeout_conn, - (void*)wait_condition); + (void*)(intptr_t)wait_condition); if (CMtrace_on(cm, CMConnectionVerbose)) { char *attr_str = attr_list_to_string(attrs); CMtrace_out(cm, CMConnectionVerbose, @@ -1629,10 +1640,10 @@ timeout_conn(CManager cm, void *client_data) fprintf(out, "CMConnection NULL\n"); return; } - fprintf(out, "CMConnection %lx, reference count %d, closed %d\n\tattrs : ", - (long) conn, conn->conn_ref_count, conn->closed); + fprintf(out, "CMConnection %p, reference count %d, closed %d\n\tattrs : ", + conn, conn->conn_ref_count, conn->closed); fdump_attr_list(out, conn->attrs); - fprintf(out, "\tbuffer_full_point %ld, current buffer_end %ld\n", + fprintf(out, "\tbuffer_full_point %zd, current buffer_end %zd\n", conn->buffer_full_point, conn->buffer_data_end); fprintf(out, "\twrite_pending %d\n", conn->write_pending); } @@ -1787,7 +1798,7 @@ timeout_conn(CManager cm, void *client_data) CMtrace_out(cm, CMBufferVerbose, "cm_get_data_buf called with len %zu\n", length); while (tmp != NULL) { - CMtrace_out(cm, CMBufferVerbose, " buffer %d %p, size is %ld, data %p, ref_count %d\n", + CMtrace_out(cm, CMBufferVerbose, " buffer %d %p, size is %zd, data %p, ref_count %d\n", buffer_count, tmp, tmp->size, tmp->buffer, tmp->ref_count); buffer_count++; tmp = tmp->next; @@ -1807,7 +1818,7 @@ timeout_conn(CManager cm, void *client_data) tmp = cm->cm_buffer_list; while (tmp != NULL) { if (tmp->ref_count <= 0) { - if ((tmp->size >= length) && ((tmp->size/10) < length)) { + if ((tmp->size >= (size_t)length) && ((tmp->size/10) < (size_t)length)) { CMtrace_out(cm, CMBufferVerbose, "cm_get_data_buf called len %zu, return existing %p, next %p, count %d\n", length, tmp, tmp->next, buffer_count); tmp->ref_count = 1; @@ -1820,7 +1831,7 @@ timeout_conn(CManager cm, void *client_data) tmp = cm->cm_buffer_list; while (tmp != NULL) { if (tmp->ref_count <= 0) { - if ((tmp->size >= length)) { + if ((tmp->size >= (size_t)length)) { char *t = INT_CMrealloc(tmp->buffer, length); if (t == NULL) { return NULL; @@ -1838,7 +1849,7 @@ timeout_conn(CManager cm, void *client_data) /* well, look for a small one to realloc up */ while (tmp != NULL) { if (tmp->ref_count <= 0) { - if (tmp->size <= length) { + if (tmp->size <= (size_t)length) { char *t = INT_CMrealloc(tmp->buffer, length); if (t == NULL) { return NULL; @@ -1927,18 +1938,18 @@ timeout_conn(CManager cm, void *client_data) CMbuffer tmp = cm->cm_buffer_list; printf("Known CM buffers are:\n"); while (tmp != NULL) { - printf("Buffer begin %p, size %ld, end %p\n", + printf("Buffer begin %p, size %zd, end %p\n", tmp->buffer, tmp->size, (char*)tmp->buffer + tmp->size); tmp = tmp->next; } return NULL; } - int (*cm_write_hook)(int) = (int (*)(int)) NULL; - int (*cm_preread_hook)(int,char*) = (int (*)(int, char*)) NULL; - void (*cm_postread_hook)(int,char*) = (void (*)(int, char*)) NULL; + int (*cm_write_hook)(size_t) = (int (*)(size_t)) NULL; + int (*cm_preread_hook)(size_t,char*) = (int (*)(size_t, char*)) NULL; + void (*cm_postread_hook)(size_t,char*) = (void (*)(size_t, char*)) NULL; void (*cm_last_postread_hook)() = (void (*)()) NULL; - static int CMact_on_data(CMConnection conn, CMbuffer cm_buffer, char *buffer, long length); + static size_t CMact_on_data(CMConnection conn, CMbuffer cm_buffer, char *buffer, size_t length); static void process_pending_queue(CManager cm, void *junk) { @@ -1948,11 +1959,11 @@ timeout_conn(CManager cm, void *client_data) CManager_lock(cm); while (cm->pending_data_queue) { pending_queue entry = cm->pending_data_queue; - int result; + size_t result; cm->pending_data_queue = entry->next; result = CMact_on_data(entry->conn, entry->buffer, entry->buffer->buffer, entry->length); if (result != 0) { - printf("in process pending, CMact_on_data returned %d\n", result); + printf("in process pending, CMact_on_data returned %zd\n", result); } cm_return_data_buf(cm, entry->buffer); free(entry); @@ -1984,7 +1995,7 @@ timeout_conn(CManager cm, void *client_data) static CMbuffer - fill_cmbuffer(CManager cm, char *buf, long length) + fill_cmbuffer(CManager cm, char *buf, size_t length) { CMbuffer ret = cm_get_data_buf(cm, length); memcpy(ret->buffer, buf, length); @@ -1996,11 +2007,11 @@ timeout_conn(CManager cm, void *client_data) CManager cm = conn->cm; int do_read = 1; int read_msg_count = 0; - long read_byte_count = 0; - int result; + size_t read_byte_count = 0; + size_t result; static int first = 1; static int read_ahead_msg_limit = 50; - static long read_ahead_byte_limit = 1024*1024*1024; + static size_t read_ahead_byte_limit = 1024*1024*1024; static int use_blocking_reads = 1; int first_four = 0; char *tmp_message_buffer = NULL; @@ -2020,7 +2031,7 @@ timeout_conn(CManager cm, void *client_data) } tmp = getenv("CMReadAheadByteLimit"); if (tmp != NULL) { - if (sscanf(tmp, "%ld", &read_ahead_byte_limit) != 1) { + if (sscanf(tmp, "%zd", &read_ahead_byte_limit) != 1) { printf("Read ahead byte limit \"%s\" not parsed\n", tmp); } } @@ -2054,7 +2065,7 @@ timeout_conn(CManager cm, void *client_data) first_four = 1; } if (trans->read_to_buffer_func) { - CMtrace_out(cm, CMLowLevelVerbose, "CMdata continuing read, already have %ld bytes, trying to read total %ld\n", buffer_data_end, buffer_full_point); + CMtrace_out(cm, CMLowLevelVerbose, "CMdata continuing read, already have %zd bytes, trying to read total %zd\n", buffer_data_end, buffer_full_point); } else { CMtrace_out(cm, CMLowLevelVerbose, "CMdata block read beginning\n"); } @@ -2117,7 +2128,7 @@ timeout_conn(CManager cm, void *client_data) return; } buffer_data_end += actual; - if (actual < read_len) { + if (actual < (ssize_t)read_len) { /* partial read, we know we don't have enough data now, roll on */ CMtrace_out(cm, CMLowLevelVerbose, "CMdata read partial, got %zu\n", actual); @@ -2192,7 +2203,7 @@ timeout_conn(CManager cm, void *client_data) if ((read_msg_count > read_ahead_msg_limit) || (read_byte_count > read_ahead_byte_limit)) { CMtrace_out(cm, CMDataVerbose, - "CM - readahead not tried, fairness, read %d msgs, %ld bytes\n", + "CM - readahead not tried, fairness, read %d msgs, %zd bytes\n", read_msg_count, read_byte_count); return; } else { @@ -2251,8 +2262,8 @@ timeout_conn(CManager cm, void *client_data) } } - static int - CMact_on_data(CMConnection conn, CMbuffer cm_buffer, char *buffer, long length) + static size_t + CMact_on_data(CMConnection conn, CMbuffer cm_buffer, char *buffer, size_t length) { char *base = buffer; char *check_sum_base = buffer; @@ -2336,9 +2347,9 @@ timeout_conn(CManager cm, void *client_data) case 0x4f494250: /* incoming FFS format protocol message */ { extern int CM_pbio_query(CMConnection conn, CMTransport trans, - char *buffer, long length); + char *buffer, size_t length); - int ret = CM_pbio_query(conn, conn->trans, buffer, length); + size_t ret = CM_pbio_query(conn, conn->trans, buffer, length); CManager_lock(cm); return ret; } @@ -2347,7 +2358,7 @@ timeout_conn(CManager cm, void *client_data) CManager_lock(cm); if (local) cm_return_data_buf(cm, local); if (ret == -1) { - printf("Unknown message on connection %lx, failed %d, closed %d, %x\n", (long) conn, conn->failed, conn->closed, *(int*)buffer); + printf("Unknown message on connection %p, failed %d, closed %d, %x\n", conn, conn->failed, conn->closed, *(int*)buffer); CMtrace_out(conn->cm, CMFreeVerbose, "Calling connection unknown message failed with dereference %p\n", conn); INT_CMConnection_failed(conn); } @@ -2476,7 +2487,7 @@ timeout_conn(CManager cm, void *client_data) } } - if (length < header_len + data_length + attr_length) { + if ((ssize_t)length < header_len + data_length + attr_length) { return header_len + data_length + attr_length - length; } @@ -2531,13 +2542,13 @@ timeout_conn(CManager cm, void *client_data) } if (event_msg) { CMbuffer local = NULL; - CMtrace_out(cm, CMDataVerbose, "CM - Receiving event message data len %ld, attr len %d, stone_id %x\n", - (long)data_length, attr_length, stone_id); + CMtrace_out(cm, CMDataVerbose, "CM - Receiving event message data len %" PRId64 ", attr len %d, stone_id %x\n", + data_length, attr_length, stone_id); if (attrs == NULL){ attrs = CMcreate_attr_list(cm); } - set_int_attr(attrs, CM_EVENT_SIZE, data_length); - set_long_attr(attrs, CM_INCOMING_CONNECTION, (long)conn); + set_int_attr(attrs, CM_EVENT_SIZE, (int)data_length); + set_long_attr(attrs, CM_INCOMING_CONNECTION, (intptr_t)conn); if (cm_buffer == NULL) { local = fill_cmbuffer(cm, buffer, length); @@ -2612,7 +2623,7 @@ timeout_conn(CManager cm, void *client_data) if (FFSdecode_in_place_possible(original_format)) { if (!FFSdecode_in_place(cm->FFScontext, data_buffer, - (void**) (long) &decode_buffer)) { + (void**) (intptr_t) &decode_buffer)) { printf("Decode failed\n"); return 0; } @@ -2761,8 +2772,8 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) extern void CMWriteQueuedData(transport_entry trans, CMConnection conn) { attr_list attrs = NULL; /* GSE fix */ - CMtrace_out(conn->cm, CMLowLevelVerbose, "CMWriteQueuedData, conn %lx, header %d, attr %d\n", - (long)conn, conn->queued_data.rem_header_len, + CMtrace_out(conn->cm, CMLowLevelVerbose, "CMWriteQueuedData, conn %p, header %zd, attr %zd\n", + conn, conn->queued_data.rem_header_len, conn->queued_data.rem_attr_len); if (conn->queued_data.rem_header_len != 0) { struct FFSEncodeVec tmp_vec[1]; @@ -2776,12 +2787,12 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) if (actual == -1) { goto failed; } - if (actual < conn->queued_data.rem_header_len) { + if (actual < (ssize_t)conn->queued_data.rem_header_len) { conn->queued_data.rem_header_len -= actual; memmove(&conn->queued_data.rem_header[0], &conn->queued_data.rem_header[actual], conn->queued_data.rem_header_len); - CMtrace_out(conn->cm, CMLowLevelVerbose, "CMWriteQueuedData, conn %p, remaining header %d\n", + CMtrace_out(conn->cm, CMLowLevelVerbose, "CMWriteQueuedData, conn %p, remaining header %zd\n", conn, conn->queued_data.rem_header_len); return; } @@ -2798,10 +2809,10 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) if (actual == -1) { goto failed; } - if (actual < conn->queued_data.rem_attr_len) { + if (actual < (ssize_t)conn->queued_data.rem_attr_len) { conn->queued_data.rem_attr_len -= actual; conn->queued_data.rem_attr_base += actual; - CMtrace_out(conn->cm, CMLowLevelVerbose, "CMWriteQueuedData, conn %p, remaining attr %d\n", + CMtrace_out(conn->cm, CMLowLevelVerbose, "CMWriteQueuedData, conn %p, remaining attr %zd\n", conn, conn->queued_data.rem_attr_len); return; } @@ -2823,10 +2834,10 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) if (actual == -1) { goto failed; } - if (actual < length) { + if (actual < (ssize_t)length) { int i = 0; CMtrace_out(conn->cm, CMLowLevelVerbose, "Continued partial pending write, %zu bytes sent\n", actual); - while (actual > vec[i].iov_len) { + while (actual > (ssize_t)vec[i].iov_len) { actual -= vec[i].iov_len; i++; vec_count--; @@ -2834,8 +2845,8 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) vec[i].iov_len -= actual; vec[i].iov_base = (char*)vec[i].iov_base + actual; conn->queued_data.vector_data = &vec[i]; - CMtrace_out(conn->cm, CMLowLevelVerbose, "CMWriteQueuedData, conn %lx, %zu remaining data vectors\n", - (long)conn, vec_count); + CMtrace_out(conn->cm, CMLowLevelVerbose, "CMWriteQueuedData, conn %p, %zu remaining data vectors\n", + conn, vec_count); return; } } @@ -2880,7 +2891,7 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) if (conn->write_callbacks) { int i = 0; CMConnHandlerListEntry callbacks[16]; - int callback_len = conn->write_callback_len; + size_t callback_len = conn->write_callback_len; assert(conn->write_callback_len <= 16); memcpy(callbacks, conn->write_callbacks, sizeof(callbacks[0]) * conn->write_callback_len); for (i = 0; i < callback_len; ++i) { @@ -3029,7 +3040,8 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) } static void - remove_pending_write_callback_by_id(CMConnection conn, int id) { + remove_pending_write_callback_by_id(CMConnection conn, SOCKET ids) { + int id = (int)(intptr_t)ids; assert(id < conn->write_callback_len && id >= 0); conn->write_callbacks[id].func = NULL; } @@ -3071,7 +3083,7 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) static void wake_pending_write(CManager cm, CMConnection conn, void *param) { - int cond = (long)param; + int cond = (int)(intptr_t)param; remove_pending_write_callback(conn, wake_pending_write, param); INT_CMCondition_signal(cm, cond); } @@ -3094,7 +3106,7 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) while (conn->write_pending && !conn->closed) { int cond = INT_CMCondition_get(conn->cm, conn); add_pending_write_callback(conn, wake_pending_write, - (void*) (long)cond); + (void*) (intptr_t)cond); CMtrace_out(conn->cm, CMLowLevelVerbose, "Condition wait for conn %p\n", conn); if (INT_CMCondition_wait(conn->cm, cond) == 0) { /* condition wait failed, connection is dead */ @@ -3113,7 +3125,7 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) int INT_CMwrite_raw(CMConnection conn, FFSEncodeVector full_vec, FFSEncodeVector data_vec, - long vec_count, long byte_count, attr_list attrs, int data_vec_stack) + long vec_count, size_t byte_count, attr_list attrs, int data_vec_stack) { return INT_CMwrite_raw_notify(conn, full_vec, data_vec, vec_count, byte_count, attrs, data_vec_stack, NULL, NULL); @@ -3122,13 +3134,13 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) /* Returns 1 if successful, -1 if deferred, 0 on error */ int INT_CMwrite_raw_notify(CMConnection conn, FFSEncodeVector full_vec, FFSEncodeVector data_vec, - long vec_count, long byte_count, attr_list attrs, int data_vec_stack, + long vec_count, size_t byte_count, attr_list attrs, int data_vec_stack, CMcompletion_notify_func notify_func, void *notify_client_data) { size_t actual = 0; unsigned char checksum = 0; int i, j, start; - long count = 0; + size_t count = 0; size_t length = 0; if (conn->closed || conn->failed) return 0; @@ -3169,7 +3181,7 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) conn->transport_data, 0); cm_wake_any_pending_write(conn); } - if (actual_bytes < length) { + if (actual_bytes < (ssize_t)length) { /* copy remaining and send it later */ if (actual_bytes < 0 ) actual_bytes = 0; if (data_vec_stack) { @@ -3180,7 +3192,7 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) conn->trans->set_write_notify(conn->trans, &CMstatic_trans_svcs, conn->transport_data, 1); conn->write_pending = 1; CMtrace_out(conn->cm, CMLowLevelVerbose, - "Partial write, queued %ld bytes\n", + "Partial write, queued %zd bytes\n", length - actual_bytes); return 1; } @@ -3230,7 +3242,7 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) void *header_ptr = NULL; int header_len = 0; int no_attr_header[2] = {0x434d4400, 0}; /* CMD\0 in first entry */ - int no_attr_long_header[4] = {0x434d4401, 0x434d4401, 0, 0}; /* CMD\1 in first entry, pad to 16 */ +// not yet impl int no_attr_long_header[4] = {0x434d4401, 0x434d4401, 0, 0}; /* CMD\1 in first entry, pad to 16 */ int attr_header[4] = {0x434d4100, 0x434d4100, 0, 0}; /* CMA\0 in first entry, pad to 16 */ int attr_long_header[4] = {0x434d4101, 0, 0, 0}; /* CMA\1 in first entry */ FFSEncodeVector vec; @@ -3316,11 +3328,11 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) } if (!long_message) { if (attrs_present) { - attr_header[2] = length; + attr_header[2] = (int)length; header_ptr = &attr_header; header_len = sizeof(attr_header); } else { - no_attr_header[1] = length; + no_attr_header[1] = (int)length; header_ptr = &no_attr_header; header_len = sizeof(no_attr_header); } @@ -3372,7 +3384,7 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) vec_count, byte_count); } - actual = INT_CMwrite_raw(conn, tmp_vec, vec, vec_count, byte_count, attrs, 0); + actual = INT_CMwrite_raw(conn, tmp_vec, vec, (int)vec_count, byte_count, attrs, 0); if (tmp_vec != &static_vec[0]) { INT_CMfree(tmp_vec); } @@ -3390,12 +3402,12 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) #ifdef EV_INTERNAL_H extern int internal_write_event(CMConnection conn, CMFormat format, void *remote_path_id, - int path_len, event_item *event, attr_list attrs, long *event_len_p) + int path_len, event_item *event, attr_list attrs, size_t *event_len_p) { FFSEncodeVector vec; struct FFSEncodeVec preencoded_vec[2]; - long data_length = 0, actual; - size_t vec_count = 0; + size_t data_length = 0, actual; + long vec_count = 0; int attr_len = 0; int do_write = 1; void *encoded_attrs = NULL; @@ -3436,7 +3448,7 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) dump_char_limit = atoi(size_str); } } - fprintf(cm->CMTrace_file, "CM - Writing EVENT record %lx of type %s\n", (long)event, + fprintf(cm->CMTrace_file, "CM - Writing EVENT record %p of type %s\n", event, name_of_FMformat(format->fmformat)); if (attrs != NULL) { fprintf(cm->CMTrace_file, "CM - write attributes are:"); @@ -3485,7 +3497,7 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) &attr_len); attr_len = (attr_len +7) & -8; /* round up to even 8 */ } - CMtrace_out(conn->cm, CMDataVerbose, "CM - Total write size is %ld bytes data + %d bytes attrs\n", data_length, attr_len); + CMtrace_out(conn->cm, CMDataVerbose, "CM - Total write size is %zd bytes data + %d bytes attrs\n", data_length, attr_len); if (cm_write_hook != NULL) { do_write = cm_write_hook(data_length); } @@ -3497,7 +3509,7 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) if (vec_count >= sizeof(static_vec)/ sizeof(static_vec[0])) { tmp_vec = INT_CMmalloc((vec_count+3) * sizeof(*tmp_vec)); } - header[1] = data_length; + header[1] = (int)data_length; if (path_len != 4) { header[0] = 0x434d4700; header[3] = (path_len + 7) & -8; @@ -3520,7 +3532,7 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) vec_count++; byte_count += sizeof(header); CMtrace_out(conn->cm, CMLowLevelVerbose, - "Writing %zu vectors, total %zu bytes in writev\n", + "Writing %lu vectors, total %zu bytes in writev\n", vec_count, byte_count); } else { tmp_vec[0].iov_base = &header; @@ -3532,10 +3544,9 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) byte_count += sizeof(header) + header[2]; vec_count += 2; CMtrace_out(conn->cm, CMLowLevelVerbose, - "Writing %zu vectors, total %zu bytes (including attrs) in writev\n", + "Writing %lu vectors, total %zu bytes (including attrs) in writev\n", vec_count, byte_count); } - char *header_ptr = (char*)&header[0]; actual = INT_CMwrite_raw(conn, tmp_vec, vec, vec_count, byte_count, attrs, vec == &preencoded_vec[0]); if (tmp_vec != &static_vec[0]) { @@ -3589,13 +3600,13 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) } extern void - INT_CMunregister_write_callback(CMConnection conn, int id) + INT_CMunregister_write_callback(CMConnection conn, SOCKET id) { remove_pending_write_callback_by_id(conn, id); } extern void - INT_CM_fd_add_select(CManager cm, int fd, select_list_func handler_func, + INT_CM_fd_add_select(CManager cm, SOCKET fd, select_list_func handler_func, void *param1, void *param2) { if (!handler_func) { @@ -3611,7 +3622,7 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) } extern void - CM_fd_write_select(CManager cm, int fd, select_list_func handler_func, + CM_fd_write_select(CManager cm, SOCKET fd, select_list_func handler_func, void *param1, void *param2) { if (!cm->control_list->select_initialized) { @@ -3623,7 +3634,7 @@ INT_CMregister_invalid_message_handler(CManager cm, CMUnregCMHandler handler) } extern void - CM_fd_remove_select(CManager cm, int fd) + CM_fd_remove_select(CManager cm, SOCKET fd) { if (!cm->control_list->select_initialized) { CM_init_select(cm->control_list, cm); @@ -3830,21 +3841,21 @@ CM_init_select(CMControlList cl, CManager cm) thr_thread_t server_thread = thr_fork((void*(*)(void*))server_thread_func, (void*)cm); - if (server_thread == (thr_thread_t) NULL) { + if (server_thread == (thr_thread_t) (intptr_t)NULL) { return; } CMtrace_out(cm, CMLowLevelVerbose, - "CM - Forked comm thread %lx\n", (long)server_thread); + "CM - Forked comm thread %p\n", (void*)(intptr_t)server_thread); cm->control_list->server_thread = server_thread; cm->control_list->cl_reference_count++; cm->control_list->free_reference_count++; cl->has_thread = 1; cm->reference_count++; - CMtrace_out(cm, CMFreeVerbose, "Forked - CManager %lx ref count now %d\n", - (long) cm, cm->reference_count); + CMtrace_out(cm, CMFreeVerbose, "Forked - CManager %p ref count now %d\n", + cm, cm->reference_count); } cl->select_initialized = 1; - CMtrace_out(cm, CMFreeVerbose, "CManager adding select shutdown function, %lx\n",(long)shutdown_function); + CMtrace_out(cm, CMFreeVerbose, "CManager adding select shutdown function, %p\n",shutdown_function); internal_add_shutdown_task(cm, select_shutdown, (void*)shutdown_function, SHUTDOWN_TASK); { void ** data = malloc(3 * sizeof(void*)); @@ -3859,7 +3870,7 @@ CM_init_select(CMControlList cl, CManager cm) wake_function(CManager cm, void *cond) { CManager_lock(cm); - INT_CMCondition_signal(cm, (int)(long)cond); + INT_CMCondition_signal(cm, (int)(intptr_t)cond); CManager_unlock(cm); } @@ -3868,7 +3879,7 @@ CM_init_select(CMControlList cl, CManager cm) { int cond = INT_CMCondition_get(cm, NULL); CMTaskHandle handle = - INT_CMadd_delayed_task(cm, sec, 0, wake_function, (void*)(long)cond); + INT_CMadd_delayed_task(cm, sec, 0, wake_function, (void*)(intptr_t)cond); INT_CMfree(handle); INT_CMCondition_wait(cm, cond); } @@ -3878,7 +3889,7 @@ CM_init_select(CMControlList cl, CManager cm) { int cond = INT_CMCondition_get(cm, NULL); CMTaskHandle handle = - INT_CMadd_delayed_task(cm, 0, usec, wake_function, (void*)(long)cond); + INT_CMadd_delayed_task(cm, 0, usec, wake_function, (void*)(intptr_t)cond); INT_CMfree(handle); INT_CMCondition_wait(cm, cond); } @@ -3952,6 +3963,20 @@ int offset_compare(const void* lhsv, const void* rhsv) return lhs->offset.tv_usec - rhs->offset.tv_usec; } +#ifdef _MSC_VER +static inline void timeradd(struct timeval *a, struct timeval *b, + struct timeval *res) +{ + res->tv_sec = a->tv_sec + b->tv_sec; + res->tv_usec = a->tv_usec + b->tv_usec; + if (res->tv_usec >= 1000000) + { + res->tv_usec -= 1000000; + res->tv_sec++; + } +} +#endif + extern int INT_CMinstall_pull_schedule(CManager cm, struct timeval *base_time, struct timeval *period, CMavail_period_ptr avail) @@ -4003,7 +4028,7 @@ INT_CMinstall_pull_schedule(CManager cm, struct timeval *base_time, cm->avail = sorted; transport_entry *trans_list; trans_list = cm->transports; - CMtrace_out(cm, CMTransportVerbose, "CM installed pull schedule with period %ld secs, %ld usecs\n", period->tv_sec, (long) period->tv_usec); + CMtrace_out(cm, CMTransportVerbose, "CM installed pull schedule with period %ld secs, %zd usecs\n", period->tv_sec, (size_t) period->tv_usec); while ((trans_list != NULL) && (*trans_list != NULL)) { if ((*trans_list)->install_pull_schedule_func) { (*trans_list)->install_pull_schedule_func(&CMstatic_trans_svcs, diff --git a/cm_control.c b/cm_control.c index 72f0f5426b..4344aedf6c 100644 --- a/cm_control.c +++ b/cm_control.c @@ -238,11 +238,11 @@ INT_CMCondition_wait(CManager cm, int condition) } cond->waiting++; if (cm_control_debug_flag) { - fprintf(cm->CMTrace_file, "CMLowLevel In condition wait, server thread = %lx\n", - (long)cl->server_thread); + fprintf(cm->CMTrace_file, "CMLowLevel In condition wait, server thread = %p\n", + (void*)(intptr_t)cl->server_thread); } if (!cl->has_thread) { - if ((cl->server_thread == (thr_thread_t) NULL) || (cl->server_thread == thr_thread_self())) { + if ((cl->server_thread == (thr_thread_t) (intptr_t) NULL) || (cl->server_thread == thr_thread_self())) { cl->cond_polling = 1; while (!(cond->signaled || cond->failed)) { if (cm_control_debug_flag) { @@ -255,7 +255,7 @@ INT_CMCondition_wait(CManager cm, int condition) fprintf(cm->CMTrace_file, "CMLowLevel after Polling for CMcondition %d\n", condition); } /* the poll and handle will set cl->server_thread, restore it */ - cl->server_thread = (thr_thread_t) NULL; + cl->server_thread = (thr_thread_t) (intptr_t)NULL; if (cm_control_debug_flag) { fprintf(cm->CMTrace_file, "CMLowLevel In condition wait, reset server thread = %lx\n", (long)cl->server_thread); diff --git a/cm_evol.c b/cm_evol.c index b091f014fb..bd661eac22 100644 --- a/cm_evol.c +++ b/cm_evol.c @@ -11,7 +11,7 @@ #endif #include #ifdef HAVE_WINDOWS_H -#include +#include #define __ANSI_CPP__ #else #include diff --git a/cm_formats.c b/cm_formats.c index 4bb978a1c2..a040751f89 100644 --- a/cm_formats.c +++ b/cm_formats.c @@ -8,7 +8,9 @@ #ifdef HAVE_MALLOC_H #include #endif +#ifdef HAVE_UNISTD_H #include +#endif #include #else diff --git a/cm_internal.h b/cm_internal.h index bbbeda2199..173a1ce366 100644 --- a/cm_internal.h +++ b/cm_internal.h @@ -1,7 +1,7 @@ #ifndef __I_O__ #include #endif -#ifndef _SYS_TIME_H +#ifdef HAVE_SYS_TIME_H #include "sys/time.h" #endif #ifndef _CM_SCHEDULE_H @@ -11,6 +11,7 @@ #include "config.h" #endif +#ifndef _MSC_VER #include #define thr_mutex_t pthread_mutex_t #define thr_thread_t pthread_t @@ -18,7 +19,7 @@ #define thr_thread_self() pthread_self() #define thr_thread_exit(status) pthread_exit(status); #define thr_thread_detach(thread) pthread_detach(thread); -#define thr_thread_yield() pthread_yield(); +#define thr_thread_yield() sched_yield() #define thr_thread_join(t, s) pthread_join(t, s) #define thr_mutex_init(m) pthread_mutex_init(&m, NULL); #define thr_mutex_lock(m) pthread_mutex_lock(&m); @@ -29,6 +30,29 @@ #define thr_condition_signal(c) pthread_cond_signal(&c); #define thr_condition_broadcast(c) pthread_cond_broadcast(&c); #define thr_condition_free(c) pthread_cond_destroy(&c); +#define thr_thread_create(w,x,y,z) pthread_create(w,x,y,z); +#else +//#include +#include +#define thr_mutex_t HANDLE +#define thr_thread_t DWORD +#define thr_condition_t HANDLE +#define thr_thread_create(w,x,y,z) 0 +#define thr_thread_self() GetCurrentThreadId() +#define thr_thread_exit(status) +#define thr_thread_detach(thread) +#define thr_thread_yield() +#define thr_thread_join(t, s) (void)s +#define thr_mutex_init(m) +#define thr_mutex_lock(m) +#define thr_mutex_unlock(m) +#define thr_mutex_free(m) +#define thr_condition_init(c) +#define thr_condition_wait(c, m) +#define thr_condition_signal(c) +#define thr_condition_broadcast(c) +#define thr_condition_free(c) +#endif #include @@ -221,9 +245,9 @@ typedef struct _CMControlList { struct queued_data_rec { char rem_header[32]; - int rem_header_len; + size_t rem_header_len; char *rem_attr_base; - int rem_attr_len; + size_t rem_attr_len; FFSEncodeVector vector_data; CMbuffer buffer_to_free; }; @@ -267,14 +291,14 @@ struct _CMConnection { CMCloseHandlerList close_list; - int write_callback_len; + size_t write_callback_len; CMConnHandlerList write_callbacks; AttrBuffer attr_encode_buffer; char header_buffer[HEADER_BUFFER_SIZE]; /* holds data until we know final size */ CMbuffer message_buffer; /* final destination of buffer */ - long buffer_full_point; /* data required for buffer to be full */ - long buffer_data_end; /* last point with valid data in buffer */ + size_t buffer_full_point; /* data required for buffer to be full */ + size_t buffer_data_end; /* last point with valid data in buffer */ attr_list characteristics; chr_time bandwidth_start_time; @@ -335,14 +359,14 @@ extern void CMtransport_trace(CManager cm, const char *format, ...); extern void CMtransport_verbose(CManager cm, CMTraceType trace, const char *format, ...); extern void -CM_fd_add_select(CManager cm, int fd, select_list_func handler_func, +CM_fd_add_select(CManager cm, SOCKET fd, select_list_func handler_func, void *param1, void *param2); extern void -CM_fd_write_select(CManager cm, int fd, select_list_func handler_func, +CM_fd_write_select(CManager cm, SOCKET fd, select_list_func handler_func, void *param1, void *param2); -extern void CM_fd_remove_select(CManager cm, int fd); +extern void CM_fd_remove_select(CManager cm, SOCKET fd); extern CMConnection CMConnection_create(transport_entry trans, void *transport_data, @@ -379,7 +403,7 @@ internal_add_shutdown_task(CManager cm, CMPollFunc func, void *client_data, int extern void internal_cm_network_submit(CManager cm, CMbuffer cm_data_buf, attr_list attrs, CMConnection conn, - void *buffer, int length, int stone_id); + void *buffer, size_t length, int stone_id); #define CMcreate_attr_list(cm) CMint_create_attr_list(cm, __FILE__, __LINE__) #define INT_CMfree_attr_list(cm, l) CMint_free_attr_list(cm, l, __FILE__, __LINE__) #define CMadd_ref_attr_list(cm, l) CMint_add_ref_attr_list(cm, l, __FILE__, __LINE__) @@ -394,8 +418,10 @@ extern attr_list CMint_attr_copy_list(CManager cm, attr_list l, char *file, int extern void CMint_attr_merge_lists(CManager cm, attr_list l1, attr_list l2, char *file, int line); extern attr_list CMint_decode_attr_from_xmit(CManager cm, void * buf, char *file, int line); -extern void* INT_CMrealloc(void *ptr, int size); -extern void* INT_CMmalloc(int size); +extern void* INT_CMrealloc(void *ptr, size_t size); +extern void* INT_CMmalloc(size_t size); +#define malloc(x) INT_CMmalloc(x) +#define realloc(ptr, size) INT_CMrealloc(ptr, size) extern void INT_CMfree(void *ptr); extern void INT_CMadd_shutdown_task(CManager cm, CMPollFunc func, void *client_data, int task_type); extern void INT_CManager_close(CManager cm); @@ -479,7 +505,7 @@ INT_CMregister_write_callback(CMConnection conn, CMWriteCallbackFunc handler, void *client_data); extern void -INT_CMunregister_write_callback(CMConnection conn, int id); +INT_CMunregister_write_callback(CMConnection conn, SOCKET id); extern void INT_CMadd_poll(CManager cm, CMPollFunc func, void *client_data); extern void @@ -531,7 +557,7 @@ INT_CMprobe_bandwidth(CMConnection conn, long size, attr_list attrs); extern int INT_CMConnection_write_would_block(CMConnection conn); extern void INT_CMusleep(CManager cm, int usecs); extern void INT_CM_insert_contact_info(CManager cm, attr_list attrs); -extern void INT_CM_fd_add_select(CManager cm, int fd, select_func handler_func, void *param1, void *param2); +extern void INT_CM_fd_add_select(CManager cm, SOCKET fd, select_func handler_func, void *param1, void *param2); extern void INT_CMstart_read_thread(CMConnection conn); extern void INT_EVadd_standard_routines(CManager cm, char *extern_string, cod_extern_entry *externs); extern void INT_EVadd_standard_structs(CManager cm, FMStructDescList *lists); @@ -543,6 +569,20 @@ extern int CMtrace_PID; extern int CMtrace_init(CManager cm, CMTraceType t); extern void INT_CMTrace_file_id(int ID); #define CMtrace_on(cm, trace_type) ((cm->CMTrace_file == NULL) ? CMtrace_init(cm, trace_type) : CMtrace_val[trace_type]) +#ifdef _MSC_VER +#include +#include +#define CLOCK_MONOTONIC 1 +static int clock_gettime(int cl, struct timespec* spec) +{ + __int64 wintime; GetSystemTimeAsFileTime((FILETIME*)&wintime); + wintime -= 116444736000000000i64; //1jan1601 to 1jan1970 + spec->tv_sec = (long)(wintime / 10000000i64); //seconds + spec->tv_nsec = wintime % 10000000i64 * 100; //nano-seconds + return 0; +} +#define HAVE_CLOCK_GETTIME +#endif #ifdef HAVE_CLOCK_GETTIME #define TRACE_TIME_DECL struct timespec ts #define TRACE_TIME_GET clock_gettime(CLOCK_MONOTONIC, &ts) @@ -552,15 +592,16 @@ extern void INT_CMTrace_file_id(int ID); #define TRACE_TIME_GET gettimeofday(&tv, NULL) #define TRACE_TIME_PRINTDETAILS "%lld.%.6ld - ", (long long)tv.tv_sec, (long)tv.tv_usec #endif + #define CMtrace_out(cm, trace_type, ...) {TRACE_TIME_DECL ; (CMtrace_on(cm,trace_type) ? (CMtrace_PID ? fprintf(cm->CMTrace_file, "P%lxT%lx - ", (long) getpid(), (long)thr_thread_self()) : 0) , CMtrace_timing? TRACE_TIME_GET,fprintf(cm->CMTrace_file, TRACE_TIME_PRINTDETAILS):0, fprintf(cm->CMTrace_file, __VA_ARGS__) : 0);fflush(cm->CMTrace_file);} -extern void CMdo_performance_response(CMConnection conn, long length, int func, +extern void CMdo_performance_response(CMConnection conn, size_t length, int func, int byte_swap, char *buffer); extern int INT_CMwrite_raw(CMConnection conn, FFSEncodeVector full_vec, FFSEncodeVector data_vec, - long vec_count, long byte_count, attr_list attrs, int data_vec_stack); + long vec_count, size_t byte_count, attr_list attrs, int data_vec_stack); int INT_CMwrite_raw_notify(CMConnection conn, FFSEncodeVector full_vec, FFSEncodeVector data_vec, - long vec_count, long byte_count, attr_list attrs, int data_vec_stack, + long vec_count, size_t byte_count, attr_list attrs, int data_vec_stack, CMcompletion_notify_func notify_func, void *notify_client_data); extern void INT_CMConnection_dereference(CMConnection conn); diff --git a/cm_lock.c b/cm_lock.c index 067dca5025..1522f9c9ca 100644 --- a/cm_lock.c +++ b/cm_lock.c @@ -1,20 +1,18 @@ #include "config.h" -#ifndef MODULE #include #include +#ifdef HAVE_UNISTD_H #include -#else -#include "kernel/kcm.h" -#include "kernel/library.h" #endif +#include "config.h" + #include "ffs.h" #include "atl.h" #include "evpath.h" #include "chr_time.h" #include "cm_internal.h" -#include "config.h" #undef NDEBUG #include "assert.h" diff --git a/cm_pbio.c b/cm_pbio.c index cbec85342a..9e41a5d42b 100644 --- a/cm_pbio.c +++ b/cm_pbio.c @@ -3,10 +3,12 @@ #ifndef MODULE #include #include +#ifdef HAVE_UNISTD_H #include +#endif #include #ifdef HAVE_WINDOWS_H -#include +#include #else #include #include @@ -127,7 +129,7 @@ static int CMpbio_send_format_request(char *format_ID, int format_ID_length, CMConnection conn, int cond); extern int CM_pbio_query(CMConnection conn, CMTransport trans, - char *buffer, long length); + char *buffer, size_t length); static int request_in_pending(CManager cm, void *format_ID, int format_id_length) @@ -540,7 +542,7 @@ byte_swap(char *data, int size) } extern int -CM_pbio_query(CMConnection conn, CMTransport trans, char *buffer, long length) +CM_pbio_query(CMConnection conn, CMTransport trans, char *buffer, size_t length) { struct pbio_exchange_msg tmp_msg; struct pbio_exchange_msg *msg; diff --git a/cm_perf.c b/cm_perf.c index 065ca1e94f..a1328f0c3c 100644 --- a/cm_perf.c +++ b/cm_perf.c @@ -12,7 +12,7 @@ #endif #include #ifdef HAVE_WINDOWS_H -#include +#include #define __ANSI_CPP__ #else #include @@ -60,7 +60,7 @@ static atom_t CM_TRANS_MEGABITS_SEC = -1; #define CMRegressivePerfBandwidthResult (unsigned int) 0xf9 void -CMdo_performance_response(CMConnection conn, long length, int func, +CMdo_performance_response(CMConnection conn, size_t length, int func, int byte_swap, char *buffer) { /* part of length was read already */ @@ -89,7 +89,7 @@ CMdo_performance_response(CMConnection conn, long length, int func, tmp_vec[1].iov_len = length - sizeof(header); tmp_vec[1].iov_base = buffer; - CMtrace_out(conn->cm, CMTransportVerbose, "CM - responding to latency probe of %ld bytes\n", length); + CMtrace_out(conn->cm, CMTransportVerbose, "CM - responding to latency probe of %zd bytes\n", length); actual = INT_CMwrite_raw(conn, tmp_vec, tmp_vec + 1, 2, length, NULL, 0); if (actual != 2) { printf("perf write failed\n"); @@ -230,7 +230,7 @@ CMdo_performance_response(CMConnection conn, long length, int func, if (upcall_result) { str_list = attr_list_to_string(upcall_result); free_attr_list(upcall_result); - tmp_vec[1].iov_len = header[4] = strlen(str_list) + 1; + tmp_vec[1].iov_len = header[4] = (int)strlen(str_list) + 1; tmp_vec[1].iov_base = str_list; header[2] += header[4]; } @@ -524,7 +524,7 @@ INT_CMtest_transport(CMConnection conn, attr_list how) struct FFSEncodeVec *write_vec; struct FFSEncodeVec *tmp_vec, *header_vec; int header[6]; - long size; + ssize_t size; int vecs = 1; int verbose = 0; int repeat_count = 1; @@ -558,7 +558,7 @@ INT_CMtest_transport(CMConnection conn, attr_list how) char *attr_str = attr_list_to_string(how); - start_size = strlen(attr_str) + sizeof(header) + 1; + start_size = (int)strlen(attr_str) + (int)sizeof(header) + 1; /* CMP\0 in first entry for CMPerformance message */ ((int*)header)[0] = 0x434d5000; /* size in second entry, high byte gives CMPerf operation */ @@ -573,7 +573,7 @@ INT_CMtest_transport(CMConnection conn, attr_list how) ((int*)header)[5] = 0; INT_CMCondition_set_client_data( conn->cm, cond, &result); - CMtrace_out(conn->cm, CMTransportVerbose, "CM - Initiating transport test of %ld bytes, %d messages\n", size, repeat_count); + CMtrace_out(conn->cm, CMTransportVerbose, "CM - Initiating transport test of %zd bytes, %d messages\n", size, repeat_count); CMtrace_out(conn->cm, CMTransportVerbose, "CM - transport test, sending first message\n"); @@ -590,7 +590,7 @@ INT_CMtest_transport(CMConnection conn, attr_list how) } tmp_vec = NULL; - int each = (size + vecs - 1) / vecs; + size_t each = (size + vecs - 1) / vecs; for (i=0; i tmp_vec[0].iov_len) { diff --git a/cm_schedule.h b/cm_schedule.h index d2eec1a364..32ed8bb54b 100644 --- a/cm_schedule.h +++ b/cm_schedule.h @@ -7,6 +7,9 @@ extern "C" { #endif +#ifdef _MSC_VER +#include +#endif typedef struct _avail_period { struct timeval offset; struct timeval duration; diff --git a/cm_threadio.c b/cm_threadio.c index 9d4e76a455..08441bbd12 100644 --- a/cm_threadio.c +++ b/cm_threadio.c @@ -43,14 +43,12 @@ void* read_thread_func(void *conn_raw) { } static thr_thread_t -thr_fork(func, arg) -void*(*func)(void*); -void *arg; +thr_fork(void*(*func)(void*), void *arg) { - pthread_t new_thread = 0; - int err = pthread_create(&new_thread, NULL, (void*(*)(void*))func, arg); + thr_thread_t new_thread = 0; + int err = thr_thread_create(&new_thread, NULL, (void*(*)(void*))func, arg); if (err != 0) { - return (thr_thread_t) NULL; + return (thr_thread_t) (intptr_t) NULL; } else { return (thr_thread_t) new_thread; } diff --git a/cm_transport.c b/cm_transport.c index 27e949d021..33e7883f2d 100644 --- a/cm_transport.c +++ b/cm_transport.c @@ -1,27 +1,22 @@ #include "config.h" -#ifndef MODULE #include #include #include +#ifdef HAVE_UNISTD_H #include -#else -#include "kernel/kcm.h" -#include "kernel/cm_kernel.h" -#include "kernel/library.h" -/* don't pull in sys/types if MODULE is defined */ -#define _SYS_TYPES_H #endif + #include #include #include "chr_time.h" -#include -#include #if !NO_DYNAMIC_LINKING #include "dlloader.h" #endif #undef NDEBUG #include "assert.h" +#include +#include extern struct CMtrans_services_s CMstatic_trans_svcs; /* const lt_dlsymlist lt_preloaded_symbols[1] = { { 0, 0 } }; */ @@ -159,15 +154,15 @@ load_transport(CManager cm, const char *trans_name, int quiet) lt_dlsym(handle, "initialize"); transport->listen = (CMTransport_listen_func) lt_dlsym(handle, "non_blocking_listen"); - transport->initiate_conn = (CMConnection(*)()) + transport->initiate_conn = (CMTransport_conn_func) lt_dlsym(handle, "initiate_conn"); transport->initiate_conn_nonblocking = (CMTransport_NBconn_func) lt_dlsym(handle, "initiate_conn_nonblocking"); - transport->finalize_conn_nonblocking = (CMConnection(*)()) + transport->finalize_conn_nonblocking = (CMTransport_NBconn_final_func) lt_dlsym(handle, "finalize_conn_nonblocking"); - transport->self_check = (int (*)()) lt_dlsym(handle, "self_check"); + transport->self_check = (CMTransport_self_check_func) lt_dlsym(handle, "self_check"); transport->connection_eq = - (int (*)()) lt_dlsym(handle, "connection_eq"); + (CMTransport_connection_eq_func) lt_dlsym(handle, "connection_eq"); transport->shutdown_conn = (CMTransport_shutdown_conn_func) lt_dlsym(handle, "shutdown_conn"); transport->read_to_buffer_func = (CMTransport_read_to_buffer_func) diff --git a/cm_transport.h b/cm_transport.h index 5dbba4da04..929c2f1b5b 100644 --- a/cm_transport.h +++ b/cm_transport.h @@ -4,7 +4,7 @@ #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif -#ifndef _SYS_TIME_H +#ifdef HAVE_SYS_TIME_H #include "sys/time.h" #endif #ifndef _CM_SCHEDULE_H @@ -13,13 +13,22 @@ extern "C" { #include #include "sys/types.h" +#ifdef _MSC_VER +#include + typedef SSIZE_T ssize_t; +#else +#include +#ifndef SOCKET +#define SOCKET int +#endif +#endif typedef struct _transport_item *transport_entry; typedef struct _transport_item *CMTransport; typedef struct _CMbuffer { void *buffer; - long size; + size_t size; int ref_count; struct _CMbuffer *next; void (*return_callback)(void *); @@ -31,21 +40,21 @@ typedef enum _CMTraceType { CMLastTraceType /* add before this one */ } CMTraceType; -typedef void *(*CMTransport_malloc_func)(int); -typedef void *(*CMTransport_realloc_func)(void*, int); +typedef void *(*CMTransport_malloc_func)(size_t); +typedef void *(*CMTransport_realloc_func)(void*, size_t); typedef void (*CMTransport_free_func)(void*); typedef void (*CMTransport_wake_comm_thread_func)(CManager cm); typedef void (*CMTransport_condition_signal_func)(CManager cm, int condition); typedef void (*select_list_func)(void *, void*); -typedef void (*CMAddSelectFunc)(void *svcs, void *select_data, int fd, +typedef void (*CMAddSelectFunc)(void *svcs, void *select_data, SOCKET fd, select_list_func func, void *param1, void *param2); -typedef void (*CMTransport_fd_add_select)(CManager cm, int fd, select_list_func handler_func, +typedef void (*CMTransport_fd_add_select)(CManager cm, SOCKET fd, select_list_func handler_func, void *param1, void *param2); -typedef void (*CMTransport_fd_remove_select)(CManager cm, int fd); +typedef void (*CMTransport_fd_remove_select)(CManager cm, SOCKET fd); typedef void (*CMTransport_trace)(CManager cm, const char *format, ...); typedef void (*CMTransport_verbose)(CManager cm, CMTraceType trace, const char *format, ...); typedef CMConnection (*CMTransport_conn_create)(transport_entry trans, @@ -70,7 +79,7 @@ typedef CMbuffer (*CMTransport_create_data_buffer)(CManager cm, void *buffer, ss typedef int (*CMTransport_modify_global_lock)(CManager cm, const char *file, int line); typedef void (*CMTransport_add_buffer_to_pending_queue)(CManager cm, CMConnection conn, CMbuffer buf, long length); typedef void (*CMTransport_cond_wait_CM_lock)(CManager cm, void *cond, char *file, int line); -typedef void (*CMRemoveSelectFunc)(void *svcs, void *select_data, int fd); +typedef void (*CMRemoveSelectFunc)(void *svcs, void *select_data, SOCKET fd); typedef struct _periodic_task *periodic_task_handle; typedef periodic_task_handle (*CMAddPeriodicFunc) diff --git a/cm_util.c b/cm_util.c index a0d1ea0ec6..d6509555db 100644 --- a/cm_util.c +++ b/cm_util.c @@ -209,8 +209,8 @@ CMint_create_attr_list(CManager cm, char *file, int line) { attr_list list = create_attr_list(); (void)cm; - CMtrace_out(cm, CMAttrVerbose, "Creating attr list %lx at %s:%d\n", - (long)list, file, line); + CMtrace_out(cm, CMAttrVerbose, "Creating attr list %p at %s:%d\n", + list, file, line); return list; } @@ -219,8 +219,8 @@ CMint_free_attr_list(CManager cm, attr_list l, char *file, int line) { int count = attr_list_ref_count(l); (void)cm; - CMtrace_out(cm, CMAttrVerbose, "Freeing attr list %lx at %s:%d, ref count was %d\n", - (long)l, file, line, count); + CMtrace_out(cm, CMAttrVerbose, "Freeing attr list %p at %s:%d, ref count was %d\n", + l, file, line, count); free_attr_list(l); } @@ -232,8 +232,8 @@ CMint_add_ref_attr_list(CManager cm, attr_list l, char *file, int line) (void)cm; if (l == NULL) return NULL; count = attr_list_ref_count(l); - CMtrace_out(cm, CMAttrVerbose, "Adding ref attr list %lx at %s:%d, ref count now %d\n", - (long)l, file, line, count+1); + CMtrace_out(cm, CMAttrVerbose, "Adding ref attr list %p at %s:%d, ref count now %d\n", + l, file, line, count+1); return add_ref_attr_list(l); } @@ -242,8 +242,8 @@ CMint_attr_copy_list(CManager cm, attr_list l, char *file, int line) { attr_list ret = attr_copy_list(l); (void)cm; - CMtrace_out(cm, CMAttrVerbose, "Copy attr list %lx at %s:%d, new list %p\n", - (long)l, file, line, ret); + CMtrace_out(cm, CMAttrVerbose, "Copy attr list %p at %s:%d, new list %p\n", + l, file, line, ret); return ret; } @@ -262,26 +262,33 @@ CMint_decode_attr_from_xmit(CManager cm, void * buf, char *file, int line) { attr_list l = decode_attr_from_xmit(buf); (void)cm; - CMtrace_out(cm, CMAttrVerbose, "decode attr list from xmit at %s:%d, new list %lx\n", - file, line, (long)l); + CMtrace_out(cm, CMAttrVerbose, "decode attr list from xmit at %s:%d, new list %p\n", + file, line, l); return l; } +#undef realloc +#undef malloc extern void* -INT_CMrealloc(void *ptr, int size) +INT_CMrealloc(void *ptr, size_t size) { void *tmp = realloc(ptr, size); if ((tmp == 0) && (size != 0)) { - printf("Realloc failed on ptr %lx, size %d\n", (long)ptr, size); + printf("Realloc failed on ptr %p, size %zd\n", ptr, size); perror("realloc"); } return tmp; } extern void* -INT_CMmalloc(int size) +INT_CMmalloc(size_t size) { - return malloc(size); + void* tmp = malloc(size); + if ((tmp == 0) && (size != 0)) { + printf("Malloc failed on size %zd\n", size); + perror("malloc"); + } + return tmp; } extern void diff --git a/cmenet.c b/cmenet.c index d69af9c50b..3e04e45134 100644 --- a/cmenet.c +++ b/cmenet.c @@ -4,14 +4,119 @@ # pragma warning (disable: 1418) #endif +#undef NDEBUG +#ifdef HAVE_WINDOWS_H +#include +#include +#include +#include +#define getpid() _getpid() +#else +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_TIMES_H +#include +#endif +#include +#ifdef HAVE_SYS_SOCKIO_H +#include +#endif +#ifdef HAVE_SYS_SELECT_H +#include +#endif +#ifdef HAVE_SYS_UN_H +#include +#endif +#ifdef HAVE_SYS_UIO_H +#include +#endif +#ifdef HAVE_HOSTLIB_H +#include "hostLib.h" +#endif +#ifdef HAVE_STREAMS_UN_H +#include +#endif +#include +#include +#ifdef HAVE_NETDB_H +#include +#endif +#endif +#include +#include +#ifndef HAVE_WINDOWS_H +#include +#include +#include +#else +#include +#define drand48() (((double)rand())/((double)RAND_MAX)) +#define lrand48() rand() +#define srand48(x) +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif #undef NDEBUG #include +#include #include #include -#include #include +#ifdef HAVE_MEMORY_H +#include +#endif + +#include +#include "evpath.h" +#include "cm_transport.h" +#include "ev_select.h" + +#ifndef _MSC_VER #include -#include +#define thr_mutex_t pthread_mutex_t +#define thr_thread_t pthread_t +#define thr_condition_t pthread_cond_t +#define thr_thread_self() pthread_self() +#define thr_thread_exit(status) pthread_exit(status); +#define thr_thread_detach(thread) pthread_detach(thread); +#define thr_thread_yield() sched_yield() +#define thr_thread_join(t, s) pthread_join(t, s) +#define thr_mutex_init(m) pthread_mutex_init(&m, NULL); +#define thr_mutex_lock(m) pthread_mutex_lock(&m); +#define thr_mutex_unlock(m) pthread_mutex_unlock(&m); +#define thr_mutex_free(m) pthread_mutex_destroy(&m); +#define thr_condition_init(c) pthread_cond_init(&c, NULL); +#define thr_condition_wait(c, m) pthread_cond_wait(&c, &m); +#define thr_condition_signal(c) pthread_cond_signal(&c); +#define thr_condition_broadcast(c) pthread_cond_broadcast(&c); +#define thr_condition_free(c) pthread_cond_destroy(&c); +#define thr_thread_create(w,x,y,z) pthread_create(w,x,y,z); +#else +//#include +#include +#define thr_mutex_t HANDLE +#define thr_thread_t DWORD +#define thr_condition_t HANDLE +#define thr_thread_create(w,x,y,z) 0 +#define thr_thread_self() GetCurrentThreadId() +#define thr_thread_exit(status) +#define thr_thread_detach(thread) +#define thr_thread_yield() +#define thr_thread_join(t, s) (void)s +#define thr_mutex_init(m) +#define thr_mutex_lock(m) +#define thr_mutex_unlock(m) +#define thr_mutex_free(m) +#define thr_condition_init(c) +#define thr_condition_wait(c, m) +#define thr_condition_signal(c) +#define thr_condition_broadcast(c) +#define thr_condition_free(c) +#endif #ifdef USE_ZPL_ENET #define ENET_IMPLEMENTATION @@ -83,18 +188,19 @@ extern void ZPLENETdummy() { // for warning suppression #define INTERFACE_NAME(NAME) libcmenet_LTX_ ## NAME #include #endif +#ifndef _MSC_VER #include +#endif #include +#ifdef HAVE_SYS_TIME_H #include +#endif #ifdef __MACH__ #include #include #endif -#include -#include "evpath.h" -#include "cm_transport.h" typedef struct _queued_data { @@ -120,7 +226,7 @@ typedef struct enet_client_data { int wake_read_fd; enet_uint32 last_host_service_zero_return; CMTaskHandle periodic_handle; - pthread_mutex_t enet_lock; + thr_mutex_t enet_lock; int enet_locked; struct enet_connection_data *pending_connections; } *enet_client_data_ptr; @@ -174,7 +280,7 @@ static void IntENET_lock(enet_client_data_ptr ecd, char *file, int line) { // if (file) printf("(PID %lx, TID %lx) Trying ENET Lock at %s, line %d\n", (long) getpid(), (long)gettid(), file, line); - pthread_mutex_lock(&ecd->enet_lock); + thr_mutex_lock(ecd->enet_lock); // if (file) printf("GOT ENET Lock at %s, line %d\n", file, line); ecd->enet_locked++; } @@ -184,7 +290,7 @@ IntENET_unlock(enet_client_data_ptr ecd, char *file, int line) { // if (file) printf("(PID %lx, TID %lx) ENET Unlock at %s, line %d\n", (long) getpid(), (long)gettid(), file, line); ecd->enet_locked--; - pthread_mutex_unlock(&ecd->enet_lock); + thr_mutex_unlock(ecd->enet_lock); } static int @@ -243,7 +349,7 @@ handle_packet(CManager cm, CMtrans_services svc, transport_entry trans, enet_con CMbuffer cb; svc->trace_out(cm, "A packet of length %u was received.\n", (unsigned int) packet->dataLength); - econn_d->read_buffer_len = packet->dataLength; + econn_d->read_buffer_len = (int) packet->dataLength; cb = svc->create_data_and_link_buffer(cm, packet->data, econn_d->read_buffer_len); @@ -504,7 +610,7 @@ enet_accept_conn(enet_client_data_ptr ecd, transport_entry trans, svc->trace_out(trans->cm, "Accepted ENET RUDP connection from UNKNOWN host"); } add_attr(conn_attr_list, CM_PEER_LISTEN_PORT, Attr_Int4, - (attr_value) (long)enet_conn_data->remote_contact_port); + (attr_value) (intptr_t)enet_conn_data->remote_contact_port); #ifndef USE_IPV6 struct in_addr addr; addr.s_addr = htonl(enet_conn_data->remote_IP); @@ -560,14 +666,14 @@ enet_initiate_conn(CManager cm, CMtrans_services svc, transport_entry trans, } if (!query_attr(attrs, CM_ENET_HOSTNAME, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & host_name)) { + /* value pointer */ (attr_value *)(intptr_t) & host_name)) { svc->trace_out(cm, TPORT " transport found no CM_ENET_HOSTNAME attribute"); host_name = NULL; } else { svc->trace_out(cm, TPORT " transport connect to host %s", host_name); } if (!query_attr(attrs, CM_ENET_ADDR, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & host_ip)) { + /* value pointer */ (attr_value *)(intptr_t) & host_ip)) { svc->trace_out(cm, "CMEnet transport found no CM_ENET_ADDR attribute"); /* wasn't there */ host_ip = 0; @@ -581,7 +687,7 @@ enet_initiate_conn(CManager cm, CMtrans_services svc, transport_entry trans, } if (!query_attr(attrs, CM_ENET_PORT, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & int_port_num)) { + /* value pointer */ (attr_value *)(intptr_t) & int_port_num)) { svc->trace_out(cm, "CMEnet transport found no CM_ENET_PORT attribute"); return 0; } else { @@ -589,13 +695,13 @@ enet_initiate_conn(CManager cm, CMtrans_services svc, transport_entry trans, } if (!query_attr(attrs, CM_ENET_CONN_TIMEOUT, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & timeout)) { + /* value pointer */ (attr_value *)(intptr_t) & timeout)) { svc->trace_out(cm, "CMEnet transport found no CM_ENET_CONN_TIMEOUT attribute"); } else { svc->trace_out(cm, "CMEnet transport connection timeout set to %d msecs", timeout); } if (!query_attr(attrs, CM_ENET_CONN_REUSE, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & conn_reuse)) { + /* value pointer */ (attr_value *)(intptr_t) & conn_reuse)) { svc->trace_out(cm, "CMEnet transport found no CM_ENET_CONN_REUSE attribute"); } else { svc->trace_out(cm, "CMEnet transport connection reuse set to %d", conn_reuse); @@ -750,7 +856,7 @@ INTERFACE_NAME(finalize_conn_nonblocking)(CManager cm, CMtrans_services svc, } add_attr(conn_attr_list, CM_PEER_LISTEN_PORT, Attr_Int4, - (attr_value) (long)final_conn_data->remote_contact_port); + (attr_value) (intptr_t)final_conn_data->remote_contact_port); conn = svc->connection_create(trans, final_conn_data, conn_attr_list); final_conn_data->conn = conn; free_attr_list(conn_attr_list); @@ -792,18 +898,18 @@ INTERFACE_NAME(self_check)(CManager cm, CMtrans_services svc, IP = ntohl(INADDR_LOOPBACK); } if (!query_attr(attrs, CM_ENET_HOSTNAME, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & host_name)) { + /* value pointer */ (attr_value *)(intptr_t) & host_name)) { svc->trace_out(cm, "CMself check CMEnet transport found no CM_ENET_HOSTNAME attribute"); host_name = NULL; } if (!query_attr(attrs, CM_ENET_ADDR, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & host_addr)) { + /* value pointer */ (attr_value *)(intptr_t) & host_addr)) { svc->trace_out(cm, "CMself check CMEnet transport found no CM_ENET_ADDR attribute"); if (host_name == NULL) return 0; host_addr = 0; } if (!query_attr(attrs, CM_ENET_PORT, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & int_port_num)) { + /* value pointer */ (attr_value *)(intptr_t) & int_port_num)) { svc->trace_out(cm, "CMself check CMEnet transport found no CM_ENET_PORT attribute"); return 0; } @@ -842,16 +948,16 @@ INTERFACE_NAME(connection_eq)(CManager cm, CMtrans_services svc, (void) trans; if (!query_attr(attrs, CM_ENET_HOSTNAME, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & host_name)) { + /* value pointer */ (attr_value *)(intptr_t) & host_name)) { svc->trace_out(cm, "CMEnet transport found no CM_ENET_HOST attribute"); } if (!query_attr(attrs, CM_ENET_PORT, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & int_port_num)) { + /* value pointer */ (attr_value *)(intptr_t) & int_port_num)) { svc->trace_out(cm, "Conn Eq CMenet transport found no CM_ENET_PORT attribute"); return 0; } if (!query_attr(attrs, CM_ENET_ADDR, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & requested_IP)) { + /* value pointer */ (attr_value *)(intptr_t) & requested_IP)) { svc->trace_out(cm, "CMENET transport found no CM_ENET_ADDR attribute"); } if (requested_IP == -1) { @@ -912,7 +1018,7 @@ build_listen_attrs(CManager cm, CMtrans_services svc, enet_client_data_ptr ecd, } if ((IP != 0) && !use_hostname) { add_attr(ret_list, CM_ENET_ADDR, Attr_Int4, - (attr_value) (long)IP); + (attr_value) (intptr_t)IP); } if ((getenv("CMEnetsUseHostname") != NULL) || use_hostname) { @@ -922,7 +1028,7 @@ build_listen_attrs(CManager cm, CMtrans_services svc, enet_client_data_ptr ecd, add_int_attr(ret_list, CM_ENET_ADDR, INADDR_LOOPBACK); } add_attr(ret_list, CM_ENET_PORT, Attr_Int4, - (attr_value) (long)int_port_num); + (attr_value) (intptr_t)int_port_num); add_attr(ret_list, CM_TRANSPORT, Attr_String, (attr_value) strdup(TRANSPORT_STRING)); @@ -972,7 +1078,7 @@ INTERFACE_NAME(non_blocking_listen)(CManager cm, CMtrans_services svc, */ if (listen_info != NULL && !query_attr(listen_info, CM_ENET_PORT, - NULL, (attr_value *)(long) & attr_port_num)) { + NULL, (attr_value *)(intptr_t) & attr_port_num)) { port_num = 0; } else { if (attr_port_num > USHRT_MAX || attr_port_num < 0) { @@ -1042,17 +1148,16 @@ INTERFACE_NAME(non_blocking_listen)(CManager cm, CMtrans_services svc, svc->trace_out(cm, "CMEnet is listening on port %d\n", address.port); } else { /* specified port range */ - long seedval = time(NULL) + getpid(); /* port num is free. Constrain to range 26000 : 26100 */ int size; int tries; - srand48(seedval); + srand48(time(NULL) + getpid()); restart: size = high_bound - low_bound; tries = 10; while (tries > 0) { - int target = low_bound + size * drand48(); + int target = low_bound + (int)(size * drand48()); address.port = target; svc->trace_out(cm, "CMEnet trying to bind port %d", target); @@ -1206,7 +1311,7 @@ INTERFACE_NAME(writev_func)(CMtrans_services svc, enet_conn_data_ptr ecd, wake_enet_server_thread(ecd->ecd); - return iovcnt; + return (int)iovcnt; } @@ -1244,6 +1349,159 @@ shutdown_enet_thread } } +#ifdef HAVE_WINDOWS_H +static char* +WSAerror_str(err) +int err; +{ + switch(err) { + case WSAEINTR: return "WSAEINTR"; + case WSAEBADF: return "WSAEBADF"; + case WSAEACCES: return "WSAEACCES"; + case WSAEFAULT: return "WSAEFAULT"; + case WSAEINVAL: return "WSAEINVAL"; + case WSAEMFILE: return "WSAEMFILE"; + case WSAEWOULDBLOCK: return "WSAEWOULDBLOCK"; + case WSAEINPROGRESS: return "WSAEINPROGRESS"; + case WSAEALREADY: return "WSAEALREADY"; + case WSAENOTSOCK: return "WSAENOTSOCK"; + case WSAEDESTADDRREQ: return "WSAEDESTADDRREQ"; + case WSAEMSGSIZE: return "WSAEMSGSIZE"; + case WSAEPROTOTYPE: return "WSAEPROTOTYPE"; + case WSAENOPROTOOPT: return "WSAENOPROTOOPT"; + case WSAEPROTONOSUPPORT: return "WSAEPROTONOSUPPORT"; + case WSAESOCKTNOSUPPORT: return "WSAESOCKTNOSUPPORT"; + case WSAEOPNOTSUPP: return "WSAEOPNOTSUPP"; + case WSAEPFNOSUPPORT: return "WSAEPFNOSUPPORT"; + case WSAEAFNOSUPPORT: return "WSAEAFNOSUPPORT"; + case WSAEADDRINUSE: return "WSAEADDRINUSE"; + case WSAEADDRNOTAVAIL: return "WSAEADDRNOTAVAIL"; + case WSAENETDOWN: return "WSAENETDOWN"; + case WSAENETUNREACH: return "WSAENETUNREACH"; + case WSAENETRESET: return "WSAENETRESET"; + case WSAECONNABORTED: return "WSAECONNABORTED"; + case WSAECONNRESET: return "WSAECONNRESET"; + case WSAENOBUFS: return "WSAENOBUFS"; + case WSAEISCONN: return "WSAEISCONN"; + case WSAENOTCONN: return "WSAENOTCONN"; + case WSAESHUTDOWN: return "WSAESHUTDOWN"; + case WSAETOOMANYREFS: return "WSAETOOMANYREFS"; + case WSAETIMEDOUT: return "WSAETIMEDOUT"; + case WSAECONNREFUSED: return "WSAECONNREFUSED"; + case WSAELOOP: return "WSAELOOP"; + case WSAENAMETOOLONG: return "WSAENAMETOOLONG"; + case WSAEHOSTDOWN: return "WSAEHOSTDOWN"; + case WSAEHOSTUNREACH: return "WSAEHOSTUNREACH"; + case WSAENOTEMPTY: return "WSAENOTEMPTY"; + case WSAEPROCLIM: return "WSAEPROCLIM"; + case WSAEUSERS: return "WSAEUSERS"; + case WSAEDQUOT: return "WSAEDQUOT"; + case WSAESTALE: return "WSAESTALE"; + case WSAEREMOTE: return "WSAEREMOTE"; + case WSAEDISCON: return "WSAEDISCON"; + case WSASYSNOTREADY: return "WSASYSNOTREADY"; + case WSAVERNOTSUPPORTED: return "WSAVERNOTSUPPORTED"; + case WSANOTINITIALISED: return "WSANOTINITIALISED"; + default: return "Unknown Winsock error"; + } +} +/* + * Note. Unfortunately, the _pipe() function on WinNT + * produces FDs that you can't use in select(). This ruins what we want + * this pipe for, which is to wake up a thread sleeping in select(). + * So, we need to introduce a pipe function that returns two socket FDs. + * NT Sux. + */ + +int +pipe(filedes) +SOCKET filedes[2]; +{ + + int length; + struct sockaddr_in sock_addr; + int sock_opt_val = 1; + SOCKET sock1, sock2, conn_sock; + unsigned long block = TRUE; + int delay_value = 1; + + conn_sock = socket(AF_INET, SOCK_STREAM, 0); + if (conn_sock == SOCKET_ERROR) { + fprintf(stderr, "Cannot open INET socket\n"); + return -1; + } + sock_addr.sin_family = PF_INET; + sock_addr.sin_addr.s_addr = INADDR_ANY; + sock_addr.sin_port = 0; + if (bind(conn_sock, (struct sockaddr *) &sock_addr, + sizeof sock_addr) == SOCKET_ERROR) { + fprintf(stderr, "Cannot bind INET socket\n"); + return -1; + } + length = sizeof sock_addr; + if (getsockname(conn_sock, (struct sockaddr *) &sock_addr, &length) < 0) { + fprintf(stderr, "Cannot get socket name\n"); + return -1; + } + /* begin listening for conns */ + if (listen(conn_sock, FD_SETSIZE)) { + fprintf(stderr, "listen failed\n"); + return -1; + } + +/* send sock */ + if ((sock1 = socket(AF_INET, SOCK_STREAM, 0)) == SOCKET_ERROR) { + return -1; + } + sock_addr.sin_addr.s_addr = 0x0100007f; /* loopback */ + sock_addr.sin_family = PF_INET; + if (ioctlsocket(sock1, FIONBIO, &block) != 0) { + printf("ioctl failed\n"); + } + if (connect(sock1, (struct sockaddr *) &sock_addr, + sizeof sock_addr) == SOCKET_ERROR) { + int err = WSAGetLastError(); + if (err != WSAEWOULDBLOCK) { + printf("unexpected error from connect, %s\n", WSAerror_str(err)); + } + } + + if ((sock2 = accept(conn_sock, (struct sockaddr *) 0, (int *) 0)) == SOCKET_ERROR) { + int err = WSAGetLastError(); + printf("err was %s\n", WSAerror_str(err)); + } + + setsockopt(sock2, IPPROTO_TCP, TCP_NODELAY, (char *) &delay_value, + sizeof(delay_value)); + { + fd_set stXcptFDS,stWriteFDS; + struct timeval stTimeOut; /* for select() timeout (none) */ + int wRet; + + EVPATH_FD_ZERO((fd_set FAR*)&(stXcptFDS)); + EVPATH_FD_ZERO((fd_set FAR*)&(stWriteFDS)); + FD_SET(sock1, (fd_set FAR*)&(stWriteFDS)); + FD_SET(sock1, (fd_set FAR*)&(stXcptFDS)); + stTimeOut.tv_sec = 10; + stTimeOut.tv_usec = 0; + wRet = select(-1, NULL, + (fd_set FAR*)&(stWriteFDS), + (fd_set FAR*)&(stXcptFDS), + NULL); + if (wRet == SOCKET_ERROR) { + int err = WSAGetLastError(); + printf("err was %s\n", WSAerror_str(err)); + } + } + setsockopt(sock1, IPPROTO_TCP, TCP_NODELAY, (char *) &delay_value, + sizeof(delay_value)); + + filedes[0] = sock1; + filedes[1] = sock2; + return 0; +} +#endif + #ifdef __cplusplus extern "C" #else @@ -1289,7 +1547,7 @@ INTERFACE_NAME(initialize)(CManager cm, CMtrans_services svc, } enet_data = (enet_client_data_ptr) svc->malloc_func(sizeof(struct enet_client_data)); memset(enet_data, 0, sizeof(struct enet_client_data)); - pthread_mutex_init(&enet_data->enet_lock, NULL); + thr_mutex_init(enet_data->enet_lock); enet_data->enet_locked = 0; enet_data->cm = cm; enet_data->hostname = NULL; diff --git a/cmepoll.c b/cmepoll.c index 2d42ffa55a..57951c177d 100644 --- a/cmepoll.c +++ b/cmepoll.c @@ -3,8 +3,8 @@ #include #ifdef HAVE_WINDOWS_H +#include #include -#include #include #define getpid() _getpid() #else diff --git a/cmib.c b/cmib.c index d9f9b0c922..0100083b6d 100644 --- a/cmib.c +++ b/cmib.c @@ -3,8 +3,8 @@ #include #ifdef HAVE_WINDOWS_H +#include #include -#include #define getpid() _getpid() #else #include diff --git a/cmmulticast.c b/cmmulticast.c index d80b4bfb3b..82fdec1075 100644 --- a/cmmulticast.c +++ b/cmmulticast.c @@ -3,9 +3,11 @@ #include #ifdef HAVE_WINDOWS_H +#include +#include #include -#include #define getpid() _getpid() +#define close(x) closesocket(x) #else #ifdef HAVE_SYS_TIME_H #include @@ -95,8 +97,8 @@ typedef struct multicast_transport_data { typedef struct mcast_connection_data { int mcast_IP; int mcast_port; - int input_fd; - int output_fd; + SOCKET input_fd; + SOCKET output_fd; struct sockaddr_in output_addr; struct sockaddr_in my_addr; char read_buffer[MSGBUFSIZE]; @@ -106,11 +108,7 @@ typedef struct mcast_connection_data { multicast_transport_data_ptr mtd; } *mcast_conn_data_ptr; -#ifdef WSAEWOULDBLOCK -#define EWOULDBLOCK WSAEWOULDBLOCK -#define EAGAIN WSAEINPROGRESS -#define EINTR WSAEINTR -#define errno GetLastError() +#ifdef _MSC_VER #define read(fd, buf, len) recv(fd, buf, len, 0) #define write(fd, buf, len) send(fd, buf, len, 0) #endif @@ -183,11 +181,11 @@ libcmmulticast_LTX_shutdown_conn(CMtrans_services svc, mcast_conn_data_ptr mcd) #include "qual_hostname.c" -static int +static SOCKET initiate_conn(CManager cm, CMtrans_services svc, transport_entry trans, attr_list attrs, mcast_conn_data_ptr mcast_conn_data, attr_list conn_attr_list, int no_more_redirect) { int one = 1; - int input_fd, output_fd; + SOCKET input_fd, output_fd; int int_port_num; u_short port_num; multicast_transport_data_ptr mtd = (multicast_transport_data_ptr) trans->trans_data; @@ -199,7 +197,7 @@ initiate_conn(CManager cm, CMtrans_services svc, transport_entry trans, attr_lis (void) no_more_redirect; if (!query_attr(attrs, CM_MCAST_ADDR, /* type pointer */ NULL, - /* value pointer */ (attr_value *) (long) &mcast_ip)) { + /* value pointer */ (attr_value *) (intptr_t) &mcast_ip)) { svc->trace_out(cm, "CMMulticast transport found no MCAST_ADDR attribute"); /* wasn't there */ mcast_ip = 0; @@ -210,7 +208,7 @@ initiate_conn(CManager cm, CMtrans_services svc, transport_entry trans, attr_lis return -1; if (!query_attr(attrs, CM_MCAST_PORT, /* type pointer */ NULL, - /* value pointer */ (attr_value *) (long) &int_port_num)) { + /* value pointer */ (attr_value *) (intptr_t) &int_port_num)) { svc->trace_out(cm, "CMMulticast transport found no MCAST_PORT attribute"); return -1; } else { @@ -246,7 +244,7 @@ initiate_conn(CManager cm, CMtrans_services svc, transport_entry trans, attr_lis /* use setsockopt() to request that the kernel join a multicast group */ mreq.imr_multiaddr.s_addr = htonl(mcast_ip); mreq.imr_interface.s_addr = htonl(INADDR_ANY); - if (setsockopt(input_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) { + if (setsockopt(input_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char*) & mreq, sizeof(mreq)) < 0) { perror("setsockopt"); exit(1); } @@ -320,7 +318,7 @@ libcmmulticast_LTX_initiate_conn(CManager cm,CMtrans_services svc, transport_ent mcast_conn_data_ptr mcast_conn_data = create_mcast_conn_data(svc); attr_list conn_attr_list = create_attr_list(); CMConnection conn; - int sock; + SOCKET sock; if ((sock = initiate_conn(cm, svc, trans, attrs, mcast_conn_data, conn_attr_list, 0)) < 0) return NULL; @@ -354,12 +352,12 @@ libcmmulticast_LTX_connection_eq(CManager cm, CMtrans_services svc, transport_en int requested_IP = -1; if (!query_attr(attrs, CM_MCAST_PORT, /* type pointer */ NULL, - /* value pointer */ (attr_value *) (long) &int_port_num)) { + /* value pointer */ (attr_value *) (intptr_t) &int_port_num)) { svc->trace_out(cm, "Conn Eq CMMulticast transport found no MCAST_PORT attribute"); return 0; } if (!query_attr(attrs, CM_MCAST_ADDR, /* type pointer */ NULL, - /* value pointer */ (attr_value *) (long) &requested_IP)) { + /* value pointer */ (attr_value *) (intptr_t) &requested_IP)) { svc->trace_out(cm, "CMMulticast transport found no MCAST_ADDR attribute"); } svc->trace_out(cm, "CMMulticast Conn_eq comparing IP/ports %x/%d and %x/%d", @@ -376,11 +374,7 @@ libcmmulticast_LTX_connection_eq(CManager cm, CMtrans_services svc, transport_en extern attr_list -libcmmulticast_LTX_non_blocking_listen(cm, svc, trans, listen_info) -CManager cm; -CMtrans_services svc; -transport_entry trans; -attr_list listen_info; +libcmmulticast_LTX_non_blocking_listen(CManager cm, CMtrans_services svc, transport_entry trans, attr_list listen_info) { /* meaningless in muticast */ return NULL; @@ -404,11 +398,7 @@ struct iovec { * that are more efficient if they allocate their own buffer space. */ extern void * -libcmmulticast_LTX_read_func(svc, mcd, requested_len, actual_len) -CMtrans_services svc; -mcast_conn_data_ptr mcd; -int requested_len; -int *actual_len; +libcmmulticast_LTX_read_func(CMtrans_services svc, mcast_conn_data_ptr mcd, int requested_len, int *actual_len) { char *ret = &mcd->read_buffer[mcd->read_pointer]; *actual_len = requested_len; @@ -420,16 +410,16 @@ int *actual_len; /* this is not defined in some places where it should be. Conservative. */ #define IOV_MAX 16 #endif - +#ifdef _MSC_VER +#define msghdr _WSAMSG +#include +#endif extern int -libcmmulticast_LTX_writev_func(svc, mcd, iov, iovcnt, attrs) -CMtrans_services svc; -mcast_conn_data_ptr mcd; -struct iovec *iov; -int iovcnt; -attr_list attrs; +libcmmulticast_LTX_writev_func(CMtrans_services svc, mcast_conn_data_ptr mcd, struct iovec *iov, int iovcnt, attr_list attrs) { - int fd = mcd->output_fd; + SOCKET fd = mcd->output_fd; +#ifndef _MSC_VER + // no real equivalent on windows struct sockaddr_in addr = mcd->output_addr; struct msghdr msg; svc->trace_out(mcd->mtd->cm, "CMMcast writev of %d vectors on fd %d", @@ -443,6 +433,7 @@ attr_list attrs; perror("write sendmsg"); exit(1); } +#endif if (mcd->my_addr.sin_port == 0) { unsigned int nl; int IP = get_self_ip_addr(NULL, svc); @@ -472,9 +463,7 @@ free_mcast_data(CManager cm, void *mtdv) } extern void * -libcmmulticast_LTX_initialize(cm, svc) -CManager cm; -CMtrans_services svc; +libcmmulticast_LTX_initialize(CManager cm, CMtrans_services svc) { static int atom_init = 0; diff --git a/cmprobe.c b/cmprobe.c index 9a5c8932fb..90cdcc1d56 100644 --- a/cmprobe.c +++ b/cmprobe.c @@ -9,11 +9,12 @@ #include #include "evpath.h" #include +#ifdef _MSC_VER +#define sleep(x) Sleep(x*1000) +#endif int -main(argc, argv) - int argc; - char **argv; +main(int argc, char **argv) { CManager cm; CMConnection conn = NULL; diff --git a/cmselect.c b/cmselect.c index dcb4727635..36a6a6265a 100644 --- a/cmselect.c +++ b/cmselect.c @@ -3,10 +3,9 @@ #include #ifdef HAVE_WINDOWS_H +#include #include -#include #include -#define getpid() _getpid() #else #ifdef HAVE_SYS_TIME_H #include @@ -48,16 +47,48 @@ #ifdef HAVE_MEMORY_H #include #endif +#ifdef HAVE_PTHREAD_H +#include +#endif +#ifdef HAVE_SCHED_H +#include +#endif #include #include "evpath.h" #include "cm_transport.h" +#include "cm_internal.h" #include "ev_select.h" -#include -#include -#define thr_thread_t pthread_t -#define thr_thread_self() pthread_self() -#define thr_thread_yield() sched_yield() +#ifdef _MSC_VER +#define getpid() _getpid() +#define close(x) closesocket(x) +#endif +#undef realloc +#undef malloc + +extern void* +select_realloc(void* ptr, size_t size) +{ + void* tmp = realloc(ptr, size); + if ((tmp == 0) && (size != 0)) { + printf("Realloc failed on ptr %p, size %zd\n", ptr, size); + perror("realloc"); + } + return tmp; +} + +extern void* +select_malloc(size_t size) +{ + void* tmp = malloc(size); + if ((tmp == 0) && (size != 0)) { + printf("Malloc failed on size %zd\n", size); + perror("malloc"); + } + return tmp; +} +#define realloc(ptr, size) select_realloc(ptr, size) +#define malloc(size) select_malloc(size) #ifndef SOCKET_ERROR #define SOCKET_ERROR -1 @@ -107,14 +138,13 @@ static WORD wVersionRequested = MAKEWORD(1, 1); static WSADATA wsaData; int nErrorStatus; static char*WSAerror_str(int err); +#ifndef FD_SETSIZE #define FD_SETSIZE 1024 #endif +#endif static void -init_select_data(svc, sdp, cm) -CMtrans_services svc; -select_data_ptr *sdp; -CManager cm; +init_select_data(CMtrans_services svc, select_data_ptr *sdp, CManager cm) { select_data_ptr sd = malloc(sizeof(struct select_data)); *sdp = sd; @@ -122,7 +152,7 @@ CManager cm; EVPATH_FD_ZERO((fd_set *) sd->fdset); sd->write_set = svc->malloc_func(sizeof(fd_set)); EVPATH_FD_ZERO((fd_set *) sd->write_set); - sd->server_thread = (thr_thread_t) NULL; + sd->server_thread = (thr_thread_t)(intptr_t) NULL; sd->closed = 0; sd->sel_item_max = 0; sd->select_items = (FunctionListElement *) svc->malloc_func(sizeof(FunctionListElement)); @@ -157,9 +187,7 @@ typedef struct _periodic_task { } task_handle_s; static void -free_select_data(svc, sdp) -CMtrans_services svc; -select_data_ptr *sdp; +free_select_data(CMtrans_services svc, select_data_ptr *sdp) { periodic_task_handle tasks; select_data_ptr sd = *sdp; @@ -186,10 +214,7 @@ select_data_ptr *sdp; ((tvp)->tv_usec cmp (uvp)->tv_usec)))) static void -set_soonest_timeout(timeout, task_list, now) -struct timeval *timeout; -periodic_task_handle task_list; -struct timeval now; +set_soonest_timeout(struct timeval *timeout, periodic_task_handle task_list, struct timeval now) { struct timeval this_delay; if (task_list == NULL) return; @@ -212,10 +237,7 @@ struct timeval now; } static void -increment_time(time, increment_sec, increment_usec) -struct timeval *time; -int increment_sec; -int increment_usec; +increment_time(struct timeval *time, int increment_sec, int increment_usec) { time->tv_usec += increment_usec; time->tv_sec += increment_sec; @@ -229,11 +251,7 @@ static void shutdown_wake_mechanism(select_data_ptr sd); static void -socket_select(svc, sd, timeout_sec, timeout_usec) -CMtrans_services svc; -select_data_ptr sd; -int timeout_sec; -int timeout_usec; +socket_select(CMtrans_services svc, select_data_ptr sd, int timeout_sec, int timeout_usec) { int i, res; fd_set rd_set, wr_set; @@ -241,7 +259,7 @@ int timeout_usec; int tmp_select_consistency_number = sd->select_consistency_number; if (sd->closed) { - sd->server_thread = (thr_thread_t) NULL; + sd->server_thread = (thr_thread_t)(intptr_t) NULL; return; } @@ -249,7 +267,7 @@ int timeout_usec; /* assert CM is locked */ assert(CM_LOCKED(svc, sd->cm)); } - if (sd->server_thread == (thr_thread_t) NULL) { + if (sd->server_thread == (thr_thread_t)(intptr_t) NULL) { /* no server thread set, must be this one */ sd->server_thread = thr_thread_self(); } @@ -272,7 +290,7 @@ int timeout_usec; */ struct _timeb nowb; _ftime(&nowb); - now.tv_sec = nowb.time; + now.tv_sec = (long)nowb.time; now.tv_usec = nowb.millitm * 1000; #endif if (timeout_usec >= 1000000) { @@ -302,7 +320,7 @@ int timeout_usec; ACQUIRE_CM_LOCK(svc, sd->cm); } if (sd->closed) { - sd->server_thread = (thr_thread_t) NULL; + sd->server_thread = (thr_thread_t)(intptr_t) NULL; return; } #ifndef HAVE_WINDOWS_H @@ -380,7 +398,7 @@ int timeout_usec; if (errno_val == WSAEINTR || errno_val == WSAEINVAL) { return; } else { - fprintf(stderr, "select failed, errno %d\n", + fprintf(stderr, "select failed, errno %s\n", WSAerror_str(errno_val)); } return; @@ -421,7 +439,7 @@ int timeout_usec; if (res != 0) { for (i = 0; i <= sd->sel_item_max; i++) { if (sd->closed) { - sd->server_thread = (thr_thread_t) NULL; + sd->server_thread = (thr_thread_t)(intptr_t) NULL; return; } if (FD_ISSET(i, &wr_set)) { @@ -468,7 +486,7 @@ int timeout_usec; */ struct _timeb nowb; _ftime(&nowb); - now.tv_sec = nowb.time; + now.tv_sec = (long) nowb.time; now.tv_usec = nowb.millitm * 1000; #endif while (this_periodic_task != NULL ) { @@ -509,13 +527,7 @@ int timeout_usec; } extern void -libcmselect_LTX_add_select(svc, sdp, fd, func, arg1, arg2) -CMtrans_services svc; -select_data_ptr *sdp; -int fd; -select_list_func func; -void *arg1; -void *arg2; +libcmselect_LTX_add_select(CMtrans_services svc, select_data_ptr *sdp, int fd, select_list_func func, void *arg1, void *arg2) { select_data_ptr sd = *((select_data_ptr *)sdp); if (sd->cm) { @@ -567,13 +579,7 @@ void *arg2; } extern void -libcmselect_LTX_write_select(svc, sdp, fd, func, arg1, arg2) -CMtrans_services svc; -select_data_ptr *sdp; -int fd; -select_list_func func; -void *arg1; -void *arg2; +libcmselect_LTX_write_select(CMtrans_services svc, select_data_ptr *sdp, int fd, select_list_func func, void *arg1, void *arg2) { select_data_ptr sd = *((select_data_ptr *)sdp); if (sd == NULL) { @@ -630,15 +636,7 @@ void *arg2; } extern periodic_task_handle -libcmselect_LTX_add_periodic(svc, sdp, interval_sec, interval_usec, - func, arg1, arg2) -CMtrans_services svc; -select_data_ptr *sdp; -int interval_sec; -int interval_usec; -select_list_func func; -void *arg1; -void *arg2; +libcmselect_LTX_add_periodic(CMtrans_services svc, select_data_ptr *sdp, int interval_sec, int interval_usec, select_list_func func, void *arg1, void *arg2) { select_data_ptr sd = *((select_data_ptr *)sdp); periodic_task_handle handle = malloc(sizeof(struct _periodic_task)); @@ -663,7 +661,7 @@ void *arg2; { struct _timeb nowb; _ftime(&nowb); - handle->next_time.tv_sec = nowb.time; + handle->next_time.tv_sec = (long)nowb.time; handle->next_time.tv_usec = nowb.millitm * 1000; } #endif @@ -685,15 +683,7 @@ void *arg2; extern periodic_task_handle -libcmselect_LTX_add_delayed_task(svc, sdp, delay_sec, delay_usec, - func, arg1, arg2) -CMtrans_services svc; -select_data_ptr *sdp; -int delay_sec; -int delay_usec; -select_list_func func; -void *arg1; -void *arg2; +libcmselect_LTX_add_delayed_task(CMtrans_services svc, select_data_ptr *sdp, int delay_sec, int delay_usec, select_list_func func, void *arg1, void *arg2) { select_data_ptr sd = *((select_data_ptr *)sdp); periodic_task_handle handle = malloc(sizeof(struct _periodic_task)); @@ -718,8 +708,8 @@ void *arg2; */ struct _timeb nowb; _ftime(&nowb); - handle->next_time.tv_sec = nowb.time; - handle->next_time.tv_usec = nowb.millitm * 1000; + handle->next_time.tv_sec = (long)nowb.time; + handle->next_time.tv_usec = (long)(nowb.millitm * 1000); } #endif increment_time(&handle->next_time, delay_sec, delay_usec); @@ -739,9 +729,7 @@ void *arg2; } static int -remove_periodic_task(sd, handle) -select_data_ptr sd; -periodic_task_handle handle; +remove_periodic_task(select_data_ptr sd, periodic_task_handle handle) { periodic_task_handle list, last = NULL; list = sd->periodic_task_list; @@ -779,10 +767,7 @@ periodic_task_handle handle; extern void -libcmselect_LTX_remove_periodic(svc, sdp, handle) -CMtrans_services svc; -select_data_ptr *sdp; -periodic_task_handle handle; +libcmselect_LTX_remove_periodic(CMtrans_services svc, select_data_ptr *sdp, periodic_task_handle handle) { select_data_ptr sd = *((select_data_ptr *)sdp); if (sd == NULL) return; @@ -792,10 +777,7 @@ periodic_task_handle handle; } extern void -libcmselect_LTX_remove_select(svc, sdp, fd) -CMtrans_services svc; -select_data_ptr *sdp; -int fd; +libcmselect_LTX_remove_select(CMtrans_services svc, select_data_ptr *sdp, int fd) { select_data_ptr sd = *((select_data_ptr *)sdp); if (sd == NULL) { @@ -811,8 +793,7 @@ int fd; } static void -shutdown_wake_mechanism(sd) -select_data_ptr sd; +shutdown_wake_mechanism(select_data_ptr sd) { if (sd->wake_read_fd == -1) return; close(sd->wake_read_fd); @@ -820,12 +801,10 @@ select_data_ptr sd; sd->wake_read_fd = sd->wake_write_fd = -1; } -static void read_wake_fd(fd_as_ptr, junk) -void *fd_as_ptr; -void *junk; +static void read_wake_fd(void *fd_as_ptr, void *junk) { char buffer; - int fd = (int) (long)fd_as_ptr; + SOCKET fd = (SOCKET) (intptr_t)fd_as_ptr; #ifdef HAVE_WINDOWS_H recv(fd, &buffer, 1, 0); #else @@ -901,13 +880,13 @@ int err; int pipe(filedes) -int filedes[2]; +SOCKET filedes[2]; { int length; struct sockaddr_in sock_addr; int sock_opt_val = 1; - int sock1, sock2, conn_sock; + SOCKET sock1, sock2, conn_sock; unsigned long block = TRUE; int delay_value = 1; @@ -989,9 +968,7 @@ int filedes[2]; #endif static void -setup_wake_mechanism(svc, sdp) -CMtrans_services svc; -select_data_ptr *sdp; +setup_wake_mechanism(CMtrans_services svc, select_data_ptr *sdp) { int filedes[2]; @@ -1010,13 +987,11 @@ select_data_ptr *sdp; svc->verbose(sd->cm, CMSelectVerbose, "CMSelect Adding read_wake_fd as action on fd %d", sd->wake_read_fd); libcmselect_LTX_add_select(svc, sdp, sd->wake_read_fd, read_wake_fd, - (void*)(long)sd->wake_read_fd, NULL); + (void*)(intptr_t)sd->wake_read_fd, NULL); } extern void -libcmselect_LTX_wake_function(svc, sdp) -CMtrans_services svc; -select_data_ptr *sdp; +libcmselect_LTX_wake_function(CMtrans_services svc, select_data_ptr *sdp) { if (*sdp != NULL) { wake_server_thread(*sdp); @@ -1024,8 +999,7 @@ select_data_ptr *sdp; } static void -wake_server_thread(sd) -select_data_ptr sd; +wake_server_thread(select_data_ptr sd) { static char buffer = 'W'; /* doesn't matter what we write */ if (sd->wake_write_fd != -1) { @@ -1040,9 +1014,7 @@ select_data_ptr sd; } extern void -libcmselect_LTX_blocking_function(svc, client_data) -CMtrans_services svc; -void *client_data; +libcmselect_LTX_blocking_function(CMtrans_services svc, void *client_data) { select_data_ptr sd = *((select_data_ptr *)client_data); if (sd == NULL) { @@ -1057,9 +1029,7 @@ void *client_data; } extern void -libcmselect_LTX_polling_function(svc, client_data) -CMtrans_services svc; -void *client_data; +libcmselect_LTX_polling_function(CMtrans_services svc, void *client_data) { select_data_ptr sd = *((select_data_ptr *)client_data); if (sd == NULL) { @@ -1074,10 +1044,7 @@ void *client_data; } extern void -libcmselect_LTX_select_initialize(svc, cm, client_data) -CMtrans_services svc; -CManager cm; -void *client_data; +libcmselect_LTX_select_initialize(CMtrans_services svc, CManager cm, void *client_data) { if (*((select_data_ptr *)client_data) == NULL) { init_select_data(svc, (select_data_ptr*)client_data, cm); @@ -1085,10 +1052,7 @@ void *client_data; } extern void -libcmselect_LTX_select_shutdown(svc, cm, client_data) -CMtrans_services svc; -CManager cm; -void *client_data; +libcmselect_LTX_select_shutdown(CMtrans_services svc, CManager cm, void *client_data) { select_data_ptr *sdp = client_data; select_data_ptr sd = *sdp; @@ -1101,10 +1065,7 @@ void *client_data; } extern void -libcmselect_LTX_select_free(svc, cm, client_data) -CMtrans_services svc; -CManager cm; -void *client_data; +libcmselect_LTX_select_free(CMtrans_services svc, CManager cm, void *client_data) { select_data_ptr *sdp = client_data; select_data_ptr sd = *sdp; @@ -1119,9 +1080,7 @@ void *client_data; } extern void -libcmselect_LTX_select_stop(svc, client_data) -CMtrans_services svc; -void *client_data; +libcmselect_LTX_select_stop(CMtrans_services svc, void *client_data) { if (*((select_data_ptr *)client_data) != NULL) { (*((select_data_ptr*)client_data))->closed = 1; diff --git a/cmsockets.c b/cmsockets.c index 14a7452137..26d83b88cd 100644 --- a/cmsockets.c +++ b/cmsockets.c @@ -3,8 +3,10 @@ #include #ifdef HAVE_WINDOWS_H +#include #include -#include +#include +#include #define getpid() _getpid() #else #include @@ -45,6 +47,8 @@ #include #include #include +#else +#include #endif #ifdef HAVE_UNISTD_H #include @@ -86,7 +90,7 @@ typedef struct socket_client_data { CManager cm; char *hostname; int listen_count; - int *listen_fds; + SOCKET *listen_fds; int *listen_ports; attr_list characteristics; CMtrans_services svc; @@ -97,19 +101,17 @@ typedef enum {Block, Non_Block} socket_block_state; typedef struct socket_connection_data { int remote_IP; int remote_contact_port; - int fd; + SOCKET fd; socket_client_data_ptr sd; socket_block_state block_state; CMConnection conn; } *socket_conn_data_ptr; -#ifdef WSAEWOULDBLOCK -#define EWOULDBLOCK WSAEWOULDBLOCK -#define EAGAIN WSAEINPROGRESS -#define EINTR WSAEINTR -#define errno GetLastError() +#ifdef _MSC_VER #define read(fd, buf, len) recv(fd, buf, len, 0) #define write(fd, buf, len) send(fd, buf, len, 0) +#define close(x) closesocket(x) +#define INST_ADDRSTRLEN 50 #endif static atom_t CM_FD = -1; @@ -127,15 +129,14 @@ static atom_t CM_IP_ADDR = -1; #define TIMING_GUARD_STOP gettimeofday(&t1, NULL); timersub(&t1, &t0, &diff); if (diff.tv_sec > 0) fprintf(stderr, "TIME GUARD at %s:%d exceeded, time was was <%ld.%06ld> secs\n", __FILE__, __LINE__, (long)diff.tv_sec, (long)diff.tv_usec);} static int -check_host(hostname, sin_addr) -char *hostname; -void *sin_addr; +check_host(char *hostname, void *sin_addr) { struct hostent *host_addr; host_addr = gethostbyname(hostname); if (host_addr == NULL) { struct in_addr addr; - if (inet_aton(hostname, &addr) == 0) { + if (inet_pton(PF_INET, hostname, &addr) == 0) { +// if (inet_aton(hostname, &addr) == 0) { /* * not translatable as a hostname or * as a dot-style string IP address @@ -151,8 +152,7 @@ void *sin_addr; } static socket_conn_data_ptr -create_socket_conn_data(svc) -CMtrans_services svc; +create_socket_conn_data(CMtrans_services svc) { socket_conn_data_ptr socket_conn_data = svc->malloc_func(sizeof(struct socket_connection_data)); @@ -203,20 +203,22 @@ int fd; #endif +#ifndef INET_ADDRSTRLEN +#define INET_ADDRSTRLEN 50 +#endif + /* * Accept socket connection */ static void -socket_accept_conn(void_trans, void_conn_sock) -void *void_trans; -void *void_conn_sock; +socket_accept_conn(void *void_trans, void *void_conn_sock) { transport_entry trans = (transport_entry) void_trans; - int conn_sock = (int) (long) void_conn_sock; + int conn_sock = (int) (intptr_t) void_conn_sock; socket_client_data_ptr sd = (socket_client_data_ptr) trans->trans_data; CMtrans_services svc = sd->svc; socket_conn_data_ptr socket_conn_data; - int sock; + SOCKET sock; struct sockaddr sock_addr; unsigned int sock_len = sizeof(sock_addr); int int_port_num; @@ -262,24 +264,24 @@ void *void_conn_sock; socket_conn_data->conn = conn; add_attr(conn_attr_list, CM_FD, Attr_Int4, - (attr_value) (long)sock); + (attr_value) (intptr_t)sock); sock_len = sizeof(sock_addr); memset(&sock_addr, 0, sock_len); getsockname(sock, (struct sockaddr *) &sock_addr, &sock_len); int_port_num = ntohs(((struct sockaddr_in *) &sock_addr)->sin_port); add_attr(conn_attr_list, CM_THIS_CONN_PORT, Attr_Int4, - (attr_value) (long)int_port_num); + (attr_value) (intptr_t)int_port_num); memset(&sock_addr, 0, sizeof(sock_addr)); sock_len = sizeof(sock_addr); if (getpeername(sock, &sock_addr, &sock_len) == 0) { int_port_num = ntohs(((struct sockaddr_in *) &sock_addr)->sin_port); add_attr(conn_attr_list, CM_PEER_CONN_PORT, Attr_Int4, - (attr_value) (long)int_port_num); + (attr_value) (intptr_t)int_port_num); socket_conn_data->remote_IP = ntohl(((struct sockaddr_in *) &sock_addr)->sin_addr.s_addr); add_attr(conn_attr_list, CM_PEER_IP, Attr_Int4, - (attr_value) (long)socket_conn_data->remote_IP); + (attr_value) (intptr_t)socket_conn_data->remote_IP); } { char str[INET_ADDRSTRLEN]; @@ -295,7 +297,7 @@ void *void_conn_sock; socket_conn_data->remote_contact_port = ntohs(socket_conn_data->remote_contact_port); add_attr(conn_attr_list, CM_PEER_LISTEN_PORT, Attr_Int4, - (attr_value) (long)socket_conn_data->remote_contact_port); + (attr_value) (intptr_t)socket_conn_data->remote_contact_port); svc->trace_out(sd->cm, "Remote host (IP %x) is listening at port %d\n", socket_conn_data->remote_IP, socket_conn_data->remote_contact_port); @@ -310,9 +312,7 @@ void *void_conn_sock; } extern void -libcmsockets_LTX_shutdown_conn(svc, scd) -CMtrans_services svc; -socket_conn_data_ptr scd; +libcmsockets_LTX_shutdown_conn(CMtrans_services svc, socket_conn_data_ptr scd) { svc->connection_deref(scd->conn); svc->fd_remove_select(scd->sd->cm, scd->fd); @@ -339,16 +339,10 @@ is_private_10(int IP) return ((IP & 0xff000000) == 0x0A000000); /* equal 10.x.x.x */ } -static int -initiate_conn(cm, svc, trans, attrs, socket_conn_data, conn_attr_list) -CManager cm; -CMtrans_services svc; -transport_entry trans; -attr_list attrs; -socket_conn_data_ptr socket_conn_data; -attr_list conn_attr_list; +static SOCKET +initiate_conn(CManager cm, CMtrans_services svc, transport_entry trans, attr_list attrs, socket_conn_data_ptr socket_conn_data, attr_list conn_attr_list) { - int sock; + SOCKET sock; #ifdef TCP_NODELAY int delay_value = 1; @@ -373,14 +367,14 @@ attr_list conn_attr_list; assert(CM_LOCKED(svc, sd->cm)); } if (!query_attr(attrs, CM_IP_HOSTNAME, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & host_name)) { + /* value pointer */ (attr_value *)(intptr_t) & host_name)) { svc->trace_out(cm, "TCP/IP transport found no IP_HOST attribute"); host_name = NULL; } else { svc->trace_out(cm, "TCP/IP transport connect to host %s", host_name); } if (!query_attr(attrs, CM_IP_ADDR, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & host_ip)) { + /* value pointer */ (attr_value *)(intptr_t) & host_ip)) { svc->trace_out(cm, "TCP/IP transport found no IP_ADDR attribute"); /* wasn't there */ host_ip = 0; @@ -391,7 +385,7 @@ attr_list conn_attr_list; return -1; if (!query_attr(attrs, CM_IP_PORT, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & int_port_num)) { + /* value pointer */ (attr_value *)(intptr_t) & int_port_num)) { svc->trace_out(cm, "TCP/IP transport found no IP_PORT attribute"); return -1; } else { @@ -487,7 +481,7 @@ attr_list conn_attr_list; if (sd->listen_count) { local_listen_port = htons(sd->listen_ports[0]); } - if (write(sock, &local_listen_port, 4) != 4) { + if (write(sock, (const char *) & local_listen_port, 4) != 4) { svc->trace_out(cm, "Write failed\n"); return -1; } @@ -499,14 +493,14 @@ attr_list conn_attr_list; socket_conn_data->sd = sd; add_attr(conn_attr_list, CM_FD, Attr_Int4, - (attr_value) (long)sock); + (attr_value) (intptr_t)sock); sock_len = sizeof(sock_addr); getsockname(sock, (struct sockaddr *) &sock_addr, &sock_len); int_port_num = ntohs(((struct sockaddr_in *) &sock_addr)->sin_port); add_attr(conn_attr_list, CM_THIS_CONN_PORT, Attr_Int4, - (attr_value) (long)int_port_num); + (attr_value) (intptr_t)int_port_num); add_attr(conn_attr_list, CM_PEER_IP, Attr_Int4, - (attr_value) (long)socket_conn_data->remote_IP); + (attr_value) (intptr_t)socket_conn_data->remote_IP); return sock; } @@ -517,16 +511,12 @@ attr_list conn_attr_list; * (name_str stores the machine name). */ extern CMConnection -libcmsockets_LTX_initiate_conn(cm, svc, trans, attrs) -CManager cm; -CMtrans_services svc; -transport_entry trans; -attr_list attrs; +libcmsockets_LTX_initiate_conn(CManager cm, CMtrans_services svc, transport_entry trans, attr_list attrs) { socket_conn_data_ptr socket_conn_data = create_socket_conn_data(svc); attr_list conn_attr_list = create_attr_list(); CMConnection conn; - int sock; + SOCKET sock; socket_client_data_ptr sd = trans->trans_data; if (sd->cm) { @@ -537,7 +527,7 @@ attr_list attrs; return NULL; add_attr(conn_attr_list, CM_PEER_LISTEN_PORT, Attr_Int4, - (attr_value) (long)socket_conn_data->remote_contact_port); + (attr_value) (intptr_t)socket_conn_data->remote_contact_port); conn = svc->connection_create(trans, socket_conn_data, conn_attr_list); socket_conn_data->conn = conn; @@ -561,11 +551,7 @@ attr_list attrs; * same as ours and if the IP_PORT matches the one we are listening on. */ extern int -libcmsockets_LTX_self_check(cm, svc, trans, attrs) -CManager cm; -CMtrans_services svc; -transport_entry trans; -attr_list attrs; +libcmsockets_LTX_self_check(CManager cm, CMtrans_services svc, transport_entry trans, attr_list attrs) { socket_client_data_ptr sd = trans->trans_data; @@ -582,18 +568,18 @@ attr_list attrs; if (IP == 0) IP = INADDR_LOOPBACK; } if (!query_attr(attrs, CM_IP_HOSTNAME, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & host_name)) { + /* value pointer */ (attr_value *)(intptr_t) & host_name)) { svc->trace_out(cm, "CMself check TCP/IP transport found no IP_HOST attribute"); host_name = NULL; } if (!query_attr(attrs, CM_IP_ADDR, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & host_addr)) { + /* value pointer */ (attr_value *)(intptr_t) & host_addr)) { svc->trace_out(cm, "CMself check TCP/IP transport found no IP_ADDR attribute"); if (host_name == NULL) return 0; host_addr = 0; } if (!query_attr(attrs, CM_IP_PORT, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & int_port_num)) { + /* value pointer */ (attr_value *)(intptr_t) & int_port_num)) { svc->trace_out(cm, "CMself check TCP/IP transport found no IP_PORT attribute"); return 0; } @@ -620,12 +606,7 @@ attr_list attrs; } extern int -libcmsockets_LTX_connection_eq(cm, svc, trans, attrs, scd) -CManager cm; -CMtrans_services svc; -transport_entry trans; -attr_list attrs; -socket_conn_data_ptr scd; +libcmsockets_LTX_connection_eq(CManager cm, CMtrans_services svc, transport_entry trans, attr_list attrs, socket_conn_data_ptr scd) { int int_port_num; @@ -633,16 +614,16 @@ socket_conn_data_ptr scd; char *host_name = NULL; if (!query_attr(attrs, CM_IP_HOSTNAME, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & host_name)) { + /* value pointer */ (attr_value *)(intptr_t) & host_name)) { svc->trace_out(cm, "TCP/IP transport found no IP_HOST attribute"); } if (!query_attr(attrs, CM_IP_PORT, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & int_port_num)) { + /* value pointer */ (attr_value *)(intptr_t) & int_port_num)) { svc->trace_out(cm, "Conn Eq TCP/IP transport found no IP_PORT attribute"); return 0; } if (!query_attr(attrs, CM_IP_ADDR, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & requested_IP)) { + /* value pointer */ (attr_value *)(intptr_t) & requested_IP)) { svc->trace_out(cm, "TCP/IP transport found no IP_ADDR attribute"); } if (requested_IP == -1) { @@ -668,17 +649,13 @@ socket_conn_data_ptr scd; * Create an IP socket for connection from other CMs */ extern attr_list -libcmsockets_LTX_non_blocking_listen(cm, svc, trans, listen_info) -CManager cm; -CMtrans_services svc; -transport_entry trans; -attr_list listen_info; +libcmsockets_LTX_non_blocking_listen(CManager cm, CMtrans_services svc, transport_entry trans, attr_list listen_info) { socket_client_data_ptr sd = trans->trans_data; unsigned int length; struct sockaddr_in sock_addr; int sock_opt_val = 1; - int conn_sock = 0; + SOCKET conn_sock = 0; int attr_port_num = 0; u_short port_num = 0; int port_range_low, port_range_high; @@ -695,7 +672,7 @@ attr_list listen_info; */ if (listen_info != NULL && !query_attr(listen_info, CM_IP_PORT, - NULL, (attr_value *)(long) & attr_port_num)) { + NULL, (attr_value *)(intptr_t) & attr_port_num)) { port_num = 0; } else { if (attr_port_num > USHRT_MAX || attr_port_num < 0) { @@ -758,14 +735,14 @@ attr_list listen_info; return NULL; } } else { - long seedval = time(NULL) + getpid(); + long seedval = (long) time(NULL) + getpid(); /* port num is free. Constrain to range to standards */ int size = port_range_high - port_range_low; int tries = 30; int result = SOCKET_ERROR; - srand48(seedval); + srand(seedval); while (tries > 0) { - int target = port_range_low + size * drand48(); + int target = port_range_low + (rand() % size); sock_addr.sin_port = htons(target); svc->trace_out(cm, "CMSocket trying to bind port %d", target); result = bind(conn_sock, (struct sockaddr *) &sock_addr, @@ -774,7 +751,7 @@ attr_list listen_info; if (result != SOCKET_ERROR) tries = 0; if (tries%5 == 4) { /* try reseeding in case we're in sync with another process */ - srand48(time(NULL) + getpid()); + srand((int)time(NULL) + (int)getpid()); } if (tries == 20) { /* damn, tried a lot, increase the range (This might violate specified range) */ @@ -796,8 +773,8 @@ attr_list listen_info; return NULL; } svc->trace_out(cm, "CMSockets Adding socket_accept_conn as action on fd %d", conn_sock); - svc->fd_add_select(cm, conn_sock, socket_accept_conn, - (void *) trans, (void *) (long)conn_sock); + svc->fd_add_select(cm, conn_sock, (select_list_func)socket_accept_conn, + (void *) trans, (void *) (intptr_t)conn_sock); length = sizeof(sock_addr); if (getsockname(conn_sock, (struct sockaddr *) &sock_addr, &length) < 0) { @@ -833,7 +810,7 @@ attr_list listen_info; sd->hostname = strdup(host_name); if ((IP != 0) && (!use_hostname)) { add_attr(ret_list, CM_IP_ADDR, Attr_Int4, - (attr_value) (long)IP); + (attr_value) (intptr_t)IP); } if ((getenv("CMSocketsUseHostname") != NULL) || use_hostname) { @@ -844,7 +821,7 @@ attr_list listen_info; (attr_value)INADDR_LOOPBACK); } add_attr(ret_list, CM_IP_PORT, Attr_Int4, - (attr_value) (long)int_port_num); + (attr_value) (intptr_t)int_port_num); return ret_list; } @@ -863,11 +840,7 @@ struct iovec { #endif extern void -libcmsockets_LTX_set_write_notify(trans, svc, scd, enable) -transport_entry trans; -CMtrans_services svc; -socket_conn_data_ptr scd; -int enable; +libcmsockets_LTX_set_write_notify(transport_entry trans, CMtrans_services svc, socket_conn_data_ptr scd, int enable) { if (enable != 0) { svc->fd_write_select(trans->cm, scd->fd, (select_list_func) trans->write_possible, @@ -883,6 +856,7 @@ static void set_block_state(CMtrans_services svc, socket_conn_data_ptr scd, socket_block_state needed_block_state) { +#ifndef _MSC_VER int fdflags = fcntl(scd->fd, F_GETFL, 0); if (fdflags == -1) { perror("getflags\n"); @@ -904,24 +878,22 @@ set_block_state(CMtrans_services svc, socket_conn_data_ptr scd, svc->trace_out(scd->sd->cm, "CMSocket switch fd %d to nonblocking", scd->fd); } +#else +#endif } -extern int -libcmsockets_LTX_read_to_buffer_func(svc, scd, buffer, requested_len, - non_blocking) -CMtrans_services svc; -socket_conn_data_ptr scd; -void *buffer; -ssize_t requested_len; -int non_blocking; +extern ssize_t +libcmsockets_LTX_read_to_buffer_func(CMtrans_services svc, socket_conn_data_ptr scd, void *buffer, ssize_t requested_len, int non_blocking) { ssize_t left, iget; - +#ifndef _MSC_VER + // GSE int fdflags = fcntl(scd->fd, F_GETFL, 0); if (fdflags == -1) { perror("getflags\n"); return -1; } +#endif if (scd->block_state == Block) { svc->trace_out(scd->sd->cm, "CMSocket fd %d state block", scd->fd); } else { @@ -934,7 +906,7 @@ int non_blocking; scd->fd); set_block_state(svc, scd, Non_Block); } - iget = read(scd->fd, (char *) buffer, requested_len); + iget = read(scd->fd, (char *) buffer, (int)requested_len); if ((iget == -1) || (iget == 0)) { int lerrno = errno; if ((lerrno != EWOULDBLOCK) && @@ -957,7 +929,7 @@ int non_blocking; while (left > 0) { int lerrno; iget = read(scd->fd, (char *) buffer + requested_len - left, - left); + (int)left); lerrno = errno; if (iget == -1) { if ((lerrno != EWOULDBLOCK) && @@ -1010,8 +982,8 @@ int iovcnt; while (left > 0) { errno = 0; size_t this_write = left; - char *this_base = iov[i].iov_base + iov[i].iov_len - left; - iget = write(fd, this_base, this_write); + char *this_base = ((char*)iov[i].iov_base) + iov[i].iov_len - left; + iget = write(fd, this_base, (int)this_write); if (iget == -1) { int lerrno = errno; if ((lerrno != EWOULDBLOCK) && @@ -1031,13 +1003,10 @@ int iovcnt; } #endif -int long_writev(svc, scd, iovs, iovcnt) -CMtrans_services svc; -socket_conn_data_ptr scd; -void *iovs; -int iovcnt; +int long_writev(CMtrans_services svc, socket_conn_data_ptr scd, void *iovs, int iovcnt) { assert(0); // for right now, don't try this + return 0; } #ifndef MAX_RW_COUNT @@ -1045,15 +1014,10 @@ int iovcnt; #define MAX_RW_COUNT 0x7ffff000 #endif -extern int -libcmsockets_LTX_writev_func(svc, scd, iovs, iovcnt, attrs) -CMtrans_services svc; -socket_conn_data_ptr scd; -void *iovs; -int iovcnt; -attr_list attrs; +extern ssize_t +libcmsockets_LTX_writev_func(CMtrans_services svc, socket_conn_data_ptr scd, void *iovs, int iovcnt, attr_list attrs) { - int fd = scd->fd; + SOCKET fd = scd->fd; ssize_t left = 0; ssize_t iget = 0; ssize_t iovleft, i; @@ -1120,15 +1084,10 @@ attr_list attrs; } /* non blocking version */ -extern int -libcmsockets_LTX_NBwritev_func(svc, scd, iovs, iovcnt, attrs) -CMtrans_services svc; -socket_conn_data_ptr scd; -void *iovs; -int iovcnt; -attr_list attrs; +extern ssize_t +libcmsockets_LTX_NBwritev_func(CMtrans_services svc, socket_conn_data_ptr scd, void *iovs, int iovcnt, attr_list attrs) { - int fd = scd->fd; + SOCKET fd = scd->fd; ssize_t init_bytes, left = 0; ssize_t iget = 0; ssize_t iovleft, i; @@ -1180,8 +1139,8 @@ attr_list attrs; int socket_global_init = 0; #ifdef HAVE_WINDOWS_H -/* Winsock init stuff, ask for ver 1.1 */ -static WORD wVersionRequested = MAKEWORD(1, 1); +/* Winsock init stuff, ask for ver 2.2 */ +static WORD wVersionRequested = MAKEWORD(2, 2); static WSADATA wsaData; #endif @@ -1275,9 +1234,9 @@ cmsockets_add_static_transport(CManager cm, CMtrans_services svc) transport->cm = cm; transport->transport_init = (CMTransport_func)libcmsockets_LTX_initialize; transport->listen = (CMTransport_listen_func)libcmsockets_LTX_non_blocking_listen; - transport->initiate_conn = (CMConnection(*)())libcmsockets_LTX_initiate_conn; - transport->self_check = (int(*)())libcmsockets_LTX_self_check; - transport->connection_eq = (int(*)())libcmsockets_LTX_connection_eq; + transport->initiate_conn = (CMTransport_conn_func)libcmsockets_LTX_initiate_conn; + transport->self_check = (CMTransport_self_check_func)libcmsockets_LTX_self_check; + transport->connection_eq = (CMTransport_connection_eq_func)libcmsockets_LTX_connection_eq; transport->shutdown_conn = (CMTransport_shutdown_conn_func)libcmsockets_LTX_shutdown_conn; transport->read_to_buffer_func = (CMTransport_read_to_buffer_func)libcmsockets_LTX_read_to_buffer_func; transport->read_block_func = (CMTransport_read_block_func)NULL; diff --git a/cmudp.c b/cmudp.c index 35cb2d32f2..bcde47ad61 100644 --- a/cmudp.c +++ b/cmudp.c @@ -3,8 +3,8 @@ #include #ifdef HAVE_WINDOWS_H +#include #include -#include #define getpid() _getpid() #else #ifdef HAVE_SYS_TIME_H @@ -87,7 +87,7 @@ static atom_t CM_TRANSPORT_RELIABLE = -1; typedef struct udp_transport_data { CManager cm; CMtrans_services svc; - int socket_fd; + SOCKET socket_fd; int self_ip; int self_port; attr_list characteristics; @@ -109,17 +109,12 @@ typedef struct udp_connection_data { } *udp_conn_data_ptr; #ifdef WSAEWOULDBLOCK -#define EWOULDBLOCK WSAEWOULDBLOCK -#define EAGAIN WSAEINPROGRESS -#define EINTR WSAEINTR -#define errno GetLastError() #define read(fd, buf, len) recv(fd, buf, len, 0) #define write(fd, buf, len) send(fd, buf, len, 0) #endif static udp_conn_data_ptr -create_udp_conn_data(svc) -CMtrans_services svc; +create_udp_conn_data(CMtrans_services svc) { udp_conn_data_ptr udp_conn_data = svc->malloc_func(sizeof(struct udp_connection_data)); @@ -197,9 +192,7 @@ int fd; #endif extern void -libcmudp_LTX_shutdown_conn(svc, ucd) -CMtrans_services svc; -udp_conn_data_ptr ucd; +libcmudp_LTX_shutdown_conn(CMtrans_services svc, udp_conn_data_ptr ucd) { unlink_connection(ucd->utd, ucd); svc->connection_deref(ucd->conn); @@ -209,10 +202,16 @@ udp_conn_data_ptr ucd; #include "qual_hostname.c" +#ifdef _MSC_VER +static int inet_aton(const char* cp, struct in_addr* addr) +{ + addr->s_addr = inet_addr(cp); + return (addr->s_addr == INADDR_NONE) ? 0 : 1; +} +#endif + static int -check_host(hostname, sin_addr) -char *hostname; -void *sin_addr; +check_host(char *hostname, void *sin_addr) { struct hostent *host_addr; host_addr = gethostbyname(hostname); @@ -234,13 +233,7 @@ void *sin_addr; } static int -initiate_udp_conn(cm, svc, trans, attrs, udp_conn_data, conn_attr_list) -CManager cm; -CMtrans_services svc; -transport_entry trans; -attr_list attrs; -udp_conn_data_ptr udp_conn_data; -attr_list conn_attr_list; +initiate_udp_conn(CManager cm, CMtrans_services svc, transport_entry trans, attr_list attrs, udp_conn_data_ptr udp_conn_data, attr_list conn_attr_list) { int int_port_num; udp_transport_data_ptr utd = (udp_transport_data_ptr) trans->trans_data; @@ -251,14 +244,14 @@ attr_list conn_attr_list; memset(&dest_addr, 0, sizeof(dest_addr)); if (!query_attr(attrs, CM_IP_HOSTNAME, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & host_name)) { + /* value pointer */ (attr_value *)(intptr_t) & host_name)) { svc->trace_out(cm, "UDP transport found no UDP_HOST attribute"); host_name = NULL; } else { svc->trace_out(cm, "UDP transport connect to host %s", host_name); } if (!query_attr(attrs, CM_UDP_ADDR, /* type pointer */ NULL, - /* value pointer */ (attr_value *) (long) &udp_ip)) { + /* value pointer */ (attr_value *) (intptr_t) &udp_ip)) { svc->trace_out(cm, "CMUDP transport found no UDP_ADDR attribute"); /* wasn't there */ udp_ip = 0; @@ -269,7 +262,7 @@ attr_list conn_attr_list; return -1; if (!query_attr(attrs, CM_UDP_PORT, /* type pointer */ NULL, - /* value pointer */ (attr_value *) (long) &int_port_num)) { + /* value pointer */ (attr_value *) (intptr_t) &int_port_num)) { svc->trace_out(cm, "CMUDP transport found no UDP_PORT attribute"); return -1; } else { @@ -278,7 +271,7 @@ attr_list conn_attr_list; if (((network_string = getenv("CM_NETWORK")) != NULL) && (host_name != NULL)) { - int name_len = strlen(host_name) + 2 + strlen(network_string); + size_t name_len = strlen(host_name) + 2 + strlen(network_string); char *new_host_name = svc->malloc_func(name_len); char *first_dot = strchr(host_name, '.'); memset(new_host_name, 0, name_len); @@ -334,7 +327,7 @@ static void libcmudp_data_available(void *vtrans, void *vinput) { transport_entry trans = vtrans; - int input_fd = (long)vinput; + SOCKET input_fd = (SOCKET) (intptr_t) vinput; ssize_t nbytes; udp_transport_data_ptr utd = (udp_transport_data_ptr) trans->trans_data; udp_conn_data_ptr ucd = utd->connections; @@ -343,7 +336,7 @@ libcmudp_data_available(void *vtrans, void *vinput) char *msgbuf; int unused; - if (recvfrom(input_fd, &unused, 4, MSG_PEEK, + if (recvfrom(input_fd, (char*) & unused, 4, MSG_PEEK, (struct sockaddr *) &addr, &addrlen) != 4) { return; } @@ -398,11 +391,7 @@ libcmudp_data_available(void *vtrans, void *vinput) * Initiate a connection to a udp group. */ extern CMConnection -libcmudp_LTX_initiate_conn(cm, svc, trans, attrs) -CManager cm; -CMtrans_services svc; -transport_entry trans; -attr_list attrs; +libcmudp_LTX_initiate_conn(CManager cm, CMtrans_services svc, transport_entry trans, attr_list attrs) { udp_conn_data_ptr udp_conn_data = create_udp_conn_data(svc); attr_list conn_attr_list = create_attr_list(); @@ -431,11 +420,7 @@ attr_list attrs; * indicated by the attribute list, would we be connecting to ourselves? */ extern int -libcmudp_LTX_self_check(cm, svc, trans, attrs) -CManager cm; -CMtrans_services svc; -transport_entry trans; -attr_list attrs; +libcmudp_LTX_self_check(CManager cm, CMtrans_services svc, transport_entry trans, attr_list attrs) { udp_transport_data_ptr utd = trans->trans_data; int host_addr; @@ -448,18 +433,18 @@ attr_list attrs; IP = get_self_ip_addr(cm, svc); } if (!query_attr(attrs, CM_IP_HOSTNAME, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & host_name)) { + /* value pointer */ (attr_value *)(intptr_t) & host_name)) { svc->trace_out(cm, "CMself check UDP transport found no IP_HOST attribute"); host_name = NULL; } if (!query_attr(attrs, CM_UDP_ADDR, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & host_addr)) { + /* value pointer */ (attr_value *)(intptr_t) & host_addr)) { svc->trace_out(cm, "CMself check UDP transport found no UDP_ADDR attribute"); if (host_name == NULL) return 0; host_addr = 0; } if (!query_attr(attrs, CM_UDP_PORT, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & int_port_num)) { + /* value pointer */ (attr_value *)(intptr_t) & int_port_num)) { svc->trace_out(cm, "CMself check UDP transport found no UDP_PORT attribute"); return 0; } @@ -482,12 +467,7 @@ attr_list attrs; } extern int -libcmudp_LTX_connection_eq(cm, svc, trans, attrs, ucd) -CManager cm; -CMtrans_services svc; -transport_entry trans; -attr_list attrs; -udp_conn_data_ptr ucd; +libcmudp_LTX_connection_eq(CManager cm, CMtrans_services svc, transport_entry trans, attr_list attrs, udp_conn_data_ptr ucd) { int int_port_num; @@ -495,19 +475,19 @@ udp_conn_data_ptr ucd; char *host_name = NULL; if (!query_attr(attrs, CM_IP_HOSTNAME, /* type pointer */ NULL, - /* value pointer */ (attr_value *)(long) & host_name)) { + /* value pointer */ (attr_value *)(intptr_t) & host_name)) { svc->trace_out(cm, "UDP transport found no UDP_HOST attribute"); host_name = NULL; } else { svc->trace_out(cm, "UDP transport connect to host %s", host_name); } if (!query_attr(attrs, CM_UDP_PORT, /* type pointer */ NULL, - /* value pointer */ (attr_value *) (long) &int_port_num)) { + /* value pointer */ (attr_value *) (intptr_t) &int_port_num)) { svc->trace_out(cm, "Conn Eq CMUdp transport found no UDP_PORT attribute"); return 0; } if (!query_attr(attrs, CM_UDP_ADDR, /* type pointer */ NULL, - /* value pointer */ (attr_value *) (long) &requested_IP)) { + /* value pointer */ (attr_value *) (intptr_t) &requested_IP)) { svc->trace_out(cm, "CMUdp transport found no UDP_ADDR attribute"); } svc->trace_out(cm, "CMUdp Conn_eq comparing IP/ports %x/%d and %x/%d", @@ -531,11 +511,7 @@ udp_conn_data_ptr ucd; extern attr_list -libcmudp_LTX_non_blocking_listen(cm, svc, trans, listen_info) -CManager cm; -CMtrans_services svc; -transport_entry trans; -attr_list listen_info; +libcmudp_LTX_non_blocking_listen(CManager cm, CMtrans_services svc, transport_entry trans, attr_list listen_info) { udp_transport_data_ptr utd = trans->trans_data; int int_port_num = 0; @@ -543,13 +519,13 @@ attr_list listen_info; attr_list listen_list; unsigned int nl; int one = 1; - int socket_fd; + SOCKET socket_fd; struct sockaddr_in addr; int IP = get_self_ip_addr(cm, svc); if (listen_info != NULL && (!query_attr(listen_info, CM_UDP_PORT, /* type pointer */ NULL, - (attr_value *) (long) &int_port_num))) { + (attr_value *) (intptr_t) &int_port_num))) { svc->trace_out(cm, "CMUDP transport found no UDP_PORT attribute"); int_port_num = 0; } else { @@ -599,7 +575,7 @@ attr_list listen_info; (attr_value) strdup("udp")); svc->trace_out(cm, "CMudp Adding libcmudp_data_available as action on fd %d", socket_fd); svc->fd_add_select(cm, socket_fd, libcmudp_data_available, - (void *) trans, (void *) (long)socket_fd); + (void *) trans, (void *) (intptr_t)socket_fd); utd->socket_fd = socket_fd; utd->self_ip = IP; utd->self_port = ntohs(addr.sin_port); @@ -624,11 +600,7 @@ struct iovec { * that are more efficient if they allocate their own buffer space. */ extern void * -libcmudp_LTX_read_block_func(svc, ucd, actual_len, offset_ptr) -CMtrans_services svc; -udp_conn_data_ptr ucd; -size_t *actual_len; -size_t *offset_ptr; +libcmudp_LTX_read_block_func(CMtrans_services svc, udp_conn_data_ptr ucd, size_t *actual_len, size_t *offset_ptr) { *actual_len = ucd->read_buf_len; *offset_ptr = 0; @@ -642,16 +614,9 @@ size_t *offset_ptr; #endif extern int -libcmudp_LTX_writev_func(svc, ucd, iov, iovcnt, attrs) -CMtrans_services svc; -udp_conn_data_ptr ucd; -struct iovec *iov; -size_t iovcnt; -attr_list attrs; +libcmudp_LTX_writev_func(CMtrans_services svc, udp_conn_data_ptr ucd, struct iovec *iov, size_t iovcnt, attr_list attrs) { - int fd = ucd->utd->socket_fd; - struct sockaddr_in addr = ucd->dest_addr; - struct msghdr msg; + SOCKET fd = ucd->utd->socket_fd; if (ucd->utd->socket_fd == -1) { if ((ucd->utd->socket_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("socket"); @@ -661,6 +626,9 @@ attr_list attrs; fd = ucd->utd->socket_fd; svc->trace_out(ucd->utd->cm, "CMUdp writev of %d vectors on fd %d", iovcnt, fd); +#ifndef _MSC_VER + struct sockaddr_in addr = ucd->dest_addr; + struct msghdr msg; memset(&msg, 0, sizeof(msg)); msg.msg_name = (void*)&addr; msg.msg_namelen = sizeof(addr); @@ -670,7 +638,10 @@ attr_list attrs; perror("write sendmsg"); exit(1); } - return iovcnt; +#else + // no reimplementation for windows currently +#endif + return (int)iovcnt; } #ifdef HAVE_WINDOWS_H @@ -690,9 +661,7 @@ free_udp_data(CManager cm, void *utdv) } extern void * -libcmudp_LTX_initialize(cm, svc) -CManager cm; -CMtrans_services svc; +libcmudp_LTX_initialize(CManager cm, CMtrans_services svc) { static int atom_init = 0; @@ -748,9 +717,9 @@ cmudp_add_static_transport(CManager cm, CMtrans_services svc) transport->cm = cm; transport->transport_init = (CMTransport_func)libcmudp_LTX_initialize; transport->listen = (CMTransport_listen_func)libcmudp_LTX_non_blocking_listen; - transport->initiate_conn = (CMConnection(*)())libcmudp_LTX_initiate_conn; - transport->self_check = (int(*)())libcmudp_LTX_self_check; - transport->connection_eq = (int(*)())libcmudp_LTX_connection_eq; + transport->initiate_conn = (CMTransport_conn_func)libcmudp_LTX_initiate_conn; + transport->self_check = (CMTransport_self_check_func)libcmudp_LTX_self_check; + transport->connection_eq = (CMTransport_connection_eq_func)libcmudp_LTX_connection_eq; transport->shutdown_conn = (CMTransport_shutdown_conn_func)libcmudp_LTX_shutdown_conn; transport->read_to_buffer_func = (CMTransport_read_to_buffer_func)NULL; transport->read_block_func = (CMTransport_read_block_func)libcmudp_LTX_read_block_func;; diff --git a/config.h.cmake b/config.h.cmake index 2a747f5964..13943a10a8 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -135,8 +135,8 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_WINDOWS_H -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_WINSOCK_H +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_WINSOCK2_H /* The size of `int', as computed by sizeof. */ #define SIZEOF_INT @SIZEOF_INT@ diff --git a/dfg_tests/anon_multi_test.c b/dfg_tests/anon_multi_test.c index 8b37368885..16a3a35eb8 100644 --- a/dfg_tests/anon_multi_test.c +++ b/dfg_tests/anon_multi_test.c @@ -15,6 +15,14 @@ #include "config.h" #include "ev_dfg.h" #include "test_support.h" +#ifdef HAVE_WINDOWS_H +#include +#define drand48() (((double)rand())/((double)RAND_MAX)) +#define lrand48() rand() +#define srand48(x) +#else +#include +#endif static int status; static EVclient test_client; @@ -379,6 +387,7 @@ submit any remaining anon from bottom (oldest) } } } + extern int be_test_master(int argc, char **argv) { diff --git a/dfg_tests/auto_tree_test.c b/dfg_tests/auto_tree_test.c index e7bd5df7d6..d4b1d781b6 100644 --- a/dfg_tests/auto_tree_test.c +++ b/dfg_tests/auto_tree_test.c @@ -1,10 +1,12 @@ #include #include #include +#include "config.h" +#ifdef HAVE_UNISTD_H #include +#endif #include -#include "config.h" #include "cod.h" #include "ev_dfg.h" #include "test_support.h" @@ -33,7 +35,7 @@ int generate_record() { return getpid(); } static cod_extern_entry externs[] = { - {"generate_record", (void *) (long) generate_record}, + {"generate_record", (void *) (intptr_t) generate_record}, {NULL, NULL} }; static char extern_string[] = "int generate_record();\0\0"; @@ -43,6 +45,14 @@ char *COD_generate = "{\n\ return 1;\n\ }"; +static void +fail_and_die(int signal) +{ + (void)signal; + fprintf(stderr, "auto_tree_test failed to complete in reasonable time\n"); + exit(1); +} + extern int be_test_master(int argc, char **argv) { @@ -58,7 +68,11 @@ be_test_master(int argc, char **argv) EVdfg test_dfg; EVclient_sinks sink_capabilities; +#ifdef HAVE_WINDOWS_H + SetTimer(NULL, 5, 1000, (TIMERPROC) fail_and_die); +#else alarm(240); /* reset time limit to 4 minutes */ +#endif if (argc == 1) { sscanf(argv[0], "%d", &level_count); } diff --git a/dfg_tests/delayed_submit.c b/dfg_tests/delayed_submit.c index 7f0d5f9058..be9b50ddd5 100644 --- a/dfg_tests/delayed_submit.c +++ b/dfg_tests/delayed_submit.c @@ -5,9 +5,26 @@ #include #include #include +#include "config.h" +#ifdef HAVE_SYS_TIME_H #include +#endif +#ifdef _MSC_VER +#include +#include +#endif +#ifndef timersub +#define timersub(a, b, result) \ + do { \ + (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + if ((result)->tv_usec < 0) { \ + --(result)->tv_sec; \ + (result)->tv_usec += 1000000; \ + } \ + } while (0) +#endif // timersub -#include "config.h" #include "evpath.h" #include "ev_dfg.h" #include "test_support.h" @@ -45,7 +62,17 @@ event_handler(CManager cm, void *vevent, void *client_data, attr_list attrs) (void)cm; (void)client_data; if (quiet <= 0) printf("In handler for stone %d\n", EVexecuting_stone(cm)); - gettimeofday(&now, NULL); +#ifdef HAVE_GETTIMEOFDAY + gettimeofday((struct timeval*)&now, NULL); +#else + /* GSE... No gettimeofday on windows. + * Must use _ftime, get millisec time, convert to usec. Bleh. + */ + struct _timeb nowb; + _ftime(&nowb); + ((struct timeval*)&now)->tv_sec = (long)nowb.time; + ((struct timeval*)&now)->tv_usec = nowb.millitm * 1000; +#endif timersub(&now, &event->submit_time, &delay); if (quiet <= 0) { printf("Now is %ld.%06d, sent %ld.%06d\n", (long)now.tv_sec, (int)now.tv_usec, (long)event->submit_time.tv_sec, (int)event->submit_time.tv_usec); diff --git a/dfg_tests/fail_chain_test.c b/dfg_tests/fail_chain_test.c index a9ebbf8b2f..a3673e6db4 100755 --- a/dfg_tests/fail_chain_test.c +++ b/dfg_tests/fail_chain_test.c @@ -1,9 +1,11 @@ #include #include +#include "config.h" #include +#ifdef HAVE_UNISTD_H #include -#include "config.h" +#endif #include "evpath.h" #include "ev_dfg.h" #include "test_support.h" @@ -114,6 +116,14 @@ fail_handler(EVdfg dfg, char *failed_node_name, int failed_stone) EVdfg_realize(dfg); } +static void +fail_and_die(int signal) +{ + (void)signal; + fprintf(stderr, "auto_tree_test failed to complete in reasonable time\n"); + exit(1); +} + extern int be_test_master(int argc, char **argv) { @@ -127,7 +137,11 @@ be_test_master(int argc, char **argv) EVclient_sinks sink_capabilities; EVclient_sources source_capabilities; +#ifdef HAVE_WINDOWS_H + SetTimer(NULL, 5, 1000, (TIMERPROC) fail_and_die); +#else alarm(240); /* reset time limit to 4 minutes */ +#endif if (argc == 1) { sscanf(argv[0], "%d", &node_count); } @@ -242,7 +256,11 @@ be_test_child(int argc, char **argv) EVclient_sinks sink_capabilities; EVclient_sources source_capabilities; +#ifdef HAVE_WINDOWS_H + SetTimer(NULL, 5, 1000, (TIMERPROC) fail_and_die); +#else alarm(240); /* reset time limit to 4 minutes */ +#endif cm = CManager_create(); if (argc != 3) { printf("Child usage: evtest \n"); diff --git a/dfg_tests/metrics_test.c b/dfg_tests/metrics_test.c index 112542192e..46f0bdd4ff 100644 --- a/dfg_tests/metrics_test.c +++ b/dfg_tests/metrics_test.c @@ -1,10 +1,12 @@ #include #include #include +#include "config.h" +#ifdef HAVE_UNISTD_H #include +#endif #include -#include "config.h" #include "cod.h" #include "ev_dfg.h" #include "test_support.h" diff --git a/dfg_tests/multi_test.c b/dfg_tests/multi_test.c index bb8467a830..a7d094644d 100644 --- a/dfg_tests/multi_test.c +++ b/dfg_tests/multi_test.c @@ -70,7 +70,7 @@ void generate_a_record(rec_a_ptr event) { /* always even */ - event->a_field = ((int) lrand48() % 50) * 2; + event->a_field = ((int) rand() % 50) * 2; } static @@ -78,7 +78,7 @@ void generate_b_record(rec_b_ptr event) { /* always odd */ - event->b_field = ((int) lrand48() % 50) * 2 + 1; + event->b_field = ((int) rand() % 50) * 2 + 1; } static diff --git a/dfg_tests/router_test.c b/dfg_tests/router_test.c index dee11f0844..6a3efca232 100644 --- a/dfg_tests/router_test.c +++ b/dfg_tests/router_test.c @@ -8,6 +8,13 @@ #include "ev_dfg.h" #include "test_support.h" +#ifdef HAVE_WINDOWS_H +#include +#define drand48() (((double)rand())/((double)RAND_MAX)) +#define lrand48() rand() +#define srand48(x) +#endif + static int status; static EVclient test_client; diff --git a/dfg_tests/self_reconfig_test.c b/dfg_tests/self_reconfig_test.c index 253f7f9a3f..4970d8d050 100644 --- a/dfg_tests/self_reconfig_test.c +++ b/dfg_tests/self_reconfig_test.c @@ -1,9 +1,11 @@ #include #include +#include "config.h" #include +#ifdef HAVE_UNISTD_H #include -#include "config.h" +#endif #include "evpath.h" #include "ev_dfg.h" #include "test_support.h" @@ -142,6 +144,14 @@ reconfig_handler(EVdfg dfg) } +static void +fail_and_die(int signal) +{ + (void)signal; + fprintf(stderr, "auto_tree_test failed to complete in reasonable time\n"); + exit(1); +} + extern int be_test_master(int argc, char **argv) { @@ -155,7 +165,11 @@ be_test_master(int argc, char **argv) EVclient_sinks sink_capabilities; EVclient_sources source_capabilities; +#ifdef HAVE_WINDOWS_H + SetTimer(NULL, 5, 1000, (TIMERPROC) fail_and_die); +#else alarm(240); /* reset time limit to 4 minutes */ +#endif if (argc == 1) { sscanf(argv[0], "%d", &node_count); } @@ -279,7 +293,11 @@ be_test_child(int argc, char **argv) EVclient_sinks sink_capabilities; EVclient_sources source_capabilities; +#ifdef HAVE_WINDOWS_H + SetTimer(NULL, 5, 1000, (TIMERPROC) fail_and_die); +#else alarm(240); /* reset time limit to 4 minutes */ +#endif cm = CManager_create(); if (argc != 3) { printf("Child usage: evtest \n"); diff --git a/dfg_tests/test_support.c b/dfg_tests/test_support.c index 8d4bab0558..4c49643ad7 100644 --- a/dfg_tests/test_support.c +++ b/dfg_tests/test_support.c @@ -7,13 +7,17 @@ #include #include #include +#ifdef HAVE_ARPA_INET_H #include +#endif #include "ev_dfg.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) +#define waitpid(x, tmp, z) { WaitForSingleObject(OpenProcess(0,0,(DWORD)x), INFINITE); GetExitCodeProcess(OpenProcess(0,0,(DWORD)x), tmp);} #else #include #endif @@ -139,7 +143,7 @@ run_subprocess(char **args) { static int count = 0; #ifdef HAVE_WINDOWS_H - int child; + intptr_t child; child = _spawnv(_P_NOWAIT, "./evtest.exe", args); if (child == -1) { printf("failed for evtest\n"); @@ -284,10 +288,10 @@ main(int argc, char **argv) printf("Missing --ssh destination\n"); usage(); } - first_colon = index(argv[2], ':'); + first_colon = strchr(argv[2], ':'); if (first_colon) { *first_colon = 0; - second_colon = index(first_colon+1, ':'); + second_colon = strchr(first_colon+1, ':'); } else { second_colon = NULL; } @@ -328,7 +332,7 @@ main(int argc, char **argv) argc--; } if (remote_directory[0] != 0) { - if (rindex(argv0, '/')) argv0 = rindex(argv0, '/') + 1; + if (strrchr(argv0, '/')) argv0 = strrchr(argv0, '/') + 1; subproc_args[cur_subproc_arg] = malloc(strlen(remote_directory) + strlen(argv0) + 4); strcpy(subproc_args[cur_subproc_arg], remote_directory); diff --git a/dfg_tests/test_support.h b/dfg_tests/test_support.h index 98efc13a2e..e72b4b9a0f 100644 --- a/dfg_tests/test_support.h +++ b/dfg_tests/test_support.h @@ -1,4 +1,8 @@ #include "evpath.h" +#ifdef _MSC_VER +#define pid_t intptr_t +#include +#endif typedef struct _complex_rec { double r; diff --git a/dfg_tests/tree_test.c b/dfg_tests/tree_test.c index b55718b55e..d157647986 100644 --- a/dfg_tests/tree_test.c +++ b/dfg_tests/tree_test.c @@ -2,9 +2,11 @@ #include #include #include +#include "config.h" +#ifdef HAVE_UNISTD_H #include +#endif -#include "config.h" #include "ev_dfg.h" #include "test_support.h" @@ -25,6 +27,14 @@ simple_handler(CManager cm, void *vevent, void *client_data, attr_list attrs) } +static void +fail_and_die(int signal) +{ + (void)signal; + fprintf(stderr, "tree_test failed to complete in reasonable time\n"); + exit(1); +} + extern int be_test_master(int argc, char **argv) { @@ -43,7 +53,11 @@ be_test_master(int argc, char **argv) EVclient_sinks sink_capabilities; EVclient_sources source_capabilities; - alarm(240); /* reset time limit to 4 minutes */ +#ifdef HAVE_WINDOWS_H + SetTimer(NULL, 5, 1000, (TIMERPROC) fail_and_die); +#else + alarm(300); +#endif if (argc == 1) { sscanf(argv[0], "%d", &level_count); } diff --git a/dlloader.c b/dlloader.c index eedaf678bf..e4c5ad3791 100644 --- a/dlloader.c +++ b/dlloader.c @@ -1,11 +1,75 @@ #include "config.h" +#ifndef _MSC_VER #include +#endif #include #include #include #include "dlloader.h" static char **search_list = NULL; +#ifdef _MSC_VER +#include + +static struct { + long lasterror; + const char* err_rutin; +} var = { + 0, + NULL +}; + +void* dlopen(const char* filename, int flags) +{ + HINSTANCE hInst; + + hInst = LoadLibrary(filename); + if (hInst == NULL) { + var.lasterror = GetLastError(); + var.err_rutin = "dlopen"; + } + return hInst; +} + +int dlclose(void* handle) +{ + BOOL ok; + int rc = 0; + + ok = FreeLibrary((HINSTANCE)handle); + if (!ok) { + var.lasterror = GetLastError(); + var.err_rutin = "dlclose"; + rc = -1; + } + return rc; +} + +void* dlsym(void* handle, const char* name) +{ + FARPROC fp; + + fp = GetProcAddress((HINSTANCE)handle, name); + if (!fp) { + var.lasterror = GetLastError(); + var.err_rutin = "dlsym"; + } + return (void*)(intptr_t)fp; +} + +const char* dlerror(void) +{ + static char errstr[88]; + + if (var.lasterror) { + sprintf(errstr, "%s error #%ld", var.err_rutin, var.lasterror); + return errstr; + } + else { + return NULL; + } +} +#endif void CMdladdsearchdir(char *string) @@ -33,6 +97,7 @@ CMset_dlopen_verbose(int verbose) { dlopen_verbose = verbose; } +#undef dlopen void * CMdlopen(void *CMTrace_filev, char *in_lib, int mode) @@ -48,13 +113,13 @@ CMdlopen(void *CMTrace_filev, char *in_lib, int mode) if (dlopen_verbose == -1) { dlopen_verbose = (getenv("CMTransportVerbose") != NULL); } - tmp = rindex(in_lib, '.'); + tmp = strrchr(in_lib, '.'); if (dlopen_verbose) fprintf(CMTrace_file, "Trying to dlopen %s\n", in_lib); if (tmp && (strcmp(tmp, ".la") == 0)) { /* can't open .la files */ lib = malloc(strlen(in_lib) + strlen(MODULE_EXT) + 8); strcpy(lib, in_lib); - strcpy(rindex(lib, '.'), MODULE_EXT); + strcpy(strrchr(lib, '.'), MODULE_EXT); if (dlopen_verbose) fprintf(CMTrace_file, "Dlopen module name replaced, now %s\n", lib); } else { lib = strdup(in_lib); @@ -64,7 +129,7 @@ CMdlopen(void *CMTrace_filev, char *in_lib, int mode) char *tmp = malloc(strlen(list[0]) + strlen(lib) + 2); sprintf(tmp, "%s/%s", list[0], lib); handle = dlopen(tmp, RTLD_LAZY); - char *err = dlerror(); + const char *err = dlerror(); if (dlopen_verbose) { if (err) { fprintf(CMTrace_file, "Failed to dlopen %s, error is %s\n", tmp, err); @@ -78,7 +143,7 @@ CMdlopen(void *CMTrace_filev, char *in_lib, int mode) } if (!handle) { handle = dlopen(lib, RTLD_LAZY); - char *err = dlerror(); + const char *err = dlerror(); if (dlopen_verbose) { if (err) { fprintf(CMTrace_file, "Failed to dlopen %s, error is %s\n", tmp, err); @@ -89,7 +154,7 @@ CMdlopen(void *CMTrace_filev, char *in_lib, int mode) } if (!handle) return NULL; dlh = malloc(sizeof(*dlh)); - tmp = rindex(lib, '/'); /* find name start */ + tmp = strrchr(lib, '/'); /* find name start */ if (!tmp) tmp = lib; char *cm_lib_prefix; @@ -104,7 +169,7 @@ CMdlopen(void *CMTrace_filev, char *in_lib, int mode) dlh->lib_prefix = malloc(strlen(tmp) + 4); strcpy(dlh->lib_prefix, tmp); } - tmp = rindex(dlh->lib_prefix, '.'); + tmp = strrchr(dlh->lib_prefix, '.'); strcpy(tmp, "_LTX_"); /* kill postfix, add _LTX_ */ dlh->dlopen_handle = handle; free(lib); diff --git a/dlloader.h b/dlloader.h index 828be60f92..e0e063097b 100644 --- a/dlloader.h +++ b/dlloader.h @@ -1,4 +1,13 @@ + +#ifndef _MSC_VER #include +#else +#define RTLD_GLOBAL 0x100 /* do not hide entries in this module */ +#define RTLD_LOCAL 0x000 /* hide entries in this module */ + +#define RTLD_LAZY 0x000 /* accept unresolved externs */ +#define RTLD_NOW 0x001 /* abort if module has unresolved externs */ +#endif #define lt_dlopen(x) CMdlopen(cm, x, 0) #define lt_dladdsearchdir(x) CMdladdsearchdir(x) #define lt_dlsym(x, y) CMdlsym(x, y) diff --git a/ev_dfg.c b/ev_dfg.c index b37ca4fbb4..3493e0a431 100644 --- a/ev_dfg.c +++ b/ev_dfg.c @@ -4,8 +4,10 @@ #include #include #include +#ifdef HAVE_UNISTD_H #include -#include +#endif +#include #ifdef HAVE_COD_H #include "cod.h" @@ -79,15 +81,135 @@ static void free_master_msg(EVmaster_msg *msg); static void free_dfg_state(EVdfg_configuration state); static void free_attrs_msg(EVflush_attrs_reconfig_ptr msg); -static FMStructDescRec EVdfg_conn_shutdown_format_list[]; -static FMStructDescRec EVdfg_deploy_ack_format_list[]; -static FMStructDescRec EVdfg_flush_attrs_reconfig_format_list[]; -static FMStructDescRec EVdfg_node_join_format_list[]; -static FMStructDescRec EVdfg_ready_format_list[]; -static FMStructDescRec EVdfg_deploy_format_list[]; -static FMStructDescRec EVdfg_deploy_ack_format_list[]; -static FMStructDescRec EVclient_shutdown_format_list[]; -static FMStructDescRec EVclient_shutdown_contribution_format_list[]; + +static FMField EVleaf_element_flds[] = { + {"name", "string", sizeof(char*), FMOffset(leaf_element*, name)}, + {"FMtype", "string", sizeof(char*), FMOffset(leaf_element*, FMtype)}, + {NULL, NULL, 0, 0} +}; + +static FMField EVnode_join_msg_flds[] = { + {"node_name", "string", sizeof(char*), FMOffset(EVnode_join_ptr, node_name)}, + {"contact_string", "string", sizeof(char*), FMOffset(EVnode_join_ptr, contact_string)}, + {"source_count", "integer", sizeof(int), FMOffset(EVnode_join_ptr, source_count)}, + {"sink_count", "integer", sizeof(int), FMOffset(EVnode_join_ptr, sink_count)}, + {"sources", "source_element[source_count]", sizeof(leaf_element), FMOffset(EVnode_join_ptr, sources)}, + {"sinks", "sink_element[sink_count]", sizeof(leaf_element), FMOffset(EVnode_join_ptr, sinks)}, + {NULL, NULL, 0, 0} +}; + +static FMStructDescRec EVdfg_node_join_format_list[] = { + {"EVdfg_node_join", EVnode_join_msg_flds, sizeof(EVnode_join_msg), NULL}, + {"sink_element", EVleaf_element_flds, sizeof(leaf_element), NULL}, + {"source_element", EVleaf_element_flds, sizeof(leaf_element), NULL}, + {NULL, NULL, 0, NULL} +}; + +static FMField EVready_msg_flds[] = { + {"node_id", "integer", sizeof(int), FMOffset(EVready_ptr, node_id)}, + {NULL, NULL, 0, 0} +}; + +static FMStructDescRec EVdfg_ready_format_list[] = { + {"EVdfg_ready", EVready_msg_flds, sizeof(EVready_msg), NULL}, + {NULL, NULL, 0, NULL} +}; + +static FMField EVdeploy_ack_msg_flds[] = { + {"node_id", "string", sizeof(char*), FMOffset(EVdeploy_ack_ptr, node_id)}, + {NULL, NULL, 0, 0} +}; + +static FMStructDescRec EVdfg_deploy_ack_format_list[] = { + {"EVdfg_deploy_ack", EVdeploy_ack_msg_flds, sizeof(EVdeploy_ack_msg), NULL}, + {NULL, NULL, 0, NULL} +}; + +static FMField EVshutdown_msg_flds[] = { + {"value", "integer", sizeof(int), FMOffset(EVshutdown_ptr, value)}, + {NULL, NULL, 0, 0} +}; + +static FMStructDescRec EVclient_shutdown_format_list[] = { + {"EVclient_shutdown", EVshutdown_msg_flds, sizeof(EVshutdown_msg), NULL}, + {NULL, NULL, 0, NULL} +}; + +static FMField EVshutdown_contribution_msg_flds[] = { + {"value", "integer", sizeof(int), FMOffset(EVshutdown_contribution_ptr, value)}, + {NULL, NULL, 0, 0} +}; + +static FMStructDescRec EVclient_shutdown_contribution_format_list[] = { + {"EVclient_shutdown_contribution", EVshutdown_contribution_msg_flds, sizeof(EVshutdown_contribution_msg), NULL}, + {NULL, NULL, 0, NULL} +}; + +static FMField EVconn_shutdown_msg_flds[] = { + {"stone", "integer", sizeof(int), FMOffset(EVconn_shutdown_ptr, stone)}, + {NULL, NULL, 0, 0} +}; + +static FMStructDescRec EVdfg_conn_shutdown_format_list[] = { + {"EVdfg_conn_shutdown", EVconn_shutdown_msg_flds, sizeof(EVconn_shutdown_msg), NULL}, + {NULL, NULL, 0, NULL} +}; + +static FMField EVattr_stone_flds[] = { + {"stone", "integer", sizeof(long), FMOffset(EVattr_stone_ptr, stone)}, + {"attr_str", "string", sizeof(char*), FMOffset(EVattr_stone_ptr, attr_str)}, + {NULL, NULL, 0, 0} +}; + +static FMField EVflush_attrs_reconfig_msg_flds[] = { + {"reconfig", "integer", sizeof(int), FMOffset(EVflush_attrs_reconfig_ptr, reconfig)}, + {"count", "integer", sizeof(long), FMOffset(EVflush_attrs_reconfig_ptr, count)}, + {"attr_stone_list", "attr_stone_element[count]", sizeof(EVattr_stone_struct), FMOffset(EVflush_attrs_reconfig_ptr, attr_stone_list)}, + {NULL, NULL, 0, 0} +}; + +static FMStructDescRec EVdfg_flush_attrs_reconfig_format_list[] = { + {"EVflush_attrs_reconfig", EVflush_attrs_reconfig_msg_flds, sizeof(EVflush_attrs_reconfig_msg), NULL}, + {"attr_stone_element", EVattr_stone_flds, sizeof(EVattr_stone_struct), NULL}, + {NULL, NULL, 0, NULL} +}; + +static FMField EVdfg_stone_flds[] = { + {"global_stone_id", "integer", sizeof(int), + FMOffset(deploy_msg_stone, global_stone_id)}, + {"attrs", "string", sizeof(char*), + FMOffset(deploy_msg_stone, attrs)}, + {"period_secs", "integer", sizeof(int), + FMOffset(deploy_msg_stone, period_secs)}, + {"period_usecs", "integer", sizeof(int), + FMOffset(deploy_msg_stone, period_usecs)}, + {"out_count", "integer", sizeof(int), + FMOffset(deploy_msg_stone, out_count)}, + {"out_links", "integer[out_count]", sizeof(int), + FMOffset(deploy_msg_stone, out_links)}, + {"action", "string", sizeof(char*), + FMOffset(deploy_msg_stone, action)}, + {"extra_actions", "integer", sizeof(int), + FMOffset(deploy_msg_stone, extra_actions)}, + {"xactions", "string[extra_actions]", sizeof(char*), + FMOffset(deploy_msg_stone, xactions)}, + {NULL, NULL, 0, 0} +}; + +static FMField EVdfg_deploy_msg_flds[] = { + {"canonical_name", "string", sizeof(char*), + FMOffset(EVdfg_deploy_ptr, canonical_name)}, + {"stone_count", "integer", sizeof(int), + FMOffset(EVdfg_deploy_ptr, stone_count)}, + {"stone_list", "EVdfg_deploy_stone[stone_count]", sizeof(struct _EVdfg_msg_stone), FMOffset(EVdfg_deploy_ptr, stone_list)}, + {NULL, NULL, 0, 0} +}; + +static FMStructDescRec EVdfg_deploy_format_list[] = { + {"EVdfg_deploy", EVdfg_deploy_msg_flds, sizeof(EVdfg_deploy_msg), NULL}, + {"EVdfg_deploy_stone", EVdfg_stone_flds, sizeof(struct _EVdfg_msg_stone), NULL}, + {NULL, NULL, 0, NULL} +}; /* msg action model @@ -176,9 +298,10 @@ EVdfg_stone INT_EVdfg_create_source_stone(EVdfg dfg, char *source_name) { EVdfg_stone tmp; - int len = strlen(source_name) + strlen("source:"); + size_t len = strlen(source_name) + strlen("source:"); char *act = malloc(len + 1); - strcpy(stpcpy(&act[0], "source:"), source_name); + strcpy(&act[0], "source:"); + strcat(&act[0], source_name); tmp = INT_EVdfg_create_stone(dfg, &act[0]); free(act); return tmp; @@ -187,9 +310,10 @@ INT_EVdfg_create_source_stone(EVdfg dfg, char *source_name) extern void INT_EVdfg_add_sink_action(EVdfg_stone stone, char *sink_name) { - int len = strlen(sink_name) + strlen("sink:"); + size_t len = strlen(sink_name) + strlen("sink:"); char *act = malloc(len + 1); - strcpy(stpcpy(&act[0], "sink:"), sink_name); + strcpy(&act[0], "sink:"); + strcat(&act[0], sink_name); INT_EVdfg_add_action(stone, &act[0]); free(act); } @@ -198,9 +322,10 @@ EVdfg_stone INT_EVdfg_create_sink_stone(EVdfg dfg, char *sink_name) { EVdfg_stone tmp; - int len = strlen(sink_name) + strlen("sink:"); + size_t len = strlen(sink_name) + strlen("sink:"); char *act = malloc(len + 1); - strcpy(stpcpy(&act[0], "sink:"), sink_name); + strcpy(&act[0], "sink:"); + strcat(&act[0], sink_name); tmp = INT_EVdfg_create_stone(dfg, &act[0]); free(act); return tmp; @@ -1457,7 +1582,7 @@ INT_EVdfg_create(EVmaster master) extern char *INT_EVmaster_get_contact_list(EVmaster master) { - attr_list listen_list, contact_list = NULL; + attr_list contact_list = NULL; atom_t CM_TRANSPORT = attr_atom_from_string("CM_TRANSPORT"); atom_t CM_ENET_CONN_TIMEOUT = attr_atom_from_string("CM_ENET_CONN_TIMEOUT"); CManager cm = master->cm; @@ -1465,7 +1590,7 @@ extern char *INT_EVmaster_get_contact_list(EVmaster master) /* use enet transport if available */ #if defined(ENET_FOUND) || defined(ZPL_ENET_AVAILABLE) - listen_list = create_attr_list(); + attr_list listen_list = create_attr_list(); #if defined(ENET_FOUND) add_string_attr(listen_list, CM_TRANSPORT, strdup("enet")); #elif defined(ZPL_ENET_AVAILABLE) @@ -1636,6 +1761,7 @@ INT_EVclient_ready_wait(EVclient client) client->ready_condition = -1; CMtrace_out(client->cm, EVdfgVerbose, "DFG %p ready wait released\n", client); return 1; + } extern int @@ -1835,8 +1961,8 @@ dfg_assoc_client(CManager cm, char* node_name, char *master_contact, EVmaster ma fprintf(stderr, "Only one call to EVclient_assoc() or EVclient_assoc_local() per CManager allowed.\n"); return NULL; } - dfg_extern_map[0].extern_value = (void*)(long)cod_EVdfg_trigger_reconfig; - dfg_extern_map[1].extern_value = (void*)(long)cod_EVdfg_flush_attrs; + dfg_extern_map[0].extern_value = (void*)(intptr_t)cod_EVdfg_trigger_reconfig; + dfg_extern_map[1].extern_value = (void*)(intptr_t)cod_EVdfg_flush_attrs; INT_EVadd_standard_routines(cm, dfg_extern_string, dfg_extern_map); @@ -2769,132 +2895,3 @@ check_all_nodes_registered(EVmaster master) dfg->deployed_stone_count = dfg->stone_count; master->old_node_count = master->node_count; } - -static FMField EVleaf_element_flds[] = { - {"name", "string", sizeof(char*), FMOffset(leaf_element*, name)}, - {"FMtype", "string", sizeof(char*), FMOffset(leaf_element*, FMtype)}, - {NULL, NULL, 0, 0} -}; - -static FMField EVnode_join_msg_flds[] = { - {"node_name", "string", sizeof(char*), FMOffset(EVnode_join_ptr, node_name)}, - {"contact_string", "string", sizeof(char*), FMOffset(EVnode_join_ptr, contact_string)}, - {"source_count", "integer", sizeof(int), FMOffset(EVnode_join_ptr, source_count)}, - {"sink_count", "integer", sizeof(int), FMOffset(EVnode_join_ptr, sink_count)}, - {"sources", "source_element[source_count]", sizeof(leaf_element), FMOffset(EVnode_join_ptr, sources)}, - {"sinks", "sink_element[sink_count]", sizeof(leaf_element), FMOffset(EVnode_join_ptr, sinks)}, - {NULL, NULL, 0, 0} -}; - -static FMStructDescRec EVdfg_node_join_format_list[] = { - {"EVdfg_node_join", EVnode_join_msg_flds, sizeof(EVnode_join_msg), NULL}, - {"sink_element", EVleaf_element_flds, sizeof(leaf_element), NULL}, - {"source_element", EVleaf_element_flds, sizeof(leaf_element), NULL}, - {NULL, NULL, 0, NULL} -}; - -static FMField EVready_msg_flds[] = { - {"node_id", "integer", sizeof(int), FMOffset(EVready_ptr, node_id)}, - {NULL, NULL, 0, 0} -}; - -static FMStructDescRec EVdfg_ready_format_list[] = { - {"EVdfg_ready", EVready_msg_flds, sizeof(EVready_msg), NULL}, - {NULL, NULL, 0, NULL} -}; - -static FMField EVdeploy_ack_msg_flds[] = { - {"node_id", "string", sizeof(char*), FMOffset(EVdeploy_ack_ptr, node_id)}, - {NULL, NULL, 0, 0} -}; - -static FMStructDescRec EVdfg_deploy_ack_format_list[] = { - {"EVdfg_deploy_ack", EVdeploy_ack_msg_flds, sizeof(EVdeploy_ack_msg), NULL}, - {NULL, NULL, 0, NULL} -}; - -static FMField EVshutdown_msg_flds[] = { - {"value", "integer", sizeof(int), FMOffset(EVshutdown_ptr, value)}, - {NULL, NULL, 0, 0} -}; - -static FMStructDescRec EVclient_shutdown_format_list[] = { - {"EVclient_shutdown", EVshutdown_msg_flds, sizeof(EVshutdown_msg), NULL}, - {NULL, NULL, 0, NULL} -}; - -static FMField EVshutdown_contribution_msg_flds[] = { - {"value", "integer", sizeof(int), FMOffset(EVshutdown_contribution_ptr, value)}, - {NULL, NULL, 0, 0} -}; - -static FMStructDescRec EVclient_shutdown_contribution_format_list[] = { - {"EVclient_shutdown_contribution", EVshutdown_contribution_msg_flds, sizeof(EVshutdown_contribution_msg), NULL}, - {NULL, NULL, 0, NULL} -}; - -static FMField EVconn_shutdown_msg_flds[] = { - {"stone", "integer", sizeof(int), FMOffset(EVconn_shutdown_ptr, stone)}, - {NULL, NULL, 0, 0} -}; - -static FMStructDescRec EVdfg_conn_shutdown_format_list[] = { - {"EVdfg_conn_shutdown", EVconn_shutdown_msg_flds, sizeof(EVconn_shutdown_msg), NULL}, - {NULL, NULL, 0, NULL} -}; - -static FMField EVattr_stone_flds[] = { - {"stone", "integer", sizeof(long), FMOffset(EVattr_stone_ptr, stone)}, - {"attr_str", "string", sizeof(char*), FMOffset(EVattr_stone_ptr, attr_str)}, - {NULL, NULL, 0, 0} -}; - -static FMField EVflush_attrs_reconfig_msg_flds[] = { - {"reconfig", "integer", sizeof(int), FMOffset(EVflush_attrs_reconfig_ptr, reconfig)}, - {"count", "integer", sizeof(long), FMOffset(EVflush_attrs_reconfig_ptr, count)}, - {"attr_stone_list", "attr_stone_element[count]", sizeof(EVattr_stone_struct), FMOffset(EVflush_attrs_reconfig_ptr, attr_stone_list)}, - {NULL, NULL, 0, 0} -}; - -static FMStructDescRec EVdfg_flush_attrs_reconfig_format_list[] = { - {"EVflush_attrs_reconfig", EVflush_attrs_reconfig_msg_flds, sizeof(EVflush_attrs_reconfig_msg), NULL}, - {"attr_stone_element", EVattr_stone_flds, sizeof(EVattr_stone_struct), NULL}, - {NULL, NULL, 0, NULL} -}; - -static FMField EVdfg_stone_flds[] = { - {"global_stone_id", "integer", sizeof(int), - FMOffset(deploy_msg_stone, global_stone_id)}, - {"attrs", "string", sizeof(char*), - FMOffset(deploy_msg_stone, attrs)}, - {"period_secs", "integer", sizeof(int), - FMOffset(deploy_msg_stone, period_secs)}, - {"period_usecs", "integer", sizeof(int), - FMOffset(deploy_msg_stone, period_usecs)}, - {"out_count", "integer", sizeof(int), - FMOffset(deploy_msg_stone, out_count)}, - {"out_links", "integer[out_count]", sizeof(int), - FMOffset(deploy_msg_stone, out_links)}, - {"action", "string", sizeof(char*), - FMOffset(deploy_msg_stone, action)}, - {"extra_actions", "integer", sizeof(int), - FMOffset(deploy_msg_stone, extra_actions)}, - {"xactions", "string[extra_actions]", sizeof(char*), - FMOffset(deploy_msg_stone, xactions)}, - {NULL, NULL, 0, 0} -}; - -static FMField EVdfg_deploy_msg_flds[] = { - {"canonical_name", "string", sizeof(char*), - FMOffset(EVdfg_deploy_ptr, canonical_name)}, - {"stone_count", "integer", sizeof(int), - FMOffset(EVdfg_deploy_ptr, stone_count)}, - {"stone_list", "EVdfg_deploy_stone[stone_count]", sizeof(struct _EVdfg_msg_stone), FMOffset(EVdfg_deploy_ptr, stone_list)}, - {NULL, NULL, 0, 0} -}; - -static FMStructDescRec EVdfg_deploy_format_list[] = { - {"EVdfg_deploy", EVdfg_deploy_msg_flds, sizeof(EVdfg_deploy_msg), NULL}, - {"EVdfg_deploy_stone", EVdfg_stone_flds, sizeof(struct _EVdfg_msg_stone), NULL}, - {NULL, NULL, 0, NULL} -}; diff --git a/ev_internal.h b/ev_internal.h index c2218e4a01..f787a372b9 100644 --- a/ev_internal.h +++ b/ev_internal.h @@ -8,7 +8,7 @@ typedef struct _event_item { int event_encoded; event_pkg_contents contents; void *encoded_event; - size_t event_len; + ssize_t event_len; void *decoded_event; FFSEncodeVector encoded_eventv; FMFormat reference_format; @@ -234,7 +234,7 @@ typedef struct _EVclient_sources { typedef struct _ev_handler_activation_rec { struct _ev_handler_activation_rec *prev; - pthread_t thread_id; + thr_thread_t thread_id; EVstone stone_id; struct _ev_handler_activation_rec *next; } ev_handler_activation_rec, *ev_handler_activation_ptr; @@ -325,7 +325,7 @@ extern void REVPinit(CManager cm); extern int internal_write_event(CMConnection conn, CMFormat format, void *remote_path_id, int path_len, event_item *event, - attr_list attrs, long *event_len_p); + attr_list attrs, size_t *event_len_p); extern EVaction INT_EVassoc_mutated_imm_action(CManager cm, EVstone stone, EVaction act_num, EVImmediateHandlerFunc func, void *client_data, @@ -372,7 +372,7 @@ extern void INT_EVsubmit_general(EVsource source, void *data, EVFreeFunction free_func, attr_list attrs); extern void -INT_EVsubmit_encoded(CManager cm, EVstone stone, void *data, int data_len, attr_list attrs); +INT_EVsubmit_encoded(CManager cm, EVstone stone, void *data, size_t data_len, attr_list attrs); extern EVsource INT_EVcreate_submit_handle_free(CManager cm, EVstone stone, FMStructDescList data_format, diff --git a/evp.c b/evp.c index 1d23d5d860..f72ddb0cf8 100644 --- a/evp.c +++ b/evp.c @@ -5,8 +5,10 @@ #include #include #include -#include +#include +#ifdef HAVE_UNISTD_H #include +#endif #include #include "evpath.h" @@ -1253,7 +1255,7 @@ decode_action(CManager cm, event_item *event, response_cache_element *act) void *decode_buffer; if (!FFSdecode_in_place(act->o.decode.context, event->encoded_event, - (void**) (long) &decode_buffer)) { + (void**) (intptr_t) &decode_buffer)) { printf("Decode failed\n"); return 0; } @@ -1263,7 +1265,7 @@ decode_action(CManager cm, event_item *event, response_cache_element *act) event->reference_format = act->o.decode.target_reference_format; return event; } else { - int decoded_length = FFS_est_decode_length(act->o.decode.context, + size_t decoded_length = FFS_est_decode_length(act->o.decode.context, event->encoded_event, event->event_len); CMbuffer cm_decode_buf = cm_get_data_buf(cm, decoded_length); @@ -1284,7 +1286,7 @@ decode_action(CManager cm, event_item *event, response_cache_element *act) case Event_App_Owned: { /* can't do anything with the old event, make a new one */ - int decoded_length = FFS_est_decode_length(act->o.decode.context, + size_t decoded_length = FFS_est_decode_length(act->o.decode.context, event->encoded_event, event->event_len); event_item *new_event = get_free_event(evp); @@ -1330,7 +1332,7 @@ encode_event(CManager cm, event_item *event) event->encoded_event = FFSencode(event->ioBuffer, event->reference_format, event->decoded_event, - &event->event_len); + (size_t*)&event->event_len); event->event_encoded = 1; } @@ -1434,9 +1436,9 @@ fdump_action(FILE* out, stone_type stone, response_cache_element *resp, int a, c fprintf(out, "\n"); switch(act->action_type) { case Action_Bridge: - fprintf(out, " Target: %s: connection %lx, remote_stone_id %d\n", + fprintf(out, " Target: %s: connection %p, remote_stone_id %d\n", (act->o.bri.remote_path ? act->o.bri.remote_path : "NULL" ), - (long)(void*)act->o.bri.conn, act->o.bri.remote_stone_id); + (void*)act->o.bri.conn, act->o.bri.remote_stone_id); if (act->o.bri.conn != NULL) fdump_attr_list(out, act->o.bri.conn->attrs); if (act->o.bri.conn_failed) fprintf(out, "Connection has FAILED!\n"); break; @@ -1486,8 +1488,8 @@ static void fdump_stone(FILE* out, stone_type stone) { int i; - fprintf(out, "Dump stone ID %d, local addr %lx, default action %d\n", - stone->local_id, (long)stone, stone->default_action); + fprintf(out, "Dump stone ID %d, local addr %p, default action %d\n", + stone->local_id, stone, stone->default_action); fprintf(out, " Target Stones:"); { int i; @@ -1616,7 +1618,7 @@ static void push_activation_record_on_stack(CManager cm, ev_handler_activation_ptr rec) { event_path_data evp = cm->evp; - rec->thread_id = pthread_self(); + rec->thread_id = thr_thread_self(); if (evp->activation_stack != NULL) { evp->activation_stack->prev = rec; } @@ -1630,7 +1632,7 @@ pop_activation_record_from_stack(CManager cm, ev_handler_activation_ptr rec) { event_path_data evp = cm->evp; ev_handler_activation_ptr tmp; - pthread_t self = pthread_self(); + thr_thread_t self = thr_thread_self(); if (!evp->activation_stack) { printf("Activation stack inconsistency! No records!\n"); return; @@ -1661,7 +1663,7 @@ find_activation_record_from_stack(CManager cm) { event_path_data evp = cm->evp; ev_handler_activation_ptr tmp; - pthread_t self = pthread_self(); + thr_thread_t self = thr_thread_self(); tmp = evp->activation_stack; while(tmp) { if (tmp->thread_id == self) { @@ -1746,7 +1748,7 @@ process_events_stone(CManager cm, int s, action_class c) char *tmp = NULL; if (event->reference_format) tmp = global_name_of_FMFormat(event->reference_format); - printf("No action found for event %lx submitted to \n", (long)event); + printf("No action found for event %p submitted to \n", event); print_stone_identifier(evp, s); printf("\n"); dump_stone(stone_struct(evp, s)); @@ -1782,7 +1784,7 @@ process_events_stone(CManager cm, int s, action_class c) resp = &stone->response_cache[resp_id]; } if (CMtrace_on(cm, EVerbose)) { - fprintf(cm->CMTrace_file, "next action event %lx on ", (long)event); + fprintf(cm->CMTrace_file, "next action event %p on ", event); fprint_stone_identifier(cm->CMTrace_file, evp, s); fprintf(cm->CMTrace_file, " action type is %s, reference_format is %p (%s), stage is %d, requires_decoded is %d\n", action_str[resp->action_type], resp->reference_format, @@ -2046,7 +2048,7 @@ static void stone_close_handler(CManager cm, CMConnection conn, void *client_data) { event_path_data evp = cm->evp; - int s = (long)client_data; /* stone ID */ + int s = (int)(intptr_t)client_data; /* stone ID */ int a = 0; stone_type stone; EVStoneCloseHandlerFunc handler = NULL; @@ -2181,7 +2183,7 @@ do_bridge_action(CManager cm, int s) return -1; } INT_CMconn_register_close_handler(conn, stone_close_handler, - (void*)(long)s); + (void*)(intptr_t)s); } while (stone->queue->queue_head != NULL) { int ret = 1; @@ -2214,7 +2216,7 @@ do_bridge_action(CManager cm, int s) }*/ } event_item *event = dequeue_event(cm, stone); - long event_length = 0; + size_t event_length = 0; if (act->o.bri.conn == NULL) { CMtrace_out(cm, EVerbose, "Bridge stone %x has closed connection\n", s); } else { @@ -2260,7 +2262,7 @@ do_bridge_action(CManager cm, int s) } else { static atom_t EV_EVENT_COUNT = -1; static atom_t EV_EVENT_LSUM = -1; - int length_sum = 0; + ssize_t length_sum = 0; int event_count = 0; if (EV_EVENT_COUNT == -1) { EV_EVENT_COUNT = attr_atom_from_string("EV_EVENT_COUNT"); @@ -2270,12 +2272,12 @@ do_bridge_action(CManager cm, int s) stone->stone_attrs = create_attr_list(); } else { get_int_attr(stone->stone_attrs, EV_EVENT_COUNT, &event_count); - get_int_attr(stone->stone_attrs, EV_EVENT_LSUM, &length_sum); + get_long_attr(stone->stone_attrs, EV_EVENT_LSUM, &length_sum); } event_count++; length_sum += event_length; set_int_attr(stone->stone_attrs, EV_EVENT_COUNT, event_count); - set_int_attr(stone->stone_attrs, EV_EVENT_LSUM, length_sum); + set_long_attr(stone->stone_attrs, EV_EVENT_LSUM, length_sum); } } stone->is_outputting = 0; @@ -2519,7 +2521,7 @@ INT_EVassoc_bridge_action(CManager cm, EVstone stone_num, attr_list contact_list return -1; } INT_CMconn_register_close_handler(conn, stone_close_handler, - (void*)(long)stone_num); + (void*)(intptr_t)stone_num); } stone->proto_actions = realloc(stone->proto_actions, (action_num + 1) * @@ -3158,7 +3160,7 @@ EVregister_format_set(CManager cm, FMStructDescList list) static void EVauto_submit_func(CManager cm, void* vstone) { - int stone_num = (long) vstone; + int stone_num = (int)(intptr_t) vstone; event_item *event; CManager_lock(cm); event = get_free_event(cm->evp); @@ -3213,7 +3215,7 @@ INT_EVenable_auto_stone(CManager cm, EVstone stone_num, int period_sec, } handle = INT_CMadd_periodic_task(cm, period_sec, period_usec, EVauto_submit_func, - (void*)(long)stone_num); + (void*)(intptr_t)stone_num); stone->periodic_handle = handle; if (CMtrace_on(cm, EVerbose)) { fprintf(cm->CMTrace_file, "Enabling auto events on "); @@ -3271,7 +3273,7 @@ reference_event(event_item *event) extern void internal_cm_network_submit(CManager cm, CMbuffer cm_data_buf, attr_list attrs, CMConnection conn, - void *buffer, int length, int stone_id) + void *buffer, size_t length, int stone_id) { event_path_data evp = cm->evp; event_item *event = get_free_event(evp); @@ -3444,7 +3446,7 @@ INT_EVsubmit(EVsource source, void *data, attr_list attrs) } void -INT_EVsubmit_encoded(CManager cm, EVstone stone, void *data, int data_len, attr_list attrs) +INT_EVsubmit_encoded(CManager cm, EVstone stone, void *data, size_t data_len, attr_list attrs) { event_path_data evp = cm->evp; event_item *event = get_free_event(evp); @@ -3470,7 +3472,7 @@ free_evp(CManager cm, void *not_used) event_path_data evp = cm->evp; int s; (void)not_used; - CMtrace_out(cm, CMFreeVerbose, "Freeing evpath information, evp %lx\n", (long) evp); + CMtrace_out(cm, CMFreeVerbose, "Freeing evpath information, evp %p\n", evp); for (s = 0 ; s < evp->stone_count; s++) { INT_EVfree_stone(cm, s + evp->stone_base_num); } @@ -3521,9 +3523,9 @@ EVPinit(CManager cm) * just so that we're more likely to catch mitmatched stone/CM * combos in threaded situations. */ - srand48(time(NULL)); + srand((int)time(NULL)); while (cm->evp->stone_base_num == 0) { - cm->evp->stone_base_num = lrand48() & 0xffff; + cm->evp->stone_base_num = rand() & 0xffff; } } CMtrace_out(cm, EVerbose, "INITATED EVPATH, base stone num is %x\n", @@ -3574,8 +3576,8 @@ INT_EVtake_event_buffer(CManager cm, void *event) } if (cur == NULL) { fprintf(stderr, - "Event address (%lx) in INT_EVtake_event_buffer does not match currently executing event on this CM.\n", - (long) event); + "Event address (%p) in INT_EVtake_event_buffer does not match currently executing event on this CM.\n", + event); return 0; } @@ -3630,8 +3632,8 @@ INT_EVreturn_event_buffer(CManager cm, void *event) last = tmp; tmp = tmp->next; } - fprintf(stderr, "Event %lx not found in taken events list\n", - (long) event); + fprintf(stderr, "Event %p not found in taken events list\n", + event); } extern FMFormat diff --git a/evp_threads.c b/evp_threads.c index 9360e0264c..cd22b3aba6 100644 --- a/evp_threads.c +++ b/evp_threads.c @@ -5,8 +5,10 @@ #include #include #include -#include +#include +#ifdef HAVE_UNISTD_H #include +#endif #include "evpath.h" #include "cm_internal.h" diff --git a/evpath.h b/evpath.h index e9151e1e14..37e6b7b992 100644 --- a/evpath.h +++ b/evpath.h @@ -57,7 +57,7 @@ typedef struct _CMTaskHandle *CMTaskHandle; * and a pointer to their locations. */ typedef struct buf_entry { - long length; /*!< length of the encoded buffer */ + size_t length; /*!< length of the encoded buffer */ void *buffer; /*!< base address of the encoded buffer */ } *EVevent_list; @@ -590,7 +590,7 @@ extern void CMreturn_buffer (CManager cm, void *data); * Otherwise return the number of additional bytes necessary. */ typedef int (*CMNonCMHandler) (CMConnection conn, CMTransport transport, - char *buffer, long length); + char *buffer, size_t length); /*! * register a handler for raw (non-CM) messages. @@ -842,7 +842,7 @@ typedef void (*select_func) (void *param1, void*param2); * \param param2 The value to be passed as param2 to the handler_func. */ extern void -CM_fd_add_select (CManager cm, int fd, select_func handler_func, +CM_fd_add_select (CManager cm, SOCKET fd, select_func handler_func, void *param1, void *param2); /*! @@ -1182,7 +1182,7 @@ typedef int (*EVSimpleHandlerFunc) (CManager cm, void *message, void *client_dat * was delivered with. These are determined by the transport and may * include those specified in CMwrite_attr() when the data was written. */ -typedef int (*EVRawHandlerFunc) (CManager cm, void *message, int msg_len, void *client_data, +typedef int (*EVRawHandlerFunc) (CManager cm, void *message, size_t msg_len, void *client_data, attr_list attrs); /*! @@ -1927,7 +1927,7 @@ EVsubmit_general(EVsource source, void *data, EVFreeFunction free_func, * */ extern void -EVsubmit_encoded(CManager cm, EVstone stone, void *data, int data_len, +EVsubmit_encoded(CManager cm, EVstone stone, void *data, size_t data_len, attr_list attrs); /*! @@ -2377,7 +2377,7 @@ CMtest_transport(CMConnection conn, attr_list how); * contain the final values of testing. * */ -typedef attr_list (*CMperf_upcall)(CManager cm, void *buffer, long length, int type, attr_list list); +typedef attr_list (*CMperf_upcall)(CManager cm, void *buffer, size_t length, int type, attr_list list); /*! * install the callback function to support transport testing diff --git a/examples/derived_recv.c b/examples/derived_recv.c index 18eaa460e4..fe2775201c 100644 --- a/examples/derived_recv.c +++ b/examples/derived_recv.c @@ -41,7 +41,7 @@ int main(int argc, char **argv) string_list = attr_list_to_string(CMget_contact_list(cm)); filter_spec = create_filter_action_spec(simple_format_list, "{ return input.integer_field % 2;}"); - encoded_filter_spec = atl_base64_encode(filter_spec, strlen(filter_spec) + 1); + encoded_filter_spec = atl_base64_encode(filter_spec, (unsigned int) strlen(filter_spec) + 1); printf("Contact list \"%d:%s:%s\"\n", stone, string_list, encoded_filter_spec); free(filter_spec); free(encoded_filter_spec); diff --git a/examples/transform_recv.c b/examples/transform_recv.c index b87bc0977c..c82af11f7f 100644 --- a/examples/transform_recv.c +++ b/examples/transform_recv.c @@ -76,7 +76,7 @@ int main(int argc, char **argv) trans_spec = create_transform_action_spec(simple_format_list, output_format_list, trans_func); printf("trns spec is %s\n", trans_spec); - encoded_trans_spec = atl_base64_encode(trans_spec, strlen(trans_spec) + 1); + encoded_trans_spec = atl_base64_encode(trans_spec, (unsigned int) strlen(trans_spec) + 1); printf("Contact list \"%d:%s:%s\"\n", stone, string_list, encoded_trans_spec); free(trans_spec); free(encoded_trans_spec); diff --git a/examples/transform_recv2.c b/examples/transform_recv2.c index cc03d6c6de..1ef50c81ee 100644 --- a/examples/transform_recv2.c +++ b/examples/transform_recv2.c @@ -98,8 +98,8 @@ int main(int argc, char **argv) trans_func); trans_spec2 = create_transform_action_spec(second_format_list, output_format_list, trans_func2); - encoded_trans_spec = atl_base64_encode(trans_spec, strlen(trans_spec) + 1); - encoded_trans_spec2 = atl_base64_encode(trans_spec2, strlen(trans_spec2) + 1); + encoded_trans_spec = atl_base64_encode(trans_spec, (unsigned int) strlen(trans_spec) + 1); + encoded_trans_spec2 = atl_base64_encode(trans_spec2, (unsigned int) strlen(trans_spec2) + 1); printf("Contact list \"%d:%s:%s:%s\"\n", stone, string_list, encoded_trans_spec, encoded_trans_spec2); free(trans_spec); diff --git a/examples/transform_recv3.c b/examples/transform_recv3.c index ddf9140625..95adc7eebc 100644 --- a/examples/transform_recv3.c +++ b/examples/transform_recv3.c @@ -110,8 +110,8 @@ int main(int argc, char **argv) trans_func); trans_spec2 = create_transform_action_spec(second_format_list, output_format_list, trans_func2); - encoded_trans_spec = atl_base64_encode(trans_spec, strlen(trans_spec) + 1); - encoded_trans_spec2 = atl_base64_encode(trans_spec2, strlen(trans_spec2) + 1); + encoded_trans_spec = atl_base64_encode(trans_spec, (unsigned int) strlen(trans_spec) + 1); + encoded_trans_spec2 = atl_base64_encode(trans_spec2, (unsigned int) strlen(trans_spec2) + 1); printf("Contact list \"%d:%s:%s:%s\"\n", stone, string_list, encoded_trans_spec, encoded_trans_spec2); free(trans_spec); diff --git a/gen_interface.pl b/gen_interface.pl index b3f07894c2..f76852ba75 100755 --- a/gen_interface.pl +++ b/gen_interface.pl @@ -617,11 +617,22 @@ sub mod_EVhandler { #include "atl.h" #include "evpath.h" #include "stdio.h" -#include "cm_internal.h" #ifdef LT_LIBPREFIX #include "ltdl.h" +#else +#ifdef _MSC_VER +#include +#define RTLD_GLOBAL 1 +#define RTLD_LAZY 2 +extern void* dlopen(const char* filename, int flags); +extern int dlclose(void* handle); +extern void* dlsym(void* handle, const char* name); +extern const char* dlerror(void); + #else #include +#endif + #define lt_dlopen(x) dlopen(x, 0) #define lt_dlsym(x, y) dlsym(x, y) #define lt_dlhandle void* @@ -631,7 +642,7 @@ sub mod_EVhandler { #include "stdio.h" #include "string.h" #include "stdlib.h" -#include +#include "cm_internal.h" #ifdef __cplusplus extern "C" \{ #endif @@ -796,7 +807,7 @@ sub mod_EVhandler { REVPlookup_format_structs(CManager cm, char *format_name) { FMFormat format; - int slen = strlen(format_name); + int slen = (int)strlen(format_name); int i; unsigned char *id = malloc(slen/2); for (i=0; i < slen/2; i++) { diff --git a/ip_config.c b/ip_config.c index 8c8eba9c3b..f52f9e881d 100644 --- a/ip_config.c +++ b/ip_config.c @@ -6,11 +6,16 @@ #ifdef HAVE_SYS_SOCKIO_H #include #endif -#include #ifdef HAVE_WINDOWS_H -#include +#include +#include +#include #define __ANSI_CPP__ +#ifndef INET_ADDRSTRLEN +#define INET_ADDRSTRLEN 50 +#endif #else +#include #include #include #include @@ -19,7 +24,9 @@ #include #endif #include +#ifdef HAVE_UNISTD_H #include +#endif #include #include #ifdef STDC_HEADERS @@ -50,7 +57,7 @@ static int ipv4_is_loopback(int addr) static void dump_output(int length_estimate, char *format, ...); static int -get_self_ip_iface(CMTransport_trace trace_func, void* trace_data, char *interface) +get_self_ip_iface(CMTransport_trace trace_func, void* trace_data, char *iface) { struct hostent *host = NULL; char hostname_buf[256]; @@ -102,30 +109,30 @@ get_self_ip_iface(CMTransport_trace trace_func, void* trace_data, char *interfac // inet_ntop(family, tmp, buf, sizeof(buf))); } } - if (!interface) interface = getenv(IPCONFIG_ENVVAR_PREFIX "INTERFACE"); - if (interface != NULL) { - trace_func(trace_data, "CM searching for interface %s\n", interface); - if (first_call) dump_output(1023, "\t" IPCONFIG_ENVVAR_PREFIX "IP_CONFIG interface %s requested\n", interface); + if (!iface) iface = getenv(IPCONFIG_ENVVAR_PREFIX "INTERFACE"); + if (iface != NULL) { + trace_func(trace_data, "CM searching for interface %s\n", iface); + if (first_call) dump_output(1023, "\t" IPCONFIG_ENVVAR_PREFIX "IP_CONFIG interface %s requested\n", iface); for (if_addr = if_addrs; if_addr != NULL; if_addr = if_addr->ifa_next) { int family; uint32_t IP; if (!if_addr->ifa_addr) continue; family = if_addr->ifa_addr->sa_family; if (family != AF_INET) continue; /* currently not looking for ipv6 */ - if (strncmp(if_addr->ifa_name, interface, strlen(interface)) != 0) continue; + if (strncmp(if_addr->ifa_name, iface, strlen(iface)) != 0) continue; tmp = &((struct sockaddr_in *)if_addr->ifa_addr)->sin_addr; trace_func(trace_data, "CM Interface specified, returning ->%s : %s", if_addr->ifa_name, inet_ntop(family, tmp, buf, sizeof(buf))); if (first_call) - dump_output(1023, "\t" IPCONFIG_ENVVAR_PREFIX "IP_CONFIG interface %s found, using IP %s\n", interface, + dump_output(1023, "\t" IPCONFIG_ENVVAR_PREFIX "IP_CONFIG interface %s found, using IP %s\n", iface, inet_ntop(family, tmp, buf, sizeof(buf))); IP = ntohl(*(uint32_t*)tmp); free(if_addrs); first_call = 0; return IP; } - printf("Warning! " IPCONFIG_ENVVAR_PREFIX "INTERFACE specified as \"%s\", but no active interface by that name found\n", interface); + printf("Warning! " IPCONFIG_ENVVAR_PREFIX "INTERFACE specified as \"%s\", but no active interface by that name found\n", iface); } first_call = 0; @@ -166,7 +173,7 @@ get_self_ip_iface(CMTransport_trace trace_func, void* trace_data, char *interfac } #endif gethostname(hostname_buf, sizeof(hostname_buf)); - if (index(hostname_buf, '.') != NULL) { + if (strchr(hostname_buf, '.') != NULL) { /* don't even check for host if not fully qualified */ host = gethostbyname(hostname_buf); } @@ -387,7 +394,7 @@ get_qual_hostname(char *buf, int len, attr_list attrs, } } if (network_string != NULL) { - int name_len = strlen(buf) + 2 + strlen(network_string); + size_t name_len = strlen(buf) + 2 + strlen(network_string); char *new_name_str = malloc(name_len); char *first_dot = strchr(buf, '.'); @@ -469,13 +476,22 @@ dump_output(int length_estimate, char *format, ...) #endif vsprintf(tmp, format, ap); va_end(ap); - IP_config_output_len += strlen(tmp); + IP_config_output_len += (int)strlen(tmp); if (free_tmp) free(tmp); } #ifndef HOST_NAME_MAX #define HOST_NAME_MAX 255 #endif +#ifdef _MSC_VER +static int inet_aton(const char* cp, struct in_addr* addr) +{ + addr->s_addr = inet_addr(cp); + return (addr->s_addr == INADDR_NONE) ? 0 : 1; +} +#endif + + extern void get_IP_config(char *hostname_buf, int len, int* IP_p, int *port_range_low_p, int *port_range_high_p, int *use_hostname_p, attr_list attrs, CMTransport_trace trace_func, void *trace_data) @@ -487,7 +503,7 @@ get_IP_config(char *hostname_buf, int len, int* IP_p, int *port_range_low_p, int static int use_hostname = 0; char hostname_to_use[HOST_NAME_MAX+1]; int IP_to_use; - char *interface = NULL; + char *iface = NULL; if (first_call) { char *preferred_hostname = getenv(IPCONFIG_ENVVAR_PREFIX "HOSTNAME"); @@ -587,10 +603,10 @@ get_IP_config(char *hostname_buf, int len, int* IP_p, int *port_range_low_p, int } - if (get_string_attr(attrs, CM_IP_INTERFACE, &interface)) { + if (get_string_attr(attrs, CM_IP_INTERFACE, &iface)) { /* don't use predetermined stuff ! */ get_qual_hostname(hostname_to_use, sizeof(hostname_to_use) - 1 , attrs, NULL, trace_func, trace_data); - IP_to_use = get_self_ip_iface(trace_func, trace_data, interface); + IP_to_use = get_self_ip_iface(trace_func, trace_data, iface); } else { strcpy(hostname_to_use, determined_hostname); IP_to_use = determined_IP; diff --git a/metrics.c b/metrics.c index f5a95ab6e9..fdfc365f64 100644 --- a/metrics.c +++ b/metrics.c @@ -4,11 +4,12 @@ #include #include #include -#include #include #include #include +#ifdef HAVE_SYS_TIME_H #include +#endif #include #ifdef HAVE_UNISTD_H #include @@ -18,6 +19,14 @@ #include #endif +#ifdef _MSC_VER +#define open _open +#define read _read +#define close _close +#include +#include +#endif + #ifdef HAVE_MAC_SYSCTL #include #include @@ -85,8 +94,8 @@ char * skip_token (const char *p) int slurpfile(const char *filename, char *buffer, int buflen) { +#ifndef _MSC_VER int fd, read_len; - fd = open(filename, O_RDONLY); if(fd < 0) { printf("open() error on file %s \n", filename); @@ -104,6 +113,9 @@ int slurpfile(const char *filename, char *buffer, int buflen) buffer[read_len] = '\0'; close(fd); return read_len; +#else + return 0; +#endif } char *update_file(struct sensor_slurp *sf) { @@ -172,6 +184,7 @@ unsigned long total_jiffies_func ( void ) { void cpu_and_core_usage_func (double usage[]) { +#ifndef _MSC_VER char *p; int n, numcores, i; numcores = num_cpustates_func(); @@ -215,7 +228,7 @@ void cpu_and_core_usage_func (double usage[]) p = skip_whitespace(p); } - +#endif } double cpu_user_func ( void ) @@ -339,7 +352,7 @@ double cpu_idle_func ( void ) } /**************NET FUNCTIONS*****************/ -long received_bytes(char *interface) +long received_bytes(char *iface) { static long r_bytes=0; #ifdef HAVE_MAC_SYSCTL @@ -356,7 +369,7 @@ long received_bytes(char *interface) mib[5] = 0; mlen = 6; - ifindex = if_nametoindex(interface); + ifindex = if_nametoindex(iface); sysctl(mib,mlen,NULL,&vlen,NULL,0); buf = malloc(vlen); sysctl(mib,mlen,buf,&vlen,NULL,0); @@ -380,10 +393,10 @@ long received_bytes(char *interface) #else char *temp_if; char *p; - if(interface == NULL) + if(iface == NULL) temp_if = strdup("eth0"); else - temp_if = strdup((const char *)interface); + temp_if = strdup((const char *)iface); sensor_slurp proc_net = { "/proc/net/dev" }; p = update_file(&proc_net); while (p && strncmp(p,temp_if,strlen(temp_if))) @@ -400,7 +413,7 @@ long received_bytes(char *interface) return r_bytes; } -long sent_bytes(char *interface) +long sent_bytes(char *iface) { long s_bytes; #ifdef HAVE_MAC_SYSCTL @@ -418,7 +431,7 @@ long sent_bytes(char *interface) mib[5] = 0; mlen = 6; - ifindex = if_nametoindex(interface); + ifindex = if_nametoindex(iface); sysctl(mib,mlen,NULL,&vlen,NULL,0); buf = malloc(vlen); sysctl(mib,mlen,buf,&vlen,NULL,0); @@ -441,10 +454,10 @@ long sent_bytes(char *interface) char *temp_if; char *p; int i=0; - if(interface == NULL) + if(iface == NULL) temp_if = strdup("eth0"); else - temp_if = strdup((const char *)interface); + temp_if = strdup((const char *)iface); sensor_slurp proc_net = { "/proc/net/dev" }; p = update_file(&proc_net); while (p && strncmp(p,temp_if,strlen(temp_if))) @@ -470,7 +483,7 @@ long sent_bytes(char *interface) * bandwidth is returned. On OS X the two calls have to be atleast 425 microseconds apart. * */ -double net_bw(char *interface, char *stage) +double net_bw(char *iface, char *stage) { static long old_s_bytes, new_s_bytes, old_r_bytes, new_r_bytes, start_time, end_time; long s_bytes, r_bytes; @@ -490,7 +503,7 @@ double net_bw(char *interface, char *stage) mib[5] = 0; mlen = 6; - ifindex = if_nametoindex(interface); + ifindex = if_nametoindex(iface); sysctl(mib,mlen,NULL,&vlen,NULL,0); buf = malloc(vlen); sysctl(mib,mlen,buf,&vlen,NULL,0); @@ -518,14 +531,24 @@ double net_bw(char *interface, char *stage) char *temp_if; char *p; - if(interface == NULL) + if(iface == NULL) temp_if = strdup("eth0"); else - temp_if = strdup((const char*)interface); + temp_if = strdup((const char*)iface); sensor_slurp proc_net = { "/proc/net/dev" }; p = update_file(&proc_net); - gettimeofday(&t,NULL); - +#ifndef HAVE_WINDOWS_H + gettimeofday(&t, NULL); +#else + /* GSE... No gettimeofday on windows. + * Must use _ftime, get millisec time, convert to usec. Bleh. + */ + + struct _timeb nowb; + _ftime(&nowb); + t.tv_sec = (long)nowb.time; + t.tv_usec = nowb.millitm * 1000; +#endif while (p && strncmp(p,temp_if,strlen(temp_if))) { p = skip_token(p); @@ -580,6 +603,7 @@ double dgettimeofday( void ) /**************OS FUNCTIONS**************/ char* os_type() { +#ifndef _MSC_VER static struct utsname output; static int first = 1; if (first) { @@ -587,9 +611,13 @@ char* os_type() { first = 0; } return strdup(output.sysname); +#else + return strdup("Windows"); +#endif } char* os_release() { +#ifndef _MSC_VER static struct utsname output; static int first = 1; if (first) { @@ -597,6 +625,9 @@ char* os_release() { first = 0; } return strdup(output.release); +#else + return strdup("Windows Release"); +#endif } /* Should probably test if gethostname & uname exist on box before using them.... */ @@ -979,22 +1010,22 @@ add_metrics_routines(stone_type stone, cod_parse_context context) * some compilers think it isn't a static initialization to put this * in the structure above, so do it explicitly. */ - externs[0].extern_value = (void *) (long) dgettimeofday; - externs[1].extern_value = (void *) (long) hw_cpus; - externs[2].extern_value = (void *) (long) hw_cpu_min_freq; - externs[3].extern_value = (void *) (long) hw_cpu_max_freq; - externs[4].extern_value = (void *) (long) hw_cpu_curr_freq; - externs[5].extern_value = (void *) (long) os_type; - externs[6].extern_value = (void *) (long) os_release; - externs[7].extern_value = (void *) (long) hostname; - externs[8].extern_value = (void *) (long) stat_uptime; - externs[9].extern_value = (void *) (long) stat_loadavg_one; - externs[10].extern_value = (void *) (long) stat_loadavg_five; - externs[11].extern_value = (void *) (long) stat_loadavg_fifteen; - externs[12].extern_value = (void *) (long) vm_mem_total; - externs[13].extern_value = (void *) (long) vm_mem_free; - externs[14].extern_value = (void *) (long) vm_swap_total; - externs[15].extern_value = (void *) (long) vm_swap_free; + externs[0].extern_value = (void *) (intptr_t) dgettimeofday; + externs[1].extern_value = (void *) (intptr_t) hw_cpus; + externs[2].extern_value = (void *) (intptr_t) hw_cpu_min_freq; + externs[3].extern_value = (void *) (intptr_t) hw_cpu_max_freq; + externs[4].extern_value = (void *) (intptr_t) hw_cpu_curr_freq; + externs[5].extern_value = (void *) (intptr_t) os_type; + externs[6].extern_value = (void *) (intptr_t) os_release; + externs[7].extern_value = (void *) (intptr_t) hostname; + externs[8].extern_value = (void *) (intptr_t) stat_uptime; + externs[9].extern_value = (void *) (intptr_t) stat_loadavg_one; + externs[10].extern_value = (void *) (intptr_t) stat_loadavg_five; + externs[11].extern_value = (void *) (intptr_t) stat_loadavg_fifteen; + externs[12].extern_value = (void *) (intptr_t) vm_mem_total; + externs[13].extern_value = (void *) (intptr_t) vm_mem_free; + externs[14].extern_value = (void *) (intptr_t) vm_swap_total; + externs[15].extern_value = (void *) (intptr_t) vm_swap_free; cod_assoc_externs(context, externs); cod_parse_for_context(extern_string, context); diff --git a/mtests/bulktest.c b/mtests/bulktest.c index 23c151edec..678396c3d1 100644 --- a/mtests/bulktest.c +++ b/mtests/bulktest.c @@ -14,6 +14,8 @@ #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) + #else #include #endif @@ -188,7 +190,11 @@ simple_handler(CManager cm, CMConnection conn, void *vevent, void *client_data, (int) sum, (int) scan_sum); } msg_count++; +#ifdef _MSC_VER + Sleep(10); +#else usleep(10000); +#endif if ((quiet <= -1) || (sum != scan_sum)) { printf("In the handler, event data is :\n"); printf(" integer_field = %d\n", event->integer_field); @@ -453,8 +459,8 @@ do_regression_master_test() } done++; } - } #endif + } if (msg_count != MSG_COUNT) { int i = 10; while ((i >= 0) && (msg_count != MSG_COUNT)) { diff --git a/mtests/cmconn.c b/mtests/cmconn.c index 064f27ed7f..a2a3cafdd3 100644 --- a/mtests/cmconn.c +++ b/mtests/cmconn.c @@ -22,10 +22,19 @@ #include #include #include +#ifdef HAVE_ARPA_INET_H #include +#endif #include "evpath.h" +#ifdef HAVE_SYS_WAIT_H #include - +#endif +#ifdef _MSC_VER +#define drand48() (((double)rand())/((double)RAND_MAX)) +#define lrand48() rand() +#define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) +#endif typedef struct _msg_rec { char *contact_list; int message_id; @@ -133,7 +142,7 @@ main(int argc, char **argv) PARSE_ARGS(); - srand48(getpid()); + srand(getpid()); CM_TRANSPORT = attr_atom_from_string("CM_TRANSPORT"); if (regression && regression_master) { diff --git a/mtests/cmping.c b/mtests/cmping.c index fab7188ebd..067eb11f76 100644 --- a/mtests/cmping.c +++ b/mtests/cmping.c @@ -8,15 +8,18 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include +#include +#include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif typedef struct _complex_rec { @@ -131,7 +134,7 @@ simple_handler(CManager cm, CMConnection conn, void *vevent, void *client_data, (int) sum, (int) scan_sum); } if ((quiet <= 0) || (sum != scan_sum)) { - printf("In the handler, connection is %lx, event data is :\n", (long) conn); + printf("In the handler, connection is %p, event data is :\n", conn); printf(" integer_field = %d\n", event->integer_field); printf(" short_field = %d\n", event->short_field); printf(" long_field = %ld\n", event->long_field); @@ -206,7 +209,7 @@ main(int argc, char **argv) #define HELLO_PORT 12345 #define HELLO_GROUP "225.0.0.37" int addr; - (void) inet_aton(HELLO_GROUP, (struct in_addr *)&addr); + (void) inet_pton(AF_INET, HELLO_GROUP, (struct in_addr *)&addr); contact_list = create_attr_list(); add_attr(contact_list, CM_MCAST_ADDR, Attr_Int4, (attr_value) (long)addr); @@ -308,7 +311,7 @@ do_regression_master_test() #define HELLO_PORT 12345 #define HELLO_GROUP "225.0.0.37" int addr; - (void) inet_aton(HELLO_GROUP, (struct in_addr *)&addr); + (void) inet_pton(AF_INET, HELLO_GROUP, (struct in_addr *)&addr); contact_list = create_attr_list(); add_attr(contact_list, CM_MCAST_ADDR, Attr_Int4, (attr_value) (long)addr); diff --git a/mtests/cmtest.c b/mtests/cmtest.c index 5a15524480..0396443fee 100644 --- a/mtests/cmtest.c +++ b/mtests/cmtest.c @@ -8,15 +8,18 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include +#include +#include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0, 0, (DWORD)x),y) #else #include +#include #endif typedef struct _complex_rec { @@ -127,7 +130,7 @@ simple_handler(CManager cm, CMConnection conn, void *vevent, void *client_data, (int) sum, (int) scan_sum); } if ((quiet <= 0) || (sum != scan_sum)) { - printf("In the handler, connection is %lx, event data is :\n", (long)conn); + printf("In the handler, connection is %p, event data is :\n", conn); printf(" integer_field = %d\n", event->integer_field); printf(" short_field = %d\n", event->short_field); printf(" long_field = %ld\n", event->long_field); @@ -207,7 +210,7 @@ main(int argc, char **argv) #define HELLO_PORT 12345 #define HELLO_GROUP "225.0.0.37" int addr; - (void) inet_aton(HELLO_GROUP, (struct in_addr *)&addr); + (void) inet_pton(AF_INET, HELLO_GROUP, (struct in_addr *)&addr); contact_list = create_attr_list(); add_attr(contact_list, CM_MCAST_ADDR, Attr_Int4, (attr_value) (long)addr); @@ -321,7 +324,7 @@ do_regression_master_test() #define HELLO_PORT 12345 #define HELLO_GROUP "225.0.0.37" int addr; - (void) inet_aton(HELLO_GROUP, (struct in_addr *)&addr); + (void) inet_pton(AF_INET, HELLO_GROUP, (struct in_addr *)&addr); contact_list = create_attr_list(); add_attr(contact_list, CM_MCAST_ADDR, Attr_Int4, (attr_value) (long)addr); diff --git a/mtests/support.c b/mtests/support.c index 5f52740c1e..01bb680382 100644 --- a/mtests/support.c +++ b/mtests/support.c @@ -2,6 +2,10 @@ static char *ssh_args[6]={NULL, NULL, NULL, NULL, NULL, NULL}; static char remote_directory[1024] = ""; static char *argv0; static int no_fork = 0; +#ifdef _MSC_VER +#define pid_t intptr_t +#include +#endif static void usage() @@ -34,10 +38,10 @@ usage() printf("Missing --ssh destination\n");\ usage();\ }\ - first_colon = index(argv[2], ':');\ + first_colon = strchr(argv[2], ':');\ if (first_colon) {\ *first_colon = 0;\ - second_colon = index(first_colon+1, ':');\ + second_colon = strchr(first_colon+1, ':');\ } else {\ second_colon = NULL;\ }\ @@ -92,7 +96,7 @@ run_subprocess(char **args) { char **run_args = args; #ifdef HAVE_WINDOWS_H - int child; + intptr_t child; child = _spawnv(_P_NOWAIT, "./evtest.exe", args); if (child == -1) { printf("failed for evtest\n"); @@ -113,7 +117,7 @@ run_subprocess(char **args) i++; } if (remote_directory[0] != 0) { - if (rindex(argv0, '/')) argv0 = rindex(argv0, '/') + 1; + if (strrchr(argv0, '/')) argv0 = strrchr(argv0, '/') + 1; run_args[i] = malloc(strlen(remote_directory) + strlen(argv0) + 4); strcpy(run_args[i], remote_directory); diff --git a/mtests/take_test.c b/mtests/take_test.c index eb4fdf8cd6..ed7183f5d2 100644 --- a/mtests/take_test.c +++ b/mtests/take_test.c @@ -14,6 +14,8 @@ #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) + #else #include #endif @@ -96,7 +98,7 @@ static FMStructDescRec simple_format_list[] = }; static size_t size = 100000; -static size_t vecs = 1; +static long vecs = 1; static void @@ -140,7 +142,7 @@ generate_record(simple_rec_ptr event) printf("Vecs = %ld\n", vecs); for (i=0; i < vecs; i++) { event->vecs[i].iov_len = size/vecs; - printf("Vec_len = %ld\n", size/vecs); + printf("Vec_len = %zd\n", size/vecs); event->vecs[i].iov_base = malloc(event->vecs[i].iov_len); memset(event->vecs[i].iov_base, 0, event->vecs[i].iov_len); } @@ -236,11 +238,11 @@ static char *transport = NULL; argv++;\ argc--;\ } else if (strcmp(&argv[1][1], "vecs") == 0) {\ - if (sscanf(argv[2], "%zu", &vecs) != 1) {\ + if (sscanf(argv[2], "%lu", &vecs) != 1) {\ printf("Unparseable argument to -vecs, %s\n", argv[2]);\ }\ argv++;\ - argc--; + argc--;\ #include "support.c" @@ -388,7 +390,7 @@ do_regression_master_test() sprintf(&size_str[0], "%zu", size); args[3] = size_str; args[4] = "-vecs"; - sprintf(&vec_str[0], "%zu", vecs); + sprintf(&vec_str[0], "%lu", vecs); args[5] = vec_str; args[6] = string_list; @@ -447,8 +449,8 @@ do_regression_master_test() } done++; } - } #endif + } if (msg_count != MSG_COUNT) { int i = 10; while ((i >= 0) && (msg_count != MSG_COUNT)) { diff --git a/mtests/trans_test.c b/mtests/trans_test.c index fff5a7a9a6..a51fe995f5 100644 --- a/mtests/trans_test.c +++ b/mtests/trans_test.c @@ -17,6 +17,16 @@ #else #define MPI_Finalize() #endif +#ifdef _MSC_VER +#define pid_t intptr_t +#include +#include +#include +#include +#include +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) +#define getcwd(x,y) _getcwd(x,y) +#endif static atom_t CM_TRANS_TEST_SIZE = 10240; static atom_t CM_TRANS_TEST_VECS = 4; @@ -40,7 +50,7 @@ static int received_count = 0; static int *received_counts = NULL; static int taken_corrupt = 0; static int expected_count = -1; -static long write_size = -1; +static size_t write_size = (size_t)( - 1); static int verbose = 0; static int take = 0; static int size_error = 0; @@ -52,13 +62,13 @@ static int me = 0; static int install_schedule = 0; typedef struct _buf_list { int checksum; - long length; + size_t length; void *buffer; } *buf_list; chr_time bandwidth_start_time; attr_list -trans_test_upcall(CManager cm, void *buffer, long length, int type, attr_list list) +trans_test_upcall(CManager cm, void *buffer, size_t length, int type, attr_list list) { static buf_list buffer_list = NULL; static int buffer_count = 0; @@ -81,17 +91,17 @@ trans_test_upcall(CManager cm, void *buffer, long length, int type, attr_list li } if (list) { get_int_attr(list, CM_TRANS_TEST_REPEAT, &expected_count); - get_long_attr(list, CM_TRANS_TEST_SIZE, &write_size); + get_long_attr(list, CM_TRANS_TEST_SIZE, (ssize_t*) &write_size); get_int_attr(list, CM_TRANS_TEST_VERBOSE, &verbose); get_int_attr(list, CM_TRANS_TEST_TAKE_RECEIVE_BUFFER, &take); } return NULL; case 1: /* body message */ - if (verbose) printf("Body message %d received from node %d, length %ld\n", *(int*)buffer, + if (verbose) printf("Body message %d received from node %d, length %zd\n", *(int*)buffer, ((int*)buffer)[1], length); if (length != (write_size - 12 /* test protocol swallows a little as header */)) { - printf("Error in body delivery size, expected %ld, got %ld\n", write_size - 12, length); + printf("Error in body delivery size, expected %zd, got %zd\n", write_size - 12, length); size_error++; } if (use_mpi) { @@ -161,7 +171,7 @@ trans_test_upcall(CManager cm, void *buffer, long length, int type, attr_list li set_double_attr(list, CM_TRANS_TEST_DURATION, chr_time_to_secs(&bandwidth_start_time)); if (get_double_attr(list, CM_TRANS_TEST_DURATION, &secs)) { - long size = received_count * write_size * (np-1); + size_t size = received_count * write_size * (np-1); double megabits = (double)size*8 / ((double)1000*1000); double megabits_sec = megabits / secs; set_double_attr(ret, CM_TRANS_MEGABITS_SEC, megabits_sec); @@ -196,7 +206,7 @@ fail_and_die(int signal) (void)signal; fprintf(stderr, "Trans_test failed to complete in reasonable time, increase from -timeout %d\n", timeout); fprintf(stderr, "Stats are : vec_count = %d, size = %ld, msg_count = %d, reuse_write = %d, received_count = %d\n", vec_count, size, msg_count, reuse_write, received_count); - fprintf(stderr, " reuse_write = %d, received_count = %d, taken_corrupt = %d, expected_count = %d, write_size = %ld, size_error = %d\n", reuse_write, received_count, taken_corrupt, expected_count, write_size, size_error); + fprintf(stderr, " reuse_write = %d, received_count = %d, taken_corrupt = %d, expected_count = %d, write_size = %zd, size_error = %d\n", reuse_write, received_count, taken_corrupt, expected_count, write_size, size_error); if (subproc_proc != 0) { kill(subproc_proc, 9); } @@ -209,7 +219,7 @@ pid_t run_subprocess(char **args) { #ifdef HAVE_WINDOWS_H - int child; + intptr_t child; child = _spawnv(_P_NOWAIT, args[0], args); if (child == -1) { printf("failed for cmtest\n"); @@ -257,9 +267,7 @@ usage() } int -main(argc, argv) - int argc; - char **argv; +main(int argc, char **argv) { CManager cm; CMConnection conn = NULL; @@ -418,7 +426,9 @@ main(argc, argv) #else me = 0; #endif - +#ifdef HAVE_WINDOWS_H + SetTimer(NULL, 5, timeout, (TIMERPROC)fail_and_die); +#else struct sigaction sigact; sigact.sa_flags = 0; sigact.sa_handler = fail_and_die; @@ -426,6 +436,7 @@ main(argc, argv) sigaddset(&sigact.sa_mask, SIGALRM); sigaction(SIGALRM, &sigact, NULL); alarm(timeout); +#endif cm = CManager_create(); CMinstall_perf_upcall(cm, trans_test_upcall); @@ -487,7 +498,17 @@ main(argc, argv) openings[1].duration.tv_sec = 4; openings[1].duration.tv_usec = 0; openings[2].offset.tv_sec = 0; openings[2].offset.tv_usec = 0; openings[2].duration.tv_sec = 0; openings[2].duration.tv_usec = 0; - gettimeofday(&now, NULL); +#ifdef HAVE_GETTIMEOFDAY + gettimeofday((struct timeval*)&now, NULL); +#else + /* GSE... No gettimeofday on windows. + * Must use _ftime, get millisec time, convert to usec. Bleh. + */ + struct _timeb nowb; + _ftime(&nowb); + ((struct timeval*)&now)->tv_sec = (long)nowb.time; + ((struct timeval*)&now)->tv_usec = nowb.millitm * 1000; +#endif now.tv_sec--; CMinstall_pull_schedule(cm, &now, &period, &openings[0]); } diff --git a/qual_hostname.c b/qual_hostname.c index 0ae06dc134..c917626e8c 100644 --- a/qual_hostname.c +++ b/qual_hostname.c @@ -6,11 +6,11 @@ #ifdef HAVE_SYS_SOCKIO_H #include #endif -#include #ifdef HAVE_WINDOWS_H -#include +#include #define __ANSI_CPP__ #else +#include #include #include #include @@ -364,7 +364,7 @@ get_qual_hostname(void *cm, char *buf, int len, CMtrans_services svc, attr_list } } if (network_string != NULL) { - int name_len = strlen(buf) + 2 + strlen(network_string); + size_t name_len = strlen(buf) + 2 + strlen(network_string); char *new_name_str = svc->malloc_func(name_len); char *first_dot = strchr(buf, '.'); diff --git a/response.c b/response.c index b44f5756c9..fae5c44294 100644 --- a/response.c +++ b/response.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -116,16 +115,16 @@ add_FMfieldlist_to_string(char *str, FMStructDescRec *f) { int index, field_count = 0; FMFieldList list = f->field_list; - int len = strlen(str); + int len = (int) strlen(str); char *tmp_str; - len += strlen(f->format_name) + 5 + 35 + 20; + len += (int)strlen(f->format_name) + 5 + 35 + 20; str = realloc(str, len); while(list && (list[field_count].field_name != NULL)) field_count++; tmp_str = str + strlen(str); sprintf(tmp_str, "FMFormat \"%s\" StructSize %d FieldCount %d\n", f->format_name, f->struct_size, field_count); for (index = 0; index < field_count; index++) { - len += strlen(list[index].field_name) +strlen(list[index].field_type) + 50; + len += (int)strlen(list[index].field_name) + (int) strlen(list[index].field_type) + 50; str = realloc(str, len); tmp_str = str + strlen(str); sprintf(tmp_str, " FMField \"%s\" \"%s\" %d %d\n", @@ -423,9 +422,9 @@ create_terminal_action_spec(FMStructDescList format_list) char * INT_create_bridge_action_spec(int stone_id, char *contact) { - int size = strlen(contact); + int size = (int) strlen(contact); char *output; - size += strlen("Bridge Action") + 20; + size += (int) strlen("Bridge Action") + 20; output = malloc(size); sprintf(output, "Bridge Action %d %s", stone_id, contact); return output; @@ -594,7 +593,7 @@ filter_wrapper(CManager cm, struct _event_item *event, void *client_data, ev_state.out_stones = out_stones; if (ec != NULL) { #ifdef HAVE_COD_H - cod_assoc_client_data(ec, 0x34567890, (long)&ev_state); + cod_assoc_client_data(ec, 0x34567890, (intptr_t)&ev_state); ret = ((int(*)(cod_exec_context, void *, attr_list))instance->u.filter.code->func)(ec, event->decoded_event, attrs); #endif @@ -629,7 +628,7 @@ router_wrapper(CManager cm, struct _event_item *event, void *client_data, ev_state.cur_event = event; ev_state.out_count = out_count; ev_state.out_stones = out_stones; - cod_assoc_client_data(ec, 0x34567890, (long)&ev_state); + cod_assoc_client_data(ec, 0x34567890, (intptr_t)&ev_state); ret = (func)(ec, event->decoded_event, attrs); #endif } @@ -687,7 +686,7 @@ transform_wrapper(CManager cm, struct _event_item *event, void *client_data, if (ec != NULL) { #ifdef HAVE_COD_H func = (int(*)(cod_exec_context, void *, void*, attr_list, attr_list))instance->u.transform.code->func; - cod_assoc_client_data(ec, 0x34567890, (long)&ev_state); + cod_assoc_client_data(ec, 0x34567890, (intptr_t)&ev_state); ret = func(ec, event->decoded_event, out_event, attrs, output_attrs); #endif } else { @@ -1087,7 +1086,7 @@ queued_wrapper(CManager cm, struct _queue *queue, queue_item *item, ev_state.item = item; ev_state.instance = instance; ev_state.did_output = 0; - cod_assoc_client_data(ec, 0x34567890, (long)&ev_state); + cod_assoc_client_data(ec, 0x34567890, (intptr_t)&ev_state); func(ec); @@ -1106,8 +1105,7 @@ generate_multityped_code(CManager cm, struct response_spec *mrd, stone_type ston extern void -free_struct_list(list) -FMStructDescList list; +free_struct_list(FMStructDescList list) { int format_count = 0; int format; @@ -1702,6 +1700,21 @@ internal_cod_submit(cod_exec_context ec, int port, void *data, void *type_info) internal_cod_submit_general(ec, port, data, type_info, NULL, NULL); } +#ifdef _MSC_VER +static long lrand48() +{ + return rand(); +} + +static double drand48() { + return (double)(rand()) / (double)(RAND_MAX); +} +static void +sleep(int t) +{ + Sleep(t * 1000); +} +#endif static void add_standard_routines(stone_type stone, cod_parse_context context) { @@ -1744,19 +1757,20 @@ add_standard_routines(stone_type stone, cod_parse_context context) * some compilers think it isn't a static initialization to put this * in the structure above, so do it explicitly. */ - externs[0].extern_value = (void *) (long) printf; - externs[1].extern_value = (void *) (long) malloc; - externs[2].extern_value = (void *) (long) free; - externs[3].extern_value = (void *) (long) lrand48; - externs[4].extern_value = (void *) (long) drand48; - externs[5].extern_value = (void *) (long) &stone->stone_attrs; - externs[6].extern_value = (void *) (long) &internal_cod_submit; - externs[7].extern_value = (void *) (long) &internal_cod_submit_attr; - externs[8].extern_value = (void *) (long) &internal_cod_submit_general; - externs[9].extern_value = (void *) (long) &sleep; - externs[10].extern_value = (void *) (long) &cod_max_output; - externs[11].extern_value = (void *) (long) &cod_target_stone_on_port; - externs[12].extern_value = (void *) (long) &cod_ev_get_stone_attrs; + + externs[0].extern_value = (void *) (intptr_t) printf; + externs[1].extern_value = (void *) (intptr_t) malloc; + externs[2].extern_value = (void *) (intptr_t) free; + externs[3].extern_value = (void *) (intptr_t) lrand48; + externs[4].extern_value = (void *) (intptr_t) drand48; + externs[5].extern_value = (void *) (intptr_t) &stone->stone_attrs; + externs[6].extern_value = (void *) (intptr_t) &internal_cod_submit; + externs[7].extern_value = (void *) (intptr_t) &internal_cod_submit_attr; + externs[8].extern_value = (void *) (intptr_t) &internal_cod_submit_general; + externs[9].extern_value = (void *) (intptr_t) &sleep; + externs[10].extern_value = (void *) (intptr_t) &cod_max_output; + externs[11].extern_value = (void *) (intptr_t) &cod_target_stone_on_port; + externs[12].extern_value = (void *) (intptr_t) &cod_ev_get_stone_attrs; cod_assoc_externs(context, externs); cod_parse_for_context(extern_string, context); @@ -1840,7 +1854,7 @@ add_typed_queued_routines(cod_parse_context context, int index, const char *fmt_ * the index here is the index of the queue itself, * while the index in the calls above is the index of the referenced queue item */ - cod_set_closure(cur->extern_name, (void*)(long)index, context); + cod_set_closure(cur->extern_name, (void*)(intptr_t)index, context); free(cur->extern_name); } free(externs); @@ -1860,7 +1874,7 @@ add_typed_queued_routines(cod_parse_context context, int index, const char *fmt_ * the index here is the index of the queue itself, * while the index in the calls above is the index of the referenced queue item */ - cod_set_closure(cur->extern_name, (void*)(long)index, context); + cod_set_closure(cur->extern_name, (void*)(intptr_t)index, context); free(cur->extern_name); } } @@ -1927,11 +1941,11 @@ add_queued_routines(cod_parse_context context, FMFormat *formats) cod_assoc_externs(context, externs); cod_parse_for_context(extern_string, context); - cod_set_closure("EVdiscard_full", (void*)(long)-1, context); - cod_set_closure("EVdiscard_and_submit_full", (void*)(long)-1, context); - cod_set_closure("EVget_attrs_full", (void*)(long)-1, context); - cod_set_closure("EVdata_full", (void*)(long)-1, context); - cod_set_closure("EVcount_full", (void*)(long)-1, context); + cod_set_closure("EVdiscard_full", (void*)(intptr_t)-1, context); + cod_set_closure("EVdiscard_and_submit_full", (void*)(intptr_t)-1, context); + cod_set_closure("EVget_attrs_full", (void*)(intptr_t)-1, context); + cod_set_closure("EVdata_full", (void*)(intptr_t)-1, context); + cod_set_closure("EVcount_full", (void*)(intptr_t)-1, context); for (cur = formats, i = 0; *cur; ++cur, ++i) { add_typed_queued_routines(context, i, name_of_FMformat(*cur)); @@ -1960,7 +1974,7 @@ extern sm_ref cod_build_param_node(const char *id, sm_ref typ, int param_num); extern void cod_add_decl_to_parse_context(const char *name, sm_ref item, cod_parse_context context); -extern void +extern FFS_DECLSPEC void cod_add_param(const char *id, const char *typ, int param_num, cod_parse_context context); diff --git a/response.h b/response.h index ae85c1eeaa..9fdd396f53 100644 --- a/response.h +++ b/response.h @@ -1,4 +1,4 @@ -extern int response_data_free(); +extern int response_data_free(CManager cm, void *resp_void); extern void * install_response_handler(CManager cm, int stone_id, char *response_spec, diff --git a/rtests/evtest.c b/rtests/evtest.c index e0f137798b..cf1a2ac732 100644 --- a/rtests/evtest.c +++ b/rtests/evtest.c @@ -8,16 +8,20 @@ #include #include #include -#include #include "evpath.h" #include "revpath.h" #ifdef HAVE_WINDOWS_H #include +#include +#include + #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif typedef struct _complex_rec { @@ -293,7 +297,7 @@ do_regression_master_test() #define HELLO_PORT 12345 #define HELLO_GROUP "225.0.0.37" int addr; - (void) inet_aton(HELLO_GROUP, (struct in_addr *)&addr); + (void) inet_pton(AF_INET, HELLO_GROUP, (struct in_addr *)&addr); contact_list = create_attr_list(); add_attr(contact_list, CM_MCAST_ADDR, Attr_Int4, (attr_value) (long)addr); diff --git a/rtests/extract_test.c b/rtests/extract_test.c index 980a8b8fc5..ed2677329b 100644 --- a/rtests/extract_test.c +++ b/rtests/extract_test.c @@ -8,15 +8,18 @@ #include #include #include -#include #include "evpath.h" #include "revpath.h" #ifdef HAVE_WINDOWS_H #include +#include < ws2tcpip.h> +#include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0, 0, (DWORD)x),y) #else +#include #include #endif @@ -362,7 +365,7 @@ do_regression_master_test() #define HELLO_PORT 12345 #define HELLO_GROUP "225.0.0.37" int addr; - (void) inet_aton(HELLO_GROUP, (struct in_addr *)&addr); + (void) inet_pton(AF_INET, HELLO_GROUP, (struct in_addr *)&addr); contact_list = create_attr_list(); add_attr(contact_list, CM_MCAST_ADDR, Attr_Int4, (attr_value) (long)addr); diff --git a/rtests/remote_terminal_test.c b/rtests/remote_terminal_test.c index e3f87521ed..999bb626b4 100644 --- a/rtests/remote_terminal_test.c +++ b/rtests/remote_terminal_test.c @@ -8,15 +8,18 @@ #include #include #include -#include #include "evpath.h" #include "revpath.h" #ifdef HAVE_WINDOWS_H #include +#include +#include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else +#include #include #endif @@ -287,7 +290,7 @@ do_regression_master_test() #define HELLO_PORT 12345 #define HELLO_GROUP "225.0.0.37" int addr; - (void) inet_aton(HELLO_GROUP, (struct in_addr *)&addr); + (void) inet_pton(AF_INET, HELLO_GROUP, (struct in_addr *)&addr); contact_list = create_attr_list(); add_attr(contact_list, CM_MCAST_ADDR, Attr_Int4, (attr_value) (long)addr); diff --git a/tests/auto_test.c b/tests/auto_test.c index 95e00db44c..492b9dcd02 100644 --- a/tests/auto_test.c +++ b/tests/auto_test.c @@ -8,15 +8,16 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif typedef struct _complex_rec { diff --git a/tests/bulktest.c b/tests/bulktest.c index ccd5aba339..af28afa6c4 100644 --- a/tests/bulktest.c +++ b/tests/bulktest.c @@ -10,15 +10,16 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif #define MSG_COUNT 30 @@ -292,10 +293,10 @@ main(int argc, char **argv) printf("Missing --ssh destination\n"); usage(); } - first_colon = index(argv[2], ':'); + first_colon = strchr(argv[2], ':'); if (first_colon) { *first_colon = 0; - second_colon = index(first_colon+1, ':'); + second_colon = strchr(first_colon+1, ':'); } else { second_colon = NULL; } @@ -500,19 +501,19 @@ static int do_regression_master_test() { CManager cm; - char *args[20] = {"bulktest", "-c", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + char* args[20] = { "bulktest", "-c", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; int last_arg = 2; int exit_state; int forked = 0; attr_list contact_list, listen_list = NULL; - char *string_list, *postfix; + char* string_list, * postfix; char size_str[40]; char vec_str[40]; char msg_str[40]; EVstone handle; int done = 0; #ifdef HAVE_WINDOWS_H - SetTimer(NULL, 5, 1000, (TIMERPROC) fail_and_die); + SetTimer(NULL, 5, 1000, (TIMERPROC)fail_and_die); #else struct sigaction sigact; sigact.sa_flags = 0; @@ -522,49 +523,52 @@ do_regression_master_test() sigaction(SIGALRM, &sigact, NULL); alarm(300); #endif + cm = CManager_create(); forked = CMfork_comm_thread(cm); if (transport || ((transport = getenv("CMTransport")) != NULL)) { listen_list = create_attr_list(); add_attr(listen_list, CM_TRANSPORT, Attr_String, - (attr_value) strdup(transport)); + (attr_value)strdup(transport)); } if ((postfix = getenv("CMNetworkPostfix")) != NULL) { if (listen_list == NULL) listen_list = create_attr_list(); add_attr(listen_list, CM_NETWORK_POSTFIX, Attr_String, - (attr_value) strdup(postfix)); + (attr_value)strdup(postfix)); } CMlisten_specific(cm, listen_list); if (listen_list) free_attr_list(listen_list); contact_list = CMget_contact_list(cm); if (transport != NULL) { - char *actual_transport = NULL; - get_string_attr(contact_list, CM_TRANSPORT, &actual_transport); - if (!actual_transport || (strncmp(actual_transport, transport, strlen(actual_transport)) != 0)) { - printf("Failed to load transport \"%s\"\n", transport); - exit(1); - } + char* actual_transport = NULL; + get_string_attr(contact_list, CM_TRANSPORT, &actual_transport); + if (!actual_transport || (strncmp(actual_transport, transport, strlen(actual_transport)) != 0)) { + printf("Failed to load transport \"%s\"\n", transport); + exit(1); + } } + if (contact_list) { string_list = attr_list_to_string(contact_list); free_attr_list(contact_list); - } else { + } + else { /* must be multicast, hardcode a contact list */ #define HELLO_PORT 12345 #define HELLO_GROUP "225.0.0.37" int addr; - (void) inet_aton(HELLO_GROUP, (struct in_addr *)&addr); + (void)inet_aton(HELLO_GROUP, (struct in_addr*)&addr); contact_list = create_attr_list(); add_attr(contact_list, CM_MCAST_ADDR, Attr_Int4, - (attr_value) (long)addr); + (attr_value)(long)addr); add_attr(contact_list, CM_MCAST_PORT, Attr_Int4, - (attr_value) HELLO_PORT); + (attr_value)HELLO_PORT); add_attr(contact_list, CM_TRANSPORT, Attr_String, - (attr_value) "multicast"); - (void) CMinitiate_conn(cm, contact_list); + (attr_value)"multicast"); + (void)CMinitiate_conn(cm, contact_list); string_list = attr_list_to_string(contact_list); free_attr_list(contact_list); - } + } args[last_arg++] = "-size"; sprintf(&size_str[0], "%d", size); args[last_arg++] = size_str; @@ -580,7 +584,8 @@ do_regression_master_test() if (quiet <= 0) { if (forked) { printf("Forked a communication thread\n"); - } else { + } + else { printf("Doing non-threaded communication handling\n"); } } @@ -600,11 +605,11 @@ do_regression_master_test() perror("cwait"); } if (exit_state == 0) { - if (quiet <= 0) + if (quiet <= 0) printf("Subproc exitted\n"); } else { printf("Single remote subproc exit with status %d\n", - exit_state); + exit_state); } #else int result; @@ -622,20 +627,22 @@ do_regression_master_test() if (result == subproc_proc) { if (WIFEXITED(exit_state)) { if (WEXITSTATUS(exit_state) == 0) { - if (quiet <= 0) + if (quiet <= 0) printf("Subproc exited\n"); - } else { + } + else { printf("Single remote subproc exit with status %d\n", - WEXITSTATUS(exit_state)); + WEXITSTATUS(exit_state)); } - } else if (WIFSIGNALED(exit_state)) { + } + else if (WIFSIGNALED(exit_state)) { printf("Single remote subproc died with signal %d\n", - WTERMSIG(exit_state)); + WTERMSIG(exit_state)); } done++; } - } #endif + } if (msg_count != msg_limit) { int i = 10; while ((i >= 0) && (msg_count != msg_limit)) { @@ -646,8 +653,8 @@ do_regression_master_test() free(string_list); CManager_close(cm); if (message_count != expected_count) { - printf ("failure, received %d messages instead of %d\n", - message_count, expected_count); + printf("failure, received %d messages instead of %d\n", + message_count, expected_count); } return !(message_count == expected_count); } diff --git a/tests/evtest.c b/tests/evtest.c index 492ebe87e5..7359753152 100644 --- a/tests/evtest.c +++ b/tests/evtest.c @@ -8,15 +8,18 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include +#include +#include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif typedef struct _complex_rec { @@ -208,7 +211,7 @@ main(int argc, char **argv) #define HELLO_PORT 12345 #define HELLO_GROUP "225.0.0.37" int addr; - (void) inet_aton(HELLO_GROUP, (struct in_addr *)&addr); + (void) inet_pton(AF_INET, HELLO_GROUP, (struct in_addr *)&addr); contact_list = create_attr_list(); add_attr(contact_list, CM_MCAST_ADDR, Attr_Int4, (attr_value) (long)addr); diff --git a/tests/executing_stone_test.c b/tests/executing_stone_test.c index aef65d7fe3..fbca66a21a 100644 --- a/tests/executing_stone_test.c +++ b/tests/executing_stone_test.c @@ -15,9 +15,19 @@ #include #include #include +#ifdef HAVE_ARPA_INET_H #include +#endif #include "evpath.h" +#ifdef HAVE_SYS_WAIT_H #include +#endif +#ifdef HAVE_WINDOWS_H +#include +#define drand48() (((double)rand())/((double)RAND_MAX)) +#define lrand48() rand() +#define srand48(x) +#endif typedef struct _complex_rec { diff --git a/tests/extract_test.c b/tests/extract_test.c index 4724aa05ef..5e036c6657 100644 --- a/tests/extract_test.c +++ b/tests/extract_test.c @@ -8,15 +8,16 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif typedef struct _complex_rec { diff --git a/tests/filter2_test.c b/tests/filter2_test.c index b12e283b16..6fb5f6d73a 100644 --- a/tests/filter2_test.c +++ b/tests/filter2_test.c @@ -20,15 +20,16 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif typedef struct _complex_rec { diff --git a/tests/filter_test.c b/tests/filter_test.c index c3155bebe5..bc680fc189 100644 --- a/tests/filter_test.c +++ b/tests/filter_test.c @@ -11,15 +11,16 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif typedef struct _complex_rec { @@ -179,8 +180,8 @@ main(int argc, char **argv) PARSE_ARGS(); - if (rindex(argv0, '/')) { - char *last_slash = rindex(argv0, '/'); + if (strrchr(argv0, '/')) { + char *last_slash = strrchr(argv0, '/'); *last_slash = 0; EVadd_dll_search_dir(argv0); *last_slash = '/'; diff --git a/tests/http_test.c b/tests/http_test.c index ca82f2e943..f1ced50ea0 100644 --- a/tests/http_test.c +++ b/tests/http_test.c @@ -8,15 +8,16 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif typedef struct _complex_rec { diff --git a/tests/multi_thread.c b/tests/multi_thread.c index 4d59e1eef0..db740c3f0e 100644 --- a/tests/multi_thread.c +++ b/tests/multi_thread.c @@ -8,7 +8,9 @@ #include #include #include +#ifdef HAVE_ARPA_INET_H #include +#endif #include "evpath.h" #ifdef HAVE_WINDOWS_H #include diff --git a/tests/multiq_test.c b/tests/multiq_test.c index 54670da561..163db5290d 100644 --- a/tests/multiq_test.c +++ b/tests/multiq_test.c @@ -12,15 +12,16 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif typedef struct _rec_a { diff --git a/tests/no_type_router_test.c b/tests/no_type_router_test.c index 9fa4b0320c..3a49811360 100644 --- a/tests/no_type_router_test.c +++ b/tests/no_type_router_test.c @@ -11,15 +11,16 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif typedef struct _complex_rec { diff --git a/tests/rawtest.c b/tests/rawtest.c index bf8203db11..0a40e4f819 100644 --- a/tests/rawtest.c +++ b/tests/rawtest.c @@ -8,13 +8,16 @@ #include #include #include +#ifdef HAVE_ARPA_INET_H #include +#endif #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include #endif @@ -145,7 +148,7 @@ simple_handler(CManager cm, void *vevent, void *client_data, attr_list attrs) static FFSContext c = NULL; static int -raw_handler(CManager cm, void *vevent, int len, void *client_data, +raw_handler(CManager cm, void *vevent, size_t len, void *client_data, attr_list attrs) { FFSTypeHandle f; @@ -290,7 +293,7 @@ do_regression_master_test() srand48(1); handle = EValloc_stone(cm); - EVassoc_raw_terminal_action(cm, handle, raw_handler, &message_count); + EVassoc_raw_terminal_action(cm, handle, (EVRawHandlerFunc) raw_handler, &message_count); /* do a local test */ generate_record(&data); diff --git a/tests/rawtest2.c b/tests/rawtest2.c index ce205ee7cb..242ee5065c 100644 --- a/tests/rawtest2.c +++ b/tests/rawtest2.c @@ -8,13 +8,16 @@ #include #include #include +#ifdef HAVE_ARPA_INET_H #include +#endif #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include #endif @@ -153,7 +156,7 @@ simple_handler(CManager cm, void *vevent, void *client_data, attr_list attrs) static FFSContext c = NULL; static int -raw_handler(CManager cm, void *vevent, int len, void *client_data, +raw_handler(CManager cm, void *vevent, size_t len, void *client_data, attr_list attrs) { FFSTypeHandle f; diff --git a/tests/router_test.c b/tests/router_test.c index fa4830b4fb..d99d503971 100644 --- a/tests/router_test.c +++ b/tests/router_test.c @@ -11,15 +11,16 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif typedef struct _complex_rec { diff --git a/tests/router_test2.c b/tests/router_test2.c index ffcf6941c1..43a8919e2a 100644 --- a/tests/router_test2.c +++ b/tests/router_test2.c @@ -8,15 +8,16 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif typedef struct _complex_rec { diff --git a/tests/split_test.c b/tests/split_test.c index 58fca1cb77..6aa2d22abd 100644 --- a/tests/split_test.c +++ b/tests/split_test.c @@ -8,15 +8,16 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif typedef struct _complex_rec { @@ -80,8 +81,7 @@ static FMStructDescRec simple_format_list[] = static void -generate_record(event) -simple_rec_ptr event; +generate_record(simple_rec_ptr event) { long sum = 0; event->integer_field = (int) lrand48() % 100; @@ -108,11 +108,7 @@ int quiet = 1; static int -simple_handler(cm, vevent, client_data, attrs) -CManager cm; -void *vevent; -void *client_data; -attr_list attrs; +simple_handler(CManager cm, void *vevent, void *client_data, attr_list attrs) { simple_rec_ptr event = vevent; long sum = 0, scan_sum = 0; @@ -159,9 +155,7 @@ char *control = NULL; #include "support.c" int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { CManager cm; int regression_master = 1; @@ -218,7 +212,7 @@ char **argv; free_attr_list(contact_list); } stone = EValloc_stone(cm); - EVassoc_terminal_action(cm, stone, simple_format_list, simple_handler, NULL); + EVassoc_terminal_action(cm, stone, simple_format_list, (EVSimpleHandlerFunc)simple_handler, NULL); printf("Contact list \"%d:%s\"\n", stone, string_list); CMsleep(cm, 120); } else { @@ -276,8 +270,7 @@ char **argv; static pid_t subproc_proc = 0; static void -fail_and_die(signal) -int signal; +fail_and_die(int signal) { fprintf(stderr, "split_test failed to complete in reasonable time\n"); if (subproc_proc != 0) { @@ -353,7 +346,7 @@ do_regression_master_test() srand48(1); handle = EValloc_stone(cm); - EVassoc_terminal_action(cm, handle, simple_format_list, simple_handler, &message_count); + EVassoc_terminal_action(cm, handle, simple_format_list, (EVSimpleHandlerFunc)simple_handler, &message_count); args[2] = string_list; args[2] = malloc(10 + strlen(string_list)); diff --git a/tests/submit_test.c b/tests/submit_test.c index 6f73648abb..7d7d933038 100644 --- a/tests/submit_test.c +++ b/tests/submit_test.c @@ -11,15 +11,16 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif typedef struct _complex_rec { diff --git a/tests/support.c b/tests/support.c index c785302788..5a13be452c 100644 --- a/tests/support.c +++ b/tests/support.c @@ -2,6 +2,10 @@ static char *ssh_args[6]={NULL, NULL, NULL, NULL, NULL, NULL}; static char remote_directory[1024] = ""; static char *argv0; static int no_fork = 0; +#ifdef _MSC_VER +#define pid_t intptr_t +#include +#endif static void usage() @@ -34,10 +38,10 @@ usage() printf("Missing --ssh destination\n");\ usage();\ }\ - first_colon = index(argv[2], ':');\ + first_colon = strchr(argv[2], ':');\ if (first_colon) {\ *first_colon = 0;\ - second_colon = index(first_colon+1, ':');\ + second_colon = strchr(first_colon+1, ':');\ } else {\ second_colon = NULL;\ }\ @@ -86,12 +90,20 @@ usage() argc--;\ } +#ifdef _MSC_VER +static int inet_aton(const char* cp, struct in_addr* addr) +{ + addr->s_addr = inet_addr(cp); + return (addr->s_addr == INADDR_NONE) ? 0 : 1; +} +#endif + pid_t run_subprocess(char **args) { char **run_args = args; #ifdef HAVE_WINDOWS_H - int child; + intptr_t child; child = _spawnv(_P_NOWAIT, "./evtest.exe", args); if (child == -1) { printf("failed for evtest\n"); @@ -112,7 +124,7 @@ run_subprocess(char **args) i++; } if (remote_directory[0] != 0) { - if (rindex(argv0, '/')) argv0 = rindex(argv0, '/') + 1; + if (strrchr(argv0, '/')) argv0 = strrchr(argv0, '/') + 1; run_args[i] = malloc(strlen(remote_directory) + strlen(argv0) + 4); strcpy(run_args[i], remote_directory); diff --git a/tests/take_test.c b/tests/take_test.c index 34f03299c0..c3add025ac 100644 --- a/tests/take_test.c +++ b/tests/take_test.c @@ -481,8 +481,8 @@ do_regression_master_test() } done++; } - } #endif + } if (msg_count != MSG_COUNT) { int i = 10; while ((i >= 0) && (msg_count != MSG_COUNT)) { diff --git a/tests/testdll/foo.c b/tests/testdll/foo.c index cdbe1eb813..b22665fe10 100644 --- a/tests/testdll/foo.c +++ b/tests/testdll/foo.c @@ -4,7 +4,12 @@ #if defined (__INTEL_COMPILER) # pragma warning (disable: 1418) #endif - +#ifdef _MSC_VER +#include +#define srand48(s) srand(s) +#define drand48() (rand()*(1./RAND_MAX)) +#define lrand48() ((long long)rand() << 32 | rand()) +#endif typedef struct _complex_rec { double r; double i; diff --git a/tests/thin_client.c b/tests/thin_client.c index de820630a3..9925f641e8 100644 --- a/tests/thin_client.c +++ b/tests/thin_client.c @@ -2,12 +2,21 @@ #include #include #include +#ifndef HAVE_WINDOWS_H #include #include #include #include -#include #include +#else +#include +#include +#define drand48() (((double)rand())/((double)RAND_MAX)) +#define lrand48() rand() +#define srand48(x) +#define close(x) closesocket(x) +#endif +#include #include "ffs.h" typedef struct _simple_rec { @@ -40,7 +49,10 @@ FMStructDescRec thin_formats[] = { {"thin_message", simple_field_list, sizeof(simple_rec), NULL}, {NULL, NULL, 0, NULL}}; -static int do_connection(char* host, int port); +#ifndef _MSC_VER +#define SOCKET int +#endif +static SOCKET do_connection(char* host, int port); static void generate_record (simple_rec_ptr event); int @@ -53,7 +65,7 @@ main(int argc, char **argv) FMFormat ioformat; FMContext fmc; simple_rec rec; - long conn; + SOCKET conn; char *comment = strdup("Stone xxxxx"); if ((argc != 4) || (sscanf(argv[2], "%d", &remote_port) != 1) @@ -69,7 +81,7 @@ main(int argc, char **argv) printf("Connection to %s:%d failed\n", remote_host, remote_port); exit(1); } - out_connection = open_FFSfd((void*)conn, "w"); + out_connection = open_FFSfd((void*)(intptr_t)conn, "w"); sprintf(comment, "Stone %d", stone); write_comment_FFSfile(out_connection, comment); @@ -83,7 +95,7 @@ main(int argc, char **argv) return 0; } -int +SOCKET do_connection(char * remote_host, int port) { struct hostent *host_addr; @@ -91,7 +103,7 @@ do_connection(char * remote_host, int port) memset((char*)&sin, 0, sizeof(sin)); - int conn = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + SOCKET conn = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (conn == -1) return -1; diff --git a/tests/thin_test.c b/tests/thin_test.c index 4e26d090f9..f6a3340d9d 100644 --- a/tests/thin_test.c +++ b/tests/thin_test.c @@ -8,13 +8,16 @@ #include #include #include +#ifdef HAVE_ARPA_INET_H #include +#endif #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include #endif diff --git a/tests/transform_test.c b/tests/transform_test.c index f4b79f9eac..c36a3f014f 100644 --- a/tests/transform_test.c +++ b/tests/transform_test.c @@ -11,15 +11,16 @@ #include #include #include -#include #include "evpath.h" #ifdef HAVE_WINDOWS_H #include #define drand48() (((double)rand())/((double)RAND_MAX)) #define lrand48() rand() #define srand48(x) +#define kill(x,y) TerminateProcess(OpenProcess(0,0,(DWORD)x),y) #else #include +#include #endif typedef struct _complex_rec { @@ -186,7 +187,7 @@ output_handler(CManager cm, void *vevent, void *client_data, attr_list attrs) return 0; } -static int do_regression_master_test(); +static int do_regression_master_test(int do_dll); static int regression = 1; static int repeat_count = 10; static atom_t CM_TRANSPORT; @@ -220,8 +221,8 @@ main(int argc, char **argv) PARSE_ARGS(); - if (rindex(argv0, '/')) { - char *last_slash = rindex(argv0, '/'); + if (strrchr(argv0, '/')) { + char *last_slash = strrchr(argv0, '/'); *last_slash = 0; EVadd_dll_search_dir(argv0); *last_slash = '/'; diff --git a/thin_server.c b/thin_server.c index 965f468266..7384bffaa4 100644 --- a/thin_server.c +++ b/thin_server.c @@ -2,12 +2,22 @@ #include #include #include +#ifdef HAVE_WINSOCK2_H +#include +#include +#define drand48() (((double)rand())/((double)RAND_MAX)) +#define lrand48() rand() +#define srand48(x) +#else #include #include #include #include +#endif #include +#ifdef HAVE_UNISTD_H #include +#endif #include "evpath.h" #include "cm_internal.h" @@ -31,7 +41,7 @@ EVthin_socket_listen(CManager cm, char **hostname_p, int *port_p) unsigned int length; struct sockaddr_in sock_addr; int sock_opt_val = 1; - int conn_sock; + SOCKET conn_sock; int int_port_num = 0; u_short port_num = 0; char host_name[256]; @@ -52,14 +62,14 @@ EVthin_socket_listen(CManager cm, char **hostname_p, int *port_p) return 0; } { - long seedval = time(NULL) + getpid(); + long seedval = (long)time(NULL) + (long)getpid(); /* port num is free. Constrain to range to standards */ int size = high_bound - low_bound; int tries = 30; int result = SOCKET_ERROR; srand48(seedval); while (tries > 0) { - int target = low_bound + size * drand48(); + int target = low_bound + (int)(size * drand48()); sock_addr.sin_port = htons(target); CMtrace_out(cm, CMConnectionVerbose, "CMSocket trying to bind port %d", target); result = bind(conn_sock, (struct sockaddr *) &sock_addr, @@ -105,7 +115,7 @@ EVthin_socket_listen(CManager cm, char **hostname_p, int *port_p) /* set the port num as one we can be contacted at */ CM_fd_add_select(cm, conn_sock, socket_accept_thin_client, - (void *) cm, (void *) (long)conn_sock); + (void *) cm, (void *) (intptr_t)conn_sock); // int_port_num = (unsigned short)(ntohs(sock_addr.sin_port)); @@ -120,7 +130,7 @@ EVthin_socket_listen(CManager cm, char **hostname_p, int *port_p) typedef struct thin_conn { FFSFile ffsfile; - int fd; + SOCKET fd; int target_stone; int format_count; FMStructDescList *format_list; @@ -200,7 +210,7 @@ thin_data_available(void *cmv, void * conn_datav) } case FFSdata: { FFSTypeHandle next_format = FFSnext_type_handle(cd->ffsfile); - int len = FFSnext_data_length(cd->ffsfile); + size_t len = FFSnext_data_length(cd->ffsfile); int format_num = FMformat_index(FMFormat_of_original(next_format)); void *data = malloc(len); FFSread(cd->ffsfile, data); @@ -238,8 +248,8 @@ static void socket_accept_thin_client(void *cmv, void * sockv) { CManager cm = (CManager) cmv; - int conn_sock = (int) (long)sockv; - int sock; + SOCKET conn_sock = (int) (intptr_t)sockv; + SOCKET sock; struct sockaddr sock_addr; unsigned int sock_len = sizeof(sock_addr); int int_port_num; @@ -287,7 +297,7 @@ socket_accept_thin_client(void *cmv, void * sockv) (void) int_port_num; cd = malloc(sizeof(*cd)); memset(cd, 0, sizeof(*cd)); - cd->ffsfile = open_FFSfd((void*)(long)sock, "r"); + cd->ffsfile = open_FFSfd((void*)(intptr_t)sock, "r"); cd->fd = sock; cd->src_list = malloc(sizeof(cd->src_list[0])); cd->src_list[0] = NULL; From 6535ef97f5b422338de9c9e9b2ac12400aece6b2 Mon Sep 17 00:00:00 2001 From: atl Upstream Date: Wed, 7 Jun 2023 16:41:35 -0400 Subject: [PATCH 3/7] atl 2023-06-07 (f3c23577) Code extracted from: https://github.com/GTkorvo/atl.git at commit f3c23577274edec8685bd7cbbeb7eb35aa9f48e9 (master). Upstream Shortlog ----------------- --- atl.h | 10 +++++-- atom.c | 35 ++++++---------------- atom_server.c | 10 ++----- attr.c | 13 ++++---- tclHash.c | 82 +++++++++++---------------------------------------- 5 files changed, 43 insertions(+), 107 deletions(-) diff --git a/atl.h b/atl.h index 4657ed8f48..8b35cf7167 100644 --- a/atl.h +++ b/atl.h @@ -16,6 +16,12 @@ extern "C" { #ifndef _STDINT_H #include #endif +#if defined(_MSC_VER) +#include +typedef SSIZE_T ssize_t; +#else +#include +#endif typedef int atom_t; @@ -117,7 +123,7 @@ extern int set_int_attr (attr_list attrs, atom_t attr_id, int value ); extern int set_long_attr (attr_list attrs, atom_t attr_id, - long value ); + ssize_t value ); extern int set_string_attr (attr_list attrs, atom_t attr_id, char *string ); @@ -150,7 +156,7 @@ extern int query_attr ( attr_list attrs, atom_t attr_id, attr_value_type *val_type_p, attr_value *value_p); extern int get_int_attr ( attr_list attrs, atom_t attr_id, int *value_p); -extern int get_long_attr ( attr_list attrs, atom_t attr_id, long *value_p); +extern int get_long_attr ( attr_list attrs, atom_t attr_id, ssize_t *value_p); extern int get_double_attr ( attr_list attrs, atom_t attr_id, double *value_p); extern int get_float_attr ( attr_list attrs, atom_t attr_id, float *value_p); extern int get_string_attr ( attr_list attrs, atom_t attr_id, char **value_p); diff --git a/atom.c b/atom.c index 1eaf6f7896..7417164309 100644 --- a/atom.c +++ b/atom.c @@ -72,9 +72,7 @@ static int establish_server_connection(atom_server as, int do_fallback); #define O_NONBLOCK 0x80 #endif static void -set_blocking(as, block) -atom_server as; -int block; +set_blocking(atom_server as, int block) { if (block && ((as->flags & O_NONBLOCK) == 0)) { return; /* already blocking */ @@ -109,9 +107,7 @@ int block; } static void -handle_unexpected_msg(as, msg) -atom_server as; -char *msg; +handle_unexpected_msg(atom_server as, char *msg) { switch (msg[0]) { case 'E':{ @@ -167,9 +163,7 @@ char *msg; static int -enter_atom_into_cache(as, msg) -atom_server as; -send_get_atom_msg_ptr msg; +enter_atom_into_cache(atom_server as, send_get_atom_msg_ptr msg) { int new; char *str; @@ -204,10 +198,7 @@ send_get_atom_msg_ptr msg; } void -set_string_and_atom(as, str, atom) -atom_server as; -char *str; -atom_t atom; +set_string_and_atom(atom_server as, char *str, atom_t atom) { send_get_atom_msg tmp_value; Tcl_HashEntry *entry = NULL, *entry2 = NULL; @@ -315,9 +306,7 @@ fill_hostaddr(void *addr, char *hostname) } static int -establish_server_connection(as, do_fallback) -atom_server as; -int do_fallback; +establish_server_connection(atom_server as, int do_fallback) { SOCKET sock; int delay_value = 1; @@ -411,9 +400,7 @@ extern atom_t ATLget_hash(const char *str); extern atom_t -atom_from_string(as, str) -atom_server as; -char *str; +atom_from_string(atom_server as, char *str) { atom_t atom; @@ -426,9 +413,7 @@ char *str; extern char * -string_from_atom(as, atom) -atom_server as; -atom_t atom; +string_from_atom(atom_server as, atom_t atom) { send_get_atom_msg tmp_rec; send_get_atom_msg_ptr stored; @@ -482,8 +467,7 @@ atom_t atom; extern char * -get_server_id(as) -atom_server as; +get_server_id(atom_server as) { return as->server_id; } @@ -615,8 +599,7 @@ free_atom_server(atom_server as) } atom_server -init_atom_server(cache_style) -atom_cache_type cache_style; +init_atom_server(atom_cache_type cache_style) { atom_server as = (atom_server) malloc(sizeof(atom_server_struct)); diff --git a/atom_server.c b/atom_server.c index 787231f1a1..5e2be06fe4 100644 --- a/atom_server.c +++ b/atom_server.c @@ -149,9 +149,7 @@ establish_server_connection() } int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { int sockfd, tcpfd; int quiet = 0; @@ -344,8 +342,7 @@ process_data(char* buf, char *response) } static void -handle_udp_data(sockfd) -int sockfd; +handle_udp_data(int sockfd) { int numbytes; socklen_t addr_len = sizeof(struct sockaddr); @@ -377,8 +374,7 @@ int sockfd; } static void -handle_tcp_data(sockfd) -int sockfd; +handle_tcp_data(int sockfd) { int numbytes; unsigned char len; diff --git a/attr.c b/attr.c index da7ca89cdc..d94064213f 100644 --- a/attr.c +++ b/attr.c @@ -42,7 +42,7 @@ typedef struct attr_union { double d; float f; int i; - long l; + ssize_t l; void *p; attr_opaque o; }u; @@ -165,8 +165,7 @@ add_pattr(attr_list list, atom_t attr_id, attr_value_type val_type, static void -init_global_atom_server(asp) -atom_server *asp; +init_global_atom_server(atom_server *asp) { static int first = 1; if (*asp != NULL) return; @@ -446,7 +445,7 @@ set_float_attr(attr_list list, atom_t attr_id, double fvalue) } extern int -set_long_attr(attr_list list, atom_t attr_id, long lvalue) +set_long_attr(attr_list list, atom_t attr_id, ssize_t lvalue) { attr_value_type t = Attr_Int4; attr_union tmp; @@ -1237,7 +1236,7 @@ get_int_attr(attr_list l, atom_t attr_id, int *valp) *valp = v.u.i; break; case Attr_Int8: - if (sizeof(long) == 8) *valp = v.u.l; + if (sizeof(size_t) == 8) *valp = (int)v.u.l; *valp = v.u.i; break; case Attr_Float16: @@ -1259,7 +1258,7 @@ get_int_attr(attr_list l, atom_t attr_id, int *valp) } int -get_long_attr(attr_list l, atom_t attr_id, long *valp) +get_long_attr(attr_list l, atom_t attr_id, ssize_t *valp) { attr_value_type t; attr_union v; @@ -1308,7 +1307,7 @@ get_double_attr(attr_list l, atom_t attr_id, double *valp) *valp = v.u.i; break; case Attr_Int8: - if (sizeof(long) == 8) *valp = v.u.l; + if (sizeof(ssize_t) == 8) *valp = (double) v.u.l; *valp = v.u.i; break; case Attr_Float16: diff --git a/tclHash.c b/tclHash.c index 0fbe63b8c2..56636eb03b 100644 --- a/tclHash.c +++ b/tclHash.c @@ -94,12 +94,7 @@ static void tcl_panic _ANSI_ARGS_((char *str)); */ void -Tcl_InitHashTable(tablePtr, keyType) -register Tcl_HashTable *tablePtr; /* Pointer to table record, which - * * is supplied by the caller. */ -int keyType; /* Type of keys to use in table: * - * TCL_STRING_KEYS, TCL_ONE_WORD_KEYS, * - * or an integer >= 2. */ +Tcl_InitHashTable(register Tcl_HashTable *tablePtr, int keyType) { tablePtr->buckets = tablePtr->staticBuckets; tablePtr->staticBuckets[0] = tablePtr->staticBuckets[1] = 0; @@ -142,8 +137,7 @@ int keyType; /* Type of keys to use in table: * */ void -Tcl_DeleteHashEntry(entryPtr) -Tcl_HashEntry *entryPtr; +Tcl_DeleteHashEntry(Tcl_HashEntry *entryPtr) { register Tcl_HashEntry *prevPtr; @@ -182,8 +176,7 @@ Tcl_HashEntry *entryPtr; */ void -Tcl_DeleteHashTable(tablePtr) -register Tcl_HashTable *tablePtr; /* Table to delete. */ +Tcl_DeleteHashTable(register Tcl_HashTable *tablePtr) { register Tcl_HashEntry *hPtr, *nextPtr; int i; @@ -240,10 +233,7 @@ register Tcl_HashTable *tablePtr; /* Table to delete. */ */ Tcl_HashEntry * -Tcl_FirstHashEntry(tablePtr, searchPtr) -Tcl_HashTable *tablePtr; /* Table to search. */ -Tcl_HashSearch *searchPtr; /* Place to store information about * - * progress through the table. */ +Tcl_FirstHashEntry(Tcl_HashTable *tablePtr, Tcl_HashSearch *searchPtr) { searchPtr->tablePtr = tablePtr; searchPtr->nextIndex = 0; @@ -271,12 +261,7 @@ Tcl_HashSearch *searchPtr; /* Place to store information about * */ Tcl_HashEntry * -Tcl_NextHashEntry(searchPtr) -register Tcl_HashSearch *searchPtr; /* Place to store information - * about * progress through the - * table. Must * have been - * initialized by calling * - * Tcl_FirstHashEntry. */ +Tcl_NextHashEntry(register Tcl_HashSearch *searchPtr) { Tcl_HashEntry *hPtr; @@ -313,8 +298,7 @@ register Tcl_HashSearch *searchPtr; /* Place to store information */ char * -Tcl_HashStats(tablePtr) -Tcl_HashTable *tablePtr; /* Table for which to produce stats. */ +Tcl_HashStats(Tcl_HashTable *tablePtr) { #define NUM_COUNTERS 10 int count[NUM_COUNTERS], overflow, i, j; @@ -384,9 +368,7 @@ Tcl_HashTable *tablePtr; /* Table for which to produce stats. */ */ static unsigned int -HashString(string) -register char *string; /* String from which to compute hash - * value. */ +HashString(register char *string) { register unsigned int result; register int c; @@ -438,9 +420,7 @@ register char *string; /* String from which to compute hash */ static Tcl_HashEntry * -StringFind(tablePtr, key) -Tcl_HashTable *tablePtr; /* Table in which to lookup entry. */ -char *key; /* Key to use to find matching entry. */ +StringFind(Tcl_HashTable *tablePtr, char *key) { register Tcl_HashEntry *hPtr; register char *p1, *p2; @@ -488,12 +468,7 @@ char *key; /* Key to use to find matching entry. */ */ static Tcl_HashEntry * -StringCreate(tablePtr, key, newPtr) -Tcl_HashTable *tablePtr; /* Table in which to lookup entry. */ -char *key; /* Key to use to find or create matching * - * entry. */ -int *newPtr; /* Store info here telling whether a new * - * entry was created. */ +StringCreate(Tcl_HashTable *tablePtr, char *key, int *newPtr) { register Tcl_HashEntry *hPtr; register char *p1, *p2; @@ -563,9 +538,7 @@ int *newPtr; /* Store info here telling whether a new * */ static Tcl_HashEntry * -OneWordFind(tablePtr, key) -Tcl_HashTable *tablePtr; /* Table in which to lookup entry. */ -register char *key; /* Key to use to find matching entry. */ +OneWordFind(Tcl_HashTable *tablePtr, register char *key) { register Tcl_HashEntry *hPtr; int index; @@ -607,12 +580,7 @@ register char *key; /* Key to use to find matching entry. */ */ static Tcl_HashEntry * -OneWordCreate(tablePtr, key, newPtr) -Tcl_HashTable *tablePtr; /* Table in which to lookup entry. */ -register char *key; /* Key to use to find or create matching * - * entry. */ -int *newPtr; /* Store info here telling whether a new * - * entry was created. */ +OneWordCreate(Tcl_HashTable *tablePtr, register char *key, int *newPtr) { register Tcl_HashEntry *hPtr; int index; @@ -675,9 +643,7 @@ int *newPtr; /* Store info here telling whether a new * */ static Tcl_HashEntry * -ArrayFind(tablePtr, key) -Tcl_HashTable *tablePtr; /* Table in which to lookup entry. */ -char *key; /* Key to use to find matching entry. */ +ArrayFind(Tcl_HashTable *tablePtr, char *key) { register Tcl_HashEntry *hPtr; int *arrayPtr = (int *) key; @@ -731,12 +697,7 @@ char *key; /* Key to use to find matching entry. */ */ static Tcl_HashEntry * -ArrayCreate(tablePtr, key, newPtr) -Tcl_HashTable *tablePtr; /* Table in which to lookup entry. */ -register char *key; /* Key to use to find or create matching * - * entry. */ -int *newPtr; /* Store info here telling whether a new * - * entry was created. */ +ArrayCreate(Tcl_HashTable *tablePtr, register char *key, int *newPtr) { register Tcl_HashEntry *hPtr; int *arrayPtr = (int *) key; @@ -816,9 +777,7 @@ int *newPtr; /* Store info here telling whether a new * /* ARGSUSED */ static Tcl_HashEntry * -BogusFind(tablePtr, key) -Tcl_HashTable *tablePtr; /* Table in which to lookup entry. */ -char *key; /* Key to use to find matching entry. */ +BogusFind(Tcl_HashTable *tablePtr, char *key) { tcl_panic("called Tcl_FindHashEntry on deleted table"); return NULL; @@ -844,12 +803,7 @@ char *key; /* Key to use to find matching entry. */ /* ARGSUSED */ static Tcl_HashEntry * -BogusCreate(tablePtr, key, newPtr) -Tcl_HashTable *tablePtr; /* Table in which to lookup entry. */ -char *key; /* Key to use to find or create matching * - * entry. */ -int *newPtr; /* Store info here telling whether a new * - * entry was created. */ +BogusCreate(Tcl_HashTable *tablePtr, char *key, int *newPtr) { tcl_panic("called Tcl_CreateHashEntry on deleted table"); return NULL; @@ -876,8 +830,7 @@ int *newPtr; /* Store info here telling whether a new * */ static void -RebuildTable(tablePtr) -register Tcl_HashTable *tablePtr; /* Table to enlarge. */ +RebuildTable(register Tcl_HashTable *tablePtr) { int oldSize, count, index; Tcl_HashEntry **oldBuckets; @@ -940,8 +893,7 @@ register Tcl_HashTable *tablePtr; /* Table to enlarge. */ } static void -tcl_panic(str) -char *str; +tcl_panic(char *str) { fprintf(stderr, "Hash panic: %s\n", str); exit(1); From 1e45542d2f841243a0837da6ccf161c71ce16dc9 Mon Sep 17 00:00:00 2001 From: ffs Upstream Date: Tue, 6 Jun 2023 17:26:10 -0400 Subject: [PATCH 4/7] ffs 2023-06-06 (46d79432) Code extracted from: https://github.com/GTkorvo/ffs.git at commit 46d79432dc67ee91a56ec2acbdc09624b3e4bd08 (master). Upstream Shortlog ----------------- --- CMakeLists.txt | 64 +- cod/cg.c | 64 +- cod/cod.h | 77 +- cod/cod.l | 17 +- cod/cod.y | 149 +- cod/pregen_source/Linux/cod.tab.c | 563 ++-- cod/pregen_source/Linux/cod.y | 161 +- cod/pregen_source/Windows/cod.l | 17 +- cod/pregen_source/Windows/cod.tab.c | 4571 +++++++++++++-------------- cod/pregen_source/Windows/cod.y | 161 +- cod/pregen_source/Windows/lex.yy.c | 688 ++-- cod/standard.c | 189 +- cod/struct.pl | 2 +- cod/tests/atl_test.c | 19 +- cod/tests/compound_assignment.c | 27 +- cod/tests/control.c | 55 +- cod/tests/data_funcs.c | 17 +- cod/tests/data_funcs.h | 3 + cod/tests/general.ops | 27 +- cod/tests/gray.c | 9 +- cod/tests/mix.c | 1 + cod/tests/strings.c | 11 +- cod/tests/structs.c | 17 +- cod/tests/t1.c | 42 +- cod/tests/t10.c | 51 +- cod/tests/t11.c | 1 + cod/tests/t12.c | 13 +- cod/tests/t2.c | 27 +- cod/tests/t3.c | 51 +- cod/tests/t4.c | 5 +- cod/tests/t5.c | 5 +- cod/tests/t6.c | 5 +- cod/tests/t7.c | 17 +- cod/tests/t8.c | 49 +- cod/tests/t9.c | 5 +- cod/tests/time.c | 52 +- cod/tests/xform.c | 1 + config.h.cmake | 3 + ffs/evol.c | 23 +- ffs/ffs.c | 186 +- ffs/ffs.h.in | 96 +- ffs/ffs_conv.c | 349 +- ffs/ffs_file.c | 140 +- ffs/ffs_formats.c | 11 +- ffs/ffs_gen.c | 125 +- ffs/ffs_gen.h | 12 +- ffs/ffs_internal.h | 24 +- ffs/ffs_marshal.c | 14 +- ffs/ffs_marshal.h | 2 +- ffs/nt_io.c | 352 --- ffs/progs/FFScp.c | 4 +- ffs/progs/FFSdump.c | 4 +- ffs/progs/FFSsort.c | 4 +- ffs/tests/adios2_bug.c | 2 +- ffs/tests/context_test.c | 118 +- ffs/tests/context_test2.c | 76 +- ffs/tests/ffs_file_test.c | 52 +- ffs/tests/ffs_index_test.c | 52 +- ffs/tests/ffs_write.c | 38 +- ffs/tests/fortran_test.c | 71 +- ffs/tests/get_set_test.c | 4 +- ffs/tests/marshal_test.c | 2 + ffs/tests/marshal_test2.c | 2 + ffs/tests/no_leaf_test.c | 12 +- ffs/tests/test_file_unique.c | 4 +- ffs/tests/test_funcs.c | 39 +- ffs/tests/test_funcs.h | 9 + ffs/unix_io.c | 284 -- fm/fm.h | 151 +- fm/fm_dump.c | 128 +- fm/fm_formats.c | 435 +-- fm/fm_get.c | 204 +- fm/fm_internal.h | 43 +- {ffs => fm}/io_interface.h | 46 +- fm/lookup3.c | 2 + fm/nt_io.c | 197 +- fm/null_io.c | 30 +- fm/progs/format_cmd.c | 16 +- fm/progs/format_dump.c | 13 +- fm/progs/format_info.c | 4 +- fm/progs/format_server.c | 7 +- fm/progs/server.c | 129 +- fm/server_acts.c | 32 +- fm/tests/align_test.c | 4 +- fm/tests/compat_test.c | 6 +- fm/tests/format_test.c | 47 +- fm/tests/scale_test.c | 16 +- fm/tests/self_format_test.c | 38 +- fm/tests/test_funcs.c | 45 +- fm/tests/test_funcs.h | 4 + fm/unix_io.c | 170 +- fm/xml.c | 161 +- version.c | 2 +- 93 files changed, 5071 insertions(+), 6206 deletions(-) delete mode 100755 ffs/nt_io.c delete mode 100755 ffs/unix_io.c rename {ffs => fm}/io_interface.h (62%) mode change 100755 => 100644 diff --git a/CMakeLists.txt b/CMakeLists.txt index 17643dc1b3..b426801a7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ if(POLICY CMP0074) cmake_policy(SET CMP0074 NEW) endif() -project(FFS VERSION 2.0.0) +project(FFS VERSION 3.0.0) # Some boilerplate to setup nice output directories include(GNUInstallDirs) @@ -20,6 +20,7 @@ else() endif() mark_as_advanced(CMAKE_INSTALL_CMAKEDIR) +list(INSERT CMAKE_PREFIX_PATH 0 ${CMAKE_INSTALL_PREFIX}) list(INSERT CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake) if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY @@ -54,6 +55,23 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE RelWithDebInfo) endif() +if(WIN32) + # Automagic to do the DLL / LIB song and dance + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) + + # Silence MSVC warnings + if(CMAKE_C_COMPILER_ID MATCHES "MSVC" OR + CMAKE_C_SIMULATE_ID MATCHES "MSVC") + add_definitions( + -D_CRT_SECURE_NO_DEPRECATE + -D_CRT_SECURE_NO_WARNINGS + -D_SCL_SECURE_NO_DEPRECATE + -D_WINSOCK_DEPRECATED_NO_WARNINGS + -D_CRT_NONSTDC_NO_DEPRECATE) + set (MSVC_PERL_FLAGS "-msvc-long") + endif() +endif() + include(CMakeDependentOption) # Setup shared library defaults. If explicitly specified somehow, then default @@ -64,6 +82,19 @@ cmake_dependent_option(BUILD_SHARED_LIBS "Build shared libraries (so/dylib/dll)." ${SHARED_LIBS_SUPPORTED} "SHARED_LIBS_SUPPORTED" OFF) mark_as_advanced(BUILD_SHARED_LIBS) +if(MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS -DFFS_SRC) +endif() + +# Default to a RelWithDebInfo build if not specified +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE RelWithDebInfo) +endif() + +set(TARGET_DEP_INC) +set(TARGET_DEP_LIBS) +set(PKG_DEP_PKG) +set(PKG_DEP_LIBS) include(CheckFunctionExists) include(CheckIncludeFiles) @@ -88,19 +119,25 @@ if(NOT (DEFINED NO_SOCKETS)) set(NO_SOCKETS TRUE) endif() endif() -if(NO_SOCKETS) +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(WINDOWS TRUE) +endif() + +if(NO_SOCKETS AND !WINDOWS) set(FM_SOCKET_IO null_io.c) -elseif(WIN32) - set(FM_SOCKET_IO server_acts.c nt_io.c) +elseif(WINDOWS) + set(FM_SOCKET_IO "server_acts.c;nt_io.c") + set(FFS_FILE_IO nt_io.c) else() - set(FM_SOCKET_IO server_acts.c unix_io.c) + set(FM_SOCKET_IO "server_acts.c;unix_io.c") + set(FFS_FILE_IO unix_io.c) endif() set(FM_SRC_LIST fm_formats.c fm_dump.c lookup3.c string_conversion.c fm_get.c xml.c - ${FM_SOCKET_IO}) + ${FM_SOCKET_IO} ${FFS_FILE_IO}) foreach(FM_SRC ${FM_SRC_LIST}) - list(APPEND FM_MASTER_SRC_LIST fm/${FM_SRC}) + list(APPEND FM_MASTER_SRC_LIST fm/${FM_SRC} ) endforeach() set(COD_SRC_LIST cg.c standard.c) @@ -109,7 +146,7 @@ foreach(COD_SRC ${COD_SRC_LIST}) endforeach() set(FFS_SRC_LIST - ffs.c ffs_formats.c ffs_conv.c ffs_gen.c ffs_file.c unix_io.c evol.c + ffs.c ffs_formats.c ffs_conv.c ffs_gen.c ffs_file.c evol.c ffs_marshal.c) foreach(FFS_SRC ${FFS_SRC_LIST}) list(APPEND FFS_MASTER_SRC_LIST ffs/${FFS_SRC}) @@ -154,7 +191,7 @@ add_custom_target(generated DEPENDS cod_node.c ${BISON_CODParser_OUTPUT_SOURCE}) list(APPEND COD_MASTER_SRC_LIST ${BISON_CODParser_OUTPUT_SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/cod_node.c) - + list(APPEND FFS_MASTER_SRC_LIST ${FM_MASTER_SRC_LIST} ${COD_MASTER_SRC_LIST}) set(FFS_LIBRARY_PREFIX "" CACHE STRING @@ -179,6 +216,9 @@ if(SHARED_LIBS_SUPPORTED) else() set(NO_DYNAMIC_LINKING TRUE) endif() +#if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(NO_DYNAMIC_LINKING TRUE) +#endif() target_include_directories(ffs PUBLIC $ @@ -189,7 +229,7 @@ target_include_directories(ffs PUBLIC $ $) -find_package(dill 2.3.1 QUIET) +find_package(dill 3.0.0) option(FFS_USE_DILL "Enable Dill code generation" ${DILL_FOUND}) @@ -231,7 +271,7 @@ CHECK_INCLUDE_FILE(winsock.h HAVE_WINSOCK_H) if(SIZEOF_SIZE_T EQUAL SIZEOF_INT) set(UIO_SIZE_T_TYPE "unsigned int") else() - set(UIO_SIZE_T_TYPE "unsigned long") + set(UIO_SIZE_T_TYPE "size_t") endif() configure_file(ffs/ffs.h.in ffs/ffs.h @ONLY) @@ -260,7 +300,7 @@ if(NOT HAS_IOV_BASE_IOVEC) endif() if(NOT DEFINED FORMAT_SERVER_HOST) - set(FORMAT_SERVER_HOST "eisenhauer.dyndns.org") + set(FORMAT_SERVER_HOST "formathost.cercs.gatech.edu") endif() if(NOT DEFINED FORMAT_SERVICE_DOMAIN) diff --git a/cod/cg.c b/cod/cg.c index bfbf94812e..1b41d8d3af 100644 --- a/cod/cg.c +++ b/cod/cg.c @@ -64,6 +64,8 @@ enum { #if defined(_MSC_VER) #define strdup _strdup +#include +typedef SSIZE_T ssize_t; #endif typedef struct _opnd_enc_info { @@ -339,15 +341,15 @@ generate_arg_str(sm_ref net) arg_count = 0; } for (i = 0; i < arg_count ; i++) { - int len; + size_t len; if (arg_types[i] == -1) { printf("Arg %d not declared\n", i); return arg_str; } len = strlen(arg_str) + 8; arg_str = realloc(arg_str, len); - strcat(arg_str, "%"); - strcat(arg_str, arg_type_str[arg_types[i]]); + strncat(arg_str, "%", len); + strncat(arg_str, arg_type_str[arg_types[i]], len); } free(arg_types); return arg_str; @@ -432,11 +434,7 @@ int cg_get_size(dill_stream s, sm_ref node) static void cg_generate_static_block(dill_stream s, cod_code descr); extern void * -cod_cg_net(net, ret_type, offset_p, code_descriptor) -sm_ref net; -int ret_type; -unsigned int *offset_p; -cod_code code_descriptor; +cod_cg_net(sm_ref net, int ret_type, unsigned int *offset_p, cod_code code_descriptor) { void *init_func; static int debug_cg = -1; @@ -446,7 +444,7 @@ cod_code code_descriptor; dill_exec_handle handle; #endif if (debug_cg == -1) { - debug_cg = (int)(long)(getenv("COD_DEBUG")); + debug_cg = (int)(intptr_t)(getenv("COD_DEBUG")); } #if defined(HAVE_DILL_H) arg_str = generate_arg_str(net); @@ -853,7 +851,7 @@ evaluate_simple_init_and_assign(dill_stream s, sm_ref init, int cg_type, void *v assert(FALSE); } } else { - long l; + ssize_t l; char *val = const_val->node.constant.const_val; if (const_val->node.constant.token == character_constant) { if (*val == 'L') val++ ; @@ -866,11 +864,11 @@ evaluate_simple_init_and_assign(dill_stream s, sm_ref init, int cg_type, void *v val++; switch(*val) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': - if (sscanf(val, "%lo", &l) != 1) + if (sscanf(val, "%zo", &l) != 1) printf("octal char sscanf failed %s\n", val); break; case 'x': - if (sscanf(val+1, "%lx", &l) != 1) + if (sscanf(val+1, "%zx", &l) != 1) printf("hex char sscanf failed, %s\n", val); break; case '\\': @@ -912,14 +910,14 @@ evaluate_simple_init_and_assign(dill_stream s, sm_ref init, int cg_type, void *v /* hex or octal */ if (val[1] == 'x') { /* hex */ - if (sscanf(val+2, "%lx", &l) != 1) + if (sscanf(val+2, "%zx", &l) != 1) printf("sscanf failed\n"); } else { - if (sscanf(val, "%lo", &l) != 1) + if (sscanf(val, "%zo", &l) != 1) printf("sscanf failed\n"); } } else { - if (sscanf(val, "%ld", &l) != 1) + if (sscanf(val, "%zd", &l) != 1) printf("sscanf failed\n"); } } @@ -937,16 +935,16 @@ evaluate_simple_init_and_assign(dill_stream s, sm_ref init, int cg_type, void *v *(unsigned short *)(var_base) = (unsigned short)l; break; case DILL_I: - *(int *)(var_base) = l; + *(int *)(var_base) = (int)l; break; case DILL_U: - *(unsigned int *)(var_base) = l; + *(unsigned int *)(var_base) = (unsigned int)l; break; case DILL_L: - *(long *)(var_base) = l; + *(ssize_t *)(var_base) = l; break; case DILL_UL: - *(unsigned long *)(var_base) = l; + *(size_t *)(var_base) = l; break; case DILL_P: *(void **)(var_base) = (void*)l; @@ -1004,14 +1002,14 @@ cg_decl(dill_stream s, sm_ref decl, cod_code descr) if (decl->node.declaration.static_var && !is_block_type) { /* do SIMPLE statics */ decl->node.declaration.cg_address = - (void*)(long)descr->static_size_required; + (void*)(ssize_t)descr->static_size_required; descr->static_size_required += 8; if (descr->data == NULL) { descr->data = malloc(descr->static_size_required); } else { descr->data = realloc(descr->data, descr->static_size_required); } - var_base = (char*)descr->data + (long)decl->node.declaration.cg_address; + var_base = (char*)descr->data + (intptr_t)decl->node.declaration.cg_address; } if (var_base) { if (decl->node.declaration.init_value == NULL) { @@ -1074,16 +1072,16 @@ cg_decl(dill_stream s, sm_ref decl, cod_code descr) /* array */ if (decl->node.declaration.static_var) { decl->node.declaration.cg_address = - (void*)(long)descr->static_size_required; + (void*)(ssize_t)descr->static_size_required; descr->static_size_required += ctype->node.array_type_decl.cg_static_size * ctype->node.array_type_decl.cg_element_size; if (descr->data == NULL) { descr->data = malloc(descr->static_size_required); } else { descr->data = realloc(descr->data, descr->static_size_required); } - var_base = (char*)descr->data + (long)decl->node.declaration.cg_address; + var_base = (char*)descr->data + (intptr_t)decl->node.declaration.cg_address; lvar = dill_getreg(s, DILL_P); - dill_addpi(s, lvar, cg_get_static_block(s, descr), (long)decl->node.declaration.cg_address); /* op_i_addpi */ + dill_addpi(s, lvar, cg_get_static_block(s, descr), (intptr_t)decl->node.declaration.cg_address); /* op_i_addpi */ } else { dill_reg block = dill_getvblock(s, ctype->node.array_type_decl.cg_static_size * ctype->node.array_type_decl.cg_element_size); @@ -1093,14 +1091,14 @@ cg_decl(dill_stream s, sm_ref decl, cod_code descr) } else if (!is_block_type) { if (decl->node.declaration.static_var) { decl->node.declaration.cg_address = - (void*)(long)descr->static_size_required; + (void*)(ssize_t)descr->static_size_required; descr->static_size_required += cg_get_size(s, decl); if (descr->data == NULL) { descr->data = malloc(descr->static_size_required); } else { descr->data = realloc(descr->data, descr->static_size_required); } - var_base = (char*)descr->data + (long)decl->node.declaration.cg_address; + var_base = (char*)descr->data + (intptr_t)decl->node.declaration.cg_address; } else if ((decl->node.declaration.addr_taken) || (ctype && (ctype->node_type == cod_struct_type_decl))) { /* make sure it's in memory if its address is taken */ @@ -1115,14 +1113,14 @@ cg_decl(dill_stream s, sm_ref decl, cod_code descr) assert(struct_type->node_type == cod_struct_type_decl); if (decl->node.declaration.static_var) { decl->node.declaration.cg_address = - (void*)(long)descr->static_size_required; + (void*)(ssize_t)descr->static_size_required; descr->static_size_required += cg_get_size(s, decl); if (descr->data == NULL) { descr->data = malloc(descr->static_size_required); } else { descr->data = realloc(descr->data, descr->static_size_required); } - var_base = (char*)descr->data + (long)decl->node.declaration.cg_address; + var_base = (char*)descr->data + (intptr_t)decl->node.declaration.cg_address; } else { if ((struct_type->node.struct_type_decl.cg_size % dill_type_align(s, DILL_D)) != 0) { int struct_size = struct_type->node.struct_type_decl.cg_size; @@ -2415,7 +2413,7 @@ cod_expand_dyn_array(void *base_addr, long new_size, long old_size, long struct_ static int debug_cg = -1; if (debug_cg == -1) { - debug_cg = (int)(long)(getenv("COD_DEBUG")); + debug_cg = (int)(intptr_t)(getenv("COD_DEBUG")); } if (debug_cg) { printf("cod_expand_dyn_array, base_addr %p, old_base %p, new_size %ld, old_size %ld, struct_size %ld\n", @@ -2616,7 +2614,7 @@ cg_expr(dill_stream s, sm_ref expr, int need_assignable, cod_code descr) dill_reg static_block; if (expr->node.declaration.static_var) { static_block = cg_get_static_block(s, descr); - dill_addpi(s, lvar, static_block, (long)expr->node.declaration.cg_address); /* op_i_addpi */ + dill_addpi(s, lvar, static_block, (intptr_t)expr->node.declaration.cg_address); /* op_i_addpi */ } else { dill_setp(s, lvar, expr->node.declaration.cg_address); /* op_i_addpi */ } @@ -3904,7 +3902,7 @@ cod_create_exec_context(cod_code code) void *block = malloc(code->static_size_required); /* copy initialized data */ memcpy(block, code->data, code->static_size_required); - dill_assoc_client_data(cod_ctx->ec, 0x23234, (long)block); + dill_assoc_client_data(cod_ctx->ec, 0x23234, (intptr_t)block); cod_ctx->static_data = block; } else { cod_ctx->static_data = NULL; @@ -3948,12 +3946,12 @@ extern int cod_install_state(cod_exec_context ec, void *state, int length) } extern void -cod_assoc_client_data(cod_exec_context ec, int key, long value) +cod_assoc_client_data(cod_exec_context ec, int key, intptr_t value) { dill_assoc_client_data(ec->ec, key, value); } -extern long +extern intptr_t cod_get_client_data(cod_exec_context ec, int key) { return dill_get_client_data(ec->ec, key); diff --git a/cod/cod.h b/cod/cod.h index c92417ce5d..0a866ea8e8 100644 --- a/cod/cod.h +++ b/cod/cod.h @@ -6,16 +6,15 @@ extern "C" { #endif -#if defined(FUNCPROTO) || defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) -#ifndef ARGS -#define ARGS(args) args -#endif +#ifndef FFS_DECL_SPEC +#if defined(_MSC_VER) && !defined(FFS_SRC) +#define FFS_DECLSPEC __declspec(dllimport) #else -#ifndef ARGS -#define ARGS(args) (/*args*/) +#define FFS_DECLSPEC #endif #endif +#include /*! * cod_parse_context is the basic handle controlling generation of @@ -113,7 +112,7 @@ typedef cod_extern_entry *cod_extern_list; * \return Will return a new initialized cod_parse_context unless there is * no available memory. */ -extern cod_parse_context new_cod_parse_context(void); +extern FFS_DECLSPEC cod_parse_context new_cod_parse_context(void); /*! * Free a handle to an cod_parse_context. @@ -122,7 +121,7 @@ extern cod_parse_context new_cod_parse_context(void); * Calling this routine frees all memory associated with the parse context, * but not that of code that has been generated from this context. */ -extern void cod_free_parse_context ARGS((cod_parse_context context)); +extern FFS_DECLSPEC void cod_free_parse_context(cod_parse_context context); /*! * Associate a set of "name, external address" pairs with a parse context @@ -136,8 +135,8 @@ extern void cod_free_parse_context ARGS((cod_parse_context context)); * \param externs the list of "name, external address" pairs to be * associated. This list should be terminated with a {NULL, 0} pair. */ -extern void cod_assoc_externs ARGS((cod_parse_context context, - cod_extern_list externs)); +extern FFS_DECLSPEC void cod_assoc_externs(cod_parse_context context, + cod_extern_list externs); /*! * \brief This is used to establish the parameter profile and return type @@ -152,7 +151,7 @@ extern void cod_assoc_externs ARGS((cod_parse_context context, * "int proc(double d, int *i)" * */ -extern void +extern FFS_DECLSPEC void cod_subroutine_declaration(const char *decl, cod_parse_context context); /*! @@ -164,7 +163,7 @@ cod_subroutine_declaration(const char *decl, cod_parse_context context); * the structure. * \param context the context in which the type is to be made available. */ -extern void cod_add_simple_struct_type(const char *name, FMFieldList field_list, +extern FFS_DECLSPEC void cod_add_simple_struct_type(const char *name, FMFieldList field_list, cod_parse_context context); /*! @@ -175,7 +174,7 @@ extern void cod_add_simple_struct_type(const char *name, FMFieldList field_list, * the structures. * \param context the context in which the type is to be made available. */ -extern void cod_add_struct_type(FMStructDescList format_list, +extern FFS_DECLSPEC void cod_add_struct_type(FMStructDescList format_list, cod_parse_context context); /*! @@ -186,7 +185,7 @@ extern void cod_add_struct_type(FMStructDescList format_list, * \param param_num the numeral of the new parameter (0 is first) * \param context the context in which the subroutine is being declared. */ -extern void +extern FFS_DECLSPEC void cod_add_param(const char *id, const char *typ, int param_num, cod_parse_context context); @@ -200,7 +199,7 @@ cod_add_param(const char *id, const char *typ, int param_num, * \param context the context in which the subroutine is being declared. */ #ifdef __FM__ -extern void +extern FFS_DECLSPEC void cod_add_encoded_param(const char *id, char *data, int param_num, FMContext c, cod_parse_context context); #endif @@ -211,7 +210,7 @@ cod_add_encoded_param(const char *id, char *data, int param_num, * \param typ the data type of the return value. * \param context the context in which the subroutine is being declared. */ -extern void +extern FFS_DECLSPEC void cod_set_return_type(char *typ, cod_parse_context context); /*! @@ -247,7 +246,7 @@ typedef struct _cod_code_struct { * \param code the string representing the function body. * \param context the context in which the function body is to be generated. */ -cod_code cod_code_gen ARGS((char *code, cod_parse_context context)); +cod_code cod_code_gen(char *code, cod_parse_context context); /*! * perform syntactical and semantic checking of a function body without @@ -256,7 +255,7 @@ cod_code cod_code_gen ARGS((char *code, cod_parse_context context)); * \param code the string representing the function body. * \param context the context in which the function body is to be checked. */ -int cod_code_verify ARGS((char *code, cod_parse_context context)); +int cod_code_verify(char *code, cod_parse_context context); /*! * Free all resources associated with the generated code associated with the @@ -264,7 +263,7 @@ int cod_code_verify ARGS((char *code, cod_parse_context context)); * * \param code the handle to the resources that will be free'd. */ -extern void cod_code_free ARGS((cod_code code)); +extern FFS_DECLSPEC void cod_code_free(cod_code code); /*! * create an execution context associated with a code block @@ -272,7 +271,7 @@ extern void cod_code_free ARGS((cod_code code)); * \param code the handle to the code bloc * \return the created execution context */ -extern cod_exec_context cod_create_exec_context ARGS((cod_code code)); +extern FFS_DECLSPEC cod_exec_context cod_create_exec_context(cod_code code); /*! * Free all resources associated with the generated code associated with the @@ -280,7 +279,7 @@ extern cod_exec_context cod_create_exec_context ARGS((cod_code code)); * * \param code the handle to the resources that will be free'd. */ -extern void cod_exec_context_free ARGS((cod_exec_context ec)); +extern FFS_DECLSPEC void cod_exec_context_free(cod_exec_context ec); /*! * Associate application-level data with an execution context. This is @@ -292,7 +291,7 @@ extern void cod_exec_context_free ARGS((cod_exec_context ec)); * \param key the value that will serve as a key to retrieve the data * \param value the 'long' data that will be associated with the key */ -extern void cod_assoc_client_data(cod_exec_context ec, int key, long value); +extern FFS_DECLSPEC void cod_assoc_client_data(cod_exec_context ec, int key, intptr_t value); /*! * Retrieve application-level data with an execution context. This is @@ -306,7 +305,7 @@ extern void cod_assoc_client_data(cod_exec_context ec, int key, long value); * \param key the value that will serve as a key to retrieve the data * \return the 'long' data that was associated with the key */ -extern long cod_get_client_data(cod_exec_context ec, int key); +extern FFS_DECLSPEC intptr_t cod_get_client_data(cod_exec_context ec, int key); /*! * Extract static state from an execution context. @@ -316,7 +315,7 @@ extern long cod_get_client_data(cod_exec_context ec, int key); * the length of the returned state block * \return a pointer to the extracted state */ -extern void *cod_extract_state(cod_exec_context ec, int *length_p); +extern FFS_DECLSPEC void *cod_extract_state(cod_exec_context ec, int *length_p); /*! * Install static state into an execution context. @@ -326,7 +325,7 @@ extern void *cod_extract_state(cod_exec_context ec, int *length_p); * \param state_size the size of the state block * \return 1 on success, 0 on failure */ -extern int cod_install_state(cod_exec_context ec, void *state, int length); +extern FFS_DECLSPEC int cod_install_state(cod_exec_context ec, void *state, int length); /*! * \brief This parses a string to determine what external @@ -338,7 +337,7 @@ extern int cod_install_state(cod_exec_context ec, void *state, int length); * \param context The parse context in which the declarations should be * visible. */ -int cod_parse_for_context ARGS((char *code, cod_parse_context context)); +int cod_parse_for_context(char *code, cod_parse_context context); /*! * \brief This parses a string to setup global variables that are @@ -350,14 +349,14 @@ int cod_parse_for_context ARGS((char *code, cod_parse_context context)); * \param context The parse context in which the declarations should be * visible. */ -int cod_parse_for_globals ARGS((char *code, cod_parse_context context)); +int cod_parse_for_globals(char *code, cod_parse_context context); /*! * Duplicate a handle to an cod_parse_context. * * \param context the cod_parse_context to be duplicated. */ -extern cod_parse_context cod_copy_context ARGS((cod_parse_context context)); +extern FFS_DECLSPEC cod_parse_context cod_copy_context(cod_parse_context context); /*! * Duplicate a handle to an cod_parse_context, specifically adapting the results to @@ -366,7 +365,7 @@ extern cod_parse_context cod_copy_context ARGS((cod_parse_context context)); * * \param context the cod_parse_context to be duplicated. */ -extern cod_parse_context cod_copy_globals ARGS((cod_parse_context context)); +extern FFS_DECLSPEC cod_parse_context cod_copy_globals(cod_parse_context context); /*! * err_out_func_t is a function pointer type. Functions matching this @@ -375,7 +374,7 @@ extern cod_parse_context cod_copy_globals ARGS((cod_parse_context context)); * cod_set_error_func() * \param string the textual representation of the error. */ -typedef void (*err_out_func_t) ARGS((void *client_data, char *string)); +typedef void (*err_out_func_t)(void *client_data, char *string); /*! * cod_set_error_func establishes a new error output routine for COD. @@ -385,8 +384,8 @@ typedef void (*err_out_func_t) ARGS((void *client_data, char *string)); * \param context the context in which errors are to be captured * \param err_func the function to be called when errors occur */ -void cod_set_error_func ARGS((cod_parse_context context, - err_out_func_t err_func)); +void cod_set_error_func(cod_parse_context context, + err_out_func_t err_func); /*! * cod_set_dont_coerce_return restricts COD to more strict type matching for expressions and return values @@ -394,14 +393,14 @@ void cod_set_error_func ARGS((cod_parse_context context, * \param context the context to restrict * \param value True if coercion is not to be applied to return values, false by default */ -void cod_set_dont_coerce_return ARGS((cod_parse_context context, int value)); +void cod_set_dont_coerce_return(cod_parse_context context, int value); /*! * This will dump (to stdout) a disassembled version of the * machine code that has been generated * \param code the cod_code handle containing the code to be dumped. */ -void cod_dump ARGS((cod_code code)); +void cod_dump(cod_code code); /*! * This will generate rollback code for message morphing @@ -409,8 +408,8 @@ void cod_dump ARGS((cod_code code)); * \param format2 the old format. This is the format of the output message. * \param xform_code The COD code string that transforms data from format1 to format2. */ -extern cod_code -gen_rollback_code ARGS((FMStructDescList format1, FMStructDescList format2, char *xform_code)); +extern FFS_DECLSPEC cod_code +gen_rollback_code(FMStructDescList format1, FMStructDescList format2, char *xform_code); /*! * \brief This is used to add an integer constant available in a particular context. @@ -418,8 +417,8 @@ gen_rollback_code ARGS((FMStructDescList format1, FMStructDescList format2, char * \param value The value of the constant * \param context the context in which this is to be created */ -extern void cod_add_int_constant_to_parse_context ARGS((const char *id, int value, - cod_parse_context context)); +extern FFS_DECLSPEC void cod_add_int_constant_to_parse_context(const char *id, int value, + cod_parse_context context); /*! * \brief Sets what value cod_closure_context will send to a subroutine. @@ -427,7 +426,7 @@ extern void cod_add_int_constant_to_parse_context ARGS((const char *id, int valu * \param value The value to send * \param context The context in which the subroutine has been declared. */ -extern void cod_set_closure ARGS((char *name, void* value, cod_parse_context context)); +extern FFS_DECLSPEC void cod_set_closure(char *name, void* value, cod_parse_context context); #if defined(__cplusplus) || defined(c_plusplus) } diff --git a/cod/cod.l b/cod/cod.l index 1aeba7fb0f..fd5517b57a 100644 --- a/cod/cod.l +++ b/cod/cod.l @@ -71,8 +71,7 @@ extern int my_yy_input(); #endif static int -is_defined_type(id) -char *id; +is_defined_type(char *id) { int i = 0; while(types && types[i]) { @@ -83,8 +82,7 @@ char *id; } static int -is_enumeration_constant(id) -char *id; +is_enumeration_constant(char *id) { int i = 0; while(enums && enums[i]) { @@ -329,7 +327,7 @@ static char *create_string_from_yytext() static void check_strbuf() { - int cur_len = string_buf_ptr - string_buffer; + intptr_t cur_len = string_buf_ptr - string_buffer; if ((cur_len + 1) == buffer_len) { buffer_len += 20; string_buffer = realloc(string_buffer, buffer_len + 1); @@ -429,19 +427,14 @@ char **enum_constants; static YY_BUFFER_STATE bb = NULL; static void -reset_types_table(defined_types, enumerated_constants) -char **defined_types; -char **enumerated_constants; +reset_types_table(char **defined_types, char **enumerated_constants) { types = defined_types; enums = enumerated_constants; } static void -setup_for_string_parse(string, defined_types, enum_constants) -const char *string; -char **defined_types; -char **enum_constants; +setup_for_string_parse(const char *string, char **defined_types, char **enum_constants) { types = defined_types; enums = enum_constants; diff --git a/cod/cod.y b/cod/cod.y index 8ea0b75c73..5d21652bd8 100644 --- a/cod/cod.y +++ b/cod/cod.y @@ -34,10 +34,6 @@ int cod_kplugins_integration = 0; #include #endif #endif -#include "fm.h" -#include "fm_internal.h" -#include "cod.h" -#include "cod_internal.h" #undef NDEBUG #include "assert.h" #ifndef LINUX_KERNEL_MODULE @@ -61,6 +57,10 @@ int cod_kplugins_integration = 0; #define OP_DBL_Digs (DBL_DIG + 3) #endif #endif +#include "fm.h" +#include "fm_internal.h" +#include "cod.h" +#include "cod_internal.h" #include "structs.h" #ifdef HAVE_DILL_H #include "dill.h" @@ -88,6 +88,11 @@ typedef void *dill_stream; #endif #if defined(_MSC_VER) #define strdup _strdup +#define isatty _isatty +#define fileno _fileno +#include +#include +#include #endif #ifndef LINUX_KERNEL_MODULE #ifdef STDC_HEADERS @@ -112,14 +117,17 @@ char *strdup(const char *s) return p; } #endif +#ifdef _MSC_VER +#undef strncpy +#endif #define YY_NO_INPUT static char* gen_anon() { static int anon_count = 0; - char *ret = malloc(strlen("Anonymous-xxxxxxxxxxxxxxxxx")); - sprintf(ret, "Anonymous-%d", anon_count++); + char *ret = malloc(40); + snprintf(ret, 40, "Anonymous-%d", anon_count++); return ret; } @@ -1872,6 +1880,9 @@ constant : ; %% +#ifdef _MSC_VER +#define YY_NO_UNISTD_H +#endif #include "lex.yy.c" typedef struct scope *scope_ptr; @@ -1936,7 +1947,7 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) { char *out; char *ptr; - if (index(input, '#') == NULL) return NULL; + if (strchr(input, '#') == NULL) return NULL; out = strdup(input); ptr = out; *white = 0; @@ -1950,10 +1961,10 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) char *include_end; ptr += 8; while(isspace(*ptr)) ptr++; - line_end = index(ptr, '\n'); + line_end = strchr(ptr, '\n'); if (line_end) *line_end = 0; if ((*ptr == '<') || (*ptr == '"')) { - include_end = (*ptr == '<') ? index(ptr, '>') : index((ptr+1), '"'); + include_end = (*ptr == '<') ? strchr(ptr, '>') : strchr((ptr+1), '"'); if (!include_end) { printf("improper #include, \"%s\"\n", ptr); goto skip; @@ -1974,10 +1985,10 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) } skip: /* skip to next line */ - ptr = index(ptr, '\n'); + ptr = strchr(ptr, '\n'); while (ptr && (*(ptr - 1) == '\'')) { /* continued line */ - ptr = index(ptr, '\n'); + ptr = strchr(ptr, '\n'); } } { @@ -1992,9 +2003,7 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) } int -cod_parse_for_globals(code, context) -char *code; -cod_parse_context context; +cod_parse_for_globals(char *code, cod_parse_context context) { int ret; context->alloc_globals = 1; @@ -2003,9 +2012,7 @@ cod_parse_context context; return ret; } int -cod_parse_for_context(code, context) -char *code; -cod_parse_context context; +cod_parse_for_context(char *code, cod_parse_context context) { sm_list decls; int ret; @@ -2070,12 +2077,10 @@ static int include_prefix(char *code) break; } } - return tmp - code; + return (int)(intptr_t)(tmp - code); } cod_code -cod_code_gen(code, context) -char *code; -cod_parse_context context; +cod_code_gen(char *code, cod_parse_context context) { sm_ref tmp, tmp2; cod_code ret_code; @@ -2086,7 +2091,7 @@ cod_parse_context context; if (code != NULL) { if ((bracket = include_prefix(code))) { char *prefix = malloc(bracket+1), *tmp; - strncpy(prefix, code, bracket); + strncpy(prefix, code, bracket + 1); prefix[bracket] = 0; tmp = prefix; while(isspace(*tmp)) tmp++; @@ -2138,7 +2143,7 @@ cod_parse_context context; tmp->node.compound_statement.decls = NULL; tmp2->node.compound_statement.decls = NULL; cod_rfree(tmp2); - ret_code->func = (void(*)())(long)func; + ret_code->func = (void(*)(void))(intptr_t)func; return ret_code; } @@ -2156,9 +2161,7 @@ cod_dump(cod_code code) int -cod_code_verify(code, context) -char *code; -cod_parse_context context; +cod_code_verify(char *code, cod_parse_context context) { sm_ref tmp; @@ -2196,8 +2199,7 @@ cod_parse_context context; } extern void -cod_code_free(code) -cod_code code; +cod_code_free(cod_code code) { if (code->code_memory_block) free(code->code_memory_block); if (code->data) free(code->data); @@ -2257,7 +2259,7 @@ print_context(cod_parse_context context, int line, int character) offset = character - 40; } line_copy = copy_line(line_begin + offset); - line_len = strlen(line_copy); + line_len = (int)strlen(line_copy); if (line_len > 60) { line_copy[60] = 0; } @@ -2274,8 +2276,7 @@ print_context(cod_parse_context context, int line, int character) context->error_func(context->client_data, "^\n"); } -void yyerror(str) -char *str; +void yyerror(char *str) { char tmp_str[100]; sprintf(tmp_str, "## Error %s\n", str); @@ -2469,8 +2470,7 @@ struct scope { extern cod_parse_context -cod_copy_context(context) -cod_parse_context context; +cod_copy_context(cod_parse_context context) { int i, count; int type_count = 0; @@ -2507,8 +2507,7 @@ cod_parse_context context; extern void dump_scope(scope_ptr scope); extern cod_parse_context -cod_copy_globals(context) -cod_parse_context context; +cod_copy_globals(cod_parse_context context) { int i, count; int type_count = 0; @@ -2847,7 +2846,7 @@ determine_op_type(cod_parse_context context, sm_ref expr, if ((left_type == DILL_UL) || (right_type == DILL_UL)) return DILL_UL; if ((left_type == DILL_L) || (right_type == DILL_L)) { /* GSE -bug This test should be for *generated* target, not host */ - if (sizeof(long) > sizeof(unsigned int)) { + if (sizeof(intptr_t) > sizeof(unsigned int)) { /* Long can represent all values of unsigned int */ return DILL_L; } else { @@ -3198,7 +3197,7 @@ type_list_to_string(cod_parse_context context, sm_list type_list, int *size) *size = sizeof(int); return strdup("integer"); case DILL_L: - *size = sizeof(long); + *size = sizeof(intptr_t); return strdup("integer"); case DILL_S: *size = sizeof(short); @@ -3207,7 +3206,7 @@ type_list_to_string(cod_parse_context context, sm_list type_list, int *size) *size = sizeof(int); return strdup("unsigned integer"); case DILL_UL: - *size = sizeof(long); + *size = sizeof(intptr_t); return strdup("unsigned integer"); case DILL_US: *size = sizeof(short); @@ -4111,7 +4110,7 @@ unsigned long, long long, unsigned long long */ long i; - int len = strlen(val); + int len = (int)strlen(val); int hex = 0; int specified_unsgned = 0, specified_lng = 0; if (val[0] == '0') { @@ -5610,9 +5609,7 @@ cod_remove_defined_types(cod_parse_context context, int count) } void -cod_add_defined_type(id, context) -char *id; -cod_parse_context context; +cod_add_defined_type(char *id, cod_parse_context context) { int count = 0; while(context->defined_types && context->defined_types[count]) count++; @@ -5629,9 +5626,7 @@ cod_parse_context context; } void -cod_add_enum_const(id, context) -char *id; -cod_parse_context context; +cod_add_enum_const(char *id, cod_parse_context context) { int count = 0; while(context->enumerated_constants && context->enumerated_constants[count]) count++; @@ -5672,9 +5667,7 @@ cod_add_struct_type(FMStructDescList format_list, } static int -str_to_data_type(str, size) -char *str; -int size; +str_to_data_type(char *str, int size) { char *tmp = malloc(strlen(str) + 1); char *free_str = tmp; @@ -5696,7 +5689,7 @@ int size; } if ((strcmp(str, "integer") == 0) || (strcmp(str, "enumeration") == 0)) { free(free_str); - if (size == sizeof(long)) { + if (size == sizeof(intptr_t)) { return DILL_L; } else if (size == sizeof(int)) { return DILL_I; @@ -5709,7 +5702,7 @@ int size; } } else if (strcmp(str, "unsigned integer") == 0) { free(free_str); - if (size == sizeof(long)) { + if (size == sizeof(intptr_t)) { return DILL_UL; } else if (size == sizeof(int)) { return DILL_U; @@ -5744,9 +5737,7 @@ int size; } static int -array_str_to_data_type(str, size) -char *str; -int size; +array_str_to_data_type(char *str, int size) { int ret_type; char field_type[1024]; @@ -5766,14 +5757,8 @@ int size; } static sm_ref -build_subtype_nodes(context, decl, f, desc, err, scope, must_free_p) -cod_parse_context context; -sm_ref decl; -field* f; -FMTypeDesc *desc; -int *err; -scope_ptr scope; -int *must_free_p; +build_subtype_nodes(cod_parse_context context, sm_ref decl, field* f, FMTypeDesc *desc, + int *err, scope_ptr scope, int *must_free_p) { sm_ref ret = NULL; sm_ref subtype = NULL; @@ -5896,16 +5881,8 @@ int *must_free_p; } static void -build_type_nodes(context, decl, f, fields, cg_size, cg_type, desc, err, scope) -cod_parse_context context; -sm_ref decl; -field* f; -sm_list fields; -int cg_size; -int cg_type; -FMTypeDesc* desc; -int *err; -scope_ptr scope; +build_type_nodes(cod_parse_context context, sm_ref decl, field* f, sm_list fields, + int cg_size, int cg_type, FMTypeDesc* desc, int *err, scope_ptr scope) { int must_free_flag = 0; sm_ref complex_type = build_subtype_nodes(context, decl, f, desc, err, scope, &must_free_flag); @@ -5919,13 +5896,7 @@ scope_ptr scope; } static int -semanticize_array_element_node(context, array, super_type, base_type_spec, - scope) -cod_parse_context context; -sm_ref array; -sm_ref super_type; -sm_list base_type_spec; -scope_ptr scope; +semanticize_array_element_node(cod_parse_context context, sm_ref array, sm_ref super_type, sm_list base_type_spec, scope_ptr scope) { if (array->node.array_type_decl.size_expr != NULL) { if (!is_constant_expr(array->node.array_type_decl.size_expr)) { @@ -5993,10 +5964,7 @@ scope_ptr scope; } static int -semanticize_array_type_node(context, array, scope) -cod_parse_context context; -sm_ref array; -scope_ptr scope; +semanticize_array_type_node(cod_parse_context context, sm_ref array, scope_ptr scope) { if (!array->node.array_type_decl.dimensions) { array->node.array_type_decl.dimensions = malloc(sizeof(dimen_s)); @@ -6500,7 +6468,7 @@ static void uniqueify_names(FMStructDescList list, char *prefix) { int i = 0; - int prefix_len = strlen(prefix); + int prefix_len = (int)strlen(prefix); while (list[i].format_name != NULL) { int j = 0; FMFieldList fl = list[i].field_list; @@ -6511,11 +6479,11 @@ uniqueify_names(FMStructDescList list, char *prefix) free((char*)list[i].format_name); list[i].format_name = new_name; while (fl[j].field_name != 0) { - int field_type_len = strlen(fl[j].field_type); + int field_type_len = (int)strlen(fl[j].field_type); char *bracket = strchr(fl[j].field_type, '['); int k; if (bracket != NULL) { - field_type_len = (long) bracket - (long) fl[j].field_type; + field_type_len = (int)((intptr_t) bracket - (intptr_t) fl[j].field_type); } for (k = 0; k < i; k++) { char *new_type; @@ -6603,9 +6571,10 @@ get_constant_float_value(cod_parse_context context, sm_ref expr) default: assert(FALSE); } + return 0.0; } -static long +static intptr_t get_constant_long_value(cod_parse_context context, sm_ref expr) { double dresult; @@ -6624,6 +6593,7 @@ get_constant_long_value(cod_parse_context context, sm_ref expr) default: assert(FALSE); } + return -1; } extern sm_ref @@ -6717,7 +6687,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ is_ivalue=1; break; case op_eq: - ivalue = left_val = right_val; + ivalue = left_val == right_val; is_ivalue=1; break; case op_neq: @@ -6762,7 +6732,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ *free_result = 1; } else { /* we get an integer result */ - long left_val = 0, right_val = 0, value; + intptr_t left_val = 0, right_val = 0, value; char str_val[40]; if (expr->node.operator.left) left_val = get_constant_long_value(context, left); @@ -6841,7 +6811,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ } ret = cod_new_constant(); ret->node.constant.token = integer_constant; - sprintf(str_val, "%ld", value); + sprintf(str_val, "%zd", value); ret->node.constant.const_val = strdup(str_val); *free_result = 1; } @@ -6863,5 +6833,6 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ default: assert(FALSE); } + return NULL; } diff --git a/cod/pregen_source/Linux/cod.tab.c b/cod/pregen_source/Linux/cod.tab.c index 1d42833f97..3e09ac5b37 100644 --- a/cod/pregen_source/Linux/cod.tab.c +++ b/cod/pregen_source/Linux/cod.tab.c @@ -238,9 +238,12 @@ /* Copy the first part of user declarations. */ -#line 1 "cod/cod.y" +#line 1 "cod.y" #include "config.h" +#ifdef __NVCOMPILER +#pragma diag_suppress 550, 111, 941 +#endif #if defined (__INTEL_COMPILER) # pragma warning (disable: 2215) #endif @@ -272,10 +275,6 @@ int cod_kplugins_integration = 0; #include #endif #endif -#include "fm.h" -#include "fm_internal.h" -#include "cod.h" -#include "cod_internal.h" #undef NDEBUG #include "assert.h" #ifndef LINUX_KERNEL_MODULE @@ -299,6 +298,10 @@ int cod_kplugins_integration = 0; #define OP_DBL_Digs (DBL_DIG + 3) #endif #endif +#include "fm.h" +#include "fm_internal.h" +#include "cod.h" +#include "cod_internal.h" #include "structs.h" #ifdef HAVE_DILL_H #include "dill.h" @@ -320,9 +323,17 @@ enum { DILL_EC, DILL_ERR /* no type */ }; +typedef void *dill_stream; +#define dill_create_stream() 0 +#define dill_type_size(c, s) 0 #endif #if defined(_MSC_VER) #define strdup _strdup +#define isatty _isatty +#define fileno _fileno +#include +#include +#include #endif #ifndef LINUX_KERNEL_MODULE #ifdef STDC_HEADERS @@ -347,14 +358,17 @@ char *strdup(const char *s) return p; } #endif +#ifdef _MSC_VER +#undef strncpy +#endif #define YY_NO_INPUT static char* gen_anon() { static int anon_count = 0; - char *ret = malloc(strlen("Anonymous-xxxxxxxxxxxxxxxxx")); - sprintf(ret, "Anonymous-%d", anon_count++); + char *ret = malloc(40); + snprintf(ret, 40, "Anonymous-%d", anon_count++); return ret; } @@ -444,7 +458,7 @@ cod_dup_list(sm_list list) #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE -#line 187 "cod/cod.y" +#line 201 "cod.y" { lx_info info; sm_ref reference; @@ -453,7 +467,7 @@ typedef union YYSTYPE char *string; } /* Line 193 of yacc.c. */ -#line 457 "/Users/eisen/prog/ffs/build/cod.tab.c" +#line 471 "cod.tab.c" YYSTYPE; # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 @@ -466,7 +480,7 @@ typedef union YYSTYPE /* Line 216 of yacc.c. */ -#line 470 "/Users/eisen/prog/ffs/build/cod.tab.c" +#line 484 "cod.tab.c" #ifdef short # undef short @@ -836,27 +850,27 @@ static const yytype_int16 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 344, 344, 348, 354, 360, 362, 369, 371, 378, - 385, 392, 398, 404, 411, 421, 427, 441, 442, 449, - 456, 463, 470, 485, 488, 491, 494, 497, 500, 506, - 507, 516, 518, 527, 536, 547, 549, 558, 569, 571, - 580, 591, 593, 602, 611, 620, 631, 633, 642, 653, - 655, 666, 668, 679, 681, 692, 694, 705, 707, 718, - 720, 731, 733, 735, 737, 739, 741, 743, 745, 747, - 749, 751, 756, 759, 770, 772, 782, 786, 791, 810, - 817, 809, 900, 906, 911, 917, 922, 928, 933, 941, - 943, 959, 964, 969, 978, 983, 988, 993, 998, 1003, - 1008, 1013, 1018, 1023, 1028, 1033, 1036, 1042, 1045, 1048, - 1054, 1055, 1061, 1062, 1074, 1075, 1126, 1131, 1143, 1146, - 1152, 1157, 1163, 1171, 1178, 1185, 1192, 1199, 1209, 1215, - 1225, 1231, 1239, 1247, 1249, 1263, 1272, 1275, 1284, 1293, - 1300, 1310, 1318, 1326, 1334, 1348, 1359, 1370, 1381, 1401, - 1406, 1419, 1420, 1435, 1441, 1456, 1465, 1504, 1505, 1551, - 1555, 1560, 1565, 1570, 1578, 1586, 1599, 1615, 1620, 1625, - 1638, 1644, 1653, 1659, 1662, 1665, 1671, 1676, 1677, 1678, - 1679, 1680, 1681, 1688, 1695, 1698, 1706, 1708, 1722, 1727, - 1732, 1738, 1744, 1753, 1757, 1767, 1776, 1793, 1803, 1813, - 1827, 1829, 1832, 1839, 1846, 1853, 1860 + 0, 358, 358, 362, 368, 374, 376, 383, 385, 392, + 399, 406, 412, 418, 425, 435, 441, 455, 456, 463, + 470, 477, 484, 499, 502, 505, 508, 511, 514, 520, + 521, 530, 532, 541, 550, 561, 563, 572, 583, 585, + 594, 605, 607, 616, 625, 634, 645, 647, 656, 667, + 669, 680, 682, 693, 695, 706, 708, 719, 721, 732, + 734, 745, 747, 749, 751, 753, 755, 757, 759, 761, + 763, 765, 770, 773, 784, 786, 796, 800, 805, 824, + 831, 823, 914, 920, 925, 931, 936, 942, 947, 955, + 957, 973, 978, 983, 992, 997, 1002, 1007, 1012, 1017, + 1022, 1027, 1032, 1037, 1042, 1047, 1050, 1056, 1059, 1062, + 1068, 1069, 1075, 1076, 1088, 1089, 1140, 1145, 1157, 1160, + 1166, 1171, 1177, 1185, 1192, 1199, 1206, 1213, 1223, 1229, + 1239, 1245, 1253, 1261, 1263, 1277, 1286, 1289, 1298, 1307, + 1314, 1324, 1332, 1340, 1348, 1362, 1373, 1384, 1395, 1415, + 1420, 1433, 1434, 1449, 1455, 1470, 1479, 1518, 1519, 1565, + 1569, 1574, 1579, 1584, 1592, 1600, 1613, 1629, 1634, 1639, + 1652, 1658, 1667, 1673, 1676, 1679, 1685, 1690, 1691, 1692, + 1693, 1694, 1695, 1702, 1709, 1712, 1720, 1722, 1736, 1741, + 1746, 1752, 1758, 1767, 1771, 1781, 1790, 1807, 1817, 1827, + 1841, 1843, 1846, 1853, 1860, 1867, 1874 }; #endif @@ -2137,21 +2151,21 @@ yyparse () switch (yyn) { case 2: -#line 344 "cod/cod.y" +#line 358 "cod.y" { yyparse_value = (sm_ref)(yyvsp[(1) - (1)].list); ;} break; case 3: -#line 348 "cod/cod.y" +#line 362 "cod.y" { yyparse_value = (yyvsp[(1) - (1)].reference); ;} break; case 4: -#line 354 "cod/cod.y" +#line 368 "cod.y" { (yyval.reference) = cod_new_identifier(); (yyval.reference)->node.identifier.id = (yyvsp[(1) - (1)].info).string; @@ -2160,12 +2174,12 @@ yyparse () break; case 6: -#line 363 "cod/cod.y" +#line 377 "cod.y" { (yyval.reference) = (yyvsp[(2) - (3)].reference); ;} break; case 8: -#line 371 "cod/cod.y" +#line 385 "cod.y" { (yyval.reference) = cod_new_element_ref(); (yyval.reference)->node.element_ref.lx_srcpos = (yyvsp[(2) - (4)].info).lx_srcpos; @@ -2175,7 +2189,7 @@ yyparse () break; case 9: -#line 378 "cod/cod.y" +#line 392 "cod.y" { (yyval.reference) = cod_new_field_ref(); (yyval.reference)->node.field_ref.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2185,7 +2199,7 @@ yyparse () break; case 10: -#line 385 "cod/cod.y" +#line 399 "cod.y" { (yyval.reference) = cod_new_subroutine_call(); (yyval.reference)->node.subroutine_call.lx_srcpos = (yyvsp[(2) - (4)].info).lx_srcpos; @@ -2195,7 +2209,7 @@ yyparse () break; case 11: -#line 392 "cod/cod.y" +#line 406 "cod.y" { (yyval.reference) = cod_new_subroutine_call(); (yyval.reference)->node.subroutine_call.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2205,7 +2219,7 @@ yyparse () break; case 12: -#line 398 "cod/cod.y" +#line 412 "cod.y" { (yyval.reference) = cod_new_field_ref(); (yyval.reference)->node.field_ref.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2215,7 +2229,7 @@ yyparse () break; case 13: -#line 404 "cod/cod.y" +#line 418 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (2)].info).lx_srcpos; @@ -2226,7 +2240,7 @@ yyparse () break; case 14: -#line 411 "cod/cod.y" +#line 425 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (2)].info).lx_srcpos; @@ -2237,7 +2251,7 @@ yyparse () break; case 15: -#line 421 "cod/cod.y" +#line 435 "cod.y" { (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = (yyvsp[(1) - (1)].reference); @@ -2246,7 +2260,7 @@ yyparse () break; case 16: -#line 427 "cod/cod.y" +#line 441 "cod.y" { sm_list tmp = (yyvsp[(1) - (3)].list); while (tmp->next != NULL) { @@ -2260,7 +2274,7 @@ yyparse () break; case 18: -#line 442 "cod/cod.y" +#line 456 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; @@ -2271,7 +2285,7 @@ yyparse () break; case 19: -#line 449 "cod/cod.y" +#line 463 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; @@ -2282,7 +2296,7 @@ yyparse () break; case 20: -#line 456 "cod/cod.y" +#line 470 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; @@ -2293,7 +2307,7 @@ yyparse () break; case 21: -#line 463 "cod/cod.y" +#line 477 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; @@ -2304,7 +2318,7 @@ yyparse () break; case 22: -#line 470 "cod/cod.y" +#line 484 "cod.y" { /* dummy up a cast to hold the sm_list of the type */ sm_ref cast = cod_new_cast(); @@ -2321,49 +2335,49 @@ yyparse () break; case 23: -#line 485 "cod/cod.y" +#line 499 "cod.y" { (yyval.info).op = op_address; ;} break; case 24: -#line 488 "cod/cod.y" +#line 502 "cod.y" { (yyval.info).op = op_deref; ;} break; case 25: -#line 491 "cod/cod.y" +#line 505 "cod.y" { (yyval.info).op = op_plus; ;} break; case 26: -#line 494 "cod/cod.y" +#line 508 "cod.y" { (yyval.info).op = op_minus; ;} break; case 27: -#line 497 "cod/cod.y" +#line 511 "cod.y" { (yyval.info).op = op_not; ;} break; case 28: -#line 500 "cod/cod.y" +#line 514 "cod.y" { (yyval.info).op = op_log_neg; ;} break; case 30: -#line 507 "cod/cod.y" +#line 521 "cod.y" { (yyval.reference) = cod_new_cast(); (yyval.reference)->node.cast.lx_srcpos = (yyvsp[(1) - (4)].info).lx_srcpos; @@ -2373,7 +2387,7 @@ yyparse () break; case 32: -#line 519 "cod/cod.y" +#line 533 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2384,7 +2398,7 @@ yyparse () break; case 33: -#line 528 "cod/cod.y" +#line 542 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2395,7 +2409,7 @@ yyparse () break; case 34: -#line 537 "cod/cod.y" +#line 551 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2406,7 +2420,7 @@ yyparse () break; case 36: -#line 550 "cod/cod.y" +#line 564 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.op = op_plus; @@ -2417,7 +2431,7 @@ yyparse () break; case 37: -#line 559 "cod/cod.y" +#line 573 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2428,7 +2442,7 @@ yyparse () break; case 39: -#line 572 "cod/cod.y" +#line 586 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2439,7 +2453,7 @@ yyparse () break; case 40: -#line 581 "cod/cod.y" +#line 595 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2450,7 +2464,7 @@ yyparse () break; case 42: -#line 594 "cod/cod.y" +#line 608 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2461,7 +2475,7 @@ yyparse () break; case 43: -#line 603 "cod/cod.y" +#line 617 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2472,7 +2486,7 @@ yyparse () break; case 44: -#line 612 "cod/cod.y" +#line 626 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2483,7 +2497,7 @@ yyparse () break; case 45: -#line 621 "cod/cod.y" +#line 635 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2494,7 +2508,7 @@ yyparse () break; case 47: -#line 634 "cod/cod.y" +#line 648 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2505,7 +2519,7 @@ yyparse () break; case 48: -#line 643 "cod/cod.y" +#line 657 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2516,7 +2530,7 @@ yyparse () break; case 50: -#line 656 "cod/cod.y" +#line 670 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2527,7 +2541,7 @@ yyparse () break; case 52: -#line 669 "cod/cod.y" +#line 683 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2538,7 +2552,7 @@ yyparse () break; case 54: -#line 682 "cod/cod.y" +#line 696 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2549,7 +2563,7 @@ yyparse () break; case 56: -#line 695 "cod/cod.y" +#line 709 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2560,7 +2574,7 @@ yyparse () break; case 58: -#line 708 "cod/cod.y" +#line 722 "cod.y" { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2571,7 +2585,7 @@ yyparse () break; case 60: -#line 721 "cod/cod.y" +#line 735 "cod.y" { (yyval.reference) = cod_new_conditional_operator(); (yyval.reference)->node.conditional_operator.lx_srcpos = (yyvsp[(2) - (5)].info).lx_srcpos; @@ -2582,67 +2596,67 @@ yyparse () break; case 61: -#line 732 "cod/cod.y" +#line 746 "cod.y" { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_eq;;} break; case 62: -#line 734 "cod/cod.y" +#line 748 "cod.y" { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_mult;;} break; case 63: -#line 736 "cod/cod.y" +#line 750 "cod.y" { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_div;;} break; case 64: -#line 738 "cod/cod.y" +#line 752 "cod.y" { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_modulus;;} break; case 65: -#line 740 "cod/cod.y" +#line 754 "cod.y" { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_plus;;} break; case 66: -#line 742 "cod/cod.y" +#line 756 "cod.y" { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_minus;;} break; case 67: -#line 744 "cod/cod.y" +#line 758 "cod.y" { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_left_shift;;} break; case 68: -#line 746 "cod/cod.y" +#line 760 "cod.y" { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_right_shift;;} break; case 69: -#line 748 "cod/cod.y" +#line 762 "cod.y" { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_arith_and;;} break; case 70: -#line 750 "cod/cod.y" +#line 764 "cod.y" { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_arith_xor;;} break; case 71: -#line 752 "cod/cod.y" +#line 766 "cod.y" { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_arith_or;;} break; case 72: -#line 757 "cod/cod.y" +#line 771 "cod.y" { (yyval.reference) = (yyvsp[(1) - (1)].reference);;} break; case 73: -#line 760 "cod/cod.y" +#line 774 "cod.y" { (yyval.reference) = cod_new_assignment_expression(); (yyval.reference)->node.assignment_expression.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2653,12 +2667,12 @@ yyparse () break; case 74: -#line 771 "cod/cod.y" +#line 785 "cod.y" {(yyval.reference) = (yyvsp[(1) - (1)].reference);;} break; case 75: -#line 773 "cod/cod.y" +#line 787 "cod.y" { (yyval.reference) = cod_new_comma_expression(); (yyval.reference)->node.comma_expression.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -2668,7 +2682,7 @@ yyparse () break; case 77: -#line 786 "cod/cod.y" +#line 800 "cod.y" { (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = (yyvsp[(1) - (1)].reference); @@ -2677,7 +2691,7 @@ yyparse () break; case 78: -#line 791 "cod/cod.y" +#line 805 "cod.y" { sm_list tmp = (yyvsp[(1) - (3)].list); while (tmp->next != NULL) { @@ -2692,7 +2706,7 @@ yyparse () break; case 79: -#line 810 "cod/cod.y" +#line 824 "cod.y" { if (parsing_type) { yyparse_value = (sm_ref) (yyvsp[(1) - (1)].list); @@ -2702,7 +2716,7 @@ yyparse () break; case 80: -#line 817 "cod/cod.y" +#line 831 "cod.y" { /* stop here if we're just doing a proc decl */ if (parsing_param_spec) { (yyval.reference) = (yyvsp[(3) - (3)].list)->node; @@ -2733,7 +2747,7 @@ yyparse () break; case 81: -#line 845 "cod/cod.y" +#line 859 "cod.y" { (yyval.list) = (yyvsp[(3) - (5)].list); sm_list dtmp = (yyvsp[(3) - (5)].list); @@ -2792,14 +2806,14 @@ yyparse () break; case 82: -#line 900 "cod/cod.y" +#line 914 "cod.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; case 83: -#line 906 "cod/cod.y" +#line 920 "cod.y" { (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = (yyvsp[(1) - (1)].reference); @@ -2808,7 +2822,7 @@ yyparse () break; case 84: -#line 911 "cod/cod.y" +#line 925 "cod.y" { sm_list tmp = malloc(sizeof(struct list_struct)); tmp->node = (yyvsp[(1) - (2)].reference); @@ -2818,7 +2832,7 @@ yyparse () break; case 85: -#line 917 "cod/cod.y" +#line 931 "cod.y" { (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = (yyvsp[(1) - (1)].reference); @@ -2827,7 +2841,7 @@ yyparse () break; case 86: -#line 922 "cod/cod.y" +#line 936 "cod.y" { sm_list tmp = malloc(sizeof(struct list_struct)); tmp->node = (yyvsp[(1) - (2)].reference); @@ -2837,7 +2851,7 @@ yyparse () break; case 87: -#line 928 "cod/cod.y" +#line 942 "cod.y" { (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = (yyvsp[(1) - (1)].reference); @@ -2846,7 +2860,7 @@ yyparse () break; case 88: -#line 933 "cod/cod.y" +#line 947 "cod.y" { sm_list tmp = malloc(sizeof(struct list_struct)); tmp->node = (yyvsp[(1) - (2)].reference); @@ -2856,7 +2870,7 @@ yyparse () break; case 90: -#line 944 "cod/cod.y" +#line 958 "cod.y" { if ((yyvsp[(1) - (3)].reference)->node_type == cod_declaration) { (yyvsp[(1) - (3)].reference)->node.declaration.init_value = (yyvsp[(3) - (3)].reference); @@ -2872,7 +2886,7 @@ yyparse () break; case 91: -#line 959 "cod/cod.y" +#line 973 "cod.y" { (yyval.reference) = cod_new_type_specifier(); (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -2881,7 +2895,7 @@ yyparse () break; case 92: -#line 964 "cod/cod.y" +#line 978 "cod.y" { (yyval.reference) = cod_new_type_specifier(); (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -2890,7 +2904,7 @@ yyparse () break; case 93: -#line 969 "cod/cod.y" +#line 983 "cod.y" { (yyval.reference) = cod_new_type_specifier(); (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -2899,7 +2913,7 @@ yyparse () break; case 94: -#line 978 "cod/cod.y" +#line 992 "cod.y" { (yyval.reference) = cod_new_type_specifier(); (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -2908,7 +2922,7 @@ yyparse () break; case 95: -#line 983 "cod/cod.y" +#line 997 "cod.y" { (yyval.reference) = cod_new_type_specifier(); (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -2917,7 +2931,7 @@ yyparse () break; case 96: -#line 988 "cod/cod.y" +#line 1002 "cod.y" { (yyval.reference) = cod_new_type_specifier(); (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -2926,7 +2940,7 @@ yyparse () break; case 97: -#line 993 "cod/cod.y" +#line 1007 "cod.y" { (yyval.reference) = cod_new_type_specifier(); (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -2935,7 +2949,7 @@ yyparse () break; case 98: -#line 998 "cod/cod.y" +#line 1012 "cod.y" { (yyval.reference) = cod_new_type_specifier(); (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -2944,7 +2958,7 @@ yyparse () break; case 99: -#line 1003 "cod/cod.y" +#line 1017 "cod.y" { (yyval.reference) = cod_new_type_specifier(); (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -2953,7 +2967,7 @@ yyparse () break; case 100: -#line 1008 "cod/cod.y" +#line 1022 "cod.y" { (yyval.reference) = cod_new_type_specifier(); (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -2962,7 +2976,7 @@ yyparse () break; case 101: -#line 1013 "cod/cod.y" +#line 1027 "cod.y" { (yyval.reference) = cod_new_type_specifier(); (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -2971,7 +2985,7 @@ yyparse () break; case 102: -#line 1018 "cod/cod.y" +#line 1032 "cod.y" { (yyval.reference) = cod_new_type_specifier(); (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -2980,7 +2994,7 @@ yyparse () break; case 103: -#line 1023 "cod/cod.y" +#line 1037 "cod.y" { (yyval.reference) = cod_new_type_specifier(); (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -2989,7 +3003,7 @@ yyparse () break; case 104: -#line 1028 "cod/cod.y" +#line 1042 "cod.y" { (yyval.reference) = cod_new_identifier(); (yyval.reference)->node.identifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -2998,49 +3012,49 @@ yyparse () break; case 105: -#line 1033 "cod/cod.y" +#line 1047 "cod.y" { (yyval.reference) = (yyvsp[(1) - (1)].reference); ;} break; case 106: -#line 1036 "cod/cod.y" +#line 1050 "cod.y" { (yyval.reference) = (yyvsp[(1) - (1)].reference); ;} break; case 107: -#line 1042 "cod/cod.y" +#line 1056 "cod.y" { (yyval.reference) = cod_build_parsed_type_node(yycontext, (yyvsp[(2) - (5)].info).string, (yyvsp[(4) - (5)].list)); ;} break; case 108: -#line 1045 "cod/cod.y" +#line 1059 "cod.y" { (yyval.reference) = cod_build_parsed_type_node(yycontext, strdup("anon"), (yyvsp[(3) - (4)].list)); ;} break; case 109: -#line 1048 "cod/cod.y" +#line 1062 "cod.y" { (yyval.reference) = cod_build_parsed_type_node(yycontext, (yyvsp[(2) - (2)].info).string, NULL); ;} break; case 111: -#line 1055 "cod/cod.y" +#line 1069 "cod.y" { yyerror("UNIONs not supported!"); ;} break; case 113: -#line 1062 "cod/cod.y" +#line 1076 "cod.y" { sm_list tmp = (yyvsp[(1) - (2)].list); while (tmp->next != NULL) { @@ -3052,12 +3066,12 @@ yyparse () break; case 114: -#line 1074 "cod/cod.y" +#line 1088 "cod.y" { ;} break; case 115: -#line 1075 "cod/cod.y" +#line 1089 "cod.y" { sm_list type_spec = (yyvsp[(1) - (3)].list); sm_list decl_list = (yyvsp[(2) - (3)].list); @@ -3108,7 +3122,7 @@ yyparse () break; case 116: -#line 1126 "cod/cod.y" +#line 1140 "cod.y" { (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = (yyvsp[(1) - (1)].reference); @@ -3117,7 +3131,7 @@ yyparse () break; case 117: -#line 1131 "cod/cod.y" +#line 1145 "cod.y" { sm_list tmp = (yyvsp[(1) - (3)].list); while (tmp->next != NULL) { @@ -3131,7 +3145,7 @@ yyparse () break; case 119: -#line 1146 "cod/cod.y" +#line 1160 "cod.y" { sm_list tmp = malloc(sizeof(struct list_struct)); tmp->node = (yyvsp[(1) - (2)].reference); @@ -3141,7 +3155,7 @@ yyparse () break; case 120: -#line 1152 "cod/cod.y" +#line 1166 "cod.y" { (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = (yyvsp[(1) - (1)].reference); @@ -3150,7 +3164,7 @@ yyparse () break; case 121: -#line 1157 "cod/cod.y" +#line 1171 "cod.y" { sm_list tmp = malloc(sizeof(struct list_struct)); tmp->node = (yyvsp[(1) - (2)].reference); @@ -3160,7 +3174,7 @@ yyparse () break; case 122: -#line 1163 "cod/cod.y" +#line 1177 "cod.y" { (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = (yyvsp[(1) - (1)].reference); @@ -3169,7 +3183,7 @@ yyparse () break; case 123: -#line 1171 "cod/cod.y" +#line 1185 "cod.y" { (yyval.reference) = cod_new_enum_type_decl(); (yyval.reference)->node.enum_type_decl.id = gen_anon(); @@ -3180,7 +3194,7 @@ yyparse () break; case 124: -#line 1178 "cod/cod.y" +#line 1192 "cod.y" { (yyval.reference) = cod_new_enum_type_decl(); (yyval.reference)->node.enum_type_decl.id = gen_anon(); @@ -3191,7 +3205,7 @@ yyparse () break; case 125: -#line 1185 "cod/cod.y" +#line 1199 "cod.y" { (yyval.reference) = cod_new_enum_type_decl(); (yyval.reference)->node.enum_type_decl.id = (yyvsp[(2) - (5)].info).string; @@ -3202,7 +3216,7 @@ yyparse () break; case 126: -#line 1192 "cod/cod.y" +#line 1206 "cod.y" { (yyval.reference) = cod_new_enum_type_decl(); (yyval.reference)->node.enum_type_decl.id = (yyvsp[(2) - (6)].info).string; @@ -3213,7 +3227,7 @@ yyparse () break; case 127: -#line 1199 "cod/cod.y" +#line 1213 "cod.y" { (yyval.reference) = cod_new_enum_type_decl(); (yyval.reference)->node.enum_type_decl.id = (yyvsp[(2) - (2)].info).string; @@ -3224,7 +3238,7 @@ yyparse () break; case 128: -#line 1209 "cod/cod.y" +#line 1223 "cod.y" { sm_list tmp = malloc(sizeof(struct list_struct)); tmp->node = (yyvsp[(1) - (1)].reference); @@ -3234,7 +3248,7 @@ yyparse () break; case 129: -#line 1215 "cod/cod.y" +#line 1229 "cod.y" { sm_list tmp = malloc(sizeof(struct list_struct)); tmp->node = (yyvsp[(3) - (3)].reference); @@ -3244,7 +3258,7 @@ yyparse () break; case 130: -#line 1225 "cod/cod.y" +#line 1239 "cod.y" { (yyval.reference) = cod_new_enumerator(); (yyval.reference)->node.enumerator.id = (yyvsp[(1) - (3)].info).string; @@ -3253,7 +3267,7 @@ yyparse () break; case 131: -#line 1231 "cod/cod.y" +#line 1245 "cod.y" { (yyval.reference) = cod_new_enumerator(); (yyval.reference)->node.enumerator.id = (yyvsp[(1) - (1)].info).string; @@ -3262,7 +3276,7 @@ yyparse () break; case 132: -#line 1239 "cod/cod.y" +#line 1253 "cod.y" { (yyval.reference) = cod_new_type_specifier(); (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -3271,7 +3285,7 @@ yyparse () break; case 134: -#line 1249 "cod/cod.y" +#line 1263 "cod.y" { (yyval.reference) = (yyvsp[(2) - (2)].reference); if ((yyval.reference)->node_type == cod_declaration) { @@ -3286,7 +3300,7 @@ yyparse () break; case 135: -#line 1263 "cod/cod.y" +#line 1277 "cod.y" { (yyval.reference) = cod_new_declaration(); (yyval.reference)->node.declaration.param_num = -1; @@ -3299,14 +3313,14 @@ yyparse () break; case 136: -#line 1272 "cod/cod.y" +#line 1286 "cod.y" { (yyval.reference) = (yyvsp[(2) - (3)].reference); ;} break; case 137: -#line 1275 "cod/cod.y" +#line 1289 "cod.y" { (yyval.reference) = cod_new_declaration(); (yyval.reference)->node.declaration.param_num = -1; @@ -3319,7 +3333,7 @@ yyparse () break; case 138: -#line 1284 "cod/cod.y" +#line 1298 "cod.y" { (yyval.reference) = cod_new_declaration(); (yyval.reference)->node.declaration.param_num = -1; @@ -3332,7 +3346,7 @@ yyparse () break; case 139: -#line 1293 "cod/cod.y" +#line 1307 "cod.y" { (yyval.reference) = cod_new_array_type_decl(); (yyval.reference)->node.array_type_decl.lx_srcpos = (yyvsp[(2) - (4)].info).lx_srcpos; @@ -3343,7 +3357,7 @@ yyparse () break; case 140: -#line 1300 "cod/cod.y" +#line 1314 "cod.y" { (yyval.reference) = cod_new_array_type_decl(); (yyval.reference)->node.array_type_decl.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; @@ -3354,7 +3368,7 @@ yyparse () break; case 141: -#line 1310 "cod/cod.y" +#line 1324 "cod.y" { sm_ref star = cod_new_type_specifier(); star->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; @@ -3366,7 +3380,7 @@ yyparse () break; case 142: -#line 1318 "cod/cod.y" +#line 1332 "cod.y" { sm_ref star = cod_new_type_specifier(); star->node.type_specifier.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; @@ -3378,7 +3392,7 @@ yyparse () break; case 143: -#line 1326 "cod/cod.y" +#line 1340 "cod.y" { sm_ref star = cod_new_type_specifier(); star->node.type_specifier.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; @@ -3390,7 +3404,7 @@ yyparse () break; case 144: -#line 1334 "cod/cod.y" +#line 1348 "cod.y" { sm_list tmp = (yyvsp[(2) - (3)].list); sm_ref star = cod_new_type_specifier(); @@ -3408,7 +3422,7 @@ yyparse () break; case 145: -#line 1348 "cod/cod.y" +#line 1362 "cod.y" { sm_ref star = cod_new_type_specifier(); if(!cod_segmented_pointers) { @@ -3423,7 +3437,7 @@ yyparse () break; case 146: -#line 1359 "cod/cod.y" +#line 1373 "cod.y" { sm_ref star = cod_new_type_specifier(); if(!cod_segmented_pointers) { @@ -3438,7 +3452,7 @@ yyparse () break; case 147: -#line 1370 "cod/cod.y" +#line 1384 "cod.y" { sm_ref star = cod_new_type_specifier(); if(!cod_segmented_pointers) { @@ -3453,7 +3467,7 @@ yyparse () break; case 148: -#line 1381 "cod/cod.y" +#line 1395 "cod.y" { sm_list tmp = (yyvsp[(2) - (3)].list); sm_ref star = cod_new_type_specifier(); @@ -3474,7 +3488,7 @@ yyparse () break; case 149: -#line 1401 "cod/cod.y" +#line 1415 "cod.y" { (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = (yyvsp[(1) - (1)].reference); @@ -3483,7 +3497,7 @@ yyparse () break; case 150: -#line 1406 "cod/cod.y" +#line 1420 "cod.y" { sm_list tmp = (yyvsp[(1) - (2)].list); while (tmp->next != NULL) { @@ -3497,7 +3511,7 @@ yyparse () break; case 152: -#line 1420 "cod/cod.y" +#line 1434 "cod.y" { sm_list tmp = (yyvsp[(1) - (3)].list); sm_ref id = cod_new_declaration(); @@ -3513,7 +3527,7 @@ yyparse () break; case 153: -#line 1435 "cod/cod.y" +#line 1449 "cod.y" { (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = (yyvsp[(1) - (1)].reference); @@ -3522,7 +3536,7 @@ yyparse () break; case 154: -#line 1441 "cod/cod.y" +#line 1455 "cod.y" { sm_list tmp = (yyvsp[(1) - (3)].list); while (tmp->next != NULL) { @@ -3536,7 +3550,7 @@ yyparse () break; case 155: -#line 1456 "cod/cod.y" +#line 1470 "cod.y" { (yyval.reference) = cod_new_declaration(); (yyval.reference)->node.declaration.param_num = -1; @@ -3549,7 +3563,7 @@ yyparse () break; case 156: -#line 1465 "cod/cod.y" +#line 1479 "cod.y" { (yyval.reference) = (yyvsp[(2) - (2)].reference); if ((yyval.reference)->node_type == cod_declaration) { @@ -3590,7 +3604,7 @@ yyparse () break; case 158: -#line 1505 "cod/cod.y" +#line 1519 "cod.y" { sm_list tmp = (yyvsp[(1) - (2)].list); while (tmp->next != NULL) { @@ -3602,7 +3616,7 @@ yyparse () break; case 160: -#line 1556 "cod/cod.y" +#line 1570 "cod.y" { (yyval.reference) = cod_new_initializer_list(); (yyval.reference)->node.initializer_list.initializers = (yyvsp[(2) - (3)].list); @@ -3610,7 +3624,7 @@ yyparse () break; case 161: -#line 1561 "cod/cod.y" +#line 1575 "cod.y" { (yyval.reference) = cod_new_initializer_list(); (yyval.reference)->node.initializer_list.initializers = (yyvsp[(2) - (4)].list); @@ -3618,12 +3632,12 @@ yyparse () break; case 162: -#line 1565 "cod/cod.y" +#line 1579 "cod.y" { (yyval.reference) = (yyvsp[(1) - (1)].reference);;} break; case 163: -#line 1570 "cod/cod.y" +#line 1584 "cod.y" { sm_ref initializer = cod_new_initializer(); initializer->node.initializer.designation = (yyvsp[(1) - (2)].list); @@ -3635,7 +3649,7 @@ yyparse () break; case 164: -#line 1578 "cod/cod.y" +#line 1592 "cod.y" { sm_ref initializer = cod_new_initializer(); initializer->node.initializer.designation = NULL; @@ -3647,7 +3661,7 @@ yyparse () break; case 165: -#line 1586 "cod/cod.y" +#line 1600 "cod.y" { sm_list tmp = (yyvsp[(1) - (4)].list); sm_ref initializer = cod_new_initializer(); @@ -3664,7 +3678,7 @@ yyparse () break; case 166: -#line 1599 "cod/cod.y" +#line 1613 "cod.y" { sm_list tmp = (yyvsp[(1) - (3)].list); sm_ref initializer = cod_new_initializer(); @@ -3681,12 +3695,12 @@ yyparse () break; case 167: -#line 1616 "cod/cod.y" +#line 1630 "cod.y" { (yyval.list) = (yyvsp[(1) - (2)].list);;} break; case 168: -#line 1620 "cod/cod.y" +#line 1634 "cod.y" { (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = (yyvsp[(1) - (1)].reference); @@ -3695,7 +3709,7 @@ yyparse () break; case 169: -#line 1625 "cod/cod.y" +#line 1639 "cod.y" { sm_list tmp = (yyvsp[(1) - (2)].list); while (tmp->next != NULL) { @@ -3709,7 +3723,7 @@ yyparse () break; case 170: -#line 1639 "cod/cod.y" +#line 1653 "cod.y" { (yyval.reference) = cod_new_designator(); (yyval.reference)->node.designator.expression = (yyvsp[(2) - (3)].reference); @@ -3718,7 +3732,7 @@ yyparse () break; case 171: -#line 1645 "cod/cod.y" +#line 1659 "cod.y" { (yyval.reference) = cod_new_designator(); (yyval.reference)->node.designator.expression = NULL; @@ -3727,7 +3741,7 @@ yyparse () break; case 172: -#line 1653 "cod/cod.y" +#line 1667 "cod.y" { sm_list tmp = malloc(sizeof(struct list_struct)); tmp->node = (yyvsp[(1) - (1)].reference); @@ -3737,21 +3751,21 @@ yyparse () break; case 173: -#line 1659 "cod/cod.y" +#line 1673 "cod.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; case 174: -#line 1662 "cod/cod.y" +#line 1676 "cod.y" { (yyval.list) = NULL; ;} break; case 175: -#line 1665 "cod/cod.y" +#line 1679 "cod.y" { sm_list tmp = malloc(sizeof(struct list_struct)); tmp->node = (yyvsp[(2) - (2)].reference); @@ -3761,14 +3775,14 @@ yyparse () break; case 176: -#line 1671 "cod/cod.y" +#line 1685 "cod.y" { (yyval.list) = cod_append_list((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].list)); ;} break; case 183: -#line 1688 "cod/cod.y" +#line 1702 "cod.y" { (yyval.reference) = cod_new_label_statement(); (yyval.reference)->node.label_statement.name = (yyvsp[(1) - (3)].info).string; @@ -3777,14 +3791,14 @@ yyparse () break; case 184: -#line 1695 "cod/cod.y" +#line 1709 "cod.y" { (yyval.reference) = cod_new_compound_statement(); ;} break; case 185: -#line 1698 "cod/cod.y" +#line 1712 "cod.y" { int count = (yyvsp[(1) - (3)].info).type_stack_count; (yyval.reference) = cod_new_compound_statement(); @@ -3794,12 +3808,12 @@ yyparse () break; case 186: -#line 1706 "cod/cod.y" +#line 1720 "cod.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; case 187: -#line 1708 "cod/cod.y" +#line 1722 "cod.y" { if ((yyvsp[(1) - (2)].list) == NULL) { (yyval.list) = (yyvsp[(2) - (2)].list); @@ -3815,7 +3829,7 @@ yyparse () break; case 188: -#line 1722 "cod/cod.y" +#line 1736 "cod.y" { (yyval.reference) = cod_new_return_statement(); (yyval.reference)->node.return_statement.expression = (yyvsp[(2) - (3)].reference); @@ -3824,7 +3838,7 @@ yyparse () break; case 189: -#line 1727 "cod/cod.y" +#line 1741 "cod.y" { (yyval.reference) = cod_new_return_statement(); (yyval.reference)->node.return_statement.expression = NULL; @@ -3833,7 +3847,7 @@ yyparse () break; case 190: -#line 1732 "cod/cod.y" +#line 1746 "cod.y" { (yyval.reference) = cod_new_jump_statement(); (yyval.reference)->node.jump_statement.continue_flag = 1; @@ -3843,7 +3857,7 @@ yyparse () break; case 191: -#line 1738 "cod/cod.y" +#line 1752 "cod.y" { (yyval.reference) = cod_new_jump_statement(); (yyval.reference)->node.jump_statement.continue_flag = 0; @@ -3853,7 +3867,7 @@ yyparse () break; case 192: -#line 1744 "cod/cod.y" +#line 1758 "cod.y" { (yyval.reference) = cod_new_jump_statement(); (yyval.reference)->node.jump_statement.continue_flag = 0; @@ -3863,14 +3877,14 @@ yyparse () break; case 193: -#line 1753 "cod/cod.y" +#line 1767 "cod.y" { (yyval.reference) = NULL; ;} break; case 194: -#line 1757 "cod/cod.y" +#line 1771 "cod.y" { (yyval.reference) = cod_new_expression_statement(); (yyval.reference)->node.expression_statement.expression = (yyvsp[(1) - (2)].reference); @@ -3878,7 +3892,7 @@ yyparse () break; case 195: -#line 1768 "cod/cod.y" +#line 1782 "cod.y" { (yyval.reference) = cod_new_selection_statement(); (yyval.reference)->node.selection_statement.lx_srcpos = (yyvsp[(1) - (5)].info).lx_srcpos; @@ -3889,7 +3903,7 @@ yyparse () break; case 196: -#line 1777 "cod/cod.y" +#line 1791 "cod.y" { (yyval.reference) = cod_new_selection_statement(); (yyval.reference)->node.selection_statement.lx_srcpos = (yyvsp[(1) - (7)].info).lx_srcpos; @@ -3900,7 +3914,7 @@ yyparse () break; case 197: -#line 1794 "cod/cod.y" +#line 1808 "cod.y" { (yyval.reference) = cod_new_iteration_statement(); (yyval.reference)->node.iteration_statement.lx_srcpos = (yyvsp[(1) - (9)].info).lx_srcpos; @@ -3912,7 +3926,7 @@ yyparse () break; case 198: -#line 1804 "cod/cod.y" +#line 1818 "cod.y" { (yyval.reference) = cod_new_iteration_statement(); (yyval.reference)->node.iteration_statement.lx_srcpos = (yyvsp[(1) - (5)].info).lx_srcpos; @@ -3924,7 +3938,7 @@ yyparse () break; case 199: -#line 1814 "cod/cod.y" +#line 1828 "cod.y" { (yyval.reference) = cod_new_iteration_statement(); (yyval.reference)->node.iteration_statement.lx_srcpos = (yyvsp[(1) - (7)].info).lx_srcpos; @@ -3937,12 +3951,12 @@ yyparse () break; case 200: -#line 1827 "cod/cod.y" +#line 1841 "cod.y" { (yyval.reference) = NULL; ;} break; case 202: -#line 1832 "cod/cod.y" +#line 1846 "cod.y" { (yyval.reference) = cod_new_constant(); (yyval.reference)->node.constant.token = integer_constant; @@ -3952,7 +3966,7 @@ yyparse () break; case 203: -#line 1839 "cod/cod.y" +#line 1853 "cod.y" { (yyval.reference) = cod_new_constant(); (yyval.reference)->node.constant.token = floating_constant; @@ -3962,7 +3976,7 @@ yyparse () break; case 204: -#line 1846 "cod/cod.y" +#line 1860 "cod.y" { (yyval.reference) = cod_new_constant(); (yyval.reference)->node.constant.token = string_constant; @@ -3972,7 +3986,7 @@ yyparse () break; case 205: -#line 1853 "cod/cod.y" +#line 1867 "cod.y" { (yyval.reference) = cod_new_constant(); (yyval.reference)->node.constant.token = character_constant; @@ -3982,7 +3996,7 @@ yyparse () break; case 206: -#line 1860 "cod/cod.y" +#line 1874 "cod.y" { (yyval.reference) = cod_new_constant(); (yyval.reference)->node.constant.token = character_constant; @@ -3993,7 +4007,7 @@ yyparse () /* Line 1267 of yacc.c. */ -#line 3997 "/Users/eisen/prog/ffs/build/cod.tab.c" +#line 4011 "cod.tab.c" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -4207,8 +4221,11 @@ yyparse () } -#line 1868 "cod/cod.y" +#line 1882 "cod.y" +#ifdef _MSC_VER +#define YY_NO_UNISTD_H +#endif #include "lex.yy.c" typedef struct scope *scope_ptr; @@ -4273,7 +4290,7 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) { char *out; char *ptr; - if (index(input, '#') == NULL) return NULL; + if (strchr(input, '#') == NULL) return NULL; out = strdup(input); ptr = out; *white = 0; @@ -4287,10 +4304,10 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) char *include_end; ptr += 8; while(isspace(*ptr)) ptr++; - line_end = index(ptr, '\n'); + line_end = strchr(ptr, '\n'); if (line_end) *line_end = 0; if ((*ptr == '<') || (*ptr == '"')) { - include_end = (*ptr == '<') ? index(ptr, '>') : index((ptr+1), '"'); + include_end = (*ptr == '<') ? strchr(ptr, '>') : strchr((ptr+1), '"'); if (!include_end) { printf("improper #include, \"%s\"\n", ptr); goto skip; @@ -4311,10 +4328,10 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) } skip: /* skip to next line */ - ptr = index(ptr, '\n'); + ptr = strchr(ptr, '\n'); while (ptr && (*(ptr - 1) == '\'')) { /* continued line */ - ptr = index(ptr, '\n'); + ptr = strchr(ptr, '\n'); } } { @@ -4329,9 +4346,7 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) } int -cod_parse_for_globals(code, context) -char *code; -cod_parse_context context; +cod_parse_for_globals(char *code, cod_parse_context context) { int ret; context->alloc_globals = 1; @@ -4340,9 +4355,7 @@ cod_parse_context context; return ret; } int -cod_parse_for_context(code, context) -char *code; -cod_parse_context context; +cod_parse_for_context(char *code, cod_parse_context context) { sm_list decls; int ret; @@ -4407,12 +4420,10 @@ static int include_prefix(char *code) break; } } - return tmp - code; + return (int)(intptr_t)(tmp - code); } cod_code -cod_code_gen(code, context) -char *code; -cod_parse_context context; +cod_code_gen(char *code, cod_parse_context context) { sm_ref tmp, tmp2; cod_code ret_code; @@ -4423,7 +4434,7 @@ cod_parse_context context; if (code != NULL) { if ((bracket = include_prefix(code))) { char *prefix = malloc(bracket+1), *tmp; - strncpy(prefix, code, bracket); + strncpy(prefix, code, bracket + 1); prefix[bracket] = 0; tmp = prefix; while(isspace(*tmp)) tmp++; @@ -4475,7 +4486,7 @@ cod_parse_context context; tmp->node.compound_statement.decls = NULL; tmp2->node.compound_statement.decls = NULL; cod_rfree(tmp2); - ret_code->func = (void(*)())(long)func; + ret_code->func = (void(*)(void))(intptr_t)func; return ret_code; } @@ -4493,9 +4504,7 @@ cod_dump(cod_code code) int -cod_code_verify(code, context) -char *code; -cod_parse_context context; +cod_code_verify(char *code, cod_parse_context context) { sm_ref tmp; @@ -4533,8 +4542,7 @@ cod_parse_context context; } extern void -cod_code_free(code) -cod_code code; +cod_code_free(cod_code code) { if (code->code_memory_block) free(code->code_memory_block); if (code->data) free(code->data); @@ -4594,7 +4602,7 @@ print_context(cod_parse_context context, int line, int character) offset = character - 40; } line_copy = copy_line(line_begin + offset); - line_len = strlen(line_copy); + line_len = (int)strlen(line_copy); if (line_len > 60) { line_copy[60] = 0; } @@ -4611,8 +4619,7 @@ print_context(cod_parse_context context, int line, int character) context->error_func(context->client_data, "^\n"); } -void yyerror(str) -char *str; +void yyerror(char *str) { char tmp_str[100]; sprintf(tmp_str, "## Error %s\n", str); @@ -4806,8 +4813,7 @@ struct scope { extern cod_parse_context -cod_copy_context(context) -cod_parse_context context; +cod_copy_context(cod_parse_context context) { int i, count; int type_count = 0; @@ -4844,8 +4850,7 @@ cod_parse_context context; extern void dump_scope(scope_ptr scope); extern cod_parse_context -cod_copy_globals(context) -cod_parse_context context; +cod_copy_globals(cod_parse_context context) { int i, count; int type_count = 0; @@ -5184,7 +5189,7 @@ determine_op_type(cod_parse_context context, sm_ref expr, if ((left_type == DILL_UL) || (right_type == DILL_UL)) return DILL_UL; if ((left_type == DILL_L) || (right_type == DILL_L)) { /* GSE -bug This test should be for *generated* target, not host */ - if (sizeof(long) > sizeof(unsigned int)) { + if (sizeof(intptr_t) > sizeof(unsigned int)) { /* Long can represent all values of unsigned int */ return DILL_L; } else { @@ -5535,7 +5540,7 @@ type_list_to_string(cod_parse_context context, sm_list type_list, int *size) *size = sizeof(int); return strdup("integer"); case DILL_L: - *size = sizeof(long); + *size = sizeof(intptr_t); return strdup("integer"); case DILL_S: *size = sizeof(short); @@ -5544,7 +5549,7 @@ type_list_to_string(cod_parse_context context, sm_list type_list, int *size) *size = sizeof(int); return strdup("unsigned integer"); case DILL_UL: - *size = sizeof(long); + *size = sizeof(intptr_t); return strdup("unsigned integer"); case DILL_US: *size = sizeof(short); @@ -6448,7 +6453,7 @@ unsigned long, long long, unsigned long long */ long i; - int len = strlen(val); + int len = (int)strlen(val); int hex = 0; int specified_unsgned = 0, specified_lng = 0; if (val[0] == '0') { @@ -7947,9 +7952,7 @@ cod_remove_defined_types(cod_parse_context context, int count) } void -cod_add_defined_type(id, context) -char *id; -cod_parse_context context; +cod_add_defined_type(char *id, cod_parse_context context) { int count = 0; while(context->defined_types && context->defined_types[count]) count++; @@ -7966,9 +7969,7 @@ cod_parse_context context; } void -cod_add_enum_const(id, context) -char *id; -cod_parse_context context; +cod_add_enum_const(char *id, cod_parse_context context) { int count = 0; while(context->enumerated_constants && context->enumerated_constants[count]) count++; @@ -8009,9 +8010,7 @@ cod_add_struct_type(FMStructDescList format_list, } static int -str_to_data_type(str, size) -char *str; -int size; +str_to_data_type(char *str, int size) { char *tmp = malloc(strlen(str) + 1); char *free_str = tmp; @@ -8033,7 +8032,7 @@ int size; } if ((strcmp(str, "integer") == 0) || (strcmp(str, "enumeration") == 0)) { free(free_str); - if (size == sizeof(long)) { + if (size == sizeof(intptr_t)) { return DILL_L; } else if (size == sizeof(int)) { return DILL_I; @@ -8046,7 +8045,7 @@ int size; } } else if (strcmp(str, "unsigned integer") == 0) { free(free_str); - if (size == sizeof(long)) { + if (size == sizeof(intptr_t)) { return DILL_UL; } else if (size == sizeof(int)) { return DILL_U; @@ -8081,9 +8080,7 @@ int size; } static int -array_str_to_data_type(str, size) -char *str; -int size; +array_str_to_data_type(char *str, int size) { int ret_type; char field_type[1024]; @@ -8103,14 +8100,8 @@ int size; } static sm_ref -build_subtype_nodes(context, decl, f, desc, err, scope, must_free_p) -cod_parse_context context; -sm_ref decl; -field* f; -FMTypeDesc *desc; -int *err; -scope_ptr scope; -int *must_free_p; +build_subtype_nodes(cod_parse_context context, sm_ref decl, field* f, FMTypeDesc *desc, + int *err, scope_ptr scope, int *must_free_p) { sm_ref ret = NULL; sm_ref subtype = NULL; @@ -8206,8 +8197,8 @@ int *must_free_p; ret->node.reference_type_decl.cg_referenced_type = DILL_ERR; ret->node.reference_type_decl.sm_complex_referenced_type = subtype; if (must_free_flag) { - if (ret->node.array_type_decl.freeable_complex_element_type) { - cod_rfree(ret->node.array_type_decl.freeable_complex_element_type); + if (ret->node.reference_type_decl.freeable_complex_referenced_type) { + cod_rfree(ret->node.reference_type_decl.freeable_complex_referenced_type); } ret->node.reference_type_decl.freeable_complex_referenced_type = subtype; } @@ -8233,16 +8224,8 @@ int *must_free_p; } static void -build_type_nodes(context, decl, f, fields, cg_size, cg_type, desc, err, scope) -cod_parse_context context; -sm_ref decl; -field* f; -sm_list fields; -int cg_size; -int cg_type; -FMTypeDesc* desc; -int *err; -scope_ptr scope; +build_type_nodes(cod_parse_context context, sm_ref decl, field* f, sm_list fields, + int cg_size, int cg_type, FMTypeDesc* desc, int *err, scope_ptr scope) { int must_free_flag = 0; sm_ref complex_type = build_subtype_nodes(context, decl, f, desc, err, scope, &must_free_flag); @@ -8256,13 +8239,7 @@ scope_ptr scope; } static int -semanticize_array_element_node(context, array, super_type, base_type_spec, - scope) -cod_parse_context context; -sm_ref array; -sm_ref super_type; -sm_list base_type_spec; -scope_ptr scope; +semanticize_array_element_node(cod_parse_context context, sm_ref array, sm_ref super_type, sm_list base_type_spec, scope_ptr scope) { if (array->node.array_type_decl.size_expr != NULL) { if (!is_constant_expr(array->node.array_type_decl.size_expr)) { @@ -8330,10 +8307,7 @@ scope_ptr scope; } static int -semanticize_array_type_node(context, array, scope) -cod_parse_context context; -sm_ref array; -scope_ptr scope; +semanticize_array_type_node(cod_parse_context context, sm_ref array, scope_ptr scope) { if (!array->node.array_type_decl.dimensions) { array->node.array_type_decl.dimensions = malloc(sizeof(dimen_s)); @@ -8837,7 +8811,7 @@ static void uniqueify_names(FMStructDescList list, char *prefix) { int i = 0; - int prefix_len = strlen(prefix); + int prefix_len = (int)strlen(prefix); while (list[i].format_name != NULL) { int j = 0; FMFieldList fl = list[i].field_list; @@ -8845,14 +8819,14 @@ uniqueify_names(FMStructDescList list, char *prefix) malloc(strlen(list[i].format_name) + prefix_len + 1); strcpy(new_name, prefix); strcpy(new_name + prefix_len, list[i].format_name); - free(list[i].format_name); + free((char*)list[i].format_name); list[i].format_name = new_name; while (fl[j].field_name != 0) { - int field_type_len = strlen(fl[j].field_type); + int field_type_len = (int)strlen(fl[j].field_type); char *bracket = strchr(fl[j].field_type, '['); int k; if (bracket != NULL) { - field_type_len = (long) bracket - (long) fl[j].field_type; + field_type_len = (int)((intptr_t) bracket - (intptr_t) fl[j].field_type); } for (k = 0; k < i; k++) { char *new_type; @@ -8940,9 +8914,10 @@ get_constant_float_value(cod_parse_context context, sm_ref expr) default: assert(FALSE); } + return 0.0; } -static long +static intptr_t get_constant_long_value(cod_parse_context context, sm_ref expr) { double dresult; @@ -8961,6 +8936,7 @@ get_constant_long_value(cod_parse_context context, sm_ref expr) default: assert(FALSE); } + return -1; } extern sm_ref @@ -9054,7 +9030,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ is_ivalue=1; break; case op_eq: - ivalue = left_val = right_val; + ivalue = left_val == right_val; is_ivalue=1; break; case op_neq: @@ -9099,7 +9075,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ *free_result = 1; } else { /* we get an integer result */ - long left_val = 0, right_val = 0, value; + intptr_t left_val = 0, right_val = 0, value; char str_val[40]; if (expr->node.operator.left) left_val = get_constant_long_value(context, left); @@ -9178,7 +9154,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ } ret = cod_new_constant(); ret->node.constant.token = integer_constant; - sprintf(str_val, "%ld", value); + sprintf(str_val, "%zd", value); ret->node.constant.const_val = strdup(str_val); *free_result = 1; } @@ -9200,6 +9176,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ default: assert(FALSE); } + return NULL; } diff --git a/cod/pregen_source/Linux/cod.y b/cod/pregen_source/Linux/cod.y index 6fcf832a75..5d21652bd8 100644 --- a/cod/pregen_source/Linux/cod.y +++ b/cod/pregen_source/Linux/cod.y @@ -1,5 +1,8 @@ %{ #include "config.h" +#ifdef __NVCOMPILER +#pragma diag_suppress 550, 111, 941 +#endif #if defined (__INTEL_COMPILER) # pragma warning (disable: 2215) #endif @@ -31,10 +34,6 @@ int cod_kplugins_integration = 0; #include #endif #endif -#include "fm.h" -#include "fm_internal.h" -#include "cod.h" -#include "cod_internal.h" #undef NDEBUG #include "assert.h" #ifndef LINUX_KERNEL_MODULE @@ -58,6 +57,10 @@ int cod_kplugins_integration = 0; #define OP_DBL_Digs (DBL_DIG + 3) #endif #endif +#include "fm.h" +#include "fm_internal.h" +#include "cod.h" +#include "cod_internal.h" #include "structs.h" #ifdef HAVE_DILL_H #include "dill.h" @@ -79,9 +82,17 @@ enum { DILL_EC, DILL_ERR /* no type */ }; +typedef void *dill_stream; +#define dill_create_stream() 0 +#define dill_type_size(c, s) 0 #endif #if defined(_MSC_VER) #define strdup _strdup +#define isatty _isatty +#define fileno _fileno +#include +#include +#include #endif #ifndef LINUX_KERNEL_MODULE #ifdef STDC_HEADERS @@ -106,14 +117,17 @@ char *strdup(const char *s) return p; } #endif +#ifdef _MSC_VER +#undef strncpy +#endif #define YY_NO_INPUT static char* gen_anon() { static int anon_count = 0; - char *ret = malloc(strlen("Anonymous-xxxxxxxxxxxxxxxxx")); - sprintf(ret, "Anonymous-%d", anon_count++); + char *ret = malloc(40); + snprintf(ret, 40, "Anonymous-%d", anon_count++); return ret; } @@ -1866,6 +1880,9 @@ constant : ; %% +#ifdef _MSC_VER +#define YY_NO_UNISTD_H +#endif #include "lex.yy.c" typedef struct scope *scope_ptr; @@ -1930,7 +1947,7 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) { char *out; char *ptr; - if (index(input, '#') == NULL) return NULL; + if (strchr(input, '#') == NULL) return NULL; out = strdup(input); ptr = out; *white = 0; @@ -1944,10 +1961,10 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) char *include_end; ptr += 8; while(isspace(*ptr)) ptr++; - line_end = index(ptr, '\n'); + line_end = strchr(ptr, '\n'); if (line_end) *line_end = 0; if ((*ptr == '<') || (*ptr == '"')) { - include_end = (*ptr == '<') ? index(ptr, '>') : index((ptr+1), '"'); + include_end = (*ptr == '<') ? strchr(ptr, '>') : strchr((ptr+1), '"'); if (!include_end) { printf("improper #include, \"%s\"\n", ptr); goto skip; @@ -1968,10 +1985,10 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) } skip: /* skip to next line */ - ptr = index(ptr, '\n'); + ptr = strchr(ptr, '\n'); while (ptr && (*(ptr - 1) == '\'')) { /* continued line */ - ptr = index(ptr, '\n'); + ptr = strchr(ptr, '\n'); } } { @@ -1986,9 +2003,7 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) } int -cod_parse_for_globals(code, context) -char *code; -cod_parse_context context; +cod_parse_for_globals(char *code, cod_parse_context context) { int ret; context->alloc_globals = 1; @@ -1997,9 +2012,7 @@ cod_parse_context context; return ret; } int -cod_parse_for_context(code, context) -char *code; -cod_parse_context context; +cod_parse_for_context(char *code, cod_parse_context context) { sm_list decls; int ret; @@ -2064,12 +2077,10 @@ static int include_prefix(char *code) break; } } - return tmp - code; + return (int)(intptr_t)(tmp - code); } cod_code -cod_code_gen(code, context) -char *code; -cod_parse_context context; +cod_code_gen(char *code, cod_parse_context context) { sm_ref tmp, tmp2; cod_code ret_code; @@ -2080,7 +2091,7 @@ cod_parse_context context; if (code != NULL) { if ((bracket = include_prefix(code))) { char *prefix = malloc(bracket+1), *tmp; - strncpy(prefix, code, bracket); + strncpy(prefix, code, bracket + 1); prefix[bracket] = 0; tmp = prefix; while(isspace(*tmp)) tmp++; @@ -2132,7 +2143,7 @@ cod_parse_context context; tmp->node.compound_statement.decls = NULL; tmp2->node.compound_statement.decls = NULL; cod_rfree(tmp2); - ret_code->func = (void(*)())(long)func; + ret_code->func = (void(*)(void))(intptr_t)func; return ret_code; } @@ -2150,9 +2161,7 @@ cod_dump(cod_code code) int -cod_code_verify(code, context) -char *code; -cod_parse_context context; +cod_code_verify(char *code, cod_parse_context context) { sm_ref tmp; @@ -2190,8 +2199,7 @@ cod_parse_context context; } extern void -cod_code_free(code) -cod_code code; +cod_code_free(cod_code code) { if (code->code_memory_block) free(code->code_memory_block); if (code->data) free(code->data); @@ -2251,7 +2259,7 @@ print_context(cod_parse_context context, int line, int character) offset = character - 40; } line_copy = copy_line(line_begin + offset); - line_len = strlen(line_copy); + line_len = (int)strlen(line_copy); if (line_len > 60) { line_copy[60] = 0; } @@ -2268,8 +2276,7 @@ print_context(cod_parse_context context, int line, int character) context->error_func(context->client_data, "^\n"); } -void yyerror(str) -char *str; +void yyerror(char *str) { char tmp_str[100]; sprintf(tmp_str, "## Error %s\n", str); @@ -2463,8 +2470,7 @@ struct scope { extern cod_parse_context -cod_copy_context(context) -cod_parse_context context; +cod_copy_context(cod_parse_context context) { int i, count; int type_count = 0; @@ -2501,8 +2507,7 @@ cod_parse_context context; extern void dump_scope(scope_ptr scope); extern cod_parse_context -cod_copy_globals(context) -cod_parse_context context; +cod_copy_globals(cod_parse_context context) { int i, count; int type_count = 0; @@ -2841,7 +2846,7 @@ determine_op_type(cod_parse_context context, sm_ref expr, if ((left_type == DILL_UL) || (right_type == DILL_UL)) return DILL_UL; if ((left_type == DILL_L) || (right_type == DILL_L)) { /* GSE -bug This test should be for *generated* target, not host */ - if (sizeof(long) > sizeof(unsigned int)) { + if (sizeof(intptr_t) > sizeof(unsigned int)) { /* Long can represent all values of unsigned int */ return DILL_L; } else { @@ -3192,7 +3197,7 @@ type_list_to_string(cod_parse_context context, sm_list type_list, int *size) *size = sizeof(int); return strdup("integer"); case DILL_L: - *size = sizeof(long); + *size = sizeof(intptr_t); return strdup("integer"); case DILL_S: *size = sizeof(short); @@ -3201,7 +3206,7 @@ type_list_to_string(cod_parse_context context, sm_list type_list, int *size) *size = sizeof(int); return strdup("unsigned integer"); case DILL_UL: - *size = sizeof(long); + *size = sizeof(intptr_t); return strdup("unsigned integer"); case DILL_US: *size = sizeof(short); @@ -4105,7 +4110,7 @@ unsigned long, long long, unsigned long long */ long i; - int len = strlen(val); + int len = (int)strlen(val); int hex = 0; int specified_unsgned = 0, specified_lng = 0; if (val[0] == '0') { @@ -5604,9 +5609,7 @@ cod_remove_defined_types(cod_parse_context context, int count) } void -cod_add_defined_type(id, context) -char *id; -cod_parse_context context; +cod_add_defined_type(char *id, cod_parse_context context) { int count = 0; while(context->defined_types && context->defined_types[count]) count++; @@ -5623,9 +5626,7 @@ cod_parse_context context; } void -cod_add_enum_const(id, context) -char *id; -cod_parse_context context; +cod_add_enum_const(char *id, cod_parse_context context) { int count = 0; while(context->enumerated_constants && context->enumerated_constants[count]) count++; @@ -5666,9 +5667,7 @@ cod_add_struct_type(FMStructDescList format_list, } static int -str_to_data_type(str, size) -char *str; -int size; +str_to_data_type(char *str, int size) { char *tmp = malloc(strlen(str) + 1); char *free_str = tmp; @@ -5690,7 +5689,7 @@ int size; } if ((strcmp(str, "integer") == 0) || (strcmp(str, "enumeration") == 0)) { free(free_str); - if (size == sizeof(long)) { + if (size == sizeof(intptr_t)) { return DILL_L; } else if (size == sizeof(int)) { return DILL_I; @@ -5703,7 +5702,7 @@ int size; } } else if (strcmp(str, "unsigned integer") == 0) { free(free_str); - if (size == sizeof(long)) { + if (size == sizeof(intptr_t)) { return DILL_UL; } else if (size == sizeof(int)) { return DILL_U; @@ -5738,9 +5737,7 @@ int size; } static int -array_str_to_data_type(str, size) -char *str; -int size; +array_str_to_data_type(char *str, int size) { int ret_type; char field_type[1024]; @@ -5760,14 +5757,8 @@ int size; } static sm_ref -build_subtype_nodes(context, decl, f, desc, err, scope, must_free_p) -cod_parse_context context; -sm_ref decl; -field* f; -FMTypeDesc *desc; -int *err; -scope_ptr scope; -int *must_free_p; +build_subtype_nodes(cod_parse_context context, sm_ref decl, field* f, FMTypeDesc *desc, + int *err, scope_ptr scope, int *must_free_p) { sm_ref ret = NULL; sm_ref subtype = NULL; @@ -5863,8 +5854,8 @@ int *must_free_p; ret->node.reference_type_decl.cg_referenced_type = DILL_ERR; ret->node.reference_type_decl.sm_complex_referenced_type = subtype; if (must_free_flag) { - if (ret->node.array_type_decl.freeable_complex_element_type) { - cod_rfree(ret->node.array_type_decl.freeable_complex_element_type); + if (ret->node.reference_type_decl.freeable_complex_referenced_type) { + cod_rfree(ret->node.reference_type_decl.freeable_complex_referenced_type); } ret->node.reference_type_decl.freeable_complex_referenced_type = subtype; } @@ -5890,16 +5881,8 @@ int *must_free_p; } static void -build_type_nodes(context, decl, f, fields, cg_size, cg_type, desc, err, scope) -cod_parse_context context; -sm_ref decl; -field* f; -sm_list fields; -int cg_size; -int cg_type; -FMTypeDesc* desc; -int *err; -scope_ptr scope; +build_type_nodes(cod_parse_context context, sm_ref decl, field* f, sm_list fields, + int cg_size, int cg_type, FMTypeDesc* desc, int *err, scope_ptr scope) { int must_free_flag = 0; sm_ref complex_type = build_subtype_nodes(context, decl, f, desc, err, scope, &must_free_flag); @@ -5913,13 +5896,7 @@ scope_ptr scope; } static int -semanticize_array_element_node(context, array, super_type, base_type_spec, - scope) -cod_parse_context context; -sm_ref array; -sm_ref super_type; -sm_list base_type_spec; -scope_ptr scope; +semanticize_array_element_node(cod_parse_context context, sm_ref array, sm_ref super_type, sm_list base_type_spec, scope_ptr scope) { if (array->node.array_type_decl.size_expr != NULL) { if (!is_constant_expr(array->node.array_type_decl.size_expr)) { @@ -5987,10 +5964,7 @@ scope_ptr scope; } static int -semanticize_array_type_node(context, array, scope) -cod_parse_context context; -sm_ref array; -scope_ptr scope; +semanticize_array_type_node(cod_parse_context context, sm_ref array, scope_ptr scope) { if (!array->node.array_type_decl.dimensions) { array->node.array_type_decl.dimensions = malloc(sizeof(dimen_s)); @@ -6494,7 +6468,7 @@ static void uniqueify_names(FMStructDescList list, char *prefix) { int i = 0; - int prefix_len = strlen(prefix); + int prefix_len = (int)strlen(prefix); while (list[i].format_name != NULL) { int j = 0; FMFieldList fl = list[i].field_list; @@ -6502,14 +6476,14 @@ uniqueify_names(FMStructDescList list, char *prefix) malloc(strlen(list[i].format_name) + prefix_len + 1); strcpy(new_name, prefix); strcpy(new_name + prefix_len, list[i].format_name); - free(list[i].format_name); + free((char*)list[i].format_name); list[i].format_name = new_name; while (fl[j].field_name != 0) { - int field_type_len = strlen(fl[j].field_type); + int field_type_len = (int)strlen(fl[j].field_type); char *bracket = strchr(fl[j].field_type, '['); int k; if (bracket != NULL) { - field_type_len = (long) bracket - (long) fl[j].field_type; + field_type_len = (int)((intptr_t) bracket - (intptr_t) fl[j].field_type); } for (k = 0; k < i; k++) { char *new_type; @@ -6597,9 +6571,10 @@ get_constant_float_value(cod_parse_context context, sm_ref expr) default: assert(FALSE); } + return 0.0; } -static long +static intptr_t get_constant_long_value(cod_parse_context context, sm_ref expr) { double dresult; @@ -6618,6 +6593,7 @@ get_constant_long_value(cod_parse_context context, sm_ref expr) default: assert(FALSE); } + return -1; } extern sm_ref @@ -6711,7 +6687,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ is_ivalue=1; break; case op_eq: - ivalue = left_val = right_val; + ivalue = left_val == right_val; is_ivalue=1; break; case op_neq: @@ -6756,7 +6732,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ *free_result = 1; } else { /* we get an integer result */ - long left_val = 0, right_val = 0, value; + intptr_t left_val = 0, right_val = 0, value; char str_val[40]; if (expr->node.operator.left) left_val = get_constant_long_value(context, left); @@ -6835,7 +6811,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ } ret = cod_new_constant(); ret->node.constant.token = integer_constant; - sprintf(str_val, "%ld", value); + sprintf(str_val, "%zd", value); ret->node.constant.const_val = strdup(str_val); *free_result = 1; } @@ -6857,5 +6833,6 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ default: assert(FALSE); } + return NULL; } diff --git a/cod/pregen_source/Windows/cod.l b/cod/pregen_source/Windows/cod.l index 1aeba7fb0f..fd5517b57a 100644 --- a/cod/pregen_source/Windows/cod.l +++ b/cod/pregen_source/Windows/cod.l @@ -71,8 +71,7 @@ extern int my_yy_input(); #endif static int -is_defined_type(id) -char *id; +is_defined_type(char *id) { int i = 0; while(types && types[i]) { @@ -83,8 +82,7 @@ char *id; } static int -is_enumeration_constant(id) -char *id; +is_enumeration_constant(char *id) { int i = 0; while(enums && enums[i]) { @@ -329,7 +327,7 @@ static char *create_string_from_yytext() static void check_strbuf() { - int cur_len = string_buf_ptr - string_buffer; + intptr_t cur_len = string_buf_ptr - string_buffer; if ((cur_len + 1) == buffer_len) { buffer_len += 20; string_buffer = realloc(string_buffer, buffer_len + 1); @@ -429,19 +427,14 @@ char **enum_constants; static YY_BUFFER_STATE bb = NULL; static void -reset_types_table(defined_types, enumerated_constants) -char **defined_types; -char **enumerated_constants; +reset_types_table(char **defined_types, char **enumerated_constants) { types = defined_types; enums = enumerated_constants; } static void -setup_for_string_parse(string, defined_types, enum_constants) -const char *string; -char **defined_types; -char **enum_constants; +setup_for_string_parse(const char *string, char **defined_types, char **enum_constants) { types = defined_types; enums = enum_constants; diff --git a/cod/pregen_source/Windows/cod.tab.c b/cod/pregen_source/Windows/cod.tab.c index 1d42833f97..55f7fbfbdb 100644 --- a/cod/pregen_source/Windows/cod.tab.c +++ b/cod/pregen_source/Windows/cod.tab.c @@ -1,14 +1,14 @@ -/* A Bison parser, made by GNU Bison 2.3. */ +/* A Bison parser, made by GNU Bison 3.8.2. */ -/* Skeleton implementation for Bison's Yacc-like parsers in C +/* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 - Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, + Inc. - This program is free software; you can redistribute it and/or modify + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -16,9 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -36,6 +34,10 @@ /* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. */ +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ + /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. @@ -43,11 +45,11 @@ define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ -/* Identify Bison output. */ -#define YYBISON 1 +/* Identify Bison output, and Bison version. */ +#define YYBISON 30802 -/* Bison version. */ -#define YYBISON_VERSION "2.3" +/* Bison version string. */ +#define YYBISON_VERSION "3.8.2" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -55,192 +57,22 @@ /* Pure parsers. */ #define YYPURE 0 -/* Using locations. */ -#define YYLSP_NEEDED 0 +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 -/* Tokens. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - ARROW = 258, - LPAREN = 259, - RPAREN = 260, - LCURLY = 261, - RCURLY = 262, - COLON = 263, - QUESTION = 264, - LBRACKET = 265, - RBRACKET = 266, - DOT = 267, - STAR = 268, - AT = 269, - SLASH = 270, - MODULUS = 271, - PLUS = 272, - MINUS = 273, - TILDE = 274, - LEQ = 275, - LT = 276, - GEQ = 277, - GT = 278, - EQ = 279, - NEQ = 280, - LEFT_SHIFT = 281, - RIGHT_SHIFT = 282, - ASSIGN = 283, - MUL_ASSIGN = 284, - DIV_ASSIGN = 285, - MOD_ASSIGN = 286, - ADD_ASSIGN = 287, - SUB_ASSIGN = 288, - LEFT_ASSIGN = 289, - RIGHT_ASSIGN = 290, - AND_ASSIGN = 291, - XOR_ASSIGN = 292, - OR_ASSIGN = 293, - LOG_OR = 294, - LOG_AND = 295, - ARITH_OR = 296, - ARITH_AND = 297, - ARITH_XOR = 298, - INC_OP = 299, - DEC_OP = 300, - BANG = 301, - SEMI = 302, - IF = 303, - ELSE = 304, - FOR = 305, - DO = 306, - WHILE = 307, - CHAR = 308, - SHORT = 309, - INT = 310, - LONG = 311, - UNSIGNED = 312, - SIGNED = 313, - FLOAT = 314, - DOUBLE = 315, - VOID = 316, - STRING = 317, - STATIC = 318, - EXTERN_TOKEN = 319, - STRUCT = 320, - ENUM = 321, - UNION = 322, - CONST = 323, - SIZEOF = 324, - TYPEDEF = 325, - RETURN_TOKEN = 326, - CONTINUE = 327, - BREAK = 328, - GOTO = 329, - PRINT = 330, - COMMA = 331, - DOTDOTDOT = 332, - integer_constant = 333, - character_constant = 334, - string_constant = 335, - floating_constant = 336, - identifier_ref = 337, - type_id = 338, - enumeration_constant = 339 - }; -#endif -/* Tokens. */ -#define ARROW 258 -#define LPAREN 259 -#define RPAREN 260 -#define LCURLY 261 -#define RCURLY 262 -#define COLON 263 -#define QUESTION 264 -#define LBRACKET 265 -#define RBRACKET 266 -#define DOT 267 -#define STAR 268 -#define AT 269 -#define SLASH 270 -#define MODULUS 271 -#define PLUS 272 -#define MINUS 273 -#define TILDE 274 -#define LEQ 275 -#define LT 276 -#define GEQ 277 -#define GT 278 -#define EQ 279 -#define NEQ 280 -#define LEFT_SHIFT 281 -#define RIGHT_SHIFT 282 -#define ASSIGN 283 -#define MUL_ASSIGN 284 -#define DIV_ASSIGN 285 -#define MOD_ASSIGN 286 -#define ADD_ASSIGN 287 -#define SUB_ASSIGN 288 -#define LEFT_ASSIGN 289 -#define RIGHT_ASSIGN 290 -#define AND_ASSIGN 291 -#define XOR_ASSIGN 292 -#define OR_ASSIGN 293 -#define LOG_OR 294 -#define LOG_AND 295 -#define ARITH_OR 296 -#define ARITH_AND 297 -#define ARITH_XOR 298 -#define INC_OP 299 -#define DEC_OP 300 -#define BANG 301 -#define SEMI 302 -#define IF 303 -#define ELSE 304 -#define FOR 305 -#define DO 306 -#define WHILE 307 -#define CHAR 308 -#define SHORT 309 -#define INT 310 -#define LONG 311 -#define UNSIGNED 312 -#define SIGNED 313 -#define FLOAT 314 -#define DOUBLE 315 -#define VOID 316 -#define STRING 317 -#define STATIC 318 -#define EXTERN_TOKEN 319 -#define STRUCT 320 -#define ENUM 321 -#define UNION 322 -#define CONST 323 -#define SIZEOF 324 -#define TYPEDEF 325 -#define RETURN_TOKEN 326 -#define CONTINUE 327 -#define BREAK 328 -#define GOTO 329 -#define PRINT 330 -#define COMMA 331 -#define DOTDOTDOT 332 -#define integer_constant 333 -#define character_constant 334 -#define string_constant 335 -#define floating_constant 336 -#define identifier_ref 337 -#define type_id 338 -#define enumeration_constant 339 - - - - -/* Copy the first part of user declarations. */ -#line 1 "cod/cod.y" + +/* First part of user prologue. */ +#line 1 "cod.y" #include "config.h" +#ifdef __NVCOMPILER +#pragma diag_suppress 550, 111, 941 +#endif #if defined (__INTEL_COMPILER) # pragma warning (disable: 2215) #endif @@ -272,10 +104,6 @@ int cod_kplugins_integration = 0; #include #endif #endif -#include "fm.h" -#include "fm_internal.h" -#include "cod.h" -#include "cod_internal.h" #undef NDEBUG #include "assert.h" #ifndef LINUX_KERNEL_MODULE @@ -299,6 +127,10 @@ int cod_kplugins_integration = 0; #define OP_DBL_Digs (DBL_DIG + 3) #endif #endif +#include "fm.h" +#include "fm_internal.h" +#include "cod.h" +#include "cod_internal.h" #include "structs.h" #ifdef HAVE_DILL_H #include "dill.h" @@ -320,9 +152,17 @@ enum { DILL_EC, DILL_ERR /* no type */ }; +typedef void *dill_stream; +#define dill_create_stream() 0 +#define dill_type_size(c, s) 0 #endif #if defined(_MSC_VER) #define strdup _strdup +#define isatty _isatty +#define fileno _fileno +#include +#include +#include #endif #ifndef LINUX_KERNEL_MODULE #ifdef STDC_HEADERS @@ -347,14 +187,17 @@ char *strdup(const char *s) return p; } #endif +#ifdef _MSC_VER +#undef strncpy +#endif #define YY_NO_INPUT static char* gen_anon() { static int anon_count = 0; - char *ret = malloc(strlen("Anonymous-xxxxxxxxxxxxxxxxx")); - sprintf(ret, "Anonymous-%d", anon_count++); + char *ret = malloc(40); + snprintf(ret, 40, "Anonymous-%d", anon_count++); return ret; } @@ -423,80 +266,408 @@ cod_dup_list(sm_list list) return ret_list; } +#line 270 "cod.tab.c" + +# ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast (Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) +# else +# define YY_CAST(Type, Val) ((Type) (Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) +# endif +# endif +# ifndef YY_NULLPTR +# if defined __cplusplus +# if 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif +# else +# define YY_NULLPTR ((void*)0) +# endif +# endif + -/* Enabling traces. */ +/* Debug traces. */ #ifndef YYDEBUG # define YYDEBUG 0 #endif - -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 0 +#if YYDEBUG +extern int yydebug; #endif -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE 0 +/* Token kinds. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + enum yytokentype + { + YYEMPTY = -2, + YYEOF = 0, /* "end of file" */ + YYerror = 256, /* error */ + YYUNDEF = 257, /* "invalid token" */ + ARROW = 258, /* ARROW */ + LPAREN = 259, /* LPAREN */ + RPAREN = 260, /* RPAREN */ + LCURLY = 261, /* LCURLY */ + RCURLY = 262, /* RCURLY */ + COLON = 263, /* COLON */ + QUESTION = 264, /* QUESTION */ + LBRACKET = 265, /* LBRACKET */ + RBRACKET = 266, /* RBRACKET */ + DOT = 267, /* DOT */ + STAR = 268, /* STAR */ + AT = 269, /* AT */ + SLASH = 270, /* SLASH */ + MODULUS = 271, /* MODULUS */ + PLUS = 272, /* PLUS */ + MINUS = 273, /* MINUS */ + TILDE = 274, /* TILDE */ + LEQ = 275, /* LEQ */ + LT = 276, /* LT */ + GEQ = 277, /* GEQ */ + GT = 278, /* GT */ + EQ = 279, /* EQ */ + NEQ = 280, /* NEQ */ + LEFT_SHIFT = 281, /* LEFT_SHIFT */ + RIGHT_SHIFT = 282, /* RIGHT_SHIFT */ + ASSIGN = 283, /* ASSIGN */ + MUL_ASSIGN = 284, /* MUL_ASSIGN */ + DIV_ASSIGN = 285, /* DIV_ASSIGN */ + MOD_ASSIGN = 286, /* MOD_ASSIGN */ + ADD_ASSIGN = 287, /* ADD_ASSIGN */ + SUB_ASSIGN = 288, /* SUB_ASSIGN */ + LEFT_ASSIGN = 289, /* LEFT_ASSIGN */ + RIGHT_ASSIGN = 290, /* RIGHT_ASSIGN */ + AND_ASSIGN = 291, /* AND_ASSIGN */ + XOR_ASSIGN = 292, /* XOR_ASSIGN */ + OR_ASSIGN = 293, /* OR_ASSIGN */ + LOG_OR = 294, /* LOG_OR */ + LOG_AND = 295, /* LOG_AND */ + ARITH_OR = 296, /* ARITH_OR */ + ARITH_AND = 297, /* ARITH_AND */ + ARITH_XOR = 298, /* ARITH_XOR */ + INC_OP = 299, /* INC_OP */ + DEC_OP = 300, /* DEC_OP */ + BANG = 301, /* BANG */ + SEMI = 302, /* SEMI */ + IF = 303, /* IF */ + ELSE = 304, /* ELSE */ + FOR = 305, /* FOR */ + DO = 306, /* DO */ + WHILE = 307, /* WHILE */ + CHAR = 308, /* CHAR */ + SHORT = 309, /* SHORT */ + INT = 310, /* INT */ + LONG = 311, /* LONG */ + UNSIGNED = 312, /* UNSIGNED */ + SIGNED = 313, /* SIGNED */ + FLOAT = 314, /* FLOAT */ + DOUBLE = 315, /* DOUBLE */ + VOID = 316, /* VOID */ + STRING = 317, /* STRING */ + STATIC = 318, /* STATIC */ + EXTERN_TOKEN = 319, /* EXTERN_TOKEN */ + STRUCT = 320, /* STRUCT */ + ENUM = 321, /* ENUM */ + UNION = 322, /* UNION */ + CONST = 323, /* CONST */ + SIZEOF = 324, /* SIZEOF */ + TYPEDEF = 325, /* TYPEDEF */ + RETURN_TOKEN = 326, /* RETURN_TOKEN */ + CONTINUE = 327, /* CONTINUE */ + BREAK = 328, /* BREAK */ + GOTO = 329, /* GOTO */ + PRINT = 330, /* PRINT */ + COMMA = 331, /* COMMA */ + DOTDOTDOT = 332, /* DOTDOTDOT */ + integer_constant = 333, /* integer_constant */ + character_constant = 334, /* character_constant */ + string_constant = 335, /* string_constant */ + floating_constant = 336, /* floating_constant */ + identifier_ref = 337, /* identifier_ref */ + type_id = 338, /* type_id */ + enumeration_constant = 339 /* enumeration_constant */ + }; + typedef enum yytokentype yytoken_kind_t; #endif +/* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE -#line 187 "cod/cod.y" +union YYSTYPE { +#line 201 "cod.y" + lx_info info; sm_ref reference; operator_t operator; sm_list list; char *string; -} -/* Line 193 of yacc.c. */ -#line 457 "/Users/eisen/prog/ffs/build/cod.tab.c" - YYSTYPE; -# define yystype YYSTYPE /* obsolescent; will be withdrawn */ -# define YYSTYPE_IS_DECLARED 1 + +#line 409 "cod.tab.c" + +}; +typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 #endif +extern YYSTYPE yylval; + + +int yyparse (void); + + + +/* Symbol kind. */ +enum yysymbol_kind_t +{ + YYSYMBOL_YYEMPTY = -2, + YYSYMBOL_YYEOF = 0, /* "end of file" */ + YYSYMBOL_YYerror = 1, /* error */ + YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ + YYSYMBOL_ARROW = 3, /* ARROW */ + YYSYMBOL_LPAREN = 4, /* LPAREN */ + YYSYMBOL_RPAREN = 5, /* RPAREN */ + YYSYMBOL_LCURLY = 6, /* LCURLY */ + YYSYMBOL_RCURLY = 7, /* RCURLY */ + YYSYMBOL_COLON = 8, /* COLON */ + YYSYMBOL_QUESTION = 9, /* QUESTION */ + YYSYMBOL_LBRACKET = 10, /* LBRACKET */ + YYSYMBOL_RBRACKET = 11, /* RBRACKET */ + YYSYMBOL_DOT = 12, /* DOT */ + YYSYMBOL_STAR = 13, /* STAR */ + YYSYMBOL_AT = 14, /* AT */ + YYSYMBOL_SLASH = 15, /* SLASH */ + YYSYMBOL_MODULUS = 16, /* MODULUS */ + YYSYMBOL_PLUS = 17, /* PLUS */ + YYSYMBOL_MINUS = 18, /* MINUS */ + YYSYMBOL_TILDE = 19, /* TILDE */ + YYSYMBOL_LEQ = 20, /* LEQ */ + YYSYMBOL_LT = 21, /* LT */ + YYSYMBOL_GEQ = 22, /* GEQ */ + YYSYMBOL_GT = 23, /* GT */ + YYSYMBOL_EQ = 24, /* EQ */ + YYSYMBOL_NEQ = 25, /* NEQ */ + YYSYMBOL_LEFT_SHIFT = 26, /* LEFT_SHIFT */ + YYSYMBOL_RIGHT_SHIFT = 27, /* RIGHT_SHIFT */ + YYSYMBOL_ASSIGN = 28, /* ASSIGN */ + YYSYMBOL_MUL_ASSIGN = 29, /* MUL_ASSIGN */ + YYSYMBOL_DIV_ASSIGN = 30, /* DIV_ASSIGN */ + YYSYMBOL_MOD_ASSIGN = 31, /* MOD_ASSIGN */ + YYSYMBOL_ADD_ASSIGN = 32, /* ADD_ASSIGN */ + YYSYMBOL_SUB_ASSIGN = 33, /* SUB_ASSIGN */ + YYSYMBOL_LEFT_ASSIGN = 34, /* LEFT_ASSIGN */ + YYSYMBOL_RIGHT_ASSIGN = 35, /* RIGHT_ASSIGN */ + YYSYMBOL_AND_ASSIGN = 36, /* AND_ASSIGN */ + YYSYMBOL_XOR_ASSIGN = 37, /* XOR_ASSIGN */ + YYSYMBOL_OR_ASSIGN = 38, /* OR_ASSIGN */ + YYSYMBOL_LOG_OR = 39, /* LOG_OR */ + YYSYMBOL_LOG_AND = 40, /* LOG_AND */ + YYSYMBOL_ARITH_OR = 41, /* ARITH_OR */ + YYSYMBOL_ARITH_AND = 42, /* ARITH_AND */ + YYSYMBOL_ARITH_XOR = 43, /* ARITH_XOR */ + YYSYMBOL_INC_OP = 44, /* INC_OP */ + YYSYMBOL_DEC_OP = 45, /* DEC_OP */ + YYSYMBOL_BANG = 46, /* BANG */ + YYSYMBOL_SEMI = 47, /* SEMI */ + YYSYMBOL_IF = 48, /* IF */ + YYSYMBOL_ELSE = 49, /* ELSE */ + YYSYMBOL_FOR = 50, /* FOR */ + YYSYMBOL_DO = 51, /* DO */ + YYSYMBOL_WHILE = 52, /* WHILE */ + YYSYMBOL_CHAR = 53, /* CHAR */ + YYSYMBOL_SHORT = 54, /* SHORT */ + YYSYMBOL_INT = 55, /* INT */ + YYSYMBOL_LONG = 56, /* LONG */ + YYSYMBOL_UNSIGNED = 57, /* UNSIGNED */ + YYSYMBOL_SIGNED = 58, /* SIGNED */ + YYSYMBOL_FLOAT = 59, /* FLOAT */ + YYSYMBOL_DOUBLE = 60, /* DOUBLE */ + YYSYMBOL_VOID = 61, /* VOID */ + YYSYMBOL_STRING = 62, /* STRING */ + YYSYMBOL_STATIC = 63, /* STATIC */ + YYSYMBOL_EXTERN_TOKEN = 64, /* EXTERN_TOKEN */ + YYSYMBOL_STRUCT = 65, /* STRUCT */ + YYSYMBOL_ENUM = 66, /* ENUM */ + YYSYMBOL_UNION = 67, /* UNION */ + YYSYMBOL_CONST = 68, /* CONST */ + YYSYMBOL_SIZEOF = 69, /* SIZEOF */ + YYSYMBOL_TYPEDEF = 70, /* TYPEDEF */ + YYSYMBOL_RETURN_TOKEN = 71, /* RETURN_TOKEN */ + YYSYMBOL_CONTINUE = 72, /* CONTINUE */ + YYSYMBOL_BREAK = 73, /* BREAK */ + YYSYMBOL_GOTO = 74, /* GOTO */ + YYSYMBOL_PRINT = 75, /* PRINT */ + YYSYMBOL_COMMA = 76, /* COMMA */ + YYSYMBOL_DOTDOTDOT = 77, /* DOTDOTDOT */ + YYSYMBOL_integer_constant = 78, /* integer_constant */ + YYSYMBOL_character_constant = 79, /* character_constant */ + YYSYMBOL_string_constant = 80, /* string_constant */ + YYSYMBOL_floating_constant = 81, /* floating_constant */ + YYSYMBOL_identifier_ref = 82, /* identifier_ref */ + YYSYMBOL_type_id = 83, /* type_id */ + YYSYMBOL_enumeration_constant = 84, /* enumeration_constant */ + YYSYMBOL_YYACCEPT = 85, /* $accept */ + YYSYMBOL_start = 86, /* start */ + YYSYMBOL_primary_expression = 87, /* primary_expression */ + YYSYMBOL_postfix_expression = 88, /* postfix_expression */ + YYSYMBOL_argument_expression_list = 89, /* argument_expression_list */ + YYSYMBOL_unary_expression = 90, /* unary_expression */ + YYSYMBOL_unary_operator = 91, /* unary_operator */ + YYSYMBOL_cast_expression = 92, /* cast_expression */ + YYSYMBOL_multiplicative_expression = 93, /* multiplicative_expression */ + YYSYMBOL_additive_expression = 94, /* additive_expression */ + YYSYMBOL_shift_expression = 95, /* shift_expression */ + YYSYMBOL_relational_expression = 96, /* relational_expression */ + YYSYMBOL_equality_expression = 97, /* equality_expression */ + YYSYMBOL_and_expression = 98, /* and_expression */ + YYSYMBOL_exclusive_or_expression = 99, /* exclusive_or_expression */ + YYSYMBOL_inclusive_or_expression = 100, /* inclusive_or_expression */ + YYSYMBOL_logical_and_expression = 101, /* logical_and_expression */ + YYSYMBOL_logical_or_expression = 102, /* logical_or_expression */ + YYSYMBOL_conditional_expression = 103, /* conditional_expression */ + YYSYMBOL_assignment_operator = 104, /* assignment_operator */ + YYSYMBOL_assignment_expression = 105, /* assignment_expression */ + YYSYMBOL_expression = 106, /* expression */ + YYSYMBOL_constant_expression = 107, /* constant_expression */ + YYSYMBOL_init_declarator_list = 108, /* init_declarator_list */ + YYSYMBOL_declaration = 109, /* declaration */ + YYSYMBOL_110_1 = 110, /* $@1 */ + YYSYMBOL_111_2 = 111, /* @2 */ + YYSYMBOL_declaration_specifiers = 112, /* declaration_specifiers */ + YYSYMBOL_init_declarator = 113, /* init_declarator */ + YYSYMBOL_storage_class_specifier = 114, /* storage_class_specifier */ + YYSYMBOL_type_specifier = 115, /* type_specifier */ + YYSYMBOL_struct_or_union_specifier = 116, /* struct_or_union_specifier */ + YYSYMBOL_struct_or_union = 117, /* struct_or_union */ + YYSYMBOL_struct_declaration_list = 118, /* struct_declaration_list */ + YYSYMBOL_struct_declaration = 119, /* struct_declaration */ + YYSYMBOL_struct_declarator_list = 120, /* struct_declarator_list */ + YYSYMBOL_struct_declarator = 121, /* struct_declarator */ + YYSYMBOL_specifier_qualifier_list = 122, /* specifier_qualifier_list */ + YYSYMBOL_enum_specifier = 123, /* enum_specifier */ + YYSYMBOL_enumerator_list = 124, /* enumerator_list */ + YYSYMBOL_enumerator = 125, /* enumerator */ + YYSYMBOL_type_qualifier = 126, /* type_qualifier */ + YYSYMBOL_declarator = 127, /* declarator */ + YYSYMBOL_direct_declarator = 128, /* direct_declarator */ + YYSYMBOL_pointer = 129, /* pointer */ + YYSYMBOL_type_qualifier_list = 130, /* type_qualifier_list */ + YYSYMBOL_parameter_type_list = 131, /* parameter_type_list */ + YYSYMBOL_parameter_list = 132, /* parameter_list */ + YYSYMBOL_parameter_declaration = 133, /* parameter_declaration */ + YYSYMBOL_type_name = 134, /* type_name */ + YYSYMBOL_abstract_declarator = 135, /* abstract_declarator */ + YYSYMBOL_initializer = 136, /* initializer */ + YYSYMBOL_initializer_list = 137, /* initializer_list */ + YYSYMBOL_designation = 138, /* designation */ + YYSYMBOL_designator_list = 139, /* designator_list */ + YYSYMBOL_designator = 140, /* designator */ + YYSYMBOL_decls_stmts_list = 141, /* decls_stmts_list */ + YYSYMBOL_statement = 142, /* statement */ + YYSYMBOL_labeled_statement = 143, /* labeled_statement */ + YYSYMBOL_compound_statement = 144, /* compound_statement */ + YYSYMBOL_declaration_list = 145, /* declaration_list */ + YYSYMBOL_jump_statement = 146, /* jump_statement */ + YYSYMBOL_expression_statement = 147, /* expression_statement */ + YYSYMBOL_selection_statement = 148, /* selection_statement */ + YYSYMBOL_iteration_statement = 149, /* iteration_statement */ + YYSYMBOL_expression_opt = 150, /* expression_opt */ + YYSYMBOL_constant = 151 /* constant */ +}; +typedef enum yysymbol_kind_t yysymbol_kind_t; -/* Copy the second part of user declarations. */ -/* Line 216 of yacc.c. */ -#line 470 "/Users/eisen/prog/ffs/build/cod.tab.c" #ifdef short # undef short #endif -#ifdef YYTYPE_UINT8 -typedef YYTYPE_UINT8 yytype_uint8; -#else -typedef unsigned char yytype_uint8; +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + and (if available) are included + so that the code can choose integer types of a good width. */ + +#ifndef __PTRDIFF_MAX__ +# include /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif #endif -#ifdef YYTYPE_INT8 -typedef YYTYPE_INT8 yytype_int8; -#elif (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ + +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; +#else typedef signed char yytype_int8; +#endif + +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; #else -typedef short int yytype_int8; +typedef short yytype_int16; +#endif + +/* Work around bug in HP-UX 11.23, which defines these macros + incorrectly for preprocessor constants. This workaround can likely + be removed in 2023, as HPE has promised support for HP-UX 11.23 + (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of + . */ +#ifdef __hpux +# undef UINT_LEAST8_MAX +# undef UINT_LEAST16_MAX +# define UINT_LEAST8_MAX 255 +# define UINT_LEAST16_MAX 65535 #endif -#ifdef YYTYPE_UINT16 -typedef YYTYPE_UINT16 yytype_uint16; +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; #else -typedef unsigned short int yytype_uint16; +typedef short yytype_uint8; #endif -#ifdef YYTYPE_INT16 -typedef YYTYPE_INT16 yytype_int16; +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; #else -typedef short int yytype_int16; +typedef int yytype_uint16; +#endif + +#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif #endif #ifndef YYSIZE_T @@ -504,55 +675,106 @@ typedef short int yytype_int16; # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t -# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else -# define YYSIZE_T unsigned int +# define YYSIZE_T unsigned # endif #endif -#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) +#define YYSIZE_MAXIMUM \ + YY_CAST (YYPTRDIFF_T, \ + (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ + ? YYPTRDIFF_MAXIMUM \ + : YY_CAST (YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) + + +/* Stored state numbers (used for stacks). */ +typedef yytype_int16 yy_state_t; + +/* State numbers in computations. */ +typedef int yy_state_fast_t; #ifndef YY_ # if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ -# define YY_(msgid) dgettext ("bison-runtime", msgid) +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) # endif # endif # ifndef YY_ -# define YY_(msgid) msgid +# define YY_(Msgid) Msgid +# endif +#endif + + +#ifndef YY_ATTRIBUTE_PURE +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) +# else +# define YY_ATTRIBUTE_PURE +# endif +#endif + +#ifndef YY_ATTRIBUTE_UNUSED +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +# else +# define YY_ATTRIBUTE_UNUSED # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(e) ((void) (e)) +# define YY_USE(E) ((void) (E)) #else -# define YYUSE(e) /* empty */ +# define YY_USE(E) /* empty */ #endif -/* Identity function, used to suppress warnings about constant conditions. */ -#ifndef lint -# define YYID(n) (n) -#else -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static int -YYID (int i) +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ +# if __GNUC__ * 100 + __GNUC_MINOR__ < 407 +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") +# else +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# endif +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") #else -static int -YYID (i) - int i; +# define YY_INITIAL_VALUE(Value) Value #endif -{ - return i; -} +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + +#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END \ + _Pragma ("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END #endif -#if ! defined yyoverflow || YYERROR_VERBOSE + +#define YY_ASSERT(E) ((void) (0 && (E))) + +#if !defined yyoverflow /* The parser invokes alloca or malloc; define the necessary symbols. */ @@ -569,11 +791,11 @@ YYID (i) # define alloca _alloca # else # define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # endif @@ -581,8 +803,8 @@ YYID (i) # endif # ifdef YYSTACK_ALLOC - /* Pacify GCC's `empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) + /* Pacify GCC's 'empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) # ifndef YYSTACK_ALLOC_MAXIMUM /* The OS might guarantee only one guard page at the bottom of the stack, and a page size can be as small as 4096 bytes. So we cannot safely @@ -596,88 +818,89 @@ YYID (i) # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif -# if (defined __cplusplus && ! defined _STDLIB_H \ +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) + && (defined YYFREE || defined free))) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc -# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# if ! defined malloc && ! defined EXIT_SUCCESS void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free -# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# if ! defined free && ! defined EXIT_SUCCESS void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif # endif -#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ - +#endif /* !defined yyoverflow */ #if (! defined yyoverflow \ && (! defined __cplusplus \ - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc { - yytype_int16 yyss; - YYSTYPE yyvs; - }; + yy_state_t yyss_alloc; + YYSTYPE yyvs_alloc; +}; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ # define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) -/* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) -# else -# define YYCOPY(To, From, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ - while (YYID (0)) -# endif -# endif +# define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ -# define YYSTACK_RELOCATE(Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack, Stack, yysize); \ - Stack = &yyptr->Stack; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (YYID (0)) +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYPTRDIFF_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF (*yyptr); \ + } \ + while (0) #endif +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from SRC to DST. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) +# else +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYPTRDIFF_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ + while (0) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + /* YYFINAL -- State number of the termination state. */ #define YYFINAL 88 /* YYLAST -- Last index in YYTABLE. */ @@ -689,18 +912,23 @@ union yyalloc #define YYNNTS 67 /* YYNRULES -- Number of rules. */ #define YYNRULES 206 -/* YYNRULES -- Number of states. */ +/* YYNSTATES -- Number of states. */ #define YYNSTATES 321 -/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ -#define YYUNDEFTOK 2 +/* YYMAXUTOK -- Last valid token kind. */ #define YYMAXUTOK 339 -#define YYTRANSLATE(YYX) \ - ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) -/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ -static const yytype_uint8 yytranslate[] = +/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ +#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ + : YYSYMBOL_YYUNDEF) + +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM + as returned by yylex. */ +static const yytype_int8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -739,144 +967,58 @@ static const yytype_uint8 yytranslate[] = }; #if YYDEBUG -/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in - YYRHS. */ -static const yytype_uint16 yyprhs[] = -{ - 0, 0, 3, 5, 7, 9, 11, 15, 17, 22, - 26, 31, 35, 39, 42, 45, 47, 51, 53, 56, - 59, 62, 65, 70, 72, 74, 76, 78, 80, 82, - 84, 89, 91, 95, 99, 103, 105, 109, 113, 115, - 119, 123, 125, 129, 133, 137, 141, 143, 147, 151, - 153, 157, 159, 163, 165, 169, 171, 175, 177, 181, - 183, 189, 191, 193, 195, 197, 199, 201, 203, 205, - 207, 209, 211, 213, 217, 219, 223, 225, 227, 231, - 232, 233, 239, 242, 244, 247, 249, 252, 254, 257, - 259, 263, 265, 267, 269, 271, 273, 275, 277, 279, - 281, 283, 285, 287, 289, 291, 293, 295, 301, 306, - 309, 311, 313, 315, 318, 321, 325, 327, 331, 333, - 336, 338, 341, 343, 348, 354, 360, 367, 370, 372, - 376, 380, 382, 384, 386, 389, 391, 395, 400, 404, - 409, 413, 415, 418, 421, 425, 427, 430, 433, 437, - 439, 442, 444, 448, 450, 454, 456, 459, 461, 464, - 466, 470, 475, 477, 480, 482, 487, 491, 494, 496, - 499, 503, 506, 508, 510, 513, 516, 519, 521, 523, - 525, 527, 529, 531, 535, 538, 542, 544, 547, 551, - 554, 557, 560, 564, 566, 569, 575, 583, 593, 599, - 607, 608, 610, 612, 614, 616, 618 +/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ +static const yytype_int16 yyrline[] = +{ + 0, 358, 358, 362, 368, 374, 376, 383, 385, 392, + 399, 406, 412, 418, 425, 435, 441, 455, 456, 463, + 470, 477, 484, 499, 502, 505, 508, 511, 514, 520, + 521, 530, 532, 541, 550, 561, 563, 572, 583, 585, + 594, 605, 607, 616, 625, 634, 645, 647, 656, 667, + 669, 680, 682, 693, 695, 706, 708, 719, 721, 732, + 734, 745, 747, 749, 751, 753, 755, 757, 759, 761, + 763, 765, 770, 773, 784, 786, 796, 800, 805, 824, + 831, 823, 914, 920, 925, 931, 936, 942, 947, 955, + 957, 973, 978, 983, 992, 997, 1002, 1007, 1012, 1017, + 1022, 1027, 1032, 1037, 1042, 1047, 1050, 1056, 1059, 1062, + 1068, 1069, 1075, 1076, 1088, 1089, 1140, 1145, 1157, 1160, + 1166, 1171, 1177, 1185, 1192, 1199, 1206, 1213, 1223, 1229, + 1239, 1245, 1253, 1261, 1263, 1277, 1286, 1289, 1298, 1307, + 1314, 1324, 1332, 1340, 1348, 1362, 1373, 1384, 1395, 1415, + 1420, 1433, 1434, 1449, 1455, 1470, 1479, 1518, 1519, 1565, + 1569, 1574, 1579, 1584, 1592, 1600, 1613, 1629, 1634, 1639, + 1652, 1658, 1667, 1673, 1676, 1679, 1685, 1690, 1691, 1692, + 1693, 1694, 1695, 1702, 1709, 1712, 1720, 1722, 1736, 1741, + 1746, 1752, 1758, 1767, 1771, 1781, 1790, 1807, 1817, 1827, + 1841, 1843, 1846, 1853, 1860, 1867, 1874 }; +#endif -/* YYRHS -- A `-1'-separated list of the rules' RHS. */ -static const yytype_int16 yyrhs[] = -{ - 86, 0, -1, 145, -1, 144, -1, 82, -1, 151, - -1, 4, 106, 5, -1, 87, -1, 88, 10, 106, - 11, -1, 88, 12, 82, -1, 88, 4, 89, 5, - -1, 88, 4, 5, -1, 88, 3, 82, -1, 88, - 44, -1, 88, 45, -1, 105, -1, 89, 76, 105, - -1, 88, -1, 44, 90, -1, 45, 90, -1, 91, - 92, -1, 69, 90, -1, 69, 4, 134, 5, -1, - 42, -1, 13, -1, 17, -1, 18, -1, 19, -1, - 46, -1, 90, -1, 4, 134, 5, 92, -1, 92, - -1, 93, 13, 92, -1, 93, 15, 92, -1, 93, - 16, 92, -1, 93, -1, 94, 17, 93, -1, 94, - 18, 93, -1, 94, -1, 95, 26, 94, -1, 95, - 27, 94, -1, 95, -1, 96, 21, 95, -1, 96, - 23, 95, -1, 96, 20, 95, -1, 96, 22, 95, - -1, 96, -1, 97, 24, 96, -1, 97, 25, 96, - -1, 97, -1, 98, 42, 97, -1, 98, -1, 99, - 43, 98, -1, 99, -1, 100, 41, 99, -1, 100, - -1, 101, 40, 100, -1, 101, -1, 102, 39, 101, - -1, 102, -1, 102, 9, 106, 8, 103, -1, 28, - -1, 29, -1, 30, -1, 31, -1, 32, -1, 33, - -1, 34, -1, 35, -1, 36, -1, 37, -1, 38, - -1, 103, -1, 90, 104, 105, -1, 105, -1, 106, - 76, 105, -1, 103, -1, 113, -1, 108, 76, 113, - -1, -1, -1, 112, 110, 108, 111, 47, -1, 112, - 47, -1, 114, -1, 114, 112, -1, 115, -1, 115, - 112, -1, 126, -1, 126, 112, -1, 127, -1, 127, - 28, 136, -1, 70, -1, 63, -1, 64, -1, 53, - -1, 54, -1, 55, -1, 56, -1, 59, -1, 60, - -1, 61, -1, 58, -1, 57, -1, 62, -1, 83, - -1, 116, -1, 123, -1, 117, 82, 6, 118, 7, - -1, 117, 6, 118, 7, -1, 117, 82, -1, 65, - -1, 67, -1, 119, -1, 118, 119, -1, 122, 47, - -1, 122, 120, 47, -1, 121, -1, 120, 76, 121, - -1, 127, -1, 115, 122, -1, 115, -1, 126, 122, - -1, 126, -1, 66, 6, 124, 7, -1, 66, 6, - 124, 76, 7, -1, 66, 82, 6, 124, 7, -1, - 66, 82, 6, 124, 76, 7, -1, 66, 82, -1, - 125, -1, 124, 76, 125, -1, 82, 28, 107, -1, - 82, -1, 68, -1, 128, -1, 129, 128, -1, 82, - -1, 4, 127, 5, -1, 82, 4, 131, 5, -1, - 82, 4, 5, -1, 128, 10, 107, 11, -1, 128, - 10, 11, -1, 13, -1, 13, 130, -1, 13, 129, - -1, 13, 130, 129, -1, 14, -1, 14, 130, -1, - 14, 129, -1, 14, 130, 129, -1, 126, -1, 130, - 126, -1, 132, -1, 132, 76, 77, -1, 133, -1, - 132, 76, 133, -1, 112, -1, 112, 127, -1, 122, - -1, 122, 135, -1, 129, -1, 6, 137, 7, -1, - 6, 137, 76, 7, -1, 105, -1, 138, 136, -1, - 136, -1, 137, 76, 138, 136, -1, 137, 76, 136, - -1, 139, 28, -1, 140, -1, 139, 140, -1, 10, - 107, 11, -1, 12, 82, -1, 142, -1, 109, -1, - 1, 47, -1, 141, 142, -1, 141, 109, -1, 143, - -1, 144, -1, 147, -1, 148, -1, 149, -1, 146, - -1, 82, 8, 142, -1, 6, 7, -1, 6, 141, - 7, -1, 109, -1, 145, 109, -1, 71, 106, 47, - -1, 71, 47, -1, 72, 47, -1, 73, 47, -1, - 74, 82, 47, -1, 47, -1, 106, 47, -1, 48, - 4, 106, 5, 142, -1, 48, 4, 106, 5, 142, - 49, 142, -1, 50, 4, 150, 47, 150, 47, 150, - 5, 142, -1, 52, 4, 106, 5, 142, -1, 51, - 142, 52, 4, 106, 5, 47, -1, -1, 106, -1, - 78, -1, 81, -1, 80, -1, 79, -1, 84, -1 -}; +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) -/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = -{ - 0, 344, 344, 348, 354, 360, 362, 369, 371, 378, - 385, 392, 398, 404, 411, 421, 427, 441, 442, 449, - 456, 463, 470, 485, 488, 491, 494, 497, 500, 506, - 507, 516, 518, 527, 536, 547, 549, 558, 569, 571, - 580, 591, 593, 602, 611, 620, 631, 633, 642, 653, - 655, 666, 668, 679, 681, 692, 694, 705, 707, 718, - 720, 731, 733, 735, 737, 739, 741, 743, 745, 747, - 749, 751, 756, 759, 770, 772, 782, 786, 791, 810, - 817, 809, 900, 906, 911, 917, 922, 928, 933, 941, - 943, 959, 964, 969, 978, 983, 988, 993, 998, 1003, - 1008, 1013, 1018, 1023, 1028, 1033, 1036, 1042, 1045, 1048, - 1054, 1055, 1061, 1062, 1074, 1075, 1126, 1131, 1143, 1146, - 1152, 1157, 1163, 1171, 1178, 1185, 1192, 1199, 1209, 1215, - 1225, 1231, 1239, 1247, 1249, 1263, 1272, 1275, 1284, 1293, - 1300, 1310, 1318, 1326, 1334, 1348, 1359, 1370, 1381, 1401, - 1406, 1419, 1420, 1435, 1441, 1456, 1465, 1504, 1505, 1551, - 1555, 1560, 1565, 1570, 1578, 1586, 1599, 1615, 1620, 1625, - 1638, 1644, 1653, 1659, 1662, 1665, 1671, 1676, 1677, 1678, - 1679, 1680, 1681, 1688, 1695, 1698, 1706, 1708, 1722, 1727, - 1732, 1738, 1744, 1753, 1757, 1767, 1776, 1793, 1803, 1813, - 1827, 1829, 1832, 1839, 1846, 1853, 1860 -}; -#endif +#if YYDEBUG || 0 +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { - "$end", "error", "$undefined", "ARROW", "LPAREN", "RPAREN", "LCURLY", - "RCURLY", "COLON", "QUESTION", "LBRACKET", "RBRACKET", "DOT", "STAR", - "AT", "SLASH", "MODULUS", "PLUS", "MINUS", "TILDE", "LEQ", "LT", "GEQ", - "GT", "EQ", "NEQ", "LEFT_SHIFT", "RIGHT_SHIFT", "ASSIGN", "MUL_ASSIGN", - "DIV_ASSIGN", "MOD_ASSIGN", "ADD_ASSIGN", "SUB_ASSIGN", "LEFT_ASSIGN", - "RIGHT_ASSIGN", "AND_ASSIGN", "XOR_ASSIGN", "OR_ASSIGN", "LOG_OR", - "LOG_AND", "ARITH_OR", "ARITH_AND", "ARITH_XOR", "INC_OP", "DEC_OP", - "BANG", "SEMI", "IF", "ELSE", "FOR", "DO", "WHILE", "CHAR", "SHORT", - "INT", "LONG", "UNSIGNED", "SIGNED", "FLOAT", "DOUBLE", "VOID", "STRING", - "STATIC", "EXTERN_TOKEN", "STRUCT", "ENUM", "UNION", "CONST", "SIZEOF", - "TYPEDEF", "RETURN_TOKEN", "CONTINUE", "BREAK", "GOTO", "PRINT", "COMMA", - "DOTDOTDOT", "integer_constant", "character_constant", "string_constant", + "\"end of file\"", "error", "\"invalid token\"", "ARROW", "LPAREN", + "RPAREN", "LCURLY", "RCURLY", "COLON", "QUESTION", "LBRACKET", + "RBRACKET", "DOT", "STAR", "AT", "SLASH", "MODULUS", "PLUS", "MINUS", + "TILDE", "LEQ", "LT", "GEQ", "GT", "EQ", "NEQ", "LEFT_SHIFT", + "RIGHT_SHIFT", "ASSIGN", "MUL_ASSIGN", "DIV_ASSIGN", "MOD_ASSIGN", + "ADD_ASSIGN", "SUB_ASSIGN", "LEFT_ASSIGN", "RIGHT_ASSIGN", "AND_ASSIGN", + "XOR_ASSIGN", "OR_ASSIGN", "LOG_OR", "LOG_AND", "ARITH_OR", "ARITH_AND", + "ARITH_XOR", "INC_OP", "DEC_OP", "BANG", "SEMI", "IF", "ELSE", "FOR", + "DO", "WHILE", "CHAR", "SHORT", "INT", "LONG", "UNSIGNED", "SIGNED", + "FLOAT", "DOUBLE", "VOID", "STRING", "STATIC", "EXTERN_TOKEN", "STRUCT", + "ENUM", "UNION", "CONST", "SIZEOF", "TYPEDEF", "RETURN_TOKEN", + "CONTINUE", "BREAK", "GOTO", "PRINT", "COMMA", "DOTDOTDOT", + "integer_constant", "character_constant", "string_constant", "floating_constant", "identifier_ref", "type_id", "enumeration_constant", "$accept", "start", "primary_expression", "postfix_expression", "argument_expression_list", "unary_expression", "unary_operator", @@ -886,7 +1028,7 @@ static const char *const yytname[] = "logical_and_expression", "logical_or_expression", "conditional_expression", "assignment_operator", "assignment_expression", "expression", "constant_expression", "init_declarator_list", - "declaration", "@1", "@2", "declaration_specifiers", "init_declarator", + "declaration", "$@1", "@2", "declaration_specifiers", "init_declarator", "storage_class_specifier", "type_specifier", "struct_or_union_specifier", "struct_or_union", "struct_declaration_list", "struct_declaration", "struct_declarator_list", "struct_declarator", @@ -898,134 +1040,28 @@ static const char *const yytname[] = "designator_list", "designator", "decls_stmts_list", "statement", "labeled_statement", "compound_statement", "declaration_list", "jump_statement", "expression_statement", "selection_statement", - "iteration_statement", "expression_opt", "constant", 0 + "iteration_statement", "expression_opt", "constant", YY_NULLPTR }; -#endif -# ifdef YYPRINT -/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to - token YYLEX-NUM. */ -static const yytype_uint16 yytoknum[] = -{ - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, - 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, - 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, - 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, - 335, 336, 337, 338, 339 -}; -# endif - -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) { - 0, 85, 86, 86, 87, 87, 87, 88, 88, 88, - 88, 88, 88, 88, 88, 89, 89, 90, 90, 90, - 90, 90, 90, 91, 91, 91, 91, 91, 91, 92, - 92, 93, 93, 93, 93, 94, 94, 94, 95, 95, - 95, 96, 96, 96, 96, 96, 97, 97, 97, 98, - 98, 99, 99, 100, 100, 101, 101, 102, 102, 103, - 103, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 105, 105, 106, 106, 107, 108, 108, 110, - 111, 109, 109, 112, 112, 112, 112, 112, 112, 113, - 113, 114, 114, 114, 115, 115, 115, 115, 115, 115, - 115, 115, 115, 115, 115, 115, 115, 116, 116, 116, - 117, 117, 118, 118, 119, 119, 120, 120, 121, 122, - 122, 122, 122, 123, 123, 123, 123, 123, 124, 124, - 125, 125, 126, 127, 127, 128, 128, 128, 128, 128, - 128, 129, 129, 129, 129, 129, 129, 129, 129, 130, - 130, 131, 131, 132, 132, 133, 133, 134, 134, 135, - 136, 136, 136, 137, 137, 137, 137, 138, 139, 139, - 140, 140, 141, 141, 141, 141, 141, 142, 142, 142, - 142, 142, 142, 143, 144, 144, 145, 145, 146, 146, - 146, 146, 146, 147, 147, 148, 148, 149, 149, 149, - 150, 150, 151, 151, 151, 151, 151 -}; + return yytname[yysymbol]; +} +#endif -/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = -{ - 0, 2, 1, 1, 1, 1, 3, 1, 4, 3, - 4, 3, 3, 2, 2, 1, 3, 1, 2, 2, - 2, 2, 4, 1, 1, 1, 1, 1, 1, 1, - 4, 1, 3, 3, 3, 1, 3, 3, 1, 3, - 3, 1, 3, 3, 3, 3, 1, 3, 3, 1, - 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, - 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 3, 1, 3, 1, 1, 3, 0, - 0, 5, 2, 1, 2, 1, 2, 1, 2, 1, - 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 5, 4, 2, - 1, 1, 1, 2, 2, 3, 1, 3, 1, 2, - 1, 2, 1, 4, 5, 5, 6, 2, 1, 3, - 3, 1, 1, 1, 2, 1, 3, 4, 3, 4, - 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, - 2, 1, 3, 1, 3, 1, 2, 1, 2, 1, - 3, 4, 1, 2, 1, 4, 3, 2, 1, 2, - 3, 2, 1, 1, 2, 2, 2, 1, 1, 1, - 1, 1, 1, 3, 2, 3, 1, 2, 3, 2, - 2, 2, 3, 1, 2, 5, 7, 9, 5, 7, - 0, 1, 1, 1, 1, 1, 1 -}; +#define YYPACT_NINF (-239) -/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state - STATE-NUM when YYTABLE doesn't specify something else to do. Zero - means the default is an error. */ -static const yytype_uint8 yydefact[] = -{ - 0, 0, 94, 95, 96, 97, 102, 101, 98, 99, - 100, 103, 92, 93, 110, 0, 111, 132, 91, 104, - 0, 186, 79, 83, 85, 105, 0, 106, 87, 3, - 2, 0, 0, 184, 24, 25, 26, 27, 23, 0, - 0, 28, 193, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 202, 205, 204, 203, 4, 206, 7, 17, - 29, 0, 31, 35, 38, 41, 46, 49, 51, 53, - 55, 57, 59, 72, 74, 0, 173, 0, 172, 177, - 178, 182, 179, 180, 181, 5, 0, 127, 1, 82, - 0, 84, 86, 0, 109, 88, 187, 174, 4, 0, - 120, 157, 122, 0, 0, 18, 19, 0, 200, 0, - 0, 0, 21, 189, 0, 190, 191, 0, 0, 0, - 0, 0, 0, 13, 14, 61, 62, 63, 64, 65, - 66, 67, 68, 69, 70, 71, 0, 29, 20, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 194, 0, - 185, 176, 175, 131, 0, 128, 0, 0, 141, 145, - 135, 80, 77, 89, 133, 0, 0, 112, 0, 0, - 6, 119, 159, 158, 121, 0, 0, 201, 0, 0, - 0, 0, 188, 192, 183, 12, 11, 0, 15, 0, - 9, 73, 32, 33, 34, 36, 37, 39, 40, 44, - 42, 45, 43, 47, 48, 50, 52, 54, 56, 0, - 58, 75, 0, 123, 0, 0, 0, 149, 143, 142, - 147, 146, 0, 0, 0, 0, 0, 134, 108, 113, - 114, 0, 116, 118, 0, 30, 0, 200, 0, 0, - 22, 10, 0, 8, 0, 76, 130, 124, 129, 125, - 0, 136, 150, 144, 148, 138, 155, 0, 151, 153, - 78, 81, 0, 162, 90, 140, 0, 115, 0, 107, - 195, 0, 0, 198, 16, 60, 126, 156, 137, 0, - 0, 0, 164, 0, 0, 0, 168, 139, 117, 0, - 200, 0, 152, 154, 0, 171, 160, 0, 163, 167, - 169, 196, 0, 199, 170, 161, 166, 0, 0, 165, - 197 -}; +#define yypact_value_is_default(Yyn) \ + ((Yyn) == YYPACT_NINF) -/* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int16 yydefgoto[] = -{ - -1, 20, 58, 59, 197, 60, 61, 62, 63, 64, - 65, 66, 67, 68, 69, 70, 71, 72, 73, 136, - 74, 75, 256, 171, 21, 90, 234, 22, 172, 23, - 24, 25, 26, 176, 177, 241, 242, 178, 27, 164, - 165, 28, 173, 174, 175, 229, 267, 268, 269, 103, - 183, 274, 293, 294, 295, 296, 77, 78, 79, 80, - 30, 81, 82, 83, 84, 188, 85 -}; +#define YYTABLE_NINF (-1) + +#define yytable_value_is_error(Yyn) \ + 0 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ -#define YYPACT_NINF -239 static const yytype_int16 yypact[] = { 808, 232, -239, -239, -239, -239, -239, -239, -239, -239, @@ -1063,6 +1099,46 @@ static const yytype_int16 yypact[] = -239 }; +/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 0, 0, 94, 95, 96, 97, 102, 101, 98, 99, + 100, 103, 92, 93, 110, 0, 111, 132, 91, 104, + 0, 186, 79, 83, 85, 105, 0, 106, 87, 3, + 2, 0, 0, 184, 24, 25, 26, 27, 23, 0, + 0, 28, 193, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 202, 205, 204, 203, 4, 206, 7, 17, + 29, 0, 31, 35, 38, 41, 46, 49, 51, 53, + 55, 57, 59, 72, 74, 0, 173, 0, 172, 177, + 178, 182, 179, 180, 181, 5, 0, 127, 1, 82, + 0, 84, 86, 0, 109, 88, 187, 174, 4, 0, + 120, 157, 122, 0, 0, 18, 19, 0, 200, 0, + 0, 0, 21, 189, 0, 190, 191, 0, 0, 0, + 0, 0, 0, 13, 14, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 0, 29, 20, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 194, 0, + 185, 176, 175, 131, 0, 128, 0, 0, 141, 145, + 135, 80, 77, 89, 133, 0, 0, 112, 0, 0, + 6, 119, 159, 158, 121, 0, 0, 201, 0, 0, + 0, 0, 188, 192, 183, 12, 11, 0, 15, 0, + 9, 73, 32, 33, 34, 36, 37, 39, 40, 44, + 42, 45, 43, 47, 48, 50, 52, 54, 56, 0, + 58, 75, 0, 123, 0, 0, 0, 149, 143, 142, + 147, 146, 0, 0, 0, 0, 0, 134, 108, 113, + 114, 0, 116, 118, 0, 30, 0, 200, 0, 0, + 22, 10, 0, 8, 0, 76, 130, 124, 129, 125, + 0, 136, 150, 144, 148, 138, 155, 0, 151, 153, + 78, 81, 0, 162, 90, 140, 0, 115, 0, 107, + 195, 0, 0, 198, 16, 60, 126, 156, 137, 0, + 0, 0, 164, 0, 0, 0, 168, 139, 117, 0, + 200, 0, 152, 154, 0, 171, 160, 0, 163, 167, + 169, 196, 0, 199, 170, 161, 166, 0, 0, 165, + 197 +}; + /* YYPGOTO[NTERM-NUM]. */ static const yytype_int16 yypgoto[] = { @@ -1075,12 +1151,22 @@ static const yytype_int16 yypgoto[] = -239, -239, -239, -239, -239, -238, -239 }; -/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule which - number is the opposite. If zero, do what YYDEFACT says. - If YYTABLE_NINF, syntax error. */ -#define YYTABLE_NINF -1 -static const yytype_uint16 yytable[] = +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int16 yydefgoto[] = +{ + 0, 20, 58, 59, 197, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 136, + 74, 75, 256, 171, 21, 90, 234, 22, 172, 23, + 24, 25, 26, 176, 177, 241, 242, 178, 27, 164, + 165, 28, 173, 174, 175, 229, 267, 268, 269, 103, + 183, 274, 293, 294, 295, 296, 77, 78, 79, 80, + 30, 81, 82, 83, 84, 188, 85 +}; + +/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ +static const yytype_int16 yytable[] = { 109, 167, 99, 91, 92, 105, 106, 257, 95, 281, 168, 169, 198, 112, 258, 138, 156, 182, 114, 101, @@ -1286,8 +1372,8 @@ static const yytype_int16 yycheck[] = -1, -1, -1, -1, -1, 83 }; -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ +/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of + state STATE-NUM. */ static const yytype_uint8 yystos[] = { 0, 6, 53, 54, 55, 56, 57, 58, 59, 60, @@ -1325,178 +1411,154 @@ static const yytype_uint8 yystos[] = 142 }; -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 +/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ +static const yytype_uint8 yyr1[] = +{ + 0, 85, 86, 86, 87, 87, 87, 88, 88, 88, + 88, 88, 88, 88, 88, 89, 89, 90, 90, 90, + 90, 90, 90, 91, 91, 91, 91, 91, 91, 92, + 92, 93, 93, 93, 93, 94, 94, 94, 95, 95, + 95, 96, 96, 96, 96, 96, 97, 97, 97, 98, + 98, 99, 99, 100, 100, 101, 101, 102, 102, 103, + 103, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 105, 105, 106, 106, 107, 108, 108, 110, + 111, 109, 109, 112, 112, 112, 112, 112, 112, 113, + 113, 114, 114, 114, 115, 115, 115, 115, 115, 115, + 115, 115, 115, 115, 115, 115, 115, 116, 116, 116, + 117, 117, 118, 118, 119, 119, 120, 120, 121, 122, + 122, 122, 122, 123, 123, 123, 123, 123, 124, 124, + 125, 125, 126, 127, 127, 128, 128, 128, 128, 128, + 128, 129, 129, 129, 129, 129, 129, 129, 129, 130, + 130, 131, 131, 132, 132, 133, 133, 134, 134, 135, + 136, 136, 136, 137, 137, 137, 137, 138, 139, 139, + 140, 140, 141, 141, 141, 141, 141, 142, 142, 142, + 142, 142, 142, 143, 144, 144, 145, 145, 146, 146, + 146, 146, 146, 147, 147, 148, 148, 149, 149, 149, + 150, 150, 151, 151, 151, 151, 151 +}; + +/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ +static const yytype_int8 yyr2[] = +{ + 0, 2, 1, 1, 1, 1, 3, 1, 4, 3, + 4, 3, 3, 2, 2, 1, 3, 1, 2, 2, + 2, 2, 4, 1, 1, 1, 1, 1, 1, 1, + 4, 1, 3, 3, 3, 1, 3, 3, 1, 3, + 3, 1, 3, 3, 3, 3, 1, 3, 3, 1, + 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, + 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 3, 1, 3, 1, 1, 3, 0, + 0, 5, 2, 1, 2, 1, 2, 1, 2, 1, + 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 5, 4, 2, + 1, 1, 1, 2, 2, 3, 1, 3, 1, 2, + 1, 2, 1, 4, 5, 5, 6, 2, 1, 3, + 3, 1, 1, 1, 2, 1, 3, 4, 3, 4, + 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, + 2, 1, 3, 1, 3, 1, 2, 1, 2, 1, + 3, 4, 1, 2, 1, 4, 3, 2, 1, 2, + 3, 2, 1, 1, 2, 2, 2, 1, 1, 1, + 1, 1, 1, 3, 2, 3, 1, 2, 3, 2, + 2, 2, 3, 1, 2, 5, 7, 9, 5, 7, + 0, 1, 1, 1, 1, 1, 1 +}; + -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab +enum { YYENOMEM = -2 }; +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) -/* Like YYERROR except do call yyerror. This remains here temporarily - to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. */ +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab +#define YYNOMEM goto yyexhaustedlab -#define YYFAIL goto yyerrlab #define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY && yylen == 1) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - yytoken = YYTRANSLATE (yychar); \ - YYPOPSTACK (1); \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (YYID (0)) - - -#define YYTERROR 1 -#define YYERRCODE 256 - - -/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. - If N is 0, then set CURRENT to the empty location which ends - the previous symbol: RHS[0] (always defined). */ - -#define YYRHSLOC(Rhs, K) ((Rhs)[K]) -#ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (YYID (N)) \ - { \ - (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ - (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ - (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ - (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ - } \ - else \ - { \ - (Current).first_line = (Current).last_line = \ - YYRHSLOC (Rhs, 0).last_line; \ - (Current).first_column = (Current).last_column = \ - YYRHSLOC (Rhs, 0).last_column; \ - } \ - while (YYID (0)) -#endif +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) + +/* Backward compatibility with an undocumented macro. + Use YYerror or YYUNDEF. */ +#define YYERRCODE YYUNDEF -/* YY_LOCATION_PRINT -- Print the location on the stream. - This macro was not mandated originally: define only if we know - we won't break user code: when these are the locations we know. */ +/* Enable debugging if requested. */ +#if YYDEBUG -#ifndef YY_LOCATION_PRINT -# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL -# define YY_LOCATION_PRINT(File, Loc) \ - fprintf (File, "%d.%d-%d.%d", \ - (Loc).first_line, (Loc).first_column, \ - (Loc).last_line, (Loc).last_column) -# else -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf # endif -#endif +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) -/* YYLEX -- calling `yylex' with the right arguments. */ -#ifdef YYLEX_PARAM -# define YYLEX yylex (YYLEX_PARAM) -#else -# define YYLEX yylex () -#endif -/* Enable debugging if requested. */ -#if YYDEBUG -# ifndef YYFPRINTF -# include /* INFRINGES ON USER NAME SPACE */ -# define YYFPRINTF fprintf -# endif +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Kind, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + + +/*-----------------------------------. +| Print this symbol's value on YYO. | +`-----------------------------------*/ -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (YYID (0)) - -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, \ - Type, Value); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (YYID (0)) - - -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ - -/*ARGSUSED*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) -#else -static void -yy_symbol_value_print (yyoutput, yytype, yyvaluep) - FILE *yyoutput; - int yytype; - YYSTYPE const * const yyvaluep; -#endif +yy_symbol_value_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) { + FILE *yyoutput = yyo; + YY_USE (yyoutput); if (!yyvaluep) return; -# ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# else - YYUSE (yyoutput); -# endif - switch (yytype) - { - default: - break; - } + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE (yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END } -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ +/*---------------------------. +| Print this symbol on YYO. | +`---------------------------*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) -#else -static void -yy_symbol_print (yyoutput, yytype, yyvaluep) - FILE *yyoutput; - int yytype; - YYSTYPE const * const yyvaluep; -#endif +yy_symbol_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) { - if (yytype < YYNTOKENS) - YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); - else - YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + YYFPRINTF (yyo, "%s %s (", + yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); - yy_symbol_value_print (yyoutput, yytype, yyvaluep); - YYFPRINTF (yyoutput, ")"); + yy_symbol_value_print (yyo, yykind, yyvaluep); + YYFPRINTF (yyo, ")"); } /*------------------------------------------------------------------. @@ -1504,80 +1566,68 @@ yy_symbol_print (yyoutput, yytype, yyvaluep) | TOP (included). | `------------------------------------------------------------------*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static void -yy_stack_print (yytype_int16 *bottom, yytype_int16 *top) -#else -static void -yy_stack_print (bottom, top) - yytype_int16 *bottom; - yytype_int16 *top; -#endif +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) { YYFPRINTF (stderr, "Stack now"); - for (; bottom <= top; ++bottom) - YYFPRINTF (stderr, " %d", *bottom); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } YYFPRINTF (stderr, "\n"); } -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (YYID (0)) +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) /*------------------------------------------------. | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static void -yy_reduce_print (YYSTYPE *yyvsp, int yyrule) -#else static void -yy_reduce_print (yyvsp, yyrule) - YYSTYPE *yyvsp; - int yyrule; -#endif +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, + int yyrule) { + int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - unsigned long int yylno = yyrline[yyrule]; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", - yyrule - 1, yylno); + YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", + yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { - fprintf (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], - &(yyvsp[(yyi + 1) - (yynrhs)]) - ); - fprintf (stderr, "\n"); + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, + YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), + &yyvsp[(yyi + 1) - (yynrhs)]); + YYFPRINTF (stderr, "\n"); } } -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (yyvsp, Rule); \ -} while (YYID (0)) +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyssp, yyvsp, Rule); \ +} while (0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YYDPRINTF(Args) ((void) 0) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ -#ifndef YYINITDEPTH +#ifndef YYINITDEPTH # define YYINITDEPTH 200 #endif @@ -1592,478 +1642,219 @@ int yydebug; # define YYMAXDEPTH 10000 #endif - - -#if YYERROR_VERBOSE - -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else -/* Return the length of YYSTR. */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static YYSIZE_T -yystrlen (const char *yystr) -#else -static YYSIZE_T -yystrlen (yystr) - const char *yystr; -#endif -{ - YYSIZE_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; - return yylen; -} -# endif -# endif - -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else -/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in - YYDEST. */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static char * -yystpcpy (char *yydest, const char *yysrc) -#else -static char * -yystpcpy (yydest, yysrc) - char *yydest; - const char *yysrc; -#endif -{ - char *yyd = yydest; - const char *yys = yysrc; - - while ((*yyd++ = *yys++) != '\0') - continue; - - return yyd - 1; -} -# endif -# endif - -# ifndef yytnamerr -/* Copy to YYRES the contents of YYSTR after stripping away unnecessary - quotes and backslashes, so that it's suitable for yyerror. The - heuristic is that double-quoting is unnecessary unless the string - contains an apostrophe, a comma, or backslash (other than - backslash-backslash). YYSTR is taken from yytname. If YYRES is - null, do not copy; instead, return the length of what the result - would have been. */ -static YYSIZE_T -yytnamerr (char *yyres, const char *yystr) -{ - if (*yystr == '"') - { - YYSIZE_T yyn = 0; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes: ; - } - - if (! yyres) - return yystrlen (yystr); - return yystpcpy (yyres, yystr) - yyres; -} -# endif - -/* Copy into YYRESULT an error message about the unexpected token - YYCHAR while in state YYSTATE. Return the number of bytes copied, - including the terminating null byte. If YYRESULT is null, do not - copy anything; just return the number of bytes that would be - copied. As a special case, return 0 if an ordinary "syntax error" - message will do. Return YYSIZE_MAXIMUM if overflow occurs during - size calculation. */ -static YYSIZE_T -yysyntax_error (char *yyresult, int yystate, int yychar) -{ - int yyn = yypact[yystate]; - - if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) - return 0; - else - { - int yytype = YYTRANSLATE (yychar); - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); - YYSIZE_T yysize = yysize0; - YYSIZE_T yysize1; - int yysize_overflow = 0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - int yyx; - -# if 0 - /* This is so xgettext sees the translatable formats that are - constructed on the fly. */ - YY_("syntax error, unexpected %s"); - YY_("syntax error, unexpected %s, expecting %s"); - YY_("syntax error, unexpected %s, expecting %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); -# endif - char *yyfmt; - char const *yyf; - static char const yyunexpected[] = "syntax error, unexpected %s"; - static char const yyexpecting[] = ", expecting %s"; - static char const yyor[] = " or %s"; - char yyformat[sizeof yyunexpected - + sizeof yyexpecting - 1 - + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) - * (sizeof yyor - 1))]; - char const *yyprefix = yyexpecting; - - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yycount = 1; - - yyarg[0] = yytname[yytype]; - yyfmt = yystpcpy (yyformat, yyunexpected); - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - yyformat[sizeof yyunexpected - 1] = '\0'; - break; - } - yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - yyfmt = yystpcpy (yyfmt, yyprefix); - yyprefix = yyor; - } - yyf = YY_(yyformat); - yysize1 = yysize + yystrlen (yyf); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - if (yysize_overflow) - return YYSIZE_MAXIMUM; - if (yyresult) - { - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - char *yyp = yyresult; - int yyi = 0; - while ((*yyp = *yyf) != '\0') - { - if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyf += 2; - } - else - { - yyp++; - yyf++; - } - } - } - return yysize; - } -} -#endif /* YYERROR_VERBOSE */ - /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ -/*ARGSUSED*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) -#else static void -yydestruct (yymsg, yytype, yyvaluep) - const char *yymsg; - int yytype; - YYSTYPE *yyvaluep; -#endif +yydestruct (const char *yymsg, + yysymbol_kind_t yykind, YYSTYPE *yyvaluep) { - YYUSE (yyvaluep); - + YY_USE (yyvaluep); if (!yymsg) yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); - - switch (yytype) - { + YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); - default: - break; - } + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE (yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END } - - -/* Prevent warnings from -Wmissing-prototypes. */ - -#ifdef YYPARSE_PARAM -#if defined __STDC__ || defined __cplusplus -int yyparse (void *YYPARSE_PARAM); -#else -int yyparse (); -#endif -#else /* ! YYPARSE_PARAM */ -#if defined __STDC__ || defined __cplusplus -int yyparse (void); -#else -int yyparse (); -#endif -#endif /* ! YYPARSE_PARAM */ - -/* The look-ahead symbol. */ +/* Lookahead token kind. */ int yychar; -/* The semantic value of the look-ahead symbol. */ +/* The semantic value of the lookahead symbol. */ YYSTYPE yylval; - /* Number of syntax errors so far. */ int yynerrs; + /*----------. | yyparse. | `----------*/ -#ifdef YYPARSE_PARAM -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -int -yyparse (void *YYPARSE_PARAM) -#else -int -yyparse (YYPARSE_PARAM) - void *YYPARSE_PARAM; -#endif -#else /* ! YYPARSE_PARAM */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) int yyparse (void) -#else -int -yyparse () - -#endif -#endif { - - int yystate; - int yyn; - int yyresult; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; - /* Look-ahead token as an internal (translated) token number. */ - int yytoken = 0; -#if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ - char yymsgbuf[128]; - char *yymsg = yymsgbuf; - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; -#endif - - /* Three stacks and their tools: - `yyss': related to states, - `yyvs': related to semantic values, - `yyls': related to locations. - - Refer to the stacks thru separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ - - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss = yyssa; - yytype_int16 *yyssp; - - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs = yyvsa; - YYSTYPE *yyvsp; + yy_state_fast_t yystate = 0; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus = 0; + /* Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + /* Their size. */ + YYPTRDIFF_T yystacksize = YYINITDEPTH; -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) + /* The state stack: array, bottom, top. */ + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss = yyssa; + yy_state_t *yyssp = yyss; - YYSIZE_T yystacksize = YYINITDEPTH; + /* The semantic value stack: array, bottom, top. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs = yyvsa; + YYSTYPE *yyvsp = yyvs; + int yyn; + /* The return value of yyparse. */ + int yyresult; + /* Lookahead symbol kind. */ + yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) + /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ int yylen = 0; YYDPRINTF ((stderr, "Starting parse\n")); - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - - yyssp = yyss; - yyvsp = yyvs; + yychar = YYEMPTY; /* Cause a token to be read. */ goto yysetstate; + /*------------------------------------------------------------. -| yynewstate -- Push a new state, which is found in yystate. | +| yynewstate -- push a new state, which is found in yystate. | `------------------------------------------------------------*/ - yynewstate: +yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. So pushing a state here evens the stacks. */ yyssp++; - yysetstate: - *yyssp = yystate; + +/*--------------------------------------------------------------------. +| yysetstate -- set current state (the top of the stack) to yystate. | +`--------------------------------------------------------------------*/ +yysetstate: + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YY_ASSERT (0 <= yystate && yystate < YYNSTATES); + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + YY_STACK_PRINT (yyss, yyssp); if (yyss + yystacksize - 1 <= yyssp) +#if !defined yyoverflow && !defined YYSTACK_RELOCATE + YYNOMEM; +#else { /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; + YYPTRDIFF_T yysize = yyssp - yyss + 1; -#ifdef yyoverflow +# if defined yyoverflow { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; - - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - - &yystacksize); - - yyss = yyss1; - yyvs = yyvs1; + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + yy_state_t *yyss1 = yyss; + YYSTYPE *yyvs1 = yyvs; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * YYSIZEOF (*yyssp), + &yyvs1, yysize * YYSIZEOF (*yyvsp), + &yystacksize); + yyss = yyss1; + yyvs = yyvs1; } -#else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE - goto yyexhaustedlab; -# else +# else /* defined YYSTACK_RELOCATE */ /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; + YYNOMEM; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; + yystacksize = YYMAXDEPTH; { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss); - YYSTACK_RELOCATE (yyvs); - + yy_state_t *yyss1 = yyss; + union yyalloc *yyptr = + YY_CAST (union yyalloc *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); + if (! yyptr) + YYNOMEM; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); # undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); } # endif -#endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; - - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "Stack size increased to %ld\n", + YY_CAST (long, yystacksize))); + YY_IGNORE_USELESS_CAST_END if (yyss + yystacksize - 1 <= yyssp) - YYABORT; + YYABORT; } +#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + if (yystate == YYFINAL) + YYACCEPT; goto yybackup; + /*-----------. | yybackup. | `-----------*/ yybackup: - /* Do appropriate processing given the current state. Read a - look-ahead token if we need one and don't already have one. */ + lookahead token if we need one and don't already have one. */ - /* First try to decide what to do without reference to look-ahead token. */ + /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yyn == YYPACT_NINF) + if (yypact_value_is_default (yyn)) goto yydefault; - /* Not known => get a look-ahead token if don't already have one. */ + /* Not known => get a lookahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ + /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ if (yychar == YYEMPTY) { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; + YYDPRINTF ((stderr, "Reading a token\n")); + yychar = yylex (); } if (yychar <= YYEOF) { - yychar = yytoken = YYEOF; + yychar = YYEOF; + yytoken = YYSYMBOL_YYEOF; YYDPRINTF ((stderr, "Now at end of input.\n")); } + else if (yychar == YYerror) + { + /* The scanner already issued an error message, process directly + to error recovery. But do not keep the error token as + lookahead, it is too special and may lead us to an endless + loop in error recovery. */ + yychar = YYUNDEF; + yytoken = YYSYMBOL_YYerror; + goto yyerrlab1; + } else { yytoken = YYTRANSLATE (yychar); @@ -2078,30 +1869,26 @@ yyparse () yyn = yytable[yyn]; if (yyn <= 0) { - if (yyn == 0 || yyn == YYTABLE_NINF) - goto yyerrlab; + if (yytable_value_is_error (yyn)) + goto yyerrlab; yyn = -yyn; goto yyreduce; } - if (yyn == YYFINAL) - YYACCEPT; - /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; - /* Shift the look-ahead token. */ + /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - - /* Discard the shifted token unless it is eof. */ - if (yychar != YYEOF) - yychar = YYEMPTY; - yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + /* Discard the shifted token. */ + yychar = YYEMPTY; goto yynewstate; @@ -2116,14 +1903,14 @@ yyparse () /*-----------------------------. -| yyreduce -- Do a reduction. | +| yyreduce -- do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ yylen = yyr2[yyn]; /* If YYLEN is nonzero, implement the default value of the action: - `$$ = $1'. + '$$ = $1'. Otherwise, the following line sets YYVAL to garbage. This behavior is undocumented and Bison @@ -2136,613 +1923,676 @@ yyparse () YY_REDUCE_PRINT (yyn); switch (yyn) { - case 2: -#line 344 "cod/cod.y" - { - yyparse_value = (sm_ref)(yyvsp[(1) - (1)].list); - ;} + case 2: /* start: declaration_list */ +#line 358 "cod.y" + { + yyparse_value = (sm_ref)(yyvsp[0].list); + } +#line 1932 "cod.tab.c" break; - case 3: -#line 348 "cod/cod.y" - { - yyparse_value = (yyvsp[(1) - (1)].reference); - ;} + case 3: /* start: compound_statement */ +#line 362 "cod.y" + { + yyparse_value = (yyvsp[0].reference); + } +#line 1940 "cod.tab.c" break; - case 4: -#line 354 "cod/cod.y" - { + case 4: /* primary_expression: identifier_ref */ +#line 368 "cod.y" + { (yyval.reference) = cod_new_identifier(); - (yyval.reference)->node.identifier.id = (yyvsp[(1) - (1)].info).string; - (yyval.reference)->node.identifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; - ;} + (yyval.reference)->node.identifier.id = (yyvsp[0].info).string; + (yyval.reference)->node.identifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; + } +#line 1950 "cod.tab.c" break; - case 6: -#line 363 "cod/cod.y" - { (yyval.reference) = (yyvsp[(2) - (3)].reference); ;} + case 6: /* primary_expression: LPAREN expression RPAREN */ +#line 377 "cod.y" + { (yyval.reference) = (yyvsp[-1].reference); } +#line 1956 "cod.tab.c" break; - case 8: -#line 371 "cod/cod.y" - { + case 8: /* postfix_expression: postfix_expression LBRACKET expression RBRACKET */ +#line 385 "cod.y" + { (yyval.reference) = cod_new_element_ref(); - (yyval.reference)->node.element_ref.lx_srcpos = (yyvsp[(2) - (4)].info).lx_srcpos; - (yyval.reference)->node.element_ref.expression = (yyvsp[(3) - (4)].reference); - (yyval.reference)->node.element_ref.array_ref = (yyvsp[(1) - (4)].reference); - ;} + (yyval.reference)->node.element_ref.lx_srcpos = (yyvsp[-2].info).lx_srcpos; + (yyval.reference)->node.element_ref.expression = (yyvsp[-1].reference); + (yyval.reference)->node.element_ref.array_ref = (yyvsp[-3].reference); + } +#line 1967 "cod.tab.c" break; - case 9: -#line 378 "cod/cod.y" - { + case 9: /* postfix_expression: postfix_expression DOT identifier_ref */ +#line 392 "cod.y" + { (yyval.reference) = cod_new_field_ref(); - (yyval.reference)->node.field_ref.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; - (yyval.reference)->node.field_ref.lx_field = (yyvsp[(3) - (3)].info).string; - (yyval.reference)->node.field_ref.struct_ref = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.field_ref.lx_srcpos = (yyvsp[-1].info).lx_srcpos; + (yyval.reference)->node.field_ref.lx_field = (yyvsp[0].info).string; + (yyval.reference)->node.field_ref.struct_ref = (yyvsp[-2].reference); + } +#line 1978 "cod.tab.c" break; - case 10: -#line 385 "cod/cod.y" - { + case 10: /* postfix_expression: postfix_expression LPAREN argument_expression_list RPAREN */ +#line 399 "cod.y" + { (yyval.reference) = cod_new_subroutine_call(); - (yyval.reference)->node.subroutine_call.lx_srcpos = (yyvsp[(2) - (4)].info).lx_srcpos; - (yyval.reference)->node.subroutine_call.arguments = (yyvsp[(3) - (4)].list); - (yyval.reference)->node.subroutine_call.sm_func_ref = (yyvsp[(1) - (4)].reference); - ;} + (yyval.reference)->node.subroutine_call.lx_srcpos = (yyvsp[-2].info).lx_srcpos; + (yyval.reference)->node.subroutine_call.arguments = (yyvsp[-1].list); + (yyval.reference)->node.subroutine_call.sm_func_ref = (yyvsp[-3].reference); + } +#line 1989 "cod.tab.c" break; - case 11: -#line 392 "cod/cod.y" - { + case 11: /* postfix_expression: postfix_expression LPAREN RPAREN */ +#line 406 "cod.y" + { (yyval.reference) = cod_new_subroutine_call(); - (yyval.reference)->node.subroutine_call.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.subroutine_call.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.subroutine_call.arguments = NULL; - (yyval.reference)->node.subroutine_call.sm_func_ref = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.subroutine_call.sm_func_ref = (yyvsp[-2].reference); + } +#line 2000 "cod.tab.c" break; - case 12: -#line 398 "cod/cod.y" - { + case 12: /* postfix_expression: postfix_expression ARROW identifier_ref */ +#line 412 "cod.y" + { (yyval.reference) = cod_new_field_ref(); - (yyval.reference)->node.field_ref.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; - (yyval.reference)->node.field_ref.lx_field = (yyvsp[(3) - (3)].info).string; - (yyval.reference)->node.field_ref.struct_ref = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.field_ref.lx_srcpos = (yyvsp[-1].info).lx_srcpos; + (yyval.reference)->node.field_ref.lx_field = (yyvsp[0].info).string; + (yyval.reference)->node.field_ref.struct_ref = (yyvsp[-2].reference); + } +#line 2011 "cod.tab.c" break; - case 13: -#line 404 "cod/cod.y" - { + case 13: /* postfix_expression: postfix_expression INC_OP */ +#line 418 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (2)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.operator.op = op_inc; (yyval.reference)->node.operator.right = NULL; - (yyval.reference)->node.operator.left = (yyvsp[(1) - (2)].reference); - ;} + (yyval.reference)->node.operator.left = (yyvsp[-1].reference); + } +#line 2023 "cod.tab.c" break; - case 14: -#line 411 "cod/cod.y" - { + case 14: /* postfix_expression: postfix_expression DEC_OP */ +#line 425 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (2)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.operator.op = op_dec; (yyval.reference)->node.operator.right = NULL; - (yyval.reference)->node.operator.left = (yyvsp[(1) - (2)].reference); - ;} + (yyval.reference)->node.operator.left = (yyvsp[-1].reference); + } +#line 2035 "cod.tab.c" break; - case 15: -#line 421 "cod/cod.y" - { + case 15: /* argument_expression_list: assignment_expression */ +#line 435 "cod.y" + { (yyval.list) = malloc(sizeof(struct list_struct)); - (yyval.list)->node = (yyvsp[(1) - (1)].reference); + (yyval.list)->node = (yyvsp[0].reference); (yyval.list)->next = NULL; - ;} + } +#line 2045 "cod.tab.c" break; - case 16: -#line 427 "cod/cod.y" - { - sm_list tmp = (yyvsp[(1) - (3)].list); + case 16: /* argument_expression_list: argument_expression_list COMMA assignment_expression */ +#line 441 "cod.y" + { + sm_list tmp = (yyvsp[-2].list); while (tmp->next != NULL) { tmp = tmp->next; } tmp->next = malloc(sizeof(struct list_struct)); - tmp->next->node = (yyvsp[(3) - (3)].reference); + tmp->next->node = (yyvsp[0].reference); tmp->next->next = NULL; - (yyval.list) = (yyvsp[(1) - (3)].list); - ;} + (yyval.list) = (yyvsp[-2].list); + } +#line 2060 "cod.tab.c" break; - case 18: -#line 442 "cod/cod.y" - { + case 18: /* unary_expression: INC_OP unary_expression */ +#line 456 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_inc; - (yyval.reference)->node.operator.right = (yyvsp[(2) - (2)].reference); + (yyval.reference)->node.operator.right = (yyvsp[0].reference); (yyval.reference)->node.operator.left = NULL; - ;} + } +#line 2072 "cod.tab.c" break; - case 19: -#line 449 "cod/cod.y" - { + case 19: /* unary_expression: DEC_OP unary_expression */ +#line 463 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_dec; - (yyval.reference)->node.operator.right = (yyvsp[(2) - (2)].reference); + (yyval.reference)->node.operator.right = (yyvsp[0].reference); (yyval.reference)->node.operator.left = NULL; - ;} + } +#line 2084 "cod.tab.c" break; - case 20: -#line 456 "cod/cod.y" - { + case 20: /* unary_expression: unary_operator cast_expression */ +#line 470 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; - (yyval.reference)->node.operator.op = (yyvsp[(1) - (2)].info).op; - (yyval.reference)->node.operator.right = (yyvsp[(2) - (2)].reference); + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; + (yyval.reference)->node.operator.op = (yyvsp[-1].info).op; + (yyval.reference)->node.operator.right = (yyvsp[0].reference); (yyval.reference)->node.operator.left = NULL; - ;} + } +#line 2096 "cod.tab.c" break; - case 21: -#line 463 "cod/cod.y" - { + case 21: /* unary_expression: SIZEOF unary_expression */ +#line 477 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_sizeof; - (yyval.reference)->node.operator.right = (yyvsp[(2) - (2)].reference); + (yyval.reference)->node.operator.right = (yyvsp[0].reference); (yyval.reference)->node.operator.left = NULL; - ;} + } +#line 2108 "cod.tab.c" break; - case 22: -#line 470 "cod/cod.y" - { + case 22: /* unary_expression: SIZEOF LPAREN type_name RPAREN */ +#line 484 "cod.y" + { /* dummy up a cast to hold the sm_list of the type */ sm_ref cast = cod_new_cast(); - cast->node.cast.lx_srcpos = (yyvsp[(1) - (4)].info).lx_srcpos; - cast->node.cast.type_spec = (yyvsp[(3) - (4)].list); + cast->node.cast.lx_srcpos = (yyvsp[-3].info).lx_srcpos; + cast->node.cast.type_spec = (yyvsp[-1].list); cast->node.cast.expression = NULL; (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(1) - (4)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-3].info).lx_srcpos; (yyval.reference)->node.operator.op = op_sizeof; (yyval.reference)->node.operator.right = cast; (yyval.reference)->node.operator.left = NULL; - ;} + } +#line 2126 "cod.tab.c" break; - case 23: -#line 485 "cod/cod.y" - { + case 23: /* unary_operator: ARITH_AND */ +#line 499 "cod.y" + { (yyval.info).op = op_address; - ;} + } +#line 2134 "cod.tab.c" break; - case 24: -#line 488 "cod/cod.y" - { + case 24: /* unary_operator: STAR */ +#line 502 "cod.y" + { (yyval.info).op = op_deref; - ;} + } +#line 2142 "cod.tab.c" break; - case 25: -#line 491 "cod/cod.y" - { + case 25: /* unary_operator: PLUS */ +#line 505 "cod.y" + { (yyval.info).op = op_plus; - ;} + } +#line 2150 "cod.tab.c" break; - case 26: -#line 494 "cod/cod.y" - { + case 26: /* unary_operator: MINUS */ +#line 508 "cod.y" + { (yyval.info).op = op_minus; - ;} + } +#line 2158 "cod.tab.c" break; - case 27: -#line 497 "cod/cod.y" - { + case 27: /* unary_operator: TILDE */ +#line 511 "cod.y" + { (yyval.info).op = op_not; - ;} + } +#line 2166 "cod.tab.c" break; - case 28: -#line 500 "cod/cod.y" - { + case 28: /* unary_operator: BANG */ +#line 514 "cod.y" + { (yyval.info).op = op_log_neg; - ;} + } +#line 2174 "cod.tab.c" break; - case 30: -#line 507 "cod/cod.y" - { + case 30: /* cast_expression: LPAREN type_name RPAREN cast_expression */ +#line 521 "cod.y" + { (yyval.reference) = cod_new_cast(); - (yyval.reference)->node.cast.lx_srcpos = (yyvsp[(1) - (4)].info).lx_srcpos; - (yyval.reference)->node.cast.type_spec = (yyvsp[(2) - (4)].list); - (yyval.reference)->node.cast.expression = (yyvsp[(4) - (4)].reference); - ;} + (yyval.reference)->node.cast.lx_srcpos = (yyvsp[-3].info).lx_srcpos; + (yyval.reference)->node.cast.type_spec = (yyvsp[-2].list); + (yyval.reference)->node.cast.expression = (yyvsp[0].reference); + } +#line 2185 "cod.tab.c" break; - case 32: -#line 519 "cod/cod.y" - { + case 32: /* multiplicative_expression: multiplicative_expression STAR cast_expression */ +#line 533 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_mult; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2197 "cod.tab.c" break; - case 33: -#line 528 "cod/cod.y" - { + case 33: /* multiplicative_expression: multiplicative_expression SLASH cast_expression */ +#line 542 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_div; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2209 "cod.tab.c" break; - case 34: -#line 537 "cod/cod.y" - { + case 34: /* multiplicative_expression: multiplicative_expression MODULUS cast_expression */ +#line 551 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_modulus; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2221 "cod.tab.c" break; - case 36: -#line 550 "cod/cod.y" - { + case 36: /* additive_expression: additive_expression PLUS multiplicative_expression */ +#line 564 "cod.y" + { (yyval.reference) = cod_new_operator(); (yyval.reference)->node.operator.op = op_plus; - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2233 "cod.tab.c" break; - case 37: -#line 559 "cod/cod.y" - { + case 37: /* additive_expression: additive_expression MINUS multiplicative_expression */ +#line 573 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_minus; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2245 "cod.tab.c" break; - case 39: -#line 572 "cod/cod.y" - { + case 39: /* shift_expression: shift_expression LEFT_SHIFT additive_expression */ +#line 586 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_left_shift; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2257 "cod.tab.c" break; - case 40: -#line 581 "cod/cod.y" - { + case 40: /* shift_expression: shift_expression RIGHT_SHIFT additive_expression */ +#line 595 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_right_shift; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2269 "cod.tab.c" break; - case 42: -#line 594 "cod/cod.y" - { + case 42: /* relational_expression: relational_expression LT shift_expression */ +#line 608 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_lt; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2281 "cod.tab.c" break; - case 43: -#line 603 "cod/cod.y" - { + case 43: /* relational_expression: relational_expression GT shift_expression */ +#line 617 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_gt; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2293 "cod.tab.c" break; - case 44: -#line 612 "cod/cod.y" - { + case 44: /* relational_expression: relational_expression LEQ shift_expression */ +#line 626 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_leq; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2305 "cod.tab.c" break; - case 45: -#line 621 "cod/cod.y" - { + case 45: /* relational_expression: relational_expression GEQ shift_expression */ +#line 635 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_geq; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2317 "cod.tab.c" break; - case 47: -#line 634 "cod/cod.y" - { + case 47: /* equality_expression: equality_expression EQ relational_expression */ +#line 648 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_eq; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2329 "cod.tab.c" break; - case 48: -#line 643 "cod/cod.y" - { + case 48: /* equality_expression: equality_expression NEQ relational_expression */ +#line 657 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_neq; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2341 "cod.tab.c" break; - case 50: -#line 656 "cod/cod.y" - { + case 50: /* and_expression: and_expression ARITH_AND equality_expression */ +#line 670 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_arith_and; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2353 "cod.tab.c" break; - case 52: -#line 669 "cod/cod.y" - { + case 52: /* exclusive_or_expression: exclusive_or_expression ARITH_XOR and_expression */ +#line 683 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_arith_xor; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2365 "cod.tab.c" break; - case 54: -#line 682 "cod/cod.y" - { + case 54: /* inclusive_or_expression: inclusive_or_expression ARITH_OR exclusive_or_expression */ +#line 696 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_arith_or; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2377 "cod.tab.c" break; - case 56: -#line 695 "cod/cod.y" - { + case 56: /* logical_and_expression: logical_and_expression LOG_AND inclusive_or_expression */ +#line 709 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_log_and; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2389 "cod.tab.c" break; - case 58: -#line 708 "cod/cod.y" - { + case 58: /* logical_or_expression: logical_or_expression LOG_OR logical_and_expression */ +#line 722 "cod.y" + { (yyval.reference) = cod_new_operator(); - (yyval.reference)->node.operator.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.operator.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.operator.op = op_log_or; - (yyval.reference)->node.operator.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.operator.left = (yyvsp[(1) - (3)].reference); - ;} + (yyval.reference)->node.operator.right = (yyvsp[0].reference); + (yyval.reference)->node.operator.left = (yyvsp[-2].reference); + } +#line 2401 "cod.tab.c" break; - case 60: -#line 721 "cod/cod.y" - { + case 60: /* conditional_expression: logical_or_expression QUESTION expression COLON conditional_expression */ +#line 735 "cod.y" + { (yyval.reference) = cod_new_conditional_operator(); - (yyval.reference)->node.conditional_operator.lx_srcpos = (yyvsp[(2) - (5)].info).lx_srcpos; - (yyval.reference)->node.conditional_operator.condition = (yyvsp[(1) - (5)].reference); - (yyval.reference)->node.conditional_operator.e1 = (yyvsp[(3) - (5)].reference); - (yyval.reference)->node.conditional_operator.e2 = (yyvsp[(5) - (5)].reference); - ;} + (yyval.reference)->node.conditional_operator.lx_srcpos = (yyvsp[-3].info).lx_srcpos; + (yyval.reference)->node.conditional_operator.condition = (yyvsp[-4].reference); + (yyval.reference)->node.conditional_operator.e1 = (yyvsp[-2].reference); + (yyval.reference)->node.conditional_operator.e2 = (yyvsp[0].reference); + } +#line 2413 "cod.tab.c" break; - case 61: -#line 732 "cod/cod.y" - { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_eq;;} + case 61: /* assignment_operator: ASSIGN */ +#line 746 "cod.y" + { (yyval.info) = (yyvsp[0].info); (yyval.info).op = op_eq;} +#line 2419 "cod.tab.c" break; - case 62: -#line 734 "cod/cod.y" - { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_mult;;} + case 62: /* assignment_operator: MUL_ASSIGN */ +#line 748 "cod.y" + { (yyval.info) = (yyvsp[0].info); (yyval.info).op = op_mult;} +#line 2425 "cod.tab.c" break; - case 63: -#line 736 "cod/cod.y" - { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_div;;} + case 63: /* assignment_operator: DIV_ASSIGN */ +#line 750 "cod.y" + { (yyval.info) = (yyvsp[0].info); (yyval.info).op = op_div;} +#line 2431 "cod.tab.c" break; - case 64: -#line 738 "cod/cod.y" - { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_modulus;;} + case 64: /* assignment_operator: MOD_ASSIGN */ +#line 752 "cod.y" + { (yyval.info) = (yyvsp[0].info); (yyval.info).op = op_modulus;} +#line 2437 "cod.tab.c" break; - case 65: -#line 740 "cod/cod.y" - { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_plus;;} + case 65: /* assignment_operator: ADD_ASSIGN */ +#line 754 "cod.y" + { (yyval.info) = (yyvsp[0].info); (yyval.info).op = op_plus;} +#line 2443 "cod.tab.c" break; - case 66: -#line 742 "cod/cod.y" - { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_minus;;} + case 66: /* assignment_operator: SUB_ASSIGN */ +#line 756 "cod.y" + { (yyval.info) = (yyvsp[0].info); (yyval.info).op = op_minus;} +#line 2449 "cod.tab.c" break; - case 67: -#line 744 "cod/cod.y" - { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_left_shift;;} + case 67: /* assignment_operator: LEFT_ASSIGN */ +#line 758 "cod.y" + { (yyval.info) = (yyvsp[0].info); (yyval.info).op = op_left_shift;} +#line 2455 "cod.tab.c" break; - case 68: -#line 746 "cod/cod.y" - { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_right_shift;;} + case 68: /* assignment_operator: RIGHT_ASSIGN */ +#line 760 "cod.y" + { (yyval.info) = (yyvsp[0].info); (yyval.info).op = op_right_shift;} +#line 2461 "cod.tab.c" break; - case 69: -#line 748 "cod/cod.y" - { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_arith_and;;} + case 69: /* assignment_operator: AND_ASSIGN */ +#line 762 "cod.y" + { (yyval.info) = (yyvsp[0].info); (yyval.info).op = op_arith_and;} +#line 2467 "cod.tab.c" break; - case 70: -#line 750 "cod/cod.y" - { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_arith_xor;;} + case 70: /* assignment_operator: XOR_ASSIGN */ +#line 764 "cod.y" + { (yyval.info) = (yyvsp[0].info); (yyval.info).op = op_arith_xor;} +#line 2473 "cod.tab.c" break; - case 71: -#line 752 "cod/cod.y" - { (yyval.info) = (yyvsp[(1) - (1)].info); (yyval.info).op = op_arith_or;;} + case 71: /* assignment_operator: OR_ASSIGN */ +#line 766 "cod.y" + { (yyval.info) = (yyvsp[0].info); (yyval.info).op = op_arith_or;} +#line 2479 "cod.tab.c" break; - case 72: -#line 757 "cod/cod.y" - { (yyval.reference) = (yyvsp[(1) - (1)].reference);;} + case 72: /* assignment_expression: conditional_expression */ +#line 771 "cod.y" + { (yyval.reference) = (yyvsp[0].reference);} +#line 2485 "cod.tab.c" break; - case 73: -#line 760 "cod/cod.y" - { + case 73: /* assignment_expression: unary_expression assignment_operator assignment_expression */ +#line 774 "cod.y" + { (yyval.reference) = cod_new_assignment_expression(); - (yyval.reference)->node.assignment_expression.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; - (yyval.reference)->node.assignment_expression.left = (yyvsp[(1) - (3)].reference); - (yyval.reference)->node.assignment_expression.right = (yyvsp[(3) - (3)].reference); - (yyval.reference)->node.assignment_expression.op = (yyvsp[(2) - (3)].info).op; - ;} + (yyval.reference)->node.assignment_expression.lx_srcpos = (yyvsp[-1].info).lx_srcpos; + (yyval.reference)->node.assignment_expression.left = (yyvsp[-2].reference); + (yyval.reference)->node.assignment_expression.right = (yyvsp[0].reference); + (yyval.reference)->node.assignment_expression.op = (yyvsp[-1].info).op; + } +#line 2497 "cod.tab.c" break; - case 74: -#line 771 "cod/cod.y" - {(yyval.reference) = (yyvsp[(1) - (1)].reference);;} + case 74: /* expression: assignment_expression */ +#line 785 "cod.y" + {(yyval.reference) = (yyvsp[0].reference);} +#line 2503 "cod.tab.c" break; - case 75: -#line 773 "cod/cod.y" - { + case 75: /* expression: expression COMMA assignment_expression */ +#line 787 "cod.y" + { (yyval.reference) = cod_new_comma_expression(); - (yyval.reference)->node.comma_expression.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; - (yyval.reference)->node.comma_expression.left = (yyvsp[(1) - (3)].reference); - (yyval.reference)->node.comma_expression.right = (yyvsp[(3) - (3)].reference); - ;} + (yyval.reference)->node.comma_expression.lx_srcpos = (yyvsp[-1].info).lx_srcpos; + (yyval.reference)->node.comma_expression.left = (yyvsp[-2].reference); + (yyval.reference)->node.comma_expression.right = (yyvsp[0].reference); + } +#line 2514 "cod.tab.c" break; - case 77: -#line 786 "cod/cod.y" - { + case 77: /* init_declarator_list: init_declarator */ +#line 800 "cod.y" + { (yyval.list) = malloc(sizeof(struct list_struct)); - (yyval.list)->node = (yyvsp[(1) - (1)].reference); + (yyval.list)->node = (yyvsp[0].reference); (yyval.list)->next = NULL; - ;} + } +#line 2524 "cod.tab.c" break; - case 78: -#line 791 "cod/cod.y" - { - sm_list tmp = (yyvsp[(1) - (3)].list); + case 78: /* init_declarator_list: init_declarator_list COMMA init_declarator */ +#line 805 "cod.y" + { + sm_list tmp = (yyvsp[-2].list); while (tmp->next != NULL) { tmp = tmp->next; } tmp->next = malloc(sizeof(struct list_struct)); tmp = tmp->next; - tmp->node = (yyvsp[(3) - (3)].reference); + tmp->node = (yyvsp[0].reference); tmp->next = NULL; - (yyval.list) = (yyvsp[(1) - (3)].list); - ;} + (yyval.list) = (yyvsp[-2].list); + } +#line 2540 "cod.tab.c" break; - case 79: -#line 810 "cod/cod.y" - { + case 79: /* $@1: %empty */ +#line 824 "cod.y" + { if (parsing_type) { - yyparse_value = (sm_ref) (yyvsp[(1) - (1)].list); + yyparse_value = (sm_ref) (yyvsp[0].list); YYACCEPT; } - ;} + } +#line 2551 "cod.tab.c" break; - case 80: -#line 817 "cod/cod.y" - { /* stop here if we're just doing a proc decl */ + case 80: /* @2: %empty */ +#line 831 "cod.y" + { /* stop here if we're just doing a proc decl */ if (parsing_param_spec) { - (yyval.reference) = (yyvsp[(3) - (3)].list)->node; + (yyval.reference) = (yyvsp[0].list)->node; if ((yyval.reference)->node_type == cod_declaration) { if ((yyval.reference)->node.declaration.type_spec == NULL) { - (yyval.reference)->node.declaration.type_spec = (yyvsp[(1) - (3)].list); + (yyval.reference)->node.declaration.type_spec = (yyvsp[-2].list); } else { /* * the pointer type list (with the declarator) * goes at the end */ - sm_list tmp = (yyvsp[(1) - (3)].list); + sm_list tmp = (yyvsp[-2].list); while (tmp->next != NULL) { tmp = tmp->next; } tmp->next = (yyval.reference)->node.declaration.type_spec; - (yyval.reference)->node.declaration.type_spec = (yyvsp[(1) - (3)].list); + (yyval.reference)->node.declaration.type_spec = (yyvsp[-2].list); } } else { printf("unexpected node in init_declarator\n"); cod_print((yyval.reference)); } - yyparse_value = (yyvsp[(3) - (3)].list)->node; - free((yyvsp[(3) - (3)].list)); + yyparse_value = (yyvsp[0].list)->node; + free((yyvsp[0].list)); YYACCEPT; } - ;} + } +#line 2583 "cod.tab.c" break; - case 81: -#line 845 "cod/cod.y" - { - (yyval.list) = (yyvsp[(3) - (5)].list); - sm_list dtmp = (yyvsp[(3) - (5)].list); + case 81: /* declaration: declaration_specifiers $@1 init_declarator_list @2 SEMI */ +#line 859 "cod.y" + { + (yyval.list) = (yyvsp[-2].list); + sm_list dtmp = (yyvsp[-2].list); while (dtmp) { sm_list type_spec; if (dtmp->next != NULL) { - type_spec = cod_dup_list((yyvsp[(1) - (5)].list)); + type_spec = cod_dup_list((yyvsp[-4].list)); } else { - type_spec = (yyvsp[(1) - (5)].list); + type_spec = (yyvsp[-4].list); } sm_ref decl = dtmp->node; if (decl->node_type == cod_declaration) { @@ -2787,281 +2637,312 @@ yyparse () } dtmp = dtmp->next; } - (void)(yyvsp[(4) - (5)].reference); - ;} + (void)(yyvsp[-1].reference); + } +#line 2643 "cod.tab.c" break; - case 82: -#line 900 "cod/cod.y" - { - (yyval.list) = (yyvsp[(1) - (2)].list); - ;} + case 82: /* declaration: declaration_specifiers SEMI */ +#line 914 "cod.y" + { + (yyval.list) = (yyvsp[-1].list); + } +#line 2651 "cod.tab.c" break; - case 83: -#line 906 "cod/cod.y" - { + case 83: /* declaration_specifiers: storage_class_specifier */ +#line 920 "cod.y" + { (yyval.list) = malloc(sizeof(struct list_struct)); - (yyval.list)->node = (yyvsp[(1) - (1)].reference); + (yyval.list)->node = (yyvsp[0].reference); (yyval.list)->next = NULL; - ;} + } +#line 2661 "cod.tab.c" break; - case 84: -#line 911 "cod/cod.y" - { + case 84: /* declaration_specifiers: storage_class_specifier declaration_specifiers */ +#line 925 "cod.y" + { sm_list tmp = malloc(sizeof(struct list_struct)); - tmp->node = (yyvsp[(1) - (2)].reference); - tmp->next = (yyvsp[(2) - (2)].list); + tmp->node = (yyvsp[-1].reference); + tmp->next = (yyvsp[0].list); (yyval.list) = tmp; - ;} + } +#line 2672 "cod.tab.c" break; - case 85: -#line 917 "cod/cod.y" - { + case 85: /* declaration_specifiers: type_specifier */ +#line 931 "cod.y" + { (yyval.list) = malloc(sizeof(struct list_struct)); - (yyval.list)->node = (yyvsp[(1) - (1)].reference); + (yyval.list)->node = (yyvsp[0].reference); (yyval.list)->next = NULL; - ;} + } +#line 2682 "cod.tab.c" break; - case 86: -#line 922 "cod/cod.y" - { + case 86: /* declaration_specifiers: type_specifier declaration_specifiers */ +#line 936 "cod.y" + { sm_list tmp = malloc(sizeof(struct list_struct)); - tmp->node = (yyvsp[(1) - (2)].reference); - tmp->next = (yyvsp[(2) - (2)].list); + tmp->node = (yyvsp[-1].reference); + tmp->next = (yyvsp[0].list); (yyval.list) = tmp; - ;} + } +#line 2693 "cod.tab.c" break; - case 87: -#line 928 "cod/cod.y" - { + case 87: /* declaration_specifiers: type_qualifier */ +#line 942 "cod.y" + { (yyval.list) = malloc(sizeof(struct list_struct)); - (yyval.list)->node = (yyvsp[(1) - (1)].reference); + (yyval.list)->node = (yyvsp[0].reference); (yyval.list)->next = NULL; - ;} + } +#line 2703 "cod.tab.c" break; - case 88: -#line 933 "cod/cod.y" - { + case 88: /* declaration_specifiers: type_qualifier declaration_specifiers */ +#line 947 "cod.y" + { sm_list tmp = malloc(sizeof(struct list_struct)); - tmp->node = (yyvsp[(1) - (2)].reference); - tmp->next = (yyvsp[(2) - (2)].list); + tmp->node = (yyvsp[-1].reference); + tmp->next = (yyvsp[0].list); (yyval.list) = tmp; - ;} + } +#line 2714 "cod.tab.c" break; - case 90: -#line 944 "cod/cod.y" - { - if ((yyvsp[(1) - (3)].reference)->node_type == cod_declaration) { - (yyvsp[(1) - (3)].reference)->node.declaration.init_value = (yyvsp[(3) - (3)].reference); - } else if ((yyvsp[(1) - (3)].reference)->node_type == cod_array_type_decl) { - sm_ref tmp = (yyvsp[(1) - (3)].reference)->node.array_type_decl.element_ref; + case 90: /* init_declarator: declarator ASSIGN initializer */ +#line 958 "cod.y" + { + if ((yyvsp[-2].reference)->node_type == cod_declaration) { + (yyvsp[-2].reference)->node.declaration.init_value = (yyvsp[0].reference); + } else if ((yyvsp[-2].reference)->node_type == cod_array_type_decl) { + sm_ref tmp = (yyvsp[-2].reference)->node.array_type_decl.element_ref; while (tmp->node_type == cod_array_type_decl) { tmp = tmp->node.array_type_decl.element_ref; } assert(tmp->node_type == cod_declaration); - tmp->node.declaration.init_value = (yyvsp[(3) - (3)].reference); + tmp->node.declaration.init_value = (yyvsp[0].reference); } - ;} + } +#line 2731 "cod.tab.c" break; - case 91: -#line 959 "cod/cod.y" - { + case 91: /* storage_class_specifier: TYPEDEF */ +#line 973 "cod.y" + { (yyval.reference) = cod_new_type_specifier(); - (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.type_specifier.token = TYPEDEF; - ;} + } +#line 2741 "cod.tab.c" break; - case 92: -#line 964 "cod/cod.y" - { + case 92: /* storage_class_specifier: STATIC */ +#line 978 "cod.y" + { (yyval.reference) = cod_new_type_specifier(); - (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.type_specifier.token = STATIC; - ;} + } +#line 2751 "cod.tab.c" break; - case 93: -#line 969 "cod/cod.y" - { + case 93: /* storage_class_specifier: EXTERN_TOKEN */ +#line 983 "cod.y" + { (yyval.reference) = cod_new_type_specifier(); - (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.type_specifier.token = EXTERN_TOKEN; - ;} + } +#line 2761 "cod.tab.c" break; - case 94: -#line 978 "cod/cod.y" - { + case 94: /* type_specifier: CHAR */ +#line 992 "cod.y" + { (yyval.reference) = cod_new_type_specifier(); - (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.type_specifier.token = CHAR; - ;} + } +#line 2771 "cod.tab.c" break; - case 95: -#line 983 "cod/cod.y" - { + case 95: /* type_specifier: SHORT */ +#line 997 "cod.y" + { (yyval.reference) = cod_new_type_specifier(); - (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.type_specifier.token = SHORT; - ;} + } +#line 2781 "cod.tab.c" break; - case 96: -#line 988 "cod/cod.y" - { + case 96: /* type_specifier: INT */ +#line 1002 "cod.y" + { (yyval.reference) = cod_new_type_specifier(); - (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.type_specifier.token = INT; - ;} + } +#line 2791 "cod.tab.c" break; - case 97: -#line 993 "cod/cod.y" - { + case 97: /* type_specifier: LONG */ +#line 1007 "cod.y" + { (yyval.reference) = cod_new_type_specifier(); - (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.type_specifier.token = LONG; - ;} + } +#line 2801 "cod.tab.c" break; - case 98: -#line 998 "cod/cod.y" - { + case 98: /* type_specifier: FLOAT */ +#line 1012 "cod.y" + { (yyval.reference) = cod_new_type_specifier(); - (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.type_specifier.token = FLOAT; - ;} + } +#line 2811 "cod.tab.c" break; - case 99: -#line 1003 "cod/cod.y" - { + case 99: /* type_specifier: DOUBLE */ +#line 1017 "cod.y" + { (yyval.reference) = cod_new_type_specifier(); - (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.type_specifier.token = DOUBLE; - ;} + } +#line 2821 "cod.tab.c" break; - case 100: -#line 1008 "cod/cod.y" - { + case 100: /* type_specifier: VOID */ +#line 1022 "cod.y" + { (yyval.reference) = cod_new_type_specifier(); - (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.type_specifier.token = VOID; - ;} + } +#line 2831 "cod.tab.c" break; - case 101: -#line 1013 "cod/cod.y" - { + case 101: /* type_specifier: SIGNED */ +#line 1027 "cod.y" + { (yyval.reference) = cod_new_type_specifier(); - (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.type_specifier.token = SIGNED; - ;} + } +#line 2841 "cod.tab.c" break; - case 102: -#line 1018 "cod/cod.y" - { + case 102: /* type_specifier: UNSIGNED */ +#line 1032 "cod.y" + { (yyval.reference) = cod_new_type_specifier(); - (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.type_specifier.token = UNSIGNED; - ;} + } +#line 2851 "cod.tab.c" break; - case 103: -#line 1023 "cod/cod.y" - { + case 103: /* type_specifier: STRING */ +#line 1037 "cod.y" + { (yyval.reference) = cod_new_type_specifier(); - (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.type_specifier.token = STRING; - ;} + } +#line 2861 "cod.tab.c" break; - case 104: -#line 1028 "cod/cod.y" - { + case 104: /* type_specifier: type_id */ +#line 1042 "cod.y" + { (yyval.reference) = cod_new_identifier(); - (yyval.reference)->node.identifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; - (yyval.reference)->node.identifier.id = (yyvsp[(1) - (1)].info).string; - ;} + (yyval.reference)->node.identifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; + (yyval.reference)->node.identifier.id = (yyvsp[0].info).string; + } +#line 2871 "cod.tab.c" break; - case 105: -#line 1033 "cod/cod.y" - { - (yyval.reference) = (yyvsp[(1) - (1)].reference); - ;} + case 105: /* type_specifier: struct_or_union_specifier */ +#line 1047 "cod.y" + { + (yyval.reference) = (yyvsp[0].reference); + } +#line 2879 "cod.tab.c" break; - case 106: -#line 1036 "cod/cod.y" - { - (yyval.reference) = (yyvsp[(1) - (1)].reference); - ;} + case 106: /* type_specifier: enum_specifier */ +#line 1050 "cod.y" + { + (yyval.reference) = (yyvsp[0].reference); + } +#line 2887 "cod.tab.c" break; - case 107: -#line 1042 "cod/cod.y" - { - (yyval.reference) = cod_build_parsed_type_node(yycontext, (yyvsp[(2) - (5)].info).string, (yyvsp[(4) - (5)].list)); - ;} + case 107: /* struct_or_union_specifier: struct_or_union identifier_ref LCURLY struct_declaration_list RCURLY */ +#line 1056 "cod.y" + { + (yyval.reference) = cod_build_parsed_type_node(yycontext, (yyvsp[-3].info).string, (yyvsp[-1].list)); + } +#line 2895 "cod.tab.c" break; - case 108: -#line 1045 "cod/cod.y" - { - (yyval.reference) = cod_build_parsed_type_node(yycontext, strdup("anon"), (yyvsp[(3) - (4)].list)); - ;} + case 108: /* struct_or_union_specifier: struct_or_union LCURLY struct_declaration_list RCURLY */ +#line 1059 "cod.y" + { + (yyval.reference) = cod_build_parsed_type_node(yycontext, strdup("anon"), (yyvsp[-1].list)); + } +#line 2903 "cod.tab.c" break; - case 109: -#line 1048 "cod/cod.y" - { - (yyval.reference) = cod_build_parsed_type_node(yycontext, (yyvsp[(2) - (2)].info).string, NULL); - ;} + case 109: /* struct_or_union_specifier: struct_or_union identifier_ref */ +#line 1062 "cod.y" + { + (yyval.reference) = cod_build_parsed_type_node(yycontext, (yyvsp[0].info).string, NULL); + } +#line 2911 "cod.tab.c" break; - case 111: -#line 1055 "cod/cod.y" - { + case 111: /* struct_or_union: UNION */ +#line 1069 "cod.y" + { yyerror("UNIONs not supported!"); - ;} + } +#line 2919 "cod.tab.c" break; - case 113: -#line 1062 "cod/cod.y" - { - sm_list tmp = (yyvsp[(1) - (2)].list); + case 113: /* struct_declaration_list: struct_declaration_list struct_declaration */ +#line 1076 "cod.y" + { + sm_list tmp = (yyvsp[-1].list); while (tmp->next != NULL) { tmp = tmp->next; } - tmp->next =(yyvsp[(2) - (2)].list); - (yyval.list) = (yyvsp[(1) - (2)].list); - ;} + tmp->next =(yyvsp[0].list); + (yyval.list) = (yyvsp[-1].list); + } +#line 2932 "cod.tab.c" break; - case 114: -#line 1074 "cod/cod.y" - { ;} + case 114: /* struct_declaration: specifier_qualifier_list SEMI */ +#line 1088 "cod.y" + { } +#line 2938 "cod.tab.c" break; - case 115: -#line 1075 "cod/cod.y" - { - sm_list type_spec = (yyvsp[(1) - (3)].list); - sm_list decl_list = (yyvsp[(2) - (3)].list); - (yyval.list) = (yyvsp[(2) - (3)].list); + case 115: /* struct_declaration: specifier_qualifier_list struct_declarator_list SEMI */ +#line 1089 "cod.y" + { + sm_list type_spec = (yyvsp[-2].list); + sm_list decl_list = (yyvsp[-1].list); + (yyval.list) = (yyvsp[-1].list); /******** GSE This isn't right. Reusing potentially modified type spec */ while (decl_list != NULL) { sm_ref decl = decl_list->node; @@ -3073,7 +2954,7 @@ yyparse () * the pointer type list (with the declarator) * goes at the end */ - sm_list tmp = (yyvsp[(1) - (3)].list); + sm_list tmp = (yyvsp[-2].list); while (tmp->next != NULL) { tmp = tmp->next; } @@ -3104,402 +2985,436 @@ yyparse () type_spec = cod_dup_list(type_spec); } } - ;} + } +#line 2990 "cod.tab.c" break; - case 116: -#line 1126 "cod/cod.y" - { + case 116: /* struct_declarator_list: struct_declarator */ +#line 1140 "cod.y" + { (yyval.list) = malloc(sizeof(struct list_struct)); - (yyval.list)->node = (yyvsp[(1) - (1)].reference); + (yyval.list)->node = (yyvsp[0].reference); (yyval.list)->next = NULL; - ;} + } +#line 3000 "cod.tab.c" break; - case 117: -#line 1131 "cod/cod.y" - { - sm_list tmp = (yyvsp[(1) - (3)].list); + case 117: /* struct_declarator_list: struct_declarator_list COMMA struct_declarator */ +#line 1145 "cod.y" + { + sm_list tmp = (yyvsp[-2].list); while (tmp->next != NULL) { tmp = tmp->next; } tmp->next = malloc(sizeof(struct list_struct)); - tmp->next->node = (yyvsp[(3) - (3)].reference); + tmp->next->node = (yyvsp[0].reference); tmp->next->next = NULL; - (yyval.list) = (yyvsp[(1) - (3)].list); - ;} + (yyval.list) = (yyvsp[-2].list); + } +#line 3015 "cod.tab.c" break; - case 119: -#line 1146 "cod/cod.y" - { + case 119: /* specifier_qualifier_list: type_specifier specifier_qualifier_list */ +#line 1160 "cod.y" + { sm_list tmp = malloc(sizeof(struct list_struct)); - tmp->node = (yyvsp[(1) - (2)].reference); - tmp->next = (yyvsp[(2) - (2)].list); + tmp->node = (yyvsp[-1].reference); + tmp->next = (yyvsp[0].list); (yyval.list) = tmp; - ;} + } +#line 3026 "cod.tab.c" break; - case 120: -#line 1152 "cod/cod.y" - { + case 120: /* specifier_qualifier_list: type_specifier */ +#line 1166 "cod.y" + { (yyval.list) = malloc(sizeof(struct list_struct)); - (yyval.list)->node = (yyvsp[(1) - (1)].reference); + (yyval.list)->node = (yyvsp[0].reference); (yyval.list)->next = NULL; - ;} + } +#line 3036 "cod.tab.c" break; - case 121: -#line 1157 "cod/cod.y" - { + case 121: /* specifier_qualifier_list: type_qualifier specifier_qualifier_list */ +#line 1171 "cod.y" + { sm_list tmp = malloc(sizeof(struct list_struct)); - tmp->node = (yyvsp[(1) - (2)].reference); - tmp->next = (yyvsp[(2) - (2)].list); + tmp->node = (yyvsp[-1].reference); + tmp->next = (yyvsp[0].list); (yyval.list) = tmp; - ;} + } +#line 3047 "cod.tab.c" break; - case 122: -#line 1163 "cod/cod.y" - { + case 122: /* specifier_qualifier_list: type_qualifier */ +#line 1177 "cod.y" + { (yyval.list) = malloc(sizeof(struct list_struct)); - (yyval.list)->node = (yyvsp[(1) - (1)].reference); + (yyval.list)->node = (yyvsp[0].reference); (yyval.list)->next = NULL; - ;} + } +#line 3057 "cod.tab.c" break; - case 123: -#line 1171 "cod/cod.y" - { + case 123: /* enum_specifier: ENUM LCURLY enumerator_list RCURLY */ +#line 1185 "cod.y" + { (yyval.reference) = cod_new_enum_type_decl(); (yyval.reference)->node.enum_type_decl.id = gen_anon(); - (yyval.reference)->node.enum_type_decl.enums = (yyvsp[(3) - (4)].list); - (yyval.reference)->node.enum_type_decl.lx_srcpos = (yyvsp[(1) - (4)].info).lx_srcpos; + (yyval.reference)->node.enum_type_decl.enums = (yyvsp[-1].list); + (yyval.reference)->node.enum_type_decl.lx_srcpos = (yyvsp[-3].info).lx_srcpos; // cod_add_defined_type(decl->node.declaration.id, yycontext); - ;} + } +#line 3069 "cod.tab.c" break; - case 124: -#line 1178 "cod/cod.y" - { + case 124: /* enum_specifier: ENUM LCURLY enumerator_list COMMA RCURLY */ +#line 1192 "cod.y" + { (yyval.reference) = cod_new_enum_type_decl(); (yyval.reference)->node.enum_type_decl.id = gen_anon(); - (yyval.reference)->node.enum_type_decl.enums = (yyvsp[(3) - (5)].list); - (yyval.reference)->node.enum_type_decl.lx_srcpos = (yyvsp[(1) - (5)].info).lx_srcpos; + (yyval.reference)->node.enum_type_decl.enums = (yyvsp[-2].list); + (yyval.reference)->node.enum_type_decl.lx_srcpos = (yyvsp[-4].info).lx_srcpos; // cod_add_defined_type(decl->node.declaration.id, yycontext); - ;} + } +#line 3081 "cod.tab.c" break; - case 125: -#line 1185 "cod/cod.y" - { + case 125: /* enum_specifier: ENUM identifier_ref LCURLY enumerator_list RCURLY */ +#line 1199 "cod.y" + { (yyval.reference) = cod_new_enum_type_decl(); - (yyval.reference)->node.enum_type_decl.id = (yyvsp[(2) - (5)].info).string; - (yyval.reference)->node.enum_type_decl.enums = (yyvsp[(4) - (5)].list); - (yyval.reference)->node.enum_type_decl.lx_srcpos = (yyvsp[(1) - (5)].info).lx_srcpos; + (yyval.reference)->node.enum_type_decl.id = (yyvsp[-3].info).string; + (yyval.reference)->node.enum_type_decl.enums = (yyvsp[-1].list); + (yyval.reference)->node.enum_type_decl.lx_srcpos = (yyvsp[-4].info).lx_srcpos; // cod_add_defined_type(decl->node.declaration.id, yycontext); - ;} + } +#line 3093 "cod.tab.c" break; - case 126: -#line 1192 "cod/cod.y" - { + case 126: /* enum_specifier: ENUM identifier_ref LCURLY enumerator_list COMMA RCURLY */ +#line 1206 "cod.y" + { (yyval.reference) = cod_new_enum_type_decl(); - (yyval.reference)->node.enum_type_decl.id = (yyvsp[(2) - (6)].info).string; - (yyval.reference)->node.enum_type_decl.enums = (yyvsp[(4) - (6)].list); - (yyval.reference)->node.enum_type_decl.lx_srcpos = (yyvsp[(1) - (6)].info).lx_srcpos; + (yyval.reference)->node.enum_type_decl.id = (yyvsp[-4].info).string; + (yyval.reference)->node.enum_type_decl.enums = (yyvsp[-2].list); + (yyval.reference)->node.enum_type_decl.lx_srcpos = (yyvsp[-5].info).lx_srcpos; // cod_add_defined_type(decl->node.declaration.id, yycontext); - ;} + } +#line 3105 "cod.tab.c" break; - case 127: -#line 1199 "cod/cod.y" - { + case 127: /* enum_specifier: ENUM identifier_ref */ +#line 1213 "cod.y" + { (yyval.reference) = cod_new_enum_type_decl(); - (yyval.reference)->node.enum_type_decl.id = (yyvsp[(2) - (2)].info).string; + (yyval.reference)->node.enum_type_decl.id = (yyvsp[0].info).string; (yyval.reference)->node.enum_type_decl.enums = NULL; - (yyval.reference)->node.enum_type_decl.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; + (yyval.reference)->node.enum_type_decl.lx_srcpos = (yyvsp[-1].info).lx_srcpos; // cod_add_defined_type(decl->node.declaration.id, yycontext); - ;} + } +#line 3117 "cod.tab.c" break; - case 128: -#line 1209 "cod/cod.y" - { + case 128: /* enumerator_list: enumerator */ +#line 1223 "cod.y" + { sm_list tmp = malloc(sizeof(struct list_struct)); - tmp->node = (yyvsp[(1) - (1)].reference); + tmp->node = (yyvsp[0].reference); tmp->next = NULL; (yyval.list) = tmp; - ;} + } +#line 3128 "cod.tab.c" break; - case 129: -#line 1215 "cod/cod.y" - { + case 129: /* enumerator_list: enumerator_list COMMA enumerator */ +#line 1229 "cod.y" + { sm_list tmp = malloc(sizeof(struct list_struct)); - tmp->node = (yyvsp[(3) - (3)].reference); - tmp->next = (yyvsp[(1) - (3)].list); + tmp->node = (yyvsp[0].reference); + tmp->next = (yyvsp[-2].list); (yyval.list) = tmp; - ;} + } +#line 3139 "cod.tab.c" break; - case 130: -#line 1225 "cod/cod.y" - { + case 130: /* enumerator: identifier_ref ASSIGN constant_expression */ +#line 1239 "cod.y" + { (yyval.reference) = cod_new_enumerator(); - (yyval.reference)->node.enumerator.id = (yyvsp[(1) - (3)].info).string; - (yyval.reference)->node.enumerator.const_expression = (yyvsp[(3) - (3)].reference); - ;} + (yyval.reference)->node.enumerator.id = (yyvsp[-2].info).string; + (yyval.reference)->node.enumerator.const_expression = (yyvsp[0].reference); + } +#line 3149 "cod.tab.c" break; - case 131: -#line 1231 "cod/cod.y" - { + case 131: /* enumerator: identifier_ref */ +#line 1245 "cod.y" + { (yyval.reference) = cod_new_enumerator(); - (yyval.reference)->node.enumerator.id = (yyvsp[(1) - (1)].info).string; + (yyval.reference)->node.enumerator.id = (yyvsp[0].info).string; (yyval.reference)->node.enumerator.const_expression = NULL; - ;} + } +#line 3159 "cod.tab.c" break; - case 132: -#line 1239 "cod/cod.y" - { + case 132: /* type_qualifier: CONST */ +#line 1253 "cod.y" + { (yyval.reference) = cod_new_type_specifier(); - (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + (yyval.reference)->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.type_specifier.token = CONST; - ;} + } +#line 3169 "cod.tab.c" break; - case 134: -#line 1249 "cod/cod.y" - { - (yyval.reference) = (yyvsp[(2) - (2)].reference); + case 134: /* declarator: pointer direct_declarator */ +#line 1263 "cod.y" + { + (yyval.reference) = (yyvsp[0].reference); if ((yyval.reference)->node_type == cod_declaration) { - (yyval.reference)->node.declaration.type_spec = (yyvsp[(1) - (2)].list); + (yyval.reference)->node.declaration.type_spec = (yyvsp[-1].list); } else if ((yyval.reference)->node_type == cod_array_type_decl) { - (yyval.reference)->node.array_type_decl.type_spec = (yyvsp[(1) - (2)].list); + (yyval.reference)->node.array_type_decl.type_spec = (yyvsp[-1].list); } else { printf("Unknown direct_declarator entry\n"); cod_print((yyval.reference)); } - ;} + } +#line 3185 "cod.tab.c" break; - case 135: -#line 1263 "cod/cod.y" - { + case 135: /* direct_declarator: identifier_ref */ +#line 1277 "cod.y" + { (yyval.reference) = cod_new_declaration(); (yyval.reference)->node.declaration.param_num = -1; - (yyval.reference)->node.declaration.id = (yyvsp[(1) - (1)].info).string; + (yyval.reference)->node.declaration.id = (yyvsp[0].info).string; (yyval.reference)->node.declaration.init_value = NULL; - (yyval.reference)->node.declaration.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + (yyval.reference)->node.declaration.lx_srcpos = (yyvsp[0].info).lx_srcpos; (yyval.reference)->node.declaration.is_subroutine = 0; (yyval.reference)->node.declaration.params = NULL; - ;} + } +#line 3199 "cod.tab.c" break; - case 136: -#line 1272 "cod/cod.y" - { - (yyval.reference) = (yyvsp[(2) - (3)].reference); - ;} + case 136: /* direct_declarator: LPAREN declarator RPAREN */ +#line 1286 "cod.y" + { + (yyval.reference) = (yyvsp[-1].reference); + } +#line 3207 "cod.tab.c" break; - case 137: -#line 1275 "cod/cod.y" - { + case 137: /* direct_declarator: identifier_ref LPAREN parameter_type_list RPAREN */ +#line 1289 "cod.y" + { (yyval.reference) = cod_new_declaration(); (yyval.reference)->node.declaration.param_num = -1; - (yyval.reference)->node.declaration.id = (yyvsp[(1) - (4)].info).string; + (yyval.reference)->node.declaration.id = (yyvsp[-3].info).string; (yyval.reference)->node.declaration.init_value = NULL; - (yyval.reference)->node.declaration.lx_srcpos = (yyvsp[(1) - (4)].info).lx_srcpos; + (yyval.reference)->node.declaration.lx_srcpos = (yyvsp[-3].info).lx_srcpos; (yyval.reference)->node.declaration.is_subroutine = 1; - (yyval.reference)->node.declaration.params = (yyvsp[(3) - (4)].list); - ;} + (yyval.reference)->node.declaration.params = (yyvsp[-1].list); + } +#line 3221 "cod.tab.c" break; - case 138: -#line 1284 "cod/cod.y" - { + case 138: /* direct_declarator: identifier_ref LPAREN RPAREN */ +#line 1298 "cod.y" + { (yyval.reference) = cod_new_declaration(); (yyval.reference)->node.declaration.param_num = -1; - (yyval.reference)->node.declaration.id = (yyvsp[(1) - (3)].info).string; + (yyval.reference)->node.declaration.id = (yyvsp[-2].info).string; (yyval.reference)->node.declaration.init_value = NULL; - (yyval.reference)->node.declaration.lx_srcpos = (yyvsp[(1) - (3)].info).lx_srcpos; + (yyval.reference)->node.declaration.lx_srcpos = (yyvsp[-2].info).lx_srcpos; (yyval.reference)->node.declaration.is_subroutine = 1; (yyval.reference)->node.declaration.params = NULL; - ;} + } +#line 3235 "cod.tab.c" break; - case 139: -#line 1293 "cod/cod.y" - { + case 139: /* direct_declarator: direct_declarator LBRACKET constant_expression RBRACKET */ +#line 1307 "cod.y" + { (yyval.reference) = cod_new_array_type_decl(); - (yyval.reference)->node.array_type_decl.lx_srcpos = (yyvsp[(2) - (4)].info).lx_srcpos; - (yyval.reference)->node.array_type_decl.size_expr = (yyvsp[(3) - (4)].reference); - (yyval.reference)->node.array_type_decl.element_ref = (yyvsp[(1) - (4)].reference); + (yyval.reference)->node.array_type_decl.lx_srcpos = (yyvsp[-2].info).lx_srcpos; + (yyval.reference)->node.array_type_decl.size_expr = (yyvsp[-1].reference); + (yyval.reference)->node.array_type_decl.element_ref = (yyvsp[-3].reference); (yyval.reference)->node.array_type_decl.sm_dynamic_size = NULL; - ;} + } +#line 3247 "cod.tab.c" break; - case 140: -#line 1300 "cod/cod.y" - { + case 140: /* direct_declarator: direct_declarator LBRACKET RBRACKET */ +#line 1314 "cod.y" + { (yyval.reference) = cod_new_array_type_decl(); - (yyval.reference)->node.array_type_decl.lx_srcpos = (yyvsp[(2) - (3)].info).lx_srcpos; + (yyval.reference)->node.array_type_decl.lx_srcpos = (yyvsp[-1].info).lx_srcpos; (yyval.reference)->node.array_type_decl.size_expr = NULL; - (yyval.reference)->node.array_type_decl.element_ref = (yyvsp[(1) - (3)].reference); + (yyval.reference)->node.array_type_decl.element_ref = (yyvsp[-2].reference); (yyval.reference)->node.array_type_decl.sm_dynamic_size = NULL; - ;} + } +#line 3259 "cod.tab.c" break; - case 141: -#line 1310 "cod/cod.y" - { + case 141: /* pointer: STAR */ +#line 1324 "cod.y" + { sm_ref star = cod_new_type_specifier(); - star->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + star->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; star->node.type_specifier.token = STAR; (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = star; (yyval.list)->next = NULL; - ;} + } +#line 3272 "cod.tab.c" break; - case 142: -#line 1318 "cod/cod.y" - { + case 142: /* pointer: STAR type_qualifier_list */ +#line 1332 "cod.y" + { sm_ref star = cod_new_type_specifier(); - star->node.type_specifier.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; + star->node.type_specifier.lx_srcpos = (yyvsp[-1].info).lx_srcpos; star->node.type_specifier.token = STAR; (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = star; - (yyval.list)->next = (yyvsp[(2) - (2)].list); - ;} + (yyval.list)->next = (yyvsp[0].list); + } +#line 3285 "cod.tab.c" break; - case 143: -#line 1326 "cod/cod.y" - { + case 143: /* pointer: STAR pointer */ +#line 1340 "cod.y" + { sm_ref star = cod_new_type_specifier(); - star->node.type_specifier.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; + star->node.type_specifier.lx_srcpos = (yyvsp[-1].info).lx_srcpos; star->node.type_specifier.token = STAR; (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = star; - (yyval.list)->next = (yyvsp[(2) - (2)].list); - ;} + (yyval.list)->next = (yyvsp[0].list); + } +#line 3298 "cod.tab.c" break; - case 144: -#line 1334 "cod/cod.y" - { - sm_list tmp = (yyvsp[(2) - (3)].list); + case 144: /* pointer: STAR type_qualifier_list pointer */ +#line 1348 "cod.y" + { + sm_list tmp = (yyvsp[-1].list); sm_ref star = cod_new_type_specifier(); - star->node.type_specifier.lx_srcpos = (yyvsp[(1) - (3)].info).lx_srcpos; + star->node.type_specifier.lx_srcpos = (yyvsp[-2].info).lx_srcpos; star->node.type_specifier.token = STAR; while (tmp->next != NULL) { tmp = tmp->next; } - tmp->next = (yyvsp[(3) - (3)].list); + tmp->next = (yyvsp[0].list); (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = star; - (yyval.list)->next = (yyvsp[(2) - (3)].list); - ;} + (yyval.list)->next = (yyvsp[-1].list); + } +#line 3317 "cod.tab.c" break; - case 145: -#line 1348 "cod/cod.y" - { + case 145: /* pointer: AT */ +#line 1362 "cod.y" + { sm_ref star = cod_new_type_specifier(); if(!cod_segmented_pointers) { yyerror("Segmented pointers disabled!"); } - star->node.type_specifier.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; + star->node.type_specifier.lx_srcpos = (yyvsp[0].info).lx_srcpos; star->node.type_specifier.token = AT; (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = star; (yyval.list)->next = NULL; - ;} + } +#line 3333 "cod.tab.c" break; - case 146: -#line 1359 "cod/cod.y" - { + case 146: /* pointer: AT type_qualifier_list */ +#line 1373 "cod.y" + { sm_ref star = cod_new_type_specifier(); if(!cod_segmented_pointers) { yyerror("Segmented pointers disabled!"); } - star->node.type_specifier.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; + star->node.type_specifier.lx_srcpos = (yyvsp[-1].info).lx_srcpos; star->node.type_specifier.token = AT; (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = star; - (yyval.list)->next = (yyvsp[(2) - (2)].list); - ;} + (yyval.list)->next = (yyvsp[0].list); + } +#line 3349 "cod.tab.c" break; - case 147: -#line 1370 "cod/cod.y" - { + case 147: /* pointer: AT pointer */ +#line 1384 "cod.y" + { sm_ref star = cod_new_type_specifier(); if(!cod_segmented_pointers) { yyerror("Segmented pointers disabled!"); } - star->node.type_specifier.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; + star->node.type_specifier.lx_srcpos = (yyvsp[-1].info).lx_srcpos; star->node.type_specifier.token = AT; (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = star; - (yyval.list)->next = (yyvsp[(2) - (2)].list); - ;} + (yyval.list)->next = (yyvsp[0].list); + } +#line 3365 "cod.tab.c" break; - case 148: -#line 1381 "cod/cod.y" - { - sm_list tmp = (yyvsp[(2) - (3)].list); + case 148: /* pointer: AT type_qualifier_list pointer */ +#line 1395 "cod.y" + { + sm_list tmp = (yyvsp[-1].list); sm_ref star = cod_new_type_specifier(); if(!cod_segmented_pointers) { yyerror("Segmented pointers disabled!"); } - star->node.type_specifier.lx_srcpos = (yyvsp[(1) - (3)].info).lx_srcpos; + star->node.type_specifier.lx_srcpos = (yyvsp[-2].info).lx_srcpos; star->node.type_specifier.token = AT; while (tmp->next != NULL) { tmp = tmp->next; } - tmp->next = (yyvsp[(3) - (3)].list); + tmp->next = (yyvsp[0].list); (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = star; - (yyval.list)->next = (yyvsp[(2) - (3)].list); - ;} + (yyval.list)->next = (yyvsp[-1].list); + } +#line 3387 "cod.tab.c" break; - case 149: -#line 1401 "cod/cod.y" - { + case 149: /* type_qualifier_list: type_qualifier */ +#line 1415 "cod.y" + { (yyval.list) = malloc(sizeof(struct list_struct)); - (yyval.list)->node = (yyvsp[(1) - (1)].reference); + (yyval.list)->node = (yyvsp[0].reference); (yyval.list)->next = NULL; - ;} + } +#line 3397 "cod.tab.c" break; - case 150: -#line 1406 "cod/cod.y" - { - sm_list tmp = (yyvsp[(1) - (2)].list); + case 150: /* type_qualifier_list: type_qualifier_list type_qualifier */ +#line 1420 "cod.y" + { + sm_list tmp = (yyvsp[-1].list); while (tmp->next != NULL) { tmp = tmp->next; } tmp->next = malloc(sizeof(struct list_struct)); - tmp->next->node = (yyvsp[(2) - (2)].reference); + tmp->next->node = (yyvsp[0].reference); tmp->next->next = NULL; - (yyval.list) = (yyvsp[(1) - (2)].list); - ;} + (yyval.list) = (yyvsp[-1].list); + } +#line 3412 "cod.tab.c" break; - case 152: -#line 1420 "cod/cod.y" - { - sm_list tmp = (yyvsp[(1) - (3)].list); + case 152: /* parameter_type_list: parameter_list COMMA DOTDOTDOT */ +#line 1434 "cod.y" + { + sm_list tmp = (yyvsp[-2].list); sm_ref id = cod_new_declaration(); while (tmp->next != NULL) { tmp = tmp->next; @@ -3508,585 +3423,606 @@ yyparse () tmp->next->node = id; tmp->next->next = NULL; id->node.declaration.id = strdup("..."); - (yyval.list) = (yyvsp[(1) - (3)].list); - ;} + (yyval.list) = (yyvsp[-2].list); + } +#line 3429 "cod.tab.c" break; - case 153: -#line 1435 "cod/cod.y" - { + case 153: /* parameter_list: parameter_declaration */ +#line 1449 "cod.y" + { (yyval.list) = malloc(sizeof(struct list_struct)); - (yyval.list)->node = (yyvsp[(1) - (1)].reference); + (yyval.list)->node = (yyvsp[0].reference); (yyval.list)->next = NULL; - ;} + } +#line 3439 "cod.tab.c" break; - case 154: -#line 1441 "cod/cod.y" - { - sm_list tmp = (yyvsp[(1) - (3)].list); + case 154: /* parameter_list: parameter_list COMMA parameter_declaration */ +#line 1455 "cod.y" + { + sm_list tmp = (yyvsp[-2].list); while (tmp->next != NULL) { tmp = tmp->next; } tmp->next = malloc(sizeof(struct list_struct)); - tmp->next->node = (yyvsp[(3) - (3)].reference); + tmp->next->node = (yyvsp[0].reference); tmp->next->next = NULL; - (yyval.list) = (yyvsp[(1) - (3)].list); - ;} + (yyval.list) = (yyvsp[-2].list); + } +#line 3454 "cod.tab.c" break; - case 155: -#line 1456 "cod/cod.y" - { + case 155: /* parameter_declaration: declaration_specifiers */ +#line 1470 "cod.y" + { (yyval.reference) = cod_new_declaration(); (yyval.reference)->node.declaration.param_num = -1; (yyval.reference)->node.declaration.id = gen_anon(); (yyval.reference)->node.declaration.init_value = NULL; (yyval.reference)->node.declaration.is_subroutine = 0; (yyval.reference)->node.declaration.params = NULL; - (yyval.reference)->node.declaration.type_spec = (yyvsp[(1) - (1)].list); - ;} + (yyval.reference)->node.declaration.type_spec = (yyvsp[0].list); + } +#line 3468 "cod.tab.c" break; - case 156: -#line 1465 "cod/cod.y" - { - (yyval.reference) = (yyvsp[(2) - (2)].reference); + case 156: /* parameter_declaration: declaration_specifiers declarator */ +#line 1479 "cod.y" + { + (yyval.reference) = (yyvsp[0].reference); if ((yyval.reference)->node_type == cod_declaration) { (yyval.reference)->node.declaration.static_var = 0; if ((yyval.reference)->node.declaration.type_spec == NULL) { - (yyval.reference)->node.declaration.type_spec = (yyvsp[(1) - (2)].list); + (yyval.reference)->node.declaration.type_spec = (yyvsp[-1].list); } else { /* * the pointer type list (with the declarator) * goes at the end */ - sm_list tmp = (yyvsp[(1) - (2)].list); + sm_list tmp = (yyvsp[-1].list); while (tmp->next != NULL) { tmp = tmp->next; } tmp->next = (yyval.reference)->node.declaration.type_spec; - (yyval.reference)->node.declaration.type_spec = (yyvsp[(1) - (2)].list); + (yyval.reference)->node.declaration.type_spec = (yyvsp[-1].list); } } else if ((yyval.reference)->node_type == cod_array_type_decl) { if ((yyval.reference)->node.array_type_decl.type_spec == NULL) { - (yyval.reference)->node.array_type_decl.type_spec = (yyvsp[(1) - (2)].list); + (yyval.reference)->node.array_type_decl.type_spec = (yyvsp[-1].list); } else { /* * the pointer type list (with the declarator) * goes at the end */ - sm_list tmp = (yyvsp[(1) - (2)].list); + sm_list tmp = (yyvsp[-1].list); while (tmp->next != NULL) { tmp = tmp->next; } tmp->next = (yyval.reference)->node.array_type_decl.type_spec; - (yyval.reference)->node.array_type_decl.type_spec = (yyvsp[(1) - (2)].list); + (yyval.reference)->node.array_type_decl.type_spec = (yyvsp[-1].list); } } else { printf("unexpected node in parameter_declaration"); } - ;} + } +#line 3510 "cod.tab.c" break; - case 158: -#line 1505 "cod/cod.y" - { - sm_list tmp = (yyvsp[(1) - (2)].list); + case 158: /* type_name: specifier_qualifier_list abstract_declarator */ +#line 1519 "cod.y" + { + sm_list tmp = (yyvsp[-1].list); while (tmp->next != NULL) { tmp = tmp->next; } - tmp->next = (yyvsp[(2) - (2)].list); - (yyval.list) = (yyvsp[(1) - (2)].list); - ;} + tmp->next = (yyvsp[0].list); + (yyval.list) = (yyvsp[-1].list); + } +#line 3523 "cod.tab.c" break; - case 160: -#line 1556 "cod/cod.y" - { + case 160: /* initializer: LCURLY initializer_list RCURLY */ +#line 1570 "cod.y" + { (yyval.reference) = cod_new_initializer_list(); - (yyval.reference)->node.initializer_list.initializers = (yyvsp[(2) - (3)].list); - ;} + (yyval.reference)->node.initializer_list.initializers = (yyvsp[-1].list); + } +#line 3532 "cod.tab.c" break; - case 161: -#line 1561 "cod/cod.y" - { + case 161: /* initializer: LCURLY initializer_list COMMA RCURLY */ +#line 1575 "cod.y" + { (yyval.reference) = cod_new_initializer_list(); - (yyval.reference)->node.initializer_list.initializers = (yyvsp[(2) - (4)].list); - ;} + (yyval.reference)->node.initializer_list.initializers = (yyvsp[-2].list); + } +#line 3541 "cod.tab.c" break; - case 162: -#line 1565 "cod/cod.y" - { (yyval.reference) = (yyvsp[(1) - (1)].reference);;} + case 162: /* initializer: assignment_expression */ +#line 1579 "cod.y" + { (yyval.reference) = (yyvsp[0].reference);} +#line 3547 "cod.tab.c" break; - case 163: -#line 1570 "cod/cod.y" - { + case 163: /* initializer_list: designation initializer */ +#line 1584 "cod.y" + { sm_ref initializer = cod_new_initializer(); - initializer->node.initializer.designation = (yyvsp[(1) - (2)].list); - initializer->node.initializer.initializer = (yyvsp[(2) - (2)].reference); + initializer->node.initializer.designation = (yyvsp[-1].list); + initializer->node.initializer.initializer = (yyvsp[0].reference); (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = initializer; (yyval.list)->next = NULL; - ;} + } +#line 3560 "cod.tab.c" break; - case 164: -#line 1578 "cod/cod.y" - { + case 164: /* initializer_list: initializer */ +#line 1592 "cod.y" + { sm_ref initializer = cod_new_initializer(); initializer->node.initializer.designation = NULL; - initializer->node.initializer.initializer = (yyvsp[(1) - (1)].reference); + initializer->node.initializer.initializer = (yyvsp[0].reference); (yyval.list) = malloc(sizeof(struct list_struct)); (yyval.list)->node = initializer; (yyval.list)->next = NULL; - ;} + } +#line 3573 "cod.tab.c" break; - case 165: -#line 1586 "cod/cod.y" - { - sm_list tmp = (yyvsp[(1) - (4)].list); + case 165: /* initializer_list: initializer_list COMMA designation initializer */ +#line 1600 "cod.y" + { + sm_list tmp = (yyvsp[-3].list); sm_ref initializer = cod_new_initializer(); - initializer->node.initializer.designation = (yyvsp[(3) - (4)].list); - initializer->node.initializer.initializer = (yyvsp[(4) - (4)].reference); + initializer->node.initializer.designation = (yyvsp[-1].list); + initializer->node.initializer.initializer = (yyvsp[0].reference); while (tmp->next != NULL) { tmp = tmp->next; } tmp->next = malloc(sizeof(struct list_struct)); tmp->next->node = initializer; tmp->next->next = NULL; - (yyval.list) = (yyvsp[(1) - (4)].list); - ;} + (yyval.list) = (yyvsp[-3].list); + } +#line 3591 "cod.tab.c" break; - case 166: -#line 1599 "cod/cod.y" - { - sm_list tmp = (yyvsp[(1) - (3)].list); + case 166: /* initializer_list: initializer_list COMMA initializer */ +#line 1613 "cod.y" + { + sm_list tmp = (yyvsp[-2].list); sm_ref initializer = cod_new_initializer(); initializer->node.initializer.designation = NULL; - initializer->node.initializer.initializer = (yyvsp[(3) - (3)].reference); + initializer->node.initializer.initializer = (yyvsp[0].reference); while (tmp->next != NULL) { tmp = tmp->next; } tmp->next = malloc(sizeof(struct list_struct)); tmp->next->node = initializer; tmp->next->next = NULL; - (yyval.list) = (yyvsp[(1) - (3)].list); - ;} + (yyval.list) = (yyvsp[-2].list); + } +#line 3609 "cod.tab.c" break; - case 167: -#line 1616 "cod/cod.y" - { (yyval.list) = (yyvsp[(1) - (2)].list);;} + case 167: /* designation: designator_list ASSIGN */ +#line 1630 "cod.y" + { (yyval.list) = (yyvsp[-1].list);} +#line 3615 "cod.tab.c" break; - case 168: -#line 1620 "cod/cod.y" - { + case 168: /* designator_list: designator */ +#line 1634 "cod.y" + { (yyval.list) = malloc(sizeof(struct list_struct)); - (yyval.list)->node = (yyvsp[(1) - (1)].reference); + (yyval.list)->node = (yyvsp[0].reference); (yyval.list)->next = NULL; - ;} + } +#line 3625 "cod.tab.c" break; - case 169: -#line 1625 "cod/cod.y" - { - sm_list tmp = (yyvsp[(1) - (2)].list); + case 169: /* designator_list: designator_list designator */ +#line 1639 "cod.y" + { + sm_list tmp = (yyvsp[-1].list); while (tmp->next != NULL) { tmp = tmp->next; } tmp->next = malloc(sizeof(struct list_struct)); - tmp->next->node = (yyvsp[(2) - (2)].reference); + tmp->next->node = (yyvsp[0].reference); tmp->next->next = NULL; - (yyval.list) = (yyvsp[(1) - (2)].list); - ;} + (yyval.list) = (yyvsp[-1].list); + } +#line 3640 "cod.tab.c" break; - case 170: -#line 1639 "cod/cod.y" - { + case 170: /* designator: LBRACKET constant_expression RBRACKET */ +#line 1653 "cod.y" + { (yyval.reference) = cod_new_designator(); - (yyval.reference)->node.designator.expression = (yyvsp[(2) - (3)].reference); + (yyval.reference)->node.designator.expression = (yyvsp[-1].reference); (yyval.reference)->node.designator.id = NULL; - ;} + } +#line 3650 "cod.tab.c" break; - case 171: -#line 1645 "cod/cod.y" - { + case 171: /* designator: DOT identifier_ref */ +#line 1659 "cod.y" + { (yyval.reference) = cod_new_designator(); (yyval.reference)->node.designator.expression = NULL; - (yyval.reference)->node.designator.id = (yyvsp[(2) - (2)].info).string; - ;} + (yyval.reference)->node.designator.id = (yyvsp[0].info).string; + } +#line 3660 "cod.tab.c" break; - case 172: -#line 1653 "cod/cod.y" - { + case 172: /* decls_stmts_list: statement */ +#line 1667 "cod.y" + { sm_list tmp = malloc(sizeof(struct list_struct)); - tmp->node = (yyvsp[(1) - (1)].reference); + tmp->node = (yyvsp[0].reference); tmp->next = NULL; (yyval.list) = tmp; - ;} + } +#line 3671 "cod.tab.c" break; - case 173: -#line 1659 "cod/cod.y" - { - (yyval.list) = (yyvsp[(1) - (1)].list); - ;} + case 173: /* decls_stmts_list: declaration */ +#line 1673 "cod.y" + { + (yyval.list) = (yyvsp[0].list); + } +#line 3679 "cod.tab.c" break; - case 174: -#line 1662 "cod/cod.y" - { + case 174: /* decls_stmts_list: error SEMI */ +#line 1676 "cod.y" + { (yyval.list) = NULL; - ;} + } +#line 3687 "cod.tab.c" break; - case 175: -#line 1665 "cod/cod.y" - { + case 175: /* decls_stmts_list: decls_stmts_list statement */ +#line 1679 "cod.y" + { sm_list tmp = malloc(sizeof(struct list_struct)); - tmp->node = (yyvsp[(2) - (2)].reference); + tmp->node = (yyvsp[0].reference); tmp->next = NULL; - (yyval.list) = cod_append_list((yyvsp[(1) - (2)].list), tmp); - ;} + (yyval.list) = cod_append_list((yyvsp[-1].list), tmp); + } +#line 3698 "cod.tab.c" break; - case 176: -#line 1671 "cod/cod.y" - { - (yyval.list) = cod_append_list((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].list)); - ;} + case 176: /* decls_stmts_list: decls_stmts_list declaration */ +#line 1685 "cod.y" + { + (yyval.list) = cod_append_list((yyvsp[-1].list), (yyvsp[0].list)); + } +#line 3706 "cod.tab.c" break; - case 183: -#line 1688 "cod/cod.y" - { + case 183: /* labeled_statement: identifier_ref COLON statement */ +#line 1702 "cod.y" + { (yyval.reference) = cod_new_label_statement(); - (yyval.reference)->node.label_statement.name = (yyvsp[(1) - (3)].info).string; - (yyval.reference)->node.label_statement.statement = (yyvsp[(3) - (3)].reference); - ;} + (yyval.reference)->node.label_statement.name = (yyvsp[-2].info).string; + (yyval.reference)->node.label_statement.statement = (yyvsp[0].reference); + } +#line 3716 "cod.tab.c" break; - case 184: -#line 1695 "cod/cod.y" - { + case 184: /* compound_statement: LCURLY RCURLY */ +#line 1709 "cod.y" + { (yyval.reference) = cod_new_compound_statement(); - ;} + } +#line 3724 "cod.tab.c" break; - case 185: -#line 1698 "cod/cod.y" - { - int count = (yyvsp[(1) - (3)].info).type_stack_count; + case 185: /* compound_statement: LCURLY decls_stmts_list RCURLY */ +#line 1712 "cod.y" + { + int count = (yyvsp[-2].info).type_stack_count; (yyval.reference) = cod_new_compound_statement(); - (yyval.reference)->node.compound_statement.decls = (yyvsp[(2) - (3)].list); + (yyval.reference)->node.compound_statement.decls = (yyvsp[-1].list); cod_remove_defined_types(yycontext, count); - ;} + } +#line 3735 "cod.tab.c" break; - case 186: -#line 1706 "cod/cod.y" - { (yyval.list) = (yyvsp[(1) - (1)].list); ;} + case 186: /* declaration_list: declaration */ +#line 1720 "cod.y" + { (yyval.list) = (yyvsp[0].list); } +#line 3741 "cod.tab.c" break; - case 187: -#line 1708 "cod/cod.y" - { - if ((yyvsp[(1) - (2)].list) == NULL) { - (yyval.list) = (yyvsp[(2) - (2)].list); + case 187: /* declaration_list: declaration_list declaration */ +#line 1722 "cod.y" + { + if ((yyvsp[-1].list) == NULL) { + (yyval.list) = (yyvsp[0].list); } else { - sm_list tmp = (yyvsp[(1) - (2)].list); + sm_list tmp = (yyvsp[-1].list); while (tmp->next != NULL) { tmp = tmp->next; } - tmp->next = (yyvsp[(2) - (2)].list); - (yyval.list) = (yyvsp[(1) - (2)].list); + tmp->next = (yyvsp[0].list); + (yyval.list) = (yyvsp[-1].list); } - ;} + } +#line 3758 "cod.tab.c" break; - case 188: -#line 1722 "cod/cod.y" - { + case 188: /* jump_statement: RETURN_TOKEN expression SEMI */ +#line 1736 "cod.y" + { (yyval.reference) = cod_new_return_statement(); - (yyval.reference)->node.return_statement.expression = (yyvsp[(2) - (3)].reference); - (yyval.reference)->node.return_statement.lx_srcpos = (yyvsp[(1) - (3)].info).lx_srcpos; - ;} + (yyval.reference)->node.return_statement.expression = (yyvsp[-1].reference); + (yyval.reference)->node.return_statement.lx_srcpos = (yyvsp[-2].info).lx_srcpos; + } +#line 3768 "cod.tab.c" break; - case 189: -#line 1727 "cod/cod.y" - { + case 189: /* jump_statement: RETURN_TOKEN SEMI */ +#line 1741 "cod.y" + { (yyval.reference) = cod_new_return_statement(); (yyval.reference)->node.return_statement.expression = NULL; - (yyval.reference)->node.return_statement.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; - ;} + (yyval.reference)->node.return_statement.lx_srcpos = (yyvsp[-1].info).lx_srcpos; + } +#line 3778 "cod.tab.c" break; - case 190: -#line 1732 "cod/cod.y" - { + case 190: /* jump_statement: CONTINUE SEMI */ +#line 1746 "cod.y" + { (yyval.reference) = cod_new_jump_statement(); (yyval.reference)->node.jump_statement.continue_flag = 1; (yyval.reference)->node.jump_statement.goto_target = NULL; - (yyval.reference)->node.jump_statement.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; - ;} + (yyval.reference)->node.jump_statement.lx_srcpos = (yyvsp[-1].info).lx_srcpos; + } +#line 3789 "cod.tab.c" break; - case 191: -#line 1738 "cod/cod.y" - { + case 191: /* jump_statement: BREAK SEMI */ +#line 1752 "cod.y" + { (yyval.reference) = cod_new_jump_statement(); (yyval.reference)->node.jump_statement.continue_flag = 0; (yyval.reference)->node.jump_statement.goto_target = NULL; - (yyval.reference)->node.jump_statement.lx_srcpos = (yyvsp[(1) - (2)].info).lx_srcpos; - ;} + (yyval.reference)->node.jump_statement.lx_srcpos = (yyvsp[-1].info).lx_srcpos; + } +#line 3800 "cod.tab.c" break; - case 192: -#line 1744 "cod/cod.y" - { + case 192: /* jump_statement: GOTO identifier_ref SEMI */ +#line 1758 "cod.y" + { (yyval.reference) = cod_new_jump_statement(); (yyval.reference)->node.jump_statement.continue_flag = 0; - (yyval.reference)->node.jump_statement.goto_target = (yyvsp[(2) - (3)].info).string; - (yyval.reference)->node.jump_statement.lx_srcpos = (yyvsp[(1) - (3)].info).lx_srcpos; - ;} + (yyval.reference)->node.jump_statement.goto_target = (yyvsp[-1].info).string; + (yyval.reference)->node.jump_statement.lx_srcpos = (yyvsp[-2].info).lx_srcpos; + } +#line 3811 "cod.tab.c" break; - case 193: -#line 1753 "cod/cod.y" - { + case 193: /* expression_statement: SEMI */ +#line 1767 "cod.y" + { (yyval.reference) = NULL; - ;} + } +#line 3819 "cod.tab.c" break; - case 194: -#line 1757 "cod/cod.y" - { + case 194: /* expression_statement: expression SEMI */ +#line 1771 "cod.y" + { (yyval.reference) = cod_new_expression_statement(); - (yyval.reference)->node.expression_statement.expression = (yyvsp[(1) - (2)].reference); - ;} + (yyval.reference)->node.expression_statement.expression = (yyvsp[-1].reference); + } +#line 3828 "cod.tab.c" break; - case 195: -#line 1768 "cod/cod.y" - { + case 195: /* selection_statement: IF LPAREN expression RPAREN statement */ +#line 1782 "cod.y" + { (yyval.reference) = cod_new_selection_statement(); - (yyval.reference)->node.selection_statement.lx_srcpos = (yyvsp[(1) - (5)].info).lx_srcpos; - (yyval.reference)->node.selection_statement.conditional = (yyvsp[(3) - (5)].reference); - (yyval.reference)->node.selection_statement.then_part = (yyvsp[(5) - (5)].reference); + (yyval.reference)->node.selection_statement.lx_srcpos = (yyvsp[-4].info).lx_srcpos; + (yyval.reference)->node.selection_statement.conditional = (yyvsp[-2].reference); + (yyval.reference)->node.selection_statement.then_part = (yyvsp[0].reference); (yyval.reference)->node.selection_statement.else_part = NULL; - ;} + } +#line 3840 "cod.tab.c" break; - case 196: -#line 1777 "cod/cod.y" - { + case 196: /* selection_statement: IF LPAREN expression RPAREN statement ELSE statement */ +#line 1791 "cod.y" + { (yyval.reference) = cod_new_selection_statement(); - (yyval.reference)->node.selection_statement.lx_srcpos = (yyvsp[(1) - (7)].info).lx_srcpos; - (yyval.reference)->node.selection_statement.conditional = (yyvsp[(3) - (7)].reference); - (yyval.reference)->node.selection_statement.then_part = (yyvsp[(5) - (7)].reference); - (yyval.reference)->node.selection_statement.else_part = (yyvsp[(7) - (7)].reference); - ;} + (yyval.reference)->node.selection_statement.lx_srcpos = (yyvsp[-6].info).lx_srcpos; + (yyval.reference)->node.selection_statement.conditional = (yyvsp[-4].reference); + (yyval.reference)->node.selection_statement.then_part = (yyvsp[-2].reference); + (yyval.reference)->node.selection_statement.else_part = (yyvsp[0].reference); + } +#line 3852 "cod.tab.c" break; - case 197: -#line 1794 "cod/cod.y" - { + case 197: /* iteration_statement: FOR LPAREN expression_opt SEMI expression_opt SEMI expression_opt RPAREN statement */ +#line 1808 "cod.y" + { (yyval.reference) = cod_new_iteration_statement(); - (yyval.reference)->node.iteration_statement.lx_srcpos = (yyvsp[(1) - (9)].info).lx_srcpos; - (yyval.reference)->node.iteration_statement.init_expr = (yyvsp[(3) - (9)].reference); - (yyval.reference)->node.iteration_statement.test_expr = (yyvsp[(5) - (9)].reference); - (yyval.reference)->node.iteration_statement.iter_expr = (yyvsp[(7) - (9)].reference); - (yyval.reference)->node.iteration_statement.statement = (yyvsp[(9) - (9)].reference); - ;} + (yyval.reference)->node.iteration_statement.lx_srcpos = (yyvsp[-8].info).lx_srcpos; + (yyval.reference)->node.iteration_statement.init_expr = (yyvsp[-6].reference); + (yyval.reference)->node.iteration_statement.test_expr = (yyvsp[-4].reference); + (yyval.reference)->node.iteration_statement.iter_expr = (yyvsp[-2].reference); + (yyval.reference)->node.iteration_statement.statement = (yyvsp[0].reference); + } +#line 3865 "cod.tab.c" break; - case 198: -#line 1804 "cod/cod.y" - { + case 198: /* iteration_statement: WHILE LPAREN expression RPAREN statement */ +#line 1818 "cod.y" + { (yyval.reference) = cod_new_iteration_statement(); - (yyval.reference)->node.iteration_statement.lx_srcpos = (yyvsp[(1) - (5)].info).lx_srcpos; + (yyval.reference)->node.iteration_statement.lx_srcpos = (yyvsp[-4].info).lx_srcpos; (yyval.reference)->node.iteration_statement.init_expr = NULL; - (yyval.reference)->node.iteration_statement.test_expr = (yyvsp[(3) - (5)].reference); + (yyval.reference)->node.iteration_statement.test_expr = (yyvsp[-2].reference); (yyval.reference)->node.iteration_statement.iter_expr = NULL; - (yyval.reference)->node.iteration_statement.statement = (yyvsp[(5) - (5)].reference); - ;} + (yyval.reference)->node.iteration_statement.statement = (yyvsp[0].reference); + } +#line 3878 "cod.tab.c" break; - case 199: -#line 1814 "cod/cod.y" - { + case 199: /* iteration_statement: DO statement WHILE LPAREN expression RPAREN SEMI */ +#line 1828 "cod.y" + { (yyval.reference) = cod_new_iteration_statement(); - (yyval.reference)->node.iteration_statement.lx_srcpos = (yyvsp[(1) - (7)].info).lx_srcpos; + (yyval.reference)->node.iteration_statement.lx_srcpos = (yyvsp[-6].info).lx_srcpos; (yyval.reference)->node.iteration_statement.init_expr = NULL; (yyval.reference)->node.iteration_statement.test_expr = NULL; - (yyval.reference)->node.iteration_statement.post_test_expr = (yyvsp[(5) - (7)].reference); + (yyval.reference)->node.iteration_statement.post_test_expr = (yyvsp[-2].reference); (yyval.reference)->node.iteration_statement.iter_expr = NULL; - (yyval.reference)->node.iteration_statement.statement = (yyvsp[(2) - (7)].reference); - ;} + (yyval.reference)->node.iteration_statement.statement = (yyvsp[-5].reference); + } +#line 3892 "cod.tab.c" break; - case 200: -#line 1827 "cod/cod.y" - { (yyval.reference) = NULL; ;} + case 200: /* expression_opt: %empty */ +#line 1841 "cod.y" + { (yyval.reference) = NULL; } +#line 3898 "cod.tab.c" break; - case 202: -#line 1832 "cod/cod.y" - { + case 202: /* constant: integer_constant */ +#line 1846 "cod.y" + { (yyval.reference) = cod_new_constant(); (yyval.reference)->node.constant.token = integer_constant; - (yyval.reference)->node.constant.const_val = (yyvsp[(1) - (1)].info).string; - (yyval.reference)->node.constant.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; - ;} + (yyval.reference)->node.constant.const_val = (yyvsp[0].info).string; + (yyval.reference)->node.constant.lx_srcpos = (yyvsp[0].info).lx_srcpos; + } +#line 3909 "cod.tab.c" break; - case 203: -#line 1839 "cod/cod.y" - { + case 203: /* constant: floating_constant */ +#line 1853 "cod.y" + { (yyval.reference) = cod_new_constant(); (yyval.reference)->node.constant.token = floating_constant; - (yyval.reference)->node.constant.const_val = (yyvsp[(1) - (1)].info).string; - (yyval.reference)->node.constant.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; - ;} + (yyval.reference)->node.constant.const_val = (yyvsp[0].info).string; + (yyval.reference)->node.constant.lx_srcpos = (yyvsp[0].info).lx_srcpos; + } +#line 3920 "cod.tab.c" break; - case 204: -#line 1846 "cod/cod.y" - { + case 204: /* constant: string_constant */ +#line 1860 "cod.y" + { (yyval.reference) = cod_new_constant(); (yyval.reference)->node.constant.token = string_constant; - (yyval.reference)->node.constant.const_val = (yyvsp[(1) - (1)].info).string; - (yyval.reference)->node.constant.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; - ;} + (yyval.reference)->node.constant.const_val = (yyvsp[0].info).string; + (yyval.reference)->node.constant.lx_srcpos = (yyvsp[0].info).lx_srcpos; + } +#line 3931 "cod.tab.c" break; - case 205: -#line 1853 "cod/cod.y" - { + case 205: /* constant: character_constant */ +#line 1867 "cod.y" + { (yyval.reference) = cod_new_constant(); (yyval.reference)->node.constant.token = character_constant; - (yyval.reference)->node.constant.const_val = (yyvsp[(1) - (1)].info).string; - (yyval.reference)->node.constant.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; - ;} + (yyval.reference)->node.constant.const_val = (yyvsp[0].info).string; + (yyval.reference)->node.constant.lx_srcpos = (yyvsp[0].info).lx_srcpos; + } +#line 3942 "cod.tab.c" break; - case 206: -#line 1860 "cod/cod.y" - { + case 206: /* constant: enumeration_constant */ +#line 1874 "cod.y" + { (yyval.reference) = cod_new_constant(); (yyval.reference)->node.constant.token = character_constant; - (yyval.reference)->node.constant.const_val = (yyvsp[(1) - (1)].info).string; - (yyval.reference)->node.constant.lx_srcpos = (yyvsp[(1) - (1)].info).lx_srcpos; - ;} + (yyval.reference)->node.constant.const_val = (yyvsp[0].info).string; + (yyval.reference)->node.constant.lx_srcpos = (yyvsp[0].info).lx_srcpos; + } +#line 3953 "cod.tab.c" break; -/* Line 1267 of yacc.c. */ -#line 3997 "/Users/eisen/prog/ffs/build/cod.tab.c" +#line 3957 "cod.tab.c" + default: break; } - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ + YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); YYPOPSTACK (yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval; - - /* Now `shift' the result of the reduction. Determine what state + /* Now 'shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ - - yyn = yyr1[yyn]; - - yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; - if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTOKENS]; + { + const int yylhs = yyr1[yyn] - YYNTOKENS; + const int yyi = yypgoto[yylhs] + *yyssp; + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp + ? yytable[yyi] + : yydefgoto[yylhs]); + } goto yynewstate; -/*------------------------------------. -| yyerrlab -- here on detecting error | -`------------------------------------*/ +/*--------------------------------------. +| yyerrlab -- here on detecting error. | +`--------------------------------------*/ yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; -#if ! YYERROR_VERBOSE yyerror (YY_("syntax error")); -#else - { - YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); - if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) - { - YYSIZE_T yyalloc = 2 * yysize; - if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) - yyalloc = YYSTACK_ALLOC_MAXIMUM; - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yyalloc); - if (yymsg) - yymsg_alloc = yyalloc; - else - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - } - } - - if (0 < yysize && yysize <= yymsg_alloc) - { - (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (yymsg); - } - else - { - yyerror (YY_("syntax error")); - if (yysize != 0) - goto yyexhaustedlab; - } - } -#endif } - - if (yyerrstatus == 3) { - /* If just tried and failed to reuse look-ahead token after an - error, discard it. */ + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ if (yychar <= YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == YYEOF) - YYABORT; - } + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } else - { - yydestruct ("Error: discarding", - yytoken, &yylval); - yychar = YYEMPTY; - } + { + yydestruct ("Error: discarding", + yytoken, &yylval); + yychar = YYEMPTY; + } } - /* Else will try to reuse look-ahead token after shifting the error + /* Else will try to reuse lookahead token after shifting the error token. */ goto yyerrlab1; @@ -4095,14 +4031,13 @@ yyparse () | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: + /* Pacify compilers when the user code never invokes YYERROR and the + label yyerrorlab therefore never appears in user code. */ + if (0) + YYERROR; + ++yynerrs; - /* Pacify compilers like GCC when the user code never invokes - YYERROR and the label yyerrorlab therefore never appears in user - code. */ - if (/*CONSTCOND*/ 0) - goto yyerrorlab; - - /* Do not reclaim the symbols of the rule which action triggered + /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ YYPOPSTACK (yylen); yylen = 0; @@ -4115,42 +4050,42 @@ yyparse () | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ + yyerrstatus = 3; /* Each real token shifted decrements this. */ + /* Pop stack until we find a state that shifts the error token. */ for (;;) { yyn = yypact[yystate]; - if (yyn != YYPACT_NINF) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } + if (!yypact_value_is_default (yyn)) + { + yyn += YYSYMBOL_YYerror; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } /* Pop the current state because it cannot handle the error token. */ if (yyssp == yyss) - YYABORT; + YYABORT; yydestruct ("Error: popping", - yystos[yystate], yyvsp); + YY_ACCESSING_SYMBOL (yystate), yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } - if (yyn == YYFINAL) - YYACCEPT; - + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); yystate = yyn; goto yynewstate; @@ -4161,54 +4096,61 @@ yyparse () `-------------------------------------*/ yyacceptlab: yyresult = 0; - goto yyreturn; + goto yyreturnlab; + /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: yyresult = 1; - goto yyreturn; + goto yyreturnlab; -#ifndef yyoverflow -/*-------------------------------------------------. -| yyexhaustedlab -- memory exhaustion comes here. | -`-------------------------------------------------*/ + +/*-----------------------------------------------------------. +| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | +`-----------------------------------------------------------*/ yyexhaustedlab: yyerror (YY_("memory exhausted")); yyresult = 2; - /* Fall through. */ -#endif + goto yyreturnlab; -yyreturn: - if (yychar != YYEOF && yychar != YYEMPTY) - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval); - /* Do not reclaim the symbols of the rule which action triggered + +/*----------------------------------------------------------. +| yyreturnlab -- parsing is finished, clean up and return. | +`----------------------------------------------------------*/ +yyreturnlab: + if (yychar != YYEMPTY) + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + } + /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); YY_STACK_PRINT (yyss, yyssp); while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp); + YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); YYPOPSTACK (1); } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif -#if YYERROR_VERBOSE - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); -#endif - /* Make sure YYID is used. */ - return YYID (yyresult); -} + return yyresult; +} -#line 1868 "cod/cod.y" +#line 1882 "cod.y" +#ifdef _MSC_VER +#define YY_NO_UNISTD_H +#endif #include "lex.yy.c" typedef struct scope *scope_ptr; @@ -4273,7 +4215,7 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) { char *out; char *ptr; - if (index(input, '#') == NULL) return NULL; + if (strchr(input, '#') == NULL) return NULL; out = strdup(input); ptr = out; *white = 0; @@ -4287,10 +4229,10 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) char *include_end; ptr += 8; while(isspace(*ptr)) ptr++; - line_end = index(ptr, '\n'); + line_end = strchr(ptr, '\n'); if (line_end) *line_end = 0; if ((*ptr == '<') || (*ptr == '"')) { - include_end = (*ptr == '<') ? index(ptr, '>') : index((ptr+1), '"'); + include_end = (*ptr == '<') ? strchr(ptr, '>') : strchr((ptr+1), '"'); if (!include_end) { printf("improper #include, \"%s\"\n", ptr); goto skip; @@ -4311,10 +4253,10 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) } skip: /* skip to next line */ - ptr = index(ptr, '\n'); + ptr = strchr(ptr, '\n'); while (ptr && (*(ptr - 1) == '\'')) { /* continued line */ - ptr = index(ptr, '\n'); + ptr = strchr(ptr, '\n'); } } { @@ -4329,9 +4271,7 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) } int -cod_parse_for_globals(code, context) -char *code; -cod_parse_context context; +cod_parse_for_globals(char *code, cod_parse_context context) { int ret; context->alloc_globals = 1; @@ -4340,9 +4280,7 @@ cod_parse_context context; return ret; } int -cod_parse_for_context(code, context) -char *code; -cod_parse_context context; +cod_parse_for_context(char *code, cod_parse_context context) { sm_list decls; int ret; @@ -4407,12 +4345,10 @@ static int include_prefix(char *code) break; } } - return tmp - code; + return (int)(intptr_t)(tmp - code); } cod_code -cod_code_gen(code, context) -char *code; -cod_parse_context context; +cod_code_gen(char *code, cod_parse_context context) { sm_ref tmp, tmp2; cod_code ret_code; @@ -4423,7 +4359,7 @@ cod_parse_context context; if (code != NULL) { if ((bracket = include_prefix(code))) { char *prefix = malloc(bracket+1), *tmp; - strncpy(prefix, code, bracket); + strncpy(prefix, code, bracket + 1); prefix[bracket] = 0; tmp = prefix; while(isspace(*tmp)) tmp++; @@ -4475,7 +4411,7 @@ cod_parse_context context; tmp->node.compound_statement.decls = NULL; tmp2->node.compound_statement.decls = NULL; cod_rfree(tmp2); - ret_code->func = (void(*)())(long)func; + ret_code->func = (void(*)(void))(intptr_t)func; return ret_code; } @@ -4493,9 +4429,7 @@ cod_dump(cod_code code) int -cod_code_verify(code, context) -char *code; -cod_parse_context context; +cod_code_verify(char *code, cod_parse_context context) { sm_ref tmp; @@ -4533,8 +4467,7 @@ cod_parse_context context; } extern void -cod_code_free(code) -cod_code code; +cod_code_free(cod_code code) { if (code->code_memory_block) free(code->code_memory_block); if (code->data) free(code->data); @@ -4594,7 +4527,7 @@ print_context(cod_parse_context context, int line, int character) offset = character - 40; } line_copy = copy_line(line_begin + offset); - line_len = strlen(line_copy); + line_len = (int)strlen(line_copy); if (line_len > 60) { line_copy[60] = 0; } @@ -4611,8 +4544,7 @@ print_context(cod_parse_context context, int line, int character) context->error_func(context->client_data, "^\n"); } -void yyerror(str) -char *str; +void yyerror(char *str) { char tmp_str[100]; sprintf(tmp_str, "## Error %s\n", str); @@ -4806,8 +4738,7 @@ struct scope { extern cod_parse_context -cod_copy_context(context) -cod_parse_context context; +cod_copy_context(cod_parse_context context) { int i, count; int type_count = 0; @@ -4844,8 +4775,7 @@ cod_parse_context context; extern void dump_scope(scope_ptr scope); extern cod_parse_context -cod_copy_globals(context) -cod_parse_context context; +cod_copy_globals(cod_parse_context context) { int i, count; int type_count = 0; @@ -5184,7 +5114,7 @@ determine_op_type(cod_parse_context context, sm_ref expr, if ((left_type == DILL_UL) || (right_type == DILL_UL)) return DILL_UL; if ((left_type == DILL_L) || (right_type == DILL_L)) { /* GSE -bug This test should be for *generated* target, not host */ - if (sizeof(long) > sizeof(unsigned int)) { + if (sizeof(intptr_t) > sizeof(unsigned int)) { /* Long can represent all values of unsigned int */ return DILL_L; } else { @@ -5535,7 +5465,7 @@ type_list_to_string(cod_parse_context context, sm_list type_list, int *size) *size = sizeof(int); return strdup("integer"); case DILL_L: - *size = sizeof(long); + *size = sizeof(intptr_t); return strdup("integer"); case DILL_S: *size = sizeof(short); @@ -5544,7 +5474,7 @@ type_list_to_string(cod_parse_context context, sm_list type_list, int *size) *size = sizeof(int); return strdup("unsigned integer"); case DILL_UL: - *size = sizeof(long); + *size = sizeof(intptr_t); return strdup("unsigned integer"); case DILL_US: *size = sizeof(short); @@ -6448,7 +6378,7 @@ unsigned long, long long, unsigned long long */ long i; - int len = strlen(val); + int len = (int)strlen(val); int hex = 0; int specified_unsgned = 0, specified_lng = 0; if (val[0] == '0') { @@ -7947,9 +7877,7 @@ cod_remove_defined_types(cod_parse_context context, int count) } void -cod_add_defined_type(id, context) -char *id; -cod_parse_context context; +cod_add_defined_type(char *id, cod_parse_context context) { int count = 0; while(context->defined_types && context->defined_types[count]) count++; @@ -7966,9 +7894,7 @@ cod_parse_context context; } void -cod_add_enum_const(id, context) -char *id; -cod_parse_context context; +cod_add_enum_const(char *id, cod_parse_context context) { int count = 0; while(context->enumerated_constants && context->enumerated_constants[count]) count++; @@ -8009,9 +7935,7 @@ cod_add_struct_type(FMStructDescList format_list, } static int -str_to_data_type(str, size) -char *str; -int size; +str_to_data_type(char *str, int size) { char *tmp = malloc(strlen(str) + 1); char *free_str = tmp; @@ -8033,7 +7957,7 @@ int size; } if ((strcmp(str, "integer") == 0) || (strcmp(str, "enumeration") == 0)) { free(free_str); - if (size == sizeof(long)) { + if (size == sizeof(intptr_t)) { return DILL_L; } else if (size == sizeof(int)) { return DILL_I; @@ -8046,7 +7970,7 @@ int size; } } else if (strcmp(str, "unsigned integer") == 0) { free(free_str); - if (size == sizeof(long)) { + if (size == sizeof(intptr_t)) { return DILL_UL; } else if (size == sizeof(int)) { return DILL_U; @@ -8081,9 +8005,7 @@ int size; } static int -array_str_to_data_type(str, size) -char *str; -int size; +array_str_to_data_type(char *str, int size) { int ret_type; char field_type[1024]; @@ -8103,14 +8025,8 @@ int size; } static sm_ref -build_subtype_nodes(context, decl, f, desc, err, scope, must_free_p) -cod_parse_context context; -sm_ref decl; -field* f; -FMTypeDesc *desc; -int *err; -scope_ptr scope; -int *must_free_p; +build_subtype_nodes(cod_parse_context context, sm_ref decl, field* f, FMTypeDesc *desc, + int *err, scope_ptr scope, int *must_free_p) { sm_ref ret = NULL; sm_ref subtype = NULL; @@ -8206,8 +8122,8 @@ int *must_free_p; ret->node.reference_type_decl.cg_referenced_type = DILL_ERR; ret->node.reference_type_decl.sm_complex_referenced_type = subtype; if (must_free_flag) { - if (ret->node.array_type_decl.freeable_complex_element_type) { - cod_rfree(ret->node.array_type_decl.freeable_complex_element_type); + if (ret->node.reference_type_decl.freeable_complex_referenced_type) { + cod_rfree(ret->node.reference_type_decl.freeable_complex_referenced_type); } ret->node.reference_type_decl.freeable_complex_referenced_type = subtype; } @@ -8233,16 +8149,8 @@ int *must_free_p; } static void -build_type_nodes(context, decl, f, fields, cg_size, cg_type, desc, err, scope) -cod_parse_context context; -sm_ref decl; -field* f; -sm_list fields; -int cg_size; -int cg_type; -FMTypeDesc* desc; -int *err; -scope_ptr scope; +build_type_nodes(cod_parse_context context, sm_ref decl, field* f, sm_list fields, + int cg_size, int cg_type, FMTypeDesc* desc, int *err, scope_ptr scope) { int must_free_flag = 0; sm_ref complex_type = build_subtype_nodes(context, decl, f, desc, err, scope, &must_free_flag); @@ -8256,13 +8164,7 @@ scope_ptr scope; } static int -semanticize_array_element_node(context, array, super_type, base_type_spec, - scope) -cod_parse_context context; -sm_ref array; -sm_ref super_type; -sm_list base_type_spec; -scope_ptr scope; +semanticize_array_element_node(cod_parse_context context, sm_ref array, sm_ref super_type, sm_list base_type_spec, scope_ptr scope) { if (array->node.array_type_decl.size_expr != NULL) { if (!is_constant_expr(array->node.array_type_decl.size_expr)) { @@ -8330,10 +8232,7 @@ scope_ptr scope; } static int -semanticize_array_type_node(context, array, scope) -cod_parse_context context; -sm_ref array; -scope_ptr scope; +semanticize_array_type_node(cod_parse_context context, sm_ref array, scope_ptr scope) { if (!array->node.array_type_decl.dimensions) { array->node.array_type_decl.dimensions = malloc(sizeof(dimen_s)); @@ -8837,7 +8736,7 @@ static void uniqueify_names(FMStructDescList list, char *prefix) { int i = 0; - int prefix_len = strlen(prefix); + int prefix_len = (int)strlen(prefix); while (list[i].format_name != NULL) { int j = 0; FMFieldList fl = list[i].field_list; @@ -8845,14 +8744,14 @@ uniqueify_names(FMStructDescList list, char *prefix) malloc(strlen(list[i].format_name) + prefix_len + 1); strcpy(new_name, prefix); strcpy(new_name + prefix_len, list[i].format_name); - free(list[i].format_name); + free((char*)list[i].format_name); list[i].format_name = new_name; while (fl[j].field_name != 0) { - int field_type_len = strlen(fl[j].field_type); + int field_type_len = (int)strlen(fl[j].field_type); char *bracket = strchr(fl[j].field_type, '['); int k; if (bracket != NULL) { - field_type_len = (long) bracket - (long) fl[j].field_type; + field_type_len = (int)((intptr_t) bracket - (intptr_t) fl[j].field_type); } for (k = 0; k < i; k++) { char *new_type; @@ -8940,9 +8839,10 @@ get_constant_float_value(cod_parse_context context, sm_ref expr) default: assert(FALSE); } + return 0.0; } -static long +static intptr_t get_constant_long_value(cod_parse_context context, sm_ref expr) { double dresult; @@ -8961,6 +8861,7 @@ get_constant_long_value(cod_parse_context context, sm_ref expr) default: assert(FALSE); } + return -1; } extern sm_ref @@ -9054,7 +8955,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ is_ivalue=1; break; case op_eq: - ivalue = left_val = right_val; + ivalue = left_val == right_val; is_ivalue=1; break; case op_neq: @@ -9099,7 +9000,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ *free_result = 1; } else { /* we get an integer result */ - long left_val = 0, right_val = 0, value; + intptr_t left_val = 0, right_val = 0, value; char str_val[40]; if (expr->node.operator.left) left_val = get_constant_long_value(context, left); @@ -9178,7 +9079,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ } ret = cod_new_constant(); ret->node.constant.token = integer_constant; - sprintf(str_val, "%ld", value); + sprintf(str_val, "%Id", value); ret->node.constant.const_val = strdup(str_val); *free_result = 1; } @@ -9200,6 +9101,6 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ default: assert(FALSE); } + return NULL; } - diff --git a/cod/pregen_source/Windows/cod.y b/cod/pregen_source/Windows/cod.y index 6fcf832a75..d71e908d4d 100644 --- a/cod/pregen_source/Windows/cod.y +++ b/cod/pregen_source/Windows/cod.y @@ -1,5 +1,8 @@ %{ #include "config.h" +#ifdef __NVCOMPILER +#pragma diag_suppress 550, 111, 941 +#endif #if defined (__INTEL_COMPILER) # pragma warning (disable: 2215) #endif @@ -31,10 +34,6 @@ int cod_kplugins_integration = 0; #include #endif #endif -#include "fm.h" -#include "fm_internal.h" -#include "cod.h" -#include "cod_internal.h" #undef NDEBUG #include "assert.h" #ifndef LINUX_KERNEL_MODULE @@ -58,6 +57,10 @@ int cod_kplugins_integration = 0; #define OP_DBL_Digs (DBL_DIG + 3) #endif #endif +#include "fm.h" +#include "fm_internal.h" +#include "cod.h" +#include "cod_internal.h" #include "structs.h" #ifdef HAVE_DILL_H #include "dill.h" @@ -79,9 +82,17 @@ enum { DILL_EC, DILL_ERR /* no type */ }; +typedef void *dill_stream; +#define dill_create_stream() 0 +#define dill_type_size(c, s) 0 #endif #if defined(_MSC_VER) #define strdup _strdup +#define isatty _isatty +#define fileno _fileno +#include +#include +#include #endif #ifndef LINUX_KERNEL_MODULE #ifdef STDC_HEADERS @@ -106,14 +117,17 @@ char *strdup(const char *s) return p; } #endif +#ifdef _MSC_VER +#undef strncpy +#endif #define YY_NO_INPUT static char* gen_anon() { static int anon_count = 0; - char *ret = malloc(strlen("Anonymous-xxxxxxxxxxxxxxxxx")); - sprintf(ret, "Anonymous-%d", anon_count++); + char *ret = malloc(40); + snprintf(ret, 40, "Anonymous-%d", anon_count++); return ret; } @@ -1866,6 +1880,9 @@ constant : ; %% +#ifdef _MSC_VER +#define YY_NO_UNISTD_H +#endif #include "lex.yy.c" typedef struct scope *scope_ptr; @@ -1930,7 +1947,7 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) { char *out; char *ptr; - if (index(input, '#') == NULL) return NULL; + if (strchr(input, '#') == NULL) return NULL; out = strdup(input); ptr = out; *white = 0; @@ -1944,10 +1961,10 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) char *include_end; ptr += 8; while(isspace(*ptr)) ptr++; - line_end = index(ptr, '\n'); + line_end = strchr(ptr, '\n'); if (line_end) *line_end = 0; if ((*ptr == '<') || (*ptr == '"')) { - include_end = (*ptr == '<') ? index(ptr, '>') : index((ptr+1), '"'); + include_end = (*ptr == '<') ? strchr(ptr, '>') : strchr((ptr+1), '"'); if (!include_end) { printf("improper #include, \"%s\"\n", ptr); goto skip; @@ -1968,10 +1985,10 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) } skip: /* skip to next line */ - ptr = index(ptr, '\n'); + ptr = strchr(ptr, '\n'); while (ptr && (*(ptr - 1) == '\'')) { /* continued line */ - ptr = index(ptr, '\n'); + ptr = strchr(ptr, '\n'); } } { @@ -1986,9 +2003,7 @@ cod_preprocessor(char *input, cod_parse_context context, int*white) } int -cod_parse_for_globals(code, context) -char *code; -cod_parse_context context; +cod_parse_for_globals(char *code, cod_parse_context context) { int ret; context->alloc_globals = 1; @@ -1997,9 +2012,7 @@ cod_parse_context context; return ret; } int -cod_parse_for_context(code, context) -char *code; -cod_parse_context context; +cod_parse_for_context(char *code, cod_parse_context context) { sm_list decls; int ret; @@ -2064,12 +2077,10 @@ static int include_prefix(char *code) break; } } - return tmp - code; + return (int)(intptr_t)(tmp - code); } cod_code -cod_code_gen(code, context) -char *code; -cod_parse_context context; +cod_code_gen(char *code, cod_parse_context context) { sm_ref tmp, tmp2; cod_code ret_code; @@ -2080,7 +2091,7 @@ cod_parse_context context; if (code != NULL) { if ((bracket = include_prefix(code))) { char *prefix = malloc(bracket+1), *tmp; - strncpy(prefix, code, bracket); + strncpy(prefix, code, bracket + 1); prefix[bracket] = 0; tmp = prefix; while(isspace(*tmp)) tmp++; @@ -2132,7 +2143,7 @@ cod_parse_context context; tmp->node.compound_statement.decls = NULL; tmp2->node.compound_statement.decls = NULL; cod_rfree(tmp2); - ret_code->func = (void(*)())(long)func; + ret_code->func = (void(*)(void))(intptr_t)func; return ret_code; } @@ -2150,9 +2161,7 @@ cod_dump(cod_code code) int -cod_code_verify(code, context) -char *code; -cod_parse_context context; +cod_code_verify(char *code, cod_parse_context context) { sm_ref tmp; @@ -2190,8 +2199,7 @@ cod_parse_context context; } extern void -cod_code_free(code) -cod_code code; +cod_code_free(cod_code code) { if (code->code_memory_block) free(code->code_memory_block); if (code->data) free(code->data); @@ -2251,7 +2259,7 @@ print_context(cod_parse_context context, int line, int character) offset = character - 40; } line_copy = copy_line(line_begin + offset); - line_len = strlen(line_copy); + line_len = (int)strlen(line_copy); if (line_len > 60) { line_copy[60] = 0; } @@ -2268,8 +2276,7 @@ print_context(cod_parse_context context, int line, int character) context->error_func(context->client_data, "^\n"); } -void yyerror(str) -char *str; +void yyerror(char *str) { char tmp_str[100]; sprintf(tmp_str, "## Error %s\n", str); @@ -2463,8 +2470,7 @@ struct scope { extern cod_parse_context -cod_copy_context(context) -cod_parse_context context; +cod_copy_context(cod_parse_context context) { int i, count; int type_count = 0; @@ -2501,8 +2507,7 @@ cod_parse_context context; extern void dump_scope(scope_ptr scope); extern cod_parse_context -cod_copy_globals(context) -cod_parse_context context; +cod_copy_globals(cod_parse_context context) { int i, count; int type_count = 0; @@ -2841,7 +2846,7 @@ determine_op_type(cod_parse_context context, sm_ref expr, if ((left_type == DILL_UL) || (right_type == DILL_UL)) return DILL_UL; if ((left_type == DILL_L) || (right_type == DILL_L)) { /* GSE -bug This test should be for *generated* target, not host */ - if (sizeof(long) > sizeof(unsigned int)) { + if (sizeof(intptr_t) > sizeof(unsigned int)) { /* Long can represent all values of unsigned int */ return DILL_L; } else { @@ -3192,7 +3197,7 @@ type_list_to_string(cod_parse_context context, sm_list type_list, int *size) *size = sizeof(int); return strdup("integer"); case DILL_L: - *size = sizeof(long); + *size = sizeof(intptr_t); return strdup("integer"); case DILL_S: *size = sizeof(short); @@ -3201,7 +3206,7 @@ type_list_to_string(cod_parse_context context, sm_list type_list, int *size) *size = sizeof(int); return strdup("unsigned integer"); case DILL_UL: - *size = sizeof(long); + *size = sizeof(intptr_t); return strdup("unsigned integer"); case DILL_US: *size = sizeof(short); @@ -4105,7 +4110,7 @@ unsigned long, long long, unsigned long long */ long i; - int len = strlen(val); + int len = (int)strlen(val); int hex = 0; int specified_unsgned = 0, specified_lng = 0; if (val[0] == '0') { @@ -5604,9 +5609,7 @@ cod_remove_defined_types(cod_parse_context context, int count) } void -cod_add_defined_type(id, context) -char *id; -cod_parse_context context; +cod_add_defined_type(char *id, cod_parse_context context) { int count = 0; while(context->defined_types && context->defined_types[count]) count++; @@ -5623,9 +5626,7 @@ cod_parse_context context; } void -cod_add_enum_const(id, context) -char *id; -cod_parse_context context; +cod_add_enum_const(char *id, cod_parse_context context) { int count = 0; while(context->enumerated_constants && context->enumerated_constants[count]) count++; @@ -5666,9 +5667,7 @@ cod_add_struct_type(FMStructDescList format_list, } static int -str_to_data_type(str, size) -char *str; -int size; +str_to_data_type(char *str, int size) { char *tmp = malloc(strlen(str) + 1); char *free_str = tmp; @@ -5690,7 +5689,7 @@ int size; } if ((strcmp(str, "integer") == 0) || (strcmp(str, "enumeration") == 0)) { free(free_str); - if (size == sizeof(long)) { + if (size == sizeof(intptr_t)) { return DILL_L; } else if (size == sizeof(int)) { return DILL_I; @@ -5703,7 +5702,7 @@ int size; } } else if (strcmp(str, "unsigned integer") == 0) { free(free_str); - if (size == sizeof(long)) { + if (size == sizeof(intptr_t)) { return DILL_UL; } else if (size == sizeof(int)) { return DILL_U; @@ -5738,9 +5737,7 @@ int size; } static int -array_str_to_data_type(str, size) -char *str; -int size; +array_str_to_data_type(char *str, int size) { int ret_type; char field_type[1024]; @@ -5760,14 +5757,8 @@ int size; } static sm_ref -build_subtype_nodes(context, decl, f, desc, err, scope, must_free_p) -cod_parse_context context; -sm_ref decl; -field* f; -FMTypeDesc *desc; -int *err; -scope_ptr scope; -int *must_free_p; +build_subtype_nodes(cod_parse_context context, sm_ref decl, field* f, FMTypeDesc *desc, + int *err, scope_ptr scope, int *must_free_p) { sm_ref ret = NULL; sm_ref subtype = NULL; @@ -5863,8 +5854,8 @@ int *must_free_p; ret->node.reference_type_decl.cg_referenced_type = DILL_ERR; ret->node.reference_type_decl.sm_complex_referenced_type = subtype; if (must_free_flag) { - if (ret->node.array_type_decl.freeable_complex_element_type) { - cod_rfree(ret->node.array_type_decl.freeable_complex_element_type); + if (ret->node.reference_type_decl.freeable_complex_referenced_type) { + cod_rfree(ret->node.reference_type_decl.freeable_complex_referenced_type); } ret->node.reference_type_decl.freeable_complex_referenced_type = subtype; } @@ -5890,16 +5881,8 @@ int *must_free_p; } static void -build_type_nodes(context, decl, f, fields, cg_size, cg_type, desc, err, scope) -cod_parse_context context; -sm_ref decl; -field* f; -sm_list fields; -int cg_size; -int cg_type; -FMTypeDesc* desc; -int *err; -scope_ptr scope; +build_type_nodes(cod_parse_context context, sm_ref decl, field* f, sm_list fields, + int cg_size, int cg_type, FMTypeDesc* desc, int *err, scope_ptr scope) { int must_free_flag = 0; sm_ref complex_type = build_subtype_nodes(context, decl, f, desc, err, scope, &must_free_flag); @@ -5913,13 +5896,7 @@ scope_ptr scope; } static int -semanticize_array_element_node(context, array, super_type, base_type_spec, - scope) -cod_parse_context context; -sm_ref array; -sm_ref super_type; -sm_list base_type_spec; -scope_ptr scope; +semanticize_array_element_node(cod_parse_context context, sm_ref array, sm_ref super_type, sm_list base_type_spec, scope_ptr scope) { if (array->node.array_type_decl.size_expr != NULL) { if (!is_constant_expr(array->node.array_type_decl.size_expr)) { @@ -5987,10 +5964,7 @@ scope_ptr scope; } static int -semanticize_array_type_node(context, array, scope) -cod_parse_context context; -sm_ref array; -scope_ptr scope; +semanticize_array_type_node(cod_parse_context context, sm_ref array, scope_ptr scope) { if (!array->node.array_type_decl.dimensions) { array->node.array_type_decl.dimensions = malloc(sizeof(dimen_s)); @@ -6494,7 +6468,7 @@ static void uniqueify_names(FMStructDescList list, char *prefix) { int i = 0; - int prefix_len = strlen(prefix); + int prefix_len = (int)strlen(prefix); while (list[i].format_name != NULL) { int j = 0; FMFieldList fl = list[i].field_list; @@ -6502,14 +6476,14 @@ uniqueify_names(FMStructDescList list, char *prefix) malloc(strlen(list[i].format_name) + prefix_len + 1); strcpy(new_name, prefix); strcpy(new_name + prefix_len, list[i].format_name); - free(list[i].format_name); + free((char*)list[i].format_name); list[i].format_name = new_name; while (fl[j].field_name != 0) { - int field_type_len = strlen(fl[j].field_type); + int field_type_len = (int)strlen(fl[j].field_type); char *bracket = strchr(fl[j].field_type, '['); int k; if (bracket != NULL) { - field_type_len = (long) bracket - (long) fl[j].field_type; + field_type_len = (int)((intptr_t) bracket - (intptr_t) fl[j].field_type); } for (k = 0; k < i; k++) { char *new_type; @@ -6597,9 +6571,10 @@ get_constant_float_value(cod_parse_context context, sm_ref expr) default: assert(FALSE); } + return 0.0; } -static long +static intptr_t get_constant_long_value(cod_parse_context context, sm_ref expr) { double dresult; @@ -6618,6 +6593,7 @@ get_constant_long_value(cod_parse_context context, sm_ref expr) default: assert(FALSE); } + return -1; } extern sm_ref @@ -6711,7 +6687,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ is_ivalue=1; break; case op_eq: - ivalue = left_val = right_val; + ivalue = left_val == right_val; is_ivalue=1; break; case op_neq: @@ -6756,7 +6732,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ *free_result = 1; } else { /* we get an integer result */ - long left_val = 0, right_val = 0, value; + intptr_t left_val = 0, right_val = 0, value; char str_val[40]; if (expr->node.operator.left) left_val = get_constant_long_value(context, left); @@ -6835,7 +6811,7 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ } ret = cod_new_constant(); ret->node.constant.token = integer_constant; - sprintf(str_val, "%ld", value); + sprintf(str_val, "%Id", value); ret->node.constant.const_val = strdup(str_val); *free_result = 1; } @@ -6857,5 +6833,6 @@ evaluate_constant_return_expr(cod_parse_context context, sm_ref expr, int *free_ default: assert(FALSE); } + return NULL; } diff --git a/cod/pregen_source/Windows/lex.yy.c b/cod/pregen_source/Windows/lex.yy.c index e754ca5f93..b2a48531fa 100644 --- a/cod/pregen_source/Windows/lex.yy.c +++ b/cod/pregen_source/Windows/lex.yy.c @@ -1,6 +1,5 @@ -#line 2 "/Users/eisen/prog/ffs/build/lex.yy.c" -#line 4 "/Users/eisen/prog/ffs/build/lex.yy.c" +#line 2 "lex.yy.c" #define YY_INT_ALIGNED short int @@ -8,8 +7,8 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 35 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 4 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif @@ -47,7 +46,6 @@ typedef int16_t flex_int16_t; typedef uint16_t flex_uint16_t; typedef int32_t flex_int32_t; typedef uint32_t flex_uint32_t; -typedef uint64_t flex_uint64_t; #else typedef signed char flex_int8_t; typedef short int flex_int16_t; @@ -55,7 +53,6 @@ typedef int flex_int32_t; typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; -#endif /* ! C99 */ /* Limits of integral types. */ #ifndef INT8_MIN @@ -86,63 +83,61 @@ typedef unsigned int flex_uint32_t; #define UINT32_MAX (4294967295U) #endif -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ +#ifndef SIZE_MAX +#define SIZE_MAX (~(size_t)0) +#endif -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) +#endif /* ! C99 */ -#define YY_USE_CONST +#endif /* ! FLEXINT_H */ -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ +/* begin standard C++ headers. */ -#ifdef YY_USE_CONST +/* TODO: this is always defined, so inline it */ #define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) #else -#define yyconst +#define yynoreturn #endif /* Returned upon end-of-file. */ #define YY_NULL 0 -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. +/* Promotes a possibly negative, possibly signed char to an + * integer in range [0..255] for use as an array index. */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) +#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()-less * definition of BEGIN. */ #define BEGIN (yy_start) = 1 + 2 * - /* Translate the current start state into a value that can be later handed * to BEGIN to return to the state. The YYSTATE alias is for lex * compatibility. */ #define YY_START (((yy_start) - 1) / 2) #define YYSTATE YY_START - /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - /* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin ) - +#define YY_NEW_FILE yyrestart( yyin ) #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ #ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else #define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ #endif /* The state buf must be large enough to hold one state per character in the main buffer. @@ -159,15 +154,16 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; typedef size_t yy_size_t; #endif -extern yy_size_t yyleng; +extern int yyleng; extern FILE *yyin, *yyout; #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 - + #define YY_LESS_LINENO(n) + #define YY_LINENO_REWIND_TO(ptr) /* Return all but the first "n" matched characters back to the input stream. */ #define yyless(n) \ @@ -182,7 +178,6 @@ extern FILE *yyin, *yyout; YY_DO_BEFORE_ACTION; /* set up yytext again */ \ } \ while ( 0 ) - #define unput(c) yyunput( c, (yytext_ptr) ) #ifndef YY_STRUCT_YY_BUFFER_STATE @@ -197,12 +192,12 @@ struct yy_buffer_state /* Size of input buffer in bytes, not including room for EOB * characters. */ - yy_size_t yy_buf_size; + int yy_buf_size; /* Number of characters read into yy_ch_buf, not including EOB * characters. */ - yy_size_t yy_n_chars; + int yy_n_chars; /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to @@ -225,7 +220,7 @@ struct yy_buffer_state int yy_bs_lineno; /**< The line count. */ int yy_bs_column; /**< The column count. */ - + /* Whether to try to fill the input buffer when we reach the * end of it. */ @@ -253,7 +248,7 @@ struct yy_buffer_state /* Stack of input buffers. */ static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ +static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general @@ -264,7 +259,6 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ : NULL) - /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ @@ -272,11 +266,11 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ /* yy_hold_char holds the character lost when yytext is formed. */ static char yy_hold_char; -static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ -yy_size_t yyleng; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int yyleng; /* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; +static char *yy_c_buf_p = NULL; static int yy_init = 0; /* whether we need to initialize */ static int yy_start = 0; /* start state number */ @@ -285,82 +279,78 @@ static int yy_start = 0; /* start state number */ */ static int yy_did_buffer_switch_on_eof; -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); +void yyrestart ( FILE *input_file ); +void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); +void yy_delete_buffer ( YY_BUFFER_STATE b ); +void yy_flush_buffer ( YY_BUFFER_STATE b ); +void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state ( void ); -static void yyensure_buffer_stack (void ); -static void yy_load_buffer_state (void ); -static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); +static void yyensure_buffer_stack ( void ); +static void yy_load_buffer_state ( void ); +static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file ); +#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER ) -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) +YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); +YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ); - -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); +void *yyalloc ( yy_size_t ); +void *yyrealloc ( void *, yy_size_t ); +void yyfree ( void * ); #define yy_new_buffer yy_create_buffer - #define yy_set_interactive(is_interactive) \ { \ if ( ! YY_CURRENT_BUFFER ){ \ yyensure_buffer_stack (); \ YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ } - #define yy_set_bol(at_bol) \ { \ if ( ! YY_CURRENT_BUFFER ){\ yyensure_buffer_stack (); \ YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ } - #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) /* Begin user sect3 */ +typedef flex_uint8_t YY_CHAR; -typedef unsigned char YY_CHAR; - -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; +FILE *yyin = NULL, *yyout = NULL; typedef int yy_state_type; extern int yylineno; - int yylineno = 1; extern char *yytext; +#ifdef yytext_ptr +#undef yytext_ptr +#endif #define yytext_ptr yytext -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -static void yy_fatal_error (yyconst char msg[] ); +static yy_state_type yy_get_previous_state ( void ); +static yy_state_type yy_try_NUL_trans ( yy_state_type current_state ); +static int yy_get_next_buffer ( void ); +static void yynoreturn yy_fatal_error ( const char* msg ); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ #define YY_DO_BEFORE_ACTION \ (yytext_ptr) = yy_bp; \ - yyleng = (yy_size_t) (yy_cp - yy_bp); \ + yyleng = (int) (yy_cp - yy_bp); \ (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ (yy_c_buf_p) = yy_cp; - #define YY_NUM_RULES 107 #define YY_END_OF_BUFFER 108 /* This struct is not used in this scanner, @@ -370,7 +360,7 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static yyconst flex_int16_t yy_accept[284] = +static const flex_int16_t yy_accept[284] = { 0, 0, 0, 0, 0, 90, 90, 108, 107, 105, 106, 72, 76, 12, 38, 107, 2, 3, 9, 13, 8, @@ -405,7 +395,7 @@ static yyconst flex_int16_t yy_accept[284] = 61, 48, 0 } ; -static yyconst flex_int32_t yy_ec[256] = +static const YY_CHAR yy_ec[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -437,7 +427,7 @@ static yyconst flex_int32_t yy_ec[256] = 1, 1, 1, 1, 1 } ; -static yyconst flex_int32_t yy_meta[68] = +static const YY_CHAR yy_meta[68] = { 0, 1, 1, 2, 1, 3, 1, 1, 4, 1, 1, 5, 1, 1, 1, 6, 1, 7, 7, 7, 8, @@ -448,7 +438,7 @@ static yyconst flex_int32_t yy_meta[68] = 11, 10, 10, 1, 1, 1, 1 } ; -static yyconst flex_int16_t yy_base[299] = +static const flex_int16_t yy_base[299] = { 0, 0, 0, 65, 66, 69, 70, 614, 615, 615, 615, 589, 615, 588, 67, 574, 615, 615, 586, 63, 615, @@ -485,7 +475,7 @@ static yyconst flex_int16_t yy_base[299] = } ; -static yyconst flex_int16_t yy_def[299] = +static const flex_int16_t yy_def[299] = { 0, 283, 1, 284, 284, 285, 285, 283, 283, 283, 283, 283, 283, 283, 283, 286, 283, 283, 283, 283, 283, @@ -522,7 +512,7 @@ static yyconst flex_int16_t yy_def[299] = } ; -static yyconst flex_int16_t yy_nxt[683] = +static const flex_int16_t yy_nxt[683] = { 0, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 25, 25, @@ -601,7 +591,7 @@ static yyconst flex_int16_t yy_nxt[683] = 283, 283 } ; -static yyconst flex_int16_t yy_chk[683] = +static const flex_int16_t yy_chk[683] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -694,8 +684,8 @@ int yy_flex_debug = 0; #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET char *yytext; -#line 1 "cod/cod.l" -#line 18 "cod/cod.l" +#line 1 "cod.l" +#line 18 "cod.l" static int lex_offset = 1; static int line_count = 1; static char *create_string_from_yytext(); @@ -752,8 +742,7 @@ extern int my_yy_input(); #endif static int -is_defined_type(id) -char *id; +is_defined_type(char *id) { int i = 0; while(types && types[i]) { @@ -764,8 +753,7 @@ char *id; } static int -is_enumeration_constant(id) -char *id; +is_enumeration_constant(char *id) { int i = 0; while(enums && enums[i]) { @@ -778,8 +766,9 @@ static void check_strbuf(); static int buffer_len; static char *string_buffer; static char *string_buf_ptr; +#line 769 "lex.yy.c" -#line 783 "/Users/eisen/prog/ffs/build/lex.yy.c" +#line 771 "lex.yy.c" #define INITIAL 0 #define string_cond 1 @@ -797,36 +786,36 @@ static char *string_buf_ptr; #define YY_EXTRA_TYPE void * #endif -static int yy_init_globals (void ); +static int yy_init_globals ( void ); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ -int yylex_destroy (void ); +int yylex_destroy ( void ); -int yyget_debug (void ); +int yyget_debug ( void ); -void yyset_debug (int debug_flag ); +void yyset_debug ( int debug_flag ); -YY_EXTRA_TYPE yyget_extra (void ); +YY_EXTRA_TYPE yyget_extra ( void ); -void yyset_extra (YY_EXTRA_TYPE user_defined ); +void yyset_extra ( YY_EXTRA_TYPE user_defined ); -FILE *yyget_in (void ); +FILE *yyget_in ( void ); -void yyset_in (FILE * in_str ); +void yyset_in ( FILE * _in_str ); -FILE *yyget_out (void ); +FILE *yyget_out ( void ); -void yyset_out (FILE * out_str ); +void yyset_out ( FILE * _out_str ); -yy_size_t yyget_leng (void ); + int yyget_leng ( void ); -char *yyget_text (void ); +char *yyget_text ( void ); -int yyget_lineno (void ); +int yyget_lineno ( void ); -void yyset_lineno (int line_number ); +void yyset_lineno ( int _line_number ); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -834,35 +823,43 @@ void yyset_lineno (int line_number ); #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int yywrap (void ); +extern "C" int yywrap ( void ); #else -extern int yywrap (void ); +extern int yywrap ( void ); #endif #endif - static void yyunput (int c,char *buf_ptr ); +#ifndef YY_NO_UNPUT + + static void yyunput ( int c, char *buf_ptr ); +#endif + #ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); +static void yy_flex_strncpy ( char *, const char *, int ); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); +static int yy_flex_strlen ( const char * ); #endif #ifndef YY_NO_INPUT - #ifdef __cplusplus -static int yyinput (void ); +static int yyinput ( void ); #else -static int input (void ); +static int input ( void ); #endif #endif /* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else #define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ #endif /* Copy whatever the last rule matched to the standard output. */ @@ -870,7 +867,7 @@ static int input (void ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO fwrite( yytext, yyleng, 1, yyout ) +#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, @@ -881,7 +878,7 @@ static int input (void ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - yy_size_t n; \ + int n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -894,7 +891,7 @@ static int input (void ); else \ { \ errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \ { \ if( errno != EINTR) \ { \ @@ -949,7 +946,7 @@ extern int yylex (void); /* Code executed at the end of each rule. */ #ifndef YY_BREAK -#define YY_BREAK break; +#define YY_BREAK /*LINTED*/break; #endif #define YY_RULE_SETUP \ @@ -959,16 +956,10 @@ extern int yylex (void); */ YY_DECL { - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; -#line 103 "cod/cod.l" - - - -#line 971 "/Users/eisen/prog/ffs/build/lex.yy.c" - if ( !(yy_init) ) { (yy_init) = 1; @@ -989,13 +980,20 @@ YY_DECL if ( ! YY_CURRENT_BUFFER ) { yyensure_buffer_stack (); YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); + yy_create_buffer( yyin, YY_BUF_SIZE ); } - yy_load_buffer_state( ); + yy_load_buffer_state( ); } - while ( 1 ) /* loops until end-of-file is reached */ + { +#line 101 "cod.l" + + + +#line 994 "lex.yy.c" + + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { yy_cp = (yy_c_buf_p); @@ -1011,7 +1009,7 @@ YY_DECL yy_match: do { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; @@ -1021,9 +1019,9 @@ YY_DECL { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 284 ) - yy_c = yy_meta[(unsigned int) yy_c]; + yy_c = yy_meta[yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; ++yy_cp; } while ( yy_base[yy_current_state] != 615 ); @@ -1052,352 +1050,352 @@ YY_DECL case 1: YY_RULE_SETUP -#line 106 "cod/cod.l" +#line 104 "cod.l" {RETURN(ARROW);} YY_BREAK case 2: YY_RULE_SETUP -#line 107 "cod/cod.l" +#line 105 "cod.l" {RETURN(LPAREN);} YY_BREAK case 3: YY_RULE_SETUP -#line 108 "cod/cod.l" +#line 106 "cod.l" {RETURN(RPAREN);} YY_BREAK case 4: YY_RULE_SETUP -#line 109 "cod/cod.l" +#line 107 "cod.l" {RETURN(LBRACKET);} YY_BREAK case 5: YY_RULE_SETUP -#line 110 "cod/cod.l" +#line 108 "cod.l" {RETURN(RBRACKET);} YY_BREAK case 6: YY_RULE_SETUP -#line 111 "cod/cod.l" +#line 109 "cod.l" {RETURN(DOTDOTDOT);} YY_BREAK case 7: YY_RULE_SETUP -#line 112 "cod/cod.l" +#line 110 "cod.l" {RETURN(DOT);} YY_BREAK case 8: YY_RULE_SETUP -#line 113 "cod/cod.l" +#line 111 "cod.l" {RETURN(COMMA);} YY_BREAK case 9: YY_RULE_SETUP -#line 114 "cod/cod.l" +#line 112 "cod.l" {RETURN(STAR);} YY_BREAK case 10: YY_RULE_SETUP -#line 115 "cod/cod.l" +#line 113 "cod.l" {RETURN(AT);} YY_BREAK case 11: YY_RULE_SETUP -#line 116 "cod/cod.l" +#line 114 "cod.l" {RETURN(SLASH);} YY_BREAK case 12: YY_RULE_SETUP -#line 117 "cod/cod.l" +#line 115 "cod.l" {RETURN(MODULUS);} YY_BREAK case 13: YY_RULE_SETUP -#line 118 "cod/cod.l" +#line 116 "cod.l" {RETURN(PLUS);} YY_BREAK case 14: YY_RULE_SETUP -#line 119 "cod/cod.l" +#line 117 "cod.l" {RETURN(MINUS);} YY_BREAK case 15: YY_RULE_SETUP -#line 120 "cod/cod.l" +#line 118 "cod.l" {RETURN(TILDE);} YY_BREAK case 16: YY_RULE_SETUP -#line 121 "cod/cod.l" +#line 119 "cod.l" {RETURN(LEQ);} YY_BREAK case 17: YY_RULE_SETUP -#line 122 "cod/cod.l" +#line 120 "cod.l" {RETURN(LT);} YY_BREAK case 18: YY_RULE_SETUP -#line 123 "cod/cod.l" +#line 121 "cod.l" {RETURN(GEQ);} YY_BREAK case 19: YY_RULE_SETUP -#line 124 "cod/cod.l" +#line 122 "cod.l" {RETURN(GT);} YY_BREAK case 20: YY_RULE_SETUP -#line 125 "cod/cod.l" +#line 123 "cod.l" {RETURN(LEFT_SHIFT);} YY_BREAK case 21: YY_RULE_SETUP -#line 126 "cod/cod.l" +#line 124 "cod.l" {RETURN(RIGHT_SHIFT);} YY_BREAK case 22: YY_RULE_SETUP -#line 127 "cod/cod.l" +#line 125 "cod.l" {RETURN(EQ);} YY_BREAK case 23: YY_RULE_SETUP -#line 128 "cod/cod.l" +#line 126 "cod.l" {RETURN(NEQ);} YY_BREAK case 24: YY_RULE_SETUP -#line 129 "cod/cod.l" +#line 127 "cod.l" {RETURN(ASSIGN);} YY_BREAK case 25: YY_RULE_SETUP -#line 130 "cod/cod.l" +#line 128 "cod.l" {RETURN(MUL_ASSIGN);} YY_BREAK case 26: YY_RULE_SETUP -#line 131 "cod/cod.l" +#line 129 "cod.l" {RETURN(DIV_ASSIGN);} YY_BREAK case 27: YY_RULE_SETUP -#line 132 "cod/cod.l" +#line 130 "cod.l" {RETURN(MOD_ASSIGN);} YY_BREAK case 28: YY_RULE_SETUP -#line 133 "cod/cod.l" +#line 131 "cod.l" {RETURN(ADD_ASSIGN);} YY_BREAK case 29: YY_RULE_SETUP -#line 134 "cod/cod.l" +#line 132 "cod.l" {RETURN(SUB_ASSIGN);} YY_BREAK case 30: YY_RULE_SETUP -#line 135 "cod/cod.l" +#line 133 "cod.l" {RETURN(LEFT_ASSIGN);} YY_BREAK case 31: YY_RULE_SETUP -#line 136 "cod/cod.l" +#line 134 "cod.l" {RETURN(RIGHT_ASSIGN);} YY_BREAK case 32: YY_RULE_SETUP -#line 137 "cod/cod.l" +#line 135 "cod.l" {RETURN(AND_ASSIGN);} YY_BREAK case 33: YY_RULE_SETUP -#line 138 "cod/cod.l" +#line 136 "cod.l" {RETURN(XOR_ASSIGN);} YY_BREAK case 34: YY_RULE_SETUP -#line 139 "cod/cod.l" +#line 137 "cod.l" {RETURN(OR_ASSIGN);} YY_BREAK case 35: YY_RULE_SETUP -#line 140 "cod/cod.l" +#line 138 "cod.l" {RETURN(LOG_OR);} YY_BREAK case 36: YY_RULE_SETUP -#line 141 "cod/cod.l" +#line 139 "cod.l" {RETURN(LOG_AND);} YY_BREAK case 37: YY_RULE_SETUP -#line 142 "cod/cod.l" +#line 140 "cod.l" {RETURN(ARITH_OR);} YY_BREAK case 38: YY_RULE_SETUP -#line 143 "cod/cod.l" +#line 141 "cod.l" {RETURN(ARITH_AND);} YY_BREAK case 39: YY_RULE_SETUP -#line 144 "cod/cod.l" +#line 142 "cod.l" {RETURN(ARITH_XOR);} YY_BREAK case 40: YY_RULE_SETUP -#line 145 "cod/cod.l" +#line 143 "cod.l" {RETURN(INC_OP);} YY_BREAK case 41: YY_RULE_SETUP -#line 146 "cod/cod.l" +#line 144 "cod.l" {RETURN(DEC_OP);} YY_BREAK case 42: YY_RULE_SETUP -#line 147 "cod/cod.l" +#line 145 "cod.l" {RETURN(SEMI);} YY_BREAK case 43: YY_RULE_SETUP -#line 148 "cod/cod.l" +#line 146 "cod.l" {RETURN(IF);} YY_BREAK case 44: YY_RULE_SETUP -#line 149 "cod/cod.l" +#line 147 "cod.l" {RETURN(ELSE);} YY_BREAK case 45: YY_RULE_SETUP -#line 150 "cod/cod.l" +#line 148 "cod.l" {RETURN(FOR);} YY_BREAK case 46: YY_RULE_SETUP -#line 151 "cod/cod.l" +#line 149 "cod.l" {RETURN(WHILE);} YY_BREAK case 47: YY_RULE_SETUP -#line 152 "cod/cod.l" +#line 150 "cod.l" {RETURN(DO);} YY_BREAK case 48: YY_RULE_SETUP -#line 153 "cod/cod.l" +#line 151 "cod.l" {RETURN(UNSIGNED);} YY_BREAK case 49: YY_RULE_SETUP -#line 154 "cod/cod.l" +#line 152 "cod.l" {RETURN(SIGNED);} YY_BREAK case 50: YY_RULE_SETUP -#line 155 "cod/cod.l" +#line 153 "cod.l" {RETURN(SHORT);} YY_BREAK case 51: YY_RULE_SETUP -#line 156 "cod/cod.l" +#line 154 "cod.l" {RETURN(INT);} YY_BREAK case 52: YY_RULE_SETUP -#line 157 "cod/cod.l" +#line 155 "cod.l" {RETURN(LONG);} YY_BREAK case 53: YY_RULE_SETUP -#line 158 "cod/cod.l" +#line 156 "cod.l" {RETURN(CHAR);} YY_BREAK case 54: YY_RULE_SETUP -#line 159 "cod/cod.l" +#line 157 "cod.l" {RETURN(STRING);} YY_BREAK case 55: YY_RULE_SETUP -#line 160 "cod/cod.l" +#line 158 "cod.l" {RETURN(FLOAT);} YY_BREAK case 56: YY_RULE_SETUP -#line 161 "cod/cod.l" +#line 159 "cod.l" {RETURN(DOUBLE);} YY_BREAK case 57: YY_RULE_SETUP -#line 162 "cod/cod.l" +#line 160 "cod.l" {RETURN(VOID);} YY_BREAK case 58: YY_RULE_SETUP -#line 163 "cod/cod.l" +#line 161 "cod.l" {RETURN(STATIC);} YY_BREAK case 59: YY_RULE_SETUP -#line 164 "cod/cod.l" +#line 162 "cod.l" {RETURN(EXTERN_TOKEN);} YY_BREAK case 60: YY_RULE_SETUP -#line 165 "cod/cod.l" +#line 163 "cod.l" {RETURN(TYPEDEF);} YY_BREAK case 61: YY_RULE_SETUP -#line 166 "cod/cod.l" +#line 164 "cod.l" {RETURN(CONTINUE);} YY_BREAK case 62: YY_RULE_SETUP -#line 167 "cod/cod.l" +#line 165 "cod.l" {RETURN(BREAK);} YY_BREAK case 63: YY_RULE_SETUP -#line 168 "cod/cod.l" +#line 166 "cod.l" {RETURN(GOTO);} YY_BREAK case 64: YY_RULE_SETUP -#line 169 "cod/cod.l" +#line 167 "cod.l" {RETURN(CONST);} YY_BREAK case 65: YY_RULE_SETUP -#line 170 "cod/cod.l" +#line 168 "cod.l" {RETURN(SIZEOF);} YY_BREAK case 66: YY_RULE_SETUP -#line 171 "cod/cod.l" +#line 169 "cod.l" {RETURN(STRUCT);} YY_BREAK case 67: YY_RULE_SETUP -#line 172 "cod/cod.l" +#line 170 "cod.l" {RETURN(ENUM);} YY_BREAK case 68: YY_RULE_SETUP -#line 173 "cod/cod.l" +#line 171 "cod.l" {RETURN(UNION);} YY_BREAK case 69: YY_RULE_SETUP -#line 174 "cod/cod.l" +#line 172 "cod.l" {RETURN(RETURN_TOKEN);} YY_BREAK case 70: YY_RULE_SETUP -#line 175 "cod/cod.l" +#line 173 "cod.l" { int count = 0; while(types && types[count]) count++; @@ -1407,27 +1405,27 @@ YY_RULE_SETUP YY_BREAK case 71: YY_RULE_SETUP -#line 181 "cod/cod.l" +#line 179 "cod.l" {RETURN(RCURLY);} YY_BREAK case 72: YY_RULE_SETUP -#line 182 "cod/cod.l" +#line 180 "cod.l" {RETURN(BANG);} YY_BREAK case 73: YY_RULE_SETUP -#line 183 "cod/cod.l" +#line 181 "cod.l" {RETURN(COLON);} YY_BREAK case 74: YY_RULE_SETUP -#line 184 "cod/cod.l" +#line 182 "cod.l" {RETURN(QUESTION);} YY_BREAK case 75: YY_RULE_SETUP -#line 185 "cod/cod.l" +#line 183 "cod.l" { yylval.info.string = create_string_from_yytext(); if (is_defined_type(yylval.info.string)) { @@ -1441,7 +1439,7 @@ YY_RULE_SETUP YY_BREAK case 76: YY_RULE_SETUP -#line 196 "cod/cod.l" +#line 194 "cod.l" { buffer_len = 20; string_buffer = malloc(20 + 1); @@ -1450,7 +1448,7 @@ YY_RULE_SETUP YY_BREAK case 77: YY_RULE_SETUP -#line 202 "cod/cod.l" +#line 200 "cod.l" { /* saw closing quote - all done */ BEGIN(INITIAL); *string_buf_ptr = '\0'; @@ -1464,14 +1462,14 @@ YY_RULE_SETUP case 78: /* rule 78 can match eol */ YY_RULE_SETUP -#line 212 "cod/cod.l" +#line 210 "cod.l" { yyerror("Unterminated string constant"); } YY_BREAK case 79: YY_RULE_SETUP -#line 216 "cod/cod.l" +#line 214 "cod.l" { /* hex escape sequence */ int result; @@ -1488,7 +1486,7 @@ YY_RULE_SETUP YY_BREAK case 80: YY_RULE_SETUP -#line 230 "cod/cod.l" +#line 228 "cod.l" { /* octal escape sequence */ int result; @@ -1505,45 +1503,45 @@ YY_RULE_SETUP YY_BREAK case 81: YY_RULE_SETUP -#line 244 "cod/cod.l" +#line 242 "cod.l" { yyerror("bad character escape"); } YY_BREAK case 82: YY_RULE_SETUP -#line 248 "cod/cod.l" +#line 246 "cod.l" {check_strbuf();*string_buf_ptr++ = '\n';} YY_BREAK case 83: YY_RULE_SETUP -#line 249 "cod/cod.l" +#line 247 "cod.l" {check_strbuf();*string_buf_ptr++ = '\t';} YY_BREAK case 84: YY_RULE_SETUP -#line 250 "cod/cod.l" +#line 248 "cod.l" {check_strbuf();*string_buf_ptr++ = '\r';} YY_BREAK case 85: YY_RULE_SETUP -#line 251 "cod/cod.l" +#line 249 "cod.l" {check_strbuf();*string_buf_ptr++ = '\b';} YY_BREAK case 86: YY_RULE_SETUP -#line 252 "cod/cod.l" +#line 250 "cod.l" {check_strbuf();*string_buf_ptr++ = '\f';} YY_BREAK case 87: /* rule 87 can match eol */ YY_RULE_SETUP -#line 254 "cod/cod.l" +#line 252 "cod.l" {check_strbuf();*string_buf_ptr++ = yytext[1];} YY_BREAK case 88: YY_RULE_SETUP -#line 256 "cod/cod.l" +#line 254 "cod.l" { char *yptr = yytext; @@ -1555,38 +1553,38 @@ YY_RULE_SETUP YY_BREAK case 89: YY_RULE_SETUP -#line 267 "cod/cod.l" +#line 265 "cod.l" BEGIN(comment); YY_BREAK case 90: YY_RULE_SETUP -#line 269 "cod/cod.l" +#line 267 "cod.l" {lex_offset += yyleng;} /* eat anything that's not a '*' */ YY_BREAK case 91: YY_RULE_SETUP -#line 270 "cod/cod.l" +#line 268 "cod.l" {lex_offset += yyleng;} /* eat up '*'s not followed by '/'s */ YY_BREAK case 92: /* rule 92 can match eol */ YY_RULE_SETUP -#line 271 "cod/cod.l" +#line 269 "cod.l" {++line_count;lex_offset = 1;} YY_BREAK case 93: YY_RULE_SETUP -#line 272 "cod/cod.l" +#line 270 "cod.l" {lex_offset += yyleng;BEGIN(INITIAL);} YY_BREAK case 94: YY_RULE_SETUP -#line 273 "cod/cod.l" +#line 271 "cod.l" { /* consume //-comment */ } YY_BREAK case 95: YY_RULE_SETUP -#line 275 "cod/cod.l" +#line 273 "cod.l" { yylval.info.string = create_string_from_yytext(); RETURN(character_constant); @@ -1594,7 +1592,7 @@ YY_RULE_SETUP YY_BREAK case 96: YY_RULE_SETUP -#line 279 "cod/cod.l" +#line 277 "cod.l" { yylval.info.string = create_string_from_yytext(); RETURN(integer_constant); @@ -1602,7 +1600,7 @@ YY_RULE_SETUP YY_BREAK case 97: YY_RULE_SETUP -#line 283 "cod/cod.l" +#line 281 "cod.l" { yylval.info.string = create_string_from_yytext(); RETURN(integer_constant); @@ -1610,7 +1608,7 @@ YY_RULE_SETUP YY_BREAK case 98: YY_RULE_SETUP -#line 288 "cod/cod.l" +#line 286 "cod.l" { yylval.info.string = create_string_from_yytext(); RETURN(integer_constant); @@ -1618,7 +1616,7 @@ YY_RULE_SETUP YY_BREAK case 99: YY_RULE_SETUP -#line 293 "cod/cod.l" +#line 291 "cod.l" { yylval.info.string = create_string_from_yytext(); RETURN(floating_constant); @@ -1626,7 +1624,7 @@ YY_RULE_SETUP YY_BREAK case 100: YY_RULE_SETUP -#line 297 "cod/cod.l" +#line 295 "cod.l" { yylval.info.string = create_string_from_yytext(); RETURN(floating_constant); @@ -1634,7 +1632,7 @@ YY_RULE_SETUP YY_BREAK case 101: YY_RULE_SETUP -#line 301 "cod/cod.l" +#line 299 "cod.l" { yylval.info.string = create_string_from_yytext(); RETURN(floating_constant); @@ -1642,7 +1640,7 @@ YY_RULE_SETUP YY_BREAK case 102: YY_RULE_SETUP -#line 305 "cod/cod.l" +#line 303 "cod.l" { yylval.info.string = create_string_from_yytext(); RETURN(floating_constant); @@ -1650,7 +1648,7 @@ YY_RULE_SETUP YY_BREAK case 103: YY_RULE_SETUP -#line 310 "cod/cod.l" +#line 308 "cod.l" { yylval.info.string = create_string_from_yytext(); RETURN(floating_constant); @@ -1658,7 +1656,7 @@ YY_RULE_SETUP YY_BREAK case 104: YY_RULE_SETUP -#line 315 "cod/cod.l" +#line 313 "cod.l" { yylval.info.string = create_string_from_yytext(); RETURN(floating_constant); @@ -1666,21 +1664,21 @@ YY_RULE_SETUP YY_BREAK case 105: YY_RULE_SETUP -#line 320 "cod/cod.l" +#line 318 "cod.l" {lex_offset += yyleng;} YY_BREAK case 106: /* rule 106 can match eol */ YY_RULE_SETUP -#line 321 "cod/cod.l" +#line 319 "cod.l" {lex_offset = 1; line_count++;} YY_BREAK case 107: YY_RULE_SETUP -#line 322 "cod/cod.l" +#line 320 "cod.l" ECHO; YY_BREAK -#line 1684 "/Users/eisen/prog/ffs/build/lex.yy.c" +#line 1681 "lex.yy.c" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(string_cond): case YY_STATE_EOF(comment): @@ -1760,7 +1758,7 @@ case YY_STATE_EOF(comment): { (yy_did_buffer_switch_on_eof) = 0; - if ( yywrap( ) ) + if ( yywrap( ) ) { /* Note: because we've taken care in * yy_get_next_buffer() to have set up @@ -1813,6 +1811,7 @@ case YY_STATE_EOF(comment): "fatal flex scanner internal error--no action found" ); } /* end of action switch */ } /* end of scanning one token */ + } /* end of user's declarations */ } /* end of yylex */ /* yy_get_next_buffer - try to read in a new buffer @@ -1824,9 +1823,9 @@ case YY_STATE_EOF(comment): */ static int yy_get_next_buffer (void) { - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = (yytext_ptr); - register int number_to_move, i; + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = (yytext_ptr); + int number_to_move, i; int ret_val; if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) @@ -1855,7 +1854,7 @@ static int yy_get_next_buffer (void) /* Try to read more data. */ /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); @@ -1868,21 +1867,21 @@ static int yy_get_next_buffer (void) else { - yy_size_t num_to_read = + int num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) { /* Not enough room in the buffer - grow it. */ /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; int yy_c_buf_p_offset = (int) ((yy_c_buf_p) - b->yy_ch_buf); if ( b->yy_is_our_buffer ) { - yy_size_t new_size = b->yy_buf_size * 2; + int new_size = b->yy_buf_size * 2; if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size / 8; @@ -1891,11 +1890,12 @@ static int yy_get_next_buffer (void) b->yy_ch_buf = (char *) /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + yyrealloc( (void *) b->yy_ch_buf, + (yy_size_t) (b->yy_buf_size + 2) ); } else /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; + b->yy_ch_buf = NULL; if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( @@ -1923,7 +1923,7 @@ static int yy_get_next_buffer (void) if ( number_to_move == YY_MORE_ADJ ) { ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin ); + yyrestart( yyin ); } else @@ -1937,12 +1937,15 @@ static int yy_get_next_buffer (void) else ret_val = EOB_ACT_CONTINUE_SCAN; - if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ - yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( + (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + /* "- 2" to take care of EOB's */ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); } (yy_n_chars) += number_to_move; @@ -1958,14 +1961,14 @@ static int yy_get_next_buffer (void) static yy_state_type yy_get_previous_state (void) { - register yy_state_type yy_current_state; - register char *yy_cp; + yy_state_type yy_current_state; + char *yy_cp; yy_current_state = (yy_start); for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; @@ -1975,9 +1978,9 @@ static int yy_get_next_buffer (void) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 284 ) - yy_c = yy_meta[(unsigned int) yy_c]; + yy_c = yy_meta[yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; } return yy_current_state; @@ -1990,10 +1993,10 @@ static int yy_get_next_buffer (void) */ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) { - register int yy_is_jam; - register char *yy_cp = (yy_c_buf_p); + int yy_is_jam; + char *yy_cp = (yy_c_buf_p); - register YY_CHAR yy_c = 1; + YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; @@ -2003,17 +2006,19 @@ static int yy_get_next_buffer (void) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 284 ) - yy_c = yy_meta[(unsigned int) yy_c]; + yy_c = yy_meta[yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; yy_is_jam = (yy_current_state == 283); - return yy_is_jam ? 0 : yy_current_state; + return yy_is_jam ? 0 : yy_current_state; } - static void yyunput (int c, register char * yy_bp ) +#ifndef YY_NO_UNPUT + + static void yyunput (int c, char * yy_bp ) { - register char *yy_cp; + char *yy_cp; yy_cp = (yy_c_buf_p); @@ -2023,10 +2028,10 @@ static int yy_get_next_buffer (void) if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) { /* need to shift things up to make room */ /* +2 for EOB chars. */ - register yy_size_t number_to_move = (yy_n_chars) + 2; - register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + int number_to_move = (yy_n_chars) + 2; + char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - register char *source = + char *source = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) @@ -2035,7 +2040,7 @@ static int yy_get_next_buffer (void) yy_cp += (int) (dest - source); yy_bp += (int) (dest - source); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + (yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size; if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) YY_FATAL_ERROR( "flex scanner push-back overflow" ); @@ -2048,6 +2053,8 @@ static int yy_get_next_buffer (void) (yy_c_buf_p) = yy_cp; } +#endif + #ifndef YY_NO_INPUT #ifdef __cplusplus static int yyinput (void) @@ -2072,7 +2079,7 @@ static int yy_get_next_buffer (void) else { /* need more input */ - yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); + int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); ++(yy_c_buf_p); switch ( yy_get_next_buffer( ) ) @@ -2089,13 +2096,13 @@ static int yy_get_next_buffer (void) */ /* Reset buffer status. */ - yyrestart(yyin ); + yyrestart( yyin ); /*FALLTHROUGH*/ case EOB_ACT_END_OF_FILE: { - if ( yywrap( ) ) + if ( yywrap( ) ) return 0; if ( ! (yy_did_buffer_switch_on_eof) ) @@ -2133,11 +2140,11 @@ static int yy_get_next_buffer (void) if ( ! YY_CURRENT_BUFFER ){ yyensure_buffer_stack (); YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); + yy_create_buffer( yyin, YY_BUF_SIZE ); } - yy_init_buffer(YY_CURRENT_BUFFER,input_file ); - yy_load_buffer_state( ); + yy_init_buffer( YY_CURRENT_BUFFER, input_file ); + yy_load_buffer_state( ); } /** Switch to a different input buffer. @@ -2165,7 +2172,7 @@ static int yy_get_next_buffer (void) } YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); + yy_load_buffer_state( ); /* We don't actually know whether we did this switch during * EOF (yywrap()) processing, but the only time this flag @@ -2193,7 +2200,7 @@ static void yy_load_buffer_state (void) { YY_BUFFER_STATE b; - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); @@ -2202,13 +2209,13 @@ static void yy_load_buffer_state (void) /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); + b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_is_our_buffer = 1; - yy_init_buffer(b,file ); + yy_init_buffer( b, file ); return b; } @@ -2227,15 +2234,11 @@ static void yy_load_buffer_state (void) YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); + yyfree( (void *) b->yy_ch_buf ); - yyfree((void *) b ); + yyfree( (void *) b ); } -#ifndef __cplusplus -extern int isatty (int ); -#endif /* __cplusplus */ - /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. @@ -2245,7 +2248,7 @@ extern int isatty (int ); { int oerrno = errno; - yy_flush_buffer(b ); + yy_flush_buffer( b ); b->yy_input_file = file; b->yy_fill_buffer = 1; @@ -2288,7 +2291,7 @@ extern int isatty (int ); b->yy_buffer_status = YY_BUFFER_NEW; if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); + yy_load_buffer_state( ); } /** Pushes the new state onto the stack. The new state becomes @@ -2319,7 +2322,7 @@ void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) YY_CURRENT_BUFFER_LVALUE = new_buffer; /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); + yy_load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1; } @@ -2338,7 +2341,7 @@ void yypop_buffer_state (void) --(yy_buffer_stack_top); if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); + yy_load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1; } } @@ -2356,15 +2359,15 @@ static void yyensure_buffer_stack (void) * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ - num_to_alloc = 1; + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) ); if ( ! (yy_buffer_stack) ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - + (yy_buffer_stack_max) = num_to_alloc; (yy_buffer_stack_top) = 0; return; @@ -2373,7 +2376,7 @@ static void yyensure_buffer_stack (void) if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ /* Increase the buffer to prepare for a possible push. */ - int grow_size = 8 /* arbitrary grow size */; + yy_size_t grow_size = 8 /* arbitrary grow size */; num_to_alloc = (yy_buffer_stack_max) + grow_size; (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc @@ -2393,7 +2396,7 @@ static void yyensure_buffer_stack (void) * @param base the character buffer * @param size the size in bytes of the character buffer * - * @return the newly allocated buffer state object. + * @return the newly allocated buffer state object. */ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) { @@ -2403,23 +2406,23 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) base[size-2] != YY_END_OF_BUFFER_CHAR || base[size-1] != YY_END_OF_BUFFER_CHAR ) /* They forgot to leave room for the EOB's. */ - return 0; + return NULL; - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ b->yy_buf_pos = b->yy_ch_buf = base; b->yy_is_our_buffer = 0; - b->yy_input_file = 0; + b->yy_input_file = NULL; b->yy_n_chars = b->yy_buf_size; b->yy_is_interactive = 0; b->yy_at_bol = 1; b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; - yy_switch_to_buffer(b ); + yy_switch_to_buffer( b ); return b; } @@ -2432,28 +2435,29 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) * @note If you want to scan bytes that may contain NUL values, then use * yy_scan_bytes() instead. */ -YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) +YY_BUFFER_STATE yy_scan_string (const char * yystr ) { - return yy_scan_bytes(yystr,strlen(yystr) ); + return yy_scan_bytes( yystr, (int) strlen(yystr) ); } /** Setup the input buffer state to scan the given bytes. The next call to yylex() will * scan from a @e copy of @a bytes. - * @param bytes the byte buffer to scan - * @param len the number of bytes in the buffer pointed to by @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. * * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) +YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) { YY_BUFFER_STATE b; char *buf; - yy_size_t n, i; + yy_size_t n; + int i; /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; - buf = (char *) yyalloc(n ); + n = (yy_size_t) (_yybytes_len + 2); + buf = (char *) yyalloc( n ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); @@ -2462,7 +2466,7 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - b = yy_scan_buffer(buf,n ); + b = yy_scan_buffer( buf, n ); if ( ! b ) YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); @@ -2478,9 +2482,9 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len #define YY_EXIT_FAILURE 2 #endif -static void yy_fatal_error (yyconst char* msg ) +static void yynoreturn yy_fatal_error (const char* msg ) { - (void) fprintf( stderr, "%s\n", msg ); + fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); } @@ -2508,7 +2512,7 @@ static void yy_fatal_error (yyconst char* msg ) */ int yyget_lineno (void) { - + return yylineno; } @@ -2531,7 +2535,7 @@ FILE *yyget_out (void) /** Get the length of the current token. * */ -yy_size_t yyget_leng (void) +int yyget_leng (void) { return yyleng; } @@ -2546,29 +2550,29 @@ char *yyget_text (void) } /** Set the current line number. - * @param line_number + * @param _line_number line number * */ -void yyset_lineno (int line_number ) +void yyset_lineno (int _line_number ) { - yylineno = line_number; + yylineno = _line_number; } /** Set the input stream. This does not discard the current * input buffer. - * @param in_str A readable stream. + * @param _in_str A readable stream. * * @see yy_switch_to_buffer */ -void yyset_in (FILE * in_str ) +void yyset_in (FILE * _in_str ) { - yyin = in_str ; + yyin = _in_str ; } -void yyset_out (FILE * out_str ) +void yyset_out (FILE * _out_str ) { - yyout = out_str ; + yyout = _out_str ; } int yyget_debug (void) @@ -2576,9 +2580,9 @@ int yyget_debug (void) return yy_flex_debug; } -void yyset_debug (int bdebug ) +void yyset_debug (int _bdebug ) { - yy_flex_debug = bdebug ; + yy_flex_debug = _bdebug ; } static int yy_init_globals (void) @@ -2587,10 +2591,10 @@ static int yy_init_globals (void) * This function is called from yylex_destroy(), so don't allocate here. */ - (yy_buffer_stack) = 0; + (yy_buffer_stack) = NULL; (yy_buffer_stack_top) = 0; (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = (char *) 0; + (yy_c_buf_p) = NULL; (yy_init) = 0; (yy_start) = 0; @@ -2599,8 +2603,8 @@ static int yy_init_globals (void) yyin = stdin; yyout = stdout; #else - yyin = (FILE *) 0; - yyout = (FILE *) 0; + yyin = NULL; + yyout = NULL; #endif /* For future reference: Set errno on error, since we are called by @@ -2615,7 +2619,7 @@ int yylex_destroy (void) /* Pop the buffer stack, destroying each element. */ while(YY_CURRENT_BUFFER){ - yy_delete_buffer(YY_CURRENT_BUFFER ); + yy_delete_buffer( YY_CURRENT_BUFFER ); YY_CURRENT_BUFFER_LVALUE = NULL; yypop_buffer_state(); } @@ -2636,18 +2640,19 @@ int yylex_destroy (void) */ #ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +static void yy_flex_strncpy (char* s1, const char * s2, int n ) { - register int i; + + int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; } #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) +static int yy_flex_strlen (const char * s ) { - register int n; + int n; for ( n = 0; s[n]; ++n ) ; @@ -2657,11 +2662,12 @@ static int yy_flex_strlen (yyconst char * s ) void *yyalloc (yy_size_t size ) { - return (void *) malloc( size ); + return malloc(size); } void *yyrealloc (void * ptr, yy_size_t size ) { + /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter @@ -2669,18 +2675,17 @@ void *yyrealloc (void * ptr, yy_size_t size ) * any pointer type to void*, and deal with argument conversions * as though doing an assignment. */ - return (void *) realloc( (char *) ptr, size ); + return realloc(ptr, size); } void yyfree (void * ptr ) { - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" -#line 322 "cod/cod.l" - +#line 320 "cod.l" static char *create_string_from_yytext() { @@ -2691,7 +2696,7 @@ static char *create_string_from_yytext() static void check_strbuf() { - int cur_len = string_buf_ptr - string_buffer; + intptr_t cur_len = string_buf_ptr - string_buffer; if ((cur_len + 1) == buffer_len) { buffer_len += 20; string_buffer = realloc(string_buffer, buffer_len + 1); @@ -2791,19 +2796,14 @@ char **enum_constants; static YY_BUFFER_STATE bb = NULL; static void -reset_types_table(defined_types, enumerated_constants) -char **defined_types; -char **enumerated_constants; +reset_types_table(char **defined_types, char **enumerated_constants) { types = defined_types; enums = enumerated_constants; } static void -setup_for_string_parse(string, defined_types, enum_constants) -const char *string; -char **defined_types; -char **enum_constants; +setup_for_string_parse(const char *string, char **defined_types, char **enum_constants) { types = defined_types; enums = enum_constants; diff --git a/cod/standard.c b/cod/standard.c index 194dad6f09..2735741153 100644 --- a/cod/standard.c +++ b/cod/standard.c @@ -22,18 +22,17 @@ #include "structs.h" #undef NDEBUG #include "assert.h" -#ifndef LINUX_KERNEL_MODULE #include #ifdef HAVE_MALLOC_H #include #endif #include + +#ifndef _MSC_VER +#include #else -#include -#include -#include +#define strdup _strdup #endif -#include #ifndef LINUX_KERNEL_MODULE #ifdef HAVE_ATL_H #include "atl.h" @@ -122,11 +121,11 @@ attr_ivalue(attr_list l, char *name) return i; } -static long +static ssize_t attr_lvalue(attr_list l, char *name) { atom_t atom = attr_atom_from_string(name); - long lo = 0; + ssize_t lo = 0; if (atom == 0 ) return 0; get_long_attr(l, atom, &lo); @@ -183,21 +182,54 @@ static void close_ffs_file(FFSFile fname) close_FFSfile(fname); } -int -gettimeofday_wrapper(struct timeval * tp) -{ - int ret = gettimeofday(tp, NULL); - return ret; -} - - -#include typedef struct chr_time { double d1; double d2; double d3; } chr_time; +#ifdef _MSC_VER +#include +#include // portable: uint64_t MSVC: __int64 + +#ifndef _WINSOCKAPI_ +// MSVC defines this in winsock2.h!? +typedef struct timeval { + long tv_sec; + long tv_usec; +} timeval; +#endif + +int gettimeofday(struct timeval* tp, struct timezone* tzp) +{ + // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's + // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC) + // until 00:00:00 January 1, 1970 + static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL); + + SYSTEMTIME system_time; + FILETIME file_time; + uint64_t time; + + GetSystemTime(&system_time); + SystemTimeToFileTime(&system_time, &file_time); + time = ((uint64_t)file_time.dwLowDateTime); + time += ((uint64_t)file_time.dwHighDateTime) << 32; + + tp->tv_sec = (long)((time - EPOCH) / 10000000L); + tp->tv_usec = (long)(system_time.wMilliseconds * 1000); + return 0; +} +#else +#include +#endif + +int +gettimeofday_wrapper(struct timeval* tp) +{ + int ret = gettimeofday(tp, NULL); + return ret; +} static void chr_get_time( chr_time *time) @@ -347,35 +379,35 @@ static cod_extern_entry internal_externs[] = static cod_extern_entry externs[] = { #ifdef HAVE_ATL_H - {"attr_set", (void*)(long)attr_set}, - {"create_attr_list", (void*)(long)attr_create_list}, - {"copy_attr_list", (void*)(long)attr_copy_list}, - {"free_attr_list", (void*)(long)attr_free_list}, - {"set_int_attr", (void*)(long)std_set_int_attr}, - {"set_long_attr", (void*)(long)std_set_long_attr}, - {"set_double_attr", (void*)(long)std_set_double_attr}, - {"set_float_attr", (void*)(long)std_set_float_attr}, - {"set_string_attr", (void*)(long)std_set_string_attr}, - {"attr_ivalue", (void*)(long)attr_ivalue}, - {"attr_lvalue", (void*)(long)attr_lvalue}, - {"attr_dvalue", (void*)(long)attr_dvalue}, - {"attr_fvalue", (void*)(long)attr_fvalue}, - {"attr_svalue", (void*)(long)attr_svalue}, + {"attr_set", (void*)(intptr_t)attr_set}, + {"create_attr_list", (void*)(intptr_t)attr_create_list}, + {"copy_attr_list", (void*)(intptr_t)attr_copy_list}, + {"free_attr_list", (void*)(intptr_t)attr_free_list}, + {"set_int_attr", (void*)(intptr_t)std_set_int_attr}, + {"set_long_attr", (void*)(intptr_t)std_set_long_attr}, + {"set_double_attr", (void*)(intptr_t)std_set_double_attr}, + {"set_float_attr", (void*)(intptr_t)std_set_float_attr}, + {"set_string_attr", (void*)(intptr_t)std_set_string_attr}, + {"attr_ivalue", (void*)(intptr_t)attr_ivalue}, + {"attr_lvalue", (void*)(intptr_t)attr_lvalue}, + {"attr_dvalue", (void*)(intptr_t)attr_dvalue}, + {"attr_fvalue", (void*)(intptr_t)attr_fvalue}, + {"attr_svalue", (void*)(intptr_t)attr_svalue}, #endif - {"chr_get_time", (void*)(long)chr_get_time}, - {"chr_timer_diff", (void*)(long)chr_timer_diff}, - {"chr_timer_eq_zero", (void*)(long)chr_timer_eq_zero}, - {"chr_timer_sum", (void*)(long)chr_timer_sum}, - {"chr_timer_start", (void*)(long)chr_timer_start}, - {"chr_timer_stop", (void*)(long)chr_timer_stop}, - {"chr_time_to_nanosecs", (void*)(long)chr_time_to_nanosecs}, - {"chr_time_to_microsecs", (void*)(long)chr_time_to_microsecs}, - {"chr_time_to_millisecs", (void*)(long)chr_time_to_millisecs}, - {"chr_time_to_secs", (void*)(long)chr_time_to_secs}, - {"chr_approx_resolution", (void*)(long)chr_approx_resolution}, - {"gettimeofday", (void*)(long)gettimeofday_wrapper}, - {"open_ffs", (void*)(long)open_ffs_file}, - {"close_ffs", (void*)(long)close_ffs_file}, + {"chr_get_time", (void*)(intptr_t)chr_get_time}, + {"chr_timer_diff", (void*)(intptr_t)chr_timer_diff}, + {"chr_timer_eq_zero", (void*)(intptr_t)chr_timer_eq_zero}, + {"chr_timer_sum", (void*)(intptr_t)chr_timer_sum}, + {"chr_timer_start", (void*)(intptr_t)chr_timer_start}, + {"chr_timer_stop", (void*)(intptr_t)chr_timer_stop}, + {"chr_time_to_nanosecs", (void*)(intptr_t)chr_time_to_nanosecs}, + {"chr_time_to_microsecs", (void*)(intptr_t)chr_time_to_microsecs}, + {"chr_time_to_millisecs", (void*)(intptr_t)chr_time_to_millisecs}, + {"chr_time_to_secs", (void*)(intptr_t)chr_time_to_secs}, + {"chr_approx_resolution", (void*)(intptr_t)chr_approx_resolution}, + {"gettimeofday", (void*)(intptr_t)gettimeofday_wrapper}, + {"open_ffs", (void*)(intptr_t)open_ffs_file}, + {"close_ffs", (void*)(intptr_t)close_ffs_file}, {(void*)0, (void*)0} }; @@ -433,35 +465,35 @@ cod_add_standard_elements(cod_parse_context context) #endif /* LINUX_KERNEL_MODULE */ #if NO_DYNAMIC_LINKING -#define sym(x) (void*)(long)x +#define sym(x) (void*)(intptr_t)x #else #define sym(x) (void*)0 #endif static cod_extern_entry string_externs[] = { - {"memchr", (void*)(long)memchr}, - {"memcmp", (void*)(long)memcmp}, - {"memcpy", (void*)(long)memcpy}, - {"memmove", (void*)(long)memmove}, - {"memset", (void*)(long)memset}, - {"strcat", (void*)(long)strcat}, - {"strchr", (void*)(long)strchr}, - {"strcmp", (void*)(long)strcmp}, - {"strcoll", (void*)(long)strcoll}, - {"strcpy", (void*)(long)strcpy}, - {"strcspn", (void*)(long)strcspn}, - {"strerror", (void*)(long)strerror}, - {"strlen", (void*)(long)strlen}, - {"strncat", (void*)(long)strncat}, - {"strncmp", (void*)(long)strncmp}, - {"strncpy", (void*)(long)strncpy}, - {"strpbrk", (void*)(long)strpbrk}, - {"strrchr", (void*)(long)strrchr}, - {"strspn", (void*)(long)strspn}, - {"strstr", (void*)(long)strstr}, - {"strtok", (void*)(long)strtok}, - {"strxfrm", (void*)(long)strxfrm}, + {"memchr", (void*)(intptr_t)memchr}, + {"memcmp", (void*)(intptr_t)memcmp}, + {"memcpy", (void*)(intptr_t)memcpy}, + {"memmove", (void*)(intptr_t)memmove}, + {"memset", (void*)(intptr_t)memset}, + {"strcat", (void*)(intptr_t)strcat}, + {"strchr", (void*)(intptr_t)strchr}, + {"strcmp", (void*)(intptr_t)strcmp}, + {"strcoll", (void*)(intptr_t)strcoll}, + {"strcpy", (void*)(intptr_t)strcpy}, + {"strcspn", (void*)(intptr_t)strcspn}, + {"strerror", (void*)(intptr_t)strerror}, + {"strlen", (void*)(intptr_t)strlen}, + {"strncat", (void*)(intptr_t)strncat}, + {"strncmp", (void*)(intptr_t)strncmp}, + {"strncpy", (void*)(intptr_t)strncpy}, + {"strpbrk", (void*)(intptr_t)strpbrk}, + {"strrchr", (void*)(intptr_t)strrchr}, + {"strspn", (void*)(intptr_t)strspn}, + {"strstr", (void*)(intptr_t)strstr}, + {"strtok", (void*)(intptr_t)strtok}, + {"strxfrm", (void*)(intptr_t)strxfrm}, {NULL, NULL} }; @@ -491,14 +523,16 @@ int strxfrm(char *s1, const char *s2, int size);\n\ static cod_extern_entry strings_externs[] = { - {"bcmp", (void*)(long)bcmp}, - {"bcopy", (void*)(long)bcopy}, - {"bzero", (void*)(long)bzero}, - {"index", (void*)(long)index}, - {"rindex", (void*)(long)rindex}, - {"ffs", (void*)(long)ffs}, - {"strcasecmp", (void*)(long)strcasecmp}, - {"strncasecmp", (void*)(long)strncasecmp}, +#ifndef _MSC_VER + {"bcmp", (void*)(intptr_t)bcmp}, + {"bcopy", (void*)(intptr_t)bcopy}, + {"bzero", (void*)(intptr_t)bzero}, + {"index", (void*)(intptr_t)index}, + {"rindex", (void*)(intptr_t)rindex}, + {"ffs", (void*)(intptr_t)ffs}, + {"strcasecmp", (void*)(intptr_t)strcasecmp}, + {"strncasecmp", (void*)(intptr_t)strncasecmp}, +#endif {NULL, NULL} }; @@ -651,7 +685,7 @@ static void dlload_externs(char *libname, cod_extern_entry *externs); extern void cod_process_include(char *name, cod_parse_context context) { - int char_count = index(name, '.') - name; + intptr_t char_count = strchr(name, '.') - name; if (char_count < 0) char_count = strlen(name); if (strncmp(name, "string", char_count) == 0) { cod_assoc_externs(context, string_externs); @@ -668,7 +702,10 @@ cod_process_include(char *name, cod_parse_context context) } } +#if !NO_DYNAMIC_LINKING #include +#endif + static void dlload_externs(char *libname, cod_extern_entry *externs) { diff --git a/cod/struct.pl b/cod/struct.pl index ec6ace2276..056fa056cb 100755 --- a/cod/struct.pl +++ b/cod/struct.pl @@ -284,7 +284,7 @@ sub gen_copy { sub gen_srcpos { my($houtfile, $coutfile) = @_; print $houtfile "extern srcpos cod_get_srcpos(sm_ref expr);\n"; - print $coutfile "extern srcpos cod_get_srcpos(expr)\nsm_ref expr;\n{\n"; + print $coutfile "extern srcpos cod_get_srcpos(sm_ref expr)\n{\n"; print $coutfile " switch(expr->node_type) {\n"; foreach my $name (@display_order) { foreach my $field ( @{$structs{$name}->{order}} ) { diff --git a/cod/tests/atl_test.c b/cod/tests/atl_test.c index bb570d7548..0b53d97cfe 100644 --- a/cod/tests/atl_test.c +++ b/cod/tests/atl_test.c @@ -7,6 +7,7 @@ #include #include +#include #ifndef HAVE_ATL_H int main() @@ -37,7 +38,7 @@ main(int argc, char **argv) static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; /* test external call */ @@ -65,7 +66,7 @@ main(int argc, char **argv) cod_subroutine_declaration("int proc(attr_list l)", context); gen_code = cod_code_gen(code, context); - func = (int (*)(attr_list))(long)gen_code->func; + func = (int (*)(attr_list))(intptr_t)gen_code->func; if ((func)(l) != 15) { printf("Function didn't return 15\n"); @@ -76,7 +77,7 @@ main(int argc, char **argv) cod_subroutine_declaration("int proc(attr_list l)", context2); gen_code = cod_code_gen(code, context2); - func = (int (*)(attr_list))(long)gen_code->func; + func = (int (*)(attr_list))(intptr_t)gen_code->func; if ((func)(l) != 15) { printf("Function didn't return 15\n"); @@ -91,7 +92,7 @@ main(int argc, char **argv) static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {"l", (void*) 0}, {(void*)0, (void*)0} }; @@ -121,7 +122,7 @@ main(int argc, char **argv) cod_subroutine_declaration("int proc()", context); gen_code = cod_code_gen(code, context); - func = (int (*)(attr_list))(long)gen_code->func; + func = (int (*)(attr_list))(intptr_t)gen_code->func; if ((func)(l) != 15) { printf("Function didn't return 15\n"); @@ -138,7 +139,7 @@ main(int argc, char **argv) static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; /* test external call */ @@ -160,7 +161,7 @@ main(int argc, char **argv) cod_subroutine_declaration("int proc(attr_list l[], int i)", context); gen_code = cod_code_gen(code, context); - func = (int (*)(attr_list*, int))(long)gen_code->func; + func = (int (*)(attr_list*, int))(intptr_t)gen_code->func; l[0] = create_attr_list(); set_attr(l[0], attr_atom_from_string("test_value"), Attr_Int4, (attr_value)15); @@ -185,7 +186,7 @@ main(int argc, char **argv) static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; /* test external call */ @@ -212,7 +213,7 @@ main(int argc, char **argv) cod_subroutine_declaration("double proc(int limit)", context); gen_code = cod_code_gen(code, context); - func = (double (*)(int))(long)gen_code->func; + func = (double (*)(int))(intptr_t)gen_code->func; big = (func)(1000000); little = (func)(10000); diff --git a/cod/tests/compound_assignment.c b/cod/tests/compound_assignment.c index 119ea760f0..eaf248fa08 100644 --- a/cod/tests/compound_assignment.c +++ b/cod/tests/compound_assignment.c @@ -2,6 +2,7 @@ #include "cod.h" #include #include +#include #include #define assert(EX) ((EX) ? (void)0 : (fprintf(stderr, "\"%s\" failed, file %s, line %d\n", #EX, __FILE__, __LINE__), exit(1))) @@ -19,6 +20,8 @@ cod_add_param("ec", "cod_exec_context", 0, x);\ if (output_file) cod_set_error_func(x, error_func); #define EC_param0 ec #define EC_param1 ec, +#define EC_param0_decl cod_exec_context +#define EC_param1_decl cod_exec_context, #endif static int verbose = 0; @@ -71,19 +74,19 @@ main(int argc, char **argv) static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; cod_code gen_code; long ret; - long (*func)(); + long (*func)(EC_param0_decl); GEN_PARSE_CONTEXT(context); cod_assoc_externs(context, externs); cod_parse_for_context(extern_string, context); gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; ret = func(EC_param0); assert(ret == 19); ret = func(EC_param0); @@ -114,19 +117,19 @@ main(int argc, char **argv) static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; cod_code gen_code; long ret; - long (*func)(); + long (*func)(EC_param0_decl); GEN_PARSE_CONTEXT(context); cod_assoc_externs(context, externs); cod_parse_for_context(extern_string, context); gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; ret = func(EC_param0); assert(ret == 524); ret = func(EC_param0); @@ -155,19 +158,19 @@ main(int argc, char **argv) static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; cod_code gen_code; long ret; - long (*func)(); + long (*func)(EC_param0_decl); GEN_PARSE_CONTEXT(context); cod_assoc_externs(context, externs); cod_parse_for_context(extern_string, context); gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; ret = func(EC_param0); assert(ret == 0x1159e24 + 0x1159e2); ret = func(EC_param0); @@ -202,19 +205,19 @@ printf(\"after q = %x, r = %x, s = %x\\n\", q, r, s);\n\ static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; cod_code gen_code; long ret; - long (*func)(); + long (*func)(EC_param0_decl); GEN_PARSE_CONTEXT(context); cod_assoc_externs(context, externs); cod_parse_for_context(extern_string, context); gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; ret = func(EC_param0); assert(ret == 0x8c + 0x6776 + 0x6802); ret = func(EC_param0); diff --git a/cod/tests/control.c b/cod/tests/control.c index 6a876c25be..5d0497c5f3 100644 --- a/cod/tests/control.c +++ b/cod/tests/control.c @@ -2,6 +2,7 @@ #include "data_funcs.h" #include "cod.h" #include +#include #include #include @@ -19,6 +20,8 @@ x = new_cod_parse_context();\ cod_add_param("ec", "cod_exec_context", 0, x); #define EC_param0 ec #define EC_param1 ec, +#define EC_param0_decl cod_exec_context +#define EC_param1_decl cod_exec_context, #endif extern void @@ -48,7 +51,7 @@ main(int argc, char**argv) static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; char code_string[] = "\ @@ -68,7 +71,7 @@ main(int argc, char**argv) cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); @@ -77,7 +80,7 @@ main(int argc, char**argv) gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == 17); @@ -91,7 +94,7 @@ main(int argc, char**argv) static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; char code_string[] = "\ @@ -109,7 +112,7 @@ top:\n\ cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); @@ -118,7 +121,7 @@ top:\n\ gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == 20); @@ -132,7 +135,7 @@ top:\n\ static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; char code_string[] = "\ @@ -147,7 +150,7 @@ top:\n\ cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); @@ -156,7 +159,7 @@ top:\n\ gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == 11); @@ -170,7 +173,7 @@ top:\n\ static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; char code_string[] = "\ @@ -191,7 +194,7 @@ top:\n\ cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); @@ -200,7 +203,7 @@ top:\n\ gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == 420); @@ -214,7 +217,7 @@ top:\n\ static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; char code_string[] = "\ @@ -235,7 +238,7 @@ top:\n\ cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); @@ -244,7 +247,7 @@ top:\n\ gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == 420); @@ -258,7 +261,7 @@ top:\n\ static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; char code_string[] = "\ @@ -279,7 +282,7 @@ top:\n\ cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); @@ -288,7 +291,7 @@ top:\n\ gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == 420); @@ -305,9 +308,9 @@ top:\n\ static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, - {"EVdiscard", (void*)(long)discard}, - {"EVcount", (void*)(long)count}, + {"printf", (void*)(intptr_t)printf}, + {"EVdiscard", (void*)(intptr_t)discard}, + {"EVcount", (void*)(intptr_t)count}, {(void*)0, (void*)0} }; char code_string[] = "\ @@ -321,7 +324,7 @@ top:\n\ cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); @@ -332,7 +335,7 @@ top:\n\ gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == 5 + 7 + 9); @@ -346,7 +349,7 @@ top:\n\ static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; char code_string[] = "\ @@ -361,7 +364,7 @@ top:\n\ cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); @@ -370,7 +373,7 @@ top:\n\ gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == 42); diff --git a/cod/tests/data_funcs.c b/cod/tests/data_funcs.c index 10114efb49..0774019e5d 100644 --- a/cod/tests/data_funcs.c +++ b/cod/tests/data_funcs.c @@ -1,10 +1,21 @@ #include "config.h" #include "fm.h" #include +#include #include #include #include +#ifdef HAVE_UNISTD_H #include +#endif +#include +#include + +#ifdef _MSC_VER +#define read(x,y,z) _read(x,y,z) +#define open(x,y,z) _open(x,y,z) +#include +#endif #define MAGIC 0x4356ffaa /* random magic */ #define assert(EX) ((EX) ? (void)0 : (fprintf(stderr, "\"%s\" failed, file %s, line %d\n", #EX, __FILE__, __LINE__), exit(1))) @@ -48,9 +59,7 @@ write_buffer(char *filename, FMStructDescList desc, void *data, } static void -byte_swap(data, size) -char *data; -int size; +byte_swap(char *data, int size) { int i; assert((size % 2) == 0); @@ -103,7 +112,7 @@ char *read_buffer(FMContext c, char *read_file, int test_num) static int data_test_num = -1; char *buf; if (f == 0) { - int in_magic; + int in_magic = 0; f = open(read_file, O_RDONLY, 0777); if(read(f, &in_magic, 4) != 4) exit(1); if (in_magic != MAGIC) { diff --git a/cod/tests/data_funcs.h b/cod/tests/data_funcs.h index 46a5f2bcf4..45c1500284 100644 --- a/cod/tests/data_funcs.h +++ b/cod/tests/data_funcs.h @@ -1,4 +1,7 @@ #include "fm.h" +#ifdef _MSC_VER +#define strdup(s) _strdup(s) +#endif extern void write_buffer(char *filename, FMStructDescList desc, void *data, int test_num); diff --git a/cod/tests/general.ops b/cod/tests/general.ops index f8cfdb4f92..a3a2d588f7 100644 --- a/cod/tests/general.ops +++ b/cod/tests/general.ops @@ -5,9 +5,10 @@ sub upperc { return $_; } -%c_types = ('c', 'signed char', 'uc', 'unsigned char', 's', 'short', 'us', 'unsigned short', 'i', 'int', 'u', 'unsigned int', 'l', 'long', 'ul', 'unsigned long', 'p', 'char*', 'f', 'float', 'd', 'double'); -%rand_types = ('c', 'l', 'uc', 'l', 's', 'l', 'us', 'l', 'i', 'l', 'u', 'l', 'l', 'l', 'ul', 'l', 'p', '(char *)l', 'f', 'd', 'd', 'd'); -%c_print_formats = ('c', '%d', 'uc', '%u', 's', '%d', 'us', '%u', 'i', '%d', 'u', '%u', 'l', '%ld', 'ul', '%lu', 'p', '%lx', 'f', '%g', 'd', '%g'); +%c_types = ('c', 'signed char', 'uc', 'unsigned char', 's', 'short', 'us', 'unsigned short', 'i', 'int', 'u', 'unsigned int', 'l', 'intptr_t', 'ul', 'uintptr_t', 'p', 'char*', 'f', 'float', 'd', 'double'); +%cod_types = ('c', 'signed char', 'uc', 'unsigned char', 's', 'short', 'us', 'unsigned short', 'i', 'int', 'u', 'unsigned int', 'l', 'long', 'ul', 'unsigned long', 'p', 'char*', 'f', 'float', 'd', 'double'); +%rand_types = ('c', 'l', 'uc', 'l', 's', 'l', 'us', 'l', 'i', 'l', 'u', 'l', 'l', 'l', 'ul', 'l', 'p', '(intptr_t)l', 'f', 'd', 'd', 'd'); +%c_print_formats = ('c', '%d', 'uc', '%u', 's', '%d', 'us', '%u', 'i', '%d', 'u', '%u', 'l', '%zd', 'ul', '%zu', 'p', '%lx', 'f', '%g', 'd', '%g'); %drisc_arg_formats = ('c', '%i', 'uc', '%u', 's', '%i', 'us', '%u', 'i', '%i', 'u', '%u', 'l', '%l', 'ul', '%ul', 'p', '%p', 'f', '%f', 'd', '%d'); %type_masks = ('c', "f", 'uc', "f", 's', "f ff fff", 'us', "f ff fff", 'i', "f ff fff ffff fffff ffffff fffffff", 'u', "f ff fff ffff fffff ffffff fffffff", 'l', "f ff fff ffff fffff ffffff fffffff", 'ul', "f ff fff ffff fffff ffffff fffffff"); @@ -77,7 +78,9 @@ sub arith_insn { foreach(split(' ', $type_list)) { $t2 = ${_}; $c_type1 = $c_types{$t1}; + $cod_type1 = $cod_types{$t1}; $c_type2 = $c_types{$t2}; + $cod_type2 = $cod_types{$t2}; $c_pformat1 = $c_print_formats{$t1}; $c_pformat2 = $c_print_formats{$t2}; $line = __LINE__ + 3; @@ -132,6 +135,9 @@ sub arith_insn { if (($t1 eq "uc") || ($t1 eq "us") || ($t1 eq "u") || ($t1 eq "ul")) { $result_if = "if ((expected_result == 0) || (expected_result == ($c_type1) 0x$type_max{$t1}) || (expected_result == ($c_type1) 0x$type_max2{$t1})) continue;\n $result_if"; } + if (($t1 eq "ul") && (($t2 eq "d") || ($t2 eq "f"))) { + $result_if = "if (source1_ul > ((ssize_t)11<<52)) continue;\n $result_if"; + } if (($t1 eq "uc") && ($c_op eq "/")) { $range_decl .= "\n unsigned int expect_int;"; $div_continue .= "\n expect_int = (unsigned int) $expected_value;"; @@ -142,8 +148,8 @@ print COUT<func; + proc = ($c_type1 (*)($c_type1, $c_type2))(intptr_t)gen_code->func; for (i=0 ; i < sizeof($vals1)/sizeof($vals1\[0\]) ; i++) { @@ -814,6 +820,7 @@ print COUT< #include "string.h" #include "math.h" @@ -823,6 +830,10 @@ print COUT< +typedef SSIZE_T ssize_t; +#endif #else extern double drand48(); extern long lrand48(); @@ -944,7 +955,7 @@ EOF print COUT " br_src${dr_type}_vals[5] = ($c_type) -((long)rand1_$dr_type) - 1;\n"; } print COUT " externs[0].extern_name = \"printf\";\n"; - print COUT " externs[0].extern_value = (void*)(long)printf;\n"; + print COUT " externs[0].extern_value = (void*)(intptr_t)printf;\n"; print COUT " externs[1].extern_name = (void*)0;\n"; print COUT " externs[1].extern_value = (void*)0;\n"; print COUT "}\n"; diff --git a/cod/tests/gray.c b/cod/tests/gray.c index 463df677f5..3e9ed3f5da 100644 --- a/cod/tests/gray.c +++ b/cod/tests/gray.c @@ -2,6 +2,7 @@ #include "cod.h" #include #include +#include #define assert(EX) ((EX) ? (void)0 : (fprintf(stderr, "\"%s\" failed, file %s, line %d\n", #EX, __FILE__, __LINE__), exit(1))) @@ -66,7 +67,7 @@ void doOneTest(void (*f)(), int step) */ func = (long (*)(unsigned char *, unsigned char *, unsigned long, unsigned long, - unsigned char *)) (long) f; + unsigned char *)) (intptr_t) f; /* pre-clear the output buffer */ for(p=output; p < output + sizeof(output); ) *p++ = 0x0; @@ -91,8 +92,8 @@ void doOneTest(void (*f)(), int step) } /* first, the easy size check */ - if (result != sizeof(gray)) { printf("result is %ld, not %ld\n", result, - (long)sizeof(gray));} + if (result != sizeof(gray)) { printf("result is %ld, not %zu\n", result, + sizeof(gray));} assert(result == sizeof(gray)); /* then compare the whole image w/ expected gray */ @@ -180,7 +181,7 @@ main(int argc, char **argv) static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; diff --git a/cod/tests/mix.c b/cod/tests/mix.c index 93837f5b25..82911462f4 100644 --- a/cod/tests/mix.c +++ b/cod/tests/mix.c @@ -1,6 +1,7 @@ #include "config.h" #include "cod.h" #include +#include #define IMGDEBUG diff --git a/cod/tests/strings.c b/cod/tests/strings.c index 6deed13038..1d2da8351b 100644 --- a/cod/tests/strings.c +++ b/cod/tests/strings.c @@ -2,6 +2,7 @@ #include "cod.h" #include #include +#include #include #ifdef HAVE_MALLOC_H #include @@ -30,10 +31,10 @@ char *strstr(char* s1, char *s2);\n\ void free(void *pointer);\n"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, - {"malloc", (void*)(long)malloc}, - {"strstr", (void*)(long)strstr}, - {"free", (void*)(long)free}, + {"printf", (void*)(intptr_t)printf}, + {"malloc", (void*)(intptr_t)malloc}, + {"strstr", (void*)(intptr_t)strstr}, + {"free", (void*)(intptr_t)free}, {(void*)0, (void*)0} }; cod_parse_context context = new_cod_parse_context(); @@ -48,7 +49,7 @@ void free(void *pointer);\n"; if (gen_code == NULL) { printf("Code generation failed for test 2\n"); } else { - func = (char*(*)(char*)) (long) gen_code->func; + func = (char*(*)(char*)) (intptr_t) gen_code->func; result = func("I'd really like a cream soda please!"); assert(strcmp("soda please!", result) == 0); cod_code_free(gen_code); diff --git a/cod/tests/structs.c b/cod/tests/structs.c index d9d9788ef6..7af5718d69 100644 --- a/cod/tests/structs.c +++ b/cod/tests/structs.c @@ -8,6 +8,7 @@ #include "data_funcs.h" #include "cod.h" #include +#include #include #include @@ -17,12 +18,16 @@ static int verbose = 0; x = new_cod_parse_context(); #define EC_param0 #define EC_param1 +#define EC_param0_decl +#define EC_param1_decl #else #define GEN_PARSE_CONTEXT(x) \ x = new_cod_parse_context();\ cod_add_param("ec", "cod_exec_context", 0, x); #define EC_param0 ec #define EC_param1 ec, +#define EC_param0_decl cod_exec_context +#define EC_param1_decl cod_exec_context, #endif #define assert(EX) ((EX) ? (void)0 : (fprintf(stderr, "\"%s\" failed, file %s, line %d\n", #EX, __FILE__, __LINE__), exit(1))) @@ -62,13 +67,13 @@ main(int argc, char**argv) cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == 4); @@ -93,13 +98,13 @@ main(int argc, char**argv) cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == 4); @@ -126,13 +131,13 @@ main(int argc, char**argv) cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == 4); diff --git a/cod/tests/t1.c b/cod/tests/t1.c index aa48bd7cfc..194d005822 100644 --- a/cod/tests/t1.c +++ b/cod/tests/t1.c @@ -8,6 +8,7 @@ #include "data_funcs.h" #include "cod.h" #include +#include #include #include @@ -17,12 +18,16 @@ static int verbose = 0; x = new_cod_parse_context(); #define EC_param0 #define EC_param1 +#define EC_param0_decl +#define EC_param1_decl #else #define GEN_PARSE_CONTEXT(x) \ x = new_cod_parse_context();\ cod_add_param("ec", "cod_exec_context", 0, x); #define EC_param0 ec #define EC_param1 ec, +#define EC_param0_decl cod_exec_context ec +#define EC_param1_decl cod_exec_context ec, #endif #define assert(EX) ((EX) ? (void)0 : (fprintf(stderr, "\"%s\" failed, file %s, line %d\n", #EX, __FILE__, __LINE__), exit(1))) @@ -82,13 +87,13 @@ main(int argc, char**argv) cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == 42); @@ -109,13 +114,13 @@ main(int argc, char**argv) cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == (!2)); @@ -138,7 +143,7 @@ main(int argc, char**argv) cod_parse_context context = new_cod_parse_context(); cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param1_decl int); #ifdef NO_EMULATION cod_subroutine_declaration("int proc(int i)", context); @@ -147,7 +152,7 @@ main(int argc, char**argv) #endif gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param1_decl int)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); assert(func(EC_param1 15) == 87); cod_exec_context_free(ec); @@ -165,20 +170,20 @@ main(int argc, char**argv) typedef struct test { int i; int j; - long k; + size_t k; short l; } test_struct, *test_struct_p; static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; FMField struct_fields[] = { {"i", "integer", sizeof(int), FMOffset(test_struct_p, i)}, {"j", "integer", sizeof(int), FMOffset(test_struct_p, j)}, - {"k", "integer", sizeof(long), FMOffset(test_struct_p, k)}, + {"k", "integer", sizeof(size_t), FMOffset(test_struct_p, k)}, {"l", "integer", sizeof(short), FMOffset(test_struct_p, l)}, {(void*)0, (void*)0, 0, 0}}; @@ -187,7 +192,7 @@ main(int argc, char**argv) test_struct str; test_struct *param = &str; cod_code gen_code; - long (*func)(); + long (*func)(EC_param1_decl test_struct_p); cod_assoc_externs(context, externs); cod_parse_for_context(extern_string, context); @@ -211,13 +216,14 @@ main(int argc, char**argv) } gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)(test_struct_p)) (long) gen_code->func; + func = (long(*)(EC_param1_decl test_struct_p)) gen_code->func; if (verbose) cod_dump(gen_code); str.i = 15; str.j = 4; str.k = 10; str.l = 3; + long tmp = func(EC_param1 param); assert(func(EC_param1 param) == 90); cod_exec_context_free(ec); cod_code_free(gen_code); @@ -232,7 +238,7 @@ main(int argc, char**argv) static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; static char code[] = "{\ @@ -259,7 +265,7 @@ main(int argc, char**argv) int i, j; double levels[253][37]; cod_code gen_code; - double (*func)(), result; + double (*func)(EC_param1_decl double*), result; double *param = &levels[0][0]; cod_assoc_externs(context, externs); @@ -293,7 +299,7 @@ main(int argc, char**argv) gen_code = cod_code_gen(code, context); ec = cod_create_exec_context(gen_code); - func = (double (*)())(long) gen_code->func; + func = (double (*)(EC_param1_decl double*))(intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param1 param); if (result != 18126.00) { @@ -315,8 +321,8 @@ main(int argc, char**argv) int *dummy(int*p);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, - {"dummy", (void*)(long)dummy}, + {"printf", (void*)(intptr_t)printf}, + {"dummy", (void*)(intptr_t)dummy}, {(void*)0, (void*)0} }; typedef struct test { @@ -340,7 +346,7 @@ int *dummy(int*p);"; int i, j = 0; double levels; cod_code gen_code; - int *(*func)(), *result; + int *(*func)(EC_param1_decl test_struct *), *result; test_struct strct; test_struct *param = &strct; @@ -373,7 +379,7 @@ int *dummy(int*p);"; gen_code = cod_code_gen(code, context); ec = cod_create_exec_context(gen_code); - func = (int * (*)())(long) gen_code->func; + func = (int * (*)(EC_param1_decl test_struct*)) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param1 param); if (result != (int*)&strct.levels) { diff --git a/cod/tests/t10.c b/cod/tests/t10.c index ec208fe6a4..b686013139 100644 --- a/cod/tests/t10.c +++ b/cod/tests/t10.c @@ -1,6 +1,7 @@ #include "config.h" #include "cod.h" #include +#include #include #ifdef HAVE_MALLOC_H #include @@ -26,9 +27,9 @@ void *malloc(int size);\n\ void free(void *pointer);\n"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, - {"malloc", (void*)(long)malloc}, - {"free", (void*)(long)free}, + {"printf", (void*)(intptr_t)printf}, + {"malloc", (void*)(intptr_t)malloc}, + {"free", (void*)(intptr_t)free}, {(void*)0, (void*)0} }; char code_string[] = "\ @@ -60,7 +61,7 @@ void free(void *pointer);\n"; cod_assoc_externs(context, externs); cod_parse_for_context(extern_string, context); gen_code = cod_code_gen(code_string, context); - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); assert(result == 42); cod_code_free(gen_code); @@ -110,9 +111,9 @@ void *malloc(int size);\n\ void free(void *pointer);\n"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, - {"malloc", (void*)(long)malloc}, - {"free", (void*)(long)free}, + {"printf", (void*)(intptr_t)printf}, + {"malloc", (void*)(intptr_t)malloc}, + {"free", (void*)(intptr_t)free}, {(void*)0, (void*)0} }; cod_parse_context context = new_cod_parse_context(); @@ -126,7 +127,7 @@ void free(void *pointer);\n"; if (gen_code == NULL) { printf("Code generation failed for test 2\n"); } else { - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); assert(result == 21); cod_code_free(gen_code); @@ -163,9 +164,9 @@ void *malloc(int size);\n\ void free(void *pointer);\n"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, - {"malloc", (void*)(long)malloc}, - {"free", (void*)(long)free}, + {"printf", (void*)(intptr_t)printf}, + {"malloc", (void*)(intptr_t)malloc}, + {"free", (void*)(intptr_t)free}, {(void*)0, (void*)0} }; cod_parse_context context = new_cod_parse_context(); @@ -179,7 +180,7 @@ void free(void *pointer);\n"; if (gen_code == NULL) { printf("Code generation failed for test 3\n"); } else { - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); assert(result == 20); cod_code_free(gen_code); @@ -215,9 +216,9 @@ void *malloc(int size);\n\ void free(void *pointer);\n"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, - {"malloc", (void*)(long)malloc}, - {"free", (void*)(long)free}, + {"printf", (void*)(intptr_t)printf}, + {"malloc", (void*)(intptr_t)malloc}, + {"free", (void*)(intptr_t)free}, {(void*)0, (void*)0} }; cod_parse_context context = new_cod_parse_context(); @@ -231,7 +232,7 @@ void free(void *pointer);\n"; if (gen_code == NULL) { printf("Code generation failed for test 3\n"); } else { - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); assert(result == 20); cod_code_free(gen_code); @@ -265,9 +266,9 @@ void free(void *pointer);\n"; static char extern_string[] = "int printf(string format, ...);\n"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, - {"malloc", (void*)(long)malloc}, - {"free", (void*)(long)free}, + {"printf", (void*)(intptr_t)printf}, + {"malloc", (void*)(intptr_t)malloc}, + {"free", (void*)(intptr_t)free}, {(void*)0, (void*)0} }; cod_parse_context context = new_cod_parse_context(); @@ -281,7 +282,7 @@ void free(void *pointer);\n"; if (gen_code == NULL) { printf("Code generation failed for test 3\n"); } else { - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); assert(result == 20); cod_code_free(gen_code); @@ -337,14 +338,14 @@ static FMField dyn_arrays_field_list[] = static char extern_string[] = "int printf(string format, ...);\n"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, - {"malloc", (void*)(long)malloc}, - {"free", (void*)(long)free}, + {"printf", (void*)(intptr_t)printf}, + {"malloc", (void*)(intptr_t)malloc}, + {"free", (void*)(intptr_t)free}, {(void*)0, (void*)0} }; cod_parse_context context = new_cod_parse_context(); cod_code gen_code; - long (*func)(); + long (*func)(dyn_arrays *); long result; cod_assoc_externs(context, externs); @@ -356,7 +357,7 @@ static FMField dyn_arrays_field_list[] = printf("Code generation failed for test 3\n"); } else { dyn_arrays input; - func = (long(*)()) (long) gen_code->func; + func = (long(*)(dyn_arrays*)) (intptr_t) gen_code->func; input.dim1 = 7; input.dim2 = 5; input.dim3 = 3; diff --git a/cod/tests/t11.c b/cod/tests/t11.c index 30f86b465a..1b16b31cb9 100644 --- a/cod/tests/t11.c +++ b/cod/tests/t11.c @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/cod/tests/t12.c b/cod/tests/t12.c index 5ab112405f..1c55395174 100644 --- a/cod/tests/t12.c +++ b/cod/tests/t12.c @@ -1,6 +1,7 @@ #include "config.h" #include "cod.h" #include +#include #include #include #ifdef HAVE_MALLOC_H @@ -48,12 +49,12 @@ main(int argc, char **argv) static char extern_string[] = "int printf(string format, ...);\n"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; cod_parse_context context = new_cod_parse_context(); cod_code gen_code; - long (*func)(); + long (*func)(cod_exec_context); long result; cod_assoc_externs(context, externs); @@ -68,7 +69,7 @@ main(int argc, char **argv) void *state; int state_size = 0; ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(cod_exec_context)) (intptr_t) gen_code->func; result = func(ec); if (verbose) printf("Run number after first run is %ld, expected 1\nGrabbing state...", result); assert(result == 1); @@ -132,12 +133,12 @@ main(int argc, char **argv) static char extern_string[] = "int printf(string format, ...);\n"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; cod_parse_context context = new_cod_parse_context(); cod_code gen_code; - long (*func)(); + long (*func)(cod_exec_context); long result; cod_assoc_externs(context, externs); @@ -152,7 +153,7 @@ main(int argc, char **argv) void *state; int state_size = 0; ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(cod_exec_context)) (intptr_t) gen_code->func; result = func(ec); assert(result == 0); diff --git a/cod/tests/t2.c b/cod/tests/t2.c index a17b56ce6b..437d983dd6 100644 --- a/cod/tests/t2.c +++ b/cod/tests/t2.c @@ -12,6 +12,7 @@ #endif #define assert(EX) ((EX) ? (void)0 : (fprintf(stderr, "\"%s\" failed, file %s, line %d\n", #EX, __FILE__, __LINE__), exit(1))) #include +#include #include int @@ -51,7 +52,7 @@ main(int argc, char **argv) static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; /* test external call */ @@ -70,7 +71,7 @@ main(int argc, char **argv) cod_subroutine_declaration("void proc(int i, double d, string s)", context); gen_code = cod_code_gen(code, context); - func = (void (*)(int, double, char*))(long)gen_code->func; + func = (void (*)(int, double, char*))(intptr_t)gen_code->func; printf("Expect -> \"values are is %d, %g, %s\"\n", 5, 3.14159, "hello!"); (func)(5, (double)3.14159, "hello!"); @@ -89,7 +90,7 @@ main(int argc, char **argv) static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; static char code[] = "{\ @@ -142,7 +143,7 @@ main(int argc, char **argv) write_buffer(write_file, &formats[0], &tmp, test_num); } gen_code = cod_code_gen(code, context); - func = (double (*)(test_struct_p))(long) gen_code->func; + func = (double (*)(test_struct_p))(intptr_t) gen_code->func; assert((func)(param) == 46.00); free(tmp.vals); cod_code_free(gen_code); @@ -160,7 +161,7 @@ main(int argc, char **argv) static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; static char code[] = "{\ @@ -214,7 +215,7 @@ main(int argc, char **argv) write_buffer(write_file, &formats[0], &tmp, test_num); } gen_code = cod_code_gen(code, context); - func = (int (*)(test_struct_p))(long) gen_code->func; + func = (int (*)(test_struct_p))(intptr_t) gen_code->func; assert((func)(param) == 145); free(tmp.vals); cod_code_free(gen_code); @@ -231,7 +232,7 @@ main(int argc, char **argv) static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; static char code[] = "{\ @@ -283,7 +284,7 @@ main(int argc, char **argv) write_buffer(write_file, &formats[0], &tmp, test_num); } gen_code = cod_code_gen(code, context); - func = (double (*)(test_struct_p))(long) gen_code->func; + func = (double (*)(test_struct_p))(intptr_t) gen_code->func; assert((func)(param) == 46.00); free(tmp.vals); cod_code_free(gen_code); @@ -301,7 +302,7 @@ main(int argc, char **argv) static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; static char code[] = "{\ @@ -355,7 +356,7 @@ main(int argc, char **argv) write_buffer(write_file, &formats[0], &tmp, test_num); } gen_code = cod_code_gen(code, context); - func = (double (*)(test_struct_p))(long) gen_code->func; + func = (double (*)(test_struct_p))(intptr_t) gen_code->func; assert((func)(param) == 46.00); free(tmp.vals); cod_code_free(gen_code); @@ -378,8 +379,8 @@ main(int argc, char **argv) static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, - {"malloc", (void*)(long)malloc}, + {"printf", (void*)(intptr_t)printf}, + {"malloc", (void*)(intptr_t)malloc}, {(void*)0, (void*)0} }; static char code[] = "{\ @@ -433,7 +434,7 @@ return testing;\n\ write_buffer(write_file, &formats[0], &tmp, test_num); } gen_code = cod_code_gen(code, context); - func = (double (*)(test_struct_p))(long) gen_code->func; + func = (double (*)(test_struct_p))(intptr_t) gen_code->func; assert((func)(param) == 46.00); (void)func; free(tmp.vals); diff --git a/cod/tests/t3.c b/cod/tests/t3.c index 802d50599d..fa0eed8536 100644 --- a/cod/tests/t3.c +++ b/cod/tests/t3.c @@ -10,6 +10,7 @@ #include #define assert(EX) ((EX) ? (void)0 : (fprintf(stderr, "\"%s\" failed, file %s, line %d\n", #EX, __FILE__, __LINE__), exit(1))) #include +#include static double testd(){return 1.0;} static int testi(){return 4;} @@ -20,6 +21,8 @@ x = new_cod_parse_context();\ if (output_file) cod_set_error_func(x, error_func); #define EC_param0 #define EC_param1 +#define EC_param0_decl +#define EC_param1_decl #else #define GEN_PARSE_CONTEXT(x) \ x = new_cod_parse_context();\ @@ -27,6 +30,8 @@ cod_add_param("ec", "cod_exec_context", 0, x);\ if (output_file) cod_set_error_func(x, error_func); #define EC_param0 ec #define EC_param1 ec, +#define EC_param0_decl cod_exec_context ec +#define EC_param1_decl cod_exec_context ec, #endif static int verbose = 0; @@ -88,12 +93,12 @@ main(int argc, char **argv) static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; cod_code gen_code; long ret; - long (*func)(); + long (*func)(EC_param0_decl); if (verbose) printf("Running test 1 (-o 1)\n"); GEN_PARSE_CONTEXT(context); @@ -101,7 +106,7 @@ main(int argc, char **argv) cod_parse_for_context(extern_string, context); gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; ret = func(EC_param0); assert(ret == 23); ret = func(EC_param0); @@ -128,7 +133,7 @@ main(int argc, char **argv) cod_parse_context context = new_cod_parse_context(); cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param1_decl int); if (verbose) printf("Running test 2 (-o 2)\n"); #ifdef NO_EMULATION @@ -138,7 +143,7 @@ main(int argc, char **argv) #endif gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)(int)) (long) gen_code->func; + func = (long(*)(EC_param1_decl int)) (intptr_t) gen_code->func; assert(func(EC_param1 15) == 87); cod_exec_context_free(ec); cod_code_free(gen_code); @@ -170,7 +175,7 @@ main(int argc, char **argv) cod_exec_context ec; test_struct str; cod_code gen_code; - long (*func)(); + long (*func)(EC_param1_decl test_struct_p); if (verbose) printf("Running test 3 (-o 3)\n"); cod_add_simple_struct_type("struct_type", struct_fields, context); @@ -182,7 +187,7 @@ main(int argc, char **argv) gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)(test_struct_p)) (long) gen_code->func; + func = (long(*)(EC_param1_decl test_struct_p)) (intptr_t) gen_code->func; str.i = 15; str.j = 4; @@ -198,7 +203,7 @@ main(int argc, char **argv) static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; char code_string[] = {"\ @@ -227,7 +232,7 @@ char code_string[] = {"\ cod_exec_context ec; test_struct str; cod_code gen_code; - long (*func)(); + long (*func)(EC_param1_decl test_struct_p); if (verbose) printf("Running test 4 (-o 4)\n"); cod_assoc_externs(context, externs); @@ -242,7 +247,7 @@ char code_string[] = {"\ gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)(test_struct_p)) (long) gen_code->func; + func = (long(*)(EC_param1_decl test_struct_p)) (intptr_t) gen_code->func; str.i = 15; str.j = 4; @@ -280,7 +285,7 @@ char code_string[] = {"\ int i, j; double levels[253][37], result; cod_code gen_code; - double (*func)(); + double (*func)(EC_param1_decl double*); if (verbose) printf("Running test 5 (-o 5)\n"); @@ -299,7 +304,7 @@ char code_string[] = {"\ gen_code = cod_code_gen(code, context); ec = cod_create_exec_context(gen_code); - func = (double (*)(double*))(long) gen_code->func; + func = (double (*)(EC_param1_decl double*))(intptr_t) gen_code->func; result = (func)(EC_param1 &levels[0][0]); if (result != 18126.00) { printf("Expected %g, got %g\n", 18126.0, result); @@ -313,8 +318,8 @@ char code_string[] = {"\ double testd();"; static cod_extern_entry externs[] = { - {"testd", (void*)(long)testd}, - {"printf", (void*)(long)printf}, + {"testd", (void*)(intptr_t)testd}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; static char code[] = "{\ @@ -326,7 +331,7 @@ char code_string[] = {"\ cod_exec_context ec; double result; cod_code gen_code; - double (*func)(); + double (*func)(EC_param0_decl); if (verbose) printf("Running test 6 (-o 6)\n"); cod_assoc_externs(context, externs); @@ -339,7 +344,7 @@ char code_string[] = {"\ #endif gen_code = cod_code_gen(code, context); ec = cod_create_exec_context(gen_code); - func = (double (*)())(long) gen_code->func; + func = (double (*)(EC_param0_decl))(intptr_t) gen_code->func; result = (func)(EC_param0); if (result != 1.0) { printf("Expected %g, got %g\n", 1.0, result); @@ -372,11 +377,11 @@ char code_string[] = {"\ static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); if (verbose) printf("Running test 7 (-o 7)\n"); GEN_PARSE_CONTEXT(context); @@ -384,7 +389,7 @@ char code_string[] = {"\ cod_parse_for_context(extern_string, context); gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; assert(func(EC_param0) == 23); assert(func(EC_param0) == 29); assert(func(EC_param0) == 35); @@ -398,8 +403,8 @@ char code_string[] = {"\ int testi();"; static cod_extern_entry externs[] = { - {"testi", (void*)(long)testi}, - {"printf", (void*)(long)printf}, + {"testi", (void*)(intptr_t)testi}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; static char code[] = "{\ @@ -411,7 +416,7 @@ char code_string[] = {"\ cod_exec_context ec; int result; cod_code gen_code; - int (*func)(); + int (*func)(EC_param0_decl); if (verbose) printf("Running test 8 (-o 8)\n"); cod_assoc_externs(context, externs); @@ -424,7 +429,7 @@ char code_string[] = {"\ #endif gen_code = cod_code_gen(code, context); ec = cod_create_exec_context(gen_code); - func = (int (*)())(long) gen_code->func; + func = (int (*)(EC_param0_decl))(intptr_t) gen_code->func; result = (func)(EC_param0); if (result != 0) { printf("Expected %d, got %d\n", 0, result); diff --git a/cod/tests/t4.c b/cod/tests/t4.c index af799f9cb2..dbe5a7f01d 100644 --- a/cod/tests/t4.c +++ b/cod/tests/t4.c @@ -5,6 +5,7 @@ #include "config.h" #include #include +#include #define assert(EX) ((EX) ? (void)0 : (fprintf(stderr, "\"%s\" failed, file %s, line %d\n", #EX, __FILE__, __LINE__), exit(1))) #include #include "cod.h" @@ -348,7 +349,7 @@ comment\n\ static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; int ret; @@ -389,7 +390,7 @@ comment\n\ static cod_extern_entry externs[] = { - {"junk", (void*)(long)printf}, + {"junk", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; int ret; diff --git a/cod/tests/t5.c b/cod/tests/t5.c index 262cf1ad58..de9b927536 100644 --- a/cod/tests/t5.c +++ b/cod/tests/t5.c @@ -10,6 +10,7 @@ #endif #define assert(EX) ((EX) ? (void)0 : (fprintf(stderr, "\"%s\" failed, file %s, line %d\n", #EX, __FILE__, __LINE__), exit(1))) #include +#include #include struct order_header { @@ -190,7 +191,7 @@ main(int argc, char **argv) static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; /* test external call */ @@ -306,7 +307,7 @@ main(int argc, char **argv) } gen_code = cod_code_gen(code, context); - func = (void (*)(void*,void*))(long)gen_code->func; + func = (void (*)(void*,void*))(intptr_t)gen_code->func; memset(&out_order, 0, sizeof(out_order)); (func)((void*)param, (void*)&out_order); if (out_order.station_id != order.station_id) { diff --git a/cod/tests/t6.c b/cod/tests/t6.c index e70032f3c6..2c0c01a842 100644 --- a/cod/tests/t6.c +++ b/cod/tests/t6.c @@ -8,6 +8,7 @@ #endif #define assert(EX) ((EX) ? (void)0 : (fprintf(stderr, "\"%s\" failed, file %s, line %d\n", #EX, __FILE__, __LINE__), exit(1))) #include +#include #include typedef struct @@ -58,7 +59,7 @@ main() static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; static char code[] = "{\n\ @@ -83,7 +84,7 @@ main() cod_subroutine_declaration("int proc(FrameData *output)", context); gen_code = cod_code_gen(code, context); - func = (void (*)(void*))(long)gen_code->func; + func = (void (*)(void*))(intptr_t)gen_code->func; data.num_points = 0; data.image_data = NULL; diff --git a/cod/tests/t7.c b/cod/tests/t7.c index 63f03aee61..c97423b1b1 100644 --- a/cod/tests/t7.c +++ b/cod/tests/t7.c @@ -15,6 +15,7 @@ #endif #define assert(EX) ((EX) ? (void)0 : (fprintf(stderr, "\"%s\" failed, file %s, line %d\n", #EX, __FILE__, __LINE__), exit(1))) #include +#include #include static int verbose = 0; @@ -23,12 +24,16 @@ static int verbose = 0; x = new_cod_parse_context(); #define EC_param0 #define EC_param1 +#define EC_param0_decl +#define EC_param1_decl #else #define GEN_PARSE_CONTEXT(x) \ x = new_cod_parse_context();\ cod_add_param("ec", "cod_exec_context", 0, x); #define EC_param0 ec #define EC_param1 ec, +#define EC_param0_decl cod_exec_context +#define EC_param1_decl cod_exec_context, #endif typedef struct _multi_array_rec { @@ -142,8 +147,8 @@ main(int argc, char **argv) int submit(cod_exec_context ec, int port, void *d, cod_type_spec dt);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, - {"submit", (void*)(long)submit}, + {"printf", (void*)(intptr_t)printf}, + {"submit", (void*)(intptr_t)submit}, {(void*)0, (void*)0} }; static char code[] = "{\n\ @@ -206,11 +211,11 @@ main(int argc, char **argv) cod_subroutine_declaration("void proc(cod_exec_context ec, simple *input)", context); gen_code = cod_code_gen(code, context); - func = (void (*)(cod_exec_context, void*))(long)gen_code->func; + func = (void (*)(cod_exec_context, void*))(intptr_t)gen_code->func; cod_dump(gen_code); ec = cod_create_exec_context(gen_code); - printf("Main ec is %lx\n", (long) ec); + printf("Main ec is %p\n", ec); func(ec, &multi_array); cod_exec_context_free(ec); cod_code_free(gen_code); @@ -234,13 +239,13 @@ main(int argc, char **argv) cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == 8); diff --git a/cod/tests/t8.c b/cod/tests/t8.c index fb64474339..532a29a39b 100644 --- a/cod/tests/t8.c +++ b/cod/tests/t8.c @@ -7,6 +7,7 @@ #include #include #include +#include static int verbose = 0; @@ -46,7 +47,7 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); assert(result == 7); cod_code_free(gen_code); @@ -54,7 +55,7 @@ main(int argc, char** argv) } test_num++; if ((run_only == -1) || (run_only == test_num)) { /* 1 */ - /* test cast of complex type (&j) to basic type (long) */ + /* test cast of complex type (&j) to basic type (intptr_t) */ char code_string[] = "\ {\n\ int j = 2;\n\ @@ -75,7 +76,7 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); if (result != 7) { printf("Expected 7, got %ld in t8, subtest 2\n", result); @@ -127,7 +128,7 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); assert(result==8); cod_code_free(gen_code); @@ -157,7 +158,7 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); assert(result == sizeof(int)); cod_code_free(gen_code); @@ -187,9 +188,9 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); - assert(result == -sizeof(int)); + assert(result == -(long) sizeof(int)); cod_code_free(gen_code); cod_free_parse_context(context); } @@ -216,7 +217,7 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); assert(result == sizeof(double *)); cod_code_free(gen_code); @@ -247,7 +248,7 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); assert(result == 2*sizeof(double)); cod_code_free(gen_code); @@ -277,7 +278,7 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); assert(result == 2*sizeof(double *)); cod_code_free(gen_code); @@ -308,7 +309,7 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); assert(result == 2); cod_code_free(gen_code); @@ -340,7 +341,7 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); assert(result == -2); cod_code_free(gen_code); @@ -372,7 +373,7 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); if (result != 16/sizeof(void*)) { printf(" op minus result is %ld\n", result); @@ -407,9 +408,9 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); - if (result != -(16/sizeof(void*))) { + if (result != -(16/(long)sizeof(void*))) { printf(" 2nd op minus result is %ld\n", result); exit(1); } @@ -442,7 +443,7 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); assert(result == -2*(long)sizeof(double)); cod_code_free(gen_code); @@ -473,7 +474,7 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (long(*)()) (long) gen_code->func; + func = (long(*)()) (intptr_t) gen_code->func; result = func(); assert(result == -2*(long)sizeof(double *)); cod_code_free(gen_code); @@ -495,8 +496,8 @@ main(int argc, char** argv) cod_parse_context context = new_cod_parse_context(); cod_code gen_code; unsigned char *p = (unsigned char *) "hiya"; - long (*func)(unsigned char *); - long result; + intptr_t (*func)(unsigned char *); + intptr_t result; cod_subroutine_declaration("long test(unsigned char * param)", context); gen_code = cod_code_gen(code_string, context); @@ -504,9 +505,9 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (long(*)(unsigned char *)) (long) gen_code->func; + func = (intptr_t(*)(unsigned char *)) (intptr_t) gen_code->func; result = func(p); - assert(result == (long) p); + assert(result == (intptr_t) p); cod_code_free(gen_code); cod_free_parse_context(context); } @@ -532,7 +533,7 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (int(*)(int *)) (long) gen_code->func; + func = (int(*)(int *)) (intptr_t) gen_code->func; result = func(&i); if (result != 8) printf("result was %d, not 8\n", result); if (i != 9) printf("i was %d, not 9\n", i); @@ -562,7 +563,7 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (int(*)(int *)) (long) gen_code->func; + func = (int(*)(int *)) (intptr_t) gen_code->func; result = func(&i); if (result != 9) printf("result was %d, not 8\n", result); if (i != 9) printf("i was %d, not 9\n", i); @@ -590,7 +591,7 @@ main(int argc, char** argv) printf("Code generation failed!\n"); return -1; } - func = (int*(*)(int *)) (long) gen_code->func; + func = (int*(*)(int *)) (intptr_t) gen_code->func; result = func(&i); if (result != (&i + 1)) printf("result was %p, not %p\n", result, &i + 1); diff --git a/cod/tests/t9.c b/cod/tests/t9.c index 24f0ef888b..b876f90073 100644 --- a/cod/tests/t9.c +++ b/cod/tests/t9.c @@ -2,6 +2,7 @@ #include "cod.h" #define assert(EX) ((EX) ? (void)0 : (fprintf(stderr, "\"%s\" failed, file %s, line %d\n", #EX, __FILE__, __LINE__), exit(1))) #include +#include char code_string[] = "{return sizeof(int);}"; char code_string2[] = "{return sizeof(int*);}"; char code_string3[] = "{ int j; return sizeof j;}"; @@ -19,12 +20,12 @@ main() cod_exec_context ec; cod_code gen_code; - int (*func)(); + int (*func)(cod_exec_context); cod_add_param("ec", "cod_exec_context", 0, context); gen_code = cod_code_gen(code_blocks[test], context); ec = cod_create_exec_context(gen_code); - func = (int(*)())gen_code->func; + func = (int(*)(cod_exec_context))gen_code->func; ret = (func)(ec); if (ret != results[test]) { printf("bad test %d, ret was %d\n", test, ret); diff --git a/cod/tests/time.c b/cod/tests/time.c index 0d541004c1..851166b1e8 100644 --- a/cod/tests/time.c +++ b/cod/tests/time.c @@ -9,6 +9,7 @@ #include "cod.h" #define assert(EX) ((EX) ? (void)0 : (fprintf(stderr, "\"%s\" failed, file %s, line %d\n", #EX, __FILE__, __LINE__), exit(1))) #include +#include #include #include @@ -18,12 +19,16 @@ static int verbose = 0; x = new_cod_parse_context(); #define EC_param0 #define EC_param1 +#define EC_param0_decl +#define EC_param1_decl #else #define GEN_PARSE_CONTEXT(x) \ x = new_cod_parse_context();\ cod_add_param("ec", "cod_exec_context", 0, x); #define EC_param0 ec #define EC_param1 ec, +#define EC_param0_decl cod_exec_context +#define EC_param1_decl cod_exec_context, #endif extern void @@ -72,29 +77,36 @@ main(int argc, char**argv) static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; char code_string[] = "\n\ {\n\ timeval t1, t2;\n \ - int delay = 10000;\n\ + int delay = 5000;\n\ long accum = 0;\n\ long usec_duration;\n\ + long sec_diff = 0;\n\ + long usec_diff = 0;\n\ gettimeofday(&t1);\n\ \n\ if (t1.tv_sec < 1423159919) { /* in the past */ \n\ return 0;\n\ }\n\ while(delay > 0) { /* just so there's a duration */\n \ + printf(\"slow loop %g\\n\", (double)delay * (double) accum);\n\ delay--;\n\ accum++;\n\ }\n\ gettimeofday(&t2);\n\ - usec_duration = (t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec;\n\ + sec_diff = t2.tv_sec - t1.tv_sec;\n\ + usec_diff = t2.tv_usec - t1.tv_usec;\n\ + printf(\"sec diff = %ld\\n\", sec_diff);\n\ + printf(\"usec diff = %ld\\n\", usec_diff);\n\ + usec_duration = sec_diff * 1000000 + usec_diff;\n\ \n\ - if ((usec_duration < 1) || (usec_duration > 1000000)) {\n\ + if ((usec_duration < 1) || (usec_duration > 10000000)) {\n\ printf(\"duration is %d usecs, unreasonable\\n\", usec_duration);\n \ return 0; /* seems unreasonable */\n\ }\n\ @@ -104,7 +116,7 @@ main(int argc, char**argv) cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); @@ -112,7 +124,7 @@ main(int argc, char**argv) cod_parse_for_context(extern_string, context); gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == 1); @@ -133,13 +145,13 @@ main(int argc, char**argv) cod_parse_context context; cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param0_decl); long result; GEN_PARSE_CONTEXT(context); gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param0_decl)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param0); assert(result == (!2)); @@ -162,7 +174,7 @@ main(int argc, char**argv) cod_parse_context context = new_cod_parse_context(); cod_exec_context ec; cod_code gen_code; - long (*func)(); + long (*func)(EC_param1_decl int); #ifdef NO_EMULATION cod_subroutine_declaration("int proc(int i)", context); @@ -171,7 +183,7 @@ main(int argc, char**argv) #endif gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)()) (long) gen_code->func; + func = (long(*)(EC_param1_decl int)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); assert(func(EC_param1 15) == 87); cod_exec_context_free(ec); @@ -196,7 +208,7 @@ main(int argc, char**argv) static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; FMField struct_fields[] = { @@ -211,7 +223,7 @@ main(int argc, char**argv) test_struct str; test_struct *param = &str; cod_code gen_code; - long (*func)(); + long (*func)(EC_param1_decl test_struct_p); cod_assoc_externs(context, externs); cod_parse_for_context(extern_string, context); @@ -235,7 +247,7 @@ main(int argc, char**argv) } gen_code = cod_code_gen(code_string, context); ec = cod_create_exec_context(gen_code); - func = (long(*)(test_struct_p)) (long) gen_code->func; + func = (long(*)(EC_param1_decl test_struct_p)) (intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); str.i = 15; @@ -256,7 +268,7 @@ main(int argc, char**argv) static char extern_string[] = "int printf(string format, ...);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, + {"printf", (void*)(intptr_t)printf}, {(void*)0, (void*)0} }; static char code[] = "{\ @@ -283,7 +295,7 @@ main(int argc, char**argv) int i, j; double levels[253][37]; cod_code gen_code; - double (*func)(), result; + double (*func)(EC_param1_decl double*), result; double *param = &levels[0][0]; cod_assoc_externs(context, externs); @@ -317,7 +329,7 @@ main(int argc, char**argv) gen_code = cod_code_gen(code, context); ec = cod_create_exec_context(gen_code); - func = (double (*)())(long) gen_code->func; + func = (double (*)(EC_param1_decl double*))(intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param1 param); if (result != 18126.00) { @@ -339,8 +351,8 @@ main(int argc, char**argv) int *dummy(int*p);"; static cod_extern_entry externs[] = { - {"printf", (void*)(long)printf}, - {"dummy", (void*)(long)dummy}, + {"printf", (void*)(intptr_t)printf}, + {"dummy", (void*)(intptr_t)dummy}, {(void*)0, (void*)0} }; typedef struct test { @@ -364,7 +376,7 @@ int *dummy(int*p);"; int i, j = 1; double levels; cod_code gen_code; - int *(*func)(), *result; + int *(*func)(EC_param1_decl test_struct*), *result; test_struct strct; test_struct *param = &strct; @@ -397,7 +409,7 @@ int *dummy(int*p);"; gen_code = cod_code_gen(code, context); ec = cod_create_exec_context(gen_code); - func = (int * (*)())(long) gen_code->func; + func = (int * (*)(EC_param1_decl test_struct*))(intptr_t) gen_code->func; if (verbose) cod_dump(gen_code); result = func(EC_param1 param); if (result != (int*)&strct.levels) { diff --git a/cod/tests/xform.c b/cod/tests/xform.c index c9a0ca603d..2a4ee877e3 100644 --- a/cod/tests/xform.c +++ b/cod/tests/xform.c @@ -2,6 +2,7 @@ #include "ecl.h" #define assert(EX) ((EX) ? (void)0 : (fprintf(stderr, "\"%s\" failed, file %s, line %d\n", #EX, __FILE__, __LINE__), exit(1))) #include +#include #define IMGDEBUG diff --git a/config.h.cmake b/config.h.cmake index 1c0181a1a8..d02baec245 100755 --- a/config.h.cmake +++ b/config.h.cmake @@ -126,6 +126,9 @@ /* The number of bytes in type long long */ #define SIZEOF_LONG_LONG @SIZEOF_LONG_LONG@ +/* The number of bytes in type size_t */ +#define SIZEOF_SIZE_T @SIZEOF_SIZE_T@ + /* Define to `int' if does not define. */ #cmakedefine pid_t diff --git a/ffs/evol.c b/ffs/evol.c index 2c3a4d28bc..cd5bed3d87 100755 --- a/ffs/evol.c +++ b/ffs/evol.c @@ -82,9 +82,7 @@ FFS_determine_conversion(FFSContext c, FFSTypeHandle format) } static int -IO_field_type_eq(str1, str2) -const char *str1; -const char *str2; +IO_field_type_eq(const char *str1, const char *str2) { FMdata_type t1, t2; long t1_count, t2_count; @@ -101,8 +99,8 @@ const char *str2; char *colon2 = strchr(tmp_str2, ':'); char *lparen1 = strchr(str1, '['); char *lparen2 = strchr(str2, '['); - int count1 = 0; - int count2 = 0; + intptr_t count1 = 0; + intptr_t count2 = 0; if (colon1 != NULL) { count1 = colon1 - tmp_str1; @@ -133,13 +131,7 @@ const char *str2; * Returns FFSformat_order * */ static FMformat_order -FMformat_cmp_diff(format1, format2, diff1, diff2) -FMFormat format1; -FMFormat format2; -int *diff1; /* Number of fields present in format1 and - * not in format2 */ -int *diff2; /* Number of fields present in format2 and - * not in format1 */ +FMformat_cmp_diff(FMFormat format1, FMFormat format2, int *diff1, int *diff2) { FMformat_order tmp_result = Format_Equal; FMFieldList orig_field_list1 = format1->field_list; @@ -439,13 +431,10 @@ FMformat_compat_cmp2(FMFormat format, FMFormat *formatList, } extern void * -FFScreate_compat_info(prior_format, xform_code, len_p) -FMFormat prior_format; -char *xform_code; -int *len_p; +FFScreate_compat_info(FMFormat prior_format, char *xform_code, size_t *len_p) { char *block; - int block_len = strlen(xform_code) + prior_format->server_ID.length +1; + size_t block_len = strlen(xform_code) + prior_format->server_ID.length +1; block = malloc(block_len); memcpy(block, prior_format->server_ID.value, diff --git a/ffs/ffs.c b/ffs/ffs.c index a2f5ffe1f8..2bc61274c8 100755 --- a/ffs/ffs.c +++ b/ffs/ffs.c @@ -4,19 +4,19 @@ #include "assert.h" #include "ffs.h" #include "cod.h" -#include "fm_internal.h" -#include "ffs_internal.h" #include "string.h" #include "stdio.h" #include "stdlib.h" +#include "fm_internal.h" +#include "ffs_internal.h" #include "ffs_marshal.h" static void * quick_get_pointer(FMFieldPtr iofield, void *data); -static unsigned long +static size_t quick_get_ulong(FMFieldPtr iofield, void *data); void -quick_put_ulong(FMFieldPtr iofield, unsigned long value, void *data); +quick_put_ulong(FMFieldPtr iofield, size_t value, void *data); static ssize_t add_to_tmp_buffer(FFSBuffer buf, size_t size); static int64_t @@ -41,8 +41,8 @@ typedef struct encode_state { int addr_list_is_stack; int addr_list_cnt; addr_list_entry *addr_list; - int malloc_addr_size; - int saved_offset_difference; + ssize_t malloc_addr_size; + ssize_t saved_offset_difference; void *orig_data; }*estate; @@ -227,7 +227,7 @@ FFSencode_internal(FFSBuffer b, FMFormat fmformat, void *data, size_t *buf_size, struct encode_state state; init_encode_state(&state); size_t base_offset = 0; - int header_size; + size_t header_size; state.iovec_is_stack = 1; state.iovec = stack_iov_array; @@ -336,7 +336,7 @@ fixup_output_vector(FFSBuffer b, estate s) } static void -add_to_addr_list(estate s, void *addr, int offset) +add_to_addr_list(estate s, void *addr, size_t offset) { if (s->addr_list_is_stack) { if (s->addr_list_cnt == STACK_ARRAY_SIZE) { @@ -361,11 +361,11 @@ add_to_addr_list(estate s, void *addr, int offset) s->addr_list_cnt++; } -static int +static ssize_t search_addr_list(estate s, void *addr) { int i; - size_t previous_offset = (size_t) -1; + ssize_t previous_offset = (ssize_t) -1; for (i=0; i < s->addr_list_cnt; i++) { if (s->addr_list[i].addr == addr) { previous_offset = s->addr_list[i].offset; @@ -390,8 +390,8 @@ FFSencode_vector(FFSBuffer b, FMFormat fmformat, void *data) addr_list_entry stack_addr_list[STACK_ARRAY_SIZE]; struct encode_state state; init_encode_state(&state); - int base_offset = 0; - int header_size; + ssize_t base_offset = 0; + ssize_t header_size; state.iovec_is_stack = 1; state.iovec = stack_iov_array; @@ -473,7 +473,7 @@ handle_subfields(FFSBuffer buf, FMFormat f, estate s, size_t data_offset) if (!f->variant) return 1; for (i = 0; i < f->field_count; i++) { - int subfield_offset = data_offset + f->field_list[i].field_offset; + size_t subfield_offset = data_offset + f->field_list[i].field_offset; int ret; if (field_is_flat(f, &f->var_list[i].type_desc)) continue; ret = handle_subfield(buf, f, s, subfield_offset, data_offset, @@ -484,7 +484,7 @@ handle_subfields(FFSBuffer buf, FMFormat f, estate s, size_t data_offset) } static void -set_dynamic_array_size(FMFormat f, FFSBuffer buf, int parent_offset, FMTypeDesc *t, int new_value) +set_dynamic_array_size(FMFormat f, FFSBuffer buf, size_t parent_offset, FMTypeDesc *t, int new_value) { struct _FMgetFieldStruct src_spec; int field = t->control_field_index; @@ -501,7 +501,7 @@ set_dynamic_array_size(FMFormat f, FFSBuffer buf, int parent_offset, FMTypeDesc static size_t -determine_size(FMFormat f, FFSBuffer buf, int parent_offset, FMTypeDesc *t) +determine_size(FMFormat f, FFSBuffer buf, size_t parent_offset, FMTypeDesc *t) { switch (t->type) { case FMType_pointer: @@ -565,8 +565,8 @@ handle_subfield(FFSBuffer buf, FMFormat f, estate s, size_t data_offset, size_t } if (f->recursive) { - size_t previous_offset = search_addr_list(s, ptr_value); - if (previous_offset != (size_t)-1) { + ssize_t previous_offset = search_addr_list(s, ptr_value); + if (previous_offset != (ssize_t)-1) { quick_put_ulong(&src_spec, previous_offset, (char*)buf->tmp_buffer + data_offset); return 1; @@ -602,15 +602,15 @@ handle_subfield(FFSBuffer buf, FMFormat f, estate s, size_t data_offset, size_t cod_exec_context ec = marshal_info->ec; struct subsample_marshal_data smd; new_offset = allocate_tmp_space(s, buf, size, 8, &tmp_data_loc); - smd.element_count = element_count; + smd.element_count = (int)element_count; smd.element_size = element_size; smd.src_ptr = ptr_value; smd.dst_ptr = (char*)buf->tmp_buffer + new_offset; smd.marshalled_count = 0; #ifdef DO_DCG - cod_assoc_client_data(ec, 0x534d4450, (long)&smd); + cod_assoc_client_data(ec, 0x534d4450, (intptr_t)&smd); #endif - marshal_info->subsample_array_func(ec, s->orig_data, element_count); + marshal_info->subsample_array_func(ec, s->orig_data, (int)element_count); /* fixup size */ set_dynamic_array_size(f, buf, parent_offset, t->next, smd.marshalled_count); @@ -715,7 +715,7 @@ extern FFSEncodeVector copy_all_to_FFSBuffer(FFSBuffer buf, FFSEncodeVector vec) { int i = 0; - int vec_offset = (long) vec - (long)buf->tmp_buffer; + intptr_t vec_offset = (intptr_t) vec - (intptr_t)buf->tmp_buffer; /* * vec and some of the buffers may be in the memory managed by the * FFSBuffer. The goal here to is put *everything* into the FFSBuffer. @@ -724,10 +724,10 @@ copy_all_to_FFSBuffer(FFSBuffer buf, FFSEncodeVector vec) while (vec[vec_count].iov_base != NULL) { vec_count++; } - assert(((unsigned long)vec >= (unsigned long)buf->tmp_buffer) && - ((unsigned long)vec < (unsigned long)buf->tmp_buffer + buf->tmp_buffer_size)); + assert(((uintptr_t)vec >= (uintptr_t)buf->tmp_buffer) && + ((uintptr_t)vec < (uintptr_t)buf->tmp_buffer + buf->tmp_buffer_size)); { - size_t already_in[vec_count]; + size_t* already_in = malloc(sizeof(already_in[0]) * vec_count); while (vec[i].iov_base != NULL) { if (((char*)vec[i].iov_base >= (char*)buf->tmp_buffer) && ((char*)vec[i].iov_base < (char*)buf->tmp_buffer + buf->tmp_buffer_size)) { @@ -744,9 +744,9 @@ copy_all_to_FFSBuffer(FFSBuffer buf, FFSEncodeVector vec) } i = 0; - while (((FFSEncodeVector)((long)buf->tmp_buffer + vec_offset))[i].iov_base != + while (((FFSEncodeVector)((intptr_t)buf->tmp_buffer + vec_offset))[i].iov_base != NULL) { - FFSEncodeVector v = (void*)((long) buf->tmp_buffer + vec_offset); + FFSEncodeVector v = (void*)((intptr_t) buf->tmp_buffer + vec_offset); if (already_in[i] == 0) { /* if this is an external buffer, copy it */ ssize_t offset = add_to_tmp_buffer(buf, v[i].iov_len); @@ -758,17 +758,18 @@ copy_all_to_FFSBuffer(FFSBuffer buf, FFSEncodeVector vec) } i++; } + free(already_in); } /* reallocation done now */ - vec = (void*)((long)buf->tmp_buffer + vec_offset); + vec = (void*)((intptr_t)buf->tmp_buffer + vec_offset); i = 0; while (vec[i].iov_base != NULL) { - if (((long)vec[i].iov_base > 0) && - ((long)vec[i].iov_base <= buf->tmp_buffer_size)) { + if (((intptr_t)vec[i].iov_base > 0) && + ((uintptr_t)vec[i].iov_base <= (uintptr_t)buf->tmp_buffer_size)) { /* * remap pointers into temp so that they're addresses */ - vec[i].iov_base = (void*)((long)vec[i].iov_base + (char *)buf->tmp_buffer - 1); + vec[i].iov_base = (void*)((intptr_t)vec[i].iov_base + (char *)buf->tmp_buffer - 1); } i++; } @@ -974,7 +975,7 @@ FFSset_simple_target(FFSContext c, char *format_name, FMFieldList field_list, si FMStructDescRec struct_list[2]; struct_list[0].format_name = format_name; struct_list[0].field_list = field_list; - struct_list[0].struct_size = struct_size; + struct_list[0].struct_size = (int) struct_size; struct_list[0].opt_info = NULL; struct_list[1].format_name = NULL; struct_list[1].field_list = NULL; @@ -1018,8 +1019,7 @@ typedef struct _conversion_action { } conversion_action, *conversion_action_ptr; static int -in_place_base_conversion_possible(conv) -IOConversionPtr conv; +in_place_base_conversion_possible(IOConversionPtr conv) { switch (conv->conversion_type) { case buffer_and_convert: @@ -1047,8 +1047,7 @@ IOConversionPtr conv; } static int -in_place_variant_conversion_possible(conv) -IOConversionPtr conv; +in_place_variant_conversion_possible(IOConversionPtr conv) { switch (conv->conversion_type) { case copy_dynamic_portion: @@ -1097,14 +1096,10 @@ FFSdecode_in_place_possible(FFSTypeHandle format) } } -#define expand_size_to_align(size) ((((size) & 0x7) == 0) ? (size) : (((size) + 8) & (int) -8)) +#define expand_size_to_align(size) ((((size) & 0x7) == 0) ? (size) : (((size) + 8) & (size_t) -8)) static int -set_conversion_params(ioformat, input_record_len, conv, params) -FFSTypeHandle ioformat; -int64_t input_record_len; -IOConversionPtr conv; -conversion_action_ptr params; +set_conversion_params(FFSTypeHandle ioformat, int64_t input_record_len, IOConversionPtr conv, conversion_action_ptr params) { FFSContext c = ioformat->context; size_t final_base_size; @@ -1121,7 +1116,7 @@ conversion_action_ptr params; ssize_t final_string_offset; void *final_string_address; - final_base_size = expand_size_to_align(ioformat->body->record_length + conv->base_size_delta); + final_base_size = (size_t) expand_size_to_align((size_t)(ioformat->body->record_length + conv->base_size_delta)); src_base_size = expand_size_to_align(ioformat->body->record_length); possible_converted_variant_size = final_variant_size_for_record(input_record_len, conv); @@ -1187,8 +1182,8 @@ conversion_action_ptr params; } else { final_string_offset = 0; final_string_address = - params->final_base + expand_size_to_align(ioformat->body->record_length + - conv->base_size_delta); + params->final_base + (size_t)expand_size_to_align((size_t)(ioformat->body->record_length + + conv->base_size_delta)); } /* set variant src values */ @@ -1241,39 +1236,34 @@ conversion_action_ptr params; } static int64_t -final_variant_size_for_record(input_record_len, conv) -int64_t input_record_len; -IOConversionPtr conv; +final_variant_size_for_record(int64_t input_record_len, IOConversionPtr conv) { return (int) ((input_record_len - conv->ioformat->body->record_length) * conv->max_var_expansion); } -extern int +extern size_t FFS_decode_length_format(FFSContext context, FFSTypeHandle ioformat, - long record_length) + size_t record_length) { IOConversionPtr conv; int64_t variant_part, final_base_size, src_base_size; if (ioformat == NULL) - return -1; + return (size_t)-1; conv = ioformat->conversion; if (!ioformat->conversion) return record_length; variant_part = final_variant_size_for_record(record_length, ioformat->conversion); - final_base_size = expand_size_to_align(ioformat->body->record_length + - conv->base_size_delta); + final_base_size = expand_size_to_align((int64_t)(ioformat->body->record_length + + conv->base_size_delta)); src_base_size = expand_size_to_align(ioformat->body->record_length); return variant_part + Max(final_base_size, src_base_size); } -extern long -FFS_est_decode_length(context, src, record_length) -FFSContext context; -char *src; -long record_length; +extern size_t +FFS_est_decode_length(FFSContext context, char *src, size_t record_length) { FFSTypeHandle ioformat = FFSTypeHandle_from_encode(context, src); return FFS_decode_length_format(context, ioformat, record_length); @@ -1297,18 +1287,13 @@ FFSheader_size(FFSTypeHandle ioformat) extern int -FFShas_conversion(ioformat) -FFSTypeHandle ioformat; +FFShas_conversion(FFSTypeHandle ioformat) { return (ioformat->conversion != NULL); } static int -FFSinternal_decode(ioformat, src, dest, to_buffer) -FFSTypeHandle ioformat; -char *src; /* incoming data to be decoded */ -void *dest; /* area to hold decoded data */ -int to_buffer; +FFSinternal_decode(FFSTypeHandle ioformat, char *src, void *dest, int to_buffer) { FFSContext iofile = ioformat->context; IOConversionPtr conv; @@ -1393,16 +1378,15 @@ int to_buffer; } static int -check_conversion(ioformat) -FFSTypeHandle ioformat; +check_conversion(FFSTypeHandle ioformat) { if (ioformat->conversion == NULL) { if (ioformat->status == not_checked) { FFS_determine_conversion(ioformat->context, ioformat); } if (ioformat->status == none_available) { - fprintf(stderr, "FFS Warning: Attempting to decode when no conversion has been set. \n Record is of type \"%s\", ioformat 0x%lx.\n No data returned.\n", - ioformat->body->format_name, (long) ioformat); + fprintf(stderr, "FFS Warning: Attempting to decode when no conversion has been set. \n Record is of type \"%s\", ioformat 0x%p.\n No data returned.\n", + ioformat->body->format_name, ioformat); ioformat->status = none_available; return 0; } @@ -1411,10 +1395,7 @@ FFSTypeHandle ioformat; } extern int -FFSdecode(iocontext, src, dest) -FFSContext iocontext; -char *src; /* incoming data to be decoded */ -char *dest; /* area to hold decoded data */ +FFSdecode(FFSContext iocontext, char *src, char *dest) { FFSTypeHandle ioformat; ioformat = FFSTypeHandle_from_encode(iocontext, src); @@ -1428,10 +1409,7 @@ char *dest; /* area to hold decoded data */ } extern int -FFSdecode_in_place(iocontext, src, dest_ptr) -FFSContext iocontext; -char *src; /* incoming data to be decoded */ -void **dest_ptr; /* area to hold pointer to decoded data */ +FFSdecode_in_place(FFSContext iocontext, char *src, void **dest_ptr) { FFSTypeHandle ioformat = FFSTypeHandle_from_encode(iocontext, src); int header_size; @@ -1451,10 +1429,7 @@ void **dest_ptr; /* area to hold pointer to decoded data */ } extern int -FFSdecode_to_buffer(iocontext, src, dest) -FFSContext iocontext; -char *src; /* incoming data to be decoded */ -void *dest; /* area to hold decoded data */ +FFSdecode_to_buffer(FFSContext iocontext, char *src, void *dest) { FFSTypeHandle ioformat; ioformat = FFSTypeHandle_from_encode(iocontext, src); @@ -1468,9 +1443,7 @@ void *dest; /* area to hold decoded data */ } extern FFSTypeHandle -FFS_target_from_encode(c, data) -FFSContext c; -char *data; /* incoming data to be decoded */ +FFS_target_from_encode(FFSContext c, char *data) { FFSTypeHandle f; /* first element in encoded buffer is format ID */ @@ -1486,9 +1459,7 @@ char *data; /* incoming data to be decoded */ } static void -byte_swap(data, size) -char *data; -int size; +byte_swap(char *data, int size) { int i; assert((size % 2) == 0); @@ -1522,14 +1493,13 @@ create_fixed_FFSBuffer(char *buffer, size_t size) { FFSBuffer buf = malloc(sizeof(struct _FFSBuffer)); buf->tmp_buffer = buffer; - buf->tmp_buffer_size = -size; + buf->tmp_buffer_size = -(ssize_t)size; buf->tmp_buffer_in_use_size = 0; return buf; } void -free_FFSBuffer(buf) -FFSBuffer buf; +free_FFSBuffer(FFSBuffer buf) { if ((buf->tmp_buffer_size > 0) && buf->tmp_buffer) free(buf->tmp_buffer); @@ -1538,9 +1508,7 @@ FFSBuffer buf; extern char * -make_tmp_buffer(buf, size) -FFSBuffer buf; -int64_t size; +make_tmp_buffer(FFSBuffer buf, int64_t size) { if (buf->tmp_buffer_size < 0) { /* fixed size buffer */ @@ -1566,22 +1534,20 @@ int64_t size; static ssize_t -add_to_tmp_buffer(buf, size) -FFSBuffer buf; -size_t size; +add_to_tmp_buffer(FFSBuffer buf, size_t size) { - long old_size = buf->tmp_buffer_in_use_size; + ssize_t old_size = buf->tmp_buffer_in_use_size; size += old_size; if (buf->tmp_buffer_size < 0) { /* fixed size buffer */ - if (size > (-buf->tmp_buffer_size)) return -1; + if (size > (size_t)(-buf->tmp_buffer_size)) return -1; } else { if (buf->tmp_buffer_size == 0) { int64_t tmp_size = Max(size, TMP_BUFFER_INIT_SIZE); buf->tmp_buffer = malloc(tmp_size); } - if (size > buf->tmp_buffer_size) { + if (size > (size_t)buf->tmp_buffer_size) { buf->tmp_buffer = realloc(buf->tmp_buffer, size); buf->tmp_buffer_size = size; } @@ -1611,14 +1577,13 @@ set_bigendian () { words_bigendian = (u.c[sizeof (long) - 1] == 1); return words_bigendian; } - +#ifndef WORDS_BIGENDIAN #define WORDS_BIGENDIAN ((words_bigendian == -1) ? set_bigendian() : words_bigendian) #endif +#endif -static unsigned long -quick_get_ulong(iofield, data) -FMFieldPtr iofield; -void *data; +static size_t +quick_get_ulong(FMFieldPtr iofield, void *data) { data = (void *) ((char *) data + iofield->offset); /* only used when field type is an integer and aligned by its size */ @@ -1656,9 +1621,7 @@ void *data; } static void * -quick_get_pointer(iofield, data) -FMFieldPtr iofield; -void *data; +quick_get_pointer(FMFieldPtr iofield, void *data) { union { void *p; @@ -1682,14 +1645,14 @@ void *data; break; } case 8: -#if SIZEOF_LONG == 8 +#if SIZEOF_SIZE_T == 8 memcpy(&u.p, data, 8); #else { int tmp; /* must be fetching 4 bytes of the 8 available */ if (WORDS_BIGENDIAN) - memcpy(&tmp, data + 4, 4); + memcpy(&tmp, ((char*)data) + 4, 4); else memcpy(&tmp, data, 4); u.tmp = (unsigned long) tmp; @@ -1701,10 +1664,7 @@ void *data; } void -quick_put_ulong(iofield, value, data) -FMFieldPtr iofield; -unsigned long value; -void *data; +quick_put_ulong(FMFieldPtr iofield, size_t value, void *data) { data = (void *) ((char *) data + iofield->offset); /* only used when field type is an integer and aligned by its size */ @@ -1721,7 +1681,7 @@ void *data; break; } case 8:{ - unsigned long tmp = value; + size_t tmp = value; memcpy(data, &tmp, 8); break; } diff --git a/ffs/ffs.h.in b/ffs/ffs.h.in index 49956eb218..3708464633 100644 --- a/ffs/ffs.h.in +++ b/ffs/ffs.h.in @@ -51,13 +51,13 @@ typedef struct _FFSTypeHandle *FFSTypeHandle; typedef struct _FFSIndexItem *FFSIndexItem; #define create_FFSContext() create_FFSContext_FM(NULL) -extern FFSContext create_FFSContext_FM(FMContext fmc); +extern FFS_DECLSPEC FFSContext create_FFSContext_FM(FMContext fmc); -extern FFSBuffer create_FFSBuffer(); -extern FFSBuffer create_fixed_FFSBuffer(char *buffer, size_t size); -extern void free_FFSBuffer(FFSBuffer buf); +extern FFS_DECLSPEC FFSBuffer create_FFSBuffer(); +extern FFS_DECLSPEC FFSBuffer create_fixed_FFSBuffer(char *buffer, size_t size); +extern FFS_DECLSPEC void free_FFSBuffer(FFSBuffer buf); -extern char * +extern FFS_DECLSPEC char * FFSencode(FFSBuffer b, FMFormat ioformat, void *data, size_t *buf_size); typedef struct FFSEncodeVec { @@ -65,133 +65,133 @@ typedef struct FFSEncodeVec { @UIO_SIZE_T_TYPE@ iov_len; } *FFSEncodeVector; -extern FFSEncodeVector +extern FFS_DECLSPEC FFSEncodeVector FFSencode_vector(FFSBuffer b, FMFormat fmformat, void *data); -extern char * +extern FFS_DECLSPEC char * FFSencode_no_leaf_copy(FFSBuffer b, FMFormat fmformat, void *data, size_t *buf_size); -extern int FFSdecode_in_place_possible(FFSTypeHandle); +extern FFS_DECLSPEC int FFSdecode_in_place_possible(FFSTypeHandle); -extern FFSTypeHandle FFSTypeHandle_from_encode(FFSContext c, char *b); +extern FFS_DECLSPEC FFSTypeHandle FFSTypeHandle_from_encode(FFSContext c, char *b); -extern FFSTypeHandle FFSTypeHandle_by_index(FFSContext c, int index); +extern FFS_DECLSPEC FFSTypeHandle FFSTypeHandle_by_index(FFSContext c, int index); -extern char * FFSTypeHandle_name(FFSTypeHandle f); +extern FFS_DECLSPEC char * FFSTypeHandle_name(FFSTypeHandle f); -extern void +extern FFS_DECLSPEC void establish_conversion(FFSContext c, FFSTypeHandle f, FMStructDescList struct_list); -extern int +extern FFS_DECLSPEC int FFShas_conversion(FFSTypeHandle format); -extern long -FFS_est_decode_length(FFSContext context, char *encoded, long record_length); +extern FFS_DECLSPEC size_t +FFS_est_decode_length(FFSContext context, char *encoded, size_t record_length); -extern int +extern FFS_DECLSPEC int FFSdecode_in_place(FFSContext context, char *encode, void **dest_ptr); -extern int +extern FFS_DECLSPEC int FFSdecode_to_buffer(FFSContext context, char *encode, void *dest); -extern int +extern FFS_DECLSPEC int FFSdecode(FFSContext context, char *encode, char *dest); -extern FFSTypeHandle +extern FFS_DECLSPEC FFSTypeHandle FFSset_fixed_target(FFSContext c, FMStructDescList struct_list); -extern FFSTypeHandle +extern FFS_DECLSPEC FFSTypeHandle FFS_target_from_encode(FFSContext c, char *data); -extern FMFormat +extern FFS_DECLSPEC FMFormat FMFormat_of_original(FFSTypeHandle h); -extern FFSEncodeVector +extern FFS_DECLSPEC FFSEncodeVector copy_all_to_FFSBuffer(FFSBuffer buf, FFSEncodeVector vec); -extern FFSEncodeVector +extern FFS_DECLSPEC FFSEncodeVector copy_vector_to_FFSBuffer(FFSBuffer buf, FFSEncodeVector vec); -extern FMContext +extern FFS_DECLSPEC FMContext FMContext_from_FFS(FFSContext c); -extern void +extern FFS_DECLSPEC void free_FFSContext(FFSContext c); -extern FMStructDescList +extern FFS_DECLSPEC FMStructDescList get_localized_formats(FMFormat f); /* file interface follows*/ -extern FFSFile +extern FFS_DECLSPEC FFSFile open_FFSfile(const char *path, const char *flags); -extern FFSFile +extern FFS_DECLSPEC FFSFile open_FFSfd(void *fd, const char *flags); -extern void +extern FFS_DECLSPEC void close_FFSfile(FFSFile file); -extern void +extern FFS_DECLSPEC void free_FFSfile(FFSFile file); -extern int +extern FFS_DECLSPEC int write_FFSfile(FFSFile f, FMFormat format, void *data); -extern int +extern FFS_DECLSPEC int write_FFSfile_attrs(FFSFile f, FMFormat format, void *data, attr_list attrs); -extern int +extern FFS_DECLSPEC int write_comment_FFSfile(FFSFile f, const char *comment); -extern long +extern FFS_DECLSPEC size_t FFSfile_next_decode_length(FFSFile iofile); typedef enum { FFSerror=1, FFSend=2, FFSdata=4, FFSformat=8, FFScomment=16, FFSindex=32 } FFSRecordType; -extern void +extern FFS_DECLSPEC void FFSset_visible(FFSFile ffsfile, int bitmap); -extern FFSRecordType +extern FFS_DECLSPEC FFSRecordType FFSnext_record_type(FFSFile ffsfile); -extern long +extern FFS_DECLSPEC size_t FFSnext_data_length(FFSFile file); -extern FFSTypeHandle +extern FFS_DECLSPEC FFSTypeHandle FFSnext_type_handle(FFSFile ffsfile); -extern char * +extern FFS_DECLSPEC char * FFSread_comment(FFSFile ffsfile); -extern int +extern FFS_DECLSPEC int FFSread(FFSFile ffsfile, void *dest); -extern int +extern FFS_DECLSPEC int FFSread_attr(FFSFile file, void *dest, attr_list *attr); -extern int +extern FFS_DECLSPEC int FFSread_to_buffer(FFSFile file, FFSBuffer b, void **dest); -extern attr_list +extern FFS_DECLSPEC attr_list FFSattrs_from_last_read(FFSFile file); -extern FFSTypeHandle +extern FFS_DECLSPEC FFSTypeHandle FFSread_format(FFSFile ffsfile); -extern FFSIndexItem +extern FFS_DECLSPEC FFSIndexItem FFSread_index(FFSFile ffsfile); -extern FFSContext +extern FFS_DECLSPEC FFSContext FFSContext_of_file(FFSFile f); -extern FMContext +extern FFS_DECLSPEC FMContext FMContext_of_file(FFSFile f); -extern int +extern FFS_DECLSPEC int FFSseek(FFSFile file, int data_item); #if defined(__cplusplus) || defined(c_plusplus) diff --git a/ffs/ffs_conv.c b/ffs/ffs_conv.c index 5d4c5f5196..938c929c36 100755 --- a/ffs/ffs_conv.c +++ b/ffs/ffs_conv.c @@ -13,6 +13,7 @@ #endif #include #include +#include #ifdef HAVE_DILL_H #include "dill.h" @@ -95,8 +96,7 @@ static char *float_format_str[] = { static int IO_shut_up = 0; static int -min_align_size(size) -int size; +min_align_size(int size) { int align_size = 8; /* conservative on current machines */ switch (size) { @@ -172,8 +172,7 @@ init_float_formats() void -FFSfree_conversion(conv) -IOConversionPtr conv; +FFSfree_conversion(IOConversionPtr conv) { int i; for (i = 0; i < conv->conv_count; i++) { @@ -206,10 +205,7 @@ IOConversionPtr conv; * */ static void -field_name_strip_get_default(io_field, out_field_name, default_val) -const FMField *io_field; -char *out_field_name; -void **default_val; +field_name_strip_get_default(const FMField *io_field, char *out_field_name, void **default_val) { char *s, *s1; char *base_type = base_data_type(io_field->field_type); @@ -282,21 +278,9 @@ find_field_for_conv(char *field_name, FMFieldList fields, int cur_field, void *s static IOConversionPtr -create_conversion(src_ioformat, target_field_list, target_struct_size, - pointer_size, byte_reversal, target_fp_format, - initial_conversion, target_column_major, - string_offset_size, converted_strings, target_list) -FFSTypeHandle src_ioformat; -FMFieldList target_field_list; -int target_struct_size; -int pointer_size; -int byte_reversal; -FMfloat_format target_fp_format; -IOconversion_type initial_conversion; -int target_column_major; -int string_offset_size; -int converted_strings; -FMStructDescList target_list; +create_conversion(FFSTypeHandle src_ioformat, FMFieldList target_field_list, int target_struct_size, int pointer_size, + int byte_reversal, FMfloat_format target_fp_format, IOconversion_type initial_conversion, + int target_column_major, int string_offset_size, int converted_strings, FMStructDescList target_list) { int target_field_count = count_FMfield(target_field_list); FMFieldList nfl_sort = copy_field_list(target_field_list); @@ -609,10 +593,10 @@ FMStructDescList target_list; } } else { - fprintf(stderr, "Unknown field type for field %s ->\"%s\", format %lx\n", + fprintf(stderr, "Unknown field type for field %s ->\"%s\", format %p\n", input_field.field_name, src_ioformat->body->field_list[input_index].field_type, - (long)src_ioformat); + src_ioformat); FFSfree_conversion(conv_ptr); return NULL; } @@ -665,14 +649,8 @@ FMStructDescList target_list; extern void -set_general_IOconversion_for_format(iofile, file_ioformat, native_field_list, - native_struct_size, pointer_size, target_list) -FFSContext iofile; -FFSTypeHandle file_ioformat; -FMFieldList native_field_list; -int native_struct_size; -int pointer_size; -FMStructDescList target_list; +set_general_IOconversion_for_format(FFSContext iofile, FFSTypeHandle file_ioformat, FMFieldList native_field_list, + int native_struct_size, int pointer_size, FMStructDescList target_list) { IOConversionPtr conv_ptr; IOconversion_type conv_type = none_required; @@ -704,10 +682,7 @@ FMStructDescList target_list; } static int -set_conversion_from_list(iocontext, ioformat, struct_list) -FFSContext iocontext; -FFSTypeHandle ioformat; -FMStructDescList struct_list; +set_conversion_from_list(FFSContext iocontext, FFSTypeHandle ioformat, FMStructDescList struct_list) { int i = 0; while(struct_list[i].format_name != NULL) { @@ -764,10 +739,7 @@ static void link_conversion_sets(FFSTypeHandle ioformat){} extern void -establish_conversion(iocontext, ioformat, struct_list) -FFSContext iocontext; -FFSTypeHandle ioformat; -FMStructDescList struct_list; +establish_conversion(FFSContext iocontext, FFSTypeHandle ioformat, FMStructDescList struct_list) { int use_package = 0; @@ -780,12 +752,7 @@ FMStructDescList struct_list; } extern void -ffs_internal_convert_field(src_spec, src, dest_type, dest_size, dest) -FMFieldPtr src_spec; -void *src; -FMdata_type dest_type; -int dest_size; -void *dest; +ffs_internal_convert_field(FMFieldPtr src_spec, void *src, FMdata_type dest_type, int dest_size, void *dest) { int float_OK = 1; if (dest_type == float_type) { @@ -833,10 +800,13 @@ void *dest; *dest_field = (short) tmp; } else if (dest_size == sizeof(int)) { int *dest_field = (int *) dest; - *dest_field = tmp; + *dest_field = (int) tmp; } else if (dest_size == sizeof(long)) { - long *dest_field = (long *) dest; - *dest_field = tmp; + long* dest_field = (long*)dest; + *dest_field = (long)tmp; + } else if (dest_size == sizeof(size_t)) { + size_t* dest_field = (size_t*)dest; + *dest_field = (long)tmp; #if SIZEOF_LONG_LONG != 0 } else if (dest_size == sizeof(long long)) { long long lltmp = tmp; @@ -847,7 +817,7 @@ void *dest; } case char_type: { - char tmp = get_big_int(src_spec, src); + char tmp = (char)get_big_int(src_spec, src); char *dest_field = (char *) dest; *dest_field = tmp; break; @@ -855,7 +825,7 @@ void *dest; case boolean_type: case enumeration_type: { - int tmp = get_big_int(src_spec, src); + int tmp = (int) get_big_int(src_spec, src); int *dest_field = (int *) dest; *dest_field = tmp; break; @@ -870,10 +840,10 @@ void *dest; unsigned short *dest_field = (unsigned short *) dest; *dest_field = (unsigned short) tmp; } else if (dest_size == sizeof(int)) { - unsigned int *dest_field = (unsigned int *) dest; - *dest_field = tmp; - } else if (dest_size == sizeof(long)) { - unsigned long *dest_field = (unsigned long *) dest; + unsigned int* dest_field = (unsigned int*)dest; + *dest_field = (unsigned int)tmp; + } else if (dest_size == sizeof(size_t)) { + size_t* dest_field = (size_t*)dest; *dest_field = tmp; #if SIZEOF_LONG_LONG != 0 } else if (dest_size == sizeof(long long)) { @@ -933,10 +903,10 @@ typedef struct conv_status { void *dest; void *src_pointer_base; void *dest_pointer_base; - int src_offset_adjust; - int dest_offset_adjust; - int cur_offset; - int *control_value; + ssize_t src_offset_adjust; + ssize_t dest_offset_adjust; + size_t cur_offset; + size_t *control_value; int target_pointer_size; int src_pointer_size; int register_args; @@ -946,7 +916,7 @@ typedef struct conv_status { typedef struct run_time_conv_status { void *src_pointer_base; void *dest_pointer_base; - int dest_offset_adjust; + ssize_t dest_offset_adjust; } *RTConvStatus; static void @@ -954,9 +924,7 @@ internal_convert_record(IOConversionPtr conv, ConvStatus conv_status, void *src, void *dest, int data_already_copied); static void -print_IOConversion(conv_ptr, indent) -IOConversionPtr conv_ptr; -int indent; +print_IOConversion(IOConversionPtr conv_ptr, int indent) { int i; int ind; @@ -988,12 +956,12 @@ int indent; } for (ind = 0; ind < indent; ind++) printf(" "); - printf(" base_size_delta=%d, max_var_exp=%g, target_pointer_size=%d, string_offset=%d, converted_strings=%d\n", + printf(" base_size_delta=%zd, max_var_exp=%g, target_pointer_size=%d, string_offset=%zd, converted_strings=%d\n", conv_ptr->base_size_delta, conv_ptr->max_var_expansion, conv_ptr->target_pointer_size, conv_ptr->string_offset_size, conv_ptr->converted_strings); - printf(" conversion_function= %lx, required_align=%d\n", - (long) conv_ptr->conv_func, conv_ptr->required_alignment); + printf(" conversion_function= %p, required_align=%d\n", + conv_ptr->conv_func, conv_ptr->required_alignment); for (ind = 0; ind < indent; ind++) printf(" "); printf(" There are %d conversions registered:\n", conv_ptr->conv_count); @@ -1042,7 +1010,7 @@ int indent; for (ind = 0; ind < indent; ind++) printf(" "); if (conv_ptr->conversions[i].default_value == NULL) { - printf(" Src offset : %d size %d\n", src_field->offset, + printf(" Src offset : %zd size %d\n", src_field->offset, src_field->size); } else { int j; @@ -1054,7 +1022,7 @@ int indent; } for (ind = 0; ind < indent; ind++) printf(" "); - printf(" Dst offset : %d size %d\n", + printf(" Dst offset : %zd size %d\n", conv_ptr->conversions[i].dest_offset, conv_ptr->conversions[i].dest_size); if (conv_ptr->conversions[i].subconversion) { @@ -1072,9 +1040,7 @@ int indent; } static void -print_IOConversion_as_XML(conv_ptr, indent) -IOConversionPtr conv_ptr; -int indent; +print_IOConversion_as_XML(IOConversionPtr conv_ptr, int indent) { int i; int ind; @@ -1107,10 +1073,10 @@ int indent; } for (ind = 0; ind < indent; ind++) printf(" "); - printf("%d\n", conv_ptr->base_size_delta); + printf("%zd\n", conv_ptr->base_size_delta); printf("%g\n", conv_ptr->max_var_expansion); printf("%d\n", conv_ptr->target_pointer_size); - printf("%d\n", conv_ptr->string_offset_size); + printf("%zd\n", conv_ptr->string_offset_size); printf("%d\n", conv_ptr->converted_strings); for (ind = 0; ind < indent; ind++) printf(" "); @@ -1151,12 +1117,12 @@ int indent; } for (ind = 0; ind < indent; ind++) printf(" "); - printf("%d%d\n", + printf("%zd%d\n", src_field->offset, src_field->size); for (ind = 0; ind < indent; ind++) printf(" "); - printf("%d%d\n", + printf("%zd%d\n", conv_ptr->conversions[i].dest_offset, conv_ptr->conversions[i].dest_size); if (conv_ptr->conversions[i].subconversion) { @@ -1175,26 +1141,19 @@ int indent; extern void -dump_IOConversion(conv_ptr) -IOConversionPtr conv_ptr; +dump_IOConversion(IOConversionPtr conv_ptr) { print_IOConversion(conv_ptr, 0); } extern void -dump_IOConversion_as_XML(conv_ptr) -IOConversionPtr conv_ptr; +dump_IOConversion_as_XML(IOConversionPtr conv_ptr) { print_IOConversion_as_XML(conv_ptr, 0); } void -FFSconvert_record(conv, src, dest, final_string_base, src_string_base) -IOConversionPtr conv; -void *src; -void *dest; -void *final_string_base; -void *src_string_base; +FFSconvert_record(IOConversionPtr conv, void *src, void *dest, void *final_string_base, void *src_string_base) { struct conv_status cs; if (src_string_base == NULL) { @@ -1206,13 +1165,13 @@ void *src_string_base; int i; int limit = 30; int *tmp = (int *) (((char *) src_string_base) - - (((long) src_string_base) % 4)); + (((intptr_t) src_string_base) % 4)); printf("record of type \"%s\", contents :\n", conv->ioformat->body->format_name); if (limit * sizeof(int) > conv->ioformat->body->record_length) limit = conv->ioformat->body->record_length / sizeof(int); for (i = 0; i < limit; i += 4) { - printf("%lx: %8x %8x %8x %8x\n", (long) ((char *) src) + (i * 4), + printf("%p: %8x %8x %8x %8x\n", ((char *) src) + (i * 4), ((int *) src)[i], ((int *) src)[i + 1], ((int *) src)[i + 2], ((int *) src)[i + 3]); } @@ -1233,7 +1192,7 @@ void *src_string_base; } } */ for (i = 0; i < limit; i += 4) { - printf("%lx: %8x %8x %8x %8x\n", (long) ((char *) tmp) + (i * 4), + printf("%p: %8x %8x %8x %8x\n", ((char *) tmp) + (i * 4), ((int *) tmp)[i], ((int *) tmp)[i + 1], ((int *) tmp)[i + 2], @@ -1243,14 +1202,14 @@ void *src_string_base; } rtcs.src_pointer_base = src_string_base; rtcs.dest_pointer_base = final_string_base; - rtcs.dest_offset_adjust = -conv->string_offset_size; + rtcs.dest_offset_adjust = -(ssize_t) conv->string_offset_size; conv->conv_func(src, dest, &rtcs); return; } else { cs.src_pointer_base = src_string_base; cs.dest_pointer_base = final_string_base; - cs.src_offset_adjust = -conv->string_offset_size; - cs.dest_offset_adjust = -conv->string_offset_size; + cs.src_offset_adjust = -(ssize_t)conv->string_offset_size; + cs.dest_offset_adjust = -(ssize_t)conv->string_offset_size; cs.cur_offset = 0; cs.control_value = NULL; cs.target_pointer_size = conv->target_pointer_size; @@ -1261,20 +1220,21 @@ void *src_string_base; } void -transpose_array(int *dimens, char *src, char *dest, int source_column_major, +transpose_array(size_t *dimens, char *src, char *dest, int source_column_major, FMdata_type dest_type, int dest_size, FMFieldPtr src_spec) { int dimen_count = 0; - int *index; - int i, cur_index; - int jump = 1; + size_t *index; + size_t i; + ssize_t cur_index; + size_t jump = 1; while (dimens[dimen_count] != 0) dimen_count++; struct _FMgetFieldStruct tmp_spec = *src_spec; if (dimen_count <= 1) return; - index = malloc(sizeof(int) * dimen_count); + index = malloc(sizeof(index[0]) * dimen_count); for(i = 0; i< dimen_count; i++) { index[i] = 0; } @@ -1285,8 +1245,8 @@ transpose_array(int *dimens, char *src, char *dest, int source_column_major, } while(index[0] < dimens[0]) { if (cur_index == (dimen_count-1)) { - int col_index_base = 0; - int row_index_base = 0; + size_t col_index_base = 0; + size_t row_index_base = 0; int i; void * dest_field; if (dimen_count >= 2) { @@ -1353,7 +1313,7 @@ transpose_array(int *dimens, char *src, char *dest, int source_column_major, free(index); } -static long +static size_t get_offset_for_addr(char *src_field_addr, ConvStatus conv_status, IOconvFieldStruct *conv) { @@ -1377,7 +1337,7 @@ convert_address_field(char *src_field_addr, char **output_source_ptr, int dest_size = conv_status->target_pointer_size; char *output_dest = NULL; char *output_source = NULL; - int offset = get_offset_for_addr(src_field_addr, conv_status, + size_t offset = get_offset_for_addr(src_field_addr, conv_status, conv); if (offset != 0) { int align_tmp = 0; @@ -1387,7 +1347,7 @@ convert_address_field(char *src_field_addr, char **output_source_ptr, output_dest = (char*)conv_status->dest_pointer_base + offset + conv_status->dest_offset_adjust; - if ((align_tmp = (((unsigned long)output_dest) % required_alignment)) != 0) { + if ((align_tmp = (((uintptr_t)output_dest) % required_alignment)) != 0) { output_dest += (required_alignment - align_tmp); conv_status->dest_offset_adjust += (required_alignment - align_tmp); } @@ -1402,7 +1362,7 @@ convert_address_field(char *src_field_addr, char **output_source_ptr, static void -new_convert_address_field(int offset, char **output_source_ptr, +new_convert_address_field(size_t offset, char **output_source_ptr, char *dest_field_addr, char **output_dest_ptr, ConvStatus conv_status, int required_alignment) { @@ -1418,7 +1378,7 @@ new_convert_address_field(int offset, char **output_source_ptr, output_dest = (char*)conv_status->dest_pointer_base + offset + conv_status->dest_offset_adjust; - if ((align_tmp = (((unsigned long)output_dest) % required_alignment)) != 0) { + if ((align_tmp = (((uintptr_t)output_dest) % required_alignment)) != 0) { output_dest += (required_alignment - align_tmp); conv_status->dest_offset_adjust += (required_alignment - align_tmp); } @@ -1431,7 +1391,7 @@ new_convert_address_field(int offset, char **output_source_ptr, } } -static int +static ssize_t decode_size_delta(ConvStatus conv_status, IOconvFieldStruct *conv, FMTypeDesc *type_desc) { @@ -1470,7 +1430,6 @@ item_size(ConvStatus conv_status, return 0; } - static void new_convert_field(char *src_field_addr, char *dest_field_addr, ConvStatus conv_status, @@ -1480,7 +1439,7 @@ new_convert_field(char *src_field_addr, char *dest_field_addr, switch(type_desc->type) { case FMType_pointer: { char *new_src, *new_dest; - int offset = get_offset_for_addr(src_field_addr, conv_status, + size_t offset = get_offset_for_addr(src_field_addr, conv_status, conv); new_convert_address_field(offset, &new_src, dest_field_addr, &new_dest, conv_status, 8); @@ -1538,7 +1497,7 @@ new_convert_field(char *src_field_addr, char *dest_field_addr, break; } case FMType_array: { - int elements = 1, i; + size_t elements = 1, i; char *new_src = src_field_addr; char *new_dest = dest_field_addr; FMTypeDesc *next = type_desc; @@ -1553,8 +1512,8 @@ new_convert_field(char *src_field_addr, char *dest_field_addr, } if (conv->rc_swap == no_row_column_swap) { if (!data_already_copied) { - int base_delta = decode_size_delta(conv_status, conv, next); - int total_delta = base_delta * elements; + ssize_t base_delta = decode_size_delta(conv_status, conv, next); + size_t total_delta = base_delta * elements; conv_status->dest_offset_adjust += total_delta; if (conv_status->global_conv->conversion_type == copy_dynamic_portion) { int base_size = item_size(conv_status, conv, next); @@ -1595,7 +1554,7 @@ new_convert_field(char *src_field_addr, char *dest_field_addr, int source_column_major = (conv->rc_swap == swap_source_column_major); int dimen_count = conv->iovar->dimen_count; - int *dimens = malloc(sizeof(int) * (dimen_count + 1)); + size_t *dimens = malloc(sizeof(dimens[0]) * (dimen_count + 1)); int i = 0; FMdata_type dest_type = conv->src_field.data_type; int dest_size = conv->dest_size; @@ -1625,22 +1584,18 @@ new_convert_field(char *src_field_addr, char *dest_field_addr, } static void -internal_convert_record(conv, conv_status, src, dest, data_already_copied) -IOConversionPtr conv; -ConvStatus conv_status; -void *src; -void *dest; -int data_already_copied; +internal_convert_record(IOConversionPtr conv, ConvStatus conv_status, void *src, + void *dest, int data_already_copied) { int i; - int *control_value = NULL; + size_t *control_value = NULL; if (conv->conversion_type == none_required) return; for (i = 0; i < conv->conv_count; i++) { FMTypeDesc *next = &conv->conversions[i].iovar->type_desc; while (next != NULL) { if ((next->type == FMType_array) && (next->static_size == 0)) { - long elements; + size_t elements; FMFormat f = conv->ioformat->body; int field = next->control_field_index; struct _FMgetFieldStruct tmp_src_spec; @@ -1652,7 +1607,7 @@ int data_already_copied; elements = get_big_int(&tmp_src_spec, src); if (control_value == NULL) { int j; - control_value = (int *) malloc(sizeof(int) * f->field_count); + control_value = (size_t *) malloc(sizeof(control_value[0]) * f->field_count); for (j = 0; j < f->field_count; j++) control_value[j] = 0; conv_status->control_value = control_value; @@ -1702,9 +1657,7 @@ int data_already_copied; static MAX_INTEGER_TYPE -get_big_int(iofield, data) -FMFieldPtr iofield; -void *data; +get_big_int(FMFieldPtr iofield, void *data) { if (iofield->data_type == integer_type) { if (iofield->size == sizeof(char)) { @@ -1731,7 +1684,7 @@ void *data; return tmp; } else if (iofield->size == 2 * sizeof(long)) { long tmp; - int low_bytes_offset = iofield->offset; + size_t low_bytes_offset = iofield->offset; if (WORDS_BIGENDIAN) { if (!iofield->byte_swap) { low_bytes_offset += sizeof(long); @@ -1771,9 +1724,7 @@ void *data; } static MAX_UNSIGNED_TYPE -get_big_unsigned(iofield, data) -FMFieldPtr iofield; -void *data; +get_big_unsigned(FMFieldPtr iofield, void *data) { if ((iofield->data_type == unsigned_type) || (iofield->data_type == enumeration_type) || @@ -1802,7 +1753,7 @@ void *data; return tmp; } else if (iofield->size == 2 * sizeof(long)) { unsigned long tmp; - int low_bytes_offset = iofield->offset; + size_t low_bytes_offset = iofield->offset; if (WORDS_BIGENDIAN) { if (!iofield->byte_swap) { low_bytes_offset += sizeof(long); @@ -1870,9 +1821,7 @@ float_conversion(unsigned char*value, int size, FMfloat_format src_format, } static MAX_FLOAT_TYPE -get_big_float(iofield, data) -FMFieldPtr iofield; -void *data; +get_big_float(FMFieldPtr iofield, void *data) { if (iofield->data_type == float_type) { if (iofield->size == sizeof(float)) { @@ -1946,9 +1895,7 @@ void *data; } static void -byte_swap(data, size) -char *data; -int size; +byte_swap(char *data, int size) { int i; assert((size % 2) == 0); @@ -1966,10 +1913,7 @@ int ffs_getreg(dill_stream s, int *reg_p, int type, int var_tmp){return 0;} int ffs_localb(void*s, int size) {return 0;} extern conv_routine -generate_conversion(conv, src_alignment, dest_alignment) -IOConversionPtr conv; -int src_alignment; -int dest_alignment; +generate_conversion(IOConversionPtr conv, int src_alignment, int dest_alignment) { return NULL; } @@ -1979,8 +1923,7 @@ int dest_alignment; #define max(x,y) (xdata_type) { case integer_type: @@ -2017,9 +1960,7 @@ struct _FMgetFieldStruct *field; } static int -conv_required_alignment(c, conv) -dill_stream c; -IOConversionPtr conv; +conv_required_alignment(dill_stream c, IOConversionPtr conv) { if (conv->conv_count == 0) return 0; return conv->ioformat->body->alignment; @@ -2116,14 +2057,10 @@ static void NO_SANITIZE_THREAD read_generation_environment_variables(void) extern - conv_routine -generate_conversion(conv, src_alignment, dest_alignment) -IOConversionPtr conv; -int src_alignment; -int dest_alignment; +conv_routine +generate_conversion(IOConversionPtr conv, int src_alignment, int dest_alignment) { dill_stream c = NULL; - dill_exec_handle conversion_handle; void (*conversion_routine)(); dill_reg args[6]; dill_reg tmp_regs[10]; @@ -2213,7 +2150,7 @@ int dest_alignment; if (debug_code_generation()) { if (register_args) { dill_reg src_pointer_base, dest_pointer_base, dest_offset_adjust; dill_scallv(c, (void*)printf, "printf", "%P%P%p%p%p", - "convert for %s called with src= %lx, dest %lx, rt_conv_status =%lx\n", + "convert for %s called with src= %p, dest %p, rt_conv_status =%p\n", format_name, args[0], args[1], args[2]); ffs_getreg(c, &src_pointer_base, DILL_P, DILL_VAR); dill_ldpi(c, src_pointer_base, args[2], FMOffset(RTConvStatus,src_pointer_base)); @@ -2222,7 +2159,7 @@ int dest_alignment; ffs_getreg(c, &dest_offset_adjust, DILL_I, DILL_VAR); dill_ldpi(c, dest_offset_adjust, args[2], FMOffset(RTConvStatus,dest_offset_adjust)); dill_scallv(c, (void*)printf, "printf", "%P%p%p%p", - "rt_conv_status is src_pointer_base= %lx, dest_pointer_base=%lx, dest_offset_adjust =%lx\n", + "rt_conv_status is src_pointer_base= %p, dest_pointer_base=%p, dest_offset_adjust =%zd\n", src_pointer_base, dest_pointer_base, dest_offset_adjust); } else { #ifdef HAVE_DILL_H @@ -2232,11 +2169,11 @@ int dest_alignment; } #endif dill_scallv(c, (void*)printf, "printf", "%P%P%p%p", - "convert for %s called with src= %lx, dest %lx\n", + "convert for %s called with src= %p, dest %p\n", format_name, args[0], args[1]); dill_ldpi(c, v_at, dill_lp(c), args[2]); dill_scallv(c, (void*)printf, "printf", "%P%p", - " rt_conv_status %lx\n", + " rt_conv_status %p\n", v_at); #ifdef HAVE_DILL_H dill_raw_putreg(c, v_at, DILL_I); @@ -2268,7 +2205,7 @@ int dest_alignment; dill_anduli(c, tmp, args[0], mask); dill_beqli(c, tmp, 0, zero_target); dill_scallv(c, (void*)printf, "printf", "%P%P%p%I", - "convert for %s called with bad align src= %lx, align is %d\n", + "convert for %s called with bad align src= %p, align is %d\n", format_name, args[0], conv->required_alignment); dill_mark_label(c, zero_target); } @@ -2276,8 +2213,8 @@ int dest_alignment; cs.src_pointer_base = 0; cs.dest_pointer_base = 0; - cs.src_offset_adjust = -conv->string_offset_size; - cs.dest_offset_adjust = -conv->string_offset_size; + cs.src_offset_adjust = -(ssize_t)conv->string_offset_size; + cs.dest_offset_adjust = -(ssize_t)conv->string_offset_size; cs.cur_offset = 0; cs.control_value = NULL; cs.target_pointer_size = conv->target_pointer_size; @@ -2295,7 +2232,11 @@ int dest_alignment; dill_free_stream(c); return NULL; } else { + dill_exec_handle conversion_handle; + conversion_handle = dill_finalize(c); + dill_free_handle(conversion_handle); + conversion_handle = dill_get_handle(c); conv->free_data = conversion_handle; conv->free_func = (void(*)(void*))&dill_free_handle; conversion_routine = (void(*)()) dill_get_fp(conversion_handle); @@ -2311,8 +2252,8 @@ int dest_alignment; static void gen_mem_float_conv(dill_stream c, struct _FMgetFieldStruct src, int src_addr, - int src_offset, int assume_align, - int dest_reg, int dest_offset, + size_t src_offset, int assume_align, + int dest_reg, size_t dest_offset, int dest_size, int dst_aligned) { FMfloat_format src_format = (FMfloat_format) src.src_float_format; @@ -2459,17 +2400,9 @@ gen_mem_float_conv(dill_stream c, struct _FMgetFieldStruct src, int src_addr, } static void -gen_simple_field_conv(c, tmp_spec, assume_align, src_addr, src_offset, - dest_size, dest_type, dest_addr, dest_offset) -dill_stream c; -struct _FMgetFieldStruct tmp_spec; -int assume_align; -dill_reg src_addr; -int src_offset; -int dest_size; -FMdata_type dest_type; -dill_reg dest_addr; -int dest_offset; +gen_simple_field_conv(dill_stream c, struct _FMgetFieldStruct tmp_spec, int assume_align, + dill_reg src_addr, size_t src_offset, int dest_size, + FMdata_type dest_type, dill_reg dest_addr, size_t dest_offset) { /* simple conversion */ iogen_oprnd src_oprnd; @@ -2556,25 +2489,11 @@ int dest_offset; } static void -gen_convert_address_field(c, tmp_spec, assume_align, src_addr, src_offset, - dest_size, dest_addr, dest_offset, string_offset_size, - rt_conv_status, base_size_delta, - string_src_reg, string_dest_reg, register_args, null_target) -dill_stream c; -struct _FMgetFieldStruct tmp_spec; -int assume_align; -dill_reg src_addr; -int src_offset; -int dest_size; -dill_reg dest_addr; -int dest_offset; -int string_offset_size; -dill_reg rt_conv_status; -int base_size_delta; -dill_reg *string_src_reg; -dill_reg *string_dest_reg; -int register_args; -int null_target; +gen_convert_address_field(dill_stream c, struct _FMgetFieldStruct tmp_spec, int assume_align, + dill_reg src_addr, size_t src_offset, size_t dest_size, dill_reg dest_addr, + size_t dest_offset, size_t string_offset_size, dill_reg rt_conv_status, + size_t base_size_delta, dill_reg *string_src_reg, dill_reg *string_dest_reg, + int register_args, int null_target) { iogen_oprnd src_oprnd; int src_drisc_type; @@ -2609,7 +2528,7 @@ int null_target; } #ifdef VERBOSE dill_scallv(c, (void*)printf, "printf", "%P%i%p%I", - "Fetched msgptr %d from address %lx offset %d\n", src_oprnd.vc_reg, + "Fetched msgptr %d from address %p offset %d\n", src_oprnd.vc_reg, src_addr, src_offset); #endif @@ -2654,7 +2573,7 @@ int null_target; iogen_oprnd tmp_oprnd; printf("Doing gen size conversion\n"); tmp_oprnd = gen_size_conversion(c, src_oprnd, - dest_size); + (int)dest_size); free_oprnd(c, src_oprnd); src_oprnd = tmp_oprnd; } @@ -2667,19 +2586,10 @@ int null_target; } static void -generate_convert_field(c, conv_status, src_addr, src_offset, - dest_addr, dest_offset, - rt_conv_status, conv, type_desc, data_already_copied) -dill_stream c; -ConvStatus conv_status; -dill_reg src_addr; -int src_offset; -dill_reg dest_addr; -int dest_offset; -dill_reg rt_conv_status; -IOconvFieldStruct *conv; -FMTypeDesc *type_desc; -int data_already_copied; +generate_convert_field(dill_stream c, ConvStatus conv_status, dill_reg src_addr, + size_t src_offset, dill_reg dest_addr, size_t dest_offset, + dill_reg rt_conv_status, IOconvFieldStruct *conv, FMTypeDesc *type_desc, + int data_already_copied) { switch(type_desc->type) { case FMType_pointer: { @@ -2728,7 +2638,7 @@ int data_already_copied; #ifdef VERBOSE dill_scallv(c, (void*)printf, "printf", "%P%p", - "storing POINTER value %lx\n",actual_dest_reg); + "storing POINTER value %p\n",actual_dest_reg); #endif dill_stpi(c, actual_dest_reg, dest_addr, dest_offset); @@ -2750,7 +2660,7 @@ int data_already_copied; if (!data_already_copied) { #ifdef VERBOSE dill_scallv(c, (void*)printf, "printf", "%P%p%p", - "Calling Strcpy with args %lx, %lx\n",actual_dest_reg, actual_src_reg); + "Calling Strcpy with args %p, %p\n",actual_dest_reg, actual_src_reg); #endif dill_scallv(c, (void*)strcpy, "strcpy", "%p%p", actual_dest_reg, actual_src_reg); @@ -2789,7 +2699,7 @@ int data_already_copied; new_src, new_dest)); if (debug_code_generation()) { /* VCALL2V(printf, "%P%p", - "After subroutine call, new src_string_base is %lx\n", src_string_base);*/ + "After subroutine call, new src_string_base is %p\n", src_string_base);*/ } ffs_putreg(c, new_src, DILL_P); ffs_putreg(c, new_dest, DILL_P); @@ -2905,7 +2815,7 @@ int data_already_copied; next = type_desc; while (next->type == FMType_array) { if (next->static_size == 0) { - dill_reg addr_reg = (dill_reg)(long)conv_status->control_value; + dill_reg addr_reg = (dill_reg)(intptr_t)conv_status->control_value; dill_reg val; int field = next->control_field_index; ffs_getreg(c, &val, DILL_I, DILL_TEMP); @@ -2915,7 +2825,7 @@ int data_already_copied; next = next->next; } if (!data_already_copied) { - int base_delta = decode_size_delta(conv_status, conv, next); + ssize_t base_delta = decode_size_delta(conv_status, conv, next); if (conv_status->global_conv->conversion_type == copy_dynamic_portion) { int base_size = item_size(conv_status, conv, next); dill_reg size; @@ -2923,7 +2833,7 @@ int data_already_copied; dill_mulii(c, size, loop_var, base_size); #ifdef VERBOSE dill_scallv(c, (void*)printf, "printf", "%P%p%p", - "Calling Memcpy with args %lx, %lx, %d\n",dest_addr, src_addr, size); + "Calling Memcpy with args %p, %p, %d\n",dest_addr, src_addr, size); #endif dill_scallv(c, (void*)memcpy, "memcpy", "%p%p%i", dest_addr, src_addr, size); @@ -2935,7 +2845,7 @@ int data_already_copied; dill_mulii(c, delta, loop_var, base_delta); #ifdef VERBOSE dill_scallv(c, (void*)printf, "printf", "%P%p", - "Adjusting dest_pointer_base by %lx\n", delta); + "Adjusting dest_pointer_base by %p\n", delta); #endif dill_ldpi(c, dest_src_ptr, rt_conv_status, FMOffset(RTConvStatus,dest_pointer_base)); dill_addp(c, dest_src_ptr, dest_src_ptr, delta); @@ -2944,7 +2854,7 @@ int data_already_copied; } if (debug_code_generation()) { - dill_scallv(c, (void*)printf, "printf", "%P%S%p", + dill_scallv(c, (void*)printf, "printf", "%P%P%p", "format %s, field Initial loopvar = %x\n", conv_status->global_conv->ioformat->body->format_name, loop_var); } @@ -3022,7 +2932,7 @@ int data_already_copied; if (next->static_size != 0) { dill_seti(c, tmp, next->static_size); } else { - dill_reg addr_reg = (dill_reg)(long)conv_status->control_value; + dill_reg addr_reg = (dill_reg)(intptr_t)conv_status->control_value; int field = next->control_field_index; dill_ldii(c, tmp, addr_reg, field*sizeof(int)); } @@ -3055,13 +2965,8 @@ int data_already_copied; } extern void -new_generate_conversion_code(c, conv_status, conv, args, assume_align, register_args) -dill_stream c; -ConvStatus conv_status; -IOConversionPtr conv; -dill_reg *args; -int assume_align; -int register_args; +new_generate_conversion_code(dill_stream c, ConvStatus conv_status, IOConversionPtr conv, dill_reg *args, + int assume_align, int register_args) { int i; dill_reg src_addr = args[0]; @@ -3114,7 +3019,7 @@ int register_args; #else addr_reg = dill_getreg(c, DILL_P); dill_virtual_lea(c, addr_reg, control_base); - conv_status->control_value = (int*)(long)addr_reg; + conv_status->control_value = (size_t*)(intptr_t)addr_reg; } assert(addr_reg != -1); gen_store(c, src_oprnd, addr_reg, field*sizeof(int), @@ -3129,8 +3034,8 @@ int register_args; FMFieldPtr src_spec = &conv->conversions[i].src_field; FMTypeDesc *type_desc = &conv->conversions[i].iovar->type_desc; int byte_swap = conv->conversions[i].src_field.byte_swap; - int dest_offset = conv->conversions[i].dest_offset; - int src_offset = src_spec->offset; + size_t dest_offset = conv->conversions[i].dest_offset; + size_t src_offset = src_spec->offset; int elements = get_static_array_element_count(conv->conversions[i].iovar); if (conv->conversions[i].src_field.size == 1) byte_swap = 0; diff --git a/ffs/ffs_file.c b/ffs/ffs_file.c index afdda325d1..9fbf77dfff 100644 --- a/ffs/ffs_file.c +++ b/ffs/ffs_file.c @@ -4,16 +4,24 @@ #include "assert.h" #include "atl.h" #include "ffs.h" -#include "fm_internal.h" -#include "ffs_internal.h" -#include "strings.h" +#include "string.h" #include "stdio.h" #include "stdlib.h" +#ifndef _MSC_VER #include "unistd.h" +#include +#else +#include +#include +#endif #include "errno.h" #include "string.h" -#include - +#include "sys/types.h" +#include +#include +#include +#include "fm_internal.h" +#include "ffs_internal.h" #include "io_interface.h" typedef struct _CDLLnode { @@ -218,8 +226,7 @@ static FFSRecordType next_record_type(FFSFile ffsfile); static void update_fpos(FFSFile f) { - int fd = (int)(long)f->file_id; - f->fpos = lseek(fd, 0, SEEK_CUR); + f->fpos = ffs_file_lseek_func(f->file_id, 0, SEEK_CUR); } static void @@ -400,20 +407,20 @@ open_FFSfile(const char *path, const char *flags) parse_flags(flags, &allow_input, &allow_output, &raw, &index); if (allow_input && allow_output) { - file = ffs_file_open_func(path, "a", NULL, NULL); + file = (FFSFile) (ffs_file_open_func)(path, "a", NULL, NULL); if (file == (void*)0) { /* if open for append failed, try creating it */ - file = ffs_file_open_func(path, "w", NULL, NULL); + file = (FFSFile)(ffs_file_open_func)(path, "w", NULL, NULL); } } else if (allow_input) { - file = ffs_file_open_func(path, "r", NULL, NULL); + file = (FFSFile)(ffs_file_open_func)(path, "r", NULL, NULL); } else { - file = ffs_file_open_func(path, "w", NULL, NULL); + file = (FFSFile)(ffs_file_open_func)(path, "w", NULL, NULL); } if (file == NULL) { char msg[128]; - (void) sprintf(msg, "open_FFSfile failed for %s :", path); + (void) snprintf(msg, sizeof(msg), "open_FFSfile failed for %s :", path); perror(msg); return NULL; } @@ -434,15 +441,8 @@ FMContext_of_file(FFSFile f) } extern void -set_interface_FFSFile(f, write_func, read_func, writev_func, readv_func, - max_iov, close_func) -FFSFile f; -IOinterface_func write_func; -IOinterface_func read_func; -IOinterface_funcv writev_func; -IOinterface_funcv readv_func; -int max_iov; -IOinterface_close close_func; +set_interface_FFSFile(FFSFile f, IOinterface_func write_func, IOinterface_func read_func, IOinterface_funcv writev_func, + IOinterface_funcv readv_func, int max_iov, IOinterface_close close_func) { f->write_func = write_func; f->read_func = read_func; @@ -481,10 +481,9 @@ static void init_write_index_block(FFSFile f) { int data_index_start = 0; - int fd = (int)(long)f->file_id; off_t end_of_index; if (f->read_index == NULL) { /* if not append */ - end_of_index = lseek(fd, INDEX_BLOCK_SIZE, SEEK_CUR); + end_of_index = ffs_file_lseek_func(f->file_id, INDEX_BLOCK_SIZE, SEEK_CUR); if (f->cur_index) { data_index_start = f->cur_index->write_info.data_index_end; } else { @@ -512,30 +511,29 @@ static void output_index_end(FFSFile f); static void dump_index_block(FFSFile f) { - int fd = (int)(long)f->file_id; - off_t end = lseek(fd, 0, SEEK_CUR); + off_t end = ffs_file_lseek_func(f->file_id, 0, SEEK_CUR); int ret; - int size = f->cur_index->write_info.index_block_size; + size_t size = f->cur_index->write_info.index_block_size; unsigned char *index_base = f->cur_index->write_info.index_block; output_index_end(f); f->cur_index->write_info.data_index_end = f->data_count-1; - lseek(fd, f->cur_index->write_info.base_file_pos, SEEK_SET); + ffs_file_lseek_func(f->file_id, f->cur_index->write_info.base_file_pos, SEEK_SET); /* * next_data indicator is a 2 4-byte chunks in network byte order. * In the first chunk, * the top byte is 0x4, next three are length of the index block. */ - *((int*)index_base) = htonl((0x4<<24) | size); - *((int*)(index_base+4)) = htonl(end); /* link to next index */ - *((int*)(index_base+8)) = htonl(f->cur_index->write_info.data_index_start); /* data_index_start); */ - *((int*)(index_base+12)) = htonl(f->cur_index->write_info.data_index_end); /* data_index_end); */ + *((int*)index_base) = (int) htonl((0x4<<24) | (long)size); + *((int*)(index_base + 4)) = (int)htonl(end); /* link to next index */ + *((int*)(index_base+8)) = (int)htonl(f->cur_index->write_info.data_index_start); /* data_index_start); */ + *((int*)(index_base+12)) = (int)htonl(f->cur_index->write_info.data_index_end); /* data_index_end); */ ret = f->write_func(f->file_id, index_base, size, NULL, NULL); if (ret != size) { printf("Index write failed errno %d\n", errno); } - lseek(fd, end, SEEK_SET); + ffs_file_lseek_func(f->file_id, end, SEEK_SET); init_write_index_block(f); } @@ -797,7 +795,7 @@ write_comment_FFSfile(FFSFile f, const char *comment) { struct iovec vec[2]; - int byte_size = strlen(comment) + 1; + size_t byte_size = strlen(comment) + 1; int indicator; /* * next_comment indicator is a 4-byte chunk in network byte order. @@ -1057,11 +1055,10 @@ FFSread_index(FFSFile ffsfile) char *index_data; FFSIndexItem index_item; off_t index_fpos; - int index_size; - int fd = (int)(long)ffsfile->file_id; - int currentPos = lseek(fd, (size_t)0, SEEK_CUR); - int end = lseek(fd, (size_t)0, SEEK_END); - lseek(fd, currentPos, SEEK_SET); // seek back to original spot + size_t index_size; + int currentPos = ffs_file_lseek_func(ffsfile->file_id, (size_t)0, SEEK_CUR); + int end = ffs_file_lseek_func(ffsfile->file_id, (size_t)0, SEEK_END); + ffs_file_lseek_func(ffsfile->file_id, currentPos, SEEK_SET); // seek back to original spot if (ffsfile->read_ahead == FALSE) { (void) next_record_type(ffsfile); @@ -1150,8 +1147,7 @@ FFSdump_index(FFSIndexItem index_item) extern FFSTypeHandle -FFSnext_type_handle(ffsfile) -FFSFile ffsfile; +FFSnext_type_handle(FFSFile ffsfile) { if (ffsfile->status != OpenForRead) return NULL; @@ -1169,7 +1165,7 @@ FFSFile ffsfile; return ffsfile->next_data_handle; } -extern long +extern size_t FFSfile_next_decode_length(FFSFile iofile) { FFSContext context = iofile->c; @@ -1181,8 +1177,7 @@ FFSfile_next_decode_length(FFSFile iofile) extern char * -FFSread_comment(ffsfile) -FFSFile ffsfile; +FFSread_comment(FFSFile ffsfile) { if (ffsfile->status != OpenForRead) return NULL; @@ -1208,7 +1203,6 @@ FFSFile ffsfile; static int FFSset_fpos(FFSFile file, off_t fpos) { - int fd = (int)(long)file->file_id; /* dangerous to set FPOS if not indexed, but we'll allow it */ if (file->file_org == Indexed) { /* @@ -1224,7 +1218,7 @@ FFSset_fpos(FFSFile file, off_t fpos) last_element = &file->index_tail->elements[last_element_index]; while(fpos > last_element->fpos) { /* don't skip forward past index blocks without reading them */ - if (lseek(fd, file->index_tail->next_index_offset, SEEK_SET) == -1) + if (ffs_file_lseek_func(file->file_id, file->index_tail->next_index_offset, SEEK_SET) == -1) return 0; file->read_ahead = FALSE; (void) FFSread_index(file); @@ -1233,7 +1227,7 @@ FFSset_fpos(FFSFile file, off_t fpos) last_element = &file->index_tail->elements[last_element_index]; } } - if (lseek(fd, fpos, SEEK_SET) == -1) return 0; + if (ffs_file_lseek_func(file->file_id, fpos, SEEK_SET) == -1) return 0; file->read_ahead = FALSE; return 1; } @@ -1245,7 +1239,6 @@ FFSset_fpos(FFSFile file, off_t fpos) extern int FFSseek(FFSFile file, int data_item) { - int fd = (int)(long)file->file_id; struct _FFSIndexItem *index; off_t fpos; int index_item; @@ -1265,7 +1258,7 @@ FFSseek(FFSFile file, int data_item) while (data_item > file->index_tail->last_data_count && file->index_tail != prev_index_tail) { /* don't skip forward past index blocks without reading them */ - if (lseek(fd, file->index_tail->next_index_offset, SEEK_SET) == -1) + if (ffs_file_lseek_func(file->file_id, file->index_tail->next_index_offset, SEEK_SET) == -1) return 0; file->read_ahead = FALSE; prev_index_tail = file->index_tail; @@ -1299,9 +1292,7 @@ FFSseek(FFSFile file, int data_item) static int -get_AtomicInt(file, file_int_ptr) -FFSFile file; -FILE_INT *file_int_ptr; +get_AtomicInt(FFSFile file, FILE_INT *file_int_ptr) { #if SIZEOF_INT == 4 int tmp_value; @@ -1318,11 +1309,10 @@ FILE_INT *file_int_ptr; static void read_all_index_and_formats(FFSFile file) { - int fd = (int)(long)file->file_id; off_t fpos = 1; - int currentPos = lseek(fd, (size_t)0, SEEK_CUR); - int end = lseek(fd, (size_t)0, SEEK_END); - lseek(fd, currentPos, SEEK_SET); // seek back to original spot + int currentPos = ffs_file_lseek_func(file->file_id, (size_t)0, SEEK_CUR); + int end = ffs_file_lseek_func(file->file_id, (size_t)0, SEEK_END); + ffs_file_lseek_func(file->file_id, currentPos, SEEK_SET); // seek back to original spot if (!file->index_head) FFSread_index(file); @@ -1340,7 +1330,7 @@ read_all_index_and_formats(FFSFile file) for (i = 0; i < file->index_tail->elem_count; i++) { if (file->index_tail->elements[i].type == FFSformat) { fpos = file->index_tail->elements[i].fpos; - if (lseek(fd, fpos, SEEK_SET) == -1) + if (ffs_file_lseek_func(file->file_id, fpos, SEEK_SET) == -1) return; (void) FFSread_format(file); } @@ -1348,13 +1338,13 @@ read_all_index_and_formats(FFSFile file) /* skip to next index block */ fpos = file->index_tail->next_index_offset; if (fpos != end) { - if (lseek(fd, fpos, SEEK_SET) == -1) + if (ffs_file_lseek_func(file->file_id, fpos, SEEK_SET) == -1) return; FFSread_index(file); } } - lseek(fd, 0, SEEK_END); - file->fpos = lseek(fd, 0, SEEK_CUR); + ffs_file_lseek_func(file->file_id, 0, SEEK_END); + file->fpos = ffs_file_lseek_func(file->file_id, 0, SEEK_CUR); } static void @@ -1382,14 +1372,12 @@ convert_last_index_block(FFSFile ffsfile) } ffsfile->cur_index->write_info.data_index_start = htonl(*((int*)(index_data+8)));; ffsfile->data_count = read_index->last_data_count + 1; - int fd = (int)(long)ffsfile->file_id; - if (lseek(fd, 0, SEEK_END) == -1) + if (ffs_file_lseek_func(ffsfile->file_id, 0, SEEK_END) == -1) return; } FFSRecordType -FFSnext_record_type(ffsfile) -FFSFile ffsfile; +FFSnext_record_type(FFSFile ffsfile) { FFSRecordType next = next_record_type(ffsfile); while ((next & ffsfile->visible_items_bitmap) != next) { @@ -1408,8 +1396,7 @@ FFSset_visible(FFSFile ffsfile, int bitmap) static FFSRecordType -next_record_type(ffsfile) -FFSFile ffsfile; +next_record_type(FFSFile ffsfile) { FILE_INT indicator_chunk = 0; restart: @@ -1479,11 +1466,10 @@ FFSFile ffsfile; if (!ffsfile->next_actual_handle && ffsfile->index_head) { struct _FFSIndexItem *index = NULL; - int fd = (int)(long)ffsfile->file_id; - off_t fpos_bak = lseek(fd, 0, SEEK_CUR); + off_t fpos_bak = ffs_file_lseek_func(ffsfile->file_id, 0, SEEK_CUR); int fid_len = ffsfile->next_fid_len; char tmp_fid_storage[64]; - int tmp_data_len; + size_t tmp_data_len; int done = 0; assert(sizeof(tmp_fid_storage) > fid_len); /* store away the format ID we've read */ @@ -1501,10 +1487,10 @@ FFSFile ffsfile; !(memcmp(elem->format_id, tmp_buf, ffsfile->next_fid_len))) { - if (lseek(fd, elem->fpos, SEEK_SET) != -1) { + if (ffs_file_lseek_func(ffsfile->file_id, elem->fpos, SEEK_SET) != -1) { ffsfile->read_ahead = FALSE; FFSread_format(ffsfile); - lseek(fd, fpos_bak, SEEK_SET); + ffs_file_lseek_func(ffsfile->file_id, fpos_bak, SEEK_SET); ffsfile->read_ahead = TRUE; ffsfile->next_record_type = FFSdata; /* tmp_buf might have changed */ @@ -1545,7 +1531,7 @@ FFSFile ffsfile; if ((ffsfile->next_data_handle == NULL) && (!ffsfile->raw_flag)) { /* no target for this format, discard */ - int more = ffsfile->next_data_len - ffsfile->next_fid_len; + size_t more = ffsfile->next_data_len - ffsfile->next_fid_len; if (ffsfile->read_func(ffsfile->file_id, tmp_buf + ffsfile->next_fid_len, more, NULL, NULL) != more) { @@ -1574,7 +1560,7 @@ FFSFile ffsfile; ffsfile->next_record_type = FFSindex; ffsfile->next_data_len = indicator_chunk & 0xffffff; /* if (!ffsfile->expose_index) { - lseek((int)(long)ffsfile->file_id, INDEX_BLOCK_SIZE-4, SEEK_CUR); + ffs_file_lseek_func((int)(intptr_t)ffsfile->file_id, INDEX_BLOCK_SIZE-4, SEEK_CUR); ffsfile->read_ahead = FALSE; return next_record_type(ffsfile); }*/ @@ -1589,7 +1575,7 @@ FFSFile ffsfile; return ffsfile->next_record_type; } -extern long +extern size_t FFSnext_data_length(FFSFile file) { if (file->status != OpenForRead) @@ -1608,7 +1594,7 @@ extern int FFSread(FFSFile file, void *dest) { int header_size; - int read_size; + size_t read_size; char *tmp_buf; if (file->status != OpenForRead) @@ -1701,7 +1687,7 @@ FFSread_raw(FFSFile file, void *dest, int buffer_size, FFSTypeHandle *fp) { FFSTypeHandle f; int header_size; - int read_size; + size_t read_size; if (file->status != OpenForRead) return 0; @@ -1732,7 +1718,7 @@ FFSread_raw_header(FFSFile file, void *dest, int buffer_size, FFSTypeHandle *fp) { FFSTypeHandle f; int header_size; - int read_size; + size_t read_size; if (file->status != OpenForRead) return 0; @@ -1767,7 +1753,7 @@ extern int FFSread_to_buffer(FFSFile file, FFSBuffer b, void **dest) { int header_size; - int read_size; + size_t read_size; char *tmp_buf; if (file->status != OpenForRead) diff --git a/ffs/ffs_formats.c b/ffs/ffs_formats.c index 03e98061ac..198f14a60d 100644 --- a/ffs/ffs_formats.c +++ b/ffs/ffs_formats.c @@ -13,7 +13,9 @@ #endif #include #include -extern char *getenv(const char *name); +#ifdef HAVE_STDLIB_H +#include +#endif #ifdef DO_DCG #include "dill.h" @@ -115,8 +117,7 @@ local_size(int field_index, FMFormat f, FMTypeDesc *type, } static int -min_align_size(size) -int size; +min_align_size(int size) { int align_size = 8; /* conservative on current machines */ switch (size) { @@ -138,9 +139,7 @@ int size; } static int -min_align_type(typ, size) -FMdata_type typ; -int size; +min_align_type(FMdata_type typ, int size) { #ifndef DO_DCG return min_align_size(size); diff --git a/ffs/ffs_gen.c b/ffs/ffs_gen.c index a8ea77e398..de770a2a13 100755 --- a/ffs/ffs_gen.c +++ b/ffs/ffs_gen.c @@ -20,13 +20,7 @@ #define gen_fatal(str) do {fprintf(stderr, "%s\n", str); exit(0);} while (0) iogen_oprnd -gen_operand(src_reg, offset, size, data_type, aligned, byte_swap) -dill_reg src_reg; -int offset; -int size; -FMdata_type data_type; -int aligned; -int byte_swap; +gen_operand(dill_reg src_reg, size_t offset, int size, FMdata_type data_type, int aligned, int byte_swap) { iogen_oprnd ret_val; ret_val.address = 1; @@ -41,9 +35,7 @@ int byte_swap; } void -gen_load(c, src_oprnd) -dill_stream c; -iogen_oprnd_ptr src_oprnd; +gen_load(dill_stream c, iogen_oprnd_ptr src_oprnd) { iogen_oprnd tmp_val; tmp_val = gen_fetch(c, @@ -54,13 +46,8 @@ iogen_oprnd_ptr src_oprnd; } iogen_oprnd -gen_bswap_fetch(c, src_reg, offset, size, data_type, aligned) -dill_stream c; -dill_reg src_reg; -int offset; -int size; -FMdata_type data_type; -int aligned; +gen_bswap_fetch(dill_stream c, dill_reg src_reg, size_t offset, + int size, FMdata_type data_type, int aligned) { iogen_oprnd ret_val; ret_val.address = 0; @@ -95,8 +82,8 @@ int aligned; REG_DEBUG(("get %d in gen_Fetch\n", _vrr(ret_val.vc_reg))); dill_ldbsii(c, ret_val.vc_reg, src_reg, offset); break; -#if SIZEOF_LONG != 4 - case SIZEOF_LONG: +#if SIZEOF_SIZE_T != 4 + case SIZEOF_SIZE_T: if (!ffs_getreg(c, &ret_val.vc_reg, DILL_L, DILL_TEMP)) gen_fatal("gen fetch out of registers \n"); REG_DEBUG(("get %d in gen_Fetch\n", _vrr(ret_val.vc_reg))); @@ -167,8 +154,8 @@ int aligned; REG_DEBUG(("get %d in gen_Fetch\n", _vrr(ret_val.vc_reg))); dill_ldbsui(c, ret_val.vc_reg, src_reg, offset); break; -#if SIZEOF_LONG != 4 - case SIZEOF_LONG: +#if SIZEOF_SIZE_T != 4 + case SIZEOF_SIZE_T: if (!ffs_getreg(c, &ret_val.vc_reg, DILL_UL, DILL_TEMP)) gen_fatal("gen fetch out of registers \n"); REG_DEBUG(("get %d in gen_Fetch\n", _vrr(ret_val.vc_reg))); @@ -231,8 +218,8 @@ gen_set(dill_stream c, int size, char* value) REG_DEBUG(("get %d in gen_Fetch\n", _vrr(ret_val.vc_reg))); dill_seti(c, ret_val.vc_reg, *((int*)value)); break; -#if SIZEOF_LONG != 4 - case SIZEOF_LONG: +#if SIZEOF_SIZE_T != 4 + case SIZEOF_SIZE_T: if (!ffs_getreg(c, &ret_val.vc_reg, DILL_L, DILL_TEMP)) gen_fatal("gen fetch out of registers \n"); REG_DEBUG(("get %d in gen_Fetch\n", _vrr(ret_val.vc_reg))); @@ -261,14 +248,8 @@ gen_set(dill_stream c, int size, char* value) } iogen_oprnd -gen_fetch(c, src_reg, offset, size, data_type, aligned, byte_swap) -dill_stream c; -dill_reg src_reg; -int offset; -int size; -FMdata_type data_type; -int aligned; -int byte_swap; +gen_fetch(dill_stream c, dill_reg src_reg, size_t offset, size_t size, + FMdata_type data_type, int aligned, int byte_swap) { iogen_oprnd ret_val; @@ -276,13 +257,13 @@ int byte_swap; if (dill_has_ldbs(c)) { /* have byte swap load extension */ if (byte_swap && (data_type != float_type)) { - return gen_bswap_fetch(c, src_reg, offset, size, data_type, + return gen_bswap_fetch(c, src_reg, offset, (int)size, data_type, aligned); } } #endif ret_val.address = 0; - ret_val.size = size; + ret_val.size = (int)size; ret_val.data_type = data_type; ret_val.offset = 0; ret_val.aligned = 0; @@ -313,8 +294,8 @@ int byte_swap; REG_DEBUG(("get %d in gen_Fetch\n", _vrr(ret_val.vc_reg))); dill_ldii(c, ret_val.vc_reg, src_reg, offset); break; -#if SIZEOF_LONG != 4 - case SIZEOF_LONG: +#if SIZEOF_SIZE_T != 4 + case SIZEOF_SIZE_T: if (!ffs_getreg(c, &ret_val.vc_reg, DILL_L, DILL_TEMP)) gen_fatal("gen fetch out of registers \n"); REG_DEBUG(("get %d in gen_Fetch\n", _vrr(ret_val.vc_reg))); @@ -361,8 +342,8 @@ int byte_swap; REG_DEBUG(("get %d in gen_Fetch\n", _vrr(ret_val.vc_reg))); dill_ldui(c, ret_val.vc_reg, src_reg, offset); break; -#if SIZEOF_LONG != 4 - case SIZEOF_LONG: +#if SIZEOF_SIZE_T != 4 + case SIZEOF_SIZE_T: if (!ffs_getreg(c, &ret_val.vc_reg, DILL_UL, DILL_TEMP)) gen_fatal("gen fetch out of registers \n"); REG_DEBUG(("get %d in gen_Fetch\n", _vrr(ret_val.vc_reg))); @@ -423,9 +404,7 @@ int byte_swap; } void -gen_byte_swap(c, src_oprnd) -dill_stream c; -iogen_oprnd_ptr src_oprnd; +gen_byte_swap(dill_stream c, iogen_oprnd_ptr src_oprnd) { iogen_oprnd swap_oprnd; if (src_oprnd->address) { @@ -460,7 +439,7 @@ iogen_oprnd_ptr src_oprnd; dill_bswapi(c, swap_oprnd.vc_reg, swap_oprnd.vc_reg); break; case 8: - if (sizeof(long) == 4) { + if (sizeof(size_t) == 4) { /* swap top and bottom */ dill_reg tmp_reg = swap_oprnd.vc_reg; swap_oprnd.vc_reg = swap_oprnd.vc_reg2; @@ -491,14 +470,8 @@ iogen_oprnd_ptr src_oprnd; } void -gen_store(c, src, dest_reg, offset, size, data_type, aligned) -dill_stream c; -iogen_oprnd src; -dill_reg dest_reg; -int offset; -int size; -FMdata_type data_type; -int aligned; +gen_store(dill_stream c, iogen_oprnd src, dill_reg dest_reg, ssize_t offset, + int size, FMdata_type data_type, int aligned) { assert(src.size == size); @@ -519,8 +492,8 @@ int aligned; case 4: /* sizeof int */ dill_stii(c, src.vc_reg, dest_reg, offset); break; -#if SIZEOF_LONG != 4 - case SIZEOF_LONG: +#if SIZEOF_SIZE_T != 4 + case SIZEOF_SIZE_T: dill_stli(c, src.vc_reg, dest_reg, offset); break; #else @@ -550,8 +523,8 @@ int aligned; case 4: /* sizeof int */ dill_stui(c, src.vc_reg, dest_reg, offset); break; -#if SIZEOF_LONG != 4 - case SIZEOF_LONG: +#if SIZEOF_SIZE_T != 4 + case SIZEOF_SIZE_T: dill_stuli(c, src.vc_reg, dest_reg, offset); break; #else @@ -586,14 +559,8 @@ int aligned; } void -gen_memcpy(c, src, src_offset, dest, dest_offset, size, const_size) -dill_stream c; -dill_reg src; -int src_offset; -dill_reg dest; -int dest_offset; -dill_reg size; -int const_size; +gen_memcpy(dill_stream c, dill_reg src, size_t src_offset, dill_reg dest, + size_t dest_offset, dill_reg size, int const_size) { dill_reg final_src, final_dest; if (src_offset != 0) { @@ -625,9 +592,7 @@ int const_size; } void -free_oprnd(c, oprnd) -dill_stream c; -iogen_oprnd oprnd; +free_oprnd(dill_stream c, iogen_oprnd oprnd) { REG_DEBUG(("put %d in free\n", _vrr(oprnd.vc_reg))); switch (oprnd.data_type) { @@ -647,8 +612,8 @@ iogen_oprnd oprnd; case 4: /* sizeof int */ ffs_putreg(c, oprnd.vc_reg, DILL_I); break; -#if SIZEOF_LONG != 4 - case SIZEOF_LONG: +#if SIZEOF_SIZE_T != 4 + case SIZEOF_SIZE_T: ffs_putreg(c, oprnd.vc_reg, DILL_L); break; #else @@ -673,8 +638,8 @@ iogen_oprnd oprnd; case 4: /* sizeof int */ ffs_putreg(c, oprnd.vc_reg, DILL_U); break; -#if SIZEOF_LONG != 4 - case SIZEOF_LONG: +#if SIZEOF_SIZE_T != 4 + case SIZEOF_SIZE_T: ffs_putreg(c, oprnd.vc_reg, DILL_UL); break; #else @@ -704,10 +669,7 @@ iogen_oprnd oprnd; } iogen_oprnd -gen_type_conversion(c, src_oprnd, data_type) -dill_stream c; -iogen_oprnd src_oprnd; -FMdata_type data_type; +gen_type_conversion(dill_stream c, iogen_oprnd src_oprnd, FMdata_type data_type) { iogen_oprnd result_oprnd = src_oprnd; dill_reg at; /* temporary */ @@ -718,7 +680,7 @@ FMdata_type data_type; assert(FALSE); break; case integer_type: - result_oprnd.size = sizeof(long); + result_oprnd.size = sizeof(size_t); if (!ffs_getreg(c, &result_oprnd.vc_reg, DILL_L, DILL_TEMP)) gen_fatal("gen type convert out of registers \n"); REG_DEBUG(("get %d in type_convert\n", _vrr(result_oprnd.vc_reg))); @@ -742,7 +704,7 @@ FMdata_type data_type; dill_cvu2l(c, result_oprnd.vc_reg, src_oprnd.vc_reg); break; case 8: -#if SIZEOF_LONG == 8 +#if SIZEOF_SIZE_T == 8 dill_cvul2l(c, result_oprnd.vc_reg, src_oprnd.vc_reg); #else result_oprnd.size = 8; @@ -799,7 +761,7 @@ FMdata_type data_type; dill_cvi2ul(c, result_oprnd.vc_reg, src_oprnd.vc_reg); break; case 8: -#if SIZEOF_LONG == 8 +#if SIZEOF_SIZE_T == 8 dill_cvl2ul(c, result_oprnd.vc_reg, src_oprnd.vc_reg); #else result_oprnd.size = 8; @@ -861,7 +823,7 @@ FMdata_type data_type; ffs_putreg(c, at, DILL_L); break; case 8: -#if SIZEOF_LONG == 8 +#if SIZEOF_SIZE_T == 8 dill_cvl2d(c, result_oprnd.vc_reg, src_oprnd.vc_reg); #else { @@ -900,7 +862,7 @@ FMdata_type data_type; dill_cvi2d(c, result_oprnd.vc_reg, src_oprnd.vc_reg); break; case 8: -#if SIZEOF_LONG == 8 +#if SIZEOF_SIZE_T == 8 dill_cvl2d(c, result_oprnd.vc_reg, src_oprnd.vc_reg); #else { @@ -936,10 +898,7 @@ FMdata_type data_type; } iogen_oprnd -gen_size_conversion(c, src_oprnd, size) -dill_stream c; -iogen_oprnd src_oprnd; -int size; +gen_size_conversion(dill_stream c, iogen_oprnd src_oprnd, int size) { iogen_oprnd result_oprnd = src_oprnd; dill_reg at; /* temporary */ @@ -1001,7 +960,7 @@ int size; } break; case 8: -#if SIZEOF_LONG == 8 +#if SIZEOF_SIZE_T == 8 if (!ffs_getreg(c, &result_oprnd.vc_reg, DILL_L, DILL_TEMP)) gen_fatal("gen size convert out of registers \n"); REG_DEBUG(("get %d in size convert\n", _vrr(result_oprnd.vc_reg))); @@ -1099,7 +1058,7 @@ int size; } break; case 8: -#if SIZEOF_LONG == 8 +#if SIZEOF_SIZE_T == 8 if (!ffs_getreg(c, &result_oprnd.vc_reg, DILL_UL, DILL_TEMP)) gen_fatal("gen size convert out of registers \n"); REG_DEBUG(("get %d in size convert\n", _vrr(result_oprnd.vc_reg))); diff --git a/ffs/ffs_gen.h b/ffs/ffs_gen.h index 623fdfeebb..35356b53d1 100755 --- a/ffs/ffs_gen.h +++ b/ffs/ffs_gen.h @@ -2,7 +2,7 @@ typedef struct { int address; /* if TRUE, reg contains the *address* of the data */ FMdata_type data_type; int size; - int offset; + size_t offset; int aligned; int byte_swap; dill_reg vc_reg; @@ -13,11 +13,11 @@ iogen_oprnd gen_set(dill_stream c, int size, char*value); iogen_oprnd -gen_fetch(dill_stream c, dill_reg src_reg, int offset, int size, +gen_fetch(dill_stream c, dill_reg src_reg, size_t offset, size_t size, FMdata_type data_type, int aligned, int byte_swap); iogen_oprnd -gen_operand(dill_reg src_reg, int offset, int size, +gen_operand(dill_reg src_reg, size_t offset, int size, FMdata_type data_type, int aligned, int byte_swap); void @@ -28,12 +28,12 @@ gen_byte_swap(dill_stream c, iogen_oprnd_ptr src_oprnd); void gen_store(dill_stream c, - iogen_oprnd src, dill_reg dest_reg, int offset, int size, + iogen_oprnd src, dill_reg dest_reg, ssize_t offset, int size, FMdata_type data_type, int aligned); void -gen_memcpy(dill_stream c, dill_reg src, int src_offset, dill_reg dest, - int dest_offset, dill_reg size, int const_size); +gen_memcpy(dill_stream c, dill_reg src, size_t src_offset, dill_reg dest, + size_t dest_offset, dill_reg size, int const_size); void free_oprnd(dill_stream c, iogen_oprnd oprnd); diff --git a/ffs/ffs_internal.h b/ffs/ffs_internal.h index 1a24efb58f..f4e07c7467 100755 --- a/ffs/ffs_internal.h +++ b/ffs/ffs_internal.h @@ -1,5 +1,6 @@ #ifndef FFS_INTERNAL_H #include "../fm/fm.h" +#include "../fm/fm_internal.h" #define MAGIC_NUMBER 0x4356ffa9 /* random magic */ #define REVERSE_MAGIC_NUMBER 0xa9ff5643 /* byte reversed random @@ -25,10 +26,17 @@ extern short bswap_16(short s); extern int bswap_32(int l); #endif +#if defined(_MSC_VER) && !defined(strdup) +#define strdup _strdup +#include +typedef SSIZE_T ssize_t; +#define strncpy(to, from, len) strcpy_s(to, len, from) +#endif + struct _FFSBuffer { void *tmp_buffer; - long tmp_buffer_size; - long tmp_buffer_in_use_size; + ssize_t tmp_buffer_size; + ssize_t tmp_buffer_in_use_size; }; typedef struct _internal_iovec { @@ -67,7 +75,7 @@ struct _FFSTypeHandle { struct _IOgetFieldStruct { int offset; - int size; + size_t size; FMdata_type data_type; unsigned char byte_swap; unsigned char src_float_format; @@ -85,7 +93,7 @@ typedef enum { typedef struct _IOconvFieldStruct { struct _FMgetFieldStruct src_field; FMVarInfoStruct *iovar; - int dest_offset; + ssize_t dest_offset; int dest_size; void *default_value; row_column_swap_type rc_swap; @@ -99,7 +107,7 @@ typedef struct _IOConversionStruct { int notify_of_format_change; FMFieldList native_field_list; int conv_count; - int base_size_delta; /* native size - file record length */ + size_t base_size_delta; /* native size - file record length */ double max_var_expansion; int target_pointer_size; FFSContext context; @@ -112,7 +120,7 @@ typedef struct _IOConversionStruct { conv_routine conv_func2; conv_routine conv_func1; int required_alignment; - int string_offset_size; + size_t string_offset_size; int converted_strings; IOconvFieldStruct conversions[1]; } IOConversionStruct; @@ -191,9 +199,9 @@ extern char * make_tmp_buffer(FFSBuffer buf, int64_t size); -extern int +extern size_t FFS_decode_length_format(FFSContext context, FFSTypeHandle ioformat, - long record_length); + size_t record_length); extern void FFS_determine_conversion(FFSContext c, FFSTypeHandle format); diff --git a/ffs/ffs_marshal.c b/ffs/ffs_marshal.c index d8366236ef..feca64b7c7 100644 --- a/ffs/ffs_marshal.c +++ b/ffs/ffs_marshal.c @@ -95,9 +95,9 @@ install_drop_code(FMFormat f, char *field, char*code_str) * some compilers think it isn't a static initialization to put this * in the structure above, so do it explicitly. */ - externs[0].extern_value = (void *) (long) printf; - externs[1].extern_value = (void *) (long) malloc; - externs[2].extern_value = (void *) (long) free; + externs[0].extern_value = (void *) (intptr_t) printf; + externs[1].extern_value = (void *) (intptr_t) malloc; + externs[2].extern_value = (void *) (intptr_t) free; for (i=0; i< f->field_count; i++) { @@ -169,10 +169,10 @@ install_subsample_code(FMFormat f, char *field, char*code_str) * some compilers think it isn't a static initialization to put this * in the structure above, so do it explicitly. */ - externs[0].extern_value = (void *) (long) printf; - externs[1].extern_value = (void *) (long) malloc; - externs[2].extern_value = (void *) (long) memcpy; - externs[3].extern_value = (void *) (long) copy_array_element; + externs[0].extern_value = (void *) (intptr_t) printf; + externs[1].extern_value = (void *) (intptr_t) malloc; + externs[2].extern_value = (void *) (intptr_t) memcpy; + externs[3].extern_value = (void *) (intptr_t) copy_array_element; for (i=0; i< f->field_count; i++) { diff --git a/ffs/ffs_marshal.h b/ffs/ffs_marshal.h index 1f0bc0ced3..218fdea4e2 100644 --- a/ffs/ffs_marshal.h +++ b/ffs/ffs_marshal.h @@ -22,7 +22,7 @@ get_marshal_info(FMFormat f, FMTypeDesc *t); struct subsample_marshal_data { int element_count; - int element_size; + size_t element_size; void *src_ptr; void *dst_ptr; int marshalled_count; diff --git a/ffs/nt_io.c b/ffs/nt_io.c deleted file mode 100755 index abb6e5e763..0000000000 --- a/ffs/nt_io.c +++ /dev/null @@ -1,352 +0,0 @@ -#include "config.h" -#include -#ifdef HAVE_SYS_UIO_H -#include -#endif -#define FD_SETSIZE 1024 -#include -#include -#include -#include "ffs.h" -#include "io_interface.h" -#include "ffs_internal.h" - -static int -nt_file_read_func(conn, buffer, length, errno_p, result_p) -void *conn; -void *buffer; -int length; -int *errno_p; -char **result_p; -{ - int left = length; - DWORD iget; - BOOL bResult; - bResult = ReadFile(conn, (char *) buffer, length, &iget, NULL); - - if (iget == 0) { - *result_p = "End of file"; - *errno_p = 0; - return 0; /* end of file */ - } else { - if (!bResult) { - *errno_p = GetLastError(); - if ((*errno_p != WSAEWOULDBLOCK) && - (*errno_p != WSAEINPROGRESS) && - (*errno_p != WSAEINTR)) { - /* serious error */ - return -1; - } else { - *errno_p = 0; - iget = 0; - } - } - } - - left = length - iget; - while (left > 0) { - bResult = ReadFile((HANDLE) conn, (char *) buffer + length - left, - left, &iget, NULL); - if (iget == 0) { - *result_p = "End of file"; - *errno_p = 0; - return length - left; /* end of file */ - } else { - if (!bResult) { - *errno_p = GetLastError(); - if ((*errno_p != WSAEWOULDBLOCK) && - (*errno_p != WSAEINPROGRESS) && - (*errno_p != WSAEINTR)) { - /* serious error */ - return (length - left); - } else { - *errno_p = 0; - iget = 0; - } - } - } - left -= iget; - } - return length; -} - -static int -nt_socket_read_func(conn, buffer, length, errno_p, result_p) -void *conn; -void *buffer; -int length; -int *errno_p; -char **result_p; -{ - int left = length; - int iget; - iget = recv((unsigned int) conn, (char *) buffer + length - left, left, 0); - if (iget == 0) { - *result_p = NULL; - *errno_p = 0; - return 0; /* No more socket data */ - } else if (iget == SOCKET_ERROR) { - *errno_p = WSAGetLastError(); - if ((*errno_p != WSAEWOULDBLOCK) && - (*errno_p != WSAEINPROGRESS) && - (*errno_p != WSAECONNRESET) && - (*errno_p != WSAEINTR)) { - /* serious error */ - fprintf(stderr, "WINSOCK ERROR during receive, %i on socket %i\n", - *errno_p, conn); - return -1; - } else { - if (*errno_p == WSAECONNRESET) - return -1; - *errno_p = 0; - iget = 0; - } - } - left = length - iget; - while (left > 0) { - iget = recv((unsigned int) conn, (char *) buffer + length - left, - left, 0); - if (iget == 0) { - *result_p = NULL; - *errno_p = 0; - return length - left; /* no more socket data */ - } else { - if (iget == SOCKET_ERROR) { - *errno_p = WSAGetLastError(); - if ((*errno_p != WSAEWOULDBLOCK) && - (*errno_p != WSAEINPROGRESS) && - (*errno_p != WSAECONNRESET) && - (*errno_p != WSAEINTR)) { - - /* serious error */ - fprintf(stderr, "WINSOCK ERROR during receive2, %i on socket %i\n", - *errno_p, conn); - return (length - left); - } else { - if (*errno_p == WSAECONNRESET) - return -1; - *errno_p = 0; - iget = 0; - } - } - } - left -= iget; - } - - return length; -} - - -static int -nt_file_write_func(conn, buffer, length, errno_p, result_p) -void *conn; -void *buffer; -int length; -int *errno_p; -char **result_p; -{ - int left = length; - int iget = 0; - BOOL bResult; - - while (left > 0) { - bResult = WriteFile((HANDLE) conn, (char *) buffer + length - left, - left, &iget, NULL); - if (!bResult) { - *errno_p = GetLastError(); - if ((*errno_p != WSAEWOULDBLOCK) && - (*errno_p != WSAEINPROGRESS) && - (*errno_p != WSAEINTR)) { - /* serious error */ - return (length - left); - } else { - *errno_p = 0; - iget = 0; - } - } - left -= iget; - } - return length; -} - - -static int -nt_socket_write_func(conn, buffer, length, errno_p, result_p) -void *conn; -void *buffer; -int length; -int *errno_p; -char **result_p; -{ - int left = length; - int iget = 0; - - while (left > 0) { - iget = send((unsigned int) conn, (char *) buffer + length - left, - left, 0); - if (iget == SOCKET_ERROR) { - *errno_p = GetLastError(); - if ((*errno_p != WSAEWOULDBLOCK) && - (*errno_p != WSAEINPROGRESS) && - (*errno_p != WSAEINTR)) { - /* serious error */ - return (length - left); - } else { - *errno_p = 0; - iget = 0; - } - } - left -= iget; - } - return length; -} - - -static int -nt_close_func(conn) -void *conn; -{ - DWORD status; - /* make sure handle exists before we close it. *otherwise -- an * * * - * access error occurs */ - if (GetHandleInformation(conn, &status)) { - CloseHandle((HANDLE) conn); - return 1; - } - return 0; -} - -static void * -nt_file_open_func(path, flag_str) -const char *path; -const char *flag_str; -{ - - void *file; - long tmp_flags = (long)flag_str; - tmp_flags &= ~(O_TRUNC); - tmp_flags &= ~(O_CREAT); - int input = TRUE; - - if (strcmp(flag_str, "r") == 0) { - input = TRUE; - } else if (strcmp(flag_str, "w") == 0) { - input = FALSE; - } else { - fprintf(stderr, "Open flags value not understood for file \"%s\"\n", - path); - return NULL; - } - - if (input) { - file = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL); - - } else { - file = CreateFile(path, GENERIC_WRITE, FILE_SHARE_READ, - NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL); - } - if (file == INVALID_HANDLE_VALUE) { - return NULL; - } else { - return file; - } -} - - -static int -nt_socket_readv_func(conn, iov, icount, errno_p, result_p) -void *conn; -struct iovec *iov; -int icount; -int *errno_p; -char **result_p; -{ - - int i = 0; - for (; i < icount; i++) { - if (nt_socket_read_func(conn, iov[i].iov_base, iov[i].iov_len, - errno_p, result_p) != iov[i].iov_len) { - return i; - } - } - return icount; -} - - -static int -null_file_readv_func(conn, iov, icount, errno_p, result_p) -void *conn; -struct iovec *iov; -int icount; -int *errno_p; -char **result_p; -{ - - int i = 0; - for (; i < icount; i++) { - if (nt_file_read_func(conn, iov[i].iov_base, iov[i].iov_len, errno_p, - result_p) != iov[i].iov_len) { - return i; - } - } - return icount; -} - - -/* Winsock init stuff, ask for ver 1.1 */ -static WORD wVersionRequested = MAKEWORD(1, 1); -static WSADATA wsaData; - -static void -nt_socket_init_func() -{ - int nErrorStatus; - nErrorStatus = WSAStartup(wVersionRequested, &wsaData); - if (nErrorStatus != 0) { - fprintf(stderr, "Could not initialize windows socket library!"); - WSACleanup(); - exit(-1); - } -} - - -static int -nt_poll_func(conn) -void *conn; -{ - int fd = (int) (long) conn; - struct timeval time; - fd_set read_fds; - int ret_val; - - time.tv_sec = time.tv_usec = 0; - FD_ZERO(&read_fds); - FD_SET(fd, &read_fds); - if (fd > FD_SETSIZE) { - fprintf(stderr, "Internal Error, stupid WINSOCK large FD bug.\n"); - fprintf(stderr, "Increase FD_SETSIZE. Item not added to fdset.\n"); - } - ret_val = select(FD_SETSIZE, &read_fds, NULL, NULL, &time); - return (ret_val > 0); -} - -IOinterface_func ffs_file_read_func = (IOinterface_func)nt_file_read_func; -IOinterface_func ffs_file_write_func = (IOinterface_func)nt_file_write_func; -IOinterface_funcv ffs_file_readv_func = (IOinterface_funcv)null_file_readv_func; -IOinterface_funcv ffs_file_writev_func = NULL; - - -IOinterface_func ffs_read_func = (IOinterface_func)nt_socket_read_func; -IOinterface_func ffs_write_func = (IOinterface_func)nt_socket_write_func; -IOinterface_funcv ffs_readv_func = (IOinterface_funcv)nt_socket_readv_func; -IOinterface_funcv ffs_writev_func = NULL; -int ffs_max_iov = 1; - - -IOinterface_open ffs_file_open_func = (IOinterface_open)nt_file_open_func; -IOinterface_close ffs_close_func = (IOinterface_close) nt_close_func; -IOinterface_poll ffs_poll_func = (IOinterface_poll)nt_poll_func; -IOinterface_func ffs_server_read_func = (IOinterface_func)nt_socket_read_func; -IOinterface_func ffs_server_write_func = (IOinterface_func)nt_socket_write_func; -IOinterface_init ffs_sockets_init_func = (IOinterface_init)nt_socket_init_func; diff --git a/ffs/progs/FFScp.c b/ffs/progs/FFScp.c index 9f2cf454da..e2a747e818 100644 --- a/ffs/progs/FFScp.c +++ b/ffs/progs/FFScp.c @@ -23,9 +23,7 @@ write_encoded_FFSfile(FFSFile f, void *data, DATA_LEN_TYPE byte_size, FFSContext attr_list attrs); int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { FFSFile in_file = NULL, out_file = NULL; int buffer_size = 1024; diff --git a/ffs/progs/FFSdump.c b/ffs/progs/FFSdump.c index d6644983a0..cdb3c53c1e 100644 --- a/ffs/progs/FFSdump.c +++ b/ffs/progs/FFSdump.c @@ -30,9 +30,7 @@ extern char * dump_raw_FMrecord_to_string(FMContext fmc, FMFormat format, void *data); int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { FFSFile ffsfile = NULL; int buffer_size = 1024; diff --git a/ffs/progs/FFSsort.c b/ffs/progs/FFSsort.c index e42bf32362..4184d73c71 100755 --- a/ffs/progs/FFSsort.c +++ b/ffs/progs/FFSsort.c @@ -260,9 +260,7 @@ typedef enum { #define combine(a,b) ((int)(a) * 10 + (int)(b)) int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { FFSFile in_file = NULL, out_file = NULL; int buffer_size = 1024; diff --git a/ffs/tests/adios2_bug.c b/ffs/tests/adios2_bug.c index 91c0588351..9f6aa698e3 100644 --- a/ffs/tests/adios2_bug.c +++ b/ffs/tests/adios2_bug.c @@ -532,7 +532,7 @@ void *CP_distributeDataFromRankZero(FFSContext ffs_c, void *root_info, FFSContext context = ffs_c; // FFSTypeHandle ffs_type = FFSTypeHandle_from_encode(context, Buffer); - if (verbose) printf("BUFFER IS AT %p, DataSize is %ld (0x%lx), End is %p\n", Buffer, DataSize, DataSize, Buffer+DataSize); + if (verbose) printf("BUFFER IS AT %p, DataSize is %zu (0x%zx), End is %p\n", Buffer, DataSize, DataSize, Buffer+DataSize); FFSdecode_in_place(context, Buffer, &RetVal); if (verbose) { diff --git a/ffs/tests/context_test.c b/ffs/tests/context_test.c index 0654823a80..19af8d4442 100755 --- a/ffs/tests/context_test.c +++ b/ffs/tests/context_test.c @@ -8,26 +8,34 @@ #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_SYS_UIO_H +#include +#endif #ifdef HAVE_MEMORY_H #include #endif #ifdef HAVE_MALLOC_H #include #endif -#include + #include #include -#include #include "ffs.h" #include "test_funcs.h" +#include +#include + +#if defined(_MSC_VER) +#include "winsock.h" // ntohl +#endif extern void dump_FMFormat(FMFormat ioformat); -static void test_receive(char *buffer, int buf_size, int finished, +static void test_receive(char *buffer, size_t buf_size, int finished, int test_level); -static void test_all_receive(char *buffer, int buf_size, int finished); -static void write_buffer(FMFormat format, char *buf, int size); +static void test_all_receive(char *buffer, size_t buf_size, int finished); +static void write_buffer(FMFormat format, char *buf, size_t size); static void read_test_only(); static int write_output = 0; @@ -41,9 +49,7 @@ static int verbose = 0; static FMContext loaded_FMcontext = NULL; int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { FMContext src_context; FFSBuffer encode_buffer; @@ -66,7 +72,6 @@ char **argv; ninth_rec var_var; string_array_rec str_array; int i, j; -// struct node nodes[10]; FMFormat sixth_rec_ioformat, ninth_rec_ioformat, string_array_ioformat; FMFormat derive_ioformat, multi_array_ioformat, add_action_ioformat; @@ -644,8 +649,7 @@ char **argv; #endif static char * -get_buffer(size_p) -int *size_p; +get_buffer(size_t *size_p) { static int file_fd = 0; static char *buffer = NULL; @@ -671,6 +675,7 @@ int *size_p; } } if(read(file_fd, &indicator, 4) != 4) exit(1); + indicator = ntohl(indicator); if ((indicator >> 24) == 0x2) { /* got a format coming in */ @@ -722,7 +727,7 @@ static void read_test_only() { char *input; - int size; + size_t size; while ((input = get_buffer(&size)) != NULL) { test_all_receive(input, size, 0); } @@ -738,8 +743,7 @@ static FFSTypeHandle multi_array_ioformat, triangle_ioformat, add_action_ioforma static FFSTypeHandle node_ioformat; static void -set_targets(context) -FFSContext context; +set_targets(FFSContext context) { if ((test_only == NULL) || (strcmp(test_only, "first_rec") == 0)) first_rec_ioformat = FFSset_fixed_target(context, first_format_list); @@ -773,26 +777,26 @@ FFSContext context; node_ioformat = FFSset_fixed_target(context, node_format_list); } -int base_size_func(FFSContext context, char *src, int rec_len, - int native_struct_size) +size_t base_size_func(FFSContext context, char *src, size_t rec_len, + size_t native_struct_size) { return native_struct_size; } -int total_size_func(FFSContext context, char *src, int rec_len, - int native_struct_size) +size_t total_size_func(FFSContext context, char *src, size_t rec_len, + size_t native_struct_size) { return FFS_est_decode_length(context, src, rec_len); } static int -decode_in_place(FFSContext context, char *src, int src_len, void *dest) +decode_in_place(FFSContext context, char *src, size_t src_len, void *dest) { if (FFSdecode_in_place_possible(FFSTypeHandle_from_encode(context, src))) { int ret, header_len; char *real_dest; ret = FFSdecode_in_place(context, src, (void**)&real_dest); - header_len = real_dest - src; + header_len = (int)(intptr_t)(real_dest - src); memcpy(dest, real_dest, src_len - header_len); return ret; } else { @@ -801,22 +805,22 @@ decode_in_place(FFSContext context, char *src, int src_len, void *dest) } static int -decode_IOcontext_wrapper(FFSContext context, char *src, int src_len, void *dest) +decode_IOcontext_wrapper(FFSContext context, char *src, size_t src_len, void *dest) { return FFSdecode(context, src, dest); } static int -decode_to_buffer_IOcontext_wrapper(FFSContext context, char *src, int src_len, +decode_to_buffer_IOcontext_wrapper(FFSContext context, char *src, size_t src_len, void *dest) { return FFSdecode_to_buffer(context, src, dest); } -typedef int (*size_func_t)(FFSContext context, char *src, int buf_size, - int nativ_struct); +typedef size_t (*size_func_t)(FFSContext context, char *src, size_t buf_size, + size_t nativ_struct); -typedef int (*decode_func_t)(FFSContext context, char *src, int src_len, +typedef int (*decode_func_t)(FFSContext context, char *src, size_t src_len, void *dest); size_func_t size_funcs[] = {base_size_func, total_size_func, total_size_func}; @@ -828,10 +832,7 @@ decode_func_t decode_funcs[] = {decode_IOcontext_wrapper, #define NUM_TESTS 3 static void -test_all_receive(buffer, buf_size, finished) -char *buffer; -int buf_size; -int finished; +test_all_receive(char *buffer, size_t buf_size, int finished) { int test_type = 0; char *tmp_buffer = malloc(buf_size); @@ -843,8 +844,7 @@ int finished; } static void* -get_mem(size) -int size; +get_mem(size_t size) { char *buffer; unsigned int beef = 0xdeadbeef; @@ -855,9 +855,7 @@ int size; } static void -check_mem(size, buffer) -int size; -char *buffer; +check_mem(size_t size, char *buffer) { unsigned int beef = 0xdeadbeef; if (memcmp(buffer+size, &beef, 4) != 0) { @@ -867,11 +865,7 @@ char *buffer; static void -test_receive(buffer, buf_size, finished, test_level) -char *buffer; -int buf_size; -int finished; -int test_level; +test_receive(char *buffer, size_t buf_size, int finished, int test_level) { static FFSContext c = NULL; /* static int comment_count[NUM_TESTS] = {0,0,0};*/ @@ -941,7 +935,7 @@ int test_level; } */ } else if (((test_only == NULL) || (strcmp(test_only, "second_rec") == 0)) && (buffer_format == second_rec_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, sizeof(second_rec)); + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(second_rec)); second_rec *read_data = get_mem(size); memset(read_data, 0, size); if (!decode_func(rcv_context, buffer, buf_size, read_data)) @@ -954,7 +948,7 @@ int test_level; free(read_data); } else if (((test_only == NULL) || (strcmp(test_only, "third_rec") == 0)) && (buffer_format == third_rec_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, sizeof(third_rec)); + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(third_rec)); third_rec *read_data = get_mem(size); memset(read_data, 0, size); if (!decode_func(rcv_context, buffer, buf_size, read_data)) @@ -967,7 +961,7 @@ int test_level; free(read_data); } else if (((test_only == NULL) || (strcmp(test_only, "fourth_rec") == 0)) && (buffer_format == fourth_rec_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, sizeof(fourth_rec)); + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(fourth_rec)); fourth_rec *read_data = get_mem(size); memset(read_data, 0, size); if (!decode_func(rcv_context, buffer, buf_size, read_data)) @@ -981,7 +975,7 @@ int test_level; fourth_rec_count[test_level]++; } else if (((test_only == NULL) || (strcmp(test_only, "fifth_rec") == 0)) && (buffer_format == fifth_rec_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, sizeof(fifth_rec)); + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(fifth_rec)); fifth_rec *read_data = get_mem(size); memset(read_data, 0, size); if (!decode_func(rcv_context, buffer, buf_size, read_data)) @@ -995,7 +989,7 @@ int test_level; fifth_rec_count[test_level]++; } else if (((test_only == NULL) || (strcmp(test_only, "sixth_rec") == 0)) && (buffer_format == sixth_rec_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, sizeof(sixth_rec)); + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(sixth_rec)); sixth_rec *read_data = get_mem(size); memset(read_data, 0, size); if (!decode_func(rcv_context, buffer, buf_size, read_data)) @@ -1008,7 +1002,7 @@ int test_level; free(read_data); } else if (((test_only == NULL) || (strcmp(test_only, "nested_rec") == 0)) && (buffer_format == nested_rec_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, sizeof(nested_rec)); + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(nested_rec)); nested_rec *read_data = get_mem(size); memset(read_data, 0, size); if (!decode_func(rcv_context, buffer, buf_size, read_data)) @@ -1021,7 +1015,7 @@ int test_level; free(read_data); } else if (((test_only == NULL) || (strcmp(test_only, "later_rec") == 0)) && (buffer_format == later_rec_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, sizeof(later_rec)); + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(later_rec)); later_rec *read_data = get_mem(size); memset(read_data, 0, size); if (!decode_func(rcv_context, buffer, buf_size, read_data)) @@ -1034,7 +1028,7 @@ int test_level; free(read_data); } else if (((test_only == NULL) || (strcmp(test_only, "ninth_rec") == 0)) && (buffer_format == ninth_rec_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, sizeof(ninth_rec)); + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(ninth_rec)); ninth_rec *read_data = get_mem(size); memset(read_data, 0, size); if (!decode_func(rcv_context, buffer, buf_size, read_data)) @@ -1047,7 +1041,7 @@ int test_level; free(read_data); } else if (((test_only == NULL) || (strcmp(test_only, "string_array") == 0)) && (buffer_format == string_array_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(string_array_rec)); string_array_rec *sread_data = get_mem(size); memset(sread_data, 0, size); @@ -1062,7 +1056,7 @@ int test_level; free(sread_data); } else if (((test_only == NULL) || (strcmp(test_only, "derive") == 0)) && (buffer_format == derive_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(DeriveMsg)); DeriveMsgPtr read_data = get_mem(size); memset(read_data, 0, size); @@ -1076,7 +1070,7 @@ int test_level; free(read_data); } else if (((test_only == NULL) || (strcmp(test_only, "multi_array") == 0)) && (buffer_format == multi_array_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(multi_array)); multi_array_rec *read_data = get_mem(size); memset(read_data, 0, size); @@ -1090,7 +1084,7 @@ int test_level; free(read_data); } else if (((test_only == NULL) || (strcmp(test_only, "triangle_param") == 0)) && (buffer_format == triangle_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(multi_array)); triangle_param *read_data = get_mem(size); memset(read_data, 0, size); @@ -1104,7 +1098,7 @@ int test_level; free(read_data); } else if (((test_only == NULL) || (strcmp(test_only, "add_action") == 0)) && (buffer_format == add_action_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(add_rec)); add_rec_ptr read_data = get_mem(size); memset(read_data, 0, size); @@ -1118,7 +1112,7 @@ int test_level; free(read_data); } else if (((test_only == NULL) || (strcmp(test_only, "node") == 0)) && (buffer_format == node_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(add_rec)); node_ptr read_data = get_mem(size); struct visit_table v; @@ -1189,10 +1183,7 @@ static FMFormat seen_formats[100]; static int seen_count = 0; static void -write_buffer(format, buf, size) -FMFormat format; -char *buf; -int size; +write_buffer(FMFormat format, char *buf, size_t size) { static int file_fd = 0; int i; @@ -1213,7 +1204,7 @@ int size; int indicator; int format_len; } format_header; - struct iovec vec[4]; + struct FFSEncodeVec vec[4]; char *server_id; int id_len; char *server_rep; @@ -1241,10 +1232,17 @@ int size; vec[2].iov_base = server_rep; vec[3].iov_len = 0; vec[3].iov_base = NULL; - if (writev(file_fd, vec, 3) == -1) { +#ifndef _MSC_VER + if (writev(file_fd, (const struct iovec *) vec, 3) == -1) { printf("Writev failed\n"); exit(1); } +#else + write(file_fd, vec[0].iov_base, (int)vec[0].iov_len); + write(file_fd, vec[1].iov_base, (int)vec[1].iov_len); + write(file_fd, vec[2].iov_base, (int)vec[2].iov_len); +#endif + seen_formats[seen_count++] = format; } @@ -1255,5 +1253,5 @@ int size; indicator = htonl((size & 0xffffff) | 0x3 << 24); if (write(file_fd, &indicator, 4) != 4) {printf("Write 4 failed\n");exit(1);} - if (write(file_fd, buf, size) != size) {printf("Write size failed\n");exit(1);} + if (write(file_fd, buf, (unsigned int)size) != size) {printf("Write size failed\n");exit(1);} } diff --git a/ffs/tests/context_test2.c b/ffs/tests/context_test2.c index 218a7ba6a8..654dcadc68 100644 --- a/ffs/tests/context_test2.c +++ b/ffs/tests/context_test2.c @@ -19,11 +19,13 @@ #include "ffs.h" #include "test_funcs.h" +#include +#include -static void test_receive(char *buffer, int buf_size, int finished, +static void test_receive(char *buffer, size_t buf_size, int finished, int test_level); -static void test_all_receive(char *buffer, int buf_size, int finished); -static void write_buffer(char *buf, int size); +static void test_all_receive(char *buffer, size_t buf_size, int finished); +static void write_buffer(char *buf, size_t size); static void read_test_only(); static int write_output = 0; @@ -37,9 +39,7 @@ static int verbose = 0; static FMContext loaded_FMcontext = NULL; int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { FMContext src_context; FFSBuffer encode_buffer; @@ -173,8 +173,7 @@ char **argv; #endif static char * -get_buffer(size_p) -int *size_p; +get_buffer(size_t *size_p) { static int file_fd = 0; static char *buffer = NULL; @@ -236,7 +235,7 @@ static void read_test_only() { char *input; - int size; + size_t size; while ((input = get_buffer(&size)) != NULL) { test_all_receive(input, size, 0); } @@ -253,34 +252,33 @@ static FFSTypeHandle psa_ioformat; static FFSTypeHandle reader_register_ioformat; static void -set_targets(context) -FFSContext context; +set_targets(FFSContext context) { node_ioformat = FFSset_fixed_target(context, node_format_list); psa_ioformat = FFSset_fixed_target(context, pointer_to_static_format_list); reader_register_ioformat = FFSset_fixed_target(context, reader_register_format_list); } -int base_size_func(FFSContext context, char *src, int rec_len, - int native_struct_size) +size_t base_size_func(FFSContext context, char *src, size_t rec_len, + size_t native_struct_size) { return native_struct_size; } -int total_size_func(FFSContext context, char *src, int rec_len, - int native_struct_size) +size_t total_size_func(FFSContext context, char *src, size_t rec_len, + size_t native_struct_size) { return FFS_est_decode_length(context, src, rec_len); } static int -decode_in_place(FFSContext context, char *src, int src_len, void *dest) +decode_in_place(FFSContext context, char *src, size_t src_len, void *dest) { if (FFSdecode_in_place_possible(FFSTypeHandle_from_encode(context, src))) { int ret, header_len; char *real_dest; ret = FFSdecode_in_place(context, src, (void**)&real_dest); - header_len = real_dest - src; + header_len = (int)(intptr_t)(real_dest - src); memcpy(dest, real_dest, src_len - header_len); return ret; } else { @@ -289,22 +287,22 @@ decode_in_place(FFSContext context, char *src, int src_len, void *dest) } static int -decode_IOcontext_wrapper(FFSContext context, char *src, int src_len, void *dest) +decode_IOcontext_wrapper(FFSContext context, char *src, size_t src_len, void *dest) { return FFSdecode(context, src, dest); } static int -decode_to_buffer_IOcontext_wrapper(FFSContext context, char *src, int src_len, +decode_to_buffer_IOcontext_wrapper(FFSContext context, char *src, size_t src_len, void *dest) { return FFSdecode_to_buffer(context, src, dest); } -typedef int (*size_func_t)(FFSContext context, char *src, int buf_size, - int nativ_struct); +typedef size_t (*size_func_t)(FFSContext context, char *src, size_t buf_size, + size_t nativ_struct); -typedef int (*decode_func_t)(FFSContext context, char *src, int src_len, +typedef int (*decode_func_t)(FFSContext context, char *src, size_t src_len, void *dest); size_func_t size_funcs[] = {base_size_func, total_size_func, total_size_func}; @@ -316,10 +314,7 @@ decode_func_t decode_funcs[] = {decode_IOcontext_wrapper, #define NUM_TESTS 3 static void -test_all_receive(buffer, buf_size, finished) -char *buffer; -int buf_size; -int finished; +test_all_receive(char *buffer, size_t buf_size, int finished) { int test_type = 0; char *tmp_buffer = malloc(buf_size); @@ -331,8 +326,7 @@ int finished; } static void* -get_mem(size) -int size; +get_mem(size_t size) { char *buffer; unsigned int beef = 0xdeadbeef; @@ -343,9 +337,7 @@ int size; } static void -check_mem(size, buffer) -int size; -char *buffer; +check_mem(size_t size, char *buffer) { unsigned int beef = 0xdeadbeef; if (memcmp(buffer+size, &beef, 4) != 0) { @@ -355,11 +347,7 @@ char *buffer; static void -test_receive(buffer, buf_size, finished, test_level) -char *buffer; -int buf_size; -int finished; -int test_level; +test_receive(char *buffer, size_t buf_size, int finished, int test_level) { static FFSContext c = NULL; static int node_rec_count[NUM_TESTS] = {0,0,0}; @@ -382,7 +370,7 @@ int test_level; } if (((test_only == NULL) || (strcmp(test_only, "node") == 0)) && (buffer_format == node_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(add_rec)); node_ptr read_data = get_mem(size); struct visit_table v; @@ -404,7 +392,7 @@ int test_level; node_rec_count[test_level]++; } else if (((test_only == NULL) || (strcmp(test_only, "psa") == 0)) && (buffer_format == psa_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(add_rec)); pointer_to_static_array_ptr read_data = get_mem(size); memset(read_data, 0, size); @@ -418,7 +406,7 @@ int test_level; free(read_data); } else if (((test_only == NULL) || (strcmp(test_only, "reader_register") == 0)) && (buffer_format == reader_register_ioformat)) { - int size = size_func(rcv_context, buffer, buf_size, + size_t size = size_func(rcv_context, buffer, buf_size, sizeof(add_rec)); struct _reader_register_msg *read_data = get_mem(size); memset(read_data, 0, size); @@ -453,9 +441,7 @@ int test_level; } static void -write_buffer(buf, size) -char *buf; -int size; +write_buffer(char *buf, size_t size) { static int file_fd = 0; unsigned short ssize; @@ -465,11 +451,11 @@ int size; if (file_fd == 0) { file_fd = open(output_file, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0777); } - printf("Writing buffer of size %d\n", size); - ssize = size; + printf("Writing buffer of size %zd\n", size); + ssize = (unsigned short) size; csize = ssize & 0xff; if (write(file_fd, &csize, 1) != 1) exit(1);/* low byte of 2-byte size */ csize = ((ssize >> 8) & 0xff); if (write(file_fd, &csize, 1) != 1) exit(1);/* high byte of 2-byte size */ - if (write(file_fd, buf, size) != size) exit(1); + if (write(file_fd, buf, (int)size) != size) exit(1); } diff --git a/ffs/tests/ffs_file_test.c b/ffs/tests/ffs_file_test.c index 764b2e0aba..da860348b9 100755 --- a/ffs/tests/ffs_file_test.c +++ b/ffs/tests/ffs_file_test.c @@ -19,36 +19,26 @@ static int verbose = 0; static char *test_only = NULL; -int -size_func_sizeof(iofile, size) -FFSFile iofile; -int size; +size_t +size_func_sizeof(FFSFile iofile, size_t size) { return size; } -int -size_func_next_size(iofile, size) -FFSFile iofile; -int size; +size_t +size_func_next_size(FFSFile iofile, size_t size) { return FFSfile_next_decode_length(iofile); } int -read_func_no_buffer(iofile, data, size) -FFSFile iofile; -void *data; -int size; +read_func_no_buffer(FFSFile iofile, void *data, size_t size) { return FFSread(iofile, data); } int -read_func_buffer(iofile, data, size) -FFSFile iofile; -void *data; -int size; +read_func_buffer(FFSFile iofile, void *data, size_t size) { FFSBuffer b = create_fixed_FFSBuffer(data, size); int ret = FFSread_to_buffer(iofile, b, NULL); @@ -65,8 +55,7 @@ static FFSTypeHandle multi_array_ioformat, triangle_ioformat, add_action_ioforma static FFSTypeHandle node_ioformat, embedded_rec_ioformat; static void -set_targets(context) -FFSContext context; +set_targets(FFSContext context) { if ((test_only == NULL) || (strcmp(test_only, "first_rec") == 0)) first_rec_ioformat = FFSset_fixed_target(context, first_format_list); @@ -113,10 +102,7 @@ FFSContext context; } void -do_test(input_file, size_func, read_func) -char *input_file; -int (*size_func) (FFSFile, int); -int (*read_func) (); +do_test(char *input_file, size_t (*size_func) (FFSFile, size_t), int (*read_func) (FFSFile iofile, void *data, size_t size)) { FFSFile iofile; int finished = 0; @@ -186,7 +172,7 @@ int (*read_func) (); exit(1); } } else if (FFSnext_type_handle(iofile) == second_rec_ioformat) { - int size = size_func(iofile, sizeof(second_rec)); + size_t size = size_func(iofile, sizeof(second_rec)); second_rec *read_data = malloc(size); memset(read_data, 0, size); if (!read_func(iofile, read_data, size)) @@ -197,7 +183,7 @@ int (*read_func) (); } free(read_data); } else if (FFSnext_type_handle(iofile) == third_rec_ioformat) { - int size = size_func(iofile, sizeof(third_rec)); + size_t size = size_func(iofile, sizeof(third_rec)); third_rec *read_data = malloc(size); memset(read_data, 0, size); if (!read_func(iofile, read_data, size)) @@ -208,7 +194,7 @@ int (*read_func) (); } free(read_data); } else if (FFSnext_type_handle(iofile) == fourth_rec_ioformat) { - int size = size_func(iofile, sizeof(fourth_rec)); + size_t size = size_func(iofile, sizeof(fourth_rec)); fourth_rec *read_data = malloc(size); memset(read_data, 0, size); if (!read_func(iofile, read_data, size)) @@ -224,7 +210,7 @@ int (*read_func) (); printf("Emb Rec failure\n"); FFSread(iofile, NULL); } else if (FFSnext_type_handle(iofile) == fifth_rec_ioformat) { - int size = size_func(iofile, sizeof(fifth_rec)); + size_t size = size_func(iofile, sizeof(fifth_rec)); fifth_rec *read_data = malloc(size); memset(read_data, 0, size); if (!read_func(iofile, read_data, size)) @@ -236,7 +222,7 @@ int (*read_func) (); free(read_data); fifth_rec_count++; } else if (FFSnext_type_handle(iofile) == sixth_rec_ioformat) { - int size = size_func(iofile, sizeof(sixth_rec)); + size_t size = size_func(iofile, sizeof(sixth_rec)); sixth_rec *read_data = malloc(size); memset(read_data, 0, size); if (!read_func(iofile, read_data, size)) @@ -247,7 +233,7 @@ int (*read_func) (); } free(read_data); } else if (FFSnext_type_handle(iofile) == nested_rec_ioformat) { - int size = size_func(iofile, sizeof(nested_rec)); + size_t size = size_func(iofile, sizeof(nested_rec)); nested_rec *read_data = malloc(size); memset(read_data, 0, size); if (!read_func(iofile, read_data, size)) @@ -258,7 +244,7 @@ int (*read_func) (); } free(read_data); } else if (FFSnext_type_handle(iofile) == later_rec_ioformat) { - int size = size_func(iofile, sizeof(later_rec)); + size_t size = size_func(iofile, sizeof(later_rec)); later_rec *read_data = malloc(size); memset(read_data, 0, size); if (!read_func(iofile, read_data, size)) @@ -269,7 +255,7 @@ int (*read_func) (); } free(read_data); } else if (FFSnext_type_handle(iofile) == ninth_rec_ioformat) { - int size = size_func(iofile, sizeof(ninth_rec)); + size_t size = size_func(iofile, sizeof(ninth_rec)); ninth_rec *read_data = malloc(size); memset(read_data, 0, size); if (!read_func(iofile, read_data, size)) @@ -280,7 +266,7 @@ int (*read_func) (); } free(read_data); } else if (FFSnext_type_handle(iofile) == string_array_ioformat) { - int size = size_func(iofile, sizeof(string_array_rec)); + size_t size = size_func(iofile, sizeof(string_array_rec)); string_array_rec *read_data = malloc(size); memset(read_data, 0, size); if (!read_func(iofile, read_data, size)) @@ -358,9 +344,7 @@ int (*read_func) (); int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { int i; char *input_file = "test_output"; diff --git a/ffs/tests/ffs_index_test.c b/ffs/tests/ffs_index_test.c index c00afdf1d4..ad3ade1801 100644 --- a/ffs/tests/ffs_index_test.c +++ b/ffs/tests/ffs_index_test.c @@ -19,18 +19,14 @@ static int verbose = 0; static char *test_only = NULL; -int -size_func_sizeof(iofile, size) -FFSFile iofile; -int size; +size_t +size_func_sizeof(FFSFile iofile, size_t size) { return size; } -int -size_func_next_size(iofile, size) -FFSFile iofile; -int size; +size_t +size_func_next_size(FFSFile iofile, size_t size) { return FFSfile_next_decode_length(iofile); } @@ -38,19 +34,13 @@ int size; attr_list last_attrs = NULL; int -read_func_no_buffer(iofile, data, size) -FFSFile iofile; -void *data; -int size; +read_func_no_buffer(FFSFile iofile, void *data, size_t size) { return FFSread_attr(iofile, data, &last_attrs); } int -read_func_buffer(iofile, data, size) -FFSFile iofile; -void *data; -int size; +read_func_buffer(FFSFile iofile, void *data, size_t size) { FFSBuffer b = create_fixed_FFSBuffer(data, size); int ret = FFSread_to_buffer(iofile, b, NULL); @@ -68,8 +58,7 @@ static FFSTypeHandle multi_array_ioformat, triangle_ioformat, add_action_ioforma static FFSTypeHandle node_ioformat, embedded_rec_ioformat; static void -set_targets(context) -FFSContext context; +set_targets(FFSContext context) { if ((test_only == NULL) || (strcmp(test_only, "first_rec") == 0)) first_rec_ioformat = FFSset_fixed_target(context, first_format_list); @@ -116,10 +105,7 @@ FFSContext context; } void -do_test(input_file, size_func, read_func) -char *input_file; -int (*size_func) (FFSFile, int); -int (*read_func) (); +do_test(char *input_file, size_t (*size_func) (FFSFile, size_t), int (*read_func) (FFSFile iofile, void *data, size_t size)) { FFSFile iofile; int item_count = 0; @@ -217,7 +203,7 @@ int (*read_func) (); exit(1); } } else if (FFSnext_type_handle(iofile) == second_rec_ioformat) { - int size = size_func(iofile, sizeof(second_rec)); + size_t size = size_func(iofile, sizeof(second_rec)); second_rec *read_data = malloc(size); int iter_attr = -1; memset(read_data, 0, size); @@ -235,7 +221,7 @@ int (*read_func) (); second_rec_count++; free(read_data); } else if (FFSnext_type_handle(iofile) == third_rec_ioformat) { - int size = size_func(iofile, sizeof(third_rec)); + size_t size = size_func(iofile, sizeof(third_rec)); third_rec *read_data = malloc(size); int iter_attr = -1; memset(read_data, 0, size); @@ -250,7 +236,7 @@ int (*read_func) (); free(read_data); third_rec_count++; } else if (FFSnext_type_handle(iofile) == fourth_rec_ioformat) { - int size = size_func(iofile, sizeof(fourth_rec)); + size_t size = size_func(iofile, sizeof(fourth_rec)); fourth_rec *read_data = malloc(size); memset(read_data, 0, size); if (!read_func(iofile, read_data, size)) @@ -266,7 +252,7 @@ int (*read_func) (); printf("Emb Rec failure\n"); FFSread(iofile, NULL); } else if (FFSnext_type_handle(iofile) == fifth_rec_ioformat) { - int size = size_func(iofile, sizeof(fifth_rec)); + size_t size = size_func(iofile, sizeof(fifth_rec)); fifth_rec *read_data = malloc(size); int iter_attr = -1; memset(read_data, 0, size); @@ -280,7 +266,7 @@ int (*read_func) (); free(read_data); fifth_rec_count++; } else if (FFSnext_type_handle(iofile) == sixth_rec_ioformat) { - int size = size_func(iofile, sizeof(sixth_rec)); + size_t size = size_func(iofile, sizeof(sixth_rec)); sixth_rec *read_data = malloc(size); memset(read_data, 0, size); if (!read_func(iofile, read_data, size)) @@ -291,7 +277,7 @@ int (*read_func) (); } free(read_data); } else if (FFSnext_type_handle(iofile) == nested_rec_ioformat) { - int size = size_func(iofile, sizeof(nested_rec)); + size_t size = size_func(iofile, sizeof(nested_rec)); nested_rec *read_data = malloc(size); memset(read_data, 0, size); if (!read_func(iofile, read_data, size)) @@ -303,7 +289,7 @@ int (*read_func) (); } free(read_data); } else if (FFSnext_type_handle(iofile) == later_rec_ioformat) { - int size = size_func(iofile, sizeof(later_rec)); + size_t size = size_func(iofile, sizeof(later_rec)); later_rec *read_data = malloc(size); memset(read_data, 0, size); if (!read_func(iofile, read_data, size)) @@ -314,7 +300,7 @@ int (*read_func) (); } free(read_data); } else if (FFSnext_type_handle(iofile) == ninth_rec_ioformat) { - int size = size_func(iofile, sizeof(ninth_rec)); + size_t size = size_func(iofile, sizeof(ninth_rec)); ninth_rec *read_data = malloc(size); memset(read_data, 0, size); if (!read_func(iofile, read_data, size)) @@ -325,7 +311,7 @@ int (*read_func) (); } free(read_data); } else if (FFSnext_type_handle(iofile) == string_array_ioformat) { - int size = size_func(iofile, sizeof(string_array_rec)); + size_t size = size_func(iofile, sizeof(string_array_rec)); string_array_rec *read_data = malloc(size); memset(read_data, 0, size); if (!read_func(iofile, read_data, size)) @@ -405,9 +391,7 @@ int (*read_func) (); int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { int i; char *input_file = "test_output"; diff --git a/ffs/tests/ffs_write.c b/ffs/tests/ffs_write.c index 6189042627..048c267cb7 100755 --- a/ffs/tests/ffs_write.c +++ b/ffs/tests/ffs_write.c @@ -102,7 +102,7 @@ main(int argc, char **argv) str_list[0].opt_info = &opt_info[0]; str_list[1].format_name = NULL; - opt_info[0].info_len = strlen(first_xml) +1; + opt_info[0].info_len = (int)strlen(first_xml) +1; opt_info[0].info_block = first_xml; first_rec_ioformat = register_data_format(src_context, str_list); str_list[0].format_name = "string format"; @@ -110,7 +110,7 @@ main(int argc, char **argv) str_list[0].struct_size = sizeof(second_rec); str_list[0].opt_info = &opt_info[0]; str_list[1].format_name = NULL; - opt_info[0].info_len = strlen(string_xml) +1; + opt_info[0].info_len = (int)strlen(string_xml) +1; opt_info[0].info_block = string_xml; second_rec_ioformat = register_data_format(src_context, str_list); @@ -119,7 +119,7 @@ main(int argc, char **argv) str_list[0].struct_size = sizeof(third_rec); str_list[0].opt_info = &opt_info[0]; str_list[1].format_name = NULL; - opt_info[0].info_len = strlen(third_xml) +1; + opt_info[0].info_len = (int)strlen(third_xml) +1; opt_info[0].info_block = third_xml; third_rec_ioformat = register_data_format(src_context, str_list); @@ -128,7 +128,7 @@ main(int argc, char **argv) str_list[0].struct_size = sizeof(fourth_rec); str_list[0].opt_info = &opt_info[0]; str_list[1].format_name = NULL; - opt_info[0].info_len = strlen(fourth_xml) +1; + opt_info[0].info_len = (int)strlen(fourth_xml) +1; opt_info[0].info_block = fourth_xml; fourth_rec_ioformat = register_data_format(src_context, str_list); @@ -137,7 +137,7 @@ main(int argc, char **argv) str_list[0].struct_size = sizeof(embedded_rec); str_list[0].opt_info = &opt_info[0]; str_list[1].format_name = NULL; - opt_info[0].info_len = strlen(embedded_xml) +1; + opt_info[0].info_len = (int)strlen(embedded_xml) +1; opt_info[0].info_block = embedded_xml; embedded_rec_ioformat = register_data_format(src_context, str_list); @@ -153,10 +153,10 @@ main(int argc, char **argv) str_list[1].struct_size = sizeof(second_rec); str_list[1].opt_info = &opt_info2[0]; str_list[2].format_name = NULL; - opt_info[0].info_len = strlen(var_array_xml) +1; + opt_info[0].info_len = (int)strlen(var_array_xml) +1; opt_info[0].info_block = var_array_xml; opt_info2[0].info_type = 0x584D4C20; /* XML */ - opt_info2[0].info_len = strlen(string_xml) +1; + opt_info2[0].info_len = (int)strlen(string_xml) +1; opt_info2[0].info_block = string_xml; opt_info2[1].info_type = 0; opt_info2[1].info_len = 0; @@ -276,7 +276,7 @@ main(int argc, char **argv) str_list[0].opt_info = &opt_info[0]; str_list[1].format_name = NULL; - opt_info[0].info_len = strlen(first_xml) +1; + opt_info[0].info_len = (int)strlen(first_xml) +1; opt_info[0].info_block = first_xml; first_rec_ioformat = register_data_format(src_context, str_list); @@ -286,7 +286,7 @@ main(int argc, char **argv) str_list[0].struct_size = sizeof(second_rec); str_list[0].opt_info = &opt_info[0]; str_list[1].format_name = NULL; - opt_info[0].info_len = strlen(string_xml) +1; + opt_info[0].info_len = (int)strlen(string_xml) +1; opt_info[0].info_block = string_xml; second_rec_ioformat = register_data_format(src_context, str_list); @@ -295,7 +295,7 @@ main(int argc, char **argv) str_list[0].struct_size = sizeof(third_rec); str_list[0].opt_info = &opt_info[0]; str_list[1].format_name = NULL; - opt_info[0].info_len = strlen(third_xml) +1; + opt_info[0].info_len = (int)strlen(third_xml) +1; opt_info[0].info_block = third_xml; third_rec_ioformat = register_data_format(src_context, str_list); @@ -304,7 +304,7 @@ main(int argc, char **argv) str_list[0].struct_size = sizeof(fourth_rec); str_list[0].opt_info = &opt_info[0]; str_list[1].format_name = NULL; - opt_info[0].info_len = strlen(fourth_xml) +1; + opt_info[0].info_len = (int)strlen(fourth_xml) +1; opt_info[0].info_block = fourth_xml; fourth_rec_ioformat = register_data_format(src_context, str_list); @@ -313,7 +313,7 @@ main(int argc, char **argv) str_list[0].struct_size = sizeof(embedded_rec); str_list[0].opt_info = &opt_info[0]; str_list[1].format_name = NULL; - opt_info[0].info_len = strlen(embedded_xml) +1; + opt_info[0].info_len = (int)strlen(embedded_xml) + 1; opt_info[0].info_block = embedded_xml; embedded_rec_ioformat = register_data_format(src_context, str_list); (void)embedded_rec_ioformat; @@ -329,10 +329,10 @@ main(int argc, char **argv) str_list[1].struct_size = sizeof(second_rec); str_list[1].opt_info = &opt_info2[0]; str_list[2].format_name = NULL; - opt_info[0].info_len = strlen(var_array_xml) +1; + opt_info[0].info_len = (int)strlen(var_array_xml) +1; opt_info[0].info_block = var_array_xml; opt_info2[0].info_type = 0x584D4C20; /* XML */ - opt_info2[0].info_len = strlen(string_xml) +1; + opt_info2[0].info_len = (int)strlen(string_xml) +1; opt_info2[0].info_block = string_xml; opt_info2[1].info_type = 0; opt_info2[1].info_len = 0; @@ -346,7 +346,7 @@ main(int argc, char **argv) str_list[0].struct_size = sizeof(later_rec); str_list[0].opt_info = NULL; str_list[1].format_name = NULL; - opt_info[0].info_len = strlen(later_xml) +1; + opt_info[0].info_len = (int)strlen(later_xml) +1; opt_info[0].info_block = later_xml; later_ioformat = register_data_format(src_context, str_list); @@ -359,7 +359,7 @@ main(int argc, char **argv) str_list[1].struct_size = sizeof(second_rec); str_list[1].opt_info = &opt_info2[0]; str_list[2].format_name = NULL; - opt_info[0].info_len = strlen(nested_xml) +1; + opt_info[0].info_len = (int)strlen(nested_xml) +1; opt_info[0].info_block = nested_xml; nested_ioformat = register_data_format(src_context, str_list); @@ -433,7 +433,7 @@ main(int argc, char **argv) str_list[0].struct_size = sizeof(later_rec); str_list[0].opt_info = &opt_info[0]; str_list[1].format_name = NULL; - opt_info[0].info_len = strlen(later2_xml) +1; + opt_info[0].info_len = (int)strlen(later2_xml) +1; opt_info[0].info_block = later2_xml; later_ioformat = register_data_format(src_context, str_list); @@ -506,10 +506,10 @@ main(int argc, char **argv) str_list[1].struct_size = sizeof(struct _io_encode_vec); str_list[1].opt_info = &opt_info2[0]; str_list[2].format_name = NULL; - opt_info[0].info_len = strlen(event_xml) +1; + opt_info[0].info_len = (int)strlen(event_xml) +1; opt_info[0].info_block = event_xml; - opt_info2[0].info_len = strlen(event_vec_xml) +1; + opt_info2[0].info_len = (int)strlen(event_vec_xml) +1; opt_info2[0].info_block = event_vec_xml; ninth_rec_ioformat = register_data_format(src_context, str_list); diff --git a/ffs/tests/fortran_test.c b/ffs/tests/fortran_test.c index 5a2d8a77c0..a3948ac671 100755 --- a/ffs/tests/fortran_test.c +++ b/ffs/tests/fortran_test.c @@ -20,10 +20,13 @@ #include "test_funcs.h" -static void test_receive (char *buffer, int buf_size, int finished, +#include +#include + +static void test_receive (char *buffer, size_t buf_size, int finished, int test_level); -static void test_all_receive (char *buffer, int buf_size, int finished); -static void write_buffer (char *buf, int size); +static void test_all_receive (char *buffer, size_t buf_size, int finished); +static void write_buffer (char *buf, size_t size); static void read_test_only(); static int write_output = 0; @@ -35,9 +38,7 @@ static char *test_only = NULL; static FFSContext rcv_context = NULL; int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { FMContext src_context; FFSBuffer buffer; @@ -75,7 +76,7 @@ char **argv; if (fail) exit(1); exit(0); } - src_context = create_FMcontext(NULL); + src_context = create_FMcontext(); set_array_order_FMContext(src_context, 1); fortran_array_ioformat = register_data_format(src_context, @@ -104,8 +105,7 @@ char **argv; #endif static char * -get_buffer(size_p) -int *size_p; +get_buffer(int *size_p) { static int file_fd = 0; static char *buffer = NULL; @@ -175,33 +175,32 @@ read_test_only() static FFSTypeHandle multi_array_ioformat; static void -set_targets(context) -FFSContext context; +set_targets(FFSContext context) { multi_array_ioformat = FFSset_fixed_target(context, multi_array_format_list); } -int base_size_func(FFSContext context, char *src, int rec_len, - int native_struct_size) +size_t base_size_func(FFSContext context, char *src, size_t rec_len, + size_t native_struct_size) { return native_struct_size; } -int total_size_func(FFSContext context, char *src, int rec_len, - int native_struct_size) +size_t total_size_func(FFSContext context, char *src, size_t rec_len, + size_t native_struct_size) { return FFS_est_decode_length(context, src, rec_len); } static int -decode_in_place(FFSContext context, char *src, int src_len, void *dest) +decode_in_place(FFSContext context, char *src, size_t src_len, void *dest) { if (FFSdecode_in_place_possible(FFSTypeHandle_from_encode(context, src))) { int ret, header_len; char *real_dest; ret = FFSdecode_in_place(context, src, (void**)&real_dest); - header_len = real_dest - src; + header_len = (int)(intptr_t)(real_dest - src); memcpy(dest, real_dest, src_len - header_len); return ret; } else { @@ -210,22 +209,22 @@ decode_in_place(FFSContext context, char *src, int src_len, void *dest) } static int -decode_IOcontext_wrapper(FFSContext context, char *src, int src_len, void *dest) +decode_IOcontext_wrapper(FFSContext context, char *src, size_t src_len, void *dest) { return FFSdecode(context, src, dest); } static int -decode_to_buffer_IOcontext_wrapper(FFSContext context, char *src, int src_len, +decode_to_buffer_IOcontext_wrapper(FFSContext context, char *src, size_t src_len, void *dest) { return FFSdecode_to_buffer(context, src, dest); } -typedef int (*size_func_t)(FFSContext context, char *src, int buf_size, - int nativ_struct); +typedef size_t (*size_func_t)(FFSContext context, char *src, size_t buf_size, + size_t nativ_struct); -typedef int (*decode_func_t)(FFSContext context, char *src, int src_len, +typedef int (*decode_func_t)(FFSContext context, char *src, size_t src_len, void *dest); size_func_t size_funcs[] = {base_size_func, total_size_func, total_size_func}; @@ -237,10 +236,7 @@ decode_func_t decode_funcs[] = {decode_IOcontext_wrapper, #define NUM_TESTS 3 static void -test_all_receive(buffer, buf_size, finished) -char *buffer; -int buf_size; -int finished; +test_all_receive(char *buffer, size_t buf_size, int finished) { int test_type = 0; char *tmp_buffer = malloc(buf_size); @@ -252,8 +248,7 @@ int finished; } static void* -get_mem(size) -int size; +get_mem(size_t size) { char *buffer; unsigned int beef = 0xdeadbeef; @@ -264,9 +259,7 @@ int size; } static void -check_mem(size, buffer) -int size; -char *buffer; +check_mem(size_t size, char *buffer) { unsigned int beef = 0xdeadbeef; if (memcmp(buffer+size, &beef, 4) != 0) { @@ -276,11 +269,7 @@ char *buffer; static void -test_receive(buffer, buf_size, finished, test_level) -char *buffer; -int buf_size; -int finished; -int test_level; +test_receive(char *buffer, size_t buf_size, int finished, int test_level) { static FFSContext c = NULL; @@ -300,7 +289,7 @@ int test_level; exit(1); } if (buffer_format == multi_array_ioformat) { - int size = size_func(c, buffer, buf_size, + size_t size = size_func(c, buffer, buf_size, sizeof(multi_array)); multi_array_rec2 *read_data = get_mem(size); memset(read_data, 0, size); @@ -331,9 +320,7 @@ int test_level; } static void -write_buffer(buf, size) -char *buf; -int size; +write_buffer(char *buf, size_t size) { static int file_fd = 0; unsigned short ssize; @@ -343,10 +330,10 @@ int size; if (file_fd == 0) { file_fd = open(output_file, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0777); } - ssize = size; + ssize = (unsigned short) size; csize = ssize & 0xff; if (write(file_fd, &csize, 1) != 1) exit(1);/* low byte of 2-byte size */ csize = ((ssize >> 8) & 0xff); if (write(file_fd, &csize, 1) != 1) exit(1);/* high byte of 2-byte size */ - if (write(file_fd, buf, size) != size) exit(1); + if (write(file_fd, buf, (int)size) != size) exit(1); } diff --git a/ffs/tests/get_set_test.c b/ffs/tests/get_set_test.c index 108dc67aa3..53727d7aeb 100644 --- a/ffs/tests/get_set_test.c +++ b/ffs/tests/get_set_test.c @@ -26,9 +26,7 @@ */ int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { third_rec test_rec; void *data_ptr, *tmp_ptr, *encode_buffer, *base_data; diff --git a/ffs/tests/marshal_test.c b/ffs/tests/marshal_test.c index a5068a57f9..106dc2e016 100644 --- a/ffs/tests/marshal_test.c +++ b/ffs/tests/marshal_test.c @@ -4,7 +4,9 @@ #include #include #include +#ifndef _MSC_VER #include +#endif #include "ffs.h" typedef struct _second_rec { diff --git a/ffs/tests/marshal_test2.c b/ffs/tests/marshal_test2.c index 397859ad0a..b9a44ed947 100644 --- a/ffs/tests/marshal_test2.c +++ b/ffs/tests/marshal_test2.c @@ -4,7 +4,9 @@ #include #include #include +#ifndef _MSC_VER #include +#endif #include "ffs.h" extern void diff --git a/ffs/tests/no_leaf_test.c b/ffs/tests/no_leaf_test.c index cda3212781..3316ccb64e 100644 --- a/ffs/tests/no_leaf_test.c +++ b/ffs/tests/no_leaf_test.c @@ -84,9 +84,7 @@ FMStructDescRec data_struct_list[] = { }; int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { data_struct data; void *encode_buffer, *base_of_encoded_array1, *base_of_encoded_array2; @@ -106,8 +104,8 @@ char **argv; /* setup a test record to play with */ data.s1.x = data.s2.x = data.x = 10; data.s1.y = data.y = 5; - data.s1.array1 = (void*)(0xdeadbeef); /* should get a seg fault if we dereference this */ - data.s2.array2 = (void*)(0xD15EA5E); /* should get a seg fault if we dereference this */ + data.s1.array1 = (void*)(intptr_t)(0xdeadbeef); /* should get a seg fault if we dereference this */ + data.s2.array2 = (void*)(intptr_t)(0xD15EA5E); /* should get a seg fault if we dereference this */ /* register a format so we can do more stuff */ @@ -124,11 +122,11 @@ char **argv; cod_set_return_type("Struct_array1", cod_context); gen_code1 = cod_code_gen("{return encode.s1.array1;}", cod_context); - func1 = (void*(*)(void*)) (long) gen_code1->func; + func1 = (void*(*)(void*)) (intptr_t) gen_code1->func; base_of_encoded_array1 = func1(encode_buffer); gen_code2 = cod_code_gen("{return encode.s2.array2;}", cod_context); - func2 = (void*(*)(void*)) (long) gen_code2->func; + func2 = (void*(*)(void*)) (intptr_t) gen_code2->func; base_of_encoded_array2 = func2(encode_buffer); for (x=0; x < 10; x++) { diff --git a/ffs/tests/test_file_unique.c b/ffs/tests/test_file_unique.c index 1c8c99161c..a7e3b908f2 100644 --- a/ffs/tests/test_file_unique.c +++ b/ffs/tests/test_file_unique.c @@ -35,9 +35,7 @@ file_checksum(char *filename) } int -main(argc,argv) -int argc; -char **argv; +main(int argc, char **argv) { unsigned int base_sum, sum; int i, found_match = 0; diff --git a/ffs/tests/test_funcs.c b/ffs/tests/test_funcs.c index 0f3ebe3af4..abe485022f 100755 --- a/ffs/tests/test_funcs.c +++ b/ffs/tests/test_funcs.c @@ -153,8 +153,7 @@ char *event_vec_xml = "\ \n"; int -first_rec_eq(r1, r2) -first_rec *r1, *r2; +first_rec_eq(first_rec *r1, first_rec *r2) { if (r1->integer_field != r2->integer_field) return 0; @@ -166,8 +165,7 @@ first_rec *r1, *r2; } int -second_rec_eq(r1, r2) -second_rec *r1, *r2; +second_rec_eq(second_rec *r1, second_rec *r2) { if (r1->integer_field != r2->integer_field) { printf("integer_field 1 is %d (0x%x), integer_field 2 is %d (0x%x)\n", @@ -210,8 +208,7 @@ second_rec *r1, *r2; } int -third_rec_eq(r1, r2) -third_rec *r1, *r2; +third_rec_eq(third_rec *r1, third_rec *r2) { if (r1->integer_field != r2->integer_field) { printf("integer field 1 is %d (0x%x), integer_field 2 is %d (0x%x)\n", @@ -285,8 +282,7 @@ third_rec *r1, *r2; #define ARRAY_SIZE 14 int -fourth_rec_eq(r1, r2) -fourth_rec *r1, *r2; +fourth_rec_eq(fourth_rec *r1, fourth_rec *r2) { int i, j; if (r1->ifield != r2->ifield) { @@ -311,8 +307,7 @@ fourth_rec *r1, *r2; } int -emb_rec_eq(r1, r2) -embedded_rec *r1, *r2; +emb_rec_eq(embedded_rec *r1, embedded_rec *r2) { if (r1->ifield != r2->ifield) { printf("ifield 1 is %d (%x), ifield 2 is %d (%x)\n", @@ -343,8 +338,7 @@ embedded_rec *r1, *r2; } int -fifth_rec_eq(r1, r2) -fifth_rec *r1, *r2; +fifth_rec_eq(fifth_rec *r1, fifth_rec *r2) { int i; for (i = 0; i < 4; i++) { @@ -357,8 +351,7 @@ fifth_rec *r1, *r2; } int -sixth_rec_eq(r1, r2) -sixth_rec *r1, *r2; +sixth_rec_eq(sixth_rec *r1, sixth_rec *r2) { int i; if (r1->icount != r2->icount) @@ -403,8 +396,7 @@ sixth_rec *r1, *r2; } int -nested_rec_eq(r1, r2) -nested_rec *r1, *r2; +nested_rec_eq(nested_rec *r1, nested_rec *r2) { if (r1->integer_field != r2->integer_field) { printf("nested, R1 integer = %d, R2 %d\n", r1->integer_field, @@ -434,8 +426,7 @@ nested_rec *r1, *r2; } int -later_rec_eq(r1, r2) -later_rec *r1, *r2; +later_rec_eq(later_rec *r1, later_rec *r2) { if (r1->integer_field != r2->integer_field) return 0; @@ -453,8 +444,7 @@ later_rec *r1, *r2; } int -ninth_rec_eq(r1, r2) -ninth_rec *r1, *r2; +ninth_rec_eq(ninth_rec *r1, ninth_rec *r2) { int i; if (r1->vec_length != r2->vec_length) @@ -473,8 +463,7 @@ ninth_rec *r1, *r2; } int -string_array_eq(r1, r2) -string_array_rec *r1, *r2; +string_array_eq(string_array_rec *r1, string_array_rec *r2) { int i; if (r1->array_len != r2->array_len) @@ -1488,13 +1477,13 @@ init_written_data() reader_pointer_array[0] = malloc(sizeof(struct _cp_init_info)); reader_pointer_array[0]->contact_info = "contact info 1"; reader_pointer_array[0]->target_stone = 101; - reader_pointer_array[0]->reader_ID = (void*)0xdead0001; + reader_pointer_array[0]->reader_ID = (void*)(intptr_t)0xdead0001; reader_pointer_array[1] = malloc(sizeof(struct _cp_init_info)); reader_pointer_array[1]->contact_info = "contact info 2"; reader_pointer_array[1]->target_stone = 102; - reader_pointer_array[1]->reader_ID = (void*)0xdead0002; + reader_pointer_array[1]->reader_ID = (void*)(intptr_t)0xdead0002; - reader_register.writer_file = (void*)0xdeadbeef; + reader_register.writer_file = (void*)(intptr_t)0xdeadbeef; reader_register.writer_response_condition = 13; reader_register.reader_cohort_size = 2; reader_register.CP_reader_info = &reader_pointer_array[0]; diff --git a/ffs/tests/test_funcs.h b/ffs/tests/test_funcs.h index 19cee46832..65075c3af9 100755 --- a/ffs/tests/test_funcs.h +++ b/ffs/tests/test_funcs.h @@ -1,3 +1,12 @@ +#ifdef _MSC_VER +#define strdup(s) _strdup(s) +#define open(x,y,z) _open(x,y,z) +#define read(x,y,z) _read(x,y,z) +#define write(x,y,z) _write(x,y,z) +#define close(x) _close(x) +#define unlink(x) _unlink(x) +#include +#endif typedef struct _newer_rec { int ganzzahl; double gleitkommazahl; diff --git a/ffs/unix_io.c b/ffs/unix_io.c deleted file mode 100755 index a5cac05111..0000000000 --- a/ffs/unix_io.c +++ /dev/null @@ -1,284 +0,0 @@ -#include "config.h" -#include -#include -#include -#include -#include -#ifdef HAVE_MEMORY_H -#include -#endif -#ifdef HAVE_SYS_UIO_H -#include -#define HAVE_IOVEC_DEFINE -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#include "assert.h" -#include "ffs.h" -#include "fm_internal.h" -#include "ffs_internal.h" -#include "io_interface.h" - -static int -unix_read_func(conn, buffer, length, errno_p, result_p) -void *conn; -void *buffer; -int length; -int *errno_p; -char **result_p; -{ - int left = length; - int iget; - int fd = (int) (long) conn; - - iget = read(fd, (char *) buffer, length); - if (iget == 0) { - if (result_p) *result_p = "End of file"; - if (errno_p) *errno_p = 0; - return 0; /* end of file */ - } else if (iget == -1) { - int lerrno = errno; - if (errno_p) *errno_p = lerrno; - if ((lerrno != EWOULDBLOCK) && - (lerrno != EAGAIN) && - (lerrno != EINTR)) { - /* serious error */ - return -1; - } else { - if (errno_p) *errno_p = 0; - iget = 0; - } - } - left = length - iget; - while (left > 0) { - iget = read(fd, (char *) buffer + length - left, left); - if (iget == 0) { - if (result_p) *result_p = "End of file"; - if (errno_p) *errno_p = 0; - return length - left; /* end of file */ - } else if (iget == -1) { - int lerrno = errno; - if (errno_p) *errno_p = errno; - if ((lerrno != EWOULDBLOCK) && - (lerrno != EAGAIN) && - (lerrno != EINTR)) { - /* serious error */ - return (length - left); - } else { - if (errno_p) *errno_p = 0; - iget = 0; - } - } - left -= iget; - } - return length; -} - -static int -unix_readv_func(conn, iov, icount, errno_p, result_p) -void *conn; -struct iovec *iov; -int icount; -int *errno_p; -char **result_p; -{ - int orig_icount = icount; - int fd = (int) (long)conn; - int iget; - - while (icount > 0) { - iget = readv(fd, (struct iovec *) iov, icount); - if (iget == 0) { - if (result_p) *result_p = "End of file"; - if (errno_p) *errno_p = 0; - return 0; /* end of file */ - } else if (iget == -1) { - if (errno_p) *errno_p = errno; - if ((errno != EWOULDBLOCK) && - (errno != EAGAIN) && - (errno != EINTR)) { - /* serious error */ - return -1; - } else { - if (errno_p) *errno_p = 0; - iget = 0; - } - } - while (iget > 0) { - if (iov[0].iov_len <= iget) { - iget -= iov[0].iov_len; - iov++; - icount--; - } else { - iov[0].iov_len -= iget; - iov[0].iov_base = ((char*)iov[0].iov_base) + iget; - iget = 0; - } - } - } - return orig_icount; -} - -static int -unix_write_func(conn, buffer, length, errno_p, result_p) -void *conn; -void *buffer; -int length; -int *errno_p; -char **result_p; -{ - int left = length; - int iget = 0; - int fd = (int) (long)conn; - - while (left > 0) { - iget = write(fd, (char *) buffer + length - left, left); - if (iget == -1) { - int lerrno = errno; - if (errno_p) *errno_p = errno; - if ((lerrno != EWOULDBLOCK) && - (lerrno != EAGAIN) && - (lerrno != EINTR)) { - /* serious error */ - return (length - left); - } else { - if (errno_p) *errno_p = 0; - iget = 0; - } - } - left -= iget; - } - return length; -} - -static int -unix_writev_func(conn, iov, iovcnt, errno_p, result_p) -void *conn; -struct iovec *iov; -int iovcnt; -int *errno_p; -char **result_p; -{ - int fd = (int) (long) conn; - int left = 0; - int iget = 0; - int iovleft, i; - - iovleft = iovcnt; - - /* sum lengths */ - for (i=0; i 0) { - iget = writev(fd, (struct iovec *) &iov[iovcnt - iovleft], iovleft); - if (iget == -1) { - if ((errno != EWOULDBLOCK) && (errno != EAGAIN)) { - /* serious error */ - if (errno_p) *errno_p = errno; - return (iovcnt - iovleft); - } else { - iget = 0; - } - } - if (iget == left) - return iovcnt; - - left -= iget; - while (iget > 0) { - iget -= iov[iovcnt - iovleft].iov_len; - iovleft--; - } - - if (iget < 0) { - /* - * Only part of the last block was written. Modify IO - * vector to indicate the remaining block to be written. - */ - /* restore iovleft and iget to cover remaining block*/ - iovleft++; - iget += iov[iovcnt - iovleft].iov_len; - - /* adjust count down and base up by number of bytes written */ - iov[iovcnt-iovleft].iov_len -= iget; - iov[iovcnt-iovleft].iov_base = - (char*)(iov[iovcnt-iovleft].iov_base) + iget; - } - } - return iovcnt; -} - -static int -unix_close_func(conn) -void *conn; -{ - return close((int) (long) conn); -} - -static void * -unix_file_open_func(path, flag_str, input, output) -const char *path; -const char *flag_str; -int *input; -int *output; -{ - int flags; - int file_id; - long tmp_flags = (long)flag_str; - if (input) *input = 0; - if (output) *output = 0; - - tmp_flags &= ~(O_TRUNC); - tmp_flags &= ~(O_CREAT); - if ((O_RDONLY == tmp_flags) || - (O_WRONLY == tmp_flags)) { - /* must be old style call */ - flags = (long)flag_str; - if (input) *input = (O_RDONLY == (long)flag_str); - if (output) *output = (O_WRONLY & (long)flag_str); - } else { - if (strcmp(flag_str, "r") == 0) { - flags = O_RDONLY; - if (input) *input = 1; - } else if (strcmp(flag_str, "w") == 0) { - flags = O_WRONLY | O_CREAT | O_TRUNC; - if (output) *output = 1; - } else if (strcmp(flag_str, "a") == 0) { - flags = O_RDWR; - if (output) *output = 1; - if (input) *input = 1; - } else { - fprintf(stderr, "Open flags value not understood for file \"%s\"\n", - path); - return NULL; - } - } - file_id = open(path, flags, 0777); - if (file_id == -1) { - return NULL; - } else { - return (void*) (long) file_id; - } -} - - - -IOinterface_func ffs_file_read_func = unix_read_func; -IOinterface_func ffs_file_write_func = unix_write_func; -IOinterface_funcv ffs_file_readv_func = unix_readv_func; -IOinterface_funcv ffs_file_writev_func = unix_writev_func; - -IOinterface_func ffs_read_func = unix_read_func; -IOinterface_func ffs_write_func = unix_write_func; -IOinterface_funcv ffs_readv_func = unix_readv_func; -IOinterface_funcv ffs_writev_func = unix_writev_func; -#ifndef IOV_MAX -#define IOV_MAX 16 -#endif -int ffs_max_iov = IOV_MAX; -IOinterface_close ffs_close_func = unix_close_func; -IOinterface_open ffs_file_open_func = unix_file_open_func; -IOinterface_func ffs_server_read_func = unix_read_func; -IOinterface_func ffs_server_write_func = unix_write_func; -IOinterface_init ffs_sockets_init_func = NULL; diff --git a/fm/fm.h b/fm/fm.h index 185c76bff9..cba86f288a 100755 --- a/fm/fm.h +++ b/fm/fm.h @@ -4,14 +4,23 @@ #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif +#include +#include + typedef struct _FMContextStruct *FMContext; -extern FMContext create_FMcontext(); -extern FMContext create_local_FMcontext(); -extern void free_FMcontext(FMContext c); -extern void add_ref_FMcontext(); -extern void FMcontext_allow_self_formats(FMContext fmc); -extern int +#if defined(_MSC_VER) && !defined(FFS_SRC) +#define FFS_DECLSPEC __declspec(dllimport) +#else +#define FFS_DECLSPEC +#endif + +extern FFS_DECLSPEC FMContext create_FMcontext(); +extern FFS_DECLSPEC FMContext create_local_FMcontext(); +extern FFS_DECLSPEC void free_FMcontext(FMContext c); +extern FFS_DECLSPEC void add_ref_FMcontext(FMContext c); +extern FFS_DECLSPEC void FMcontext_allow_self_formats(FMContext fmc); +extern FFS_DECLSPEC int FMcontext_get_format_server_identifier(FMContext fmc); @@ -76,19 +85,19 @@ typedef enum { typedef struct _FMFormatBody *FMFormatBodyPtr; typedef FMFormatBodyPtr FMFormat; -extern char * +extern FFS_DECLSPEC char * get_server_rep_FMformat(FMFormat ioformat, int *rep_length); -extern char * +extern FFS_DECLSPEC char * get_server_ID_FMformat(FMFormat ioformat, int *id_length); -extern FMContext +extern FFS_DECLSPEC FMContext FMContext_from_FMformat(FMFormat ioformat); -extern int +extern FFS_DECLSPEC int get_rep_len_format_ID(void *format_ID); -extern void +extern FFS_DECLSPEC void set_array_order_FMContext(FMContext iofile, int column_major); FMFormat @@ -100,23 +109,23 @@ FMformat_index(FMFormat f); FMFormat FMformat_by_index(FMContext c, int index); -extern FMFormat +extern FFS_DECLSPEC FMFormat load_external_format_FMcontext(FMContext iocontext, char *server_id, int id_size, char *server_rep); -extern void +extern FFS_DECLSPEC void add_opt_info_FMformat(FMFormat format, int typ, int len, void *block); -extern FMFormat +extern FFS_DECLSPEC FMFormat FMregister_simple_format(FMContext context, char *format_name, FMFieldList field_list, int struct_size); -extern FMFormat +extern FFS_DECLSPEC FMFormat register_data_format(FMContext context, FMStructDescList struct_list); -extern FMFormat +extern FFS_DECLSPEC FMFormat FMregister_data_format(FMContext context, FMStructDescList struct_list); -extern void free_FMfield_list(FMFieldList list); +extern FFS_DECLSPEC void free_FMfield_list(FMFieldList list); /*! * lookup the FMFormat associated with a particular FMStructDescList @@ -139,7 +148,7 @@ extern void free_FMfield_list(FMFieldList list); * address. Normally if you use static format lists, the addresses will * be unique. */ -extern FMFormat +extern FFS_DECLSPEC FMFormat FMlookup_format(FMContext context, FMStructDescList struct_list); typedef enum {Format_Less, Format_Greater, Format_Equal, @@ -152,125 +161,125 @@ typedef struct compat_formats { char *xform_code; } *FMcompat_formats; -extern FMcompat_formats +extern FFS_DECLSPEC FMcompat_formats FMget_compat_formats(FMFormat ioformat); -extern char * +extern FFS_DECLSPEC char * name_of_FMformat(FMFormat format); -extern FMStructDescList +extern FFS_DECLSPEC FMStructDescList format_list_of_FMFormat(FMFormat format); -extern void +extern FFS_DECLSPEC void FMlocalize_structs(FMStructDescList list); -extern char * +extern FFS_DECLSPEC char * global_name_of_FMFormat(FMFormat format); -extern FMFieldList +extern FFS_DECLSPEC FMFieldList copy_field_list(FMFieldList list); -extern FMStructDescList +extern FFS_DECLSPEC FMStructDescList FMcopy_struct_list(FMStructDescList list); -extern void +extern FFS_DECLSPEC void FMfree_struct_list(FMStructDescList list); -extern int +extern FFS_DECLSPEC int FMstruct_size_field_list(FMFieldList list, int pointer_size); -extern FMStructDescList +extern FFS_DECLSPEC FMStructDescList FMlocalize_formats(FMStructDescList list); -extern int +extern FFS_DECLSPEC int count_FMfield(FMFieldList list); -extern void print_server_ID(unsigned char *ID); -extern void print_format_ID(FMFormat ioformat); -extern void fprint_server_ID(void * file,unsigned char *ID); +extern FFS_DECLSPEC void print_server_ID(unsigned char *ID); +extern FFS_DECLSPEC void print_format_ID(FMFormat ioformat); +extern FFS_DECLSPEC void fprint_server_ID(void * file,unsigned char *ID); -extern int FMformatID_len(char *buffer); +extern FFS_DECLSPEC int FMformatID_len(char *buffer); -extern int +extern FFS_DECLSPEC int FMdump_data(FMFormat format, void *data, int character_limit); -extern int +extern FFS_DECLSPEC int FMdump_encoded_data(FMFormat format, void *data, int character_limit); -extern void +extern FFS_DECLSPEC void FMdump_XML(FMFormat format, void *data, int encoded); -extern void +extern FFS_DECLSPEC void FMdump_encoded_XML(FMContext c, void *data, int character_limit); -extern int +extern FFS_DECLSPEC int FMfdump_data(void *file, FMFormat format, void *data, int character_limit); -extern int +extern FFS_DECLSPEC int FMfdump_encoded_data(void *file, FMFormat format, void *data, int character_limit); -extern void +extern FFS_DECLSPEC void FMfdump_XML(void *file, FMFormat format, void *data, int encoded); -extern void +extern FFS_DECLSPEC void FMfdump_encoded_XML(void *file, FMContext c, void *data, int character_limit); -extern char* +extern FFS_DECLSPEC char* FMunencoded_to_XML_string(FMContext fmcontext, FMFormat format, void *data); -extern void +extern FFS_DECLSPEC void FMfree_var_rec_elements(FMFormat format, void *data); -extern char *FMbase_type(const char *field_type); +extern FFS_DECLSPEC char *FMbase_type(const char *field_type); #define XML_OPT_INFO 0x584D4C20 #define COMPAT_OPT_INFO 0x45564F4C #define COMPAT_OPT_INFO_FMFILE 0x45564F4D typedef struct _FMgetFieldStruct *FMFieldPtr; -extern FMFieldPtr get_FMfieldPtrFromList(FMFieldList field_list, +extern FFS_DECLSPEC FMFieldPtr get_FMfieldPtrFromList(FMFieldList field_list, const char *fieldname); -extern void * +extern FFS_DECLSPEC void * get_FMfieldAddr_by_name(FMFieldList field_list, const char *fieldname, void *data); -extern void * +extern FFS_DECLSPEC void * get_FMPtrField_by_name(FMFieldList field_list, const char *fieldname, void *data, int encode); -extern int +extern FFS_DECLSPEC int set_FMPtrField_by_name(FMFieldList field_list, const char *fieldname, void *data, void *ptr_value); -extern int +extern FFS_DECLSPEC int get_FMfieldInt_by_name(FMFieldList field_list, const char *fieldname, void *data); -extern long +extern FFS_DECLSPEC size_t get_FMfieldLong_by_name(FMFieldList field_list, const char *fieldname, void *data); -extern void * FMheader_skip(FMContext c, void *data); -extern char *get_FMstring_base(FMFieldPtr iofield, void *data, void *string_base); -extern void *get_FMFieldAddr(FMFieldPtr iofield, void *data); -extern void *get_FMaddr (FMFieldPtr iofield, void *data, void *string_base, int encode); -extern void *put_FMaddr (FMFieldPtr iofield, void *data); -extern float get_FMfloat(FMFieldPtr iofield, void *data); -extern double get_FMdouble(FMFieldPtr iofield, void *data); -extern short get_FMshort(FMFieldPtr iofield, void *data); -extern int get_FMint(FMFieldPtr iofield, void *data); -extern long get_FMlong(FMFieldPtr iofield, void *data); -extern void get_FMlong8(FMFieldPtr iofield, void *data, unsigned long *low_long, long *high_long); +extern FFS_DECLSPEC void * FMheader_skip(FMContext c, void *data); +extern FFS_DECLSPEC char *get_FMstring_base(FMFieldPtr iofield, void *data, void *string_base); +extern FFS_DECLSPEC void *get_FMFieldAddr(FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC void *get_FMaddr (FMFieldPtr iofield, void *data, void *string_base, int encode); +extern FFS_DECLSPEC void *put_FMaddr (FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC float get_FMfloat(FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC double get_FMdouble(FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC short get_FMshort(FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC int get_FMint(FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC size_t get_FMlong(FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC void get_FMlong8(FMFieldPtr iofield, void *data, unsigned long *low_long, long *high_long); #if defined(SIZEOF_LONG_LONG) #if SIZEOF_LONG_LONG != 0 -extern long long get_FMlong_long(FMFieldPtr iofield, void *data); -extern unsigned long long get_FMulong_long(FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC long long get_FMlong_long(FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC unsigned long long get_FMulong_long(FMFieldPtr iofield, void *data); #endif #endif #if defined(SIZEOF_LONG_DOUBLE) #if SIZEOF_LONG_DOUBLE != 0 -extern long double get_FMlong_double(FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC long double get_FMlong_double(FMFieldPtr iofield, void *data); #endif #endif -extern unsigned short get_FMushort(FMFieldPtr iofield, void *data); -extern unsigned int get_FMuint(FMFieldPtr iofield, void *data); -extern unsigned long get_FMulong(FMFieldPtr iofield, void *data); -extern int get_FMulong8(FMFieldPtr iofield, void *data, unsigned long *low_long, unsigned long *high_long); -extern char *get_FMstring(FMFieldPtr iofield, void *data); -extern char get_FMchar(FMFieldPtr iofield, void *data); -extern int get_FMenum(FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC unsigned short get_FMushort(FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC unsigned int get_FMuint(FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC size_t get_FMulong(FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC int get_FMulong8(FMFieldPtr iofield, void *data, unsigned long *low_long, unsigned long *high_long); +extern FFS_DECLSPEC char *get_FMstring(FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC char get_FMchar(FMFieldPtr iofield, void *data); +extern FFS_DECLSPEC int get_FMenum(FMFieldPtr iofield, void *data); #if defined(__cplusplus) || defined(c_plusplus) } diff --git a/fm/fm_dump.c b/fm/fm_dump.c index 28ca42a73e..2c77715be3 100644 --- a/fm/fm_dump.c +++ b/fm/fm_dump.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "assert.h" #include "fm.h" #include "fm_internal.h" @@ -30,13 +30,13 @@ extern FMfloat_format fm_my_float_format; typedef struct addr_list { void *addr; - int offset; + size_t offset; } addr_list_entry; typedef struct dump_state { int encoded; - int output_len; - int output_limit; + size_t output_len; + ssize_t output_limit; int use_XML; int indent; char *offset_base; @@ -54,14 +54,12 @@ typedef struct dump_state { }*dstate; static void free_addr_list(dstate s); -static int search_addr_list(dstate s, void *addr); -static void add_to_addr_list(dstate s, void *addr, int offset); -static int dump_subfields(void *base, FMFormat f, dstate s, int data_offset); +static ssize_t search_addr_list(dstate s, void *addr); +static void add_to_addr_list(dstate s, void *addr, size_t offset); +static int dump_subfields(void *base, FMFormat f, dstate s, size_t data_offset); static void -byte_swap(data, size) -char *data; -int size; +byte_swap(char *data, int size) { int i; assert((size % 2) == 0); @@ -73,7 +71,7 @@ int size; } extern int -dump_output(dstate s, int length_estimate, char *format, ...) +dump_output(dstate s, size_t length_estimate, char *format, ...) { char buf[1024]; char *tmp = &buf[0]; @@ -81,7 +79,7 @@ dump_output(dstate s, int length_estimate, char *format, ...) int free_tmp = 0; int use_buf = 1; if ((s->output_limit != -1) && - (s->output_len + length_estimate > s->output_limit)) { + (s->output_len + length_estimate > (size_t)s->output_limit)) { return 0; } if (s->output_string != NULL) { @@ -100,7 +98,7 @@ dump_output(dstate s, int length_estimate, char *format, ...) #else va_start(ap); #endif - vsprintf(tmp, format, ap); + vsnprintf(tmp, sizeof(buf), format, ap); va_end(ap); s->output_len += strlen(tmp); if (s->use_file_out) { @@ -125,14 +123,13 @@ set_bigendian () { words_bigendian = (u.c[sizeof (long) - 1] == 1); return words_bigendian; } - +#ifndef WORDS_BIGENDIAN #define WORDS_BIGENDIAN ((words_bigendian == -1) ? set_bigendian() : words_bigendian) #endif +#endif static unsigned long -quick_get_ulong(iofield, data) -FMFieldPtr iofield; -void *data; +quick_get_ulong(FMFieldPtr iofield, void *data) { data = (void *) ((char *) data + iofield->offset); /* only used when field type is an integer and aligned by its size */ @@ -169,9 +166,7 @@ void *data; } static void * -quick_get_pointer(field, data) -FMFieldPtr field; -void *data; +quick_get_pointer(FMFieldPtr field, void *data) { union { void *p; @@ -239,20 +234,13 @@ static int internal_dump_data(FMFormat format, void *data, dstate state); extern int -FMdump_data(format, data, character_limit) -FMFormat format; -void *data; -int character_limit; +FMdump_data(FMFormat format, void *data, int character_limit) { return FMfdump_data(stdout, format, data, character_limit); } extern int -FMfdump_data(out, format, data, character_limit) -void *out; -FMFormat format; -void *data; -int character_limit; +FMfdump_data(void *out, FMFormat format, void *data, int character_limit) { int ret; struct dump_state state; @@ -288,7 +276,7 @@ internal_dump_data(FMFormat format, void *data, dstate state) } static int -dump_subfield(void *base, FMFormat f, dstate s, int data_offset, void* parent_base, FMTypeDesc *t); +dump_subfield(void *base, FMFormat f, dstate s, size_t data_offset, void* parent_base, FMTypeDesc *t); #define FALSE 0 #define TRUE 1 @@ -356,12 +344,12 @@ stop_field(dstate s, FMFieldList f, FMTypeDesc *t) } static int -dump_subfields(void *base, FMFormat f, dstate s, int data_offset) +dump_subfields(void *base, FMFormat f, dstate s, size_t data_offset) { int i; for (i = 0; i < f->field_count; i++) { - int subfield_offset = data_offset + f->field_list[i].field_offset; + size_t subfield_offset = data_offset + f->field_list[i].field_offset; FMFieldList fmfield = &f->field_list[i]; int ret; start_field(s, fmfield, &f->var_list[i].type_desc); @@ -370,7 +358,7 @@ dump_subfields(void *base, FMFormat f, dstate s, int data_offset) &f->var_list[i].type_desc); stop_field(s, fmfield, &f->var_list[i].type_desc); if (ret != 1) return 0; - if ((s->output_limit != -1) && (s->output_len >= s->output_limit)) return 0; + if ((s->output_limit != -1) && (s->output_len >= (size_t)s->output_limit)) return 0; } return 1; } @@ -414,18 +402,8 @@ determine_dump_size(FMFormat f, void *data, void* parent_base, FMTypeDesc *t) static int -sdump_value(s, field_type, field_size, field_offset, top_format, data, - string_base, byte_reversal, float_format, encode) -dstate s; -const char *field_type; -int field_size; -int field_offset; -FMFormat top_format; -void *data; -void *string_base; -int byte_reversal; -int float_format; -int encode; +sdump_value(dstate s, const char *field_type, int field_size, size_t field_offset, FMFormat top_format, + void *data, void *string_base, int byte_reversal, int float_format, int encode) { FMgetFieldStruct descr; /*OK */ long junk; @@ -438,7 +416,7 @@ int encode; if (descr.data_type == integer_type) { if (field_size <= sizeof(long)) { - long tmp = get_FMlong(&descr, data); + size_t tmp = get_FMlong(&descr, data); dump_output(s, 25, "%ld ", tmp); } else if (field_size == 2 * sizeof(long) && field_size == 8) { unsigned long low_long; @@ -456,7 +434,7 @@ int encode; } } else if (descr.data_type == unsigned_type) { if (field_size <= sizeof(unsigned long)) { - unsigned long tmp = get_FMulong(&descr, data); + ssize_t tmp = get_FMulong(&descr, data); dump_output(s, 25, "%lu ", tmp); } else if (field_size == 2 * sizeof(long) && field_size == 8) { unsigned long low_long, high_long; @@ -472,10 +450,10 @@ int encode; dump_output(s, 20, "+uint size %u+ ", field_size); } } else if (descr.data_type == enumeration_type) { - unsigned long tmp = get_FMulong(&descr, data); + size_t tmp = get_FMulong(&descr, data); dump_output(s, 25, "%lu ", tmp); } else if (descr.data_type == boolean_type) { - unsigned long tmp = get_FMulong(&descr, data); + size_t tmp = get_FMulong(&descr, data); dump_output(s, 25, "%lu ", tmp); if (tmp == 0) { dump_output(s, 5, "false "); @@ -525,16 +503,16 @@ int encode; } static int -dump_subfield(void*base, FMFormat f, dstate s, int data_offset, void* parent_base, FMTypeDesc *t) +dump_subfield(void*base, FMFormat f, dstate s, size_t data_offset, void* parent_base, FMTypeDesc *t) { - if ((s->output_limit != -1) && (s->output_len > s->output_limit)) return 0; + if ((s->output_limit != -1) && (s->output_len > (size_t)s->output_limit)) return 0; switch (t->type) { case FMType_pointer: { struct _FMgetFieldStruct src_spec; - int new_offset; + size_t new_offset; char *ptr_value; memset(&src_spec, 0, sizeof(src_spec)); src_spec.size = f->pointer_size; @@ -550,16 +528,16 @@ dump_subfield(void*base, FMFormat f, dstate s, int data_offset, void* parent_bas #if defined (__INTEL_COMPILER) # pragma warning (disable: 810) #endif - new_offset = (long) ptr_value; + new_offset = (intptr_t) ptr_value; #if defined (__INTEL_COMPILER) # pragma warning (default: 810) #endif - ptr_value = (long)ptr_value + s->offset_base; + ptr_value = (intptr_t)ptr_value + s->offset_base; } else { - new_offset = ptr_value - s->offset_base; + new_offset = (intptr_t)ptr_value - (intptr_t)s->offset_base; } if (f->recursive) { - int previous_offset = search_addr_list(s, ptr_value); + ssize_t previous_offset = search_addr_list(s, ptr_value); if (previous_offset != -1) { /* already visited this */ return 1; @@ -583,7 +561,7 @@ dump_subfield(void*base, FMFormat f, dstate s, int data_offset, void* parent_bas dump_output(s, 5, "NULL "); } else { if (s->encoded) { - ptr_value = (long)ptr_value + s->offset_base; + ptr_value = (intptr_t)ptr_value + s->offset_base; } dump_output(s, strlen(ptr_value) + 2, "\"%s\"", ptr_value); } @@ -610,7 +588,7 @@ dump_subfield(void*base, FMFormat f, dstate s, int data_offset, void* parent_bas } element_size = determine_dump_size(f, base, parent_base, next); for (i = 0; i < elements ; i++) { - int element_offset = data_offset + i * element_size; + size_t element_offset = data_offset + i * element_size; if (!dump_subfield(base, f, s, element_offset, parent_base, next)) return 0; } break; @@ -628,7 +606,7 @@ dump_subfield(void*base, FMFormat f, dstate s, int data_offset, void* parent_bas } case FMType_simple: { FMFieldList fmfield = &f->field_list[t->field_index]; - int field_offset = data_offset; + size_t field_offset = data_offset; int field_size = fmfield->field_size; const char *field_type = fmfield->field_type; int byte_reversal = f->byte_reversal; @@ -644,7 +622,7 @@ dump_subfield(void*base, FMFormat f, dstate s, int data_offset, void* parent_bas } static void -add_to_addr_list(dstate s, void *addr, int offset) +add_to_addr_list(dstate s, void *addr, size_t offset) { if (s->addr_list_is_stack) { if (s->addr_list_cnt == STACK_ARRAY_SIZE) { @@ -669,11 +647,11 @@ add_to_addr_list(dstate s, void *addr, int offset) s->addr_list_cnt++; } -static int +static ssize_t search_addr_list(dstate s, void *addr) { int i; - int previous_offset = -1; + ssize_t previous_offset = -1; for (i=0; i < s->addr_list_cnt; i++) { if (s->addr_list[i].addr == addr) { previous_offset = s->addr_list[i].offset; @@ -692,10 +670,7 @@ free_addr_list(dstate s) } extern int -dump_raw_FMrecord(fmc,format, data) -FMContext fmc; -FMFormat format; -void *data; +dump_raw_FMrecord(FMContext fmc, FMFormat format, void *data) { struct dump_state state; init_dump_state(&state); @@ -710,10 +685,7 @@ void *data; } extern char * -dump_raw_FMrecord_to_string(fmc,format, data) -FMContext fmc; -FMFormat format; -void *data; +dump_raw_FMrecord_to_string(FMContext fmc, FMFormat format, void *data) { struct dump_state state; init_dump_state(&state); @@ -731,11 +703,7 @@ void *data; } extern int -FMfdump_encoded_data(out, format, data, character_limit) -void *out; -FMFormat format; -void *data; -int character_limit; +FMfdump_encoded_data(void *out, FMFormat format, void *data, int character_limit) { int ret; int header_size = format->server_ID.length; @@ -762,10 +730,7 @@ int character_limit; } extern int -FMdump_encoded_data(format, data, character_limit) -FMFormat format; -void *data; -int character_limit; +FMdump_encoded_data(FMFormat format, void *data, int character_limit) { return FMfdump_encoded_data((void*)stdout, format, data, character_limit); } @@ -826,10 +791,7 @@ FMdump_encoded_XML(FMContext c, void *data, int limit) } extern void -dump_unencoded_FMrecord_as_XML(fmc, format, data) -FMContext fmc; -FMFormat format; -void *data; +dump_unencoded_FMrecord_as_XML(FMContext fmc, FMFormat format, void *data) { struct dump_state state; if (FMhas_XML_info(format)) { diff --git a/fm/fm_formats.c b/fm/fm_formats.c index ca3f3dee83..83414a45a5 100755 --- a/fm/fm_formats.c +++ b/fm/fm_formats.c @@ -34,7 +34,7 @@ #include #include #include -#include +#include #else #include "kernel/pbio_kernel.h" #include "kernel/kpbio.h" @@ -44,6 +44,9 @@ #include "assert.h" #include "fm.h" #include "fm_internal.h" +#if defined(_MSC_VER) +#define strdup _strdup +#endif static int server_register_format(FMContext fmc, FMFormat fmformat); static int self_server_register_format(FMContext fmc, @@ -200,8 +203,7 @@ create_local_FMcontext() } static void -free_FMformat(body) -FMFormat body; +free_FMformat(FMFormat body) { int i; body->ref_count--; @@ -295,11 +297,7 @@ FMformatID_len(char *buffer) } extern void -add_opt_info_FMformat(format, typ, len, block) -FMFormat format; -int typ; -int len; -void *block; +add_opt_info_FMformat(FMFormat format, int typ, int len, void *block) { int count = 0; if (format->opt_info == NULL) { @@ -385,15 +383,13 @@ FMget_compat_formats(FMFormat fmformat) } FMFormat -get_local_format_IOcontext(iocontext, buffer) -FMContext iocontext; -void *buffer; +get_local_format_IOcontext(FMContext iocontext, void *buffer) { FMContext fmc = (FMContext) iocontext; int i; if (get_format_server_verbose()) { - printf("Get Format searching in context %lx for format ", - (long)iocontext); + printf("Get Format searching in context %p for format ", + iocontext); print_server_ID(buffer); printf("\n"); } @@ -459,9 +455,7 @@ void *buffer; } FMFormat -FMformat_from_ID(iocontext, buffer) -FMContext iocontext; -char *buffer; +FMformat_from_ID(FMContext iocontext, char *buffer) { FMContext fmc = (FMContext) iocontext; FMFormat new_format; @@ -532,22 +526,21 @@ char *buffer; new_format = server_get_format(iocontext, buffer); } if (get_format_server_verbose()) { - printf("Read format from format server %lx\n", - (long)new_format); + printf("Read format from format server %p\n", + new_format); if (new_format != NULL) { dump_FMFormat(new_format); } else { printf("Format unknown. Request was: "); print_server_ID((void*)buffer); - printf("\n\tcontext was %lx\n", (long)iocontext); + printf("\n\tcontext was %p\n", iocontext); } } return new_format; } char ** -get_subformat_names(field_list) -FMFieldList field_list; +get_subformat_names(FMFieldList field_list) { int name_count = 0; int field = 0; @@ -573,11 +566,8 @@ FMFieldList field_list; static void -get_subformats_context(fmformat, format_list_p, format_count_p, stack_p) -FMFormat fmformat; -FMFormat **format_list_p; -int *format_count_p; -FMFormat **stack_p; +get_subformats_context(FMFormat fmformat, FMFormat **format_list_p, int *format_count_p, + FMFormat **stack_p) { int field; int stack_depth = 0; @@ -614,8 +604,7 @@ FMFormat **stack_p; } FMFormat * -get_subformats_IOformat(fmformat) -FMFormat fmformat; +get_subformats_IOformat(FMFormat fmformat) { int format_count = 0; FMFormat *format_list = malloc(sizeof(FMFormat)); @@ -636,9 +625,7 @@ FMformat_index(FMFormat f) } FMFormat -FMformat_by_index(fmc, index) -FMContext fmc; -int index; +FMformat_by_index(FMContext fmc, int index) { if (index < fmc->reg_format_count) { return fmc->format_list[index]; @@ -680,8 +667,7 @@ new_FMFormat() extern void -expand_FMContext(fmc) -FMContext fmc; +expand_FMContext(FMContext fmc) { int new_count = fmc->format_list_size + 10; int new_size = sizeof(FMFormat) * (new_count); @@ -899,9 +885,7 @@ typedef struct { } *sld; static int -type_alignment(fmformat, field) -FMFormat fmformat; -int field; +type_alignment(FMFormat fmformat, int field) { FMVarInfoList var = &fmformat->var_list[field]; FMTypeDesc *t = &var->type_desc; @@ -1192,8 +1176,7 @@ gen_var_dimens(FMFormat fmformat, int field) } extern void -set_alignment(fmformat) -FMFormat fmformat; +set_alignment(FMFormat fmformat) { int field_align; int field; @@ -1208,9 +1191,7 @@ FMFormat fmformat; extern int -generate_var_list(fmformat, formats) -FMFormat fmformat; -FMFormat *formats; +generate_var_list(FMFormat fmformat, FMFormat *formats) { FMVarInfoList new_var_list; FMFieldList field_list = fmformat->field_list; @@ -1278,19 +1259,16 @@ FMFormat *formats; } static format_rep -add_server_subformat_rep(fmformat, super_rep, super_rep_size) -FMFormat fmformat; -char *super_rep; -int *super_rep_size; +add_server_subformat_rep(FMFormat fmformat, char *super_rep, size_t *super_rep_size) { int byte_reversal = fmformat->byte_reversal; - int rep_size = (sizeof(struct _field_wire_format_1) * + size_t rep_size = (sizeof(struct _field_wire_format_1) * (fmformat->field_count)); int i; int opt_info_count = 0; struct _subformat_wire_format *rep; char *string_base; - int cur_offset; + ssize_t cur_offset; struct _field_wire_format_1 *fields; int OUR_BYTE_ORDER = WORDS_BIGENDIAN; int OTHER_BYTE_ORDER = (WORDS_BIGENDIAN ? 0 : 1); @@ -1303,11 +1281,11 @@ int *super_rep_size; rep_size += sizeof(struct _subformat_wire_format_1); - rep_size = (rep_size + 3) & -4; /* round up by even 4 */ + rep_size = (rep_size + 3) & (size_t)-4; /* round up by even 4 */ while (fmformat->opt_info && (fmformat->opt_info[opt_info_count].info_type != 0)) { rep_size += fmformat->opt_info[opt_info_count].info_len; - rep_size = (rep_size + 3) & -4; /* round up by even 4 */ + rep_size = (rep_size + 3) & (size_t)-4; /* round up by even 4 */ opt_info_count++; } rep_size += (opt_info_count + 1) * sizeof(struct _opt_info_wire_format); @@ -1327,7 +1305,7 @@ int *super_rep_size; string_base = (char *) rep; - rep->f.f1.name_offset = cur_offset; + rep->f.f1.name_offset = (unsigned int)cur_offset; if (byte_reversal) byte_swap((char*) &rep->f.f1.name_offset, 4); strcpy(string_base + cur_offset, fmformat->format_name); cur_offset += strlen(fmformat->format_name) + 1; @@ -1348,12 +1326,12 @@ int *super_rep_size; if (byte_reversal) byte_swap((char*) &fields[i].field_size, 4); fields[i].field_offset = fmformat->field_list[i].field_offset; if (byte_reversal) byte_swap((char*) &fields[i].field_offset, 4); - fields[i].field_name_offset = cur_offset; + fields[i].field_name_offset = (unsigned int)cur_offset; if (byte_reversal) byte_swap((char*) &fields[i].field_name_offset, 4); strcpy(string_base + cur_offset, fmformat->field_list[i].field_name); cur_offset += strlen(fmformat->field_list[i].field_name) + 1; - fields[i].field_type_offset = cur_offset; + fields[i].field_type_offset = (unsigned int) cur_offset; if (byte_reversal) byte_swap((char*) &fields[i].field_type_offset, 4); strcpy(string_base + cur_offset, fmformat->field_list[i].field_type); @@ -1368,7 +1346,7 @@ int *super_rep_size; *(string_base + cur_offset++) = 0; } rep->f.f1.opt_info_offset = cur_offset & 0xffff; - rep->f.f1.top_bytes_opt_info_offset = cur_offset >> 16; + rep->f.f1.top_bytes_opt_info_offset = (unsigned short)(cur_offset >> 16); if (byte_reversal) byte_swap((char*) &rep->f.f1.opt_info_offset, 2); if (byte_reversal) byte_swap((char*) &rep->f.f1.top_bytes_opt_info_offset, 2); info_base = cur_offset +string_base; @@ -1387,7 +1365,7 @@ int *super_rep_size; if (byte_reversal) byte_swap((char*) &tmp_base.info_type, 4); tmp_base.info_len = fmformat->opt_info[i].info_len; if (byte_reversal) byte_swap((char*) &tmp_base.info_len, 4); - tmp_base.info_offset = cur_offset; + tmp_base.info_offset = (int) cur_offset; if (byte_reversal) byte_swap((char*) &tmp_base.info_offset, 4); memcpy(info_base + i*sizeof(tmp_base), &tmp_base, sizeof(tmp_base)); memcpy(string_base + cur_offset, @@ -1404,21 +1382,20 @@ int *super_rep_size; *(string_base + cur_offset++) = 0; } assert(cur_offset == rep_size); - rep->f.f1.subformat_rep_length = htons(rep_size); - rep->f.f1.top_bytes_subformat_rep_length = htons(rep_size>>16); + rep->f.f1.subformat_rep_length = htons((short)rep_size); + rep->f.f1.top_bytes_subformat_rep_length = htons((short)(rep_size>>16)); *super_rep_size += rep_size; return (format_rep) super_rep; } static format_rep -build_server_format_rep(fmformat) -FMFormat fmformat; +build_server_format_rep(FMFormat fmformat) { int subformat_count = 0; FMFormat *subformats = fmformat->subformats; int i; struct _format_wire_format *rep = malloc(sizeof(*rep)); - int rep_size = sizeof(*rep); + size_t rep_size = sizeof(*rep); int OUR_BYTE_ORDER = WORDS_BIGENDIAN; int OTHER_BYTE_ORDER = (WORDS_BIGENDIAN ? 0 : 1); @@ -1438,7 +1415,7 @@ FMFormat fmformat; rep->f.f1.server_rep_version = 2; rep->f.f1.subformat_count = subformat_count; rep->f.f1.recursive_flag = 0; /* GSE must set right */ - rep->f.f1.top_bytes_format_rep_length = htons(rep_size>>16); + rep->f.f1.top_bytes_format_rep_length = htons((short)(rep_size>>16)); return (format_rep) rep; } @@ -1449,9 +1426,7 @@ FMFormat fmformat; * server_format_rep fields. */ static FMFormat -search_compatible_formats(iocontext, fmformat) -FMContext iocontext; -FMFormat fmformat; +search_compatible_formats(FMContext iocontext, FMFormat fmformat) { int i, search_rep_length; FMContext fmc = (FMContext) iocontext; @@ -1461,7 +1436,7 @@ FMFormat fmformat; } search_rep_length = ntohs(fmformat->server_format_rep->format_rep_length); if (fmformat->server_format_rep->server_rep_version > 0) { - search_rep_length += (ntohs(fmformat->server_format_rep->top_bytes_format_rep_length) >> 16); + search_rep_length += (ntohs(fmformat->server_format_rep->top_bytes_format_rep_length) << 16); } /* search locally first */ @@ -1480,8 +1455,8 @@ FMFormat fmformat; rep_length = ntohs(tmp->server_format_rep->format_rep_length); if (search_rep_length != rep_length) { if (get_format_server_verbose()) { - printf("Format %s found in context %lx, but server reps have different lengths, %d and %d\n", - fmformat->format_name, (long) iocontext, + printf("Format %s found in context %p, but server reps have different lengths, %d and %d\n", + fmformat->format_name, iocontext, search_rep_length, rep_length); } continue; @@ -1491,8 +1466,8 @@ FMFormat fmformat; return tmp; } else { if (get_format_server_verbose()) { - printf("Format %s found in context %lx, but server reps are different\n", - fmformat->format_name, (long) iocontext); + printf("Format %s found in context %p, but server reps are different\n", + fmformat->format_name, iocontext); } } } @@ -1570,7 +1545,7 @@ validate_and_copy_field_list(FMFieldList field_list, FMFormat fmformat) int simple_string = 0; if (strchr(field_list[field].field_type, '[') == NULL) { /* not an array */ - if (index(field_list[field].field_type, '*') == NULL) { + if (strchr(field_list[field].field_type, '*') == NULL) { if (FMstr_to_data_type(field_list[field].field_type) == string_type) { simple_string = 1; } @@ -1581,7 +1556,7 @@ validate_and_copy_field_list(FMFieldList field_list, FMFormat fmformat) } else { int ret = is_var_array_field(field_list, field); if (ret == -1) return NULL; /* rejected */ - if ((ret == 1) || (index(field_list[field].field_type, '*'))) { + if ((ret == 1) || (strchr(field_list[field].field_type, '*'))) { /* variant array, real_field_size is * fmc->pointer_size */ field_size = fmformat->pointer_size; @@ -1721,9 +1696,7 @@ void add_format(FMFormat f, FMFormat* sorted, FMFormat *visited, FMFormat* stack static int -topo_order_subformats(super_format, format_count) -FMFormat super_format; -int format_count; +topo_order_subformats(FMFormat super_format, int format_count) { FMFormat sorted[100], visit[100], stack[100]; int sorted_count = 1; @@ -1942,8 +1915,8 @@ register_data_format(FMContext context, FMStructDescList struct_list) return NULL; } if (get_format_server_verbose()) { - printf("Registered format with format server - %lx in context %lx\n", - (long) formats[0], (long) context); + printf("Registered format with format server - %p in context %p\n", + formats[0], context); dump_FMFormat(formats[0]); } } else { @@ -1952,8 +1925,8 @@ register_data_format(FMContext context, FMStructDescList struct_list) cache_format->ref_count++; if (get_format_server_verbose()) { - printf("Cache hit on format registration %lx \"%s\" ", - (long)cache_format, cache_format->format_name); + printf("Cache hit on format registration %p \"%s\" ", + cache_format, cache_format->format_name); print_format_ID(cache_format); printf("\n"); } @@ -1987,7 +1960,7 @@ generate_format3_server_ID(server_ID_type *server_ID, INT4 hash1 = 0, hash2 = 0; UINT4 server_format_rep_length = ntohs(server_format_rep->format_rep_length); if (server_format_rep->server_rep_version > 0) { - server_format_rep_length += (ntohs(server_format_rep->top_bytes_format_rep_length) >> 16); + server_format_rep_length += (ntohs(server_format_rep->top_bytes_format_rep_length) << 16); } if (server_format_rep_length > (1 << 26)) fprintf(stderr, "Format rep too long in generate_format_server_ID\n"); server_ID->length = 12; @@ -2007,17 +1980,15 @@ generate_format3_server_ID(server_ID_type *server_ID, printf("\n"); } ((version_3_format_ID *) server_ID->value)->rep_len = - htons(server_format_rep_length >> 2); // Mod length by 4 - ((version_3_format_ID *) server_ID->value)->top_byte_rep_len = - htons(server_format_rep_length >> 18); // Essentially, we capture the top 26 bytes of the server length + htons((short)(server_format_rep_length >> 2)); // Mod length by 4 + ((version_3_format_ID *) server_ID->value)->top_byte_rep_len = (unsigned char) + htons((short)(server_format_rep_length >> 18)); // Essentially, we capture the top 26 bytes of the server length ((version_3_format_ID *) server_ID->value)->hash1 = htonl(hash1); ((version_3_format_ID *) server_ID->value)->hash2 = htonl(hash2); } static int -self_server_register_format(fmc, fmformat) -FMContext fmc; -FMFormat fmformat; +self_server_register_format(FMContext fmc, FMFormat fmformat) { format_rep server_format_rep; /* we're a format server ourselves, assign an ID */ @@ -2045,8 +2016,7 @@ FMFormat fmformat; } int -count_FMfield(list) -FMFieldList list; +count_FMfield(FMFieldList list) { int i = 0; while (list[i].field_name != NULL) { @@ -2057,9 +2027,7 @@ FMFieldList list; extern int -struct_size_IOfield(fmc, list) -FMContext fmc; -FMFieldList list; +struct_size_IOfield(FMContext fmc, FMFieldList list) { int i = 0; int struct_size = 0; @@ -2090,24 +2058,20 @@ FMFieldList list; } extern int -struct_size_field_list(list, pointer_size) -FMFieldList list; -int pointer_size; +struct_size_field_list(FMFieldList list, int pointer_size) { return FMstruct_size_field_list(list, pointer_size); } extern int -FMstruct_size_field_list(list, pointer_size) -FMFieldList list; -int pointer_size; +FMstruct_size_field_list(FMFieldList list, int pointer_size) { int i = 0; int struct_size = 0; while (list[i].field_name != NULL) { int field_size = 0; - if ((is_var_array_field(list, i) == 1) || (index(list[i].field_type, '*'))) { + if ((is_var_array_field(list, i) == 1) || (strchr(list[i].field_type, '*'))) { /* variant array, real_field_size is fmformat->pointer_size */ field_size = pointer_size; } else { @@ -2126,16 +2090,14 @@ int pointer_size; extern FMFieldList -field_list_of_IOformat(format) -FMFormat format; +field_list_of_IOformat(FMFormat format) { return format->field_list; } extern int -compare_field_lists(list1, list2) -FMFieldList list1, list2; +compare_field_lists(FMFieldList list1, FMFieldList list2) { int i = 0; do { @@ -2169,8 +2131,7 @@ FMFieldList list1, list2; */ extern FMFieldList -max_field_lists(list1, list2) -FMFieldList list1, list2; +max_field_lists(FMFieldList list1, FMFieldList list2) { FMFieldList max_field_list = NULL; FMFieldList tlist2; @@ -2264,8 +2225,7 @@ FMFieldList list1, list2; extern FMFieldList -copy_field_list(list) -FMFieldList list; +copy_field_list(FMFieldList list) { int field_count = count_FMfield(list); FMFieldList new_field_list; @@ -2288,8 +2248,7 @@ FMFieldList list; extern FMStructDescList -FMcopy_struct_list(list) -FMStructDescList list; +FMcopy_struct_list(FMStructDescList list) { int format_count = 0; FMStructDescList new_list; @@ -2314,8 +2273,7 @@ FMStructDescList list; extern void -free_field_list(list) -FMFieldList list; +free_field_list(FMFieldList list) { int i = 0; while (list[i].field_name != NULL) { @@ -2328,8 +2286,7 @@ FMFieldList list; extern void -FMfree_struct_list(list) -FMStructDescList list; +FMfree_struct_list(FMStructDescList list) { int format_count = 0; int format; @@ -2371,9 +2328,7 @@ field_name_compar(const void *a, const void *b) } FMformat_order -FMformat_cmp(format1, format2) -FMFormat format1; -FMFormat format2; +FMformat_cmp(FMFormat format1, FMFormat format2) { FMformat_order tmp_result = Format_Equal; FMFieldList field_list1 = @@ -2518,8 +2473,7 @@ FMFormat format2; extern char * -name_of_FMformat(format) -FMFormat format; +name_of_FMformat(FMFormat format) { return format->format_name; } @@ -2531,15 +2485,13 @@ format_list_of_FMFormat(FMFormat format) } extern FMdata_type -FMarray_str_to_data_type(str, element_count_ptr) -const char *str; -long *element_count_ptr; +FMarray_str_to_data_type(const char *str, long *element_count_ptr) { FMdata_type ret_type; char field_type[1024]; char *left_paren; long element_count = 1; - int field_type_len; + size_t field_type_len; #ifdef MODULE char *temp_ptr = 0; #endif @@ -2549,7 +2501,7 @@ long *element_count_ptr; return ret_type; } field_type_len = left_paren - str; - strncpy(field_type, str, field_type_len); + strncpy(field_type, str, sizeof(field_type)); field_type[field_type_len] = 0; ret_type = FMstr_to_data_type(field_type); while (left_paren != NULL) { @@ -2578,9 +2530,7 @@ long *element_count_ptr; } extern int -field_type_eq(str1, str2) -const char *str1; -const char *str2; +field_type_eq(const char *str1, const char *str2) { FMdata_type t1, t2; long t1_count, t2_count; @@ -2597,8 +2547,8 @@ const char *str2; char *colon2 = strchr(tmp_str2, ':'); char *lparen1 = strchr(str1, '['); char *lparen2 = strchr(str2, '['); - int count1 = 0; - int count2 = 0; + size_t count1 = 0; + size_t count2 = 0; if (colon1 != NULL) { count1 = colon1 - tmp_str1; @@ -2624,8 +2574,7 @@ const char *str2; } extern char * -base_data_type(str) -const char *str; +base_data_type(const char *str) { char *typ; while (isspace((int)*str) || (*str == '*') || (*str == '(')) { /* skip preceeding space */ @@ -2642,15 +2591,13 @@ const char *str; } extern char * -FMbase_type(field_type) -const char *field_type; +FMbase_type(const char *field_type) { return base_data_type(field_type); } extern FMdata_type -FMstr_to_data_type(str) -const char *str; +FMstr_to_data_type(const char *str) { const char *end; while (isspace((int)*str) || (*str == '*') || (*str == '(')) { /* skip preceeding space */ @@ -2862,8 +2809,7 @@ IOget_array_size_dimen(const char *str, FMFieldList fields, int dimen, int *cont } extern const char * -data_type_to_str(dat) -FMdata_type dat; +data_type_to_str(FMdata_type dat) { switch (dat) { case integer_type: @@ -2887,12 +2833,8 @@ FMdata_type dat; extern void -get_FMformat_characteristics(format, ff, intf, column_major, pointer_size) -FMFormat format; -FMfloat_format *ff; -FMinteger_format *intf; -int *column_major; -int *pointer_size; +get_FMformat_characteristics(FMFormat format, FMfloat_format *ff, FMinteger_format *intf, + int *column_major, int *pointer_size) { if (WORDS_BIGENDIAN) { if (format->byte_reversal) { @@ -2915,24 +2857,21 @@ int *pointer_size; extern int -pointer_size_of_IOformat(format) -FMFormat format; +pointer_size_of_IOformat(FMFormat format) { return format->pointer_size; } extern FMContext -fmc_of_IOformat(format) -FMFormat format; +fmc_of_IOformat(FMFormat format) { return format->context; } extern void -dump_FMFormat(fmformat) -FMFormat fmformat; +dump_FMFormat(FMFormat fmformat) { int index, i; printf("\tFormat \"%s\"; size = %d; Field_Count = %d; Endian = %d; Float format = %s;\n\t\t Pointer size = %d; Column_major_arrays = %d; Alignment = %d; Index = %d, File Version = %d; ", @@ -3005,8 +2944,7 @@ FMFormat fmformat; } extern void -dump_FMFormat_as_XML(fmformat) -FMFormat fmformat; +dump_FMFormat_as_XML(FMFormat fmformat) { int index, i; printf("\n"); @@ -3036,15 +2974,13 @@ FMFormat fmformat; } extern void -add_ref_FMcontext(c) -FMContext c; +add_ref_FMcontext(FMContext c) { c->ref_count++; } extern void -free_FMcontext(c) -FMContext c; +free_FMcontext(FMContext c) { int i; c->ref_count--; @@ -3061,13 +2997,8 @@ FMContext c; #define DUMP #ifdef DUMP static void -free_FMfield(fmformat, field, data, string_base, encode, verbose) -FMFormat fmformat; -int field; -void *data; -void *string_base; -int encode; -int verbose; +free_FMfield(FMFormat fmformat, int field, void *data, void *string_base, + int encode, int verbose) { FMFieldList iofield = &fmformat->field_list[field]; FMVarInfoList iovar = &fmformat->var_list[field]; @@ -3081,15 +3012,15 @@ int verbose; if ((iovar->string == 0) && (iovar->var_array == 0) && - (index(iofield->field_type, '*') == NULL) && + (strchr(iofield->field_type, '*') == NULL) && (iovar->data_type != unknown_type)) { /* must be simple data type or array of simple data types */ return; } dimension = FMget_array_element_count(fmformat, iovar, data, encode); - if ((iovar->var_array) || (index(iofield->field_type, '*') != NULL)) { + if ((iovar->var_array) || (strchr(iofield->field_type, '*') != NULL)) { FMgetFieldStruct descr; /* OK */ - long tmp_offset; + size_t tmp_offset; descr.offset = iofield->field_offset; descr.size = fmformat->pointer_size; descr.data_type = integer_type; @@ -3125,15 +3056,13 @@ int verbose; data_offset += sub_field_size; } } - if ((iovar->var_array) || (index(iofield->field_type, '*') != NULL)) { + if ((iovar->var_array) || (strchr(iofield->field_type, '*') != NULL)) { free(data); } } extern void -FMfree_var_rec_elements(fmformat, data) -FMFormat fmformat; -void *data; +FMfree_var_rec_elements(FMFormat fmformat, void *data) { int index; if (fmformat->variant == 0) return; /* nothing to do */ @@ -3146,8 +3075,8 @@ extern long FMget_array_element_count(FMFormat f, FMVarInfoList var, char *data, int encode) { int i; - long count = 1; - long tmp; + size_t count = 1; + size_t tmp; for (i = 0; i < var->dimen_count; i++) { if (var->dimens[i].static_size != 0) { count = count * var->dimens[i].static_size; @@ -3167,14 +3096,12 @@ FMget_array_element_count(FMFormat f, FMVarInfoList var, char *data, int encode) count = count * tmp; } } - return count; + return (long) count; } #endif static void -byte_swap(data, size) -char *data; -int size; +byte_swap(char *data, int size) { int i; assert((size % 2) == 0); @@ -3192,16 +3119,13 @@ int size; #define FILE_INT INT4 static int -put_serverAtomicInt(fd, file_int_ptr, fmc) -void *fd; -FILE_INT *file_int_ptr; -FMContext fmc; +put_serverAtomicInt(void *fd, FILE_INT *file_int_ptr, FMContext fmc) { #if SIZEOF_INT == 4 int tmp_value = *file_int_ptr; int junk_errno; char *junk_result_str; - if (os_server_write_func(fd, &tmp_value, 4, &junk_errno, &junk_result_str) != 4) { + if (ffs_server_write_func(fd, &tmp_value, 4, &junk_errno, &junk_result_str) != 4) { printf("SERVER WRITE FAILED, ERRNO = %d\n", junk_errno); return 0; } @@ -3212,16 +3136,13 @@ FMContext fmc; } static int -get_serverAtomicInt(fd, file_int_ptr, byte_reversal) -void *fd; -FILE_INT *file_int_ptr; -int byte_reversal; +get_serverAtomicInt(void *fd, FILE_INT *file_int_ptr, int byte_reversal) { #if SIZEOF_INT == 4 int tmp_value; int junk_errno; char *junk_result_str; - if (os_server_read_func(fd, &tmp_value, 4, &junk_errno, &junk_result_str) != 4) { + if (ffs_server_read_func(fd, &tmp_value, 4, &junk_errno, &junk_result_str) != 4) { printf("SERVER READ FAILED, ERRNO = %d\n", junk_errno); return 0; @@ -3239,15 +3160,18 @@ extern int unix_timeout_read_func(void *conn, void *buffer, int length, int *errno_p, char **result_p); +#ifdef _MSC_VER +#define srand48(x) srand((int)(x)) +#define drand48() ((double)rand()/RAND_MAX) +#define sleep(sec) Sleep(1000 * sec) +#endif + extern int -serverAtomicRead(fd, buffer, length) -void *fd; -void *buffer; -int length; +serverAtomicRead(void *fd, void *buffer, int length) { char *junk_result_str = NULL; int junk_errno; - int ret = os_server_read_func(fd, buffer, length, &junk_errno, + int ret = ffs_server_read_func(fd, buffer, length, &junk_errno, &junk_result_str); if (getenv("BAD_CLIENT") && (drand48() < 0.0001)) sleep(600); @@ -3264,22 +3188,18 @@ int length; } extern int -serverAtomicWrite(fd, buffer, length) -void *fd; -void *buffer; -int length; +serverAtomicWrite(void *fd, void *buffer, int length) { char *junk_result_str; int junk_errno; if (getenv("BAD_CLIENT") && (drand48() < 0.001)) sleep(600); - return os_server_write_func(fd, buffer, length, &junk_errno, + return ffs_server_write_func(fd, buffer, length, &junk_errno, &junk_result_str); } static void -provisional_use_warning(fd) -int fd; +provisional_use_warning(int fd) { static int warned = 0; @@ -3298,9 +3218,7 @@ dump_server_error(char *string, FMContext context) } static int -server_register_format(fmc, format) -FMContext fmc; -FMFormat format; +server_register_format(FMContext fmc, FMFormat format) { int tries = 0; @@ -3333,12 +3251,12 @@ FMFormat format; format_rep rep = format->server_format_rep; tmp.len = rep->format_rep_length; - ret = os_server_write_func(fmc->server_fd, &tmp, sizeof(tmp), + ret = ffs_server_write_func(fmc->server_fd, &tmp, sizeof(tmp), &errno, &errstr); if (ret != sizeof(tmp)) goto retry; - ret = os_server_write_func(fmc->server_fd, + ret = ffs_server_write_func(fmc->server_fd, (char*) rep + sizeof(tmp.len), ntohs(rep->format_rep_length) - sizeof(tmp.len), &errno, &errstr); @@ -3351,7 +3269,7 @@ FMFormat format; goto retry; } if (ret_info[0] == 'P') { - provisional_use_warning((int) (long) fmc->server_fd); + provisional_use_warning((int) (intptr_t) fmc->server_fd); } else { if (ret_info[0] != 'I') { dump_server_error("Bad character from format server\n", fmc); @@ -3378,11 +3296,7 @@ static const char xchars[] = "0123456789abcdef"; #define nibble2hex(val) (xchars[val & 0x0f]) static char * -stringify_field_type(type, base_format, buffer, size) -const char *type; -FMFormat base_format; -char *buffer; -int size; +stringify_field_type(const char *type, FMFormat base_format, char *buffer, int size) { char *index_start; unsigned char *server_ID; @@ -3435,9 +3349,7 @@ int size; } extern int -global_name_eq(format1, format2) -FMFormat format1; -FMFormat format2; +global_name_eq(FMFormat format1, FMFormat format2) { if (format1->server_ID.length != format2->server_ID.length) return 0; @@ -3447,18 +3359,16 @@ FMFormat format2; extern char * -global_name_of_FMFormat(format) -FMFormat format; +global_name_of_FMFormat(FMFormat format) { - int size = strlen(format->format_name) + 3 + + int size = (int) strlen(format->format_name) + 3 + 2 * format->server_ID.length; char *buffer = malloc(size); return stringify_field_type(format->format_name, format, buffer, size); } static FMFormat -expand_subformat_from_rep_0(rep) -struct _subformat_wire_format *rep; +expand_subformat_from_rep_0(struct _subformat_wire_format *rep) { FMFormat format = new_FMFormat(); struct _field_wire_format_0 *fields; @@ -3571,8 +3481,7 @@ struct _subformat_wire_format *rep; static FMFormat -expand_subformat_from_rep_1(rep) -struct _subformat_wire_format *rep; +expand_subformat_from_rep_1(struct _subformat_wire_format *rep) { FMFormat format = new_FMFormat(); struct _field_wire_format_1 *fields; @@ -3687,8 +3596,7 @@ struct _subformat_wire_format *rep; static FMFormat -expand_subformat_from_rep(rep) -struct _subformat_wire_format *rep; +expand_subformat_from_rep(struct _subformat_wire_format *rep) { if (rep->f.f0.server_rep_version == 0) { return expand_subformat_from_rep_0(rep); @@ -3704,8 +3612,7 @@ struct _subformat_wire_format *rep; } extern FMFormat -expand_format_from_rep(rep) -format_rep rep; +expand_format_from_rep(format_rep rep) { int format_count; FMFormat top_format; @@ -3817,20 +3724,16 @@ fill_derived_format_values(FMContext fmc, FMFormat format) } extern void -add_format_to_iofile(fmc, format, id_size, id_buffer, index) -FMContext fmc; -FMFormat format; -int id_size; -void *id_buffer; -int index; +add_format_to_iofile(FMContext fmc, FMFormat format, int id_size, + void *id_buffer, int index) { int subformat_count = 0; int i, field; if (get_format_server_verbose()) { - printf("Entering format %s (%lx) into context %lx ", - format->format_name, (long)format, - (long)fmc); + printf("Entering format %s (%p) into context %p ", + format->format_name, format, + fmc); print_server_ID(id_buffer); } while (format->subformats && format->subformats[subformat_count]) { @@ -3890,6 +3793,11 @@ int index; } } +#ifdef _MSC_VER +#define srand48(x) srand((int)(x)) +#define drand48() ((double)rand()/RAND_MAX) +#endif + int FMcontext_get_format_server_identifier(FMContext fmc) { @@ -3897,7 +3805,7 @@ FMcontext_get_format_server_identifier(FMContext fmc) return -1; } if (fmc->format_server_identifier == 0) { - srand48(getpid()); + srand48(time(0)); if (establish_server_connection_ptr(fmc, host_and_fallback) == 0) { if (establish_server_connection_ptr(fmc, host_and_fallback) == 0) { printf("Failed to contact format server\n"); @@ -3908,9 +3816,7 @@ FMcontext_get_format_server_identifier(FMContext fmc) } static FMFormat -server_get_format(iocontext, buffer) -FMContext iocontext; -void *buffer; +server_get_format(FMContext iocontext, void *buffer) { FMContext fmc = (FMContext) iocontext; FMFormat format = NULL; @@ -3955,7 +3861,7 @@ void *buffer; goto retry; } if (return_char == 'P') { - provisional_use_warning((int) (long) fmc->server_fd); + provisional_use_warning((int) (intptr_t) fmc->server_fd); if (serverAtomicRead(fmc->server_fd, &return_char, 1) != 1) { if (get_format_server_verbose()) { printf("Retrying because of failed read\n"); @@ -4017,9 +3923,7 @@ void *buffer; } extern void -server_get_server_ID(fd, server_ID) -void *fd; -void *server_ID; +server_get_server_ID(void *fd, void *server_ID) { int id_size = 8; @@ -4036,14 +3940,14 @@ stringify_server_ID(unsigned char *ID, char *buffer, int len) case 0: if (len < id_size * 2) break; for (i = 0; i < id_size; i++) { - point += sprintf(&buffer[point], "%2x", ID[i]); + point += snprintf(&buffer[point], len - point, "%2x", ID[i]); } break; case 1:{ version_1_format_ID id1; memcpy(&id1, ID, 10); if (len < 3+3+6+10+6+50) /* approx size */ return; - sprintf(buffer, "\n", + snprintf(buffer, len, "\n", id1.version, id1.salt, ntohs(id1.port), ntohl(id1.IP_addr), ntohs(id1.format_identifier)); break; @@ -4051,22 +3955,21 @@ stringify_server_ID(unsigned char *ID, char *buffer, int len) case 2:{ version_2_format_ID *id2 = (version_2_format_ID*)ID; if (len < 3+3+6+10+6+50) /* approx size */ return; - sprintf(buffer, "\n", + snprintf(buffer, len, "\n", id2->version, id2->unused, ntohs(id2->rep_len) << 2, ntohl(id2->hash1), ntohl(id2->hash2)); break; } default: if (len < 30) return; - sprintf(buffer, "server_ID.value); } @@ -4115,8 +4017,7 @@ void *format_ID; #endif extern int -get_rep_len_format_ID(format_ID) -void *format_ID; +get_rep_len_format_ID(void *format_ID) { switch (version_of_format_ID(format_ID)) { case 2:{ @@ -4170,10 +4071,7 @@ void *format_ID; /* write header information to the format server */ extern int -server_write_header(fmc, enc_len, enc_buffer) -FMContext fmc; -int enc_len; -unsigned char *enc_buffer; +server_write_header(FMContext fmc, int enc_len, unsigned char *enc_buffer) { FILE_INT magic = MAGIC_NUMBER + CURRENT_PROTOCOL_VERSION; FILE_INT server_pid; @@ -4223,9 +4121,7 @@ version_of_format_ID(void *server_ID) } extern char * -get_server_rep_FMformat(format, rep_length) -FMFormat format; -int *rep_length; +get_server_rep_FMformat(FMFormat format, int *rep_length) { if (format->server_format_rep == NULL) { format->server_format_rep = @@ -4239,28 +4135,22 @@ int *rep_length; } extern char * -get_server_ID_FMformat(format, id_length) -FMFormat format; -int *id_length; +get_server_ID_FMformat(FMFormat format, int *id_length) { *id_length = format->server_ID.length; return format->server_ID.value; } extern FMContext -FMContext_from_FMformat(format) -FMFormat format; +FMContext_from_FMformat(FMFormat format) { return format->context; } extern FMFormat -load_external_format_FMcontext(iocontext, server_id, id_size, server_rep) -FMContext iocontext; -char *server_id; -int id_size; -char *server_rep; +load_external_format_FMcontext(FMContext iocontext, char *server_id, int id_size, + char *server_rep) { FMFormat format = get_local_format_IOcontext(iocontext, server_id); @@ -4300,3 +4190,24 @@ set_array_order_FMContext(FMContext iofile, int column_major) iofile->native_column_major_arrays = column_major; } +#undef malloc +#undef realloc + +void* ffs_malloc(size_t s) +{ + void* tmp = malloc(s); + if (!tmp) { + fprintf(stderr, "FFS out of memory\n"); + exit(1); + } + return tmp; +} +void* ffs_realloc(void* ptr, size_t s) +{ + void* tmp = realloc(ptr, s); + if (!tmp) { + fprintf(stderr, "FFS out of memory\n"); + exit(1); + } + return tmp; +} diff --git a/fm/fm_get.c b/fm/fm_get.c index 70f19e4284..6b0e1829ca 100755 --- a/fm/fm_get.c +++ b/fm/fm_get.c @@ -29,21 +29,19 @@ #include "fm_internal.h" #include "assert.h" -#ifndef tolower +#if !defined(tolower) & !defined(_MSC_VER) extern int tolower(int); #endif extern FMfloat_format fm_my_float_format; -static long get_offset(void *, int, int); +static size_t get_offset(void *, int, int); static MAX_UNSIGNED_TYPE get_big_unsigned(FMFieldPtr field, void *data); static MAX_FLOAT_TYPE get_big_float(FMFieldPtr field, void *data); static int get_long_warn = 0; static void -byte_swap(data, size) -char *data; -int size; +byte_swap(char *data, int size) { int i; assert((size % 2) == 0); @@ -55,9 +53,7 @@ int size; } static MAX_INTEGER_TYPE -get_big_int(field, data) -FMFieldPtr field; -void *data; +get_big_int(FMFieldPtr field, void *data) { if (field->data_type == integer_type) { if (field->size == sizeof(char)) { @@ -76,15 +72,15 @@ void *data; if (field->byte_swap) byte_swap((char *) &tmp, (int) sizeof(int)); return (long) tmp; - } else if (field->size == sizeof(long)) { - long tmp; - memcpy(&tmp, (char *) data + field->offset, sizeof(long)); + } else if (field->size == sizeof(size_t)) { + size_t tmp; + memcpy(&tmp, (char *) data + field->offset, sizeof(size_t)); if (field->byte_swap) - byte_swap((char *) &tmp, (int)sizeof(long)); + byte_swap((char *) &tmp, (int)sizeof(size_t)); return tmp; } else if (field->size == 2 * sizeof(long)) { long tmp; - int low_bytes_offset = field->offset; + size_t low_bytes_offset = field->offset; if (WORDS_BIGENDIAN) { if (!field->byte_swap) { low_bytes_offset += sizeof(long); @@ -124,9 +120,7 @@ void *data; } static MAX_UNSIGNED_TYPE -get_big_unsigned(field, data) -FMFieldPtr field; -void *data; +get_big_unsigned(FMFieldPtr field, void *data) { if ((field->data_type == unsigned_type) || (field->data_type == enumeration_type) || @@ -147,15 +141,15 @@ void *data; if (field->byte_swap) byte_swap((char *) &tmp, (int)sizeof(int)); return (MAX_UNSIGNED_TYPE) tmp; - } else if (field->size == sizeof(long)) { - unsigned long tmp; - memcpy(&tmp, (char *) data + field->offset, sizeof(long)); + } else if (field->size == sizeof(size_t)) { + size_t tmp; + memcpy(&tmp, (char *) data + field->offset, sizeof(size_t)); if (field->byte_swap) - byte_swap((char *) &tmp, (int)sizeof(long)); + byte_swap((char *) &tmp, (int)sizeof(size_t)); return tmp; } else if (field->size == 2 * sizeof(long)) { unsigned long tmp; - int low_bytes_offset = field->offset; + size_t low_bytes_offset = field->offset; if (WORDS_BIGENDIAN) { if (!field->byte_swap) { low_bytes_offset += sizeof(long); @@ -224,9 +218,7 @@ float_conversion(unsigned char*value, int size, FMfloat_format src_format, } static MAX_FLOAT_TYPE -get_big_float(field, data) -FMFieldPtr field; -void *data; +get_big_float(FMFieldPtr field, void *data) { if (field->data_type == float_type) { if (field->size == sizeof(float)) { @@ -301,19 +293,15 @@ void *data; } extern float -get_FMfloat(field, data) -FMFieldPtr field; -void *data; +get_FMfloat(FMFieldPtr field, void *data) { float tmp; - tmp = get_big_float(field, data); + tmp = (float)get_big_float(field, data); return tmp; } extern double -get_FMdouble(field, data) -FMFieldPtr field; -void *data; +get_FMdouble(FMFieldPtr field, void *data) { double tmp; tmp = get_big_float(field, data); @@ -323,9 +311,7 @@ void *data; #if SIZEOF_LONG_DOUBLE != 0 extern long double -get_FMlong_double(field, data) -FMFieldPtr field; -void *data; +get_FMlong_double(FMFieldPtr field, void *data) { long double tmp; tmp = get_big_float(field, data); @@ -334,74 +320,58 @@ void *data; #endif extern short -get_FMshort(field, data) -FMFieldPtr field; -void *data; +get_FMshort(FMFieldPtr field, void *data) { - short tmp = get_big_int(field, data); + short tmp = (short)get_big_int(field, data); return tmp; } extern unsigned short -get_FMushort(field, data) -FMFieldPtr field; -void *data; +get_FMushort(FMFieldPtr field, void *data) { - unsigned short tmp = get_big_unsigned(field, data); + unsigned short tmp = (unsigned short) get_big_unsigned(field, data); return tmp; } extern int -get_FMint(field, data) -FMFieldPtr field; -void *data; +get_FMint(FMFieldPtr field, void *data) { - int tmp= get_big_int(field, data); + int tmp = (int) get_big_int(field, data); return tmp; } extern unsigned int -get_FMuint(field, data) -FMFieldPtr field; -void *data; +get_FMuint(FMFieldPtr field, void *data) { - unsigned int tmp = get_big_unsigned(field, data); + unsigned int tmp = (unsigned int) get_big_unsigned(field, data); return tmp; } -extern long -get_FMlong(field, data) -FMFieldPtr field; -void *data; +extern size_t +get_FMlong(FMFieldPtr field, void *data) { - long tmp = get_big_int(field, data); + ssize_t tmp = get_big_int(field, data); return tmp; } -extern unsigned long -get_FMulong(field, data) -FMFieldPtr field; -void *data; +extern size_t +get_FMulong(FMFieldPtr field, void *data) { - unsigned long tmp = get_big_unsigned(field, data); + size_t tmp = get_big_unsigned(field, data); return tmp; } #if SIZEOF_LONG_LONG != 0 extern long long -get_FMlong_long(field, data) -FMFieldPtr field; -void *data; +get_FMlong_long(FMFieldPtr field, void *data) { long long tmp= get_big_int(field, data); return tmp; } extern unsigned long long -get_FMulong_long(field, data) -FMFieldPtr field; -void *data; +get_FMulong_long(FMFieldPtr field, void *data) { unsigned long long tmp = get_big_unsigned(field, data); return tmp; @@ -410,19 +380,15 @@ void *data; #endif extern void -get_FMlong8(field, data, low_long, high_long) -FMFieldPtr field; -void *data; -unsigned long *low_long; -long *high_long; +get_FMlong8(FMFieldPtr field, void *data, unsigned long *low_long, long *high_long) { *low_long = 0; if (high_long) *high_long = 0; if (field->data_type == integer_type) { if (field->size == 2 * sizeof(long)) { - int low_bytes_offset = field->offset; - int high_bytes_offset = field->offset; + size_t low_bytes_offset = field->offset; + size_t high_bytes_offset = field->offset; FMgetFieldStruct tmp_field; /*OK */ tmp_field = *field; if (WORDS_BIGENDIAN) { @@ -440,15 +406,15 @@ long *high_long; } tmp_field.size = sizeof(long); tmp_field.offset = low_bytes_offset; - *low_long = get_FMulong(&tmp_field, data); + *low_long = (unsigned long) get_FMulong(&tmp_field, data); if (high_long) { tmp_field = *field; tmp_field.size = sizeof(long); tmp_field.offset = high_bytes_offset; - *high_long = get_FMlong(&tmp_field, data); + *high_long = (long) get_FMlong(&tmp_field, data); } } else { - *low_long = get_FMlong(field, data); + *low_long = (long) get_FMlong(field, data); } } else if (field->data_type == float_type) { MAX_FLOAT_TYPE tmp; @@ -461,19 +427,15 @@ long *high_long; } extern int -get_FMulong8(field, data, low_long, high_long) -FMFieldPtr field; -void *data; -unsigned long *low_long; -unsigned long *high_long; +get_FMulong8(FMFieldPtr field, void *data, unsigned long *low_long, unsigned long *high_long) { *low_long = 0; if (high_long) *high_long = 0; if (field->data_type == unsigned_type) { if (field->size == 2 * sizeof(long)) { - int low_bytes_offset = field->offset; - int high_bytes_offset = field->offset; + size_t low_bytes_offset = field->offset; + size_t high_bytes_offset = field->offset; FMgetFieldStruct tmp_field; /*OK */ tmp_field = *field; if (WORDS_BIGENDIAN) { @@ -491,16 +453,16 @@ unsigned long *high_long; } tmp_field.size = sizeof(unsigned long); tmp_field.offset = low_bytes_offset; - *low_long = get_FMulong(&tmp_field, data); + *low_long = (unsigned long) get_FMulong(&tmp_field, data); if (high_long) { tmp_field = *field; tmp_field.size = sizeof(unsigned long); tmp_field.offset = high_bytes_offset; - *high_long = get_FMulong(&tmp_field, data); + *high_long = (unsigned long) get_FMulong(&tmp_field, data); } return 0; } else { - *low_long = get_FMulong(field, data); + *low_long = (unsigned long) get_FMulong(field, data); return 0; } } else if (field->data_type == integer_type) { @@ -521,9 +483,7 @@ unsigned long *high_long; } extern char -get_FMchar(field, data) -FMFieldPtr field; -void *data; +get_FMchar(FMFieldPtr field, void *data) { if (field->data_type == char_type) { return (char) *((char *) data + field->offset); @@ -536,9 +496,7 @@ void *data; } extern int -get_FMenum(field, data) -FMFieldPtr field; -void *data; +get_FMenum(FMFieldPtr field, void *data) { FMgetFieldStruct tmp_field; /*OK */ tmp_field = *field; @@ -547,24 +505,19 @@ void *data; } extern char * -get_FMstring(field, data) -FMFieldPtr field; -void *data; +get_FMstring(FMFieldPtr field, void *data) { return get_FMstring_base(field, data, data); } extern char * -get_FMstring_base(field, data, string_base) -FMFieldPtr field; -void *data; -void *string_base; +get_FMstring_base(FMFieldPtr field, void *data, void *string_base) { - unsigned long offset = get_offset((void *) ((char *) data + field->offset), + uintptr_t offset = get_offset((void *) ((char *) data + field->offset), field->size, field->byte_swap); if (offset == 0) { return NULL; - } else if (offset > (unsigned long) data) { /* probably * + } else if (offset > (uintptr_t) data) { /* probably * * converted * * string */ return (char *) offset; @@ -574,13 +527,9 @@ void *string_base; } extern void * -get_FMaddr(field, data, string_base, encode) -FMFieldPtr field; -void *data; -void *string_base; -int encode; +get_FMaddr(FMFieldPtr field, void *data, void *string_base, int encode) { - unsigned long offset = get_offset((void *) ((char *) data + field->offset), + uintptr_t offset = get_offset((void *) ((char *) data + field->offset), field->size, field->byte_swap); if (offset == 0) { return NULL; @@ -591,11 +540,8 @@ int encode; } } -static long -get_offset(data, size, swap) -void *data; -int size; -int swap; +static size_t +get_offset(void *data, int size, int swap) { FMgetFieldStruct field; /*OK */ field.offset = 0; @@ -605,16 +551,14 @@ int swap; if (size == sizeof(int)) { return get_FMlong(&field, data); } else { - field.offset = size - sizeof(long); - field.size = sizeof(long); + field.offset = size - sizeof(size_t); + field.size = sizeof(size_t); return get_FMlong(&field, data); } } extern int -FM_field_type_eq(str1, str2) -const char *str1; -const char *str2; +FM_field_type_eq(const char *str1, const char *str2) { FMdata_type t1, t2; long t1_count, t2_count; @@ -631,8 +575,8 @@ const char *str2; char *colon2 = strchr(tmp_str2, ':'); char *lparen1 = strchr(str1, '['); char *lparen2 = strchr(str2, '['); - int count1 = 0; - int count2 = 0; + intptr_t count1 = 0; + intptr_t count2 = 0; if (colon1 != NULL) { count1 = colon1 - tmp_str1; @@ -658,11 +602,7 @@ const char *str2; } extern int -IOget_array_size_dimen(str, fields, dimen, control_field) -const char *str; -FMFieldList fields; -int dimen; -int *control_field; +IOget_array_size_dimen(const char *str, FMFieldList fields, int dimen, int *control_field) { char *left_paren, *end; long static_size; @@ -725,9 +665,7 @@ int *control_field; } extern FMFieldPtr -get_FMfieldPtrFromList(field_list, fieldname) -FMFieldList field_list; -const char *fieldname; +get_FMfieldPtrFromList(FMFieldList field_list, const char *fieldname) { int index; FMFieldPtr ret_val; @@ -797,7 +735,7 @@ get_FMfieldInt_by_name(FMFieldList field_list, const char *fieldname, void *data return get_FMint(&descr, data); } -extern long +extern size_t get_FMfieldLong_by_name(FMFieldList field_list, const char *fieldname, void *data) { int index; @@ -839,7 +777,7 @@ get_FMPtrField_by_name(FMFieldList field_list, const char *fieldname, void *data field.size = sizeof(void*); field.byte_swap = 0; - unsigned long offset = get_offset((void *) ((char *) data + field.offset), + size_t offset = get_offset((void *) ((char *) data + field.offset), field.size, field.byte_swap); if (offset == 0) { return NULL; @@ -869,9 +807,7 @@ set_FMPtrField_by_name(FMFieldList field_list, const char *fieldname, void *data } extern FMFieldPtr -get_FMfieldPtr(format, fieldname) -FMFormat format; -const char *fieldname; +get_FMfieldPtr(FMFormat format, const char *fieldname) { int index; FMFieldPtr ret_val; @@ -908,9 +844,7 @@ const char *fieldname; } extern FMFieldPtr -get_local_FieldPtr(format, fieldname) -FMFormat format; -const char *fieldname; +get_local_FieldPtr(FMFormat format, const char *fieldname) { FMFieldPtr ret_val = get_FMfieldPtr(format, fieldname); diff --git a/fm/fm_internal.h b/fm/fm_internal.h index 0fe802822f..1fd7abc0c5 100755 --- a/fm/fm_internal.h +++ b/fm/fm_internal.h @@ -1,6 +1,13 @@ #ifndef FM_INTERNAL_H #define FM_INTERNAL_H +#if defined(_MSC_VER) +#include +typedef SSIZE_T ssize_t; +#define strncpy(dest, src, size) strcpy_s(dest, size, src) +#define snprintf sprintf_s +#endif + #define MAGIC_NUMBER 0x4356ffa9 /* random magic */ #define REVERSE_MAGIC_NUMBER 0xa9ff5643 /* byte reversed random * magic */ @@ -91,7 +98,7 @@ extern FMTypeDesc* gen_FMTypeDesc(FMFieldList fl, int field, const char *typ); typedef struct _FMgetFieldStruct { - int offset; + size_t offset; int size; FMdata_type data_type; unsigned char byte_swap; @@ -262,18 +269,22 @@ typedef struct { #define MAX_UNSIGNED_TYPE unsigned MAX_INTEGER_TYPE -typedef int (*IOinterface_func)(void *conn, void *buffer, int length, +typedef int (*IOinterface_func)(void *conn, void *buffer, size_t length, int *errno_p, char **result_p); #if !defined(HAVE_IOVEC_DEFINE) && !defined(_STRUCT_IOVEC) && !(defined(_BITS_UIO_H)) -#define HAVE_IOVEC_DEFINE +#define _STRUCT_IOVEC struct iovec { const void *iov_base; - long iov_len; + size_t iov_len; }; #else +#ifdef _MSC_VER +#include "winsock.h" +#else #include #endif +#endif typedef int (*IOinterface_funcv)(void *conn, struct iovec *iov, int icount, int *errno_p, @@ -286,20 +297,12 @@ typedef int (*IOinterface_poll)(void *conn); typedef void *(*IOinterface_open)(const char *path, const char *flag_str, int *input, int *output); +typedef int (*IOinterface_lseek)(void* conn, size_t pos, int cmd); typedef void (*IOinterface_init)(void ); -extern IOinterface_func os_file_read_func; -extern IOinterface_func os_file_write_func; - -extern IOinterface_func os_read_func; -extern IOinterface_func os_write_func; -extern int os_max_iov; -extern IOinterface_close os_close_func; -extern IOinterface_poll os_poll_func; -extern IOinterface_open os_file_open_func; -extern IOinterface_func os_server_read_func; -extern IOinterface_func os_server_write_func; -extern IOinterface_init os_sockets_init_func; +extern IOinterface_func ffs_server_read_func; +extern IOinterface_func ffs_server_write_func; +extern IOinterface_init ffs_sockets_init_func; extern int version_of_format_ID(void *server_ID); extern int FFS_gen_authentication (unsigned char *outbuf); @@ -321,4 +324,12 @@ extern void dump_FMFormat(FMFormat ioformat); extern int format_server_restarted(FMContext context); extern int FMhas_XML_info(FMFormat format); extern int get_internal_format_server_identifier(format_server fs); + +#ifdef HAVE_MALLOC_H +#include +#endif +#define malloc(x) ffs_malloc(x) +#define realloc(ptr, s) ffs_realloc(ptr, s) +void* ffs_malloc(size_t s); +void* ffs_realloc(void* ptr, size_t s); #endif diff --git a/ffs/io_interface.h b/fm/io_interface.h old mode 100755 new mode 100644 similarity index 62% rename from ffs/io_interface.h rename to fm/io_interface.h index 3ca19aed96..e0f635bdec --- a/ffs/io_interface.h +++ b/fm/io_interface.h @@ -1,52 +1,37 @@ -#if defined(HAVE_WINDOWS_H) && !defined(NEED_IOVEC_DEFINE) -#define NEED_IOVEC_DEFINE -#endif - -#ifdef NEED_IOVEC_DEFINE -struct iovec { - void *iov_base; - int iov_len; -}; -#endif - -#if defined(FUNCPROTO) || defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) -#ifndef ARGS -#define ARGS(args) args -#endif -#else -#ifndef ARGS -#define ARGS(args) (/*args*/) -#endif -#endif - -#ifndef HAVE_IOVEC_DEFINE -#define HAVE_IOVEC_DEFINE +#if defined(HAVE_WINDOWS_H) && !defined(NEED_IOVEC_DEFINE) && !defined(_STRUCT_IOVEC) +#define _STRUCT_IOVEC struct iovec { const void *iov_base; size_t iov_len; }; #endif +#ifndef _MSC_VER +#define SOCKET int +#endif + #ifndef FM_INTERNAL_H -typedef int (*IOinterface_func) ARGS((void *conn, void *buffer, int length, - int *errno_p, char **result_p)); +typedef int (*IOinterface_func)(void *conn, void *buffer, size_t length, + int *errno_p, char **result_p); -typedef int (*IOinterface_funcv) ARGS((void *conn, struct iovec *iov, +typedef int (*IOinterface_funcv)(void *conn, struct iovec *iov, int icount, int *errno_p, - char **result_p)); + char **result_p); -typedef int (*IOinterface_close) ARGS((void *conn)); +typedef int (*IOinterface_close)(void *conn); -typedef int (*IOinterface_poll) ARGS((void *conn)); +typedef int (*IOinterface_poll)(void *conn); typedef void *(*IOinterface_open)(const char *path, const char *flag_str, int *input, int *output); typedef void (*IOinterface_init)(void ); +typedef int (*IOinterface_lseek)(void* conn, size_t pos, int cmd); #endif extern IOinterface_func ffs_file_read_func; extern IOinterface_func ffs_file_write_func; extern IOinterface_funcv ffs_file_readv_func; extern IOinterface_funcv ffs_file_writev_func; +extern IOinterface_lseek ffs_file_lseek_func; extern IOinterface_func ffs_read_func; extern IOinterface_func ffs_write_func; @@ -55,7 +40,9 @@ extern IOinterface_funcv ffs_writev_func; extern int ffs_max_iov; extern IOinterface_close ffs_close_func; extern IOinterface_open ffs_file_open_func; +extern IOinterface_init ffs_sockets_init_func; +#ifdef __FFS_H__ extern void set_interface_FFSFile(FFSFile f, IOinterface_func write_func, IOinterface_func read_func, @@ -77,3 +64,4 @@ set_socket_interface_FFSFile(FFSFile f); extern void set_file_interface_FFSFile(FFSFile f); +#endif diff --git a/fm/lookup3.c b/fm/lookup3.c index 1c1e56c47d..ee6463540d 100755 --- a/fm/lookup3.c +++ b/fm/lookup3.c @@ -37,7 +37,9 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy. #include /* defines printf for tests */ #include /* defines time_t for timings in the test */ #include /* defines uint32_t etc */ +#ifndef _MSC_VER #include /* attempt to define endianness */ +#endif #ifdef linux # include /* attempt to define endianness */ #endif diff --git a/fm/nt_io.c b/fm/nt_io.c index b532473c73..c0d047c808 100755 --- a/fm/nt_io.c +++ b/fm/nt_io.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "ffs.h" #include "io_interface.h" #include "ffs_internal.h" @@ -26,21 +27,14 @@ char **result_p; bResult = ReadFile(conn, (char *) buffer, length, &iget, NULL); if (iget == 0) { - *result_p = "End of file"; - *errno_p = 0; + if (result_p) *result_p = "End of file"; + if (errno_p) *errno_p = 0; return 0; /* end of file */ } else { if (!bResult) { - *errno_p = GetLastError(); - if ((*errno_p != WSAEWOULDBLOCK) && - (*errno_p != WSAEINPROGRESS) && - (*errno_p != WSAEINTR)) { - /* serious error */ - return -1; - } else { - *errno_p = 0; - iget = 0; - } + return -1; + } else { + if(errno_p) *errno_p = 0; } } @@ -49,22 +43,15 @@ char **result_p; bResult = ReadFile((HANDLE) conn, (char *) buffer + length - left, left, &iget, NULL); if (iget == 0) { - *result_p = "End of file"; - *errno_p = 0; + if (result_p) *result_p = "End of file"; + if (errno_p) *errno_p = 0; return length - left; /* end of file */ } else { if (!bResult) { - *errno_p = GetLastError(); - if ((*errno_p != WSAEWOULDBLOCK) && - (*errno_p != WSAEINPROGRESS) && - (*errno_p != WSAEINTR)) { - /* serious error */ return (length - left); } else { - *errno_p = 0; - iget = 0; + if (errno_p) *errno_p = 0; } - } } left -= iget; } @@ -81,52 +68,54 @@ char **result_p; { int left = length; int iget; - iget = recv((unsigned int) conn, (char *) buffer + length - left, left, 0); + iget = recv((unsigned int) (intptr_t)conn, (char *) buffer + length - left, left, 0); if (iget == 0) { - *result_p = NULL; - *errno_p = 0; + if (result_p) *result_p = NULL; + if (errno_p) *errno_p = 0; return 0; /* No more socket data */ } else if (iget == SOCKET_ERROR) { - *errno_p = WSAGetLastError(); - if ((*errno_p != WSAEWOULDBLOCK) && - (*errno_p != WSAEINPROGRESS) && - (*errno_p != WSAECONNRESET) && - (*errno_p != WSAEINTR)) { + DWORD tmp = WSAGetLastError(); + if (errno_p) *errno_p = tmp; + if ((tmp != WSAEWOULDBLOCK) && + (tmp != WSAEINPROGRESS) && + (tmp != WSAECONNRESET) && + (tmp != WSAEINTR)) { /* serious error */ - fprintf(stderr, "WINSOCK ERROR during receive, %i on socket %i\n", - *errno_p, conn); + fprintf(stderr, "WINSOCK ERROR during receive, %i on socket %p\n", + tmp, conn); return -1; } else { - if (*errno_p == WSAECONNRESET) + if (tmp == WSAECONNRESET) return -1; - *errno_p = 0; + if (errno_p) *errno_p = 0; iget = 0; } } left = length - iget; while (left > 0) { - iget = recv((unsigned int) conn, (char *) buffer + length - left, + iget = recv((unsigned int)(intptr_t) conn, (char *) buffer + length - left, left, 0); if (iget == 0) { - *result_p = NULL; - *errno_p = 0; + if (result_p) *result_p = NULL; + if (errno_p) *errno_p = 0; return length - left; /* no more socket data */ } else { if (iget == SOCKET_ERROR) { - *errno_p = WSAGetLastError(); - if ((*errno_p != WSAEWOULDBLOCK) && - (*errno_p != WSAEINPROGRESS) && - (*errno_p != WSAECONNRESET) && - (*errno_p != WSAEINTR)) { + DWORD tmp = WSAGetLastError(); + if (errno_p) *errno_p = tmp; + if ((tmp != WSAEWOULDBLOCK) && + (tmp != WSAEINPROGRESS) && + (tmp != WSAECONNRESET) && + (tmp != WSAEINTR)) { /* serious error */ - fprintf(stderr, "WINSOCK ERROR during receive2, %i on socket %i\n", - *errno_p, conn); + fprintf(stderr, "WINSOCK ERROR during receive2, %i on socket %p\n", + tmp, conn); return (length - left); } else { - if (*errno_p == WSAECONNRESET) + if (tmp == WSAECONNRESET) return -1; - *errno_p = 0; + if(errno_p) *errno_p = 0; iget = 0; } } @@ -154,14 +143,15 @@ char **result_p; bResult = WriteFile((HANDLE) conn, (char *) buffer + length - left, left, &iget, NULL); if (!bResult) { - *errno_p = GetLastError(); - if ((*errno_p != WSAEWOULDBLOCK) && - (*errno_p != WSAEINPROGRESS) && - (*errno_p != WSAEINTR)) { + DWORD tmp = GetLastError(); + if (errno_p) tmp = tmp; + if ((tmp != WSAEWOULDBLOCK) && + (tmp != WSAEINPROGRESS) && + (tmp != WSAEINTR)) { /* serious error */ return (length - left); } else { - *errno_p = 0; + if(errno_p) *errno_p = 0; iget = 0; } } @@ -183,17 +173,18 @@ char **result_p; int iget = 0; while (left > 0) { - iget = send((unsigned int) conn, (char *) buffer + length - left, + iget = send((unsigned int) (intptr_t)conn, (char *) buffer + length - left, left, 0); if (iget == SOCKET_ERROR) { - *errno_p = GetLastError(); - if ((*errno_p != WSAEWOULDBLOCK) && - (*errno_p != WSAEINPROGRESS) && - (*errno_p != WSAEINTR)) { + DWORD tmp = GetLastError(); + if (errno_p) *errno_p = tmp; + if ((tmp != WSAEWOULDBLOCK) && + (tmp != WSAEINPROGRESS) && + (tmp != WSAEINTR)) { /* serious error */ return (length - left); } else { - *errno_p = 0; + if (errno_p) *errno_p = 0; iget = 0; } } @@ -218,28 +209,34 @@ void *conn; } static void * -nt_file_open_func(path, flag_str, input, output) -const char *path; -const char *flag_str; -int *input; -int *output; +nt_file_open_func(const char *path, const char *flag_str, int *input, int *output) { - + int readfile = 0; + int writefile = 0; void *file; - long tmp_flags = (long)flag_str; + long tmp_flags = (long)(intptr_t)flag_str; + if (input) *input = 0; + if (output) *output = 0; + tmp_flags &= ~(O_TRUNC); tmp_flags &= ~(O_CREAT); if ((O_RDONLY == tmp_flags) || (O_WRONLY == tmp_flags)) { /* must be old style call */ - *input = (O_RDONLY == (long) flag_str); - *output = (O_WRONLY & (long) flag_str); + if (input) *input = (O_RDONLY == (long) (intptr_t)flag_str); + if (output) *output = (O_WRONLY & (long) (intptr_t)flag_str); } else { if (strcmp(flag_str, "r") == 0) { - *input = TRUE; + if (input) *input = TRUE; + readfile = 1; } else if (strcmp(flag_str, "w") == 0) { - *output = TRUE; + if (output) *output = TRUE; + writefile = 1; + } else if (strcmp(flag_str, "a") == 0) { + if (output) *output = 1; + if (input) *input = 1; + readfile = writefile = 1; } else { fprintf(stderr, "Open flags value not understood for file \"%s\"\n", path); @@ -247,7 +244,7 @@ int *output; } } - if (*input) { + if (readfile) { file = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL); @@ -262,6 +259,12 @@ int *output; } } +static int +nt_file_lseek_func (void *file, size_t pos, int origin) +{ + return SetFilePointer((HANDLE)file, (long)pos, 0, origin); +} + static int nt_socket_readv_func(conn, iov, icount, errno_p, result_p) @@ -302,14 +305,35 @@ char **result_p; return icount; } +static int +null_file_writev_func(conn, iov, icount, errno_p, result_p) +void* conn; +struct iovec* iov; +int icount; +int* errno_p; +char** result_p; +{ + + int i = 0; + for (; i < icount; i++) { + if (nt_file_write_func(conn, iov[i].iov_base, iov[i].iov_len, errno_p, + result_p) != iov[i].iov_len) { + return i; + } + } + return icount; +} /* Winsock init stuff, ask for ver 1.1 */ -static WORD wVersionRequested = MAKEWORD(1, 1); +static WORD wVersionRequested = MAKEWORD(2, 2); static WSADATA wsaData; static void nt_socket_init_func() { + static int once = 0; + if (once) return; + once = 1; int nErrorStatus; nErrorStatus = WSAStartup(wVersionRequested, &wsaData); if (nErrorStatus != 0) { @@ -324,7 +348,7 @@ static int nt_poll_func(conn) void *conn; { - int fd = (int) (long) conn; + int fd = (int) (intptr_t) conn; struct timeval time; fd_set read_fds; int ret_val; @@ -340,22 +364,23 @@ void *conn; return (ret_val > 0); } -IOinterface_func os_file_read_func = (IOinterface_func)nt_file_read_func; -IOinterface_func os_file_write_func = (IOinterface_func)nt_file_write_func; -IOinterface_funcv os_file_readv_func = (IOinterface_funcv)null_file_readv_func; -IOinterface_funcv os_file_writev_func = NULL; +IOinterface_func ffs_file_read_func = (IOinterface_func)nt_file_read_func; +IOinterface_func ffs_file_write_func = (IOinterface_func)nt_file_write_func; +IOinterface_funcv ffs_file_readv_func = (IOinterface_funcv)null_file_readv_func; +IOinterface_funcv ffs_file_writev_func = (IOinterface_funcv)null_file_writev_func; +IOinterface_lseek ffs_file_lseek_func = (IOinterface_lseek)nt_file_lseek_func; -IOinterface_func os_read_func = (IOinterface_func)nt_socket_read_func; -IOinterface_func os_write_func = (IOinterface_func)nt_socket_write_func; -IOinterface_funcv os_readv_func = (IOinterface_funcv)nt_socket_readv_func; -IOinterface_funcv os_writev_func = NULL; -int os_max_iov = 1; +IOinterface_func ffs_read_func = (IOinterface_func)nt_socket_read_func; +IOinterface_func ffs_write_func = (IOinterface_func)nt_socket_write_func; +IOinterface_funcv ffs_readv_func = (IOinterface_funcv)nt_socket_readv_func; +IOinterface_funcv ffs_writev_func = NULL; +int ffs_max_iov = 1; -IOinterface_open os_file_open_func = (IOinterface_open)nt_file_open_func; -IOinterface_close os_close_func = (IOinterface_close) nt_close_func; -IOinterface_poll os_poll_func = (IOinterface_poll)nt_poll_func; -IOinterface_func os_server_read_func = (IOinterface_func)nt_socket_read_func; -IOinterface_func os_server_write_func = (IOinterface_func)nt_socket_write_func; -IOinterface_init os_sockets_init_func = (IOinterface_init)nt_socket_init_func; +IOinterface_open ffs_file_open_func = (IOinterface_open)nt_file_open_func; +IOinterface_close ffs_close_func = (IOinterface_close) nt_close_func; +IOinterface_poll ffs_poll_func = (IOinterface_poll)nt_poll_func; +IOinterface_func ffs_server_read_func = (IOinterface_func)nt_socket_read_func; +IOinterface_func ffs_server_write_func = (IOinterface_func)nt_socket_write_func; +IOinterface_init ffs_sockets_init_func = (IOinterface_init)nt_socket_init_func; diff --git a/fm/null_io.c b/fm/null_io.c index 0c68b25dfe..d3b65f5bbf 100644 --- a/fm/null_io.c +++ b/fm/null_io.c @@ -101,22 +101,22 @@ void *conn; } -IOinterface_func os_file_read_func = null_read_func; -IOinterface_func os_file_write_func = null_write_func; -/*IOinterface_funcv os_file_readv_func = unix_readv_func; - IOinterface_funcv os_file_writev_func = unix_writev_func;*/ +IOinterface_func ffs_file_read_func = (IOinterface_func)null_read_func; +IOinterface_func ffs_file_write_func = (IOinterface_func)null_write_func; +/*IOinterface_funcv ffs_file_readv_func = unix_readv_func; + IOinterface_funcv ffs_file_writev_func = unix_writev_func;*/ -IOinterface_func os_read_func = null_read_func; -IOinterface_func os_write_func = null_write_func; -/*IOinterface_funcv os_readv_func = unix_readv_func; - IOinterface_funcv os_writev_func = unix_writev_func;*/ +IOinterface_func ffs_read_func = (IOinterface_func) null_read_func; +IOinterface_func ffs_write_func = (IOinterface_func)null_write_func; +/*IOinterface_funcv ffs_readv_func = unix_readv_func; + IOinterface_funcv ffs_writev_func = unix_writev_func;*/ #ifndef IOV_MAX #define IOV_MAX 16 #endif -int os_max_iov = IOV_MAX; -IOinterface_close os_close_func = null_close_func; -IOinterface_poll os_poll_func = null_poll_func; -IOinterface_open os_file_open_func = null_file_open_func; -IOinterface_func os_server_read_func = null_read_func; -IOinterface_func os_server_write_func = null_write_func; -IOinterface_init os_sockets_init_func = NULL; +int ffs_max_iov = IOV_MAX; +IOinterface_close ffs_close_func = (IOinterface_close)null_close_func; +IOinterface_poll ffs_poll_func = (IOinterface_poll)null_poll_func; +IOinterface_open ffs_file_open_func = (IOinterface_open)null_file_open_func; +IOinterface_func ffs_server_read_func = (IOinterface_func)null_read_func; +IOinterface_func ffs_server_write_func = (IOinterface_func)null_write_func; +IOinterface_init ffs_sockets_init_func = NULL; diff --git a/fm/progs/format_cmd.c b/fm/progs/format_cmd.c index 395167fd76..c9ce7fc2d8 100755 --- a/fm/progs/format_cmd.c +++ b/fm/progs/format_cmd.c @@ -27,14 +27,11 @@ extern int (*establish_server_connection_ptr)(FMContext fmc, action_t action); static int -serverAtomicWrite(fd, buffer, length) -void* fd; -void *buffer; -int length; +serverAtomicWrite(void* fd, void *buffer, int length) { char *junk_result_str; int junk_errno; - return os_server_write_func(fd, buffer, length, &junk_errno, + return ffs_server_write_func(fd, buffer, length, &junk_errno, &junk_result_str); } @@ -48,8 +45,7 @@ usage_exit() static char *format_server_host = "\"not set\""; static void -die_with_error(sig) -int sig; +die_with_error(int sig) { fprintf(stderr, "Format server %s not responding. Timeout.\n", format_server_host); @@ -57,11 +53,9 @@ int sig; } int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { - FMContext context = create_FMcontext(NULL); + FMContext context = create_FMcontext(); char format_command_char = 'c'; char format_dump_char = 'D'; char format_read_char = 'R'; diff --git a/fm/progs/format_dump.c b/fm/progs/format_dump.c index 82c6ad659e..08dc3df730 100755 --- a/fm/progs/format_dump.c +++ b/fm/progs/format_dump.c @@ -24,23 +24,18 @@ extern int sleep(); extern int (*establish_server_connection_ptr)(FMContext fmc, action_t action); static int -serverAtomicWrite(fd, buffer, length) -void* fd; -void *buffer; -int length; +serverAtomicWrite(void* fd, void *buffer, int length) { char *junk_result_str; int junk_errno; - return os_server_write_func(fd, buffer, length, &junk_errno, + return ffs_server_write_func(fd, buffer, length, &junk_errno, &junk_result_str); } int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { - FMContext context = create_FMcontext(NULL); + FMContext context = create_FMcontext(); char format_dump_char = 'D'; /* if (os_sockets_init_func != NULL) os_sockets_init_func();*/ diff --git a/fm/progs/format_info.c b/fm/progs/format_info.c index 0e2f532f20..bb68c02ed8 100755 --- a/fm/progs/format_info.c +++ b/fm/progs/format_info.c @@ -24,9 +24,7 @@ extern int sleep(); extern int (*establish_server_connection_ptr)(FMContext fmc, action_t action); int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { FMContext context = create_FMcontext(); FMFormat ioformat = NULL; diff --git a/fm/progs/format_server.c b/fm/progs/format_server.c index d2a0a40807..bbb698bac0 100755 --- a/fm/progs/format_server.c +++ b/fm/progs/format_server.c @@ -57,8 +57,7 @@ #include static void -die_with_error(sig) -int sig; +die_with_error(int sig) { fprintf(stderr, "Format server not responding. Timeout.\n"); exit(1); @@ -76,9 +75,7 @@ static int no_log = 0; extern void ffs_set_no_log(int in_no_log); int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { int i; int fs_port = DEFAULT_FS_PORT; diff --git a/fm/progs/server.c b/fm/progs/server.c index e5ba615b03..8730d26b69 100755 --- a/fm/progs/server.c +++ b/fm/progs/server.c @@ -50,6 +50,7 @@ #include "fm.h" #include "fm_internal.h" +#include "io_interface.h" #ifdef HAVE_MALLOC_H #include #endif @@ -137,7 +138,7 @@ extern int select(int width, fd_set * readfds, fd_set * writefds, #else #include #endif -extern time_t time(); +#include extern pid_t getpid(); #ifndef HAVE_GETDOMAINNAME extern int getdomainname(char *name, size_t len); @@ -244,15 +245,11 @@ LOG(format_server fs, char *format,...) } static int -LogAtomicRead(fs, fd, buffer, length) -format_server fs; -void *fd; -void *buffer; -long length; +LogAtomicRead(format_server fs, void *fd, void *buffer, long length) { char *junk_result_str = NULL; int junk_errno; - int ret = os_server_read_func(fd, buffer, length, &junk_errno, + int ret = ffs_server_read_func(fd, buffer, length, &junk_errno, &junk_result_str); if (getenv("BAD_CLIENT") && (drand48() < 0.0001)) sleep(600); @@ -365,7 +362,7 @@ format_server_poll_and_handle(format_server fs) FSClient_force_close(fs->ports[i]); } else if (i != (long) fs->conn_sock_inet) { FD_CLR((unsigned long) i, &fs->fdset); - os_close_func((void *) (long) i); + ffs_close_func((void *) (long) i); } found_one++; } @@ -409,9 +406,7 @@ format_server_poll_and_handle(format_server fs) } static int -format_eq(form1, form2) -IOFormatRep form1; -IOFormatRep form2; +format_eq(IOFormatRep form1, IOFormatRep form2) { int i; int all_zero = 1; @@ -446,9 +441,7 @@ IOFormatRep form2; static int server_format_count = 0; static void -byte_swap(data, size) -char *data; -int size; +byte_swap(char *data, int size) { int i; assert((size % 2) == 0); @@ -478,18 +471,18 @@ dump_formats_to_file(format_server fs) void *id = ioformat->server_ID.value; char *junk_result_str; int junk_errno; - if (os_server_write_func((void *) fd, &id_len, sizeof(id_len), + if (ffs_server_write_func((void *) fd, &id_len, sizeof(id_len), &junk_errno, &junk_result_str) != sizeof(id_len)) { fprintf(stderr, "error writing dump id len\n"); return; } - if (os_server_write_func((void *) fd, id, id_len, &junk_errno, + if (ffs_server_write_func((void *) fd, id, id_len, &junk_errno, &junk_result_str) != id_len) { fprintf(stderr, "error writing dump id \n"); return; } - if (os_server_write_func((void *) fd, rep, rep_len, &junk_errno, + if (ffs_server_write_func((void *) fd, rep, rep_len, &junk_errno, &junk_result_str) != rep_len) { fprintf(stderr, "error writing dump format rep\n"); return; @@ -647,7 +640,7 @@ register_format_to_master(format_server fs, IOFormatRep ioformat) format_rep rep = ioformat->server_format_rep; tmp.len = ntohs(ioformat->server_ID.length); - ret = os_server_write_func(server_fd, &tmp, sizeof(tmp), + ret = ffs_server_write_func(server_fd, &tmp, sizeof(tmp), &errno, &errstr); if (ret != sizeof(tmp)) { close((int)(long)server_fd); @@ -655,7 +648,7 @@ register_format_to_master(format_server fs, IOFormatRep ioformat) LOG(fs, "Write failed1\n"); return; } - ret = os_server_write_func(server_fd, + ret = ffs_server_write_func(server_fd, ioformat->server_ID.value, ioformat->server_ID.length, &errno, &errstr); @@ -671,14 +664,14 @@ register_format_to_master(format_server fs, IOFormatRep ioformat) print_server_ID( (unsigned char *) ioformat->server_ID.value); printf("Writing %d bytes of format rep\n", ntohs(rep->format_rep_length)); } - ret = os_server_write_func(server_fd, &rep->format_rep_length, 2, &errno, &errstr); + ret = ffs_server_write_func(server_fd, &rep->format_rep_length, 2, &errno, &errstr); if (ret != 2) { close((int)(long)server_fd); fs->proxy_context_to_master->server_fd = (void*)-1; LOG(fs, "Write failed3\n"); return; } - ret = os_server_write_func(server_fd, (char*) rep, + ret = ffs_server_write_func(server_fd, (char*) rep, ntohs(rep->format_rep_length), &errno, &errstr); if (ret != ntohs(rep->format_rep_length)) { @@ -723,13 +716,13 @@ get_format_from_master(format_server fs, IOFormatRep ioformat) server_fd = fs->proxy_context_to_master->server_fd; id_size = get[1] = ioformat->server_ID.length; - if ((ret = os_server_write_func(server_fd, &get[0], 2, &errno, &errstr)) != 2) { + if ((ret = ffs_server_write_func(server_fd, &get[0], 2, &errno, &errstr)) != 2) { close((int)(long)server_fd); fs->proxy_context_to_master->server_fd = (void*)-1; LOG(fs, "Write failed2.1, ret is %d\n", ret); return NULL; } - if (os_server_write_func(server_fd, ioformat->server_ID.value, id_size, &errno, &errstr) != id_size) { + if (ffs_server_write_func(server_fd, ioformat->server_ID.value, id_size, &errno, &errstr) != id_size) { close((int)(long)server_fd); fs->proxy_context_to_master->server_fd = (void*)-1; LOG(fs, "Write failed3\n"); @@ -799,12 +792,7 @@ get_format_from_master(format_server fs, IOFormatRep ioformat) static IOFormatRep -find_format(fs, fsc, ioformat, new_format_mode, requested_id_version) -format_server fs; -FSClient fsc; -IOFormatRep ioformat; -int new_format_mode; -int requested_id_version; +find_format(format_server fs, FSClient fsc, IOFormatRep ioformat, int new_format_mode, int requested_id_version) { format_list *list = fs->lists[0]; format_list *last = NULL, *new = NULL; @@ -947,7 +935,7 @@ FSClient_close(FSClient fsc) LOG(fs, "Doing Mutex unLock at Line %d ", __LINE__); pthread_mutex_unlock(&fs->lock); /* moved close outside of the mutex because sometimes it blocks */ - os_close_func((void *) (long) fd); + ffs_close_func((void *) (long) fd); if (fs->fork_threads) pthread_exit(NULL); } @@ -965,7 +953,7 @@ FSClient_force_close(FSClient fsc) shutdown(fd, SHUT_RDWR); // pthread_kill(fsc->handler_thread, 13); pthread_join(fsc->handler_thread, NULL); - os_close_func((void *) (long) fd); + ffs_close_func((void *) (long) fd); fs->portCount--; // fsc->fd = 0; } @@ -1011,16 +999,13 @@ get_internal_format_server_identifier(format_server fs) #define FILE_INT INT4 static int -put_serverAtomicInt(fd, file_int_ptr, fmc) -void *fd; -FILE_INT *file_int_ptr; -FMContext fmc; +put_serverAtomicInt(void *fd, FILE_INT *file_int_ptr, FMContext fmc) { #if SIZEOF_INT == 4 int tmp_value = *file_int_ptr; int junk_errno; char *junk_result_str; - if (os_server_write_func(fd, &tmp_value, 4, &junk_errno, &junk_result_str) != 4) { + if (ffs_server_write_func(fd, &tmp_value, 4, &junk_errno, &junk_result_str) != 4) { printf("SERVER WRITE FAILED, ERRNO = %d\n", junk_errno); return 0; } @@ -1031,16 +1016,13 @@ FMContext fmc; } static int -get_serverAtomicInt(fd, file_int_ptr, byte_reversal) -void *fd; -FILE_INT *file_int_ptr; -int byte_reversal; +get_serverAtomicInt(void *fd, FILE_INT *file_int_ptr, int byte_reversal) { #if SIZEOF_INT == 4 int tmp_value; int junk_errno; char *junk_result_str; - if (os_server_read_func(fd, &tmp_value, 4, &junk_errno, &junk_result_str) != 4) { + if (ffs_server_read_func(fd, &tmp_value, 4, &junk_errno, &junk_result_str) != 4) { printf("SERVER READ FAILED, ERRNO = %d\n", junk_errno); return 0; @@ -1059,10 +1041,7 @@ unix_timeout_read_func(void *conn, void *buffer, int length, int *errno_p, char **result_p); static int -get_serverTimeoutInt(fd, file_int_ptr, byte_reversal) -void *fd; -FILE_INT *file_int_ptr; -int byte_reversal; +get_serverTimeoutInt(void *fd, FILE_INT *file_int_ptr, int byte_reversal) { #if SIZEOF_INT == 4 int tmp_value; @@ -1080,8 +1059,7 @@ int byte_reversal; } static void -server_read_header(fsc) -FSClient fsc; +server_read_header(FSClient fsc) { FILE_INT magic; FILE_INT float_format; @@ -1164,9 +1142,7 @@ FSClient fsc; } static void -format_server_handle_data(fs, fsc) -format_server fs; -FSClient fsc; +format_server_handle_data(format_server fs, FSClient fsc) { char next_action; int input_bytes = 0; @@ -1250,12 +1226,12 @@ FSClient fsc; ret[0] = 'P'; } */ ret[1] = ioformat->server_ID.length; - if (os_server_write_func(fd, &ret[0], 2, NULL, NULL) != 2) { + if (ffs_server_write_func(fd, &ret[0], 2, NULL, NULL) != 2) { LOG(fs, "Close on atomic write fail"); FSClient_close(fsc); return; } - if (os_server_write_func(fd, ioformat->server_ID.value, + if (ffs_server_write_func(fd, ioformat->server_ID.value, ioformat->server_ID.length, NULL, NULL) != ioformat->server_ID.length) { LOG(fs, "Close on atomic write fail 2"); @@ -1401,7 +1377,7 @@ FSClient fsc; fsc->formats_fetched++; LOG(fs, "Doing Mutex unLock at Line %d ", __LINE__); pthread_mutex_unlock(&fs->lock); - ret = os_server_write_func(fd, &tmp, sizeof(tmp), + ret = ffs_server_write_func(fd, &tmp, sizeof(tmp), &errno, &errstr); if (ret != sizeof(tmp)) { LOG(fs, "Close on atomic read fail g3"); @@ -1411,7 +1387,7 @@ FSClient fsc; if ((ioformat != NULL) && (ioformat->server_format_rep != NULL)) { format_rep rep = ioformat->server_format_rep; - ret = os_server_write_func(fd, + ret = ffs_server_write_func(fd, (char *) rep + sizeof(rep->format_rep_length), ntohs(rep->format_rep_length) - sizeof(rep->format_rep_length), &errno, &errstr); @@ -1449,13 +1425,13 @@ FSClient fsc; tmp = htonl(out_count); LOG(fs, "Doing Mutex unLock at Line %d ", __LINE__); pthread_mutex_unlock(&fs->lock); - os_server_write_func(fd, &tmp, 4, &junk_errno, + ffs_server_write_func(fd, &tmp, 4, &junk_errno, &junk_str); for (i = 0; i < out_count; i++) { tmp = htonl(out_list[i].length); - os_server_write_func(fd, &tmp, 4, + ffs_server_write_func(fd, &tmp, 4, &junk_errno, &junk_str); - os_server_write_func(fd, out_list[i].value, + ffs_server_write_func(fd, out_list[i].value, out_list[i].length, &junk_errno, &junk_str); } @@ -1471,17 +1447,17 @@ FSClient fsc; int tmp; tmp = htonl(out_count); - os_server_write_func(fd, &tmp, 4, &junk_errno, + ffs_server_write_func(fd, &tmp, 4, &junk_errno, &junk_str); for (i = 0; i < out_count; i++) { char *time_str; - os_server_write_func(fd, &hostlist[i].ip_addr, 4, + ffs_server_write_func(fd, &hostlist[i].ip_addr, 4, &junk_errno, &junk_str); time_str = (char *) ctime(&hostlist[i].intro_time); tmp = htonl(strlen(time_str) + 1); - os_server_write_func(fd, &tmp, 4, &junk_errno, + ffs_server_write_func(fd, &tmp, 4, &junk_errno, &junk_str); - os_server_write_func(fd, time_str, strlen(time_str) + 1, + ffs_server_write_func(fd, time_str, strlen(time_str) + 1, &junk_errno, &junk_str); } } @@ -1556,7 +1532,7 @@ FSClient fsc; printf("ping from client\n"); } /* send it back */ - os_server_write_func(fd, &next_action, 1, &junk_errno, + ffs_server_write_func(fd, &next_action, 1, &junk_errno, &junk_str); break; case 'P': @@ -1564,7 +1540,7 @@ FSClient fsc; printf("ping/request for ID from client\n"); } /* send it back */ - os_server_write_func(fd, &fs->format_server_identifier, 4, &junk_errno, + ffs_server_write_func(fd, &fs->format_server_identifier, 4, &junk_errno, &junk_str); break; } @@ -1734,7 +1710,7 @@ format_server_create() if (fs == NULL) return NULL; -/* if (os_sockets_init_func != NULL) os_sockets_init_func();*/ +/* if (ffs_sockets_init_func != NULL) ffs_sockets_init_func();*/ my_pid = (int) getpid(); @@ -2023,9 +1999,7 @@ format_server_accept_conn_sock(format_server fs, void *conn_sock) } static time_t -get_time_for_host(ip_addr, hostname) -struct in_addr ip_addr; -char *hostname; +get_time_for_host(struct in_addr ip_addr, char *hostname) { int i; if (hostlist == NULL) { @@ -2053,9 +2027,7 @@ static char **postfix_list = NULL; #define GRACE_PERIOD_SEC 60 * 60 * 24 * 3 static void -out_domain_rejection(fd, fsc) -int fd; -FSClient fsc; +out_domain_rejection(int fd, FSClient fsc) { struct sockaddr sock_addr; int sock_len = sizeof(sock_addr); @@ -2293,10 +2265,7 @@ dump_stats_to_log(format_server server_fs) } static FMFormat -register_server_format(fs, iocontext, str_list) -format_server fs; -FMContext iocontext; -FMStructDescList str_list; +register_server_format(format_server fs, FMContext iocontext, FMStructDescList str_list) { FMFormat ioformat = register_data_format(iocontext, str_list); IOFormatRep iofr = malloc(sizeof(*iofr)); @@ -2503,18 +2472,18 @@ send_stats(FSClient fsc) } free(start); tmp = htonl(id_len); - os_server_write_func(fsc->fd, &tmp, 4, &junk_errno, + ffs_server_write_func(fsc->fd, &tmp, 4, &junk_errno, &junk_str); - os_server_write_func(fsc->fd, server_ID, id_len, + ffs_server_write_func(fsc->fd, server_ID, id_len, &junk_errno, &junk_str); tmp = htonl(rep_len); - os_server_write_func(fsc->fd, &tmp, 4, &junk_errno, + ffs_server_write_func(fsc->fd, &tmp, 4, &junk_errno, &junk_str); - os_server_write_func(fsc->fd, server_rep, rep_len, + ffs_server_write_func(fsc->fd, server_rep, rep_len, &junk_errno, &junk_str); tmp = htonl(stats_block_len); - os_server_write_func(fsc->fd, &tmp, 4, &junk_errno, + ffs_server_write_func(fsc->fd, &tmp, 4, &junk_errno, &junk_str); - os_server_write_func(fsc->fd, stats_block, stats_block_len, + ffs_server_write_func(fsc->fd, stats_block, stats_block_len, &junk_errno, &junk_str); } diff --git a/fm/server_acts.c b/fm/server_acts.c index 3a428d08da..3a5e16c2dc 100755 --- a/fm/server_acts.c +++ b/fm/server_acts.c @@ -26,8 +26,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#include -#include #ifdef HAVE_SOCKLIB_H #include "sockLib.h" #include "hostLib.h" @@ -39,6 +37,8 @@ #ifdef HAVE_SYS_UN_H #include #endif +#include +#include #include #include #include @@ -56,6 +56,7 @@ #include "assert.h" #include "fm.h" #include "fm_internal.h" +#include "io_interface.h" #else #include "config.h" @@ -96,6 +97,10 @@ typedef enum {Raw, Authenticated} Server_Protocol; #define CIPHER_BUF_SIZE 1024 +#ifdef _MSC_VER +#define strncasecmp _strnicmp +#define strcasecmp _stricmp +#endif static int fill_hostaddr(void *addr, char *hostname, Server_Protocol *protocol) @@ -160,11 +165,9 @@ extern int server_write_header(FMContext fmc, int enc_len, unsigned char *enc_buffer); extern int -establish_server_connection(iofile, action) -FMContext iofile; -action_t action; +establish_server_connection(FMContext iofile, action_t action) { - int sock; + SOCKET sock; int ret; Server_Protocol protocol = Raw; int conn_is_dead = 0; @@ -174,14 +177,7 @@ action_t action; #else struct socket *socket; #endif - - if (format_server_verbose == -1) { - if (getenv("FORMAT_SERVER_VERBOSE") == NULL) { - format_server_verbose = 0; - } else { - format_server_verbose = 1; - } - } + if (ffs_sockets_init_func) ffs_sockets_init_func(); if (iofile->server_fd != (void*)-1) { #ifndef MODULE @@ -198,12 +194,12 @@ action_t action; #endif timeout.tv_sec = 0; timeout.tv_usec = 0; - FD_SET( (int)(long)iofile->server_fd, &rd_set); + FD_SET( (int)(intptr_t)iofile->server_fd, &rd_set); ret = select(FD_SETSIZE, &rd_set, (fd_set*)NULL, (fd_set *) NULL, &timeout); if (ret == -1) { if (format_server_verbose) - printf("Dead connection, Select return is %d, server fd is %ld, errno is %d\n", ret, (long)iofile->server_fd, errno); + printf("Dead connection, Select return is %d, server fd is %p, errno is %d\n", ret, (void*)(intptr_t)iofile->server_fd, errno); conn_is_dead = 1; } #else @@ -323,9 +319,9 @@ action_t action; setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *) &delay_value, sizeof(delay_value)); delay_value = 1; - setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &delay_value, sizeof(delay_value)); + setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (const char *)& delay_value, sizeof(delay_value)); #endif - iofile->server_fd = (void*) (long) sock; + iofile->server_fd = (void*) (intptr_t) sock; if (protocol == Authenticated) { unsigned char outbuf[CIPHER_BUF_SIZE]; diff --git a/fm/tests/align_test.c b/fm/tests/align_test.c index a69bb05837..8fbd3114e8 100644 --- a/fm/tests/align_test.c +++ b/fm/tests/align_test.c @@ -135,9 +135,7 @@ do_test(FMStructDescList list) int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { if (argc > 1) { if (strcmp(argv[1], "-v") == 0) { diff --git a/fm/tests/compat_test.c b/fm/tests/compat_test.c index 757456dd05..0436aa80a9 100644 --- a/fm/tests/compat_test.c +++ b/fm/tests/compat_test.c @@ -135,11 +135,9 @@ do_test(FMStructDescList list) int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { - FMContext context = create_local_FMcontext(NULL); + FMContext context = create_local_FMcontext(); FMFormat ioformat1, ioformat2; FMStructDescRec str_list[5]; diff --git a/fm/tests/format_test.c b/fm/tests/format_test.c index 2ebb110af4..66fff8a917 100755 --- a/fm/tests/format_test.c +++ b/fm/tests/format_test.c @@ -3,22 +3,21 @@ #include #include "config.h" +#ifdef HAVE_UNISTD_H +#include +#endif #include #include "fm.h" #include "fm_internal.h" #ifdef HAVE_WINDOWS_H #include #define sleep(x) Sleep(1000*x) -#else -extern int sleep(); #endif #include "test_funcs.h" int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { int continuous_test = 0; @@ -53,7 +52,7 @@ char **argv; unsigned char id[] = {02, 00, 00, 37, 103, 189, 231, 165, 33, 254, 42, 32}; printf("Doing get test\n"); first_rec_ioformat = FMformat_from_ID(context, (char *) &id[0]); - printf("format is %lx\n", (long)first_rec_ioformat); + printf("format is %p\n", first_rec_ioformat); return 0; } if (XML_test) { @@ -75,7 +74,7 @@ char **argv; dump_FMFormat(first_rec_ioformat); } else if (!continuous_test && !restart_test) { FMContext context = create_FMcontext(); - FMContext local_context = create_local_FMcontext(NULL); + FMContext local_context = create_local_FMcontext(); FMFormat first_rec_ioformat; FMcontext_allow_self_formats(context); str_list[0].format_name = "first format"; @@ -84,7 +83,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("format is %lx\n", (long)first_rec_ioformat); + printf("format is %p\n", first_rec_ioformat); if (first_rec_ioformat != NULL) { int id_len, i; char *id =get_server_ID_FMformat(first_rec_ioformat, &id_len); @@ -104,7 +103,7 @@ char **argv; print_server_ID((unsigned char *)id); } } else if (restart_test) { - FMContext static_context = create_FMcontext(NULL); + FMContext static_context = create_FMcontext(); while (1) { if (format_server_restarted(static_context)) { printf("Format server was restarted\n"); @@ -112,9 +111,9 @@ char **argv; sleep(120); } } else { - FMContext static_context = create_FMcontext(NULL); + FMContext static_context = create_FMcontext(); while (1) { - FMContext context = create_FMcontext(NULL); + FMContext context = create_FMcontext(); FMFormat first_rec_ioformat; if (format_server_restarted(static_context)) { @@ -126,7 +125,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("first format is %lx\n", (long)first_rec_ioformat); + printf("first format is %p\n", first_rec_ioformat); sleep(10); @@ -139,7 +138,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("second format is %lx\n", (long)first_rec_ioformat); + printf("second format is %p\n", first_rec_ioformat); sleep(20); @@ -152,7 +151,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("third format is %lx\n", (long)first_rec_ioformat); + printf("third format is %p\n", first_rec_ioformat); sleep(30); @@ -165,7 +164,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("fourth format is %lx\n", (long)first_rec_ioformat); + printf("fourth format is %p\n", first_rec_ioformat); sleep(40); if (format_server_restarted(static_context)) { @@ -177,7 +176,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("embedded format is %lx\n", (long)first_rec_ioformat); + printf("embedded format is %p\n", first_rec_ioformat); sleep(50); @@ -194,7 +193,7 @@ char **argv; str_list[1].opt_info = NULL; str_list[2].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("fifth format is %lx\n", (long)first_rec_ioformat); + printf("fifth format is %p\n", first_rec_ioformat); sleep(60); @@ -207,7 +206,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("later format is %lx\n", (long)first_rec_ioformat); + printf("later format is %p\n", first_rec_ioformat); sleep(70); @@ -220,7 +219,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("later2 format is %lx\n", (long)first_rec_ioformat); + printf("later2 format is %p\n", first_rec_ioformat); sleep(80); @@ -237,7 +236,7 @@ char **argv; str_list[1].opt_info = NULL; str_list[2].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("nested format is %lx\n", (long)first_rec_ioformat); + printf("nested format is %p\n", first_rec_ioformat); sleep(90); @@ -254,7 +253,7 @@ char **argv; str_list[1].opt_info = NULL; str_list[2].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("sixth format is %lx\n", (long)first_rec_ioformat); + printf("sixth format is %p\n", first_rec_ioformat); sleep(100); @@ -262,7 +261,7 @@ char **argv; printf("Format server was restarted\n"); } first_rec_ioformat = register_data_format(context, str_list); - printf("eventvec format is %lx\n", (long)first_rec_ioformat); + printf("eventvec format is %p\n", first_rec_ioformat); sleep(110); @@ -279,7 +278,7 @@ char **argv; str_list[1].opt_info = NULL; str_list[2].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("ninth format is %lx\n", (long)first_rec_ioformat); + printf("ninth format is %p\n", first_rec_ioformat); sleep(120); @@ -292,7 +291,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("string array format is %lx\n", (long)first_rec_ioformat); + printf("string array format is %p\n", first_rec_ioformat); sleep(130); free_FMcontext(context); diff --git a/fm/tests/scale_test.c b/fm/tests/scale_test.c index 241ec00531..5e06f7f20b 100644 --- a/fm/tests/scale_test.c +++ b/fm/tests/scale_test.c @@ -5,7 +5,6 @@ #include "config.h" #include #include -#include #include "fm.h" #include "ffs.h" @@ -21,7 +20,7 @@ extern int sleep(); char *gen_name(int i) { char tmp_name[128]; - sprintf(tmp_name, "SST_Variable_FieldName that's really really long because I can't imagine why %d", i); + snprintf(tmp_name, sizeof(tmp_name), "SST_Variable_FieldName that's really really long because I can't imagine why %d", i); return strdup(tmp_name); } @@ -32,10 +31,13 @@ struct base_elem { int64_t *array2; }; +#ifdef _MSC_VER +// this is not important on windows +#define clock_gettime(x,y) +#endif + int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { FMStructDescRec str_list[5]; @@ -62,12 +64,12 @@ char **argv; list[cur_count+1].field_size = 8; list[cur_count+1].field_offset = (cur_count+1) * 8; list[cur_count+2].field_name = n3; - sprintf(tmp, "integer[%s]", n1); + snprintf(tmp, sizeof(tmp), "integer[%s]", n1); list[cur_count+2].field_type = strdup(tmp); list[cur_count+2].field_size = 8; list[cur_count+2].field_offset = (cur_count+2) * 8; list[cur_count+3].field_name = n4; - sprintf(tmp, "integer[%s]", n2); + snprintf(tmp, sizeof(tmp), "integer[%s]", n2); list[cur_count+3].field_type = strdup(tmp); list[cur_count+3].field_size = 8; list[cur_count+3].field_offset = (cur_count+3) * 8; diff --git a/fm/tests/self_format_test.c b/fm/tests/self_format_test.c index 3c9dc57a3a..ab031b1e94 100755 --- a/fm/tests/self_format_test.c +++ b/fm/tests/self_format_test.c @@ -9,16 +9,14 @@ #ifdef HAVE_WINDOWS_H #include #define sleep(x) Sleep(1000*x) -#else -extern int sleep(); #endif - +#ifdef HAVE_UNISTD_H +#include +#endif #include "test_funcs.h" int -main(argc, argv) -int argc; -char **argv; +main(int argc, char **argv) { FMContext context = create_local_FMcontext(); @@ -67,7 +65,7 @@ char **argv; first_rec_ioformat = register_data_format(context, str_list); ID = get_server_ID_FMformat (first_rec_ioformat, &id_length); print_server_ID((unsigned char *)ID); - printf("format is %lx\n", (long)first_rec_ioformat); + printf("format is %p\n", first_rec_ioformat); } else if (restart_test) { FMContext static_context = create_FMcontext(); while (1) { @@ -90,7 +88,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("first format is %lx\n", (long)first_rec_ioformat); + printf("first format is %p\n", first_rec_ioformat); sleep(10); @@ -103,7 +101,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("second format is %lx\n", (long)first_rec_ioformat); + printf("second format is %p\n", first_rec_ioformat); sleep(20); @@ -116,7 +114,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("third format is %lx\n", (long)first_rec_ioformat); + printf("third format is %p\n", first_rec_ioformat); sleep(30); @@ -129,7 +127,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("fourth format is %lx\n", (long)first_rec_ioformat); + printf("fourth format is %p\n", first_rec_ioformat); sleep(40); if (format_server_restarted(static_context)) { @@ -141,7 +139,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("embedded format is %lx\n", (long)first_rec_ioformat); + printf("embedded format is %p\n", first_rec_ioformat); sleep(50); @@ -158,7 +156,7 @@ char **argv; str_list[1].opt_info = NULL; str_list[2].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("fifth format is %lx\n", (long)first_rec_ioformat); + printf("fifth format is %p\n", first_rec_ioformat); sleep(60); @@ -171,7 +169,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("later format is %lx\n", (long)first_rec_ioformat); + printf("later format is %p\n", first_rec_ioformat); sleep(70); @@ -184,7 +182,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("later2 format is %lx\n", (long)first_rec_ioformat); + printf("later2 format is %p\n", first_rec_ioformat); sleep(80); @@ -201,7 +199,7 @@ char **argv; str_list[1].opt_info = NULL; str_list[2].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("nested format is %lx\n", (long)first_rec_ioformat); + printf("nested format is %p\n", first_rec_ioformat); sleep(90); @@ -218,7 +216,7 @@ char **argv; str_list[1].opt_info = NULL; str_list[2].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("sixth format is %lx\n", (long)first_rec_ioformat); + printf("sixth format is %p\n", first_rec_ioformat); sleep(100); @@ -226,7 +224,7 @@ char **argv; printf("Format server was restarted\n"); } first_rec_ioformat = register_data_format(context, str_list); - printf("eventvec format is %lx\n", (long)first_rec_ioformat); + printf("eventvec format is %p\n", first_rec_ioformat); sleep(110); @@ -243,7 +241,7 @@ char **argv; str_list[1].opt_info = NULL; str_list[2].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("ninth format is %lx\n", (long)first_rec_ioformat); + printf("ninth format is %p\n", first_rec_ioformat); sleep(120); @@ -256,7 +254,7 @@ char **argv; str_list[0].opt_info = NULL; str_list[1].format_name = NULL; first_rec_ioformat = register_data_format(context, str_list); - printf("string array format is %lx\n", (long)first_rec_ioformat); + printf("string array format is %p\n", first_rec_ioformat); sleep(130); free_FMcontext(context); diff --git a/fm/tests/test_funcs.c b/fm/tests/test_funcs.c index f44518ebe8..bce5c531e6 100755 --- a/fm/tests/test_funcs.c +++ b/fm/tests/test_funcs.c @@ -144,8 +144,7 @@ char *event_vec_xml = "\ \n"; int -first_rec_eq(r1, r2) -first_rec *r1, *r2; +first_rec_eq(first_rec *r1, first_rec *r2) { if (r1->integer_field != r2->integer_field) return 0; @@ -157,8 +156,7 @@ first_rec *r1, *r2; } int -second_rec_eq(r1, r2) -second_rec *r1, *r2; +second_rec_eq(second_rec *r1, second_rec *r2) { if (r1->integer_field != r2->integer_field) { printf("integer_field 1 is %d (0x%x), integer_field 2 is %d (0x%x)\n", @@ -201,8 +199,7 @@ second_rec *r1, *r2; } int -third_rec_eq(r1, r2) -third_rec *r1, *r2; +third_rec_eq(third_rec *r1, third_rec *r2) { if (r1->integer_field != r2->integer_field) { printf("integer field 1 is %d (0x%x), integer_field 2 is %d (0x%x)\n", @@ -276,8 +273,7 @@ third_rec *r1, *r2; #define ARRAY_SIZE 14 int -fourth_rec_eq(r1, r2) -fourth_rec *r1, *r2; +fourth_rec_eq(fourth_rec *r1, fourth_rec *r2) { int i, j; if (r1->ifield != r2->ifield) { @@ -302,8 +298,7 @@ fourth_rec *r1, *r2; } int -emb_rec_eq(r1, r2) -embedded_rec *r1, *r2; +emb_rec_eq(embedded_rec *r1, embedded_rec *r2) { if (r1->ifield != r2->ifield) { printf("ifield 1 is %d (%x), ifield 2 is %d (%x)\n", @@ -334,8 +329,7 @@ embedded_rec *r1, *r2; } int -fifth_rec_eq(r1, r2) -fifth_rec *r1, *r2; +fifth_rec_eq(fifth_rec *r1, fifth_rec *r2) { int i; for (i = 0; i < 4; i++) { @@ -348,8 +342,7 @@ fifth_rec *r1, *r2; } int -sixth_rec_eq(r1, r2) -sixth_rec *r1, *r2; +sixth_rec_eq(sixth_rec *r1, sixth_rec *r2) { int i; if (r1->icount != r2->icount) @@ -394,8 +387,7 @@ sixth_rec *r1, *r2; } int -nested_rec_eq(r1, r2) -nested_rec *r1, *r2; +nested_rec_eq(nested_rec *r1, nested_rec *r2) { if (r1->integer_field != r2->integer_field) { printf("nested, R1 integer = %d, R2 %d\n", r1->integer_field, @@ -425,8 +417,7 @@ nested_rec *r1, *r2; } int -later_rec_eq(r1, r2) -later_rec *r1, *r2; +later_rec_eq(later_rec *r1, later_rec *r2) { if (r1->integer_field != r2->integer_field) return 0; @@ -444,8 +435,7 @@ later_rec *r1, *r2; } int -ninth_rec_eq(r1, r2) -ninth_rec *r1, *r2; +ninth_rec_eq(ninth_rec *r1, ninth_rec *r2) { int i; if (r1->vec_length != r2->vec_length) @@ -464,8 +454,7 @@ ninth_rec *r1, *r2; } int -string_array_eq(r1, r2) -string_array_rec *r1, *r2; +string_array_eq(string_array_rec *r1, string_array_rec *r2) { int i; if (r1->array_len != r2->array_len) @@ -1058,9 +1047,9 @@ init_written_data() k = 0; for (i = 1; i < 20; i += 5) { - rec6_array[k].string = malloc(10); - memset(rec6_array[k].string, 0, 10); - sprintf(rec6_array[k].string, "variant%d", i); + rec6_array[k].string = malloc(20); + memset(rec6_array[k].string, 0, 20); + snprintf(rec6_array[k].string, 20, "variant%d", i); rec6_array[k].icount = 2 * i; rec6_array[k].var_int_array = malloc(sizeof(((sixth_rec_ptr) 0)->var_int_array[0]) * rec6_array[k].icount); rec6_array[k].var_double_array = malloc(sizeof(double) * rec6_array[k].icount); @@ -1071,9 +1060,9 @@ init_written_data() rec6_array[k].var_string_array[j].integer_field = 345 * j; rec6_array[k].var_string_array[j].short_field = j; rec6_array[k].var_string_array[j].long_field = 785 * j; - rec6_array[k].var_string_array[j].string = malloc(15); - memset(rec6_array[k].var_string_array[j].string, 0, 15); - sprintf(rec6_array[k].var_string_array[j].string, + rec6_array[k].var_string_array[j].string = malloc(25); + memset(rec6_array[k].var_string_array[j].string, 0, 25); + snprintf(rec6_array[k].var_string_array[j].string, 25, "substring%d", j); rec6_array[k].var_string_array[j].double_field = 3.1415 * j; rec6_array[k].var_string_array[j].char_field = 'a' + 2 * j; diff --git a/fm/tests/test_funcs.h b/fm/tests/test_funcs.h index bf7fea40fc..d0eecba4f5 100755 --- a/fm/tests/test_funcs.h +++ b/fm/tests/test_funcs.h @@ -332,3 +332,7 @@ extern char *nested_xml; extern char *event_xml; extern char *event_vec_xml; extern char *multi_array_xml; +#if defined(_MSC_VER) +#define strdup _strdup +#define snprintf sprintf_s +#endif diff --git a/fm/unix_io.c b/fm/unix_io.c index ffbb854251..47c6eacbbf 100755 --- a/fm/unix_io.c +++ b/fm/unix_io.c @@ -34,12 +34,7 @@ extern int select(int width, fd_set *readfds, fd_set *writefds, #endif static int -unix_read_func(conn, buffer, length, errno_p, result_p) -void *conn; -void *buffer; -int length; -int *errno_p; -char **result_p; +unix_read_func(void *conn, void *buffer, size_t length, int *errno_p, char **result_p) { int left = length; int iget; @@ -89,12 +84,7 @@ char **result_p; } int -unix_timeout_read_func(conn, buffer, length, errno_p, result_p) -void *conn; -void *buffer; -int length; -int *errno_p; -char **result_p; +unix_timeout_read_func(void *conn, void *buffer, size_t length, int *errno_p, char **result_p) { int left = length; int count = 2; @@ -172,12 +162,7 @@ char **result_p; } static int -unix_write_func(conn, buffer, length, errno_p, result_p) -void *conn; -void *buffer; -int length; -int *errno_p; -char **result_p; +unix_write_func(void *conn, void *buffer, size_t length, int *errno_p, char **result_p) { int left = length; int iget = 0; @@ -204,23 +189,19 @@ char **result_p; } static int -unix_close_func(conn) -void *conn; +unix_close_func(void *conn) { return close((int) (long) conn); } static void * -unix_file_open_func(path, flag_str, input, output) -const char *path; -const char *flag_str; -int *input; -int *output; +unix_file_open_func(const char *path, const char *flag_str, int *input, int *output) { int flags; int file_id; long tmp_flags = (long)flag_str; - *input = *output = 0; + if (input) *input = 0; + if (output) *output = 0; tmp_flags &= ~(O_TRUNC); tmp_flags &= ~(O_CREAT); @@ -228,15 +209,19 @@ int *output; (O_WRONLY == tmp_flags)) { /* must be old style call */ flags = (long)flag_str; - *input = (O_RDONLY == (long)flag_str); - *output = (O_WRONLY & (long)flag_str); + if (input) *input = (O_RDONLY == (long)flag_str); + if (output) *output = (O_WRONLY & (long)flag_str); } else { if (strcmp(flag_str, "r") == 0) { flags = O_RDONLY; - *input = 1; + if (input) *input = 1; } else if (strcmp(flag_str, "w") == 0) { flags = O_WRONLY | O_CREAT | O_TRUNC; - *output = 1; + if (output) *output = 1; + } else if (strcmp(flag_str, "a") == 0) { + flags = O_RDWR; + if (output) *output = 1; + if (input) *input = 1; } else { fprintf(stderr, "Open flags value not understood for file \"%s\"\n", path); @@ -252,8 +237,98 @@ int *output; } static int -unix_poll_func(conn) -void *conn; +unix_writev_func(void *conn, struct iovec *iov, int iovcnt, int *errno_p, char **result_p) +{ + int fd = (int) (long) conn; + int left = 0; + int iget = 0; + int iovleft, i; + + iovleft = iovcnt; + + /* sum lengths */ + for (i=0; i 0) { + iget = writev(fd, (struct iovec *) &iov[iovcnt - iovleft], iovleft); + if (iget == -1) { + if ((errno != EWOULDBLOCK) && (errno != EAGAIN)) { + /* serious error */ + if (errno_p) *errno_p = errno; + return (iovcnt - iovleft); + } else { + iget = 0; + } + } + if (iget == left) + return iovcnt; + + left -= iget; + while (iget > 0) { + iget -= iov[iovcnt - iovleft].iov_len; + iovleft--; + } + + if (iget < 0) { + /* + * Only part of the last block was written. Modify IO + * vector to indicate the remaining block to be written. + */ + /* restore iovleft and iget to cover remaining block*/ + iovleft++; + iget += iov[iovcnt - iovleft].iov_len; + + /* adjust count down and base up by number of bytes written */ + iov[iovcnt-iovleft].iov_len -= iget; + iov[iovcnt-iovleft].iov_base = + (char*)(iov[iovcnt-iovleft].iov_base) + iget; + } + } + return iovcnt; +} + +static int +unix_readv_func(void *conn, struct iovec *iov, int icount, int *errno_p, char **result_p) +{ + int orig_icount = icount; + int fd = (int) (long)conn; + int iget; + + while (icount > 0) { + iget = readv(fd, (struct iovec *) iov, icount); + if (iget == 0) { + if (result_p) *result_p = "End of file"; + if (errno_p) *errno_p = 0; + return 0; /* end of file */ + } else if (iget == -1) { + if (errno_p) *errno_p = errno; + if ((errno != EWOULDBLOCK) && + (errno != EAGAIN) && + (errno != EINTR)) { + /* serious error */ + return -1; + } else { + if (errno_p) *errno_p = 0; + iget = 0; + } + } + while (iget > 0) { + if (iov[0].iov_len <= iget) { + iget -= iov[0].iov_len; + iov++; + icount--; + } else { + iov[0].iov_len -= iget; + iov[0].iov_base = ((char*)iov[0].iov_base) + iget; + iget = 0; + } + } + } + return orig_icount; +} + +static int +unix_poll_func(void *conn) { int fd = (int) (long) conn; struct timeval time; @@ -273,19 +348,28 @@ void *conn; return (ret_val > 0); } -IOinterface_func os_file_read_func = unix_read_func; -IOinterface_func os_file_write_func = unix_write_func; +static int +unix_file_lseek_func (void *file, size_t pos, int origin) +{ + return lseek((intptr_t)file, (long)pos, origin); +} + +IOinterface_func ffs_file_read_func = unix_read_func; +IOinterface_func ffs_file_write_func = unix_write_func; +IOinterface_funcv ffs_file_readv_func = unix_readv_func; +IOinterface_funcv ffs_file_writev_func = unix_writev_func; +IOinterface_lseek ffs_file_lseek_func = (IOinterface_lseek)unix_file_lseek_func; -IOinterface_func os_read_func = unix_read_func; -IOinterface_func os_write_func = unix_write_func; +IOinterface_func ffs_read_func = unix_read_func; +IOinterface_func ffs_write_func = unix_write_func; #ifndef IOV_MAX #define IOV_MAX 16 #endif -int os_max_iov = IOV_MAX; -IOinterface_close os_close_func = unix_close_func; -IOinterface_poll os_poll_func = unix_poll_func; -IOinterface_open os_file_open_func = unix_file_open_func; -IOinterface_func os_server_read_func = unix_read_func; -IOinterface_func os_server_write_func = unix_write_func; -IOinterface_init os_sockets_init_func = NULL; +int ffs_max_iov = IOV_MAX; +IOinterface_close ffs_close_func = unix_close_func; +IOinterface_poll ffs_poll_func = unix_poll_func; +IOinterface_open ffs_file_open_func = unix_file_open_func; +IOinterface_func ffs_server_read_func = unix_read_func; +IOinterface_func ffs_server_write_func = unix_write_func; +IOinterface_init ffs_sockets_init_func = NULL; diff --git a/fm/xml.c b/fm/xml.c index e6a71f3ff3..8a7d3927d7 100755 --- a/fm/xml.c +++ b/fm/xml.c @@ -53,7 +53,7 @@ generic_field_to_XML(FMFormat format, int field, static int is_tag(char *tag, char *xml_stream) { - int len = strlen(tag); + int len = (int) strlen(tag); if (strncmp(xml_stream, tag, len) != 0) return 0; if (isalnum((int)xml_stream[len])) return 0; /* not end of stream tag */ if (xml_stream[len] == '_') return 0; @@ -92,11 +92,11 @@ expand_dstring(ffs_dstring ds, int min) static void dcatstr(ffs_dstring ds, char *str) { - int len = strlen(str); + int len = (int) strlen(str); if (ds->length + len + 1 > ds->max_alloc) { expand_dstring(ds, len + 1); } - strcat(&ds->string[ds->length], str); + strncat(&ds->string[ds->length], str, ds->max_alloc); ds->length += len; } @@ -120,11 +120,7 @@ record_to_XML_string(FMFormat format, void *data, int encoded) } static ffs_dstring -raw_to_XML_string(c, format, data, encoded) -FMContext c; -FMFormat format; -void *data; -int encoded; +raw_to_XML_string(FMContext c, FMFormat format, void *data, int encoded) { int index; ffs_dstring ds; @@ -146,10 +142,7 @@ int encoded; } extern void -dump_raw_IOrecord_as_XML(c, format, data) -FMContext c; -FMFormat format; -void *data; +dump_raw_IOrecord_as_XML(FMContext c, FMFormat format, void *data) { ffs_dstring dstr = raw_to_XML_string(c, format, data, 1); printf("%s", dstr->string); @@ -233,9 +226,9 @@ internal_record_to_XML_string(FMFormat format, void *data, void *string_base, ff case integer_type: { char tmp[64]; - long l; + ssize_t l; l = get_FMlong(field_ptr, base); - sprintf(tmp, "%ld", l); + snprintf(tmp, sizeof(tmp), "%zd", l); dcatstr(ds, tmp); break; } @@ -243,15 +236,15 @@ internal_record_to_XML_string(FMFormat format, void *data, void *string_base, ff case enumeration_type: { char tmp[64]; - unsigned long l; + size_t l; l = get_FMulong(field_ptr, base); - sprintf(tmp, "%lu", l); + snprintf(&tmp[0], sizeof(tmp), "%zu", l); dcatstr(ds, tmp); break; } case boolean_type: { - unsigned long l; + size_t l; l = get_FMulong(field_ptr, base); if (l) dcatstr(ds, "true"); @@ -264,7 +257,7 @@ internal_record_to_XML_string(FMFormat format, void *data, void *string_base, ff char tmp[64]; double d; d = get_FMdouble(field_ptr, base); - sprintf(tmp, "%g", d); + snprintf(tmp, sizeof(tmp), "%g", d); dcatstr(ds, tmp); break; } @@ -286,7 +279,7 @@ internal_record_to_XML_string(FMFormat format, void *data, void *string_base, ff case unknown_type: { int field = info[i].field_num; - int offset = field_ptr->offset; + size_t offset = field_ptr->offset; FMFormat sub = format->field_subformats[field]; if (sub != NULL) { internal_record_to_XML_string(sub, (char*)base+offset, @@ -354,7 +347,7 @@ get_field_num(int* field_num_ptr, FMFormat format, char *left, char *right) } extern void * -get_optinfo_FMFormat(FMFormat format, int info_type, int *len_p) +get_optinfo_FMFormat(FMFormat format, int info_type, size_t *len_p) { int i = 0; if (format->opt_info == NULL) return NULL; @@ -373,27 +366,27 @@ extern FMfloat_format fm_my_float_format; static xml_output_info build_XML_output_info(FMFormat format) { - int i = 0, last_mark; + ssize_t i = 0, last_mark; char *XML_opt_data = NULL; - int XML_data_len = 0; + size_t XML_data_len = 0; xml_output_info info = NULL; - int info_count = 0; + size_t info_count = 0; XML_opt_data = get_optinfo_FMFormat(format, 0x584D4C20, &XML_data_len); if (XML_opt_data == NULL) return NULL; last_mark = 0; i = -1; - while (++i < XML_data_len) { + while (++i < (intptr_t) XML_data_len) { if (XML_opt_data[i] != '<') { continue; } if (is_tag("/FFS:array", &XML_opt_data[i+1])) { /* array terminatfmn */ - int post_len = i - last_mark + 1; + ssize_t post_len = i - last_mark + 1; info[info_count].element_poststring = malloc(post_len); - strncpy(info[info_count].element_poststring, - &XML_opt_data[last_mark], post_len -1); + strncpy(info[info_count].element_poststring, + &XML_opt_data[last_mark], post_len - 1); info[info_count].element_poststring[post_len -1] = 0; info_count++; i += 13; @@ -401,7 +394,7 @@ build_XML_output_info(FMFormat format) continue; } if (is_tag("FFS:data", &XML_opt_data[i+1])) { - int pre_len = i - last_mark; + size_t pre_len = i - last_mark; FMdata_type data_type; int field_num; long junk; @@ -446,7 +439,7 @@ build_XML_output_info(FMFormat format) } if (is_tag("FFS:array", &XML_opt_data[i+1])) { /* array terminatfmn */ - int pre_len = i - last_mark; + size_t pre_len = i - last_mark; char *right_end = strchr(&XML_opt_data[i+10], '>'); char *prestring = malloc(pre_len + 1); @@ -466,7 +459,7 @@ build_XML_output_info(FMFormat format) } if (is_tag("FFS:array_data_mark", &XML_opt_data[i+1])) { /* array terminatfmn */ - int pre_len = i - last_mark; + size_t pre_len = i - last_mark; int field_num; char *right_end = strchr(&XML_opt_data[i+9], '>'); char *prestring = malloc(pre_len + 1); @@ -501,7 +494,7 @@ build_XML_output_info(FMFormat format) } } if (info_count != 0) { - int post_len = XML_data_len - last_mark; + size_t post_len = XML_data_len - last_mark; char *poststring = malloc(post_len + 1); strncpy(poststring, &XML_opt_data[last_mark], post_len); poststring[post_len] = 0; @@ -525,7 +518,7 @@ build_XML_output_info(FMFormat format) static int get_int_attr(int *int_ptr, char *name, char *start, char *end) { - int name_len = strlen(name); + int name_len = (int)strlen(name); start -= 1; while(++start < (end - name_len)) { if (*start == *name) { @@ -552,7 +545,7 @@ get_int_attr(int *int_ptr, char *name, char *start, char *end) static int get_str_attr(char **str_ptr, char *name, char *start, char *end) { - int name_len = strlen(name); + int name_len = (int)strlen(name); start -= 1; while(++start < (end - name_len)) { if (*start == *name) { @@ -608,14 +601,8 @@ FMhas_XML_info(FMFormat format) } extern void -dump_FMfield_as_XML(c, format, field, data, string_base, encode, verbose) -FMContext c; -FMFormat format; -int field; -void *data; -void *string_base; -int encode; -int verbose; +dump_FMfield_as_XML(FMContext c, FMFormat format, int field, void *data, + void *string_base, int encode, int verbose) { ffs_dstring ds = new_dstring(); generic_field_to_XML(format, field, data, string_base, encode, @@ -626,18 +613,9 @@ int verbose; } extern int -add_single_value_as_XML(field_type, field_size, field_offset, - data, string_base, byte_reversal, float_format, - encode, ds) -const char *field_type; -int field_size; -int field_offset; -void *data; -void *string_base; -int byte_reversal; -int float_format; -int encode; -ffs_dstring ds; +add_single_value_as_XML(const char *field_type, int field_size, int field_offset, void *data, + void *string_base, int byte_reversal, int float_format, int encode, + ffs_dstring ds) { FMgetFieldStruct descr; /* OK */ char str[64]; @@ -651,72 +629,72 @@ ffs_dstring ds; str[0] = 0; if (descr.data_type == integer_type) { if (field_size <= sizeof(long)) { - long tmp = get_FMlong(&descr, data); - sprintf(str, "%ld", tmp); + size_t tmp = get_FMlong(&descr, data); + snprintf(str, sizeof(str), "%zd", tmp); } else if (field_size == 2 * sizeof(long) && field_size == 8) { unsigned long low_long; long high_long; get_FMlong8(&descr, data, &low_long, &high_long); if (high_long == 0) { - sprintf(str, "%ld ", low_long); + snprintf(str, sizeof(str), "%ld ", low_long); } else { - sprintf(str, "0x%lx%08lx ", high_long, low_long); + snprintf(str, sizeof(str), "0x%lx%08lx ", high_long, low_long); } } else if (field_size > sizeof(long)) { - sprintf(str, ""); + snprintf(str, sizeof(str), ""); } else { - sprintf(str, "", field_size); + snprintf(str, sizeof(str), "", field_size); } } else if (descr.data_type == unsigned_type) { if (field_size <= sizeof(unsigned long)) { - unsigned long tmp = get_FMulong(&descr, data); - sprintf(str, "%lu ", tmp); + size_t tmp = get_FMulong(&descr, data); + snprintf(str, sizeof(str), "%zu ", tmp); } else if (field_size == 2 * sizeof(long) && field_size == 8) { unsigned long low_long, high_long; get_FMulong8(&descr, data, &low_long, &high_long); if (high_long == 0) { - sprintf(str, "%lu ", low_long); + snprintf(str, sizeof(str), "%lu ", low_long); } else { - sprintf(str, "0x%lx%08lx ", high_long, low_long); + snprintf(str, sizeof(str), "0x%lx%08lx ", high_long, low_long); } } else if (field_size > sizeof(long)) { - sprintf(str, ""); + snprintf(str, sizeof(str), ""); } else { - sprintf(str, "", field_size); + snprintf(str, sizeof(str), "", field_size); } } else if (descr.data_type == enumeration_type) { - sprintf(str, "%u ", *(int *) ((char *) data + field_offset)); + snprintf(str, sizeof(str), "%u ", *(int *) ((char *) data + field_offset)); } else if (descr.data_type == boolean_type) { if (*(int *) ((char *) data + field_offset) == 0) { - strcpy(str, "false "); + strncpy(str, "false ", sizeof(str)); } else { - strcpy(str, "true "); + strncpy(str, "true ", sizeof(str)); } } else if (descr.data_type == float_type) { if (field_size == sizeof(float)) { float tmp = get_FMfloat(&descr, data); - sprintf(str, "%g ", tmp); + snprintf(str, sizeof(str), "%g ", tmp); } else if (field_size == sizeof(double)) { double tmp = get_FMdouble(&descr, data); - sprintf(str, "%g ", tmp); + snprintf(str, sizeof(str), "%g ", tmp); #if SIZEOF_LONG_DOUBLE != 0 && SIZEOF_LONG_DOUBLE != SIZEOF_DOUBLE } else if (field_size == sizeof(long double)) { long double tmp; memcpy(&tmp, (float *) ((char *) data + field_offset), sizeof(double)); - sprintf(str, "%Lg ", tmp); + snprintf(str, sizeof(str), "%Lg ", tmp); #endif } else { if (field_size < sizeof(float)) { - sprintf(str, ""); + snprintf(str, sizeof(str), ""); } else if (field_size > sizeof(double)) { - sprintf(str, ""); + snprintf(str, sizeof(str), ""); } else { - sprintf(str, "", field_size); + snprintf(str, sizeof(str), "", field_size); } } } else if (descr.data_type == char_type) { - sprintf(str, "%c ", *(char *) ((char *) data + field_offset)); + snprintf(str, sizeof(str), "%c ", *(char *) ((char *) data + field_offset)); } else if (descr.data_type == string_type) { char *tmp_str = (char *) get_FMaddr(&descr, data, string_base, encode); if (tmp_str != 0) { @@ -731,21 +709,9 @@ ffs_dstring ds; } static void -add_value_as_XML(field_type, field_size, field_offset, format, field, data, - string_base, byte_reversal, float_format, encode, - in_array, ds) -const char *field_type; -int field_size; -int field_offset; -FMFormat format; -int field; -void *data; -void *string_base; -int byte_reversal; -int float_format; -int encode; -int in_array; -ffs_dstring ds; +add_value_as_XML(const char *field_type, int field_size, int field_offset, FMFormat format, int field, + void *data, void *string_base, int byte_reversal, int float_format, int encode, + int in_array, ffs_dstring ds) { if (add_single_value_as_XML(field_type, field_size, field_offset, data, string_base, byte_reversal, @@ -780,13 +746,8 @@ ffs_dstring ds; } static void -generic_field_to_XML(format, field, data, string_base, encode, ds) -FMFormat format; -int field; -void *data; -void *string_base; -int encode; -ffs_dstring ds; +generic_field_to_XML(FMFormat format, int field, void *data, void *string_base, + int encode, ffs_dstring ds) { FMFieldList fmfield = &format->field_list[field]; FMVarInfoList iovar = &format->var_list[field]; @@ -814,7 +775,7 @@ ffs_dstring ds; int offset = fmfield->field_offset; dcatstr(ds, "\n"); *left_paren = 0; - strcpy(sub_type, field_type); + strncpy(sub_type, field_type, sizeof(sub_type)); *left_paren = '['; dimension = strtol(left_paren + 1, NULL, 10); @@ -826,7 +787,7 @@ ffs_dstring ds; return; } else { FMgetFieldStruct descr; /* OK */ - long tmp_offset; + size_t tmp_offset; dimension = FMget_array_element_count(format, iovar, data, encode); @@ -862,7 +823,7 @@ ffs_dstring ds; int sub_field_size, offset = fmfield->field_offset; dcatstr(ds, "\n"); *left_paren = 0; - strcpy(sub_type, field_type); + strncpy(sub_type, field_type, sizeof(sub_type)); dimension1 = strtol(left_paren + 1, &temp_ptr, 10); dimension2 = strtol(temp_ptr + 2, &temp_ptr, 10); diff --git a/version.c b/version.c index 085efd2ad8..8d7e3ee75f 100755 --- a/version.c +++ b/version.c @@ -1,6 +1,6 @@ #include -static char *FFS_version = "FFS Version 1.4.0 - Sun Dec 24 07:57:49 EST 2017\n"; +static char *FFS_version = "FFS Version 3.0.0 - Sun May 14 17:04:30 EDT 2023\n"; void FFSprint_version() From 20afb0eebfb40c571a36808333276114e97cf61c Mon Sep 17 00:00:00 2001 From: dill Upstream Date: Fri, 9 Jun 2023 14:20:14 -0400 Subject: [PATCH 5/7] dill 2023-06-09 (6c94efb3) Code extracted from: https://github.com/GTkorvo/dill.git at commit 6c94efb329e239d654b69d6640c47c0b9bb778c5 (master). Upstream Shortlog ----------------- --- CMakeLists.txt | 4 +- base.ops | 8 +- dill_cplus.c | 42 +- dill_internal.h | 291 +- dill_pkg.c | 110 +- dill_util.c | 1594 +++++----- tests/CMakeLists.txt | 9 +- tests/call-gen | 2 +- tests/stest.c | 4 + tests/test-gen | 12 +- virtual.c | 6691 +++++++++++++++++++++-------------------- virtual.h | 59 +- virtual.ops | 45 +- vm.c | 1039 +++---- vtests/basic_call.c | 2 +- vtests/general.ops | 36 +- vtests/opt.c | 8 +- vtests/t1.c | 4 +- x86_64.c | 3859 +++++++++++++----------- x86_64.h | 551 ++-- x86_64_disassembler.c | 1482 ++++----- x86_64_rt.c | 73 +- 22 files changed, 8419 insertions(+), 7506 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 59673d03de..bd86a32d99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.0) # The directory label is used for CDash to treat DILL as a subproject of GTKorvo set(CMAKE_DIRECTORY_LABELS DILL) -project(DILL VERSION 2.4.1 LANGUAGES C CXX) +project(DILL VERSION 3.0.0 LANGUAGES C CXX) # Some boilerplate to setup nice output directories include(GNUInstallDirs) @@ -38,7 +38,7 @@ endif() if(NOT DEFINED DILL_HEADER_COMPONENT) set(DILL_HEADER_COMPONENT dev) endif() - +add_definitions(-DDILL_SRC) if(WIN32) # Automagic to do the DLL / LIB song and dance set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) diff --git a/base.ops b/base.ops index a31e033429..cd7e3bf3c0 100755 --- a/base.ops +++ b/base.ops @@ -64,7 +64,11 @@ print HOUT "#define dill_jpi(s, dest_imm) (s->j->jpi)(s, dest_imm)\n"; print HOUT "#define dill_jalp(s, return_addr_reg, target) (s->j->jal)(s, return_addr_reg, target)\n"; print HOUT "#define dill_special(s, type, param) if (s->j->special) (s->j->special)(s, type, param)\n"; - +print HOUT "#if defined(_MSC_VER) && !defined(DILL_SRC)\n"; +print HOUT "#define DILL_DECLSPEC __declspec(dllimport)\n"; +print HOUT "#else\n"; +print HOUT "#define DILL_DECLSPEC\n"; +print HOUT "#endif\n"; print COUT "\n/* This file is generated from base.ops. Do not edit directly. */\n\n"; print COUT "#include \"dill.h\"\n"; print COUT "\nchar *arith3_name[] = \{".substr($enum_a3,2). "\};\n"; @@ -72,7 +76,7 @@ print COUT "\nchar *arith2_name[] = \{".substr($enum_a2,2). "\};\n"; foreach $key (sort keys %poly_array) { $poly_array{$key} .= " "; print COUT "int dill_${key}_poly_map[] = {\n"; - print HOUT "extern int dill_${key}_poly_map[];\n"; + print HOUT "extern DILL_DECLSPEC int dill_${key}_poly_map[];\n"; print HOUT "#define dill_P$key(s, typ, dest, src1, src2) (s->j->jmp_a3)[dill_${key}_poly_map[typ]](s, s->j->a3_data[dill_${key}_poly_map[typ]].data1, s->j->a3_data[dill_${key}_poly_map[typ]].data2, dest, src1, src2)\n"; foreach (split(' ', "c uc s us i u l ul p f d v b")) { $typ = $_; diff --git a/dill_cplus.c b/dill_cplus.c index 8ae7ae59d8..ef893c03cb 100644 --- a/dill_cplus.c +++ b/dill_cplus.c @@ -1,43 +1,43 @@ -#include "config.h" #include +#include "config.h" typedef struct mp { union { - void *call_ptr; - long vtindex; + void* call_ptr; + long vtindex; } u; - int delta; /* offset from base, used with multiple inheritance */ - int vflag; /* used on archs where call_ptr might be legitmately odd */ -} *method_pointer; + int delta; /* offset from base, used with multiple inheritance */ + int vflag; /* used on archs where call_ptr might be legitmately odd */ +} * method_pointer; -extern -void *get_this_ptr( method_pointer m, void *object_ptr) +extern void* +get_this_ptr(method_pointer m, void* object_ptr) { - void *th; - th = ((char *)object_ptr) + (m->delta / 2); + void* th; + th = ((char*)object_ptr) + (m->delta / 2); return th; } -extern -void *get_xfer_ptr( method_pointer m, void *object_ptr) +extern void* +get_xfer_ptr(method_pointer m, void* object_ptr) { - void *cptr; + void* cptr; cptr = m->u.call_ptr; #if defined(NOTDEF) - if (m->vflag != 0) { /* vflag indicates virtual on some archs*/ + if (m->vflag != 0) { /* vflag indicates virtual on some archs*/ #elif defined(HOST_ARM6) || defined(HOST_ARM7) - if ((m->delta & 0x1) == 1) { /* odd delta indicates virtual on some archs*/ + if ((m->delta & 0x1) == 1) { /* odd delta indicates virtual on some archs*/ #else - if ((m->u.vtindex & 0x1) == 1) { /* METHOD_PTR IS ODD - virtual */ + if ((m->u.vtindex & 0x1) == 1) { /* METHOD_PTR IS ODD - virtual */ #endif - int vtableindex = m->u.vtindex & -4; - void **vtable = *((void***)object_ptr); + int vtableindex = m->u.vtindex & -4; + void** vtable = *((void***)object_ptr); - vtable = (void **)(((char*)vtable) + vtableindex); + vtable = (void**)(((char*)vtable) + vtableindex); #ifdef HOST_IA64 - cptr = vtable; + cptr = vtable; #else - cptr = *vtable; + cptr = *vtable; #endif } return cptr; diff --git a/dill_internal.h b/dill_internal.h index effb408911..ed5670f7fb 100644 --- a/dill_internal.h +++ b/dill_internal.h @@ -1,18 +1,32 @@ -extern void extend_dill_stream(dill_stream s); -extern void dump_cur_dill_insn(dill_stream s); -extern jmp_table alloc_dill_jump_table(void); +#define malloc(size) dill_malloc(size) +#define realloc(ptr, size) dill_realloc(ptr, size) + +#include +#include + +extern void* +dill_malloc(size_t size); +extern void* +dill_realloc(void* ptr, size_t size); + +extern void +extend_dill_stream(dill_stream s); +extern void +dump_cur_dill_insn(dill_stream s); +extern jmp_table +alloc_dill_jump_table(void); #define INIT_CODE_SIZE 64 -typedef struct arg_info { +typedef struct arg_info { char type; - char is_register; /* true if parameter is in register */ - char is_immediate; /* true if actual is an immediate */ - int in_reg; /* callee register it's in */ - int out_reg; /* caller register it's in */ - int offset; /* otherwise at this offset from v_pp */ + char is_register; /* true if parameter is in register */ + char is_immediate; /* true if actual is an immediate */ + int in_reg; /* callee register it's in */ + int out_reg; /* caller register it's in */ + int offset; /* otherwise at this offset from v_pp */ int used; -} *arg_info_list; +} * arg_info_list; typedef struct reg_set { long init_avail[1]; @@ -28,42 +42,41 @@ struct branch_location { }; struct data_mark { - void **addr; + void** addr; int label; }; struct branch_table { int next_label; int max_alloc; - int *label_locs; - char **label_name; + int* label_locs; + char** label_name; int branch_count; int branch_alloc; - struct branch_location *branch_locs; + struct branch_location* branch_locs; int data_segment_size; - char *data_segment; + char* data_segment; }; -typedef struct branch_table *branch_t; - +typedef struct branch_table* branch_t; struct call_location { int loc; - void *xfer_addr; - const char *xfer_name; - void *mach_info; + void* xfer_addr; + const char* xfer_name; + void* mach_info; }; typedef struct call_table { int call_alloc; int call_count; - struct call_location *call_locs; + struct call_location* call_locs; } call_t; typedef struct ret_table { int ret_alloc; int ret_count; - int *ret_locs; + int* ret_locs; } ret_t; typedef void (*mach_reset_func)(dill_stream s); @@ -74,8 +87,8 @@ typedef struct vreg_info { int offset; int need_assign; struct { - short use_count; - short def_count; + short use_count; + short def_count; } use_info; int assign_loc; @@ -93,17 +106,17 @@ typedef struct preg_info { typedef struct saved { jmp_table mach_jump; mach_reset_func mach_reset; - void *mach_info; - char *code_base; - char *cur_ip; - char *code_limit; + void* mach_info; + char* code_base; + char* cur_ip; + char* code_limit; } saved_insn_info; struct dill_private_ctx { - char *code_base; - char *cur_ip; - char *code_limit; - void *fp; + char* code_base; + char* cur_ip; + char* code_limit; + void* fp; int ret_type; struct branch_table branch_table; struct call_table call_table; @@ -112,7 +125,7 @@ struct dill_private_ctx { mach_reset_func native_mach_reset; saved_insn_info native; saved_insn_info virtual; - void *mach_info; + void* mach_info; int machine_strr_tmp_reg; reg_set var_i; reg_set tmp_i; @@ -120,96 +133,96 @@ struct dill_private_ctx { reg_set tmp_f; int c_param_count; int save_param_count; - dill_reg **c_param_regs; + dill_reg** c_param_regs; arg_info_list c_param_args; - dill_parameter_type **c_param_structs; + dill_parameter_type** c_param_structs; int doing_reverse_push; int unavail_called; int vreg_count; - vreg_info *vregs; + vreg_info* vregs; int v_tmps[DILL_B][3]; int used_frame; /* below used for libffi emulation */ - void*emu_args; - void*cifp; - void*closure; + void* emu_args; + void* cifp; + void* closure; }; struct reg_type { union { - struct { + struct { #ifdef WORDS_BIGENDIAN #if SIZEOF_LONG == 4 - char junk1, junk2, junk3; + char junk1, junk2, junk3; #else - char junk1, junk2, junk3, junk4, junk5, junk6, junk7; + char junk1, junk2, junk3, junk4, junk5, junk6, junk7; #endif #endif - signed char c; - } c; - struct { + signed char c; + } c; + struct { #ifdef WORDS_BIGENDIAN #if SIZEOF_LONG == 4 - char junk1, junk2, junk3; + char junk1, junk2, junk3; #else - char junk1, junk2, junk3, junk4, junk5, junk6, junk7; + char junk1, junk2, junk3, junk4, junk5, junk6, junk7; #endif #endif - unsigned char uc; - } uc; - struct { + unsigned char uc; + } uc; + struct { #ifdef WORDS_BIGENDIAN #if SIZEOF_LONG == 4 - char junk1, junk2; + char junk1, junk2; #else - char junk1, junk2, junk3, junk4, junk5, junk6; + char junk1, junk2, junk3, junk4, junk5, junk6; #endif #endif - short s; - } s; - struct { + short s; + } s; + struct { #ifdef WORDS_BIGENDIAN #if SIZEOF_LONG == 4 - char junk1, junk2; + char junk1, junk2; #else - char junk1, junk2, junk3, junk4, junk5, junk6; + char junk1, junk2, junk3, junk4, junk5, junk6; #endif #endif - unsigned short us; - } us; - struct { + unsigned short us; + } us; + struct { #ifdef WORDS_BIGENDIAN #if SIZEOF_LONG == 8 - char junk1, junk2, junk3, junk4; + char junk1, junk2, junk3, junk4; #endif #endif - int i; - } i; - struct { + int i; + } i; + struct { #ifdef WORDS_BIGENDIAN #if SIZEOF_LONG == 8 - char junk1, junk2, junk3, junk4; + char junk1, junk2, junk3, junk4; #endif #endif - unsigned int u; - } u; - struct { - long l; - } l; - struct { - unsigned long ul; - } ul; - struct { - void * p; - } p; - struct { - float f; - } f; - struct { - double d; - } d; + unsigned int u; + } u; + struct { + intptr_t l; + } l; + struct { + uintptr_t ul; + } ul; + struct { + void* p; + } p; + struct { + float f; + } f; + struct { + double d; + } d; } u; }; @@ -220,30 +233,39 @@ struct calling_param { struct client_data_struct { int key; - long value; + intptr_t value; }; struct dec { dill_stream dc; int ret_reg; int param_count; - struct reg_type *r; - struct reg_type *p; + struct reg_type* r; + struct reg_type* p; int out_param_count; - struct calling_param *out_params; + struct calling_param* out_params; int client_data_count; - struct client_data_struct *client_data; + struct client_data_struct* client_data; }; -extern int dill_mustsave(reg_set *regs, int reg); -extern int dill_wasused(reg_set *regs, int reg); -extern void dill_mark_branch_location(dill_stream s, int label); -extern void dill_mark_call_location(dill_stream s, const char *xfer_name, - void *xfer_address); -extern void dill_mark_ret_location(dill_stream s); -extern void dill_end_vararg_push(dill_stream s); -extern void dill_dump_reg(dill_stream s, int typ, int reg); -extern void setup_VM_proc(dill_stream s); +extern int +dill_mustsave(reg_set* regs, int reg); +extern int +dill_wasused(reg_set* regs, int reg); +extern void +dill_mark_branch_location(dill_stream s, int label); +extern void +dill_mark_call_location(dill_stream s, + const char* xfer_name, + void* xfer_address); +extern void +dill_mark_ret_location(dill_stream s); +extern void +dill_end_vararg_push(dill_stream s); +extern void +dill_dump_reg(dill_stream s, int typ, int reg); +extern void +setup_VM_proc(dill_stream s); typedef struct dill_pkg_1 { unsigned short magic; @@ -253,55 +275,56 @@ typedef struct dill_pkg_1 { short symbol_count; int code_size; short code_offset; -} *dill_pkg; +} * dill_pkg; typedef struct xfer_rec { /*! the textual name of the external entry */ - const char *xfer_name; + const char* xfer_name; /*! the address of the external entry */ - void *xfer_addr; + void* xfer_addr; } xfer_entry; -extern void dill_lookup_xfer_addrs(call_t *t, xfer_entry *x); +extern void +dill_lookup_xfer_addrs(call_t* t, xfer_entry* x); struct dill_exec_s { int ref_count; - void *code_base; + void* code_base; int size; void (*fp)(); /* below used for libffi emulation */ - void*emu_args; - void*cifp; - void*closure; + void* emu_args; + void* cifp; + void* closure; }; -#define DECLARE_JUMP_TABLE(NAME) \ -struct jmp_table_s NAME ## _table_s;\ -arith_op3 NAME ## _a3[dill_jmp_a3_size+1];\ -jmp_data NAME ## _a3_data[dill_jmp_a3_size+1];\ -arith_op3i NAME ## _a3i[dill_jmp_a3_size+1];\ -jmp_data NAME ## _a3i_data[dill_jmp_a3_size+1];\ -arith_op2 NAME ## _a2[dill_jmp_a2_size+1];\ -jmp_data NAME ## _a2_data[dill_jmp_a2_size+1];\ -branch_op NAME ## _b[dill_jmp_branch_size+1];\ -branch_opi NAME ## _bi[dill_jmp_branch_size+1];\ -jmp_data NAME ## _b_data[dill_jmp_branch_size+1];\ -compare_op NAME ## _c[dill_jmp_compare_size+1];\ -compare_opi NAME ## _ci[dill_jmp_compare_size+1];\ -jmp_data NAME ## _c_data[dill_jmp_compare_size+1];\ -\ -jmp_table NAME ## _jump_table = & NAME ## _table_s; - -#define FILL_JUMP_STRUCTURE(NAME)\ - NAME ## _jump_table->jmp_a3 = &NAME ## _a3[0];\ - NAME ## _jump_table->a3_data = &NAME ## _a3_data[0];\ - NAME ## _jump_table->jmp_a3i = &NAME ## _a3i[0];\ - NAME ## _jump_table->a3i_data = &NAME ## _a3i_data[0];\ - NAME ## _jump_table->jmp_a2 = &NAME ## _a2[0];\ - NAME ## _jump_table->a2_data = &NAME ## _a2_data[0];\ - NAME ## _jump_table->jmp_b = &NAME ## _b[0];\ - NAME ## _jump_table->jmp_bi = &NAME ## _bi[0];\ - NAME ## _jump_table->b_data = &NAME ## _b_data[0];\ - NAME ## _jump_table->jmp_c = &NAME ## _c[0];\ - NAME ## _jump_table->jmp_ci = &NAME ## _ci[0];\ - NAME ## _jump_table->c_data = &NAME ## _c_data[0]; +#define DECLARE_JUMP_TABLE(NAME) \ + struct jmp_table_s NAME##_table_s; \ + arith_op3 NAME##_a3[dill_jmp_a3_size + 1]; \ + jmp_data NAME##_a3_data[dill_jmp_a3_size + 1]; \ + arith_op3i NAME##_a3i[dill_jmp_a3_size + 1]; \ + jmp_data NAME##_a3i_data[dill_jmp_a3_size + 1]; \ + arith_op2 NAME##_a2[dill_jmp_a2_size + 1]; \ + jmp_data NAME##_a2_data[dill_jmp_a2_size + 1]; \ + branch_op NAME##_b[dill_jmp_branch_size + 1]; \ + branch_opi NAME##_bi[dill_jmp_branch_size + 1]; \ + jmp_data NAME##_b_data[dill_jmp_branch_size + 1]; \ + compare_op NAME##_c[dill_jmp_compare_size + 1]; \ + compare_opi NAME##_ci[dill_jmp_compare_size + 1]; \ + jmp_data NAME##_c_data[dill_jmp_compare_size + 1]; \ + \ + jmp_table NAME##_jump_table = &NAME##_table_s; + +#define FILL_JUMP_STRUCTURE(NAME) \ + NAME##_jump_table->jmp_a3 = &NAME##_a3[0]; \ + NAME##_jump_table->a3_data = &NAME##_a3_data[0]; \ + NAME##_jump_table->jmp_a3i = &NAME##_a3i[0]; \ + NAME##_jump_table->a3i_data = &NAME##_a3i_data[0]; \ + NAME##_jump_table->jmp_a2 = &NAME##_a2[0]; \ + NAME##_jump_table->a2_data = &NAME##_a2_data[0]; \ + NAME##_jump_table->jmp_b = &NAME##_b[0]; \ + NAME##_jump_table->jmp_bi = &NAME##_bi[0]; \ + NAME##_jump_table->b_data = &NAME##_b_data[0]; \ + NAME##_jump_table->jmp_c = &NAME##_c[0]; \ + NAME##_jump_table->jmp_ci = &NAME##_ci[0]; \ + NAME##_jump_table->c_data = &NAME##_c_data[0]; diff --git a/dill_pkg.c b/dill_pkg.c index 63bffa0010..38faa32897 100644 --- a/dill_pkg.c +++ b/dill_pkg.c @@ -1,9 +1,5 @@ #include "config.h" -#ifdef HAVE_MALLOC_H -#include -#endif - #ifdef STDC_HEADERS #include #include @@ -14,27 +10,29 @@ #include "dill_internal.h" static void -unpack_package(char *package, call_t *t, char **code_p) +unpack_package(char* package, call_t* t, char** code_p) { int count; int pkg_size = sizeof(struct dill_pkg_1); - char *p; - struct dill_pkg_1 *pkg = (struct dill_pkg_1 *) package; + char* p; + struct dill_pkg_1* pkg = (struct dill_pkg_1*)package; - pkg_size = (pkg_size + 7) & -8; /* round up to mod 8 */ + pkg_size = (pkg_size + 7) & -8; /* round up to mod 8 */ p = package + pkg_size; - if (pkg->magic != 0xbeef) printf("Not valid package\n"); - if (pkg->pkg_version != 1) printf("Not valid package version\n"); + if (pkg->magic != 0xbeef) + printf("Not valid package\n"); + if (pkg->pkg_version != 1) + printf("Not valid package version\n"); t->call_alloc = t->call_count = pkg->symbol_count; t->call_locs = malloc(sizeof(t->call_locs[0]) * pkg->symbol_count); memset(t->call_locs, 0, sizeof(t->call_locs[0]) * pkg->symbol_count); - for (count = 0; countsymbol_count; count++) { - size_t call_len; - t->call_locs[count].loc = *((int*)p); - t->call_locs[count].xfer_name = (p + sizeof(int)); - call_len = sizeof(int) + strlen(t->call_locs[count].xfer_name) + 1; - call_len = (call_len + 7) & (size_t)-8; /* round up to mod 8 */ - p += call_len; + for (count = 0; count < pkg->symbol_count; count++) { + size_t call_len; + t->call_locs[count].loc = *((int*)p); + t->call_locs[count].xfer_name = (p + sizeof(int)); + call_len = sizeof(int) + strlen(t->call_locs[count].xfer_name) + 1; + call_len = (call_len + 7) & (size_t)-8; /* round up to mod 8 */ + p += call_len; } *code_p = p; } @@ -42,72 +40,80 @@ unpack_package(char *package, call_t *t, char **code_p) extern void* dill_package_entry(char* package) { - struct dill_pkg_1 *pkg = (struct dill_pkg_1 *) package; + struct dill_pkg_1* pkg = (struct dill_pkg_1*)package; return package + pkg->code_offset + pkg->entry_offset; } -extern char * sparc_package_stitch(char *code, call_t *t, dill_pkg pkg); -extern char * x86_package_stitch(char *code, call_t *t, dill_pkg pkg); -extern char * x86_64_package_stitch(char *code, call_t *t, dill_pkg pkg); -extern char * arm5_package_stitch(char *code, call_t *t, dill_pkg pkg); -extern char * arm6_package_stitch(char *code, call_t *t, dill_pkg pkg); -extern char * arm8_package_stitch(char *code, call_t *t, dill_pkg pkg); -extern char * ia64_package_stitch(char *code, call_t *t, dill_pkg pkg); -extern char * powerpc_package_stitch(char *code, call_t *t, dill_pkg pkg); -extern char * ppc64le_package_stitch(char *code, call_t *t, dill_pkg pkg); +extern char* +sparc_package_stitch(char* code, call_t* t, dill_pkg pkg); +extern char* +x86_package_stitch(char* code, call_t* t, dill_pkg pkg); +extern char* +x86_64_package_stitch(char* code, call_t* t, dill_pkg pkg); +extern char* +arm5_package_stitch(char* code, call_t* t, dill_pkg pkg); +extern char* +arm6_package_stitch(char* code, call_t* t, dill_pkg pkg); +extern char* +arm8_package_stitch(char* code, call_t* t, dill_pkg pkg); +extern char* +ia64_package_stitch(char* code, call_t* t, dill_pkg pkg); +extern char* +powerpc_package_stitch(char* code, call_t* t, dill_pkg pkg); +extern char* +ppc64le_package_stitch(char* code, call_t* t, dill_pkg pkg); extern void -dill_lookup_xfer_addrs(call_t *t, xfer_entry *x) +dill_lookup_xfer_addrs(call_t* t, xfer_entry* x) { int i; for (i = 0; i < t->call_count; i++) { - xfer_entry *e = x; - while(e->xfer_name != NULL) { - if (strcmp(e->xfer_name, t->call_locs[i].xfer_name) == 0) { - t->call_locs[i].xfer_addr = e->xfer_addr; - } - e++; - } + xfer_entry* e = x; + while (e->xfer_name != NULL) { + if (strcmp(e->xfer_name, t->call_locs[i].xfer_name) == 0) { + t->call_locs[i].xfer_addr = e->xfer_addr; + } + e++; + } } } extern dill_exec_handle -dill_package_stitch(char *pkg, dill_extern_entry* extra_externs) +dill_package_stitch(char* pkg, dill_extern_entry* extra_externs) { dill_exec_handle handle = malloc(sizeof(*handle)); - char *code; + char* code; call_t t; unpack_package(pkg, &t, &code); if (extra_externs) { - dill_lookup_xfer_addrs(&t, (xfer_entry *)extra_externs); + dill_lookup_xfer_addrs(&t, (xfer_entry*)extra_externs); } #if defined(HOST_X86) && !defined(DILL_IGNORE_NATIVE) - char *p = x86_package_stitch(code, &t, (dill_pkg) pkg); + char* p = x86_package_stitch(code, &t, (dill_pkg)pkg); #elif defined(HOST_SPARC) && !defined(DILL_IGNORE_NATIVE) - char *p = sparc_package_stitch(code, &t, (dill_pkg) pkg); + char* p = sparc_package_stitch(code, &t, (dill_pkg)pkg); #elif defined(HOST_SPARCV9) && !defined(DILL_IGNORE_NATIVE) - char *p = sparc_package_stitch(code, &t, (dill_pkg) pkg); + char* p = sparc_package_stitch(code, &t, (dill_pkg)pkg); #elif defined(HOST_X86_64) && !defined(DILL_IGNORE_NATIVE) - char *p = x86_64_package_stitch(code, &t, (dill_pkg) pkg); + char* p = x86_64_package_stitch(code, &t, (dill_pkg)pkg); #elif defined(HOST_IA64) && !defined(DILL_IGNORE_NATIVE) - char *p = ia64_package_stitch(code, &t, (dill_pkg) pkg); + char* p = ia64_package_stitch(code, &t, (dill_pkg)pkg); #elif defined(HOST_ARM5) && !defined(DILL_IGNORE_NATIVE) - char *p = arm5_package_stitch(code, &t, (dill_pkg) pkg); + char* p = arm5_package_stitch(code, &t, (dill_pkg)pkg); #elif defined(HOST_ARM6) && !defined(DILL_IGNORE_NATIVE) - char *p = arm6_package_stitch(code, &t, (dill_pkg) pkg); + char* p = arm6_package_stitch(code, &t, (dill_pkg)pkg); #elif defined(HOST_ARM7) && !defined(DILL_IGNORE_NATIVE) - char *p = arm6_package_stitch(code, &t, (dill_pkg) pkg); + char* p = arm6_package_stitch(code, &t, (dill_pkg)pkg); #elif defined(HOST_ARM8) && !defined(DILL_IGNORE_NATIVE) - char *p = arm8_package_stitch(code, &t, (dill_pkg) pkg); + char* p = arm8_package_stitch(code, &t, (dill_pkg)pkg); #elif defined(HOST_POWERPC) && !defined(DILL_IGNORE_NATIVE) - char *p = powerpc_package_stitch(code, &t, (dill_pkg) pkg); + char* p = powerpc_package_stitch(code, &t, (dill_pkg)pkg); #elif defined(HOST_PPC64LE) && !defined(DILL_IGNORE_NATIVE) - char *p = ppc64le_package_stitch(code, &t, (dill_pkg) pkg); + char* p = ppc64le_package_stitch(code, &t, (dill_pkg)pkg); #else - char *p = NULL; + char* p = NULL; #endif free(t.call_locs); - handle->fp = (void(*)()) p; + handle->fp = (void (*)())p; return handle; } - diff --git a/dill_util.c b/dill_util.c index 27cee8a62e..083fc31543 100644 --- a/dill_util.c +++ b/dill_util.c @@ -3,59 +3,41 @@ #ifndef NATIVE_ARCH #define NATIVE_ARCH "UNKNOWN" #endif -#ifdef LINUX_KERNEL_MODULE -#ifndef MODULE -#define MODULE -#endif -#ifndef __KERNEL__ -#define __KERNEL__ -#endif -#include -#include -#endif #include "dill.h" -#include "dill_internal.h" -#ifndef LINUX_KERNEL_MODULE #include #include #ifdef HAVE_MALLOC_H #include #endif -#include #include -#ifdef HAVE_UNISTD_H +#include +#ifdef _MSC_VER +#include +typedef SSIZE_T ssize_t; +#else #include #endif -#include #include +#include #ifdef USE_MMAP_CODE_SEG #include #endif -#else -#include -#include -#include "kdill.h" - -#define malloc (void *)DAllocMM -#define free(a) DFreeMM((addrs_t)a) -#define realloc(a,b) (void *)DReallocMM((addrs_t)a, b) -#define fprintf(fmt, args...) printk(args) -#define printf printk -#define exit sys_exit -#undef USE_MMAP_CODE_SEG -extern char *getenv(const char *name); -#endif +#include "dill_internal.h" -static char *DILL_version = "DILL Version "DILL_VERSION"\n"; +static char* DILL_version = "DILL Version " DILL_VERSION "\n"; -void DILLprint_version(){ - printf("%s",DILL_version); +void +DILLprint_version() +{ + printf("%s", DILL_version); } -extern void init_code_block(dill_stream s); -static void free_code_blocks(dill_stream s); +extern void +init_code_block(dill_stream s); +static void +free_code_blocks(dill_stream s); #define END_OF_CODE_BUFFER 60 @@ -79,13 +61,13 @@ dill_register_init(dill_stream s) static void dill_branch_init(dill_stream s) { - struct branch_table *t = &s->p->branch_table; + struct branch_table* t = &s->p->branch_table; int i; t->next_label = 0; - for (i=0; imax_alloc; i++) { - t->label_locs[i] = -1; - t->label_name[i] = NULL; + for (i = 0; i < t->max_alloc; i++) { + t->label_locs[i] = -1; + t->label_name[i] = NULL; } t->branch_count = 0; t->data_segment_size = 0; @@ -94,7 +76,7 @@ dill_branch_init(dill_stream s) static void dill_call_init(dill_stream s) { - struct call_table *t = &s->p->call_table; + struct call_table* t = &s->p->call_table; t->call_count = 0; } @@ -102,13 +84,14 @@ dill_call_init(dill_stream s) static void dill_ret_init(dill_stream s) { - struct ret_table *t = &s->p->ret_table; + struct ret_table* t = &s->p->ret_table; t->ret_count = 0; } #ifdef BUILD_EMULATOR #include "ffi.h" -void free_emulator_handler_bits(dill_exec_handle handle); +void +free_emulator_handler_bits(dill_exec_handle handle); #endif static void @@ -120,28 +103,42 @@ reset_context(dill_stream s) dill_branch_init(s); dill_call_init(s); dill_ret_init(s); - if (s->p->emu_args) free(s->p->emu_args); - if (s->p->cifp) free(s->p->cifp); + if (s->p->emu_args) + free(s->p->emu_args); + if (s->p->cifp) + free(s->p->cifp); #ifdef BUILD_EMULATOR - if (s->p->closure) ffi_closure_free(s->p->closure); + if (s->p->closure) + ffi_closure_free(s->p->closure); #endif s->p->emu_args = NULL; s->p->cifp = NULL; s->p->closure = NULL; } -extern void dill_sparc_init(dill_stream s); -extern void dill_sparcv9_init(dill_stream s); -extern void dill_x86_init(dill_stream s); -extern void dill_x86_64_init(dill_stream s); -extern void dill_arm5_init(dill_stream s); -extern void dill_arm6_init(dill_stream s); -extern void dill_arm7_init(dill_stream s); -extern void dill_arm8_init(dill_stream s); -extern void dill_ppc64le_init(dill_stream s); -extern void dill_ia64_init(dill_stream s); +extern void +dill_sparc_init(dill_stream s); +extern void +dill_sparcv9_init(dill_stream s); +extern void +dill_x86_init(dill_stream s); +extern void +dill_x86_64_init(dill_stream s); +extern void +dill_arm5_init(dill_stream s); +extern void +dill_arm6_init(dill_stream s); +extern void +dill_arm7_init(dill_stream s); +extern void +dill_arm8_init(dill_stream s); +extern void +dill_ppc64le_init(dill_stream s); +extern void +dill_ia64_init(dill_stream s); #if defined(EMULATION_ONLY) -static void null_init(dill_stream s) +static void +null_init(dill_stream s) { extern int virtual_type_align[]; extern int virtual_type_size[]; @@ -153,63 +150,71 @@ static void null_init(dill_stream s) #endif static int -set_mach_reset(dill_stream s, char *arch) +set_mach_reset(dill_stream s, char* arch) { -#if (defined(MULTI_TARGET) || defined(HOST_SPARC) || defined(HOST_SPARCV9)) && !defined(DILL_IGNORE_NATIVE) +#if (defined(MULTI_TARGET) || defined(HOST_SPARC) || defined(HOST_SPARCV9)) && \ + !defined(DILL_IGNORE_NATIVE) if (strcmp(arch, "sparc") == 0) { - s->p->mach_reset = dill_sparc_init; - return 1; + s->p->mach_reset = dill_sparc_init; + return 1; } else if (strcmp(arch, "sparcv9") == 0) { - s->p->mach_reset = dill_sparcv9_init; - return 1; - } else + s->p->mach_reset = dill_sparcv9_init; + return 1; + } else #endif -#if (defined(MULTI_TARGET) || defined(HOST_X86)) && !defined(DILL_IGNORE_NATIVE) - if (strcmp(arch, "x86") == 0) { - s->p->mach_reset = dill_x86_init; - return 1; - } else +#if (defined(MULTI_TARGET) || defined(HOST_X86)) && !defined(DILL_IGNORE_NATIVE) + if (strcmp(arch, "x86") == 0) { + s->p->mach_reset = dill_x86_init; + return 1; + } else #endif -#if (defined(MULTI_TARGET) || defined(HOST_X86_64)) && !defined(DILL_IGNORE_NATIVE) - if (strcmp(arch, "x86_64") == 0) { - s->p->mach_reset = dill_x86_64_init; - return 1; - } else +#if (defined(MULTI_TARGET) || defined(HOST_X86_64)) && \ + !defined(DILL_IGNORE_NATIVE) + if (strcmp(arch, "x86_64") == 0) { + s->p->mach_reset = dill_x86_64_init; + return 1; + } else #endif -#if (defined(MULTI_TARGET) || defined(HOST_IA64)) && !defined(DILL_IGNORE_NATIVE) - if (strcmp(arch, "ia64") == 0) { - s->p->mach_reset = dill_ia64_init; - return 1; - } else +#if (defined(MULTI_TARGET) || defined(HOST_IA64)) && \ + !defined(DILL_IGNORE_NATIVE) + if (strcmp(arch, "ia64") == 0) { + s->p->mach_reset = dill_ia64_init; + return 1; + } else #endif -#if (defined(MULTI_TARGET) || defined(HOST_ARM5)) && !defined(DILL_IGNORE_NATIVE) - if (strcmp(arch, "arm5") == 0) { - s->p->mach_reset = dill_arm5_init; - return 1; +#if (defined(MULTI_TARGET) || defined(HOST_ARM5)) && \ + !defined(DILL_IGNORE_NATIVE) + if (strcmp(arch, "arm5") == 0) { + s->p->mach_reset = dill_arm5_init; + return 1; } #endif -#if (defined(MULTI_TARGET) || defined(HOST_ARM6)|| defined(HOST_ARM7)) && !defined(DILL_IGNORE_NATIVE) +#if (defined(MULTI_TARGET) || defined(HOST_ARM6) || defined(HOST_ARM7)) && \ + !defined(DILL_IGNORE_NATIVE) if (strcmp(arch, "arm6") == 0) { - s->p->mach_reset = dill_arm6_init; - return 1; + s->p->mach_reset = dill_arm6_init; + return 1; } #endif -#if (defined(MULTI_TARGET) || defined(HOST_ARM7)) && !defined(DILL_IGNORE_NATIVE) +#if (defined(MULTI_TARGET) || defined(HOST_ARM7)) && \ + !defined(DILL_IGNORE_NATIVE) if (strcmp(arch, "arm7") == 0) { - s->p->mach_reset = dill_arm6_init; - return 1; + s->p->mach_reset = dill_arm6_init; + return 1; } #endif -#if (defined(MULTI_TARGET) || defined(HOST_ARM8)) && !defined(DILL_IGNORE_NATIVE) +#if (defined(MULTI_TARGET) || defined(HOST_ARM8)) && \ + !defined(DILL_IGNORE_NATIVE) if (strcmp(arch, "arm8") == 0) { - s->p->mach_reset = dill_arm8_init; - return 1; + s->p->mach_reset = dill_arm8_init; + return 1; } #endif -#if (defined(MULTI_TARGET) || defined(HOST_PPC64LE)) && !defined(DILL_IGNORE_NATIVE) +#if (defined(MULTI_TARGET) || defined(HOST_PPC64LE)) && \ + !defined(DILL_IGNORE_NATIVE) if (strcmp(arch, "ppc64le") == 0) { - s->p->mach_reset = dill_ppc64le_init; - return 1; + s->p->mach_reset = dill_ppc64le_init; + return 1; } #endif #if defined(EMULATION_ONLY) || defined(DILL_IGNORE_NATIVE) @@ -222,16 +227,20 @@ set_mach_reset(dill_stream s, char *arch) extern void dill_free_stream(dill_stream s) { - if (s->p->branch_table.label_locs) free(s->p->branch_table.label_locs); + if (s->p->branch_table.label_locs) + free(s->p->branch_table.label_locs); if (s->p->branch_table.label_name) { - int i=0; - for (i=0; i< s->p->branch_table.max_alloc; i++) { - if (s->p->branch_table.label_name[i]) free(s->p->branch_table.label_name[i]); - } - free(s->p->branch_table.label_name); + int i = 0; + for (i = 0; i < s->p->branch_table.max_alloc; i++) { + if (s->p->branch_table.label_name[i]) + free(s->p->branch_table.label_name[i]); + } + free(s->p->branch_table.label_name); } - if (s->p->branch_table.branch_locs) free(s->p->branch_table.branch_locs); - if (s->p->branch_table.data_segment) free(s->p->branch_table.data_segment); + if (s->p->branch_table.branch_locs) + free(s->p->branch_table.branch_locs); + if (s->p->branch_table.data_segment) + free(s->p->branch_table.data_segment); free(s->p->call_table.call_locs); free(s->p->ret_table.ret_locs); free(s->p->c_param_regs); @@ -239,47 +248,55 @@ dill_free_stream(dill_stream s) free(s->p->c_param_structs); free_code_blocks(s); if (s->p->mach_info) { - if ((s->p->mach_info != s->p->virtual.mach_info) && - (s->p->mach_info != s->p->native.mach_info)) free(s->p->mach_info); + if ((s->p->mach_info != s->p->virtual.mach_info) && + (s->p->mach_info != s->p->native.mach_info)) + free(s->p->mach_info); } - if (s->p->vregs) free(s->p->vregs); - if (s->p->virtual.mach_info) free(s->p->virtual.mach_info); - if (s->p->native.mach_info) free(s->p->native.mach_info); - if (s->p->emu_args) free(s->p->emu_args); - if (s->p->cifp) free(s->p->cifp); + if (s->p->vregs) + free(s->p->vregs); + if (s->p->virtual.mach_info) + free(s->p->virtual.mach_info); + if (s->p->native.mach_info) + free(s->p->native.mach_info); + if (s->p->emu_args) + free(s->p->emu_args); + if (s->p->cifp) + free(s->p->cifp); #ifdef BUILD_EMULATOR - if (s->p->closure) ffi_closure_free(s->p->closure); + if (s->p->closure) + ffi_closure_free(s->p->closure); #endif free(s->p); s->p = NULL; free(s); } -extern void DILLprint_version(); +extern void +DILLprint_version(); extern dill_stream -dill_cross_init(char *arch) +dill_cross_init(char* arch) { - dill_stream s = (dill_stream) malloc(sizeof(struct dill_stream_s)); - char *env = getenv("DILL_DEBUG"); - struct branch_table *bt; - struct call_table *ct; - struct ret_table *rt; + dill_stream s = (dill_stream)malloc(sizeof(struct dill_stream_s)); + char* env = getenv("DILL_DEBUG"); + struct branch_table* bt; + struct call_table* ct; + struct ret_table* rt; memset(s, 0, sizeof(struct dill_stream_s)); - s->p = (private_ctx) malloc(sizeof(struct dill_private_ctx)); + s->p = (private_ctx)malloc(sizeof(struct dill_private_ctx)); memset(s->p, 0, sizeof(struct dill_private_ctx)); if (env == NULL) { - s->dill_debug = 0; + s->dill_debug = 0; } else { - s->dill_debug = 1; - DILLprint_version(); + s->dill_debug = 1; + DILLprint_version(); } s->p->mach_info = NULL; if (!set_mach_reset(s, arch)) { - fprintf(stderr, "DILL support for architecture %s not found.\n", arch); - free(s->p); - free(s); - return NULL; + fprintf(stderr, "DILL support for architecture %s not found.\n", arch); + free(s->p); + free(s); + return NULL; } init_code_block(s); s->p->cur_ip = s->p->code_base; @@ -322,9 +339,8 @@ dill_cross_init(char *arch) return s; } -extern void dill_virtual_init(dill_stream s); - - +extern void +dill_virtual_init(dill_stream s); extern dill_stream dill_create_stream() @@ -348,11 +364,12 @@ dill_create_stream() s->p->virtual.code_limit = s->p->code_limit; return s; } - #ifndef EMULATION_ONLY extern void -dill_native_dcg(){} +dill_native_dcg() +{ +} #endif extern dill_stream @@ -366,26 +383,30 @@ extend_params(dill_stream s, int argno) { int i; if (s->p->c_param_count == 0) { - s->p->c_param_regs = malloc(sizeof(s->p->c_param_regs[0]) * (argno + 2)); - s->p->c_param_args = malloc(sizeof(s->p->c_param_args[0]) * (argno + 2)); - s->p->c_param_structs = malloc(sizeof(s->p->c_param_structs[0]) * (argno + 2)); + s->p->c_param_regs = + malloc(sizeof(s->p->c_param_regs[0]) * (argno + 2)); + s->p->c_param_args = + malloc(sizeof(s->p->c_param_args[0]) * (argno + 2)); + s->p->c_param_structs = + malloc(sizeof(s->p->c_param_structs[0]) * (argno + 2)); } else if (s->p->c_param_count <= (argno + 1)) { - s->p->c_param_regs = realloc(s->p->c_param_regs, - sizeof(s->p->c_param_regs[0]) * (argno + 2)); - s->p->c_param_args = realloc(s->p->c_param_args, - sizeof(s->p->c_param_args[0]) * (argno + 2)); - s->p->c_param_structs = realloc(s->p->c_param_structs, - sizeof(s->p->c_param_structs[0]) * (argno + 2)); + s->p->c_param_regs = realloc( + s->p->c_param_regs, sizeof(s->p->c_param_regs[0]) * (argno + 2)); + s->p->c_param_args = realloc( + s->p->c_param_args, sizeof(s->p->c_param_args[0]) * (argno + 2)); + s->p->c_param_structs = + realloc(s->p->c_param_structs, + sizeof(s->p->c_param_structs[0]) * (argno + 2)); } for (i = s->p->c_param_count; i <= argno; i++) { - s->p->c_param_regs[i] = NULL; - s->p->c_param_args[i].type = DILL_V; - s->p->c_param_args[i].is_register = 0; - s->p->c_param_args[i].is_immediate = 0; - s->p->c_param_args[i].in_reg = 0; - s->p->c_param_args[i].out_reg = 0; - s->p->c_param_args[i].offset = 0; - s->p->c_param_structs[i] = NULL; + s->p->c_param_regs[i] = NULL; + s->p->c_param_args[i].type = DILL_V; + s->p->c_param_args[i].is_register = 0; + s->p->c_param_args[i].is_immediate = 0; + s->p->c_param_args[i].in_reg = 0; + s->p->c_param_args[i].out_reg = 0; + s->p->c_param_args[i].offset = 0; + s->p->c_param_structs[i] = NULL; } s->p->c_param_count = (argno + 1); } @@ -400,15 +421,15 @@ extern int dill_param_reg(dill_stream s, int argno) { if (argno >= s->p->c_param_count) { - printf("Warning, dill_param_reg requested param %d, largest is %d\n", - argno, s->p->c_param_count-1); - return -1; + printf("Warning, dill_param_reg requested param %d, largest is %d\n", + argno, s->p->c_param_count - 1); + return -1; } return s->p->c_param_args[argno].in_reg; } extern void -dill_param_alloc(dill_stream s, int argno, int type, dill_reg *reg_p) +dill_param_alloc(dill_stream s, int argno, int type, dill_reg* reg_p) { extend_params(s, argno); s->p->c_param_regs[argno] = reg_p; @@ -416,8 +437,10 @@ dill_param_alloc(dill_stream s, int argno, int type, dill_reg *reg_p) } extern void -dill_param_struct_alloc(dill_stream s, int argno, int type, - dill_parameter_type *struct_p) +dill_param_struct_alloc(dill_stream s, + int argno, + int type, + dill_parameter_type* struct_p) { extend_params(s, argno); s->p->c_param_structs[argno] = struct_p; @@ -425,47 +448,47 @@ dill_param_struct_alloc(dill_stream s, int argno, int type, } extern void -dill_start_simple_proc(dill_stream s, const char *subr_name, int ret_type) +dill_start_simple_proc(dill_stream s, const char* subr_name, int ret_type) { int i; - if (!s->p->unavail_called) reset_context(s); + if (!s->p->unavail_called) + reset_context(s); s->p->ret_type = ret_type; s->p->unavail_called = 0; - (s->j->proc_start)(s, (char*)subr_name, s->p->c_param_count, s->p->c_param_args, - NULL); - for (i=0; i < s->p->c_param_count; i++) { - if (s->p->c_param_regs[i] != NULL) { - *s->p->c_param_regs[i] = s->p->c_param_args[i].in_reg; - } - if (s->p->c_param_structs[i] != NULL) { - s->p->c_param_structs[i]->is_register = - s->p->c_param_args[i].is_register; - s->p->c_param_structs[i]->reg = s->p->c_param_args[i].in_reg; - s->p->c_param_structs[i]->offset = s->p->c_param_args[i].offset; - } - } + (s->j->proc_start)(s, (char*)subr_name, s->p->c_param_count, + s->p->c_param_args, NULL); + for (i = 0; i < s->p->c_param_count; i++) { + if (s->p->c_param_regs[i] != NULL) { + *s->p->c_param_regs[i] = s->p->c_param_args[i].in_reg; + } + if (s->p->c_param_structs[i] != NULL) { + s->p->c_param_structs[i]->is_register = + s->p->c_param_args[i].is_register; + s->p->c_param_structs[i]->reg = s->p->c_param_args[i].in_reg; + s->p->c_param_structs[i]->offset = s->p->c_param_args[i].offset; + } + } s->p->c_param_count = 0; if (s->p->c_param_regs) { - free(s->p->c_param_regs); - s->p->c_param_regs = NULL; + free(s->p->c_param_regs); + s->p->c_param_regs = NULL; } if (s->p->c_param_args) { - free(s->p->c_param_args); - s->p->c_param_args = NULL; + free(s->p->c_param_args); + s->p->c_param_args = NULL; } if (s->p->c_param_structs) { - free(s->p->c_param_structs); - s->p->c_param_structs = NULL; + free(s->p->c_param_structs); + s->p->c_param_structs = NULL; } } -extern void * +extern void* dill_get_fp(dill_exec_handle h) { - return (void *) h->fp; + return (void*)h->fp; } - extern dill_exec_handle dill_finalize(dill_stream s) { @@ -474,7 +497,7 @@ dill_finalize(dill_stream s) s->p->save_param_count = s->p->c_param_count; s->p->c_param_count = 0; memset(handle, 0, sizeof(*handle)); - handle->fp = (void(*)())s->p->fp; + handle->fp = (void (*)())s->p->fp; handle->ref_count = 1; handle->size = 0; return handle; @@ -485,16 +508,18 @@ dill_get_handle(dill_stream s) { char* native_base = s->p->native.code_base; dill_exec_handle handle = malloc(sizeof(*handle)); - intptr_t size = (intptr_t)s->p->native.code_limit - (intptr_t)s->p->native.code_base + END_OF_CODE_BUFFER; + intptr_t size = (intptr_t)s->p->native.code_limit - + (intptr_t)s->p->native.code_base + END_OF_CODE_BUFFER; s->p->native.code_base = NULL; if (native_base == 0) { native_base = s->p->code_base; - size = (intptr_t)s->p->code_limit - (intptr_t)s->p->code_base + END_OF_CODE_BUFFER; - s->p->code_base = NULL; + size = (intptr_t)s->p->code_limit - (intptr_t)s->p->code_base + + END_OF_CODE_BUFFER; + s->p->code_base = NULL; } - handle->fp = (void(*)())s->p->fp; + handle->fp = (void (*)())s->p->fp; handle->ref_count = 1; - handle->size = size; + handle->size = (int)size; handle->code_base = native_base; /* below used for libffi emulation */ handle->emu_args = s->p->emu_args; @@ -510,15 +535,17 @@ extern void dill_free_handle(dill_exec_handle handle) { handle->ref_count--; - if (handle->ref_count > 0) return; + if (handle->ref_count > 0) + return; if (handle->size != 0) { - if (handle->code_base) { + if (handle->code_base) { #ifdef USE_MMAP_CODE_SEG - if (munmap(handle->code_base, handle->size) == -1) perror("unmap 1"); + if (munmap(handle->code_base, handle->size) == -1) + perror("unmap 1"); #else - free(handle->code_base); + free(handle->code_base); #endif - } + } } handle->code_base = NULL; handle->size = 0; @@ -534,49 +561,51 @@ dill_ref_handle(dill_exec_handle handle) handle->ref_count++; } -static char * -dill_build_package(dill_stream s, int *pkg_len) +static char* +dill_build_package(dill_stream s, int* pkg_len) { - struct call_table *t = &s->p->call_table; + struct call_table* t = &s->p->call_table; int pkg_size = sizeof(struct dill_pkg_1); - char *pkg; + char* pkg; int i; - pkg_size = (pkg_size + 7) & -8; /* round up to mod 8 */ + pkg_size = (pkg_size + 7) & -8; /* round up to mod 8 */ pkg = malloc(pkg_size); memset(pkg, 0, pkg_size); - ((struct dill_pkg_1 *)pkg)->magic = 0xbeef; - ((struct dill_pkg_1 *)pkg)->pkg_version = 1; - ((struct dill_pkg_1 *)pkg)->symbol_count = t->call_count; + ((struct dill_pkg_1*)pkg)->magic = 0xbeef; + ((struct dill_pkg_1*)pkg)->pkg_version = 1; + ((struct dill_pkg_1*)pkg)->symbol_count = t->call_count; for (i = 0; i < t->call_count; i++) { - int call_len = sizeof(int) + strlen(t->call_locs[i].xfer_name) + 1; - char *call_loc; - - call_len = (call_len + 7) & -8; /* round up to mod 8 */ - pkg = realloc(pkg, pkg_size + call_len); - call_loc = pkg + pkg_size; - pkg_size += call_len; - *((int*)call_loc) = t->call_locs[i].loc; - *((int*)(call_loc + call_len - 4)) = 0; /* zero last bit */ - strcpy(call_loc + 4, t->call_locs[i].xfer_name); + int call_len = + (int)(sizeof(int) + strlen(t->call_locs[i].xfer_name) + 1); + char* call_loc; + + call_len = (call_len + 7) & -8; /* round up to mod 8 */ + pkg = realloc(pkg, pkg_size + call_len); + call_loc = pkg + pkg_size; + pkg_size += call_len; + *((int*)call_loc) = t->call_locs[i].loc; + *((int*)(call_loc + call_len - 4)) = 0; /* zero last bit */ + strcpy(call_loc + 4, t->call_locs[i].xfer_name); } pkg = realloc(pkg, pkg_size + dill_code_size(s)); - ((struct dill_pkg_1 *)pkg)->code_size = dill_code_size(s); - ((struct dill_pkg_1 *)pkg)->code_offset = pkg_size; + ((struct dill_pkg_1*)pkg)->code_size = dill_code_size(s); + ((struct dill_pkg_1*)pkg)->code_offset = pkg_size; memcpy(pkg + pkg_size, s->p->code_base, dill_code_size(s)); pkg_size += dill_code_size(s); *pkg_len = pkg_size; - ((struct dill_pkg_1 *)pkg)->entry_offset = (short)( (char*)s->p->fp - (char*)s->p->code_base); + ((struct dill_pkg_1*)pkg)->entry_offset = + (short)((char*)s->p->fp - (char*)s->p->code_base); return pkg; } -extern char * -dill_finalize_package(dill_stream s, int *pkg_len) +extern char* +dill_finalize_package(dill_stream s, int* pkg_len) { (s->j->package_end)(s); s->p->save_param_count = s->p->c_param_count; s->p->c_param_count = 0; - char *p = dill_build_package(s, pkg_len); + char* p = dill_build_package(s, pkg_len); return p; } @@ -587,103 +616,112 @@ dill_code_size(dill_stream s) if (native_base == 0) { native_base = s->p->code_base; } - return (int) ((char*)s->p->cur_ip - native_base); + return (int)((char*)s->p->cur_ip - native_base); } -extern void * -dill_clone_code(dill_stream s, void *new_base, int size) +extern void* +dill_clone_code(dill_stream s, void* new_base, int size) { return (s->j->clone_code)(s, new_base, size); } -extern void * +extern void* dill_take_code(dill_stream s) { - void *ret = s->p->code_base; + void* ret = s->p->code_base; s->p->code_base = NULL; s->p->native.code_base = NULL; return ret; } extern int -dill_alloc_label(dill_stream s, char *name) +dill_alloc_label(dill_stream s, char* name) { - struct branch_table *t = &s->p->branch_table; + struct branch_table* t = &s->p->branch_table; if (t->next_label == t->max_alloc) { - t->max_alloc++; - t->label_locs = realloc(t->label_locs, sizeof(int)*t->max_alloc); - t->label_name = realloc(t->label_name, sizeof(char*)*t->max_alloc); + t->max_alloc++; + t->label_locs = realloc(t->label_locs, sizeof(int) * t->max_alloc); + t->label_name = realloc(t->label_name, sizeof(char*) * t->max_alloc); } t->label_locs[t->next_label] = -1; t->label_name[t->next_label] = NULL; - if (name) t->label_name[t->next_label] = strdup(name); + if (name) + t->label_name[t->next_label] = strdup(name); return t->next_label++; } -extern void dill_mark_label(dill_stream s, int label) +extern void +dill_mark_label(dill_stream s, int label) { - struct branch_table *t = &s->p->branch_table; - int label_loc = (int) ((char*)s->p->cur_ip - (char*)s->p->code_base); + struct branch_table* t = &s->p->branch_table; + int label_loc = (int)((char*)s->p->cur_ip - (char*)s->p->code_base); t->label_locs[label] = label_loc; - if (s->j->mark_label) (s->j->mark_label)(s, 0, 0, 0, 0, label); + if (s->j->mark_label) + (s->j->mark_label)(s, 0, 0, 0, 0, label); if (s->dill_debug) { - if (t->label_name[label] == NULL) { - printf("L%d:\n", label); - } else { - printf("L%d<%s>:\n", label, t->label_name[label]); - } + if (t->label_name[label] == NULL) { + printf("L%d:\n", label); + } else { + printf("L%d<%s>:\n", label, t->label_name[label]); + } } } -extern int dill_is_label_mark(dill_stream s) +extern int +dill_is_label_mark(dill_stream s) { - struct branch_table *t = &s->p->branch_table; + struct branch_table* t = &s->p->branch_table; int i; - int current_loc = (int) ((char*)s->p->cur_ip - (char*)s->p->code_base); + int current_loc = (int)((char*)s->p->cur_ip - (char*)s->p->code_base); for (i = 0; i < t->max_alloc; i++) { - if (t->label_locs[0] == current_loc) return 1; + if (t->label_locs[0] == current_loc) + return 1; } return 0; } -extern void dill_mark_branch_location(dill_stream s, int label) +extern void +dill_mark_branch_location(dill_stream s, int label) { - struct branch_table *t = &s->p->branch_table; + struct branch_table* t = &s->p->branch_table; int branch_loc = (int)((char*)s->p->cur_ip - (char*)s->p->code_base); if (t->branch_count == t->branch_alloc) { - t->branch_alloc++; - t->branch_locs = realloc(t->branch_locs, - sizeof(struct branch_location)*t->branch_alloc); + t->branch_alloc++; + t->branch_locs = realloc( + t->branch_locs, sizeof(struct branch_location) * t->branch_alloc); } t->branch_locs[t->branch_count].label = label; t->branch_locs[t->branch_count].loc = branch_loc; t->branch_count++; } -extern void dill_mark_ret_location(dill_stream s) +extern void +dill_mark_ret_location(dill_stream s) { - struct ret_table *t = &s->p->ret_table; - int ret_loc = (int) ((char*)s->p->cur_ip - (char*)s->p->code_base); + struct ret_table* t = &s->p->ret_table; + int ret_loc = (int)((char*)s->p->cur_ip - (char*)s->p->code_base); if (t->ret_count == t->ret_alloc) { - t->ret_alloc++; - t->ret_locs = realloc(t->ret_locs, sizeof(int)*t->ret_alloc); + t->ret_alloc++; + t->ret_locs = realloc(t->ret_locs, sizeof(int) * t->ret_alloc); } t->ret_locs[t->ret_count] = ret_loc; t->ret_count++; } -extern void dill_mark_call_location(dill_stream s, const char *xfer_name, - void *xfer_address) +extern void +dill_mark_call_location(dill_stream s, + const char* xfer_name, + void* xfer_address) { - struct call_table *t = &s->p->call_table; - int call_loc = (int) ((char*)s->p->cur_ip - (char*)s->p->code_base); + struct call_table* t = &s->p->call_table; + int call_loc = (int)((char*)s->p->cur_ip - (char*)s->p->code_base); if (t->call_count == t->call_alloc) { - t->call_alloc++; - t->call_locs = realloc(t->call_locs, - sizeof(struct call_location)*t->call_alloc); + t->call_alloc++; + t->call_locs = + realloc(t->call_locs, sizeof(struct call_location) * t->call_alloc); } t->call_locs[t->call_count].loc = call_loc; t->call_locs[t->call_count].xfer_addr = xfer_address; @@ -693,92 +731,134 @@ extern void dill_mark_call_location(dill_stream s, const char *xfer_name, } extern int -dill_add_const(dill_stream s, void *addr, int size) +dill_add_const(dill_stream s, void* addr, int size) { - struct branch_table *t = &s->p->branch_table; + struct branch_table* t = &s->p->branch_table; int offset = t->data_segment_size; - t->data_segment = realloc(t->data_segment, offset + size); + t->data_segment = realloc(t->data_segment, offset + size); memcpy(t->data_segment + offset, addr, size); t->data_segment_size += size; return offset; } -static -arg_info_list -translate_arg_str(const char *string, int *count) +static arg_info_list +translate_arg_str(const char* string, int* count) { int cnt = 0; arg_info_list list = malloc(sizeof(list[0])); - + while (string && (*string != 0)) { - if (*string != '%') { - fprintf(stderr, "invalid format, expected %%, got \"%c\"\n", - *string); - return NULL; - } - string++; - list[cnt].is_register = 0; - list[cnt].is_immediate = (isupper((int)(*string)) != 0); - list[cnt].in_reg = 0; - list[cnt].out_reg = 0; - list[cnt].offset = 0; - list[cnt].type = 0; - switch(tolower(*string)) { + if (*string != '%') { + fprintf(stderr, "invalid format, expected %%, got \"%c\"\n", + *string); + return NULL; + } + string++; + list[cnt].is_register = 0; + list[cnt].is_immediate = (isupper((int)(*string)) != 0); + list[cnt].in_reg = 0; + list[cnt].out_reg = 0; + list[cnt].offset = 0; + list[cnt].type = 0; + switch (tolower(*string)) { case 'u': - string++; - switch(tolower(*string)) { - case 'l': list[cnt].type = DILL_UL; string++; break; - case 's': list[cnt].type = DILL_US; string++; break; - case 'c': list[cnt].type = DILL_UC; string++; break; - case '%': case '\0': - list[cnt].type = DILL_U; break; - default: - fprintf(stderr, "invalid format, unexpect char \"%c\" after %%u\n", *string); - } - break; - case 'p': list[cnt].type = DILL_P; string++; break; - case 'l': list[cnt].type = DILL_L; string++; break; - case 'i': list[cnt].type = DILL_I; string++; break; - case 's': list[cnt].type = DILL_S; string++; break; - case 'c': list[cnt].type = DILL_C; string++; break; - case 'b': list[cnt].type = DILL_B; string++; break; - case 'f': list[cnt].type = DILL_F; string++; break; - case 'd': list[cnt].type = DILL_D; string++; break; - case 'e': - string++; - if (tolower(*string) == 'c') { - if (cnt == 0) { - list[cnt].type = DILL_EC; string++; break; - } else { - fprintf(stderr, "%%ec format must be first format\n"); - } - } else { - fprintf(stderr, "invalid format, unexpect char \"%c\" after %%e\n", *string); - } - string++; - break; + string++; + switch (tolower(*string)) { + case 'l': + list[cnt].type = DILL_UL; + string++; + break; + case 's': + list[cnt].type = DILL_US; + string++; + break; + case 'c': + list[cnt].type = DILL_UC; + string++; + break; + case '%': + case '\0': + list[cnt].type = DILL_U; + break; + default: + fprintf(stderr, + "invalid format, unexpect char \"%c\" after %%u\n", + *string); + } + break; + case 'p': + list[cnt].type = DILL_P; + string++; + break; + case 'l': + list[cnt].type = DILL_L; + string++; + break; + case 'i': + list[cnt].type = DILL_I; + string++; + break; + case 's': + list[cnt].type = DILL_S; + string++; + break; + case 'c': + list[cnt].type = DILL_C; + string++; + break; + case 'b': + list[cnt].type = DILL_B; + string++; + break; + case 'f': + list[cnt].type = DILL_F; + string++; + break; + case 'd': + list[cnt].type = DILL_D; + string++; + break; + case 'e': + string++; + if (tolower(*string) == 'c') { + if (cnt == 0) { + list[cnt].type = DILL_EC; + string++; + break; + } else { + fprintf(stderr, "%%ec format must be first format\n"); + } + } else { + fprintf(stderr, + "invalid format, unexpect char \"%c\" after %%e\n", + *string); + } + string++; + break; default: - fprintf(stderr, "invalid format, unexpect char \"%c\" after %%\n", *string); - string++; - } - cnt++; - list = realloc(list, sizeof(list[0]) * (cnt+1)); + fprintf(stderr, "invalid format, unexpect char \"%c\" after %%\n", + *string); + string++; + } + cnt++; + list = realloc(list, sizeof(list[0]) * (cnt + 1)); } *count = cnt; return list; } extern void -dill_start_proc(dill_stream s, char *name, int ret_type, char *arg_str) +dill_start_proc(dill_stream s, char* name, int ret_type, char* arg_str) { int arg_count = 0; arg_info_list args; - if (!s->p->unavail_called) reset_context(s); + if (!s->p->unavail_called) + reset_context(s); s->p->c_param_count = 0; s->p->ret_type = ret_type; if (s->p->c_param_args != NULL) { - free (s->p->c_param_args); - s->p->c_param_args = NULL; + free(s->p->c_param_args); + s->p->c_param_args = NULL; } args = s->p->c_param_args = translate_arg_str(arg_str, &arg_count); s->p->c_param_count = arg_count; @@ -795,13 +875,15 @@ init_code_block(dill_stream s) #endif static long ps = -1; if (ps == -1) { - ps = (getpagesize ()); + ps = (getpagesize()); } - if (ps > size) size = ps; - s->p->code_base = (void*)mmap(0, 4096/*INIT_CODE_SIZE*/, - PROT_EXEC | PROT_READ | PROT_WRITE, - MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); - if (s->p->code_base == (void*)-1) perror("mmap"); + if (ps > size) + size = ps; + s->p->code_base = (void*)mmap(0, 4096 /*INIT_CODE_SIZE*/, + PROT_EXEC | PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (s->p->code_base == (void*)-1) + perror("mmap"); #else s->p->code_base = (void*)malloc(size); #endif @@ -813,42 +895,52 @@ free_code_blocks(dill_stream s) { #ifdef USE_MMAP_CODE_SEG if (s->p->code_base) { - int size = (long)s->p->code_limit - (long)s->p->code_base + END_OF_CODE_BUFFER; - if (munmap(s->p->code_base, size) == -1) perror("unmap 1"); + int size = + (long)s->p->code_limit - (long)s->p->code_base + END_OF_CODE_BUFFER; + if (munmap(s->p->code_base, size) == -1) + perror("unmap 1"); } - if (s->p->virtual.code_base && (s->p->virtual.code_base != s->p->code_base) ) { - int vsize = (long)s->p->virtual.code_limit - (long)s->p->virtual.code_base + END_OF_CODE_BUFFER; - if (munmap(s->p->code_base, vsize) == -1) perror("unmap v"); + if (s->p->virtual.code_base && + (s->p->virtual.code_base != s->p->code_base)) { + int vsize = (long)s->p->virtual.code_limit - + (long)s->p->virtual.code_base + END_OF_CODE_BUFFER; + if (munmap(s->p->code_base, vsize) == -1) + perror("unmap v"); } - if (s->p->native.code_base && (s->p->native.code_base != s->p->code_base) ) { - int nsize = (long)s->p->native.code_limit - (long)s->p->native.code_base + END_OF_CODE_BUFFER; - if (munmap(s->p->code_base, nsize) == -1) perror("unmap n"); + if (s->p->native.code_base && (s->p->native.code_base != s->p->code_base)) { + int nsize = (long)s->p->native.code_limit - + (long)s->p->native.code_base + END_OF_CODE_BUFFER; + if (munmap(s->p->code_base, nsize) == -1) + perror("unmap n"); } #else - if (s->p->code_base) free(s->p->code_base); - if (s->p->virtual.code_base && (s->p->virtual.code_base != s->p->code_base) ) - free(s->p->virtual.code_base); - if (s->p->native.code_base && (s->p->native.code_base != s->p->code_base) ) - free(s->p->native.code_base); + if (s->p->code_base) + free(s->p->code_base); + if (s->p->virtual.code_base && (s->p->virtual.code_base != s->p->code_base)) + free(s->p->virtual.code_base); + if (s->p->native.code_base && (s->p->native.code_base != s->p->code_base)) + free(s->p->native.code_base); #endif } extern void extend_dill_stream(dill_stream s) { - int size = (int)((char*)s->p->code_limit - (char*)s->p->code_base + END_OF_CODE_BUFFER); + int size = (int)((char*)s->p->code_limit - (char*)s->p->code_base + + END_OF_CODE_BUFFER); int cur_ip = (int)((char*)s->p->cur_ip - (char*)s->p->code_base); int new_size = size * 2; #ifdef USE_MMAP_CODE_SEG { - void *old = s->p->code_base; - void *new = mmap(0, new_size, - PROT_EXEC | PROT_READ | PROT_WRITE, - MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); - if (new == (void*)-1) perror("mmap1"); - memcpy(new, old, size); - s->p->code_base = new; - if (munmap(old, size) == -1) perror("munmap exp"); + void* old = s->p->code_base; + void* new = mmap(0, new_size, PROT_EXEC | PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (new == (void*)-1) + perror("mmap1"); + memcpy(new, old, size); + s->p->code_base = new; + if (munmap(old, size) == -1) + perror("munmap exp"); } #else s->p->code_base = realloc(s->p->code_base, new_size); @@ -857,53 +949,58 @@ extend_dill_stream(dill_stream s) s->p->code_limit = ((char*)s->p->code_base) + new_size - END_OF_CODE_BUFFER; } -extern jmp_table alloc_dill_jump_table() +extern jmp_table +alloc_dill_jump_table() { - fprintf(stderr, "Don't use alloc_dill_jump_table(). Rewrite to use DECLARE_JUMP_TABLE() and FILL_JUMP_STRUCTURE()\n"); + fprintf(stderr, + "Don't use alloc_dill_jump_table(). Rewrite to use " + "DECLARE_JUMP_TABLE() and FILL_JUMP_STRUCTURE()\n"); return NULL; } -#define BIT_ON(i, bitvec) (((((long)1)<p->var_f.used); - SET_BIT(reg, s->p->tmp_f.used); - break; + SET_BIT(reg, s->p->tmp_f.used); + break; default: SET_BIT(reg, s->p->var_i.used); - SET_BIT(reg, s->p->tmp_i.used); - break; + SET_BIT(reg, s->p->tmp_i.used); + break; } } -int -dill_mustsave(reg_set *regs, int reg) +int +dill_mustsave(reg_set* regs, int reg) { return BIT_ON(reg, regs->mustsave); } -int -dill_wasused(reg_set *regs, int reg) +int +dill_wasused(reg_set* regs, int reg) { return BIT_ON(reg, regs->used); } static int -reg_alloc(reg_set *regs) +reg_alloc(reg_set* regs) { int reg; if (regs->avail[0] == 0) { - return -1; + return -1; } reg = 0; while (!BIT_ON(reg, regs->avail)) { - reg++; + reg++; } RESET_BIT(reg, regs->avail); return reg; @@ -912,46 +1009,48 @@ reg_alloc(reg_set *regs) extern void dill_alloc_specific(dill_stream s, dill_reg reg, int type, int class) { - switch(type) { - case DILL_D: case DILL_F: - if (class == DILL_VAR) { - SET_BIT(reg, s->p->var_f.avail); - RESET_BIT(reg, s->p->var_f.mustsave); - } else { - SET_BIT(reg, s->p->tmp_f.avail); - } - break; + switch (type) { + case DILL_D: + case DILL_F: + if (class == DILL_VAR) { + SET_BIT(reg, s->p->var_f.avail); + RESET_BIT(reg, s->p->var_f.mustsave); + } else { + SET_BIT(reg, s->p->tmp_f.avail); + } + break; default: - if (class == DILL_VAR) { - SET_BIT(reg, s->p->var_i.avail); - RESET_BIT(reg, s->p->var_i.mustsave); - } else { - SET_BIT(reg, s->p->tmp_i.avail); - } - break; + if (class == DILL_VAR) { + SET_BIT(reg, s->p->var_i.avail); + RESET_BIT(reg, s->p->var_i.mustsave); + } else { + SET_BIT(reg, s->p->tmp_i.avail); + } + break; } } extern void dill_dealloc_specific(dill_stream s, dill_reg reg, int type, int class) { - switch(type) { - case DILL_D: case DILL_F: - if (class == DILL_VAR) { - RESET_BIT(reg, s->p->var_f.avail); - SET_BIT(reg, s->p->var_f.mustsave); - } else { - RESET_BIT(reg, s->p->tmp_f.avail); - } - break; + switch (type) { + case DILL_D: + case DILL_F: + if (class == DILL_VAR) { + RESET_BIT(reg, s->p->var_f.avail); + SET_BIT(reg, s->p->var_f.mustsave); + } else { + RESET_BIT(reg, s->p->tmp_f.avail); + } + break; default: - if (class == DILL_VAR) { - RESET_BIT(reg, s->p->var_i.avail); - SET_BIT(reg, s->p->var_i.mustsave); - } else { - RESET_BIT(reg, s->p->tmp_i.avail); - } - break; + if (class == DILL_VAR) { + RESET_BIT(reg, s->p->var_i.avail); + SET_BIT(reg, s->p->var_i.mustsave); + } else { + RESET_BIT(reg, s->p->tmp_i.avail); + } + break; } } @@ -959,51 +1058,53 @@ extern void dill_raw_unavailreg(dill_stream s, int type, dill_reg reg) { if (s->p->unavail_called == 0) { - reset_context(s); - s->p->unavail_called = 1; + reset_context(s); + s->p->unavail_called = 1; } - switch(type) { - case DILL_D: case DILL_F: - RESET_BIT(reg, s->p->var_f.avail); - RESET_BIT(reg, s->p->tmp_f.avail); - break; + switch (type) { + case DILL_D: + case DILL_F: + RESET_BIT(reg, s->p->var_f.avail); + RESET_BIT(reg, s->p->tmp_f.avail); + break; default: - RESET_BIT(reg, s->p->var_i.avail); - RESET_BIT(reg, s->p->tmp_i.avail); - break; + RESET_BIT(reg, s->p->var_i.avail); + RESET_BIT(reg, s->p->tmp_i.avail); + break; } } extern void dill_raw_availreg(dill_stream s, int type, dill_reg reg) { - switch(type) { - case DILL_D: case DILL_F: - if (BIT_ON(reg, s->p->tmp_f.members)) { - SET_BIT(reg, s->p->tmp_f.avail); - } else if (BIT_ON(reg, s->p->var_f.members)) { - SET_BIT(reg, s->p->var_f.avail); - } else { - printf("mk avail not in set error %d\n", reg); - } - break; + switch (type) { + case DILL_D: + case DILL_F: + if (BIT_ON(reg, s->p->tmp_f.members)) { + SET_BIT(reg, s->p->tmp_f.avail); + } else if (BIT_ON(reg, s->p->var_f.members)) { + SET_BIT(reg, s->p->var_f.avail); + } else { + printf("mk avail not in set error %d\n", reg); + } + break; default: - if (BIT_ON(reg, s->p->tmp_i.members)) { - SET_BIT(reg, s->p->tmp_i.avail); - } else if (BIT_ON(reg, s->p->var_i.members)) { - SET_BIT(reg, s->p->var_i.avail); - } else { - printf("mk avail not in set error %d\n", reg); - } - break; + if (BIT_ON(reg, s->p->tmp_i.members)) { + SET_BIT(reg, s->p->tmp_i.avail); + } else if (BIT_ON(reg, s->p->var_i.members)) { + SET_BIT(reg, s->p->var_i.avail); + } else { + printf("mk avail not in set error %d\n", reg); + } + break; } } extern int dill_getreg(dill_stream s, int typ) { - s->p->vregs = realloc(s->p->vregs, - (s->p->vreg_count +1) * sizeof(vreg_info)); + s->p->vregs = + realloc(s->p->vregs, (s->p->vreg_count + 1) * sizeof(vreg_info)); s->p->vregs[s->p->vreg_count].typ = typ; s->p->vregs[s->p->vreg_count].use_info.use_count = 0; s->p->vregs[s->p->vreg_count].use_info.def_count = 0; @@ -1014,8 +1115,8 @@ dill_getreg(dill_stream s, int typ) extern int dill_getvblock(dill_stream s, int size) { - s->p->vregs = realloc(s->p->vregs, - (s->p->vreg_count +1) * sizeof(vreg_info)); + s->p->vregs = + realloc(s->p->vregs, (s->p->vreg_count + 1) * sizeof(vreg_info)); s->p->vregs[s->p->vreg_count].typ = DILL_B; s->p->vregs[s->p->vreg_count].offset = size; s->p->vregs[s->p->vreg_count].use_info.use_count = 0; @@ -1023,100 +1124,103 @@ dill_getvblock(dill_stream s, int size) return ((s->p->vreg_count++) + 100); } -extern int -dill_raw_getreg(dill_stream s, dill_reg *reg_p, int type, int class) +extern int +dill_raw_getreg(dill_stream s, dill_reg* reg_p, int type, int class) { int reg = -1; switch (type) { - case DILL_D: case DILL_F: - if (class == DILL_VAR) { - if ((reg = reg_alloc(&s->p->var_f)) == -1) { - reg = reg_alloc(&s->p->tmp_f); - } - if (reg != -1) { - SET_BIT(reg, s->p->tmp_f.mustsave); - SET_BIT(reg, s->p->tmp_f.used); - } - *reg_p = reg; - return (reg != -1); - } else { - if ((reg = reg_alloc(&s->p->tmp_f)) == -1) { - reg = reg_alloc(&s->p->var_f); - } - if (reg != -1) { - SET_BIT(reg, s->p->tmp_f.used); - } - *reg_p = reg; - return (reg != -1); - } + case DILL_D: + case DILL_F: + if (class == DILL_VAR) { + if ((reg = reg_alloc(&s->p->var_f)) == -1) { + reg = reg_alloc(&s->p->tmp_f); + } + if (reg != -1) { + SET_BIT(reg, s->p->tmp_f.mustsave); + SET_BIT(reg, s->p->tmp_f.used); + } + *reg_p = reg; + return (reg != -1); + } else { + if ((reg = reg_alloc(&s->p->tmp_f)) == -1) { + reg = reg_alloc(&s->p->var_f); + } + if (reg != -1) { + SET_BIT(reg, s->p->tmp_f.used); + } + *reg_p = reg; + return (reg != -1); + } default: - if (class == DILL_VAR) { - if ((reg = reg_alloc(&s->p->var_i)) == -1) { - reg = reg_alloc(&s->p->tmp_i); - if (reg != -1) { - SET_BIT(reg, s->p->tmp_i.mustsave); - SET_BIT(reg, s->p->tmp_i.used); - } - } else { - SET_BIT(reg, s->p->var_i.used); - } - *reg_p = reg; - return (reg != -1); - } else { - if ((reg = reg_alloc(&s->p->tmp_i)) == -1) { - reg = reg_alloc(&s->p->var_i); - } - if (reg != -1) { - SET_BIT(reg, s->p->tmp_i.used); - } - *reg_p = reg; - return (reg != -1); - } + if (class == DILL_VAR) { + if ((reg = reg_alloc(&s->p->var_i)) == -1) { + reg = reg_alloc(&s->p->tmp_i); + if (reg != -1) { + SET_BIT(reg, s->p->tmp_i.mustsave); + SET_BIT(reg, s->p->tmp_i.used); + } + } else { + SET_BIT(reg, s->p->var_i.used); + } + *reg_p = reg; + return (reg != -1); + } else { + if ((reg = reg_alloc(&s->p->tmp_i)) == -1) { + reg = reg_alloc(&s->p->var_i); + } + if (reg != -1) { + SET_BIT(reg, s->p->tmp_i.used); + } + *reg_p = reg; + return (reg != -1); + } } -} +} extern void dill_raw_putreg(dill_stream s, dill_reg reg, int type) { switch (type) { - case DILL_F: case DILL_D: - if (BIT_ON(reg, s->p->tmp_f.members)) { - dill_alloc_specific(s, reg, type, DILL_TEMP); - } else if (BIT_ON(reg, s->p->var_f.members)) { - dill_alloc_specific(s, reg, type, DILL_VAR); - } else { - /* - * special case, if the put reg is invalid (-1) and - * the member set is empty, give no warning. - */ - if ((s->p->var_f.members[0] != 0) || (reg != -1)) { - printf("Putreg not in set error %d\n", reg); - } - } - break; + case DILL_F: + case DILL_D: + if (BIT_ON(reg, s->p->tmp_f.members)) { + dill_alloc_specific(s, reg, type, DILL_TEMP); + } else if (BIT_ON(reg, s->p->var_f.members)) { + dill_alloc_specific(s, reg, type, DILL_VAR); + } else { + /* + * special case, if the put reg is invalid (-1) and + * the member set is empty, give no warning. + */ + if ((s->p->var_f.members[0] != 0) || (reg != -1)) { + printf("Putreg not in set error %d\n", reg); + } + } + break; default: - if (BIT_ON(reg, s->p->tmp_i.members)) { - dill_alloc_specific(s, reg, type, DILL_TEMP); - } else if (BIT_ON(reg, s->p->var_i.members)) { - dill_alloc_specific(s, reg, type, DILL_VAR); - } else { - printf("Putreg not in set error %d\n", reg); - } - break; + if (BIT_ON(reg, s->p->tmp_i.members)) { + dill_alloc_specific(s, reg, type, DILL_TEMP); + } else if (BIT_ON(reg, s->p->var_i.members)) { + dill_alloc_specific(s, reg, type, DILL_VAR); + } else { + printf("Putreg not in set error %d\n", reg); + } + break; } -} +} -extern int +extern int dill_do_reverse_vararg_push(dill_stream s) { if (s->j->do_reverse_push) { - s->p->doing_reverse_push = 1; - return 1; + s->p->doing_reverse_push = 1; + return 1; } return 0; } -extern void dill_end_vararg_push(dill_stream s) +extern void +dill_end_vararg_push(dill_stream s) { s->p->doing_reverse_push = 0; } @@ -1125,9 +1229,9 @@ extern int dill_type_of(dill_stream s, int vreg) { if (vreg >= 100) { - return s->p->vregs[vreg - 100].typ; + return s->p->vregs[vreg - 100].typ; } else { - return s->p->c_param_args[vreg].type; + return s->p->c_param_args[vreg].type; } } @@ -1136,13 +1240,13 @@ typedef union { int i; long l; unsigned long ul; - void *p; + void* p; float f; double d; } type_union; -static void -do_vararg_push(dill_stream s, const char *arg_str, va_list ap) +static void +do_vararg_push(dill_stream s, const char* arg_str, va_list ap) { int i, arg_count; int reverse = 0; @@ -1153,93 +1257,108 @@ do_vararg_push(dill_stream s, const char *arg_str, va_list ap) reverse = dill_do_reverse_vararg_push(s); - for(i = 0; i < arg_count; i++) { - if(!args[i].is_immediate) { - value[i].i = va_arg(ap, int); - } else { - switch(args[i].type) { - case DILL_UC: case DILL_US: case DILL_U: - value[i].u = va_arg(ap, unsigned); - break; - case DILL_C: case DILL_S: case DILL_I: - value[i].i = va_arg(ap, int); - break; - case DILL_L: - value[i].l = va_arg(ap, long); - break; - case DILL_UL: - value[i].ul = va_arg(ap, unsigned long); - break; - case DILL_P: - value[i].p = va_arg(ap, void *); - break; - case DILL_F: - value[i].f = (float)va_arg(ap, double); - break; - case DILL_D: - value[i].d = va_arg(ap, double); - break; - default: - fprintf(stderr, - "do_push_args: unknown type\n"); - exit(1); - } - } + for (i = 0; i < arg_count; i++) { + if (!args[i].is_immediate) { + value[i].i = va_arg(ap, int); + } else { + switch (args[i].type) { + case DILL_UC: + case DILL_US: + case DILL_U: + value[i].u = va_arg(ap, unsigned); + break; + case DILL_C: + case DILL_S: + case DILL_I: + value[i].i = va_arg(ap, int); + break; + case DILL_L: + value[i].l = va_arg(ap, long); + break; + case DILL_UL: + value[i].ul = va_arg(ap, unsigned long); + break; + case DILL_P: + value[i].p = va_arg(ap, void*); + break; + case DILL_F: + value[i].f = (float)va_arg(ap, double); + break; + case DILL_D: + value[i].d = va_arg(ap, double); + break; + default: + fprintf(stderr, "do_push_args: unknown type\n"); + exit(1); + } + } } /* push all arguments */ - for(i = 0; i < arg_count; i++) { - int arg = i; - if (reverse) { - arg = arg_count - i - 1; - } - if(!args[arg].is_immediate) { - dill_push_arg(s, args[arg].type, value[arg].i); - } else { - switch(args[arg].type) { - case DILL_UC: case DILL_US: case DILL_U: - dill_push_argui(s, value[arg].u); - break; - case DILL_C: case DILL_S: case DILL_I: - dill_push_argii(s, value[arg].i); - break; - case DILL_L: - dill_push_argli(s, value[arg].l); - break; - case DILL_UL: - dill_push_arguli(s, value[arg].ul); - break; - case DILL_P: - dill_push_argpi(s, value[arg].p); - break; - case DILL_F: - dill_push_argfi(s, value[arg].f); - break; - case DILL_D: - dill_push_argdi(s, value[arg].d); - break; - default: - fprintf(stderr, - "do_push_args: unknown type\n"); - exit(1); - } - } + for (i = 0; i < arg_count; i++) { + int arg = i; + if (reverse) { + arg = arg_count - i - 1; + } + if (!args[arg].is_immediate) { + dill_push_arg(s, args[arg].type, value[arg].i); + } else { + switch (args[arg].type) { + case DILL_UC: + case DILL_US: + case DILL_U: + dill_push_argui(s, value[arg].u); + break; + case DILL_C: + case DILL_S: + case DILL_I: + dill_push_argii(s, value[arg].i); + break; + case DILL_L: + dill_push_argli(s, value[arg].l); + break; + case DILL_UL: + dill_push_arguli(s, value[arg].ul); + break; + case DILL_P: + dill_push_argpi(s, value[arg].p); + break; + case DILL_F: + dill_push_argfi(s, value[arg].f); + break; + case DILL_D: + dill_push_argdi(s, value[arg].d); + break; + default: + fprintf(stderr, "do_push_args: unknown type\n"); + exit(1); + } + } } free(args); } - -void dill_scallv(dill_stream s, void *ptr, const char *name, const char *arg_str, ...) +void +dill_scallv(dill_stream s, + void* ptr, + const char* name, + const char* arg_str, + ...) { va_list ap; va_start(ap, arg_str); do_vararg_push(s, arg_str, ap); - (void) s->j->calli(s, DILL_V, ptr, (char*)name); + (void)s->j->calli(s, DILL_V, ptr, (char*)name); va_end(ap); } -int dill_scalli(dill_stream s, void* ptr, const char *name, const char *arg_str, ...) +int +dill_scalli(dill_stream s, + void* ptr, + const char* name, + const char* arg_str, + ...) { int ret_reg; va_list ap; @@ -1250,7 +1369,13 @@ int dill_scalli(dill_stream s, void* ptr, const char *name, const char *arg_str, return ret_reg; } -int dill_scallu(dill_stream s, void *ptr, const char *name, const char *arg_str, ...) { +int +dill_scallu(dill_stream s, + void* ptr, + const char* name, + const char* arg_str, + ...) +{ int ret_reg; va_list ap; va_start(ap, arg_str); @@ -1260,7 +1385,13 @@ int dill_scallu(dill_stream s, void *ptr, const char *name, const char *arg_str, return ret_reg; } -int dill_scallp(dill_stream s, void *ptr, const char *name, const char *arg_str, ...) { +int +dill_scallp(dill_stream s, + void* ptr, + const char* name, + const char* arg_str, + ...) +{ int ret_reg; va_list ap; va_start(ap, arg_str); @@ -1270,7 +1401,13 @@ int dill_scallp(dill_stream s, void *ptr, const char *name, const char *arg_str, return ret_reg; } -int dill_scallul(dill_stream s, void *ptr, const char *name, const char *arg_str, ...) { +int +dill_scallul(dill_stream s, + void* ptr, + const char* name, + const char* arg_str, + ...) +{ int ret_reg; va_list ap; va_start(ap, arg_str); @@ -1280,7 +1417,13 @@ int dill_scallul(dill_stream s, void *ptr, const char *name, const char *arg_str return ret_reg; } -int dill_scalll(dill_stream s, void *ptr, const char *name, const char *arg_str, ...) { +int +dill_scalll(dill_stream s, + void* ptr, + const char* name, + const char* arg_str, + ...) +{ int ret_reg; va_list ap; va_start(ap, arg_str); @@ -1290,7 +1433,13 @@ int dill_scalll(dill_stream s, void *ptr, const char *name, const char *arg_str, return ret_reg; } -int dill_scallf(dill_stream s, void *ptr, const char *name, const char *arg_str, ...) { +int +dill_scallf(dill_stream s, + void* ptr, + const char* name, + const char* arg_str, + ...) +{ int ret_reg; va_list ap; va_start(ap, arg_str); @@ -1300,7 +1449,13 @@ int dill_scallf(dill_stream s, void *ptr, const char *name, const char *arg_str, return ret_reg; } -int dill_scalld(dill_stream s, void *ptr, const char *name, const char *arg_str, ...) { +int +dill_scalld(dill_stream s, + void* ptr, + const char* name, + const char* arg_str, + ...) +{ int ret_reg; va_list ap; va_start(ap, arg_str); @@ -1311,34 +1466,43 @@ int dill_scalld(dill_stream s, void *ptr, const char *name, const char *arg_str, } extern void -dill_error(char *msg) +dill_error(char* msg) { printf("%s", msg); } extern void -dill_pbr(dill_stream s, int op_type, int data_type, dill_reg src1, dill_reg src2, - int label) +dill_pbr(dill_stream s, + int op_type, + int data_type, + dill_reg src1, + dill_reg src2, + int label) { int index; - if ((op_type < dill_eq_code ) || (op_type > dill_ne_code)) { - printf("Bad op type in dill_pbr\n"); + if ((op_type < dill_eq_code) || (op_type > dill_ne_code)) { + printf("Bad op type in dill_pbr\n"); } index = data_type + 11 * op_type; - (s->j->jmp_b)[index](s, s->j->b_data[index].data1, - s->j->b_data[index].data2, src1, src2, label); + (s->j->jmp_b)[index](s, s->j->b_data[index].data1, + s->j->b_data[index].data2, src1, src2, label); } extern void -dill_pcompare(dill_stream s, int op_type, int data_type, dill_reg dest, dill_reg src1, dill_reg src2) +dill_pcompare(dill_stream s, + int op_type, + int data_type, + dill_reg dest, + dill_reg src1, + dill_reg src2) { int index; - if ((op_type < dill_eq_code ) || (op_type > dill_ne_code)) { - printf("Bad op type in dill_pcompare\n"); + if ((op_type < dill_eq_code) || (op_type > dill_ne_code)) { + printf("Bad op type in dill_pcompare\n"); } index = data_type + 11 * op_type; - (s->j->jmp_c)[index](s, s->j->c_data[index].data1, - s->j->c_data[index].data2, dest, src1, src2); + (s->j->jmp_c)[index](s, s->j->c_data[index].data1, + s->j->c_data[index].data2, dest, src1, src2); } extern void @@ -1347,9 +1511,9 @@ dill_dump_reg(dill_stream s, int typ, int reg) s->j->print_reg(s, typ, reg); } -#if !defined (HAVE_DIS_ASM_H) || defined(NO_DISASSEMBLER) +#if !defined(HAVE_DIS_ASM_H) || defined(NO_DISASSEMBLER) struct disassemble_info { - void *junk; + void* junk; }; #endif @@ -1359,120 +1523,105 @@ struct disassemble_info { #include "dis-asm.h" #ifndef NO_INLINED_BFD_PROCS #if defined(BFD64) -bfd_vma -bfd_getl64 (addr) +bfd_vma bfd_getl64(addr) #ifdef BFD_BYTE - register const bfd_byte *addr; + register const bfd_byte* addr; #else - const void *addr; + const void* addr; #endif { #if SIZEOF_LONG == 8 - register const unsigned char *addrp = addr; - bfd_vma low, high; - high= (((((((addrp[7] << 8) | - addrp[6]) << 8) | - addrp[5]) << 8) | - addrp[4])); - - low = ((((((((bfd_vma)addrp[3] << 8) | - addrp[2]) << 8) | - addrp[1]) << 8) | - addrp[0]) ); - - return high << 32 | low; + register const unsigned char* addrp = addr; + bfd_vma low, high; + high = + (((((((addrp[7] << 8) | addrp[6]) << 8) | addrp[5]) << 8) | addrp[4])); + + low = ((((((((bfd_vma)addrp[3] << 8) | addrp[2]) << 8) | addrp[1]) << 8) | + addrp[0])); + + return high << 32 | low; #else - return 0; + return 0; #endif - } #endif -bfd_vma -bfd_getb32 (addr) +bfd_vma bfd_getb32(addr) #ifdef BFD_BYTE - register const bfd_byte *addr; + register const bfd_byte* addr; #else - const void *addr; + const void* addr; #endif { - register const unsigned char *addrp = addr; - return (((((bfd_vma)addrp[0] << 8) | addrp[1]) << 8) - | addrp[2]) << 8 | addrp[3]; + register const unsigned char* addrp = addr; + return (((((bfd_vma)addrp[0] << 8) | addrp[1]) << 8) | addrp[2]) << 8 | + addrp[3]; } -bfd_vma -bfd_getl32 (addr) +bfd_vma bfd_getl32(addr) #ifdef BFD_BYTE - register const bfd_byte *addr; + register const bfd_byte* addr; #else - const void *addr; + const void* addr; #endif { - register const unsigned char *addrp = addr; - return (((((bfd_vma)addrp[3] << 8) | addrp[2]) << 8) - | addrp[1]) << 8 | addrp[0]; + register const unsigned char* addrp = addr; + return (((((bfd_vma)addrp[3] << 8) | addrp[2]) << 8) | addrp[1]) << 8 | + addrp[0]; } -bfd_vma -bfd_getb16 (addr) +bfd_vma bfd_getb16(addr) #ifdef BFD_BYTE - register const bfd_byte *addr; + register const bfd_byte* addr; #else - const void *addr; + const void* addr; #endif { - register const unsigned char *addrp = addr; - return (addrp[0] << 8) | addrp[1]; + register const unsigned char* addrp = addr; + return (addrp[0] << 8) | addrp[1]; } -bfd_vma -bfd_getl16 (addr) +bfd_vma bfd_getl16(addr) #ifdef BFD_BYTE - register const bfd_byte *addr; + register const bfd_byte* addr; #else - const void *addr; + const void* addr; #endif { - register const unsigned char *addrp = addr; - return (addrp[1] << 8) | addrp[0]; + register const unsigned char* addrp = addr; + return (addrp[1] << 8) | addrp[0]; } -enum bfd_architecture -bfd_get_arch (abfd) - bfd *abfd; +enum bfd_architecture bfd_get_arch(abfd) bfd* abfd; { return abfd->arch_info->arch; } -void * -xmalloc(size) -int size; +void* xmalloc(size) int size; { return (void*)malloc(size); } -char * -xstrdup (s) - const char *s; +char* xstrdup(s) const char* s; { - int len; - char *ret; + int len; + char* ret; - len = strlen (s); - ret = xmalloc (len + 1); - strcpy (ret, s); - return ret; + len = strlen(s); + ret = xmalloc(len + 1); + strcpy(ret, s); + return ret; } #endif extern void -dump_dill_insn(dill_stream s, void *p) +dump_dill_insn(dill_stream s, void* p) { struct disassemble_info info; int l; - if (s->j->init_disassembly(s, &info) == 0) return; + if (s->j->init_disassembly(s, &info) == 0) + return; printf("%lx - %x - ", (unsigned long)p, (unsigned int)*(int*)p); l = s->j->print_insn(s, &info, p); @@ -1489,6 +1638,13 @@ dump_cur_dill_insn(dill_stream s) extern void dump_cur_dill_insn(dill_stream s) { + struct disassemble_info info; + s->j->init_disassembly(s, &info); + + void* p = s->p->cur_ip; + printf("%p - %x - ", p, (unsigned)*(int*)p); + (void)s->j->print_insn(s, &info, (void*)p); + printf("\n"); } #endif @@ -1496,75 +1652,99 @@ extern void dill_dump(dill_stream s) { struct disassemble_info info; - void *base = s->p->code_base; + void* base = s->p->code_base; int native_missing = 0; - if ((base != s->p->virtual.code_base) && - (s->p->virtual.code_base != NULL) && (s->p->virtual.mach_jump != NULL)){ - /* Section to dump virtual code base *after* dcg completion */ - /* only do this if we're not currently in the middle of virtual generation */ - void *code_limit = s->p->virtual.cur_ip; - base = s->p->virtual.code_base; - s->p->virtual.mach_jump->init_disassembly(s, &info); - void *p; - int l; - int insn_count = 0; - printf("\nDILL virtual instruction stream\n\n"); - for (p =base; p < code_limit;) { - printf("%p - %x - ", p, (unsigned)*(int*)p); - l = s->p->virtual.mach_jump->print_insn(s, &info, (void *)p); - printf("\n"); - if (l == -1) return; - p = (char*)p + l; - insn_count++; - } - printf("\nDumped %d virtual instructions\n\n", insn_count); + (s->p->virtual.code_base != NULL) && + (s->p->virtual.mach_jump != NULL)) { + /* Section to dump virtual code base *after* dcg completion */ + /* only do this if we're not currently in the middle of virtual + * generation */ + void* code_limit = s->p->virtual.cur_ip; + base = s->p->virtual.code_base; + s->p->virtual.mach_jump->init_disassembly(s, &info); + void* p; + int l; + int insn_count = 0; + printf("\nDILL virtual instruction stream\n\n"); + for (p = base; p < code_limit;) { + printf("%p - %x - ", p, (unsigned)*(int*)p); + l = s->p->virtual.mach_jump->print_insn(s, &info, (void*)p); + printf("\n"); + if (l == -1) + return; + p = (char*)p + l; + insn_count++; + } + printf("\nDumped %d virtual instructions\n\n", insn_count); } #if defined(NO_DISASSEMBLER) native_missing = 1; #endif base = s->p->code_base; if (base == NULL) { - base = s->p->native.code_base; + base = s->p->native.code_base; } if (base == NULL) { - printf("No code to dump\n"); - return; + printf("No code to dump\n"); + return; } /* if ((s->j != s->p->virtual.mach_jump) && native_missing) { */ /* printf("No native disassembler available\n"); */ /* return; */ /* } */ - (void) native_missing; + (void)native_missing; if (s->j->init_disassembly(s, &info) == 0) { - printf("No native disassembler available\n"); + printf("No native disassembler available\n"); } else { - void *p; - int l; - int insn_count = 0; - if ((s->j != s->p->virtual.mach_jump) && (s->p->fp != NULL) ) - base = s->p->fp; - for (p =base; (char*) p < s->p->cur_ip;) { - int i; - struct branch_table *t = &s->p->branch_table; - for (i=0; i < t->next_label; i++) { - if (t->label_locs[i] == - ((char*)p - (char*)base)) { - printf("L%d:\n", i); - } - } - if (p == s->p->fp) { - printf("Function entry point:\n"); - } - printf("%p - %x - ", p, (unsigned)*(int*)p); - l = s->j->print_insn(s, &info, (void *)p); - printf("\n"); - if (l <= 0) return; - p = (char*)p + l; - insn_count++; - } - printf("\nDumped %d instructions\n\n", insn_count); + void* p; + int l; + int insn_count = 0; + if ((s->j != s->p->virtual.mach_jump) && (s->p->fp != NULL)) + base = s->p->fp; + for (p = base; (char*)p < s->p->cur_ip;) { + int i; + struct branch_table* t = &s->p->branch_table; + for (i = 0; i < t->next_label; i++) { + if (t->label_locs[i] == ((char*)p - (char*)base)) { + printf("L%d:\n", i); + } + } + if (p == s->p->fp) { + printf("Function entry point:\n"); + } + printf("%p - %x - ", p, (unsigned)*(int*)p); + l = s->j->print_insn(s, &info, (void*)p); + printf("\n"); + if (l <= 0) + return; + p = (char*)p + l; + insn_count++; + } + printf("\nDumped %d instructions\n\n", insn_count); } } +#undef malloc +#undef realloc + +extern void* +dill_malloc(size_t size) +{ + void* tmp = malloc(size); + if (tmp) + return tmp; + fprintf(stderr, "Dill out of memory, exiting\n"); + exit(1); +} + +extern void* +dill_realloc(void* ptr, size_t size) +{ + void* tmp = realloc(ptr, size); + if (tmp) + return tmp; + fprintf(stderr, "Dill out of memory, exiting\n"); + exit(1); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8662e65a31..44e135155b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,9 +34,12 @@ if(NOT (CMAKE_C_COMPILER_ID MATCHES "MSVC" OR set_target_properties(dill_regress PROPERTIES COMPILE_FLAGS "-O0") endif() -add_executable(cplus cplus.cc) -target_link_libraries(cplus dill ${DIS_LIBS}) -add_test(NAME dill_cplus COMMAND cplus) +if(NOT (CMAKE_C_COMPILER_ID MATCHES "MSVC" OR + CMAKE_C_SIMULATE_ID MATCHES "MSVC")) + add_executable(cplus cplus.cc) + target_link_libraries(cplus dill ${DIS_LIBS}) + add_test(NAME dill_cplus COMMAND cplus) +endif() add_executable(stest stest.c) target_link_libraries(stest dill ${DIS_LIBS}) diff --git a/tests/call-gen b/tests/call-gen index 0c8d5da4ed..6ff2765532 100644 --- a/tests/call-gen +++ b/tests/call-gen @@ -195,7 +195,7 @@ int main(int argc, char *argv[]) { s2l = rand() + 1; s1f = (float)rand() / rand(); - s2f = (float)rand() / (rand()+1) * ((rand()%1) ? 1. : -1.); + s2f = (float)rand() / (float) ((rand()+1) * ((rand()%1) ? 1. : -1.)); s1d = (double)rand() / rand(); s2d = (double)rand() / (rand()+1) * ((rand()%1) ? 1. : -1.); diff --git a/tests/stest.c b/tests/stest.c index db89d57c2b..05be83c703 100644 --- a/tests/stest.c +++ b/tests/stest.c @@ -134,6 +134,10 @@ int main() { if (target == (void*)-1) perror("mmap"); #else target = (void*)malloc(dill_code_size(s)); + if (!target) { + printf("out of memory\n"); + return 1; + } #endif ip = (int (*)()) dill_clone_code(s, target, dill_code_size(s)); dill_free_stream(s); diff --git a/tests/test-gen b/tests/test-gen index 22c2a134de..3da37510d7 100644 --- a/tests/test-gen +++ b/tests/test-gen @@ -208,6 +208,12 @@ sub emit_unary { $insni = "$insn" . "i"; $cast1 = ($t eq "p") ? "" : ""; + if (($op eq '-') and ($t eq "u")) { + $op = '(unsigned) - (int)'; + } + if (($op eq '-') and ($t eq "ul")) { + $op = '(uintptr_t) - (intptr_t)'; + } $upt = "\U$t\E"; print<\n#include \"string.h\"\n#include \"dill.h\"\n#include \n#include \n\n"; + print "int dill_errors;\n#include \n#include \"string.h\"\n#include \"dill.h\"\n#include \n#include \n#include \n\n"; print< -#include "config.h" -#include "dill.h" -#include "dill_internal.h" -#include "virtual.h" -#ifndef LINUX_KERNEL_MODULE -#include -#include #include +#include +#include #include -#ifdef HAVE_MALLOC_H -#include -#endif -#include +#include "config.h" +#include "dill.h" +#ifdef _MSC_VER +#include +typedef SSIZE_T ssize_t; #else -#ifdef LINUX_KERNEL_MODULE -#ifndef __KERNEL__ -#define __KERNEL__ -#endif -#endif -#include -#include -#include -#include "kdill.h" -#include "library.h" - -#define printf printk -#define fprintf(file, args...) printk (args) -#define malloc (void *)DAllocMM -#define realloc(a,b) (void *)DReallocMM((addrs_t)a, b) -#define free(a) DFreeMM((addrs_t) a) -#define qsort _quicksort +#include #endif +#include "dill_internal.h" +#include "virtual.h" -extern char *arith3_name[]; -extern char *arith2_name[]; -extern char *dill_type_names[]; -extern char *branch_op_names[]; -extern char *compare_op_names[]; +extern char* arith3_name[]; +extern char* arith2_name[]; +extern char* dill_type_names[]; +extern char* branch_op_names[]; +extern char* compare_op_names[]; -typedef void (*apply_func)(dill_stream c, basic_block b, - virtual_insn *ip, int loc); +typedef void (*apply_func)(dill_stream c, + basic_block b, + virtual_insn* ip, + int loc); -static void apply_to_each(dill_stream c, void *insns, virtual_mach_info vmi, - apply_func func); +static void +apply_to_each(dill_stream c, + void* insns, + virtual_mach_info vmi, + apply_func func); -static const char *prefix_names[] = {"X86_CS_PREFIX", "X86_SS_PREFIX", - "X86_DS_PREFIX", "X86_ES_PREFIX", - "X86_FS_PREFIX", "X86_GS_PREFIX"}; +static const char* prefix_names[] = {"X86_CS_PREFIX", "X86_SS_PREFIX", + "X86_DS_PREFIX", "X86_ES_PREFIX", + "X86_FS_PREFIX", "X86_GS_PREFIX"}; -#define OPND(x) ((x >= 100) ? ((dill_type_of(c, x) == DILL_B) ? 'B' : 'R') :'P'), x +#define OPND(x) \ + ((x >= 100) ? ((dill_type_of(c, x) == DILL_B) ? 'B' : 'R') : 'P'), x extern int -virtual_print_insn(dill_stream c, void *info_ptr, void *i) +virtual_print_insn(dill_stream c, void* info_ptr, void* i) { - virtual_insn *insn = (virtual_insn *)i; + virtual_insn* insn = (virtual_insn*)i; int insn_code = insn->insn_code; - switch(insn->class_code) { + switch (insn->class_code) { case iclass_arith3: - printf("%s %c%d, %c%d, %c%d", arith3_name[insn_code], - OPND(insn->opnds.a3.dest), - OPND(insn->opnds.a3.src1), - OPND(insn->opnds.a3.src2)); + printf("%s %c%d, %c%d, %c%d", arith3_name[insn_code], + OPND(insn->opnds.a3.dest), OPND(insn->opnds.a3.src1), + OPND(insn->opnds.a3.src2)); break; case iclass_arith3i: - printf("%si %c%d, %c%d, %zu", arith3_name[insn_code], - OPND(insn->opnds.a3i.dest), - OPND(insn->opnds.a3i.src), insn->opnds.a3i.u.imm); + printf("%si %c%d, %c%d, %zu", arith3_name[insn_code], + OPND(insn->opnds.a3i.dest), OPND(insn->opnds.a3i.src), + insn->opnds.a3i.u.imm); break; case iclass_arith2: printf("%s %c%d, %c%d", arith2_name[insn_code], - OPND(insn->opnds.a2.dest), OPND(insn->opnds.a2.src)); + OPND(insn->opnds.a2.dest), OPND(insn->opnds.a2.src)); break; - case iclass_convert: - { - int from_index = (insn->insn_code >> 4) & 0xf; - int to_index = insn->insn_code & 0xf; + case iclass_convert: { + int from_index = (insn->insn_code >> 4) & 0xf; + int to_index = insn->insn_code & 0xf; printf("cv%s2%s %c%d, %c%d", dill_type_names[from_index], - dill_type_names[to_index], OPND(insn->opnds.a2.dest), - OPND(insn->opnds.a2.src)); + dill_type_names[to_index], OPND(insn->opnds.a2.dest), + OPND(insn->opnds.a2.src)); break; } - case iclass_loadstore: - { - int typ = insn->insn_code & 0xf; - int store = (insn->insn_code & 0x10) == 0x10; - int bswap = (insn->insn_code & 0x20) == 0x20; + case iclass_loadstore: { + int typ = insn->insn_code & 0xf; + int store = (insn->insn_code & 0x10) == 0x10; + int bswap = (insn->insn_code & 0x20) == 0x20; printf("%s%s%s %c%d, %c%d, %c%d", bswap ? "bs" : "", - store == 0 ? "ld" : "st", - dill_type_names[typ], OPND(insn->opnds.a3.dest), - OPND(insn->opnds.a3.src1), OPND(insn->opnds.a3.src2)); + store == 0 ? "ld" : "st", dill_type_names[typ], + OPND(insn->opnds.a3.dest), OPND(insn->opnds.a3.src1), + OPND(insn->opnds.a3.src2)); break; } - case iclass_loadstorei: - { - int typ = insn->insn_code & 0xf; - int store = (insn->insn_code & 0x10) == 0x10; - int bswap = (insn->insn_code & 0x20) == 0x20; + case iclass_loadstorei: { + int typ = insn->insn_code & 0xf; + int store = (insn->insn_code & 0x10) == 0x10; + int bswap = (insn->insn_code & 0x20) == 0x20; printf("%s%s%si %c%d, %c%d, %zu", bswap ? "bs" : "", - store == 0 ? "ld" : "st", - dill_type_names[typ], OPND(insn->opnds.a3i.dest), - OPND(insn->opnds.a3i.src), insn->opnds.a3i.u.imm); + store == 0 ? "ld" : "st", dill_type_names[typ], + OPND(insn->opnds.a3i.dest), OPND(insn->opnds.a3i.src), + insn->opnds.a3i.u.imm); break; } - case iclass_lea: - { + case iclass_lea: { printf("lea %c%d, %c%d, %zx", OPND(insn->opnds.a3i.dest), - OPND(insn->opnds.a3i.src), insn->opnds.a3i.u.imm); + OPND(insn->opnds.a3i.src), insn->opnds.a3i.u.imm); break; } - case iclass_set: - { - int typ = insn->insn_code & 0xf; - printf("set%s %c%d, %zx", - dill_type_names[typ], OPND(insn->opnds.a3i.dest), - insn->opnds.a3i.u.imm); + case iclass_set: { + int typ = insn->insn_code & 0xf; + printf("set%s %c%d, %zx", dill_type_names[typ], + OPND(insn->opnds.a3i.dest), insn->opnds.a3i.u.imm); break; } - case iclass_setf: - { - int typ = insn->insn_code & 0xf; - union { - double imm; - int imm_i[2]; - } u; - u.imm = insn->opnds.sf.imm; - printf("set%s %c%d, %g 0x(%x)0x(%x)", - dill_type_names[typ], OPND(insn->opnds.sf.dest), - insn->opnds.sf.imm, u.imm_i[0], u.imm_i[1]); + case iclass_setf: { + int typ = insn->insn_code & 0xf; + union { + double imm; + int imm_i[2]; + } u; + u.imm = insn->opnds.sf.imm; + printf("set%s %c%d, %g 0x(%x)0x(%x)", dill_type_names[typ], + OPND(insn->opnds.sf.dest), insn->opnds.sf.imm, u.imm_i[0], + u.imm_i[1]); break; } - case iclass_mov: - { - int typ = insn->insn_code & 0xf; - printf("mov%s %c%d, %c%d", - dill_type_names[typ], OPND(insn->opnds.a2.dest), - OPND(insn->opnds.a2.src)); + case iclass_mov: { + int typ = insn->insn_code & 0xf; + printf("mov%s %c%d, %c%d", dill_type_names[typ], + OPND(insn->opnds.a2.dest), OPND(insn->opnds.a2.src)); break; } - case iclass_reti: - { - int typ = insn->insn_code & 0xf; - printf("ret%si %zu", - dill_type_names[typ], insn->opnds.a3i.u.imm); + case iclass_reti: { + int typ = insn->insn_code & 0xf; + printf("ret%si %zu", dill_type_names[typ], insn->opnds.a3i.u.imm); break; } - case iclass_ret: - { - int typ = insn->insn_code & 0xf; - printf("ret%s %c%d", - dill_type_names[typ], OPND(insn->opnds.a1.src)); + case iclass_ret: { + int typ = insn->insn_code & 0xf; + printf("ret%s %c%d", dill_type_names[typ], OPND(insn->opnds.a1.src)); break; } - case iclass_branch: - { - int br_op = insn->insn_code; - struct branch_table *t = &c->p->branch_table; - printf("b%s %c%d, %c%d, L%d", branch_op_names[br_op], - OPND(insn->opnds.br.src1), - OPND(insn->opnds.br.src2), insn->opnds.br.label); - if (t->label_name[insn->opnds.br.label] != NULL) { - printf("<%s>", t->label_name[insn->opnds.br.label]); - } + case iclass_branch: { + int br_op = insn->insn_code; + struct branch_table* t = &c->p->branch_table; + printf("b%s %c%d, %c%d, L%d", branch_op_names[br_op], + OPND(insn->opnds.br.src1), OPND(insn->opnds.br.src2), + insn->opnds.br.label); + if (t->label_name[insn->opnds.br.label] != NULL) { + printf("<%s>", t->label_name[insn->opnds.br.label]); + } break; } - case iclass_compare: - { - int c_op = insn->insn_code; - printf("%s %c%d, %c%d, %c%d", compare_op_names[c_op], - OPND(insn->opnds.a3.dest), - OPND(insn->opnds.a3.src1), - OPND(insn->opnds.a3.src2)); + case iclass_compare: { + int c_op = insn->insn_code; + printf("%s %c%d, %c%d, %c%d", compare_op_names[c_op], + OPND(insn->opnds.a3.dest), OPND(insn->opnds.a3.src1), + OPND(insn->opnds.a3.src2)); break; } - case iclass_branchi: - { - int br_op = insn->insn_code; - struct branch_table *t = &c->p->branch_table; - printf("b%si %c%d, %p, L%d", branch_op_names[br_op], - OPND(insn->opnds.bri.src), - (void*)insn->opnds.bri.imm_l, insn->opnds.bri.label); - if (t->label_name[insn->opnds.bri.label] != NULL) { - printf("<%s>", t->label_name[insn->opnds.bri.label]); - } + case iclass_branchi: { + int br_op = insn->insn_code; + struct branch_table* t = &c->p->branch_table; + printf("b%si %c%d, %p, L%d", branch_op_names[br_op], + OPND(insn->opnds.bri.src), (void*)insn->opnds.bri.imm_l, + insn->opnds.bri.label); + if (t->label_name[insn->opnds.bri.label] != NULL) { + printf("<%s>", t->label_name[insn->opnds.bri.label]); + } break; } - case iclass_jump_to_label: - { - struct branch_table *t = &c->p->branch_table; + case iclass_jump_to_label: { + struct branch_table* t = &c->p->branch_table; printf("br L%d", insn->opnds.br.label); - if (t->label_name[insn->opnds.br.label] != NULL) { - printf("<%s>", t->label_name[insn->opnds.br.label]); - } + if (t->label_name[insn->opnds.br.label] != NULL) { + printf("<%s>", t->label_name[insn->opnds.br.label]); + } break; } - case iclass_mark_label: - { - struct branch_table *t = &c->p->branch_table; + case iclass_mark_label: { + struct branch_table* t = &c->p->branch_table; printf("L%d:", insn->opnds.label.label); - if (t->label_name[insn->opnds.label.label] != NULL) { - printf("<%s>", t->label_name[insn->opnds.label.label]); - } + if (t->label_name[insn->opnds.label.label] != NULL) { + printf("<%s>", t->label_name[insn->opnds.label.label]); + } break; } - case iclass_jump_to_reg: - { + case iclass_jump_to_reg: { printf("jmp %c%d", OPND(insn->opnds.br.src1)); - break; + break; } - case iclass_jump_to_imm: - { + case iclass_jump_to_imm: { printf("jmp 0x%p", insn->opnds.bri.imm_a); break; } - case iclass_special: - { - switch (insn->opnds.spec.type) { - case DILL_NOP: - printf("special NOP"); - break; - case DILL_SEGMENTED_FOLLOWS: - printf("special SEGMENTED %s", - prefix_names[insn->opnds.spec.param]); - break; - } + case iclass_special: { + switch (insn->opnds.spec.type) { + case DILL_NOP: + printf("special NOP"); + break; + case DILL_SEGMENTED_FOLLOWS: + printf("special SEGMENTED %s", + prefix_names[insn->opnds.spec.param]); + break; + } break; } - case iclass_call: - { - int typ = insn->insn_code & 0xf; - int reg = insn->insn_code & 0x10; - if (typ != DILL_V) { - if (reg != 0) { - printf("call%s R%p, %c%d", dill_type_names[typ], - (void*)insn->opnds.calli.imm_l, OPND(insn->opnds.calli.src)); - } else { - const char *call_name = insn->opnds.calli.xfer_name; - if (call_name) { - printf("call%s 0x%p<%s>, %c%d", dill_type_names[typ], - insn->opnds.calli.imm_a, call_name, - OPND(insn->opnds.calli.src)); - } else { - printf("call%s 0x%p, %c%d", dill_type_names[typ], - insn->opnds.calli.imm_a, OPND(insn->opnds.calli.src)); - } - } - } else { - if (reg != 0) { - printf("call%s R%p", dill_type_names[typ], - (void*)insn->opnds.calli.imm_l); - } else { - const char *call_name = insn->opnds.calli.xfer_name; - if (call_name) { - printf("call%s 0x%p<%s>", dill_type_names[typ], - insn->opnds.calli.imm_a, call_name); - } else { - printf("call%s 0x%p", dill_type_names[typ], - insn->opnds.calli.imm_a); - } - } - } + case iclass_call: { + int typ = insn->insn_code & 0xf; + int reg = insn->insn_code & 0x10; + if (typ != DILL_V) { + if (reg != 0) { + printf("call%s R%p, %c%d", dill_type_names[typ], + (void*)insn->opnds.calli.imm_l, + OPND(insn->opnds.calli.src)); + } else { + const char* call_name = insn->opnds.calli.xfer_name; + if (call_name) { + printf("call%s 0x%p<%s>, %c%d", dill_type_names[typ], + insn->opnds.calli.imm_a, call_name, + OPND(insn->opnds.calli.src)); + } else { + printf("call%s 0x%p, %c%d", dill_type_names[typ], + insn->opnds.calli.imm_a, + OPND(insn->opnds.calli.src)); + } + } + } else { + if (reg != 0) { + printf("call%s R%p", dill_type_names[typ], + (void*)insn->opnds.calli.imm_l); + } else { + const char* call_name = insn->opnds.calli.xfer_name; + if (call_name) { + printf("call%s 0x%p<%s>", dill_type_names[typ], + insn->opnds.calli.imm_a, call_name); + } else { + printf("call%s 0x%p", dill_type_names[typ], + insn->opnds.calli.imm_a); + } + } + } break; } - case iclass_push: - { - int typ = insn->insn_code & 0xf; - if ((short)insn->opnds.a1.src < 0) { - if ((short)insn->opnds.a1.src == -1) { - printf("pushinit"); - } else { - int non_var_arg = -((short)insn->opnds.a1.src) - 2; - printf("pushinit varidiac, %d nonvar args", non_var_arg); - } - } else { - printf("push%s %c%d", dill_type_names[typ], - OPND(insn->opnds.a1.src)); - } + case iclass_push: { + int typ = insn->insn_code & 0xf; + if ((short)insn->opnds.a1.src < 0) { + if ((short)insn->opnds.a1.src == -1) { + printf("pushinit"); + } else { + int non_var_arg = -((short)insn->opnds.a1.src) - 2; + printf("pushinit varidiac, %d nonvar args", non_var_arg); + } + } else { + printf("push%s %c%d", dill_type_names[typ], + OPND(insn->opnds.a1.src)); + } break; } - case iclass_pushi: - { - int typ = insn->insn_code & 0xf; - if (typ == DILL_P) { - printf("push%si 0x%p", dill_type_names[typ], insn->opnds.a3i.u.imm_a); - } else { - printf("push%si 0x%zx", dill_type_names[typ], insn->opnds.a3i.u.imm); - } + case iclass_pushi: { + int typ = insn->insn_code & 0xf; + if (typ == DILL_P) { + printf("push%si 0x%p", dill_type_names[typ], + insn->opnds.a3i.u.imm_a); + } else { + printf("push%si 0x%zx", dill_type_names[typ], + insn->opnds.a3i.u.imm); + } break; } - case iclass_pushf: - { - int typ = insn->insn_code; + case iclass_pushf: { + int typ = insn->insn_code; printf("push%si %g", dill_type_names[typ], insn->opnds.sf.imm); break; } case iclass_nop: - printf("nop"); + printf("nop"); } return sizeof(*insn); } static int -insn_same_except_dest(virtual_insn *i, virtual_insn *j) +insn_same_except_dest(virtual_insn* i, virtual_insn* j) { int icode = i->insn_code; int jcode = j->insn_code; - - if (i->class_code != j->class_code) return 0; - switch(i->class_code) { + + if (i->class_code != j->class_code) + return 0; + switch (i->class_code) { case iclass_arith3: case iclass_compare: - return ((icode == jcode) && (i->opnds.a3.src1 == j->opnds.a3.src1) && - (i->opnds.a3.src2 == j->opnds.a3.src2)); + return ((icode == jcode) && (i->opnds.a3.src1 == j->opnds.a3.src1) && + (i->opnds.a3.src2 == j->opnds.a3.src2)); case iclass_arith3i: - return ((icode == jcode) && (i->opnds.a3i.src == j->opnds.a3i.src) && - (i->opnds.a3i.u.imm == j->opnds.a3i.u.imm)); + return ((icode == jcode) && (i->opnds.a3i.src == j->opnds.a3i.src) && + (i->opnds.a3i.u.imm == j->opnds.a3i.u.imm)); case iclass_arith2: - return ((icode == jcode) && (i->opnds.a2.src == j->opnds.a2.src)); + return ((icode == jcode) && (i->opnds.a2.src == j->opnds.a2.src)); case iclass_convert: - return ((icode == jcode) && (i->opnds.a2.src == j->opnds.a2.src)); + return ((icode == jcode) && (i->opnds.a2.src == j->opnds.a2.src)); case iclass_loadstore: - return ((icode == jcode) && (i->opnds.a3.src1 == j->opnds.a3.src1) && - (i->opnds.a3.src2 == j->opnds.a3.src2)); + return ((icode == jcode) && (i->opnds.a3.src1 == j->opnds.a3.src1) && + (i->opnds.a3.src2 == j->opnds.a3.src2)); case iclass_loadstorei: - return ((icode == jcode) && (i->opnds.a3i.src == j->opnds.a3i.src) && - (i->opnds.a3i.u.imm == j->opnds.a3i.u.imm)); + return ((icode == jcode) && (i->opnds.a3i.src == j->opnds.a3i.src) && + (i->opnds.a3i.u.imm == j->opnds.a3i.u.imm)); case iclass_lea: - return ((i->opnds.a3i.src == j->opnds.a3i.src) && - (i->opnds.a3i.u.imm == j->opnds.a3i.u.imm)); + return ((i->opnds.a3i.src == j->opnds.a3i.src) && + (i->opnds.a3i.u.imm == j->opnds.a3i.u.imm)); case iclass_set: case iclass_setf: - return 0; + return 0; case iclass_mov: - return ((icode == jcode) && (i->opnds.a2.src == j->opnds.a2.src)); + return ((icode == jcode) && (i->opnds.a2.src == j->opnds.a2.src)); case iclass_reti: case iclass_ret: case iclass_branch: @@ -346,48 +312,48 @@ insn_same_except_dest(virtual_insn *i, virtual_insn *j) case iclass_pushf: case iclass_nop: case iclass_mark_label: - break; + break; } return 0; } static void -pushpop_inuse_regs(dill_stream c, int pop, virtual_insn *ip) +pushpop_inuse_regs(dill_stream c, int pop, virtual_insn* ip) { int i = 0; /* no actual reg assigns, so only the params are in use */ - for(i=0; ip->c_param_count; i++) { - if (c->p->c_param_args[i].is_register) { - c->j->save_restore(c, pop, c->p->c_param_args[i].type, - c->p->c_param_args[i].in_reg); - } + for (i = 0; i < c->p->c_param_count; i++) { + if (c->p->c_param_args[i].is_register) { + c->j->save_restore(c, pop, c->p->c_param_args[i].type, + c->p->c_param_args[i].in_reg); + } } } - -#define end_bb(b, lab, f) \ -{\ -bb->end_branch_label = lab; \ -bb->fall_through = f;\ -bb->end = i - 1;\ -vmi->bbcount++;\ -vmi->bblist = realloc(vmi->bblist, sizeof(struct basic_block) * (vmi->bbcount +1));\ -bb = &vmi->bblist[vmi->bbcount];\ -bb->start = i;\ -bb->end = -1;\ -bb->label = -1;\ -bb->end_branch_label = -1;\ -bb->fall_through = 0; \ -bb->is_loop_start = 0; \ -bb->is_loop_end = 0; \ -bb->regs_used = new_bit_vec(c->p->vreg_count);\ -bb->regs_defined = new_bit_vec(c->p->vreg_count);\ -} +#define end_bb(b, lab, f) \ + { \ + bb->end_branch_label = lab; \ + bb->fall_through = f; \ + bb->end = i - 1; \ + vmi->bbcount++; \ + vmi->bblist = realloc( \ + vmi->bblist, sizeof(struct basic_block) * (vmi->bbcount + 1)); \ + bb = &vmi->bblist[vmi->bbcount]; \ + bb->start = i; \ + bb->end = -1; \ + bb->label = -1; \ + bb->end_branch_label = -1; \ + bb->fall_through = 0; \ + bb->is_loop_start = 0; \ + bb->is_loop_end = 0; \ + bb->regs_used = new_bit_vec(c->p->vreg_count); \ + bb->regs_defined = new_bit_vec(c->p->vreg_count); \ + } static bit_vec new_bit_vec(int max) { - int len = (max +7) >> 3; + int len = (max + 7) >> 3; bit_vec ret = malloc(sizeof(struct bitv) + len - 2); ret->len = len; memset(&ret->vec[0], 0, len); @@ -430,14 +396,15 @@ static void dump_reg_vec(bit_vec v) { int i; - if (v == NULL) return; - for (i=0; i < v->len; i++) { - int j; - for (j=0; j < 7; j++) { - if ((v->vec[i] & (1 << j)) != 0) { - printf(" R%d", i * 8 + j + 100); - } - } + if (v == NULL) + return; + for (i = 0; i < v->len; i++) { + int j; + for (j = 0; j < 7; j++) { + if ((v->vec[i] & (1 << j)) != 0) { + printf(" R%d", i * 8 + j + 100); + } + } } } @@ -445,8 +412,8 @@ static int has_single_def_use(dill_stream c, int vreg) { if (vreg >= 100) { - return ((c->p->vregs[vreg-100].use_info.use_count == 1) && - (c->p->vregs[vreg-100].use_info.def_count == 1)); + return ((c->p->vregs[vreg - 100].use_info.use_count == 1) && + (c->p->vregs[vreg - 100].use_info.def_count == 1)); } return 0; } @@ -455,20 +422,20 @@ static void set_unused(dill_stream c, basic_block bb, int vreg) { if (vreg >= 100) { - c->p->vregs[vreg-100].use_info.use_count = 0; - c->p->vregs[vreg-100].use_info.def_count = 0; - bit_vec_clear(bb->regs_defined, vreg - 100); - bit_vec_clear(bb->regs_used, vreg - 100); - } + c->p->vregs[vreg - 100].use_info.use_count = 0; + c->p->vregs[vreg - 100].use_info.def_count = 0; + bit_vec_clear(bb->regs_defined, vreg - 100); + bit_vec_clear(bb->regs_used, vreg - 100); + } } static void set_used(dill_stream c, int vreg) { if (vreg >= 100) { - c->p->vregs[vreg-100].use_info.use_count++; + c->p->vregs[vreg - 100].use_info.use_count++; } else { - c->p->c_param_args[vreg].used++; + c->p->c_param_args[vreg].used++; } } @@ -476,67 +443,76 @@ static void set_defined(dill_stream c, int vreg) { if (vreg >= 100) { - c->p->vregs[vreg-100].use_info.def_count++; + c->p->vregs[vreg - 100].use_info.def_count++; } } -static void bb_defines(dill_stream c, basic_block bb, int vreg) +static void +bb_defines(dill_stream c, basic_block bb, int vreg) { if (vreg >= 100) { - /* not param */ - if (!bit_vec_is_set(bb->regs_used, vreg - 100)) { - bit_vec_set(bb->regs_defined, vreg - 100); - } - set_defined(c, vreg); + /* not param */ + if (!bit_vec_is_set(bb->regs_used, vreg - 100)) { + bit_vec_set(bb->regs_defined, vreg - 100); + } + set_defined(c, vreg); } } -static void bb_uses(dill_stream c, basic_block bb, int vreg) +static void +bb_uses(dill_stream c, basic_block bb, int vreg) { if (vreg >= 100) { - /* not param */ - if (!bit_vec_is_set(bb->regs_defined, vreg - 100)) { - bit_vec_set(bb->regs_used, vreg - 100); - } - set_used(c, vreg); + /* not param */ + if (!bit_vec_is_set(bb->regs_defined, vreg - 100)) { + bit_vec_set(bb->regs_used, vreg - 100); + } + set_used(c, vreg); } } static void add_pred(basic_block bb, int pred) { - bb->pred_list = realloc(bb->pred_list, (bb->pred_count+1) * sizeof(int)); + bb->pred_list = realloc(bb->pred_list, (bb->pred_count + 1) * sizeof(int)); bb->pred_list[bb->pred_count] = pred; bb->pred_count++; } static void -dump_bb(dill_stream c, struct basic_block *bb, int i) +dump_bb(dill_stream c, struct basic_block* bb, int i) { - int j; - printf("\nBasic block %d, start %d, end %d, label %d, fall %d, branch_to %d\n", - i, bb->start, bb->end, - bb->label, bb->fall_through, - bb->end_branch_label); - printf(" defines :"); dump_reg_vec(bb->regs_defined); - printf("\n uses :"); dump_reg_vec(bb->regs_used); - printf("\n live_at_end :"); dump_reg_vec(bb->live_at_end); - printf("\n succ :"); - for (j=0; j < bb->succ_count; j++) { - printf(" %d", bb->succ_list[j]); - } - printf("\n preds :"); - for (j=0; j < bb->pred_count; j++) { - printf(" %d", bb->pred_list[j]); - } - if (bb->is_loop_start) printf(" - LOOP_START"); - if (bb->is_loop_end) printf(" - LOOP_END"); + size_t j; + printf( + "\nBasic block %d, start %zd, end %zd, label %d, fall %d, branch_to " + "%d\n", + i, bb->start, bb->end, bb->label, bb->fall_through, + bb->end_branch_label); + printf(" defines :"); + dump_reg_vec(bb->regs_defined); + printf("\n uses :"); + dump_reg_vec(bb->regs_used); + printf("\n live_at_end :"); + dump_reg_vec(bb->live_at_end); + printf("\n succ :"); + for (j = 0; j < bb->succ_count; j++) { + printf(" %d", bb->succ_list[j]); + } + printf("\n preds :"); + for (j = 0; j < bb->pred_count; j++) { + printf(" %d", bb->pred_list[j]); + } + if (bb->is_loop_start) + printf(" - LOOP_START"); + if (bb->is_loop_end) + printf(" - LOOP_END"); printf("\n"); - for (j = bb->start; j <= bb->end; j++) { - printf(" %d - ", j); - virtual_print_insn(c, NULL, ((char *)c->p->virtual.code_base) + - j * sizeof(virtual_insn)); - printf("\n"); + for (j = (size_t)bb->start; j <= (size_t)bb->end; j++) { + printf(" %zd - ", j); + virtual_print_insn( + c, NULL, + ((char*)c->p->virtual.code_base) + j * sizeof(virtual_insn)); + printf("\n"); } } @@ -545,8 +521,8 @@ dump_bbs(dill_stream c) { virtual_mach_info vmi = (virtual_mach_info)c->p->mach_info; int i; - for (i=0; i < vmi->bbcount; i++) { - dump_bb(c, &vmi->bblist[i], i); + for (i = 0; i < vmi->bbcount; i++) { + dump_bb(c, &vmi->bblist[i], i); } } @@ -555,13 +531,14 @@ add_regs(bit_vec dest, bit_vec src) { int change = 0; int i, len = dest->len; - if (len > src->len) i = src->len; - for (i=0; i < len; i++) { - char tmp = (dest->vec[i] | src->vec[i]); - if (tmp != dest->vec[i]) { - change = 1; - dest->vec[i] = tmp; - } + if (len > src->len) + i = src->len; + for (i = 0; i < len; i++) { + char tmp = (dest->vec[i] | src->vec[i]); + if (tmp != dest->vec[i]) { + change = 1; + dest->vec[i] = tmp; + } } return change; } @@ -570,9 +547,10 @@ static void remove_regs(bit_vec dest, bit_vec src) { int i, len = dest->len; - if (len > src->len) i = src->len; - for (i=0; i < len; i++) { - dest->vec[i] = (dest->vec[i] & ~src->vec[i]); + if (len > src->len) + i = src->len; + for (i = 0; i < len; i++) { + dest->vec[i] = (dest->vec[i] & ~src->vec[i]); } } @@ -588,77 +566,77 @@ build_live(dill_stream c) virtual_mach_info vmi = (virtual_mach_info)c->p->mach_info; int i, change = 1; bit_vec live_at_begin = new_bit_vec(c->p->vreg_count); - for (i=0; i < vmi->bbcount; i++) { - basic_block bb = &vmi->bblist[i]; - bb->live_at_end = new_bit_vec(c->p->vreg_count); - } - for (i= 0; i < vmi->bbcount; i++) { - basic_block bb = &vmi->bblist[i]; - int j; - for (j = 0 ; j < bb->pred_count; j++) { - /* foreach predecessor add regs we use to preds live_at_end */ - basic_block pred_bb = &vmi->bblist[bb->pred_list[j]]; - (void) add_regs(pred_bb->live_at_end, bb->regs_used); - } + for (i = 0; i < vmi->bbcount; i++) { + basic_block bb = &vmi->bblist[i]; + bb->live_at_end = new_bit_vec(c->p->vreg_count); + } + for (i = 0; i < vmi->bbcount; i++) { + basic_block bb = &vmi->bblist[i]; + int j; + for (j = 0; j < bb->pred_count; j++) { + /* foreach predecessor add regs we use to preds live_at_end */ + basic_block pred_bb = &vmi->bblist[bb->pred_list[j]]; + (void)add_regs(pred_bb->live_at_end, bb->regs_used); + } } while (change) { - /* go through the bbs until live lists stabilize */ - change = 0; - for (i= 0; i < vmi->bbcount; i++) { - basic_block bb = &vmi->bblist[i]; - int j; - - clear_bit_vec(live_at_begin); - add_regs(live_at_begin, bb->live_at_end); - remove_regs(live_at_begin, bb->regs_defined); - for (j = 0 ; j < bb->pred_count; j++) { - /* - * foreach predecessor add regs live at our beginning - * to preds live_at_end - */ - basic_block pred_bb = &vmi->bblist[bb->pred_list[j]]; - change |= add_regs(pred_bb->live_at_end, live_at_begin); - } - } + /* go through the bbs until live lists stabilize */ + change = 0; + for (i = 0; i < vmi->bbcount; i++) { + basic_block bb = &vmi->bblist[i]; + int j; + + clear_bit_vec(live_at_begin); + add_regs(live_at_begin, bb->live_at_end); + remove_regs(live_at_begin, bb->regs_defined); + for (j = 0; j < bb->pred_count; j++) { + /* + * foreach predecessor add regs live at our beginning + * to preds live_at_end + */ + basic_block pred_bb = &vmi->bblist[bb->pred_list[j]]; + change |= add_regs(pred_bb->live_at_end, live_at_begin); + } + } } free(live_at_begin); } static int -insn_defines(virtual_insn *insn) +insn_defines(virtual_insn* insn) { - switch(insn->class_code) { + switch (insn->class_code) { case iclass_arith3: case iclass_compare: - return insn->opnds.a3.dest; + return insn->opnds.a3.dest; case iclass_arith3i: - return insn->opnds.a3i.dest; + return insn->opnds.a3i.dest; case iclass_arith2: - return insn->opnds.a2.dest; + return insn->opnds.a2.dest; case iclass_convert: - return insn->opnds.a2.dest; + return insn->opnds.a2.dest; case iclass_loadstorei: - if (insn->insn_code & 0x10) { - /* store */ - return -1; - } else { - return insn->opnds.a3i.dest; - } + if (insn->insn_code & 0x10) { + /* store */ + return -1; + } else { + return insn->opnds.a3i.dest; + } case iclass_lea: - return insn->opnds.a3i.dest; + return insn->opnds.a3i.dest; case iclass_loadstore: - if (insn->insn_code & 0x10) { - /* store */ - return -1; - } else { - return insn->opnds.a3.dest; - } + if (insn->insn_code & 0x10) { + /* store */ + return -1; + } else { + return insn->opnds.a3.dest; + } case iclass_set: - return insn->opnds.a3i.dest; + return insn->opnds.a3i.dest; case iclass_setf: - return insn->opnds.sf.dest; + return insn->opnds.sf.dest; case iclass_mov: - return insn->opnds.a2.dest; + return insn->opnds.a2.dest; case iclass_reti: case iclass_ret: case iclass_branch: @@ -667,63 +645,62 @@ insn_defines(virtual_insn *insn) case iclass_jump_to_reg: case iclass_jump_to_imm: case iclass_special: - return -1; - case iclass_call: - { - int typ = insn->insn_code & 0xf; - /* put the return register definition in the next bb */ - if (typ != DILL_V) { - return insn->opnds.calli.src; - } - return -1; + return -1; + case iclass_call: { + int typ = insn->insn_code & 0xf; + /* put the return register definition in the next bb */ + if (typ != DILL_V) { + return insn->opnds.calli.src; + } + return -1; } case iclass_push: case iclass_pushi: case iclass_pushf: case iclass_nop: case iclass_mark_label: - return -1; + return -1; default: - assert(0); + assert(0); } return -1; } static int -insn_define_test(virtual_insn *insn, int vreg) +insn_define_test(virtual_insn* insn, int vreg) { - switch(insn->class_code) { + switch (insn->class_code) { case iclass_arith3: case iclass_compare: - return insn->opnds.a3.dest == vreg; + return insn->opnds.a3.dest == vreg; case iclass_arith3i: - return insn->opnds.a3i.dest == vreg; + return insn->opnds.a3i.dest == vreg; case iclass_arith2: - return insn->opnds.a2.dest == vreg; + return insn->opnds.a2.dest == vreg; case iclass_convert: - return insn->opnds.a2.dest == vreg; + return insn->opnds.a2.dest == vreg; case iclass_lea: - return insn->opnds.a3i.dest == vreg; + return insn->opnds.a3i.dest == vreg; case iclass_loadstorei: - if (insn->insn_code & 0x10) { - /* store */ - return 0; - } else { - return insn->opnds.a3i.dest == vreg; - } + if (insn->insn_code & 0x10) { + /* store */ + return 0; + } else { + return insn->opnds.a3i.dest == vreg; + } case iclass_loadstore: - if (insn->insn_code & 0x10) { - /* store */ - return 0; - } else { - return insn->opnds.a3.dest == vreg; - } + if (insn->insn_code & 0x10) { + /* store */ + return 0; + } else { + return insn->opnds.a3.dest == vreg; + } case iclass_set: - return insn->opnds.a3i.dest == vreg; + return insn->opnds.a3i.dest == vreg; case iclass_setf: - return insn->opnds.sf.dest == vreg; + return insn->opnds.sf.dest == vreg; case iclass_mov: - return insn->opnds.a2.dest == vreg; + return insn->opnds.a2.dest == vreg; case iclass_reti: case iclass_ret: case iclass_branch: @@ -732,296 +709,349 @@ insn_define_test(virtual_insn *insn, int vreg) case iclass_jump_to_reg: case iclass_jump_to_imm: case iclass_special: - return 0; - case iclass_call: - { - int typ = insn->insn_code & 0xf; - /* put the return register definition in the next bb */ - if (typ != DILL_V) { - return insn->opnds.calli.src == vreg; - } - return 0; + return 0; + case iclass_call: { + int typ = insn->insn_code & 0xf; + /* put the return register definition in the next bb */ + if (typ != DILL_V) { + return insn->opnds.calli.src == vreg; + } + return 0; } case iclass_push: case iclass_pushi: case iclass_pushf: case iclass_nop: case iclass_mark_label: - return 0; + return 0; default: - assert(0); + assert(0); } return 0; } - static void -insn_uses(virtual_insn *insn, int *used) +insn_uses(virtual_insn* insn, int* used) { used[0] = -1; used[1] = -1; used[2] = -1; - switch(insn->class_code) { + switch (insn->class_code) { case iclass_arith3: case iclass_compare: - used[0] = insn->opnds.a3.src1; - used[1] = insn->opnds.a3.src2; - break; + used[0] = insn->opnds.a3.src1; + used[1] = insn->opnds.a3.src2; + break; case iclass_arith3i: - used[0] = insn->opnds.a3i.src; - break; + used[0] = insn->opnds.a3i.src; + break; case iclass_arith2: - used[0] = insn->opnds.a2.src; - break; + used[0] = insn->opnds.a2.src; + break; case iclass_convert: - used[0] = insn->opnds.a2.src; - break; + used[0] = insn->opnds.a2.src; + break; case iclass_lea: - used[0] = insn->opnds.a3i.src; - break; + used[0] = insn->opnds.a3i.src; + break; case iclass_loadstorei: - used[0] = insn->opnds.a3i.src; - if (insn->insn_code & 0x10) { - /* store */ - used[1] = insn->opnds.a3i.dest; - } - break; + used[0] = insn->opnds.a3i.src; + if (insn->insn_code & 0x10) { + /* store */ + used[1] = insn->opnds.a3i.dest; + } + break; case iclass_loadstore: - used[0] = insn->opnds.a3.src1; - used[1] = insn->opnds.a3.src2; - if (insn->insn_code & 0x10) { - /* store */ - used[2] = insn->opnds.a3.dest; - } - break; + used[0] = insn->opnds.a3.src1; + used[1] = insn->opnds.a3.src2; + if (insn->insn_code & 0x10) { + /* store */ + used[2] = insn->opnds.a3.dest; + } + break; case iclass_set: - break; + break; case iclass_setf: - break; + break; case iclass_mov: - used[0] = insn->opnds.a2.src; - break; + used[0] = insn->opnds.a2.src; + break; case iclass_reti: - break; + break; case iclass_ret: - used[0] = insn->opnds.a1.src; - break; + used[0] = insn->opnds.a1.src; + break; case iclass_branch: - used[0] = insn->opnds.br.src1; - used[1] = insn->opnds.br.src2; - break; + used[0] = insn->opnds.br.src1; + used[1] = insn->opnds.br.src2; + break; case iclass_branchi: - used[0] = insn->opnds.bri.src; - break; + used[0] = insn->opnds.bri.src; + break; case iclass_jump_to_label: - break; + break; case iclass_jump_to_reg: - used[0] = insn->opnds.bri.src; - break; + used[0] = insn->opnds.bri.src; + break; case iclass_jump_to_imm: case iclass_special: - break; + break; case iclass_call: { - int reg = insn->insn_code & 0x10; - if (reg != 0) { - long imm = (long) insn->opnds.calli.imm_l; - int src1_vreg = imm; - used[0] = src1_vreg; - } - break; + int reg = insn->insn_code & 0x10; + if (reg != 0) { + size_t imm = (size_t)insn->opnds.calli.imm_l; + int src1_vreg = (int)imm; + used[0] = src1_vreg; + } + break; } case iclass_push: - if ((short)insn->opnds.a1.src >= 0) - used[0] = insn->opnds.a1.src; - break; + if ((short)insn->opnds.a1.src >= 0) + used[0] = insn->opnds.a1.src; + break; case iclass_pushi: - break; + break; case iclass_pushf: - break; + break; case iclass_nop: - break; + break; } } static void -replace_insn_src(virtual_insn *insn, int replace_vreg, int new_vreg) +replace_insn_src(virtual_insn* insn, int replace_vreg, int new_vreg) { - switch(insn->class_code) { + switch (insn->class_code) { case iclass_arith3: case iclass_compare: - if (replace_vreg == insn->opnds.a3.src1) { - insn->opnds.a3.src1 = new_vreg; return;}; - if (replace_vreg == insn->opnds.a3.src2) { - insn->opnds.a3.src2 = new_vreg; return;}; - break; + if (replace_vreg == insn->opnds.a3.src1) { + insn->opnds.a3.src1 = new_vreg; + return; + }; + if (replace_vreg == insn->opnds.a3.src2) { + insn->opnds.a3.src2 = new_vreg; + return; + }; + break; case iclass_arith3i: - if (replace_vreg == insn->opnds.a3i.src) { - insn->opnds.a3i.src = new_vreg; return;}; - break; + if (replace_vreg == insn->opnds.a3i.src) { + insn->opnds.a3i.src = new_vreg; + return; + }; + break; case iclass_arith2: - if (replace_vreg == insn->opnds.a2.src) { - insn->opnds.a2.src = new_vreg; return;}; - break; + if (replace_vreg == insn->opnds.a2.src) { + insn->opnds.a2.src = new_vreg; + return; + }; + break; case iclass_convert: - if (replace_vreg == insn->opnds.a2.src) { - insn->opnds.a2.src = new_vreg; return;}; - break; + if (replace_vreg == insn->opnds.a2.src) { + insn->opnds.a2.src = new_vreg; + return; + }; + break; case iclass_lea: - if (replace_vreg == insn->opnds.a3i.src) { - insn->opnds.a3i.src = new_vreg; return;}; - break; + if (replace_vreg == insn->opnds.a3i.src) { + insn->opnds.a3i.src = new_vreg; + return; + }; + break; case iclass_loadstorei: - if (replace_vreg == insn->opnds.a3i.src) { - insn->opnds.a3i.src = new_vreg; return;}; - if (insn->insn_code & 0x10) { - /* store */ - if (replace_vreg == insn->opnds.a3i.dest) { - insn->opnds.a3i.dest = new_vreg; return;}; - } - break; + if (replace_vreg == insn->opnds.a3i.src) { + insn->opnds.a3i.src = new_vreg; + return; + }; + if (insn->insn_code & 0x10) { + /* store */ + if (replace_vreg == insn->opnds.a3i.dest) { + insn->opnds.a3i.dest = new_vreg; + return; + }; + } + break; case iclass_loadstore: - if (replace_vreg == insn->opnds.a3.src1) { - insn->opnds.a3.src1 = new_vreg; return;}; - if (replace_vreg == insn->opnds.a3.src2) { - insn->opnds.a3.src2 = new_vreg; return;}; - if (insn->insn_code & 0x10) { - /* store */ - if (replace_vreg == insn->opnds.a3.dest) { - insn->opnds.a3.dest = new_vreg; return;}; - } - break; + if (replace_vreg == insn->opnds.a3.src1) { + insn->opnds.a3.src1 = new_vreg; + return; + }; + if (replace_vreg == insn->opnds.a3.src2) { + insn->opnds.a3.src2 = new_vreg; + return; + }; + if (insn->insn_code & 0x10) { + /* store */ + if (replace_vreg == insn->opnds.a3.dest) { + insn->opnds.a3.dest = new_vreg; + return; + }; + } + break; case iclass_set: - break; + break; case iclass_setf: - break; + break; case iclass_mov: - if (replace_vreg == insn->opnds.a2.src) { - insn->opnds.a2.src = new_vreg; return;}; - break; + if (replace_vreg == insn->opnds.a2.src) { + insn->opnds.a2.src = new_vreg; + return; + }; + break; case iclass_reti: - break; + break; case iclass_ret: - if (replace_vreg == insn->opnds.a1.src) { - insn->opnds.a1.src = new_vreg; return;}; - break; + if (replace_vreg == insn->opnds.a1.src) { + insn->opnds.a1.src = new_vreg; + return; + }; + break; case iclass_branch: - if (replace_vreg == insn->opnds.br.src1) { - insn->opnds.br.src1 = new_vreg; return;}; - if (replace_vreg == insn->opnds.br.src2) { - insn->opnds.br.src2 = new_vreg; return;}; - break; + if (replace_vreg == insn->opnds.br.src1) { + insn->opnds.br.src1 = new_vreg; + return; + }; + if (replace_vreg == insn->opnds.br.src2) { + insn->opnds.br.src2 = new_vreg; + return; + }; + break; case iclass_branchi: - if (replace_vreg == insn->opnds.bri.src) { - insn->opnds.bri.src = new_vreg; return;}; - break; + if (replace_vreg == insn->opnds.bri.src) { + insn->opnds.bri.src = new_vreg; + return; + }; + break; case iclass_jump_to_label: - break; + break; case iclass_jump_to_reg: - if (replace_vreg == insn->opnds.bri.src) { - insn->opnds.bri.src = new_vreg; return;}; - break; + if (replace_vreg == insn->opnds.bri.src) { + insn->opnds.bri.src = new_vreg; + return; + }; + break; case iclass_jump_to_imm: case iclass_special: - break; + break; case iclass_call: - break; + break; case iclass_push: - if ((short)insn->opnds.a1.src >= 0) - if (replace_vreg == insn->opnds.a1.src) { - insn->opnds.a1.src = new_vreg; return;}; - break; + if ((short)insn->opnds.a1.src >= 0) + if (replace_vreg == insn->opnds.a1.src) { + insn->opnds.a1.src = new_vreg; + return; + }; + break; case iclass_pushi: - break; + break; case iclass_pushf: - break; + break; case iclass_nop: - break; + break; } assert(0); } static int -insn_use_test(virtual_insn *insn, int vreg) +insn_use_test(virtual_insn* insn, int vreg) { - switch(insn->class_code) { + switch (insn->class_code) { case iclass_arith3: case iclass_compare: - if (vreg == insn->opnds.a3.src1) return 1; - if (vreg == insn->opnds.a3.src2) return 1; - break; + if (vreg == insn->opnds.a3.src1) + return 1; + if (vreg == insn->opnds.a3.src2) + return 1; + break; case iclass_arith3i: - if (vreg == insn->opnds.a3i.src) return 1; - break; + if (vreg == insn->opnds.a3i.src) + return 1; + break; case iclass_arith2: - if (vreg == insn->opnds.a2.src) return 1; - break; + if (vreg == insn->opnds.a2.src) + return 1; + break; case iclass_convert: - if (vreg == insn->opnds.a2.src) return 1; - break; + if (vreg == insn->opnds.a2.src) + return 1; + break; case iclass_lea: - if (vreg == insn->opnds.a3i.src) return 1; - break; + if (vreg == insn->opnds.a3i.src) + return 1; + break; case iclass_loadstorei: - if (vreg == insn->opnds.a3i.src) return 1; - if (insn->insn_code & 0x10) { - /* store */ - if (vreg == insn->opnds.a3i.dest) return 1; - } - break; + if (vreg == insn->opnds.a3i.src) + return 1; + if (insn->insn_code & 0x10) { + /* store */ + if (vreg == insn->opnds.a3i.dest) + return 1; + } + break; case iclass_loadstore: - if (vreg == insn->opnds.a3.src1) return 1; - if (vreg == insn->opnds.a3.src2) return 1; - if (insn->insn_code & 0x10) { - /* store */ - if (vreg == insn->opnds.a3.dest) return 1; - } - break; + if (vreg == insn->opnds.a3.src1) + return 1; + if (vreg == insn->opnds.a3.src2) + return 1; + if (insn->insn_code & 0x10) { + /* store */ + if (vreg == insn->opnds.a3.dest) + return 1; + } + break; case iclass_set: - break; + break; case iclass_setf: - break; + break; case iclass_mov: - if (vreg == insn->opnds.a2.src) return 1; - break; + if (vreg == insn->opnds.a2.src) + return 1; + break; case iclass_reti: - break; + break; case iclass_ret: - if (vreg == insn->opnds.a1.src) return 1; - break; + if (vreg == insn->opnds.a1.src) + return 1; + break; case iclass_branch: - if (vreg == insn->opnds.br.src1) return 1; - if (vreg == insn->opnds.br.src2) return 1; - break; + if (vreg == insn->opnds.br.src1) + return 1; + if (vreg == insn->opnds.br.src2) + return 1; + break; case iclass_branchi: - if (vreg == insn->opnds.bri.src) return 1; - break; + if (vreg == insn->opnds.bri.src) + return 1; + break; case iclass_jump_to_label: - break; + break; case iclass_jump_to_reg: - if (vreg == insn->opnds.bri.src) return 1; - break; + if (vreg == insn->opnds.bri.src) + return 1; + break; case iclass_jump_to_imm: case iclass_special: - break; - case iclass_call:{ - int reg = insn->insn_code & 0x10; - if (reg != 0) { - long imm = (long) insn->opnds.calli.imm_l; - int src1_vreg = imm; - if (vreg == src1_vreg) return 1; - } - break; + break; + case iclass_call: { + int reg = insn->insn_code & 0x10; + if (reg != 0) { + size_t imm = (size_t)insn->opnds.calli.imm_l; + int src1_vreg = (int)imm; + if (vreg == src1_vreg) + return 1; + } + break; } case iclass_push: - if ((short)insn->opnds.a1.src >= 0) - if (vreg == insn->opnds.a1.src) return 1; - break; + if ((short)insn->opnds.a1.src >= 0) + if (vreg == insn->opnds.a1.src) + return 1; + break; case iclass_pushi: - break; + break; case iclass_pushf: - break; + break; case iclass_nop: - break; + break; } return 0; } @@ -1030,149 +1060,152 @@ static void free_bbs(virtual_mach_info vmi) { int i; - for (i=0 ; i < vmi->bbcount; i++) { - basic_block bb = &vmi->bblist[i]; - if (bb->pred_list) free(bb->pred_list); - if (bb->succ_list) free(bb->succ_list); - free(bb->regs_used); - free(bb->regs_defined); - free(bb->live_at_end); - if (bb->reg_assigns) free(bb->reg_assigns); - } - if (vmi->bblist) free(vmi->bblist); + for (i = 0; i < vmi->bbcount; i++) { + basic_block bb = &vmi->bblist[i]; + if (bb->pred_list) + free(bb->pred_list); + if (bb->succ_list) + free(bb->succ_list); + free(bb->regs_used); + free(bb->regs_defined); + free(bb->live_at_end); + if (bb->reg_assigns) + free(bb->reg_assigns); + } + if (vmi->bblist) + free(vmi->bblist); vmi->bblist = NULL; vmi->bbcount = 0; } static void -build_bb_body(dill_stream c, virtual_insn *insn, int i, virtual_insn *insns) +build_bb_body(dill_stream c, virtual_insn* insn, int i, virtual_insn* insns) { virtual_mach_info vmi = (virtual_mach_info)c->p->mach_info; - basic_block bb = &vmi->bblist[vmi->bbcount]; \ - struct branch_table *t = &c->p->branch_table; + basic_block bb = &vmi->bblist[vmi->bbcount]; + struct branch_table* t = &c->p->branch_table; int j; - switch(insn->class_code) { + switch (insn->class_code) { case iclass_arith3: case iclass_compare: - bb_uses(c, bb, insn->opnds.a3.src1); - bb_uses(c, bb, insn->opnds.a3.src2); - bb_defines(c, bb, insn->opnds.a3.dest); - break; + bb_uses(c, bb, insn->opnds.a3.src1); + bb_uses(c, bb, insn->opnds.a3.src2); + bb_defines(c, bb, insn->opnds.a3.dest); + break; case iclass_arith3i: - bb_uses(c, bb, insn->opnds.a3i.src); - bb_defines(c, bb, insn->opnds.a3i.dest); - break; + bb_uses(c, bb, insn->opnds.a3i.src); + bb_defines(c, bb, insn->opnds.a3i.dest); + break; case iclass_arith2: - bb_uses(c, bb, insn->opnds.a2.src); - bb_defines(c, bb, insn->opnds.a2.dest); - break; + bb_uses(c, bb, insn->opnds.a2.src); + bb_defines(c, bb, insn->opnds.a2.dest); + break; case iclass_convert: - bb_uses(c, bb, insn->opnds.a2.src); - bb_defines(c, bb, insn->opnds.a2.dest); - break; + bb_uses(c, bb, insn->opnds.a2.src); + bb_defines(c, bb, insn->opnds.a2.dest); + break; case iclass_lea: - bb_uses(c, bb, insn->opnds.a3i.src); - bb_defines(c, bb, insn->opnds.a3i.dest); - break; + bb_uses(c, bb, insn->opnds.a3i.src); + bb_defines(c, bb, insn->opnds.a3i.dest); + break; case iclass_loadstorei: - bb_uses(c, bb, insn->opnds.a3i.src); - if (insn->insn_code & 0x10) { - /* store */ - bb_uses(c, bb, insn->opnds.a3i.dest); - } else { - bb_defines(c, bb, insn->opnds.a3i.dest); - } - break; + bb_uses(c, bb, insn->opnds.a3i.src); + if (insn->insn_code & 0x10) { + /* store */ + bb_uses(c, bb, insn->opnds.a3i.dest); + } else { + bb_defines(c, bb, insn->opnds.a3i.dest); + } + break; case iclass_loadstore: - bb_uses(c, bb, insn->opnds.a3.src1); - bb_uses(c, bb, insn->opnds.a3.src2); - if (insn->insn_code & 0x10) { - /* store */ - bb_uses(c, bb, insn->opnds.a3.dest); - } else { - bb_defines(c, bb, insn->opnds.a3.dest); - } - break; + bb_uses(c, bb, insn->opnds.a3.src1); + bb_uses(c, bb, insn->opnds.a3.src2); + if (insn->insn_code & 0x10) { + /* store */ + bb_uses(c, bb, insn->opnds.a3.dest); + } else { + bb_defines(c, bb, insn->opnds.a3.dest); + } + break; case iclass_set: - bb_defines(c, bb, insn->opnds.a3i.dest); - break; + bb_defines(c, bb, insn->opnds.a3i.dest); + break; case iclass_setf: - bb_defines(c, bb, insn->opnds.sf.dest); - break; + bb_defines(c, bb, insn->opnds.sf.dest); + break; case iclass_mov: - bb_uses(c, bb, insn->opnds.a2.src); - bb_defines(c, bb, insn->opnds.a2.dest); - break; + bb_uses(c, bb, insn->opnds.a2.src); + bb_defines(c, bb, insn->opnds.a2.dest); + break; case iclass_reti: - break; + break; case iclass_ret: - bb_uses(c, bb, insn->opnds.a1.src); - break; + bb_uses(c, bb, insn->opnds.a1.src); + break; case iclass_branch: - bb_uses(c, bb, insn->opnds.br.src1); - bb_uses(c, bb, insn->opnds.br.src2); - end_bb(bb, insn->opnds.br.label, 1); - break; + bb_uses(c, bb, insn->opnds.br.src1); + bb_uses(c, bb, insn->opnds.br.src2); + end_bb(bb, insn->opnds.br.label, 1); + break; case iclass_branchi: - bb_uses(c, bb, insn->opnds.bri.src); - end_bb(bb, insn->opnds.bri.label, 1); - break; + bb_uses(c, bb, insn->opnds.bri.src); + end_bb(bb, insn->opnds.bri.label, 1); + break; case iclass_jump_to_label: - end_bb(bb, insn->opnds.br.label, 0); - break; + end_bb(bb, insn->opnds.br.label, 0); + break; case iclass_jump_to_reg: - bb_uses(c, bb, insn->opnds.br.src1); - end_bb(bb, -1, 0); - break; + bb_uses(c, bb, insn->opnds.br.src1); + end_bb(bb, -1, 0); + break; case iclass_jump_to_imm: - end_bb(bb, -1, 0); - break; - case iclass_call: - { - int typ = insn->insn_code & 0xf; - end_bb(bb, -1, 1); - /* put the return register definition in the next bb */ - if (typ != DILL_V) { - bb_defines(c, bb, insn->opnds.calli.src); - } - break; + end_bb(bb, -1, 0); + break; + case iclass_call: { + int typ = insn->insn_code & 0xf; + end_bb(bb, -1, 1); + /* put the return register definition in the next bb */ + if (typ != DILL_V) { + bb_defines(c, bb, insn->opnds.calli.src); + } + break; } case iclass_push: - if ((short)insn->opnds.a1.src >= 0) - bb_uses(c, bb, insn->opnds.a1.src); - break; + if ((short)insn->opnds.a1.src >= 0) + bb_uses(c, bb, insn->opnds.a1.src); + break; case iclass_special: - break; + break; case iclass_pushi: - break; + break; case iclass_pushf: - break; + break; case iclass_nop: case iclass_mark_label: - break; - } - for (j=0; j < t->next_label; j++) { - if ((unsigned)t->label_locs[j] == - ((char*)insn - (char*)insns) + sizeof(virtual_insn)) { - int fall_through = 1; - switch (insns[i-1].class_code) { - case iclass_ret: - case iclass_reti: - fall_through = 0; - default: - break; - } - if (bb->start != i) { - end_bb(bb, -1, fall_through); - } - bb->label = j; - } + break; + } + for (j = 0; j < t->next_label; j++) { + if ((unsigned)t->label_locs[j] == + ((char*)insn - (char*)insns) + sizeof(virtual_insn)) { + int fall_through = 1; + switch (insns[i - 1].class_code) { + case iclass_ret: + case iclass_reti: + fall_through = 0; + default: + break; + } + if (bb->start != i) { + end_bb(bb, -1, fall_through); + } + bb->label = j; + } } } static void -build_bbs(dill_stream c, void *vinsns, void *prefix_begin, void *code_end) +build_bbs(dill_stream c, void* vinsns, void* prefix_begin, void* code_end) { virtual_mach_info vmi = (virtual_mach_info)c->p->mach_info; basic_block bb; @@ -1192,57 +1225,56 @@ build_bbs(dill_stream c, void *vinsns, void *prefix_begin, void *code_end) bb->is_loop_start = 0; bb->is_loop_end = 0; if (prefix_begin < code_end) { - i = ((char*)prefix_begin - (char*)insns)/sizeof(virtual_insn); - bb->start = i; - while((insn = &insns[i++]) < (virtual_insn *)code_end) { - build_bb_body(c, insn, i, insns); - } - bb = &vmi->bblist[vmi->bbcount]; - i -= 1; - end_bb(bb, -1, 1); + i = ((char*)prefix_begin - (char*)insns) / sizeof(virtual_insn); + bb->start = i; + while ((insn = &insns[i++]) < (virtual_insn*)code_end) { + build_bb_body(c, insn, (int)i, insns); + } + bb = &vmi->bblist[vmi->bbcount]; + i -= 1; + end_bb(bb, -1, 1); } i = 0; bb->start = i; - while((insn = &insns[i++]) < (virtual_insn *)prefix_begin) { - build_bb_body(c, insn, i, insns); + while ((insn = &insns[i++]) < (virtual_insn*)prefix_begin) { + build_bb_body(c, insn, (int)i, insns); } bb = &vmi->bblist[vmi->bbcount]; end_bb(bb, -1, 0); free(bb->regs_used); free(bb->regs_defined); - (bb - 1) ->end--; - for (i=0; i < vmi->bbcount; i++) { - basic_block bb = &vmi->bblist[i]; - bb->pred_count = bb->succ_count = 0; - bb->succ_list = malloc(2* sizeof(int)); - bb->pred_list = malloc(sizeof(int)); - bb->reg_assigns = NULL; - } - for (i=0; i < vmi->bbcount; i++) { - basic_block bb = &vmi->bblist[i]; - if (bb->fall_through) { - bb->succ_list[bb->succ_count] = i+1; - bb->succ_count++; - add_pred(&vmi->bblist[i+1], i); - } - if (bb->end_branch_label != -1) { - int j; - for (j=0; j < vmi->bbcount; j++) { - if (vmi->bblist[j].label == bb->end_branch_label) { - bb->succ_list[bb->succ_count] = j; - bb->succ_count++; - add_pred(&vmi->bblist[j], i); - j = vmi->bbcount; - } - } - } + (bb - 1)->end--; + for (i = 0; i < vmi->bbcount; i++) { + basic_block bb = &vmi->bblist[i]; + bb->pred_count = bb->succ_count = 0; + bb->succ_list = malloc(2 * sizeof(int)); + bb->pred_list = malloc(sizeof(int)); + bb->reg_assigns = NULL; + } + for (i = 0; i < vmi->bbcount; i++) { + basic_block bb = &vmi->bblist[i]; + if (bb->fall_through) { + bb->succ_list[bb->succ_count] = (int)i + 1; + bb->succ_count++; + add_pred(&vmi->bblist[i + 1], (int)i); + } + if (bb->end_branch_label != -1) { + int j; + for (j = 0; j < vmi->bbcount; j++) { + if (vmi->bblist[j].label == bb->end_branch_label) { + bb->succ_list[bb->succ_count] = j; + bb->succ_count++; + add_pred(&vmi->bblist[j], (int)i); + j = vmi->bbcount; + } + } + } } build_live(c); -/* calculate_depth(c);*/ + /* calculate_depth(c);*/ } - -typedef void (*bv_func)(int bit, void *p1, void *p2); +typedef void (*bv_func)(int bit, void* p1, void* p2); static void do_reg_assign(int bit, basic_block bb, dill_stream c) @@ -1250,282 +1282,284 @@ do_reg_assign(int bit, basic_block bb, dill_stream c) /* no local preg for live registers */ int preg; if ((c->p->vregs[bit].use_info.use_count == 0) && - (c->p->vregs[bit].use_info.def_count == 0)) { - if (c->dill_debug) - printf("virtual reg %d optimized away\n", bit + 100); - return; + (c->p->vregs[bit].use_info.def_count == 0)) { + if (c->dill_debug) + printf("virtual reg %d optimized away\n", bit + 100); + return; } if (bit_vec_is_set(bb->live_at_end, bit)) { - c->p->vregs[bit].need_assign = 1; - return; + c->p->vregs[bit].need_assign = 1; + return; } if (dill_raw_getreg(c, &preg, c->p->vregs[bit].typ, DILL_VAR) == 0) { - c->p->vregs[bit].need_assign = 1; - bb->reg_assigns[bit] = -1; - if (c->dill_debug) - printf("No more tmp regs for virtual reg %d\n", bit + 100); + c->p->vregs[bit].need_assign = 1; + bb->reg_assigns[bit] = -1; + if (c->dill_debug) + printf("No more tmp regs for virtual reg %d\n", bit + 100); } else { - bb->reg_assigns[bit] = preg; - if (c->dill_debug) - printf("virtual reg %d assigned to preg %d\n", - bit + 100, bb->reg_assigns[bit]); + bb->reg_assigns[bit] = preg; + if (c->dill_debug) + printf("virtual reg %d assigned to preg %d\n", bit + 100, + bb->reg_assigns[bit]); } } static void -do_use_def_count(dill_stream c, basic_block bb, virtual_insn *insns, int loc) +do_use_def_count(dill_stream c, basic_block bb, virtual_insn* insns, int loc) { - virtual_insn *insn = &((virtual_insn *)insns)[loc]; - switch(insn->class_code) { + virtual_insn* insn = &((virtual_insn*)insns)[loc]; + switch (insn->class_code) { case iclass_arith3: case iclass_compare: - set_used(c, insn->opnds.a3.src1); - set_used(c, insn->opnds.a3.src2); - set_defined(c, insn->opnds.a3.dest); - break; + set_used(c, insn->opnds.a3.src1); + set_used(c, insn->opnds.a3.src2); + set_defined(c, insn->opnds.a3.dest); + break; case iclass_arith3i: - set_used(c, insn->opnds.a3i.src); - set_defined(c, insn->opnds.a3i.dest); - break; + set_used(c, insn->opnds.a3i.src); + set_defined(c, insn->opnds.a3i.dest); + break; case iclass_arith2: - set_used(c, insn->opnds.a2.src); - set_defined(c, insn->opnds.a2.dest); - break; + set_used(c, insn->opnds.a2.src); + set_defined(c, insn->opnds.a2.dest); + break; case iclass_convert: - set_used(c, insn->opnds.a2.src); - set_defined(c, insn->opnds.a2.dest); - break; + set_used(c, insn->opnds.a2.src); + set_defined(c, insn->opnds.a2.dest); + break; case iclass_lea: - set_used(c, insn->opnds.a3i.src); - set_defined(c, insn->opnds.a3i.dest); - break; + set_used(c, insn->opnds.a3i.src); + set_defined(c, insn->opnds.a3i.dest); + break; case iclass_loadstorei: - set_used(c, insn->opnds.a3i.src); - if (insn->insn_code & 0x10) { - /* store */ - set_used(c, insn->opnds.a3i.dest); - } else { - set_defined(c, insn->opnds.a3i.dest); - } - break; + set_used(c, insn->opnds.a3i.src); + if (insn->insn_code & 0x10) { + /* store */ + set_used(c, insn->opnds.a3i.dest); + } else { + set_defined(c, insn->opnds.a3i.dest); + } + break; case iclass_loadstore: - set_used(c, insn->opnds.a3.src1); - set_used(c, insn->opnds.a3.src2); - if (insn->insn_code & 0x10) { - /* store */ - set_used(c, insn->opnds.a3.dest); - } else { - set_defined(c, insn->opnds.a3.dest); - } - break; + set_used(c, insn->opnds.a3.src1); + set_used(c, insn->opnds.a3.src2); + if (insn->insn_code & 0x10) { + /* store */ + set_used(c, insn->opnds.a3.dest); + } else { + set_defined(c, insn->opnds.a3.dest); + } + break; case iclass_set: - set_defined(c, insn->opnds.a3i.dest); - break; + set_defined(c, insn->opnds.a3i.dest); + break; case iclass_setf: - set_defined(c, insn->opnds.sf.dest); - break; + set_defined(c, insn->opnds.sf.dest); + break; case iclass_mov: - set_used(c, insn->opnds.a2.src); - set_defined(c, insn->opnds.a2.dest); - break; + set_used(c, insn->opnds.a2.src); + set_defined(c, insn->opnds.a2.dest); + break; case iclass_reti: - break; + break; case iclass_ret: - set_used(c, insn->opnds.a1.src); - break; + set_used(c, insn->opnds.a1.src); + break; case iclass_branch: - set_used(c, insn->opnds.br.src1); - set_used(c, insn->opnds.br.src2); - break; + set_used(c, insn->opnds.br.src1); + set_used(c, insn->opnds.br.src2); + break; case iclass_branchi: - set_used(c, insn->opnds.bri.src); - break; + set_used(c, insn->opnds.bri.src); + break; case iclass_jump_to_label: - break; + break; case iclass_jump_to_reg: - set_used(c, insn->opnds.br.src1); - break; + set_used(c, insn->opnds.br.src1); + break; case iclass_jump_to_imm: - break; + break; case iclass_special: - break; + break; case iclass_call: { - int reg = insn->insn_code & 0x10; - if ((insn->insn_code & 0xf) != DILL_V) { - set_defined(c, insn->opnds.calli.src); - } - if (reg != 0) { - long imm = (long)insn->opnds.calli.imm_l; - int src1_vreg = imm; - set_used(c, src1_vreg); - } - break; + int reg = insn->insn_code & 0x10; + if ((insn->insn_code & 0xf) != DILL_V) { + set_defined(c, insn->opnds.calli.src); + } + if (reg != 0) { + size_t imm = (size_t)insn->opnds.calli.imm_l; + int src1_vreg = (int)imm; + set_used(c, src1_vreg); + } + break; } case iclass_push: - if ((short)insn->opnds.a1.src >= 0) - set_used(c, insn->opnds.a1.src); - break; + if ((short)insn->opnds.a1.src >= 0) + set_used(c, insn->opnds.a1.src); + break; case iclass_pushi: - break; + break; case iclass_pushf: - break; + break; case iclass_nop: - break; + break; } } static void -reset_use_def_count(dill_stream c, virtual_insn *insns, virtual_mach_info vmi) +reset_use_def_count(dill_stream c, virtual_insn* insns, virtual_mach_info vmi) { - int i; - for(i=0; i< c->p->vreg_count; i++) { - c->p->vregs[i].use_info.use_count = 0; - c->p->vregs[i].use_info.def_count = 0; + for (i = 0; i < c->p->vreg_count; i++) { + c->p->vregs[i].use_info.use_count = 0; + c->p->vregs[i].use_info.def_count = 0; } - for(i=0; i < c->p->c_param_count; i++) { - c->p->c_param_args[i].used = 0; + for (i = 0; i < c->p->c_param_count; i++) { + c->p->c_param_args[i].used = 0; } apply_to_each(c, insns, vmi, do_use_def_count); } - + void -foreach_bit(bit_vec v, bv_func func, void *p1, void *p2) +foreach_bit(bit_vec v, bv_func func, void* p1, void* p2) { int i; - for (i=0; i< v->len; i++) { - int j; - for (j = 0; j < 2; j++) { - unsigned char nibble = (v->vec[i] >> (j * 4)) & 0xf; - switch(nibble) { - case 0xf: - func(i * 8 + j * 4 + 3, p1, p2); - func(i * 8 + j * 4 + 2, p1, p2); - func(i * 8 + j * 4 + 1, p1, p2); - func(i * 8 + j * 4 + 0, p1, p2); - break; - case 0xe: - func(i * 8 + j * 4 + 3, p1, p2); - func(i * 8 + j * 4 + 2, p1, p2); - func(i * 8 + j * 4 + 1, p1, p2); - break; - case 0xd: - func(i * 8 + j * 4 + 3, p1, p2); - func(i * 8 + j * 4 + 2, p1, p2); - func(i * 8 + j * 4 + 0, p1, p2); - break; - case 0xc: - func(i * 8 + j * 4 + 3, p1, p2); - func(i * 8 + j * 4 + 2, p1, p2); - break; - case 0xb: - func(i * 8 + j * 4 + 3, p1, p2); - func(i * 8 + j * 4 + 1, p1, p2); - func(i * 8 + j * 4 + 0, p1, p2); - break; - case 0xa: - func(i * 8 + j * 4 + 3, p1, p2); - func(i * 8 + j * 4 + 1, p1, p2); - break; - case 0x9: - func(i * 8 + j * 4 + 3, p1, p2); - func(i * 8 + j * 4 + 0, p1, p2); - break; - case 0x8: - func(i * 8 + j * 4 + 3, p1, p2); - break; - case 0x7: - func(i * 8 + j * 4 + 2, p1, p2); - func(i * 8 + j * 4 + 1, p1, p2); - func(i * 8 + j * 4 + 0, p1, p2); - break; - case 0x6: - func(i * 8 + j * 4 + 2, p1, p2); - func(i * 8 + j * 4 + 1, p1, p2); - break; - case 0x5: - func(i * 8 + j * 4 + 2, p1, p2); - func(i * 8 + j * 4 + 0, p1, p2); - break; - case 0x4: - func(i * 8 + j * 4 + 2, p1, p2); - break; - case 0x3: - func(i * 8 + j * 4 + 1, p1, p2); - func(i * 8 + j * 4 + 0, p1, p2); - break; - case 0x2: - func(i * 8 + j * 4 + 1, p1, p2); - break; - case 0x1: - func(i * 8 + j * 4 + 0, p1, p2); - break; - case 0x0: - break; - } - } + for (i = 0; i < v->len; i++) { + int j; + for (j = 0; j < 2; j++) { + unsigned char nibble = (v->vec[i] >> (j * 4)) & 0xf; + switch (nibble) { + case 0xf: + func(i * 8 + j * 4 + 3, p1, p2); + func(i * 8 + j * 4 + 2, p1, p2); + func(i * 8 + j * 4 + 1, p1, p2); + func(i * 8 + j * 4 + 0, p1, p2); + break; + case 0xe: + func(i * 8 + j * 4 + 3, p1, p2); + func(i * 8 + j * 4 + 2, p1, p2); + func(i * 8 + j * 4 + 1, p1, p2); + break; + case 0xd: + func(i * 8 + j * 4 + 3, p1, p2); + func(i * 8 + j * 4 + 2, p1, p2); + func(i * 8 + j * 4 + 0, p1, p2); + break; + case 0xc: + func(i * 8 + j * 4 + 3, p1, p2); + func(i * 8 + j * 4 + 2, p1, p2); + break; + case 0xb: + func(i * 8 + j * 4 + 3, p1, p2); + func(i * 8 + j * 4 + 1, p1, p2); + func(i * 8 + j * 4 + 0, p1, p2); + break; + case 0xa: + func(i * 8 + j * 4 + 3, p1, p2); + func(i * 8 + j * 4 + 1, p1, p2); + break; + case 0x9: + func(i * 8 + j * 4 + 3, p1, p2); + func(i * 8 + j * 4 + 0, p1, p2); + break; + case 0x8: + func(i * 8 + j * 4 + 3, p1, p2); + break; + case 0x7: + func(i * 8 + j * 4 + 2, p1, p2); + func(i * 8 + j * 4 + 1, p1, p2); + func(i * 8 + j * 4 + 0, p1, p2); + break; + case 0x6: + func(i * 8 + j * 4 + 2, p1, p2); + func(i * 8 + j * 4 + 1, p1, p2); + break; + case 0x5: + func(i * 8 + j * 4 + 2, p1, p2); + func(i * 8 + j * 4 + 0, p1, p2); + break; + case 0x4: + func(i * 8 + j * 4 + 2, p1, p2); + break; + case 0x3: + func(i * 8 + j * 4 + 1, p1, p2); + func(i * 8 + j * 4 + 0, p1, p2); + break; + case 0x2: + func(i * 8 + j * 4 + 1, p1, p2); + break; + case 0x1: + func(i * 8 + j * 4 + 0, p1, p2); + break; + case 0x0: + break; + } + } } } static void -do_register_assign(dill_stream c, void *insns, void *code_end, int vlp, - virtual_mach_info vmi) +do_register_assign(dill_stream c, + void* insns, + void* code_end, + int vlp, + virtual_mach_info vmi) { int i; int itmpa, itmpb, dtmpa, dtmpb; if ((dill_raw_getreg(c, &itmpa, DILL_L, DILL_TEMP) == 0) || - (dill_raw_getreg(c, &itmpb, DILL_L, DILL_TEMP) == 0)) { - fprintf(stderr, "Failure to get temporary regs in register assign\n"); + (dill_raw_getreg(c, &itmpb, DILL_L, DILL_TEMP) == 0)) { + fprintf(stderr, "Failure to get temporary regs in register assign\n"); } dill_raw_getreg(c, &dtmpa, DILL_D, DILL_TEMP); dill_raw_getreg(c, &dtmpb, DILL_D, DILL_TEMP); - for (i=0; i< DILL_B; i++) { - switch(i) { - case DILL_D: - case DILL_F: - c->p->v_tmps[i][0] = dtmpa; - c->p->v_tmps[i][1] = dtmpb; - c->p->v_tmps[i][2] = dtmpa; - break; - default: - c->p->v_tmps[i][0] = itmpa; - c->p->v_tmps[i][1] = itmpb; - c->p->v_tmps[i][2] = c->p->machine_strr_tmp_reg; - break; - } - } - - for (i= 0; i < vmi->bbcount; i++) { - basic_block bb = &vmi->bblist[i]; - int j; - bb->reg_assigns = malloc(sizeof(short) * c->p->vreg_count); - memset(bb->reg_assigns, 0xff, sizeof(short) * c->p->vreg_count); - foreach_bit(bb->regs_defined, (bv_func) do_reg_assign, bb, c); - for (j = 0 ; j < c->p->vreg_count; j++) { - if (bb->reg_assigns[j] != -1) { - dill_raw_putreg(c, bb->reg_assigns[j], c->p->vregs[j].typ); - } - } - } - - for(i=0; i< c->p->vreg_count; i++) { - if (i == (vlp - 100) ) { - c->p->vregs[i].preg = c->dill_local_pointer; - c->p->vregs[i].offset = 0; - } else if (c->p->vregs[i].typ == DILL_B) { - /* block, size stored in offset value */ - int size = c->p->vregs[i].offset; - c->p->vregs[i].preg = -1; - c->p->vregs[i].offset = dill_localb(c, size); - } else { - c->p->vregs[i].preg = -1; - if (c->p->vregs[i].typ != DILL_V) { - c->p->vregs[i].offset = dill_local(c, c->p->vregs[i].typ); - } else { - printf("internal void register error\n"); - } - } + for (i = 0; i < DILL_B; i++) { + switch (i) { + case DILL_D: + case DILL_F: + c->p->v_tmps[i][0] = dtmpa; + c->p->v_tmps[i][1] = dtmpb; + c->p->v_tmps[i][2] = dtmpa; + break; + default: + c->p->v_tmps[i][0] = itmpa; + c->p->v_tmps[i][1] = itmpb; + c->p->v_tmps[i][2] = c->p->machine_strr_tmp_reg; + break; + } + } + + for (i = 0; i < vmi->bbcount; i++) { + basic_block bb = &vmi->bblist[i]; + int j; + bb->reg_assigns = malloc(sizeof(short) * c->p->vreg_count); + memset(bb->reg_assigns, 0xff, sizeof(short) * c->p->vreg_count); + foreach_bit(bb->regs_defined, (bv_func)do_reg_assign, bb, c); + for (j = 0; j < c->p->vreg_count; j++) { + if (bb->reg_assigns[j] != -1) { + dill_raw_putreg(c, bb->reg_assigns[j], c->p->vregs[j].typ); + } + } + } + + for (i = 0; i < c->p->vreg_count; i++) { + if (i == (vlp - 100)) { + c->p->vregs[i].preg = c->dill_local_pointer; + c->p->vregs[i].offset = 0; + } else if (c->p->vregs[i].typ == DILL_B) { + /* block, size stored in offset value */ + int size = c->p->vregs[i].offset; + c->p->vregs[i].preg = -1; + c->p->vregs[i].offset = dill_localb(c, size); + } else { + c->p->vregs[i].preg = -1; + if (c->p->vregs[i].typ != DILL_V) { + c->p->vregs[i].offset = dill_local(c, c->p->vregs[i].typ); + } else { + printf("internal void register error\n"); + } + } } } @@ -1533,17 +1567,17 @@ static int preg_of(dill_stream c, basic_block bb, int vreg) { if (vreg >= 100) { - if (bb->reg_assigns[vreg - 100] == -1) { - return c->p->vregs[vreg - 100].preg; - } else { - return bb->reg_assigns[vreg - 100]; - } + if (bb->reg_assigns[vreg - 100] == -1) { + return c->p->vregs[vreg - 100].preg; + } else { + return bb->reg_assigns[vreg - 100]; + } } else { - /* parameter */; - if (c->p->c_param_args[vreg].is_register) { - return c->p->c_param_args[vreg].in_reg; - } - return -1; + /* parameter */; + if (c->p->c_param_args[vreg].is_register) { + return c->p->c_param_args[vreg].in_reg; + } + return -1; } } @@ -1551,10 +1585,10 @@ static int offset_of(dill_stream c, int vreg) { if (vreg >= 100) { - return c->p->vregs[vreg - 100].offset; + return c->p->vregs[vreg - 100].offset; } else { - /* parameter */; - return c->p->c_param_args[vreg].offset; + /* parameter */; + return c->p->c_param_args[vreg].offset; } } @@ -1562,12 +1596,14 @@ extern void dill_virtual_lea(dill_stream c, int dest, int src) { if (src < 100) { - printf("error, attempt to do dill_virtual_lea on non-virtual\n"); - return; + printf("error, attempt to do dill_virtual_lea on non-virtual\n"); + return; } if (dill_type_of(c, src) != DILL_B) { - printf("error, attempt to do dill_virtual_lea on variable of type other than V_B\n"); - return; + printf( + "error, attempt to do dill_virtual_lea on variable of type other " + "than V_B\n"); + return; } dill_lea(c, dest, src, 0); } @@ -1586,12 +1622,12 @@ load_oprnd(dill_stream c, int tmp_num, int vreg) int typ = dill_type_of(c, vreg); int tmp = c->p->v_tmps[typ][tmp_num]; if (vreg >= 100) { - c->j->loadi(c, typ, 0, tmp, c->dill_local_pointer, offset); + c->j->loadi(c, typ, 0, tmp, c->dill_local_pointer, offset); } else { - c->j->loadi(c, typ, 0, tmp, c->dill_param_reg_pointer, offset); + c->j->loadi(c, typ, 0, tmp, c->dill_param_reg_pointer, offset); } return tmp; -} +} static int is_commutative(int insn_code) @@ -1604,7 +1640,7 @@ is_commutative(int insn_code) case dill_jmp_addp: case dill_jmp_addf: case dill_jmp_addd: - return 1; + return 1; case dill_jmp_subi: case dill_jmp_subu: case dill_jmp_subul: @@ -1612,14 +1648,14 @@ is_commutative(int insn_code) case dill_jmp_subp: case dill_jmp_subf: case dill_jmp_subd: - return 0; + return 0; case dill_jmp_muli: case dill_jmp_mulu: case dill_jmp_mulul: case dill_jmp_mull: case dill_jmp_mulf: case dill_jmp_muld: - return 1; + return 1; case dill_jmp_divi: case dill_jmp_divu: case dill_jmp_divul: @@ -1630,7 +1666,7 @@ is_commutative(int insn_code) case dill_jmp_modu: case dill_jmp_modul: case dill_jmp_modl: - return 0; + return 0; case dill_jmp_xori: case dill_jmp_xoru: case dill_jmp_xorul: @@ -1643,7 +1679,7 @@ is_commutative(int insn_code) case dill_jmp_oru: case dill_jmp_orul: case dill_jmp_orl: - return 1; + return 1; case dill_jmp_lshi: case dill_jmp_lshu: case dill_jmp_lshul: @@ -1652,16 +1688,16 @@ is_commutative(int insn_code) case dill_jmp_rshu: case dill_jmp_rshul: case dill_jmp_rshl: - return 0; + return 0; default: - printf("Unknown opcode in is_commutative\n"); - return 0; + printf("Unknown opcode in is_commutative\n"); + return 0; } } static int is_compare_commutative(int insn_code) { - switch(insn_code) { + switch (insn_code) { case dill_jmp_ceqi: case dill_jmp_cequ: case dill_jmp_cequl: @@ -1669,7 +1705,7 @@ is_compare_commutative(int insn_code) case dill_jmp_ceqp: case dill_jmp_ceqd: case dill_jmp_ceqf: - return 1; + return 1; case dill_jmp_cgei: case dill_jmp_cgeu: case dill_jmp_cgeul: @@ -1698,7 +1734,7 @@ is_compare_commutative(int insn_code) case dill_jmp_cltp: case dill_jmp_cltd: case dill_jmp_cltf: - return 0; + return 0; case dill_jmp_cnei: case dill_jmp_cneu: case dill_jmp_cneul: @@ -1706,10 +1742,10 @@ is_compare_commutative(int insn_code) case dill_jmp_cnep: case dill_jmp_cned: case dill_jmp_cnef: - return 1; + return 1; default: - printf("Unknown opcode in is_compare_commutative\n"); - return 0; + printf("Unknown opcode in is_compare_commutative\n"); + return 0; } } @@ -1720,25 +1756,26 @@ store_oprnd(dill_stream c, int tmp_num, int vreg) int typ = dill_type_of(c, vreg); int tmp = c->p->v_tmps[typ][tmp_num]; if (vreg >= 100) { - c->j->storei(c, typ, 0, tmp, c->dill_local_pointer, offset); + c->j->storei(c, typ, 0, tmp, c->dill_local_pointer, offset); } else { - c->j->storei(c, typ, 0, tmp, c->dill_param_reg_pointer, offset); + c->j->storei(c, typ, 0, tmp, c->dill_param_reg_pointer, offset); } return tmp; -} +} typedef struct label_translation { int old_location; int old_label; int new_label; -} *label_translation_table; +} * label_translation_table; static int get_new_label(int old_label, label_translation_table ltable) { while (ltable->old_label != -1) { - if (ltable->old_label == old_label) return ltable->new_label; - ltable++; + if (ltable->old_label == old_label) + return ltable->new_label; + ltable++; } printf("New label not found\n"); return -1; @@ -1748,7 +1785,8 @@ static void emit_getreg(int bit, basic_block bb, dill_stream c) { if (bb->reg_assigns[bit] != -1) { - dill_dealloc_specific(c, bb->reg_assigns[bit], c->p->vregs[bit].typ, DILL_VAR); + dill_dealloc_specific(c, bb->reg_assigns[bit], c->p->vregs[bit].typ, + DILL_VAR); } } @@ -1756,773 +1794,771 @@ static void emit_putreg(int bit, basic_block bb, dill_stream c) { if (bb->reg_assigns[bit] != -1) { - dill_raw_putreg(c, bb->reg_assigns[bit], c->p->vregs[bit].typ); + dill_raw_putreg(c, bb->reg_assigns[bit], c->p->vregs[bit].typ); } } static int count_verbose = -1; static void -emit_insns(dill_stream c, void *insns, label_translation_table ltable, - virtual_mach_info vmi) +emit_insns(dill_stream c, + void* insns, + label_translation_table ltable, + virtual_mach_info vmi) { int label_xlate = 0; - int i, j = 0; - virtual_insn *ip; + size_t i, j = 0; + virtual_insn* ip; if (count_verbose == -1) { - count_verbose = (getenv ("DILL_COUNTS") != NULL); + count_verbose = (getenv("DILL_COUNTS") != NULL); } for (i = 0; i < vmi->bbcount; i++) { - basic_block bb = &vmi->bblist[i]; - int last_dest_vreg = -1; - int last_store_loc = 0; - int insn_start = (int)((char*)c->p->cur_ip - (char *)c->p->code_base); - int insn_count = bb->end - bb->start; - foreach_bit(bb->regs_defined, (bv_func) emit_getreg, bb, c); - for (j = bb->start; j <= bb->end; j++) { - int loc; - ip = &((virtual_insn *)insns)[j]; - loc = (int)((char*)ip - (char*)insns); - while ((loc != 0) && (ltable[label_xlate].old_location == loc)) { - dill_mark_label(c, ltable[label_xlate].new_label); - label_xlate++; - } - if (c->dill_debug) { - printf(" v "); - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - switch(ip->class_code) { - case iclass_arith3: { - /* arith 3 operand integer insns */ - int dest_vreg = ip->opnds.a3.dest; - int src1_vreg = ip->opnds.a3.src1; - int src2_vreg = ip->opnds.a3.src2; - int dest_preg; - int src1_preg; - int src2_preg; - int insn_code = ip->insn_code; - if ((last_dest_vreg == src2_vreg) && - is_commutative(insn_code)) { - /* we only optimize opnd1, switch them */ - src1_vreg = ip->opnds.a3.src2; - src2_vreg = ip->opnds.a3.src1; - } - dest_preg = preg_of(c, bb, dest_vreg); - src1_preg = preg_of(c, bb, src1_vreg); - src2_preg = preg_of(c, bb, src2_vreg); - if (src1_preg == -1) { - /* load src1 */ - if ((last_dest_vreg == src1_vreg) && - (tmp_for_vreg(c, 0, src1_vreg) != -1)) { - if (has_single_def_use(c, src1_vreg)) { - if (c->dill_debug) { - printf(" -- Eliminating previous store -- \n"); - } - c->p->cur_ip = (char*)c->p->code_base + last_store_loc; - } - src1_preg = tmp_for_vreg(c, 0, src1_vreg); - } else { - src1_preg = load_oprnd(c, 0, src1_vreg); - } - } - if (src2_preg == -1) { - /* load src2 */ - src2_preg = load_oprnd(c, 1, src2_vreg); - } - if (dest_preg == -1) { - dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; - } - ( c->j->jmp_a3)[insn_code](c, - c->j->a3_data[insn_code].data1, - c->j->a3_data[insn_code].data2, - dest_preg, src1_preg, src2_preg); - if (preg_of(c, bb, dest_vreg) == -1) { - /* no dest reg, store result */ - last_store_loc = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); - store_oprnd(c, 0, dest_vreg); - last_dest_vreg = dest_vreg; - } else { - last_dest_vreg = -1; - } - } - break; - case iclass_compare: { - /* compare 3 operand insns */ - int dest_vreg = ip->opnds.a3.dest; - int src1_vreg = ip->opnds.a3.src1; - int src2_vreg = ip->opnds.a3.src2; - int dest_preg; - int src1_preg; - int src2_preg; - int insn_code = ip->insn_code; - if ((last_dest_vreg == src2_vreg) && - is_compare_commutative(insn_code)) { - /* we only optimize opnd1, switch them */ - src1_vreg = ip->opnds.a3.src2; - src2_vreg = ip->opnds.a3.src1; - } - dest_preg = preg_of(c, bb, dest_vreg); - src1_preg = preg_of(c, bb, src1_vreg); - src2_preg = preg_of(c, bb, src2_vreg); - if (src1_preg == -1) { - /* load src1 */ - if ((last_dest_vreg == src1_vreg) && - (tmp_for_vreg(c, 0, src1_vreg) != -1)) { - if (has_single_def_use(c, src1_vreg)) { - if (c->dill_debug) { - printf(" -- Eliminating previous store -- \n"); - } - c->p->cur_ip = (char*)c->p->code_base + last_store_loc; - } - src1_preg = tmp_for_vreg(c, 0, src1_vreg); - } else { - src1_preg = load_oprnd(c, 0, src1_vreg); - } - } - if (src2_preg == -1) { - /* load src2 */ - src2_preg = load_oprnd(c, 1, src2_vreg); - } - if (dest_preg == -1) { - dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; - } - ( c->j->jmp_c)[insn_code](c, - c->j->c_data[insn_code].data1, - c->j->c_data[insn_code].data2, - dest_preg, src1_preg, src2_preg); - if (preg_of(c, bb, dest_vreg) == -1) { - /* no dest reg, store result */ - last_store_loc = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); - store_oprnd(c, 0, dest_vreg); - last_dest_vreg = dest_vreg; - } else { - last_dest_vreg = -1; - } - } - break; - case iclass_arith2: { - /* arith 2 operand integer insns */ - int dest_vreg = ip->opnds.a2.dest; - int src_vreg = ip->opnds.a2.src; - int dest_preg = preg_of(c, bb, dest_vreg); - int src_preg = preg_of(c, bb, src_vreg); - int insn_code = ip->insn_code; - if (src_preg == -1) { - /* load src */ - if ((last_dest_vreg == src_vreg) && - (tmp_for_vreg(c, 0, src_vreg) != -1)) { - if (has_single_def_use(c, src_vreg)) { - if (c->dill_debug) { - printf(" -- Eliminating previous store -- \n"); - } - c->p->cur_ip = (char*)c->p->code_base + last_store_loc; - } - src_preg = tmp_for_vreg(c, 0, src_vreg); - } else { - src_preg = load_oprnd(c, 0, src_vreg); - } - } - if (dest_preg == -1) { - dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; - } - ( c->j->jmp_a2)[insn_code](c, - c->j->a2_data[insn_code].data1, - c->j->a2_data[insn_code].data2, - dest_preg, src_preg); - if (preg_of(c, bb, dest_vreg) == -1) { - /* no dest reg, store result */ - last_store_loc = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); - store_oprnd(c, 0, dest_vreg); - last_dest_vreg = dest_vreg; - } else { - last_dest_vreg = -1; - } - } - break; - case iclass_arith3i: - { - /* arith 3 immediate operand integer insns */ - int dest_vreg = ip->opnds.a3i.dest; - int src_vreg = ip->opnds.a3i.src; - intptr_t imm = ip->opnds.a3i.u.imm; - int dest_preg = preg_of(c, bb, dest_vreg); - int src_preg = preg_of(c, bb, src_vreg); - int insn_code = ip->insn_code; - if (src_preg == -1) { - /* load src */ - if ((last_dest_vreg == src_vreg) && - (tmp_for_vreg(c, 0, src_vreg) != -1)) { - if (has_single_def_use(c, src_vreg)) { - if (c->dill_debug) { - printf(" -- Eliminating previous store -- \n"); - } - c->p->cur_ip = (char*)c->p->code_base + last_store_loc; - } - src_preg = tmp_for_vreg(c, 0, src_vreg); - } else { - src_preg = load_oprnd(c, 0, src_vreg); - } - } - if (dest_preg == -1) { - dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; - } - ( c->j->jmp_a3i)[insn_code](c, - c->j->a3i_data[insn_code].data1, - c->j->a3i_data[insn_code].data2, - dest_preg, src_preg, imm); - if (preg_of(c, bb, dest_vreg) == -1) { - /* no dest reg, store result */ - last_store_loc = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); - store_oprnd(c, 0, dest_vreg); - last_dest_vreg = dest_vreg; - } else { - last_dest_vreg = -1; - } - } - break; - case iclass_ret:{ - /* arith operand integer insns */ - int src_vreg = ip->opnds.a1.src; - int src_preg = preg_of(c, bb, src_vreg); - if (src_preg == -1) { - /* load src */ - if ((last_dest_vreg == src_vreg) && - (tmp_for_vreg(c, 0, src_vreg) != -1)) { - if (has_single_def_use(c, src_vreg)) { - if (c->dill_debug) { - printf(" -- Eliminating previous store -- \n"); - } - c->p->cur_ip = (char*)c->p->code_base + last_store_loc; - } - src_preg = tmp_for_vreg(c, 0, src_vreg); - } else { - src_preg = load_oprnd(c, 0, src_vreg); - } - } - ( c->j->ret)(c, ip->insn_code, 0, src_preg); - last_dest_vreg = -1; - } - break; - case iclass_convert: { - /* conversion insns */ - int dest_vreg = ip->opnds.a2.dest; - int src_vreg = ip->opnds.a2.src; - int dest_preg = preg_of(c, bb, dest_vreg); - int src_preg = preg_of(c, bb, src_vreg); - int from_type = (ip->insn_code >> 4) & 0xf; - int to_type = ip->insn_code & 0xf; - if (src_preg == -1) { - /* load src */ - if ((last_dest_vreg == src_vreg) && - (tmp_for_vreg(c, 0, src_vreg) != -1)) { - if (has_single_def_use(c, src_vreg)) { - if (c->dill_debug) { - printf(" -- Eliminating previous store -- \n"); - } - c->p->cur_ip = (char*)c->p->code_base + last_store_loc; - } - src_preg = tmp_for_vreg(c, 0, src_vreg); - } else { - src_preg = load_oprnd(c, 0, src_vreg); - } - } - if (dest_preg == -1) { - dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; - } - ( c->j->convert)(c, from_type, to_type, dest_preg, src_preg); - if (preg_of(c, bb, dest_vreg) == -1) { - /* no dest reg, store result */ - last_store_loc = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); - store_oprnd(c, 0, dest_vreg); - last_dest_vreg = dest_vreg; - } else { - last_dest_vreg = -1; - } - } - break; - case iclass_loadstore: { - /* load/store 3 operand integer insns */ - int dest_vreg = ip->opnds.a3.dest; - int src1_vreg = ip->opnds.a3.src1; - int src2_vreg = ip->opnds.a3.src2; - int dest_preg; - int src1_preg; - int src2_preg; - int store = ((ip->insn_code & 0x10) == 0x10); - int bswap = ((ip->insn_code & 0x20) == 0x20); - int typ = ip->insn_code & 0xf; - - if (last_dest_vreg == src2_vreg) { - /* we only optimize opnd1, switch them */ - /* load store is commutative */ - src1_vreg = ip->opnds.a3.src2; - src2_vreg = ip->opnds.a3.src1; - } - dest_preg = preg_of(c, bb, dest_vreg); - src1_preg = preg_of(c, bb, src1_vreg); - src2_preg = preg_of(c, bb, src2_vreg); - if (src1_preg == -1) { - /* load src1 */ - if ((last_dest_vreg == src1_vreg) && - (tmp_for_vreg(c, 0, src1_vreg) != -1)) { - if (has_single_def_use(c, src1_vreg)) { - if (c->dill_debug) { - printf(" -- Eliminating previous store -- \n"); - } - c->p->cur_ip = (char*)c->p->code_base + last_store_loc; - } - src1_preg = tmp_for_vreg(c, 0, src1_vreg); - } else { - src1_preg = load_oprnd(c, 0, src1_vreg); - } - } - if (src2_preg == -1) { - /* load src2 */ - src2_preg = load_oprnd(c, 1, src2_vreg); - } - if (store == 0) { - if (dest_preg == -1) { - dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; - } - if (bswap) { - ( c->j->bsload)(c, typ, 0, dest_preg, src1_preg, src2_preg); - } else { - ( c->j->load)(c, typ, 0, dest_preg, src1_preg, src2_preg); - } - if (preg_of(c, bb, dest_vreg) == -1) { - /* no dest reg, store result */ - last_store_loc = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); - store_oprnd(c, 0, dest_vreg); - last_dest_vreg = dest_vreg; - } else { - last_dest_vreg = -1; - } - } else { - if (dest_preg == -1) { - dest_preg = load_oprnd(c, 2, dest_vreg); - } - ( c->j->store)(c, typ, 0, dest_preg, src1_preg, src2_preg); - last_dest_vreg = -1; - } - } - break; - case iclass_lea: - { - /* load effective address */ - int dest_vreg = ip->opnds.a3i.dest; - int src_vreg = ip->opnds.a3i.src; - intptr_t imm = ip->opnds.a3i.u.imm; - int dest_preg = preg_of(c, bb, dest_vreg); - int src_preg = preg_of(c, bb, src_vreg); - if (src_preg == -1) { - /* load src */ - if ((last_dest_vreg == src_vreg) && - (tmp_for_vreg(c, 0, src_vreg) != -1)) { - if (has_single_def_use(c, src_vreg)) { - if (c->dill_debug) { - printf(" -- Eliminating previous store -- \n"); - } - c->p->cur_ip = (char*)c->p->code_base + last_store_loc; - } - src_preg = tmp_for_vreg(c, 0, src_vreg); - } else { - src_preg = load_oprnd(c, 0, src_vreg); - } - } - if (dest_preg == -1) { - dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; - } - ( c->j->lea)(c, 0, 0, dest_preg, src_preg, imm); - if (preg_of(c, bb, dest_vreg) == -1) { - /* no dest reg, store result */ - last_store_loc = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); - store_oprnd(c, 0, dest_vreg); - last_dest_vreg = dest_vreg; - } else { - last_dest_vreg = -1; - } - } - break; - case iclass_loadstorei: - { - /* load store immediate operand integer insns */ - int dest_vreg = ip->opnds.a3i.dest; - int src_vreg = ip->opnds.a3i.src; - intptr_t imm = ip->opnds.a3i.u.imm; - int dest_preg = preg_of(c, bb, dest_vreg); - int src_preg = preg_of(c, bb, src_vreg); - int store = ((ip->insn_code & 0x10) == 0x10); - int bswap = ((ip->insn_code & 0x20) == 0x20); - int typ = ip->insn_code & 0xf; - if (src_preg == -1) { - /* load src */ - if ((last_dest_vreg == src_vreg) && - (tmp_for_vreg(c, 0, src_vreg) != -1)) { - if (has_single_def_use(c, src_vreg)) { - if (c->dill_debug) { - printf(" -- Eliminating previous store -- \n"); - } - c->p->cur_ip = (char*)c->p->code_base + last_store_loc; - } - src_preg = tmp_for_vreg(c, 0, src_vreg); - } else { - src_preg = load_oprnd(c, 0, src_vreg); - } - } - if (store == 0) { - if (dest_preg == -1) { - dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; - } - if (bswap) { - ( c->j->bsloadi)(c, typ, 0, dest_preg, src_preg, imm); - } else { - ( c->j->loadi)(c, typ, 0, dest_preg, src_preg, imm); - } - if (preg_of(c, bb, dest_vreg) == -1) { - /* no dest reg, store result */ - last_store_loc = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); - store_oprnd(c, 0, dest_vreg); - last_dest_vreg = dest_vreg; - } else { - last_dest_vreg = -1; - } - } else { - if (dest_preg == -1) { - dest_preg = load_oprnd(c, 1, dest_vreg); - } - /* a store, dest is the source of the store */ - ( c->j->storei)(c, typ, 0, dest_preg, src_preg, imm); - last_dest_vreg = -1; - } - } - break; - case iclass_set: - { - /* load store immediate operand integer insns */ - int dest_vreg = ip->opnds.a3i.dest; - intptr_t imm = ip->opnds.a3i.u.imm; - int dest_preg = preg_of(c, bb, dest_vreg); - int typ = ip->insn_code & 0xf; - if (dest_preg == -1) { - dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; - } - ( c->j->set)(c, typ, 0, dest_preg, imm); - if (preg_of(c, bb, dest_vreg) == -1) { - /* no dest reg, store result */ - last_store_loc = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); - store_oprnd(c, 0, dest_vreg); - last_dest_vreg = dest_vreg; - } else { - last_dest_vreg = -1; - } - } - break; - case iclass_setf: - { - /* load store immediate operand integer insns */ - int dest_vreg = ip->opnds.sf.dest; - double imm = ip->opnds.sf.imm; - int dest_preg = preg_of(c, bb, dest_vreg); - int typ = ip->insn_code & 0xf; - if (dest_preg == -1) { - dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; - } - ( c->j->setf)(c, typ, 0, dest_preg, imm); - if (preg_of(c, bb, dest_vreg) == -1) { - /* no dest reg, store result */ - last_store_loc = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); - store_oprnd(c, 0, dest_vreg); - last_dest_vreg = dest_vreg; - } else { - last_dest_vreg = -1; - } - } - break; - case iclass_mov: { - /* mov insns */ - int dest_vreg = ip->opnds.a2.dest; - int src_vreg = ip->opnds.a2.src; - int dest_preg = preg_of(c, bb, dest_vreg); - int src_preg = preg_of(c, bb, src_vreg); - int typ = ip->insn_code & 0xf; - if (src_preg == -1) { - /* load src */ - if ((last_dest_vreg == src_vreg) && - (tmp_for_vreg(c, 0, src_vreg) != -1)) { - if (has_single_def_use(c, src_vreg)) { - if (c->dill_debug) { - printf(" -- Eliminating previous store -- \n"); - } - c->p->cur_ip = (char*)c->p->code_base + last_store_loc; - } - src_preg = tmp_for_vreg(c, 0, src_vreg); - } else { - src_preg = load_oprnd(c, 0, src_vreg); - } - } - if (dest_preg == -1) { - dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; - } - ( c->j->mov)(c, typ, 0, dest_preg, src_preg); - if (preg_of(c, bb, dest_vreg) == -1) { - /* no dest reg, store result */ - last_store_loc = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); - store_oprnd(c, 0, dest_vreg); - last_dest_vreg = dest_vreg; - } else { - last_dest_vreg = -1; - } - } - break; - case iclass_reti: - { - /* return immediate integer insns */ - intptr_t imm = ip->opnds.a3i.u.imm; - int typ = ip->insn_code & 0xf; - ( c->j->reti)(c, typ, 0, imm); - last_dest_vreg = -1; - } - break; - case iclass_branch: - { - /* branch */ - int br_op = ip->insn_code; - int label = get_new_label(ip->opnds.br.label, ltable); - int src1_vreg = ip->opnds.br.src1; - int src2_vreg = ip->opnds.br.src2; - int src1_preg; - int src2_preg; -/* if (last_dest_vreg == src2_vreg) { - # we should do this is we reverse the sense of the branch * - src1_vreg = ip->opnds.br.src2; - src2_vreg = ip->opnds.br.src1; - } -*/ - src1_preg = preg_of(c, bb, src1_vreg); - src2_preg = preg_of(c, bb, src2_vreg); - if (src1_preg == -1) { - /* load src1 */ - if ((last_dest_vreg == src1_vreg) && - (tmp_for_vreg(c, 0, src1_vreg) != -1)) { - if (has_single_def_use(c, src1_vreg)) { - if (c->dill_debug) { - printf(" -- Eliminating previous store -- \n"); - } - c->p->cur_ip = (char*)c->p->code_base + last_store_loc; - } - src1_preg = tmp_for_vreg(c, 0, src1_vreg); - } else { - src1_preg = load_oprnd(c, 0, src1_vreg); - } - } - if (src2_preg == -1) { - /* load src2 */ - src2_preg = load_oprnd(c, 1, src2_vreg); - } - ( c->j->jmp_b)[br_op](c, c->j->b_data[br_op].data1, - c->j->b_data[br_op].data2, - src1_preg, src2_preg, label); - last_dest_vreg = -1; - } - break; - case iclass_branchi: - { - /* branch immediate */ - int br_op = ip->insn_code; - int label = get_new_label(ip->opnds.bri.label, ltable); - int src1_vreg = ip->opnds.bri.src; - intptr_t imm = ip->opnds.bri.imm_l; - int src1_preg = preg_of(c, bb, src1_vreg); - if (src1_preg == -1) { - /* load src1 */ - if ((last_dest_vreg == src1_vreg) && - (tmp_for_vreg(c, 0, src1_vreg) != -1)) { - if (has_single_def_use(c, src1_vreg)) { - if (c->dill_debug) { - printf(" -- Eliminating previous store -- \n"); - } - c->p->cur_ip = (char*)c->p->code_base + last_store_loc; - } - src1_preg = tmp_for_vreg(c, 0, src1_vreg); - } else { - src1_preg = load_oprnd(c, 0, src1_vreg); - } - } - - ( c->j->jmp_bi)[br_op](c, c->j->b_data[br_op].data1, - c->j->b_data[br_op].data2, - src1_preg, imm, label); - last_dest_vreg = -1; - } - break; - case iclass_jump_to_label: - { - /* branch immediate */ - int label = get_new_label(ip->opnds.br.label, ltable); - dill_jv(c, label); - last_dest_vreg = -1; - } - break; - case iclass_jump_to_reg: - { - int src1_vreg = ip->opnds.br.src1; - int src1_preg = preg_of(c, bb, src1_vreg); - if (src1_preg == -1) { - /* load src1 */ - if ((last_dest_vreg == src1_vreg) && - (tmp_for_vreg(c, 0, src1_vreg) != -1)) { - if (has_single_def_use(c, src1_vreg)) { - if (c->dill_debug) { - printf(" -- Eliminating previous store -- \n"); - } - c->p->cur_ip = (char*)c->p->code_base + last_store_loc; - } - src1_preg = tmp_for_vreg(c, 0, src1_vreg); - } else { - src1_preg = load_oprnd(c, 0, src1_vreg); - } - } - - dill_jp(c, src1_preg); - last_dest_vreg = -1; - } - break; - case iclass_jump_to_imm: - { - void *imm = ip->opnds.bri.imm_a; - dill_jpi(c, imm); - last_dest_vreg = -1; - } - break; - case iclass_special: - dill_special(c, ip->opnds.spec.type, ip->opnds.spec.param); - break; - case iclass_call: - { - basic_block next_bb = &vmi->bblist[i+1]; - int dest_vreg = ip->opnds.calli.src; - int dest_preg = 0; - - int reg = ip->insn_code & 0x10; - int typ = ip->insn_code & 0xf; - int rr; - - if (typ != DILL_V) dest_preg = preg_of(c, next_bb, dest_vreg); - if (reg != 0) { - intptr_t src1_vreg = ip->opnds.calli.imm_l; - int src1_preg = preg_of(c, bb, src1_vreg); - if (src1_preg == -1) { - /* load src1 */ - if ((last_dest_vreg == src1_vreg) && - (tmp_for_vreg(c, 0, src1_vreg) != -1)) { - if (has_single_def_use(c, src1_vreg)) { - if (c->dill_debug) { - printf(" -- Eliminating previous store -- \n"); - } - c->p->cur_ip = (char*)c->p->code_base + last_store_loc; - } - src1_preg = tmp_for_vreg(c, 0, src1_vreg); - } else { - src1_preg = load_oprnd(c, 0, src1_vreg); - } - } - rr = dill_pcallr(c, typ, src1_preg); - } else { - rr = dill_pcall(c, typ, ip->opnds.calli.imm_a, ip->opnds.calli.xfer_name); - } - if (typ != DILL_V) { - if (preg_of(c, next_bb, dest_vreg) == -1) { - /* no dest reg, store result */ - int offset = offset_of(c, dest_vreg); - int typ = dill_type_of(c, dest_vreg); - if (dest_vreg >= 100) { - c->j->storei(c, typ, 0, rr, c->dill_local_pointer, - offset); - } else { - c->j->storei(c, typ, 0, rr, c->dill_param_reg_pointer, - offset); - } - } else { - /* move return value to result */ - c->j->mov(c, typ, 0, dest_preg, rr); - } - } - pushpop_inuse_regs(c, 1, ip); - last_dest_vreg = -1; - } - break; - case iclass_push: - { - int typ = ip->insn_code & 0xf; - int src1_vreg = ip->opnds.a1.src; - int src1_preg; - if ((short)ip->opnds.a1.src >= 0) { - /* neg 1 used to signal push init */ - src1_preg = preg_of(c, bb, src1_vreg); - if (src1_preg == -1) { - /* load src1 */ - if ((last_dest_vreg == src1_vreg) && - (tmp_for_vreg(c, 0, src1_vreg) != -1)) { - if (has_single_def_use(c, src1_vreg)) { - if (c->dill_debug) { - printf(" -- Eliminating previous store -- \n"); - } - c->p->cur_ip = (char*)c->p->code_base + last_store_loc; - } - src1_preg = tmp_for_vreg(c, 0, src1_vreg); - } else { - src1_preg = load_oprnd(c, 0, src1_vreg); - } - } - } else { - pushpop_inuse_regs(c, 0, ip); - src1_preg = -1; - } - dill_push_arg(c, typ, src1_preg); - last_dest_vreg = -1; - } - break; - case iclass_pushi: - { - int typ = ip->insn_code & 0xf; - if (typ == DILL_P) { - void *imm = ip->opnds.a3i.u.imm_a; - dill_push_argpi(c, imm); - } else { - intptr_t imm = ip->opnds.a3i.u.imm; - dill_push_argii(c, imm); - } - last_dest_vreg = -1; - } - break; - case iclass_pushf: - { - int typ = ip->insn_code & 0xf; - double imm = ip->opnds.sf.imm; - c->j->pushfi(c, typ, imm); - last_dest_vreg = -1; - } - break; - case iclass_nop: - break; - } - } - foreach_bit(bb->regs_defined, (bv_func)emit_putreg, bb, c); - if (count_verbose) { - int insn_end = (int)( (char*)c->p->cur_ip - (char*)c->p->code_base); - printf("Basic Block %d, %d virtual instructions, %d physical instructions\n", - i, insn_count, c->j->count_insn(c, insn_start, insn_end)); - } - } - if ((unsigned)ltable[label_xlate].old_location == j * sizeof(virtual_insn)) { - dill_mark_label(c, ltable[label_xlate].new_label); - label_xlate++; + basic_block bb = &vmi->bblist[i]; + int last_dest_vreg = -1; + int last_store_loc = 0; + int insn_start = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); + int insn_count = (int)(bb->end - bb->start); + foreach_bit(bb->regs_defined, (bv_func)emit_getreg, bb, c); + for (j = (size_t)bb->start; j <= (size_t)bb->end; j++) { + int loc; + ip = &((virtual_insn*)insns)[j]; + loc = (int)((char*)ip - (char*)insns); + while ((loc != 0) && (ltable[label_xlate].old_location == loc)) { + dill_mark_label(c, ltable[label_xlate].new_label); + label_xlate++; + } + if (c->dill_debug) { + printf(" v "); + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + switch (ip->class_code) { + case iclass_arith3: { + /* arith 3 operand integer insns */ + int dest_vreg = ip->opnds.a3.dest; + int src1_vreg = ip->opnds.a3.src1; + int src2_vreg = ip->opnds.a3.src2; + int dest_preg; + int src1_preg; + int src2_preg; + int insn_code = ip->insn_code; + if ((last_dest_vreg == src2_vreg) && + is_commutative(insn_code)) { + /* we only optimize opnd1, switch them */ + src1_vreg = ip->opnds.a3.src2; + src2_vreg = ip->opnds.a3.src1; + } + dest_preg = preg_of(c, bb, dest_vreg); + src1_preg = preg_of(c, bb, src1_vreg); + src2_preg = preg_of(c, bb, src2_vreg); + if (src1_preg == -1) { + /* load src1 */ + if ((last_dest_vreg == src1_vreg) && + (tmp_for_vreg(c, 0, src1_vreg) != -1)) { + if (has_single_def_use(c, src1_vreg)) { + if (c->dill_debug) { + printf(" -- Eliminating previous store -- \n"); + } + c->p->cur_ip = + (char*)c->p->code_base + last_store_loc; + } + src1_preg = tmp_for_vreg(c, 0, src1_vreg); + } else { + src1_preg = load_oprnd(c, 0, src1_vreg); + } + } + if (src2_preg == -1) { + /* load src2 */ + src2_preg = load_oprnd(c, 1, src2_vreg); + } + if (dest_preg == -1) { + dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; + } + (c->j->jmp_a3)[insn_code](c, c->j->a3_data[insn_code].data1, + c->j->a3_data[insn_code].data2, + dest_preg, src1_preg, src2_preg); + if (preg_of(c, bb, dest_vreg) == -1) { + /* no dest reg, store result */ + last_store_loc = + (int)((char*)c->p->cur_ip - (char*)c->p->code_base); + store_oprnd(c, 0, dest_vreg); + last_dest_vreg = dest_vreg; + } else { + last_dest_vreg = -1; + } + } break; + case iclass_compare: { + /* compare 3 operand insns */ + int dest_vreg = ip->opnds.a3.dest; + int src1_vreg = ip->opnds.a3.src1; + int src2_vreg = ip->opnds.a3.src2; + int dest_preg; + int src1_preg; + int src2_preg; + int insn_code = ip->insn_code; + if ((last_dest_vreg == src2_vreg) && + is_compare_commutative(insn_code)) { + /* we only optimize opnd1, switch them */ + src1_vreg = ip->opnds.a3.src2; + src2_vreg = ip->opnds.a3.src1; + } + dest_preg = preg_of(c, bb, dest_vreg); + src1_preg = preg_of(c, bb, src1_vreg); + src2_preg = preg_of(c, bb, src2_vreg); + if (src1_preg == -1) { + /* load src1 */ + if ((last_dest_vreg == src1_vreg) && + (tmp_for_vreg(c, 0, src1_vreg) != -1)) { + if (has_single_def_use(c, src1_vreg)) { + if (c->dill_debug) { + printf(" -- Eliminating previous store -- \n"); + } + c->p->cur_ip = + (char*)c->p->code_base + last_store_loc; + } + src1_preg = tmp_for_vreg(c, 0, src1_vreg); + } else { + src1_preg = load_oprnd(c, 0, src1_vreg); + } + } + if (src2_preg == -1) { + /* load src2 */ + src2_preg = load_oprnd(c, 1, src2_vreg); + } + if (dest_preg == -1) { + dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; + } + (c->j->jmp_c)[insn_code](c, c->j->c_data[insn_code].data1, + c->j->c_data[insn_code].data2, + dest_preg, src1_preg, src2_preg); + if (preg_of(c, bb, dest_vreg) == -1) { + /* no dest reg, store result */ + last_store_loc = + (int)((char*)c->p->cur_ip - (char*)c->p->code_base); + store_oprnd(c, 0, dest_vreg); + last_dest_vreg = dest_vreg; + } else { + last_dest_vreg = -1; + } + } break; + case iclass_arith2: { + /* arith 2 operand integer insns */ + int dest_vreg = ip->opnds.a2.dest; + int src_vreg = ip->opnds.a2.src; + int dest_preg = preg_of(c, bb, dest_vreg); + int src_preg = preg_of(c, bb, src_vreg); + int insn_code = ip->insn_code; + if (src_preg == -1) { + /* load src */ + if ((last_dest_vreg == src_vreg) && + (tmp_for_vreg(c, 0, src_vreg) != -1)) { + if (has_single_def_use(c, src_vreg)) { + if (c->dill_debug) { + printf(" -- Eliminating previous store -- \n"); + } + c->p->cur_ip = + (char*)c->p->code_base + last_store_loc; + } + src_preg = tmp_for_vreg(c, 0, src_vreg); + } else { + src_preg = load_oprnd(c, 0, src_vreg); + } + } + if (dest_preg == -1) { + dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; + } + (c->j->jmp_a2)[insn_code](c, c->j->a2_data[insn_code].data1, + c->j->a2_data[insn_code].data2, + dest_preg, src_preg); + if (preg_of(c, bb, dest_vreg) == -1) { + /* no dest reg, store result */ + last_store_loc = + (int)((char*)c->p->cur_ip - (char*)c->p->code_base); + store_oprnd(c, 0, dest_vreg); + last_dest_vreg = dest_vreg; + } else { + last_dest_vreg = -1; + } + } break; + case iclass_arith3i: { + /* arith 3 immediate operand integer insns */ + int dest_vreg = ip->opnds.a3i.dest; + int src_vreg = ip->opnds.a3i.src; + intptr_t imm = ip->opnds.a3i.u.imm; + int dest_preg = preg_of(c, bb, dest_vreg); + int src_preg = preg_of(c, bb, src_vreg); + int insn_code = ip->insn_code; + if (src_preg == -1) { + /* load src */ + if ((last_dest_vreg == src_vreg) && + (tmp_for_vreg(c, 0, src_vreg) != -1)) { + if (has_single_def_use(c, src_vreg)) { + if (c->dill_debug) { + printf(" -- Eliminating previous store -- \n"); + } + c->p->cur_ip = + (char*)c->p->code_base + last_store_loc; + } + src_preg = tmp_for_vreg(c, 0, src_vreg); + } else { + src_preg = load_oprnd(c, 0, src_vreg); + } + } + if (dest_preg == -1) { + dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; + } + (c->j->jmp_a3i)[insn_code](c, c->j->a3i_data[insn_code].data1, + c->j->a3i_data[insn_code].data2, + dest_preg, src_preg, imm); + if (preg_of(c, bb, dest_vreg) == -1) { + /* no dest reg, store result */ + last_store_loc = + (int)((char*)c->p->cur_ip - (char*)c->p->code_base); + store_oprnd(c, 0, dest_vreg); + last_dest_vreg = dest_vreg; + } else { + last_dest_vreg = -1; + } + } break; + case iclass_ret: { + /* arith operand integer insns */ + int src_vreg = ip->opnds.a1.src; + int src_preg = preg_of(c, bb, src_vreg); + if (src_preg == -1) { + /* load src */ + if ((last_dest_vreg == src_vreg) && + (tmp_for_vreg(c, 0, src_vreg) != -1)) { + if (has_single_def_use(c, src_vreg)) { + if (c->dill_debug) { + printf(" -- Eliminating previous store -- \n"); + } + c->p->cur_ip = + (char*)c->p->code_base + last_store_loc; + } + src_preg = tmp_for_vreg(c, 0, src_vreg); + } else { + src_preg = load_oprnd(c, 0, src_vreg); + } + } + (c->j->ret)(c, ip->insn_code, 0, src_preg); + last_dest_vreg = -1; + } break; + case iclass_convert: { + /* conversion insns */ + int dest_vreg = ip->opnds.a2.dest; + int src_vreg = ip->opnds.a2.src; + int dest_preg = preg_of(c, bb, dest_vreg); + int src_preg = preg_of(c, bb, src_vreg); + int from_type = (ip->insn_code >> 4) & 0xf; + int to_type = ip->insn_code & 0xf; + if (src_preg == -1) { + /* load src */ + if ((last_dest_vreg == src_vreg) && + (tmp_for_vreg(c, 0, src_vreg) != -1)) { + if (has_single_def_use(c, src_vreg)) { + if (c->dill_debug) { + printf(" -- Eliminating previous store -- \n"); + } + c->p->cur_ip = + (char*)c->p->code_base + last_store_loc; + } + src_preg = tmp_for_vreg(c, 0, src_vreg); + } else { + src_preg = load_oprnd(c, 0, src_vreg); + } + } + if (dest_preg == -1) { + dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; + } + (c->j->convert)(c, from_type, to_type, dest_preg, src_preg); + if (preg_of(c, bb, dest_vreg) == -1) { + /* no dest reg, store result */ + last_store_loc = + (int)((char*)c->p->cur_ip - (char*)c->p->code_base); + store_oprnd(c, 0, dest_vreg); + last_dest_vreg = dest_vreg; + } else { + last_dest_vreg = -1; + } + } break; + case iclass_loadstore: { + /* load/store 3 operand integer insns */ + int dest_vreg = ip->opnds.a3.dest; + int src1_vreg = ip->opnds.a3.src1; + int src2_vreg = ip->opnds.a3.src2; + int dest_preg; + int src1_preg; + int src2_preg; + int store = ((ip->insn_code & 0x10) == 0x10); + int bswap = ((ip->insn_code & 0x20) == 0x20); + int typ = ip->insn_code & 0xf; + + if (last_dest_vreg == src2_vreg) { + /* we only optimize opnd1, switch them */ + /* load store is commutative */ + src1_vreg = ip->opnds.a3.src2; + src2_vreg = ip->opnds.a3.src1; + } + dest_preg = preg_of(c, bb, dest_vreg); + src1_preg = preg_of(c, bb, src1_vreg); + src2_preg = preg_of(c, bb, src2_vreg); + if (src1_preg == -1) { + /* load src1 */ + if ((last_dest_vreg == src1_vreg) && + (tmp_for_vreg(c, 0, src1_vreg) != -1)) { + if (has_single_def_use(c, src1_vreg)) { + if (c->dill_debug) { + printf(" -- Eliminating previous store -- \n"); + } + c->p->cur_ip = + (char*)c->p->code_base + last_store_loc; + } + src1_preg = tmp_for_vreg(c, 0, src1_vreg); + } else { + src1_preg = load_oprnd(c, 0, src1_vreg); + } + } + if (src2_preg == -1) { + /* load src2 */ + src2_preg = load_oprnd(c, 1, src2_vreg); + } + if (store == 0) { + if (dest_preg == -1) { + dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; + } + if (bswap) { + (c->j->bsload)(c, typ, 0, dest_preg, src1_preg, + src2_preg); + } else { + (c->j->load)(c, typ, 0, dest_preg, src1_preg, + src2_preg); + } + if (preg_of(c, bb, dest_vreg) == -1) { + /* no dest reg, store result */ + last_store_loc = + (int)((char*)c->p->cur_ip - (char*)c->p->code_base); + store_oprnd(c, 0, dest_vreg); + last_dest_vreg = dest_vreg; + } else { + last_dest_vreg = -1; + } + } else { + if (dest_preg == -1) { + dest_preg = load_oprnd(c, 2, dest_vreg); + } + (c->j->store)(c, typ, 0, dest_preg, src1_preg, src2_preg); + last_dest_vreg = -1; + } + } break; + case iclass_lea: { + /* load effective address */ + int dest_vreg = ip->opnds.a3i.dest; + int src_vreg = ip->opnds.a3i.src; + intptr_t imm = ip->opnds.a3i.u.imm; + int dest_preg = preg_of(c, bb, dest_vreg); + int src_preg = preg_of(c, bb, src_vreg); + if (src_preg == -1) { + /* load src */ + if ((last_dest_vreg == src_vreg) && + (tmp_for_vreg(c, 0, src_vreg) != -1)) { + if (has_single_def_use(c, src_vreg)) { + if (c->dill_debug) { + printf(" -- Eliminating previous store -- \n"); + } + c->p->cur_ip = + (char*)c->p->code_base + last_store_loc; + } + src_preg = tmp_for_vreg(c, 0, src_vreg); + } else { + src_preg = load_oprnd(c, 0, src_vreg); + } + } + if (dest_preg == -1) { + dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; + } + (c->j->lea)(c, 0, 0, dest_preg, src_preg, imm); + if (preg_of(c, bb, dest_vreg) == -1) { + /* no dest reg, store result */ + last_store_loc = + (int)((char*)c->p->cur_ip - (char*)c->p->code_base); + store_oprnd(c, 0, dest_vreg); + last_dest_vreg = dest_vreg; + } else { + last_dest_vreg = -1; + } + } break; + case iclass_loadstorei: { + /* load store immediate operand integer insns */ + int dest_vreg = ip->opnds.a3i.dest; + int src_vreg = ip->opnds.a3i.src; + intptr_t imm = ip->opnds.a3i.u.imm; + int dest_preg = preg_of(c, bb, dest_vreg); + int src_preg = preg_of(c, bb, src_vreg); + int store = ((ip->insn_code & 0x10) == 0x10); + int bswap = ((ip->insn_code & 0x20) == 0x20); + int typ = ip->insn_code & 0xf; + if (src_preg == -1) { + /* load src */ + if ((last_dest_vreg == src_vreg) && + (tmp_for_vreg(c, 0, src_vreg) != -1)) { + if (has_single_def_use(c, src_vreg)) { + if (c->dill_debug) { + printf(" -- Eliminating previous store -- \n"); + } + c->p->cur_ip = + (char*)c->p->code_base + last_store_loc; + } + src_preg = tmp_for_vreg(c, 0, src_vreg); + } else { + src_preg = load_oprnd(c, 0, src_vreg); + } + } + if (store == 0) { + if (dest_preg == -1) { + dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; + } + if (bswap) { + (c->j->bsloadi)(c, typ, 0, dest_preg, src_preg, imm); + } else { + (c->j->loadi)(c, typ, 0, dest_preg, src_preg, imm); + } + if (preg_of(c, bb, dest_vreg) == -1) { + /* no dest reg, store result */ + last_store_loc = + (int)((char*)c->p->cur_ip - (char*)c->p->code_base); + store_oprnd(c, 0, dest_vreg); + last_dest_vreg = dest_vreg; + } else { + last_dest_vreg = -1; + } + } else { + if (dest_preg == -1) { + dest_preg = load_oprnd(c, 1, dest_vreg); + } + /* a store, dest is the source of the store */ + (c->j->storei)(c, typ, 0, dest_preg, src_preg, imm); + last_dest_vreg = -1; + } + } break; + case iclass_set: { + /* load store immediate operand integer insns */ + int dest_vreg = ip->opnds.a3i.dest; + intptr_t imm = ip->opnds.a3i.u.imm; + int dest_preg = preg_of(c, bb, dest_vreg); + int typ = ip->insn_code & 0xf; + if (dest_preg == -1) { + dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; + } + (c->j->set)(c, typ, 0, dest_preg, imm); + if (preg_of(c, bb, dest_vreg) == -1) { + /* no dest reg, store result */ + last_store_loc = + (int)((char*)c->p->cur_ip - (char*)c->p->code_base); + store_oprnd(c, 0, dest_vreg); + last_dest_vreg = dest_vreg; + } else { + last_dest_vreg = -1; + } + } break; + case iclass_setf: { + /* load store immediate operand integer insns */ + int dest_vreg = ip->opnds.sf.dest; + double imm = ip->opnds.sf.imm; + int dest_preg = preg_of(c, bb, dest_vreg); + int typ = ip->insn_code & 0xf; + if (dest_preg == -1) { + dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; + } + (c->j->setf)(c, typ, 0, dest_preg, imm); + if (preg_of(c, bb, dest_vreg) == -1) { + /* no dest reg, store result */ + last_store_loc = + (int)((char*)c->p->cur_ip - (char*)c->p->code_base); + store_oprnd(c, 0, dest_vreg); + last_dest_vreg = dest_vreg; + } else { + last_dest_vreg = -1; + } + } break; + case iclass_mov: { + /* mov insns */ + int dest_vreg = ip->opnds.a2.dest; + int src_vreg = ip->opnds.a2.src; + int dest_preg = preg_of(c, bb, dest_vreg); + int src_preg = preg_of(c, bb, src_vreg); + int typ = ip->insn_code & 0xf; + if (src_preg == -1) { + /* load src */ + if ((last_dest_vreg == src_vreg) && + (tmp_for_vreg(c, 0, src_vreg) != -1)) { + if (has_single_def_use(c, src_vreg)) { + if (c->dill_debug) { + printf(" -- Eliminating previous store -- \n"); + } + c->p->cur_ip = + (char*)c->p->code_base + last_store_loc; + } + src_preg = tmp_for_vreg(c, 0, src_vreg); + } else { + src_preg = load_oprnd(c, 0, src_vreg); + } + } + if (dest_preg == -1) { + dest_preg = c->p->v_tmps[dill_type_of(c, dest_vreg)][0]; + } + (c->j->mov)(c, typ, 0, dest_preg, src_preg); + if (preg_of(c, bb, dest_vreg) == -1) { + /* no dest reg, store result */ + last_store_loc = + (int)((char*)c->p->cur_ip - (char*)c->p->code_base); + store_oprnd(c, 0, dest_vreg); + last_dest_vreg = dest_vreg; + } else { + last_dest_vreg = -1; + } + } break; + case iclass_reti: { + /* return immediate integer insns */ + intptr_t imm = ip->opnds.a3i.u.imm; + int typ = ip->insn_code & 0xf; + (c->j->reti)(c, typ, 0, imm); + last_dest_vreg = -1; + } break; + case iclass_branch: { + /* branch */ + int br_op = ip->insn_code; + int label = get_new_label(ip->opnds.br.label, ltable); + int src1_vreg = ip->opnds.br.src1; + int src2_vreg = ip->opnds.br.src2; + int src1_preg; + int src2_preg; + /* if (last_dest_vreg == src2_vreg) { + # we should do this is we reverse the sense of the + branch * src1_vreg = ip->opnds.br.src2; src2_vreg = + ip->opnds.br.src1; + } + */ + src1_preg = preg_of(c, bb, src1_vreg); + src2_preg = preg_of(c, bb, src2_vreg); + if (src1_preg == -1) { + /* load src1 */ + if ((last_dest_vreg == src1_vreg) && + (tmp_for_vreg(c, 0, src1_vreg) != -1)) { + if (has_single_def_use(c, src1_vreg)) { + if (c->dill_debug) { + printf(" -- Eliminating previous store -- \n"); + } + c->p->cur_ip = + (char*)c->p->code_base + last_store_loc; + } + src1_preg = tmp_for_vreg(c, 0, src1_vreg); + } else { + src1_preg = load_oprnd(c, 0, src1_vreg); + } + } + if (src2_preg == -1) { + /* load src2 */ + src2_preg = load_oprnd(c, 1, src2_vreg); + } + (c->j->jmp_b)[br_op](c, c->j->b_data[br_op].data1, + c->j->b_data[br_op].data2, src1_preg, + src2_preg, label); + last_dest_vreg = -1; + } break; + case iclass_branchi: { + /* branch immediate */ + int br_op = ip->insn_code; + int label = get_new_label(ip->opnds.bri.label, ltable); + int src1_vreg = ip->opnds.bri.src; + intptr_t imm = ip->opnds.bri.imm_l; + int src1_preg = preg_of(c, bb, src1_vreg); + if (src1_preg == -1) { + /* load src1 */ + if ((last_dest_vreg == src1_vreg) && + (tmp_for_vreg(c, 0, src1_vreg) != -1)) { + if (has_single_def_use(c, src1_vreg)) { + if (c->dill_debug) { + printf(" -- Eliminating previous store -- \n"); + } + c->p->cur_ip = + (char*)c->p->code_base + last_store_loc; + } + src1_preg = tmp_for_vreg(c, 0, src1_vreg); + } else { + src1_preg = load_oprnd(c, 0, src1_vreg); + } + } + + (c->j->jmp_bi)[br_op](c, c->j->b_data[br_op].data1, + c->j->b_data[br_op].data2, src1_preg, imm, + label); + last_dest_vreg = -1; + } break; + case iclass_jump_to_label: { + /* branch immediate */ + int label = get_new_label(ip->opnds.br.label, ltable); + dill_jv(c, label); + last_dest_vreg = -1; + } break; + case iclass_jump_to_reg: { + int src1_vreg = ip->opnds.br.src1; + int src1_preg = preg_of(c, bb, src1_vreg); + if (src1_preg == -1) { + /* load src1 */ + if ((last_dest_vreg == src1_vreg) && + (tmp_for_vreg(c, 0, src1_vreg) != -1)) { + if (has_single_def_use(c, src1_vreg)) { + if (c->dill_debug) { + printf(" -- Eliminating previous store -- \n"); + } + c->p->cur_ip = + (char*)c->p->code_base + last_store_loc; + } + src1_preg = tmp_for_vreg(c, 0, src1_vreg); + } else { + src1_preg = load_oprnd(c, 0, src1_vreg); + } + } + + dill_jp(c, src1_preg); + last_dest_vreg = -1; + } break; + case iclass_jump_to_imm: { + void* imm = ip->opnds.bri.imm_a; + dill_jpi(c, imm); + last_dest_vreg = -1; + } break; + case iclass_special: + dill_special(c, ip->opnds.spec.type, ip->opnds.spec.param); + break; + case iclass_call: { + basic_block next_bb = &vmi->bblist[i + 1]; + int dest_vreg = ip->opnds.calli.src; + int dest_preg = 0; + + int reg = ip->insn_code & 0x10; + int typ = ip->insn_code & 0xf; + int rr; + + if (typ != DILL_V) + dest_preg = preg_of(c, next_bb, dest_vreg); + if (reg != 0) { + intptr_t src1_vreg = ip->opnds.calli.imm_l; + int src1_preg = preg_of(c, bb, (int)src1_vreg); + if (src1_preg == -1) { + /* load src1 */ + if ((last_dest_vreg == src1_vreg) && + (tmp_for_vreg(c, 0, (int)src1_vreg) != -1)) { + if (has_single_def_use(c, (int)src1_vreg)) { + if (c->dill_debug) { + printf( + " -- Eliminating previous store -- " + "\n"); + } + c->p->cur_ip = + (char*)c->p->code_base + last_store_loc; + } + src1_preg = tmp_for_vreg(c, 0, (int)src1_vreg); + } else { + src1_preg = load_oprnd(c, 0, (int)src1_vreg); + } + } + rr = dill_pcallr(c, typ, src1_preg); + } else { + rr = dill_pcall(c, typ, ip->opnds.calli.imm_a, + ip->opnds.calli.xfer_name); + } + if (typ != DILL_V) { + if (preg_of(c, next_bb, dest_vreg) == -1) { + /* no dest reg, store result */ + int offset = offset_of(c, dest_vreg); + int typ = dill_type_of(c, dest_vreg); + if (dest_vreg >= 100) { + c->j->storei(c, typ, 0, rr, c->dill_local_pointer, + offset); + } else { + c->j->storei(c, typ, 0, rr, + c->dill_param_reg_pointer, offset); + } + } else { + /* move return value to result */ + c->j->mov(c, typ, 0, dest_preg, rr); + } + } + pushpop_inuse_regs(c, 1, ip); + last_dest_vreg = -1; + } break; + case iclass_push: { + int typ = ip->insn_code & 0xf; + int src1_vreg = ip->opnds.a1.src; + int src1_preg; + if ((short)ip->opnds.a1.src >= 0) { + /* neg 1 used to signal push init */ + src1_preg = preg_of(c, bb, src1_vreg); + if (src1_preg == -1) { + /* load src1 */ + if ((last_dest_vreg == src1_vreg) && + (tmp_for_vreg(c, 0, src1_vreg) != -1)) { + if (has_single_def_use(c, src1_vreg)) { + if (c->dill_debug) { + printf( + " -- Eliminating previous store -- " + "\n"); + } + c->p->cur_ip = + (char*)c->p->code_base + last_store_loc; + } + src1_preg = tmp_for_vreg(c, 0, src1_vreg); + } else { + src1_preg = load_oprnd(c, 0, src1_vreg); + } + } + } else { + pushpop_inuse_regs(c, 0, ip); + src1_preg = -1; + } + dill_push_arg(c, typ, src1_preg); + last_dest_vreg = -1; + } break; + case iclass_pushi: { + int typ = ip->insn_code & 0xf; + if (typ == DILL_P) { + void* imm = ip->opnds.a3i.u.imm_a; + dill_push_argpi(c, imm); + } else { + intptr_t imm = ip->opnds.a3i.u.imm; + dill_push_argii(c, imm); + } + last_dest_vreg = -1; + } break; + case iclass_pushf: { + int typ = ip->insn_code & 0xf; + double imm = ip->opnds.sf.imm; + c->j->pushfi(c, typ, imm); + last_dest_vreg = -1; + } break; + case iclass_nop: + break; + } + } + foreach_bit(bb->regs_defined, (bv_func)emit_putreg, bb, c); + if (count_verbose) { + int insn_end = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); + printf( + "Basic Block %zd, %d virtual instructions, %d physical " + "instructions\n", + i, insn_count, c->j->count_insn(c, insn_start, insn_end)); + } + } + if ((unsigned)ltable[label_xlate].old_location == + j * sizeof(virtual_insn)) { + dill_mark_label(c, ltable[label_xlate].new_label); + label_xlate++; } if (ltable[label_xlate].old_location != -1) { - printf("Some labels (%d, old loc %d) not placed\n", label_xlate, - ltable[label_xlate].old_location); + printf("Some labels (%d, old loc %d) not placed\n", label_xlate, + ltable[label_xlate].old_location); } } @@ -2530,7 +2566,7 @@ static int live_at_end(basic_block bb, int vreg) { if (vreg >= 100) { - return bit_vec_is_set(bb->live_at_end, vreg - 100); + return bit_vec_is_set(bb->live_at_end, vreg - 100); } return 1; } @@ -2541,7 +2577,7 @@ get_tentative_assign(dill_stream c, int vreg, bit_vec vec) int tmp; dill_raw_getreg(c, &tmp, dill_type_of(c, vreg), DILL_VAR); if (tmp != -1) { - bit_vec_set(vec, tmp); + bit_vec_set(vec, tmp); } return tmp; } @@ -2551,30 +2587,31 @@ put_unless(int bit, dill_stream c, int preg_assigned) { int typ = preg_assigned >> 24; if (bit != (preg_assigned & 0xffffff)) { - dill_raw_putreg(c, bit, typ); + dill_raw_putreg(c, bit, typ); } } static void put_tentative_assigns(dill_stream c, int preg_assigned, bit_vec vec, int typ) { - foreach_bit(vec, (bv_func) put_unless, c, - (void*)(intptr_t)((preg_assigned&0xffffff) | (intptr_t)typ<<24)); + foreach_bit( + vec, (bv_func)put_unless, c, + (void*)(intptr_t)((preg_assigned & 0xffffff) | (intptr_t)typ << 24)); } typedef struct reg_state { dill_stream c; basic_block bb; - preg_info *fpregs; - preg_info *ipregs; + preg_info* fpregs; + preg_info* ipregs; int reg_count; int ret_reg; int ret_vreg; - vreg_info *param_info; + vreg_info* param_info; } reg_state; static void -init_reg_state(reg_state *state, dill_stream c) +init_reg_state(reg_state* state, dill_stream c) { int i; state->fpregs = malloc(sizeof(preg_info)); @@ -2583,770 +2620,775 @@ init_reg_state(reg_state *state, dill_stream c) state->ret_reg = -1; state->ret_vreg = -1; state->param_info = malloc(sizeof(vreg_info) * c->p->c_param_count); - for (i=0; i< c->p->c_param_count; i++) { - if (c->p->c_param_args[i].is_register) { - state->param_info[i].update_in_reg = 0; - state->param_info[i].value_in_mem = 0; - state->param_info[i].in_reg = c->p->c_param_args[i].in_reg; - } else { - state->param_info[i].update_in_reg = 0; - state->param_info[i].value_in_mem = 1; - state->param_info[i].in_reg = -1; - } + for (i = 0; i < c->p->c_param_count; i++) { + if (c->p->c_param_args[i].is_register) { + state->param_info[i].update_in_reg = 0; + state->param_info[i].value_in_mem = 0; + state->param_info[i].in_reg = c->p->c_param_args[i].in_reg; + } else { + state->param_info[i].update_in_reg = 0; + state->param_info[i].value_in_mem = 1; + state->param_info[i].in_reg = -1; + } } } static void -reset_reg_state(reg_state *state) +reset_reg_state(reg_state* state) { int i; - for (i=0; i < state->reg_count; i++) { - state->fpregs[i].holds = state->ipregs[i].holds = -1; + for (i = 0; i < state->reg_count; i++) { + state->fpregs[i].holds = state->ipregs[i].holds = -1; } } static int -update_in_reg(reg_state *s, int vreg) +update_in_reg(reg_state* s, int vreg) { - vreg_info *vregs = s->c->p->vregs; + vreg_info* vregs = s->c->p->vregs; if (vreg >= 100) { - return vregs[vreg - 100].update_in_reg; + return vregs[vreg - 100].update_in_reg; } else { - if (!s->c->p->c_param_args[vreg].is_register) { - return s->param_info[vreg].update_in_reg; - } + if (!s->c->p->c_param_args[vreg].is_register) { + return s->param_info[vreg].update_in_reg; + } } return 0; } static void -set_update_in_reg(reg_state *s, int vreg, int value) +set_update_in_reg(reg_state* s, int vreg, int value) { - vreg_info *vregs = s->c->p->vregs; + vreg_info* vregs = s->c->p->vregs; if (vreg >= 100) { - vregs[vreg - 100].update_in_reg = value; + vregs[vreg - 100].update_in_reg = value; } else { - if (!s->c->p->c_param_args[vreg].is_register) { - s->param_info[vreg].update_in_reg = value; - } + if (!s->c->p->c_param_args[vreg].is_register) { + s->param_info[vreg].update_in_reg = value; + } } } static void -set_value_in_mem(reg_state *s, int vreg, int value) +set_value_in_mem(reg_state* s, int vreg, int value) { - vreg_info *vregs = s->c->p->vregs; + vreg_info* vregs = s->c->p->vregs; if (vreg >= 100) { - vregs[vreg - 100].value_in_mem = value; + vregs[vreg - 100].value_in_mem = value; } else { - if (!s->c->p->c_param_args[vreg].is_register) { - s->param_info[vreg].value_in_mem = value; - } + if (!s->c->p->c_param_args[vreg].is_register) { + s->param_info[vreg].value_in_mem = value; + } } } static int -value_in_mem(reg_state *s, int vreg) +value_in_mem(reg_state* s, int vreg) { - vreg_info *vregs = s->c->p->vregs; + vreg_info* vregs = s->c->p->vregs; if (vreg >= 100) { - return vregs[vreg - 100].value_in_mem; + return vregs[vreg - 100].value_in_mem; } else { - if (!s->c->p->c_param_args[vreg].is_register) { - return s->param_info[vreg].value_in_mem; - } + if (!s->c->p->c_param_args[vreg].is_register) { + return s->param_info[vreg].value_in_mem; + } } return 0; } static void -set_in_reg(reg_state *s, int vreg, int value) +set_in_reg(reg_state* s, int vreg, int value) { - vreg_info *vregs = s->c->p->vregs; + vreg_info* vregs = s->c->p->vregs; if (vreg >= 100) { - vregs[vreg - 100].in_reg = value; + vregs[vreg - 100].in_reg = value; } else { - if (!s->c->p->c_param_args[vreg].is_register) { - s->param_info[vreg].in_reg = value; - } + if (!s->c->p->c_param_args[vreg].is_register) { + s->param_info[vreg].in_reg = value; + } } } static int -get_in_reg(reg_state *s, int vreg) +get_in_reg(reg_state* s, int vreg) { - vreg_info *vregs = s->c->p->vregs; + vreg_info* vregs = s->c->p->vregs; if (vreg >= 100) { - return vregs[vreg - 100].in_reg; + return vregs[vreg - 100].in_reg; } else { - if (!s->c->p->c_param_args[vreg].is_register) { - return s->param_info[vreg].in_reg; - } else { - return s->c->p->c_param_args[vreg].in_reg; - } + if (!s->c->p->c_param_args[vreg].is_register) { + return s->param_info[vreg].in_reg; + } else { + return s->c->p->c_param_args[vreg].in_reg; + } } } static void -set_assign_loc(reg_state *s, int vreg, int value) +set_assign_loc(reg_state* s, int vreg, int value) { - vreg_info *vregs = s->c->p->vregs; + vreg_info* vregs = s->c->p->vregs; if (vreg >= 100) { - vregs[vreg - 100].assign_loc = value; + vregs[vreg - 100].assign_loc = value; } else { - if (!s->c->p->c_param_args[vreg].is_register) { - s->param_info[vreg].assign_loc = value; - } + if (!s->c->p->c_param_args[vreg].is_register) { + s->param_info[vreg].assign_loc = value; + } } } static int -get_assign_loc(reg_state *s, int vreg) +get_assign_loc(reg_state* s, int vreg) { - vreg_info *vregs = s->c->p->vregs; + vreg_info* vregs = s->c->p->vregs; if (vreg >= 100) { - return vregs[vreg - 100].assign_loc; + return vregs[vreg - 100].assign_loc; } else { - if (!s->c->p->c_param_args[vreg].is_register) { - return s->param_info[vreg].assign_loc; - } + if (!s->c->p->c_param_args[vreg].is_register) { + return s->param_info[vreg].assign_loc; + } } return 0; } static void -set_last_use(reg_state *s, int vreg, int value) +set_last_use(reg_state* s, int vreg, int value) { - vreg_info *vregs = s->c->p->vregs; + vreg_info* vregs = s->c->p->vregs; if (vreg >= 100) { - vregs[vreg - 100].last_use = value; + vregs[vreg - 100].last_use = value; } else { - if (!s->c->p->c_param_args[vreg].is_register) { - s->param_info[vreg].last_use = value; - } + if (!s->c->p->c_param_args[vreg].is_register) { + s->param_info[vreg].last_use = value; + } } } static int -get_last_use(reg_state *s, int vreg) +get_last_use(reg_state* s, int vreg) { - vreg_info *vregs = s->c->p->vregs; + vreg_info* vregs = s->c->p->vregs; if (vreg >= 100) { - return vregs[vreg - 100].last_use; + return vregs[vreg - 100].last_use; } else { - if (!s->c->p->c_param_args[vreg].is_register) { - return s->param_info[vreg].last_use; - } + if (!s->c->p->c_param_args[vreg].is_register) { + return s->param_info[vreg].last_use; + } } return 0; } static int -get_use_metric(reg_state *s, int vreg) +get_use_metric(reg_state* s, int vreg) { - vreg_info *vregs = s->c->p->vregs; + vreg_info* vregs = s->c->p->vregs; if (vreg >= 100) { - return vregs[vreg - 100].use_metric; + return vregs[vreg - 100].use_metric; } else { - if (!s->c->p->c_param_args[vreg].is_register) { - return s->param_info[vreg].use_metric; - } + if (!s->c->p->c_param_args[vreg].is_register) { + return s->param_info[vreg].use_metric; + } } return 0; } static void -spill_current_pregs(reg_state *state) +spill_current_pregs(reg_state* state) { dill_stream c = state->c; basic_block bb = state->bb; - preg_info *pregs =state->ipregs; - vreg_info *vregs = state->c->p->vregs; + preg_info* pregs = state->ipregs; + vreg_info* vregs = state->c->p->vregs; int i; int a; - for (a = 0; a < 2 ; a++) { - if (a == 1) { - pregs =state->fpregs; - } - - for (i=0; i < state->reg_count; i++) { - int vreg = pregs[i].holds; - if (vreg >= 100) { - if (update_in_reg(state, vreg) && live_at_end(bb, vreg)) { - int offset = offset_of(c, vreg); - int typ = dill_type_of(c, vreg); - if (offset == 0xdeadbeef) { - /* not previously spilled */ - /* cannot be parameter */ - offset = vregs[vreg-100].offset = dill_local(c, typ); - } - /* spill vreg to memory */ - if (vreg >= 100) { - c->j->storei(c, typ, 0, i, c->dill_local_pointer, offset); - } else { - c->j->storei(c, typ, 0, i, c->dill_param_reg_pointer, offset); - } - set_update_in_reg(state, vreg, 0); - set_value_in_mem(state, vreg, 1); - set_in_reg(state, vreg, -1); - } - } - } + for (a = 0; a < 2; a++) { + if (a == 1) { + pregs = state->fpregs; + } + + for (i = 0; i < state->reg_count; i++) { + int vreg = pregs[i].holds; + if (vreg >= 100) { + if (update_in_reg(state, vreg) && live_at_end(bb, vreg)) { + int offset = offset_of(c, vreg); + int typ = dill_type_of(c, vreg); + if (offset == 0xdeadbeef) { + /* not previously spilled */ + /* cannot be parameter */ + offset = vregs[vreg - 100].offset = dill_local(c, typ); + } + /* spill vreg to memory */ + if (vreg >= 100) { + c->j->storei(c, typ, 0, i, c->dill_local_pointer, + offset); + } else { + c->j->storei(c, typ, 0, i, c->dill_param_reg_pointer, + offset); + } + set_update_in_reg(state, vreg, 0); + set_value_in_mem(state, vreg, 1); + set_in_reg(state, vreg, -1); + } + } + } } } - -static int -select_reg(reg_state *state, int vreg, int loc, int src) +static int +select_reg(reg_state* state, int vreg, int loc, int src) { static int reg_debug = -1; int ret_reg = -1; int old_vreg = -1; - vreg_info *vregs = state->c->p->vregs; + vreg_info* vregs = state->c->p->vregs; dill_stream c = state->c; basic_block bb = state->bb; - preg_info *pregs; - preg_info *fpregs =state->fpregs; - preg_info *ipregs =state->ipregs; + preg_info* pregs; + preg_info* fpregs = state->fpregs; + preg_info* ipregs = state->ipregs; switch (dill_type_of(c, vreg)) { - case DILL_F: case DILL_D: - pregs = state->fpregs; - break; + case DILL_F: + case DILL_D: + pregs = state->fpregs; + break; default: - pregs = state->ipregs; - break; + pregs = state->ipregs; + break; } if (reg_debug == -1) { - reg_debug = (getenv("REG_DEBUG") != NULL); + reg_debug = (getenv("REG_DEBUG") != NULL); } if (vreg < 100) { - /* parameter */ - if (c->p->c_param_args[vreg].is_register) { - return c->p->c_param_args[vreg].in_reg; - } + /* parameter */ + if (c->p->c_param_args[vreg].is_register) { + return c->p->c_param_args[vreg].in_reg; + } } if (vreg == 100) { - return dill_lp(c); + return dill_lp(c); } if (dill_type_of(c, vreg) == DILL_B) { - /* not really using this */ - return -1; + /* not really using this */ + return -1; } if (get_in_reg(state, vreg) != -1) { - ret_reg = get_in_reg(state, vreg); - set_assign_loc(state, vreg, loc); - if (!src) set_update_in_reg(state, vreg, 1); - return ret_reg; + ret_reg = get_in_reg(state, vreg); + set_assign_loc(state, vreg, loc); + if (!src) + set_update_in_reg(state, vreg, 1); + return ret_reg; } else { - int preg; - struct bitv tmp_assigns[6]; - int tentative_assign = -1; - init_bit_vec(&tmp_assigns[0], sizeof(tmp_assigns)); - if (reg_debug) printf("Get assignment for vreg %d\n", vreg); - while ((preg = get_tentative_assign(c, vreg, &tmp_assigns[0])) - != -1) { - int used_vreg; - if (reg_debug) printf("checking preg %d\n", preg); - if (preg >= state->reg_count) { - int i; - fpregs = realloc(fpregs, sizeof(reg_state)*(preg+1)); - ipregs = realloc(ipregs, sizeof(reg_state)*(preg+1)); - state->fpregs = fpregs; - state->ipregs = ipregs; - for (i = state->reg_count; i <= preg; i++) { - ipregs[i].holds = fpregs[i].holds = -1; - } - switch (dill_type_of(c, vreg)) { - case DILL_F: case DILL_D: - pregs = state->fpregs; - break; - default: - pregs = state->ipregs; - break; - } - state->reg_count = preg+1; - } - used_vreg = pregs[preg].holds; - if (used_vreg == -1) { - ret_reg = preg; - if (reg_debug) - printf("preg %d empty, assigning to vreg %d\n", - preg, vreg); - break; - } - if ((get_assign_loc(state, used_vreg) == loc) && src) { - if (reg_debug) - printf("preg %d assigned to vreg %d at this loc\n", - preg, used_vreg); - continue; - } - if ((get_last_use(state, used_vreg) < loc) || - (!src && (get_last_use(state, used_vreg) == loc))) { - ret_reg = preg; - if (reg_debug) - printf("preg %d assigned to vreg %d, but that vreg is done, assigning\n", - preg, used_vreg); - break; - } - if (tentative_assign == -1) { - tentative_assign = preg; - if (reg_debug) - printf("preg %d is new tentative assign\n", preg); - } else if (get_use_metric(state, pregs[tentative_assign].holds) > - get_use_metric(state, used_vreg)) { - if (reg_debug) - printf("preg %d is better tentative assign\n", preg); - tentative_assign = preg; - } else { - if (reg_debug) - printf("previous assign %d was better tentative assign\n", - tentative_assign); - } - } - if (ret_reg == -1) ret_reg = tentative_assign; - put_tentative_assigns(c, -1, &tmp_assigns[0], - dill_type_of(c, vreg)); - } - if (ret_reg != -1) old_vreg = pregs[ret_reg].holds; + int preg; + struct bitv tmp_assigns[6]; + int tentative_assign = -1; + init_bit_vec(&tmp_assigns[0], sizeof(tmp_assigns)); + if (reg_debug) + printf("Get assignment for vreg %d\n", vreg); + while ((preg = get_tentative_assign(c, vreg, &tmp_assigns[0])) != -1) { + int used_vreg; + if (reg_debug) + printf("checking preg %d\n", preg); + if (preg >= state->reg_count) { + int i; + fpregs = realloc(fpregs, sizeof(reg_state) * (preg + 1)); + ipregs = realloc(ipregs, sizeof(reg_state) * (preg + 1)); + state->fpregs = fpregs; + state->ipregs = ipregs; + for (i = state->reg_count; i <= preg; i++) { + ipregs[i].holds = fpregs[i].holds = -1; + } + switch (dill_type_of(c, vreg)) { + case DILL_F: + case DILL_D: + pregs = state->fpregs; + break; + default: + pregs = state->ipregs; + break; + } + state->reg_count = preg + 1; + } + used_vreg = pregs[preg].holds; + if (used_vreg == -1) { + ret_reg = preg; + if (reg_debug) + printf("preg %d empty, assigning to vreg %d\n", preg, vreg); + break; + } + if ((get_assign_loc(state, used_vreg) == loc) && src) { + if (reg_debug) + printf("preg %d assigned to vreg %d at this loc\n", preg, + used_vreg); + continue; + } + if ((get_last_use(state, used_vreg) < loc) || + (!src && (get_last_use(state, used_vreg) == loc))) { + ret_reg = preg; + if (reg_debug) + printf( + "preg %d assigned to vreg %d, but that vreg is done, " + "assigning\n", + preg, used_vreg); + break; + } + if (tentative_assign == -1) { + tentative_assign = preg; + if (reg_debug) + printf("preg %d is new tentative assign\n", preg); + } else if (get_use_metric(state, pregs[tentative_assign].holds) > + get_use_metric(state, used_vreg)) { + if (reg_debug) + printf("preg %d is better tentative assign\n", preg); + tentative_assign = preg; + } else { + if (reg_debug) + printf("previous assign %d was better tentative assign\n", + tentative_assign); + } + } + if (ret_reg == -1) + ret_reg = tentative_assign; + put_tentative_assigns(c, -1, &tmp_assigns[0], dill_type_of(c, vreg)); + } + if (ret_reg != -1) + old_vreg = pregs[ret_reg].holds; if (old_vreg != -1) { - /* if this is not the same as the old assignment */ - if (((get_last_use(state, old_vreg) > loc) || live_at_end(bb, old_vreg))&& - update_in_reg(state, old_vreg)) { - int offset = offset_of(c, old_vreg); - int typ = dill_type_of(c, old_vreg); - set_value_in_mem(state, old_vreg, 1); - set_update_in_reg(state, old_vreg, 0); - if (offset == 0xdeadbeef) { - /* not previously spilled */ - offset = vregs[old_vreg-100].offset = dill_local(c, typ); - } - /* spill vreg to memory */ - if (reg_debug) - printf("Spilling vreg %d to memory, new assignment is %d\n", - old_vreg, vreg); - if (old_vreg >= 100) { - c->j->storei(c, typ, 0, ret_reg, c->dill_local_pointer, offset); - } else { - c->j->storei(c, typ, 0, ret_reg, c->dill_param_reg_pointer, offset); - } - } - set_in_reg(state, old_vreg, -1); + /* if this is not the same as the old assignment */ + if (((get_last_use(state, old_vreg) > loc) || + live_at_end(bb, old_vreg)) && + update_in_reg(state, old_vreg)) { + int offset = offset_of(c, old_vreg); + int typ = dill_type_of(c, old_vreg); + set_value_in_mem(state, old_vreg, 1); + set_update_in_reg(state, old_vreg, 0); + if (offset == 0xdeadbeef) { + /* not previously spilled */ + offset = vregs[old_vreg - 100].offset = dill_local(c, typ); + } + /* spill vreg to memory */ + if (reg_debug) + printf("Spilling vreg %d to memory, new assignment is %d\n", + old_vreg, vreg); + if (old_vreg >= 100) { + c->j->storei(c, typ, 0, ret_reg, c->dill_local_pointer, offset); + } else { + c->j->storei(c, typ, 0, ret_reg, c->dill_param_reg_pointer, + offset); + } + } + set_in_reg(state, old_vreg, -1); } if (src && value_in_mem(state, vreg)) { - int offset = offset_of(c, vreg); - int typ = dill_type_of(c, vreg); - if (offset == 0xdeadbeef) { - /* not previously assigned */ - printf("Virtual register %d used as source but not previously assigned \n", vreg); - offset = 0; - } - if (reg_debug) - printf("Loading vreg %d from offset %d into preg %d\n", - vreg, offset, ret_reg); - if (vreg >= 100) { - c->j->loadi(c, typ, 0, ret_reg, c->dill_local_pointer, offset); - } else { - c->j->loadi(c, typ, 0, ret_reg, c->dill_param_reg_pointer, offset); - } + int offset = offset_of(c, vreg); + int typ = dill_type_of(c, vreg); + if (offset == 0xdeadbeef) { + /* not previously assigned */ + printf( + "Virtual register %d used as source but not previously " + "assigned \n", + vreg); + offset = 0; + } + if (reg_debug) + printf("Loading vreg %d from offset %d into preg %d\n", vreg, + offset, ret_reg); + if (vreg >= 100) { + c->j->loadi(c, typ, 0, ret_reg, c->dill_local_pointer, offset); + } else { + c->j->loadi(c, typ, 0, ret_reg, c->dill_param_reg_pointer, offset); + } } else { - set_update_in_reg(state, vreg, 1); + set_update_in_reg(state, vreg, 1); } - if (ret_reg != -1) pregs[ret_reg].holds = vreg; + if (ret_reg != -1) + pregs[ret_reg].holds = vreg; set_in_reg(state, vreg, ret_reg); set_assign_loc(state, vreg, loc); - if (src && (ret_reg == -1) && !value_in_mem(state,vreg)) { - /* special x86 no float regs case */ - int offset = offset_of(c, vreg); - int typ = dill_type_of(c, vreg); - if (reg_debug) - printf("Special x86 loading vreg %d from offset %d into preg %d\n", - vreg, offset, ret_reg); - if (vreg >= 100) { - c->j->loadi(c, typ, 0, ret_reg, c->dill_local_pointer, offset); - } else { - c->j->loadi(c, typ, 0, ret_reg, c->dill_param_reg_pointer, offset); - } + if (src && (ret_reg == -1) && !value_in_mem(state, vreg)) { + /* special x86 no float regs case */ + int offset = offset_of(c, vreg); + int typ = dill_type_of(c, vreg); + if (reg_debug) + printf("Special x86 loading vreg %d from offset %d into preg %d\n", + vreg, offset, ret_reg); + if (vreg >= 100) { + c->j->loadi(c, typ, 0, ret_reg, c->dill_local_pointer, offset); + } else { + c->j->loadi(c, typ, 0, ret_reg, c->dill_param_reg_pointer, offset); + } } return ret_reg; } static void -update_vreg_info(reg_state *s, basic_block bb, virtual_insn *ip, int loc) +update_vreg_info(reg_state* s, basic_block bb, virtual_insn* ip, int loc) { int i; int used[4]; insn_uses(ip, &used[0]); used[3] = insn_defines(ip); for (i = 0; i < 4; i++) { - if (used[i] == -1) continue; - if (i < 3) { - set_last_use(s, used[i], loc); - } - if (value_in_mem(s, used[i]) == -1) { - set_value_in_mem(s, used[i], loc); /* first use */ - } - if (used[i] >= 100) { - s->c->p->vregs[used[i]-100].use_metric++; - } else { - if (!s->c->p->c_param_args[used[i]].is_register) { - s->param_info[used[i]].use_metric++; - } - } + if (used[i] == -1) + continue; + if (i < 3) { + set_last_use(s, used[i], loc); + } + if (value_in_mem(s, used[i]) == -1) { + set_value_in_mem(s, used[i], loc); /* first use */ + } + if (used[i] >= 100) { + s->c->p->vregs[used[i] - 100].use_metric++; + } else { + if (!s->c->p->c_param_args[used[i]].is_register) { + s->param_info[used[i]].use_metric++; + } + } } } static void -new_emit_insns(dill_stream c, void *insns, label_translation_table ltable, - virtual_mach_info vmi) +new_emit_insns(dill_stream c, + void* insns, + label_translation_table ltable, + virtual_mach_info vmi) { int label_xlate = 0; - int i, j = 0; + size_t i, j = 0; reg_state state; if (count_verbose == -1) { - count_verbose = (getenv ("DILL_COUNTS") != NULL); + count_verbose = (getenv("DILL_COUNTS") != NULL); } init_reg_state(&state, c); state.c = c; - for (j=0; j < c->p->vreg_count; j++) { - if (dill_type_of(c, 100 + j) == DILL_B) { - /* offset is really size, fix that */ - c->p->vregs[j].offset = dill_localb(c, c->p->vregs[j].offset); - } + for (j = 0; j < c->p->vreg_count; j++) { + if (dill_type_of(c, 100 + j) == DILL_B) { + /* offset is really size, fix that */ + c->p->vregs[j].offset = dill_localb(c, c->p->vregs[j].offset); + } } for (i = 0; i < vmi->bbcount; i++) { - basic_block bb = &vmi->bblist[i]; - int insn_count = bb->end - bb->start; - int insn_start; - for (j=0; j < c->p->vreg_count; j++) { - c->p->vregs[j].assign_loc = -1; - c->p->vregs[j].in_reg = -1; - c->p->vregs[j].last_use = -1; - c->p->vregs[j].use_metric = 0; - c->p->vregs[j].update_in_reg = 0; - c->p->vregs[j].value_in_mem = -1; - } - for (j=0; j < c->p->c_param_count; j++) { - state.param_info[j].assign_loc = -1; - state.param_info[j].in_reg = -1; - state.param_info[j].last_use = -1; - state.param_info[j].use_metric = 0; - state.param_info[j].update_in_reg = 0; - state.param_info[j].value_in_mem = -1; - } - for (j = bb->start; j <= bb->end; j++) { - virtual_insn *ip = &((virtual_insn *)insns)[j]; - update_vreg_info(&state, bb, ip, j); - } - for (j=0; j < c->p->vreg_count; j++) { - if (get_last_use(&state, j + 100) == -1) continue; - c->p->vregs[j].use_metric *= insn_count; - c->p->vregs[j].use_metric /= (c->p->vregs[j].last_use - - c->p->vregs[j].value_in_mem +1); - c->p->vregs[j].value_in_mem = - bit_vec_is_set(bb->regs_used, j); - } - for (j=0; j < c->p->c_param_count; j++) { - if (c->p->c_param_args[j].is_register) { - state.param_info[j].update_in_reg = 0; - state.param_info[j].value_in_mem = 0; - state.param_info[j].in_reg = c->p->c_param_args[j].in_reg; - } else { - state.param_info[j].update_in_reg = 0; - state.param_info[j].value_in_mem = 1; - state.param_info[j].in_reg = -1; - } - } - reset_reg_state(&state); - if (c->dill_debug) { - printf("============= Starting basic block %d ===========\n", i); - dump_bb(c, bb, i); - } - insn_start = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); - for (j = bb->start; j <= bb->end; j++) { - virtual_insn *ip; - int vused[3]; - int vdest; - int pused[3]; - int pdest = -1; - int loc; - int i; - int insn_code; - state.bb = bb; - ip = &((virtual_insn *)insns)[j]; - insn_code = ip->insn_code; - loc = (int)((char*)ip - (char*)insns); - while (ltable[label_xlate].old_location == loc) { - dill_mark_label(c, ltable[label_xlate].new_label); - label_xlate++; - } - if (c->dill_debug) { - printf(" v loc(%d) ", loc); - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - if (j == bb->end) { - /* in case we branch out of this puppy */ - spill_current_pregs(&state); - } - - insn_uses(ip, &vused[0]); - vdest = insn_defines(ip); - if (state.ret_vreg != -1) { - if (c->p->vregs[state.ret_vreg - 100].last_use == j) { - /* only used here, use the ret ret */ - c->p->vregs[state.ret_vreg - 100].in_reg = state.ret_reg; - } else { - int tmp = select_reg(&state, state.ret_vreg, j, 0); - ( c->j->mov)(c, dill_type_of(c, state.ret_vreg), 0, tmp, - state.ret_reg); - } - state.ret_vreg = -1; - } - for(i=0; (i < 3) && (vused[i] != -1); i++) { - pused[i] = select_reg(&state, vused[i], j, 1/*src*/); - } - if (vdest != -1) { - pdest = select_reg(&state, vdest, j, 0/*dest*/); - } - if (c->dill_debug && ((vdest != -1) || (vused[0] != -1))) { - printf("\tvregs\t\t"); - if (vdest != -1) { - printf(" %c%d = ", OPND(vdest)); - dill_dump_reg(c, dill_type_of(c, vdest), pdest); - printf("(%d) - ", pdest); - } - for(i=0; (i < 3) && (vused[i] != -1); i++) { - printf(" %c%d = ", OPND(vused[i])); - dill_dump_reg(c, dill_type_of(c, vused[i]), pused[i]); - printf("(%d) - ", pused[i]); - } - printf("\n"); - } - switch(ip->class_code) { - case iclass_arith3: - /* arith 3 operand integer insns */ - ( c->j->jmp_a3)[insn_code](c, - c->j->a3_data[insn_code].data1, - c->j->a3_data[insn_code].data2, - pdest, pused[0], pused[1]); - break; - case iclass_compare: - ( c->j->jmp_c)[insn_code](c, - c->j->c_data[insn_code].data1, - c->j->c_data[insn_code].data2, - pdest, pused[0], pused[1]); - break; - case iclass_arith2: - ( c->j->jmp_a2)[insn_code](c, - c->j->a2_data[insn_code].data1, - c->j->a2_data[insn_code].data2, - pdest, pused[0]); - break; - case iclass_arith3i: - /* arith 3 immediate operand integer insns */ - ( c->j->jmp_a3i)[insn_code](c, - c->j->a3i_data[insn_code].data1, - c->j->a3i_data[insn_code].data2, - pdest, pused[0], - ip->opnds.a3i.u.imm); - break; - case iclass_ret: - ( c->j->ret)(c, ip->insn_code, 0, pused[0]); - break; - case iclass_convert: - /* conversion insns */ - ( c->j->convert)(c, (ip->insn_code >> 4) & 0xf, - ip->insn_code & 0xf, pdest, pused[0]); - break; - case iclass_loadstore: { - /* load/store 3 operand integer insns */ - int store = ((ip->insn_code & 0x10) == 0x10); - int bswap = ((ip->insn_code & 0x20) == 0x20); - int typ = ip->insn_code & 0xf; - if (store == 0) { - if (bswap) { - ( c->j->bsload)(c, typ, 0, pdest, pused[0], pused[1]); - } else { - ( c->j->load)(c, typ, 0, pdest, pused[0], pused[1]); - } - } else { - ( c->j->store)(c, typ, 0, pused[2], pused[0], pused[1]); - } - } - break; - case iclass_lea: { - int offset = (int) ip->opnds.a3i.u.imm + offset_of(c, vused[0]); - int add_code = dill_jmp_addp; - if (offset == 0) { - c->j->mov(c, DILL_P, 0, pdest, dill_lp(c)); - } else { - (c->j->jmp_a3i)[add_code](c, - c->j->a3i_data[add_code].data1, - c->j->a3i_data[add_code].data2, - pdest, dill_lp(c), offset); - } - break; - } - case iclass_loadstorei: - /* load store immediate operand integer insns */ - if ((ip->insn_code & 0x10) == 0) { - if ((ip->insn_code & 0x20) == 0x20) { - ( c->j->bsloadi)(c, ip->insn_code & 0xf, 0, - pdest, pused[0], - ip->opnds.a3i.u.imm); - } else { - ( c->j->loadi)(c, ip->insn_code & 0xf, 0, - pdest, pused[0], - ip->opnds.a3i.u.imm); - } - } else { - /* a store, dest is the source of the store */ - ( c->j->storei)(c, ip->insn_code & 0xf, 0, - pused[1], pused[0], - ip->opnds.a3i.u.imm); - } - break; - case iclass_set: - /* load store immediate operand integer insns */ - ( c->j->set)(c, ip->insn_code & 0xf, 0, pdest, - ip->opnds.a3i.u.imm); - break; - case iclass_setf: - ( c->j->setf)(c, ip->insn_code & 0xf, 0, pdest, - ip->opnds.sf.imm); - break; - case iclass_mov: - ( c->j->mov)(c, ip->insn_code & 0xf, 0, pdest, pused[0]); - break; - case iclass_reti: - /* return immediate integer insns */ - ( c->j->reti)(c, ip->insn_code & 0xf, 0, ip->opnds.a3i.u.imm); - break; - case iclass_branch: - { - /* branch */ - int br_op = ip->insn_code; - int label = get_new_label(ip->opnds.br.label, ltable); - ( c->j->jmp_b)[br_op](c, c->j->b_data[br_op].data1, - c->j->b_data[br_op].data2, - pused[0], pused[1], label); - } - break; - case iclass_branchi: - { - /* branch immediate */ - int br_op = ip->insn_code; - int label = get_new_label(ip->opnds.bri.label, ltable); - intptr_t imm = ip->opnds.bri.imm_l; - ( c->j->jmp_bi)[br_op](c, c->j->b_data[br_op].data1, - c->j->b_data[br_op].data2, - pused[0], imm, label); - } - break; - case iclass_jump_to_label: - { - /* branch immediate */ - int label = get_new_label(ip->opnds.br.label, ltable); - dill_jv(c, label); - } - break; - case iclass_jump_to_reg: - dill_jp(c, pused[0]); - break; - case iclass_jump_to_imm: - dill_jpi(c, ip->opnds.bri.imm_a); - break; - case iclass_special: - dill_special(c, ip->opnds.spec.type, ip->opnds.spec.param); - break; - case iclass_call: - { - int reg = ip->insn_code & 0x10; - int typ = ip->insn_code & 0xf; - int rr; - - if (reg != 0) { - rr = dill_pcallr(c, typ, pused[0]); - } else { - rr = dill_pcall(c, typ, ip->opnds.calli.imm_a, ip->opnds.calli.xfer_name); - } - state.ret_reg = rr; - state.ret_vreg = vdest; - pushpop_inuse_regs(c, 1, ip); - } - break; - case iclass_push: - { - int typ = ip->insn_code & 0xf; - if ((short)ip->opnds.a1.src < 0) { - pushpop_inuse_regs(c, 0, ip); - dill_push_arg(c, typ, (short)ip->opnds.a1.src); - } else { - dill_push_arg(c, typ, pused[0]); - } - } - break; - case iclass_pushi:{ - int typ = ip->insn_code & 0xf; - if (typ == DILL_P) { - void *imm = ip->opnds.a3i.u.imm_a; - dill_push_argpi(c, imm); - } else { - intptr_t imm = ip->opnds.a3i.u.imm; - dill_push_argii(c, imm); - } - break; - } - case iclass_pushf: - c->j->pushfi(c, ip->insn_code & 0xf, ip->opnds.sf.imm); - break; - case iclass_nop: - break; - case iclass_mark_label: - break; - } - if ((pdest == -1) && (vdest != -1)) { - /* special x86 no float regs case */ - int offset = offset_of(c, vdest); - int typ = dill_type_of(c, vdest); - set_value_in_mem(&state, vdest, 1); - set_update_in_reg(&state, vdest, 0); - if (offset == 0xdeadbeef) { - /* not previously spilled */ - offset = c->p->vregs[vdest-100].offset = dill_local(c, typ); - } - /* spill vreg to memory */ - if (vdest >= 100) { - c->j->storei(c, typ, 0, -1, c->dill_local_pointer, offset); - } else { - c->j->storei(c, typ, 0, -1, c->dill_param_reg_pointer, offset); - } - set_in_reg(&state, vdest, -1); - state.ret_vreg = -1; - } - } - spill_current_pregs(&state); - if (count_verbose) { - int insn_end = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); - printf("Basic Block %d, %d virtual instructions, %d physical instructions\n", - i, insn_count, c->j->count_insn(c, insn_start, insn_end)); - } - } - if ((unsigned)ltable[label_xlate].old_location == j * sizeof(virtual_insn)) { - dill_mark_label(c, ltable[label_xlate].new_label); - label_xlate++; + basic_block bb = &vmi->bblist[i]; + int insn_count = (int)(bb->end - bb->start); + int insn_start; + for (j = 0; j < c->p->vreg_count; j++) { + c->p->vregs[j].assign_loc = -1; + c->p->vregs[j].in_reg = -1; + c->p->vregs[j].last_use = -1; + c->p->vregs[j].use_metric = 0; + c->p->vregs[j].update_in_reg = 0; + c->p->vregs[j].value_in_mem = -1; + } + for (j = 0; j < c->p->c_param_count; j++) { + state.param_info[j].assign_loc = -1; + state.param_info[j].in_reg = -1; + state.param_info[j].last_use = -1; + state.param_info[j].use_metric = 0; + state.param_info[j].update_in_reg = 0; + state.param_info[j].value_in_mem = -1; + } + for (j = (size_t)bb->start; j <= (size_t)bb->end; j++) { + virtual_insn* ip = &((virtual_insn*)insns)[j]; + update_vreg_info(&state, bb, ip, (int)j); + } + for (j = 0; j < c->p->vreg_count; j++) { + if (get_last_use(&state, (int)j + 100) == -1) + continue; + c->p->vregs[j].use_metric *= insn_count; + c->p->vregs[j].use_metric /= + (c->p->vregs[j].last_use - c->p->vregs[j].value_in_mem + 1); + c->p->vregs[j].value_in_mem = bit_vec_is_set(bb->regs_used, (int)j); + } + for (j = 0; j < c->p->c_param_count; j++) { + if (c->p->c_param_args[j].is_register) { + state.param_info[j].update_in_reg = 0; + state.param_info[j].value_in_mem = 0; + state.param_info[j].in_reg = c->p->c_param_args[j].in_reg; + } else { + state.param_info[j].update_in_reg = 0; + state.param_info[j].value_in_mem = 1; + state.param_info[j].in_reg = -1; + } + } + reset_reg_state(&state); + if (c->dill_debug) { + printf("============= Starting basic block %zd ===========\n", i); + dump_bb(c, bb, (int)i); + } + insn_start = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); + for (j = (size_t)bb->start; j <= (size_t)bb->end; j++) { + virtual_insn* ip; + int vused[3]; + int vdest; + int pused[3]; + int pdest = -1; + int loc; + int i; + int insn_code; + state.bb = bb; + ip = &((virtual_insn*)insns)[j]; + insn_code = ip->insn_code; + loc = (int)((char*)ip - (char*)insns); + while (ltable[label_xlate].old_location == loc) { + dill_mark_label(c, ltable[label_xlate].new_label); + label_xlate++; + } + if (c->dill_debug) { + printf(" v loc(%d) ", loc); + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + if (j == bb->end) { + /* in case we branch out of this puppy */ + spill_current_pregs(&state); + } + + insn_uses(ip, &vused[0]); + vdest = insn_defines(ip); + if (state.ret_vreg != -1) { + if (c->p->vregs[state.ret_vreg - 100].last_use == j) { + /* only used here, use the ret ret */ + c->p->vregs[state.ret_vreg - 100].in_reg = state.ret_reg; + } else { + int tmp = select_reg(&state, state.ret_vreg, (int)j, 0); + (c->j->mov)(c, dill_type_of(c, state.ret_vreg), 0, tmp, + state.ret_reg); + } + state.ret_vreg = -1; + } + for (i = 0; (i < 3) && (vused[i] != -1); i++) { + pused[i] = select_reg(&state, vused[i], (int)j, 1 /*src*/); + } + if (vdest != -1) { + pdest = select_reg(&state, vdest, (int)j, 0 /*dest*/); + } + if (c->dill_debug && ((vdest != -1) || (vused[0] != -1))) { + printf("\tvregs\t\t"); + if (vdest != -1) { + printf(" %c%d = ", OPND(vdest)); + dill_dump_reg(c, dill_type_of(c, vdest), pdest); + printf("(%d) - ", pdest); + } + for (i = 0; (i < 3) && (vused[i] != -1); i++) { + printf(" %c%d = ", OPND(vused[i])); + dill_dump_reg(c, dill_type_of(c, vused[i]), pused[i]); + printf("(%d) - ", pused[i]); + } + printf("\n"); + } + switch (ip->class_code) { + case iclass_arith3: + /* arith 3 operand integer insns */ + (c->j->jmp_a3)[insn_code](c, c->j->a3_data[insn_code].data1, + c->j->a3_data[insn_code].data2, pdest, + pused[0], pused[1]); + break; + case iclass_compare: + (c->j->jmp_c)[insn_code](c, c->j->c_data[insn_code].data1, + c->j->c_data[insn_code].data2, pdest, + pused[0], pused[1]); + break; + case iclass_arith2: + (c->j->jmp_a2)[insn_code](c, c->j->a2_data[insn_code].data1, + c->j->a2_data[insn_code].data2, pdest, + pused[0]); + break; + case iclass_arith3i: + /* arith 3 immediate operand integer insns */ + (c->j->jmp_a3i)[insn_code](c, c->j->a3i_data[insn_code].data1, + c->j->a3i_data[insn_code].data2, + pdest, pused[0], + ip->opnds.a3i.u.imm); + break; + case iclass_ret: + (c->j->ret)(c, ip->insn_code, 0, pused[0]); + break; + case iclass_convert: + /* conversion insns */ + (c->j->convert)(c, (ip->insn_code >> 4) & 0xf, + ip->insn_code & 0xf, pdest, pused[0]); + break; + case iclass_loadstore: { + /* load/store 3 operand integer insns */ + int store = ((ip->insn_code & 0x10) == 0x10); + int bswap = ((ip->insn_code & 0x20) == 0x20); + int typ = ip->insn_code & 0xf; + if (store == 0) { + if (bswap) { + (c->j->bsload)(c, typ, 0, pdest, pused[0], pused[1]); + } else { + (c->j->load)(c, typ, 0, pdest, pused[0], pused[1]); + } + } else { + (c->j->store)(c, typ, 0, pused[2], pused[0], pused[1]); + } + } break; + case iclass_lea: { + int offset = (int)ip->opnds.a3i.u.imm + offset_of(c, vused[0]); + int add_code = dill_jmp_addp; + if (offset == 0) { + c->j->mov(c, DILL_P, 0, pdest, dill_lp(c)); + } else { + (c->j->jmp_a3i)[add_code](c, c->j->a3i_data[add_code].data1, + c->j->a3i_data[add_code].data2, + pdest, dill_lp(c), offset); + } + break; + } + case iclass_loadstorei: + /* load store immediate operand integer insns */ + if ((ip->insn_code & 0x10) == 0) { + if ((ip->insn_code & 0x20) == 0x20) { + (c->j->bsloadi)(c, ip->insn_code & 0xf, 0, pdest, + pused[0], ip->opnds.a3i.u.imm); + } else { + (c->j->loadi)(c, ip->insn_code & 0xf, 0, pdest, + pused[0], ip->opnds.a3i.u.imm); + } + } else { + /* a store, dest is the source of the store */ + (c->j->storei)(c, ip->insn_code & 0xf, 0, pused[1], + pused[0], ip->opnds.a3i.u.imm); + } + break; + case iclass_set: + /* load store immediate operand integer insns */ + (c->j->set)(c, ip->insn_code & 0xf, 0, pdest, + ip->opnds.a3i.u.imm); + break; + case iclass_setf: + (c->j->setf)(c, ip->insn_code & 0xf, 0, pdest, + ip->opnds.sf.imm); + break; + case iclass_mov: + (c->j->mov)(c, ip->insn_code & 0xf, 0, pdest, pused[0]); + break; + case iclass_reti: + /* return immediate integer insns */ + (c->j->reti)(c, ip->insn_code & 0xf, 0, ip->opnds.a3i.u.imm); + break; + case iclass_branch: { + /* branch */ + int br_op = ip->insn_code; + int label = get_new_label(ip->opnds.br.label, ltable); + (c->j->jmp_b)[br_op](c, c->j->b_data[br_op].data1, + c->j->b_data[br_op].data2, pused[0], + pused[1], label); + } break; + case iclass_branchi: { + /* branch immediate */ + int br_op = ip->insn_code; + int label = get_new_label(ip->opnds.bri.label, ltable); + intptr_t imm = ip->opnds.bri.imm_l; + (c->j->jmp_bi)[br_op](c, c->j->b_data[br_op].data1, + c->j->b_data[br_op].data2, pused[0], imm, + label); + } break; + case iclass_jump_to_label: { + /* branch immediate */ + int label = get_new_label(ip->opnds.br.label, ltable); + dill_jv(c, label); + } break; + case iclass_jump_to_reg: + dill_jp(c, pused[0]); + break; + case iclass_jump_to_imm: + dill_jpi(c, ip->opnds.bri.imm_a); + break; + case iclass_special: + dill_special(c, ip->opnds.spec.type, ip->opnds.spec.param); + break; + case iclass_call: { + int reg = ip->insn_code & 0x10; + int typ = ip->insn_code & 0xf; + int rr; + + if (reg != 0) { + rr = dill_pcallr(c, typ, pused[0]); + } else { + rr = dill_pcall(c, typ, ip->opnds.calli.imm_a, + ip->opnds.calli.xfer_name); + } + state.ret_reg = rr; + state.ret_vreg = vdest; + pushpop_inuse_regs(c, 1, ip); + } break; + case iclass_push: { + int typ = ip->insn_code & 0xf; + if ((short)ip->opnds.a1.src < 0) { + pushpop_inuse_regs(c, 0, ip); + dill_push_arg(c, typ, (short)ip->opnds.a1.src); + } else { + dill_push_arg(c, typ, pused[0]); + } + } break; + case iclass_pushi: { + int typ = ip->insn_code & 0xf; + if (typ == DILL_P) { + void* imm = ip->opnds.a3i.u.imm_a; + dill_push_argpi(c, imm); + } else { + intptr_t imm = ip->opnds.a3i.u.imm; + dill_push_argii(c, imm); + } + break; + } + case iclass_pushf: + c->j->pushfi(c, ip->insn_code & 0xf, ip->opnds.sf.imm); + break; + case iclass_nop: + break; + case iclass_mark_label: + break; + } + if ((pdest == -1) && (vdest != -1)) { + /* special x86 no float regs case */ + int offset = offset_of(c, vdest); + int typ = dill_type_of(c, vdest); + set_value_in_mem(&state, vdest, 1); + set_update_in_reg(&state, vdest, 0); + if (offset == 0xdeadbeef) { + /* not previously spilled */ + offset = c->p->vregs[vdest - 100].offset = + dill_local(c, typ); + } + /* spill vreg to memory */ + if (vdest >= 100) { + c->j->storei(c, typ, 0, -1, c->dill_local_pointer, offset); + } else { + c->j->storei(c, typ, 0, -1, c->dill_param_reg_pointer, + offset); + } + set_in_reg(&state, vdest, -1); + state.ret_vreg = -1; + } + } + spill_current_pregs(&state); + if (count_verbose) { + int insn_end = (int)((char*)c->p->cur_ip - (char*)c->p->code_base); + printf( + "Basic Block %zd, %d virtual instructions, %d physical " + "instructions\n", + i, insn_count, c->j->count_insn(c, insn_start, insn_end)); + } + } + if ((unsigned)ltable[label_xlate].old_location == + j * sizeof(virtual_insn)) { + dill_mark_label(c, ltable[label_xlate].new_label); + label_xlate++; } if (ltable[label_xlate].old_location != -1) { - int loc = (int)((char*)&((virtual_insn *)insns)[j] - ((char*) insns)); - while (ltable[label_xlate].old_location == loc) { - dill_mark_label(c, ltable[label_xlate].new_label); - label_xlate++; - } - if (ltable[label_xlate].old_location != -1) { - printf("Some labels2 (%d, old loc %d name \"%s\") not placed\n", label_xlate, - ltable[label_xlate].old_location, c->p->branch_table.label_name[ltable[label_xlate].old_location]); - } + int loc = (int)((char*)&((virtual_insn*)insns)[j] - ((char*)insns)); + while (ltable[label_xlate].old_location == loc) { + dill_mark_label(c, ltable[label_xlate].new_label); + label_xlate++; + } + if (ltable[label_xlate].old_location != -1) { + printf("Some labels2 (%d, old loc %d name \"%s\") not placed\n", + label_xlate, ltable[label_xlate].old_location, + c->p->branch_table + .label_name[ltable[label_xlate].old_location]); + } } free(state.fpregs); free(state.ipregs); @@ -3354,443 +3396,462 @@ new_emit_insns(dill_stream c, void *insns, label_translation_table ltable, } static void -apply_to_each(dill_stream c, void *insns, virtual_mach_info vmi, - apply_func func) +apply_to_each(dill_stream c, + void* insns, + virtual_mach_info vmi, + apply_func func) { - int i, j = 0; + size_t i, j = 0; for (i = 0; i < vmi->bbcount; i++) { - basic_block bb = &vmi->bblist[i]; - for (j = bb->start; j <= bb->end; j++) { - (func)(c, bb, insns, j); - } + basic_block bb = &vmi->bblist[i]; + for (j = (size_t)bb->start; j <= (size_t)bb->end; j++) { + (func)(c, bb, insns, (int)j); + } } } -static int -const_prop_ip(dill_stream c, basic_block bb, virtual_insn *ip, virtual_insn *set_ip, int one_only) +static int +const_prop_ip(dill_stream c, + basic_block bb, + virtual_insn* ip, + virtual_insn* set_ip, + int one_only) { int set_vreg = set_ip->opnds.a3i.dest; int set_typ = set_ip->insn_code & 0xf; int found = 0; union { - intptr_t imm; - char *imm_a; + intptr_t imm; + char* imm_a; } set; set.imm = set_ip->opnds.a3i.u.imm; set.imm_a = set_ip->opnds.a3i.u.imm_a; - switch(ip->class_code) { - case iclass_arith3: - { - /* arith 3 operand integer insns */ - int dest_vreg = ip->opnds.a3.dest; - int src1_vreg = ip->opnds.a3.src1; - int src2_vreg = ip->opnds.a3.src2; - int insn_code = ip->insn_code; - if ((src1_vreg == set_vreg) && - is_commutative(insn_code)) { - src2_vreg = ip->opnds.a3.src1; - src1_vreg = ip->opnds.a3.src2; - } - if (src2_vreg == set_vreg) { - int typ = ip->insn_code & 0xf; - if (c->dill_debug) { - printf(" Replacing "); - virtual_print_insn(c, NULL, ip); - printf(" with "); - } - ip->class_code = iclass_arith3i; - ip->opnds.a3i.dest = dest_vreg; - ip->opnds.a3i.src = src1_vreg; - if (typ != DILL_P) { - ip->opnds.a3i.u.imm = set.imm; - } else { - ip->opnds.a3i.u.imm_a = set.imm_a; - } - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - found++; - } - } - break; - case iclass_arith2: - { - /* arith 2 operand integer insns */ - int dest_vreg = ip->opnds.a2.dest; - int src_vreg = ip->opnds.a2.src; - int insn_code = ip->insn_code; - if (src_vreg == set_vreg) { - int typ = ip->insn_code & 0xf; - if (c->dill_debug) { - printf(" Replacing "); - virtual_print_insn(c, NULL, ip); - printf(" with "); - } - ip->class_code = iclass_set; - ip->opnds.a3i.dest = dest_vreg; - switch(insn_code) { - case dill_jmp_negi: case dill_jmp_negu: - case dill_jmp_negl: case dill_jmp_negul: - set.imm = -set.imm; - break; - case dill_jmp_comi: case dill_jmp_comu: - case dill_jmp_coml: case dill_jmp_comul: - set.imm = ~set.imm; - break; - case dill_jmp_noti: case dill_jmp_notu: - case dill_jmp_notl: case dill_jmp_notul: - set.imm = !set.imm; - break; - default: - assert(0); - break; - } - if (typ != DILL_P) { - ip->opnds.a3i.u.imm = set.imm; - } else { - ip->opnds.a3i.u.imm_a = set.imm_a; - } - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - found++; - } - break; + switch (ip->class_code) { + case iclass_arith3: { + /* arith 3 operand integer insns */ + int dest_vreg = ip->opnds.a3.dest; + int src1_vreg = ip->opnds.a3.src1; + int src2_vreg = ip->opnds.a3.src2; + int insn_code = ip->insn_code; + if ((src1_vreg == set_vreg) && is_commutative(insn_code)) { + src2_vreg = ip->opnds.a3.src1; + src1_vreg = ip->opnds.a3.src2; + } + if (src2_vreg == set_vreg) { + int typ = ip->insn_code & 0xf; + if (c->dill_debug) { + printf(" Replacing "); + virtual_print_insn(c, NULL, ip); + printf(" with "); + } + ip->class_code = iclass_arith3i; + ip->opnds.a3i.dest = dest_vreg; + ip->opnds.a3i.src = src1_vreg; + if (typ != DILL_P) { + ip->opnds.a3i.u.imm = set.imm; + } else { + ip->opnds.a3i.u.imm_a = set.imm_a; + } + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + found++; + } + } break; + case iclass_arith2: { + /* arith 2 operand integer insns */ + int dest_vreg = ip->opnds.a2.dest; + int src_vreg = ip->opnds.a2.src; + int insn_code = ip->insn_code; + if (src_vreg == set_vreg) { + int typ = ip->insn_code & 0xf; + if (c->dill_debug) { + printf(" Replacing "); + virtual_print_insn(c, NULL, ip); + printf(" with "); + } + ip->class_code = iclass_set; + ip->opnds.a3i.dest = dest_vreg; + switch (insn_code) { + case dill_jmp_negi: + case dill_jmp_negu: + case dill_jmp_negl: + case dill_jmp_negul: + set.imm = -set.imm; + break; + case dill_jmp_comi: + case dill_jmp_comu: + case dill_jmp_coml: + case dill_jmp_comul: + set.imm = ~set.imm; + break; + case dill_jmp_noti: + case dill_jmp_notu: + case dill_jmp_notl: + case dill_jmp_notul: + set.imm = !set.imm; + break; + default: + assert(0); + break; + } + if (typ != DILL_P) { + ip->opnds.a3i.u.imm = set.imm; + } else { + ip->opnds.a3i.u.imm_a = set.imm_a; + } + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + found++; + } + break; } - case iclass_arith3i: - { - /* arith 3 immediate operand integer insns */ - int dest_vreg = ip->opnds.a3i.dest; - int src_vreg = ip->opnds.a3i.src; - int insn_code = ip->insn_code; - union { - intptr_t imm; - char *imm_a; - } u; - u.imm = ip->opnds.a3i.u.imm; - u.imm_a = ip->opnds.a3i.u.imm_a; - if (src_vreg == set_vreg) { - int typ = ip->insn_code & 0xf; - if (c->dill_debug) { - printf(" Replacing "); - virtual_print_insn(c, NULL, ip); - printf(" with "); - } - switch (insn_code) { - case dill_jmp_addi: case dill_jmp_addu: - case dill_jmp_addul: case dill_jmp_addl: - set.imm = set.imm + u.imm; - break; - case dill_jmp_addp: - set.imm_a = set.imm_a + u.imm; - typ = DILL_P; - break; - case dill_jmp_subi: case dill_jmp_subu: - case dill_jmp_subul: case dill_jmp_subl: - set.imm = set.imm - u.imm; - break; - case dill_jmp_subp: - set.imm_a = set.imm_a - u.imm; - typ = DILL_P; - break; - case dill_jmp_muli: case dill_jmp_mulu: - case dill_jmp_mulul: case dill_jmp_mull: - set.imm = set.imm * u.imm; - break; - case dill_jmp_divi: case dill_jmp_divu: - case dill_jmp_divul: case dill_jmp_divl: - set.imm = set.imm / u.imm; - break; - case dill_jmp_modi: case dill_jmp_modu: - case dill_jmp_modul: case dill_jmp_modl: - set.imm = set.imm % u.imm; - break; - case dill_jmp_xori: case dill_jmp_xoru: - case dill_jmp_xorul: case dill_jmp_xorl: - set.imm = set.imm ^ u.imm; - break; - case dill_jmp_andi: case dill_jmp_andu: - case dill_jmp_andul: case dill_jmp_andl: - set.imm = set.imm & u.imm; - break; - case dill_jmp_ori: case dill_jmp_oru: - case dill_jmp_orul: case dill_jmp_orl: - set.imm = set.imm | u.imm; - break; - case dill_jmp_lshi: case dill_jmp_lshu: - case dill_jmp_lshul: case dill_jmp_lshl: - set.imm = set.imm << u.imm; - break; - case dill_jmp_rshi: case dill_jmp_rshu: - case dill_jmp_rshul: case dill_jmp_rshl: - set.imm = set.imm >> u.imm; - break; - default: - assert(0); - } - ip->insn_code = typ; - ip->class_code = iclass_set; - ip->opnds.a3i.dest = dest_vreg; - if (typ != DILL_P) { - ip->opnds.a3i.u.imm = set.imm; - } else { - ip->opnds.a3i.u.imm_a = set.imm_a; - } - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - found++; - } - } - break; - case iclass_ret: - { - /* arith operand integer insns */ - int src_vreg = ip->opnds.a1.src; - if (src_vreg == set_vreg) { - int typ = ip->insn_code & 0xf; - if (c->dill_debug) { - printf(" Replacing "); - virtual_print_insn(c, NULL, ip); - printf(" with "); - } - ip->class_code = iclass_reti; - ip->insn_code = set_typ; - if (typ != DILL_P) { - ip->opnds.a3i.u.imm = set.imm; - } else { - ip->opnds.a3i.u.imm_a = set.imm_a; - } - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - found++; - } - } - break; + case iclass_arith3i: { + /* arith 3 immediate operand integer insns */ + int dest_vreg = ip->opnds.a3i.dest; + int src_vreg = ip->opnds.a3i.src; + int insn_code = ip->insn_code; + union { + intptr_t imm; + char* imm_a; + } u; + u.imm = ip->opnds.a3i.u.imm; + u.imm_a = ip->opnds.a3i.u.imm_a; + if (src_vreg == set_vreg) { + int typ = ip->insn_code & 0xf; + if (c->dill_debug) { + printf(" Replacing "); + virtual_print_insn(c, NULL, ip); + printf(" with "); + } + switch (insn_code) { + case dill_jmp_addi: + case dill_jmp_addu: + case dill_jmp_addul: + case dill_jmp_addl: + set.imm = set.imm + u.imm; + break; + case dill_jmp_addp: + set.imm_a = set.imm_a + u.imm; + typ = DILL_P; + break; + case dill_jmp_subi: + case dill_jmp_subu: + case dill_jmp_subul: + case dill_jmp_subl: + set.imm = set.imm - u.imm; + break; + case dill_jmp_subp: + set.imm_a = set.imm_a - u.imm; + typ = DILL_P; + break; + case dill_jmp_muli: + case dill_jmp_mulu: + case dill_jmp_mulul: + case dill_jmp_mull: + set.imm = set.imm * u.imm; + break; + case dill_jmp_divi: + case dill_jmp_divu: + case dill_jmp_divul: + case dill_jmp_divl: + set.imm = set.imm / u.imm; + break; + case dill_jmp_modi: + case dill_jmp_modu: + case dill_jmp_modul: + case dill_jmp_modl: + set.imm = set.imm % u.imm; + break; + case dill_jmp_xori: + case dill_jmp_xoru: + case dill_jmp_xorul: + case dill_jmp_xorl: + set.imm = set.imm ^ u.imm; + break; + case dill_jmp_andi: + case dill_jmp_andu: + case dill_jmp_andul: + case dill_jmp_andl: + set.imm = set.imm & u.imm; + break; + case dill_jmp_ori: + case dill_jmp_oru: + case dill_jmp_orul: + case dill_jmp_orl: + set.imm = set.imm | u.imm; + break; + case dill_jmp_lshi: + case dill_jmp_lshu: + case dill_jmp_lshul: + case dill_jmp_lshl: + set.imm = set.imm << u.imm; + break; + case dill_jmp_rshi: + case dill_jmp_rshu: + case dill_jmp_rshul: + case dill_jmp_rshl: + set.imm = set.imm >> u.imm; + break; + default: + assert(0); + } + ip->insn_code = typ; + ip->class_code = iclass_set; + ip->opnds.a3i.dest = dest_vreg; + if (typ != DILL_P) { + ip->opnds.a3i.u.imm = set.imm; + } else { + ip->opnds.a3i.u.imm_a = set.imm_a; + } + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + found++; + } + } break; + case iclass_ret: { + /* arith operand integer insns */ + int src_vreg = ip->opnds.a1.src; + if (src_vreg == set_vreg) { + int typ = ip->insn_code & 0xf; + if (c->dill_debug) { + printf(" Replacing "); + virtual_print_insn(c, NULL, ip); + printf(" with "); + } + ip->class_code = iclass_reti; + ip->insn_code = set_typ; + if (typ != DILL_P) { + ip->opnds.a3i.u.imm = set.imm; + } else { + ip->opnds.a3i.u.imm_a = set.imm_a; + } + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + found++; + } + } break; case iclass_convert: { - /* conversion insns */ - int dest_vreg = ip->opnds.a2.dest; - int src_vreg = ip->opnds.a2.src; - int from_type = (ip->insn_code >> 4) & 0xf; - int to_type = ip->insn_code & 0xf; - if (src_vreg == set_vreg) { - if (c->dill_debug) { - printf(" Replacing "); - virtual_print_insn(c, NULL, ip); - printf(" with "); - } - ip->class_code = iclass_set; - ip->insn_code = to_type; - switch(to_type) { - case DILL_C: - ip->opnds.a3i.u.imm = (char)set.imm; - ip->opnds.a3i.dest = dest_vreg; - break; - case DILL_S: - ip->opnds.a3i.u.imm = (short)set.imm; - ip->opnds.a3i.dest = dest_vreg; - case DILL_I: - case DILL_L: - ip->opnds.a3i.u.imm = set.imm; - ip->opnds.a3i.dest = dest_vreg; - break; - case DILL_UC: - ip->opnds.a3i.u.imm = (unsigned char) set.imm; - ip->opnds.a3i.dest = dest_vreg; - break; - case DILL_US: - ip->opnds.a3i.u.imm = (unsigned short) set.imm; - ip->opnds.a3i.dest = dest_vreg; - break; - case DILL_U: - ip->opnds.a3i.u.imm = (unsigned) set.imm; - ip->opnds.a3i.dest = dest_vreg; - break; - case DILL_UL: - ip->opnds.a3i.u.imm = (unsigned long) set.imm; - ip->opnds.a3i.dest = dest_vreg; - break; - case DILL_P: - ip->class_code = iclass_set; - ip->insn_code = DILL_P; - ip->opnds.a3i.u.imm_a = (void*)set.imm; - ip->opnds.a3i.dest = dest_vreg; - break; - case DILL_F: case DILL_D: - ip->class_code = iclass_setf; - ip->insn_code = to_type; - ip->opnds.sf.dest = dest_vreg; - switch(from_type) { - case DILL_UC: case DILL_US: - case DILL_U: case DILL_UL: - ip->opnds.sf.imm = (double) - (unsigned long) set.imm; - break; - default: - ip->opnds.sf.imm = (double) set.imm; - break; - } - } - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - found++; - } - } - break; + /* conversion insns */ + int dest_vreg = ip->opnds.a2.dest; + int src_vreg = ip->opnds.a2.src; + int from_type = (ip->insn_code >> 4) & 0xf; + int to_type = ip->insn_code & 0xf; + if (src_vreg == set_vreg) { + if (c->dill_debug) { + printf(" Replacing "); + virtual_print_insn(c, NULL, ip); + printf(" with "); + } + ip->class_code = iclass_set; + ip->insn_code = to_type; + switch (to_type) { + case DILL_C: + ip->opnds.a3i.u.imm = (char)set.imm; + ip->opnds.a3i.dest = dest_vreg; + break; + case DILL_S: + ip->opnds.a3i.u.imm = (short)set.imm; + ip->opnds.a3i.dest = dest_vreg; + case DILL_I: + case DILL_L: + ip->opnds.a3i.u.imm = set.imm; + ip->opnds.a3i.dest = dest_vreg; + break; + case DILL_UC: + ip->opnds.a3i.u.imm = (unsigned char)set.imm; + ip->opnds.a3i.dest = dest_vreg; + break; + case DILL_US: + ip->opnds.a3i.u.imm = (unsigned short)set.imm; + ip->opnds.a3i.dest = dest_vreg; + break; + case DILL_U: + ip->opnds.a3i.u.imm = (unsigned)set.imm; + ip->opnds.a3i.dest = dest_vreg; + break; + case DILL_UL: + ip->opnds.a3i.u.imm = (uintptr_t)set.imm; + ip->opnds.a3i.dest = dest_vreg; + break; + case DILL_P: + ip->class_code = iclass_set; + ip->insn_code = DILL_P; + ip->opnds.a3i.u.imm_a = (void*)set.imm; + ip->opnds.a3i.dest = dest_vreg; + break; + case DILL_F: + case DILL_D: + ip->class_code = iclass_setf; + ip->insn_code = to_type; + ip->opnds.sf.dest = dest_vreg; + switch (from_type) { + case DILL_UC: + case DILL_US: + case DILL_U: + case DILL_UL: + ip->opnds.sf.imm = (double)(uintptr_t)set.imm; + break; + default: + ip->opnds.sf.imm = (double)set.imm; + break; + } + } + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + found++; + } + } break; case iclass_loadstore: { - /* load/store 3 operand integer insns */ - int dest_vreg = ip->opnds.a3.dest; - int src1_vreg = ip->opnds.a3.src1; - int src2_vreg = ip->opnds.a3.src2; - - if (set_vreg == src1_vreg) { - /* we only optimize src2_VREG, switch them */ - /* load store is commutative */ - src1_vreg = ip->opnds.a3.src2; - src2_vreg = ip->opnds.a3.src1; - } - if (src2_vreg == set_vreg) { - if (c->dill_debug) { - printf(" Replacing "); - virtual_print_insn(c, NULL, ip); - printf(" with "); - } - ip->class_code = iclass_loadstorei; - ip->opnds.a3i.dest = dest_vreg; - ip->opnds.a3i.src = src1_vreg; - ip->opnds.a3i.u.imm = set.imm; - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - found++; - } - } - break; + /* load/store 3 operand integer insns */ + int dest_vreg = ip->opnds.a3.dest; + int src1_vreg = ip->opnds.a3.src1; + int src2_vreg = ip->opnds.a3.src2; + + if (set_vreg == src1_vreg) { + /* we only optimize src2_VREG, switch them */ + /* load store is commutative */ + src1_vreg = ip->opnds.a3.src2; + src2_vreg = ip->opnds.a3.src1; + } + if (src2_vreg == set_vreg) { + if (c->dill_debug) { + printf(" Replacing "); + virtual_print_insn(c, NULL, ip); + printf(" with "); + } + ip->class_code = iclass_loadstorei; + ip->opnds.a3i.dest = dest_vreg; + ip->opnds.a3i.src = src1_vreg; + ip->opnds.a3i.u.imm = set.imm; + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + found++; + } + } break; case iclass_loadstorei: - break; + break; case iclass_lea: - break; + break; case iclass_set: - break; + break; case iclass_setf: - break; + break; case iclass_mov: { - /* mov insns */ - int dest_vreg = ip->opnds.a2.dest; - int src_vreg = ip->opnds.a2.src; - if (src_vreg == set_vreg) { - if (c->dill_debug) { - printf(" Replacing "); - virtual_print_insn(c, NULL, ip); - printf(" with "); - } - ip->class_code = iclass_set; - ip->opnds.a3i.dest = dest_vreg; - ip->opnds.a3i.u.imm = set.imm; - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - found++; - } - } - break; + /* mov insns */ + int dest_vreg = ip->opnds.a2.dest; + int src_vreg = ip->opnds.a2.src; + if (src_vreg == set_vreg) { + if (c->dill_debug) { + printf(" Replacing "); + virtual_print_insn(c, NULL, ip); + printf(" with "); + } + ip->class_code = iclass_set; + ip->opnds.a3i.dest = dest_vreg; + ip->opnds.a3i.u.imm = set.imm; + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + found++; + } + } break; case iclass_compare: case iclass_reti: - break; - case iclass_branch: - { - /* branch */ - int label = ip->opnds.br.label; - int src1_vreg = ip->opnds.br.src1; - int src2_vreg = ip->opnds.br.src2; -/* int br_op = ip->insn_code; - if (last_dest_vreg == src2_vreg) { - # we should do this is we reverse the sense of the branch * - src1_vreg = ip->opnds.br.src2; - src2_vreg = ip->opnds.br.src1; - } -*/ - if (src2_vreg == set_vreg) { - if (c->dill_debug) { - printf(" Replacing "); - virtual_print_insn(c, NULL, ip); - printf(" with "); - } - ip->class_code = iclass_branchi; - ip->opnds.bri.src = src1_vreg; - ip->opnds.bri.label = label; - ip->opnds.bri.imm_l = set.imm; - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - found++; - } - } - break; + break; + case iclass_branch: { + /* branch */ + int label = ip->opnds.br.label; + int src1_vreg = ip->opnds.br.src1; + int src2_vreg = ip->opnds.br.src2; + /* int br_op = ip->insn_code; + if (last_dest_vreg == src2_vreg) { + # we should do this is we reverse the + sense of the branch * src1_vreg = ip->opnds.br.src2; src2_vreg = + ip->opnds.br.src1; + } + */ + if (src2_vreg == set_vreg) { + if (c->dill_debug) { + printf(" Replacing "); + virtual_print_insn(c, NULL, ip); + printf(" with "); + } + ip->class_code = iclass_branchi; + ip->opnds.bri.src = src1_vreg; + ip->opnds.bri.label = label; + ip->opnds.bri.imm_l = set.imm; + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + found++; + } + } break; case iclass_branchi: - break; + break; case iclass_jump_to_label: - break; + break; case iclass_jump_to_reg: - break; + break; case iclass_jump_to_imm: - break; + break; case iclass_special: - break; + break; case iclass_call: - break; - case iclass_push: - { - int src1_vreg = ip->opnds.a1.src; - if (src1_vreg == set_vreg) { - int typ = ip->insn_code & 0xf; - if (c->dill_debug) { - printf(" Replacing "); - virtual_print_insn(c, NULL, ip); - printf(" with "); - } - ip->class_code = iclass_pushi; - if (typ != DILL_P) { - ip->opnds.a3i.u.imm = set.imm; - } else { - ip->opnds.a3i.u.imm_a = set.imm_a; - } - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - found++; - } - } - break; + break; + case iclass_push: { + int src1_vreg = ip->opnds.a1.src; + if (src1_vreg == set_vreg) { + int typ = ip->insn_code & 0xf; + if (c->dill_debug) { + printf(" Replacing "); + virtual_print_insn(c, NULL, ip); + printf(" with "); + } + ip->class_code = iclass_pushi; + if (typ != DILL_P) { + ip->opnds.a3i.u.imm = set.imm; + } else { + ip->opnds.a3i.u.imm_a = set.imm_a; + } + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + found++; + } + } break; case iclass_pushi: - break; + break; case iclass_pushf: - break; + break; case iclass_nop: - break; + break; case iclass_mark_label: - break; + break; } if (found) { - if (set_vreg >= 100) { - c->p->vregs[set_vreg-100].use_info.use_count--; - } - if (c->p->vregs[set_vreg-100].use_info.use_count == 0) { - set_ip->class_code = iclass_nop; - set_unused(c, bb, set_vreg); - } + if (set_vreg >= 100) { + c->p->vregs[set_vreg - 100].use_info.use_count--; + } + if (c->p->vregs[set_vreg - 100].use_info.use_count == 0) { + set_ip->class_code = iclass_nop; + set_unused(c, bb, set_vreg); + } } return found; } @@ -3803,454 +3864,472 @@ is_convert_noop(int insn_code) /* GSE -bug This test should be for *generated* target, not host */ if (sizeof(long) != sizeof(int)) { - return 0; + return 0; } else { - switch(from_type) { - case DILL_I: case DILL_U: - case DILL_L: case DILL_UL: - switch(to_type) { - case DILL_I: case DILL_U: - case DILL_L: case DILL_UL: - return 1; - } - } + switch (from_type) { + case DILL_I: + case DILL_U: + case DILL_L: + case DILL_UL: + switch (to_type) { + case DILL_I: + case DILL_U: + case DILL_L: + case DILL_UL: + return 1; + } + } } return 0; } static void -do_const_prop(dill_stream c, basic_block bb, virtual_insn *insns, int loc) +do_const_prop(dill_stream c, basic_block bb, virtual_insn* insns, int loc) { - virtual_insn *set_ip = &((virtual_insn *)insns)[loc]; - if ((set_ip->class_code == iclass_set) && - has_single_def_use(c, set_ip->opnds.a3i.dest)){ - - int found = 0; - int k; - - if (c->dill_debug) { - printf(" Forward propagating "); - virtual_print_insn(c, NULL, set_ip); - printf("\n"); - } - for (k = loc + 1; ((k <= bb->end) && (!found)); k++) { - virtual_insn *ip = &((virtual_insn *)insns)[k]; - found = const_prop_ip(c, bb, ip, set_ip, 1); - } + virtual_insn* set_ip = &((virtual_insn*)insns)[loc]; + if ((set_ip->class_code == iclass_set) && + has_single_def_use(c, set_ip->opnds.a3i.dest)) { + int found = 0; + int k; + + if (c->dill_debug) { + printf(" Forward propagating "); + virtual_print_insn(c, NULL, set_ip); + printf("\n"); + } + for (k = loc + 1; ((k <= bb->end) && (!found)); k++) { + virtual_insn* ip = &((virtual_insn*)insns)[k]; + found = const_prop_ip(c, bb, ip, set_ip, 1); + } } else if (set_ip->class_code == iclass_set) { - int k; - int vdest = insn_defines(set_ip); - if (c->dill_debug) { - printf(" Forward propagating const "); - virtual_print_insn(c, NULL, set_ip); - printf("\n"); - } - for (k = loc + 1; ((k <= bb->end) && (vdest != insn_defines(&((virtual_insn *)insns)[k]))); k++) { - virtual_insn *ip = &((virtual_insn *)insns)[k]; - const_prop_ip(c, bb, ip, set_ip, 0); - } - if (k <= bb->end) { - /* if we ended in insn_defines, substitute the one that defines it */ - const_prop_ip(c, bb, &((virtual_insn *)insns)[k], set_ip, 0); - } + int k; + int vdest = insn_defines(set_ip); + if (c->dill_debug) { + printf(" Forward propagating const "); + virtual_print_insn(c, NULL, set_ip); + printf("\n"); + } + for (k = loc + 1; ((k <= bb->end) && + (vdest != insn_defines(&((virtual_insn*)insns)[k]))); + k++) { + virtual_insn* ip = &((virtual_insn*)insns)[k]; + const_prop_ip(c, bb, ip, set_ip, 0); + } + if (k <= bb->end) { + /* if we ended in insn_defines, substitute the one that defines it + */ + const_prop_ip(c, bb, &((virtual_insn*)insns)[k], set_ip, 0); + } } else if (((set_ip->class_code == iclass_mov) || - ((set_ip->class_code == iclass_convert) && - is_convert_noop(set_ip->insn_code))) && - has_single_def_use(c, set_ip->opnds.a2.src)){ - /* back propagate move */ - int mov_src = set_ip->opnds.a2.src; - int mov_dest = set_ip->opnds.a2.dest; - int found = 0; - int k; - - if (c->dill_debug) { - printf(" mov propagating "); - virtual_print_insn(c, NULL, set_ip); - printf("\n"); - } - for (k = loc - 1; ((k > bb->start) && (!found)); k--) { - virtual_insn *ip = &((virtual_insn *)insns)[k]; - switch(ip->class_code) { - case iclass_arith3: { - /* arith 3 operand integer insns */ - int dest_vreg = ip->opnds.a3.dest; - if (dest_vreg == mov_src) { - if (c->dill_debug) { - printf(" Replacing "); - virtual_print_insn(c, NULL, ip); - printf(" with "); - } - ip->opnds.a3i.dest = mov_dest; - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - set_ip->class_code = iclass_nop; - set_unused(c, bb, mov_src); - found++; - } - } - break; - case iclass_arith2: { - /* arith 2 operand integer insns */ - int dest_vreg = ip->opnds.a2.dest; - if (dest_vreg == mov_src) { - if (c->dill_debug) { - printf(" Replacing "); - virtual_print_insn(c, NULL, ip); - printf(" with "); - } - ip->opnds.a2.dest = mov_dest; - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - set_ip->class_code = iclass_nop; - set_unused(c, bb, mov_src); - found++; - } - break; - } - case iclass_arith3i: - { - /* arith 3 immediate operand integer insns */ - int dest_vreg = ip->opnds.a3i.dest; - if (dest_vreg == mov_src) { - if (c->dill_debug) { - printf(" Replacing "); - virtual_print_insn(c, NULL, ip); - printf(" with "); - } - ip->opnds.a3i.dest = mov_dest; - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - set_ip->class_code = iclass_nop; - set_unused(c, bb, mov_src); - found++; - } - } - break; - case iclass_ret: - break; - case iclass_convert: { - /* conversion insns */ - int dest_vreg = ip->opnds.a2.dest; - if (dest_vreg == mov_src) { - if (c->dill_debug) { - printf(" Replacing "); - virtual_print_insn(c, NULL, ip); - printf(" with "); - } - ip->opnds.a2.dest = mov_dest; - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - set_ip->class_code = iclass_nop; - set_unused(c, bb, mov_src); - found++; - } - } - break; - case iclass_loadstore: { - int store = ((ip->insn_code & 0x10) == 0x10); - /* load/store 3 operand integer insns */ - int dest_vreg = ip->opnds.a3.dest; - - if (!store && (dest_vreg == mov_src)) { - if (c->dill_debug) { - printf(" Replacing "); - virtual_print_insn(c, NULL, ip); - printf(" with "); - } - ip->opnds.a3i.dest = mov_src; - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - set_ip->class_code = iclass_nop; - set_unused(c, bb, mov_src); - found++; - } - } - break; - case iclass_loadstorei: - break; - case iclass_lea: - break; - case iclass_set: - break; - case iclass_setf: - break; - case iclass_mov: { - /* mov insns */ - int dest_vreg = ip->opnds.a2.dest; - if (dest_vreg == mov_src) { - if (c->dill_debug) { - printf(" Replacing "); - virtual_print_insn(c, NULL, ip); - printf(" with "); - } - ip->opnds.a2.dest = mov_dest; - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - set_ip->class_code = iclass_nop; - set_unused(c, bb, mov_src); - found++; - } - } - break; - case iclass_reti: - case iclass_branch: - case iclass_branchi: - case iclass_compare: - case iclass_jump_to_label: - case iclass_jump_to_reg: - case iclass_jump_to_imm: - case iclass_special: - case iclass_call: - case iclass_push: - case iclass_pushi: - case iclass_pushf: - case iclass_nop: - case iclass_mark_label: - break; - } - } + ((set_ip->class_code == iclass_convert) && + is_convert_noop(set_ip->insn_code))) && + has_single_def_use(c, set_ip->opnds.a2.src)) { + /* back propagate move */ + int mov_src = set_ip->opnds.a2.src; + int mov_dest = set_ip->opnds.a2.dest; + int found = 0; + int k; + + if (c->dill_debug) { + printf(" mov propagating "); + virtual_print_insn(c, NULL, set_ip); + printf("\n"); + } + for (k = loc - 1; ((k > bb->start) && (!found)); k--) { + virtual_insn* ip = &((virtual_insn*)insns)[k]; + switch (ip->class_code) { + case iclass_arith3: { + /* arith 3 operand integer insns */ + int dest_vreg = ip->opnds.a3.dest; + if (dest_vreg == mov_src) { + if (c->dill_debug) { + printf(" Replacing "); + virtual_print_insn(c, NULL, ip); + printf(" with "); + } + ip->opnds.a3i.dest = mov_dest; + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + set_ip->class_code = iclass_nop; + set_unused(c, bb, mov_src); + found++; + } + } break; + case iclass_arith2: { + /* arith 2 operand integer insns */ + int dest_vreg = ip->opnds.a2.dest; + if (dest_vreg == mov_src) { + if (c->dill_debug) { + printf(" Replacing "); + virtual_print_insn(c, NULL, ip); + printf(" with "); + } + ip->opnds.a2.dest = mov_dest; + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + set_ip->class_code = iclass_nop; + set_unused(c, bb, mov_src); + found++; + } + break; + } + case iclass_arith3i: { + /* arith 3 immediate operand integer insns */ + int dest_vreg = ip->opnds.a3i.dest; + if (dest_vreg == mov_src) { + if (c->dill_debug) { + printf(" Replacing "); + virtual_print_insn(c, NULL, ip); + printf(" with "); + } + ip->opnds.a3i.dest = mov_dest; + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + set_ip->class_code = iclass_nop; + set_unused(c, bb, mov_src); + found++; + } + } break; + case iclass_ret: + break; + case iclass_convert: { + /* conversion insns */ + int dest_vreg = ip->opnds.a2.dest; + if (dest_vreg == mov_src) { + if (c->dill_debug) { + printf(" Replacing "); + virtual_print_insn(c, NULL, ip); + printf(" with "); + } + ip->opnds.a2.dest = mov_dest; + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + set_ip->class_code = iclass_nop; + set_unused(c, bb, mov_src); + found++; + } + } break; + case iclass_loadstore: { + int store = ((ip->insn_code & 0x10) == 0x10); + /* load/store 3 operand integer insns */ + int dest_vreg = ip->opnds.a3.dest; + + if (!store && (dest_vreg == mov_src)) { + if (c->dill_debug) { + printf(" Replacing "); + virtual_print_insn(c, NULL, ip); + printf(" with "); + } + ip->opnds.a3i.dest = mov_src; + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + set_ip->class_code = iclass_nop; + set_unused(c, bb, mov_src); + found++; + } + } break; + case iclass_loadstorei: + break; + case iclass_lea: + break; + case iclass_set: + break; + case iclass_setf: + break; + case iclass_mov: { + /* mov insns */ + int dest_vreg = ip->opnds.a2.dest; + if (dest_vreg == mov_src) { + if (c->dill_debug) { + printf(" Replacing "); + virtual_print_insn(c, NULL, ip); + printf(" with "); + } + ip->opnds.a2.dest = mov_dest; + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + set_ip->class_code = iclass_nop; + set_unused(c, bb, mov_src); + found++; + } + } break; + case iclass_reti: + case iclass_branch: + case iclass_branchi: + case iclass_compare: + case iclass_jump_to_label: + case iclass_jump_to_reg: + case iclass_jump_to_imm: + case iclass_special: + case iclass_call: + case iclass_push: + case iclass_pushi: + case iclass_pushf: + case iclass_nop: + case iclass_mark_label: + break; + } + } } } static void -const_propagation(dill_stream c, void *insns, virtual_mach_info vmi) +const_propagation(dill_stream c, void* insns, virtual_mach_info vmi) { apply_to_each(c, insns, vmi, do_const_prop); } static void -do_com_sub_exp(dill_stream c, basic_block bb, virtual_insn *insns, int loc) +do_com_sub_exp(dill_stream c, basic_block bb, virtual_insn* insns, int loc) { - virtual_insn *root_insn = &((virtual_insn *)insns)[loc]; + virtual_insn* root_insn = &((virtual_insn*)insns)[loc]; int def_vreg = insn_defines(root_insn); int do_ldi0_optim = 0; int k; int stop = 0; int used_vregs[3]; int root_is_load; - if (def_vreg == -1) return; + if (def_vreg == -1) + return; insn_uses(root_insn, &used_vregs[0]); - if (used_vregs[0] == -1) return; - if ((root_insn->class_code == iclass_arith3) && - (root_insn->insn_code == dill_jmp_addp)) do_ldi0_optim = 1; - + if (used_vregs[0] == -1) + return; + if ((root_insn->class_code == iclass_arith3) && + (root_insn->insn_code == dill_jmp_addp)) + do_ldi0_optim = 1; + if (def_vreg != -1) { - if ((used_vregs[0] == def_vreg) || (used_vregs[1] == def_vreg) || - (used_vregs[2] == def_vreg)) return; + if ((used_vregs[0] == def_vreg) || (used_vregs[1] == def_vreg) || + (used_vregs[2] == def_vreg)) + return; } - /* + /* * see if we can find an instruction just like ( - * except for dest) this ahead + * except for dest) this ahead */ if (c->dill_debug) { - printf("Try to replace %d ", loc); - virtual_print_insn(c, NULL, root_insn); - printf("\n"); + printf("Try to replace %d ", loc); + virtual_print_insn(c, NULL, root_insn); + printf("\n"); } root_is_load = (((root_insn->class_code == iclass_loadstorei) || - (root_insn->class_code == iclass_loadstore)) && - (((root_insn->insn_code & 0x10) == 0x10) == 0)); + (root_insn->class_code == iclass_loadstore)) && + (((root_insn->insn_code & 0x10) == 0x10) == 0)); for (k = loc + 1; ((k <= bb->end) && (!stop)); k++) { - virtual_insn *ip = &((virtual_insn *)insns)[k]; - int replace_vreg = insn_defines(ip); - int l, stop2, insn_is_store; - /* stop looking if old dest is wiped */ - if (insn_define_test(ip, def_vreg)) stop++; - /* stop looking if srcs become different */ - if (insn_define_test(ip, used_vregs[0])) stop++; - if ((used_vregs[1] != -1) && - insn_define_test(ip, used_vregs[1])) stop++; - if ((used_vregs[2] != -1) && - insn_define_test(ip, used_vregs[2])) stop++; - /* stop looking if this is a load and we're about to pass a store */ - insn_is_store = (((ip->class_code == iclass_loadstorei) || - (ip->class_code == iclass_loadstore)) && - ((ip->insn_code & 0x10) == 0x10)); - if (root_is_load && insn_is_store) stop++; - - if (do_ldi0_optim && - (ip->class_code == iclass_loadstorei) && - (ip->opnds.a3i.src == def_vreg) && - (ip->opnds.a3i.u.imm == 0)) { - int use_target = 1; - /* - * we've found a load immediate with an imm of 0 and with - * a source that is the result of a prior add - * combine them. - */ - if (def_vreg==used_vregs[0]) use_target++; - if (def_vreg==used_vregs[1]) use_target++; - if ((use_target != 0) && - (c->p->vregs[def_vreg-100].use_info.use_count != use_target)) { - continue; - } - if (c->dill_debug) { - printf("load opt, changing - "); - virtual_print_insn(c, NULL, ip); - printf(" - to - "); - } - ip->class_code = iclass_loadstore; - ip->opnds.a3.dest = ip->opnds.a3i.dest; - ip->opnds.a3.src1 = used_vregs[0]; - ip->opnds.a3.src2 = used_vregs[1]; - if (c->dill_debug) { - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - if (def_vreg >= 100) { - c->p->vregs[def_vreg-100].use_info.use_count--; - } - if (c->p->vregs[def_vreg-100].use_info.use_count == (use_target-1)){ - c->p->vregs[def_vreg-100].use_info.def_count--; - if (c->dill_debug) { - printf("load opt eliminating - "); - virtual_print_insn(c, NULL, root_insn); - printf("\n"); - } - root_insn->class_code = iclass_nop; - continue; - } - } - - if (replace_vreg == -1) continue; - if (insn_use_test(ip, def_vreg)) do_ldi0_optim = 0; - - /* - * insn is the same except for dest, make it a noop - * and fixup uses of replace_vreg going forward - */ - if (!insn_same_except_dest(ip, root_insn)) continue; - if (live_at_end(bb, replace_vreg)) continue; - if (c->dill_debug) { - printf("eliminating - - %d - ", k); - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - - if (ip->class_code == iclass_loadstore) { - if (k > loc + 1) { - virtual_insn *previous_ip = &((virtual_insn *)insns)[k - 1]; - if ((previous_ip->class_code == iclass_special) && - (previous_ip->opnds.spec.type == DILL_SEGMENTED_FOLLOWS)) { - /* - * We're eliminating a loadstore and previous was a - * special SEGMENTED_FOLLOWS, kill the special too. - */ - previous_ip->class_code = iclass_nop; - } - } - } - - ip->class_code = iclass_nop; - stop2 = 0; - for (l = k + 1; ((l <= bb->end) && (!stop2)); l++) { - virtual_insn *sub_ip = &((virtual_insn *)insns)[l]; - if (insn_define_test(sub_ip, replace_vreg)) { - stop2++; - } - if (!insn_use_test(sub_ip, replace_vreg)) continue; - if (c->dill_debug) { - printf(" Reg %d forward subst - Replacing %d ", - def_vreg, l); - virtual_print_insn(c, NULL, sub_ip); - printf(" with "); - } - replace_insn_src(sub_ip, replace_vreg, def_vreg); - set_used(c, def_vreg); - if (c->dill_debug) { - virtual_print_insn(c, NULL, sub_ip); - printf("\n"); - } - } + virtual_insn* ip = &((virtual_insn*)insns)[k]; + int replace_vreg = insn_defines(ip); + int l, stop2, insn_is_store; + /* stop looking if old dest is wiped */ + if (insn_define_test(ip, def_vreg)) + stop++; + /* stop looking if srcs become different */ + if (insn_define_test(ip, used_vregs[0])) + stop++; + if ((used_vregs[1] != -1) && insn_define_test(ip, used_vregs[1])) + stop++; + if ((used_vregs[2] != -1) && insn_define_test(ip, used_vregs[2])) + stop++; + /* stop looking if this is a load and we're about to pass a store */ + insn_is_store = (((ip->class_code == iclass_loadstorei) || + (ip->class_code == iclass_loadstore)) && + ((ip->insn_code & 0x10) == 0x10)); + if (root_is_load && insn_is_store) + stop++; + + if (do_ldi0_optim && (ip->class_code == iclass_loadstorei) && + (ip->opnds.a3i.src == def_vreg) && (ip->opnds.a3i.u.imm == 0)) { + int use_target = 1; + /* + * we've found a load immediate with an imm of 0 and with + * a source that is the result of a prior add + * combine them. + */ + if (def_vreg == used_vregs[0]) + use_target++; + if (def_vreg == used_vregs[1]) + use_target++; + if ((use_target != 0) && + (c->p->vregs[def_vreg - 100].use_info.use_count != + use_target)) { + continue; + } + if (c->dill_debug) { + printf("load opt, changing - "); + virtual_print_insn(c, NULL, ip); + printf(" - to - "); + } + ip->class_code = iclass_loadstore; + ip->opnds.a3.dest = ip->opnds.a3i.dest; + ip->opnds.a3.src1 = used_vregs[0]; + ip->opnds.a3.src2 = used_vregs[1]; + if (c->dill_debug) { + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + if (def_vreg >= 100) { + c->p->vregs[def_vreg - 100].use_info.use_count--; + } + if (c->p->vregs[def_vreg - 100].use_info.use_count == + (use_target - 1)) { + c->p->vregs[def_vreg - 100].use_info.def_count--; + if (c->dill_debug) { + printf("load opt eliminating - "); + virtual_print_insn(c, NULL, root_insn); + printf("\n"); + } + root_insn->class_code = iclass_nop; + continue; + } + } + + if (replace_vreg == -1) + continue; + if (insn_use_test(ip, def_vreg)) + do_ldi0_optim = 0; + + /* + * insn is the same except for dest, make it a noop + * and fixup uses of replace_vreg going forward + */ + if (!insn_same_except_dest(ip, root_insn)) + continue; + if (live_at_end(bb, replace_vreg)) + continue; + if (c->dill_debug) { + printf("eliminating - - %d - ", k); + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + + if (ip->class_code == iclass_loadstore) { + if (k > loc + 1) { + virtual_insn* previous_ip = &((virtual_insn*)insns)[k - 1]; + if ((previous_ip->class_code == iclass_special) && + (previous_ip->opnds.spec.type == DILL_SEGMENTED_FOLLOWS)) { + /* + * We're eliminating a loadstore and previous was a + * special SEGMENTED_FOLLOWS, kill the special too. + */ + previous_ip->class_code = iclass_nop; + } + } + } + + ip->class_code = iclass_nop; + stop2 = 0; + for (l = k + 1; ((l <= bb->end) && (!stop2)); l++) { + virtual_insn* sub_ip = &((virtual_insn*)insns)[l]; + if (insn_define_test(sub_ip, replace_vreg)) { + stop2++; + } + if (!insn_use_test(sub_ip, replace_vreg)) + continue; + if (c->dill_debug) { + printf(" Reg %d forward subst - Replacing %d ", def_vreg, l); + virtual_print_insn(c, NULL, sub_ip); + printf(" with "); + } + replace_insn_src(sub_ip, replace_vreg, def_vreg); + set_used(c, def_vreg); + if (c->dill_debug) { + virtual_print_insn(c, NULL, sub_ip); + printf("\n"); + } + } } if (c->dill_debug) { - printf("stopped \n"); + printf("stopped \n"); } } static void -CSE_elimination(dill_stream c, void *insns, virtual_mach_info vmi) +CSE_elimination(dill_stream c, void* insns, virtual_mach_info vmi) { apply_to_each(c, insns, vmi, do_com_sub_exp); } static void -kill_dead(dill_stream c, basic_block bb, virtual_insn *insns, int loc) +kill_dead(dill_stream c, basic_block bb, virtual_insn* insns, int loc) { - virtual_insn *root_insn = &((virtual_insn *)insns)[loc]; + virtual_insn* root_insn = &((virtual_insn*)insns)[loc]; int def_vreg = insn_defines(root_insn); int k; int stop = 0; - if (root_insn->class_code == iclass_call) return; + if (root_insn->class_code == iclass_call) + return; if (def_vreg >= 100) { - if (c->p->vregs[def_vreg-100].use_info.use_count == 0) { - root_insn->class_code = iclass_nop; - set_unused(c, bb, def_vreg); - } + if (c->p->vregs[def_vreg - 100].use_info.use_count == 0) { + root_insn->class_code = iclass_nop; + set_unused(c, bb, def_vreg); + } } for (k = loc + 1; ((k <= bb->end) && (!stop)); k++) { - virtual_insn *ip = &((virtual_insn *)insns)[k]; - int used_vregs[3]; - insn_uses(ip, &used_vregs[0]); - if ((def_vreg == used_vregs[0]) || (def_vreg == used_vregs[1]) - ||(def_vreg == used_vregs[2])) { - stop++; - } else { - if (insn_defines(ip) == def_vreg) { - /* got another define before a use, kill the first */ - root_insn->class_code = iclass_nop; - stop++; - } - } - } - + virtual_insn* ip = &((virtual_insn*)insns)[k]; + int used_vregs[3]; + insn_uses(ip, &used_vregs[0]); + if ((def_vreg == used_vregs[0]) || (def_vreg == used_vregs[1]) || + (def_vreg == used_vregs[2])) { + stop++; + } else { + if (insn_defines(ip) == def_vreg) { + /* got another define before a use, kill the first */ + root_insn->class_code = iclass_nop; + stop++; + } + } + } } static void -kill_dead_regs(dill_stream c, void *insns, virtual_mach_info vmi) +kill_dead_regs(dill_stream c, void* insns, virtual_mach_info vmi) { apply_to_each(c, insns, vmi, kill_dead); /* kill unused arguments */ - while ((c->p->c_param_count>0) && (c->p->c_param_args[c->p->c_param_count-1].used == 0)) { - c->p->c_param_count--; + while ((c->p->c_param_count > 0) && + (c->p->c_param_args[c->p->c_param_count - 1].used == 0)) { + c->p->c_param_count--; } } extern void -virtual_proc_start(dill_stream c, char *subr_name, int arg_count, - arg_info_list args, dill_reg *arglist) +virtual_proc_start(dill_stream c, + char* subr_name, + int arg_count, + arg_info_list args, + dill_reg* arglist) { int i; virtual_mach_info vmi = (virtual_mach_info)c->p->mach_info; vmi->arg_info = args; vmi->prefix_code_start = -1; for (i = 0; i < arg_count; i++) { - c->p->c_param_args[i].in_reg = i; + c->p->c_param_args[i].in_reg = i; } } -extern void dill_virtual_init(dill_stream c); +extern void +dill_virtual_init(dill_stream c); static void fill_label_translation(dill_stream c, label_translation_table lt) { int i = 0; while (lt[i].old_label != -1) { - lt[i].new_label = dill_alloc_label(c, NULL); - i++; + lt[i].new_label = dill_alloc_label(c, NULL); + i++; } } @@ -4259,27 +4338,27 @@ build_label_translation(dill_stream c) { int i; int label_count = c->p->branch_table.next_label; - label_translation_table l = malloc(sizeof(struct label_translation) * - (label_count + 1)); - for(i = 0; i < label_count; i++) { - l[i].old_label = i; - l[i].old_location = c->p->branch_table.label_locs[i]; + label_translation_table l = + malloc(sizeof(struct label_translation) * (label_count + 1)); + for (i = 0; i < label_count; i++) { + l[i].old_label = i; + l[i].old_location = c->p->branch_table.label_locs[i]; } /* Good old reliable insertion sort */ { - int i, curIdx; - struct label_translation tmp; - - for(curIdx = 0; curIdx < label_count; curIdx++) { - for(i = curIdx+1; i < label_count; i++) { - if(l[curIdx].old_location > l[i].old_location) { - /* swap them */ - tmp = l[curIdx]; - l[curIdx] = l[i]; - l[i] = tmp; - } + int i, curIdx; + struct label_translation tmp; + + for (curIdx = 0; curIdx < label_count; curIdx++) { + for (i = curIdx + 1; i < label_count; i++) { + if (l[curIdx].old_location > l[i].old_location) { + /* swap them */ + tmp = l[curIdx]; + l[curIdx] = l[i]; + l[i] = tmp; + } + } } - } } l[label_count].old_location = -1; l[label_count].old_label = -1; @@ -4290,27 +4369,31 @@ build_label_translation(dill_stream c) static int virtual_insn_count(dill_stream c) { - virtual_insn *insn = (virtual_insn*)c->p->code_base; + virtual_insn* insn = (virtual_insn*)c->p->code_base; int count = 0; - for (; insn < (virtual_insn *)c->p->cur_ip; insn++) { - if (insn->class_code != iclass_nop) count++; + for (; insn < (virtual_insn*)c->p->cur_ip; insn++) { + if (insn->class_code != iclass_nop) + count++; } return count; } -void init_code_block(dill_stream s); - +void +init_code_block(dill_stream s); + extern void -virtual_reti(dill_stream s, int type, int junk, long imm); +virtual_reti(dill_stream s, int type, int junk, IMM_TYPE imm); -extern void dill_begin_prefix_code(dill_stream s) +extern void +dill_begin_prefix_code(dill_stream s) { virtual_mach_info vmi = (virtual_mach_info)s->p->mach_info; /* have to be in virtual mode */ - assert(s->j->proc_start == (dill_mach_proc_start)virtual_proc_start); + assert(s->j->proc_start == (dill_mach_proc_start)virtual_proc_start); /* insert a return, so we don't fall into prefix code */ virtual_reti(s, DILL_I, 0, 0); - vmi->prefix_code_start = (int) (s->p->cur_ip - s->p->code_base) / sizeof(virtual_insn); + vmi->prefix_code_start = + (int)(s->p->cur_ip - s->p->code_base) / sizeof(virtual_insn); } static dill_foreign_cg_func dill_foreign_cg = NULL; @@ -4330,49 +4413,55 @@ virtual_do_end(dill_stream s, int package) static int do_emulation = -1; virtual_mach_info vmi = (virtual_mach_info)s->p->mach_info; - void *insns = s->p->code_base; - void *code_end = s->p->cur_ip; - void *prefix_begin = (char*)insns + (vmi->prefix_code_start * sizeof(virtual_insn));; + void* insns = s->p->code_base; + void* code_end = s->p->cur_ip; + void* prefix_begin = + (char*)insns + (vmi->prefix_code_start * sizeof(virtual_insn)); + ; label_translation_table ltable; int virtual_local_pointer = s->dill_local_pointer; if (dill_verbose == -1) { - dill_verbose = (getenv ("DILL_VERBOSE") != NULL); - no_optimize = (getenv ("DILL_NOOPTIMIZE") != NULL); - old_reg_alloc = (getenv ("DILL_OLD_REGS") != NULL); - do_emulation = (getenv("DILL_DO_EMULATION") != NULL); + dill_verbose = (getenv("DILL_VERBOSE") != NULL); + no_optimize = (getenv("DILL_NOOPTIMIZE") != NULL); + old_reg_alloc = (getenv("DILL_OLD_REGS") != NULL); + do_emulation = (getenv("DILL_DO_EMULATION") != NULL); #ifdef EMULATION_ONLY - do_emulation = 1; + do_emulation = 1; #endif } - if (vmi->prefix_code_start == -1) prefix_begin = code_end; + s->p->virtual.code_base = s->p->code_base; + if (vmi->prefix_code_start == -1) + prefix_begin = code_end; build_bbs(s, insns, prefix_begin, code_end); if (!no_optimize) { - if (count_verbose == -1) { - count_verbose = (getenv ("DILL_COUNTS") != NULL); - } - if (count_verbose == 1) { - printf("Prior to optimization, %d non-null virtual insns\n", - virtual_insn_count(s)); - } - const_propagation(s, insns, vmi); - if (count_verbose == 1) { - printf("After constant propagation, %d non-null virtual insns\n", - virtual_insn_count(s)); - } - CSE_elimination(s, insns, vmi); - if (count_verbose == 1) { - printf("After duplicate instruction elimination (CSE-lite), %d non-null virtual insns\n", - virtual_insn_count(s)); - } - reset_use_def_count(s, insns, vmi); - kill_dead_regs(s, insns, vmi); + if (count_verbose == -1) { + count_verbose = (getenv("DILL_COUNTS") != NULL); + } + if (count_verbose == 1) { + printf("Prior to optimization, %d non-null virtual insns\n", + virtual_insn_count(s)); + } + const_propagation(s, insns, vmi); + if (count_verbose == 1) { + printf("After constant propagation, %d non-null virtual insns\n", + virtual_insn_count(s)); + } + CSE_elimination(s, insns, vmi); + if (count_verbose == 1) { + printf( + "After duplicate instruction elimination (CSE-lite), %d " + "non-null virtual insns\n", + virtual_insn_count(s)); + } + reset_use_def_count(s, insns, vmi); + kill_dead_regs(s, insns, vmi); } if (dill_verbose) { - dump_bbs(s); - s->dill_debug = 1; + dump_bbs(s); + s->dill_debug = 1; } s->p->virtual.mach_jump = s->j; s->p->virtual.mach_reset = s->p->mach_reset; @@ -4383,64 +4472,66 @@ virtual_do_end(dill_stream s, int package) if (do_emulation) { #ifdef BUILD_EMULATOR - /* do a return, just in case it's missing */ - if (vmi->prefix_code_start == -1) { - dill_retii(s,0); - s->p->virtual.cur_ip = s->p->cur_ip; - } - setup_VM_proc(s); + /* do a return, just in case it's missing */ + if (vmi->prefix_code_start == -1) { + dill_retii(s, 0); + s->p->virtual.cur_ip = s->p->cur_ip; + } + setup_VM_proc(s); #endif - free_bbs(vmi); - s->p->mach_reset = dill_virtual_init; + free_bbs(vmi); + s->p->mach_reset = dill_virtual_init; } else if (dill_foreign_cg) { - (dill_foreign_cg)(s, (virtual_insn *)s->p->code_base, (virtual_insn *)s->p->cur_ip); + (dill_foreign_cg)(s, (virtual_insn*)s->p->code_base, + (virtual_insn*)s->p->cur_ip); } else { - s->j = s->p->native.mach_jump; - s->p->mach_reset = s->p->native.mach_reset; - s->p->mach_info = s->p->native.mach_info; - s->p->code_base = s->p->native.code_base; - s->p->native.code_base = NULL; - s->p->native.mach_info = NULL; - if (s->p->code_base == NULL) { - init_code_block(s); - s->p->native.code_base = s->p->code_base; - s->p->native.code_limit = s->p->code_limit; - } - s->p->cur_ip = s->p->code_base; - s->p->code_limit = s->p->native.code_limit; - - s->p->native_mach_reset(s); - ltable = build_label_translation(s); - (s->j->proc_start)(s, "no name", s->p->c_param_count, - vmi->arg_info, (void*)0); - fill_label_translation(s, ltable); - if (old_reg_alloc) { - do_register_assign(s, insns, code_end, virtual_local_pointer, vmi); - emit_insns(s, insns, ltable, vmi); - } else { - new_emit_insns(s, insns, ltable, vmi); - } - free_bbs(vmi); - free(ltable); - if (package) { - s->j->package_end(s); - } else { - dill_exec_handle h; - h = dill_finalize(s); - dill_free_handle(h); - } - s->j = s->p->native.mach_jump; - s->p->native.mach_reset = s->p->mach_reset; - s->p->native.mach_info = s->p->mach_info; - s->p->native.code_base = s->p->code_base; - s->p->native.cur_ip = s->p->cur_ip; - s->p->native.code_limit = s->p->code_limit; - if (!package) s->p->code_base = NULL; - s->p->mach_info = NULL; - s->p->mach_reset = dill_virtual_init; + s->j = s->p->native.mach_jump; + s->p->mach_reset = s->p->native.mach_reset; + s->p->mach_info = s->p->native.mach_info; + s->p->code_base = s->p->native.code_base; + s->p->native.code_base = NULL; + s->p->native.mach_info = NULL; + if (s->p->code_base == NULL) { + init_code_block(s); + s->p->native.code_base = s->p->code_base; + s->p->native.code_limit = s->p->code_limit; + } + s->p->cur_ip = s->p->code_base; + s->p->code_limit = s->p->native.code_limit; + + s->p->native_mach_reset(s); + ltable = build_label_translation(s); + (s->j->proc_start)(s, "no name", s->p->c_param_count, vmi->arg_info, + (void*)0); + fill_label_translation(s, ltable); + if (old_reg_alloc) { + do_register_assign(s, insns, code_end, virtual_local_pointer, vmi); + emit_insns(s, insns, ltable, vmi); + } else { + new_emit_insns(s, insns, ltable, vmi); + } + free_bbs(vmi); + free(ltable); + if (package) { + s->j->package_end(s); + } else { + dill_exec_handle h; + h = dill_finalize(s); + dill_free_handle(h); + } + s->j = s->p->native.mach_jump; + s->p->native.mach_reset = s->p->mach_reset; + s->p->native.mach_info = s->p->mach_info; + s->p->native.code_base = s->p->code_base; + s->p->native.cur_ip = s->p->cur_ip; + s->p->native.code_limit = s->p->code_limit; + if (!package) + s->p->code_base = NULL; + s->p->mach_info = NULL; + s->p->mach_reset = dill_virtual_init; } if (dill_verbose) { - dill_dump(s); + dill_dump(s); } } @@ -4456,45 +4547,49 @@ virtual_package_end(dill_stream c) virtual_do_end(c, 1 /* package */); } - extern dill_exec_ctx dill_get_exec_context(dill_stream c) { dill_exec_ctx ec = malloc(sizeof(struct dec)); - int vreg_count = c->p->vreg_count + 1; /* always at least 1 */ + int vreg_count = c->p->vreg_count + 1; /* always at least 1 */ int j; memset(ec, 0, sizeof(struct dec)); ec->dc = c; - if (vreg_count < 1) vreg_count = 1; + if (vreg_count < 1) + vreg_count = 1; ec->r = malloc(sizeof(ec->r[0]) * vreg_count); if (c->p->save_param_count >= 0) { - ec->p = malloc(sizeof(ec->p[0]) * c->p->save_param_count); + ec->p = malloc(sizeof(ec->p[0]) * c->p->save_param_count); } else { - ec->p = malloc(1); + ec->p = malloc(1); } ec->client_data_count = 0; ec->out_param_count = 0; ec->out_params = NULL; - for (j=0; j < c->p->vreg_count; j++) { - if (dill_type_of(c, 100 + j) == DILL_B) { - /* offset is really size, fix that */ - if (c->p->vregs[j].offset > 0) { - /* this is only used for interpretation */ - ec->r[j].u.p.p = malloc(c->p->vregs[j].offset); - } - /* GSE this is leaked!!!! must fix... !!!! */ - } + for (j = 0; j < c->p->vreg_count; j++) { + if (dill_type_of(c, 100 + j) == DILL_B) { + /* offset is really size, fix that */ + if (c->p->vregs[j].offset > 0) { + /* this is only used for interpretation */ + ec->r[j].u.p.p = malloc(c->p->vregs[j].offset); + } + /* GSE this is leaked!!!! must fix... !!!! */ + } } return ec; } - + extern void dill_free_exec_context(dill_exec_ctx ec) { - if (ec->r) free(ec->r); - if (ec->p) free(ec->p); - if (ec->client_data) free(ec->client_data); - if (ec->out_params) free(ec->out_params); + if (ec->r) + free(ec->r); + if (ec->p) + free(ec->p); + if (ec->client_data) + free(ec->client_data); + if (ec->out_params) + free(ec->out_params); free(ec); } @@ -4502,17 +4597,18 @@ extern void dill_assoc_client_data(dill_exec_ctx ec, int key, IMM_TYPE value) { int i = 0; - for (i=0; i < ec->client_data_count; i++) { - if (ec->client_data[i].key == key) { - ec->client_data[i].value = value; - return; - } + for (i = 0; i < ec->client_data_count; i++) { + if (ec->client_data[i].key == key) { + ec->client_data[i].value = value; + return; + } } if (ec->client_data_count == 0) { - ec->client_data = malloc(sizeof(struct client_data_struct)); + ec->client_data = malloc(sizeof(struct client_data_struct)); } else { - ec->client_data = realloc(ec->client_data, sizeof(struct client_data_struct) * - (ec->client_data_count + 1)); + ec->client_data = + realloc(ec->client_data, sizeof(struct client_data_struct) * + (ec->client_data_count + 1)); } ec->client_data[ec->client_data_count].key = key; ec->client_data[ec->client_data_count++].value = value; @@ -4522,11 +4618,10 @@ extern IMM_TYPE dill_get_client_data(dill_exec_ctx ec, int key) { int i = 0; - for (i=0; i < ec->client_data_count; i++) { - if (ec->client_data[i].key == key) { - return ec->client_data[i].value; - } + for (i = 0; i < ec->client_data_count; i++) { + if (ec->client_data[i].key == key) { + return ec->client_data[i].value; + } } return -1; } - diff --git a/virtual.h b/virtual.h index 910b4b3c94..5dc313b9ac 100644 --- a/virtual.h +++ b/virtual.h @@ -1,50 +1,59 @@ -#define INSN_OUT(c, i) \ -if ((((char*)c->p->cur_ip) + sizeof(virtual_insn)) >= (char*)c->p->code_limit) {\ - extend_dill_stream(c);\ -}\ -*(virtual_insn*)c->p->cur_ip = i;\ -if (c->dill_debug) {\ -printf("%p -- ", c->p->cur_ip);\ -virtual_print_insn(c, NULL, c->p->cur_ip);\ -printf("\n");}\ -c->p->cur_ip = ((char*)c->p->cur_ip)+ sizeof(virtual_insn) +#define INSN_OUT(c, i) \ + if ((((char*)c->p->cur_ip) + sizeof(virtual_insn)) >= \ + (char*)c->p->code_limit) { \ + extend_dill_stream(c); \ + } \ + *(virtual_insn*)c->p->cur_ip = i; \ + if (c->dill_debug) { \ + printf("%p -- ", c->p->cur_ip); \ + virtual_print_insn(c, NULL, c->p->cur_ip); \ + printf("\n"); \ + } \ + c->p->cur_ip = ((char*)c->p->cur_ip) + sizeof(virtual_insn) typedef struct bitv { short len; char vec[2]; -} *bit_vec; +} * bit_vec; typedef struct basic_block { - int start; - int end; + ssize_t start; + ssize_t end; int label; int end_branch_label; int fall_through; int pred_count; - int *pred_list; + int* pred_list; int succ_count; - int *succ_list; + int* succ_list; bit_vec regs_used; bit_vec regs_defined; bit_vec live_at_end; - short *reg_assigns; + short* reg_assigns; int visited; int is_loop_start; int is_loop_end; -} *basic_block; - +} * basic_block; + typedef struct mach_info { arg_info_list arg_info; int bbcount; basic_block bblist; int prefix_code_start; -} *virtual_mach_info; +} * virtual_mach_info; -extern int dill_type_of(dill_stream c, int vreg); +extern int +dill_type_of(dill_stream c, size_t vreg); +extern void +virtual_proc_start(dill_stream c, + char* subr_name, + int arg_count, + arg_info_list args, + dill_reg* arglist); +extern void +virtual_end(dill_stream c); extern void -virtual_proc_start(dill_stream c, char *subr_name, int arg_count, - arg_info_list args, dill_reg *arglist); -extern void virtual_end(dill_stream c); -extern void virtual_package_end(dill_stream c); -extern int virtual_print_insn(dill_stream c, void *info_ptr, void *i); +virtual_package_end(dill_stream c); +extern int +virtual_print_insn(dill_stream c, void* info_ptr, void* i); diff --git a/virtual.ops b/virtual.ops index bdac2355f3..35e03b44cd 100644 --- a/virtual.ops +++ b/virtual.ops @@ -164,14 +164,22 @@ sub arith_insn { sub arith2_insn { local ($ops, $type_list, $subr) = @_; + %src1_cast = ('u', '(unsigned int)'); foreach(split(' ', $ops)) { $op = $_; $c_op = $c_operations{$op}; foreach(split(' ', $type_list)) { + if (($c_op eq '-') and ($_ eq "u")) { + $actual_op = '(unsigned) - (int)'; + } elsif (($c_op eq '-') and ($_ eq "ul")) { + $actual_op = '(uintptr_t) - (intptr_t)'; + } else { + $actual_op = $c_op; + } $jmp_a2_assigns = $jmp_a2_assigns . "\t ${mach}_jump_table->jmp_a2[dill_jmp_${op}${_}] = $subr;\n"; $jmp_a2_assigns = $jmp_a2_assigns . "\t ${mach}_jump_table->a2_data[dill_jmp_${op}${_}].data1 = dill_jmp_${op}${_};\n"; $jmp_a2_assigns = $jmp_a2_assigns . "\t ${mach}_jump_table->a2_data[dill_jmp_${op}${_}].data2 = 0;\n"; - $vm_a2_code .= "\t case dill_jmp_${op}${_}: dest->u.${_}.${_} = $c_op $src_cast{$_} src->u.${_}.${_}; break;\n"; + $vm_a2_code .= "\t case dill_jmp_${op}${_}: dest->u.${_}.${_} = $actual_op $src_cast{$_} src->u.${_}.${_}; break;\n"; } } } @@ -179,6 +187,7 @@ sub arith2_insn { sub arithi_insn { local ($ops, $type_list, $subr, $code1, $code2) = @_; %src1_cast = ('p', '(char*)'); + %src2_cast = ('i', '(int)', 'u', '(unsigned int)'); foreach(split(' ', $ops)) { $op = $_; $c_op = $c_operations{$op}; @@ -209,6 +218,7 @@ sub branch_insn { sub branchi_insn { local($ops, $types, $subr) = @_; + %src1_cast = ('u', '(unsigned int)', 'ul', '(uintptr_t)', 'p', '(IMM_TYPE)'); foreach (split(' ', $ops)) { $op = $_; $c_op = $c_operations{$op}; @@ -236,7 +246,7 @@ sub compare_insn { sub convert { local($from_types, $to_types) = @_; - %src_cast = ('pul', '(IMM_TYPE)', 'ulp', '(void*)'); + %src_cast = ('pul', '(IMM_TYPE)', 'ulp', '(void*)', 'c', '(char)', 's', '(short)', 'uc', '(unsigned char)', 'us', '(unsigned short)', 'i', '(int)', 'u', '(unsigned int)', 'l', '(intptr_t)', 'ul', '(uintptr_t)', 'f', '(float)', 'd', '(double)'); %convert_right = ('c', 'src->u.c.c', 's', '((short)(0xffff & src->u.s.s))', 'i', '((int)(0xffffffff & src->u.i.i))', 'uc', '((unsigned char)(0xff & src->u.uc.uc))', 'us', '((unsigned short)(0xffff & src->u.us.us))', 'u', '((unsigned int)(0xffffffff & src->u.u.u))', 'l', 'src->u.l.l', 'ul', '(UIMM_TYPE)src->u.ul.ul', 'd', 'src->u.d.d', 'f', 'src->u.f.f', 'p', 'src->u.l.l'); foreach (split(' ', $from_types)) { $from = $_; @@ -246,7 +256,7 @@ sub convert { } $dest_fld = ${_}; if ($_ eq "p") {$dest_fld = "ul";} - $vm_cvt_code .= "\tcase CONV(DILL_" . &upperc(${from}) . ", DILL_" . &upperc($_) . "): dest->u.${dest_fld}.${dest_fld} = $convert_right{$from}; break;\n"; + $vm_cvt_code .= "\tcase CONV(DILL_" . &upperc(${from}) . ", DILL_" . &upperc($_) . "): dest->u.${dest_fld}.${dest_fld} = $src_cast{$_} $convert_right{$from}; break;\n"; } } } @@ -278,36 +288,19 @@ print COUT< #include #include #include -#ifdef HAVE_MALLOC_H -#include -#endif #include +#ifdef _MSC_VER +#include +typedef SSIZE_T ssize_t; #else -#ifdef LINUX_KERNEL_MODULE -#ifndef __KERNEL__ -#define __KERNEL__ -#endif -#endif -#include -#include -#include -#include "kdill.h" -#include "library.h" - -#define printf printk -#define fprintf(file, args...) printk (args) -#define malloc (void *)DAllocMM -#define realloc(a,b) (void *)DReallocMM((addrs_t)a, b) -#define free(a) DFreeMM((addrs_t) a) -#define qsort _quicksort +#include #endif +#include "dill_internal.h" +#include "virtual.h" static void dill_varith3(dill_stream s, int op3, int op, int dest, int src1, int src2) diff --git a/vm.c b/vm.c index a16bf4e543..c3764e7790 100644 --- a/vm.c +++ b/vm.c @@ -1,28 +1,34 @@ #include "config.h" #include "dill.h" -#include "dill_internal.h" -#include "virtual.h" #undef NDEBUG -#include "assert.h" -#include #include +#include +#include "assert.h" #ifdef HAVE_MALLOC_H #include #endif -#include -#include #include +#include +#include +#ifdef _MSC_VER +#include +typedef SSIZE_T ssize_t; +#else +#include +#endif -#define PREG(ec, reg) ((reg < 100) ? &ec->p[reg] : &ec->r[reg-100]) - +#define PREG(ec, reg) ((reg < 100) ? &ec->p[reg] : &ec->r[reg - 100]) +#include "dill_internal.h" +#include "virtual.h" #include "vm_include.c" #ifdef BUILD_EMULATOR #include -static void run_emulation(dill_exec_ctx ec); +static void +run_emulation(dill_exec_ctx ec); -static -void emu_func(ffi_cif *cif, void*vret, void* args[], void *client_data) +static void +emu_func(ffi_cif* cif, void* vret, void* args[], void* client_data) { int i; dill_stream c = client_data; @@ -30,96 +36,94 @@ void emu_func(ffi_cif *cif, void*vret, void* args[], void *client_data) dill_exec_ctx ec; if ((param_count >= 1) && (c->p->c_param_args[0].type == DILL_EC)) { - ec = *(dill_exec_ctx*)args[0]; + ec = *(dill_exec_ctx*)args[0]; } else { - /* create an execution context to use */ - ec = dill_get_exec_context(c); - } + /* create an execution context to use */ + ec = dill_get_exec_context(c); + } if (!ec->p) { - ec->p = malloc(param_count * sizeof(struct reg_type)); + ec->p = malloc(param_count * sizeof(struct reg_type)); } - for (i= 0; i < param_count; i++) { - switch (c->p->c_param_args[i].type) { - case DILL_C: - ec->p[i].u.c.c = *((char **)args)[i]; - break; - case DILL_UC: - ec->p[i].u.uc.uc = *((unsigned char **)args)[i]; - break; - case DILL_S: - ec->p[i].u.s.s = *((short **)args)[i]; - break; - case DILL_US: - ec->p[i].u.us.us = *((unsigned short **)args)[i]; - break; - case DILL_I: - ec->p[i].u.i.i = *((int **)args)[i]; - break; - case DILL_U: - ec->p[i].u.u.u = *((unsigned int **)args)[i]; - break; - case DILL_L: - ec->p[i].u.l.l = *((long **)args)[i]; - break; - case DILL_UL: - ec->p[i].u.ul.ul = *((unsigned long **)args)[i]; - break; - case DILL_F: - ec->p[i].u.f.f = *((float **)args)[i]; - break; - case DILL_D: - ec->p[i].u.d.d = *((double **)args)[i]; - break; - case DILL_P: - case DILL_EC: - ec->p[i].u.p.p = *((void ***)args)[i]; - break; - } + for (i = 0; i < param_count; i++) { + switch (c->p->c_param_args[i].type) { + case DILL_C: + ec->p[i].u.c.c = *((char**)args)[i]; + break; + case DILL_UC: + ec->p[i].u.uc.uc = *((unsigned char**)args)[i]; + break; + case DILL_S: + ec->p[i].u.s.s = *((short**)args)[i]; + break; + case DILL_US: + ec->p[i].u.us.us = *((unsigned short**)args)[i]; + break; + case DILL_I: + ec->p[i].u.i.i = *((int**)args)[i]; + break; + case DILL_U: + ec->p[i].u.u.u = *((unsigned int**)args)[i]; + break; + case DILL_L: + ec->p[i].u.l.l = *((long**)args)[i]; + break; + case DILL_UL: + ec->p[i].u.ul.ul = *((unsigned long**)args)[i]; + break; + case DILL_F: + ec->p[i].u.f.f = *((float**)args)[i]; + break; + case DILL_D: + ec->p[i].u.d.d = *((double**)args)[i]; + break; + case DILL_P: + case DILL_EC: + ec->p[i].u.p.p = *((void***)args)[i]; + break; + } } /* execute the function */ run_emulation(ec); /* do return */ - switch(c->p->ret_type) { + switch (c->p->ret_type) { case DILL_C: - *((long *)vret) = (PREG(ec, ec->ret_reg)->u.c.c); - break; + *((long*)vret) = (PREG(ec, ec->ret_reg)->u.c.c); + break; case DILL_UC: - *((ffi_arg *)vret) = (PREG(ec, ec->ret_reg)->u.uc.uc); - break; + *((ffi_arg*)vret) = (PREG(ec, ec->ret_reg)->u.uc.uc); + break; case DILL_S: - *((ffi_sarg *)vret) = (PREG(ec, ec->ret_reg)->u.s.s); - break; + *((ffi_sarg*)vret) = (PREG(ec, ec->ret_reg)->u.s.s); + break; case DILL_US: - *((ffi_arg *)vret) = (PREG(ec, ec->ret_reg)->u.us.us); - break; + *((ffi_arg*)vret) = (PREG(ec, ec->ret_reg)->u.us.us); + break; case DILL_I: - *((ffi_sarg *)vret) = (PREG(ec, ec->ret_reg)->u.i.i); - break; + *((ffi_sarg*)vret) = (PREG(ec, ec->ret_reg)->u.i.i); + break; case DILL_U: - *((ffi_arg *)vret) = (PREG(ec, ec->ret_reg)->u.u.u); - break; + *((ffi_arg*)vret) = (PREG(ec, ec->ret_reg)->u.u.u); + break; case DILL_L: - *((ffi_sarg *)vret) = (PREG(ec, ec->ret_reg)->u.l.l); - break; + *((ffi_sarg*)vret) = (PREG(ec, ec->ret_reg)->u.l.l); + break; case DILL_UL: - *((ffi_arg *)vret) = (PREG(ec, ec->ret_reg)->u.ul.ul); - break; + *((ffi_arg*)vret) = (PREG(ec, ec->ret_reg)->u.ul.ul); + break; case DILL_F: - *((float *)vret) = (PREG(ec, ec->ret_reg)->u.f.f); - break; + *((float*)vret) = (PREG(ec, ec->ret_reg)->u.f.f); + break; case DILL_D: - *((double *)vret) = (PREG(ec, ec->ret_reg)->u.d.d); - break; + *((double*)vret) = (PREG(ec, ec->ret_reg)->u.d.d); + break; case DILL_P: - *((void**)vret) = (PREG(ec, ec->ret_reg)->u.p.p); - break; + *((void**)vret) = (PREG(ec, ec->ret_reg)->u.p.p); + break; } } -extern void * -emulate_clone_code(c, new_base, available_size) -dill_stream c; -void *new_base; +extern void* emulate_clone_code(c, new_base, available_size) dill_stream c; +void* new_base; int available_size; { return c->p->fp; @@ -128,20 +132,23 @@ int available_size; void free_emulator_handler_bits(dill_exec_handle handle) { - if (handle->emu_args) free(handle->emu_args); - if (handle->cifp) free(handle->cifp); - if (handle->closure) ffi_closure_free(handle->closure); + if (handle->emu_args) + free(handle->emu_args); + if (handle->cifp) + free(handle->cifp); + if (handle->closure) + ffi_closure_free(handle->closure); } void setup_VM_proc(dill_stream c) { - ffi_cif *cifp = malloc(sizeof(ffi_cif)); - ffi_type **args = NULL; - ffi_closure *closure; - void *func; - ffi_type *ret_type; - void *ret_addr = NULL; + ffi_cif* cifp = malloc(sizeof(ffi_cif)); + ffi_type** args = NULL; + ffi_closure* closure; + void* func; + ffi_type* ret_type; + void* ret_addr = NULL; int i; c->p->fp = NULL; @@ -151,92 +158,90 @@ setup_VM_proc(dill_stream c) switch (c->p->ret_type) { case DILL_C: - ret_type = &ffi_type_sint8; - break; + ret_type = &ffi_type_sint8; + break; case DILL_UC: - ret_type = &ffi_type_uint8; - break; + ret_type = &ffi_type_uint8; + break; case DILL_S: - ret_type = &ffi_type_sint16; - break; + ret_type = &ffi_type_sint16; + break; case DILL_US: - ret_type = &ffi_type_uint16; - break; + ret_type = &ffi_type_uint16; + break; case DILL_I: - ret_type = &ffi_type_sint32; - break; + ret_type = &ffi_type_sint32; + break; case DILL_U: - ret_type = &ffi_type_uint32; - break; + ret_type = &ffi_type_uint32; + break; case DILL_L: - ret_type = &ffi_type_sint64; - break; + ret_type = &ffi_type_sint64; + break; case DILL_UL: - ret_type = &ffi_type_uint64; - break; + ret_type = &ffi_type_uint64; + break; case DILL_P: - ret_type = &ffi_type_pointer; - break; + ret_type = &ffi_type_pointer; + break; case DILL_F: - ret_type = &ffi_type_float; - break; + ret_type = &ffi_type_float; + break; case DILL_D: - ret_type = &ffi_type_double; - break; + ret_type = &ffi_type_double; + break; case DILL_V: - ret_type = &ffi_type_void; - break; + ret_type = &ffi_type_void; + break; } args = malloc(c->p->c_param_count * sizeof(args[0])); - for (i=0; i < c->p->c_param_count; i++) { - switch(c->p->c_param_args[i].type) { - case DILL_C: - args[i] = &ffi_type_sint8; - break; - case DILL_UC: - args[i] = &ffi_type_uint8; - break; - case DILL_S: - args[i] = &ffi_type_sint16; - break; - case DILL_US: - args[i] = &ffi_type_uint16; - break; - case DILL_I: - args[i] = &ffi_type_sint32; - break; - case DILL_U: - args[i] = &ffi_type_uint32; - break; - case DILL_L: - args[i] = &ffi_type_sint64; - break; - case DILL_UL: - args[i] = &ffi_type_uint64; - break; - case DILL_EC: - case DILL_P: - args[i] = &ffi_type_pointer; - break; - case DILL_F: - args[i] = &ffi_type_float; - break; - case DILL_D: - args[i] = &ffi_type_double; - break; - case DILL_V: - args[i] = &ffi_type_void; - } + for (i = 0; i < c->p->c_param_count; i++) { + switch (c->p->c_param_args[i].type) { + case DILL_C: + args[i] = &ffi_type_sint8; + break; + case DILL_UC: + args[i] = &ffi_type_uint8; + break; + case DILL_S: + args[i] = &ffi_type_sint16; + break; + case DILL_US: + args[i] = &ffi_type_uint16; + break; + case DILL_I: + args[i] = &ffi_type_sint32; + break; + case DILL_U: + args[i] = &ffi_type_uint32; + break; + case DILL_L: + args[i] = &ffi_type_sint64; + break; + case DILL_UL: + args[i] = &ffi_type_uint64; + break; + case DILL_EC: + case DILL_P: + args[i] = &ffi_type_pointer; + break; + case DILL_F: + args[i] = &ffi_type_float; + break; + case DILL_D: + args[i] = &ffi_type_double; + break; + case DILL_V: + args[i] = &ffi_type_void; + } } - if (ffi_prep_cif(cifp, FFI_DEFAULT_ABI, c->p->c_param_count, - ret_type, args) != FFI_OK) { - return; + if (ffi_prep_cif(cifp, FFI_DEFAULT_ABI, c->p->c_param_count, ret_type, + args) != FFI_OK) { + return; } - if (ffi_prep_closure_loc(closure, cifp, emu_func, - c, func) != FFI_OK) { - - return; + if (ffi_prep_closure_loc(closure, cifp, emu_func, c, func) != FFI_OK) { + return; } c->p->fp = func; c->p->emu_args = args; @@ -244,373 +249,373 @@ setup_VM_proc(dill_stream c) c->p->closure = closure; } -static void run_emulation(dill_exec_ctx ec) +static void +run_emulation(dill_exec_ctx ec) { dill_stream c = ec->dc; - void *insns = c->p->code_base; - virtual_insn *ip = &((virtual_insn *)insns)[0]; + void* insns = c->p->code_base; + virtual_insn* ip = &((virtual_insn*)insns)[0]; virtual_mach_info vmi = (virtual_mach_info)c->p->mach_info; if (vmi->prefix_code_start != -1) { - ip = (virtual_insn*)((char*)insns + (vmi->prefix_code_start * sizeof(virtual_insn))); + ip = (virtual_insn*)((char*)insns + + (vmi->prefix_code_start * sizeof(virtual_insn))); } int varidiac_call = 0; while (1) { - struct reg_type *pused[3]; - struct reg_type *pdest; - int loc; - int insn_code; - insn_code = ip->insn_code; - loc = ((char*)ip - (char*)insns); - if (c->dill_debug) { - printf(" v loc(%d) ", loc); - virtual_print_insn(c, NULL, ip); - printf("\n"); - } - switch(ip->class_code) { - case iclass_arith3: { - /* arith 3 operand integer insns */ - int r0 = ip->opnds.a3.src1; - int r1 = ip->opnds.a3.src2; - int d = ip->opnds.a3.dest; - pused[0] = PREG(ec, r0); - pused[1] = PREG(ec, r1); - pdest = PREG(ec, d); - emulate_arith3(insn_code, pdest, pused[0], pused[1]); - break; - } - case iclass_arith2: { - /* arith 2 operand integer insns */ - int r0 = ip->opnds.a2.src; - int d = ip->opnds.a2.dest; - pused[0] = PREG(ec, r0); - pdest = PREG(ec, d); - emulate_arith2(insn_code, pdest, pused[0]); - break; - } - case iclass_arith3i:{ - /* arith 3 immediate operand integer insns */ - int r0 = ip->opnds.a3i.src; - int d = ip->opnds.a3i.dest; - pused[0] = PREG(ec, r0); - pdest = PREG(ec, d); - emulate_arith3i(insn_code, pdest, pused[0], ip->opnds.a3i.u.imm); - break; - } - case iclass_ret: - ec->ret_reg = ip->opnds.a1.src; - return; - break; - case iclass_convert: { - int r0 = ip->opnds.a2.src; - int d = ip->opnds.a2.dest; - pused[0] = PREG(ec, r0); - pdest = PREG(ec, d); - emulate_convert(ip->insn_code & 0xff, pdest, pused[0]); - break; - } - case iclass_loadstore: { - /* load store immediate operand integer insns */ - pdest = PREG(ec, ip->opnds.a3.dest); - pused[0] = PREG(ec, ip->opnds.a3.src1); - pused[1] = PREG(ec, ip->opnds.a3.src2); - if ((ip->insn_code >> 4) == 0) { - emulate_loadi(ip->insn_code & 0xf, - pdest, pused[0], - pused[1]->u.l.l); - } else { - /* a store, dest is the source of the store */ - emulate_storei(ip->insn_code & 0xf, - pdest, pused[0], - pused[1]->u.l.l); - } - break; - } - case iclass_lea: { - int offset = ip->opnds.a3i.u.imm; - pused[0] = PREG(ec, ip->opnds.a3i.src); - pdest = PREG(ec, ip->opnds.a3i.dest); - pdest->u.p.p = ((char*)pused[0]->u.p.p) + offset; - break; - } - case iclass_loadstorei: - /* load store immediate operand integer insns */ - pdest = PREG(ec, ip->opnds.a3i.dest); - pused[0] = PREG(ec, ip->opnds.a3i.src); - if ((ip->insn_code >> 4) == 0) { - emulate_loadi(ip->insn_code & 0xf, - pdest, pused[0], - ip->opnds.a3i.u.imm); - } else { - /* a store, dest is the source of the store */ - emulate_storei(ip->insn_code & 0xf, - pdest, pused[0], - ip->opnds.a3i.u.imm); - } - break; - case iclass_set: { - pdest = PREG(ec, ip->opnds.a3i.dest); - pdest->u.l.l = ip->opnds.a3i.u.imm; - break; - } - case iclass_setf: { - pdest = PREG(ec, ip->opnds.sf.dest); - if ((ip->insn_code & 0xf) == DILL_F) { - pdest->u.f.f = (float) ip->opnds.sf.imm; - } else { - pdest->u.d.d = ip->opnds.sf.imm; - } - break; - } - case iclass_mov: { - pdest = PREG(ec, ip->opnds.a2.dest); - pused[0] = PREG(ec, ip->opnds.a2.src); + struct reg_type* pused[3]; + struct reg_type* pdest; + int loc; + int insn_code; + insn_code = ip->insn_code; + loc = ((char*)ip - (char*)insns); + if (c->dill_debug) { + printf(" v loc(%d) ", loc); + virtual_print_insn(c, NULL, ip); + printf("\n"); + } + switch (ip->class_code) { + case iclass_arith3: { + /* arith 3 operand integer insns */ + int r0 = ip->opnds.a3.src1; + int r1 = ip->opnds.a3.src2; + int d = ip->opnds.a3.dest; + pused[0] = PREG(ec, r0); + pused[1] = PREG(ec, r1); + pdest = PREG(ec, d); + emulate_arith3(insn_code, pdest, pused[0], pused[1]); + break; + } + case iclass_arith2: { + /* arith 2 operand integer insns */ + int r0 = ip->opnds.a2.src; + int d = ip->opnds.a2.dest; + pused[0] = PREG(ec, r0); + pdest = PREG(ec, d); + emulate_arith2(insn_code, pdest, pused[0]); + break; + } + case iclass_arith3i: { + /* arith 3 immediate operand integer insns */ + int r0 = ip->opnds.a3i.src; + int d = ip->opnds.a3i.dest; + pused[0] = PREG(ec, r0); + pdest = PREG(ec, d); + emulate_arith3i(insn_code, pdest, pused[0], ip->opnds.a3i.u.imm); + break; + } + case iclass_ret: + ec->ret_reg = ip->opnds.a1.src; + return; + break; + case iclass_convert: { + int r0 = ip->opnds.a2.src; + int d = ip->opnds.a2.dest; + pused[0] = PREG(ec, r0); + pdest = PREG(ec, d); + emulate_convert(ip->insn_code & 0xff, pdest, pused[0]); + break; + } + case iclass_loadstore: { + /* load store immediate operand integer insns */ + pdest = PREG(ec, ip->opnds.a3.dest); + pused[0] = PREG(ec, ip->opnds.a3.src1); + pused[1] = PREG(ec, ip->opnds.a3.src2); + if ((ip->insn_code >> 4) == 0) { + emulate_loadi(ip->insn_code & 0xf, pdest, pused[0], + pused[1]->u.l.l); + } else { + /* a store, dest is the source of the store */ + emulate_storei(ip->insn_code & 0xf, pdest, pused[0], + pused[1]->u.l.l); + } + break; + } + case iclass_lea: { + int offset = ip->opnds.a3i.u.imm; + pused[0] = PREG(ec, ip->opnds.a3i.src); + pdest = PREG(ec, ip->opnds.a3i.dest); + pdest->u.p.p = ((char*)pused[0]->u.p.p) + offset; + break; + } + case iclass_loadstorei: + /* load store immediate operand integer insns */ + pdest = PREG(ec, ip->opnds.a3i.dest); + pused[0] = PREG(ec, ip->opnds.a3i.src); + if ((ip->insn_code >> 4) == 0) { + emulate_loadi(ip->insn_code & 0xf, pdest, pused[0], + ip->opnds.a3i.u.imm); + } else { + /* a store, dest is the source of the store */ + emulate_storei(ip->insn_code & 0xf, pdest, pused[0], + ip->opnds.a3i.u.imm); + } + break; + case iclass_set: { + pdest = PREG(ec, ip->opnds.a3i.dest); + pdest->u.l.l = ip->opnds.a3i.u.imm; + break; + } + case iclass_setf: { + pdest = PREG(ec, ip->opnds.sf.dest); + if ((ip->insn_code & 0xf) == DILL_F) { + pdest->u.f.f = (float)ip->opnds.sf.imm; + } else { + pdest->u.d.d = ip->opnds.sf.imm; + } + break; + } + case iclass_mov: { + pdest = PREG(ec, ip->opnds.a2.dest); + pused[0] = PREG(ec, ip->opnds.a2.src); - pdest->u = pused[0]->u; - break; - } - case iclass_reti: - /* return immediate integer insns */ - /* arbitrarily destroy reg 100 and return it */ - ec->ret_reg = 100; -// switch(ip->insn_code & 0xf) { - PREG(ec, ec->ret_reg)->u.l.l = ip->opnds.a3i.u.imm; - return; - case iclass_branch: - { - /* branch */ - int br_op = ip->insn_code; - int r0 = ip->opnds.br.src1; - int r1 = ip->opnds.br.src2; - pused[0] = PREG(ec, r0); - pused[1] = PREG(ec, r1); - if (emulate_branch(br_op, pused[0], pused[1])) { - ip = (void*)(((char *)(&((virtual_insn *)insns)[-1])) + c->p->branch_table.label_locs[ip->opnds.br.label]); - } - } - break; - case iclass_branchi: - { - /* branch immediate */ - int br_op = ip->insn_code; - int r0 = ip->opnds.bri.src; - pused[0] = PREG(ec, r0); - if (emulate_branchi(br_op, pused[0], ip->opnds.bri.imm_l)) { - ip = (void*)(((char *)(&((virtual_insn *)insns)[-1])) + c->p->branch_table.label_locs[ip->opnds.bri.label]); - } - } - break; - case iclass_jump_to_label: - ip = (void*)(((char *)(&((virtual_insn *)insns)[-1])) + c->p->branch_table.label_locs[ip->opnds.br.label]); - break; - break; - case iclass_jump_to_reg: - printf("Unimpl13\n"); - /* dill_jp(c, pused[0]);*/ - break; - case iclass_jump_to_imm: - printf("Unimpl14\n"); - dill_jpi(c, ip->opnds.bri.imm_a); - break; - case iclass_special: - printf("Unimpl15\n"); - dill_special(c, ip->opnds.spec.type, ip->opnds.spec.param); - break; - case iclass_call: - { - int i; - int ret_reg = ip->opnds.bri.src; - int reg = ip->insn_code & 0x10; - int typ = ip->insn_code & 0xf; - ffi_type **args = malloc(sizeof(args[0])*ec->out_param_count); - void **values = malloc(sizeof(values[0])*ec->out_param_count); - void *func; - ffi_type *ret_type; - void *ret_addr = NULL; - ffi_cif cif; - int ret; - pused[0] = PREG(ec, ret_reg); - if (reg != 0) { - func = PREG(ec, (long)ip->opnds.bri.imm_l)->u.p.p; - } else { - func = (void*)ip->opnds.bri.imm_a; - } - switch(typ) { - case DILL_C: - ret_type = &ffi_type_sint8; - ret_addr = &pused[0]->u.l.l; - break; - case DILL_UC: - ret_type = &ffi_type_uint8; - ret_addr = &pused[0]->u.ul.ul; - break; - case DILL_S: - ret_type = &ffi_type_sint16; - ret_addr = &pused[0]->u.l.l; - break; - case DILL_US: - ret_type = &ffi_type_uint16; - ret_addr = &pused[0]->u.ul.ul; - break; - case DILL_I: - ret_type = &ffi_type_sint32; - ret_addr = &pused[0]->u.l.l; - break; - case DILL_U: - ret_type = &ffi_type_uint32; - ret_addr = &pused[0]->u.ul.ul; - break; - case DILL_L: - ret_type = &ffi_type_sint64; - ret_addr = &pused[0]->u.l.l; - break; - case DILL_UL: - ret_type = &ffi_type_uint64; - ret_addr = &pused[0]->u.ul.ul; - break; - case DILL_P: - ret_type = &ffi_type_pointer; - ret_addr = &pused[0]->u.p.p; - break; - case DILL_F: - ret_type = &ffi_type_float; - ret_addr = &pused[0]->u.f.f; - break; - case DILL_D: - ret_type = &ffi_type_double; - ret_addr = &pused[0]->u.d.d; - break; - case DILL_V: - ret_type = &ffi_type_void; - ret_addr = NULL; - break; - } - for (i=0; i < ec->out_param_count; i++) { - switch(ec->out_params[i].typ) { - case DILL_C: - args[i] = &ffi_type_sint8; - values[i] = &ec->out_params[i].val.u.c.c; - break; - case DILL_UC: - args[i] = &ffi_type_uint8; - values[i] = &ec->out_params[i].val.u.uc.uc; - break; - case DILL_S: - args[i] = &ffi_type_sint16; - values[i] = &ec->out_params[i].val.u.s.s; - break; - case DILL_US: - args[i] = &ffi_type_uint16; - values[i] = &ec->out_params[i].val.u.us.us; - break; - case DILL_I: - args[i] = &ffi_type_sint32; - values[i] = &ec->out_params[i].val.u.i.i; - break; - case DILL_U: - args[i] = &ffi_type_uint32; - values[i] = &ec->out_params[i].val.u.u.u; - break; - case DILL_L: - args[i] = &ffi_type_sint64; - values[i] = &ec->out_params[i].val.u.l.l; - break; - case DILL_UL: - args[i] = &ffi_type_uint64; - values[i] = &ec->out_params[i].val.u.ul.ul; - break; - case DILL_P: - args[i] = &ffi_type_pointer; - values[i] = &ec->out_params[i].val.u.p.p; - break; - case DILL_F: - args[i] = &ffi_type_float; - values[i] = &ec->out_params[i].val.u.f.f; - break; - case DILL_D: - args[i] = &ffi_type_double; - values[i] = &ec->out_params[i].val.u.d.d; - break; - case DILL_V: - break; - } - } - if (varidiac_call <= -2) { - ret = ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, - -(varidiac_call +2), - ec->out_param_count, - ret_type, args); - } else { - ret = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, ec->out_param_count, - ret_type, args); - } - if (ret == FFI_OK) { - ffi_call(&cif, func, ret_addr, values); - } - } - break; + pdest->u = pused[0]->u; + break; + } + case iclass_reti: + /* return immediate integer insns */ + /* arbitrarily destroy reg 100 and return it */ + ec->ret_reg = 100; + // switch(ip->insn_code & 0xf) { + PREG(ec, ec->ret_reg)->u.l.l = ip->opnds.a3i.u.imm; + return; + case iclass_branch: { + /* branch */ + int br_op = ip->insn_code; + int r0 = ip->opnds.br.src1; + int r1 = ip->opnds.br.src2; + pused[0] = PREG(ec, r0); + pused[1] = PREG(ec, r1); + if (emulate_branch(br_op, pused[0], pused[1])) { + ip = (void*)(((char*)(&((virtual_insn*)insns)[-1])) + + c->p->branch_table.label_locs[ip->opnds.br.label]); + } + } break; + case iclass_branchi: { + /* branch immediate */ + int br_op = ip->insn_code; + int r0 = ip->opnds.bri.src; + pused[0] = PREG(ec, r0); + if (emulate_branchi(br_op, pused[0], ip->opnds.bri.imm_l)) { + ip = + (void*)(((char*)(&((virtual_insn*)insns)[-1])) + + c->p->branch_table.label_locs[ip->opnds.bri.label]); + } + } break; + case iclass_jump_to_label: + ip = (void*)(((char*)(&((virtual_insn*)insns)[-1])) + + c->p->branch_table.label_locs[ip->opnds.br.label]); + break; + break; + case iclass_jump_to_reg: + printf("Unimpl13\n"); + /* dill_jp(c, pused[0]);*/ + break; + case iclass_jump_to_imm: + printf("Unimpl14\n"); + dill_jpi(c, ip->opnds.bri.imm_a); + break; + case iclass_special: + printf("Unimpl15\n"); + dill_special(c, ip->opnds.spec.type, ip->opnds.spec.param); + break; + case iclass_call: { + int i; + int ret_reg = ip->opnds.bri.src; + int reg = ip->insn_code & 0x10; + int typ = ip->insn_code & 0xf; + ffi_type** args = malloc(sizeof(args[0]) * ec->out_param_count); + void** values = malloc(sizeof(values[0]) * ec->out_param_count); + void* func; + ffi_type* ret_type; + void* ret_addr = NULL; + ffi_cif cif; + int ret; + pused[0] = PREG(ec, ret_reg); + if (reg != 0) { + func = PREG(ec, (long)ip->opnds.bri.imm_l)->u.p.p; + } else { + func = (void*)ip->opnds.bri.imm_a; + } + switch (typ) { + case DILL_C: + ret_type = &ffi_type_sint8; + ret_addr = &pused[0]->u.l.l; + break; + case DILL_UC: + ret_type = &ffi_type_uint8; + ret_addr = &pused[0]->u.ul.ul; + break; + case DILL_S: + ret_type = &ffi_type_sint16; + ret_addr = &pused[0]->u.l.l; + break; + case DILL_US: + ret_type = &ffi_type_uint16; + ret_addr = &pused[0]->u.ul.ul; + break; + case DILL_I: + ret_type = &ffi_type_sint32; + ret_addr = &pused[0]->u.l.l; + break; + case DILL_U: + ret_type = &ffi_type_uint32; + ret_addr = &pused[0]->u.ul.ul; + break; + case DILL_L: + ret_type = &ffi_type_sint64; + ret_addr = &pused[0]->u.l.l; + break; + case DILL_UL: + ret_type = &ffi_type_uint64; + ret_addr = &pused[0]->u.ul.ul; + break; + case DILL_P: + ret_type = &ffi_type_pointer; + ret_addr = &pused[0]->u.p.p; + break; + case DILL_F: + ret_type = &ffi_type_float; + ret_addr = &pused[0]->u.f.f; + break; + case DILL_D: + ret_type = &ffi_type_double; + ret_addr = &pused[0]->u.d.d; + break; + case DILL_V: + ret_type = &ffi_type_void; + ret_addr = NULL; + break; + } + for (i = 0; i < ec->out_param_count; i++) { + switch (ec->out_params[i].typ) { + case DILL_C: + args[i] = &ffi_type_sint8; + values[i] = &ec->out_params[i].val.u.c.c; + break; + case DILL_UC: + args[i] = &ffi_type_uint8; + values[i] = &ec->out_params[i].val.u.uc.uc; + break; + case DILL_S: + args[i] = &ffi_type_sint16; + values[i] = &ec->out_params[i].val.u.s.s; + break; + case DILL_US: + args[i] = &ffi_type_uint16; + values[i] = &ec->out_params[i].val.u.us.us; + break; + case DILL_I: + args[i] = &ffi_type_sint32; + values[i] = &ec->out_params[i].val.u.i.i; + break; + case DILL_U: + args[i] = &ffi_type_uint32; + values[i] = &ec->out_params[i].val.u.u.u; + break; + case DILL_L: + args[i] = &ffi_type_sint64; + values[i] = &ec->out_params[i].val.u.l.l; + break; + case DILL_UL: + args[i] = &ffi_type_uint64; + values[i] = &ec->out_params[i].val.u.ul.ul; + break; + case DILL_P: + args[i] = &ffi_type_pointer; + values[i] = &ec->out_params[i].val.u.p.p; + break; + case DILL_F: + args[i] = &ffi_type_float; + values[i] = &ec->out_params[i].val.u.f.f; + break; + case DILL_D: + args[i] = &ffi_type_double; + values[i] = &ec->out_params[i].val.u.d.d; + break; + case DILL_V: + break; + } + } + if (varidiac_call <= -2) { + ret = ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, + -(varidiac_call + 2), + ec->out_param_count, ret_type, args); + } else { + ret = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, ec->out_param_count, + ret_type, args); + } + if (ret == FFI_OK) { + ffi_call(&cif, func, ret_addr, values); + } + } break; - case iclass_push: - { - int typ = ip->insn_code & 0xf; - int r0 = ip->opnds.a1.src; - if ((short)ip->opnds.a1.src < 0) { - /* this is really push init, with varidiac status in src */ - ec->out_param_count = 0; - ec->out_params = malloc(sizeof(ec->out_params[0])); - varidiac_call = 0; - if (((short)ip->opnds.a1.src) <= -2) { - varidiac_call = (short)ip->opnds.a1.src; - } - } else { - ec->out_params = realloc(ec->out_params, sizeof(ec->out_params[0]) * (ec->out_param_count + 1)); - ec->out_params[ec->out_param_count].typ = typ; - ec->out_params[ec->out_param_count].val = *PREG(ec, r0); - ec->out_param_count++; - } - } - break; - case iclass_pushi: { - int typ = ip->insn_code & 0xf; - ec->out_params = realloc(ec->out_params, sizeof(ec->out_params[0]) * (ec->out_param_count + 1)); - ec->out_params[ec->out_param_count].typ = typ; - if (typ == DILL_P) { - ec->out_params[ec->out_param_count].val.u.p.p = ip->opnds.a3i.u.imm_a; - } else { - ec->out_params[ec->out_param_count].val.u.l.l = ip->opnds.a3i.u.imm; - } - ec->out_param_count++; - break; - } - case iclass_pushf: - ec->out_params = realloc(ec->out_params, sizeof(ec->out_params[0]) * (ec->out_param_count + 1)); - ec->out_params[ec->out_param_count].typ = DILL_D; - ec->out_params[ec->out_param_count].val.u.l.l = ip->opnds.a3i.u.imm; - ec->out_param_count++; - break; - case iclass_nop: - break; - case iclass_compare: - { - /* arith 3 operand integer insns */ - int r0 = ip->opnds.a3.src1; - int r1 = ip->opnds.a3.src2; - int d = ip->opnds.a3.dest; - pused[0] = PREG(ec, r0); - pused[1] = PREG(ec, r1); - pdest = PREG(ec, d); - pdest->u.i.i = emulate_compare(insn_code, pused[0], pused[1]); - break; - } - case iclass_mark_label: - break; - default: - printf("Unhandled insn in emulator, %p - %d\n", ip, ip->class_code); - break; - } - ip++; - if (ip >= (virtual_insn *)c->p->virtual.cur_ip) { - ip = &((virtual_insn *)insns)[0]; - } + case iclass_push: { + int typ = ip->insn_code & 0xf; + int r0 = ip->opnds.a1.src; + if ((short)ip->opnds.a1.src < 0) { + /* this is really push init, with varidiac status in src */ + ec->out_param_count = 0; + ec->out_params = malloc(sizeof(ec->out_params[0])); + varidiac_call = 0; + if (((short)ip->opnds.a1.src) <= -2) { + varidiac_call = (short)ip->opnds.a1.src; + } + } else { + ec->out_params = + realloc(ec->out_params, sizeof(ec->out_params[0]) * + (ec->out_param_count + 1)); + ec->out_params[ec->out_param_count].typ = typ; + ec->out_params[ec->out_param_count].val = *PREG(ec, r0); + ec->out_param_count++; + } + } break; + case iclass_pushi: { + int typ = ip->insn_code & 0xf; + ec->out_params = + realloc(ec->out_params, + sizeof(ec->out_params[0]) * (ec->out_param_count + 1)); + ec->out_params[ec->out_param_count].typ = typ; + if (typ == DILL_P) { + ec->out_params[ec->out_param_count].val.u.p.p = + ip->opnds.a3i.u.imm_a; + } else { + ec->out_params[ec->out_param_count].val.u.l.l = + ip->opnds.a3i.u.imm; + } + ec->out_param_count++; + break; + } + case iclass_pushf: + ec->out_params = + realloc(ec->out_params, + sizeof(ec->out_params[0]) * (ec->out_param_count + 1)); + ec->out_params[ec->out_param_count].typ = DILL_D; + ec->out_params[ec->out_param_count].val.u.l.l = ip->opnds.a3i.u.imm; + ec->out_param_count++; + break; + case iclass_nop: + break; + case iclass_compare: { + /* arith 3 operand integer insns */ + int r0 = ip->opnds.a3.src1; + int r1 = ip->opnds.a3.src2; + int d = ip->opnds.a3.dest; + pused[0] = PREG(ec, r0); + pused[1] = PREG(ec, r1); + pdest = PREG(ec, d); + pdest->u.i.i = emulate_compare(insn_code, pused[0], pused[1]); + break; + } + case iclass_mark_label: + break; + default: + printf("Unhandled insn in emulator, %p - %d\n", ip, ip->class_code); + break; + } + ip++; + if (ip >= (virtual_insn*)c->p->virtual.cur_ip) { + ip = &((virtual_insn*)insns)[0]; + } } } #endif diff --git a/vtests/basic_call.c b/vtests/basic_call.c index 124b8d2198..2dd1a3a98e 100644 --- a/vtests/basic_call.c +++ b/vtests/basic_call.c @@ -254,7 +254,7 @@ void e () { dill_addii(s, l,k,3); dill_reti(s, l); handle = dill_finalize(s); - ip = (int(*)())dill_get_fp(handle); + ip = (int(*)(int (*)(int, int), int, int, int, int, int, int, int, int, int))dill_get_fp(handle); if (verbose) dill_dump(s); diff --git a/vtests/general.ops b/vtests/general.ops index e7e6713762..c30094cd63 100644 --- a/vtests/general.ops +++ b/vtests/general.ops @@ -102,7 +102,7 @@ sub arith_insn { if (defined($c_src1_values{$full_op})) { $vals = $c_src1_values{$full_op}; print COUT " for (i=0 ; i < sizeof($vals)/sizeof($vals\[0\]) ; i++) {\n"; - print COUT " $c_type source1_$_ = $vals\[i\];\n"; + print COUT " $c_type source1_$_ = ($c_type) $vals\[i\];\n"; } else { print COUT " {\n"; print COUT " $c_type source1_$_ = rand1_$_;\n"; @@ -110,7 +110,7 @@ sub arith_insn { if (defined($c_src2_values{$full_op})) { $vals = $c_src2_values{$full_op}; print COUT " for (j=0 ; j < sizeof($vals)/sizeof($vals\[0\]) ; j++) {\n"; - print COUT " $c_type source2_$_ = $vals\[j\];\n"; + print COUT " $c_type source2_$_ = ($c_type) $vals\[j\];\n"; } else { print COUT " {\n"; print COUT " $c_type source2_$_ = rand2_$_;\n"; @@ -243,6 +243,13 @@ sub arith2_insn { $c_pformat = $c_print_formats{${_}}; $arg_str = "$drisc_arg_formats{${_}}"; $full_op = "${dill_op}${_}"; + if (($c_op eq '-') and ($_ eq "u")) { + $actual_op = '(unsigned) - (int)'; + } elsif (($c_op eq '-') and ($_ eq "ul")) { + $actual_op = '(uintptr_t) - (intptr_t)'; + } else { + $actual_op = $c_op; + } print COUT "\n /* test for dill_$dill_op${_} */\n"; print COUT " if (verbose) printf(\"test for dill_$dill_op${_}\");\n"; if (defined($c_src1_values{$full_op})) { @@ -273,7 +280,7 @@ print COUT< #endif +#include #ifdef _MSC_VER #include @@ -1079,14 +1087,14 @@ main(int argc, char **argv) { dill_stream c = dill_create_stream(); int failed = 0, verbose = 0; - int i, j; + size_t i, j; EOF # print COUT "# line ". (__LINE__ + 2) . " \"general.ops\"\n"; foreach $dill_type (keys %c_types) { $c_type = $c_types{$dill_type}; $rand_type = $rand_types{$dill_type}; - print COUT " $c_type rand1_$dill_type = ${rand_type}rand48();\n"; - print COUT " $c_type rand2_$dill_type = ${rand_type}rand48();\n"; + print COUT " $c_type rand1_$dill_type = ($c_type)${rand_type}rand48();\n"; + print COUT " $c_type rand2_$dill_type = ($c_type)${rand_type}rand48();\n"; print COUT " $c_type src1${dill_type}_vals[2];\n"; print COUT " $c_type src2${dill_type}_vals[2];\n"; print COUT " $c_type br_src${dill_type}_vals[6];\n"; @@ -1110,21 +1118,23 @@ EOF print COUT " src2${dill_type}_vals[0] = rand2_$dill_type;\n"; print COUT " src2${dill_type}_vals[1] = -rand2_$dill_type;\n"; } + %u_casts = ('uc', '(char)', 'us', '(short)', 'u', '(int)', 'ul', '(intptr_t)'); foreach $dill_type (split(' ', "uc us u ul")) { $c_type = $c_types{$dill_type}; + print COUT " src1${dill_type}_vals[0] = ($c_type) rand1_$dill_type;\n"; - print COUT " src1${dill_type}_vals[1] = ($c_type) -rand1_$dill_type;\n"; + print COUT " src1${dill_type}_vals[1] = ($c_type) - $u_casts{$dill_type} rand1_$dill_type;\n"; print COUT " src2${dill_type}_vals[0] = ($c_type) rand2_$dill_type;\n"; - print COUT " src2${dill_type}_vals[1] = ($c_type) -rand2_$dill_type;\n"; + print COUT " src2${dill_type}_vals[1] = ($c_type) - $u_casts{$dill_type} rand2_$dill_type;\n"; } foreach $dill_type (split(' ', "uc c us s i u l ul d f")) { $c_type = $c_types{$dill_type}; print COUT " br_src${dill_type}_vals[0] = ($c_type) rand1_$dill_type;\n"; - print COUT " br_src${dill_type}_vals[1] = ($c_type) -rand1_$dill_type;\n"; + print COUT " br_src${dill_type}_vals[1] = ($c_type) - $u_casts{$dill_type} rand1_$dill_type;\n"; print COUT " br_src${dill_type}_vals[2] = ($c_type) rand1_$dill_type + 1;\n"; - print COUT " br_src${dill_type}_vals[3] = ($c_type) -rand1_$dill_type + 1;\n"; + print COUT " br_src${dill_type}_vals[3] = ($c_type) -($u_casts{$dill_type} rand1_$dill_type) + 1;\n"; print COUT " br_src${dill_type}_vals[4] = ($c_type) rand1_$dill_type - 1;\n"; - print COUT " br_src${dill_type}_vals[5] = ($c_type) -rand1_$dill_type - 1;\n"; + print COUT " br_src${dill_type}_vals[5] = ($c_type) -($u_casts{$dill_type} rand1_$dill_type) - 1;\n"; } $dill_type = 'p'; $c_type = $c_types{'p'}; diff --git a/vtests/opt.c b/vtests/opt.c index ea781dabba..984c378980 100644 --- a/vtests/opt.c +++ b/vtests/opt.c @@ -20,7 +20,7 @@ void a () { dill_reg a; dill_exec_ctx ec; dill_exec_handle handle; - int (*ip)(); + int (*ip)(dill_exec_ctx, int); int result; dill_start_proc(s, "a_gen", DILL_I, "%EC%i"); @@ -32,7 +32,7 @@ void a () { dill_addii(s, a, a, 20); dill_reti(s, a); handle = dill_finalize(s); - ip = (int(*)())dill_get_fp(handle); + ip = (int(*)(dill_exec_ctx, int))dill_get_fp(handle); if (verbose) dill_dump(s); @@ -51,7 +51,7 @@ void b () { dill_reg a; dill_exec_ctx ec; dill_exec_handle handle; - int (*ip)(); + int (*ip)(dill_exec_ctx, int); int result; dill_start_proc(s, "a_gen", DILL_I, "%EC%i"); @@ -63,7 +63,7 @@ void b () { dill_addii(s, a, a, 1); dill_reti(s, a); handle = dill_finalize(s); - ip = (int(*)())dill_get_fp(handle); + ip = (int(*)(dill_exec_ctx, int))dill_get_fp(handle); if (verbose) dill_dump(s); diff --git a/vtests/t1.c b/vtests/t1.c index fb329d0b3f..cb820a31e4 100644 --- a/vtests/t1.c +++ b/vtests/t1.c @@ -21,7 +21,7 @@ void a () { dill_reg a,b,p3,d,e,f; dill_exec_ctx ec; dill_exec_handle handle; - int (*ip)(); + int (*ip)(dill_exec_ctx, int , int ); dill_start_proc(s, "a_gen", DILL_I, "%EC%i%i"); @@ -47,7 +47,7 @@ void a () { dill_addi(s, f, f, e); dill_reti(s, f); handle = dill_finalize(s); - ip = (int(*)())dill_get_fp(handle); + ip = (int(*)(dill_exec_ctx, int, int))dill_get_fp(handle); #ifdef USE_MMAP_CODE_SEG #ifndef MAP_ANONYMOUS diff --git a/x86_64.c b/x86_64.c index 8b2959a1cc..068d403c14 100644 --- a/x86_64.c +++ b/x86_64.c @@ -1,502 +1,538 @@ #include "config.h" -#ifdef LINUX_KERNEL_MODULE -#ifndef MODULE -#define MODULE -#endif -#ifndef __KERNEL__ -#define __KERNEL__ -#endif -#include -#include -#endif - #undef NDEBUG #include "assert.h" -#ifndef LINUX_KERNEL_MODULE +#include #include #include -#include -#ifdef HAVE_MALLOC_H -#include -#endif #include -#else -#include "kdill.h" -#define fprintf(fmt, args...) printk(args) -#define printf printk -#define malloc (void *)DAllocMM -#define free(a) DFreeMM((addrs_t) a) -#endif -/* - * GANEV: note that we have to include "x86_64.h" _after_ including - * "kdill.h" because it needs to #undef and then re-#define a few - * symbols (namely, EAX, EBX, etc. defined in - */ #include "dill.h" #include "dill_internal.h" #include "x86_64.h" #define MOV32 0x89 -#define Mod(x) ((x)<<6) -#define RegOp(x) ((7&(x))<<3) -#define RM(x) (7&(x)) -#define ModRM(mod,reg,rm) (Mod(mod)|RegOp(reg)|RM(rm)) -#define SIB(scale, index, base) (((scale)<<6) | ((0x7 & (index))<<3) | (0x7 & (base))) +#define Mod(x) ((x) << 6) +#define RegOp(x) ((7 & (x)) << 3) +#define RM(x) (7 & (x)) +#define ModRM(mod, reg, rm) (Mod(mod) | RegOp(reg) | RM(rm)) +#define SIB(scale, index, base) \ + (((scale) << 6) | ((0x7 & (index)) << 3) | (0x7 & (base))) #define INSN_OUT(s, i) printf("Bad opout, line %d\n", __LINE__) -#define x86_64_savei(s, imm) -#define x86_64_andi(s, dest, src, imm) x86_64_arith3i(s, 0x4, 0x2, dest, src, imm) +#define x86_64_savei(s, imm) +#define x86_64_andi(s, dest, src, imm) \ + x86_64_arith3i(s, 0x4, 0x2, dest, src, imm) -static void x86_64_push_reg(dill_stream s, int src); -static void x86_64_pop_reg(dill_stream s, int src); +static void +x86_64_push_reg(dill_stream s, int src); +static void +x86_64_pop_reg(dill_stream s, int src); #define x86_64_nop(s) BYTE_OUT1(s, 0x90) -static char *char_regs[] = {"AL", "CL", "DL", "BL", "AH", "CH", "DH", "BH"}; -static char *short_regs[] = {"AX", "CX", "DX", "BX", "SP", "BP", "SI", "DI"}; -static char *int_regs[] = {"EAX", "ECX", "EDX", "EBX", "ESP", "EBP", "ESI", "EDI"}; -char *long_regs[] = {"RAX", "RCX", "RDX", "RBX", "RSP", "RBP", "RSI", "RDI"}; -char *float_regs[] = {"RAX", "RCX", "RDX", "RBX", "RSP", "RBP", "RSI", "RDI"}; +static char* char_regs[] = {"AL", "CL", "DL", "BL", "AH", "CH", "DH", "BH"}; +static char* short_regs[] = {"AX", "CX", "DX", "BX", "SP", "BP", "SI", "DI"}; +static char* int_regs[] = {"EAX", "ECX", "EDX", "EBX", + "ESP", "EBP", "ESI", "EDI"}; +char* long_regs[] = {"RAX", "RCX", "RDX", "RBX", "RSP", "RBP", "RSI", "RDI"}; +char* float_regs[] = {"RAX", "RCX", "RDX", "RBX", "RSP", "RBP", "RSI", "RDI"}; #define IREG 0 #define FREG 1 #define _temp_reg EAX #define _frame_reg EBP -#define roundup(a,b) ((a + (b-1)) & (-b)) -static void x86_64_pmov(dill_stream s, int typ, int dest, int src); +#define roundup(a, b) ((a + (b - 1)) & (-b)) +static void +x86_64_pmov(dill_stream s, int typ, int dest, int src); -static -struct basic_type_info -{ char size; +static struct basic_type_info { + char size; char align; char reg_type; } type_info[] = { - { 1, 1, IREG}, /* C */ - { 1, 1, IREG}, /* UC */ - { 2, 2, IREG}, /* S */ - { 2, 2, IREG}, /* US */ - { 4, 4, IREG}, /* I */ - { 4, 4, IREG}, /* U */ - { sizeof(uintptr_t), sizeof(uintptr_t), IREG}, /* UL */ - { sizeof(intptr_t), sizeof(intptr_t), IREG}, /* L */ - { sizeof(char*), sizeof(char*), IREG}, /* P */ - { sizeof(float), sizeof(float), FREG}, /* F */ - { sizeof(double), sizeof(double), FREG}, /* D */ - { 0, 8, IREG}, /* V */ - { -1, 8, IREG}, /* B */ - { sizeof(void*), sizeof(void*), IREG}, /* EC */ + {1, 1, IREG}, /* C */ + {1, 1, IREG}, /* UC */ + {2, 2, IREG}, /* S */ + {2, 2, IREG}, /* US */ + {4, 4, IREG}, /* I */ + {4, 4, IREG}, /* U */ + {sizeof(uintptr_t), sizeof(uintptr_t), IREG}, /* UL */ + {sizeof(intptr_t), sizeof(intptr_t), IREG}, /* L */ + {sizeof(char*), sizeof(char*), IREG}, /* P */ + {sizeof(float), sizeof(float), FREG}, /* F */ + {sizeof(double), sizeof(double), FREG}, /* D */ + {0, 8, IREG}, /* V */ + {-1, 8, IREG}, /* B */ + {sizeof(void*), sizeof(void*), IREG}, /* EC */ }; int x86_64_type_align[] = { - 1, /* C */ - 1, /* UC */ - 2, /* S */ - 2, /* US */ - 4, /* I */ - 4, /* U */ - sizeof(uintptr_t), /* UL */ - sizeof(intptr_t), /* L */ - sizeof(char*), /* P */ - 4, /* F */ - 4, /* D */ - 4, /* V */ - 4, /* B */ - sizeof(char*), /* EC */ + 1, /* C */ + 1, /* UC */ + 2, /* S */ + 2, /* US */ + 4, /* I */ + 4, /* U */ + sizeof(uintptr_t), /* UL */ + sizeof(intptr_t), /* L */ + sizeof(char*), /* P */ + 4, /* F */ + 4, /* D */ + 4, /* V */ + 4, /* B */ + sizeof(char*), /* EC */ }; int x86_64_type_size[] = { - 1, /* C */ - 1, /* UC */ - 2, /* S */ - 2, /* US */ - 4, /* I */ - 4, /* U */ - sizeof(uintptr_t), /* UL */ - sizeof(intptr_t), /* L */ - sizeof(char*), /* P */ - 4, /* F */ - 8, /* D */ - 4, /* V */ - 0, /* B */ - sizeof(char*), /* EC */ + 1, /* C */ + 1, /* UC */ + 2, /* S */ + 2, /* US */ + 4, /* I */ + 4, /* U */ + sizeof(uintptr_t), /* UL */ + sizeof(intptr_t), /* L */ + sizeof(char*), /* P */ + 4, /* F */ + 8, /* D */ + 4, /* V */ + 0, /* B */ + sizeof(char*), /* EC */ }; static void BYTE_OUT2R(dill_stream s, int rex, int insn1, int insn2) { - unsigned char *tmp_ip; + unsigned char* tmp_ip; if (s->p->cur_ip >= s->p->code_limit) { - extend_dill_stream(s); + extend_dill_stream(s); } - tmp_ip = (unsigned char *) s->p->cur_ip; + tmp_ip = (unsigned char*)s->p->cur_ip; if (rex != 0) { - *tmp_ip = (unsigned char)rex|0x40; - *(tmp_ip + 1) = (unsigned char)insn1; - *(tmp_ip + 2) = (unsigned char)insn2; + *tmp_ip = (unsigned char)rex | 0x40; + *(tmp_ip + 1) = (unsigned char)insn1; + *(tmp_ip + 2) = (unsigned char)insn2; } else { - *(tmp_ip) = (unsigned char)insn1; - *(tmp_ip + 1) = (unsigned char)insn2; + *(tmp_ip) = (unsigned char)insn1; + *(tmp_ip + 1) = (unsigned char)insn2; } - if (s->dill_debug) dump_cur_dill_insn(s); - s->p->cur_ip = ((char*)s->p->cur_ip)+2; - if (rex !=0) s->p->cur_ip++; + if (s->dill_debug) + dump_cur_dill_insn(s); + s->p->cur_ip = ((char*)s->p->cur_ip) + 2; + if (rex != 0) + s->p->cur_ip++; } static void BYTE_OUT1R(dill_stream s, int rex, int insn1) { - unsigned char *tmp_ip; + unsigned char* tmp_ip; if (s->p->cur_ip >= s->p->code_limit) { - extend_dill_stream(s); + extend_dill_stream(s); } - tmp_ip = (unsigned char *) s->p->cur_ip; + tmp_ip = (unsigned char*)s->p->cur_ip; if (rex != 0) { - *tmp_ip = (unsigned char)rex|0x40; - *(tmp_ip + 1) = (unsigned char)insn1; + *tmp_ip = (unsigned char)rex | 0x40; + *(tmp_ip + 1) = (unsigned char)insn1; } else { - *(tmp_ip) = (unsigned char)insn1; + *(tmp_ip) = (unsigned char)insn1; } - if (s->dill_debug) dump_cur_dill_insn(s); - s->p->cur_ip = ((char*)s->p->cur_ip)+1; - if (rex !=0) s->p->cur_ip++; + if (s->dill_debug) + dump_cur_dill_insn(s); + s->p->cur_ip = ((char*)s->p->cur_ip) + 1; + if (rex != 0) + s->p->cur_ip++; } static void BYTE_OUT2IR(dill_stream s, int rex, int insn1, int insn2, int imm32) { - unsigned char *tmp_ip; + unsigned char* tmp_ip; if (s->p->cur_ip >= s->p->code_limit) { - extend_dill_stream(s); + extend_dill_stream(s); } - tmp_ip = (unsigned char *) s->p->cur_ip; + tmp_ip = (unsigned char*)s->p->cur_ip; if (rex != 0) { - int tmp = imm32; - *tmp_ip = (unsigned char)rex|0x40; - *(tmp_ip + 1) = (unsigned char)insn1; - *(tmp_ip + 2) = (unsigned char)insn2; - memcpy(tmp_ip + 3, &tmp, 4); + int tmp = imm32; + *tmp_ip = (unsigned char)rex | 0x40; + *(tmp_ip + 1) = (unsigned char)insn1; + *(tmp_ip + 2) = (unsigned char)insn2; + memcpy(tmp_ip + 3, &tmp, 4); } else { - int tmp = imm32; - *(tmp_ip) = (unsigned char)insn1; - *(tmp_ip + 1) = (unsigned char)insn2; - memcpy(tmp_ip + 2, &tmp, 4); + int tmp = imm32; + *(tmp_ip) = (unsigned char)insn1; + *(tmp_ip + 1) = (unsigned char)insn2; + memcpy(tmp_ip + 2, &tmp, 4); } - if (s->dill_debug) dump_cur_dill_insn(s); - s->p->cur_ip = ((char*)s->p->cur_ip)+6; - if (rex !=0) s->p->cur_ip++; + if (s->dill_debug) + dump_cur_dill_insn(s); + s->p->cur_ip = ((char*)s->p->cur_ip) + 6; + if (rex != 0) + s->p->cur_ip++; } static void BYTE_OUT3IR(dill_stream s, int rex, int insn1, int insn2, int insn3, int imm32) { - unsigned char *tmp_ip; + unsigned char* tmp_ip; if (s->p->cur_ip >= s->p->code_limit) { - extend_dill_stream(s); + extend_dill_stream(s); } - tmp_ip = (unsigned char *) s->p->cur_ip; + tmp_ip = (unsigned char*)s->p->cur_ip; if (rex != 0) { - int tmp = imm32; - *tmp_ip = (unsigned char)rex|0x40; - *(tmp_ip + 1) = (unsigned char)insn1; - *(tmp_ip + 2) = (unsigned char)insn2; - *(tmp_ip + 3) = (unsigned char)insn3; - memcpy(tmp_ip + 4, &tmp, 4); + int tmp = imm32; + *tmp_ip = (unsigned char)rex | 0x40; + *(tmp_ip + 1) = (unsigned char)insn1; + *(tmp_ip + 2) = (unsigned char)insn2; + *(tmp_ip + 3) = (unsigned char)insn3; + memcpy(tmp_ip + 4, &tmp, 4); } else { - int tmp = imm32; - *(tmp_ip) = (unsigned char)insn1; - *(tmp_ip + 1) = (unsigned char)insn2; - *(tmp_ip + 2) = (unsigned char)insn3; - memcpy(tmp_ip + 3, &tmp, 4); + int tmp = imm32; + *(tmp_ip) = (unsigned char)insn1; + *(tmp_ip + 1) = (unsigned char)insn2; + *(tmp_ip + 2) = (unsigned char)insn3; + memcpy(tmp_ip + 3, &tmp, 4); } - if (s->dill_debug) dump_cur_dill_insn(s); - s->p->cur_ip = ((char*)s->p->cur_ip)+7; - if (rex !=0) s->p->cur_ip++; + if (s->dill_debug) + dump_cur_dill_insn(s); + s->p->cur_ip = ((char*)s->p->cur_ip) + 7; + if (rex != 0) + s->p->cur_ip++; } static void BYTE_OUT1IR(dill_stream s, int rex, int insn1, int imm32) { - unsigned char *tmp_ip; + unsigned char* tmp_ip; if (s->p->cur_ip >= s->p->code_limit) { - extend_dill_stream(s); + extend_dill_stream(s); } - tmp_ip = (unsigned char *) s->p->cur_ip; + tmp_ip = (unsigned char*)s->p->cur_ip; if (rex != 0) { - int tmp = imm32; - *tmp_ip = (unsigned char)rex|0x40; - *(tmp_ip + 1) = (unsigned char)insn1; - memcpy(tmp_ip + 2, &tmp, 4); + int tmp = imm32; + *tmp_ip = (unsigned char)rex | 0x40; + *(tmp_ip + 1) = (unsigned char)insn1; + memcpy(tmp_ip + 2, &tmp, 4); } else { - int tmp = imm32; - *(tmp_ip) = (unsigned char)insn1; - memcpy(tmp_ip + 1, &tmp, 4); + int tmp = imm32; + *(tmp_ip) = (unsigned char)insn1; + memcpy(tmp_ip + 1, &tmp, 4); } - if (s->dill_debug) dump_cur_dill_insn(s); - s->p->cur_ip = ((char*)s->p->cur_ip)+5; - if (rex !=0) s->p->cur_ip++; + if (s->dill_debug) + dump_cur_dill_insn(s); + s->p->cur_ip = ((char*)s->p->cur_ip) + 5; + if (rex != 0) + s->p->cur_ip++; } static void BYTE_OUT1LR(dill_stream s, int rex, int insn1, intptr_t imm64) { - unsigned char *tmp_ip; + unsigned char* tmp_ip; if (s->p->cur_ip >= s->p->code_limit) { - extend_dill_stream(s); + extend_dill_stream(s); } - tmp_ip = (unsigned char *) s->p->cur_ip; + tmp_ip = (unsigned char*)s->p->cur_ip; if (rex != 0) { - intptr_t tmp = imm64; - *tmp_ip = (unsigned char)rex|0x40; - *(tmp_ip + 1) = (unsigned char)insn1; - memcpy(tmp_ip + 2, &tmp, 8); + intptr_t tmp = imm64; + *tmp_ip = (unsigned char)rex | 0x40; + *(tmp_ip + 1) = (unsigned char)insn1; + memcpy(tmp_ip + 2, &tmp, 8); } else { - intptr_t tmp = imm64; - *(tmp_ip) = (unsigned char)insn1; - memcpy(tmp_ip + 1, &tmp, 8); + intptr_t tmp = imm64; + *(tmp_ip) = (unsigned char)insn1; + memcpy(tmp_ip + 1, &tmp, 8); } - if (s->dill_debug) dump_cur_dill_insn(s); - s->p->cur_ip = ((char*)s->p->cur_ip)+9; - if (rex !=0) s->p->cur_ip++; + if (s->dill_debug) + dump_cur_dill_insn(s); + s->p->cur_ip = ((char*)s->p->cur_ip) + 9; + if (rex != 0) + s->p->cur_ip++; } static void BYTE_OUT3R(dill_stream s, int rex, int insn1, int insn2, int insn3) { - unsigned char *tmp_ip; + unsigned char* tmp_ip; if (s->p->cur_ip >= s->p->code_limit) { - extend_dill_stream(s); + extend_dill_stream(s); } - tmp_ip = (unsigned char *) s->p->cur_ip; + tmp_ip = (unsigned char*)s->p->cur_ip; if (rex != 0) { - *tmp_ip = (unsigned char)rex|0x40; - *(tmp_ip + 1) = (unsigned char)insn1; - *(tmp_ip + 2) = (unsigned char)insn2; - *(tmp_ip + 3) = (unsigned char)insn3; + *tmp_ip = (unsigned char)rex | 0x40; + *(tmp_ip + 1) = (unsigned char)insn1; + *(tmp_ip + 2) = (unsigned char)insn2; + *(tmp_ip + 3) = (unsigned char)insn3; } else { - *(tmp_ip) = (unsigned char)insn1; - *(tmp_ip + 1) = (unsigned char)insn2; - *(tmp_ip + 2) = (unsigned char)insn3; + *(tmp_ip) = (unsigned char)insn1; + *(tmp_ip + 1) = (unsigned char)insn2; + *(tmp_ip + 2) = (unsigned char)insn3; } - if (s->dill_debug) dump_cur_dill_insn(s); - s->p->cur_ip = ((char*)s->p->cur_ip)+3; - if (rex !=0) s->p->cur_ip++; + if (s->dill_debug) + dump_cur_dill_insn(s); + s->p->cur_ip = ((char*)s->p->cur_ip) + 3; + if (rex != 0) + s->p->cur_ip++; } static void BYTE_OUT4R(dill_stream s, int rex, int insn1, int insn2, int insn3, int insn4) { - unsigned char *tmp_ip; + unsigned char* tmp_ip; if (s->p->cur_ip >= s->p->code_limit) { - extend_dill_stream(s); + extend_dill_stream(s); } - tmp_ip = (unsigned char *) s->p->cur_ip; + tmp_ip = (unsigned char*)s->p->cur_ip; if (rex != 0) { - *tmp_ip = (unsigned char)rex|0x40; - *(tmp_ip + 1) = (unsigned char)insn1; - *(tmp_ip + 2) = (unsigned char)insn2; - *(tmp_ip + 3) = (unsigned char)insn3; - *(tmp_ip + 4) = (unsigned char)insn4; + *tmp_ip = (unsigned char)rex | 0x40; + *(tmp_ip + 1) = (unsigned char)insn1; + *(tmp_ip + 2) = (unsigned char)insn2; + *(tmp_ip + 3) = (unsigned char)insn3; + *(tmp_ip + 4) = (unsigned char)insn4; } else { - *(tmp_ip) = (unsigned char)insn1; - *(tmp_ip + 1) = (unsigned char)insn2; - *(tmp_ip + 2) = (unsigned char)insn3; - *(tmp_ip + 3) = (unsigned char)insn4; + *(tmp_ip) = (unsigned char)insn1; + *(tmp_ip + 1) = (unsigned char)insn2; + *(tmp_ip + 2) = (unsigned char)insn3; + *(tmp_ip + 3) = (unsigned char)insn4; } - if (s->dill_debug) dump_cur_dill_insn(s); - s->p->cur_ip = ((char*)s->p->cur_ip)+4; - if (rex !=0) s->p->cur_ip++; + if (s->dill_debug) + dump_cur_dill_insn(s); + s->p->cur_ip = ((char*)s->p->cur_ip) + 4; + if (rex != 0) + s->p->cur_ip++; } static void -BYTE_OUT1R3I(dill_stream s, int insn1, int rex, int insn2, int insn3, int insn4, int imm) -{ - unsigned char *tmp_ip; +BYTE_OUT1R3I(dill_stream s, + int insn1, + int rex, + int insn2, + int insn3, + int insn4, + int imm) +{ + unsigned char* tmp_ip; if (s->p->cur_ip >= s->p->code_limit) { - extend_dill_stream(s); + extend_dill_stream(s); } - tmp_ip = (unsigned char *) s->p->cur_ip; + tmp_ip = (unsigned char*)s->p->cur_ip; if (rex != 0) { - *(tmp_ip + 0) = (unsigned char)insn1; - *(tmp_ip + 1) = (unsigned char)rex|0x40; - *(tmp_ip + 2) = (unsigned char)insn2; - *(tmp_ip + 3) = (unsigned char)insn3; - *(tmp_ip + 4) = (unsigned char)insn4; - *((int*)(tmp_ip + 5)) = imm; + *(tmp_ip + 0) = (unsigned char)insn1; + *(tmp_ip + 1) = (unsigned char)rex | 0x40; + *(tmp_ip + 2) = (unsigned char)insn2; + *(tmp_ip + 3) = (unsigned char)insn3; + *(tmp_ip + 4) = (unsigned char)insn4; + *((int*)(tmp_ip + 5)) = imm; } else { - *(tmp_ip) = (unsigned char)insn1; - *(tmp_ip + 1) = (unsigned char)insn2; - *(tmp_ip + 2) = (unsigned char)insn3; - *(tmp_ip + 3) = (unsigned char)insn4; - *((int*)(tmp_ip + 4)) = imm; + *(tmp_ip) = (unsigned char)insn1; + *(tmp_ip + 1) = (unsigned char)insn2; + *(tmp_ip + 2) = (unsigned char)insn3; + *(tmp_ip + 3) = (unsigned char)insn4; + *((int*)(tmp_ip + 4)) = imm; } - if (s->dill_debug) dump_cur_dill_insn(s); - s->p->cur_ip = ((char*)s->p->cur_ip)+8; - if (rex !=0) s->p->cur_ip++; + if (s->dill_debug) + dump_cur_dill_insn(s); + s->p->cur_ip = ((char*)s->p->cur_ip) + 8; + if (rex != 0) + s->p->cur_ip++; } static void -BYTE_OUT1R4I(dill_stream s, int insn1, int rex, int insn2, int insn3, int insn4, int insn5, int imm) -{ - unsigned char *tmp_ip; +BYTE_OUT1R4I(dill_stream s, + int insn1, + int rex, + int insn2, + int insn3, + int insn4, + int insn5, + int imm) +{ + unsigned char* tmp_ip; if (s->p->cur_ip >= s->p->code_limit) { - extend_dill_stream(s); + extend_dill_stream(s); } - tmp_ip = (unsigned char *) s->p->cur_ip; + tmp_ip = (unsigned char*)s->p->cur_ip; if (rex != 0) { - *(tmp_ip + 0) = (unsigned char)insn1; - *(tmp_ip + 1) = (unsigned char)rex|0x40; - *(tmp_ip + 2) = (unsigned char)insn2; - *(tmp_ip + 3) = (unsigned char)insn3; - *(tmp_ip + 4) = (unsigned char)insn4; - *(tmp_ip + 5) = (unsigned char)insn5; - *((int*)(tmp_ip + 6)) = imm; + *(tmp_ip + 0) = (unsigned char)insn1; + *(tmp_ip + 1) = (unsigned char)rex | 0x40; + *(tmp_ip + 2) = (unsigned char)insn2; + *(tmp_ip + 3) = (unsigned char)insn3; + *(tmp_ip + 4) = (unsigned char)insn4; + *(tmp_ip + 5) = (unsigned char)insn5; + *((int*)(tmp_ip + 6)) = imm; } else { - *(tmp_ip) = (unsigned char)insn1; - *(tmp_ip + 1) = (unsigned char)insn2; - *(tmp_ip + 2) = (unsigned char)insn3; - *(tmp_ip + 3) = (unsigned char)insn4; - *(tmp_ip + 4) = (unsigned char)insn5; - *((int*)(tmp_ip + 5)) = imm; + *(tmp_ip) = (unsigned char)insn1; + *(tmp_ip + 1) = (unsigned char)insn2; + *(tmp_ip + 2) = (unsigned char)insn3; + *(tmp_ip + 3) = (unsigned char)insn4; + *(tmp_ip + 4) = (unsigned char)insn5; + *((int*)(tmp_ip + 5)) = imm; } - if (s->dill_debug) dump_cur_dill_insn(s); - s->p->cur_ip = ((char*)s->p->cur_ip)+9; - if (rex !=0) s->p->cur_ip++; + if (s->dill_debug) + dump_cur_dill_insn(s); + s->p->cur_ip = ((char*)s->p->cur_ip) + 9; + if (rex != 0) + s->p->cur_ip++; } static void BYTE_OUT1R3(dill_stream s, int insn1, int rex, int insn2, int insn3, int insn4) { - unsigned char *tmp_ip; + unsigned char* tmp_ip; if (s->p->cur_ip >= s->p->code_limit) { - extend_dill_stream(s); + extend_dill_stream(s); } - tmp_ip = (unsigned char *) s->p->cur_ip; + tmp_ip = (unsigned char*)s->p->cur_ip; if (rex != 0) { - *(tmp_ip + 0) = (unsigned char)insn1; - *(tmp_ip + 1)= (unsigned char)rex|0x40; - *(tmp_ip + 2) = (unsigned char)insn2; - *(tmp_ip + 3) = (unsigned char)insn3; - *(tmp_ip + 4) = (unsigned char)insn4; + *(tmp_ip + 0) = (unsigned char)insn1; + *(tmp_ip + 1) = (unsigned char)rex | 0x40; + *(tmp_ip + 2) = (unsigned char)insn2; + *(tmp_ip + 3) = (unsigned char)insn3; + *(tmp_ip + 4) = (unsigned char)insn4; } else { - *(tmp_ip) = (unsigned char)insn1; - *(tmp_ip + 1) = (unsigned char)insn2; - *(tmp_ip + 2) = (unsigned char)insn3; - *(tmp_ip + 3) = (unsigned char)insn4; + *(tmp_ip) = (unsigned char)insn1; + *(tmp_ip + 1) = (unsigned char)insn2; + *(tmp_ip + 2) = (unsigned char)insn3; + *(tmp_ip + 3) = (unsigned char)insn4; } - if (s->dill_debug) dump_cur_dill_insn(s); - s->p->cur_ip = ((char*)s->p->cur_ip)+4; - if (rex !=0) s->p->cur_ip++; + if (s->dill_debug) + dump_cur_dill_insn(s); + s->p->cur_ip = ((char*)s->p->cur_ip) + 4; + if (rex != 0) + s->p->cur_ip++; } static void -BYTE_OUT1R4(dill_stream s, int insn1, int rex, int insn2, int insn3, int insn4, int insn5) -{ - unsigned char *tmp_ip; +BYTE_OUT1R4(dill_stream s, + int insn1, + int rex, + int insn2, + int insn3, + int insn4, + int insn5) +{ + unsigned char* tmp_ip; if (s->p->cur_ip >= s->p->code_limit) { - extend_dill_stream(s); + extend_dill_stream(s); } - tmp_ip = (unsigned char *) s->p->cur_ip; + tmp_ip = (unsigned char*)s->p->cur_ip; if (rex != 0) { - *(tmp_ip + 0) = (unsigned char)insn1; - *(tmp_ip + 1)= (unsigned char)rex|0x40; - *(tmp_ip + 2) = (unsigned char)insn2; - *(tmp_ip + 3) = (unsigned char)insn3; - *(tmp_ip + 4) = (unsigned char)insn4; - *(tmp_ip + 5) = (unsigned char)insn5; + *(tmp_ip + 0) = (unsigned char)insn1; + *(tmp_ip + 1) = (unsigned char)rex | 0x40; + *(tmp_ip + 2) = (unsigned char)insn2; + *(tmp_ip + 3) = (unsigned char)insn3; + *(tmp_ip + 4) = (unsigned char)insn4; + *(tmp_ip + 5) = (unsigned char)insn5; } else { - *(tmp_ip) = (unsigned char)insn1; - *(tmp_ip + 1) = (unsigned char)insn2; - *(tmp_ip + 2) = (unsigned char)insn3; - *(tmp_ip + 3) = (unsigned char)insn4; - *(tmp_ip + 4) = (unsigned char)insn5; + *(tmp_ip) = (unsigned char)insn1; + *(tmp_ip + 1) = (unsigned char)insn2; + *(tmp_ip + 2) = (unsigned char)insn3; + *(tmp_ip + 3) = (unsigned char)insn4; + *(tmp_ip + 4) = (unsigned char)insn5; } - if (s->dill_debug) dump_cur_dill_insn(s); - s->p->cur_ip = ((char*)s->p->cur_ip)+5; - if (rex !=0) s->p->cur_ip++; + if (s->dill_debug) + dump_cur_dill_insn(s); + s->p->cur_ip = ((char*)s->p->cur_ip) + 5; + if (rex != 0) + s->p->cur_ip++; } static void -BYTE_OUT1R5(dill_stream s, int insn1, int rex, int insn2, int insn3, int insn4, int insn5, int insn6) -{ - unsigned char *tmp_ip; +BYTE_OUT1R5(dill_stream s, + int insn1, + int rex, + int insn2, + int insn3, + int insn4, + int insn5, + int insn6) +{ + unsigned char* tmp_ip; if (s->p->cur_ip >= s->p->code_limit) { - extend_dill_stream(s); + extend_dill_stream(s); } - tmp_ip = (unsigned char *) s->p->cur_ip; + tmp_ip = (unsigned char*)s->p->cur_ip; if (rex != 0) { - *(tmp_ip + 0) = (unsigned char)insn1; - *(tmp_ip + 1)= (unsigned char)rex|0x40; - *(tmp_ip + 2) = (unsigned char)insn2; - *(tmp_ip + 3) = (unsigned char)insn3; - *(tmp_ip + 4) = (unsigned char)insn4; - *(tmp_ip + 5) = (unsigned char)insn5; - *(tmp_ip + 6) = (unsigned char)insn6; + *(tmp_ip + 0) = (unsigned char)insn1; + *(tmp_ip + 1) = (unsigned char)rex | 0x40; + *(tmp_ip + 2) = (unsigned char)insn2; + *(tmp_ip + 3) = (unsigned char)insn3; + *(tmp_ip + 4) = (unsigned char)insn4; + *(tmp_ip + 5) = (unsigned char)insn5; + *(tmp_ip + 6) = (unsigned char)insn6; } else { - *(tmp_ip) = (unsigned char)insn1; - *(tmp_ip + 1) = (unsigned char)insn2; - *(tmp_ip + 2) = (unsigned char)insn3; - *(tmp_ip + 3) = (unsigned char)insn4; - *(tmp_ip + 4) = (unsigned char)insn5; - *(tmp_ip + 5) = (unsigned char)insn6; + *(tmp_ip) = (unsigned char)insn1; + *(tmp_ip + 1) = (unsigned char)insn2; + *(tmp_ip + 2) = (unsigned char)insn3; + *(tmp_ip + 3) = (unsigned char)insn4; + *(tmp_ip + 4) = (unsigned char)insn5; + *(tmp_ip + 5) = (unsigned char)insn6; } - if (s->dill_debug) dump_cur_dill_insn(s); - s->p->cur_ip = ((char*)s->p->cur_ip)+6; - if (rex !=0) s->p->cur_ip++; + if (s->dill_debug) + dump_cur_dill_insn(s); + s->p->cur_ip = ((char*)s->p->cur_ip) + 6; + if (rex != 0) + s->p->cur_ip++; } -#define x86_64_movi(s, dest, src) x86_64_pmov(s, DILL_I, dest, src) -#define x86_64_movl(s, dest, src) x86_64_pmov(s, DILL_L, dest, src) -#define x86_64_movd(s, dest, src) x86_64_pmov(s, DILL_D, dest, src) -#define x86_64_movf(s, dest, src) x86_64_pmov(s, DILL_F, dest, src) +#define x86_64_movi(s, dest, src) x86_64_pmov(s, DILL_I, dest, src) +#define x86_64_movl(s, dest, src) x86_64_pmov(s, DILL_L, dest, src) +#define x86_64_movd(s, dest, src) x86_64_pmov(s, DILL_D, dest, src) +#define x86_64_movf(s, dest, src) x86_64_pmov(s, DILL_F, dest, src) -static void x86_64_push_reg(dill_stream s, int src) +static void +x86_64_push_reg(dill_stream s, int src) { int rex = 0; - if (src > RDI) rex|= REX_B; - BYTE_OUT1R(s, rex, 0x50+(src&0x7)); + if (src > RDI) + rex |= REX_B; + BYTE_OUT1R(s, rex, 0x50 + (src & 0x7)); } -static void x86_64_pop_reg(dill_stream s, int src) +static void +x86_64_pop_reg(dill_stream s, int src) { int rex = 0; - if (src > RDI) rex|= REX_B; - BYTE_OUT1R(s, rex, 0x58+(src&0x7)); + if (src > RDI) + rex |= REX_B; + BYTE_OUT1R(s, rex, 0x58 + (src & 0x7)); } - static void -x86_64_rshai(dill_stream s, int dest, int src, int imm) +x86_64_rshai(dill_stream s, int dest, int src, int imm) { int rex = REX_W; - if (dest !=src) { + if (dest != src) { x86_64_movl(s, dest, src); } - if (dest > RDI) rex |= REX_B; + if (dest > RDI) + rex |= REX_B; BYTE_OUT3R(s, rex, 0xc1, ModRM(0x3, 0x7, dest), imm & 0xff); } static void -x86_64_rshi(dill_stream s, int dest, int src, int imm) +x86_64_rshi(dill_stream s, int dest, int src, int imm) { int rex = REX_W; - if (dest !=src) { - x86_64_movl(s, dest, src); + if (dest != src) { + x86_64_movl(s, dest, src); } - if (dest > RDI) rex |= REX_B; + if (dest > RDI) + rex |= REX_B; BYTE_OUT3R(s, rex, 0xc1, ModRM(0x3, 0x5, dest), imm & 0xff); } static void -x86_64_lshi(dill_stream s, int dest, int src, int imm) +x86_64_lshi(dill_stream s, int dest, int src, int imm) { int rex = REX_W; if (dest != src) { x86_64_movl(s, dest, src); } - if (dest > RDI) rex |= REX_B; + if (dest > RDI) + rex |= REX_B; BYTE_OUT3R(s, rex, 0xc1, ModRM(0x3, 0x4, dest), imm & 0xff); } @@ -504,26 +540,34 @@ static void x86_64_pmov(dill_stream s, int typ, int dest, int src) { int rex = 0; - if ((typ == DILL_L) || (typ == DILL_UL) || (typ == DILL_P)) rex = REX_W; - if (src > RDI) rex |= REX_R; - if (dest > RDI) rex |= REX_B; + if ((typ == DILL_L) || (typ == DILL_UL) || (typ == DILL_P)) + rex = REX_W; + if (src > RDI) + rex |= REX_R; + if (dest > RDI) + rex |= REX_B; if (src != dest) { - switch (typ) { - case DILL_D: case DILL_F: - // The 0x29 form of this instruction is not supported by valgrind - // the 0x28 version reverses the operands. - // BYTE_OUT1(s, 0x66); - // BYTE_OUT3R(s, rex, 0x0f, 0x29, ModRM(0x3, src, dest)); - rex = 0; - if (dest > RDI) rex |= REX_R; - if (src > RDI) rex |= REX_B; - BYTE_OUT1(s, 0x66); - BYTE_OUT3R(s, rex, 0x0f, 0x28, ModRM(0x3, dest, src)); - break; - default: - BYTE_OUT2R(s, rex, MOV32, ModRM(0x3, src, dest)); - break; - } + switch (typ) { + case DILL_D: + case DILL_F: + // The 0x29 form of this instruction is not supported by + // valgrind + // the 0x28 version reverses the operands. + // BYTE_OUT1(s, 0x66); + // BYTE_OUT3R(s, rex, 0x0f, 0x29, ModRM(0x3, src, + // dest)); + rex = 0; + if (dest > RDI) + rex |= REX_R; + if (src > RDI) + rex |= REX_B; + BYTE_OUT1(s, 0x66); + BYTE_OUT3R(s, rex, 0x0f, 0x28, ModRM(0x3, dest, src)); + break; + default: + BYTE_OUT2R(s, rex, MOV32, ModRM(0x3, src, dest)); + break; + } } } @@ -531,105 +575,110 @@ static void x86_64_sxmov(dill_stream s, int typ, int src, int dest) { int rex = REX_W; - if (src > RDI) rex |= REX_R; - if (dest > RDI) rex |= REX_B; + if (src > RDI) + rex |= REX_R; + if (dest > RDI) + rex |= REX_B; if (src != dest) { switch (typ) { - case DILL_C: - BYTE_OUT3R(s, rex, 0x0f, 0xbe, ModRM(0x3, src, dest)); - break; - case DILL_UC: - BYTE_OUT3R(s, rex, 0x0f, 0xb6, ModRM(0x3, src, dest)); - break; - case DILL_S: - BYTE_OUT3R(s, rex, 0x0f, 0xbf, ModRM(0x3, src, dest)); - break; - case DILL_US: - BYTE_OUT3R(s, rex, 0x0f, 0xb7, ModRM(0x3, src, dest)); - break; - } - } -} - -extern void x86_64_farith2(s, b1, typ, dest, src) -dill_stream s; -int b1; -int typ; -int dest; -int src; + case DILL_C: + BYTE_OUT3R(s, rex, 0x0f, 0xbe, ModRM(0x3, src, dest)); + break; + case DILL_UC: + BYTE_OUT3R(s, rex, 0x0f, 0xb6, ModRM(0x3, src, dest)); + break; + case DILL_S: + BYTE_OUT3R(s, rex, 0x0f, 0xbf, ModRM(0x3, src, dest)); + break; + case DILL_US: + BYTE_OUT3R(s, rex, 0x0f, 0xb7, ModRM(0x3, src, dest)); + break; + } + } +} + +extern void +x86_64_farith2(dill_stream s, int b1, int typ, int dest, int src) { /* this is fneg */ int rex = 0; int op = 0xf3; - if (src > XMM7) rex |= REX_B; - if (dest > XMM7) rex |= REX_R; - + if (src > XMM7) + rex |= REX_B; + if (dest > XMM7) + rex |= REX_R; + /* clear dest */ { - int rex1 = 0; - if (dest > XMM7) rex1 = REX_R|REX_B; - BYTE_OUT3R(s, rex1, 0x0f, 0x57, ModRM(0x3, dest, dest)); // GSE really rex1? Late fix. - } - if (typ == DILL_D) op = 0xf2; + int rex1 = 0; + if (dest > XMM7) + rex1 = REX_R | REX_B; + BYTE_OUT3R(s, rex1, 0x0f, 0x57, + ModRM(0x3, dest, dest)); // GSE really rex1? Late fix. + } + if (typ == DILL_D) + op = 0xf2; BYTE_OUT1R3(s, op, rex, 0x0f, 0x5c, ModRM(0x3, dest, src)); } -extern void x86_64_farith(s, b1, typ, dest, src1, src2) -dill_stream s; -int b1; -int typ; -int dest; -int src1; -int src2; +extern void +x86_64_farith(dill_stream s, int b1, int typ, int dest, int src1, int src2) { int rex = 0; int op = 0xf3; - + if (src2 == dest) { - /* protect src2 from overwrite (below) */ - x86_64_movd(s, XMM0, src2); - src2 = XMM0; - } - if (src2 > XMM7) rex |= REX_B; - if (dest > XMM7) rex |= REX_R; - if (src1 != dest) x86_64_movd(s, dest, src1); - if (typ == DILL_D) op = 0xf2; + /* protect src2 from overwrite (below) */ + x86_64_movd(s, XMM0, src2); + src2 = XMM0; + } + if (src2 > XMM7) + rex |= REX_B; + if (dest > XMM7) + rex |= REX_R; + if (src1 != dest) + x86_64_movd(s, dest, src1); + if (typ == DILL_D) + op = 0xf2; BYTE_OUT1R3(s, op, rex, 0x0f, b1, ModRM(0x3, dest, src2)); } static void -x86_64_seti(dill_stream s, int r, int val) +x86_64_seti(dill_stream s, int r, int val) { int rex = 0; - if (r > RDI) rex |= REX_B; + if (r > RDI) + rex |= REX_B; BYTE_OUT1IR(s, rex, 0xb8 + (0x7 & r), val); } -static void +static void x86_64_setl(dill_stream s, int r, IMM_TYPE val) { int rex = REX_W; - if (r > RDI) rex |= REX_B; + if (r > RDI) + rex |= REX_B; BYTE_OUT1LR(s, rex, 0xb8 + ((0x7) & r), val); } -extern void -x86_64_setp(dill_stream s, int type, int junk, int r, void *val) +extern void +x86_64_setp(dill_stream s, int type, int junk, int r, void* val) { int rex = REX_W; union { - intptr_t l; - void *a; + intptr_t l; + void* a; } a; a.a = val; - if (r > RDI) rex |= REX_B; + if (r > RDI) + rex |= REX_B; BYTE_OUT1LR(s, rex, 0xb8 + ((0x7) & r), a.l); } extern int x86_64_local(dill_stream s, int type) { - x86_64_mach_info smi = (x86_64_mach_info) s->p->mach_info; + x86_64_mach_info smi = (x86_64_mach_info)s->p->mach_info; s->p->used_frame++; smi->act_rec_size += roundup(type_info[type].size, smi->stack_align); @@ -639,7 +688,7 @@ x86_64_local(dill_stream s, int type) extern int x86_64_localb(dill_stream s, int size) { - x86_64_mach_info smi = (x86_64_mach_info) s->p->mach_info; + x86_64_mach_info smi = (x86_64_mach_info)s->p->mach_info; s->p->used_frame++; smi->act_rec_size = roundup(smi->act_rec_size, size); @@ -647,64 +696,67 @@ x86_64_localb(dill_stream s, int size) return (-smi->act_rec_size) + smi->stack_constant_offset; } -extern int x86_64_local_op(dill_stream s, int flag, int val) +extern int +x86_64_local_op(dill_stream s, int flag, int val) { int size = val; if (flag == 0) { - size = type_info[val].size; + size = type_info[val].size; } return x86_64_localb(s, size); -} +} #define BEGIN_FLOAT_SAVE 64 extern void x86_64_save_restore_op(dill_stream s, int save_restore, int type, int reg) { - x86_64_mach_info smi = (x86_64_mach_info) s->p->mach_info; + x86_64_mach_info smi = (x86_64_mach_info)s->p->mach_info; int offset = 0; switch (type) { - case DILL_D: case DILL_F: - offset = reg * smi->stack_align + BEGIN_FLOAT_SAVE; - break; + case DILL_D: + case DILL_F: + offset = reg * smi->stack_align + BEGIN_FLOAT_SAVE; + break; default: - if ((reg == RBX) || ((reg >= R12) && (reg <= R15))) { - /* RBX, R12-R15 inclusive are callee-saved, caller doesn't save */ - return; - } - switch (reg) { - case RDI: - offset = 0; - break; - case RSI: - offset = 8; - break; - case RDX: - offset = 16; - break; - case RCX: - offset = 24; - break; - case R8: - offset = 32; - break; - case R9: - offset = 40; - break; - case R10: - offset = 48; - break; - case R11: - offset = 56; - break; - default: - printf("x86_64 save_restore called with int reg %d\n", reg); - assert(0); /* shouldn't happen */ - } + if ((reg == RBX) || ((reg >= R12) && (reg <= R15))) { + /* RBX, R12-R15 inclusive are callee-saved, caller doesn't save + */ + return; + } + switch (reg) { + case RDI: + offset = 0; + break; + case RSI: + offset = 8; + break; + case RDX: + offset = 16; + break; + case RCX: + offset = 24; + break; + case R8: + offset = 32; + break; + case R9: + offset = 40; + break; + case R10: + offset = 48; + break; + case R11: + offset = 56; + break; + default: + printf("x86_64 save_restore called with int reg %d\n", reg); + assert(0); /* shouldn't happen */ + } } if (save_restore == 0) { /* save */ - x86_64_pstorei(s, type, 0, reg, _frame_reg, smi->save_base + offset); - } else { /* restore */ - x86_64_ploadi(s, type, 0, reg, _frame_reg, smi->save_base + offset); + x86_64_pstorei(s, type, 0, reg, _frame_reg, smi->save_base + offset); + } else { /* restore */ + x86_64_ploadi(s, type, 0, reg, _frame_reg, smi->save_base + offset); } s->p->used_frame++; } @@ -730,11 +782,11 @@ x86_64_save_restore_op(dill_stream s, int save_restore, int type, int reg) * %rdi used to pass 1st argument to functions No * %r8 used to pass 5th argument to functions No * %r9 used to pass 6th argument to functions No - * %r10 temporary register, used for passing a + * %r10 temporary register, used for passing a * function?s static chain pointer No * %r11 temporary register No * %r12-r15 callee-saved registers Yes - * %xmm0-%xmm1 used to pass and return floating point + * %xmm0-%xmm1 used to pass and return floating point * arguments No * %xmm2-%xmm7 used to pass floating point arguments No * %xmm8-%xmm15 temporary registers No @@ -742,7 +794,7 @@ x86_64_save_restore_op(dill_stream s, int save_restore, int type, int reg) * %st0 temporary register; used to return long double args No * %st1 temporary registers; used to return long double args No * %st2-%st7 temporary registers No - * %fs Reserved for system use (as thread specific data register) + * %fs Reserved for system use (as thread specific data register) Figure 3.33: Register Save Area (modified -- GSE ) Register Offset @@ -769,89 +821,126 @@ static int arg_regs[] = {RCX, RDX, R8, R9}; static void save_required_regs(dill_stream s, int force) { - if (s->p->call_table.call_count != 0) force++; + if (s->p->call_table.call_count != 0) + force++; #ifdef OSX if (force) { - dill_andii(s, ESP, ESP, -16); /* make sure it's multiple of 16 */ + dill_andii(s, ESP, ESP, -16); /* make sure it's multiple of 16 */ } #endif /* callee is supposed to save these */ - if (force || dill_wasused(&s->p->var_i, EBX) || dill_wasused(&s->p->tmp_i, EBX)) { - x86_64_push_reg(s, EBX); + if (force || dill_wasused(&s->p->var_i, EBX) || + dill_wasused(&s->p->tmp_i, EBX)) { + x86_64_push_reg(s, EBX); } - if (force || dill_wasused(&s->p->var_i, R12) || dill_wasused(&s->p->tmp_i, R12)) { - x86_64_push_reg(s, R12); + if (force || dill_wasused(&s->p->var_i, R12) || + dill_wasused(&s->p->tmp_i, R12)) { + x86_64_push_reg(s, R12); } - if (force || dill_wasused(&s->p->var_i, R13) || dill_wasused(&s->p->tmp_i, R13)) { - x86_64_push_reg(s, R13); + if (force || dill_wasused(&s->p->var_i, R13) || + dill_wasused(&s->p->tmp_i, R13)) { + x86_64_push_reg(s, R13); } - if (force || dill_wasused(&s->p->var_i, R14) || dill_wasused(&s->p->tmp_i, R14)) { - x86_64_push_reg(s, R14); + if (force || dill_wasused(&s->p->var_i, R14) || + dill_wasused(&s->p->tmp_i, R14)) { + x86_64_push_reg(s, R14); } - if (force || dill_wasused(&s->p->var_i, R15) || dill_wasused(&s->p->tmp_i, R15)) { - x86_64_push_reg(s, R15); + if (force || dill_wasused(&s->p->var_i, R15) || + dill_wasused(&s->p->tmp_i, R15)) { + x86_64_push_reg(s, R15); } } -static int -generate_prefix_code(dill_stream s, int force, int ar_size, dill_reg *arglist) +static int +generate_prefix_code(dill_stream s, int force, int ar_size, dill_reg* arglist) { int end, start = (int)((char*)s->p->cur_ip - (char*)s->p->code_base); int i, int_arg_count, float_arg_count; arg_info_list args = s->p->c_param_args; - if ((s->p->c_param_count > 0) || s->p->used_frame || (s->p->call_table.call_count != 0) || force) { - x86_64_push_reg(s, EBP); - x86_64_movl(s, EBP, ESP); + if ((s->p->c_param_count > 0) || s->p->used_frame || + (s->p->call_table.call_count != 0) || force) { + x86_64_push_reg(s, EBP); + x86_64_movl(s, EBP, ESP); } if (force || s->p->used_frame || (s->p->call_table.call_count != 0)) { - /* do local space reservation */ - dill_subli(s, ESP, ESP, ar_size); + /* do local space reservation */ + dill_subli(s, ESP, ESP, ar_size); } save_required_regs(s, force); - int_arg_count = float_arg_count = 0; /* reset */ + int_arg_count = float_arg_count = 0; /* reset */ for (i = 0; i < s->p->c_param_count; i++) { - int came_in_a_reg = 0; - switch (args[i].type) { - case DILL_D: case DILL_F: - came_in_a_reg = (float_arg_count++ < 8); - break; - default: - came_in_a_reg = (int_arg_count++ < 6); - break; - } - if (came_in_a_reg && (args[i].in_reg == -1)) { - /* not enough regs for this, store it to the stack */ - int real_offset = args[i].offset; - x86_64_pstorei(s, args[i].type, 0, arg_regs[int_arg_count-1], EBP, - real_offset); - continue; - } - if (came_in_a_reg && args[i].is_register) { - switch(args[i].type) { - case DILL_D: case DILL_F: - x86_64_movd(s, args[i].in_reg, float_arg_count-1); - break; - case DILL_UC: case DILL_C: case DILL_US: case DILL_S: - x86_64_sxmov(s, args[i].type, args[i].in_reg, arg_regs[int_arg_count-1]); - break; - default: - x86_64_movl(s, args[i].in_reg, arg_regs[int_arg_count-1]); - break; - } - continue; - } - if (args[i].is_register) { - /* general offset from fp*/ - int real_offset = args[i].offset; - x86_64_ploadi(s, args[i].type, 0, args[i].in_reg, EBP, real_offset); - } - + int came_in_a_reg = 0; + switch (args[i].type) { + case DILL_D: + case DILL_F: +#ifdef USE_WINDOWS_CALLS + came_in_a_reg = (float_arg_count + int_arg_count) < 4; + float_arg_count++; +#else + came_in_a_reg = (float_arg_count++ < 8); +#endif + break; + default: +#ifdef USE_WINDOWS_CALLS + came_in_a_reg = (float_arg_count + int_arg_count) < 4; + int_arg_count++; +#else + came_in_a_reg = (int_arg_count++ < 6); +#endif + break; + } + if (came_in_a_reg && (args[i].in_reg == -1)) { + /* not enough regs for this, store it to the stack */ + int real_offset = args[i].offset; + x86_64_pstorei(s, args[i].type, 0, arg_regs[int_arg_count - 1], EBP, + real_offset); + continue; + } + if (came_in_a_reg && args[i].is_register) { + switch (args[i].type) { + case DILL_D: + case DILL_F: +#ifdef USE_WINDOWS_CALLS + x86_64_movd(s, args[i].in_reg, + float_arg_count + int_arg_count - 1); +#else + x86_64_movd(s, args[i].in_reg, float_arg_count - 1); +#endif + break; + case DILL_UC: + case DILL_C: + case DILL_US: + case DILL_S: +#ifdef USE_WINDOWS_CALLS + x86_64_sxmov(s, args[i].type, args[i].in_reg, + arg_regs[float_arg_count + int_arg_count - 1]); +#else + x86_64_sxmov(s, args[i].type, args[i].in_reg, + arg_regs[int_arg_count - 1]); +#endif + break; + default: +#ifdef USE_WINDOWS_CALLS + x86_64_movl(s, args[i].in_reg, + arg_regs[int_arg_count + float_arg_count - 1]); +#else + x86_64_movl(s, args[i].in_reg, arg_regs[int_arg_count - 1]); +#endif + break; + } + continue; + } + if (args[i].is_register) { + /* general offset from fp*/ + int real_offset = args[i].offset; + x86_64_ploadi(s, args[i].type, 0, args[i].in_reg, EBP, real_offset); + } } end = (int)((char*)s->p->cur_ip - (char*)s->p->code_base); @@ -859,20 +948,23 @@ generate_prefix_code(dill_stream s, int force, int ar_size, dill_reg *arglist) } extern void -x86_64_proc_start(dill_stream s, char *subr_name, int arg_count, arg_info_list args, - dill_reg *arglist) +x86_64_proc_start(dill_stream s, + char* subr_name, + int arg_count, + arg_info_list args, + dill_reg* arglist) { int i, int_arg_count, float_arg_count; int cur_arg_offset = 0; - x86_64_mach_info smi = (x86_64_mach_info) s->p->mach_info; + x86_64_mach_info smi = (x86_64_mach_info)s->p->mach_info; smi->pending_prefix = 0; smi->last_proc_ret_end = 0; /* leave some space */ x86_64_local(s, DILL_D); smi->conversion_word = x86_64_local(s, DILL_D); smi->fcu_word = x86_64_local(s, DILL_I); - smi->save_base = x86_64_localb(s, BEGIN_FLOAT_SAVE + 16*16); + smi->save_base = x86_64_localb(s, BEGIN_FLOAT_SAVE + 16 * 16); s->p->used_frame = 0; cur_arg_offset = 16; @@ -880,82 +972,122 @@ x86_64_proc_start(dill_stream s, char *subr_name, int arg_count, arg_info_list a float_arg_count = 0; for (i = 0; i < arg_count; i++) { args[i].in_reg = -1; - args[i].out_reg = -1; - args[i].is_register = 0; - if (arglist != NULL) arglist[i] = -1; - if ((args[i].type != DILL_F) && (args[i].type != DILL_D) && (int_arg_count < 6)) { - args[i].offset = smi->save_base + int_arg_count*8; - int_arg_count++; - if (int_arg_count <= 4) { - dill_reg tmp_reg; - if (dill_raw_getreg(s, &tmp_reg, args[i].type, DILL_VAR)) { - args[i].in_reg = tmp_reg; - if (arglist != NULL) arglist[i] = tmp_reg; - args[i].is_register = 1; - } - } else { - if (int_arg_count <= (sizeof(arg_regs) / sizeof(arg_regs[0]))) { - args[i].is_register = 1; - args[i].in_reg = arg_regs[int_arg_count-1]; - } - } - } else if (((args[i].type == DILL_F) || (args[i].type == DILL_D)) && (float_arg_count < 8)) { - args[i].offset = smi->save_base + BEGIN_FLOAT_SAVE + float_arg_count*8; - float_arg_count++; - if (float_arg_count <= 4) { - dill_reg tmp_reg; - if (dill_raw_getreg(s, &tmp_reg, args[i].type, DILL_VAR)) { - args[i].in_reg = tmp_reg; - if (arglist != NULL) arglist[i] = tmp_reg; - args[i].is_register = 1; - } - } - } else { - args[i].offset = cur_arg_offset; - cur_arg_offset += roundup(type_info[(int)args[i].type].size, smi->stack_align); - } - } - /* make local space reservation constant big so we have a word to patch */ - /* use the nop op code so that if we don't use all of it we get nops */ - (void) generate_prefix_code(s, 1 /* force */, 0x909090, arglist); - - smi->backpatch_offset = (int)((char*)s->p->cur_ip - (char*)s->p->code_base); + args[i].out_reg = -1; + args[i].is_register = 0; + if (arglist != NULL) + arglist[i] = -1; +#ifdef USE_WINDOWS_CALLS + if ((args[i].type != DILL_F) && (args[i].type != DILL_D) && + (int_arg_count + float_arg_count < 4)) { + cur_arg_offset += + roundup(type_info[(int)args[i].type].size, smi->stack_align); +#else + if ((args[i].type != DILL_F) && (args[i].type != DILL_D) && + (int_arg_count < 6)) { +#endif + + args[i].offset = smi->save_base + int_arg_count * 8; + int_arg_count++; +#ifdef USE_WINDOWS_CALLS + if (int_arg_count + float_arg_count <= 4) { +#else + if (int_arg_count <= 4) { +#endif + dill_reg tmp_reg; + if (dill_raw_getreg(s, &tmp_reg, args[i].type, DILL_VAR)) { + args[i].in_reg = tmp_reg; + if (arglist != NULL) + arglist[i] = tmp_reg; + args[i].is_register = 1; + } + } else { +#ifdef USE_WINDOWS_CALLS + if (int_arg_count + float_arg_count <= + (sizeof(arg_regs) / sizeof(arg_regs[0]))) { +#else + if (int_arg_count <= (sizeof(arg_regs) / sizeof(arg_regs[0]))) { +#endif + args[i].is_register = 1; + args[i].in_reg = arg_regs[int_arg_count - 1]; + } + } +#ifdef USE_WINDOWS_CALLS + } else if (((args[i].type == DILL_F) || (args[i].type == DILL_D)) && + (int_arg_count + float_arg_count < 4)) { + cur_arg_offset += + roundup(type_info[(int)args[i].type].size, smi->stack_align); +#else + } else if (((args[i].type == DILL_F) || (args[i].type == DILL_D)) && + (float_arg_count < 8)) { +#endif + + args[i].offset = + smi->save_base + BEGIN_FLOAT_SAVE + float_arg_count * 8; + float_arg_count++; + if (float_arg_count <= 4) { + dill_reg tmp_reg; + if (dill_raw_getreg(s, &tmp_reg, args[i].type, DILL_VAR)) { + args[i].in_reg = tmp_reg; + if (arglist != NULL) + arglist[i] = tmp_reg; + args[i].is_register = 1; + } + } + } else { + args[i].offset = cur_arg_offset; + cur_arg_offset += + roundup(type_info[(int)args[i].type].size, smi->stack_align); + } + } + /* make local space reservation constant big so we have a word to patch */ + /* use the nop op code so that if we don't use all of it we get nops */ + (void)generate_prefix_code(s, 1 /* force */, 0x909090, arglist); + + smi->backpatch_offset = (int)((char*)s->p->cur_ip - (char*)s->p->code_base); } static void -x86_64_proc_ret(dill_stream s) +x86_64_proc_ret(dill_stream s) { - x86_64_mach_info smi = (x86_64_mach_info) s->p->mach_info; + x86_64_mach_info smi = (x86_64_mach_info)s->p->mach_info; int force = 0; - if (s->p->call_table.call_count != 0) force++; + if (s->p->call_table.call_count != 0) + force++; - /* last thing was a ret and there's not a label here, we don't need another ret */ + /* last thing was a ret and there's not a label here, we don't need another + * ret */ if ((smi->last_proc_ret_end == s->p->cur_ip) && !dill_is_label_mark(s)) - return; + return; - if (force || dill_wasused(&s->p->var_i, R15) || dill_wasused(&s->p->tmp_i, R15)) { - x86_64_pop_reg(s, R15); + if (force || dill_wasused(&s->p->var_i, R15) || + dill_wasused(&s->p->tmp_i, R15)) { + x86_64_pop_reg(s, R15); } - if (force || dill_wasused(&s->p->var_i, R14) || dill_wasused(&s->p->tmp_i, R14)) { - x86_64_pop_reg(s, R14); + if (force || dill_wasused(&s->p->var_i, R14) || + dill_wasused(&s->p->tmp_i, R14)) { + x86_64_pop_reg(s, R14); } - if (force || dill_wasused(&s->p->var_i, R13) || dill_wasused(&s->p->tmp_i, R13)) { - x86_64_pop_reg(s, R13); + if (force || dill_wasused(&s->p->var_i, R13) || + dill_wasused(&s->p->tmp_i, R13)) { + x86_64_pop_reg(s, R13); } - if (force || dill_wasused(&s->p->var_i, R12) || dill_wasused(&s->p->tmp_i, R12)) { - x86_64_pop_reg(s, R12); + if (force || dill_wasused(&s->p->var_i, R12) || + dill_wasused(&s->p->tmp_i, R12)) { + x86_64_pop_reg(s, R12); } - if (force || dill_wasused(&s->p->var_i, EBX) || dill_wasused(&s->p->tmp_i, EBX)) { - x86_64_pop_reg(s, EBX); + if (force || dill_wasused(&s->p->var_i, EBX) || + dill_wasused(&s->p->tmp_i, EBX)) { + x86_64_pop_reg(s, EBX); } - if ((s->p->c_param_count > 0) || s->p->used_frame || (s->p->call_table.call_count != 0)) { + if ((s->p->c_param_count > 0) || s->p->used_frame || + (s->p->call_table.call_count != 0)) { x86_64_movl(s, ESP, EBP); - x86_64_pop_reg(s, EBP); + x86_64_pop_reg(s, EBP); } BYTE_OUT1(s, 0xc3); smi->last_proc_ret_end = s->p->cur_ip; } - + static unsigned char ld_opcodes[] = { 0x8a, /* DILL_C */ 0x8a, /* DILL_UC */ @@ -973,139 +1105,165 @@ static unsigned char ld_opcodes[] = { 0x8b, /* DILL_EC */ }; -static void x86_64_clear(s, dest) -dill_stream s; -int dest; +static void +x86_64_clear(dill_stream s, int dest) { int rex = REX_W; - if (dest > RDI) rex |= REX_B | REX_R; - BYTE_OUT2R(s, rex, 0x33, ModRM(0x3, dest, dest)); /* xor dest, dest */ + if (dest > RDI) + rex |= REX_B | REX_R; + BYTE_OUT2R(s, rex, 0x33, ModRM(0x3, dest, dest)); /* xor dest, dest */ } extern void -x86_64_ploadi(dill_stream s, int type, int junk, int dest, int src, IMM_TYPE offset) +x86_64_ploadi(dill_stream s, + int type, + int junk, + int dest, + int src, + IMM_TYPE offset) { unsigned char opcode = ld_opcodes[type]; int tmp_dest = dest; - x86_64_mach_info smi = (x86_64_mach_info) s->p->mach_info; + x86_64_mach_info smi = (x86_64_mach_info)s->p->mach_info; int rex = 0; int float_op = 0; if ((type == DILL_L) || (type == DILL_UL) || (type == DILL_P)) { - rex = REX_W; + rex = REX_W; } switch (type) { - case DILL_F: - float_op = 0xf3; - break; + case DILL_F: + float_op = 0xf3; + break; case DILL_D: - float_op = 0xf2; - break; + float_op = 0xf2; + break; case DILL_C: case DILL_UC: - if (dest >= ESP) { - /* movb doesn't work for big regs, load to eax */ - tmp_dest = EAX; - } - if (type == DILL_UC) { - /* clear high bytes */ - if (src == tmp_dest) { - /* don't destroy source */ - tmp_dest = EAX; - } - x86_64_clear(s, tmp_dest); - } - break; - case DILL_S: case DILL_US: - if (type == DILL_US) { - /* clear high bytes */ - if (src == tmp_dest) { - /* don't destroy source */ - tmp_dest = EAX; - } - x86_64_clear(s, tmp_dest); - } - BYTE_OUT1(s, 0x66); - break; - case DILL_L: case DILL_UL: case DILL_P: + if (dest >= ESP) { + /* movb doesn't work for big regs, load to eax */ + tmp_dest = EAX; + } + if (type == DILL_UC) { + /* clear high bytes */ + if (src == tmp_dest) { + /* don't destroy source */ + tmp_dest = EAX; + } + x86_64_clear(s, tmp_dest); + } + break; + case DILL_S: + case DILL_US: + if (type == DILL_US) { + /* clear high bytes */ + if (src == tmp_dest) { + /* don't destroy source */ + tmp_dest = EAX; + } + x86_64_clear(s, tmp_dest); + } + BYTE_OUT1(s, 0x66); + break; + case DILL_L: + case DILL_UL: + case DILL_P: /* fall through */ default: - break; + break; } if (smi->pending_prefix != 0) { BYTE_OUT1(s, smi->pending_prefix); - smi->pending_prefix = 0; + smi->pending_prefix = 0; } - if (src > RDI) rex |= REX_B; - if (tmp_dest > RDI) rex |= REX_R; + if (src > RDI) + rex |= REX_B; + if (tmp_dest > RDI) + rex |= REX_R; if (((0x7 & src) == RSP) && - (((offset & 0xffffffff80000000) == 0) || - ((offset & 0xffffffff80000000) == 0xffffffff80000000))) { - /* must use SIB because ModRM has a discontinuity */ - if (offset == 0) { - if (float_op != 0) { - BYTE_OUT1R4(s, float_op, rex, 0x0f, 0x10, ModRM(0x0, tmp_dest, 0x4), SIB(0,4,src)); - } else { - BYTE_OUT3R(s, rex, opcode, ModRM(0x0, tmp_dest, 0x4),SIB(0,4,src)); - } - } else if (((intptr_t)offset <= 127) && ((intptr_t)offset > -128)) { - if (float_op != 0) { - BYTE_OUT1R5(s, float_op, rex, 0x0f, 0x10, ModRM(0x1, tmp_dest, src), SIB(0,ESP,0x4),offset & 0xff); - } else { - BYTE_OUT4R(s, rex, opcode, ModRM(0x1, tmp_dest, src), SIB(0,ESP,0x4), offset & 0xff); - } - } else { - if (float_op != 0) { - BYTE_OUT1R4I(s, float_op, rex, 0x0f, 0x10, ModRM(0x2, tmp_dest, 0x4), SIB(0,4,src), offset); - } else { - BYTE_OUT3IR(s, rex, opcode, ModRM(0x2, tmp_dest, 0x4), SIB(0,4,src),offset); - } - } + (((offset & 0xffffffff80000000) == 0) || + ((offset & 0xffffffff80000000) == 0xffffffff80000000))) { + /* must use SIB because ModRM has a discontinuity */ + if (offset == 0) { + if (float_op != 0) { + BYTE_OUT1R4(s, float_op, rex, 0x0f, 0x10, + ModRM(0x0, tmp_dest, 0x4), SIB(0, 4, src)); + } else { + BYTE_OUT3R(s, rex, opcode, ModRM(0x0, tmp_dest, 0x4), + SIB(0, 4, src)); + } + } else if (((intptr_t)offset <= 127) && ((intptr_t)offset > -128)) { + if (float_op != 0) { + BYTE_OUT1R5(s, float_op, rex, 0x0f, 0x10, + ModRM(0x1, tmp_dest, src), SIB(0, ESP, 0x4), + offset & 0xff); + } else { + BYTE_OUT4R(s, rex, opcode, ModRM(0x1, tmp_dest, src), + SIB(0, ESP, 0x4), offset & 0xff); + } + } else { + if (float_op != 0) { + BYTE_OUT1R4I(s, float_op, rex, 0x0f, 0x10, + ModRM(0x2, tmp_dest, 0x4), SIB(0, 4, src), + (int)offset); + } else { + BYTE_OUT3IR(s, rex, opcode, ModRM(0x2, tmp_dest, 0x4), + SIB(0, 4, src), (int)offset); + } + } } else { - if ((offset == 0) && ((src &0x7) != 5)){ /* avoid discontinuity in ModRM */ - if (float_op != 0) { - BYTE_OUT1R3(s, float_op, rex, 0x0f, 0x10, ModRM(0x0, tmp_dest, src)); - } else { - BYTE_OUT2R(s, rex, opcode, ModRM(0x0, tmp_dest, src)); - } - } else if (((intptr_t)offset <= 127) && ((intptr_t)offset > -128)) { - if (float_op != 0) { - BYTE_OUT1R4(s, float_op, rex, 0x0f, 0x10, ModRM(0x1, tmp_dest, src), offset & 0xff); - } else { - BYTE_OUT3R(s, rex, opcode, ModRM(0x1, tmp_dest, src), offset & 0xff); - } - } else if (((offset & 0xffffffff80000000) == 0) || - ((offset & 0xffffffff80000000) == 0xffffffff80000000)) { - if (float_op != 0) { - BYTE_OUT1R3I(s, float_op, rex, 0x0f, 0x10, ModRM(0x2, tmp_dest, src), offset); - } else { - BYTE_OUT2IR(s, rex, opcode, ModRM(0x2, tmp_dest, src), offset); - } - } else { - /* really big offset */ - if (dest != src) { - /* use dest since it'll be destroyed by the load */ - x86_64_setl(s, dest, offset); - x86_64_pload(s, type, 0, dest, src, dest); - } else { - /* destroy src, but since it's the same as dest, it's lost anyway */ - x86_64_arith3i(s, 0, DILL_L, src, src, offset); - x86_64_ploadi(s, type, 0, dest, src, 0); - } - } - } - switch(type){ + if ((offset == 0) && + ((src & 0x7) != 5)) { /* avoid discontinuity in ModRM */ + if (float_op != 0) { + BYTE_OUT1R3(s, float_op, rex, 0x0f, 0x10, + ModRM(0x0, tmp_dest, src)); + } else { + BYTE_OUT2R(s, rex, opcode, ModRM(0x0, tmp_dest, src)); + } + } else if (((intptr_t)offset <= 127) && ((intptr_t)offset > -128)) { + if (float_op != 0) { + BYTE_OUT1R4(s, float_op, rex, 0x0f, 0x10, + ModRM(0x1, tmp_dest, src), offset & 0xff); + } else { + BYTE_OUT3R(s, rex, opcode, ModRM(0x1, tmp_dest, src), + offset & 0xff); + } + } else if (((offset & 0xffffffff80000000) == 0) || + ((offset & 0xffffffff80000000) == 0xffffffff80000000)) { + if (float_op != 0) { + BYTE_OUT1R3I(s, float_op, rex, 0x0f, 0x10, + ModRM(0x2, tmp_dest, src), (int)offset); + } else { + BYTE_OUT2IR(s, rex, opcode, ModRM(0x2, tmp_dest, src), + (int)offset); + } + } else { + /* really big offset */ + if (dest != src) { + /* use dest since it'll be destroyed by the load */ + x86_64_setl(s, dest, offset); + x86_64_pload(s, type, 0, dest, src, dest); + } else { + /* destroy src, but since it's the same as dest, it's lost + * anyway */ + x86_64_arith3i(s, 0, DILL_L, src, src, offset); + x86_64_ploadi(s, type, 0, dest, src, 0); + } + } + } + switch (type) { case DILL_C: - x86_64_lshi(s, dest, tmp_dest, 56); - x86_64_rshai(s, dest, dest, 56); - break; + x86_64_lshi(s, dest, tmp_dest, 56); + x86_64_rshai(s, dest, dest, 56); + break; case DILL_S: - x86_64_lshi(s, dest, tmp_dest, 48); - x86_64_rshai(s, dest, dest, 48); - break; - case DILL_UC: case DILL_US: - if (dest != tmp_dest) - x86_64_movi(s, dest, tmp_dest); - break; + x86_64_lshi(s, dest, tmp_dest, 48); + x86_64_rshai(s, dest, dest, 48); + break; + case DILL_UC: + case DILL_US: + if (dest != tmp_dest) + x86_64_movi(s, dest, tmp_dest); + break; } } @@ -1116,149 +1274,171 @@ x86_64_pload(dill_stream s, int type, int junk, int dest, int src1, int src2) int tmp_dest = dest; int clear_high_bytes_after_load = 0; - x86_64_mach_info smi = (x86_64_mach_info) s->p->mach_info; + x86_64_mach_info smi = (x86_64_mach_info)s->p->mach_info; int rex = 0; int float_op = 0; if ((type == DILL_L) || (type == DILL_UL) || (type == DILL_P)) { - rex = REX_W; + rex = REX_W; } - switch(type){ + switch (type) { case DILL_C: case DILL_UC: - if (dest >= ESP) { - /* movb doesn't work for big regs, load to eax */ - tmp_dest = EAX; - } - if (type == DILL_UC) { - /* clear high bytes */ - if ((src1 == tmp_dest) || (src2 == tmp_dest)) { - /* don't destroy source */ - tmp_dest = EAX; - } - if ((src1 == EAX) || (src2 == EAX)) { - clear_high_bytes_after_load = 1; - } else { - x86_64_clear(s, tmp_dest); - } - } - break; - case DILL_S: case DILL_US: - if (type == DILL_US) { - /* clear high bytes */ - if ((src1 == tmp_dest) || (src2 == tmp_dest)) { - /* don't destroy source */ - tmp_dest = EAX; - } - if ((src1 == EAX) || (src2 == EAX)) { - clear_high_bytes_after_load = 1; - } else { - x86_64_clear(s, tmp_dest); - } - } - BYTE_OUT1(s, 0x66); - break; + if (dest >= ESP) { + /* movb doesn't work for big regs, load to eax */ + tmp_dest = EAX; + } + if (type == DILL_UC) { + /* clear high bytes */ + if ((src1 == tmp_dest) || (src2 == tmp_dest)) { + /* don't destroy source */ + tmp_dest = EAX; + } + if ((src1 == EAX) || (src2 == EAX)) { + clear_high_bytes_after_load = 1; + } else { + x86_64_clear(s, tmp_dest); + } + } + break; + case DILL_S: + case DILL_US: + if (type == DILL_US) { + /* clear high bytes */ + if ((src1 == tmp_dest) || (src2 == tmp_dest)) { + /* don't destroy source */ + tmp_dest = EAX; + } + if ((src1 == EAX) || (src2 == EAX)) { + clear_high_bytes_after_load = 1; + } else { + x86_64_clear(s, tmp_dest); + } + } + BYTE_OUT1(s, 0x66); + break; case DILL_F: - float_op = 0xf3; - break; + float_op = 0xf3; + break; case DILL_D: - float_op = 0xf2; - break; - case DILL_L: case DILL_UL: case DILL_P: - if (smi->stack_align == 4) { - type = DILL_I; - } + float_op = 0xf2; + break; + case DILL_L: + case DILL_UL: + case DILL_P: + if (smi->stack_align == 4) { + type = DILL_I; + } } if (smi->pending_prefix != 0) { BYTE_OUT1(s, smi->pending_prefix); - smi->pending_prefix = 0; - } - if ((src2 & 0x7) == 0x5) { /* avoid SIB discontinuity */ - int tmp = src1; - src1 = src2; - src2 = tmp; - } - if (src1 > RDI) rex |= REX_X; - if (src2 > RDI) rex |= REX_B; - if (tmp_dest > RDI) rex |= REX_R; + smi->pending_prefix = 0; + } + if ((src2 & 0x7) == 0x5) { /* avoid SIB discontinuity */ + int tmp = src1; + src1 = src2; + src2 = tmp; + } + if (src1 > RDI) + rex |= REX_X; + if (src2 > RDI) + rex |= REX_B; + if (tmp_dest > RDI) + rex |= REX_R; if (float_op != 0) { - BYTE_OUT1R4(s, float_op, rex, 0x0f, 0x10, ModRM(0x0, tmp_dest, 0x4), SIB(0,src1,src2)); + BYTE_OUT1R4(s, float_op, rex, 0x0f, 0x10, ModRM(0x0, tmp_dest, 0x4), + SIB(0, src1, src2)); } else { - BYTE_OUT3R(s, rex, opcode, ModRM(0x0, tmp_dest, 0x4), SIB(0,src1,src2)); + BYTE_OUT3R(s, rex, opcode, ModRM(0x0, tmp_dest, 0x4), + SIB(0, src1, src2)); } - switch(type){ + switch (type) { case DILL_C: - x86_64_lshi(s, dest, tmp_dest, 56); - x86_64_rshai(s, dest, dest, 56); - break; + x86_64_lshi(s, dest, tmp_dest, 56); + x86_64_rshai(s, dest, dest, 56); + break; case DILL_S: - x86_64_lshi(s, dest, tmp_dest, 48); - x86_64_rshai(s, dest, dest, 48); - break; - case DILL_UC: case DILL_US: - if (dest != tmp_dest) { - if (clear_high_bytes_after_load) { - int bits = 56; - if (type == DILL_US) bits = 48; - x86_64_lshi(s, dest, tmp_dest, bits); - x86_64_rshi(s, dest, dest, bits); - } else { - x86_64_movi(s, dest, tmp_dest); - } - } - break; + x86_64_lshi(s, dest, tmp_dest, 48); + x86_64_rshai(s, dest, dest, 48); + break; + case DILL_UC: + case DILL_US: + if (dest != tmp_dest) { + if (clear_high_bytes_after_load) { + int bits = 56; + if (type == DILL_US) + bits = 48; + x86_64_lshi(s, dest, tmp_dest, bits); + x86_64_rshi(s, dest, dest, bits); + } else { + x86_64_movi(s, dest, tmp_dest); + } + } + break; } } extern void -x86_64_pbsloadi(dill_stream s, int type, int junk, int dest, int src, IMM_TYPE offset) +x86_64_pbsloadi(dill_stream s, + int type, + int junk, + int dest, + int src, + IMM_TYPE offset) { int rex = 0; int fdest = dest; int ltype = type; switch (type) { case DILL_D: - ltype = DILL_L; - fdest = dest; - dest = EAX; - break; + ltype = DILL_L; + fdest = dest; + dest = EAX; + break; case DILL_F: - ltype = DILL_I; - fdest = dest; - dest = EAX; - break; + ltype = DILL_I; + fdest = dest; + dest = EAX; + break; } x86_64_ploadi(s, ltype, junk, dest, src, offset); - if (dest > RDI) rex |= REX_B; - switch(type) { + if (dest > RDI) + rex |= REX_B; + switch (type) { case DILL_F: - rex = 0; - if (fdest > RDI) rex |= REX_R; - x86_64_bswap(s, 0, DILL_I, EAX, EAX); - BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, fdest, EAX)); - break; + rex = 0; + if (fdest > RDI) + rex |= REX_R; + x86_64_bswap(s, 0, DILL_I, EAX, EAX); + BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, fdest, EAX)); + break; case DILL_D: - rex = REX_W; - if (fdest > RDI) rex |= REX_R; - x86_64_bswap(s, 0, DILL_L, EAX, EAX); - BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, fdest, EAX)); - break; - case DILL_L: case DILL_UL: case DILL_P: - rex |= REX_W; - /* falling through */ - case DILL_I: case DILL_U: - BYTE_OUT2R(s, rex, 0x0f, 0xc8 + (dest&0x7)); /* byteswap dest */ - break; - case DILL_S: case DILL_US: - /* byteswap 32 bits and shift down 16 */ - BYTE_OUT2R(s, rex, 0x0f, 0xc8 + (dest&0x7)); /* byteswap dest */ - x86_64_rshi(s, dest, dest, 16); - break; - case DILL_C: case DILL_UC: - break; + rex = REX_W; + if (fdest > RDI) + rex |= REX_R; + x86_64_bswap(s, 0, DILL_L, EAX, EAX); + BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, fdest, EAX)); + break; + case DILL_L: + case DILL_UL: + case DILL_P: + rex |= REX_W; + /* falling through */ + case DILL_I: + case DILL_U: + BYTE_OUT2R(s, rex, 0x0f, 0xc8 + (dest & 0x7)); /* byteswap dest */ + break; + case DILL_S: + case DILL_US: + /* byteswap 32 bits and shift down 16 */ + BYTE_OUT2R(s, rex, 0x0f, 0xc8 + (dest & 0x7)); /* byteswap dest */ + x86_64_rshi(s, dest, dest, 16); + break; + case DILL_C: + case DILL_UC: + break; } } - extern void x86_64_pbsload(dill_stream s, int type, int junk, int dest, int src1, int src2) { @@ -1267,43 +1447,51 @@ x86_64_pbsload(dill_stream s, int type, int junk, int dest, int src1, int src2) int ltype = type; switch (type) { case DILL_D: - ltype = DILL_L; - fdest = dest; - dest = EAX; - break; + ltype = DILL_L; + fdest = dest; + dest = EAX; + break; case DILL_F: - ltype = DILL_I; - fdest = dest; - dest = EAX; - break; + ltype = DILL_I; + fdest = dest; + dest = EAX; + break; } - if (dest > RDI) rex |= REX_B; + if (dest > RDI) + rex |= REX_B; x86_64_pload(s, ltype, junk, dest, src1, src2); - switch(type) { + switch (type) { case DILL_F: - rex = 0; - x86_64_bswap(s, 0, DILL_I, EAX, EAX); - if (fdest > RDI) rex |= REX_R; - BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, fdest, EAX)); - break; + rex = 0; + x86_64_bswap(s, 0, DILL_I, EAX, EAX); + if (fdest > RDI) + rex |= REX_R; + BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, fdest, EAX)); + break; case DILL_D: - rex = REX_W; - if (fdest > RDI) rex |= REX_R; - x86_64_bswap(s, 0, DILL_L, EAX, EAX); - BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, fdest, EAX)); - break; - case DILL_L: case DILL_UL: case DILL_P: - rex |= REX_W; - case DILL_I: case DILL_U: - BYTE_OUT2R(s, rex, 0x0f, 0xc8 + (dest&0x7)); /* byteswap dest */ - break; - case DILL_S: case DILL_US: - /* byteswap 32 bits and shift down 16 */ - BYTE_OUT2R(s, rex, 0x0f, 0xc8 + (dest&0x7)); /* byteswap dest */ - x86_64_rshi(s, dest, dest, 16); - break; - case DILL_C: case DILL_UC: - break; + rex = REX_W; + if (fdest > RDI) + rex |= REX_R; + x86_64_bswap(s, 0, DILL_L, EAX, EAX); + BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, fdest, EAX)); + break; + case DILL_L: + case DILL_UL: + case DILL_P: + rex |= REX_W; + case DILL_I: + case DILL_U: + BYTE_OUT2R(s, rex, 0x0f, 0xc8 + (dest & 0x7)); /* byteswap dest */ + break; + case DILL_S: + case DILL_US: + /* byteswap 32 bits and shift down 16 */ + BYTE_OUT2R(s, rex, 0x0f, 0xc8 + (dest & 0x7)); /* byteswap dest */ + x86_64_rshi(s, dest, dest, 16); + break; + case DILL_C: + case DILL_UC: + break; } } @@ -1324,137 +1512,165 @@ static unsigned char st_opcodes[] = { 0x89, /* DILL_EC */ }; extern void -x86_64_pstorei(dill_stream s, int type, int junk, int dest, int src, IMM_TYPE offset) -{ - x86_64_mach_info smi = (x86_64_mach_info) s->p->mach_info; +x86_64_pstorei(dill_stream s, + int type, + int junk, + int dest, + int src, + IMM_TYPE offset) +{ + x86_64_mach_info smi = (x86_64_mach_info)s->p->mach_info; int rex = 0, float_op = 0; if ((type == DILL_L) || (type == DILL_UL) || (type == DILL_P)) { - rex = REX_W; + rex = REX_W; } - switch(type) { - case DILL_C: case DILL_UC: - if (dest >= ESP) { - /* movb doesn't work for big regs, move to eax */ - x86_64_movi(s, EAX, dest); - dest = EAX; - } - break; + switch (type) { + case DILL_C: + case DILL_UC: + if (dest >= ESP) { + /* movb doesn't work for big regs, move to eax */ + x86_64_movi(s, EAX, dest); + dest = EAX; + } + break; } switch (type) { case DILL_F: - float_op = 0xf3; - break; + float_op = 0xf3; + break; case DILL_D: - float_op = 0xf2; - break; - case DILL_S: case DILL_US: - BYTE_OUT1(s, 0x66); - break; + float_op = 0xf2; + break; + case DILL_S: + case DILL_US: + BYTE_OUT1(s, 0x66); + break; default: - break; + break; } if (smi->pending_prefix != 0) { BYTE_OUT1(s, smi->pending_prefix); - smi->pending_prefix = 0; - } - if (dest > RDI) rex |= REX_R; - if (src > RDI) rex |= REX_B; - if (((src&0x7) == ESP) && - (((offset & 0xffffffff80000000) == 0) || - ((offset & 0xffffffff80000000) == 0xffffffff80000000))) { - if (((intptr_t)offset <= 127) && ((intptr_t)offset > -128)) { - if (float_op != 0) { - BYTE_OUT1R5(s, float_op, rex, 0x0f, 0x11, ModRM(0x1, dest, src), SIB(0x0,ESP,0x4), offset & 0xff); - } else { - BYTE_OUT4R(s, rex, st_opcodes[type], ModRM(0x1, dest, src), SIB(0x0,ESP,0x4), offset & 0xff); - } - } else { - if (float_op != 0) { - BYTE_OUT1R4I(s, float_op, rex, 0x0f, 0x11, ModRM(0x2, dest, 0x4), SIB(0,4,src), offset); - } else { - BYTE_OUT3IR(s, rex, st_opcodes[type], ModRM(0x2, dest, 0x4), SIB(0,4,src),offset); - } - } + smi->pending_prefix = 0; + } + if (dest > RDI) + rex |= REX_R; + if (src > RDI) + rex |= REX_B; + if (((src & 0x7) == ESP) && + (((offset & 0xffffffff80000000) == 0) || + ((offset & 0xffffffff80000000) == 0xffffffff80000000))) { + if (((intptr_t)offset <= 127) && ((intptr_t)offset > -128)) { + if (float_op != 0) { + BYTE_OUT1R5(s, float_op, rex, 0x0f, 0x11, ModRM(0x1, dest, src), + SIB(0x0, ESP, 0x4), offset & 0xff); + } else { + BYTE_OUT4R(s, rex, st_opcodes[type], ModRM(0x1, dest, src), + SIB(0x0, ESP, 0x4), offset & 0xff); + } + } else { + if (float_op != 0) { + BYTE_OUT1R4I(s, float_op, rex, 0x0f, 0x11, + ModRM(0x2, dest, 0x4), SIB(0, 4, src), + (int)offset); + } else { + BYTE_OUT3IR(s, rex, st_opcodes[type], ModRM(0x2, dest, 0x4), + SIB(0, 4, src), (int)offset); + } + } } else { - if ((offset == 0) && ((src &0x7) != 5)){ /* avoid discontinuity in ModRM */ - if (float_op != 0) { - BYTE_OUT1R3(s, float_op, rex, 0x0f, 0x11, ModRM(0x0, dest, src)); - } else { - BYTE_OUT2R(s, rex, st_opcodes[type], ModRM(0x0, dest, src)); - } - } else if (((intptr_t)offset <= 127) && ((intptr_t)offset > -128)) { - if (float_op != 0) { - BYTE_OUT1R4(s, float_op, rex, 0x0f, 0x11, ModRM(0x1, dest, src), offset & 0xff); - } else { - BYTE_OUT3R(s, rex, st_opcodes[type], ModRM(0x1, dest, src), offset & 0xff); - } - } else if (((offset & 0xffffffff80000000) == 0) || - ((offset & 0xffffffff80000000) == 0xffffffff80000000)) { - /* safe INT offset using only low 31 bits */ - if (float_op != 0) { - BYTE_OUT1R3I(s, float_op, rex, 0x0f, 0x11, ModRM(0x2, dest, src), offset); - } else { - BYTE_OUT2IR(s, rex, st_opcodes[type], ModRM(0x2, dest, src), offset); - } - } else { - x86_64_push_reg(s, src); - x86_64_arith3i(s, 0, DILL_L, src, src, offset); - x86_64_pstorei(s, type, 0, dest, src, 0); - x86_64_pop_reg(s, src); - } + if ((offset == 0) && + ((src & 0x7) != 5)) { /* avoid discontinuity in ModRM */ + if (float_op != 0) { + BYTE_OUT1R3(s, float_op, rex, 0x0f, 0x11, + ModRM(0x0, dest, src)); + } else { + BYTE_OUT2R(s, rex, st_opcodes[type], ModRM(0x0, dest, src)); + } + } else if (((intptr_t)offset <= 127) && ((intptr_t)offset > -128)) { + if (float_op != 0) { + BYTE_OUT1R4(s, float_op, rex, 0x0f, 0x11, ModRM(0x1, dest, src), + offset & 0xff); + } else { + BYTE_OUT3R(s, rex, st_opcodes[type], ModRM(0x1, dest, src), + offset & 0xff); + } + } else if (((offset & 0xffffffff80000000) == 0) || + ((offset & 0xffffffff80000000) == 0xffffffff80000000)) { + /* safe INT offset using only low 31 bits */ + if (float_op != 0) { + BYTE_OUT1R3I(s, float_op, rex, 0x0f, 0x11, + ModRM(0x2, dest, src), (int)offset); + } else { + BYTE_OUT2IR(s, rex, st_opcodes[type], ModRM(0x2, dest, src), + (int)offset); + } + } else { + x86_64_push_reg(s, src); + x86_64_arith3i(s, 0, DILL_L, src, src, offset); + x86_64_pstorei(s, type, 0, dest, src, 0); + x86_64_pop_reg(s, src); + } } } extern void x86_64_pstore(dill_stream s, int type, int junk, int dest, int src1, int src2) { - x86_64_mach_info smi = (x86_64_mach_info) s->p->mach_info; + x86_64_mach_info smi = (x86_64_mach_info)s->p->mach_info; int rex = 0, float_op = 0; if ((type == DILL_L) || (type == DILL_UL) || (type == DILL_P)) { - rex = REX_W; + rex = REX_W; } switch (type) { case DILL_F: - float_op = 0xf3; - break; + float_op = 0xf3; + break; case DILL_D: - float_op = 0xf2; - break; - case DILL_S: case DILL_US: - BYTE_OUT1(s, 0x66); - break; + float_op = 0xf2; + break; + case DILL_S: + case DILL_US: + BYTE_OUT1(s, 0x66); + break; default: - break; + break; } if (smi->pending_prefix != 0) { BYTE_OUT1(s, smi->pending_prefix); - smi->pending_prefix = 0; - } - if ((src2 & 0x7) == 0x5) { /* avoid SIB discontinuity */ - int tmp = src1; - src1 = src2; - src2 = tmp; - } - if (src1 > RDI) rex |= REX_X; - if (src2 > RDI) rex |= REX_B; - if (dest > RDI) rex |= REX_R; + smi->pending_prefix = 0; + } + if ((src2 & 0x7) == 0x5) { /* avoid SIB discontinuity */ + int tmp = src1; + src1 = src2; + src2 = tmp; + } + if (src1 > RDI) + rex |= REX_X; + if (src2 > RDI) + rex |= REX_B; + if (dest > RDI) + rex |= REX_R; if (float_op != 0) { - BYTE_OUT1R4(s, float_op, rex, 0x0f, 0x11, ModRM(0x0, dest, 0x4), SIB(0,src1,src2)); + BYTE_OUT1R4(s, float_op, rex, 0x0f, 0x11, ModRM(0x0, dest, 0x4), + SIB(0, src1, src2)); } else { - BYTE_OUT3R(s, rex, st_opcodes[type], ModRM(0x0, dest, 0x4), SIB(0,src1,src2)); + BYTE_OUT3R(s, rex, st_opcodes[type], ModRM(0x0, dest, 0x4), + SIB(0, src1, src2)); } } -extern double dill_x86_64_hidden_ULtoD(unsigned long a); -extern unsigned long dill_x86_64_hidden_DtoUL(double a); +extern double +dill_x86_64_hidden_ULtoD(size_t a); +extern size_t +dill_x86_64_hidden_DtoUL(double a); -extern void x86_64_div(dill_stream s, int op3, int op, int dest, int src1, - int src2) +extern void +x86_64_div(dill_stream s, int op3, int op, int dest, int src1, int src2) { } -extern void x86_64_divi(dill_stream s, int op3, int op, int dest, int src, - IMM_TYPE imm) +extern void +x86_64_divi(dill_stream s, int op3, int op, int dest, int src, IMM_TYPE imm) { } @@ -1464,182 +1680,198 @@ x86_64_mov(dill_stream s, int type, int junk, int dest, int src) x86_64_pmov(s, type, dest, src); } -extern void x86_64_arith3(s, op, typ, dest, src1, src2) -dill_stream s; -int op; -int typ; -int dest; -int src1; -int src2; +extern void +x86_64_arith3(dill_stream s, int op, int typ, int dest, int src1, int src2) { - int commut = ( op != 0x2b); /* subtract not commutative */ + int commut = (op != 0x2b); /* subtract not commutative */ int rex = 0; if ((typ == DILL_L) || (typ == DILL_UL) || (typ == DILL_P)) { - rex = REX_W; + rex = REX_W; } if (commut && (dest == src1)) { - if (dest > RDI) rex |= REX_R; - if (src2 > RDI) rex |= REX_B; - BYTE_OUT2R(s, rex, op, ModRM(0x3, dest, src2)); + if (dest > RDI) + rex |= REX_R; + if (src2 > RDI) + rex |= REX_B; + BYTE_OUT2R(s, rex, op, ModRM(0x3, dest, src2)); } else if (commut && (dest == src2)) { - if (dest > RDI) rex |= REX_R; - if (src1 > RDI) rex |= REX_B; - BYTE_OUT2R(s, rex, op, ModRM(0x3, dest, src1)); + if (dest > RDI) + rex |= REX_R; + if (src1 > RDI) + rex |= REX_B; + BYTE_OUT2R(s, rex, op, ModRM(0x3, dest, src1)); } else if (dest == src2) { - assert(op == 0x2b); /* must be subtract */ - int rex1 = rex, rex2 = rex; - if (dest > RDI) rex1 |= REX_B; - BYTE_OUT2R(s, rex1, 0xf7, ModRM(0x3, 0x3, dest)); /* neg src2/dest */ - if (dest > RDI) rex2 |= REX_R; - if (src1 > RDI) rex2 |= REX_B; - BYTE_OUT2R(s, rex2, 0x03, ModRM(0x3, dest, src1)); /* add src1, dest */ + assert(op == 0x2b); /* must be subtract */ + int rex1 = rex, rex2 = rex; + if (dest > RDI) + rex1 |= REX_B; + BYTE_OUT2R(s, rex1, 0xf7, ModRM(0x3, 0x3, dest)); /* neg src2/dest */ + if (dest > RDI) + rex2 |= REX_R; + if (src1 > RDI) + rex2 |= REX_B; + BYTE_OUT2R(s, rex2, 0x03, ModRM(0x3, dest, src1)); /* add src1, dest */ } else { - int rex1 = rex, rex2 = rex; - if (dest > RDI) rex1 |= REX_B; - if (src1 > RDI) rex1 |= REX_R; - BYTE_OUT2R(s, rex1, MOV32, ModRM(0x3, src1, dest)); - if (src2 > RDI) rex2 |= REX_B; - if (dest > RDI) rex2 |= REX_R; - BYTE_OUT2R(s, rex2, op, ModRM(0x3, dest, src2)); + int rex1 = rex, rex2 = rex; + if (dest > RDI) + rex1 |= REX_B; + if (src1 > RDI) + rex1 |= REX_R; + BYTE_OUT2R(s, rex1, MOV32, ModRM(0x3, src1, dest)); + if (src2 > RDI) + rex2 |= REX_B; + if (dest > RDI) + rex2 |= REX_R; + BYTE_OUT2R(s, rex2, op, ModRM(0x3, dest, src2)); } } -extern void x86_64_arith2(s, op, subop, dest, src) -dill_stream s; -int op; -int subop; -int dest; -int src; +extern void +x86_64_arith2(dill_stream s, int op, int subop, int dest, int src) { if (op == 0) { - int tmp_dest = dest; - int rex1 = REX_W, rex2 = REX_W; - /* must be not */ - if (dest >= ESP) { - tmp_dest = EAX; - } - if (src > RDI) rex1 |= REX_B; - BYTE_OUT3R(s, rex1, 0x83, ModRM(0x3, 0x7, src), 0); /* cmp */ - x86_64_seti(s, tmp_dest, 0); - if (src > RDI) rex2 |= REX_R; - if (tmp_dest > RDI) rex2 |= REX_B; - BYTE_OUT3R(s, rex2, 0x0f, 0x94, ModRM(0x3, src, tmp_dest)); /* sete dest */ - if (tmp_dest != dest) { - x86_64_movi(s, dest, tmp_dest); - } + int tmp_dest = dest; + int rex1 = REX_W, rex2 = REX_W; + /* must be not */ + if (dest >= ESP) { + tmp_dest = EAX; + } + if (src > RDI) + rex1 |= REX_B; + BYTE_OUT3R(s, rex1, 0x83, ModRM(0x3, 0x7, src), 0); /* cmp */ + x86_64_seti(s, tmp_dest, 0); + if (src > RDI) + rex2 |= REX_R; + if (tmp_dest > RDI) + rex2 |= REX_B; + BYTE_OUT3R(s, rex2, 0x0f, 0x94, + ModRM(0x3, src, tmp_dest)); /* sete dest */ + if (tmp_dest != dest) { + x86_64_movi(s, dest, tmp_dest); + } } else { - int rex = REX_W; - if (src != dest) { - int rex1 = rex; - if (dest > RDI) rex1 |= REX_B; - if (src > RDI) rex1 |= REX_R; - BYTE_OUT2R(s, rex1, MOV32, ModRM(0x3, src, dest)); - } - if (dest > RDI) rex |= REX_B; - BYTE_OUT2R(s, rex, op, ModRM(0x3, subop, dest)); + int rex = REX_W; + if (src != dest) { + int rex1 = rex; + if (dest > RDI) + rex1 |= REX_B; + if (src > RDI) + rex1 |= REX_R; + BYTE_OUT2R(s, rex1, MOV32, ModRM(0x3, src, dest)); + } + if (dest > RDI) + rex |= REX_B; + BYTE_OUT2R(s, rex, op, ModRM(0x3, subop, dest)); } } -extern void x86_64_bswap(s, junk, typ, dest, src) -dill_stream s; -int junk; -int typ; -int dest; -int src; +extern void +x86_64_bswap(dill_stream s, int junk, int typ, int dest, int src) { int rex = 0; - switch(typ) { - case DILL_F: - rex = 0; - if (dest > RDI) rex |= REX_R; - BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x7e, ModRM(0x3, src, EAX)); - x86_64_bswap(s, 0, DILL_I, EAX, EAX); - BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, dest, EAX)); - break; + switch (typ) { + case DILL_F: + rex = 0; + if (dest > RDI) + rex |= REX_R; + BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x7e, ModRM(0x3, src, EAX)); + x86_64_bswap(s, 0, DILL_I, EAX, EAX); + BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, dest, EAX)); + break; case DILL_D: - rex = REX_W; - if (dest > RDI) rex |= REX_R; - BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x7e, ModRM(0x3, src, EAX)); - x86_64_bswap(s, 0, DILL_L, EAX, EAX); - BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, dest, EAX)); - break; - case DILL_L: case DILL_UL: case DILL_P: - rex |= REX_W; - case DILL_I: case DILL_U: - if (dest > RDI) rex |= REX_B; - if (dest != src) { - x86_64_movl(s, dest, src); - } - BYTE_OUT2R(s, rex, 0x0f, 0xc8 + (dest&0x7)); /* byteswap dest */ - break; - case DILL_S: case DILL_US: - if (dest > RDI) rex |= REX_B; - if (dest != src) { - x86_64_movl(s, dest, src); - } - /* byteswap 32 bits and shift down 16 */ - BYTE_OUT2R(s, rex, 0x0f, 0xc8 + (dest&0x7)); /* byteswap dest */ - x86_64_rshi(s, dest, dest, 16); - break; - case DILL_C: case DILL_UC: - break; - } -} - -extern void x86_64_mul(s, sign, imm, dest, src1, src2) -dill_stream s; -int sign; -int imm; -int dest; -int src1; -IMM_TYPE src2; -{ + rex = REX_W; + if (dest > RDI) + rex |= REX_R; + BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x7e, ModRM(0x3, src, EAX)); + x86_64_bswap(s, 0, DILL_L, EAX, EAX); + BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, dest, EAX)); + break; + case DILL_L: + case DILL_UL: + case DILL_P: + rex |= REX_W; + case DILL_I: + case DILL_U: + if (dest > RDI) + rex |= REX_B; + if (dest != src) { + x86_64_movl(s, dest, src); + } + BYTE_OUT2R(s, rex, 0x0f, 0xc8 + (dest & 0x7)); /* byteswap dest */ + break; + case DILL_S: + case DILL_US: + if (dest > RDI) + rex |= REX_B; + if (dest != src) { + x86_64_movl(s, dest, src); + } + /* byteswap 32 bits and shift down 16 */ + BYTE_OUT2R(s, rex, 0x0f, 0xc8 + (dest & 0x7)); /* byteswap dest */ + x86_64_rshi(s, dest, dest, 16); + break; + case DILL_C: + case DILL_UC: + break; + } +} + +extern void +x86_64_mul(dill_stream s, + int sign, + int imm, + int dest, + int src1, + IMM_TYPE imm_src2) +{ + int src2 = (int)imm_src2; int rex = REX_W; /* make src1 be EAX */ if (dest != EAX) { - x86_64_push_reg(s, EAX); + x86_64_push_reg(s, EAX); } if (dest != EDX) { - x86_64_push_reg(s, EDX); + x86_64_push_reg(s, EDX); } - - if ((src2 == EAX) && !imm){ - int tmp = src2; - src1 = src2; - src2 = tmp; + + if ((src2 == EAX) && !imm) { + int tmp = src2; + src1 = src2; + src2 = tmp; } if (src1 != EAX) { - x86_64_movl(s, EAX, src1); + x86_64_movl(s, EAX, src1); } if (imm == 0) { - if (src2 > RDI) rex |= REX_B; - BYTE_OUT2R(s, rex, 0xf7, ModRM(0x3, sign ? 0x5 : 0x4, src2)); + if (src2 > RDI) + rex |= REX_B; + BYTE_OUT2R(s, rex, 0xf7, ModRM(0x3, sign ? 0x5 : 0x4, src2)); } else { - /* src2 is really immediate */ - if (sign && ((src2 & 0xffffffff80000000) == 0)) { - BYTE_OUT2IR(s, rex, 0x69, ModRM(0x3, 0, EAX), src2); - } else { - x86_64_setl(s, EDX, src2); - BYTE_OUT2R(s, rex, 0xf7, ModRM(0x3, 0x4, EDX)); - } + /* src2 is really immediate */ + if (sign && ((imm_src2 & 0xffffffff80000000) == 0)) { + BYTE_OUT2IR(s, rex, 0x69, ModRM(0x3, 0, EAX), (int)imm_src2); + } else { + x86_64_setl(s, EDX, imm_src2); + BYTE_OUT2R(s, rex, 0xf7, ModRM(0x3, 0x4, EDX)); + } } if (dest != EDX) { - x86_64_pop_reg(s, EDX); + x86_64_pop_reg(s, EDX); } if (dest != EAX) { - x86_64_movl(s, dest, EAX); - x86_64_pop_reg(s, EAX); + x86_64_movl(s, dest, EAX); + x86_64_pop_reg(s, EAX); } } -extern void x86_64_div_modi(s, div, type, dest, src1, imm) -dill_stream s; -int div; -int type; -int dest; -int src1; -IMM_TYPE imm; +extern void +x86_64_div_modi(dill_stream s, + int div, + int type, + int dest, + int src1, + IMM_TYPE imm) { x86_64_push_reg(s, EBP); x86_64_setl(s, EBP, imm); @@ -1647,332 +1879,334 @@ IMM_TYPE imm; x86_64_pop_reg(s, EBP); } -extern void x86_64_div_mod(s, div, type, dest, src1, src2) -dill_stream s; -int div; -int type; -int dest; -int src1; -int src2; +extern void +x86_64_div_mod(dill_stream s, int div, int type, int dest, int src1, int src2) { int tmp_src2 = src2; int rex = 0; int sign = ((type == DILL_I) || (type == DILL_L)); - + if ((type == DILL_UL) || (type == DILL_L)) { - rex = REX_W; + rex = REX_W; } - /* Well, this is awkward. divi must use EDX and EAX for src1, destroying both */ + /* Well, this is awkward. divi must use EDX and EAX for src1, destroying + * both */ /* save eax and edx, (unless one is the dest) */ if (dest != EAX) { - x86_64_push_reg(s, EAX); + x86_64_push_reg(s, EAX); } if (dest != EDX) { - x86_64_push_reg(s, EDX); + x86_64_push_reg(s, EDX); } if ((src2 == EAX) || (src2 == EDX)) { - /* we'll move src2 to EBP */ - tmp_src2 = EBP; - x86_64_push_reg(s, EBP); - x86_64_movl(s, EBP, src2); + /* we'll move src2 to EBP */ + tmp_src2 = EBP; + x86_64_push_reg(s, EBP); + x86_64_movl(s, EBP, src2); } if (src1 != EAX) { - x86_64_movl(s, EAX, src1); + x86_64_movl(s, EAX, src1); } if (type == DILL_I) { - BYTE_OUT1(s, 0x99); /* cltd (altern cdq) */ -/* rex |= REX_W;*/ + BYTE_OUT1(s, 0x99); /* cltd (altern cdq) */ + /* rex |= REX_W;*/ } else if (sign) { - x86_64_rshai(s, EDX, EAX, 63); -/* x86_64_movl(s, EDX, EAX);*/ + x86_64_rshai(s, EDX, EAX, 63); + /* x86_64_movl(s, EDX, EAX);*/ } else { - x86_64_clear(s, EDX); + x86_64_clear(s, EDX); } - if (tmp_src2 > RDI) rex |= REX_B; + if (tmp_src2 > RDI) + rex |= REX_B; BYTE_OUT2R(s, rex, 0xf7, ModRM(0x3, sign ? 0x7 : 0x6, tmp_src2)); if ((src2 == EDX) || (src2 == EAX)) { - x86_64_pop_reg(s, EBP); + x86_64_pop_reg(s, EBP); } if (div && (dest != EAX)) { - x86_64_movl(s, dest, EAX); + x86_64_movl(s, dest, EAX); } if (!div && (dest != EDX)) { - x86_64_movl(s, dest, EDX); + x86_64_movl(s, dest, EDX); } if (dest != EDX) { - x86_64_pop_reg(s, EDX); + x86_64_pop_reg(s, EDX); } if (dest != EAX) { - x86_64_pop_reg(s, EAX); + x86_64_pop_reg(s, EAX); } - } static int group1_eax_op[] = { - 0x05 /* add */, - 0x0d /* or */, - 0x15 /* adc */, - 0x1d /* sbb */, - 0x25 /* and */, - 0x2d /* sub */, - 0x35 /* xor */, - 0x3d /* cmp */ + 0x05 /* add */, 0x0d /* or */, 0x15 /* adc */, 0x1d /* sbb */, + 0x25 /* and */, 0x2d /* sub */, 0x35 /* xor */, 0x3d /* cmp */ }; -extern void x86_64_arith3i(s, op, typ, dest, src, imm) -dill_stream s; -int op; -int typ; -int dest; -int src; -IMM_TYPE imm; +extern void +x86_64_arith3i(dill_stream s, int op, int typ, int dest, int src, IMM_TYPE imm) { int rex = 0; if ((typ == DILL_L) || (typ == DILL_UL) || (typ == DILL_P)) { - rex = REX_W; + rex = REX_W; } if (dest != src) { - int rex1 = rex; - if (dest > RDI) rex1 |= REX_B; - if (src > RDI) rex1 |= REX_R; - BYTE_OUT2R(s, rex1, MOV32, ModRM(0x3, src, dest)); + int rex1 = rex; + if (dest > RDI) + rex1 |= REX_B; + if (src > RDI) + rex1 |= REX_R; + BYTE_OUT2R(s, rex1, MOV32, ModRM(0x3, src, dest)); } if ((imm <= 127) && (imm > -128)) { - int rex1 = rex; - if (dest > RDI) rex1 |= REX_B; - BYTE_OUT3R(s, rex1, 0x83, ModRM(0x3, op, dest), imm & 0xff); - return; + int rex1 = rex; + if (dest > RDI) + rex1 |= REX_B; + BYTE_OUT3R(s, rex1, 0x83, ModRM(0x3, op, dest), imm & 0xff); + return; } if ((0xffffffff80000000 & imm) == 0) { - /* int-sized immediate */ - if (dest == EAX) { - BYTE_OUT1IR(s, rex, group1_eax_op[op], imm); - } else { - int rex2 = rex; - if (dest > RDI) rex2 |= REX_B; - BYTE_OUT2IR(s, rex2, 0x81, ModRM(0x3, op, dest), imm); - } + /* int-sized immediate */ + if (dest == EAX) { + BYTE_OUT1IR(s, rex, group1_eax_op[op], (int)imm); + } else { + int rex2 = rex; + if (dest > RDI) + rex2 |= REX_B; + BYTE_OUT2IR(s, rex2, 0x81, ModRM(0x3, op, dest), (int)imm); + } } else { - int tmp_reg = dest; - if (src == dest) { - if (src == EAX) { - tmp_reg = R11; - } else { - tmp_reg = EAX; - } - x86_64_push_reg(s, tmp_reg); - } - x86_64_pset(s, typ, 0, tmp_reg, imm); - switch(op) { - case 0: /* add */ op = 0x03; /* reg to reg */ break; - case 5: /* sub */ op = 0x2b; /* reg to reg */ break; - case 4: /* and */ op = 0x23; /* reg to reg */ break; - case 1: /* or */ op = 0x0b; /* reg to reg */ break; - case 6: /* xor */ op = 0x33; /* reg to reg */ break; - } - x86_64_arith3(s, op, typ, dest, src, tmp_reg); - if (src == dest) { - x86_64_pop_reg(s, tmp_reg); - } - } -} - -extern void x86_64_shift(s, op, type, dest, src1, src2) -dill_stream s; -int op; -int type; -int dest; -int src1; -int src2; + int tmp_reg = dest; + if (src == dest) { + if (src == EAX) { + tmp_reg = R11; + } else { + tmp_reg = EAX; + } + x86_64_push_reg(s, tmp_reg); + } + x86_64_pset(s, typ, 0, tmp_reg, imm); + switch (op) { + case 0: /* add */ + op = 0x03; /* reg to reg */ + break; + case 5: /* sub */ + op = 0x2b; /* reg to reg */ + break; + case 4: /* and */ + op = 0x23; /* reg to reg */ + break; + case 1: /* or */ + op = 0x0b; /* reg to reg */ + break; + case 6: /* xor */ + op = 0x33; /* reg to reg */ + break; + } + x86_64_arith3(s, op, typ, dest, src, tmp_reg); + if (src == dest) { + x86_64_pop_reg(s, tmp_reg); + } + } +} + +extern void +x86_64_shift(dill_stream s, int op, int type, int dest, int src1, int src2) { int tmp_dest = dest; int rex = 0; if ((type == DILL_L) || (type == DILL_UL) || (type == DILL_P)) { - rex = REX_W; + rex = REX_W; } if ((dest == ECX) || (dest == src2)) { - x86_64_push_reg(s, EAX); - tmp_dest = EAX; + x86_64_push_reg(s, EAX); + tmp_dest = EAX; } if (tmp_dest != src1) { - x86_64_movl(s, tmp_dest, src1); + x86_64_movl(s, tmp_dest, src1); } if (src2 != ECX) { - x86_64_push_reg(s, ECX); - x86_64_movl(s, ECX, src2); + x86_64_push_reg(s, ECX); + x86_64_movl(s, ECX, src2); } - if (tmp_dest > RDI) rex |= REX_B; + if (tmp_dest > RDI) + rex |= REX_B; BYTE_OUT2R(s, rex, 0xd3, ModRM(0x3, op, tmp_dest)); if (src2 != ECX) { - x86_64_pop_reg(s, ECX); + x86_64_pop_reg(s, ECX); } if ((dest == ECX) || (dest == src2)) { - x86_64_movl(s, dest, tmp_dest); - x86_64_pop_reg(s, EAX); + x86_64_movl(s, dest, tmp_dest); + x86_64_pop_reg(s, EAX); } } -extern void x86_64_shifti(s, op, type, dest, src, imm) -dill_stream s; -int op; -int type; -int dest; -int src; -IMM_TYPE imm; +extern void +x86_64_shifti(dill_stream s, int op, int type, int dest, int src, IMM_TYPE imm) { int rex = 0; if ((type == DILL_L) || (type == DILL_UL) || (type == DILL_P)) { - rex = REX_W; + rex = REX_W; } if (dest != src) { - x86_64_movl(s, dest, src); + x86_64_movl(s, dest, src); } - if (dest > RDI) rex |= REX_B; + if (dest > RDI) + rex |= REX_B; BYTE_OUT3R(s, rex, 0xc1, ModRM(0x3, op, dest), imm & 0xff); } -#define CONV(x,y) ((x*100)+y) +#define CONV(x, y) ((x * 100) + y) extern void -x86_64_convert(dill_stream s, int from_type, int to_type, - int dest, int src) +x86_64_convert(dill_stream s, int from_type, int to_type, int dest, int src) { - switch(CONV(from_type, to_type)) { + switch (CONV(from_type, to_type)) { case CONV(DILL_I, DILL_L): - case CONV(DILL_L,DILL_I): - case CONV(DILL_I,DILL_UL): - /* signext24 - lsh32, rsha32 */ - x86_64_lshi(s, dest, src, 32); - x86_64_rshai(s, dest, dest, 32); - break; - case CONV(DILL_U,DILL_I): - case CONV(DILL_U,DILL_UL): - case CONV(DILL_U,DILL_L): + case CONV(DILL_L, DILL_I): + case CONV(DILL_I, DILL_UL): + /* signext24 - lsh32, rsha32 */ + x86_64_lshi(s, dest, src, 32); + x86_64_rshai(s, dest, dest, 32); + break; + case CONV(DILL_U, DILL_I): + case CONV(DILL_U, DILL_UL): + case CONV(DILL_U, DILL_L): case CONV(DILL_I, DILL_U): - case CONV(DILL_UL,DILL_U): - case CONV(DILL_L,DILL_U): - /* clear upper 32 - lsh32, rsh32 */ - x86_64_lshi(s, dest, src, 32); - x86_64_rshi(s, dest, dest, 32); - break; - case CONV(DILL_UL,DILL_I): - case CONV(DILL_UL,DILL_L): - case CONV(DILL_L,DILL_UL): - case CONV(DILL_P,DILL_UL): - case CONV(DILL_UL,DILL_P): - if(src == dest) return; - x86_64_movl(s, dest,src); - break; - case CONV(DILL_D,DILL_F): - case CONV(DILL_F,DILL_D): - /* cvtss2sd */ - /* cvtsd2ss */ - { - int rex = 0; - /* cvts{d,s}2s{s,d} */ - if (src > RDI) rex |= REX_B; - if (dest > RDI) rex |= REX_R; - BYTE_OUT1R3(s, (from_type == DILL_D) ? 0xf2 : 0xf3, rex, 0xf, 0x5a, ModRM(0x3, dest, src)); - break; - } - case CONV(DILL_F,DILL_U): - case CONV(DILL_F,DILL_UL): - case CONV(DILL_F,DILL_US): - case CONV(DILL_F,DILL_UC): - case CONV(DILL_D,DILL_U): - case CONV(DILL_D,DILL_UL): - case CONV(DILL_D,DILL_US): - case CONV(DILL_D,DILL_UC): - { - int return_reg; - if (from_type == DILL_F) { - x86_64_convert(s, DILL_F, DILL_D, XMM0, src); - src = XMM0; - } - return_reg = dill_scallul(s, (void*)dill_x86_64_hidden_DtoUL, "dill_x86_64_hidden_DtoUL", "%d", src); - if (to_type == DILL_U) { - x86_64_lshi(s, dest, return_reg, 32); - x86_64_rshi(s, dest, dest, 32); - } else { - x86_64_pmov(s, to_type, dest, return_reg); - } - break; - } - case CONV(DILL_F,DILL_I): - case CONV(DILL_F,DILL_L): - case CONV(DILL_F,DILL_S): - case CONV(DILL_F,DILL_C): - case CONV(DILL_D,DILL_I): - case CONV(DILL_D,DILL_L): - case CONV(DILL_D,DILL_S): - case CONV(DILL_D,DILL_C): - { - int rex = 0; - /* cvttsd2si */ - if (to_type == DILL_L) rex = REX_W; - if (src > RDI) rex |= REX_B; - if (dest > RDI) rex |= REX_R; - BYTE_OUT1R3(s, (from_type == DILL_D) ? 0xf2 : 0xf3, rex, 0xf, 0x2c, ModRM(0x3, dest, src)); - break; - } - case CONV(DILL_I,DILL_D): - case CONV(DILL_I,DILL_F): - case CONV(DILL_S,DILL_D): - case CONV(DILL_S,DILL_F): - case CONV(DILL_C,DILL_D): - case CONV(DILL_C,DILL_F): - { - int rex = 0; - /* cvtsi2s{s,d} */ - if (src > RDI) rex |= REX_B; - if (dest > RDI) rex |= REX_R; - BYTE_OUT1R3(s, (to_type == DILL_D) ? 0xf2 : 0xf3, rex, 0xf, 0x2a, ModRM(0x3, dest, src)); - break; - } - case CONV(DILL_L,DILL_F): - case CONV(DILL_L,DILL_D): - case CONV(DILL_U,DILL_D): - case CONV(DILL_U,DILL_F): - case CONV(DILL_US,DILL_D): - case CONV(DILL_US,DILL_F): - case CONV(DILL_UC,DILL_D): - case CONV(DILL_UC,DILL_F): - { - int rex = REX_W; - /* cvtsi2s{s,d} */ - if (src > RDI) rex |= REX_B; - if (dest > RDI) rex |= REX_R; - BYTE_OUT1R3(s, (to_type == DILL_D) ? 0xf2 : 0xf3, rex, 0xf, 0x2a, ModRM(0x3, dest, src)); - break; - } - case CONV(DILL_UL,DILL_D): - case CONV(DILL_UL,DILL_F): - { - int return_reg = dill_scalld(s, (void*)dill_x86_64_hidden_ULtoD, "dill_x86_64_hidden_ULtoD", "%l", src); - if (to_type == DILL_F) { - BYTE_OUT1R3(s, 0xf2, 0, 0xf, 0x5a, ModRM(0x3, return_reg, return_reg)); - } - x86_64_pmov(s, to_type, dest, return_reg); - break; - } - case CONV(DILL_C,DILL_I): - case CONV(DILL_C,DILL_L): - case CONV(DILL_C,DILL_U): - case CONV(DILL_C,DILL_UL): - case CONV(DILL_C,DILL_S): - case CONV(DILL_S,DILL_C): - case CONV(DILL_US,DILL_C): - /* signext56 - lsh56, rsha56 */ - x86_64_lshi(s, dest, src, 56); - x86_64_rshai(s, dest, dest, 56); - break; + case CONV(DILL_UL, DILL_U): + case CONV(DILL_L, DILL_U): + /* clear upper 32 - lsh32, rsh32 */ + x86_64_lshi(s, dest, src, 32); + x86_64_rshi(s, dest, dest, 32); + break; + case CONV(DILL_UL, DILL_I): + case CONV(DILL_UL, DILL_L): + case CONV(DILL_L, DILL_UL): + case CONV(DILL_P, DILL_UL): + case CONV(DILL_UL, DILL_P): + if (src == dest) + return; + x86_64_movl(s, dest, src); + break; + case CONV(DILL_D, DILL_F): + case CONV(DILL_F, DILL_D): + /* cvtss2sd */ + /* cvtsd2ss */ + { + int rex = 0; + /* cvts{d,s}2s{s,d} */ + if (src > RDI) + rex |= REX_B; + if (dest > RDI) + rex |= REX_R; + BYTE_OUT1R3(s, (from_type == DILL_D) ? 0xf2 : 0xf3, rex, 0xf, 0x5a, + ModRM(0x3, dest, src)); + break; + } + case CONV(DILL_F, DILL_U): + case CONV(DILL_F, DILL_UL): + case CONV(DILL_F, DILL_US): + case CONV(DILL_F, DILL_UC): + case CONV(DILL_D, DILL_U): + case CONV(DILL_D, DILL_UL): + case CONV(DILL_D, DILL_US): + case CONV(DILL_D, DILL_UC): { + int return_reg; + if (from_type == DILL_F) { + x86_64_convert(s, DILL_F, DILL_D, XMM0, src); + src = XMM0; + } + return_reg = dill_scallul(s, (void*)dill_x86_64_hidden_DtoUL, + "dill_x86_64_hidden_DtoUL", "%d", src); + if (to_type == DILL_U) { + x86_64_lshi(s, dest, return_reg, 32); + x86_64_rshi(s, dest, dest, 32); + } else { + x86_64_pmov(s, to_type, dest, return_reg); + } + break; + } + case CONV(DILL_F, DILL_I): + case CONV(DILL_F, DILL_L): + case CONV(DILL_F, DILL_S): + case CONV(DILL_F, DILL_C): + case CONV(DILL_D, DILL_I): + case CONV(DILL_D, DILL_L): + case CONV(DILL_D, DILL_S): + case CONV(DILL_D, DILL_C): { + int rex = 0; + /* cvttsd2si */ + if (to_type == DILL_L) + rex = REX_W; + if (src > RDI) + rex |= REX_B; + if (dest > RDI) + rex |= REX_R; + BYTE_OUT1R3(s, (from_type == DILL_D) ? 0xf2 : 0xf3, rex, 0xf, 0x2c, + ModRM(0x3, dest, src)); + break; + } + case CONV(DILL_I, DILL_D): + case CONV(DILL_I, DILL_F): + case CONV(DILL_S, DILL_D): + case CONV(DILL_S, DILL_F): + case CONV(DILL_C, DILL_D): + case CONV(DILL_C, DILL_F): { + int rex = 0; + /* cvtsi2s{s,d} */ + if (src > RDI) + rex |= REX_B; + if (dest > RDI) + rex |= REX_R; + BYTE_OUT1R3(s, (to_type == DILL_D) ? 0xf2 : 0xf3, rex, 0xf, 0x2a, + ModRM(0x3, dest, src)); + break; + } + case CONV(DILL_L, DILL_F): + case CONV(DILL_L, DILL_D): + case CONV(DILL_U, DILL_D): + case CONV(DILL_U, DILL_F): + case CONV(DILL_US, DILL_D): + case CONV(DILL_US, DILL_F): + case CONV(DILL_UC, DILL_D): + case CONV(DILL_UC, DILL_F): { + int rex = REX_W; + /* cvtsi2s{s,d} */ + if (src > RDI) + rex |= REX_B; + if (dest > RDI) + rex |= REX_R; + BYTE_OUT1R3(s, (to_type == DILL_D) ? 0xf2 : 0xf3, rex, 0xf, 0x2a, + ModRM(0x3, dest, src)); + break; + } + case CONV(DILL_UL, DILL_D): + case CONV(DILL_UL, DILL_F): { + int return_reg = dill_scalld(s, (void*)dill_x86_64_hidden_ULtoD, + "dill_x86_64_hidden_ULtoD", "%l", src); + if (to_type == DILL_F) { + BYTE_OUT1R3(s, 0xf2, 0, 0xf, 0x5a, + ModRM(0x3, return_reg, return_reg)); + } + x86_64_pmov(s, to_type, dest, return_reg); + break; + } + case CONV(DILL_C, DILL_I): + case CONV(DILL_C, DILL_L): + case CONV(DILL_C, DILL_U): + case CONV(DILL_C, DILL_UL): + case CONV(DILL_C, DILL_S): + case CONV(DILL_S, DILL_C): + case CONV(DILL_US, DILL_C): + /* signext56 - lsh56, rsha56 */ + x86_64_lshi(s, dest, src, 56); + x86_64_rshai(s, dest, dest, 56); + break; case CONV(DILL_C, DILL_US): - /* signext56 - lsh56, rsha56 */ - x86_64_lshi(s, dest, src, 56); - x86_64_rshai(s, dest, dest, 56); - x86_64_andi(s, dest, dest, 0xffff); - break; + /* signext56 - lsh56, rsha56 */ + x86_64_lshi(s, dest, src, 56); + x86_64_rshai(s, dest, dest, 56); + x86_64_andi(s, dest, dest, 0xffff); + break; case CONV(DILL_I, DILL_C): case CONV(DILL_U, DILL_C): case CONV(DILL_L, DILL_C): @@ -1984,22 +2218,22 @@ x86_64_convert(dill_stream s, int from_type, int to_type, case CONV(DILL_L, DILL_UC): case CONV(DILL_UL, DILL_UC): case CONV(DILL_US, DILL_UC): - x86_64_andi(s, dest, src, 0xff); - break; - case CONV(DILL_S,DILL_I): - case CONV(DILL_S,DILL_L): - case CONV(DILL_S,DILL_U): - case CONV(DILL_S,DILL_UL): - case CONV(DILL_S,DILL_US): - case CONV(DILL_US,DILL_S): - /* signext48 - lsh48, rsha48 */ - x86_64_lshi(s, dest, src, 48); - x86_64_rshai(s, dest, dest, 48); - break; - case CONV(DILL_US,DILL_I): - case CONV(DILL_US,DILL_L): - case CONV(DILL_US,DILL_U): - case CONV(DILL_US,DILL_UL): + x86_64_andi(s, dest, src, 0xff); + break; + case CONV(DILL_S, DILL_I): + case CONV(DILL_S, DILL_L): + case CONV(DILL_S, DILL_U): + case CONV(DILL_S, DILL_UL): + case CONV(DILL_S, DILL_US): + case CONV(DILL_US, DILL_S): + /* signext48 - lsh48, rsha48 */ + x86_64_lshi(s, dest, src, 48); + x86_64_rshai(s, dest, dest, 48); + break; + case CONV(DILL_US, DILL_I): + case CONV(DILL_US, DILL_L): + case CONV(DILL_US, DILL_U): + case CONV(DILL_US, DILL_UL): case CONV(DILL_I, DILL_S): case CONV(DILL_U, DILL_S): case CONV(DILL_L, DILL_S): @@ -2008,337 +2242,416 @@ x86_64_convert(dill_stream s, int from_type, int to_type, case CONV(DILL_U, DILL_US): case CONV(DILL_L, DILL_US): case CONV(DILL_UL, DILL_US): - /* zero uppper 48 - lsh48, rsh48 */ - x86_64_lshi(s, dest, src, 48); - x86_64_rshi(s, dest, dest, 48); - break; + /* zero uppper 48 - lsh48, rsh48 */ + x86_64_lshi(s, dest, src, 48); + x86_64_rshi(s, dest, dest, 48); + break; default: - printf("Unknown case in x86_64 convert %d\n", CONV(from_type,to_type)); + printf("Unknown case in x86_64 convert %d\n", CONV(from_type, to_type)); } } static unsigned char op_conds[] = { - 0x84, /* dill_beq_code */ /* signed */ - 0x8d, /* dill_bge_code */ - 0x8F, /* dill_bgt_code */ - 0x8e, /* dill_ble_code */ - 0x8c, /* dill_blt_code */ - 0x85, /* dill_bne_code */ - - 0x84, /* dill_beq_code */ /* unsigned */ - 0x83, /* dill_bge_code */ - 0x87, /* dill_bgt_code */ - 0x86, /* dill_ble_code */ - 0x82, /* dill_blt_code */ - 0x85, /* dill_bne_code */ + 0x84, + /* dill_beq_code */ /* signed */ + 0x8d, /* dill_bge_code */ + 0x8F, /* dill_bgt_code */ + 0x8e, /* dill_ble_code */ + 0x8c, /* dill_blt_code */ + 0x85, /* dill_bne_code */ + + 0x84, + /* dill_beq_code */ /* unsigned */ + 0x83, /* dill_bge_code */ + 0x87, /* dill_bgt_code */ + 0x86, /* dill_ble_code */ + 0x82, /* dill_blt_code */ + 0x85, /* dill_bne_code */ }; static unsigned char fop_conds[] = { - 0x84, /* dill_beq_code */ /* z = 1*/ - 0x86, /* dill_bge_code */ /* jna */ - 0x82, /* dill_bgt_code */ - 0x83, /* dill_ble_code */ /* c = 0 */ - 0x87, /* dill_blt_code */ - 0x85, /* dill_bne_code */ + 0x84, + /* dill_beq_code */ /* z = 1*/ + 0x86, + /* dill_bge_code */ /* jna */ + 0x82, /* dill_bgt_code */ + 0x83, + /* dill_ble_code */ /* c = 0 */ + 0x87, /* dill_blt_code */ + 0x85, /* dill_bne_code */ }; extern void x86_64_branch(dill_stream s, int op, int type, int src1, int src2, int label) { int rex = 0; - if ((type == DILL_L) || (type == DILL_UL) || (type == DILL_P)) rex |= REX_W; + if ((type == DILL_L) || (type == DILL_UL) || (type == DILL_P)) + rex |= REX_W; - switch(type) { + switch (type) { case DILL_U: case DILL_UL: case DILL_US: case DILL_UC: - op += 6; /* second set of codes */ - /* fall through */ + op += 6; /* second set of codes */ + /* fall through */ default: - if (src1 > RDI) rex |= REX_B; - if (src2 > RDI) rex |= REX_R; - if (type == DILL_D) { - BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x2e, ModRM(0x3, src2, src1)); - } else if (type == DILL_F) { - BYTE_OUT3R(s, rex, 0x0f, 0x2e, ModRM(0x3, src2, src1)); - } else { - BYTE_OUT2R(s, rex, 0x39, ModRM(0x3, src2, src1)); - } - dill_mark_branch_location(s, label); - if ((type == DILL_D) || (type == DILL_F)) { - BYTE_OUT2I(s, 0x0f, fop_conds[op], 0); - } else { - BYTE_OUT2I(s, 0x0f, op_conds[op], 0); - } + if (src1 > RDI) + rex |= REX_B; + if (src2 > RDI) + rex |= REX_R; + if (type == DILL_D) { + BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x2e, ModRM(0x3, src2, src1)); + } else if (type == DILL_F) { + BYTE_OUT3R(s, rex, 0x0f, 0x2e, ModRM(0x3, src2, src1)); + } else { + BYTE_OUT2R(s, rex, 0x39, ModRM(0x3, src2, src1)); + } + dill_mark_branch_location(s, label); + if ((type == DILL_D) || (type == DILL_F)) { + BYTE_OUT2I(s, 0x0f, fop_conds[op], 0); + } else { + BYTE_OUT2I(s, 0x0f, op_conds[op], 0); + } } x86_64_nop(s); } static unsigned char set_op_conds[] = { - 0x94, /* dill_beq_code */ /* signed */ - 0x9d, /* dill_bge_code */ - 0x9F, /* dill_bgt_code */ - 0x9e, /* dill_ble_code */ - 0x9c, /* dill_blt_code */ - 0x95, /* dill_bne_code */ - - 0x94, /* dill_beq_code */ /* unsigned */ - 0x93, /* dill_bge_code */ - 0x97, /* dill_bgt_code */ - 0x96, /* dill_ble_code */ - 0x92, /* dill_blt_code */ - 0x95, /* dill_bne_code */ - - 0x94, /* dill_beq_code */ /* floating */ /* z = 1*/ - 0x96, /* dill_bge_code */ /* jna */ - 0x92, /* dill_bgt_code */ - 0x93, /* dill_ble_code */ /* c = 0 */ - 0x97, /* dill_blt_code */ - 0x95, /* dill_bne_code */ + 0x94, + /* dill_beq_code */ /* signed */ + 0x9d, /* dill_bge_code */ + 0x9F, /* dill_bgt_code */ + 0x9e, /* dill_ble_code */ + 0x9c, /* dill_blt_code */ + 0x95, /* dill_bne_code */ + + 0x94, + /* dill_beq_code */ /* unsigned */ + 0x93, /* dill_bge_code */ + 0x97, /* dill_bgt_code */ + 0x96, /* dill_ble_code */ + 0x92, /* dill_blt_code */ + 0x95, /* dill_bne_code */ + + 0x94, + /* dill_beq_code */ /* floating */ /* z = 1*/ + 0x96, + /* dill_bge_code */ /* jna */ + 0x92, /* dill_bgt_code */ + 0x93, + /* dill_ble_code */ /* c = 0 */ + 0x97, /* dill_blt_code */ + 0x95, /* dill_bne_code */ }; extern void x86_64_compare(dill_stream s, int op, int type, int dest, int src1, int src2) { int rex = 0; - if ((type == DILL_L) || (type == DILL_UL) || (type == DILL_P)) rex |= REX_W; + if ((type == DILL_L) || (type == DILL_UL) || (type == DILL_P)) + rex |= REX_W; - switch(type) { + switch (type) { case DILL_UC: case DILL_US: case DILL_U: case DILL_UL: - op += 6; /* second set of codes */ - /* fall through */ - break; + op += 6; /* second set of codes */ + /* fall through */ + break; case DILL_F: case DILL_D: - op += 12; /* third set of codes */ + op += 12; /* third set of codes */ } - if (src1 > RDI) rex |= REX_B; - if (src2 > RDI) rex |= REX_R; + if (src1 > RDI) + rex |= REX_B; + if (src2 > RDI) + rex |= REX_R; if (type == DILL_D) { - BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x2e, ModRM(0x3, src2, src1)); + BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x2e, ModRM(0x3, src2, src1)); } else if (type == DILL_F) { - BYTE_OUT3R(s, rex, 0x0f, 0x2e, ModRM(0x3, src2, src1)); + BYTE_OUT3R(s, rex, 0x0f, 0x2e, ModRM(0x3, src2, src1)); } else { - BYTE_OUT2R(s, rex, 0x39, ModRM(0x3, src2, src1)); /* compare */ + BYTE_OUT2R(s, rex, 0x39, ModRM(0x3, src2, src1)); /* compare */ } - BYTE_OUT3(s, 0x0f, set_op_conds[op],ModRM(0x3, EAX,EAX)); /* sete */ + BYTE_OUT3(s, 0x0f, set_op_conds[op], ModRM(0x3, EAX, EAX)); /* sete */ rex = 0; - if (dest > RDI) rex = REX_R; - BYTE_OUT3R(s, rex, 0x0f, 0xb6, ModRM(0x3, dest, EAX)); /* movzbl */ + if (dest > RDI) + rex = REX_R; + BYTE_OUT3R(s, rex, 0x0f, 0xb6, ModRM(0x3, dest, EAX)); /* movzbl */ } extern void -x86_64_comparei(dill_stream s, int op, int type, int dest, int src, IMM_TYPE imm) +x86_64_comparei(dill_stream s, + int op, + int type, + int dest, + int src, + IMM_TYPE imm) { int rex = 0; - if ((type == DILL_L) || (type == DILL_UL) || (type == DILL_P)) rex |= REX_W; + if ((type == DILL_L) || (type == DILL_UL) || (type == DILL_P)) + rex |= REX_W; - switch(type) { + switch (type) { case DILL_F: case DILL_D: - fprintf(stderr, "Shouldn't happen\n"); - break; + fprintf(stderr, "Shouldn't happen\n"); + break; case DILL_UC: case DILL_US: case DILL_U: case DILL_UL: - op += 6; /* second set of codes */ - /* fall through */ + op += 6; /* second set of codes */ + /* fall through */ } - if (src > RDI) rex |= REX_B; + if (src > RDI) + rex |= REX_B; if (imm < 0xffffffff) { - BYTE_OUT2IR(s, rex, 0x81, ModRM(0x3, 0x7, src), imm); /* cmp */ + BYTE_OUT2IR(s, rex, 0x81, ModRM(0x3, 0x7, src), (int)imm); /* cmp */ } else { - x86_64_setl(s, EAX, imm); - BYTE_OUT2R(s, rex, 0x39, ModRM(0x3, EAX, src)); + x86_64_setl(s, EAX, imm); + BYTE_OUT2R(s, rex, 0x39, ModRM(0x3, EAX, src)); } - BYTE_OUT3(s, 0x0f, set_op_conds[op],ModRM(0x3, EAX,EAX)); /* sete */ - BYTE_OUT3(s, 0x0f, 0xb6, ModRM(0x3, dest, EAX)); /* movzbl */ + BYTE_OUT3(s, 0x0f, set_op_conds[op], ModRM(0x3, EAX, EAX)); /* sete */ + BYTE_OUT3(s, 0x0f, 0xb6, ModRM(0x3, dest, EAX)); /* movzbl */ rex = 0; - if (dest > RDI) rex = REX_R; - BYTE_OUT3R(s, rex, 0x0f, 0xb6, ModRM(0x3, dest, EAX)); /* movzbl */ + if (dest > RDI) + rex = REX_R; + BYTE_OUT3R(s, rex, 0x0f, 0xb6, ModRM(0x3, dest, EAX)); /* movzbl */ } -extern void +extern void x86_64_jump_to_label(dill_stream s, unsigned long label) { dill_mark_branch_location(s, label); BYTE_OUT1I(s, 0xe9, 0); } -extern void x86_64_jump_to_reg(dill_stream s, unsigned long reg) +extern void +x86_64_jump_to_reg(dill_stream s, unsigned long reg) { int rex = 0; - if (reg > RDI) rex |= REX_B; + if (reg > RDI) + rex |= REX_B; BYTE_OUT2R(s, rex, 0xff, ModRM(0x3, 0x4, reg)); } -extern void x86_64_jump_to_imm(dill_stream s, void *imm) +extern void +x86_64_jump_to_imm(dill_stream s, void* imm) { - x86_64_seti(s, EAX, (intptr_t) imm); + x86_64_seti(s, EAX, (int)(intptr_t)imm); BYTE_OUT2(s, 0xff, ModRM(0x3, 0x4, EAX)); } -extern void +extern void x86_64_jal(dill_stream s, int return_addr_reg, int target) { -/* jump, source addr to return_addr_reg */ + /* jump, source addr to return_addr_reg */ } -extern void +extern void x86_64_special(dill_stream s, special_operations type, intptr_t param) { - x86_64_mach_info smi = (x86_64_mach_info) s->p->mach_info; + x86_64_mach_info smi = (x86_64_mach_info)s->p->mach_info; switch (type) { case DILL_NOP: - break; + break; case DILL_SEGMENTED_FOLLOWS: - switch(param) { - case DILL_X86_CS_PREFIX: - smi->pending_prefix = 0x2e; - break; - case DILL_X86_SS_PREFIX: - smi->pending_prefix = 0x36; - break; - case DILL_X86_DS_PREFIX: - smi->pending_prefix = 0x3e; - break; - case DILL_X86_ES_PREFIX: - smi->pending_prefix = 0x26; - break; - case DILL_X86_FS_PREFIX: - smi->pending_prefix = 0x64; - break; - case DILL_X86_GS_PREFIX: - smi->pending_prefix = 0x65; - break; - default: - fprintf(stderr, "Unknown x86 segment prefix!\n"); - } - break; - } -} - -static void internal_push(dill_stream s, int type, int immediate, - void *value_ptr) -{ - x86_64_mach_info smi = (x86_64_mach_info) s->p->mach_info; + switch (param) { + case DILL_X86_CS_PREFIX: + smi->pending_prefix = 0x2e; + break; + case DILL_X86_SS_PREFIX: + smi->pending_prefix = 0x36; + break; + case DILL_X86_DS_PREFIX: + smi->pending_prefix = 0x3e; + break; + case DILL_X86_ES_PREFIX: + smi->pending_prefix = 0x26; + break; + case DILL_X86_FS_PREFIX: + smi->pending_prefix = 0x64; + break; + case DILL_X86_GS_PREFIX: + smi->pending_prefix = 0x65; + break; + default: + fprintf(stderr, "Unknown x86 segment prefix!\n"); + } + break; + } +} + +static void +internal_push(dill_stream s, int type, int immediate, void* value_ptr) +{ + x86_64_mach_info smi = (x86_64_mach_info)s->p->mach_info; struct arg_info arg; arg.is_immediate = immediate; - switch(type) { - case DILL_C: case DILL_S: case DILL_I: case DILL_L: case DILL_P: case DILL_EC: - arg.type = DILL_L; - break; - case DILL_UC: case DILL_US: case DILL_U: case DILL_UL: - arg.type = DILL_UL; - break; - case DILL_D: case DILL_F: - arg.type = type; + switch (type) { + case DILL_C: + case DILL_S: + case DILL_I: + case DILL_L: + case DILL_P: + case DILL_EC: + arg.type = DILL_L; + break; + case DILL_UC: + case DILL_US: + case DILL_U: + case DILL_UL: + arg.type = DILL_UL; + break; + case DILL_D: + case DILL_F: + arg.type = type; break; default: - assert(0); + assert(0); } - - if (smi->varidiac_call && (smi->int_arg_count + smi->float_arg_count >= smi->non_var_args)) { - if (type == DILL_F) { - arg.type = DILL_D; - if (immediate) { - /* value_ptr is already pointing to a double, no special case */ - type = DILL_D; - } - } + if (smi->varidiac_call && + (smi->int_arg_count + smi->float_arg_count >= smi->non_var_args)) { + if (type == DILL_F) { + arg.type = DILL_D; + if (immediate) { + /* value_ptr is already pointing to a double, no special case */ + type = DILL_D; + } + } } if ((arg.type != DILL_D) && (arg.type != DILL_F)) { - if (smi->int_arg_count < sizeof(arg_regs) / sizeof(arg_regs[0])) { - arg.is_register = 1; - arg.in_reg = arg.out_reg = arg_regs[smi->int_arg_count]; - smi->int_arg_count++; - } else { - arg.is_register = 0; - arg.offset = smi->cur_arg_offset; - smi->cur_arg_offset += - roundup(type_info[(int)arg.type].size, smi->stack_align); - } +#ifndef USE_WINDOWS_CALLS + if (smi->int_arg_count < sizeof(arg_regs) / sizeof(arg_regs[0])) { +#else + if (smi->float_arg_count + smi->int_arg_count < + sizeof(arg_regs) / sizeof(arg_regs[0])) { +#endif + arg.is_register = 1; + arg.in_reg = arg.out_reg = arg_regs[smi->int_arg_count]; +#ifdef USE_WINDOWS_CALLS + arg.in_reg = arg.out_reg = + arg_regs[smi->int_arg_count + smi->float_arg_count]; + arg.offset = smi->cur_arg_offset; + smi->cur_arg_offset += + roundup(type_info[(int)arg.type].size, smi->stack_align); +#endif + smi->int_arg_count++; + } else { + arg.is_register = 0; + arg.offset = smi->cur_arg_offset; + smi->cur_arg_offset += + roundup(type_info[(int)arg.type].size, smi->stack_align); + } } else { - if (smi->float_arg_count < 8) { - arg.is_register = 1; - arg.in_reg = arg.out_reg = smi->float_arg_count; - smi->float_arg_count++; - } else { - arg.is_register = 0; - arg.offset = smi->cur_arg_offset; - smi->cur_arg_offset += - roundup(type_info[(int)arg.type].size, smi->stack_align); - } +#ifndef USE_WINDOWS_CALLS + if (smi->float_arg_count < 8) { +#else + if (smi->float_arg_count + smi->int_arg_count < 4) { +#endif + arg.is_register = 1; + arg.in_reg = arg.out_reg = smi->float_arg_count; +#ifdef USE_WINDOWS_CALLS + arg.in_reg = arg.out_reg = + smi->float_arg_count + smi->int_arg_count; + arg.offset = smi->cur_arg_offset; + smi->cur_arg_offset += + roundup(type_info[(int)arg.type].size, smi->stack_align); +#endif + smi->float_arg_count++; + } else { + arg.is_register = 0; + arg.offset = smi->cur_arg_offset; + smi->cur_arg_offset += + roundup(type_info[(int)arg.type].size, smi->stack_align); + } } if (arg.is_register == 0) { - if (arg.offset == 0) { - smi->call_backpatch_offset = (char*)s->p->cur_ip - (char*)s->p->code_base; - dill_subli(s, ESP, ESP, 0x70909090); /* tentative for backpatch */ - smi->call_stack_space = 128; - } - /* store it on the stack only */ - if (arg.is_immediate) { - int arg_type = arg.type; - if (type == DILL_F) { - union { - float f; - int i; - } a; - a.f = (float) *(double*)value_ptr; - x86_64_setl(s, EAX, a.i); - arg_type = DILL_I; - } else { - x86_64_setl(s, EAX, *(intptr_t*)value_ptr); - arg_type = DILL_L; - } - x86_64_pstorei(s, arg_type, 0, EAX, ESP, arg.offset); - } else { - /* need to handle DILL_F upconvert to DILL_D here? */ - x86_64_pstorei(s, arg.type, 0, *(int*)value_ptr, ESP, - arg.offset); - } + if (arg.offset == 0) { + smi->call_backpatch_offset = + (int)((char*)s->p->cur_ip - (char*)s->p->code_base); + dill_subli(s, ESP, ESP, 0x70909090); /* tentative for backpatch */ + smi->call_stack_space = 128; + } + /* store it on the stack only */ + if (arg.is_immediate) { + int arg_type = arg.type; + if (type == DILL_F) { + union { + float f; + int i; + } a; + a.f = (float)*(double*)value_ptr; + x86_64_setl(s, EAX, a.i); + arg_type = DILL_I; + } else { + x86_64_setl(s, EAX, *(intptr_t*)value_ptr); + arg_type = DILL_L; + } + x86_64_pstorei(s, arg_type, 0, EAX, ESP, arg.offset); + } else { + /* need to handle DILL_F upconvert to DILL_D here? */ + x86_64_pstorei(s, arg.type, 0, *(int*)value_ptr, ESP, + (IMM_TYPE)arg.offset); + } } else { - if ((type != DILL_F) && (type != DILL_D)) { - if (arg.is_immediate) { - x86_64_setl(s, arg.out_reg, *(intptr_t*)value_ptr); - } else { - x86_64_pmov(s, arg.type, arg.out_reg, *(int*) value_ptr); - } - } else { - /* float types handled here */ - if (arg.is_immediate) { - if ((type == DILL_F) || (type == DILL_D)) { - /* set appropriate register */ - x86_64_setf(s, type, 0, arg.out_reg, - *(double*)value_ptr); - } else { - x86_64_setl(s, arg.out_reg, *(intptr_t*)value_ptr); - } - } else { - /* move to the appropriate float reg */ - if ((type == DILL_F) && (arg.type == DILL_D)) { - /* special case for upconverting varidiac args */ - x86_64_convert(s, DILL_F, DILL_D, arg.out_reg, *(int*)value_ptr); - } else { - x86_64_mov(s, type, 0, arg.out_reg, *(int*)value_ptr); - } - } - - } - } -} - -static void push_init(dill_stream s) -{ - x86_64_mach_info smi = (x86_64_mach_info) s->p->mach_info; + if ((type != DILL_F) && (type != DILL_D)) { + if (arg.is_immediate) { + x86_64_setl(s, arg.out_reg, *(intptr_t*)value_ptr); + } else { + x86_64_pmov(s, arg.type, arg.out_reg, *(int*)value_ptr); + } + } else { + /* float types handled here */ + if (arg.is_immediate) { + if ((type == DILL_F) || (type == DILL_D)) { + /* set appropriate register */ +#ifdef USE_WINDOWS_CALLS + x86_64_setf(s, type, 0, arg.out_reg, *(double*)value_ptr); + x86_64_setl(s, arg_regs[arg.out_reg], + *(IMM_TYPE*)value_ptr); +#else + x86_64_setf(s, type, 0, arg.out_reg, *(double*)value_ptr); +#endif + } else { + x86_64_setl(s, arg.out_reg, *(intptr_t*)value_ptr); + } + } else { + /* move to the appropriate float reg */ + if ((type == DILL_F) && (arg.type == DILL_D)) { + /* special case for upconverting varidiac args */ + x86_64_convert(s, DILL_F, DILL_D, arg.out_reg, + *(int*)value_ptr); + } else { + x86_64_mov(s, type, 0, arg.out_reg, *(int*)value_ptr); + } +#ifdef USE_WINDOWS_CALLS + { + int rex = REX_W; + if (arg_regs[arg.out_reg] > RDI) + rex |= REX_B; + if (arg.out_reg > RDI) + rex |= REX_R; + // move float reg to corresponding integer + BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x7e, + ModRM(0x3, arg.out_reg, arg_regs[arg.out_reg])); + } +#endif + } + } + } +} + +static void +push_init(dill_stream s) +{ + x86_64_mach_info smi = (x86_64_mach_info)s->p->mach_info; smi->varidiac_call = 0; smi->cur_arg_offset = 0; smi->int_arg_count = 0; @@ -2347,53 +2660,77 @@ static void push_init(dill_stream s) smi->call_stack_space = 0; } -extern void x86_64_push(dill_stream s, int type, int reg) +extern void +x86_64_push(dill_stream s, int type, int reg) { - x86_64_mach_info smi = (x86_64_mach_info) s->p->mach_info; + x86_64_mach_info smi = (x86_64_mach_info)s->p->mach_info; if ((type == DILL_V) && (reg <= -1)) { - push_init(s); - if (reg <= -2) { - smi->varidiac_call = 1; - smi->non_var_args = -(reg + 2); - } + push_init(s); + if (reg <= -2) { + smi->varidiac_call = 1; + smi->non_var_args = -(reg + 2); + } } else { - internal_push(s, type, 0, ®); + internal_push(s, type, 0, ®); } } -extern void x86_64_pushi(dill_stream s, int type, IMM_TYPE value) +extern void +x86_64_pushi(dill_stream s, int type, IMM_TYPE value) { internal_push(s, type, 1, &value); } -extern void x86_64_pushpi(dill_stream s, int type, void *value) +extern void +x86_64_pushpi(dill_stream s, int type, void* value) { internal_push(s, type, 1, &value); } -extern void x86_64_pushfi(dill_stream s, int type, double value) +extern void +x86_64_pushfi(dill_stream s, int type, double value) { internal_push(s, type, 1, &value); } -extern int x86_64_calli(dill_stream s, int type, void *xfer_address, const char *name) +extern int +x86_64_calli(dill_stream s, int type, void* xfer_address, const char* name) { int rex = REX_W; + int i; int tmp_call_reg = R11; - if (tmp_call_reg > RDI) rex |= REX_B; - + if (tmp_call_reg > RDI) + rex |= REX_B; + + /* save temporary registers */ + for (i = XMM8; i < XMM15; i += 1) { + if (dill_mustsave(&s->p->tmp_f, i)) { + x86_64_save_restore_op(s, 0, DILL_D, i); + } + } + /* save temporary registers */ dill_mark_call_location(s, name, xfer_address); - BYTE_OUT1LR(s, rex, 0xb8 + (0x7 & tmp_call_reg), 0); /* setl */ - return x86_64_callr(s, type, R11); + BYTE_OUT1LR(s, rex, 0xb8 + (0x7 & tmp_call_reg), 0); /* setl */ + int ret_reg = x86_64_callr(s, type, R11); + + /* restore temporary registers */ + for (i = XMM8; i < XMM15; i += 1) { + if (dill_mustsave(&s->p->tmp_f, i)) { + x86_64_save_restore_op(s, 1, DILL_D, i); + } + } + return ret_reg; } -extern int x86_64_callr(dill_stream s, int type, int src) +extern int +x86_64_callr(dill_stream s, int type, int src) { - x86_64_mach_info smi = (x86_64_mach_info) s->p->mach_info; + x86_64_mach_info smi = (x86_64_mach_info)s->p->mach_info; int caller_side_ret_reg = EAX; int rex = REX_W; - if (src > RDI) rex |= REX_B; + if (src > RDI) + rex |= REX_B; /* save temporary registers */ /* call through reg */ @@ -2401,69 +2738,77 @@ extern int x86_64_callr(dill_stream s, int type, int src) BYTE_OUT2R(s, rex, 0xff, ModRM(0x3, 0x2, src)); /* restore temporary registers */ if ((type == DILL_D) || (type == DILL_F)) { -/* caller_side_ret_reg = _f0;*/ + /* caller_side_ret_reg = _f0;*/ } if (smi->call_stack_space != 0) { - void *save_ip = s->p->cur_ip; - int call_stack_size = roundup(smi->call_stack_space, 8) + 16; + void* save_ip = s->p->cur_ip; + int call_stack_size = roundup(smi->call_stack_space, 8) + 16; - /* backpatch space reservation */ - s->p->cur_ip = (char*)s->p->code_base + smi->call_backpatch_offset; - dill_subli(s, ESP, ESP, call_stack_size); + /* backpatch space reservation */ + s->p->cur_ip = (char*)s->p->code_base + smi->call_backpatch_offset; + dill_subli(s, ESP, ESP, call_stack_size); - s->p->cur_ip = save_ip; - /* undo arg space reservation */ - dill_addli(s, ESP, ESP, call_stack_size); + s->p->cur_ip = save_ip; + /* undo arg space reservation */ + dill_addli(s, ESP, ESP, call_stack_size); } return caller_side_ret_reg; } extern void -x86_64_branchi(dill_stream s, int op, int type, int src, IMM_TYPE imm, int label) +x86_64_branchi(dill_stream s, + int op, + int type, + int src, + IMM_TYPE imm, + int label) { int rex = 0; - if ((type == DILL_L) || (type == DILL_UL) || (type == DILL_P)) rex |= REX_W; + if ((type == DILL_L) || (type == DILL_UL) || (type == DILL_P)) + rex |= REX_W; - switch(type) { + switch (type) { case DILL_F: case DILL_D: - fprintf(stderr, "Shouldn't happen\n"); - break; + fprintf(stderr, "Shouldn't happen\n"); + break; case DILL_U: case DILL_UL: case DILL_US: case DILL_UC: -/* - switch(op) { - case dill_bge_code: { - imm = imm-1; - op = dill_bgt_code; - break; - } - case dill_blt_code: { - imm = imm-1; - op = dill_ble_code; - break; - } - } -*/ - op += 6; /* second set of codes */ - /* fall through */ + /* + switch(op) { + case dill_bge_code: { + imm = imm-1; + op = dill_bgt_code; + break; + } + case dill_blt_code: { + imm = imm-1; + op = dill_ble_code; + break; + } + } + */ + op += 6; /* second set of codes */ + /* fall through */ default: -/* BYTE_OUT2(s, 0x39, ModRM(0x3, src2, src1));*/ - if (src > RDI) rex |= REX_B; - if (imm < 0x7fffffff) { - BYTE_OUT2IR(s, rex, 0x81, ModRM(0x3, 0x7, src), imm); /* cmp */ - } else { - x86_64_setl(s, EAX, imm); - BYTE_OUT2R(s, rex, 0x39, ModRM(0x3, EAX, src)); - } - dill_mark_branch_location(s, label); - BYTE_OUT2I(s, 0x0f, op_conds[op], 0); + /* BYTE_OUT2(s, 0x39, ModRM(0x3, src2, src1));*/ + if (src > RDI) + rex |= REX_B; + if (((uintptr_t)imm) < 0x7fffffff) { + BYTE_OUT2IR(s, rex, 0x81, ModRM(0x3, 0x7, src), (int)imm); /* cmp */ + } else { + x86_64_setl(s, EAX, imm); + BYTE_OUT2R(s, rex, 0x39, ModRM(0x3, EAX, src)); + } + dill_mark_branch_location(s, label); + BYTE_OUT2I(s, 0x0f, op_conds[op], 0); } } -extern void x86_64_ret(dill_stream s, int data1, int data2, int src) +extern void +x86_64_ret(dill_stream s, int data1, int data2, int src) { switch (data1) { case DILL_C: @@ -2475,31 +2820,36 @@ extern void x86_64_ret(dill_stream s, int data1, int data2, int src) case DILL_L: case DILL_UL: case DILL_P: - if (src != EAX) x86_64_movl(s, EAX, src); - break; + if (src != EAX) + x86_64_movl(s, EAX, src); + break; case DILL_F: - if (src != XMM0) x86_64_movf(s, XMM0, src); - break; + if (src != XMM0) + x86_64_movf(s, XMM0, src); + break; case DILL_D: - if (src != XMM0) x86_64_movd(s, XMM0, src); - break; + if (src != XMM0) + x86_64_movd(s, XMM0, src); + break; } x86_64_proc_ret(s); } -extern void x86_64_retf(dill_stream s, int data1, int data2, double imm) +extern void +x86_64_retf(dill_stream s, int data1, int data2, double imm) { - switch(data1) { + switch (data1) { case DILL_F: - x86_64_setf(s, DILL_F, 0, XMM0, imm); - break; + x86_64_setf(s, DILL_F, 0, XMM0, imm); + break; case DILL_D: - x86_64_setf(s, DILL_D, 0, XMM0, imm); - break; + x86_64_setf(s, DILL_D, 0, XMM0, imm); + break; } } -extern void x86_64_reti(dill_stream s, int data1, int data2, IMM_TYPE imm) +extern void +x86_64_reti(dill_stream s, int data1, int data2, IMM_TYPE imm) { switch (data1) { case DILL_C: @@ -2508,13 +2858,13 @@ extern void x86_64_reti(dill_stream s, int data1, int data2, IMM_TYPE imm) case DILL_US: case DILL_I: case DILL_U: - x86_64_seti(s, EAX, imm); - break; + x86_64_seti(s, EAX, (int)imm); + break; case DILL_L: case DILL_UL: case DILL_P: - x86_64_setl(s, EAX, imm); - break; + x86_64_setl(s, EAX, imm); + break; } x86_64_proc_ret(s); } @@ -2522,46 +2872,46 @@ extern void x86_64_reti(dill_stream s, int data1, int data2, IMM_TYPE imm) static void x86_64_data_link(dill_stream s) { -/* struct branch_table *t = &s->p->branch_table; - int i; - for (i=0; i < t->data_mark_count; i++) { - int label = t->data_marks[i].label; - void *label_addr = t->label_locs[label] + (char*)s->p->code_base; - *t->data_marks[i].addr = label_addr; - }*/ + /* struct branch_table *t = &s->p->branch_table; + int i; + for (i=0; i < t->data_mark_count; i++) { + int label = t->data_marks[i].label; + void *label_addr = t->label_locs[label] + (char*)s->p->code_base; + *t->data_marks[i].addr = label_addr; + }*/ } static void x86_64_branch_link(dill_stream s) { - struct branch_table *t = &s->p->branch_table; + struct branch_table* t = &s->p->branch_table; int i; - for(i=0; i< t->branch_count; i++) { - int label = t->branch_locs[i].label; - int label_offset = t->label_locs[label] - t->branch_locs[i].loc; - char *branch_addr = (char*)((char *)s->p->code_base + - t->branch_locs[i].loc); - int offset; - if (*branch_addr == 0x0f) { - branch_addr +=2; /* conditional */ - offset = 6; - } else { - branch_addr++; /* unconditional */ - offset = 5; - } - int tmp = label_offset - offset; - memcpy(branch_addr, &tmp, 4); + for (i = 0; i < t->branch_count; i++) { + int label = t->branch_locs[i].label; + int label_offset = t->label_locs[label] - t->branch_locs[i].loc; + char* branch_addr = + (char*)((char*)s->p->code_base + t->branch_locs[i].loc); + int offset; + if (*branch_addr == 0x0f) { + branch_addr += 2; /* conditional */ + offset = 6; + } else { + branch_addr++; /* unconditional */ + offset = 5; + } + int tmp = label_offset - offset; + memcpy(branch_addr, &tmp, 4); } } extern void -x86_64_rt_call_link(char *code, call_t *t); +x86_64_rt_call_link(char* code, call_t* t); static void x86_64_call_link(dill_stream s) { - call_t *t = &s->p->call_table; + call_t* t = &s->p->call_table; x86_64_rt_call_link(s->p->code_base, t); } @@ -2569,11 +2919,11 @@ x86_64_call_link(dill_stream s) static void x86_64_emit_save(dill_stream s) { - x86_64_mach_info smi = (x86_64_mach_info) s->p->mach_info; - void *save_ip = s->p->cur_ip; + x86_64_mach_info smi = (x86_64_mach_info)s->p->mach_info; + void* save_ip = s->p->cur_ip; int ar_size = smi->act_rec_size; int prefix_size; - ar_size = roundup(ar_size, 16) + 8; + ar_size = roundup(ar_size, 16) + 8 + 32; s->p->cur_ip = (char*)s->p->code_base; @@ -2584,42 +2934,42 @@ x86_64_emit_save(dill_stream s) /* re-generate in the right place */ if (prefix_size != generate_prefix_code(s, 0, ar_size, NULL)) { - printf("2nd generation different than first\n"); + printf("2nd generation different than first\n"); } s->p->cur_ip = save_ip; } - + #ifdef USE_VIRTUAL_PROTECT #include -#include #include +#include #endif static void -x86_64_flush(void *base, void *limit) +x86_64_flush(void* base, void* limit) { #if defined(HOST_X86_64) { - volatile void *ptr = base; + volatile void* ptr = base; - /* flush every 8 bytes of preallocated insn stream. */ - while((char*)ptr < (char*) limit) { + /* flush every 8 bytes of preallocated insn stream. */ + while ((char*)ptr < (char*)limit) { #ifndef _MSC_VER #ifdef __x86_64__ - asm volatile ("clflush (%0)" : /* */ : "r" (ptr)); + asm volatile("clflush (%0)" : /* */ : "r"(ptr)); #endif #else - _mm_clflush((const void *) ptr); + _mm_clflush((const void*)ptr); #endif - ptr = (char *)ptr + 8; - } + ptr = (char*)ptr + 8; + } #ifndef _MSC_VER - asm volatile("nop"); - asm volatile("nop"); - asm volatile("nop"); - asm volatile("nop"); - asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); #endif } #endif @@ -2629,10 +2979,9 @@ x86_64_flush(void *base, void *limit) size_t size = ((intptr_t)limit - (intptr_t)base); result = VirtualProtect(base, size, PAGE_EXECUTE_READWRITE, &dummy); #endif -} +} extern void -x86_64_end(s) -dill_stream s; +x86_64_end(dill_stream s) { x86_64_proc_ret(s); x86_64_branch_link(s); @@ -2643,8 +2992,7 @@ dill_stream s; } extern void -x86_64_package_end(s) -dill_stream s; +x86_64_package_end(dill_stream s) { x86_64_proc_ret(s); x86_64_branch_link(s); @@ -2652,19 +3000,17 @@ dill_stream s; x86_64_flush(s->p->code_base, s->p->code_limit); } -extern void * -x86_64_clone_code(s, new_base, available_size) -dill_stream s; -void *new_base; -int available_size; +extern void* +x86_64_clone_code(dill_stream s, void* new_base, int available_size) { int size = dill_code_size(s); - void *old_base = s->p->code_base; - void *native_base = s->p->code_base; + void* old_base = s->p->code_base; + void* native_base = s->p->code_base; if (available_size < size) { - return NULL; + return NULL; } - if (native_base == NULL) native_base = s->p->native.code_base; + if (native_base == NULL) + native_base = s->p->native.code_base; memcpy(new_base, native_base, size); s->p->code_base = new_base; s->p->cur_ip = (char*)new_base + size; @@ -2675,79 +3021,88 @@ int available_size; s->p->code_base = old_base; s->p->cur_ip = (char*)old_base + size; s->p->fp = old_base; + x86_64_flush(new_base, (char*)new_base + size); + return new_base; } extern void x86_64_pset(dill_stream s, int type, int junk, int dest, IMM_TYPE imm) { - switch(type) { - case DILL_L: case DILL_UL: case DILL_P: - x86_64_setl(s, dest, imm); - break; + switch (type) { + case DILL_L: + case DILL_UL: + case DILL_P: + x86_64_setl(s, dest, imm); + break; default: - x86_64_seti(s, dest, imm); - break; + x86_64_seti(s, dest, (int)imm); + break; } s->p->used_frame++; -} +} extern void x86_64_setf(dill_stream s, int type, int junk, int dest, double imm) { union { - float f; - int i; + float f; + int i; } a; union { - double d; - int i[2]; - intptr_t l; + double d; + int i[2]; + intptr_t l; } b; if (type == DILL_F) { - int rex = 0; - a.f = imm; - x86_64_seti(s, EAX, a.i); - if (dest > RDI) rex |= REX_R; - BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, dest, EAX)); + int rex = 0; + a.f = (float)imm; + x86_64_seti(s, EAX, a.i); + if (dest > RDI) + rex |= REX_R; + BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, dest, EAX)); } else { - int rex = REX_W; - b.d = imm; - x86_64_setl(s, EAX, b.l); - if (dest > RDI) rex |= REX_R; - BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, dest, EAX)); + int rex = REX_W; + b.d = imm; + x86_64_setl(s, EAX, b.l); + if (dest > RDI) + rex |= REX_R; + BYTE_OUT1R3(s, 0x66, rex, 0x0f, 0x6e, ModRM(0x3, dest, EAX)); } -} - +} -#define bit_R(x) (1<p->var_i.init_avail[0] = (bit_R(EBX)|bit_R(R12)|bit_R(R13)|bit_R(R14)|bit_R(R15)); + s->p->var_i.init_avail[0] = + (bit_R(EBX) | bit_R(R12) | bit_R(R13) | bit_R(R14) | bit_R(R15)); s->p->var_i.members[0] = s->p->var_i.init_avail[0]; s->p->tmp_i.init_avail[0] = (bit_R(R11)); s->p->tmp_i.members[0] = s->p->tmp_i.init_avail[0] | bit_R(EAX); s->p->var_f.init_avail[0] = 0; s->p->var_f.members[0] = s->p->var_f.init_avail[0]; - s->p->tmp_f.init_avail[0] = (bit_R(XMM8)|bit_R(XMM9)|bit_R(XMM10)|bit_R(XMM11)|bit_R(XMM12)|bit_R(XMM13)|bit_R(XMM14)|bit_R(XMM15)); - s->p->tmp_f.members[0] = s->p->tmp_f.init_avail[0]|bit_R(XMM0)|bit_R(XMM1)|bit_R(XMM2)|bit_R(XMM3)|bit_R(XMM4)|bit_R(XMM5)|bit_R(XMM6)|bit_R(XMM7); + s->p->tmp_f.init_avail[0] = + (bit_R(XMM8) | bit_R(XMM9) | bit_R(XMM10) | bit_R(XMM11) | + bit_R(XMM12) | bit_R(XMM13) | bit_R(XMM14) | bit_R(XMM15)); + s->p->tmp_f.members[0] = + s->p->tmp_f.init_avail[0] | bit_R(XMM0) | bit_R(XMM1) | bit_R(XMM2) | + bit_R(XMM3) | bit_R(XMM4) | bit_R(XMM5) | bit_R(XMM6) | bit_R(XMM7); } extern void* -gen_x86_64_mach_info(s) -dill_stream s; +gen_x86_64_mach_info(dill_stream s) { x86_64_mach_info smi = malloc(sizeof(*smi)); if (s->p->mach_info != NULL) { - free(s->p->mach_info); - s->p->mach_info = NULL; - s->p->native.mach_info = NULL; + free(s->p->mach_info); + s->p->mach_info = NULL; + s->p->native.mach_info = NULL; } x86_64_reg_init(s); smi->act_rec_size = 0; - smi->stack_align = 8; /* 8 for x86_64 */ + smi->stack_align = 8; /* 8 for x86_64 */ smi->stack_constant_offset = 0; /* 2047 for x86_64v9 */ smi->conversion_word = 0; smi->fcu_word = 0; @@ -2759,11 +3114,12 @@ dill_stream s; /* GENERIC BINUTILS DISASSEMBLER */ #include "dis-asm.h" -#define MAXLENGTH (1<<23) /* Max length of function that can be disassembled */ +#define MAXLENGTH \ + (1 << 23) /* Max length of function that can be disassembled */ #ifdef LINUX_KERNEL_MODULE extern int -kfprintf(FILE *file, const char *fmt, ...) +kfprintf(FILE* file, const char* fmt, ...) { static char printk_buf[1024]; int val; @@ -2775,16 +3131,16 @@ kfprintf(FILE *file, const char *fmt, ...) return val; } -#undef stdout +#undef stdout #define stdout (FILE*)0 #define FPRINTF_FUNCTION kfprintf #else #define FPRINTF_FUNCTION fprintf #endif extern int -x86_64_init_disassembly_info(dill_stream s, void * ptr) +x86_64_init_disassembly_info(dill_stream s, void* ptr) { - struct disassemble_info *i = ptr; + struct disassemble_info* i = ptr; #ifdef INIT_DISASSEMBLE_INFO_THREE_ARG INIT_DISASSEMBLE_INFO(*i, stdout, FPRINTF_FUNCTION); i->endian = BFD_ENDIAN_LITTLE; @@ -2794,11 +3150,11 @@ x86_64_init_disassembly_info(dill_stream s, void * ptr) i->mach = bfd_mach_x86_64; i->disassembler_options = "x86-64"; if (s->p->code_base != NULL) { - i->buffer = (bfd_byte *)s->p->code_base; - i->buffer_vma = (bfd_vma)s->p->code_base; + i->buffer = (bfd_byte*)s->p->code_base; + i->buffer_vma = (bfd_vma)s->p->code_base; } else { - i->buffer = (bfd_byte *)s->p->native.code_base; - i->buffer_vma = (bfd_vma)s->p->native.code_base; + i->buffer = (bfd_byte*)s->p->native.code_base; + i->buffer_vma = (bfd_vma)s->p->native.code_base; } i->buffer_length = MAXLENGTH; #ifdef HAVE_PRINT_INSN_I386 @@ -2809,7 +3165,7 @@ x86_64_init_disassembly_info(dill_stream s, void * ptr) } extern int -x86_64_print_insn(dill_stream s, void *info_ptr, void *insn) +x86_64_print_insn(dill_stream s, void* info_ptr, void* insn) { #ifdef HAVE_PRINT_INSN_I386 return print_insn_i386((bfd_vma)insn, info_ptr); @@ -2818,51 +3174,63 @@ x86_64_print_insn(dill_stream s, void *info_ptr, void *insn) #endif } -extern void null_func(){} +extern void +null_func() +{ +} extern int x86_64_count_insn(dill_stream s, int start, int end) { #ifdef HAVE_PRINT_INSN_I386 struct disassemble_info i; int count; - char *insn_ptr; + char* insn_ptr; #ifdef INIT_DISASSEMBLE_INFO_THREE_ARG - INIT_DISASSEMBLE_INFO(i, stdout, (fprintf_ftype) null_func); + INIT_DISASSEMBLE_INFO(i, stdout, (fprintf_ftype)null_func); i.endian = BFD_ENDIAN_LITTLE; #else INIT_DISASSEMBLE_INFO(i, stdout); #endif i.mach = bfd_mach_i386_i386; if (s->p->code_base != NULL) { - i.buffer = (bfd_byte *)s->p->code_base; - i.buffer_vma = (bfd_vma)s->p->code_base; + i.buffer = (bfd_byte*)s->p->code_base; + i.buffer_vma = (bfd_vma)s->p->code_base; } else { - i.buffer = (bfd_byte *)s->p->native.code_base; - i.buffer_vma = (bfd_vma)s->p->native.code_base; + i.buffer = (bfd_byte*)s->p->native.code_base; + i.buffer_vma = (bfd_vma)s->p->native.code_base; } i.buffer_length = MAXLENGTH; count = 0; - insn_ptr = (char*) (i.buffer + start); - while((intptr_t)insn_ptr < (intptr_t)i.buffer + end) { - insn_ptr += print_insn_i386((bfd_vma)insn_ptr, &i); - count++; + insn_ptr = (char*)(i.buffer + start); + while ((intptr_t)insn_ptr < (intptr_t)i.buffer + end) { + insn_ptr += print_insn_i386((bfd_vma)insn_ptr, &i); + count++; } return count; #else - /* no print insn, just return the buffer length */ + /* no print insn, just return the buffer length */ return end - start; #endif } #else extern int x86_64_count_insn(dill_stream s, int start, int end) -{ /* no print insn, just return the buffer length */ +{ /* no print insn, just return the buffer length */ return end - start; } extern int -x86_64_init_disassembly_info(dill_stream s, void * ptr){return 1;} -unsigned int x86_64_disassemble(unsigned char *bytes, unsigned int max, int offset, char *output); -extern int x86_64_print_insn(dill_stream s, void *info_ptr, void *insn){ +x86_64_init_disassembly_info(dill_stream s, void* ptr) +{ + return 1; +} +unsigned int +x86_64_disassemble(unsigned char* bytes, + unsigned int max, + int offset, + char* output); +extern int +x86_64_print_insn(dill_stream s, void* info_ptr, void* insn) +{ char out[128] = ""; int ret = x86_64_disassemble(insn, sizeof(out), 0, out); printf("%s", out); @@ -2873,30 +3241,35 @@ extern int x86_64_print_insn(dill_stream s, void *info_ptr, void *insn){ extern void x86_64_print_reg(dill_stream s, int typ, int reg) { - switch(typ) { - case DILL_C: case DILL_UC: - if ((reg > 0) && (reg < sizeof(char_regs)/sizeof(char_regs[0]))) { - printf("%s", char_regs[reg]); - return; - } - break; - case DILL_S: case DILL_US: - if ((reg > 0) && (reg < sizeof(short_regs)/sizeof(short_regs[0]))) { - printf("%s", short_regs[reg]); - return; - } - break; -/* case DILL_C: case DILL_UC: case DILL_S: case DILL_US:*/ - case DILL_I: case DILL_U: case DILL_L: case DILL_UL: - if ((reg > 0) && (reg < sizeof(int_regs)/sizeof(int_regs[0]))) { - printf("%s", int_regs[reg]); - return; - } - break; - case DILL_F: case DILL_D: - printf("Fstack"); - return; + switch (typ) { + case DILL_C: + case DILL_UC: + if ((reg > 0) && (reg < sizeof(char_regs) / sizeof(char_regs[0]))) { + printf("%s", char_regs[reg]); + return; + } + break; + case DILL_S: + case DILL_US: + if ((reg > 0) && (reg < sizeof(short_regs) / sizeof(short_regs[0]))) { + printf("%s", short_regs[reg]); + return; + } + break; + /* case DILL_C: case DILL_UC: case DILL_S: case DILL_US:*/ + case DILL_I: + case DILL_U: + case DILL_L: + case DILL_UL: + if ((reg > 0) && (reg < sizeof(int_regs) / sizeof(int_regs[0]))) { + printf("%s", int_regs[reg]); + return; + } + break; + case DILL_F: + case DILL_D: + printf("Fstack"); + return; } printf("NoReg(%d)", reg); } - diff --git a/x86_64.h b/x86_64.h index 048143512b..8bda58431e 100644 --- a/x86_64.h +++ b/x86_64.h @@ -1,163 +1,217 @@ #ifndef _X86_64_H #define _X86_64_H -#define BYTE_OUT1(c, insn1) \ -do { \ -if (c->p->cur_ip >= c->p->code_limit) {\ - extend_dill_stream(c);\ -}\ -*(unsigned char*)c->p->cur_ip = (unsigned char)insn1;\ -if (c->dill_debug) dump_cur_dill_insn(c);\ -c->p->cur_ip = ((char*)c->p->cur_ip)+1; \ -} while (0) +#define BYTE_OUT1(c, insn1) \ + do { \ + if (c->p->cur_ip >= c->p->code_limit) { \ + extend_dill_stream(c); \ + } \ + *(unsigned char*)c->p->cur_ip = (unsigned char)insn1; \ + if (c->dill_debug) \ + dump_cur_dill_insn(c); \ + c->p->cur_ip = ((char*)c->p->cur_ip) + 1; \ + } while (0) -#define BYTE_OUT2(c, insn1, insn2) \ -do { \ -if (c->p->cur_ip >= c->p->code_limit) {\ - extend_dill_stream(c);\ -}\ -*(unsigned char*)c->p->cur_ip = (unsigned char)insn1;\ -*(((unsigned char*)c->p->cur_ip) + 1)= (unsigned char)insn2;\ -if (c->dill_debug) dump_cur_dill_insn(c);\ -c->p->cur_ip = ((char*)c->p->cur_ip)+2; \ -} while (0) +#define BYTE_OUT2(c, insn1, insn2) \ + do { \ + if (c->p->cur_ip >= c->p->code_limit) { \ + extend_dill_stream(c); \ + } \ + *(unsigned char*)c->p->cur_ip = (unsigned char)insn1; \ + *(((unsigned char*)c->p->cur_ip) + 1) = (unsigned char)insn2; \ + if (c->dill_debug) \ + dump_cur_dill_insn(c); \ + c->p->cur_ip = ((char*)c->p->cur_ip) + 2; \ + } while (0) -#define BYTE_OUT3(c, insn1, insn2, insn3) \ -do { \ -if (c->p->cur_ip >= c->p->code_limit) {\ - extend_dill_stream(c);\ -}\ -*(unsigned char*)c->p->cur_ip = (unsigned char)insn1;\ -*(((unsigned char*)c->p->cur_ip) + 1)= (unsigned char)insn2;\ -*(((unsigned char*)c->p->cur_ip) + 2)= (unsigned char)insn3;\ -if (c->dill_debug) dump_cur_dill_insn(c);\ - c->p->cur_ip = ((char*)c->p->cur_ip)+3; \ -} while (0) +#define BYTE_OUT3(c, insn1, insn2, insn3) \ + do { \ + if (c->p->cur_ip >= c->p->code_limit) { \ + extend_dill_stream(c); \ + } \ + *(unsigned char*)c->p->cur_ip = (unsigned char)insn1; \ + *(((unsigned char*)c->p->cur_ip) + 1) = (unsigned char)insn2; \ + *(((unsigned char*)c->p->cur_ip) + 2) = (unsigned char)insn3; \ + if (c->dill_debug) \ + dump_cur_dill_insn(c); \ + c->p->cur_ip = ((char*)c->p->cur_ip) + 3; \ + } while (0) -#define BYTE_OUT4(c, insn1, insn2, insn3, insn4) \ -do { \ -if (c->p->cur_ip >= c->p->code_limit) {\ - extend_dill_stream(c);\ -}\ -*(unsigned char*)c->p->cur_ip = (unsigned char)insn1;\ -*(((unsigned char*)c->p->cur_ip) + 1)= (unsigned char)insn2;\ -*(((unsigned char*)c->p->cur_ip) + 2)= (unsigned char)insn3;\ -*(((unsigned char*)c->p->cur_ip) + 3)= (unsigned char)insn4;\ -if (c->dill_debug) dump_cur_dill_insn(c);\ - c->p->cur_ip = ((char*)c->p->cur_ip)+4; \ -} while (0) +#define BYTE_OUT4(c, insn1, insn2, insn3, insn4) \ + do { \ + if (c->p->cur_ip >= c->p->code_limit) { \ + extend_dill_stream(c); \ + } \ + *(unsigned char*)c->p->cur_ip = (unsigned char)insn1; \ + *(((unsigned char*)c->p->cur_ip) + 1) = (unsigned char)insn2; \ + *(((unsigned char*)c->p->cur_ip) + 2) = (unsigned char)insn3; \ + *(((unsigned char*)c->p->cur_ip) + 3) = (unsigned char)insn4; \ + if (c->dill_debug) \ + dump_cur_dill_insn(c); \ + c->p->cur_ip = ((char*)c->p->cur_ip) + 4; \ + } while (0) -#define BYTE_OUT5(c, insn1, insn2, insn3, insn4, insn5) \ -do { \ -if (c->p->cur_ip >= c->p->code_limit) {\ - extend_dill_stream(c);\ -}\ -*(unsigned char*)c->p->cur_ip = (unsigned char)insn1;\ -*(((unsigned char*)c->p->cur_ip) + 1)= (unsigned char)insn2;\ -*(((unsigned char*)c->p->cur_ip) + 2)= (unsigned char)insn3;\ -*(((unsigned char*)c->p->cur_ip) + 3)= (unsigned char)insn4;\ -*(((unsigned char*)c->p->cur_ip) + 4)= (unsigned char)insn5;\ -if (c->dill_debug) dump_cur_dill_insn(c);\ - c->p->cur_ip = ((char*)c->p->cur_ip)+5; \ -} while (0) +#define BYTE_OUT5(c, insn1, insn2, insn3, insn4, insn5) \ + do { \ + if (c->p->cur_ip >= c->p->code_limit) { \ + extend_dill_stream(c); \ + } \ + *(unsigned char*)c->p->cur_ip = (unsigned char)insn1; \ + *(((unsigned char*)c->p->cur_ip) + 1) = (unsigned char)insn2; \ + *(((unsigned char*)c->p->cur_ip) + 2) = (unsigned char)insn3; \ + *(((unsigned char*)c->p->cur_ip) + 3) = (unsigned char)insn4; \ + *(((unsigned char*)c->p->cur_ip) + 4) = (unsigned char)insn5; \ + if (c->dill_debug) \ + dump_cur_dill_insn(c); \ + c->p->cur_ip = ((char*)c->p->cur_ip) + 5; \ + } while (0) -#define BYTE_OUT6(c, insn1, insn2, insn3, insn4, insn5, insn6) \ -do { \ -if (c->p->cur_ip >= c->p->code_limit) {\ - extend_dill_stream(c);\ -}\ -*(unsigned char*)c->p->cur_ip = (unsigned char)insn1;\ -*(((unsigned char*)c->p->cur_ip) + 1)= (unsigned char)insn2;\ -*(((unsigned char*)c->p->cur_ip) + 2)= (unsigned char)insn3;\ -*(((unsigned char*)c->p->cur_ip) + 3)= (unsigned char)insn4;\ -*(((unsigned char*)c->p->cur_ip) + 4)= (unsigned char)insn5;\ -*(((unsigned char*)c->p->cur_ip) + 5)= (unsigned char)insn6;\ -if (c->dill_debug) dump_cur_dill_insn(c);\ - c->p->cur_ip = ((char*)c->p->cur_ip)+6; \ -} while (0) +#define BYTE_OUT6(c, insn1, insn2, insn3, insn4, insn5, insn6) \ + do { \ + if (c->p->cur_ip >= c->p->code_limit) { \ + extend_dill_stream(c); \ + } \ + *(unsigned char*)c->p->cur_ip = (unsigned char)insn1; \ + *(((unsigned char*)c->p->cur_ip) + 1) = (unsigned char)insn2; \ + *(((unsigned char*)c->p->cur_ip) + 2) = (unsigned char)insn3; \ + *(((unsigned char*)c->p->cur_ip) + 3) = (unsigned char)insn4; \ + *(((unsigned char*)c->p->cur_ip) + 4) = (unsigned char)insn5; \ + *(((unsigned char*)c->p->cur_ip) + 5) = (unsigned char)insn6; \ + if (c->dill_debug) \ + dump_cur_dill_insn(c); \ + c->p->cur_ip = ((char*)c->p->cur_ip) + 6; \ + } while (0) -#define BYTE_OUT3I(c, insn1, insn2, insn3, imm32) \ -do { \ -if (c->p->cur_ip >= c->p->code_limit) {\ - extend_dill_stream(c);\ -}\ -*(unsigned char*)c->p->cur_ip = (unsigned char)insn1;\ -*(((unsigned char*)c->p->cur_ip) + 1)= (unsigned char)insn2;\ -*(((unsigned char*)c->p->cur_ip) + 2)= (unsigned char)insn3;\ -*(unsigned int *)(((unsigned char*)c->p->cur_ip) + 3)= (unsigned int)imm32;\ -if (c->dill_debug) dump_cur_dill_insn(c);\ - c->p->cur_ip = ((char*)c->p->cur_ip)+7; \ -} while (0) +#define BYTE_OUT3I(c, insn1, insn2, insn3, imm32) \ + do { \ + if (c->p->cur_ip >= c->p->code_limit) { \ + extend_dill_stream(c); \ + } \ + *(unsigned char*)c->p->cur_ip = (unsigned char)insn1; \ + *(((unsigned char*)c->p->cur_ip) + 1) = (unsigned char)insn2; \ + *(((unsigned char*)c->p->cur_ip) + 2) = (unsigned char)insn3; \ + *(unsigned int*)(((unsigned char*)c->p->cur_ip) + 3) = \ + (unsigned int)imm32; \ + if (c->dill_debug) \ + dump_cur_dill_insn(c); \ + c->p->cur_ip = ((char*)c->p->cur_ip) + 7; \ + } while (0) -#define BYTE_OUT3S(c, insn1, insn2, insn3, imm16) \ -do { \ -if (c->p->cur_ip >= c->p->code_limit) {\ - extend_dill_stream(c);\ -}\ -*(unsigned char*)c->p->cur_ip = (unsigned char)insn1;\ -*(((unsigned char*)c->p->cur_ip) + 1)= (unsigned char)insn2;\ -*(((unsigned char*)c->p->cur_ip) + 2)= (unsigned char)insn3;\ -*(unsigned short *)(((unsigned char*)c->p->cur_ip) + 3)= (unsigned short)imm16;\ -if (c->dill_debug) dump_cur_dill_insn(c);\ - c->p->cur_ip = ((char*)c->p->cur_ip)+5; \ -} while (0) +#define BYTE_OUT3S(c, insn1, insn2, insn3, imm16) \ + do { \ + if (c->p->cur_ip >= c->p->code_limit) { \ + extend_dill_stream(c); \ + } \ + *(unsigned char*)c->p->cur_ip = (unsigned char)insn1; \ + *(((unsigned char*)c->p->cur_ip) + 1) = (unsigned char)insn2; \ + *(((unsigned char*)c->p->cur_ip) + 2) = (unsigned char)insn3; \ + *(unsigned short*)(((unsigned char*)c->p->cur_ip) + 3) = \ + (unsigned short)imm16; \ + if (c->dill_debug) \ + dump_cur_dill_insn(c); \ + c->p->cur_ip = ((char*)c->p->cur_ip) + 5; \ + } while (0) -#define BYTE_OUT1I(c, insn1, imm32) \ -do { \ -if (c->p->cur_ip >= c->p->code_limit) {\ - extend_dill_stream(c);\ -}\ -*(unsigned char*)c->p->cur_ip = (unsigned char)insn1;\ -*(unsigned int *)(((unsigned char*)c->p->cur_ip) + 1)= (unsigned int)imm32;\ -if (c->dill_debug) dump_cur_dill_insn(c);\ - c->p->cur_ip = ((char*)c->p->cur_ip)+5; \ -} while (0) +#define BYTE_OUT1I(c, insn1, imm32) \ + do { \ + if (c->p->cur_ip >= c->p->code_limit) { \ + extend_dill_stream(c); \ + } \ + *(unsigned char*)c->p->cur_ip = (unsigned char)insn1; \ + *(unsigned int*)(((unsigned char*)c->p->cur_ip) + 1) = \ + (unsigned int)imm32; \ + if (c->dill_debug) \ + dump_cur_dill_insn(c); \ + c->p->cur_ip = ((char*)c->p->cur_ip) + 5; \ + } while (0) -#define BYTE_OUT2I(c, insn1, insn2,imm32) \ -do { \ -unsigned int tmp = (unsigned int) imm32; \ -if (c->p->cur_ip >= c->p->code_limit) {\ - extend_dill_stream(c);\ -}\ -*(unsigned char*)c->p->cur_ip = (unsigned char)insn1;\ -*(((unsigned char*)c->p->cur_ip) + 1)= (unsigned char)insn2;\ -memcpy((((unsigned char*)c->p->cur_ip) + 2), &tmp, 4);\ -if (c->dill_debug) dump_cur_dill_insn(c);\ - c->p->cur_ip = ((char*)c->p->cur_ip)+6; \ -} while (0) +#define BYTE_OUT2I(c, insn1, insn2, imm32) \ + do { \ + unsigned int tmp = (unsigned int)imm32; \ + if (c->p->cur_ip >= c->p->code_limit) { \ + extend_dill_stream(c); \ + } \ + *(unsigned char*)c->p->cur_ip = (unsigned char)insn1; \ + *(((unsigned char*)c->p->cur_ip) + 1) = (unsigned char)insn2; \ + memcpy((((unsigned char*)c->p->cur_ip) + 2), &tmp, 4); \ + if (c->dill_debug) \ + dump_cur_dill_insn(c); \ + c->p->cur_ip = ((char*)c->p->cur_ip) + 6; \ + } while (0) -#define BYTE_OUT2II(c, insn1, insn2,imm32, imm32_2) \ -do { \ -unsigned int tmp = (unsigned int) imm32;\ -unsigned int tmp2 = (unsigned int) imm32_2;\ -if (c->p->cur_ip >= c->p->code_limit) {\ - extend_dill_stream(c);\ -}\ -*(unsigned char*)c->p->cur_ip = (unsigned char)insn1;\ -*(((unsigned char*)c->p->cur_ip) + 1)= (unsigned char)insn2;\ -memcpy((((unsigned char*)c->p->cur_ip) + 2), &tmp, 4);\ -memcpy((((unsigned char*)c->p->cur_ip) + 6), &tmp2, 4);\ -if (c->dill_debug) dump_cur_dill_insn(c);\ - c->p->cur_ip = ((char*)c->p->cur_ip)+10; \ -} while (0) - -#ifdef LINUX_KERNEL_MODULE -#undef EAX -#undef ECX -#undef EDX -#undef EBX -#undef ESP -#undef EBP -#undef ESI -#undef EDI -#endif +#define BYTE_OUT2II(c, insn1, insn2, imm32, imm32_2) \ + do { \ + unsigned int tmp = (unsigned int)imm32; \ + unsigned int tmp2 = (unsigned int)imm32_2; \ + if (c->p->cur_ip >= c->p->code_limit) { \ + extend_dill_stream(c); \ + } \ + *(unsigned char*)c->p->cur_ip = (unsigned char)insn1; \ + *(((unsigned char*)c->p->cur_ip) + 1) = (unsigned char)insn2; \ + memcpy((((unsigned char*)c->p->cur_ip) + 2), &tmp, 4); \ + memcpy((((unsigned char*)c->p->cur_ip) + 6), &tmp2, 4); \ + if (c->dill_debug) \ + dump_cur_dill_insn(c); \ + c->p->cur_ip = ((char*)c->p->cur_ip) + 10; \ + } while (0) enum { - AL = 0, CL, DL, BL, AH, CH, DH, BH, /* r8 */ - AX = 0, CX, DX, BX, SP, BP, SI, DI, /* r16 */ - EAX = 0, ECX, EDX, EBX, ESP, EBP, ESI, EDI, /* r32 */ - RAX = 0, RCX, RDX, RBX, RSP, RBP, RSI, RDI, R8, R9, R10, R11, R12, R13, R14, R15, /* r64 */ - XMM0 = 0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7, XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15 + AL = 0, + CL, + DL, + BL, + AH, + CH, + DH, + BH, /* r8 */ + AX = 0, + CX, + DX, + BX, + SP, + BP, + SI, + DI, /* r16 */ + EAX = 0, + ECX, + EDX, + EBX, + ESP, + EBP, + ESI, + EDI, /* r32 */ + RAX = 0, + RCX, + RDX, + RBX, + RSP, + RBP, + RSI, + RDI, + R8, + R9, + R10, + R11, + R12, + R13, + R14, + R15, /* r64 */ + XMM0 = 0, + XMM1, + XMM2, + XMM3, + XMM4, + XMM5, + XMM6, + XMM7, + XMM8, + XMM9, + XMM10, + XMM11, + XMM12, + XMM13, + XMM14, + XMM15 }; #define REX_W 0x8 @@ -180,57 +234,124 @@ typedef struct x86_64_mach_info { int call_backpatch_offset; int call_stack_space; char pending_prefix; - char *last_proc_ret_end; + char* last_proc_ret_end; int varidiac_call; int non_var_args; -} *x86_64_mach_info; +} * x86_64_mach_info; extern int x86_64_type_align[]; extern int x86_64_type_size[]; -extern void *gen_x86_64_mach_info(); -extern void x86_64_arith3(dill_stream c, int op, int commut, int dest, int src1, int src2); -extern void x86_64_arith2(dill_stream c, int op, int subop, int dest, int src); -extern void x86_64_mul(dill_stream c, int signed, int imm, int dest, int src1, IMM_TYPE src2); +extern void* +gen_x86_64_mach_info(dill_stream s); +extern void +x86_64_arith3(dill_stream c, int op, int commut, int dest, int src1, int src2); +extern void +x86_64_arith2(dill_stream c, int op, int subop, int dest, int src); +extern void +x86_64_mul(dill_stream c, + int signed, + int imm, + int dest, + int src1, + IMM_TYPE src2); -extern void x86_64_div_mod(dill_stream c, int sign, int div, int dest, int src1, int src2); -extern void x86_64_div_modi(dill_stream c, int sign, int div, int dest, int src1, IMM_TYPE imm); -extern void x86_64_arith3i(dill_stream c, int op, int commut, int dest, int src1, IMM_TYPE src2); -extern void x86_64_shift(dill_stream c, int op, int junk, int dest, int src1, int src2); -extern void x86_64_shifti(dill_stream c, int op, int junk, int dest, int src, IMM_TYPE imm); -extern void x86_64_special(dill_stream c, special_operations type, IMM_TYPE param); -extern void x86_64_set(dill_stream c, int r, IMM_TYPE imm); -extern void x86_64_proc_start(dill_stream c, char *subr_name, int arg_count, - arg_info_list args, dill_reg *arglist); -extern void x86_64_end(dill_stream c); -extern void x86_64_package_end(dill_stream c); -extern void *x86_64_clone_code(dill_stream c, void *base, int size); -extern void x86_64_ret(dill_stream c, int data1, int data2, int src); -extern void x86_64_reti(dill_stream c, int data1, int data2, IMM_TYPE imm); -extern void x86_64_retf(dill_stream c, int data1, int data2, double imm); -extern int x86_64_getreg(dill_stream c, dill_reg *reg_p, int type, int class); -extern int x86_64_putreg(dill_stream c, dill_reg reg, int type); -extern void -x86_64_ploadi(dill_stream c, int type, int junk, int dest, int src, IMM_TYPE offset); +extern void +x86_64_div_mod(dill_stream c, int sign, int div, int dest, int src1, int src2); +extern void +x86_64_div_modi(dill_stream c, + int sign, + int div, + int dest, + int src1, + IMM_TYPE imm); +extern void +x86_64_arith3i(dill_stream c, + int op, + int commut, + int dest, + int src1, + IMM_TYPE src2); +extern void +x86_64_shift(dill_stream c, int op, int junk, int dest, int src1, int src2); +extern void +x86_64_shifti(dill_stream c, int op, int junk, int dest, int src, IMM_TYPE imm); +extern void +x86_64_special(dill_stream c, special_operations type, IMM_TYPE param); +extern void +x86_64_set(dill_stream c, int r, IMM_TYPE imm); +extern void +x86_64_proc_start(dill_stream c, + char* subr_name, + int arg_count, + arg_info_list args, + dill_reg* arglist); +extern void +x86_64_end(dill_stream c); +extern void +x86_64_package_end(dill_stream c); +extern void* +x86_64_clone_code(dill_stream c, void* base, int size); +extern void +x86_64_ret(dill_stream c, int data1, int data2, int src); +extern void +x86_64_reti(dill_stream c, int data1, int data2, IMM_TYPE imm); +extern void +x86_64_retf(dill_stream c, int data1, int data2, double imm); +extern int +x86_64_getreg(dill_stream c, dill_reg* reg_p, int type, int class); +extern int +x86_64_putreg(dill_stream c, dill_reg reg, int type); +extern void +x86_64_ploadi(dill_stream c, + int type, + int junk, + int dest, + int src, + IMM_TYPE offset); extern void x86_64_pload(dill_stream c, int type, int junk, int dest, int src1, int src2); extern void -x86_64_pbsloadi(dill_stream c, int type, int junk, int dest, int src, IMM_TYPE offset); +x86_64_pbsloadi(dill_stream c, + int type, + int junk, + int dest, + int src, + IMM_TYPE offset); extern void x86_64_pbsload(dill_stream c, int type, int junk, int dest, int src1, int src2); extern void -x86_64_pstorei(dill_stream c, int type, int junk, int dest, int src, IMM_TYPE offset); +x86_64_pstorei(dill_stream c, + int type, + int junk, + int dest, + int src, + IMM_TYPE offset); extern void x86_64_pstore(dill_stream c, int type, int junk, int dest, int src1, int src2); extern void -x86_64_modi(dill_stream c, int type, int junk, int dest, int src, IMM_TYPE offset); +x86_64_modi(dill_stream c, + int type, + int junk, + int dest, + int src, + IMM_TYPE offset); extern void x86_64_mod(dill_stream c, int type, int junk, int dest, int src1, int src2); extern void -x86_64_divi(dill_stream c, int type, int junk, int dest, int src, IMM_TYPE offset); +x86_64_divi(dill_stream c, + int type, + int junk, + int dest, + int src, + IMM_TYPE offset); extern void x86_64_div(dill_stream c, int type, int junk, int dest, int src1, int src2); extern void -x86_64_converti(dill_stream c, int from_type, int to_type, int dest, IMM_TYPE src); +x86_64_converti(dill_stream c, + int from_type, + int to_type, + int dest, + IMM_TYPE src); extern void x86_64_convert(dill_stream c, int from_type, int to_type, int dest, int src); extern void @@ -240,39 +361,67 @@ x86_64_pset(dill_stream c, int type, int junk, int dest, IMM_TYPE imm); extern void x86_64_setf(dill_stream c, int type, int junk, int dest, double imm); extern void -x86_64_setp(dill_stream c, int type, int junk, int dest, void *imm); +x86_64_setp(dill_stream c, int type, int junk, int dest, void* imm); extern void x86_64_branch(dill_stream c, int op, int type, int src1, int src2, int label); extern void -x86_64_branchi(dill_stream c, int op, int type, int src, IMM_TYPE imm, int label); +x86_64_branchi(dill_stream c, + int op, + int type, + int src, + IMM_TYPE imm, + int label); extern void x86_64_compare(dill_stream s, int op, int type, int dest, int src1, int src2); extern void -x86_64_comparei(dill_stream s, int op, int type, int dest, int src, IMM_TYPE imm); -extern void +x86_64_comparei(dill_stream s, + int op, + int type, + int dest, + int src, + IMM_TYPE imm); +extern void x86_64_lea(dill_stream c, int junk, int junk1, int dest, int src, IMM_TYPE imm); -extern void +extern void x86_64_farith(dill_stream c, int op, int typ, int dest, int src1, int src2); -extern void +extern void x86_64_farith2(dill_stream c, int op, int typ, int dest, int src); -extern void x86_64_bswap(dill_stream c, int op, int typ, int dest, int src); -extern void x86_64_jump_to_label(dill_stream c, unsigned long label); -extern void x86_64_jump_to_reg(dill_stream c, unsigned long reg); -extern void x86_64_jump_to_imm(dill_stream c, void *imm); -extern void x86_64_jal(dill_stream c, int return_addr_reg, int target); -extern int x86_64_calli(dill_stream c, int type, void *xfer_address, const char *name); -extern int x86_64_callr(dill_stream c, int type, int src); -extern void x86_64_push(dill_stream c, int type, int reg); -extern void x86_64_pushi(dill_stream c, int type, IMM_TYPE value); -extern void x86_64_pushpi(dill_stream c, int type, void *value); -extern void x86_64_pushfi(dill_stream c, int type, double value); -extern int x86_64_local_op(dill_stream c, int flag, int val); -extern int x86_64_local(dill_stream c, int type); -extern int x86_64_localb(dill_stream c, int size); -extern void x86_64_save_restore_op(dill_stream c, int save_restore, int type, - int reg); -extern int x86_64_init_disassembly_info(dill_stream c, void * ptr); -extern int x86_64_print_insn(dill_stream c, void *info_ptr, void *insn); -extern int x86_64_count_insn(dill_stream c, int start, int end); -extern void x86_64_print_reg(dill_stream c, int typ, int reg); +extern void +x86_64_bswap(dill_stream c, int op, int typ, int dest, int src); +extern void +x86_64_jump_to_label(dill_stream c, unsigned long label); +extern void +x86_64_jump_to_reg(dill_stream c, unsigned long reg); +extern void +x86_64_jump_to_imm(dill_stream c, void* imm); +extern void +x86_64_jal(dill_stream c, int return_addr_reg, int target); +extern int +x86_64_calli(dill_stream c, int type, void* xfer_address, const char* name); +extern int +x86_64_callr(dill_stream c, int type, int src); +extern void +x86_64_push(dill_stream c, int type, int reg); +extern void +x86_64_pushi(dill_stream c, int type, IMM_TYPE value); +extern void +x86_64_pushpi(dill_stream c, int type, void* value); +extern void +x86_64_pushfi(dill_stream c, int type, double value); +extern int +x86_64_local_op(dill_stream c, int flag, int val); +extern int +x86_64_local(dill_stream c, int type); +extern int +x86_64_localb(dill_stream c, int size); +extern void +x86_64_save_restore_op(dill_stream c, int save_restore, int type, int reg); +extern int +x86_64_init_disassembly_info(dill_stream c, void* ptr); +extern int +x86_64_print_insn(dill_stream c, void* info_ptr, void* insn); +extern int +x86_64_count_insn(dill_stream c, int start, int end); +extern void +x86_64_print_reg(dill_stream c, int typ, int reg); #endif diff --git a/x86_64_disassembler.c b/x86_64_disassembler.c index 4bd4217ef8..7cf6c50df4 100644 --- a/x86_64_disassembler.c +++ b/x86_64_disassembler.c @@ -1,750 +1,796 @@ /* - * This file is not an official part of DILL, but is included temporarily for debugging purposes. - * It is a modification of disassembler.c from https://github.com/btbd/disassembler. (Modified to compile on windows.) And is subject to the APACHE license. + * This file is not an official part of DILL, but is included temporarily for + * debugging purposes. It is a modification of disassembler.c from + * https://github.com/btbd/disassembler. (Modified to compile on windows.) And + * is subject to the APACHE license. */ #include #include #include -unsigned int x86_64_disassemble(unsigned char *bytes, unsigned int max, int offset, char *output) { - static char register_mnemonics8[][0xF] = { "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh" }; - static char register_mnemonics16[][0xF] = { "ax", "cx", "dx", "bx", "ax", "cx", "dx", "bx" }; - static char register_mnemonics32[][0xF] = { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi" }; +unsigned int +x86_64_disassemble(unsigned char* bytes, + unsigned int max, + int offset, + char* output) +{ + static char register_mnemonics8[][0xF] = {"al", "cl", "dl", "bl", + "ah", "ch", "dh", "bh"}; + static char register_mnemonics16[][0xF] = {"ax", "cx", "dx", "bx", + "ax", "cx", "dx", "bx"}; + static char register_mnemonics32[][0xF] = {"eax", "ecx", "edx", "ebx", + "esp", "ebp", "esi", "edi"}; - static char sib_base_mnemonics[][0xF] = { "[eax", "[ecx", "[edx", "[ebx", "[esp", "[ebp", "[esi", "[edi" }; - static char sib_scale_mnemonics[][0xF] = { "*1", "*2", "*4", "*8" }; + static char sib_base_mnemonics[][0xF] = {"[eax", "[ecx", "[edx", "[ebx", + "[esp", "[ebp", "[esi", "[edi"}; + static char sib_scale_mnemonics[][0xF] = {"*1", "*2", "*4", "*8"}; - enum { - AL, EAX, ES, CS, SS, DS, ONE, CL, XMM0, BND0, BAD, MM0, - IMM8, IMM16, IMM32, REL8, REL32, PTR1632, R, RM, - BYTE, WORD, DWORD, QWORD, FWORD, XMMWORD - }; + enum { + AL, + EAX, + ES, + CS, + SS, + DS, + ONE, + CL, + XMM0, + BND0, + BAD, + MM0, + IMM8, + IMM16, + IMM32, + REL8, + REL32, + PTR1632, + R, + RM, + BYTE, + WORD, + DWORD, + QWORD, + FWORD, + XMMWORD + }; - typedef struct { - char hasModRM, size; - char mnemonic[0xFF]; - char argument_count; - char arguments[4]; - } INSTRUCTION; + typedef struct { + char hasModRM, size; + char mnemonic[0xFF]; + char argument_count; + char arguments[4]; + } INSTRUCTION; - static INSTRUCTION standard_instructions[] = { - { 1, BYTE, "add ", 2, {RM, R} }, // 0 - { 1, DWORD, "add ", 2, {RM, R} }, // 1 - { 1, BYTE, "add ", 2, {R, RM} }, // 2 - { 1, DWORD, "add ", 2, {R, RM} }, // 3 - { 0, 0, "add ", 2, {AL, IMM8} }, // 4 - { 0, 0, "add ", 2, {EAX, IMM32} }, // 5 - { 0, 0, "push es", 0 }, // 6 - { 0, 0, "pop es", 0 }, // 7 - { 1, BYTE, "or ", 2, {RM, R} }, // 8 - { 1, DWORD, "or ", 2, {RM, R} }, // 9 - { 1, BYTE, "or ", 2, {R, RM} }, // A - { 1, DWORD, "or ", 2, {R, RM} }, // B - { 0, 0, "or ", 2, {AL, IMM8} }, // C - { 0, 0, "or ", 2, {EAX, IMM32} }, // D - { 0, 0, "push cs", 0 }, // E - { 0 }, // F - Two-byte instructions - { 1, BYTE, "adc ", 2, {RM, R} }, // 10 - { 1, DWORD, "adc ", 2, {RM, R} }, // 11 - { 1, BYTE, "adc ", 2, {R, RM} }, // 12 - { 1, DWORD, "adc ", 2, {R, RM} }, // 13 - { 0, 0, "adc ", 2, {AL, IMM8} }, // 14 - { 0, 0, "adc ", 2, {EAX, IMM32} }, // 15 - { 0, 0, "push ss", 0 }, // 16 - { 0, 0, "pop ss", 0 }, // 17 - { 1, BYTE, "sbb ", 2, {RM, R} }, // 18 - { 1, DWORD, "sbb ", 2, {RM, R} }, // 19 - { 1, BYTE, "sbb ", 2, {R, RM} }, // 1A - { 1, DWORD, "sbb ", 2, {R, R} }, // 1B - { 0, 0, "sbb ", 2, {AL, IMM8} }, // 1C - { 0, 0, "sbb ", 2, {EAX, IMM32} }, // 1D - { 0, 0, "push ds", 0 }, // 1E - { 0, 0, "pop ds", 0 }, // 1F - { 1, BYTE, "and ", 2, {RM, R} }, // 20 - { 1, DWORD, "and ", 2, {RM, R} }, // 21 - { 1, BYTE, "and ", 2, {R, RM} }, // 22 - { 1, DWORD, "and ", 2, {R, RM} }, // 23 - { 0, 0, "and ", 2, {AL, IMM8} }, // 24 - { 0, 0, "and ", 2, {EAX, IMM32} }, // 25 - { 0, 0, "es ", 0 }, // 26 - { 0, 0, "daa ", 0 }, // 27 - { 1, BYTE, "sub ", 2, {RM, R} }, // 28 - { 1, DWORD, "sub ", 2, {RM, R} }, // 29 - { 1, BYTE, "sub ", 2, {R, RM} }, // 2A - { 1, DWORD, "sub ", 2, {R, RM} }, // 2B - { 0, 0, "sub ", 2, {AL, IMM8} }, // 2C - { 0, 0, "sub ", 2, {EAX, IMM32} }, // 2D - { 0, 0, "cs ", 0 }, // 2E - { 0, 0, "das ", 0 }, // 2F - { 1, BYTE, "xor ", 2, {RM, R} }, // 30 - { 1, DWORD, "xor ", 2, {RM, R} }, // 31 - { 1, BYTE, "xor ", 2, {R, RM} }, // 32 - { 1, DWORD, "xor ", 2, {R, RM} }, // 33 - { 0, 0, "xor ", 2, {AL, IMM8} }, // 34 - { 0, 0, "xor ", 2, {EAX, IMM32} }, // 35 - { 0, 0, "ss ", 0 }, // 36 - { 0, 0, "aaa ", 0 }, // 37 - { 1, BYTE, "cmp ", 2, {RM, R} }, // 38 - { 1, DWORD, "cmp ", 2, {RM, R} }, // 39 - { 1, BYTE, "cmp ", 2, {R, RM} }, // 3A - { 1, DWORD, "cmp ", 2, {R, RM} }, // 3B - { 0, 0, "cmp ", 2, {AL, IMM8} }, // 3C - { 0, 0, "cmp ", 2, {EAX, IMM32} }, // 3D - { 0, 0, "ds ", 0 }, // 3E - { 0, 0, "aas ", 0 }, // 3F - { 0, 0, "inc eax", 0 }, // 40 - { 0, 0, "inc ecx", 0 }, // 41 - { 0, 0, "inc edx", 0 }, // 42 - { 0, 0, "inc ebx", 0 }, // 43 - { 0, 0, "inc esp", 0 }, // 44 - { 0, 0, "inc ebp", 0 }, // 45 - { 0, 0, "inc esi", 0 }, // 46 - { 0, 0, "inc edi", 0 }, // 47 - { 0, 0, "dec eax", 0 }, // 48 - { 0, 0, "dec ecx", 0 }, // 49 - { 0, 0, "dec edx", 0 }, // 4A - { 0, 0, "dec ebx", 0 }, // 4B - { 0, 0, "dec esp", 0 }, // 4C - { 0, 0, "dec ebp", 0 }, // 4D - { 0, 0, "dec esi", 0 }, // 4E - { 0, 0, "dec edi", 0 }, // 4F - { 0, 0, "push eax", 0 }, // 50 - { 0, 0, "push ecx", 0 }, // 51 - { 0, 0, "push edx", 0 }, // 52 - { 0, 0, "push ebx", 0 }, // 53 - { 0, 0, "push esp", 0 }, // 54 - { 0, 0, "push ebp", 0 }, // 55 - { 0, 0, "push esi", 0 }, // 56 - { 0, 0, "push edi", 0 }, // 57 - { 0, 0, "pop eax", 0 }, // 58 - { 0, 0, "pop ecx", 0 }, // 59 - { 0, 0, "pop edx", 0 }, // 5A - { 0, 0, "pop ebx", 0 }, // 5B - { 0, 0, "pop esp", 0 }, // 5C - { 0, 0, "pop ebp", 0 }, // 5D - { 0, 0, "pop esi", 0 }, // 5E - { 0, 0, "pop edi", 0 }, // 5F - { 0, 0, "pusha", 0 }, // 60 - { 0, 0, "popa", 0 }, // 61 - { 1, QWORD, "bound ", 2, {R, RM} }, // 62 - { 1, WORD, "arpl ", 2, {RM, R} }, // 63 - { 0, 0, "fs ", 0 }, // 64 - { 0, 0, "gs ", 0 }, // 65 - { 0, 0, "data16 ", 0 }, // 66 - { 0, 0, "addr16 ", 0 }, // 67 - { 0, 0, "push ", 1, {IMM32} }, // 68 - { 1, DWORD, "imul ", 3, {R, RM, IMM32} }, // 69 - { 0, 0, "push ", 1, {IMM8} }, // 6A - { 1, DWORD, "imul ", 3, {R, RM, IMM8} }, // 6B - { 0, 0, "ins BYTE PTR es:[edi],dx", 0 }, // 6C - { 0, 0, "ins DWORD PTR es:[edi],dx", 0 }, // 6D - { 0, 0, "outs dx,BYTE PTR ds:[esi]", 0 }, // 6E - { 0, 0, "outs dx,DWORD PTR ds:[esi]", 0 }, // 6F - { 0, 0, "jo ", 1, {REL8} }, // 70 - { 0, 0, "jno ", 1, {REL8} }, // 71 - { 0, 0, "jb ", 1, {REL8} }, // 72 - { 0, 0, "jnb ", 1, {REL8} }, // 73 - { 0, 0, "jz ", 1, {REL8} }, // 74 - { 0, 0, "jne ", 1, {REL8} }, // 75 - { 0, 0, "jbe ", 1, {REL8} }, // 76 - { 0, 0, "ja ", 1, {REL8} }, // 77 - { 0, 0, "js ", 1, {REL8} }, // 78 - { 0, 0, "jns ", 1, {REL8} }, // 79 - { 0, 0, "jp ", 1, {REL8} }, // 7A - { 0, 0, "jnp ", 1, {REL8} }, // 7B - { 0, 0, "jl ", 1, {REL8} }, // 7C - { 0, 0, "jnl ", 1, {REL8} }, // 7D - { 0, 0, "jle ", 1, {REL8} }, // 7E - { 0, 0, "jnle ", 1, {REL8} }, // 7F - { 1, BYTE, "add ", 2, {RM, IMM8} }, // 80 - { 1, DWORD, "add ", 2, {RM, IMM32} }, // 81 - { 0, 0, ".byte 0x82", 0 }, // 82 - { 1, DWORD, "adc ", 2, {RM, IMM8} }, // 83 - { 1, BYTE, "test ", 2, {RM, R} }, // 84 - { 1, DWORD, "test ", 2, {RM, R} }, // 85 - { 1, BYTE, "xchg ", 2, {RM, R} }, // 86 - { 1, DWORD, "xchg ", 2, {RM, R} }, // 87 - { 1, BYTE, "mov ", 2, {RM, R} }, // 88 - { 1, DWORD, "mov ", 2, {RM, R} }, // 89 - { 1, BYTE, "mov ", 2, {R, RM} }, // 8A - { 1, DWORD, "mov ", 2, {R, RM} }, // 8B - { 1, WORD, "mov ", 2, {RM, SS} }, // 8C - { 1, 0, "lea ", 2, {R, RM} }, // 8D - { 1, WORD, "mov ss,", 1, {RM} }, // 8E - { 1, DWORD, "pop ", 1, {RM} }, // 8F - { 0, 0, "nop", 0 }, // 90 - { 0, 0, "xchg ecx,eax", 0 }, // 91 - { 0, 0, "xchg edx,eax", 0 }, // 92 - { 0, 0, "xchg ebx,eax", 0 }, // 93 - { 0, 0, "xchg esp,eax", 0 }, // 94 - { 0, 0, "xchg ebp,eax", 0 }, // 95 - { 0, 0, "xchg esi,eax", 0 }, // 96 - { 0, 0, "xchg edi,eax", 0 }, // 97 - { 0, 0, "cwde", 0 }, // 98 - { 0, 0, "cdq", 0 }, // 99 - { 0, 0, "call ", 1, {PTR1632} }, // 9A - { 0, 0, "fwait", 0 }, // 9B - { 0, 0, "pushf", 0 }, // 9C - { 0, 0, "popf", 0 }, // 9D - { 0, 0, "sahf", 0 }, // 9E - { 0, 0, "lahf", 0 }, // 9F - { 0, 0, "mov al,ds:", 1, {IMM8} }, // A0 - { 0, 0, "mov eax,ds:", 1, {IMM8} }, // A1 - { 0, 0, "mov ds:", 2, {IMM8, AL} }, // A2 - { 0, 0, "mov ds:", 2, {IMM32, EAX} }, // A3 - { 0, 0, "movs BYTE PTR es:[edi],BYTE PTR ds:[esi]", 0 }, // A4 - { 0, 0, "movs DWORD PTR es:[edi],DWORD PTR ds:[esi]", 0 }, // A5 - { 0, 0, "cmps BYTE PTR es:[esi],BYTE PTR ds:[edi]", 0 }, // A6 - { 0, 0, "cmps DWORD PTR es:[esi],DWORD PTR ds:[edi]", 0 }, // A7 - { 0, 0, "test al,", 1, {IMM8} }, // A8 - { 0, 0, "test eax,", 1, {IMM32} }, // A9 - { 0, 0, "stos BYTE PTR es:[edi],al", 0 }, // AA - { 0, 0, "stos DWORD PTR es:[edi],eax", 0 }, // AB - { 0, 0, "lods al,BYTE PTR ds:[esi]", 0 }, // AC - { 0, 0, "lods eax,DWORD PTR ds:[esi]", 0 }, // AD - { 0, 0, "scas al,BYTE PTR es:[edi]", 0 }, // AE - { 0, 0, "scas eax,DWORD PTR es:[edi]", 0 }, // AF - { 0, 0, "mov al,", 1, {IMM8} }, // B0 - { 0, 0, "mov cl,", 1, {IMM8} }, // B1 - { 0, 0, "mov dl,", 1, {IMM8} }, // B2 - { 0, 0, "mov bl,", 1, {IMM8} }, // B3 - { 0, 0, "mov ah,", 1, {IMM8} }, // B4 - { 0, 0, "mov ch,", 1, {IMM8} }, // B5 - { 0, 0, "mov dh,", 1, {IMM8} }, // B6 - { 0, 0, "mov bh,", 1, {IMM8} }, // B7 - { 0, 0, "mov eax,", 1, {IMM32} }, // B8 - { 0, 0, "mov ecx,", 1, {IMM32} }, // B9 - { 0, 0, "mov edx,", 1, {IMM32} }, // BA - { 0, 0, "mov ebx,", 1, {IMM32} }, // BB - { 0, 0, "mov esp,", 1, {IMM32} }, // BC - { 0, 0, "mov ebp,", 1, {IMM32} }, // BD - { 0, 0, "mov esi,", 1, {IMM32} }, // BE - { 0, 0, "mov edi,", 1, {IMM32} }, // BF - { 1, BYTE, "rol ", 2, {RM, IMM8} }, // C0 - { 1, DWORD, "rol ", 2, {RM, IMM8} }, // C1 - { 0, 0, "ret ", 1, {IMM16} }, // C2 - { 0, 0, "ret", 0 }, // C3 - { 1, FWORD, "les eax,", 1, {RM} }, // C4 - { 1, FWORD, "lds eax,", 1, {RM} }, // C5 - { 1, BYTE, "mov ", 2, {RM, IMM8} }, // C6 - { 1, DWORD, "mov ", 2, {RM, IMM32} }, // C7 - { 0, 0, "enter ", 2, {IMM16, IMM8} }, // C8 - { 0, 0, "leave", 0 }, // C9 - { 0, 0, "retf ", 1, {IMM16} }, // CA - { 0, 0, "retf", 0 }, // CB - { 0, 0, "int3", 0 }, // CC - { 0, 0, "int ", 1, {IMM8} }, // CD - { 0, 0, "into", 0 }, // CE - { 0, 0, "iret", 0 }, // CF - { 1, BYTE, "rol ", 2, {RM, ONE} }, // D0 - { 1, DWORD, "rol ", 2, {RM, ONE} }, // D1 - { 1, BYTE, "rol ", 2, {RM, CL} }, // D2 - { 1, DWORD, "rol ", 2, {RM, CL} }, // D3 - { 0, 0, "aam ", 1, {IMM8} }, // D4 - { 0, 0, "aad ", 1, {IMM8} }, // D5 - { 0, 0, ".byte 0xd6", 0 }, // D6 - { 0, 0, "xlat BYTE PTR ds:[ebx]", 0 }, // D7 - { 1, DWORD, "fadd ", 1, {RM} }, // D8 - { 1, DWORD, "fld ", 1, {RM} }, // D9 - { 1, DWORD, "fiadd ", 1, {RM} }, // DA - { 1, DWORD, "fild ", 1, {RM} }, // DB - { 1, QWORD, "fadd ", 1, {RM} }, // DC - { 1, QWORD, "fld ", 1, {RM} }, // DD - { 1, WORD, "fiadd ", 1, {RM} }, // DE - { 1, WORD, "fild ", 1, {RM} }, // DF - { 0, 0, "loopne ", 1, {REL8} }, // E0 - { 0, 0, "loope ", 1, {REL8} }, // E1 - { 0, 0, "loop ", 1, {REL8} }, // E2 - { 0, 0, "jecxz ", 1, {REL8} }, // E3 - { 0, 0, "in al,", 1, {IMM8} }, // E4 - { 0, 0, "in eax,", 1, {IMM8} }, // E5 - { 0, 0, "out ", 2, {IMM8, AL} }, // E6 - { 0, 0, "out ", 2, {IMM8, EAX} }, // E7 - { 0, 0, "call ", 1, {REL32} }, // E8 - { 0, 0, "jmp ", 1, {REL32} }, // E9 - { 0, 0, "jmpf ", 1, {PTR1632} }, // EA - { 0, 0, "jmp ", 1, {REL8} }, // EB - { 0, 0, "in al,dx", 0 }, // EC - { 0, 0, "in eax,dx", 0 }, // ED - { 0, 0, "out dx,al", 0 }, // EE - { 0, 0, "out dx,eax", 0 }, // EF - { 0, 0, "lock ", 0 }, // F0 - { 0, 0, "icebp", 0 }, // F1 - { 0, 0, "repnz ", 0 }, // F2 - { 0, 0, "repz", 0 }, // F3 - { 0, 0, "hlt", 0 }, // F4 - { 0, 0, "cmc", 0 }, // F5 - { 1, BYTE, "test ", 2, {RM, IMM8} }, // F6 - { 1, DWORD, "test ", 2, {RM, IMM32} }, // F7 - { 0, 0, "clc", 0 }, // F8 - { 0, 0, "stc", 0 }, // F9 - { 0, 0, "cli", 0 }, // FA - { 0, 0, "sti", 0 }, // FB - { 0, 0, "cld", 0 }, // FC - { 0, 0, "std", 0 }, // FD - { 1, BYTE, "inc ", 1, {RM} }, // FE - { 1, DWORD, "inc ", 1, {RM} } // FF - }; + static INSTRUCTION standard_instructions[] = { + {1, BYTE, "add ", 2, {RM, R}}, // 0 + {1, DWORD, "add ", 2, {RM, R}}, // 1 + {1, BYTE, "add ", 2, {R, RM}}, // 2 + {1, DWORD, "add ", 2, {R, RM}}, // 3 + {0, 0, "add ", 2, {AL, IMM8}}, // 4 + {0, 0, "add ", 2, {EAX, IMM32}}, // 5 + {0, 0, "push es", 0}, // 6 + {0, 0, "pop es", 0}, // 7 + {1, BYTE, "or ", 2, {RM, R}}, // 8 + {1, DWORD, "or ", 2, {RM, R}}, // 9 + {1, BYTE, "or ", 2, {R, RM}}, // A + {1, DWORD, "or ", 2, {R, RM}}, // B + {0, 0, "or ", 2, {AL, IMM8}}, // C + {0, 0, "or ", 2, {EAX, IMM32}}, // D + {0, 0, "push cs", 0}, // E + {0}, // F - Two-byte instructions + {1, BYTE, "adc ", 2, {RM, R}}, // 10 + {1, DWORD, "adc ", 2, {RM, R}}, // 11 + {1, BYTE, "adc ", 2, {R, RM}}, // 12 + {1, DWORD, "adc ", 2, {R, RM}}, // 13 + {0, 0, "adc ", 2, {AL, IMM8}}, // 14 + {0, 0, "adc ", 2, {EAX, IMM32}}, // 15 + {0, 0, "push ss", 0}, // 16 + {0, 0, "pop ss", 0}, // 17 + {1, BYTE, "sbb ", 2, {RM, R}}, // 18 + {1, DWORD, "sbb ", 2, {RM, R}}, // 19 + {1, BYTE, "sbb ", 2, {R, RM}}, // 1A + {1, DWORD, "sbb ", 2, {R, R}}, // 1B + {0, 0, "sbb ", 2, {AL, IMM8}}, // 1C + {0, 0, "sbb ", 2, {EAX, IMM32}}, // 1D + {0, 0, "push ds", 0}, // 1E + {0, 0, "pop ds", 0}, // 1F + {1, BYTE, "and ", 2, {RM, R}}, // 20 + {1, DWORD, "and ", 2, {RM, R}}, // 21 + {1, BYTE, "and ", 2, {R, RM}}, // 22 + {1, DWORD, "and ", 2, {R, RM}}, // 23 + {0, 0, "and ", 2, {AL, IMM8}}, // 24 + {0, 0, "and ", 2, {EAX, IMM32}}, // 25 + {0, 0, "es ", 0}, // 26 + {0, 0, "daa ", 0}, // 27 + {1, BYTE, "sub ", 2, {RM, R}}, // 28 + {1, DWORD, "sub ", 2, {RM, R}}, // 29 + {1, BYTE, "sub ", 2, {R, RM}}, // 2A + {1, DWORD, "sub ", 2, {R, RM}}, // 2B + {0, 0, "sub ", 2, {AL, IMM8}}, // 2C + {0, 0, "sub ", 2, {EAX, IMM32}}, // 2D + {0, 0, "cs ", 0}, // 2E + {0, 0, "das ", 0}, // 2F + {1, BYTE, "xor ", 2, {RM, R}}, // 30 + {1, DWORD, "xor ", 2, {RM, R}}, // 31 + {1, BYTE, "xor ", 2, {R, RM}}, // 32 + {1, DWORD, "xor ", 2, {R, RM}}, // 33 + {0, 0, "xor ", 2, {AL, IMM8}}, // 34 + {0, 0, "xor ", 2, {EAX, IMM32}}, // 35 + {0, 0, "ss ", 0}, // 36 + {0, 0, "aaa ", 0}, // 37 + {1, BYTE, "cmp ", 2, {RM, R}}, // 38 + {1, DWORD, "cmp ", 2, {RM, R}}, // 39 + {1, BYTE, "cmp ", 2, {R, RM}}, // 3A + {1, DWORD, "cmp ", 2, {R, RM}}, // 3B + {0, 0, "cmp ", 2, {AL, IMM8}}, // 3C + {0, 0, "cmp ", 2, {EAX, IMM32}}, // 3D + {0, 0, "ds ", 0}, // 3E + {0, 0, "aas ", 0}, // 3F + {0, 0, "inc eax", 0}, // 40 + {0, 0, "inc ecx", 0}, // 41 + {0, 0, "inc edx", 0}, // 42 + {0, 0, "inc ebx", 0}, // 43 + {0, 0, "inc esp", 0}, // 44 + {0, 0, "inc ebp", 0}, // 45 + {0, 0, "inc esi", 0}, // 46 + {0, 0, "inc edi", 0}, // 47 + {0, 0, "dec eax", 0}, // 48 + {0, 0, "dec ecx", 0}, // 49 + {0, 0, "dec edx", 0}, // 4A + {0, 0, "dec ebx", 0}, // 4B + {0, 0, "dec esp", 0}, // 4C + {0, 0, "dec ebp", 0}, // 4D + {0, 0, "dec esi", 0}, // 4E + {0, 0, "dec edi", 0}, // 4F + {0, 0, "push eax", 0}, // 50 + {0, 0, "push ecx", 0}, // 51 + {0, 0, "push edx", 0}, // 52 + {0, 0, "push ebx", 0}, // 53 + {0, 0, "push esp", 0}, // 54 + {0, 0, "push ebp", 0}, // 55 + {0, 0, "push esi", 0}, // 56 + {0, 0, "push edi", 0}, // 57 + {0, 0, "pop eax", 0}, // 58 + {0, 0, "pop ecx", 0}, // 59 + {0, 0, "pop edx", 0}, // 5A + {0, 0, "pop ebx", 0}, // 5B + {0, 0, "pop esp", 0}, // 5C + {0, 0, "pop ebp", 0}, // 5D + {0, 0, "pop esi", 0}, // 5E + {0, 0, "pop edi", 0}, // 5F + {0, 0, "pusha", 0}, // 60 + {0, 0, "popa", 0}, // 61 + {1, QWORD, "bound ", 2, {R, RM}}, // 62 + {1, WORD, "arpl ", 2, {RM, R}}, // 63 + {0, 0, "fs ", 0}, // 64 + {0, 0, "gs ", 0}, // 65 + {0, 0, "data16 ", 0}, // 66 + {0, 0, "addr16 ", 0}, // 67 + {0, 0, "push ", 1, {IMM32}}, // 68 + {1, DWORD, "imul ", 3, {R, RM, IMM32}}, // 69 + {0, 0, "push ", 1, {IMM8}}, // 6A + {1, DWORD, "imul ", 3, {R, RM, IMM8}}, // 6B + {0, 0, "ins BYTE PTR es:[edi],dx", 0}, // 6C + {0, 0, "ins DWORD PTR es:[edi],dx", 0}, // 6D + {0, 0, "outs dx,BYTE PTR ds:[esi]", 0}, // 6E + {0, 0, "outs dx,DWORD PTR ds:[esi]", 0}, // 6F + {0, 0, "jo ", 1, {REL8}}, // 70 + {0, 0, "jno ", 1, {REL8}}, // 71 + {0, 0, "jb ", 1, {REL8}}, // 72 + {0, 0, "jnb ", 1, {REL8}}, // 73 + {0, 0, "jz ", 1, {REL8}}, // 74 + {0, 0, "jne ", 1, {REL8}}, // 75 + {0, 0, "jbe ", 1, {REL8}}, // 76 + {0, 0, "ja ", 1, {REL8}}, // 77 + {0, 0, "js ", 1, {REL8}}, // 78 + {0, 0, "jns ", 1, {REL8}}, // 79 + {0, 0, "jp ", 1, {REL8}}, // 7A + {0, 0, "jnp ", 1, {REL8}}, // 7B + {0, 0, "jl ", 1, {REL8}}, // 7C + {0, 0, "jnl ", 1, {REL8}}, // 7D + {0, 0, "jle ", 1, {REL8}}, // 7E + {0, 0, "jnle ", 1, {REL8}}, // 7F + {1, BYTE, "add ", 2, {RM, IMM8}}, // 80 + {1, DWORD, "add ", 2, {RM, IMM32}}, // 81 + {0, 0, ".byte 0x82", 0}, // 82 + {1, DWORD, "adc ", 2, {RM, IMM8}}, // 83 + {1, BYTE, "test ", 2, {RM, R}}, // 84 + {1, DWORD, "test ", 2, {RM, R}}, // 85 + {1, BYTE, "xchg ", 2, {RM, R}}, // 86 + {1, DWORD, "xchg ", 2, {RM, R}}, // 87 + {1, BYTE, "mov ", 2, {RM, R}}, // 88 + {1, DWORD, "mov ", 2, {RM, R}}, // 89 + {1, BYTE, "mov ", 2, {R, RM}}, // 8A + {1, DWORD, "mov ", 2, {R, RM}}, // 8B + {1, WORD, "mov ", 2, {RM, SS}}, // 8C + {1, 0, "lea ", 2, {R, RM}}, // 8D + {1, WORD, "mov ss,", 1, {RM}}, // 8E + {1, DWORD, "pop ", 1, {RM}}, // 8F + {0, 0, "nop", 0}, // 90 + {0, 0, "xchg ecx,eax", 0}, // 91 + {0, 0, "xchg edx,eax", 0}, // 92 + {0, 0, "xchg ebx,eax", 0}, // 93 + {0, 0, "xchg esp,eax", 0}, // 94 + {0, 0, "xchg ebp,eax", 0}, // 95 + {0, 0, "xchg esi,eax", 0}, // 96 + {0, 0, "xchg edi,eax", 0}, // 97 + {0, 0, "cwde", 0}, // 98 + {0, 0, "cdq", 0}, // 99 + {0, 0, "call ", 1, {PTR1632}}, // 9A + {0, 0, "fwait", 0}, // 9B + {0, 0, "pushf", 0}, // 9C + {0, 0, "popf", 0}, // 9D + {0, 0, "sahf", 0}, // 9E + {0, 0, "lahf", 0}, // 9F + {0, 0, "mov al,ds:", 1, {IMM8}}, // A0 + {0, 0, "mov eax,ds:", 1, {IMM8}}, // A1 + {0, 0, "mov ds:", 2, {IMM8, AL}}, // A2 + {0, 0, "mov ds:", 2, {IMM32, EAX}}, // A3 + {0, 0, "movs BYTE PTR es:[edi],BYTE PTR ds:[esi]", 0}, // A4 + {0, 0, "movs DWORD PTR es:[edi],DWORD PTR ds:[esi]", 0}, // A5 + {0, 0, "cmps BYTE PTR es:[esi],BYTE PTR ds:[edi]", 0}, // A6 + {0, 0, "cmps DWORD PTR es:[esi],DWORD PTR ds:[edi]", 0}, // A7 + {0, 0, "test al,", 1, {IMM8}}, // A8 + {0, 0, "test eax,", 1, {IMM32}}, // A9 + {0, 0, "stos BYTE PTR es:[edi],al", 0}, // AA + {0, 0, "stos DWORD PTR es:[edi],eax", 0}, // AB + {0, 0, "lods al,BYTE PTR ds:[esi]", 0}, // AC + {0, 0, "lods eax,DWORD PTR ds:[esi]", 0}, // AD + {0, 0, "scas al,BYTE PTR es:[edi]", 0}, // AE + {0, 0, "scas eax,DWORD PTR es:[edi]", 0}, // AF + {0, 0, "mov al,", 1, {IMM8}}, // B0 + {0, 0, "mov cl,", 1, {IMM8}}, // B1 + {0, 0, "mov dl,", 1, {IMM8}}, // B2 + {0, 0, "mov bl,", 1, {IMM8}}, // B3 + {0, 0, "mov ah,", 1, {IMM8}}, // B4 + {0, 0, "mov ch,", 1, {IMM8}}, // B5 + {0, 0, "mov dh,", 1, {IMM8}}, // B6 + {0, 0, "mov bh,", 1, {IMM8}}, // B7 + {0, 0, "mov eax,", 1, {IMM32}}, // B8 + {0, 0, "mov ecx,", 1, {IMM32}}, // B9 + {0, 0, "mov edx,", 1, {IMM32}}, // BA + {0, 0, "mov ebx,", 1, {IMM32}}, // BB + {0, 0, "mov esp,", 1, {IMM32}}, // BC + {0, 0, "mov ebp,", 1, {IMM32}}, // BD + {0, 0, "mov esi,", 1, {IMM32}}, // BE + {0, 0, "mov edi,", 1, {IMM32}}, // BF + {1, BYTE, "rol ", 2, {RM, IMM8}}, // C0 + {1, DWORD, "rol ", 2, {RM, IMM8}}, // C1 + {0, 0, "ret ", 1, {IMM16}}, // C2 + {0, 0, "ret", 0}, // C3 + {1, FWORD, "les eax,", 1, {RM}}, // C4 + {1, FWORD, "lds eax,", 1, {RM}}, // C5 + {1, BYTE, "mov ", 2, {RM, IMM8}}, // C6 + {1, DWORD, "mov ", 2, {RM, IMM32}}, // C7 + {0, 0, "enter ", 2, {IMM16, IMM8}}, // C8 + {0, 0, "leave", 0}, // C9 + {0, 0, "retf ", 1, {IMM16}}, // CA + {0, 0, "retf", 0}, // CB + {0, 0, "int3", 0}, // CC + {0, 0, "int ", 1, {IMM8}}, // CD + {0, 0, "into", 0}, // CE + {0, 0, "iret", 0}, // CF + {1, BYTE, "rol ", 2, {RM, ONE}}, // D0 + {1, DWORD, "rol ", 2, {RM, ONE}}, // D1 + {1, BYTE, "rol ", 2, {RM, CL}}, // D2 + {1, DWORD, "rol ", 2, {RM, CL}}, // D3 + {0, 0, "aam ", 1, {IMM8}}, // D4 + {0, 0, "aad ", 1, {IMM8}}, // D5 + {0, 0, ".byte 0xd6", 0}, // D6 + {0, 0, "xlat BYTE PTR ds:[ebx]", 0}, // D7 + {1, DWORD, "fadd ", 1, {RM}}, // D8 + {1, DWORD, "fld ", 1, {RM}}, // D9 + {1, DWORD, "fiadd ", 1, {RM}}, // DA + {1, DWORD, "fild ", 1, {RM}}, // DB + {1, QWORD, "fadd ", 1, {RM}}, // DC + {1, QWORD, "fld ", 1, {RM}}, // DD + {1, WORD, "fiadd ", 1, {RM}}, // DE + {1, WORD, "fild ", 1, {RM}}, // DF + {0, 0, "loopne ", 1, {REL8}}, // E0 + {0, 0, "loope ", 1, {REL8}}, // E1 + {0, 0, "loop ", 1, {REL8}}, // E2 + {0, 0, "jecxz ", 1, {REL8}}, // E3 + {0, 0, "in al,", 1, {IMM8}}, // E4 + {0, 0, "in eax,", 1, {IMM8}}, // E5 + {0, 0, "out ", 2, {IMM8, AL}}, // E6 + {0, 0, "out ", 2, {IMM8, EAX}}, // E7 + {0, 0, "call ", 1, {REL32}}, // E8 + {0, 0, "jmp ", 1, {REL32}}, // E9 + {0, 0, "jmpf ", 1, {PTR1632}}, // EA + {0, 0, "jmp ", 1, {REL8}}, // EB + {0, 0, "in al,dx", 0}, // EC + {0, 0, "in eax,dx", 0}, // ED + {0, 0, "out dx,al", 0}, // EE + {0, 0, "out dx,eax", 0}, // EF + {0, 0, "lock ", 0}, // F0 + {0, 0, "icebp", 0}, // F1 + {0, 0, "repnz ", 0}, // F2 + {0, 0, "repz", 0}, // F3 + {0, 0, "hlt", 0}, // F4 + {0, 0, "cmc", 0}, // F5 + {1, BYTE, "test ", 2, {RM, IMM8}}, // F6 + {1, DWORD, "test ", 2, {RM, IMM32}}, // F7 + {0, 0, "clc", 0}, // F8 + {0, 0, "stc", 0}, // F9 + {0, 0, "cli", 0}, // FA + {0, 0, "sti", 0}, // FB + {0, 0, "cld", 0}, // FC + {0, 0, "std", 0}, // FD + {1, BYTE, "inc ", 1, {RM}}, // FE + {1, DWORD, "inc ", 1, {RM}} // FF + }; - static INSTRUCTION extended_instructions[] = { - { 1, WORD, "sldt ", 1, {RM} }, // 0 - { 1, 0, "sgdtd ", 1, {RM} }, // 1 - { 1, 0, "lar eax,WORD PTR ", 1, {RM} }, // 2 - { 1, 0, "lsl eax,WORD PTR ", 1, {RM} }, // 3 - { 0, 0, ".word 0x0f04", 0 }, // 4 - { 0, 0, "syscall", 0 }, // 5 - { 0, 0, "clts", 0 }, // 6 - { 0, 0, "sysret", 0 }, // 7 - { 0, 0, "invd", 0 }, // 8 - { 0, 0, "wbinvd", 0 }, // 9 - { 0, 0, ".word 0x0f0a", 0 }, // A - { 0, 0, "ud2", 0 }, // B - { 0, 0, ".word 0x0f0c", 0 }, // C - { 1, BYTE, "prefetch ", 1, {RM} }, // D - { 0, 0, "femms", 0 }, // E - { 0 }, // F - Illegal - { 1, XMMWORD, "movups xmm0,", 1, {RM} }, // 10 - { 1, XMMWORD, "movups ", 2, {RM, XMM0} }, // 11 - { 1, QWORD, "movlps xmm0,", 1, {RM} }, // 12 - { 1, QWORD, "movlps ", 2, {RM, XMM0} }, // 13 - { 1, XMMWORD, "unpcklps xmm0,", 1, {RM} }, // 14 - { 1, XMMWORD, "unpckhps xmm0,", 1, {RM} }, // 15 - { 1, QWORD, "movhps xmm0,", 1, {RM} }, // 16 - { 1, QWORD, "movhps ", 2, {RM, XMM0} }, // 17 - { 1, BYTE, "prefetchnta ", 1, {RM} }, // 18 - { 1, DWORD, "nop ", 1, {RM} }, // 19 - { 1, 0, "bndldx bnd0,", 1, {RM} }, // 1A - { 1, 0, "bndstx ", 2, {RM, BND0} }, // 1B - { 1, DWORD, "nop ", 1, {RM} }, // 1C - { 1, DWORD, "nop ", 1, {RM} }, // 1D - { 1, DWORD, "nop ", 1, {RM} }, // 1E - { 1, DWORD, "nop ", 1, {RM} }, // 1F - { 0, 0, ".word 0x0f20", 0 }, // 20 - { 0, 0, ".word 0x0f21", 0 }, // 21 - { 0, 0, ".word 0x0f22", 0 }, // 22 - { 0, 0, ".word 0x0f23", 0 }, // 23 - { 0, 0, ".word 0x0f24", 0 }, // 24 - { 0, 0, ".word 0x0f25", 0 }, // 25 - { 0, 0, ".word 0x0f26", 0 }, // 26 - { 0, 0, ".word 0x0f27", 0 }, // 27 - { 1, XMMWORD, "movaps xmm0,", 1, {RM} }, // 28 - { 1, XMMWORD, "movaps ", 2, {RM, XMM0} }, // 29 - { 1, QWORD, "cvtpi2ps xmm0,", 1, {RM} }, // 2A - { 1, XMMWORD, "movntps ", 2, {RM, XMM0} }, // 2B - { 1, QWORD, "cvttps2pi mm0,", 1, {RM} }, // 2C - { 1, QWORD, "cvtps2pi mm0,", 1, {RM} }, // 2D - { 1, DWORD, "ucomiss xmm0,", 1, {RM} }, // 2E - { 1, DWORD, "comiss xmm0,", 1, {RM} }, // 2F - { 0, 0, "wrmsr", 0 }, // 30 - { 0, 0, "rdtsc", 0 }, // 31 - { 0, 0, "rdmsr", 0 }, // 32 - { 0, 0, "rdpmc", 0 }, // 33 - { 0, 0, "sysenter", 0 }, // 34 - { 0, 0, "sysexit", 0 }, // 35 - { 0, 0, ".word 0x0f36", 0 }, // 36 - { 0, 0, "getsec", 0 }, // 37 - { 1, QWORD, "pshufb mm0,", 1, {RM} }, // 38 - { 0, 0, ".word 0x0f39", 0 }, // 39 - { 0, 0, "(bad)", 1, {(BAD)} }, // 3A - { 0, 0, ".word 0x0f3b", 0 }, // 3B - { 0, 0, ".word 0x0f3c", 0 }, // 3C - { 0, 0, ".word 0x0f3d", 0 }, // 3D - { 0, 0, ".word 0x0f3e", 0 }, // 3E - { 0, 0, ".word 0x0f3f", 0 }, // 3F - { 1, DWORD, "cmovo ", 2, {R, RM} }, // 40 - { 1, DWORD, "cmovno ", 2, {R, RM} }, // 41 - { 1, DWORD, "cmovb ", 2, {R, RM} }, // 42 - { 1, DWORD, "cmovae ", 2, {R, RM} }, // 43 - { 1, DWORD, "cmove ", 2, {R, RM} }, // 44 - { 1, DWORD, "cmovne ", 2, {R, RM} }, // 45 - { 1, DWORD, "cmovbe ", 2, {R, RM} }, // 46 - { 1, DWORD, "cmova ", 2, {R, RM} }, // 47 - { 1, DWORD, "cmovs ", 2, {R, RM} }, // 48 - { 1, DWORD, "cmovns ", 2, {R, RM} }, // 49 - { 1, DWORD, "cmovp ", 2, {R, RM} }, // 4A - { 1, DWORD, "cmovnp ", 2, {R, RM} }, // 4B - { 1, DWORD, "cmovl ", 2, {R, RM} }, // 4C - { 1, DWORD, "cmovge ", 2, {R, RM} }, // 4D - { 1, DWORD, "cmovle ", 2, {R, RM} }, // 4E - { 1, DWORD, "cmovg ", 2, {R, RM} }, // 4F - { 0, 0, ".word 0x0f50", 0 }, // 50 - { 1, XMMWORD, "sqrtps xmm0,", 1, {RM} }, // 51 - { 1, XMMWORD, "rsqrtps xmm0,", 1, {RM} }, // 52 - { 1, XMMWORD, "rcpps xmm0,", 1, {RM} }, // 53 - { 1, XMMWORD, "andps xmm0,", 1, {RM} }, // 54 - { 1, XMMWORD, "andnps xmm0,", 1, {RM} }, // 55 - { 1, XMMWORD, "orps xmm0,", 1, {RM} }, // 56 - { 1, XMMWORD, "xorps xmm0,", 1, {RM} }, // 57 - { 1, XMMWORD, "addps xmm0,", 1, {RM} }, // 58 - { 1, XMMWORD, "mulps xmm0,", 1, {RM} }, // 59 - { 1, QWORD, "cvtps2pd xmm0,", 1, {RM} }, // 5A - { 1, XMMWORD, "cvtdp2ps xmm0,", 1, {RM} }, // 5B - { 1, XMMWORD, "subps xmm0,", 1, {RM} }, // 5C - { 1, XMMWORD, "minps xmm0,", 1, {RM} }, // 5D - { 1, XMMWORD, "divps xmm0,", 1, {RM} }, // 5E - { 1, XMMWORD, "maxps xmm0,", 1, {RM} }, // 5F - { 1, DWORD, "punpcklbw mm0,", 1, {RM} }, // 60 - { 1, DWORD, "punpcklwd mm0,", 1, {RM} }, // 61 - { 1, DWORD, "punpckldq mm0,", 1, {RM} }, // 62 - { 1, QWORD, "packsswb mm0,", 1, {RM} }, // 63 - { 1, QWORD, "pcmpgtb mm0,", 1, {RM} }, // 64 - { 1, QWORD, "pcmpgtw mm0,", 1, {RM} }, // 65 - { 1, QWORD, "pcmpgtd mm0,", 1, {RM} }, // 66 - { 1, QWORD, "packuswb mm0,", 1, {RM} }, // 67 - { 1, QWORD, "punpckhbw mm0,", 1, {RM} }, // 68 - { 1, QWORD, "punpckhwd mm0,", 1, {RM} }, // 69 - { 1, QWORD, "punpckhdq mm0,", 1, {RM} }, // 6A - { 1, QWORD, "packssdw mm0,", 1, {RM} }, // 6B - { 0, 0, ".word 0x0f6c", 0 }, // 6C - { 0, 0, ".word 0x0f6d", 0 }, // 6D - { 1, DWORD, "movd mm0,", 1, {RM} }, // 6E - { 1, QWORD, "movq mm0,", 1, {RM} }, // 6F - { 1, QWORD, "pshufw mm0,", 2, {RM, IMM8} }, // 70 - { 0, 0, ".word 0x0f71", 0 }, // 71 - { 0, 0, ".word 0x0f72", 0 }, // 72 - { 0, 0, ".word 0x0f73", 0 }, // 73 - { 1, QWORD, "pcmpeqb mm0,", 1, {RM} }, // 74 - { 1, QWORD, "pcmpeqw mm0,", 1, {RM} }, // 75 - { 1, QWORD, "pcmpeqd mm0,", 1, {RM} }, // 76 - { 0, 0, "emms", 0 }, // 77 - { 1, DWORD, "vmread ", 2, {RM, R} }, // 78 - { 1, DWORD, "vmwrite ", 2, {R, RM} }, // 79 - { 0, 0, "(bad)", 1, {BAD} }, // 7A - { 0, 0, ".word 0x0f7b", 0 }, // 7B - { 0, 0, ".word 0x0f7c", 0 }, // 7C - { 0, 0, ".word 0x0f7d", 0 }, // 7D - { 1, DWORD, "movd ", 2, {RM, MM0} }, // 7E - { 1, QWORD, "movq ", 2, {RM, MM0} }, // 7F - { 0, 0, "jo ", 1, {REL32} }, // 80 - { 0, 0, "jno ", 1, {REL32} }, // 81 - { 0, 0, "jb ", 1, {REL32} }, // 82 - { 0, 0, "jae ", 1, {REL32} }, // 83 - { 0, 0, "je ", 1, {REL32} }, // 84 - { 0, 0, "jne ", 1, {REL32} }, // 85 - { 0, 0, "jbe ", 1, {REL32} }, // 86 - { 0, 0, "ja ", 1, {REL32} }, // 87 - { 0, 0, "js ", 1, {REL32} }, // 88 - { 0, 0, "jns ", 1, {REL32} }, // 89 - { 0, 0, "jp ", 1, {REL32} }, // 8A - { 0, 0, "jnp ", 1, {REL32} }, // 8B - { 0, 0, "jl ", 1, {REL32} }, // 8C - { 0, 0, "jge ", 1, {REL32} }, // 8D - { 0, 0, "jle ", 1, {REL32} }, // 8E - { 0, 0, "jg ", 1, {REL32} }, // 8F - { 1, BYTE, "seto ", 1, {RM} }, // 90 - { 1, BYTE, "setno ", 1, {RM} }, // 91 - { 1, BYTE, "setb ", 1, {RM} }, // 92 - { 1, BYTE, "setae ", 1, {RM} }, // 93 - { 1, BYTE, "sete ", 1, {RM} }, // 94 - { 1, BYTE, "setne ", 1, {RM} }, // 95 - { 1, BYTE, "setbe ", 1, {RM} }, // 96 - { 1, BYTE, "seta ", 1, {RM} }, // 97 - { 1, BYTE, "sets ", 1, {RM} }, // 98 - { 1, BYTE, "setns ", 1, {RM} }, // 99 - { 1, BYTE, "setp ", 1, {RM} }, // 9A - { 1, BYTE, "setnp ", 1, {RM} }, // 9B - { 1, BYTE, "setl ", 1, {RM} }, // 9C - { 1, BYTE, "setge ", 1, {RM} }, // 9D - { 1, BYTE, "setle ", 1, {RM} }, // 9E - { 1, BYTE, "setg ", 1, {RM} }, // 9F - { 0, 0, "push fs", 0 }, // A0 - { 0, 0, "pop fs", 0 }, // A1 - { 0, 0, "cpuid", 0 }, // A2 - { 1, DWORD, "bt ", 2, {RM, R} }, // A3 - { 1, DWORD, "shld ", 3, {RM, R, IMM8} }, // A4 - { 1, DWORD, "shld ", 3, {RM, R, CL} }, // A5 - { 0 }, // A6 - Illegal - { 0 }, // A7 - Illegal - { 0, 0, "push gs", 0 }, // A8 - { 0, 0, "pop gs", 0 }, // A9 - { 0, 0, "rsm", 0 }, // AA - { 1, DWORD, "bts ", 2, {RM, R} }, // AB - { 1, DWORD, "shrd ", 3, {RM, R, IMM8} }, // AC - { 1, DWORD, "shrd ", 3, {RM, R, CL} }, // AD - { 1, 0, "fxsave ", 1, {RM} }, // AE - { 1, DWORD, "imul ", 2, {R, RM} }, // AF - { 1, BYTE, "cmpxchg ", 2, {RM, AL} }, // B0 - { 1, DWORD, "cmpxchg ", 2, {RM, R} }, // B1 - { 1, FWORD, "lss ", 2, {R, RM} }, // B2 - { 1, DWORD, "btr ", 2, {RM, R} }, // B3 - { 1, FWORD, "lfs ", 2, {R, RM} }, // B4 - { 1, FWORD, "lgs ", 2, {R, RM} }, // B5 - { 1, BYTE, "movzx ", 2, {R, RM} }, // B6 - { 1, WORD, "movzx ", 2, {R, RM} }, // B7 - { 0, 0, ".word 0x0fb8", 0 }, // B8 - { 0, 0, "ud1", 0 }, // B9 - { 0, 0, ".word 0x0fba", 0 }, // BA - { 1, DWORD, "btc ", 2, {RM, R} }, // BB - { 1, DWORD, "bsf ", 2, {R, RM} }, // BC - { 1, DWORD, "bsr ", 2, {R, RM} }, // BD - { 1, BYTE, "movsx ", 2, {R, RM} }, // BE - { 1, WORD, "movsx ", 2, {R, RM} }, // BF - { 1, BYTE, "xadd ", 2, {RM, R} }, // C0 - { 1, DWORD, "xadd ", 2, {RM, R} }, // C1 - { 1, XMMWORD, "cmpeqps xmm0,", 1, {RM} }, // C2 - { 1, QWORD, "movnti ", 2, {RM, R} }, // C3 - { 1, WORD, "pinsrw mm0,", 2, {RM, IMM8} }, // C4 - { 1, 0, "pextrw ", 3, {R, MM0, IMM8} }, // C5 - { 1, XMMWORD, "shufps xmm0,", 2, {RM, IMM8} }, // C6 - { 0, 0, ".word 0x0fc7", 0 }, // C7 - { 0, 0, "bswap eax", 0 }, // C8 - { 0, 0, "bswap ecx", 0 }, // C9 - { 0, 0, "bswap edx", 0 }, // CA - { 0, 0, "bswap ebx", 0 }, // CB - { 0, 0, "bswap esp", 0 }, // CC - { 0, 0, "bswap ebp", 0 }, // CD - { 0, 0, "bswap esi", 0 }, // CE - { 0, 0, "bswap edi", 0 }, // CF - { 0, 0, ".word 0x0fd0", 0 }, // D0 - { 1, QWORD, "psrlw mm0,", 1, {RM} }, // D1 - { 1, QWORD, "psrld mm0,", 1, {RM} }, // D2 - { 1, QWORD, "psrlq mm0,", 1, {RM} }, // D3 - { 1, QWORD, "paddq mm0,", 1, {RM} }, // D4 - { 1, QWORD, "pmullw mm0,", 1, {RM} }, // D5 - { 0, 0, ".word 0x0fd6,", 0 }, // D6 - { 0, 0, ".word 0x0fd7,", 0 }, // D7 - { 1, QWORD, "psubusb mm0,", 1, {RM} }, // D8 - { 1, QWORD, "psubusw mm0,", 1, {RM} }, // D9 - { 1, QWORD, "pminub mm0,", 1, {RM} }, // DA - { 1, QWORD, "pand mm0,", 1, {RM} }, // DB - { 1, QWORD, "paddusb mm0,", 1, {RM} }, // DC - { 1, QWORD, "psubusw mm0,", 1, {RM} }, // DD - { 1, QWORD, "pmaxub mm0,", 1, {RM} }, // DE - { 1, QWORD, "pandn mm0,", 1, {RM} }, // DF - { 1, QWORD, "pavgb mm0,", 1, {RM} }, // E0 - { 1, QWORD, "psraw mm0,", 1, {RM} }, // E1 - { 1, QWORD, "psrad mm0,", 1, {RM} }, // E2 - { 1, QWORD, "pavgw mm0,", 1, {RM} }, // E3 - { 1, QWORD, "pmulhuw mm0,", 1, {RM} }, // E4 - { 1, QWORD, "pmulhw mm0,", 1, {RM} }, // E5 - { 0, 0, ".word 0x0fe6", 0 }, // E6 - { 1, QWORD, "movntq ", 2, {RM, MM0} }, // E7 - { 1, QWORD, "psubsb mm0,", 1, {RM} }, // E8 - { 1, QWORD, "psubsw mm0,", 1, {RM} }, // E9 - { 1, QWORD, "pminsw mm0,", 1, {RM} }, // EA - { 1, QWORD, "por mm0,", 1, {RM} }, // EB - { 1, QWORD, "paddsb mm0,", 1, {RM} }, // EC - { 1, QWORD, "paddsw mm0,", 1, {RM} }, // ED - { 1, QWORD, "pmaxsw mm0,", 1, {RM} }, // EE - { 1, QWORD, "pxor mm0,", 1, {RM} }, // EF - { 0, 0, ".word 0x0ff0", 0 }, // F0 - { 1, QWORD, "psllow mm0,", 1, {RM} }, // F1 - { 1, QWORD, "pslld mm0,", 1, {RM} }, // F2 - { 1, QWORD, "psllq mm0,", 1, {RM} }, // F3 - { 1, QWORD, "pmuludq mm0,", 1, {RM} }, // F4 - { 1, QWORD, "pmaddwd mm0,", 1, {RM} }, // F5 - { 1, QWORD, "psadbw mm0,", 1, {RM} }, // F6 - { 0 }, // F7 - Illegal - { 1, QWORD, "psubb mm0,", 1, {RM} }, // F8 - { 1, QWORD, "psubw mm0,", 1, {RM} }, // F9 - { 1, QWORD, "psubd mm0,", 1, {RM} }, // FA - { 1, QWORD, "psubq mm0,", 1, {RM} }, // FB - { 1, QWORD, "paddb mm0,", 1, {RM} }, // FC - { 1, QWORD, "paddw mm0,", 1, {RM} }, // FD - { 1, QWORD, "paddd mm0,", 1, {RM} }, // FE - { 0 }, // FF - Illegal - }; + static INSTRUCTION extended_instructions[] = { + {1, WORD, "sldt ", 1, {RM}}, // 0 + {1, 0, "sgdtd ", 1, {RM}}, // 1 + {1, 0, "lar eax,WORD PTR ", 1, {RM}}, // 2 + {1, 0, "lsl eax,WORD PTR ", 1, {RM}}, // 3 + {0, 0, ".word 0x0f04", 0}, // 4 + {0, 0, "syscall", 0}, // 5 + {0, 0, "clts", 0}, // 6 + {0, 0, "sysret", 0}, // 7 + {0, 0, "invd", 0}, // 8 + {0, 0, "wbinvd", 0}, // 9 + {0, 0, ".word 0x0f0a", 0}, // A + {0, 0, "ud2", 0}, // B + {0, 0, ".word 0x0f0c", 0}, // C + {1, BYTE, "prefetch ", 1, {RM}}, // D + {0, 0, "femms", 0}, // E + {0}, // F - Illegal + {1, XMMWORD, "movups xmm0,", 1, {RM}}, // 10 + {1, XMMWORD, "movups ", 2, {RM, XMM0}}, // 11 + {1, QWORD, "movlps xmm0,", 1, {RM}}, // 12 + {1, QWORD, "movlps ", 2, {RM, XMM0}}, // 13 + {1, XMMWORD, "unpcklps xmm0,", 1, {RM}}, // 14 + {1, XMMWORD, "unpckhps xmm0,", 1, {RM}}, // 15 + {1, QWORD, "movhps xmm0,", 1, {RM}}, // 16 + {1, QWORD, "movhps ", 2, {RM, XMM0}}, // 17 + {1, BYTE, "prefetchnta ", 1, {RM}}, // 18 + {1, DWORD, "nop ", 1, {RM}}, // 19 + {1, 0, "bndldx bnd0,", 1, {RM}}, // 1A + {1, 0, "bndstx ", 2, {RM, BND0}}, // 1B + {1, DWORD, "nop ", 1, {RM}}, // 1C + {1, DWORD, "nop ", 1, {RM}}, // 1D + {1, DWORD, "nop ", 1, {RM}}, // 1E + {1, DWORD, "nop ", 1, {RM}}, // 1F + {0, 0, ".word 0x0f20", 0}, // 20 + {0, 0, ".word 0x0f21", 0}, // 21 + {0, 0, ".word 0x0f22", 0}, // 22 + {0, 0, ".word 0x0f23", 0}, // 23 + {0, 0, ".word 0x0f24", 0}, // 24 + {0, 0, ".word 0x0f25", 0}, // 25 + {0, 0, ".word 0x0f26", 0}, // 26 + {0, 0, ".word 0x0f27", 0}, // 27 + {1, XMMWORD, "movaps xmm0,", 1, {RM}}, // 28 + {1, XMMWORD, "movaps ", 2, {RM, XMM0}}, // 29 + {1, QWORD, "cvtpi2ps xmm0,", 1, {RM}}, // 2A + {1, XMMWORD, "movntps ", 2, {RM, XMM0}}, // 2B + {1, QWORD, "cvttps2pi mm0,", 1, {RM}}, // 2C + {1, QWORD, "cvtps2pi mm0,", 1, {RM}}, // 2D + {1, DWORD, "ucomiss xmm0,", 1, {RM}}, // 2E + {1, DWORD, "comiss xmm0,", 1, {RM}}, // 2F + {0, 0, "wrmsr", 0}, // 30 + {0, 0, "rdtsc", 0}, // 31 + {0, 0, "rdmsr", 0}, // 32 + {0, 0, "rdpmc", 0}, // 33 + {0, 0, "sysenter", 0}, // 34 + {0, 0, "sysexit", 0}, // 35 + {0, 0, ".word 0x0f36", 0}, // 36 + {0, 0, "getsec", 0}, // 37 + {1, QWORD, "pshufb mm0,", 1, {RM}}, // 38 + {0, 0, ".word 0x0f39", 0}, // 39 + {0, 0, "(bad)", 1, {(BAD)}}, // 3A + {0, 0, ".word 0x0f3b", 0}, // 3B + {0, 0, ".word 0x0f3c", 0}, // 3C + {0, 0, ".word 0x0f3d", 0}, // 3D + {0, 0, ".word 0x0f3e", 0}, // 3E + {0, 0, ".word 0x0f3f", 0}, // 3F + {1, DWORD, "cmovo ", 2, {R, RM}}, // 40 + {1, DWORD, "cmovno ", 2, {R, RM}}, // 41 + {1, DWORD, "cmovb ", 2, {R, RM}}, // 42 + {1, DWORD, "cmovae ", 2, {R, RM}}, // 43 + {1, DWORD, "cmove ", 2, {R, RM}}, // 44 + {1, DWORD, "cmovne ", 2, {R, RM}}, // 45 + {1, DWORD, "cmovbe ", 2, {R, RM}}, // 46 + {1, DWORD, "cmova ", 2, {R, RM}}, // 47 + {1, DWORD, "cmovs ", 2, {R, RM}}, // 48 + {1, DWORD, "cmovns ", 2, {R, RM}}, // 49 + {1, DWORD, "cmovp ", 2, {R, RM}}, // 4A + {1, DWORD, "cmovnp ", 2, {R, RM}}, // 4B + {1, DWORD, "cmovl ", 2, {R, RM}}, // 4C + {1, DWORD, "cmovge ", 2, {R, RM}}, // 4D + {1, DWORD, "cmovle ", 2, {R, RM}}, // 4E + {1, DWORD, "cmovg ", 2, {R, RM}}, // 4F + {0, 0, ".word 0x0f50", 0}, // 50 + {1, XMMWORD, "sqrtps xmm0,", 1, {RM}}, // 51 + {1, XMMWORD, "rsqrtps xmm0,", 1, {RM}}, // 52 + {1, XMMWORD, "rcpps xmm0,", 1, {RM}}, // 53 + {1, XMMWORD, "andps xmm0,", 1, {RM}}, // 54 + {1, XMMWORD, "andnps xmm0,", 1, {RM}}, // 55 + {1, XMMWORD, "orps xmm0,", 1, {RM}}, // 56 + {1, XMMWORD, "xorps xmm0,", 1, {RM}}, // 57 + {1, XMMWORD, "addps xmm0,", 1, {RM}}, // 58 + {1, XMMWORD, "mulps xmm0,", 1, {RM}}, // 59 + {1, QWORD, "cvtps2pd xmm0,", 1, {RM}}, // 5A + {1, XMMWORD, "cvtdp2ps xmm0,", 1, {RM}}, // 5B + {1, XMMWORD, "subps xmm0,", 1, {RM}}, // 5C + {1, XMMWORD, "minps xmm0,", 1, {RM}}, // 5D + {1, XMMWORD, "divps xmm0,", 1, {RM}}, // 5E + {1, XMMWORD, "maxps xmm0,", 1, {RM}}, // 5F + {1, DWORD, "punpcklbw mm0,", 1, {RM}}, // 60 + {1, DWORD, "punpcklwd mm0,", 1, {RM}}, // 61 + {1, DWORD, "punpckldq mm0,", 1, {RM}}, // 62 + {1, QWORD, "packsswb mm0,", 1, {RM}}, // 63 + {1, QWORD, "pcmpgtb mm0,", 1, {RM}}, // 64 + {1, QWORD, "pcmpgtw mm0,", 1, {RM}}, // 65 + {1, QWORD, "pcmpgtd mm0,", 1, {RM}}, // 66 + {1, QWORD, "packuswb mm0,", 1, {RM}}, // 67 + {1, QWORD, "punpckhbw mm0,", 1, {RM}}, // 68 + {1, QWORD, "punpckhwd mm0,", 1, {RM}}, // 69 + {1, QWORD, "punpckhdq mm0,", 1, {RM}}, // 6A + {1, QWORD, "packssdw mm0,", 1, {RM}}, // 6B + {0, 0, ".word 0x0f6c", 0}, // 6C + {0, 0, ".word 0x0f6d", 0}, // 6D + {1, DWORD, "movd mm0,", 1, {RM}}, // 6E + {1, QWORD, "movq mm0,", 1, {RM}}, // 6F + {1, QWORD, "pshufw mm0,", 2, {RM, IMM8}}, // 70 + {0, 0, ".word 0x0f71", 0}, // 71 + {0, 0, ".word 0x0f72", 0}, // 72 + {0, 0, ".word 0x0f73", 0}, // 73 + {1, QWORD, "pcmpeqb mm0,", 1, {RM}}, // 74 + {1, QWORD, "pcmpeqw mm0,", 1, {RM}}, // 75 + {1, QWORD, "pcmpeqd mm0,", 1, {RM}}, // 76 + {0, 0, "emms", 0}, // 77 + {1, DWORD, "vmread ", 2, {RM, R}}, // 78 + {1, DWORD, "vmwrite ", 2, {R, RM}}, // 79 + {0, 0, "(bad)", 1, {BAD}}, // 7A + {0, 0, ".word 0x0f7b", 0}, // 7B + {0, 0, ".word 0x0f7c", 0}, // 7C + {0, 0, ".word 0x0f7d", 0}, // 7D + {1, DWORD, "movd ", 2, {RM, MM0}}, // 7E + {1, QWORD, "movq ", 2, {RM, MM0}}, // 7F + {0, 0, "jo ", 1, {REL32}}, // 80 + {0, 0, "jno ", 1, {REL32}}, // 81 + {0, 0, "jb ", 1, {REL32}}, // 82 + {0, 0, "jae ", 1, {REL32}}, // 83 + {0, 0, "je ", 1, {REL32}}, // 84 + {0, 0, "jne ", 1, {REL32}}, // 85 + {0, 0, "jbe ", 1, {REL32}}, // 86 + {0, 0, "ja ", 1, {REL32}}, // 87 + {0, 0, "js ", 1, {REL32}}, // 88 + {0, 0, "jns ", 1, {REL32}}, // 89 + {0, 0, "jp ", 1, {REL32}}, // 8A + {0, 0, "jnp ", 1, {REL32}}, // 8B + {0, 0, "jl ", 1, {REL32}}, // 8C + {0, 0, "jge ", 1, {REL32}}, // 8D + {0, 0, "jle ", 1, {REL32}}, // 8E + {0, 0, "jg ", 1, {REL32}}, // 8F + {1, BYTE, "seto ", 1, {RM}}, // 90 + {1, BYTE, "setno ", 1, {RM}}, // 91 + {1, BYTE, "setb ", 1, {RM}}, // 92 + {1, BYTE, "setae ", 1, {RM}}, // 93 + {1, BYTE, "sete ", 1, {RM}}, // 94 + {1, BYTE, "setne ", 1, {RM}}, // 95 + {1, BYTE, "setbe ", 1, {RM}}, // 96 + {1, BYTE, "seta ", 1, {RM}}, // 97 + {1, BYTE, "sets ", 1, {RM}}, // 98 + {1, BYTE, "setns ", 1, {RM}}, // 99 + {1, BYTE, "setp ", 1, {RM}}, // 9A + {1, BYTE, "setnp ", 1, {RM}}, // 9B + {1, BYTE, "setl ", 1, {RM}}, // 9C + {1, BYTE, "setge ", 1, {RM}}, // 9D + {1, BYTE, "setle ", 1, {RM}}, // 9E + {1, BYTE, "setg ", 1, {RM}}, // 9F + {0, 0, "push fs", 0}, // A0 + {0, 0, "pop fs", 0}, // A1 + {0, 0, "cpuid", 0}, // A2 + {1, DWORD, "bt ", 2, {RM, R}}, // A3 + {1, DWORD, "shld ", 3, {RM, R, IMM8}}, // A4 + {1, DWORD, "shld ", 3, {RM, R, CL}}, // A5 + {0}, // A6 - Illegal + {0}, // A7 - Illegal + {0, 0, "push gs", 0}, // A8 + {0, 0, "pop gs", 0}, // A9 + {0, 0, "rsm", 0}, // AA + {1, DWORD, "bts ", 2, {RM, R}}, // AB + {1, DWORD, "shrd ", 3, {RM, R, IMM8}}, // AC + {1, DWORD, "shrd ", 3, {RM, R, CL}}, // AD + {1, 0, "fxsave ", 1, {RM}}, // AE + {1, DWORD, "imul ", 2, {R, RM}}, // AF + {1, BYTE, "cmpxchg ", 2, {RM, AL}}, // B0 + {1, DWORD, "cmpxchg ", 2, {RM, R}}, // B1 + {1, FWORD, "lss ", 2, {R, RM}}, // B2 + {1, DWORD, "btr ", 2, {RM, R}}, // B3 + {1, FWORD, "lfs ", 2, {R, RM}}, // B4 + {1, FWORD, "lgs ", 2, {R, RM}}, // B5 + {1, BYTE, "movzx ", 2, {R, RM}}, // B6 + {1, WORD, "movzx ", 2, {R, RM}}, // B7 + {0, 0, ".word 0x0fb8", 0}, // B8 + {0, 0, "ud1", 0}, // B9 + {0, 0, ".word 0x0fba", 0}, // BA + {1, DWORD, "btc ", 2, {RM, R}}, // BB + {1, DWORD, "bsf ", 2, {R, RM}}, // BC + {1, DWORD, "bsr ", 2, {R, RM}}, // BD + {1, BYTE, "movsx ", 2, {R, RM}}, // BE + {1, WORD, "movsx ", 2, {R, RM}}, // BF + {1, BYTE, "xadd ", 2, {RM, R}}, // C0 + {1, DWORD, "xadd ", 2, {RM, R}}, // C1 + {1, XMMWORD, "cmpeqps xmm0,", 1, {RM}}, // C2 + {1, QWORD, "movnti ", 2, {RM, R}}, // C3 + {1, WORD, "pinsrw mm0,", 2, {RM, IMM8}}, // C4 + {1, 0, "pextrw ", 3, {R, MM0, IMM8}}, // C5 + {1, XMMWORD, "shufps xmm0,", 2, {RM, IMM8}}, // C6 + {0, 0, ".word 0x0fc7", 0}, // C7 + {0, 0, "bswap eax", 0}, // C8 + {0, 0, "bswap ecx", 0}, // C9 + {0, 0, "bswap edx", 0}, // CA + {0, 0, "bswap ebx", 0}, // CB + {0, 0, "bswap esp", 0}, // CC + {0, 0, "bswap ebp", 0}, // CD + {0, 0, "bswap esi", 0}, // CE + {0, 0, "bswap edi", 0}, // CF + {0, 0, ".word 0x0fd0", 0}, // D0 + {1, QWORD, "psrlw mm0,", 1, {RM}}, // D1 + {1, QWORD, "psrld mm0,", 1, {RM}}, // D2 + {1, QWORD, "psrlq mm0,", 1, {RM}}, // D3 + {1, QWORD, "paddq mm0,", 1, {RM}}, // D4 + {1, QWORD, "pmullw mm0,", 1, {RM}}, // D5 + {0, 0, ".word 0x0fd6,", 0}, // D6 + {0, 0, ".word 0x0fd7,", 0}, // D7 + {1, QWORD, "psubusb mm0,", 1, {RM}}, // D8 + {1, QWORD, "psubusw mm0,", 1, {RM}}, // D9 + {1, QWORD, "pminub mm0,", 1, {RM}}, // DA + {1, QWORD, "pand mm0,", 1, {RM}}, // DB + {1, QWORD, "paddusb mm0,", 1, {RM}}, // DC + {1, QWORD, "psubusw mm0,", 1, {RM}}, // DD + {1, QWORD, "pmaxub mm0,", 1, {RM}}, // DE + {1, QWORD, "pandn mm0,", 1, {RM}}, // DF + {1, QWORD, "pavgb mm0,", 1, {RM}}, // E0 + {1, QWORD, "psraw mm0,", 1, {RM}}, // E1 + {1, QWORD, "psrad mm0,", 1, {RM}}, // E2 + {1, QWORD, "pavgw mm0,", 1, {RM}}, // E3 + {1, QWORD, "pmulhuw mm0,", 1, {RM}}, // E4 + {1, QWORD, "pmulhw mm0,", 1, {RM}}, // E5 + {0, 0, ".word 0x0fe6", 0}, // E6 + {1, QWORD, "movntq ", 2, {RM, MM0}}, // E7 + {1, QWORD, "psubsb mm0,", 1, {RM}}, // E8 + {1, QWORD, "psubsw mm0,", 1, {RM}}, // E9 + {1, QWORD, "pminsw mm0,", 1, {RM}}, // EA + {1, QWORD, "por mm0,", 1, {RM}}, // EB + {1, QWORD, "paddsb mm0,", 1, {RM}}, // EC + {1, QWORD, "paddsw mm0,", 1, {RM}}, // ED + {1, QWORD, "pmaxsw mm0,", 1, {RM}}, // EE + {1, QWORD, "pxor mm0,", 1, {RM}}, // EF + {0, 0, ".word 0x0ff0", 0}, // F0 + {1, QWORD, "psllow mm0,", 1, {RM}}, // F1 + {1, QWORD, "pslld mm0,", 1, {RM}}, // F2 + {1, QWORD, "psllq mm0,", 1, {RM}}, // F3 + {1, QWORD, "pmuludq mm0,", 1, {RM}}, // F4 + {1, QWORD, "pmaddwd mm0,", 1, {RM}}, // F5 + {1, QWORD, "psadbw mm0,", 1, {RM}}, // F6 + {0}, // F7 - Illegal + {1, QWORD, "psubb mm0,", 1, {RM}}, // F8 + {1, QWORD, "psubw mm0,", 1, {RM}}, // F9 + {1, QWORD, "psubd mm0,", 1, {RM}}, // FA + {1, QWORD, "psubq mm0,", 1, {RM}}, // FB + {1, QWORD, "paddb mm0,", 1, {RM}}, // FC + {1, QWORD, "paddw mm0,", 1, {RM}}, // FD + {1, QWORD, "paddd mm0,", 1, {RM}}, // FE + {0}, // FF - Illegal + }; - unsigned char *base = bytes; - unsigned char opcode = *bytes++; - char modRM_mod = 0; - char modRM_reg = 0; - char modRM_rm = 0; + unsigned char* base = bytes; + unsigned char opcode = *bytes++; + char modRM_mod = 0; + char modRM_reg = 0; + char modRM_rm = 0; + INSTRUCTION* instructions = standard_instructions; + if (opcode == 0x0F) { // Extended opcodes + if (max < 2 || *bytes == 0x0F || *bytes == 0xA6 || *bytes == 0xA7 || + *bytes == 0xF7 || *bytes == 0xFF) { + goto ILLEGAL; + } - INSTRUCTION *instructions= standard_instructions; - if (opcode == 0x0F) { // Extended opcodes - if (max < 2 || *bytes == 0x0F || *bytes == 0xA6 || *bytes == 0xA7 || *bytes == 0xF7 || *bytes == 0xFF) { - goto ILLEGAL; - } + instructions = extended_instructions; + opcode = *bytes++; + } - instructions = extended_instructions; - opcode = *bytes++; - } + if (!instructions[opcode].hasModRM) { + goto OUTPUT; // Skip ModRM byte parsing + } - if (!instructions[opcode].hasModRM) { - goto OUTPUT; // Skip ModRM byte parsing - } + char RM_output[0xFF]; + char R_output[0xFF]; - char RM_output[0xFF]; - char R_output[0xFF]; + modRM_mod = ((*bytes) >> 6) & 0b11; // Bits 7-6. + modRM_reg = ((*bytes) >> 3) & 0b111; // Bits 5-3. + modRM_rm = (*bytes++) & 0b111; // Bits 2-0. - modRM_mod = ((*bytes) >> 6) & 0b11; // Bits 7-6. - modRM_reg = ((*bytes) >> 3) & 0b111; // Bits 5-3. - modRM_rm = (*bytes++) & 0b111; // Bits 2-0. + switch (instructions[opcode].size) { + case WORD: + strcpy(R_output, register_mnemonics16[(int)modRM_reg]); + break; + case BYTE: + strcpy(R_output, register_mnemonics8[(int)modRM_reg]); + break; + default: + strcpy(R_output, register_mnemonics32[(int)modRM_reg]); + } - switch (instructions[opcode].size) { - case WORD: - strcpy(R_output, register_mnemonics16[(int)modRM_reg]); - break; - case BYTE: - strcpy(R_output, register_mnemonics8[(int)modRM_reg]); - break; - default: - strcpy(R_output, register_mnemonics32[(int)modRM_reg]); - } + if (modRM_mod == 0b11) { // Register addressing mode. + switch (instructions[opcode].size) { + case BYTE: + sprintf(RM_output, "%s", register_mnemonics8[(int)modRM_rm]); + break; + case WORD: + sprintf(RM_output, "%s", register_mnemonics16[(int)modRM_rm]); + break; + default: + sprintf(RM_output, "%s", register_mnemonics32[(int)modRM_rm]); + } + } else if (modRM_mod == 0b00 && + modRM_rm == 0b101) { // Displacement only addressing mode. + sprintf(RM_output, "[0x%x]", *(int*)bytes); + bytes += 4; + } else { // One-byte or four-byte signed displacement follows addressing + // mode byte(s). + if (modRM_rm == 0b100) { // Contains SIB byte + char SIB_scale = ((*bytes) >> 6) & 0b11; // Bits 7-6. + char SIB_index = ((*bytes) >> 3) & 0b111; // Bits 5-3. + char SIB_base = (*bytes++) & 0b111; // Bits 2-0. - if (modRM_mod == 0b11) { // Register addressing mode. - switch (instructions[opcode].size) { - case BYTE: - sprintf(RM_output, "%s", register_mnemonics8[(int)modRM_rm]); - break; - case WORD: - sprintf(RM_output, "%s", register_mnemonics16[(int)modRM_rm]); - break; - default: - sprintf(RM_output, "%s", register_mnemonics32[(int)modRM_rm]); - } - } else if (modRM_mod == 0b00 && modRM_rm == 0b101) { // Displacement only addressing mode. - sprintf(RM_output, "[0x%x]", *(int *)bytes); - bytes += 4; - } else { // One-byte or four-byte signed displacement follows addressing mode byte(s). - if (modRM_rm == 0b100) { // Contains SIB byte - char SIB_scale = ((*bytes) >> 6) & 0b11; // Bits 7-6. - char SIB_index = ((*bytes) >> 3) & 0b111; // Bits 5-3. - char SIB_base = (*bytes++) & 0b111; // Bits 2-0. + if (SIB_base == 0b101 && modRM_mod == 0b00) { + sprintf(RM_output, "[0x%x", *(int*)bytes); + bytes += 4; + } else { + strcpy(RM_output, sib_base_mnemonics[(int)SIB_base]); + } - if (SIB_base == 0b101 && modRM_mod == 0b00) { - sprintf(RM_output, "[0x%x", *(int *)bytes); - bytes += 4; - } else { - strcpy(RM_output, sib_base_mnemonics[(int)SIB_base]); - } + if (SIB_index != 0b100) { + strcat(RM_output, "+"); + strcat(RM_output, register_mnemonics32[(int)SIB_index]); + strcat(RM_output, sib_scale_mnemonics[(int)SIB_scale]); + } + } else { + sprintf(RM_output, "[%s", register_mnemonics32[(int)modRM_rm]); + } - if (SIB_index != 0b100) { - strcat(RM_output, "+"); - strcat(RM_output, register_mnemonics32[(int)SIB_index]); - strcat(RM_output, sib_scale_mnemonics[(int)SIB_scale]); - } - } else { - sprintf(RM_output, "[%s", register_mnemonics32[(int)modRM_rm]); - } + if (modRM_mod == 0b01) { // One-byte signed displacement follows + // addressing mode byte(s). + if (*bytes > 0x7F) { + sprintf(RM_output + strlen(RM_output), "-0x%x]", + -*(char*)bytes++); + } else { + sprintf(RM_output + strlen(RM_output), "+0x%x]", + *(char*)bytes++); + } + } else if (modRM_mod == 0b10) { // Four-byte signed displacement + // follows addressing mode byte(s). + if (*(unsigned int*)bytes > 0x7FFFFFFF) { + sprintf(RM_output + strlen(RM_output), "-0x%x]", -*(int*)bytes); + } else { + sprintf(RM_output + strlen(RM_output), "+0x%x]", + *(unsigned int*)bytes); + } - if (modRM_mod == 0b01) { // One-byte signed displacement follows addressing mode byte(s). - if (*bytes > 0x7F) { - sprintf(RM_output + strlen(RM_output), "-0x%x]", -*(char *)bytes++); - } else { - sprintf(RM_output + strlen(RM_output), "+0x%x]", *(char *)bytes++); - } - } else if (modRM_mod == 0b10) { // Four-byte signed displacement follows addressing mode byte(s). - if (*(unsigned int *)bytes > 0x7FFFFFFF) { - sprintf(RM_output + strlen(RM_output), "-0x%x]", -*(int *)bytes); - } else { - sprintf(RM_output + strlen(RM_output), "+0x%x]", *(unsigned int *)bytes); - } - - bytes += 4; - } else { - strcat(RM_output, "]"); - } - } + bytes += 4; + } else { + strcat(RM_output, "]"); + } + } OUTPUT: - strcpy(output, instructions[opcode].mnemonic); - int i; - for (i = 0; i < instructions[opcode].argument_count; i++) { - if (i > 0) { - strcat(output, ","); - } + strcpy(output, instructions[opcode].mnemonic); + int i; + for (i = 0; i < instructions[opcode].argument_count; i++) { + if (i > 0) { + strcat(output, ","); + } - switch (instructions[opcode].arguments[i]) { - case RM: - if (modRM_mod != 0b11) { - switch (instructions[opcode].size) { - case BYTE: - strcat(output, "BYTE PTR "); - break; - case WORD: - strcat(output, "WORD PTR "); - break; - case DWORD: - strcat(output, "DWORD PTR "); - break; - case QWORD: - strcat(output, "QWORD PTR "); - break; - case FWORD: - strcat(output, "FWORD PTR "); - break; - case XMMWORD: - strcat(output, "XMMWORD PTR "); - break; - } - } + switch (instructions[opcode].arguments[i]) { + case RM: + if (modRM_mod != 0b11) { + switch (instructions[opcode].size) { + case BYTE: + strcat(output, "BYTE PTR "); + break; + case WORD: + strcat(output, "WORD PTR "); + break; + case DWORD: + strcat(output, "DWORD PTR "); + break; + case QWORD: + strcat(output, "QWORD PTR "); + break; + case FWORD: + strcat(output, "FWORD PTR "); + break; + case XMMWORD: + strcat(output, "XMMWORD PTR "); + break; + } + } - strcat(output, RM_output); - break; - case R: - strcat(output, R_output); - break; - case IMM8: - sprintf(output + strlen(output), "0x%x", *bytes++); - break; - case IMM16: - sprintf(output + strlen(output), "0x%x", *(short *)bytes); - bytes += 2; - break; - case IMM32: - sprintf(output + strlen(output), "0x%x", *(int *)bytes); - bytes += 4; - break; - case REL8: - sprintf(output + strlen(output), "0x%x", (unsigned int) (offset + ((bytes - base) + 1) + *(char *)bytes)); - bytes += 1; - break; - case REL32: - sprintf(output + strlen(output), "0x%x", (unsigned int) (offset + ((bytes - base) + 4) + *(int *)bytes)); - bytes += 4; - break; - case PTR1632: - sprintf(output + strlen(output), "0x%x:0x%x", *(short *)(bytes + 4), *(int *)bytes); - bytes += 6; - break; - case AL: - strcat(output, "al"); - break; - case EAX: - strcat(output, "eax"); - break; - case ES: - strcat(output, "es"); - break; - case CS: - strcat(output, "cs"); - break; - case SS: - strcat(output, "ss"); - break; - case DS: - strcat(output, "ds"); - break; - case ONE: - strcat(output, "1"); - break; - case CL: - strcat(output, "cl"); - break; - case XMM0: - strcat(output, "xmm0"); - break; - case BND0: - strcat(output, "bnd0"); - break; - case BAD: - bytes++; - break; - case MM0: - strcat(output, "mm0"); - break; - } - } + strcat(output, RM_output); + break; + case R: + strcat(output, R_output); + break; + case IMM8: + sprintf(output + strlen(output), "0x%x", *bytes++); + break; + case IMM16: + sprintf(output + strlen(output), "0x%x", *(short*)bytes); + bytes += 2; + break; + case IMM32: + sprintf(output + strlen(output), "0x%x", *(int*)bytes); + bytes += 4; + break; + case REL8: + sprintf( + output + strlen(output), "0x%x", + (unsigned int)(offset + ((bytes - base) + 1) + *(char*)bytes)); + bytes += 1; + break; + case REL32: + sprintf( + output + strlen(output), "0x%x", + (unsigned int)(offset + ((bytes - base) + 4) + *(int*)bytes)); + bytes += 4; + break; + case PTR1632: + sprintf(output + strlen(output), "0x%x:0x%x", *(short*)(bytes + 4), + *(int*)bytes); + bytes += 6; + break; + case AL: + strcat(output, "al"); + break; + case EAX: + strcat(output, "eax"); + break; + case ES: + strcat(output, "es"); + break; + case CS: + strcat(output, "cs"); + break; + case SS: + strcat(output, "ss"); + break; + case DS: + strcat(output, "ds"); + break; + case ONE: + strcat(output, "1"); + break; + case CL: + strcat(output, "cl"); + break; + case XMM0: + strcat(output, "xmm0"); + break; + case BND0: + strcat(output, "bnd0"); + break; + case BAD: + bytes++; + break; + case MM0: + strcat(output, "mm0"); + break; + } + } - if (((unsigned int)(bytes - base)) <= max) { - return bytes - base; - } + if (((unsigned int)(bytes - base)) <= max) { + return (unsigned int)(bytes - base); + } ILLEGAL: - sprintf(output, ".byte 0x%02x\n", opcode); - return 1; + sprintf(output, ".byte 0x%02x\n", opcode); + return 1; } diff --git a/x86_64_rt.c b/x86_64_rt.c index 39a6abc9ae..2a686a79bd 100644 --- a/x86_64_rt.c +++ b/x86_64_rt.c @@ -1,8 +1,7 @@ -#include "config.h" #include #include +#include "config.h" #include "dill.h" -#include "dill_internal.h" #ifdef HAVE_SYS_MMAN_H #include "sys/mman.h" #endif @@ -11,15 +10,23 @@ #endif #ifdef USE_VIRTUAL_PROTECT #include -#include #include +#include #endif +#include "dill_internal.h" #include "x86.h" -extern double dill_x86_64_hidden_ULtoD(unsigned long a) -{ return (double) a; } -extern unsigned long dill_x86_64_hidden_DtoUL(double a) -{ unsigned long l = a; return l; } +extern double +dill_x86_64_hidden_ULtoD(size_t a) +{ + return (double)a; +} +extern size_t +dill_x86_64_hidden_DtoUL(double a) +{ + size_t l = (long)a; + return l; +} static xfer_entry x86_64_xfer_recs[5] = { {"dill_x86_64_hidden_ULtoD", dill_x86_64_hidden_ULtoD}, @@ -27,50 +34,50 @@ static xfer_entry x86_64_xfer_recs[5] = { {(char*)0, (void*)0}}; extern void -x86_64_rt_call_link(char *code, call_t *t) +x86_64_rt_call_link(char* code, call_t* t) { int i; - for(i=0; i< t->call_count; i++) { - uintptr_t tmp = (uintptr_t) t->call_locs[i].xfer_addr; - long *call_addr = (long *) (code + t->call_locs[i].loc + 2); - memcpy(call_addr, &tmp, 8); + for (i = 0; i < t->call_count; i++) { + uintptr_t tmp = (uintptr_t)t->call_locs[i].xfer_addr; + long* call_addr = (long*)(code + t->call_locs[i].loc + 2); + memcpy(call_addr, &tmp, 8); } } static void -x86_64_flush(void *base, void *limit) +x86_64_flush(void* base, void* limit) { #if defined(HOST_X86_64) { - volatile void *ptr = base; + volatile void* ptr = base; - /* flush every 8 bytes of preallocated insn stream. */ - while((char*)ptr < (char*) limit) { + /* flush every 8 bytes of preallocated insn stream. */ + while ((char*)ptr < (char*)limit) { #ifndef _MSC_VER #ifdef __x86_64__ - asm volatile ("clflush (%0)" : /* */ : "r" (ptr)); + asm volatile("clflush (%0)" : /* */ : "r"(ptr)); #endif #else - _mm_clflush((const void *) ptr); + _mm_clflush((const void*)ptr); #endif - ptr = (char *)ptr + 8; - } + ptr = (char*)ptr + 8; + } #ifndef _MSC_VER - asm volatile("nop"); - asm volatile("nop"); - asm volatile("nop"); - asm volatile("nop"); - asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); #endif } #endif -} +} -extern char * -x86_64_package_stitch(char *code, call_t *t, dill_pkg pkg) +extern char* +x86_64_package_stitch(char* code, call_t* t, dill_pkg pkg) { - char *tmp = code; + char* tmp = code; dill_lookup_xfer_addrs(t, &x86_64_xfer_recs[0]); x86_64_rt_call_link(code, t); x86_64_flush(code, code + 1024); @@ -78,15 +85,15 @@ x86_64_package_stitch(char *code, call_t *t, dill_pkg pkg) #ifndef MAP_ANONYMOUS #define MAP_ANONYMOUS MAP_ANON #endif - tmp = (void*)mmap(0, pkg->code_size, - PROT_EXEC | PROT_READ | PROT_WRITE, - MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + tmp = (void*)mmap(0, pkg->code_size, PROT_EXEC | PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); memcpy(tmp, code, pkg->code_size); #endif #ifdef USE_VIRTUAL_PROTECT int result; DWORD dummy; - result = VirtualProtect(tmp, pkg->code_size, PAGE_EXECUTE_READWRITE, &dummy); + result = + VirtualProtect(tmp, pkg->code_size, PAGE_EXECUTE_READWRITE, &dummy); #endif return tmp + pkg->entry_offset; } From 8ea624a70da0f17b0e76cfc56a00b3ec705b8663 Mon Sep 17 00:00:00 2001 From: Greg Eisenhauer Date: Sun, 2 Jul 2023 15:32:22 -0400 Subject: [PATCH 6/7] Tweaks for BP5 on Windows --- cmake/DetectOptions.cmake | 2 +- source/adios2/engine/bp5/BP5Reader.cpp | 12 ++--- source/adios2/engine/bp5/BP5Writer.cpp | 54 +++++++++++-------- .../bp5/BP5Writer_EveryoneWrites_Async.cpp | 2 +- .../toolkit/format/bp5/BP5Deserializer.cpp | 44 +++++++-------- .../toolkit/format/bp5/BP5Serializer.cpp | 39 +++++++------- .../adios2/bindings/C/TestBPWriteTypes.cpp | 10 ---- .../adios2/interface/TestADIOSInterface.cpp | 18 +------ 8 files changed, 85 insertions(+), 96 deletions(-) diff --git a/cmake/DetectOptions.cmake b/cmake/DetectOptions.cmake index b3c271c647..509b221fd2 100644 --- a/cmake/DetectOptions.cmake +++ b/cmake/DetectOptions.cmake @@ -451,7 +451,7 @@ if(DAOS_FOUND) endif() # BP5 -if(ADIOS2_USE_BP5 AND NOT WIN32) +if(ADIOS2_USE_BP5) set(ADIOS2_HAVE_BP5 TRUE) endif() diff --git a/source/adios2/engine/bp5/BP5Reader.cpp b/source/adios2/engine/bp5/BP5Reader.cpp index 1e8b6abf00..673dbfbd61 100644 --- a/source/adios2/engine/bp5/BP5Reader.cpp +++ b/source/adios2/engine/bp5/BP5Reader.cpp @@ -368,7 +368,7 @@ void BP5Reader::PerformGets() // then main thread process the last subset for (size_t tid = 0; tid < nThreads - 1; ++tid) { - futures[tid] = std::async(std::launch::async, lf_Reader, tid + 1, + futures[tid] = std::async(std::launch::async, lf_Reader, (int)(tid + 1), maxOpenFiles); } // main thread runs last subset of reads @@ -513,9 +513,9 @@ void BP5Reader::InitParameters() } size_t limit = helper::RaiseLimitNoFile(); - if (m_Parameters.MaxOpenFilesAtOnce > limit - 8) + if (m_Parameters.MaxOpenFilesAtOnce > (unsigned int) limit - 8) { - m_Parameters.MaxOpenFilesAtOnce = limit - 8; + m_Parameters.MaxOpenFilesAtOnce = (unsigned int) limit - 8; } } @@ -986,11 +986,11 @@ size_t BP5Reader::ParseMetadataIndex(format::BufferSTL &bufferSTL, { auto p = m_WriterMap.emplace(m_StepsCount, WriterMapStruct()); auto &s = p.first->second; - s.WriterCount = helper::ReadValue( + s.WriterCount = (uint32_t)helper::ReadValue( buffer, position, m_Minifooter.IsLittleEndian); - s.AggregatorCount = helper::ReadValue( + s.AggregatorCount = (uint32_t)helper::ReadValue( buffer, position, m_Minifooter.IsLittleEndian); - s.SubfileCount = helper::ReadValue( + s.SubfileCount = (uint32_t)helper::ReadValue( buffer, position, m_Minifooter.IsLittleEndian); // Get the process -> subfile map s.RankToSubfile.reserve(s.WriterCount); diff --git a/source/adios2/engine/bp5/BP5Writer.cpp b/source/adios2/engine/bp5/BP5Writer.cpp index 1deb7090cb..32cb7e8bda 100644 --- a/source/adios2/engine/bp5/BP5Writer.cpp +++ b/source/adios2/engine/bp5/BP5Writer.cpp @@ -160,6 +160,7 @@ void BP5Writer::WriteMetaMetadata( m_FileMetaMetadataManager.WriteFiles((char *)b.MetaMetaInfo, b.MetaMetaInfoLen); } + m_FileMetaMetadataManager.FlushFiles(); } uint64_t @@ -206,6 +207,8 @@ BP5Writer::WriteMetadata(const std::vector &MetaDataBlocks, MetaDataSize += b.iov_len; } + m_FileMetadataManager.FlushFiles(); + m_MetaDataPos += MetaDataSize; return MetaDataSize; } @@ -272,6 +275,7 @@ void BP5Writer::WriteData(format::BufferV *Data) std::to_string(m_Parameters.AggregationType) + "is not supported in BP5"); } + m_FileDataManager.FlushFiles(); delete Data; } } @@ -337,8 +341,6 @@ void BP5Writer::WriteData_EveryoneWrites(format::BufferV *Data, void BP5Writer::WriteMetadataFileIndex(uint64_t MetaDataPos, uint64_t MetaDataSize) { - m_FileMetadataManager.FlushFiles(); - // bufsize: Step record size_t bufsize = 1 + (4 + ((FlushPosSizeInfo.size() * 2) + 1) * m_Comm.Size()) * @@ -407,7 +409,6 @@ void BP5Writer::WriteMetadataFileIndex(uint64_t MetaDataPos, } m_FileMetadataIndexManager.WriteFiles((char *)buf.data(), buf.size()); - #ifdef DUMPDATALOCINFO std::cout << "Flush count is :" << FlushPosSizeInfo.size() << std::endl; std::cout << "Write Index positions = {" << std::endl; @@ -427,6 +428,8 @@ void BP5Writer::WriteMetadataFileIndex(uint64_t MetaDataPos, } std::cout << "}" << std::endl; #endif + m_FileMetadataIndexManager.FlushFiles(); + /* reset for next timestep */ FlushPosSizeInfo.clear(); } @@ -472,7 +475,7 @@ void BP5Writer::MarshalAttributes() if (!attributePair.second->m_IsSingleValue) { - element_count = (*baseAttr)->m_Elements; + element_count = (int)(*baseAttr)->m_Elements; } if (type == DataType::None) @@ -511,7 +514,7 @@ void BP5Writer::MarshalAttributes() void *data_addr = &attribute.m_DataSingleValue; \ if (!attribute.m_IsSingleValue) \ { \ - element_count = attribute.m_Elements; \ + element_count = (int)attribute.m_Elements; \ data_addr = attribute.m_DataArray.data(); \ } \ m_BP5Serializer.MarshalAttribute(attribute.m_Name.c_str(), type, \ @@ -536,7 +539,7 @@ void BP5Writer::EndStep() // true: advances step auto TSInfo = m_BP5Serializer.CloseTimestep( - m_WriterStep, m_Parameters.AsyncWrite || m_Parameters.DirectIO); + (int)m_WriterStep, m_Parameters.AsyncWrite || m_Parameters.DirectIO); /* TSInfo includes NewMetaMetaBlocks, the MetaEncodeBuffer, the * AttributeEncodeBuffer and the data encode Vector */ @@ -684,6 +687,10 @@ void BP5Writer::EndStep() m_AsyncWriteLock.unlock(); } } + m_FileMetadataIndexManager.FlushFiles(); + m_FileMetadataManager.FlushFiles(); + m_FileMetaMetadataManager.FlushFiles(); + m_FileDataManager.FlushFiles(); m_Profiler.Stop("ES"); m_WriterStep++; @@ -752,7 +759,8 @@ void BP5Writer::InitParameters() { size_t k = m_Parameters.StripeSize / m_Parameters.DirectIOAlignOffset + 1; - m_Parameters.StripeSize = k * m_Parameters.DirectIOAlignOffset; + m_Parameters.StripeSize = + (unsigned int)(k * m_Parameters.DirectIOAlignOffset); } if (m_Parameters.BufferChunkSize % m_Parameters.DirectIOAlignOffset) { @@ -852,12 +860,12 @@ uint64_t BP5Writer::CountStepsInMetadataIndex(format::BufferSTL &bufferSTL) { case IndexRecord::WriterMapRecord: { - m_AppendWriterCount = - helper::ReadValue(buffer, position, IsLittleEndian); - m_AppendAggregatorCount = - helper::ReadValue(buffer, position, IsLittleEndian); - m_AppendSubfileCount = - helper::ReadValue(buffer, position, IsLittleEndian); + m_AppendWriterCount = (uint32_t)helper::ReadValue( + buffer, position, IsLittleEndian); + m_AppendAggregatorCount = (uint32_t)helper::ReadValue( + buffer, position, IsLittleEndian); + m_AppendSubfileCount = (uint32_t)helper::ReadValue( + buffer, position, IsLittleEndian); if (m_AppendSubfileCount > nDataFiles) { nDataFiles = m_AppendSubfileCount; @@ -939,12 +947,12 @@ uint64_t BP5Writer::CountStepsInMetadataIndex(format::BufferSTL &bufferSTL) { case IndexRecord::WriterMapRecord: { - m_AppendWriterCount = - helper::ReadValue(buffer, position, IsLittleEndian); - m_AppendAggregatorCount = - helper::ReadValue(buffer, position, IsLittleEndian); - m_AppendSubfileCount = - helper::ReadValue(buffer, position, IsLittleEndian); + m_AppendWriterCount = (uint32_t)helper::ReadValue( + buffer, position, IsLittleEndian); + m_AppendAggregatorCount = (uint32_t)helper::ReadValue( + buffer, position, IsLittleEndian); + m_AppendSubfileCount = (uint32_t)helper::ReadValue( + buffer, position, IsLittleEndian); // Get the process -> subfile map writerToFileMap.clear(); @@ -1796,8 +1804,8 @@ void BP5Writer::PutCommon(VariableBase &variable, const void *values, bool sync) helper::DimsArray MemoryCount(variable.m_MemoryCount); helper::DimsArray varCount(variable.m_Count); - int DimCount = variable.m_Count.size(); - std::vector ZeroDims(DimCount); + int DimCount = (int)variable.m_Count.size(); + helper::DimsArray ZeroDims(DimCount, (size_t)0); // get a temporary span then fill with memselection now format::BufferV::BufferPos bp5span(0, 0, 0); @@ -1816,8 +1824,8 @@ void BP5Writer::PutCommon(VariableBase &variable, const void *values, bool sync) } helper::NdCopy((const char *)values, helper::CoreDims(ZeroDims), MemoryCount, sourceRowMajor, false, (char *)ptr, - MemoryStart, varCount, sourceRowMajor, false, ObjSize, - helper::CoreDims(), helper::CoreDims(), + MemoryStart, varCount, sourceRowMajor, false, + (int)ObjSize, helper::CoreDims(), helper::CoreDims(), helper::CoreDims(), helper::CoreDims(), false /* safemode */, variable.m_MemSpace); } diff --git a/source/adios2/engine/bp5/BP5Writer_EveryoneWrites_Async.cpp b/source/adios2/engine/bp5/BP5Writer_EveryoneWrites_Async.cpp index c9f8f02079..a8f7827adb 100644 --- a/source/adios2/engine/bp5/BP5Writer_EveryoneWrites_Async.cpp +++ b/source/adios2/engine/bp5/BP5Writer_EveryoneWrites_Async.cpp @@ -88,7 +88,7 @@ void BP5Writer::AsyncWriteOwnData(AsyncWriteInfo *info, size_t wrote = 0; size_t block = 0; size_t temp_offset = 0; - size_t max_size = std::max(1024 * 1024UL, totalsize / 100UL); + size_t max_size = std::max((size_t)1024 * 1024UL, totalsize / 100UL); bool firstWrite = seekOnFirstWrite; while (block < nBlocks) diff --git a/source/adios2/toolkit/format/bp5/BP5Deserializer.cpp b/source/adios2/toolkit/format/bp5/BP5Deserializer.cpp index 9a0c98c432..17a0cc57d5 100644 --- a/source/adios2/toolkit/format/bp5/BP5Deserializer.cpp +++ b/source/adios2/toolkit/format/bp5/BP5Deserializer.cpp @@ -41,6 +41,7 @@ using namespace adios2::helper; #ifdef _WIN32 #pragma warning(disable : 4250) +#define strdup(x) _strdup(x) #endif namespace adios2 @@ -57,7 +58,7 @@ void BP5Deserializer::InstallMetaMetaData(MetaMetaInfoBlock &MM) memcpy(FormatID, MM.MetaMetaID, MM.MetaMetaIDLen); memcpy(MetaMetaInfo, MM.MetaMetaInfo, MM.MetaMetaInfoLen); load_external_format_FMcontext(FMContext_from_FFS(ReaderFFSContext), - FormatID, MM.MetaMetaIDLen, MetaMetaInfo); + FormatID, (int) MM.MetaMetaIDLen, MetaMetaInfo); free(FormatID); } @@ -82,7 +83,7 @@ bool BP5Deserializer::NameIndicatesArray(const char *Name) bool BP5Deserializer::NameIndicatesAttrArray(const char *Name) { - int Len = strlen(Name); + auto Len = strlen(Name); return (strcmp("ElemCount", Name + Len - 9) == 0); } @@ -175,7 +176,7 @@ const char *BP5Deserializer::BreakdownVarName(const char *Name, ++p; // skip '_' if (*type_p == DataType::Struct) { - p = index(p, '_'); + p = strchr(p, '_'); ++p; } return p; @@ -216,7 +217,7 @@ void BP5Deserializer::BreakdownV1ArrayName(const char *Name, char **base_name_p, const char *NameStart = strchr(strchr(Name + 4, '_') + 1, '_') + 1; // + 3 to skip BP5_ or bp5_ prefix sscanf(Name + 4, "%d_%d", &ElementSize, &Type); - const char *Plus = index(Name, '+'); + const char *Plus = strchr(Name, '+'); MinMax = false; while (Plus && (*Plus == '+')) { @@ -224,7 +225,7 @@ void BP5Deserializer::BreakdownV1ArrayName(const char *Name, char **base_name_p, if (sscanf(Plus, "+%dO", &Len) == 1) { // Operator Spec Operator = true; - const char *OpStart = index(Plus, 'O') + 1; + const char *OpStart = strchr(Plus, 'O') + 1; Plus = OpStart + Len; } else if (strncmp(Plus, "+MM", 3) == 0) @@ -236,7 +237,7 @@ void BP5Deserializer::BreakdownV1ArrayName(const char *Name, char **base_name_p, *element_size_p = ElementSize; *type_p = (DataType)Type; *base_name_p = strdup(NameStart); - *(rindex(*base_name_p, '_')) = 0; + *(strrchr(*base_name_p, '_')) = 0; } void BP5Deserializer::BreakdownArrayName(const char *Name, char **base_name_p, @@ -386,7 +387,7 @@ BP5Deserializer::ControlInfo *BP5Deserializer::BuildControl(FMFormat Format) FMFieldList List = StructList[0].field_list; while (List->field_name != NULL) { - char *ind = (char *)index(List->field_type, '['); + char *ind = (char *)strchr(List->field_type, '['); if (!ind) { DataType Type = TranslateFFSType2ADIOS( @@ -426,7 +427,7 @@ BP5Deserializer::ControlInfo *BP5Deserializer::BuildControl(FMFormat Format) } if (V1_fields) { - i += MetaRecFields; + i += (int)MetaRecFields; } else { @@ -655,7 +656,7 @@ void BP5Deserializer::InstallMetaData(void *MetadataBlock, size_t BlockLen, } else { - int DecodedLength = FFS_est_decode_length( + auto DecodedLength = FFS_est_decode_length( ReaderFFSContext, (char *)MetadataBlock, BlockLen); BaseData = malloc(DecodedLength); FFSdecode_to_buffer(ReaderFFSContext, (char *)MetadataBlock, BaseData); @@ -882,7 +883,7 @@ void BP5Deserializer::InstallMetaData(void *MetadataBlock, size_t BlockLen, { VarRec->Variable = ArrayVarSetup( m_Engine, VarRec->VarName, VarRec->Type, - meta_base->Dims, meta_base->Shape, meta_base->Offsets, + (int)meta_base->Dims, meta_base->Shape, meta_base->Offsets, meta_base->Count, VarRec->Def, VarRec->ReaderDef); static_cast(VarRec->Variable)->m_Engine = m_Engine; @@ -957,6 +958,7 @@ void BP5Deserializer::InstallMetaData(void *MetadataBlock, size_t BlockLen, } catch (const std::invalid_argument &e) { + (void)e; // We'll catch here if a variable creation encounters a duplicate // variable name in the IO helper::Throw( @@ -1025,7 +1027,7 @@ void BP5Deserializer::InstallAttributeData(void *AttributeBlock, } else { - int DecodedLength = FFS_est_decode_length( + auto DecodedLength = FFS_est_decode_length( ReaderFFSContext, (char *)AttributeBlock, BlockLen); BaseData = malloc(DecodedLength); FFSBuffer decode_buf = @@ -1120,7 +1122,7 @@ void BP5Deserializer::InstallAttributesV1(FFSTypeHandle FFSformat, i++; char *FieldName = strdup(FieldList[i].field_name + 4); // skip BP5_ char *FieldType = strdup(FieldList[i].field_type); - *index(FieldType, '[') = 0; + *strchr(FieldType, '[') = 0; Type = (DataType)TranslateFFSType2ADIOS(FieldType, FieldList[i].field_size); if (Type == adios2::DataType::Struct) @@ -1767,7 +1769,7 @@ void BP5Deserializer::FinalizeGet(const ReadRequest &Read, const bool freeAddr) (MetaArrayRec *)GetMetadataBase(Req.VarRec, Req.Step, Read.WriterRank); size_t *GlobalDimensions = writer_meta_base->Shape; - int DimCount = writer_meta_base->Dims; + auto DimCount = writer_meta_base->Dims; std::vector ZeroSel(DimCount); size_t *RankOffset = &writer_meta_base->Offsets[DimCount * Read.BlockID]; size_t *RankSize = &writer_meta_base->Count[DimCount * Read.BlockID]; @@ -1818,7 +1820,7 @@ void BP5Deserializer::FinalizeGet(const ReadRequest &Read, const bool freeAddr) { SelOffset = ZeroSel.data(); } - for (int i = 0; i < DimCount; i++) + for (int i = 0; i < (int) DimCount; i++) { GlobalDimensions[i] = RankSize[i]; } @@ -1929,7 +1931,7 @@ int BP5Deserializer::FindOffset(size_t Dims, const size_t *Size, int Offset = 0; for (size_t i = 0; i < Dims; i++) { - Offset = Index[i] + (Size[i] * Offset); + Offset = (int)(Index[i] + (Size[i] * Offset)); } return Offset; } @@ -2030,7 +2032,7 @@ void *BP5Deserializer::GetMetadataBase(BP5VarRec *VarRec, size_t Step, size_t CI_VarIndex = (*CI->CIVarIndex)[VarRec->VarNum]; BP5MetadataInfoStruct *BaseData = (BP5MetadataInfoStruct *)(*MetadataBaseArray[Step])[WriterRank]; - if (!BP5BitfieldTest(BaseData, CI_VarIndex)) + if (!BP5BitfieldTest(BaseData, (int)CI_VarIndex)) { // Var appears in CI, but wasn't written on this step return NULL; @@ -2058,12 +2060,12 @@ MinVarInfo *BP5Deserializer::MinBlocksInfo(const VariableBase &Var, size_t Step) { BP5VarRec *VarRec = LookupVarByKey((void *)&Var); - MinVarInfo *MV = new MinVarInfo(VarRec->DimCount, VarRec->GlobalDims); + MinVarInfo *MV = new MinVarInfo((int)VarRec->DimCount, VarRec->GlobalDims); const size_t writerCohortSize = WriterCohortSize(Step); size_t Id = 0; MV->Step = Step; - MV->Dims = VarRec->DimCount; + MV->Dims = (int)VarRec->DimCount; MV->Shape = NULL; MV->IsReverseDims = ((MV->Dims > 1) && (m_WriterIsRowMajor != m_ReaderIsRowMajor)); @@ -2093,7 +2095,7 @@ MinVarInfo *BP5Deserializer::MinBlocksInfo(const VariableBase &Var, size_t Step) { MinBlockInfo Blk; Blk.MinMax.Init(VarRec->Type); - Blk.WriterID = WriterRank; + Blk.WriterID = (int)WriterRank; Blk.BlockID = Id++; Blk.BufferP = writer_meta_base; Blk.Start = NULL; @@ -2157,7 +2159,7 @@ MinVarInfo *BP5Deserializer::MinBlocksInfo(const VariableBase &Var, size_t Step) if (writer_meta_base->Count) Count = writer_meta_base->Count + (i * MV->Dims); MinBlockInfo Blk; - Blk.WriterID = WriterRank; + Blk.WriterID = (int)WriterRank; Blk.BlockID = Id++; Blk.Start = Offsets; Blk.Count = Count; @@ -2285,7 +2287,7 @@ size_t BP5Deserializer::RelativeToAbsoluteStep(const BP5VarRec *VarRec, BaseData = (BP5MetadataInfoStruct *)(*MetadataBaseArray[AbsStep])[WriterRank]; if (BP5BitfieldTest((BP5MetadataInfoStruct *)BaseData, - VarRec->VarNum)) + (int)VarRec->VarNum)) { // variable appeared on this step RelStep--; diff --git a/source/adios2/toolkit/format/bp5/BP5Serializer.cpp b/source/adios2/toolkit/format/bp5/BP5Serializer.cpp index af4c780cf3..dbe595093e 100644 --- a/source/adios2/toolkit/format/bp5/BP5Serializer.cpp +++ b/source/adios2/toolkit/format/bp5/BP5Serializer.cpp @@ -22,6 +22,9 @@ #ifdef _WIN32 #pragma warning(disable : 4250) #endif +#ifdef _MSC_VER +#define strdup(x) _strdup(x) +#endif namespace adios2 { @@ -121,7 +124,7 @@ void BP5Serializer::RecalcAttributeStorageSize() Info.AttributeData = realloc(Info.AttributeData, NewAttributeSize + 8); memset((char *)(Info.AttributeData) + Info.AttributeSize, 0, NewAttributeSize - Info.AttributeSize); - Info.AttributeSize = NewAttributeSize; + Info.AttributeSize = (int) NewAttributeSize; } } @@ -228,7 +231,7 @@ char *BP5Serializer::BuildVarName(const char *base_name, const ShapeID Shape, { const char *Prefix = NamePrefix(Shape); - int Len = strlen(base_name) + 2 + strlen(Prefix) + 16; + auto Len = strlen(base_name) + 2 + strlen(Prefix) + 16; char *Ret = (char *)malloc(Len); if (element_size == 0) { @@ -245,22 +248,22 @@ char *BP5Serializer::BuildVarName(const char *base_name, const ShapeID Shape, } static char *BuildLongName(const char *base_name, const ShapeID Shape, - const int type, const int element_size, + const int type, const size_t element_size, const char *StructID) { const char *Prefix = NamePrefix(Shape); - int StructIDLen = 0; + size_t StructIDLen = 0; if (StructID) StructIDLen = strlen(StructID); - int Len = strlen(base_name) + 3 + strlen(Prefix) + StructIDLen + 16; + size_t Len = strlen(base_name) + 3 + strlen(Prefix) + StructIDLen + 16; char *Ret = (char *)malloc(Len); if (StructID) { - snprintf(Ret, Len, "%s_%d_%d_%s", Prefix, element_size, type, StructID); + snprintf(Ret, Len, "%s_%zd_%d_%s", Prefix, element_size, type, StructID); } else { - snprintf(Ret, Len, "%s_%d_%d", Prefix, element_size, type); + snprintf(Ret, Len, "%s_%zd_%d", Prefix, element_size, type); } strcat(Ret, "_"); strcat(Ret, base_name); @@ -283,7 +286,7 @@ char *BP5Serializer::BuildArrayDimsName(const char *base_name, const int type, const int element_size) { const char *Prefix = NamePrefix(ShapeID::GlobalArray); - int Len = strlen(base_name) + 3 + strlen(Prefix) + 16; + size_t Len = strlen(base_name) + 3 + strlen(Prefix) + 16; char *Ret = (char *)malloc(Len); snprintf(Ret, Len, "%s%d_%d_", Prefix, element_size, type); strcat(Ret, base_name); @@ -296,7 +299,7 @@ char *BP5Serializer::BuildArrayDBCountName(const char *base_name, const int element_size) { const char *Prefix = NamePrefix(ShapeID::GlobalArray); - int Len = strlen(base_name) + 3 + strlen(Prefix) + 16; + size_t Len = strlen(base_name) + 3 + strlen(Prefix) + 16; char *Ret = (char *)malloc(Len); snprintf(Ret, Len, "%s%d_%d_", Prefix, element_size, type); strcat(Ret, base_name); @@ -309,7 +312,7 @@ char *BP5Serializer::BuildArrayBlockCountName(const char *base_name, const int element_size) { const char *Prefix = NamePrefix(ShapeID::GlobalArray); - int Len = strlen(base_name) + 3 + strlen(Prefix) + 24; + size_t Len = strlen(base_name) + 3 + strlen(Prefix) + 24; char *Ret = (char *)malloc(Len); snprintf(Ret, Len, "%s%d_%d_", Prefix, element_size, type); strcat(Ret, base_name); @@ -450,7 +453,7 @@ BP5Serializer::CreateWriterRec(void *Variable, const char *Name, DataType Type, Rec->Key = Variable; Rec->Shape = VB->m_ShapeID; Rec->FieldID = Info.RecCount; - Rec->DimCount = DimCount; + Rec->DimCount = (int)DimCount; Rec->Type = (int)Type; Rec->OperatorType = NULL; char *TextStructID = NULL; @@ -467,7 +470,7 @@ BP5Serializer::CreateWriterRec(void *Variable, const char *Name, DataType Type, List[i].field_name = strdup(SD->Name(i).c_str()); List[i].field_type = TranslateADIOS2Type2FFS(SD->Type(i)); List[i].field_size = TypeElementSize(SD->Type(i)); - List[i].field_offset = SD->Offset(i); + List[i].field_offset = (int)SD->Offset(i); if (SD->ElementCount(i) != 1) { size_t Len = strlen(List[i].field_type) + 10; @@ -487,7 +490,7 @@ BP5Serializer::CreateWriterRec(void *Variable, const char *Name, DataType Type, {NULL, NULL, 0, NULL}}; struct_list[0].format_name = strdup(SD->StructName().c_str()); struct_list[0].field_list = List; - struct_list[0].struct_size = SD->StructSize(); + struct_list[0].struct_size = (int)SD->StructSize(); FMFormat Format = register_data_format(Info.LocalFMContext, &struct_list[0]); @@ -508,7 +511,7 @@ BP5Serializer::CreateWriterRec(void *Variable, const char *Name, DataType Type, char *SstName = BuildVarName(Name, VB->m_ShapeID, 0, 0); // size and type in full field spec AddField(&Info.MetaFields, &Info.MetaFieldCount, SstName, Type, - ElemSize); + (int)ElemSize); free(SstName); RecalcMarshalStorageSize(); Rec->MetaOffset = Info.MetaFields[Info.MetaFieldCount - 1].field_offset; @@ -930,9 +933,9 @@ void BP5Serializer::MarshalAttribute(const char *Name, const DataType Type, { // simple field, only simple attribute name and value char *SstName = - BuildVarName(Name, ShapeID::GlobalValue, (int)Type, ElemSize); + BuildVarName(Name, ShapeID::GlobalValue, (int)Type, (int)ElemSize); AddField(&Info.AttributeFields, &Info.AttributeFieldCount, SstName, - Type, ElemSize); + Type, (int)ElemSize); free(SstName); RecalcAttributeStorageSize(); int DataOffset = @@ -952,7 +955,7 @@ void BP5Serializer::MarshalAttribute(const char *Name, const DataType Type, int CountOffset = Info.AttributeFields[Info.AttributeFieldCount - 1].field_offset; AddVarArrayField(&Info.AttributeFields, &Info.AttributeFieldCount, - ArrayName, Type, ElemSize, ElemCountName); + ArrayName, Type, (int)ElemSize, ElemCountName); int DataOffset = Info.AttributeFields[Info.AttributeFieldCount - 1].field_offset; free(ElemCountName); @@ -1102,7 +1105,7 @@ void BP5Serializer::ProcessDeferredMinMax() MetaArrayRecMM *MetaEntry = (MetaArrayRecMM *)((char *)(MetadataBuf) + Def.MetaOffset); void **MMPtrLoc = (void **)(((char *)MetaEntry) + Def.MinMaxOffset); - int ElemSize = helper::GetDataTypeSize(Def.Type); + auto ElemSize = helper::GetDataTypeSize(Def.Type); memcpy(((char *)*MMPtrLoc) + ElemSize * (2 * (Def.BlockNum)), &MinMax.MinUnion, ElemSize); diff --git a/testing/adios2/bindings/C/TestBPWriteTypes.cpp b/testing/adios2/bindings/C/TestBPWriteTypes.cpp index f684815686..fb6d4fa9b2 100644 --- a/testing/adios2/bindings/C/TestBPWriteTypes.cpp +++ b/testing/adios2/bindings/C/TestBPWriteTypes.cpp @@ -181,12 +181,7 @@ TEST_F(ADIOS2_C_API, ADIOS2BPWriteTypes) char *engineType = new char[engineTypeSize + 1](); adios2_engine_get_type(engineType, &engineTypeSize, engineH); -#if defined(_WIN64) || defined(_WIN32) - // default staying BP4 for now - EXPECT_EQ(std::string(engineType, engineTypeSize), "BP4Writer"); -#else EXPECT_EQ(std::string(engineType, engineTypeSize), "BP5Writer"); -#endif adios2_close(engineH); @@ -207,12 +202,7 @@ TEST_F(ADIOS2_C_API, ADIOS2BPWriteTypes) adios2_mode m; adios2_error e = adios2_engine_openmode(&m, engineH); EXPECT_EQ(e, adios2_error_none); -#if defined(_WIN64) || defined(_WIN32) - // default staying BP4 for now - EXPECT_EQ(m, adios2_mode_read); -#else EXPECT_EQ(m, adios2_mode_readRandomAccess); -#endif adios2_bool result; char name[30]; diff --git a/testing/adios2/interface/TestADIOSInterface.cpp b/testing/adios2/interface/TestADIOSInterface.cpp index b9f49f5ed3..ceaf41409b 100644 --- a/testing/adios2/interface/TestADIOSInterface.cpp +++ b/testing/adios2/interface/TestADIOSInterface.cpp @@ -129,14 +129,9 @@ TEST_F(ADIOS2_CXX11_API, APIToString) EXPECT_EQ(ToString(attribute), "Attribute(Name: \"attr_float\")"); auto engine = io.Open("test.bp", adios2::Mode::Write); -#if defined(_WIN64) || defined(_WIN32) - // default staying BP4 for now - EXPECT_EQ(ToString(engine), - "Engine(Name: \"test.bp\", Type: \"BP4Writer\")"); -#else + EXPECT_EQ(ToString(engine), "Engine(Name: \"test.bp\", Type: \"BP5Writer\")"); -#endif } TEST_F(ADIOS2_CXX11_API, operatorLL) @@ -163,12 +158,8 @@ TEST_F(ADIOS2_CXX11_API_IO, Engine) adios2::Engine engine = m_Io.Open("types.bp", adios2::Mode::Write); EXPECT_EQ(engine.Name(), "types.bp"); -#if defined(_WIN64) || defined(_WIN32) - // default staying BP4 for now - EXPECT_EQ(engine.Type(), "BP4Writer"); -#else EXPECT_EQ(engine.Type(), "BP5Writer"); -#endif + engine.Close(); } @@ -179,12 +170,7 @@ TEST_F(ADIOS2_CXX11_API_IO, EngineDefault) adios2::Engine engine = m_Io.Open("types.bp", adios2::Mode::Write); EXPECT_EQ(engine.Name(), "types.bp"); -#if defined(_WIN64) || defined(_WIN32) - // default staying BP4 for now - EXPECT_EQ(engine.Type(), "BP4Writer"); -#else EXPECT_EQ(engine.Type(), "BP5Writer"); -#endif engine.Close(); } From e08dba0420a59ee6403486360dd54a6c9b5e8dd7 Mon Sep 17 00:00:00 2001 From: Greg Eisenhauer Date: Sun, 2 Jul 2023 21:39:22 -0400 Subject: [PATCH 7/7] String fix and timeout --- source/adios2/core/Variable.tcc | 4 ++++ testing/adios2/engine/staging-common/TestSupp.cmake | 2 ++ 2 files changed, 6 insertions(+) diff --git a/source/adios2/core/Variable.tcc b/source/adios2/core/Variable.tcc index 9a641c3cef..884a00afe6 100644 --- a/source/adios2/core/Variable.tcc +++ b/source/adios2/core/Variable.tcc @@ -113,9 +113,13 @@ std::pair Variable::DoMinMax(const size_t step) const MinMaxStruct MM; if (m_Engine->VariableMinMax(*this, step, MM)) { + if (std::is_same::value) { + return minMax; + } else { minMax.first = *(T *)&MM.MinUnion; minMax.second = *(T *)&MM.MaxUnion; return minMax; + } } } if (m_Engine != nullptr && !m_FirstStreamingStep) diff --git a/testing/adios2/engine/staging-common/TestSupp.cmake b/testing/adios2/engine/staging-common/TestSupp.cmake index f0294aeded..24b71902b3 100644 --- a/testing/adios2/engine/staging-common/TestSupp.cmake +++ b/testing/adios2/engine/staging-common/TestSupp.cmake @@ -70,8 +70,10 @@ set (1x1GetSync_CMD "run_test.py.$ -nw 1 -nr 1 --rarg=--read_mode --rarg set (1x1DontCloseWriter_CMD "run_test.py.$ -nw 1 -nr 1 --warg=--dont_close") set (1x1DontCloseReader_CMD "run_test.py.$ -nw 1 -nr 1 --rarg=--dont_close") set (1x1DefSync_CMD "TestDefSyncWrite --data_size 200 --engine_params ChunkSize=500,MinDeferredSize=150") +set (1x1DefSync_TIMEOUT 180) set (1x1VarDestruction_CMD "run_test.py.$ -nw 1 -nr 1 --rarg=--var_destruction") set (1x1DataWrite_CMD "TestDefSyncWrite --flush --data_size 200 --engine_params ChunkSize=500,MinDeferredSize=150") +set (1x1DataWrite_TIMEOUT 180) set (1x1.NoPreload_CMD "run_test.py.$ -nw 1 -nr 1 --rarg=PreloadMode=SstPreloadNone,RENGINE_PARAMS") set (1x1.SstRUDP_CMD "run_test.py.$ -nw 1 -nr 1 --rarg=DataTransport=WAN,WANDataTransport=enet,RENGINE_PARAMS --warg=DataTransport=WAN,WANDataTransport=enet,WENGINE_PARAMS") set (1x1.NoData_CMD "run_test.py.$ -nw 1 -nr 1 --warg=--no_data --rarg=--no_data")