Ticket #688: faster_pbc_to_exe.patch
File faster_pbc_to_exe.patch, 2.1 KB (added by Util, 13 years ago) |
---|
-
tools/dev/pbc_to_exe.pir
172 172 .return(infile, cfile, objfile, exefile) 173 173 .end 174 174 175 # The PBC will be represented as a C string, so this sub builds a table 176 # of the C representation of each ASCII character, for lookup by ordinal value. 177 .sub 'generate_encoding_table' 178 # Use '\%o' for speed, or '\x%02x' for readability 179 .const string encoding_format = '\%o' 180 181 # The 'sprintf' op requires the arglist to be in an array, even when 182 # there is only one arg. 183 .local pmc one_number 184 one_number = new 'FixedIntegerArray' 185 set one_number, 1 186 187 .local pmc coded_strings 188 coded_strings = new 'FixedStringArray' 189 set coded_strings, 256 190 191 .local int index 192 index = 0 193 194 next_index: 195 one_number[0] = index 196 $S0 = sprintf encoding_format, one_number 197 coded_strings[index] = $S0 198 inc index 199 if index < 256 goto next_index 200 201 .return (coded_strings) 202 .end 203 175 204 .sub 'generate_code' 176 205 .param string infile 177 206 .local pmc ifh 178 207 ifh = open infile, 'r' 179 208 unless ifh goto err_infile 209 210 .local pmc encoding_table 211 encoding_table = 'generate_encoding_table'() 212 180 213 .local string codestring 181 214 .local int size 182 codestring = "const Parrot_UInt1 program_code[] = {" 215 codestring = "const char * program_code =\n" 216 codestring .= '"' 183 217 size = 0 184 218 185 219 read_loop: … … 195 229 code_loop: 196 230 unless pos < pbclength goto code_done 197 231 $I0 = ord pbcstring, pos 198 $S0 = $I0232 $S0 = encoding_table[$I0] 199 233 codestring .= $S0 200 codestring .= ','201 234 inc pos 202 235 inc size 203 236 $I0 = size % 32 204 237 unless $I0 == 0 goto code_loop 238 codestring .= '"' 205 239 codestring .= "\n" 240 codestring .= '"' 206 241 goto code_loop 207 242 code_done: 208 243 goto read_loop … … 210 245 read_done: 211 246 close ifh 212 247 213 codestring .= "\n};\n\n" 248 codestring .= '"' 249 codestring .= "\n;\n\n" 214 250 codestring .= "const int bytecode_size = " 215 251 $S0 = size 216 252 codestring .= $S0