From bf628dc6092a9007336a825c13e09d80663a05a5 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Sun, 16 Jun 2024 17:51:46 +0800 Subject: [PATCH] treewide: refactor some constants to environment.ts --- commands.ts | 95 +++++++++++++++++++++++++++++++++++++++++++------- compiler.ts | 48 ++----------------------- environment.ts | 22 ++++++++++++ 3 files changed, 108 insertions(+), 57 deletions(-) create mode 100644 environment.ts diff --git a/commands.ts b/commands.ts index ce7fc04..a15adfb 100644 --- a/commands.ts +++ b/commands.ts @@ -20,16 +20,87 @@ export function systemdRun(unit: string, workingDirectory: string = process.cwd( ]; } -export function runcpu(workload: string = 'test'): string[] { - return [ - "runcpu", - "-c", - "clang-O2", - "-i", - workload, - "pop2_s", - "--action", - "run", - "--nobuild", - ]; +function undefList(opt: T | undefined, fn: (opt: T) => U) { + return opt ? fn(opt) : [] +} + +const optFlag = (flag: string, opt: string | undefined) => undefList(opt, opt => [flag, opt]) + +export module SPECCommands { + + interface SPECOptions { + /** + * Config file, used for compiling flags, compiler versions, etc. + */ + config?: string + + /** + * SPEC workload scale for each benchmark + */ + workload?: "test" | "train" | "ref" + + /** + * Selected benchmarks + */ + benchmarks?: string[] + + buildType?: "nobuild" | "rebuild" | "plain", + } + + export function runcpuOptions(o: SPECOptions): string[] { + return [ + ...optFlag("-c", o.config), + ...optFlag("-i", o.workload), + ...undefList(o.buildType, opt => { + switch (opt) { + case "nobuild": + return ["--nobuild"] + case "rebuild": + return ["--rebuild"] + case "plain": + return [] + } + }), + ...undefList(o.benchmarks, bench => bench) + ] + } +} + +export module CompilerCommands { + + export interface GeneralOptions { + output?: string; + + outputKind?: "exe" | "object" | "assembly" | "preprocessed" + } + + export function generalCommand(options: GeneralOptions) { + return [ + ...optFlag("-o", options.output), + ...undefList(options.outputKind, (opt) => { + switch (opt) { + case "object": + return ["-c"] + case "exe": + return [] + case "assembly": + return ["-S"] + case "preprocessed": + return ["-E"] + } + }) + ] + } + + export interface PreprocessorOptions { + includeDirs?: string[]; + } + + export function preprocessorCommand(options: PreprocessorOptions) { + return [ + ...undefList(options.includeDirs, dirs => dirs.flatMap(name => ["-I", name])) + ] + } + + } diff --git a/compiler.ts b/compiler.ts index b2bc5a9..beb65a0 100644 --- a/compiler.ts +++ b/compiler.ts @@ -2,21 +2,8 @@ import child_process from "child_process" import { PlatformPath } from "path" import path from "path" -const PREFIX = "/home/lyc/workspace/sw-autovec/swllvm-13.0.0-vect0919/local/installed/85e4fed0c9e4cd4ab8bce89f307127ccbad31294" -const PREFIXBIN = path.join(PREFIX, "bin") -const LLVM_EXTRACT = path.join(PREFIXBIN, "llvm-extract") - -const SYSROOT_PREFIX = "/usr/sw/standard-830-6b-test" - -const CXX = path.join(PREFIXBIN, "clang++") -const CC = path.join(PREFIXBIN, "clang") -const FC = path.join(PREFIXBIN, "flang") - -const SYSROOT_COMMAND = [ - "--sysroot", - SYSROOT_PREFIX, -] - +// FIXME: these imports basically looks ugly. +import { LLVM_EXTRACT, PREFIX, SYSROOT_PREFIX, FLANG } from "./environment"; /** @@ -93,35 +80,6 @@ export async function extract(options: ExtractOptions) { return exitcode } -export interface GeneralOptions { - output?: string; - - outputKind?: "exe" | "object" | "assembly" | "preprocessed" -} - -export function generalCommand(options: GeneralOptions) { - return [ - ...(options.output ? ["-o", options.output] : []), - ...(options.outputKind ? { - exe: [], - object: ["-c"], - assembly: ["-S"], - preprocessed: ["-E"] - }[options.outputKind] : []) - ] -} - -export interface PreprocessorOptions { - includeDirs?: string[]; -} - -export function preprocessorCommand(options: PreprocessorOptions) { - return [ - ...((options.includeDirs ?? []).flatMap(name => ["-I", name])) - ] -} - - /** * Links objects into an executable using specified environment variables and paths. @@ -140,7 +98,7 @@ export async function link(objects: string[], exe: string) { // Construct link command const linkcmd = [ - FC, + FLANG, ...objects, "-L", path.join(PREFIX, 'lib'), // TODO: Implement rpath logic here if needed diff --git a/environment.ts b/environment.ts new file mode 100644 index 0000000..5a5999b --- /dev/null +++ b/environment.ts @@ -0,0 +1,22 @@ +import path from "path" + +export const HOME = path.join("/home", "lyc") + +export const SW_AUTOVEC = path.join(HOME, "workspace", "sw-autovec") + +export const LLVM_SRC = path.join(SW_AUTOVEC, "swllvm-13.0.0-vect0919") +export const LLVM_INSTALL = path.join(LLVM_SRC, "local", "installed") + +/// Default toolchain version used in SPEC2017 +export const PREFIX = path.join(LLVM_SRC, "85e4fed0c9e4cd4ab8bce89f307127ccbad31294") +export const PREFIXBIN = path.join(PREFIX, "bin") +export const LLVM_EXTRACT = path.join(PREFIXBIN, "llvm-extract") + + +export const SPEC = path.join(SW_AUTOVEC, "spec2017") + +export const CXX = path.join(PREFIXBIN, "clang++") +export const CC = path.join(PREFIXBIN, "clang") +export const FLANG = path.join(PREFIXBIN, "flang") + +export const SYSROOT_PREFIX = "/usr/sw/standard-830-6b-test"