last fixes
This commit is contained in:
parent
81c808ba74
commit
6d223dc85d
11 changed files with 111 additions and 117 deletions
32
compile.php
32
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,6 +79,10 @@ h3 {
|
|||
padding: 6px;
|
||||
}
|
||||
|
||||
#stats > div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#about {
|
||||
float: right;
|
||||
padding: 3em 1em;
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
#include <util/delay.h>
|
||||
#include <avr/io.h>
|
||||
/* ADC initialisieren */
|
||||
void adc_init(void) {
|
||||
uint16_t result;
|
||||
|
||||
ADMUX = (0<<REFS1) | (1<<REFS0); // AVcc als Referenz benutzen
|
||||
// ADMUX = (1<<REFS1) | (1<<REFS0); // interne Referenzspannung nutzen
|
||||
ADCSRA = (1<<ADPS1) | (1<<ADPS0); // Frequenzvorteiler
|
||||
ADCSRA |= (1<<ADEN); // ADC aktivieren
|
||||
|
||||
/* nach Aktivieren des ADC wird ein "Dummy-Readout" empfohlen, man liest
|
||||
also einen Wert und verwirft diesen, um den ADC "warmlaufen zu lassen" */
|
||||
ADCSRA |= (1<<ADSC); // eine ADC-Wandlung
|
||||
while (ADCSRA & (1<<ADSC) ) {} // auf Abschluss der Konvertierung warten
|
||||
|
||||
/* ADCW muss einmal gelesen werden, sonst wird Ergebnis der nächsten
|
||||
Wandlung nicht übernommen. */
|
||||
result = ADCW;
|
||||
}
|
||||
|
||||
/* ADC Einzelmessung */
|
||||
uint16_t adc_read(uint8_t channel) {
|
||||
// Kanal waehlen, ohne andere Bits zu beeinflußen
|
||||
ADMUX = (ADMUX & ~(0x1F)) | (channel & 0x1F);
|
||||
ADCSRA |= (1<<ADSC); // eine Wandlung "single conversion"
|
||||
while (ADCSRA & (1<<ADSC) ) {} // auf Abschluss der Konvertierung warten
|
||||
return ADCW; // ADC auslesen und zurückgeben
|
||||
}
|
||||
|
||||
/* ADC Mehrfachmessung mit Mittelwertbbildung */
|
||||
uint16_t adc_read_avg(uint8_t channel, uint8_t average) {
|
||||
uint32_t result = 0;
|
||||
|
||||
for (uint8_t i = 0; i < average; ++i ) {
|
||||
result += adc_read( channel );
|
||||
}
|
||||
|
||||
return (uint16_t) (result / average);
|
||||
}
|
||||
|
||||
struct state_t {
|
||||
int direction:1;
|
||||
int running:1;
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
uint16_t adcval = 0;
|
||||
uint16_t counter = 0;
|
||||
struct state_t state = {0, 1};
|
||||
|
||||
adc_init();
|
||||
|
||||
/* setup ports */
|
||||
DDRC = 0xff; /* set port A as output */
|
||||
PORTC = 0xff; /* disable output */
|
||||
DDRA = 0x00; /* set port C as input */
|
||||
PORTA = 0xff; /* enable pullups */
|
||||
|
||||
while (1) {
|
||||
adcval = adc_read(7); // 10bit => < 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);
|
||||
}
|
||||
}
|
||||
}
|
19
examples/if.c
Normal file
19
examples/if.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <stdint.h>
|
||||
|
||||
int main ( void ) {
|
||||
uint8_t a = 2;
|
||||
uint8_t b = 23;
|
||||
|
||||
again:
|
||||
|
||||
if (a & b) {
|
||||
b--;
|
||||
|
||||
goto again;
|
||||
}
|
||||
else {
|
||||
a--;
|
||||
}
|
||||
|
||||
a += b;
|
||||
}
|
29
examples/switch.c
Normal file
29
examples/switch.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include <stdint.h>
|
||||
|
||||
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);
|
||||
|
||||
}
|
13
index.html
13
index.html
|
@ -24,11 +24,12 @@
|
|||
<div id="examples">
|
||||
Lade Beispielcode:
|
||||
<select size="1" >
|
||||
<option value="ex1.c">Simple Loop</option>
|
||||
<option value="ex2.c">Fibonacci</option>
|
||||
<option value="ex3.c">Arithmetik</option>
|
||||
<option value="ex4.c">Interrupt</option>
|
||||
<option value="ex5.c">Lauflicht</option>
|
||||
<option value="loop.c">Simple Loop</option>
|
||||
<option value="switch.c">Switch</option>
|
||||
<option value="if.c">if, then, else</option>
|
||||
<option value="fib.c">Fibonacci</option>
|
||||
<option value="arit.c">Arithmetik</option>
|
||||
<option value="int.c">Interrupt</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -58,7 +59,7 @@
|
|||
<h3>Options</h3>
|
||||
<div><form name="options">
|
||||
<table>
|
||||
<tr><td>Kommentare</td><td><input type="checkbox" value="1" name="comments" /></td></tr>
|
||||
<tr><td>Kommentare</td><td><input type="checkbox" value="1" name="comments" checked="checked" /></td></tr>
|
||||
<tr><td>Maschinencodierung</td><td>
|
||||
<select name="format">
|
||||
<option value="bin" selected="selected">binär</option>
|
||||
|
|
51
js/script.js
51
js/script.js
|
@ -1,5 +1,5 @@
|
|||
var mapping = new Array;
|
||||
var timeout = null;
|
||||
var mapping;
|
||||
var timeout;
|
||||
|
||||
$(document).ready(function(){
|
||||
// load default code
|
||||
|
@ -40,21 +40,22 @@ $(document).ready(function(){
|
|||
}
|
||||
});
|
||||
|
||||
$('#ansic textarea').mousemove(function(e) {
|
||||
var hover = getHoverLine($(this), e);
|
||||
if (hover) {
|
||||
var line = hover.index()+1;
|
||||
$('#ansic textarea')
|
||||
.mousemove(function(e) {
|
||||
var hover = getHoverLine($(this), e);
|
||||
if (hover) {
|
||||
var line = hover.index()+1;
|
||||
|
||||
if (mapping.ansic[line]) {
|
||||
var start = mapping.ansic[line][0];
|
||||
var end = mapping.ansic[line][1];
|
||||
if (mapping.ansic[line]) {
|
||||
var start = mapping.ansic[line][0];
|
||||
var end = mapping.ansic[line][1];
|
||||
|
||||
selectLines($(this), false, line);
|
||||
selectLines($('#assembler textarea'), true, start, end);
|
||||
selectLines($('#byte textarea'), true, mapping.assembler[start], mapping.assembler[end]);
|
||||
selectLines($(this), false, line);
|
||||
selectLines($('#assembler textarea'), true, start, end);
|
||||
selectLines($('#byte textarea'), true, mapping.assembler[start], mapping.assembler[end]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#assembler textarea').mousemove(function(e) {
|
||||
var hover = getHoverLine($(this), e);
|
||||
|
@ -87,10 +88,13 @@ function compile() {
|
|||
var code = $('#ansic textarea').val();
|
||||
|
||||
$.post('compile.php?' + $('form').serialize(), code, function(json) {
|
||||
mapping = json.mapping;
|
||||
timeout = null; // free timeout
|
||||
|
||||
updateEditor($('#assembler .editor textarea'), json.code.assembler);
|
||||
updateEditor($('#byte .editor textarea'), json.code.byte);
|
||||
renderStats(json.stats);
|
||||
|
||||
|
||||
if (json.messages) {
|
||||
$('#messages pre').text(json.messages);
|
||||
$('#messages').show('slow');
|
||||
|
@ -98,9 +102,6 @@ function compile() {
|
|||
else {
|
||||
$('#messages').hide('slow');
|
||||
}
|
||||
|
||||
mapping = json.mapping;
|
||||
timeout = null; // free timeout
|
||||
}, 'json');
|
||||
}
|
||||
|
||||
|
@ -160,7 +161,7 @@ function updateEditor(editor, value) {
|
|||
var lines = editor.val().split("\n").length;
|
||||
|
||||
overlay.empty();
|
||||
for (var i = 0; i < lines; i++) {
|
||||
for (var i = 0; i < lines+2; i++) {
|
||||
overlay.append($('<pre>').text(i+1));
|
||||
}
|
||||
}
|
||||
|
@ -187,12 +188,18 @@ function getHoverLine(editor, e) {
|
|||
}
|
||||
|
||||
function renderStats(stats) {
|
||||
var table = $('<table>');
|
||||
var cLines = $('#ansic textarea').val().split("\n").length;
|
||||
var asInstr = $('#byte textarea').val().split("\n").length;
|
||||
var max;
|
||||
|
||||
var par = $('<p>')
|
||||
.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 = $('<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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue