Browse Source

Fix up AVR line processing. Fixes #164

dev/git-series/gccdum
Matt Godbolt 6 years ago
parent
commit
ce82847723
  1. 4
      .idea/misc.xml
  2. 4
      etc/config/c++.danger.properties
  3. 16
      lib/asm.js
  4. 126
      test/cases/avr-loop.asm
  5. 226
      test/cases/avr-loop.asm.directives.labels.comments.json
  6. 1
      test/test.js

4
.idea/misc.xml

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_3" assert-keyword="false" jdk-15="false" />
</project>

4
etc/config/c++.danger.properties

@ -1,6 +1,6 @@
# Matt's home development computer
defaultCompiler=g54
compilers=g54:g47:g48:AWS
compilers=g54:g47:g48:avr
#compilers=localhost@20480
compiler.g54.exe=/usr/bin/g++
compiler.g54.name=g++ 5.4
@ -8,4 +8,6 @@ compiler.g47.exe=/usr/bin/g++-4.7
compiler.g47.name=g++ 4.7
compiler.g48.exe=/usr/bin/g++-4.8
compiler.g48.name=g++ 4.8
compiler.avr.exe=/usr/bin/avr-g++
compiler.avr.name=g++ avr
#compiler-wrapper=./c-preload/compiler-wrapper

16
lib/asm.js

@ -114,8 +114,9 @@
var prevLabel = "";
var directive = /^\s*\..*$/;
var commentOnly = /^\s*(#|@|\/\/).*/;
var commentOnly = /^\s*(((#|@|\/\/).*)|(\/\*.*\*\/))$/;
var sourceTag = /^\s*\.loc\s+(\d+)\s+(\d+).*/;
var sourceStab = /^\s*\.stabn\s+(\d+),0,(\d+),.*/;
var stdInLooking = /.*<stdin>|-|example/;
var endBlock = /\.(cfi_endproc|data|text|section)/;
var source = null;
@ -132,6 +133,19 @@
source = parseInt(match[2]);
}
}
if (!!(match = line.match(sourceStab))) {
// cf http://www.math.utah.edu/docs/info/stabs_11.html#SEC48
switch (parseInt(match[1])) {
case 68:
source = parseInt(match[2]);
break;
case 132:
case 100:
source = null;
prevLabel = null;
break;
}
}
if (line.match(endBlock)) {
source = null;
prevLabel = null;

126
test/cases/avr-loop.asm

@ -0,0 +1,126 @@
.file "example.cpp"
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__CCP__ = 0x34
__tmp_reg__ = 0
__zero_reg__ = 1
.stabs "/gcc-explorer/",100,0,4,.Ltext0
.stabs "/tmp/gcc-explorer-compiler116922-97-ldr5x6/example.cpp",100,0,4,.Ltext0
.text
.Ltext0:
.stabs "gcc2_compiled.",60,0,0,0
.stabs "__builtin_va_list:t(0,1)=*(0,2)=(0,2)",128,0,0,0
.stabs "complex long double:t(0,3)=R3;8;0;",128,0,0,0
.stabs "complex double:t(0,4)=R3;8;0;",128,0,0,0
.stabs "complex float:t(0,5)=R3;8;0;",128,0,0,0
.stabs "complex int:t(0,6)=s4real:(0,7)=r(0,7);-32768;32767;,0,16;imag:(0,7),16,16;;",128,0,0,0
.stabs "long long unsigned int:t(0,8)=@s64;r(0,8);0;01777777777777777777777;",128,0,0,0
.stabs "long unsigned int:t(0,9)=@s32;r(0,9);0;037777777777;",128,0,0,0
.stabs "unsigned int:t(0,10)=r(0,10);0;0177777;",128,0,0,0
.stabs "unsigned char:t(0,11)=@s8;r(0,11);0;255;",128,0,0,0
.stabs "long long int:t(0,12)=@s64;r(0,12);01000000000000000000000;0777777777777777777777;",128,0,0,0
.stabs "long int:t(0,13)=@s32;r(0,13);020000000000;017777777777;",128,0,0,0
.stabs "int:t(0,7)",128,0,0,0
.stabs "signed char:t(0,14)=@s8;r(0,14);-128;127;",128,0,0,0
.stabs "char:t(0,15)=r(0,15);0;127;",128,0,0,0
.stabs "signed:t(0,7)",128,0,0,0
.stabs "unsigned long:t(0,9)",128,0,0,0
.stabs "long long unsigned:t(0,8)",128,0,0,0
.stabs "short int:t(0,16)=r(0,16);-32768;32767;",128,0,0,0
.stabs "short unsigned int:t(0,17)=r(0,17);0;0177777;",128,0,0,0
.stabs "unsigned short:t(0,17)",128,0,0,0
.stabs "float:t(0,18)=r(0,7);4;0;",128,0,0,0
.stabs "double:t(0,19)=r(0,7);4;0;",128,0,0,0
.stabs "long double:t(0,20)=r(0,7);4;0;",128,0,0,0
.stabs "void:t(0,2)",128,0,0,0
.stabs "wchar_t:t(0,21)=r(0,21);-32768;32767;",128,0,0,0
.stabs "bool:t(0,22)=@s8;-16;",128,0,0,0
.stabs "__vtbl_ptr_type:t(0,23)=*(0,24)=f(0,7)",128,0,0,0
.stabs "foo():F(0,7)",36,0,2,foo()
.global foo()
.type foo(), @function
foo():
.stabd 46,0,0
.stabn 68,0,2,.LM0-.LFBB1
.LM0:
.LFBB1:
push r29
push r28
rcall .
rcall .
in r28,__SP_L__
in r29,__SP_H__
/* prologue: function */
/* frame size = 4 */
/* stack size = 6 */
.L__stack_usage = 6
.LBB2:
.stabn 68,0,3,.LM1-.LFBB1
.LM1:
std Y+2,__zero_reg__
std Y+1,__zero_reg__
.LBB3:
.stabn 68,0,4,.LM2-.LFBB1
.LM2:
std Y+4,__zero_reg__
std Y+3,__zero_reg__
rjmp .L2
.L4:
.stabn 68,0,5,.LM3-.LFBB1
.LM3:
rcall bar()
ldd r18,Y+1
ldd r19,Y+2
add r24,r18
adc r25,r19
std Y+2,r25
std Y+1,r24
.stabn 68,0,4,.LM4-.LFBB1
.LM4:
ldd r24,Y+3
ldd r25,Y+4
adiw r24,1
std Y+4,r25
std Y+3,r24
.L2:
.stabn 68,0,4,.LM5-.LFBB1
.LM5:
ldi r18,lo8(1)
ldd r24,Y+3
ldd r25,Y+4
cpi r24,100
cpc r25,__zero_reg__
brlt .L3
ldi r18,lo8(0)
.L3:
tst r18
brne .L4
.LBE3:
.stabn 68,0,7,.LM6-.LFBB1
.LM6:
ldd r24,Y+1
ldd r25,Y+2
/* epilogue start */
.LBE2:
.stabn 68,0,8,.LM7-.LFBB1
.LM7:
pop __tmp_reg__
pop __tmp_reg__
pop __tmp_reg__
pop __tmp_reg__
pop r28
pop r29
ret
.size foo(), .-foo()
.stabs "a:(0,7)",128,0,3,1
.stabn 192,0,0,.LBB2-.LFBB1
.stabs "i:(0,7)",128,0,4,3
.stabn 192,0,0,.LBB3-.LFBB1
.stabn 224,0,0,.LBE3-.LFBB1
.stabn 224,0,0,.LBE2-.LFBB1
.Lscope1:
.stabs "",36,0,0,.Lscope1-.LFBB1
.stabd 78,0,0
.stabs "",100,0,0,.Letext0
.Letext0:

226
test/cases/avr-loop.asm.directives.labels.comments.json

@ -0,0 +1,226 @@
[
{
"text": "__SREG__ = 0x3f",
"source": null
},
{
"text": "__SP_H__ = 0x3e",
"source": null
},
{
"text": "__SP_L__ = 0x3d",
"source": null
},
{
"text": "__CCP__ = 0x34",
"source": null
},
{
"text": "__tmp_reg__ = 0",
"source": null
},
{
"text": "__zero_reg__ = 1",
"source": null
},
{
"text": "foo():",
"source": null
},
{
"text": ".LFBB1:",
"source": null
},
{
"text": " push r29",
"source": 2
},
{
"text": " push r28",
"source": 2
},
{
"text": " rcall .",
"source": 2
},
{
"text": " rcall .",
"source": 2
},
{
"text": " in r28,__SP_L__",
"source": 2
},
{
"text": " in r29,__SP_H__",
"source": 2
},
{
"text": " std Y+2,__zero_reg__",
"source": 3
},
{
"text": " std Y+1,__zero_reg__",
"source": 3
},
{
"text": " std Y+4,__zero_reg__",
"source": 4
},
{
"text": " std Y+3,__zero_reg__",
"source": 4
},
{
"text": " rjmp .L2",
"source": 4
},
{
"text": ".L4:",
"source": null
},
{
"text": ".LM3:",
"source": null
},
{
"text": " rcall bar()",
"source": 5
},
{
"text": " ldd r18,Y+1",
"source": 5
},
{
"text": " ldd r19,Y+2",
"source": 5
},
{
"text": " add r24,r18",
"source": 5
},
{
"text": " adc r25,r19",
"source": 5
},
{
"text": " std Y+2,r25",
"source": 5
},
{
"text": " std Y+1,r24",
"source": 5
},
{
"text": ".LM4:",
"source": null
},
{
"text": " ldd r24,Y+3",
"source": 4
},
{
"text": " ldd r25,Y+4",
"source": 4
},
{
"text": " adiw r24,1",
"source": 4
},
{
"text": " std Y+4,r25",
"source": 4
},
{
"text": " std Y+3,r24",
"source": 4
},
{
"text": ".L2:",
"source": null
},
{
"text": ".LM5:",
"source": null
},
{
"text": " ldi r18,lo8(1)",
"source": 4
},
{
"text": " ldd r24,Y+3",
"source": 4
},
{
"text": " ldd r25,Y+4",
"source": 4
},
{
"text": " cpi r24,100",
"source": 4
},
{
"text": " cpc r25,__zero_reg__",
"source": 4
},
{
"text": " brlt .L3",
"source": 4
},
{
"text": " ldi r18,lo8(0)",
"source": 4
},
{
"text": ".L3:",
"source": null
},
{
"text": " tst r18",
"source": 4
},
{
"text": " brne .L4",
"source": 4
},
{
"text": " ldd r24,Y+1",
"source": 7
},
{
"text": " ldd r25,Y+2",
"source": 7
},
{
"text": " pop __tmp_reg__",
"source": 8
},
{
"text": " pop __tmp_reg__",
"source": 8
},
{
"text": " pop __tmp_reg__",
"source": 8
},
{
"text": " pop __tmp_reg__",
"source": 8
},
{
"text": " pop r28",
"source": 8
},
{
"text": " pop r29",
"source": 8
},
{
"text": " ret",
"source": 8
},
{
"text": "",
"source": null
}
]

1
test/test.js

@ -106,6 +106,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/avr-loop.asm", "cases/avr-loop.asm.directives.labels.comments.json", {directives: true, labels: true, commentOnly: true});
cases.forEach(function (x) {
testFilter(x, ".directives", {directives: true})

Loading…
Cancel
Save