From bb9e4909638cd73294e20ef0dece70546e84b38c Mon Sep 17 00:00:00 2001 From: yuppox Date: Sat, 23 Mar 2019 02:12:05 -0700 Subject: [PATCH] Changed: process_defines now uses a calloc'd tempstr like process_includes. Using a variable-length array was the only barrier for the MS compiler. Added Visual Studio solution and project files. --- libtvm/tvm_preprocessor.c | 10 +- msvc/TVInterpreter/TVInterpreter.vcxproj | 140 +++++++++++++++++++++ msvc/TinyVM.sln | 41 ++++++ msvc/TinyVM/TinyVM.vcxproj | 152 +++++++++++++++++++++++ 4 files changed, 341 insertions(+), 2 deletions(-) create mode 100644 msvc/TVInterpreter/TVInterpreter.vcxproj create mode 100644 msvc/TinyVM.sln create mode 100644 msvc/TinyVM/TinyVM.vcxproj diff --git a/libtvm/tvm_preprocessor.c b/libtvm/tvm_preprocessor.c index 1afce18..aa5099d 100644 --- a/libtvm/tvm_preprocessor.c +++ b/libtvm/tvm_preprocessor.c @@ -2,7 +2,10 @@ #include #include +#ifndef WIN32 #include +#endif + #include static int process_includes( @@ -79,9 +82,9 @@ static int process_defines( } int length = (end - (begin + offset)); - char tempstr[length + 1]; + char *tempstr; + tempstr = calloc(length + 1, sizeof(char)); - memset(tempstr, 0, length + 1); memcpy(tempstr, begin + offset, length); char *keystr = tempstr; @@ -97,6 +100,7 @@ static int process_defines( if (!keystr || !valstr) { printf("Define missing arguments.\n"); + free(tempstr); return -1; } @@ -104,6 +108,7 @@ static int process_defines( tvm_htab_add_ref(defines, keystr, valstr, strlen(valstr) + 1); else { printf("Multiple definitions for %s.\n", keystr); + free(tempstr); return -1; } @@ -117,6 +122,7 @@ static int process_defines( *src = realloc(*src, sizeof(char) * new_src_len); *src_len = new_src_len; + free(tempstr); return 1; } diff --git a/msvc/TVInterpreter/TVInterpreter.vcxproj b/msvc/TVInterpreter/TVInterpreter.vcxproj new file mode 100644 index 0000000..2d62244 --- /dev/null +++ b/msvc/TVInterpreter/TVInterpreter.vcxproj @@ -0,0 +1,140 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {FE1433C7-4E1A-44A4-8472-8B43C3CC5680} + TVInterpreter + 10.0.17763.0 + TVMInterpreter + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + true + ../../include + + + ../Debug + TinyVM.lib;%(AdditionalDependencies) + + + + + Level3 + Disabled + true + true + ../../include + + + TinyVM.lib;%(AdditionalDependencies) + ../x64/Debug + + + + + Level3 + MaxSpeed + true + true + true + true + ../../include + + + true + true + ../Release + TinyVM.lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + true + true + ../../include + + + true + true + TinyVM.lib;%(AdditionalDependencies) + ../x64/Release + + + + + + + + + \ No newline at end of file diff --git a/msvc/TinyVM.sln b/msvc/TinyVM.sln new file mode 100644 index 0000000..b18d667 --- /dev/null +++ b/msvc/TinyVM.sln @@ -0,0 +1,41 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.329 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TinyVM", "TinyVM\TinyVM.vcxproj", "{5FA12866-D457-43F8-AF6A-3A3B61657B70}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TVInterpreter", "TVInterpreter\TVInterpreter.vcxproj", "{FE1433C7-4E1A-44A4-8472-8B43C3CC5680}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5FA12866-D457-43F8-AF6A-3A3B61657B70}.Debug|x64.ActiveCfg = Debug|x64 + {5FA12866-D457-43F8-AF6A-3A3B61657B70}.Debug|x64.Build.0 = Debug|x64 + {5FA12866-D457-43F8-AF6A-3A3B61657B70}.Debug|x86.ActiveCfg = Debug|Win32 + {5FA12866-D457-43F8-AF6A-3A3B61657B70}.Debug|x86.Build.0 = Debug|Win32 + {5FA12866-D457-43F8-AF6A-3A3B61657B70}.Release|x64.ActiveCfg = Release|x64 + {5FA12866-D457-43F8-AF6A-3A3B61657B70}.Release|x64.Build.0 = Release|x64 + {5FA12866-D457-43F8-AF6A-3A3B61657B70}.Release|x86.ActiveCfg = Release|Win32 + {5FA12866-D457-43F8-AF6A-3A3B61657B70}.Release|x86.Build.0 = Release|Win32 + {FE1433C7-4E1A-44A4-8472-8B43C3CC5680}.Debug|x64.ActiveCfg = Debug|x64 + {FE1433C7-4E1A-44A4-8472-8B43C3CC5680}.Debug|x64.Build.0 = Debug|x64 + {FE1433C7-4E1A-44A4-8472-8B43C3CC5680}.Debug|x86.ActiveCfg = Debug|Win32 + {FE1433C7-4E1A-44A4-8472-8B43C3CC5680}.Debug|x86.Build.0 = Debug|Win32 + {FE1433C7-4E1A-44A4-8472-8B43C3CC5680}.Release|x64.ActiveCfg = Release|x64 + {FE1433C7-4E1A-44A4-8472-8B43C3CC5680}.Release|x64.Build.0 = Release|x64 + {FE1433C7-4E1A-44A4-8472-8B43C3CC5680}.Release|x86.ActiveCfg = Release|Win32 + {FE1433C7-4E1A-44A4-8472-8B43C3CC5680}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {59EC05DD-A5B7-4A82-8B30-D3BAAA59A019} + EndGlobalSection +EndGlobal diff --git a/msvc/TinyVM/TinyVM.vcxproj b/msvc/TinyVM/TinyVM.vcxproj new file mode 100644 index 0000000..e24c300 --- /dev/null +++ b/msvc/TinyVM/TinyVM.vcxproj @@ -0,0 +1,152 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + 15.0 + {5FA12866-D457-43F8-AF6A-3A3B61657B70} + TinyVM + 10.0.17763.0 + TVMLib + + + + StaticLibrary + true + v141 + MultiByte + + + StaticLibrary + false + v141 + true + MultiByte + + + StaticLibrary + true + v141 + MultiByte + + + StaticLibrary + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + tinyvm + + + tinyvm + + + tinyvm + + + tinyvm + + + + Level3 + Disabled + true + true + ../../include + _CRT_SECURE_NO_WARNINGS;WIN32;%(PreprocessorDefinitions) + + + + + + + Level3 + Disabled + true + true + ../../include + _CRT_SECURE_NO_WARNINGS;WIN32;%(PreprocessorDefinitions) + + + + + Level3 + MaxSpeed + true + true + true + true + ../../include + _CRT_SECURE_NO_WARNINGS;WIN32;%(PreprocessorDefinitions) + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + ../../include + _CRT_SECURE_NO_WARNINGS;WIN32;%(PreprocessorDefinitions) + + + true + true + + + + + + \ No newline at end of file