Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: fixes #282

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7c60702
MAINT: include win32 headers
xoviat Oct 20, 2017
40a509a
ENH: allow getcpu to work on windows
xoviat Oct 20, 2017
c536602
FIX: type
xoviat Oct 20, 2017
e11c001
FIX: types
xoviat Oct 20, 2017
3db63d7
FIX: types
xoviat Oct 20, 2017
f869d3c
FIX: typo
xoviat Oct 20, 2017
1fb9d7d
Windows Fixes
isuruf Oct 21, 2017
f88bde0
Remove ifndefs
isuruf Oct 21, 2017
9a85087
Merge pull request #1 from isuruf/windows
xoviat Oct 21, 2017
f7ae936
Rename WIN32->_WIN32
isuruf Oct 21, 2017
1f9c24e
Add empty methods for __abort_* methods temporarily
isuruf Oct 21, 2017
7037215
More windows fixes
isuruf Oct 21, 2017
e7f9ea6
Don't use grep or sort
isuruf Oct 21, 2017
0f428b1
Fix generating upperilm.sort
isuruf Oct 21, 2017
452047c
Add truncate definition; thanks to @xoviat
isuruf Oct 21, 2017
f0cbfc3
Add empty methods for mkstemp and vasprintf
isuruf Oct 21, 2017
d96738b
ENH: implement new win32 functions
xoviat Oct 21, 2017
a3fc1dd
FIX: types
xoviat Oct 21, 2017
8a117ac
Fix _WIN32
isuruf Oct 21, 2017
238b722
Merge branch 'windows' of https://github.com/isuruf/flang
isuruf Oct 21, 2017
f3759be
Use asprintf from https://github.com/littlstar/asprintf.c
isuruf Oct 21, 2017
b828ea8
Fix more _WIN32
isuruf Oct 21, 2017
284a664
Implement dtime3f for windows. credits to xoviat
isuruf Oct 21, 2017
88b6886
Remove annoying asserts
isuruf Oct 21, 2017
76911b9
More WIN32
isuruf Oct 21, 2017
d5440d6
sed WINNT, WIN32, WIN64 -> _WIN32 for runtime/flang
isuruf Oct 21, 2017
0e270f6
Merge pull request #2 from isuruf/windows
xoviat Oct 21, 2017
ac6690a
FIX anonymous structs
xoviat Oct 22, 2017
41bcca7
FIX: missed first time
xoviat Oct 22, 2017
884ceee
Merge pull request #1 from xoviat/patch-2
isuruf Oct 22, 2017
f370f8f
Fix CMake
isuruf Oct 22, 2017
f7e4154
Misc MSVC fixes
isuruf Oct 22, 2017
d8bd20d
sed UINT64->FLANG_UINT64
isuruf Oct 22, 2017
07a3e9c
sed INT64->FLANG_INT64
isuruf Oct 22, 2017
b097a42
Revert "sed INT64->FLANG_INT64"
isuruf Oct 22, 2017
44eec07
sed INT64->FLANG_INT64
isuruf Oct 22, 2017
c66db1e
Merge pull request #3 from isuruf/windows
xoviat Oct 23, 2017
fda6633
FIX: update useless ifdef
xoviat Oct 23, 2017
d122790
More windows fixes
isuruf Oct 23, 2017
890322e
Merge pull request #4 from isuruf/windows
xoviat Oct 24, 2017
d31a96c
[runtime/amod] remove _win32 ifdefs
xoviat Oct 25, 2017
9f2bfc7
[runtime/mthdecls] win64 -> win32
xoviat Oct 25, 2017
14b631e
[runtime/utils] add fortio binary mode
xoviat Oct 25, 2017
5845da3
[runtime/utils] add gettimeofday
xoviat Oct 25, 2017
b5aa05f
[runtime/utils] externalize gettimeofday
xoviat Oct 25, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ cmake_minimum_required(VERSION 2.8)
# CMake's Fortran tests
SET(CMAKE_Fortran_COMPILER_WORKS 1)

if( NOT DEFINED TARGET_ARCHITECTURE )
execute_process(COMMAND uname -m OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE TARGET_ARCHITECTURE)
endif()

if( NOT DEFINED TARGET_OS )
execute_process(COMMAND uname -s OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE TARGET_OS)
set(CMAKE_Fortran_PREPROCESS_SOURCE
"<CMAKE_Fortran_COMPILER> -cpp <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> -o <PREPROCESSED_SOURCE>")

# If we are not building as a part of LLVM, build Flang as an
# standalone project, using LLVM as an external library:
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
project(Flang)
endif()

set(TARGET_OS ${CMAKE_HOST_SYSTEM_NAME})
set(TARGET_ARCHITECTURE ${CMAKE_HOST_SYSTEM_PROCESSOR})

if( ${TARGET_OS} STREQUAL "Linux" )
set(OS "LINUX")
set(OSNAME "Linux")
Expand All @@ -51,16 +54,23 @@ if( ${TARGET_OS} STREQUAL "Linux" )
message("Unsupported architecture: ${TARGET_ARCHITECTURE}" )
return()
endif()
elseif(${TARGET_OS} STREQUAL "Windows" )
set(OS "WINDOWS")
set(OSNAME "Windows")
if( ${TARGET_ARCHITECTURE} STREQUAL "AMD64" )
set(TARGET_ARCHITECTURE "x86_64")
set(ARCHNAME x86-64)
set(ARCH X86)
set(WRDSZ 64)
else()
message("Unsupported architecture: ${TARGET_ARCHITECTURE}" )
return()
endif()
else()
message("Unsupported OS: ${TARGET_OS}" )
return()
endif()

# The cmake documentation states that these are set. They are not so we
# set them here
set(CMAKE_HOST_SYSTEM_NAME ${TARGET_OS})
set(CMAKE_HOST_SYSTEM_PROCESSOR ${TARGET_ARCHITECTURE})

# If we are not building as a part of LLVM, build Flang as an
# standalone project, using LLVM as an external library:
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
Expand Down
2 changes: 2 additions & 0 deletions include/legacy-util-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ extern "C" {
#include <stdlib.h>
#include <string.h>
#include <time.h> /* time() */
#ifndef _WIN32
#include <unistd.h> /* getcwd() */
#endif

/* See tmpfile(3). */
FILE *tmpf(char *ignored);
Expand Down
32 changes: 32 additions & 0 deletions lib/scutil/cpu-stopwatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* since the most recent call. Very much not thread-safe.
*/

#ifndef _WIN32

#include <sys/times.h>
#include <unistd.h>
#include "scutil.h"
Expand Down Expand Up @@ -51,3 +53,33 @@ getcpu(void)
last = now;
return elapsed;
}

#else

#include <Windows.h>
//#include "scutil.h"

unsigned long
getcpu(void)
{
LARGE_INTEGER ticks_per_second = {-1};
LARGE_INTEGER ticks;

unsigned long last = 0;
unsigned long now, elapsed;

/* Initialize ticks_per_second. */
if (ticks_per_second.QuadPart <= 0)
QueryPerformanceFrequency(&ticks_per_second.QuadPart);

QueryPerformanceCounter(&ticks);
now = ticks.QuadPart;
now *= 1000; /* milliseconds */
now /= ticks_per_second.QuadPart;

elapsed = now - last;
last = now;
return elapsed;
}

#endif
2 changes: 1 addition & 1 deletion lib/scutil/host-fp-folding.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ configure_denormals(bool denorms_are_zeros, bool flush_to_zero)
fenv_t fenv;
if (fegetenv(&fenv) != 0)
fprintf(stderr, "fegetenv() failed: %s\n", strerror(errno));
#ifdef __x86_64__
#if defined(__x86_64__) && !defined(_WIN32)
fenv.__mxcsr &= ~0x0040;
if (denorms_are_zeros)
fenv.__mxcsr |= 0x0040;
Expand Down
10 changes: 9 additions & 1 deletion lib/scutil/lockfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@
* Clean up by deleting the uniquely named file we had created earlier.
*/

#include <unistd.h>
#ifndef _WIN32
#include <unistd.h>
#else
#include <Winsock2.h>
#include <process.h>
#endif
#include <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
Expand All @@ -64,6 +69,9 @@ static char *udir = NULL;
*/
static long uwaiting;

#ifdef _WIN32
#define pid_t int
#endif
int
__pg_make_lock_file(char *dir)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/scutil/path-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include "legacy-util-api.h"
#include <stddef.h>
#include <string.h>
#ifndef _WIN32
#include <unistd.h> /* access() */
#endif

void
basenam(const char *orig_path, const char *optional_suffix, char *basename)
Expand Down
11 changes: 8 additions & 3 deletions lib/scutil/pgnewfil.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
#include <sys/stat.h>
#include <fcntl.h>

#if defined(HOST_WIN)
#if defined(_WIN32)
#include <direct.h>
#include <io.h>
#include <sys/stat.h>
extern unsigned long getpid(void);
#else
#include <unistd.h>
Expand All @@ -42,6 +43,10 @@ int pgnewfil_debug = 0;
#endif
extern size_t strlen();

#ifndef S_ISDIR
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
#endif

/*
* copy chars from q to p, terminate string, return end of string
*/
Expand Down Expand Up @@ -307,7 +312,7 @@ pg_makenewfile(char *pfx, char *sfx, int make)
if (!make) {
break;
} else {
#if defined(HOST_WIN)
#if defined(_WIN32)
fd = _open(filename, _O_CREAT | _O_BINARY | _O_EXCL | _O_RDWR, _S_IWRITE);
#else
fd = open(filename, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
Expand Down Expand Up @@ -353,7 +358,7 @@ pg_makenewdir(char *pfx, char *sfx, int make)
if (r == -1 && errno == ENOENT) {
if (make) {
int err;
#if defined(HOST_WIN) || defined(WINNT) || defined(WIN64)
#if defined(_WIN32) || defined(WINNT) || defined(WIN64)
err = _mkdir(filename);
#else
err = mkdir(filename, S_IRWXG | S_IRWXO | S_IXUSR | S_IWUSR | S_IRUSR);
Expand Down
20 changes: 14 additions & 6 deletions runtime/flang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,12 @@ add_flang_library(flang_static
${FTN_SUPPORT}
${SHARED_SOURCES}
)

if (MSVC)
set_property(TARGET flang_static PROPERTY OUTPUT_NAME flang_static)
else()
set_property(TARGET flang_static PROPERTY OUTPUT_NAME flang)
endif()

set(SHARED_LIBRARY TRUE)
add_flang_library(flang_shared
Expand All @@ -489,9 +494,12 @@ add_flang_library(flang_shared
${SHARED_SOURCES}
)
set_property(TARGET flang_shared PROPERTY OUTPUT_NAME flang)
target_link_libraries(flang_shared ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/libflangrti.so)
target_link_libraries(flang_shared flangrti_shared)
# Resolve symbols against libm and librt
target_link_libraries(flang_shared m rt)
target_link_libraries(flang_shared rt)
if (NOT MSVC)
target_link_libraries(flang_shared m)
endif()

set(SHARED_LIBRARY FALSE)

Expand Down Expand Up @@ -538,7 +546,6 @@ set_source_files_properties(
OBJECT_DEPENDS ${CMAKE_Fortran_MODULE_DIRECTORY}/iso_c_binding.mod
)


set_target_properties(flang_static flang_shared
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${FLANG_RTE_LIB_DIR}
Expand Down Expand Up @@ -568,9 +575,10 @@ add_dependencies(flang_shared
flang2
)

target_compile_options(flang_static PRIVATE -fPIC)

target_compile_options(flang_shared PRIVATE -fPIC)
if (NOT MSVC)
target_compile_options(flang_static PRIVATE -fPIC)
target_compile_options(flang_shared PRIVATE -fPIC)
endif()

target_compile_options(flang_static PUBLIC $<$<COMPILE_LANGUAGE:Fortran>:-Mreentrant>)

Expand Down
2 changes: 2 additions & 0 deletions runtime/flang/access3f.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
/* access3f.c - Implements LIB3F access subroutine. */

/* must include ent3f.h AFTER io3f.h */
#ifndef _WIN32
#include <unistd.h>
#endif

#include "io3f.h"
#include "ent3f.h"
Expand Down
2 changes: 1 addition & 1 deletion runtime/flang/alarm3f.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/* alarm3f.c - Implements LIB3F alarm subprogram. */

#ifndef WINNT
#ifndef _WIN32
#include <signal.h>
#include "ent3f.h"

Expand Down
4 changes: 2 additions & 2 deletions runtime/flang/allo.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ I8(__fort_alloc)(__INT_T nelem, dtype kind, size_t len, __STAT_T *stat,
char msg[80];
char *p_env;

#if (defined(WIN64) || defined(WIN32))
#if (defined(_WIN32))
#define ALN_LARGE
#else
#undef ALN_LARGE
Expand Down Expand Up @@ -396,7 +396,7 @@ I8(__alloc04)(__NELEM_T nelem, dtype kind, size_t len,
if (!ISPRESENT(errmsg))
errmsg = NULL;

#if (defined(WIN64) || defined(WIN32))
#if (defined(_WIN32))
#define ALN_LARGE
#else
#undef ALN_LARGE
Expand Down
8 changes: 0 additions & 8 deletions runtime/flang/amod.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,8 @@

#include "mthdecls.h"

#if defined(WIN64)
float __fmth_i_amod(float f, float g);
#endif

float
__mth_i_amod(float f, float g)
{
#if defined(WIN64)
return __fmth_i_amod(f, g);
#else
return FMODF(f, g);
#endif
}
4 changes: 2 additions & 2 deletions runtime/flang/assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ __fortio_assign(char *item, /* where to store */
case __INT8:
if (__ftn_32in64_)
I64_MSH(valp->val.i8) = 0;
PP_INT4(item) = valp->val.i8[0];
PP_INT4(item + 4) = valp->val.i8[1];
PP_INT4(item) = I64_LSH(valp->val.i8);
PP_INT4(item + 4) = I64_MSH(valp->val.i8);
break;
case __REAL4:
PP_REAL4(item) = (float)I64_LSH(valp->val.i8);
Expand Down
Loading