summaryrefslogtreecommitdiff
path: root/apps/plugins/lua
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2018-12-17 09:36:52 -0600
committerWilliam Wilgus <me.theuser@yahoo.com>2018-12-17 09:41:15 -0600
commit28f91ff3dc6e0d7f98c793d022e405781f292eb6 (patch)
treeccacedf2de2a973dfa5061d2a41020982b979131 /apps/plugins/lua
parent622f3f2497a5910e32b0f72beebb216433c97b60 (diff)
downloadrockbox-28f91ff3dc6e0d7f98c793d022e405781f292eb6.tar.gz
rockbox-28f91ff3dc6e0d7f98c793d022e405781f292eb6.zip
Lua Fix settings_helper for the gigaBeastS
the gigabeatS has an embedded struct that needs to be parsed Change-Id: I88c9101afaaa95182f37ade1410cccb4fb768e33
Diffstat (limited to 'apps/plugins/lua')
-rw-r--r--apps/plugins/lua/lua.make2
-rwxr-xr-xapps/plugins/lua/settings_helper.pl66
2 files changed, 51 insertions, 17 deletions
diff --git a/apps/plugins/lua/lua.make b/apps/plugins/lua/lua.make
index ef9705a63d..0eb3c5a5c2 100644
--- a/apps/plugins/lua/lua.make
+++ b/apps/plugins/lua/lua.make
@@ -41,7 +41,7 @@ $(LUA_BUILDDIR)/actions.lua: $(LUA_OBJ) $(LUA_SRCDIR)/action_helper.pl
41 $(call PRINTS,GEN $(@F))$(CC) $(PLUGINFLAGS) $(INCLUDES) -E $(APPSDIR)/plugins/lib/pluginlib_actions.h | $(LUA_SRCDIR)/action_helper.pl > $(LUA_BUILDDIR)/actions.lua 41 $(call PRINTS,GEN $(@F))$(CC) $(PLUGINFLAGS) $(INCLUDES) -E $(APPSDIR)/plugins/lib/pluginlib_actions.h | $(LUA_SRCDIR)/action_helper.pl > $(LUA_BUILDDIR)/actions.lua
42 42
43$(LUA_BUILDDIR)/settings.lua: $(LUA_OBJ) $(LUA_SRCDIR)/settings_helper.pl 43$(LUA_BUILDDIR)/settings.lua: $(LUA_OBJ) $(LUA_SRCDIR)/settings_helper.pl
44 $(SILENT)$(CC) $(INCLUDES) -E $(TARGET) $(CFLAGS) -include plugin.h -include cuesheet.h - < /dev/null | $(LUA_SRCDIR)/settings_helper.pl | \ 44 $(SILENT)$(CC) $(INCLUDES) -E -P $(TARGET) $(CFLAGS) -include plugin.h -include cuesheet.h - < /dev/null | $(LUA_SRCDIR)/settings_helper.pl | \
45 $(CC) $(INCLUDES) $(TARGET) $(CFLAGS) -S -x c -include config.h -include plugin.h -o $(LUA_BUILDDIR)/settings_helper.s - 45 $(CC) $(INCLUDES) $(TARGET) $(CFLAGS) -S -x c -include config.h -include plugin.h -o $(LUA_BUILDDIR)/settings_helper.s -
46 $(call PRINTS,GEN $(@F))$(LUA_SRCDIR)/settings_helper.pl < $(LUA_BUILDDIR)/settings_helper.s > $(LUA_BUILDDIR)/settings.lua 46 $(call PRINTS,GEN $(@F))$(LUA_SRCDIR)/settings_helper.pl < $(LUA_BUILDDIR)/settings_helper.s > $(LUA_BUILDDIR)/settings.lua
47 47
diff --git a/apps/plugins/lua/settings_helper.pl b/apps/plugins/lua/settings_helper.pl
index 215d3a2a3c..2945afd354 100755
--- a/apps/plugins/lua/settings_helper.pl
+++ b/apps/plugins/lua/settings_helper.pl
@@ -17,6 +17,8 @@
17# KIND, either express or implied. 17# KIND, either express or implied.
18# 18#
19############################################################################ 19############################################################################
20use strict;
21use warnings;
20 22
21# Extracts members from c struct 23# Extracts members from c struct
22# places them in a lua array 'member = {offset,size,"type"}' 24# places them in a lua array 'member = {offset,size,"type"}'
@@ -36,7 +38,7 @@ my @sections = (
36 'struct eq_band_setting', 38 'struct eq_band_setting',
37 'struct compressor_settings', 39 'struct compressor_settings',
38 'struct mp3_enc_config', 40 'struct mp3_enc_config',
39 '', 41 '', # nothing to be captured just placeholder for lua section
40 'struct mp3entry', 42 'struct mp3entry',
41 'struct mp3_albumart', 43 'struct mp3_albumart',
42 'struct embedded_cuesheet', 44 'struct embedded_cuesheet',
@@ -108,6 +110,9 @@ my $decl_regex = qr/^(.+?\s.+;)/;
108my $typevar_regex = qr/\W*(?<type>.*?)\W*(?<var>[^\s\[]+)(?<arr>)\W*;/; 110my $typevar_regex = qr/\W*(?<type>.*?)\W*(?<var>[^\s\[]+)(?<arr>)\W*;/;
109my$typevar_array_regex = qr/\W*(?<type>.*?)\W*(?<var>[^\s\[]+)\W*(?<arr>\[.+\]).*;/; 111my$typevar_array_regex = qr/\W*(?<type>.*?)\W*(?<var>[^\s\[]+)\W*(?<arr>\[.+\]).*;/;
110 112
113# struct or union defined within another structure
114my $embed_structunion_regex = qr/\W*(struct|union\s[^;}]+)/;
115
111#.."section",.."member"..=..offset,..size,..type,..arrayct 116#.."section",.."member"..=..offset,..size,..type,..arrayct
112my $asm_regex = qr/.*?,.*?(\".+?\".*?=.*?,.+?,.+?\".+\".*?,.*);/; 117my $asm_regex = qr/.*?,.*?(\".+?\".*?=.*?,.+?,.+?\".+\".*?,.*);/;
113my $asmMOST_regex = qr/\"(?<member>.+)\"=(?<offset>\d+),(?<size>\d+),\"(?<type>.+)\",(?<arr>\d+).*/; 118my $asmMOST_regex = qr/\"(?<member>.+)\"=(?<offset>\d+),(?<size>\d+),\"(?<type>.+)\",(?<arr>\d+).*/;
@@ -132,7 +137,7 @@ while(my $line = <STDIN>)
132 137
133 chomp($line); 138 chomp($line);
134 139
135 if($header) #second pass 140 if($header) # [PASS 2]
136 { 141 {
137 for(my $i = 0; $i < @sections; $i++) 142 for(my $i = 0; $i < @sections; $i++)
138 { 143 {
@@ -156,7 +161,7 @@ while(my $line = <STDIN>)
156 @section_count[$i] = 0; 161 @section_count[$i] = 0;
157 } 162 }
158 } 163 }
159 else #first pass 164 else # [PASS 1]
160 { 165 {
161 if($line =~ $incl_regex){$current_include = $1; next;} 166 if($line =~ $incl_regex){$current_include = $1; next;}
162 elsif($line =~ $extern_regex){next;} 167 elsif($line =~ $extern_regex){next;}
@@ -173,6 +178,25 @@ while(my $line = <STDIN>)
173 $section_lists[$i] .= $1.'@'; 178 $section_lists[$i] .= $1.'@';
174 $section_count[$i]++; 179 $section_count[$i]++;
175 } 180 }
181 # struct or union defined within a structure skip if single line
182 elsif($line =~ $embed_structunion_regex && (index($line, "}") < 0))
183 {
184 my $embedtype = $line;
185 $embedtype =~ s{[^\w\d_]+}{}gx; #strip non conforming chars
186 while($line = <STDIN>)
187 {
188 #skip over the contents user will have to determine how to parse
189 if($line =~ /^\s*}.+$/)
190 {
191 if($line =~ $decl_regex)
192 {
193 $section_lists[$i] .= $embedtype." ".$1.'@';
194 $section_count[$i]++;
195 }
196 last
197 }
198 }
199 }
176 200
177 # struct end? 201 # struct end?
178 if($line =~ $section_end_regex) 202 if($line =~ $section_end_regex)
@@ -206,7 +230,7 @@ for(my $i = 0; $i < @sections; $i++)
206} 230}
207 231
208sub Extract_Variable { 232sub Extract_Variable {
209 #extracts the member, offset, size, and type from the include file 233 #[PASS 1] extracts the member, offset, size, and type from the include file
210 my $sinput = $_[0]; 234 my $sinput = $_[0];
211 my ($type, $var, $arr); 235 my ($type, $var, $arr);
212 236
@@ -216,6 +240,7 @@ sub Extract_Variable {
216 $type = $+{type}; 240 $type = $+{type};
217 $var = $+{var}; 241 $var = $+{var};
218 $arr = $+{var}; 242 $arr = $+{var};
243 if($type eq ''){$type = "<unknown>";}
219 if($sinput =~ s/\bchar\b//){$type = $replace_type{'#string#'};} 244 if($sinput =~ s/\bchar\b//){$type = $replace_type{'#string#'};}
220 else{$type .= ${array_marker};} #for identification of array .. stripped later 245 else{$type .= ${array_marker};} #for identification of array .. stripped later
221 } 246 }
@@ -225,24 +250,32 @@ sub Extract_Variable {
225 $var = $+{var}; 250 $var = $+{var};
226 $arr = $+{var}; 251 $arr = $+{var};
227 } 252 }
228 else { return ('', '', ''); } 253 else {
254 warn "Skipping ".$sinput."\n";
255 return ('', '', '');
256 }
229 257
258 # Type substitutions
230 $type =~ s/^(unsigned|signed|struct)/$replace_type_prefix{$1}/x; 259 $type =~ s/^(unsigned|signed|struct)/$replace_type_prefix{$1}/x;
231 $type =~ s/\b(const|enum)\b/$replace_type_prefix{$1}/gx; 260 $type =~ s/\b(const|enum)\b/$replace_type_prefix{$1}/gx;
232 $type =~ s/^(?:.?+)(bool)\b/$replace_type{lc $1}/ix; 261 $type =~ s/^(?:.?+)(bool)\b/$replace_type{lc $1}/ix;
233 $type =~ s/^(uint|int)(?:\d\d_t)\b/$replace_type{lc $1}/ix; 262 $type =~ s/^(uint|int)(?:\d\d_t)\b/$replace_type{lc $1}/ix; # ...intNN_t...
234 $type =~ s/\b(int|long|char|double)(${array_marker}.*)?\b/$replace_type{$1}$2/; 263 if($type =~ $array_mark_regex)
264 {
265 $type =~ s/\b(int|long|char|double)(${array_marker}.*)\b/$replace_type{$1}$2/;
266 }
267 else {$type =~ s/\b(int|long|char|double)\b/$replace_type{$1}/;}
235 $type =~ s{\s+}{}gx; 268 $type =~ s{\s+}{}gx;
236 269
237 $var =~ s{[^\w\d_]+}{}gx; #strip non conforming chars 270 $var =~ s{[^\w\d_]+}{}gx; # strip non conforming chars
238 271
239 $arr =~ s{[^\[\d\]]+}{}gx; 272 $arr =~ s{[^\[\d\]]+}{}gx; # get element count
240 273
241 return ($type, $var, $arr); 274 return ($type, $var, $arr);
242} 275}
243 276
244sub Print_Variable { 277sub Print_Variable {
245 #prints the member, offset, size, and type from the assembly file 278 #[PASS 2] prints the member, offset, size, and type from the assembly file
246 my $sinput = $_[0]; 279 my $sinput = $_[0];
247 my ($member, $offset, $size, $type, $arr); 280 my ($member, $offset, $size, $type, $arr);
248 281
@@ -255,7 +288,7 @@ sub Print_Variable {
255 $type = $+{type}; 288 $type = $+{type};
256 $arr = $+{arr}; 289 $arr = $+{arr};
257 290
258 if($type =~ /^(.*)${array_marker}$/) #strip array marker add [n] 291 if($type =~ /^(.*)${array_marker}$/) # strip array marker add [n]
259 { 292 {
260 $type = sprintf('%s[%d]', $1, $arr); 293 $type = sprintf('%s[%d]', $1, $arr);
261 } 294 }
@@ -266,7 +299,7 @@ sub Print_Variable {
266 return 0; 299 return 0;
267} 300}
268 301
269if($header) #output sections to lua file 302if($header) #output sections to lua file [PASS 2]
270{ 303{
271 print "-- Don't change this file!\n"; 304 print "-- Don't change this file!\n";
272 printf "-- It is automatically generated %s\n", $svnrev; 305 printf "-- It is automatically generated %s\n", $svnrev;
@@ -309,8 +342,8 @@ if($header) #output sections to lua file
309 exit; 342 exit;
310} 343}
311 344
312#else output sections to .c file 345#else output sections to .c file [PASS 1]
313my $header = join(", ", $helper_name, @sections); 346my $c_header = join(", ", $helper_name, @sections);
314my $print_variable = 'PRINT_M_O_S_T'; 347my $print_variable = 'PRINT_M_O_S_T';
315my $print_array = 'PRINT_ARRAY_M_O_S_T'; 348my $print_array = 'PRINT_ARRAY_M_O_S_T';
316my $emit_asm = 'ASM_EMIT_M_O_S_T'; 349my $emit_asm = 'ASM_EMIT_M_O_S_T';
@@ -335,6 +368,8 @@ print <<EOF
335("/* "#name ", " #member " = %0, %1, " #type ", %2; */\\n" : : \\ 368("/* "#name ", " #member " = %0, %1, " #type ", %2; */\\n" : : \\
336"n"(offset), "n"(size), "n"(elems)) 369"n"(offset), "n"(size), "n"(elems))
337 370
371/* constraint 'n' - An immediate integer operand with a known numeric value is allowed */
372
338#undef ${print_variable} 373#undef ${print_variable}
339#define ${print_variable}(name, member, value, type) ${emit_asm}(#name, \\ 374#define ${print_variable}(name, member, value, type) ${emit_asm}(#name, \\
340#member, #type, offsetof(name, member), sizeof(value), 0) 375#member, #type, offsetof(name, member), sizeof(value), 0)
@@ -348,7 +383,7 @@ int main(void)
348 383
349/* GAS supports C-style comments in asm files other compilers may not */ 384/* GAS supports C-style comments in asm files other compilers may not */
350/* This header identifies assembler output for second pass */ 385/* This header identifies assembler output for second pass */
351asm volatile("/* $header; */"); 386asm volatile("/* $c_header; */");
352 387
353EOF 388EOF
354; 389;
@@ -394,4 +429,3 @@ EOF
394 429
395#my ($user,$system,$cuser,$csystem) = times; 430#my ($user,$system,$cuser,$csystem) = times;
396#warn "Pass1 ".$user." ".$system." ".$cuser." ".$csystem."\n"; 431#warn "Pass1 ".$user." ".$system." ".$cuser." ".$csystem."\n";
397