Added an example of how to import external functions

This commit is contained in:
Cédric Pasteur 2010-07-27 11:12:33 +02:00
parent d3fea3aad3
commit ac8dce35dc
5 changed files with 28 additions and 0 deletions

6
examples/extern_C/README Normal file
View File

@ -0,0 +1,6 @@
This example show how to import an external function written in C in an Heptagon program.
- The .epi file contains the signature of the function in Heptagon.
- Only functions with no side effects can be safely imported.
- The imported function must have the same calling convention as generated code (inputs given by value, outputs in a f_out structure).
- The generated code will include "mathext.h", that should define the step function

View File

@ -0,0 +1,6 @@
open Mathext
fun f(a:float) returns (o:float)
let
o = mycos(a);
tel

View File

@ -0,0 +1,7 @@
#include <math.h>
#include "mathext.h"
void mycos(float a, mycos_out *out)
{
out->o = cos(a);
}

View File

@ -0,0 +1 @@
val fun mycos(a:float) returns (o:float)

View File

@ -0,0 +1,8 @@
#ifdef MATHEXT_H
#define MATHEXT_H
struct mycos_out {
float o;
};
void mycos(float a, mycos_out *o);