From 6d223dc85d437c69b4b41993f7cee655d5b10dce Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 13 Jul 2011 00:19:05 +0200 Subject: [PATCH] last fixes --- compile.php | 32 ++++++++++----- css/style.css | 4 ++ examples/{ex3.c => arit.c} | 0 examples/ex5.c | 80 -------------------------------------- examples/{ex2.c => fib.c} | 0 examples/if.c | 19 +++++++++ examples/{ex4.c => int.c} | 0 examples/{ex1.c => loop.c} | 0 examples/switch.c | 29 ++++++++++++++ index.html | 13 ++++--- js/script.js | 51 +++++++++++++----------- 11 files changed, 111 insertions(+), 117 deletions(-) rename examples/{ex3.c => arit.c} (100%) delete mode 100644 examples/ex5.c rename examples/{ex2.c => fib.c} (100%) create mode 100644 examples/if.c rename examples/{ex4.c => int.c} (100%) rename examples/{ex1.c => loop.c} (100%) create mode 100644 examples/switch.c diff --git a/compile.php b/compile.php index 98973e4..b1750ee 100644 --- a/compile.php +++ b/compile.php @@ -24,7 +24,22 @@ elseif (strlen($code) > $maxLength) { else { // compile $outFile = tempnam('/tmp', 'tc_out_'); - $disableOptimize = ' -O0 -fno-align-loops -fno-argument-alias -fno-auto-inc-dec -fno-branch-count-reg -fno-common -fno-early-inlining -fno-eliminate-unused-debug-types -fno-function-cse -fno-gcse-lm -fno-ident -fno-ivopts -fno-keep-static-consts -fno-leading-underscore -fmath-errno -fno-merge-debug-strings -fno-move-loop-invariants -fpeephole -fno-reg-struct-return -fno-sched-interblock -fno-sched-spec -fno-sched-stalled-insns-dep -fno-signed-zeros -fno-split-ivs-in-unroller -fno-toplevel-reorder -fno-trapping-math -fno-tree-cselim -fno-tree-loop-im -fno-tree-loop-ivcanon -fno-tree-loop-optimize -fno-tree-reassoc -fno-tree-scev-cprop -fno-tree-vect-loop-version -fno-var-tracking -fno-verbose-asm -fno-zero-initialized-in-bss -fno-argument-noalias -fno-math-errno -fno-pcc-struct-return -fno-peephole'; + $disableOptimize = ' -O0 -fno-align-loops -fno-argument-alias' . + ' -fno-auto-inc-dec -fno-branch-count-reg -fno-common' . + ' -fno-early-inlining -fno-eliminate-unused-debug-types' . + ' -fno-function-cse -fno-gcse-lm -fno-ident -fno-ivopts' . + ' -fno-keep-static-consts -fno-leading-underscore' . + ' -fmath-errno -fno-merge-debug-strings' . + ' -fno-move-loop-invariants -fpeephole -fno-reg-struct-return' . + ' -fno-sched-interblock -fno-sched-spec -fno-sched-stalled-insns-dep' . + ' -fno-signed-zeros -fno-split-ivs-in-unroller' . + ' -fno-toplevel-reorder -fno-trapping-math -fno-tree-cselim' . + ' -fno-tree-loop-im -fno-tree-loop-ivcanon -fno-tree-loop-optimize' . + ' -fno-tree-reassoc -fno-tree-scev-cprop -fno-tree-vect-loop-version' . + ' -fno-var-tracking -fno-verbose-asm -fno-zero-initialized-in-bss' . + ' -fno-argument-noalias -fno-math-errno' . + ' -fno-pcc-struct-return -fno-peephole'; + $cmd = 'avr-gcc -mmcu=' . $mmcu . ' -g3 -o ' . $outFile . ' ' . $codeFile; if ($oLevel < 0) { @@ -42,7 +57,6 @@ else { // refactor $dumpLines = explode("\n", $dump); - $lastMapping = null; $lastLine = null; $assembler = array(); @@ -55,7 +69,6 @@ else { ); foreach ($dumpLines as $line) { // parsing objdump - // if (preg_match( // mnemonic '/^\s{2}([0-9a-f]{2}):\t' . // address \s{2}9a:\ŧ '((?:[0-9a-f]{2}\s)+)\s+' . // byte ec e5\s+\t @@ -80,6 +93,7 @@ else { $assembler[] = $as; $byte[] = format($bytes, $format); $mnemonics[$matches[3]] = (isset($mnemonics[$matches[3]])) ? $mnemonics[$matches[3]] + 1 : 1; + $mapping['assembler'][count($assembler)] = count($byte); $mapping['byte'][count($byte)] = count($assembler); } @@ -133,12 +147,12 @@ function format($data, $format) { }, $data)); } else { // if ($format == 'bin') { default - return implode(' ', array_map(function($value) { - - return str_pad(decbin($value), 4, '0', STR_PAD_LEFT); - }, str_split(implode('', array_map(function($value) { - return str_pad(dechex($value), 2, '0', STR_PAD_LEFT); - }, $data))))); + $bin = array(); + foreach ($data as $byte) { + $bin[] = str_pad(decbin($byte >> 4), 4, '0', STR_PAD_LEFT); // high nipple + $bin[] = str_pad(decbin($byte & 0x0f), 4, '0', STR_PAD_LEFT); // low nipple + } + return implode(' ', $bin); } } diff --git a/css/style.css b/css/style.css index 9304640..8afc060 100755 --- a/css/style.css +++ b/css/style.css @@ -79,6 +79,10 @@ h3 { padding: 6px; } +#stats > div { + display: none; +} + #about { float: right; padding: 3em 1em; diff --git a/examples/ex3.c b/examples/arit.c similarity index 100% rename from examples/ex3.c rename to examples/arit.c diff --git a/examples/ex5.c b/examples/ex5.c deleted file mode 100644 index afc8768..0000000 --- a/examples/ex5.c +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include -/* ADC initialisieren */ -void adc_init(void) { - uint16_t result; - - ADMUX = (0< < 1024 - _delay_ms(adcval/2); // < 5secs - - if (PINA & (1 << 0)) { /* start/pause */ - state.running ^= 0xff; - } - - if (!(PINA & (1 << 1))) { /* change direction */ - PORTC = 0xff; - counter = 0; - state.direction ^= 0xff; - } - - if (state.running) { - counter += (state.direction) ? 1 : -1; - counter %= 8; - PORTC ^= (1 << counter); - } - } -} diff --git a/examples/ex2.c b/examples/fib.c similarity index 100% rename from examples/ex2.c rename to examples/fib.c diff --git a/examples/if.c b/examples/if.c new file mode 100644 index 0000000..924d00e --- /dev/null +++ b/examples/if.c @@ -0,0 +1,19 @@ +#include + +int main ( void ) { + uint8_t a = 2; + uint8_t b = 23; + + again: + + if (a & b) { + b--; + + goto again; + } + else { + a--; + } + + a += b; +} diff --git a/examples/ex4.c b/examples/int.c similarity index 100% rename from examples/ex4.c rename to examples/int.c diff --git a/examples/ex1.c b/examples/loop.c similarity index 100% rename from examples/ex1.c rename to examples/loop.c diff --git a/examples/switch.c b/examples/switch.c new file mode 100644 index 0000000..b1a1e75 --- /dev/null +++ b/examples/switch.c @@ -0,0 +1,29 @@ +#include + +int main ( void ) { + char hello[] = "Hello World!"; + char *str_p = hello; + + uint8_t l_count = 0; + uint8_t o_count = 0; + uint8_t else_count = 0; + + + do { + switch (*str_p) { + case 'o': + o_count++; + break; + + case 'l': + l_count++; + break; + + default: + else_count++; + } + + ++str_p; + } while (*str_p); + +} diff --git a/index.html b/index.html index 77c25eb..8ce8619 100644 --- a/index.html +++ b/index.html @@ -24,11 +24,12 @@
Lade Beispielcode: 
@@ -58,7 +59,7 @@

Options

- +
Kommentare
Kommentare
Maschinencodierung '); + var cLines = $('#ansic textarea').val().split("\n").length; + var asInstr = $('#byte textarea').val().split("\n").length; var max; + var par = $('

') + .html('Dein Code besteht aus ' + cLines + ' Zeilen Code, die in ' + + asInstr + ' Assembler Instruktionen übersetzt werden. Das sind ' + + Math.round(asInstr/cLines) + ' mal mehr Instruktionen als C-Zeilen!'); + var table = $('

'); + for (var mnemonic in stats) { var count = stats[mnemonic]; - if (!max) max = count; table.append( @@ -205,5 +212,5 @@ function renderStats(stats) { ); } - $('#stats div').empty().append(table); + $('#stats div').empty().append(par).append(table); }