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

PS4 support #3221

Merged
merged 1 commit into from Jul 1, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions include/swift/Basic/LangOptions.h
Expand Up @@ -184,8 +184,7 @@ namespace swift {
Target.getOSVersion(major, minor, revision);
} else if (Target.isOSLinux() || Target.isOSFreeBSD() ||
Target.isAndroid() || Target.isOSWindows() ||
Target.getTriple().empty())
{
Target.isPS4() || Target.getTriple().empty()) {
major = minor = revision = 0;
} else {
llvm_unreachable("Unsupported target OS");
Expand Down
8 changes: 5 additions & 3 deletions lib/Basic/LangOptions.cpp
Expand Up @@ -31,7 +31,8 @@ static const StringRef SupportedConditionalCompilationOSs[] = {
"Linux",
"FreeBSD",
"Windows",
"Android"
"Android",
"PS4",
};

static const StringRef SupportedConditionalCompilationArches[] = {
Expand Down Expand Up @@ -128,9 +129,10 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
addPlatformConditionValue("os", "FreeBSD");
else if (triple.isOSWindows())
addPlatformConditionValue("os", "Windows");
else {
else if (triple.isPS4())
addPlatformConditionValue("os", "PS4");
else
UnsupportedOS = true;
}

bool UnsupportedArch = false;

Expand Down
3 changes: 2 additions & 1 deletion lib/Basic/Platform.cpp
Expand Up @@ -105,7 +105,6 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
case llvm::Triple::CUDA:
case llvm::Triple::NVCL:
case llvm::Triple::AMDHSA:
case llvm::Triple::PS4:
case llvm::Triple::ELFIAMCU:
return "";
case llvm::Triple::Darwin:
Expand All @@ -120,6 +119,8 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
return "freebsd";
case llvm::Triple::Win32:
return "windows";
case llvm::Triple::PS4:
return "ps4";
}
llvm_unreachable("unsupported OS");
}
Expand Down
37 changes: 21 additions & 16 deletions lib/IRGen/IRGenModule.cpp
Expand Up @@ -796,6 +796,15 @@ llvm::SmallString<32> getTargetDependentLibraryOption(const llvm::Triple &T,
buffer += ".lib";
if (quote)
buffer += '"';
} else if (T.isPS4()) {
bool quote = library.find(' ') != StringRef::npos;

buffer += "\01";
if (quote)
buffer += '"';
buffer += library;
if (quote)
buffer += '"';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches what Clang does in its PS4TargetCodeGenInfo, so LGTM.

} else {
buffer += "-l";
buffer += library;
Expand Down Expand Up @@ -897,11 +906,9 @@ void IRGenModule::emitAutolinkInfo() {
}),
AutolinkEntries.end());

switch (TargetInfo.OutputObjectFormat) {
case llvm::Triple::UnknownObjectFormat:
llvm_unreachable("unknown object format");
case llvm::Triple::COFF:
case llvm::Triple::MachO: {
if (TargetInfo.OutputObjectFormat == llvm::Triple::COFF ||
TargetInfo.OutputObjectFormat == llvm::Triple::MachO ||
Triple.isPS4()) {
llvm::LLVMContext &ctx = Module.getContext();

if (!LinkerOptions) {
Expand All @@ -917,9 +924,10 @@ void IRGenModule::emitAutolinkInfo() {
(void)FoundOldEntry;
assert(FoundOldEntry && "Could not replace old linker options entry?");
}
break;
}
case llvm::Triple::ELF: {
} else {
assert(TargetInfo.OutputObjectFormat == llvm::Triple::ELF &&
"expected ELF output format");

// Merge the entries into null-separated string.
llvm::SmallString<64> EntriesString;
for (auto &EntryNode : AutolinkEntries) {
Expand All @@ -931,19 +939,16 @@ void IRGenModule::emitAutolinkInfo() {
}
}
auto EntriesConstant = llvm::ConstantDataArray::getString(
LLVMContext, EntriesString, /*AddNull=*/false);
LLVMContext, EntriesString, /*AddNull=*/false);

auto var = new llvm::GlobalVariable(*getModule(),
EntriesConstant->getType(), true,
llvm::GlobalValue::PrivateLinkage,
EntriesConstant,
"_swift1_autolink_entries");
auto var =
new llvm::GlobalVariable(*getModule(), EntriesConstant->getType(), true,
llvm::GlobalValue::PrivateLinkage,
EntriesConstant, "_swift1_autolink_entries");
var->setSection(".swift1_autolink_entries");
var->setAlignment(getPointerAlignment().getValue());

addUsedGlobal(var);
break;
}
}

if (!IRGen.Opts.ForceLoadSymbolName.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/StdlibUnittest/RaceTest.swift
Expand Up @@ -40,7 +40,7 @@ import SwiftPrivate
import SwiftPrivatePthreadExtras
#if os(OSX) || os(iOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
import Glibc
#endif

Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/StdlibUnittest/StdlibCoreExtras.swift
Expand Up @@ -14,7 +14,7 @@ import SwiftPrivate
import SwiftPrivateLibcExtras
#if os(OSX) || os(iOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
import Glibc
#endif

Expand Down
20 changes: 19 additions & 1 deletion stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb
Expand Up @@ -20,7 +20,7 @@ import SwiftPrivateLibcExtras

#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
import Glibc
#endif

Expand Down Expand Up @@ -1406,6 +1406,7 @@ public enum OSVersion : CustomStringConvertible {
case linux
case freeBSD
case android
case ps4

public var description: String {
switch self {
Expand All @@ -1427,6 +1428,8 @@ public enum OSVersion : CustomStringConvertible {
return "Linux"
case .freeBSD:
return "FreeBSD"
case .ps4:
return "PS4"
case .android:
return "Android"
}
Expand Down Expand Up @@ -1463,6 +1466,8 @@ func _getOSVersion() -> OSVersion {
return .linux
#elseif os(FreeBSD)
return .freeBSD
#elseif os(PS4)
return .ps4
#elseif os(Android)
return .android
#else
Expand Down Expand Up @@ -1539,6 +1544,8 @@ public enum TestRunPredicate : CustomStringConvertible {

case freeBSDAny(reason: String)

case ps4Any(reason: String)

case androidAny(reason: String)

case objCRuntime(/*reason:*/ String)
Expand Down Expand Up @@ -1624,6 +1631,9 @@ public enum TestRunPredicate : CustomStringConvertible {
case .freeBSDAny(reason: let reason):
return "freeBSDAny(*, reason: \(reason))"

case .ps4Any(reason: let reason):
return "ps4Any(*, reason: \(reason))"

case .objCRuntime(let reason):
return "Objective-C runtime, reason: \(reason))"
case .nativeRuntime(let reason):
Expand Down Expand Up @@ -1881,6 +1891,14 @@ public enum TestRunPredicate : CustomStringConvertible {
return false
}

case .ps4Any:
switch _getRunningOSVersion() {
case .ps4:
return true
default:
return false
}

case .objCRuntime:
#if _runtime(_ObjC)
return true
Expand Down
6 changes: 4 additions & 2 deletions stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift
Expand Up @@ -13,7 +13,7 @@
import SwiftPrivate
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
import Glibc
#endif

Expand Down Expand Up @@ -284,7 +284,9 @@ internal func _getEnviron() -> UnsafeMutablePointer<UnsafeMutablePointer<CChar>?
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
return _NSGetEnviron().pointee
#elseif os(FreeBSD)
return environ;
return environ
#elseif os(PS4)
return environ
#elseif os(Android)
return environ
#else
Expand Down
Expand Up @@ -13,7 +13,7 @@
import SwiftPrivate
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
import Glibc
#endif

Expand Down
Expand Up @@ -12,7 +12,7 @@

#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
import Glibc
#endif

Expand Down
Expand Up @@ -17,7 +17,7 @@

#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
import Glibc
#endif

Expand Down
12 changes: 6 additions & 6 deletions stdlib/public/Platform/Platform.swift
Expand Up @@ -96,7 +96,7 @@ public func || <T : Boolean>(

public var errno : Int32 {
get {
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD)
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD) || os(PS4)
return __error().pointee
// FIXME: os(Windows) should be replaced, such as triple(Cygwin)
#elseif os(Android) || os(Windows)
Expand All @@ -106,7 +106,7 @@ public var errno : Int32 {
#endif
}
set(val) {
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD)
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD) || os(PS4)
return __error().pointee = val
#elseif os(Android) || os(Windows)
return __errno().pointee = val
Expand All @@ -121,7 +121,7 @@ public var errno : Int32 {
// stdio.h
//===----------------------------------------------------------------------===//

#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD)
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD) || os(PS4)
public var stdin : UnsafeMutablePointer<FILE> {
get {
return __stdinp
Expand Down Expand Up @@ -354,7 +354,7 @@ public var SIG_DFL: sig_t? { return nil }
public var SIG_IGN: sig_t { return unsafeBitCast(1, to: sig_t.self) }
public var SIG_ERR: sig_t { return unsafeBitCast(-1, to: sig_t.self) }
public var SIG_HOLD: sig_t { return unsafeBitCast(5, to: sig_t.self) }
#elseif os(Linux) || os(FreeBSD) || os(Android) || os(Windows)
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Windows)
#if os(Windows)
// In Cygwin, the below SIG_* have the same value with Linux.
// Verified with libstdc++6 v5.3.0 in Cygwin v2.4.1 64bit.
Expand Down Expand Up @@ -386,7 +386,7 @@ public var SEM_FAILED: UnsafeMutablePointer<sem_t>? {
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
// The value is ABI. Value verified to be correct for OS X, iOS, watchOS, tvOS.
return UnsafeMutablePointer<sem_t>(bitPattern: -1)
#elseif os(Linux) || os(FreeBSD) || os(Android) || os(Windows)
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Windows)
// The value is ABI. Value verified to be correct on Glibc.
return UnsafeMutablePointer<sem_t>(bitPattern: 0)
#else
Expand Down Expand Up @@ -429,7 +429,7 @@ public func sem_open(
//===----------------------------------------------------------------------===//

// FreeBSD defines extern char **environ differently than Linux.
#if os(FreeBSD)
#if os(FreeBSD) || os(PS4)
@_silgen_name("_swift_FreeBSD_getEnv")
func _swift_FreeBSD_getEnv(
) -> UnsafeMutablePointer<UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>>
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Platform/tgmath.swift.gyb
Expand Up @@ -247,7 +247,7 @@ public func scalbn(_ x: ${T}, _ n: Int) -> ${T} {

% # This is AllFloatTypes not OverlayFloatTypes because of the tuple return.
% for T, CT, f in AllFloatTypes():
#if os(Linux) || os(FreeBSD) || os(Android) || os(Windows)
#if os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Windows)
@_transparent
public func lgamma(_ x: ${T}) -> (${T}, Int) {
var sign = CInt(0)
Expand Down
2 changes: 1 addition & 1 deletion test/1_stdlib/PrintFloat.swift
Expand Up @@ -6,7 +6,7 @@
// REQUIRES: executable_test

import StdlibUnittest
#if os(Linux) || os(FreeBSD) || os(Android)
#if os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
import Glibc
#else
import Darwin
Expand Down
2 changes: 1 addition & 1 deletion test/1_stdlib/tgmath.swift
@@ -1,7 +1,7 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test

#if os(Linux) || os(FreeBSD) || os(Android)
#if os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
import Glibc
// FIXME: this is a quick hack for non Darwin platforms
// where they doesn't have CoreGraphics module.
Expand Down
2 changes: 1 addition & 1 deletion test/1_stdlib/tgmath_optimized.swift
Expand Up @@ -3,7 +3,7 @@
// RUN: %target-run %t/a.out
// REQUIRES: executable_test

#if os(Linux) || os(FreeBSD) || os(Android)
#if os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
import Glibc
#else
import Darwin
Expand Down
13 changes: 13 additions & 0 deletions test/IRGen/autolink-psei.swift
@@ -0,0 +1,13 @@
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: %swift -target x86_64-scei-ps4 -parse-as-library -parse-stdlib -emit-module-path %t/module.swiftmodule -module-name module -module-link-name module %s
// RUN: %swift -target x86_64-scei-ps4 -parse-as-library -parse-stdlib -module-name autolink -I %t -D MAIN_MODULE -emit-ir -o - %s | FileCheck %s -check-prefix CHECK-IR

#if MAIN_MODULE
import module
#endif

// CHECK-IR: !{{[0-9]+}} = !{i32 {{[0-9]+}}, !"Linker Options", [[NODE:![0-9]+]]}
// CHECK-IR: [[NODE]] = !{[[LIST:![0-9]+]]}
// CHECK-IR: [[LIST]] = !{!"\01module"}

2 changes: 1 addition & 1 deletion test/Interpreter/SDK/libc.swift
Expand Up @@ -7,7 +7,7 @@

#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
import Glibc
#endif

Expand Down
16 changes: 16 additions & 0 deletions test/Parse/ConditionalCompilation/x86_64PS4Target.swift
@@ -0,0 +1,16 @@
// RUN: %swift -parse %s -verify -target x86_64-scei-ps4 -disable-objc-interop -parse-stdlib
// RUN: %swift-ide-test -test-input-complete -source-filename %s -target x86_64-scei-ps4

#if os(FreeBSD)
// This block should not parse.
// os(FreeBSD) does not imply os(PS4)
let i : Int = "Hello"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no space before ":".

#endif

#if arch(x86_64) && os(PS4) && _runtime(_Native) && _endian(little)
class C {}
var x = C()
#endif

var y = x

Expand Up @@ -2,7 +2,7 @@
// REQUIRES: executable_test

import StdlibUnittest
#if os(Linux) || os(FreeBSD) || os(Android)
#if os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
import Glibc
#else
import Darwin
Expand Down