Skip to content

Commit

Permalink
Make sure subtracting SizeRanges results in valid SizeRange.
Browse files Browse the repository at this point in the history
  • Loading branch information
dillof committed Mar 28, 2024
1 parent bdfed5f commit 1d73563
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/SizeRange.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ SizeRange SizeRange::operator-(const SizeRange &other) const {
if (!other.maximum) {
return {0, {}};
}
auto new_minimum = minimum - *other.maximum;
auto new_minimum = *other.maximum > minimum ? 0 : minimum - *other.maximum;
if (!maximum) {
return {new_minimum, {}};
}
else {
return {new_minimum, *maximum - other.minimum};
auto new_maximum = other.minimum > *maximum ? 0 : *maximum - other.minimum;
return {new_minimum, std::max(new_minimum, new_maximum)};
}
}

Expand Down
108 changes: 108 additions & 0 deletions tests/long-branch-short.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
arguments --create-library --target 45gs02 a.s
file a.s <inline>
.define YES
.section code
test {
lda drive
bne skip
lda #8
sta drive
skip:
rts
}
test2 {
store_word $5678, drive
lda drive
bne skip
store_word $abcd, drive
skip:
rts
}
test3 {
.if .defined(NO) {
.repeat $80 {
nop
}
}
.if .defined(YES) {
jsr $5678
}
store_word $5678, drive
lda drive
bne skip
store_word $abcd, drive
skip:
rts
}
.macro store_word value, address {
lda #<(value)
sta address
lda #>(value)
sta address + 1
}
drive = $1234
end-of-inline-data
file a.lib {} <inline>
.format_version 1.0
.target "45gs02"
.constant drive {
visibility: private
value: $1234
}
.macro store_word {
visibility: private
arguments: value, address
body <
.data $a9, <value:1
.if .in_range($00, $ff, address) {
.data $85, address:1
}
.else {
.data $8d, address:2
}
.data $a9, >value:1
.if .in_range($00, $ff, (address+$01)) {
.data $85, (address+$01):1
}
.else {
.data $8d, (address+$01):2
}
>
}
.object test {
visibility: private
section: code
body <
.data $ad, $1234, $d0, $05:-1, $a9, $08, $8d, $1234, $60
>
}
.object test2 {
visibility: private
section: code
body <
.scope {
.data $a9, $78, $8d, $1234, $a9, $56, $8d, $1235
}
.data $ad, $1234, $d0, $0a:-1
.scope {
.data $a9, $cd, $8d, $1234, $a9, $ab, $8d, $1235
}
.data $60
>
}
.object test3 {
visibility: private
section: code
body <
.data $20, $5678
.scope {
.data $a9, $78, $8d, $1234, $a9, $56, $8d, $1235
}
.data $ad, $1234, $d0, $0a:-1
.scope {
.data $a9, $cd, $8d, $1234, $a9, $ab, $8d, $1235
}
.data $60
>
}
end-of-inline-data

0 comments on commit 1d73563

Please sign in to comment.