Updated the example

This commit is contained in:
Cédric Pasteur 2010-07-27 11:32:58 +02:00
parent ac8dce35dc
commit 4e5617588c
5 changed files with 49 additions and 6 deletions

View file

@ -4,3 +4,8 @@ This example show how to import an external function written in C in an 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
To make it work:
heptc mathext.epi
heptc imports.ept
gcc -std=c99 -I . mathext.c imports_c/*.c -o imports

View file

@ -3,4 +3,9 @@ open Mathext
fun f(a:float) returns (o:float)
let
o = mycos(a);
tel
node g(a:float) returns (o:float)
let
o = st_cos(a);
tel

View file

@ -1,7 +1,21 @@
#include <math.h>
#include "mathext.h"
void mycos(float a, mycos_out *out)
void mycos_step(float a, mycos_out *out)
{
out->o = cos(a);
}
void st_cos_reset(st_cos_mem *self)
{
self->i = 0;
for(int j = 0; j < 100; ++j)
self->mem[j] = 0.0;
}
void st_cos_step(float a, st_cos_out *out, st_cos_mem *self)
{
out->o = self->mem[self->i];
self->i = (self->i++) % 100;
self->mem[self->i] = cos(a);
}

View file

@ -1 +1,3 @@
val fun mycos(a:float) returns (o:float)
val fun mycos(a:float) returns (o:float)
val node st_cos(a:float) returns (o:float)

View file

@ -1,8 +1,25 @@
#ifdef MATHEXT_H
#ifndef MATHEXT_H
#define MATHEXT_H
struct mycos_out {
/* Example of a combinatorial function */
typedef struct mycos_out {
float o;
};
} mycos_out;
void mycos_step(float a, mycos_out *o);
/* Example of a statefull function. */
typedef struct st_cos_out {
float o;
} st_cos_out;
typedef struct st_cos_mem {
int i;
float mem[100];
} st_cos_mem;
void st_cos_reset(st_cos_mem *self);
void st_cos_step(float a, st_cos_out *out, st_cos_mem *self);
#endif
void mycos(float a, mycos_out *o);