Commit 1d23e27ca3ae13655041d4aaf6325a922e3bef27

Authored by Salvador Abreu
1 parent dd7468b7
Exists in master

incremental

runtime/test3
No preview for this file type
sim2c-1.0/epilogue.m4
... ... @@ -2,5 +2,6 @@ _divert_(-1)_dnl_
2 2 # -----------------------------------------------------------------------------
3 3 _divert_(0)_dnl_
4 4 #include <stdio.h>
  5 +#include <stdlib.h>
5 6 _dumpdata_
6 7 _dumptext_
... ...
sim2c-1.0/sim2c 100644 → 100755
sim2c-1.0/test1 100644 → 100755
No preview for this file type
sim2c-1.0/test2.c
... ... @@ -1,228 +0,0 @@
1   -#include <stdio.h>
2   -
3   -// == Global data =============================================================
4   -
5   -#define W * 4
6   -#define KB * 1024
7   -#define MB KB KB
8   -
9   -#define DATA_SZ 1 MB
10   -#define HEAP_SZ 1 MB
11   -#define STACK_SZ 1 MB
12   -
13   -#define MEM_SZ ((DATA_SZ) + (HEAP_SZ) + (STACK_SZ))
14   -
15   -union {
16   - int mem[0];
17   - struct {
18   - int m_display[0]; // data label for "display"
19   - int a_0001;
20   - int a_0002;
21   - int a_0003;
22   - int m_htop[0]; // data label for "htop"
23   - int a_0004;
24   - int m_heap[0]; // data label for "heap"
25   - } named;
26   - struct {
27   - int z_data[DATA_SZ];
28   - int z_heap[HEAP_SZ];
29   - int z_stack[STACK_SZ];
30   - } zone;
31   -} global;
32   -
33   -#define M global.mem
34   -#define DATA global.zone.z_data
35   -#define HEAP global.zone.z_heap
36   -#define STACK global.zone.z_stack
37   -
38   -int SP = MEM_SZ;
39   -int FP = 0;
40   -int SR;
41   -void *PC; // (unused)
42   -
43   -// -- Names for global variables ----------------------------------------------
44   -
45   -#define GV_display ((int *) &global.named.m_display - (int *) &global.named)
46   -#define GV_htop ((int *) &global.named.m_htop - (int *) &global.named)
47   -#define GV_heap ((int *) &global.named.m_heap - (int *) &global.named)
48   -
49   -// == Program =================================================================
50   -
51   -int main (int argc, char *argv[])
52   -{
53   - int i;
54   -
55   -// -- Initialization ----------------------------------------------------------
56   - global.named.a_0001 = 0;
57   - global.named.a_0002 = 0;
58   - global.named.a_0003 = 0;
59   - global.named.a_0004 = GV_heap;
60   -
61   -// -- Library -----------------------------------------------------------------
62   -
63   - goto lib_init; // skip library code!
64   -
65   -print_int: // print_int (int) -> ()
66   - printf ("%d\n", M[SP+1]);
67   - goto * ((void *) M[SP++]);
68   -
69   -print_char: // print_char (int) -> ()
70   - putchar (M[SP+1]);
71   - goto * ((void *) M[SP++]);
72   -
73   -read_int: // read_int () -> int
74   - scanf ("%d", &M[SP+1]);
75   - goto * ((void *) M[SP++]);
76   -
77   -read_char: // read_char () -> int
78   - M[SP+1] = getchar ();
79   - goto * ((void *) M[SP++]);
80   -
81   -halt: // halt () -> ()
82   - return 0;
83   -
84   -dump_regs: // dump_regs () -> ()
85   - {
86   - printf ("-- Register dump --\n");
87   - printf ("SP = 0x%x (%d)\n", (int) SP, (int) SP);
88   - printf ("FP = 0x%x (%d)\n", (int) FP, (int) FP);
89   - printf ("SR = 0x%x (%d)\n", (int) SR, (int) SR);
90   - printf ("PC = (unused)\n");
91   - }
92   - goto * ((void *) M[SP++]);
93   -
94   -dump_stack: // dump_stack () -> ()
95   - {
96   - printf ("-- Stack dump --\n");
97   - }
98   - goto * ((void *) M[SP++]);
99   -
100   -stack_trace: // stack_trace () -> ()
101   - {
102   - printf ("-- Stack trace --\n");
103   - }
104   - goto * ((void *) M[SP++]);
105   -
106   -lib_init:
107   - {
108   - // (declarations for function ) (print_int);
109   - // (declarations for function ) (print_char);
110   - // (declarations for function ) (read_int);
111   - // (declarations for function ) (read_char);
112   - // (declarations for function ) (halt);
113   - // (declarations for function ) (dump_regs);
114   - // (declarations for function ) (dump_stack);
115   - // (declarations for function ) (stack_trace);
116   - }
117   -
118   -// -- Start execution ---------------------------------------------------------
119   - M[--SP] = (int) &&L_exit_program; // Save return address for main program
120   - goto program; // start kicking...
121   -L_exit_program: // Return here, and...
122   - exit (0); // quit.
123   -
124   -
125   -// -- Instructions ------------------------------------------------------------
126   - M[--SP] = (int) &&_let_0; // PUSH _let_0
127   - goto * ((void *) M[SP++]); // JUMP
128   -nfactor_1:
129   - M[--SP] = 4; // PUSH 4
130   - { int N = M[SP]; M[SP]= FP; FP=SP+1; SP -= N; } // LINK
131   - M[--SP] = GV_display; // PUSH display
132   - M[--SP] = 8; // PUSH 8
133   - M[SP+1] = M[SP+1] + M[SP+0]; ++SP; // ADD
134   - M[SP-1] = M[SP]; --SP; // DUP
135   - M[SP] = M[M[SP]]; // LOAD
136   - M[--SP] = -4; // PUSH -4
137   - M[SP] = M[SP] + FP; // LOCAL
138   - M[M[SP]] = M[SP+1]; SP += 2; // STORE
139   - M[--SP] = 0; // PUSH 0
140   - M[SP] = M[SP] + FP; // LOCAL
141   - M[SP-1] = M[SP]; M[SP] = M[SP+1]; M[SP+1]=M[SP-1]; // SWAP
142   - M[M[SP]] = M[SP+1]; SP += 2; // STORE
143   - M[--SP] = (int) &&_then_1; // PUSH _then_1
144   - M[--SP] = (int) &&_neq_3; // PUSH _neq_3
145   - M[--SP] = 12; // PUSH 12
146   - M[SP] = M[SP] + FP; // LOCAL
147   - M[SP] = M[M[SP]]; // LOAD
148   - M[--SP] = 0; // PUSH 0
149   - M[SP+1] = M[SP+1] - M[SP+0]; ++SP; // SUB
150   - if (! M[SP++]) goto P_26; // SKIPZ
151   - goto * ((void *) M[SP++]); // JUMP
152   -P_26: ++SP; // POP
153   - M[--SP] = 1; // PUSH 1
154   - M[--SP] = (int) &&_fimeq_4; // PUSH _fimeq_4
155   - goto * ((void *) M[SP++]); // JUMP
156   -_neq_3:
157   - M[--SP] = 0; // PUSH 0
158   -_fimeq_4:
159   - if (! M[SP++]) goto P_33; // SKIPZ
160   - goto * ((void *) M[SP++]); // JUMP
161   -P_33: ++SP; // POP
162   - M[--SP] = 12; // PUSH 12
163   - M[SP] = M[SP] + FP; // LOCAL
164   - M[SP] = M[M[SP]]; // LOAD
165   - M[--SP] = 12; // PUSH 12
166   - M[SP] = M[SP] + FP; // LOCAL
167   - M[SP] = M[M[SP]]; // LOAD
168   - M[--SP] = 1; // PUSH 1
169   - M[SP+1] = M[SP+1] - M[SP+0]; ++SP; // SUB
170   - M[SP-1] = M[SP]; --SP; // DUP
171   - M[--SP] = (int) &&nfactor_1; // PUSH nfactor_1
172   - { void *C = (void *) M[SP]; M[SP]=(int)&&P_45; goto *C; } // CALL
173   -P_45: M[SP-1] = M[SP]; M[SP] = M[SP+1]; M[SP+1]=M[SP-1]; // SWAP
174   - ++SP; // POP
175   - M[SP+1] = M[SP+1] * M[SP+0]; ++SP; // MUL
176   - M[--SP] = (int) &&_fimif_2; // PUSH _fimif_2
177   - goto * ((void *) M[SP++]); // JUMP
178   -_then_1:
179   - M[--SP] = 1; // PUSH 1
180   -_fimif_2:
181   - M[--SP] = 8; // PUSH 8
182   - M[SP] = M[SP] + FP; // LOCAL
183   - M[M[SP]] = M[SP+1]; SP += 2; // STORE
184   - M[--SP] = -4; // PUSH -4
185   - M[SP] = M[SP] + FP; // LOCAL
186   - M[SP] = M[M[SP]]; // LOAD
187   - M[--SP] = GV_display; // PUSH display
188   - M[--SP] = 8; // PUSH 8
189   - M[SP+1] = M[SP+1] + M[SP+0]; ++SP; // ADD
190   - M[M[SP]] = M[SP+1]; SP += 2; // STORE
191   - SP=FP; FP=M[SP-1]; // UNLINK
192   - goto * ((void *) M[SP++]); // JUMP
193   -_let_0:
194   - M[--SP] = 0; // PUSH 0
195   - M[--SP] = 4; // PUSH 4
196   - { int N = M[SP]; M[SP]= FP; FP=SP+1; SP -= N; } // LINK
197   - M[--SP] = GV_display; // PUSH display
198   - M[--SP] = 4; // PUSH 4
199   - M[SP+1] = M[SP+1] + M[SP+0]; ++SP; // ADD
200   - M[SP-1] = M[SP]; --SP; // DUP
201   - M[SP] = M[M[SP]]; // LOAD
202   - M[--SP] = -4; // PUSH -4
203   - M[SP] = M[SP] + FP; // LOCAL
204   - M[M[SP]] = M[SP+1]; SP += 2; // STORE
205   - M[--SP] = 0; // PUSH 0
206   - M[SP] = M[SP] + FP; // LOCAL
207   - M[SP-1] = M[SP]; M[SP] = M[SP+1]; M[SP+1]=M[SP-1]; // SWAP
208   - M[M[SP]] = M[SP+1]; SP += 2; // STORE
209   - M[--SP] = 10; // PUSH 10
210   - M[SP-1] = M[SP]; --SP; // DUP
211   - M[--SP] = (int) &&nfactor_1; // PUSH nfactor_1
212   - { void *C = (void *) M[SP]; M[SP]=(int)&&P_82; goto *C; } // CALL
213   -P_82: M[SP-1] = M[SP]; M[SP] = M[SP+1]; M[SP+1]=M[SP-1]; // SWAP
214   - ++SP; // POP
215   - M[--SP] = 4; // PUSH 4
216   - M[SP] = M[SP] + FP; // LOCAL
217   - M[M[SP]] = M[SP+1]; SP += 2; // STORE
218   - M[--SP] = -4; // PUSH -4
219   - M[SP] = M[SP] + FP; // LOCAL
220   - M[SP] = M[M[SP]]; // LOAD
221   - M[--SP] = GV_display; // PUSH display
222   - M[--SP] = 4; // PUSH 4
223   - M[SP+1] = M[SP+1] + M[SP+0]; ++SP; // ADD
224   - M[M[SP]] = M[SP+1]; SP += 2; // STORE
225   - SP=FP; FP=M[SP-1]; // UNLINK
226   -
227   -}
228   -
sim2c-1.0/test3
No preview for this file type
sim2c-1.0/test3.c
... ... @@ -13,15 +13,15 @@
13 13 #define MEM_SZ ((DATA_SZ) + (HEAP_SZ) + (STACK_SZ))
14 14  
15 15 union {
16   - long mem[0];
  16 + int mem[0];
17 17 struct {
18   - long m_x;
19   - long m_xpto[20];
  18 + int m_x;
  19 + int m_xpto[20];
20 20 } named;
21 21 struct {
22   - long z_data[DATA_SZ];
23   - long z_heap[HEAP_SZ];
24   - long z_stack[STACK_SZ];
  22 + int z_data[DATA_SZ];
  23 + int z_heap[HEAP_SZ];
  24 + int z_stack[STACK_SZ];
25 25 } zone;
26 26 } global;
27 27  
... ... @@ -30,21 +30,21 @@ union {
30 30 #define HEAP global.zone.z_heap
31 31 #define STACK global.zone.z_stack
32 32  
33   -long SP = MEM_SZ;
34   -long FP = 0;
35   -long SR;
  33 +int SP = MEM_SZ;
  34 +int FP = 0;
  35 +int SR;
36 36 void *PC; // (unused)
37 37  
38 38 // -- Names for global variables ----------------------------------------------
39 39  
40   -#define GV_x ((long *) &global.named.m_x - (long *) &global.named)
41   -#define GV_xpto ((long *) &global.named.m_xpto - (long *) &global.named)
  40 +#define GV_x ((int *) &global.named.m_x - (int *) &global.named)
  41 +#define GV_xpto ((int *) &global.named.m_xpto - (int *) &global.named)
42 42  
43 43 // == Program =================================================================
44 44  
45 45 int main (int argc, char *argv[])
46 46 {
47   - long i;
  47 + int i;
48 48  
49 49 // -- Initialization ----------------------------------------------------------
50 50 global.named.m_x = 123;
... ... @@ -55,7 +55,7 @@ int main (int argc, char *argv[])
55 55 goto lib_init; // skip library code!
56 56  
57 57 print_int: // print_int (int) -> ()
58   - printf ("%ld\n", M[SP+1]);
  58 + printf ("%d\n", M[SP+1]);
59 59 goto * ((void *) M[SP++]);
60 60  
61 61 print_char: // print_char (int) -> ()
... ... @@ -76,9 +76,9 @@ halt: // halt () -&gt; ()
76 76 dump_regs: // dump_regs () -> ()
77 77 {
78 78 printf ("-- Register dump --\n");
79   - printf ("SP = 0x%x (%d)\n", (long) SP, (long) SP);
80   - printf ("FP = 0x%x (%d)\n", (long) FP, (long) FP);
81   - printf ("SR = 0x%x (%d)\n", (long) SR, (long) SR);
  79 + printf ("SP = 0x%x (%d)\n", (int) SP, (int) SP);
  80 + printf ("FP = 0x%x (%d)\n", (int) FP, (int) FP);
  81 + printf ("SR = 0x%x (%d)\n", (int) SR, (int) SR);
82 82 printf ("PC = (unused)\n");
83 83 }
84 84 goto * ((void *) M[SP++]);
... ... @@ -108,7 +108,7 @@ lib_init:
108 108 }
109 109  
110 110 // -- Start execution ---------------------------------------------------------
111   - M[--SP] = (long) &&L_exit_program; // Save return address for main program
  111 + M[--SP] = (int) &&L_exit_program; // Save return address for main program
112 112 goto program; // start kicking...
113 113 L_exit_program: // Return here, and...
114 114 exit (0); // quit.
... ... @@ -117,10 +117,10 @@ L_exit_program: // Return here, and...
117 117 // -- Instructions ------------------------------------------------------------
118 118 program:
119 119 M[--SP] = 0; // PUSH 0
120   - { long N = M[SP]; M[SP]= FP; FP=SP+1; SP -= N; } // LINK
  120 + { int N = M[SP]; M[SP]= FP; FP=SP+1; SP -= N; } // LINK
121 121 M[--SP] = 12; // PUSH 12
122   - M[--SP] = (long) &&print_int; // PUSH print_int
123   - { void *C = (void *) M[SP]; M[SP]=(long)&&P_6; goto *C; } // CALL
  122 + M[--SP] = (int) &&print_int; // PUSH print_int
  123 + { void *C = (void *) M[SP]; M[SP]=(int)&&P_6; goto *C; } // CALL
124 124 P_6: SP=FP; FP=M[SP-1]; // UNLINK
125 125 goto * ((void *) M[SP++]); // JUMP
126 126  
... ...
sim2c-1.0/test4 100644 → 100755
No preview for this file type
sim2c-1.0/test5 100644 → 100755
No preview for this file type