Send opcodes as strings. Fix up ARM opcode and label handling

dev/git-series/gccdum
Matt Godbolt 7 years ago
parent 3e405c0a9f
commit 0362e0cbae

@ -42,9 +42,9 @@ var labelFind = /[.a-zA-Z_@$][a-zA-Z_$@0-9.]*/g;
var labelDef = /^(.*):$/;
// 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 = /\?[^ ]+@@[^ ]+/;
var mangledIdentifier = /\?[^ ]+@@[^ |]+/;
var commentedLine = /([^;]+);\s*(.*)/;
var numberRe = /^\s+(([0-9a-f]+\b\s*)([0-9a-f][0-9a-f]\b\s*)*)(.*)/;
var numberRe = /^\s+(([0-9a-f]+\b\s*)(([0-9a-f][0-9a-f])+\b\s*)*)(.*)/;
function debug() {
logger.debug.apply(logger, arguments);
@ -74,17 +74,17 @@ function AddrOpcoder() {
prevOffset = -1;
return line;
}
var restOfLine = match[4];
var numbers = match[1].split(/\s+/).filter(function (x) {
return x;
}).map(function (x) {
return parseInt(x, 16);
});
var restOfLine = match[5];
var numbers = _.chain(match[1].split(/\s+/))
.filter(function (x) {
return x !== "";
})
.value();
// If restOfLine is empty, we should accumulate offset opcodes...
if (restOfLine === "") {
if (prevOffset < 0) {
// First in a batch of opcodes, so first is the offset
prevOffset = numbers[0];
prevOffset = parseInt(numbers[0], 16);
prevOpcodes = numbers.splice(1);
} else {
prevOpcodes = prevOpcodes.concat(numbers);
@ -96,7 +96,7 @@ function AddrOpcoder() {
self.opcodes = prevOpcodes.concat(numbers);
prevOffset = -1;
} else {
self.offset = numbers[0];
self.offset = parseInt(numbers[0], 16);
self.opcodes = numbers.splice(1);
}
}
@ -116,7 +116,7 @@ function ClParser(filters) {
}
ClParser.prototype._add = function (obj) {
if (obj.text === "" ) return;
if (obj.text === "") return;
if (this.currentLabel) obj.label = this.currentLabel;
obj.text = expandTabs(obj.text);
if (this.filters.binary && this.opcoder.hasOpcodes()) {

@ -238,8 +238,6 @@
var address = parseInt(match[1], 16);
var opcodes = match[2].split(" ").filter(function (x) {
return x;
}).map(function (x) {
return parseInt(x, 16);
});
var disassembly = " " + match[4];
var links = null;

@ -225,15 +225,10 @@ define(function (require) {
_.each(this.assembly, _.bind(function (obj, line) {
var opcodes = $("<div class='opcodes'></div>");
if (obj.opcodes) {
var title = [];
_.each(obj.opcodes, function (op) {
var opcodeNum = "00" + op.toString(16);
opcodeNum = opcodeNum.substr(opcodeNum.length - 2);
title.push(opcodeNum);
var opcode = $("<span class='opcode'>" + opcodeNum + "</span>");
opcodes.append(opcode);
opcodes.append($("<span class='opcode'>" + op + "</span>"));
});
opcodes.attr('title', title.join(" "));
opcodes.attr('title', obj.opcodes.join(" "));
}
this.outputEditor.setGutterMarker(line, 'opcodes', opcodes[0]);
if (obj.links) {

@ -0,0 +1,95 @@
; Listing generated by Microsoft (R) Optimizing Compiler Version 19.00.24224.0
TTL Z:\tmp\example.cpp
THUMB
.drectve
DCB "-defaultlib:LIBCMT "
DCB "-defaultlib:OLDNAMES "
EXPORT |?moose@@YAHHH@Z| ; moose
.pdata
|$pdata1$?moose@@YAHHH@Z| DCD imagerel |?moose@@YAHHH@Z|
DCD 0xfd1160d5
; Function compile flags: /Ogtpy
; File z:\tmp\example.cpp
.text$mn
00000 |?moose@@YAHHH@Z| PROC ; moose
; 3 : int moose(int x, int y) {
00000 b538 push {r3-r5,lr}
00002 |$M22|
00002 4605 mov r5,r0
; 4 : int foo = 1;
00004 2001 movs r0,#1
; 5 : for (int i = 0; i < y; ++i)
00006 2400 movs r4,#0
00008 eea4 5b90 vdup.32 q10,r5
0000c 2900 cmp r1,#0
0000e dd2b ble |$LN18@moose|
00010 2908 cmp r1,#8
00012 d321 bcc |$LN11@moose|
00014 108b asrs r3,r1,#2
00016 eb01 7353 add r3,r1,r3,lsr #0x1D
0001a 10db asrs r3,r3,#3
0001c eba1 03c3 sub r3,r1,r3,lsl #3
00020 efc0 0e70 vmov.i64 q8,#0
00024 1acb subs r3,r1,r3
00026 ef60 21f0 vmov q9,q8
0002a ef64 49f4 vmul.i32 q10,q10,q10
0002e |$LL4@moose|
0002e 3408 adds r4,r4,#8
00030 429c cmp r4,r3
00032 ef64 08e0 vadd.i32 q8,q10,q8
00036 ef64 28e2 vadd.i32 q9,q10,q9
0003a dbf8 blt |$LL4@moose|
0003c ef62 08e0 vadd.i32 q8,q9,q8
00040 ee31 2b90 vmov.32 r2,d17[1]
00044 ee11 3b90 vmov.32 r3,d17[0]
00048 441a add r2,r2,r3
0004a ee30 3b90 vmov.32 r3,d16[1]
0004e 441a add r2,r2,r3
00050 ee10 3b90 vmov.32 r3,d16[0]
00054 4413 add r3,r3,r2
00056 1c58 adds r0,r3,#1
00058 |$LN11@moose|
00058 428c cmp r4,r1
0005a da04 bge |$LN17@moose|
0005c 1b0b subs r3,r1,r4
0005e fb03 f305 mul r3,r3,r5
00062 fb03 0005 mla r0,r3,r5,r0
00066 |$LN17@moose|
00066 |$M20|
; 6 : foo += thing(x);
; 7 : return foo;
; 8 : }
00066 bd38 pop {r3-r5,pc}
00068 |$LN18@moose|
00068 |$M21|
00068 bd38 pop {r3-r5,pc}
0006a |$M23|
ENDP ; |?moose@@YAHHH@Z|, moose
; Function compile flags: /Ogtpy
; File z:\tmp\example.cpp
.text$mn
00000 |?thing@@YAHH@Z| PROC ; thing
; 1 : static int thing(int a) { return a * a; }
00000 fb00 f000 mul r0,r0,r0
00004 |$M4|
00004 4770 bx lr
ENDP ; |?thing@@YAHH@Z|, thing
END

@ -0,0 +1,214 @@
[
{
"source": null,
"text": " |moose| PROC"
},
{
"source": null,
"text": " push {r3-r5,lr}"
},
{
"source": null,
"text": " |$M22|"
},
{
"source": null,
"text": " mov r5,r0"
},
{
"source": null,
"text": " movs r0,#1"
},
{
"source": null,
"text": " movs r4,#0"
},
{
"source": null,
"text": " vdup.32 q10,r5"
},
{
"source": null,
"text": " cmp r1,#0"
},
{
"source": null,
"text": " ble |$LN18@moose|"
},
{
"source": null,
"text": " cmp r1,#8"
},
{
"source": null,
"text": " bcc |$LN11@moose|"
},
{
"source": null,
"text": " asrs r3,r1,#2"
},
{
"source": null,
"text": " add r3,r1,r3,lsr #0x1D"
},
{
"source": null,
"text": " asrs r3,r3,#3"
},
{
"source": null,
"text": " sub r3,r1,r3,lsl #3"
},
{
"source": null,
"text": " vmov.i64 q8,#0"
},
{
"source": null,
"text": " subs r3,r1,r3"
},
{
"source": null,
"text": " vmov q9,q8"
},
{
"source": null,
"text": " vmul.i32 q10,q10,q10"
},
{
"source": null,
"text": " |$LL4@moose|"
},
{
"source": null,
"text": " adds r4,r4,#8"
},
{
"source": null,
"text": " cmp r4,r3"
},
{
"source": null,
"text": " vadd.i32 q8,q10,q8"
},
{
"source": null,
"text": " vadd.i32 q9,q10,q9"
},
{
"source": null,
"text": " blt |$LL4@moose|"
},
{
"source": null,
"text": " vadd.i32 q8,q9,q8"
},
{
"source": null,
"text": " vmov.32 r2,d17[1]"
},
{
"source": null,
"text": " vmov.32 r3,d17[0]"
},
{
"source": null,
"text": " add r2,r2,r3"
},
{
"source": null,
"text": " vmov.32 r3,d16[1]"
},
{
"source": null,
"text": " add r2,r2,r3"
},
{
"source": null,
"text": " vmov.32 r3,d16[0]"
},
{
"source": null,
"text": " add r3,r3,r2"
},
{
"source": null,
"text": " adds r0,r3,#1"
},
{
"source": null,
"text": " |$LN11@moose|"
},
{
"source": null,
"text": " cmp r4,r1"
},
{
"source": null,
"text": " bge |$LN17@moose|"
},
{
"source": null,
"text": " subs r3,r1,r4"
},
{
"source": null,
"text": " mul r3,r3,r5"
},
{
"source": null,
"text": " mla r0,r3,r5,r0"
},
{
"source": null,
"text": " |$LN17@moose|"
},
{
"source": null,
"text": " |$M20|"
},
{
"source": null,
"text": " pop {r3-r5,pc}"
},
{
"source": null,
"text": " |$LN18@moose|"
},
{
"source": null,
"text": " |$M21|"
},
{
"source": null,
"text": " pop {r3-r5,pc}"
},
{
"source": null,
"text": " |$M23|"
},
{
"source": null,
"text": "ENDP"
},
{
"source": null,
"text": " |thing| PROC"
},
{
"source": null,
"text": " mul r0,r0,r0"
},
{
"source": null,
"text": " |$M4|"
},
{
"source": null,
"text": " bx lr"
},
{
"source": null,
"text": "ENDP"
}
]

@ -0,0 +1,412 @@
[
{
"opcodes": [],
"address": 0,
"source": null,
"text": " |moose| PROC"
},
{
"opcodes": [
"b538"
],
"address": 0,
"source": null,
"text": " push {r3-r5,lr}"
},
{
"opcodes": [],
"address": 2,
"source": null,
"text": " |$M22|"
},
{
"opcodes": [
"4605"
],
"address": 2,
"source": null,
"text": " mov r5,r0"
},
{
"opcodes": [
"2001"
],
"address": 4,
"source": null,
"text": " movs r0,#1"
},
{
"opcodes": [
"2400"
],
"address": 6,
"source": null,
"text": " movs r4,#0"
},
{
"opcodes": [
"eea4",
"5b90"
],
"address": 8,
"source": null,
"text": " vdup.32 q10,r5"
},
{
"opcodes": [
"2900"
],
"address": 12,
"source": null,
"text": " cmp r1,#0"
},
{
"opcodes": [
"dd2b"
],
"address": 14,
"source": null,
"text": " ble |$LN18@moose|"
},
{
"opcodes": [
"2908"
],
"address": 16,
"source": null,
"text": " cmp r1,#8"
},
{
"opcodes": [
"d321"
],
"address": 18,
"source": null,
"text": " bcc |$LN11@moose|"
},
{
"opcodes": [
"108b"
],
"address": 20,
"source": null,
"text": " asrs r3,r1,#2"
},
{
"opcodes": [
"eb01",
"7353"
],
"address": 22,
"source": null,
"text": " add r3,r1,r3,lsr #0x1D"
},
{
"opcodes": [
"10db"
],
"address": 26,
"source": null,
"text": " asrs r3,r3,#3"
},
{
"opcodes": [
"eba1",
"03c3"
],
"address": 28,
"source": null,
"text": " sub r3,r1,r3,lsl #3"
},
{
"opcodes": [
"efc0",
"0e70"
],
"address": 32,
"source": null,
"text": " vmov.i64 q8,#0"
},
{
"opcodes": [
"1acb"
],
"address": 36,
"source": null,
"text": " subs r3,r1,r3"
},
{
"opcodes": [
"ef60",
"21f0"
],
"address": 38,
"source": null,
"text": " vmov q9,q8"
},
{
"opcodes": [
"ef64",
"49f4"
],
"address": 42,
"source": null,
"text": " vmul.i32 q10,q10,q10"
},
{
"opcodes": [],
"address": 46,
"source": null,
"text": " |$LL4@moose|"
},
{
"opcodes": [
"3408"
],
"address": 46,
"source": null,
"text": " adds r4,r4,#8"
},
{
"opcodes": [
"429c"
],
"address": 48,
"source": null,
"text": " cmp r4,r3"
},
{
"opcodes": [
"ef64",
"08e0"
],
"address": 50,
"source": null,
"text": " vadd.i32 q8,q10,q8"
},
{
"opcodes": [
"ef64",
"28e2"
],
"address": 54,
"source": null,
"text": " vadd.i32 q9,q10,q9"
},
{
"opcodes": [
"dbf8"
],
"address": 58,
"source": null,
"text": " blt |$LL4@moose|"
},
{
"opcodes": [
"ef62",
"08e0"
],
"address": 60,
"source": null,
"text": " vadd.i32 q8,q9,q8"
},
{
"opcodes": [
"ee31",
"2b90"
],
"address": 64,
"source": null,
"text": " vmov.32 r2,d17[1]"
},
{
"opcodes": [
"ee11",
"3b90"
],
"address": 68,
"source": null,
"text": " vmov.32 r3,d17[0]"
},
{
"opcodes": [
"441a"
],
"address": 72,
"source": null,
"text": " add r2,r2,r3"
},
{
"opcodes": [
"ee30",
"3b90"
],
"address": 74,
"source": null,
"text": " vmov.32 r3,d16[1]"
},
{
"opcodes": [
"441a"
],
"address": 78,
"source": null,
"text": " add r2,r2,r3"
},
{
"opcodes": [
"ee10",
"3b90"
],
"address": 80,
"source": null,
"text": " vmov.32 r3,d16[0]"
},
{
"opcodes": [
"4413"
],
"address": 84,
"source": null,
"text": " add r3,r3,r2"
},
{
"opcodes": [
"1c58"
],
"address": 86,
"source": null,
"text": " adds r0,r3,#1"
},
{
"opcodes": [],
"address": 88,
"source": null,
"text": " |$LN11@moose|"
},
{
"opcodes": [
"428c"
],
"address": 88,
"source": null,
"text": " cmp r4,r1"
},
{
"opcodes": [
"da04"
],
"address": 90,
"source": null,
"text": " bge |$LN17@moose|"
},
{
"opcodes": [
"1b0b"
],
"address": 92,
"source": null,
"text": " subs r3,r1,r4"
},
{
"opcodes": [
"fb03",
"f305"
],
"address": 94,
"source": null,
"text": " mul r3,r3,r5"
},
{
"opcodes": [
"fb03",
"0005"
],
"address": 98,
"source": null,
"text": " mla r0,r3,r5,r0"
},
{
"opcodes": [],
"address": 102,
"source": null,
"text": " |$LN17@moose|"
},
{
"opcodes": [],
"address": 102,
"source": null,
"text": " |$M20|"
},
{
"opcodes": [
"bd38"
],
"address": 102,
"source": null,
"text": " pop {r3-r5,pc}"
},
{
"opcodes": [],
"address": 104,
"source": null,
"text": " |$LN18@moose|"
},
{
"opcodes": [],
"address": 104,
"source": null,
"text": " |$M21|"
},
{
"opcodes": [
"bd38"
],
"address": 104,
"source": null,
"text": " pop {r3-r5,pc}"
},
{
"opcodes": [],
"address": 106,
"source": null,
"text": " |$M23|"
},
{
"source": null,
"text": "ENDP"
},
{
"opcodes": [],
"address": 0,
"source": null,
"text": " |thing| PROC"
},
{
"opcodes": [
"fb00",
"f000"
],
"address": 0,
"source": null,
"text": " mul r0,r0,r0"
},
{
"opcodes": [],
"address": 4,
"source": null,
"text": " |$M4|"
},
{
"opcodes": [
"4770"
],
"address": 4,
"source": null,
"text": " bx lr"
},
{
"source": null,
"text": "ENDP"
}
]

@ -5,10 +5,10 @@
},
{
"opcodes": [
72,
141,
65,
8
"48",
"8d",
"41",
"08"
],
"address": 0,
"source": 2,
@ -16,9 +16,9 @@
},
{
"opcodes": [
72,
43,
209
"48",
"2b",
"d1"
],
"address": 4,
"source": 2,
@ -26,11 +26,11 @@
},
{
"opcodes": [
185,
0,
64,
0,
0
"b9",
"00",
"40",
"00",
"00"
],
"address": 7,
"source": 2,
@ -38,10 +38,10 @@
},
{
"opcodes": [
15,
31,
64,
0
"0f",
"1f",
"40",
"00"
],
"address": 12,
"source": 2,
@ -53,12 +53,12 @@
},
{
"opcodes": [
242,
15,
16,
68,
2,
248
"f2",
"0f",
"10",
"44",
"02",
"f8"
],
"address": 16,
"source": 3,
@ -66,11 +66,11 @@
},
{
"opcodes": [
102,
15,
47,
64,
248
"66",
"0f",
"2f",
"40",
"f8"
],
"address": 22,
"source": 3,
@ -78,8 +78,8 @@
},
{
"opcodes": [
118,
5
"76",
"05"
],
"address": 27,
"source": 3,
@ -87,11 +87,11 @@
},
{
"opcodes": [
242,
15,
17,
64,
248
"f2",
"0f",
"11",
"40",
"f8"
],
"address": 29,
"source": 3,
@ -103,11 +103,11 @@
},
{
"opcodes": [
242,
15,
16,
4,
2
"f2",
"0f",
"10",
"04",
"02"
],
"address": 34,
"source": 3,
@ -115,10 +115,10 @@
},
{
"opcodes": [
102,
15,
47,
0
"66",
"0f",
"2f",
"00"
],
"address": 39,
"source": 3,
@ -126,8 +126,8 @@
},
{
"opcodes": [
118,
4
"76",
"04"
],
"address": 43,
"source": 3,
@ -135,10 +135,10 @@
},
{
"opcodes": [
242,
15,
17,
0
"f2",
"0f",
"11",
"00"
],
"address": 45,
"source": 3,
@ -150,12 +150,12 @@
},
{
"opcodes": [
242,
15,
16,
68,
2,
8
"f2",
"0f",
"10",
"44",
"02",
"08"
],
"address": 49,
"source": 3,
@ -163,11 +163,11 @@
},
{
"opcodes": [
102,
15,
47,
64,
8
"66",
"0f",
"2f",
"40",
"08"
],
"address": 55,
"source": 3,
@ -175,8 +175,8 @@
},
{
"opcodes": [
118,
5
"76",
"05"
],
"address": 60,
"source": 3,
@ -184,11 +184,11 @@
},
{
"opcodes": [
242,
15,
17,
64,
8
"f2",
"0f",
"11",
"40",
"08"
],
"address": 62,
"source": 3,
@ -200,12 +200,12 @@
},
{
"opcodes": [
242,
15,
16,
68,
2,
16
"f2",
"0f",
"10",
"44",
"02",
"10"
],
"address": 67,
"source": 3,
@ -213,11 +213,11 @@
},
{
"opcodes": [
102,
15,
47,
64,
16
"66",
"0f",
"2f",
"40",
"10"
],
"address": 73,
"source": 3,
@ -225,8 +225,8 @@
},
{
"opcodes": [
118,
5
"76",
"05"
],
"address": 78,
"source": 3,
@ -234,11 +234,11 @@
},
{
"opcodes": [
242,
15,
17,
64,
16
"f2",
"0f",
"11",
"40",
"10"
],
"address": 80,
"source": 3,
@ -250,10 +250,10 @@
},
{
"opcodes": [
72,
131,
192,
32
"48",
"83",
"c0",
"20"
],
"address": 85,
"source": 3,
@ -261,10 +261,10 @@
},
{
"opcodes": [
72,
131,
233,
1
"48",
"83",
"e9",
"01"
],
"address": 89,
"source": 2,
@ -272,8 +272,8 @@
},
{
"opcodes": [
117,
177
"75",
"b1"
],
"address": 93,
"source": 2,
@ -281,7 +281,7 @@
},
{
"opcodes": [
195
"c3"
],
"address": 95,
"source": 4,

@ -17,10 +17,10 @@
},
{
"opcodes": [
72,
131,
236,
120
"48",
"83",
"ec",
"78"
],
"address": 0,
"source": 5,
@ -28,13 +28,13 @@
},
{
"opcodes": [
72,
139,
5,
0,
0,
0,
0
"48",
"8b",
"05",
"00",
"00",
"00",
"00"
],
"address": 4,
"source": 5,
@ -42,9 +42,9 @@
},
{
"opcodes": [
72,
51,
196
"48",
"33",
"c4"
],
"address": 11,
"source": 5,
@ -52,11 +52,11 @@
},
{
"opcodes": [
72,
137,
68,
36,
104
"48",
"89",
"44",
"24",
"68"
],
"address": 14,
"source": 5,
@ -64,13 +64,13 @@
},
{
"opcodes": [
72,
141,
21,
0,
0,
0,
0
"48",
"8d",
"15",
"00",
"00",
"00",
"00"
],
"address": 19,
"source": 6,
@ -78,11 +78,11 @@
},
{
"opcodes": [
72,
141,
76,
36,
72
"48",
"8d",
"4c",
"24",
"48"
],
"address": 26,
"source": 6,
@ -90,11 +90,11 @@
},
{
"opcodes": [
232,
0,
0,
0,
0
"e8",
"00",
"00",
"00",
"00"
],
"address": 31,
"source": 6,
@ -102,11 +102,11 @@
},
{
"opcodes": [
186,
0,
1,
0,
0
"ba",
"00",
"01",
"00",
"00"
],
"address": 36,
"source": 9,
@ -114,11 +114,11 @@
},
{
"opcodes": [
185,
1,
0,
0,
0
"b9",
"01",
"00",
"00",
"00"
],
"address": 41,
"source": 9,
@ -126,11 +126,11 @@
},
{
"opcodes": [
232,
0,
0,
0,
0
"e8",
"00",
"00",
"00",
"00"
],
"address": 46,
"source": 9,
@ -138,9 +138,9 @@
},
{
"opcodes": [
68,
139,
192
"44",
"8b",
"c0"
],
"address": 51,
"source": 9,
@ -148,13 +148,13 @@
},
{
"opcodes": [
72,
141,
21,
0,
0,
0,
0
"48",
"8d",
"15",
"00",
"00",
"00",
"00"
],
"address": 54,
"source": 9,
@ -162,11 +162,11 @@
},
{
"opcodes": [
72,
141,
76,
36,
32
"48",
"8d",
"4c",
"24",
"20"
],
"address": 61,
"source": 9,
@ -174,11 +174,11 @@
},
{
"opcodes": [
232,
0,
0,
0,
0
"e8",
"00",
"00",
"00",
"00"
],
"address": 66,
"source": 9,
@ -186,11 +186,11 @@
},
{
"opcodes": [
72,
141,
76,
36,
32
"48",
"8d",
"4c",
"24",
"20"
],
"address": 71,
"source": 11,
@ -198,11 +198,11 @@
},
{
"opcodes": [
232,
0,
0,
0,
0
"e8",
"00",
"00",
"00",
"00"
],
"address": 76,
"source": 11,
@ -210,11 +210,11 @@
},
{
"opcodes": [
72,
141,
76,
36,
72
"48",
"8d",
"4c",
"24",
"48"
],
"address": 81,
"source": 11,
@ -222,11 +222,11 @@
},
{
"opcodes": [
232,
0,
0,
0,
0
"e8",
"00",
"00",
"00",
"00"
],
"address": 86,
"source": 11,
@ -234,11 +234,11 @@
},
{
"opcodes": [
72,
139,
76,
36,
104
"48",
"8b",
"4c",
"24",
"68"
],
"address": 91,
"source": 11,
@ -246,9 +246,9 @@
},
{
"opcodes": [
72,
51,
204
"48",
"33",
"cc"
],
"address": 96,
"source": 11,
@ -256,11 +256,11 @@
},
{
"opcodes": [
232,
0,
0,
0,
0