Browse Source

Started work on lazy sa

Casper Thule 3 years ago
parent
commit
62d1d11dd1

BIN
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/lazy/Controller.fmu


+ 20 - 2
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/lazy/lazy_canonical.sa

@@ -22,7 +22,10 @@ param 	INIT_OBJ_DETECTED := false,
 		INIT_PASSENGER_STOP := false,
 		INIT_DRIVER_UP := false,
 		INIT_DRIVER_DOWN := false,
-		INIT_DRIVER_STOP := false;
+		INIT_DRIVER_STOP := false,
+		INIT_UP := false,
+		INIT_DOWN := false,
+		INIT_STOP := false;
 
 control var	tn := -1.0,
 			tl := -1.0,
@@ -67,5 +70,20 @@ control rules {
 	return step_size;
 }
 
-in var
+in var 
+	stored_sa_obj_detected := INIT_OBJ_DETECTED,
+	stored_sa_passenger_up := INIT_PASSENGER_UP,
+	stored_sa_passenger_down := INIT_PASSENGER_DOWN,
+	stored_sa_passenger_stop := INIT_PASSENGER_STOP,
+	stored_sa_driver_up := INIT_DRIVER_UP,
+	stored_sa_driver_down := INIT_DRIVER_DOWN,
+	stored_sa_driver_stop := INIT_DRIVER_STOP;
 
+in rules {
+	true 
+}
+	
+out var
+	stored_sa_up := INIT_UP,
+	stored_sa_down := INIT_DOWN,
+	stored_sa_stop := INIT_STOP;

+ 3 - 2
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend

@@ -349,8 +349,9 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			}
 			
 			void «adapClassName»::initialize()
-			{
-				auto path = Fmu::combinePath(resourceLocation, make_shared<string>("«fmuTypeName».fmu"));
+			{				
+				auto path = make_shared<string>(*resourceLocation);
+				path->append(string("«fmuTypeName».fmu"));
 				auto «fmuName»Fmu = make_shared<fmi2::Fmu>(*path);
 				«fmuName»Fmu->initialize();
 				this->«fmuName» = «fmuName»Fmu->instantiate("«fmuName»",fmi2CoSimulation, "«guid»", true, true, shared_from_this());

+ 12 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/ModelDescriptionBuilder.java

@@ -16,6 +16,7 @@ import org.w3c.dom.Element;
 
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVCausality;
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType;
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVVariability;
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ScalarVariable;
 
 public class ModelDescriptionBuilder {
@@ -45,8 +46,10 @@ public class ModelDescriptionBuilder {
 		modelVariables = doc.createElement("ModelVariables");
 		rootElement.appendChild(modelVariables);
 
+		Element modelStructure = doc.createElement("ModelStructure");
+		rootElement.appendChild(modelStructure);
 		outputs = doc.createElement("Outputs");
-		rootElement.appendChild(outputs);
+		modelStructure.appendChild(outputs);
 	}
 
 	public String getNextValueReference() {
@@ -81,6 +84,13 @@ public class ModelDescriptionBuilder {
 			if (var.getStart() != null) {
 				svType.setAttribute("start", var.getStart());
 			}
+			else
+			{
+				if(var.getVariability() == SVVariability.continuous && var.getCausality() == SVCausality.input)
+				{
+					svType.setAttribute("start", "0.0");
+				}
+			}
 		}
 
 	}
@@ -88,6 +98,7 @@ public class ModelDescriptionBuilder {
 	private Element createUnknown(String index) {
 		Element e = doc.createElement("Unknown");
 		e.setAttribute("index", index);
+		e.setAttribute("dependencies", "");
 		return e;
 	}
 

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

@@ -58,7 +58,7 @@ class StaticGenerators {
 			name = new std::string(instanceName);
 			g_functions = functions;
 			fmiprintf("instantiating %s\n", instanceName);
-			auto resourceLoc = make_shared<std::string>(fmuResourceLocation);
+			auto resourceLoc = make_shared<std::string>(URIToNativePath(fmuResourceLocation));
 			g_adaptation = make_shared<adaptation::«adapClassName»>(resourceLoc, functions);
 			try
 			{

+ 98 - 47
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/src/be/uantwerpen/ansymo/semanticadaptation/testframework/StaticGenerators.xtend

@@ -147,24 +147,41 @@ class StaticGenerators {
 	def static String generateCMakeLists(String projectName, String frameworkPath)
 	{
 		'''
-		cmake_minimum_required (VERSION 2.8.5)
+		#
+		# #%~
+		# The Overture Abstract Syntax Tree
+		# %%
+		# Copyright (C) 2017 - 2014 Aarhus University
+		# %%
+		# This program is free software: you can redistribute it and/or modify
+		# it under the terms of the GNU General Public License as
+		# published by the Free Software Foundation, either version 3 of the
+		# License, or (at your option) any later version.
+		# 
+		# This program is distributed in the hope that it will be useful,
+		# but WITHOUT ANY WARRANTY; without even the implied warranty of
+		# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+		# GNU General Public License for more details.
+		# 
+		# You should have received a copy of the GNU General Public
+		# License along with this program.  If not, see
+		# <http://www.gnu.org/licenses/gpl-3.0.html>.
+		# #~%
+		#
+		cmake_minimum_required (VERSION 3.5.2)
+		# this (3.5.2) is the first version where External Project uses --recursive
 		project («projectName» C CXX)
 		
-		include(CheckCXXCompilerFlag)
-		
-		#set(CMAKE_VERBOSE_MAKEFILE on)
+		# HOW to
+		#
+		# cmake -DCMAKE_TOOLCHAIN_FILE=msys-toolchain.cmake -DCMAKE_BUILD_TYPE=Debug .
+		# make
+		# 
+		# to list dependencies use:
+		#  objdump -p binaries/win64/window-sa.dll |  grep 'DLL Name:'
+		#
 		
-		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()
 		
-		add_definitions(-DFMI_COSIMULATION)
 		
 		if (WIN32)
 			#windows, becuase windows just cannot figure out to do it correct. 
@@ -175,66 +192,100 @@ class StaticGenerators {
 			
 			set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
 			set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
+		endif() 
+		
+		
+		# Checkout the hcf sources
+		set(HCF_DIR hcf)
+		if(EXISTS ${HCF_DIR})
+			#execute_process(COMMAND git pull WORKING_DIRECTORY ${HCF_DIR})
+		else()
+			execute_process(COMMAND git clone --depth 1 git@github.com:into-cps/hybridCosimulation-framework.git ${HCF_DIR} )
+			execute_process(COMMAND git submodule update --init --recursive WORKING_DIRECTORY ${HCF_DIR})
 		endif()
+		add_subdirectory(${HCF_DIR}/semantic-adaptation)
+		
+		include(CheckCXXCompilerFlag)
 		
-		add_subdirectory («frameworkPath»)
 		
-		include_directories(src)
+		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()
+		
+		add_definitions(-DFMI_COSIMULATION)
 		
+		include_directories(sources)
 		
-		file(GLOB CPP_FILES src/*.cpp)
+		file(GLOB CPP_FILES sources/*.cpp)
 		
-		file(GLOB CPP_MAIN_FILES src/main*.cpp)
+		file(GLOB CPP_MAIN_FILES sources/main*.cpp)
 		
 		list(REMOVE_ITEM CPP_FILES ${CPP_MAIN_FILES})
 		
 		## library ##
 		
+		#determine the library path
+		set(FMI_BIN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/binaries")
+		
+		if(WIN32 OR MINGW)
+			set(FMI_BIN_DIR "${FMI_BIN_DIR}/win")
+			# not sure why this doesnt work on MSYS so we just reset it
+			SET (CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
+		endif()
+		
+		if(APPLE)
+			set(FMI_BIN_DIR "${FMI_BIN_DIR}/darwin")
+		endif()
+		
+		if(UNIX AND NOT APPLE)
+		  # for Linux, BSD, Solaris, Minix
+			set(FMI_BIN_DIR "${FMI_BIN_DIR}/linux")
+		endif()
+		
+		
+		if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
+		  set(FMI_BIN_DIR "${FMI_BIN_DIR}64")
+		else ()
+			set(FMI_BIN_DIR "${FMI_BIN_DIR}32")
+		endif ()
+		
+		message("FMI output is ${FMI_BIN_DIR}")
+		#SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
+		file(MAKE_DIRECTORY ${FMI_BIN_DIR})
+		set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${FMI_BIN_DIR})
+		set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${FMI_BIN_DIR})
+		
+		#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY bb)
+		#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${FMI_BIN_DIR})
+		
+		
 		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)
+		SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
+		
 		
+		set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
 		
 		## 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")
+			set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++ -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_custom_command(${PROJECT_NAME}_main POST_BUILD COMMAND "find . -name *.exe -exec echo {} \; -exec bash -c \"objdump -p {} | grep 'DLL Name:'\" \;")		
-		
 		'''
 	}