diff options
| Commit | c32eda4e697803824e79878c74d541b81fbd04d8 (patch) | |
|---|---|---|
| Author | 2018-11-15 11:35:44 +0200 | |
| Committer | 2018-11-15 11:35:44 +0200 | |
| Files | ace7bdc0df3791b6db8878d52ba98cb368e180b8 | |
| IPL-c32eda4e697803824e79878c74d541b81fbd04d8.tar IPL-c32eda4e697803824e79878c74d541b81fbd04d8.tar.gz IPL-c32eda4e697803824e79878c74d541b81fbd04d8.zip | ||
| Parent | a7cd9d4f8d83024402bacb39786e5e1a018a0a04 (diff) | |
| Parent | d7b2e339ff06c64bcb1322eec396d4995da6b17a (diff) | |
Merge pull request #48 from SofiaCPP/feature/spasm_asm
Spasm tests and latest instruction set
31 files changed, 1307 insertions, 586 deletions
diff --git a/JSImpl/solution/JSImpl.sln b/JSImpl/solution/JSImpl.sln index 9915cf9..17799fc 100644 --- a/JSImpl/solution/JSImpl.sln +++ b/JSImpl/solution/JSImpl.sln @@ -1,15 +1,33 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Spasm", "Spasm", "{9892E17D-8434-0C54-6DEF-1FA8593093A4}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gtest", "gtest", "{1BAF0A7D-0751-3553-F00B-49A7DC4CBCA3}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "JSImpl", "JSImpl", "{C30B5025-2FEB-CEC0-3803-5A97A4613522}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sprun", "..\..\spasm\solution\sprun.vcxproj", "{FD605F10-6975-87C1-32F7-2A219ECA83F2}"
+ ProjectSection(ProjectDependencies) = postProject
+ {AE0A9E7C-9A41-9F0D-432E-85102F441B0F} = {AE0A9E7C-9A41-9F0D-432E-85102F441B0F}
+ EndProjectSection
+EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "..\test\Test.vcxproj", "{45DC8C7C-3113-8E0D-DAFF-7310C6150A0F}"
ProjectSection(ProjectDependencies) = postProject
{AE0A9E7C-9A41-9F0D-432E-85102F441B0F} = {AE0A9E7C-9A41-9F0D-432E-85102F441B0F}
+ {3F16CDE1-AB80-8158-F4BE-32FE60685FAD} = {3F16CDE1-AB80-8158-F4BE-32FE60685FAD}
{19EA680D-85FE-90BE-4E80-341EBA538DEF} = {19EA680D-85FE-90BE-4E80-341EBA538DEF}
{EC34880F-5849-B0C0-21CB-53208D9EACF1} = {EC34880F-5849-B0C0-21CB-53208D9EACF1}
{B686840F-229B-ACC0-EB1C-502057F0A8F1} = {B686840F-229B-ACC0-EB1C-502057F0A8F1}
{30B03E7E-1C68-80CB-856F-592771461BBC} = {30B03E7E-1C68-80CB-856F-592771461BBC}
EndProjectSection
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest", "..\test\gtest.vcxproj", "{EC34880F-5849-B0C0-21CB-53208D9EACF1}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gmock", "..\test\gmock.vcxproj", "{B686840F-229B-ACC0-EB1C-502057F0A8F1}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_main", "..\test\gtest_main.vcxproj", "{30B03E7E-1C68-80CB-856F-592771461BBC}"
+EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "JSLib", "JSLib.vcxproj", "{19EA680D-85FE-90BE-4E80-341EBA538DEF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "JSImpl", "JSImpl.vcxproj", "{549B84BA-403D-AF90-29F8-C2E4153936E1}"
@@ -17,19 +35,13 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "JSImpl", "JSImpl.vcxproj", {19EA680D-85FE-90BE-4E80-341EBA538DEF} = {19EA680D-85FE-90BE-4E80-341EBA538DEF}
EndProjectSection
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest", "..\test\gtest.vcxproj", "{EC34880F-5849-B0C0-21CB-53208D9EACF1}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gmock", "..\test\gmock.vcxproj", "{B686840F-229B-ACC0-EB1C-502057F0A8F1}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_main", "..\test\gtest_main.vcxproj", "{30B03E7E-1C68-80CB-856F-592771461BBC}"
-EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sprt", "..\..\spasm\solution\sprt.vcxproj", "{AE0A9E7C-9A41-9F0D-432E-85102F441B0F}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spasm", "..\..\spasm\solution\spasm.vcxproj", "{69185F10-D52C-87C1-9EAE-2A210A8283F2}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spasm_lib", "..\..\spasm\solution\spasm_lib.vcxproj", "{3F16CDE1-AB80-8158-F4BE-32FE60685FAD}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sprun", "..\..\spasm\solution\sprun.vcxproj", "{FD605F10-6975-87C1-32F7-2A219ECA83F2}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spasm", "..\..\spasm\solution\spasm.vcxproj", "{69185F10-D52C-87C1-9EAE-2A210A8283F2}"
ProjectSection(ProjectDependencies) = postProject
- {AE0A9E7C-9A41-9F0D-432E-85102F441B0F} = {AE0A9E7C-9A41-9F0D-432E-85102F441B0F}
+ {3F16CDE1-AB80-8158-F4BE-32FE60685FAD} = {3F16CDE1-AB80-8158-F4BE-32FE60685FAD}
EndProjectSection
EndProject
Global
@@ -38,18 +50,14 @@ Global Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {FD605F10-6975-87C1-32F7-2A219ECA83F2}.Debug|x64.ActiveCfg = Debug|x64
+ {FD605F10-6975-87C1-32F7-2A219ECA83F2}.Debug|x64.Build.0 = Debug|x64
+ {FD605F10-6975-87C1-32F7-2A219ECA83F2}.Release|x64.ActiveCfg = Release|x64
+ {FD605F10-6975-87C1-32F7-2A219ECA83F2}.Release|x64.Build.0 = Release|x64
{45DC8C7C-3113-8E0D-DAFF-7310C6150A0F}.Debug|x64.ActiveCfg = Debug|x64
{45DC8C7C-3113-8E0D-DAFF-7310C6150A0F}.Debug|x64.Build.0 = Debug|x64
{45DC8C7C-3113-8E0D-DAFF-7310C6150A0F}.Release|x64.ActiveCfg = Release|x64
{45DC8C7C-3113-8E0D-DAFF-7310C6150A0F}.Release|x64.Build.0 = Release|x64
- {19EA680D-85FE-90BE-4E80-341EBA538DEF}.Debug|x64.ActiveCfg = Debug|x64
- {19EA680D-85FE-90BE-4E80-341EBA538DEF}.Debug|x64.Build.0 = Debug|x64
- {19EA680D-85FE-90BE-4E80-341EBA538DEF}.Release|x64.ActiveCfg = Release|x64
- {19EA680D-85FE-90BE-4E80-341EBA538DEF}.Release|x64.Build.0 = Release|x64
- {549B84BA-403D-AF90-29F8-C2E4153936E1}.Debug|x64.ActiveCfg = Debug|x64
- {549B84BA-403D-AF90-29F8-C2E4153936E1}.Debug|x64.Build.0 = Debug|x64
- {549B84BA-403D-AF90-29F8-C2E4153936E1}.Release|x64.ActiveCfg = Release|x64
- {549B84BA-403D-AF90-29F8-C2E4153936E1}.Release|x64.Build.0 = Release|x64
{EC34880F-5849-B0C0-21CB-53208D9EACF1}.Debug|x64.ActiveCfg = Debug|x64
{EC34880F-5849-B0C0-21CB-53208D9EACF1}.Debug|x64.Build.0 = Debug|x64
{EC34880F-5849-B0C0-21CB-53208D9EACF1}.Release|x64.ActiveCfg = Release|x64
@@ -62,22 +70,39 @@ Global {30B03E7E-1C68-80CB-856F-592771461BBC}.Debug|x64.Build.0 = Debug|x64
{30B03E7E-1C68-80CB-856F-592771461BBC}.Release|x64.ActiveCfg = Release|x64
{30B03E7E-1C68-80CB-856F-592771461BBC}.Release|x64.Build.0 = Release|x64
+ {19EA680D-85FE-90BE-4E80-341EBA538DEF}.Debug|x64.ActiveCfg = Debug|x64
+ {19EA680D-85FE-90BE-4E80-341EBA538DEF}.Debug|x64.Build.0 = Debug|x64
+ {19EA680D-85FE-90BE-4E80-341EBA538DEF}.Release|x64.ActiveCfg = Release|x64
+ {19EA680D-85FE-90BE-4E80-341EBA538DEF}.Release|x64.Build.0 = Release|x64
+ {549B84BA-403D-AF90-29F8-C2E4153936E1}.Debug|x64.ActiveCfg = Debug|x64
+ {549B84BA-403D-AF90-29F8-C2E4153936E1}.Debug|x64.Build.0 = Debug|x64
+ {549B84BA-403D-AF90-29F8-C2E4153936E1}.Release|x64.ActiveCfg = Release|x64
+ {549B84BA-403D-AF90-29F8-C2E4153936E1}.Release|x64.Build.0 = Release|x64
{AE0A9E7C-9A41-9F0D-432E-85102F441B0F}.Debug|x64.ActiveCfg = Debug|x64
{AE0A9E7C-9A41-9F0D-432E-85102F441B0F}.Debug|x64.Build.0 = Debug|x64
{AE0A9E7C-9A41-9F0D-432E-85102F441B0F}.Release|x64.ActiveCfg = Release|x64
{AE0A9E7C-9A41-9F0D-432E-85102F441B0F}.Release|x64.Build.0 = Release|x64
+ {3F16CDE1-AB80-8158-F4BE-32FE60685FAD}.Debug|x64.ActiveCfg = Debug|x64
+ {3F16CDE1-AB80-8158-F4BE-32FE60685FAD}.Debug|x64.Build.0 = Debug|x64
+ {3F16CDE1-AB80-8158-F4BE-32FE60685FAD}.Release|x64.ActiveCfg = Release|x64
+ {3F16CDE1-AB80-8158-F4BE-32FE60685FAD}.Release|x64.Build.0 = Release|x64
{69185F10-D52C-87C1-9EAE-2A210A8283F2}.Debug|x64.ActiveCfg = Debug|x64
{69185F10-D52C-87C1-9EAE-2A210A8283F2}.Debug|x64.Build.0 = Debug|x64
{69185F10-D52C-87C1-9EAE-2A210A8283F2}.Release|x64.ActiveCfg = Release|x64
{69185F10-D52C-87C1-9EAE-2A210A8283F2}.Release|x64.Build.0 = Release|x64
- {FD605F10-6975-87C1-32F7-2A219ECA83F2}.Debug|x64.ActiveCfg = Debug|x64
- {FD605F10-6975-87C1-32F7-2A219ECA83F2}.Debug|x64.Build.0 = Debug|x64
- {FD605F10-6975-87C1-32F7-2A219ECA83F2}.Release|x64.ActiveCfg = Release|x64
- {FD605F10-6975-87C1-32F7-2A219ECA83F2}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
+ {FD605F10-6975-87C1-32F7-2A219ECA83F2} = {9892E17D-8434-0C54-6DEF-1FA8593093A4}
+ {EC34880F-5849-B0C0-21CB-53208D9EACF1} = {1BAF0A7D-0751-3553-F00B-49A7DC4CBCA3}
+ {B686840F-229B-ACC0-EB1C-502057F0A8F1} = {1BAF0A7D-0751-3553-F00B-49A7DC4CBCA3}
+ {30B03E7E-1C68-80CB-856F-592771461BBC} = {1BAF0A7D-0751-3553-F00B-49A7DC4CBCA3}
+ {19EA680D-85FE-90BE-4E80-341EBA538DEF} = {C30B5025-2FEB-CEC0-3803-5A97A4613522}
+ {549B84BA-403D-AF90-29F8-C2E4153936E1} = {C30B5025-2FEB-CEC0-3803-5A97A4613522}
+ {AE0A9E7C-9A41-9F0D-432E-85102F441B0F} = {9892E17D-8434-0C54-6DEF-1FA8593093A4}
+ {3F16CDE1-AB80-8158-F4BE-32FE60685FAD} = {9892E17D-8434-0C54-6DEF-1FA8593093A4}
+ {69185F10-D52C-87C1-9EAE-2A210A8283F2} = {9892E17D-8434-0C54-6DEF-1FA8593093A4}
EndGlobalSection
EndGlobal
diff --git a/JSImpl/solution/JSImpl.vcxproj b/JSImpl/solution/JSImpl.vcxproj index 8b58a96..0aa8deb 100644 --- a/JSImpl/solution/JSImpl.vcxproj +++ b/JSImpl/solution/JSImpl.vcxproj @@ -21,11 +21,13 @@ <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
diff --git a/JSImpl/solution/JSLib.vcxproj b/JSImpl/solution/JSLib.vcxproj index bb5c860..1d0f63a 100644 --- a/JSImpl/solution/JSLib.vcxproj +++ b/JSImpl/solution/JSLib.vcxproj @@ -21,11 +21,13 @@ <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@@ -111,23 +113,23 @@ </ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\src\ASTInterpreter.h" />
+ <ClInclude Include="..\src\ASTPrinter.h" />
+ <ClInclude Include="..\src\CommonTypes.h" />
<ClInclude Include="..\src\Expression.h" />
+ <ClInclude Include="..\src\ExpressionDefinitions.h" />
<ClInclude Include="..\src\ExpressionsFwd.h" />
- <ClInclude Include="..\src\ASTPrinter.h" />
<ClInclude Include="..\src\ExpressionVisitor.h" />
<ClInclude Include="..\src\Lexer.h" />
- <ClInclude Include="..\src\CommonTypes.h" />
- <ClInclude Include="..\src\ExpressionDefinitions.h" />
<ClInclude Include="..\src\Parser.h" />
</ItemGroup>
<ItemGroup>
- <ClCompile Include="..\src\Lexer.cpp">
- </ClCompile>
<ClCompile Include="..\src\ASTInterpreter.cpp">
</ClCompile>
+ <ClCompile Include="..\src\ASTPrinter.cpp">
+ </ClCompile>
<ClCompile Include="..\src\Expression.cpp">
</ClCompile>
- <ClCompile Include="..\src\ASTPrinter.cpp">
+ <ClCompile Include="..\src\Lexer.cpp">
</ClCompile>
<ClCompile Include="..\src\Parser.cpp">
</ClCompile>
diff --git a/JSImpl/solution/JSLib.vcxproj.filters b/JSImpl/solution/JSLib.vcxproj.filters index a5801c7..afcbbb9 100644 --- a/JSImpl/solution/JSLib.vcxproj.filters +++ b/JSImpl/solution/JSLib.vcxproj.filters @@ -9,25 +9,25 @@ <ClInclude Include="..\src\ASTInterpreter.h">
<Filter>src</Filter>
</ClInclude>
- <ClInclude Include="..\src\Expression.h">
+ <ClInclude Include="..\src\ASTPrinter.h">
<Filter>src</Filter>
</ClInclude>
- <ClInclude Include="..\src\ExpressionsFwd.h">
+ <ClInclude Include="..\src\CommonTypes.h">
<Filter>src</Filter>
</ClInclude>
- <ClInclude Include="..\src\ASTPrinter.h">
+ <ClInclude Include="..\src\Expression.h">
<Filter>src</Filter>
</ClInclude>
- <ClInclude Include="..\src\ExpressionVisitor.h">
+ <ClInclude Include="..\src\ExpressionDefinitions.h">
<Filter>src</Filter>
</ClInclude>
- <ClInclude Include="..\src\Lexer.h">
+ <ClInclude Include="..\src\ExpressionsFwd.h">
<Filter>src</Filter>
</ClInclude>
- <ClInclude Include="..\src\CommonTypes.h">
+ <ClInclude Include="..\src\ExpressionVisitor.h">
<Filter>src</Filter>
</ClInclude>
- <ClInclude Include="..\src\ExpressionDefinitions.h">
+ <ClInclude Include="..\src\Lexer.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\src\Parser.h">
@@ -35,16 +35,16 @@ </ClInclude>
</ItemGroup>
<ItemGroup>
- <ClCompile Include="..\src\Lexer.cpp">
+ <ClCompile Include="..\src\ASTInterpreter.cpp">
<Filter>src</Filter>
</ClCompile>
- <ClCompile Include="..\src\ASTInterpreter.cpp">
+ <ClCompile Include="..\src\ASTPrinter.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\src\Expression.cpp">
<Filter>src</Filter>
</ClCompile>
- <ClCompile Include="..\src\ASTPrinter.cpp">
+ <ClCompile Include="..\src\Lexer.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\src\Parser.cpp">
diff --git a/JSImpl/solution/Makefile b/JSImpl/solution/Makefile index b920fc7..00cafb3 100644 --- a/JSImpl/solution/Makefile +++ b/JSImpl/solution/Makefile @@ -6,21 +6,13 @@ ifndef config endif export config -PROJECTS := JSImpl JSLib Test gmock gtest gtest_main spasm sprt sprun +PROJECTS := JSImpl JSLib Test gmock gtest gtest_main spasm spasm_lib sprt sprun .PHONY: all clean help $(PROJECTS) all: $(PROJECTS) -JSLib: - @echo "==== Building JSLib ($(config)) ====" - @${MAKE} --no-print-directory -C . -f JSLib.make - -JSImpl: JSLib - @echo "==== Building JSImpl ($(config)) ====" - @${MAKE} --no-print-directory -C . -f JSImpl.make - -Test: sprt JSLib gtest gmock gtest_main +Test: sprt spasm_lib JSLib gtest gmock gtest_main @echo "==== Building Test ($(config)) ====" @${MAKE} --no-print-directory -C ../test -f Test.make @@ -36,11 +28,23 @@ gtest_main: @echo "==== Building gtest_main ($(config)) ====" @${MAKE} --no-print-directory -C ../test -f gtest_main.make +JSLib: + @echo "==== Building JSLib ($(config)) ====" + @${MAKE} --no-print-directory -C . -f JSLib.make + +JSImpl: JSLib + @echo "==== Building JSImpl ($(config)) ====" + @${MAKE} --no-print-directory -C . -f JSImpl.make + sprt: @echo "==== Building sprt ($(config)) ====" @${MAKE} --no-print-directory -C ../../spasm/solution -f sprt.make -spasm: +spasm_lib: + @echo "==== Building spasm_lib ($(config)) ====" + @${MAKE} --no-print-directory -C ../../spasm/solution -f spasm_lib.make + +spasm: spasm_lib @echo "==== Building spasm ($(config)) ====" @${MAKE} --no-print-directory -C ../../spasm/solution -f spasm.make @@ -49,13 +53,14 @@ sprun: sprt @${MAKE} --no-print-directory -C ../../spasm/solution -f sprun.make clean: - @${MAKE} --no-print-directory -C . -f JSLib.make clean - @${MAKE} --no-print-directory -C . -f JSImpl.make clean @${MAKE} --no-print-directory -C ../test -f Test.make clean @${MAKE} --no-print-directory -C ../test -f gtest.make clean @${MAKE} --no-print-directory -C ../test -f gmock.make clean @${MAKE} --no-print-directory -C ../test -f gtest_main.make clean + @${MAKE} --no-print-directory -C . -f JSLib.make clean + @${MAKE} --no-print-directory -C . -f JSImpl.make clean @${MAKE} --no-print-directory -C ../../spasm/solution -f sprt.make clean + @${MAKE} --no-print-directory -C ../../spasm/solution -f spasm_lib.make clean @${MAKE} --no-print-directory -C ../../spasm/solution -f spasm.make clean @${MAKE} --no-print-directory -C ../../spasm/solution -f sprun.make clean @@ -69,13 +74,14 @@ help: @echo "TARGETS:" @echo " all (default)" @echo " clean" - @echo " JSLib" - @echo " JSImpl" @echo " Test" @echo " gtest" @echo " gmock" @echo " gtest_main" + @echo " JSLib" + @echo " JSImpl" @echo " sprt" + @echo " spasm_lib" @echo " spasm" @echo " sprun" @echo "" diff --git a/JSImpl/solution/genie.lua b/JSImpl/solution/genie.lua index 28a8515..aa5889d 100644 --- a/JSImpl/solution/genie.lua +++ b/JSImpl/solution/genie.lua @@ -24,21 +24,24 @@ solution 'JSImpl' objdir(root .. 'obj/Release') configuration '*' - project 'JSLib' - kind 'StaticLib' - language 'C++' - uuid(os.uuid('JSLib')) - files '../src/*.cpp' - removefiles '../src/main.cpp' - files '../src/*.h' - - project 'JSImpl' - kind 'ConsoleApp' - language 'C++' - uuid(os.uuid('JSImpl')) - files '../src/main.cpp' - links 'JSLib' - include '../test' - include '../../spasm/solution/' startproject 'Test' + + group 'JSImpl' + project 'JSLib' + kind 'StaticLib' + language 'C++' + uuid(os.uuid('JSLib')) + files '../src/*.cpp' + removefiles '../src/main.cpp' + files '../src/*.h' + + project 'JSImpl' + kind 'ConsoleApp' + language 'C++' + uuid(os.uuid('JSImpl')) + files '../src/main.cpp' + links 'JSLib' + + group 'Spasm' + include '../../spasm/solution/' diff --git a/JSImpl/test/Test.make b/JSImpl/test/Test.make index 4540d2d..e1a6ad4 100644 --- a/JSImpl/test/Test.make +++ b/JSImpl/test/Test.make @@ -47,7 +47,7 @@ ifeq ($(config),debug64) TARGETDIR = ../build/bin/Debug TARGET = $(TARGETDIR)/Test DEFINES += -D_SCL_SECURE_NO_WARNINGS - INCLUDES += -I"googletest/googletest/include" -I"googletest/googlemock/include" -I".." -I"../../spasm/src" + INCLUDES += -I"googletest/googletest/include" -I"googletest/googlemock/include" -I".." -I"../../spasm/src" -I"../../spasm/src/asm" ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP -MP $(DEFINES) $(INCLUDES) ALL_ASMFLAGS += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -m64 ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -m64 @@ -56,7 +56,7 @@ ifeq ($(config),debug64) ALL_OBJCPPFLAGS += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -m64 -std=c++14 ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_LDFLAGS += $(LDFLAGS) -L"../build/bin/Debug" -L"." -m64 - LDDEPS += ../build/bin/Debug/libsprt.a ../build/bin/Debug/libJSLib.a ../build/bin/Debug/libgtest.a ../build/bin/Debug/libgmock.a ../build/bin/Debug/libgtest_main.a + LDDEPS += ../build/bin/Debug/libsprt.a ../build/bin/Debug/libspasm_lib.a ../build/bin/Debug/libJSLib.a ../build/bin/Debug/libgtest.a ../build/bin/Debug/libgmock.a ../build/bin/Debug/libgtest_main.a LIBS += $(LDDEPS) -lpthread EXTERNAL_LIBS += LINKOBJS = $(OBJECTS) @@ -80,7 +80,7 @@ ifeq ($(config),release64) TARGETDIR = ../build/bin/Release TARGET = $(TARGETDIR)/Test DEFINES += -D_SCL_SECURE_NO_WARNINGS - INCLUDES += -I"googletest/googletest/include" -I"googletest/googlemock/include" -I".." -I"../../spasm/src" + INCLUDES += -I"googletest/googletest/include" -I"googletest/googlemock/include" -I".." -I"../../spasm/src" -I"../../spasm/src/asm" ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP -MP $(DEFINES) $(INCLUDES) ALL_ASMFLAGS += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -O3 -m64 ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -O3 -m64 @@ -89,7 +89,7 @@ ifeq ($(config),release64) ALL_OBJCPPFLAGS += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -O3 -m64 -std=c++14 ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_LDFLAGS += $(LDFLAGS) -L"../build/bin/Release" -L"." -m64 - LDDEPS += ../build/bin/Release/libsprt.a ../build/bin/Release/libJSLib.a ../build/bin/Release/libgtest.a ../build/bin/Release/libgmock.a ../build/bin/Release/libgtest_main.a + LDDEPS += ../build/bin/Release/libsprt.a ../build/bin/Release/libspasm_lib.a ../build/bin/Release/libJSLib.a ../build/bin/Release/libgtest.a ../build/bin/Release/libgmock.a ../build/bin/Release/libgtest_main.a LIBS += $(LDDEPS) -lpthread EXTERNAL_LIBS += LINKOBJS = $(OBJECTS) diff --git a/JSImpl/test/Test.vcxproj b/JSImpl/test/Test.vcxproj index 3a7058a..c099f1c 100644 --- a/JSImpl/test/Test.vcxproj +++ b/JSImpl/test/Test.vcxproj @@ -57,7 +57,7 @@ <ClCompile>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<Optimization>Disabled</Optimization>
- <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;..\..\spasm\src\asm;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -72,7 +72,7 @@ </ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;..\..\spasm\src\asm;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -87,7 +87,7 @@ <ClCompile>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<Optimization>MaxSpeed</Optimization>
- <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;..\..\spasm\src\asm;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<StringPooling>true</StringPooling>
@@ -102,7 +102,7 @@ </ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;..\..\spasm\src\asm;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -129,6 +129,9 @@ <ProjectReference Include="..\..\spasm\solution\sprt.vcxproj">
<Project>{AE0A9E7C-9A41-9F0D-432E-85102F441B0F}</Project>
</ProjectReference>
+ <ProjectReference Include="..\..\spasm\solution\spasm_lib.vcxproj">
+ <Project>{3F16CDE1-AB80-8158-F4BE-32FE60685FAD}</Project>
+ </ProjectReference>
<ProjectReference Include="..\solution\JSLib.vcxproj">
<Project>{19EA680D-85FE-90BE-4E80-341EBA538DEF}</Project>
</ProjectReference>
diff --git a/JSImpl/test/genie.lua b/JSImpl/test/genie.lua index ba0f0c2..c3cd1d6 100644 --- a/JSImpl/test/genie.lua +++ b/JSImpl/test/genie.lua @@ -10,9 +10,11 @@ project 'Test' 'googletest/googlemock/include', '..', '../../spasm/src', + '../../spasm/src/asm', } links { 'sprt', + 'spasm_lib', 'JSLib', 'gtest', 'gmock', @@ -22,35 +24,36 @@ project 'Test' links 'pthread' configuration '*' -project 'gtest' - kind 'StaticLib' - language 'C++' - uuid(os.uuid('gtest')) - files 'googletest/googletest/src/gtest-all.cc' - files 'googletest/googletest/include/gtest/*.h' - includedirs { - 'googletest/googletest', - 'googletest/googletest/include', - } +group 'gtest' + project 'gtest' + kind 'StaticLib' + language 'C++' + uuid(os.uuid('gtest')) + files 'googletest/googletest/src/gtest-all.cc' + files 'googletest/googletest/include/gtest/*.h' + includedirs { + 'googletest/googletest', + 'googletest/googletest/include', + } -project 'gmock' - kind 'StaticLib' - language 'C++' - uuid(os.uuid('gmock')) - files 'googletest/googlemock/src/gmock-all.cc' - files 'googletest/googlemock/include/gmock/*.h' - includedirs { - 'googletest/googlemock', - 'googletest/googlemock/include', - 'googletest/googletest/include', - } + project 'gmock' + kind 'StaticLib' + language 'C++' + uuid(os.uuid('gmock')) + files 'googletest/googlemock/src/gmock-all.cc' + files 'googletest/googlemock/include/gmock/*.h' + includedirs { + 'googletest/googlemock', + 'googletest/googlemock/include', + 'googletest/googletest/include', + } -project 'gtest_main' - kind 'StaticLib' - language 'C++' - uuid(os.uuid('gtest_main')) - files 'googletest/googletest/src/gtest_main.cc' - includedirs { - 'googletest/googletest', - 'googletest/googletest/include', - } + project 'gtest_main' + kind 'StaticLib' + language 'C++' + uuid(os.uuid('gtest_main')) + files 'googletest/googletest/src/gtest_main.cc' + includedirs { + 'googletest/googletest', + 'googletest/googletest/include', + } diff --git a/JSImpl/test/gmock.vcxproj b/JSImpl/test/gmock.vcxproj index 8fbaa69..f4e2bec 100644 --- a/JSImpl/test/gmock.vcxproj +++ b/JSImpl/test/gmock.vcxproj @@ -21,11 +21,13 @@ <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@@ -114,17 +116,17 @@ </Link>
</ItemDefinitionGroup>
<ItemGroup>
- <ClInclude Include="googletest\googlemock\include\gmock\gmock-spec-builders.h" />
- <ClInclude Include="googletest\googlemock\include\gmock\gmock.h" />
<ClInclude Include="googletest\googlemock\include\gmock\gmock-actions.h" />
- <ClInclude Include="googletest\googlemock\include\gmock\gmock-generated-matchers.h" />
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock-cardinalities.h" />
<ClInclude Include="googletest\googlemock\include\gmock\gmock-generated-actions.h" />
- <ClInclude Include="googletest\googlemock\include\gmock\gmock-more-matchers.h" />
<ClInclude Include="googletest\googlemock\include\gmock\gmock-generated-function-mockers.h" />
- <ClInclude Include="googletest\googlemock\include\gmock\gmock-cardinalities.h" />
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock-generated-matchers.h" />
<ClInclude Include="googletest\googlemock\include\gmock\gmock-generated-nice-strict.h" />
- <ClInclude Include="googletest\googlemock\include\gmock\gmock-more-actions.h" />
<ClInclude Include="googletest\googlemock\include\gmock\gmock-matchers.h" />
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock-more-actions.h" />
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock-more-matchers.h" />
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock-spec-builders.h" />
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="googletest\googlemock\src\gmock-all.cc">
diff --git a/JSImpl/test/gmock.vcxproj.filters b/JSImpl/test/gmock.vcxproj.filters index 01914f2..7ecdd12 100644 --- a/JSImpl/test/gmock.vcxproj.filters +++ b/JSImpl/test/gmock.vcxproj.filters @@ -18,37 +18,37 @@ </Filter>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="googletest\googlemock\include\gmock\gmock-spec-builders.h">
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock-actions.h">
<Filter>googletest\googlemock\include\gmock</Filter>
</ClInclude>
- <ClInclude Include="googletest\googlemock\include\gmock\gmock.h">
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock-cardinalities.h">
<Filter>googletest\googlemock\include\gmock</Filter>
</ClInclude>
- <ClInclude Include="googletest\googlemock\include\gmock\gmock-actions.h">
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock-generated-actions.h">
<Filter>googletest\googlemock\include\gmock</Filter>
</ClInclude>
- <ClInclude Include="googletest\googlemock\include\gmock\gmock-generated-matchers.h">
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock-generated-function-mockers.h">
<Filter>googletest\googlemock\include\gmock</Filter>
</ClInclude>
- <ClInclude Include="googletest\googlemock\include\gmock\gmock-generated-actions.h">
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock-generated-matchers.h">
<Filter>googletest\googlemock\include\gmock</Filter>
</ClInclude>
- <ClInclude Include="googletest\googlemock\include\gmock\gmock-more-matchers.h">
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock-generated-nice-strict.h">
<Filter>googletest\googlemock\include\gmock</Filter>
</ClInclude>
- <ClInclude Include="googletest\googlemock\include\gmock\gmock-generated-function-mockers.h">
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock-matchers.h">
<Filter>googletest\googlemock\include\gmock</Filter>
</ClInclude>
- <ClInclude Include="googletest\googlemock\include\gmock\gmock-cardinalities.h">
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock-more-actions.h">
<Filter>googletest\googlemock\include\gmock</Filter>
</ClInclude>
- <ClInclude Include="googletest\googlemock\include\gmock\gmock-generated-nice-strict.h">
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock-more-matchers.h">
<Filter>googletest\googlemock\include\gmock</Filter>
</ClInclude>
- <ClInclude Include="googletest\googlemock\include\gmock\gmock-more-actions.h">
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock-spec-builders.h">
<Filter>googletest\googlemock\include\gmock</Filter>
</ClInclude>
- <ClInclude Include="googletest\googlemock\include\gmock\gmock-matchers.h">
+ <ClInclude Include="googletest\googlemock\include\gmock\gmock.h">
<Filter>googletest\googlemock\include\gmock</Filter>
</ClInclude>
</ItemGroup>
diff --git a/JSImpl/test/gtest.vcxproj b/JSImpl/test/gtest.vcxproj index 623e8f5..7adfade 100644 --- a/JSImpl/test/gtest.vcxproj +++ b/JSImpl/test/gtest.vcxproj @@ -21,11 +21,13 @@ <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@@ -114,16 +116,16 @@ </Link>
</ItemDefinitionGroup>
<ItemGroup>
- <ClInclude Include="googletest\googletest\include\gtest\gtest_prod.h" />
+ <ClInclude Include="googletest\googletest\include\gtest\gtest-death-test.h" />
<ClInclude Include="googletest\googletest\include\gtest\gtest-message.h" />
<ClInclude Include="googletest\googletest\include\gtest\gtest-param-test.h" />
- <ClInclude Include="googletest\googletest\include\gtest\gtest-test-part.h" />
<ClInclude Include="googletest\googletest\include\gtest\gtest-printers.h" />
- <ClInclude Include="googletest\googletest\include\gtest\gtest-typed-test.h" />
<ClInclude Include="googletest\googletest\include\gtest\gtest-spi.h" />
- <ClInclude Include="googletest\googletest\include\gtest\gtest_pred_impl.h" />
+ <ClInclude Include="googletest\googletest\include\gtest\gtest-test-part.h" />
+ <ClInclude Include="googletest\googletest\include\gtest\gtest-typed-test.h" />
<ClInclude Include="googletest\googletest\include\gtest\gtest.h" />
- <ClInclude Include="googletest\googletest\include\gtest\gtest-death-test.h" />
+ <ClInclude Include="googletest\googletest\include\gtest\gtest_pred_impl.h" />
+ <ClInclude Include="googletest\googletest\include\gtest\gtest_prod.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="googletest\googletest\src\gtest-all.cc">
diff --git a/JSImpl/test/gtest.vcxproj.filters b/JSImpl/test/gtest.vcxproj.filters index 780060b..3a35c75 100644 --- a/JSImpl/test/gtest.vcxproj.filters +++ b/JSImpl/test/gtest.vcxproj.filters @@ -18,7 +18,7 @@ </Filter>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="googletest\googletest\include\gtest\gtest_prod.h">
+ <ClInclude Include="googletest\googletest\include\gtest\gtest-death-test.h">
<Filter>googletest\googletest\include\gtest</Filter>
</ClInclude>
<ClInclude Include="googletest\googletest\include\gtest\gtest-message.h">
@@ -27,25 +27,25 @@ <ClInclude Include="googletest\googletest\include\gtest\gtest-param-test.h">
<Filter>googletest\googletest\include\gtest</Filter>
</ClInclude>
- <ClInclude Include="googletest\googletest\include\gtest\gtest-test-part.h">
- <Filter>googletest\googletest\include\gtest</Filter>
- </ClInclude>
<ClInclude Include="googletest\googletest\include\gtest\gtest-printers.h">
<Filter>googletest\googletest\include\gtest</Filter>
</ClInclude>
- <ClInclude Include="googletest\googletest\include\gtest\gtest-typed-test.h">
+ <ClInclude Include="googletest\googletest\include\gtest\gtest-spi.h">
<Filter>googletest\googletest\include\gtest</Filter>
</ClInclude>
- <ClInclude Include="googletest\googletest\include\gtest\gtest-spi.h">
+ <ClInclude Include="googletest\googletest\include\gtest\gtest-test-part.h">
<Filter>googletest\googletest\include\gtest</Filter>
</ClInclude>
- <ClInclude Include="googletest\googletest\include\gtest\gtest_pred_impl.h">
+ <ClInclude Include="googletest\googletest\include\gtest\gtest-typed-test.h">
<Filter>googletest\googletest\include\gtest</Filter>
</ClInclude>
<ClInclude Include="googletest\googletest\include\gtest\gtest.h">
<Filter>googletest\googletest\include\gtest</Filter>
</ClInclude>
- <ClInclude Include="googletest\googletest\include\gtest\gtest-death-test.h">
+ <ClInclude Include="googletest\googletest\include\gtest\gtest_pred_impl.h">
+ <Filter>googletest\googletest\include\gtest</Filter>
+ </ClInclude>
+ <ClInclude Include="googletest\googletest\include\gtest\gtest_prod.h">
<Filter>googletest\googletest\include\gtest</Filter>
</ClInclude>
</ItemGroup>
diff --git a/JSImpl/test/gtest_main.vcxproj b/JSImpl/test/gtest_main.vcxproj index 997d941..2ce7ce4 100644 --- a/JSImpl/test/gtest_main.vcxproj +++ b/JSImpl/test/gtest_main.vcxproj @@ -21,11 +21,13 @@ <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
diff --git a/JSImpl/test/sprtTests.cpp b/JSImpl/test/sprtTests.cpp index 7621ca3..eef7147 100644 --- a/JSImpl/test/sprtTests.cpp +++ b/JSImpl/test/sprtTests.cpp @@ -1,6 +1,7 @@ #include <gtest/gtest.h> #include <spasm.hpp> +#include <assembler.hpp> #include <sstream> using Spasm::OpCodes; @@ -9,12 +10,12 @@ struct SPRTTest : public ::testing::Test { typedef std::vector<Spasm::byte> ByteCode; - void Run(ByteCode& code) + void Run(const ByteCode& code) { Run(code.data(), code.size()); } - void Run(Spasm::byte* bytecode, size_t size) + void Run(const Spasm::byte* bytecode, size_t size) { VM.Initialize(size, bytecode, Input, Output); ASSERT_EQ(Spasm::Spasm::RunResult::Success, VM.run()); @@ -27,6 +28,19 @@ struct SPRTTest : public ::testing::Test std::ostringstream Output; }; +struct SPASMTest : public SPRTTest +{ + void CompileAndRun(const std::string& program) + { + SpasmImpl::ASM::Bytecode_Memory bytecode; + std::istringstream programInput; + programInput.str(program); + ASSERT_TRUE(SpasmImpl::ASM::compile(programInput, bytecode)) + << "Could not compile the program:" << std::endl << program; + Run(bytecode.bytecode()); + } +}; + TEST_F(SPRTTest, Empty) { } @@ -184,22 +198,22 @@ TEST_F(SPRTTest, JumpFalse) TEST_F(SPRTTest, Call) { Spasm::byte bytecode[] = { - OpCodes::Alloc, 5, // 2 + OpCodes::Push, 5, // 2 OpCodes::Const, 1, 0, // 5 OpCodes::Const, 2, 6, // 8 OpCodes::Const, 3, 7, // 11 OpCodes::Const, 4, 2, // 14 - OpCodes::Push, 3, // 16 - OpCodes::Push, 2, // 18 - OpCodes::Push, 4, // 20 + OpCodes::PushFrom, 3, // 16 + OpCodes::PushFrom, 2, // 18 + OpCodes::PushFrom, 4, // 20 OpCodes::Call, 25, // 22 OpCodes::Print, 4, // 24 - OpCodes::Halt, // 25 + OpCodes::Halt, // 25 OpCodes::Print, 0, // 27 OpCodes::Print, -1, // 29 OpCodes::Print, -2, // 31 OpCodes::Mul, 1, -2, -1,// 33 - OpCodes::Ret, 1, // 35 + OpCodes::Ret, 1, // 35 }; Run(bytecode, sizeof(bytecode)); @@ -218,3 +232,81 @@ TEST_F(SPRTTest, Read) ASSERT_EQ(Output.str(), "42"); } +TEST_F(SPASMTest, RSyntax) +{ + const char* program = + "push 5" "\n" + "const r1 0" "\n" + "const r2 6" "\n" + "const r3 7" "\n" + "const r4 2" "\n" + "pushr r3" "\n" + "pushr r2" "\n" + "pushr r4" "\n" + "call mult" "\n" + "popr r1" "\n" + "print r1" "\n" + "halt" "\n" + "label mult" "\n" + "print a0" "\n" + "print a1" "\n" + "print a2" "\n" + "mul r1 a2 a1" "\n" + "ret r1" "\n" + "" + ; + CompileAndRun(program); + ASSERT_EQ(Output.str(), "26742"); +} + +TEST_F(SPASMTest, Call) +{ + const char* program = + "push 5" "\n" + "const 1 0" "\n" + "const 2 6" "\n" + "const 3 7" "\n" + "const 4 2" "\n" + "pushr 3" "\n" + "pushr 2" "\n" + "pushr 4" "\n" + "call mult" "\n" + "print 4" "\n" + "halt" "\n" + "label mult" "\n" + "print 0" "\n" + "print -1" "\n" + "print -2" "\n" + "mul 1 -2 -1" "\n" + "ret 1" "\n" + "" + ; + CompileAndRun(program); + ASSERT_EQ(Output.str(), "26742"); +} + +TEST_F(SPASMTest, GCD) +{ + const char* program = + "push 3" "\n" + "read 1" "\n" + "read 2" "\n" + "label loop" "\n" + "less 3 1 2" "\n" + "jmpt 3 sub_ba" "\n" + "less 3 2 1" "\n" + "jmpt 3 sub_ab" "\n" + "print 1" "\n" + "halt" "\n" + "label sub_ab" "\n" + "sub 1 1 2" "\n" + "jmp loop" "\n" + "label sub_ba" "\n" + "sub 2 2 1" "\n" + "jmp loop" "\n" + "" + ; + Input.str("21 12"); + CompileAndRun(program); + ASSERT_EQ(Output.str(), "3"); +} diff --git a/spasm/solution/genie.lua b/spasm/solution/genie.lua index b310ad0..d1fb495 100644 --- a/spasm/solution/genie.lua +++ b/spasm/solution/genie.lua @@ -34,11 +34,24 @@ end removefiles '../src/main.cpp' files '../src/*.h' + project 'spasm_lib' + kind 'StaticLib' + language 'C++' + uuid(os.uuid('spasm_lib')) + files '../src/asm/*.cpp' + removefiles { + '../src/asm/main.cpp', + '../src/asm/lexdump.cpp', + '../src/asm/lexdump3.cpp', + } + files '../src/asm/*.h' + project 'spasm' kind 'ConsoleApp' language 'C++' uuid(os.uuid('spasm')) - files '../src/asm/*.cpp' + links 'spasm_lib' + files '../src/asm/main.cpp' removefiles { '../src/asm/lexdump.cpp', '../src/asm/lexdump3.cpp', diff --git a/spasm/solution/spasm.make b/spasm/solution/spasm.make index f2aa890..6c081cc 100644 --- a/spasm/solution/spasm.make +++ b/spasm/solution/spasm.make @@ -54,20 +54,14 @@ ifeq ($(config),debug64) ALL_OBJCFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -m64 ALL_OBJCPPFLAGS += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -m64 -std=c++14 ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) - ALL_LDFLAGS += $(LDFLAGS) -m64 - LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -L"../../JSImpl/build/bin/Debug" -m64 + LDDEPS += ../../JSImpl/build/bin/Debug/libspasm_lib.a LIBS += $(LDDEPS) EXTERNAL_LIBS += LINKOBJS = $(OBJECTS) LINKCMD = $(CXX) -o $(TARGET) $(LINKOBJS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS) OBJECTS := \ - $(OBJDIR)/src/asm/assembler.o \ - $(OBJDIR)/src/asm/bytecode.o \ - $(OBJDIR)/src/asm/lexer.o \ $(OBJDIR)/src/asm/main.o \ - $(OBJDIR)/src/asm/symbol.o \ - $(OBJDIR)/src/asm/token.o \ - $(OBJDIR)/src/asm/tokenizer.o \ define PREBUILDCMDS endef @@ -89,20 +83,14 @@ ifeq ($(config),release64) ALL_OBJCFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -O3 -m64 ALL_OBJCPPFLAGS += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -O3 -m64 -std=c++14 ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) - ALL_LDFLAGS += $(LDFLAGS) -m64 - LDDEPS += + ALL_LDFLAGS += $(LDFLAGS) -L"../../JSImpl/build/bin/Release" -m64 + LDDEPS += ../../JSImpl/build/bin/Release/libspasm_lib.a LIBS += $(LDDEPS) EXTERNAL_LIBS += LINKOBJS = $(OBJECTS) LINKCMD = $(CXX) -o $(TARGET) $(LINKOBJS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS) OBJECTS := \ - $(OBJDIR)/src/asm/assembler.o \ - $(OBJDIR)/src/asm/bytecode.o \ - $(OBJDIR)/src/asm/lexer.o \ $(OBJDIR)/src/asm/main.o \ - $(OBJDIR)/src/asm/symbol.o \ - $(OBJDIR)/src/asm/token.o \ - $(OBJDIR)/src/asm/tokenizer.o \ define PREBUILDCMDS endef @@ -162,34 +150,10 @@ $(GCH_OBJC): $(PCH) $(MAKEFILE) | $(OBJDIR) $(SILENT) $(CXX) $(ALL_OBJCPPFLAGS) -x objective-c++-header $(DEFINES) $(INCLUDES) -o "$@" -c "$<" endif -$(OBJDIR)/src/asm/assembler.o: ../src/asm/assembler.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/src/asm - @echo $(notdir $<) - $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" - -$(OBJDIR)/src/asm/bytecode.o: ../src/asm/bytecode.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/src/asm - @echo $(notdir $<) - $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" - -$(OBJDIR)/src/asm/lexer.o: ../src/asm/lexer.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/src/asm - @echo $(notdir $<) - $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" - $(OBJDIR)/src/asm/main.o: ../src/asm/main.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/src/asm @echo $(notdir $<) $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" -$(OBJDIR)/src/asm/symbol.o: ../src/asm/symbol.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/src/asm - @echo $(notdir $<) - $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" - -$(OBJDIR)/src/asm/token.o: ../src/asm/token.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/src/asm - @echo $(notdir $<) - $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" - -$(OBJDIR)/src/asm/tokenizer.o: ../src/asm/tokenizer.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/src/asm - @echo $(notdir $<) - $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" - -include $(OBJECTS:%.o=%.d) ifneq (,$(PCH)) -include $(OBJDIR)/$(notdir $(PCH)).d diff --git a/spasm/solution/spasm.vcxproj b/spasm/solution/spasm.vcxproj index e39730e..b0b5718 100644 --- a/spasm/solution/spasm.vcxproj +++ b/spasm/solution/spasm.vcxproj @@ -21,11 +21,13 @@ <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@@ -110,20 +112,13 @@ </Link>
</ItemDefinitionGroup>
<ItemGroup>
- <ClCompile Include="..\src\asm\tokenizer.cpp">
- </ClCompile>
- <ClCompile Include="..\src\asm\bytecode.cpp">
- </ClCompile>
- <ClCompile Include="..\src\asm\assembler.cpp">
- </ClCompile>
- <ClCompile Include="..\src\asm\lexer.cpp">
- </ClCompile>
- <ClCompile Include="..\src\asm\token.cpp">
- </ClCompile>
<ClCompile Include="..\src\asm\main.cpp">
</ClCompile>
- <ClCompile Include="..\src\asm\symbol.cpp">
- </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="spasm_lib.vcxproj">
+ <Project>{3F16CDE1-AB80-8158-F4BE-32FE60685FAD}</Project>
+ </ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/spasm/solution/spasm.vcxproj.filters b/spasm/solution/spasm.vcxproj.filters index 30cc8cb..a9d3fb8 100644 --- a/spasm/solution/spasm.vcxproj.filters +++ b/spasm/solution/spasm.vcxproj.filters @@ -9,26 +9,8 @@ </Filter>
</ItemGroup>
<ItemGroup>
- <ClCompile Include="..\src\asm\tokenizer.cpp">
- <Filter>src\asm</Filter>
- </ClCompile>
- <ClCompile Include="..\src\asm\bytecode.cpp">
- <Filter>src\asm</Filter>
- </ClCompile>
- <ClCompile Include="..\src\asm\assembler.cpp">
- <Filter>src\asm</Filter>
- </ClCompile>
- <ClCompile Include="..\src\asm\lexer.cpp">
- <Filter>src\asm</Filter>
- </ClCompile>
- <ClCompile Include="..\src\asm\token.cpp">
- <Filter>src\asm</Filter>
- </ClCompile>
<ClCompile Include="..\src\asm\main.cpp">
<Filter>src\asm</Filter>
</ClCompile>
- <ClCompile Include="..\src\asm\symbol.cpp">
- <Filter>src\asm</Filter>
- </ClCompile>
</ItemGroup>
</Project>
diff --git a/spasm/solution/spasm_lib.make b/spasm/solution/spasm_lib.make new file mode 100644 index 0000000..94b4322 --- /dev/null +++ b/spasm/solution/spasm_lib.make @@ -0,0 +1,196 @@ +# GNU Make project makefile autogenerated by GENie +ifndef config + config=debug64 +endif + +ifndef verbose + SILENT = @ +endif + +SHELLTYPE := msdos +ifeq (,$(ComSpec)$(COMSPEC)) + SHELLTYPE := posix +endif +ifeq (/bin,$(findstring /bin,$(SHELL))) + SHELLTYPE := posix +endif +ifeq (/bin,$(findstring /bin,$(MAKESHELL))) + SHELLTYPE := posix +endif + +ifeq (posix,$(SHELLTYPE)) + MKDIR = $(SILENT) mkdir -p "$(1)" + COPY = $(SILENT) cp -fR "$(1)" "$(2)" + RM = $(SILENT) rm -f "$(1)" +else + MKDIR = $(SILENT) mkdir "$(subst /,\\,$(1))" 2> nul || exit 0 + COPY = $(SILENT) copy /Y "$(subst /,\\,$(1))" "$(subst /,\\,$(2))" + RM = $(SILENT) del /F "$(subst /,\\,$(1))" 2> nul || exit 0 +endif + +CC = gcc +CXX = g++ +AR = ar + +ifndef RESCOMP + ifdef WINDRES + RESCOMP = $(WINDRES) + else + RESCOMP = windres + endif +endif + +MAKEFILE = spasm_lib.make + +ifeq ($(config),debug64) + OBJDIR = ../../JSImpl/build/obj/Debug/x64/Debug/spasm_lib + TARGETDIR = ../../JSImpl/build/bin/Debug + TARGET = $(TARGETDIR)/libspasm_lib.a + DEFINES += -D_SCL_SECURE_NO_WARNINGS + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP -MP $(DEFINES) $(INCLUDES) + ALL_ASMFLAGS += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -m64 + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -m64 + ALL_CXXFLAGS += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -m64 -std=c++14 + ALL_OBJCFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -m64 + ALL_OBJCPPFLAGS += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -m64 -std=c++14 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + ALL_LDFLAGS += $(LDFLAGS) -m64 + LDDEPS += + LIBS += $(LDDEPS) + EXTERNAL_LIBS += + LINKOBJS = $(OBJECTS) + LINKCMD = $(AR) -rcs $(TARGET) + OBJECTS := \ + $(OBJDIR)/src/asm/assembler.o \ + $(OBJDIR)/src/asm/bytecode.o \ + $(OBJDIR)/src/asm/lexer.o \ + $(OBJDIR)/src/asm/symbol.o \ + $(OBJDIR)/src/asm/token.o \ + $(OBJDIR)/src/asm/tokenizer.o \ + + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +endif + +ifeq ($(config),release64) + OBJDIR = ../../JSImpl/build/obj/Release/x64/Release/spasm_lib + TARGETDIR = ../../JSImpl/build/bin/Release + TARGET = $(TARGETDIR)/libspasm_lib.a + DEFINES += -D_SCL_SECURE_NO_WARNINGS + ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP -MP $(DEFINES) $(INCLUDES) + ALL_ASMFLAGS += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -O3 -m64 + ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -O3 -m64 + ALL_CXXFLAGS += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -O3 -m64 -std=c++14 + ALL_OBJCFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -O3 -m64 + ALL_OBJCPPFLAGS += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -O3 -m64 -std=c++14 + ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) + ALL_LDFLAGS += $(LDFLAGS) -m64 + LDDEPS += + LIBS += $(LDDEPS) + EXTERNAL_LIBS += + LINKOBJS = $(OBJECTS) + LINKCMD = $(AR) -rcs $(TARGET) + OBJECTS := \ + $(OBJDIR)/src/asm/assembler.o \ + $(OBJDIR)/src/asm/bytecode.o \ + $(OBJDIR)/src/asm/lexer.o \ + $(OBJDIR)/src/asm/symbol.o \ + $(OBJDIR)/src/asm/token.o \ + $(OBJDIR)/src/asm/tokenizer.o \ + + define PREBUILDCMDS + endef + define PRELINKCMDS + endef + define POSTBUILDCMDS + endef +endif + +OBJDIRS := \ + $(OBJDIR) \ + $(OBJDIR)/src/asm \ + +RESOURCES := \ + +.PHONY: clean prebuild prelink + +all: $(OBJDIRS) $(TARGETDIR) prebuild prelink $(TARGET) + @: + +$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(EXTERNAL_LIBS) $(RESOURCES) | $(TARGETDIR) $(OBJDIRS) + @echo Archiving spasm_lib +ifeq (posix,$(SHELLTYPE)) + $(SILENT) rm -f $(TARGET) +else + $(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET)) +endif + $(SILENT) $(LINKCMD) $(LINKOBJS) + $(POSTBUILDCMDS) + +$(TARGETDIR): + @echo Creating $(TARGETDIR) + -$(call MKDIR,$(TARGETDIR)) + +$(OBJDIRS): + @echo Creating $(@) + -$(call MKDIR,$@) + +clean: + @echo Cleaning spasm_lib +ifeq (posix,$(SHELLTYPE)) + $(SILENT) rm -f $(TARGET) + $(SILENT) rm -rf $(OBJDIR) +else + $(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET)) + $(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR)) +endif + +prebuild: + $(PREBUILDCMDS) + +prelink: + $(PRELINKCMDS) + +ifneq (,$(PCH)) +$(GCH): $(PCH) $(MAKEFILE) | $(OBJDIR) + @echo $(notdir $<) + $(SILENT) $(CXX) $(ALL_CXXFLAGS) -x c++-header $(DEFINES) $(INCLUDES) -o "$@" -c "$<" + +$(GCH_OBJC): $(PCH) $(MAKEFILE) | $(OBJDIR) + @echo $(notdir $<) + $(SILENT) $(CXX) $(ALL_OBJCPPFLAGS) -x objective-c++-header $(DEFINES) $(INCLUDES) -o "$@" -c "$<" +endif + +$(OBJDIR)/src/asm/assembler.o: ../src/asm/assembler.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/src/asm + @echo $(notdir $<) + $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" + +$(OBJDIR)/src/asm/bytecode.o: ../src/asm/bytecode.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/src/asm + @echo $(notdir $<) + $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" + +$(OBJDIR)/src/asm/lexer.o: ../src/asm/lexer.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/src/asm + @echo $(notdir $<) + $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" + +$(OBJDIR)/src/asm/symbol.o: ../src/asm/symbol.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/src/asm + @echo $(notdir $<) + $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" + +$(OBJDIR)/src/asm/token.o: ../src/asm/token.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/src/asm + @echo $(notdir $<) + $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" + +$(OBJDIR)/src/asm/tokenizer.o: ../src/asm/tokenizer.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/src/asm + @echo $(notdir $<) + $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" + +-include $(OBJECTS:%.o=%.d) +ifneq (,$(PCH)) + -include $(OBJDIR)/$(notdir $(PCH)).d + -include $(OBJDIR)/$(notdir $(PCH))_objc.d +endif diff --git a/spasm/solution/spasm_lib.vcxproj b/spasm/solution/spasm_lib.vcxproj new file mode 100644 index 0000000..bf3908e --- /dev/null +++ b/spasm/solution/spasm_lib.vcxproj @@ -0,0 +1,131 @@ +<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{3F16CDE1-AB80-8158-F4BE-32FE60685FAD}</ProjectGuid>
+ <RootNamespace>spasm_lib</RootNamespace>
+ <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+ <Keyword>Win32Proj</Keyword>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <OutDir>..\..\JSImpl\build\bin\Debug\</OutDir>
+ <IntDir>..\..\JSImpl\build\obj\Debug\x64\Debug\spasm_lib\</IntDir>
+ <TargetName>spasm_lib</TargetName>
+ <TargetExt>.lib</TargetExt>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <OutDir>..\..\JSImpl\build\bin\Release\</OutDir>
+ <IntDir>..\..\JSImpl\build\obj\Release\x64\Release\spasm_lib\</IntDir>
+ <TargetName>spasm_lib</TargetName>
+ <TargetExt>.lib</TargetExt>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <MinimalRebuild>false</MinimalRebuild>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
+ <PrecompiledHeader></PrecompiledHeader>
+ <WarningLevel>Level4</WarningLevel>
+ <TreatWarningAsError>true</TreatWarningAsError>
+ <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+ <ProgramDataBaseFileName>$(OutDir)spasm_lib.pdb</ProgramDataBaseFileName>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ResourceCompile>
+ <Lib>
+ <OutputFile>$(OutDir)spasm_lib.lib</OutputFile>
+ <TargetMachine>MachineX64</TargetMachine>
+ </Lib>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <ProgramDatabaseFile>$(OutDir)spasm_lib.pdb</ProgramDatabaseFile>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
+ <Optimization>MaxSpeed</Optimization>
+ <PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <MinimalRebuild>false</MinimalRebuild>
+ <StringPooling>true</StringPooling>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
+ <PrecompiledHeader></PrecompiledHeader>
+ <WarningLevel>Level4</WarningLevel>
+ <TreatWarningAsError>true</TreatWarningAsError>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <ProgramDataBaseFileName>$(OutDir)spasm_lib.pdb</ProgramDataBaseFileName>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ResourceCompile>
+ <Lib>
+ <OutputFile>$(OutDir)spasm_lib.lib</OutputFile>
+ <TargetMachine>MachineX64</TargetMachine>
+ </Lib>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <ProgramDatabaseFile>$(OutDir)spasm_lib.pdb</ProgramDatabaseFile>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="..\src\asm\assembler.cpp">
+ </ClCompile>
+ <ClCompile Include="..\src\asm\bytecode.cpp">
+ </ClCompile>
+ <ClCompile Include="..\src\asm\lexer.cpp">
+ </ClCompile>
+ <ClCompile Include="..\src\asm\symbol.cpp">
+ </ClCompile>
+ <ClCompile Include="..\src\asm\token.cpp">
+ </ClCompile>
+ <ClCompile Include="..\src\asm\tokenizer.cpp">
+ </ClCompile>
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
diff --git a/spasm/solution/spasm_lib.vcxproj.filters b/spasm/solution/spasm_lib.vcxproj.filters new file mode 100644 index 0000000..6415708 --- /dev/null +++ b/spasm/solution/spasm_lib.vcxproj.filters @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="src">
+ <UniqueIdentifier>{2DAB880B-99B4-887C-2230-9F7C8E38947C}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="src\asm">
+ <UniqueIdentifier>{6A9848A9-D677-C744-DF8F-521B4BEE2DA6}</UniqueIdentifier>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\src\asm\assembler.cpp">
+ <Filter>src\asm</Filter>
+ </ClCompile>
+ <ClCompile Include="..\src\asm\bytecode.cpp">
+ <Filter>src\asm</Filter>
+ </ClCompile>
+ <ClCompile Include="..\src\asm\lexer.cpp">
+ <Filter>src\asm</Filter>
+ </ClCompile>
+ <ClCompile Include="..\src\asm\symbol.cpp">
+ <Filter>src\asm</Filter>
+ </ClCompile>
+ <ClCompile Include="..\src\asm\token.cpp">
+ <Filter>src\asm</Filter>
+ </ClCompile>
+ <ClCompile Include="..\src\asm\tokenizer.cpp">
+ <Filter>src\asm</Filter>
+ </ClCompile>
+ </ItemGroup>
+</Project>
diff --git a/spasm/solution/sprt.vcxproj b/spasm/solution/sprt.vcxproj index 2698c10..bd7f6c0 100644 --- a/spasm/solution/sprt.vcxproj +++ b/spasm/solution/sprt.vcxproj @@ -21,11 +21,13 @@ <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
diff --git a/spasm/solution/sprun.vcxproj b/spasm/solution/sprun.vcxproj index ea923b4..ee6678e 100644 --- a/spasm/solution/sprun.vcxproj +++ b/spasm/solution/sprun.vcxproj @@ -21,11 +21,13 @@ <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
diff --git a/spasm/src/asm/bytecode.hpp b/spasm/src/asm/bytecode.hpp index d249db8..374ccef 100644 --- a/spasm/src/asm/bytecode.hpp +++ b/spasm/src/asm/bytecode.hpp @@ -13,8 +13,8 @@ namespace ASM class Bytecode_Stream { public: - typedef unsigned char byte; - typedef byte Opcode_t; + typedef int8_t byte; + typedef byte Opcode_t; virtual ~Bytecode_Stream(); virtual void push_opcode(Opcode_t) = 0; diff --git a/spasm/src/asm/lexer.cpp b/spasm/src/asm/lexer.cpp index a012650..3af83c7 100644 --- a/spasm/src/asm/lexer.cpp +++ b/spasm/src/asm/lexer.cpp @@ -1,4 +1,4 @@ -/* Generated by re2c 1.1.1 on Wed Nov 14 19:46:01 2018 */ +/* Generated by re2c 1.1.1 on Thu Nov 15 10:01:26 2018 */ #line 1 "lexer.re" #include <iostream> @@ -128,7 +128,7 @@ bool Lexer::tokenize(TokenStream& ts) } yy2: ++cursor; -#line 237 "lexer.re" +#line 254 "lexer.re" { ts.push_token(Token(Token::EndInput, lineno)); @@ -138,7 +138,7 @@ bool Lexer::tokenize(TokenStream& ts) yy4: ++cursor; yy5: -#line 243 "lexer.re" +#line 260 "lexer.re" { return false; } @@ -157,7 +157,7 @@ bool Lexer::tokenize(TokenStream& ts) goto yy8; } yy8: -#line 224 "lexer.re" +#line 241 "lexer.re" { token_start = cursor; @@ -166,10 +166,9 @@ bool Lexer::tokenize(TokenStream& ts) #line 150 "lexer.cpp" yy9: ++cursor; -#line 230 "lexer.re" +#line 247 "lexer.re" { ++lineno; - token_start = cursor; continue; @@ -195,12 +194,9 @@ bool Lexer::tokenize(TokenStream& ts) goto yy13; } yy13: -#line 58 "lexer.re" +#line 59 "lexer.re" { - ts.push_token(Token(Token::Integer, lineno, - - token_start, cursor)); - + ts.push_token(Token(Token::Integer, lineno, token_start, cursor)); token_start = cursor; continue; @@ -303,12 +299,9 @@ bool Lexer::tokenize(TokenStream& ts) goto yy18; } yy18: -#line 216 "lexer.re" +#line 233 "lexer.re" { - ts.push_token(Token(Token::Ident, lineno, token_start, - - cursor)); - + ts.push_token(Token(Token::Ident, lineno, token_start, cursor)); token_start = cursor; continue; @@ -318,10 +311,20 @@ bool Lexer::tokenize(TokenStream& ts) yych = *++cursor; switch (yych) { - case 'd': + case '0': goto yy31; - case 'l': - goto yy32; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + goto yy33; + case 'd': + goto yy35; default: goto yy17; } @@ -330,9 +333,9 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case 'a': - goto yy33; + goto yy36; case 'o': - goto yy34; + goto yy37; default: goto yy17; } @@ -341,9 +344,9 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case 'i': - goto yy35; + goto yy38; case 'u': - goto yy36; + goto yy39; default: goto yy17; } @@ -352,7 +355,7 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case 'm': - goto yy37; + goto yy40; default: goto yy17; } @@ -361,9 +364,9 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case 'a': - goto yy38; + goto yy41; case 'e': - goto yy39; + goto yy42; default: goto yy17; } @@ -372,9 +375,9 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case 'o': - goto yy40; + goto yy43; case 'u': - goto yy41; + goto yy44; default: goto yy17; } @@ -383,11 +386,11 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case 'o': - goto yy42; + goto yy45; case 'r': - goto yy43; + goto yy46; case 'u': - goto yy44; + goto yy47; default: goto yy17; } @@ -395,8 +398,20 @@ bool Lexer::tokenize(TokenStream& ts) yych = *++cursor; switch (yych) { + case '0': + goto yy48; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + goto yy50; case 'e': - goto yy45; + goto yy52; default: goto yy17; } @@ -405,7 +420,7 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case 'u': - goto yy46; + goto yy53; default: goto yy17; } @@ -438,7 +453,7 @@ bool Lexer::tokenize(TokenStream& ts) case 'd': case 'e': case 'f': - goto yy47; + goto yy54; default: goto yy30; } @@ -449,151 +464,454 @@ bool Lexer::tokenize(TokenStream& ts) yych = *++cursor; switch (yych) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': case 'd': - goto yy50; + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + goto yy16; default: - goto yy17; + goto yy32; } yy32: - yych = *++cursor; +#line 74 "lexer.re" + { + Token t(Token::Integer, lineno, token_start + 1, cursor); + t.set_int(-t.value_int()); + ts.push_token(t); + token_start = cursor; + continue; + } +#line 473 "lexer.cpp" + yy33: + ++cursor; + if (limit <= cursor) + return true; + yych = *cursor; switch (yych) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + goto yy33; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': case 'l': - goto yy52; + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + goto yy16; + default: + goto yy32; + } + yy35: + yych = *++cursor; + switch (yych) + { + case 'd': + goto yy57; default: goto yy17; } - yy33: + yy36: yych = *++cursor; switch (yych) { case 'l': - goto yy53; + goto yy59; default: goto yy17; } - yy34: + yy37: yych = *++cursor; switch (yych) { case 'n': - goto yy54; + goto yy60; default: goto yy17; } - yy35: + yy38: yych = *++cursor; switch (yych) { case 'v': - goto yy55; + goto yy61; default: goto yy17; } - yy36: + yy39: yych = *++cursor; switch (yych) { case 'p': - goto yy57; + goto yy63; default: goto yy17; } - yy37: + yy40: yych = *++cursor; switch (yych) { case 'p': - goto yy59; + goto yy65; default: goto yy17; } - yy38: + yy41: yych = *++cursor; switch (yych) { case 'b': - goto yy61; + goto yy67; default: goto yy17; } - yy39: + yy42: yych = *++cursor; switch (yych) { case 'q': - goto yy62; + goto yy68; case 's': - goto yy64; + goto yy70; default: goto yy17; } - yy40: + yy43: yych = *++cursor; switch (yych) { case 'd': - goto yy65; + goto yy71; default: goto yy17; } - yy41: + yy44: yych = *++cursor; switch (yych) { case 'l': - goto yy67; + goto yy73; default: goto yy17; } - yy42: + yy45: yych = *++cursor; switch (yych) { case 'p': - goto yy69; + goto yy75; default: goto yy17; } - yy43: + yy46: yych = *++cursor; switch (yych) { case 'i': - goto yy71; + goto yy77; default: goto yy17; } - yy44: + yy47: yych = *++cursor; switch (yych) { case 's': - goto yy72; + goto yy78; default: goto yy17; } - yy45: + yy48: yych = *++cursor; switch (yych) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': case 'a': - goto yy73; + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': case 't': - goto yy74; + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + goto yy16; + default: + goto yy49; + } + yy49: +#line 67 "lexer.re" + { + ts.push_token( + Token(Token::Integer, lineno, token_start + 1, cursor)); + token_start = cursor; + + continue; + } +#line 700 "lexer.cpp" + yy50: + ++cursor; + if (limit <= cursor) + return true; + yych = *cursor; + switch (yych) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + goto yy50; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + goto yy16; + default: + goto yy49; + } + yy52: + yych = *++cursor; + switch (yych) + { + case 'a': + goto yy79; + case 't': + goto yy80; default: goto yy17; } - yy46: + yy53: yych = *++cursor; switch (yych) { case 'b': - goto yy76; + goto yy82; default: goto yy17; } - yy47: + yy54: ++cursor; if (limit <= cursor) return true; @@ -622,23 +940,20 @@ bool Lexer::tokenize(TokenStream& ts) case 'd': case 'e': case 'f': - goto yy47; + goto yy54; default: - goto yy49; + goto yy56; } - yy49: -#line 66 "lexer.re" + yy56: +#line 83 "lexer.re" { - ts.push_token(Token(Token::XInteger, lineno, - - token_start, cursor)); - + ts.push_token(Token(Token::XInteger, lineno, token_start, cursor)); token_start = cursor; continue; } -#line 512 "lexer.cpp" - yy50: +#line 822 "lexer.cpp" + yy57: yych = *++cursor; switch (yych) { @@ -707,46 +1022,36 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy51; + goto yy58; } - yy51: -#line 120 "lexer.re" + yy58: +#line 137 "lexer.re" { ts.push_token(Token(Token::Add, lineno)); - token_start = cursor; continue; } -#line 589 "lexer.cpp" - yy52: - yych = *++cursor; - switch (yych) - { - case 'o': - goto yy78; - default: - goto yy17; - } - yy53: +#line 899 "lexer.cpp" + yy59: yych = *++cursor; switch (yych) { case 'l': - goto yy79; + goto yy84; default: goto yy17; } - yy54: + yy60: yych = *++cursor; switch (yych) { case 's': - goto yy81; + goto yy86; default: goto yy17; } - yy55: + yy61: yych = *++cursor; switch (yych) { @@ -815,19 +1120,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy56; + goto yy62; } - yy56: -#line 141 "lexer.re" + yy62: +#line 158 "lexer.re" { ts.push_token(Token(Token::Div, lineno)); - token_start = cursor; continue; } -#line 684 "lexer.cpp" - yy57: +#line 988 "lexer.cpp" + yy63: yych = *++cursor; switch (yych) { @@ -896,19 +1200,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy58; + goto yy64; } - yy58: -#line 99 "lexer.re" + yy64: +#line 116 "lexer.re" { ts.push_token(Token(Token::Dup, lineno)); - token_start = cursor; continue; } -#line 761 "lexer.cpp" - yy59: +#line 1065 "lexer.cpp" + yy65: yych = *++cursor; switch (yych) { @@ -975,32 +1278,31 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; case 'f': - goto yy82; + goto yy87; case 't': - goto yy84; + goto yy89; default: - goto yy60; + goto yy66; } - yy60: -#line 169 "lexer.re" + yy66: +#line 186 "lexer.re" { ts.push_token(Token(Token::Jump, lineno)); - token_start = cursor; continue; } -#line 838 "lexer.cpp" - yy61: +#line 1142 "lexer.cpp" + yy67: yych = *++cursor; switch (yych) { case 'e': - goto yy86; + goto yy91; default: goto yy17; } - yy62: + yy68: yych = *++cursor; switch (yych) { @@ -1069,28 +1371,27 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy63; + goto yy69; } - yy63: -#line 196 "lexer.re" + yy69: +#line 213 "lexer.re" { ts.push_token(Token(Token::LessEq, lineno)); - token_start = cursor; continue; } -#line 921 "lexer.cpp" - yy64: +#line 1225 "lexer.cpp" + yy70: yych = *++cursor; switch (yych) { case 's': - goto yy87; + goto yy92; default: goto yy17; } - yy65: + yy71: yych = *++cursor; switch (yych) { @@ -1159,19 +1460,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy66; + goto yy72; } - yy66: -#line 148 "lexer.re" + yy72: +#line 165 "lexer.re" { ts.push_token(Token(Token::Mod, lineno)); - token_start = cursor; continue; } -#line 1004 "lexer.cpp" - yy67: +#line 1308 "lexer.cpp" + yy73: yych = *++cursor; switch (yych) { @@ -1240,19 +1540,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy68; + goto yy74; } - yy68: -#line 134 "lexer.re" + yy74: +#line 151 "lexer.re" { ts.push_token(Token(Token::Mul, lineno)); - token_start = cursor; continue; } -#line 1081 "lexer.cpp" - yy69: +#line 1385 "lexer.cpp" + yy75: yych = *++cursor; switch (yych) { @@ -1310,8 +1609,8 @@ bool Lexer::tokenize(TokenStream& ts) case 'o': case 'p': case 'q': - case 'r': case 's': + case 't': case 'u': case 'v': case 'w': @@ -1319,49 +1618,48 @@ bool Lexer::tokenize(TokenStream& ts) case 'y': case 'z': goto yy16; - case 't': - goto yy89; + case 'r': + goto yy94; default: - goto yy70; + goto yy76; } - yy70: -#line 86 "lexer.re" + yy76: +#line 103 "lexer.re" { ts.push_token(Token(Token::Pop, lineno)); - token_start = cursor; continue; } -#line 1158 "lexer.cpp" - yy71: +#line 1462 "lexer.cpp" + yy77: yych = *++cursor; switch (yych) { case 'n': - goto yy90; + goto yy96; default: goto yy17; } - yy72: + yy78: yych = *++cursor; switch (yych) { case 'h': - goto yy91; + goto yy97; default: goto yy17; } - yy73: + yy79: yych = *++cursor; switch (yych) { case 'd': - goto yy93; + goto yy99; default: goto yy17; } - yy74: + yy80: yych = *++cursor; switch (yych) { @@ -1430,19 +1728,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy75; + goto yy81; } - yy75: -#line 189 "lexer.re" + yy81: +#line 206 "lexer.re" { ts.push_token(Token(Token::Ret, lineno)); - token_start = cursor; continue; } -#line 1253 "lexer.cpp" - yy76: +#line 1557 "lexer.cpp" + yy82: yych = *++cursor; switch (yych) { @@ -1511,28 +1808,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy77; + goto yy83; } - yy77: -#line 127 "lexer.re" + yy83: +#line 144 "lexer.re" { ts.push_token(Token(Token::Sub, lineno)); - token_start = cursor; continue; } -#line 1330 "lexer.cpp" - yy78: - yych = *++cursor; - switch (yych) - { - case 'c': - goto yy95; - default: - goto yy17; - } - yy79: +#line 1634 "lexer.cpp" + yy84: yych = *++cursor; switch (yych) { @@ -1601,28 +1888,27 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy80; + goto yy85; } - yy80: -#line 182 "lexer.re" + yy85: +#line 199 "lexer.re" { ts.push_token(Token(Token::Call, lineno)); - token_start = cursor; continue; } -#line 1413 "lexer.cpp" - yy81: +#line 1711 "lexer.cpp" + yy86: yych = *++cursor; switch (yych) { case 't': - goto yy97; + goto yy101; default: goto yy17; } - yy82: + yy87: yych = *++cursor; switch (yych) { @@ -1691,19 +1977,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy83; + goto yy88; } - yy83: -#line 162 "lexer.re" + yy88: +#line 179 "lexer.re" { ts.push_token(Token(Token::JumpF, lineno)); - token_start = cursor; continue; } -#line 1496 "lexer.cpp" - yy84: +#line 1794 "lexer.cpp" + yy89: yych = *++cursor; switch (yych) { @@ -1772,28 +2057,27 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy85; + goto yy90; } - yy85: -#line 155 "lexer.re" + yy90: +#line 172 "lexer.re" { ts.push_token(Token(Token::JumpT, lineno)); - token_start = cursor; continue; } -#line 1573 "lexer.cpp" - yy86: +#line 1871 "lexer.cpp" + yy91: yych = *++cursor; switch (yych) { case 'l': - goto yy99; + goto yy103; default: goto yy17; } - yy87: + yy92: yych = *++cursor; switch (yych) { @@ -1862,37 +2146,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy88; + goto yy93; } - yy88: -#line 202 "lexer.re" + yy93: +#line 219 "lexer.re" { ts.push_token(Token(Token::Less, lineno)); - token_start = cursor; continue; } -#line 1656 "lexer.cpp" - yy89: - yych = *++cursor; - switch (yych) - { - case 'o': - goto yy101; - default: - goto yy17; - } - yy90: - yych = *++cursor; - switch (yych) - { - case 't': - goto yy103; - default: - goto yy17; - } - yy91: +#line 1954 "lexer.cpp" + yy94: yych = *++cursor; switch (yych) { @@ -1961,19 +2226,27 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy92; + goto yy95; } - yy92: -#line 74 "lexer.re" + yy95: +#line 109 "lexer.re" { - ts.push_token(Token(Token::Push, lineno)); - + ts.push_token(Token(Token::PopTo, lineno)); token_start = cursor; continue; } -#line 1745 "lexer.cpp" - yy93: +#line 2031 "lexer.cpp" + yy96: + yych = *++cursor; + switch (yych) + { + case 't': + goto yy105; + default: + goto yy17; + } + yy97: yych = *++cursor; switch (yych) { @@ -2031,7 +2304,6 @@ bool Lexer::tokenize(TokenStream& ts) case 'o': case 'p': case 'q': - case 'r': case 's': case 't': case 'u': @@ -2041,20 +2313,21 @@ bool Lexer::tokenize(TokenStream& ts) case 'y': case 'z': goto yy16; + case 'r': + goto yy107; default: - goto yy94; + goto yy98; } - yy94: -#line 106 "lexer.re" + yy98: +#line 97 "lexer.re" { - ts.push_token(Token(Token::Read, lineno)); - + ts.push_token(Token(Token::Push, lineno)); token_start = cursor; continue; } -#line 1822 "lexer.cpp" - yy95: +#line 2114 "lexer.cpp" + yy99: yych = *++cursor; switch (yych) { @@ -2123,19 +2396,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy96; + goto yy100; } - yy96: -#line 80 "lexer.re" + yy100: +#line 123 "lexer.re" { - ts.push_token(Token(Token::Alloc, lineno)); - + ts.push_token(Token(Token::Read, lineno)); token_start = cursor; continue; } -#line 1899 "lexer.cpp" - yy97: +#line 2191 "lexer.cpp" + yy101: yych = *++cursor; switch (yych) { @@ -2204,19 +2476,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy98; + goto yy102; } - yy98: -#line 175 "lexer.re" + yy102: +#line 192 "lexer.re" { ts.push_token(Token(Token::Const, lineno)); - token_start = cursor; continue; } -#line 1976 "lexer.cpp" - yy99: +#line 2268 "lexer.cpp" + yy103: yych = *++cursor; switch (yych) { @@ -2285,19 +2556,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy100; + goto yy104; } - yy100: -#line 209 "lexer.re" + yy104: +#line 226 "lexer.re" { ts.push_token(Token(Token::Label, lineno)); - token_start = cursor; continue; } -#line 2053 "lexer.cpp" - yy101: +#line 2345 "lexer.cpp" + yy105: yych = *++cursor; switch (yych) { @@ -2366,19 +2636,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy102; + goto yy106; } - yy102: -#line 92 "lexer.re" + yy106: +#line 130 "lexer.re" { - ts.push_token(Token(Token::PopTo, lineno)); - + ts.push_token(Token(Token::Print, lineno)); token_start = cursor; continue; } -#line 2130 "lexer.cpp" - yy103: +#line 2422 "lexer.cpp" + yy107: yych = *++cursor; switch (yych) { @@ -2447,20 +2716,19 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy104; + goto yy108; } - yy104: -#line 113 "lexer.re" + yy108: +#line 91 "lexer.re" { - ts.push_token(Token(Token::Print, lineno)); - + ts.push_token(Token(Token::PushFrom, lineno)); token_start = cursor; continue; } -#line 2207 "lexer.cpp" +#line 2499 "lexer.cpp" } -#line 247 "lexer.re" +#line 264 "lexer.re" } return true; } diff --git a/spasm/src/asm/lexer.re b/spasm/src/asm/lexer.re index 298e340..c182653 100644 --- a/spasm/src/asm/lexer.re +++ b/spasm/src/asm/lexer.re @@ -52,6 +52,7 @@ DIGIT = [0-9] ; XDIGIT = [0-9a-fA-F] ; INTEGER = "-"? "0" | ([1-9] DIGIT*) ; +NONNEGATIVE = "0" | ([1-9] DIGIT*) ; XINTEGER = "0" [xX] XDIGIT+ ; IDENTIFIER = [a-zA-Z_] [0-9a-zA-Z_]* ; @@ -63,6 +64,22 @@ INTEGER { continue; } +"r" NONNEGATIVE { + ts.push_token (Token (Token::Integer, lineno, + token_start + 1, cursor)); + token_start = cursor; + + continue; + } +"a" NONNEGATIVE { + Token t(Token::Integer, lineno, + token_start + 1, cursor); + t.set_int(-t.value_int()); + ts.push_token(t); + token_start = cursor; + continue; + } + XINTEGER { ts.push_token (Token (Token::XInteger, lineno, token_start, cursor)); @@ -71,14 +88,14 @@ XINTEGER { continue; } -"push" { - ts.push_token (Token (Token::Push, lineno)); +"pushr" { + ts.push_token (Token (Token::PushFrom, lineno)); token_start = cursor; continue; } -"alloc" { - ts.push_token (Token (Token::Alloc, lineno)); +"push" { + ts.push_token (Token (Token::Push, lineno)); token_start = cursor; continue; @@ -89,7 +106,7 @@ XINTEGER { continue; } -"popto" { +"popr" { ts.push_token (Token (Token::PopTo, lineno)); token_start = cursor; diff --git a/spasm/src/asm/token.hpp b/spasm/src/asm/token.hpp index a763196..364b315 100644 --- a/spasm/src/asm/token.hpp +++ b/spasm/src/asm/token.hpp @@ -3,34 +3,6 @@ #include <string> -#define TOKENS \ - TOK(Halt) \ - TOK(Dup) \ - TOK(Pop) \ - TOK(PopTo) \ - TOK(Push) \ - TOK(Alloc) \ - TOK(Print) \ - TOK(Read) \ - TOK(Call) \ - TOK(Ret) \ - TOK(Jump) \ - TOK(JumpT) \ - TOK(JumpF) \ - TOK(Const) \ - TOK(Add) \ - TOK(Sub) \ - TOK(Mul) \ - TOK(Div) \ - TOK(Mod) \ - TOK(Less) \ - TOK(LessEq) \ - TOK(Label) \ - TOK(Ident) \ - TOK(Integer) \ - TOK(XInteger) \ - TOK(EndInput) - namespace SpasmImpl { namespace ASM @@ -42,38 +14,38 @@ class Token public: enum Token_type { - _NoArgBegin, - Halt = _NoArgBegin, - Dup, - Pop, - _OneArgBegin, - PopTo = _OneArgBegin, - Push, - Alloc, - Print, - Read, - Call, - Ret, - Jump, - _TwoArgBegin, - JumpT = _TwoArgBegin, - JumpF, - Const, - _ThreeArgBegin, - Add = _ThreeArgBegin, - Sub, - Mul, - Div, - Mod, - Less, - LessEq, - _NotOpCodeBegin, - Label = _NotOpCodeBegin, - Ident, - //Register, - Integer, - XInteger, - EndInput, + _NoArgBegin, + Halt = _NoArgBegin, + Dup, + Pop, + _OneArgBegin, + PopTo = _OneArgBegin, + PushFrom, + Push, + Print, + Read, + Call, + Ret, + Jump, + _TwoArgBegin, + JumpT = _TwoArgBegin, + JumpF, + Const, + _ThreeArgBegin, + Add = _ThreeArgBegin, + Sub, + Mul, + Div, + Mod, + Less, + LessEq, + _NotOpCodeBegin, + Label = _NotOpCodeBegin, + Ident, + // Register, + Integer, + XInteger, + EndInput, NotUsed }; @@ -86,6 +58,7 @@ class Token size_t lineno() const; int value_int() const; + void set_int(int v) { _value_int = v; } const std::string& value_str() const; diff --git a/spasm/src/spasm.cpp b/spasm/src/spasm.cpp index d06552d..8e5e36d 100644 --- a/spasm/src/spasm.cpp +++ b/spasm/src/spasm.cpp @@ -55,23 +55,30 @@ Spasm::RunResult Spasm::run() dup(); break; case OpCodes::Pop: - pop(); + { + const auto count = PC_t(read_reg(size)); + assert(m_SP - count >= m_FP); + m_SP -= count; break; + } case OpCodes::PopTo: + { + const auto arg0 = read_reg(size); + popto(arg0); break; - case OpCodes::Push: + } + case OpCodes::PushFrom: { const auto arg0 = read_reg(size); push(arg0); break; } - case OpCodes::Alloc: + case OpCodes::Push: { const auto count = PC_t(read_reg(size)); - for (PC_t i = 0; i < count; ++i) - { - push_data(0); - } + assert(m_SP + count <= &data_stack[data_stack.size() - 1]); + std::fill(m_SP, m_SP + count, 0); + m_SP += count; break; } case OpCodes::Print: @@ -199,12 +206,9 @@ void Spasm::push(reg_t reg) push_data(get_local(reg)); } -/*! -** Pops a data_t object from the data stack. -*/ -void Spasm::pop() +void Spasm::popto(reg_t reg) { - --m_SP; + m_FP[reg] = *(--m_SP); } /*! diff --git a/spasm/src/spasm.hpp b/spasm/src/spasm.hpp index 85b2e8d..01015d3 100644 --- a/spasm/src/spasm.hpp +++ b/spasm/src/spasm.hpp @@ -1,14 +1,14 @@ -#ifndef SPASM_HPP -#define SPASM_HPP - -#include "spasm_impl.hpp" - -namespace Spasm -{ -using SpasmImpl::byte; -using SpasmImpl::PC_t; -using SpasmImpl::Spasm; -using SpasmImpl::OpCodes; -} // namespace Spasm - -#endif // #ifndef SPASM_HPP +#ifndef SPASM_HPP
+#define SPASM_HPP
+
+#include "spasm_impl.hpp"
+
+namespace Spasm
+{
+using SpasmImpl::byte;
+using SpasmImpl::OpCodes;
+using SpasmImpl::PC_t;
+using SpasmImpl::Spasm;
+} // namespace Spasm
+
+#endif // #ifndef SPASM_HPP
diff --git a/spasm/src/spasm_impl.hpp b/spasm/src/spasm_impl.hpp index 75fb4c4..7c2bd38 100644 --- a/spasm/src/spasm_impl.hpp +++ b/spasm/src/spasm_impl.hpp @@ -13,8 +13,8 @@ enum OpCodes : char Dup, Pop, PopTo, + PushFrom, Push, - Alloc, Print, Read, Call, @@ -45,14 +45,15 @@ class Spasm public: Spasm(); void Initialize(PC_t, - const byte*, - std::istream& = std::cin, - std::ostream& = std::cout); + const byte*, + std::istream& = std::cin, + std::ostream& = std::cout); ~Spasm(); Spasm(const Spasm&) = delete; Spasm& operator=(const Spasm&) = delete; - enum RunResult { + enum RunResult + { Success, Exception, NotImplemented, @@ -77,7 +78,8 @@ class Spasm //! Frame pointer - the start of the stack for the current function data_t* m_FP = nullptr; - struct Frame { + struct Frame + { PC_t ReturnAddress; PC_t FramePointer; PC_t StackPointer; @@ -94,8 +96,7 @@ class Spasm std::ostream* ostr; void push(reg_t reg); - void pop(reg_t reg); - void pop(); + void popto(reg_t reg); void dup(); void print(reg_t reg); |
