Browse Source

Correctly identify PROC and ENDP even when a comment is on the same line. Fixes #235

dev/git-series/gccdum
Matt Godbolt 6 years ago
parent
commit
65b5bf49c4
  1. 8
      lib/asm-cl.js
  2. 90
      test/cases/cl-main-opt-out.asm
  3. 94
      test/cases/cl-main-opt-out.directives.labels.comments.json
  4. 2
      test/filter-tests.js

8
lib/asm-cl.js

@ -34,12 +34,12 @@ var gccExplorerDir = /\\compiler-explorer-compiler/; // has to match part of the
// * optional leading whitespace
// * middle part
// * comment part
var parseRe = /^(\s*)([^;]*)(;.*)*$/;
var isProc = /.*PROC$/;
var isEndp = /.*ENDP$/;
var parseRe = /^(\s*)([^;]*)(;.*)?$/;
var isProc = /.*PROC\s*$/;
var isEndp = /.*ENDP\s*$/;
var constDef = /^([a-zA-Z_$@][a-zA-Z_$@0-9.]*)\s*=.*$/;
var labelFind = /[.a-zA-Z_@$][a-zA-Z_$@0-9.]*/g;
var labelDef = /^(.*):$/;
var labelDef = /^(.*):\s*$/;
// Anything identifier-looking with a "@@" in the middle, and a comment at the end
// is treated as a mangled name. The comment will be used to replace the identifier.
var mangledIdentifier = /\?[^ ]+@@[^ |]+/;

90
test/cases/cl-main-opt-out.asm

@ -0,0 +1,90 @@
; Listing generated by Microsoft (R) Optimizing Compiler Version 19.00.24224.0
include listing.inc
INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES
PUBLIC main
PUBLIC ??$make_array@$00$02$04$01$02$04$05$03$07$08$01@@YA?AV?$array@H$0L@@std@@XZ ; make_array<1,3,5,2,3,5,6,4,8,9,2>
PUBLIC ??A?$array@H$0L@@std@@QEBAAEBH_K@Z ; std::array<int,11>::operator[]
; Function compile flags: /Ogtpy
; File z:\home\mgodbolt\apps\windows\14.0.24224-pre\lib\native\include\array
; COMDAT ??A?$array@H$0L@@std@@QEBAAEBH_K@Z
_TEXT SEGMENT
this$ = 8
_Pos$ = 16
??A?$array@H$0L@@std@@QEBAAEBH_K@Z PROC ; std::array<int,11>::operator[], COMDAT
; 167 : #if _ITERATOR_DEBUG_LEVEL == 0
; 168 : return (_Elems[_Pos]);
00000 48 8d 04 91 lea rax, QWORD PTR [rcx+rdx*4]
; 169 :
; 170 : #else /* _ITERATOR_DEBUG_LEVEL == 0 */
; 171 : return (_Size <= _Pos
; 172 : ? (_Bad_subscript(), _Elems[_Pos])
; 173 : : _Elems[_Pos]);
; 174 : #endif /* _ITERATOR_DEBUG_LEVEL == 0 */
; 175 : }
00004 c3 ret 0
??A?$array@H$0L@@std@@QEBAAEBH_K@Z ENDP ; std::array<int,11>::operator[]
_TEXT ENDS
; Function compile flags: /Ogtpy
; File z:\tmp\example.cpp
; COMDAT ??$make_array@$00$02$04$01$02$04$05$03$07$08$01@@YA?AV?$array@H$0L@@std@@XZ
_TEXT SEGMENT
$T1 = 8
??$make_array@$00$02$04$01$02$04$05$03$07$08$01@@YA?AV?$array@H$0L@@std@@XZ PROC ; make_array<1,3,5,2,3,5,6,4,8,9,2>, COMDAT
; 6 : return std::array<int, sizeof...(vars)>{vars...};
00000 c7 01 01 00 00
00 mov DWORD PTR [rcx], 1
00006 48 8b c1 mov rax, rcx
00009 c7 41 04 03 00
00 00 mov DWORD PTR [rcx+4], 3
00010 c7 41 08 05 00
00 00 mov DWORD PTR [rcx+8], 5
00017 c7 41 0c 02 00
00 00 mov DWORD PTR [rcx+12], 2
0001e c7 41 10 03 00
00 00 mov DWORD PTR [rcx+16], 3
00025 c7 41 14 05 00
00 00 mov DWORD PTR [rcx+20], 5
0002c c7 41 18 06 00
00 00 mov DWORD PTR [rcx+24], 6
00033 c7 41 1c 04 00
00 00 mov DWORD PTR [rcx+28], 4
0003a c7 41 20 08 00
00 00 mov DWORD PTR [rcx+32], 8
00041 c7 41 24 09 00
00 00 mov DWORD PTR [rcx+36], 9
00048 c7 41 28 02 00
00 00 mov DWORD PTR [rcx+40], 2
; 7 : }
0004f c3 ret 0
??$make_array@$00$02$04$01$02$04$05$03$07$08$01@@YA?AV?$array@H$0L@@std@@XZ ENDP ; make_array<1,3,5,2,3,5,6,4,8,9,2>
_TEXT ENDS
; Function compile flags: /Ogtpy
; File z:\tmp\example.cpp
; COMDAT main
_TEXT SEGMENT
main PROC ; COMDAT
; 11 : constexpr auto a = make_array<1,3,5,2,3,5,6,4,8,9,2>();
; 12 :
; 13 : return a[2];
00000 b8 05 00 00 00 mov eax, 5
; 14 : }
00005 c3 ret 0
main ENDP
_TEXT ENDS
END

94
test/cases/cl-main-opt-out.directives.labels.comments.json

@ -0,0 +1,94 @@
[
{
"source": null,
"text": "std::array<int,11>::operator[], COMDAT PROC"
},
{
"source": null,
"text": " lea rax, QWORD PTR [rcx+rdx*4]"
},
{
"source": null,
"text": " ret 0"
},
{
"source": null,
"text": "std::array<int,11>::operator[] ENDP"
},
{
"source": null,
"text": "make_array<1,3,5,2,3,5,6,4,8,9,2>, COMDAT PROC"
},
{
"source": null,
"text": " mov DWORD PTR [rcx], 1"
},
{
"source": null,
"text": " mov rax, rcx"
},
{
"source": null,
"text": " mov DWORD PTR [rcx+4], 3"
},
{
"source": null,
"text": " mov DWORD PTR [rcx+8], 5"
},
{
"source": null,
"text": " mov DWORD PTR [rcx+12], 2"
},
{
"source": null,
"text": " mov DWORD PTR [rcx+16], 3"
},
{
"source": null,
"text": " mov DWORD PTR [rcx+20], 5"
},
{
"source": null,
"text": " mov DWORD PTR [rcx+24], 6"
},
{
"source": null,
"text": " mov DWORD PTR [rcx+28], 4"
},
{
"source": null,
"text": " mov DWORD PTR [rcx+32], 8"
},
{
"source": null,
"text": " mov DWORD PTR [rcx+36], 9"
},
{
"source": null,
"text": " mov DWORD PTR [rcx+40], 2"
},
{
"source": null,
"text": " ret 0"
},
{
"source": null,
"text": "make_array<1,3,5,2,3,5,6,4,8,9,2> ENDP"
},
{
"source": null,
"text": "main PROC; COMDAT"
},
{
"source": null,
"text": " mov eax, 5"
},
{
"source": null,
"text": " ret 0"
},
{
"source": null,
"text": "main ENDP"
}
]

2
test/filter-tests.js

@ -98,6 +98,7 @@ function testFilter(filename, suffix, filters) {
// bless("cases/cl-regex.asm", "cases/cl-regex.asm.dlcb.json", {directives: true, labels: true, commentOnly: true, binary:true});
// bless("cases/cl-maxarray.asm", "cases/cl-maxarray.asm.dlcb.json", {directives: true, labels: true, commentOnly: true, binary:true});
// bless("cases/cl64-sum.asm", "cases/cl64-sum.asm.dlcb.json", {directives: true, labels: true, commentOnly: true, binary:true});
// bless("cases/cl-main-opt-out.asm", "cases/cl-main-opt-out.directives.labels.comments.json", {directives: true, labels: true, commentOnly: true});
// bless("cases/avr-loop.asm", "cases/avr-loop.asm.directives.labels.comments.json", {directives: true, labels: true, commentOnly: true});
// bless("cases/bug-192.asm", "cases/bug-192.asm.directives.labels.comments.json", {directives: true, labels: true, commentOnly: true});
// bless("cases/arm-moose.asm", "cases/arm-moose.asm.directives.labels.comments.json", {directives: true, labels: true, commentOnly: true});
@ -133,3 +134,4 @@ describe('Filter test cases', function () {
});
});
});

Loading…
Cancel
Save