diff options
| Commit | c32eda4e697803824e79878c74d541b81fbd04d8 (patch) | |
|---|---|---|
| Author | 2018-11-15 11:35:44 +0200 | |
| Committer | 2018-11-15 11:35:44 +0200 | |
| Files | ace7bdc0df3791b6db8878d52ba98cb368e180b8 /spasm | |
| 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
16 files changed, 1021 insertions, 442 deletions
| -rw-r--r-- | spasm/solution/genie.lua | 15 | ||||
| -rw-r--r-- | spasm/solution/spasm.make | 44 | ||||
| -rw-r--r-- | spasm/solution/spasm.vcxproj | 19 | ||||
| -rw-r--r-- | spasm/solution/spasm.vcxproj.filters | 18 | ||||
| -rw-r--r-- | spasm/solution/spasm_lib.make | 196 | ||||
| -rw-r--r-- | spasm/solution/spasm_lib.vcxproj | 131 | ||||
| -rw-r--r-- | spasm/solution/spasm_lib.vcxproj.filters | 31 | ||||
| -rw-r--r-- | spasm/solution/sprt.vcxproj | 2 | ||||
| -rw-r--r-- | spasm/solution/sprun.vcxproj | 2 | ||||
| -rw-r--r-- | spasm/src/asm/bytecode.hpp | 4 | ||||
| -rw-r--r-- | spasm/src/asm/lexer.cpp | 808 | ||||
| -rw-r--r-- | spasm/src/asm/lexer.re | 27 | ||||
| -rw-r--r-- | spasm/src/asm/token.hpp | 93 | ||||
| -rw-r--r-- | spasm/src/spasm.cpp | 28 | ||||
| -rw-r--r-- | spasm/src/spasm.hpp | 28 | ||||
| -rw-r--r-- | spasm/src/spasm_impl.hpp | 17 |
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); |
