[PATCH] D34764: Introduce FileEdit utility

Chandler Carruth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 28 11:29:33 PDT 2017


chandlerc added a comment.

In https://reviews.llvm.org/D34764#794086, @rnk wrote:

> @chandlerc I think we have use cases for file splitting in the linker. Many interesting test cases require two object files, and it's annoying to have to make a separate file in %S/Inputs just for this. Consider lld/test/COFF/reloc-discarded.s. I recently added this and I need to make a COFF object that defines a global in a comdat. This is the RUN: line I used to do that:
>
>   # RUN: echo -e '.section .bss,"bw",discard,main_global\n.global main_global\n main_global:\n .long 0' | \
>   # RUN:     llvm-mc - -filetype=obj -o %t1.obj -triple x86_64-windows-msvc
>
>
> That's pretty unreadable.


FWIW, I agree this is awful.

I'm not as fussed as you seem to be about having separate files... but OK.

> I would much rather write:
> 
>   # RUN: FileEdit %s %t
>   # RUN: llvm-mc %t/a.s -o %t/a.obj -filetype=obj -triple x86_64-windows-msvc
>   # RUN: llvm-mc %t/b.s -o %t/b.obj -filetype=obj -triple x86_64-windows-msvc
>   # RUN: lld-link %t/a.obj %t/b.obj -entry ...
>   
>   # SPLIT: a.s
>   .section .bss,"bw",discard,main_global
>   .globl main_global
>   main_global:
>       .long 0
>   
>   # SPLIT: b.s
>   .section .bss,"bw",discard,main_global
>   .globl main_global
>   main_global:
>       .long 0
>   ...
> 
> 
> Editors would enable assembly syntax highlighting, even. You can apply the same technique to Clang tests that need headers.

I just don't think we need a new syntax or tool here.

We can run the preprocessor to create a header file, and then include it. We can use the preprocessor to have a single source file and compile it in N different ways.

We could even use preprocessed assembly to solve the issue you cite in the `lld` test suite. I'd honestly rather continue using the *existing* file manipulation syntaxes rather than adding yet another magic comment that actually does semantic splitting.


https://reviews.llvm.org/D34764





More information about the llvm-commits mailing list