Skip to content

Commit eedc956

Browse files
committed
use inline functions
1 parent cef5a31 commit eedc956

File tree

4 files changed

+84
-25
lines changed

4 files changed

+84
-25
lines changed

llvm/include/llvm/Support/AutoConvert.h

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#ifdef __MVS__
1818
#include <_Ccsid.h>
19+
#endif
1920
#ifdef __cplusplus
2021
#include "llvm/Support/ErrorOr.h"
2122
#include <system_error>
@@ -28,16 +29,55 @@
2829
#ifdef __cplusplus
2930
extern "C" {
3031
#endif /* __cplusplus */
32+
3133
int enablezOSAutoConversion(int FD);
3234
int disablezOSAutoConversion(int FD);
3335
int restorezOSStdHandleAutoConversion(int FD);
36+
3437
#ifdef __cplusplus
3538
}
3639
#endif /* __cplusplus */
3740

3841
#ifdef __cplusplus
3942
namespace llvm {
4043

44+
inline std::error_code disableAutoConversion(int FD) {
45+
#ifdef __MVS__
46+
return disablezOSAutoConversion(FD);
47+
#endif
48+
return std::error_code();
49+
}
50+
51+
inline std::error_code enableAutoConversion(int FD) {
52+
#ifdef __MVS__
53+
return enablezOSAutoConversion(FD);
54+
#endif
55+
return std::error_code();
56+
}
57+
58+
inline std::error_code restoreStdHandleAutoConversion(int FD) {
59+
#ifdef __MVS__
60+
return restorezOSStdHandleAutoConversion(FD);
61+
#endif
62+
return std::error_code();
63+
}
64+
65+
inline std::error_code setFileTag(int FD, int CCSID, bool Text) {
66+
#ifdef __MVS__
67+
return setzOSFileTag(FD, CCSID, Text);
68+
#endif
69+
return std::error_code();
70+
}
71+
72+
inline ErrorOr<bool> needConversion(const char *FileName, const int FD = -1) {
73+
#ifdef __MVS__
74+
return needzOSConversion(FileName, FD);
75+
#endif
76+
return false;
77+
}
78+
79+
#ifdef __MVS__
80+
4181
/** \brief Disable the z/OS enhanced ASCII auto-conversion for the file
4282
* descriptor.
4383
*/
@@ -49,9 +89,11 @@ std::error_code disablezOSAutoConversion(int FD);
4989
*/
5090
std::error_code enablezOSAutoConversion(int FD);
5191

92+
5293
/** Restore the z/OS enhanced ASCII auto-conversion for the std handle. */
5394
std::error_code restorezOSStdHandleAutoConversion(int FD);
5495

96+
5597
/** \brief Set the tag information for a file descriptor. */
5698
std::error_code setzOSFileTag(int FD, int CCSID, bool Text);
5799

@@ -63,9 +105,8 @@ ErrorOr<__ccsid_t> getzOSFileTag(const char *FileName, const int FD = -1);
63105
*/
64106
ErrorOr<bool> needzOSConversion(const char *FileName, const int FD = -1);
65107

108+
#endif /* __MVS__*/
66109
} /* namespace llvm */
67110
#endif /* __cplusplus */
68111

69-
#endif /* __MVS__ */
70-
71112
#endif /* LLVM_SUPPORT_AUTOCONVERT_H */

llvm/lib/Support/InitLLVM.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,28 @@
1818
#include "llvm/Support/Windows/WindowsSupport.h"
1919
#endif
2020

21-
#ifdef __MVS__
21+
#if defined(HAVE_UNISTD_H)
2222
#include <unistd.h>
23+
#else
24+
#ifndef STDIN_FILENO
25+
#define STDIN_FILENO 0
26+
#endif
27+
#ifndef STDOUT_FILENO
28+
#define STDOUT_FILENO 1
29+
#endif
30+
#ifndef STDERR_FILENO
31+
#define STDERR_FILENO 2
32+
#endif
33+
#endif
2334

2435
void CleanupStdHandles(void *Cookie) {
2536
llvm::raw_ostream *Outs = &llvm::outs(), *Errs = &llvm::errs();
2637
Outs->flush();
2738
Errs->flush();
28-
llvm::restorezOSStdHandleAutoConversion(STDIN_FILENO);
29-
llvm::restorezOSStdHandleAutoConversion(STDOUT_FILENO);
30-
llvm::restorezOSStdHandleAutoConversion(STDERR_FILENO);
39+
llvm::restoreStdHandleAutoConversion(STDIN_FILENO);
40+
llvm::restoreStdHandleAutoConversion(STDOUT_FILENO);
41+
llvm::restoreStdHandleAutoConversion(STDERR_FILENO);
3142
}
32-
#endif
3343

3444
using namespace llvm;
3545
using namespace llvm::sys;
@@ -41,10 +51,10 @@ InitLLVM::InitLLVM(int &Argc, const char **&Argv,
4151
assert(!Initialized && "InitLLVM was already initialized!");
4252
Initialized = true;
4353
#endif
44-
#ifdef __MVS__
54+
4555
// Bring stdin/stdout/stderr into a known state.
4656
sys::AddSignalHandler(CleanupStdHandles, nullptr);
47-
#endif
57+
4858
if (InstallPipeSignalExitHandler)
4959
// The pipe signal handler must be installed before any other handlers are
5060
// registered. This is because the Unix \ref RegisterHandlers function does
@@ -68,8 +78,8 @@ InitLLVM::InitLLVM(int &Argc, const char **&Argv,
6878

6979
// If turning on conversion for stderr fails then the error message
7080
// may be garbled. There is no solution to this problem.
71-
ExitOnErr(errorCodeToError(llvm::enablezOSAutoConversion(STDERR_FILENO)));
72-
ExitOnErr(errorCodeToError(llvm::enablezOSAutoConversion(STDOUT_FILENO)));
81+
ExitOnErr(errorCodeToError(llvm::enableAutoConversion(STDERR_FILENO)));
82+
ExitOnErr(errorCodeToError(llvm::enableAutoConversion(STDOUT_FILENO)));
7383
#endif
7484

7585
#ifdef _WIN32
@@ -97,8 +107,6 @@ InitLLVM::InitLLVM(int &Argc, const char **&Argv,
97107
}
98108

99109
InitLLVM::~InitLLVM() {
100-
#ifdef __MVS__
101110
CleanupStdHandles(nullptr);
102-
#endif
103111
llvm_shutdown();
104112
}

llvm/lib/Support/MemoryBuffer.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/ADT/SmallString.h"
1616
#include "llvm/Config/config.h"
1717
#include "llvm/Support/Alignment.h"
18+
#include "llvm/Support/AutoConvert.h"
1819
#include "llvm/Support/Errc.h"
1920
#include "llvm/Support/Error.h"
2021
#include "llvm/Support/ErrorHandling.h"
@@ -34,9 +35,6 @@
3435
#include <io.h>
3536
#endif
3637

37-
#ifdef __MVS__
38-
#include "llvm/Support/AutoConvert.h"
39-
#endif
4038
using namespace llvm;
4139

4240
//===----------------------------------------------------------------------===//
@@ -508,15 +506,15 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
508506
}
509507

510508
#ifdef __MVS__
511-
ErrorOr<bool> NeedConversion = needzOSConversion(Filename.str().c_str(), FD);
512-
if (std::error_code EC = NeedConversion.getError())
509+
ErrorOr<bool> NeedsConversion = needConversion(Filename.str().c_str(), FD);
510+
if (std::error_code EC = NeedsConversion.getError())
513511
return EC;
514512
// File size may increase due to EBCDIC -> UTF-8 conversion, therefore we
515513
// cannot trust the file size and we create the memory buffer by copying
516514
// off the stream.
517515
// Note: This only works with the assumption of reading a full file (i.e,
518516
// Offset == 0 and MapSize == FileSize). Reading a file slice does not work.
519-
if (Offset == 0 && MapSize == FileSize && *NeedConversion)
517+
if (*NeedsConversion && Offset == 0 && MapSize == FileSize)
520518
return getMemoryBufferForStream(FD, Filename);
521519
#endif
522520

llvm/lib/Support/raw_ostream.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434

3535
#if defined(HAVE_UNISTD_H)
3636
# include <unistd.h>
37+
#else
38+
#ifndef STDIN_FILENO
39+
#define STDIN_FILENO 0
40+
#endif
41+
#ifndef STDOUT_FILENO
42+
#define STDOUT_FILENO 1
43+
#endif
44+
#ifndef STDERR_FILENO
45+
#define STDERR_FILENO 2
46+
#endif
3747
#endif
3848

3949
#if defined(__CYGWIN__)
@@ -894,21 +904,23 @@ void raw_fd_ostream::anchor() {}
894904
raw_fd_ostream &llvm::outs() {
895905
// Set buffer settings to model stdout behavior.
896906
std::error_code EC;
897-
#ifdef __MVS__
898-
EC = enablezOSAutoConversion(STDOUT_FILENO);
907+
908+
// On z/OS we need to enable auto conversion
909+
EC = enableAutoConversion(STDOUT_FILENO);
899910
assert(!EC);
900-
#endif
911+
901912
static raw_fd_ostream S("-", EC, sys::fs::OF_None);
902913
assert(!EC);
903914
return S;
904915
}
905916

906917
raw_fd_ostream &llvm::errs() {
907918
// Set standard error to be unbuffered.
908-
#ifdef __MVS__
909-
std::error_code EC = enablezOSAutoConversion(STDERR_FILENO);
919+
920+
// On z/OS we need to enable auto conversion
921+
std::error_code EC = enableAutoConversion(STDERR_FILENO);
910922
assert(!EC);
911-
#endif
923+
912924
static raw_fd_ostream S(STDERR_FILENO, false, true);
913925
return S;
914926
}

0 commit comments

Comments
 (0)