From 5e18953517d55b03de69c3f4b288cb5e0cc5e607 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Fri, 13 Aug 2021 22:03:52 +0200 Subject: [PATCH] Added test. --- src/main/kc/include/stdio.h | 3 +- .../kickc/test/TestProgramsFast.java | 5 + src/test/kc/printf-18.c | 17 + src/test/ref/printf-18.asm | 587 +++ src/test/ref/printf-18.cfg | 291 ++ src/test/ref/printf-18.log | 4352 +++++++++++++++++ src/test/ref/printf-18.sym | 130 + 7 files changed, 5384 insertions(+), 1 deletion(-) create mode 100644 src/test/kc/printf-18.c create mode 100644 src/test/ref/printf-18.asm create mode 100644 src/test/ref/printf-18.cfg create mode 100644 src/test/ref/printf-18.log create mode 100644 src/test/ref/printf-18.sym diff --git a/src/main/kc/include/stdio.h b/src/main/kc/include/stdio.h index 6d52f33c1..3d88da3ce 100644 --- a/src/main/kc/include/stdio.h +++ b/src/main/kc/include/stdio.h @@ -2,4 +2,5 @@ /// Functions for performing input and output. #include -#include \ No newline at end of file +#include +#include \ No newline at end of file diff --git a/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java b/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java index 619dd7324..cd22d8318 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java +++ b/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java @@ -879,6 +879,11 @@ public class TestProgramsFast extends TestPrograms { assertError("printf-error-1.c", "Needed printf sub-procedure not found"); } + @Test + public void testPrintf18() throws IOException { + compileAndCompare("printf-18.c"); + } + @Test public void testPrintf17() throws IOException { compileAndCompare("printf-17.c"); diff --git a/src/test/kc/printf-18.c b/src/test/kc/printf-18.c new file mode 100644 index 000000000..e540dbcb5 --- /dev/null +++ b/src/test/kc/printf-18.c @@ -0,0 +1,17 @@ +// Tests snprintf function call rewriting +// Test snprintf() and printf() in the same file + +#include + +char BUF1[20]; +char BUF2[20]; +char * screen = (char*)0x0400; + +void main() { + snprintf(BUF1, 20, "hello world!"); + snprintf(BUF2, 20, "hello %s%c", "world", '!'); + printf("-%s- -%s-", BUF1, BUF2); +} + + + diff --git a/src/test/ref/printf-18.asm b/src/test/ref/printf-18.asm new file mode 100644 index 000000000..ec60c1614 --- /dev/null +++ b/src/test/ref/printf-18.asm @@ -0,0 +1,587 @@ +// Tests snprintf function call rewriting +// Test snprintf() and printf() in the same file + // Commodore 64 PRG executable file +.file [name="printf-18.prg", type="prg", segments="Program"] +.segmentdef Program [segments="Basic, Code, Data"] +.segmentdef Basic [start=$0801] +.segmentdef Code [start=$80d] +.segmentdef Data [startAfter="Code"] +.segment Basic +:BasicUpstart(__start) + .const LIGHT_BLUE = $e + .const STACK_BASE = $103 + /// Color Ram + .label COLORRAM = $d800 + /// Default address of screen character matrix + .label DEFAULT_SCREEN = $400 + // The number of bytes on the screen + // The current cursor x-position + .label conio_cursor_x = 8 + // The current cursor y-position + .label conio_cursor_y = 9 + // The current text cursor line start + .label conio_line_text = $a + // The current color cursor line start + .label conio_line_color = $c + /// The capacity of the buffer (n passed to snprintf()) + /// Used to hold state while printing + .label __snprintf_capacity = $e + // The number of chars that would have been filled when printing without capacity. Grows even after size>capacity. + /// Used to hold state while printing + .label __snprintf_size = $10 + /// Current position in the buffer being filled ( initially *s passed to snprintf() + /// Used to hold state while printing + .label __snprintf_buffer = $12 +.segment Code +__start: { + // __ma char conio_cursor_x = 0 + lda #0 + sta.z conio_cursor_x + // __ma char conio_cursor_y = 0 + sta.z conio_cursor_y + // __ma char *conio_line_text = CONIO_SCREEN_TEXT + lda #DEFAULT_SCREEN + sta.z conio_line_text+1 + // __ma char *conio_line_color = CONIO_SCREEN_COLORS + lda #COLORRAM + sta.z conio_line_color+1 + // volatile size_t __snprintf_capacity + lda #<0 + sta.z __snprintf_capacity + sta.z __snprintf_capacity+1 + // volatile size_t __snprintf_size + sta.z __snprintf_size + sta.z __snprintf_size+1 + // char * __snprintf_buffer + sta.z __snprintf_buffer + sta.z __snprintf_buffer+1 + // #pragma constructor_for(conio_c64_init, cputc, clrscr, cscroll) + jsr conio_c64_init + jsr main + rts +} +/// Print a character into snprintf buffer +/// Used by snprintf() +/// @param c The character to print +// void snputc(__register(X) char c) +snputc: { + .const OFFSET_STACK_C = 0 + tsx + lda STACK_BASE+OFFSET_STACK_C,x + tax + // ++__snprintf_size; + inc.z __snprintf_size + bne !+ + inc.z __snprintf_size+1 + !: + // if(__snprintf_size > __snprintf_capacity) + lda.z __snprintf_size+1 + cmp.z __snprintf_capacity+1 + bne !+ + lda.z __snprintf_size + cmp.z __snprintf_capacity + beq __b1 + !: + bcc __b1 + // } + rts + __b1: + // if(__snprintf_size==__snprintf_capacity) + lda.z __snprintf_size+1 + cmp.z __snprintf_capacity+1 + bne __b2 + lda.z __snprintf_size + cmp.z __snprintf_capacity + bne __b2 + ldx #0 + __b2: + // *(__snprintf_buffer++) = c + // Append char + txa + ldy #0 + sta (__snprintf_buffer),y + // *(__snprintf_buffer++) = c; + inc.z __snprintf_buffer + bne !+ + inc.z __snprintf_buffer+1 + !: + rts +} +// Set initial cursor position +conio_c64_init: { + // Position cursor at current line + .label BASIC_CURSOR_LINE = $d6 + // char line = *BASIC_CURSOR_LINE + ldx BASIC_CURSOR_LINE + // if(line>=CONIO_HEIGHT) + cpx #$19 + bcc __b1 + ldx #$19-1 + __b1: + // gotoxy(0, line) + jsr gotoxy + // } + rts +} +// Output one character at the current cursor position +// Moves the cursor forward. Scrolls the entire screen if needed +// void cputc(__register(A) char c) +cputc: { + .const OFFSET_STACK_C = 0 + tsx + lda STACK_BASE+OFFSET_STACK_C,x + // if(c=='\n') + cmp #'\n' + beq __b1 + // conio_line_text[conio_cursor_x] = c + ldy.z conio_cursor_x + sta (conio_line_text),y + // conio_line_color[conio_cursor_x] = conio_textcolor + lda #LIGHT_BLUE + sta (conio_line_color),y + // if(++conio_cursor_x==CONIO_WIDTH) + inc.z conio_cursor_x + lda #$28 + cmp.z conio_cursor_x + bne __breturn + // cputln() + jsr cputln + __breturn: + // } + rts + __b1: + // cputln() + jsr cputln + rts +} +main: { + // snprintf(BUF1, 20, "hello world!") + lda #BUF1 + sta.z snprintf_init.s+1 + jsr snprintf_init + // snprintf(BUF1, 20, "hello world!") + lda #snputc + sta.z printf_str.putc+1 + lda #s + sta.z printf_str.s+1 + jsr printf_str + // snprintf(BUF1, 20, "hello world!") + lda #0 + pha + jsr snputc + pla + // snprintf(BUF2, 20, "hello %s%c", "world", '!') + lda #BUF2 + sta.z snprintf_init.s+1 + jsr snprintf_init + // snprintf(BUF2, 20, "hello %s%c", "world", '!') + lda #snputc + sta.z printf_str.putc+1 + lda #s1 + sta.z printf_str.s+1 + jsr printf_str + // snprintf(BUF2, 20, "hello %s%c", "world", '!') + lda #snputc + sta.z printf_string.putc+1 + lda #str + sta.z printf_string.str+1 + jsr printf_string + // snprintf(BUF2, 20, "hello %s%c", "world", '!') + lda #'!' + pha + jsr snputc + pla + lda #0 + pha + jsr snputc + pla + // printf("-%s- -%s-", BUF1, BUF2) + lda #cputc + sta.z printf_str.putc+1 + lda #s2 + sta.z printf_str.s+1 + jsr printf_str + // printf("-%s- -%s-", BUF1, BUF2) + lda #cputc + sta.z printf_string.putc+1 + lda #BUF1 + sta.z printf_string.str+1 + jsr printf_string + // printf("-%s- -%s-", BUF1, BUF2) + lda #cputc + sta.z printf_str.putc+1 + lda #s3 + sta.z printf_str.s+1 + jsr printf_str + // printf("-%s- -%s-", BUF1, BUF2) + lda #cputc + sta.z printf_string.putc+1 + lda #BUF2 + sta.z printf_string.str+1 + jsr printf_string + // printf("-%s- -%s-", BUF1, BUF2) + lda #cputc + sta.z printf_str.putc+1 + lda #s2 + sta.z printf_str.s+1 + jsr printf_str + // } + rts + .segment Data + s: .text "hello world!" + .byte 0 + s1: .text "hello " + .byte 0 + str: .text "world" + .byte 0 + s2: .text "-" + .byte 0 + s3: .text "- -" + .byte 0 +} +.segment Code +// Set the cursor to the specified position +// void gotoxy(char x, __register(X) char y) +gotoxy: { + .const x = 0 + .label __5 = $18 + .label __6 = $14 + .label __7 = $14 + .label line_offset = $14 + .label __8 = $16 + .label __9 = $14 + // if(y>CONIO_HEIGHT) + cpx #$19+1 + bcc __b2 + ldx #0 + __b2: + // conio_cursor_x = x + lda #x + sta.z conio_cursor_x + // conio_cursor_y = y + stx.z conio_cursor_y + // unsigned int line_offset = (unsigned int)y*CONIO_WIDTH + txa + sta.z __7 + lda #0 + sta.z __7+1 + lda.z __7 + asl + sta.z __8 + lda.z __7+1 + rol + sta.z __8+1 + asl.z __8 + rol.z __8+1 + clc + lda.z __9 + adc.z __8 + sta.z __9 + lda.z __9+1 + adc.z __8+1 + sta.z __9+1 + asl.z line_offset + rol.z line_offset+1 + asl.z line_offset + rol.z line_offset+1 + asl.z line_offset + rol.z line_offset+1 + // CONIO_SCREEN_TEXT + line_offset + lda.z line_offset + clc + adc #DEFAULT_SCREEN + sta.z __5+1 + // conio_line_text = CONIO_SCREEN_TEXT + line_offset + lda.z __5 + sta.z conio_line_text + lda.z __5+1 + sta.z conio_line_text+1 + // CONIO_SCREEN_COLORS + line_offset + lda.z __6 + clc + adc #COLORRAM + sta.z __6+1 + // conio_line_color = CONIO_SCREEN_COLORS + line_offset + lda.z __6 + sta.z conio_line_color + lda.z __6+1 + sta.z conio_line_color+1 + // } + rts +} +// Print a newline +cputln: { + // conio_line_text += CONIO_WIDTH + lda #$28 + clc + adc.z conio_line_text + sta.z conio_line_text + bcc !+ + inc.z conio_line_text+1 + !: + // conio_line_color += CONIO_WIDTH + lda #$28 + clc + adc.z conio_line_color + sta.z conio_line_color + bcc !+ + inc.z conio_line_color+1 + !: + // conio_cursor_x = 0 + lda #0 + sta.z conio_cursor_x + // conio_cursor_y++; + inc.z conio_cursor_y + // cscroll() + jsr cscroll + // } + rts +} +/// Initialize the snprintf() state +// void snprintf_init(__zp(2) char *s, unsigned int n) +snprintf_init: { + .label s = 2 + // __snprintf_capacity = n + lda #<$14 + sta.z __snprintf_capacity + lda #>$14 + sta.z __snprintf_capacity+1 + // __snprintf_size = 0 + lda #<0 + sta.z __snprintf_size + sta.z __snprintf_size+1 + // __snprintf_buffer = s + lda.z s + sta.z __snprintf_buffer + lda.z s+1 + sta.z __snprintf_buffer+1 + // } + rts +} +/// Print a NUL-terminated string +// void printf_str(__zp(2) void (*putc)(char), __zp(4) const char *s) +printf_str: { + .label s = 4 + .label putc = 2 + __b1: + // while(c=*s++) + ldy #0 + lda (s),y + inc.z s + bne !+ + inc.z s+1 + !: + cmp #0 + bne __b2 + // } + rts + __b2: + // putc(c) + pha + jsr icall4 + pla + jmp __b1 + icall4: + jmp (putc) +} +// Print a string value using a specific format +// Handles justification and min length +// void printf_string(__zp(2) void (*putc)(char), __zp(4) char *str, char format_min_length, char format_justify_left) +printf_string: { + .label putc = 2 + .label str = 4 + // printf_str(putc, str) + jsr printf_str + // } + rts +} +// Scroll the entire screen if the cursor is beyond the last line +cscroll: { + // if(conio_cursor_y==CONIO_HEIGHT) + lda #$19 + cmp.z conio_cursor_y + bne __breturn + // memcpy(CONIO_SCREEN_TEXT, CONIO_SCREEN_TEXT+CONIO_WIDTH, CONIO_BYTES-CONIO_WIDTH) + lda #DEFAULT_SCREEN + sta.z memcpy.destination+1 + lda #DEFAULT_SCREEN+$28 + sta.z memcpy.source+1 + jsr memcpy + // memcpy(CONIO_SCREEN_COLORS, CONIO_SCREEN_COLORS+CONIO_WIDTH, CONIO_BYTES-CONIO_WIDTH) + lda #COLORRAM + sta.z memcpy.destination+1 + lda #COLORRAM+$28 + sta.z memcpy.source+1 + jsr memcpy + // memset(CONIO_SCREEN_TEXT+CONIO_BYTES-CONIO_WIDTH, ' ', CONIO_WIDTH) + ldx #' ' + lda #DEFAULT_SCREEN+$19*$28-$28 + sta.z memset.str+1 + jsr memset + // memset(CONIO_SCREEN_COLORS+CONIO_BYTES-CONIO_WIDTH, conio_textcolor, CONIO_WIDTH) + ldx #LIGHT_BLUE + lda #COLORRAM+$19*$28-$28 + sta.z memset.str+1 + jsr memset + // conio_line_text -= CONIO_WIDTH + sec + lda.z conio_line_text + sbc #$28 + sta.z conio_line_text + lda.z conio_line_text+1 + sbc #0 + sta.z conio_line_text+1 + // conio_line_color -= CONIO_WIDTH + sec + lda.z conio_line_color + sbc #$28 + sta.z conio_line_color + lda.z conio_line_color+1 + sbc #0 + sta.z conio_line_color+1 + // conio_cursor_y--; + dec.z conio_cursor_y + __breturn: + // } + rts +} +// Copy block of memory (forwards) +// Copies the values of num bytes from the location pointed to by source directly to the memory block pointed to by destination. +// void * memcpy(__zp($1c) void *destination, __zp(6) void *source, unsigned int num) +memcpy: { + .label src_end = $1a + .label dst = $1c + .label src = 6 + .label source = 6 + .label destination = $1c + // char* src_end = (char*)source+num + lda.z source + clc + adc #<$19*$28-$28 + sta.z src_end + lda.z source+1 + adc #>$19*$28-$28 + sta.z src_end+1 + __b1: + // while(src!=src_end) + lda.z src+1 + cmp.z src_end+1 + bne __b2 + lda.z src + cmp.z src_end + bne __b2 + // } + rts + __b2: + // *dst++ = *src++ + ldy #0 + lda (src),y + sta (dst),y + // *dst++ = *src++; + inc.z dst + bne !+ + inc.z dst+1 + !: + inc.z src + bne !+ + inc.z src+1 + !: + jmp __b1 +} +// Copies the character c (an unsigned char) to the first num characters of the object pointed to by the argument str. +// void * memset(__zp(6) void *str, __register(X) char c, unsigned int num) +memset: { + .label end = $1c + .label dst = 6 + .label str = 6 + // char* end = (char*)str + num + lda #$28 + clc + adc.z str + sta.z end + lda #0 + adc.z str+1 + sta.z end+1 + __b2: + // for(char* dst = str; dst!=end; dst++) + lda.z dst+1 + cmp.z end+1 + bne __b3 + lda.z dst + cmp.z end + bne __b3 + // } + rts + __b3: + // *dst = c + txa + ldy #0 + sta (dst),y + // for(char* dst = str; dst!=end; dst++) + inc.z dst + bne !+ + inc.z dst+1 + !: + jmp __b2 +} +.segment Data + BUF1: .fill $14, 0 + BUF2: .fill $14, 0 diff --git a/src/test/ref/printf-18.cfg b/src/test/ref/printf-18.cfg new file mode 100644 index 000000000..1568d11a7 --- /dev/null +++ b/src/test/ref/printf-18.cfg @@ -0,0 +1,291 @@ + +void __start() +__start: scope:[__start] from + [0] phi() + to:__start::__init1 +__start::__init1: scope:[__start] from __start + [1] conio_cursor_x = 0 + [2] conio_cursor_y = 0 + [3] conio_line_text = DEFAULT_SCREEN + [4] conio_line_color = COLORRAM + [5] __snprintf_capacity = 0 + [6] __snprintf_size = 0 + [7] __snprintf_buffer = (char *) 0 + [8] call conio_c64_init + to:__start::@1 +__start::@1: scope:[__start] from __start::__init1 + [9] phi() + [10] call main + to:__start::@return +__start::@return: scope:[__start] from __start::@1 + [11] return + to:@return + +__stackcall void snputc(char c) +snputc: scope:[snputc] from + [12] snputc::c#0 = stackidx(char,snputc::OFFSET_STACK_C) + [13] __snprintf_size = ++ __snprintf_size + [14] if(__snprintf_size<=__snprintf_capacity) goto snputc::@1 + to:snputc::@return +snputc::@return: scope:[snputc] from snputc snputc::@2 + [15] return + to:@return +snputc::@1: scope:[snputc] from snputc + [16] if(__snprintf_size!=__snprintf_capacity) goto snputc::@3 + to:snputc::@2 +snputc::@3: scope:[snputc] from snputc::@1 + [17] phi() + to:snputc::@2 +snputc::@2: scope:[snputc] from snputc::@1 snputc::@3 + [18] snputc::c#2 = phi( snputc::@3/snputc::c#0, snputc::@1/0 ) + [19] *__snprintf_buffer = snputc::c#2 + [20] __snprintf_buffer = ++ __snprintf_buffer + to:snputc::@return + +void conio_c64_init() +conio_c64_init: scope:[conio_c64_init] from __start::__init1 + [21] conio_c64_init::line#0 = *conio_c64_init::BASIC_CURSOR_LINE + [22] if(conio_c64_init::line#0<$19) goto conio_c64_init::@2 + to:conio_c64_init::@1 +conio_c64_init::@2: scope:[conio_c64_init] from conio_c64_init + [23] phi() + to:conio_c64_init::@1 +conio_c64_init::@1: scope:[conio_c64_init] from conio_c64_init conio_c64_init::@2 + [24] conio_c64_init::line#2 = phi( conio_c64_init::@2/conio_c64_init::line#0, conio_c64_init/$19-1 ) + [25] gotoxy::y#2 = conio_c64_init::line#2 + [26] call gotoxy + to:conio_c64_init::@return +conio_c64_init::@return: scope:[conio_c64_init] from conio_c64_init::@1 + [27] return + to:@return + +__stackcall void cputc(char c) +cputc: scope:[cputc] from + [28] cputc::c#0 = stackidx(char,cputc::OFFSET_STACK_C) + [29] if(cputc::c#0==' +') goto cputc::@1 + to:cputc::@2 +cputc::@2: scope:[cputc] from cputc + [30] conio_line_text[conio_cursor_x] = cputc::c#0 + [31] conio_line_color[conio_cursor_x] = LIGHT_BLUE + [32] conio_cursor_x = ++ conio_cursor_x + [33] if(conio_cursor_x!=$28) goto cputc::@return + to:cputc::@3 +cputc::@3: scope:[cputc] from cputc::@2 + [34] phi() + [35] call cputln + to:cputc::@return +cputc::@return: scope:[cputc] from cputc::@1 cputc::@2 cputc::@3 + [36] return + to:@return +cputc::@1: scope:[cputc] from cputc + [37] phi() + [38] call cputln + to:cputc::@return + +void main() +main: scope:[main] from __start::@1 + [39] phi() + [40] call snprintf_init + to:main::@1 +main::@1: scope:[main] from main + [41] phi() + [42] call printf_str + to:main::@2 +main::@2: scope:[main] from main::@1 + [43] stackpush(char) = 0 + [44] callexecute snputc + sideeffect stackpullbytes(1) + [46] call snprintf_init + to:main::@3 +main::@3: scope:[main] from main::@2 + [47] phi() + [48] call printf_str + to:main::@4 +main::@4: scope:[main] from main::@3 + [49] phi() + [50] call printf_string + to:main::@5 +main::@5: scope:[main] from main::@4 + [51] stackpush(char) = '!' + [52] callexecute snputc + sideeffect stackpullbytes(1) + [54] stackpush(char) = 0 + [55] callexecute snputc + sideeffect stackpullbytes(1) + [57] call printf_str + to:main::@6 +main::@6: scope:[main] from main::@5 + [58] phi() + [59] call printf_string + to:main::@7 +main::@7: scope:[main] from main::@6 + [60] phi() + [61] call printf_str + to:main::@8 +main::@8: scope:[main] from main::@7 + [62] phi() + [63] call printf_string + to:main::@9 +main::@9: scope:[main] from main::@8 + [64] phi() + [65] call printf_str + to:main::@return +main::@return: scope:[main] from main::@9 + [66] return + to:@return + +void gotoxy(char x , char y) +gotoxy: scope:[gotoxy] from conio_c64_init::@1 + [67] if(gotoxy::y#2<$19+1) goto gotoxy::@3 + to:gotoxy::@1 +gotoxy::@3: scope:[gotoxy] from gotoxy + [68] phi() + to:gotoxy::@1 +gotoxy::@1: scope:[gotoxy] from gotoxy gotoxy::@3 + [69] gotoxy::y#4 = phi( gotoxy::@3/gotoxy::y#2, gotoxy/0 ) + to:gotoxy::@2 +gotoxy::@2: scope:[gotoxy] from gotoxy::@1 + [70] conio_cursor_x = gotoxy::x#2 + [71] conio_cursor_y = gotoxy::y#4 + [72] gotoxy::$7 = (unsigned int)gotoxy::y#4 + [73] gotoxy::$8 = gotoxy::$7 << 2 + [74] gotoxy::$9 = gotoxy::$8 + gotoxy::$7 + [75] gotoxy::line_offset#0 = gotoxy::$9 << 3 + [76] gotoxy::$5 = DEFAULT_SCREEN + gotoxy::line_offset#0 + [77] conio_line_text = gotoxy::$5 + [78] gotoxy::$6 = COLORRAM + gotoxy::line_offset#0 + [79] conio_line_color = gotoxy::$6 + to:gotoxy::@return +gotoxy::@return: scope:[gotoxy] from gotoxy::@2 + [80] return + to:@return + +void cputln() +cputln: scope:[cputln] from cputc::@1 cputc::@3 + [81] conio_line_text = conio_line_text + $28 + [82] conio_line_color = conio_line_color + $28 + [83] conio_cursor_x = 0 + [84] conio_cursor_y = ++ conio_cursor_y + [85] call cscroll + to:cputln::@return +cputln::@return: scope:[cputln] from cputln + [86] return + to:@return + +void snprintf_init(char *s , unsigned int n) +snprintf_init: scope:[snprintf_init] from main main::@2 + [87] snprintf_init::s#2 = phi( main/BUF1, main::@2/BUF2 ) + [88] __snprintf_capacity = $14 + [89] __snprintf_size = 0 + [90] __snprintf_buffer = snprintf_init::s#2 + to:snprintf_init::@return +snprintf_init::@return: scope:[snprintf_init] from snprintf_init + [91] return + to:@return + +void printf_str(void (*putc)(char) , const char *s) +printf_str: scope:[printf_str] from main::@1 main::@3 main::@5 main::@7 main::@9 printf_string::@1 + [92] printf_str::putc#8 = phi( main::@1/&snputc, main::@3/&snputc, main::@5/&cputc, main::@7/&cputc, main::@9/&cputc, printf_string::@1/printf_str::putc#0 ) + [92] printf_str::s#8 = phi( main::@1/main::s, main::@3/main::s1, main::@5/main::s2, main::@7/main::s3, main::@9/main::s2, printf_string::@1/printf_str::s#1 ) + to:printf_str::@1 +printf_str::@1: scope:[printf_str] from printf_str printf_str::@2 + [93] printf_str::s#7 = phi( printf_str/printf_str::s#8, printf_str::@2/printf_str::s#0 ) + [94] printf_str::c#1 = *printf_str::s#7 + [95] printf_str::s#0 = ++ printf_str::s#7 + [96] if(0!=printf_str::c#1) goto printf_str::@2 + to:printf_str::@return +printf_str::@return: scope:[printf_str] from printf_str::@1 + [97] return + to:@return +printf_str::@2: scope:[printf_str] from printf_str::@1 + [98] stackpush(char) = printf_str::c#1 + [99] callexecute *printf_str::putc#8 + sideeffect stackpullbytes(1) + to:printf_str::@1 + +void printf_string(void (*putc)(char) , char *str , char format_min_length , char format_justify_left) +printf_string: scope:[printf_string] from main::@4 main::@6 main::@8 + [101] printf_string::putc#10 = phi( main::@4/&snputc, main::@6/&cputc, main::@8/&cputc ) + [101] printf_string::str#10 = phi( main::@4/main::str, main::@6/BUF1, main::@8/BUF2 ) + to:printf_string::@1 +printf_string::@1: scope:[printf_string] from printf_string + [102] printf_str::putc#0 = printf_string::putc#10 + [103] printf_str::s#1 = printf_string::str#10 + [104] call printf_str + to:printf_string::@return +printf_string::@return: scope:[printf_string] from printf_string::@1 + [105] return + to:@return + +void cscroll() +cscroll: scope:[cscroll] from cputln + [106] if(conio_cursor_y!=$19) goto cscroll::@return + to:cscroll::@1 +cscroll::@1: scope:[cscroll] from cscroll + [107] phi() + [108] call memcpy + to:cscroll::@2 +cscroll::@2: scope:[cscroll] from cscroll::@1 + [109] phi() + [110] call memcpy + to:cscroll::@3 +cscroll::@3: scope:[cscroll] from cscroll::@2 + [111] phi() + [112] call memset + to:cscroll::@4 +cscroll::@4: scope:[cscroll] from cscroll::@3 + [113] phi() + [114] call memset + to:cscroll::@5 +cscroll::@5: scope:[cscroll] from cscroll::@4 + [115] conio_line_text = conio_line_text - $28 + [116] conio_line_color = conio_line_color - $28 + [117] conio_cursor_y = -- conio_cursor_y + to:cscroll::@return +cscroll::@return: scope:[cscroll] from cscroll cscroll::@5 + [118] return + to:@return + +void * memcpy(void *destination , void *source , unsigned int num) +memcpy: scope:[memcpy] from cscroll::@1 cscroll::@2 + [119] memcpy::destination#2 = phi( cscroll::@1/(void *)DEFAULT_SCREEN, cscroll::@2/(void *)COLORRAM ) + [119] memcpy::source#2 = phi( cscroll::@1/(void *)DEFAULT_SCREEN+$28, cscroll::@2/(void *)COLORRAM+$28 ) + [120] memcpy::src_end#0 = (char *)memcpy::source#2 + (unsigned int)$19*$28-$28 + [121] memcpy::src#4 = (char *)memcpy::source#2 + [122] memcpy::dst#4 = (char *)memcpy::destination#2 + to:memcpy::@1 +memcpy::@1: scope:[memcpy] from memcpy memcpy::@2 + [123] memcpy::dst#2 = phi( memcpy/memcpy::dst#4, memcpy::@2/memcpy::dst#1 ) + [123] memcpy::src#2 = phi( memcpy/memcpy::src#4, memcpy::@2/memcpy::src#1 ) + [124] if(memcpy::src#2!=memcpy::src_end#0) goto memcpy::@2 + to:memcpy::@return +memcpy::@return: scope:[memcpy] from memcpy::@1 + [125] return + to:@return +memcpy::@2: scope:[memcpy] from memcpy::@1 + [126] *memcpy::dst#2 = *memcpy::src#2 + [127] memcpy::dst#1 = ++ memcpy::dst#2 + [128] memcpy::src#1 = ++ memcpy::src#2 + to:memcpy::@1 + +void * memset(void *str , char c , unsigned int num) +memset: scope:[memset] from cscroll::@3 cscroll::@4 + [129] memset::c#4 = phi( cscroll::@3/' ', cscroll::@4/LIGHT_BLUE ) + [129] memset::str#3 = phi( cscroll::@3/(void *)DEFAULT_SCREEN+(unsigned int)$19*$28-$28, cscroll::@4/(void *)COLORRAM+(unsigned int)$19*$28-$28 ) + to:memset::@1 +memset::@1: scope:[memset] from memset + [130] memset::end#0 = (char *)memset::str#3 + $28 + [131] memset::dst#4 = (char *)memset::str#3 + to:memset::@2 +memset::@2: scope:[memset] from memset::@1 memset::@3 + [132] memset::dst#2 = phi( memset::@1/memset::dst#4, memset::@3/memset::dst#1 ) + [133] if(memset::dst#2!=memset::end#0) goto memset::@3 + to:memset::@return +memset::@return: scope:[memset] from memset::@2 + [134] return + to:@return +memset::@3: scope:[memset] from memset::@2 + [135] *memset::dst#2 = memset::c#4 + [136] memset::dst#1 = ++ memset::dst#2 + to:memset::@2 diff --git a/src/test/ref/printf-18.log b/src/test/ref/printf-18.log new file mode 100644 index 000000000..4b3808d64 --- /dev/null +++ b/src/test/ref/printf-18.log @@ -0,0 +1,4352 @@ +Fixing struct type size struct printf_buffer_number to 12 +Fixing struct type size struct printf_buffer_number to 12 +Fixing struct type size struct printf_buffer_number to 12 +Fixing struct type SIZE_OF struct printf_buffer_number to 12 +Fixing struct type SIZE_OF struct printf_buffer_number to 12 +Setting inferred __stackcall on procedure affected by address-of __stackcall void snputc(char c) caused by statement call printf_str(&snputc, "hello world!") +Setting inferred __stackcall on procedure affected by address-of __stackcall void snputc(char c) caused by statement call printf_str(&snputc, "hello ") +Setting inferred __stackcall on procedure affected by address-of __stackcall void snputc(char c) caused by statement call printf_string(&snputc, "world", { 0, 0 }) +Setting inferred __stackcall on procedure affected by address-of __stackcall void cputc(char c) caused by statement call printf_str(&cputc, "-") +Setting inferred __stackcall on procedure affected by address-of __stackcall void cputc(char c) caused by statement call printf_string(&cputc, BUF1, { 0, 0 }) +Setting inferred __stackcall on procedure affected by address-of __stackcall void cputc(char c) caused by statement call printf_str(&cputc, "- -") +Setting inferred __stackcall on procedure affected by address-of __stackcall void cputc(char c) caused by statement call printf_string(&cputc, BUF2, { 0, 0 }) +Setting inferred __stackcall on procedure affected by address-of __stackcall void cputc(char c) caused by statement call printf_str(&cputc, "-") +Converting variable modified inside __stackcall procedure snputc() to load/store __snprintf_buffer +Adding parameter assignment in __stackcall procedure cputc::c = param(cputc::c) +Adding parameter assignment in __stackcall procedure snputc::c = param(snputc::c) +Added struct type cast to parameter value list call printf_string(&snputc, "world", (struct printf_format_string){ 0, 0 }) +Added struct type cast to parameter value list call printf_string(&cputc, BUF1, (struct printf_format_string){ 0, 0 }) +Added struct type cast to parameter value list call printf_string(&cputc, BUF2, (struct printf_format_string){ 0, 0 }) +Inlined call vicSelectGfxBank::$0 = call toDd00(vicSelectGfxBank::gfx) +Inlined call call __init +Eliminating unused variable with no statement memcpy::$0 +Eliminating unused variable with no statement memset::$2 +Eliminating unused variable with no statement gotoxy::$4 +Eliminating unused variable with no statement printf_buffer +Eliminating unused variable with no statement main::$0 +Eliminating unused variable with no statement main::$1 +Eliminating unused variable with no statement main::$2 +Calling convention STACK_CALL adding prepare/execute/finalize for call *printf_str::putc printf_str::c +Calling convention STACK_CALL adding prepare/execute/finalize for call *printf_padding::putc printf_padding::pad +Calling convention __stackcall adding prepare/execute/finalize for call snputc(0) +Calling convention __stackcall adding prepare/execute/finalize for call snputc('!') +Calling convention __stackcall adding prepare/execute/finalize for call snputc(0) +Calling convention STACK_CALL replacing param(cputc::c) with stackidx(char,cputc::OFFSET_STACK_C) +Calling convention STACK_CALL replacing param(snputc::c) with stackidx(char,snputc::OFFSET_STACK_C) +Calling convention STACK_CALL adding stack push stackpush(char) = printf_str::c +Calling convention STACK_CALL adding stack push stackpush(char) = printf_padding::pad +Calling convention STACK_CALL adding stack push stackpush(char) = 0 +Calling convention STACK_CALL adding stack push stackpush(char) = '!' +Calling convention STACK_CALL adding stack push stackpush(char) = 0 + +CONTROL FLOW GRAPH SSA + +void * memcpy(void *destination , void *source , unsigned int num) +memcpy: scope:[memcpy] from cscroll::@3 cscroll::@4 + memcpy::num#2 = phi( cscroll::@3/memcpy::num#0, cscroll::@4/memcpy::num#1 ) + memcpy::destination#2 = phi( cscroll::@3/memcpy::destination#0, cscroll::@4/memcpy::destination#1 ) + memcpy::source#2 = phi( cscroll::@3/memcpy::source#0, cscroll::@4/memcpy::source#1 ) + memcpy::src#0 = ((char *)) memcpy::source#2 + memcpy::dst#0 = ((char *)) memcpy::destination#2 + memcpy::$2 = (char *)memcpy::source#2 + memcpy::src_end#0 = memcpy::$2 + memcpy::num#2 + to:memcpy::@1 +memcpy::@1: scope:[memcpy] from memcpy memcpy::@2 + memcpy::destination#4 = phi( memcpy/memcpy::destination#2, memcpy::@2/memcpy::destination#5 ) + memcpy::dst#3 = phi( memcpy/memcpy::dst#0, memcpy::@2/memcpy::dst#1 ) + memcpy::src_end#1 = phi( memcpy/memcpy::src_end#0, memcpy::@2/memcpy::src_end#2 ) + memcpy::src#2 = phi( memcpy/memcpy::src#0, memcpy::@2/memcpy::src#1 ) + memcpy::$1 = memcpy::src#2 != memcpy::src_end#1 + if(memcpy::$1) goto memcpy::@2 + to:memcpy::@3 +memcpy::@2: scope:[memcpy] from memcpy::@1 + memcpy::destination#5 = phi( memcpy::@1/memcpy::destination#4 ) + memcpy::src_end#2 = phi( memcpy::@1/memcpy::src_end#1 ) + memcpy::dst#2 = phi( memcpy::@1/memcpy::dst#3 ) + memcpy::src#3 = phi( memcpy::@1/memcpy::src#2 ) + *memcpy::dst#2 = *memcpy::src#3 + memcpy::dst#1 = ++ memcpy::dst#2 + memcpy::src#1 = ++ memcpy::src#3 + to:memcpy::@1 +memcpy::@3: scope:[memcpy] from memcpy::@1 + memcpy::destination#3 = phi( memcpy::@1/memcpy::destination#4 ) + memcpy::return#0 = memcpy::destination#3 + to:memcpy::@return +memcpy::@return: scope:[memcpy] from memcpy::@3 + memcpy::return#4 = phi( memcpy::@3/memcpy::return#0 ) + memcpy::return#1 = memcpy::return#4 + return + to:@return + +void * memset(void *str , char c , unsigned int num) +memset: scope:[memset] from cscroll::@5 cscroll::@6 + memset::c#5 = phi( cscroll::@5/memset::c#0, cscroll::@6/memset::c#1 ) + memset::str#4 = phi( cscroll::@5/memset::str#0, cscroll::@6/memset::str#1 ) + memset::num#2 = phi( cscroll::@5/memset::num#0, cscroll::@6/memset::num#1 ) + memset::$0 = memset::num#2 > 0 + memset::$1 = ! memset::$0 + if(memset::$1) goto memset::@1 + to:memset::@2 +memset::@1: scope:[memset] from memset memset::@3 + memset::str#2 = phi( memset/memset::str#4, memset::@3/memset::str#5 ) + memset::return#0 = memset::str#2 + to:memset::@return +memset::@2: scope:[memset] from memset + memset::c#4 = phi( memset/memset::c#5 ) + memset::num#3 = phi( memset/memset::num#2 ) + memset::str#3 = phi( memset/memset::str#4 ) + memset::$4 = (char *)memset::str#3 + memset::end#0 = memset::$4 + memset::num#3 + memset::dst#0 = ((char *)) memset::str#3 + to:memset::@3 +memset::@3: scope:[memset] from memset::@2 memset::@4 + memset::c#3 = phi( memset::@2/memset::c#4, memset::@4/memset::c#2 ) + memset::str#5 = phi( memset::@2/memset::str#3, memset::@4/memset::str#6 ) + memset::end#1 = phi( memset::@2/memset::end#0, memset::@4/memset::end#2 ) + memset::dst#2 = phi( memset::@2/memset::dst#0, memset::@4/memset::dst#1 ) + memset::$3 = memset::dst#2 != memset::end#1 + if(memset::$3) goto memset::@4 + to:memset::@1 +memset::@4: scope:[memset] from memset::@3 + memset::str#6 = phi( memset::@3/memset::str#5 ) + memset::end#2 = phi( memset::@3/memset::end#1 ) + memset::dst#3 = phi( memset::@3/memset::dst#2 ) + memset::c#2 = phi( memset::@3/memset::c#3 ) + *memset::dst#3 = memset::c#2 + memset::dst#1 = ++ memset::dst#3 + to:memset::@3 +memset::@return: scope:[memset] from memset::@1 + memset::return#4 = phi( memset::@1/memset::return#0 ) + memset::return#1 = memset::return#4 + return + to:@return + +unsigned int strlen(char *str) +strlen: scope:[strlen] from printf_string::@3 + strlen::str#4 = phi( printf_string::@3/strlen::str#1 ) + strlen::len#0 = 0 + to:strlen::@1 +strlen::@1: scope:[strlen] from strlen strlen::@2 + strlen::len#4 = phi( strlen/strlen::len#0, strlen::@2/strlen::len#1 ) + strlen::str#2 = phi( strlen/strlen::str#4, strlen::@2/strlen::str#0 ) + strlen::$0 = 0 != *strlen::str#2 + if(strlen::$0) goto strlen::@2 + to:strlen::@3 +strlen::@2: scope:[strlen] from strlen::@1 + strlen::str#3 = phi( strlen::@1/strlen::str#2 ) + strlen::len#2 = phi( strlen::@1/strlen::len#4 ) + strlen::len#1 = ++ strlen::len#2 + strlen::str#0 = ++ strlen::str#3 + to:strlen::@1 +strlen::@3: scope:[strlen] from strlen::@1 + strlen::len#3 = phi( strlen::@1/strlen::len#4 ) + strlen::return#0 = strlen::len#3 + to:strlen::@return +strlen::@return: scope:[strlen] from strlen::@3 + strlen::return#3 = phi( strlen::@3/strlen::return#0 ) + strlen::return#1 = strlen::return#3 + return + to:@return + +void gotoxy(char x , char y) +gotoxy: scope:[gotoxy] from conio_c64_init::@1 cscroll::@2 + gotoxy::x#5 = phi( conio_c64_init::@1/gotoxy::x#2, cscroll::@2/gotoxy::x#1 ) + gotoxy::y#3 = phi( conio_c64_init::@1/gotoxy::y#2, cscroll::@2/gotoxy::y#1 ) + gotoxy::$0 = gotoxy::y#3 > $19 + gotoxy::$1 = ! gotoxy::$0 + if(gotoxy::$1) goto gotoxy::@1 + to:gotoxy::@3 +gotoxy::@1: scope:[gotoxy] from gotoxy gotoxy::@3 + gotoxy::y#5 = phi( gotoxy/gotoxy::y#3, gotoxy::@3/gotoxy::y#0 ) + gotoxy::x#3 = phi( gotoxy/gotoxy::x#5, gotoxy::@3/gotoxy::x#6 ) + gotoxy::$2 = gotoxy::x#3 >= $28 + gotoxy::$3 = ! gotoxy::$2 + if(gotoxy::$3) goto gotoxy::@2 + to:gotoxy::@4 +gotoxy::@3: scope:[gotoxy] from gotoxy + gotoxy::x#6 = phi( gotoxy/gotoxy::x#5 ) + gotoxy::y#0 = 0 + to:gotoxy::@1 +gotoxy::@2: scope:[gotoxy] from gotoxy::@1 gotoxy::@4 + gotoxy::y#4 = phi( gotoxy::@1/gotoxy::y#5, gotoxy::@4/gotoxy::y#6 ) + gotoxy::x#4 = phi( gotoxy::@1/gotoxy::x#3, gotoxy::@4/gotoxy::x#0 ) + conio_cursor_x = gotoxy::x#4 + conio_cursor_y = gotoxy::y#4 + gotoxy::$7 = (unsigned int)gotoxy::y#4 + gotoxy::line_offset#0 = gotoxy::$7 * $28 + gotoxy::$5 = CONIO_SCREEN_TEXT + gotoxy::line_offset#0 + conio_line_text = gotoxy::$5 + gotoxy::$6 = CONIO_SCREEN_COLORS + gotoxy::line_offset#0 + conio_line_color = gotoxy::$6 + to:gotoxy::@return +gotoxy::@4: scope:[gotoxy] from gotoxy::@1 + gotoxy::y#6 = phi( gotoxy::@1/gotoxy::y#5 ) + gotoxy::x#0 = 0 + to:gotoxy::@2 +gotoxy::@return: scope:[gotoxy] from gotoxy::@2 + return + to:@return + +__stackcall void cputc(char c) +cputc: scope:[cputc] from + cputc::c#0 = stackidx(char,cputc::OFFSET_STACK_C) + cputc::$0 = cputc::c#0 == ' +' + if(cputc::$0) goto cputc::@1 + to:cputc::@2 +cputc::@1: scope:[cputc] from cputc + call cputln + to:cputc::@4 +cputc::@4: scope:[cputc] from cputc::@1 + to:cputc::@return +cputc::@2: scope:[cputc] from cputc + cputc::c#1 = phi( cputc/cputc::c#0 ) + conio_line_text[conio_cursor_x] = cputc::c#1 + conio_line_color[conio_cursor_x] = conio_textcolor + conio_cursor_x = ++ conio_cursor_x + cputc::$1 = conio_cursor_x == $28 + cputc::$2 = ! cputc::$1 + if(cputc::$2) goto cputc::@return + to:cputc::@3 +cputc::@3: scope:[cputc] from cputc::@2 + call cputln + to:cputc::@5 +cputc::@5: scope:[cputc] from cputc::@3 + to:cputc::@return +cputc::@return: scope:[cputc] from cputc::@2 cputc::@4 cputc::@5 + return + to:@return + +void cputln() +cputln: scope:[cputln] from cputc::@1 cputc::@3 + conio_line_text = conio_line_text + $28 + conio_line_color = conio_line_color + $28 + conio_cursor_x = 0 + conio_cursor_y = ++ conio_cursor_y + call cscroll + to:cputln::@1 +cputln::@1: scope:[cputln] from cputln + to:cputln::@return +cputln::@return: scope:[cputln] from cputln::@1 + return + to:@return + +void cscroll() +cscroll: scope:[cscroll] from cputln + cscroll::$0 = conio_cursor_y == $19 + cscroll::$1 = ! cscroll::$0 + if(cscroll::$1) goto cscroll::@return + to:cscroll::@1 +cscroll::@1: scope:[cscroll] from cscroll + cscroll::$7 = 0 != conio_scroll_enable + if(cscroll::$7) goto cscroll::@3 + to:cscroll::@2 +cscroll::@3: scope:[cscroll] from cscroll::@1 + memcpy::destination#0 = (void *)CONIO_SCREEN_TEXT + memcpy::source#0 = (void *)CONIO_SCREEN_TEXT+$28 + memcpy::num#0 = $19*$28-$28 + call memcpy + memcpy::return#2 = memcpy::return#1 + to:cscroll::@4 +cscroll::@4: scope:[cscroll] from cscroll::@3 + memcpy::destination#1 = (void *)CONIO_SCREEN_COLORS + memcpy::source#1 = (void *)CONIO_SCREEN_COLORS+$28 + memcpy::num#1 = $19*$28-$28 + call memcpy + memcpy::return#3 = memcpy::return#1 + to:cscroll::@5 +cscroll::@5: scope:[cscroll] from cscroll::@4 + memset::str#0 = (void *)CONIO_SCREEN_TEXT+$19*$28-$28 + memset::c#0 = ' ' + memset::num#0 = $28 + call memset + memset::return#2 = memset::return#1 + to:cscroll::@6 +cscroll::@6: scope:[cscroll] from cscroll::@5 + memset::str#1 = (void *)CONIO_SCREEN_COLORS+$19*$28-$28 + memset::c#1 = conio_textcolor + memset::num#1 = $28 + call memset + memset::return#3 = memset::return#1 + to:cscroll::@7 +cscroll::@7: scope:[cscroll] from cscroll::@6 + conio_line_text = conio_line_text - $28 + conio_line_color = conio_line_color - $28 + conio_cursor_y = -- conio_cursor_y + to:cscroll::@return +cscroll::@2: scope:[cscroll] from cscroll::@1 + gotoxy::x#1 = 0 + gotoxy::y#1 = 0 + call gotoxy + to:cscroll::@8 +cscroll::@8: scope:[cscroll] from cscroll::@2 + to:cscroll::@return +cscroll::@return: scope:[cscroll] from cscroll cscroll::@7 cscroll::@8 + return + to:@return + +void conio_c64_init() +conio_c64_init: scope:[conio_c64_init] from __start::__init1 + conio_c64_init::line#0 = *conio_c64_init::BASIC_CURSOR_LINE + conio_c64_init::$0 = conio_c64_init::line#0 >= $19 + conio_c64_init::$1 = ! conio_c64_init::$0 + if(conio_c64_init::$1) goto conio_c64_init::@1 + to:conio_c64_init::@2 +conio_c64_init::@1: scope:[conio_c64_init] from conio_c64_init conio_c64_init::@2 + conio_c64_init::line#2 = phi( conio_c64_init/conio_c64_init::line#0, conio_c64_init::@2/conio_c64_init::line#1 ) + gotoxy::x#2 = 0 + gotoxy::y#2 = conio_c64_init::line#2 + call gotoxy + to:conio_c64_init::@3 +conio_c64_init::@3: scope:[conio_c64_init] from conio_c64_init::@1 + to:conio_c64_init::@return +conio_c64_init::@2: scope:[conio_c64_init] from conio_c64_init + conio_c64_init::line#1 = $19-1 + to:conio_c64_init::@1 +conio_c64_init::@return: scope:[conio_c64_init] from conio_c64_init::@3 + return + to:@return + +void printf_str(void (*putc)(char) , const char *s) +printf_str: scope:[printf_str] from main::@1 main::@3 main::@5 main::@7 main::@9 printf_string::@2 + printf_str::putc#8 = phi( main::@1/printf_str::putc#1, main::@3/printf_str::putc#2, main::@5/printf_str::putc#3, main::@7/printf_str::putc#4, main::@9/printf_str::putc#5, printf_string::@2/printf_str::putc#0 ) + printf_str::s#8 = phi( main::@1/printf_str::s#2, main::@3/printf_str::s#3, main::@5/printf_str::s#4, main::@7/printf_str::s#5, main::@9/printf_str::s#6, printf_string::@2/printf_str::s#1 ) + printf_str::c#0 = 0 + to:printf_str::@1 +printf_str::@1: scope:[printf_str] from printf_str printf_str::@2 + printf_str::putc#7 = phi( printf_str/printf_str::putc#8, printf_str::@2/printf_str::putc#6 ) + printf_str::s#7 = phi( printf_str/printf_str::s#8, printf_str::@2/printf_str::s#9 ) + printf_str::c#1 = *printf_str::s#7 + printf_str::$0 = printf_str::c#1 + printf_str::s#0 = ++ printf_str::s#7 + printf_str::$2 = 0 != printf_str::$0 + if(printf_str::$2) goto printf_str::@2 + to:printf_str::@return +printf_str::@2: scope:[printf_str] from printf_str::@1 + printf_str::s#9 = phi( printf_str::@1/printf_str::s#0 ) + printf_str::putc#6 = phi( printf_str::@1/printf_str::putc#7 ) + printf_str::c#2 = phi( printf_str::@1/printf_str::c#1 ) + stackpush(char) = printf_str::c#2 + callexecute *printf_str::putc#6 + sideeffect stackpullbytes(1) + to:printf_str::@1 +printf_str::@return: scope:[printf_str] from printf_str::@1 + return + to:@return + +void printf_padding(void (*putc)(char) , char pad , char length) +printf_padding: scope:[printf_padding] from printf_string::@5 printf_string::@6 + printf_padding::putc#4 = phi( printf_string::@5/printf_padding::putc#0, printf_string::@6/printf_padding::putc#1 ) + printf_padding::pad#4 = phi( printf_string::@5/printf_padding::pad#0, printf_string::@6/printf_padding::pad#1 ) + printf_padding::length#3 = phi( printf_string::@5/printf_padding::length#0, printf_string::@6/printf_padding::length#1 ) + printf_padding::i#0 = 0 + to:printf_padding::@1 +printf_padding::@1: scope:[printf_padding] from printf_padding printf_padding::@3 + printf_padding::putc#3 = phi( printf_padding/printf_padding::putc#4, printf_padding::@3/printf_padding::putc#5 ) + printf_padding::pad#3 = phi( printf_padding/printf_padding::pad#4, printf_padding::@3/printf_padding::pad#5 ) + printf_padding::length#2 = phi( printf_padding/printf_padding::length#3, printf_padding::@3/printf_padding::length#4 ) + printf_padding::i#2 = phi( printf_padding/printf_padding::i#0, printf_padding::@3/printf_padding::i#1 ) + printf_padding::$0 = printf_padding::i#2 < printf_padding::length#2 + if(printf_padding::$0) goto printf_padding::@2 + to:printf_padding::@return +printf_padding::@2: scope:[printf_padding] from printf_padding::@1 + printf_padding::length#5 = phi( printf_padding::@1/printf_padding::length#2 ) + printf_padding::i#4 = phi( printf_padding::@1/printf_padding::i#2 ) + printf_padding::putc#2 = phi( printf_padding::@1/printf_padding::putc#3 ) + printf_padding::pad#2 = phi( printf_padding::@1/printf_padding::pad#3 ) + stackpush(char) = printf_padding::pad#2 + callexecute *printf_padding::putc#2 + sideeffect stackpullbytes(1) + to:printf_padding::@3 +printf_padding::@3: scope:[printf_padding] from printf_padding::@2 + printf_padding::putc#5 = phi( printf_padding::@2/printf_padding::putc#2 ) + printf_padding::pad#5 = phi( printf_padding::@2/printf_padding::pad#2 ) + printf_padding::length#4 = phi( printf_padding::@2/printf_padding::length#5 ) + printf_padding::i#3 = phi( printf_padding::@2/printf_padding::i#4 ) + printf_padding::i#1 = ++ printf_padding::i#3 + to:printf_padding::@1 +printf_padding::@return: scope:[printf_padding] from printf_padding::@1 + return + to:@return + +void printf_string(void (*putc)(char) , char *str , char format_min_length , char format_justify_left) +printf_string: scope:[printf_string] from main::@4 main::@6 main::@8 + printf_string::putc#9 = phi( main::@4/printf_string::putc#0, main::@6/printf_string::putc#1, main::@8/printf_string::putc#2 ) + printf_string::str#5 = phi( main::@4/printf_string::str#0, main::@6/printf_string::str#1, main::@8/printf_string::str#2 ) + printf_string::format_justify_left#5 = phi( main::@4/printf_string::format_justify_left#0, main::@6/printf_string::format_justify_left#1, main::@8/printf_string::format_justify_left#2 ) + printf_string::format_min_length#3 = phi( main::@4/printf_string::format_min_length#0, main::@6/printf_string::format_min_length#1, main::@8/printf_string::format_min_length#2 ) + printf_string::padding#0 = 0 + printf_string::$14 = 0 != printf_string::format_min_length#3 + printf_string::$0 = ! printf_string::$14 + if(printf_string::$0) goto printf_string::@1 + to:printf_string::@3 +printf_string::@1: scope:[printf_string] from printf_string printf_string::@4 printf_string::@7 + printf_string::str#6 = phi( printf_string/printf_string::str#5, printf_string::@4/printf_string::str#8, printf_string::@7/printf_string::str#9 ) + printf_string::putc#6 = phi( printf_string/printf_string::putc#9, printf_string::@4/printf_string::putc#10, printf_string::@7/printf_string::putc#11 ) + printf_string::padding#3 = phi( printf_string/printf_string::padding#0, printf_string::@4/printf_string::padding#2, printf_string::@7/printf_string::padding#1 ) + printf_string::format_justify_left#3 = phi( printf_string/printf_string::format_justify_left#5, printf_string::@4/printf_string::format_justify_left#6, printf_string::@7/printf_string::format_justify_left#7 ) + printf_string::$15 = 0 != printf_string::format_justify_left#3 + printf_string::$1 = ! printf_string::$15 + printf_string::$2 = printf_string::$1 && printf_string::padding#3 + printf_string::$3 = ! printf_string::$2 + if(printf_string::$3) goto printf_string::@2 + to:printf_string::@5 +printf_string::@3: scope:[printf_string] from printf_string + printf_string::putc#12 = phi( printf_string/printf_string::putc#9 ) + printf_string::format_justify_left#9 = phi( printf_string/printf_string::format_justify_left#5 ) + printf_string::format_min_length#5 = phi( printf_string/printf_string::format_min_length#3 ) + printf_string::str#3 = phi( printf_string/printf_string::str#5 ) + strlen::str#1 = printf_string::str#3 + call strlen + strlen::return#2 = strlen::return#1 + to:printf_string::@7 +printf_string::@7: scope:[printf_string] from printf_string::@3 + printf_string::str#9 = phi( printf_string::@3/printf_string::str#3 ) + printf_string::putc#11 = phi( printf_string::@3/printf_string::putc#12 ) + printf_string::format_justify_left#7 = phi( printf_string::@3/printf_string::format_justify_left#9 ) + printf_string::format_min_length#4 = phi( printf_string::@3/printf_string::format_min_length#5 ) + strlen::return#4 = phi( printf_string::@3/strlen::return#2 ) + printf_string::$9 = strlen::return#4 + printf_string::len#0 = (signed char)printf_string::$9 + printf_string::$13 = (signed char)printf_string::format_min_length#4 + printf_string::$10 = printf_string::$13 - printf_string::len#0 + printf_string::padding#1 = printf_string::$10 + printf_string::$11 = printf_string::padding#1 < 0 + printf_string::$12 = ! printf_string::$11 + if(printf_string::$12) goto printf_string::@1 + to:printf_string::@4 +printf_string::@4: scope:[printf_string] from printf_string::@7 + printf_string::str#8 = phi( printf_string::@7/printf_string::str#9 ) + printf_string::putc#10 = phi( printf_string::@7/printf_string::putc#11 ) + printf_string::format_justify_left#6 = phi( printf_string::@7/printf_string::format_justify_left#7 ) + printf_string::padding#2 = 0 + to:printf_string::@1 +printf_string::@2: scope:[printf_string] from printf_string::@1 printf_string::@9 + printf_string::padding#7 = phi( printf_string::@1/printf_string::padding#3, printf_string::@9/printf_string::padding#8 ) + printf_string::format_justify_left#8 = phi( printf_string::@1/printf_string::format_justify_left#3, printf_string::@9/printf_string::format_justify_left#10 ) + printf_string::str#4 = phi( printf_string::@1/printf_string::str#6, printf_string::@9/printf_string::str#7 ) + printf_string::putc#3 = phi( printf_string::@1/printf_string::putc#6, printf_string::@9/printf_string::putc#7 ) + printf_str::putc#0 = printf_string::putc#3 + printf_str::s#1 = printf_string::str#4 + call printf_str + to:printf_string::@8 +printf_string::@8: scope:[printf_string] from printf_string::@2 + printf_string::putc#8 = phi( printf_string::@2/printf_string::putc#3 ) + printf_string::padding#4 = phi( printf_string::@2/printf_string::padding#7 ) + printf_string::format_justify_left#4 = phi( printf_string::@2/printf_string::format_justify_left#8 ) + printf_string::$6 = printf_string::format_justify_left#4 && printf_string::padding#4 + printf_string::$7 = ! printf_string::$6 + if(printf_string::$7) goto printf_string::@return + to:printf_string::@6 +printf_string::@5: scope:[printf_string] from printf_string::@1 + printf_string::format_justify_left#11 = phi( printf_string::@1/printf_string::format_justify_left#3 ) + printf_string::str#10 = phi( printf_string::@1/printf_string::str#6 ) + printf_string::padding#5 = phi( printf_string::@1/printf_string::padding#3 ) + printf_string::putc#4 = phi( printf_string::@1/printf_string::putc#6 ) + printf_padding::putc#0 = printf_string::putc#4 + printf_padding::pad#0 = ' ' + printf_padding::length#0 = (char)printf_string::padding#5 + call printf_padding + to:printf_string::@9 +printf_string::@9: scope:[printf_string] from printf_string::@5 + printf_string::padding#8 = phi( printf_string::@5/printf_string::padding#5 ) + printf_string::format_justify_left#10 = phi( printf_string::@5/printf_string::format_justify_left#11 ) + printf_string::str#7 = phi( printf_string::@5/printf_string::str#10 ) + printf_string::putc#7 = phi( printf_string::@5/printf_string::putc#4 ) + to:printf_string::@2 +printf_string::@6: scope:[printf_string] from printf_string::@8 + printf_string::padding#6 = phi( printf_string::@8/printf_string::padding#4 ) + printf_string::putc#5 = phi( printf_string::@8/printf_string::putc#8 ) + printf_padding::putc#1 = printf_string::putc#5 + printf_padding::pad#1 = ' ' + printf_padding::length#1 = (char)printf_string::padding#6 + call printf_padding + to:printf_string::@10 +printf_string::@10: scope:[printf_string] from printf_string::@6 + to:printf_string::@return +printf_string::@return: scope:[printf_string] from printf_string::@10 printf_string::@8 + return + to:@return + +void snprintf_init(char *s , unsigned int n) +snprintf_init: scope:[snprintf_init] from main main::@2 + snprintf_init::s#2 = phi( main/snprintf_init::s#0, main::@2/snprintf_init::s#1 ) + snprintf_init::n#2 = phi( main/snprintf_init::n#0, main::@2/snprintf_init::n#1 ) + __snprintf_capacity = snprintf_init::n#2 + __snprintf_size = 0 + __snprintf_buffer = snprintf_init::s#2 + to:snprintf_init::@return +snprintf_init::@return: scope:[snprintf_init] from snprintf_init + return + to:@return + +__stackcall void snputc(char c) +snputc: scope:[snputc] from + snputc::c#0 = stackidx(char,snputc::OFFSET_STACK_C) + __snprintf_size = ++ __snprintf_size + snputc::$0 = __snprintf_size > __snprintf_capacity + snputc::$1 = ! snputc::$0 + if(snputc::$1) goto snputc::@1 + to:snputc::@return +snputc::@1: scope:[snputc] from snputc + snputc::c#3 = phi( snputc/snputc::c#0 ) + snputc::$2 = __snprintf_size == __snprintf_capacity + snputc::$3 = ! snputc::$2 + if(snputc::$3) goto snputc::@2 + to:snputc::@3 +snputc::@return: scope:[snputc] from snputc snputc::@2 + return + to:@return +snputc::@2: scope:[snputc] from snputc::@1 snputc::@3 + snputc::c#2 = phi( snputc::@1/snputc::c#3, snputc::@3/snputc::c#1 ) + *__snprintf_buffer = snputc::c#2 + __snprintf_buffer = ++ __snprintf_buffer + to:snputc::@return +snputc::@3: scope:[snputc] from snputc::@1 + snputc::c#1 = 0 + to:snputc::@2 + +void main() +main: scope:[main] from __start::@1 + snprintf_init::s#0 = BUF1 + snprintf_init::n#0 = $14 + call snprintf_init + to:main::@1 +main::@1: scope:[main] from main + printf_str::putc#1 = &snputc + printf_str::s#2 = main::s + call printf_str + to:main::@2 +main::@2: scope:[main] from main::@1 + stackpush(char) = 0 + callexecute snputc + sideeffect stackpullbytes(1) + snprintf_init::s#1 = BUF2 + snprintf_init::n#1 = $14 + call snprintf_init + to:main::@3 +main::@3: scope:[main] from main::@2 + printf_str::putc#2 = &snputc + printf_str::s#3 = main::s1 + call printf_str + to:main::@4 +main::@4: scope:[main] from main::@3 + printf_string::putc#0 = &snputc + printf_string::str#0 = main::str + printf_string::format_min_length#0 = 0 + printf_string::format_justify_left#0 = 0 + call printf_string + to:main::@5 +main::@5: scope:[main] from main::@4 + stackpush(char) = '!' + callexecute snputc + sideeffect stackpullbytes(1) + stackpush(char) = 0 + callexecute snputc + sideeffect stackpullbytes(1) + printf_str::putc#3 = &cputc + printf_str::s#4 = main::s2 + call printf_str + to:main::@6 +main::@6: scope:[main] from main::@5 + printf_string::putc#1 = &cputc + printf_string::str#1 = BUF1 + printf_string::format_min_length#1 = 0 + printf_string::format_justify_left#1 = 0 + call printf_string + to:main::@7 +main::@7: scope:[main] from main::@6 + printf_str::putc#4 = &cputc + printf_str::s#5 = main::s3 + call printf_str + to:main::@8 +main::@8: scope:[main] from main::@7 + printf_string::putc#2 = &cputc + printf_string::str#2 = BUF2 + printf_string::format_min_length#2 = 0 + printf_string::format_justify_left#2 = 0 + call printf_string + to:main::@9 +main::@9: scope:[main] from main::@8 + printf_str::putc#5 = &cputc + printf_str::s#6 = main::s4 + call printf_str + to:main::@10 +main::@10: scope:[main] from main::@9 + to:main::@return +main::@return: scope:[main] from main::@10 + return + to:@return + +void __start() +__start: scope:[__start] from + to:__start::__init1 +__start::__init1: scope:[__start] from __start + conio_cursor_x = 0 + conio_cursor_y = 0 + conio_line_text = CONIO_SCREEN_TEXT + conio_line_color = CONIO_SCREEN_COLORS + conio_textcolor = CONIO_TEXTCOLOR_DEFAULT + conio_scroll_enable = 1 + __snprintf_capacity = 0 + __snprintf_size = 0 + __snprintf_buffer = (char *) 0 + call conio_c64_init + to:__start::@2 +__start::@2: scope:[__start] from __start::__init1 + to:__start::@1 +__start::@1: scope:[__start] from __start::@2 + call main + to:__start::@3 +__start::@3: scope:[__start] from __start::@1 + to:__start::@return +__start::@return: scope:[__start] from __start::@3 + return + to:@return + +SYMBOL TABLE SSA +__constant char BUF1[$14] = { fill( $14, 0) } +__constant char BUF2[$14] = { fill( $14, 0) } +__constant char * const COLORRAM = (char *)$d800 +__constant char * const CONIO_SCREEN_COLORS = COLORRAM +__constant char * const CONIO_SCREEN_TEXT = DEFAULT_SCREEN +__constant const char CONIO_TEXTCOLOR_DEFAULT = LIGHT_BLUE +__constant char * const DEFAULT_SCREEN = (char *)$400 +__constant const char LIGHT_BLUE = $e +__constant char RADIX::BINARY = 2 +__constant char RADIX::DECIMAL = $a +__constant char RADIX::HEXADECIMAL = $10 +__constant char RADIX::OCTAL = 8 +__constant unsigned int STACK_BASE = $103 +__loadstore char *__snprintf_buffer +__loadstore volatile unsigned int __snprintf_capacity +__loadstore volatile unsigned int __snprintf_size +void __start() +void conio_c64_init() +bool conio_c64_init::$0 +bool conio_c64_init::$1 +__constant char * const conio_c64_init::BASIC_CURSOR_LINE = (char *)$d6 +char conio_c64_init::line +char conio_c64_init::line#0 +char conio_c64_init::line#1 +char conio_c64_init::line#2 +__loadstore char conio_cursor_x +__loadstore char conio_cursor_y +__loadstore char *conio_line_color +__loadstore char *conio_line_text +__loadstore char conio_scroll_enable +__loadstore char conio_textcolor +__stackcall void cputc(char c) +bool cputc::$0 +bool cputc::$1 +bool cputc::$2 +__constant char cputc::OFFSET_STACK_C = 0 +char cputc::c +char cputc::c#0 +char cputc::c#1 +void cputln() +void cscroll() +bool cscroll::$0 +bool cscroll::$1 +bool cscroll::$7 +void gotoxy(char x , char y) +bool gotoxy::$0 +bool gotoxy::$1 +bool gotoxy::$2 +bool gotoxy::$3 +char *gotoxy::$5 +char *gotoxy::$6 +unsigned int gotoxy::$7 +unsigned int gotoxy::line_offset +unsigned int gotoxy::line_offset#0 +char gotoxy::x +char gotoxy::x#0 +char gotoxy::x#1 +char gotoxy::x#2 +char gotoxy::x#3 +char gotoxy::x#4 +char gotoxy::x#5 +char gotoxy::x#6 +char gotoxy::y +char gotoxy::y#0 +char gotoxy::y#1 +char gotoxy::y#2 +char gotoxy::y#3 +char gotoxy::y#4 +char gotoxy::y#5 +char gotoxy::y#6 +void main() +__constant char main::s[$d] = "hello world!" +__constant char main::s1[7] = "hello " +__constant char main::s2[2] = "-" +__constant char main::s3[4] = "- -" +__constant char main::s4[2] = "-" +__constant char main::str[6] = "world" +void * memcpy(void *destination , void *source , unsigned int num) +bool memcpy::$1 +char *memcpy::$2 +void *memcpy::destination +void *memcpy::destination#0 +void *memcpy::destination#1 +void *memcpy::destination#2 +void *memcpy::destination#3 +void *memcpy::destination#4 +void *memcpy::destination#5 +char *memcpy::dst +char *memcpy::dst#0 +char *memcpy::dst#1 +char *memcpy::dst#2 +char *memcpy::dst#3 +unsigned int memcpy::num +unsigned int memcpy::num#0 +unsigned int memcpy::num#1 +unsigned int memcpy::num#2 +void *memcpy::return +void *memcpy::return#0 +void *memcpy::return#1 +void *memcpy::return#2 +void *memcpy::return#3 +void *memcpy::return#4 +void *memcpy::source +void *memcpy::source#0 +void *memcpy::source#1 +void *memcpy::source#2 +char *memcpy::src +char *memcpy::src#0 +char *memcpy::src#1 +char *memcpy::src#2 +char *memcpy::src#3 +char *memcpy::src_end +char *memcpy::src_end#0 +char *memcpy::src_end#1 +char *memcpy::src_end#2 +void * memset(void *str , char c , unsigned int num) +bool memset::$0 +bool memset::$1 +bool memset::$3 +char *memset::$4 +char memset::c +char memset::c#0 +char memset::c#1 +char memset::c#2 +char memset::c#3 +char memset::c#4 +char memset::c#5 +char *memset::dst +char *memset::dst#0 +char *memset::dst#1 +char *memset::dst#2 +char *memset::dst#3 +char *memset::end +char *memset::end#0 +char *memset::end#1 +char *memset::end#2 +unsigned int memset::num +unsigned int memset::num#0 +unsigned int memset::num#1 +unsigned int memset::num#2 +unsigned int memset::num#3 +void *memset::return +void *memset::return#0 +void *memset::return#1 +void *memset::return#2 +void *memset::return#3 +void *memset::return#4 +void *memset::str +void *memset::str#0 +void *memset::str#1 +void *memset::str#2 +void *memset::str#3 +void *memset::str#4 +void *memset::str#5 +void *memset::str#6 +void printf_padding(void (*putc)(char) , char pad , char length) +bool printf_padding::$0 +char printf_padding::i +char printf_padding::i#0 +char printf_padding::i#1 +char printf_padding::i#2 +char printf_padding::i#3 +char printf_padding::i#4 +char printf_padding::length +char printf_padding::length#0 +char printf_padding::length#1 +char printf_padding::length#2 +char printf_padding::length#3 +char printf_padding::length#4 +char printf_padding::length#5 +char printf_padding::pad +char printf_padding::pad#0 +char printf_padding::pad#1 +char printf_padding::pad#2 +char printf_padding::pad#3 +char printf_padding::pad#4 +char printf_padding::pad#5 +void (*printf_padding::putc)(char) +void (*printf_padding::putc#0)(char) +void (*printf_padding::putc#1)(char) +void (*printf_padding::putc#2)(char) +void (*printf_padding::putc#3)(char) +void (*printf_padding::putc#4)(char) +void (*printf_padding::putc#5)(char) +void printf_str(void (*putc)(char) , const char *s) +char printf_str::$0 +bool printf_str::$2 +char printf_str::c +char printf_str::c#0 +char printf_str::c#1 +char printf_str::c#2 +void (*printf_str::putc)(char) +void (*printf_str::putc#0)(char) +void (*printf_str::putc#1)(char) +void (*printf_str::putc#2)(char) +void (*printf_str::putc#3)(char) +void (*printf_str::putc#4)(char) +void (*printf_str::putc#5)(char) +void (*printf_str::putc#6)(char) +void (*printf_str::putc#7)(char) +void (*printf_str::putc#8)(char) +const char *printf_str::s +const char *printf_str::s#0 +const char *printf_str::s#1 +const char *printf_str::s#2 +const char *printf_str::s#3 +const char *printf_str::s#4 +const char *printf_str::s#5 +const char *printf_str::s#6 +const char *printf_str::s#7 +const char *printf_str::s#8 +const char *printf_str::s#9 +void printf_string(void (*putc)(char) , char *str , char format_min_length , char format_justify_left) +bool printf_string::$0 +bool printf_string::$1 +signed char printf_string::$10 +bool printf_string::$11 +bool printf_string::$12 +signed char printf_string::$13 +bool printf_string::$14 +bool printf_string::$15 +bool printf_string::$2 +bool printf_string::$3 +bool printf_string::$6 +bool printf_string::$7 +unsigned int printf_string::$9 +struct printf_format_string printf_string::format +char printf_string::format_justify_left +char printf_string::format_justify_left#0 +char printf_string::format_justify_left#1 +char printf_string::format_justify_left#10 +char printf_string::format_justify_left#11 +char printf_string::format_justify_left#2 +char printf_string::format_justify_left#3 +char printf_string::format_justify_left#4 +char printf_string::format_justify_left#5 +char printf_string::format_justify_left#6 +char printf_string::format_justify_left#7 +char printf_string::format_justify_left#8 +char printf_string::format_justify_left#9 +char printf_string::format_min_length +char printf_string::format_min_length#0 +char printf_string::format_min_length#1 +char printf_string::format_min_length#2 +char printf_string::format_min_length#3 +char printf_string::format_min_length#4 +char printf_string::format_min_length#5 +signed char printf_string::len +signed char printf_string::len#0 +signed char printf_string::padding +signed char printf_string::padding#0 +signed char printf_string::padding#1 +signed char printf_string::padding#2 +signed char printf_string::padding#3 +signed char printf_string::padding#4 +signed char printf_string::padding#5 +signed char printf_string::padding#6 +signed char printf_string::padding#7 +signed char printf_string::padding#8 +void (*printf_string::putc)(char) +void (*printf_string::putc#0)(char) +void (*printf_string::putc#1)(char) +void (*printf_string::putc#10)(char) +void (*printf_string::putc#11)(char) +void (*printf_string::putc#12)(char) +void (*printf_string::putc#2)(char) +void (*printf_string::putc#3)(char) +void (*printf_string::putc#4)(char) +void (*printf_string::putc#5)(char) +void (*printf_string::putc#6)(char) +void (*printf_string::putc#7)(char) +void (*printf_string::putc#8)(char) +void (*printf_string::putc#9)(char) +char *printf_string::str +char *printf_string::str#0 +char *printf_string::str#1 +char *printf_string::str#10 +char *printf_string::str#2 +char *printf_string::str#3 +char *printf_string::str#4 +char *printf_string::str#5 +char *printf_string::str#6 +char *printf_string::str#7 +char *printf_string::str#8 +char *printf_string::str#9 +void snprintf_init(char *s , unsigned int n) +unsigned int snprintf_init::n +unsigned int snprintf_init::n#0 +unsigned int snprintf_init::n#1 +unsigned int snprintf_init::n#2 +char *snprintf_init::s +char *snprintf_init::s#0 +char *snprintf_init::s#1 +char *snprintf_init::s#2 +__stackcall void snputc(char c) +bool snputc::$0 +bool snputc::$1 +bool snputc::$2 +bool snputc::$3 +__constant char snputc::OFFSET_STACK_C = 0 +char snputc::c +char snputc::c#0 +char snputc::c#1 +char snputc::c#2 +char snputc::c#3 +unsigned int strlen(char *str) +bool strlen::$0 +unsigned int strlen::len +unsigned int strlen::len#0 +unsigned int strlen::len#1 +unsigned int strlen::len#2 +unsigned int strlen::len#3 +unsigned int strlen::len#4 +unsigned int strlen::return +unsigned int strlen::return#0 +unsigned int strlen::return#1 +unsigned int strlen::return#2 +unsigned int strlen::return#3 +unsigned int strlen::return#4 +char *strlen::str +char *strlen::str#0 +char *strlen::str#1 +char *strlen::str#2 +char *strlen::str#3 +char *strlen::str#4 + +Adding number conversion cast (unumber) 0 in memset::$0 = memset::num#2 > 0 +Adding number conversion cast (unumber) 0 in strlen::$0 = 0 != *strlen::str#2 +Adding number conversion cast (unumber) $19 in gotoxy::$0 = gotoxy::y#3 > $19 +Adding number conversion cast (unumber) $28 in gotoxy::$2 = gotoxy::x#3 >= $28 +Adding number conversion cast (unumber) 0 in gotoxy::y#0 = 0 +Adding number conversion cast (unumber) $28 in gotoxy::line_offset#0 = gotoxy::$7 * $28 +Adding number conversion cast (unumber) 0 in gotoxy::x#0 = 0 +Adding number conversion cast (unumber) $28 in cputc::$1 = conio_cursor_x == $28 +Adding number conversion cast (unumber) $28 in conio_line_text = conio_line_text + $28 +Adding number conversion cast (unumber) $28 in conio_line_color = conio_line_color + $28 +Adding number conversion cast (unumber) 0 in conio_cursor_x = 0 +Adding number conversion cast (unumber) $19 in cscroll::$0 = conio_cursor_y == $19 +Adding number conversion cast (unumber) 0 in cscroll::$7 = 0 != conio_scroll_enable +Adding number conversion cast (unumber) $28 in memcpy::source#0 = (void *)CONIO_SCREEN_TEXT+$28 +Adding number conversion cast (unumber) $19*$28-$28 in memcpy::num#0 = $19*$28-$28 +Adding number conversion cast (unumber) $28 in memcpy::source#1 = (void *)CONIO_SCREEN_COLORS+$28 +Adding number conversion cast (unumber) $19*$28-$28 in memcpy::num#1 = $19*$28-$28 +Adding number conversion cast (unumber) $28 in memset::str#0 = (void *)CONIO_SCREEN_TEXT+$19*$28-$28 +Adding number conversion cast (unumber) $19*$28 in memset::str#0 = (void *)CONIO_SCREEN_TEXT+$19*$28-(unumber)$28 +Adding number conversion cast (unumber) $28 in memset::num#0 = $28 +Adding number conversion cast (unumber) $28 in memset::str#1 = (void *)CONIO_SCREEN_COLORS+$19*$28-$28 +Adding number conversion cast (unumber) $19*$28 in memset::str#1 = (void *)CONIO_SCREEN_COLORS+$19*$28-(unumber)$28 +Adding number conversion cast (unumber) $28 in memset::num#1 = $28 +Adding number conversion cast (unumber) $28 in conio_line_text = conio_line_text - $28 +Adding number conversion cast (unumber) $28 in conio_line_color = conio_line_color - $28 +Adding number conversion cast (unumber) 0 in gotoxy::x#1 = 0 +Adding number conversion cast (unumber) 0 in gotoxy::y#1 = 0 +Adding number conversion cast (unumber) $19 in conio_c64_init::$0 = conio_c64_init::line#0 >= $19 +Adding number conversion cast (unumber) 0 in gotoxy::x#2 = 0 +Adding number conversion cast (unumber) $19-1 in conio_c64_init::line#1 = $19-1 +Adding number conversion cast (unumber) 0 in printf_str::$2 = 0 != printf_str::$0 +Adding number conversion cast (unumber) 0 in printf_string::$14 = 0 != printf_string::format_min_length#3 +Adding number conversion cast (unumber) 0 in printf_string::$15 = 0 != printf_string::format_justify_left#3 +Adding number conversion cast (snumber) 0 in printf_string::$11 = printf_string::padding#1 < 0 +Adding number conversion cast (snumber) 0 in printf_string::padding#2 = 0 +Adding number conversion cast (unumber) 0 in __snprintf_size = 0 +Adding number conversion cast (unumber) 0 in snputc::c#1 = 0 +Adding number conversion cast (unumber) $14 in snprintf_init::n#0 = $14 +Adding number conversion cast (unumber) $14 in snprintf_init::n#1 = $14 +Successful SSA optimization PassNAddNumberTypeConversions +Inlining cast memcpy::src#0 = (char *)memcpy::source#2 +Inlining cast memcpy::dst#0 = (char *)memcpy::destination#2 +Inlining cast memset::dst#0 = (char *)memset::str#3 +Inlining cast gotoxy::y#0 = (unumber)0 +Inlining cast gotoxy::x#0 = (unumber)0 +Inlining cast conio_cursor_x = (unumber)0 +Inlining cast memcpy::num#0 = (unumber)$19*$28-$28 +Inlining cast memcpy::num#1 = (unumber)$19*$28-$28 +Inlining cast memset::num#0 = (unumber)$28 +Inlining cast memset::num#1 = (unumber)$28 +Inlining cast gotoxy::x#1 = (unumber)0 +Inlining cast gotoxy::y#1 = (unumber)0 +Inlining cast gotoxy::x#2 = (unumber)0 +Inlining cast conio_c64_init::line#1 = (unumber)$19-1 +Inlining cast printf_string::padding#2 = (snumber)0 +Inlining cast __snprintf_size = (unumber)0 +Inlining cast snputc::c#1 = (unumber)0 +Inlining cast snprintf_init::n#0 = (unumber)$14 +Inlining cast snprintf_init::n#1 = (unumber)$14 +Successful SSA optimization Pass2InlineCast +Simplifying constant pointer cast (char *) 55296 +Simplifying constant pointer cast (char *) 1024 +Simplifying constant pointer cast (char *) 214 +Simplifying constant integer cast 0 +Simplifying constant integer cast 0 +Simplifying constant integer cast $19 +Simplifying constant integer cast $28 +Simplifying constant integer cast 0 +Simplifying constant integer cast $28 +Simplifying constant integer cast 0 +Simplifying constant integer cast $28 +Simplifying constant integer cast $28 +Simplifying constant integer cast $28 +Simplifying constant integer cast 0 +Simplifying constant integer cast $19 +Simplifying constant integer cast 0 +Simplifying constant integer cast $28 +Simplifying constant integer cast $28 +Simplifying constant integer cast $28 +Simplifying constant integer cast $28 +Simplifying constant integer cast $28 +Simplifying constant integer cast $28 +Simplifying constant integer cast $28 +Simplifying constant integer cast $28 +Simplifying constant integer cast 0 +Simplifying constant integer cast 0 +Simplifying constant integer cast $19 +Simplifying constant integer cast 0 +Simplifying constant integer cast 0 +Simplifying constant integer cast 0 +Simplifying constant integer cast 0 +Simplifying constant integer cast 0 +Simplifying constant integer cast 0 +Simplifying constant integer cast 0 +Simplifying constant integer cast 0 +Simplifying constant integer cast $14 +Simplifying constant integer cast $14 +Successful SSA optimization PassNCastSimplification +Finalized unsigned number type (char) 0 +Finalized unsigned number type (char) 0 +Finalized unsigned number type (char) $19 +Finalized unsigned number type (char) $28 +Finalized unsigned number type (char) 0 +Finalized unsigned number type (char) $28 +Finalized unsigned number type (char) 0 +Finalized unsigned number type (char) $28 +Finalized unsigned number type (char) $28 +Finalized unsigned number type (char) $28 +Finalized unsigned number type (char) 0 +Finalized unsigned number type (char) $19 +Finalized unsigned number type (char) 0 +Finalized unsigned number type (char) $28 +Finalized unsigned number type (char) $28 +Finalized unsigned number type (char) $28 +Finalized unsigned number type (char) $28 +Finalized unsigned number type (char) $28 +Finalized unsigned number type (char) $28 +Finalized unsigned number type (char) $28 +Finalized unsigned number type (char) $28 +Finalized unsigned number type (char) 0 +Finalized unsigned number type (char) 0 +Finalized unsigned number type (char) $19 +Finalized unsigned number type (char) 0 +Finalized unsigned number type (char) 0 +Finalized unsigned number type (char) 0 +Finalized unsigned number type (char) 0 +Finalized signed number type (signed char) 0 +Finalized signed number type (signed char) 0 +Finalized unsigned number type (char) 0 +Finalized unsigned number type (char) 0 +Finalized unsigned number type (char) $14 +Finalized unsigned number type (char) $14 +Successful SSA optimization PassNFinalizeNumberTypeConversions +Inversing boolean not [19] memset::$1 = memset::num#2 <= 0 from [18] memset::$0 = memset::num#2 > 0 +Inversing boolean not [51] gotoxy::$1 = gotoxy::y#3 <= $19 from [50] gotoxy::$0 = gotoxy::y#3 > $19 +Inversing boolean not [55] gotoxy::$3 = gotoxy::x#3 < $28 from [54] gotoxy::$2 = gotoxy::x#3 >= $28 +Inversing boolean not [80] cputc::$2 = conio_cursor_x != $28 from [79] cputc::$1 = conio_cursor_x == $28 +Inversing boolean not [91] cscroll::$1 = conio_cursor_y != $19 from [90] cscroll::$0 = conio_cursor_y == $19 +Inversing boolean not [124] conio_c64_init::$1 = conio_c64_init::line#0 < $19 from [123] conio_c64_init::$0 = conio_c64_init::line#0 >= $19 +Inversing boolean not [160] printf_string::$0 = 0 == printf_string::format_min_length#3 from [159] printf_string::$14 = 0 != printf_string::format_min_length#3 +Inversing boolean not [164] printf_string::$1 = 0 == printf_string::format_justify_left#3 from [163] printf_string::$15 = 0 != printf_string::format_justify_left#3 +Inversing boolean not [179] printf_string::$12 = printf_string::padding#1 >= 0 from [178] printf_string::$11 = printf_string::padding#1 < 0 +Inversing boolean not [211] snputc::$1 = __snprintf_size <= __snprintf_capacity from [210] snputc::$0 = __snprintf_size > __snprintf_capacity +Inversing boolean not [215] snputc::$3 = __snprintf_size != __snprintf_capacity from [214] snputc::$2 = __snprintf_size == __snprintf_capacity +Successful SSA optimization Pass2UnaryNotSimplification +Alias candidate removed (volatile)conio_line_text = gotoxy::$5 +Alias candidate removed (volatile)conio_line_color = gotoxy::$6 +Alias memcpy::src#2 = memcpy::src#3 +Alias memcpy::dst#2 = memcpy::dst#3 +Alias memcpy::src_end#1 = memcpy::src_end#2 +Alias memcpy::destination#3 = memcpy::destination#5 memcpy::destination#4 memcpy::return#0 memcpy::return#4 memcpy::return#1 +Alias memset::return#0 = memset::str#2 memset::return#4 memset::return#1 +Alias memset::str#3 = memset::str#4 +Alias memset::num#2 = memset::num#3 +Alias memset::c#4 = memset::c#5 +Alias memset::c#2 = memset::c#3 +Alias memset::dst#2 = memset::dst#3 +Alias memset::end#1 = memset::end#2 +Alias memset::str#5 = memset::str#6 +Alias strlen::len#2 = strlen::len#4 strlen::len#3 strlen::return#0 strlen::return#3 strlen::return#1 +Alias strlen::str#2 = strlen::str#3 +Alias gotoxy::x#5 = gotoxy::x#6 +Alias gotoxy::y#5 = gotoxy::y#6 +Alias cputc::c#0 = cputc::c#1 +Alias printf_str::c#1 = printf_str::$0 printf_str::c#2 +Alias printf_str::putc#6 = printf_str::putc#7 +Alias printf_str::s#0 = printf_str::s#9 +Alias printf_padding::pad#2 = printf_padding::pad#3 printf_padding::pad#5 +Alias printf_padding::putc#2 = printf_padding::putc#3 printf_padding::putc#5 +Alias printf_padding::i#2 = printf_padding::i#4 printf_padding::i#3 +Alias printf_padding::length#2 = printf_padding::length#5 printf_padding::length#4 +Alias printf_string::str#3 = printf_string::str#5 printf_string::str#9 printf_string::str#8 +Alias printf_string::format_min_length#3 = printf_string::format_min_length#5 printf_string::format_min_length#4 +Alias printf_string::format_justify_left#5 = printf_string::format_justify_left#9 printf_string::format_justify_left#7 printf_string::format_justify_left#6 +Alias printf_string::putc#10 = printf_string::putc#12 printf_string::putc#9 printf_string::putc#11 +Alias strlen::return#2 = strlen::return#4 +Alias printf_string::padding#1 = printf_string::$10 +Alias printf_string::format_justify_left#4 = printf_string::format_justify_left#8 +Alias printf_string::padding#4 = printf_string::padding#7 printf_string::padding#6 +Alias printf_string::putc#3 = printf_string::putc#8 printf_string::putc#5 +Alias printf_string::putc#4 = printf_string::putc#6 printf_string::putc#7 +Alias printf_string::padding#3 = printf_string::padding#5 printf_string::padding#8 +Alias printf_string::str#10 = printf_string::str#6 printf_string::str#7 +Alias printf_string::format_justify_left#10 = printf_string::format_justify_left#11 printf_string::format_justify_left#3 +Alias snputc::c#0 = snputc::c#3 +Successful SSA optimization Pass2AliasElimination +Alias candidate removed (volatile)conio_line_text = gotoxy::$5 +Alias candidate removed (volatile)conio_line_color = gotoxy::$6 +Alias gotoxy::x#3 = gotoxy::x#5 +Alias gotoxy::y#4 = gotoxy::y#5 +Alias printf_string::format_justify_left#10 = printf_string::format_justify_left#5 printf_string::format_justify_left#4 +Alias printf_string::putc#10 = printf_string::putc#4 printf_string::putc#3 +Alias printf_string::str#10 = printf_string::str#3 printf_string::str#4 +Alias printf_string::padding#3 = printf_string::padding#4 +Successful SSA optimization Pass2AliasElimination +Alias candidate removed (volatile)conio_line_text = gotoxy::$5 +Alias candidate removed (volatile)conio_line_color = gotoxy::$6 +Identical Phi Values memcpy::src_end#1 memcpy::src_end#0 +Identical Phi Values memcpy::destination#3 memcpy::destination#2 +Identical Phi Values memset::end#1 memset::end#0 +Identical Phi Values memset::str#5 memset::str#3 +Identical Phi Values memset::c#2 memset::c#4 +Identical Phi Values strlen::str#4 strlen::str#1 +Identical Phi Values printf_str::putc#6 printf_str::putc#8 +Identical Phi Values printf_padding::length#2 printf_padding::length#3 +Identical Phi Values printf_padding::pad#2 printf_padding::pad#4 +Identical Phi Values printf_padding::putc#2 printf_padding::putc#4 +Successful SSA optimization Pass2IdenticalPhiElimination +Identical Phi Values memset::return#0 memset::str#3 +Successful SSA optimization Pass2IdenticalPhiElimination +Simple Condition memcpy::$1 [7] if(memcpy::src#2!=memcpy::src_end#0) goto memcpy::@2 +Simple Condition memset::$1 [14] if(memset::num#2<=0) goto memset::@1 +Simple Condition memset::$3 [21] if(memset::dst#2!=memset::end#0) goto memset::@4 +Simple Condition strlen::$0 [29] if(0!=*strlen::str#2) goto strlen::@2 +Simple Condition gotoxy::$1 [35] if(gotoxy::y#3<=$19) goto gotoxy::@1 +Simple Condition gotoxy::$3 [38] if(gotoxy::x#3<$28) goto gotoxy::@2 +Simple Condition cputc::$0 [53] if(cputc::c#0==' +') goto cputc::@1 +Simple Condition cputc::$2 [59] if(conio_cursor_x!=$28) goto cputc::@return +Simple Condition cscroll::$1 [69] if(conio_cursor_y!=$19) goto cscroll::@return +Simple Condition cscroll::$7 [71] if(0!=conio_scroll_enable) goto cscroll::@3 +Simple Condition conio_c64_init::$1 [101] if(conio_c64_init::line#0<$19) goto conio_c64_init::@1 +Simple Condition printf_str::$2 [114] if(0!=printf_str::c#1) goto printf_str::@2 +Simple Condition printf_padding::$0 [123] if(printf_padding::i#2=0) goto printf_string::@1 +Simple Condition snputc::$1 [171] if(__snprintf_size<=__snprintf_capacity) goto snputc::@1 +Simple Condition snputc::$3 [173] if(__snprintf_size!=__snprintf_capacity) goto snputc::@2 +Successful SSA optimization Pass2ConditionalJumpSimplification +Rewriting ! if()-condition to reversed if() [136] printf_string::$3 = ! printf_string::$2 +Rewriting && if()-condition to two if()s [135] printf_string::$2 = printf_string::$1 && printf_string::padding#3 +Rewriting ! if()-condition to reversed if() [152] printf_string::$7 = ! printf_string::$6 +Rewriting && if()-condition to two if()s [151] printf_string::$6 = printf_string::format_justify_left#10 && printf_string::padding#3 +Successful SSA optimization Pass2ConditionalAndOrRewriting +Warning! Adding boolean cast to non-boolean condition printf_string::format_justify_left#10 +Warning! Adding boolean cast to non-boolean condition printf_string::padding#3 +Warning! Adding boolean cast to non-boolean condition printf_string::padding#3 +Constant right-side identified [74] memcpy::num#0 = (unumber)$19*$28-$28 +Constant right-side identified [79] memcpy::num#1 = (unumber)$19*$28-$28 +Constant right-side identified [106] conio_c64_init::line#1 = (unumber)$19-1 +Successful SSA optimization Pass2ConstantRValueConsolidation +Constant strlen::len#0 = 0 +Constant gotoxy::y#0 = 0 +Constant gotoxy::x#0 = 0 +Constant memcpy::destination#0 = (void *)CONIO_SCREEN_TEXT +Constant memcpy::source#0 = (void *)CONIO_SCREEN_TEXT+$28 +Constant memcpy::num#0 = (unumber)$19*$28-$28 +Constant memcpy::destination#1 = (void *)CONIO_SCREEN_COLORS +Constant memcpy::source#1 = (void *)CONIO_SCREEN_COLORS+$28 +Constant memcpy::num#1 = (unumber)$19*$28-$28 +Constant memset::str#0 = (void *)CONIO_SCREEN_TEXT+(unsigned int)$19*$28-$28 +Constant memset::c#0 = ' ' +Constant memset::num#0 = $28 +Constant memset::str#1 = (void *)CONIO_SCREEN_COLORS+(unsigned int)$19*$28-$28 +Constant memset::num#1 = $28 +Constant gotoxy::x#1 = 0 +Constant gotoxy::y#1 = 0 +Constant gotoxy::x#2 = 0 +Constant conio_c64_init::line#1 = (unumber)$19-1 +Constant printf_str::c#0 = 0 +Constant printf_padding::i#0 = 0 +Constant printf_string::padding#0 = 0 +Constant printf_string::padding#2 = 0 +Constant printf_padding::pad#0 = ' ' +Constant printf_padding::pad#1 = ' ' +Constant snputc::c#1 = 0 +Constant snprintf_init::s#0 = BUF1 +Constant snprintf_init::n#0 = $14 +Constant printf_str::putc#1 = &snputc +Constant printf_str::s#2 = main::s +Constant snprintf_init::s#1 = BUF2 +Constant snprintf_init::n#1 = $14 +Constant printf_str::putc#2 = &snputc +Constant printf_str::s#3 = main::s1 +Constant printf_string::putc#0 = &snputc +Constant printf_string::str#0 = main::str +Constant printf_string::format_min_length#0 = 0 +Constant printf_string::format_justify_left#0 = 0 +Constant printf_str::putc#3 = &cputc +Constant printf_str::s#4 = main::s2 +Constant printf_string::putc#1 = &cputc +Constant printf_string::str#1 = BUF1 +Constant printf_string::format_min_length#1 = 0 +Constant printf_string::format_justify_left#1 = 0 +Constant printf_str::putc#4 = &cputc +Constant printf_str::s#5 = main::s3 +Constant printf_string::putc#2 = &cputc +Constant printf_string::str#2 = BUF2 +Constant printf_string::format_min_length#2 = 0 +Constant printf_string::format_justify_left#2 = 0 +Constant printf_str::putc#5 = &cputc +Constant printf_str::s#6 = main::s4 +Constant conio_textcolor = CONIO_TEXTCOLOR_DEFAULT +Constant conio_scroll_enable = 1 +Successful SSA optimization Pass2ConstantIdentification +Constant memset::c#1 = conio_textcolor +Successful SSA optimization Pass2ConstantIdentification +if() condition always true - replacing block destination [71] if(0!=conio_scroll_enable) goto cscroll::@3 +Successful SSA optimization Pass2ConstantIfs +Consolidated constant strings into main::s2 +Successful SSA optimization Pass2ConstantStringConsolidation +Rewriting conditional comparison [35] if(gotoxy::y#3<=$19) goto gotoxy::@1 +Removing PHI-reference to removed block (cscroll::@2) in block gotoxy +Removing PHI-reference to removed block (cscroll::@2) in block gotoxy +Removing unused block cscroll::@2 +Removing unused block cscroll::@8 +Successful SSA optimization Pass2EliminateUnusedBlocks +Eliminating unused variable memcpy::return#2 and assignment [57] memcpy::return#2 = memcpy::destination#2 +Eliminating unused variable memcpy::return#3 and assignment [59] memcpy::return#3 = memcpy::destination#2 +Eliminating unused variable memset::return#2 and assignment [61] memset::return#2 = memset::str#3 +Eliminating unused variable memset::return#3 and assignment [63] memset::return#3 = memset::str#3 +Eliminating unused constant gotoxy::x#1 +Eliminating unused constant gotoxy::y#1 +Eliminating unused constant printf_str::c#0 +Eliminating unused constant conio_scroll_enable +Successful SSA optimization PassNEliminateUnusedVars +Adding number conversion cast (unumber) $19+1 in if(gotoxy::y#3<$19+1) goto gotoxy::@1 +Adding number conversion cast (unumber) 1 in if(gotoxy::y#3<(unumber)$19+1) goto gotoxy::@1 +Adding number conversion cast (unumber) 0 in printf_string::$16 = 0 != printf_string::format_justify_left#10 +Adding number conversion cast (snumber) 0 in printf_string::$17 = 0 != printf_string::padding#3 +Adding number conversion cast (snumber) 0 in printf_string::$18 = 0 != printf_string::padding#3 +Successful SSA optimization PassNAddNumberTypeConversions +Simplifying constant integer cast $19+(unumber)1 +Simplifying constant integer cast 1 +Simplifying constant integer cast 0 +Simplifying constant integer cast 0 +Simplifying constant integer cast 0 +Successful SSA optimization PassNCastSimplification +Finalized unsigned number type (char) 1 +Finalized unsigned number type (char) 0 +Finalized signed number type (signed char) 0 +Finalized signed number type (signed char) 0 +Successful SSA optimization PassNFinalizeNumberTypeConversions +Alias candidate removed (volatile)conio_line_text = gotoxy::$5 +Alias candidate removed (volatile)conio_line_color = gotoxy::$6 +Identical Phi Values gotoxy::y#3 gotoxy::y#2 +Identical Phi Values gotoxy::x#3 gotoxy::x#2 +Successful SSA optimization Pass2IdenticalPhiElimination +Simple Condition printf_string::$1 [91] if(0==printf_string::format_justify_left#10) goto printf_string::@11 +Simple Condition printf_string::$16 [104] if(0!=printf_string::format_justify_left#10) goto printf_string::@12 +Simple Condition printf_string::$17 [156] if(0!=printf_string::padding#3) goto printf_string::@5 +Simple Condition printf_string::$18 [158] if(0!=printf_string::padding#3) goto printf_string::@6 +Successful SSA optimization Pass2ConditionalJumpSimplification +Negating conditional jump and destination [91] if(0!=printf_string::format_justify_left#10) goto printf_string::@2 +Negating conditional jump and destination [104] if(0==printf_string::format_justify_left#10) goto printf_string::@return +Successful SSA optimization Pass2ConditionalJumpSequenceImprovement +if() condition always true - replacing block destination [29] if(gotoxy::x#2<$28) goto gotoxy::@2 +Successful SSA optimization Pass2ConstantIfs +Removing PHI-reference to removed block (gotoxy::@4) in block gotoxy::@2 +Removing unused block gotoxy::@4 +Successful SSA optimization Pass2EliminateUnusedBlocks +Eliminating unused constant gotoxy::x#0 +Successful SSA optimization PassNEliminateUnusedVars +Alias candidate removed (volatile)conio_line_text = gotoxy::$5 +Alias candidate removed (volatile)conio_line_color = gotoxy::$6 +Identical Phi Values gotoxy::x#4 gotoxy::x#2 +Successful SSA optimization Pass2IdenticalPhiElimination +Alias candidate removed (volatile)conio_line_text = gotoxy::$5 +Alias candidate removed (volatile)conio_line_color = gotoxy::$6 +Inlining Noop Cast [1] memcpy::src#0 = (char *)memcpy::source#2 keeping memcpy::source#2 +Inlining Noop Cast [2] memcpy::dst#0 = (char *)memcpy::destination#2 keeping memcpy::destination#2 +Inlining Noop Cast [3] memcpy::$2 = (char *)memcpy::source#2 keeping memcpy::source#2 +Inlining Noop Cast [13] memset::$4 = (char *)memset::str#3 keeping memset::str#3 +Inlining Noop Cast [15] memset::dst#0 = (char *)memset::str#3 keeping memset::str#3 +Inlining Noop Cast [93] printf_string::$13 = (signed char)printf_string::format_min_length#3 keeping printf_string::format_min_length#3 +Successful SSA optimization Pass2NopCastInlining +Rewriting multiplication to use shift and addition[31] gotoxy::line_offset#0 = gotoxy::$7 * $28 +Inlining constant with var siblings memcpy::destination#0 +Inlining constant with var siblings memcpy::source#0 +Inlining constant with var siblings memcpy::num#0 +Inlining constant with var siblings memcpy::destination#1 +Inlining constant with var siblings memcpy::source#1 +Inlining constant with var siblings memcpy::num#1 +Inlining constant with var siblings memset::str#0 +Inlining constant with var siblings memset::c#0 +Inlining constant with var siblings memset::num#0 +Inlining constant with var siblings memset::str#1 +Inlining constant with var siblings memset::num#1 +Inlining constant with var siblings memset::c#1 +Inlining constant with var siblings strlen::len#0 +Inlining constant with var siblings gotoxy::y#0 +Inlining constant with var siblings conio_c64_init::line#1 +Inlining constant with var siblings printf_str::putc#1 +Inlining constant with var siblings printf_str::s#2 +Inlining constant with var siblings printf_str::putc#2 +Inlining constant with var siblings printf_str::s#3 +Inlining constant with var siblings printf_str::putc#3 +Inlining constant with var siblings printf_str::s#4 +Inlining constant with var siblings printf_str::putc#4 +Inlining constant with var siblings printf_str::s#5 +Inlining constant with var siblings printf_str::putc#5 +Inlining constant with var siblings printf_str::s#6 +Inlining constant with var siblings printf_padding::i#0 +Inlining constant with var siblings printf_padding::pad#0 +Inlining constant with var siblings printf_padding::pad#1 +Inlining constant with var siblings printf_string::padding#0 +Inlining constant with var siblings printf_string::padding#2 +Inlining constant with var siblings printf_string::putc#0 +Inlining constant with var siblings printf_string::str#0 +Inlining constant with var siblings printf_string::format_min_length#0 +Inlining constant with var siblings printf_string::format_justify_left#0 +Inlining constant with var siblings printf_string::putc#1 +Inlining constant with var siblings printf_string::str#1 +Inlining constant with var siblings printf_string::format_min_length#1 +Inlining constant with var siblings printf_string::format_justify_left#1 +Inlining constant with var siblings printf_string::putc#2 +Inlining constant with var siblings printf_string::str#2 +Inlining constant with var siblings printf_string::format_min_length#2 +Inlining constant with var siblings printf_string::format_justify_left#2 +Inlining constant with var siblings snprintf_init::s#0 +Inlining constant with var siblings snprintf_init::n#0 +Inlining constant with var siblings snprintf_init::s#1 +Inlining constant with var siblings snprintf_init::n#1 +Inlining constant with var siblings snputc::c#1 +Constant inlined conio_textcolor = LIGHT_BLUE +Constant inlined printf_str::putc#1 = &snputc +Constant inlined memset::num#1 = $28 +Constant inlined printf_str::putc#2 = &snputc +Constant inlined memset::num#0 = $28 +Constant inlined printf_str::putc#3 = &cputc +Constant inlined strlen::len#0 = 0 +Constant inlined printf_string::format_min_length#0 = 0 +Constant inlined printf_string::format_min_length#1 = 0 +Constant inlined printf_string::format_min_length#2 = 0 +Constant inlined printf_str::s#5 = main::s3 +Constant inlined printf_str::putc#4 = &cputc +Constant inlined printf_str::s#6 = main::s2 +Constant inlined printf_str::putc#5 = &cputc +Constant inlined printf_str::s#3 = main::s1 +Constant inlined snputc::c#1 = 0 +Constant inlined printf_str::s#4 = main::s2 +Constant inlined CONIO_SCREEN_TEXT = DEFAULT_SCREEN +Constant inlined printf_str::s#2 = main::s +Constant inlined printf_string::putc#1 = &cputc +Constant inlined printf_string::putc#0 = &snputc +Constant inlined printf_string::putc#2 = &cputc +Constant inlined memcpy::source#0 = (void *)DEFAULT_SCREEN+$28 +Constant inlined snprintf_init::n#0 = $14 +Constant inlined snprintf_init::n#1 = $14 +Constant inlined printf_string::padding#0 = 0 +Constant inlined printf_string::padding#2 = 0 +Constant inlined memset::c#0 = ' ' +Constant inlined memset::c#1 = LIGHT_BLUE +Constant inlined memcpy::destination#0 = (void *)DEFAULT_SCREEN +Constant inlined memcpy::destination#1 = (void *)COLORRAM +Constant inlined conio_c64_init::line#1 = (char)$19-1 +Constant inlined memcpy::source#1 = (void *)COLORRAM+$28 +Constant inlined printf_string::str#0 = main::str +Constant inlined printf_string::str#2 = BUF2 +Constant inlined printf_string::str#1 = BUF1 +Constant inlined CONIO_TEXTCOLOR_DEFAULT = LIGHT_BLUE +Constant inlined memset::str#1 = (void *)COLORRAM+(unsigned int)$19*$28-$28 +Constant inlined printf_padding::pad#0 = ' ' +Constant inlined memset::str#0 = (void *)DEFAULT_SCREEN+(unsigned int)$19*$28-$28 +Constant inlined printf_padding::i#0 = 0 +Constant inlined printf_padding::pad#1 = ' ' +Constant inlined CONIO_SCREEN_COLORS = COLORRAM +Constant inlined main::s4 = main::s2 +Constant inlined memcpy::num#1 = (unsigned int)$19*$28-$28 +Constant inlined memcpy::num#0 = (unsigned int)$19*$28-$28 +Constant inlined snprintf_init::s#0 = BUF1 +Constant inlined snprintf_init::s#1 = BUF2 +Constant inlined gotoxy::y#0 = 0 +Constant inlined printf_string::format_justify_left#1 = 0 +Constant inlined printf_string::format_justify_left#0 = 0 +Constant inlined printf_string::format_justify_left#2 = 0 +Successful SSA optimization Pass2ConstantInlining +Alias candidate removed (volatile)conio_line_text = gotoxy::$5 +Alias candidate removed (volatile)conio_line_color = gotoxy::$6 +Alias gotoxy::line_offset#0 = gotoxy::$10 +Successful SSA optimization Pass2AliasElimination +Alias candidate removed (volatile)conio_line_text = gotoxy::$5 +Alias candidate removed (volatile)conio_line_color = gotoxy::$6 +Identical Phi Values memcpy::num#2 (unsigned int)$19*$28-$28 +Identical Phi Values memset::num#2 $28 +Identical Phi Values printf_string::format_min_length#3 0 +Identical Phi Values printf_string::format_justify_left#10 0 +Identical Phi Values snprintf_init::n#2 $14 +Successful SSA optimization Pass2IdenticalPhiElimination +Constant value identified (signed char)0 in [90] printf_string::padding#1 = (signed char)0 - printf_string::len#0 +Successful SSA optimization Pass2ConstantValues +if() condition always false - eliminating [9] if($28<=0) goto memset::@1 +if() condition always true - replacing block destination [82] if(0==0) goto printf_string::@1 +if() condition always false - eliminating [84] if(0!=0) goto printf_string::@2 +if() condition always true - replacing block destination [95] if(0==0) goto printf_string::@return +Successful SSA optimization Pass2ConstantIfs +Simplifying constant evaluating to zero (signed char)0 in [90] printf_string::padding#1 = (signed char)0 - printf_string::len#0 +Successful SSA optimization PassNSimplifyConstantZero +Simplifying expression containing zero printf_string::len#0 in [90] printf_string::padding#1 = 0 - printf_string::len#0 +Successful SSA optimization PassNSimplifyExpressionWithZero +Eliminating variable strlen::str#2 from unused block strlen::@1 +Eliminating variable strlen::len#2 from unused block strlen::@1 +Eliminating variable strlen::len#1 from unused block strlen::@2 +Eliminating variable strlen::str#0 from unused block strlen::@2 +Eliminating variable strlen::str#1 from unused block printf_string::@3 +Eliminating variable strlen::return#2 from unused block printf_string::@3 +Eliminating variable printf_string::$9 from unused block printf_string::@7 +Eliminating variable printf_string::len#0 from unused block printf_string::@7 +Eliminating variable printf_string::padding#1 from unused block printf_string::@7 +Eliminating variable printf_padding::putc#1 from unused block printf_string::@6 +Eliminating variable printf_padding::length#1 from unused block printf_string::@6 +Removing unused procedure strlen +Removing unused procedure block strlen +Removing PHI-reference to removed block (strlen) in block strlen::@1 +Removing PHI-reference to removed block (strlen) in block strlen::@1 +Removing unused procedure block strlen::@1 +Removing unused procedure block strlen::@2 +Removing unused procedure block strlen::@3 +Removing unused procedure block strlen::@return +Removing unused block printf_string::@3 +Removing PHI-reference to removed block (printf_string::@7) in block printf_string::@1 +Removing unused block printf_string::@7 +Removing PHI-reference to removed block (printf_string::@4) in block printf_string::@1 +Removing unused block printf_string::@4 +Removing PHI-reference to removed block (printf_string::@6) in block printf_padding +Removing PHI-reference to removed block (printf_string::@6) in block printf_padding +Removing PHI-reference to removed block (printf_string::@6) in block printf_padding +Removing unused block printf_string::@6 +Removing unused block printf_string::@10 +Removing unused block printf_string::@12 +Successful SSA optimization Pass2EliminateUnusedBlocks +Alias candidate removed (volatile)conio_line_text = gotoxy::$5 +Alias candidate removed (volatile)conio_line_color = gotoxy::$6 +Identical Phi Values printf_padding::length#3 printf_padding::length#0 +Identical Phi Values printf_padding::pad#4 ' ' +Identical Phi Values printf_padding::putc#4 printf_padding::putc#0 +Identical Phi Values printf_string::padding#3 0 +Successful SSA optimization Pass2IdenticalPhiElimination +Constant right-side identified [81] printf_padding::length#0 = (char)0 +Successful SSA optimization Pass2ConstantRValueConsolidation +Constant printf_padding::length#0 = (char)0 +Successful SSA optimization Pass2ConstantIdentification +if() condition always false - eliminating [69] if(printf_padding::i#2capacity. + /// Used to hold state while printing + .label __snprintf_size = $10 + /// Current position in the buffer being filled ( initially *s passed to snprintf() + /// Used to hold state while printing + .label __snprintf_buffer = $12 +.segment Code + // __start +__start: { + jmp __init1 + // __start::__init1 + __init1: + // [1] conio_cursor_x = 0 -- vbuz1=vbuc1 + lda #0 + sta.z conio_cursor_x + // [2] conio_cursor_y = 0 -- vbuz1=vbuc1 + lda #0 + sta.z conio_cursor_y + // [3] conio_line_text = DEFAULT_SCREEN -- pbuz1=pbuc1 + lda #DEFAULT_SCREEN + sta.z conio_line_text+1 + // [4] conio_line_color = COLORRAM -- pbuz1=pbuc1 + lda #COLORRAM + sta.z conio_line_color+1 + // [5] __snprintf_capacity = 0 -- vwuz1=vwuc1 + lda #<0 + sta.z __snprintf_capacity + lda #>0 + sta.z __snprintf_capacity+1 + // [6] __snprintf_size = 0 -- vwuz1=vwuc1 + lda #<0 + sta.z __snprintf_size + lda #>0 + sta.z __snprintf_size+1 + // [7] __snprintf_buffer = (char *) 0 -- pbuz1=pbuc1 + lda #<0 + sta.z __snprintf_buffer + lda #>0 + sta.z __snprintf_buffer+1 + // [8] call conio_c64_init + jsr conio_c64_init + // [9] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1] + __b1_from___init1: + jmp __b1 + // __start::@1 + __b1: + // [10] call main + // [39] phi from __start::@1 to main [phi:__start::@1->main] + main_from___b1: + jsr main + jmp __breturn + // __start::@return + __breturn: + // [11] return + rts +} + // snputc +/// Print a character into snprintf buffer +/// Used by snprintf() +/// @param c The character to print +// void snputc(__register(X) char c) +snputc: { + .const OFFSET_STACK_C = 0 + // [12] snputc::c#0 = stackidx(char,snputc::OFFSET_STACK_C) -- vbuxx=_stackidxbyte_vbuc1 + tsx + lda STACK_BASE+OFFSET_STACK_C,x + tax + // [13] __snprintf_size = ++ __snprintf_size -- vwuz1=_inc_vwuz1 + inc.z __snprintf_size + bne !+ + inc.z __snprintf_size+1 + !: + // [14] if(__snprintf_size<=__snprintf_capacity) goto snputc::@1 -- vwuz1_le_vwuz2_then_la1 + lda.z __snprintf_size+1 + cmp.z __snprintf_capacity+1 + bne !+ + lda.z __snprintf_size + cmp.z __snprintf_capacity + beq __b1 + !: + bcc __b1 + jmp __breturn + // snputc::@return + __breturn: + // [15] return + rts + // snputc::@1 + __b1: + // [16] if(__snprintf_size!=__snprintf_capacity) goto snputc::@3 -- vwuz1_neq_vwuz2_then_la1 + lda.z __snprintf_size+1 + cmp.z __snprintf_capacity+1 + bne __b3_from___b1 + lda.z __snprintf_size + cmp.z __snprintf_capacity + bne __b3_from___b1 + // [18] phi from snputc::@1 to snputc::@2 [phi:snputc::@1->snputc::@2] + __b2_from___b1: + // [18] phi snputc::c#2 = 0 [phi:snputc::@1->snputc::@2#0] -- vbuxx=vbuc1 + ldx #0 + jmp __b2 + // [17] phi from snputc::@1 to snputc::@3 [phi:snputc::@1->snputc::@3] + __b3_from___b1: + jmp __b3 + // snputc::@3 + __b3: + // [18] phi from snputc::@3 to snputc::@2 [phi:snputc::@3->snputc::@2] + __b2_from___b3: + // [18] phi snputc::c#2 = snputc::c#0 [phi:snputc::@3->snputc::@2#0] -- register_copy + jmp __b2 + // snputc::@2 + __b2: + // [19] *__snprintf_buffer = snputc::c#2 -- _deref_pbuz1=vbuxx + // Append char + txa + ldy #0 + sta (__snprintf_buffer),y + // [20] __snprintf_buffer = ++ __snprintf_buffer -- pbuz1=_inc_pbuz1 + inc.z __snprintf_buffer + bne !+ + inc.z __snprintf_buffer+1 + !: + jmp __breturn +} + // conio_c64_init +// Set initial cursor position +conio_c64_init: { + // Position cursor at current line + .label BASIC_CURSOR_LINE = $d6 + // [21] conio_c64_init::line#0 = *conio_c64_init::BASIC_CURSOR_LINE -- vbuxx=_deref_pbuc1 + ldx BASIC_CURSOR_LINE + // [22] if(conio_c64_init::line#0<$19) goto conio_c64_init::@2 -- vbuxx_lt_vbuc1_then_la1 + cpx #$19 + bcc __b2_from_conio_c64_init + // [24] phi from conio_c64_init to conio_c64_init::@1 [phi:conio_c64_init->conio_c64_init::@1] + __b1_from_conio_c64_init: + // [24] phi conio_c64_init::line#2 = $19-1 [phi:conio_c64_init->conio_c64_init::@1#0] -- vbuxx=vbuc1 + ldx #$19-1 + jmp __b1 + // [23] phi from conio_c64_init to conio_c64_init::@2 [phi:conio_c64_init->conio_c64_init::@2] + __b2_from_conio_c64_init: + jmp __b2 + // conio_c64_init::@2 + __b2: + // [24] phi from conio_c64_init::@2 to conio_c64_init::@1 [phi:conio_c64_init::@2->conio_c64_init::@1] + __b1_from___b2: + // [24] phi conio_c64_init::line#2 = conio_c64_init::line#0 [phi:conio_c64_init::@2->conio_c64_init::@1#0] -- register_copy + jmp __b1 + // conio_c64_init::@1 + __b1: + // [25] gotoxy::y#2 = conio_c64_init::line#2 + // [26] call gotoxy + jsr gotoxy + jmp __breturn + // conio_c64_init::@return + __breturn: + // [27] return + rts +} + // cputc +// Output one character at the current cursor position +// Moves the cursor forward. Scrolls the entire screen if needed +// void cputc(__register(A) char c) +cputc: { + .const OFFSET_STACK_C = 0 + // [28] cputc::c#0 = stackidx(char,cputc::OFFSET_STACK_C) -- vbuaa=_stackidxbyte_vbuc1 + tsx + lda STACK_BASE+OFFSET_STACK_C,x + // [29] if(cputc::c#0==' ') goto cputc::@1 -- vbuaa_eq_vbuc1_then_la1 + cmp #'\n' + beq __b1_from_cputc + jmp __b2 + // cputc::@2 + __b2: + // [30] conio_line_text[conio_cursor_x] = cputc::c#0 -- pbuz1_derefidx_vbuz2=vbuaa + ldy.z conio_cursor_x + sta (conio_line_text),y + // [31] conio_line_color[conio_cursor_x] = LIGHT_BLUE -- pbuz1_derefidx_vbuz2=vbuc1 + lda #LIGHT_BLUE + ldy.z conio_cursor_x + sta (conio_line_color),y + // [32] conio_cursor_x = ++ conio_cursor_x -- vbuz1=_inc_vbuz1 + inc.z conio_cursor_x + // [33] if(conio_cursor_x!=$28) goto cputc::@return -- vbuz1_neq_vbuc1_then_la1 + lda #$28 + cmp.z conio_cursor_x + bne __breturn + // [34] phi from cputc::@2 to cputc::@3 [phi:cputc::@2->cputc::@3] + __b3_from___b2: + jmp __b3 + // cputc::@3 + __b3: + // [35] call cputln + jsr cputln + jmp __breturn + // cputc::@return + __breturn: + // [36] return + rts + // [37] phi from cputc to cputc::@1 [phi:cputc->cputc::@1] + __b1_from_cputc: + jmp __b1 + // cputc::@1 + __b1: + // [38] call cputln + jsr cputln + jmp __breturn +} + // main +main: { + // [40] call snprintf_init + // [87] phi from main to snprintf_init [phi:main->snprintf_init] + snprintf_init_from_main: + // [87] phi snprintf_init::s#2 = BUF1 [phi:main->snprintf_init#0] -- pbuz1=pbuc1 + lda #BUF1 + sta.z snprintf_init.s+1 + jsr snprintf_init + // [41] phi from main to main::@1 [phi:main->main::@1] + __b1_from_main: + jmp __b1 + // main::@1 + __b1: + // [42] call printf_str + // [92] phi from main::@1 to printf_str [phi:main::@1->printf_str] + printf_str_from___b1: + // [92] phi printf_str::putc#8 = &snputc [phi:main::@1->printf_str#0] -- pprz1=pprc1 + lda #snputc + sta.z printf_str.putc+1 + // [92] phi printf_str::s#8 = main::s [phi:main::@1->printf_str#1] -- pbuz1=pbuc1 + lda #s + sta.z printf_str.s+1 + jsr printf_str + jmp __b2 + // main::@2 + __b2: + // [43] stackpush(char) = 0 -- _stackpushbyte_=vbuc1 + lda #0 + pha + // [44] callexecute snputc -- call_vprc1 + jsr snputc + // sideeffect stackpullbytes(1) -- _stackpullbyte_1 + pla + // [46] call snprintf_init + // [87] phi from main::@2 to snprintf_init [phi:main::@2->snprintf_init] + snprintf_init_from___b2: + // [87] phi snprintf_init::s#2 = BUF2 [phi:main::@2->snprintf_init#0] -- pbuz1=pbuc1 + lda #BUF2 + sta.z snprintf_init.s+1 + jsr snprintf_init + // [47] phi from main::@2 to main::@3 [phi:main::@2->main::@3] + __b3_from___b2: + jmp __b3 + // main::@3 + __b3: + // [48] call printf_str + // [92] phi from main::@3 to printf_str [phi:main::@3->printf_str] + printf_str_from___b3: + // [92] phi printf_str::putc#8 = &snputc [phi:main::@3->printf_str#0] -- pprz1=pprc1 + lda #snputc + sta.z printf_str.putc+1 + // [92] phi printf_str::s#8 = main::s1 [phi:main::@3->printf_str#1] -- pbuz1=pbuc1 + lda #s1 + sta.z printf_str.s+1 + jsr printf_str + // [49] phi from main::@3 to main::@4 [phi:main::@3->main::@4] + __b4_from___b3: + jmp __b4 + // main::@4 + __b4: + // [50] call printf_string + // [101] phi from main::@4 to printf_string [phi:main::@4->printf_string] + printf_string_from___b4: + // [101] phi printf_string::putc#10 = &snputc [phi:main::@4->printf_string#0] -- pprz1=pprc1 + lda #snputc + sta.z printf_string.putc+1 + // [101] phi printf_string::str#10 = main::str [phi:main::@4->printf_string#1] -- pbuz1=pbuc1 + lda #str + sta.z printf_string.str+1 + jsr printf_string + jmp __b5 + // main::@5 + __b5: + // [51] stackpush(char) = '!' -- _stackpushbyte_=vbuc1 + lda #'!' + pha + // [52] callexecute snputc -- call_vprc1 + jsr snputc + // sideeffect stackpullbytes(1) -- _stackpullbyte_1 + pla + // [54] stackpush(char) = 0 -- _stackpushbyte_=vbuc1 + lda #0 + pha + // [55] callexecute snputc -- call_vprc1 + jsr snputc + // sideeffect stackpullbytes(1) -- _stackpullbyte_1 + pla + // [57] call printf_str + // [92] phi from main::@5 to printf_str [phi:main::@5->printf_str] + printf_str_from___b5: + // [92] phi printf_str::putc#8 = &cputc [phi:main::@5->printf_str#0] -- pprz1=pprc1 + lda #cputc + sta.z printf_str.putc+1 + // [92] phi printf_str::s#8 = main::s2 [phi:main::@5->printf_str#1] -- pbuz1=pbuc1 + lda #s2 + sta.z printf_str.s+1 + jsr printf_str + // [58] phi from main::@5 to main::@6 [phi:main::@5->main::@6] + __b6_from___b5: + jmp __b6 + // main::@6 + __b6: + // [59] call printf_string + // [101] phi from main::@6 to printf_string [phi:main::@6->printf_string] + printf_string_from___b6: + // [101] phi printf_string::putc#10 = &cputc [phi:main::@6->printf_string#0] -- pprz1=pprc1 + lda #cputc + sta.z printf_string.putc+1 + // [101] phi printf_string::str#10 = BUF1 [phi:main::@6->printf_string#1] -- pbuz1=pbuc1 + lda #BUF1 + sta.z printf_string.str+1 + jsr printf_string + // [60] phi from main::@6 to main::@7 [phi:main::@6->main::@7] + __b7_from___b6: + jmp __b7 + // main::@7 + __b7: + // [61] call printf_str + // [92] phi from main::@7 to printf_str [phi:main::@7->printf_str] + printf_str_from___b7: + // [92] phi printf_str::putc#8 = &cputc [phi:main::@7->printf_str#0] -- pprz1=pprc1 + lda #cputc + sta.z printf_str.putc+1 + // [92] phi printf_str::s#8 = main::s3 [phi:main::@7->printf_str#1] -- pbuz1=pbuc1 + lda #s3 + sta.z printf_str.s+1 + jsr printf_str + // [62] phi from main::@7 to main::@8 [phi:main::@7->main::@8] + __b8_from___b7: + jmp __b8 + // main::@8 + __b8: + // [63] call printf_string + // [101] phi from main::@8 to printf_string [phi:main::@8->printf_string] + printf_string_from___b8: + // [101] phi printf_string::putc#10 = &cputc [phi:main::@8->printf_string#0] -- pprz1=pprc1 + lda #cputc + sta.z printf_string.putc+1 + // [101] phi printf_string::str#10 = BUF2 [phi:main::@8->printf_string#1] -- pbuz1=pbuc1 + lda #BUF2 + sta.z printf_string.str+1 + jsr printf_string + // [64] phi from main::@8 to main::@9 [phi:main::@8->main::@9] + __b9_from___b8: + jmp __b9 + // main::@9 + __b9: + // [65] call printf_str + // [92] phi from main::@9 to printf_str [phi:main::@9->printf_str] + printf_str_from___b9: + // [92] phi printf_str::putc#8 = &cputc [phi:main::@9->printf_str#0] -- pprz1=pprc1 + lda #cputc + sta.z printf_str.putc+1 + // [92] phi printf_str::s#8 = main::s2 [phi:main::@9->printf_str#1] -- pbuz1=pbuc1 + lda #s2 + sta.z printf_str.s+1 + jsr printf_str + jmp __breturn + // main::@return + __breturn: + // [66] return + rts + .segment Data + s: .text "hello world!" + .byte 0 + s1: .text "hello " + .byte 0 + str: .text "world" + .byte 0 + s2: .text "-" + .byte 0 + s3: .text "- -" + .byte 0 +} +.segment Code + // gotoxy +// Set the cursor to the specified position +// void gotoxy(char x, __register(X) char y) +gotoxy: { + .const x = 0 + .label __5 = $18 + .label __6 = $14 + .label __7 = $14 + .label line_offset = $14 + .label __8 = $16 + .label __9 = $14 + // [67] if(gotoxy::y#2<$19+1) goto gotoxy::@3 -- vbuxx_lt_vbuc1_then_la1 + cpx #$19+1 + bcc __b3_from_gotoxy + // [69] phi from gotoxy to gotoxy::@1 [phi:gotoxy->gotoxy::@1] + __b1_from_gotoxy: + // [69] phi gotoxy::y#4 = 0 [phi:gotoxy->gotoxy::@1#0] -- vbuxx=vbuc1 + ldx #0 + jmp __b1 + // [68] phi from gotoxy to gotoxy::@3 [phi:gotoxy->gotoxy::@3] + __b3_from_gotoxy: + jmp __b3 + // gotoxy::@3 + __b3: + // [69] phi from gotoxy::@3 to gotoxy::@1 [phi:gotoxy::@3->gotoxy::@1] + __b1_from___b3: + // [69] phi gotoxy::y#4 = gotoxy::y#2 [phi:gotoxy::@3->gotoxy::@1#0] -- register_copy + jmp __b1 + // gotoxy::@1 + __b1: + jmp __b2 + // gotoxy::@2 + __b2: + // [70] conio_cursor_x = gotoxy::x#2 -- vbuz1=vbuc1 + lda #x + sta.z conio_cursor_x + // [71] conio_cursor_y = gotoxy::y#4 -- vbuz1=vbuxx + stx.z conio_cursor_y + // [72] gotoxy::$7 = (unsigned int)gotoxy::y#4 -- vwuz1=_word_vbuxx + txa + sta.z __7 + lda #0 + sta.z __7+1 + // [73] gotoxy::$8 = gotoxy::$7 << 2 -- vwuz1=vwuz2_rol_2 + lda.z __7 + asl + sta.z __8 + lda.z __7+1 + rol + sta.z __8+1 + asl.z __8 + rol.z __8+1 + // [74] gotoxy::$9 = gotoxy::$8 + gotoxy::$7 -- vwuz1=vwuz2_plus_vwuz1 + clc + lda.z __9 + adc.z __8 + sta.z __9 + lda.z __9+1 + adc.z __8+1 + sta.z __9+1 + // [75] gotoxy::line_offset#0 = gotoxy::$9 << 3 -- vwuz1=vwuz1_rol_3 + asl.z line_offset + rol.z line_offset+1 + asl.z line_offset + rol.z line_offset+1 + asl.z line_offset + rol.z line_offset+1 + // [76] gotoxy::$5 = DEFAULT_SCREEN + gotoxy::line_offset#0 -- pbuz1=pbuc1_plus_vwuz2 + lda.z line_offset + clc + adc #DEFAULT_SCREEN + sta.z __5+1 + // [77] conio_line_text = gotoxy::$5 -- pbuz1=pbuz2 + lda.z __5 + sta.z conio_line_text + lda.z __5+1 + sta.z conio_line_text+1 + // [78] gotoxy::$6 = COLORRAM + gotoxy::line_offset#0 -- pbuz1=pbuc1_plus_vwuz1 + lda.z __6 + clc + adc #COLORRAM + sta.z __6+1 + // [79] conio_line_color = gotoxy::$6 -- pbuz1=pbuz2 + lda.z __6 + sta.z conio_line_color + lda.z __6+1 + sta.z conio_line_color+1 + jmp __breturn + // gotoxy::@return + __breturn: + // [80] return + rts +} + // cputln +// Print a newline +cputln: { + // [81] conio_line_text = conio_line_text + $28 -- pbuz1=pbuz1_plus_vbuc1 + lda #$28 + clc + adc.z conio_line_text + sta.z conio_line_text + bcc !+ + inc.z conio_line_text+1 + !: + // [82] conio_line_color = conio_line_color + $28 -- pbuz1=pbuz1_plus_vbuc1 + lda #$28 + clc + adc.z conio_line_color + sta.z conio_line_color + bcc !+ + inc.z conio_line_color+1 + !: + // [83] conio_cursor_x = 0 -- vbuz1=vbuc1 + lda #0 + sta.z conio_cursor_x + // [84] conio_cursor_y = ++ conio_cursor_y -- vbuz1=_inc_vbuz1 + inc.z conio_cursor_y + // [85] call cscroll + jsr cscroll + jmp __breturn + // cputln::@return + __breturn: + // [86] return + rts +} + // snprintf_init +/// Initialize the snprintf() state +// void snprintf_init(__zp(2) char *s, unsigned int n) +snprintf_init: { + .label s = 2 + // [88] __snprintf_capacity = $14 -- vwuz1=vbuc1 + lda #<$14 + sta.z __snprintf_capacity + lda #>$14 + sta.z __snprintf_capacity+1 + // [89] __snprintf_size = 0 -- vwuz1=vbuc1 + lda #<0 + sta.z __snprintf_size + lda #>0 + sta.z __snprintf_size+1 + // [90] __snprintf_buffer = snprintf_init::s#2 -- pbuz1=pbuz2 + lda.z s + sta.z __snprintf_buffer + lda.z s+1 + sta.z __snprintf_buffer+1 + jmp __breturn + // snprintf_init::@return + __breturn: + // [91] return + rts +} + // printf_str +/// Print a NUL-terminated string +// void printf_str(__zp(2) void (*putc)(char), __zp(4) const char *s) +printf_str: { + .label s = 4 + .label putc = 2 + // [93] phi from printf_str printf_str::@2 to printf_str::@1 [phi:printf_str/printf_str::@2->printf_str::@1] + __b1_from_printf_str: + __b1_from___b2: + // [93] phi printf_str::s#7 = printf_str::s#8 [phi:printf_str/printf_str::@2->printf_str::@1#0] -- register_copy + jmp __b1 + // printf_str::@1 + __b1: + // [94] printf_str::c#1 = *printf_str::s#7 -- vbuaa=_deref_pbuz1 + ldy #0 + lda (s),y + // [95] printf_str::s#0 = ++ printf_str::s#7 -- pbuz1=_inc_pbuz1 + inc.z s + bne !+ + inc.z s+1 + !: + // [96] if(0!=printf_str::c#1) goto printf_str::@2 -- 0_neq_vbuaa_then_la1 + cmp #0 + bne __b2 + jmp __breturn + // printf_str::@return + __breturn: + // [97] return + rts + // printf_str::@2 + __b2: + // [98] stackpush(char) = printf_str::c#1 -- _stackpushbyte_=vbuaa + pha + // [99] callexecute *printf_str::putc#8 -- call__deref_pprz1 + jsr icall4 + // sideeffect stackpullbytes(1) -- _stackpullbyte_1 + pla + jmp __b1_from___b2 + // Outside Flow + icall4: + jmp (putc) +} + // printf_string +// Print a string value using a specific format +// Handles justification and min length +// void printf_string(__zp(2) void (*putc)(char), __zp(4) char *str, char format_min_length, char format_justify_left) +printf_string: { + .label putc = 2 + .label str = 4 + jmp __b1 + // printf_string::@1 + __b1: + // [102] printf_str::putc#0 = printf_string::putc#10 + // [103] printf_str::s#1 = printf_string::str#10 + // [104] call printf_str + // [92] phi from printf_string::@1 to printf_str [phi:printf_string::@1->printf_str] + printf_str_from___b1: + // [92] phi printf_str::putc#8 = printf_str::putc#0 [phi:printf_string::@1->printf_str#0] -- register_copy + // [92] phi printf_str::s#8 = printf_str::s#1 [phi:printf_string::@1->printf_str#1] -- register_copy + jsr printf_str + jmp __breturn + // printf_string::@return + __breturn: + // [105] return + rts +} + // cscroll +// Scroll the entire screen if the cursor is beyond the last line +cscroll: { + // [106] if(conio_cursor_y!=$19) goto cscroll::@return -- vbuz1_neq_vbuc1_then_la1 + lda #$19 + cmp.z conio_cursor_y + bne __breturn + // [107] phi from cscroll to cscroll::@1 [phi:cscroll->cscroll::@1] + __b1_from_cscroll: + jmp __b1 + // cscroll::@1 + __b1: + // [108] call memcpy + // [119] phi from cscroll::@1 to memcpy [phi:cscroll::@1->memcpy] + memcpy_from___b1: + // [119] phi memcpy::destination#2 = (void *)DEFAULT_SCREEN [phi:cscroll::@1->memcpy#0] -- pvoz1=pvoc1 + lda #DEFAULT_SCREEN + sta.z memcpy.destination+1 + // [119] phi memcpy::source#2 = (void *)DEFAULT_SCREEN+$28 [phi:cscroll::@1->memcpy#1] -- pvoz1=pvoc1 + lda #DEFAULT_SCREEN+$28 + sta.z memcpy.source+1 + jsr memcpy + // [109] phi from cscroll::@1 to cscroll::@2 [phi:cscroll::@1->cscroll::@2] + __b2_from___b1: + jmp __b2 + // cscroll::@2 + __b2: + // [110] call memcpy + // [119] phi from cscroll::@2 to memcpy [phi:cscroll::@2->memcpy] + memcpy_from___b2: + // [119] phi memcpy::destination#2 = (void *)COLORRAM [phi:cscroll::@2->memcpy#0] -- pvoz1=pvoc1 + lda #COLORRAM + sta.z memcpy.destination+1 + // [119] phi memcpy::source#2 = (void *)COLORRAM+$28 [phi:cscroll::@2->memcpy#1] -- pvoz1=pvoc1 + lda #COLORRAM+$28 + sta.z memcpy.source+1 + jsr memcpy + // [111] phi from cscroll::@2 to cscroll::@3 [phi:cscroll::@2->cscroll::@3] + __b3_from___b2: + jmp __b3 + // cscroll::@3 + __b3: + // [112] call memset + // [129] phi from cscroll::@3 to memset [phi:cscroll::@3->memset] + memset_from___b3: + // [129] phi memset::c#4 = ' ' [phi:cscroll::@3->memset#0] -- vbuxx=vbuc1 + ldx #' ' + // [129] phi memset::str#3 = (void *)DEFAULT_SCREEN+(unsigned int)$19*$28-$28 [phi:cscroll::@3->memset#1] -- pvoz1=pvoc1 + lda #DEFAULT_SCREEN+$19*$28-$28 + sta.z memset.str+1 + jsr memset + // [113] phi from cscroll::@3 to cscroll::@4 [phi:cscroll::@3->cscroll::@4] + __b4_from___b3: + jmp __b4 + // cscroll::@4 + __b4: + // [114] call memset + // [129] phi from cscroll::@4 to memset [phi:cscroll::@4->memset] + memset_from___b4: + // [129] phi memset::c#4 = LIGHT_BLUE [phi:cscroll::@4->memset#0] -- vbuxx=vbuc1 + ldx #LIGHT_BLUE + // [129] phi memset::str#3 = (void *)COLORRAM+(unsigned int)$19*$28-$28 [phi:cscroll::@4->memset#1] -- pvoz1=pvoc1 + lda #COLORRAM+$19*$28-$28 + sta.z memset.str+1 + jsr memset + jmp __b5 + // cscroll::@5 + __b5: + // [115] conio_line_text = conio_line_text - $28 -- pbuz1=pbuz1_minus_vbuc1 + sec + lda.z conio_line_text + sbc #$28 + sta.z conio_line_text + lda.z conio_line_text+1 + sbc #0 + sta.z conio_line_text+1 + // [116] conio_line_color = conio_line_color - $28 -- pbuz1=pbuz1_minus_vbuc1 + sec + lda.z conio_line_color + sbc #$28 + sta.z conio_line_color + lda.z conio_line_color+1 + sbc #0 + sta.z conio_line_color+1 + // [117] conio_cursor_y = -- conio_cursor_y -- vbuz1=_dec_vbuz1 + dec.z conio_cursor_y + jmp __breturn + // cscroll::@return + __breturn: + // [118] return + rts +} + // memcpy +// Copy block of memory (forwards) +// Copies the values of num bytes from the location pointed to by source directly to the memory block pointed to by destination. +// void * memcpy(__zp($1c) void *destination, __zp(6) void *source, unsigned int num) +memcpy: { + .label src_end = $1a + .label dst = $1c + .label src = 6 + .label source = 6 + .label destination = $1c + // [120] memcpy::src_end#0 = (char *)memcpy::source#2 + (unsigned int)$19*$28-$28 -- pbuz1=pbuz2_plus_vwuc1 + lda.z source + clc + adc #<$19*$28-$28 + sta.z src_end + lda.z source+1 + adc #>$19*$28-$28 + sta.z src_end+1 + // [121] memcpy::src#4 = (char *)memcpy::source#2 + // [122] memcpy::dst#4 = (char *)memcpy::destination#2 + // [123] phi from memcpy memcpy::@2 to memcpy::@1 [phi:memcpy/memcpy::@2->memcpy::@1] + __b1_from_memcpy: + __b1_from___b2: + // [123] phi memcpy::dst#2 = memcpy::dst#4 [phi:memcpy/memcpy::@2->memcpy::@1#0] -- register_copy + // [123] phi memcpy::src#2 = memcpy::src#4 [phi:memcpy/memcpy::@2->memcpy::@1#1] -- register_copy + jmp __b1 + // memcpy::@1 + __b1: + // [124] if(memcpy::src#2!=memcpy::src_end#0) goto memcpy::@2 -- pbuz1_neq_pbuz2_then_la1 + lda.z src+1 + cmp.z src_end+1 + bne __b2 + lda.z src + cmp.z src_end + bne __b2 + jmp __breturn + // memcpy::@return + __breturn: + // [125] return + rts + // memcpy::@2 + __b2: + // [126] *memcpy::dst#2 = *memcpy::src#2 -- _deref_pbuz1=_deref_pbuz2 + ldy #0 + lda (src),y + ldy #0 + sta (dst),y + // [127] memcpy::dst#1 = ++ memcpy::dst#2 -- pbuz1=_inc_pbuz1 + inc.z dst + bne !+ + inc.z dst+1 + !: + // [128] memcpy::src#1 = ++ memcpy::src#2 -- pbuz1=_inc_pbuz1 + inc.z src + bne !+ + inc.z src+1 + !: + jmp __b1_from___b2 +} + // memset +// Copies the character c (an unsigned char) to the first num characters of the object pointed to by the argument str. +// void * memset(__zp(6) void *str, __register(X) char c, unsigned int num) +memset: { + .label end = $1c + .label dst = 6 + .label str = 6 + jmp __b1 + // memset::@1 + __b1: + // [130] memset::end#0 = (char *)memset::str#3 + $28 -- pbuz1=pbuz2_plus_vbuc1 + lda #$28 + clc + adc.z str + sta.z end + lda #0 + adc.z str+1 + sta.z end+1 + // [131] memset::dst#4 = (char *)memset::str#3 + // [132] phi from memset::@1 memset::@3 to memset::@2 [phi:memset::@1/memset::@3->memset::@2] + __b2_from___b1: + __b2_from___b3: + // [132] phi memset::dst#2 = memset::dst#4 [phi:memset::@1/memset::@3->memset::@2#0] -- register_copy + jmp __b2 + // memset::@2 + __b2: + // [133] if(memset::dst#2!=memset::end#0) goto memset::@3 -- pbuz1_neq_pbuz2_then_la1 + lda.z dst+1 + cmp.z end+1 + bne __b3 + lda.z dst + cmp.z end + bne __b3 + jmp __breturn + // memset::@return + __breturn: + // [134] return + rts + // memset::@3 + __b3: + // [135] *memset::dst#2 = memset::c#4 -- _deref_pbuz1=vbuxx + txa + ldy #0 + sta (dst),y + // [136] memset::dst#1 = ++ memset::dst#2 -- pbuz1=_inc_pbuz1 + inc.z dst + bne !+ + inc.z dst+1 + !: + jmp __b2_from___b3 +} + // File Data +.segment Data + BUF1: .fill $14, 0 + BUF2: .fill $14, 0 + +ASSEMBLER OPTIMIZATIONS +Removing instruction jmp __init1 +Removing instruction jmp __b1 +Removing instruction jmp __breturn +Removing instruction jmp __breturn +Removing instruction jmp __b3 +Removing instruction jmp __b2 +Removing instruction jmp __b2 +Removing instruction jmp __b1 +Removing instruction jmp __breturn +Removing instruction jmp __b2 +Removing instruction jmp __b3 +Removing instruction jmp __breturn +Removing instruction jmp __b1 +Removing instruction jmp __b1 +Removing instruction jmp __b2 +Removing instruction jmp __b3 +Removing instruction jmp __b4 +Removing instruction jmp __b5 +Removing instruction jmp __b6 +Removing instruction jmp __b7 +Removing instruction jmp __b8 +Removing instruction jmp __b9 +Removing instruction jmp __breturn +Removing instruction jmp __b3 +Removing instruction jmp __b1 +Removing instruction jmp __b2 +Removing instruction jmp __breturn +Removing instruction jmp __breturn +Removing instruction jmp __breturn +Removing instruction jmp __b1 +Removing instruction jmp __breturn +Removing instruction jmp __b1 +Removing instruction jmp __breturn +Removing instruction jmp __b1 +Removing instruction jmp __b2 +Removing instruction jmp __b3 +Removing instruction jmp __b4 +Removing instruction jmp __b5 +Removing instruction jmp __breturn +Removing instruction jmp __b1 +Removing instruction jmp __breturn +Removing instruction jmp __b1 +Removing instruction jmp __b2 +Removing instruction jmp __breturn +Succesful ASM optimization Pass5NextJumpElimination +Removing instruction lda #0 +Removing instruction lda #>0 +Removing instruction lda #<0 +Removing instruction lda #>0 +Removing instruction lda #<0 +Removing instruction lda #>0 +Removing instruction ldy.z conio_cursor_x +Removing instruction lda #>0 +Removing instruction ldy #0 +Succesful ASM optimization Pass5UnnecesaryLoadElimination +Replacing label __b3_from___b1 with __b2 +Replacing label __b3_from___b1 with __b2 +Replacing label __b2_from_conio_c64_init with __b1 +Replacing label __b1_from_cputc with __b1 +Replacing label __b3_from_gotoxy with __b2 +Replacing label __b1 with __b2 +Replacing label __b1_from___b2 with __b1 +Replacing label __b1_from___b2 with __b1 +Replacing label __b2_from___b3 with __b2 +Removing instruction __b1_from___init1: +Removing instruction main_from___b1: +Removing instruction __b3_from___b1: +Removing instruction __b3: +Removing instruction __b2_from___b3: +Removing instruction __b2_from_conio_c64_init: +Removing instruction __b2: +Removing instruction __b1_from___b2: +Removing instruction __b3_from___b2: +Removing instruction __b1_from_cputc: +Removing instruction __b1_from_main: +Removing instruction printf_str_from___b1: +Removing instruction __b3_from___b2: +Removing instruction printf_str_from___b3: +Removing instruction __b4_from___b3: +Removing instruction printf_string_from___b4: +Removing instruction __b6_from___b5: +Removing instruction printf_string_from___b6: +Removing instruction __b7_from___b6: +Removing instruction printf_str_from___b7: +Removing instruction __b8_from___b7: +Removing instruction printf_string_from___b8: +Removing instruction __b9_from___b8: +Removing instruction printf_str_from___b9: +Removing instruction __b3_from_gotoxy: +Removing instruction __b3: +Removing instruction __b1_from___b3: +Removing instruction __b1: +Removing instruction __b1_from_printf_str: +Removing instruction __b1_from___b2: +Removing instruction printf_str_from___b1: +Removing instruction __b1_from_cscroll: +Removing instruction memcpy_from___b1: +Removing instruction __b2_from___b1: +Removing instruction memcpy_from___b2: +Removing instruction __b3_from___b2: +Removing instruction memset_from___b3: +Removing instruction __b4_from___b3: +Removing instruction memset_from___b4: +Removing instruction __b1_from_memcpy: +Removing instruction __b1_from___b2: +Removing instruction __b2_from___b1: +Removing instruction __b2_from___b3: +Succesful ASM optimization Pass5RedundantLabelElimination +Removing instruction __init1: +Removing instruction __b1: +Removing instruction __breturn: +Removing instruction __b2_from___b1: +Removing instruction __b1_from_conio_c64_init: +Removing instruction __breturn: +Removing instruction __b2: +Removing instruction __b3: +Removing instruction snprintf_init_from_main: +Removing instruction __b1: +Removing instruction __b2: +Removing instruction snprintf_init_from___b2: +Removing instruction __b3: +Removing instruction __b4: +Removing instruction __b5: +Removing instruction printf_str_from___b5: +Removing instruction __b6: +Removing instruction __b7: +Removing instruction __b8: +Removing instruction __b9: +Removing instruction __breturn: +Removing instruction __b1_from_gotoxy: +Removing instruction __breturn: +Removing instruction __breturn: +Removing instruction __breturn: +Removing instruction __breturn: +Removing instruction __b1: +Removing instruction __breturn: +Removing instruction __b1: +Removing instruction __b2: +Removing instruction __b3: +Removing instruction __b4: +Removing instruction __b5: +Removing instruction __breturn: +Removing instruction __b1: +Removing instruction __breturn: +Succesful ASM optimization Pass5UnusedLabelElimination +Replacing jump to rts with rts in jmp __breturn +Replacing jump to rts with rts in jmp __breturn +Succesful ASM optimization Pass5DoubleJumpElimination +Removing instruction jmp __b2 +Removing instruction jmp __b1 +Removing instruction jmp __b2 +Succesful ASM optimization Pass5NextJumpElimination +Removing instruction __breturn: +Succesful ASM optimization Pass5UnusedLabelElimination + +FINAL SYMBOL TABLE +__constant char BUF1[$14] = { fill( $14, 0) } +__constant char BUF2[$14] = { fill( $14, 0) } +__constant char * const COLORRAM = (char *) 55296 +__constant char * const DEFAULT_SCREEN = (char *) 1024 +__constant const char LIGHT_BLUE = $e +__constant char RADIX::BINARY = 2 +__constant char RADIX::DECIMAL = $a +__constant char RADIX::HEXADECIMAL = $10 +__constant char RADIX::OCTAL = 8 +__constant unsigned int STACK_BASE = $103 +__loadstore char *__snprintf_buffer // zp[2]:18 16.916666666666664 +__loadstore volatile unsigned int __snprintf_capacity // zp[2]:14 11.730769230769232 +__loadstore volatile unsigned int __snprintf_size // zp[2]:16 20.279999999999998 +void __start() +void conio_c64_init() +__constant char * const conio_c64_init::BASIC_CURSOR_LINE = (char *) 214 +char conio_c64_init::line +char conio_c64_init::line#0 // reg byte x 11.0 +char conio_c64_init::line#2 // reg byte x 22.0 +__loadstore char conio_cursor_x // zp[1]:8 24.799999999999997 +__loadstore char conio_cursor_y // zp[1]:9 18.608695652173914 +__loadstore char *conio_line_color // zp[2]:12 14.954545454545453 +__loadstore char *conio_line_text // zp[2]:10 15.666666666666668 +__stackcall void cputc(char c) +__constant char cputc::OFFSET_STACK_C = 0 +char cputc::c +char cputc::c#0 // reg byte a 3.0 +void cputln() +void cscroll() +void gotoxy(char x , char y) +char *gotoxy::$5 // zp[2]:24 202.0 +char *gotoxy::$6 // zp[2]:20 202.0 +unsigned int gotoxy::$7 // zp[2]:20 151.5 +unsigned int gotoxy::$8 // zp[2]:22 202.0 +unsigned int gotoxy::$9 // zp[2]:20 202.0 +unsigned int gotoxy::line_offset +unsigned int gotoxy::line_offset#0 // line_offset zp[2]:20 101.0 +char gotoxy::x +__constant char gotoxy::x#2 = 0 // x +char gotoxy::y +char gotoxy::y#2 // reg byte x 71.0 +char gotoxy::y#4 // reg byte x 67.33333333333333 +void main() +__constant char main::s[$d] = "hello world!" +__constant char main::s1[7] = "hello " +__constant char main::s2[2] = "-" +__constant char main::s3[4] = "- -" +__constant char main::str[6] = "world" +void * memcpy(void *destination , void *source , unsigned int num) +void *memcpy::destination +void *memcpy::destination#2 // destination zp[2]:28 +char *memcpy::dst +char *memcpy::dst#1 // dst zp[2]:28 10001.0 +char *memcpy::dst#2 // dst zp[2]:28 10334.666666666666 +char *memcpy::dst#4 // dst zp[2]:28 2002.0 +unsigned int memcpy::num +void *memcpy::return +void *memcpy::source +void *memcpy::source#2 // source zp[2]:6 +char *memcpy::src +char *memcpy::src#1 // src zp[2]:6 20002.0 +char *memcpy::src#2 // src zp[2]:6 10251.25 +char *memcpy::src#4 // src zp[2]:6 1001.0 +char *memcpy::src_end +char *memcpy::src_end#0 // src_end zp[2]:26 1375.25 +void * memset(void *str , char c , unsigned int num) +char memset::c +char memset::c#4 // reg byte x 1428.7142857142858 +char *memset::dst +char *memset::dst#1 // dst zp[2]:6 20002.0 +char *memset::dst#2 // dst zp[2]:6 13668.333333333332 +char *memset::dst#4 // dst zp[2]:6 2002.0 +char *memset::end +char *memset::end#0 // end zp[2]:28 1833.6666666666665 +unsigned int memset::num +void *memset::return +void *memset::str +void *memset::str#3 // str zp[2]:6 +void printf_str(void (*putc)(char) , const char *s) +char printf_str::c +char printf_str::c#1 // reg byte a 10001.0 +void (*printf_str::putc)(char) +void (*printf_str::putc#0)(char) // putc zp[2]:2 101.0 +void (*printf_str::putc#8)(char) // putc zp[2]:2 1010.0 +const char *printf_str::s +const char *printf_str::s#0 // s zp[2]:4 10001.0 +const char *printf_str::s#1 // s zp[2]:4 202.0 +const char *printf_str::s#7 // s zp[2]:4 15502.0 +const char *printf_str::s#8 // s zp[2]:4 1102.0 +void printf_string(void (*putc)(char) , char *str , char format_min_length , char format_justify_left) +struct printf_format_string printf_string::format +char printf_string::format_justify_left +char printf_string::format_min_length +signed char printf_string::len +signed char printf_string::padding +void (*printf_string::putc)(char) +void (*printf_string::putc#10)(char) // putc zp[2]:2 101.0 +char *printf_string::str +char *printf_string::str#10 // str zp[2]:4 50.5 +void snprintf_init(char *s , unsigned int n) +unsigned int snprintf_init::n +char *snprintf_init::s +char *snprintf_init::s#2 // s zp[2]:2 33.666666666666664 +__stackcall void snputc(char c) +__constant char snputc::OFFSET_STACK_C = 0 +char snputc::c +char snputc::c#0 // reg byte x 40.4 +char snputc::c#2 // reg byte x 202.0 + +reg byte x [ snputc::c#2 snputc::c#0 ] +reg byte x [ conio_c64_init::line#2 conio_c64_init::line#0 ] +reg byte x [ gotoxy::y#4 gotoxy::y#2 ] +zp[2]:2 [ printf_str::putc#8 printf_str::putc#0 printf_string::putc#10 snprintf_init::s#2 ] +zp[2]:4 [ printf_str::s#7 printf_str::s#8 printf_str::s#1 printf_str::s#0 printf_string::str#10 ] +zp[2]:6 [ memset::str#3 memset::dst#2 memset::dst#4 memset::dst#1 memcpy::source#2 memcpy::src#2 memcpy::src#4 memcpy::src#1 ] +reg byte x [ memset::c#4 ] +zp[1]:8 [ conio_cursor_x ] +zp[1]:9 [ conio_cursor_y ] +zp[2]:10 [ conio_line_text ] +zp[2]:12 [ conio_line_color ] +zp[2]:14 [ __snprintf_capacity ] +zp[2]:16 [ __snprintf_size ] +zp[2]:18 [ __snprintf_buffer ] +reg byte a [ cputc::c#0 ] +zp[2]:20 [ gotoxy::$7 gotoxy::$9 gotoxy::line_offset#0 gotoxy::$6 ] +zp[2]:22 [ gotoxy::$8 ] +zp[2]:24 [ gotoxy::$5 ] +reg byte a [ printf_str::c#1 ] +zp[2]:26 [ memcpy::src_end#0 ] +zp[2]:28 [ memset::end#0 memcpy::destination#2 memcpy::dst#2 memcpy::dst#4 memcpy::dst#1 ] + + +FINAL ASSEMBLER +Score: 2465 + + // File Comments +// Tests snprintf function call rewriting +// Test snprintf() and printf() in the same file + // Upstart + // Commodore 64 PRG executable file +.file [name="printf-18.prg", type="prg", segments="Program"] +.segmentdef Program [segments="Basic, Code, Data"] +.segmentdef Basic [start=$0801] +.segmentdef Code [start=$80d] +.segmentdef Data [startAfter="Code"] +.segment Basic +:BasicUpstart(__start) + // Global Constants & labels + .const LIGHT_BLUE = $e + .const STACK_BASE = $103 + /// Color Ram + .label COLORRAM = $d800 + /// Default address of screen character matrix + .label DEFAULT_SCREEN = $400 + // The number of bytes on the screen + // The current cursor x-position + .label conio_cursor_x = 8 + // The current cursor y-position + .label conio_cursor_y = 9 + // The current text cursor line start + .label conio_line_text = $a + // The current color cursor line start + .label conio_line_color = $c + /// The capacity of the buffer (n passed to snprintf()) + /// Used to hold state while printing + .label __snprintf_capacity = $e + // The number of chars that would have been filled when printing without capacity. Grows even after size>capacity. + /// Used to hold state while printing + .label __snprintf_size = $10 + /// Current position in the buffer being filled ( initially *s passed to snprintf() + /// Used to hold state while printing + .label __snprintf_buffer = $12 +.segment Code + // __start +__start: { + // __start::__init1 + // __ma char conio_cursor_x = 0 + // [1] conio_cursor_x = 0 -- vbuz1=vbuc1 + lda #0 + sta.z conio_cursor_x + // __ma char conio_cursor_y = 0 + // [2] conio_cursor_y = 0 -- vbuz1=vbuc1 + sta.z conio_cursor_y + // __ma char *conio_line_text = CONIO_SCREEN_TEXT + // [3] conio_line_text = DEFAULT_SCREEN -- pbuz1=pbuc1 + lda #DEFAULT_SCREEN + sta.z conio_line_text+1 + // __ma char *conio_line_color = CONIO_SCREEN_COLORS + // [4] conio_line_color = COLORRAM -- pbuz1=pbuc1 + lda #COLORRAM + sta.z conio_line_color+1 + // volatile size_t __snprintf_capacity + // [5] __snprintf_capacity = 0 -- vwuz1=vwuc1 + lda #<0 + sta.z __snprintf_capacity + sta.z __snprintf_capacity+1 + // volatile size_t __snprintf_size + // [6] __snprintf_size = 0 -- vwuz1=vwuc1 + sta.z __snprintf_size + sta.z __snprintf_size+1 + // char * __snprintf_buffer + // [7] __snprintf_buffer = (char *) 0 -- pbuz1=pbuc1 + sta.z __snprintf_buffer + sta.z __snprintf_buffer+1 + // #pragma constructor_for(conio_c64_init, cputc, clrscr, cscroll) + // [8] call conio_c64_init + jsr conio_c64_init + // [9] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1] + // __start::@1 + // [10] call main + // [39] phi from __start::@1 to main [phi:__start::@1->main] + jsr main + // __start::@return + // [11] return + rts +} + // snputc +/// Print a character into snprintf buffer +/// Used by snprintf() +/// @param c The character to print +// void snputc(__register(X) char c) +snputc: { + .const OFFSET_STACK_C = 0 + // [12] snputc::c#0 = stackidx(char,snputc::OFFSET_STACK_C) -- vbuxx=_stackidxbyte_vbuc1 + tsx + lda STACK_BASE+OFFSET_STACK_C,x + tax + // ++__snprintf_size; + // [13] __snprintf_size = ++ __snprintf_size -- vwuz1=_inc_vwuz1 + inc.z __snprintf_size + bne !+ + inc.z __snprintf_size+1 + !: + // if(__snprintf_size > __snprintf_capacity) + // [14] if(__snprintf_size<=__snprintf_capacity) goto snputc::@1 -- vwuz1_le_vwuz2_then_la1 + lda.z __snprintf_size+1 + cmp.z __snprintf_capacity+1 + bne !+ + lda.z __snprintf_size + cmp.z __snprintf_capacity + beq __b1 + !: + bcc __b1 + // snputc::@return + // } + // [15] return + rts + // snputc::@1 + __b1: + // if(__snprintf_size==__snprintf_capacity) + // [16] if(__snprintf_size!=__snprintf_capacity) goto snputc::@3 -- vwuz1_neq_vwuz2_then_la1 + lda.z __snprintf_size+1 + cmp.z __snprintf_capacity+1 + bne __b2 + lda.z __snprintf_size + cmp.z __snprintf_capacity + bne __b2 + // [18] phi from snputc::@1 to snputc::@2 [phi:snputc::@1->snputc::@2] + // [18] phi snputc::c#2 = 0 [phi:snputc::@1->snputc::@2#0] -- vbuxx=vbuc1 + ldx #0 + // [17] phi from snputc::@1 to snputc::@3 [phi:snputc::@1->snputc::@3] + // snputc::@3 + // [18] phi from snputc::@3 to snputc::@2 [phi:snputc::@3->snputc::@2] + // [18] phi snputc::c#2 = snputc::c#0 [phi:snputc::@3->snputc::@2#0] -- register_copy + // snputc::@2 + __b2: + // *(__snprintf_buffer++) = c + // [19] *__snprintf_buffer = snputc::c#2 -- _deref_pbuz1=vbuxx + // Append char + txa + ldy #0 + sta (__snprintf_buffer),y + // *(__snprintf_buffer++) = c; + // [20] __snprintf_buffer = ++ __snprintf_buffer -- pbuz1=_inc_pbuz1 + inc.z __snprintf_buffer + bne !+ + inc.z __snprintf_buffer+1 + !: + rts +} + // conio_c64_init +// Set initial cursor position +conio_c64_init: { + // Position cursor at current line + .label BASIC_CURSOR_LINE = $d6 + // char line = *BASIC_CURSOR_LINE + // [21] conio_c64_init::line#0 = *conio_c64_init::BASIC_CURSOR_LINE -- vbuxx=_deref_pbuc1 + ldx BASIC_CURSOR_LINE + // if(line>=CONIO_HEIGHT) + // [22] if(conio_c64_init::line#0<$19) goto conio_c64_init::@2 -- vbuxx_lt_vbuc1_then_la1 + cpx #$19 + bcc __b1 + // [24] phi from conio_c64_init to conio_c64_init::@1 [phi:conio_c64_init->conio_c64_init::@1] + // [24] phi conio_c64_init::line#2 = $19-1 [phi:conio_c64_init->conio_c64_init::@1#0] -- vbuxx=vbuc1 + ldx #$19-1 + // [23] phi from conio_c64_init to conio_c64_init::@2 [phi:conio_c64_init->conio_c64_init::@2] + // conio_c64_init::@2 + // [24] phi from conio_c64_init::@2 to conio_c64_init::@1 [phi:conio_c64_init::@2->conio_c64_init::@1] + // [24] phi conio_c64_init::line#2 = conio_c64_init::line#0 [phi:conio_c64_init::@2->conio_c64_init::@1#0] -- register_copy + // conio_c64_init::@1 + __b1: + // gotoxy(0, line) + // [25] gotoxy::y#2 = conio_c64_init::line#2 + // [26] call gotoxy + jsr gotoxy + // conio_c64_init::@return + // } + // [27] return + rts +} + // cputc +// Output one character at the current cursor position +// Moves the cursor forward. Scrolls the entire screen if needed +// void cputc(__register(A) char c) +cputc: { + .const OFFSET_STACK_C = 0 + // [28] cputc::c#0 = stackidx(char,cputc::OFFSET_STACK_C) -- vbuaa=_stackidxbyte_vbuc1 + tsx + lda STACK_BASE+OFFSET_STACK_C,x + // if(c=='\n') + // [29] if(cputc::c#0==' ') goto cputc::@1 -- vbuaa_eq_vbuc1_then_la1 + cmp #'\n' + beq __b1 + // cputc::@2 + // conio_line_text[conio_cursor_x] = c + // [30] conio_line_text[conio_cursor_x] = cputc::c#0 -- pbuz1_derefidx_vbuz2=vbuaa + ldy.z conio_cursor_x + sta (conio_line_text),y + // conio_line_color[conio_cursor_x] = conio_textcolor + // [31] conio_line_color[conio_cursor_x] = LIGHT_BLUE -- pbuz1_derefidx_vbuz2=vbuc1 + lda #LIGHT_BLUE + sta (conio_line_color),y + // if(++conio_cursor_x==CONIO_WIDTH) + // [32] conio_cursor_x = ++ conio_cursor_x -- vbuz1=_inc_vbuz1 + inc.z conio_cursor_x + // [33] if(conio_cursor_x!=$28) goto cputc::@return -- vbuz1_neq_vbuc1_then_la1 + lda #$28 + cmp.z conio_cursor_x + bne __breturn + // [34] phi from cputc::@2 to cputc::@3 [phi:cputc::@2->cputc::@3] + // cputc::@3 + // cputln() + // [35] call cputln + jsr cputln + // cputc::@return + __breturn: + // } + // [36] return + rts + // [37] phi from cputc to cputc::@1 [phi:cputc->cputc::@1] + // cputc::@1 + __b1: + // cputln() + // [38] call cputln + jsr cputln + rts +} + // main +main: { + // snprintf(BUF1, 20, "hello world!") + // [40] call snprintf_init + // [87] phi from main to snprintf_init [phi:main->snprintf_init] + // [87] phi snprintf_init::s#2 = BUF1 [phi:main->snprintf_init#0] -- pbuz1=pbuc1 + lda #BUF1 + sta.z snprintf_init.s+1 + jsr snprintf_init + // [41] phi from main to main::@1 [phi:main->main::@1] + // main::@1 + // snprintf(BUF1, 20, "hello world!") + // [42] call printf_str + // [92] phi from main::@1 to printf_str [phi:main::@1->printf_str] + // [92] phi printf_str::putc#8 = &snputc [phi:main::@1->printf_str#0] -- pprz1=pprc1 + lda #snputc + sta.z printf_str.putc+1 + // [92] phi printf_str::s#8 = main::s [phi:main::@1->printf_str#1] -- pbuz1=pbuc1 + lda #s + sta.z printf_str.s+1 + jsr printf_str + // main::@2 + // snprintf(BUF1, 20, "hello world!") + // [43] stackpush(char) = 0 -- _stackpushbyte_=vbuc1 + lda #0 + pha + // [44] callexecute snputc -- call_vprc1 + jsr snputc + // sideeffect stackpullbytes(1) -- _stackpullbyte_1 + pla + // snprintf(BUF2, 20, "hello %s%c", "world", '!') + // [46] call snprintf_init + // [87] phi from main::@2 to snprintf_init [phi:main::@2->snprintf_init] + // [87] phi snprintf_init::s#2 = BUF2 [phi:main::@2->snprintf_init#0] -- pbuz1=pbuc1 + lda #BUF2 + sta.z snprintf_init.s+1 + jsr snprintf_init + // [47] phi from main::@2 to main::@3 [phi:main::@2->main::@3] + // main::@3 + // snprintf(BUF2, 20, "hello %s%c", "world", '!') + // [48] call printf_str + // [92] phi from main::@3 to printf_str [phi:main::@3->printf_str] + // [92] phi printf_str::putc#8 = &snputc [phi:main::@3->printf_str#0] -- pprz1=pprc1 + lda #snputc + sta.z printf_str.putc+1 + // [92] phi printf_str::s#8 = main::s1 [phi:main::@3->printf_str#1] -- pbuz1=pbuc1 + lda #s1 + sta.z printf_str.s+1 + jsr printf_str + // [49] phi from main::@3 to main::@4 [phi:main::@3->main::@4] + // main::@4 + // snprintf(BUF2, 20, "hello %s%c", "world", '!') + // [50] call printf_string + // [101] phi from main::@4 to printf_string [phi:main::@4->printf_string] + // [101] phi printf_string::putc#10 = &snputc [phi:main::@4->printf_string#0] -- pprz1=pprc1 + lda #snputc + sta.z printf_string.putc+1 + // [101] phi printf_string::str#10 = main::str [phi:main::@4->printf_string#1] -- pbuz1=pbuc1 + lda #str + sta.z printf_string.str+1 + jsr printf_string + // main::@5 + // snprintf(BUF2, 20, "hello %s%c", "world", '!') + // [51] stackpush(char) = '!' -- _stackpushbyte_=vbuc1 + lda #'!' + pha + // [52] callexecute snputc -- call_vprc1 + jsr snputc + // sideeffect stackpullbytes(1) -- _stackpullbyte_1 + pla + // [54] stackpush(char) = 0 -- _stackpushbyte_=vbuc1 + lda #0 + pha + // [55] callexecute snputc -- call_vprc1 + jsr snputc + // sideeffect stackpullbytes(1) -- _stackpullbyte_1 + pla + // printf("-%s- -%s-", BUF1, BUF2) + // [57] call printf_str + // [92] phi from main::@5 to printf_str [phi:main::@5->printf_str] + // [92] phi printf_str::putc#8 = &cputc [phi:main::@5->printf_str#0] -- pprz1=pprc1 + lda #cputc + sta.z printf_str.putc+1 + // [92] phi printf_str::s#8 = main::s2 [phi:main::@5->printf_str#1] -- pbuz1=pbuc1 + lda #s2 + sta.z printf_str.s+1 + jsr printf_str + // [58] phi from main::@5 to main::@6 [phi:main::@5->main::@6] + // main::@6 + // printf("-%s- -%s-", BUF1, BUF2) + // [59] call printf_string + // [101] phi from main::@6 to printf_string [phi:main::@6->printf_string] + // [101] phi printf_string::putc#10 = &cputc [phi:main::@6->printf_string#0] -- pprz1=pprc1 + lda #cputc + sta.z printf_string.putc+1 + // [101] phi printf_string::str#10 = BUF1 [phi:main::@6->printf_string#1] -- pbuz1=pbuc1 + lda #BUF1 + sta.z printf_string.str+1 + jsr printf_string + // [60] phi from main::@6 to main::@7 [phi:main::@6->main::@7] + // main::@7 + // printf("-%s- -%s-", BUF1, BUF2) + // [61] call printf_str + // [92] phi from main::@7 to printf_str [phi:main::@7->printf_str] + // [92] phi printf_str::putc#8 = &cputc [phi:main::@7->printf_str#0] -- pprz1=pprc1 + lda #cputc + sta.z printf_str.putc+1 + // [92] phi printf_str::s#8 = main::s3 [phi:main::@7->printf_str#1] -- pbuz1=pbuc1 + lda #s3 + sta.z printf_str.s+1 + jsr printf_str + // [62] phi from main::@7 to main::@8 [phi:main::@7->main::@8] + // main::@8 + // printf("-%s- -%s-", BUF1, BUF2) + // [63] call printf_string + // [101] phi from main::@8 to printf_string [phi:main::@8->printf_string] + // [101] phi printf_string::putc#10 = &cputc [phi:main::@8->printf_string#0] -- pprz1=pprc1 + lda #cputc + sta.z printf_string.putc+1 + // [101] phi printf_string::str#10 = BUF2 [phi:main::@8->printf_string#1] -- pbuz1=pbuc1 + lda #BUF2 + sta.z printf_string.str+1 + jsr printf_string + // [64] phi from main::@8 to main::@9 [phi:main::@8->main::@9] + // main::@9 + // printf("-%s- -%s-", BUF1, BUF2) + // [65] call printf_str + // [92] phi from main::@9 to printf_str [phi:main::@9->printf_str] + // [92] phi printf_str::putc#8 = &cputc [phi:main::@9->printf_str#0] -- pprz1=pprc1 + lda #cputc + sta.z printf_str.putc+1 + // [92] phi printf_str::s#8 = main::s2 [phi:main::@9->printf_str#1] -- pbuz1=pbuc1 + lda #s2 + sta.z printf_str.s+1 + jsr printf_str + // main::@return + // } + // [66] return + rts + .segment Data + s: .text "hello world!" + .byte 0 + s1: .text "hello " + .byte 0 + str: .text "world" + .byte 0 + s2: .text "-" + .byte 0 + s3: .text "- -" + .byte 0 +} +.segment Code + // gotoxy +// Set the cursor to the specified position +// void gotoxy(char x, __register(X) char y) +gotoxy: { + .const x = 0 + .label __5 = $18 + .label __6 = $14 + .label __7 = $14 + .label line_offset = $14 + .label __8 = $16 + .label __9 = $14 + // if(y>CONIO_HEIGHT) + // [67] if(gotoxy::y#2<$19+1) goto gotoxy::@3 -- vbuxx_lt_vbuc1_then_la1 + cpx #$19+1 + bcc __b2 + // [69] phi from gotoxy to gotoxy::@1 [phi:gotoxy->gotoxy::@1] + // [69] phi gotoxy::y#4 = 0 [phi:gotoxy->gotoxy::@1#0] -- vbuxx=vbuc1 + ldx #0 + // [68] phi from gotoxy to gotoxy::@3 [phi:gotoxy->gotoxy::@3] + // gotoxy::@3 + // [69] phi from gotoxy::@3 to gotoxy::@1 [phi:gotoxy::@3->gotoxy::@1] + // [69] phi gotoxy::y#4 = gotoxy::y#2 [phi:gotoxy::@3->gotoxy::@1#0] -- register_copy + // gotoxy::@1 + // gotoxy::@2 + __b2: + // conio_cursor_x = x + // [70] conio_cursor_x = gotoxy::x#2 -- vbuz1=vbuc1 + lda #x + sta.z conio_cursor_x + // conio_cursor_y = y + // [71] conio_cursor_y = gotoxy::y#4 -- vbuz1=vbuxx + stx.z conio_cursor_y + // unsigned int line_offset = (unsigned int)y*CONIO_WIDTH + // [72] gotoxy::$7 = (unsigned int)gotoxy::y#4 -- vwuz1=_word_vbuxx + txa + sta.z __7 + lda #0 + sta.z __7+1 + // [73] gotoxy::$8 = gotoxy::$7 << 2 -- vwuz1=vwuz2_rol_2 + lda.z __7 + asl + sta.z __8 + lda.z __7+1 + rol + sta.z __8+1 + asl.z __8 + rol.z __8+1 + // [74] gotoxy::$9 = gotoxy::$8 + gotoxy::$7 -- vwuz1=vwuz2_plus_vwuz1 + clc + lda.z __9 + adc.z __8 + sta.z __9 + lda.z __9+1 + adc.z __8+1 + sta.z __9+1 + // [75] gotoxy::line_offset#0 = gotoxy::$9 << 3 -- vwuz1=vwuz1_rol_3 + asl.z line_offset + rol.z line_offset+1 + asl.z line_offset + rol.z line_offset+1 + asl.z line_offset + rol.z line_offset+1 + // CONIO_SCREEN_TEXT + line_offset + // [76] gotoxy::$5 = DEFAULT_SCREEN + gotoxy::line_offset#0 -- pbuz1=pbuc1_plus_vwuz2 + lda.z line_offset + clc + adc #DEFAULT_SCREEN + sta.z __5+1 + // conio_line_text = CONIO_SCREEN_TEXT + line_offset + // [77] conio_line_text = gotoxy::$5 -- pbuz1=pbuz2 + lda.z __5 + sta.z conio_line_text + lda.z __5+1 + sta.z conio_line_text+1 + // CONIO_SCREEN_COLORS + line_offset + // [78] gotoxy::$6 = COLORRAM + gotoxy::line_offset#0 -- pbuz1=pbuc1_plus_vwuz1 + lda.z __6 + clc + adc #COLORRAM + sta.z __6+1 + // conio_line_color = CONIO_SCREEN_COLORS + line_offset + // [79] conio_line_color = gotoxy::$6 -- pbuz1=pbuz2 + lda.z __6 + sta.z conio_line_color + lda.z __6+1 + sta.z conio_line_color+1 + // gotoxy::@return + // } + // [80] return + rts +} + // cputln +// Print a newline +cputln: { + // conio_line_text += CONIO_WIDTH + // [81] conio_line_text = conio_line_text + $28 -- pbuz1=pbuz1_plus_vbuc1 + lda #$28 + clc + adc.z conio_line_text + sta.z conio_line_text + bcc !+ + inc.z conio_line_text+1 + !: + // conio_line_color += CONIO_WIDTH + // [82] conio_line_color = conio_line_color + $28 -- pbuz1=pbuz1_plus_vbuc1 + lda #$28 + clc + adc.z conio_line_color + sta.z conio_line_color + bcc !+ + inc.z conio_line_color+1 + !: + // conio_cursor_x = 0 + // [83] conio_cursor_x = 0 -- vbuz1=vbuc1 + lda #0 + sta.z conio_cursor_x + // conio_cursor_y++; + // [84] conio_cursor_y = ++ conio_cursor_y -- vbuz1=_inc_vbuz1 + inc.z conio_cursor_y + // cscroll() + // [85] call cscroll + jsr cscroll + // cputln::@return + // } + // [86] return + rts +} + // snprintf_init +/// Initialize the snprintf() state +// void snprintf_init(__zp(2) char *s, unsigned int n) +snprintf_init: { + .label s = 2 + // __snprintf_capacity = n + // [88] __snprintf_capacity = $14 -- vwuz1=vbuc1 + lda #<$14 + sta.z __snprintf_capacity + lda #>$14 + sta.z __snprintf_capacity+1 + // __snprintf_size = 0 + // [89] __snprintf_size = 0 -- vwuz1=vbuc1 + lda #<0 + sta.z __snprintf_size + sta.z __snprintf_size+1 + // __snprintf_buffer = s + // [90] __snprintf_buffer = snprintf_init::s#2 -- pbuz1=pbuz2 + lda.z s + sta.z __snprintf_buffer + lda.z s+1 + sta.z __snprintf_buffer+1 + // snprintf_init::@return + // } + // [91] return + rts +} + // printf_str +/// Print a NUL-terminated string +// void printf_str(__zp(2) void (*putc)(char), __zp(4) const char *s) +printf_str: { + .label s = 4 + .label putc = 2 + // [93] phi from printf_str printf_str::@2 to printf_str::@1 [phi:printf_str/printf_str::@2->printf_str::@1] + // [93] phi printf_str::s#7 = printf_str::s#8 [phi:printf_str/printf_str::@2->printf_str::@1#0] -- register_copy + // printf_str::@1 + __b1: + // while(c=*s++) + // [94] printf_str::c#1 = *printf_str::s#7 -- vbuaa=_deref_pbuz1 + ldy #0 + lda (s),y + // [95] printf_str::s#0 = ++ printf_str::s#7 -- pbuz1=_inc_pbuz1 + inc.z s + bne !+ + inc.z s+1 + !: + // [96] if(0!=printf_str::c#1) goto printf_str::@2 -- 0_neq_vbuaa_then_la1 + cmp #0 + bne __b2 + // printf_str::@return + // } + // [97] return + rts + // printf_str::@2 + __b2: + // putc(c) + // [98] stackpush(char) = printf_str::c#1 -- _stackpushbyte_=vbuaa + pha + // [99] callexecute *printf_str::putc#8 -- call__deref_pprz1 + jsr icall4 + // sideeffect stackpullbytes(1) -- _stackpullbyte_1 + pla + jmp __b1 + // Outside Flow + icall4: + jmp (putc) +} + // printf_string +// Print a string value using a specific format +// Handles justification and min length +// void printf_string(__zp(2) void (*putc)(char), __zp(4) char *str, char format_min_length, char format_justify_left) +printf_string: { + .label putc = 2 + .label str = 4 + // printf_string::@1 + // printf_str(putc, str) + // [102] printf_str::putc#0 = printf_string::putc#10 + // [103] printf_str::s#1 = printf_string::str#10 + // [104] call printf_str + // [92] phi from printf_string::@1 to printf_str [phi:printf_string::@1->printf_str] + // [92] phi printf_str::putc#8 = printf_str::putc#0 [phi:printf_string::@1->printf_str#0] -- register_copy + // [92] phi printf_str::s#8 = printf_str::s#1 [phi:printf_string::@1->printf_str#1] -- register_copy + jsr printf_str + // printf_string::@return + // } + // [105] return + rts +} + // cscroll +// Scroll the entire screen if the cursor is beyond the last line +cscroll: { + // if(conio_cursor_y==CONIO_HEIGHT) + // [106] if(conio_cursor_y!=$19) goto cscroll::@return -- vbuz1_neq_vbuc1_then_la1 + lda #$19 + cmp.z conio_cursor_y + bne __breturn + // [107] phi from cscroll to cscroll::@1 [phi:cscroll->cscroll::@1] + // cscroll::@1 + // memcpy(CONIO_SCREEN_TEXT, CONIO_SCREEN_TEXT+CONIO_WIDTH, CONIO_BYTES-CONIO_WIDTH) + // [108] call memcpy + // [119] phi from cscroll::@1 to memcpy [phi:cscroll::@1->memcpy] + // [119] phi memcpy::destination#2 = (void *)DEFAULT_SCREEN [phi:cscroll::@1->memcpy#0] -- pvoz1=pvoc1 + lda #DEFAULT_SCREEN + sta.z memcpy.destination+1 + // [119] phi memcpy::source#2 = (void *)DEFAULT_SCREEN+$28 [phi:cscroll::@1->memcpy#1] -- pvoz1=pvoc1 + lda #DEFAULT_SCREEN+$28 + sta.z memcpy.source+1 + jsr memcpy + // [109] phi from cscroll::@1 to cscroll::@2 [phi:cscroll::@1->cscroll::@2] + // cscroll::@2 + // memcpy(CONIO_SCREEN_COLORS, CONIO_SCREEN_COLORS+CONIO_WIDTH, CONIO_BYTES-CONIO_WIDTH) + // [110] call memcpy + // [119] phi from cscroll::@2 to memcpy [phi:cscroll::@2->memcpy] + // [119] phi memcpy::destination#2 = (void *)COLORRAM [phi:cscroll::@2->memcpy#0] -- pvoz1=pvoc1 + lda #COLORRAM + sta.z memcpy.destination+1 + // [119] phi memcpy::source#2 = (void *)COLORRAM+$28 [phi:cscroll::@2->memcpy#1] -- pvoz1=pvoc1 + lda #COLORRAM+$28 + sta.z memcpy.source+1 + jsr memcpy + // [111] phi from cscroll::@2 to cscroll::@3 [phi:cscroll::@2->cscroll::@3] + // cscroll::@3 + // memset(CONIO_SCREEN_TEXT+CONIO_BYTES-CONIO_WIDTH, ' ', CONIO_WIDTH) + // [112] call memset + // [129] phi from cscroll::@3 to memset [phi:cscroll::@3->memset] + // [129] phi memset::c#4 = ' ' [phi:cscroll::@3->memset#0] -- vbuxx=vbuc1 + ldx #' ' + // [129] phi memset::str#3 = (void *)DEFAULT_SCREEN+(unsigned int)$19*$28-$28 [phi:cscroll::@3->memset#1] -- pvoz1=pvoc1 + lda #DEFAULT_SCREEN+$19*$28-$28 + sta.z memset.str+1 + jsr memset + // [113] phi from cscroll::@3 to cscroll::@4 [phi:cscroll::@3->cscroll::@4] + // cscroll::@4 + // memset(CONIO_SCREEN_COLORS+CONIO_BYTES-CONIO_WIDTH, conio_textcolor, CONIO_WIDTH) + // [114] call memset + // [129] phi from cscroll::@4 to memset [phi:cscroll::@4->memset] + // [129] phi memset::c#4 = LIGHT_BLUE [phi:cscroll::@4->memset#0] -- vbuxx=vbuc1 + ldx #LIGHT_BLUE + // [129] phi memset::str#3 = (void *)COLORRAM+(unsigned int)$19*$28-$28 [phi:cscroll::@4->memset#1] -- pvoz1=pvoc1 + lda #COLORRAM+$19*$28-$28 + sta.z memset.str+1 + jsr memset + // cscroll::@5 + // conio_line_text -= CONIO_WIDTH + // [115] conio_line_text = conio_line_text - $28 -- pbuz1=pbuz1_minus_vbuc1 + sec + lda.z conio_line_text + sbc #$28 + sta.z conio_line_text + lda.z conio_line_text+1 + sbc #0 + sta.z conio_line_text+1 + // conio_line_color -= CONIO_WIDTH + // [116] conio_line_color = conio_line_color - $28 -- pbuz1=pbuz1_minus_vbuc1 + sec + lda.z conio_line_color + sbc #$28 + sta.z conio_line_color + lda.z conio_line_color+1 + sbc #0 + sta.z conio_line_color+1 + // conio_cursor_y--; + // [117] conio_cursor_y = -- conio_cursor_y -- vbuz1=_dec_vbuz1 + dec.z conio_cursor_y + // cscroll::@return + __breturn: + // } + // [118] return + rts +} + // memcpy +// Copy block of memory (forwards) +// Copies the values of num bytes from the location pointed to by source directly to the memory block pointed to by destination. +// void * memcpy(__zp($1c) void *destination, __zp(6) void *source, unsigned int num) +memcpy: { + .label src_end = $1a + .label dst = $1c + .label src = 6 + .label source = 6 + .label destination = $1c + // char* src_end = (char*)source+num + // [120] memcpy::src_end#0 = (char *)memcpy::source#2 + (unsigned int)$19*$28-$28 -- pbuz1=pbuz2_plus_vwuc1 + lda.z source + clc + adc #<$19*$28-$28 + sta.z src_end + lda.z source+1 + adc #>$19*$28-$28 + sta.z src_end+1 + // [121] memcpy::src#4 = (char *)memcpy::source#2 + // [122] memcpy::dst#4 = (char *)memcpy::destination#2 + // [123] phi from memcpy memcpy::@2 to memcpy::@1 [phi:memcpy/memcpy::@2->memcpy::@1] + // [123] phi memcpy::dst#2 = memcpy::dst#4 [phi:memcpy/memcpy::@2->memcpy::@1#0] -- register_copy + // [123] phi memcpy::src#2 = memcpy::src#4 [phi:memcpy/memcpy::@2->memcpy::@1#1] -- register_copy + // memcpy::@1 + __b1: + // while(src!=src_end) + // [124] if(memcpy::src#2!=memcpy::src_end#0) goto memcpy::@2 -- pbuz1_neq_pbuz2_then_la1 + lda.z src+1 + cmp.z src_end+1 + bne __b2 + lda.z src + cmp.z src_end + bne __b2 + // memcpy::@return + // } + // [125] return + rts + // memcpy::@2 + __b2: + // *dst++ = *src++ + // [126] *memcpy::dst#2 = *memcpy::src#2 -- _deref_pbuz1=_deref_pbuz2 + ldy #0 + lda (src),y + sta (dst),y + // *dst++ = *src++; + // [127] memcpy::dst#1 = ++ memcpy::dst#2 -- pbuz1=_inc_pbuz1 + inc.z dst + bne !+ + inc.z dst+1 + !: + // [128] memcpy::src#1 = ++ memcpy::src#2 -- pbuz1=_inc_pbuz1 + inc.z src + bne !+ + inc.z src+1 + !: + jmp __b1 +} + // memset +// Copies the character c (an unsigned char) to the first num characters of the object pointed to by the argument str. +// void * memset(__zp(6) void *str, __register(X) char c, unsigned int num) +memset: { + .label end = $1c + .label dst = 6 + .label str = 6 + // memset::@1 + // char* end = (char*)str + num + // [130] memset::end#0 = (char *)memset::str#3 + $28 -- pbuz1=pbuz2_plus_vbuc1 + lda #$28 + clc + adc.z str + sta.z end + lda #0 + adc.z str+1 + sta.z end+1 + // [131] memset::dst#4 = (char *)memset::str#3 + // [132] phi from memset::@1 memset::@3 to memset::@2 [phi:memset::@1/memset::@3->memset::@2] + // [132] phi memset::dst#2 = memset::dst#4 [phi:memset::@1/memset::@3->memset::@2#0] -- register_copy + // memset::@2 + __b2: + // for(char* dst = str; dst!=end; dst++) + // [133] if(memset::dst#2!=memset::end#0) goto memset::@3 -- pbuz1_neq_pbuz2_then_la1 + lda.z dst+1 + cmp.z end+1 + bne __b3 + lda.z dst + cmp.z end + bne __b3 + // memset::@return + // } + // [134] return + rts + // memset::@3 + __b3: + // *dst = c + // [135] *memset::dst#2 = memset::c#4 -- _deref_pbuz1=vbuxx + txa + ldy #0 + sta (dst),y + // for(char* dst = str; dst!=end; dst++) + // [136] memset::dst#1 = ++ memset::dst#2 -- pbuz1=_inc_pbuz1 + inc.z dst + bne !+ + inc.z dst+1 + !: + jmp __b2 +} + // File Data +.segment Data + BUF1: .fill $14, 0 + BUF2: .fill $14, 0 + diff --git a/src/test/ref/printf-18.sym b/src/test/ref/printf-18.sym new file mode 100644 index 000000000..c39535f88 --- /dev/null +++ b/src/test/ref/printf-18.sym @@ -0,0 +1,130 @@ +__constant char BUF1[$14] = { fill( $14, 0) } +__constant char BUF2[$14] = { fill( $14, 0) } +__constant char * const COLORRAM = (char *) 55296 +__constant char * const DEFAULT_SCREEN = (char *) 1024 +__constant const char LIGHT_BLUE = $e +__constant char RADIX::BINARY = 2 +__constant char RADIX::DECIMAL = $a +__constant char RADIX::HEXADECIMAL = $10 +__constant char RADIX::OCTAL = 8 +__constant unsigned int STACK_BASE = $103 +__loadstore char *__snprintf_buffer // zp[2]:18 16.916666666666664 +__loadstore volatile unsigned int __snprintf_capacity // zp[2]:14 11.730769230769232 +__loadstore volatile unsigned int __snprintf_size // zp[2]:16 20.279999999999998 +void __start() +void conio_c64_init() +__constant char * const conio_c64_init::BASIC_CURSOR_LINE = (char *) 214 +char conio_c64_init::line +char conio_c64_init::line#0 // reg byte x 11.0 +char conio_c64_init::line#2 // reg byte x 22.0 +__loadstore char conio_cursor_x // zp[1]:8 24.799999999999997 +__loadstore char conio_cursor_y // zp[1]:9 18.608695652173914 +__loadstore char *conio_line_color // zp[2]:12 14.954545454545453 +__loadstore char *conio_line_text // zp[2]:10 15.666666666666668 +__stackcall void cputc(char c) +__constant char cputc::OFFSET_STACK_C = 0 +char cputc::c +char cputc::c#0 // reg byte a 3.0 +void cputln() +void cscroll() +void gotoxy(char x , char y) +char *gotoxy::$5 // zp[2]:24 202.0 +char *gotoxy::$6 // zp[2]:20 202.0 +unsigned int gotoxy::$7 // zp[2]:20 151.5 +unsigned int gotoxy::$8 // zp[2]:22 202.0 +unsigned int gotoxy::$9 // zp[2]:20 202.0 +unsigned int gotoxy::line_offset +unsigned int gotoxy::line_offset#0 // line_offset zp[2]:20 101.0 +char gotoxy::x +__constant char gotoxy::x#2 = 0 // x +char gotoxy::y +char gotoxy::y#2 // reg byte x 71.0 +char gotoxy::y#4 // reg byte x 67.33333333333333 +void main() +__constant char main::s[$d] = "hello world!" +__constant char main::s1[7] = "hello " +__constant char main::s2[2] = "-" +__constant char main::s3[4] = "- -" +__constant char main::str[6] = "world" +void * memcpy(void *destination , void *source , unsigned int num) +void *memcpy::destination +void *memcpy::destination#2 // destination zp[2]:28 +char *memcpy::dst +char *memcpy::dst#1 // dst zp[2]:28 10001.0 +char *memcpy::dst#2 // dst zp[2]:28 10334.666666666666 +char *memcpy::dst#4 // dst zp[2]:28 2002.0 +unsigned int memcpy::num +void *memcpy::return +void *memcpy::source +void *memcpy::source#2 // source zp[2]:6 +char *memcpy::src +char *memcpy::src#1 // src zp[2]:6 20002.0 +char *memcpy::src#2 // src zp[2]:6 10251.25 +char *memcpy::src#4 // src zp[2]:6 1001.0 +char *memcpy::src_end +char *memcpy::src_end#0 // src_end zp[2]:26 1375.25 +void * memset(void *str , char c , unsigned int num) +char memset::c +char memset::c#4 // reg byte x 1428.7142857142858 +char *memset::dst +char *memset::dst#1 // dst zp[2]:6 20002.0 +char *memset::dst#2 // dst zp[2]:6 13668.333333333332 +char *memset::dst#4 // dst zp[2]:6 2002.0 +char *memset::end +char *memset::end#0 // end zp[2]:28 1833.6666666666665 +unsigned int memset::num +void *memset::return +void *memset::str +void *memset::str#3 // str zp[2]:6 +void printf_str(void (*putc)(char) , const char *s) +char printf_str::c +char printf_str::c#1 // reg byte a 10001.0 +void (*printf_str::putc)(char) +void (*printf_str::putc#0)(char) // putc zp[2]:2 101.0 +void (*printf_str::putc#8)(char) // putc zp[2]:2 1010.0 +const char *printf_str::s +const char *printf_str::s#0 // s zp[2]:4 10001.0 +const char *printf_str::s#1 // s zp[2]:4 202.0 +const char *printf_str::s#7 // s zp[2]:4 15502.0 +const char *printf_str::s#8 // s zp[2]:4 1102.0 +void printf_string(void (*putc)(char) , char *str , char format_min_length , char format_justify_left) +struct printf_format_string printf_string::format +char printf_string::format_justify_left +char printf_string::format_min_length +signed char printf_string::len +signed char printf_string::padding +void (*printf_string::putc)(char) +void (*printf_string::putc#10)(char) // putc zp[2]:2 101.0 +char *printf_string::str +char *printf_string::str#10 // str zp[2]:4 50.5 +void snprintf_init(char *s , unsigned int n) +unsigned int snprintf_init::n +char *snprintf_init::s +char *snprintf_init::s#2 // s zp[2]:2 33.666666666666664 +__stackcall void snputc(char c) +__constant char snputc::OFFSET_STACK_C = 0 +char snputc::c +char snputc::c#0 // reg byte x 40.4 +char snputc::c#2 // reg byte x 202.0 + +reg byte x [ snputc::c#2 snputc::c#0 ] +reg byte x [ conio_c64_init::line#2 conio_c64_init::line#0 ] +reg byte x [ gotoxy::y#4 gotoxy::y#2 ] +zp[2]:2 [ printf_str::putc#8 printf_str::putc#0 printf_string::putc#10 snprintf_init::s#2 ] +zp[2]:4 [ printf_str::s#7 printf_str::s#8 printf_str::s#1 printf_str::s#0 printf_string::str#10 ] +zp[2]:6 [ memset::str#3 memset::dst#2 memset::dst#4 memset::dst#1 memcpy::source#2 memcpy::src#2 memcpy::src#4 memcpy::src#1 ] +reg byte x [ memset::c#4 ] +zp[1]:8 [ conio_cursor_x ] +zp[1]:9 [ conio_cursor_y ] +zp[2]:10 [ conio_line_text ] +zp[2]:12 [ conio_line_color ] +zp[2]:14 [ __snprintf_capacity ] +zp[2]:16 [ __snprintf_size ] +zp[2]:18 [ __snprintf_buffer ] +reg byte a [ cputc::c#0 ] +zp[2]:20 [ gotoxy::$7 gotoxy::$9 gotoxy::line_offset#0 gotoxy::$6 ] +zp[2]:22 [ gotoxy::$8 ] +zp[2]:24 [ gotoxy::$5 ] +reg byte a [ printf_str::c#1 ] +zp[2]:26 [ memcpy::src_end#0 ] +zp[2]:28 [ memset::end#0 memcpy::destination#2 memcpy::dst#2 memcpy::dst#4 memcpy::dst#1 ]