mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-25 20:32:25 +00:00
Added test.
This commit is contained in:
parent
48f4e99826
commit
5e18953517
@ -2,4 +2,5 @@
|
||||
/// Functions for performing input and output.
|
||||
|
||||
#include <stddef.h>
|
||||
#include <printf.h>
|
||||
#include <printf.h>
|
||||
#include <snprintf.h>
|
@ -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");
|
||||
|
17
src/test/kc/printf-18.c
Normal file
17
src/test/kc/printf-18.c
Normal file
@ -0,0 +1,17 @@
|
||||
// Tests snprintf function call rewriting
|
||||
// Test snprintf() and printf() in the same file
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
587
src/test/ref/printf-18.asm
Normal file
587
src/test/ref/printf-18.asm
Normal file
@ -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
|
||||
lda #>DEFAULT_SCREEN
|
||||
sta.z conio_line_text+1
|
||||
// __ma char *conio_line_color = CONIO_SCREEN_COLORS
|
||||
lda #<COLORRAM
|
||||
sta.z conio_line_color
|
||||
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
|
||||
lda #>BUF1
|
||||
sta.z snprintf_init.s+1
|
||||
jsr snprintf_init
|
||||
// snprintf(BUF1, 20, "hello world!")
|
||||
lda #<snputc
|
||||
sta.z printf_str.putc
|
||||
lda #>snputc
|
||||
sta.z printf_str.putc+1
|
||||
lda #<s
|
||||
sta.z printf_str.s
|
||||
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
|
||||
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
|
||||
lda #>snputc
|
||||
sta.z printf_str.putc+1
|
||||
lda #<s1
|
||||
sta.z printf_str.s
|
||||
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
|
||||
lda #>snputc
|
||||
sta.z printf_string.putc+1
|
||||
lda #<str
|
||||
sta.z printf_string.str
|
||||
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
|
||||
lda #>cputc
|
||||
sta.z printf_str.putc+1
|
||||
lda #<s2
|
||||
sta.z printf_str.s
|
||||
lda #>s2
|
||||
sta.z printf_str.s+1
|
||||
jsr printf_str
|
||||
// printf("-%s- -%s-", BUF1, BUF2)
|
||||
lda #<cputc
|
||||
sta.z printf_string.putc
|
||||
lda #>cputc
|
||||
sta.z printf_string.putc+1
|
||||
lda #<BUF1
|
||||
sta.z printf_string.str
|
||||
lda #>BUF1
|
||||
sta.z printf_string.str+1
|
||||
jsr printf_string
|
||||
// printf("-%s- -%s-", BUF1, BUF2)
|
||||
lda #<cputc
|
||||
sta.z printf_str.putc
|
||||
lda #>cputc
|
||||
sta.z printf_str.putc+1
|
||||
lda #<s3
|
||||
sta.z printf_str.s
|
||||
lda #>s3
|
||||
sta.z printf_str.s+1
|
||||
jsr printf_str
|
||||
// printf("-%s- -%s-", BUF1, BUF2)
|
||||
lda #<cputc
|
||||
sta.z printf_string.putc
|
||||
lda #>cputc
|
||||
sta.z printf_string.putc+1
|
||||
lda #<BUF2
|
||||
sta.z printf_string.str
|
||||
lda #>BUF2
|
||||
sta.z printf_string.str+1
|
||||
jsr printf_string
|
||||
// printf("-%s- -%s-", BUF1, BUF2)
|
||||
lda #<cputc
|
||||
sta.z printf_str.putc
|
||||
lda #>cputc
|
||||
sta.z printf_str.putc+1
|
||||
lda #<s2
|
||||
sta.z printf_str.s
|
||||
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
|
||||
lda.z line_offset+1
|
||||
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
|
||||
lda.z __6+1
|
||||
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
|
||||
lda #>DEFAULT_SCREEN
|
||||
sta.z memcpy.destination+1
|
||||
lda #<DEFAULT_SCREEN+$28
|
||||
sta.z memcpy.source
|
||||
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
|
||||
lda #>COLORRAM
|
||||
sta.z memcpy.destination+1
|
||||
lda #<COLORRAM+$28
|
||||
sta.z memcpy.source
|
||||
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
|
||||
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
|
||||
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
|
291
src/test/ref/printf-18.cfg
Normal file
291
src/test/ref/printf-18.cfg
Normal file
@ -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
|
4352
src/test/ref/printf-18.log
Normal file
4352
src/test/ref/printf-18.log
Normal file
File diff suppressed because it is too large
Load Diff
130
src/test/ref/printf-18.sym
Normal file
130
src/test/ref/printf-18.sym
Normal file
@ -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 ]
|
Loading…
Reference in New Issue
Block a user