summaryrefslogtreecommitdiff
path: root/macros/CCodeGeneration
diff options
context:
space:
mode:
authorsiddhu89902016-05-27 11:50:04 +0530
committersiddhu89902016-05-27 11:50:04 +0530
commit212c54043e454e41ca4b23a5b965d4dbd4b683fe (patch)
treec1b62c677facad021562292b823b5e21978c0e4b /macros/CCodeGeneration
parenta6d6a9c1e88b75668868af691c9731075a514ffb (diff)
downloadScilab2C_fossee_old-212c54043e454e41ca4b23a5b965d4dbd4b683fe.tar.gz
Scilab2C_fossee_old-212c54043e454e41ca4b23a5b965d4dbd4b683fe.tar.bz2
Scilab2C_fossee_old-212c54043e454e41ca4b23a5b965d4dbd4b683fe.zip
Support for basic ODE function added
Diffstat (limited to 'macros/CCodeGeneration')
-rw-r--r--macros/CCodeGeneration/C_FinalizeCode.binbin13584 -> 16292 bytes
-rw-r--r--macros/CCodeGeneration/C_FinalizeCode.sci18
-rw-r--r--macros/CCodeGeneration/C_Funcall.binbin62220 -> 71780 bytes
-rw-r--r--macros/CCodeGeneration/C_Funcall.sci109
-rw-r--r--macros/CCodeGeneration/C_GenDeclarations.binbin21532 -> 22000 bytes
-rw-r--r--macros/CCodeGeneration/C_GenDeclarations.sci28
-rw-r--r--macros/CCodeGeneration/C_GenerateFunName.binbin6436 -> 6736 bytes
-rw-r--r--macros/CCodeGeneration/C_GenerateFunName.sci5
-rw-r--r--macros/CCodeGeneration/C_GenerateMakefile.binbin26144 -> 26832 bytes
-rw-r--r--macros/CCodeGeneration/C_GenerateMakefile.sci4
10 files changed, 124 insertions, 40 deletions
diff --git a/macros/CCodeGeneration/C_FinalizeCode.bin b/macros/CCodeGeneration/C_FinalizeCode.bin
index 5cc2148..44c534e 100644
--- a/macros/CCodeGeneration/C_FinalizeCode.bin
+++ b/macros/CCodeGeneration/C_FinalizeCode.bin
Binary files differ
diff --git a/macros/CCodeGeneration/C_FinalizeCode.sci b/macros/CCodeGeneration/C_FinalizeCode.sci
index 69cad55..1f3c6b5 100644
--- a/macros/CCodeGeneration/C_FinalizeCode.sci
+++ b/macros/CCodeGeneration/C_FinalizeCode.sci
@@ -73,6 +73,24 @@ PrintStringInfo('** ----------------- ',FinalCFileName,'file','y');
PrintStringInfo('*/',FinalCFileName,'file','y');
PrintStringInfo('#include ""'+tmphdrname+tmphdrext+'""',...
FinalCFileName,'file','y');
+//If current file is main C file, include header files corresponding to ODE
+//functions, if any.
+if(SharedInfo.NextSCIFunName == SharedInfo.SCIMainFunName)
+ if(size(SharedInfo.ODElist) <> 0) //check if list is empty
+ //If not empty, add those header files here.
+ for cntlist = 1:size(SharedInfo.ODElist)
+ PrintStringInfo('#include ""'+SharedInfo.ODElist(cntlist)+'.h""',...
+ FinalCFileName,'file','y');
+ end
+
+ end
+end
+
+//If current function contains ODEs, add gsl/gsl_errno.h.
+if (mtlb_strcmp(part(SharedInfo.CurrentFunInfo.CFunctionName,1:5),'odefn') == %T)
+ PrintStringInfo('#include <gsl/gsl_errno.h>',...
+ FinalCFileName,'file','y');
+end
PrintStringInfo('/*',FinalCFileName,'file','y');
PrintStringInfo('** --------------------- ',FinalCFileName,'file','y');
PrintStringInfo('** --- End Includes. --- ',FinalCFileName,'file','y');
diff --git a/macros/CCodeGeneration/C_Funcall.bin b/macros/CCodeGeneration/C_Funcall.bin
index 3682387..f54c0c3 100644
--- a/macros/CCodeGeneration/C_Funcall.bin
+++ b/macros/CCodeGeneration/C_Funcall.bin
Binary files differ
diff --git a/macros/CCodeGeneration/C_Funcall.sci b/macros/CCodeGeneration/C_Funcall.sci
index 3669e54..eec20c7 100644
--- a/macros/CCodeGeneration/C_Funcall.sci
+++ b/macros/CCodeGeneration/C_Funcall.sci
@@ -180,6 +180,9 @@ if (FunInfo.CFunctionName == SharedInfo.CMainFunName)
else
CCall =CCall+'int ';
end
+elseif (mtlb_strcmp(part(CFunName,1:5),'odefn') == %T)
+ //Return type of function containing ODEs must be int.
+ CCall = CCall + 'int ';
else
if (PosFirstOutScalar >= 1)
if (FlagCall == 1)
@@ -207,39 +210,84 @@ end
PrintStringInfo(' C call after output scalar args check: '+CCall,ReportFileName,'file','y');
// #RNU_RES_E
clear counterin
-for counterin = 1:NInArg
-
- if (InArg(counterin).Type == 'g' & InArg(counterin).Scope == 'String')
- TmpInArgName = '""'+InArg(counterin).Name+'""';
- elseif (InArg(counterin).Type == 'z' & (InArg(counterin).Scope == 'Number'))
- TmpInArgName = 'DoubleComplex('+SCI2Cstring(real(InArg(counterin).Value))+','+SCI2Cstring(imag(InArg(counterin).Value))+')';
- elseif (InArg(counterin).Type == 'c' & (InArg(counterin).Scope == 'Number'))
- TmpInArgName = 'FloatComplex('+SCI2Cstring(real(InArg(counterin).Value))+','+SCI2Cstring(imag(InArg(counterin).Value))+')';
- else
- TmpInArgName = InArg(counterin).Name;
- end
+if(mtlb_strcmp(part(CFunName,1:5),'odefn') == %F)
+ for counterin = 1:NInArg
- TmpInArgType = C_Type(InArg(counterin).Type);
+ if (InArg(counterin).Type == 'g' & InArg(counterin).Scope == 'String')
+ TmpInArgName = '""'+InArg(counterin).Name+'""';
+ elseif (InArg(counterin).Type == 'z' & (InArg(counterin).Scope == 'Number'))
+ TmpInArgName = 'DoubleComplex('+SCI2Cstring(real(InArg(counterin).Value))+','+SCI2Cstring(imag(InArg(counterin).Value))+')';
+ elseif (InArg(counterin).Type == 'c' & (InArg(counterin).Scope == 'Number'))
+ TmpInArgName = 'FloatComplex('+SCI2Cstring(real(InArg(counterin).Value))+','+SCI2Cstring(imag(InArg(counterin).Value))+')';
+ else
+ TmpInArgName = InArg(counterin).Name;
+ end
- //if (FunctionName == 'OpEqual')
- // TmpInArgSizeVar = '__'+OutArg(counterin).Name+'Size';
- // else
- TmpInArgSizeVar = '__'+InArg(counterin).Name+'Size';
- //end
+ TmpInArgType = C_Type(InArg(counterin).Type);
- if (InArg(counterin).Dimension == 0)
- if (FlagCall == 0)
- CCall = CCall+TmpInArgType+' ';
- end
- CCall = CCall+TmpInArgName+',';
- else
- if (FlagCall == 0)
- CCall = CCall+TmpInArgType+'* '+TmpInArgName+', int* __'+TmpInArgName+'Size,';
+ //if (FunctionName == 'OpEqual')
+ // TmpInArgSizeVar = '__'+OutArg(counterin).Name+'Size';
+ // else
+ TmpInArgSizeVar = '__'+InArg(counterin).Name+'Size';
+ //end
+
+ if (InArg(counterin).Dimension == 0)
+ if (FlagCall == 0)
+ CCall = CCall+TmpInArgType+' ';
+ end
+ CCall = CCall+TmpInArgName+',';
else
- CCall = CCall+TmpInArgName+', '+TmpInArgSizeVar+',';
+ if (FlagCall == 0)
+ CCall = CCall+TmpInArgType+'* '+TmpInArgName+', int* __'+TmpInArgName+'Size,';
+ else
+ CCall = CCall+TmpInArgName+', '+TmpInArgSizeVar+',';
+ end
+ end
+ end
+else
+ //If current function contains 'odefn' at the beginning, then it contains
+ //differnetial equations and its function call need to be differnt than
+ //other function call. GSL library being used for solving ODEs, requires
+ //function containing odes in specific format which is differnt than generated
+ //above.
+ for counterin = 1:NInArg
+
+ if(counterin <> 3) //Skip third argument
+ if (InArg(counterin).Type == 'g' & InArg(counterin).Scope == 'String')
+ TmpInArgName = '""'+InArg(counterin).Name+'""';
+ elseif (InArg(counterin).Type == 'z' & (InArg(counterin).Scope == 'Number'))
+ TmpInArgName = 'DoubleComplex('+SCI2Cstring(real(InArg(counterin).Value))+','+SCI2Cstring(imag(InArg(counterin).Value))+')';
+ elseif (InArg(counterin).Type == 'c' & (InArg(counterin).Scope == 'Number'))
+ TmpInArgName = 'FloatComplex('+SCI2Cstring(real(InArg(counterin).Value))+','+SCI2Cstring(imag(InArg(counterin).Value))+')';
+ else
+ TmpInArgName = InArg(counterin).Name;
+ end
+
+ TmpInArgType = C_Type(InArg(counterin).Type);
+
+ //if (FunctionName == 'OpEqual')
+ // TmpInArgSizeVar = '__'+OutArg(counterin).Name+'Size';
+ // else
+ TmpInArgSizeVar = '__'+InArg(counterin).Name+'Size';
+ //end
+
+ if (InArg(counterin).Dimension == 0)
+ if (FlagCall == 0)
+ CCall = CCall+TmpInArgType+' ';
+ end
+ CCall = CCall+TmpInArgName+',';
+ else
+ if (FlagCall == 0)
+ CCall = CCall+TmpInArgType+'* '+TmpInArgName+', ';//int* __'+TmpInArgName+'Size,';
+ else
+ CCall = CCall+TmpInArgName+', ';//+TmpInArgSizeVar+',';
+ end
+ end
end
end
+
end
+
// #RNU_RES_B
PrintStringInfo(' C call after input args analysis: '+CCall,ReportFileName,'file','y');
// #RNU_RES_E
@@ -308,6 +356,11 @@ if (part(CCall,length(CCall):length(CCall)) == ',')
CCall = part(CCall,1:length(CCall)-1);
end
+//__ysize is added to input arguments at last to comply with form required by GSL
+if(mtlb_strcmp(part(CFunName,1:5),'odefn') == %T)
+ CCall = CCall + ', int* '+TmpInArgSizeVar;
+end
+
CCall = CCall+')';
if (FlagCall == 1)
CCall = CCall+';';
@@ -352,8 +405,12 @@ if mtlb_strcmp(FunctionName,'return')
PrintStringInfo(' return function of the AST is skipped.',ReportFileName,'file','y');
//RN provo a non skippare e a mettere la return.
// #RNU_RES_E
+
if (SharedInfo.CurrentFunInfo.CFunctionName == SharedInfo.CMainFunName)
CCall = CCall+'return(0);';
+ elseif (mtlb_strcmp(part(SharedInfo.CurrentFunInfo.CFunctionName,1:5),'odefn') == %T)
+ //For GSL library, function containing ODEs must return GSL_SUCCESS
+ CCall = CCall + 'return GSL_SUCCESS;'
else
if (SharedInfo.CurrentFunInfo.PosFirstOutScalar > 0)
CCall = CCall+'return('+SharedInfo.CurrentFunInfo.OutArg(SharedInfo.CurrentFunInfo.PosFirstOutScalar).Name+');'
diff --git a/macros/CCodeGeneration/C_GenDeclarations.bin b/macros/CCodeGeneration/C_GenDeclarations.bin
index 8bd7257..1e6c455 100644
--- a/macros/CCodeGeneration/C_GenDeclarations.bin
+++ b/macros/CCodeGeneration/C_GenDeclarations.bin
Binary files differ
diff --git a/macros/CCodeGeneration/C_GenDeclarations.sci b/macros/CCodeGeneration/C_GenDeclarations.sci
index 7a6565e..eb61723 100644
--- a/macros/CCodeGeneration/C_GenDeclarations.sci
+++ b/macros/CCodeGeneration/C_GenDeclarations.sci
@@ -92,24 +92,28 @@ if (ArgStruct.Dimension > 0)
Cdeclaration(2) = Cdeclaration(2)+';';
end
else
- if (FlagExt == 1)
- Cdeclaration(1) = 'extern ';
+ if (ArgStruct.Type == 'f')
+ //do nothing. This is a function name. Will be declared in header file.
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
- if (ArgStruct.Type == 'z')
- Cdeclaration(1) = Cdeclaration(1)+' = DoubleComplex('+SCI2Cstring(real(ArgStruct.Value))+','+SCI2Cstring(imag(ArgStruct.Value))+')';
+ 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
- Cdeclaration(1) = Cdeclaration(1)+' = FloatComplex('+SCI2Cstring(real(ArgStruct.Value))+','+SCI2Cstring(imag(ArgStruct.Value))+')';
+ 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
end
end
+ Cdeclaration(1) = Cdeclaration(1)+';';
end
- Cdeclaration(1) = Cdeclaration(1)+';';
end
diff --git a/macros/CCodeGeneration/C_GenerateFunName.bin b/macros/CCodeGeneration/C_GenerateFunName.bin
index 9a4af08..8486a3b 100644
--- a/macros/CCodeGeneration/C_GenerateFunName.bin
+++ b/macros/CCodeGeneration/C_GenerateFunName.bin
Binary files differ
diff --git a/macros/CCodeGeneration/C_GenerateFunName.sci b/macros/CCodeGeneration/C_GenerateFunName.sci
index 54c641f..d87fb9c 100644
--- a/macros/CCodeGeneration/C_GenerateFunName.sci
+++ b/macros/CCodeGeneration/C_GenerateFunName.sci
@@ -23,14 +23,14 @@ function CFunName = C_GenerateFunName(FunctionName,InArg,NInArg,OutArg,NOutArg)
// ------------------------------
SCI2CNInArgCheck(argn(2),5,5);
CFunName = '';
-if((IsAVRSupportFunction(FunctionName)) | (IsRPISupportFunction(FunctionName)))
+if((IsAVRSupportFunction(FunctionName)) | (IsRPISupportFunction(FunctionName)) | ...
+ (mtlb_strcmp(part(FunctionName,1:5),'odefn') == %T))
//If current function is an AVR or RPi function, then function name can be just
//plain function name without any input/output arguments types
CFunName = CFunName+FunctionName;
else
-
for tmpcnt = 1:NInArg
if (InArg(tmpcnt).Dimension == 1)
CFunName = CFunName+InArg(tmpcnt).Type+'2';
@@ -48,5 +48,6 @@ else
CFunName = CFunName+OutArg(tmpcnt).Type+SCI2Cstring(OutArg(tmpcnt).Dimension);
end
end
+
end
endfunction
diff --git a/macros/CCodeGeneration/C_GenerateMakefile.bin b/macros/CCodeGeneration/C_GenerateMakefile.bin
index 43de229..76090ba 100644
--- a/macros/CCodeGeneration/C_GenerateMakefile.bin
+++ b/macros/CCodeGeneration/C_GenerateMakefile.bin
Binary files differ
diff --git a/macros/CCodeGeneration/C_GenerateMakefile.sci b/macros/CCodeGeneration/C_GenerateMakefile.sci
index 4817af1..fecbf91 100644
--- a/macros/CCodeGeneration/C_GenerateMakefile.sci
+++ b/macros/CCodeGeneration/C_GenerateMakefile.sci
@@ -75,6 +75,10 @@ else
PrintStringInfo('LDFLAGS = -lblas -llapack -lm ',FileInfo.MakefileFilename,'file','y','y');
end
end
+//If ode function is used, add libgsl.
+if(size(SharedInfo.ODElist) <> 0)
+ PrintStringInfo('LDFLAGS += -lgsl',FileInfo.MakefileFilename,'file','y','y');
+end
// Binary definition
PrintStringInfo('EXEFILENAME = mytest.exe',FileInfo.MakefileFilename,'file','y','y');