-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathInterface.pl
119 lines (93 loc) · 2.93 KB
/
Interface.pl
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
### Class Interface: Create a struct with function pointers ###################
BEGIN {
package Interface;
sub new {
my $proto = shift;
my %params = @_;
my $class = ref($proto) || $proto;
my $self = {};
$self->{SFD} = $params{'sfd'};
$self->{BIAS} = -1;
$self->{PADCNT} = 1;
bless ($self, $class);
return $self;
}
sub header {
my $self = shift;
my $sfd = $self->{SFD};
print "/* Automatically generated function table (sfdc SFDC_VERSION)! Do not edit! */\n";
print "\n";
print "#ifndef $sfd->{'BASENAME'}_INTERFACE_DEF_H\n";
print "#define $sfd->{'BASENAME'}_INTERFACE_DEF_H\n";
print "\n";
foreach my $inc (@{$$sfd{'includes'}}) {
print "#include $inc\n";
}
foreach my $td (@{$$sfd{'typedefs'}}) {
print "typedef $td;\n";
}
print "\n";
$self->define_interface_data();
print "\n";
print "struct $sfd->{BaseName}IFace\n";
print "{\n";
$self->output_prelude();
}
sub function {
my $self = shift;
my $sfd = $self->{SFD};
my %params = @_;
my $prototype = $params{'prototype'};
if ($self->{BIAS} == -1) {
$self->{BIAS} = $prototype->{bias} - 6;
}
while ($self->{BIAS} < ($prototype->{bias} - 6)) {
print " APTR Pad$self->{PADCNT};\n";
$self->{BIAS} += 6;
++$self->{PADCNT};
}
$self->{BIAS} = $prototype->{bias};
$self->output_function(@_);
}
sub footer {
my $self = shift;
my $sfd = $self->{SFD};
print "};\n";
print "\n";
print "#endif /* $sfd->{'BASENAME'}_INTERFACE_DEF_H */\n";
}
# Helper functions
sub define_interface_data {
my $self = shift;
my $sfd = $self->{SFD};
print "struct $sfd->{BaseName}InterfaceData {\n";
print " $sfd->{basetype} LibBase;\n";
print "};\n";
}
sub output_prelude {
my $self = shift;
my $sfd = $self->{SFD};
print " struct $sfd->{BaseName}InterfaceData Data;\n";
print "\n";
print " static struct $sfd->{BaseName}IFace* CreateIFace($sfd->{basetype} _$sfd->{base}) {\n";
print " struct $sfd->{BaseName}IFace* _iface = new struct $sfd->{BaseName}IFace();\n";
print " _iface->Data.LibBase = _$sfd->{base};\n";
print " return _iface;\n";
print " }\n";
print "\n";
print " static void DestroyIFace(struct $sfd->{BaseName}IFace* _iface) {\n";
print " delete _iface;\n";
print " }\n";
print "\n";
}
sub output_function {
my $self = shift;
my $sfd = $self->{SFD};
my %params = @_;
my $prototype = $params{'prototype'};
print " $prototype->{return} ";
print "$prototype->{funcname}(";
print join (', ', @{$prototype->{args}});
print ");\n";
}
}