diff options
Diffstat (limited to 'macros/CCodeGeneration')
30 files changed, 3096 insertions, 0 deletions
diff --git a/macros/CCodeGeneration/C_FinalizeCode.sci b/macros/CCodeGeneration/C_FinalizeCode.sci new file mode 100644 index 0000000..33a1d79 --- /dev/null +++ b/macros/CCodeGeneration/C_FinalizeCode.sci @@ -0,0 +1,116 @@ +function C_FinalizeCode(FileInfo,SharedInfo) +// function C_FinalizeCode(FileInfo,SharedInfo) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 27-Oct-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +// --- Load File Info Structure. --- +load(FileInfoDatFile,'FileInfo'); + +// --- Load Shared Info Structure. --- +load(FileInfo.SharedInfoDatFile,'SharedInfo'); + +CPass2FileName = FileInfo.Funct(SharedInfo.NextSCIFunNumber).CPass2FileName; +FinalCFileName = FileInfo.Funct(SharedInfo.NextSCIFunNumber).FinalCFileName; +Pass1HeaderFileName = FileInfo.Funct(SharedInfo.NextSCIFunNumber).Pass1HeaderFileName; +FinalHeaderFileName = FileInfo.Funct(SharedInfo.NextSCIFunNumber).FinalHeaderFileName; +// #RNU_RES_B +PrintStringInfo('Generating the final C code in:'+FinalCFileName,... + FileInfo.Funct(SharedInfo.NextSCIFunNumber).ReportFileName,'file','y'); +// #RNU_RES_E +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +// --------------------------------- +// --- Finalize the header file. --- +// --------------------------------- +if(SharedInfo.OpenCVUsed) + PrintStringInfo('#include ""cvcore.hpp""',Pass1HeaderFileName,'file','y'); + PrintStringInfo('#include ""int_cvcore.hpp""',Pass1HeaderFileName,'file','y'); + PrintStringInfo('#include ""cvhighgui.hpp""',Pass1HeaderFileName,'file','y'); + PrintStringInfo('#include ""int_cvhighgui.hpp""',Pass1HeaderFileName,'file','y'); + PrintStringInfo('#include ""cvimgproc.hpp""',Pass1HeaderFileName,'file','y'); + PrintStringInfo('#include ""int_cvimgproc.hpp""',Pass1HeaderFileName,'file','y'); +end +PrintStringInfo('/*',Pass1HeaderFileName,'file','y'); +PrintStringInfo('** ---------------------------- ',Pass1HeaderFileName,'file','y'); +PrintStringInfo('** --- End USER2C Includes. --- ',Pass1HeaderFileName,'file','y'); +PrintStringInfo('** ---------------------------- ',Pass1HeaderFileName,'file','y'); +PrintStringInfo('*/',Pass1HeaderFileName,'file','y'); +//PrintStringInfo('#ifdef __cplusplus',Pass1HeaderFileName,'file','y'); +//PrintStringInfo('} /* extern ""C"" */',Pass1HeaderFileName,'file','y'); +//PrintStringInfo('#endif',Pass1HeaderFileName,'file','y'); +PrintStringInfo('#endif',Pass1HeaderFileName,'file','y'); +// ------------------------------------- +// --- End Finalize the header file. --- +// ------------------------------------- + +[tmphdrpath,tmphdrname,tmphdrext] = fileparts(Pass1HeaderFileName); + +// #RNU_RES_B +// -------------------------------------------------- +// --- Copy the C code into the C code directory. --- +// -------------------------------------------------- +// #RNU_RES_E +C_SCI2CHeader(FinalCFileName); +PrintStringInfo('/*',FinalCFileName,'file','y'); +PrintStringInfo('** ----------------- ',FinalCFileName,'file','y'); +PrintStringInfo('** --- Includes. --- ',FinalCFileName,'file','y'); +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.Includelist) <> 0) //check if list is empty + //If not empty, add those header files here. + for cntlist = 1:size(SharedInfo.Includelist) + PrintStringInfo('#include ""'+SharedInfo.Includelist(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'); +PrintStringInfo('** --------------------- ',FinalCFileName,'file','y'); +PrintStringInfo('*/',FinalCFileName,'file','y'); +PrintStringInfo(' ',FinalCFileName,'file','y'); +PrintStringInfo(' ',FinalCFileName,'file','y'); +PrintStringInfo(' ',FinalCFileName,'file','y'); +SCI2Ccopyfile(CPass2FileName,... + FinalCFileName,'append'); +SCI2Ccopyfile(Pass1HeaderFileName,... + FinalHeaderFileName,'append'); + + +endfunction diff --git a/macros/CCodeGeneration/C_ForExpression.sci b/macros/CCodeGeneration/C_ForExpression.sci new file mode 100644 index 0000000..4e75c06 --- /dev/null +++ b/macros/CCodeGeneration/C_ForExpression.sci @@ -0,0 +1,217 @@ +function SharedInfo = C_ForExpression(FileInfo,SharedInfo) +// function SharedInfo = C_ForExpression(FileInfo,SharedInfo) +// ----------------------------------------------------------------- +// Get function for a generic SCI2C table. +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 15-Nov-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; + +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +CPass1FileName = FileInfo.Funct(nxtscifunnumber).CPass1FileName; +CPass1ForProlFileName = FileInfo.Funct(nxtscifunnumber).CPass1ForProlFileName(SharedInfo.For.Level); +CDeclarationFileName = FileInfo.Funct(nxtscifunnumber).CDeclarationFileName; +CPass1ForEpilFileName = FileInfo.Funct(nxtscifunnumber).CPass1ForEpilFileName(SharedInfo.For.Level); + +// #RNU_RES_B +PrintStringInfo(' ',ReportFileName,'file','y'); +PrintStringInfo('***Generating C code***',ReportFileName,'file','y','n'); +// #RNU_RES_E +CCall =''; +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +// ---------------------------- +// --- Generate the C call. --- +// ---------------------------- + +// ------------------------- +// --- Manage all cases. --- +// ------------------------- +if (SharedInfo.ForExpr.AssignmentFun == SharedInfo.CFunId.EqScalar) + // #RNU_RES_B + // --------------- + // --- Case 1. --- + // --------------- + PrintStringInfo(' Handling For Expression with scalar equal.',ReportFileName,'file','y'); + + // for a = 10 or for a = sin(tan(b)) where b is scalar: + // In this case non for loops are needed.--> Do nothing! + + // ------------------------------------------------------------------------------------- + // --- Generate Prologue and Epilogue -> Copy the first N-1 lines of the for.c code. --- + // ------------------------------------------------------------------------------------- + // #RNU_RES_E + [C_Strings,NumCStrings] = File2StringArray(FileInfo.Funct(nxtscifunnumber).CPass1ForProlFileName(SharedInfo.For.Level)); + C_Strings = stripblanks(C_Strings); + + for cntstr = 1:NumCStrings + // #RNU_RES_B + // Prologue + // #RNU_RES_E + PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+C_Strings(cntstr),CPass1FileName,'file','y'); + end + // #RNU_RES_B + // Epilogue + // #RNU_RES_E + PrintStringInfo(' ',CPass1ForEpilFileName ,'file','y'); + +elseif (SharedInfo.ForExpr.AssignmentFun == SharedInfo.CFunId.OpColon) + // #RNU_RES_B + // --------------- + // --- Case 2. --- + // --------------- + // for a = 1:10 + PrintStringInfo(' Handling For Expression with OpColon.',ReportFileName,'file','y'); + // #RNU_RES_E + + // #RNU_RES_B + // ------------------------------------------------------------------------------------- + // --- Generate Prologue and Epilogue -> Copy the first N-1 lines of the for.c code. --- + // ------------------------------------------------------------------------------------- + // #RNU_RES_E + [C_Strings,NumCStrings] = File2StringArray(FileInfo.Funct(nxtscifunnumber).CPass1ForProlFileName(SharedInfo.For.Level)); + C_Strings = stripblanks(C_Strings); + for cntstr = 1:NumCStrings + // #RNU_RES_B + // Prologue + // #RNU_RES_E + PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+C_Strings(cntstr),CPass1FileName,'file','y','n'); + // #RNU_RES_B + // Epilogue + // #RNU_RES_E + if (length(C_Strings(cntstr)) == 0) + C_Strings(cntstr) = ' '; // RNU for Bruno: If I don't do that I get a PrintStringInfo error related to mputstr. + // Function not defined for given argument type(s),
+ // check arguments or define function %0_mputstr for overloading. + end + PrintStringInfo(string(C_Strings(cntstr)),CPass1ForEpilFileName ,'file','y','n'); + end + // #RNU_RES_B + // ---------------------------------------- + // --- Insert "}" in the epilogue file. --- + // ---------------------------------------- + // #RNU_RES_E + PrintStringInfo('}',CPass1ForEpilFileName ,'file','y'); + + // #RNU_RES_B + // ------------------------------ + // --- Insert for expression. --- + // ------------------------------ + // #RNU_RES_E + CCall = 'for('+SharedInfo.ForExpr.SclValCntArg.Name+' = '+SharedInfo.ForExpr.OpColonInfoIn1+'; '... + +SharedInfo.ForExpr.SclValCntArg.Name+' <= '+SharedInfo.ForExpr.OpColonInfoIn3+'; '... + +SharedInfo.ForExpr.SclValCntArg.Name+' += '+SharedInfo.ForExpr.OpColonInfoIn2+')'; + PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CCall,CPass1FileName,'file','y'); + + // #RNU_RES_B + // ------------------- + // --- Insert "{". --- + // ------------------- + // #RNU_RES_E + CCall = '{'; + PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CCall,CPass1FileName,'file','y'); + + // --------------------------------- + // --- Update Indentation Level. --- + // --------------------------------- + SharedInfo.NIndent = SharedInfo.NIndent + 1; + +elseif (SharedInfo.ForExpr.AssignmentFun == SharedInfo.CFunId.EqMatrix | ... + SharedInfo.ForExpr.AssignmentFun == SharedInfo.CFunId.GenFunMtx) + // #RNU_RES_B + // --------------- + // --- Case 3. --- + // --------------- + PrintStringInfo(' Handling For Expression with Matrix Equal/Function.',ReportFileName,'file','y'); + + // for cnt = TMP where TMP is a matrix + // for cnt = fun(TMP) where TMP is a matrix + // Conversion is performed as shown in the following example: + // init code for temp vars --> copy all for.c code (up to last-1 line) into C pass1 code. + // intSCI2C __forcnt1; --> declaration file. + // replace in the last C line CntArg.Name with '__TmpVal'+CntArg.Name + // for (__forcnt1 = 0; __forcnt1 < CntArg.Size(1)*CntArg.Size(2); __forcnt1++) + // { + // CntArg.Name = '__TmpVal'+CntArg.Name[__forcnt1]; + // init code for temp vars + // } + + // ------------------------------------------------------------------------------------- + // --- Generate Prologue and Epilogue -> Copy the first N-1 lines of the for.c code. --- + // ------------------------------------------------------------------------------------- + // #RNU_RES_E + [C_Strings,NumCStrings] = File2StringArray(FileInfo.Funct(nxtscifunnumber).CPass1ForProlFileName(SharedInfo.For.Level)); + C_Strings = stripblanks(C_Strings); + + for cntstr = 1:NumCStrings + // Prologue + PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+C_Strings(cntstr),CPass1FileName,'file','y'); + // Epilogue + PrintStringInfo(C_Strings(cntstr),CPass1ForEpilFileName ,'file','y'); + end + + // #RNU_RES_B + // ---------------------------------------- + // --- Insert "}" in the epilogue file. --- + // ---------------------------------------- + // #RNU_RES_E + PrintStringInfo('}',CPass1ForEpilFileName ,'file','y'); + + // ------------------------------ + // --- Insert for expression. --- + // ------------------------------ + CCall = 'for('+SharedInfo.ForExpr.IntCntArg.Name+' = 0'+'; '+... + SharedInfo.ForExpr.IntCntArg.Name+' < '+SharedInfo.ForExpr.MtxValCntArg.Size(1)+'*'+SharedInfo.ForExpr.MtxValCntArg.Size(2)+'; '+... + SharedInfo.ForExpr.IntCntArg.Name+'++)'; + PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CCall,CPass1FileName,'file','y'); + + // ------------------- + // --- Insert "{". --- + // ------------------- + CCall = '{'; + PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CCall,CPass1FileName,'file','y'); + + // --------------------------------- + // --- Update Indentation Level. --- + // --------------------------------- + SharedInfo.NIndent = SharedInfo.NIndent + 1; + + // #RNU_RES_B + // ---------------------------------------------------- + // --- Add code to read the element of CntArg.Name. --- + // ---------------------------------------------------- + // #RNU_RES_E + CCall = SharedInfo.ForExpr.SclValCntArg.Name+' = '+SharedInfo.ForExpr.MtxValCntArg.Name+'['+SharedInfo.ForExpr.IntCntArg.Name+'];'; + PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CCall,CPass1FileName,'file','y'); + +else + // --------------- + // --- Case 5. --- + // --------------- + + SCI2Cerror('Could not manage the for expression.'); +end + +endfunction diff --git a/macros/CCodeGeneration/C_Funcall.sci b/macros/CCodeGeneration/C_Funcall.sci new file mode 100644 index 0000000..450ad08 --- /dev/null +++ b/macros/CCodeGeneration/C_Funcall.sci @@ -0,0 +1,467 @@ +function SharedInfo = C_Funcall(FunInfo,FileInfo,SharedInfo,FlagCall) +// function SharedInfo = C_Funcall(FunInfo,FileInfo,SharedInfo,FlagCall) +// ----------------------------------------------------------------- +// Get function for a generic SCI2C table. +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 27-Oct-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),4,4); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; + +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +CPass1FileName = FileInfo.Funct(nxtscifunnumber).CPass1FileName; +CPass1FreeFileName = FileInfo.Funct(nxtscifunnumber).CPass1FreeFileName; +HeaderFileName = FileInfo.Funct(nxtscifunnumber).Pass1HeaderFileName; +CDeclarationFileName = FileInfo.Funct(nxtscifunnumber).CDeclarationFileName; +CInitVarsFileName = FileInfo.Funct(nxtscifunnumber).CInitVarsFileName; +IndentLevel = SharedInfo.NIndent; +CCall = ''; +Target = SharedInfo.Target; +// --- Extract Function Info. --- +FunctionName = FunInfo.SCIFunctionName; +CFunName = FunInfo.CFunctionName; +InArg = FunInfo.InArg; +NInArg = FunInfo.NInArg; +OutArg = FunInfo.OutArg; +NOutArg = FunInfo.NOutArg; +PosFirstOutScalar = FunInfo.PosFirstOutScalar; + +// #RNU_RES_B +PrintStringInfo(' ',ReportFileName,'file','y'); +PrintStringInfo('***Generating C code***',ReportFileName,'file','y'); +// #RNU_RES_E +// --------------------------- +// --- End Initialization. --- +// --------------------------- + + +// -------------------------------------------------- +// --- Manage anticipated exit from the function. --- +// -------------------------------------------------- +if (SharedInfo.SkipNextFun > 0) + SharedInfo.SkipNextFun = SharedInfo.SkipNextFun - 1; + return; +end + +// #RNU_RES_B +// Exit if the function is a precision specifier and the corresponding flag is 1. +// #RNU_RES_E +if ((sum(mtlb_strcmp(FunctionName,SharedInfo.Annotations.DataPrec)) > 0) & ... + (SharedInfo.SkipNextPrec == 1)) + // #RNU_RES_B + PrintStringInfo(' Skipping code generating because already generated in the previous function.',ReportFileName,'file','y'); + // #RNU_RES_E + SharedInfo.SkipNextPrec = SharedInfo.SkipNextPrec - 1; + return; +end + +// #RNU_RES_B +// Exit if the function is OpEqual and the corresponding skip flag is enabled. +// #RNU_RES_E +if ((mtlb_strcmp(FunctionName,'OpEqual')) & ... + (SharedInfo.SkipNextEqual == 1)) + // #RNU_RES_B + PrintStringInfo(' Skipping code generating because already generated in the previous function.',ReportFileName,'file','y'); + // #RNU_RES_E + SharedInfo.SkipNextEqual = SharedInfo.SkipNextEqual - 1; + return; +end + +// #BJ +// size should be managed as other functions +// otherwise size(4) will lead to a C variable __4Size reference +// wich will never exists + +// #RNU_RES_B +// Exit if the function is size. +// #RNU_RES_E +// if ((mtlb_strcmp(FunctionName,'size'))) +// // #RNU_RES_B +// PrintStringInfo(' Anticipated exit for the size function.',ReportFileName,'file','y'); +// // #RNU_RES_E +// CCall =''; +// if (NInArg == 1) +// if (NOutArg == 1) +// CCall = CCall+OutArg(1).Name+'[0] = __'+InArg(1).Name+'Size[0];'; +// // #RNU_RES_B +// PrintStringInfo(' '+CCall,ReportFileName,'file','y'); +// // #RNU_RES_E +// PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y'); + +// CCall =''; +// CCall = CCall+OutArg(1).Name+'[1] = __'+InArg(1).Name+'Size[1];'; +// // #RNU_RES_B +// PrintStringInfo(' '+CCall,ReportFileName,'file','y'); +// // #RNU_RES_E +// PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y'); +// elseif (NOutArg == 2) +// CCall = CCall+OutArg(1).Name+' = __'+InArg(1).Name+'Size[0];'; +// // #RNU_RES_B +// PrintStringInfo(' '+CCall,ReportFileName,'file','y'); +// // #RNU_RES_E +// PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y'); + +// CCall =''; +// CCall = CCall+OutArg(2).Name+' = __'+InArg(1).Name+'Size[1];'; +// // #RNU_RES_B +// PrintStringInfo(' '+CCall,ReportFileName,'file','y'); +// // #RNU_RES_E +// PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y'); +// else +// SCI2Cerror('Don''t know how to manage size function with number of output args different from 1 and 2.'); +// end +// elseif (NInArg == 2) +// if (NOutArg == 1) +// if (InArg(2).Value == 1) +// CCall = CCall+OutArg(1).Name+' = __'+InArg(1).Name+'Size[0];'; +// // #RNU_RES_B +// PrintStringInfo(' '+CCall,ReportFileName,'file','y'); +// // #RNU_RES_E +// PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y'); +// elseif (InArg(2).Value == 2) +// CCall = CCall+OutArg(1).Name+' = __'+InArg(1).Name+'Size[1];'; +// // #RNU_RES_B +// PrintStringInfo(' '+CCall,ReportFileName,'file','y'); +// // #RNU_RES_E +// PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y'); +// else +// SCI2Cerror('Not known the value of the second input arg for the size function.'); +// end +// else +// SCI2Cerror('Don''t know how to manage size function with number of output args different from 1.'); +// end +// else +// SCI2Cerror('Don''t know how to manage size function with number of input args different from 1 and 2.'); +// end +// return; +// end +// ------------------------------------------------------ +// --- End Manage anticipated exit from the function. --- +// ------------------------------------------------------ + +// #RNU_RES_B +// ------------------------------------------------------------ +// --- Allocate memory and size array for output arguments. --- +// ------------------------------------------------------------ +// #RNU_RES_E +if (FlagCall == 1) +// #RNU_RES_B +//RNU qui va tolto tutto una volta sicuri che la memallocout puo' essere fatta dentro la st_insoutarg +// C_MemAllocOutTempVars(OutArg,NOutArg,CPass1FileName,CPass1FreeFileName,IndentLevel,ReportFileName); +// #RNU_RES_E +end + +// ---------------------------- +// --- Generate the C call. --- +// ---------------------------- +CCall =''; +if(mtlb_strcmp(part(CFunName,1:9),'PI_thread') == %T) +//Functions that are to be ru in separate thread in case of RPi target, +//need to have specific name which is PI_THREAD(functionname) + +CCall = CCall + 'PI_THREAD('+CFunName+')' +else + + if (FunInfo.CFunctionName == SharedInfo.CMainFunName) + if (FlagCall == 1) + error(9999, 'main function called in a source code!'); + 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) + CCall = CCall+OutArg(PosFirstOutScalar).Name+' = '; + else + CCall = CCall+C_Type(OutArg(PosFirstOutScalar).Type)+' '; + end + else + if (FlagCall == 0) + CCall = CCall+'void '; + end + end + end + + + // FIXME : Wrap library function call with prefixed name + + //if CFunName == "main" + CCall = CCall + CFunName + "("; + //else + // CCall = CCall+"SCI2C("+CFunName+")("; + //end + + // #RNU_RES_B + PrintStringInfo(' C call after output scalar args check: '+CCall,ReportFileName,'file','y'); + // #RNU_RES_E + clear counterin + if(mtlb_strcmp(part(CFunName,1:5),'odefn') == %F) + 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 + 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 + 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((NInArg == 4 & counterin <> 3) | (NInArg == 5 & counterin <> 4)) //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 + for counterout = 1:NOutArg + TmpOutArgName = OutArg(counterout).Name; + TmpOutArgType = C_Type(OutArg(counterout).Type); + if (counterout == PosFirstOutScalar) + if (FlagCall == 0) + // #RNU_RES_B + // --- Write in the declaration file the returned output scalar (if any). --- + // #RNU_RES_E + outscalardeclaration = TmpOutArgType+' '+TmpOutArgName+';'; + // #RNU_RES_B + PrintStringInfo(outscalardeclaration,ReportFileName,'file','y'); + // #RNU_RES_E + PrintStringInfo(C_IndentBlanks(1)+outscalardeclaration,CDeclarationFileName,'file','y'); + PrintStringInfo(' ',CDeclarationFileName,'file','y'); + end + else + if (OutArg(counterout).Dimension == 0) + if (FlagCall == 0) + // --- Write in the declaration file the returned output scalar (if any). --- + outscalardeclaration = TmpOutArgType+' '+TmpOutArgName+';'; + PrintStringInfo(outscalardeclaration,ReportFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(1)+outscalardeclaration,CDeclarationFileName,'file','y'); + PrintStringInfo(' ',CDeclarationFileName,'file','y'); + CCall = CCall+TmpOutArgType+'* __ptr'+TmpOutArgName+', '; + else + CCall = CCall+'&'+TmpOutArgName+', ';//NUT: verifica se ci vuole l'& + end + else + if (FlagCall == 0) + CCall = CCall+TmpOutArgType+'* '+TmpOutArgName+','; + if (OutArg(counterout).FindLike == 1) + CCall = CCall+'int* __'+TmpOutArgName+'Size'+','; + end + // #RNU_RES_B + //NUT prova a sostituire le variabili strutture con variabili dichiarate all'inizio del codice. + // --- Declare the size of the output arguments. --- + // #RNU_RES_E + outscalardeclaration = 'int __'+TmpOutArgName+'Size[2];'; + PrintStringInfo(outscalardeclaration,ReportFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(1)+outscalardeclaration,CDeclarationFileName,'file','y'); + outscalardeclaration = '__'+TmpOutArgName+'Size[0] = '+(OutArg(counterout).Size(1))+';'; + PrintStringInfo(outscalardeclaration,ReportFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(1)+outscalardeclaration,CInitVarsFileName,'file','y'); + outscalardeclaration = '__'+TmpOutArgName+'Size[1] = '+(OutArg(counterout).Size(2))+';'; + PrintStringInfo(outscalardeclaration,ReportFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(1)+outscalardeclaration,CInitVarsFileName,'file','y'); + PrintStringInfo(' ',CInitVarsFileName,'file','y'); + else + CCall = CCall+OutArg(counterout).Name+','; + if (OutArg(counterout).FindLike == 1) + CCall = CCall+'(int* ) __'+TmpOutArgName+'Size'+','; + end + end + end + end + end + PrintStringInfo(' C call after output args analysis: '+CCall,ReportFileName,'file','y'); + // Remove the last " " and "," + if (part(CCall,length(CCall):length(CCall)) == ' ') + CCall = part(CCall,1:length(CCall)-1); + end + 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+';'; + end + +end +//NUT: la parte di generazione della C call va inserita in una funzione a parte. +//NUT: tale funzione deve avere anche uno switch che consenta di generare differenti versioni +//NUT: delle chiamate C in accordo con la libreria disponibile, fermo restando che +//NUT: e' sempre possibile fornire la lista delle macro. +if mtlb_strcmp(FunctionName,'return') + // Here I introduce the pointer assignment for output scalar arguments. + for cntout = 1:SharedInfo.CurrentFunInfo.NOutArg + if (cntout ~= SharedInfo.CurrentFunInfo.PosFirstOutScalar & ... + SharedInfo.CurrentFunInfo.OutArg(cntout).Dimension == 0) + CCall = ''; + CCall = CCall+'*__ptr'+SharedInfo.CurrentFunInfo.OutArg(cntout).Name+' = '+... + SharedInfo.CurrentFunInfo.OutArg(cntout).Name+';'; + PrintStringInfo(' '+CCall,ReportFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y'); + end + end + // --- Then I free the memory dinamically allocated. --- + // ---------------------------- + // --- Handle Free section. --- + // ---------------------------- + PrintStringInfo(C_IndentBlanks(1)+'/*',CPass1FreeFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(1)+'** ------------------------- ',CPass1FreeFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(1)+'** --- End Free Section. --- ',CPass1FreeFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(1)+'** ------------------------- ',CPass1FreeFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(1)+'*/',CPass1FreeFileName,'file','y'); + PrintStringInfo(' ',CPass1FreeFileName,'file','y'); + SCI2Ccopyfile(CPass1FreeFileName,... + CPass1FileName,'append'); + // -------------------------------- + // --- End Handle Free section. --- + // -------------------------------- + + // --- Then I introduce the return to the first scalar output arguments. --- + CCall = ''; + // #RNU_RES_B + //NUT: non capisco questo skip a questo punto. + //NUT: perche' la return finale la sto gestendo nella AST_HandleEndProgram. + 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+');' + end + end + // #RNU_RES_B + PrintStringInfo(' '+CCall,ReportFileName,'file','y'); + // #RNU_RES_E + PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y'); +else + // #RNU_RES_B + PrintStringInfo(' '+CCall,ReportFileName,'file','y'); + // #RNU_RES_E + PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y'); + if (FlagCall == 0) + // Add prototype to the header file + + C_InitHeader(CCall+';',HeaderFileName,SharedInfo.Sci2CLibMainHeaderFName,Target,SharedInfo.OpenCVUsed); + + // Add { at the beginning of the function. + PrintStringInfo(' {',ReportFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(IndentLevel)+'{',CPass1FileName,'file','y'); + + end +end + +// #RNU_RES_B +// Add in the C code the new size of the output argument when SCI2Cresize function is called. +// #RNU_RES_E +if (FunctionName == 'SCI2Cresize') + // #RNU_RES_B + PrintStringInfo(' Found SCI2Cresize -> Changing the size of the output argument.',ReportFileName,'file','y'); + // #RNU_RES_E + OutArgName = OutArg(counterout).Name; + tmpcode = '__'+OutArgName+'Size[0]='+OutArg(counterout).Size(1)+';'; + PrintStringInfo(C_IndentBlanks(IndentLevel)+tmpcode,CPass1FileName,'file','y'); + // #RNU_RES_B + PrintStringInfo(' '+tmpcode,ReportFileName,'file','y'); + // #RNU_RES_E + tmpcode = '__'+OutArgName+'Size[1]='+OutArg(counterout).Size(2)+';'; + PrintStringInfo(C_IndentBlanks(IndentLevel)+tmpcode,CPass1FileName,'file','y'); + // #RNU_RES_B + PrintStringInfo(' '+tmpcode,ReportFileName,'file','y'); + // #RNU_RES_E +end +endfunction diff --git a/macros/CCodeGeneration/C_GenDeclarations.sci b/macros/CCodeGeneration/C_GenDeclarations.sci new file mode 100644 index 0000000..41ba3a9 --- /dev/null +++ b/macros/CCodeGeneration/C_GenDeclarations.sci @@ -0,0 +1,135 @@ +function Cdeclaration = C_GenDeclarations(ArgStruct,CDeclarationFileName,IndentLevel,ReportFileName,FlagExt,ResizeApproach) +// function Cdeclaration = C_GenDeclarations(ArgStruct,CDeclarationFileName,IndentLevel,ReportFileName,FlagExt,ResizeApproach) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 27-Oct-2007 -- Raffaele Nutricato: Author. +// 10-Jun-2008 -- Raffaele Nutricato: adapted to work with realloc function. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// Generate C corresponding declaration given some information in ArgStruct +// + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ + 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. + +PrintStringInfo(' ',ReportFileName,'file','y'); +PrintStringInfo('***Generating C declaration***',ReportFileName,'file','y'); +// #RNU_RES_E + +Cdeclaration = ''; +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)+'};'; + 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 (ArgStruct.Type == 'fn') + //do nothing. This is a function name. Will be declared in header file. + 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); + 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 + end + end + Cdeclaration(1) = Cdeclaration(1)+';'; + end +end + + +// -------------------------------------------- +// --- Write C declaration into the C file. --- +// -------------------------------------------- +for cntdecl = 1:size(Cdeclaration, '*') + PrintStringInfo(' '+Cdeclaration(cntdecl),ReportFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(IndentLevel)+Cdeclaration(cntdecl),CDeclarationFileName,'file','y'); +end + +PrintStringInfo(' Writing C declaration in: '+CDeclarationFileName,ReportFileName,'file','y'); +PrintStringInfo(' ',CDeclarationFileName,'file','y'); + +endfunction +// #RNU_RES_B +//NUT: dove sta il controllo che verifica se dopo aver dichiarato una local A[10] essa viene utilizzata +//NUT: per memorizzare un A = sin(B) dove B[11]?? +// #RNU_RES_E diff --git a/macros/CCodeGeneration/C_GenerateFunName.sci b/macros/CCodeGeneration/C_GenerateFunName.sci new file mode 100644 index 0000000..a1373de --- /dev/null +++ b/macros/CCodeGeneration/C_GenerateFunName.sci @@ -0,0 +1,56 @@ +function CFunName = C_GenerateFunName(FunctionName,InArg,NInArg,OutArg,NOutArg) +// function CFunName = C_GenerateFunName(FunctionName,InArg,NInArg,OutArg,NOutArg) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// 26-Oct-2007 -- Alberto Morea: Test Ok. +// 11-Nov-2007 -- Raffaele Nutricato: changed naming rule. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),5,5); +CFunName = ''; +if((IsAVRSupportFunction(FunctionName)) | (IsRPISupportFunction(FunctionName)) | ... + (mtlb_strcmp(part(FunctionName,1:5),'odefn') == %T) |... + (mtlb_strcmp(part(FunctionName,1:9),'PI_thread') == %T)| ... + (mtlb_strcmp(part(FunctionName,1:4),'ISR_') == %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 +//Slimilarly for functions conataining ode functions and functions to be called in +//separate thread in RPi + CFunName = CFunName+FunctionName; + +else + for tmpcnt = 1:NInArg + if (InArg(tmpcnt).Dimension == 1) + CFunName = CFunName+InArg(tmpcnt).Type+'2'; + else + CFunName = CFunName+InArg(tmpcnt).Type+SCI2Cstring(InArg(tmpcnt).Dimension); + end + end + + CFunName = CFunName+FunctionName; + + for tmpcnt = 1:NOutArg + if (OutArg(tmpcnt).Dimension == 1) + CFunName = CFunName+OutArg(tmpcnt).Type+'2'; + else + CFunName = CFunName+OutArg(tmpcnt).Type+SCI2Cstring(OutArg(tmpcnt).Dimension); + end + end + +end +endfunction diff --git a/macros/CCodeGeneration/C_GenerateLaunchScript.sci b/macros/CCodeGeneration/C_GenerateLaunchScript.sci new file mode 100644 index 0000000..027d4c7 --- /dev/null +++ b/macros/CCodeGeneration/C_GenerateLaunchScript.sci @@ -0,0 +1,86 @@ +function C_GenerateLaunchScript(OutDir,ListSCI2CInputPrmFiles) +// function C_GenerateLaunchScript(OutDir,ListSCI2CInputPrmFiles) +// ----------------------------------------------------------------- +// #RNU_RES_B +// Generate the script that can be used to compile all the regression +// tests and to run them and finally to write results in the report +// file. +// #RNU_RES_E +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 26-Jan-2008 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +ScriptFileName = fullfile(OutDir,'LaunchRegressionTests.rc'); +NTranslations = size(ListSCI2CInputPrmFiles,1); +// --------------------------- +// --- End Initialization. --- +// --------------------------- +SCI2Cmdelete(ScriptFileName); +PrintStringInfo('#! /bin/bash ',ScriptFileName,'file','y'); +PrintStringInfo(' ',ScriptFileName,'file','y'); +PrintStringInfo('maindir=$PWD',ScriptFileName,'file','y'); +PrintStringInfo(' ',ScriptFileName,'file','y'); +PrintStringInfo('INTIALIZE()',ScriptFileName,'file','y'); +PrintStringInfo('{',ScriptFileName,'file','y'); +PrintStringInfo(' reportfile=$maindir/RegressionTestsReport.txt',ScriptFileName,'file','y'); +PrintStringInfo(' echo ""#############'+'#################"" > $reportfile',ScriptFileName,'file','y'); +PrintStringInfo(' echo ""REPORT OF THE REGRESSION TESTS"" > $reportfile',ScriptFileName,'file','y'); +PrintStringInfo(' echo ""#############'+'#################"" > $reportfile',ScriptFileName,'file','y'); +PrintStringInfo(' echo ""Author: Raffaele Nutricato"" > $reportfile',ScriptFileName,'file','y'); +PrintStringInfo(' echo ""Copyright 2008 Raffaele Nutricato"" > $reportfile',ScriptFileName,'file','y'); +PrintStringInfo(' echo "" "" > $reportfile',ScriptFileName,'file','y'); +PrintStringInfo(' cd $maindir ',ScriptFileName,'file','y'); +PrintStringInfo('}',ScriptFileName,'file','y'); +PrintStringInfo(' ',ScriptFileName,'file','y'); +PrintStringInfo('EXECUTE()',ScriptFileName,'file','y'); +PrintStringInfo('{',ScriptFileName,'file','y'); +PrintStringInfo(' echo ""xxxxxxxxxxxxxx'+'xxxxxxxxxxxxxxxxxx'+'xxxxxxxxxxxx""',ScriptFileName,'file','y'); +PrintStringInfo(' echo "" "" >> $reportfile',ScriptFileName,'file','y'); +PrintStringInfo(' echo "" "" >> $reportfile',ScriptFileName,'file','y'); +PrintStringInfo(' echo "" "" >> $reportfile',ScriptFileName,'file','y'); +PrintStringInfo(' echo ""xxxxxxxxxxxxxx'+'xxxxxxxxxxxxxxxxxxxxxxx'+'xxxxxxx"" >> $reportfile',ScriptFileName,'file','y'); +PrintStringInfo(' echo $testname ',ScriptFileName,'file','y'); +PrintStringInfo(' echo $testname >> $reportfile',ScriptFileName,'file','y'); +PrintStringInfo(' echo ""xxxxxxxxxxxxxxx'+'xxxxxxxxxxxxxxxxx'+'xxxxxxxxxxxx"" ',ScriptFileName,'file','y'); +PrintStringInfo(' echo ""xxxxxxxxxxxxxxxx'+'xxxxxxxxxxxxxxxxxxxx'+'xxxxxxxx"" >> $reportfile',ScriptFileName,'file','y'); +PrintStringInfo(' cd $testname/C_Code',ScriptFileName,'file','y'); +PrintStringInfo(' make >> $reportfile',ScriptFileName,'file','y'); +PrintStringInfo(' cd $maindir',ScriptFileName,'file','y'); +PrintStringInfo(' echo "" "" >> $reportfile',ScriptFileName,'file','y'); +PrintStringInfo(' echo "" "" >> $reportfile',ScriptFileName,'file','y'); +PrintStringInfo(' echo "" "" >> $reportfile',ScriptFileName,'file','y'); +PrintStringInfo('}',ScriptFileName,'file','y'); +PrintStringInfo(' ',ScriptFileName,'file','y'); +PrintStringInfo('#############'+'##############',ScriptFileName,'file','y'); +PrintStringInfo('### ADD YOUR TESTS HERE ###',ScriptFileName,'file','y'); +PrintStringInfo('##############'+'#############',ScriptFileName,'file','y'); +PrintStringInfo('INTIALIZE',ScriptFileName,'file','y'); +PrintStringInfo(' ',ScriptFileName,'file','y'); + +for cnttransl = 1:NTranslations + [testpath,tmpname,tmpext] = fileparts(ListSCI2CInputPrmFiles(cnttransl)); + testpath = ConvertPathMat2C(testpath,'cygwin'); + PrintStringInfo('testname=""'+testpath+'""',ScriptFileName,'file','y'); + PrintStringInfo('EXECUTE $testname',ScriptFileName,'file','y'); + PrintStringInfo(' ',ScriptFileName,'file','y'); +end + +endfunction diff --git a/macros/CCodeGeneration/C_GenerateMakefile.sci b/macros/CCodeGeneration/C_GenerateMakefile.sci new file mode 100644 index 0000000..7dfb4da --- /dev/null +++ b/macros/CCodeGeneration/C_GenerateMakefile.sci @@ -0,0 +1,146 @@ +//Removed 4 lines code from end that causes ot generate the Makefile.mak file that is not needed with cygwin +//Changed at line 52 +function C_GenerateMakefile(FileInfo,SharedInfo) +// function C_GenerateMakefile(FileInfo,SharedInfo) +// ----------------------------------------------------------------- +// Generate the makefile. +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 26-Jan-2008 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +PrintStepInfo('Generating Builder '+FileInfo.MakefileFilename,... + FileInfo.GeneralReport,'both'); + +target = SharedInfo.Target; +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +PrintStringInfo('# SCI2C Makefile',FileInfo.MakefileFilename,'file','y'); +PrintStringInfo('# hArtes EU Project.',FileInfo.MakefileFilename,'file','y'); +PrintStringInfo('# Authors: PoliBa & Inria',FileInfo.MakefileFilename,'file','y'); +PrintStringInfo('# -----------------------',FileInfo.MakefileFilename,'file','y'); +PrintStringInfo('# --- USER PARAMETERS ---',FileInfo.MakefileFilename,'file','y'); +PrintStringInfo('# -----------------------',FileInfo.MakefileFilename,'file','y'); +PrintStringInfo('# --- DIRECTORIES AND FILES ---',FileInfo.MakefileFilename,'file','y'); + +makecsrcdir = pathconvert('src/c', %f, %f, 'u'); +makehsrcdir = pathconvert('includes', %f, %f, 'u'); +makeisrcdir = pathconvert('interfaces', %f, %f, 'u'); +makelibdir = pathconvert('libraries', %f, %f, 'u'); +makesci2cdir = FileInfo.CStyleOutCCCodeDir; + + +PrintStringInfo('CSRCDIR = '+makecsrcdir,FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('HSRCDIR = '+makehsrcdir,FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('ISRCDIR = '+makeisrcdir,FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('LIBDIR = '+makelibdir,FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('SCI2CDIR = .',FileInfo.MakefileFilename,'file','y','y'); + +if getos() == 'Windows' then + + // Compiler definition + PrintStringInfo('CC = gcc',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('CXX = g++',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('CFLAGS = -Wall -pedantic -g -I $(HSRCDIR) -I $(ISRCDIR)',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('CXXFLAGS = -Wall -pedantic -g -I $(HSRCDIR) -I $(ISRCDIR)',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('LDFLAGS = -L./ -lblasplus -llapack -lm',FileInfo.MakefileFilename,'file','y','y'); //Added -L./ and -lblasplus(previously it was -lblas) + +else + if (target == 'RPi') + PrintStringInfo('CC = arm-linux-gnueabihf-gcc ',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('CXX = arm-linux-gnueabihf-g++ ',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('CFLAGS = -Wall -pedantic -g -I $(HSRCDIR) -I $(ISRCDIR) -L $(LIBDIR)',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('CXXFLAGS = -Wall -pedantic -g -I $(HSRCDIR) -I $(ISRCDIR) -L $(LIBDIR)',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('LDFLAGS = -llapack -lrefblas -lgfortran -lwiringPi',FileInfo.MakefileFilename,'file','y','y'); + else + PrintStringInfo('CC = gcc',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('CXX = g++',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('CFLAGS = -Wall -pedantic -g -I $(HSRCDIR) -I $(ISRCDIR) -L $(LIBDIR)',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('CXXFLAGS = -Wall -pedantic -g -I $(HSRCDIR) -I $(ISRCDIR) -L $(LIBDIR)',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('LDFLAGS = -lblas -llapack -lm ',FileInfo.MakefileFilename,'file','y','y'); + end + if(SharedInfo.OpenCVUsed == %T) + PrintStringInfo('LDFLAGS += -lopencv_calib3d -lopencv_contrib -lopencv_features2d -lopencv_flann -lopencv_gpu',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('LDFLAGS += -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('LDFLAGS += -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('LDFLAGS += -lopencv_ts -lopencv_video -lopencv_videostab -lopencv_core -lrt -lpthread -lm -ldl', FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('LDFLAGS += -lIlmImf -ljpeg -ljasper -ltiff -lpng -lzlib -lstdc++',FileInfo.MakefileFilename,'file','y','y'); + end +end +//If ode function is used, add libgsl. +if(size(SharedInfo.Includelist) <> 0) + if((mtlb_strcmp(part(SharedInfo.Includelist(1),1:5),'odefn') == %T)) + PrintStringInfo('LDFLAGS += -lgsl',FileInfo.MakefileFilename,'file','y','y'); + end +end + +// Binary definition +PrintStringInfo('EXEFILENAME = '+SharedInfo.SCIMainFunName,FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('EXEFILE = $(SCI2CDIR)/$(EXEFILENAME)', FileInfo.MakefileFilename,'file','y','y'); + +// Sources +//Check the output format selected and insert files according to it +PrintStringInfo('SRC = $(wildcard $(CSRCDIR)/*.c)', FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('SRCC = $(wildcard $(CSRCDIR)/*.cpp)', FileInfo.MakefileFilename,'file','y','y'); + +// Objects +PrintStringInfo('OBJ = $(SRC:.c=.o)', FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('OBJC = $(SRCC:.cpp=.o)', FileInfo.MakefileFilename,'file','y','y'); + +// Rules +PrintStringInfo('# ---------------',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('# --- TARGETS ---',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('# ---------------',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('compileexecute: $(OBJ) $(OBJC)',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo "" ""',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""============================""',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""Generation of the executable""',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""============================""',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t$(CXX) $(CFLAGS) $(OBJ) $(OBJC) *.c $(LDFLAGS) -o $(EXEFILE)',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo "" ""',FileInfo.MakefileFilename,'file','y','y'); +if(target == "StandAlone") + PrintStringInfo('\t@echo ""==============""',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('\t@echo ""Executing code""',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('\t@echo ""==============""',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('\t$(EXEFILE)',FileInfo.MakefileFilename,'file','y','y'); +end +PrintStringInfo('clean:',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo "" ""',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""=============================""',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""Removing only exe + obj files""',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""=============================""',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\trm -rf $(EXEFILE)',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\trm -rf $(OBJ)',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\trm -rf $(OBJC)',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo "" ""',FileInfo.MakefileFilename,'file','y','y'); + +PrintStringInfo('distclean: clean',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo "" ""',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""==========================""',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""Removing only the exe file""',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""==========================""',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\trm -rf $(EXEFILE)',FileInfo.MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo "" ""',FileInfo.MakefileFilename,'file','y','y'); + + + +endfunction diff --git a/macros/CCodeGeneration/C_GenerateMakefile_msvc.sci b/macros/CCodeGeneration/C_GenerateMakefile_msvc.sci new file mode 100644 index 0000000..00ffb63 --- /dev/null +++ b/macros/CCodeGeneration/C_GenerateMakefile_msvc.sci @@ -0,0 +1,131 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2010-2010 - DIGITEO - Allan CORNET +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// +// + +function C_GenerateMakefile_msvc(FileInfo, SharedInfo) +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +MakefileFilename = FileInfo.MakefileFilename + '.mak'; + +// ----------------------- +// --- Initialization. --- +// ----------------------- +PrintStepInfo('Generating Builder '+MakefileFilename,... + FileInfo.GeneralReport,'both'); + +target = SharedInfo.Target; + +PrintStringInfo('# SCI2C Makefile (Visual Studio 2008)',MakefileFilename,'file','y','y'); +PrintStringInfo('# hArtes EU Project.',MakefileFilename,'file','y','y'); +PrintStringInfo('# Authors: PoliBa & Inria & DIGITEO',MakefileFilename,'file','y','y'); +PrintStringInfo('# -----------------------',MakefileFilename,'file','y','y'); +PrintStringInfo('# --- USER PARAMETERS ---',MakefileFilename,'file','y','y'); +PrintStringInfo('# -----------------------',MakefileFilename,'file','y','y'); +PrintStringInfo('# --- DIRECTORIES AND FILES ---',MakefileFilename,'file','y','y'); + +makecsrcdir = pathconvert('src/c', %f, %f, 'u'); +makehsrcdir = pathconvert('includes', %f, %f, 'u'); +makeisrcdir = pathconvert('interfaces', %f, %f, 'u'); +makelibdir = pathconvert('libraries', %f, %f, 'u'); +makesci2cdir = FileInfo.CStyleOutCCCodeDir; + +PrintStringInfo('CSRCDIR = '+makecsrcdir,MakefileFilename,'file','y','y'); +PrintStringInfo('HSRCDIR = '+makehsrcdir,MakefileFilename,'file','y','y'); +PrintStringInfo('ISRCDIR = '+makeisrcdir,MakefileFilename,'file','y','y'); +PrintStringInfo('SCI2CDIR = .',MakefileFilename,'file','y','y'); + +PrintStringInfo('DIR_OBJ=Release',MakefileFilename,'file','y','y'); +//PrintStringInfo('LAPACK_LIB =$(SCI2CDIR)/libraries/lapack.lib',MakefileFilename,'file','y','y'); +//PrintStringInfo('BLAS_LIB = $(SCI2CDIR)/libraries/blasplus.lib',MakefileFilename,'file','y','y'); +PrintStringInfo('LIB_PATH = $(SCI2CDIR)/libraries',MakefileFilename,'file','y','y'); +PrintStringInfo('LIBS = lapack.lib blasplus.lib',MakefileFilename,'file','y','y'); +PrintStringInfo('LIBS = $(LIBS) kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib',MakefileFilename,'file','y','y'); +PrintStringInfo('CC = cl',MakefileFilename,'file','y','y'); +PrintStringInfo('LINKER = link',MakefileFilename,'file','y','y'); +PrintStringInfo('LINKER_OPTIMISATION_MODE=/RELEASE ',MakefileFilename,'file','y','y'); +PrintStringInfo('CC__OPTIMISATION_MODE=-Z7 -O2 -MT',MakefileFilename,'file','y','y'); +PrintStringInfo('CC_OPTIONS = $(CC_COMMON) -W3 -Gd $(CC__OPTIMISATION_MODE) /Fo""$(DIR_OBJ)/"" /Fd""$(DIR_OBJ)/"" ',MakefileFilename,'file','y','y'); +PrintStringInfo('CFLAGS = $(CC_OPTIONS) -I""$(HSRCDIR)"" -I""$(ISRCDIR)"" /EHsc /TP ',MakefileFilename,'file','y','y'); +PrintStringInfo('EXEFILENAME = '+SharedInfo.SCIMainFunName,MakefileFilename,'file','y','y'); +PrintStringInfo('EXEFILE = $(SCI2CDIR)\\$(EXEFILENAME)',MakefileFilename,'file','y','y'); +PrintStringInfo('MAIN_SRC = $(SCI2CDIR)/main.c',MakefileFilename,'file','y','y'); + +if(SharedInfo.OpenCVUsed == %T) + PrintStringInfo('LIBS = $(LIBS) opencv_calib3d2413.lib opencv_contrib2413.lib opencv_features2d2413.lib',MakefileFilename,'file','y','y'); + PrintStringInfo('LIBS = $(LIBS) opencv_flann2413.lib opencv_gpu2413.lib opencv_highgui2413.lib ',MakefileFilename,'file','y','y'); + PrintStringInfo('LIBS = $(LIBS) opencv_imgproc2413.lib opencv_legacy2413.lib opencv_ml2413.lib opencv_nonfree2413.lib',MakefileFilename,'file','y','y'); + PrintStringInfo('LIBS = $(LIBS) opencv_objdetect2413.lib opencv_ocl2413.lib opencv_photo2413.lib opencv_stitching2413.lib',MakefileFilename,'file','y','y'); + PrintStringInfo('LIBS = $(LIBS) opencv_superres2413.lib opencv_ts2413.lib opencv_video2413.lib opencv_videostab2413.lib opencv_core2413.lib',MakefileFilename,'file','y','y'); + PrintStringInfo('LIBS = $(LIBS) IlmImf.lib libjpeg.lib libjasper.lib libtiff.lib libpng.lib zlib.lib',MakefileFilename,'file','y','y'); +end +// Sources +PrintStringInfo('SRC = $(CSRCDIR)/*.c', MakefileFilename,'file','y','y'); +PrintStringInfo('SRCC = $(CSRCDIR)/*.cpp', MakefileFilename,'file','y','y'); + +//PrintStringInfo('SRC = \\', MakefileFilename,'file','y','y'); +//allSources = getAllSources(); +//nbSources = size(allSources); +//for i = 1:(nbSources(1) - 1) +// [tmppath,tmpfile,tmpext] = fileparts(allSources(i)); +// PrintStringInfo(' $(CSRCDIR)/'+tmpfile+tmpext+' \\', MakefileFilename,'file','y','y'); +//end +//[tmppath,tmpfile,tmpext] = fileparts(allSources(nbSources(1))); +//PrintStringInfo(' $(CSRCDIR)/'+tmpfile+tmpext, MakefileFilename,'file','y','y'); + +PrintStringInfo('OBJ = $(SRC:.c=.obj) $(MAIN_SRC:.c=.obj)',MakefileFilename,'file','y','y'); +PrintStringInfo('OBJC = $(SRCC:.cpp=.o)', MakefileFilename,'file','y','y'); +PrintStringInfo('# ---------------',MakefileFilename,'file','y','y'); +PrintStringInfo('# --- TARGETS ---',MakefileFilename,'file','y','y'); +PrintStringInfo('# ---------------',MakefileFilename,'file','y','y'); +PrintStringInfo('compileexecute: ',MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo "" ""',MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""============================""',MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""Generation of the executable""',MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""============================""',MakefileFilename,'file','y','y'); +PrintStringInfo('\t-IF NOT EXIST $(DIR_OBJ) mkdir $(DIR_OBJ)',MakefileFilename,'file','y','y'); +PrintStringInfo('\t$(CC) $(CFLAGS) $(SRC) $(SRCC) $(MAIN_SRC) /link /LIBPATH:$(LIB_PATH) $(LIBS) /out:$(EXEFILE).exe',MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo "" ""',MakefileFilename,'file','y','y'); +if(target == "StandAlone") + PrintStringInfo('\t@echo ""==============""',MakefileFilename,'file','y','y'); + PrintStringInfo('\t@echo ""Executing code""',MakefileFilename,'file','y','y'); + PrintStringInfo('\t@echo ""==============""',MakefileFilename,'file','y','y'); + PrintStringInfo('\t$(EXEFILE).exe',MakefileFilename,'file','y','y'); +end +PrintStringInfo('clean:',MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo "" ""',MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""=============================""',MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""Removing only exe + obj files""',MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""=============================""',MakefileFilename,'file','y','y'); +PrintStringInfo('\t-del ""$(DIR_OBJ)\*.obj""',MakefileFilename,'file','y','y'); +PrintStringInfo('\t-rmdir ""$(DIR_OBJ)""',MakefileFilename,'file','y','y'); +PrintStringInfo('\t-del $(EXEFILE).exe',MakefileFilename,'file','y','y'); +PrintStringInfo('\t-del $(EXEFILE).exp',MakefileFilename,'file','y','y'); +PrintStringInfo('\t-del $(EXEFILE).lib',MakefileFilename,'file','y','y'); +PrintStringInfo('\t-del $(EXEFILE).pdb',MakefileFilename,'file','y','y'); +PrintStringInfo('\t-del $(EXEFILE).ilk',MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo "" ""',MakefileFilename,'file','y','y'); +PrintStringInfo('distclean: clean',MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo "" ""',MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""==========================""',MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""Removing only the exe file""',MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo ""==========================""',MakefileFilename,'file','y','y'); +PrintStringInfo('\t-del $(EXEFILE).exe',MakefileFilename,'file','y','y'); +PrintStringInfo('\t-del $(EXEFILE).exp',MakefileFilename,'file','y','y'); +PrintStringInfo('\t-del $(EXEFILE).lib',MakefileFilename,'file','y','y'); +PrintStringInfo('\t-del $(EXEFILE).pdb',MakefileFilename,'file','y','y'); +PrintStringInfo('\t-del $(EXEFILE).ilk',MakefileFilename,'file','y','y'); +PrintStringInfo('\t@echo "" ""',MakefileFilename,'file','y','y'); + + +endfunction
\ No newline at end of file diff --git a/macros/CCodeGeneration/C_GenerateMkfle_arduino.sci b/macros/CCodeGeneration/C_GenerateMkfle_arduino.sci new file mode 100644 index 0000000..c66b976 --- /dev/null +++ b/macros/CCodeGeneration/C_GenerateMkfle_arduino.sci @@ -0,0 +1,24 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE + +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Author: Yash Pratap Singh Tomar +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + + +function C_GenerateMkfle_arduino(FileInfo,SharedInfo) + + PrintStringInfo('ARDUINO_DIR = /usr/share/arduino',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('ARDMK_DIR = /usr/share/arduino',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('AVR_TOOLS_DIR = /usr',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('BOARD_TAG = ' + SharedInfo.Board_name ,FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('USER_LIB_PATH = ../',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('ARDUINO_LIBS = ../src/c ../includes ../interfaces ../ Wire',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('ARDUINO_PORT = /dev/ttyACM0',FileInfo.MakefileFilename,'file','y','y'); + PrintStringInfo('include /usr/share/arduino/Arduino.mk',FileInfo.MakefileFilename,'file','y','y'); + +endfunction diff --git a/macros/CCodeGeneration/C_GenerateSCI2CHeader.sci b/macros/CCodeGeneration/C_GenerateSCI2CHeader.sci new file mode 100644 index 0000000..bced724 --- /dev/null +++ b/macros/CCodeGeneration/C_GenerateSCI2CHeader.sci @@ -0,0 +1,21 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2010-2010 - DIGITEO - Bruno JOFRET +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// +// +function C_GenerateSCI2CHeader(OutputPath, FunctionPrefix) + FileName = OutputPath+"scilab2c.h" + C_SCI2CHeader(FileName); + PrintStringInfo('#ifndef __SCILAB2C_H__',FileName,'file','y'); + PrintStringInfo('#define __SCILAB2C_H__',FileName,'file','y'); + PrintStringInfo('',FileName,'file','y'); + PrintStringInfo('#define SCI2C(Name) '+FunctionPrefix+'_##Name',FileName,'file','y'); + PrintStringInfo('',FileName,'file','y'); + PrintStringInfo('#endif /* !__SCILAB2C_H__ */',FileName,'file','y'); +endfunction diff --git a/macros/CCodeGeneration/C_IfElseBlocks.sci b/macros/CCodeGeneration/C_IfElseBlocks.sci new file mode 100644 index 0000000..92ac94f --- /dev/null +++ b/macros/CCodeGeneration/C_IfElseBlocks.sci @@ -0,0 +1,68 @@ +function SharedInfo = C_IfElseBlocks(FileInfo,SharedInfo,InOutStatements) +// function SharedInfo = C_IfElseBlocks(FileInfo,SharedInfo,InOutStatements) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 27-Oct-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),3,3); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; + +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +CPass1FileName = FileInfo.Funct(nxtscifunnumber).CPass1FileName; + +IndentLevel = SharedInfo.NIndent; + +// #RNU_RES_B +PrintStringInfo(' ',ReportFileName,'file','y'); +PrintStringInfo(' Generate ""{"" or ""}"" code for if/else statement',ReportFileName,'file','y'); +// #RNU_RES_E +CCall = ''; +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +// #RNU_RES_B +// ----------------------------------------------------- +// --- Generate the C call/Update indentation level. --- +// ----------------------------------------------------- +// #RNU_RES_E +if (InOutStatements=='in') + CCall = CCall+'{'; + PrintStringInfo(' '+CCall,ReportFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y'); + IndentLevel = IndentLevel + 1; +elseif (InOutStatements=='out') + CCall = CCall+'}'; + IndentLevel = IndentLevel - 1; + PrintStringInfo(' '+CCall,ReportFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y'); +else + error(9999, 'Unknown setting for InOutStatements: '+InOutStatements+'.'); +end + +// #RNU_RES_B +PrintStringInfo(' Updating indentation level to:'+string(IndentLevel),ReportFileName,'file','y'); +// #RNU_RES_E +SharedInfo.NIndent = IndentLevel; + +endfunction diff --git a/macros/CCodeGeneration/C_IfExpression.sci b/macros/CCodeGeneration/C_IfExpression.sci new file mode 100644 index 0000000..48a0538 --- /dev/null +++ b/macros/CCodeGeneration/C_IfExpression.sci @@ -0,0 +1,91 @@ +function SharedInfo = C_IfExpression(IfCondArg,NIfCondArg,ASTIfExpType,FileInfo,SharedInfo) +// function SharedInfo = C_IfExpression(IfCondArg,NIfCondArg,ASTIfExpType,FileInfo,SharedInfo) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 27-Oct-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),5,5); + +// --- Check NIfCondArg value. --- +if ((NIfCondArg ~= 1) & (ASTIfExpType~='else')) + error(9999, 'Cannot manage ""if/elseif"" with a number of condition variables not equal to 1.'); +end + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; + +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +CPass1FileName = FileInfo.Funct(nxtscifunnumber).CPass1FileName; + +// #RNU_RES_B +PrintStringInfo(' ',ReportFileName,'file','y'); +PrintStringInfo('***Generating C code***',ReportFileName,'file','y'); +// #RNU_RES_E +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +// -------------------------------------------- +// --- Generate the C name of the function. --- +// -------------------------------------------- +if (ASTIfExpType=='if') + CFunName = 'if'; +elseif (ASTIfExpType=='elseif') + CFunName = 'if'; +elseif (ASTIfExpType=='else') + CFunName = 'else'; +else + error(9999, 'Unknown ASTIfExpType ""'+ASTIfExpType+'"".'); +end + +// ---------------------------- +// --- Generate the C call. --- +// ---------------------------- +if SCI2Cstrncmps1size(ASTIfExpType,'else') + // #RNU_RES_B + // before opening a new C block, closes the previous one. + // #RNU_RES_E + SharedInfo = C_IfElseBlocks(FileInfo,SharedInfo,'out'); +end + +CCall =''; +CCall = CCall+CFunName; +if (ASTIfExpType~='else') + CCall = CCall+'('+IfCondArg(1)+')'; +end +PrintStringInfo(' '+CCall,ReportFileName,'file','y'); +PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CCall,CPass1FileName,'file','y'); + +SharedInfo = C_IfElseBlocks(FileInfo,SharedInfo,'in'); + +// #RNU_RES_B +// --------------------------------- +// --- Update counter nested if. --- +// --------------------------------- +// #RNU_RES_E +if (ASTIfExpType=='elseif') + // #RNU_RES_B + // every elseif statement a new } is required. + // #RNU_RES_E + SharedInfo.CountNestedIf = SharedInfo.CountNestedIf + 1; +end + +endfunction diff --git a/macros/CCodeGeneration/C_IndentBlanks.sci b/macros/CCodeGeneration/C_IndentBlanks.sci new file mode 100644 index 0000000..9304aef --- /dev/null +++ b/macros/CCodeGeneration/C_IndentBlanks.sci @@ -0,0 +1,31 @@ +function OutBlanksString = C_IndentBlanks(IndentLevel) +// function OutBlanksString = C_IndentBlanks(IndentLevel) +// ----------------------------------------------------------------- +// Delete function for a generic SCI2C table. +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// 26-Oct-2007 -- Alberto Morea: Test Ok. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),1,1); + +OutBlanksString = ''; +BlanksPerLevel = ' '; +for cntind = 1:IndentLevel + OutBlanksString = OutBlanksString + BlanksPerLevel; +end + +endfunction diff --git a/macros/CCodeGeneration/C_InitHeader.sci b/macros/CCodeGeneration/C_InitHeader.sci new file mode 100644 index 0000000..97dcf0d --- /dev/null +++ b/macros/CCodeGeneration/C_InitHeader.sci @@ -0,0 +1,77 @@ +function C_InitHeader(C_Prototype,HeaderFileName,Sci2CLibMainHeaderFName,Target,OpenCVUsed) +// function C_InitHeader(C_Prototype,HeaderFileName,Sci2CLibMainHeaderFName) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 27-Oct-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),5,5); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +// --------------------------- +// --- End Initialization. --- +// --------------------------- + + +C_SCI2CHeader(HeaderFileName); +[tmppath,tmpfname,tmpextension]=fileparts(HeaderFileName); +PrintStringInfo('#ifndef '+tmpfname+'_h',HeaderFileName,'file','y'); +PrintStringInfo('#define '+tmpfname+'_h',HeaderFileName,'file','y'); +PrintStringInfo('/*',HeaderFileName,'file','y'); +PrintStringInfo('** ------------------- ',HeaderFileName,'file','y'); +PrintStringInfo('** ----- Target ------ ',HeaderFileName,'file','y'); +PrintStringInfo('** ------------------- ',HeaderFileName,'file','y'); +PrintStringInfo('*/',HeaderFileName,'file','y'); +PrintStringInfo('#define ' + Target + '1 1' ,HeaderFileName,'file','y'); +PrintStringInfo('/*',HeaderFileName,'file','y'); +PrintStringInfo('** ----------------------- ',HeaderFileName,'file','y'); +PrintStringInfo('** --- SCI2C Includes. --- ',HeaderFileName,'file','y'); +PrintStringInfo('** ----------------------- ',HeaderFileName,'file','y'); +PrintStringInfo('*/',HeaderFileName,'file','y'); +PrintStringInfo('#include ""'+Sci2CLibMainHeaderFName+'""',HeaderFileName,'file','y'); +PrintStringInfo('/*',HeaderFileName,'file','y'); +PrintStringInfo('** --------------------------- ',HeaderFileName,'file','y'); +PrintStringInfo('** --- End SCI2C Includes. --- ',HeaderFileName,'file','y'); +PrintStringInfo('** --------------------------- ',HeaderFileName,'file','y'); +PrintStringInfo('*/',HeaderFileName,'file','y'); +PrintStringInfo(' ',HeaderFileName,'file','y'); +PrintStringInfo(' ',HeaderFileName,'file','y'); +//PrintStringInfo('#ifdef __cplusplus',HeaderFileName,'file','y'); +//PrintStringInfo('extern ""C"" {',HeaderFileName,'file','y'); +//PrintStringInfo('#endif',HeaderFileName,'file','y'); +PrintStringInfo('/*',HeaderFileName,'file','y'); +PrintStringInfo('** ------------------- ',HeaderFileName,'file','y'); +PrintStringInfo('** --- Prototypes. --- ',HeaderFileName,'file','y'); +PrintStringInfo('** ------------------- ',HeaderFileName,'file','y'); +PrintStringInfo('*/',HeaderFileName,'file','y'); +PrintStringInfo(C_IndentBlanks(0)+C_Prototype,HeaderFileName,'file','y'); +PrintStringInfo('/*',HeaderFileName,'file','y'); +PrintStringInfo('** ----------------------- ',HeaderFileName,'file','y'); +PrintStringInfo('** --- End Prototypes. --- ',HeaderFileName,'file','y'); +PrintStringInfo('** ----------------------- ',HeaderFileName,'file','y'); +PrintStringInfo('*/',HeaderFileName,'file','y'); +PrintStringInfo(' ',HeaderFileName,'file','y'); +PrintStringInfo(' ',HeaderFileName,'file','y'); +PrintStringInfo('/*',HeaderFileName,'file','y'); +PrintStringInfo('** ------------------------ ',HeaderFileName,'file','y'); +PrintStringInfo('** --- USER2C Includes. --- ',HeaderFileName,'file','y'); +PrintStringInfo('** ------------------------ ',HeaderFileName,'file','y'); +PrintStringInfo('*/',HeaderFileName,'file','y'); + +endfunction diff --git a/macros/CCodeGeneration/C_MemAllocOutTempVars.sci b/macros/CCodeGeneration/C_MemAllocOutTempVars.sci new file mode 100644 index 0000000..dedcfd3 --- /dev/null +++ b/macros/CCodeGeneration/C_MemAllocOutTempVars.sci @@ -0,0 +1,64 @@ +function C_MemAllocOutTempVars(OutArg,NOutArg,CPass1FileName,CPass1FreeFileName,IndentLevel,ReportFileName,ResizeApproach) +// function C_MemAllocOutTempVars(OutArg,NOutArg,CPass1FileName,CPass1FreeFileName,IndentLevel,ReportFileName,ResizeApproach) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 27-Oct-2007 -- Raffaele Nutricato: Author. +// 10-Jun-2008 -- Raffaele Nutricato: replaced malloc with realloc. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),7,7); + +// #RNU_RES_B +PrintStringInfo(' ',ReportFileName,'file','y'); +PrintStringInfo('***Allocating memory for temp variables***',ReportFileName,'file','y'); +// #RNU_RES_E + +// #RNU_RES_B +// --- Allocate memory and size array for output arguments. --- +// #RNU_RES_E +for counterout = 1:NOutArg + if (OutArg(counterout).Dimension > 0) + // #RNU_RES_B + // if ((OutArg(counterout).Scope == 'Temp') | (OutArg(counterout).FindLike == -1) | ... + // (isnum(OutArg(counterout).Size(1))==%F) | (isnum(OutArg(counterout).Size(2))==%F)) + //NUT: qui forse ci vuole un check per verificare se per caso la variabile e' globale e non se ne conosce la size numerica. + //NUT infatti. Per ora se la size numerica assumo che la variabile globale e' da reallocare. Secondo me occorre aggiungere + //NUT un campo negli argomenti che specifichi la presenza di realloc da fare. + //NUT: ho tolto il check sulle temp perche' se una temp ha size numerica non voglio fare malloc. + //RNU sulle stringhe ancora non applico realloc + // #RNU_RES_E + if ((OutArg(counterout).FindLike == -1) | ... + (isnum(OutArg(counterout).Size(1))==%F) | (isnum(OutArg(counterout).Size(2))==%F)| ... + (ResizeApproach=='REALLOC_ALL_RESIZE_ALL' & OutArg(counterout).Type ~= 'g')) + OutArgName = OutArg(counterout).Name; + tmpcode = '__'+OutArgName+'Size[0]='+OutArg(counterout).Size(1)+';'; + PrintStringInfo(C_IndentBlanks(IndentLevel)+tmpcode,CPass1FileName,'file','y'); + PrintStringInfo(' '+tmpcode,ReportFileName,'file','y'); + tmpcode = '__'+OutArgName+'Size[1]='+OutArg(counterout).Size(2)+';'; + PrintStringInfo(C_IndentBlanks(IndentLevel)+tmpcode,CPass1FileName,'file','y'); + PrintStringInfo(' '+tmpcode,ReportFileName,'file','y'); + //a->val = (double *) malloc(nnz * sizeof(double)); + // numbers = (int*) realloc (numbers, count * sizeof(int)); + tmpcode = OutArgName+' = ('+C_Type(OutArg(counterout).Type)+'*) realloc('+OutArgName+',('+OutArg(counterout).Size(1)+')*('+OutArg(counterout).Size(2)+')*sizeof('+C_Type(OutArg(counterout).Type)+'));'; + PrintStringInfo(C_IndentBlanks(IndentLevel)+tmpcode,CPass1FileName,'file','y'); + PrintStringInfo(' '+tmpcode,ReportFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(1)+'free('+OutArgName+');',CPass1FreeFileName,'file','y'); + end + end +end + +endfunction diff --git a/macros/CCodeGeneration/C_SCI2CHeader.sci b/macros/CCodeGeneration/C_SCI2CHeader.sci new file mode 100644 index 0000000..42c25a4 --- /dev/null +++ b/macros/CCodeGeneration/C_SCI2CHeader.sci @@ -0,0 +1,46 @@ +function C_SCI2CHeader(FileName) +// function C_SCI2CHeader(FileName) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 21-Dec-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),1,1); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +// --------------------------- +// --- End Initialization. --- +// --------------------------- + + +PrintStringInfo('/*',FileName,'file','y'); +PrintStringInfo('** ************************************************',FileName,'file','y'); +PrintStringInfo('** This file has been generated using',FileName,'file','y'); +PrintStringInfo('** Scilab2C (Version '+getScilab2cVersion()+')',FileName,'file','y'); +PrintStringInfo('**',FileName,'file','y'); +PrintStringInfo('** Please visit following links for more informations:',FileName,'file','y'); +PrintStringInfo('** Atoms Module: http://atoms.scilab.org/toolboxes/scilab2c',FileName,'file','y'); +PrintStringInfo('** Scilab2C Forge: http://forge.scilab.org/index.php/p/scilab2c/',FileName,'file','y'); +PrintStringInfo('** Scilab2C ML: http://forge.scilab.org/index.php/p/scilab2c/',FileName,'file','y'); +PrintStringInfo('** ************************************************',FileName,'file','y'); +PrintStringInfo('*/',FileName,'file','y'); +PrintStringInfo(' ',FileName,'file','y'); +PrintStringInfo(' ',FileName,'file','y'); + +endfunction diff --git a/macros/CCodeGeneration/C_Type.sci b/macros/CCodeGeneration/C_Type.sci new file mode 100644 index 0000000..d296c5c --- /dev/null +++ b/macros/CCodeGeneration/C_Type.sci @@ -0,0 +1,66 @@ +function OutC_Type = C_Type(ArgType) +// function OutC_Type = C_Type(ArgType) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 27-Oct-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),1,1); + +if (ArgType == 's') + OutC_Type = 'float'; +elseif (ArgType == 'd') + OutC_Type = 'double'; +elseif (ArgType == 'c') + OutC_Type = 'floatComplex'; +elseif (ArgType == 'z') + OutC_Type = 'doubleComplex'; +elseif (ArgType == 'i') + OutC_Type = 'int'; +elseif (ArgType == 'g') + OutC_Type = 'char'; +elseif (ArgType == 'f') + OutC_Type = 'FILE *'; +elseif (ArgType == 'u8') + OutC_Type = 'uint8'; +elseif (ArgType == 'i8') + OutC_Type = 'int8'; +elseif (ArgType == 'u16') + OutC_Type = 'uint16'; +elseif (ArgType == 'i16') + OutC_Type = 'int16'; +elseif (ArgType == 'u32') + OutC_Type = 'uint32'; +elseif (ArgType == 'i32') + OutC_Type = 'int32'; +elseif (ArgType == 'fn') //This type introduced for ODE function, + // as it's one of the inout argument is name of the other function + OutC_Type = ''; +elseif (ArgType == 'mt') + OutC_Type = 'Mat' +elseif (ArgType == 'ss') + OutC_Type = 'double' + //This type is introduced for storing state space systems. + //It is a matrix of size (n+k)*(n+m+1), for n states, m inputs, + //k outputs. It stores matrices A,B,C,D and initial state in following form + // | A B X0 | + // | C D 0 | + +else + error(9999, 'Unknown Argument Type: ""'+ArgType+'"".'); +end +endfunction diff --git a/macros/CCodeGeneration/C_WhileExpression.sci b/macros/CCodeGeneration/C_WhileExpression.sci new file mode 100644 index 0000000..edd2830 --- /dev/null +++ b/macros/CCodeGeneration/C_WhileExpression.sci @@ -0,0 +1,93 @@ +function SharedInfo = C_WhileExpression(FileInfo,SharedInfo) +// function SharedInfo = C_WhileExpression(FileInfo,SharedInfo) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 15-Nov-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; + +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +CPass1FileName = FileInfo.Funct(nxtscifunnumber).CPass1FileName; + +CPass1WhileProlFileName = FileInfo.Funct(nxtscifunnumber).CPass1WhileProlFileName(SharedInfo.While.Level); +CPass1WhileEpilFileName = FileInfo.Funct(nxtscifunnumber).CPass1WhileEpilFileName(SharedInfo.While.Level); +CDeclarationFileName = FileInfo.Funct(nxtscifunnumber).CDeclarationFileName; + +// #RNU_RES_B +PrintStringInfo(' ',ReportFileName,'file','y'); +PrintStringInfo('***Generating C code***',ReportFileName,'file','y'); +// #RNU_RES_E +CCall =''; +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +// ---------------------------- +// --- Generate the C call. --- +// ---------------------------- + +// ------------------------- +// --- Manage all cases. --- +// ------------------------- +PrintStringInfo(' Handling While Expression with OpColon.',ReportFileName,'file','y'); //NUT: sistema il commento. + +// ------------------------------------------------------------------------------------- +// --- Generate Prologue and Epilogue -> Copy the first N-1 lines of the for.c code. --- +// ------------------------------------------------------------------------------------- +[C_Strings,NumCStrings] = File2StringArray(CPass1WhileProlFileName); +C_Strings = stripblanks(C_Strings); +for cntstr = 1:NumCStrings + // Prologue + PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+C_Strings(cntstr),CPass1FileName,'file','y','n'); + // Epilogue + if (length(C_Strings(cntstr)) == 0) + C_Strings(cntstr) = ' '; // RNU for Bruno: If I don't do that I get a PrintStringInfo error related to mputstr. + // Function not defined for given argument type(s),
+ // check arguments or define function %0_mputstr for overloading. + end + PrintStringInfo(C_Strings(cntstr),CPass1WhileEpilFileName ,'file','y','n'); +end +// ---------------------------------------- +// --- Insert "}" in the epilogue file. --- +// ---------------------------------------- +PrintStringInfo('}',CPass1WhileEpilFileName ,'file','y'); + +// ------------------------------ +// --- Insert for expression. --- +// ------------------------------ +CCall = 'while('+SharedInfo.WhileExpr.CondVar+')'; +PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CCall,CPass1FileName,'file','y'); + +// ------------------- +// --- Insert "{". --- +// ------------------- +CCall = '{'; +PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CCall,CPass1FileName,'file','y'); + +// --------------------------------- +// --- Update Indentation Level. --- +// --------------------------------- +SharedInfo.NIndent = SharedInfo.NIndent + 1; + +endfunction diff --git a/macros/CCodeGeneration/GenCFunDatFiles.sci b/macros/CCodeGeneration/GenCFunDatFiles.sci new file mode 100644 index 0000000..9af858c --- /dev/null +++ b/macros/CCodeGeneration/GenCFunDatFiles.sci @@ -0,0 +1,73 @@ +function GenCFunDatFiles(FunctionName,FunPrecSpecifier,FunTypeAnnot,FunSizeAnnot,InArg,NInArg,OutArg,NOutArg,CFunName,LibTypeInfo,FunInfoDatDir) +// function GenCFunDatFiles(FunctionName,FunPrecSpecifier,FunTypeAnnot,FunSizeAnnot,InArg,NInArg,OutArg,NOutArg,CFunName,LibTypeInfo,FunInfoDatDir) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 30-Oct-2007 -- Raffaele Nutricato: Author. +// 30-Oct-2007 -- Alberto Morea: Test Ok. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// #RNU_RES_B +//NUT Nella fun info posso mettere le size simboliche per out arg e non quelle numeriche +//NUT che non usero' mai, anche perche' se un giorno decidero' di cambiare approccio e usero' funzioni +//NUT differenti per size differenti allora dovro' cambiare anche il loro nome per distinguerle +//NUT e di conseguenza avro' funinfo differenti. +// #RNU_RES_E +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),11,11); + + +// ----------------------- +// --- Initialization. --- +// ----------------------- +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +// #RNU_RES_B +// ---------------------------------------------------------- +// --- Find Position of the first output scalar argument. --- +// ---------------------------------------------------------- +// #RNU_RES_E +PosFirstOutScalar = 0; +FoundOutScalar = 0; +for counterout = 1:NOutArg + if (OutArg(counterout).Dimension == 0) + if (FoundOutScalar==0) + PosFirstOutScalar = counterout; + FoundOutScalar = 1; + end + end +end + +// ------------------------------------ +// --- Update C function dat files. --- +// ------------------------------------ +clear FunInfo +FunInfo.SCIFunctionName = FunctionName; +FunInfo.CFunctionName = CFunName; +FunInfo.FunPrecSpecifier = FunPrecSpecifier; +FunInfo.FunTypeAnnot = FunTypeAnnot; +FunInfo.FunSizeAnnot = FunSizeAnnot; +FunInfo.InArg = InArg; +FunInfo.NInArg = NInArg; +FunInfo.OutArg = OutArg; +FunInfo.NOutArg = NOutArg; +FunInfo.PosFirstOutScalar = PosFirstOutScalar; +FunInfo.LibTypeInfo = LibTypeInfo; +save(fullfile(FunInfoDatDir,CFunName+'.dat'), "FunInfo"); +clear FunInfo + +endfunction diff --git a/macros/CCodeGeneration/GetClsFileName.sci b/macros/CCodeGeneration/GetClsFileName.sci new file mode 100644 index 0000000..46f0820 --- /dev/null +++ b/macros/CCodeGeneration/GetClsFileName.sci @@ -0,0 +1,95 @@ +function SCI2CClassFileName = GetClsFileName(FunName,FileInfo,SharedInfo) +// function SCI2CClassFileName = GetClsFileName(FunName,FileInfo,SharedInfo) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-Jul-2007 -- Nutricato Raffaele: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),3,3); + +// //NUT: verifica che il nome sia accettabile e che non +// //NUT: occorra spezzettarla in piu funzioni. + +// --- Extraction of the function name and number. --- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; + +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; + +// --- Initialization. --- +tmpannfilename = FunName+'.ann'; +tmpscifilename = FunName+'.sci'; +AnnFileName = ''; +ClsFileName = '' + +SCI2CClassSpecifier = SharedInfo.Annotations.FUNCLASS; +FlagFoundAnnFile = 0; +// #RNU_RES_B +//NUT: qui e' presente la lista delle priorita' di accesso alle annotazioni. +// #RNU_RES_E +if SCI2Cfileexist(FileInfo.USER2CLibCAnnFun,tmpannfilename) + // #RNU_RES_B + // It is a C function of the USER2C library. + // #RNU_RES_E + FlagFoundAnnFile = 1; + AnnFileName = fullfile(FileInfo.USER2CLibCAnnFun,tmpannfilename); + SCI2CClassName = FL_GetFunctionClass(AnnFileName,SCI2CClassSpecifier,ReportFileName); + SCI2CClassFileName = fullfile(FileInfo.USER2CLibCAnnCls,SCI2CClassName+'.acls'); +elseif SCI2Cfileexist(FileInfo.USER2CLibSCIAnnFun,tmpannfilename) + // #RNU_RES_B + // It is a scilab function of the USER2C library. + // #RNU_RES_E + FlagFoundAnnFile = 1; + AnnFileName = fullfile(FileInfo.USER2CLibSCIAnnFun,tmpannfilename); + SCI2CClassName = FL_GetFunctionClass(AnnFileName,SCI2CClassSpecifier,ReportFileName); + SCI2CClassFileName = fullfile(FileInfo.USER2CLibSCIAnnCls,SCI2CClassName+'.acls'); +elseif (SCI2Cfileexist(FileInfo.SCI2CLibCAnnFun,tmpannfilename)) + // #RNU_RES_B + // It is a C function of the SCI2C library. + // #RNU_RES_E + FlagFoundAnnFile = 1; + AnnFileName = fullfile(FileInfo.SCI2CLibCAnnFun,tmpannfilename); + SCI2CClassName = FL_GetFunctionClass(AnnFileName,SCI2CClassSpecifier,ReportFileName); + SCI2CClassFileName = fullfile(FileInfo.SCI2CLibCAnnCls,SCI2CClassName+'.acls'); +elseif (SCI2Cfileexist(FileInfo.SCI2CLibSCIAnnFun,tmpannfilename)) + // #RNU_RES_B + // It is a scilab function of the SCI2C library. + // #RNU_RES_E + FlagFoundAnnFile = 1; + AnnFileName = fullfile(FileInfo.SCI2CLibSCIAnnFun,tmpannfilename); + SCI2CClassName = FL_GetFunctionClass(AnnFileName,SCI2CClassSpecifier,ReportFileName); + SCI2CClassFileName = fullfile(FileInfo.SCI2CLibSCIAnnCls,SCI2CClassName+'.acls'); +end + +if (FlagFoundAnnFile == 0) + [FlagFoundAnnFile,fullpathscifilename] = SCI2CFindFile(FileInfo.UserSciFilesPaths,FunName+'.sci'); + if (FlagFoundAnnFile == 0) + // #RNU_RES_B + PrintStringInfo(' ',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: Missing function annotation. Could not find',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: an associated .sci or .ann file for function: '+FunName,ReportFileName,'both','y'); + PrintStringInfo(' ',ReportFileName,'both','y'); + // #RNU_RES_E + error(9999, 'SCI2CERROR: Missing function annotation. Could not find an associated .sci or .ann file for function: '+FunName); + end + AnnFileName = fullfile(FileInfo.USER2CLibSCIAnnFun,tmpannfilename); + SCI2CClassName = FunName; + SCI2CClassFileName = fullfile(FileInfo.USER2CLibSCIAnnCls,SCI2CClassName+'.acls'); + Sci2AnnotationFile(fullpathscifilename,SCI2CClassFileName,AnnFileName,... + SharedInfo.Annotations.USERFUN,ReportFileName); +end +endfunction diff --git a/macros/CCodeGeneration/GetSymbolDimension.sci b/macros/CCodeGeneration/GetSymbolDimension.sci new file mode 100644 index 0000000..5828e0a --- /dev/null +++ b/macros/CCodeGeneration/GetSymbolDimension.sci @@ -0,0 +1,68 @@ +function symboldimension = GetSymbolDimension(Field_Size) +// function symboldimension = GetSymbolDimension(Field_Size) +// ----------------------------------------------------------------- +// #RNU_RES_B +// Get the dimesion (0D,1D,2D) of a symbol given its size. +// +// Input data: +// Field_Size: it is the Size field of the InArg or OutArg structures. +// It is a 2-element array. N-dim array are not supported +// in this release. +// +// Output data: +// symboldimension: number specifying the dimension of the symbol. +// 0 = scalar; 1 = column or row; 2 = matrix; 3 = hypermatrix. +// +// #RNU_RES_E +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// 26-Oct-2007 -- Alberto Morea: Test Ok. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ + SCI2CNInArgCheck(argn(2),1,1); + +// Size is expressed as an array of two strings. + Nelem = max(size(Field_Size)); + if (Nelem < 2) + error(9999, '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) + error(9999, 'Found a symbol that has zeros elements. 0xN or Nx0 matrices are not allowed.'); + elseif (tmpnum == 1) + Field_Type(countersize) = 0; + else + Field_Type(countersize) = 1; + 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 diff --git a/macros/CCodeGeneration/GetWhileCondVariable.sci b/macros/CCodeGeneration/GetWhileCondVariable.sci new file mode 100644 index 0000000..ba4c7e9 --- /dev/null +++ b/macros/CCodeGeneration/GetWhileCondVariable.sci @@ -0,0 +1,72 @@ +function SharedInfo = GetWhileCondVariable(OutArg,NOutArg,FunctionName,FileInfo,SharedInfo) +// function SharedInfo = GetWhileCondVariable(OutArg,NOutArg,FunctionName,FileInfo,SharedInfo) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// 26-Oct-2007 -- Alberto Morea: Test Ok. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +//NUT: secondo me questa funzione non serve a nulla + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),5,5); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; + +// #RNU_RES_B +PrintStringInfo(' ',ReportFileName,'file','y'); +PrintStringInfo('***Checking if the current function is handling while counter variables.***',ReportFileName,'file','y'); +// #RNU_RES_E + +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +// #RNU_RES_B +// ----------------------------------------------- +// --- Initial Check on While counter variables. --- +// ----------------------------------------------- +// #RNU_RES_E +if ((SharedInfo.WhileExpr.OnExec > 0) & (NOutArg==1)) + // #RNU_RES_B + //NUT: se sono in una while expression devo memorizzarmi l'ultima variabile di output + //NUT: perche' e' quella che contiene la condizione da testare, + //NUT: allora io me le salvo tutte e l'ultima salvata sara' quella che andra' a finire + //NUT: nella while. + // #RNU_RES_E + SharedInfo.WhileExpr.CondVar = OutArg(1).Name; + // #RNU_RES_B + //if (SharedInfo.WhileExpr.AssignmentFun == 0) + //NUT: Test also that SharedInfo.WhileExpr.AssignmentFun because sometimes Equal are dummy! + //NUT: verifica se e' giusta questa mia affermazione. + //RNU il seguente test e' stato spostato nella AST_HandleWhileStatem.c perche' + //RNU: secondo me la matrice finale non e' supportata dalla while, ma while(det(M)>0) + //RNU: puo' essere benissimo supportato. + // if (OutArg.Dimension > 0) + // SCI2CerrorFile('Cannot manage while with matrix conditions',ReportFileName); + // SharedInfo.SkipNextFun = 0; //NUT verifica se serve + // end + // #RNU_RES_E + SharedInfo.WhileExpr.DimCondVar = OutArg(1).Dimension; + ///end +end + +endfunction diff --git a/macros/CCodeGeneration/JoinDeclarAndCcode.sci b/macros/CCodeGeneration/JoinDeclarAndCcode.sci new file mode 100644 index 0000000..2c69f46 --- /dev/null +++ b/macros/CCodeGeneration/JoinDeclarAndCcode.sci @@ -0,0 +1,173 @@ +function JoinDeclarAndCcode(FileInfoDatFile) +// function JoinDeclarAndCcode(FileInfoDatFile) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 07-Nov-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),1,1); + +// --------------------- +// --- Load section. --- +// --------------------- +// --- Load File Info Structure. --- +load(FileInfoDatFile,'FileInfo'); + +// --- Load Shared Info Structure. --- +load(FileInfo.SharedInfoDatFile,'SharedInfo'); +// ------------------------- +// --- End load section. --- +// ------------------------- + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +funnumber = SharedInfo.NextSCIFunNumber; + +CPass1FileName = FileInfo.Funct(funnumber).CPass1FileName; +CPass2FileName = FileInfo.Funct(funnumber).CPass2FileName; +CDeclarationFileName = FileInfo.Funct(funnumber).CDeclarationFileName; +CGblDeclarFileName = FileInfo.Funct(funnumber).CGblDeclarFileName; +CInitVarsFileName = FileInfo.Funct(funnumber).CInitVarsFileName; +ReportFileName = FileInfo.Funct(funnumber).ReportFileName; + +CPass1V1FileFid = SCI2COpenFileRead(CPass1FileName); +CDeclarationFileFid = SCI2COpenFileRead(CDeclarationFileName); +CGblDeclarFileFid = SCI2COpenFileRead(CGblDeclarFileName); +CInitVarsFileFid = SCI2COpenFileRead(CInitVarsFileName); +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +PrintStepInfo('Joining declaration and C-call files',ReportFileName,'file'); + +PrintStringInfo('/*',CPass2FileName,'file','y'); +PrintStringInfo('** -------------------------------------',CPass2FileName,'file','y'); +PrintStringInfo('** --- Global Variables Declaration. ---',CPass2FileName,'file','y'); +PrintStringInfo('** -------------------------------------',CPass2FileName,'file','y'); +PrintStringInfo('*/',CPass2FileName,'file','y'); +// #RNU_RES_B +// --- Copy in V2 the global declaration file. --- +// #RNU_RES_E +while (~meof(CGblDeclarFileFid)) + // Read a line from C Global Declaration file. + tmpcline = mgetl(CGblDeclarFileFid,1); + if (length(tmpcline) == 0) + tmpcline = ' '; + end + + noblkstmpcline = stripblanks(tmpcline); + PrintStringInfo(tmpcline,CPass2FileName,'file','y'); +end +PrintStringInfo('/*',CPass2FileName,'file','y'); +PrintStringInfo('** -----------------------------------------',CPass2FileName,'file','y'); +PrintStringInfo('** --- End Global Variables Declaration. ---',CPass2FileName,'file','y'); +PrintStringInfo('** -----------------------------------------',CPass2FileName,'file','y'); +PrintStringInfo('*/',CPass2FileName,'file','y'); +PrintStringInfo(' ',CPass2FileName,'file','y'); + +// #RNU_RES_B +// --- Copy in V2 the first part of V1 up to "{". --- +// #RNU_RES_E +FoundCurlyBracket = 0; +while ((~meof(CPass1V1FileFid)) & (FoundCurlyBracket == 0)) + // Read a line from C Pass1 file. + tmpcline = mgetl(CPass1V1FileFid,1); + noblkstmpcline = stripblanks(tmpcline); + if (length(noblkstmpcline) > 0) + if (SCI2Cstrncmps1size('{',noblkstmpcline)) + FoundCurlyBracket = 1; + end + else + tmpcline = ' '; + end + PrintStringInfo(tmpcline,CPass2FileName,'file','y'); +end + +if (FoundCurlyBracket == 0) + SCI2CerrorFile('""{"" char not found in:'+CPass1FileName,ReportFileName); +end + +PrintStringInfo('/*',CPass2FileName,'file','y'); +PrintStringInfo('** -----------------------------',CPass2FileName,'file','y'); +PrintStringInfo('** --- Variable Declaration. ---',CPass2FileName,'file','y'); +PrintStringInfo('** -----------------------------',CPass2FileName,'file','y'); +PrintStringInfo('*/',CPass2FileName,'file','y'); +// --- Copy in V2 the declaration file. --- +while (~meof(CDeclarationFileFid)) + // Read a line from C Declaration file. + tmpcline = mgetl(CDeclarationFileFid,1); + if (length(tmpcline) == 0) + tmpcline = ' '; + end + + noblkstmpcline = stripblanks(tmpcline); + PrintStringInfo(tmpcline,CPass2FileName,'file','y'); +end + +// #RNU_RES_B +// --- Copy in V2 the variable initialization file. --- +// #RNU_RES_E +while (~meof(CInitVarsFileFid)) + // Read a line from C Declaration file. + tmpcline = mgetl(CInitVarsFileFid,1); + if (length(tmpcline) == 0) + tmpcline = ' '; + end + + noblkstmpcline = stripblanks(tmpcline); + PrintStringInfo(tmpcline,CPass2FileName,'file','y'); +end +PrintStringInfo('/*',CPass2FileName,'file','y'); +PrintStringInfo('** ---------------------------------',CPass2FileName,'file','y'); +PrintStringInfo('** --- End Variable Declaration. ---',CPass2FileName,'file','y'); +PrintStringInfo('** ---------------------------------',CPass2FileName,'file','y'); +PrintStringInfo('*/',CPass2FileName,'file','y'); + + +PrintStringInfo('/*',CPass2FileName,'file','y'); +PrintStringInfo('** ---------------',CPass2FileName,'file','y'); +PrintStringInfo('** --- C code. ---',CPass2FileName,'file','y'); +PrintStringInfo('** ---------------',CPass2FileName,'file','y'); +PrintStringInfo('*/',CPass2FileName,'file','y'); + +if((SharedInfo.Target == "RPi") & (nxtscifunname == SharedInfo.SCIMainFunName)) + //Add wiringPiSetup() function as it is required + PrintStringInfo('wiringPiSetup();',CPass2FileName,'file','y'); +end +// --- Copy the remaining part of V1 in V2. --- +while (~meof(CPass1V1FileFid)) + // #RNU_RES_B + // Read a line from C Pass1 file. + // #RNU_RES_E + tmpcline = mgetl(CPass1V1FileFid,1); + if (length(tmpcline) == 0) + tmpcline = ' '; + end + PrintStringInfo(tmpcline,CPass2FileName,'file','y'); +end + +// -------------------- +// --- Close Files. --- +// -------------------- +mclose(CPass1V1FileFid); +mclose(CDeclarationFileFid); +mclose(CGblDeclarFileFid); +mclose(CInitVarsFileFid); + +endfunction diff --git a/macros/CCodeGeneration/SCI2CMakefileTemplate.bkp b/macros/CCodeGeneration/SCI2CMakefileTemplate.bkp new file mode 100644 index 0000000..65184df --- /dev/null +++ b/macros/CCodeGeneration/SCI2CMakefileTemplate.bkp @@ -0,0 +1,230 @@ +
+# --- C COMPILER ---
+CC = gcc
+CFLAGS = -Wall -pedantic -O3 -I $(HSRCDIR)
+# ---------------------------
+# --- END USER PARAMETERS ---
+# ---------------------------
+
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+# DON'T TOUCH ANYTHING BELOW THIS LINE
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+
+ELEMENTARY_FUNCTIONS_DIR = $(CSRCDIR)/src/elementaryFunctions
+CFLAGS_ELEMENTARY_FUNCTIONS = -I $(ELEMENTARY_FUNCTIONS_DIR)/includes -I $(ELEMENTARY_FUNCTIONS_DIR)/interfaces
+
+
+EXEFILE = $(SCI2CDIR)/$(EXEFILENAME)
+
+objects = \
+ $(OBJDIR)/doubleComplex.o \
+ $(OBJDIR)/floatComplex.o \
+ $(OBJDIR)/RealToComplex.o \
+ $(OBJDIR)/conj.o \
+ $(OBJDIR)/disp.o \
+ $(OBJDIR)/ones.o \
+ $(OBJDIR)/zeros.o \
+ $(OBJDIR)/OpApex.o \
+ $(OBJDIR)/OpColon.o \
+ $(OBJDIR)/OpDotStar.o \
+ $(OBJDIR)/OpDotHat.o \
+ $(OBJDIR)/OpDotSlash.o \
+ $(OBJDIR)/OpEqual.o \
+ $(OBJDIR)/OpPlus.o \
+ $(OBJDIR)/OpMinus.o \
+ $(OBJDIR)/OpStar.o \
+ $(OBJDIR)/OpIns.o \
+ $(OBJDIR)/OpExt.o \
+ $(OBJDIR)/OpRc.o \
+ $(OBJDIR)/OpCc.o \
+ $(OBJDIR)/cos.o \
+ $(OBJDIR)/cosh.o \
+ $(OBJDIR)/sin.o \
+ $(OBJDIR)/sinh.o \
+ $(OBJDIR)/FileManagement.o \
+ $(OBJDIR)/OpLogLt.o \
+ $(OBJDIR)/OpLogGt.o \
+ $(OBJDIR)/OpLogGe.o \
+ $(OBJDIR)/OpLogLe.o \
+ $(OBJDIR)/OpLogEq.o \
+ $(OBJDIR)/Find.o \
+ $(OBJDIR)/ConvertPrecision.o \
+ $(OBJDIR)/SCI2Cfft.o \
+ $(OBJDIR)/SCI2Cconvol.o \
+ $(OBJDIR)/ssqrts.o \
+ $(OBJDIR)/dsqrts.o \
+ $(OBJDIR)/csqrts.o \
+ $(OBJDIR)/zsqrts.o \
+ $(OBJDIR)/ssqrta.o \
+ $(OBJDIR)/dsqrta.o \
+ $(OBJDIR)/csqrta.o \
+ $(OBJDIR)/zsqrta.o
+
+# ---------------
+# --- TARGETS ---
+# ---------------
+compileexecute: $(objects)
+ @echo " "
+ @echo "============================"
+ @echo "Generation of the executable"
+ @echo "============================"
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) $(objects) $(SCI2CDIR)/*.c -o $(EXEFILE)
+ @echo " "
+ @echo "=============="
+ @echo "Executing code"
+ @echo "=============="
+ $(EXEFILE)
+
+clean:
+ @echo " "
+ @echo "============================="
+ @echo "Removing only exe + obj files"
+ @echo "============================="
+ rm -rf $(EXEFILE)
+ rm -rf $(objects)
+ @echo " "
+
+cleanexe:
+ @echo " "
+ @echo "=========================="
+ @echo "Removing only the exe file"
+ @echo "=========================="
+ rm -rf $(EXEFILE)
+ @echo " "
+
+$(OBJDIR)/doubleComplex.o: $(CSRCDIR)/doubleComplex.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/doubleComplex.c -o $(OBJDIR)/doubleComplex.o
+
+$(OBJDIR)/floatComplex.o: $(CSRCDIR)/floatComplex.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/floatComplex.c -o $(OBJDIR)/floatComplex.o
+
+$(OBJDIR)/RealToComplex.o: $(CSRCDIR)/RealToComplex.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/RealToComplex.c -o $(OBJDIR)/RealToComplex.o
+
+$(OBJDIR)/conj.o: $(CSRCDIR)/conj.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/conj.c -o $(OBJDIR)/conj.o
+
+$(OBJDIR)/disp.o: $(CSRCDIR)/disp.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/disp.c -o $(OBJDIR)/disp.o
+
+$(OBJDIR)/zeros.o: $(CSRCDIR)/zeros.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/zeros.c -o $(OBJDIR)/zeros.o
+
+$(OBJDIR)/ones.o: $(CSRCDIR)/ones.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/ones.c -o $(OBJDIR)/ones.o
+
+$(OBJDIR)/OpApex.o: $(CSRCDIR)/OpApex.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpApex.c -o $(OBJDIR)/OpApex.o
+
+$(OBJDIR)/OpColon.o: $(CSRCDIR)/OpColon.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpColon.c -o $(OBJDIR)/OpColon.o
+
+$(OBJDIR)/OpDotStar.o: $(CSRCDIR)/OpDotStar.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpDotStar.c -o $(OBJDIR)/OpDotStar.o
+
+$(OBJDIR)/OpDotHat.o: $(CSRCDIR)/OpDotHat.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpDotHat.c -o $(OBJDIR)/OpDotHat.o
+
+$(OBJDIR)/OpDotSlash.o: $(CSRCDIR)/OpDotSlash.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpDotSlash.c -o $(OBJDIR)/OpDotSlash.o
+
+$(OBJDIR)/OpEqual.o: $(CSRCDIR)/OpEqual.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpEqual.c -o $(OBJDIR)/OpEqual.o
+
+$(OBJDIR)/OpPlus.o: $(CSRCDIR)/OpPlus.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpPlus.c -o $(OBJDIR)/OpPlus.o
+
+$(OBJDIR)/OpMinus.o: $(CSRCDIR)/OpMinus.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpMinus.c -o $(OBJDIR)/OpMinus.o
+
+$(OBJDIR)/OpStar.o: $(CSRCDIR)/OpStar.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpStar.c -o $(OBJDIR)/OpStar.o
+
+$(OBJDIR)/OpIns.o: $(CSRCDIR)/OpIns.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpIns.c -o $(OBJDIR)/OpIns.o
+
+$(OBJDIR)/OpExt.o: $(CSRCDIR)/OpExt.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpExt.c -o $(OBJDIR)/OpExt.o
+
+$(OBJDIR)/OpRc.o: $(CSRCDIR)/OpRc.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpRc.c -o $(OBJDIR)/OpRc.o
+
+$(OBJDIR)/OpCc.o: $(CSRCDIR)/OpCc.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpCc.c -o $(OBJDIR)/OpCc.o
+
+$(OBJDIR)/cos.o: $(CSRCDIR)/cos.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/cos.c -o $(OBJDIR)/cos.o
+
+$(OBJDIR)/cosh.o: $(CSRCDIR)/cosh.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/cosh.c -o $(OBJDIR)/cosh.o
+
+$(OBJDIR)/sin.o: $(CSRCDIR)/sin.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/sin.c -o $(OBJDIR)/sin.o
+
+$(OBJDIR)/sinh.o: $(CSRCDIR)/sinh.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/sinh.c -o $(OBJDIR)/sinh.o
+
+$(OBJDIR)/FileManagement.o: $(CSRCDIR)/FileManagement.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/FileManagement.c -o $(OBJDIR)/FileManagement.o
+
+$(OBJDIR)/OpLogLt.o: $(CSRCDIR)/OpLogLt.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpLogLt.c -o $(OBJDIR)/OpLogLt.o
+
+$(OBJDIR)/OpLogGt.o: $(CSRCDIR)/OpLogGt.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpLogGt.c -o $(OBJDIR)/OpLogGt.o
+
+$(OBJDIR)/OpLogLe.o: $(CSRCDIR)/OpLogLe.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpLogLe.c -o $(OBJDIR)/OpLogLe.o
+
+$(OBJDIR)/OpLogGe.o: $(CSRCDIR)/OpLogGe.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpLogGe.c -o $(OBJDIR)/OpLogGe.o
+
+$(OBJDIR)/OpLogEq.o: $(CSRCDIR)/OpLogEq.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpLogEq.c -o $(OBJDIR)/OpLogEq.o
+
+$(OBJDIR)/Find.o: $(CSRCDIR)/Find.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/Find.c -o $(OBJDIR)/Find.o
+
+$(OBJDIR)/ConvertPrecision.o: $(CSRCDIR)/ConvertPrecision.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/ConvertPrecision.c -o $(OBJDIR)/ConvertPrecision.o
+
+$(OBJDIR)/SCI2Cfft.o: $(CSRCDIR)/SCI2Cfft.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/SCI2Cfft.c -o $(OBJDIR)/SCI2Cfft.o
+
+$(OBJDIR)/SCI2Cconvol.o: $(CSRCDIR)/SCI2Cconvol.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/SCI2Cconvol.c -o $(OBJDIR)/SCI2Cconvol.o
+
+$(OBJDIR)/sqrt.o: $(CSRCELEMFUNDIR)/sqrt/*sqrt*.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCELEMFUNDIR)/sqrt/*sqrt*.c -o $(OBJDIR)/sqrt.o
+
+$(OBJDIR)/ssqrts.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/ssqrts.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/ssqrts.c -o $(OBJDIR)/ssqrts.o
+
+$(OBJDIR)/dsqrts.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/dsqrts.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/dsqrts.c -o $(OBJDIR)/dsqrts.o
+
+$(OBJDIR)/csqrts.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/csqrts.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/csqrts.c -o $(OBJDIR)/csqrts.o
+
+$(OBJDIR)/zsqrts.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/zsqrts.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/zsqrts.c -o $(OBJDIR)/zsqrts.o
+
+$(OBJDIR)/ssqrta.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/ssqrta.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/ssqrta.c -o $(OBJDIR)/ssqrta.o
+
+$(OBJDIR)/dsqrta.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/dsqrta.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/dsqrta.c -o $(OBJDIR)/dsqrta.o
+
+$(OBJDIR)/csqrta.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/csqrta.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/csqrta.c -o $(OBJDIR)/csqrta.o
+
+$(OBJDIR)/zsqrta.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/zsqrta.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/zsqrta.c -o $(OBJDIR)/zsqrta.o
diff --git a/macros/CCodeGeneration/SCI2CMakefileTemplate.bkp1 b/macros/CCodeGeneration/SCI2CMakefileTemplate.bkp1 new file mode 100644 index 0000000..65184df --- /dev/null +++ b/macros/CCodeGeneration/SCI2CMakefileTemplate.bkp1 @@ -0,0 +1,230 @@ +
+# --- C COMPILER ---
+CC = gcc
+CFLAGS = -Wall -pedantic -O3 -I $(HSRCDIR)
+# ---------------------------
+# --- END USER PARAMETERS ---
+# ---------------------------
+
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+# DON'T TOUCH ANYTHING BELOW THIS LINE
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+
+ELEMENTARY_FUNCTIONS_DIR = $(CSRCDIR)/src/elementaryFunctions
+CFLAGS_ELEMENTARY_FUNCTIONS = -I $(ELEMENTARY_FUNCTIONS_DIR)/includes -I $(ELEMENTARY_FUNCTIONS_DIR)/interfaces
+
+
+EXEFILE = $(SCI2CDIR)/$(EXEFILENAME)
+
+objects = \
+ $(OBJDIR)/doubleComplex.o \
+ $(OBJDIR)/floatComplex.o \
+ $(OBJDIR)/RealToComplex.o \
+ $(OBJDIR)/conj.o \
+ $(OBJDIR)/disp.o \
+ $(OBJDIR)/ones.o \
+ $(OBJDIR)/zeros.o \
+ $(OBJDIR)/OpApex.o \
+ $(OBJDIR)/OpColon.o \
+ $(OBJDIR)/OpDotStar.o \
+ $(OBJDIR)/OpDotHat.o \
+ $(OBJDIR)/OpDotSlash.o \
+ $(OBJDIR)/OpEqual.o \
+ $(OBJDIR)/OpPlus.o \
+ $(OBJDIR)/OpMinus.o \
+ $(OBJDIR)/OpStar.o \
+ $(OBJDIR)/OpIns.o \
+ $(OBJDIR)/OpExt.o \
+ $(OBJDIR)/OpRc.o \
+ $(OBJDIR)/OpCc.o \
+ $(OBJDIR)/cos.o \
+ $(OBJDIR)/cosh.o \
+ $(OBJDIR)/sin.o \
+ $(OBJDIR)/sinh.o \
+ $(OBJDIR)/FileManagement.o \
+ $(OBJDIR)/OpLogLt.o \
+ $(OBJDIR)/OpLogGt.o \
+ $(OBJDIR)/OpLogGe.o \
+ $(OBJDIR)/OpLogLe.o \
+ $(OBJDIR)/OpLogEq.o \
+ $(OBJDIR)/Find.o \
+ $(OBJDIR)/ConvertPrecision.o \
+ $(OBJDIR)/SCI2Cfft.o \
+ $(OBJDIR)/SCI2Cconvol.o \
+ $(OBJDIR)/ssqrts.o \
+ $(OBJDIR)/dsqrts.o \
+ $(OBJDIR)/csqrts.o \
+ $(OBJDIR)/zsqrts.o \
+ $(OBJDIR)/ssqrta.o \
+ $(OBJDIR)/dsqrta.o \
+ $(OBJDIR)/csqrta.o \
+ $(OBJDIR)/zsqrta.o
+
+# ---------------
+# --- TARGETS ---
+# ---------------
+compileexecute: $(objects)
+ @echo " "
+ @echo "============================"
+ @echo "Generation of the executable"
+ @echo "============================"
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) $(objects) $(SCI2CDIR)/*.c -o $(EXEFILE)
+ @echo " "
+ @echo "=============="
+ @echo "Executing code"
+ @echo "=============="
+ $(EXEFILE)
+
+clean:
+ @echo " "
+ @echo "============================="
+ @echo "Removing only exe + obj files"
+ @echo "============================="
+ rm -rf $(EXEFILE)
+ rm -rf $(objects)
+ @echo " "
+
+cleanexe:
+ @echo " "
+ @echo "=========================="
+ @echo "Removing only the exe file"
+ @echo "=========================="
+ rm -rf $(EXEFILE)
+ @echo " "
+
+$(OBJDIR)/doubleComplex.o: $(CSRCDIR)/doubleComplex.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/doubleComplex.c -o $(OBJDIR)/doubleComplex.o
+
+$(OBJDIR)/floatComplex.o: $(CSRCDIR)/floatComplex.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/floatComplex.c -o $(OBJDIR)/floatComplex.o
+
+$(OBJDIR)/RealToComplex.o: $(CSRCDIR)/RealToComplex.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/RealToComplex.c -o $(OBJDIR)/RealToComplex.o
+
+$(OBJDIR)/conj.o: $(CSRCDIR)/conj.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/conj.c -o $(OBJDIR)/conj.o
+
+$(OBJDIR)/disp.o: $(CSRCDIR)/disp.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/disp.c -o $(OBJDIR)/disp.o
+
+$(OBJDIR)/zeros.o: $(CSRCDIR)/zeros.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/zeros.c -o $(OBJDIR)/zeros.o
+
+$(OBJDIR)/ones.o: $(CSRCDIR)/ones.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/ones.c -o $(OBJDIR)/ones.o
+
+$(OBJDIR)/OpApex.o: $(CSRCDIR)/OpApex.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpApex.c -o $(OBJDIR)/OpApex.o
+
+$(OBJDIR)/OpColon.o: $(CSRCDIR)/OpColon.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpColon.c -o $(OBJDIR)/OpColon.o
+
+$(OBJDIR)/OpDotStar.o: $(CSRCDIR)/OpDotStar.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpDotStar.c -o $(OBJDIR)/OpDotStar.o
+
+$(OBJDIR)/OpDotHat.o: $(CSRCDIR)/OpDotHat.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpDotHat.c -o $(OBJDIR)/OpDotHat.o
+
+$(OBJDIR)/OpDotSlash.o: $(CSRCDIR)/OpDotSlash.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpDotSlash.c -o $(OBJDIR)/OpDotSlash.o
+
+$(OBJDIR)/OpEqual.o: $(CSRCDIR)/OpEqual.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpEqual.c -o $(OBJDIR)/OpEqual.o
+
+$(OBJDIR)/OpPlus.o: $(CSRCDIR)/OpPlus.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpPlus.c -o $(OBJDIR)/OpPlus.o
+
+$(OBJDIR)/OpMinus.o: $(CSRCDIR)/OpMinus.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpMinus.c -o $(OBJDIR)/OpMinus.o
+
+$(OBJDIR)/OpStar.o: $(CSRCDIR)/OpStar.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpStar.c -o $(OBJDIR)/OpStar.o
+
+$(OBJDIR)/OpIns.o: $(CSRCDIR)/OpIns.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpIns.c -o $(OBJDIR)/OpIns.o
+
+$(OBJDIR)/OpExt.o: $(CSRCDIR)/OpExt.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpExt.c -o $(OBJDIR)/OpExt.o
+
+$(OBJDIR)/OpRc.o: $(CSRCDIR)/OpRc.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpRc.c -o $(OBJDIR)/OpRc.o
+
+$(OBJDIR)/OpCc.o: $(CSRCDIR)/OpCc.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpCc.c -o $(OBJDIR)/OpCc.o
+
+$(OBJDIR)/cos.o: $(CSRCDIR)/cos.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/cos.c -o $(OBJDIR)/cos.o
+
+$(OBJDIR)/cosh.o: $(CSRCDIR)/cosh.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/cosh.c -o $(OBJDIR)/cosh.o
+
+$(OBJDIR)/sin.o: $(CSRCDIR)/sin.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/sin.c -o $(OBJDIR)/sin.o
+
+$(OBJDIR)/sinh.o: $(CSRCDIR)/sinh.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/sinh.c -o $(OBJDIR)/sinh.o
+
+$(OBJDIR)/FileManagement.o: $(CSRCDIR)/FileManagement.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/FileManagement.c -o $(OBJDIR)/FileManagement.o
+
+$(OBJDIR)/OpLogLt.o: $(CSRCDIR)/OpLogLt.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpLogLt.c -o $(OBJDIR)/OpLogLt.o
+
+$(OBJDIR)/OpLogGt.o: $(CSRCDIR)/OpLogGt.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpLogGt.c -o $(OBJDIR)/OpLogGt.o
+
+$(OBJDIR)/OpLogLe.o: $(CSRCDIR)/OpLogLe.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpLogLe.c -o $(OBJDIR)/OpLogLe.o
+
+$(OBJDIR)/OpLogGe.o: $(CSRCDIR)/OpLogGe.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpLogGe.c -o $(OBJDIR)/OpLogGe.o
+
+$(OBJDIR)/OpLogEq.o: $(CSRCDIR)/OpLogEq.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/OpLogEq.c -o $(OBJDIR)/OpLogEq.o
+
+$(OBJDIR)/Find.o: $(CSRCDIR)/Find.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/Find.c -o $(OBJDIR)/Find.o
+
+$(OBJDIR)/ConvertPrecision.o: $(CSRCDIR)/ConvertPrecision.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/ConvertPrecision.c -o $(OBJDIR)/ConvertPrecision.o
+
+$(OBJDIR)/SCI2Cfft.o: $(CSRCDIR)/SCI2Cfft.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/SCI2Cfft.c -o $(OBJDIR)/SCI2Cfft.o
+
+$(OBJDIR)/SCI2Cconvol.o: $(CSRCDIR)/SCI2Cconvol.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCDIR)/SCI2Cconvol.c -o $(OBJDIR)/SCI2Cconvol.o
+
+$(OBJDIR)/sqrt.o: $(CSRCELEMFUNDIR)/sqrt/*sqrt*.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) -c $(CSRCELEMFUNDIR)/sqrt/*sqrt*.c -o $(OBJDIR)/sqrt.o
+
+$(OBJDIR)/ssqrts.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/ssqrts.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/ssqrts.c -o $(OBJDIR)/ssqrts.o
+
+$(OBJDIR)/dsqrts.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/dsqrts.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/dsqrts.c -o $(OBJDIR)/dsqrts.o
+
+$(OBJDIR)/csqrts.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/csqrts.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/csqrts.c -o $(OBJDIR)/csqrts.o
+
+$(OBJDIR)/zsqrts.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/zsqrts.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/zsqrts.c -o $(OBJDIR)/zsqrts.o
+
+$(OBJDIR)/ssqrta.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/ssqrta.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/ssqrta.c -o $(OBJDIR)/ssqrta.o
+
+$(OBJDIR)/dsqrta.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/dsqrta.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/dsqrta.c -o $(OBJDIR)/dsqrta.o
+
+$(OBJDIR)/csqrta.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/csqrta.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/csqrta.c -o $(OBJDIR)/csqrta.o
+
+$(OBJDIR)/zsqrta.o: $(CSRCDIR)/src/elementaryFunctions/sqrt/zsqrta.c $(HSRCDIR)/*.h
+ $(CC) $(CFLAGS) $(CFLAGS_ELEMENTARY_FUNCTIONS) -c $(ELEMENTARY_FUNCTIONS_DIR)/sqrt/zsqrta.c -o $(OBJDIR)/zsqrta.o
diff --git a/macros/CCodeGeneration/SCI2CMakefileTemplate.bkp2 b/macros/CCodeGeneration/SCI2CMakefileTemplate.bkp2 new file mode 100644 index 0000000..c6ba2a9 --- /dev/null +++ b/macros/CCodeGeneration/SCI2CMakefileTemplate.bkp2 @@ -0,0 +1,126 @@ +
+# --- C COMPILER ---
+CC = gcc
+CFLAGS = -Wall -pedantic -O3 -I $(HSRCDIR) -I $(ISRCDIR)
+# ---------------------------
+# --- END USER PARAMETERS ---
+# ---------------------------
+
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+# DON'T TOUCH ANYTHING BELOW THIS LINE
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+# ------------------------------------
+
+EXEFILE = $(SCI2CDIR)/$(EXEFILENAME)
+
+SWSRCS = \
+ $(CSRCDIR)/doubleComplex.c \
+ $(CSRCDIR)/floatComplex.c \
+ $(CSRCDIR)/RealToComplex.c \
+ $(CSRCDIR)/conj.c \
+ $(CSRCDIR)/disp.c \
+ $(CSRCDIR)/ones.c \
+ $(CSRCDIR)/zeros.c \
+ $(CSRCDIR)/OpApex.c \
+ $(CSRCDIR)/OpColon.c \
+ $(CSRCDIR)/OpDotStar.c \
+ $(CSRCDIR)/OpDotHat.c \
+ $(CSRCDIR)/OpDotSlash.c \
+ $(CSRCDIR)/OpEqual.c \
+ $(CSRCDIR)/OpPlus.c \
+ $(CSRCDIR)/OpMinus.c \
+ $(CSRCDIR)/OpStar.c \
+ $(CSRCDIR)/OpIns.c \
+ $(CSRCDIR)/OpExt.c \
+ $(CSRCDIR)/OpRc.c \
+ $(CSRCDIR)/OpCc.c \
+ $(CSRCDIR)/cos.c \
+ $(CSRCDIR)/cosh.c \
+ $(CSRCDIR)/sin.c \
+ $(CSRCDIR)/sinh.c \
+ $(CSRCDIR)/FileManagement.c \
+ $(CSRCDIR)/OpLogLt.c \
+ $(CSRCDIR)/OpLogGt.c \
+ $(CSRCDIR)/OpLogGe.c \
+ $(CSRCDIR)/OpLogLe.c \
+ $(CSRCDIR)/OpLogEq.c \
+ $(CSRCDIR)/OpLogOr.c \
+ $(CSRCDIR)/OpLogAnd.c \
+ $(CSRCDIR)/Find.c \
+ $(CSRCDIR)/ConvertPrecision.c \
+ $(CSRCDIR)/SCI2Cfft.c \
+ $(CSRCDIR)/SCI2Cconvol.c \
+ $(CSRCDIR)/ssqrts.c \
+ $(CSRCDIR)/dsqrts.c \
+ $(CSRCDIR)/csqrts.c \
+ $(CSRCDIR)/zsqrts.c \
+ $(CSRCDIR)/ssqrta.c \
+ $(CSRCDIR)/dsqrta.c \
+ $(CSRCDIR)/csqrta.c \
+ $(CSRCDIR)/zsqrta.c \
+ $(CSRCDIR)/sabss.c \ + $(CSRCDIR)/dabss.c \ + $(CSRCDIR)/cabss.c \ + $(CSRCDIR)/zabss.c \ + $(CSRCDIR)/sabsa.c \ + $(CSRCDIR)/dabsa.c \ + $(CSRCDIR)/cabsa.c \ + $(CSRCDIR)/zabsa.c \ + $(CSRCDIR)/sexps.c \ + $(CSRCDIR)/dexps.c \ + $(CSRCDIR)/cexps.c \ + $(CSRCDIR)/zexps.c \ + $(CSRCDIR)/sexpa.c \ + $(CSRCDIR)/dexpa.c \ + $(CSRCDIR)/cexpa.c \ + $(CSRCDIR)/zexpa.c +
+SWOBJS = $(SWSRCS:.c=.o) +
+# ---------------
+# --- TARGETS ---
+# ---------------
+compileexecute: $(SWOBJS)
+ @echo " "
+ @echo "============================"
+ @echo "Generation of the executable"
+ @echo "============================"
+ $(CC) $(CFLAGS) $(SWOBJS) $(SCI2CDIR)/*.c -o $(EXEFILE)
+ @echo " "
+ @echo "=============="
+ @echo "Executing code"
+ @echo "=============="
+ $(EXEFILE)
+
+clean:
+ @echo " "
+ @echo "============================="
+ @echo "Removing only exe + obj files"
+ @echo "============================="
+ rm -rf $(EXEFILE)
+ rm -rf $(SWOBJS)
+ @echo " "
+
+cleanexe:
+ @echo " "
+ @echo "=========================="
+ @echo "Removing only the exe file"
+ @echo "=========================="
+ rm -rf $(EXEFILE)
+ @echo " "
+
+# how to compile object code .o from C source files .c (general rule) +# space between -o and filename for SUN make +.c.o: + $(CC) $(CFLAGS) -c -o $(@) $<
+
+# Make object code from source +swobjs: $(SWOBJS) +
diff --git a/macros/CCodeGeneration/Sci2AnnotationFile.sci b/macros/CCodeGeneration/Sci2AnnotationFile.sci new file mode 100644 index 0000000..001ed25 --- /dev/null +++ b/macros/CCodeGeneration/Sci2AnnotationFile.sci @@ -0,0 +1,55 @@ +function Sci2AnnotationFile(SciFileName,ClsFileName,AnnFileName,AnnSpecifier,ReportFileName) +// function Sci2AnnotationFile(SciFileName,ClsFileName,AnnFileName,AnnSpecifier,ReportFileName) +// -------------------------------------------------------------------------------- +// #RNU_RES_B +// This function reads the .sci input file and generates the correspondig .ann +// and .acls files. +// #RNU_RES_E +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 25-Jun-2007 -- Nutricato Raffaele: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),5,5); + +[tmppath,tmpfunname,tmpext] = fileparts(SciFileName); + +// --------------------------------------- +// --- Open the .sci file (read only). --- +// --------------------------------------- +inscifid = SCI2COpenFileRead(SciFileName); + +// ---------------------------------------------- +// --- Loop over the lines of the input file. --- +// ---------------------------------------------- +line_position = 0; +L_AnnSpecifierP1 = length(AnnSpecifier)+1; +while (meof(inscifid) == 0) + check_string = stripblanks(mgetl(inscifid,1)); + line_position = line_position + 1; + L_string = length(check_string); + if (L_string >= 1) + if (SCI2Cstrncmps1size(AnnSpecifier,check_string)) + tmpannotation = stripblanks(part(check_string,L_AnnSpecifierP1:L_string)); + PrintStringInfo(tmpannotation,ClsFileName,'file','y'); + end + end +end +mclose(inscifid); +// -------------------------------------------------- +// --- End loop over the lines of the input file. --- +// -------------------------------------------------- +PrintStringInfo('CLASS: '+tmpfunname,AnnFileName,'file','y'); +endfunction diff --git a/macros/CCodeGeneration/buildmacros.sce b/macros/CCodeGeneration/buildmacros.sce new file mode 100644 index 0000000..60fd284 --- /dev/null +++ b/macros/CCodeGeneration/buildmacros.sce @@ -0,0 +1,15 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2009-2009 - DIGITEO - Bruno JOFRET +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// +// + +tbx_build_macros(TOOLBOX_NAME, get_absolute_file_path('buildmacros.sce')); + +clear tbx_build_macros; diff --git a/macros/CCodeGeneration/lib b/macros/CCodeGeneration/lib Binary files differnew file mode 100644 index 0000000..8316c66 --- /dev/null +++ b/macros/CCodeGeneration/lib diff --git a/macros/CCodeGeneration/names b/macros/CCodeGeneration/names new file mode 100644 index 0000000..5311c7f --- /dev/null +++ b/macros/CCodeGeneration/names @@ -0,0 +1,24 @@ +C_FinalizeCode +C_ForExpression +C_Funcall +C_GenDeclarations +C_GenerateFunName +C_GenerateLaunchScript +C_GenerateMakefile +C_GenerateMakefile_msvc +C_GenerateMkfle_arduino +C_GenerateSCI2CHeader +C_IfElseBlocks +C_IfExpression +C_IndentBlanks +C_InitHeader +C_MemAllocOutTempVars +C_SCI2CHeader +C_Type +C_WhileExpression +GenCFunDatFiles +GetClsFileName +GetSymbolDimension +GetWhileCondVariable +JoinDeclarAndCcode +Sci2AnnotationFile |