feat(tp3-obj1)

This commit is contained in:
Hugo Meens 2025-04-25 12:08:31 +02:00
parent e4242061c3
commit bba56ded14
9 changed files with 152 additions and 2 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.tar.gz
*.out
*.log
*.ecpi

View File

@ -6,10 +6,10 @@ all: main
a: extern.epi
heptc $<
$(OBJ): hs_handler.ept a
b: hs_handler.ept a
heptc -target c $<
main: $(OBJ)
main: b
gcc -I $(LIB_PATH)/c -I . main.c $(OBJ)
clean:

21
tp3-obj1-meens/Makefile Normal file
View File

@ -0,0 +1,21 @@
LIB_PATH=$(shell heptc -where)
OBJ=extern.c first_c/first.c first_c/first_types.c
all: main
a: extern.epi
heptc $<
$(OBJ): first.ept a
heptc -target c $<
main: $(OBJ)
gcc -I $(LIB_PATH)/c -I . main.c $(OBJ)
clean:
$(RM) *.log
$(RM) *.epci
$(RM) *.mls
$(RM) *.o *.obj *.obc
$(RM) -r *_c
$(RM) *.out

14
tp3-obj1-meens/extern.c Normal file
View File

@ -0,0 +1,14 @@
#include "extern.h"
#include <stdio.h>
void Extern__print_fast_step(int x, int y, int idx, Extern__print_fast_out *_out) {
printf("Fast - idx: %d, x: %d, y: %d\n", idx, x, y);
}
void Extern__print_gnc_step(int x, int y, int idx, Extern__print_gnc_out *_out) {
printf("GNC - idx: %d, x: %d, y: %d\n", idx, x, y);
}
void Extern__print_thermal_step(int idx, Extern__print_thermal_out *_out) {
printf("Thermal - idx: %d\n", idx);
}

View File

@ -0,0 +1,3 @@
fun print_fast(x:int; y:int; idx:int) returns ()
fun print_gnc(y:int; x:int; idx:int) returns ()
fun print_thermal(idx:int) returns ()

25
tp3-obj1-meens/extern.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef EXTERN_H
#define EXTERN_H
typedef struct {
int x;
int y;
int idx;
} Extern__print_fast_out;
typedef struct {
int y;
int x;
int idx;
} Extern__print_gnc_out;
typedef struct {
int idx;
} Extern__print_thermal_out;
void Extern__print_fast_step(int x, int y, int idx, Extern__print_fast_out *_out);
void Extern__print_gnc_step(int y, int x, int idx, Extern__print_gnc_out *_out);
void Extern__print_thermal_step(int idx, Extern__print_thermal_out *_out);
#endif // EXTERN_H

View File

@ -0,0 +1,6 @@
#ifndef EXTERN_TYPES_H
#define EXTERN_TYPES_H
#endif /* EXTERN_TYPES_H */

60
tp3-obj1-meens/first.ept Normal file
View File

@ -0,0 +1,60 @@
open Extern
node fast(x: int) returns (y: int)
var idx: int;
let
idx = 0 fby (idx + 1);
y = 2 * x + idx;
() = print_fast(x, y, idx);
tel
node condact_f<<y_init: int>>(c: bool; x: int) returns (y: int)
let
y = merge c
(true -> fast(x when c))
(false -> (y_init fby y) whenot c);
tel
node gnc(y: int) returns (x: int)
var idx: int;
let
idx = 0 fby (idx + 1);
x = y - idx;
() = print_gnc(y, x, idx);
tel
node condact_gnc<<x_init:int>>(c:bool; y:int) returns (x:int)
let
x = merge c
(true -> gnc (y when c))
(false -> (x_init fby x) whenot c) ;
tel
node thermal() returns ()
var idx: int;
let
idx = 0 fby (idx + 1);
() = print_thermal(idx);
tel
node condact_thermal(c: bool) returns ()
let
() = thermal() when c;
tel
node main() returns ()
var
mif_cnt,x,y:int;
clk_f,clk_gnc,clk_thermal:bool;
let
(* Clock computation *)
mif_cnt = 0 fby ((mif_cnt+1)%10) ;
clk_f = true ;
clk_thermal = (mif_cnt = 0) ;
clk_gnc = (mif_cnt = 9) ;
(* Flot de données *)
y = condact_f<<31>>(clk_f,99 fby x) ;
()= condact_thermal(true when clk_thermal) ;
x = condact_gnc<<99>>(clk_gnc,y) ;
tel

17
tp3-obj1-meens/main.c Normal file
View File

@ -0,0 +1,17 @@
#include <unistd.h>
#include "first_c/first.h"
#include "first_c/first_types.h"
int main() {
First__main_out _out;
First__main_mem self;
First__main_reset(&self);
while (1) {
First__main_step(&_out, &self);
usleep(1000000);
}
return 0;
}