@@ -83,7 +83,12 @@ def gen_cpp(symtab, indent = 0, indent_spaces: 2)
8383
8484 class UserTypeNameAst
8585 def gen_cpp ( symtab , indent = 0 , indent_spaces : 2 )
86- "#{ ' ' * indent } #{ text_value } "
86+ type = symtab . get ( text_value )
87+ if type . kind == :struct
88+ "#{ ' ' * indent } __UDB_STRUCT(#{ text_value } )"
89+ else
90+ "#{ ' ' * indent } #{ text_value } "
91+ end
8792 end
8893 end
8994
@@ -290,6 +295,12 @@ def gen_cpp(symtab, indent = 0, indent_spaces: 2)
290295 else
291296 "#{ ' ' * indent } __UDB_STATIC_PARAM(#{ text_value } ) /* #{ var . value } */"
292297 end
298+ elsif !var . nil? && var . type . global?
299+ if var . type . const?
300+ "#{ ' ' * indent } __UDB_CONST_GLOBAL(#{ text_value } )"
301+ else
302+ "#{ ' ' * indent } __UDB_MUTABLE_GLOBAL(#{ text_value } )"
303+ end
293304 else
294305 "#{ ' ' * indent } #{ text_value } "
295306 end
@@ -343,11 +354,19 @@ def gen_cpp(symtab, indent = 0, indent_spaces: 2)
343354 result = "#{ ' ' *indent } Bits<#{ bits_expression . gen_cpp ( symtab , 0 , indent_spaces :) } >"
344355 end
345356 value_else ( value_result ) do
346- result = "#{ ' ' *indent } Bits<BitsInfinitePrecision>"
357+ # see if this is a param with a bound
358+ if bits_expression . is_a? ( IdAst )
359+ sym = symtab . get ( bits_expression . text_value )
360+ if !sym . nil? && sym . param?
361+ param = symtab . cfg_arch . param ( bits_expression . text_value )
362+ result = "#{ ' ' *indent } Bits<#{ param . schema . max_val } >" if param . schema . max_val_known?
363+ end
364+ end
365+ result = "#{ ' ' *indent } Bits<BitsInfinitePrecision>" if result == ""
347366 end
348367 result
349368 elsif @type_name == "XReg"
350- "#{ ' ' *indent } Bits<#{ symtab . cfg_arch . possible_xlens . max ( ) } >"
369+ "#{ ' ' *indent } Bits<#{ symtab . cfg_arch . possible_xlens . max } >"
351370 elsif @type_name == "Boolean"
352371 "#{ ' ' *indent } bool"
353372 elsif @type_name == "U32"
@@ -507,20 +526,26 @@ def gen_cpp(symtab, indent = 0, indent_spaces: 2)
507526
508527 class FunctionCallExpressionAst
509528 def gen_cpp ( symtab , indent = 0 , indent_spaces : 2 )
510- targs_cpp = template_arg_nodes . map { |t | t . gen_cpp ( symtab , 0 , indent_spaces :) }
511- args_cpp = arg_nodes . map { |a | a . gen_cpp ( symtab , 0 , indent_spaces :) }
512- ftype = func_type ( symtab )
513- if ftype . func_def_ast . constexpr? ( symtab )
514- if targs_cpp . empty?
515- "__UDB_CONSTEXPR_FUNC_CALL #{ name . gsub ( "?" , "_Q_" ) } (#{ args_cpp . join ( ', ' ) } )"
516- else
517- "__UDB_CONSTEXPR_FUNC_CALL #{ name . gsub ( "?" , "_Q_" ) } <#{ targs_cpp . join ( ', ' ) } >(#{ args_cpp . join ( ', ' ) } )"
518- end
529+ if name == "ary_includes?"
530+ # special case
531+ args_cpp = arg_nodes . map { |a | a . gen_cpp ( symtab , 0 , indent_spaces :) }
532+ "(std::find(#{ args_cpp [ 0 ] } .begin(), #{ args_cpp [ 0 ] } .end(), #{ args_cpp [ 1 ] } ) != #{ args_cpp [ 0 ] } .end())"
519533 else
520- if targs_cpp . empty?
521- "__UDB_FUNC_CALL #{ name . gsub ( "?" , "_Q_" ) } (#{ args_cpp . join ( ', ' ) } )"
534+ targs_cpp = template_arg_nodes . map { |t | t . gen_cpp ( symtab , 0 , indent_spaces :) }
535+ args_cpp = arg_nodes . map { |a | a . gen_cpp ( symtab , 0 , indent_spaces :) }
536+ ftype = func_type ( symtab )
537+ if ftype . func_def_ast . constexpr? ( symtab )
538+ if targs_cpp . empty?
539+ "__UDB_CONSTEXPR_FUNC_CALL #{ name . gsub ( "?" , "_Q_" ) } (#{ args_cpp . join ( ', ' ) } )"
540+ else
541+ "__UDB_CONSTEXPR_FUNC_CALL #{ name . gsub ( "?" , "_Q_" ) } <#{ targs_cpp . join ( ', ' ) } >(#{ args_cpp . join ( ', ' ) } )"
542+ end
522543 else
523- "__UDB_FUNC_CALL #{ name . gsub ( "?" , "_Q_" ) } <#{ targs_cpp . join ( ', ' ) } >(#{ args_cpp . join ( ', ' ) } )"
544+ if targs_cpp . empty?
545+ "__UDB_FUNC_CALL #{ name . gsub ( "?" , "_Q_" ) } (#{ args_cpp . join ( ', ' ) } )"
546+ else
547+ "__UDB_FUNC_CALL #{ name . gsub ( "?" , "_Q_" ) } <#{ targs_cpp . join ( ', ' ) } >(#{ args_cpp . join ( ', ' ) } )"
548+ end
524549 end
525550 end
526551 end
0 commit comments