Skip to content

[SystemZ][z/OS] Refactor AutoConvert more #143955

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

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 16 additions & 29 deletions llvm/include/llvm/Support/AutoConvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <_Ccsid.h>
#endif
#ifdef __cplusplus
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/Error.h"
#include <system_error>
#endif /* __cplusplus */

Expand All @@ -41,6 +41,21 @@ int restorezOSStdHandleAutoConversion(int FD);
#ifdef __cplusplus
namespace llvm {

#ifdef __MVS__

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

/** \brief Get the the tag ccsid for a file name or a file descriptor. */
ErrorOr<__ccsid_t> getzOSFileTag(const char *FileName, const int FD = -1);

/** \brief Query the file tag to determine if it needs conversion to UTF-8
* codepage.
*/
ErrorOr<bool> needzOSConversion(const char *FileName, const int FD = -1);

#endif /* __MVS__*/

inline std::error_code disableAutoConversion(int FD) {
#ifdef __MVS__
if (::disablezOSAutoConversion(FD) == -1)
Expand Down Expand Up @@ -79,34 +94,6 @@ inline ErrorOr<bool> needConversion(const char *FileName, const int FD = -1) {
return false;
}

#ifdef __MVS__

/** \brief Disable the z/OS enhanced ASCII auto-conversion for the file
* descriptor.
*/
std::error_code disablezOSAutoConversion(int FD);

/** \brief Query the z/OS enhanced ASCII auto-conversion status of a file
* descriptor and force the conversion if the file is not tagged with a
* codepage.
*/
std::error_code enablezOSAutoConversion(int FD);

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

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

/** \brief Get the the tag ccsid for a file name or a file descriptor. */
ErrorOr<__ccsid_t> getzOSFileTag(const char *FileName, const int FD = -1);

/** \brief Query the file tag to determine if it needs conversion to UTF-8
* codepage.
*/
ErrorOr<bool> needzOSConversion(const char *FileName, const int FD = -1);

#endif /* __MVS__*/
} /* namespace llvm */
#endif /* __cplusplus */

Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Support/AutoConvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#ifdef __MVS__

#include "llvm/Support/AutoConvert.h"
#include "llvm/Support/Error.h"
#include <cassert>
#include <fcntl.h>
#include <sys/stat.h>
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Support/Unix/Path.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1097,14 +1097,14 @@ std::error_code openFile(const Twine &Name, int &ResultFD,
!Stat.st_tag.ft_txtflag && !Stat.st_tag.ft_ccsid &&
Stat.st_size == 0;
if (Flags & OF_Text) {
if (auto EC = llvm::enablezOSAutoConversion(ResultFD))
if (auto EC = llvm::enableAutoConversion(ResultFD))
return EC;
if (DoSetTag) {
if (auto EC = llvm::setzOSFileTag(ResultFD, CCSID_IBM_1047, true))
return EC;
}
} else {
if (auto EC = llvm::disablezOSAutoConversion(ResultFD))
if (auto EC = llvm::disableAutoConversion(ResultFD))
return EC;
if (DoSetTag) {
if (auto EC = llvm::setzOSFileTag(ResultFD, FT_BINARY, false))
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Support/Unix/Program.inc
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ std::error_code llvm::sys::ChangeStdoutMode(fs::OpenFlags Flags) {

std::error_code llvm::sys::ChangeStdinToBinary() {
#ifdef __MVS__
return disablezOSAutoConversion(STDIN_FILENO);
return disableAutoConversion(STDIN_FILENO);
#else
// Do nothing, as Unix doesn't differentiate between text and binary.
return std::error_code();
Expand Down
Loading