comparison gsm-fw/services/ffs/mktarget.pl @ 217:30a173257f4a

gsm-fw/services/ffs: ffs_target.c generation and compilation
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 06 Jan 2014 08:07:36 +0000
parents
children
comparison
equal deleted inserted replaced
216:0eb85790c0ed 217:30a173257f4a
1 #!/usr/bin/perl -w
2 #
3 # mktarget.pl by Mads Meisner-Jensen (mmj@ti.com)
4 #
5 # Auto-generate target code from ffs.c source file.
6 #
7
8 $FFSPATH = shift;
9 if (!defined($FFSPATH) || $FFSPATH eq "") {
10 $FFSPATH = ".";
11 }
12
13 $OUTPATH = shift;
14 if (!defined($OUTPATH) || $OUTPATH eq "") {
15 $OUTPATH = $FFSPATH;
16 }
17
18 $verbose = 1;
19
20 $STATE_OUTSIDE = 0;
21 $STATE_IN_FUNCTION = 1;
22 $STATE_IN_TASK = 2;
23 $state = $STATE_OUTSIDE;
24
25
26 ############################################################################
27 # Main
28 ############################################################################
29
30 $verbose > 0 && print "mktarget.pl operating in directory '$FFSPATH'\n";
31
32 open (FFS, "<$FFSPATH/ffs.c") || die "Failed to open 'ffs.c'";
33 print $OUTPATH;
34 open (TARGETC, ">$OUTPATH/ffs_target.c") || die "Failed to open 'ffs_target.c'";
35
36 target_put("/**********************************************************\n");
37 target_put(" *\n");
38 target_put(" * This is an auto-generated file. Do NOT edit!\n");
39 target_put(" *\n");
40 target_put(" **********************************************************/\n\n\n");
41
42 while (<FFS>)
43 {
44 if ($state == $STATE_OUTSIDE)
45 {
46 target_put($_);
47 if (/^{\s*$/) {
48 $state = $STATE_IN_FUNCTION;
49 }
50 }
51 elsif ($state == $STATE_IN_FUNCTION)
52 {
53 if (/^\s*\/\/\s*TASKBEGIN\s*(\w+)\s*(\w+)\s*\((.*)\)(.*)$/m)
54 {
55 $state = $STATE_IN_TASK;
56
57 $rettype = $1;
58 $func = $2;
59 $funclc = lc($func);
60
61 @args = split(',', $3);
62 @values = ();
63 @reqmembers = ();
64 foreach (@args) {
65 ($left, $right) = $_ =~ /(\w+)=(.+)/m;
66 push (@reqmembers, $left);
67 push (@values, $right);
68 }
69
70 @vars = split(';', $4);
71
72 task_begin();
73 }
74 else
75 {
76 target_put($_);
77 if (/^}\s*$/m) {
78 $state = $STATE_OUTSIDE;
79
80 # Write the task_* code after the function
81 target_put("\n");
82 target_put(@taskcode);
83 @taskcode = ();
84 }
85 }
86 }
87 elsif ($state == $STATE_IN_TASK)
88 {
89 if (/^.*TASKEND.*$/m)
90 {
91 $state = $STATE_IN_FUNCTION;
92
93 foreach (@values) {
94 if (/^[a-zA-Z]+/m) {
95 task_put("#undef $_\n");
96 }
97 }
98 task_put("\n");
99 # task_put(" return EFFS_OK;\n");
100 task_put("}\n\n");
101 }
102 else {
103 task_put($_);
104 }
105 }
106 else
107 {
108 die "Bad state!";
109 }
110 }
111
112 close (FFS) || die;
113 close (TARGETC) || die;
114
115 sub task_put
116 {
117 push (@taskcode, @_);
118 }
119
120 sub target_put
121 {
122 print TARGETC @_;
123 }
124
125 sub task_begin
126 {
127 $verbose > 0 && print "ffs_$funclc ($func)\n";
128 $verbose > 1 && print " args = @args\n";
129 $verbose > 1 && print " left = @values, right = @reqmembers\n";
130 $verbose > 1 && print " vars = @vars\n";
131 $verbose > 1 && print "\n";
132
133 task_put("$rettype task_$funclc(struct ffs_req_s *p)\n");
134 task_put("{\n");
135 foreach (@vars) {
136 task_put(" $_;\n");
137 }
138 task_put("\n");
139 for $i (0..$#args) {
140 # If value starts with alpha char, e.g. a variable name
141 if ($values[$i] =~ /^[a-zA-Z]+/m) {
142 task_put("#define $values[$i] p->$reqmembers[$i]\n");
143 }
144 }
145
146 target_put(" {\n");
147 target_put(" struct ffs_req_s *req;\n");
148 target_put(" MSG_ALLOC(req);\n");
149
150 for $i (0..$#args) {
151 # Typecasting is necessary for the sake of the tms470 compiler
152 if ($reqmembers[$i] eq "src") {
153 target_put(" req->$reqmembers[$i] = (char *) $values[$i];\n");
154 }
155 else {
156 target_put(" req->$reqmembers[$i] = $values[$i];\n");
157 }
158 }
159 target_put(" req->request_id = request_id_get();\n");
160 target_put(" req->fb = fb;\n");
161 target_put(" req->cp = cp;\n");
162 target_put(" req->cmd = $func;\n");
163 target_put(" MSG_SEND(req);\n");
164 target_put(" return req->request_id;\n");
165 target_put(" }\n");
166
167 }