mswasm -- Merge Source with ASM

This Perl script merges the source code in a .s file generate by the compilation of a file with the following command:

[you@yourmachine ~]% gcc -g -S foo.c

Compilation with -g -S produce a file with the following notation:

foo:
.LFB2:
 .file 1 "foo.c"
 .loc 1 4 0
 stwu 1,-16(1)
.LCFI0:
 stw 31,12(1)
.LCFI1:
 mr 31,1
.LCFI2:
 .loc 1 5 0
 li 0,42
 .loc 1 6 0
 mr 3,0
 lwz 11,0(1)
 lwz 31,-4(11)
 mr 1,11
 blr

The .loc 1 5 0 statement as the following meaning: "following lines are generated by file number 1 at line 5". The file which number is 1 is set with the statement .file 1 "foo.c"

mswasm acts as follow: it takes on standard input an assembly file generated with gcc -g -S and writes on standard output the assembly file with comments in place of .loc statements. In these comments mswasm puts the code from source file.

[you@yourmachine ~]% mswasm < foo.s >foo_out.s

The output for the previous assembly code is:

foo:
.LFB2:
 .file 1 "foo.c"

 /* foo.c 3-4 */
 /* int foo()
	 * {
	 */
 stwu 1,-16(1)
.LCFI0:
 stw 31,12(1)
.LCFI1:
 mr 31,1
.LCFI2:

 /* foo.c 5 */
 /* return 42; */
 li 0,42

 /* foo.c 6 */
 /* } */
 mr 3,0
 lwz 11,0(1)
 lwz 31,-4(11)
 mr 1,11
 blr


Download mswasm .