Skip to content

Commit 1a35344

Browse files
Merge branch 'develop' into main
2 parents 4f20109 + b680d5d commit 1a35344

18 files changed

+75
-116
lines changed

core/generators.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,11 @@ def generate_stmt_return(program, function, exp=None):
388388
if isinstance(c_type, ast.SignedInt) and probs_helper.random_value(probs.int_emulate_bool):
389389
value = probs_helper.random_value({0: 0.5, 1: 0.5})
390390
exp = ast.Literal("/* EMULATED BOOL LITERAL */ ({}) {}".format(c_type.name, value), c_type)
391-
else:
392-
exp = generate_expression(program, function, c_type, probs.return_exp_depth_prob)
393-
return ast.Return(exp, c_type)
391+
return ast.Return(exp, c_type)
392+
elif not isinstance(c_type, ast.Void): # return <expression>;
393+
exp = generate_expression(program, function, c_type, probs.return_exp_depth_prob)
394+
return ast.Return(exp, c_type)
395+
return ast.Return() # return; (without expression)
394396

395397

396398
def generate_stmt_block(program: Program, function: Function, stmt_depth: int) -> Block:
@@ -603,7 +605,6 @@ def generate_program():
603605
program = ast.Program()
604606
program.main = main_function = ast.Function("main", ast.SignedInt(), [])
605607
for i in range(number_statements):
606-
print_if_verbose("." if i % 1000 else "\n", end="")
607608
program.main.stmts.append(generate_stmt_func(program, main_function))
608609
main_function.stmts.append(generate_stmt_return(program, main_function, exp=0))
609610
return program

docs/run.html

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,48 +189,58 @@ <h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this
189189
<div class="section" id="module-run.1_function_each_type">
190190
<span id="run-1-function-each-type-module"></span><h2>run.1-function-each-type module<a class="headerlink" href="#module-run.1_function_each_type" title="Permalink to this headline"></a></h2>
191191
<p>Example execution of Cnerator to create a particular number of functions.
192-
It creates a program using the <code class="docutils literal notranslate"><span class="pre">1-function-each-type-10.json</span></code> file, running different visitors.</p>
192+
It creates a program using the <code class="docutils literal notranslate"><span class="pre">1_function-each-type-10.json</span></code> file, running different visitors.
193+
Run it from the parent folder with <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">run.1_function_each_type</span></code>.</p>
193194
</div>
194195
<div class="section" id="module-run.15_function_each_type">
195196
<span id="run-15-function-each-type-module"></span><h2>run.15-function-each-type module<a class="headerlink" href="#module-run.15_function_each_type" title="Permalink to this headline"></a></h2>
196197
<p>Example execution of Cnerator to create a particular number of functions.
197-
It creates a program using the <code class="docutils literal notranslate"><span class="pre">15-function-each-type.json</span></code> file, running different visitors.</p>
198+
It creates a program using the <code class="docutils literal notranslate"><span class="pre">15-function-each-type.json</span></code> file, running different visitors.
199+
Run it from the parent folder with <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">run.15_function_each_type</span></code>.</p>
198200
</div>
199201
<div class="section" id="module-run.2000_function_void_no_void">
200202
<span id="run-2000-function-void-no-void-module"></span><h2>run.2000-function-void-no-void module<a class="headerlink" href="#module-run.2000_function_void_no_void" title="Permalink to this headline"></a></h2>
201203
<p>Example execution of Cnerator to create a particular number of functions.
202-
It creates a program using the <code class="docutils literal notranslate"><span class="pre">2000-function-void-no-void.json</span></code> file, running different visitors.</p>
204+
It creates a program using the <code class="docutils literal notranslate"><span class="pre">2000-function-void-no-void.json</span></code> file, running different visitors.
205+
Run it from the parent folder with <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">run.2000_function_void_no_void</span></code>.</p>
203206
</div>
204207
<div class="section" id="module-run.300_function_each_type">
205208
<span id="run-300-function-each-type-module"></span><h2>run.300-function-each-type module<a class="headerlink" href="#module-run.300_function_each_type" title="Permalink to this headline"></a></h2>
206209
<p>Example execution of Cnerator to create a particular number of functions.
207-
It creates a program using the <code class="docutils literal notranslate"><span class="pre">300-function-each-type.json</span></code> file, running different visitors.</p>
210+
It creates a program using the <code class="docutils literal notranslate"><span class="pre">300-function-each-type.json</span></code> file, running different visitors.
211+
Run it from the parent folder with <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">run.300_function_each_type</span></code>.</p>
208212
</div>
209213
<div class="section" id="module-run.article">
210214
<span id="run-article-module"></span><h2>run.article module<a class="headerlink" href="#module-run.article" title="Permalink to this headline"></a></h2>
211215
<p>Example execution of Cnerator to create particular functions.
212-
It creates a program using the <code class="docutils literal notranslate"><span class="pre">article.json</span></code> file, running different visitors.</p>
216+
It creates a program using the <code class="docutils literal notranslate"><span class="pre">article.json</span></code> file, running different visitors.
217+
Run it from the parent folder with <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">run.article</span></code>.</p>
213218
</div>
214219
<div class="section" id="module-run.defaults">
215220
<span id="run-defaults-module"></span><h2>run.defaults module<a class="headerlink" href="#module-run.defaults" title="Permalink to this headline"></a></h2>
216221
<p>Example execution of Cnerator passing no parameters.
217-
It creates a random program considering the default probabilities.</p>
222+
It creates a random program considering the default probabilities.
223+
Run it from the parent folder with <a href="#id1"><span class="problematic" id="id2">``</span></a>python -m run.defaults`.</p>
218224
</div>
219225
<div class="section" id="module-run.defaults_one_file">
220226
<span id="run-defaults-one-file-module"></span><h2>run.defaults_one_file module<a class="headerlink" href="#module-run.defaults_one_file" title="Permalink to this headline"></a></h2>
221-
<p>Example execution of Cnerator passing no parameters but generation in one file (<code class="docutils literal notranslate"><span class="pre">-n</span> <span class="pre">1</span></code>).</p>
227+
<p>Example execution of Cnerator passing no parameters but generation in one file (<code class="docutils literal notranslate"><span class="pre">-n</span> <span class="pre">1</span></code>).
228+
Run it from the parent folder with <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">run.defaults_one_file</span></code>.</p>
222229
</div>
223230
<div class="section" id="module-run.help">
224231
<span id="run-help-module"></span><h2>run.help module<a class="headerlink" href="#module-run.help" title="Permalink to this headline"></a></h2>
225-
<p>Example execution of Cnerator passing the <code class="docutils literal notranslate"><span class="pre">--help</span></code> parameter.</p>
232+
<p>Example execution of Cnerator passing the <code class="docutils literal notranslate"><span class="pre">--help</span></code> parameter.
233+
Run it from the parent folder with <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">run.help</span></code>.</p>
226234
</div>
227235
<div class="section" id="module-run.probs">
228236
<span id="run-probs-module"></span><h2>run.probs module<a class="headerlink" href="#module-run.probs" title="Permalink to this headline"></a></h2>
229-
<p>Example execution of Cnerator passing the <code class="docutils literal notranslate"><span class="pre">-p</span></code> parameter to specify the probabilities of two language constructs.</p>
237+
<p>Example execution of Cnerator passing the <code class="docutils literal notranslate"><span class="pre">-p</span></code> parameter to specify the probabilities of two language constructs.
238+
Run it from the parent folder with <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">run.probs</span></code>.</p>
230239
</div>
231240
<div class="section" id="module-run.probs_file">
232241
<span id="run-probs-file-module"></span><h2>run.probs_file module<a class="headerlink" href="#module-run.probs_file" title="Permalink to this headline"></a></h2>
233-
<p>Example execution of Cnerator specifying probabilities in a json file (<code class="docutils literal notranslate"><span class="pre">example_probs.json</span></code>).</p>
242+
<p>Example execution of Cnerator specifying probabilities in a json file (<code class="docutils literal notranslate"><span class="pre">example_probs.json</span></code>).
243+
Run it from the parent folder with <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">run.probs_file</span></code>.</p>
234244
</div>
235245
</div>
236246

docs/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

run/15_function_each_type.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
Example execution of Cnerator to create a particular number of functions.
66
It creates a program using the ``15-function-each-type.json`` file, running different visitors.
7+
Run it from the parent folder with ``python -m run.15_function_each_type``.
78
"""
89

910
import sys
@@ -13,9 +14,9 @@
1314

1415
if __name__ == "__main__":
1516
sys.argv.append('-O') # generate output files in ../out
16-
sys.argv.append('../out') # generate output files in ../out
17+
sys.argv.append('out') # generate output files in ../out
1718
sys.argv.append('-f') # controlled function generation
18-
sys.argv.append('../json/functions/15-function-each-type.json') # controlled function generation
19+
sys.argv.append('json/functions/15-function-each-type.json') # controlled function generation
1920
sys.argv.append('-V') # visitor post-processing
2021
sys.argv.append('visitors.func_to_proc:visitors.return_instrumentation:visitors.fix_ptr_literal')
2122
if VERBOSE:

run/1_function_each_type.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
"""
55
Example execution of Cnerator to create a particular number of functions.
6-
It creates a program using the ``1-function-each-type-10.json`` file, running different visitors.
6+
It creates a program using the ``1_function-each-type-10.json`` file, running different visitors.
7+
Run it from the parent folder with ``python -m run.1_function_each_type``.
78
"""
89

910
import sys
@@ -13,9 +14,9 @@
1314

1415
if __name__ == "__main__":
1516
sys.argv.append('-O') # generate output files in ../out
16-
sys.argv.append('../out') # generate output files in ../out
17+
sys.argv.append('out') # generate output files in ../out
1718
sys.argv.append('-f') # controlled function generation
18-
sys.argv.append('../json/functions/1-function-each-type.json') # controlled function generation
19+
sys.argv.append('json/functions/1-function-each-type.json') # controlled function generation
1920
sys.argv.append('-V') # visitor post-processing
2021
sys.argv.append('visitors.func_to_proc:visitors.return_instrumentation:visitors.fix_ptr_literal')
2122
sys.argv.append('-n') # generate all the code in one file

run/2000_function_void_no_void.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
Example execution of Cnerator to create a particular number of functions.
66
It creates a program using the ``2000-function-void-no-void.json`` file, running different visitors.
7+
Run it from the parent folder with ``python -m run.2000_function_void_no_void``.
78
"""
89

910
import sys
@@ -13,9 +14,9 @@
1314

1415
if __name__ == "__main__":
1516
sys.argv.append('-O') # generate output files in ../out
16-
sys.argv.append('../out') # generate output files in ../out
17+
sys.argv.append('out') # generate output files in ../out
1718
sys.argv.append('-f') # controlled function generation
18-
sys.argv.append('../json/functions/2000-function-void-no-void.json') # controlled function generation
19+
sys.argv.append('json/functions/2000-function-void-no-void.json') # controlled function generation
1920
sys.argv.append('-V') # visitor post-processing
2021
sys.argv.append('visitors.func_to_proc:visitors.return_instrumentation:visitors.fix_ptr_literal')
2122
if VERBOSE:

run/300_function_each_type.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
Example execution of Cnerator to create a particular number of functions.
66
It creates a program using the ``300-function-each-type.json`` file, running different visitors.
7+
Run it from the parent folder with ``python -m run.300_function_each_type``.
78
"""
89

910
import sys
@@ -13,9 +14,9 @@
1314

1415
if __name__ == "__main__":
1516
sys.argv.append('-O') # generate output files in ../out
16-
sys.argv.append('../out') # generate output files in ../out
17+
sys.argv.append('out') # generate output files in ../out
1718
sys.argv.append('-f') # controlled function generation
18-
sys.argv.append('../json/functions/300-function-each-type.json') # controlled function generation
19+
sys.argv.append('json/functions/300-function-each-type.json') # controlled function generation
1920
sys.argv.append('-V') # visitor post-processing
2021
sys.argv.append('visitors.func_to_proc:visitors.return_instrumentation:visitors.fix_ptr_literal')
2122
if VERBOSE:

run/article.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
"""
55
Example execution of Cnerator to create particular functions.
66
It creates a program using the ``article.json`` file, running different visitors.
7+
Run it from the parent folder with ``python -m run.article``.
78
"""
89

9-
import sys
1010
import cnerator
11+
import sys
1112

1213
VERBOSE = True
1314

1415
if __name__ == "__main__":
1516
sys.argv.append('-O') # generate output files in ../out
16-
sys.argv.append('../out') # generate output files in ../out
17+
sys.argv.append('out') # generate output files in ../out
1718
sys.argv.append('-f') # controlled function generation
18-
sys.argv.append('../json/functions/article.json') # controlled function generation
19+
sys.argv.append('json/functions/article.json') # controlled function generation
1920
sys.argv.append('-V') # visitor post-processing
2021
sys.argv.append('visitors.return_instrumentation:visitors.fix_ptr_literal') # visitor post-processing
2122
sys.argv.append('-P') # probabilities file
22-
sys.argv.append('../json/probabilities/article.json') # probabilities file
23+
sys.argv.append('json/probabilities/article.json') # probabilities file
2324
sys.argv.append('-n') # generate all the code in one file
2425
sys.argv.append('1') # generate all the code in one file
2526
if VERBOSE:

run/defaults.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
Example execution of Cnerator passing no parameters.
66
It creates a random program considering the default probabilities.
7+
Run it from the parent folder with ``python -m run.defaults`.
78
"""
89

910
import sys
@@ -13,7 +14,7 @@
1314

1415
if __name__ == "__main__":
1516
sys.argv.append('-O') # generate output files in ../out
16-
sys.argv.append('../out') # generate output files in ../out
17+
sys.argv.append('out') # generate output files in ../out
1718
if VERBOSE:
1819
sys.argv.append("-v")
1920
cnerator.main()

run/defaults_one_file.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
"""
55
Example execution of Cnerator passing no parameters but generation in one file (``-n 1``).
6+
Run it from the parent folder with ``python -m run.defaults_one_file``.
67
"""
78

89
import sys
@@ -12,7 +13,7 @@
1213

1314
if __name__ == "__main__":
1415
sys.argv.append('-O') # generate output files in ../out
15-
sys.argv.append('../out') # generate output files in ../out
16+
sys.argv.append('out') # generate output files in ../out
1617
sys.argv.append('-n') # generate all the code in one file
1718
sys.argv.append('1') # generate all the code in one file
1819
if VERBOSE:

0 commit comments

Comments
 (0)