[Cbe-oss-dev] [PATCH] libspe2: Ada bindings

Sa Liu SALIU at de.ibm.com
Sat Jun 30 01:12:21 EST 2007


This patch adds Ada bindings for libspe2. 
It includes three Ada package files cbea_map.ads, libspe2.ads and 
libspe2_types.ads, which map the corresponding header files in libspe2. 
In addition, the test program testsingle.adb demonstrates sample usage of 
the package file. The script single.sh is used to build the sample.

Signed-off-by: Sa Liu <saliu at de.ibm.com>

===================================================================
diff -uprN libspe.orig/libspe2/ada/cbea_map.ads 
libspe/libspe2/ada/cbea_map.ads
--- libspe.orig/libspe2/ada/cbea_map.ads        1970-01-01 
01:00:00.000000000 +0100
+++ libspe/libspe2/ada/cbea_map.ads     2007-06-29 16:07:53.000000000 
+0200
@@ -0,0 +1,70 @@
+--
+-- Data structure declarations for SPE problem state areas
+-- (part of public API)
+--
+with System;
+with Interfaces.C;
+
+package cbea_map is
+  use System;
+  use Interfaces.C;
+
+type spe_mssync_area_t is
+  record
+    MFC_MSSync         : unsigned;
+  end record;
+type spe_mssync_area_ptr is access spe_mssync_area_t;
+
+type spe_mfc_command_area_t is
+  record
+    reserved_0_3       : char_array (0 .. 3);
+    MFC_LSA            : unsigned; 
+    MFC_EAH            : unsigned; 
+    MFC_EAL            : unsigned; 
+    MFC_Size_Tag       : unsigned; 
+    MFC_ClassID_CMD    : unsigned;
+--  MFC_CMDStatus      : unsigned;
+    reserved_18_103    : char_array (0 .. 235);
+    MFC_QStatus                : unsigned;
+    reserved_108_203   : char_array (0 .. 251);
+    Prxy_QueryType     : unsigned;
+    reserved_208_21B   : char_array (0 .. 19);
+    Prxy_QueryMask     : unsigned;
+    reserved_220_22B   : char_array (0 .. 11);
+    Prxy_TagStatus     : unsigned;
+  end record;
+type spe_mfc_command_area_ptr is access spe_mfc_command_area_t;
+
+type spe_spu_control_area_t is
+  record
+    reserved_0_3       : char_array (0 .. 3);
+    SPU_Out_Mbox       : unsigned; 
+    reserved_8_B       : char_array (0 .. 3);
+    SPU_In_Mbox                : unsigned; 
+    reserved_10_13     : char_array (0 .. 3);
+    SPU_Mbox_Stat      : unsigned; 
+    reserved_18_1B     : char_array (0 .. 3);
+    SPU_RunCntl                : unsigned; 
+    reserved_20_23     : char_array (0 .. 3);
+    SPU_Status         : unsigned; 
+    reserved_28_33     : char_array (0 .. 11);
+    SPU_NPC            : unsigned; 
+  end record;
+type spe_spu_control_area_ptr is access spe_spu_control_area_t;
+
+type spe_sig_notify_1_area_t is
+  record
+    reserved_0_B       : char_array (0 .. 11);
+    SPU_Sig_Notify_1   : unsigned; 
+  end record;
+type spe_sig_notify_1_area_ptr is access spe_sig_notify_1_area_t;
+
+type spe_sig_notify_2_area_t is
+  record
+    reserved_0_B       : char_array (0 .. 11);
+    SPU_Sig_Notify_2   : unsigned; 
+  end record;
+type spe_sig_notify_2_area_ptr is access spe_sig_notify_2_area_t;
+
+end cbea_map;
+
diff -uprN libspe.orig/libspe2/ada/helloworld.c 
libspe/libspe2/ada/helloworld.c
--- libspe.orig/libspe2/ada/helloworld.c        1970-01-01 
01:00:00.000000000 +0100
+++ libspe/libspe2/ada/helloworld.c     2007-06-29 17:14:15.000000000 
+0200
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+main()
+{
+       printf("Spu says hello!\n");
+       return 42;
+}
diff -uprN libspe.orig/libspe2/ada/libspe2.ads 
libspe/libspe2/ada/libspe2.ads
--- libspe.orig/libspe2/ada/libspe2.ads 1970-01-01 01:00:00.000000000 
+0100
+++ libspe/libspe2/ada/libspe2.ads      2007-06-29 16:07:53.000000000 
+0200
@@ -0,0 +1,341 @@
+-----------------------------------------------------------
+-- 
+-- libspe2 API functions
+-- 
+-----------------------------------------------------------
+with System;
+with Interfaces.C;
+with libspe2_types;
+
+package libspe2 is
+  use System;
+  use Interfaces.C;
+  use libspe2_types;
+
+
+--
+-- spe_context_create
+--
+  function spe_context_create
+    (flags     : unsigned;
+     gang      : spe_gang_context_ptr_t) 
+  return spe_context_ptr_t;
+  pragma Import (C, spe_context_create, "spe_context_create");
+
+--
+-- spe_context_create_affinity
+--
+  function spe_context_create_affinity
+    (flags             : unsigned;
+     affinity_neighbor : spe_context_ptr_t;
+     gang              : spe_gang_context_ptr_t) 
+  return spe_context_ptr_t;
+  pragma Import (C, spe_context_create_affinity, 
"spe_context_create_affinity");
+
+--
+-- spe_context_destroy
+--
+  function spe_context_destroy
+    (spe  : spe_context_ptr_t)
+  return Integer;
+  pragma Import (C, spe_context_destroy, "spe_context_destroy");
+
+--
+-- spe_gang_context_create
+--
+  function spe_gang_context_create
+    (flags     : unsigned)
+  return spe_gang_context_ptr_t;
+  pragma Import (C, spe_gang_context_create, "spe_gang_context_create");
+
+--
+-- spe_gang_context_destroy
+--
+  function spe_gang_context_destroy
+    (gang  : spe_gang_context_ptr_t)
+  return Integer;
+  pragma Import (C, spe_gang_context_destroy, 
"spe_gang_context_destroy");
+
+--
+-- spe_image_open
+--
+  function spe_image_open
+    (filename  : char_array)
+    return spe_program_handle_t;
+  pragma Import (C, spe_image_open, "spe_image_open");
+
+--
+-- spe_image_close
+--
+  function spe_image_close
+    (program  : spe_program_handle_t)
+    return Integer;
+  pragma Import (C, spe_image_close, "spe_image_close");
+
+--
+-- spe_program_load
+--
+  function spe_program_load
+    (spe        : spe_context_ptr_t;
+     program    : spe_program_handle_t)
+  return Integer;
+  pragma Import (C, spe_program_load, "spe_program_load");
+
+--
+-- spe_context_run
+--
+  function spe_context_run
+    (spe                : spe_context_ptr_t;
+     spe_entry_ptr             : access unsigned;
+     run_flags          : unsigned;
+     argp               : addr_ptr;
+     envp               : addr_ptr;
+     stop_info         : spe_stop_info_ptr)
+  return Integer;
+  pragma Import (C, spe_context_run, "spe_context_run");
+
+--
+-- spe_stop_info_read
+--
+  function spe_stop_info_read
+    (spe         : spe_context_ptr_t;
+     stop_info    : spe_stop_info_ptr)
+  return Integer;
+  pragma Import (C, spe_stop_info_read, "spe_stop_info_read");
+
+--
+-- spe_event_handler_create
+--
+  function spe_event_handler_create 
+  return spe_event_handler_ptr_t;
+  pragma Import (C, spe_event_handler_create, 
"spe_event_handler_create");
+
+--
+-- spe_event_handler_destroy
+--
+  function spe_event_handler_destroy 
+    (evhandler :spe_event_handler_ptr_t)
+  return Integer;
+  pragma Import (C, spe_event_handler_destroy, 
"spe_event_handler_destroy");
+
+--
+-- spe_event_handler_register
+--
+  function spe_event_handler_register 
+    (evhandler : spe_event_handler_ptr_t;
+     event     : spe_event_unit_t_ptr)
+  return Integer;
+  pragma Import (C, spe_event_handler_register, 
"spe_event_handler_register");
+
+--
+-- spe_event_handler_deregister
+--
+  function spe_event_handler_deregister 
+    (evhandler : spe_event_handler_ptr_t;
+     event     : spe_event_unit_t_ptr)
+  return Integer;
+  pragma Import (C, spe_event_handler_deregister, 
"spe_event_handler_deregister");
+
+--
+-- spe_event_wait
+--
+  function spe_event_wait 
+    (evhandler : spe_event_handler_ptr_t;
+     events    : addr_ptr;
+     max_events        : Integer;
+     timeout   : Integer)
+  return Integer;
+  pragma Import (C, spe_event_wait, "spe_event_wait");
+
+--
+-- MFCIO Proxy Commands
+--
+  function spe_mfcio_put
+    (spe       : spe_context_ptr_t;
+     ls                : unsigned;
+     ea        : addr_ptr;
+     size      : unsigned;
+     tag       : unsigned;
+     tid       : unsigned;
+     rid       : unsigned)
+  return Integer;
+  pragma Import (C, spe_mfcio_put, "spe_mfcio_put");
+
+  function spe_mfcio_putb
+    (spe       : spe_context_ptr_t;
+     ls                : unsigned;
+     ea        : addr_ptr;
+     size      : unsigned;
+     tag       : unsigned;
+     tid       : unsigned;
+     rid       : unsigned)
+  return Integer;
+  pragma Import (C, spe_mfcio_putb, "spe_mfcio_putb");
+
+  function spe_mfcio_putf
+    (spe       : spe_context_ptr_t;
+     ls                : unsigned;
+     ea        : addr_ptr;
+     size      : unsigned;
+     tag       : unsigned;
+     tid       : unsigned;
+     rid       : unsigned)
+  return Integer;
+  pragma Import (C, spe_mfcio_putf, "spe_mfcio_putf");
+
+  function spe_mfcio_get
+    (spe       : spe_context_ptr_t;
+     ls                : unsigned;
+     ea        : addr_ptr;
+     size      : unsigned;
+     tag       : unsigned;
+     tid       : unsigned;
+     rid       : unsigned)
+  return Integer;
+  pragma Import (C, spe_mfcio_get, "spe_mfcio_get");
+
+  function spe_mfcio_getb
+    (spe       : spe_context_ptr_t;
+     ls                : unsigned;
+     ea        : addr_ptr;
+     size      : unsigned;
+     tag       : unsigned;
+     tid       : unsigned;
+     rid       : unsigned)
+  return Integer;
+  pragma Import (C, spe_mfcio_getb, "spe_mfcio_getb");
+
+  function spe_mfcio_getf
+    (spe       : spe_context_ptr_t;
+     ls                : unsigned;
+     ea        : addr_ptr;
+     size      : unsigned;
+     tag       : unsigned;
+     tid       : unsigned;
+     rid       : unsigned)
+  return Integer;
+  pragma Import (C, spe_mfcio_getf, "spe_mfcio_getf");
+
+--
+-- MFCIO Tag Group Completion
+--
+  function spe_mfcio_tag_status_read
+    (spe               : spe_context_ptr_t;
+     mask              : unsigned;
+     behavior          : unsigned;
+     tag_status_ptr    : unsigned_ptr)
+  return Integer;
+  pragma Import (C, spe_mfcio_tag_status_read, 
"spe_mfcio_tag_status_read");
+
+--
+-- SPE Mailbox Facility
+--
+  function spe_out_mbox_read
+    (spe               : spe_context_ptr_t;
+     mbox_data_ptr     : unsigned_ptr;
+     count             : Integer)
+  return Integer;
+  pragma Import (C, spe_out_mbox_read, "spe_out_mbox_read");
+
+  function spe_out_mbox_status
+    (spe               : spe_context_ptr_t)
+  return Integer;
+  pragma Import (C, spe_out_mbox_status, "spe_out_mbox_status");
+
+  function spe_in_mbox_write
+    (spe               : spe_context_ptr_t;
+     mbox_data_ptr     : unsigned_ptr;
+     count             : Integer;
+     behavior          : unsigned)
+  return Integer;
+  pragma Import (C, spe_in_mbox_write, "spe_in_mbox_write");
+
+  function spe_in_mbox_status
+    (spe               : spe_context_ptr_t)
+  return Integer;
+  pragma Import (C, spe_in_mbox_status, "spe_in_mbox_status");
+
+  function spe_out_intr_mbox_read
+    (spe               : spe_context_ptr_t;
+     mbox_data_ptr     : unsigned_ptr;
+     count             : Integer;
+     behavior          : unsigned)
+  return Integer;
+  pragma Import (C, spe_out_intr_mbox_read, "spe_out_intr_mbox_read");
+
+  function spe_out_intr_mbox_status
+    (spe               : spe_context_ptr_t)
+  return Integer;
+  pragma Import (C, spe_out_intr_mbox_status, 
"spe_out_intr_mbox_status");
+
+--
+-- SPU SIgnal Notification Facility
+--
+  function spe_signal_write
+    (spe               : spe_context_ptr_t;
+     signal_reg                : unsigned;
+     data              : unsigned)
+  return Integer;
+  pragma Import (C, spe_signal_write, "spe_signal_write");
+
+--
+-- spe_ls_area_get
+--
+  function spe_ls_area_get
+    (spe               : spe_context_ptr_t)
+  return addr_ptr;
+  pragma Import (C, spe_ls_area_get, "spe_ls_area_get");
+
+--
+-- spe_ls_size_get
+--
+  function spe_ls_size_get
+    (spe               : spe_context_ptr_t)
+  return Integer;
+  pragma Import (C, spe_ls_size_get, "spe_ls_size_get");
+
+--
+-- spe_ps_area_get
+--
+  function spe_ps_area_get
+    (spe               : spe_context_ptr_t;
+     area              : ps_area)
+  return addr_ptr;
+  pragma Import (C, spe_ps_area_get, "spe_ps_area_get");
+
+--
+-- spe_callback_handler_register
+--
+  function spe_callback_handler_register
+    (handler           : addr_ptr;
+     callnum           : unsigned;
+     mode              : unsigned)
+  return Integer;
+  pragma Import (C, spe_callback_handler_register, 
"spe_callback_handler_register");
+
+--
+-- spe_callback_handler_deregister
+--
+  function spe_callback_handler_deregister
+    (callnum           : unsigned)
+  return Integer;
+  pragma Import (C, spe_callback_handler_deregister, 
"spe_callback_handler_deregister");
+
+--
+-- spe_callback_handler_query
+--
+  function spe_callback_handler_query
+    (callnum           : unsigned)
+  return spe_event_handler_ptr_t;
+  pragma Import (C, spe_callback_handler_query, 
"spe_callback_handler_query");
+
+--
+-- spe_cpu_info_get
+--
+  function spe_cpu_info_get
+    (info_requested    : Integer;
+     cpu_node          : Integer)
+  return Integer;
+  pragma Import (C, spe_cpu_info_get, "spe_cpu_info_get");
+
+end libspe2;
diff -uprN libspe.orig/libspe2/ada/libspe2_types.ads 
libspe/libspe2/ada/libspe2_types.ads
--- libspe.orig/libspe2/ada/libspe2_types.ads   1970-01-01 
01:00:00.000000000 +0100
+++ libspe/libspe2/ada/libspe2_types.ads        2007-06-29 
16:07:53.000000000 +0200
@@ -0,0 +1,210 @@
+--
+-- Definition of data types and constants
+--
+with System;
+with Interfaces.C;
+
+package libspe2_types is
+  use System;
+  use Interfaces.C;
+
+type addr_ptr is access Address;
+type int_ptr is access Integer;
+type unsigned_ptr is access unsigned;
+
+-- SPE program handle
+-- Structure spe_program_handle per CESOF specification
+-- libspe2 applications usually only keep a pointer
+-- to the program handle and do not use the structure
+-- directly.
+type spe_program_handle is
+  record
+    handle_size                : unsigned;
+    elf_image_ptr      : addr_ptr;
+    toe_shadow_ptr     : addr_ptr;
+  end record;
+type spe_program_handle_t is access spe_program_handle;
+
+-- SPE context
+-- The SPE context is one of the base data structures for
+-- the libspe2 implementation. It holds all persistent information
+-- about a "logical SPE" used by the application. This data
+-- structure should not be accessed directly, but the application
+-- uses a pointer to an SPE context as an identifier for the
+-- "logical SPE" it is dealing with through libspe2 API calls.
+type spe_context is
+  record
+    handle             : spe_program_handle;
+    base_private       : addr_ptr;
+    event_private      : addr_ptr;
+  end record;
+type spe_context_ptr_t is access spe_context;
+
+-- SPE gang context
+-- The SPE gang context is one of the base data structures for
+-- the libspe2 implementation. It holds all persistent information
+-- about a group of SPE contexts that should be treated as a gang,
+-- i.e., be execute together with certain properties. This data
+-- structure should not be accessed directly, but the application
+-- uses a pointer to an SPE gang context as an identifier for the
+-- SPE gang it is dealing with through libspe2 API calls.
+type spe_gang_context is
+  record
+    base_private       : addr_ptr;
+    event_private      : addr_ptr;
+  end record; 
+type spe_gang_context_ptr_t is access spe_gang_context;
+
+type index is range 1 .. 8;
+
+type spe_stop_info (reason: index := 1) is
+  record
+   spu_status  : Integer;
+   reserved    : Integer;
+   case reason is
+    when 1     =>      spe_exit_code           : Integer;
+    when 2     =>      spe_signal_code         : Integer;
+    when 3     =>      spe_runtime_error       : Integer;
+    when 4     =>      spe_runtime_exception   : Integer;
+    when 5     =>      spe_runtime_fatal       : Integer;
+    when 6     =>      spe_callback_error      : Integer;
+    when 7     =>      reserved_ptr            : addr_ptr;
+    when 8     =>      reserved_u64            : unsigned_long;
+   end case;
+  end record;
+
+for spe_stop_info use 
+  record
+   reason                      at 0 range 0 .. 31;
+   reserved                    at 4 range 0 .. 31;-- only for 8 bytes 
alignment
+   spe_exit_code               at 8 range 0 .. 31;
+   spe_signal_code             at 8 range 0 .. 31; 
+   spe_runtime_error           at 8 range 0 .. 31;
+   spe_runtime_exception       at 8 range 0 .. 31;
+   spe_runtime_fatal           at 8 range 0 .. 31;
+   spe_callback_error          at 8 range 0 .. 31;
+   reserved_ptr                        at 8 range 0 .. 63; 
+   reserved_u64                        at 8 range 0 .. 63; 
+   spu_status                  at 16 range 0 .. 31;
+  end record;
+
+for spe_stop_info'size use 5*32;
+
+type spe_stop_info_ptr is access spe_stop_info;
+
+type spe_event_handler_t is new Integer;
+type spe_event_handler_ptr_t is new addr_ptr;
+
+
+type spe_event_data_t is
+  record
+       ptr             : addr_ptr;
+-- FIXME: union without discriminant
+--     u32             : unsigned;
+--     u64             : unsigned_long;
+  end record;
+for spe_event_data_t'Size use 64;
+
+type spe_event_unit_t is
+  record
+    events     : unsigned;
+    spe                : spe_context_ptr_t;
+    data       : spe_event_data_t; 
+  end record;
+type spe_event_unit_t_ptr is access spe_event_unit_t;
+
+--
+--  API symbolic constants
+--
+type ps_area is (SPE_MSSYNC_AREA, SPE_MFC_COMMAND_AREA, SPE_CONTROL_AREA,
+                SPE_SIG_NOTIFY_1_AREA, SPE_SIG_NOTIFY_2_AREA);
+
+--
+-- Flags for spe_context_create
+--
+ SPE_CFG_SIGNOTIFY1_OR : constant unsigned := 16#00000010#;
+ SPE_CFG_SIGNOTIFY2_OR : constant unsigned := 16#00000020#;
+ SPE_MAP_PS            : constant unsigned := 16#00000040#;
+ SPE_ISOLATE           : constant unsigned := 16#00000080#;
+ SPE_EVENTS_ENABLE     : constant unsigned := 16#00001000#;
+ SPE_AFFINITY_MEMORY   : constant unsigned := 16#00002000#;
+
+--
+-- Symbolic constants for stop reasons
+-- as returned in spe_stop_info_t
+ SPE_EXIT              : constant Integer := 1;
+ SPE_STOP_AND_SIGNAL   : constant Integer := 2;
+ SPE_RUNTIME_ERROR     : constant Integer := 3;
+ SPE_RUNTIME_EXCEPTION : constant Integer := 4;
+ SPE_RUNTIME_FATAL     : constant Integer := 5;
+ SPE_CALLBACK_ERROR    : constant Integer := 6;
+
+--
+-- Runtime errors
+--
+ SPE_SPU_STOPPED_BY_STOP       : constant unsigned := 16#02#;-- INTERNAL 
USE ONLY
+ SPE_SPU_HALT                  : constant unsigned := 16#04#;
+ SPE_SPU_WAITING_ON_CHANNEL    : constant unsigned := 16#08#;-- INTERNAL 
USE ONLY
+ SPE_SPU_SINGLE_STEP           : constant unsigned := 16#10#;
+ SPE_SPU_INVALID_INSTR         : constant unsigned := 16#20#;
+ SPE_SPU_INVALID_CHANNEL       : constant unsigned := 16#40#;
+
+--
+-- Runtime exceptions
+--
+ SPE_DMA_ALIGNMENT     : constant unsigned := 16#0008#;
+ SPE_DMA_SEGMENTATION  : constant unsigned := 16#0020#;
+ SPE_DMA_STORAGE       : constant unsigned := 16#0040#;
+
+-- 
+-- Supported SPE events
+--
+ SPE_EVENT_OUT_INTR_MBOX: constant unsigned := 16#00000001#;
+ SPE_EVENT_IN_MBOX     : constant unsigned := 16#00000002#;
+ SPE_EVENT_TAG_GROUP   : constant unsigned := 16#00000004#;
+ SPE_EVENT_SPE_STOPPED : constant unsigned := 16#00000008#;
+ SPE_EVENT_ALL_EVENTS   : constant unsigned := 16#0000000F#; 
+
+--
+-- Behavior flags for mailbox read/write functions
+--
+ SPE_MBOX_ALL_BLOCKING         : constant unsigned := 1;
+ SPE_MBOX_ANY_BLOCKING         : constant unsigned := 2;  
+ SPE_MBOX_ANY_NONBLOCKING      : constant unsigned := 3; 
+
+--
+-- Behavior flags tag status functions
+--
+ SPE_TAG_ALL           : constant unsigned := 1;
+ SPE_TAG_ANY           : constant unsigned := 2; 
+ SPE_TAG_IMMEDIATE     : constant unsigned := 3; 
+
+--
+-- Flags for _base_spe_context_run
+--
+ SPE_DEFAULT_ENTRY     : constant unsigned := 2**int'Size-1;-- UINT_MAX 
on spe
+-- 128b user data for r3-5. --
+ SPE_RUN_USER_REGS      : constant Integer := 16#00000001#;
+ SPE_NO_CALLBACKS      : constant Integer := 16#00000002#;
+
+--
+--
+--
+ SPE_CALLBACK_NEW      : constant unsigned := 1;
+ SPE_CALLBACK_UPDATE   : constant unsigned := 2;
+
+--
+-- 
+--
+ SPE_COUNT_PHYSICAL_CPU_NODES  : constant Integer := 1;
+ SPE_COUNT_PHYSICAL_SPES       : constant Integer := 2; 
+ SPE_COUNT_USABLE_SPES         : constant Integer := 3; 
+
+--
+-- Signal Targets
+--
+ SPE_SIG_NOTIFY_REG_1  : constant unsigned := 1;
+ SPE_SIG_NOTIFY_REG_2   : constant unsigned := 2;
+
+end libspe2_types;
+
diff -uprN libspe.orig/libspe2/ada/single.sh libspe/libspe2/ada/single.sh
--- libspe.orig/libspe2/ada/single.sh   1970-01-01 01:00:00.000000000 
+0100
+++ libspe/libspe2/ada/single.sh        2007-06-29 17:13:49.000000000 
+0200
@@ -0,0 +1,3 @@
+spu-gcc helloworld.c -o hello
+ppu-gcc -c libspe2.ads libspe2_types.ads
+ppu-gnatmake testsingle.adb -o testsingle -largs -lspe2
diff -uprN libspe.orig/libspe2/ada/testsingle.adb 
libspe/libspe2/ada/testsingle.adb
--- libspe.orig/libspe2/ada/testsingle.adb      1970-01-01 
01:00:00.000000000 +0100
+++ libspe/libspe2/ada/testsingle.adb   2007-06-29 17:13:34.000000000 
+0200
@@ -0,0 +1,74 @@
+ -- 
+ -- test functions: 
+ --    spe_context_create 
+ --    spe_image_open
+ --    spe_program_load
+ --    spe_context_run
+ --    spe_context_destroy
+ --    spe_image_close
+ -- 
+with System;
+with Ada.Text_IO;
+with Interfaces.C;
+with libspe2;
+with libspe2_types;
+
+procedure testsingle is
+  use System;
+  use Ada.Text_IO;
+  use Interfaces.C;
+  use libspe2;
+  use libspe2_types;
+
+  ctx : spe_context_ptr_t;
+  flags : unsigned := 0;
+  gang : spe_gang_context_ptr_t;
+  program : spe_program_handle_t;
+  argp : addr_ptr := Null;
+  envp : addr_ptr := Null;
+  rc : Integer;
+
+  spe_entry : unsigned := SPE_DEFAULT_ENTRY;
+  spe_entry_ptr : unsigned_ptr := new unsigned'(spe_entry);
+  stop_info_ptr : spe_stop_info_ptr := new spe_stop_info;
+
+  filename : String (1 .. 5) := "hello";
+  filename_c : char_array (1 .. 6);
+
+begin
+  filename_c := To_C (filename, True); 
+  program := spe_image_open(filename_c);
+  if program = NULL then
+    Put_Line("spe_image_open failed!");
+  end if;
+ 
+  gang := Null;
+  ctx := spe_context_create(flags, gang);
+  if ctx = NULL then
+    Put_Line("spe_context_create failed!");
+  end if;
+
+  rc := spe_program_load(ctx, program);
+  if rc /= 0 then
+    Put_Line("spe_program_load failed!");
+  end if;
+
+  rc := spe_context_run(ctx, spe_entry_ptr, 0, argp, envp, 
stop_info_ptr);
+  Put_Line("exit_code: " & Integer'Image(stop_info_ptr.spe_exit_code));
+  if rc /= 0 then
+    Put_Line("spe_context_run failed!");
+  end if;
+
+  rc := spe_context_destroy (ctx); 
+  if rc /= 0 then
+    Put_Line("spe_context_destroy failed!");
+  end if;
+ 
+  rc := spe_image_close(program);
+  if rc /= 0 then
+    Put_Line("spe_image_close failed!");
+  end if;
+
+end testsingle;
+
+
===================================================================


Mit freundlichen Grüßen / Best Regards
Sa Liu, GCC on Cell/B.E. Development, LTC
Phone: (+49) 7031 163104
-----------------------------------------------------------------------------------------------------------------------------------
IBM Deutschland Entwicklung GmbH
Vorsitzender des Aufsichtsrats: Johann Weihen | Geschäftsführung: Herbert 
Kircher
Sitz der Gesellschaft: Böblingen | Registergericht: Amtsgericht Stuttgart, 
HRB 243294




More information about the cbe-oss-dev mailing list