#!/usr/bin/perl -w # Forked from mile25_bytecode_test.pl to account for one extra # character not supported by tcc. # # o = +82 # ' -> oo< # $ -> oo9 # # -> oo8 # ` -> oou use strict; # Return true if input byte is acceptable to be used in a string. Byte is # acceptable if it is printable, and it is not going to be a character # that will cause trouble when used as a preprocessor macro argument. sub is_acceptable($) { my ($byte) = @_; return $byte > 32 && $byte < 127 && index("\"\\,()'\$`", chr($byte)) < 0; } # Search through all possible offsets and print the ones that have a # proper encoding for each byte. for(my $offset = 1; $offset < 5 * 37; $offset++) { my $table = ""; my $errors = 0; for(my $i = 9; $i < 5 * 37; $i++) { # Skip over bytes that will not be used by our bytecode. if( $i == 37 || $i == 2 * 37 || $i == 3 * 37 || ($i > 4 * 37 && $i < 4 * 37 + 19) || $i > 4 * 37 + 19 ) { next; } # ($offset * $prefix + x) % (5 * 37) == $i # ($offset * $prefix + x) == $i + 5 * 37 * N # $byte = $i - $offset * $prefix + 5 * 37 * N my $prefix = 0; my $byte; for(; $prefix < 5; $prefix++) { $byte = $i - $offset * $prefix; while( $byte < 0 ) { $byte += 5 * 37; } last if is_acceptable($byte); } if( is_acceptable($byte) ) { $table .= ('o' x $prefix) . chr($byte); } else { $errors++; } } next if $errors > 0; printf 'offset = %3d, table = %3d: ', $offset, length($table); print "$table\n"; }