forked from swiftlang/swift-syntax
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request swiftlang#2063 from StevenWong12/move_swift_parser…
…_cli
- Loading branch information
Showing
20 changed files
with
127 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// swift-tools-version:5.7 | ||
|
||
import Foundation | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "SwiftParserCLI", | ||
platforms: [ | ||
.macOS(.v10_15) | ||
], | ||
products: [ | ||
.executable(name: "swift-parser-cli", targets: ["swift-parser-cli"]) | ||
], | ||
dependencies: [ | ||
.package(path: "..") | ||
], | ||
targets: [ | ||
.target( | ||
name: "InstructionCounter" | ||
), | ||
|
||
.executableTarget( | ||
name: "swift-parser-cli", | ||
dependencies: [ | ||
"InstructionCounter", | ||
.product(name: "SwiftBasicFormat", package: "swift-syntax"), | ||
.product(name: "SwiftDiagnostics", package: "swift-syntax"), | ||
.product(name: "SwiftOperators", package: "swift-syntax"), | ||
.product(name: "SwiftParser", package: "swift-syntax"), | ||
.product(name: "SwiftParserDiagnostics", package: "swift-syntax"), | ||
.product(name: "SwiftSyntax", package: "swift-syntax"), | ||
.product(name: "ArgumentParser", package: "swift-argument-parser"), | ||
] | ||
), | ||
] | ||
) | ||
|
||
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil { | ||
// Building standalone. | ||
package.dependencies += [ | ||
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2") | ||
] | ||
} else { | ||
package.dependencies += [ | ||
.package(path: "../../swift-argument-parser") | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# SwiftParserCLI | ||
|
||
This directory contains the source files of the `swift-parser-cli` program. | ||
|
||
You can build `swift-parser-cli` by checking out `swift-syntax` and running | ||
``` | ||
swift build --package-path SwiftParserCLI | ||
``` | ||
or entering this directory and running | ||
``` | ||
swift build | ||
``` | ||
|
||
You can also open the `SwiftParserCLI` package and building the `swift-parser-cli` target in Xcode. |
17 changes: 17 additions & 0 deletions
17
SwiftParserCLI/Sources/InstructionCounter/include/InstructionsExecuted.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <stdint.h> | ||
|
||
/// On macOS returns the number of instructions the process has executed since | ||
/// it was launched, on all other platforms returns 0. | ||
uint64_t getInstructionsExecuted(); |
38 changes: 38 additions & 0 deletions
38
SwiftParserCLI/Sources/InstructionCounter/src/InstructionsExecuted.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#if __APPLE__ | ||
#include <TargetConditionals.h> | ||
#if TARGET_OS_MAC && !TARGET_OS_IPHONE | ||
#define TARGET_IS_MACOS 1 | ||
#endif | ||
#endif | ||
|
||
#include "InstructionsExecuted.h" | ||
|
||
#ifdef TARGET_IS_MACOS | ||
#include <libproc.h> | ||
#include <sys/resource.h> | ||
#include <unistd.h> | ||
|
||
uint64_t getInstructionsExecuted() { | ||
struct rusage_info_v4 ru; | ||
if (proc_pid_rusage(getpid(), RUSAGE_INFO_V4, (rusage_info_t *)&ru) == 0) { | ||
return ru.ri_instructions; | ||
} | ||
return 0; | ||
} | ||
#else | ||
uint64_t getInstructionsExecuted() { | ||
return 0; | ||
} | ||
#endif |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters