Browse Source

Added functionality for:
Extracting framework from jar,
Fmu.cpp generation,
main.cpp generation and
CMakeLists.txt generation

Casper Thule 7 years ago
parent
commit
e6c5fd32e3

+ 62 - 26
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest.xtend

@@ -3,39 +3,38 @@
  */
 package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests
 
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation.BuildUtilities
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation.CppGenerator
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
 import be.uantwerpen.ansymo.semanticadaptation.tests.AbstractSemanticAdaptationTest
 import be.uantwerpen.ansymo.semanticadaptation.tests.SemanticAdaptationInjectorProvider
 import com.google.inject.Inject
+import java.io.File
+import java.io.FileWriter
+import java.nio.file.Files
 import java.util.regex.Pattern
 import org.eclipse.emf.ecore.EObject
+import org.eclipse.emf.ecore.resource.ResourceSet
+import org.eclipse.xtext.generator.IGeneratorContext
+import org.eclipse.xtext.generator.InMemoryFileSystemAccess
 import org.eclipse.xtext.testing.InjectWith
 import org.eclipse.xtext.testing.XtextRunner
 import org.eclipse.xtext.testing.util.ParseHelper
 import org.eclipse.xtext.testing.validation.ValidationTestHelper
 import org.junit.Test
 import org.junit.runner.RunWith
-import org.eclipse.xtext.generator.InMemoryFileSystemAccess
-import org.eclipse.xtext.generator.IGeneratorContext
-import org.eclipse.emf.ecore.resource.ResourceSet
-import org.junit.Ignore
-import java.io.File
-import java.io.PrintWriter
-import java.nio.file.Files
-import java.io.FileWriter
-import org.eclipse.xtext.junit4.ui.AbstractAutoEditTest
-import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation.CppGenerator
+import be.uantwerpen.ansymo.semanticadaptation.testframework.StaticGenerators
 
 @RunWith(XtextRunner)
 @InjectWith(SemanticAdaptationInjectorProvider)
 class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 
-	// @Inject CppGenerator underTest
+// @Inject CppGenerator underTest
 	@Inject extension ParseHelper<SemanticAdaptation>
 	@Inject extension  ValidationTestHelper
 
 	@Test def powerwindow_model_only() {
-		__parseNoErrors('test_input/single_folder_spec/window/window_sa_canonical.BASE.sa');
+		__parseNoErrors('test_input/single_folder_spec/window/window_sa_canonical.BASE.sa', 'generated', "powerwindow");
 //		__parseNoErrorsWithValidation('test_input/single_folder_spec/window',
 //			'test_input/single_folder_spec/window/window_sa_canonical.BASE.sa');
 	}
@@ -88,7 +87,30 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 
 	}
 
-	def __parseNoErrors(String filename) {
+	def void deleteFolder(File folder) {
+		var	files = folder.listFiles();
+		if (files !== null) { // some JVMs return null for empty dirs
+			for (File f : files) {
+				if (f.isDirectory()) {
+					deleteFolder(f);
+				} else {
+					f.delete();
+				}
+			}
+		}
+		folder.delete();
+	}
+
+	def void writeToFile(File file, String content)
+	{
+		val FileWriter writer = new FileWriter(file);
+		writer.write(content);
+		writer.close;
+		System.out.println("Stored file at: " + file.absolutePath);
+	}
+
+	def __parseNoErrors(String filename, String directory, String projectName) {
+		val buildUtils = new BuildUtilities();
 		val model = __parse(filename)
 		__assertNoParseErrors(model, filename)
 
@@ -96,24 +118,35 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 		val IGeneratorContext ctxt = null;
 		new CppGenerator().doGenerate(model.eResource, fsa, ctxt);
 
+		var genPath = new File(directory);
+		System.out.println(genPath.absolutePath)
+		if (genPath.exists) {
+			deleteFolder(genPath);
+		}
+		
+		val srcGenPath = new File(directory + File.separatorChar + "src")
+		srcGenPath.mkdirs();	
+
 		for (files : fsa.allFiles.entrySet) {
 //			System.out.println("########################")
 //			System.out.println("Filename: " + files.key.substring(14))
 //			System.out.println(files.value)
-			var path = new File("generated");
-			if (path.exists)
-				path.delete
-			else
-				path.mkdir;
-
-			path = new File(path, files.key.substring(14))
+			val path = new File(srcGenPath, files.key.substring(14))
 
-			val FileWriter writer = new FileWriter(path);
-			writer.write(files.value.toString);
-			writer.close;
-			System.out.println("Stored file: " + files.key.substring(14) + " at: " + path.absolutePath);
+			writeToFile(path, files.value.toString);
 		}
-	// System.out.println(fsa.allFiles)		
+		
+		val mainCpp = StaticGenerators.generateMainCppFile((new File(directory)).absolutePath.replace("\\","\\\\"));
+		writeToFile(new File(srcGenPath,"main.cpp"), mainCpp);
+		
+		var saFrameworkPath = new File(directory + File.separatorChar + "framework")
+		saFrameworkPath.mkdirs();
+		buildUtils.copyNativeLibFiles(saFrameworkPath);
+		System.out.println("Stored sa framework at: " + saFrameworkPath.absolutePath);
+		
+		writeToFile(new File(genPath,"CMakeLists.txt"), StaticGenerators.generateCMakeLists(projectName, "framework"));
+		
+		
 	}
 
 	def __parseNoErrorsPrint(String filename) {
@@ -126,7 +159,10 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 		return readFile(filename).parse
 	}
 
-	def __parse(String filename, ResourceSet resourceSetToUse) {
+	def __parse(
+		String filename,
+		ResourceSet resourceSetToUse
+	) {
 
 		return readFile(filename).parse(resourceSetToUse)
 	}

+ 73 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/BuildUtilities.java

@@ -0,0 +1,73 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+
+public class BuildUtilities {
+	public List<File> copyNativeLibFiles(File outfolder) {
+		List<File> libFiles;
+		File outputFile = null;
+		InputStream jarfile = null;
+		FileOutputStream fos = null;
+		JarInputStream jarstream = null;
+		JarEntry filejarentry = null;
+
+		if (!outfolder.exists()) {
+			outfolder.mkdir();
+		}
+
+		libFiles = new LinkedList<>();
+
+		try {
+			jarfile = this.getClass().getClassLoader().getResourceAsStream("jars/cppFramework.jar");
+			jarstream = new JarInputStream(jarfile);
+			filejarentry = jarstream.getNextJarEntry();
+
+			// Extract the framework files
+			while (filejarentry != null) {
+				if (!filejarentry.getName().contains("hybridCosimulation-framework") || filejarentry.isDirectory()) {
+					filejarentry = jarstream.getNextJarEntry();
+					continue;
+				}
+
+				// Ignore these files
+				if (filejarentry.getName().contains(".gitignore") || filejarentry.getName().contains(".gitmodules")
+						/*|| filejarentry.getName().contains("README.md")*/ || filejarentry.getName().contains("LICENSE")) {
+					filejarentry = jarstream.getNextJarEntry();
+					continue;
+				}
+				String tmpFileName = filejarentry.getName().replace("hybridCosimulation-framework/", "");
+
+				outputFile = new File(outfolder.toString() + File.separator + tmpFileName);
+
+				libFiles.add(new File(outfolder.getName() + File.separator + tmpFileName));
+
+				outputFile.getParentFile().mkdirs();
+				fos = new FileOutputStream(outputFile);
+
+				while (jarstream.available() > 0) {
+					int b = jarstream.read();
+					if (b >= 0) {
+						fos.write(b);
+					}
+				}
+				fos.flush();
+				fos.close();
+				jarstream.closeEntry();
+				filejarentry = jarstream.getNextJarEntry();
+			}
+			jarstream.close();
+			jarfile.close();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+
+		return libFiles;
+	}
+}

+ 4 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend

@@ -169,6 +169,10 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			val modelDescCreator = new ModelDescriptionCreator(adapExternalName);
 			val modelDescription = modelDescCreator.generateModelDescription(SASVs.values);
 			fsa.generateFile("modelDescription.xml", modelDescription);
+			
+			// Compile the fmu.cpp file
+			val fmuCppFile = StaticGenerators.GenFmuCppFile(adapClassName);
+			fsa.generateFile("Fmu.cpp", fmuCppFile);
 
 		}
 	}

+ 406 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/StaticGenerators.xtend

@@ -0,0 +1,406 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation
+
+class StaticGenerators {
+	def static String GenFmuCppFile(String adapClassName)
+	{
+		'''
+		#include "fmi2Functions.h"
+		#include <string>
+		
+		#include "«adapClassName».h"
+		
+		#include "uri.h"
+		
+		using namespace std;
+		
+		const fmi2CallbackFunctions *g_functions;
+		std::string* name;
+		
+		shared_ptr<adaptation::«adapClassName»> g_adaptation;
+		
+		template<class T>
+		static void log(const fmi2CallbackFunctions *functions,
+				fmi2ComponentEnvironment componentEnvironment, fmi2String instanceName,
+				fmi2Status status, fmi2String category, fmi2String message, T arg) {
+			if (functions != NULL && functions->logger != NULL) {
+				functions->logger(componentEnvironment, instanceName, status, category,
+						message, arg);
+			}
+		}
+		
+		static void notimplemented(fmi2Component c, fmi2String message) {
+			std::string base("Not implemented: %s");
+			std::string m(message);
+			if (g_functions != NULL) {
+				log(g_functions, (void*) 2, "", fmi2Error, "error", (base + m).c_str(),
+						"");
+			}
+		}
+		
+		template<class T>
+		static void fmiprintf(fmi2String message, T arg) {
+			if (g_functions != NULL) {
+				log(g_functions, (void*) 2, name->c_str(), fmi2OK, "logAll", message,
+						arg);
+			}
+		}
+		
+		// ---------------------------------------------------------------------------
+		// FMI functions
+		// ---------------------------------------------------------------------------
+		extern "C" fmi2Component fmi2Instantiate(fmi2String instanceName,
+				fmi2Type fmuType, fmi2String fmuGUID, fmi2String fmuResourceLocation,
+				const fmi2CallbackFunctions *functions, fmi2Boolean visible,
+				fmi2Boolean loggingOn) {
+			name = new std::string(instanceName);
+			g_functions = functions;
+			fmiprintf("instantiating %s\n", instanceName);
+			auto resourceLoc = make_shared<std::string>(fmuResourceLocation);
+			g_adaptation = make_shared<adaptation::«adapClassName»>(resourceLoc,functions);
+			g_adaptation->initialize();
+		
+			if (g_adaptation->getLastErrorState() != fmi2OK)
+				return NULL;
+		
+			return g_adaptation->getComponent();
+		}
+		
+		extern "C" fmi2Status fmi2SetupExperiment(fmi2Component c,
+				fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime,
+				fmi2Boolean stopTimeDefined, fmi2Real stopTime) {
+		
+			return g_adaptation->fmi2SetupExperiment(toleranceDefined, tolerance,
+					startTime, stopTimeDefined, stopTime);
+		}
+		
+		extern "C" fmi2Status fmi2EnterInitializationMode(fmi2Component c) {
+			return g_adaptation->fmi2EnterInitializationMode();
+		}
+		
+		extern "C" fmi2Status fmi2ExitInitializationMode(fmi2Component c) {
+			return g_adaptation->fmi2ExitInitializationMode();
+		}
+		
+		extern "C" fmi2Status fmi2Terminate(fmi2Component c) {
+			return g_adaptation->fmi2Terminate();
+		}
+		
+		extern "C" fmi2Status fmi2Reset(fmi2Component c) {
+			return fmi2OK;
+		}
+		
+		extern "C" void fmi2FreeInstance(fmi2Component c) {
+		
+		}
+		
+		// ---------------------------------------------------------------------------
+		// FMI functions: class methods not depending of a specific model instance
+		// ---------------------------------------------------------------------------
+		
+		extern "C" const char* fmi2GetVersion() {
+			return fmi2Version;
+		}
+		
+		extern "C" const char* fmi2GetTypesPlatform() {
+			return fmi2TypesPlatform;
+		}
+		
+		// ---------------------------------------------------------------------------
+		// FMI functions: logging control, setters and getters for Real, Integer,
+		// Boolean, String
+		// ---------------------------------------------------------------------------
+		
+		extern "C" fmi2Status fmi2SetDebugLogging(fmi2Component c,
+				fmi2Boolean loggingOn, size_t nCategories,
+				const fmi2String categories[]) {
+			return fmi2OK;
+		}
+		
+		extern "C" fmi2Status fmi2GetReal(fmi2Component c,
+				const fmi2ValueReference vr[], size_t nvr, fmi2Real value[]) {
+			fmi2Status status = g_adaptation->executeOutRules();
+			if (status != fmi2OK)
+				return status;
+		
+			status = g_adaptation->flushAllEnabledOutRules();
+			if (status != fmi2OK)
+				return status;
+		
+			for (int i = 0; i < nvr; i++) {
+				value[i] = g_adaptation->getFmiValueReal(vr[i]);
+		
+				status = g_adaptation->getLastErrorState();
+				if (status != fmi2OK)
+					return status;
+			}
+		
+			return fmi2OK;
+		}
+		
+		extern "C" fmi2Status fmi2GetInteger(fmi2Component c,
+				const fmi2ValueReference vr[], size_t nvr, fmi2Integer value[]) {
+		
+			fmi2Status status = g_adaptation->executeOutRules();
+			if (status != fmi2OK)
+				return status;
+			status = g_adaptation->flushAllEnabledOutRules();
+			if (status != fmi2OK)
+				return status;
+		
+			for (int i = 0; i < nvr; i++) {
+				value[i] = g_adaptation->getFmiValueInteger(vr[i]);
+		
+				status = g_adaptation->getLastErrorState();
+				if (status != fmi2OK)
+					return status;
+			}
+		
+			return fmi2OK;
+		}
+		
+		extern "C" fmi2Status fmi2GetBoolean(fmi2Component c,
+				const fmi2ValueReference vr[], size_t nvr, fmi2Boolean value[]) {
+		
+			fmi2Status status = g_adaptation->executeOutRules();
+			if (status != fmi2OK)
+				return status;
+			status = g_adaptation->flushAllEnabledOutRules();
+			if (status != fmi2OK)
+				return status;
+		
+			for (int i = 0; i < nvr; i++) {
+				value[i] = g_adaptation->getFmiValueBoolean(vr[i]);
+		
+				status = g_adaptation->getLastErrorState();
+				if (status != fmi2OK)
+					return status;
+			}
+		
+			return fmi2OK;
+		}
+		
+		extern "C" fmi2Status fmi2GetString(fmi2Component c,
+				const fmi2ValueReference vr[], size_t nvr, fmi2String value[]) {
+		
+			fmi2Status status = g_adaptation->executeOutRules();
+			if (status != fmi2OK)
+				return status;
+			status = g_adaptation->flushAllEnabledOutRules();
+			if (status != fmi2OK)
+				return status;
+		
+			return fmi2OK;
+		}
+		
+		extern "C" fmi2Status fmi2SetReal(fmi2Component c,
+				const fmi2ValueReference vr[], size_t nvr, const fmi2Real value[]) {
+			fmi2Status status = fmi2OK;
+			for (int i = 0; i < nvr; i++) {
+		//		g_functions->logger((void*) 2, name->c_str(), fmi2OK, "logAll", "setting real vr=%d, value: %f\n", vr[i], value[i]);
+				g_adaptation->setFmiValue(vr[i], value[i]);
+		
+				status = g_adaptation->getLastErrorState();
+				if (status != fmi2OK)
+					return status;
+			}
+		
+		//	g_functions->logger((void*) 2, name->c_str(), fmi2OK, "logAll", "setting real executing in rules");
+			status = g_adaptation->executeInRules();
+			return status;
+		}
+		
+		extern "C" fmi2Status fmi2SetInteger(fmi2Component c,
+				const fmi2ValueReference vr[], size_t nvr, const fmi2Integer value[]) {
+			fmi2Status status = fmi2OK;
+			for (int i = 0; i < nvr; i++) {
+				g_adaptation->setFmiValue(vr[i], value[i]);
+		
+				status = g_adaptation->getLastErrorState();
+				if (status != fmi2OK)
+					return status;
+			}
+		
+			status = g_adaptation->executeInRules();
+			return status;
+		}
+		
+		extern "C" fmi2Status fmi2SetBoolean(fmi2Component c,
+				const fmi2ValueReference vr[], size_t nvr, const fmi2Boolean value[]) {
+			fmi2Status status = fmi2OK;
+			for (int i = 0; i < nvr; i++) {
+				g_adaptation->setFmiValue(vr[i], value[i]);
+		
+				status = g_adaptation->getLastErrorState();
+				if (status != fmi2OK)
+					return status;
+			}
+			status = g_adaptation->executeInRules();
+			return status;
+		}
+		
+		extern "C" fmi2Status fmi2SetString(fmi2Component c,
+				const fmi2ValueReference vr[], size_t nvr, const fmi2String value[]) {
+		
+			fmi2Status status = g_adaptation->executeInRules();
+			return status;
+		}
+		
+		extern "C" fmi2Status fmi2GetFMUstate(fmi2Component c, fmi2FMUstate* FMUstate) {
+			return fmi2OK;
+		}
+		extern "C" fmi2Status fmi2SetFMUstate(fmi2Component c, fmi2FMUstate FMUstate) {
+			return fmi2OK;
+		}
+		extern "C" fmi2Status fmi2FreeFMUstate(fmi2Component c,
+				fmi2FMUstate* FMUstate) {
+			return fmi2OK;
+		}
+		
+		extern "C" fmi2Status fmi2SerializedFMUstateSize(fmi2Component c,
+				fmi2FMUstate FMUstate, size_t *size) {
+			notimplemented(c, "fmi2SerializedFMUstateSize");
+			return fmi2Error;
+		}
+		extern "C" fmi2Status fmi2SerializeFMUstate(fmi2Component c,
+				fmi2FMUstate FMUstate, fmi2Byte serializedState[], size_t size) {
+			notimplemented(c, "fmi2SerializeFMUstate");
+			return fmi2Error;
+		}
+		extern "C" fmi2Status fmi2DeSerializeFMUstate(fmi2Component c,
+				const fmi2Byte serializedState[], size_t size, fmi2FMUstate* FMUstate) {
+			notimplemented(c, "fmi2DeSerializeFMUstate");
+			return fmi2Error;
+		}
+		
+		extern "C" fmi2Status fmi2GetDirectionalDerivative(fmi2Component c,
+				const fmi2ValueReference vUnknown_ref[], size_t nUnknown,
+				const fmi2ValueReference vKnown_ref[], size_t nKnown,
+				const fmi2Real dvKnown[], fmi2Real dvUnknown[]) {
+			notimplemented(c, "fmi2GetDirectionalDerivative");
+			return fmi2Error;
+		}
+		
+		// ---------------------------------------------------------------------------
+		// Functions for FMI for Co-Simulation
+		// ---------------------------------------------------------------------------
+		#ifdef FMI_COSIMULATION
+		/* Simulating the slave */
+		extern "C" fmi2Status fmi2SetRealInputDerivatives(fmi2Component c, const fmi2ValueReference vr[], size_t nvr,
+				const fmi2Integer order[], const fmi2Real value[])
+		{
+			notimplemented(c, "fmi2SetRealInputDerivatives");
+			return fmi2Error;
+		}
+		
+		extern "C" fmi2Status fmi2GetRealOutputDerivatives(fmi2Component c, const fmi2ValueReference vr[], size_t nvr,
+				const fmi2Integer order[], fmi2Real value[])
+		{
+			notimplemented(c, "fmi2GetRealOutputDerivatives");
+			return fmi2Error;
+		}
+		
+		extern "C" fmi2Status fmi2CancelStep(fmi2Component c)
+		{
+			notimplemented(c, "fmi2CancelStep");
+			return fmi2Error;
+		}
+		
+		extern "C" fmi2Status fmi2DoStep(fmi2Component c, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize,
+				fmi2Boolean noSetFMUStatePriorToCurrentPoint)
+		{
+		//	fmiprintf("doStep%s\n", "");
+		
+			g_adaptation->executeControlFlow(currentCommunicationPoint, communicationStepSize);
+			return fmi2OK;
+		}
+		
+		extern "C" fmi2Status fmi2GetStatus(fmi2Component c, const fmi2StatusKind s, fmi2Status *value)
+		{
+			return fmi2OK;
+		}
+		
+		extern "C" fmi2Status fmi2GetRealStatus(fmi2Component c, const fmi2StatusKind s, fmi2Real *value)
+		{
+			return fmi2OK;
+		}
+		
+		extern "C" fmi2Status fmi2GetIntegerStatus(fmi2Component c, const fmi2StatusKind s, fmi2Integer *value)
+		{
+			return fmi2OK;
+		}
+		
+		extern "C" fmi2Status fmi2GetBooleanStatus(fmi2Component c, const fmi2StatusKind s, fmi2Boolean *value)
+		{
+			return fmi2OK;
+		}
+		
+		extern "C" fmi2Status fmi2GetStringStatus(fmi2Component c, const fmi2StatusKind s, fmi2String *value)
+		{
+			return fmi2OK;
+		}
+		
+		/* INTO cps specific*/
+		/*extern "C" fmi2Status fmi2GetMaxStepsize(fmi2Component c, fmi2Real* size)
+		 {
+		 return fmi2OK;
+		 }*/
+		
+		// ---------------------------------------------------------------------------
+		// Functions for FMI2 for Model Exchange
+		// ---------------------------------------------------------------------------
+		#else
+		/* Enter and exit the different modes */
+		fmi2Status fmi2EnterEventMode(fmi2Component c) {
+			return fmi2Error;
+		}
+		
+		fmi2Status fmi2NewDiscreteStates(fmi2Component c, fmi2EventInfo *eventInfo) {
+			return fmi2Error;
+		}
+		
+		fmi2Status fmi2EnterContinuousTimeMode(fmi2Component c) {
+			return fmi2Error;
+		}
+		
+		fmi2Status fmi2CompletedIntegratorStep(fmi2Component c,
+				fmi2Boolean noSetFMUStatePriorToCurrentPoint,
+				fmi2Boolean *enterEventMode, fmi2Boolean *terminateSimulation) {
+			return fmi2Error;
+		}
+		
+		/* Providing independent variables and re-initialization of caching */
+		fmi2Status fmi2SetTime(fmi2Component c, fmi2Real time) {
+			return fmi2Error;
+		}
+		
+		fmi2Status fmi2SetContinuousStates(fmi2Component c, const fmi2Real x[],
+				size_t nx) {
+			return fmi2Error;
+		}
+		
+		/* Evaluation of the model equations */
+		fmi2Status fmi2GetDerivatives(fmi2Component c, fmi2Real derivatives[],
+				size_t nx) {
+			return fmi2Error;
+		}
+		
+		fmi2Status fmi2GetEventIndicators(fmi2Component c, fmi2Real eventIndicators[],
+				size_t ni) {
+			return fmi2Error;
+		}
+		
+		fmi2Status fmi2GetContinuousStates(fmi2Component c, fmi2Real states[],
+				size_t nx) {
+			return fmi2Error;
+		}
+		
+		fmi2Status fmi2GetNominalsOfContinuousStates(fmi2Component c,
+				fmi2Real x_nominal[], size_t nx) {
+			return fmi2Error;
+		}
+		#endif // Model Exchange
+		
+		
+		'''
+	}
+}

+ 233 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/src/be/uantwerpen/ansymo/semanticadaptation/testframework/StaticGenerators.xtend

@@ -0,0 +1,233 @@
+package be.uantwerpen.ansymo.semanticadaptation.testframework
+
+class StaticGenerators {
+	def static String generateMainCppFile(String folderPath)
+	{
+		'''
+		/*
+		 * main.cpp
+		 *
+		 *  Created on: Mar 14, 2017
+		 *      Author: kel
+		 */
+		#include <iostream>
+		#include "fmi2TypesPlatform.h"
+		#include "fmi2Functions.h"
+		#include <string>
+		
+		#include <memory>
+		#include <iostream>
+		
+		#include <cstdio>
+		#include <stdarg.h>     /* va_list, va_start, va_arg, va_end */
+		#include <fstream>
+		
+		using namespace std;
+		
+		void fmuLoggerCache(void *componentEnvironment, fmi2String instanceName,
+				fmi2Status status, fmi2String category, fmi2String message, ...) {
+			va_list argp;
+		
+			// replace C format strings
+			va_start(argp, message);
+			size_t size = vsnprintf(nullptr, 0, message, argp) + 1; // Extra space for '\0'
+			va_end(argp);
+		
+			va_start(argp, message);
+			unique_ptr<char[]> buf(new char[size]);
+			vsnprintf(buf.get(), size, message, argp);
+			va_end(argp);
+		
+			string completeMessage = string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
+		
+			cout << "FROM MAIN: Name: " << instanceName << " Status: " << status << " Category: "
+					<< category << " Msg: " << completeMessage << endl;
+		}
+		
+		fmi2Status setReal(fmi2Component comp, fmi2ValueReference id, fmi2Real val) {
+			const fmi2ValueReference vr[] { id };
+			size_t nvr = 1;
+			fmi2Real value[] { val };
+			return fmi2SetReal(comp, vr, nvr, value);
+		}
+		
+		fmi2Real getReal(fmi2Component comp, fmi2ValueReference id) {
+			const fmi2ValueReference vr[] { id };
+			size_t nvr = 1;
+			fmi2Real value[1];
+			fmi2GetReal(comp, vr, nvr, value);
+		
+			return value[0];
+		}
+		
+		int main(int argc, char *argv[]) {
+		//	setvbuf(stdout, NULL, _IONBF, 0);
+		//	setvbuf(stderr, NULL, _IONBF, 0);
+		
+			cout << "hello" << endl;
+		
+			fmi2CallbackFunctions callback = { &fmuLoggerCache, NULL, NULL, NULL, NULL };
+			fmi2Component comp =
+					fmi2Instantiate("this system", fmi2CoSimulation, "{1234}",
+							"«folderPath»",
+							&callback, fmi2True,
+							fmi2True);
+		
+			if (comp == NULL) {
+				cout << "init failed" << endl;
+				return -1;
+			}
+		
+			if (fmi2SetupExperiment(comp, false, 0.0, 0, true, 100) != fmi2OK) {
+				printf("Error fmi2SetupExperiment");
+				return 1;
+			}
+		
+			if (fmi2EnterInitializationMode(comp) != fmi2OK) {
+				printf("Error fmi2SetupExperiment");
+				return 1;
+			}
+		
+			if (fmi2ExitInitializationMode(comp) != fmi2OK) {
+				printf("Error fmi2SetupExperiment");
+				return 1;
+			}
+		
+		#define ID_Window_SA_IN_reaction_force 0
+		#define ID_Window_SA_IN_displacement 1
+		#define ID_Window_SA_IN_speed 2
+		
+		#define ID_Window_SA_OUT_disp 3
+		#define ID_Window_SA_OUT_tau 4
+		
+			std::fstream fs;
+			fs.open("result.csv",
+					std::fstream::in | std::fstream::out | std::fstream::trunc);
+		
+			//cout << "------------ Header ---------" << endl;
+			fs << "\"time\",\"ID_Window_SA_OUT_disp\",\"ID_Window_SA_OUT_tau\"" << endl;
+			double time = 0.0;
+			double stepSize = 0.01;
+		
+			for (double time = 0.0; time < 10;) {
+				if (setReal(comp, ID_Window_SA_IN_reaction_force, -1.0) != fmi2OK) {
+					printf("Error setting real");
+					return 1;
+				}
+				if (setReal(comp, ID_Window_SA_IN_displacement, time) != fmi2OK) {
+					printf("Error setting real");
+					return 1;
+				}
+				if (setReal(comp, ID_Window_SA_IN_speed, 1.0) != fmi2OK) {
+					printf("Error setting real");
+					return 1;
+				}
+		
+				if (fmi2DoStep(comp, time, stepSize, false) != fmi2OK) {
+					printf("Errorin do step");
+					return 1;
+				}
+				time += stepSize;
+		
+				auto disp = getReal(comp, ID_Window_SA_OUT_disp);
+				auto tau = getReal(comp, ID_Window_SA_OUT_tau);
+		
+				cout << "time: " << time << " disp: " << disp << " tau: " << tau
+						<< endl;
+				fs << time << "," << disp << "," << tau << endl;
+			}
+			fs.close();
+		
+			return 0;
+		}
+		
+		'''
+	}
+
+	def static String generateCMakeLists(String projectName, String frameworkPath)
+	{
+		'''
+		cmake_minimum_required (VERSION 2.8.5)
+		project («projectName» C CXX)
+		
+		include(CheckCXXCompilerFlag)
+		
+		#set(CMAKE_VERBOSE_MAKEFILE on)
+		
+		CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
+		CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
+		if(COMPILER_SUPPORTS_CXX11)
+		    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+		elseif(COMPILER_SUPPORTS_CXX0X)
+		   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
+		else()
+		        message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
+		endif()
+		
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFMI_COSIMULATION -g")
+		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFMI_COSIMULATION -g")
+		
+		
+		
+		include_directories(src)
+		
+		
+		file(GLOB CPP_FILES src/*.cpp)
+		
+		file(GLOB CPP_MAIN_FILES src/main*.cpp)
+		
+		list(REMOVE_ITEM CPP_FILES ${CPP_MAIN_FILES})
+		
+		## library ##
+		
+		add_library(${PROJECT_NAME} SHARED ${CPP_FILES} ${CPP_FILES})
+		target_link_libraries(${PROJECT_NAME} hcf)
+		set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
+		
+		
+		## Main executable ##
+		add_executable(${PROJECT_NAME}_main ${CPP_MAIN_FILES} ${CPP_FILES})
+		target_link_libraries(${PROJECT_NAME}_main hcf)
+		
+		foreach(LETTER ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES})
+			
+		if(EXISTS "${LETTER}/libstdc++.a")
+		#   message (STATUS "${LETTER}")
+			set(STDCPP_LIBRARY "${LETTER}/libstdc++.a")
+		else()
+		#  message (STATUS "${LETTER} ---- not these")
+		endif()
+		endforeach()
+		
+		message(STATUS "Static linking with libstdc++.a in ${STDCPP_LIBRARY}")
+		#target_link_libraries(${PROJECT_NAME} ${STDCPP_LIBRARY})
+		
+		
+		
+		# I need this: -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic
+		
+		if (WIN32)
+			#windows	
+			set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++ -static-libgcc -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic")
+		 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc  -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic")
+		endif() 
+		
+		
+		
+		
+		#if(NOT APPLE)
+		#https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/pthread.3.html 
+		#it is included in system
+		find_library(PTHREAD_LIBRARY NAMES libwinpthread.dll.a)# libpthread.a libpthread.dylib )
+		#message( INFO ${PTHREAD_LIBRARY})
+		#target_link_libraries(${PROJECT_NAME}_main ${PTHREAD_LIBRARY} /C/msys64/mingw64/x86_64-w64-mingw32/lib/libwinpthread.a)
+		#endif()
+		
+		add_subdirectory («frameworkPath»)
+		
+		#add_custom_command(${PROJECT_NAME}_main POST_BUILD COMMAND "find . -name *.exe -exec echo {} \; -exec bash -c \"objdump -p {} | grep 'DLL Name:'\" \;")		
+		
+		'''
+	}
+	
+}