[LLVMdev] tblgen bug in handling case , switch_on

Sanjiv Gupta sanjiv.gupta at microchip.com
Wed Sep 9 22:26:03 PDT 2009


Sanjiv Gupta wrote:
> Mikhail Glushenkov wrote:
>   
>> Hi Sanjiv,
>>
>> On Sun, Sep 6, 2009 at 8:13 PM, Mikhail
>> Glushenkov<the.dead.shall.rise at gmail.com> wrote:
>>   
>>     
>>> Hi Sanjiv,
>>>
>>> On Sun, Sep 6, 2009 at 8:07 PM, Mikhail
>>> Glushenkov<the.dead.shall.rise at gmail.com> wrote:
>>>     
>>>       
>>>> [...]
>>>>       
>>>>         
>>> [Sorry, the formatting was a bit off]
>>>
>>>     
>>>       
>>>> The following snippet gives the expected behaviour (not tested, but
>>>> you should get the idea):
>>>>       
>>>>         
>> BTW, your mail has got me thinking about the semantics of 'case',
>> which is currently somewhat ambiguous (since it depends on context).
>> Probably 'case' should be modified to always mean 'if ... else if ...
>> else if ... [...] else ...' and the 'if (...) ... if (...) ... if
>> (...) ... [...]' form should be called something like 'match'. That
>> would be backwards-incompatible, though.
>>
>> What do you think?
>>
>>   
>>     
> Another way would be to include a "break" command, to take you after the 
> default label.
> - Sanjiv
>   
Sow we can write:

  case ( (switch_on "O0") [(append_cmd "-blah0"), (break)],
             (switch_on "O1")[(append_cmd "-blah1"), (break)],
             (switch_on "O2")[(append_cmd "-blah2"), (break)],
             (default) (append_cmd "-blah2"))

            
        
This would require generation of an unique label after each case 
construct, and a   goto uniquelabel;  in each if ( ) {...}
The other way is:
  if (first_test) {
    ....
    stop_case = true;
  }

  if (!stop_case && second_test) {
    ...
    stop_case = true;
  }

  if (!stop_case && third_test) {
    ...
  }  else {
    // default case
    ...
  }
  stop_case = false;

Also, it would be nice to have some "general predicates" to do some 
cleaning up of the command line.
For example: if an user specifies all -O0, -O1, -O2 on the command line, 
one would be able to choose only the first or last, or give an error.

option_validator ("O0", "O1", "O2"), (choose_first)
OR
option_validator ("O0", "O1", "O2"), (choose_last)
OR
option_validator ("O0", "O1", "O2"), (error "Only one of -O0, -O1, or 
-O2 are allowed).


> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>   




More information about the llvm-dev mailing list