From 94e88e887cf2ee4c6b445924d26e134a90bcbd50 Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Tue, 5 Nov 2013 10:18:00 +0100 Subject: Reorganized folders. --- .gitignore | 6 +++--- camlsim/test/clock_div_sch.net | 9 --------- camlsim/test/cm2_sch.net | 9 --------- camlsim/test/fulladder_sch.net | 12 ------------ camlsim/test/nadder_sch.net | 17 ----------------- camlsim/test/ram_sch.net | 32 -------------------------------- csim/Makefile | 2 +- csim/load.c | 4 ++++ csim/main.c | 4 ++-- sched/test/clock_div.mj | 4 ---- sched/test/clock_div.net | 9 --------- sched/test/cm2.mj | 4 ---- sched/test/cm2.net | 9 --------- sched/test/fulladder.mj | 4 ---- sched/test/fulladder.net | 12 ------------ sched/test/nadder.mj | 19 ------------------- sched/test/nadder.net | 17 ----------------- sched/test/ram.mj | 15 --------------- sched/test/ram.net | 32 -------------------------------- tests/Makefile | 18 ++++++++++++++++++ tests/clock_div.mj | 4 ++++ tests/cm2.mj | 4 ++++ tests/fulladder.mj | 4 ++++ tests/nadder.mj | 19 +++++++++++++++++++ tests/ram.mj | 15 +++++++++++++++ 25 files changed, 74 insertions(+), 210 deletions(-) delete mode 100644 camlsim/test/clock_div_sch.net delete mode 100644 camlsim/test/cm2_sch.net delete mode 100644 camlsim/test/fulladder_sch.net delete mode 100644 camlsim/test/nadder_sch.net delete mode 100644 camlsim/test/ram_sch.net delete mode 100644 sched/test/clock_div.mj delete mode 100644 sched/test/clock_div.net delete mode 100644 sched/test/cm2.mj delete mode 100644 sched/test/cm2.net delete mode 100644 sched/test/fulladder.mj delete mode 100644 sched/test/fulladder.net delete mode 100644 sched/test/nadder.mj delete mode 100644 sched/test/nadder.net delete mode 100644 sched/test/ram.mj delete mode 100644 sched/test/ram.net create mode 100644 tests/Makefile create mode 100644 tests/clock_div.mj create mode 100644 tests/cm2.mj create mode 100644 tests/fulladder.mj create mode 100644 tests/nadder.mj create mode 100644 tests/ram.mj diff --git a/.gitignore b/.gitignore index 9c555fb..7f124fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ +*.swp */_build/* */*.byte -sched/test/*_sch.net -sched/test/*.dumb -*.swp csim/csim *.o +tests/*.net +tests/*.dumb diff --git a/camlsim/test/clock_div_sch.net b/camlsim/test/clock_div_sch.net deleted file mode 100644 index 0ae5cd9..0000000 --- a/camlsim/test/clock_div_sch.net +++ /dev/null @@ -1,9 +0,0 @@ -INPUT -OUTPUT o -VAR - _l_2, c, o -IN -_l_2 = REG o -o = REG c -c = NOT _l_2 - diff --git a/camlsim/test/cm2_sch.net b/camlsim/test/cm2_sch.net deleted file mode 100644 index e9900d5..0000000 --- a/camlsim/test/cm2_sch.net +++ /dev/null @@ -1,9 +0,0 @@ -INPUT x -OUTPUT s, r -VAR - _l_1, r, s, x -IN -s = REG _l_1 -_l_1 = XOR x s -r = AND x s - diff --git a/camlsim/test/fulladder_sch.net b/camlsim/test/fulladder_sch.net deleted file mode 100644 index 96fc154..0000000 --- a/camlsim/test/fulladder_sch.net +++ /dev/null @@ -1,12 +0,0 @@ -INPUT a, b, c -OUTPUT s, r -VAR - _l_1, _l_3, _l_4, _l_5, a, b, c, r, s -IN -_l_4 = XOR a b -_l_5 = AND _l_4 c -_l_3 = AND a b -_l_1 = XOR a b -s = XOR _l_1 c -r = OR _l_3 _l_5 - diff --git a/camlsim/test/nadder_sch.net b/camlsim/test/nadder_sch.net deleted file mode 100644 index 5602eb4..0000000 --- a/camlsim/test/nadder_sch.net +++ /dev/null @@ -1,17 +0,0 @@ -INPUT a, b -OUTPUT o, c -VAR - _l_10_50, _l_11_49, _l_16_22, _l_17_21, _l_7_52, _l_9_51, a, b, c, - c_n1_27, o, s_n_26 -IN -_l_17_21 = SELECT 0 b -_l_16_22 = SELECT 0 a -c_n1_27 = 0 -_l_10_50 = XOR _l_16_22 _l_17_21 -_l_11_49 = AND _l_10_50 c_n1_27 -_l_9_51 = AND _l_16_22 _l_17_21 -_l_7_52 = XOR _l_16_22 _l_17_21 -s_n_26 = XOR _l_7_52 c_n1_27 -c = OR _l_9_51 _l_11_49 -o = s_n_26 - diff --git a/camlsim/test/ram_sch.net b/camlsim/test/ram_sch.net deleted file mode 100644 index 56dda0e..0000000 --- a/camlsim/test/ram_sch.net +++ /dev/null @@ -1,32 +0,0 @@ -INPUT ra, we, wa, c -OUTPUT o -VAR - _l_10_22, _l_10_35, _l_10_48, _l_10_61, _l_11_21, _l_11_34, _l_11_47, - _l_11_60, _l_12_20 : 3, _l_12_33 : 2, _l_12_46 : 1, _l_13_19 : 3, _l_13_32 : 2, - _l_13_45 : 1, _l_14_18 : 3, _l_14_31 : 2, _l_14_44 : 1, _l_16 : 4, - _l_9_23, _l_9_36, _l_9_49, _l_9_62, c : 4, o : 4, ra : 2, wa : 2, we -IN -_l_13_19 = SLICE 1 3 c -_l_13_32 = SLICE 1 2 _l_13_19 -_l_13_45 = SLICE 1 1 _l_13_32 -_l_10_61 = SELECT 0 _l_13_45 -o = RAM 2 4 ra we wa _l_16 -_l_12_20 = SLICE 1 3 o -_l_12_33 = SLICE 1 2 _l_12_20 -_l_12_46 = SLICE 1 1 _l_12_33 -_l_9_62 = SELECT 0 _l_12_46 -_l_11_60 = AND _l_9_62 _l_10_61 -_l_14_44 = _l_11_60 -_l_10_48 = SELECT 0 _l_13_32 -_l_9_49 = SELECT 0 _l_12_33 -_l_11_47 = AND _l_9_49 _l_10_48 -_l_14_31 = CONCAT _l_11_47 _l_14_44 -_l_10_35 = SELECT 0 _l_13_19 -_l_9_36 = SELECT 0 _l_12_20 -_l_11_34 = AND _l_9_36 _l_10_35 -_l_14_18 = CONCAT _l_11_34 _l_14_31 -_l_10_22 = SELECT 0 c -_l_9_23 = SELECT 0 o -_l_11_21 = AND _l_9_23 _l_10_22 -_l_16 = CONCAT _l_11_21 _l_14_18 - diff --git a/csim/Makefile b/csim/Makefile index 32d100d..c94bee2 100644 --- a/csim/Makefile +++ b/csim/Makefile @@ -1,4 +1,4 @@ -main: main.o load.o sim.o +csim: main.o load.o sim.o gcc -o csim $^ %.o: %.c diff --git a/csim/load.c b/csim/load.c index 05c5f70..a7e6cac 100644 --- a/csim/load.c +++ b/csim/load.c @@ -60,6 +60,10 @@ t_program *load_dumb_netlist (FILE *stream) { p->vars[i].name = malloc(42); // let's bet that the name of a variable will never be longer than 42 chars fscanf(stream, "%s\n", p->vars[i].name); + + if (p->vars[i].size >= 8*sizeof(t_value)) { + fprintf(stderr, "Warning: variable %s might be too big for machine integers.\n", p->vars[i].name); + } } // read input list diff --git a/csim/main.c b/csim/main.c index ad23cd8..a43d7c9 100644 --- a/csim/main.c +++ b/csim/main.c @@ -16,7 +16,7 @@ void usage() { printf ("\nUsage:\n\tcsim [options] \n\n"); printf("Available options:\n"); printf("\n -rom \n\tLoad a filename as a ROM file for the machine\n"); - printf("\n -n \n\tOnly run #steps steps of simulation (-1 = infinity)\n"); + printf("\n -n \n\tOnly run #steps steps of simulation (0 = infinity)\n"); printf("\n -in \n\tRead inputs from given file (eg. named pipe). Defaults to STDIN.\n"); printf("\n -out \n\tWrite outputs to given file (eg. named pipe). Defaults to STDOut.\n"); exit(1); @@ -81,7 +81,7 @@ int main(int argc, char **argv) { // Run t_machine *machine = init_machine(program); i = 0; - while (i < steps || steps == -1) { + while (i < steps || steps == 0) { read_inputs(machine, input); machine_step(machine); write_outputs(machine, output); diff --git a/sched/test/clock_div.mj b/sched/test/clock_div.mj deleted file mode 100644 index ad1e919..0000000 --- a/sched/test/clock_div.mj +++ /dev/null @@ -1,4 +0,0 @@ -main() = (o) where - o = reg(c); - c = not (reg (o)) -end where \ No newline at end of file diff --git a/sched/test/clock_div.net b/sched/test/clock_div.net deleted file mode 100644 index 9a17fc7..0000000 --- a/sched/test/clock_div.net +++ /dev/null @@ -1,9 +0,0 @@ -INPUT -OUTPUT o -VAR - _l_2, c, o -IN -c = NOT _l_2 -o = REG c -_l_2 = REG o - diff --git a/sched/test/cm2.mj b/sched/test/cm2.mj deleted file mode 100644 index 8863bf1..0000000 --- a/sched/test/cm2.mj +++ /dev/null @@ -1,4 +0,0 @@ -main(x) = (s, r) where - s = reg (x xor s); - r = x and s -end where \ No newline at end of file diff --git a/sched/test/cm2.net b/sched/test/cm2.net deleted file mode 100644 index e296b96..0000000 --- a/sched/test/cm2.net +++ /dev/null @@ -1,9 +0,0 @@ -INPUT x -OUTPUT s, r -VAR - _l_1, r, s, x -IN -r = AND x s -s = REG _l_1 -_l_1 = XOR x s - diff --git a/sched/test/fulladder.mj b/sched/test/fulladder.mj deleted file mode 100644 index c4b6b0e..0000000 --- a/sched/test/fulladder.mj +++ /dev/null @@ -1,4 +0,0 @@ -main(a,b,c) = (s, r) where - s = (a xor b) xor c; - r = (a and b) or ((a xor b) and c); -end where \ No newline at end of file diff --git a/sched/test/fulladder.net b/sched/test/fulladder.net deleted file mode 100644 index b2271c2..0000000 --- a/sched/test/fulladder.net +++ /dev/null @@ -1,12 +0,0 @@ -INPUT a, b, c -OUTPUT s, r -VAR - _l_1, _l_3, _l_4, _l_5, a, b, c, r, s -IN -r = OR _l_3 _l_5 -s = XOR _l_1 c -_l_1 = XOR a b -_l_3 = AND a b -_l_4 = XOR a b -_l_5 = AND _l_4 c - diff --git a/sched/test/nadder.mj b/sched/test/nadder.mj deleted file mode 100644 index 0c95386..0000000 --- a/sched/test/nadder.mj +++ /dev/null @@ -1,19 +0,0 @@ -fulladder(a,b,c) = (s, r) where - s = (a ^ b) ^ c; - r = (a & b) + ((a ^ b) & c); -end where - -adder(a:[n], b:[n], c_in) = (o:[n], c_out) where - if n = 0 then - o = []; - c_out = 0 - else - (s_n1, c_n1) = adder(a[1..], b[1..], c_in); - (s_n, c_out) = fulladder(a[0], b[0], c_n1); - o = s_n . s_n1 - end if -end where - -main(a, b) = (o, c) where - (o, c) = adder<1>(a,b,0) -end where \ No newline at end of file diff --git a/sched/test/nadder.net b/sched/test/nadder.net deleted file mode 100644 index bf87051..0000000 --- a/sched/test/nadder.net +++ /dev/null @@ -1,17 +0,0 @@ -INPUT a, b -OUTPUT o, c -VAR - _l_10_50, _l_11_49, _l_16_22, _l_17_21, _l_7_52, _l_9_51, a, b, c, - c_n1_27, o, s_n_26 -IN -o = s_n_26 -c = OR _l_9_51 _l_11_49 -s_n_26 = XOR _l_7_52 c_n1_27 -_l_7_52 = XOR _l_16_22 _l_17_21 -_l_9_51 = AND _l_16_22 _l_17_21 -_l_10_50 = XOR _l_16_22 _l_17_21 -_l_11_49 = AND _l_10_50 c_n1_27 -c_n1_27 = 0 -_l_16_22 = SELECT 0 a -_l_17_21 = SELECT 0 b - diff --git a/sched/test/ram.mj b/sched/test/ram.mj deleted file mode 100644 index 5bd4f29..0000000 --- a/sched/test/ram.mj +++ /dev/null @@ -1,15 +0,0 @@ -const addr = 2 -const word = 4 - -or_n(a:[n],b:[n]) = (o:[n]) where - if n = 0 then - o = [] - else - o = (a[0] or b[0]).(or_n(a[1..], b[1..])) - end if -end where - -main(ra:[addr], we, wa:[addr], c:[word]) = (o:[word]) where - o = ram(ra, we, wa, or_n(o, c)) -end where - diff --git a/sched/test/ram.net b/sched/test/ram.net deleted file mode 100644 index 56f2fc6..0000000 --- a/sched/test/ram.net +++ /dev/null @@ -1,32 +0,0 @@ -INPUT ra, we, wa, c -OUTPUT o -VAR - _l_10_22, _l_10_35, _l_10_48, _l_10_61, _l_11_21, _l_11_34, _l_11_47, - _l_11_60, _l_12_20 : 3, _l_12_33 : 2, _l_12_46 : 1, _l_13_19 : 3, _l_13_32 : 2, - _l_13_45 : 1, _l_14_18 : 3, _l_14_31 : 2, _l_14_44 : 1, _l_16 : 4, - _l_9_23, _l_9_36, _l_9_49, _l_9_62, c : 4, o : 4, ra : 2, wa : 2, we -IN -o = RAM 2 4 ra we wa _l_16 -_l_16 = CONCAT _l_11_21 _l_14_18 -_l_9_23 = SELECT 0 o -_l_10_22 = SELECT 0 c -_l_11_21 = OR _l_9_23 _l_10_22 -_l_12_20 = SLICE 1 3 o -_l_13_19 = SLICE 1 3 c -_l_14_18 = CONCAT _l_11_34 _l_14_31 -_l_9_36 = SELECT 0 _l_12_20 -_l_10_35 = SELECT 0 _l_13_19 -_l_11_34 = OR _l_9_36 _l_10_35 -_l_12_33 = SLICE 1 2 _l_12_20 -_l_13_32 = SLICE 1 2 _l_13_19 -_l_14_31 = CONCAT _l_11_47 _l_14_44 -_l_9_49 = SELECT 0 _l_12_33 -_l_10_48 = SELECT 0 _l_13_32 -_l_11_47 = OR _l_9_49 _l_10_48 -_l_12_46 = SLICE 1 1 _l_12_33 -_l_13_45 = SLICE 1 1 _l_13_32 -_l_14_44 = _l_11_60 -_l_9_62 = SELECT 0 _l_12_46 -_l_10_61 = SELECT 0 _l_13_45 -_l_11_60 = OR _l_9_62 _l_10_61 - diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..443e86a --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,18 @@ +.SECONDARY: + +MINIJAZZ=../minijazz/mjc.byte +SCHED=../sched/main.byte +SIM=../csim/csim + +%.sim: %.dumb + $(SIM) $< + +%.dumb %_sch.net: %.net + $(SCHED) $< + +%.net: %.mj + $(MINIJAZZ) $< + +clean: + rm *.net + rm *.dumb diff --git a/tests/clock_div.mj b/tests/clock_div.mj new file mode 100644 index 0000000..ad1e919 --- /dev/null +++ b/tests/clock_div.mj @@ -0,0 +1,4 @@ +main() = (o) where + o = reg(c); + c = not (reg (o)) +end where \ No newline at end of file diff --git a/tests/cm2.mj b/tests/cm2.mj new file mode 100644 index 0000000..8863bf1 --- /dev/null +++ b/tests/cm2.mj @@ -0,0 +1,4 @@ +main(x) = (s, r) where + s = reg (x xor s); + r = x and s +end where \ No newline at end of file diff --git a/tests/fulladder.mj b/tests/fulladder.mj new file mode 100644 index 0000000..c4b6b0e --- /dev/null +++ b/tests/fulladder.mj @@ -0,0 +1,4 @@ +main(a,b,c) = (s, r) where + s = (a xor b) xor c; + r = (a and b) or ((a xor b) and c); +end where \ No newline at end of file diff --git a/tests/nadder.mj b/tests/nadder.mj new file mode 100644 index 0000000..0c95386 --- /dev/null +++ b/tests/nadder.mj @@ -0,0 +1,19 @@ +fulladder(a,b,c) = (s, r) where + s = (a ^ b) ^ c; + r = (a & b) + ((a ^ b) & c); +end where + +adder(a:[n], b:[n], c_in) = (o:[n], c_out) where + if n = 0 then + o = []; + c_out = 0 + else + (s_n1, c_n1) = adder(a[1..], b[1..], c_in); + (s_n, c_out) = fulladder(a[0], b[0], c_n1); + o = s_n . s_n1 + end if +end where + +main(a, b) = (o, c) where + (o, c) = adder<1>(a,b,0) +end where \ No newline at end of file diff --git a/tests/ram.mj b/tests/ram.mj new file mode 100644 index 0000000..5bd4f29 --- /dev/null +++ b/tests/ram.mj @@ -0,0 +1,15 @@ +const addr = 2 +const word = 4 + +or_n(a:[n],b:[n]) = (o:[n]) where + if n = 0 then + o = [] + else + o = (a[0] or b[0]).(or_n(a[1..], b[1..])) + end if +end where + +main(ra:[addr], we, wa:[addr], c:[word]) = (o:[word]) where + o = ram(ra, we, wa, or_n(o, c)) +end where + -- cgit v1.2.3