Home | History | Annotate | Download | only in templates
      1 {{$clang_style := "{BasedOnStyle: Google, AccessModifierOffset: -4, ColumnLimit: 200, ContinuationIndentWidth: 8, IndentWidth: 4, AlignOperands: true, CommentPragmas: '.*'}"}}
      2 {{Global "clang-format" (Strings "clang-format" "-style" $clang_style)}}
      3 
      4 
      5 {{/*
      6 -------------------------------------------------------------------------------
      7   Emits the C translation for the specified type.
      8 -------------------------------------------------------------------------------
      9 */}}
     10 {{define "Type.Class"      }}{{if GetAnnotation $.Type "internal"}}struct {{end}}{{Macro "StructName" $.Type}}{{end}}
     11 {{define "Type.Pseudonym"  }}{{$.Type.Name}}{{end}}
     12 {{define "Type.Enum"       }}{{$.Type.Name}}{{end}}
     13 {{define "Type.StaticArray"}}{{Node "Type" $.Type.ValueType}}{{end}}
     14 {{define "Type.Pointer"    }}{{if $.Type.Const}}{{Node "ConstType" $.Type.To}}{{else}}{{Node "Type" $.Type.To}}{{end}}*{{end}}
     15 {{define "Type.Slice"      }}{{Log "%T %+v" $.Node $.Node}}{{Node "Type" $.Type.To}}*{{end}}
     16 {{define "Type#bool"       }}bool{{end}}
     17 {{define "Type#int"        }}int{{end}}
     18 {{define "Type#uint"       }}unsigned int{{end}}
     19 {{define "Type#s8"         }}int8_t{{end}}
     20 {{define "Type#u8"         }}uint8_t{{end}}
     21 {{define "Type#s16"        }}int16_t{{end}}
     22 {{define "Type#u16"        }}uint16_t{{end}}
     23 {{define "Type#s32"        }}int32_t{{end}}
     24 {{define "Type#u32"        }}uint32_t{{end}}
     25 {{define "Type#f32"        }}float{{end}}
     26 {{define "Type#s64"        }}int64_t{{end}}
     27 {{define "Type#u64"        }}uint64_t{{end}}
     28 {{define "Type#f64"        }}double{{end}}
     29 {{define "Type#void"       }}void{{end}}
     30 {{define "Type#char"       }}char{{end}}
     31 
     32 {{define "ConstType_Default"}}const {{Node "Type" $.Type}}{{end}}
     33 {{define "ConstType.Pointer"}}{{Node "Type" $.Type}} const{{end}}
     34 
     35 
     36 {{/*
     37 -------------------------------------------------------------------------------
     38   Emits the C translation for the specified documentation block (string array).
     39 -------------------------------------------------------------------------------
     40 */}}
     41 {{define "Docs"}}
     42   {{if $}}// {{$ | JoinWith "\n// "}}{{end}}
     43 {{end}}
     44 
     45 
     46 {{/*
     47 -------------------------------------------------------------------------------
     48   Emits the name of a bitfield entry.
     49 -------------------------------------------------------------------------------
     50 */}}
     51 {{define "BitfieldEntryName"}}
     52   {{AssertType $ "EnumEntry"}}
     53 
     54   {{Macro "EnumEntry" $}}
     55 {{end}}
     56 
     57 
     58 {{/*
     59 -------------------------------------------------------------------------------
     60   Emits the name of an enum type.
     61 -------------------------------------------------------------------------------
     62 */}}
     63 {{define "EnumName"}}{{AssertType $ "Enum"}}{{$.Name}}{{end}}
     64 
     65 
     66 {{/*
     67 -------------------------------------------------------------------------------
     68   Emits the name of an enum entry.
     69 -------------------------------------------------------------------------------
     70 */}}
     71 {{define "EnumEntry"}}
     72   {{AssertType $.Owner "Enum"}}
     73   {{AssertType $.Name "string"}}
     74 
     75   {{$.Name}}
     76 {{end}}
     77 
     78 
     79 {{/*
     80 -------------------------------------------------------------------------------
     81   Emits the name of the first entry of an enum.
     82 -------------------------------------------------------------------------------
     83 */}}
     84 {{define "EnumFirstEntry"}}
     85   {{AssertType $ "Enum"}}
     86 
     87   {{range $i, $e := $.Entries}}
     88     {{if not $i}}{{$e.Name}}{{end}}
     89   {{end}}
     90 {{end}}
     91 
     92 
     93 {{/*
     94 -------------------------------------------------------------------------------
     95   Emits the name of the last entry of an enum.
     96 -------------------------------------------------------------------------------
     97 */}}{{define "EnumLastEntry"}}
     98   {{AssertType $ "Enum"}}
     99 
    100   {{range $i, $e := $.Entries}}
    101     {{if not (HasMore $i $.Entries)}}{{$e.Name}}{{end}}
    102   {{end}}
    103 {{end}}
    104 
    105 
    106 {{/*
    107 -------------------------------------------------------------------------------
    108   Emits the name of a struct (class) type.
    109 -------------------------------------------------------------------------------
    110 */}}
    111 {{define "StructName"}}{{AssertType $ "Class"}}{{$.Name}}{{end}}
    112 
    113 
    114 {{/*
    115 -------------------------------------------------------------------------------
    116   Emits the name of a function.
    117 -------------------------------------------------------------------------------
    118 */}}
    119 {{define "FunctionName"}}{{AssertType $ "Function"}}{{$.Name}}{{end}}
    120 
    121 
    122 {{/*
    123 -------------------------------------------------------------------------------
    124   Emits the fixed-size-array postfix for pseudonym types annotated with @array
    125 -------------------------------------------------------------------------------
    126 */}}
    127 {{define "ArrayPostfix"}}{{Node "ArrayPostfix" $}}{{end}}
    128 {{define "ArrayPostfix.StaticArray"}}[{{$.Type.Size}}]{{end}}
    129 {{define "ArrayPostfix_Default"}}{{end}}
    130 
    131 
    132 {{/*
    133 -------------------------------------------------------------------------------
    134   Emits a C type and name for the given parameter
    135 -------------------------------------------------------------------------------
    136 */}}
    137 {{define "Parameter"}}
    138   {{AssertType $ "Parameter"}}
    139 
    140   {{if GetAnnotation $ "readonly"}}const {{end}}{{Macro "ParameterType" $}} {{$.Name}}{{Macro "ArrayPostfix" $}}
    141 {{end}}
    142 
    143 
    144 {{/*
    145 -------------------------------------------------------------------------------
    146   Emits a C name for the given parameter
    147 -------------------------------------------------------------------------------
    148 */}}
    149 {{define "ParameterName"}}
    150   {{AssertType $ "Parameter"}}
    151 
    152   {{$.Name}}
    153 {{end}}
    154 
    155 
    156 {{/*
    157 -------------------------------------------------------------------------------
    158   Emits a C type for the given parameter
    159 -------------------------------------------------------------------------------
    160 */}}
    161 {{define "ParameterType"}}{{AssertType $ "Parameter"}}{{Node "Type" $}}{{end}}
    162 
    163 
    164 {{/*
    165 -------------------------------------------------------------------------------
    166   Emits a comma-separated list of C type-name paired parameters for the given
    167   command.
    168 -------------------------------------------------------------------------------
    169 */}}
    170 {{define "Parameters"}}
    171   {{AssertType $ "Function"}}
    172 
    173   {{ForEach $.CallParameters "Parameter" | JoinWith ", "}}
    174   {{if not $.CallParameters}}void{{end}}
    175 {{end}}
    176 
    177 
    178 {{/*
    179 -------------------------------------------------------------------------------
    180   Emits the C function pointer name for the specified command.
    181 -------------------------------------------------------------------------------
    182 */}}
    183 {{define "FunctionPtrName"}}
    184   {{AssertType $ "Function"}}
    185 
    186   PFN_{{$.Name}}
    187 {{end}}
    188 
    189 
    190 {{/*
    191 -------------------------------------------------------------------------------
    192   Parses const variables as text Globals.
    193 -------------------------------------------------------------------------------
    194 */}}
    195 {{define "DefineGlobals"}}
    196   {{AssertType $ "API"}}
    197 
    198   {{range $d := $.Definitions}}
    199     {{Global $d.Name $d.Expression}}
    200   {{end}}
    201 {{end}}
    202 
    203 
    204 {{/*
    205 -------------------------------------------------------------------------------
    206   Given a function, return "Global", "Instance", or "Device" depending on which
    207   dispatch table the function belongs to.
    208 -------------------------------------------------------------------------------
    209 */}}
    210 {{define "Vtbl#VkInstance"      }}Instance{{end}}
    211 {{define "Vtbl#VkPhysicalDevice"}}Instance{{end}}
    212 {{define "Vtbl#VkDevice"        }}Device{{end}}
    213 {{define "Vtbl#VkQueue"         }}Device{{end}}
    214 {{define "Vtbl#VkCommandBuffer" }}Device{{end}}
    215 {{define "Vtbl_Default"         }}Global{{end}}
    216 {{define "Vtbl"}}
    217   {{AssertType $ "Function"}}
    218 
    219   {{if gt (len $.CallParameters) 0}}
    220     {{Node "Vtbl" (index $.CallParameters 0)}}
    221   {{else}}Global
    222   {{end}}
    223 {{end}}
    224