summaryrefslogtreecommitdiff
path: root/macros/CCodeGeneration
diff options
context:
space:
mode:
Diffstat (limited to 'macros/CCodeGeneration')
-rw-r--r--macros/CCodeGeneration/C_GenDeclarations.sci160
-rw-r--r--macros/CCodeGeneration/GetSymbolDimension.sci70
2 files changed, 113 insertions, 117 deletions
diff --git a/macros/CCodeGeneration/C_GenDeclarations.sci b/macros/CCodeGeneration/C_GenDeclarations.sci
index 936280b8..7a6565ec 100644
--- a/macros/CCodeGeneration/C_GenDeclarations.sci
+++ b/macros/CCodeGeneration/C_GenDeclarations.sci
@@ -17,11 +17,13 @@ function Cdeclaration = C_GenDeclarations(ArgStruct,CDeclarationFileName,IndentL
// Contact: raffaele.nutricato@tiscali.it
// -----------------------------------------------------------------
+// Generate C corresponding declaration given some information in ArgStruct
+//
+
// ------------------------------
// --- Check input arguments. ---
// ------------------------------
-SCI2CNInArgCheck(argn(2),6,6);
-
+ SCI2CNInArgCheck(argn(2),6,6);
// #RNU_RES_B
//NUT: ilnome di questa funzione va cambiato perche' le dichiarazioni le fanno anche i for e i while.
@@ -30,100 +32,96 @@ PrintStringInfo('***Generating C declaration***',ReportFileName,'file','y');
// #RNU_RES_E
Cdeclaration = '';
-NDeclarations = 0;
if (ArgStruct.Dimension > 0)
- if (FlagExt == 1)
- Cdeclaration(1) = 'extern ';
- Cdeclaration(2) = 'extern ';
- else
- Cdeclaration(1) = '';
- Cdeclaration(2) = '';
- end
- // #RNU_RES_B
- //NUT: vedi Mem_Alloc_Out per maggiori info sulla rimozione della temp nella if
- // if ((ArgStruct.Scope=='Temp') | (ArgStruct.FindLike == -1) | (isnum(ArgStruct.Size(1))==%F) | (isnum(ArgStruct.Size(2))==%F))
- // #RNU_RES_E
- if (ArgStruct.Type=='g')
- // if (isnan(ArgStruct.Value) )
- if ((isnum(ArgStruct.Size(1))==%F) | (isnum(ArgStruct.Size(2))==%F) )
- Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+...
- ' * '+ArgStruct.Name+';';
- else
- if ((FlagExt == 1) | (isnan(ArgStruct.Value)))
- Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+...
- ' '+ArgStruct.Name+'['+ArgStruct.Size(1)+'*'+ArgStruct.Size(2)+'];';
- else
- Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+...
- ' '+ArgStruct.Name+'['+ArgStruct.Size(1)+'*'+ArgStruct.Size(2)+'] = {'+ArgStruct.Value+'};';
- end
- end
- Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size[2] = {'+ArgStruct.Size(1)+','+ArgStruct.Size(2)+'};';
- NDeclarations = 2;
- elseif ((ArgStruct.FindLike == -1) | ...
- (isnum(ArgStruct.Size(1))==%F) | (isnum(ArgStruct.Size(2))==%F) | ...
- (ResizeApproach=='REALLOC_ALL_RESIZE_ALL' & ArgStruct.Type~='g'))
- // #RNU_RES_B
- //RNU sulle stringhe non ho ancora deciso se applicare la realloc.
- // Generate only the pointer that will be used by the malloc function.
- // #RNU_RES_E
- if (FlagExt == 1)
- Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+'* '+...
- ArgStruct.Name+';';
- else
- Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+'* '+...
- ArgStruct.Name+' = NULL;';
- end
- // Declare the Size array
- Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size[2];';
- NDeclarations = 2;
- else
- // Declare the array with its size.
+ if (FlagExt == 1)
+ Cdeclaration(1) = 'extern ';
+ Cdeclaration(2) = 'extern ';
+ else
+ Cdeclaration(1) = '';
+ Cdeclaration(2) = '';
+ end
+// #RNU_RES_B
+//NUT: vedi Mem_Alloc_Out per maggiori info sulla rimozione della temp nella if
+// if ((ArgStruct.Scope=='Temp') | (ArgStruct.FindLike == -1) | (isnum(ArgStruct.Size(1))==%F) | (isnum(ArgStruct.Size(2))==%F))
+// #RNU_RES_E
+ if (ArgStruct.Type=='g')
+// if (isnan(ArgStruct.Value) )
+ if ((isnum(ArgStruct.Size(1))==%F) | (isnum(ArgStruct.Size(2))==%F) )
Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+...
- ' '+ArgStruct.Name+'['+ArgStruct.Size(1)+'*'+ArgStruct.Size(2)+'];';
- if (FlagExt == 1)
- Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size[2];';
+ ' * '+ArgStruct.Name+';';
+ else
+ if ((FlagExt == 1) | (isnan(ArgStruct.Value)))
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+...
+ ' '+ArgStruct.Name+'['+ArgStruct.Size(1)+'*'+ArgStruct.Size(2)+'];';
else
- Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size[2] = {'+ArgStruct.Size(1)+','+ArgStruct.Size(2)+'};';
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+...
+ ' '+ArgStruct.Name+'['+ArgStruct.Size(1)+'*'+ArgStruct.Size(2)+'] = {'+ArgStruct.Value+'};';
end
- NDeclarations = 2;
- end
+ end
+ Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size[2] = {'+ArgStruct.Size(1)+','+ArgStruct.Size(2)+'};';
+ elseif ((ArgStruct.FindLike == -1) | ...
+ (isnum(ArgStruct.Size(1))==%F) | (isnum(ArgStruct.Size(2))==%F) | ...
+ (ResizeApproach=='REALLOC_ALL_RESIZE_ALL' & ArgStruct.Type~='g'))
+// #RNU_RES_B
+//RNU sulle stringhe non ho ancora deciso se applicare la realloc.
+// Generate only the pointer that will be used by the malloc function.
+// #RNU_RES_E
+ if (FlagExt == 1)
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+'* '+...
+ ArgStruct.Name+';';
+ else
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+'* '+...
+ ArgStruct.Name+' = NULL;';
+ end
+// Declare the Size array
+ Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size[2];';
+ else
+// Declare the array with its size.
+ computedSize = ArgStruct.Size(1);
+ computedSizeLength = size(ArgStruct.Size, '*');
+ computedSizeField = ArgStruct.Size(1);
+ for sizeIterator = 2:computedSizeLength;
+ computedSize = computedSize + ' * ' + ArgStruct.Size(sizeIterator);
+ computedSizeField = computedSizeField + ', ' + ArgStruct.Size(sizeIterator);
+ end
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+' '+ArgStruct.Name+'['+computedSize+'];';
+ Cdeclaration(2) = Cdeclaration(2)+C_Type('i')+' __'+ArgStruct.Name+'Size['+string(computedSizeLength)+']';
+ if (FlagExt <> 1)
+ Cdeclaration(2) = Cdeclaration(2)+' = {'+computedSizeField+'};';
+ end
+ Cdeclaration(2) = Cdeclaration(2)+';';
+ end
else
- if (FlagExt == 1)
- Cdeclaration(1) = 'extern ';
- else
- Cdeclaration(1) = '';
- end
- Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+' '+ArgStruct.Name;
- if (~isnan(ArgStruct.Value) & (FlagExt == 0))
- if isreal(ArgStruct.Value)
- Cdeclaration(1) = Cdeclaration(1)+' = '+SCI2Cstring(ArgStruct.Value);
+ if (FlagExt == 1)
+ Cdeclaration(1) = 'extern ';
+ else
+ Cdeclaration(1) = '';
+ end
+ Cdeclaration(1) = Cdeclaration(1)+C_Type(ArgStruct.Type)+' '+ArgStruct.Name;
+ if (~isnan(ArgStruct.Value) & (FlagExt == 0))
+ if isreal(ArgStruct.Value)
+ Cdeclaration(1) = Cdeclaration(1)+' = '+SCI2Cstring(ArgStruct.Value);
+ else
+ if (ArgStruct.Type == 'z')
+ Cdeclaration(1) = Cdeclaration(1)+' = DoubleComplex('+SCI2Cstring(real(ArgStruct.Value))+','+SCI2Cstring(imag(ArgStruct.Value))+')';
else
- if (ArgStruct.Type == 'z')
- Cdeclaration(1) = Cdeclaration(1)+' = DoubleComplex('+SCI2Cstring(real(ArgStruct.Value))+','+SCI2Cstring(imag(ArgStruct.Value))+')';
- else
- Cdeclaration(1) = Cdeclaration(1)+' = FloatComplex('+SCI2Cstring(real(ArgStruct.Value))+','+SCI2Cstring(imag(ArgStruct.Value))+')';
- end
+ Cdeclaration(1) = Cdeclaration(1)+' = FloatComplex('+SCI2Cstring(real(ArgStruct.Value))+','+SCI2Cstring(imag(ArgStruct.Value))+')';
end
- end
- Cdeclaration(1) = Cdeclaration(1)+';';
- NDeclarations = 1;
+ end
+ end
+ Cdeclaration(1) = Cdeclaration(1)+';';
end
// --------------------------------------------
// --- Write C declaration into the C file. ---
// --------------------------------------------
-for cntdecl = 1:NDeclarations
- // #RNU_RES_B
- PrintStringInfo(' '+Cdeclaration(cntdecl),ReportFileName,'file','y');
- // #RNU_RES_E
+for cntdecl = 1:size(Cdeclaration, '*')
+ PrintStringInfo(' '+Cdeclaration(cntdecl),ReportFileName,'file','y');
+ PrintStringInfo(C_IndentBlanks(IndentLevel)+Cdeclaration(cntdecl),CDeclarationFileName,'file','y');
end
-// #RNU_RES_B
+
PrintStringInfo(' Writing C declaration in: '+CDeclarationFileName,ReportFileName,'file','y');
-// #RNU_RES_E
-for cntdecl = 1:NDeclarations
- PrintStringInfo(C_IndentBlanks(IndentLevel)+Cdeclaration(cntdecl),CDeclarationFileName,'file','y');
-end
PrintStringInfo(' ',CDeclarationFileName,'file','y');
endfunction
diff --git a/macros/CCodeGeneration/GetSymbolDimension.sci b/macros/CCodeGeneration/GetSymbolDimension.sci
index 4fe3cc8d..bb6045a2 100644
--- a/macros/CCodeGeneration/GetSymbolDimension.sci
+++ b/macros/CCodeGeneration/GetSymbolDimension.sci
@@ -11,7 +11,7 @@ function symboldimension = GetSymbolDimension(Field_Size)
//
// Output data:
// symboldimension: number specifying the dimension of the symbol.
-// 0 = scalar; 1 = column or row; 2 = matrix.
+// 0 = scalar; 1 = column or row; 2 = matrix; 3 = hypermatrix.
//
// #RNU_RES_E
// Status:
@@ -25,46 +25,44 @@ function symboldimension = GetSymbolDimension(Field_Size)
// ------------------------------
// --- Check input arguments. ---
// ------------------------------
-SCI2CNInArgCheck(argn(2),1,1);
-
+ SCI2CNInArgCheck(argn(2),1,1);
+
// Size is expressed as an array of two strings.
-Nelem = max(size(Field_Size));
-if (Nelem < 2)
- SCI2Cerror('The size of a symbol cannot be expressed with one or zero numbers.');
-end
-for countersize = 1:Nelem
- // #RNU_RES_B
- // Field_Type = 1; if Size is Symbol or a number > 1
- // Field_Type = 0; if Size is a number == 1
- // error if Size is 0.
- // A symbol is scalar if the sum of the Field_Type elements is zero.
- // A symbol is column or row if the sum of the Field_Type elements is one.
- // A symbol is a matrix if the sum of the Field_Type elements is > 1.
- // #RNU_RES_E
- if (isnum(Field_Size(countersize)))
+ Nelem = max(size(Field_Size));
+ if (Nelem < 2)
+ SCI2Cerror('The size of a symbol cannot be expressed with one or zero numbers.');
+ end
+
+ for countersize = 1:Nelem
+// #RNU_RES_B
+// Field_Type = 1; if Size is Symbol or a number > 1
+// Field_Type = 0; if Size is a number == 1
+// error if Size is 0.
+// A symbol is scalar if the sum of the Field_Type elements is zero.
+// A symbol is column or row if the sum of the Field_Type elements is one.
+// A symbol is a matrix if the sum of the Field_Type elements is > 1.
+// #RNU_RES_E
+ if (isnum(Field_Size(countersize)))
tmpnum = eval(Field_Size(countersize));
if (tmpnum == 0)
- SCI2Cerror('Found a symbol that has zeros elements. 0xN or Nx0 matrices are not allowed.');
+ SCI2Cerror('Found a symbol that has zeros elements. 0xN or Nx0 matrices are not allowed.');
elseif (tmpnum == 1)
- Field_Type(countersize) = 0;
+ Field_Type(countersize) = 0;
else
- Field_Type(countersize) = 1;
+ Field_Type(countersize) = 1;
end
- else
- Field_Type(countersize) = 1;
- end
-end
-
-Sum_Field_Type = sum(Field_Type);
-if (Sum_Field_Type == 0)
- symboldimension = 0;
-elseif (Sum_Field_Type == 1)
- // #RNU_RES_B
- // symboldimension = 1; //NUT for this release there will not be difference between vectors and matrices.
- // #RNU_RES_E
- symboldimension = 2;
-else
- symboldimension = 2;
-end
+ else
+ Field_Type(countersize) = 1;
+ end
+ end
+ // The symbol global dimension is the count of all >1 dimension.
+ symboldimension = sum(Field_Type);
+
+ if (symboldimension == 1)
+// #RNU_RES_B
+// symboldimension = 1; //NUT for this release there will not be difference between vectors and matrices.
+// #RNU_RES_E
+ symboldimension = 2;
+ end
endfunction