Ninf-G Interface Description Language

The following statements can be used in the NINF-G IDL files.

Ninf-G IDL syntax

/* program toplevel */
program:  /* empty */
      | declaration_list
    ;

declaration_list: 
      declaration
    | declaration_list declaration
    ;

declaration:
      ``Module'' IDENTIFIER ';'
    | ``FortranFormat'' STRING ';'
    | ``CompileOptions'' STRING ';'
    | ``Globals'' globals_body
    | ``Define'' interface_definition opt_string required interface_body
    ;

interface_definition: 
        IDENTIFIER '(' parameter_list ')'
    ;

parameter_list:
       parameter
    | parameter_list ',' parameter
    ;

parameter: 
       decl_specifier declarator
    ;

decl_specifier: 
    type_specifier
    | MODE
    | MODE type_specifier
    | type_specifier MODE
    | type_specifier MODE type_specifier
    ;

type_specifier:
      TYPE
    | TYPE TYPE
    | TYPE TYPE TYPE    /* ex. unsigned long int */
    ;

declarator:
      IDENTIFIER
    | '(' declarator ')'
    | declarator '['expr_or_null ']'
    | declarator '['expr ':' range_exprs ']'
    | '*' declarator
    ;

range_exprs:
       expr     /* upper limit */
     | expr ',' expr    /* lower limit and upper limit */
     | expr ',' expr ',' expr /* lower, upper and step */

opt_string: 
    /* empty */ 
    | STRING 
    ;

language_spec: 
    /* empty */ 
    | ``fortran''
    | ``C''
    ;

required:
    /* empty */ 
    | ``Required'' STRING
    ;

interface_body:
    '{' /* C statements */ '}'
    | ``Calls'' opt_string IDENTIFIER '(' id_list ')' ';'
    ;

globals_body:
    '{'/* C statements */ '}'
    ;

id_list: IDENTIFIER
    | id_list ',' IDENTIFIER
    ;

/* index description */
expr_or_null: 
       expr 
    | /* null */
    ;

expr:     
      unary_expr
    | expr '/' expr
    | expr '%' expr
    | expr '+' expr
    | expr '-' expr
    | expr '*' expr
    ;

unary_expr:  
      primary_expr
    | '*' expr
    | '-' expr
    ;

primary_expr:
     primary_expr '[' expr ']'
    | IDENTIFIER
    | CONSTANT
    | '('  expr  ')'
    ;

/* TYPE = int, unsigned, char, short, long, long float, double */
/* MODE = mode_in, mode_out, mode_inout, mode_work, IN, OUT, INOUT, WORK*/
/* IDENTIFIER = name */
/* CONSTANT = integer literals Afloating point literals */
/* STRING = "..." */

IDL Sample

sample.idl:

Module sample;
Library "-lm";

Globals { int x,y,z; }

Define sin(IN double d, OUT double result[])
" This is test ..."
{    
    double sin();
    *result = sin(d);
}

Define mmul(long mode_in int n, mode_in double A[n][n], 
    mode_in double B[n][n],
    mode_out double C[n][n])
Required "sample.o"
Calls "C" mmul(n,A,B,C);

Define mmul2(long mode_in int n, mode_in double A[n*n+1-1], 
        mode_in double B[n*n+2-3+1],
        mode_out double C[n*n])
Required "sample.o"
Calls "C" mmul(n,A,B,C);


Define FFT(IN int n,IN int m, OUT float x[n][m], float INOUT y[m][n])
Required "sample.o"
Calls "Fortran" FFT(n,x,y);

stub generator output

# This file 'pi.mak' was created by ns_gen. Don't edit

CC = cc
include $(NS_DIR)/lib/template

# CompileOptions:


#  Just a hack for compatibility
#  Define NS_COMPILER & NS_LINKER as $(CC) if it is not defined.

# Sorry, it may be necessary to edit this part by hand
NS_COMPILER = $(CC)
NS_LINKER = $(CC)

# stub sources

NS_STUB_SRC = _stub_pi_trial.c 

# stub programs

NS_STUB_PROGRAM = _stub_pi_trial

# stub inf files
NS_INF_FILES = _stub_pi_trial.inf

# LDAP dif file
LDAP_DIF = root.ldif

all: $(NS_STUB_PROGRAM) $(NS_INF_FILES) $(LDAP_DIF)

_stub_pi_trial.o: _stub_pi_trial.c
	$(NS_COMPILER) $(CFLAGS) $(NS_CFLAGS) -c _stub_pi_trial.c
_stub_pi_trial: _stub_pi_trial.o pi_trial.o
	$(NS_LINKER) $(CFLAGS) -o _stub_pi_trial _stub_pi_trial.o $(LDFLAGS) $(NS_STUB_LDFLAGS) pi_trial.o $(LIBS)
_inf_pi_trial: _inf_pi_trial.c
	$(NS_COMPILER) $(CFLAGS) $(NS_CFLAGS)  -o _inf_pi_trial  _inf_pi_trial.c $(NS_STUB_LDFLAGS)
_stub_pi_trial.inf: _inf_pi_trial
	 ./_inf_pi_trial _stub_pi_trial.inf



$(LDAP_DIF): $(NS_INF_FILES)
	$(NS_DIR)/bin/ns_gen_dif $(NS_STUB_PROGRAM)

install: $(LDAP_DIF)
	$(INSTALL) *.ldif $(LDIF_INSTALL_DIR)

clean:
	rm -f _stub_pi_trial.o _stub_pi_trial.c
	rm -f _inf_pi_trial.c _inf_pi_trial

veryclean: clean
	rm -f $(NS_STUB_PROGRAM) $(NS_INF_FILES) $(LDAP_DIF)
	rm -f pi_trial.o


# END OF Makefile

_stub_pi_trial.c

/*=============================================================================
Module          :ns_gen
Filename        :_stub_pi_trial.c
RCS             :
        $Source:
        $Revision:
        $Author:
        $Data:Wed Feb 27 16:09:22 2002
        $Locker:
        $state:
=============================================================================*/
#include "nsstb_stub_lib.h"

/* DESCRIPTION:
monte carlo pi computation
*/

static char stub_description[] = "monte carlo pi computation";

struct nslib_expression size20[] = {
	  {
		{
		  {VALUE_CONST, 1} ,{VALUE_END_OF_OP, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		}
	  }
};

struct nslib_expression start20[] = {
	  {
		{
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		}
	  }
};

struct nslib_expression end20[] = {
	  {
		{
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		}
	  }
};

struct nslib_expression step20[] = {
	  {
		{
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		}
	  }
};



struct nslib_param_subscript dims2[] = {
	{ size20, start20, end20, step20 },
};


struct nslib_func_param params[] = {
	{ DT_INT, MODE_IN, 0, NULL, NULL },
	{ DT_LONG, MODE_IN, 0, NULL, NULL },
	{ DT_LONG, MODE_OUT, 1, dims2, NULL },
};


nslib_func_info_t nslib_func_info = {
	221,
	{
	  "pi",
	  "pi_trial" 
	},
	3,
	params, 
	{
	  {
		{
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		  {VALUE_NONE, 0} ,{VALUE_NONE, 0} ,{VALUE_NONE, 0} ,
		}
	  },
	  (nslib_backend_t)0, /* backend */
	  (ns_bool)0, /* ns_bool: specify server side shrink */
	  stub_description, 
	  0  /* information type :fortran or c */
	}
};

/* Globals */

/* Callback proxy */

/* Stub Main program */
main(int argc, char ** argv){
	int seed;
	long times;
	long *count;

	int tmp;

	nsstb_INIT(argc,argv);
	while(1){
		tmp = nsstb_REQ();
		if (!tmp){
		    break;
		}
		nsstb_SET_ARG(&seed,0);
		nsstb_SET_ARG(×,1);
		nsstb_SET_ARG(&count,2);
		nsstb_BEGIN();
{
  long counter;
  counter = pi_trial(seed, times);
  *count = counter;
}
		tmp = nsstb_END();
		if (!tmp) break;
	}
	nsstb_EXIT();
}
/*                     */