From: Guo H. <hon...@ro...> - 2006-01-11 07:59:48
|
Hi, Matt Harren First of all, thanks for your reply. Your suggestion is very useful for me. And I have translated some gcc extension options successfully using tic.ml. But I still do not know how to use foldLeftCompoundAll to add the fourth element of foo. Could you tell me more detailly. In linux kernel, the two initialzers are not equivalent. Most programmers use the final element to indicate the termination of array.So I suggest to let it be default. The following is an example from Linux-2.6 kernel: --------------------------------------------------------------------------------- /*from arch/i386/kernel/reboot.c*/ static struct dmi_system_id __initdata reboot_dmi_table[] = { 113 { /* Handle problems with rebooting on Dell 1300's */ 114 .callback = set_smp_bios_reboot, 115 .ident = "Dell PowerEdge 1300", 116 .matches = { 117 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), 118 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1300/"), 119 }, 120 }, 121 { /* Handle problems with rebooting on Dell 300's */ 122 .callback = set_bios_reboot, 123 .ident = "Dell PowerEdge 300", 124 .matches = { 125 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), 126 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 300/"), 127 }, 128 }, 129 { /* Handle problems with rebooting on Dell 2400's */ 130 .callback = set_bios_reboot, 131 .ident = "Dell PowerEdge 2400", 132 .matches = { 133 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), 134 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2400"), 135 }, 136 }, 137 { } 138 }; 139 140 static int __init reboot_init(void) 141 { 142 dmi_check_system(reboot_dmi_table); 143 return 0; 144 } --------------------------------------------------------------------------------- the function dmi_check_system(reboot_dmi_table) use the last element of reboot_dmi_table to indicate the final of reboot_dmi_table. Thanks a lot! Camelguo >Hi, > >A missing initializer for a global variable means that the compiler should >initialize that value to zero. So the two initializers are equivalent. > >If your analysis needs to see explictly that the fourth element of foo is >initialized to {0,0}, you can use foldLeftCompoundAll. > > >-- Matt > > > _____ > >From: cil...@li... >[mailto:cil...@li...] On Behalf Of hongruan >Sent: Monday, January 09, 2006 1:08 AM >To: Bug report for cil; cil-mail-list >Subject: [CIL users] Incorrect translation of static variable >initialisation > > >I try to compile the following code using CIL: >----------------test2.c start ---------------- >struct foo{ > unsigned long a; > unsigned long b; >}; > >static struct foo foos[]={ > {1,0}, > {2,0}, > {3,0}, > {}, >}; > >int >main(void) >{ > return 0; >} >----------------test2.c end ------------------ > >The commands I used are the following: >---------------------------------------------- >$gcc -E test2.c -o test2.i >$cilly.asm.exe --keepunused --out test2.cil.c test2.i >$gcc -c test2.cil.c -o test2.i >---------------------------------------------- > >But the context of the test2.cil.c is the following: >--------------test2.cil.c start--------------------- >/* Generated by CIL v. 1.3.4 */ >/* print_CIL_Input is true */ > >#line 1 "test2.c" >struct foo { > unsigned long a ; > unsigned long b ; >}; >#line 6 "test2.c" >static struct foo foos[3] = { {1UL, 0UL}, > {2UL, 0UL}, > {3UL, 0UL}}; >#line 13 "test2.c" >int main(void) >{ > > { >#line 16 > return (0); >} >} >--------------test2.cil.c end----------------------- > >BUT I think the result of struct foo foos[] should be translated into the >following: >---------------------------------------------------- >#line 6 "test2.c" >static struct foo foos[4] = { {1UL, 0UL}, > {2UL, 0UL}, > {3UL, 0UL} > {0UL, 0UL}}; >---------------------------------------------------- > >Maybe It is a bug about CIL. > >Thanks a lot! > >Camelguo > > |