-
Notifications
You must be signed in to change notification settings - Fork 0
/
CelciusFarenheit.hl
67 lines (59 loc) · 1.33 KB
/
CelciusFarenheit.hl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// -*- c -*-
#include <stdio.h>
#include <stdlib.h>
typedef int (*pifi)(int);
h2_insn_t * genC2F(h2_insn_t * ptr)
{
#[
int 32 1 C2F (int 32 1 a)
{
int 32 1 r;
r = a * 9 / 5 + 32;
return r;
}
]#
return (h2_insn_t *) ptr;
}
h2_insn_t * genF2C(h2_insn_t * ptr)
{
#[
int 32 1 F2C (int 32 1 a)
{
int 32 1 r;
r = a - 32 * 5 / 9;
return r;
}
]#
return (h2_insn_t *) ptr;
}
int main(int argc, char * argv[])
{
h2_insn_t * ptr;
int in0, res, resultOK;
pifi fC2F, fF2C;
resultOK = 0;
if (argc < 2)
{
printf("Give 1 values\n");
exit(-1);
}
in0 = atoi (argv[1]); // Get the users values in0
printf("// Compilette for conversion from celcius to farenheit\n");
ptr = h2_malloc (1024); // Allocate memory for 1024 instructions
fC2F = (pifi) genC2F (ptr); //
res = fC2F(in0); // Call generated code
printf("%d (celcius) -> (farenheit)%d\n", in0, res);
if (res != (in0 * 9 / 5 + 32))
resultOK += 1;
printf("// Compilette for conversion from farenheit to celcius\n");
ptr = h2_malloc (1024); // Allocate memory for 1024 instructions
fF2C = (pifi) genF2C (ptr); //
res = fF2C(in0); // Call generated code
printf("%d (farenheit) -> (celcius)%d\n", in0, res);
if (res != (in0 - 32 * 5 / 9))
resultOK += 1;
if (resultOK == 0)
return 0;
else
return -1;
}