------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Cheddar is a GNU GPL real-time scheduling analysis tool. -- This program provides services to automatically check schedulability and -- other performance criteria of real-time architecture models. -- -- Copyright (C) 2002-2016, Frank Singhoff, Alain Plantec, Jerome Legrand -- -- The Cheddar project was started in 2002 by -- Frank Singhoff, Lab-STICC UMR 6285 laboratory, Université de Bretagne Occidentale -- -- Cheddar has been published in the "Agence de Protection des Programmes/France" in 2008. -- Since 2008, Ellidiss technologies also contributes to the development of -- Cheddar and provides industrial support. -- -- The full list of contributors and sponsors can be found in AUTHORS.txt and SPONSORS.txt -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- -- -- Contact : cheddar@listes.univ-brest.fr -- ------------------------------------------------------------------------------ -- Last update : -- $Rev: 1249 $ -- $Date: 2014-08-28 07:02:15 +0200 (Fri, 28 Aug 2014) $ -- $Author: singhoff $ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Gtk.Menu_Item; use Gtk.Menu_Item; with Gtk; use Gtk; with Gtk.Main; use Gtk.Main; with Glib.Error; use Glib.Error; with Gtk.Widget; use Gtk.Widget; with Gtk.Dialog; use Gtk.Dialog; with Gtk.About_Dialog; use Gtk.About_Dialog; with Gtk.Label; use Gtk.Label; with Glib.Object; use Glib.Object; with Gtk.Text_Buffer; use Gtk.Text_Buffer; with Gtk.Combo_Box; use Gtk.Combo_Box; with Gtk.Text_Iter; use Gtk.Text_Iter; with Gtk.List_Store; use Gtk.List_Store; with Gtk.Tree_Model; use Gtk.Tree_Model; with Gtk.Tree_View; use Gtk.Tree_View; with Gtk.Tree_View_Column; use Gtk.Tree_View_Column; with Glib.Values; use Glib.Values; with Glib; use Glib; with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with unbounded_strings; use unbounded_strings; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Gtkada.Builder; use Gtkada.Builder; with graphical_editor.manual_callbacks; use graphical_editor.manual_callbacks; with graphical_editor.convert_text; use graphical_editor.convert_text; with caches; use caches; with caches; use caches.Cache_Blocks_Table_Package; with cache_set; use cache_set; with Cache_Block_Set; use Cache_Block_Set; with ada.exceptions; use ada.exceptions; with graphical_editor.generic_package_widget; use graphical_editor.generic_package_widget; with translate; use translate; with framework_config; use framework_config; with Debug; use Debug; with convert_unbounded_strings; package body graphical_editor.caches is -------------------------------- -- Everything must be in the right order: -- + Order of the widgets in my_tab -- + Order of the widgets in the glade file -- + Order of the fields in the tree view -- -------------------------------- cache_table_length : constant natural := 10; procedure Initialize_Cache(my_tab: in out table_widget_id ; Object : access Gtkada_Builder_Record'Class) is ob1: GObject:= Get_Object(Object, "textbuffer1"); ob2: GObject:= Get_Object(Object, "textbuffer2"); ob3: GObject:= Get_Object(Object, "textbuffer3"); ob4: GObject:= Get_Object(Object, "textbuffer4"); ob5: GObject:= Get_Object(Object, "combobox1"); ob6: GObject:= Get_Object(Object, "textbuffer6"); ob7: GObject:= Get_Object(Object, "combobox2"); ob8: GObject:= Get_Object(Object, "liststore3"); ob9: GObject:= Get_Object(Object, "treeview2"); wid1: t_widget := (ptype => buffer_string, buffer_value => Gtk_Text_Buffer(ob1)); wid2: t_widget := (ptype => buffer_integer, buffer_value => Gtk_Text_Buffer(ob2)); wid3: t_widget := (ptype => buffer_integer, buffer_value => Gtk_Text_Buffer(ob3)); wid4: t_widget := (ptype => buffer_integer, buffer_value => Gtk_Text_Buffer(ob4)); wid5: t_widget := (ptype => buffer_integer, buffer_value => Gtk_Text_Buffer(ob6)); wid6: t_widget := (ptype => combo, combo_value => Gtk_Combo_Box(ob5)); wid7: t_widget := (ptype => combo, combo_value => Gtk_Combo_Box(ob7)); wid8: t_widget := (ptype => lists, list_value => Gtk_List_Store(ob8)); wid9: t_widget := (ptype => view, view_value => Gtk_Tree_View(ob9)); wid10: t_widget := (ptype => my_window, window_value => cache_window); begin my_tab(1..cache_table_length) := (new t_widget'(wid1), new t_widget'(wid2), new t_widget'(wid3), new t_widget'(wid4), new t_widget'(wid5), new t_widget'(wid6), new t_widget'(wid7), new t_widget'(wid8), new t_widget'(wid9), new t_widget'(wid10)); end initialize_Cache; -- Data retrieved from the widgets -- cache_name : unbounded_string; cache_size : integer; cache_line_size : integer; cache_associativity : integer; block_reload_time : integer; cache_replacement_policy : Cache_Replacement_Policy_Type; cache_coherence_protocol : Cache_Coherence_Protocol_Type; procedure Check_Cache(my_tab: in out table_widget_id ; Object : access Gtkada_Builder_Record'Class) is cache_size_string, cache_line_size_string, cache_associativity_string, cache_hit_time_string, cache_miss_time_string : Unbounded_String; Integer_Ok : Boolean; begin cache_name := get_value_buffer_string(Gtk_Text_Buffer(my_tab(1).buffer_value)); cache_size_string:= suppress_space(get_value_buffer_string(Gtk_Text_Buffer(my_tab(2).buffer_value))); if (cache_size_string= "") then cache_size:= 0; else to_integer (cache_size_string, cache_size, Integer_Ok); if not Integer_Ok then Raise_Exception (cache_set.Invalid_Parameter'Identity, To_String ( "Cache size" & Lb_Must_Be_Numeric (Current_Language) )); end if; end if; cache_line_size_string:= suppress_space(get_value_buffer_string(Gtk_Text_Buffer(my_tab(3).buffer_value))); if (cache_line_size_string= "") then cache_line_size:= 0; else to_integer (cache_line_size_string, cache_line_size, Integer_Ok); if not Integer_Ok then Raise_Exception (cache_set.Invalid_Parameter'Identity, To_String ( "Cache line size" & Lb_Must_Be_Numeric (Current_Language) )); end if; end if; cache_associativity_string:= suppress_space(get_value_buffer_string(Gtk_Text_Buffer(my_tab(4).buffer_value))); if (cache_associativity_string= "") then cache_associativity:= 0; else to_integer (cache_associativity_string, cache_associativity, Integer_Ok); if not Integer_Ok then Raise_Exception (cache_set.Invalid_Parameter'Identity, To_String ( "Cache associativity" & Lb_Must_Be_Numeric (Current_Language) )); end if; end if; cache_miss_time_string:= suppress_space(get_value_buffer_string(Gtk_Text_Buffer(my_tab(5).buffer_value))); if (cache_miss_time_string= "") then block_reload_time:= 0; else to_integer (cache_miss_time_string, block_reload_time, Integer_Ok); if not Integer_Ok then Raise_Exception (cache_set.Invalid_Parameter'Identity, To_String ( "Cache miss time" & Lb_Must_Be_Numeric (Current_Language) )); end if; end if; cache_replacement_policy := to_type(to_unbounded_string(Get_Active_Text(Gtk_Combo_Box(my_tab(6).combo_value)))).cache_replacement_policy_value; cache_coherence_protocol := to_type(to_unbounded_string(Get_Active_Text(Gtk_Combo_Box(my_tab(7).combo_value)))).cache_coherence_protocol_value; Check_Cache(cache_name, cache_size, cache_line_size, cache_associativity, block_reload_time, cache_coherence_protocol, cache_replacement_policy, instruction_cache_type); end Check_cache; procedure Add_In_Sys_Cache(my_tab: in out table_widget_id ; Object : access Gtkada_Builder_Record'Class) is a_cache : Generic_Cache_Ptr; a_cache_blocks_table : Cache_Blocks_Table; a_cache_block : Cache_Block_Ptr; number_of_block : Natural; begin -- Cache Block is not support by the MMI at current release of Cheddar -- By default, cache blocks of a cache are automatically generated. number_of_block := cache_size/cache_line_size; for i in 0..number_of_block-1 loop a_cache_block := new Cache_Block; a_cache_block.name := suppress_space(To_String(cache_name & "_cb_" & i'Img)); a_cache_block.cache_block_number := Natural(i); Add(a_cache_blocks_table,a_cache_block); Add(sys.Cache_Blocks,a_cache_block); end loop; Add_Cache(sys.caches, a_cache, cache_name, cache_size, cache_line_size, cache_associativity, block_reload_time, cache_coherence_protocol, cache_replacement_policy, Instruction_Cache_Type, a_cache_blocks_table); end Add_In_Sys_Cache; procedure Deleted_In_Sys_Cache(my_tab: in out table_widget_id ; Object : access Gtkada_Builder_Record'Class) is A_cache : generic_cache_Ptr; name : unbounded_string; begin name := get_value_buffer_string(Gtk_Text_Buffer(my_tab(1).buffer_value)); A_Cache := Search_cache (sys.caches, name); Check_Entity_Referencing_a_cache(sys, a_cache); Delete (Sys.caches, A_cache); end Deleted_In_Sys_Cache; procedure Show_In_Sys_Cache(my_tab: in out table_widget_id ; Object : access Gtkada_Builder_Record'Class) is begin null; end Show_In_Sys_Cache; procedure Modify_In_Sys_Cache(my_tab: in out table_widget_id ; Object : access Gtkada_Builder_Record'Class) is A_cache_Buffer : generic_cache_ptr; A_cache : generic_cache_ptr; id : unbounded_string; begin A_cache := Search_cache (sys.caches, cache_name); id:=a_cache.cheddar_private_id; delete(sys.caches, a_cache); Add_Cache(sys.caches, a_cache_buffer, cache_name, cache_size, cache_line_size, cache_associativity, block_reload_time, cache_coherence_protocol, cache_replacement_policy, Instruction_Cache_Type); a_cache_buffer.cheddar_private_id:=id; end Modify_In_Sys_Cache; package cache_callbacks is new generic_callbacks(Number_of_widget => cache_table_length, Initialize => Initialize_Cache, Check => Check_Cache, Add_In_Sys => Add_In_Sys_Cache, Deleted_In_Sys => Deleted_In_Sys_Cache, Modify_In_Sys => Modify_In_Sys_Cache, Show_In_Sys => Show_In_Sys_Cache); use cache_callbacks; procedure Show_Cache_Widget is Builder : Gtkada_Builder; Error : Glib.Error.GError; tree_iter: Gtk_Tree_Iter; A_cache : generic_Cache_Ptr; My_Iterator : caches_Iterator; liststore: GObject; begin Gtk.Main.Init; Gtk_New (Builder); Error := Add_From_File (Builder, to_string(Glade_path) & "cache.glade"); if Error /= null then Ada.Text_IO.Put_Line ("Error : " & Get_Message (Error)); Error_Free (Error); return; end if; initialize(Sys_buffer); duplicate(sys, Sys_buffer); Set_Active (Gtk_Combo_Box(Get_Object(Builder, "combobox1")), 0); Set_Active (Gtk_Combo_Box(Get_Object(Builder, "combobox2")), 0); liststore:= Get_Object(Builder, "liststore3"); reset_iterator (sys.caches, My_Iterator); if not is_empty (sys.caches) then loop current_element (sys.caches, A_cache, My_Iterator); Append(Gtk_List_Store(liststore), tree_iter); Gtk.List_Store.Set(Gtk_List_Store(liststore), tree_iter, 0, To_String (A_cache.name)); Gtk.List_Store.Set(Gtk_List_Store(liststore), tree_iter, 1, Gint(A_cache.cache_size)); Gtk.List_Store.Set(Gtk_List_Store(liststore), tree_iter, 2, Gint(A_cache.line_size)); Gtk.List_Store.Set(Gtk_List_Store(liststore), tree_iter, 3, Gint(A_cache.associativity)); Gtk.List_Store.Set(Gtk_List_Store(liststore), tree_iter, 4, Gint(A_cache.block_reload_time)); Gtk.List_Store.Set(Gtk_List_Store(liststore), tree_iter, 5, To_String(to_label(new t_all_enumeration_type'(cache_replacement_policy_enum, a_cache.replacement_policy)))); Gtk.List_Store.Set(Gtk_List_Store(liststore), tree_iter, 6, To_String(to_label(new t_all_enumeration_type'(cache_coherence_protocol_enum, A_cache.coherence_protocol)))); exit when is_last_element (sys.caches, My_Iterator); next_element (sys.caches, My_Iterator); end loop; end if; Register_Handler (Builder => Builder, Handler_Name => "on_button6_clicked", Handler => cache_callbacks.Add_View'Access); Register_Handler (Builder => Builder, Handler_Name => "on_button5_clicked", Handler => cache_callbacks.Modify_Lign'Access); Register_Handler (Builder => Builder, Handler_Name => "on_treeview2_cursor_changed", Handler => cache_callbacks.Show_Lign_Selected'Access); Register_Handler (Builder => Builder, Handler_Name => "on_button4_clicked", Handler => cache_callbacks.Delected_Lign_Selected'Access); Register_Handler (Builder => Builder, Handler_Name => "on_button2_clicked", Handler => cache_callbacks.Cancel_View'Access); Register_Handler (Builder => Builder, Handler_Name => "on_button1_clicked", Handler => cache_callbacks.Close_View'Access); Do_Connect (Builder); Gtk.Widget.Show_All (Get_Widget (Builder, "window1")); Gtk.Main.Main; Unref (Builder); end Show_Cache_Widget; end graphical_editor.caches;