Skip to content

Commit d9d2eb6

Browse files
AJIOBsylvestre
authored andcommitted
Assembly language support
1 parent 898254e commit d9d2eb6

File tree

8 files changed

+105
-6
lines changed

8 files changed

+105
-6
lines changed

.github/workflows/integration-tests.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ jobs:
556556
- name: Chmod for binary
557557
run: chmod +x ${SCCACHE_PATH}
558558

559-
- name: Test
559+
- name: Test C/C++
560560
run: |
561561
export CXX="${SCCACHE_PATH} clang++"
562562
$CXX -c `pwd`/tests/test_clang_multicall.c
@@ -576,6 +576,16 @@ jobs:
576576
577577
${SCCACHE_PATH} --show-stats | grep -e "Cache hits\s*[1-9]"
578578
579+
- name: Test ASM
580+
run: |
581+
export ASM="${SCCACHE_PATH} clang"
582+
$ASM -c `pwd`/tests/test_intel_asm.s
583+
584+
- name: Test ASM with preprocessor
585+
run: |
586+
export ASM="${SCCACHE_PATH} clang"
587+
$ASM -c `pwd`/tests/test_intel_asm_to_preproc.S
588+
579589
hip:
580590
# Probably wouldn't matter anyway since we run in a container, but staying
581591
# close to the version is better than not.
@@ -699,7 +709,7 @@ jobs:
699709
- name: Chmod for binary
700710
run: chmod +x ${SCCACHE_PATH}
701711

702-
- name: Test
712+
- name: Test C/C++
703713
run: |
704714
export CXX="${SCCACHE_PATH} g++"
705715
$CXX -c `pwd`/tests/test_clang_multicall.c
@@ -719,6 +729,16 @@ jobs:
719729
720730
${SCCACHE_PATH} --show-stats | grep -e "Cache hits\s*[1-9]"
721731
732+
- name: Test ASM
733+
run: |
734+
export ASM="${SCCACHE_PATH} gcc"
735+
$ASM -c `pwd`/tests/test_intel_asm.s
736+
737+
- name: Test ASM with preprocessor
738+
run: |
739+
export ASM="${SCCACHE_PATH} gcc"
740+
$ASM -c `pwd`/tests/test_intel_asm_to_preproc.S
741+
722742
autotools:
723743
runs-on: ubuntu-24.04
724744
needs: build

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sccache - Shared Compilation Cache
1212

1313
sccache is a [ccache](https://ccache.dev/)-like compiler caching tool. It is used as a compiler wrapper and avoids compilation when possible, storing cached results either on [local disk](docs/Local.md) or in one of [several cloud storage backends](#storage-options).
1414

15-
sccache includes support for caching the compilation of C/C++ code, [Rust](docs/Rust.md), as well as NVIDIA's CUDA using [nvcc](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html), and [clang](https://llvm.org/docs/CompileCudaWithLLVM.html).
15+
sccache includes support for caching the compilation of Assembler, C/C++ code, [Rust](docs/Rust.md), as well as NVIDIA's CUDA using [nvcc](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html), and [clang](https://llvm.org/docs/CompileCudaWithLLVM.html), [AMD's ROCm HIP](https://rocm.docs.amd.com/projects/HIP/en/latest/index.html).
1616

1717
sccache also provides [icecream](https://github.com/icecc/icecream)-style distributed compilation (automatic packaging of local toolchains) for all supported compilers (including Rust). The distributed compilation system includes several security features that icecream lacks such as authentication, transport layer encryption, and sandboxed compiler execution on build servers. See [the distributed quickstart](docs/DistributedQuickstart.md) guide for more information.
1818

@@ -157,7 +157,7 @@ export RUSTC_WRAPPER=/path/to/sccache
157157
cargo build
158158
```
159159

160-
sccache supports gcc, clang, MSVC, rustc, [NVCC](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html), [NVC++](https://docs.nvidia.com/hpc-sdk//compilers/hpc-compilers-user-guide/index.html), and [Wind River's diab compiler](https://www.windriver.com/products/development-tools/#diab_compiler). Both gcc and msvc support Response Files, read more about their implementation [here](docs/ResponseFiles.md).
160+
sccache supports gcc, clang, MSVC, rustc, [NVCC](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html), [NVC++](https://docs.nvidia.com/hpc-sdk//compilers/hpc-compilers-user-guide/index.html), [hipcc](https://rocm.docs.amd.com/projects/HIP/en/latest/index.html), and [Wind River's diab compiler](https://www.windriver.com/products/development-tools/#diab_compiler). Both gcc and msvc support Response Files, read more about their implementation [here](docs/ResponseFiles.md).
161161

162162
If you don't [specify otherwise](#storage-options), sccache will use a local disk cache.
163163

src/compiler/c.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,10 @@ mod test {
16571657
assert_eq!(actual, Some(expected));
16581658
}
16591659

1660+
t("s", Language::Assembler);
1661+
t("S", Language::AssemblerToPreprocess);
1662+
t("sx", Language::AssemblerToPreprocess);
1663+
16601664
t("c", Language::C);
16611665

16621666
t("i", Language::CPreprocessed);

src/compiler/clang.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ impl CCompilerImpl for Clang {
127127
};
128128

129129
// Clang 14 and later support -fminimize-whitespace, which normalizes away non-semantic whitespace which in turn increases cache hit rate.
130-
if self.is_minversion(14) {
130+
// '-fminimize-whitespace' invalid for input of type assembler-with-cpp
131+
if self.is_minversion(14) && parsed_args.language != Language::AssemblerToPreprocess {
131132
ignorable_whitespace_flags.push("-fminimize-whitespace".to_string());
132133
}
133134

src/compiler/compiler.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ pub enum CompilerKind {
214214

215215
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
216216
pub enum Language {
217+
AssemblerToPreprocess,
218+
Assembler,
217219
C,
218220
Cxx,
219221
GenericHeader,
@@ -238,6 +240,8 @@ impl Language {
238240
pub fn from_file_name(file: &Path) -> Option<Self> {
239241
match file.extension().and_then(|e| e.to_str()) {
240242
// gcc: https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html
243+
Some("s") => Some(Language::Assembler),
244+
Some("S") | Some("sx") => Some(Language::AssemblerToPreprocess),
241245
Some("c") => Some(Language::C),
242246
// Could be C or C++
243247
Some("h") => Some(Language::GenericHeader),
@@ -266,6 +270,8 @@ impl Language {
266270

267271
pub fn as_str(self) -> &'static str {
268272
match self {
273+
Language::AssemblerToPreprocess => "assemblerToPreprocess",
274+
Language::Assembler => "assembler",
269275
Language::C => "c",
270276
Language::CHeader => "cHeader",
271277
Language::CPreprocessed => "cPreprocessed",
@@ -289,7 +295,8 @@ impl Language {
289295
pub fn needs_c_preprocessing(self) -> bool {
290296
!matches!(
291297
self,
292-
Language::CPreprocessed
298+
Language::Assembler
299+
| Language::CPreprocessed
293300
| Language::CxxPreprocessed
294301
| Language::ObjectiveCPreprocessed
295302
| Language::ObjectiveCxxPreprocessed
@@ -300,6 +307,8 @@ impl Language {
300307
/// Common implementation for GCC and Clang language argument mapping
301308
fn to_compiler_arg(self, cuda_arg: &'static str) -> Option<&'static str> {
302309
match self {
310+
Language::AssemblerToPreprocess => Some("assembler-with-cpp"),
311+
Language::Assembler => Some("assembler"),
303312
Language::C => Some("c"),
304313
Language::CHeader => Some("c-header"),
305314
Language::CPreprocessed => Some("cpp-output"),
@@ -337,6 +346,7 @@ impl Language {
337346
impl CompilerKind {
338347
pub fn lang_kind(&self, lang: &Language) -> String {
339348
match lang {
349+
Language::AssemblerToPreprocess | Language::Assembler => "Assembler",
340350
Language::C
341351
| Language::CHeader
342352
| Language::CPreprocessed

src/compiler/gcc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ where
404404
| Some(Unhashed(_)) => {}
405405
Some(Language(lang)) => {
406406
language = match lang.to_string_lossy().as_ref() {
407+
"assembler" => Some(Language::Assembler),
408+
"assembler-with-cpp" => Some(Language::AssemblerToPreprocess),
407409
"c" => Some(Language::C),
408410
"c-header" => Some(Language::CHeader),
409411
"c++" => Some(Language::Cxx),

tests/test_intel_asm.s

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.data
2+
3+
hello_str:
4+
.string "Hello, world!\n"
5+
6+
7+
.set hello_str_length, . - hello_str - 1
8+
9+
.text
10+
11+
.globl main
12+
13+
.type main, @function
14+
15+
16+
main:
17+
movl $4, %eax
18+
19+
movl $1, %ebx
20+
21+
movl $hello_str, %ecx
22+
23+
movl $hello_str_length, %edx
24+
25+
int $0x80
26+
27+
movl $1, %eax
28+
movl $0, %ebx
29+
int $0x80
30+
31+
.size main, . - main

tests/test_intel_asm_to_preproc.S

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.data
2+
3+
hello_str:
4+
.string "Hello, world!\n"
5+
6+
7+
.set hello_str_length, . - hello_str - 1
8+
9+
.text
10+
11+
.globl main
12+
13+
.type main, @function
14+
15+
16+
main:
17+
movl $4, %eax
18+
19+
movl $1, %ebx
20+
21+
movl $hello_str, %ecx
22+
23+
movl $hello_str_length, %edx
24+
25+
int $0x80
26+
27+
movl $1, %eax
28+
movl $0, %ebx
29+
int $0x80
30+
31+
.size main, . - main

0 commit comments

Comments
 (0)