-
Notifications
You must be signed in to change notification settings - Fork 50
CPP Backend
brett hartshorn edited this page Sep 19, 2015
·
2 revisions
After git cloning this repo, try async_channels.md, you just need Python2 and g++ installed. The command below will save the compiled exe to your temp folder and run it.
cd Rusthon
./rusthon.py ./examples/async_channels.md
The option --tar
can be used to save the source code of the translated code,
javascripts and python scripts inside the markdown, and compiled exes.
./rusthon.py myproject.md --tar project.tar
Rusthon supports GCC inline assembly using the C++ backend. This allows you to fully optimize CPU performance, and code directly for bare metal.
Assembly code is given inside a with asm(...):
indented block.
The syntax is:
with asm( outputs=R, inputs=(...), volatile=True/False, clobber=('cc', 'memory', ...) ):
movl %1 %%ebx;
...
The with asm
options follow GCC's extended ASM syntax.
http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#s5
def test_single_input( a : int ) -> int:
b = 0
with asm( outputs=b, inputs=a, volatile=True, clobber='%ebx', alignstack=True ):
movl %1, %%ebx;
movl %%ebx, %0;
return b
def test_multi_input( a : int, b : int ) -> int:
out = 0
with asm( outputs=out, inputs=(a,b), volatile=True, clobber=('%ebx','memory') ):
movl %1, %%ebx;
addl %2, %%ebx;
movl %%ebx, %0;
return out
def main():
x = test_single_input(999)
print x ## prints 999
y = test_multi_input(400, 20)
print y ## prints 420
int test_single_input(int a) {
auto b = 0;
asm volatile ( "movl %1, %%ebx;movl %%ebx, %0;" : "=r" (b) : "r" (a) : "%ebx" );
return b;
}
int test_multi_input(int a, int b) {
auto out = 0;
asm volatile ( "movl %1, %%ebx;addl %2, %%ebx;movl %%ebx, %0;" : "=r" (out) : "r" (a),"r" (b) : "%ebx","memory" );
return out;
}
int main() {
auto x = test_single_input(999);
std::cout << x << std::endl;
auto y = test_multi_input(400, 20);
std::cout << y << std::endl;
return 0;
}