From 4030f025b21a9570f03137f5342b12aa2d200c4d Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Wed, 25 Mar 2020 18:43:13 +0100 Subject: synth: introduce value_to_string. --- src/synth/synth-expr.adb | 5 +---- src/synth/synth-values.adb | 10 ++++++++++ src/synth/synth-values.ads | 4 ++++ 3 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/synth') diff --git a/src/synth/synth-expr.adb b/src/synth/synth-expr.adb index 1a55372e5..6a3408844 100644 --- a/src/synth/synth-expr.adb +++ b/src/synth/synth-expr.adb @@ -1075,13 +1075,10 @@ package body Synth.Expr is end if; declare - Str : String (1 .. Natural (V.Arr.Len)); + Str : constant String := Value_To_String (V); Res_N : Node; Val : Int64; begin - for I in V.Arr.V'Range loop - Str (Natural (I)) := Character'Val (V.Arr.V (I).Scal); - end loop; case Get_Kind (Btype) is when Iir_Kind_Enumeration_Type_Definition => Res_N := Eval_Value_Attribute (Str, Etype, Attr); diff --git a/src/synth/synth-values.adb b/src/synth/synth-values.adb index 3d4459be3..f2a9d7033 100644 --- a/src/synth/synth-values.adb +++ b/src/synth/synth-values.adb @@ -943,6 +943,16 @@ package body Synth.Values is end case; end Create_Value_Default; + function Value_To_String (Val : Value_Acc) return String + is + Str : String (1 .. Natural (Val.Arr.Len)); + begin + for I in Val.Arr.V'Range loop + Str (Natural (I)) := Character'Val (Val.Arr.V (I).Scal); + end loop; + return Str; + end Value_To_String; + procedure Init is begin Instance_Pool := Global_Pool'Access; diff --git a/src/synth/synth-values.ads b/src/synth/synth-values.ads index 7c4ec8b7c..2bbf70810 100644 --- a/src/synth/synth-values.ads +++ b/src/synth/synth-values.ads @@ -357,6 +357,10 @@ package Synth.Values is -- Create a default initial value for TYP. function Create_Value_Default (Typ : Type_Acc) return Value_Acc; + -- Convert a value to a string. The value must be a const_array of scalar, + -- which represent characters. + function Value_To_String (Val : Value_Acc) return String; + procedure Init; -- Set by Init. -- cgit v1.2.3