Revision 26017
- Date:
- 2009/03/28 02:04:11
- Files:
Legend:
- Added
- Removed
- Modified
-
misc/elfish/showcode/Makefile
1 1 2 P6=../../elf/elf_f 3 ElfSrc=../../elf/elf_f_src/ 4 ElfOriginal=$(ElfSrc)/Elf_Faster.pm 2 P6=../../elf/elf_h 3 export ELF_STD_RED_RUN := ../../STD_red/STD_red_run 5 4 6 showcode: check_path_to_STD_red_run Makefile elf_core.p5 ShowCode.pm 7 cp elf_core.p5 showcode 8 $(P6) -s -o deleteme_code ShowCode.pm 9 cat deleteme_code >> showcode 10 rm deleteme_code 5 showcode: Makefile ShowCode.pm 6 $(P6) -x -o showcode -I ../../elf/elf_h_src -e 'use Elf_wo_main' ShowCode.pm 11 7 chmod a+x showcode 12 8 13 elf_core.p5: $(P6) 14 grep -v CommandLine $(ElfOriginal) > ElfCore.pm 15 $(P6) -x -o elf_core.p5 -I $(ElfSrc) ElfCore.pm 16 17 check_path_to_STD_red_run: 18 # Checking for ELF_STD_RED_RUN=../../STD_red/STD_red_run 19 perl -we 'exit(1) if !-f shift;' $(ELF_STD_RED_RUN) 20 $(ELF_STD_RED_RUN) -e say 3 > /dev/null 21 22 9 demo: showcode 23 10 ./showcode ShowCode.pm > tmp.html 24 11 firefox tmp.html -
misc/elfish/showcode/README
3 3 4 4 click. 5 5 6 7 Clicking in one pane should highlight all three. 8 On a firefox 3.0, things are a bit flakey, and firebug flags an error. 9 When clicking in the IR pane, clicking on field values seems to work best. 10 Yes, the code is blecherous. It was all a one evening hack. 11 6 12 TODO 7 13 - Include the IR analysis info. Which was the primary motivation for this hack. -
misc/elfish/showcode/ShowCode.pm
4 4 5 5 package GLOBAL { #sigh 6 6 sub quote ($s) { 7 $s.re_gsub(/ /,' ').re_gsub(/</,'<').re_gsub(/>/,'>'); 7 $s.re_gsub(' ',' ').re_gsub('<','<').re_gsub('>','>'); 8 8 } 9 9 } 10 10 sub text_pane () { … … 14 14 $line++; 15 15 my $s = '<span id=line'~$line~' class=ln>'; 16 16 my $num = sprintf('%3d ',$line); 17 $num.re_gsub(/ /,' '); 17 $num.re_gsub(' ',' '); 18 18 '<span id=lnN'~$line~' class=lineNum>'~$num~'</span>'~$s; 19 19 }; 20 20 my $txt = ""; 21 21 $txt = $txt~$line_start.(); 22 $txt = $txt ~ $code.split(//).map(sub($e){ 22 $txt = $txt ~ $code.split('').map(sub ($e){ 23 23 $n++; 24 24 my $pre = ""; 25 25 my $post = ""; … … 103 103 $Main::ir_counter = 1; 104 104 $Main::matches = []; 105 105 $Main::irnodes = []; 106 my $parse = $*parser1.parse($code,$filename); 107 my $ir = $parse.make_ir_from_Match_tree(); 106 my $tree = $*parser1.parse($code,$filename); 107 temp $main::irbuilder = $*ast2ir_1; 108 my $ir = $tree.make_ir_from_Match_tree(); 108 109 $ir.do_all_analysis(); 109 110 110 111 sub ast_pane { 111 my $s = '<small><pre>'~$parse.match_foo~'</pre></small>'; 112 my $s = '<small><pre>'~$tree.match_foo~'</pre></small>'; 112 113 my $id2r = ' 113 114 range_from_id = [] 114 '~ $Main::matches.map(sub($e){ 115 '~ $Main::matches.map(sub ($e){ 115 116 my $id = $e[0]; 116 117 my $m = $e[1]; 117 118 'range_from_id["'~$id~'"] = ['~$m.from~','~$m.to~']' … … 125 126 } 126 127 //Ast.prototype.covers = function(n) { return (this.from <= n && n <= this.to) } 127 128 var all_asts = [ 128 '~ $Main::matches.map(sub($e){ 129 '~ $Main::matches.map(sub ($e){ 129 130 my $id = $e[0]; 130 131 my $m = $e[1]; 131 132 '(new Ast("'~$id~'",'~$m.from~','~$m.to~'))' … … 215 216 <small><pre>'~$ir.irx1_foo~'</pre></small>'; 216 217 my $id2r = ' 217 218 range_from_id = [] 218 '~ $Main::irnodes.map(sub($e){ 219 '~ $Main::irnodes.map(sub ($e){ 219 220 my $id = $e[0]; 220 221 my $ir = $e[1]; 221 222 my $m = $ir.match; … … 230 231 } 231 232 //Ir.prototype.covers = function(n) { return (this.from <= n && n <= this.to) } 232 233 var all_asts = [ 233 '~ $Main::irnodes.map(sub($e){ 234 '~ $Main::irnodes.map(sub ($e){ 234 235 my $id = $e[0]; 235 236 my $ir = $e[1]; 236 237 my $m = $ir.match; … … 343 344 #my $s = $.rule~"<"~$.from~","~$.to~",'"~$.str~"',{"; 344 345 my $id = 'm'~$Main::match_counter++; 345 346 $Main::matches.push([$id,self]); 346 my $s = "<span id="~$id~' class=m onclick="mClick(event)">'~$.rule~"<"~$.from~","~$.to~",'...',{"; 347 for $.hash.keys { 347 my $s = "<span id="~$id~' class=m onclick="mClick(event)">'~$.match_rule~"<"~$.from~","~$.to~",'...',{"; 348 for $.match_hash.keys { 348 349 my $k = $_; 349 my $v = $.hash{$k}; 350 my $v = $.match_hash{$k}; 350 351 my $vs = 'undef'; 351 352 if defined($v) { 352 353 $vs = $v.match_foo; 353 354 } 354 355 $s = $s ~ "\n "~$k~" => "~self.indent_except_top($vs)~","; 355 356 } 356 if $.hash.keys.elems {$s = $s ~ "\n"} 357 if $.match_hash.keys.elems {$s = $s ~ "\n"} 357 358 $s = $s ~ "}></span>"; 358 359 } 359 360 } 360 361 class ARRAY { 361 362 method match_foo() { 362 363 ("[\n" ~ 363 Match.indent(self.map(sub($e){$e.match_foo}).join(",\n")) ~ 364 Match.indent(self.map(sub ($e){$e.match_foo}).join(",\n")) ~ 364 365 "\n]") 365 366 } 366 367 }; … … 383 384 class STRING { 384 385 method match_foo() { 385 386 my $s = self; 386 if $s.length > 30 { $s = $s.substr(0,20)~"..."; } 387 if $s.chars > 30 { $s = $s.substr(0,20)~"..."; } 387 388 "'"~quote($s)~"'" 388 389 } 389 390 } … … 415 416 $s = $s ~ "\n"; 416 417 my $vs = ""; 417 418 my $names = $.field_names(); 418 my $values = $.field_values().map(sub($e){$e.irx1_foo()}); 419 my $values = $.field_values().map(sub ($e){$e.irx1_foo()}); 419 420 loop (my $i=0; $i < $names.elems; $i++) { 420 421 $vs = $vs ~ '<span class=irfn onclick="iClick(event,'~$id~')">'~$names[$i]~'</span> '~Match.indent_except_top($values[$i])~"\n"; 421 422 } … … 446 447 package ARRAY { 447 448 method irx1_foo() { 448 449 ("[\n" ~ 449 Match.indent(self.map(sub($e){$e.irx1_foo}).join(",\n")) ~ 450 Match.indent(self.map(sub ($e){$e.irx1_foo}).join(",\n")) ~ 450 451 "\n]") 451 452 }; 452 453 }; 453 454 package STRING { 454 455 method irx1_foo() { 455 456 my $s = self; 456 if $s.length > 30 { $s = $s.substr(0,20)~"..."; } 457 if $s.chars > 30 { $s = $s.substr(0,20)~"..."; } 457 458 "'"~quote($s)~"'" 458 459 }; 459 460 };