Commit fb3afe4529b438e0dd873f8e85f400e1668508cf

Authored by Salvador Abreu
1 parent 1d23e27c
Exists in master

doing 64bits now...

Makefile 0 → 100644
@@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
  1 +IMAGES=$(shell ls -1 */Dockerfile | sed -e s:/Dockerfile::)
  2 +COPY=sim2c_1.0-3_all.deb
  3 +
  4 +DATA=data
  5 +WORKDIR=/root
  6 +HUBU=rodalvas
  7 +
  8 +all: cplint
  9 +
  10 +.PHONY: prolog logtalk cplint clean sim2c
  11 +
  12 +prolog:
  13 + docker build $@ --tag $@:latest
  14 + docker tag $@:latest $(HUBU)/$@:latest
  15 +
  16 +sim2c:
  17 + cp $(COPY) $@/sim2c.deb
  18 + docker build $@ --tag $@:latest
  19 + docker tag $@:latest $(HUBU)/$@:latest
  20 +
  21 +
  22 +run-%::
  23 + docker run -ti \
  24 + -v $(PWD)/$(DATA):$(WORKDIR)/$(DATA) \
  25 + $(subst run-,,$@):latest
  26 +
  27 +logtalk.deb::
  28 + [ -e $(LGTDEB) ] || wget -q https://logtalk.org/files/$(LGTDEB)
  29 + ln -sf $(LGTDEB) logtalk.deb
  30 +
  31 +clean:
  32 + rm -f $(DATA)/*
  33 + docker container prune -f
  34 + docker image prune -f
  35 + docker image rm -f $(IMAGES)
sim2c-1.0/defs.m4
@@ -72,12 +72,12 @@ _define_(`store', `_np_ M[M[SP]] = M[SP+1]; SP += 2; // STORE') @@ -72,12 +72,12 @@ _define_(`store', `_np_ M[M[SP]] = M[SP+1]; SP += 2; // STORE')
72 72
73 _define_(`skipz', `_np_ if (! M[SP++]) goto _pc_at_(2); // SKIPZ') 73 _define_(`skipz', `_np_ if (! M[SP++]) goto _pc_at_(2); // SKIPZ')
74 _define_(`jump', `_np_ goto * ((void *) M[SP++]); // JUMP') 74 _define_(`jump', `_np_ goto * ((void *) M[SP++]); // JUMP')
75 -_define_(`call', `_np_ { void *C = (void *) M[SP]; M[SP]=(int)&&_pc_at_(1); goto *C; } // CALL') 75 +_define_(`call', `_np_ { void *C = (void *) M[SP]; M[SP]=(long)&&_pc_at_(1); goto *C; } // CALL')
76 76
77 _define_(`local', `_np_ M[SP] = M[SP] + FP; // LOCAL') 77 _define_(`local', `_np_ M[SP] = M[SP] + FP; // LOCAL')
78 _define_(`stack', `_np_ M[SP] = M[SP] + SP; // STACK') 78 _define_(`stack', `_np_ M[SP] = M[SP] + SP; // STACK')
79 79
80 -_define_(`link', `_np_ { int N = M[SP]; M[SP]= FP; FP=SP+1; SP -= N; } // LINK') 80 +_define_(`link', `_np_ { long N = M[SP]; M[SP]= FP; FP=SP+1; SP -= N; } // LINK')
81 _define_(`unlink', `_np_ SP=FP; FP=M[SP-1]; // UNLINK') 81 _define_(`unlink', `_np_ SP=FP; FP=M[SP-1]; // UNLINK')
82 82
83 _define_(`dup_sr', `_np_ SR = M[SP]; // DUP_SR') 83 _define_(`dup_sr', `_np_ SR = M[SP]; // DUP_SR')
@@ -90,27 +90,27 @@ _ifelse_(_regexp_($1,`^[-0-9]'), 0, `_dnl_ @@ -90,27 +90,27 @@ _ifelse_(_regexp_($1,`^[-0-9]'), 0, `_dnl_
90 $1', `_dnl_ -- Numbers go untouched ------------ 90 $1', `_dnl_ -- Numbers go untouched ------------
91 _ifdef_(`_DATA_'$1,_dnl_ 91 _ifdef_(`_DATA_'$1,_dnl_
92 _DATA_`'$1,_dnl_ -- (known) data labels ------------- 92 _DATA_`'$1,_dnl_ -- (known) data labels -------------
93 -(int) &&$1`'_dnl_ -- code labels --------------------- 93 +(long) &&$1`'_dnl_ -- code labels ---------------------
94 )')') 94 )')')
95 95
96 _define_(`label', `_dnl_ 96 _define_(`label', `_dnl_
97 _ifelse_(_data_text_,__data__,_dnl_ 97 _ifelse_(_data_text_,__data__,_dnl_
98 -` int m_`'$1[0]; // data `label' for "$1"_dnl_ 98 +` long m_`'$1[0]; // data `label' for "$1"_dnl_
99 _define_(`_DATA_'$1,`GV_'$1)_global_var_($1)',_dnl_ 99 _define_(`_DATA_'$1,`GV_'$1)_global_var_($1)',_dnl_
100 `$1:')') 100 `$1:')')
101 101
102 _define_(`_ac_',0) 102 _define_(`_ac_',0)
103 _define_(`_anon_', `_define_(`_ac_',_incr_(_ac_))_format_(`a_%04.4d',_ac_)') 103 _define_(`_anon_', `_define_(`_ac_',_incr_(_ac_))_format_(`a_%04.4d',_ac_)')
104 104
105 -_define_(`_word_',` int _anon_;_divert_(4)_dnl_ 105 +_define_(`_word_',` long _anon_;_divert_(4)_dnl_
106 global.named._format_(`a_%04.4d',_ac_) = _initializer_($1); 106 global.named._format_(`a_%04.4d',_ac_) = _initializer_($1);
107 _divert_(1)') 107 _divert_(1)')
108 108
109 -_define_(`_def_word_', ` int m_$1;_dnl_ 109 +_define_(`_def_word_', ` long m_$1;_dnl_
110 _divert_(4) global.named.m_$1 = _initializer_($2); 110 _divert_(4) global.named.m_$1 = _initializer_($2);
111 _define_(`_DATA_'$1,`GV_'$1)_global_var_($1)') 111 _define_(`_DATA_'$1,`GV_'$1)_global_var_($1)')
112 112
113 -_define_(`_def_space_', ` int m_$1[$2];_dnl_ 113 +_define_(`_def_space_', ` long m_$1[$2];_dnl_
114 _divert_(4) for (i=0; i<$2; ++i) global.named.m_$1[i] = 0; 114 _divert_(4) for (i=0; i<$2; ++i) global.named.m_$1[i] = 0;
115 _define_(`_DATA_'$1,`GV_'$1)_global_var_($1)') 115 _define_(`_DATA_'$1,`GV_'$1)_global_var_($1)')
116 116
@@ -118,7 +118,7 @@ _define_(`_initializer_&#39;,`_dnl_ @@ -118,7 +118,7 @@ _define_(`_initializer_&#39;,`_dnl_
118 _ifelse_(_regexp_($1,`^[-0-9]'), 0, `$1', `GV_`'$1')') 118 _ifelse_(_regexp_($1,`^[-0-9]'), 0, `$1', `GV_`'$1')')
119 119
120 _define_(`_global_var_',`_divert_(3)_dnl_ 120 _define_(`_global_var_',`_divert_(3)_dnl_
121 -#define GV_$1 ((int *) &global.named.m_$1 - (int *) &global.named) 121 +#define GV_$1 ((long *) &global.named.m_$1 - (long *) &global.named)
122 _divert_(1)') 122 _divert_(1)')
123 123
124 _define_(`_data_', `_divert_(1)_define_(`_data_text_', __data__)') 124 _define_(`_data_', `_divert_(1)_define_(`_data_text_', __data__)')
@@ -138,14 +138,14 @@ _define_(`_dumpdata_&#39;, ` @@ -138,14 +138,14 @@ _define_(`_dumpdata_&#39;, `
138 #define MEM_SZ ((DATA_SZ) + (HEAP_SZ) + (STACK_SZ)) 138 #define MEM_SZ ((DATA_SZ) + (HEAP_SZ) + (STACK_SZ))
139 139
140 union { 140 union {
141 - int mem[0]; 141 + long mem[0];
142 struct {_dnl_ 142 struct {_dnl_
143 _undivert_(1)_dnl_ 143 _undivert_(1)_dnl_
144 } named; 144 } named;
145 struct { 145 struct {
146 - int z_data[DATA_SZ];  
147 - int z_heap[HEAP_SZ];  
148 - int z_stack[STACK_SZ]; 146 + long z_data[DATA_SZ];
  147 + long z_heap[HEAP_SZ];
  148 + long z_stack[STACK_SZ];
149 } zone; 149 } zone;
150 } global; 150 } global;
151 151
@@ -154,9 +154,9 @@ _undivert_(1)_dnl_ @@ -154,9 +154,9 @@ _undivert_(1)_dnl_
154 #define HEAP global.zone.z_heap 154 #define HEAP global.zone.z_heap
155 #define STACK global.zone.z_stack 155 #define STACK global.zone.z_stack
156 156
157 -int SP = MEM_SZ;  
158 -int FP = 0;  
159 -int SR; 157 +long SP = MEM_SZ;
  158 +long FP = 0;
  159 +long SR;
160 void *PC; // (unused) 160 void *PC; // (unused)
161 161
162 // -- Names for global variables ---------------------------------------------- 162 // -- Names for global variables ----------------------------------------------
@@ -168,7 +168,7 @@ _define_(`_dumptext_&#39;, `_dnl_ @@ -168,7 +168,7 @@ _define_(`_dumptext_&#39;, `_dnl_
168 168
169 int main (int argc, char *argv[]) 169 int main (int argc, char *argv[])
170 { 170 {
171 - int i; 171 + long i;
172 172
173 // -- Initialization ---------------------------------------------------------- 173 // -- Initialization ----------------------------------------------------------
174 _undivert_(4)_dnl_ 174 _undivert_(4)_dnl_
@@ -178,7 +178,7 @@ _undivert_(4)_dnl_ @@ -178,7 +178,7 @@ _undivert_(4)_dnl_
178 _include_(LIBDIR/library.m4)_dnl_ 178 _include_(LIBDIR/library.m4)_dnl_
179 179
180 // -- Start execution --------------------------------------------------------- 180 // -- Start execution ---------------------------------------------------------
181 - M[--SP] = (int) &&L_exit_program; // Save return address for main program 181 + M[--SP] = (long) &&L_exit_program; // Save return address for main program
182 goto program; // start kicking... 182 goto program; // start kicking...
183 L_exit_program: // Return here, and... 183 L_exit_program: // Return here, and...
184 exit (0); // quit. 184 exit (0); // quit.
sim2c-1.0/library.m4
@@ -9,7 +9,7 @@ _divert_(0)_dnl_ @@ -9,7 +9,7 @@ _divert_(0)_dnl_
9 goto lib_init; // skip library code! 9 goto lib_init; // skip library code!
10 10
11 print_int: // print_int (int) -> () 11 print_int: // print_int (int) -> ()
12 - printf ("%d\n", M[SP+1]); 12 + printf ("%ld\n", M[SP+1]);
13 goto * ((void *) M[SP++]); 13 goto * ((void *) M[SP++]);
14 14
15 print_char: // print_char (int) -> () 15 print_char: // print_char (int) -> ()
@@ -17,7 +17,7 @@ print_char: // print_char (int) -&gt; () @@ -17,7 +17,7 @@ print_char: // print_char (int) -&gt; ()
17 goto * ((void *) M[SP++]); 17 goto * ((void *) M[SP++]);
18 18
19 read_int: // read_int () -> int 19 read_int: // read_int () -> int
20 - scanf ("%d", &M[SP+1]); 20 + scanf ("%ld", &M[SP+1]);
21 goto * ((void *) M[SP++]); 21 goto * ((void *) M[SP++]);
22 22
23 read_char: // read_char () -> int 23 read_char: // read_char () -> int
@@ -30,9 +30,9 @@ halt: // halt () -&gt; () @@ -30,9 +30,9 @@ halt: // halt () -&gt; ()
30 dump_regs: // dump_regs () -> () 30 dump_regs: // dump_regs () -> ()
31 { 31 {
32 printf ("-- Register dump --\n"); 32 printf ("-- Register dump --\n");
33 - printf ("SP = 0x%x (%d)\n", (int) SP, (int) SP);  
34 - printf ("FP = 0x%x (%d)\n", (int) FP, (int) FP);  
35 - printf ("SR = 0x%x (%d)\n", (int) SR, (int) SR); 33 + printf ("SP = 0x%lx (%ld)\n", (long) SP, (long) SP);
  34 + printf ("FP = 0x%lx (%ld)\n", (long) FP, (long) FP);
  35 + printf ("SR = 0x%lx (%ld)\n", (long) SR, (long) SR);
36 printf ("PC = (unused)\n"); 36 printf ("PC = (unused)\n");
37 } 37 }
38 goto * ((void *) M[SP++]); 38 goto * ((void *) M[SP++]);
sim2c-1.0/test3.c
1 #include <stdio.h> 1 #include <stdio.h>
  2 +#include <stdlib.h>
2 3
3 // == Global data ============================================================= 4 // == Global data =============================================================
4 5
@@ -13,15 +14,15 @@ @@ -13,15 +14,15 @@
13 #define MEM_SZ ((DATA_SZ) + (HEAP_SZ) + (STACK_SZ)) 14 #define MEM_SZ ((DATA_SZ) + (HEAP_SZ) + (STACK_SZ))
14 15
15 union { 16 union {
16 - int mem[0]; 17 + long mem[0];
17 struct { 18 struct {
18 - int m_x;  
19 - int m_xpto[20]; 19 + long m_x;
  20 + long m_xpto[20];
20 } named; 21 } named;
21 struct { 22 struct {
22 - int z_data[DATA_SZ];  
23 - int z_heap[HEAP_SZ];  
24 - int z_stack[STACK_SZ]; 23 + long z_data[DATA_SZ];
  24 + long z_heap[HEAP_SZ];
  25 + long z_stack[STACK_SZ];
25 } zone; 26 } zone;
26 } global; 27 } global;
27 28
@@ -30,21 +31,21 @@ union { @@ -30,21 +31,21 @@ union {
30 #define HEAP global.zone.z_heap 31 #define HEAP global.zone.z_heap
31 #define STACK global.zone.z_stack 32 #define STACK global.zone.z_stack
32 33
33 -int SP = MEM_SZ;  
34 -int FP = 0;  
35 -int SR; 34 +long SP = MEM_SZ;
  35 +long FP = 0;
  36 +long SR;
36 void *PC; // (unused) 37 void *PC; // (unused)
37 38
38 // -- Names for global variables ---------------------------------------------- 39 // -- Names for global variables ----------------------------------------------
39 40
40 -#define GV_x ((int *) &global.named.m_x - (int *) &global.named)  
41 -#define GV_xpto ((int *) &global.named.m_xpto - (int *) &global.named) 41 +#define GV_x ((long *) &global.named.m_x - (long *) &global.named)
  42 +#define GV_xpto ((long *) &global.named.m_xpto - (long *) &global.named)
42 43
43 // == Program ================================================================= 44 // == Program =================================================================
44 45
45 int main (int argc, char *argv[]) 46 int main (int argc, char *argv[])
46 { 47 {
47 - int i; 48 + long i;
48 49
49 // -- Initialization ---------------------------------------------------------- 50 // -- Initialization ----------------------------------------------------------
50 global.named.m_x = 123; 51 global.named.m_x = 123;
@@ -55,7 +56,7 @@ int main (int argc, char *argv[]) @@ -55,7 +56,7 @@ int main (int argc, char *argv[])
55 goto lib_init; // skip library code! 56 goto lib_init; // skip library code!
56 57
57 print_int: // print_int (int) -> () 58 print_int: // print_int (int) -> ()
58 - printf ("%d\n", M[SP+1]); 59 + printf ("%ld\n", M[SP+1]);
59 goto * ((void *) M[SP++]); 60 goto * ((void *) M[SP++]);
60 61
61 print_char: // print_char (int) -> () 62 print_char: // print_char (int) -> ()
@@ -63,7 +64,7 @@ print_char: // print_char (int) -&gt; () @@ -63,7 +64,7 @@ print_char: // print_char (int) -&gt; ()
63 goto * ((void *) M[SP++]); 64 goto * ((void *) M[SP++]);
64 65
65 read_int: // read_int () -> int 66 read_int: // read_int () -> int
66 - scanf ("%d", &M[SP+1]); 67 + scanf ("%ld", &M[SP+1]);
67 goto * ((void *) M[SP++]); 68 goto * ((void *) M[SP++]);
68 69
69 read_char: // read_char () -> int 70 read_char: // read_char () -> int
@@ -76,9 +77,9 @@ halt: // halt () -&gt; () @@ -76,9 +77,9 @@ halt: // halt () -&gt; ()
76 dump_regs: // dump_regs () -> () 77 dump_regs: // dump_regs () -> ()
77 { 78 {
78 printf ("-- Register dump --\n"); 79 printf ("-- Register dump --\n");
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); 80 + printf ("SP = 0x%lx (%ld)\n", (long) SP, (long) SP);
  81 + printf ("FP = 0x%lx (%ld)\n", (long) FP, (long) FP);
  82 + printf ("SR = 0x%lx (%ld)\n", (long) SR, (long) SR);
82 printf ("PC = (unused)\n"); 83 printf ("PC = (unused)\n");
83 } 84 }
84 goto * ((void *) M[SP++]); 85 goto * ((void *) M[SP++]);
@@ -108,7 +109,7 @@ lib_init: @@ -108,7 +109,7 @@ lib_init:
108 } 109 }
109 110
110 // -- Start execution --------------------------------------------------------- 111 // -- Start execution ---------------------------------------------------------
111 - M[--SP] = (int) &&L_exit_program; // Save return address for main program 112 + M[--SP] = (long) &&L_exit_program; // Save return address for main program
112 goto program; // start kicking... 113 goto program; // start kicking...
113 L_exit_program: // Return here, and... 114 L_exit_program: // Return here, and...
114 exit (0); // quit. 115 exit (0); // quit.
@@ -117,10 +118,10 @@ L_exit_program: // Return here, and... @@ -117,10 +118,10 @@ L_exit_program: // Return here, and...
117 // -- Instructions ------------------------------------------------------------ 118 // -- Instructions ------------------------------------------------------------
118 program: 119 program:
119 M[--SP] = 0; // PUSH 0 120 M[--SP] = 0; // PUSH 0
120 - { int N = M[SP]; M[SP]= FP; FP=SP+1; SP -= N; } // LINK 121 + { long N = M[SP]; M[SP]= FP; FP=SP+1; SP -= N; } // LINK
121 M[--SP] = 12; // PUSH 12 122 M[--SP] = 12; // PUSH 12
122 - M[--SP] = (int) &&print_int; // PUSH print_int  
123 - { void *C = (void *) M[SP]; M[SP]=(int)&&P_6; goto *C; } // CALL 123 + M[--SP] = (long) &&print_int; // PUSH print_int
  124 + { void *C = (void *) M[SP]; M[SP]=(long)&&P_6; goto *C; } // CALL
124 P_6: SP=FP; FP=M[SP-1]; // UNLINK 125 P_6: SP=FP; FP=M[SP-1]; // UNLINK
125 goto * ((void *) M[SP++]); // JUMP 126 goto * ((void *) M[SP++]); // JUMP
126 127