Skip to content

Commit

Permalink
Change C string literal type to array of char.
Browse files Browse the repository at this point in the history
  • Loading branch information
windelbouwman committed Jun 24, 2019
1 parent 64c2186 commit cd69292
Show file tree
Hide file tree
Showing 24 changed files with 469 additions and 267 deletions.
11 changes: 11 additions & 0 deletions .hgignore
Expand Up @@ -22,7 +22,16 @@ docs/_build
docs/examples.zip
examples/linux64/hello/hello
examples/linux64/snake/snake
examples/linux64/fib/main
examples/linux64/algos/main
examples/linux64/wasm_fac/wasm_fact
examples/m68k/demo
examples/microblaze/hello/trace.txt
examples/python/generated_python_structs.py
examples/python/python_snake2.py
examples/riscvpicorv32/picorv
examples/toydsl/dslenv
examples/toydsl/example
.pytest_cache/
test/.coverage
test/listings
Expand All @@ -31,6 +40,8 @@ test/FORTRAN
.mypy_cache
*report.html
tools/report*.html
tools/ppci_explorer_source.txt
tools/arch_info.html
.cache
.coverage
htmlcov
Expand Down
11 changes: 11 additions & 0 deletions docs/development.rst
Expand Up @@ -108,6 +108,17 @@ pyprof2calltree.
$ pip install pyprof2calltree
$ pyprof2calltree -i profiled.out -k
Debugging tests
~~~~~~~~~~~~~~~

To debug test cases, a handy trick is to use pudb (when not using fancy ide
like vscode or pycharm). To do this, specify the debugger to use with pytest
like this:

.. code:: bash
$ pytest -v --pdb --pdbcls pudb.debugger:Debugger --capture=no
Debugging dynamic code
~~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion examples/c/hello/std.c
@@ -1,6 +1,6 @@

#include "std.h"

void printf()
void printf(char* x)
{
}
2 changes: 1 addition & 1 deletion examples/c/hello/std.h
@@ -1,2 +1,2 @@

void printf();
void printf(char*);
45 changes: 25 additions & 20 deletions examples/python/python_snake.py
@@ -1,35 +1,40 @@
import io
from ppci.api import ir_to_python, c3toir, get_arch
from ppci.api import ir_to_python, c3_to_ir, get_arch


def run_it():
arch = get_arch('example')
bsp = io.StringIO("""
arch = get_arch("example")
bsp = io.StringIO(
"""
module bsp;
public function void sleep(int ms);
public function void putc(byte c);
public function bool get_key(int* key);
""")
"""
)

ircode = c3toir(
['../src/snake/game.c3', '../src/snake/main.c3', '../../librt/io.c3'],
[bsp], arch)
ircode = c3_to_ir(
["../src/snake/game.c3", "../src/snake/main.c3", "../../librt/io.c3"],
[bsp],
arch,
)

with open('python_snake2.py', 'w') as f:
print('import time', file=f)
print('import sys', file=f)
print('import threading', file=f)
ir_to_python(ircode, f)
with open("python_snake2.py", "w") as f:
print("import time", file=f)
print("import sys", file=f)
print("import threading", file=f)
ir_to_python([ircode], f)

print('', file=f)
print('def bsp_putc(c):', file=f)
print("", file=f)
print("def bsp_putc(c):", file=f)
print(' print(chr(c), end="")', file=f)
print('def bsp_get_key(x):', file=f)
print(' return 0', file=f)
print('def bsp_sleep(x):', file=f)
print(' time.sleep(x*0.001)', file=f)
print('main_main()', file=f)
print("def bsp_get_key(x):", file=f)
print(" return 0", file=f)
print("def bsp_sleep(x):", file=f)
print(" time.sleep(x*0.001)", file=f)
print("main_main()", file=f)

print("Now run python_snake2.py !")

print('Now run python_snake2.py !')

run_it()
3 changes: 2 additions & 1 deletion librt/libc/assert.h
@@ -1,6 +1,7 @@
#ifndef ASSERT_H
#define ASSERT_H

#define assert(x)
// do nothing for now..
#define assert(x) (0)

#endif

0 comments on commit cd69292

Please sign in to comment.