command/compiler: add optimize and target options
This commit is contained in:
@@ -1,11 +1,37 @@
|
|||||||
import { optFlag, optMultiFlag, optSwitch, undefList } from "./common";
|
import { optFlag, optMultiFlag, optSwitch, undefList } from "./common";
|
||||||
|
|
||||||
export interface GeneralOptions {
|
export interface GeneralOptions {
|
||||||
output?: string
|
output?: string;
|
||||||
|
|
||||||
sysroot?: string
|
sysroot?: string;
|
||||||
|
|
||||||
outputKind?: "exe" | "object" | "assembly" | "preprocessed"
|
outputKind?: "exe" | "object" | "assembly" | "preprocessed";
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Sw64TargetOptions {
|
||||||
|
simd?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sw64TargetOptions(o: Sw64TargetOptions) {
|
||||||
|
return [
|
||||||
|
...optSwitch("-msimd", o.simd)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options That Control Optimization.
|
||||||
|
* https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
|
||||||
|
*/
|
||||||
|
export interface OptimizeOptions {
|
||||||
|
optimize?: "1" | "2" | "3" | "0" | "s" | "fast" | "g" | "z";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function optimizeOptions(o: OptimizeOptions) {
|
||||||
|
return [
|
||||||
|
...undefList(o.optimize, optimize => {
|
||||||
|
return [`-O${optimize}`];
|
||||||
|
})
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generalCommand(options: GeneralOptions) {
|
export function generalCommand(options: GeneralOptions) {
|
||||||
@@ -14,17 +40,17 @@ export function generalCommand(options: GeneralOptions) {
|
|||||||
...undefList(options.outputKind, (opt) => {
|
...undefList(options.outputKind, (opt) => {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case "object":
|
case "object":
|
||||||
return ["-c"]
|
return ["-c"];
|
||||||
case "exe":
|
case "exe":
|
||||||
return []
|
return [];
|
||||||
case "assembly":
|
case "assembly":
|
||||||
return ["-S"]
|
return ["-S"];
|
||||||
case "preprocessed":
|
case "preprocessed":
|
||||||
return ["-E"]
|
return ["-E"];
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
...optFlag("--sysroot", options.sysroot),
|
...optFlag("--sysroot", options.sysroot),
|
||||||
]
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LinkerOptions {
|
interface LinkerOptions {
|
||||||
@@ -44,7 +70,7 @@ export function linkerCommand(options: LinkerOptions) {
|
|||||||
return [
|
return [
|
||||||
...optMultiFlag("-L", options.searchDirs),
|
...optMultiFlag("-L", options.searchDirs),
|
||||||
...optMultiFlag("-l", options.libraries),
|
...optMultiFlag("-l", options.libraries),
|
||||||
]
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PreprocessorOptions {
|
export interface PreprocessorOptions {
|
||||||
@@ -54,7 +80,7 @@ export interface PreprocessorOptions {
|
|||||||
export function preprocessorCommand(options: PreprocessorOptions) {
|
export function preprocessorCommand(options: PreprocessorOptions) {
|
||||||
return [
|
return [
|
||||||
...optMultiFlag("-I", options.includeDirs),
|
...optMultiFlag("-I", options.includeDirs),
|
||||||
]
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user