• Matthew Dempsky's avatar
    bpf_dsl: support Switch/Case expressions · 279b9aad
    Matthew Dempsky authored
    This adds support for expressions like
    
        Switch(arg)
          .Case(1, result1)
          .CASES((2, 3), result2)
          .Default(result3)
    
    Currently these expressions are compiled simply as short-hand for
    
        If(arg == 1, result1)
          .ElseIf(arg == 2 || arg == 3, result2)
          .Else(result3)
    
    but in the future we should be able to optimize it better.
    
    The CASES macro ugliness is unfortunately necessary until we're
    allowed to use C++11.  Later we'll be able to change it to
    real C++ code like "Cases({2, 3}, result2)" (which clang-format
    will then format a bit more nicely too).
    
    BUG=408845
    R=jln@chromium.org, jorgelo@chromium.org
    
    Review URL: https://codereview.chromium.org/438683004
    
    Cr-Commit-Position: refs/heads/master@{#293599}
    279b9aad
bpf_dsl.h 12.1 KB