1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-07 16:27:15 +01:00

Untested update to the new plugin API.

Various other changes to the plugin as well.
This commit is contained in:
Sandu Liviu Catalin 2016-05-22 06:20:38 +03:00
parent ddb52677bd
commit f2361a27c3
167 changed files with 15520 additions and 60635 deletions

View File

@ -0,0 +1 @@
It's safe to delete this file

1
bin/linux32/placeholder Normal file
View File

@ -0,0 +1 @@
It's safe to delete this file

View File

@ -0,0 +1 @@
It's safe to delete this file

1
bin/linux64/placeholder Normal file
View File

@ -0,0 +1 @@
It's safe to delete this file

View File

@ -1 +1 @@
Keep me!
It's safe to delete this file

View File

@ -1,7 +1,29 @@
[Config]
[Squirrel]
StackSize=2048
ErrorHandling=true
EmptyInit=false
[Log]
ConsoleDebug=true
ConsoleUser=true
ConsoleSuccess=true
ConsoleInfo=true
ConsoleWarning=true
ConsoleError=true
ConsoleFatal=true
LogFileDebug=true
LogFileUser=true
LogFileSuccess=true
LogFileInfo=true
LogFileWarning=true
LogFileError=true
LogFileFatal=true
ConsoleTimestamp=false
LogFileTimestamp=true
#Filename=mymod.log
[Scripts]
Source=bootstrap.nut
[Options]
MyOption="Hello from config!"

1
bin/win32-d/placeholder Normal file
View File

@ -0,0 +1 @@
It's safe to delete this file

1
bin/win32/placeholder Normal file
View File

@ -0,0 +1 @@
It's safe to delete this file

1
bin/win64-d/placeholder Normal file
View File

@ -0,0 +1 @@
It's safe to delete this file

1
bin/win64/placeholder Normal file
View File

@ -0,0 +1 @@
It's safe to delete this file

View File

@ -1,177 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="LibTCC" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Win32 Debug Static">
<Option output="../bin/win32-d/tcc1" prefix_auto="1" extension_auto="1" />
<Option working_dir="" />
<Option object_output="../obj/win32-d/" />
<Option type="2" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Compiler>
<Add option="-m32" />
<Add option="-g" />
<Add option="-DDEBUG" />
<Add option="-D_WIN32" />
<Add option="-DTCC_TARGET_I386" />
</Compiler>
<Linker>
<Add option="-m32" />
</Linker>
</Target>
<Target title="Win32 Release Static">
<Option output="../bin/win32/tcc1" prefix_auto="1" extension_auto="1" />
<Option working_dir="" />
<Option object_output="../obj/win32/" />
<Option type="2" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Compiler>
<Add option="-O3" />
<Add option="-m32" />
<Add option="-DNDEBUG" />
<Add option="-D_WIN32" />
<Add option="-DTCC_TARGET_I386" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m32" />
</Linker>
</Target>
<Target title="Win64 Debug Static">
<Option output="../bin/win64-d/tcc1" prefix_auto="1" extension_auto="1" />
<Option working_dir="" />
<Option object_output="../obj/win32-d/" />
<Option type="2" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Compiler>
<Add option="-m64" />
<Add option="-g" />
<Add option="-DDEBUG" />
<Add option="-D_WIN32" />
<Add option="-DTCC_TARGET_X86_64" />
</Compiler>
<Linker>
<Add option="-m64" />
</Linker>
</Target>
<Target title="Win64 Release Static">
<Option output="../bin/win64/tcc1" prefix_auto="1" extension_auto="1" />
<Option working_dir="" />
<Option object_output="../obj/win32/" />
<Option type="2" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Compiler>
<Add option="-O3" />
<Add option="-m64" />
<Add option="-DNDEBUG" />
<Add option="-D_WIN32" />
<Add option="-DTCC_TARGET_X86_64" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m64" />
</Linker>
</Target>
<Target title="Linux32 Debug Static">
<Option output="../bin/linux32-d/tcc1" prefix_auto="1" extension_auto="1" />
<Option working_dir="" />
<Option object_output="../obj/win32-d/" />
<Option type="2" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Compiler>
<Add option="-m32" />
<Add option="-g" />
<Add option="-fPIC" />
<Add option="-DDEBUG" />
<Add option="-DTCC_TARGET_I386" />
</Compiler>
<Linker>
<Add option="-m32" />
</Linker>
</Target>
<Target title="Linux32 Release Static">
<Option output="../bin/linux32/tcc1" prefix_auto="1" extension_auto="1" />
<Option working_dir="" />
<Option object_output="../obj/win32/" />
<Option type="2" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Compiler>
<Add option="-O3" />
<Add option="-m32" />
<Add option="-fPIC" />
<Add option="-DNDEBUG" />
<Add option="-DTCC_TARGET_I386" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m32" />
</Linker>
</Target>
<Target title="Linux64 Debug Static">
<Option output="../bin/linux64-d/tcc1" prefix_auto="1" extension_auto="1" />
<Option working_dir="" />
<Option object_output="../obj/win32-d/" />
<Option type="2" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Compiler>
<Add option="-m64" />
<Add option="-g" />
<Add option="-fPIC" />
<Add option="-DDEBUG" />
<Add option="-DTCC_TARGET_X86_64" />
</Compiler>
<Linker>
<Add option="-m64" />
</Linker>
</Target>
<Target title="Linux64 Release Static">
<Option output="../bin/linux64/tcc1" prefix_auto="1" extension_auto="1" />
<Option working_dir="" />
<Option object_output="../obj/win32/" />
<Option type="2" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Compiler>
<Add option="-O3" />
<Add option="-m64" />
<Add option="-fPIC" />
<Add option="-DNDEBUG" />
<Add option="-DTCC_TARGET_X86_64" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m64" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wextra" />
<Add option="-Wall" />
<Add option="-Wno-unused-parameter" />
<Add option="-DONE_SOURCE" />
<Add option="-DCONFIG_TCC_STATIC" />
<Add directory="../include" />
<Add directory="../external/TCC" />
</Compiler>
<Unit filename="../external/TCC/lib/libtcc1.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -1,446 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Mod TCC" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Win32 Debug Dynamic">
<Option output="../bin/win32-d/mod_tcc32" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/win32-d/" />
<Option object_output="../obj/mingw32-d/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-m32" />
<Add option="-g" />
<Add option="-D_DEBUG" />
<Add option="-DTCC_TARGET_I386" />
<Add option="-DTCC_TARGET_PE" />
<Add directory="../config/mingw32" />
</Compiler>
<Linker>
<Add option="-m32" />
<Add directory="../lib/mingw32-d" />
</Linker>
<ExtraCommands>
<Add after='cmd /c copy /Y &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)..\bin\plugins\$(TARGET_OUTPUT_BASENAME).dll&quot;' />
</ExtraCommands>
</Target>
<Target title="Win32 Release Dynamic">
<Option output="../bin/win32/mod_tcc32" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/win32/" />
<Option object_output="../obj/mingw32/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O3" />
<Add option="-m32" />
<Add option="-DNDEBUG" />
<Add option="-DTCC_TARGET_I386" />
<Add option="-DTCC_TARGET_PE" />
<Add directory="../config/mingw32" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m32" />
<Add directory="../lib/mingw32" />
</Linker>
<ExtraCommands>
<Add after='cmd /c copy /Y &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)..\bin\plugins\$(TARGET_OUTPUT_BASENAME).dll&quot;' />
</ExtraCommands>
</Target>
<Target title="Win64 Debug Dynamic">
<Option output="../bin/win64-d/mod_tcc64" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/win64-d/" />
<Option object_output="../obj/mingw64-d/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-m64" />
<Add option="-g" />
<Add option="-D_DEBUG" />
<Add option="-D_SQ64" />
<Add option="-DTCC_TARGET_X86_64" />
<Add option="-DTCC_TARGET_PE" />
<Add directory="../config/mingw64" />
</Compiler>
<Linker>
<Add option="-m64" />
<Add directory="../lib/mingw64-d" />
</Linker>
<ExtraCommands>
<Add after='cmd /c copy /Y &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)..\bin\plugins\$(TARGET_OUTPUT_BASENAME).dll&quot;' />
</ExtraCommands>
</Target>
<Target title="Win64 Release Dynamic">
<Option output="../bin/win64/mod_tcc64" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/win64/" />
<Option object_output="../obj/mingw64/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O3" />
<Add option="-m64" />
<Add option="-DNDEBUG" />
<Add option="-D_SQ64" />
<Add option="-DTCC_TARGET_X86_64" />
<Add option="-DTCC_TARGET_PE" />
<Add directory="../config/mingw64" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m64" />
<Add directory="../lib/mingw64" />
</Linker>
<ExtraCommands>
<Add after='cmd /c copy /Y &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)..\bin\plugins\$(TARGET_OUTPUT_BASENAME).dll&quot;' />
</ExtraCommands>
</Target>
<Target title="Linux32 Debug Dynamic">
<Option output="../bin/linux32-d/mod_tcc32" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/linux32-d/" />
<Option object_output="../obj/gcc32-d/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-m32" />
<Add option="-g" />
<Add option="-fPIC" />
<Add option="-D_DEBUG" />
<Add option="-DTCC_TARGET_I386" />
<Add directory="../config/gcc32" />
</Compiler>
<Linker>
<Add option="-m32" />
<Add directory="../lib/gcc32-d" />
</Linker>
<ExtraCommands>
<Add after='/bin/cp -rf &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)../bin/plugins/$(TARGET_OUTPUT_BASENAME).so&quot;' />
</ExtraCommands>
</Target>
<Target title="Linux32 Release Dynamic">
<Option output="../bin/linux32/mod_tcc32" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/linux32/" />
<Option object_output="../obj/gcc32/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O3" />
<Add option="-m32" />
<Add option="-fPIC" />
<Add option="-DNDEBUG" />
<Add option="-DTCC_TARGET_I386" />
<Add directory="../config/gcc32" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m32" />
<Add directory="../lib/gcc32" />
</Linker>
<ExtraCommands>
<Add after='/bin/cp -rf &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)../bin/plugins/$(TARGET_OUTPUT_BASENAME).so&quot;' />
</ExtraCommands>
</Target>
<Target title="Linux64 Debug Dynamic">
<Option output="../bin/linux64-d/mod_tcc64" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/linux64-d/" />
<Option object_output="../obj/gcc64-d/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-m64" />
<Add option="-g" />
<Add option="-fPIC" />
<Add option="-D_DEBUG" />
<Add option="-D_SQ64" />
<Add option="-DTCC_TARGET_X86_64" />
<Add directory="../config/gcc64" />
</Compiler>
<Linker>
<Add option="-m64" />
<Add directory="../lib/gcc64-d" />
</Linker>
<ExtraCommands>
<Add after='/bin/cp -rf &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)../bin/plugins/$(TARGET_OUTPUT_BASENAME).so&quot;' />
</ExtraCommands>
</Target>
<Target title="Linux64 Release Dynamic">
<Option output="../bin/linux64/mod_tcc64" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/linux64/" />
<Option object_output="../obj/gcc64/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O3" />
<Add option="-m64" />
<Add option="-fPIC" />
<Add option="-DNDEBUG" />
<Add option="-D_SQ64" />
<Add option="-DTCC_TARGET_X86_64" />
<Add directory="../config/gcc64" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m64" />
<Add directory="../lib/gcc64" />
</Linker>
<ExtraCommands>
<Add after='/bin/cp -rf &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)../bin/plugins/$(TARGET_OUTPUT_BASENAME).so&quot;' />
</ExtraCommands>
</Target>
<Target title="Win32 Debug Standalone">
<Option output="../bin/win32-d/mod_tcc32" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/win32-d/" />
<Option object_output="../obj/mingw32-d/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-m32" />
<Add option="-g" />
<Add option="-static-libgcc" />
<Add option="-static-libstdc++" />
<Add option="-enable-static" />
<Add option="-D_DEBUG" />
<Add option="-DTCC_TARGET_I386" />
<Add option="-DTCC_TARGET_PE" />
<Add directory="../config/mingw32" />
</Compiler>
<Linker>
<Add option="-m32" />
<Add option="-static" />
<Add directory="../lib/mingw32-d" />
</Linker>
<ExtraCommands>
<Add after='cmd /c copy /Y &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)..\bin\plugins\$(TARGET_OUTPUT_BASENAME).dll&quot;' />
</ExtraCommands>
</Target>
<Target title="Win32 Release Standalone">
<Option output="../bin/win32/mod_tcc32" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/win32/" />
<Option object_output="../obj/mingw32/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O3" />
<Add option="-m32" />
<Add option="-static-libgcc" />
<Add option="-static-libstdc++" />
<Add option="-enable-static" />
<Add option="-DNDEBUG" />
<Add option="-DTCC_TARGET_I386" />
<Add option="-DTCC_TARGET_PE" />
<Add directory="../config/mingw32" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m32" />
<Add option="-static" />
<Add directory="../lib/mingw32" />
</Linker>
<ExtraCommands>
<Add after='cmd /c copy /Y &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)..\bin\plugins\$(TARGET_OUTPUT_BASENAME).dll&quot;' />
</ExtraCommands>
</Target>
<Target title="Win64 Debug Standalone">
<Option output="../bin/win64-d/mod_tcc64" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/win64-d/" />
<Option object_output="../obj/mingw64-d/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-m64" />
<Add option="-g" />
<Add option="-static-libgcc" />
<Add option="-static-libstdc++" />
<Add option="-enable-static" />
<Add option="-D_DEBUG" />
<Add option="-D_SQ64" />
<Add option="-DTCC_TARGET_X86_64" />
<Add option="-DTCC_TARGET_PE" />
<Add directory="../config/mingw64" />
</Compiler>
<Linker>
<Add option="-m64" />
<Add option="-static" />
<Add directory="../lib/mingw64-d" />
</Linker>
<ExtraCommands>
<Add after='cmd /c copy /Y &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)..\bin\plugins\$(TARGET_OUTPUT_BASENAME).dll&quot;' />
</ExtraCommands>
</Target>
<Target title="Win64 Release Standalone">
<Option output="../bin/win64/mod_tcc64" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/win64/" />
<Option object_output="../obj/mingw64/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O3" />
<Add option="-m64" />
<Add option="-static-libgcc" />
<Add option="-static-libstdc++" />
<Add option="-enable-static" />
<Add option="-DNDEBUG" />
<Add option="-D_SQ64" />
<Add option="-DTCC_TARGET_X86_64" />
<Add option="-DTCC_TARGET_PE" />
<Add directory="../config/mingw64" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m64" />
<Add option="-static" />
<Add directory="../lib/mingw64" />
</Linker>
<ExtraCommands>
<Add after='cmd /c copy /Y &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)..\bin\plugins\$(TARGET_OUTPUT_BASENAME).dll&quot;' />
</ExtraCommands>
</Target>
<Target title="Linux32 Debug Standalone">
<Option output="../bin/linux32-d/mod_tcc32" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/linux32-d/" />
<Option object_output="../obj/gcc32-d/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-m32" />
<Add option="-g" />
<Add option="-static-libgcc" />
<Add option="-static-libstdc++" />
<Add option="-enable-static" />
<Add option="-fPIC" />
<Add option="-D_DEBUG" />
<Add option="-DTCC_TARGET_I386" />
<Add directory="../config/gcc32" />
</Compiler>
<Linker>
<Add option="-m32" />
<Add option="-Bstatic" />
<Add directory="../lib/gcc32-d" />
</Linker>
<ExtraCommands>
<Add after='/bin/cp -rf &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)../bin/plugins/$(TARGET_OUTPUT_BASENAME).so&quot;' />
</ExtraCommands>
</Target>
<Target title="Linux32 Release Standalone">
<Option output="../bin/linux32/mod_tcc32" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/linux32/" />
<Option object_output="../obj/gcc32/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O3" />
<Add option="-m32" />
<Add option="-static-libgcc" />
<Add option="-static-libstdc++" />
<Add option="-enable-static" />
<Add option="-fPIC" />
<Add option="-DNDEBUG" />
<Add option="-DTCC_TARGET_I386" />
<Add directory="../config/gcc32" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m32" />
<Add option="-Bstatic" />
<Add directory="../lib/gcc32" />
</Linker>
<ExtraCommands>
<Add after='/bin/cp -rf &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)../bin/plugins/$(TARGET_OUTPUT_BASENAME).so&quot;' />
</ExtraCommands>
</Target>
<Target title="Linux64 Debug Standalone">
<Option output="../bin/linux64-d/mod_tcc64" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/linux64-d/" />
<Option object_output="../obj/gcc64-d/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-m64" />
<Add option="-g" />
<Add option="-static-libgcc" />
<Add option="-static-libstdc++" />
<Add option="-enable-static" />
<Add option="-fPIC" />
<Add option="-D_DEBUG" />
<Add option="-D_SQ64" />
<Add option="-DTCC_TARGET_X86_64" />
<Add directory="../config/gcc64" />
</Compiler>
<Linker>
<Add option="-m64" />
<Add option="-Bstatic" />
<Add directory="../lib/gcc64-d" />
</Linker>
<ExtraCommands>
<Add after='/bin/cp -rf &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)../bin/plugins/$(TARGET_OUTPUT_BASENAME).so&quot;' />
</ExtraCommands>
</Target>
<Target title="Linux64 Release Standalone">
<Option output="../bin/linux64/mod_tcc64" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/linux64/" />
<Option object_output="../obj/gcc64/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O3" />
<Add option="-m64" />
<Add option="-static-libgcc" />
<Add option="-static-libstdc++" />
<Add option="-enable-static" />
<Add option="-fPIC" />
<Add option="-DNDEBUG" />
<Add option="-D_SQ64" />
<Add option="-DTCC_TARGET_X86_64" />
<Add directory="../config/gcc64" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m64" />
<Add option="-Bstatic" />
<Add directory="../lib/gcc64" />
</Linker>
<ExtraCommands>
<Add after='/bin/cp -rf &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)../bin/plugins/$(TARGET_OUTPUT_BASENAME).so&quot;' />
</ExtraCommands>
</Target>
</Build>
<Compiler>
<Add option="-Wextra" />
<Add option="-Wall" />
<Add option="-std=c++14" />
<Add option="-DSQMOD_PLUGIN_API" />
<Add option="-DSCRAT_USE_EXCEPTIONS" />
<Add option="-DSCRAT_USE_CXX11_OPTIMIZATIONS" />
<Add option="-DONE_SOURCE" />
<Add option="-DCONFIG_TCC_STATIC" />
<Add directory="../modules/tcc" />
<Add directory="../shared" />
<Add directory="../include" />
<Add directory="../config/common" />
<Add directory="../external/TCC" />
</Compiler>
<Unit filename="../external/TCC/libtcc.c">
<Option compilerVar="CC" />
<Option compiler="gcc" use="1" buildCommand="$compiler -Wno-unused-parameter -Wno-unused-function -Wno-sign-compare -Wno-pointer-sign -Wno-missing-field-initializers -Wno-maybe-uninitialized -Wno-return-type -Wno-format $options $includes -c $file -o $object" />
</Unit>
<Unit filename="../modules/tcc/API.cpp" />
<Unit filename="../modules/tcc/Common.cpp" />
<Unit filename="../modules/tcc/Common.hpp" />
<Unit filename="../modules/tcc/Module.cpp" />
<Unit filename="../modules/tcc/Module.hpp" />
<Unit filename="../modules/tcc/State.cpp" />
<Unit filename="../modules/tcc/State.hpp" />
<Unit filename="../modules/tcc/Symbol.cpp" />
<Unit filename="../modules/tcc/Symbol.hpp" />
<Unit filename="../shared/SqMod.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -447,12 +447,13 @@
<Unit filename="../source/Constants.cpp" />
<Unit filename="../source/Core.cpp" />
<Unit filename="../source/Core.hpp" />
<Unit filename="../source/CoreEntity.cpp" />
<Unit filename="../source/CoreEvents.cpp" />
<Unit filename="../source/CoreUtils.cpp" />
<Unit filename="../source/Entity/Blip.cpp" />
<Unit filename="../source/Entity/Blip.hpp" />
<Unit filename="../source/Entity/Checkpoint.cpp" />
<Unit filename="../source/Entity/Checkpoint.hpp" />
<Unit filename="../source/Entity/Forcefield.cpp" />
<Unit filename="../source/Entity/Forcefield.hpp" />
<Unit filename="../source/Entity/Keybind.cpp" />
<Unit filename="../source/Entity/Keybind.hpp" />
<Unit filename="../source/Entity/Object.cpp" />
@ -461,10 +462,6 @@
<Unit filename="../source/Entity/Pickup.hpp" />
<Unit filename="../source/Entity/Player.cpp" />
<Unit filename="../source/Entity/Player.hpp" />
<Unit filename="../source/Entity/Sprite.cpp" />
<Unit filename="../source/Entity/Sprite.hpp" />
<Unit filename="../source/Entity/Textdraw.cpp" />
<Unit filename="../source/Entity/Textdraw.hpp" />
<Unit filename="../source/Entity/Vehicle.cpp" />
<Unit filename="../source/Entity/Vehicle.hpp" />
<Unit filename="../source/Exports.cpp" />
@ -482,6 +479,10 @@
<Unit filename="../source/Library/Chrono/Timestamp.hpp" />
<Unit filename="../source/Library/Crypt.cpp" />
<Unit filename="../source/Library/Crypt.hpp" />
<Unit filename="../source/Library/Crypt/AES.cpp" />
<Unit filename="../source/Library/Crypt/AES.hpp" />
<Unit filename="../source/Library/Crypt/Hash.cpp" />
<Unit filename="../source/Library/Crypt/Hash.hpp" />
<Unit filename="../source/Library/FileIO.cpp" />
<Unit filename="../source/Library/FileIO.hpp" />
<Unit filename="../source/Library/Format.cpp" />
@ -496,12 +497,18 @@
<Unit filename="../source/Library/Shared.hpp" />
<Unit filename="../source/Library/String.cpp" />
<Unit filename="../source/Library/String.hpp" />
<Unit filename="../source/Library/SysEnv.cpp" />
<Unit filename="../source/Library/SysEnv.hpp" />
<Unit filename="../source/Library/SysPath.cpp" />
<Unit filename="../source/Library/SysPath.hpp" />
<Unit filename="../source/Library/System.cpp" />
<Unit filename="../source/Library/System.hpp" />
<Unit filename="../source/Library/System/Environment.cpp" />
<Unit filename="../source/Library/System/Environment.hpp" />
<Unit filename="../source/Library/System/Path.cpp" />
<Unit filename="../source/Library/System/Path.hpp" />
<Unit filename="../source/Library/Utils.cpp" />
<Unit filename="../source/Library/Utils.hpp" />
<Unit filename="../source/Library/Utils/BufferInterpreter.cpp" />
<Unit filename="../source/Library/Utils/BufferInterpreter.hpp" />
<Unit filename="../source/Library/Utils/BufferWrapper.cpp" />
<Unit filename="../source/Library/Utils/BufferWrapper.hpp" />
<Unit filename="../source/Logger.cpp" />
<Unit filename="../source/Logger.hpp" />
<Unit filename="../source/Main.cpp" />
@ -517,8 +524,6 @@
<Unit filename="../source/Misc/Vehicle.hpp" />
<Unit filename="../source/Misc/Weapon.cpp" />
<Unit filename="../source/Misc/Weapon.hpp" />
<Unit filename="../source/Misc/World.cpp" />
<Unit filename="../source/Misc/World.hpp" />
<Unit filename="../source/Register.cpp" />
<Unit filename="../source/Routine.cpp" />
<Unit filename="../source/Routine.hpp" />

View File

@ -10,7 +10,6 @@
<Project filename="ModSQLite.cbp" />
<Project filename="ModMMDB.cbp" />
<Project filename="ModSample.cbp" />
<Project filename="ModTCC.cbp" />
<Project filename="LibTCC.cbp" />
<Project filename="ModMongoose.cbp" />
</Workspace>
</CodeBlocks_workspace_file>

504
external/TCC/COPYING vendored
View File

@ -1,504 +0,0 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

520
external/TCC/Changelog vendored
View File

@ -1,520 +0,0 @@
Version 0.9.27:
Licensing:
- TinyCC partly relicensed to MIT license
User interface:
- define __STDC_HOSTED__ (Michael Matz, Urs Janssen)
- added support for CPATH, C_INCLUDE_PATH and LD_LIBRARY_PATH (Andrew Aladjev
and Urs Janssen)
- added option -norunsrc to control argv[0] with tcc -run (James Lyon)
- improve --with-libgcc configure help (grischka)
- improve error message when memory is full (grischka)
- improve wording about compiler switches in documentation (Thomas Preud'homme)
- use GNU triplet prefix for cross compiler names (Thomas Preud'homme)
- ignore unknown linker optimization and as-needed option (Austin English)
Features:
- added ABI tests with native compiler using libtcc (James Lyon)
- added CMake build system with support for cross-compilation (James Lyon)
- improved variable length array support (James Lyon)
- add the possibility to use noname functions by ordinal (YX Hao)
- add a install-strip target to install tcc (Thomas Preud'homme)
- add runtime selection of float ABI on ARM (Thomas Preud'homme)
- add shared lib support on x86-64 (Michael Matz)
Platforms:
- support Debian GNU/kfreeBSD 64bit userspace (Thomas Preud'homme)
- fix GNU/Hurd interpreter path (Thomas Preud'homme)
- fix configure script for FreeBSD host (Thomas Preud'homme)
- make tcc -run work reliably on ARM by flushing caches (Thomas Preud'homme)
- many x86-64 ABI fixes incl. XMM register passing (James Lyon)
- improve compatibility with mingw's long double (James Lyon)
- avoid .stabstr section name to be truncated on win32 (Roy)
- add support for load/store of _Bool value (Thomas Preud'homme)
- detect instruction with incorrect operands on x86-64 (Thomas Preud'homme)
- improved relocations on ARM (Thomas Preud'homme)
- add va_* macro implementation for ARM (Thomas Preud'homme)
- define __ARM_EABI__, __ARMEL__ and __ARM_PCS_VFP (Thomas Preud'homme)
- provide a runtime library for ARM (Thomas Preud'homme)
- vastly improved support for ARM hard float calling convention
(Thomas Preud'homme, Daniel Glöckner)
- tcc can uses libtcc1 on ARM (Thomas Preud'homme)
- use __fixdfdi for all float to integer conversion (grischka)
- simplify startup code for unix platforms (grischka)
- improve ELF generated on ARM (Thomas Preud'homme)
- add support for thumb to ARM relocation (Thomas Preud'homme)
- fix globbing to match MSVC on Windows (Thomas Preud'homme)
- deprecate FPA and OABI support for ARM (Thomas Preud'homme)
- warn about softfloat not being supported on ARM (Thomas Preud'homme)
Bug fixes:
- many code clean up (Urs Janssen, grischka)
- fixes of other's patches (grischka, Ramsay Jones, Michael Matz)
- fix documentation about __TINYC__ (Urs Janssen)
- improve build of documentation (Urs Janssen)
- improve build instructions (Jov)
- switch from texi2html to makeinfo --html to build tcc-doc.html (James Lyon)
- improve out of tree build (James Lyon)
- improved passing and returning of struct (James Lyon)
- fix CMake build on i386 and x86-64 (James Lyon)
- fix i386 calling convention issue (James Lyon)
- fix error in Windows build of tests (James Lyon)
- fix x86-64 long double passing (James Lyon)
- fix crash with undefined struct (grischka)
- normalize slashes on win32 to always use backslashes (grischka)
- use runtime function for float to int conversion on i386 (grischka)
- improved documentation for include and lib lookup on win32 (grischka)
- detect redefinition of function (Thomas Preud'homme)
- detect the use of array of functions (Thomas Preud'homme)
- detect use of enumerator with wrong enumeration (Thomas Preud'homme)
- detect redefinition of enumerator or enumeration (Thomas Preud'homme)
- set the user-defined library search paths first (Vittorio Giovara)
- detect usage of incomplete types inside struct/union (Amine Najahi)
- various macro bug fixes (Joseph Poirier)
- avoid wrong trigger of assert on x86-64 platform (Thomas Preud'homme)
- fix NaN comparison (Thomas Preud'homme)
- use libtcc for static linking with runtime library (Thomas Preud'homme)
- fix negation of 0.0 and -0.0 values (Thomas Preud'homme)
- fix use of long long as if condition (Thomas Preud'homme)
- disable bound check if libgcc is used (Thomas Preud'homme)
- error out when casting to void (grischka)
- remove circular dependency in Makefile (grischka)
- stop preventing gcc to do strict aliasing (grischka)
- fix Windows build of tcc (grischka)
- build runtime library for arm cross compiler (Thomas Preud'homme)
- fix installation of arm cross-compiler (Thomas Preud'homme)
- add basic test for cross-compiler (Thomas Preud'homme)
- fix failure when generating PE on x86-64 (Archidemon)
- fix floating point unary minus and plus (Michael Matz)
- add more tests for signed zero float (Michael Matz)
- fix precision of double on x86-64 (Vincent Lefevre)
- fix bound checking of argv with -run switch (Kirill Smelkov)
- work around a wine cmd bug when building tcc on Windows (Austin English)
- reenable some bound check tests (grischka)
- boundtest.c lookup honors VPATH (grischka)
- diff compared to CC in test[123]b? are now errors (grischka)
- fix test3 on Windows (grischka)
- prevent gcc from building (non functional) libtcc.a (grischka)
- fix warning related to PE file generation on x86-64 (grischka)
- stop mixing ordinary and implicit rule in Makefile (Iavael)
- fix integer to double conversion on ARM (Thomas Preud'homme)
- fix parameter passing of structure < 4 bytes on ARM (Thomas Preud'homme)
- disable builtin_frame_address test on ARM due to gcc bug (Thomas Preud'homme)
- fix initialization of struct on ARM (Thomas Preud'homme)
- fix parameter passing of (unsigned) long long bitfield (Thomas Preud'homme)
- improve float to integer tests (Thomas Preud'homme)
- fix relocation of Thumb branch to ARM function (Thomas Preud'homme)
- fix char wrong compatibility with [un]signed char (Thomas Preud'homme)
- choose the code to compile based on target in libtcc1 (Thomas Preud'homme)
- fix various clang warnings (Thomas Preud'homme)
- don't hardcode tcc in Makefile for tests (Thomas Preud'homme)
- fix relocation of __bound_init bound checking code (Thomas Preud'homme)
- accept only one basic type for a given variable (Thomas Preud'homme)
- fix error when using va_* with tcc using libgcc (Thomas Preud'homme)
- support GOT32 and PLT32 reloc on the same symbol (Thomas Preud'homme)
- fix memory leak due to symbol attributes (mingodad)
- partially fix bound checking of argv and arge (Thomas Preud'homme)
- fix possible dereference when getting name of symbol (grischka)
- fix va_list type definition on x86-64 (Daniel Glöckner)
- reduce number of scan-build false positive (mingodad)
version 0.9.26:
User interface:
- -MD/-MF (automatically generate dependencies for make)
- -pthread option (same as -D_REENTRANT -lpthread) (Henry Kroll III)
- -m32/-m64 to re-exec cross compiler (Henry Kroll III)
- -Wl, Mimic all GNU -option forms supported by ld (Kirill Smelkov)
- new LIBTCCAPI tcc_set_options() (grischka)
Platforms:
- Many improvements for x86-64 target (Shinichiro Hamaji, Michael Matz, grischka)
- x86-64 assembler (Frederic Feret)
- Many improvements for ARM target (Daniel Glöckner, Thomas Preud'homme)
- Support WinCE PE ARM (Timo VJ Lahde)
- Support ARM hardfloat calling convention (Thomas Preud'homme)
- Support SELinux (Security-Enhanced Linux) (Henry Kroll III)
- Support Debian GNU/kFreeBSD kernels (Pierre Chifflier)
- Support GNU/Hurd kernels (Thomas Preud'homme)
- Support OSX (tcc -run only) (Milutin Jovanovic)
- Support multiarch configuration (Thomas Preud'homme)
- Support out-of-tree build (Akim Demaille)
Features:
- C99 variable length arrays (Thomas Preud'homme & Joe Soroka)
- Asm labels for variables and functions (Thomas Preud'homme)
- STT_GNU_IFUNC (Indirect functions as externals) (Thomas Preud'homme)
- More tests (tests2) (Milutin Jovanovic)
version 0.9.25:
- first support for x86-64 target (Shinichiro Hamaji)
- support µClibc
- split tcc.c into tcc.h libtcc.c tccpp.c tccgen.c tcc.c
- improved preprocess output with linenumbers and spaces preserved
- tcc_relocate now copies code into user buffer
- fix bitfields with non-int types and in unions
- improve ARM cross-compiling (Daniel Glöckner)
- link stabstr sections from multiple objects
- better (still limited) support for multiple TCCStates
version 0.9.24:
- added verbosity levels -v, -vv, -vvv
- Accept standard input as an inputstream (Hanzac Chen)
- Support c89 compilers other than gcc (Hanzac Chen)
- -soname linker option (Marc Andre Tanner)
- Just warn about unknown directives, ignore quotes in #error/#warning
- Define __STDC_VERSION__=199901L (477)
- Switch to newer tccpe.c (includes support for resources)
- Handle backslashes within #include/#error/#warning
- Import changesets (part 4) 428,457,460,467: defines for openbsd etc.
- Use _WIN32 for a windows hosted tcc and define it for the PE target,
otherwise define __unix / __linux (Detlef Riekenberg)
- Import changesets (part 3) 409,410: ARM EABI by Daniel Glöckner
- Some in-between fixes:
TCC -E no longer hangs with macro calls involving newlines.
(next_nomacro1 now advances the read-pointer with TOK_LINEFEED)
Global cast (int g_i = 1LL;) no longer crashes tcc.
(nocode_wanted is initially 1, and only 0 for gen_function)
On win32 now tcc.exe finds 'include' & 'lib' even if itself is in 'bin'.
(new function w32_tcc_lib_path removes 'bin' if detected)
Added quick build batch file for mingw (win32/build-tcc.bat)
Last added case label optimization (455) produced wrong code. Reverted.
- Import more changesets from Rob Landley's fork (part 2):
487: Handle long long constants in gen_opic() (Rob Landley)
484: Handle parentheses within __attribute__((...)) (Rob Landley)
480: Remove a goto in decl_initializer_alloc (Rob Landley)
475: Fix dereferences in inline assembly output (Joshua Phillips)
474: Cast ptrs to ints of different sizes correctly (Joshua Phillips)
473: Fix size of structs with empty array member (Joshua Phillips)
470: No warning for && and || with mixed pointers/integers (Rob Landley)
469: Fix symbol visibility problems in the linker (Vincent Pit)
468: Allow && and || involving pointer arguments (Rob Landley)
455: Optimize case labels with no code in between (Zdenek Pavlas)
450: Implement alloca for x86 (grischka)
415: Parse unicode escape sequences (Axel Liljencrantz)
407: Add a simple va_copy() in stdarg.h (Hasso Tepper)
400: Allow typedef names as symbols (Dave Dodge)
- Import some changesets from Rob Landley's fork (part 1):
462: Use LGPL with bcheck.c and il-gen.c
458: Fix global compound literals (in unary: case '&':) (Andrew Johnson)
456: Use return code from tcc_output_file in main() (Michael Somos)
442: Fix indirections with function pointers (***fn)() (grischka)
441: Fix LL left shift in libtcc1.c:__shldi3 (grischka)
440: Pass structures and function ptrs through ?: (grischka)
439: Keep rvalue in bit assignment (bit2 = bit1 = x) (grischka)
438: Degrade nonportable pointer assignment to warning (grischka)
437: Call 'saveregs()' before jumping with logical and/or/not (grischka)
435: Put local static variables into global memory (grischka)
432/434: Cast double and ptr to bool (grischka)
420: Zero pad x87 tenbyte long doubles (Felix Nawothnig)
417: Make 'sizeof' unsigned (Rob Landley)
397: Fix save_reg for longlongs (Daniel Glöckner)
396: Fix "invalid relocation entry" problem on ubuntu - (Bernhard Fischer)
- ignore AS_NEEDED ld command
- mark executable sections as executable when running in memory
- added support for win32 wchar_t (Filip Navara)
- segment override prefix support (Filip Navara)
- normalized slashes in paths (Filip Navara)
- windows style fastcall (Filip Navara)
- support for empty input register section in asm (Filip Navara)
- anonymous union/struct support (Filip Navara)
- fixed parsing of function parameters
- workaround for function pointers in conditional expressions (Dave Dodge)
- initial '-E' option support to use the C preprocessor alone
- discard type qualifiers when comparing function parameters (Dave Dodge)
- Bug fix: A long long value used as a test expression ignores the
upper 32 bits at runtime (Dave Dodge)
- fixed multiple concatenation of PPNUM tokens (initial patch by Dave Dodge)
- fixed multiple typedef specifiers handling
- fixed sign extension in some type conversions (Dave Dodge)
version 0.9.23:
- initial PE executable format for windows version (grischka)
- '#pragma pack' support (grischka)
- '#include_next' support (Bernhard Fischer)
- ignore '-pipe' option
- added -f[no-]leading-underscore
- preprocessor function macro parsing fix (grischka)
version 0.9.22:
- simple memory optimisations: kernel compilation is 30% faster
- linker symbol definitions fixes
- gcc 3.4 fixes
- fixed value stack full error
- 'packed' attribute support for variables and structure fields
- ignore 'const' and 'volatile' in function prototypes
- allow '_Bool' in bit fields
version 0.9.21:
- ARM target support (Daniel Glöckner)
- added '-funsigned-char, '-fsigned-char' and
'-Wimplicit-function-declaration'
- fixed assignment of const struct in struct
- line comment fix (reported by Bertram Felgenhauer)
- initial TMS320C67xx target support (TK)
- win32 configure
- regparm() attribute
- many built-in assembler fixes
- added '.org', '.fill' and '.previous' assembler directives
- '-fno-common' option
- '-Ttext' linker option
- section alignment fixes
- bit fields fixes
- do not generate code for unused inline functions
- '-oformat' linker option.
- added 'binary' output format.
version 0.9.20:
- added '-w' option
- added '.gnu.linkonce' ELF sections support
- fixed libc linking when running in memory (avoid 'stat' function
errors).
- extended '-run' option to be able to give several arguments to a C
script.
version 0.9.19:
- "alacarte" linking (Dave Long)
- simpler function call
- more strict type checks
- added 'const' and 'volatile' support and associated warnings
- added -Werror, -Wunsupported, -Wwrite-strings, -Wall.
- added __builtin_types_compatible_p() and __builtin_constant_p()
- chars support in assembler (Dave Long)
- .string, .globl, .section, .text, .data and .bss asm directive
support (Dave Long)
- man page generated from tcc-doc.texi
- fixed macro argument substitution
- fixed zero argument macro parsing
- changed license to LGPL
- added -rdynamic option support
version 0.9.18:
- header fix (time.h)
- fixed inline asm without operand case
- fixed 'default:' or 'case x:' with '}' after (incorrect C construct accepted
by gcc)
- added 'A' inline asm constraint.
version 0.9.17:
- PLT generation fix
- tcc doc fixes (Peter Lund)
- struct parse fix (signaled by Pedro A. Aranda Gutierrez)
- better _Bool lvalue support (signaled by Alex Measday)
- function parameters must be converted to pointers (signaled by Neil Brown)
- sanitized string and character constant parsing
- fixed comment parse (signaled by Damian M Gryski)
- fixed macro function bug (signaled by Philippe Ribet)
- added configure (initial patch by Mitchell N Charity)
- added '-run' and '-v' options (initial patch by vlindos)
- added real date report in __DATE__ and __TIME__ macros
version 0.9.16:
- added assembler language support
- added GCC inline asm() support
- fixed multiple variable definitions : uninitialized variables are
created as COMMON symbols.
- optimized macro processing
- added GCC statement expressions support
- added GCC local labels support
- fixed array declaration in old style function parameters
- support casts in static structure initializations
- added various __xxx[__] keywords for GCC compatibility
- ignore __extension__ GCC in an expression or in a type (still not perfect)
- added '? :' GCC extension support
version 0.9.15:
- compilation fixes for glibc 2.2, gcc 2.95.3 and gcc 3.2.
- FreeBSD compile fixes. Makefile patches still missing (Carl Drougge).
- fixed file type guessing if '.' is in the path.
- fixed tcc_compile_string()
- add a dummy page in ELF files to fix RX/RW accesses (pageexec at
freemail dot hu).
version 0.9.14:
- added #warning. error message if invalid preprocessing directive.
- added CType structure to ease typing (faster parse).
- suppressed secondary hash tables (faster parse).
- rewrote parser by optimizing common cases (faster parse).
- fixed signed long long comparisons.
- fixed 'int a(), b();' declaration case.
- fixed structure init without '{}'.
- correct alignment support in structures.
- empty structures support.
- gcc testsuite now supported.
- output only warning if implicit integer/pointer conversions.
- added static bitfield init.
version 0.9.13:
- correct preprocessing token pasting (## operator) in all cases (added
preprocessing number token).
- fixed long long register spill.
- fixed signed long long '>>'.
- removed memory leaks.
- better error handling : processing can continue on link errors. A
custom callback can be added to display error messages. Most
errors do not call exit() now.
- ignore -O, -W, -m and -f options
- added old style function declarations
- added GCC __alignof__ support.
- added GCC typeof support.
- added GCC computed gotos support.
- added stack backtrace in runtime error message. Improved runtime
error position display.
version 0.9.12:
- more fixes for || and && handling.
- improved '? :' type handling.
- fixed bound checking generation with structures
- force '#endif' to be in same file as matching '#if'
- #include file optimization with '#ifndef #endif' construct detection
- macro handling optimization
- added tcc_relocate() and tcc_get_symbol() in libtcc.
version 0.9.11:
- stdarg.h fix for double type (thanks to Philippe Ribet).
- correct white space characters and added MSDOS newline support.
- fixed invalid implicit function call type declaration.
- special macros such as __LINE__ are defined if tested with defined().
- fixed '!' operator with relocated address.
- added symbol + offset relocation (fixes some static variable initializers)
- '-l' option can be specified anywhere. '-c' option yields default
output name. added '-r' option for relocatable output.
- fixed '\nnn' octal parsing.
- fixed local extern variables declarations.
version 0.9.10:
- fixed lvalue type when saved in local stack.
- fixed '#include' syntax when using macros.
- fixed '#line' bug.
- removed size limit on strings. Unified string constants handling
with variable declarations.
- added correct support for '\xX' in wchar_t strings.
- added support for bound checking in generated executables
- fixed -I include order.
- fixed incorrect function displayed in runtime error.
version 0.9.9:
- fixed preprocessor expression parsing for #if/#elif.
- relocated debug info (.stab section).
- relocated bounds info (.bounds section).
- fixed cast to char of char constants ('\377' is -1 instead of 255)
- fixed implicit cast for unary plus.
- strings and '__func__' have now 'char[]' type instead of 'char *'
(fixes sizeof() return value).
- added __start_xxx and __stop_xxx symbols in linker.
- better DLL creation support (option -shared begins to work).
- ELF sections and hash tables are resized dynamically.
- executables and DLLs are stripped by default.
version 0.9.8:
- First version of full ELF linking support (generate objects, static
executable, dynamic executable, dynamic libraries). Dynamic library
support is not finished (need PIC support in compiler and some
patches in symbol exporting).
- First version of ELF loader for object (.o) and archive (.a) files.
- Support of simple GNU ld scripts (GROUP and FILE commands)
- Separated runtime library and bound check code from TCC (smaller
compiler core).
- fixed register reload in float compare.
- fixed implicit char/short to int casting.
- allow array type for address of ('&') operator.
- fixed unused || or && result.
- added GCC style variadic macro support.
- optimized bound checking code for array access.
- tcc includes are now in $(prefix)/lib/tcc/include.
- more command line options - more consistent handling of multiple
input files.
- added tcc man page (thanks to Cyril Bouthors).
- uClibc Makefile update
- converted documentation to texinfo format.
- added developper's guide in documentation.
version 0.9.7:
- added library API for easy dynamic compilation (see libtcc.h - first
draft).
- fixed long long register spill bug.
- fixed '? :' register spill bug.
version 0.9.6:
- added floating point constant propagation (fixes negative floating
point constants bug).
version 0.9.5:
- uClibc patches (submitted by Alfonso Martone).
- error reporting fix
- added CONFIG_TCC_BCHECK to get smaller code if needed.
version 0.9.4:
- windows port (currently cannot use -g, -b and dll functions).
- faster and simpler I/O handling.
- '-D' option works in all cases.
- preprocessor fixes (#elif and empty macro args)
- floating point fixes
- first code for CIL generation (does not work yet)
version 0.9.3:
- better and smaller code generator.
- full ISOC99 64 bit 'long long' support.
- full 32 bit 'float', 64 bit 'double' and 96 bit 'long double' support.
- added '-U' option.
- added assembly sections support.
- even faster startup time by mmaping sections instead of mallocing them.
- added GNUC __attribute__ keyword support (currently supports
'section' and 'aligned' attributes).
- added ELF file output (only usable for debugging now)
- added debug symbol generation (STAB format).
- added integrated runtime error analysis ('-g' option: print clear
run time error messages instead of "Segmentation fault").
- added first version of tiny memory and bound checker ('-b' option).
version 0.9.2:
- even faster parsing.
- various syntax parsing fixes.
- fixed external relocation handling for variables or functions pointers.
- better function pointers type handling.
- can compile multiple files (-i option).
- ANSI C bit fields are supported.
- beginning of float/double/long double support.
- beginning of long long support.
version 0.9.1:
- full ISOC99 initializers handling.
- compound literals.
- structures handle in assignments and as function param or return value.
- wide chars and strings.
- macro bug fix
version 0.9:
- initial version.

104
external/TCC/README vendored
View File

@ -1,104 +0,0 @@
Tiny C Compiler - C Scripting Everywhere - The Smallest ANSI C compiler
-----------------------------------------------------------------------
Features:
--------
- SMALL! You can compile and execute C code everywhere, for example on
rescue disks.
- FAST! tcc generates optimized x86 code. No byte code
overhead. Compile, assemble and link about 7 times faster than 'gcc
-O0'.
- UNLIMITED! Any C dynamic library can be used directly. TCC is
heading torward full ISOC99 compliance. TCC can of course compile
itself.
- SAFE! tcc includes an optional memory and bound checker. Bound
checked code can be mixed freely with standard code.
- Compile and execute C source directly. No linking or assembly
necessary. Full C preprocessor included.
- C script supported : just add '#!/usr/local/bin/tcc -run' at the first
line of your C source, and execute it directly from the command
line.
Documentation:
-------------
1) Installation on a i386/x86_64/arm Linux/OSX/FreeBSD host (for Windows read tcc-win32.txt)
Note: For OSX and FreeBSD, gmake should be used instead of make.
./configure
make
make test
make install
Alternatively, out-of-tree builds are supported: you may use different
directories to hold build objects, kept separate from your source tree:
mkdir _build
cd _build
../configure
make
make test
make install
Texi2html must be installed to compile the doc.
By default, tcc is installed in /usr/local/bin.
./configure --help shows configuration options.
2) Introduction
We assume here that you know ANSI C. Look at the example ex1.c to know
what the programs look like.
The include file <tcclib.h> can be used if you want a small basic libc
include support (especially useful for floppy disks). Of course, you
can also use standard headers, although they are slower to compile.
You can begin your C script with '#!/usr/local/bin/tcc -run' on the first
line and set its execute bits (chmod a+x your_script). Then, you can
launch the C code as a shell or perl script :-) The command line
arguments are put in 'argc' and 'argv' of the main functions, as in
ANSI C.
3) Examples
ex1.c: simplest example (hello world). Can also be launched directly
as a script: './ex1.c'.
ex2.c: more complicated example: find a number with the four
operations given a list of numbers (benchmark).
ex3.c: compute fibonacci numbers (benchmark).
ex4.c: more complicated: X11 program. Very complicated test in fact
because standard headers are being used ! As for ex1.c, can also be launched
directly as a script: './ex4.c'.
ex5.c: 'hello world' with standard glibc headers.
tcc.c: TCC can of course compile itself. Used to check the code
generator.
tcctest.c: auto test for TCC which tests many subtle possible bugs. Used
when doing 'make test'.
4) Full Documentation
Please read tcc-doc.html to have all the features of TCC.
Additional information is available for the Windows port in tcc-win32.txt.
License:
-------
TCC is distributed under the GNU Lesser General Public License (see
COPYING file).
Fabrice Bellard.

View File

@ -1,59 +0,0 @@
Relicensing TinyCC
------------------
The authors listed below hereby confirm their agreement to relicense TinyCC
including their past contributions under the following terms:
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
Author (name) I agree (YES/NO) Files/Features (optional)
------------------------------------------------------------------------------
Adam Sampson YES makefiles
Daniel Glöckner NO arm-gen.c
Daniel Glöckner YES not arm-gen.c
Edmund Grimley Evans YES arm64
Fabrice Bellard YES original author
Frédéric Féret YES x86 64/16 bit asm
grischka YES tccpe.c
Henry Kroll YES
Joe Soroka YES
Kirill Smelkov YES
mingodad YES
Pip Cet YES
Shinichiro Hamaji YES x86_64-gen.c
Vincent Lefèvre YES
Thomas Preud'homme YES arm-gen.c
Timo VJ Lähde (Timppa) ? tiny_libmaker.c
TK ? tcccoff.c c67-gen.c
Urs Janssen YES
waddlesplash YES
------------------------------------------------------------------------------
Please add yourself to the list above (rsp. replace the question mark)
and (after fetching the latest version) commit to the "mob" branch with
commit message:
Relicensing TinyCC
Thanks.

110
external/TCC/TODO vendored
View File

@ -1,110 +0,0 @@
TODO list:
Bugs:
- fix macro substitution with nested definitions (ShangHongzhang)
- FPU st(0) is left unclean (kwisatz haderach). Incompatible with
optimized gcc/msc code
- constructors
- cast bug (Peter Wang)
- define incomplete type if defined several times (Peter Wang).
- test binutils/gcc compile
- tci patch + argument.
- see -lxxx bug (Michael Charity).
- see transparent union pb in /urs/include/sys/socket.h
- precise behaviour of typeof with arrays ? (__put_user macro)
but should suffice for most cases)
- handle '? x, y : z' in unsized variable initialization (',' is
considered incorrectly as separator in preparser)
- transform functions to function pointers in function parameters
(net/ipv4/ip_output.c)
- fix function pointer type display
- check lcc test suite -> fix bitfield binary operations
- check section alignment in C
- fix invalid cast in comparison 'if (v == (int8_t)v)'
- finish varargs.h support (gcc 3.2 testsuite issue)
- fix static functions declared inside block
- fix multiple unions init
- sizeof, alignof, typeof can still generate code in some cases.
- Fix the remaining libtcc memory leaks.
- make libtcc fully reentrant (except for the compilation stage itself).
- struct/union/enum definitions in nested scopes (see also Debian bug #770657)
- __STDC_IEC_559__: float f(void) { static float x = 0.0 / 0.0; return x; }
Portability:
- it is assumed that int is 32-bit and sizeof(int) == 4
- int is used when host or target size_t would make more sense
- TCC handles target floating-point (fp) values using the host's fp
arithmetic, which is simple and fast but may lead to exceptions
and inaccuracy and wrong representations when cross-compiling
Linking:
- static linking does not work
- with "-run" and libtcc, no PLT is used, so branches may be out of
range and relocations may fail; as a result libtest fails on arm64; see:
https://lists.gnu.org/archive/html/tinycc-devel/2015-03/msg00111.html
Bound checking:
- '-b' bug.
- fix bound exit on RedHat 7.3
- setjmp is not supported properly in bound checking.
- fix bound check code with '&' on local variables (currently done
only for local arrays).
- bound checking and float/long long/struct copy code. bound
checking and symbol + offset optimization
Missing features:
- disable-asm and disable-bcheck options
- __builtin_expect()
- improve '-E' option.
- atexit (Nigel Horne)
- packed attribute
- C99: add complex types (gcc 3.2 testsuite issue)
- postfix compound literals (see 20010124-1.c)
Optimizations:
- suppress specific anonymous symbol handling
- more parse optimizations (=even faster compilation)
- memory alloc optimizations (=even faster compilation)
- optimize VT_LOCAL + const
- better local variables handling (needed for other targets)
Not critical:
- C99: fix multiple compound literals inits in blocks (ISOC99
normative example - only relevant when using gotos! -> must add
boolean variable to tell if compound literal was already
initialized).
- add PowerPC or ARM code generator and improve codegen for RISC (need
to suppress VT_LOCAL and use a base register instead).
- interactive mode / integrated debugger
- fix preprocessor symbol redefinition
- add portable byte code generator and interpreter for other
unsupported architectures.
- C++: variable declaration in for, minimal 'class' support.
- win32: __intxx. use resolve for bchecked malloc et al.
check exception code (exception filter func).
- handle void (__attribute__() *ptr)()
- VLAs are implemented in a way that is not compatible with signals:
http://lists.gnu.org/archive/html/tinycc-devel/2015-11/msg00018.html
Fixed (probably):
- bug with defines:
#define spin_lock(lock) do { } while (0)
#define wq_spin_lock spin_lock
#define TEST() wq_spin_lock(a)
- typedefs can be structure fields
- see bugfixes.diff + improvement.diff from Daniel Glockner
- long long constant evaluation
- add alloca()
- gcc '-E' option.
- #include_next support for /usr/include/limits ?
- function pointers/lvalues in ? : (linux kernel net/core/dev.c)
- win32: add __stdcall, check GetModuleHandle for dlls.

View File

@ -1 +0,0 @@
0.9.26

2549
external/TCC/c67-gen.c vendored

File diff suppressed because it is too large Load Diff

446
external/TCC/coff.h vendored
View File

@ -1,446 +0,0 @@
/**************************************************************************/
/* COFF.H */
/* COFF data structures and related definitions used by the linker */
/**************************************************************************/
/*------------------------------------------------------------------------*/
/* COFF FILE HEADER */
/*------------------------------------------------------------------------*/
struct filehdr {
unsigned short f_magic; /* magic number */
unsigned short f_nscns; /* number of sections */
long f_timdat; /* time & date stamp */
long f_symptr; /* file pointer to symtab */
long f_nsyms; /* number of symtab entries */
unsigned short f_opthdr; /* sizeof(optional hdr) */
unsigned short f_flags; /* flags */
unsigned short f_TargetID; /* for C6x = 0x0099 */
};
/*------------------------------------------------------------------------*/
/* File header flags */
/*------------------------------------------------------------------------*/
#define F_RELFLG 0x01 /* relocation info stripped from file */
#define F_EXEC 0x02 /* file is executable (no unresolved refs) */
#define F_LNNO 0x04 /* line nunbers stripped from file */
#define F_LSYMS 0x08 /* local symbols stripped from file */
#define F_GSP10 0x10 /* 34010 version */
#define F_GSP20 0x20 /* 34020 version */
#define F_SWABD 0x40 /* bytes swabbed (in names) */
#define F_AR16WR 0x80 /* byte ordering of an AR16WR (PDP-11) */
#define F_LITTLE 0x100 /* byte ordering of an AR32WR (vax) */
#define F_BIG 0x200 /* byte ordering of an AR32W (3B, maxi) */
#define F_PATCH 0x400 /* contains "patch" list in optional header */
#define F_NODF 0x400
#define F_VERSION (F_GSP10 | F_GSP20)
#define F_BYTE_ORDER (F_LITTLE | F_BIG)
#define FILHDR struct filehdr
/* #define FILHSZ sizeof(FILHDR) */
#define FILHSZ 22 /* above rounds to align on 4 bytes which causes problems */
#define COFF_C67_MAGIC 0x00c2
/*------------------------------------------------------------------------*/
/* Macros to recognize magic numbers */
/*------------------------------------------------------------------------*/
#define ISMAGIC(x) (((unsigned short)(x))==(unsigned short)magic)
#define ISARCHIVE(x) ((((unsigned short)(x))==(unsigned short)ARTYPE))
#define BADMAGIC(x) (((unsigned short)(x) & 0x8080) && !ISMAGIC(x))
/*------------------------------------------------------------------------*/
/* OPTIONAL FILE HEADER */
/*------------------------------------------------------------------------*/
typedef struct aouthdr {
short magic; /* see magic.h */
short vstamp; /* version stamp */
long tsize; /* text size in bytes, padded to FW bdry*/
long dsize; /* initialized data " " */
long bsize; /* uninitialized data " " */
long entrypt; /* entry pt. */
long text_start; /* base of text used for this file */
long data_start; /* base of data used for this file */
} AOUTHDR;
#define AOUTSZ sizeof(AOUTHDR)
/*----------------------------------------------------------------------*/
/* When a UNIX aout header is to be built in the optional header, */
/* the following magic numbers can appear in that header: */
/* */
/* AOUT1MAGIC : default : readonly sharable text segment */
/* AOUT2MAGIC: : writable text segment */
/* PAGEMAGIC : : configured for paging */
/*----------------------------------------------------------------------*/
#define AOUT1MAGIC 0410
#define AOUT2MAGIC 0407
#define PAGEMAGIC 0413
/*------------------------------------------------------------------------*/
/* COMMON ARCHIVE FILE STRUCTURES */
/* */
/* ARCHIVE File Organization: */
/* _______________________________________________ */
/* |__________ARCHIVE_MAGIC_STRING_______________| */
/* |__________ARCHIVE_FILE_MEMBER_1______________| */
/* | | */
/* | Archive File Header "ar_hdr" | */
/* |.............................................| */
/* | Member Contents | */
/* | 1. External symbol directory | */
/* | 2. Text file | */
/* |_____________________________________________| */
/* |________ARCHIVE_FILE_MEMBER_2________________| */
/* | "ar_hdr" | */
/* |.............................................| */
/* | Member Contents (.o or text file) | */
/* |_____________________________________________| */
/* | . . . | */
/* | . . . | */
/* | . . . | */
/* |_____________________________________________| */
/* |________ARCHIVE_FILE_MEMBER_n________________| */
/* | "ar_hdr" | */
/* |.............................................| */
/* | Member Contents | */
/* |_____________________________________________| */
/* */
/*------------------------------------------------------------------------*/
#define COFF_ARMAG "!<arch>\n"
#define SARMAG 8
#define ARFMAG "`\n"
struct ar_hdr /* archive file member header - printable ascii */
{
char ar_name[16]; /* file member name - `/' terminated */
char ar_date[12]; /* file member date - decimal */
char ar_uid[6]; /* file member user id - decimal */
char ar_gid[6]; /* file member group id - decimal */
char ar_mode[8]; /* file member mode - octal */
char ar_size[10]; /* file member size - decimal */
char ar_fmag[2]; /* ARFMAG - string to end header */
};
/*------------------------------------------------------------------------*/
/* SECTION HEADER */
/*------------------------------------------------------------------------*/
struct scnhdr {
char s_name[8]; /* section name */
long s_paddr; /* physical address */
long s_vaddr; /* virtual address */
long s_size; /* section size */
long s_scnptr; /* file ptr to raw data for section */
long s_relptr; /* file ptr to relocation */
long s_lnnoptr; /* file ptr to line numbers */
unsigned int s_nreloc; /* number of relocation entries */
unsigned int s_nlnno; /* number of line number entries */
unsigned int s_flags; /* flags */
unsigned short s_reserved; /* reserved byte */
unsigned short s_page; /* memory page id */
};
#define SCNHDR struct scnhdr
#define SCNHSZ sizeof(SCNHDR)
/*------------------------------------------------------------------------*/
/* Define constants for names of "special" sections */
/*------------------------------------------------------------------------*/
/* #define _TEXT ".text" */
#define _DATA ".data"
#define _BSS ".bss"
#define _CINIT ".cinit"
#define _TV ".tv"
/*------------------------------------------------------------------------*/
/* The low 4 bits of s_flags is used as a section "type" */
/*------------------------------------------------------------------------*/
#define STYP_REG 0x00 /* "regular" : allocated, relocated, loaded */
#define STYP_DSECT 0x01 /* "dummy" : not allocated, relocated, not loaded */
#define STYP_NOLOAD 0x02 /* "noload" : allocated, relocated, not loaded */
#define STYP_GROUP 0x04 /* "grouped" : formed of input sections */
#define STYP_PAD 0x08 /* "padding" : not allocated, not relocated, loaded */
#define STYP_COPY 0x10 /* "copy" : used for C init tables -
not allocated, relocated,
loaded; reloc & lineno
entries processed normally */
#define STYP_TEXT 0x20 /* section contains text only */
#define STYP_DATA 0x40 /* section contains data only */
#define STYP_BSS 0x80 /* section contains bss only */
#define STYP_ALIGN 0x100 /* align flag passed by old version assemblers */
#define ALIGN_MASK 0x0F00 /* part of s_flags that is used for align vals */
#define ALIGNSIZE(x) (1 << ((x & ALIGN_MASK) >> 8))
/*------------------------------------------------------------------------*/
/* RELOCATION ENTRIES */
/*------------------------------------------------------------------------*/
struct reloc
{
long r_vaddr; /* (virtual) address of reference */
short r_symndx; /* index into symbol table */
unsigned short r_disp; /* additional bits for address calculation */
unsigned short r_type; /* relocation type */
};
#define RELOC struct reloc
#define RELSZ 10 /* sizeof(RELOC) */
/*--------------------------------------------------------------------------*/
/* define all relocation types */
/*--------------------------------------------------------------------------*/
#define R_ABS 0 /* absolute address - no relocation */
#define R_DIR16 01 /* UNUSED */
#define R_REL16 02 /* UNUSED */
#define R_DIR24 04 /* UNUSED */
#define R_REL24 05 /* 24 bits, direct */
#define R_DIR32 06 /* UNUSED */
#define R_RELBYTE 017 /* 8 bits, direct */
#define R_RELWORD 020 /* 16 bits, direct */
#define R_RELLONG 021 /* 32 bits, direct */
#define R_PCRBYTE 022 /* 8 bits, PC-relative */
#define R_PCRWORD 023 /* 16 bits, PC-relative */
#define R_PCRLONG 024 /* 32 bits, PC-relative */
#define R_OCRLONG 030 /* GSP: 32 bits, one's complement direct */
#define R_GSPPCR16 031 /* GSP: 16 bits, PC relative (in words) */
#define R_GSPOPR32 032 /* GSP: 32 bits, direct big-endian */
#define R_PARTLS16 040 /* Brahma: 16 bit offset of 24 bit address*/
#define R_PARTMS8 041 /* Brahma: 8 bit page of 24 bit address */
#define R_PARTLS7 050 /* DSP: 7 bit offset of 16 bit address */
#define R_PARTMS9 051 /* DSP: 9 bit page of 16 bit address */
#define R_REL13 052 /* DSP: 13 bits, direct */
/*------------------------------------------------------------------------*/
/* LINE NUMBER ENTRIES */
/*------------------------------------------------------------------------*/
struct lineno
{
union
{
long l_symndx ; /* sym. table index of function name
iff l_lnno == 0 */
long l_paddr ; /* (physical) address of line number */
} l_addr ;
unsigned short l_lnno ; /* line number */
};
#define LINENO struct lineno
#define LINESZ 6 /* sizeof(LINENO) */
/*------------------------------------------------------------------------*/
/* STORAGE CLASSES */
/*------------------------------------------------------------------------*/
#define C_EFCN -1 /* physical end of function */
#define C_NULL 0
#define C_AUTO 1 /* automatic variable */
#define C_EXT 2 /* external symbol */
#define C_STAT 3 /* static */
#define C_REG 4 /* register variable */
#define C_EXTDEF 5 /* external definition */
#define C_LABEL 6 /* label */
#define C_ULABEL 7 /* undefined label */
#define C_MOS 8 /* member of structure */
#define C_ARG 9 /* function argument */
#define C_STRTAG 10 /* structure tag */
#define C_MOU 11 /* member of union */
#define C_UNTAG 12 /* union tag */
#define C_TPDEF 13 /* type definition */
#define C_USTATIC 14 /* undefined static */
#define C_ENTAG 15 /* enumeration tag */
#define C_MOE 16 /* member of enumeration */
#define C_REGPARM 17 /* register parameter */
#define C_FIELD 18 /* bit field */
#define C_BLOCK 100 /* ".bb" or ".eb" */
#define C_FCN 101 /* ".bf" or ".ef" */
#define C_EOS 102 /* end of structure */
#define C_FILE 103 /* file name */
#define C_LINE 104 /* dummy sclass for line number entry */
#define C_ALIAS 105 /* duplicate tag */
#define C_HIDDEN 106 /* special storage class for external */
/* symbols in dmert public libraries */
/*------------------------------------------------------------------------*/
/* SYMBOL TABLE ENTRIES */
/*------------------------------------------------------------------------*/
#define SYMNMLEN 8 /* Number of characters in a symbol name */
#define FILNMLEN 14 /* Number of characters in a file name */
#define DIMNUM 4 /* Number of array dimensions in auxiliary entry */
struct syment
{
union
{
char _n_name[SYMNMLEN]; /* old COFF version */
struct
{
long _n_zeroes; /* new == 0 */
long _n_offset; /* offset into string table */
} _n_n;
char *_n_nptr[2]; /* allows for overlaying */
} _n;
long n_value; /* value of symbol */
short n_scnum; /* section number */
unsigned short n_type; /* type and derived type */
char n_sclass; /* storage class */
char n_numaux; /* number of aux. entries */
};
#define n_name _n._n_name
#define n_nptr _n._n_nptr[1]
#define n_zeroes _n._n_n._n_zeroes
#define n_offset _n._n_n._n_offset
/*------------------------------------------------------------------------*/
/* Relocatable symbols have a section number of the */
/* section in which they are defined. Otherwise, section */
/* numbers have the following meanings: */
/*------------------------------------------------------------------------*/
#define N_UNDEF 0 /* undefined symbol */
#define N_ABS -1 /* value of symbol is absolute */
#define N_DEBUG -2 /* special debugging symbol */
#define N_TV (unsigned short)-3 /* needs transfer vector (preload) */
#define P_TV (unsigned short)-4 /* needs transfer vector (postload) */
/*------------------------------------------------------------------------*/
/* The fundamental type of a symbol packed into the low */
/* 4 bits of the word. */
/*------------------------------------------------------------------------*/
#define _EF ".ef"
#define T_NULL 0 /* no type info */
#define T_ARG 1 /* function argument (only used by compiler) */
#define T_CHAR 2 /* character */
#define T_SHORT 3 /* short integer */
#define T_INT 4 /* integer */
#define T_LONG 5 /* long integer */
#define T_FLOAT 6 /* floating point */
#define T_DOUBLE 7 /* double word */
#define T_STRUCT 8 /* structure */
#define T_UNION 9 /* union */
#define T_ENUM 10 /* enumeration */
#define T_MOE 11 /* member of enumeration */
#define T_UCHAR 12 /* unsigned character */
#define T_USHORT 13 /* unsigned short */
#define T_UINT 14 /* unsigned integer */
#define T_ULONG 15 /* unsigned long */
/*------------------------------------------------------------------------*/
/* derived types are: */
/*------------------------------------------------------------------------*/
#define DT_NON 0 /* no derived type */
#define DT_PTR 1 /* pointer */
#define DT_FCN 2 /* function */
#define DT_ARY 3 /* array */
#define MKTYPE(basic, d1,d2,d3,d4,d5,d6) \
((basic) | ((d1) << 4) | ((d2) << 6) | ((d3) << 8) |\
((d4) << 10) | ((d5) << 12) | ((d6) << 14))
/*------------------------------------------------------------------------*/
/* type packing constants and macros */
/*------------------------------------------------------------------------*/
#define N_BTMASK_COFF 017
#define N_TMASK_COFF 060
#define N_TMASK1_COFF 0300
#define N_TMASK2_COFF 0360
#define N_BTSHFT_COFF 4
#define N_TSHIFT_COFF 2
#define BTYPE_COFF(x) ((x) & N_BTMASK_COFF)
#define ISINT(x) (((x) >= T_CHAR && (x) <= T_LONG) || \
((x) >= T_UCHAR && (x) <= T_ULONG) || (x) == T_ENUM)
#define ISFLT_COFF(x) ((x) == T_DOUBLE || (x) == T_FLOAT)
#define ISPTR_COFF(x) (((x) & N_TMASK_COFF) == (DT_PTR << N_BTSHFT_COFF))
#define ISFCN_COFF(x) (((x) & N_TMASK_COFF) == (DT_FCN << N_BTSHFT_COFF))
#define ISARY_COFF(x) (((x) & N_TMASK_COFF) == (DT_ARY << N_BTSHFT_COFF))
#define ISTAG_COFF(x) ((x)==C_STRTAG || (x)==C_UNTAG || (x)==C_ENTAG)
#define INCREF_COFF(x) ((((x)&~N_BTMASK_COFF)<<N_TSHIFT_COFF)|(DT_PTR<<N_BTSHFT_COFF)|(x&N_BTMASK_COFF))
#define DECREF_COFF(x) ((((x)>>N_TSHIFT_COFF)&~N_BTMASK_COFF)|((x)&N_BTMASK_COFF))
/*------------------------------------------------------------------------*/
/* AUXILIARY SYMBOL ENTRY */
/*------------------------------------------------------------------------*/
union auxent
{
struct
{
long x_tagndx; /* str, un, or enum tag indx */
union
{
struct
{
unsigned short x_lnno; /* declaration line number */
unsigned short x_size; /* str, union, array size */
} x_lnsz;
long x_fsize; /* size of function */
} x_misc;
union
{
struct /* if ISFCN, tag, or .bb */
{
long x_lnnoptr; /* ptr to fcn line # */
long x_endndx; /* entry ndx past block end */
} x_fcn;
struct /* if ISARY, up to 4 dimen. */
{
unsigned short x_dimen[DIMNUM];
} x_ary;
} x_fcnary;
unsigned short x_regcount; /* number of registers used by func */
} x_sym;
struct
{
char x_fname[FILNMLEN];
} x_file;
struct
{
long x_scnlen; /* section length */
unsigned short x_nreloc; /* number of relocation entries */
unsigned short x_nlinno; /* number of line numbers */
} x_scn;
};
#define SYMENT struct syment
#define SYMESZ 18 /* sizeof(SYMENT) */
#define AUXENT union auxent
#define AUXESZ 18 /* sizeof(AUXENT) */
/*------------------------------------------------------------------------*/
/* NAMES OF "SPECIAL" SYMBOLS */
/*------------------------------------------------------------------------*/
#define _STEXT ".text"
#define _ETEXT "etext"
#define _SDATA ".data"
#define _EDATA "edata"
#define _SBSS ".bss"
#define _END "end"
#define _CINITPTR "cinit"
/*--------------------------------------------------------------------------*/
/* ENTRY POINT SYMBOLS */
/*--------------------------------------------------------------------------*/
#define _START "_start"
#define _MAIN "_main"
/* _CSTART "_c_int00" (defined in params.h) */
#define _TVORIG "_tvorig"
#define _TORIGIN "_torigin"
#define _DORIGIN "_dorigin"
#define _SORIGIN "_sorigin"

View File

@ -1,7 +0,0 @@
#define CONFIG_TCCDIR "C:/Program Files (x86)/tcc"
#define TCC_VERSION "0.9.26"
/* #undef CONFIG_WIN32 */
/* #undef CONFIG_WIN64 */
/* #undef CONFIG_TCC_BCHECK */
/* #undef CONFIG_TCC_ASSERT */

3233
external/TCC/elf.h vendored

File diff suppressed because it is too large Load Diff

1502
external/TCC/i386-asm.c vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,500 +0,0 @@
DEF_ASM_OP0(clc, 0xf8) /* must be first OP0 */
DEF_ASM_OP0(cld, 0xfc)
DEF_ASM_OP0(cli, 0xfa)
DEF_ASM_OP0(clts, 0x0f06)
DEF_ASM_OP0(cmc, 0xf5)
DEF_ASM_OP0(lahf, 0x9f)
DEF_ASM_OP0(sahf, 0x9e)
DEF_ASM_OP0(pusha, 0x60)
DEF_ASM_OP0(popa, 0x61)
DEF_ASM_OP0(pushfl, 0x9c)
DEF_ASM_OP0(popfl, 0x9d)
DEF_ASM_OP0(pushf, 0x9c)
DEF_ASM_OP0(popf, 0x9d)
DEF_ASM_OP0(stc, 0xf9)
DEF_ASM_OP0(std, 0xfd)
DEF_ASM_OP0(sti, 0xfb)
DEF_ASM_OP0(aaa, 0x37)
DEF_ASM_OP0(aas, 0x3f)
DEF_ASM_OP0(daa, 0x27)
DEF_ASM_OP0(das, 0x2f)
DEF_ASM_OP0(aad, 0xd50a)
DEF_ASM_OP0(aam, 0xd40a)
DEF_ASM_OP0(cbw, 0x6698)
DEF_ASM_OP0(cwd, 0x6699)
DEF_ASM_OP0(cwde, 0x98)
DEF_ASM_OP0(cdq, 0x99)
DEF_ASM_OP0(cbtw, 0x6698)
DEF_ASM_OP0(cwtl, 0x98)
DEF_ASM_OP0(cwtd, 0x6699)
DEF_ASM_OP0(cltd, 0x99)
DEF_ASM_OP0(int3, 0xcc)
DEF_ASM_OP0(into, 0xce)
DEF_ASM_OP0(iret, 0xcf)
DEF_ASM_OP0(rsm, 0x0faa)
DEF_ASM_OP0(hlt, 0xf4)
DEF_ASM_OP0(nop, 0x90)
DEF_ASM_OP0(pause, 0xf390)
DEF_ASM_OP0(xlat, 0xd7)
/* strings */
ALT(DEF_ASM_OP0L(cmpsb, 0xa6, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(scmpb, 0xa6, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(insb, 0x6c, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(outsb, 0x6e, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(lodsb, 0xac, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(slodb, 0xac, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(movsb, 0xa4, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(smovb, 0xa4, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(scasb, 0xae, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(sscab, 0xae, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(stosb, 0xaa, 0, OPC_BWL))
ALT(DEF_ASM_OP0L(sstob, 0xaa, 0, OPC_BWL))
/* bits */
ALT(DEF_ASM_OP2(bsfw, 0x0fbc, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(bsrw, 0x0fbd, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(btw, 0x0fa3, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btw, 0x0fba, 4, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btsw, 0x0fab, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btsw, 0x0fba, 5, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btrw, 0x0fb3, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btrw, 0x0fba, 6, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btcw, 0x0fbb, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
/* prefixes */
DEF_ASM_OP0(wait, 0x9b)
DEF_ASM_OP0(fwait, 0x9b)
#ifdef I386_ASM_16
DEF_ASM_OP0(a32, 0x67)
DEF_ASM_OP0(o32, 0x66)
#else
DEF_ASM_OP0(aword, 0x67)
DEF_ASM_OP0(addr16, 0x67)
ALT(DEF_ASM_OP0(word, 0x66))
DEF_ASM_OP0(data16, 0x66)
#endif
DEF_ASM_OP0(lock, 0xf0)
DEF_ASM_OP0(rep, 0xf3)
DEF_ASM_OP0(repe, 0xf3)
DEF_ASM_OP0(repz, 0xf3)
DEF_ASM_OP0(repne, 0xf2)
DEF_ASM_OP0(repnz, 0xf2)
DEF_ASM_OP0(invd, 0x0f08)
DEF_ASM_OP0(wbinvd, 0x0f09)
DEF_ASM_OP0(cpuid, 0x0fa2)
DEF_ASM_OP0(wrmsr, 0x0f30)
DEF_ASM_OP0(rdtsc, 0x0f31)
DEF_ASM_OP0(rdmsr, 0x0f32)
DEF_ASM_OP0(rdpmc, 0x0f33)
DEF_ASM_OP0(ud2, 0x0f0b)
/* NOTE: we took the same order as gas opcode definition order */
ALT(DEF_ASM_OP2(movb, 0xa0, 0, OPC_BWL, OPT_ADDR, OPT_EAX))
ALT(DEF_ASM_OP2(movb, 0xa2, 0, OPC_BWL, OPT_EAX, OPT_ADDR))
ALT(DEF_ASM_OP2(movb, 0x88, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(movb, 0x8a, 0, OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
ALT(DEF_ASM_OP2(movb, 0xb0, 0, OPC_REG | OPC_BWL, OPT_IM, OPT_REG))
ALT(DEF_ASM_OP2(movb, 0xc6, 0, OPC_MODRM | OPC_BWL, OPT_IM, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP2(movw, 0x8c, 0, OPC_MODRM | OPC_WL, OPT_SEG, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(movw, 0x8e, 0, OPC_MODRM | OPC_WL, OPT_EA | OPT_REG, OPT_SEG))
ALT(DEF_ASM_OP2(movw, 0x0f20, 0, OPC_MODRM | OPC_WL, OPT_CR, OPT_REG32))
ALT(DEF_ASM_OP2(movw, 0x0f21, 0, OPC_MODRM | OPC_WL, OPT_DB, OPT_REG32))
ALT(DEF_ASM_OP2(movw, 0x0f24, 0, OPC_MODRM | OPC_WL, OPT_TR, OPT_REG32))
ALT(DEF_ASM_OP2(movw, 0x0f22, 0, OPC_MODRM | OPC_WL, OPT_REG32, OPT_CR))
ALT(DEF_ASM_OP2(movw, 0x0f23, 0, OPC_MODRM | OPC_WL, OPT_REG32, OPT_DB))
ALT(DEF_ASM_OP2(movw, 0x0f26, 0, OPC_MODRM | OPC_WL, OPT_REG32, OPT_TR))
ALT(DEF_ASM_OP2(movsbl, 0x0fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(movsbw, 0x0fbe, 0, OPC_MODRM | OPC_D16, OPT_REG8 | OPT_EA, OPT_REG16))
ALT(DEF_ASM_OP2(movswl, 0x0fbf, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(movzbw, 0x0fb6, 0, OPC_MODRM | OPC_WL, OPT_REG8 | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(movzwl, 0x0fb7, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP1(pushw, 0x50, 0, OPC_REG | OPC_WL, OPT_REGW))
ALT(DEF_ASM_OP1(pushw, 0xff, 6, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP1(pushw, 0x6a, 0, OPC_WL, OPT_IM8S))
ALT(DEF_ASM_OP1(pushw, 0x68, 0, OPC_WL, OPT_IM32))
ALT(DEF_ASM_OP1(pushw, 0x06, 0, OPC_WL, OPT_SEG))
ALT(DEF_ASM_OP1(popw, 0x58, 0, OPC_REG | OPC_WL, OPT_REGW))
ALT(DEF_ASM_OP1(popw, 0x8f, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP1(popw, 0x07, 0, OPC_WL, OPT_SEG))
ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WL, OPT_REG, OPT_EAX))
ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WL, OPT_EAX, OPT_REG))
ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
ALT(DEF_ASM_OP2(inb, 0xe4, 0, OPC_BWL, OPT_IM8, OPT_EAX))
ALT(DEF_ASM_OP1(inb, 0xe4, 0, OPC_BWL, OPT_IM8))
ALT(DEF_ASM_OP2(inb, 0xec, 0, OPC_BWL, OPT_DX, OPT_EAX))
ALT(DEF_ASM_OP1(inb, 0xec, 0, OPC_BWL, OPT_DX))
ALT(DEF_ASM_OP2(outb, 0xe6, 0, OPC_BWL, OPT_EAX, OPT_IM8))
ALT(DEF_ASM_OP1(outb, 0xe6, 0, OPC_BWL, OPT_IM8))
ALT(DEF_ASM_OP2(outb, 0xee, 0, OPC_BWL, OPT_EAX, OPT_DX))
ALT(DEF_ASM_OP1(outb, 0xee, 0, OPC_BWL, OPT_DX))
ALT(DEF_ASM_OP2(leaw, 0x8d, 0, OPC_MODRM | OPC_WL, OPT_EA, OPT_REG))
ALT(DEF_ASM_OP2(les, 0xc4, 0, OPC_MODRM, OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(lds, 0xc5, 0, OPC_MODRM, OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(lss, 0x0fb2, 0, OPC_MODRM, OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(lfs, 0x0fb4, 0, OPC_MODRM, OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(lgs, 0x0fb5, 0, OPC_MODRM, OPT_EA, OPT_REG32))
/* arith */
ALT(DEF_ASM_OP2(addb, 0x00, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG)) /* XXX: use D bit ? */
ALT(DEF_ASM_OP2(addb, 0x02, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
ALT(DEF_ASM_OP2(addb, 0x04, 0, OPC_ARITH | OPC_BWL, OPT_IM, OPT_EAX))
ALT(DEF_ASM_OP2(addb, 0x80, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_IM, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(addw, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WL, OPT_IM8S, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWL, OPT_EA | OPT_REG, OPT_REG))
ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(testb, 0xa8, 0, OPC_BWL, OPT_IM, OPT_EAX))
ALT(DEF_ASM_OP2(testb, 0xf6, 0, OPC_MODRM | OPC_BWL, OPT_IM, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP1(incw, 0x40, 0, OPC_REG | OPC_WL, OPT_REGW))
ALT(DEF_ASM_OP1(incb, 0xfe, 0, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP1(decw, 0x48, 0, OPC_REG | OPC_WL, OPT_REGW))
ALT(DEF_ASM_OP1(decb, 0xfe, 1, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP1(notb, 0xf6, 2, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP1(negb, 0xf6, 3, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP1(mulb, 0xf6, 4, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP1(imulb, 0xf6, 5, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP2(imulw, 0x0faf, 0, OPC_MODRM | OPC_WL, OPT_REG | OPT_EA, OPT_REG))
ALT(DEF_ASM_OP3(imulw, 0x6b, 0, OPC_MODRM | OPC_WL, OPT_IM8S, OPT_REGW | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(imulw, 0x6b, 0, OPC_MODRM | OPC_WL, OPT_IM8S, OPT_REGW))
ALT(DEF_ASM_OP3(imulw, 0x69, 0, OPC_MODRM | OPC_WL, OPT_IMW, OPT_REGW | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(imulw, 0x69, 0, OPC_MODRM | OPC_WL, OPT_IMW, OPT_REGW))
ALT(DEF_ASM_OP1(divb, 0xf6, 6, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP2(divb, 0xf6, 6, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA, OPT_EAX))
ALT(DEF_ASM_OP1(idivb, 0xf6, 7, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP2(idivb, 0xf6, 7, OPC_MODRM | OPC_BWL, OPT_REG | OPT_EA, OPT_EAX))
/* shifts */
ALT(DEF_ASM_OP2(rolb, 0xc0, 0, OPC_MODRM | OPC_BWL | OPC_SHIFT, OPT_IM8, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(rolb, 0xd2, 0, OPC_MODRM | OPC_BWL | OPC_SHIFT, OPT_CL, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP1(rolb, 0xd0, 0, OPC_MODRM | OPC_BWL | OPC_SHIFT, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP3(shldw, 0x0fa4, 0, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP3(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WL, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP2(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP3(shrdw, 0x0fac, 0, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP3(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WL, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP2(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP1(call, 0xff, 2, OPC_MODRM, OPT_INDIR))
ALT(DEF_ASM_OP1(call, 0xe8, 0, OPC_JMP, OPT_ADDR))
ALT(DEF_ASM_OP1(jmp, 0xff, 4, OPC_MODRM, OPT_INDIR))
ALT(DEF_ASM_OP1(jmp, 0xeb, 0, OPC_SHORTJMP | OPC_JMP, OPT_ADDR))
#ifdef I386_ASM_16
ALT(DEF_ASM_OP1(jmp, 0xff, 0, OPC_JMP | OPC_WL, OPT_REGW))
#endif
ALT(DEF_ASM_OP2(lcall, 0x9a, 0, 0, OPT_IM16, OPT_IM32))
ALT(DEF_ASM_OP1(lcall, 0xff, 3, 0, OPT_EA))
ALT(DEF_ASM_OP2(ljmp, 0xea, 0, 0, OPT_IM16, OPT_IM32))
ALT(DEF_ASM_OP1(ljmp, 0xff, 5, 0, OPT_EA))
ALT(DEF_ASM_OP1(int, 0xcd, 0, 0, OPT_IM8))
ALT(DEF_ASM_OP1(seto, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA))
ALT(DEF_ASM_OP1(setob, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA))
DEF_ASM_OP2(enter, 0xc8, 0, 0, OPT_IM16, OPT_IM8)
DEF_ASM_OP0(leave, 0xc9)
DEF_ASM_OP0(ret, 0xc3)
DEF_ASM_OP0(retl,0xc3)
ALT(DEF_ASM_OP1(retl,0xc2, 0, 0, OPT_IM16))
ALT(DEF_ASM_OP1(ret, 0xc2, 0, 0, OPT_IM16))
DEF_ASM_OP0(lret, 0xcb)
ALT(DEF_ASM_OP1(lret, 0xca, 0, 0, OPT_IM16))
ALT(DEF_ASM_OP1(jo, 0x70, 0, OPC_SHORTJMP | OPC_JMP | OPC_TEST, OPT_ADDR))
DEF_ASM_OP1(loopne, 0xe0, 0, OPC_SHORTJMP, OPT_ADDR)
DEF_ASM_OP1(loopnz, 0xe0, 0, OPC_SHORTJMP, OPT_ADDR)
DEF_ASM_OP1(loope, 0xe1, 0, OPC_SHORTJMP, OPT_ADDR)
DEF_ASM_OP1(loopz, 0xe1, 0, OPC_SHORTJMP, OPT_ADDR)
DEF_ASM_OP1(loop, 0xe2, 0, OPC_SHORTJMP, OPT_ADDR)
DEF_ASM_OP1(jecxz, 0xe3, 0, OPC_SHORTJMP, OPT_ADDR)
/* float */
/* specific fcomp handling */
ALT(DEF_ASM_OP0L(fcomp, 0xd8d9, 0, 0))
ALT(DEF_ASM_OP1(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST))
ALT(DEF_ASM_OP2(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0))
ALT(DEF_ASM_OP2(fadd, 0xdcc0, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST))
ALT(DEF_ASM_OP2(fmul, 0xdcc8, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST))
ALT(DEF_ASM_OP0L(fadd, 0xdec1, 0, OPC_FARITH))
ALT(DEF_ASM_OP1(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST))
ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0))
ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST))
ALT(DEF_ASM_OP0L(faddp, 0xdec1, 0, OPC_FARITH))
ALT(DEF_ASM_OP1(fadds, 0xd8, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
ALT(DEF_ASM_OP1(fiaddl, 0xda, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
ALT(DEF_ASM_OP1(faddl, 0xdc, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
ALT(DEF_ASM_OP1(fiadds, 0xde, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
DEF_ASM_OP0(fucompp, 0xdae9)
DEF_ASM_OP0(ftst, 0xd9e4)
DEF_ASM_OP0(fxam, 0xd9e5)
DEF_ASM_OP0(fld1, 0xd9e8)
DEF_ASM_OP0(fldl2t, 0xd9e9)
DEF_ASM_OP0(fldl2e, 0xd9ea)
DEF_ASM_OP0(fldpi, 0xd9eb)
DEF_ASM_OP0(fldlg2, 0xd9ec)
DEF_ASM_OP0(fldln2, 0xd9ed)
DEF_ASM_OP0(fldz, 0xd9ee)
DEF_ASM_OP0(f2xm1, 0xd9f0)
DEF_ASM_OP0(fyl2x, 0xd9f1)
DEF_ASM_OP0(fptan, 0xd9f2)
DEF_ASM_OP0(fpatan, 0xd9f3)
DEF_ASM_OP0(fxtract, 0xd9f4)
DEF_ASM_OP0(fprem1, 0xd9f5)
DEF_ASM_OP0(fdecstp, 0xd9f6)
DEF_ASM_OP0(fincstp, 0xd9f7)
DEF_ASM_OP0(fprem, 0xd9f8)
DEF_ASM_OP0(fyl2xp1, 0xd9f9)
DEF_ASM_OP0(fsqrt, 0xd9fa)
DEF_ASM_OP0(fsincos, 0xd9fb)
DEF_ASM_OP0(frndint, 0xd9fc)
DEF_ASM_OP0(fscale, 0xd9fd)
DEF_ASM_OP0(fsin, 0xd9fe)
DEF_ASM_OP0(fcos, 0xd9ff)
DEF_ASM_OP0(fchs, 0xd9e0)
DEF_ASM_OP0(fabs, 0xd9e1)
DEF_ASM_OP0(fninit, 0xdbe3)
DEF_ASM_OP0(fnclex, 0xdbe2)
DEF_ASM_OP0(fnop, 0xd9d0)
/* fp load */
DEF_ASM_OP1(fld, 0xd9c0, 0, OPC_REG, OPT_ST)
DEF_ASM_OP1(fldl, 0xd9c0, 0, OPC_REG, OPT_ST)
DEF_ASM_OP1(flds, 0xd9, 0, OPC_MODRM, OPT_EA)
ALT(DEF_ASM_OP1(fldl, 0xdd, 0, OPC_MODRM, OPT_EA))
DEF_ASM_OP1(fildl, 0xdb, 0, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fildq, 0xdf, 5, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fildll, 0xdf, 5, OPC_MODRM,OPT_EA)
DEF_ASM_OP1(fldt, 0xdb, 5, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fbld, 0xdf, 4, OPC_MODRM, OPT_EA)
/* fp store */
DEF_ASM_OP1(fst, 0xddd0, 0, OPC_REG, OPT_ST)
DEF_ASM_OP1(fstl, 0xddd0, 0, OPC_REG, OPT_ST)
DEF_ASM_OP1(fsts, 0xd9, 2, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fstps, 0xd9, 3, OPC_MODRM, OPT_EA)
ALT(DEF_ASM_OP1(fstl, 0xdd, 2, OPC_MODRM, OPT_EA))
DEF_ASM_OP1(fstpl, 0xdd, 3, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fist, 0xdf, 2, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fistp, 0xdf, 3, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fistl, 0xdb, 2, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fistpl, 0xdb, 3, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fstp, 0xddd8, 0, OPC_REG, OPT_ST)
DEF_ASM_OP1(fistpq, 0xdf, 7, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fistpll, 0xdf, 7, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fstpt, 0xdb, 7, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fbstp, 0xdf, 6, OPC_MODRM, OPT_EA)
/* exchange */
DEF_ASM_OP0(fxch, 0xd9c9)
ALT(DEF_ASM_OP1(fxch, 0xd9c8, 0, OPC_REG, OPT_ST))
/* misc FPU */
DEF_ASM_OP1(fucom, 0xdde0, 0, OPC_REG, OPT_ST )
DEF_ASM_OP1(fucomp, 0xdde8, 0, OPC_REG, OPT_ST )
DEF_ASM_OP0L(finit, 0xdbe3, 0, OPC_FWAIT)
DEF_ASM_OP1(fldcw, 0xd9, 5, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fnstcw, 0xd9, 7, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fstcw, 0xd9, 7, OPC_MODRM | OPC_FWAIT, OPT_EA )
DEF_ASM_OP0(fnstsw, 0xdfe0)
ALT(DEF_ASM_OP1(fnstsw, 0xdfe0, 0, 0, OPT_EAX ))
ALT(DEF_ASM_OP1(fnstsw, 0xdd, 7, OPC_MODRM, OPT_EA ))
DEF_ASM_OP1(fstsw, 0xdfe0, 0, OPC_FWAIT, OPT_EAX )
ALT(DEF_ASM_OP0L(fstsw, 0xdfe0, 0, OPC_FWAIT))
ALT(DEF_ASM_OP1(fstsw, 0xdd, 7, OPC_MODRM | OPC_FWAIT, OPT_EA ))
DEF_ASM_OP0L(fclex, 0xdbe2, 0, OPC_FWAIT)
DEF_ASM_OP1(fnstenv, 0xd9, 6, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fstenv, 0xd9, 6, OPC_MODRM | OPC_FWAIT, OPT_EA )
DEF_ASM_OP1(fldenv, 0xd9, 4, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fnsave, 0xdd, 6, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fsave, 0xdd, 6, OPC_MODRM | OPC_FWAIT, OPT_EA )
DEF_ASM_OP1(frstor, 0xdd, 4, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(ffree, 0xddc0, 4, OPC_REG, OPT_ST )
DEF_ASM_OP1(ffreep, 0xdfc0, 4, OPC_REG, OPT_ST )
DEF_ASM_OP1(fxsave, 0x0fae, 0, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fxrstor, 0x0fae, 1, OPC_MODRM, OPT_EA )
/* segments */
DEF_ASM_OP2(arpl, 0x63, 0, OPC_MODRM, OPT_REG16, OPT_REG16 | OPT_EA)
DEF_ASM_OP2(lar, 0x0f02, 0, OPC_MODRM, OPT_REG32 | OPT_EA, OPT_REG32)
DEF_ASM_OP1(lgdt, 0x0f01, 2, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(lidt, 0x0f01, 3, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(lldt, 0x0f00, 2, OPC_MODRM, OPT_EA | OPT_REG)
DEF_ASM_OP1(lmsw, 0x0f01, 6, OPC_MODRM, OPT_EA | OPT_REG)
ALT(DEF_ASM_OP2(lslw, 0x0f03, 0, OPC_MODRM | OPC_WL, OPT_EA | OPT_REG, OPT_REG))
DEF_ASM_OP1(ltr, 0x0f00, 3, OPC_MODRM, OPT_EA | OPT_REG)
DEF_ASM_OP1(sgdt, 0x0f01, 0, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(sidt, 0x0f01, 1, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(sldt, 0x0f00, 0, OPC_MODRM, OPT_REG | OPT_EA)
DEF_ASM_OP1(smsw, 0x0f01, 4, OPC_MODRM, OPT_REG | OPT_EA)
DEF_ASM_OP1(str, 0x0f00, 1, OPC_MODRM, OPT_REG16| OPT_EA)
DEF_ASM_OP1(verr, 0x0f00, 4, OPC_MODRM, OPT_REG | OPT_EA)
DEF_ASM_OP1(verw, 0x0f00, 5, OPC_MODRM, OPT_REG | OPT_EA)
#ifdef I386_ASM_16
/* 386 */
DEF_ASM_OP0(loadall386, 0x0f07)
#endif
/* 486 */
DEF_ASM_OP1(bswap, 0x0fc8, 0, OPC_REG, OPT_REG32 )
ALT(DEF_ASM_OP2(xaddb, 0x0fc0, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_REG | OPT_EA ))
ALT(DEF_ASM_OP2(cmpxchgb, 0x0fb0, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_REG | OPT_EA ))
DEF_ASM_OP1(invlpg, 0x0f01, 7, OPC_MODRM, OPT_EA )
DEF_ASM_OP2(boundl, 0x62, 0, OPC_MODRM, OPT_REG32, OPT_EA)
DEF_ASM_OP2(boundw, 0x62, 0, OPC_MODRM | OPC_D16, OPT_REG16, OPT_EA)
/* pentium */
DEF_ASM_OP1(cmpxchg8b, 0x0fc7, 1, OPC_MODRM, OPT_EA )
/* pentium pro */
ALT(DEF_ASM_OP2(cmovo, 0x0f40, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
#ifdef I386_ASM_16
ALT(DEF_ASM_OP2(cmovno, 0x0f41, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(cmovc, 0x0f42, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(cmovnc, 0x0f43, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(cmovz, 0x0f44, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(cmovnz, 0x0f45, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(cmovna, 0x0f46, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(cmova, 0x0f47, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
#endif
DEF_ASM_OP2(fcmovb, 0xdac0, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmove, 0xdac8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovbe, 0xdad0, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovu, 0xdad8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovnb, 0xdbc0, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovne, 0xdbc8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovnbe, 0xdbd0, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovnu, 0xdbd8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fucomi, 0xdbe8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcomi, 0xdbf0, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fucomip, 0xdfe8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcomip, 0xdff0, 0, OPC_REG, OPT_ST, OPT_ST0 )
/* mmx */
DEF_ASM_OP0(emms, 0x0f77) /* must be last OP0 */
DEF_ASM_OP2(movd, 0x0f6e, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_MMX )
ALT(DEF_ASM_OP2(movd, 0x0f7e, 0, OPC_MODRM, OPT_MMX, OPT_EA | OPT_REG32 ))
DEF_ASM_OP2(movq, 0x0f6f, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(movq, 0x0f7f, 0, OPC_MODRM, OPT_MMX, OPT_EA | OPT_MMX ))
DEF_ASM_OP2(packssdw, 0x0f6b, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(packsswb, 0x0f63, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(packuswb, 0x0f67, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddb, 0x0ffc, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddw, 0x0ffd, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddd, 0x0ffe, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddsb, 0x0fec, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddsw, 0x0fed, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddusb, 0x0fdc, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddusw, 0x0fdd, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pand, 0x0fdb, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pandn, 0x0fdf, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpeqb, 0x0f74, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpeqw, 0x0f75, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpeqd, 0x0f76, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpgtb, 0x0f64, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpgtw, 0x0f65, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpgtd, 0x0f66, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pmaddwd, 0x0ff5, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pmulhw, 0x0fe5, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pmullw, 0x0fd5, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(por, 0x0feb, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psllw, 0x0ff1, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psllw, 0x0f71, 6, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(pslld, 0x0ff2, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(pslld, 0x0f72, 6, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psllq, 0x0ff3, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psllq, 0x0f73, 6, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psraw, 0x0fe1, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psraw, 0x0f71, 4, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psrad, 0x0fe2, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psrad, 0x0f72, 4, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psrlw, 0x0fd1, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psrlw, 0x0f71, 2, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psrld, 0x0fd2, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psrld, 0x0f72, 2, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psrlq, 0x0fd3, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psrlq, 0x0f73, 2, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psubb, 0x0ff8, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubw, 0x0ff9, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubd, 0x0ffa, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubsb, 0x0fe8, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubsw, 0x0fe9, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubusb, 0x0fd8, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubusw, 0x0fd9, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpckhbw, 0x0f68, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpckhwd, 0x0f69, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpckhdq, 0x0f6a, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpcklbw, 0x0f60, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpcklwd, 0x0f61, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpckldq, 0x0f62, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pxor, 0x0fef, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
/* sse */
DEF_ASM_OP2(movups, 0x0f10, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE )
ALT(DEF_ASM_OP2(movups, 0x0f11, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 ))
DEF_ASM_OP2(movaps, 0x0f28, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE )
ALT(DEF_ASM_OP2(movaps, 0x0f29, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 ))
DEF_ASM_OP2(movhps, 0x0f16, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE )
ALT(DEF_ASM_OP2(movhps, 0x0f17, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 ))
DEF_ASM_OP2(addps, 0x0f58, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(cvtpi2ps, 0x0f2a, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_SSE )
DEF_ASM_OP2(cvtps2pi, 0x0f2d, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_MMX )
DEF_ASM_OP2(cvttps2pi, 0x0f2c, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_MMX )
DEF_ASM_OP2(divps, 0x0f5e, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(maxps, 0x0f5f, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(minps, 0x0f5d, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(mulps, 0x0f59, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(pavgb, 0x0fe0, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(pavgw, 0x0fe3, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(pmaxsw, 0x0fee, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pmaxub, 0x0fde, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pminsw, 0x0fea, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pminub, 0x0fda, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(rcpss, 0x0f53, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(rsqrtps, 0x0f52, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(sqrtps, 0x0f51, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(subps, 0x0f5c, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
#undef ALT
#undef DEF_ASM_OP0
#undef DEF_ASM_OP0L
#undef DEF_ASM_OP1
#undef DEF_ASM_OP2
#undef DEF_ASM_OP3

1134
external/TCC/i386-gen.c vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,244 +0,0 @@
/* ------------------------------------------------------------------ */
/* WARNING: relative order of tokens is important. */
/* register */
DEF_ASM(al)
DEF_ASM(cl)
DEF_ASM(dl)
DEF_ASM(bl)
DEF_ASM(ah)
DEF_ASM(ch)
DEF_ASM(dh)
DEF_ASM(bh)
DEF_ASM(ax)
DEF_ASM(cx)
DEF_ASM(dx)
DEF_ASM(bx)
DEF_ASM(sp)
DEF_ASM(bp)
DEF_ASM(si)
DEF_ASM(di)
DEF_ASM(eax)
DEF_ASM(ecx)
DEF_ASM(edx)
DEF_ASM(ebx)
DEF_ASM(esp)
DEF_ASM(ebp)
DEF_ASM(esi)
DEF_ASM(edi)
#ifdef TCC_TARGET_X86_64
DEF_ASM(rax)
DEF_ASM(rcx)
DEF_ASM(rdx)
DEF_ASM(rbx)
DEF_ASM(rsp)
DEF_ASM(rbp)
DEF_ASM(rsi)
DEF_ASM(rdi)
#endif
DEF_ASM(mm0)
DEF_ASM(mm1)
DEF_ASM(mm2)
DEF_ASM(mm3)
DEF_ASM(mm4)
DEF_ASM(mm5)
DEF_ASM(mm6)
DEF_ASM(mm7)
DEF_ASM(xmm0)
DEF_ASM(xmm1)
DEF_ASM(xmm2)
DEF_ASM(xmm3)
DEF_ASM(xmm4)
DEF_ASM(xmm5)
DEF_ASM(xmm6)
DEF_ASM(xmm7)
DEF_ASM(cr0)
DEF_ASM(cr1)
DEF_ASM(cr2)
DEF_ASM(cr3)
DEF_ASM(cr4)
DEF_ASM(cr5)
DEF_ASM(cr6)
DEF_ASM(cr7)
DEF_ASM(tr0)
DEF_ASM(tr1)
DEF_ASM(tr2)
DEF_ASM(tr3)
DEF_ASM(tr4)
DEF_ASM(tr5)
DEF_ASM(tr6)
DEF_ASM(tr7)
DEF_ASM(db0)
DEF_ASM(db1)
DEF_ASM(db2)
DEF_ASM(db3)
DEF_ASM(db4)
DEF_ASM(db5)
DEF_ASM(db6)
DEF_ASM(db7)
DEF_ASM(dr0)
DEF_ASM(dr1)
DEF_ASM(dr2)
DEF_ASM(dr3)
DEF_ASM(dr4)
DEF_ASM(dr5)
DEF_ASM(dr6)
DEF_ASM(dr7)
DEF_ASM(es)
DEF_ASM(cs)
DEF_ASM(ss)
DEF_ASM(ds)
DEF_ASM(fs)
DEF_ASM(gs)
DEF_ASM(st)
/* generic two operands */
DEF_BWLX(mov)
DEF_BWLX(add)
DEF_BWLX(or)
DEF_BWLX(adc)
DEF_BWLX(sbb)
DEF_BWLX(and)
DEF_BWLX(sub)
DEF_BWLX(xor)
DEF_BWLX(cmp)
/* unary ops */
DEF_BWLX(inc)
DEF_BWLX(dec)
DEF_BWLX(not)
DEF_BWLX(neg)
DEF_BWLX(mul)
DEF_BWLX(imul)
DEF_BWLX(div)
DEF_BWLX(idiv)
DEF_BWLX(xchg)
DEF_BWLX(test)
/* shifts */
DEF_BWLX(rol)
DEF_BWLX(ror)
DEF_BWLX(rcl)
DEF_BWLX(rcr)
DEF_BWLX(shl)
DEF_BWLX(shr)
DEF_BWLX(sar)
DEF_ASM(shldw)
DEF_ASM(shldl)
DEF_ASM(shld)
DEF_ASM(shrdw)
DEF_ASM(shrdl)
DEF_ASM(shrd)
DEF_ASM(pushw)
DEF_ASM(pushl)
#ifdef TCC_TARGET_X86_64
DEF_ASM(pushq)
#endif
DEF_ASM(push)
DEF_ASM(popw)
DEF_ASM(popl)
#ifdef TCC_TARGET_X86_64
DEF_ASM(popq)
#endif
DEF_ASM(pop)
DEF_BWL(in)
DEF_BWL(out)
DEF_WL(movzb)
DEF_ASM(movzwl)
DEF_ASM(movsbw)
DEF_ASM(movsbl)
DEF_ASM(movswl)
#ifdef TCC_TARGET_X86_64
DEF_ASM(movslq)
#endif
DEF_WLX(lea)
DEF_ASM(les)
DEF_ASM(lds)
DEF_ASM(lss)
DEF_ASM(lfs)
DEF_ASM(lgs)
DEF_ASM(call)
DEF_ASM(jmp)
DEF_ASM(lcall)
DEF_ASM(ljmp)
DEF_ASMTEST(j,)
DEF_ASMTEST(set,)
DEF_ASMTEST(set,b)
DEF_ASMTEST(cmov,)
DEF_WLX(bsf)
DEF_WLX(bsr)
DEF_WLX(bt)
DEF_WLX(bts)
DEF_WLX(btr)
DEF_WLX(btc)
DEF_WLX(lsl)
/* generic FP ops */
DEF_FP(add)
DEF_FP(mul)
DEF_ASM(fcom)
DEF_ASM(fcom_1) /* non existent op, just to have a regular table */
DEF_FP1(com)
DEF_FP(comp)
DEF_FP(sub)
DEF_FP(subr)
DEF_FP(div)
DEF_FP(divr)
DEF_BWLX(xadd)
DEF_BWLX(cmpxchg)
/* string ops */
DEF_BWLX(cmps)
DEF_BWLX(scmp)
DEF_BWL(ins)
DEF_BWL(outs)
DEF_BWLX(lods)
DEF_BWLX(slod)
DEF_BWLX(movs)
DEF_BWLX(smov)
DEF_BWLX(scas)
DEF_BWLX(ssca)
DEF_BWLX(stos)
DEF_BWLX(ssto)
/* generic asm ops */
#define ALT(x)
#define DEF_ASM_OP0(name, opcode) DEF_ASM(name)
#define DEF_ASM_OP0L(name, opcode, group, instr_type)
#define DEF_ASM_OP1(name, opcode, group, instr_type, op0)
#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1)
#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2)
#ifdef TCC_TARGET_X86_64
# include "x86_64-asm.h"
#else
# include "i386-asm.h"
#endif
#define ALT(x)
#define DEF_ASM_OP0(name, opcode)
#define DEF_ASM_OP0L(name, opcode, group, instr_type) DEF_ASM(name)
#define DEF_ASM_OP1(name, opcode, group, instr_type, op0) DEF_ASM(name)
#define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1) DEF_ASM(name)
#define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2) DEF_ASM(name)
#ifdef TCC_TARGET_X86_64
# include "x86_64-asm.h"
#else
# include "i386-asm.h"
#endif

655
external/TCC/il-gen.c vendored
View File

@ -1,655 +0,0 @@
/*
* CIL code generator for TCC
*
* Copyright (c) 2002 Fabrice Bellard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* number of available registers */
#define NB_REGS 3
/* a register can belong to several classes. The classes must be
sorted from more general to more precise (see gv2() code which does
assumptions on it). */
#define RC_ST 0x0001 /* any stack entry */
#define RC_ST0 0x0002 /* top of stack */
#define RC_ST1 0x0004 /* top - 1 */
#define RC_INT RC_ST
#define RC_FLOAT RC_ST
#define RC_IRET RC_ST0 /* function return: integer register */
#define RC_LRET RC_ST0 /* function return: second integer register */
#define RC_FRET RC_ST0 /* function return: float register */
/* pretty names for the registers */
enum {
REG_ST0 = 0,
REG_ST1,
REG_ST2,
};
const int reg_classes[NB_REGS] = {
/* ST0 */ RC_ST | RC_ST0,
/* ST1 */ RC_ST | RC_ST1,
/* ST2 */ RC_ST,
};
/* return registers for function */
#define REG_IRET REG_ST0 /* single word int return register */
#define REG_LRET REG_ST0 /* second word return register (for long long) */
#define REG_FRET REG_ST0 /* float return register */
/* defined if function parameters must be evaluated in reverse order */
/* #define INVERT_FUNC_PARAMS */
/* defined if structures are passed as pointers. Otherwise structures
are directly pushed on stack. */
/* #define FUNC_STRUCT_PARAM_AS_PTR */
/* pointer size, in bytes */
#define PTR_SIZE 4
/* long double size and alignment, in bytes */
#define LDOUBLE_SIZE 8
#define LDOUBLE_ALIGN 8
/* function call context */
typedef struct GFuncContext {
int func_call; /* func call type (FUNC_STDCALL or FUNC_CDECL) */
} GFuncContext;
/******************************************************/
/* opcode definitions */
#define IL_OP_PREFIX 0xFE
enum ILOPCodes {
#define OP(name, str, n) IL_OP_ ## name = n,
#include "il-opcodes.h"
#undef OP
};
char *il_opcodes_str[] = {
#define OP(name, str, n) [n] = str,
#include "il-opcodes.h"
#undef OP
};
/******************************************************/
/* arguments variable numbers start from there */
#define ARG_BASE 0x70000000
static FILE *il_outfile;
static void out_byte(int c)
{
*(char *)ind++ = c;
}
static void out_le32(int c)
{
out_byte(c);
out_byte(c >> 8);
out_byte(c >> 16);
out_byte(c >> 24);
}
static void init_outfile(void)
{
if (!il_outfile) {
il_outfile = stdout;
fprintf(il_outfile,
".assembly extern mscorlib\n"
"{\n"
".ver 1:0:2411:0\n"
"}\n\n");
}
}
static void out_op1(int op)
{
if (op & 0x100)
out_byte(IL_OP_PREFIX);
out_byte(op & 0xff);
}
/* output an opcode with prefix */
static void out_op(int op)
{
out_op1(op);
fprintf(il_outfile, " %s\n", il_opcodes_str[op]);
}
static void out_opb(int op, int c)
{
out_op1(op);
out_byte(c);
fprintf(il_outfile, " %s %d\n", il_opcodes_str[op], c);
}
static void out_opi(int op, int c)
{
out_op1(op);
out_le32(c);
fprintf(il_outfile, " %s 0x%x\n", il_opcodes_str[op], c);
}
/* XXX: not complete */
static void il_type_to_str(char *buf, int buf_size,
int t, const char *varstr)
{
int bt;
Sym *s, *sa;
char buf1[256];
const char *tstr;
t = t & VT_TYPE;
bt = t & VT_BTYPE;
buf[0] = '\0';
if (t & VT_UNSIGNED)
pstrcat(buf, buf_size, "unsigned ");
switch(bt) {
case VT_VOID:
tstr = "void";
goto add_tstr;
case VT_BOOL:
tstr = "bool";
goto add_tstr;
case VT_BYTE:
tstr = "int8";
goto add_tstr;
case VT_SHORT:
tstr = "int16";
goto add_tstr;
case VT_ENUM:
case VT_INT:
case VT_LONG:
tstr = "int32";
goto add_tstr;
case VT_LLONG:
tstr = "int64";
goto add_tstr;
case VT_FLOAT:
tstr = "float32";
goto add_tstr;
case VT_DOUBLE:
case VT_LDOUBLE:
tstr = "float64";
add_tstr:
pstrcat(buf, buf_size, tstr);
break;
case VT_STRUCT:
tcc_error("structures not handled yet");
break;
case VT_FUNC:
s = sym_find((unsigned)t >> VT_STRUCT_SHIFT);
il_type_to_str(buf, buf_size, s->t, varstr);
pstrcat(buf, buf_size, "(");
sa = s->next;
while (sa != NULL) {
il_type_to_str(buf1, sizeof(buf1), sa->t, NULL);
pstrcat(buf, buf_size, buf1);
sa = sa->next;
if (sa)
pstrcat(buf, buf_size, ", ");
}
pstrcat(buf, buf_size, ")");
goto no_var;
case VT_PTR:
s = sym_find((unsigned)t >> VT_STRUCT_SHIFT);
pstrcpy(buf1, sizeof(buf1), "*");
if (varstr)
pstrcat(buf1, sizeof(buf1), varstr);
il_type_to_str(buf, buf_size, s->t, buf1);
goto no_var;
}
if (varstr) {
pstrcat(buf, buf_size, " ");
pstrcat(buf, buf_size, varstr);
}
no_var: ;
}
/* patch relocation entry with value 'val' */
void greloc_patch1(Reloc *p, int val)
{
}
/* output a symbol and patch all calls to it */
void gsym_addr(t, a)
{
}
/* output jump and return symbol */
static int out_opj(int op, int c)
{
out_op1(op);
out_le32(0);
if (c == 0) {
c = ind - (int)cur_text_section->data;
}
fprintf(il_outfile, " %s L%d\n", il_opcodes_str[op], c);
return c;
}
void gsym(int t)
{
fprintf(il_outfile, "L%d:\n", t);
}
/* load 'r' from value 'sv' */
void load(int r, SValue *sv)
{
int v, fc, ft;
v = sv->r & VT_VALMASK;
fc = sv->c.i;
ft = sv->t;
if (sv->r & VT_LVAL) {
if (v == VT_LOCAL) {
if (fc >= ARG_BASE) {
fc -= ARG_BASE;
if (fc >= 0 && fc <= 4) {
out_op(IL_OP_LDARG_0 + fc);
} else if (fc <= 0xff) {
out_opb(IL_OP_LDARG_S, fc);
} else {
out_opi(IL_OP_LDARG, fc);
}
} else {
if (fc >= 0 && fc <= 4) {
out_op(IL_OP_LDLOC_0 + fc);
} else if (fc <= 0xff) {
out_opb(IL_OP_LDLOC_S, fc);
} else {
out_opi(IL_OP_LDLOC, fc);
}
}
} else if (v == VT_CONST) {
/* XXX: handle globals */
out_opi(IL_OP_LDSFLD, 0);
} else {
if ((ft & VT_BTYPE) == VT_FLOAT) {
out_op(IL_OP_LDIND_R4);
} else if ((ft & VT_BTYPE) == VT_DOUBLE) {
out_op(IL_OP_LDIND_R8);
} else if ((ft & VT_BTYPE) == VT_LDOUBLE) {
out_op(IL_OP_LDIND_R8);
} else if ((ft & VT_TYPE) == VT_BYTE)
out_op(IL_OP_LDIND_I1);
else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED))
out_op(IL_OP_LDIND_U1);
else if ((ft & VT_TYPE) == VT_SHORT)
out_op(IL_OP_LDIND_I2);
else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED))
out_op(IL_OP_LDIND_U2);
else
out_op(IL_OP_LDIND_I4);
}
} else {
if (v == VT_CONST) {
/* XXX: handle globals */
if (fc >= -1 && fc <= 8) {
out_op(IL_OP_LDC_I4_M1 + fc + 1);
} else {
out_opi(IL_OP_LDC_I4, fc);
}
} else if (v == VT_LOCAL) {
if (fc >= ARG_BASE) {
fc -= ARG_BASE;
if (fc <= 0xff) {
out_opb(IL_OP_LDARGA_S, fc);
} else {
out_opi(IL_OP_LDARGA, fc);
}
} else {
if (fc <= 0xff) {
out_opb(IL_OP_LDLOCA_S, fc);
} else {
out_opi(IL_OP_LDLOCA, fc);
}
}
} else {
/* XXX: do it */
}
}
}
/* store register 'r' in lvalue 'v' */
void store(int r, SValue *sv)
{
int v, fc, ft;
v = sv->r & VT_VALMASK;
fc = sv->c.i;
ft = sv->t;
if (v == VT_LOCAL) {
if (fc >= ARG_BASE) {
fc -= ARG_BASE;
/* XXX: check IL arg store semantics */
if (fc <= 0xff) {
out_opb(IL_OP_STARG_S, fc);
} else {
out_opi(IL_OP_STARG, fc);
}
} else {
if (fc >= 0 && fc <= 4) {
out_op(IL_OP_STLOC_0 + fc);
} else if (fc <= 0xff) {
out_opb(IL_OP_STLOC_S, fc);
} else {
out_opi(IL_OP_STLOC, fc);
}
}
} else if (v == VT_CONST) {
/* XXX: handle globals */
out_opi(IL_OP_STSFLD, 0);
} else {
if ((ft & VT_BTYPE) == VT_FLOAT)
out_op(IL_OP_STIND_R4);
else if ((ft & VT_BTYPE) == VT_DOUBLE)
out_op(IL_OP_STIND_R8);
else if ((ft & VT_BTYPE) == VT_LDOUBLE)
out_op(IL_OP_STIND_R8);
else if ((ft & VT_BTYPE) == VT_BYTE)
out_op(IL_OP_STIND_I1);
else if ((ft & VT_BTYPE) == VT_SHORT)
out_op(IL_OP_STIND_I2);
else
out_op(IL_OP_STIND_I4);
}
}
/* start function call and return function call context */
void gfunc_start(GFuncContext *c, int func_call)
{
c->func_call = func_call;
}
/* push function parameter which is in (vtop->t, vtop->c). Stack entry
is then popped. */
void gfunc_param(GFuncContext *c)
{
if ((vtop->t & VT_BTYPE) == VT_STRUCT) {
tcc_error("structures passed as value not handled yet");
} else {
/* simply push on stack */
gv(RC_ST0);
}
vtop--;
}
/* generate function call with address in (vtop->t, vtop->c) and free function
context. Stack entry is popped */
void gfunc_call(GFuncContext *c)
{
char buf[1024];
if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
/* XXX: more info needed from tcc */
il_type_to_str(buf, sizeof(buf), vtop->t, "xxx");
fprintf(il_outfile, " call %s\n", buf);
} else {
/* indirect call */
gv(RC_INT);
il_type_to_str(buf, sizeof(buf), vtop->t, NULL);
fprintf(il_outfile, " calli %s\n", buf);
}
vtop--;
}
/* generate function prolog of type 't' */
void gfunc_prolog(int t)
{
int addr, u, func_call;
Sym *sym;
char buf[1024];
init_outfile();
/* XXX: pass function name to gfunc_prolog */
il_type_to_str(buf, sizeof(buf), t, funcname);
fprintf(il_outfile, ".method static %s il managed\n", buf);
fprintf(il_outfile, "{\n");
/* XXX: cannot do better now */
fprintf(il_outfile, " .maxstack %d\n", NB_REGS);
fprintf(il_outfile, " .locals (int32, int32, int32, int32, int32, int32, int32, int32)\n");
if (!strcmp(funcname, "main"))
fprintf(il_outfile, " .entrypoint\n");
sym = sym_find((unsigned)t >> VT_STRUCT_SHIFT);
func_call = sym->r;
addr = ARG_BASE;
/* if the function returns a structure, then add an
implicit pointer parameter */
func_vt = sym->t;
func_var = (sym->c == FUNC_ELLIPSIS);
if ((func_vt & VT_BTYPE) == VT_STRUCT) {
func_vc = addr;
addr++;
}
/* define parameters */
while ((sym = sym->next) != NULL) {
u = sym->t;
sym_push(sym->v & ~SYM_FIELD, u,
VT_LOCAL | lvalue_type(sym->type.t), addr);
addr++;
}
}
/* generate function epilog */
void gfunc_epilog(void)
{
out_op(IL_OP_RET);
fprintf(il_outfile, "}\n\n");
}
/* generate a jump to a label */
int gjmp(int t)
{
return out_opj(IL_OP_BR, t);
}
/* generate a jump to a fixed address */
void gjmp_addr(int a)
{
/* XXX: handle syms */
out_opi(IL_OP_BR, a);
}
/* generate a test. set 'inv' to invert test. Stack entry is popped */
int gtst(int inv, int t)
{
int v, *p, c;
v = vtop->r & VT_VALMASK;
if (v == VT_CMP) {
c = vtop->c.i ^ inv;
switch(c) {
case TOK_EQ:
c = IL_OP_BEQ;
break;
case TOK_NE:
c = IL_OP_BNE_UN;
break;
case TOK_LT:
c = IL_OP_BLT;
break;
case TOK_LE:
c = IL_OP_BLE;
break;
case TOK_GT:
c = IL_OP_BGT;
break;
case TOK_GE:
c = IL_OP_BGE;
break;
case TOK_ULT:
c = IL_OP_BLT_UN;
break;
case TOK_ULE:
c = IL_OP_BLE_UN;
break;
case TOK_UGT:
c = IL_OP_BGT_UN;
break;
case TOK_UGE:
c = IL_OP_BGE_UN;
break;
}
t = out_opj(c, t);
} else if (v == VT_JMP || v == VT_JMPI) {
/* && or || optimization */
if ((v & 1) == inv) {
/* insert vtop->c jump list in t */
p = &vtop->c.i;
while (*p != 0)
p = (int *)*p;
*p = t;
t = vtop->c.i;
} else {
t = gjmp(t);
gsym(vtop->c.i);
}
}
vtop--;
return t;
}
/* generate an integer binary operation */
void gen_opi(int op)
{
gv2(RC_ST1, RC_ST0);
switch(op) {
case '+':
out_op(IL_OP_ADD);
goto std_op;
case '-':
out_op(IL_OP_SUB);
goto std_op;
case '&':
out_op(IL_OP_AND);
goto std_op;
case '^':
out_op(IL_OP_XOR);
goto std_op;
case '|':
out_op(IL_OP_OR);
goto std_op;
case '*':
out_op(IL_OP_MUL);
goto std_op;
case TOK_SHL:
out_op(IL_OP_SHL);
goto std_op;
case TOK_SHR:
out_op(IL_OP_SHR_UN);
goto std_op;
case TOK_SAR:
out_op(IL_OP_SHR);
goto std_op;
case '/':
case TOK_PDIV:
out_op(IL_OP_DIV);
goto std_op;
case TOK_UDIV:
out_op(IL_OP_DIV_UN);
goto std_op;
case '%':
out_op(IL_OP_REM);
goto std_op;
case TOK_UMOD:
out_op(IL_OP_REM_UN);
std_op:
vtop--;
vtop[0].r = REG_ST0;
break;
case TOK_EQ:
case TOK_NE:
case TOK_LT:
case TOK_LE:
case TOK_GT:
case TOK_GE:
case TOK_ULT:
case TOK_ULE:
case TOK_UGT:
case TOK_UGE:
vtop--;
vtop[0].r = VT_CMP;
vtop[0].c.i = op;
break;
}
}
/* generate a floating point operation 'v = t1 op t2' instruction. The
two operands are guaranted to have the same floating point type */
void gen_opf(int op)
{
/* same as integer */
gen_opi(op);
}
/* convert integers to fp 't' type. Must handle 'int', 'unsigned int'
and 'long long' cases. */
void gen_cvt_itof(int t)
{
gv(RC_ST0);
if (t == VT_FLOAT)
out_op(IL_OP_CONV_R4);
else
out_op(IL_OP_CONV_R8);
}
/* convert fp to int 't' type */
/* XXX: handle long long case */
void gen_cvt_ftoi(int t)
{
gv(RC_ST0);
switch(t) {
case VT_INT | VT_UNSIGNED:
out_op(IL_OP_CONV_U4);
break;
case VT_LLONG:
out_op(IL_OP_CONV_I8);
break;
case VT_LLONG | VT_UNSIGNED:
out_op(IL_OP_CONV_U8);
break;
default:
out_op(IL_OP_CONV_I4);
break;
}
}
/* convert from one floating point type to another */
void gen_cvt_ftof(int t)
{
gv(RC_ST0);
if (t == VT_FLOAT) {
out_op(IL_OP_CONV_R4);
} else {
out_op(IL_OP_CONV_R8);
}
}
/* end of CIL code generator */
/*************************************************************/

View File

@ -1,251 +0,0 @@
/*
* CIL opcode definition
*
* Copyright (c) 2002 Fabrice Bellard
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
OP(NOP, "nop", 0x00)
OP(BREAK, "break", 0x01)
OP(LDARG_0, "ldarg.0", 0x02)
OP(LDARG_1, "ldarg.1", 0x03)
OP(LDARG_2, "ldarg.2", 0x04)
OP(LDARG_3, "ldarg.3", 0x05)
OP(LDLOC_0, "ldloc.0", 0x06)
OP(LDLOC_1, "ldloc.1", 0x07)
OP(LDLOC_2, "ldloc.2", 0x08)
OP(LDLOC_3, "ldloc.3", 0x09)
OP(STLOC_0, "stloc.0", 0x0a)
OP(STLOC_1, "stloc.1", 0x0b)
OP(STLOC_2, "stloc.2", 0x0c)
OP(STLOC_3, "stloc.3", 0x0d)
OP(LDARG_S, "ldarg.s", 0x0e)
OP(LDARGA_S, "ldarga.s", 0x0f)
OP(STARG_S, "starg.s", 0x10)
OP(LDLOC_S, "ldloc.s", 0x11)
OP(LDLOCA_S, "ldloca.s", 0x12)
OP(STLOC_S, "stloc.s", 0x13)
OP(LDNULL, "ldnull", 0x14)
OP(LDC_I4_M1, "ldc.i4.m1", 0x15)
OP(LDC_I4_0, "ldc.i4.0", 0x16)
OP(LDC_I4_1, "ldc.i4.1", 0x17)
OP(LDC_I4_2, "ldc.i4.2", 0x18)
OP(LDC_I4_3, "ldc.i4.3", 0x19)
OP(LDC_I4_4, "ldc.i4.4", 0x1a)
OP(LDC_I4_5, "ldc.i4.5", 0x1b)
OP(LDC_I4_6, "ldc.i4.6", 0x1c)
OP(LDC_I4_7, "ldc.i4.7", 0x1d)
OP(LDC_I4_8, "ldc.i4.8", 0x1e)
OP(LDC_I4_S, "ldc.i4.s", 0x1f)
OP(LDC_I4, "ldc.i4", 0x20)
OP(LDC_I8, "ldc.i8", 0x21)
OP(LDC_R4, "ldc.r4", 0x22)
OP(LDC_R8, "ldc.r8", 0x23)
OP(LDPTR, "ldptr", 0x24)
OP(DUP, "dup", 0x25)
OP(POP, "pop", 0x26)
OP(JMP, "jmp", 0x27)
OP(CALL, "call", 0x28)
OP(CALLI, "calli", 0x29)
OP(RET, "ret", 0x2a)
OP(BR_S, "br.s", 0x2b)
OP(BRFALSE_S, "brfalse.s", 0x2c)
OP(BRTRUE_S, "brtrue.s", 0x2d)
OP(BEQ_S, "beq.s", 0x2e)
OP(BGE_S, "bge.s", 0x2f)
OP(BGT_S, "bgt.s", 0x30)
OP(BLE_S, "ble.s", 0x31)
OP(BLT_S, "blt.s", 0x32)
OP(BNE_UN_S, "bne.un.s", 0x33)
OP(BGE_UN_S, "bge.un.s", 0x34)
OP(BGT_UN_S, "bgt.un.s", 0x35)
OP(BLE_UN_S, "ble.un.s", 0x36)
OP(BLT_UN_S, "blt.un.s", 0x37)
OP(BR, "br", 0x38)
OP(BRFALSE, "brfalse", 0x39)
OP(BRTRUE, "brtrue", 0x3a)
OP(BEQ, "beq", 0x3b)
OP(BGE, "bge", 0x3c)
OP(BGT, "bgt", 0x3d)
OP(BLE, "ble", 0x3e)
OP(BLT, "blt", 0x3f)
OP(BNE_UN, "bne.un", 0x40)
OP(BGE_UN, "bge.un", 0x41)
OP(BGT_UN, "bgt.un", 0x42)
OP(BLE_UN, "ble.un", 0x43)
OP(BLT_UN, "blt.un", 0x44)
OP(SWITCH, "switch", 0x45)
OP(LDIND_I1, "ldind.i1", 0x46)
OP(LDIND_U1, "ldind.u1", 0x47)
OP(LDIND_I2, "ldind.i2", 0x48)
OP(LDIND_U2, "ldind.u2", 0x49)
OP(LDIND_I4, "ldind.i4", 0x4a)
OP(LDIND_U4, "ldind.u4", 0x4b)
OP(LDIND_I8, "ldind.i8", 0x4c)
OP(LDIND_I, "ldind.i", 0x4d)
OP(LDIND_R4, "ldind.r4", 0x4e)
OP(LDIND_R8, "ldind.r8", 0x4f)
OP(LDIND_REF, "ldind.ref", 0x50)
OP(STIND_REF, "stind.ref", 0x51)
OP(STIND_I1, "stind.i1", 0x52)
OP(STIND_I2, "stind.i2", 0x53)
OP(STIND_I4, "stind.i4", 0x54)
OP(STIND_I8, "stind.i8", 0x55)
OP(STIND_R4, "stind.r4", 0x56)
OP(STIND_R8, "stind.r8", 0x57)
OP(ADD, "add", 0x58)
OP(SUB, "sub", 0x59)
OP(MUL, "mul", 0x5a)
OP(DIV, "div", 0x5b)
OP(DIV_UN, "div.un", 0x5c)
OP(REM, "rem", 0x5d)
OP(REM_UN, "rem.un", 0x5e)
OP(AND, "and", 0x5f)
OP(OR, "or", 0x60)
OP(XOR, "xor", 0x61)
OP(SHL, "shl", 0x62)
OP(SHR, "shr", 0x63)
OP(SHR_UN, "shr.un", 0x64)
OP(NEG, "neg", 0x65)
OP(NOT, "not", 0x66)
OP(CONV_I1, "conv.i1", 0x67)
OP(CONV_I2, "conv.i2", 0x68)
OP(CONV_I4, "conv.i4", 0x69)
OP(CONV_I8, "conv.i8", 0x6a)
OP(CONV_R4, "conv.r4", 0x6b)
OP(CONV_R8, "conv.r8", 0x6c)
OP(CONV_U4, "conv.u4", 0x6d)
OP(CONV_U8, "conv.u8", 0x6e)
OP(CALLVIRT, "callvirt", 0x6f)
OP(CPOBJ, "cpobj", 0x70)
OP(LDOBJ, "ldobj", 0x71)
OP(LDSTR, "ldstr", 0x72)
OP(NEWOBJ, "newobj", 0x73)
OP(CASTCLASS, "castclass", 0x74)
OP(ISINST, "isinst", 0x75)
OP(CONV_R_UN, "conv.r.un", 0x76)
OP(ANN_DATA_S, "ann.data.s", 0x77)
OP(UNBOX, "unbox", 0x79)
OP(THROW, "throw", 0x7a)
OP(LDFLD, "ldfld", 0x7b)
OP(LDFLDA, "ldflda", 0x7c)
OP(STFLD, "stfld", 0x7d)
OP(LDSFLD, "ldsfld", 0x7e)
OP(LDSFLDA, "ldsflda", 0x7f)
OP(STSFLD, "stsfld", 0x80)
OP(STOBJ, "stobj", 0x81)
OP(CONV_OVF_I1_UN, "conv.ovf.i1.un", 0x82)
OP(CONV_OVF_I2_UN, "conv.ovf.i2.un", 0x83)
OP(CONV_OVF_I4_UN, "conv.ovf.i4.un", 0x84)
OP(CONV_OVF_I8_UN, "conv.ovf.i8.un", 0x85)
OP(CONV_OVF_U1_UN, "conv.ovf.u1.un", 0x86)
OP(CONV_OVF_U2_UN, "conv.ovf.u2.un", 0x87)
OP(CONV_OVF_U4_UN, "conv.ovf.u4.un", 0x88)
OP(CONV_OVF_U8_UN, "conv.ovf.u8.un", 0x89)
OP(CONV_OVF_I_UN, "conv.ovf.i.un", 0x8a)
OP(CONV_OVF_U_UN, "conv.ovf.u.un", 0x8b)
OP(BOX, "box", 0x8c)
OP(NEWARR, "newarr", 0x8d)
OP(LDLEN, "ldlen", 0x8e)
OP(LDELEMA, "ldelema", 0x8f)
OP(LDELEM_I1, "ldelem.i1", 0x90)
OP(LDELEM_U1, "ldelem.u1", 0x91)
OP(LDELEM_I2, "ldelem.i2", 0x92)
OP(LDELEM_U2, "ldelem.u2", 0x93)
OP(LDELEM_I4, "ldelem.i4", 0x94)
OP(LDELEM_U4, "ldelem.u4", 0x95)
OP(LDELEM_I8, "ldelem.i8", 0x96)
OP(LDELEM_I, "ldelem.i", 0x97)
OP(LDELEM_R4, "ldelem.r4", 0x98)
OP(LDELEM_R8, "ldelem.r8", 0x99)
OP(LDELEM_REF, "ldelem.ref", 0x9a)
OP(STELEM_I, "stelem.i", 0x9b)
OP(STELEM_I1, "stelem.i1", 0x9c)
OP(STELEM_I2, "stelem.i2", 0x9d)
OP(STELEM_I4, "stelem.i4", 0x9e)
OP(STELEM_I8, "stelem.i8", 0x9f)
OP(STELEM_R4, "stelem.r4", 0xa0)
OP(STELEM_R8, "stelem.r8", 0xa1)
OP(STELEM_REF, "stelem.ref", 0xa2)
OP(CONV_OVF_I1, "conv.ovf.i1", 0xb3)
OP(CONV_OVF_U1, "conv.ovf.u1", 0xb4)
OP(CONV_OVF_I2, "conv.ovf.i2", 0xb5)
OP(CONV_OVF_U2, "conv.ovf.u2", 0xb6)
OP(CONV_OVF_I4, "conv.ovf.i4", 0xb7)
OP(CONV_OVF_U4, "conv.ovf.u4", 0xb8)
OP(CONV_OVF_I8, "conv.ovf.i8", 0xb9)
OP(CONV_OVF_U8, "conv.ovf.u8", 0xba)
OP(REFANYVAL, "refanyval", 0xc2)
OP(CKFINITE, "ckfinite", 0xc3)
OP(MKREFANY, "mkrefany", 0xc6)
OP(ANN_CALL, "ann.call", 0xc7)
OP(ANN_CATCH, "ann.catch", 0xc8)
OP(ANN_DEAD, "ann.dead", 0xc9)
OP(ANN_HOISTED, "ann.hoisted", 0xca)
OP(ANN_HOISTED_CALL, "ann.hoisted.call", 0xcb)
OP(ANN_LAB, "ann.lab", 0xcc)
OP(ANN_DEF, "ann.def", 0xcd)
OP(ANN_REF_S, "ann.ref.s", 0xce)
OP(ANN_PHI, "ann.phi", 0xcf)
OP(LDTOKEN, "ldtoken", 0xd0)
OP(CONV_U2, "conv.u2", 0xd1)
OP(CONV_U1, "conv.u1", 0xd2)
OP(CONV_I, "conv.i", 0xd3)
OP(CONV_OVF_I, "conv.ovf.i", 0xd4)
OP(CONV_OVF_U, "conv.ovf.u", 0xd5)
OP(ADD_OVF, "add.ovf", 0xd6)
OP(ADD_OVF_UN, "add.ovf.un", 0xd7)
OP(MUL_OVF, "mul.ovf", 0xd8)
OP(MUL_OVF_UN, "mul.ovf.un", 0xd9)
OP(SUB_OVF, "sub.ovf", 0xda)
OP(SUB_OVF_UN, "sub.ovf.un", 0xdb)
OP(ENDFINALLY, "endfinally", 0xdc)
OP(LEAVE, "leave", 0xdd)
OP(LEAVE_S, "leave.s", 0xde)
OP(STIND_I, "stind.i", 0xdf)
OP(CONV_U, "conv.u", 0xe0)
/* prefix instructions. we use an opcode >= 256 to ease coding */
OP(ARGLIST, "arglist", 0x100)
OP(CEQ, "ceq", 0x101)
OP(CGT, "cgt", 0x102)
OP(CGT_UN, "cgt.un", 0x103)
OP(CLT, "clt", 0x104)
OP(CLT_UN, "clt.un", 0x105)
OP(LDFTN, "ldftn", 0x106)
OP(LDVIRTFTN, "ldvirtftn", 0x107)
OP(JMPI, "jmpi", 0x108)
OP(LDARG, "ldarg", 0x109)
OP(LDARGA, "ldarga", 0x10a)
OP(STARG, "starg", 0x10b)
OP(LDLOC, "ldloc", 0x10c)
OP(LDLOCA, "ldloca", 0x10d)
OP(STLOC, "stloc", 0x10e)
OP(LOCALLOC, "localloc", 0x10f)
OP(ENDFILTER, "endfilter", 0x111)
OP(UNALIGNED, "unaligned", 0x112)
OP(VOLATILE, "volatile", 0x113)
OP(TAIL, "tail", 0x114)
OP(INITOBJ, "initobj", 0x115)
OP(ANN_LIVE, "ann.live", 0x116)
OP(CPBLK, "cpblk", 0x117)
OP(INITBLK, "initblk", 0x118)
OP(ANN_REF, "ann.ref", 0x119)
OP(RETHROW, "rethrow", 0x11a)
OP(SIZEOF, "sizeof", 0x11c)
OP(REFANYTYPE, "refanytype", 0x11d)
OP(ANN_DATA, "ann.data", 0x122)
OP(ANN_ARG, "ann.arg", 0x123)

View File

@ -1,11 +0,0 @@
.text
.align 2
.global alloca
.type alloca, %function
alloca:
rsb sp, r0, sp
bic sp, sp, #7
mov r0, sp
mov pc, lr
.size alloca, .-alloca
.section .note.GNU-stack,"",%progbits

View File

@ -1,47 +0,0 @@
/* ---------------------------------------------- */
/* alloca86-bt.S */
.globl __bound_alloca
__bound_alloca:
pop %edx
pop %eax
mov %eax, %ecx
add $3,%eax
and $-4,%eax
jz p6
#ifdef TCC_TARGET_PE
p4:
cmp $4096,%eax
jbe p5
test %eax,-4096(%esp)
sub $4096,%esp
sub $4096,%eax
jmp p4
p5:
#endif
sub %eax,%esp
mov %esp,%eax
push %edx
push %eax
push %ecx
push %eax
call __bound_new_region
add $8, %esp
pop %eax
pop %edx
p6:
push %edx
push %edx
ret
/* mark stack as nonexecutable */
#if defined __ELF__ && defined __linux__
.section .note.GNU-stack,"",@progbits
#endif
/* ---------------------------------------------- */

View File

@ -1,35 +0,0 @@
/* ---------------------------------------------- */
/* alloca86.S */
.globl alloca
alloca:
pop %edx
pop %eax
add $3,%eax
and $-4,%eax
jz p3
#ifdef TCC_TARGET_PE
p1:
cmp $4096,%eax
jbe p2
test %eax,-4096(%esp)
sub $4096,%esp
sub $4096,%eax
jmp p1
p2:
#endif
sub %eax,%esp
mov %esp,%eax
p3:
push %edx
push %edx
ret
/* mark stack as nonexecutable */
#if defined __ELF__ && defined __linux__
.section .note.GNU-stack,"",@progbits
#endif
/* ---------------------------------------------- */

View File

@ -1,60 +0,0 @@
/* ---------------------------------------------- */
/* alloca86_64.S */
.globl __bound_alloca
__bound_alloca:
#ifdef TCC_TARGET_PE
# bound checking is not implemented
pop %rdx
mov %rcx,%rax
add $15,%rax
and $-16,%rax
jz p3
p1:
cmp $4096,%rax
jbe p2
test %rax,-4096(%rsp)
sub $4096,%rsp
sub $4096,%rax
jmp p1
p2:
sub %rax,%rsp
mov %rsp,%rax
add $32,%rax
p3:
push %rdx
ret
#else
pop %rdx
mov %rdi,%rax
movl %rax,%rsi # size, a second parm to the __bound_new_region
add $15,%rax
and $-16,%rax
jz p3
sub %rax,%rsp
mov %rsp,%rdi # pointer, a first parm to the __bound_new_region
mov %rsp,%rax
push %rdx
push %rax
call __bound_new_region
pop %rax
pop %rdx
p3:
push %rdx
ret
#endif
/* mark stack as nonexecutable */
#if defined __ELF__ && defined __linux__
.section .note.GNU-stack,"",@progbits
#endif
/* ---------------------------------------------- */

View File

@ -1,42 +0,0 @@
/* ---------------------------------------------- */
/* alloca86_64.S */
.globl alloca
alloca:
pop %rdx
#ifdef TCC_TARGET_PE
mov %rcx,%rax
#else
mov %rdi,%rax
#endif
add $15,%rax
and $-16,%rax
jz p3
#ifdef TCC_TARGET_PE
p1:
cmp $4096,%rax
jbe p2
test %rax,-4096(%rsp)
sub $4096,%rsp
sub $4096,%rax
jmp p1
p2:
#endif
sub %rax,%rsp
mov %rsp,%rax
#ifdef TCC_TARGET_PE
add $32,%rax
#endif
p3:
push %rdx
ret
/* mark stack as nonexecutable */
#if defined __ELF__ && defined __linux__
.section .note.GNU-stack,"",@progbits
#endif
/* ---------------------------------------------- */

View File

@ -1,489 +0,0 @@
/* TCC ARM runtime EABI
Copyright (C) 2013 Thomas Preud'homme
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/
#include <limits.h>
/* We rely on the little endianness and EABI calling convention for this to
work */
typedef struct double_unsigned_struct {
unsigned low;
unsigned high;
} double_unsigned_struct;
typedef struct unsigned_int_struct {
unsigned low;
int high;
} unsigned_int_struct;
#define REGS_RETURN(name, type) \
void name ## _return(type ret) {}
/* Float helper functions */
#define FLOAT_EXP_BITS 8
#define FLOAT_FRAC_BITS 23
#define DOUBLE_EXP_BITS 11
#define DOUBLE_FRAC_BITS 52
#define ONE_EXP(type) ((1 << (type ## _EXP_BITS - 1)) - 1)
REGS_RETURN(unsigned_int_struct, unsigned_int_struct)
REGS_RETURN(double_unsigned_struct, double_unsigned_struct)
/* float -> integer: (sign) 1.fraction x 2^(exponent - exp_for_one) */
/* float to [unsigned] long long conversion */
#define DEFINE__AEABI_F2XLZ(name, with_sign) \
void __aeabi_ ## name(unsigned val) \
{ \
int exp, high_shift, sign; \
double_unsigned_struct ret; \
\
/* compute sign */ \
sign = val >> 31; \
\
/* compute real exponent */ \
exp = val >> FLOAT_FRAC_BITS; \
exp &= (1 << FLOAT_EXP_BITS) - 1; \
exp -= ONE_EXP(FLOAT); \
\
/* undefined behavior if truncated value cannot be represented */ \
if (with_sign) { \
if (exp > 62) /* |val| too big, double cannot represent LLONG_MAX */ \
return; \
} else { \
if ((sign && exp >= 0) || exp > 63) /* if val < 0 || val too big */ \
return; \
} \
\
val &= (1 << FLOAT_FRAC_BITS) - 1; \
if (exp >= 32) { \
ret.high = 1 << (exp - 32); \
if (exp - 32 >= FLOAT_FRAC_BITS) { \
ret.high |= val << (exp - 32 - FLOAT_FRAC_BITS); \
ret.low = 0; \
} else { \
high_shift = FLOAT_FRAC_BITS - (exp - 32); \
ret.high |= val >> high_shift; \
ret.low = val << (32 - high_shift); \
} \
} else { \
ret.high = 0; \
ret.low = 1 << exp; \
if (exp > FLOAT_FRAC_BITS) \
ret.low |= val << (exp - FLOAT_FRAC_BITS); \
else \
ret.low |= val >> (FLOAT_FRAC_BITS - exp); \
} \
\
/* encode negative integer using 2's complement */ \
if (with_sign && sign) { \
ret.low = ~ret.low; \
ret.high = ~ret.high; \
if (ret.low == UINT_MAX) { \
ret.low = 0; \
ret.high++; \
} else \
ret.low++; \
} \
\
double_unsigned_struct_return(ret); \
}
/* float to unsigned long long conversion */
DEFINE__AEABI_F2XLZ(f2ulz, 0)
/* float to long long conversion */
DEFINE__AEABI_F2XLZ(f2lz, 1)
/* double to [unsigned] long long conversion */
#define DEFINE__AEABI_D2XLZ(name, with_sign) \
void __aeabi_ ## name(double_unsigned_struct val) \
{ \
int exp, high_shift, sign; \
double_unsigned_struct ret; \
\
/* compute sign */ \
sign = val.high >> 31; \
\
/* compute real exponent */ \
exp = (val.high >> (DOUBLE_FRAC_BITS - 32)); \
exp &= (1 << DOUBLE_EXP_BITS) - 1; \
exp -= ONE_EXP(DOUBLE); \
\
/* undefined behavior if truncated value cannot be represented */ \
if (with_sign) { \
if (exp > 62) /* |val| too big, double cannot represent LLONG_MAX */ \
return; \
} else { \
if ((sign && exp >= 0) || exp > 63) /* if val < 0 || val too big */ \
return; \
} \
\
val.high &= (1 << (DOUBLE_FRAC_BITS - 32)) - 1; \
if (exp >= 32) { \
ret.high = 1 << (exp - 32); \
if (exp >= DOUBLE_FRAC_BITS) { \
high_shift = exp - DOUBLE_FRAC_BITS; \
ret.high |= val.high << high_shift; \
ret.high |= val.low >> (32 - high_shift); \
ret.low = val.low << high_shift; \
} else { \
high_shift = DOUBLE_FRAC_BITS - exp; \
ret.high |= val.high >> high_shift; \
ret.low = val.high << (32 - high_shift); \
ret.low |= val.low >> high_shift; \
} \
} else { \
ret.high = 0; \
ret.low = 1 << exp; \
if (exp > DOUBLE_FRAC_BITS - 32) { \
high_shift = exp - DOUBLE_FRAC_BITS - 32; \
ret.low |= val.high << high_shift; \
ret.low |= val.low >> (32 - high_shift); \
} else \
ret.low |= val.high >> (DOUBLE_FRAC_BITS - 32 - exp); \
} \
\
/* encode negative integer using 2's complement */ \
if (with_sign && sign) { \
ret.low = ~ret.low; \
ret.high = ~ret.high; \
if (ret.low == UINT_MAX) { \
ret.low = 0; \
ret.high++; \
} else \
ret.low++; \
} \
\
double_unsigned_struct_return(ret); \
}
/* double to unsigned long long conversion */
DEFINE__AEABI_D2XLZ(d2ulz, 0)
/* double to long long conversion */
DEFINE__AEABI_D2XLZ(d2lz, 1)
/* long long to float conversion */
#define DEFINE__AEABI_XL2F(name, with_sign) \
unsigned __aeabi_ ## name(unsigned long long v) \
{ \
int s /* shift */, flb /* first lost bit */, sign = 0; \
unsigned p = 0 /* power */, ret; \
double_unsigned_struct val; \
\
/* fraction in negative float is encoded in 1's complement */ \
if (with_sign && (v & (1ULL << 63))) { \
sign = 1; \
v = ~v + 1; \
} \
val.low = v; \
val.high = v >> 32; \
/* fill fraction bits */ \
for (s = 31, p = 1 << 31; p && !(val.high & p); s--, p >>= 1); \
if (p) { \
ret = val.high & (p - 1); \
if (s < FLOAT_FRAC_BITS) { \
ret <<= FLOAT_FRAC_BITS - s; \
ret |= val.low >> (32 - (FLOAT_FRAC_BITS - s)); \
flb = (val.low >> (32 - (FLOAT_FRAC_BITS - s - 1))) & 1; \
} else { \
flb = (ret >> (s - FLOAT_FRAC_BITS - 1)) & 1; \
ret >>= s - FLOAT_FRAC_BITS; \
} \
s += 32; \
} else { \
for (s = 31, p = 1 << 31; p && !(val.low & p); s--, p >>= 1); \
if (p) { \
ret = val.low & (p - 1); \
if (s <= FLOAT_FRAC_BITS) { \
ret <<= FLOAT_FRAC_BITS - s; \
flb = 0; \
} else { \
flb = (ret >> (s - FLOAT_FRAC_BITS - 1)) & 1; \
ret >>= s - FLOAT_FRAC_BITS; \
} \
} else \
return 0; \
} \
if (flb) \
ret++; \
\
/* fill exponent bits */ \
ret |= (s + ONE_EXP(FLOAT)) << FLOAT_FRAC_BITS; \
\
/* fill sign bit */ \
ret |= sign << 31; \
\
return ret; \
}
/* unsigned long long to float conversion */
DEFINE__AEABI_XL2F(ul2f, 0)
/* long long to float conversion */
DEFINE__AEABI_XL2F(l2f, 1)
/* long long to double conversion */
#define __AEABI_XL2D(name, with_sign) \
void __aeabi_ ## name(unsigned long long v) \
{ \
int s /* shift */, high_shift, sign = 0; \
unsigned tmp, p = 0; \
double_unsigned_struct val, ret; \
\
/* fraction in negative float is encoded in 1's complement */ \
if (with_sign && (v & (1ULL << 63))) { \
sign = 1; \
v = ~v + 1; \
} \
val.low = v; \
val.high = v >> 32; \
\
/* fill fraction bits */ \
for (s = 31, p = 1 << 31; p && !(val.high & p); s--, p >>= 1); \
if (p) { \
tmp = val.high & (p - 1); \
if (s < DOUBLE_FRAC_BITS - 32) { \
high_shift = DOUBLE_FRAC_BITS - 32 - s; \
ret.high = tmp << high_shift; \
ret.high |= val.low >> (32 - high_shift); \
ret.low = val.low << high_shift; \
} else { \
high_shift = s - (DOUBLE_FRAC_BITS - 32); \
ret.high = tmp >> high_shift; \
ret.low = tmp << (32 - high_shift); \
ret.low |= val.low >> high_shift; \
if ((val.low >> (high_shift - 1)) & 1) { \
if (ret.low == UINT_MAX) { \
ret.high++; \
ret.low = 0; \
} else \
ret.low++; \
} \
} \
s += 32; \
} else { \
for (s = 31, p = 1 << 31; p && !(val.low & p); s--, p >>= 1); \
if (p) { \
tmp = val.low & (p - 1); \
if (s <= DOUBLE_FRAC_BITS - 32) { \
high_shift = DOUBLE_FRAC_BITS - 32 - s; \
ret.high = tmp << high_shift; \
ret.low = 0; \
} else { \
high_shift = s - (DOUBLE_FRAC_BITS - 32); \
ret.high = tmp >> high_shift; \
ret.low = tmp << (32 - high_shift); \
} \
} else { \
ret.high = ret.low = 0; \
double_unsigned_struct_return(ret); \
} \
} \
\
/* fill exponent bits */ \
ret.high |= (s + ONE_EXP(DOUBLE)) << (DOUBLE_FRAC_BITS - 32); \
\
/* fill sign bit */ \
ret.high |= sign << 31; \
\
double_unsigned_struct_return(ret); \
}
/* unsigned long long to double conversion */
__AEABI_XL2D(ul2d, 0)
/* long long to double conversion */
__AEABI_XL2D(l2d, 1)
/* Long long helper functions */
/* TODO: add error in case of den == 0 (see §4.3.1 and §4.3.2) */
#define define_aeabi_xdivmod_signed_type(basetype, type) \
typedef struct type { \
basetype quot; \
unsigned basetype rem; \
} type
#define define_aeabi_xdivmod_unsigned_type(basetype, type) \
typedef struct type { \
basetype quot; \
basetype rem; \
} type
#define AEABI_UXDIVMOD(name,type, rettype, typemacro) \
static inline rettype aeabi_ ## name (type num, type den) \
{ \
rettype ret; \
type quot = 0; \
\
/* Increase quotient while it is less than numerator */ \
while (num >= den) { \
type q = 1; \
\
/* Find closest power of two */ \
while ((q << 1) * den <= num && q * den <= typemacro ## _MAX / 2) \
q <<= 1; \
\
/* Compute difference between current quotient and numerator */ \
num -= q * den; \
quot += q; \
} \
ret.quot = quot; \
ret.rem = num; \
return ret; \
}
#define __AEABI_XDIVMOD(name, type, uiname, rettype, urettype, typemacro) \
void __aeabi_ ## name(type numerator, type denominator) \
{ \
unsigned type num, den; \
urettype uxdiv_ret; \
rettype ret; \
\
if (numerator >= 0) \
num = numerator; \
else \
num = 0 - numerator; \
if (denominator >= 0) \
den = denominator; \
else \
den = 0 - denominator; \
uxdiv_ret = aeabi_ ## uiname(num, den); \
/* signs differ */ \
if ((numerator & typemacro ## _MIN) != (denominator & typemacro ## _MIN)) \
ret.quot = 0 - uxdiv_ret.quot; \
else \
ret.quot = uxdiv_ret.quot; \
if (numerator < 0) \
ret.rem = 0 - uxdiv_ret.rem; \
else \
ret.rem = uxdiv_ret.rem; \
\
rettype ## _return(ret); \
}
define_aeabi_xdivmod_signed_type(long long, lldiv_t);
define_aeabi_xdivmod_unsigned_type(unsigned long long, ulldiv_t);
define_aeabi_xdivmod_signed_type(int, idiv_t);
define_aeabi_xdivmod_unsigned_type(unsigned, uidiv_t);
REGS_RETURN(lldiv_t, lldiv_t)
REGS_RETURN(ulldiv_t, ulldiv_t)
REGS_RETURN(idiv_t, idiv_t)
REGS_RETURN(uidiv_t, uidiv_t)
AEABI_UXDIVMOD(uldivmod, unsigned long long, ulldiv_t, ULONG)
__AEABI_XDIVMOD(ldivmod, long long, uldivmod, lldiv_t, ulldiv_t, LLONG)
void __aeabi_uldivmod(unsigned long long num, unsigned long long den)
{
ulldiv_t_return(aeabi_uldivmod(num, den));
}
void __aeabi_llsl(double_unsigned_struct val, int shift)
{
double_unsigned_struct ret;
if (shift >= 32) {
val.high = val.low;
val.low = 0;
shift -= 32;
}
if (shift > 0) {
ret.low = val.low << shift;
ret.high = (val.high << shift) | (val.low >> (32 - shift));
double_unsigned_struct_return(ret);
return;
}
double_unsigned_struct_return(val);
}
#define aeabi_lsr(val, shift, fill, type) \
type ## _struct ret; \
\
if (shift >= 32) { \
val.low = val.high; \
val.high = fill; \
shift -= 32; \
} \
if (shift > 0) { \
ret.high = val.high >> shift; \
ret.low = (val.high << (32 - shift)) | (val.low >> shift); \
type ## _struct_return(ret); \
return; \
} \
type ## _struct_return(val);
void __aeabi_llsr(double_unsigned_struct val, int shift)
{
aeabi_lsr(val, shift, 0, double_unsigned);
}
void __aeabi_lasr(unsigned_int_struct val, int shift)
{
aeabi_lsr(val, shift, val.high >> 31, unsigned_int);
}
/* Integer division functions */
AEABI_UXDIVMOD(uidivmod, unsigned, uidiv_t, UINT)
int __aeabi_idiv(int numerator, int denominator)
{
unsigned num, den;
uidiv_t ret;
if (numerator >= 0)
num = numerator;
else
num = 0 - numerator;
if (denominator >= 0)
den = denominator;
else
den = 0 - denominator;
ret = aeabi_uidivmod(num, den);
if ((numerator & INT_MIN) != (denominator & INT_MIN)) /* signs differ */
ret.quot *= -1;
return ret.quot;
}
unsigned __aeabi_uidiv(unsigned num, unsigned den)
{
return aeabi_uidivmod(num, den).quot;
}
__AEABI_XDIVMOD(idivmod, int, uidivmod, idiv_t, uidiv_t, INT)
void __aeabi_uidivmod(unsigned num, unsigned den)
{
uidiv_t_return(aeabi_uidivmod(num, den));
}

View File

@ -1,950 +0,0 @@
/*
* Tiny C Memory and bounds checker
*
* Copyright (c) 2002 Fabrice Bellard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) \
&& !defined(__DragonFly__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
#include <malloc.h>
#endif
#if !defined(_WIN32)
#include <unistd.h>
#endif
/* #define BOUND_DEBUG */
#ifdef BOUND_DEBUG
#define dprintf(a...) fprintf(a)
#else
#define dprintf(a...)
#endif
/* define so that bound array is static (faster, but use memory if
bound checking not used) */
/* #define BOUND_STATIC */
/* use malloc hooks. Currently the code cannot be reliable if no hooks */
#define CONFIG_TCC_MALLOC_HOOKS
#define HAVE_MEMALIGN
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
|| defined(__DragonFly__) || defined(__dietlibc__) \
|| defined(__UCLIBC__) || defined(__OpenBSD__) || defined(__NetBSD__) \
|| defined(_WIN32) || defined(TCC_UCLIBC)
#warning Bound checking does not support malloc (etc.) in this environment.
#undef CONFIG_TCC_MALLOC_HOOKS
#undef HAVE_MEMALIGN
#endif
#define BOUND_T1_BITS 13
#define BOUND_T2_BITS 11
#define BOUND_T3_BITS (sizeof(size_t)*8 - BOUND_T1_BITS - BOUND_T2_BITS)
#define BOUND_E_BITS (sizeof(size_t))
#define BOUND_T1_SIZE (1 << BOUND_T1_BITS)
#define BOUND_T2_SIZE (1 << BOUND_T2_BITS)
#define BOUND_T3_SIZE (1 << BOUND_T3_BITS)
#define BOUND_T23_BITS (BOUND_T2_BITS + BOUND_T3_BITS)
#define BOUND_T23_SIZE (1 << BOUND_T23_BITS)
/* this pointer is generated when bound check is incorrect */
#define INVALID_POINTER ((void *)(-2))
/* size of an empty region */
#define EMPTY_SIZE ((size_t)(-1))
/* size of an invalid region */
#define INVALID_SIZE 0
typedef struct BoundEntry {
size_t start;
size_t size;
struct BoundEntry *next;
size_t is_invalid; /* true if pointers outside region are invalid */
} BoundEntry;
/* external interface */
void __bound_init(void);
void __bound_new_region(void *p, size_t size);
int __bound_delete_region(void *p);
#ifdef __attribute__
/* an __attribute__ macro is defined in the system headers */
#undef __attribute__
#endif
#define FASTCALL __attribute__((regparm(3)))
void *__bound_malloc(size_t size, const void *caller);
void *__bound_memalign(size_t size, size_t align, const void *caller);
void __bound_free(void *ptr, const void *caller);
void *__bound_realloc(void *ptr, size_t size, const void *caller);
static void *libc_malloc(size_t size);
static void libc_free(void *ptr);
static void install_malloc_hooks(void);
static void restore_malloc_hooks(void);
#ifdef CONFIG_TCC_MALLOC_HOOKS
static void *saved_malloc_hook;
static void *saved_free_hook;
static void *saved_realloc_hook;
static void *saved_memalign_hook;
#endif
/* TCC definitions */
extern char __bounds_start; /* start of static bounds table */
/* error message, just for TCC */
const char *__bound_error_msg;
/* runtime error output */
extern void rt_error(size_t pc, const char *fmt, ...);
#ifdef BOUND_STATIC
static BoundEntry *__bound_t1[BOUND_T1_SIZE]; /* page table */
#else
static BoundEntry **__bound_t1; /* page table */
#endif
static BoundEntry *__bound_empty_t2; /* empty page, for unused pages */
static BoundEntry *__bound_invalid_t2; /* invalid page, for invalid pointers */
static BoundEntry *__bound_find_region(BoundEntry *e1, void *p)
{
size_t addr, tmp;
BoundEntry *e;
e = e1;
while (e != NULL) {
addr = (size_t)p;
addr -= e->start;
if (addr <= e->size) {
/* put region at the head */
tmp = e1->start;
e1->start = e->start;
e->start = tmp;
tmp = e1->size;
e1->size = e->size;
e->size = tmp;
return e1;
}
e = e->next;
}
/* no entry found: return empty entry or invalid entry */
if (e1->is_invalid)
return __bound_invalid_t2;
else
return __bound_empty_t2;
}
/* print a bound error message */
static void bound_error(const char *fmt, ...)
{
__bound_error_msg = fmt;
fprintf(stderr,"%s %s: %s\n", __FILE__, __FUNCTION__, fmt);
*(int *)0 = 0; /* force a runtime error */
}
static void bound_alloc_error(void)
{
bound_error("not enough memory for bound checking code");
}
/* return '(p + offset)' for pointer arithmetic (a pointer can reach
the end of a region in this case */
void * FASTCALL __bound_ptr_add(void *p, size_t offset)
{
size_t addr = (size_t)p;
BoundEntry *e;
__bound_init();
dprintf(stderr, "%s %s: %p %p\n", __FILE__, __FUNCTION__, p, offset);
e = __bound_t1[addr >> (BOUND_T2_BITS + BOUND_T3_BITS)];
e = (BoundEntry *)((char *)e +
((addr >> (BOUND_T3_BITS - BOUND_E_BITS)) &
((BOUND_T2_SIZE - 1) << BOUND_E_BITS)));
addr -= e->start;
if (addr > e->size) {
e = __bound_find_region(e, p);
addr = (size_t)p - e->start;
}
addr += offset;
if (addr >= e->size) {
fprintf(stderr,"%s %s: %p is outside of the region\n", __FILE__, __FUNCTION__, p + offset);
return INVALID_POINTER; /* return an invalid pointer */
}
return p + offset;
}
/* return '(p + offset)' for pointer indirection (the resulting must
be strictly inside the region */
#define BOUND_PTR_INDIR(dsize) \
void * FASTCALL __bound_ptr_indir ## dsize (void *p, size_t offset) \
{ \
size_t addr = (size_t)p; \
BoundEntry *e; \
\
dprintf(stderr, "%s %s: %p %p start\n", __FILE__, __FUNCTION__, p, offset); \
\
__bound_init(); \
e = __bound_t1[addr >> (BOUND_T2_BITS + BOUND_T3_BITS)]; \
e = (BoundEntry *)((char *)e + \
((addr >> (BOUND_T3_BITS - BOUND_E_BITS)) & \
((BOUND_T2_SIZE - 1) << BOUND_E_BITS))); \
addr -= e->start; \
if (addr > e->size) { \
e = __bound_find_region(e, p); \
addr = (size_t)p - e->start; \
} \
addr += offset + dsize; \
if (addr > e->size) { \
fprintf(stderr,"%s %s: %p is outside of the region\n", __FILE__, __FUNCTION__, p + offset); \
return INVALID_POINTER; /* return an invalid pointer */ \
} \
dprintf(stderr, "%s %s: return p+offset = %p\n", __FILE__, __FUNCTION__, p + offset); \
return p + offset; \
}
BOUND_PTR_INDIR(1)
BOUND_PTR_INDIR(2)
BOUND_PTR_INDIR(4)
BOUND_PTR_INDIR(8)
BOUND_PTR_INDIR(12)
BOUND_PTR_INDIR(16)
/* return the frame pointer of the caller */
#define GET_CALLER_FP(fp)\
{\
fp = (size_t)__builtin_frame_address(1);\
}
/* called when entering a function to add all the local regions */
void FASTCALL __bound_local_new(void *p1)
{
size_t addr, size, fp, *p = p1;
dprintf(stderr, "%s, %s start p1=%p\n", __FILE__, __FUNCTION__, p);
GET_CALLER_FP(fp);
for(;;) {
addr = p[0];
if (addr == 0)
break;
addr += fp;
size = p[1];
p += 2;
__bound_new_region((void *)addr, size);
}
dprintf(stderr, "%s, %s end\n", __FILE__, __FUNCTION__);
}
/* called when leaving a function to delete all the local regions */
void FASTCALL __bound_local_delete(void *p1)
{
size_t addr, fp, *p = p1;
GET_CALLER_FP(fp);
for(;;) {
addr = p[0];
if (addr == 0)
break;
addr += fp;
p += 2;
__bound_delete_region((void *)addr);
}
}
static BoundEntry *__bound_new_page(void)
{
BoundEntry *page;
size_t i;
page = libc_malloc(sizeof(BoundEntry) * BOUND_T2_SIZE);
if (!page)
bound_alloc_error();
for(i=0;i<BOUND_T2_SIZE;i++) {
/* put empty entries */
page[i].start = 0;
page[i].size = EMPTY_SIZE;
page[i].next = NULL;
page[i].is_invalid = 0;
}
return page;
}
/* currently we use malloc(). Should use bound_new_page() */
static BoundEntry *bound_new_entry(void)
{
BoundEntry *e;
e = libc_malloc(sizeof(BoundEntry));
return e;
}
static void bound_free_entry(BoundEntry *e)
{
libc_free(e);
}
static BoundEntry *get_page(size_t index)
{
BoundEntry *page;
page = __bound_t1[index];
if (!page || page == __bound_empty_t2 || page == __bound_invalid_t2) {
/* create a new page if necessary */
page = __bound_new_page();
__bound_t1[index] = page;
}
return page;
}
/* mark a region as being invalid (can only be used during init) */
static void mark_invalid(size_t addr, size_t size)
{
size_t start, end;
BoundEntry *page;
size_t t1_start, t1_end, i, j, t2_start, t2_end;
start = addr;
end = addr + size;
t2_start = (start + BOUND_T3_SIZE - 1) >> BOUND_T3_BITS;
if (end != 0)
t2_end = end >> BOUND_T3_BITS;
else
t2_end = 1 << (BOUND_T1_BITS + BOUND_T2_BITS);
#if 0
dprintf(stderr, "mark_invalid: start = %x %x\n", t2_start, t2_end);
#endif
/* first we handle full pages */
t1_start = (t2_start + BOUND_T2_SIZE - 1) >> BOUND_T2_BITS;
t1_end = t2_end >> BOUND_T2_BITS;
i = t2_start & (BOUND_T2_SIZE - 1);
j = t2_end & (BOUND_T2_SIZE - 1);
if (t1_start == t1_end) {
page = get_page(t2_start >> BOUND_T2_BITS);
for(; i < j; i++) {
page[i].size = INVALID_SIZE;
page[i].is_invalid = 1;
}
} else {
if (i > 0) {
page = get_page(t2_start >> BOUND_T2_BITS);
for(; i < BOUND_T2_SIZE; i++) {
page[i].size = INVALID_SIZE;
page[i].is_invalid = 1;
}
}
for(i = t1_start; i < t1_end; i++) {
__bound_t1[i] = __bound_invalid_t2;
}
if (j != 0) {
page = get_page(t1_end);
for(i = 0; i < j; i++) {
page[i].size = INVALID_SIZE;
page[i].is_invalid = 1;
}
}
}
}
void __bound_init(void)
{
size_t i;
BoundEntry *page;
size_t start, size;
size_t *p;
static int inited;
if (inited)
return;
inited = 1;
dprintf(stderr, "%s, %s() start\n", __FILE__, __FUNCTION__);
/* save malloc hooks and install bound check hooks */
install_malloc_hooks();
#ifndef BOUND_STATIC
__bound_t1 = libc_malloc(BOUND_T1_SIZE * sizeof(BoundEntry *));
if (!__bound_t1)
bound_alloc_error();
#endif
__bound_empty_t2 = __bound_new_page();
for(i=0;i<BOUND_T1_SIZE;i++) {
__bound_t1[i] = __bound_empty_t2;
}
page = __bound_new_page();
for(i=0;i<BOUND_T2_SIZE;i++) {
/* put invalid entries */
page[i].start = 0;
page[i].size = INVALID_SIZE;
page[i].next = NULL;
page[i].is_invalid = 1;
}
__bound_invalid_t2 = page;
/* invalid pointer zone */
start = (size_t)INVALID_POINTER & ~(BOUND_T23_SIZE - 1);
size = BOUND_T23_SIZE;
mark_invalid(start, size);
#if defined(CONFIG_TCC_MALLOC_HOOKS)
/* malloc zone is also marked invalid. can only use that with
* hooks because all libs should use the same malloc. The solution
* would be to build a new malloc for tcc.
*
* usually heap (= malloc zone) comes right after bss, i.e. after _end, but
* not always - either if we are running from under `tcc -b -run`, or if
* address space randomization is turned on(a), heap start will be separated
* from bss end.
*
* So sbrk(0) will be a good approximation for start_brk:
*
* - if we are a separately compiled program, __bound_init() runs early,
* and sbrk(0) should be equal or very near to start_brk(b) (in case other
* constructors malloc something), or
*
* - if we are running from under `tcc -b -run`, sbrk(0) will return
* start of heap portion which is under this program control, and not
* mark as invalid earlier allocated memory.
*
*
* (a) /proc/sys/kernel/randomize_va_space = 2, on Linux;
* usually turned on by default.
*
* (b) on Linux >= v3.3, the alternative is to read
* start_brk from /proc/self/stat
*/
start = (size_t)sbrk(0);
size = 128 * 0x100000;
mark_invalid(start, size);
#endif
/* add all static bound check values */
p = (size_t *)&__bounds_start;
while (p[0] != 0) {
__bound_new_region((void *)p[0], p[1]);
p += 2;
}
dprintf(stderr, "%s, %s() end\n\n", __FILE__, __FUNCTION__);
}
void __bound_main_arg(void **p)
{
void *start = p;
while (*p++);
dprintf(stderr, "%s, %s calling __bound_new_region(%p, %p)\n",
__FILE__, __FUNCTION__, (void *) p - start);
__bound_new_region(start, (void *) p - start);
}
void __bound_exit(void)
{
restore_malloc_hooks();
}
static inline void add_region(BoundEntry *e,
size_t start, size_t size)
{
BoundEntry *e1;
if (e->start == 0) {
/* no region : add it */
e->start = start;
e->size = size;
} else {
/* already regions in the list: add it at the head */
e1 = bound_new_entry();
e1->start = e->start;
e1->size = e->size;
e1->next = e->next;
e->start = start;
e->size = size;
e->next = e1;
}
}
/* create a new region. It should not already exist in the region list */
void __bound_new_region(void *p, size_t size)
{
size_t start, end;
BoundEntry *page, *e, *e2;
size_t t1_start, t1_end, i, t2_start, t2_end;
__bound_init();
dprintf(stderr, "%s, %s(%p, %p) start\n",
__FILE__, __FUNCTION__, p, size);
start = (size_t)p;
end = start + size;
t1_start = start >> (BOUND_T2_BITS + BOUND_T3_BITS);
t1_end = end >> (BOUND_T2_BITS + BOUND_T3_BITS);
/* start */
page = get_page(t1_start);
t2_start = (start >> (BOUND_T3_BITS - BOUND_E_BITS)) &
((BOUND_T2_SIZE - 1) << BOUND_E_BITS);
t2_end = (end >> (BOUND_T3_BITS - BOUND_E_BITS)) &
((BOUND_T2_SIZE - 1) << BOUND_E_BITS);
e = (BoundEntry *)((char *)page + t2_start);
add_region(e, start, size);
if (t1_end == t1_start) {
/* same ending page */
e2 = (BoundEntry *)((char *)page + t2_end);
if (e2 > e) {
e++;
for(;e<e2;e++) {
e->start = start;
e->size = size;
}
add_region(e, start, size);
}
} else {
/* mark until end of page */
e2 = page + BOUND_T2_SIZE;
e++;
for(;e<e2;e++) {
e->start = start;
e->size = size;
}
/* mark intermediate pages, if any */
for(i=t1_start+1;i<t1_end;i++) {
page = get_page(i);
e2 = page + BOUND_T2_SIZE;
for(e=page;e<e2;e++) {
e->start = start;
e->size = size;
}
}
/* last page */
page = get_page(t1_end);
e2 = (BoundEntry *)((char *)page + t2_end);
for(e=page;e<e2;e++) {
e->start = start;
e->size = size;
}
add_region(e, start, size);
}
dprintf(stderr, "%s, %s end\n", __FILE__, __FUNCTION__);
}
/* delete a region */
static inline void delete_region(BoundEntry *e,
void *p, size_t empty_size)
{
size_t addr;
BoundEntry *e1;
addr = (size_t)p;
addr -= e->start;
if (addr <= e->size) {
/* region found is first one */
e1 = e->next;
if (e1 == NULL) {
/* no more region: mark it empty */
e->start = 0;
e->size = empty_size;
} else {
/* copy next region in head */
e->start = e1->start;
e->size = e1->size;
e->next = e1->next;
bound_free_entry(e1);
}
} else {
/* find the matching region */
for(;;) {
e1 = e;
e = e->next;
/* region not found: do nothing */
if (e == NULL)
break;
addr = (size_t)p - e->start;
if (addr <= e->size) {
/* found: remove entry */
e1->next = e->next;
bound_free_entry(e);
break;
}
}
}
}
/* WARNING: 'p' must be the starting point of the region. */
/* return non zero if error */
int __bound_delete_region(void *p)
{
size_t start, end, addr, size, empty_size;
BoundEntry *page, *e, *e2;
size_t t1_start, t1_end, t2_start, t2_end, i;
__bound_init();
dprintf(stderr, "%s %s() start\n", __FILE__, __FUNCTION__);
start = (size_t)p;
t1_start = start >> (BOUND_T2_BITS + BOUND_T3_BITS);
t2_start = (start >> (BOUND_T3_BITS - BOUND_E_BITS)) &
((BOUND_T2_SIZE - 1) << BOUND_E_BITS);
/* find region size */
page = __bound_t1[t1_start];
e = (BoundEntry *)((char *)page + t2_start);
addr = start - e->start;
if (addr > e->size)
e = __bound_find_region(e, p);
/* test if invalid region */
if (e->size == EMPTY_SIZE || (size_t)p != e->start)
return -1;
/* compute the size we put in invalid regions */
if (e->is_invalid)
empty_size = INVALID_SIZE;
else
empty_size = EMPTY_SIZE;
size = e->size;
end = start + size;
/* now we can free each entry */
t1_end = end >> (BOUND_T2_BITS + BOUND_T3_BITS);
t2_end = (end >> (BOUND_T3_BITS - BOUND_E_BITS)) &
((BOUND_T2_SIZE - 1) << BOUND_E_BITS);
delete_region(e, p, empty_size);
if (t1_end == t1_start) {
/* same ending page */
e2 = (BoundEntry *)((char *)page + t2_end);
if (e2 > e) {
e++;
for(;e<e2;e++) {
e->start = 0;
e->size = empty_size;
}
delete_region(e, p, empty_size);
}
} else {
/* mark until end of page */
e2 = page + BOUND_T2_SIZE;
e++;
for(;e<e2;e++) {
e->start = 0;
e->size = empty_size;
}
/* mark intermediate pages, if any */
/* XXX: should free them */
for(i=t1_start+1;i<t1_end;i++) {
page = get_page(i);
e2 = page + BOUND_T2_SIZE;
for(e=page;e<e2;e++) {
e->start = 0;
e->size = empty_size;
}
}
/* last page */
page = get_page(t1_end);
e2 = (BoundEntry *)((char *)page + t2_end);
for(e=page;e<e2;e++) {
e->start = 0;
e->size = empty_size;
}
delete_region(e, p, empty_size);
}
dprintf(stderr, "%s %s() end\n", __FILE__, __FUNCTION__);
return 0;
}
/* return the size of the region starting at p, or EMPTY_SIZE if non
existent region. */
static size_t get_region_size(void *p)
{
size_t addr = (size_t)p;
BoundEntry *e;
e = __bound_t1[addr >> (BOUND_T2_BITS + BOUND_T3_BITS)];
e = (BoundEntry *)((char *)e +
((addr >> (BOUND_T3_BITS - BOUND_E_BITS)) &
((BOUND_T2_SIZE - 1) << BOUND_E_BITS)));
addr -= e->start;
if (addr > e->size)
e = __bound_find_region(e, p);
if (e->start != (size_t)p)
return EMPTY_SIZE;
return e->size;
}
/* patched memory functions */
/* force compiler to perform stores coded up to this point */
#define barrier() __asm__ __volatile__ ("": : : "memory")
static void install_malloc_hooks(void)
{
#ifdef CONFIG_TCC_MALLOC_HOOKS
saved_malloc_hook = __malloc_hook;
saved_free_hook = __free_hook;
saved_realloc_hook = __realloc_hook;
saved_memalign_hook = __memalign_hook;
__malloc_hook = __bound_malloc;
__free_hook = __bound_free;
__realloc_hook = __bound_realloc;
__memalign_hook = __bound_memalign;
barrier();
#endif
}
static void restore_malloc_hooks(void)
{
#ifdef CONFIG_TCC_MALLOC_HOOKS
__malloc_hook = saved_malloc_hook;
__free_hook = saved_free_hook;
__realloc_hook = saved_realloc_hook;
__memalign_hook = saved_memalign_hook;
barrier();
#endif
}
static void *libc_malloc(size_t size)
{
void *ptr;
restore_malloc_hooks();
ptr = malloc(size);
install_malloc_hooks();
return ptr;
}
static void libc_free(void *ptr)
{
restore_malloc_hooks();
free(ptr);
install_malloc_hooks();
}
/* XXX: we should use a malloc which ensure that it is unlikely that
two malloc'ed data have the same address if 'free' are made in
between. */
void *__bound_malloc(size_t size, const void *caller)
{
void *ptr;
/* we allocate one more byte to ensure the regions will be
separated by at least one byte. With the glibc malloc, it may
be in fact not necessary */
ptr = libc_malloc(size + 1);
if (!ptr)
return NULL;
dprintf(stderr, "%s, %s calling __bound_new_region(%p, %p)\n",
__FILE__, __FUNCTION__, ptr, size);
__bound_new_region(ptr, size);
return ptr;
}
void *__bound_memalign(size_t size, size_t align, const void *caller)
{
void *ptr;
restore_malloc_hooks();
#ifndef HAVE_MEMALIGN
if (align > 4) {
/* XXX: handle it ? */
ptr = NULL;
} else {
/* we suppose that malloc aligns to at least four bytes */
ptr = malloc(size + 1);
}
#else
/* we allocate one more byte to ensure the regions will be
separated by at least one byte. With the glibc malloc, it may
be in fact not necessary */
ptr = memalign(size + 1, align);
#endif
install_malloc_hooks();
if (!ptr)
return NULL;
dprintf(stderr, "%s, %s calling __bound_new_region(%p, %p)\n",
__FILE__, __FUNCTION__, ptr, size);
__bound_new_region(ptr, size);
return ptr;
}
void __bound_free(void *ptr, const void *caller)
{
if (ptr == NULL)
return;
if (__bound_delete_region(ptr) != 0)
bound_error("freeing invalid region");
libc_free(ptr);
}
void *__bound_realloc(void *ptr, size_t size, const void *caller)
{
void *ptr1;
size_t old_size;
if (size == 0) {
__bound_free(ptr, caller);
return NULL;
} else {
ptr1 = __bound_malloc(size, caller);
if (ptr == NULL || ptr1 == NULL)
return ptr1;
old_size = get_region_size(ptr);
if (old_size == EMPTY_SIZE)
bound_error("realloc'ing invalid pointer");
memcpy(ptr1, ptr, old_size);
__bound_free(ptr, caller);
return ptr1;
}
}
#ifndef CONFIG_TCC_MALLOC_HOOKS
void *__bound_calloc(size_t nmemb, size_t size)
{
void *ptr;
size = size * nmemb;
ptr = __bound_malloc(size, NULL);
if (!ptr)
return NULL;
memset(ptr, 0, size);
return ptr;
}
#endif
#if 0
static void bound_dump(void)
{
BoundEntry *page, *e;
size_t i, j;
fprintf(stderr, "region dump:\n");
for(i=0;i<BOUND_T1_SIZE;i++) {
page = __bound_t1[i];
for(j=0;j<BOUND_T2_SIZE;j++) {
e = page + j;
/* do not print invalid or empty entries */
if (e->size != EMPTY_SIZE && e->start != 0) {
fprintf(stderr, "%08x:",
(i << (BOUND_T2_BITS + BOUND_T3_BITS)) +
(j << BOUND_T3_BITS));
do {
fprintf(stderr, " %08lx:%08lx", e->start, e->start + e->size);
e = e->next;
} while (e != NULL);
fprintf(stderr, "\n");
}
}
}
}
#endif
/* some useful checked functions */
/* check that (p ... p + size - 1) lies inside 'p' region, if any */
static void __bound_check(const void *p, size_t size)
{
if (size == 0)
return;
p = __bound_ptr_add((void *)p, size - 1);
if (p == INVALID_POINTER)
bound_error("invalid pointer");
}
void *__bound_memcpy(void *dst, const void *src, size_t size)
{
void* p;
dprintf(stderr, "%s %s: start, dst=%p src=%p size=%p\n", __FILE__, __FUNCTION__, dst, src, size);
__bound_check(dst, size);
__bound_check(src, size);
/* check also region overlap */
if (src >= dst && src < dst + size)
bound_error("overlapping regions in memcpy()");
p = memcpy(dst, src, size);
dprintf(stderr, "%s %s: end, p=%p\n", __FILE__, __FUNCTION__, p);
return p;
}
void *__bound_memmove(void *dst, const void *src, size_t size)
{
__bound_check(dst, size);
__bound_check(src, size);
return memmove(dst, src, size);
}
void *__bound_memset(void *dst, int c, size_t size)
{
__bound_check(dst, size);
return memset(dst, c, size);
}
/* XXX: could be optimized */
int __bound_strlen(const char *s)
{
const char *p;
size_t len;
len = 0;
for(;;) {
p = __bound_ptr_indir1((char *)s, len);
if (p == INVALID_POINTER)
bound_error("bad pointer in strlen()");
if (*p == '\0')
break;
len++;
}
return len;
}
char *__bound_strcpy(char *dst, const char *src)
{
size_t len;
void *p;
dprintf(stderr, "%s %s: strcpy start, dst=%p src=%p\n", __FILE__, __FUNCTION__, dst, src);
len = __bound_strlen(src);
p = __bound_memcpy(dst, src, len + 1);
dprintf(stderr, "%s %s: strcpy end, p=%p\n", __FILE__, __FUNCTION__, dst, src, p);
return p;
}

View File

@ -1,652 +0,0 @@
/*
* TCC runtime library for arm64.
*
* Copyright (c) 2015 Edmund Grimley Evans
*
* Copying and distribution of this file, with or without modification,
* are permitted in any medium without royalty provided the copyright
* notice and this notice are preserved. This file is offered as-is,
* without any warranty.
*/
#include <stdint.h>
#include <string.h>
void __clear_cache(void *beg, void *end)
{
__arm64_clear_cache(beg, end);
}
typedef struct {
uint64_t x0, x1;
} u128_t;
static long double f3_zero(int sgn)
{
long double f;
u128_t x = { 0, (uint64_t)sgn << 63 };
memcpy(&f, &x, 16);
return f;
}
static long double f3_infinity(int sgn)
{
long double f;
u128_t x = { 0, (uint64_t)sgn << 63 | 0x7fff000000000000 };
memcpy(&f, &x, 16);
return f;
}
static long double f3_NaN(void)
{
long double f;
#if 0
// ARM's default NaN usually has just the top fraction bit set:
u128_t x = { 0, 0x7fff800000000000 };
#else
// GCC's library sets all fraction bits:
u128_t x = { -1, 0x7fffffffffffffff };
#endif
memcpy(&f, &x, 16);
return f;
}
static int fp3_convert_NaN(long double *f, int sgn, u128_t mnt)
{
u128_t x = { mnt.x0,
mnt.x1 | 0x7fff800000000000 | (uint64_t)sgn << 63 };
memcpy(f, &x, 16);
return 1;
}
static int fp3_detect_NaNs(long double *f,
int a_sgn, int a_exp, u128_t a,
int b_sgn, int b_exp, u128_t b)
{
// Detect signalling NaNs:
if (a_exp == 32767 && (a.x0 | a.x1 << 16) && !(a.x1 >> 47 & 1))
return fp3_convert_NaN(f, a_sgn, a);
if (b_exp == 32767 && (b.x0 | b.x1 << 16) && !(b.x1 >> 47 & 1))
return fp3_convert_NaN(f, b_sgn, b);
// Detect quiet NaNs:
if (a_exp == 32767 && (a.x0 | a.x1 << 16))
return fp3_convert_NaN(f, a_sgn, a);
if (b_exp == 32767 && (b.x0 | b.x1 << 16))
return fp3_convert_NaN(f, b_sgn, b);
return 0;
}
static void f3_unpack(int *sgn, int32_t *exp, u128_t *mnt, long double f)
{
u128_t x;
memcpy(&x, &f, 16);
*sgn = x.x1 >> 63;
*exp = x.x1 >> 48 & 32767;
x.x1 = x.x1 << 16 >> 16;
if (*exp)
x.x1 |= (uint64_t)1 << 48;
else
*exp = 1;
*mnt = x;
}
static u128_t f3_normalise(int32_t *exp, u128_t mnt)
{
int sh;
if (!(mnt.x0 | mnt.x1))
return mnt;
if (!mnt.x1) {
mnt.x1 = mnt.x0;
mnt.x0 = 0;
*exp -= 64;
}
for (sh = 32; sh; sh >>= 1) {
if (!(mnt.x1 >> (64 - sh))) {
mnt.x1 = mnt.x1 << sh | mnt.x0 >> (64 - sh);
mnt.x0 = mnt.x0 << sh;
*exp -= sh;
}
}
return mnt;
}
static u128_t f3_sticky_shift(int32_t sh, u128_t x)
{
if (sh >= 128) {
x.x0 = !!(x.x0 | x.x1);
x.x1 = 0;
return x;
}
if (sh >= 64) {
x.x0 = x.x1 | !!x.x0;
x.x1 = 0;
sh -= 64;
}
if (sh > 0) {
x.x0 = x.x0 >> sh | x.x1 << (64 - sh) | !!(x.x0 << (64 - sh));
x.x1 = x.x1 >> sh;
}
return x;
}
static long double f3_round(int sgn, int32_t exp, u128_t x)
{
long double f;
int error;
if (exp > 0) {
x = f3_sticky_shift(13, x);
}
else {
x = f3_sticky_shift(14 - exp, x);
exp = 0;
}
error = x.x0 & 3;
x.x0 = x.x0 >> 2 | x.x1 << 62;
x.x1 = x.x1 >> 2;
if (error == 3 || ((error == 2) & (x.x0 & 1))) {
if (!++x.x0) {
++x.x1;
if (x.x1 == (uint64_t)1 << 48)
exp = 1;
else if (x.x1 == (uint64_t)1 << 49) {
++exp;
x.x0 = x.x0 >> 1 | x.x1 << 63;
x.x1 = x.x1 >> 1;
}
}
}
if (exp >= 32767)
return f3_infinity(sgn);
x.x1 = x.x1 << 16 >> 16 | (uint64_t)exp << 48 | (uint64_t)sgn << 63;
memcpy(&f, &x, 16);
return f;
}
static long double f3_add(long double fa, long double fb, int neg)
{
u128_t a, b, x;
int32_t a_exp, b_exp, x_exp;
int a_sgn, b_sgn, x_sgn;
long double fx;
f3_unpack(&a_sgn, &a_exp, &a, fa);
f3_unpack(&b_sgn, &b_exp, &b, fb);
if (fp3_detect_NaNs(&fx, a_sgn, a_exp, a, b_sgn, b_exp, b))
return fx;
b_sgn ^= neg;
// Handle infinities and zeroes:
if (a_exp == 32767 && b_exp == 32767 && a_sgn != b_sgn)
return f3_NaN();
if (a_exp == 32767)
return f3_infinity(a_sgn);
if (b_exp == 32767)
return f3_infinity(b_sgn);
if (!(a.x0 | a.x1 | b.x0 | b.x1))
return f3_zero(a_sgn & b_sgn);
a.x1 = a.x1 << 3 | a.x0 >> 61;
a.x0 = a.x0 << 3;
b.x1 = b.x1 << 3 | b.x0 >> 61;
b.x0 = b.x0 << 3;
if (a_exp <= b_exp) {
a = f3_sticky_shift(b_exp - a_exp, a);
a_exp = b_exp;
}
else {
b = f3_sticky_shift(a_exp - b_exp, b);
b_exp = a_exp;
}
x_sgn = a_sgn;
x_exp = a_exp;
if (a_sgn == b_sgn) {
x.x0 = a.x0 + b.x0;
x.x1 = a.x1 + b.x1 + (x.x0 < a.x0);
}
else {
x.x0 = a.x0 - b.x0;
x.x1 = a.x1 - b.x1 - (x.x0 > a.x0);
if (x.x1 >> 63) {
x_sgn ^= 1;
x.x0 = -x.x0;
x.x1 = -x.x1 - !!x.x0;
}
}
if (!(x.x0 | x.x1))
return f3_zero(0);
x = f3_normalise(&x_exp, x);
return f3_round(x_sgn, x_exp + 12, x);
}
long double __addtf3(long double a, long double b)
{
return f3_add(a, b, 0);
}
long double __subtf3(long double a, long double b)
{
return f3_add(a, b, 1);
}
long double __multf3(long double fa, long double fb)
{
u128_t a, b, x;
int32_t a_exp, b_exp, x_exp;
int a_sgn, b_sgn, x_sgn;
long double fx;
f3_unpack(&a_sgn, &a_exp, &a, fa);
f3_unpack(&b_sgn, &b_exp, &b, fb);
if (fp3_detect_NaNs(&fx, a_sgn, a_exp, a, b_sgn, b_exp, b))
return fx;
// Handle infinities and zeroes:
if ((a_exp == 32767 && !(b.x0 | b.x1)) ||
(b_exp == 32767 && !(a.x0 | a.x1)))
return f3_NaN();
if (a_exp == 32767 || b_exp == 32767)
return f3_infinity(a_sgn ^ b_sgn);
if (!(a.x0 | a.x1) || !(b.x0 | b.x1))
return f3_zero(a_sgn ^ b_sgn);
a = f3_normalise(&a_exp, a);
b = f3_normalise(&b_exp, b);
x_sgn = a_sgn ^ b_sgn;
x_exp = a_exp + b_exp - 16352;
{
// Convert to base (1 << 30), discarding bottom 6 bits, which are zero,
// so there are (32, 30, 30, 30) bits in (a3, a2, a1, a0):
uint64_t a0 = a.x0 << 28 >> 34;
uint64_t b0 = b.x0 << 28 >> 34;
uint64_t a1 = a.x0 >> 36 | a.x1 << 62 >> 34;
uint64_t b1 = b.x0 >> 36 | b.x1 << 62 >> 34;
uint64_t a2 = a.x1 << 32 >> 34;
uint64_t b2 = b.x1 << 32 >> 34;
uint64_t a3 = a.x1 >> 32;
uint64_t b3 = b.x1 >> 32;
// Use 16 small multiplications and additions that do not overflow:
uint64_t x0 = a0 * b0;
uint64_t x1 = (x0 >> 30) + a0 * b1 + a1 * b0;
uint64_t x2 = (x1 >> 30) + a0 * b2 + a1 * b1 + a2 * b0;
uint64_t x3 = (x2 >> 30) + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0;
uint64_t x4 = (x3 >> 30) + a1 * b3 + a2 * b2 + a3 * b1;
uint64_t x5 = (x4 >> 30) + a2 * b3 + a3 * b2;
uint64_t x6 = (x5 >> 30) + a3 * b3;
// We now have (64, 30, 30, ...) bits in (x6, x5, x4, ...).
// Take the top 128 bits, setting bottom bit if any lower bits were set:
uint64_t y0 = (x5 << 34 | x4 << 34 >> 30 | x3 << 34 >> 60 |
!!(x3 << 38 | (x2 | x1 | x0) << 34));
uint64_t y1 = x6;
// Top bit may be zero. Renormalise:
if (!(y1 >> 63)) {
y1 = y1 << 1 | y0 >> 63;
y0 = y0 << 1;
--x_exp;
}
x.x0 = y0;
x.x1 = y1;
}
return f3_round(x_sgn, x_exp, x);
}
long double __divtf3(long double fa, long double fb)
{
u128_t a, b, x;
int32_t a_exp, b_exp, x_exp;
int a_sgn, b_sgn, x_sgn, i;
long double fx;
f3_unpack(&a_sgn, &a_exp, &a, fa);
f3_unpack(&b_sgn, &b_exp, &b, fb);
if (fp3_detect_NaNs(&fx, a_sgn, a_exp, a, b_sgn, b_exp, b))
return fx;
// Handle infinities and zeroes:
if ((a_exp == 32767 && b_exp == 32767) ||
(!(a.x0 | a.x1) && !(b.x0 | b.x1)))
return f3_NaN();
if (a_exp == 32767 || !(b.x0 | b.x1))
return f3_infinity(a_sgn ^ b_sgn);
if (!(a.x0 | a.x1) || b_exp == 32767)
return f3_zero(a_sgn ^ b_sgn);
a = f3_normalise(&a_exp, a);
b = f3_normalise(&b_exp, b);
x_sgn = a_sgn ^ b_sgn;
x_exp = a_exp - b_exp + 16395;
a.x0 = a.x0 >> 1 | a.x1 << 63;
a.x1 = a.x1 >> 1;
b.x0 = b.x0 >> 1 | b.x1 << 63;
b.x1 = b.x1 >> 1;
x.x0 = 0;
x.x1 = 0;
for (i = 0; i < 116; i++) {
x.x1 = x.x1 << 1 | x.x0 >> 63;
x.x0 = x.x0 << 1;
if (a.x1 > b.x1 || (a.x1 == b.x1 && a.x0 >= b.x0)) {
a.x1 = a.x1 - b.x1 - (a.x0 < b.x0);
a.x0 = a.x0 - b.x0;
x.x0 |= 1;
}
a.x1 = a.x1 << 1 | a.x0 >> 63;
a.x0 = a.x0 << 1;
}
x.x0 |= !!(a.x0 | a.x1);
x = f3_normalise(&x_exp, x);
return f3_round(x_sgn, x_exp, x);
}
long double __extendsftf2(float f)
{
long double fx;
u128_t x;
uint32_t a;
uint64_t aa;
memcpy(&a, &f, 4);
aa = a;
x.x0 = 0;
if (!(a << 1))
x.x1 = aa << 32;
else if (a << 1 >> 24 == 255)
x.x1 = (0x7fff000000000000 | aa >> 31 << 63 | aa << 41 >> 16 |
(uint64_t)!!(a << 9) << 47);
else
x.x1 = (aa >> 31 << 63 | ((aa >> 23 & 255) + 16256) << 48 |
aa << 41 >> 16);
memcpy(&fx, &x, 16);
return fx;
}
long double __extenddftf2(double f)
{
long double fx;
u128_t x;
uint64_t a;
memcpy(&a, &f, 8);
x.x0 = a << 60;
if (!(a << 1))
x.x1 = a;
else if (a << 1 >> 53 == 2047)
x.x1 = (0x7fff000000000000 | a >> 63 << 63 | a << 12 >> 16 |
(uint64_t)!!(a << 12) << 47);
else
x.x1 = a >> 63 << 63 | ((a >> 52 & 2047) + 15360) << 48 | a << 12 >> 16;
memcpy(&fx, &x, 16);
return fx;
}
float __trunctfsf2(long double f)
{
u128_t mnt;
int32_t exp;
int sgn;
uint32_t x;
float fx;
f3_unpack(&sgn, &exp, &mnt, f);
if (exp == 32767 && (mnt.x0 | mnt.x1 << 16))
x = 0x7fc00000 | (uint32_t)sgn << 31 | (mnt.x1 >> 25 & 0x007fffff);
else if (exp > 16510)
x = 0x7f800000 | (uint32_t)sgn << 31;
else if (exp < 16233)
x = (uint32_t)sgn << 31;
else {
exp -= 16257;
x = mnt.x1 >> 23 | !!(mnt.x0 | mnt.x1 << 41);
if (exp < 0) {
x = x >> -exp | !!(x << (32 + exp));
exp = 0;
}
if ((x & 3) == 3 || (x & 7) == 6)
x += 4;
x = ((x >> 2) + (exp << 23)) | (uint32_t)sgn << 31;
}
memcpy(&fx, &x, 4);
return fx;
}
double __trunctfdf2(long double f)
{
u128_t mnt;
int32_t exp;
int sgn;
uint64_t x;
double fx;
f3_unpack(&sgn, &exp, &mnt, f);
if (exp == 32767 && (mnt.x0 | mnt.x1 << 16))
x = (0x7ff8000000000000 | (uint64_t)sgn << 63 |
mnt.x1 << 16 >> 12 | mnt.x0 >> 60);
else if (exp > 17406)
x = 0x7ff0000000000000 | (uint64_t)sgn << 63;
else if (exp < 15308)
x = (uint64_t)sgn << 63;
else {
exp -= 15361;
x = mnt.x1 << 6 | mnt.x0 >> 58 | !!(mnt.x0 << 6);
if (exp < 0) {
x = x >> -exp | !!(x << (64 + exp));
exp = 0;
}
if ((x & 3) == 3 || (x & 7) == 6)
x += 4;
x = ((x >> 2) + ((uint64_t)exp << 52)) | (uint64_t)sgn << 63;
}
memcpy(&fx, &x, 8);
return fx;
}
int32_t __fixtfsi(long double fa)
{
u128_t a;
int32_t a_exp;
int a_sgn;
int32_t x;
f3_unpack(&a_sgn, &a_exp, &a, fa);
if (a_exp < 16369)
return 0;
if (a_exp > 16413)
return a_sgn ? -0x80000000 : 0x7fffffff;
x = a.x1 >> (16431 - a_exp);
return a_sgn ? -x : x;
}
int64_t __fixtfdi(long double fa)
{
u128_t a;
int32_t a_exp;
int a_sgn;
int64_t x;
f3_unpack(&a_sgn, &a_exp, &a, fa);
if (a_exp < 16383)
return 0;
if (a_exp > 16445)
return a_sgn ? -0x8000000000000000 : 0x7fffffffffffffff;
x = (a.x1 << 15 | a.x0 >> 49) >> (16446 - a_exp);
return a_sgn ? -x : x;
}
uint32_t __fixunstfsi(long double fa)
{
u128_t a;
int32_t a_exp;
int a_sgn;
f3_unpack(&a_sgn, &a_exp, &a, fa);
if (a_sgn || a_exp < 16369)
return 0;
if (a_exp > 16414)
return -1;
return a.x1 >> (16431 - a_exp);
}
uint64_t __fixunstfdi(long double fa)
{
u128_t a;
int32_t a_exp;
int a_sgn;
f3_unpack(&a_sgn, &a_exp, &a, fa);
if (a_sgn || a_exp < 16383)
return 0;
if (a_exp > 16446)
return -1;
return (a.x1 << 15 | a.x0 >> 49) >> (16446 - a_exp);
}
long double __floatsitf(int32_t a)
{
int sgn = 0;
int exp = 16414;
uint32_t mnt = a;
u128_t x = { 0, 0 };
long double f;
int i;
if (a) {
if (a < 0) {
sgn = 1;
mnt = -mnt;
}
for (i = 16; i; i >>= 1)
if (!(mnt >> (32 - i))) {
mnt <<= i;
exp -= i;
}
x.x1 = ((uint64_t)sgn << 63 | (uint64_t)exp << 48 |
(uint64_t)(mnt << 1) << 16);
}
memcpy(&f, &x, 16);
return f;
}
long double __floatditf(int64_t a)
{
int sgn = 0;
int exp = 16446;
uint64_t mnt = a;
u128_t x = { 0, 0 };
long double f;
int i;
if (a) {
if (a < 0) {
sgn = 1;
mnt = -mnt;
}
for (i = 32; i; i >>= 1)
if (!(mnt >> (64 - i))) {
mnt <<= i;
exp -= i;
}
x.x0 = mnt << 49;
x.x1 = (uint64_t)sgn << 63 | (uint64_t)exp << 48 | mnt << 1 >> 16;
}
memcpy(&f, &x, 16);
return f;
}
long double __floatunsitf(uint32_t a)
{
int exp = 16414;
uint32_t mnt = a;
u128_t x = { 0, 0 };
long double f;
int i;
if (a) {
for (i = 16; i; i >>= 1)
if (!(mnt >> (32 - i))) {
mnt <<= i;
exp -= i;
}
x.x1 = (uint64_t)exp << 48 | (uint64_t)(mnt << 1) << 16;
}
memcpy(&f, &x, 16);
return f;
}
long double __floatunditf(uint64_t a)
{
int exp = 16446;
uint64_t mnt = a;
u128_t x = { 0, 0 };
long double f;
int i;
if (a) {
for (i = 32; i; i >>= 1)
if (!(mnt >> (64 - i))) {
mnt <<= i;
exp -= i;
}
x.x0 = mnt << 49;
x.x1 = (uint64_t)exp << 48 | mnt << 1 >> 16;
}
memcpy(&f, &x, 16);
return f;
}
static int f3_cmp(long double fa, long double fb)
{
u128_t a, b;
memcpy(&a, &fa, 16);
memcpy(&b, &fb, 16);
return (!(a.x0 | a.x1 << 1 | b.x0 | b.x1 << 1) ? 0 :
((a.x1 << 1 >> 49 == 0x7fff && (a.x0 | a.x1 << 16)) ||
(b.x1 << 1 >> 49 == 0x7fff && (b.x0 | b.x1 << 16))) ? 2 :
a.x1 >> 63 != b.x1 >> 63 ? (int)(b.x1 >> 63) - (int)(a.x1 >> 63) :
a.x1 < b.x1 ? (int)(a.x1 >> 63 << 1) - 1 :
a.x1 > b.x1 ? 1 - (int)(a.x1 >> 63 << 1) :
a.x0 < b.x0 ? (int)(a.x1 >> 63 << 1) - 1 :
b.x0 < a.x0 ? 1 - (int)(a.x1 >> 63 << 1) : 0);
}
int __eqtf2(long double a, long double b)
{
return !!f3_cmp(a, b);
}
int __netf2(long double a, long double b)
{
return !!f3_cmp(a, b);
}
int __lttf2(long double a, long double b)
{
return f3_cmp(a, b);
}
int __letf2(long double a, long double b)
{
return f3_cmp(a, b);
}
int __gttf2(long double a, long double b)
{
return -f3_cmp(b, a);
}
int __getf2(long double a, long double b)
{
return -f3_cmp(b, a);
}

View File

@ -1,753 +0,0 @@
/* TCC runtime library.
Parts of this code are (c) 2002 Fabrice Bellard
Copyright (C) 1987, 1988, 1992, 1994, 1995 Free Software Foundation, Inc.
This file is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
This file is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <stdint.h>
#define W_TYPE_SIZE 32
#define BITS_PER_UNIT 8
typedef int Wtype;
typedef unsigned int UWtype;
typedef unsigned int USItype;
typedef long long DWtype;
typedef unsigned long long UDWtype;
struct DWstruct {
Wtype low, high;
};
typedef union
{
struct DWstruct s;
DWtype ll;
} DWunion;
typedef long double XFtype;
#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
/* the following deal with IEEE single-precision numbers */
#define EXCESS 126
#define SIGNBIT 0x80000000
#define HIDDEN (1 << 23)
#define SIGN(fp) ((fp) & SIGNBIT)
#define EXP(fp) (((fp) >> 23) & 0xFF)
#define MANT(fp) (((fp) & 0x7FFFFF) | HIDDEN)
#define PACK(s,e,m) ((s) | ((e) << 23) | (m))
/* the following deal with IEEE double-precision numbers */
#define EXCESSD 1022
#define HIDDEND (1 << 20)
#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
#define SIGND(fp) ((fp.l.upper) & SIGNBIT)
#define MANTD(fp) (((((fp.l.upper) & 0xFFFFF) | HIDDEND) << 10) | \
(fp.l.lower >> 22))
#define HIDDEND_LL ((long long)1 << 52)
#define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL)
#define PACKD_LL(s,e,m) (((long long)((s)+((e)<<20))<<32)|(m))
/* the following deal with x86 long double-precision numbers */
#define EXCESSLD 16382
#define EXPLD(fp) (fp.l.upper & 0x7fff)
#define SIGNLD(fp) ((fp.l.upper) & 0x8000)
/* only for x86 */
union ldouble_long {
long double ld;
struct {
unsigned long long lower;
unsigned short upper;
} l;
};
union double_long {
double d;
#if 1
struct {
unsigned int lower;
int upper;
} l;
#else
struct {
int upper;
unsigned int lower;
} l;
#endif
long long ll;
};
union float_long {
float f;
unsigned int l;
};
/* XXX: we don't support several builtin supports for now */
#if !defined(TCC_TARGET_X86_64) && !defined(TCC_TARGET_ARM)
/* XXX: use gcc/tcc intrinsic ? */
#if defined(TCC_TARGET_I386)
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
__asm__ ("subl %5,%1\n\tsbbl %3,%0" \
: "=r" ((USItype) (sh)), \
"=&r" ((USItype) (sl)) \
: "0" ((USItype) (ah)), \
"g" ((USItype) (bh)), \
"1" ((USItype) (al)), \
"g" ((USItype) (bl)))
#define umul_ppmm(w1, w0, u, v) \
__asm__ ("mull %3" \
: "=a" ((USItype) (w0)), \
"=d" ((USItype) (w1)) \
: "%0" ((USItype) (u)), \
"rm" ((USItype) (v)))
#define udiv_qrnnd(q, r, n1, n0, dv) \
__asm__ ("divl %4" \
: "=a" ((USItype) (q)), \
"=d" ((USItype) (r)) \
: "0" ((USItype) (n0)), \
"1" ((USItype) (n1)), \
"rm" ((USItype) (dv)))
#define count_leading_zeros(count, x) \
do { \
USItype __cbtmp; \
__asm__ ("bsrl %1,%0" \
: "=r" (__cbtmp) : "rm" ((USItype) (x))); \
(count) = __cbtmp ^ 31; \
} while (0)
#else
#error unsupported CPU type
#endif
/* most of this code is taken from libgcc2.c from gcc */
static UDWtype __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
{
DWunion ww;
DWunion nn, dd;
DWunion rr;
UWtype d0, d1, n0, n1, n2;
UWtype q0, q1;
UWtype b, bm;
nn.ll = n;
dd.ll = d;
d0 = dd.s.low;
d1 = dd.s.high;
n0 = nn.s.low;
n1 = nn.s.high;
#if !defined(UDIV_NEEDS_NORMALIZATION)
if (d1 == 0)
{
if (d0 > n1)
{
/* 0q = nn / 0D */
udiv_qrnnd (q0, n0, n1, n0, d0);
q1 = 0;
/* Remainder in n0. */
}
else
{
/* qq = NN / 0d */
if (d0 == 0)
d0 = 1 / d0; /* Divide intentionally by zero. */
udiv_qrnnd (q1, n1, 0, n1, d0);
udiv_qrnnd (q0, n0, n1, n0, d0);
/* Remainder in n0. */
}
if (rp != 0)
{
rr.s.low = n0;
rr.s.high = 0;
*rp = rr.ll;
}
}
#else /* UDIV_NEEDS_NORMALIZATION */
if (d1 == 0)
{
if (d0 > n1)
{
/* 0q = nn / 0D */
count_leading_zeros (bm, d0);
if (bm != 0)
{
/* Normalize, i.e. make the most significant bit of the
denominator set. */
d0 = d0 << bm;
n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
n0 = n0 << bm;
}
udiv_qrnnd (q0, n0, n1, n0, d0);
q1 = 0;
/* Remainder in n0 >> bm. */
}
else
{
/* qq = NN / 0d */
if (d0 == 0)
d0 = 1 / d0; /* Divide intentionally by zero. */
count_leading_zeros (bm, d0);
if (bm == 0)
{
/* From (n1 >= d0) /\ (the most significant bit of d0 is set),
conclude (the most significant bit of n1 is set) /\ (the
leading quotient digit q1 = 1).
This special case is necessary, not an optimization.
(Shifts counts of W_TYPE_SIZE are undefined.) */
n1 -= d0;
q1 = 1;
}
else
{
/* Normalize. */
b = W_TYPE_SIZE - bm;
d0 = d0 << bm;
n2 = n1 >> b;
n1 = (n1 << bm) | (n0 >> b);
n0 = n0 << bm;
udiv_qrnnd (q1, n1, n2, n1, d0);
}
/* n1 != d0... */
udiv_qrnnd (q0, n0, n1, n0, d0);
/* Remainder in n0 >> bm. */
}
if (rp != 0)
{
rr.s.low = n0 >> bm;
rr.s.high = 0;
*rp = rr.ll;
}
}
#endif /* UDIV_NEEDS_NORMALIZATION */
else
{
if (d1 > n1)
{
/* 00 = nn / DD */
q0 = 0;
q1 = 0;
/* Remainder in n1n0. */
if (rp != 0)
{
rr.s.low = n0;
rr.s.high = n1;
*rp = rr.ll;
}
}
else
{
/* 0q = NN / dd */
count_leading_zeros (bm, d1);
if (bm == 0)
{
/* From (n1 >= d1) /\ (the most significant bit of d1 is set),
conclude (the most significant bit of n1 is set) /\ (the
quotient digit q0 = 0 or 1).
This special case is necessary, not an optimization. */
/* The condition on the next line takes advantage of that
n1 >= d1 (true due to program flow). */
if (n1 > d1 || n0 >= d0)
{
q0 = 1;
sub_ddmmss (n1, n0, n1, n0, d1, d0);
}
else
q0 = 0;
q1 = 0;
if (rp != 0)
{
rr.s.low = n0;
rr.s.high = n1;
*rp = rr.ll;
}
}
else
{
UWtype m1, m0;
/* Normalize. */
b = W_TYPE_SIZE - bm;
d1 = (d1 << bm) | (d0 >> b);
d0 = d0 << bm;
n2 = n1 >> b;
n1 = (n1 << bm) | (n0 >> b);
n0 = n0 << bm;
udiv_qrnnd (q0, n1, n2, n1, d1);
umul_ppmm (m1, m0, q0, d0);
if (m1 > n1 || (m1 == n1 && m0 > n0))
{
q0--;
sub_ddmmss (m1, m0, m1, m0, d1, d0);
}
q1 = 0;
/* Remainder in (n1n0 - m1m0) >> bm. */
if (rp != 0)
{
sub_ddmmss (n1, n0, n1, n0, m1, m0);
rr.s.low = (n1 << b) | (n0 >> bm);
rr.s.high = n1 >> bm;
*rp = rr.ll;
}
}
}
}
ww.s.low = q0;
ww.s.high = q1;
return ww.ll;
}
#define __negdi2(a) (-(a))
long long __divdi3(long long u, long long v)
{
int c = 0;
DWunion uu, vv;
DWtype w;
uu.ll = u;
vv.ll = v;
if (uu.s.high < 0) {
c = ~c;
uu.ll = __negdi2 (uu.ll);
}
if (vv.s.high < 0) {
c = ~c;
vv.ll = __negdi2 (vv.ll);
}
w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
if (c)
w = __negdi2 (w);
return w;
}
long long __moddi3(long long u, long long v)
{
int c = 0;
DWunion uu, vv;
DWtype w;
uu.ll = u;
vv.ll = v;
if (uu.s.high < 0) {
c = ~c;
uu.ll = __negdi2 (uu.ll);
}
if (vv.s.high < 0)
vv.ll = __negdi2 (vv.ll);
__udivmoddi4 (uu.ll, vv.ll, (UDWtype *) &w);
if (c)
w = __negdi2 (w);
return w;
}
unsigned long long __udivdi3(unsigned long long u, unsigned long long v)
{
return __udivmoddi4 (u, v, (UDWtype *) 0);
}
unsigned long long __umoddi3(unsigned long long u, unsigned long long v)
{
UDWtype w;
__udivmoddi4 (u, v, &w);
return w;
}
/* XXX: fix tcc's code generator to do this instead */
long long __ashrdi3(long long a, int b)
{
#ifdef __TINYC__
DWunion u;
u.ll = a;
if (b >= 32) {
u.s.low = u.s.high >> (b - 32);
u.s.high = u.s.high >> 31;
} else if (b != 0) {
u.s.low = ((unsigned)u.s.low >> b) | (u.s.high << (32 - b));
u.s.high = u.s.high >> b;
}
return u.ll;
#else
return a >> b;
#endif
}
/* XXX: fix tcc's code generator to do this instead */
unsigned long long __lshrdi3(unsigned long long a, int b)
{
#ifdef __TINYC__
DWunion u;
u.ll = a;
if (b >= 32) {
u.s.low = (unsigned)u.s.high >> (b - 32);
u.s.high = 0;
} else if (b != 0) {
u.s.low = ((unsigned)u.s.low >> b) | (u.s.high << (32 - b));
u.s.high = (unsigned)u.s.high >> b;
}
return u.ll;
#else
return a >> b;
#endif
}
/* XXX: fix tcc's code generator to do this instead */
long long __ashldi3(long long a, int b)
{
#ifdef __TINYC__
DWunion u;
u.ll = a;
if (b >= 32) {
u.s.high = (unsigned)u.s.low << (b - 32);
u.s.low = 0;
} else if (b != 0) {
u.s.high = ((unsigned)u.s.high << b) | ((unsigned)u.s.low >> (32 - b));
u.s.low = (unsigned)u.s.low << b;
}
return u.ll;
#else
return a << b;
#endif
}
#ifndef COMMIT_4ad186c5ef61_IS_FIXED
long long __tcc_cvt_ftol(long double x)
{
unsigned c0, c1;
long long ret;
__asm__ __volatile__ ("fnstcw %0" : "=m" (c0));
c1 = c0 | 0x0C00;
__asm__ __volatile__ ("fldcw %0" : : "m" (c1));
__asm__ __volatile__ ("fistpll %0" : "=m" (ret));
__asm__ __volatile__ ("fldcw %0" : : "m" (c0));
return ret;
}
#endif
#endif /* !__x86_64__ */
/* XXX: fix tcc's code generator to do this instead */
float __floatundisf(unsigned long long a)
{
DWunion uu;
XFtype r;
uu.ll = a;
if (uu.s.high >= 0) {
return (float)uu.ll;
} else {
r = (XFtype)uu.ll;
r += 18446744073709551616.0;
return (float)r;
}
}
double __floatundidf(unsigned long long a)
{
DWunion uu;
XFtype r;
uu.ll = a;
if (uu.s.high >= 0) {
return (double)uu.ll;
} else {
r = (XFtype)uu.ll;
r += 18446744073709551616.0;
return (double)r;
}
}
long double __floatundixf(unsigned long long a)
{
DWunion uu;
XFtype r;
uu.ll = a;
if (uu.s.high >= 0) {
return (long double)uu.ll;
} else {
r = (XFtype)uu.ll;
r += 18446744073709551616.0;
return (long double)r;
}
}
unsigned long long __fixunssfdi (float a1)
{
register union float_long fl1;
register int exp;
register unsigned long l;
fl1.f = a1;
if (fl1.l == 0)
return (0);
exp = EXP (fl1.l) - EXCESS - 24;
l = MANT(fl1.l);
if (exp >= 41)
return (unsigned long long)-1;
else if (exp >= 0)
return (unsigned long long)l << exp;
else if (exp >= -23)
return l >> -exp;
else
return 0;
}
unsigned long long __fixunsdfdi (double a1)
{
register union double_long dl1;
register int exp;
register unsigned long long l;
dl1.d = a1;
if (dl1.ll == 0)
return (0);
exp = EXPD (dl1) - EXCESSD - 53;
l = MANTD_LL(dl1);
if (exp >= 12)
return (unsigned long long)-1;
else if (exp >= 0)
return l << exp;
else if (exp >= -52)
return l >> -exp;
else
return 0;
}
unsigned long long __fixunsxfdi (long double a1)
{
register union ldouble_long dl1;
register int exp;
register unsigned long long l;
dl1.ld = a1;
if (dl1.l.lower == 0 && dl1.l.upper == 0)
return (0);
exp = EXPLD (dl1) - EXCESSLD - 64;
l = dl1.l.lower;
if (exp > 0)
return (unsigned long long)-1;
else if (exp >= -63)
return l >> -exp;
else
return 0;
}
long long __fixsfdi (float a1)
{
long long ret; int s;
ret = __fixunssfdi((s = a1 >= 0) ? a1 : -a1);
return s ? ret : -ret;
}
long long __fixdfdi (double a1)
{
long long ret; int s;
ret = __fixunsdfdi((s = a1 >= 0) ? a1 : -a1);
return s ? ret : -ret;
}
long long __fixxfdi (long double a1)
{
long long ret; int s;
ret = __fixunsxfdi((s = a1 >= 0) ? a1 : -a1);
return s ? ret : -ret;
}
#if defined(TCC_TARGET_X86_64) && !defined(_WIN64)
#ifndef __TINYC__
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#else
/* Avoid including stdlib.h because it is not easily available when
cross compiling */
#include <stddef.h> /* size_t definition is needed for a x86_64-tcc to parse memset() */
extern void *malloc(unsigned long long);
extern void *memset(void *s, int c, size_t n);
extern void free(void*);
extern void abort(void);
#endif
enum __va_arg_type {
__va_gen_reg, __va_float_reg, __va_stack
};
//This should be in sync with the declaration on our include/stdarg.h
/* GCC compatible definition of va_list. */
typedef struct {
unsigned int gp_offset;
unsigned int fp_offset;
union {
unsigned int overflow_offset;
char *overflow_arg_area;
};
char *reg_save_area;
} __va_list_struct;
#undef __va_start
#undef __va_arg
#undef __va_copy
#undef __va_end
void __va_start(__va_list_struct *ap, void *fp)
{
memset(ap, 0, sizeof(__va_list_struct));
*ap = *(__va_list_struct *)((char *)fp - 16);
ap->overflow_arg_area = (char *)fp + ap->overflow_offset;
ap->reg_save_area = (char *)fp - 176 - 16;
}
void *__va_arg(__va_list_struct *ap,
enum __va_arg_type arg_type,
int size, int align)
{
size = (size + 7) & ~7;
align = (align + 7) & ~7;
switch (arg_type) {
case __va_gen_reg:
if (ap->gp_offset + size <= 48) {
ap->gp_offset += size;
return ap->reg_save_area + ap->gp_offset - size;
}
goto use_overflow_area;
case __va_float_reg:
if (ap->fp_offset < 128 + 48) {
ap->fp_offset += 16;
return ap->reg_save_area + ap->fp_offset - 16;
}
size = 8;
goto use_overflow_area;
case __va_stack:
use_overflow_area:
ap->overflow_arg_area += size;
ap->overflow_arg_area = (char*)((intptr_t)(ap->overflow_arg_area + align - 1) & -(intptr_t)align);
return ap->overflow_arg_area - size;
default:
#ifndef __TINYC__
fprintf(stderr, "unknown ABI type for __va_arg\n");
#endif
abort();
}
}
#endif /* __x86_64__ */
/* Flushing for tccrun */
#if defined(TCC_TARGET_X86_64) || defined(TCC_TARGET_I386)
void __clear_cache(void *beginning, void *end)
{
}
#elif defined(TCC_TARGET_ARM)
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <stdio.h>
void __clear_cache(void *beginning, void *end)
{
/* __ARM_NR_cacheflush is kernel private and should not be used in user space.
* However, there is no ARM asm parser in tcc so we use it for now */
#if 1
syscall(__ARM_NR_cacheflush, beginning, end, 0);
#else
__asm__ ("push {r7}\n\t"
"mov r7, #0xf0002\n\t"
"mov r2, #0\n\t"
"swi 0\n\t"
"pop {r7}\n\t"
"ret");
#endif
}
#else
#warning __clear_cache not defined for this architecture, avoid using tcc -run
#endif

View File

@ -1,510 +0,0 @@
/*
* Test 128-bit floating-point arithmetic on arm64:
* build with two different compilers and compare the output.
*
* Copyright (c) 2015 Edmund Grimley Evans
*
* Copying and distribution of this file, with or without modification,
* are permitted in any medium without royalty provided the copyright
* notice and this notice are preserved. This file is offered as-is,
* without any warranty.
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define check(x) ((x) ? (void)0 : check_fail(#x, __FILE__, __LINE__))
void check_fail(const char *assertion, const char *file, unsigned int line)
{
printf("%s:%d: Check (%s) failed.", file, line, assertion);
exit(1);
}
typedef struct {
unsigned long long x0, x1;
} u128_t;
float copy_fi(uint32_t x)
{
float f;
memcpy(&f, &x, 4);
return f;
}
double copy_di(uint64_t x)
{
double f;
memcpy(&f, &x, 8);
return f;
}
long double copy_ldi(u128_t x)
{
long double f;
memcpy(&f, &x, 16);
return f;
}
uint32_t copy_if(float f)
{
uint32_t x;
memcpy(&x, &f, 4);
return x;
}
uint64_t copy_id(double f)
{
uint64_t x;
memcpy(&x, &f, 8);
return x;
}
u128_t copy_ild(long double f)
{
u128_t x;
memcpy(&x, &f, 16);
return x;
}
long double make(int sgn, int exp, uint64_t high, uint64_t low)
{
u128_t x = { low,
(0x0000ffffffffffff & high) |
(0x7fff000000000000 & (uint64_t)exp << 48) |
(0x8000000000000000 & (uint64_t)sgn << 63) };
return copy_ldi(x);
}
void cmp(long double a, long double b)
{
u128_t ax = copy_ild(a);
u128_t bx = copy_ild(b);
int eq = (a == b);
int ne = (a != b);
int lt = (a < b);
int le = (a <= b);
int gt = (a > b);
int ge = (a >= b);
check(eq == 0 || eq == 1);
check(lt == 0 || lt == 1);
check(gt == 0 || gt == 1);
check(ne == !eq && le == (lt | eq) && ge == (gt | eq));
check(eq + lt + gt < 2);
printf("cmp %016llx%016llx %016llx%016llx %d %d %d\n",
ax.x1, ax.x0, bx.x1, bx.x0, lt, eq, gt);
}
void cmps(void)
{
int i, j;
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
cmp(make(i, 0, 0, 0), make(j, 0, 0, 0));
for (i = 0; i < 2; i++) {
for (j = 0; j < 64; j++) {
long double f1 = make(i, 32767, (uint64_t)1 << j, 0);
long double f2 = make(i, 32767, 0, (uint64_t)1 << j);
cmp(f1, 0);
cmp(f2, 0);
cmp(0, f1);
cmp(0, f2);
}
}
for (i = 0; i < 6; i++)
for (j = 0; j < 6; j++)
cmp(make(i & 1, i >> 1, 0, 0),
make(j & 1, j >> 1, 0, 0));
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
int a, b;
for (a = 0; a < 2; a++) {
for (b = 0; b < 2; b++) {
cmp(make(i, j, a, b), make(i, j, 0, 0));
cmp(make(i, j, 0, 0), make(i, j, a, b));
}
}
}
}
}
void xop(const char *name, long double a, long double b, long double c)
{
u128_t ax = copy_ild(a);
u128_t bx = copy_ild(b);
u128_t cx = copy_ild(c);
printf("%s %016llx%016llx %016llx%016llx %016llx%016llx\n",
name, ax.x1, ax.x0, bx.x1, bx.x0, cx.x1, cx.x0);
}
void fadd(long double a, long double b)
{
xop("add", a, b, a + b);
}
void fsub(long double a, long double b)
{
xop("sub", a, b, a - b);
}
void fmul(long double a, long double b)
{
xop("mul", a, b, a * b);
}
void fdiv(long double a, long double b)
{
xop("div", a, b, a / b);
}
void nanz(void)
{
// Check NaNs:
{
long double x[7];
int i, j, n = 0;
x[n++] = make(0, 32000, 0x95132b76effc, 0xd79035214b4f8d53);
x[n++] = make(1, 32001, 0xbe71d7a51587, 0x30601c6815d6c3ac);
x[n++] = make(0, 32767, 0, 1);
x[n++] = make(0, 32767, (uint64_t)1 << 46, 0);
x[n++] = make(1, 32767, (uint64_t)1 << 47, 0);
x[n++] = make(1, 32767, 0x7596c7099ad5, 0xe25fed2c58f73fc9);
x[n++] = make(0, 32767, 0x835d143360f9, 0x5e315efb35630666);
check(n == sizeof(x) / sizeof(*x));
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
fadd(x[i], x[j]);
fsub(x[i], x[j]);
fmul(x[i], x[j]);
fdiv(x[i], x[j]);
}
}
}
// Check infinities and zeroes:
{
long double x[6];
int i, j, n = 0;
x[n++] = make(1, 32000, 0x62acda85f700, 0x47b6c9f35edc4044);
x[n++] = make(0, 32001, 0x94b7abf55af7, 0x9f425fe354428e19);
x[n++] = make(0, 32767, 0, 0);
x[n++] = make(1, 32767, 0, 0);
x[n++] = make(0, 0, 0, 0);
x[n++] = make(1, 0, 0, 0);
check(n == sizeof(x) / sizeof(*x));
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
fadd(x[i], x[j]);
fsub(x[i], x[j]);
fmul(x[i], x[j]);
fdiv(x[i], x[j]);
}
}
}
}
void adds(void)
{
// Check shifting and add/sub:
{
int i;
for (i = -130; i <= 130; i++) {
int s1 = (uint32_t)i % 3 < 1;
int s2 = (uint32_t)i % 5 < 2;
fadd(make(s1, 16384 , 0x502c065e4f71a65d, 0xd2f9bdb031f4f031),
make(s2, 16384 + i, 0xae267395a9bc1033, 0xb56b5800da1ba448));
}
}
// Check normalisation:
{
uint64_t a0 = 0xc6bab0a6afbef5ed;
uint64_t a1 = 0x4f84136c4a2e9b52;
int ee[] = { 0, 1, 10000 };
int e, i;
for (e = 0; e < sizeof(ee) / sizeof(*ee); e++) {
int exp = ee[e];
fsub(make(0, exp, a1, a0), make(0, 0, 0, 0));
for (i = 63; i >= 0; i--)
fsub(make(0, exp, a1 | (uint64_t)1 << i >> 1, a0),
make(0, exp, a1 >> i << i, 0));
for (i = 63; i >=0; i--)
fsub(make(0, exp, a1, a0 | (uint64_t)1 << i >> 1),
make(0, exp, a1, a0 >> i << i));
}
}
// Carry/overflow from rounding:
{
fadd(make(0, 114, -1, -1), make(0, 1, 0, 0));
fadd(make(0, 32766, -1, -1), make(0, 32653, 0, 0));
fsub(make(1, 32766, -1, -1), make(0, 32653, 0, 0));
}
}
void muls(void)
{
int i, j;
{
long double max = make(0, 32766, -1, -1);
long double min = make(0, 0, 0, 1);
fmul(max, max);
fmul(max, min);
fmul(min, min);
}
for (i = 117; i > 0; i--)
fmul(make(0, 16268, 0x643dcea76edc, 0xe0877a598403627a),
make(i & 1, i, 0, 0));
fmul(make(0, 16383, -1, -3), make(0, 16383, 0, 1));
// Round to next exponent:
fmul(make(0, 16383, -1, -2), make(0, 16383, 0, 1));
// Round from subnormal to normal:
fmul(make(0, 1, -1, -1), make(0, 16382, 0, 0));
for (i = 0; i < 2; i++)
for (j = 0; j < 112; j++)
fmul(make(0, 16383, (uint64_t)1 << i, 0),
make(0, 16383,
j < 64 ? 0 : (uint64_t)1 << (j - 64),
j < 64 ? (uint64_t)1 << j : 0));
}
void divs(void)
{
int i;
{
long double max = make(0, 32766, -1, -1);
long double min = make(0, 0, 0, 1);
fdiv(max, max);
fdiv(max, min);
fdiv(min, max);
fdiv(min, min);
}
for (i = 0; i < 64; i++)
fdiv(make(0, 16383, -1, -1), make(0, 16383, -1, -(uint64_t)1 << i));
for (i = 0; i < 48; i++)
fdiv(make(0, 16383, -1, -1), make(0, 16383, -(uint64_t)1 << i, 0));
}
void cvtlsw(int32_t a)
{
long double f = a;
u128_t x = copy_ild(f);
printf("cvtlsw %08lx %016llx%016llx\n", (long)(uint32_t)a, x.x1, x.x0);
}
void cvtlsx(int64_t a)
{
long double f = a;
u128_t x = copy_ild(f);
printf("cvtlsx %016llx %016llx%016llx\n",
(long long)(uint64_t)a, x.x1, x.x0);
}
void cvtluw(uint32_t a)
{
long double f = a;
u128_t x = copy_ild(f);
printf("cvtluw %08lx %016llx%016llx\n", (long)a, x.x1, x.x0);
}
void cvtlux(uint64_t a)
{
long double f = a;
u128_t x = copy_ild(f);
printf("cvtlux %016llx %016llx%016llx\n", (long long)a, x.x1, x.x0);
}
void cvtil(long double a)
{
u128_t x = copy_ild(a);
int32_t b1 = a;
int64_t b2 = a;
uint32_t b3 = a;
uint64_t b4 = a;
printf("cvtswl %016llx%016llx %08lx\n",
x.x1, x.x0, (long)(uint32_t)b1);
printf("cvtsxl %016llx%016llx %016llx\n",
x.x1, x.x0, (long long)(uint64_t)b2);
printf("cvtuwl %016llx%016llx %08lx\n",
x.x1, x.x0, (long)b3);
printf("cvtuxl %016llx%016llx %016llx\n",
x.x1, x.x0, (long long)b4);
}
void cvtlf(float a)
{
uint32_t ax = copy_if(a);
long double b = a;
u128_t bx = copy_ild(b);
printf("cvtlf %08lx %016llx%016llx\n", (long)ax, bx.x1, bx.x0);
}
void cvtld(double a)
{
uint64_t ax = copy_id(a);
long double b = a;
u128_t bx = copy_ild(b);
printf("cvtld %016llx %016llx%016llx\n", (long long)ax, bx.x1, bx.x0);
}
void cvtfl(long double a)
{
u128_t ax = copy_ild(a);
float b = a;
uint32_t bx = copy_if(b);
printf("cvtfl %016llx%016llx %08lx\n", ax.x1, ax.x0, (long)bx);
}
void cvtdl(long double a)
{
u128_t ax = copy_ild(a);
double b = a;
uint64_t bx = copy_id(b);
printf("cvtdl %016llx%016llx %016llx\n", ax.x1, ax.x0, (long long)bx);
}
void cvts(void)
{
int i, j;
{
uint32_t x = 0xad040c5b;
cvtlsw(0);
for (i = 0; i < 31; i++)
cvtlsw(x >> (31 - i));
for (i = 0; i < 31; i++)
cvtlsw(-(x >> (31 - i)));
cvtlsw(0x80000000);
}
{
uint64_t x = 0xb630a248cad9afd2;
cvtlsx(0);
for (i = 0; i < 63; i++)
cvtlsx(x >> (63 - i));
for (i = 0; i < 63; i++)
cvtlsx(-(x >> (63 - i)));
cvtlsx(0x8000000000000000);
}
{
uint32_t x = 0xad040c5b;
cvtluw(0);
for (i = 0; i < 32; i++)
cvtluw(x >> (31 - i));
}
{
uint64_t x = 0xb630a248cad9afd2;
cvtlux(0);
for (i = 0; i < 64; i++)
cvtlux(x >> (63 - i));
}
for (i = 0; i < 2; i++) {
cvtil(make(i, 32767, 0, 1));
cvtil(make(i, 32767, (uint64_t)1 << 47, 0));
cvtil(make(i, 32767, 123, 456));
cvtil(make(i, 32767, 0, 0));
cvtil(make(i, 16382, -1, -1));
cvtil(make(i, 16383, -1, -1));
cvtil(make(i, 16384, 0x7fffffffffff, -1));
cvtil(make(i, 16384, 0x800000000000, 0));
for (j = 0; j < 68; j++)
cvtil(make(i, 16381 + j, 0xd4822c0a10ec, 0x1fe2f8b2669f5c9d));
}
cvtlf(copy_fi(0x00000000));
cvtlf(copy_fi(0x456789ab));
cvtlf(copy_fi(0x7f800000));
cvtlf(copy_fi(0x7f923456));
cvtlf(copy_fi(0x7fdbcdef));
cvtlf(copy_fi(0x80000000));
cvtlf(copy_fi(0xabcdef12));
cvtlf(copy_fi(0xff800000));
cvtlf(copy_fi(0xff923456));
cvtlf(copy_fi(0xffdbcdef));
cvtld(copy_di(0x0000000000000000));
cvtld(copy_di(0x456789abcdef0123));
cvtld(copy_di(0x7ff0000000000000));
cvtld(copy_di(0x7ff123456789abcd));
cvtld(copy_di(0x7ffabcdef1234567));
cvtld(copy_di(0x8000000000000000));
cvtld(copy_di(0xcdef123456789abc));
cvtld(copy_di(0xfff0000000000000));
cvtld(copy_di(0xfff123456789abcd));
cvtld(copy_di(0xfffabcdef1234567));
for (i = 0; i < 2; i++) { \
cvtfl(make(i, 0, 0, 0));
cvtfl(make(i, 16232, -1, -1));
cvtfl(make(i, 16233, 0, 0));
cvtfl(make(i, 16233, 0, 1));
cvtfl(make(i, 16383, 0xab0ffd000000, 0));
cvtfl(make(i, 16383, 0xab0ffd000001, 0));
cvtfl(make(i, 16383, 0xab0ffeffffff, 0));
cvtfl(make(i, 16383, 0xab0fff000000, 0));
cvtfl(make(i, 16383, 0xab0fff000001, 0));
cvtfl(make(i, 16510, 0xfffffeffffff, -1));
cvtfl(make(i, 16510, 0xffffff000000, 0));
cvtfl(make(i, 16511, 0, 0));
cvtfl(make(i, 32767, 0, 0));
cvtfl(make(i, 32767, 0, 1));
cvtfl(make(i, 32767, 0x4cbe01ac5f40, 0x75cee3c6afbb00b5));
cvtfl(make(i, 32767, 0x800000000000, 1));
cvtfl(make(i, 32767, 0xa11caaaf6a52, 0x696033e871eab099));
}
for (i = 0; i < 2; i++) {
cvtdl(make(i, 0, 0, 0));
cvtdl(make(i, 15307, -1, -1));
cvtdl(make(i, 15308, 0, 0));
cvtdl(make(i, 15308, 0, 1));
cvtdl(make(i, 16383, 0xabc123abc0ff, 0xe800000000000000));
cvtdl(make(i, 16383, 0xabc123abc0ff, 0xe800000000000001));
cvtdl(make(i, 16383, 0xabc123abc0ff, 0xf7ffffffffffffff));
cvtdl(make(i, 16383, 0xabc123abc0ff, 0xf800000000000000));
cvtdl(make(i, 16383, 0xabc123abc0ff, 0xf800000000000001));
cvtdl(make(i, 17406, 0xffffffffffff, 0xf7ffffffffffffff));
cvtdl(make(i, 17406, 0xffffffffffff, 0xf800000000000000));
cvtdl(make(i, 17407, 0, 0));
cvtdl(make(i, 32767, 0, 0));
cvtdl(make(i, 32767, 0, 1));
cvtdl(make(i, 32767, 0x4cbe01ac5f40, 0x75cee3c6afbb00b5));
cvtdl(make(i, 32767, 0x800000000000, 1));
cvtdl(make(i, 32767, 0xa11caaaf6a52, 0x696033e871eab099));
}
}
void tests(void)
{
cmps();
nanz();
adds();
muls();
divs();
cvts();
}
int main()
{
#ifdef __aarch64__
tests();
#else
printf("This test program is intended for a little-endian architecture\n"
"with an IEEE-standard 128-bit long double.\n");
#endif
return 0;
}

2327
external/TCC/libtcc.c vendored

File diff suppressed because it is too large Load Diff

104
external/TCC/libtcc.h vendored
View File

@ -1,104 +0,0 @@
#ifndef LIBTCC_H
#define LIBTCC_H
#ifndef LIBTCCAPI
# define LIBTCCAPI
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct TCCState;
typedef struct TCCState TCCState;
/* create a new TCC compilation context */
LIBTCCAPI TCCState *tcc_new(void);
/* free a TCC compilation context */
LIBTCCAPI void tcc_delete(TCCState *s);
/* set CONFIG_TCCDIR at runtime */
LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
/* set error/warning display callback */
LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque,
void (*error_func)(void *opaque, const char *msg));
/* set options as from command line (multiple supported) */
LIBTCCAPI int tcc_set_options(TCCState *s, const char *str);
/*****************************/
/* preprocessor */
/* add include path */
LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
/* add in system include path */
LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
/* define preprocessor symbol 'sym'. Can put optional value */
LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
/* undefine preprocess symbol 'sym' */
LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym);
/*****************************/
/* compiling */
/* add a file (C file, dll, object, library, ld script). Return -1 if error. */
LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename, int filetype);
#define TCC_FILETYPE_BINARY 1
#define TCC_FILETYPE_C 2
#define TCC_FILETYPE_ASM 3
#define TCC_FILETYPE_ASM_PP 4
/* compile a string containing a C source. Return -1 if error. */
LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
/*****************************/
/* linking commands */
/* set output type. MUST BE CALLED before any compilation */
LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type);
#define TCC_OUTPUT_MEMORY 1 /* output will be run in memory (default) */
#define TCC_OUTPUT_EXE 2 /* executable file */
#define TCC_OUTPUT_DLL 3 /* dynamic library */
#define TCC_OUTPUT_OBJ 4 /* object file */
#define TCC_OUTPUT_PREPROCESS 5 /* only preprocess (used internally) */
/* equivalent to -Lpath option */
LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname);
/* the library name is the same as the argument of the '-l' option */
LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname);
/* add a symbol to the compiled program */
LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val);
/* output an executable, library or object file. DO NOT call
tcc_relocate() before. */
LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename);
/* link and run main() function and return its value. DO NOT call
tcc_relocate() before. */
LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv);
/* do all relocations (needed before using tcc_get_symbol()) */
LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr);
/* possible values for 'ptr':
- TCC_RELOCATE_AUTO : Allocate and manage memory internally
- NULL : return required memory size for the step below
- memory address : copy code to memory passed by the caller
returns -1 if error. */
#define TCC_RELOCATE_AUTO (void*)1
/* return symbol value or NULL if not found */
LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
#ifdef __cplusplus
}
#endif
#endif

234
external/TCC/stab.def vendored
View File

@ -1,234 +0,0 @@
/* Table of DBX symbol codes for the GNU system.
Copyright (C) 1988, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* This contains contribution from Cygnus Support. */
/* Global variable. Only the name is significant.
To find the address, look in the corresponding external symbol. */
__define_stab (N_GSYM, 0x20, "GSYM")
/* Function name for BSD Fortran. Only the name is significant.
To find the address, look in the corresponding external symbol. */
__define_stab (N_FNAME, 0x22, "FNAME")
/* Function name or text-segment variable for C. Value is its address.
Desc is supposedly starting line number, but GCC doesn't set it
and DBX seems not to miss it. */
__define_stab (N_FUN, 0x24, "FUN")
/* Data-segment variable with internal linkage. Value is its address.
"Static Sym". */
__define_stab (N_STSYM, 0x26, "STSYM")
/* BSS-segment variable with internal linkage. Value is its address. */
__define_stab (N_LCSYM, 0x28, "LCSYM")
/* Name of main routine. Only the name is significant.
This is not used in C. */
__define_stab (N_MAIN, 0x2a, "MAIN")
/* Global symbol in Pascal.
Supposedly the value is its line number; I'm skeptical. */
__define_stab (N_PC, 0x30, "PC")
/* Number of symbols: 0, files,,funcs,lines according to Ultrix V4.0. */
__define_stab (N_NSYMS, 0x32, "NSYMS")
/* "No DST map for sym: name, ,0,type,ignored" according to Ultrix V4.0. */
__define_stab (N_NOMAP, 0x34, "NOMAP")
/* New stab from Solaris. I don't know what it means, but it
don't seem to contain useful information. */
__define_stab (N_OBJ, 0x38, "OBJ")
/* New stab from Solaris. I don't know what it means, but it
don't seem to contain useful information. Possibly related to the
optimization flags used in this module. */
__define_stab (N_OPT, 0x3c, "OPT")
/* Register variable. Value is number of register. */
__define_stab (N_RSYM, 0x40, "RSYM")
/* Modula-2 compilation unit. Can someone say what info it contains? */
__define_stab (N_M2C, 0x42, "M2C")
/* Line number in text segment. Desc is the line number;
value is corresponding address. */
__define_stab (N_SLINE, 0x44, "SLINE")
/* Similar, for data segment. */
__define_stab (N_DSLINE, 0x46, "DSLINE")
/* Similar, for bss segment. */
__define_stab (N_BSLINE, 0x48, "BSLINE")
/* Sun's source-code browser stabs. ?? Don't know what the fields are.
Supposedly the field is "path to associated .cb file". THIS VALUE
OVERLAPS WITH N_BSLINE! */
__define_stab (N_BROWS, 0x48, "BROWS")
/* GNU Modula-2 definition module dependency. Value is the modification time
of the definition file. Other is non-zero if it is imported with the
GNU M2 keyword %INITIALIZE. Perhaps N_M2C can be used if there
are enough empty fields? */
__define_stab(N_DEFD, 0x4a, "DEFD")
/* THE FOLLOWING TWO STAB VALUES CONFLICT. Happily, one is for Modula-2
and one is for C++. Still,... */
/* GNU C++ exception variable. Name is variable name. */
__define_stab (N_EHDECL, 0x50, "EHDECL")
/* Modula2 info "for imc": name,,0,0,0 according to Ultrix V4.0. */
__define_stab (N_MOD2, 0x50, "MOD2")
/* GNU C++ `catch' clause. Value is its address. Desc is nonzero if
this entry is immediately followed by a CAUGHT stab saying what exception
was caught. Multiple CAUGHT stabs means that multiple exceptions
can be caught here. If Desc is 0, it means all exceptions are caught
here. */
__define_stab (N_CATCH, 0x54, "CATCH")
/* Structure or union element. Value is offset in the structure. */
__define_stab (N_SSYM, 0x60, "SSYM")
/* Name of main source file.
Value is starting text address of the compilation. */
__define_stab (N_SO, 0x64, "SO")
/* Automatic variable in the stack. Value is offset from frame pointer.
Also used for type descriptions. */
__define_stab (N_LSYM, 0x80, "LSYM")
/* Beginning of an include file. Only Sun uses this.
In an object file, only the name is significant.
The Sun linker puts data into some of the other fields. */
__define_stab (N_BINCL, 0x82, "BINCL")
/* Name of sub-source file (#include file).
Value is starting text address of the compilation. */
__define_stab (N_SOL, 0x84, "SOL")
/* Parameter variable. Value is offset from argument pointer.
(On most machines the argument pointer is the same as the frame pointer. */
__define_stab (N_PSYM, 0xa0, "PSYM")
/* End of an include file. No name.
This and N_BINCL act as brackets around the file's output.
In an object file, there is no significant data in this entry.
The Sun linker puts data into some of the fields. */
__define_stab (N_EINCL, 0xa2, "EINCL")
/* Alternate entry point. Value is its address. */
__define_stab (N_ENTRY, 0xa4, "ENTRY")
/* Beginning of lexical block.
The desc is the nesting level in lexical blocks.
The value is the address of the start of the text for the block.
The variables declared inside the block *precede* the N_LBRAC symbol. */
__define_stab (N_LBRAC, 0xc0, "LBRAC")
/* Place holder for deleted include file. Replaces a N_BINCL and everything
up to the corresponding N_EINCL. The Sun linker generates these when
it finds multiple identical copies of the symbols from an include file.
This appears only in output from the Sun linker. */
__define_stab (N_EXCL, 0xc2, "EXCL")
/* Modula-2 scope information. Can someone say what info it contains? */
__define_stab (N_SCOPE, 0xc4, "SCOPE")
/* End of a lexical block. Desc matches the N_LBRAC's desc.
The value is the address of the end of the text for the block. */
__define_stab (N_RBRAC, 0xe0, "RBRAC")
/* Begin named common block. Only the name is significant. */
__define_stab (N_BCOMM, 0xe2, "BCOMM")
/* End named common block. Only the name is significant
(and it should match the N_BCOMM). */
__define_stab (N_ECOMM, 0xe4, "ECOMM")
/* End common (local name): value is address.
I'm not sure how this is used. */
__define_stab (N_ECOML, 0xe8, "ECOML")
/* These STAB's are used on Gould systems for Non-Base register symbols
or something like that. FIXME. I have assigned the values at random
since I don't have a Gould here. Fixups from Gould folk welcome... */
__define_stab (N_NBTEXT, 0xF0, "NBTEXT")
__define_stab (N_NBDATA, 0xF2, "NBDATA")
__define_stab (N_NBBSS, 0xF4, "NBBSS")
__define_stab (N_NBSTS, 0xF6, "NBSTS")
__define_stab (N_NBLCS, 0xF8, "NBLCS")
/* Second symbol entry containing a length-value for the preceding entry.
The value is the length. */
__define_stab (N_LENG, 0xfe, "LENG")
/* The above information, in matrix format.
STAB MATRIX
_________________________________________________
| 00 - 1F are not dbx stab symbols |
| In most cases, the low bit is the EXTernal bit|
| 00 UNDEF | 02 ABS | 04 TEXT | 06 DATA |
| 01 |EXT | 03 |EXT | 05 |EXT | 07 |EXT |
| 08 BSS | 0A INDR | 0C FN_SEQ | 0E |
| 09 |EXT | 0B | 0D | 0F |
| 10 | 12 COMM | 14 SETA | 16 SETT |
| 11 | 13 | 15 | 17 |
| 18 SETD | 1A SETB | 1C SETV | 1E WARNING|
| 19 | 1B | 1D | 1F FN |
|_______________________________________________|
| Debug entries with bit 01 set are unused. |
| 20 GSYM | 22 FNAME | 24 FUN | 26 STSYM |
| 28 LCSYM | 2A MAIN | 2C | 2E |
| 30 PC | 32 NSYMS | 34 NOMAP | 36 |
| 38 OBJ | 3A | 3C OPT | 3E |
| 40 RSYM | 42 M2C | 44 SLINE | 46 DSLINE |
| 48 BSLINE*| 4A DEFD | 4C | 4E |
| 50 EHDECL*| 52 | 54 CATCH | 56 |
| 58 | 5A | 5C | 5E |
| 60 SSYM | 62 | 64 SO | 66 |
| 68 | 6A | 6C | 6E |
| 70 | 72 | 74 | 76 |
| 78 | 7A | 7C | 7E |
| 80 LSYM | 82 BINCL | 84 SOL | 86 |
| 88 | 8A | 8C | 8E |
| 90 | 92 | 94 | 96 |
| 98 | 9A | 9C | 9E |
| A0 PSYM | A2 EINCL | A4 ENTRY | A6 |
| A8 | AA | AC | AE |
| B0 | B2 | B4 | B6 |
| B8 | BA | BC | BE |
| C0 LBRAC | C2 EXCL | C4 SCOPE | C6 |
| C8 | CA | CC | CE |
| D0 | D2 | D4 | D6 |
| D8 | DA | DC | DE |
| E0 RBRAC | E2 BCOMM | E4 ECOMM | E6 |
| E8 ECOML | EA | EC | EE |
| F0 | F2 | F4 | F6 |
| F8 | FA | FC | FE LENG |
+-----------------------------------------------+
* 50 EHDECL is also MOD2.
* 48 BSLINE is also BROWS.
*/

17
external/TCC/stab.h vendored
View File

@ -1,17 +0,0 @@
#ifndef __GNU_STAB__
/* Indicate the GNU stab.h is in use. */
#define __GNU_STAB__
#define __define_stab(NAME, CODE, STRING) NAME=CODE,
enum __stab_debug_code
{
#include "stab.def"
LAST_UNUSED_STAB_CODE
};
#undef __define_stab
#endif /* __GNU_STAB_ */

367
external/TCC/tcc.c vendored
View File

@ -1,367 +0,0 @@
/*
* TCC - Tiny C Compiler
*
* Copyright (c) 2001-2004 Fabrice Bellard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef ONE_SOURCE
#include "libtcc.c"
#else
#include "tcc.h"
#endif
static void print_paths(const char *msg, char **paths, int nb_paths)
{
int i;
printf("%s:\n%s", msg, nb_paths ? "" : " -\n");
for(i = 0; i < nb_paths; i++)
printf(" %s\n", paths[i]);
}
static void display_info(TCCState *s, int what)
{
switch (what) {
case 0:
printf("tcc version %s ("
#ifdef TCC_TARGET_I386
"i386"
#elif defined TCC_TARGET_X86_64
"x86-64"
#elif defined TCC_TARGET_C67
"C67"
#elif defined TCC_TARGET_ARM
"ARM"
# ifdef TCC_ARM_HARDFLOAT
" Hard Float"
# endif
#elif defined TCC_TARGET_ARM64
"AArch64"
# ifdef TCC_ARM_HARDFLOAT
" Hard Float"
# endif
#endif
#ifdef TCC_TARGET_PE
" Windows"
#else
" Linux"
#endif
")\n", TCC_VERSION);
break;
case 1:
printf("install: %s\n", s->tcc_lib_path);
/* print_paths("programs", NULL, 0); */
print_paths("include", s->sysinclude_paths, s->nb_sysinclude_paths);
print_paths("libraries", s->library_paths, s->nb_library_paths);
#ifndef TCC_TARGET_PE
print_paths("crt", s->crt_paths, s->nb_crt_paths);
printf("elfinterp:\n %s\n", DEFAULT_ELFINTERP(s));
#endif
break;
}
}
static void help(void)
{
printf("Tiny C Compiler "TCC_VERSION" - Copyright (C) 2001-2006 Fabrice Bellard\n"
"Usage: tcc [options...] [-o outfile] [-c] infile(s)...\n"
" tcc [options...] -run infile [arguments...]\n"
"General options:\n"
" -c compile only - generate an object file\n"
" -o outfile set output filename\n"
" -run run compiled source\n"
" -fflag set or reset (with 'no-' prefix) 'flag' (see man page)\n"
" -Wwarning set or reset (with 'no-' prefix) 'warning' (see man page)\n"
" -w disable all warnings\n"
" -v show version\n"
" -vv show included files (as sole argument: show search paths)\n"
" -dumpversion\n"
" -bench show compilation statistics\n"
" -xc -xa specify type of the next infile\n"
" - use stdin pipe as infile\n"
"Preprocessor options:\n"
" -Idir add include path 'dir'\n"
" -Dsym[=val] define 'sym' with value 'val'\n"
" -Usym undefine 'sym'\n"
" -E preprocess only\n"
" -P[1] no/alternative output of #line directives with -E\n"
" -dD dump defines\n"
"Linker options:\n"
" -Ldir add library path 'dir'\n"
" -llib link with dynamic or static library 'lib'\n"
" -pthread link with -lpthread and -D_REENTRANT (POSIX Linux)\n"
" -r generate (relocatable) object file\n"
" -rdynamic export all global symbols to dynamic linker\n"
" -shared generate a shared library\n"
" -soname set name for shared library to be used at runtime\n"
" -static static linking\n"
" -Wl,-opt[=val] set linker option (see manual)\n"
"Debugger options:\n"
" -g generate runtime debug info\n"
#ifdef CONFIG_TCC_BCHECK
" -b compile with built-in memory and bounds checker (implies -g)\n"
#endif
#ifdef CONFIG_TCC_BACKTRACE
" -bt N show N callers in stack traces\n"
#endif
"Misc options:\n"
" -nostdinc do not use standard system include paths\n"
" -nostdlib do not link with standard crt and libraries\n"
" -Bdir use 'dir' as tcc internal library and include path\n"
" -MD generate target dependencies for make\n"
" -MF depfile put generated dependencies here\n"
);
}
/* re-execute the i386/x86_64 cross-compilers with tcc -m32/-m64: */
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
#ifdef _WIN32
#include <process.h>
static int execvp_win32(const char *prog, char **argv)
{
int ret = spawnvp(P_NOWAIT, prog, (const char *const*)argv);
if (-1 == ret)
return ret;
cwait(&ret, ret, WAIT_CHILD);
exit(ret);
}
#define execvp execvp_win32
#endif
static void exec_other_tcc(TCCState *s, char **argv, const char *optarg)
{
char child_path[4096], *child_name; const char *target;
switch (atoi(optarg)) {
#ifdef TCC_TARGET_I386
case 32: break;
case 64: target = "x86_64";
#else
case 64: break;
case 32: target = "i386";
#endif
pstrcpy(child_path, sizeof child_path - 40, argv[0]);
child_name = tcc_basename(child_path);
strcpy(child_name, target);
#ifdef TCC_TARGET_PE
strcat(child_name, "-win32");
#endif
strcat(child_name, "-tcc");
if (strcmp(argv[0], child_path)) {
if (s->verbose > 0)
printf("tcc: using '%s'\n", child_name), fflush(stdout);
execvp(argv[0] = child_path, argv);
}
tcc_error("'%s' not found", child_name);
case 0: /* ignore -march etc. */
break;
default:
tcc_warning("unsupported option \"-m%s\"", optarg);
}
}
#else
#define exec_other_tcc(s, argv, optarg)
#endif
static void gen_makedeps(TCCState *s, const char *target, const char *filename)
{
FILE *depout;
char buf[1024], *ext;
int i;
if (!filename) {
/* compute filename automatically
* dir/file.o -> dir/file.d */
pstrcpy(buf, sizeof(buf), target);
ext = tcc_fileextension(buf);
pstrcpy(ext, sizeof(buf) - (ext-buf), ".d");
filename = buf;
}
if (s->verbose)
printf("<- %s\n", filename);
/* XXX return err codes instead of error() ? */
depout = fopen(filename, "w");
if (!depout)
tcc_error("could not open '%s'", filename);
fprintf(depout, "%s : \\\n", target);
for (i=0; i<s->nb_target_deps; ++i)
fprintf(depout, " %s \\\n", s->target_deps[i]);
fprintf(depout, "\n");
fclose(depout);
}
static char *default_outputfile(TCCState *s, const char *first_file)
{
char buf[1024];
char *ext;
const char *name = "a";
if (first_file && strcmp(first_file, "-"))
name = tcc_basename(first_file);
pstrcpy(buf, sizeof(buf), name);
ext = tcc_fileextension(buf);
#ifdef TCC_TARGET_PE
if (s->output_type == TCC_OUTPUT_DLL)
strcpy(ext, ".dll");
else
if (s->output_type == TCC_OUTPUT_EXE)
strcpy(ext, ".exe");
else
#endif
if (( (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) ||
(s->output_type == TCC_OUTPUT_PREPROCESS) )
&& *ext)
strcpy(ext, ".o");
else
strcpy(buf, "a.out");
return tcc_strdup(buf);
}
static int64_t getclock_us(void)
{
#ifdef _WIN32
struct _timeb tb;
_ftime(&tb);
return (tb.time * 1000LL + tb.millitm) * 1000LL;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000000LL + tv.tv_usec;
#endif
}
int main(int argc, char **argv)
{
TCCState *s;
int ret, optind, i;
int64_t start_time = 0;
s = tcc_new();
optind = tcc_parse_args(s, argc - 1, argv + 1);
if (s->do_bench)
start_time = getclock_us();
tcc_set_environment(s);
if (optind == 0) {
help();
return 1;
}
if (s->option_m)
exec_other_tcc(s, argv, s->option_m);
if (s->verbose)
display_info(s, 0);
if (s->print_search_dirs || (s->verbose == 2 && optind == 1)) {
tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
display_info(s, 1);
return 0;
}
if (s->verbose && optind == 1)
return 0;
if (s->nb_files == 0)
tcc_error("no input files\n");
/* check -c consistency : only single file handled. XXX: checks file type */
if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) {
if (s->nb_libraries != 0)
tcc_error("cannot specify libraries with -c");
/* accepts only a single input file */
if ((s->nb_files != 1) && s->outfile) {
tcc_error("cannot specify multiple files with -c and -o");
}
}
if (s->output_type == TCC_OUTPUT_PREPROCESS) {
if (!s->outfile) {
s->ppfp = stdout;
} else {
s->ppfp = fopen(s->outfile, "w");
if (!s->ppfp)
tcc_error("could not write '%s'", s->outfile);
}
}
tcc_set_output_type(s, s->output_type);
/* compile or add each files or library */
for(i = ret = 0; i < s->nb_files && ret == 0; i++) {
int filetype = *(unsigned char *)s->files[i];
const char *filename = s->files[i] + 1;
if (filename[0] == '-' && filename[1] == 'l') {
if (tcc_add_library(s, filename + 2) < 0) {
tcc_error_noabort("cannot find library 'lib%s'", filename+2);
ret = 1;
}
} else {
if (1 == s->verbose)
printf("-> %s\n", filename);
if (!s->outfile)
s->outfile = default_outputfile(s, filename);
if (tcc_add_file(s, filename, filetype) < 0)
ret = 1;
else
if (s->output_type == TCC_OUTPUT_OBJ) {
ret = !!tcc_output_file(s, s->outfile);
if (s->gen_deps && !ret)
gen_makedeps(s, s->outfile, s->deps_outfile);
if (!ret) {
if ((i+1) < s->nb_files) {
tcc_delete(s);
s = tcc_new();
tcc_parse_args(s, argc - 1, argv + 1);
tcc_set_environment(s);
if (s->output_type != TCC_OUTPUT_OBJ)
tcc_error("interlnal error");
tcc_set_output_type(s, s->output_type);
}
}
}
}
}
if (0 == ret) {
if (s->output_type == TCC_OUTPUT_MEMORY) {
#ifdef TCC_IS_NATIVE
ret = tcc_run(s, argc - 1 - optind, argv + 1 + optind);
#else
tcc_error_noabort("-run is not available in a cross compiler");
ret = 1;
#endif
} else
if (s->output_type == TCC_OUTPUT_EXE ||
s->output_type == TCC_OUTPUT_DLL)
{
ret = !!tcc_output_file(s, s->outfile);
if (s->gen_deps && !ret)
gen_makedeps(s, s->outfile, s->deps_outfile);
}
}
if (s->do_bench)
tcc_print_stats(s, getclock_us() - start_time);
tcc_delete(s);
return ret;
}

1540
external/TCC/tcc.h vendored

File diff suppressed because it is too large Load Diff

1138
external/TCC/tccasm.c vendored

File diff suppressed because it is too large Load Diff

948
external/TCC/tcccoff.c vendored
View File

@ -1,948 +0,0 @@
/*
* COFF file handling for TCC
*
* Copyright (c) 2003, 2004 TK
* Copyright (c) 2004 Fabrice Bellard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "tcc.h"
#define MAXNSCNS 255 /* MAXIMUM NUMBER OF SECTIONS */
#define MAX_STR_TABLE 1000000
AOUTHDR o_filehdr; /* OPTIONAL (A.OUT) FILE HEADER */
SCNHDR section_header[MAXNSCNS];
#define MAX_FUNCS 1000
#define MAX_FUNC_NAME_LENGTH 128
int nFuncs;
char Func[MAX_FUNCS][MAX_FUNC_NAME_LENGTH];
char AssociatedFile[MAX_FUNCS][MAX_FUNC_NAME_LENGTH];
int LineNoFilePtr[MAX_FUNCS];
int EndAddress[MAX_FUNCS];
int LastLineNo[MAX_FUNCS];
int FuncEntries[MAX_FUNCS];
int OutputTheSection(Section * sect);
short int GetCoffFlags(const char *s);
void SortSymbolTable(void);
Section *FindSection(TCCState * s1, const char *sname);
int C67_main_entry_point;
int FindCoffSymbolIndex(const char *func_name);
int nb_syms;
typedef struct {
long tag;
long size;
long fileptr;
long nextsym;
short int dummy;
} AUXFUNC;
typedef struct {
long regmask;
unsigned short lineno;
unsigned short nentries;
int localframe;
int nextentry;
short int dummy;
} AUXBF;
typedef struct {
long dummy;
unsigned short lineno;
unsigned short dummy1;
int dummy2;
int dummy3;
unsigned short dummy4;
} AUXEF;
ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f)
{
Section *tcc_sect;
SCNHDR *coff_sec;
int file_pointer;
char *Coff_str_table, *pCoff_str_table;
int CoffTextSectionNo, coff_nb_syms;
FILHDR file_hdr; /* FILE HEADER STRUCTURE */
Section *stext, *sdata, *sbss;
int i, NSectionsToOutput = 0;
Coff_str_table = pCoff_str_table = NULL;
stext = FindSection(s1, ".text");
sdata = FindSection(s1, ".data");
sbss = FindSection(s1, ".bss");
nb_syms = symtab_section->data_offset / sizeof(Elf32_Sym);
coff_nb_syms = FindCoffSymbolIndex("XXXXXXXXXX1");
file_hdr.f_magic = COFF_C67_MAGIC; /* magic number */
file_hdr.f_timdat = 0; /* time & date stamp */
file_hdr.f_opthdr = sizeof(AOUTHDR); /* sizeof(optional hdr) */
file_hdr.f_flags = 0x1143; /* flags (copied from what code composer does) */
file_hdr.f_TargetID = 0x99; /* for C6x = 0x0099 */
o_filehdr.magic = 0x0108; /* see magic.h */
o_filehdr.vstamp = 0x0190; /* version stamp */
o_filehdr.tsize = stext->data_offset; /* text size in bytes, padded to FW bdry */
o_filehdr.dsize = sdata->data_offset; /* initialized data " " */
o_filehdr.bsize = sbss->data_offset; /* uninitialized data " " */
o_filehdr.entrypt = C67_main_entry_point; /* entry pt. */
o_filehdr.text_start = stext->sh_addr; /* base of text used for this file */
o_filehdr.data_start = sdata->sh_addr; /* base of data used for this file */
// create all the section headers
file_pointer = FILHSZ + sizeof(AOUTHDR);
CoffTextSectionNo = -1;
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
NSectionsToOutput++;
if (CoffTextSectionNo == -1 && tcc_sect == stext)
CoffTextSectionNo = NSectionsToOutput; // rem which coff sect number the .text sect is
strcpy(coff_sec->s_name, tcc_sect->name); /* section name */
coff_sec->s_paddr = tcc_sect->sh_addr; /* physical address */
coff_sec->s_vaddr = tcc_sect->sh_addr; /* virtual address */
coff_sec->s_size = tcc_sect->data_offset; /* section size */
coff_sec->s_scnptr = 0; /* file ptr to raw data for section */
coff_sec->s_relptr = 0; /* file ptr to relocation */
coff_sec->s_lnnoptr = 0; /* file ptr to line numbers */
coff_sec->s_nreloc = 0; /* number of relocation entries */
coff_sec->s_flags = GetCoffFlags(coff_sec->s_name); /* flags */
coff_sec->s_reserved = 0; /* reserved byte */
coff_sec->s_page = 0; /* memory page id */
file_pointer += sizeof(SCNHDR);
}
}
file_hdr.f_nscns = NSectionsToOutput; /* number of sections */
// now loop through and determine file pointer locations
// for the raw data
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
// put raw data
coff_sec->s_scnptr = file_pointer; /* file ptr to raw data for section */
file_pointer += coff_sec->s_size;
}
}
// now loop through and determine file pointer locations
// for the relocation data
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
// put relocations data
if (coff_sec->s_nreloc > 0) {
coff_sec->s_relptr = file_pointer; /* file ptr to relocation */
file_pointer += coff_sec->s_nreloc * sizeof(struct reloc);
}
}
}
// now loop through and determine file pointer locations
// for the line number data
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
coff_sec->s_nlnno = 0;
coff_sec->s_lnnoptr = 0;
if (s1->do_debug && tcc_sect == stext) {
// count how many line nos data
// also find association between source file name and function
// so we can sort the symbol table
Stab_Sym *sym, *sym_end;
char func_name[MAX_FUNC_NAME_LENGTH],
last_func_name[MAX_FUNC_NAME_LENGTH];
unsigned long func_addr, last_pc, pc;
const char *incl_files[INCLUDE_STACK_SIZE];
int incl_index, len, last_line_num;
const char *str, *p;
coff_sec->s_lnnoptr = file_pointer; /* file ptr to linno */
func_name[0] = '\0';
func_addr = 0;
incl_index = 0;
last_func_name[0] = '\0';
last_pc = 0xffffffff;
last_line_num = 1;
sym = (Stab_Sym *) stab_section->data + 1;
sym_end =
(Stab_Sym *) (stab_section->data +
stab_section->data_offset);
nFuncs = 0;
while (sym < sym_end) {
switch (sym->n_type) {
/* function start or end */
case N_FUN:
if (sym->n_strx == 0) {
// end of function
coff_sec->s_nlnno++;
file_pointer += LINESZ;
pc = sym->n_value + func_addr;
func_name[0] = '\0';
func_addr = 0;
EndAddress[nFuncs] = pc;
FuncEntries[nFuncs] =
(file_pointer -
LineNoFilePtr[nFuncs]) / LINESZ - 1;
LastLineNo[nFuncs++] = last_line_num + 1;
} else {
// beginning of function
LineNoFilePtr[nFuncs] = file_pointer;
coff_sec->s_nlnno++;
file_pointer += LINESZ;
str =
(const char *) stabstr_section->data +
sym->n_strx;
p = strchr(str, ':');
if (!p) {
pstrcpy(func_name, sizeof(func_name), str);
pstrcpy(Func[nFuncs], sizeof(func_name), str);
} else {
len = p - str;
if (len > sizeof(func_name) - 1)
len = sizeof(func_name) - 1;
memcpy(func_name, str, len);
memcpy(Func[nFuncs], str, len);
func_name[len] = '\0';
}
// save the file that it came in so we can sort later
pstrcpy(AssociatedFile[nFuncs], sizeof(func_name),
incl_files[incl_index - 1]);
func_addr = sym->n_value;
}
break;
/* line number info */
case N_SLINE:
pc = sym->n_value + func_addr;
last_pc = pc;
last_line_num = sym->n_desc;
/* XXX: slow! */
strcpy(last_func_name, func_name);
coff_sec->s_nlnno++;
file_pointer += LINESZ;
break;
/* include files */
case N_BINCL:
str =
(const char *) stabstr_section->data + sym->n_strx;
add_incl:
if (incl_index < INCLUDE_STACK_SIZE) {
incl_files[incl_index++] = str;
}
break;
case N_EINCL:
if (incl_index > 1)
incl_index--;
break;
case N_SO:
if (sym->n_strx == 0) {
incl_index = 0; /* end of translation unit */
} else {
str =
(const char *) stabstr_section->data +
sym->n_strx;
/* do not add path */
len = strlen(str);
if (len > 0 && str[len - 1] != '/')
goto add_incl;
}
break;
}
sym++;
}
}
}
file_hdr.f_symptr = file_pointer; /* file pointer to symtab */
if (s1->do_debug)
file_hdr.f_nsyms = coff_nb_syms; /* number of symtab entries */
else
file_hdr.f_nsyms = 0;
file_pointer += file_hdr.f_nsyms * SYMNMLEN;
// OK now we are all set to write the file
fwrite(&file_hdr, FILHSZ, 1, f);
fwrite(&o_filehdr, sizeof(o_filehdr), 1, f);
// write section headers
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
fwrite(coff_sec, sizeof(SCNHDR), 1, f);
}
}
// write raw data
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
fwrite(tcc_sect->data, tcc_sect->data_offset, 1, f);
}
}
// write relocation data
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
// put relocations data
if (coff_sec->s_nreloc > 0) {
fwrite(tcc_sect->reloc,
coff_sec->s_nreloc * sizeof(struct reloc), 1, f);
}
}
}
// group the symbols in order of filename, func1, func2, etc
// finally global symbols
if (s1->do_debug)
SortSymbolTable();
// write line no data
for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
tcc_sect = s1->sections[i];
if (s1->do_debug && tcc_sect == stext) {
// count how many line nos data
Stab_Sym *sym, *sym_end;
char func_name[128], last_func_name[128];
unsigned long func_addr, last_pc, pc;
const char *incl_files[INCLUDE_STACK_SIZE];
int incl_index, len, last_line_num;
const char *str, *p;
LINENO CoffLineNo;
func_name[0] = '\0';
func_addr = 0;
incl_index = 0;
last_func_name[0] = '\0';
last_pc = 0;
last_line_num = 1;
sym = (Stab_Sym *) stab_section->data + 1;
sym_end =
(Stab_Sym *) (stab_section->data +
stab_section->data_offset);
while (sym < sym_end) {
switch (sym->n_type) {
/* function start or end */
case N_FUN:
if (sym->n_strx == 0) {
// end of function
CoffLineNo.l_addr.l_paddr = last_pc;
CoffLineNo.l_lnno = last_line_num + 1;
fwrite(&CoffLineNo, 6, 1, f);
pc = sym->n_value + func_addr;
func_name[0] = '\0';
func_addr = 0;
} else {
// beginning of function
str =
(const char *) stabstr_section->data +
sym->n_strx;
p = strchr(str, ':');
if (!p) {
pstrcpy(func_name, sizeof(func_name), str);
} else {
len = p - str;
if (len > sizeof(func_name) - 1)
len = sizeof(func_name) - 1;
memcpy(func_name, str, len);
func_name[len] = '\0';
}
func_addr = sym->n_value;
last_pc = func_addr;
last_line_num = -1;
// output a function begin
CoffLineNo.l_addr.l_symndx =
FindCoffSymbolIndex(func_name);
CoffLineNo.l_lnno = 0;
fwrite(&CoffLineNo, 6, 1, f);
}
break;
/* line number info */
case N_SLINE:
pc = sym->n_value + func_addr;
/* XXX: slow! */
strcpy(last_func_name, func_name);
// output a line reference
CoffLineNo.l_addr.l_paddr = last_pc;
if (last_line_num == -1) {
CoffLineNo.l_lnno = sym->n_desc;
} else {
CoffLineNo.l_lnno = last_line_num + 1;
}
fwrite(&CoffLineNo, 6, 1, f);
last_pc = pc;
last_line_num = sym->n_desc;
break;
/* include files */
case N_BINCL:
str =
(const char *) stabstr_section->data + sym->n_strx;
add_incl2:
if (incl_index < INCLUDE_STACK_SIZE) {
incl_files[incl_index++] = str;
}
break;
case N_EINCL:
if (incl_index > 1)
incl_index--;
break;
case N_SO:
if (sym->n_strx == 0) {
incl_index = 0; /* end of translation unit */
} else {
str =
(const char *) stabstr_section->data +
sym->n_strx;
/* do not add path */
len = strlen(str);
if (len > 0 && str[len - 1] != '/')
goto add_incl2;
}
break;
}
sym++;
}
}
}
// write symbol table
if (s1->do_debug) {
int k;
struct syment csym;
AUXFUNC auxfunc;
AUXBF auxbf;
AUXEF auxef;
int i;
Elf32_Sym *p;
const char *name;
int nstr;
int n = 0;
Coff_str_table = (char *) tcc_malloc(MAX_STR_TABLE);
pCoff_str_table = Coff_str_table;
nstr = 0;
p = (Elf32_Sym *) symtab_section->data;
for (i = 0; i < nb_syms; i++) {
name = symtab_section->link->data + p->st_name;
for (k = 0; k < 8; k++)
csym._n._n_name[k] = 0;
if (strlen(name) <= 8) {
strcpy(csym._n._n_name, name);
} else {
if (pCoff_str_table - Coff_str_table + strlen(name) >
MAX_STR_TABLE - 1)
tcc_error("String table too large");
csym._n._n_n._n_zeroes = 0;
csym._n._n_n._n_offset =
pCoff_str_table - Coff_str_table + 4;
strcpy(pCoff_str_table, name);
pCoff_str_table += strlen(name) + 1; // skip over null
nstr++;
}
if (p->st_info == 4) {
// put a filename symbol
csym.n_value = 33; // ?????
csym.n_scnum = N_DEBUG;
csym.n_type = 0;
csym.n_sclass = C_FILE;
csym.n_numaux = 0;
fwrite(&csym, 18, 1, f);
n++;
} else if (p->st_info == 0x12) {
// find the function data
for (k = 0; k < nFuncs; k++) {
if (strcmp(name, Func[k]) == 0)
break;
}
if (k >= nFuncs) {
tcc_error("debug info can't find function: %s", name);
}
// put a Function Name
csym.n_value = p->st_value; // physical address
csym.n_scnum = CoffTextSectionNo;
csym.n_type = MKTYPE(T_INT, DT_FCN, 0, 0, 0, 0, 0);
csym.n_sclass = C_EXT;
csym.n_numaux = 1;
fwrite(&csym, 18, 1, f);
// now put aux info
auxfunc.tag = 0;
auxfunc.size = EndAddress[k] - p->st_value;
auxfunc.fileptr = LineNoFilePtr[k];
auxfunc.nextsym = n + 6; // tktk
auxfunc.dummy = 0;
fwrite(&auxfunc, 18, 1, f);
// put a .bf
strcpy(csym._n._n_name, ".bf");
csym.n_value = p->st_value; // physical address
csym.n_scnum = CoffTextSectionNo;
csym.n_type = 0;
csym.n_sclass = C_FCN;
csym.n_numaux = 1;
fwrite(&csym, 18, 1, f);
// now put aux info
auxbf.regmask = 0;
auxbf.lineno = 0;
auxbf.nentries = FuncEntries[k];
auxbf.localframe = 0;
auxbf.nextentry = n + 6;
auxbf.dummy = 0;
fwrite(&auxbf, 18, 1, f);
// put a .ef
strcpy(csym._n._n_name, ".ef");
csym.n_value = EndAddress[k]; // physical address
csym.n_scnum = CoffTextSectionNo;
csym.n_type = 0;
csym.n_sclass = C_FCN;
csym.n_numaux = 1;
fwrite(&csym, 18, 1, f);
// now put aux info
auxef.dummy = 0;
auxef.lineno = LastLineNo[k];
auxef.dummy1 = 0;
auxef.dummy2 = 0;
auxef.dummy3 = 0;
auxef.dummy4 = 0;
fwrite(&auxef, 18, 1, f);
n += 6;
} else {
// try an put some type info
if ((p->st_other & VT_BTYPE) == VT_DOUBLE) {
csym.n_type = T_DOUBLE; // int
csym.n_sclass = C_EXT;
} else if ((p->st_other & VT_BTYPE) == VT_FLOAT) {
csym.n_type = T_FLOAT;
csym.n_sclass = C_EXT;
} else if ((p->st_other & VT_BTYPE) == VT_INT) {
csym.n_type = T_INT; // int
csym.n_sclass = C_EXT;
} else if ((p->st_other & VT_BTYPE) == VT_SHORT) {
csym.n_type = T_SHORT;
csym.n_sclass = C_EXT;
} else if ((p->st_other & VT_BTYPE) == VT_BYTE) {
csym.n_type = T_CHAR;
csym.n_sclass = C_EXT;
} else {
csym.n_type = T_INT; // just mark as a label
csym.n_sclass = C_LABEL;
}
csym.n_value = p->st_value;
csym.n_scnum = 2;
csym.n_numaux = 1;
fwrite(&csym, 18, 1, f);
auxfunc.tag = 0;
auxfunc.size = 0x20;
auxfunc.fileptr = 0;
auxfunc.nextsym = 0;
auxfunc.dummy = 0;
fwrite(&auxfunc, 18, 1, f);
n++;
n++;
}
p++;
}
}
if (s1->do_debug) {
// write string table
// first write the size
i = pCoff_str_table - Coff_str_table;
fwrite(&i, 4, 1, f);
// then write the strings
fwrite(Coff_str_table, i, 1, f);
tcc_free(Coff_str_table);
}
return 0;
}
// group the symbols in order of filename, func1, func2, etc
// finally global symbols
void SortSymbolTable(void)
{
int i, j, k, n = 0;
Elf32_Sym *p, *p2, *NewTable;
char *name, *name2;
NewTable = (Elf32_Sym *) tcc_malloc(nb_syms * sizeof(Elf32_Sym));
p = (Elf32_Sym *) symtab_section->data;
// find a file symbol, copy it over
// then scan the whole symbol list and copy any function
// symbols that match the file association
for (i = 0; i < nb_syms; i++) {
if (p->st_info == 4) {
name = (char *) symtab_section->link->data + p->st_name;
// this is a file symbol, copy it over
NewTable[n++] = *p;
p2 = (Elf32_Sym *) symtab_section->data;
for (j = 0; j < nb_syms; j++) {
if (p2->st_info == 0x12) {
// this is a func symbol
name2 =
(char *) symtab_section->link->data + p2->st_name;
// find the function data index
for (k = 0; k < nFuncs; k++) {
if (strcmp(name2, Func[k]) == 0)
break;
}
if (k >= nFuncs) {
tcc_error("debug (sort) info can't find function: %s", name2);
}
if (strcmp(AssociatedFile[k], name) == 0) {
// yes they match copy it over
NewTable[n++] = *p2;
}
}
p2++;
}
}
p++;
}
// now all the filename and func symbols should have been copied over
// copy all the rest over (all except file and funcs)
p = (Elf32_Sym *) symtab_section->data;
for (i = 0; i < nb_syms; i++) {
if (p->st_info != 4 && p->st_info != 0x12) {
NewTable[n++] = *p;
}
p++;
}
if (n != nb_syms)
tcc_error("Internal Compiler error, debug info");
// copy it all back
p = (Elf32_Sym *) symtab_section->data;
for (i = 0; i < nb_syms; i++) {
*p++ = NewTable[i];
}
tcc_free(NewTable);
}
int FindCoffSymbolIndex(const char *func_name)
{
int i, n = 0;
Elf32_Sym *p;
char *name;
p = (Elf32_Sym *) symtab_section->data;
for (i = 0; i < nb_syms; i++) {
name = (char *) symtab_section->link->data + p->st_name;
if (p->st_info == 4) {
// put a filename symbol
n++;
} else if (p->st_info == 0x12) {
if (strcmp(func_name, name) == 0)
return n;
n += 6;
// put a Function Name
// now put aux info
// put a .bf
// now put aux info
// put a .ef
// now put aux info
} else {
n += 2;
}
p++;
}
return n; // total number of symbols
}
int OutputTheSection(Section * sect)
{
const char *s = sect->name;
if (!strcmp(s, ".text"))
return 1;
else if (!strcmp(s, ".data"))
return 1;
else
return 0;
}
short int GetCoffFlags(const char *s)
{
if (!strcmp(s, ".text"))
return STYP_TEXT | STYP_DATA | STYP_ALIGN | 0x400;
else if (!strcmp(s, ".data"))
return STYP_DATA;
else if (!strcmp(s, ".bss"))
return STYP_BSS;
else if (!strcmp(s, ".stack"))
return STYP_BSS | STYP_ALIGN | 0x200;
else if (!strcmp(s, ".cinit"))
return STYP_COPY | STYP_DATA | STYP_ALIGN | 0x200;
else
return 0;
}
Section *FindSection(TCCState * s1, const char *sname)
{
Section *s;
int i;
for (i = 1; i < s1->nb_sections; i++) {
s = s1->sections[i];
if (!strcmp(sname, s->name))
return s;
}
tcc_error("could not find section %s", sname);
return 0;
}
ST_FUNC int tcc_load_coff(TCCState * s1, int fd)
{
// tktk TokenSym *ts;
FILE *f;
unsigned int str_size;
char *Coff_str_table, *name;
int i, k;
struct syment csym;
char name2[9];
FILHDR file_hdr; /* FILE HEADER STRUCTURE */
f = fdopen(fd, "rb");
if (!f) {
tcc_error("Unable to open .out file for input");
}
if (fread(&file_hdr, FILHSZ, 1, f) != 1)
tcc_error("error reading .out file for input");
if (fread(&o_filehdr, sizeof(o_filehdr), 1, f) != 1)
tcc_error("error reading .out file for input");
// first read the string table
if (fseek(f, file_hdr.f_symptr + file_hdr.f_nsyms * SYMESZ, SEEK_SET))
tcc_error("error reading .out file for input");
if (fread(&str_size, sizeof(int), 1, f) != 1)
tcc_error("error reading .out file for input");
Coff_str_table = (char *) tcc_malloc(str_size);
if (fread(Coff_str_table, str_size - 4, 1, f) != 1)
tcc_error("error reading .out file for input");
// read/process all the symbols
// seek back to symbols
if (fseek(f, file_hdr.f_symptr, SEEK_SET))
tcc_error("error reading .out file for input");
for (i = 0; i < file_hdr.f_nsyms; i++) {
if (fread(&csym, SYMESZ, 1, f) != 1)
tcc_error("error reading .out file for input");
if (csym._n._n_n._n_zeroes == 0) {
name = Coff_str_table + csym._n._n_n._n_offset - 4;
} else {
name = csym._n._n_name;
if (name[7] != 0) {
for (k = 0; k < 8; k++)
name2[k] = name[k];
name2[8] = 0;
name = name2;
}
}
// if (strcmp("_DAC_Buffer",name)==0) // tktk
// name[0]=0;
if (((csym.n_type & 0x30) == 0x20 && csym.n_sclass == 0x2) || ((csym.n_type & 0x30) == 0x30 && csym.n_sclass == 0x2) || (csym.n_type == 0x4 && csym.n_sclass == 0x2) || (csym.n_type == 0x8 && csym.n_sclass == 0x2) || // structures
(csym.n_type == 0x18 && csym.n_sclass == 0x2) || // pointer to structure
(csym.n_type == 0x7 && csym.n_sclass == 0x2) || // doubles
(csym.n_type == 0x6 && csym.n_sclass == 0x2)) // floats
{
// strip off any leading underscore (except for other main routine)
if (name[0] == '_' && strcmp(name, "_main") != 0)
name++;
tcc_add_symbol(s1, name, (void*)(uintptr_t)csym.n_value);
}
// skip any aux records
if (csym.n_numaux == 1) {
if (fread(&csym, SYMESZ, 1, f) != 1)
tcc_error("error reading .out file for input");
i++;
}
}
return 0;
}

3512
external/TCC/tccelf.c vendored

File diff suppressed because it is too large Load Diff

6454
external/TCC/tccgen.c vendored

File diff suppressed because it is too large Load Diff

80
external/TCC/tcclib.h vendored
View File

@ -1,80 +0,0 @@
/* Simple libc header for TCC
*
* Add any function you want from the libc there. This file is here
* only for your convenience so that you do not need to put the whole
* glibc include files on your floppy disk
*/
#ifndef _TCCLIB_H
#define _TCCLIB_H
#include <stddef.h>
#include <stdarg.h>
/* stdlib.h */
void *calloc(size_t nmemb, size_t size);
void *malloc(size_t size);
void free(void *ptr);
void *realloc(void *ptr, size_t size);
int atoi(const char *nptr);
long int strtol(const char *nptr, char **endptr, int base);
unsigned long int strtoul(const char *nptr, char **endptr, int base);
void exit(int);
/* stdio.h */
typedef struct __FILE FILE;
#define EOF (-1)
extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;
FILE *fopen(const char *path, const char *mode);
FILE *fdopen(int fildes, const char *mode);
FILE *freopen(const char *path, const char *mode, FILE *stream);
int fclose(FILE *stream);
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream);
int fgetc(FILE *stream);
char *fgets(char *s, int size, FILE *stream);
int getc(FILE *stream);
int getchar(void);
char *gets(char *s);
int ungetc(int c, FILE *stream);
int fflush(FILE *stream);
int putchar (int c);
int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int sprintf(char *str, const char *format, ...);
int snprintf(char *str, size_t size, const char *format, ...);
int asprintf(char **strp, const char *format, ...);
int dprintf(int fd, const char *format, ...);
int vprintf(const char *format, va_list ap);
int vfprintf(FILE *stream, const char *format, va_list ap);
int vsprintf(char *str, const char *format, va_list ap);
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
int vasprintf(char **strp, const char *format, va_list ap);
int vdprintf(int fd, const char *format, va_list ap);
void perror(const char *s);
/* string.h */
char *strcat(char *dest, const char *src);
char *strchr(const char *s, int c);
char *strrchr(const char *s, int c);
char *strcpy(char *dest, const char *src);
void *memcpy(void *dest, const void *src, size_t n);
void *memmove(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
char *strdup(const char *s);
size_t strlen(const char *s);
/* dlfcn.h */
#define RTLD_LAZY 0x001
#define RTLD_NOW 0x002
#define RTLD_GLOBAL 0x100
void *dlopen(const char *filename, int flag);
const char *dlerror(void);
void *dlsym(void *handle, char *symbol);
int dlclose(void *handle);
#endif /* _TCCLIB_H */

1890
external/TCC/tccpe.c vendored

File diff suppressed because it is too large Load Diff

3460
external/TCC/tccpp.c vendored

File diff suppressed because it is too large Load Diff

772
external/TCC/tccrun.c vendored
View File

@ -1,772 +0,0 @@
/*
* TCC - Tiny C Compiler - Support for -run switch
*
* Copyright (c) 2001-2004 Fabrice Bellard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "tcc.h"
/* only native compiler supports -run */
#ifdef TCC_IS_NATIVE
#ifdef CONFIG_TCC_BACKTRACE
ST_DATA int rt_num_callers = 6;
ST_DATA const char **rt_bound_error_msg;
ST_DATA void *rt_prog_main;
#endif
#ifdef _WIN32
#define ucontext_t CONTEXT
#endif
static void set_pages_executable(void *ptr, unsigned long length);
static void set_exception_handler(void);
static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level);
static void rt_error(ucontext_t *uc, const char *fmt, ...);
static int tcc_relocate_ex(TCCState *s1, void *ptr);
#ifdef _WIN64
static void win64_add_function_table(TCCState *s1);
#endif
/* ------------------------------------------------------------- */
/* Do all relocations (needed before using tcc_get_symbol())
Returns -1 on error. */
LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr)
{
int ret;
if (TCC_RELOCATE_AUTO != ptr)
return tcc_relocate_ex(s1, ptr);
ret = tcc_relocate_ex(s1, NULL);
if (ret < 0)
return ret;
#ifdef HAVE_SELINUX
{ /* Use mmap instead of malloc for Selinux. Ref:
http://www.gnu.org/s/libc/manual/html_node/File-Size.html */
char tmpfname[] = "/tmp/.tccrunXXXXXX";
int fd = mkstemp (tmpfname);
s1->mem_size = ret;
unlink (tmpfname);
ftruncate (fd, s1->mem_size);
s1->write_mem = mmap (NULL, ret, PROT_READ|PROT_WRITE,
MAP_SHARED, fd, 0);
if (s1->write_mem == MAP_FAILED)
tcc_error("/tmp not writeable");
s1->runtime_mem = mmap (NULL, ret, PROT_READ|PROT_EXEC,
MAP_SHARED, fd, 0);
if (s1->runtime_mem == MAP_FAILED)
tcc_error("/tmp not executable");
ret = tcc_relocate_ex(s1, s1->write_mem);
}
#else
s1->runtime_mem = tcc_malloc(ret);
ret = tcc_relocate_ex(s1, s1->runtime_mem);
#endif
return ret;
}
/* launch the compiled program with the given arguments */
LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv)
{
int (*prog_main)(int, char **);
int ret;
if (tcc_relocate(s1, TCC_RELOCATE_AUTO) < 0)
return -1;
prog_main = tcc_get_symbol_err(s1, s1->runtime_main);
#ifdef CONFIG_TCC_BACKTRACE
if (s1->do_debug) {
set_exception_handler();
rt_prog_main = prog_main;
}
#endif
#ifdef CONFIG_TCC_BCHECK
if (s1->do_bounds_check) {
void (*bound_init)(void);
void (*bound_exit)(void);
void (*bound_new_region)(void *p, addr_t size);
int (*bound_delete_region)(void *p);
int i;
/* set error function */
rt_bound_error_msg = tcc_get_symbol_err(s1, "__bound_error_msg");
/* XXX: use .init section so that it also work in binary ? */
bound_init = tcc_get_symbol_err(s1, "__bound_init");
bound_exit = tcc_get_symbol_err(s1, "__bound_exit");
bound_new_region = tcc_get_symbol_err(s1, "__bound_new_region");
bound_delete_region = tcc_get_symbol_err(s1, "__bound_delete_region");
bound_init();
/* mark argv area as valid */
bound_new_region(argv, argc*sizeof(argv[0]));
for (i=0; i<argc; ++i)
bound_new_region(argv[i], strlen(argv[i]));
errno = 0; /* clean errno value */
ret = (*prog_main)(argc, argv);
/* unmark argv area */
for (i=0; i<argc; ++i)
bound_delete_region(argv[i]);
bound_delete_region(argv);
bound_exit();
} else
#endif
{
errno = 0; /* clean errno value */
ret = (*prog_main)(argc, argv);
}
return ret;
}
/* relocate code. Return -1 on error, required size if ptr is NULL,
otherwise copy code into buffer passed by the caller */
static int tcc_relocate_ex(TCCState *s1, void *ptr)
{
Section *s;
unsigned long offset, length;
addr_t mem;
int i;
if (NULL == ptr) {
s1->nb_errors = 0;
#ifdef TCC_TARGET_PE
pe_output_file(s1, NULL);
#else
tcc_add_runtime(s1);
relocate_common_syms();
tcc_add_linker_symbols(s1);
build_got_entries(s1);
#endif
if (s1->nb_errors)
return -1;
}
offset = 0, mem = (addr_t)ptr;
for(i = 1; i < s1->nb_sections; i++) {
s = s1->sections[i];
if (0 == (s->sh_flags & SHF_ALLOC))
continue;
length = s->data_offset;
s->sh_addr = mem ? (mem + offset + 15) & ~15 : 0;
offset = (offset + length + 15) & ~15;
}
offset += 16;
/* relocate symbols */
relocate_syms(s1, 1);
if (s1->nb_errors)
return -1;
if (0 == mem)
return offset;
/* relocate each section */
for(i = 1; i < s1->nb_sections; i++) {
s = s1->sections[i];
if (s->reloc)
relocate_section(s1, s);
}
relocate_plt(s1);
for(i = 1; i < s1->nb_sections; i++) {
s = s1->sections[i];
if (0 == (s->sh_flags & SHF_ALLOC))
continue;
length = s->data_offset;
// printf("%-12s %08lx %04x\n", s->name, s->sh_addr, length);
ptr = (void*)s->sh_addr;
if (NULL == s->data || s->sh_type == SHT_NOBITS)
memset(ptr, 0, length);
else
memcpy(ptr, s->data, length);
/* mark executable sections as executable in memory */
if (s->sh_flags & SHF_EXECINSTR)
set_pages_executable(ptr, length);
}
#ifdef _WIN64
win64_add_function_table(s1);
#endif
return 0;
}
/* ------------------------------------------------------------- */
/* allow to run code in memory */
static void set_pages_executable(void *ptr, unsigned long length)
{
#ifdef _WIN32
unsigned long old_protect;
VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect);
#else
extern void __clear_cache(void *beginning, void *end);
#ifndef PAGESIZE
# define PAGESIZE 4096
#endif
addr_t start, end;
start = (addr_t)ptr & ~(PAGESIZE - 1);
end = (addr_t)ptr + length;
end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC);
__clear_cache(ptr, (char *)ptr + length);
#endif
}
/* ------------------------------------------------------------- */
#ifdef CONFIG_TCC_BACKTRACE
ST_FUNC void tcc_set_num_callers(int n)
{
rt_num_callers = n;
}
/* print the position in the source file of PC value 'pc' by reading
the stabs debug information */
static addr_t rt_printline(addr_t wanted_pc, const char *msg)
{
char func_name[128], last_func_name[128];
addr_t func_addr, last_pc, pc;
const char *incl_files[INCLUDE_STACK_SIZE];
int incl_index, len, last_line_num, i;
const char *str, *p;
Stab_Sym *stab_sym = NULL, *stab_sym_end, *sym;
int stab_len = 0;
char *stab_str = NULL;
if (stab_section) {
stab_len = stab_section->data_offset;
stab_sym = (Stab_Sym *)stab_section->data;
stab_str = (char *) stabstr_section->data;
}
func_name[0] = '\0';
func_addr = 0;
incl_index = 0;
last_func_name[0] = '\0';
last_pc = (addr_t)-1;
last_line_num = 1;
if (!stab_sym)
goto no_stabs;
stab_sym_end = (Stab_Sym*)((char*)stab_sym + stab_len);
for (sym = stab_sym + 1; sym < stab_sym_end; ++sym) {
switch(sym->n_type) {
/* function start or end */
case N_FUN:
if (sym->n_strx == 0) {
/* we test if between last line and end of function */
pc = sym->n_value + func_addr;
if (wanted_pc >= last_pc && wanted_pc < pc)
goto found;
func_name[0] = '\0';
func_addr = 0;
} else {
str = stab_str + sym->n_strx;
p = strchr(str, ':');
if (!p) {
pstrcpy(func_name, sizeof(func_name), str);
} else {
len = p - str;
if (len > sizeof(func_name) - 1)
len = sizeof(func_name) - 1;
memcpy(func_name, str, len);
func_name[len] = '\0';
}
func_addr = sym->n_value;
}
break;
/* line number info */
case N_SLINE:
pc = sym->n_value + func_addr;
if (wanted_pc >= last_pc && wanted_pc < pc)
goto found;
last_pc = pc;
last_line_num = sym->n_desc;
/* XXX: slow! */
strcpy(last_func_name, func_name);
break;
/* include files */
case N_BINCL:
str = stab_str + sym->n_strx;
add_incl:
if (incl_index < INCLUDE_STACK_SIZE) {
incl_files[incl_index++] = str;
}
break;
case N_EINCL:
if (incl_index > 1)
incl_index--;
break;
case N_SO:
if (sym->n_strx == 0) {
incl_index = 0; /* end of translation unit */
} else {
str = stab_str + sym->n_strx;
/* do not add path */
len = strlen(str);
if (len > 0 && str[len - 1] != '/')
goto add_incl;
}
break;
}
}
no_stabs:
/* second pass: we try symtab symbols (no line number info) */
incl_index = 0;
if (symtab_section)
{
ElfW(Sym) *sym, *sym_end;
int type;
sym_end = (ElfW(Sym) *)(symtab_section->data + symtab_section->data_offset);
for(sym = (ElfW(Sym) *)symtab_section->data + 1;
sym < sym_end;
sym++) {
type = ELFW(ST_TYPE)(sym->st_info);
if (type == STT_FUNC || type == STT_GNU_IFUNC) {
if (wanted_pc >= sym->st_value &&
wanted_pc < sym->st_value + sym->st_size) {
pstrcpy(last_func_name, sizeof(last_func_name),
(char *) strtab_section->data + sym->st_name);
func_addr = sym->st_value;
goto found;
}
}
}
}
/* did not find any info: */
fprintf(stderr, "%s %p ???\n", msg, (void*)wanted_pc);
fflush(stderr);
return 0;
found:
i = incl_index;
if (i > 0)
fprintf(stderr, "%s:%d: ", incl_files[--i], last_line_num);
fprintf(stderr, "%s %p", msg, (void*)wanted_pc);
if (last_func_name[0] != '\0')
fprintf(stderr, " %s()", last_func_name);
if (--i >= 0) {
fprintf(stderr, " (included from ");
for (;;) {
fprintf(stderr, "%s", incl_files[i]);
if (--i < 0)
break;
fprintf(stderr, ", ");
}
fprintf(stderr, ")");
}
fprintf(stderr, "\n");
fflush(stderr);
return func_addr;
}
/* emit a run time error at position 'pc' */
static void rt_error(ucontext_t *uc, const char *fmt, ...)
{
va_list ap;
addr_t pc;
int i;
fprintf(stderr, "Runtime error: ");
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
for(i=0;i<rt_num_callers;i++) {
if (rt_get_caller_pc(&pc, uc, i) < 0)
break;
pc = rt_printline(pc, i ? "by" : "at");
if (pc == (addr_t)rt_prog_main && pc)
break;
}
}
/* ------------------------------------------------------------- */
#ifndef _WIN32
/* signal handler for fatal errors */
static void sig_error(int signum, siginfo_t *siginf, void *puc)
{
ucontext_t *uc = puc;
switch(signum) {
case SIGFPE:
switch(siginf->si_code) {
case FPE_INTDIV:
case FPE_FLTDIV:
rt_error(uc, "division by zero");
break;
default:
rt_error(uc, "floating point exception");
break;
}
break;
case SIGBUS:
case SIGSEGV:
if (rt_bound_error_msg && *rt_bound_error_msg)
rt_error(uc, *rt_bound_error_msg);
else
rt_error(uc, "dereferencing invalid pointer");
break;
case SIGILL:
rt_error(uc, "illegal instruction");
break;
case SIGABRT:
rt_error(uc, "abort() called");
break;
default:
rt_error(uc, "caught signal %d", signum);
break;
}
exit(255);
}
#ifndef SA_SIGINFO
# define SA_SIGINFO 0x00000004u
#endif
/* Generate a stack backtrace when a CPU exception occurs. */
static void set_exception_handler(void)
{
struct sigaction sigact;
/* install TCC signal handlers to print debug info on fatal
runtime errors */
sigact.sa_flags = SA_SIGINFO | SA_RESETHAND;
sigact.sa_sigaction = sig_error;
sigemptyset(&sigact.sa_mask);
sigaction(SIGFPE, &sigact, NULL);
sigaction(SIGILL, &sigact, NULL);
sigaction(SIGSEGV, &sigact, NULL);
sigaction(SIGBUS, &sigact, NULL);
sigaction(SIGABRT, &sigact, NULL);
}
/* ------------------------------------------------------------- */
#ifdef __i386__
/* fix for glibc 2.1 */
#ifndef REG_EIP
#define REG_EIP EIP
#define REG_EBP EBP
#endif
/* return the PC at frame level 'level'. Return negative if not found */
static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
{
addr_t fp;
int i;
if (level == 0) {
#if defined(__APPLE__)
*paddr = uc->uc_mcontext->__ss.__eip;
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
*paddr = uc->uc_mcontext.mc_eip;
#elif defined(__dietlibc__)
*paddr = uc->uc_mcontext.eip;
#elif defined(__NetBSD__)
*paddr = uc->uc_mcontext.__gregs[_REG_EIP];
#else
*paddr = uc->uc_mcontext.gregs[REG_EIP];
#endif
return 0;
} else {
#if defined(__APPLE__)
fp = uc->uc_mcontext->__ss.__ebp;
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
fp = uc->uc_mcontext.mc_ebp;
#elif defined(__dietlibc__)
fp = uc->uc_mcontext.ebp;
#elif defined(__NetBSD__)
fp = uc->uc_mcontext.__gregs[_REG_EBP];
#else
fp = uc->uc_mcontext.gregs[REG_EBP];
#endif
for(i=1;i<level;i++) {
/* XXX: check address validity with program info */
if (fp <= 0x1000 || fp >= 0xc0000000)
return -1;
fp = ((addr_t *)fp)[0];
}
*paddr = ((addr_t *)fp)[1];
return 0;
}
}
/* ------------------------------------------------------------- */
#elif defined(__x86_64__)
/* return the PC at frame level 'level'. Return negative if not found */
static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
{
addr_t fp;
int i;
if (level == 0) {
/* XXX: only support linux */
#if defined(__APPLE__)
*paddr = uc->uc_mcontext->__ss.__rip;
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
*paddr = uc->uc_mcontext.mc_rip;
#elif defined(__NetBSD__)
*paddr = uc->uc_mcontext.__gregs[_REG_RIP];
#else
*paddr = uc->uc_mcontext.gregs[REG_RIP];
#endif
return 0;
} else {
#if defined(__APPLE__)
fp = uc->uc_mcontext->__ss.__rbp;
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
fp = uc->uc_mcontext.mc_rbp;
#elif defined(__NetBSD__)
fp = uc->uc_mcontext.__gregs[_REG_RBP];
#else
fp = uc->uc_mcontext.gregs[REG_RBP];
#endif
for(i=1;i<level;i++) {
/* XXX: check address validity with program info */
if (fp <= 0x1000)
return -1;
fp = ((addr_t *)fp)[0];
}
*paddr = ((addr_t *)fp)[1];
return 0;
}
}
/* ------------------------------------------------------------- */
#elif defined(__arm__)
/* return the PC at frame level 'level'. Return negative if not found */
static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
{
addr_t fp, sp;
int i;
if (level == 0) {
/* XXX: only supports linux */
#if defined(__linux__)
*paddr = uc->uc_mcontext.arm_pc;
#else
return -1;
#endif
return 0;
} else {
#if defined(__linux__)
fp = uc->uc_mcontext.arm_fp;
sp = uc->uc_mcontext.arm_sp;
if (sp < 0x1000)
sp = 0x1000;
#else
return -1;
#endif
/* XXX: specific to tinycc stack frames */
if (fp < sp + 12 || fp & 3)
return -1;
for(i = 1; i < level; i++) {
sp = ((addr_t *)fp)[-2];
if (sp < fp || sp - fp > 16 || sp & 3)
return -1;
fp = ((addr_t *)fp)[-3];
if (fp <= sp || fp - sp < 12 || fp & 3)
return -1;
}
/* XXX: check address validity with program info */
*paddr = ((addr_t *)fp)[-1];
return 0;
}
}
/* ------------------------------------------------------------- */
#elif defined(__aarch64__)
static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
{
if (level < 0)
return -1;
else if (level == 0) {
*paddr = uc->uc_mcontext.pc;
return 0;
}
else {
addr_t *fp = (addr_t *)uc->uc_mcontext.regs[29];
int i;
for (i = 1; i < level; i++)
fp = (addr_t *)fp[0];
*paddr = fp[1];
return 0;
}
}
/* ------------------------------------------------------------- */
#else
#warning add arch specific rt_get_caller_pc()
static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
{
return -1;
}
#endif /* !__i386__ */
/* ------------------------------------------------------------- */
#else /* WIN32 */
static long __stdcall cpu_exception_handler(EXCEPTION_POINTERS *ex_info)
{
EXCEPTION_RECORD *er = ex_info->ExceptionRecord;
CONTEXT *uc = ex_info->ContextRecord;
switch (er->ExceptionCode) {
case EXCEPTION_ACCESS_VIOLATION:
if (rt_bound_error_msg && *rt_bound_error_msg)
rt_error(uc, *rt_bound_error_msg);
else
rt_error(uc, "access violation");
break;
case EXCEPTION_STACK_OVERFLOW:
rt_error(uc, "stack overflow");
break;
case EXCEPTION_INT_DIVIDE_BY_ZERO:
rt_error(uc, "division by zero");
break;
default:
rt_error(uc, "exception caught");
break;
}
return EXCEPTION_EXECUTE_HANDLER;
}
/* Generate a stack backtrace when a CPU exception occurs. */
static void set_exception_handler(void)
{
SetUnhandledExceptionFilter(cpu_exception_handler);
}
#ifdef _WIN64
static void win64_add_function_table(TCCState *s1)
{
RtlAddFunctionTable(
(RUNTIME_FUNCTION*)s1->uw_pdata->sh_addr,
s1->uw_pdata->data_offset / sizeof (RUNTIME_FUNCTION),
text_section->sh_addr
);
}
#endif
/* return the PC at frame level 'level'. Return non zero if not found */
static int rt_get_caller_pc(addr_t *paddr, CONTEXT *uc, int level)
{
addr_t fp, pc;
int i;
#ifdef _WIN64
pc = uc->Rip;
fp = uc->Rbp;
#else
pc = uc->Eip;
fp = uc->Ebp;
#endif
if (level > 0) {
for(i=1;i<level;i++) {
/* XXX: check address validity with program info */
if (fp <= 0x1000 || fp >= 0xc0000000)
return -1;
fp = ((addr_t*)fp)[0];
}
pc = ((addr_t*)fp)[1];
}
*paddr = pc;
return 0;
}
#endif /* _WIN32 */
#endif /* CONFIG_TCC_BACKTRACE */
/* ------------------------------------------------------------- */
#ifdef CONFIG_TCC_STATIC
/* dummy function for profiling */
ST_FUNC void *dlopen(const char *filename, int flag)
{
return NULL;
}
ST_FUNC void dlclose(void *p)
{
}
ST_FUNC const char *dlerror(void)
{
return "error";
}
typedef struct TCCSyms {
char *str;
void *ptr;
} TCCSyms;
/* add the symbol you want here if no dynamic linking is done */
static TCCSyms tcc_syms[] = {
#if !defined(CONFIG_TCCBOOT)
#define TCCSYM(a) { #a, &a, },
TCCSYM(printf)
TCCSYM(fprintf)
TCCSYM(fopen)
TCCSYM(fclose)
#undef TCCSYM
#endif
{ NULL, NULL },
};
ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol)
{
TCCSyms *p;
p = tcc_syms;
while (p->str != NULL) {
if (!strcmp(p->str, symbol))
return p->ptr;
p++;
}
return NULL;
}
#elif !defined(_WIN32)
ST_FUNC void *resolve_sym(TCCState *s1, const char *sym)
{
return dlsym(RTLD_DEFAULT, sym);
}
#endif /* CONFIG_TCC_STATIC */
#endif /* TCC_IS_NATIVE */
/* ------------------------------------------------------------- */

341
external/TCC/tcctok.h vendored
View File

@ -1,341 +0,0 @@
/* keywords */
DEF(TOK_INT, "int")
DEF(TOK_VOID, "void")
DEF(TOK_CHAR, "char")
DEF(TOK_IF, "if")
DEF(TOK_ELSE, "else")
DEF(TOK_WHILE, "while")
DEF(TOK_BREAK, "break")
DEF(TOK_RETURN, "return")
DEF(TOK_FOR, "for")
DEF(TOK_EXTERN, "extern")
DEF(TOK_STATIC, "static")
DEF(TOK_UNSIGNED, "unsigned")
DEF(TOK_GOTO, "goto")
DEF(TOK_DO, "do")
DEF(TOK_CONTINUE, "continue")
DEF(TOK_SWITCH, "switch")
DEF(TOK_CASE, "case")
DEF(TOK_CONST1, "const")
DEF(TOK_CONST2, "__const") /* gcc keyword */
DEF(TOK_CONST3, "__const__") /* gcc keyword */
DEF(TOK_VOLATILE1, "volatile")
DEF(TOK_VOLATILE2, "__volatile") /* gcc keyword */
DEF(TOK_VOLATILE3, "__volatile__") /* gcc keyword */
DEF(TOK_LONG, "long")
DEF(TOK_REGISTER, "register")
DEF(TOK_SIGNED1, "signed")
DEF(TOK_SIGNED2, "__signed") /* gcc keyword */
DEF(TOK_SIGNED3, "__signed__") /* gcc keyword */
DEF(TOK_AUTO, "auto")
DEF(TOK_INLINE1, "inline")
DEF(TOK_INLINE2, "__inline") /* gcc keyword */
DEF(TOK_INLINE3, "__inline__") /* gcc keyword */
DEF(TOK_RESTRICT1, "restrict")
DEF(TOK_RESTRICT2, "__restrict")
DEF(TOK_RESTRICT3, "__restrict__")
DEF(TOK_EXTENSION, "__extension__") /* gcc keyword */
DEF(TOK_FLOAT, "float")
DEF(TOK_DOUBLE, "double")
DEF(TOK_BOOL, "_Bool")
DEF(TOK_SHORT, "short")
DEF(TOK_STRUCT, "struct")
DEF(TOK_UNION, "union")
DEF(TOK_TYPEDEF, "typedef")
DEF(TOK_DEFAULT, "default")
DEF(TOK_ENUM, "enum")
DEF(TOK_SIZEOF, "sizeof")
DEF(TOK_ATTRIBUTE1, "__attribute")
DEF(TOK_ATTRIBUTE2, "__attribute__")
DEF(TOK_ALIGNOF1, "__alignof")
DEF(TOK_ALIGNOF2, "__alignof__")
DEF(TOK_TYPEOF1, "typeof")
DEF(TOK_TYPEOF2, "__typeof")
DEF(TOK_TYPEOF3, "__typeof__")
DEF(TOK_LABEL, "__label__")
DEF(TOK_ASM1, "asm")
DEF(TOK_ASM2, "__asm")
DEF(TOK_ASM3, "__asm__")
#ifdef TCC_TARGET_ARM64
DEF(TOK_UINT128, "__uint128_t")
#endif
/*********************************************************************/
/* the following are not keywords. They are included to ease parsing */
/* preprocessor only */
DEF(TOK_DEFINE, "define")
DEF(TOK_INCLUDE, "include")
DEF(TOK_INCLUDE_NEXT, "include_next")
DEF(TOK_IFDEF, "ifdef")
DEF(TOK_IFNDEF, "ifndef")
DEF(TOK_ELIF, "elif")
DEF(TOK_ENDIF, "endif")
DEF(TOK_DEFINED, "defined")
DEF(TOK_UNDEF, "undef")
DEF(TOK_ERROR, "error")
DEF(TOK_WARNING, "warning")
DEF(TOK_LINE, "line")
DEF(TOK_PRAGMA, "pragma")
DEF(TOK___LINE__, "__LINE__")
DEF(TOK___FILE__, "__FILE__")
DEF(TOK___DATE__, "__DATE__")
DEF(TOK___TIME__, "__TIME__")
DEF(TOK___FUNCTION__, "__FUNCTION__")
DEF(TOK___VA_ARGS__, "__VA_ARGS__")
/* special identifiers */
DEF(TOK___FUNC__, "__func__")
/* special floating point values */
DEF(TOK___NAN__, "__nan__")
DEF(TOK___SNAN__, "__snan__")
DEF(TOK___INF__, "__inf__")
/* attribute identifiers */
/* XXX: handle all tokens generically since speed is not critical */
DEF(TOK_SECTION1, "section")
DEF(TOK_SECTION2, "__section__")
DEF(TOK_ALIGNED1, "aligned")
DEF(TOK_ALIGNED2, "__aligned__")
DEF(TOK_PACKED1, "packed")
DEF(TOK_PACKED2, "__packed__")
DEF(TOK_WEAK1, "weak")
DEF(TOK_WEAK2, "__weak__")
DEF(TOK_ALIAS1, "alias")
DEF(TOK_ALIAS2, "__alias__")
DEF(TOK_UNUSED1, "unused")
DEF(TOK_UNUSED2, "__unused__")
DEF(TOK_CDECL1, "cdecl")
DEF(TOK_CDECL2, "__cdecl")
DEF(TOK_CDECL3, "__cdecl__")
DEF(TOK_STDCALL1, "stdcall")
DEF(TOK_STDCALL2, "__stdcall")
DEF(TOK_STDCALL3, "__stdcall__")
DEF(TOK_FASTCALL1, "fastcall")
DEF(TOK_FASTCALL2, "__fastcall")
DEF(TOK_FASTCALL3, "__fastcall__")
DEF(TOK_MODE, "__mode__")
DEF(TOK_MODE_DI, "__DI__")
DEF(TOK_MODE_HI, "__HI__")
DEF(TOK_MODE_SI, "__SI__")
DEF(TOK_DLLEXPORT, "dllexport")
DEF(TOK_DLLIMPORT, "dllimport")
DEF(TOK_NORETURN1, "noreturn")
DEF(TOK_NORETURN2, "__noreturn__")
DEF(TOK_VISIBILITY1, "visibility")
DEF(TOK_VISIBILITY2, "__visibility__")
DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
DEF(TOK_builtin_constant_p, "__builtin_constant_p")
DEF(TOK_builtin_frame_address, "__builtin_frame_address")
DEF(TOK_builtin_return_address, "__builtin_return_address")
#ifdef TCC_TARGET_X86_64
#ifdef TCC_TARGET_PE
DEF(TOK_builtin_va_start, "__builtin_va_start")
#else
DEF(TOK_builtin_va_arg_types, "__builtin_va_arg_types")
#endif
#endif
DEF(TOK_REGPARM1, "regparm")
DEF(TOK_REGPARM2, "__regparm__")
#ifdef TCC_TARGET_ARM64
DEF(TOK___va_start, "__va_start")
DEF(TOK___va_arg, "__va_arg")
#endif
/* pragma */
DEF(TOK_pack, "pack")
#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_X86_64)
/* already defined for assembler */
DEF(TOK_ASM_push, "push")
DEF(TOK_ASM_pop, "pop")
#endif
DEF(TOK_comment, "comment")
DEF(TOK_lib, "lib")
DEF(TOK_push_macro, "push_macro")
DEF(TOK_pop_macro, "pop_macro")
DEF(TOK_once, "once")
/* builtin functions or variables */
#ifndef TCC_ARM_EABI
DEF(TOK_memcpy, "memcpy")
DEF(TOK_memmove, "memmove")
DEF(TOK_memset, "memset")
DEF(TOK___divdi3, "__divdi3")
DEF(TOK___moddi3, "__moddi3")
DEF(TOK___udivdi3, "__udivdi3")
DEF(TOK___umoddi3, "__umoddi3")
DEF(TOK___ashrdi3, "__ashrdi3")
DEF(TOK___lshrdi3, "__lshrdi3")
DEF(TOK___ashldi3, "__ashldi3")
DEF(TOK___floatundisf, "__floatundisf")
DEF(TOK___floatundidf, "__floatundidf")
# ifndef TCC_ARM_VFP
DEF(TOK___floatundixf, "__floatundixf")
DEF(TOK___fixunsxfdi, "__fixunsxfdi")
# endif
DEF(TOK___fixunssfdi, "__fixunssfdi")
DEF(TOK___fixunsdfdi, "__fixunsdfdi")
#endif
#if defined TCC_TARGET_ARM
# ifdef TCC_ARM_EABI
DEF(TOK_memcpy, "__aeabi_memcpy")
DEF(TOK_memcpy4, "__aeabi_memcpy4")
DEF(TOK_memcpy8, "__aeabi_memcpy8")
DEF(TOK_memmove, "__aeabi_memmove")
DEF(TOK_memset, "__aeabi_memset")
DEF(TOK___aeabi_ldivmod, "__aeabi_ldivmod")
DEF(TOK___aeabi_uldivmod, "__aeabi_uldivmod")
DEF(TOK___aeabi_idivmod, "__aeabi_idivmod")
DEF(TOK___aeabi_uidivmod, "__aeabi_uidivmod")
DEF(TOK___divsi3, "__aeabi_idiv")
DEF(TOK___udivsi3, "__aeabi_uidiv")
DEF(TOK___floatdisf, "__aeabi_l2f")
DEF(TOK___floatdidf, "__aeabi_l2d")
DEF(TOK___fixsfdi, "__aeabi_f2lz")
DEF(TOK___fixdfdi, "__aeabi_d2lz")
DEF(TOK___ashrdi3, "__aeabi_lasr")
DEF(TOK___lshrdi3, "__aeabi_llsr")
DEF(TOK___ashldi3, "__aeabi_llsl")
DEF(TOK___floatundisf, "__aeabi_ul2f")
DEF(TOK___floatundidf, "__aeabi_ul2d")
DEF(TOK___fixunssfdi, "__aeabi_f2ulz")
DEF(TOK___fixunsdfdi, "__aeabi_d2ulz")
# else
DEF(TOK___modsi3, "__modsi3")
DEF(TOK___umodsi3, "__umodsi3")
DEF(TOK___divsi3, "__divsi3")
DEF(TOK___udivsi3, "__udivsi3")
DEF(TOK___floatdisf, "__floatdisf")
DEF(TOK___floatdidf, "__floatdidf")
# ifndef TCC_ARM_VFP
DEF(TOK___floatdixf, "__floatdixf")
DEF(TOK___fixunssfsi, "__fixunssfsi")
DEF(TOK___fixunsdfsi, "__fixunsdfsi")
DEF(TOK___fixunsxfsi, "__fixunsxfsi")
DEF(TOK___fixxfdi, "__fixxfdi")
# endif
DEF(TOK___fixsfdi, "__fixsfdi")
DEF(TOK___fixdfdi, "__fixdfdi")
# endif
#endif
#if defined TCC_TARGET_C67
DEF(TOK__divi, "_divi")
DEF(TOK__divu, "_divu")
DEF(TOK__divf, "_divf")
DEF(TOK__divd, "_divd")
DEF(TOK__remi, "_remi")
DEF(TOK__remu, "_remu")
#endif
#if defined TCC_TARGET_I386
DEF(TOK___fixsfdi, "__fixsfdi")
DEF(TOK___fixdfdi, "__fixdfdi")
DEF(TOK___fixxfdi, "__fixxfdi")
#ifndef COMMIT_4ad186c5ef61_IS_FIXED
DEF(TOK___tcc_cvt_ftol, "__tcc_cvt_ftol")
#endif
#endif
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
DEF(TOK_alloca, "alloca")
#endif
#if defined TCC_TARGET_PE
DEF(TOK___chkstk, "__chkstk")
#endif
#ifdef TCC_TARGET_ARM64
DEF(TOK___arm64_clear_cache, "__arm64_clear_cache")
DEF(TOK___addtf3, "__addtf3")
DEF(TOK___subtf3, "__subtf3")
DEF(TOK___multf3, "__multf3")
DEF(TOK___divtf3, "__divtf3")
DEF(TOK___extendsftf2, "__extendsftf2")
DEF(TOK___extenddftf2, "__extenddftf2")
DEF(TOK___trunctfsf2, "__trunctfsf2")
DEF(TOK___trunctfdf2, "__trunctfdf2")
DEF(TOK___fixtfsi, "__fixtfsi")
DEF(TOK___fixtfdi, "__fixtfdi")
DEF(TOK___fixunstfsi, "__fixunstfsi")
DEF(TOK___fixunstfdi, "__fixunstfdi")
DEF(TOK___floatsitf, "__floatsitf")
DEF(TOK___floatditf, "__floatditf")
DEF(TOK___floatunsitf, "__floatunsitf")
DEF(TOK___floatunditf, "__floatunditf")
DEF(TOK___eqtf2, "__eqtf2")
DEF(TOK___netf2, "__netf2")
DEF(TOK___lttf2, "__lttf2")
DEF(TOK___letf2, "__letf2")
DEF(TOK___gttf2, "__gttf2")
DEF(TOK___getf2, "__getf2")
#endif
/* bound checking symbols */
#ifdef CONFIG_TCC_BCHECK
DEF(TOK___bound_ptr_add, "__bound_ptr_add")
DEF(TOK___bound_ptr_indir1, "__bound_ptr_indir1")
DEF(TOK___bound_ptr_indir2, "__bound_ptr_indir2")
DEF(TOK___bound_ptr_indir4, "__bound_ptr_indir4")
DEF(TOK___bound_ptr_indir8, "__bound_ptr_indir8")
DEF(TOK___bound_ptr_indir12, "__bound_ptr_indir12")
DEF(TOK___bound_ptr_indir16, "__bound_ptr_indir16")
DEF(TOK___bound_main_arg, "__bound_main_arg")
DEF(TOK___bound_local_new, "__bound_local_new")
DEF(TOK___bound_local_delete, "__bound_local_delete")
DEF(TOK___bound_init, "__bound_init")
# ifdef TCC_TARGET_PE
DEF(TOK_malloc, "malloc")
DEF(TOK_free, "free")
DEF(TOK_realloc, "realloc")
DEF(TOK_memalign, "memalign")
DEF(TOK_calloc, "calloc")
# endif
DEF(TOK_strlen, "strlen")
DEF(TOK_strcpy, "strcpy")
#endif
/* Tiny Assembler */
DEF_ASMDIR(byte) /* must be first directive */
DEF_ASMDIR(word)
DEF_ASMDIR(align)
DEF_ASMDIR(p2align)
DEF_ASMDIR(skip)
DEF_ASMDIR(space)
DEF_ASMDIR(string)
DEF_ASMDIR(asciz)
DEF_ASMDIR(ascii)
DEF_ASMDIR(file)
DEF_ASMDIR(globl)
DEF_ASMDIR(global)
DEF_ASMDIR(weak)
DEF_ASMDIR(hidden)
DEF_ASMDIR(ident)
DEF_ASMDIR(size)
DEF_ASMDIR(type)
DEF_ASMDIR(text)
DEF_ASMDIR(data)
DEF_ASMDIR(bss)
DEF_ASMDIR(previous)
DEF_ASMDIR(fill)
DEF_ASMDIR(org)
DEF_ASMDIR(quad)
#if defined(TCC_TARGET_I386)
DEF_ASMDIR(code16)
DEF_ASMDIR(code32)
#elif defined(TCC_TARGET_X86_64)
DEF_ASMDIR(code64)
#endif
DEF_ASMDIR(short)
DEF_ASMDIR(long)
DEF_ASMDIR(int)
DEF_ASMDIR(section) /* must be last directive */
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
#include "i386-tok.h"
#endif

View File

@ -1,249 +0,0 @@
/* -------------------------------------------------------------- */
/*
* tiny_impdef creates an export definition file (.def) from a dll
* on MS-Windows. Usage: tiny_impdef library.dll [-o outputfile]"
*
* Copyright (c) 2005,2007 grischka
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef TINY_IMPDEF_GET_EXPORT_NAMES_ONLY
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <io.h>
#include <malloc.h>
char *get_export_names(int fd);
#define tcc_free free
#define tcc_realloc realloc
/* extract the basename of a file */
static char *file_basename(const char *name)
{
const char *p = strchr(name, 0);
while (p > name
&& p[-1] != '/'
&& p[-1] != '\\'
)
--p;
return (char*)p;
}
int main(int argc, char **argv)
{
int ret, v, i;
char infile[MAX_PATH];
char outfile[MAX_PATH];
static const char *ext[] = { ".dll", ".exe", NULL };
const char *file, **pp;
char path[MAX_PATH], *p, *q;
FILE *fp, *op;
infile[0] = 0;
outfile[0] = 0;
fp = op = NULL;
v = 0;
ret = 1;
p = NULL;
for (i = 1; i < argc; ++i) {
const char *a = argv[i];
if ('-' == a[0]) {
if (0 == strcmp(a, "-v")) {
v = 1;
} else if (0 == strcmp(a, "-o")) {
if (++i == argc)
goto usage;
strcpy(outfile, argv[i]);
} else
goto usage;
} else if (0 == infile[0])
strcpy(infile, a);
else
goto usage;
}
if (0 == infile[0]) {
usage:
fprintf(stderr,
"tiny_impdef: create export definition file (.def) from a dll\n"
"Usage: tiny_impdef library.dll [-o outputfile]\n"
);
goto the_end;
}
if (0 == outfile[0])
{
strcpy(outfile, file_basename(infile));
q = strrchr(outfile, '.');
if (NULL == q)
q = strchr(outfile, 0);
strcpy(q, ".def");
}
file = infile;
#ifdef _WIN32
pp = ext;
do if (SearchPath(NULL, file, *pp, sizeof path, path, NULL)) {
file = path;
break;
} while (*pp++);
#endif
fp = fopen(file, "rb");
if (NULL == fp) {
fprintf(stderr, "tiny_impdef: no such file: %s\n", infile);
goto the_end;
}
if (v)
printf("--> %s\n", file);
p = get_export_names(fileno(fp));
if (NULL == p) {
fprintf(stderr, "tiny_impdef: could not get exported function names.\n");
goto the_end;
}
op = fopen(outfile, "w");
if (NULL == op) {
fprintf(stderr, "tiny_impdef: could not create output file: %s\n", outfile);
goto the_end;
}
fprintf(op, "LIBRARY %s\n\nEXPORTS\n", file_basename(file));
for (q = p, i = 0; *q; ++i) {
fprintf(op, "%s\n", q);
q += strlen(q) + 1;
}
if (v) {
printf("<-- %s\n", outfile);
printf("%d symbol(s) found\n", i);
}
ret = 0;
the_end:
if (p)
free(p);
if (fp)
fclose(fp);
if (op)
fclose(op);
return ret;
}
int read_mem(int fd, unsigned offset, void *buffer, unsigned len)
{
lseek(fd, offset, SEEK_SET);
return len == read(fd, buffer, len);
}
/* -------------------------------------------------------------- */
#if defined TCC_TARGET_X86_64
# define IMAGE_FILE_MACHINE 0x8664
#elif defined TCC_TARGET_ARM
# define IMAGE_FILE_MACHINE 0x01C0
#elif 1 /* defined TCC_TARGET_I386 */
# define IMAGE_FILE_MACHINE 0x014C
#endif
/* -------------------------------------------------------------- */
#endif
char *get_export_names(int fd)
{
int l, i, n, n0;
char *p;
IMAGE_SECTION_HEADER ish;
IMAGE_EXPORT_DIRECTORY ied;
IMAGE_DOS_HEADER dh;
IMAGE_FILE_HEADER ih;
DWORD sig, ref, addr, ptr, namep;
#ifdef TCC_TARGET_X86_64
IMAGE_OPTIONAL_HEADER64 oh;
#else
IMAGE_OPTIONAL_HEADER32 oh;
#endif
int pef_hdroffset, opt_hdroffset, sec_hdroffset;
n = n0 = 0;
p = NULL;
if (!read_mem(fd, 0, &dh, sizeof dh))
goto the_end;
if (!read_mem(fd, dh.e_lfanew, &sig, sizeof sig))
goto the_end;
if (sig != 0x00004550)
goto the_end;
pef_hdroffset = dh.e_lfanew + sizeof sig;
if (!read_mem(fd, pef_hdroffset, &ih, sizeof ih))
goto the_end;
if (IMAGE_FILE_MACHINE != ih.Machine)
goto the_end;
opt_hdroffset = pef_hdroffset + sizeof ih;
sec_hdroffset = opt_hdroffset + sizeof oh;
if (!read_mem(fd, opt_hdroffset, &oh, sizeof oh))
goto the_end;
if (IMAGE_DIRECTORY_ENTRY_EXPORT >= oh.NumberOfRvaAndSizes)
goto the_end;
addr = oh.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
//printf("addr: %08x\n", addr);
for (i = 0; i < ih.NumberOfSections; ++i) {
if (!read_mem(fd, sec_hdroffset + i * sizeof ish, &ish, sizeof ish))
goto the_end;
//printf("vaddr: %08x\n", ish.VirtualAddress);
if (addr >= ish.VirtualAddress && addr < ish.VirtualAddress + ish.SizeOfRawData)
goto found;
}
goto the_end;
found:
ref = ish.VirtualAddress - ish.PointerToRawData;
if (!read_mem(fd, addr - ref, &ied, sizeof ied))
goto the_end;
namep = ied.AddressOfNames - ref;
for (i = 0; i < ied.NumberOfNames; ++i) {
if (!read_mem(fd, namep, &ptr, sizeof ptr))
goto the_end;
namep += sizeof ptr;
for (l = 0;;) {
if (n+1 >= n0)
p = tcc_realloc(p, n0 = n0 ? n0 * 2 : 256);
if (!read_mem(fd, ptr - ref + l++, p + n, 1)) {
tcc_free(p), p = NULL;
goto the_end;
}
if (p[n++] == 0)
break;
}
}
if (p)
p[n] = 0;
the_end:
return p;
}
/* -------------------------------------------------------------- */

View File

@ -1,258 +0,0 @@
/*
* This program is for making libtcc1.a without ar
* tiny_libmaker - tiny elf lib maker
* usage: tiny_libmaker [lib] files...
* Copyright (c) 2007 Timppa
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../../elf.h"
#ifdef TCC_TARGET_X86_64
# define ELFCLASSW ELFCLASS64
# define ElfW(type) Elf##64##_##type
# define ELFW(type) ELF##64##_##type
#else
# define ELFCLASSW ELFCLASS32
# define ElfW(type) Elf##32##_##type
# define ELFW(type) ELF##32##_##type
#endif
#define ARMAG "!<arch>\n"
#define ARFMAG "`\n"
typedef struct ArHdr {
char ar_name[16];
char ar_date[12];
char ar_uid[6];
char ar_gid[6];
char ar_mode[8];
char ar_size[10];
char ar_fmag[2];
} ArHdr;
unsigned long le2belong(unsigned long ul) {
return ((ul & 0xFF0000)>>8)+((ul & 0xFF000000)>>24) +
((ul & 0xFF)<<24)+((ul & 0xFF00)<<8);
}
ArHdr arhdr = {
"/ ",
" ",
"0 ",
"0 ",
"0 ",
" ",
ARFMAG
};
ArHdr arhdro = {
" ",
" ",
"0 ",
"0 ",
"0 ",
" ",
ARFMAG
};
int main(int argc, char **argv)
{
FILE *fi, *fh = NULL, *fo = NULL;
ElfW(Ehdr) *ehdr;
ElfW(Shdr) *shdr;
ElfW(Sym) *sym;
int i, fsize, iarg;
char *buf, *shstr, *symtab = NULL, *strtab = NULL;
int symtabsize = 0;//, strtabsize = 0;
char *anames = NULL;
int *afpos = NULL;
int istrlen, strpos = 0, fpos = 0, funccnt = 0, funcmax, hofs;
char afile[260], tfile[260], stmp[20];
char *file, *name;
int ret = 2;
strcpy(afile, "ar_test.a");
iarg = 1;
if (argc < 2)
{
printf("usage: tiny_libmaker [lib] file...\n");
return 1;
}
for (i=1; i<argc; i++) {
istrlen = strlen(argv[i]);
if (argv[i][istrlen-2] == '.') {
if(argv[i][istrlen-1] == 'a')
strcpy(afile, argv[i]);
else if(argv[i][istrlen-1] == 'o') {
iarg = i;
break;
}
}
}
if ((fh = fopen(afile, "wb")) == NULL)
{
fprintf(stderr, "Can't open file %s \n", afile);
goto the_end;
}
sprintf(tfile, "%s.tmp", afile);
if ((fo = fopen(tfile, "wb+")) == NULL)
{
fprintf(stderr, "Can't create temporary file %s\n", tfile);
goto the_end;
}
funcmax = 250;
afpos = realloc(NULL, funcmax * sizeof *afpos); // 250 func
memcpy(&arhdro.ar_mode, "100666", 6);
//iarg = 1;
while (iarg < argc)
{
if (!strcmp(argv[iarg], "rcs")) {
iarg++;
continue;
}
if ((fi = fopen(argv[iarg], "rb")) == NULL)
{
fprintf(stderr, "Can't open file %s \n", argv[iarg]);
goto the_end;
}
fseek(fi, 0, SEEK_END);
fsize = ftell(fi);
fseek(fi, 0, SEEK_SET);
buf = malloc(fsize + 1);
fread(buf, fsize, 1, fi);
fclose(fi);
//printf("%s:\n", argv[iarg]);
// elf header
ehdr = (ElfW(Ehdr) *)buf;
if (ehdr->e_ident[4] != ELFCLASSW)
{
fprintf(stderr, "Unsupported Elf Class: %s\n", argv[iarg]);
goto the_end;
}
shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + ehdr->e_shstrndx * ehdr->e_shentsize);
shstr = (char *)(buf + shdr->sh_offset);
for (i = 0; i < ehdr->e_shnum; i++)
{
shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + i * ehdr->e_shentsize);
if (!shdr->sh_offset)
continue;
if (shdr->sh_type == SHT_SYMTAB)
{
symtab = (char *)(buf + shdr->sh_offset);
symtabsize = shdr->sh_size;
}
if (shdr->sh_type == SHT_STRTAB)
{
if (!strcmp(shstr + shdr->sh_name, ".strtab"))
{
strtab = (char *)(buf + shdr->sh_offset);
//strtabsize = shdr->sh_size;
}
}
}
if (symtab && symtabsize)
{
int nsym = symtabsize / sizeof(ElfW(Sym));
//printf("symtab: info size shndx name\n");
for (i = 1; i < nsym; i++)
{
sym = (ElfW(Sym) *) (symtab + i * sizeof(ElfW(Sym)));
if (sym->st_shndx &&
(sym->st_info == 0x10
|| sym->st_info == 0x11
|| sym->st_info == 0x12
)) {
//printf("symtab: %2Xh %4Xh %2Xh %s\n", sym->st_info, sym->st_size, sym->st_shndx, strtab + sym->st_name);
istrlen = strlen(strtab + sym->st_name)+1;
anames = realloc(anames, strpos+istrlen);
strcpy(anames + strpos, strtab + sym->st_name);
strpos += istrlen;
if (++funccnt >= funcmax) {
funcmax += 250;
afpos = realloc(afpos, funcmax * sizeof *afpos); // 250 func more
}
afpos[funccnt] = fpos;
}
}
}
file = argv[iarg];
for (name = strchr(file, 0);
name > file && name[-1] != '/' && name[-1] != '\\';
--name);
istrlen = strlen(name);
if (istrlen >= sizeof(arhdro.ar_name))
istrlen = sizeof(arhdro.ar_name) - 1;
memset(arhdro.ar_name, ' ', sizeof(arhdro.ar_name));
memcpy(arhdro.ar_name, name, istrlen);
arhdro.ar_name[istrlen] = '/';
sprintf(stmp, "%-10d", fsize);
memcpy(&arhdro.ar_size, stmp, 10);
fwrite(&arhdro, sizeof(arhdro), 1, fo);
fwrite(buf, fsize, 1, fo);
free(buf);
iarg++;
fpos += (fsize + sizeof(arhdro));
}
hofs = 8 + sizeof(arhdr) + strpos + (funccnt+1) * sizeof(int);
fpos = 0;
if ((hofs & 1)) // align
hofs++, fpos = 1;
// write header
fwrite("!<arch>\n", 8, 1, fh);
sprintf(stmp, "%-10d", (int)(strpos + (funccnt+1) * sizeof(int)));
memcpy(&arhdr.ar_size, stmp, 10);
fwrite(&arhdr, sizeof(arhdr), 1, fh);
afpos[0] = le2belong(funccnt);
for (i=1; i<=funccnt; i++)
afpos[i] = le2belong(afpos[i] + hofs);
fwrite(afpos, (funccnt+1) * sizeof(int), 1, fh);
fwrite(anames, strpos, 1, fh);
if (fpos)
fwrite("", 1, 1, fh);
// write objects
fseek(fo, 0, SEEK_END);
fsize = ftell(fo);
fseek(fo, 0, SEEK_SET);
buf = malloc(fsize + 1);
fread(buf, fsize, 1, fo);
fwrite(buf, fsize, 1, fh);
free(buf);
ret = 0;
the_end:
if (anames)
free(anames);
if (afpos)
free(afpos);
if (fh)
fclose(fh);
if (fo)
fclose(fo), remove(tfile);
return ret;
}

View File

@ -1,475 +0,0 @@
DEF_ASM_OP0(clc, 0xf8) /* must be first OP0 */
DEF_ASM_OP0(cld, 0xfc)
DEF_ASM_OP0(cli, 0xfa)
DEF_ASM_OP0(clts, 0x0f06)
DEF_ASM_OP0(cmc, 0xf5)
DEF_ASM_OP0(lahf, 0x9f)
DEF_ASM_OP0(sahf, 0x9e)
DEF_ASM_OP0(pushfl, 0x9c)
DEF_ASM_OP0(popfl, 0x9d)
DEF_ASM_OP0(pushf, 0x9c)
DEF_ASM_OP0(popf, 0x9d)
DEF_ASM_OP0(stc, 0xf9)
DEF_ASM_OP0(std, 0xfd)
DEF_ASM_OP0(sti, 0xfb)
DEF_ASM_OP0(aaa, 0x37)
DEF_ASM_OP0(aas, 0x3f)
DEF_ASM_OP0(daa, 0x27)
DEF_ASM_OP0(das, 0x2f)
DEF_ASM_OP0(aad, 0xd50a)
DEF_ASM_OP0(aam, 0xd40a)
DEF_ASM_OP0(cbw, 0x6698)
DEF_ASM_OP0(cwd, 0x6699)
DEF_ASM_OP0(cwde, 0x98)
DEF_ASM_OP0(cdq, 0x99)
DEF_ASM_OP0(cbtw, 0x6698)
DEF_ASM_OP0(cwtl, 0x98)
DEF_ASM_OP0(cwtd, 0x6699)
DEF_ASM_OP0(cltd, 0x99)
DEF_ASM_OP0(cqto, 0x4899)
DEF_ASM_OP0(int3, 0xcc)
DEF_ASM_OP0(into, 0xce)
DEF_ASM_OP0(iret, 0xcf)
DEF_ASM_OP0(rsm, 0x0faa)
DEF_ASM_OP0(hlt, 0xf4)
DEF_ASM_OP0(wait, 0x9b)
DEF_ASM_OP0(nop, 0x90)
DEF_ASM_OP0(xlat, 0xd7)
/* strings */
ALT(DEF_ASM_OP0L(cmpsb, 0xa6, 0, OPC_BWLQ))
ALT(DEF_ASM_OP0L(scmpb, 0xa6, 0, OPC_BWLQ))
ALT(DEF_ASM_OP0L(insb, 0x6c, 0, OPC_BWLQ))
ALT(DEF_ASM_OP0L(outsb, 0x6e, 0, OPC_BWLQ))
ALT(DEF_ASM_OP0L(lodsb, 0xac, 0, OPC_BWLQ))
ALT(DEF_ASM_OP0L(slodb, 0xac, 0, OPC_BWLQ))
ALT(DEF_ASM_OP0L(movsb, 0xa4, 0, OPC_BWLQ))
ALT(DEF_ASM_OP0L(smovb, 0xa4, 0, OPC_BWLQ))
ALT(DEF_ASM_OP0L(scasb, 0xae, 0, OPC_BWLQ))
ALT(DEF_ASM_OP0L(sscab, 0xae, 0, OPC_BWLQ))
ALT(DEF_ASM_OP0L(stosb, 0xaa, 0, OPC_BWLQ))
ALT(DEF_ASM_OP0L(sstob, 0xaa, 0, OPC_BWLQ))
/* bits */
ALT(DEF_ASM_OP2(bsfw, 0x0fbc, 0, OPC_MODRM | OPC_WLQ, OPT_REGW | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(bsrw, 0x0fbd, 0, OPC_MODRM | OPC_WLQ, OPT_REGW | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(btw, 0x0fa3, 0, OPC_MODRM | OPC_WLQ, OPT_REGW, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btw, 0x0fba, 4, OPC_MODRM | OPC_WLQ, OPT_IM8, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btsw, 0x0fab, 0, OPC_MODRM | OPC_WLQ, OPT_REGW, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btsw, 0x0fba, 5, OPC_MODRM | OPC_WLQ, OPT_IM8, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btrw, 0x0fb3, 0, OPC_MODRM | OPC_WLQ, OPT_REGW, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btrw, 0x0fba, 6, OPC_MODRM | OPC_WLQ, OPT_IM8, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btcw, 0x0fbb, 0, OPC_MODRM | OPC_WLQ, OPT_REGW, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WLQ, OPT_IM8, OPT_REGW | OPT_EA))
/* prefixes */
DEF_ASM_OP0(lock, 0xf0)
DEF_ASM_OP0(rep, 0xf3)
DEF_ASM_OP0(repe, 0xf3)
DEF_ASM_OP0(repz, 0xf3)
DEF_ASM_OP0(repne, 0xf2)
DEF_ASM_OP0(repnz, 0xf2)
DEF_ASM_OP0(invd, 0x0f08)
DEF_ASM_OP0(wbinvd, 0x0f09)
DEF_ASM_OP0(cpuid, 0x0fa2)
DEF_ASM_OP0(wrmsr, 0x0f30)
DEF_ASM_OP0(rdtsc, 0x0f31)
DEF_ASM_OP0(rdmsr, 0x0f32)
DEF_ASM_OP0(rdpmc, 0x0f33)
DEF_ASM_OP0(ud2, 0x0f0b)
/* NOTE: we took the same order as gas opcode definition order */
ALT(DEF_ASM_OP2(movb, 0xa0, 0, OPC_BWLQ, OPT_ADDR, OPT_EAX))
ALT(DEF_ASM_OP2(movb, 0xa2, 0, OPC_BWLQ, OPT_EAX, OPT_ADDR))
ALT(DEF_ASM_OP2(movb, 0x88, 0, OPC_MODRM | OPC_BWLQ, OPT_REG, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(movb, 0x8a, 0, OPC_MODRM | OPC_BWLQ, OPT_EA | OPT_REG, OPT_REG))
ALT(DEF_ASM_OP2(movb, 0xb0, 0, OPC_REG | OPC_BWLQ, OPT_IM, OPT_REG))
ALT(DEF_ASM_OP2(movb, 0xc6, 0, OPC_MODRM | OPC_BWLQ, OPT_IM, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP2(movw, 0x8c, 0, OPC_MODRM | OPC_WLQ, OPT_SEG, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(movw, 0x8e, 0, OPC_MODRM | OPC_WLQ, OPT_EA | OPT_REG, OPT_SEG))
ALT(DEF_ASM_OP2(movw, 0x0f20, 0, OPC_MODRM | OPC_WLQ, OPT_CR, OPT_REG64))
ALT(DEF_ASM_OP2(movw, 0x0f21, 0, OPC_MODRM | OPC_WLQ, OPT_DB, OPT_REG64))
ALT(DEF_ASM_OP2(movw, 0x0f24, 0, OPC_MODRM | OPC_WLQ, OPT_TR, OPT_REG64))
ALT(DEF_ASM_OP2(movw, 0x0f22, 0, OPC_MODRM | OPC_WLQ, OPT_REG64, OPT_CR))
ALT(DEF_ASM_OP2(movw, 0x0f23, 0, OPC_MODRM | OPC_WLQ, OPT_REG64, OPT_DB))
ALT(DEF_ASM_OP2(movw, 0x0f26, 0, OPC_MODRM | OPC_WLQ, OPT_REG64, OPT_TR))
ALT(DEF_ASM_OP2(movsbl, 0x0fbe, 0, OPC_MODRM, OPT_REG8 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(movsbw, 0x0fbe, 0, OPC_MODRM | OPC_D16, OPT_REG8 | OPT_EA, OPT_REG16))
ALT(DEF_ASM_OP2(movswl, 0x0fbf, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(movslq, 0x4863, 0, OPC_MODRM, OPT_REG32 | OPT_EA, OPT_REG))
ALT(DEF_ASM_OP2(movzbw, 0x0fb6, 0, OPC_MODRM | OPC_WL, OPT_REG8 | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(movzwl, 0x0fb7, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP1(pushw, 0x50, 0, OPC_REG | OPC_WLQ, OPT_REG64))
ALT(DEF_ASM_OP1(pushw, 0xff, 6, OPC_MODRM | OPC_WLQ, OPT_REG64 | OPT_EA))
ALT(DEF_ASM_OP1(pushw, 0x68, 0, OPC_WLQ, OPT_IM32))
ALT(DEF_ASM_OP1(pushw, 0x06, 0, OPC_WLQ, OPT_SEG))
DEF_ASM_OP1(pushb, 0x6a, 0, OPC_B, OPT_IM8S)
ALT(DEF_ASM_OP1(popw, 0x58, 0, OPC_REG | OPC_WLQ, OPT_REGW))
ALT(DEF_ASM_OP1(popw, 0x8f, 0, OPC_MODRM | OPC_WLQ, OPT_REGW | OPT_EA))
ALT(DEF_ASM_OP1(popw, 0x07, 0, OPC_WLQ, OPT_SEG))
ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WLQ, OPT_REG, OPT_EAX))
ALT(DEF_ASM_OP2(xchgw, 0x90, 0, OPC_REG | OPC_WLQ, OPT_EAX, OPT_REG))
ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWLQ, OPT_REG, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(xchgb, 0x86, 0, OPC_MODRM | OPC_BWLQ, OPT_EA | OPT_REG, OPT_REG))
ALT(DEF_ASM_OP2(inb, 0xe4, 0, OPC_BWL, OPT_IM8, OPT_EAX))
ALT(DEF_ASM_OP1(inb, 0xe4, 0, OPC_BWL, OPT_IM8))
ALT(DEF_ASM_OP2(inb, 0xec, 0, OPC_BWL, OPT_DX, OPT_EAX))
ALT(DEF_ASM_OP1(inb, 0xec, 0, OPC_BWL, OPT_DX))
ALT(DEF_ASM_OP2(outb, 0xe6, 0, OPC_BWL, OPT_EAX, OPT_IM8))
ALT(DEF_ASM_OP1(outb, 0xe6, 0, OPC_BWL, OPT_IM8))
ALT(DEF_ASM_OP2(outb, 0xee, 0, OPC_BWL, OPT_EAX, OPT_DX))
ALT(DEF_ASM_OP1(outb, 0xee, 0, OPC_BWL, OPT_DX))
ALT(DEF_ASM_OP2(leaw, 0x8d, 0, OPC_MODRM | OPC_WLQ, OPT_EA, OPT_REG))
ALT(DEF_ASM_OP2(les, 0xc4, 0, OPC_MODRM, OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(lds, 0xc5, 0, OPC_MODRM, OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(lss, 0x0fb2, 0, OPC_MODRM, OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(lfs, 0x0fb4, 0, OPC_MODRM, OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(lgs, 0x0fb5, 0, OPC_MODRM, OPT_EA, OPT_REG32))
/* arith */
ALT(DEF_ASM_OP2(addb, 0x00, 0, OPC_ARITH | OPC_MODRM | OPC_BWLQ, OPT_REG, OPT_EA | OPT_REG)) /* XXX: use D bit ? */
ALT(DEF_ASM_OP2(addb, 0x02, 0, OPC_ARITH | OPC_MODRM | OPC_BWLQ, OPT_EA | OPT_REG, OPT_REG))
ALT(DEF_ASM_OP2(addb, 0x04, 0, OPC_ARITH | OPC_BWLQ, OPT_IMNO64, OPT_EAX))
ALT(DEF_ASM_OP2(addb, 0x80, 0, OPC_ARITH | OPC_MODRM | OPC_BWLQ, OPT_IMNO64, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(addw, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WLQ, OPT_IM8S, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWLQ, OPT_EA | OPT_REG, OPT_REG))
ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWLQ, OPT_REG, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(testb, 0xa8, 0, OPC_BWLQ, OPT_IMNO64, OPT_EAX))
ALT(DEF_ASM_OP2(testb, 0xf6, 0, OPC_MODRM | OPC_BWLQ, OPT_IMNO64, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP1(incw, 0x40, 0, OPC_REG | OPC_WLQ, OPT_REGW))
ALT(DEF_ASM_OP1(incb, 0xfe, 0, OPC_MODRM | OPC_BWLQ, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP1(decw, 0x48, 0, OPC_REG | OPC_WLQ, OPT_REGW))
ALT(DEF_ASM_OP1(decb, 0xfe, 1, OPC_MODRM | OPC_BWLQ, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP1(notb, 0xf6, 2, OPC_MODRM | OPC_BWLQ, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP1(negb, 0xf6, 3, OPC_MODRM | OPC_BWLQ, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP1(mulb, 0xf6, 4, OPC_MODRM | OPC_BWLQ, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP1(imulb, 0xf6, 5, OPC_MODRM | OPC_BWLQ, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP2(imulw, 0x0faf, 0, OPC_MODRM | OPC_WLQ, OPT_REG | OPT_EA, OPT_REG))
ALT(DEF_ASM_OP3(imulw, 0x6b, 0, OPC_MODRM | OPC_WLQ, OPT_IM8S, OPT_REGW | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(imulw, 0x6b, 0, OPC_MODRM | OPC_WLQ, OPT_IM8S, OPT_REGW))
ALT(DEF_ASM_OP3(imulw, 0x69, 0, OPC_MODRM | OPC_WLQ, OPT_IMW, OPT_REGW | OPT_EA, OPT_REGW))
ALT(DEF_ASM_OP2(imulw, 0x69, 0, OPC_MODRM | OPC_WLQ, OPT_IMW, OPT_REGW))
ALT(DEF_ASM_OP1(divb, 0xf6, 6, OPC_MODRM | OPC_BWLQ, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP2(divb, 0xf6, 6, OPC_MODRM | OPC_BWLQ, OPT_REG | OPT_EA, OPT_EAX))
ALT(DEF_ASM_OP1(idivb, 0xf6, 7, OPC_MODRM | OPC_BWLQ, OPT_REG | OPT_EA))
ALT(DEF_ASM_OP2(idivb, 0xf6, 7, OPC_MODRM | OPC_BWLQ, OPT_REG | OPT_EA, OPT_EAX))
/* shifts */
ALT(DEF_ASM_OP2(rolb, 0xc0, 0, OPC_MODRM | OPC_BWLQ | OPC_SHIFT, OPT_IM8, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP2(rolb, 0xd2, 0, OPC_MODRM | OPC_BWLQ | OPC_SHIFT, OPT_CL, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP1(rolb, 0xd0, 0, OPC_MODRM | OPC_BWLQ | OPC_SHIFT, OPT_EA | OPT_REG))
ALT(DEF_ASM_OP3(shldw, 0x0fa4, 0, OPC_MODRM | OPC_WLQ, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP3(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WLQ, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP2(shldw, 0x0fa5, 0, OPC_MODRM | OPC_WLQ, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP3(shrdw, 0x0fac, 0, OPC_MODRM | OPC_WLQ, OPT_IM8, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP3(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WLQ, OPT_CL, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP2(shrdw, 0x0fad, 0, OPC_MODRM | OPC_WLQ, OPT_REGW, OPT_EA | OPT_REGW))
ALT(DEF_ASM_OP1(call, 0xff, 2, OPC_MODRM, OPT_INDIR))
ALT(DEF_ASM_OP1(call, 0xe8, 0, OPC_JMP, OPT_ADDR))
ALT(DEF_ASM_OP1(jmp, 0xff, 4, OPC_MODRM, OPT_INDIR))
ALT(DEF_ASM_OP1(jmp, 0xff, 0, OPC_JMP | OPC_WL, OPT_REGW))
ALT(DEF_ASM_OP1(jmp, 0xeb, 0, OPC_SHORTJMP | OPC_JMP, OPT_ADDR))
ALT(DEF_ASM_OP1(lcall, 0xff, 3, 0, OPT_EA))
ALT(DEF_ASM_OP1(ljmp, 0xff, 5, 0, OPT_EA))
ALT(DEF_ASM_OP1(int, 0xcd, 0, 0, OPT_IM8))
ALT(DEF_ASM_OP1(seto, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA))
ALT(DEF_ASM_OP1(setob, 0x0f90, 0, OPC_MODRM | OPC_TEST, OPT_REG8 | OPT_EA))
DEF_ASM_OP2(enter, 0xc8, 0, 0, OPT_IM16, OPT_IM8)
DEF_ASM_OP0(leave, 0xc9)
DEF_ASM_OP0(ret, 0xc3)
ALT(DEF_ASM_OP1(ret, 0xc2, 0, 0, OPT_IM16))
DEF_ASM_OP0(lret, 0xcb)
ALT(DEF_ASM_OP1(lret, 0xca, 0, 0, OPT_IM16))
ALT(DEF_ASM_OP1(jo, 0x70, 0, OPC_SHORTJMP | OPC_JMP | OPC_TEST, OPT_ADDR))
DEF_ASM_OP1(loopne, 0xe0, 0, OPC_SHORTJMP, OPT_ADDR)
DEF_ASM_OP1(loopnz, 0xe0, 0, OPC_SHORTJMP, OPT_ADDR)
DEF_ASM_OP1(loope, 0xe1, 0, OPC_SHORTJMP, OPT_ADDR)
DEF_ASM_OP1(loopz, 0xe1, 0, OPC_SHORTJMP, OPT_ADDR)
DEF_ASM_OP1(loop, 0xe2, 0, OPC_SHORTJMP, OPT_ADDR)
DEF_ASM_OP1(jecxz, 0xe3, 0, OPC_SHORTJMP, OPT_ADDR)
/* float */
/* specific fcomp handling */
ALT(DEF_ASM_OP0L(fcomp, 0xd8d9, 0, 0))
ALT(DEF_ASM_OP1(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST))
ALT(DEF_ASM_OP2(fadd, 0xd8c0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0))
ALT(DEF_ASM_OP0L(fadd, 0xdec1, 0, OPC_FARITH))
ALT(DEF_ASM_OP1(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST))
ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST, OPT_ST0))
ALT(DEF_ASM_OP2(faddp, 0xdec0, 0, OPC_FARITH | OPC_REG, OPT_ST0, OPT_ST))
ALT(DEF_ASM_OP0L(faddp, 0xdec1, 0, OPC_FARITH))
ALT(DEF_ASM_OP1(fadds, 0xd8, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
ALT(DEF_ASM_OP1(fiaddl, 0xda, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
ALT(DEF_ASM_OP1(faddl, 0xdc, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
ALT(DEF_ASM_OP1(fiadds, 0xde, 0, OPC_FARITH | OPC_MODRM, OPT_EA))
DEF_ASM_OP0(fucompp, 0xdae9)
DEF_ASM_OP0(ftst, 0xd9e4)
DEF_ASM_OP0(fxam, 0xd9e5)
DEF_ASM_OP0(fld1, 0xd9e8)
DEF_ASM_OP0(fldl2t, 0xd9e9)
DEF_ASM_OP0(fldl2e, 0xd9ea)
DEF_ASM_OP0(fldpi, 0xd9eb)
DEF_ASM_OP0(fldlg2, 0xd9ec)
DEF_ASM_OP0(fldln2, 0xd9ed)
DEF_ASM_OP0(fldz, 0xd9ee)
DEF_ASM_OP0(f2xm1, 0xd9f0)
DEF_ASM_OP0(fyl2x, 0xd9f1)
DEF_ASM_OP0(fptan, 0xd9f2)
DEF_ASM_OP0(fpatan, 0xd9f3)
DEF_ASM_OP0(fxtract, 0xd9f4)
DEF_ASM_OP0(fprem1, 0xd9f5)
DEF_ASM_OP0(fdecstp, 0xd9f6)
DEF_ASM_OP0(fincstp, 0xd9f7)
DEF_ASM_OP0(fprem, 0xd9f8)
DEF_ASM_OP0(fyl2xp1, 0xd9f9)
DEF_ASM_OP0(fsqrt, 0xd9fa)
DEF_ASM_OP0(fsincos, 0xd9fb)
DEF_ASM_OP0(frndint, 0xd9fc)
DEF_ASM_OP0(fscale, 0xd9fd)
DEF_ASM_OP0(fsin, 0xd9fe)
DEF_ASM_OP0(fcos, 0xd9ff)
DEF_ASM_OP0(fchs, 0xd9e0)
DEF_ASM_OP0(fabs, 0xd9e1)
DEF_ASM_OP0(fninit, 0xdbe3)
DEF_ASM_OP0(fnclex, 0xdbe2)
DEF_ASM_OP0(fnop, 0xd9d0)
DEF_ASM_OP0(fwait, 0x9b)
/* fp load */
DEF_ASM_OP1(fld, 0xd9c0, 0, OPC_REG, OPT_ST)
DEF_ASM_OP1(fldl, 0xd9c0, 0, OPC_REG, OPT_ST)
DEF_ASM_OP1(flds, 0xd9, 0, OPC_MODRM, OPT_EA)
ALT(DEF_ASM_OP1(fldl, 0xdd, 0, OPC_MODRM, OPT_EA))
DEF_ASM_OP1(fildl, 0xdb, 0, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fildq, 0xdf, 5, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fildll, 0xdf, 5, OPC_MODRM,OPT_EA)
DEF_ASM_OP1(fldt, 0xdb, 5, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fbld, 0xdf, 4, OPC_MODRM, OPT_EA)
/* fp store */
DEF_ASM_OP1(fst, 0xddd0, 0, OPC_REG, OPT_ST)
DEF_ASM_OP1(fstl, 0xddd0, 0, OPC_REG, OPT_ST)
DEF_ASM_OP1(fsts, 0xd9, 2, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fstps, 0xd9, 3, OPC_MODRM, OPT_EA)
ALT(DEF_ASM_OP1(fstl, 0xdd, 2, OPC_MODRM, OPT_EA))
DEF_ASM_OP1(fstpl, 0xdd, 3, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fist, 0xdf, 2, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fistp, 0xdf, 3, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fistl, 0xdb, 2, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fistpl, 0xdb, 3, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fstp, 0xddd8, 0, OPC_REG, OPT_ST)
DEF_ASM_OP1(fistpq, 0xdf, 7, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fistpll, 0xdf, 7, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fstpt, 0xdb, 7, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(fbstp, 0xdf, 6, OPC_MODRM, OPT_EA)
/* exchange */
DEF_ASM_OP0(fxch, 0xd9c9)
ALT(DEF_ASM_OP1(fxch, 0xd9c8, 0, OPC_REG, OPT_ST))
/* misc FPU */
DEF_ASM_OP1(fucom, 0xdde0, 0, OPC_REG, OPT_ST )
DEF_ASM_OP1(fucomp, 0xdde8, 0, OPC_REG, OPT_ST )
DEF_ASM_OP0L(finit, 0xdbe3, 0, OPC_FWAIT)
DEF_ASM_OP1(fldcw, 0xd9, 5, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fnstcw, 0xd9, 7, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fstcw, 0xd9, 7, OPC_MODRM | OPC_FWAIT, OPT_EA )
DEF_ASM_OP0(fnstsw, 0xdfe0)
ALT(DEF_ASM_OP1(fnstsw, 0xdfe0, 0, 0, OPT_EAX ))
ALT(DEF_ASM_OP1(fnstsw, 0xdd, 7, OPC_MODRM, OPT_EA ))
DEF_ASM_OP1(fstsw, 0xdfe0, 0, OPC_FWAIT, OPT_EAX )
ALT(DEF_ASM_OP0L(fstsw, 0xdfe0, 0, OPC_FWAIT))
ALT(DEF_ASM_OP1(fstsw, 0xdd, 7, OPC_MODRM | OPC_FWAIT, OPT_EA ))
DEF_ASM_OP0L(fclex, 0xdbe2, 0, OPC_FWAIT)
DEF_ASM_OP1(fnstenv, 0xd9, 6, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fstenv, 0xd9, 6, OPC_MODRM | OPC_FWAIT, OPT_EA )
DEF_ASM_OP1(fldenv, 0xd9, 4, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fnsave, 0xdd, 6, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fsave, 0xdd, 6, OPC_MODRM | OPC_FWAIT, OPT_EA )
DEF_ASM_OP1(frstor, 0xdd, 4, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(ffree, 0xddc0, 4, OPC_REG, OPT_ST )
DEF_ASM_OP1(ffreep, 0xdfc0, 4, OPC_REG, OPT_ST )
DEF_ASM_OP1(fxsave, 0x0fae, 0, OPC_MODRM, OPT_EA )
DEF_ASM_OP1(fxrstor, 0x0fae, 1, OPC_MODRM, OPT_EA )
/* segments */
DEF_ASM_OP2(arpl, 0x63, 0, OPC_MODRM, OPT_REG16, OPT_REG16 | OPT_EA)
DEF_ASM_OP2(lar, 0x0f02, 0, OPC_MODRM, OPT_REG32 | OPT_EA, OPT_REG32)
DEF_ASM_OP1(lgdt, 0x0f01, 2, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(lidt, 0x0f01, 3, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(lldt, 0x0f00, 2, OPC_MODRM, OPT_EA | OPT_REG)
DEF_ASM_OP1(lmsw, 0x0f01, 6, OPC_MODRM, OPT_EA | OPT_REG)
ALT(DEF_ASM_OP2(lslw, 0x0f03, 0, OPC_MODRM | OPC_WL, OPT_EA | OPT_REG, OPT_REG))
DEF_ASM_OP1(ltr, 0x0f00, 3, OPC_MODRM, OPT_EA | OPT_REG)
DEF_ASM_OP1(sgdt, 0x0f01, 0, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(sidt, 0x0f01, 1, OPC_MODRM, OPT_EA)
DEF_ASM_OP1(sldt, 0x0f00, 0, OPC_MODRM, OPT_REG | OPT_EA)
DEF_ASM_OP1(smsw, 0x0f01, 4, OPC_MODRM, OPT_REG | OPT_EA)
DEF_ASM_OP1(str, 0x0f00, 1, OPC_MODRM, OPT_REG16| OPT_EA)
DEF_ASM_OP1(verr, 0x0f00, 4, OPC_MODRM, OPT_REG | OPT_EA)
DEF_ASM_OP1(verw, 0x0f00, 5, OPC_MODRM, OPT_REG | OPT_EA)
/* 486 */
DEF_ASM_OP1(bswap, 0x0fc8, 0, OPC_REG, OPT_REG32 )
ALT(DEF_ASM_OP2(xaddb, 0x0fc0, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_REG | OPT_EA ))
ALT(DEF_ASM_OP2(cmpxchgb, 0x0fb0, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_REG | OPT_EA ))
DEF_ASM_OP1(invlpg, 0x0f01, 7, OPC_MODRM, OPT_EA )
DEF_ASM_OP2(boundl, 0x62, 0, OPC_MODRM, OPT_REG32, OPT_EA)
DEF_ASM_OP2(boundw, 0x62, 0, OPC_MODRM | OPC_D16, OPT_REG16, OPT_EA)
/* pentium */
DEF_ASM_OP1(cmpxchg8b, 0x0fc7, 1, OPC_MODRM, OPT_EA )
/* pentium pro */
ALT(DEF_ASM_OP2(cmovo, 0x0f40, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(cmovno, 0x0f41, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(cmovc, 0x0f42, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(cmovnc, 0x0f43, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(cmovz, 0x0f44, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(cmovnz, 0x0f45, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(cmovna, 0x0f46, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
ALT(DEF_ASM_OP2(cmova, 0x0f47, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
DEF_ASM_OP2(fcmovb, 0xdac0, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmove, 0xdac8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovbe, 0xdad0, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovu, 0xdad8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovnb, 0xdbc0, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovne, 0xdbc8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovnbe, 0xdbd0, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcmovnu, 0xdbd8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fucomi, 0xdbe8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcomi, 0xdbf0, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fucomip, 0xdfe8, 0, OPC_REG, OPT_ST, OPT_ST0 )
DEF_ASM_OP2(fcomip, 0xdff0, 0, OPC_REG, OPT_ST, OPT_ST0 )
/* mmx */
DEF_ASM_OP0(emms, 0x0f77) /* must be last OP0 */
DEF_ASM_OP2(movd, 0x0f6e, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_MMX )
ALT(DEF_ASM_OP2(movd, 0x0f7e, 0, OPC_MODRM, OPT_MMX, OPT_EA | OPT_REG32 ))
ALT(DEF_ASM_OP2(movq, 0x0f6f, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX ))
ALT(DEF_ASM_OP2(movq, 0x0f7f, 0, OPC_MODRM, OPT_MMX, OPT_EA | OPT_MMX ))
DEF_ASM_OP2(packssdw, 0x0f6b, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(packsswb, 0x0f63, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(packuswb, 0x0f67, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddb, 0x0ffc, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddw, 0x0ffd, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddd, 0x0ffe, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddsb, 0x0fec, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddsw, 0x0fed, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddusb, 0x0fdc, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(paddusw, 0x0fdd, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pand, 0x0fdb, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pandn, 0x0fdf, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpeqb, 0x0f74, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpeqw, 0x0f75, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpeqd, 0x0f76, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpgtb, 0x0f64, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpgtw, 0x0f65, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pcmpgtd, 0x0f66, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pmaddwd, 0x0ff5, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pmulhw, 0x0fe5, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pmullw, 0x0fd5, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(por, 0x0feb, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psllw, 0x0ff1, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psllw, 0x0f71, 6, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(pslld, 0x0ff2, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(pslld, 0x0f72, 6, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psllq, 0x0ff3, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psllq, 0x0f73, 6, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psraw, 0x0fe1, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psraw, 0x0f71, 4, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psrad, 0x0fe2, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psrad, 0x0f72, 4, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psrlw, 0x0fd1, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psrlw, 0x0f71, 2, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psrld, 0x0fd2, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psrld, 0x0f72, 2, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psrlq, 0x0fd3, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
ALT(DEF_ASM_OP2(psrlq, 0x0f73, 2, OPC_MODRM, OPT_IM8, OPT_MMX ))
DEF_ASM_OP2(psubb, 0x0ff8, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubw, 0x0ff9, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubd, 0x0ffa, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubsb, 0x0fe8, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubsw, 0x0fe9, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubusb, 0x0fd8, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(psubusw, 0x0fd9, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpckhbw, 0x0f68, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpckhwd, 0x0f69, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpckhdq, 0x0f6a, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpcklbw, 0x0f60, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpcklwd, 0x0f61, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(punpckldq, 0x0f62, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pxor, 0x0fef, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
/* sse */
DEF_ASM_OP2(movups, 0x0f10, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE )
ALT(DEF_ASM_OP2(movups, 0x0f11, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 ))
DEF_ASM_OP2(movaps, 0x0f28, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE )
ALT(DEF_ASM_OP2(movaps, 0x0f29, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 ))
DEF_ASM_OP2(movhps, 0x0f16, 0, OPC_MODRM, OPT_EA | OPT_REG32, OPT_SSE )
ALT(DEF_ASM_OP2(movhps, 0x0f17, 0, OPC_MODRM, OPT_SSE, OPT_EA | OPT_REG32 ))
DEF_ASM_OP2(addps, 0x0f58, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(cvtpi2ps, 0x0f2a, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_SSE )
DEF_ASM_OP2(cvtps2pi, 0x0f2d, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_MMX )
DEF_ASM_OP2(cvttps2pi, 0x0f2c, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_MMX )
DEF_ASM_OP2(divps, 0x0f5e, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(maxps, 0x0f5f, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(minps, 0x0f5d, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(mulps, 0x0f59, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(pavgb, 0x0fe0, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(pavgw, 0x0fe3, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(pmaxsw, 0x0fee, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pmaxub, 0x0fde, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pminsw, 0x0fea, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(pminub, 0x0fda, 0, OPC_MODRM, OPT_EA | OPT_MMX, OPT_MMX )
DEF_ASM_OP2(rcpss, 0x0f53, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(rsqrtps, 0x0f52, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(sqrtps, 0x0f51, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
DEF_ASM_OP2(subps, 0x0f5c, 0, OPC_MODRM, OPT_EA | OPT_SSE, OPT_SSE )
#undef ALT
#undef DEF_ASM_OP0
#undef DEF_ASM_OP0L
#undef DEF_ASM_OP1
#undef DEF_ASM_OP2
#undef DEF_ASM_OP3

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -122,12 +122,12 @@ bool CheckAPIVer(CCStr ver)
/* --------------------------------------------------------------------------------------------
* React to command sent by other plugins.
*/
static int OnInternalCommand(unsigned int type, const char * text)
static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
{
switch(type)
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(text))
if (CheckAPIVer(message))
{
OnSquirrelInitialize();
}
@ -146,12 +146,12 @@ static int OnInternalCommand(unsigned int type, const char * text)
/* --------------------------------------------------------------------------------------------
* The server was initialized and this plugin was loaded successfully.
*/
static int OnInitServer()
static uint8_t OnServerInitialise()
{
return 1;
}
static void OnShutdownServer(void)
static void OnServerShutdown(void)
{
// The server may still send callbacks
UnbindCallbacks();
@ -160,17 +160,17 @@ static void OnShutdownServer(void)
// ------------------------------------------------------------------------------------------------
void BindCallbacks()
{
_Clbk->OnInitServer = OnInitServer;
_Clbk->OnInternalCommand = OnInternalCommand;
_Clbk->OnShutdownServer = OnShutdownServer;
_Clbk->OnServerInitialise = OnServerInitialise;
_Clbk->OnServerShutdown = OnServerShutdown;
_Clbk->OnPluginCommand = OnPluginCommand;
}
// ------------------------------------------------------------------------------------------------
void UnbindCallbacks()
{
_Clbk->OnInitServer = nullptr;
_Clbk->OnInternalCommand = nullptr;
_Clbk->OnShutdownServer = nullptr;
_Clbk->OnServerInitialise = nullptr;
_Clbk->OnServerShutdown = nullptr;
_Clbk->OnPluginCommand = nullptr;
}
// --------------------------------------------------------------------------------------------
@ -297,17 +297,17 @@ void OutputMessageImpl(const char * msg, va_list args)
CONSOLE_SCREEN_BUFFER_INFO csb_before;
GetConsoleScreenBufferInfo( hstdout, &csb_before);
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN);
printf("[SQMOD] ");
std::printf("[SQMOD] ");
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
vprintf(msg, args);
puts("");
std::vprintf(msg, args);
std::puts("");
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
#else
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
vprintf(msg, args);
puts("");
std::printf("%c[0;32m[SQMOD]%c[0m", 27, 27);
std::vprintf(msg, args);
std::puts("");
#endif
}
@ -320,17 +320,17 @@ void OutputErrorImpl(const char * msg, va_list args)
CONSOLE_SCREEN_BUFFER_INFO csb_before;
GetConsoleScreenBufferInfo( hstdout, &csb_before);
SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
printf("[SQMOD] ");
std::printf("[SQMOD] ");
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
vprintf(msg, args);
puts("");
std::vprintf(msg, args);
std::puts("");
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
#else
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
vprintf(msg, args);
puts("");
std::printf("%c[0;91m[SQMOD]%c[0m", 27, 27);
std::vprintf(msg, args);
std::puts("");
#endif
}
@ -398,7 +398,7 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallb
return SQMOD_FAILURE;
}
// Should never reach this point but just in case
else if (host_plugin_id > (info->nPluginId))
else if (static_cast< Uint32 >(host_plugin_id) > info->pluginId)
{
OutputError("%s loaded after the host plugin", SQINI_NAME);
// Don't load!
@ -408,9 +408,12 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallb
_Func = functions;
_Clbk = callbacks;
_Info = info;
// Assign plugin information
_Info->uPluginVer = SQINI_VERSION;
std::strcpy(_Info->szName, SQINI_HOST_NAME);
// Assign plugin version
_Info->pluginVersion = SQINI_VERSION;
_Info->apiMajorVersion = PLUGIN_API_MAJOR;
_Info->apiMinorVersion = PLUGIN_API_MINOR;
// Assign the plugin name
std::snprintf(_Info->name, sizeof(_Info->name), "%s", SQINI_HOST_NAME);
// Bind callbacks
BindCallbacks();
// Notify that the plugin was successfully loaded

View File

@ -102,15 +102,6 @@ void OnSquirrelTerminate()
DefaultVM::Set(nullptr);
}
/* --------------------------------------------------------------------------------------------
* Update the plugin on each frame.
*/
static void OnFrame(float /*delta*/)
{
// Update the sessions and pool for events
Session::Process();
}
/* --------------------------------------------------------------------------------------------
* Validate the module API to make sure we don't run into issues.
*/
@ -133,12 +124,12 @@ bool CheckAPIVer(CCStr ver)
/* --------------------------------------------------------------------------------------------
* React to command sent by other plugins.
*/
static int OnInternalCommand(unsigned int type, const char * text)
static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
{
switch(type)
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(text))
if (CheckAPIVer(message))
{
OnSquirrelInitialize();
}
@ -157,33 +148,42 @@ static int OnInternalCommand(unsigned int type, const char * text)
/* --------------------------------------------------------------------------------------------
* The server was initialized and this plugin was loaded successfully.
*/
static int OnInitServer()
static uint8_t OnServerInitialise()
{
return 1;
}
static void OnShutdownServer(void)
static void OnServerShutdown(void)
{
// The server may still send callbacks
UnbindCallbacks();
}
/* --------------------------------------------------------------------------------------------
* Update the plugin on each frame.
*/
static void OnServerFrame(float /*delta*/)
{
// Update the sessions and pool for events
Session::Process();
}
// ------------------------------------------------------------------------------------------------
void BindCallbacks()
{
_Clbk->OnInitServer = OnInitServer;
_Clbk->OnFrame = OnFrame;
_Clbk->OnInternalCommand = OnInternalCommand;
_Clbk->OnShutdownServer = OnShutdownServer;
_Clbk->OnServerInitialise = OnServerInitialise;
_Clbk->OnServerShutdown = OnServerShutdown;
_Clbk->OnServerFrame = OnServerFrame;
_Clbk->OnPluginCommand = OnPluginCommand;
}
// ------------------------------------------------------------------------------------------------
void UnbindCallbacks()
{
_Clbk->OnInitServer = nullptr;
_Clbk->OnFrame = nullptr;
_Clbk->OnInternalCommand = nullptr;
_Clbk->OnShutdownServer = nullptr;
_Clbk->OnServerInitialise = nullptr;
_Clbk->OnServerShutdown = nullptr;
_Clbk->OnServerFrame = nullptr;
_Clbk->OnPluginCommand = nullptr;
}
// --------------------------------------------------------------------------------------------
@ -496,17 +496,17 @@ void OutputMessageImpl(const char * msg, va_list args)
CONSOLE_SCREEN_BUFFER_INFO csb_before;
GetConsoleScreenBufferInfo( hstdout, &csb_before);
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN);
printf("[SQMOD] ");
std::printf("[SQMOD] ");
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
vprintf(msg, args);
puts("");
std::vprintf(msg, args);
std::puts("");
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
#else
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
vprintf(msg, args);
puts("");
std::printf("%c[0;32m[SQMOD]%c[0m", 27, 27);
std::vprintf(msg, args);
std::puts("");
#endif
}
@ -519,17 +519,17 @@ void OutputErrorImpl(const char * msg, va_list args)
CONSOLE_SCREEN_BUFFER_INFO csb_before;
GetConsoleScreenBufferInfo( hstdout, &csb_before);
SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
printf("[SQMOD] ");
std::printf("[SQMOD] ");
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
vprintf(msg, args);
puts("");
std::vprintf(msg, args);
std::puts("");
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
#else
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
vprintf(msg, args);
puts("");
std::printf("%c[0;91m[SQMOD]%c[0m", 27, 27);
std::vprintf(msg, args);
std::puts("");
#endif
}
@ -597,7 +597,7 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallb
return SQMOD_FAILURE;
}
// Should never reach this point but just in case
else if (host_plugin_id > (info->nPluginId))
else if (static_cast< Uint32 >(host_plugin_id) > info->pluginId)
{
OutputError("%s loaded after the host plugin", SQIRC_NAME);
// Don't load!
@ -616,9 +616,12 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallb
_Func = functions;
_Clbk = callbacks;
_Info = info;
// Assign plugin information
_Info->uPluginVer = SQIRC_VERSION;
std::strcpy(_Info->szName, SQIRC_HOST_NAME);
// Assign plugin version
_Info->pluginVersion = SQIRC_VERSION;
_Info->apiMajorVersion = PLUGIN_API_MAJOR;
_Info->apiMinorVersion = PLUGIN_API_MINOR;
// Assign the plugin name
std::snprintf(_Info->name, sizeof(_Info->name), "%s", SQIRC_HOST_NAME);
// Bind callbacks
BindCallbacks();
// Notify that the plugin was successfully loaded

View File

@ -18,14 +18,14 @@
namespace SqMod {
// --------------------------------------------------------------------------------------------
PluginFuncs* _Func = NULL;
PluginCallbacks* _Clbk = NULL;
PluginInfo* _Info = NULL;
PluginFuncs* _Func = nullptr;
PluginCallbacks* _Clbk = nullptr;
PluginInfo* _Info = nullptr;
// --------------------------------------------------------------------------------------------
HSQAPI _SqAPI = NULL;
HSQEXPORTS _SqMod = NULL;
HSQUIRRELVM _SqVM = NULL;
HSQAPI _SqAPI = nullptr;
HSQEXPORTS _SqMod = nullptr;
HSQUIRRELVM _SqVM = nullptr;
/* ------------------------------------------------------------------------------------------------
* Bind speciffic functions to certain server events.
@ -89,7 +89,7 @@ void OnSquirrelTerminate()
{
OutputMessage("Terminating: %s", SQMMDB_NAME);
// Release the current database (if any)
DefaultVM::Set(NULL);
DefaultVM::Set(nullptr);
// Release script resources...
}
@ -99,7 +99,7 @@ void OnSquirrelTerminate()
bool CheckAPIVer(CCStr ver)
{
// Obtain the numeric representation of the API version
long vernum = strtol(ver, NULL, 10);
long vernum = strtol(ver, nullptr, 10);
// Check against version mismatch
if (vernum == SQMOD_API_VER)
return true;
@ -113,12 +113,12 @@ bool CheckAPIVer(CCStr ver)
/* --------------------------------------------------------------------------------------------
* React to command sent by other plugins.
*/
static int OnInternalCommand(unsigned int type, const char * text)
static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
{
switch(type)
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(text))
if (CheckAPIVer(message))
OnSquirrelInitialize();
break;
case SQMOD_LOAD_CMD:
@ -135,12 +135,12 @@ static int OnInternalCommand(unsigned int type, const char * text)
/* --------------------------------------------------------------------------------------------
* The server was initialized and this plugin was loaded successfully.
*/
static int OnInitServer()
static uint8_t OnServerInitialise()
{
return 1;
}
static void OnShutdownServer(void)
static void OnServerShutdown(void)
{
// The server may still send callbacks
UnbindCallbacks();
@ -149,17 +149,17 @@ static void OnShutdownServer(void)
// ------------------------------------------------------------------------------------------------
void BindCallbacks()
{
_Clbk->OnInitServer = OnInitServer;
_Clbk->OnInternalCommand = OnInternalCommand;
_Clbk->OnShutdownServer = OnShutdownServer;
_Clbk->OnServerInitialise = OnServerInitialise;
_Clbk->OnServerShutdown = OnServerShutdown;
_Clbk->OnPluginCommand = OnPluginCommand;
}
// ------------------------------------------------------------------------------------------------
void UnbindCallbacks()
{
_Clbk->OnInitServer = NULL;
_Clbk->OnInternalCommand = NULL;
_Clbk->OnShutdownServer = NULL;
_Clbk->OnServerInitialise = nullptr;
_Clbk->OnServerShutdown = nullptr;
_Clbk->OnPluginCommand = nullptr;
}
// --------------------------------------------------------------------------------------------
@ -177,17 +177,17 @@ void OutputMessageImpl(const char * msg, va_list args)
CONSOLE_SCREEN_BUFFER_INFO csb_before;
GetConsoleScreenBufferInfo( hstdout, &csb_before);
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN);
printf("[SQMOD] ");
std::printf("[SQMOD] ");
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
vprintf(msg, args);
puts("");
std::vprintf(msg, args);
std::puts("");
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
#else
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
vprintf(msg, args);
puts("");
std::printf("%c[0;32m[SQMOD]%c[0m", 27, 27);
std::vprintf(msg, args);
std::puts("");
#endif
}
@ -200,17 +200,17 @@ void OutputErrorImpl(const char * msg, va_list args)
CONSOLE_SCREEN_BUFFER_INFO csb_before;
GetConsoleScreenBufferInfo( hstdout, &csb_before);
SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
printf("[SQMOD] ");
std::printf("[SQMOD] ");
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
vprintf(msg, args);
puts("");
std::vprintf(msg, args);
std::puts("");
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
#else
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
vprintf(msg, args);
puts("");
std::printf("%c[0;91m[SQMOD]%c[0m", 27, 27);
std::vprintf(msg, args);
std::puts("");
#endif
}
@ -288,9 +288,12 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallb
_Func = functions;
_Clbk = callbacks;
_Info = info;
// Assign plugin information
_Info->uPluginVer = SQMMDB_VERSION;
strcpy(_Info->szName, SQMMDB_HOST_NAME);
// Assign plugin version
_Info->pluginVersion = SQMMDB_VERSION;
_Info->apiMajorVersion = PLUGIN_API_MAJOR;
_Info->apiMinorVersion = PLUGIN_API_MINOR;
// Assign the plugin name
std::snprintf(_Info->name, sizeof(_Info->name), "%s", SQMMDB_HOST_NAME);
// Bind callbacks
BindCallbacks();
// Notify that the plugin was successfully loaded

View File

@ -122,12 +122,12 @@ bool CheckAPIVer(CCStr ver)
/* --------------------------------------------------------------------------------------------
* React to command sent by other plugins.
*/
static int OnInternalCommand(unsigned int type, const char * text)
static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
{
switch(type)
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(text))
if (CheckAPIVer(message))
{
OnSquirrelInitialize();
}
@ -146,12 +146,12 @@ static int OnInternalCommand(unsigned int type, const char * text)
/* --------------------------------------------------------------------------------------------
* The server was initialized and this plugin was loaded successfully.
*/
static int OnInitServer()
static uint8_t OnServerInitialise()
{
return 1;
}
static void OnShutdownServer(void)
static void OnServerShutdown(void)
{
// The server may still send callbacks
UnbindCallbacks();
@ -160,17 +160,17 @@ static void OnShutdownServer(void)
// ------------------------------------------------------------------------------------------------
void BindCallbacks()
{
_Clbk->OnInitServer = OnInitServer;
_Clbk->OnInternalCommand = OnInternalCommand;
_Clbk->OnShutdownServer = OnShutdownServer;
_Clbk->OnServerInitialise = OnServerInitialise;
_Clbk->OnServerShutdown = OnServerShutdown;
_Clbk->OnPluginCommand = OnPluginCommand;
}
// ------------------------------------------------------------------------------------------------
void UnbindCallbacks()
{
_Clbk->OnInitServer = nullptr;
_Clbk->OnInternalCommand = nullptr;
_Clbk->OnShutdownServer = nullptr;
_Clbk->OnServerInitialise = nullptr;
_Clbk->OnServerShutdown = nullptr;
_Clbk->OnPluginCommand = nullptr;
}
// --------------------------------------------------------------------------------------------
@ -204,7 +204,7 @@ void OutputMessageImpl(const char * msg, va_list args)
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
#else
std::printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
std::printf("%c[0;32m[SQMOD]%c[0m", 27, 27);
std::vprintf(msg, args);
std::puts("");
#endif
@ -227,7 +227,7 @@ void OutputErrorImpl(const char * msg, va_list args)
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
#else
std::printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
std::printf("%c[0;91m[SQMOD]%c[0m", 27, 27);
std::vprintf(msg, args);
std::puts("");
#endif
@ -297,7 +297,7 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallb
return SQMOD_FAILURE;
}
// Should never reach this point but just in case
else if (host_plugin_id > (info->nPluginId))
else if (static_cast< Uint32 >(host_plugin_id) > info->pluginId)
{
OutputError("%s loaded after the host plugin", SQSAMPLE_NAME);
// Don't load!
@ -307,9 +307,12 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallb
_Func = functions;
_Clbk = callbacks;
_Info = info;
// Assign plugin information
_Info->uPluginVer = SQSAMPLE_VERSION;
std::strcpy(_Info->szName, SQSAMPLE_HOST_NAME);
// Assign plugin version
_Info->pluginVersion = SQSAMPLE_VERSION;
_Info->apiMajorVersion = PLUGIN_API_MAJOR;
_Info->apiMinorVersion = PLUGIN_API_MINOR;
// Assign the plugin name
std::snprintf(_Info->name, sizeof(_Info->name), "%s", SQSAMPLE_HOST_NAME);
// Bind callbacks
BindCallbacks();
// Notify that the plugin was successfully loaded

View File

@ -123,12 +123,12 @@ bool CheckAPIVer(CCStr ver)
/* --------------------------------------------------------------------------------------------
* React to command sent by other plugins.
*/
static int OnInternalCommand(unsigned int type, const char * text)
static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
{
switch(type)
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(text))
if (CheckAPIVer(message))
{
OnSquirrelInitialize();
}
@ -147,12 +147,12 @@ static int OnInternalCommand(unsigned int type, const char * text)
/* --------------------------------------------------------------------------------------------
* The server was initialized and this plugin was loaded successfully.
*/
static int OnInitServer()
static uint8_t OnServerInitialise()
{
return 1;
}
static void OnShutdownServer(void)
static void OnServerShutdown(void)
{
// The server may still send callbacks
UnbindCallbacks();
@ -161,17 +161,17 @@ static void OnShutdownServer(void)
// ------------------------------------------------------------------------------------------------
void BindCallbacks()
{
_Clbk->OnInitServer = OnInitServer;
_Clbk->OnInternalCommand = OnInternalCommand;
_Clbk->OnShutdownServer = OnShutdownServer;
_Clbk->OnServerInitialise = OnServerInitialise;
_Clbk->OnServerShutdown = OnServerShutdown;
_Clbk->OnPluginCommand = OnPluginCommand;
}
// ------------------------------------------------------------------------------------------------
void UnbindCallbacks()
{
_Clbk->OnInitServer = nullptr;
_Clbk->OnInternalCommand = nullptr;
_Clbk->OnShutdownServer = nullptr;
_Clbk->OnServerInitialise = nullptr;
_Clbk->OnServerShutdown = nullptr;
_Clbk->OnPluginCommand = nullptr;
}
// --------------------------------------------------------------------------------------------
@ -712,17 +712,17 @@ void OutputMessageImpl(const char * msg, va_list args)
CONSOLE_SCREEN_BUFFER_INFO csb_before;
GetConsoleScreenBufferInfo( hstdout, &csb_before);
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN);
printf("[SQMOD] ");
std::printf("[SQMOD] ");
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
vprintf(msg, args);
puts("");
std::vprintf(msg, args);
std::puts("");
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
#else
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
vprintf(msg, args);
puts("");
std::printf("%c[0;32m[SQMOD]%c[0m", 27, 27);
std::vprintf(msg, args);
std::puts("");
#endif
}
@ -735,17 +735,17 @@ void OutputErrorImpl(const char * msg, va_list args)
CONSOLE_SCREEN_BUFFER_INFO csb_before;
GetConsoleScreenBufferInfo( hstdout, &csb_before);
SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
printf("[SQMOD] ");
std::printf("[SQMOD] ");
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
vprintf(msg, args);
puts("");
std::vprintf(msg, args);
std::puts("");
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
#else
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
vprintf(msg, args);
puts("");
std::printf("%c[0;91m[SQMOD]%c[0m", 27, 27);
std::vprintf(msg, args);
std::puts("");
#endif
}
@ -813,7 +813,7 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallb
return SQMOD_FAILURE;
}
// Should never reach this point but just in case
else if (host_plugin_id > (info->nPluginId))
else if (static_cast< Uint32 >(host_plugin_id) > info->pluginId)
{
OutputError("%s loaded after the host plugin", SQSQLITE_NAME);
// Don't load!
@ -823,9 +823,12 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallb
_Func = functions;
_Clbk = callbacks;
_Info = info;
// Assign plugin information
_Info->uPluginVer = SQSQLITE_VERSION;
std::strcpy(_Info->szName, SQSQLITE_HOST_NAME);
// Assign plugin version
_Info->pluginVersion = SQSQLITE_VERSION;
_Info->apiMajorVersion = PLUGIN_API_MAJOR;
_Info->apiMinorVersion = PLUGIN_API_MINOR;
// Assign the plugin name
std::snprintf(_Info->name, sizeof(_Info->name), "%s", SQSQLITE_HOST_NAME);
// Bind callbacks
BindCallbacks();
// Notify that the plugin was successfully loaded

View File

@ -1,607 +0,0 @@
// ------------------------------------------------------------------------------------------------
#include "Common.hpp"
#include "Module.hpp"
// ------------------------------------------------------------------------------------------------
#include <cctype>
#include <cstdio>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
#define TCC_FUNC(p) reinterpret_cast< const void * >(p)
// ------------------------------------------------------------------------------------------------
static HSQUIRRELVM GetSqVM()
{
return _SqVM;
}
// ------------------------------------------------------------------------------------------------
void RegisterAPI(StateHnd & s)
{
// Make sure the state is valid and not relocated
if (!s || s->mRelocated)
{
return;
}
// Specify whether this is a 64bit build
#ifdef _SQ64
s.DefineSymbol("__SQ64", "1");
#endif // _SQ64
// ctype.h
s.AddSymbol("isalnum", TCC_FUNC(isalnum));
s.AddSymbol("isalpha", TCC_FUNC(isalpha));
s.AddSymbol("isblank", TCC_FUNC(isblank));
s.AddSymbol("iscntrl", TCC_FUNC(iscntrl));
s.AddSymbol("isdigit", TCC_FUNC(isdigit));
s.AddSymbol("isgraph", TCC_FUNC(isgraph));
s.AddSymbol("islower", TCC_FUNC(islower));
s.AddSymbol("isprint", TCC_FUNC(isprint));
s.AddSymbol("ispunct", TCC_FUNC(ispunct));
s.AddSymbol("isspace", TCC_FUNC(isspace));
s.AddSymbol("isupper", TCC_FUNC(isupper));
s.AddSymbol("isxdigit", TCC_FUNC(isxdigit));
// stdio.h
s.AddSymbol("printf", TCC_FUNC(printf));
// Helpers
s.AddSymbol("get_sqvm", TCC_FUNC(GetSqVM));
// VC:MP
s.AddSymbol("vcGetServerVersion", TCC_FUNC(_Func->GetServerVersion));
s.AddSymbol("vcGetServerSettings", TCC_FUNC(_Func->GetServerSettings));
s.AddSymbol("vcExportFunctions", TCC_FUNC(_Func->ExportFunctions));
s.AddSymbol("vcGetNumberOfPlugins", TCC_FUNC(_Func->GetNumberOfPlugins));
s.AddSymbol("vcGetPluginInfo", TCC_FUNC(_Func->GetPluginInfo));
s.AddSymbol("vcFindPlugin", TCC_FUNC(_Func->FindPlugin));
s.AddSymbol("vcGetPluginExports", TCC_FUNC(_Func->GetPluginExports));
s.AddSymbol("vcGetTime", TCC_FUNC(_Func->GetTime));
s.AddSymbol("vcprintf", TCC_FUNC(_Func->printf));
s.AddSymbol("vcSendCustomCommand", TCC_FUNC(_Func->SendCustomCommand));
s.AddSymbol("vcSendClientMessage", TCC_FUNC(_Func->SendClientMessage));
s.AddSymbol("vcSendGameMessage", TCC_FUNC(_Func->SendGameMessage));
s.AddSymbol("vcSetServerName", TCC_FUNC(_Func->SetServerName));
s.AddSymbol("vcGetServerName", TCC_FUNC(_Func->GetServerName));
s.AddSymbol("vcSetMaxPlayers", TCC_FUNC(_Func->SetMaxPlayers));
s.AddSymbol("vcGetMaxPlayers", TCC_FUNC(_Func->GetMaxPlayers));
s.AddSymbol("vcSetServerPassword", TCC_FUNC(_Func->SetServerPassword));
s.AddSymbol("vcGetServerPassword", TCC_FUNC(_Func->GetServerPassword));
s.AddSymbol("vcSetGameModeText", TCC_FUNC(_Func->SetGameModeText));
s.AddSymbol("vcGetGameModeText", TCC_FUNC(_Func->GetGameModeText));
s.AddSymbol("vcShutdownServer", TCC_FUNC(_Func->ShutdownServer));
s.AddSymbol("vcSetWorldBounds", TCC_FUNC(_Func->SetWorldBounds));
s.AddSymbol("vcGetWorldBounds", TCC_FUNC(_Func->GetWorldBounds));
s.AddSymbol("vcSetWastedSettings", TCC_FUNC(_Func->SetWastedSettings));
s.AddSymbol("vcGetWastedSettings", TCC_FUNC(_Func->GetWastedSettings));
s.AddSymbol("vcSetTimeRate", TCC_FUNC(_Func->SetTimeRate));
s.AddSymbol("vcGetTimeRate", TCC_FUNC(_Func->GetTimeRate));
s.AddSymbol("vcSetHour", TCC_FUNC(_Func->SetHour));
s.AddSymbol("vcGetHour", TCC_FUNC(_Func->GetHour));
s.AddSymbol("vcSetMinute", TCC_FUNC(_Func->SetMinute));
s.AddSymbol("vcGetMinute", TCC_FUNC(_Func->GetMinute));
s.AddSymbol("vcSetWeather", TCC_FUNC(_Func->SetWeather));
s.AddSymbol("vcGetWeather", TCC_FUNC(_Func->GetWeather));
s.AddSymbol("vcSetGravity", TCC_FUNC(_Func->SetGravity));
s.AddSymbol("vcGetGravity", TCC_FUNC(_Func->GetGravity));
s.AddSymbol("vcSetGamespeed", TCC_FUNC(_Func->SetGamespeed));
s.AddSymbol("vcGetGamespeed", TCC_FUNC(_Func->GetGamespeed));
s.AddSymbol("vcSetWaterLevel", TCC_FUNC(_Func->SetWaterLevel));
s.AddSymbol("vcGetWaterLevel", TCC_FUNC(_Func->GetWaterLevel));
s.AddSymbol("vcSetMaxHeight", TCC_FUNC(_Func->SetMaxHeight));
s.AddSymbol("vcGetMaxHeight", TCC_FUNC(_Func->GetMaxHeight));
s.AddSymbol("vcSetKillCmdDelay", TCC_FUNC(_Func->SetKillCmdDelay));
s.AddSymbol("vcGetKillCmdDelay", TCC_FUNC(_Func->GetKillCmdDelay));
s.AddSymbol("vcSetVehiclesForcedRespawnHeight", TCC_FUNC(_Func->SetVehiclesForcedRespawnHeight));
s.AddSymbol("vcGetVehiclesForcedRespawnHeight", TCC_FUNC(_Func->GetVehiclesForcedRespawnHeight));
s.AddSymbol("vcToggleSyncFrameLimiter", TCC_FUNC(_Func->ToggleSyncFrameLimiter));
s.AddSymbol("vcEnabledSyncFrameLimiter", TCC_FUNC(_Func->EnabledSyncFrameLimiter));
s.AddSymbol("vcToggleFrameLimiter", TCC_FUNC(_Func->ToggleFrameLimiter));
s.AddSymbol("vcEnabledFrameLimiter", TCC_FUNC(_Func->EnabledFrameLimiter));
s.AddSymbol("vcToggleTaxiBoostJump", TCC_FUNC(_Func->ToggleTaxiBoostJump));
s.AddSymbol("vcEnabledTaxiBoostJump", TCC_FUNC(_Func->EnabledTaxiBoostJump));
s.AddSymbol("vcToggleDriveOnWater", TCC_FUNC(_Func->ToggleDriveOnWater));
s.AddSymbol("vcEnabledDriveOnWater", TCC_FUNC(_Func->EnabledDriveOnWater));
s.AddSymbol("vcToggleFastSwitch", TCC_FUNC(_Func->ToggleFastSwitch));
s.AddSymbol("vcEnabledFastSwitch", TCC_FUNC(_Func->EnabledFastSwitch));
s.AddSymbol("vcToggleFriendlyFire", TCC_FUNC(_Func->ToggleFriendlyFire));
s.AddSymbol("vcEnabledFriendlyFire", TCC_FUNC(_Func->EnabledFriendlyFire));
s.AddSymbol("vcToggleDisableDriveby", TCC_FUNC(_Func->ToggleDisableDriveby));
s.AddSymbol("vcEnabledDisableDriveby", TCC_FUNC(_Func->EnabledDisableDriveby));
s.AddSymbol("vcTogglePerfectHandling", TCC_FUNC(_Func->TogglePerfectHandling));
s.AddSymbol("vcEnabledPerfectHandling", TCC_FUNC(_Func->EnabledPerfectHandling));
s.AddSymbol("vcToggleFlyingCars", TCC_FUNC(_Func->ToggleFlyingCars));
s.AddSymbol("vcEnabledFlyingCars", TCC_FUNC(_Func->EnabledFlyingCars));
s.AddSymbol("vcToggleJumpSwitch", TCC_FUNC(_Func->ToggleJumpSwitch));
s.AddSymbol("vcEnabledJumpSwitch", TCC_FUNC(_Func->EnabledJumpSwitch));
s.AddSymbol("vcToggleShowMarkers", TCC_FUNC(_Func->ToggleShowMarkers));
s.AddSymbol("vcEnabledShowMarkers", TCC_FUNC(_Func->EnabledShowMarkers));
s.AddSymbol("vcToggleOnlyShowTeamMarkers", TCC_FUNC(_Func->ToggleOnlyShowTeamMarkers));
s.AddSymbol("vcEnabledOnlyShowTeamMarkers", TCC_FUNC(_Func->EnabledOnlyShowTeamMarkers));
s.AddSymbol("vcToggleStuntBike", TCC_FUNC(_Func->ToggleStuntBike));
s.AddSymbol("vcEnabledStuntBike", TCC_FUNC(_Func->EnabledStuntBike));
s.AddSymbol("vcToggleShootInAir", TCC_FUNC(_Func->ToggleShootInAir));
s.AddSymbol("vcEnabledShootInAir", TCC_FUNC(_Func->EnabledShootInAir));
s.AddSymbol("vcToggleShowNametags", TCC_FUNC(_Func->ToggleShowNametags));
s.AddSymbol("vcEnabledShowNametags", TCC_FUNC(_Func->EnabledShowNametags));
s.AddSymbol("vcToggleJoinMessages", TCC_FUNC(_Func->ToggleJoinMessages));
s.AddSymbol("vcEnabledJoinMessages", TCC_FUNC(_Func->EnabledJoinMessages));
s.AddSymbol("vcToggleDeathMessages", TCC_FUNC(_Func->ToggleDeathMessages));
s.AddSymbol("vcEnabledDeathMessages", TCC_FUNC(_Func->EnabledDeathMessages));
s.AddSymbol("vcToggleChatTagsByDefaultEnabled", TCC_FUNC(_Func->ToggleChatTagsByDefaultEnabled));
s.AddSymbol("vcEnabledChatTagsByDefault", TCC_FUNC(_Func->EnabledChatTagsByDefault));
s.AddSymbol("vcCreateExplosion", TCC_FUNC(_Func->CreateExplosion));
s.AddSymbol("vcPlaySound", TCC_FUNC(_Func->PlaySound));
s.AddSymbol("vcHideMapObject", TCC_FUNC(_Func->HideMapObject));
s.AddSymbol("vcShowMapObject", TCC_FUNC(_Func->ShowMapObject));
s.AddSymbol("vcShowAllMapObjects", TCC_FUNC(_Func->ShowAllMapObjects));
s.AddSymbol("vcSetWeaponDataValue", TCC_FUNC(_Func->SetWeaponDataValue));
s.AddSymbol("vcGetWeaponDataValue", TCC_FUNC(_Func->GetWeaponDataValue));
s.AddSymbol("vcResetWeaponDataValue", TCC_FUNC(_Func->ResetWeaponDataValue));
s.AddSymbol("vcIsWeaponDataValueModified", TCC_FUNC(_Func->IsWeaponDataValueModified));
s.AddSymbol("vcResetWeaponData", TCC_FUNC(_Func->ResetWeaponData));
s.AddSymbol("vcResetAllWeaponData", TCC_FUNC(_Func->ResetAllWeaponData));
s.AddSymbol("vcGetKeyBindUnusedSlot", TCC_FUNC(_Func->GetKeyBindUnusedSlot));
s.AddSymbol("vcGetKeyBindData", TCC_FUNC(_Func->GetKeyBindData));
s.AddSymbol("vcRegisterKeyBind", TCC_FUNC(_Func->RegisterKeyBind));
s.AddSymbol("vcRemoveKeyBind", TCC_FUNC(_Func->RemoveKeyBind));
s.AddSymbol("vcRemoveAllKeyBinds", TCC_FUNC(_Func->RemoveAllKeyBinds));
s.AddSymbol("vcCreateCoordBlip", TCC_FUNC(_Func->CreateCoordBlip));
s.AddSymbol("vcDestroyCoordBlip", TCC_FUNC(_Func->DestroyCoordBlip));
s.AddSymbol("vcGetCoordBlipInfo", TCC_FUNC(_Func->GetCoordBlipInfo));
s.AddSymbol("vcCreateSprite", TCC_FUNC(_Func->CreateSprite));
s.AddSymbol("vcDestroySprite", TCC_FUNC(_Func->DestroySprite));
s.AddSymbol("vcShowSprite", TCC_FUNC(_Func->ShowSprite));
s.AddSymbol("vcHideSprite", TCC_FUNC(_Func->HideSprite));
s.AddSymbol("vcMoveSprite", TCC_FUNC(_Func->MoveSprite));
s.AddSymbol("vcSetSpriteCenter", TCC_FUNC(_Func->SetSpriteCenter));
s.AddSymbol("vcRotateSprite", TCC_FUNC(_Func->RotateSprite));
s.AddSymbol("vcSetSpriteAlpha", TCC_FUNC(_Func->SetSpriteAlpha));
s.AddSymbol("vcSetSpriteRelativity", TCC_FUNC(_Func->SetSpriteRelativity));
s.AddSymbol("vcCreateTextdraw", TCC_FUNC(_Func->CreateTextdraw));
s.AddSymbol("vcDestroyTextdraw", TCC_FUNC(_Func->DestroyTextdraw));
s.AddSymbol("vcShowTextdraw", TCC_FUNC(_Func->ShowTextdraw));
s.AddSymbol("vcHideTextdraw", TCC_FUNC(_Func->HideTextdraw));
s.AddSymbol("vcMoveTextdraw", TCC_FUNC(_Func->MoveTextdraw));
s.AddSymbol("vcSetTextdrawColour", TCC_FUNC(_Func->SetTextdrawColour));
s.AddSymbol("vcSetTextdrawRelativity", TCC_FUNC(_Func->SetTextdrawRelativity));
s.AddSymbol("vcAddRadioStream", TCC_FUNC(_Func->AddRadioStream));
s.AddSymbol("vcRemoveRadioStream", TCC_FUNC(_Func->RemoveRadioStream));
s.AddSymbol("vcSetUseClasses", TCC_FUNC(_Func->SetUseClasses));
s.AddSymbol("vcGetUseClasses", TCC_FUNC(_Func->GetUseClasses));
s.AddSymbol("vcGetPlayerClass", TCC_FUNC(_Func->GetPlayerClass));
s.AddSymbol("vcAddPlayerClass", TCC_FUNC(_Func->AddPlayerClass));
s.AddSymbol("vcSetSpawnPlayerPos", TCC_FUNC(_Func->SetSpawnPlayerPos));
s.AddSymbol("vcSetSpawnCameraPos", TCC_FUNC(_Func->SetSpawnCameraPos));
s.AddSymbol("vcSetSpawnCameraLookAt", TCC_FUNC(_Func->SetSpawnCameraLookAt));
s.AddSymbol("vcIsPlayerAdmin", TCC_FUNC(_Func->IsPlayerAdmin));
s.AddSymbol("vcSetPlayerAdmin", TCC_FUNC(_Func->SetPlayerAdmin));
s.AddSymbol("vcGetPlayerIP", TCC_FUNC(_Func->GetPlayerIP));
s.AddSymbol("vcKickPlayer", TCC_FUNC(_Func->KickPlayer));
s.AddSymbol("vcBanPlayer", TCC_FUNC(_Func->BanPlayer));
s.AddSymbol("vcBanIP", TCC_FUNC(_Func->BanIP));
s.AddSymbol("vcUnbanIP", TCC_FUNC(_Func->UnbanIP));
s.AddSymbol("vcIsIPBanned", TCC_FUNC(_Func->IsIPBanned));
s.AddSymbol("vcGetPlayerIDFromName", TCC_FUNC(_Func->GetPlayerIDFromName));
s.AddSymbol("vcIsPlayerConnected", TCC_FUNC(_Func->IsPlayerConnected));
s.AddSymbol("vcIsPlayerSpawned", TCC_FUNC(_Func->IsPlayerSpawned));
s.AddSymbol("vcIsPlayerStreamedForPlayer", TCC_FUNC(_Func->IsPlayerStreamedForPlayer));
s.AddSymbol("vcGetPlayerKey", TCC_FUNC(_Func->GetPlayerKey));
s.AddSymbol("vcSetPlayerWorld", TCC_FUNC(_Func->SetPlayerWorld));
s.AddSymbol("vcGetPlayerWorld", TCC_FUNC(_Func->GetPlayerWorld));
s.AddSymbol("vcSetPlayerSecWorld", TCC_FUNC(_Func->SetPlayerSecWorld));
s.AddSymbol("vcGetPlayerSecWorld", TCC_FUNC(_Func->GetPlayerSecWorld));
s.AddSymbol("vcGetPlayerUniqueWorld", TCC_FUNC(_Func->GetPlayerUniqueWorld));
s.AddSymbol("vcIsPlayerWorldCompatible", TCC_FUNC(_Func->IsPlayerWorldCompatible));
s.AddSymbol("vcGetPlayerState", TCC_FUNC(_Func->GetPlayerState));
s.AddSymbol("vcGetPlayerName", TCC_FUNC(_Func->GetPlayerName));
s.AddSymbol("vcSetPlayerName", TCC_FUNC(_Func->SetPlayerName));
s.AddSymbol("vcSetPlayerTeam", TCC_FUNC(_Func->SetPlayerTeam));
s.AddSymbol("vcGetPlayerTeam", TCC_FUNC(_Func->GetPlayerTeam));
s.AddSymbol("vcSetPlayerSkin", TCC_FUNC(_Func->SetPlayerSkin));
s.AddSymbol("vcGetPlayerSkin", TCC_FUNC(_Func->GetPlayerSkin));
s.AddSymbol("vcSetPlayerColour", TCC_FUNC(_Func->SetPlayerColour));
s.AddSymbol("vcGetPlayerColour", TCC_FUNC(_Func->GetPlayerColour));
s.AddSymbol("vcForcePlayerSpawn", TCC_FUNC(_Func->ForcePlayerSpawn));
s.AddSymbol("vcForcePlayerSelect", TCC_FUNC(_Func->ForcePlayerSelect));
s.AddSymbol("vcForceAllSelect", TCC_FUNC(_Func->ForceAllSelect));
s.AddSymbol("vcGivePlayerMoney", TCC_FUNC(_Func->GivePlayerMoney));
s.AddSymbol("vcSetPlayerMoney", TCC_FUNC(_Func->SetPlayerMoney));
s.AddSymbol("vcGetPlayerMoney", TCC_FUNC(_Func->GetPlayerMoney));
s.AddSymbol("vcSetPlayerScore", TCC_FUNC(_Func->SetPlayerScore));
s.AddSymbol("vcGetPlayerScore", TCC_FUNC(_Func->GetPlayerScore));
s.AddSymbol("vcGetPlayerPing", TCC_FUNC(_Func->GetPlayerPing));
s.AddSymbol("vcIsPlayerTyping", TCC_FUNC(_Func->IsPlayerTyping));
s.AddSymbol("vcGetPlayerFPS", TCC_FUNC(_Func->GetPlayerFPS));
s.AddSymbol("vcGetPlayerUID", TCC_FUNC(_Func->GetPlayerUID));
s.AddSymbol("vcGetPlayerWantedLevel", TCC_FUNC(_Func->GetPlayerWantedLevel));
s.AddSymbol("vcSetPlayerHealth", TCC_FUNC(_Func->SetPlayerHealth));
s.AddSymbol("vcGetPlayerHealth", TCC_FUNC(_Func->GetPlayerHealth));
s.AddSymbol("vcSetPlayerArmour", TCC_FUNC(_Func->SetPlayerArmour));
s.AddSymbol("vcGetPlayerArmour", TCC_FUNC(_Func->GetPlayerArmour));
s.AddSymbol("vcSetPlayerImmunityFlags", TCC_FUNC(_Func->SetPlayerImmunityFlags));
s.AddSymbol("vcGetPlayerImmunityFlags", TCC_FUNC(_Func->GetPlayerImmunityFlags));
s.AddSymbol("vcSetPlayerPos", TCC_FUNC(_Func->SetPlayerPos));
s.AddSymbol("vcGetPlayerPos", TCC_FUNC(_Func->GetPlayerPos));
s.AddSymbol("vcSetPlayerSpeed", TCC_FUNC(_Func->SetPlayerSpeed));
s.AddSymbol("vcGetPlayerSpeed", TCC_FUNC(_Func->GetPlayerSpeed));
s.AddSymbol("vcAddPlayerSpeed", TCC_FUNC(_Func->AddPlayerSpeed));
s.AddSymbol("vcSetPlayerHeading", TCC_FUNC(_Func->SetPlayerHeading));
s.AddSymbol("vcGetPlayerHeading", TCC_FUNC(_Func->GetPlayerHeading));
s.AddSymbol("vcSetPlayerAlpha", TCC_FUNC(_Func->SetPlayerAlpha));
s.AddSymbol("vcGetPlayerAlpha", TCC_FUNC(_Func->GetPlayerAlpha));
s.AddSymbol("vcGetPlayerOnFireStatus", TCC_FUNC(_Func->GetPlayerOnFireStatus));
s.AddSymbol("vcGetPlayerCrouchStatus", TCC_FUNC(_Func->GetPlayerCrouchStatus));
s.AddSymbol("vcGetPlayerAction", TCC_FUNC(_Func->GetPlayerAction));
s.AddSymbol("vcGetPlayerGameKeys", TCC_FUNC(_Func->GetPlayerGameKeys));
s.AddSymbol("vcGetPlayerAimPos", TCC_FUNC(_Func->GetPlayerAimPos));
s.AddSymbol("vcGetPlayerAimDir", TCC_FUNC(_Func->GetPlayerAimDir));
s.AddSymbol("vcPutPlayerInVehicle", TCC_FUNC(_Func->PutPlayerInVehicle));
s.AddSymbol("vcRemovePlayerFromVehicle", TCC_FUNC(_Func->RemovePlayerFromVehicle));
s.AddSymbol("vcGetPlayerInVehicleStatus", TCC_FUNC(_Func->GetPlayerInVehicleStatus));
s.AddSymbol("vcGetPlayerInVehicleSlot", TCC_FUNC(_Func->GetPlayerInVehicleSlot));
s.AddSymbol("vcGetPlayerVehicleID", TCC_FUNC(_Func->GetPlayerVehicleID));
s.AddSymbol("vcTogglePlayerControllable", TCC_FUNC(_Func->TogglePlayerControllable));
s.AddSymbol("vcEnabledPlayerControllable", TCC_FUNC(_Func->EnabledPlayerControllable));
s.AddSymbol("vcTogglePlayerDriveby", TCC_FUNC(_Func->TogglePlayerDriveby));
s.AddSymbol("vcEnabledPlayerDriveby", TCC_FUNC(_Func->EnabledPlayerDriveby));
s.AddSymbol("vcTogglePlayerWhiteScanlines", TCC_FUNC(_Func->TogglePlayerWhiteScanlines));
s.AddSymbol("vcEnabledPlayerWhiteScanlines", TCC_FUNC(_Func->EnabledPlayerWhiteScanlines));
s.AddSymbol("vcTogglePlayerGreenScanlines", TCC_FUNC(_Func->TogglePlayerGreenScanlines));
s.AddSymbol("vcEnabledPlayerGreenScanlines", TCC_FUNC(_Func->EnabledPlayerGreenScanlines));
s.AddSymbol("vcTogglePlayerWidescreen", TCC_FUNC(_Func->TogglePlayerWidescreen));
s.AddSymbol("vcEnabledPlayerWidescreen", TCC_FUNC(_Func->EnabledPlayerWidescreen));
s.AddSymbol("vcTogglePlayerShowMarkers", TCC_FUNC(_Func->TogglePlayerShowMarkers));
s.AddSymbol("vcEnabledPlayerShowMarkers", TCC_FUNC(_Func->EnabledPlayerShowMarkers));
s.AddSymbol("vcTogglePlayerAttackPriv", TCC_FUNC(_Func->TogglePlayerAttackPriv));
s.AddSymbol("vcEnabledPlayerAttackPriv", TCC_FUNC(_Func->EnabledPlayerAttackPriv));
s.AddSymbol("vcTogglePlayerHasMarker", TCC_FUNC(_Func->TogglePlayerHasMarker));
s.AddSymbol("vcEnabledPlayerHasMarker", TCC_FUNC(_Func->EnabledPlayerHasMarker));
s.AddSymbol("vcTogglePlayerChatTagsEnabled", TCC_FUNC(_Func->TogglePlayerChatTagsEnabled));
s.AddSymbol("vcEnabledPlayerChatTags", TCC_FUNC(_Func->EnabledPlayerChatTags));
s.AddSymbol("vcTogglePlayerDrunkEffects", TCC_FUNC(_Func->TogglePlayerDrunkEffects));
s.AddSymbol("vcEnabledPlayerDrunkEffects", TCC_FUNC(_Func->EnabledPlayerDrunkEffects));
s.AddSymbol("vcGivePlayerWeapon", TCC_FUNC(_Func->GivePlayerWeapon));
s.AddSymbol("vcSetPlayerWeapon", TCC_FUNC(_Func->SetPlayerWeapon));
s.AddSymbol("vcGetPlayerWeapon", TCC_FUNC(_Func->GetPlayerWeapon));
s.AddSymbol("vcGetPlayerWeaponAmmo", TCC_FUNC(_Func->GetPlayerWeaponAmmo));
s.AddSymbol("vcSetPlayerWeaponSlot", TCC_FUNC(_Func->SetPlayerWeaponSlot));
s.AddSymbol("vcGetPlayerWeaponSlot", TCC_FUNC(_Func->GetPlayerWeaponSlot));
s.AddSymbol("vcGetPlayerWeaponAtSlot", TCC_FUNC(_Func->GetPlayerWeaponAtSlot));
s.AddSymbol("vcGetPlayerAmmoAtSlot", TCC_FUNC(_Func->GetPlayerAmmoAtSlot));
s.AddSymbol("vcRemovePlayerWeapon", TCC_FUNC(_Func->RemovePlayerWeapon));
s.AddSymbol("vcRemoveAllWeapons", TCC_FUNC(_Func->RemoveAllWeapons));
s.AddSymbol("vcSetCameraPosition", TCC_FUNC(_Func->SetCameraPosition));
s.AddSymbol("vcRestoreCamera", TCC_FUNC(_Func->RestoreCamera));
s.AddSymbol("vcIsCameraLocked", TCC_FUNC(_Func->IsCameraLocked));
s.AddSymbol("vcSetPlayerAnimation", TCC_FUNC(_Func->SetPlayerAnimation));
s.AddSymbol("vcSetPlayerWantedLevel", TCC_FUNC(_Func->SetPlayerWantedLevel));
s.AddSymbol("vcGetPlayerStandingOnVehicle", TCC_FUNC(_Func->GetPlayerStandingOnVehicle));
s.AddSymbol("vcGetPlayerStandingOnObject", TCC_FUNC(_Func->GetPlayerStandingOnObject));
s.AddSymbol("vcIsPlayerAway", TCC_FUNC(_Func->IsPlayerAway));
s.AddSymbol("vcGetPlayerSpectateTarget", TCC_FUNC(_Func->GetPlayerSpectateTarget));
s.AddSymbol("vcSetPlayerSpectateTarget", TCC_FUNC(_Func->SetPlayerSpectateTarget));
s.AddSymbol("vcRedirectPlayerToServer", TCC_FUNC(_Func->RedirectPlayerToServer));
s.AddSymbol("vcCreateVehicle", TCC_FUNC(_Func->CreateVehicle));
s.AddSymbol("vcDeleteVehicle", TCC_FUNC(_Func->DeleteVehicle));
s.AddSymbol("vcGetVehicleSyncSource", TCC_FUNC(_Func->GetVehicleSyncSource));
s.AddSymbol("vcGetVehicleSyncType", TCC_FUNC(_Func->GetVehicleSyncType));
s.AddSymbol("vcIsVehicleStreamedForPlayer", TCC_FUNC(_Func->IsVehicleStreamedForPlayer));
s.AddSymbol("vcSetVehicleWorld", TCC_FUNC(_Func->SetVehicleWorld));
s.AddSymbol("vcGetVehicleWorld", TCC_FUNC(_Func->GetVehicleWorld));
s.AddSymbol("vcGetVehicleModel", TCC_FUNC(_Func->GetVehicleModel));
s.AddSymbol("vcGetVehicleOccupant", TCC_FUNC(_Func->GetVehicleOccupant));
s.AddSymbol("vcRespawnVehicle", TCC_FUNC(_Func->RespawnVehicle));
s.AddSymbol("vcSetVehicleImmunityFlags", TCC_FUNC(_Func->SetVehicleImmunityFlags));
s.AddSymbol("vcGetVehicleImmunityFlags", TCC_FUNC(_Func->GetVehicleImmunityFlags));
s.AddSymbol("vcKillVehicle", TCC_FUNC(_Func->KillVehicle));
s.AddSymbol("vcIsVehicleWrecked", TCC_FUNC(_Func->IsVehicleWrecked));
s.AddSymbol("vcSetVehiclePos", TCC_FUNC(_Func->SetVehiclePos));
s.AddSymbol("vcGetVehiclePos", TCC_FUNC(_Func->GetVehiclePos));
s.AddSymbol("vcSetVehicleRot", TCC_FUNC(_Func->SetVehicleRot));
s.AddSymbol("vcSetVehicleRotEuler", TCC_FUNC(_Func->SetVehicleRotEuler));
s.AddSymbol("vcGetVehicleRot", TCC_FUNC(_Func->GetVehicleRot));
s.AddSymbol("vcGetVehicleRotEuler", TCC_FUNC(_Func->GetVehicleRotEuler));
s.AddSymbol("vcSetVehicleSpeed", TCC_FUNC(_Func->SetVehicleSpeed));
s.AddSymbol("vcGetVehicleSpeed", TCC_FUNC(_Func->GetVehicleSpeed));
s.AddSymbol("vcAddVehicleSpeed", TCC_FUNC(_Func->AddVehicleSpeed));
s.AddSymbol("vcSetVehicleRelSpeed", TCC_FUNC(_Func->SetVehicleRelSpeed));
s.AddSymbol("vcGetVehicleRelSpeed", TCC_FUNC(_Func->GetVehicleRelSpeed));
s.AddSymbol("vcAddVehicleRelSpeed", TCC_FUNC(_Func->AddVehicleRelSpeed));
s.AddSymbol("vcSetVehicleTurnSpeed", TCC_FUNC(_Func->SetVehicleTurnSpeed));
s.AddSymbol("vcGetVehicleTurnSpeed", TCC_FUNC(_Func->GetVehicleTurnSpeed));
s.AddSymbol("vcAddVehicleTurnSpeed", TCC_FUNC(_Func->AddVehicleTurnSpeed));
s.AddSymbol("vcSetVehicleRelTurnSpeed", TCC_FUNC(_Func->SetVehicleRelTurnSpeed));
s.AddSymbol("vcGetVehicleRelTurnSpeed", TCC_FUNC(_Func->GetVehicleRelTurnSpeed));
s.AddSymbol("vcAddVehicleRelTurnSpeed", TCC_FUNC(_Func->AddVehicleRelTurnSpeed));
s.AddSymbol("vcSetVehicleSpawnPos", TCC_FUNC(_Func->SetVehicleSpawnPos));
s.AddSymbol("vcGetVehicleSpawnPos", TCC_FUNC(_Func->GetVehicleSpawnPos));
s.AddSymbol("vcSetVehicleSpawnRot", TCC_FUNC(_Func->SetVehicleSpawnRot));
s.AddSymbol("vcSetVehicleSpawnRotEuler", TCC_FUNC(_Func->SetVehicleSpawnRotEuler));
s.AddSymbol("vcGetVehicleSpawnRot", TCC_FUNC(_Func->GetVehicleSpawnRot));
s.AddSymbol("vcGetVehicleSpawnRotEuler", TCC_FUNC(_Func->GetVehicleSpawnRotEuler));
s.AddSymbol("vcSetVehicleIdleRespawnTimer", TCC_FUNC(_Func->SetVehicleIdleRespawnTimer));
s.AddSymbol("vcGetVehicleIdleRespawnTimer", TCC_FUNC(_Func->GetVehicleIdleRespawnTimer));
s.AddSymbol("vcSetVehicleHealth", TCC_FUNC(_Func->SetVehicleHealth));
s.AddSymbol("vcGetVehicleHealth", TCC_FUNC(_Func->GetVehicleHealth));
s.AddSymbol("vcSetVehicleColour", TCC_FUNC(_Func->SetVehicleColour));
s.AddSymbol("vcGetVehicleColour", TCC_FUNC(_Func->GetVehicleColour));
s.AddSymbol("vcSetVehicleDoorsLocked", TCC_FUNC(_Func->SetVehicleDoorsLocked));
s.AddSymbol("vcGetVehicleDoorsLocked", TCC_FUNC(_Func->GetVehicleDoorsLocked));
s.AddSymbol("vcSetVehiclePartStatus", TCC_FUNC(_Func->SetVehiclePartStatus));
s.AddSymbol("vcGetVehiclePartStatus", TCC_FUNC(_Func->GetVehiclePartStatus));
s.AddSymbol("vcSetVehicleTyreStatus", TCC_FUNC(_Func->SetVehicleTyreStatus));
s.AddSymbol("vcGetVehicleTyreStatus", TCC_FUNC(_Func->GetVehicleTyreStatus));
s.AddSymbol("vcSetVehicleDamageData", TCC_FUNC(_Func->SetVehicleDamageData));
s.AddSymbol("vcGetVehicleDamageData", TCC_FUNC(_Func->GetVehicleDamageData));
s.AddSymbol("vcSetVehicleAlarm", TCC_FUNC(_Func->SetVehicleAlarm));
s.AddSymbol("vcGetVehicleAlarm", TCC_FUNC(_Func->GetVehicleAlarm));
s.AddSymbol("vcSetVehicleLights", TCC_FUNC(_Func->SetVehicleLights));
s.AddSymbol("vcGetVehicleLights", TCC_FUNC(_Func->GetVehicleLights));
s.AddSymbol("vcSetVehicleRadio", TCC_FUNC(_Func->SetVehicleRadio));
s.AddSymbol("vcGetVehicleRadio", TCC_FUNC(_Func->GetVehicleRadio));
s.AddSymbol("vcSetVehicleRadioLocked", TCC_FUNC(_Func->SetVehicleRadioLocked));
s.AddSymbol("vcIsVehicleRadioLocked", TCC_FUNC(_Func->IsVehicleRadioLocked));
s.AddSymbol("vcGetVehicleGhostState", TCC_FUNC(_Func->GetVehicleGhostState));
s.AddSymbol("vcSetVehicleGhostState", TCC_FUNC(_Func->SetVehicleGhostState));
s.AddSymbol("vcGetVehicleTurretRotation", TCC_FUNC(_Func->GetVehicleTurretRotation));
s.AddSymbol("vcResetAllVehicleHandlings", TCC_FUNC(_Func->ResetAllVehicleHandlings));
s.AddSymbol("vcExistsHandlingRule", TCC_FUNC(_Func->ExistsHandlingRule));
s.AddSymbol("vcSetHandlingRule", TCC_FUNC(_Func->SetHandlingRule));
s.AddSymbol("vcGetHandlingRule", TCC_FUNC(_Func->GetHandlingRule));
s.AddSymbol("vcResetHandlingRule", TCC_FUNC(_Func->ResetHandlingRule));
s.AddSymbol("vcResetHandling", TCC_FUNC(_Func->ResetHandling));
s.AddSymbol("vcExistsInstHandlingRule", TCC_FUNC(_Func->ExistsInstHandlingRule));
s.AddSymbol("vcSetInstHandlingRule", TCC_FUNC(_Func->SetInstHandlingRule));
s.AddSymbol("vcGetInstHandlingRule", TCC_FUNC(_Func->GetInstHandlingRule));
s.AddSymbol("vcResetInstHandlingRule", TCC_FUNC(_Func->ResetInstHandlingRule));
s.AddSymbol("vcResetInstHandling", TCC_FUNC(_Func->ResetInstHandling));
s.AddSymbol("vcCreatePickup", TCC_FUNC(_Func->CreatePickup));
s.AddSymbol("vcDeletePickup", TCC_FUNC(_Func->DeletePickup));
s.AddSymbol("vcIsPickupStreamedForPlayer", TCC_FUNC(_Func->IsPickupStreamedForPlayer));
s.AddSymbol("vcSetPickupWorld", TCC_FUNC(_Func->SetPickupWorld));
s.AddSymbol("vcGetPickupWorld", TCC_FUNC(_Func->GetPickupWorld));
s.AddSymbol("vcPickupGetAlpha", TCC_FUNC(_Func->PickupGetAlpha));
s.AddSymbol("vcPickupSetAlpha", TCC_FUNC(_Func->PickupSetAlpha));
s.AddSymbol("vcPickupIsAutomatic", TCC_FUNC(_Func->PickupIsAutomatic));
s.AddSymbol("vcPickupSetAutomatic", TCC_FUNC(_Func->PickupSetAutomatic));
s.AddSymbol("vcSetPickupAutoTimer", TCC_FUNC(_Func->SetPickupAutoTimer));
s.AddSymbol("vcGetPickupAutoTimer", TCC_FUNC(_Func->GetPickupAutoTimer));
s.AddSymbol("vcPickupRefresh", TCC_FUNC(_Func->PickupRefresh));
s.AddSymbol("vcPickupGetPos", TCC_FUNC(_Func->PickupGetPos));
s.AddSymbol("vcPickupSetPos", TCC_FUNC(_Func->PickupSetPos));
s.AddSymbol("vcPickupGetModel", TCC_FUNC(_Func->PickupGetModel));
s.AddSymbol("vcPickupGetQuantity", TCC_FUNC(_Func->PickupGetQuantity));
s.AddSymbol("vcCreateObject", TCC_FUNC(_Func->CreateObject));
s.AddSymbol("vcDeleteObject", TCC_FUNC(_Func->DeleteObject));
s.AddSymbol("vcIsObjectStreamedForPlayer", TCC_FUNC(_Func->IsObjectStreamedForPlayer));
s.AddSymbol("vcGetObjectModel", TCC_FUNC(_Func->GetObjectModel));
s.AddSymbol("vcSetObjectWorld", TCC_FUNC(_Func->SetObjectWorld));
s.AddSymbol("vcGetObjectWorld", TCC_FUNC(_Func->GetObjectWorld));
s.AddSymbol("vcSetObjectAlpha", TCC_FUNC(_Func->SetObjectAlpha));
s.AddSymbol("vcGetObjectAlpha", TCC_FUNC(_Func->GetObjectAlpha));
s.AddSymbol("vcMoveObjectTo", TCC_FUNC(_Func->MoveObjectTo));
s.AddSymbol("vcMoveObjectBy", TCC_FUNC(_Func->MoveObjectBy));
s.AddSymbol("vcSetObjectPos", TCC_FUNC(_Func->SetObjectPos));
s.AddSymbol("vcGetObjectPos", TCC_FUNC(_Func->GetObjectPos));
s.AddSymbol("vcRotObjectTo", TCC_FUNC(_Func->RotObjectTo));
s.AddSymbol("vcRotObjectToEuler", TCC_FUNC(_Func->RotObjectToEuler));
s.AddSymbol("vcRotObjectBy", TCC_FUNC(_Func->RotObjectBy));
s.AddSymbol("vcRotObjectByEuler", TCC_FUNC(_Func->RotObjectByEuler));
s.AddSymbol("vcGetObjectRot", TCC_FUNC(_Func->GetObjectRot));
s.AddSymbol("vcGetObjectRotEuler", TCC_FUNC(_Func->GetObjectRotEuler));
s.AddSymbol("vcSetObjectShotReport", TCC_FUNC(_Func->SetObjectShotReport));
s.AddSymbol("vcIsObjectShotReport", TCC_FUNC(_Func->IsObjectShotReport));
s.AddSymbol("vcSetObjectBumpReport", TCC_FUNC(_Func->SetObjectBumpReport));
s.AddSymbol("vcIsObjectBumpReport", TCC_FUNC(_Func->IsObjectBumpReport));
s.AddSymbol("vcToggleWallglitch", TCC_FUNC(_Func->ToggleWallglitch));
s.AddSymbol("vcEnabledWallglitch", TCC_FUNC(_Func->EnabledWallglitch));
s.AddSymbol("vcSetVehicleSiren", TCC_FUNC(_Func->SetVehicleSiren));
s.AddSymbol("vcGetVehicleSiren", TCC_FUNC(_Func->GetVehicleSiren));
s.AddSymbol("vcGetPlayerUID2", TCC_FUNC(_Func->GetPlayerUID2));
s.AddSymbol("vcCreateCheckpoint", TCC_FUNC(_Func->CreateCheckpoint));
s.AddSymbol("vcDeleteCheckpoint", TCC_FUNC(_Func->DeleteCheckpoint));
s.AddSymbol("vcIsCheckpointStreamedForPlayer", TCC_FUNC(_Func->IsCheckpointStreamedForPlayer));
s.AddSymbol("vcSetCheckpointWorld", TCC_FUNC(_Func->SetCheckpointWorld));
s.AddSymbol("vcGetCheckpointWorld", TCC_FUNC(_Func->GetCheckpointWorld));
s.AddSymbol("vcSetCheckpointColor", TCC_FUNC(_Func->SetCheckpointColor));
s.AddSymbol("vcGetCheckpointColor", TCC_FUNC(_Func->GetCheckpointColor));
s.AddSymbol("vcSetCheckpointPos", TCC_FUNC(_Func->SetCheckpointPos));
s.AddSymbol("vcGetCheckpointPos", TCC_FUNC(_Func->GetCheckpointPos));
s.AddSymbol("vcSetCheckpointRadius", TCC_FUNC(_Func->SetCheckpointRadius));
s.AddSymbol("vcGetCheckpointRadius", TCC_FUNC(_Func->GetCheckpointRadius));
s.AddSymbol("vcGetCheckpointOwner", TCC_FUNC(_Func->GetCheckpointOwner));
s.AddSymbol("vcCreateSphere", TCC_FUNC(_Func->CreateSphere));
s.AddSymbol("vcDeleteSphere", TCC_FUNC(_Func->DeleteSphere));
s.AddSymbol("vcIsSphereStreamedForPlayer", TCC_FUNC(_Func->IsSphereStreamedForPlayer));
s.AddSymbol("vcSetSphereWorld", TCC_FUNC(_Func->SetSphereWorld));
s.AddSymbol("vcGetSphereWorld", TCC_FUNC(_Func->GetSphereWorld));
s.AddSymbol("vcSetSphereColor", TCC_FUNC(_Func->SetSphereColor));
s.AddSymbol("vcGetSphereColor", TCC_FUNC(_Func->GetSphereColor));
s.AddSymbol("vcSetSpherePos", TCC_FUNC(_Func->SetSpherePos));
s.AddSymbol("vcGetSpherePos", TCC_FUNC(_Func->GetSpherePos));
s.AddSymbol("vcSetSphereRadius", TCC_FUNC(_Func->SetSphereRadius));
s.AddSymbol("vcGetSphereRadius", TCC_FUNC(_Func->GetSphereRadius));
s.AddSymbol("vcGetSphereOwner", TCC_FUNC(_Func->GetSphereOwner));
// Squirrel Library
s.AddSymbol("sq_open", TCC_FUNC(_SqAPI->open));
s.AddSymbol("sq_newthread", TCC_FUNC(_SqAPI->newthread));
s.AddSymbol("sq_seterrorhandler", TCC_FUNC(_SqAPI->seterrorhandler));
s.AddSymbol("sq_close", TCC_FUNC(_SqAPI->close));
s.AddSymbol("sq_setforeignptr", TCC_FUNC(_SqAPI->setforeignptr));
s.AddSymbol("sq_getforeignptr", TCC_FUNC(_SqAPI->getforeignptr));
s.AddSymbol("sq_setsharedforeignptr", TCC_FUNC(_SqAPI->setsharedforeignptr));
s.AddSymbol("sq_getsharedforeignptr", TCC_FUNC(_SqAPI->getsharedforeignptr));
s.AddSymbol("sq_setvmreleasehook", TCC_FUNC(_SqAPI->setvmreleasehook));
s.AddSymbol("sq_getvmreleasehook", TCC_FUNC(_SqAPI->getvmreleasehook));
s.AddSymbol("sq_setsharedreleasehook", TCC_FUNC(_SqAPI->setsharedreleasehook));
s.AddSymbol("sq_getsharedreleasehook", TCC_FUNC(_SqAPI->getsharedreleasehook));
s.AddSymbol("sq_setprintfunc", TCC_FUNC(_SqAPI->setprintfunc));
s.AddSymbol("sq_getprintfunc", TCC_FUNC(_SqAPI->getprintfunc));
s.AddSymbol("sq_geterrorfunc", TCC_FUNC(_SqAPI->geterrorfunc));
s.AddSymbol("sq_suspendvm", TCC_FUNC(_SqAPI->suspendvm));
s.AddSymbol("sq_wakeupvm", TCC_FUNC(_SqAPI->wakeupvm));
s.AddSymbol("sq_getvmstate", TCC_FUNC(_SqAPI->getvmstate));
s.AddSymbol("sq_getversion", TCC_FUNC(_SqAPI->getversion));
s.AddSymbol("sq_compile", TCC_FUNC(_SqAPI->compile));
s.AddSymbol("sq_compilebuffer", TCC_FUNC(_SqAPI->compilebuffer));
s.AddSymbol("sq_enabledebuginfo", TCC_FUNC(_SqAPI->enabledebuginfo));
s.AddSymbol("sq_notifyallexceptions", TCC_FUNC(_SqAPI->notifyallexceptions));
s.AddSymbol("sq_setcompilererrorhandler", TCC_FUNC(_SqAPI->setcompilererrorhandler));
s.AddSymbol("sq_push", TCC_FUNC(_SqAPI->push));
s.AddSymbol("sq_pop", TCC_FUNC(_SqAPI->pop));
s.AddSymbol("sq_poptop", TCC_FUNC(_SqAPI->poptop));
s.AddSymbol("sq_remove", TCC_FUNC(_SqAPI->remove));
s.AddSymbol("sq_gettop", TCC_FUNC(_SqAPI->gettop));
s.AddSymbol("sq_settop", TCC_FUNC(_SqAPI->settop));
s.AddSymbol("sq_reservestack", TCC_FUNC(_SqAPI->reservestack));
s.AddSymbol("sq_cmp", TCC_FUNC(_SqAPI->cmp));
s.AddSymbol("sq_move", TCC_FUNC(_SqAPI->move));
s.AddSymbol("sq_newuserdata", TCC_FUNC(_SqAPI->newuserdata));
s.AddSymbol("sq_newtable", TCC_FUNC(_SqAPI->newtable));
s.AddSymbol("sq_newtableex", TCC_FUNC(_SqAPI->newtableex));
s.AddSymbol("sq_newarray", TCC_FUNC(_SqAPI->newarray));
s.AddSymbol("sq_newclosure", TCC_FUNC(_SqAPI->newclosure));
s.AddSymbol("sq_setparamscheck", TCC_FUNC(_SqAPI->setparamscheck));
s.AddSymbol("sq_bindenv", TCC_FUNC(_SqAPI->bindenv));
s.AddSymbol("sq_setclosureroot", TCC_FUNC(_SqAPI->setclosureroot));
s.AddSymbol("sq_getclosureroot", TCC_FUNC(_SqAPI->getclosureroot));
s.AddSymbol("sq_pushstring", TCC_FUNC(_SqAPI->pushstring));
s.AddSymbol("sq_pushfloat", TCC_FUNC(_SqAPI->pushfloat));
s.AddSymbol("sq_pushinteger", TCC_FUNC(_SqAPI->pushinteger));
s.AddSymbol("sq_pushbool", TCC_FUNC(_SqAPI->pushbool));
s.AddSymbol("sq_pushuserpointer", TCC_FUNC(_SqAPI->pushuserpointer));
s.AddSymbol("sq_pushnull", TCC_FUNC(_SqAPI->pushnull));
s.AddSymbol("sq_pushthread", TCC_FUNC(_SqAPI->pushthread));
s.AddSymbol("sq_gettype", TCC_FUNC(_SqAPI->gettype));
s.AddSymbol("sq_typeof", TCC_FUNC(_SqAPI->typeof_));
s.AddSymbol("sq_getsize", TCC_FUNC(_SqAPI->getsize));
s.AddSymbol("sq_gethash", TCC_FUNC(_SqAPI->gethash));
s.AddSymbol("sq_getbase", TCC_FUNC(_SqAPI->getbase));
s.AddSymbol("sq_instanceof", TCC_FUNC(_SqAPI->instanceof));
s.AddSymbol("sq_tostring", TCC_FUNC(_SqAPI->tostring));
s.AddSymbol("sq_tobool", TCC_FUNC(_SqAPI->tobool));
s.AddSymbol("sq_getstring", TCC_FUNC(_SqAPI->getstring));
s.AddSymbol("sq_getinteger", TCC_FUNC(_SqAPI->getinteger));
s.AddSymbol("sq_getfloat", TCC_FUNC(_SqAPI->getfloat));
s.AddSymbol("sq_getbool", TCC_FUNC(_SqAPI->getbool));
s.AddSymbol("sq_getthread", TCC_FUNC(_SqAPI->getthread));
s.AddSymbol("sq_getuserpointer", TCC_FUNC(_SqAPI->getuserpointer));
s.AddSymbol("sq_getuserdata", TCC_FUNC(_SqAPI->getuserdata));
s.AddSymbol("sq_settypetag", TCC_FUNC(_SqAPI->settypetag));
s.AddSymbol("sq_gettypetag", TCC_FUNC(_SqAPI->gettypetag));
s.AddSymbol("sq_setreleasehook", TCC_FUNC(_SqAPI->setreleasehook));
s.AddSymbol("sq_getreleasehook", TCC_FUNC(_SqAPI->getreleasehook));
s.AddSymbol("sq_getscratchpad", TCC_FUNC(_SqAPI->getscratchpad));
s.AddSymbol("sq_getfunctioninfo", TCC_FUNC(_SqAPI->getfunctioninfo));
s.AddSymbol("sq_getclosureinfo", TCC_FUNC(_SqAPI->getclosureinfo));
s.AddSymbol("sq_getclosurename", TCC_FUNC(_SqAPI->getclosurename));
s.AddSymbol("sq_setnativeclosurename", TCC_FUNC(_SqAPI->setnativeclosurename));
s.AddSymbol("sq_setinstanceup", TCC_FUNC(_SqAPI->setinstanceup));
s.AddSymbol("sq_getinstanceup", TCC_FUNC(_SqAPI->getinstanceup));
s.AddSymbol("sq_setclassudsize", TCC_FUNC(_SqAPI->setclassudsize));
s.AddSymbol("sq_newclass", TCC_FUNC(_SqAPI->newclass));
s.AddSymbol("sq_createinstance", TCC_FUNC(_SqAPI->createinstance));
s.AddSymbol("sq_setattributes", TCC_FUNC(_SqAPI->setattributes));
s.AddSymbol("sq_getattributes", TCC_FUNC(_SqAPI->getattributes));
s.AddSymbol("sq_getclass", TCC_FUNC(_SqAPI->getclass));
s.AddSymbol("sq_weakref", TCC_FUNC(_SqAPI->weakref));
s.AddSymbol("sq_getdefaultdelegate", TCC_FUNC(_SqAPI->getdefaultdelegate));
s.AddSymbol("sq_getmemberhandle", TCC_FUNC(_SqAPI->getmemberhandle));
s.AddSymbol("sq_getbyhandle", TCC_FUNC(_SqAPI->getbyhandle));
s.AddSymbol("sq_setbyhandle", TCC_FUNC(_SqAPI->setbyhandle));
s.AddSymbol("sq_pushroottable", TCC_FUNC(_SqAPI->pushroottable));
s.AddSymbol("sq_pushregistrytable", TCC_FUNC(_SqAPI->pushregistrytable));
s.AddSymbol("sq_pushconsttable", TCC_FUNC(_SqAPI->pushconsttable));
s.AddSymbol("sq_setroottable", TCC_FUNC(_SqAPI->setroottable));
s.AddSymbol("sq_setconsttable", TCC_FUNC(_SqAPI->setconsttable));
s.AddSymbol("sq_newslot", TCC_FUNC(_SqAPI->newslot));
s.AddSymbol("sq_deleteslot", TCC_FUNC(_SqAPI->deleteslot));
s.AddSymbol("sq_set", TCC_FUNC(_SqAPI->set));
s.AddSymbol("sq_get", TCC_FUNC(_SqAPI->get));
s.AddSymbol("sq_rawget", TCC_FUNC(_SqAPI->rawget));
s.AddSymbol("sq_rawset", TCC_FUNC(_SqAPI->rawset));
s.AddSymbol("sq_rawdeleteslot", TCC_FUNC(_SqAPI->rawdeleteslot));
s.AddSymbol("sq_newmember", TCC_FUNC(_SqAPI->newmember));
s.AddSymbol("sq_rawnewmember", TCC_FUNC(_SqAPI->rawnewmember));
s.AddSymbol("sq_arrayappend", TCC_FUNC(_SqAPI->arrayappend));
s.AddSymbol("sq_arraypop", TCC_FUNC(_SqAPI->arraypop));
s.AddSymbol("sq_arrayresize", TCC_FUNC(_SqAPI->arrayresize));
s.AddSymbol("sq_arrayreverse", TCC_FUNC(_SqAPI->arrayreverse));
s.AddSymbol("sq_arrayremove", TCC_FUNC(_SqAPI->arrayremove));
s.AddSymbol("sq_arrayinsert", TCC_FUNC(_SqAPI->arrayinsert));
s.AddSymbol("sq_setdelegate", TCC_FUNC(_SqAPI->setdelegate));
s.AddSymbol("sq_getdelegate", TCC_FUNC(_SqAPI->getdelegate));
s.AddSymbol("sq_clone", TCC_FUNC(_SqAPI->clone));
s.AddSymbol("sq_setfreevariable", TCC_FUNC(_SqAPI->setfreevariable));
s.AddSymbol("sq_next", TCC_FUNC(_SqAPI->next));
s.AddSymbol("sq_getweakrefval", TCC_FUNC(_SqAPI->getweakrefval));
s.AddSymbol("sq_clear", TCC_FUNC(_SqAPI->clear));
s.AddSymbol("sq_call", TCC_FUNC(_SqAPI->call));
s.AddSymbol("sq_resume", TCC_FUNC(_SqAPI->resume));
s.AddSymbol("sq_getlocal", TCC_FUNC(_SqAPI->getlocal));
s.AddSymbol("sq_getcallee", TCC_FUNC(_SqAPI->getcallee));
s.AddSymbol("sq_getfreevariable", TCC_FUNC(_SqAPI->getfreevariable));
s.AddSymbol("sq_throwerror", TCC_FUNC(_SqAPI->throwerror));
s.AddSymbol("sq_throwobject", TCC_FUNC(_SqAPI->throwobject));
s.AddSymbol("sq_reseterror", TCC_FUNC(_SqAPI->reseterror));
s.AddSymbol("sq_getlasterror", TCC_FUNC(_SqAPI->getlasterror));
s.AddSymbol("sq_getstackobj", TCC_FUNC(_SqAPI->getstackobj));
s.AddSymbol("sq_pushobject", TCC_FUNC(_SqAPI->pushobject));
s.AddSymbol("sq_addref", TCC_FUNC(_SqAPI->addref));
s.AddSymbol("sq_release", TCC_FUNC(_SqAPI->release));
s.AddSymbol("sq_getrefcount", TCC_FUNC(_SqAPI->getrefcount));
s.AddSymbol("sq_resetobject", TCC_FUNC(_SqAPI->resetobject));
s.AddSymbol("sq_objtostring", TCC_FUNC(_SqAPI->objtostring));
s.AddSymbol("sq_objtobool", TCC_FUNC(_SqAPI->objtobool));
s.AddSymbol("sq_objtointeger", TCC_FUNC(_SqAPI->objtointeger));
s.AddSymbol("sq_objtofloat", TCC_FUNC(_SqAPI->objtofloat));
s.AddSymbol("sq_objtouserpointer", TCC_FUNC(_SqAPI->objtouserpointer));
s.AddSymbol("sq_getobjtypetag", TCC_FUNC(_SqAPI->getobjtypetag));
s.AddSymbol("sq_getvmrefcount", TCC_FUNC(_SqAPI->getvmrefcount));
s.AddSymbol("sq_collectgarbage", TCC_FUNC(_SqAPI->collectgarbage));
s.AddSymbol("sq_resurrectunreachable", TCC_FUNC(_SqAPI->resurrectunreachable));
s.AddSymbol("sq_writeclosure", TCC_FUNC(_SqAPI->writeclosure));
s.AddSymbol("sq_readclosure", TCC_FUNC(_SqAPI->readclosure));
s.AddSymbol("sq_malloc", TCC_FUNC(_SqAPI->malloc));
s.AddSymbol("sq_realloc", TCC_FUNC(_SqAPI->realloc));
s.AddSymbol("sq_free", TCC_FUNC(_SqAPI->free));
s.AddSymbol("sq_stackinfos", TCC_FUNC(_SqAPI->stackinfos));
s.AddSymbol("sq_setdebughook", TCC_FUNC(_SqAPI->setdebughook));
s.AddSymbol("sq_setnativedebughook", TCC_FUNC(_SqAPI->setnativedebughook));
s.AddSymbol("sqstd_loadfile", TCC_FUNC(_SqAPI->loadfile));
s.AddSymbol("sqstd_dofile", TCC_FUNC(_SqAPI->dofile));
s.AddSymbol("sqstd_writeclosuretofile", TCC_FUNC(_SqAPI->writeclosuretofile));
s.AddSymbol("sqstd_createblob", TCC_FUNC(_SqAPI->createblob));
s.AddSymbol("sqstd_getblob", TCC_FUNC(_SqAPI->getblob));
s.AddSymbol("sqstd_getblobsize", TCC_FUNC(_SqAPI->getblobsize));
s.AddSymbol("sqstd_format", TCC_FUNC(_SqAPI->format));
// Host Module
s.AddSymbol("SqMod_GetSquirrelVM", TCC_FUNC(_SqMod->GetSquirrelVM));
s.AddSymbol("SqMod_LogDbg", TCC_FUNC(_SqMod->LogDbg));
s.AddSymbol("SqMod_LogUsr", TCC_FUNC(_SqMod->LogUsr));
s.AddSymbol("SqMod_LogScs", TCC_FUNC(_SqMod->LogScs));
s.AddSymbol("SqMod_LogInf", TCC_FUNC(_SqMod->LogInf));
s.AddSymbol("SqMod_LogWrn", TCC_FUNC(_SqMod->LogWrn));
s.AddSymbol("SqMod_LogErr", TCC_FUNC(_SqMod->LogErr));
s.AddSymbol("SqMod_LogFtl", TCC_FUNC(_SqMod->LogFtl));
s.AddSymbol("SqMod_LogSDbg", TCC_FUNC(_SqMod->LogSDbg));
s.AddSymbol("SqMod_LogSUsr", TCC_FUNC(_SqMod->LogSUsr));
s.AddSymbol("SqMod_LogSScs", TCC_FUNC(_SqMod->LogSScs));
s.AddSymbol("SqMod_LogSInf", TCC_FUNC(_SqMod->LogSInf));
s.AddSymbol("SqMod_LogSWrn", TCC_FUNC(_SqMod->LogSWrn));
s.AddSymbol("SqMod_LogSErr", TCC_FUNC(_SqMod->LogSErr));
s.AddSymbol("SqMod_LogSFtl", TCC_FUNC(_SqMod->LogSFtl));
s.AddSymbol("SqMod_LoadScript", TCC_FUNC(_SqMod->LoadScript));
s.AddSymbol("SqMod_GetSLongValue", TCC_FUNC(_SqMod->GetSLongValue));
s.AddSymbol("SqMod_PushSLongObject", TCC_FUNC(_SqMod->PushSLongObject));
s.AddSymbol("SqMod_GetULongValue", TCC_FUNC(_SqMod->GetULongValue));
s.AddSymbol("SqMod_PushULongObject", TCC_FUNC(_SqMod->PushULongObject));
s.AddSymbol("SqMod_GetCurrentSysTime", TCC_FUNC(_SqMod->GetCurrentSysTime));
s.AddSymbol("SqMod_GetEpochTimeMicro", TCC_FUNC(_SqMod->GetEpochTimeMicro));
s.AddSymbol("SqMod_GetEpochTimeMilli", TCC_FUNC(_SqMod->GetEpochTimeMilli));
s.AddSymbol("SqMod_GetTimestamp", TCC_FUNC(_SqMod->GetTimestamp));
s.AddSymbol("SqMod_PushTimestamp", TCC_FUNC(_SqMod->PushTimestamp));
}
} // Namespace:: SqMod

File diff suppressed because it is too large Load Diff

View File

@ -1,700 +0,0 @@
#ifndef _SQTCC_COMMON_HPP_
#define _SQTCC_COMMON_HPP_
// ------------------------------------------------------------------------------------------------
#include "ModBase.hpp"
// ------------------------------------------------------------------------------------------------
#include <cassert>
// ------------------------------------------------------------------------------------------------
#include <vector>
// ------------------------------------------------------------------------------------------------
#include <vcmp.h>
#include <sqrat.h>
// ------------------------------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
#endif
struct TCCState;
#ifdef __cplusplus
} // extern "C"
#endif
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* SOFTWARE INFORMATION
*/
#define SQTCC_NAME "Squirrel TCC Module"
#define SQTCC_AUTHOR "Sandu Liviu Catalin (S.L.C)"
#define SQTCC_COPYRIGHT "Copyright (C) 2016 Sandu Liviu Catalin"
#define SQTCC_HOST_NAME "SqModTCCHost"
#define SQTCC_VERSION 001
#define SQTCC_VERSION_STR "0.0.1"
#define SQTCC_VERSION_MAJOR 0
#define SQTCC_VERSION_MINOR 0
#define SQTCC_VERSION_PATCH 1
/* ------------------------------------------------------------------------------------------------
* Retrieve the temporary buffer.
*/
SStr GetTempBuff();
/* ------------------------------------------------------------------------------------------------
* Retrieve the size of the temporary buffer.
*/
Uint32 GetTempBuffSize();
/* ------------------------------------------------------------------------------------------------
* Throw a formatted exception.
*/
void SqThrowF(CSStr str, ...);
/* ------------------------------------------------------------------------------------------------
* Generate a formatted string.
*/
CSStr FmtStr(CSStr str, ...);
/* ------------------------------------------------------------------------------------------------
* Implements RAII to restore the VM stack to it's initial size on function exit.
*/
struct StackGuard
{
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
StackGuard();
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
StackGuard(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~StackGuard();
private:
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
StackGuard(const StackGuard &);
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
StackGuard(StackGuard &&);
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
StackGuard & operator = (const StackGuard &);
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
StackGuard & operator = (StackGuard &&);
private:
// --------------------------------------------------------------------------------------------
HSQUIRRELVM m_VM; // The VM where the stack should be restored.
Int32 m_Top; // The top of the stack when this instance was created.
};
/* ------------------------------------------------------------------------------------------------
* Helper structure for retrieving a value from the stack as a string or a formatted string.
*/
struct StackStrF
{
// --------------------------------------------------------------------------------------------
CSStr mPtr; // Pointer to the C string that was retrieved.
SQInteger mLen; // The string length if it could be retrieved.
SQRESULT mRes; // The result of the retrieval attempts.
HSQOBJECT mObj; // Strong reference to the string object.
HSQUIRRELVM mVM; // The associated virtual machine.
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
StackStrF(HSQUIRRELVM vm, SQInteger idx, bool fmt = true);
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
StackStrF(const StackStrF & o) = delete;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
StackStrF(StackStrF && o) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~StackStrF();
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
StackStrF & operator = (const StackStrF & o) = delete;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
StackStrF & operator = (StackStrF && o) = delete;
};
// ------------------------------------------------------------------------------------------------
class State;
class Symbol;
class StateHnd;
/* ------------------------------------------------------------------------------------------------
* Register the standard API on the specified compiler state.
*/
extern void RegisterAPI(StateHnd & s);
/* ------------------------------------------------------------------------------------------------
* Server events that can be toggled.
*/
enum EventType
{
EvUnknown = 0,
EvOnFrame,
EvOnPlayerConnect,
EvOnPlayerDisconnect,
EvOnPlayerBeginTyping,
EvOnPlayerEndTyping,
EvOnPlayerRequestClass,
EvOnPlayerRequestSpawn,
EvOnPlayerSpawn,
EvOnPlayerDeath,
EvOnPlayerUpdate,
EvOnPlayerRequestEnter,
EvOnPlayerEnterVehicle,
EvOnPlayerExitVehicle,
EvOnPlayerNameChange,
EvOnPlayerStateChange,
EvOnPlayerActionChange,
EvOnPlayerOnFireChange,
EvOnPlayerCrouchChange,
EvOnPlayerGameKeysChange,
EvOnPickupClaimPicked,
EvOnPickupPickedUp,
EvOnPickupRespawn,
EvOnVehicleUpdate,
EvOnVehicleExplode,
EvOnVehicleRespawn,
EvOnObjectShot,
EvOnObjectBump,
EvOnPublicMessage,
EvOnCommandMessage,
EvOnPrivateMessage,
EvOnLoginAttempt,
EvOnEntityPoolChange,
EvOnKeyBindDown,
EvOnKeyBindUp,
EvOnPlayerAwayChange,
EvOnPlayerSpectate,
EvOnPlayerCrashReport,
EvOnServerPerformanceReport,
EvOnCheckpointEntered,
EvOnCheckpointExited,
EvOnSphereEntered,
EvOnSphereExited,
EvCount
};
/* ------------------------------------------------------------------------------------------------
* Manages a reference counted compiler state handle.
*/
class StateHnd
{
// --------------------------------------------------------------------------------------------
friend class State;
friend class Symbol;
public:
// --------------------------------------------------------------------------------------------
typedef TCCState Type; // The managed type.
// --------------------------------------------------------------------------------------------
typedef Type* Pointer; // Pointer to the managed type.
typedef const Type* ConstPtr; // Constant pointer to the managed type.
// --------------------------------------------------------------------------------------------
typedef Type& Reference; // Reference to the managed type.
typedef const Type& ConstRef; // Constant reference to the managed type.
// --------------------------------------------------------------------------------------------
typedef unsigned int Counter; // Reference counter type.
/* --------------------------------------------------------------------------------------------
* Validate the managed handle and throw exception if invalid.
*/
void Validate() const;
protected:
/* --------------------------------------------------------------------------------------------
* The structure that holds the data associated with a certain state.
*/
struct Handle
{
// ----------------------------------------------------------------------------------------
Pointer mPtr; // The TCC state handle resource.
Counter mRef; // Reference count to the managed handle.
// ----------------------------------------------------------------------------------------
SDK_OnInitServer mOnInitServer;
SDK_OnShutdownServer mOnShutdownServer;
SDK_OnFrame mOnFrame;
SDK_OnPlayerConnect mOnPlayerConnect;
SDK_OnPlayerDisconnect mOnPlayerDisconnect;
SDK_OnPlayerBeginTyping mOnPlayerBeginTyping;
SDK_OnPlayerEndTyping mOnPlayerEndTyping;
SDK_OnPlayerRequestClass mOnPlayerRequestClass;
SDK_OnPlayerRequestSpawn mOnPlayerRequestSpawn;
SDK_OnPlayerSpawn mOnPlayerSpawn;
SDK_OnPlayerDeath mOnPlayerDeath;
SDK_OnPlayerUpdate mOnPlayerUpdate;
SDK_OnPlayerRequestEnter mOnPlayerRequestEnter;
SDK_OnPlayerEnterVehicle mOnPlayerEnterVehicle;
SDK_OnPlayerExitVehicle mOnPlayerExitVehicle;
SDK_OnPlayerNameChange mOnPlayerNameChange;
SDK_OnPlayerStateChange mOnPlayerStateChange;
SDK_OnPlayerActionChange mOnPlayerActionChange;
SDK_OnPlayerOnFireChange mOnPlayerOnFireChange;
SDK_OnPlayerCrouchChange mOnPlayerCrouchChange;
SDK_OnPlayerGameKeysChange mOnPlayerGameKeysChange;
SDK_OnPickupClaimPicked mOnPickupClaimPicked;
SDK_OnPickupPickedUp mOnPickupPickedUp;
SDK_OnPickupRespawn mOnPickupRespawn;
SDK_OnVehicleUpdate mOnVehicleUpdate;
SDK_OnVehicleExplode mOnVehicleExplode;
SDK_OnVehicleRespawn mOnVehicleRespawn;
SDK_OnObjectShot mOnObjectShot;
SDK_OnObjectBump mOnObjectBump;
SDK_OnPublicMessage mOnPublicMessage;
SDK_OnCommandMessage mOnCommandMessage;
SDK_OnPrivateMessage mOnPrivateMessage;
SDK_OnInternalCommand mOnInternalCommand;
SDK_OnLoginAttempt mOnLoginAttempt;
SDK_OnEntityPoolChange mOnEntityPoolChange;
SDK_OnKeyBindDown mOnKeyBindDown;
SDK_OnKeyBindUp mOnKeyBindUp;
SDK_OnPlayerAwayChange mOnPlayerAwayChange;
SDK_OnPlayerSpectate mOnPlayerSpectate;
SDK_OnPlayerCrashReport mOnPlayerCrashReport;
SDK_OnServerPerformanceReport mOnServerPerformanceReport;
SDK_OnCheckpointEntered mOnCheckpointEntered;
SDK_OnCheckpointExited mOnCheckpointExited;
SDK_OnSphereEntered mOnSphereEntered;
SDK_OnSphereExited mOnSphereExited;
// ----------------------------------------------------------------------------------------
bool mRelocated; // Whether the state was relocated.
bool mNoErrors; // Don't output errors even if there is no error handler.
// ----------------------------------------------------------------------------------------
Function mErrorHandler; // The custom script error handler.
// ----------------------------------------------------------------------------------------
String mName; // The name given to this state.
/* ----------------------------------------------------------------------------------------
* Base constructor.
*/
Handle(Counter counter, CSStr name);
/* ----------------------------------------------------------------------------------------
* Destructor.
*/
~Handle();
};
private:
// --------------------------------------------------------------------------------------------
typedef std::vector< Handle * > Handles; // List of handles that receive callbacks.
// --------------------------------------------------------------------------------------------
static Handles s_Handles;
/* --------------------------------------------------------------------------------------------
* See whether the specified state instance is in the handles list.
*/
static bool IsListed(Handle * hnd);
/* --------------------------------------------------------------------------------------------
* Add the specified state instance to the handles list to receive callbacks.
*/
static void Remember(Handle * hnd);
/* --------------------------------------------------------------------------------------------
* Remove the specified state instance from the handles list.
*/
static void Forget(Handle * hnd);
/* --------------------------------------------------------------------------------------------
* Make the specified handle to be the first in the list.
*/
static void ToHead(Handle * hnd);
protected:
/* --------------------------------------------------------------------------------------------
* The error handler assigned to every created state.
*/
static void ErrorHandler(void * opaque, const char * msg);
/* --------------------------------------------------------------------------------------------
* Add a symbol to the compiled program.
*/
void PushSymbol(CSStr name, const void * value);
/* --------------------------------------------------------------------------------------------
* Return symbol value or NULL if not found.
*/
void * PullSymbol(CSStr name) const;
private:
// --------------------------------------------------------------------------------------------
Handle* m_Hnd;
/* --------------------------------------------------------------------------------------------
* Grab a strong reference to a state handle.
*/
void Grab()
{
if (m_Hnd)
{
++(m_Hnd->mRef);
}
}
/* --------------------------------------------------------------------------------------------
* Drop a strong reference to a state handle.
*/
void Drop()
{
if (m_Hnd && --(m_Hnd->mRef) == 0)
{
delete m_Hnd; // Let the destructor take care of cleaning up (if necessary)
}
}
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
StateHnd(CSStr name)
: m_Hnd(name ? new Handle(1, name) : nullptr)
{
RegisterAPI(*this);
}
public:
/* --------------------------------------------------------------------------------------------
* Default constructor (null).
*/
StateHnd()
: m_Hnd(nullptr)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
StateHnd(const StateHnd & o)
: m_Hnd(o.m_Hnd)
{
Grab();
}
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
StateHnd(StateHnd && o)
: m_Hnd(o.m_Hnd)
{
o.m_Hnd = nullptr;
}
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~StateHnd()
{
Drop();
}
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
StateHnd & operator = (const StateHnd & o)
{
if (m_Hnd != o.m_Hnd)
{
Drop();
m_Hnd = o.m_Hnd;
Grab();
}
return *this;
}
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
StateHnd & operator = (StateHnd && o)
{
if (m_Hnd != o.m_Hnd)
{
m_Hnd = o.m_Hnd;
o.m_Hnd = nullptr;
}
return *this;
}
/* --------------------------------------------------------------------------------------------
* Perform an equality comparison between two state handles.
*/
bool operator == (const StateHnd & o) const
{
return (m_Hnd == o.m_Hnd);
}
/* --------------------------------------------------------------------------------------------
* Perform an inequality comparison between two state handles.
*/
bool operator != (const StateHnd & o) const
{
return (m_Hnd != o.m_Hnd);
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean for use in boolean operations.
*/
operator bool () const
{
return m_Hnd && m_Hnd->mPtr;
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed instance.
*/
operator Pointer ()
{
return m_Hnd ? m_Hnd->mPtr : nullptr;
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed instance.
*/
operator Pointer () const
{
return m_Hnd ? m_Hnd->mPtr : nullptr;
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed instance.
*/
operator Reference ()
{
assert(m_Hnd && m_Hnd->mPtr);
return *(m_Hnd->mPtr);
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the managed instance.
*/
operator ConstRef () const
{
assert(m_Hnd && m_Hnd->mPtr);
return *(m_Hnd->mPtr);
}
/* --------------------------------------------------------------------------------------------
* Member operator for dereferencing the managed pointer.
*/
Handle * operator -> () const
{
assert(m_Hnd);
return m_Hnd;
}
/* --------------------------------------------------------------------------------------------
* Indirection operator for obtaining a reference of the managed pointer.
*/
Handle & operator * () const
{
assert(m_Hnd);
return *m_Hnd;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the raw handle structure pointer.
*/
Handle * HndPtr()
{
return m_Hnd;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the raw handle structure pointer.
*/
Handle * HndPtr() const
{
return m_Hnd;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the number of active references to the managed instance.
*/
Counter Count() const
{
return m_Hnd ? m_Hnd->mRef : 0;
}
/* --------------------------------------------------------------------------------------------
* Set options as from command line (multiple supported).
*/
void SetOptions(CSStr opt) const;
/* --------------------------------------------------------------------------------------------
* Define preprocessor symbol 'sym'. Can put optional value.
*/
void DefineSymbol(CSStr sym, CSStr value) const;
/* --------------------------------------------------------------------------------------------
* Undefine preprocess symbol 'sym'.
*/
void UndefineSymbol(CSStr sym) const;
/* --------------------------------------------------------------------------------------------
* Add include path.
*/
void AddIncludePath(CSStr path) const;
/* --------------------------------------------------------------------------------------------
* Add in system include path.
*/
void AddSysIncludePath(CSStr path) const;
/* --------------------------------------------------------------------------------------------
* Set CONFIG_TCCDIR at runtime.
*/
void SetLibPath(CSStr path) const;
/* --------------------------------------------------------------------------------------------
* Equivalent to -Lpath option.
*/
void AddLibraryPath(CSStr path) const;
/* --------------------------------------------------------------------------------------------
* The library name is the same as the argument of the '-l' option.
*/
void AddLibrary(CSStr name) const;
/* --------------------------------------------------------------------------------------------
* Compile a string containing a C source.
*/
void CompileString(CSStr str) const;
/* --------------------------------------------------------------------------------------------
* Add a file (C file, dll, object, library, ld script).
*/
void AddFile(CSStr filename, Int32 type) const;
/* --------------------------------------------------------------------------------------------
* Do all relocations (needed before using tcc_get_symbol())
*/
void Relocate() const;
/* --------------------------------------------------------------------------------------------
* Add a symbol to the compiled program.
*/
template < typename T > void AddSymbol(CSStr name, T value)
{
PushSymbol(name, reinterpret_cast< const void * >(value));
}
/* --------------------------------------------------------------------------------------------
* Return symbol value or NULL if not found.
*/
template < typename T > T GetSymbol(CSStr name) const
{
return reinterpret_cast< T >(PullSymbol(name));
}
/* --------------------------------------------------------------------------------------------
* Server callbacks.
*/
static int OnInitServer(void);
static void OnShutdownServer(void);
static void OnFrame(float delta);
static void OnPlayerConnect(int player);
static void OnPlayerDisconnect(int player, int reason);
static void OnPlayerBeginTyping(int player);
static void OnPlayerEndTyping(int player);
static int OnPlayerRequestClass(int player, int offset);
static int OnPlayerRequestSpawn(int player);
static void OnPlayerSpawn(int player);
static void OnPlayerDeath(int player, int killer, int reason, int body_part);
static void OnPlayerUpdate(int player, int type);
static int OnPlayerRequestEnter(int player, int vehicle, int slot);
static void OnPlayerEnterVehicle(int player, int vehicle, int slot);
static void OnPlayerExitVehicle(int player, int vehicle);
static void OnPlayerNameChange(int player, const char * previous, const char * current);
static void OnPlayerStateChange(int player, int previous, int current);
static void OnPlayerActionChange(int player, int previous, int current);
static void OnPlayerOnFireChange(int player, unsigned int state);
static void OnPlayerCrouchChange(int player, unsigned int state);
static void OnPlayerGameKeysChange(int player, int previous, int current);
static int OnPickupClaimPicked(int pickup, int player);
static void OnPickupPickedUp(int pickup, int player);
static void OnPickupRespawn(int pickup);
static void OnVehicleUpdate(int vehicle, int type);
static void OnVehicleExplode(int vehicle);
static void OnVehicleRespawn(int vehicle);
static void OnObjectShot(int object, int player, int weapon);
static void OnObjectBump(int object, int player);
static int OnPublicMessage(int player, const char * message);
static int OnCommandMessage(int player, const char * command);
static int OnPrivateMessage(int player, int target, const char * message);
static int OnInternalCommand(unsigned int type, const char * text);
static int OnLoginAttempt(char * name, const char * passwd, const char * ipaddr);
static void OnEntityPoolChange(int type, int entity, unsigned int deleted);
static void OnKeyBindDown(int player, int keybind);
static void OnKeyBindUp(int player, int keybind);
static void OnPlayerAwayChange(int player, unsigned int status);
static void OnPlayerSpectate(int player, int target);
static void OnPlayerCrashReport(int player, const char * report);
static void OnServerPerformanceReport(int count, const char ** description, unsigned long long * millispent);
static void OnCheckpointEntered(int checkpoint, int player);
static void OnCheckpointExited(int checkpoint, int player);
static void OnSphereEntered(int sphere, int player);
static void OnSphereExited(int sphere, int player);
/* --------------------------------------------------------------------------------------------
* Enable or disable a certain server event.
*/
static void ToggleEvent(Int32 evt, bool toggle);
};
} // Namespace:: SqMod
#endif // _SQTCC_COMMON_HPP_

View File

@ -1,504 +0,0 @@
// --------------------------------------------------------------------------------------------
#include "Module.hpp"
#include "Common.hpp"
#include "State.hpp"
#include "Symbol.hpp"
// --------------------------------------------------------------------------------------------
#include <sqrat.h>
// --------------------------------------------------------------------------------------------
#include <cstdio>
#include <cstdlib>
#include <cstdarg>
// --------------------------------------------------------------------------------------------
#if defined(WIN32) || defined(_WIN32)
#include <Windows.h>
#endif
namespace SqMod {
// --------------------------------------------------------------------------------------------
PluginFuncs* _Func = nullptr;
PluginCallbacks* _Clbk = nullptr;
PluginInfo* _Info = nullptr;
// --------------------------------------------------------------------------------------------
HSQAPI _SqAPI = nullptr;
HSQEXPORTS _SqMod = nullptr;
HSQUIRRELVM _SqVM = nullptr;
/* ------------------------------------------------------------------------------------------------
* Bind speciffic functions to certain server events.
*/
void BindCallbacks();
/* ------------------------------------------------------------------------------------------------
* Undo changes made with BindCallbacks().
*/
void UnbindCallbacks();
/* --------------------------------------------------------------------------------------------
* Register the module API under the specified virtual machine.
*/
void RegisterAPI(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Initialize the plugin by obtaining the API provided by the host plugin.
*/
void OnSquirrelInitialize()
{
// Attempt to import the plugin API exported by the host plugin
_SqMod = sq_api_import(_Func);
// Did we failed to obtain the plugin exports?
if(!_SqMod)
{
OutputError("Failed to attach [%s] on host plugin.", SQTCC_NAME);
}
else
{
// Obtain the Squirrel API
_SqAPI = _SqMod->GetSquirrelAPI();
// Expand the Squirrel API into global functions
sq_api_expand(_SqAPI);
}
}
/* --------------------------------------------------------------------------------------------
* Load the module on the virtual machine provided by the host module.
*/
void OnSquirrelLoad()
{
// Make sure that we have a valid plugin API
if (!_SqMod)
{
return; /* Unable to proceed. */
}
// Obtain the Squirrel API and VM
_SqVM = _SqMod->GetSquirrelVM();
// Make sure that a valid virtual machine exists
if (!_SqVM)
{
return; /* Unable to proceed. */
}
// Set this as the default database
DefaultVM::Set(_SqVM);
// Register the module API
RegisterAPI(_SqVM);
// Notify about the current status
OutputMessage("Registered: %s", SQTCC_NAME);
}
/* --------------------------------------------------------------------------------------------
* The virtual machine is about to be terminated and script resources should be released.
*/
void OnSquirrelTerminate()
{
OutputMessage("Terminating: %s", SQTCC_NAME);
// Release the current database (if any)
DefaultVM::Set(nullptr);
// Release script resources...
}
/* --------------------------------------------------------------------------------------------
* Validate the module API to make sure we don't run into issues.
*/
bool CheckAPIVer(CCStr ver)
{
// Obtain the numeric representation of the API version
long vernum = std::strtol(ver, nullptr, 10);
// Check against version mismatch
if (vernum == SQMOD_API_VER)
{
return true;
}
// Log the incident
OutputError("API version mismatch on %s", SQTCC_NAME);
OutputMessage("=> Requested: %ld Have: %ld", vernum, SQMOD_API_VER);
// Invoker should not attempt to communicate through the module API
return false;
}
/* --------------------------------------------------------------------------------------------
* React to command sent by other plugins.
*/
static int OnInternalCommand(unsigned int type, const char * text)
{
// Forward the call to compiler states
int res = StateHnd::OnInternalCommand(type, text);
// Now we can process it
switch(type)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(text))
{
OnSquirrelInitialize();
}
break;
case SQMOD_LOAD_CMD:
OnSquirrelLoad();
break;
case SQMOD_TERMINATE_CMD:
OnSquirrelTerminate();
break;
default: break;
}
// Return the result
return res;
}
/* --------------------------------------------------------------------------------------------
* The server was initialized and this plugin was loaded successfully.
*/
static int OnInitServer()
{
return StateHnd::OnInitServer();
}
static void OnShutdownServer(void)
{
// Forward the call to compiler states
StateHnd::OnShutdownServer();
// The server may still send callbacks
UnbindCallbacks();
}
// ------------------------------------------------------------------------------------------------
void BindCallbacks()
{
_Clbk->OnInitServer = OnInitServer;
_Clbk->OnInternalCommand = OnInternalCommand;
_Clbk->OnShutdownServer = OnShutdownServer;
_Clbk->OnFrame = &StateHnd::OnFrame;
_Clbk->OnPlayerConnect = &StateHnd::OnPlayerConnect;
_Clbk->OnPlayerDisconnect = &StateHnd::OnPlayerDisconnect;
_Clbk->OnPlayerBeginTyping = &StateHnd::OnPlayerBeginTyping;
_Clbk->OnPlayerEndTyping = &StateHnd::OnPlayerEndTyping;
_Clbk->OnPlayerRequestClass = &StateHnd::OnPlayerRequestClass;
_Clbk->OnPlayerRequestSpawn = &StateHnd::OnPlayerRequestSpawn;
_Clbk->OnPlayerSpawn = &StateHnd::OnPlayerSpawn;
_Clbk->OnPlayerDeath = &StateHnd::OnPlayerDeath;
_Clbk->OnPlayerUpdate = &StateHnd::OnPlayerUpdate;
_Clbk->OnPlayerRequestEnter = &StateHnd::OnPlayerRequestEnter;
_Clbk->OnPlayerEnterVehicle = &StateHnd::OnPlayerEnterVehicle;
_Clbk->OnPlayerExitVehicle = &StateHnd::OnPlayerExitVehicle;
_Clbk->OnPlayerNameChange = &StateHnd::OnPlayerNameChange;
_Clbk->OnPlayerStateChange = &StateHnd::OnPlayerStateChange;
_Clbk->OnPlayerActionChange = &StateHnd::OnPlayerActionChange;
_Clbk->OnPlayerOnFireChange = &StateHnd::OnPlayerOnFireChange;
_Clbk->OnPlayerCrouchChange = &StateHnd::OnPlayerCrouchChange;
_Clbk->OnPlayerGameKeysChange = &StateHnd::OnPlayerGameKeysChange;
_Clbk->OnPickupClaimPicked = &StateHnd::OnPickupClaimPicked;
_Clbk->OnPickupPickedUp = &StateHnd::OnPickupPickedUp;
_Clbk->OnPickupRespawn = &StateHnd::OnPickupRespawn;
_Clbk->OnVehicleUpdate = &StateHnd::OnVehicleUpdate;
_Clbk->OnVehicleExplode = &StateHnd::OnVehicleExplode;
_Clbk->OnVehicleRespawn = &StateHnd::OnVehicleRespawn;
_Clbk->OnObjectShot = &StateHnd::OnObjectShot;
_Clbk->OnObjectBump = &StateHnd::OnObjectBump;
_Clbk->OnPublicMessage = &StateHnd::OnPublicMessage;
_Clbk->OnCommandMessage = &StateHnd::OnCommandMessage;
_Clbk->OnPrivateMessage = &StateHnd::OnPrivateMessage;
_Clbk->OnLoginAttempt = &StateHnd::OnLoginAttempt;
_Clbk->OnEntityPoolChange = &StateHnd::OnEntityPoolChange;
_Clbk->OnKeyBindDown = &StateHnd::OnKeyBindDown;
_Clbk->OnKeyBindUp = &StateHnd::OnKeyBindUp;
_Clbk->OnPlayerAwayChange = &StateHnd::OnPlayerAwayChange;
_Clbk->OnPlayerSpectate = &StateHnd::OnPlayerSpectate;
_Clbk->OnPlayerCrashReport = &StateHnd::OnPlayerCrashReport;
_Clbk->OnServerPerformanceReport = &StateHnd::OnServerPerformanceReport;
_Clbk->OnCheckpointEntered = &StateHnd::OnCheckpointEntered;
_Clbk->OnCheckpointExited = &StateHnd::OnCheckpointExited;
_Clbk->OnSphereEntered = &StateHnd::OnSphereEntered;
_Clbk->OnSphereExited = &StateHnd::OnSphereExited;
}
// ------------------------------------------------------------------------------------------------
void UnbindCallbacks()
{
_Clbk->OnInitServer = nullptr;
_Clbk->OnInternalCommand = nullptr;
_Clbk->OnShutdownServer = nullptr;
_Clbk->OnFrame = nullptr;
_Clbk->OnPlayerConnect = nullptr;
_Clbk->OnPlayerDisconnect = nullptr;
_Clbk->OnPlayerBeginTyping = nullptr;
_Clbk->OnPlayerEndTyping = nullptr;
_Clbk->OnPlayerRequestClass = nullptr;
_Clbk->OnPlayerRequestSpawn = nullptr;
_Clbk->OnPlayerSpawn = nullptr;
_Clbk->OnPlayerDeath = nullptr;
_Clbk->OnPlayerUpdate = nullptr;
_Clbk->OnPlayerRequestEnter = nullptr;
_Clbk->OnPlayerEnterVehicle = nullptr;
_Clbk->OnPlayerExitVehicle = nullptr;
_Clbk->OnPlayerNameChange = nullptr;
_Clbk->OnPlayerStateChange = nullptr;
_Clbk->OnPlayerActionChange = nullptr;
_Clbk->OnPlayerOnFireChange = nullptr;
_Clbk->OnPlayerCrouchChange = nullptr;
_Clbk->OnPlayerGameKeysChange = nullptr;
_Clbk->OnPickupClaimPicked = nullptr;
_Clbk->OnPickupPickedUp = nullptr;
_Clbk->OnPickupRespawn = nullptr;
_Clbk->OnVehicleUpdate = nullptr;
_Clbk->OnVehicleExplode = nullptr;
_Clbk->OnVehicleRespawn = nullptr;
_Clbk->OnObjectShot = nullptr;
_Clbk->OnObjectBump = nullptr;
_Clbk->OnPublicMessage = nullptr;
_Clbk->OnCommandMessage = nullptr;
_Clbk->OnPrivateMessage = nullptr;
_Clbk->OnLoginAttempt = nullptr;
_Clbk->OnEntityPoolChange = nullptr;
_Clbk->OnKeyBindDown = nullptr;
_Clbk->OnKeyBindUp = nullptr;
_Clbk->OnPlayerAwayChange = nullptr;
_Clbk->OnPlayerSpectate = nullptr;
_Clbk->OnPlayerCrashReport = nullptr;
_Clbk->OnServerPerformanceReport = nullptr;
_Clbk->OnCheckpointEntered = nullptr;
_Clbk->OnCheckpointExited = nullptr;
_Clbk->OnSphereEntered = nullptr;
_Clbk->OnSphereExited = nullptr;
}
// --------------------------------------------------------------------------------------------
void RegisterAPI(HSQUIRRELVM vm)
{
Table tccns(vm);
tccns.Bind(_SC("State"), Class< State >(vm, _SC("SqTccState"))
// Constructors
.Ctor< CSStr >()
// Metamethods
.Func(_SC("_cmp"), &State::Cmp)
.SquirrelFunc(_SC("_typename"), &State::Typename)
.Func(_SC("_tostring"), &State::ToString)
// Properties
.Prop(_SC("Valid"), &State::IsValid)
.Prop(_SC("Refs"), &State::GetRefCount)
.Prop(_SC("Name"), &State::GetName, &State::SetName)
.Prop(_SC("Events"), &State::GetEvents, &State::SetEvents)
// Member Methods
.Func(_SC("Release"), &State::Release)
.Func(_SC("MakeHead"), &State::MakeHead)
.Func(_SC("SetOptions"), &State::SetOptions)
.Func(_SC("UndefineSymbol"), &State::UndefineSymbol)
.Func(_SC("AddIncludePath"), &State::AddIncludePath)
.Func(_SC("AddSysIncludePath"), &State::AddSysIncludePath)
.Func(_SC("SetLibPath"), &State::SetLibPath)
.Func(_SC("AddLibraryPath"), &State::AddLibraryPath)
.Func(_SC("AddLibrary"), &State::AddLibrary)
.Func(_SC("CompileString"), &State::CompileString)
.Func(_SC("AddSource"), &State::AddSource)
.Func(_SC("AddBinary"), &State::AddBinary)
.Func(_SC("AddAsm"), &State::AddAsm)
.Func(_SC("AddAsmPP"), &State::AddAsmPP)
.Func(_SC("Relocate"), &State::Relocate)
.Func(_SC("GetSymbol"), &State::GetSymbol)
// Member Overloads
.Overload< void (State::*)(CSStr) const >(_SC("DefineSymbol"), &State::DefineSymbol)
.Overload< void (State::*)(CSStr, CSStr) const >(_SC("DefineSymbol"), &State::DefineSymbol)
);
tccns.Bind(_SC("Symbol"), Class< Symbol >(vm, _SC("SqTccSymbol"))
// Constructors
.Ctor< const State &, CSStr >()
// Metamethods
.Func(_SC("_cmp"), &Symbol::Cmp)
.SquirrelFunc(_SC("_typename"), &Symbol::Typename)
.Func(_SC("_tostring"), &Symbol::ToString)
// Properties
.Prop(_SC("Valid"), &Symbol::IsValid)
.Prop(_SC("Refs"), &Symbol::GetRefCount)
.Prop(_SC("State"), &Symbol::GetStateRef)
// Member Methods
.Func(_SC("Release"), &Symbol::Release)
// Squirrel Methods
.SquirrelFunc(_SC("Forward"), &Symbol::Forward)
);
tccns.Func(_SC("ToggleEvent"), &StateHnd::ToggleEvent);
RootTable(vm).Bind(_SC("SqTCC"), tccns);
ConstTable(vm).Enum(_SC("ETccEvent"), Enumeration(vm)
.Const(_SC("Frame"), EvOnFrame)
.Const(_SC("PlayerConnect"), EvOnPlayerConnect)
.Const(_SC("PlayerDisconnect"), EvOnPlayerDisconnect)
.Const(_SC("PlayerBeginTyping"), EvOnPlayerBeginTyping)
.Const(_SC("PlayerEndTyping"), EvOnPlayerEndTyping)
.Const(_SC("PlayerRequestClass"), EvOnPlayerRequestClass)
.Const(_SC("PlayerRequestSpawn"), EvOnPlayerRequestSpawn)
.Const(_SC("PlayerSpawn"), EvOnPlayerSpawn)
.Const(_SC("PlayerDeath"), EvOnPlayerDeath)
.Const(_SC("PlayerUpdate"), EvOnPlayerUpdate)
.Const(_SC("PlayerRequestEnter"), EvOnPlayerRequestEnter)
.Const(_SC("PlayerEnterVehicle"), EvOnPlayerEnterVehicle)
.Const(_SC("PlayerExitVehicle"), EvOnPlayerExitVehicle)
.Const(_SC("PlayerNameChange"), EvOnPlayerNameChange)
.Const(_SC("PlayerStateChange"), EvOnPlayerStateChange)
.Const(_SC("PlayerActionChange"), EvOnPlayerActionChange)
.Const(_SC("PlayerOnFireChange"), EvOnPlayerOnFireChange)
.Const(_SC("PlayerCrouchChange"), EvOnPlayerCrouchChange)
.Const(_SC("PlayerGameKeysChange"), EvOnPlayerGameKeysChange)
.Const(_SC("PickupClaimPicked"), EvOnPickupClaimPicked)
.Const(_SC("PickupPickedUp"), EvOnPickupPickedUp)
.Const(_SC("PickupRespawn"), EvOnPickupRespawn)
.Const(_SC("VehicleUpdate"), EvOnVehicleUpdate)
.Const(_SC("VehicleExplode"), EvOnVehicleExplode)
.Const(_SC("VehicleRespawn"), EvOnVehicleRespawn)
.Const(_SC("ObjectShot"), EvOnObjectShot)
.Const(_SC("ObjectBump"), EvOnObjectBump)
.Const(_SC("PublicMessage"), EvOnPublicMessage)
.Const(_SC("CommandMessage"), EvOnCommandMessage)
.Const(_SC("PrivateMessage"), EvOnPrivateMessage)
.Const(_SC("LoginAttempt"), EvOnLoginAttempt)
.Const(_SC("EntityPoolChange"), EvOnEntityPoolChange)
.Const(_SC("KeyBindDown"), EvOnKeyBindDown)
.Const(_SC("KeyBindUp"), EvOnKeyBindUp)
.Const(_SC("PlayerAwayChange"), EvOnPlayerAwayChange)
.Const(_SC("PlayerSpectate"), EvOnPlayerSpectate)
.Const(_SC("PlayerCrashReport"), EvOnPlayerCrashReport)
.Const(_SC("ServerPerformanceReport"), EvOnServerPerformanceReport)
.Const(_SC("CheckpointEntered"), EvOnCheckpointEntered)
.Const(_SC("CheckpointExited"), EvOnCheckpointExited)
.Const(_SC("SphereEntered"), EvOnSphereEntered)
.Const(_SC("SphereExited"), EvOnSphereExited)
);
}
// --------------------------------------------------------------------------------------------
void OutputMessageImpl(const char * msg, va_list args)
{
#if defined(WIN32) || defined(_WIN32)
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csb_before;
GetConsoleScreenBufferInfo( hstdout, &csb_before);
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN);
printf("[SQMOD] ");
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
vprintf(msg, args);
puts("");
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
#else
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
vprintf(msg, args);
puts("");
#endif
}
// --------------------------------------------------------------------------------------------
void OutputErrorImpl(const char * msg, va_list args)
{
#if defined(WIN32) || defined(_WIN32)
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csb_before;
GetConsoleScreenBufferInfo( hstdout, &csb_before);
SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
printf("[SQMOD] ");
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
vprintf(msg, args);
puts("");
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
#else
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
vprintf(msg, args);
puts("");
#endif
}
// --------------------------------------------------------------------------------------------
void OutputDebug(const char * msg, ...)
{
#ifdef _DEBUG
// Initialize the arguments list
va_list args;
va_start(args, msg);
// Call the output function
OutputMessageImpl(msg, args);
// Finalize the arguments list
va_end(args);
#else
SQMOD_UNUSED_VAR(msg);
#endif
}
// --------------------------------------------------------------------------------------------
void OutputMessage(const char * msg, ...)
{
// Initialize the arguments list
va_list args;
va_start(args, msg);
// Call the output function
OutputMessageImpl(msg, args);
// Finalize the arguments list
va_end(args);
}
// --------------------------------------------------------------------------------------------
void OutputError(const char * msg, ...)
{
// Initialize the arguments list
va_list args;
va_start(args, msg);
// Call the output function
OutputErrorImpl(msg, args);
// Finalize the arguments list
va_end(args);
}
} // Namespace:: SqMod
// --------------------------------------------------------------------------------------------
SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallbacks* callbacks, PluginInfo* info)
{
using namespace SqMod;
// Output plugin header
puts("");
OutputMessage("--------------------------------------------------------------------");
OutputMessage("Plugin: %s", SQTCC_NAME);
OutputMessage("Author: %s", SQTCC_AUTHOR);
OutputMessage("Legal: %s", SQTCC_COPYRIGHT);
OutputMessage("--------------------------------------------------------------------");
puts("");
// Attempt to find the host plugin ID
int host_plugin_id = functions->FindPlugin((char *)(SQMOD_HOST_NAME));
// See if our plugin was loaded after the host plugin
if (host_plugin_id < 0)
{
OutputError("%s could find the host plugin", SQTCC_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Should never reach this point but just in case
else if (host_plugin_id > (info->nPluginId))
{
OutputError("%s loaded after the host plugin", SQTCC_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Store server proxies
_Func = functions;
_Clbk = callbacks;
_Info = info;
// Assign plugin information
_Info->uPluginVer = SQTCC_VERSION;
std::strcpy(_Info->szName, SQTCC_HOST_NAME);
// Bind callbacks
BindCallbacks();
// Notify that the plugin was successfully loaded
OutputMessage("Successfully loaded %s", SQTCC_NAME);
// Dummy spacing
puts("");
// Done!
return SQMOD_SUCCESS;
}

View File

@ -1,41 +0,0 @@
#ifndef _SQTCC_MODULE_HPP_
#define _SQTCC_MODULE_HPP_
// ------------------------------------------------------------------------------------------------
#include "SqMod.h"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Proxies to comunicate with the server.
*/
extern PluginFuncs* _Func;
extern PluginCallbacks* _Clbk;
extern PluginInfo* _Info;
/* ------------------------------------------------------------------------------------------------
* Proxies to comunicate with the Squirrel plugin.
*/
extern HSQAPI _SqAPI;
extern HSQEXPORTS _SqMod;
extern HSQUIRRELVM _SqVM;
/* ------------------------------------------------------------------------------------------------
* Output a message only if the _DEBUG was defined.
*/
void OutputDebug(const char * msg, ...);
/* ------------------------------------------------------------------------------------------------
* Output a formatted user message to the console.
*/
void OutputMessage(const char * msg, ...);
/* ------------------------------------------------------------------------------------------------
* Output a formatted error message to the console.
*/
void OutputError(const char * msg, ...);
} // Namespace:: SqMod
#endif // _SQTCC_MODULE_HPP_

View File

@ -1,55 +0,0 @@
// ------------------------------------------------------------------------------------------------
#include "State.hpp"
#include "Symbol.hpp"
// ------------------------------------------------------------------------------------------------
#include <libtcc.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQInteger State::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("SqTccState");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------
void State::AddSource(CSStr filename) const
{
m_Handle.AddFile(filename, TCC_FILETYPE_C);
}
// ------------------------------------------------------------------------------------------------
void State::AddBinary(CSStr filename) const
{
m_Handle.AddFile(filename, TCC_FILETYPE_BINARY);
}
// ------------------------------------------------------------------------------------------------
void State::AddAsm(CSStr filename) const
{
m_Handle.AddFile(filename, TCC_FILETYPE_ASM);
}
// ------------------------------------------------------------------------------------------------
void State::AddAsmPP(CSStr filename) const
{
m_Handle.AddFile(filename, TCC_FILETYPE_ASM_PP);
}
// ------------------------------------------------------------------------------------------------
Symbol State::GetSymbol(CSStr name) const
{
// Is the specified name even valid?
if (!name || *name == '\0')
{
STHROWF("Invalid or empty symbol name: null");
}
// Return the requested symbol
return Symbol(m_Handle, name, m_Handle.GetSymbol< Symbol::SymPtr >(name));
}
} // Namespace:: SqMod

View File

@ -1,358 +0,0 @@
#ifndef _SQTCC_STATE_HPP_
#define _SQTCC_STATE_HPP_
// ------------------------------------------------------------------------------------------------
#include "Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Class used to manage a TCC compiler state.
*/
class State
{
private:
// --------------------------------------------------------------------------------------------
StateHnd m_Handle; // The handle to the managed compiler state resource.
public:
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
State(CSStr name)
: m_Handle(name)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Direct handle constructor.
*/
State(const StateHnd & h)
: m_Handle(h)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
State(const State & o)
: m_Handle(o.m_Handle)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
State(State && o)
: m_Handle(o.m_Handle)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~State()
{
/* Let the reference manager destroy the state when necessary. */
}
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
State & operator = (const State & o)
{
m_Handle = o.m_Handle;
return *this;
}
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
State & operator = (State && o)
{
m_Handle = o.m_Handle;
return *this;
}
/* --------------------------------------------------------------------------------------------
* Perform an equality comparison between two states.
*/
bool operator == (const State & o) const
{
return (m_Handle == o.m_Handle);
}
/* --------------------------------------------------------------------------------------------
* Perform an inequality comparison between two states.
*/
bool operator != (const State & o) const
{
return (m_Handle != o.m_Handle);
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the raw state handle.
*/
operator TCCState * ()
{
return m_Handle;
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the raw state handle.
*/
operator TCCState * () const
{
return m_Handle;
}
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const State & o) const
{
if (m_Handle == m_Handle)
{
return 0;
}
else if (m_Handle.m_Hnd > o.m_Handle.m_Hnd)
{
return 1;
}
else
{
return -1;
}
}
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const
{
return m_Handle ? m_Handle->mName.c_str() : _SC("");
}
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* See whether this state is valid.
*/
bool IsValid() const
{
return m_Handle;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated state handle.
*/
const StateHnd & GetHandle() const
{
return m_Handle;
}
/* --------------------------------------------------------------------------------------------
* Return the number of active references to this state handle.
*/
Uint32 GetRefCount() const
{
return m_Handle.Count();
}
/* --------------------------------------------------------------------------------------------
* Release the reference to the associated database state.
*/
void Release()
{
m_Handle.Drop();
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated state name.
*/
const String & GetName() const
{
// Validate the managed state
m_Handle.Validate();
// Return the requested information
return m_Handle->mName;
}
/* --------------------------------------------------------------------------------------------
* Modify the associated state name.
*/
void SetName(CSStr name)
{
// Validate the managed state
m_Handle.Validate();
// Apply the specified value
m_Handle->mName.assign(name ? name : _SC(""));
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated state receives events.
*/
bool GetEvents() const
{
// Validate the managed state
m_Handle.Validate();
// Return the requested information
return StateHnd::IsListed(m_Handle.m_Hnd);
}
/* --------------------------------------------------------------------------------------------
* Modify the associated state receives events.
*/
void SetEvents(bool toggle)
{
// Validate the managed state
m_Handle.Validate();
// Perform the requested operation
if (toggle)
{
StateHnd::Remember(m_Handle.m_Hnd);
}
else
{
StateHnd::Forget(m_Handle.m_Hnd);
}
}
/* --------------------------------------------------------------------------------------------
* Move the associated state to the head of the list.
*/
void MakeHead() const
{
// Validate the managed state
m_Handle.Validate();
// Perform the requested operation
StateHnd::ToHead(m_Handle.m_Hnd);
}
/* --------------------------------------------------------------------------------------------
* Set options as from command line (multiple supported).
*/
void SetOptions(CSStr opt) const
{
m_Handle.SetOptions(opt);
}
/* --------------------------------------------------------------------------------------------
* Define preprocessor symbol 'sym' without value.
*/
void DefineSymbol(CSStr sym) const
{
m_Handle.DefineSymbol(sym, nullptr);
}
/* --------------------------------------------------------------------------------------------
* Define preprocessor symbol 'sym' with value.
*/
void DefineSymbol(CSStr sym, CSStr value) const
{
m_Handle.DefineSymbol(sym, value);
}
/* --------------------------------------------------------------------------------------------
* Undefine preprocess symbol 'sym'.
*/
void UndefineSymbol(CSStr sym) const
{
m_Handle.UndefineSymbol(sym);
}
/* --------------------------------------------------------------------------------------------
* Add include path.
*/
void AddIncludePath(CSStr path) const
{
m_Handle.AddIncludePath(path);
}
/* --------------------------------------------------------------------------------------------
* Add in system include path.
*/
void AddSysIncludePath(CSStr path) const
{
m_Handle.AddSysIncludePath(path);
}
/* --------------------------------------------------------------------------------------------
* Set CONFIG_TCCDIR at runtime.
*/
void SetLibPath(CSStr path) const
{
m_Handle.SetLibPath(path);
}
/* --------------------------------------------------------------------------------------------
* Equivalent to -Lpath option.
*/
void AddLibraryPath(CSStr path) const
{
m_Handle.AddLibraryPath(path);
}
/* --------------------------------------------------------------------------------------------
* The library name is the same as the argument of the '-l' option.
*/
void AddLibrary(CSStr name) const
{
m_Handle.AddLibrary(name);
}
/* --------------------------------------------------------------------------------------------
* Compile a string containing a C source.
*/
void CompileString(CSStr str) const
{
m_Handle.CompileString(str);
}
/* --------------------------------------------------------------------------------------------
* Add a file containing C source.
*/
void AddSource(CSStr filename) const;
/* --------------------------------------------------------------------------------------------
* Add a binary file DLL, Object, Library etc.
*/
void AddBinary(CSStr filename) const;
/* --------------------------------------------------------------------------------------------
* Add a file containing assembly code.
*/
void AddAsm(CSStr filename) const;
/* --------------------------------------------------------------------------------------------
* Add a file containing assembly code.
*/
void AddAsmPP(CSStr filename) const;
/* --------------------------------------------------------------------------------------------
* Do all relocations (needed before using tcc_get_symbol())
*/
void Relocate() const
{
m_Handle.Relocate();
}
/* --------------------------------------------------------------------------------------------
* Return symbol from the compiled code.
*/
Symbol GetSymbol(CSStr name) const;
};
} // Namespace:: SqMod
#endif // _SQTCC_STATE_HPP_

View File

@ -1,68 +0,0 @@
// ------------------------------------------------------------------------------------------------
#include "Symbol.hpp"
#include "State.hpp"
// ------------------------------------------------------------------------------------------------
#include <libtcc.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQInteger Symbol::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("SqTccSymbol");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------
Symbol::Symbol(const State & state, CSStr name)
: Symbol(state.GetSymbol(name))
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Symbol::Symbol(const StateHnd & state, CSStr name, SymPtr sym)
: m_Handle(sym), m_State(state), m_Name(name ? name : _SC(""))
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
State Symbol::GetStateRef() const
{
return State(m_State);
}
// ------------------------------------------------------------------------------------------------
SQInteger Symbol::Forward(HSQUIRRELVM vm)
{
// The symbol instance
Symbol * symbol = nullptr;
// Attempt to retrieve the symbol instance
try
{
symbol = Var< Symbol * >(vm, 1).value;
}
catch (const Sqrat::Exception & e)
{
// Propagate the error
return sq_throwerror(vm, e.Message().c_str());
}
// Do we have a valid symbol instance?
if (!symbol)
{
return sq_throwerror(vm, "Invalid symbol instance");
}
// Do we have a valid symbol identifier?
else if (!symbol->IsValid())
{
return sq_throwerror(vm, "Invalid symbol reference");
}
// Cast the symbol to a squirrel function, forward the call and return the result
return reinterpret_cast< SQFUNCTION >((*symbol).m_Handle)(vm);
}
} // Namespace:: SqMod

View File

@ -1,215 +0,0 @@
#ifndef _SQTCC_SYMBOL_HPP_
#define _SQTCC_SYMBOL_HPP_
// ------------------------------------------------------------------------------------------------
#include "Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
*
*/
class Symbol
{
// --------------------------------------------------------------------------------------------
friend class State;
public:
// --------------------------------------------------------------------------------------------
typedef void * SymPtr; // The type of value that represents a symbol in the compiler state.
private:
// --------------------------------------------------------------------------------------------
SymPtr m_Handle; // Pointer to the actual retrieved symbol.
StateHnd m_State; // The state from where this symbol was retrieved.
String m_Name; // The name of the retrieved symbol.
protected:
/* --------------------------------------------------------------------------------------------
* Use the specified symbol and name.
*/
Symbol(const StateHnd & state, CSStr name, SymPtr sym);
public:
/* --------------------------------------------------------------------------------------------
* Extract the symbol from the specified state.
*/
Symbol(const State & state, CSStr name);
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
Symbol(const Symbol & o)
: m_Handle(o.m_Handle)
, m_State(o.m_State)
, m_Name(o.m_Name)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
Symbol(Symbol && o)
: m_Handle(o.m_Handle)
, m_State(o.m_State)
, m_Name(o.m_Name)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~Symbol()
{
/* Let the reference manager destroy the state when necessary. */
}
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
Symbol & operator = (const Symbol & o)
{
m_Handle = o.m_Handle;
m_State = o.m_State;
m_Name = o.m_Name;
return *this;
}
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
Symbol & operator = (Symbol && o)
{
m_Handle = o.m_Handle;
m_State = o.m_State;
m_Name = o.m_Name;
return *this;
}
/* --------------------------------------------------------------------------------------------
* Perform an equality comparison between two symbols.
*/
bool operator == (const Symbol & o) const
{
return (m_Handle == o.m_Handle);
}
/* --------------------------------------------------------------------------------------------
* Perform an inequality comparison between two symbols.
*/
bool operator != (const Symbol & o) const
{
return (m_Handle != o.m_Handle);
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the raw state handle.
*/
operator TCCState * ()
{
return m_State;
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the raw state handle.
*/
operator TCCState * () const
{
return m_State;
}
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Symbol & o) const
{
if (m_Handle == m_Handle)
{
return 0;
}
else if (m_Handle > o.m_Handle)
{
return 1;
}
else
{
return -1;
}
}
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
const String & ToString() const
{
return m_Name;
}
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* See whether this symbol is valid.
*/
bool IsValid() const
{
return m_Handle;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated symbol handle.
*/
SymPtr GetHandle() const
{
return m_Handle;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated state handle.
*/
const StateHnd & GetState() const
{
return m_State;
}
/* --------------------------------------------------------------------------------------------
* Return the number of active references to this state handle.
*/
Uint32 GetRefCount() const
{
return m_State.Count();
}
/* --------------------------------------------------------------------------------------------
* Release the reference to the associated database state.
*/
void Release()
{
m_Handle = nullptr;
m_Name.clear();
m_State.Drop();
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated state as a reference in script.
*/
State GetStateRef() const;
/* --------------------------------------------------------------------------------------------
* Forward this call to the actual associated symbol.
*/
static SQInteger Forward(HSQUIRRELVM vm);
};
} // Namespace:: SqMod
#endif // _SQTCC_SYMBOL_HPP_

View File

@ -124,12 +124,12 @@ bool CheckAPIVer(CCStr ver)
/* --------------------------------------------------------------------------------------------
* React to command sent by other plugins.
*/
static int OnInternalCommand(unsigned int type, const char * text)
static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
{
switch(type)
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(text))
if (CheckAPIVer(message))
{
OnSquirrelInitialize();
}
@ -148,12 +148,12 @@ static int OnInternalCommand(unsigned int type, const char * text)
/* --------------------------------------------------------------------------------------------
* The server was initialized and this plugin was loaded successfully.
*/
static int OnInitServer()
static uint8_t OnServerInitialise()
{
return 1;
}
static void OnShutdownServer(void)
static void OnServerShutdown(void)
{
// The server may still send callbacks
UnbindCallbacks();
@ -162,17 +162,17 @@ static void OnShutdownServer(void)
// ------------------------------------------------------------------------------------------------
void BindCallbacks()
{
_Clbk->OnInitServer = OnInitServer;
_Clbk->OnInternalCommand = OnInternalCommand;
_Clbk->OnShutdownServer = OnShutdownServer;
_Clbk->OnServerInitialise = OnServerInitialise;
_Clbk->OnServerShutdown = OnServerShutdown;
_Clbk->OnPluginCommand = OnPluginCommand;
}
// ------------------------------------------------------------------------------------------------
void UnbindCallbacks()
{
_Clbk->OnInitServer = nullptr;
_Clbk->OnInternalCommand = nullptr;
_Clbk->OnShutdownServer = nullptr;
_Clbk->OnServerInitialise = nullptr;
_Clbk->OnServerShutdown = nullptr;
_Clbk->OnPluginCommand = nullptr;
}
// --------------------------------------------------------------------------------------------
@ -482,17 +482,17 @@ void OutputMessageImpl(const char * msg, va_list args)
CONSOLE_SCREEN_BUFFER_INFO csb_before;
GetConsoleScreenBufferInfo( hstdout, &csb_before);
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN);
printf("[SQMOD] ");
std::printf("[SQMOD] ");
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
vprintf(msg, args);
puts("");
std::vprintf(msg, args);
std::puts("");
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
#else
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
vprintf(msg, args);
puts("");
std::printf("%c[0;32m[SQMOD]%c[0m", 27, 27);
std::vprintf(msg, args);
std::puts("");
#endif
}
@ -505,17 +505,17 @@ void OutputErrorImpl(const char * msg, va_list args)
CONSOLE_SCREEN_BUFFER_INFO csb_before;
GetConsoleScreenBufferInfo( hstdout, &csb_before);
SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
printf("[SQMOD] ");
std::printf("[SQMOD] ");
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
vprintf(msg, args);
puts("");
std::vprintf(msg, args);
std::puts("");
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
#else
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
vprintf(msg, args);
puts("");
std::printf("%c[0;91m[SQMOD]%c[0m", 27, 27);
std::vprintf(msg, args);
std::puts("");
#endif
}
@ -583,7 +583,7 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallb
return SQMOD_FAILURE;
}
// Should never reach this point but just in case
else if (host_plugin_id > (info->nPluginId))
else if (static_cast< Uint32 >(host_plugin_id) > info->pluginId)
{
OutputError("%s loaded after the host plugin", SQXML_NAME);
// Don't load!
@ -593,9 +593,12 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallb
_Func = functions;
_Clbk = callbacks;
_Info = info;
// Assign plugin information
_Info->uPluginVer = SQXML_VERSION;
std::strcpy(_Info->szName, SQXML_HOST_NAME);
// Assign plugin version
_Info->pluginVersion = SQXML_VERSION;
_Info->apiMajorVersion = PLUGIN_API_MAJOR;
_Info->apiMinorVersion = PLUGIN_API_MINOR;
// Assign the plugin name
std::snprintf(_Info->name, sizeof(_Info->name), "%s", SQXML_HOST_NAME);
// Bind callbacks
BindCallbacks();
// Notify that the plugin was successfully loaded

View File

@ -195,7 +195,7 @@ HSQEXPORTS sq_api_import(PluginFuncs * vcapi)
// Attempt to find the main plugin ID
int plugin_id = vcapi->FindPlugin((char *)(SQMOD_HOST_NAME));
// Attempt to retrieve the plugin exports
void ** plugin_exports = vcapi->GetPluginExports(plugin_id, &struct_size);
const void ** plugin_exports = vcapi->GetPluginExports(plugin_id, &struct_size);
// See if we have any imports from Squirrel
if (plugin_exports == NULL || struct_size <= 0)
{

View File

@ -17,7 +17,7 @@ SQChar AABB::Delim = ',';
// ------------------------------------------------------------------------------------------------
SQInteger AABB::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("AABB");
static const SQChar name[] = _SC("AABB");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
@ -31,14 +31,14 @@ AABB::AABB()
// ------------------------------------------------------------------------------------------------
AABB::AABB(Value sv)
: min(-sv), max(fabs(sv))
: min(-sv), max(std::fabs(sv))
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
AABB::AABB(Value xv, Value yv, Value zv)
: min(-xv, -yv, -zv), max(fabs(xv), fabs(yv), fabs(zv))
: min(-xv, -yv, -zv), max(std::fabs(xv), std::fabs(yv), std::fabs(zv))
{
/* ... */
}
@ -61,7 +61,7 @@ AABB::AABB(const Vector3 & vmin, const Vector3 & vmax)
AABB & AABB::operator = (Value s)
{
min.Set(-s);
max.Set(fabs(s));
max.Set(std::fabs(s));
return *this;
}
@ -281,11 +281,17 @@ bool AABB::operator >= (const AABB & b) const
Int32 AABB::Cmp(const AABB & o) const
{
if (*this == o)
{
return 0;
}
else if (*this > o)
{
return 1;
}
else
{
return -1;
}
}
// ------------------------------------------------------------------------------------------------
@ -298,13 +304,13 @@ CSStr AABB::ToString() const
void AABB::Set(Value ns)
{
min = -ns;
max = fabs(ns);
max = std::fabs(ns);
}
void AABB::Set(Value nx, Value ny, Value nz)
{
min.Set(-nx, -ny, -nz);
max.Set(fabs(nx), fabs(ny), fabs(nz));
max.Set(std::fabs(nx), std::fabs(ny), std::fabs(nz));
}
void AABB::Set(Value xmin, Value ymin, Value zmin, Value xmax, Value ymax, Value zmax)
@ -349,7 +355,7 @@ void AABB::Set(const Vector4 & nmin, const Vector4 & nmax)
// ------------------------------------------------------------------------------------------------
void AABB::Set(CSStr values, SQChar delim)
{
Set(GetAABB(values, delim));
Set(AABB::Get(values, delim));
}
// ------------------------------------------------------------------------------------------------
@ -359,13 +365,13 @@ AABB AABB::Abs() const
}
// ------------------------------------------------------------------------------------------------
const AABB & GetAABB(CSStr str)
const AABB & AABB::Get(CSStr str)
{
return GetAABB(str, AABB::Delim);
return AABB::Get(str, AABB::Delim);
}
// ------------------------------------------------------------------------------------------------
const AABB & GetAABB(CSStr str, SQChar delim)
const AABB & AABB::Get(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f , %f , %f , %f , %f ");
@ -389,89 +395,132 @@ const AABB & GetAABB(CSStr str, SQChar delim)
return box;
}
// ------------------------------------------------------------------------------------------------
const AABB & GetAABB()
{
static AABB box;
box.Clear();
return box;
}
const AABB & GetAABB(Float32 sv)
{
static AABB box;
box.Set(sv);
return box;
}
const AABB & GetAABB(Float32 xv, Float32 yv, Float32 zv)
{
static AABB box;
box.Set(xv, yv, zv);
return box;
}
const AABB & GetAABB(Float32 xmin, Float32 ymin, Float32 zmin, Float32 xmax, Float32 ymax, Float32 zmax)
{
static AABB box;
box.Set(xmin, ymin, zmin, xmax, ymax, zmax);
return box;
}
const AABB & GetAABB(const Vector3 & vmin, const Vector3 & vmax)
{
static AABB box;
box.Set(vmin, vmax);
return box;
}
const AABB & GetAABB(const AABB & o)
{
static AABB box;
box.Set(o);
return box;
}
// ================================================================================================
void Register_AABB(HSQUIRRELVM vm)
{
typedef AABB::Value Val;
RootTable(vm).Bind(_SC("AABB"), Class< AABB >(vm, _SC("AABB"))
/* Constructors */
// Constructors
.Ctor()
.Ctor< Val >()
.Ctor< Val, Val, Val >()
.Ctor< Val, Val, Val, Val, Val, Val >()
.Ctor< const Vector3 &, const Vector3 & >()
/* Static Members */
.SetStaticValue(_SC("delim"), &AABB::Delim)
/* Member Variables */
.Var(_SC("min"), &AABB::min)
.Var(_SC("max"), &AABB::max)
/* Properties */
.Prop(_SC("abs"), &AABB::Abs)
/* Core Metamethods */
// Static Members
.SetStaticValue(_SC("Delim"), &AABB::Delim)
// Member Variables
.Var(_SC("Min"), &AABB::min)
.Var(_SC("Max"), &AABB::max)
// Properties
.Prop(_SC("Abs"), &AABB::Abs)
// Core Metamethods
.Func(_SC("_tostring"), &AABB::ToString)
.SquirrelFunc(_SC("_typename"), &AABB::Typename)
.Func(_SC("_cmp"), &AABB::Cmp)
/* Metamethods */
.Func<AABB (AABB::*)(const AABB &) const>(_SC("_add"), &AABB::operator +)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("_sub"), &AABB::operator -)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("_mul"), &AABB::operator *)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("_div"), &AABB::operator /)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("_modulo"), &AABB::operator %)
.Func<AABB (AABB::*)(void) const>(_SC("_unm"), &AABB::operator -)
/* Setters */
.Overload<void (AABB::*)(Val)>(_SC("Set"), &AABB::Set)
.Overload<void (AABB::*)(Val, Val, Val)>(_SC("Set"), &AABB::Set)
.Overload<void (AABB::*)(Val, Val, Val, Val, Val, Val)>(_SC("Set"), &AABB::Set)
.Overload<void (AABB::*)(const AABB &)>(_SC("SetBox"), &AABB::Set)
.Overload<void (AABB::*)(const Vector3 &)>(_SC("SetVec3"), &AABB::Set)
.Overload<void (AABB::*)(const Vector3 &, const Vector3 &)>(_SC("SetVec3"), &AABB::Set)
.Overload<void (AABB::*)(const Vector4 &)>(_SC("SetVec4"), &AABB::Set)
.Overload<void (AABB::*)(const Vector4 &, const Vector4 &)>(_SC("SetVec4"), &AABB::Set)
.Overload<void (AABB::*)(CSStr, SQChar)>(_SC("SetStr"), &AABB::Set)
/* Utility Methods */
// Metamethods
.Func< AABB (AABB::*)(const AABB &) const >(_SC("_add"), &AABB::operator +)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("_sub"), &AABB::operator -)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("_mul"), &AABB::operator *)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("_div"), &AABB::operator /)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("_modulo"), &AABB::operator %)
.Func< AABB (AABB::*)(void) const >(_SC("_unm"), &AABB::operator -)
// Setters
.Overload< void (AABB::*)(Val) >(_SC("Set"), &AABB::Set)
.Overload< void (AABB::*)(Val, Val, Val) >(_SC("Set"), &AABB::Set)
.Overload< void (AABB::*)(Val, Val, Val, Val, Val, Val) >(_SC("Set"), &AABB::Set)
.Overload< void (AABB::*)(const AABB &) >(_SC("SetBox"), &AABB::Set)
.Overload< void (AABB::*)(const Vector3 &) >(_SC("SetVec3"), &AABB::Set)
.Overload< void (AABB::*)(const Vector3 &, const Vector3 &) >(_SC("SetVec3"), &AABB::Set)
.Overload< void (AABB::*)(const Vector4 &) >(_SC("SetVec4"), &AABB::Set)
.Overload< void (AABB::*)(const Vector4 &, const Vector4 &) >(_SC("SetVec4"), &AABB::Set)
.Overload< void (AABB::*)(CSStr, SQChar) >(_SC("SetStr"), &AABB::Set)
// Utility Methods
.Func(_SC("Clear"), &AABB::Clear)
/* Operator Exposure */
.Func<AABB & (AABB::*)(const AABB &)>(_SC("opAddAssign"), &AABB::operator +=)
.Func<AABB & (AABB::*)(const AABB &)>(_SC("opSubAssign"), &AABB::operator -=)
.Func<AABB & (AABB::*)(const AABB &)>(_SC("opMulAssign"), &AABB::operator *=)
.Func<AABB & (AABB::*)(const AABB &)>(_SC("opDivAssign"), &AABB::operator /=)
.Func<AABB & (AABB::*)(const AABB &)>(_SC("opModAssign"), &AABB::operator %=)
.Func<AABB & (AABB::*)(AABB::Value)>(_SC("opAddAssignS"), &AABB::operator +=)
.Func<AABB & (AABB::*)(AABB::Value)>(_SC("opSubAssignS"), &AABB::operator -=)
.Func<AABB & (AABB::*)(AABB::Value)>(_SC("opMulAssignS"), &AABB::operator *=)
.Func<AABB & (AABB::*)(AABB::Value)>(_SC("opDivAssignS"), &AABB::operator /=)
.Func<AABB & (AABB::*)(AABB::Value)>(_SC("opModAssignS"), &AABB::operator %=)
.Func<AABB & (AABB::*)(void)>(_SC("opPreInc"), &AABB::operator ++)
.Func<AABB & (AABB::*)(void)>(_SC("opPreDec"), &AABB::operator --)
.Func<AABB (AABB::*)(int)>(_SC("opPostInc"), &AABB::operator ++)
.Func<AABB (AABB::*)(int)>(_SC("opPostDec"), &AABB::operator --)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("opAdd"), &AABB::operator +)
.Func<AABB (AABB::*)(AABB::Value) const>(_SC("opAddS"), &AABB::operator +)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("opSub"), &AABB::operator -)
.Func<AABB (AABB::*)(AABB::Value) const>(_SC("opSubS"), &AABB::operator -)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("opMul"), &AABB::operator *)
.Func<AABB (AABB::*)(AABB::Value) const>(_SC("opMulS"), &AABB::operator *)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("opDiv"), &AABB::operator /)
.Func<AABB (AABB::*)(AABB::Value) const>(_SC("opDivS"), &AABB::operator /)
.Func<AABB (AABB::*)(const AABB &) const>(_SC("opMod"), &AABB::operator %)
.Func<AABB (AABB::*)(AABB::Value) const>(_SC("opModS"), &AABB::operator %)
.Func<AABB (AABB::*)(void) const>(_SC("opUnPlus"), &AABB::operator +)
.Func<AABB (AABB::*)(void) const>(_SC("opUnMinus"), &AABB::operator -)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opEqual"), &AABB::operator ==)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opNotEqual"), &AABB::operator !=)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opLessThan"), &AABB::operator <)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opGreaterThan"), &AABB::operator >)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opLessEqual"), &AABB::operator <=)
.Func<bool (AABB::*)(const AABB &) const>(_SC("opGreaterEqual"), &AABB::operator >=)
// Static Overloads
.StaticOverload< const AABB & (*)(CSStr) >(_SC("FromStr"), &GetAABB)
.StaticOverload< const AABB & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetAABB)
.StaticOverload< const AABB & (*)(CSStr) >(_SC("FromStr"), &AABB::Get)
.StaticOverload< const AABB & (*)(CSStr, SQChar) >(_SC("FromStr"), &AABB::Get)
// Operator Exposure
.Func< AABB & (AABB::*)(const AABB &) >(_SC("opAddAssign"), &AABB::operator +=)
.Func< AABB & (AABB::*)(const AABB &) >(_SC("opSubAssign"), &AABB::operator -=)
.Func< AABB & (AABB::*)(const AABB &) >(_SC("opMulAssign"), &AABB::operator *=)
.Func< AABB & (AABB::*)(const AABB &) >(_SC("opDivAssign"), &AABB::operator /=)
.Func< AABB & (AABB::*)(const AABB &) >(_SC("opModAssign"), &AABB::operator %=)
.Func< AABB & (AABB::*)(AABB::Value) >(_SC("opAddAssignS"), &AABB::operator +=)
.Func< AABB & (AABB::*)(AABB::Value) >(_SC("opSubAssignS"), &AABB::operator -=)
.Func< AABB & (AABB::*)(AABB::Value) >(_SC("opMulAssignS"), &AABB::operator *=)
.Func< AABB & (AABB::*)(AABB::Value) >(_SC("opDivAssignS"), &AABB::operator /=)
.Func< AABB & (AABB::*)(AABB::Value) >(_SC("opModAssignS"), &AABB::operator %=)
.Func< AABB & (AABB::*)(void) >(_SC("opPreInc"), &AABB::operator ++)
.Func< AABB & (AABB::*)(void) >(_SC("opPreDec"), &AABB::operator --)
.Func< AABB (AABB::*)(int) >(_SC("opPostInc"), &AABB::operator ++)
.Func< AABB (AABB::*)(int) >(_SC("opPostDec"), &AABB::operator --)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("opAdd"), &AABB::operator +)
.Func< AABB (AABB::*)(AABB::Value) const >(_SC("opAddS"), &AABB::operator +)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("opSub"), &AABB::operator -)
.Func< AABB (AABB::*)(AABB::Value) const >(_SC("opSubS"), &AABB::operator -)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("opMul"), &AABB::operator *)
.Func< AABB (AABB::*)(AABB::Value) const >(_SC("opMulS"), &AABB::operator *)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("opDiv"), &AABB::operator /)
.Func< AABB (AABB::*)(AABB::Value) const >(_SC("opDivS"), &AABB::operator /)
.Func< AABB (AABB::*)(const AABB &) const >(_SC("opMod"), &AABB::operator %)
.Func< AABB (AABB::*)(AABB::Value) const >(_SC("opModS"), &AABB::operator %)
.Func< AABB (AABB::*)(void) const >(_SC("opUnPlus"), &AABB::operator +)
.Func< AABB (AABB::*)(void) const >(_SC("opUnMinus"), &AABB::operator -)
.Func< bool (AABB::*)(const AABB &) const >(_SC("opEqual"), &AABB::operator ==)
.Func< bool (AABB::*)(const AABB &) const >(_SC("opNotEqual"), &AABB::operator !=)
.Func< bool (AABB::*)(const AABB &) const >(_SC("opLessThan"), &AABB::operator <)
.Func< bool (AABB::*)(const AABB &) const >(_SC("opGreaterThan"), &AABB::operator >)
.Func< bool (AABB::*)(const AABB &) const >(_SC("opLessEqual"), &AABB::operator <=)
.Func< bool (AABB::*)(const AABB &) const >(_SC("opGreaterEqual"), &AABB::operator >=)
);
}

View File

@ -7,16 +7,6 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the AABB type from a string.
*/
const AABB & GetAABB(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the AABB type from a string.
*/
const AABB & GetAABB(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent an axis aligned bounding box in three-dimensional space.
*/
@ -351,6 +341,17 @@ struct AABB
* Retrieve a new instance of this type with absolute component values.
*/
AABB Abs() const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the AABB type from a string.
*/
static const AABB & Get(CSStr str);
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the AABB type from a string.
*/
static const AABB & Get(CSStr str, SQChar delim);
};
} // Namespace:: SqMod

View File

@ -4,7 +4,6 @@
// ------------------------------------------------------------------------------------------------
#include <cstdlib>
#include <cstring>
#include <cstdarg>
#include <exception>
#include <stdexcept>
@ -35,9 +34,9 @@ void ThrowMemExcept(const char * msg, ...)
// Variable arguments structure
va_list args;
// Get the specified arguments
va_start (args, msg);
va_start(args, msg);
// Run the specified format
int ret = vsnprintf(buffer, sizeof(buffer), msg, args);
int ret = std::vsnprintf(buffer, sizeof(buffer), msg, args);
// Check for formatting errors
if (ret < 0)
{
@ -53,7 +52,7 @@ void ThrowMemExcept(const char * msg, ...)
static Buffer::Pointer AllocMem(Buffer::SzType size)
{
// Attempt to allocate memory directly
Buffer::Pointer ptr = reinterpret_cast< Buffer::Pointer >(malloc(size));
Buffer::Pointer ptr = reinterpret_cast< Buffer::Pointer >(std::malloc(size));
// Validate the allocated memory
if (!ptr)
{
@ -96,9 +95,9 @@ private:
struct Node
{
// ----------------------------------------------------------------------------------------
SzType mCap; /* The size of the memory chunk. */
Pointer mPtr; /* Pointer to the memory chunk. */
Node* mNext; /* The next node in the list. */
SzType mCap; // The size of the memory chunk.
Pointer mPtr; // Pointer to the memory chunk.
Node* mNext; // The next node in the list.
/* ----------------------------------------------------------------------------------------
* Base constructor.
@ -137,7 +136,7 @@ private:
// Free the memory (if any)
if (node->mPtr)
{
free(node->mPtr);
std::free(node->mPtr);
}
// Save the next node
next = node->mNext;
@ -385,7 +384,7 @@ Buffer::Buffer(const Buffer & o)
if (m_Cap)
{
Request(o.m_Cap);
memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
std::memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
}
}
@ -408,7 +407,7 @@ Buffer & Buffer::operator = (const Buffer & o)
if (m_Cap && o.m_Cap <= m_Cap)
{
// It's safe to copy the data
memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
std::memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
}
// Do we even have data to copy?
else if (!o.m_Cap)
@ -429,7 +428,7 @@ Buffer & Buffer::operator = (const Buffer & o)
// Request a larger buffer
Request(o.m_Cap);
// Now it's safe to copy the data
memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
std::memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
}
// Also copy the edit cursor
m_Cur = o.m_Cur;
@ -446,7 +445,7 @@ void Buffer::Grow(SzType n)
// Acquire a bigger buffer
Request(bkp.m_Cap + n);
// Copy the data from the old buffer
memcpy(m_Ptr, bkp.m_Ptr, bkp.m_Cap);
std::memcpy(m_Ptr, bkp.m_Ptr, bkp.m_Cap);
// Copy the previous edit cursor
m_Cur = bkp.m_Cur;
}
@ -487,7 +486,7 @@ void Buffer::Release()
// Is there a memory manager available?
if (!m_Mem)
{
free(m_Ptr); // Deallocate the memory directly
std::free(m_Ptr); // Deallocate the memory directly
}
// Find out to which category does this buffer belong
else if (m_Cap <= 1024)
@ -523,7 +522,7 @@ Buffer::SzType Buffer::Write(SzType pos, ConstPtr data, SzType size)
Grow((pos + size) - m_Cap + 32);
}
// Copy the data into the internal buffer
memcpy(m_Ptr + pos, data, size);
std::memcpy(m_Ptr + pos, data, size);
// Return the amount of data written to the buffer
return size;
}
@ -556,14 +555,14 @@ Buffer::SzType Buffer::WriteF(SzType pos, const char * fmt, va_list args)
va_copy(args_cpy, args);
// Attempt to write to the current buffer
// (if empty, it should tell us the necessary size)
int ret = vsnprintf(m_Ptr + pos, m_Cap, fmt, args);
int ret = std::vsnprintf(m_Ptr + pos, m_Cap, fmt, args);
// Do we need a bigger buffer?
if ((pos + ret) >= m_Cap)
{
// Acquire a larger buffer
Grow((pos + ret) - m_Cap + 32);
// Retry writing the requested information
ret = vsnprintf(m_Ptr + pos, m_Cap, fmt, args_cpy);
ret = std::vsnprintf(m_Ptr + pos, m_Cap, fmt, args_cpy);
}
// Return the value 0 if data could not be written
if (ret < 0)
@ -581,7 +580,7 @@ Buffer::SzType Buffer::WriteS(SzType pos, ConstPtr str)
if (str && *str != '\0')
{
// Forward this to the regular write function
return Write(pos, str, strlen(str));
return Write(pos, str, std::strlen(str));
}
// Nothing to write
return 0;
@ -605,7 +604,7 @@ void Buffer::AppendS(const char * str)
// Is there any string to write?
if (str)
{
m_Cur += Write(m_Cur, str, strlen(str));
m_Cur += Write(m_Cur, str, std::strlen(str));
}
}

View File

@ -161,6 +161,17 @@ public:
assert(m_Ptr);
return *m_Ptr;
}
/* --------------------------------------------------------------------------------------------
* Release the reference to the managed instance.
*/
void Reset()
{
if (m_Ptr)
{
Drop();
}
}
};
// ------------------------------------------------------------------------------------------------
@ -206,7 +217,7 @@ private:
public:
/* --------------------------------------------------------------------------------------------
* Default constructor (null). Not null of a previous buffer was marked as movable.
* Default constructor. (null)
*/
Buffer()
: m_Ptr(nullptr)
@ -365,20 +376,20 @@ public:
}
/* --------------------------------------------------------------------------------------------
* Retrieve the a certain element.
* Retrieve a certain element type at the specified position.
*/
template < typename T = Value > T & At(SzType n)
{
assert(n < m_Cap);
assert(n < static_cast< SzType >(m_Cap / sizeof(T)));
return reinterpret_cast< T * >(m_Ptr)[n];
}
/* --------------------------------------------------------------------------------------------
* Retrieve the a certain element.
* Retrieve a certain element type at the specified position.
*/
template < typename T = Value > const T & At(SzType n) const
{
assert(n < m_Cap);
assert(n < static_cast< SzType >(m_Cap / sizeof(T)));
return reinterpret_cast< const T * >(m_Ptr)[n];
}
@ -456,7 +467,7 @@ public:
template < typename T = Value > T & Back()
{
assert(m_Cap >= sizeof(T));
return reinterpret_cast< T * >(m_Ptr)[m_Cap-1];
return reinterpret_cast< T * >(m_Ptr)[(m_Cap / sizeof(T))-1];
}
/* --------------------------------------------------------------------------------------------
@ -465,7 +476,7 @@ public:
template < typename T = Value > const T & Back() const
{
assert(m_Cap >= sizeof(T));
return reinterpret_cast< const T * >(m_Ptr)[m_Cap-1];
return reinterpret_cast< const T * >(m_Ptr)[(m_Cap / sizeof(T))-1];
}
/* --------------------------------------------------------------------------------------------
@ -474,7 +485,7 @@ public:
template < typename T = Value > T & Prev()
{
assert(m_Cap >= (sizeof(T) * 2));
return reinterpret_cast< T * >(m_Ptr)[m_Cap-2];
return reinterpret_cast< T * >(m_Ptr)[(m_Cap / sizeof(T))-2];
}
/* --------------------------------------------------------------------------------------------
@ -483,7 +494,7 @@ public:
template < typename T = Value > const T & Prev() const
{
assert(m_Cap >= (sizeof(T) * 2));
return reinterpret_cast< const T * >(m_Ptr)[m_Cap-2];
return reinterpret_cast< const T * >(m_Ptr)[(m_Cap / sizeof(T))-2];
}
/* --------------------------------------------------------------------------------------------
@ -532,7 +543,7 @@ public:
}
/* --------------------------------------------------------------------------------------------
* Reposition the edit cursor to a fixed position within the buffer.
* Append a value to the current cursor location and advance the cursor.
*/
template < typename T = Value > void Push(T v)
{
@ -571,7 +582,7 @@ public:
template < typename T = Value > T & Before()
{
assert(m_Cur >= sizeof(T));
return reinterpret_cast< T * >(m_Ptr)[m_Cur-1];
return reinterpret_cast< T * >(m_Ptr)[(m_Cur / sizeof(T))-1];
}
/* --------------------------------------------------------------------------------------------
@ -580,7 +591,7 @@ public:
template < typename T = Value > const T & Before() const
{
assert(m_Cur >= sizeof(T));
return reinterpret_cast< const T * >(m_Ptr)[m_Cur-1];
return reinterpret_cast< const T * >(m_Ptr)[(m_Cur / sizeof(T))-1];
}
/* --------------------------------------------------------------------------------------------
@ -588,8 +599,8 @@ public:
*/
template < typename T = Value > T & After()
{
assert((m_Cur + sizeof(T)) <= (m_Cap - sizeof(T)));
return reinterpret_cast< T * >(m_Ptr)[m_Cur+1];
assert(m_Cap >= sizeof(T) && (m_Cur + sizeof(T)) <= (m_Cap - sizeof(T)));
return reinterpret_cast< T * >(m_Ptr)[(m_Cur / sizeof(T))+1];
}
/* --------------------------------------------------------------------------------------------
@ -597,8 +608,8 @@ public:
*/
template < typename T = Value > const T & After() const
{
assert((m_Cur + sizeof(T)) <= (m_Cap - sizeof(T)));
return reinterpret_cast< const T * >(m_Ptr)[m_Cur+1];
assert(m_Cap >= sizeof(T) && (m_Cur + sizeof(T)) <= (m_Cap - sizeof(T)));
return reinterpret_cast< const T * >(m_Ptr)[(m_Cur / sizeof(T))+1];
}
/* --------------------------------------------------------------------------------------------
@ -691,6 +702,18 @@ public:
}
}
/* --------------------------------------------------------------------------------------------
* Release the managed memory and manager.
*/
void ResetAll()
{
if (m_Ptr)
{
Release();
}
m_Mem.Reset();
}
/* --------------------------------------------------------------------------------------------
* Swap the contents of two buffers.
*/

View File

@ -20,7 +20,7 @@ SQChar Circle::Delim = ',';
// ------------------------------------------------------------------------------------------------
SQInteger Circle::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("Circle");
static const SQChar name[] = _SC("Circle");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
@ -98,7 +98,7 @@ Circle & Circle::operator /= (const Circle & c)
Circle & Circle::operator %= (const Circle & c)
{
pos %= c.pos;
rad = fmod(rad, c.rad);
rad = std::fmod(rad, c.rad);
return *this;
}
@ -130,7 +130,7 @@ Circle & Circle::operator /= (Value r)
Circle & Circle::operator %= (Value r)
{
rad = fmod(rad, r);
rad = std::fmod(rad, r);
return *this;
}
@ -220,7 +220,7 @@ Circle Circle::operator / (const Circle & c) const
Circle Circle::operator % (const Circle & c) const
{
return Circle(pos % c.pos, fmod(rad, c.rad));
return Circle(pos % c.pos, std::fmod(rad, c.rad));
}
// ------------------------------------------------------------------------------------------------
@ -246,7 +246,7 @@ Circle Circle::operator / (Value r) const
Circle Circle::operator % (Value r) const
{
return Circle(fmod(rad, r));
return Circle(std::fmod(rad, r));
}
// ------------------------------------------------------------------------------------------------
@ -278,7 +278,7 @@ Circle Circle::operator % (const Vector2 & p) const
// ------------------------------------------------------------------------------------------------
Circle Circle::operator + () const
{
return Circle(pos.Abs(), fabs(rad));
return Circle(pos.Abs(), std::fabs(rad));
}
Circle Circle::operator - () const
@ -321,11 +321,17 @@ bool Circle::operator >= (const Circle & c) const
Int32 Circle::Cmp(const Circle & o) const
{
if (*this == o)
{
return 0;
}
else if (*this > o)
{
return 1;
}
else
{
return -1;
}
}
// ------------------------------------------------------------------------------------------------
@ -372,7 +378,7 @@ void Circle::Set(Value nx, Value ny, Value nr)
// ------------------------------------------------------------------------------------------------
void Circle::Set(CSStr values, SQChar delim)
{
Set(GetCircle(values, delim));
Set(Circle::Get(values, delim));
}
// ------------------------------------------------------------------------------------------------
@ -385,17 +391,25 @@ void Circle::Generate()
void Circle::Generate(Value min, Value max, bool r)
{
if (EpsLt(max, min))
{
STHROWF("max value is lower than min value");
}
else if (r)
{
rad = GetRandomFloat32(min, max);
}
else
{
pos.Generate(min, max);
}
}
void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin))
{
STHROWF("max value is lower than min value");
}
pos.Generate(xmin, xmax, ymin, ymax);
}
@ -403,7 +417,9 @@ void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value rmin, Value rmax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(rmax, rmin))
{
STHROWF("max value is lower than min value");
}
pos.Generate(xmin, xmax, ymin, ymax);
rad = GetRandomFloat32(rmin, rmax);
@ -412,17 +428,17 @@ void Circle::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value rmin
// ------------------------------------------------------------------------------------------------
Circle Circle::Abs() const
{
return Circle(pos.Abs(), fabs(rad));
return Circle(pos.Abs(), std::fabs(rad));
}
// ------------------------------------------------------------------------------------------------
const Circle & GetCircle(CSStr str)
const Circle & Circle::Get(CSStr str)
{
return GetCircle(str, Circle::Delim);
return Circle::Get(str, Circle::Delim);
}
// ------------------------------------------------------------------------------------------------
const Circle & GetCircle(CSStr str, SQChar delim)
const Circle & Circle::Get(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f , %f ");
@ -443,99 +459,135 @@ const Circle & GetCircle(CSStr str, SQChar delim)
return circle;
}
// ------------------------------------------------------------------------------------------------
const Circle & GetCircle()
{
static Circle circle;
circle.Clear();
return circle;
}
const Circle & GetCircle(Float32 rv)
{
static Circle circle;
circle.Set(rv);
return circle;
}
const Circle & GetCircle(const Vector2 & pv, Float32 rv)
{
static Circle circle;
circle.Set(pv, rv);
return circle;
}
const Circle & GetCircle(Float32 xv, Float32 yv, Float32 rv)
{
static Circle circle;
circle.Set(xv, yv, rv);
return circle;
}
const Circle & GetCircle(const Circle & o)
{
static Circle circle;
circle.Set(o);
return circle;
}
// ================================================================================================
void Register_Circle(HSQUIRRELVM vm)
{
typedef Circle::Value Val;
RootTable(vm).Bind(_SC("Circle"), Class< Circle >(vm, _SC("Circle"))
/* Constructors */
// Constructors
.Ctor()
.Ctor< Val >()
.Ctor< const Vector2 &, Val >()
.Ctor< Val, Val, Val >()
/* Static Members */
// Static Members
.SetStaticValue(_SC("Delim"), &Circle::Delim)
/* Member Variables */
.Var(_SC("pos"), &Circle::pos)
.Var(_SC("rad"), &Circle::rad)
/* Properties */
.Prop(_SC("abs"), &Circle::Abs)
/* Core Metamethods */
// Member Variables
.Var(_SC("Pos"), &Circle::pos)
.Var(_SC("Rad"), &Circle::rad)
// Properties
.Prop(_SC("Abs"), &Circle::Abs)
// Core Metamethods
.Func(_SC("_tostring"), &Circle::ToString)
.SquirrelFunc(_SC("_typename"), &Circle::Typename)
.Func(_SC("_cmp"), &Circle::Cmp)
/* Metamethods */
.Func<Circle (Circle::*)(const Circle &) const>(_SC("_add"), &Circle::operator +)
.Func<Circle (Circle::*)(const Circle &) const>(_SC("_sub"), &Circle::operator -)
.Func<Circle (Circle::*)(const Circle &) const>(_SC("_mul"), &Circle::operator *)
.Func<Circle (Circle::*)(const Circle &) const>(_SC("_div"), &Circle::operator /)
.Func<Circle (Circle::*)(const Circle &) const>(_SC("_modulo"), &Circle::operator %)
.Func<Circle (Circle::*)(void) const>(_SC("_unm"), &Circle::operator -)
/* Setters */
.Overload<void (Circle::*)(const Circle &)>(_SC("Set"), &Circle::Set)
.Overload<void (Circle::*)(const Vector2 &, Val)>(_SC("Set"), &Circle::Set)
.Overload<void (Circle::*)(Val, Val, Val)>(_SC("Set"), &Circle::Set)
.Overload<void (Circle::*)(Val)>(_SC("SetRad"), &Circle::Set)
.Overload<void (Circle::*)(const Vector2 &)>(_SC("SetVec2"), &Circle::Set)
.Overload<void (Circle::*)(Val, Val)>(_SC("SetVec2"), &Circle::Set)
.Overload<void (Circle::*)(CSStr, SQChar)>(_SC("SetStr"), &Circle::Set)
/* Utility Methods */
// Metamethods
.Func< Circle (Circle::*)(const Circle &) const >(_SC("_add"), &Circle::operator +)
.Func< Circle (Circle::*)(const Circle &) const >(_SC("_sub"), &Circle::operator -)
.Func< Circle (Circle::*)(const Circle &) const >(_SC("_mul"), &Circle::operator *)
.Func< Circle (Circle::*)(const Circle &) const >(_SC("_div"), &Circle::operator /)
.Func< Circle (Circle::*)(const Circle &) const >(_SC("_modulo"), &Circle::operator %)
.Func< Circle (Circle::*)(void) const >(_SC("_unm"), &Circle::operator -)
// Setters
.Overload< void (Circle::*)(const Circle &) >(_SC("Set"), &Circle::Set)
.Overload< void (Circle::*)(const Vector2 &, Val) >(_SC("Set"), &Circle::Set)
.Overload< void (Circle::*)(Val, Val, Val) >(_SC("Set"), &Circle::Set)
.Overload< void (Circle::*)(Val) >(_SC("SetRad"), &Circle::Set)
.Overload< void (Circle::*)(const Vector2 &) >(_SC("SetVec2"), &Circle::Set)
.Overload< void (Circle::*)(Val, Val) >(_SC("SetVec2"), &Circle::Set)
.Overload< void (Circle::*)(CSStr, SQChar) >(_SC("SetStr"), &Circle::Set)
// Utility Methods
.Func(_SC("Clear"), &Circle::Clear)
/* Operator Exposure */
.Func<Circle & (Circle::*)(const Circle &)>(_SC("opAddAssign"), &Circle::operator +=)
.Func<Circle & (Circle::*)(const Circle &)>(_SC("opSubAssign"), &Circle::operator -=)
.Func<Circle & (Circle::*)(const Circle &)>(_SC("opMulAssign"), &Circle::operator *=)
.Func<Circle & (Circle::*)(const Circle &)>(_SC("opDivAssign"), &Circle::operator /=)
.Func<Circle & (Circle::*)(const Circle &)>(_SC("opModAssign"), &Circle::operator %=)
.Func<Circle & (Circle::*)(Circle::Value)>(_SC("opAddAssignR"), &Circle::operator +=)
.Func<Circle & (Circle::*)(Circle::Value)>(_SC("opSubAssignR"), &Circle::operator -=)
.Func<Circle & (Circle::*)(Circle::Value)>(_SC("opMulAssignR"), &Circle::operator *=)
.Func<Circle & (Circle::*)(Circle::Value)>(_SC("opDivAssignR"), &Circle::operator /=)
.Func<Circle & (Circle::*)(Circle::Value)>(_SC("opModAssignR"), &Circle::operator %=)
.Func<Circle & (Circle::*)(const Vector2 &)>(_SC("opAddAssignP"), &Circle::operator +=)
.Func<Circle & (Circle::*)(const Vector2 &)>(_SC("opSubAssignP"), &Circle::operator -=)
.Func<Circle & (Circle::*)(const Vector2 &)>(_SC("opMulAssignP"), &Circle::operator *=)
.Func<Circle & (Circle::*)(const Vector2 &)>(_SC("opDivAssignP"), &Circle::operator /=)
.Func<Circle & (Circle::*)(const Vector2 &)>(_SC("opModAssignP"), &Circle::operator %=)
.Func<Circle & (Circle::*)(void)>(_SC("opPreInc"), &Circle::operator ++)
.Func<Circle & (Circle::*)(void)>(_SC("opPreDec"), &Circle::operator --)
.Func<Circle (Circle::*)(int)>(_SC("opPostInc"), &Circle::operator ++)
.Func<Circle (Circle::*)(int)>(_SC("opPostDec"), &Circle::operator --)
.Func<Circle (Circle::*)(const Circle &) const>(_SC("opAdd"), &Circle::operator +)
.Func<Circle (Circle::*)(const Circle &) const>(_SC("opSub"), &Circle::operator -)
.Func<Circle (Circle::*)(const Circle &) const>(_SC("opMul"), &Circle::operator *)
.Func<Circle (Circle::*)(const Circle &) const>(_SC("opDiv"), &Circle::operator /)
.Func<Circle (Circle::*)(const Circle &) const>(_SC("opMod"), &Circle::operator %)
.Func<Circle (Circle::*)(Circle::Value) const>(_SC("opAddR"), &Circle::operator +)
.Func<Circle (Circle::*)(Circle::Value) const>(_SC("opSubR"), &Circle::operator -)
.Func<Circle (Circle::*)(Circle::Value) const>(_SC("opMulR"), &Circle::operator *)
.Func<Circle (Circle::*)(Circle::Value) const>(_SC("opDivR"), &Circle::operator /)
.Func<Circle (Circle::*)(Circle::Value) const>(_SC("opModR"), &Circle::operator %)
.Func<Circle (Circle::*)(const Vector2 &) const>(_SC("opAddP"), &Circle::operator +)
.Func<Circle (Circle::*)(const Vector2 &) const>(_SC("opSubP"), &Circle::operator -)
.Func<Circle (Circle::*)(const Vector2 &) const>(_SC("opMulP"), &Circle::operator *)
.Func<Circle (Circle::*)(const Vector2 &) const>(_SC("opDivP"), &Circle::operator /)
.Func<Circle (Circle::*)(const Vector2 &) const>(_SC("opModP"), &Circle::operator %)
.Func<Circle (Circle::*)(void) const>(_SC("opUnPlus"), &Circle::operator +)
.Func<Circle (Circle::*)(void) const>(_SC("opUnMinus"), &Circle::operator -)
.Func<bool (Circle::*)(const Circle &) const>(_SC("opEqual"), &Circle::operator ==)
.Func<bool (Circle::*)(const Circle &) const>(_SC("opNotEqual"), &Circle::operator !=)
.Func<bool (Circle::*)(const Circle &) const>(_SC("opLessThan"), &Circle::operator <)
.Func<bool (Circle::*)(const Circle &) const>(_SC("opGreaterThan"), &Circle::operator >)
.Func<bool (Circle::*)(const Circle &) const>(_SC("opLessEqual"), &Circle::operator <=)
.Func<bool (Circle::*)(const Circle &) const>(_SC("opGreaterEqual"), &Circle::operator >=)
// Static Overloads
.StaticOverload< const Circle & (*)(CSStr) >(_SC("FromStr"), &GetCircle)
.StaticOverload< const Circle & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetCircle)
.StaticOverload< const Circle & (*)(CSStr) >(_SC("FromStr"), &Circle::Get)
.StaticOverload< const Circle & (*)(CSStr, SQChar) >(_SC("FromStr"), &Circle::Get)
// Operator Exposure
.Func< Circle & (Circle::*)(const Circle &) >(_SC("opAddAssign"), &Circle::operator +=)
.Func< Circle & (Circle::*)(const Circle &) >(_SC("opSubAssign"), &Circle::operator -=)
.Func< Circle & (Circle::*)(const Circle &) >(_SC("opMulAssign"), &Circle::operator *=)
.Func< Circle & (Circle::*)(const Circle &) >(_SC("opDivAssign"), &Circle::operator /=)
.Func< Circle & (Circle::*)(const Circle &) >(_SC("opModAssign"), &Circle::operator %=)
.Func< Circle & (Circle::*)(Circle::Value) >(_SC("opAddAssignR"), &Circle::operator +=)
.Func< Circle & (Circle::*)(Circle::Value) >(_SC("opSubAssignR"), &Circle::operator -=)
.Func< Circle & (Circle::*)(Circle::Value) >(_SC("opMulAssignR"), &Circle::operator *=)
.Func< Circle & (Circle::*)(Circle::Value) >(_SC("opDivAssignR"), &Circle::operator /=)
.Func< Circle & (Circle::*)(Circle::Value) >(_SC("opModAssignR"), &Circle::operator %=)
.Func< Circle & (Circle::*)(const Vector2 &) >(_SC("opAddAssignP"), &Circle::operator +=)
.Func< Circle & (Circle::*)(const Vector2 &) >(_SC("opSubAssignP"), &Circle::operator -=)
.Func< Circle & (Circle::*)(const Vector2 &) >(_SC("opMulAssignP"), &Circle::operator *=)
.Func< Circle & (Circle::*)(const Vector2 &) >(_SC("opDivAssignP"), &Circle::operator /=)
.Func< Circle & (Circle::*)(const Vector2 &) >(_SC("opModAssignP"), &Circle::operator %=)
.Func< Circle & (Circle::*)(void) >(_SC("opPreInc"), &Circle::operator ++)
.Func< Circle & (Circle::*)(void) >(_SC("opPreDec"), &Circle::operator --)
.Func< Circle (Circle::*)(int) >(_SC("opPostInc"), &Circle::operator ++)
.Func< Circle (Circle::*)(int) >(_SC("opPostDec"), &Circle::operator --)
.Func< Circle (Circle::*)(const Circle &) const >(_SC("opAdd"), &Circle::operator +)
.Func< Circle (Circle::*)(const Circle &) const >(_SC("opSub"), &Circle::operator -)
.Func< Circle (Circle::*)(const Circle &) const >(_SC("opMul"), &Circle::operator *)
.Func< Circle (Circle::*)(const Circle &) const >(_SC("opDiv"), &Circle::operator /)
.Func< Circle (Circle::*)(const Circle &) const >(_SC("opMod"), &Circle::operator %)
.Func< Circle (Circle::*)(Circle::Value) const >(_SC("opAddR"), &Circle::operator +)
.Func< Circle (Circle::*)(Circle::Value) const >(_SC("opSubR"), &Circle::operator -)
.Func< Circle (Circle::*)(Circle::Value) const >(_SC("opMulR"), &Circle::operator *)
.Func< Circle (Circle::*)(Circle::Value) const >(_SC("opDivR"), &Circle::operator /)
.Func< Circle (Circle::*)(Circle::Value) const >(_SC("opModR"), &Circle::operator %)
.Func< Circle (Circle::*)(const Vector2 &) const >(_SC("opAddP"), &Circle::operator +)
.Func< Circle (Circle::*)(const Vector2 &) const >(_SC("opSubP"), &Circle::operator -)
.Func< Circle (Circle::*)(const Vector2 &) const >(_SC("opMulP"), &Circle::operator *)
.Func< Circle (Circle::*)(const Vector2 &) const >(_SC("opDivP"), &Circle::operator /)
.Func< Circle (Circle::*)(const Vector2 &) const >(_SC("opModP"), &Circle::operator %)
.Func< Circle (Circle::*)(void) const >(_SC("opUnPlus"), &Circle::operator +)
.Func< Circle (Circle::*)(void) const >(_SC("opUnMinus"), &Circle::operator -)
.Func< bool (Circle::*)(const Circle &) const >(_SC("opEqual"), &Circle::operator ==)
.Func< bool (Circle::*)(const Circle &) const >(_SC("opNotEqual"), &Circle::operator !=)
.Func< bool (Circle::*)(const Circle &) const >(_SC("opLessThan"), &Circle::operator <)
.Func< bool (Circle::*)(const Circle &) const >(_SC("opGreaterThan"), &Circle::operator >)
.Func< bool (Circle::*)(const Circle &) const >(_SC("opLessEqual"), &Circle::operator <=)
.Func< bool (Circle::*)(const Circle &) const >(_SC("opGreaterEqual"), &Circle::operator >=)
);
}

View File

@ -8,16 +8,6 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Circle type from a string.
*/
const Circle & GetCircle(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Circle type from a string.
*/
const Circle & GetCircle(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent a two-dimensional circle.
*/
@ -386,13 +376,25 @@ struct Circle
*/
void Clear()
{
pos.Clear(); rad = 0.0;
pos.Clear();
rad = 0.0;
}
/* --------------------------------------------------------------------------------------------
* Retrieve a new instance of this type with absolute component values.
*/
Circle Abs() const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Circle type from a string.
*/
static const Circle & Get(CSStr str);
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Circle type from a string.
*/
static const Circle & Get(CSStr str, SQChar delim);
};
} // Namespace:: SqMod

View File

@ -21,7 +21,7 @@ SQChar Color3::Delim = ',';
// ------------------------------------------------------------------------------------------------
SQInteger Color3::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("Color3");
static const SQChar name[] = _SC("Color3");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
@ -428,11 +428,17 @@ Color3::operator Color4 () const
Int32 Color3::Cmp(const Color3 & o) const
{
if (*this == o)
{
return 0;
}
else if (*this > o)
{
return 1;
}
else
{
return -1;
}
}
// ------------------------------------------------------------------------------------------------
@ -474,7 +480,7 @@ void Color3::Set(const Color4 & c)
// ------------------------------------------------------------------------------------------------
void Color3::Set(CSStr str, SQChar delim)
{
Set(GetColor3(str, delim));
Set(Color3::Get(str, delim));
}
// ------------------------------------------------------------------------------------------------
@ -533,7 +539,9 @@ void Color3::Generate()
void Color3::Generate(Value min, Value max)
{
if (max < min)
{
STHROWF("max value is lower than min value");
}
r = GetRandomUint8(min, max);
g = GetRandomUint8(min, max);
@ -543,7 +551,9 @@ void Color3::Generate(Value min, Value max)
void Color3::Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax)
{
if (rmax < rmin || gmax < gmin || bmax < bmin)
{
STHROWF("max value is lower than min value");
}
r = GetRandomUint8(rmin, rmax);
g = GetRandomUint8(gmin, gmax);
@ -565,13 +575,13 @@ void Color3::Inverse()
}
// ------------------------------------------------------------------------------------------------
const Color3 & GetColor3(CSStr str)
const Color3 & Color3::Get(CSStr str)
{
return GetColor3(str, Color3::Delim);
return Color3::Get(str, Color3::Delim);
}
// ------------------------------------------------------------------------------------------------
const Color3 & GetColor3(CSStr str, SQChar delim)
const Color3 & Color3::Get(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %u , %u , %u ");
@ -601,115 +611,144 @@ const Color3 & GetColor3(CSStr str, SQChar delim)
return col;
}
// ------------------------------------------------------------------------------------------------
const Color3 & GetColor3()
{
static Color3 col;
col.Clear();
return col;
}
const Color3 & GetColor3(Uint8 sv)
{
static Color3 col;
col.Set(sv);
return col;
}
const Color3 & GetColor3(Uint8 rv, Uint8 gv, Uint8 bv)
{
static Color3 col;
col.Set(rv, gv, bv);
return col;
}
const Color3 & GetColor3(const Color3 & o)
{
static Color3 col;
col.Set(o);
return col;
}
// ================================================================================================
void Register_Color3(HSQUIRRELVM vm)
{
typedef Color3::Value Val;
RootTable(vm).Bind(_SC("Color3"), Class< Color3 >(vm, _SC("Color3"))
/* Constructors */
// Constructors
.Ctor()
.Ctor< Val >()
.Ctor< Val, Val, Val >()
/* Static Members */
// Static Members
.SetStaticValue(_SC("Delim"), &Color3::Delim)
/* Member Variables */
.Var(_SC("r"), &Color3::r)
.Var(_SC("g"), &Color3::g)
.Var(_SC("b"), &Color3::b)
/* Properties */
.Prop(_SC("rgb"), &Color3::GetRGB, &Color3::SetRGB)
.Prop(_SC("rgba"), &Color3::GetRGBA, &Color3::SetRGBA)
.Prop(_SC("argb"), &Color3::GetARGB, &Color3::SetARGB)
.Prop(_SC("str"), &Color3::SetCol)
/* Core Metamethods */
// Member Variables
.Var(_SC("R"), &Color3::r)
.Var(_SC("G"), &Color3::g)
.Var(_SC("B"), &Color3::b)
// Properties
.Prop(_SC("RGB"), &Color3::GetRGB, &Color3::SetRGB)
.Prop(_SC("RGBA"), &Color3::GetRGBA, &Color3::SetRGBA)
.Prop(_SC("ARGB"), &Color3::GetARGB, &Color3::SetARGB)
.Prop(_SC("Str"), &Color3::SetCol)
// Core Metamethods
.Func(_SC("_tostring"), &Color3::ToString)
.SquirrelFunc(_SC("_typename"), &Color3::Typename)
.Func(_SC("_cmp"), &Color3::Cmp)
/* Metamethods */
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_add"), &Color3::operator +)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_sub"), &Color3::operator -)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_mul"), &Color3::operator *)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_div"), &Color3::operator /)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_modulo"), &Color3::operator %)
.Func<Color3 (Color3::*)(void) const>(_SC("_unm"), &Color3::operator -)
/* Setters */
.Overload<void (Color3::*)(Val)>(_SC("Set"), &Color3::Set)
.Overload<void (Color3::*)(Val, Val, Val)>(_SC("Set"), &Color3::Set)
.Overload<void (Color3::*)(const Color3 &)>(_SC("SetCol3"), &Color3::Set)
.Overload<void (Color3::*)(const Color4 &)>(_SC("SetCol4"), &Color3::Set)
.Overload<void (Color3::*)(CSStr, SQChar)>(_SC("SetStr"), &Color3::Set)
/* Random Generators */
.Overload<void (Color3::*)(void)>(_SC("Generate"), &Color3::Generate)
.Overload<void (Color3::*)(Val, Val)>(_SC("Generate"), &Color3::Generate)
.Overload<void (Color3::*)(Val, Val, Val, Val, Val, Val)>(_SC("Generate"), &Color3::Generate)
/* Utility Methods */
// Metamethods
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("_add"), &Color3::operator +)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("_sub"), &Color3::operator -)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("_mul"), &Color3::operator *)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("_div"), &Color3::operator /)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("_modulo"), &Color3::operator %)
.Func< Color3 (Color3::*)(void) const >(_SC("_unm"), &Color3::operator -)
// Setters
.Overload< void (Color3::*)(Val) >(_SC("Set"), &Color3::Set)
.Overload< void (Color3::*)(Val, Val, Val) >(_SC("Set"), &Color3::Set)
.Overload< void (Color3::*)(const Color3 &) >(_SC("SetCol3"), &Color3::Set)
.Overload< void (Color3::*)(const Color4 &) >(_SC("SetCol4"), &Color3::Set)
.Overload< void (Color3::*)(CSStr, SQChar) >(_SC("SetStr"), &Color3::Set)
// Random Generators
.Overload< void (Color3::*)(void) >(_SC("Generate"), &Color3::Generate)
.Overload< void (Color3::*)(Val, Val) >(_SC("Generate"), &Color3::Generate)
.Overload< void (Color3::*)(Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Color3::Generate)
// Utility Methods
.Func(_SC("Clear"), &Color3::Clear)
.Func(_SC("Random"), &Color3::Random)
.Func(_SC("Inverse"), &Color3::Inverse)
/* Operator Exposure */
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opAddAssign"), &Color3::operator +=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opSubAssign"), &Color3::operator -=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opMulAssign"), &Color3::operator *=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opDivAssign"), &Color3::operator /=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opModAssign"), &Color3::operator %=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opAndAssign"), &Color3::operator &=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opOrAssign"), &Color3::operator |=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opXorAssign"), &Color3::operator ^=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opShlAssign"), &Color3::operator <<=)
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opShrAssign"), &Color3::operator >>=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opAddAssignS"), &Color3::operator +=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opSubAssignS"), &Color3::operator -=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opMulAssignS"), &Color3::operator *=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opDivAssignS"), &Color3::operator /=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opModAssignS"), &Color3::operator %=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opAndAssignS"), &Color3::operator &=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opOrAssignS"), &Color3::operator |=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opXorAssignS"), &Color3::operator ^=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opShlAssignS"), &Color3::operator <<=)
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opShrAssignS"), &Color3::operator >>=)
.Func<Color3 & (Color3::*)(void)>(_SC("opPreInc"), &Color3::operator ++)
.Func<Color3 & (Color3::*)(void)>(_SC("opPreDec"), &Color3::operator --)
.Func<Color3 (Color3::*)(int)>(_SC("opPostInc"), &Color3::operator ++)
.Func<Color3 (Color3::*)(int)>(_SC("opPostDec"), &Color3::operator --)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opAdd"), &Color3::operator +)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opSub"), &Color3::operator -)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opMul"), &Color3::operator *)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opDiv"), &Color3::operator /)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opMod"), &Color3::operator %)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opAnd"), &Color3::operator &)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opOr"), &Color3::operator |)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opShl"), &Color3::operator ^)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opShl"), &Color3::operator <<)
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opShr"), &Color3::operator >>)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opAddS"), &Color3::operator +)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opSubS"), &Color3::operator -)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opMulS"), &Color3::operator *)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opDivS"), &Color3::operator /)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opModS"), &Color3::operator %)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opAndS"), &Color3::operator &)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opOrS"), &Color3::operator |)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opShlS"), &Color3::operator ^)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opShlS"), &Color3::operator <<)
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opShrS"), &Color3::operator >>)
.Func<Color3 (Color3::*)(void) const>(_SC("opUnPlus"), &Color3::operator +)
.Func<Color3 (Color3::*)(void) const>(_SC("opUnMinus"), &Color3::operator -)
.Func<Color3 (Color3::*)(void) const>(_SC("opCom"), &Color3::operator ~)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opEqual"), &Color3::operator ==)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opNotEqual"), &Color3::operator !=)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opLessThan"), &Color3::operator <)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opGreaterThan"), &Color3::operator >)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opLessEqual"), &Color3::operator <=)
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opGreaterEqual"), &Color3::operator >=)
// Static Overloads
.StaticOverload< const Color3 & (*)(CSStr) >(_SC("FromStr"), &GetColor3)
.StaticOverload< const Color3 & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetColor3)
.StaticOverload< const Color3 & (*)(CSStr) >(_SC("FromStr"), &Color3::Get)
.StaticOverload< const Color3 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Color3::Get)
// Operator Exposure
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opAddAssign"), &Color3::operator +=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opSubAssign"), &Color3::operator -=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opMulAssign"), &Color3::operator *=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opDivAssign"), &Color3::operator /=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opModAssign"), &Color3::operator %=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opAndAssign"), &Color3::operator &=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opOrAssign"), &Color3::operator |=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opXorAssign"), &Color3::operator ^=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opShlAssign"), &Color3::operator <<=)
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opShrAssign"), &Color3::operator >>=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opAddAssignS"), &Color3::operator +=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opSubAssignS"), &Color3::operator -=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opMulAssignS"), &Color3::operator *=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opDivAssignS"), &Color3::operator /=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opModAssignS"), &Color3::operator %=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opAndAssignS"), &Color3::operator &=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opOrAssignS"), &Color3::operator |=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opXorAssignS"), &Color3::operator ^=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opShlAssignS"), &Color3::operator <<=)
.Func< Color3 & (Color3::*)(Color3::Value) >(_SC("opShrAssignS"), &Color3::operator >>=)
.Func< Color3 & (Color3::*)(void) >(_SC("opPreInc"), &Color3::operator ++)
.Func< Color3 & (Color3::*)(void) >(_SC("opPreDec"), &Color3::operator --)
.Func< Color3 (Color3::*)(int) >(_SC("opPostInc"), &Color3::operator ++)
.Func< Color3 (Color3::*)(int) >(_SC("opPostDec"), &Color3::operator --)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opAdd"), &Color3::operator +)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opSub"), &Color3::operator -)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opMul"), &Color3::operator *)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opDiv"), &Color3::operator /)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opMod"), &Color3::operator %)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opAnd"), &Color3::operator &)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opOr"), &Color3::operator |)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opShl"), &Color3::operator ^)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opShl"), &Color3::operator <<)
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("opShr"), &Color3::operator >>)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opAddS"), &Color3::operator +)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opSubS"), &Color3::operator -)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opMulS"), &Color3::operator *)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opDivS"), &Color3::operator /)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opModS"), &Color3::operator %)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opAndS"), &Color3::operator &)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opOrS"), &Color3::operator |)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opShlS"), &Color3::operator ^)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opShlS"), &Color3::operator <<)
.Func< Color3 (Color3::*)(Color3::Value) const >(_SC("opShrS"), &Color3::operator >>)
.Func< Color3 (Color3::*)(void) const >(_SC("opUnPlus"), &Color3::operator +)
.Func< Color3 (Color3::*)(void) const >(_SC("opUnMinus"), &Color3::operator -)
.Func< Color3 (Color3::*)(void) const >(_SC("opCom"), &Color3::operator ~)
.Func< bool (Color3::*)(const Color3 &) const >(_SC("opEqual"), &Color3::operator ==)
.Func< bool (Color3::*)(const Color3 &) const >(_SC("opNotEqual"), &Color3::operator !=)
.Func< bool (Color3::*)(const Color3 &) const >(_SC("opLessThan"), &Color3::operator <)
.Func< bool (Color3::*)(const Color3 &) const >(_SC("opGreaterThan"), &Color3::operator >)
.Func< bool (Color3::*)(const Color3 &) const >(_SC("opLessEqual"), &Color3::operator <=)
.Func< bool (Color3::*)(const Color3 &) const >(_SC("opGreaterEqual"), &Color3::operator >=)
);
}

View File

@ -7,16 +7,6 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Color3 type from a string.
*/
const Color3 & GetColor3(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Color3 type from a string.
*/
const Color3 & GetColor3(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent an opaque RGB color.
*/
@ -476,6 +466,17 @@ struct Color3
* Inverse the color.
*/
void Inverse();
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Color3 type from a string.
*/
static const Color3 & Get(CSStr str);
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Color3 type from a string.
*/
static const Color3 & Get(CSStr str, SQChar delim);
};
} // Namespace:: SqMod

View File

@ -21,7 +21,7 @@ SQChar Color4::Delim = ',';
// ------------------------------------------------------------------------------------------------
SQInteger Color4::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("Color4");
static const SQChar name[] = _SC("Color4");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
@ -460,11 +460,17 @@ Color4::operator Color3 () const
Int32 Color4::Cmp(const Color4 & o) const
{
if (*this == o)
{
return 0;
}
else if (*this > o)
{
return 1;
}
else
{
return -1;
}
}
// ------------------------------------------------------------------------------------------------
@ -517,7 +523,7 @@ void Color4::Set(const Color3 & c)
// ------------------------------------------------------------------------------------------------
void Color4::Set(CSStr str, SQChar delim)
{
Set(GetColor4(str, delim));
Set(Color4::Get(str, delim));
}
// ------------------------------------------------------------------------------------------------
@ -579,7 +585,9 @@ void Color4::Generate()
void Color4::Generate(Value min, Value max)
{
if (max < min)
{
STHROWF("max value is lower than min value");
}
r = GetRandomUint8(min, max);
g = GetRandomUint8(min, max);
@ -590,7 +598,9 @@ void Color4::Generate(Value min, Value max)
void Color4::Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax, Value amin, Value amax)
{
if (rmax < rmin || gmax < gmin || bmax < bmin || amax < amin)
{
STHROWF("max value is lower than min value");
}
r = GetRandomUint8(rmin, rmax);
g = GetRandomUint8(gmin, gmax);
@ -614,13 +624,13 @@ void Color4::Inverse()
}
// ------------------------------------------------------------------------------------------------
const Color4 & GetColor4(CSStr str)
const Color4 & Color4::Get(CSStr str)
{
return GetColor4(str, Color4::Delim);
return Color4::Get(str, Color4::Delim);
}
// ------------------------------------------------------------------------------------------------
const Color4 & GetColor4(CSStr str, SQChar delim)
const Color4 & Color4::Get(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %u , %u , %u , %u ");
@ -642,7 +652,7 @@ const Color4 & GetColor4(CSStr str, SQChar delim)
// The sscanf function requires at least 32 bit integers
Uint32 r = 0, g = 0, b = 0, a = 0;
// Attempt to extract the component values from the specified string
sscanf(str, fs, &r, &g, &b, &a);
std::sscanf(str, fs, &r, &g, &b, &a);
// Cast the extracted integers to the value used by the Color4 type
col.r = static_cast< Color4::Value >(Clamp(r, min, max));
col.g = static_cast< Color4::Value >(Clamp(g, min, max));
@ -652,118 +662,154 @@ const Color4 & GetColor4(CSStr str, SQChar delim)
return col;
}
// ------------------------------------------------------------------------------------------------
const Color4 & GetColor4()
{
static Color4 col;
col.Clear();
return col;
}
const Color4 & GetColor4(Uint8 sv)
{
static Color4 col;
col.Set(sv);
return col;
}
const Color4 & GetColor4(Uint8 rv, Uint8 gv, Uint8 bv)
{
static Color4 col;
col.Set(rv, gv, bv);
return col;
}
const Color4 & GetColor4(Uint8 rv, Uint8 gv, Uint8 bv, Uint8 av)
{
static Color4 col;
col.Set(rv, gv, bv, av);
return col;
}
const Color4 & GetColor4(const Color4 & o)
{
static Color4 col;
col.Set(o);
return col;
}
// ================================================================================================
void Register_Color4(HSQUIRRELVM vm)
{
typedef Color4::Value Val;
RootTable(vm).Bind(_SC("Color4"), Class< Color4 >(vm, _SC("Color4"))
/* Constructors */
// Constructors
.Ctor()
.Ctor< Val >()
.Ctor< Val, Val, Val >()
.Ctor< Val, Val, Val, Val >()
/* Static Members */
// Static Members
.SetStaticValue(_SC("Delim"), &Color4::Delim)
/* Member Variables */
.Var(_SC("r"), &Color4::r)
.Var(_SC("g"), &Color4::g)
.Var(_SC("b"), &Color4::b)
.Var(_SC("a"), &Color4::a)
/* Properties */
.Prop(_SC("rgb"), &Color4::GetRGB, &Color4::SetRGB)
.Prop(_SC("rgba"), &Color4::GetRGBA, &Color4::SetRGBA)
.Prop(_SC("argb"), &Color4::GetARGB, &Color4::SetARGB)
.Prop(_SC("str"), &Color4::SetCol)
/* Core Metamethods */
// Member Variables
.Var(_SC("R"), &Color4::r)
.Var(_SC("G"), &Color4::g)
.Var(_SC("B"), &Color4::b)
.Var(_SC("A"), &Color4::a)
// Properties
.Prop(_SC("RGB"), &Color4::GetRGB, &Color4::SetRGB)
.Prop(_SC("RGBA"), &Color4::GetRGBA, &Color4::SetRGBA)
.Prop(_SC("ARGB"), &Color4::GetARGB, &Color4::SetARGB)
.Prop(_SC("Str"), &Color4::SetCol)
// Core Metamethods
.Func(_SC("_tostring"), &Color4::ToString)
.SquirrelFunc(_SC("_typename"), &Color4::Typename)
.Func(_SC("_cmp"), &Color4::Cmp)
/* Metamethods */
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("_add"), &Color4::operator +)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("_sub"), &Color4::operator -)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("_mul"), &Color4::operator *)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("_div"), &Color4::operator /)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("_modulo"), &Color4::operator %)
.Func<Color4 (Color4::*)(void) const>(_SC("_unm"), &Color4::operator -)
/* Setters */
.Overload<void (Color4::*)(Val)>(_SC("Set"), &Color4::Set)
.Overload<void (Color4::*)(Val, Val, Val)>(_SC("Set"), &Color4::Set)
.Overload<void (Color4::*)(Val, Val, Val, Val)>(_SC("Set"), &Color4::Set)
.Overload<void (Color4::*)(const Color4 &)>(_SC("SetCol4"), &Color4::Set)
.Overload<void (Color4::*)(const Color3 &)>(_SC("SetCol3"), &Color4::Set)
.Overload<void (Color4::*)(CSStr, SQChar)>(_SC("SetStr"), &Color4::Set)
/* Random Generators */
.Overload<void (Color4::*)(void)>(_SC("Generate"), &Color4::Generate)
.Overload<void (Color4::*)(Val, Val)>(_SC("Generate"), &Color4::Generate)
.Overload<void (Color4::*)(Val, Val, Val, Val, Val, Val, Val, Val)>(_SC("Generate"), &Color4::Generate)
/* Utility Methods */
// Metamethods
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_add"), &Color4::operator +)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_sub"), &Color4::operator -)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_mul"), &Color4::operator *)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_div"), &Color4::operator /)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_modulo"), &Color4::operator %)
.Func< Color4 (Color4::*)(void) const >(_SC("_unm"), &Color4::operator -)
// Setters
.Overload< void (Color4::*)(Val) >(_SC("Set"), &Color4::Set)
.Overload< void (Color4::*)(Val, Val, Val) >(_SC("Set"), &Color4::Set)
.Overload< void (Color4::*)(Val, Val, Val, Val) >(_SC("Set"), &Color4::Set)
.Overload< void (Color4::*)(const Color4 &) >(_SC("SetCol4"), &Color4::Set)
.Overload< void (Color4::*)(const Color3 &) >(_SC("SetCol3"), &Color4::Set)
.Overload< void (Color4::*)(CSStr, SQChar) >(_SC("SetStr"), &Color4::Set)
// Random Generators
.Overload< void (Color4::*)(void) >(_SC("Generate"), &Color4::Generate)
.Overload< void (Color4::*)(Val, Val) >(_SC("Generate"), &Color4::Generate)
.Overload< void (Color4::*)(Val, Val, Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Color4::Generate)
// Utility Methods
.Func(_SC("Clear"), &Color4::Clear)
.Func(_SC("Random"), &Color4::Random)
.Func(_SC("Inverse"), &Color4::Inverse)
/* Operator Exposure */
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opAddAssign"), &Color4::operator +=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opSubAssign"), &Color4::operator -=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opMulAssign"), &Color4::operator *=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opDivAssign"), &Color4::operator /=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opModAssign"), &Color4::operator %=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opAndAssign"), &Color4::operator &=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opOrAssign"), &Color4::operator |=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opXorAssign"), &Color4::operator ^=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opShlAssign"), &Color4::operator <<=)
.Func<Color4 & (Color4::*)(const Color4 &)>(_SC("opShrAssign"), &Color4::operator >>=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opAddAssignS"), &Color4::operator +=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opSubAssignS"), &Color4::operator -=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opMulAssignS"), &Color4::operator *=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opDivAssignS"), &Color4::operator /=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opModAssignS"), &Color4::operator %=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opAndAssignS"), &Color4::operator &=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opOrAssignS"), &Color4::operator |=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opXorAssignS"), &Color4::operator ^=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opShlAssignS"), &Color4::operator <<=)
.Func<Color4 & (Color4::*)(Color4::Value)>(_SC("opShrAssignS"), &Color4::operator >>=)
.Func<Color4 & (Color4::*)(void)>(_SC("opPreInc"), &Color4::operator ++)
.Func<Color4 & (Color4::*)(void)>(_SC("opPreDec"), &Color4::operator --)
.Func<Color4 (Color4::*)(int)>(_SC("opPostInc"), &Color4::operator ++)
.Func<Color4 (Color4::*)(int)>(_SC("opPostDec"), &Color4::operator --)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opAdd"), &Color4::operator +)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opSub"), &Color4::operator -)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opMul"), &Color4::operator *)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opDiv"), &Color4::operator /)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opMod"), &Color4::operator %)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opAnd"), &Color4::operator &)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opOr"), &Color4::operator |)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opShl"), &Color4::operator ^)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opShl"), &Color4::operator <<)
.Func<Color4 (Color4::*)(const Color4 &) const>(_SC("opShr"), &Color4::operator >>)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opAddS"), &Color4::operator +)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opSubS"), &Color4::operator -)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opMulS"), &Color4::operator *)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opDivS"), &Color4::operator /)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opModS"), &Color4::operator %)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opAndS"), &Color4::operator &)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opOrS"), &Color4::operator |)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opShlS"), &Color4::operator ^)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opShlS"), &Color4::operator <<)
.Func<Color4 (Color4::*)(Color4::Value) const>(_SC("opShrS"), &Color4::operator >>)
.Func<Color4 (Color4::*)(void) const>(_SC("opUnPlus"), &Color4::operator +)
.Func<Color4 (Color4::*)(void) const>(_SC("opUnMinus"), &Color4::operator -)
.Func<Color4 (Color4::*)(void) const>(_SC("opCom"), &Color4::operator ~)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opEqual"), &Color4::operator ==)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opNotEqual"), &Color4::operator !=)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opLessThan"), &Color4::operator <)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opGreaterThan"), &Color4::operator >)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opLessEqual"), &Color4::operator <=)
.Func<bool (Color4::*)(const Color4 &) const>(_SC("opGreaterEqual"), &Color4::operator >=)
// Static Overloads
.StaticOverload< const Color4 & (*)(CSStr) >(_SC("FromStr"), &GetColor4)
.StaticOverload< const Color4 & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetColor4)
.StaticOverload< const Color4 & (*)(CSStr) >(_SC("FromStr"), &Color4::Get)
.StaticOverload< const Color4 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Color4::Get)
// Operator Exposure
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opAddAssign"), &Color4::operator +=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opSubAssign"), &Color4::operator -=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opMulAssign"), &Color4::operator *=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opDivAssign"), &Color4::operator /=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opModAssign"), &Color4::operator %=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opAndAssign"), &Color4::operator &=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opOrAssign"), &Color4::operator |=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opXorAssign"), &Color4::operator ^=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opShlAssign"), &Color4::operator <<=)
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opShrAssign"), &Color4::operator >>=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opAddAssignS"), &Color4::operator +=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opSubAssignS"), &Color4::operator -=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opMulAssignS"), &Color4::operator *=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opDivAssignS"), &Color4::operator /=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opModAssignS"), &Color4::operator %=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opAndAssignS"), &Color4::operator &=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opOrAssignS"), &Color4::operator |=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opXorAssignS"), &Color4::operator ^=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opShlAssignS"), &Color4::operator <<=)
.Func< Color4 & (Color4::*)(Color4::Value) >(_SC("opShrAssignS"), &Color4::operator >>=)
.Func< Color4 & (Color4::*)(void) >(_SC("opPreInc"), &Color4::operator ++)
.Func< Color4 & (Color4::*)(void) >(_SC("opPreDec"), &Color4::operator --)
.Func< Color4 (Color4::*)(int) >(_SC("opPostInc"), &Color4::operator ++)
.Func< Color4 (Color4::*)(int) >(_SC("opPostDec"), &Color4::operator --)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opAdd"), &Color4::operator +)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opSub"), &Color4::operator -)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opMul"), &Color4::operator *)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opDiv"), &Color4::operator /)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opMod"), &Color4::operator %)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opAnd"), &Color4::operator &)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opOr"), &Color4::operator |)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opShl"), &Color4::operator ^)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opShl"), &Color4::operator <<)
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("opShr"), &Color4::operator >>)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opAddS"), &Color4::operator +)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opSubS"), &Color4::operator -)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opMulS"), &Color4::operator *)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opDivS"), &Color4::operator /)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opModS"), &Color4::operator %)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opAndS"), &Color4::operator &)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opOrS"), &Color4::operator |)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opShlS"), &Color4::operator ^)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opShlS"), &Color4::operator <<)
.Func< Color4 (Color4::*)(Color4::Value) const >(_SC("opShrS"), &Color4::operator >>)
.Func< Color4 (Color4::*)(void) const >(_SC("opUnPlus"), &Color4::operator +)
.Func< Color4 (Color4::*)(void) const >(_SC("opUnMinus"), &Color4::operator -)
.Func< Color4 (Color4::*)(void) const >(_SC("opCom"), &Color4::operator ~)
.Func< bool (Color4::*)(const Color4 &) const >(_SC("opEqual"), &Color4::operator ==)
.Func< bool (Color4::*)(const Color4 &) const >(_SC("opNotEqual"), &Color4::operator !=)
.Func< bool (Color4::*)(const Color4 &) const >(_SC("opLessThan"), &Color4::operator <)
.Func< bool (Color4::*)(const Color4 &) const >(_SC("opGreaterThan"), &Color4::operator >)
.Func< bool (Color4::*)(const Color4 &) const >(_SC("opLessEqual"), &Color4::operator <=)
.Func< bool (Color4::*)(const Color4 &) const >(_SC("opGreaterEqual"), &Color4::operator >=)
);
}

View File

@ -7,16 +7,6 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Color4 type from a string.
*/
const Color4 & GetColor4(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Color4 type from a string.
*/
const Color4 & GetColor4(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent a transparent RGBA color.
*/
@ -486,6 +476,17 @@ struct Color4
* Inverse the color.
*/
void Inverse();
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Color4 type from a string.
*/
static const Color4 & Get(CSStr str);
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Color4 type from a string.
*/
static const Color4 & Get(CSStr str, SQChar delim);
};
} // Namespace:: SqMod

View File

@ -22,7 +22,7 @@ SQChar Quaternion::Delim = ',';
// ------------------------------------------------------------------------------------------------
SQInteger Quaternion::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("Quaternion");
static const SQChar name[] = _SC("Quaternion");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
@ -122,10 +122,10 @@ Quaternion & Quaternion::operator /= (const Quaternion & q)
Quaternion & Quaternion::operator %= (const Quaternion & q)
{
x = fmod(x, q.x);
y = fmod(y, q.y);
z = fmod(z, q.z);
w = fmod(w, q.w);
x = std::fmod(x, q.x);
y = std::fmod(y, q.y);
z = std::fmod(z, q.z);
w = std::fmod(w, q.w);
return *this;
}
@ -168,10 +168,10 @@ Quaternion & Quaternion::operator /= (Value s)
Quaternion & Quaternion::operator %= (Value s)
{
x = fmod(x, s);
y = fmod(y, s);
z = fmod(z, s);
w = fmod(w, s);
x = std::fmod(x, s);
y = std::fmod(y, s);
z = std::fmod(z, s);
w = std::fmod(w, s);
return *this;
}
@ -262,18 +262,18 @@ Quaternion Quaternion::operator / (Value s) const
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::operator % (const Quaternion & q) const
{
return Quaternion(fmod(x, q.x), fmod(y, q.y), fmod(z, q.z), fmod(w, q.w));
return Quaternion(std::fmod(x, q.x), std::fmod(y, q.y), std::fmod(z, q.z), std::fmod(w, q.w));
}
Quaternion Quaternion::operator % (Value s) const
{
return Quaternion(fmod(x, s), fmod(y, s), fmod(z, s), fmod(w, s));
return Quaternion(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s), std::fmod(w, s));
}
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::operator + () const
{
return Quaternion(fabs(x), fabs(y), fabs(z), fabs(w));
return Quaternion(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
}
Quaternion Quaternion::operator - () const
@ -316,11 +316,17 @@ bool Quaternion::operator >= (const Quaternion & q) const
Int32 Quaternion::Cmp(const Quaternion & o) const
{
if (*this == o)
{
return 0;
}
else if (*this > o)
{
return 1;
}
else
{
return -1;
}
}
// ------------------------------------------------------------------------------------------------
@ -381,7 +387,7 @@ void Quaternion::Set(const Vector4 & v)
// ------------------------------------------------------------------------------------------------
void Quaternion::Set(CSStr values, SQChar delim)
{
Set(GetQuaternion(values, delim));
Set(Quaternion::Get(values, delim));
}
// ------------------------------------------------------------------------------------------------
@ -396,7 +402,9 @@ void Quaternion::Generate()
void Quaternion::Generate(Value min, Value max)
{
if (EpsLt(max, min))
{
STHROWF("max value is lower than min value");
}
x = GetRandomFloat32(min, max);
y = GetRandomFloat32(min, max);
@ -407,7 +415,9 @@ void Quaternion::Generate(Value min, Value max)
void Quaternion::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin) || EpsLt(wmax, wmin))
{
STHROWF("max value is lower than min value");
}
x = GetRandomFloat32(xmin, xmax);
y = GetRandomFloat32(ymin, ymax);
@ -418,17 +428,17 @@ void Quaternion::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value
// ------------------------------------------------------------------------------------------------
Quaternion Quaternion::Abs() const
{
return Quaternion(fabs(x), fabs(y), fabs(z), fabs(w));
return Quaternion(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
}
// ------------------------------------------------------------------------------------------------
const Quaternion & GetQuaternion(CSStr str)
const Quaternion & Quaternion::Get(CSStr str)
{
return GetQuaternion(str, Quaternion::Delim);
return Quaternion::Get(str, Quaternion::Delim);
}
// ------------------------------------------------------------------------------------------------
const Quaternion & GetQuaternion(CSStr str, SQChar delim)
const Quaternion & Quaternion::Get(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f , %f , %f ");
@ -445,98 +455,134 @@ const Quaternion & GetQuaternion(CSStr str, SQChar delim)
fs[9] = delim;
fs[14] = delim;
// Attempt to extract the component values from the specified string
sscanf(str, fs, &quat.x, &quat.y, &quat.z, &quat.w);
std::sscanf(str, fs, &quat.x, &quat.y, &quat.z, &quat.w);
// Return the resulted value
return quat;
}
// ------------------------------------------------------------------------------------------------
const Quaternion & GetQuaternion()
{
static Quaternion quat;
quat.Clear();
return quat;
}
const Quaternion & GetQuaternion(Float32 sv)
{
static Quaternion quat;
quat.Set(sv);
return quat;
}
const Quaternion & GetQuaternion(Float32 xv, Float32 yv, Float32 zv)
{
static Quaternion quat;
quat.Set(xv, yv, zv);
return quat;
}
const Quaternion & GetQuaternion(Float32 xv, Float32 yv, Float32 zv, Float32 wv)
{
static Quaternion quat;
quat.Set(xv, yv, zv, wv);
return quat;
}
const Quaternion & GetQuaternion(const Quaternion & o)
{
static Quaternion quat;
quat.Set(o);
return quat;
}
// ================================================================================================
void Register_Quaternion(HSQUIRRELVM vm)
{
typedef Quaternion::Value Val;
RootTable(vm).Bind(_SC("Quaternion"), Class< Quaternion >(vm, _SC("Quaternion"))
/* Constructors */
// Constructors
.Ctor()
.Ctor< Val >()
.Ctor< Val, Val, Val >()
.Ctor< Val, Val, Val, Val >()
/* Static Members */
// Static Members
.SetStaticValue(_SC("Delim"), &Quaternion::Delim)
/* Member Variables */
.Var(_SC("x"), &Quaternion::x)
.Var(_SC("y"), &Quaternion::y)
.Var(_SC("z"), &Quaternion::z)
.Var(_SC("w"), &Quaternion::w)
/* Properties */
.Prop(_SC("abs"), &Quaternion::Abs)
/* Core Metamethods */
// Member Variables
.Var(_SC("X"), &Quaternion::x)
.Var(_SC("Y"), &Quaternion::y)
.Var(_SC("Z"), &Quaternion::z)
.Var(_SC("W"), &Quaternion::w)
// Properties
.Prop(_SC("Abs"), &Quaternion::Abs)
// Core Metamethods
.Func(_SC("_tostring"), &Quaternion::ToString)
.SquirrelFunc(_SC("_typename"), &Quaternion::Typename)
.Func(_SC("_cmp"), &Quaternion::Cmp)
/* Metamethods */
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("_add"), &Quaternion::operator +)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("_sub"), &Quaternion::operator -)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("_mul"), &Quaternion::operator *)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("_div"), &Quaternion::operator /)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("_modulo"), &Quaternion::operator %)
.Func<Quaternion (Quaternion::*)(void) const>(_SC("_unm"), &Quaternion::operator -)
/* Setters */
.Overload<void (Quaternion::*)(Val)>(_SC("Set"), &Quaternion::Set)
.Overload<void (Quaternion::*)(Val, Val, Val)>(_SC("Set"), &Quaternion::Set)
.Overload<void (Quaternion::*)(Val, Val, Val, Val)>(_SC("Set"), &Quaternion::Set)
.Overload<void (Quaternion::*)(const Quaternion &)>(_SC("SetQuat"), &Quaternion::Set)
.Overload<void (Quaternion::*)(const Vector3 &)>(_SC("SetVec3"), &Quaternion::Set)
.Overload<void (Quaternion::*)(const Vector4 &)>(_SC("SetVec4"), &Quaternion::Set)
.Overload<void (Quaternion::*)(CSStr, SQChar)>(_SC("SetStr"), &Quaternion::Set)
/* Random Generators */
.Overload<void (Quaternion::*)(void)>(_SC("Generate"), &Quaternion::Generate)
.Overload<void (Quaternion::*)(Val, Val)>(_SC("Generate"), &Quaternion::Generate)
.Overload<void (Quaternion::*)(Val, Val, Val, Val, Val, Val, Val, Val)>(_SC("Generate"), &Quaternion::Generate)
/* Utility Methods */
// Metamethods
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("_add"), &Quaternion::operator +)
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("_sub"), &Quaternion::operator -)
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("_mul"), &Quaternion::operator *)
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("_div"), &Quaternion::operator /)
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("_modulo"), &Quaternion::operator %)
.Func< Quaternion (Quaternion::*)(void) const >(_SC("_unm"), &Quaternion::operator -)
// Setters
.Overload< void (Quaternion::*)(Val) >(_SC("Set"), &Quaternion::Set)
.Overload< void (Quaternion::*)(Val, Val, Val) >(_SC("Set"), &Quaternion::Set)
.Overload< void (Quaternion::*)(Val, Val, Val, Val) >(_SC("Set"), &Quaternion::Set)
.Overload< void (Quaternion::*)(const Quaternion &) >(_SC("SetQuat"), &Quaternion::Set)
.Overload< void (Quaternion::*)(const Vector3 &) >(_SC("SetVec3"), &Quaternion::Set)
.Overload< void (Quaternion::*)(const Vector4 &) >(_SC("SetVec4"), &Quaternion::Set)
.Overload< void (Quaternion::*)(CSStr, SQChar) >(_SC("SetStr"), &Quaternion::Set)
// Random Generators
.Overload< void (Quaternion::*)(void) >(_SC("Generate"), &Quaternion::Generate)
.Overload< void (Quaternion::*)(Val, Val) >(_SC("Generate"), &Quaternion::Generate)
.Overload< void (Quaternion::*)(Val, Val, Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Quaternion::Generate)
// Utility Methods
.Func(_SC("Clear"), &Quaternion::Clear)
/* Operator Exposure */
.Func<Quaternion & (Quaternion::*)(const Quaternion &)>(_SC("opAddAssign"), &Quaternion::operator +=)
.Func<Quaternion & (Quaternion::*)(const Quaternion &)>(_SC("opSubAssign"), &Quaternion::operator -=)
.Func<Quaternion & (Quaternion::*)(const Quaternion &)>(_SC("opMulAssign"), &Quaternion::operator *=)
.Func<Quaternion & (Quaternion::*)(const Quaternion &)>(_SC("opDivAssign"), &Quaternion::operator /=)
.Func<Quaternion & (Quaternion::*)(const Quaternion &)>(_SC("opModAssign"), &Quaternion::operator %=)
.Func<Quaternion & (Quaternion::*)(Quaternion::Value)>(_SC("opAddAssignS"), &Quaternion::operator +=)
.Func<Quaternion & (Quaternion::*)(Quaternion::Value)>(_SC("opSubAssignS"), &Quaternion::operator -=)
.Func<Quaternion & (Quaternion::*)(Quaternion::Value)>(_SC("opMulAssignS"), &Quaternion::operator *=)
.Func<Quaternion & (Quaternion::*)(Quaternion::Value)>(_SC("opDivAssignS"), &Quaternion::operator /=)
.Func<Quaternion & (Quaternion::*)(Quaternion::Value)>(_SC("opModAssignS"), &Quaternion::operator %=)
.Func<Quaternion & (Quaternion::*)(void)>(_SC("opPreInc"), &Quaternion::operator ++)
.Func<Quaternion & (Quaternion::*)(void)>(_SC("opPreDec"), &Quaternion::operator --)
.Func<Quaternion (Quaternion::*)(int)>(_SC("opPostInc"), &Quaternion::operator ++)
.Func<Quaternion (Quaternion::*)(int)>(_SC("opPostDec"), &Quaternion::operator --)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("opAdd"), &Quaternion::operator +)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("opSub"), &Quaternion::operator -)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("opMul"), &Quaternion::operator *)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("opDiv"), &Quaternion::operator /)
.Func<Quaternion (Quaternion::*)(const Quaternion &) const>(_SC("opMod"), &Quaternion::operator %)
.Func<Quaternion (Quaternion::*)(Quaternion::Value) const>(_SC("opAddS"), &Quaternion::operator +)
.Func<Quaternion (Quaternion::*)(Quaternion::Value) const>(_SC("opSubS"), &Quaternion::operator -)
.Func<Quaternion (Quaternion::*)(Quaternion::Value) const>(_SC("opMulS"), &Quaternion::operator *)
.Func<Quaternion (Quaternion::*)(Quaternion::Value) const>(_SC("opDivS"), &Quaternion::operator /)
.Func<Quaternion (Quaternion::*)(Quaternion::Value) const>(_SC("opModS"), &Quaternion::operator %)
.Func<Quaternion (Quaternion::*)(void) const>(_SC("opUnPlus"), &Quaternion::operator +)
.Func<Quaternion (Quaternion::*)(void) const>(_SC("opUnMinus"), &Quaternion::operator -)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opEqual"), &Quaternion::operator ==)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opNotEqual"), &Quaternion::operator !=)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opLessThan"), &Quaternion::operator <)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opGreaterThan"), &Quaternion::operator >)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opLessEqual"), &Quaternion::operator <=)
.Func<bool (Quaternion::*)(const Quaternion &) const>(_SC("opGreaterEqual"), &Quaternion::operator >=)
// Static Overloads
.StaticOverload< const Quaternion & (*)(CSStr) >(_SC("FromStr"), &GetQuaternion)
.StaticOverload< const Quaternion & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetQuaternion)
.StaticOverload< const Quaternion & (*)(CSStr) >(_SC("FromStr"), &Quaternion::Get)
.StaticOverload< const Quaternion & (*)(CSStr, SQChar) >(_SC("FromStr"), &Quaternion::Get)
// Operator Exposure
.Func< Quaternion & (Quaternion::*)(const Quaternion &) >(_SC("opAddAssign"), &Quaternion::operator +=)
.Func< Quaternion & (Quaternion::*)(const Quaternion &) >(_SC("opSubAssign"), &Quaternion::operator -=)
.Func< Quaternion & (Quaternion::*)(const Quaternion &) >(_SC("opMulAssign"), &Quaternion::operator *=)
.Func< Quaternion & (Quaternion::*)(const Quaternion &) >(_SC("opDivAssign"), &Quaternion::operator /=)
.Func< Quaternion & (Quaternion::*)(const Quaternion &) >(_SC("opModAssign"), &Quaternion::operator %=)
.Func< Quaternion & (Quaternion::*)(Quaternion::Value) >(_SC("opAddAssignS"), &Quaternion::operator +=)
.Func< Quaternion & (Quaternion::*)(Quaternion::Value) >(_SC("opSubAssignS"), &Quaternion::operator -=)
.Func< Quaternion & (Quaternion::*)(Quaternion::Value) >(_SC("opMulAssignS"), &Quaternion::operator *=)
.Func< Quaternion & (Quaternion::*)(Quaternion::Value) >(_SC("opDivAssignS"), &Quaternion::operator /=)
.Func< Quaternion & (Quaternion::*)(Quaternion::Value) >(_SC("opModAssignS"), &Quaternion::operator %=)
.Func< Quaternion & (Quaternion::*)(void) >(_SC("opPreInc"), &Quaternion::operator ++)
.Func< Quaternion & (Quaternion::*)(void) >(_SC("opPreDec"), &Quaternion::operator --)
.Func< Quaternion (Quaternion::*)(int) >(_SC("opPostInc"), &Quaternion::operator ++)
.Func< Quaternion (Quaternion::*)(int) >(_SC("opPostDec"), &Quaternion::operator --)
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("opAdd"), &Quaternion::operator +)
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("opSub"), &Quaternion::operator -)
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("opMul"), &Quaternion::operator *)
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("opDiv"), &Quaternion::operator /)
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("opMod"), &Quaternion::operator %)
.Func< Quaternion (Quaternion::*)(Quaternion::Value) const >(_SC("opAddS"), &Quaternion::operator +)
.Func< Quaternion (Quaternion::*)(Quaternion::Value) const >(_SC("opSubS"), &Quaternion::operator -)
.Func< Quaternion (Quaternion::*)(Quaternion::Value) const >(_SC("opMulS"), &Quaternion::operator *)
.Func< Quaternion (Quaternion::*)(Quaternion::Value) const >(_SC("opDivS"), &Quaternion::operator /)
.Func< Quaternion (Quaternion::*)(Quaternion::Value) const >(_SC("opModS"), &Quaternion::operator %)
.Func< Quaternion (Quaternion::*)(void) const >(_SC("opUnPlus"), &Quaternion::operator +)
.Func< Quaternion (Quaternion::*)(void) const >(_SC("opUnMinus"), &Quaternion::operator -)
.Func< bool (Quaternion::*)(const Quaternion &) const >(_SC("opEqual"), &Quaternion::operator ==)
.Func< bool (Quaternion::*)(const Quaternion &) const >(_SC("opNotEqual"), &Quaternion::operator !=)
.Func< bool (Quaternion::*)(const Quaternion &) const >(_SC("opLessThan"), &Quaternion::operator <)
.Func< bool (Quaternion::*)(const Quaternion &) const >(_SC("opGreaterThan"), &Quaternion::operator >)
.Func< bool (Quaternion::*)(const Quaternion &) const >(_SC("opLessEqual"), &Quaternion::operator <=)
.Func< bool (Quaternion::*)(const Quaternion &) const >(_SC("opGreaterEqual"), &Quaternion::operator >=)
);
}

View File

@ -7,16 +7,6 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Quaternion type from a string.
*/
const Quaternion & GetQuaternion(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Quaternion type from a string.
*/
const Quaternion & GetQuaternion(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Quaternion class for representing rotations.
*/
@ -341,6 +331,17 @@ struct Quaternion
* Retrieve a new instance of this type with absolute component values.
*/
Quaternion Abs() const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Quaternion type from a string.
*/
static const Quaternion & Get(CSStr str);
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Quaternion type from a string.
*/
static const Quaternion & Get(CSStr str, SQChar delim);
};
} // Namespace:: SqMod

View File

@ -1,11 +1,10 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Base/Buffer.hpp"
#include "Base/Color3.hpp"
#include "Library/Random.hpp"
#include "Library/String.hpp"
// ------------------------------------------------------------------------------------------------
#include "Base/Color3.hpp"
#include "Library/Numeric.hpp"
// ------------------------------------------------------------------------------------------------
#include <ctime>
@ -22,13 +21,9 @@
namespace SqMod {
// ------------------------------------------------------------------------------------------------
static const SQChar EMPTY_STR_CHAR = 0;
const SQChar * g_EmptyStr = &EMPTY_STR_CHAR;
// ------------------------------------------------------------------------------------------------
PluginFuncs* _Func = NULL;
PluginCallbacks* _Clbk = NULL;
PluginInfo* _Info = NULL;
PluginFuncs* _Func = nullptr;
PluginCallbacks* _Clbk = nullptr;
PluginInfo* _Info = nullptr;
/* ------------------------------------------------------------------------------------------------
* Common buffer to reduce memory allocations. To be immediately copied upon return!
@ -36,108 +31,6 @@ PluginInfo* _Info = NULL;
static SQChar g_Buffer[4096];
static SQChar g_NumBuff[1024];
// ------------------------------------------------------------------------------------------------
Object & NullObject()
{
static Object o;
o.Release();
return o;
}
// ------------------------------------------------------------------------------------------------
Array & NullArray()
{
static Array a;
a.Release();
return a;
}
// ------------------------------------------------------------------------------------------------
Function & NullFunction()
{
static Function f;
f.Release();
return f;
}
// ------------------------------------------------------------------------------------------------
bool SToB(CSStr str)
{
// Temporary buffer to store the lowercase string
SQChar buffer[8];
// The currently processed character
unsigned i = 0;
// Convert only the necessary characters to lowercase
while (i < 7 && *str != '\0')
{
buffer[i++] = static_cast< SQChar >(std::tolower(*(str++)));
}
// Add the null terminator
buffer[i] = '\0';
// Compare the lowercase string and return the result
return (std::strcmp(buffer, "true") == 0 || std::strcmp(buffer, "yes") == 0 ||
std::strcmp(buffer, "on") == 0 || std::strcmp(buffer, "1") == 0) ? true : false;
}
// ------------------------------------------------------------------------------------------------
void SqThrowF(CSStr fmt, ...)
{
// Acquire a moderately sized buffer
Buffer b(128);
// Initialize the argument list
va_list args;
va_start (args, fmt);
// Attempt to run the specified format
if (b.WriteF(0, fmt, args) == 0)
{
// Attempt to write a generic message at least
b.At(b.WriteS(0, "Unknown error has occurred")) = '\0';
}
// Release the argument list
va_end(args);
// Throw the exception with the resulted message
throw Sqrat::Exception(b.Get< SQChar >());
}
// ------------------------------------------------------------------------------------------------
CSStr ToStrF(CSStr fmt, ...)
{
// Prepare the arguments list
va_list args;
va_start(args, fmt);
// Attempt to run the specified format
int ret = vsnprintf(g_Buffer, sizeof(g_Buffer), fmt, args);
// See if the format function failed
if (ret < 0)
{
STHROWF("Failed to run the specified string format");
}
// Finalized the arguments list
va_end(args);
// Return the resulted string
return g_Buffer;
}
// ------------------------------------------------------------------------------------------------
CSStr ToStringF(CSStr fmt, ...)
{
// Acquire a moderately sized buffer
Buffer b(128);
// Prepare the arguments list
va_list args;
va_start (args, fmt);
// Attempt to run the specified format
if (b.WriteF(0, fmt, args) == 0)
{
// Make sure the string is null terminated
b.At(0) = 0;
}
// Finalized the arguments list
va_end(args);
// Return the resulted string
return b.Get< SQChar >();
}
// ------------------------------------------------------------------------------------------------
static const Color3 SQ_Color_List[] =
{
@ -283,6 +176,158 @@ static const Color3 SQ_Color_List[] =
Color3(154, 205, 50)
};
// ------------------------------------------------------------------------------------------------
const SLongInt & GetSLongInt()
{
static SLongInt l;
l.SetNum(0);
return l;
}
const SLongInt & GetSLongInt(Int64 n)
{
static SLongInt l;
l.SetNum(n);
return l;
}
const SLongInt & GetSLongInt(CSStr s)
{
static SLongInt l;
l = s;
return l;
}
const ULongInt & GetULongInt()
{
static ULongInt l;
l.SetNum(0);
return l;
}
const ULongInt & GetULongInt(Uint64 n)
{
static ULongInt l;
l.SetNum(n);
return l;
}
const ULongInt & GetULongInt(CSStr s)
{
static ULongInt l;
l = s;
return l;
}
// ------------------------------------------------------------------------------------------------
Object & NullObject()
{
static Object o;
o.Release();
return o;
}
// ------------------------------------------------------------------------------------------------
Table & NullTable()
{
static Table t;
t.Release();
return t;
}
// ------------------------------------------------------------------------------------------------
Array & NullArray()
{
static Array a;
a.Release();
return a;
}
// ------------------------------------------------------------------------------------------------
Function & NullFunction()
{
static Function f;
f.Release();
return f;
}
// ------------------------------------------------------------------------------------------------
bool SToB(CSStr str)
{
// Temporary buffer to store the lowercase string
SQChar buffer[8];
// The currently processed character
unsigned i = 0;
// Convert only the necessary characters to lowercase
while (i < 7 && *str != '\0')
{
buffer[i++] = static_cast< SQChar >(std::tolower(*(str++)));
}
// Add the null terminator
buffer[i] = '\0';
// Compare the lowercase string and return the result
return (std::strcmp(buffer, "true") == 0 || std::strcmp(buffer, "yes") == 0 ||
std::strcmp(buffer, "on") == 0 || std::strcmp(buffer, "1") == 0) ? true : false;
}
// ------------------------------------------------------------------------------------------------
void SqThrowF(CSStr fmt, ...)
{
// Acquire a moderately sized buffer
Buffer b(128);
// Initialize the argument list
va_list args;
va_start (args, fmt);
// Attempt to run the specified format
if (b.WriteF(0, fmt, args) == 0)
{
// Attempt to write a generic message at least
b.At(b.WriteS(0, "Unknown error has occurred")) = '\0';
}
// Release the argument list
va_end(args);
// Throw the exception with the resulted message
throw Sqrat::Exception(b.Get< SQChar >());
}
// ------------------------------------------------------------------------------------------------
CSStr ToStrF(CSStr fmt, ...)
{
// Prepare the arguments list
va_list args;
va_start(args, fmt);
// Attempt to run the specified format
int ret = vsnprintf(g_Buffer, sizeof(g_Buffer), fmt, args);
// See if the format function failed
if (ret < 0)
{
STHROWF("Failed to run the specified string format");
}
// Finalized the arguments list
va_end(args);
// Return the resulted string
return g_Buffer;
}
// ------------------------------------------------------------------------------------------------
CSStr ToStringF(CSStr fmt, ...)
{
// Acquire a moderately sized buffer
Buffer b(128);
// Prepare the arguments list
va_list args;
va_start (args, fmt);
// Attempt to run the specified format
if (b.WriteF(0, fmt, args) == 0)
{
// Make sure the string is null terminated
b.At(0) = 0;
}
// Finalized the arguments list
va_end(args);
// Return the resulted string
return b.Get< SQChar >();
}
// ------------------------------------------------------------------------------------------------
const Color3 & GetRandomColor()
{
@ -1190,13 +1235,17 @@ bool ConvNum< bool >::FromStr(CSStr s, Int32 /*base*/)
void Register_Base(HSQUIRRELVM vm)
{
RootTable(vm)
.Func(_SC("EpsEq"), &EpsEq<SQFloat>)
.Func(_SC("EpsLt"), &EpsLt<SQFloat>)
.Func(_SC("EpsGt"), &EpsGt<SQFloat>)
.Func(_SC("EpsLtEq"), &EpsLtEq<SQFloat>)
.Func(_SC("EpsGtEq"), &EpsGtEq<SQFloat>)
.Func(_SC("ClampI"), &Clamp<SQInteger>)
.Func(_SC("ClampF"), &Clamp<SQFloat>)
.Func(_SC("EpsEq"), &EpsEq< SQFloat >)
.Func(_SC("EpsLt"), &EpsLt< SQFloat >)
.Func(_SC("EpsGt"), &EpsGt< SQFloat >)
.Func(_SC("EpsLtEq"), &EpsLtEq< SQFloat >)
.Func(_SC("EpsGtEq"), &EpsGtEq< SQFloat >)
.Func(_SC("ClampI"), &Clamp< SQInteger >)
.Func(_SC("ClampF"), &Clamp< SQFloat >)
.Func(_SC("ClampMinI"), &ClampMin< SQInteger >)
.Func(_SC("ClampMinF"), &ClampMin< SQFloat >)
.Func(_SC("ClampMaxI"), &ClampMax< SQInteger >)
.Func(_SC("ClampMaxF"), &ClampMax< SQFloat >)
.Func(_SC("NextPow2"), &NextPow2)
.Func(_SC("SToB"), &SToB)
.Func(_SC("GetColor"), &GetColor);

View File

@ -15,9 +15,6 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
extern const SQChar * g_EmptyStr;
/* ------------------------------------------------------------------------------------------------
* Proxies to communicate with the server.
*/
@ -25,6 +22,176 @@ extern PluginFuncs* _Func;
extern PluginCallbacks* _Clbk;
extern PluginInfo* _Info;
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Primary logging functions.
*/
extern void LogDbg(CCStr fmt, ...);
extern void LogUsr(CCStr fmt, ...);
extern void LogScs(CCStr fmt, ...);
extern void LogInf(CCStr fmt, ...);
extern void LogWrn(CCStr fmt, ...);
extern void LogErr(CCStr fmt, ...);
extern void LogFtl(CCStr fmt, ...);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Secondary logging functions.
*/
extern void LogSDbg(CCStr fmt, ...);
extern void LogSUsr(CCStr fmt, ...);
extern void LogSScs(CCStr fmt, ...);
extern void LogSInf(CCStr fmt, ...);
extern void LogSWrn(CCStr fmt, ...);
extern void LogSErr(CCStr fmt, ...);
extern void LogSFtl(CCStr fmt, ...);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Primary conditional logging functions.
*/
extern bool cLogDbg(bool exp, CCStr fmt, ...);
extern bool cLogUsr(bool exp, CCStr fmt, ...);
extern bool cLogScs(bool exp, CCStr fmt, ...);
extern bool cLogInf(bool exp, CCStr fmt, ...);
extern bool cLogWrn(bool exp, CCStr fmt, ...);
extern bool cLogErr(bool exp, CCStr fmt, ...);
extern bool cLogFtl(bool exp, CCStr fmt, ...);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Secondary conditional logging functions.
*/
extern bool cLogSDbg(bool exp, CCStr fmt, ...);
extern bool cLogSUsr(bool exp, CCStr fmt, ...);
extern bool cLogSScs(bool exp, CCStr fmt, ...);
extern bool cLogSInf(bool exp, CCStr fmt, ...);
extern bool cLogSWrn(bool exp, CCStr fmt, ...);
extern bool cLogSErr(bool exp, CCStr fmt, ...);
extern bool cLogSFtl(bool exp, CCStr fmt, ...);
/* ------------------------------------------------------------------------------------------------
* Output a message only if the _DEBUG was defined.
*/
extern void OutputDebug(const char * msg, ...);
/* ------------------------------------------------------------------------------------------------
* Output a formatted user message to the console.
*/
extern void OutputMessage(const char * msg, ...);
/* ------------------------------------------------------------------------------------------------
* Output a formatted error message to the console.
*/
extern void OutputError(const char * msg, ...);
/* ------------------------------------------------------------------------------------------------
* Get a persistent AABB instance with the given values.
*/
extern const AABB & GetAABB();
extern const AABB & GetAABB(Float32 sv);
extern const AABB & GetAABB(Float32 xv, Float32 yv, Float32 zv);
extern const AABB & GetAABB(Float32 xmin, Float32 ymin, Float32 zmin, Float32 xmax, Float32 ymax, Float32 zmax);
extern const AABB & GetAABB(const Vector3 & vmin, const Vector3 & vmax);
extern const AABB & GetAABB(const AABB & o);
extern const AABB & GetAABB(AABB && o);
/* ------------------------------------------------------------------------------------------------
* Get a persistent Circle instance with the given values.
*/
extern const Circle & GetCircle();
extern const Circle & GetCircle(Float32 rv);
extern const Circle & GetCircle(const Vector2 & pv, Float32 rv);
extern const Circle & GetCircle(Float32 xv, Float32 yv, Float32 rv);
extern const Circle & GetCircle(const Circle & o);
extern const Circle & GetCircle(Circle && o);
/* ------------------------------------------------------------------------------------------------
* Get a persistent Color3 instance with the given values.
*/
extern const Color3 & GetColor3();
extern const Color3 & GetColor3(Uint8 sv);
extern const Color3 & GetColor3(Uint8 rv, Uint8 gv, Uint8 bv);
extern const Color3 & GetColor3(const Color3 & o);
extern const Color3 & GetColor3(Color3 && o);
/* ------------------------------------------------------------------------------------------------
* Get a persistent Color4 instance with the given values.
*/
extern const Color4 & GetColor4();
extern const Color4 & GetColor4(Uint8 sv);
extern const Color4 & GetColor4(Uint8 rv, Uint8 gv, Uint8 bv);
extern const Color4 & GetColor4(Uint8 rv, Uint8 gv, Uint8 bv, Uint8 av);
extern const Color4 & GetColor4(const Color4 & o);
extern const Color4 & GetColor4(Color4 && o);
/* ------------------------------------------------------------------------------------------------
* Get a persistent Quaternion instance with the given values.
*/
extern const Quaternion & GetQuaternion();
extern const Quaternion & GetQuaternion(Float32 sv);
extern const Quaternion & GetQuaternion(Float32 xv, Float32 yv, Float32 zv);
extern const Quaternion & GetQuaternion(Float32 xv, Float32 yv, Float32 zv, Float32 wv);
extern const Quaternion & GetQuaternion(const Quaternion & o);
extern const Quaternion & GetQuaternion(Quaternion && o);
/* ------------------------------------------------------------------------------------------------
* Get a persistent Sphere instance with the given values.
*/
extern const Sphere & GetSphere();
extern const Sphere & GetSphere(Float32 rv);
extern const Sphere & GetSphere(const Vector3 & pv, Float32 rv);
extern const Sphere & GetSphere(Float32 xv, Float32 yv, Float32 zv, Float32 rv);
extern const Sphere & GetSphere(const Sphere & o);
extern const Sphere & GetSphere(Sphere && o);
/* ------------------------------------------------------------------------------------------------
* Get a persistent Vector2 instance with the given values.
*/
extern const Vector2 & GetVector2();
extern const Vector2 & GetVector2(Float32 sv);
extern const Vector2 & GetVector2(Float32 xv, Float32 yv);
extern const Vector2 & GetVector2(const Vector2 & o);
extern const Vector2 & GetVector2(Vector2 && o);
/* ------------------------------------------------------------------------------------------------
* Get a persistent Vector2i instance with the given values.
*/
extern const Vector2i & GetVector2i();
extern const Vector2i & GetVector2i(Int32 sv);
extern const Vector2i & GetVector2i(Int32 xv, Int32 yv);
extern const Vector2i & GetVector2i(const Vector2i & o);
extern const Vector2i & GetVector2i(Vector2i && o);
/* ------------------------------------------------------------------------------------------------
* Get a persistent Vector3 instance with the given values.
*/
extern const Vector3 & GetVector3();
extern const Vector3 & GetVector3(Float32 sv);
extern const Vector3 & GetVector3(Float32 xv, Float32 yv, Float32 zv);
extern const Vector3 & GetVector3(const Vector3 & o);
extern const Vector3 & GetVector3(Vector3 && o);
/* ------------------------------------------------------------------------------------------------
* Get a persistent Vector4 instance with the given values.
*/
extern const Vector4 & GetVector4();
extern const Vector4 & GetVector4(Float32 sv);
extern const Vector4 & GetVector4(Float32 xv, Float32 yv, Float32 zv);
extern const Vector4 & GetVector4(Float32 xv, Float32 yv, Float32 zv, Float32 wv);
extern const Vector4 & GetVector4(const Vector4 & o);
extern const Vector4 & GetVector4(Vector4 && o);
/* ------------------------------------------------------------------------------------------------
* Get a persistent LongInt instance with the given values.
*/
const SLongInt & GetSLongInt();
const SLongInt & GetSLongInt(Int64 n);
const SLongInt & GetSLongInt(CSStr s);
const ULongInt & GetULongInt();
const ULongInt & GetULongInt(Uint64 n);
const ULongInt & GetULongInt(CSStr s);
/* ------------------------------------------------------------------------------------------------
* Retrieve the maximum value of a fundamental type.
*/
@ -1000,6 +1167,34 @@ template< typename T > inline T Clamp(T val, T min, T max)
return val;
}
/* ------------------------------------------------------------------------------------------------
* Force a value to be higher then than the imposed limit.
*/
template< typename T > inline T ClampMin(T val, T min)
{
// Is the specified value bellow the minimum?
if (val < min)
{
return min;
}
// Return the value as is
return val;
}
/* ------------------------------------------------------------------------------------------------
* Force a value to be smaller then than the imposed limit.
*/
template< typename T > inline T ClampMax(T val, T max)
{
// Is the specified value above the maximum?
if (val > max)
{
return max;
}
// Return the value as is
return val;
}
/* ------------------------------------------------------------------------------------------------
* Force a value to be within a certain range.
*/
@ -1060,26 +1255,16 @@ inline Uint32 NextPow2(Uint32 num)
return ++num;
}
/* ------------------------------------------------------------------------------------------------
* Output a message only if the _DEBUG was defined.
*/
void OutputDebug(const char * msg, ...);
/* ------------------------------------------------------------------------------------------------
* Output a formatted user message to the console.
*/
void OutputMessage(const char * msg, ...);
/* ------------------------------------------------------------------------------------------------
* Output a formatted error message to the console.
*/
void OutputError(const char * msg, ...);
/* ------------------------------------------------------------------------------------------------
* Retrieve a reference to a null script object.
*/
Object & NullObject();
/* ------------------------------------------------------------------------------------------------
* Retrieve a reference to a null/empty script table.
*/
Table & NullTable();
/* ------------------------------------------------------------------------------------------------
* Retrieve a reference to a null/empty script array.
*/
@ -1120,54 +1305,6 @@ const Color3 & GetRandomColor();
*/
Color3 GetColor(CSStr name);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Primary logging functions.
*/
void LogDbg(CCStr fmt, ...);
void LogUsr(CCStr fmt, ...);
void LogScs(CCStr fmt, ...);
void LogInf(CCStr fmt, ...);
void LogWrn(CCStr fmt, ...);
void LogErr(CCStr fmt, ...);
void LogFtl(CCStr fmt, ...);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Secondary logging functions.
*/
void LogSDbg(CCStr fmt, ...);
void LogSUsr(CCStr fmt, ...);
void LogSScs(CCStr fmt, ...);
void LogSInf(CCStr fmt, ...);
void LogSWrn(CCStr fmt, ...);
void LogSErr(CCStr fmt, ...);
void LogSFtl(CCStr fmt, ...);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Primary conditional logging functions.
*/
bool cLogDbg(bool cond, CCStr fmt, ...);
bool cLogUsr(bool cond, CCStr fmt, ...);
bool cLogScs(bool cond, CCStr fmt, ...);
bool cLogInf(bool cond, CCStr fmt, ...);
bool cLogWrn(bool cond, CCStr fmt, ...);
bool cLogErr(bool cond, CCStr fmt, ...);
bool cLogFtl(bool cond, CCStr fmt, ...);
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Secondary conditional logging functions.
*/
bool cLogSDbg(bool cond, CCStr fmt, ...);
bool cLogSUsr(bool cond, CCStr fmt, ...);
bool cLogSScs(bool cond, CCStr fmt, ...);
bool cLogSInf(bool cond, CCStr fmt, ...);
bool cLogSWrn(bool cond, CCStr fmt, ...);
bool cLogSErr(bool cond, CCStr fmt, ...);
bool cLogSFtl(bool cond, CCStr fmt, ...);
/* ------------------------------------------------------------------------------------------------
* Helper class allows the use of functions with ctype style as predicate for algorithms.
*/
@ -1234,6 +1371,52 @@ public:
}
};
/* ------------------------------------------------------------------------------------------------
* Utility implementing RAII to toggle a bit mask on and off at all costs.
*/
template < typename T > struct BitGuard
{
private:
/* ------------------------------------------------------------------------------------------------
* The lock to be toggled.
*/
T & m_Lock;
/* ------------------------------------------------------------------------------------------------
* The mask to be applied.
*/
T m_Mask;
public:
/* ------------------------------------------------------------------------------------------------
* Base constructor.
*/
BitGuard(T & lock, T mask)
: m_Lock(lock), m_Mask(mask)
{
// Apply the specified mask
m_Lock |= m_Mask;
}
/* ------------------------------------------------------------------------------------------------
* Destructor.
*/
~BitGuard()
{
// In case one of the bits was turned off in the meantime
m_Lock |= m_Mask;
// Now turn off all the bits in the mask
m_Lock ^= m_Mask;
}
};
// ------------------------------------------------------------------------------------------------
typedef BitGuard< Uint8 > BitGuardU8;
typedef BitGuard< Uint16 > BitGuardU16;
typedef BitGuard< Uint32 > BitGuardU32;
} // Namespace:: SqMod
#endif // _BASE_SHARED_HPP_

View File

@ -20,7 +20,7 @@ SQChar Sphere::Delim = ',';
// ------------------------------------------------------------------------------------------------
SQInteger Sphere::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("Sphere");
static const SQChar name[] = _SC("Sphere");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
@ -98,7 +98,7 @@ Sphere & Sphere::operator /= (const Sphere & s)
Sphere & Sphere::operator %= (const Sphere & s)
{
pos %= s.pos;
rad = fmod(rad, s.rad);
rad = std::fmod(rad, s.rad);
return *this;
}
@ -130,7 +130,7 @@ Sphere & Sphere::operator /= (Value r)
Sphere & Sphere::operator %= (Value r)
{
rad = fmod(rad, r);
rad = std::fmod(rad, r);
return *this;
}
@ -220,7 +220,7 @@ Sphere Sphere::operator / (const Sphere & s) const
Sphere Sphere::operator % (const Sphere & s) const
{
return Sphere(pos % s.pos, fmod(rad, s.rad));
return Sphere(pos % s.pos, std::fmod(rad, s.rad));
}
// ------------------------------------------------------------------------------------------------
@ -246,7 +246,7 @@ Sphere Sphere::operator / (Value r) const
Sphere Sphere::operator % (Value r) const
{
return Sphere(fmod(rad, r));
return Sphere(std::fmod(rad, r));
}
// ------------------------------------------------------------------------------------------------
@ -278,7 +278,7 @@ Sphere Sphere::operator % (const Vector3 & p) const
// ------------------------------------------------------------------------------------------------
Sphere Sphere::operator + () const
{
return Sphere(pos.Abs(), fabs(rad));
return Sphere(pos.Abs(), std::fabs(rad));
}
Sphere Sphere::operator - () const
@ -321,11 +321,17 @@ bool Sphere::operator >= (const Sphere & s) const
Int32 Sphere::Cmp(const Sphere & o) const
{
if (*this == o)
{
return 0;
}
else if (*this > o)
{
return 1;
}
else
{
return -1;
}
}
// ------------------------------------------------------------------------------------------------
@ -372,7 +378,7 @@ void Sphere::Set(Value nx, Value ny, Value nz, Value nr)
// ------------------------------------------------------------------------------------------------
void Sphere::Set(CSStr values, SQChar delim)
{
Set(GetSphere(values, delim));
Set(Sphere::Get(values, delim));
}
// ------------------------------------------------------------------------------------------------
@ -385,17 +391,25 @@ void Sphere::Generate()
void Sphere::Generate(Value min, Value max, bool r)
{
if (EpsLt(max, min))
{
STHROWF("max value is lower than min value");
}
else if (r)
{
rad = GetRandomFloat32(min, max);
}
else
{
pos.Generate(min, max);
}
}
void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin))
{
STHROWF("max value is lower than min value");
}
pos.Generate(xmin, xmax, ymin, ymax, zmin, zmax);
}
@ -403,7 +417,9 @@ void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin
void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value rmin, Value rmax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin) || EpsLt(rmax, rmin))
{
STHROWF("max value is lower than min value");
}
pos.Generate(xmin, xmax, ymin, ymax, zmin, zmax);
rad = GetRandomFloat32(rmin, rmax);
@ -412,17 +428,17 @@ void Sphere::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin
// ------------------------------------------------------------------------------------------------
Sphere Sphere::Abs() const
{
return Sphere(pos.Abs(), fabs(rad));
return Sphere(pos.Abs(), std::fabs(rad));
}
// ------------------------------------------------------------------------------------------------
const Sphere & GetSphere(CSStr str)
const Sphere & Sphere::Get(CSStr str)
{
return GetSphere(str, Sphere::Delim);
return Sphere::Get(str, Sphere::Delim);
}
// ------------------------------------------------------------------------------------------------
const Sphere & GetSphere(CSStr str, SQChar delim)
const Sphere & Sphere::Get(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f , %f , %f ");
@ -439,104 +455,140 @@ const Sphere & GetSphere(CSStr str, SQChar delim)
fs[9] = delim;
fs[14] = delim;
// Attempt to extract the component values from the specified string
sscanf(str, fs, &sphere.pos.x, &sphere.pos.y, &sphere.pos.z, &sphere.rad);
std::sscanf(str, fs, &sphere.pos.x, &sphere.pos.y, &sphere.pos.z, &sphere.rad);
// Return the resulted value
return sphere;
}
// ------------------------------------------------------------------------------------------------
const Sphere & GetSphere()
{
static Sphere sphere;
sphere.Clear();
return sphere;
}
const Sphere & GetSphere(Float32 rv)
{
static Sphere sphere;
sphere.Set(rv);
return sphere;
}
const Sphere & GetSphere(const Vector3 & pv, Float32 rv)
{
static Sphere sphere;
sphere.Set(pv, rv);
return sphere;
}
const Sphere & GetSphere(Float32 xv, Float32 yv, Float32 zv, Float32 rv)
{
static Sphere sphere;
sphere.Set(xv, yv, zv, rv);
return sphere;
}
const Sphere & GetSphere(const Sphere & o)
{
static Sphere sphere;
sphere.Set(o);
return sphere;
}
// ================================================================================================
void Register_Sphere(HSQUIRRELVM vm)
{
typedef Sphere::Value Val;
RootTable(vm).Bind(_SC("Sphere"), Class< Sphere >(vm, _SC("Sphere"))
/* Constructors */
// Constructors
.Ctor()
.Ctor< Val >()
.Ctor< const Vector3 &, Val >()
.Ctor< Val, Val, Val, Val >()
/* Static Members */
// Static Members
.SetStaticValue(_SC("Delim"), &Sphere::Delim)
/* Member Variables */
.Var(_SC("pos"), &Sphere::pos)
.Var(_SC("rad"), &Sphere::rad)
/* Properties */
.Prop(_SC("abs"), &Sphere::Abs)
/* Core Metamethods */
// Member Variables
.Var(_SC("Pos"), &Sphere::pos)
.Var(_SC("Rad"), &Sphere::rad)
// Properties
.Prop(_SC("Abs"), &Sphere::Abs)
// Core Metamethods
.Func(_SC("_tostring"), &Sphere::ToString)
.SquirrelFunc(_SC("_typename"), &Sphere::Typename)
.Func(_SC("_cmp"), &Sphere::Cmp)
/* Metamethods */
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("_add"), &Sphere::operator +)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("_sub"), &Sphere::operator -)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("_mul"), &Sphere::operator *)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("_div"), &Sphere::operator /)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("_modulo"), &Sphere::operator %)
.Func<Sphere (Sphere::*)(void) const>(_SC("_unm"), &Sphere::operator -)
/* Setters */
.Overload<void (Sphere::*)(const Sphere &)>(_SC("Set"), &Sphere::Set)
.Overload<void (Sphere::*)(const Vector3 &, Val)>(_SC("Set"), &Sphere::Set)
.Overload<void (Sphere::*)(Val, Val, Val, Val)>(_SC("Set"), &Sphere::Set)
.Overload<void (Sphere::*)(Val)>(_SC("SetRad"), &Sphere::Set)
.Overload<void (Sphere::*)(const Vector3 &)>(_SC("SetVec3"), &Sphere::Set)
.Overload<void (Sphere::*)(Val, Val, Val)>(_SC("SetVec3"), &Sphere::Set)
.Overload<void (Sphere::*)(CSStr, SQChar)>(_SC("SetStr"), &Sphere::Set)
/* Utility Methods */
// Metamethods
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("_add"), &Sphere::operator +)
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("_sub"), &Sphere::operator -)
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("_mul"), &Sphere::operator *)
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("_div"), &Sphere::operator /)
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("_modulo"), &Sphere::operator %)
.Func< Sphere (Sphere::*)(void) const >(_SC("_unm"), &Sphere::operator -)
// Setters
.Overload< void (Sphere::*)(const Sphere &) >(_SC("Set"), &Sphere::Set)
.Overload< void (Sphere::*)(const Vector3 &, Val) >(_SC("Set"), &Sphere::Set)
.Overload< void (Sphere::*)(Val, Val, Val, Val) >(_SC("Set"), &Sphere::Set)
.Overload< void (Sphere::*)(Val) >(_SC("SetRad"), &Sphere::Set)
.Overload< void (Sphere::*)(const Vector3 &) >(_SC("SetVec3"), &Sphere::Set)
.Overload< void (Sphere::*)(Val, Val, Val) >(_SC("SetVec3"), &Sphere::Set)
.Overload< void (Sphere::*)(CSStr, SQChar) >(_SC("SetStr"), &Sphere::Set)
// Utility Methods
.Func(_SC("Clear"), &Sphere::Clear)
/* Operator Exposure */
.Func<Sphere & (Sphere::*)(const Sphere &)>(_SC("opAddAssign"), &Sphere::operator +=)
.Func<Sphere & (Sphere::*)(const Sphere &)>(_SC("opSubAssign"), &Sphere::operator -=)
.Func<Sphere & (Sphere::*)(const Sphere &)>(_SC("opMulAssign"), &Sphere::operator *=)
.Func<Sphere & (Sphere::*)(const Sphere &)>(_SC("opDivAssign"), &Sphere::operator /=)
.Func<Sphere & (Sphere::*)(const Sphere &)>(_SC("opModAssign"), &Sphere::operator %=)
.Func<Sphere & (Sphere::*)(Sphere::Value)>(_SC("opAddAssignR"), &Sphere::operator +=)
.Func<Sphere & (Sphere::*)(Sphere::Value)>(_SC("opSubAssignR"), &Sphere::operator -=)
.Func<Sphere & (Sphere::*)(Sphere::Value)>(_SC("opMulAssignR"), &Sphere::operator *=)
.Func<Sphere & (Sphere::*)(Sphere::Value)>(_SC("opDivAssignR"), &Sphere::operator /=)
.Func<Sphere & (Sphere::*)(Sphere::Value)>(_SC("opModAssignR"), &Sphere::operator %=)
.Func<Sphere & (Sphere::*)(const Vector3 &)>(_SC("opAddAssignP"), &Sphere::operator +=)
.Func<Sphere & (Sphere::*)(const Vector3 &)>(_SC("opSubAssignP"), &Sphere::operator -=)
.Func<Sphere & (Sphere::*)(const Vector3 &)>(_SC("opMulAssignP"), &Sphere::operator *=)
.Func<Sphere & (Sphere::*)(const Vector3 &)>(_SC("opDivAssignP"), &Sphere::operator /=)
.Func<Sphere & (Sphere::*)(const Vector3 &)>(_SC("opModAssignP"), &Sphere::operator %=)
.Func<Sphere & (Sphere::*)(void)>(_SC("opPreInc"), &Sphere::operator ++)
.Func<Sphere & (Sphere::*)(void)>(_SC("opPreDec"), &Sphere::operator --)
.Func<Sphere (Sphere::*)(int)>(_SC("opPostInc"), &Sphere::operator ++)
.Func<Sphere (Sphere::*)(int)>(_SC("opPostDec"), &Sphere::operator --)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("opAdd"), &Sphere::operator +)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("opSub"), &Sphere::operator -)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("opMul"), &Sphere::operator *)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("opDiv"), &Sphere::operator /)
.Func<Sphere (Sphere::*)(const Sphere &) const>(_SC("opMod"), &Sphere::operator %)
.Func<Sphere (Sphere::*)(Sphere::Value) const>(_SC("opAddR"), &Sphere::operator +)
.Func<Sphere (Sphere::*)(Sphere::Value) const>(_SC("opSubR"), &Sphere::operator -)
.Func<Sphere (Sphere::*)(Sphere::Value) const>(_SC("opMulR"), &Sphere::operator *)
.Func<Sphere (Sphere::*)(Sphere::Value) const>(_SC("opDivR"), &Sphere::operator /)
.Func<Sphere (Sphere::*)(Sphere::Value) const>(_SC("opModR"), &Sphere::operator %)
.Func<Sphere (Sphere::*)(const Vector3 &) const>(_SC("opAddP"), &Sphere::operator +)
.Func<Sphere (Sphere::*)(const Vector3 &) const>(_SC("opSubP"), &Sphere::operator -)
.Func<Sphere (Sphere::*)(const Vector3 &) const>(_SC("opMulP"), &Sphere::operator *)
.Func<Sphere (Sphere::*)(const Vector3 &) const>(_SC("opDivP"), &Sphere::operator /)
.Func<Sphere (Sphere::*)(const Vector3 &) const>(_SC("opModP"), &Sphere::operator %)
.Func<Sphere (Sphere::*)(void) const>(_SC("opUnPlus"), &Sphere::operator +)
.Func<Sphere (Sphere::*)(void) const>(_SC("opUnMinus"), &Sphere::operator -)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opEqual"), &Sphere::operator ==)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opNotEqual"), &Sphere::operator !=)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opLessThan"), &Sphere::operator <)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opGreaterThan"), &Sphere::operator >)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opLessEqual"), &Sphere::operator <=)
.Func<bool (Sphere::*)(const Sphere &) const>(_SC("opGreaterEqual"), &Sphere::operator >=)
// Static Overloads
.StaticOverload< const Sphere & (*)(CSStr) >(_SC("FromStr"), &GetSphere)
.StaticOverload< const Sphere & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetSphere)
.StaticOverload< const Sphere & (*)(CSStr) >(_SC("FromStr"), &Sphere::Get)
.StaticOverload< const Sphere & (*)(CSStr, SQChar) >(_SC("FromStr"), &Sphere::Get)
// Operator Exposure
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opAddAssign"), &Sphere::operator +=)
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opSubAssign"), &Sphere::operator -=)
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opMulAssign"), &Sphere::operator *=)
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opDivAssign"), &Sphere::operator /=)
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opModAssign"), &Sphere::operator %=)
.Func< Sphere & (Sphere::*)(Sphere::Value) >(_SC("opAddAssignR"), &Sphere::operator +=)
.Func< Sphere & (Sphere::*)(Sphere::Value) >(_SC("opSubAssignR"), &Sphere::operator -=)
.Func< Sphere & (Sphere::*)(Sphere::Value) >(_SC("opMulAssignR"), &Sphere::operator *=)
.Func< Sphere & (Sphere::*)(Sphere::Value) >(_SC("opDivAssignR"), &Sphere::operator /=)
.Func< Sphere & (Sphere::*)(Sphere::Value) >(_SC("opModAssignR"), &Sphere::operator %=)
.Func< Sphere & (Sphere::*)(const Vector3 &) >(_SC("opAddAssignP"), &Sphere::operator +=)
.Func< Sphere & (Sphere::*)(const Vector3 &) >(_SC("opSubAssignP"), &Sphere::operator -=)
.Func< Sphere & (Sphere::*)(const Vector3 &) >(_SC("opMulAssignP"), &Sphere::operator *=)
.Func< Sphere & (Sphere::*)(const Vector3 &) >(_SC("opDivAssignP"), &Sphere::operator /=)
.Func< Sphere & (Sphere::*)(const Vector3 &) >(_SC("opModAssignP"), &Sphere::operator %=)
.Func< Sphere & (Sphere::*)(void) >(_SC("opPreInc"), &Sphere::operator ++)
.Func< Sphere & (Sphere::*)(void) >(_SC("opPreDec"), &Sphere::operator --)
.Func< Sphere (Sphere::*)(int) >(_SC("opPostInc"), &Sphere::operator ++)
.Func< Sphere (Sphere::*)(int) >(_SC("opPostDec"), &Sphere::operator --)
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("opAdd"), &Sphere::operator +)
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("opSub"), &Sphere::operator -)
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("opMul"), &Sphere::operator *)
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("opDiv"), &Sphere::operator /)
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("opMod"), &Sphere::operator %)
.Func< Sphere (Sphere::*)(Sphere::Value) const >(_SC("opAddR"), &Sphere::operator +)
.Func< Sphere (Sphere::*)(Sphere::Value) const >(_SC("opSubR"), &Sphere::operator -)
.Func< Sphere (Sphere::*)(Sphere::Value) const >(_SC("opMulR"), &Sphere::operator *)
.Func< Sphere (Sphere::*)(Sphere::Value) const >(_SC("opDivR"), &Sphere::operator /)
.Func< Sphere (Sphere::*)(Sphere::Value) const >(_SC("opModR"), &Sphere::operator %)
.Func< Sphere (Sphere::*)(const Vector3 &) const >(_SC("opAddP"), &Sphere::operator +)
.Func< Sphere (Sphere::*)(const Vector3 &) const >(_SC("opSubP"), &Sphere::operator -)
.Func< Sphere (Sphere::*)(const Vector3 &) const >(_SC("opMulP"), &Sphere::operator *)
.Func< Sphere (Sphere::*)(const Vector3 &) const >(_SC("opDivP"), &Sphere::operator /)
.Func< Sphere (Sphere::*)(const Vector3 &) const >(_SC("opModP"), &Sphere::operator %)
.Func< Sphere (Sphere::*)(void) const >(_SC("opUnPlus"), &Sphere::operator +)
.Func< Sphere (Sphere::*)(void) const >(_SC("opUnMinus"), &Sphere::operator -)
.Func< bool (Sphere::*)(const Sphere &) const >(_SC("opEqual"), &Sphere::operator ==)
.Func< bool (Sphere::*)(const Sphere &) const >(_SC("opNotEqual"), &Sphere::operator !=)
.Func< bool (Sphere::*)(const Sphere &) const >(_SC("opLessThan"), &Sphere::operator <)
.Func< bool (Sphere::*)(const Sphere &) const >(_SC("opGreaterThan"), &Sphere::operator >)
.Func< bool (Sphere::*)(const Sphere &) const >(_SC("opLessEqual"), &Sphere::operator <=)
.Func< bool (Sphere::*)(const Sphere &) const >(_SC("opGreaterEqual"), &Sphere::operator >=)
);
}

View File

@ -8,16 +8,6 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Sphere type from a string.
*/
const Sphere & GetSphere(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Sphere type from a string.
*/
const Sphere & GetSphere(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent a three-dimensional sphere.
*/
@ -393,6 +383,17 @@ struct Sphere
* Retrieve a new instance of this type with absolute component values.
*/
Sphere Abs() const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Sphere type from a string.
*/
static const Sphere & Get(CSStr str);
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Sphere type from a string.
*/
static const Sphere & Get(CSStr str, SQChar delim);
};
} // Namespace:: SqMod

View File

@ -21,7 +21,7 @@ SQChar Vector2::Delim = ',';
// ------------------------------------------------------------------------------------------------
SQInteger Vector2::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("Vector2");
static const SQChar name[] = _SC("Vector2");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
@ -57,14 +57,14 @@ Vector2 & Vector2::operator = (Value s)
Vector2 & Vector2::operator = (CSStr values)
{
Set(GetVector2(values, Delim));
Set(Vector2::Get(values, Delim));
return *this;
}
Vector2 & Vector2::operator = (const Vector2i & v)
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
x = ConvTo< Value >::From(v.x);
y = ConvTo< Value >::From(v.y);
return *this;
}
@ -99,8 +99,8 @@ Vector2 & Vector2::operator /= (const Vector2 & v)
Vector2 & Vector2::operator %= (const Vector2 & v)
{
x = fmod(x, v.x);
y = fmod(y, v.y);
x = std::fmod(x, v.x);
y = std::fmod(y, v.y);
return *this;
}
@ -135,8 +135,8 @@ Vector2 & Vector2::operator /= (Value s)
Vector2 & Vector2::operator %= (Value s)
{
x = fmod(x, s);
y = fmod(y, s);
x = std::fmod(x, s);
y = std::fmod(y, s);
return *this;
}
@ -195,7 +195,7 @@ Vector2 Vector2::operator / (const Vector2 & v) const
Vector2 Vector2::operator % (const Vector2 & v) const
{
return Vector2(fmod(x, v.x), fmod(y, v.y));
return Vector2(std::fmod(x, v.x), std::fmod(y, v.y));
}
// ------------------------------------------------------------------------------------------------
@ -221,13 +221,13 @@ Vector2 Vector2::operator / (Value s) const
Vector2 Vector2::operator % (Value s) const
{
return Vector2(fmod(x, s), fmod(y, s));
return Vector2(std::fmod(x, s), std::fmod(y, s));
}
// ------------------------------------------------------------------------------------------------
Vector2 Vector2::operator + () const
{
return Vector2(fabs(x), fabs(y));
return Vector2(std::fabs(x), std::fabs(y));
}
Vector2 Vector2::operator - () const
@ -270,11 +270,17 @@ bool Vector2::operator >= (const Vector2 & v) const
Int32 Vector2::Cmp(const Vector2 & o) const
{
if (*this == o)
{
return 0;
}
else if (*this > o)
{
return 1;
}
else
{
return -1;
}
}
// ------------------------------------------------------------------------------------------------
@ -305,14 +311,14 @@ void Vector2::Set(const Vector2 & v)
void Vector2::Set(const Vector2i & v)
{
x = static_cast<Value>(v.x);
y = static_cast<Value>(v.y);
x = ConvTo< Value >::From(v.x);
y = ConvTo< Value >::From(v.y);
}
// ------------------------------------------------------------------------------------------------
void Vector2::Set(CSStr values, SQChar delim)
{
Set(GetVector2(values, delim));
Set(Vector2::Get(values, delim));
}
// ------------------------------------------------------------------------------------------------
@ -325,7 +331,9 @@ void Vector2::Generate()
void Vector2::Generate(Value min, Value max)
{
if (EpsLt(max, min))
{
STHROWF("max value is lower than min value");
}
x = GetRandomFloat32(min, max);
y = GetRandomFloat32(min, max);
@ -334,7 +342,9 @@ void Vector2::Generate(Value min, Value max)
void Vector2::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin))
{
STHROWF("max value is lower than min value");
}
x = GetRandomFloat32(ymin, ymax);
y = GetRandomFloat32(xmin, xmax);
@ -343,17 +353,17 @@ void Vector2::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
// ------------------------------------------------------------------------------------------------
Vector2 Vector2::Abs() const
{
return Vector2(fabs(x), fabs(y));
return Vector2(std::fabs(x), std::fabs(y));
}
// ------------------------------------------------------------------------------------------------
const Vector2 & GetVector2(CSStr str)
const Vector2 & Vector2::Get(CSStr str)
{
return GetVector2(str, Vector2::Delim);
return Vector2::Get(str, Vector2::Delim);
}
// ------------------------------------------------------------------------------------------------
const Vector2 & GetVector2(CSStr str, SQChar delim)
const Vector2 & Vector2::Get(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f ");
@ -368,93 +378,122 @@ const Vector2 & GetVector2(CSStr str, SQChar delim)
// Assign the specified delimiter
fs[4] = delim;
// Attempt to extract the component values from the specified string
sscanf(str, fs, &vec.x, &vec.y);
std::sscanf(str, fs, &vec.x, &vec.y);
// Return the resulted value
return vec;
}
// ------------------------------------------------------------------------------------------------
const Vector2 & GetVector2()
{
static Vector2 vec;
vec.Clear();
return vec;
}
const Vector2 & GetVector2(Float32 sv)
{
static Vector2 vec;
vec.Set(sv);
return vec;
}
const Vector2 & GetVector2(Float32 xv, Float32 yv)
{
static Vector2 vec;
vec.Set(xv, yv);
return vec;
}
const Vector2 & GetVector2(const Vector2 & o)
{
static Vector2 vec;
vec.Set(o);
return vec;
}
// ================================================================================================
void Register_Vector2(HSQUIRRELVM vm)
{
typedef Vector2::Value Val;
RootTable(vm).Bind(_SC("Vector2"), Class< Vector2 >(vm, _SC("Vector2"))
/* Constructors */
// Constructors
.Ctor()
.Ctor< Val >()
.Ctor< Val, Val >()
/* Static Members */
// Static Members
.SetStaticValue(_SC("Delim"), &Vector2::Delim)
/* Member Variables */
.Var(_SC("x"), &Vector2::x)
.Var(_SC("y"), &Vector2::y)
/* Properties */
.Prop(_SC("abs"), &Vector2::Abs)
/* Core Metamethods */
// Member Variables
.Var(_SC("X"), &Vector2::x)
.Var(_SC("Y"), &Vector2::y)
// Properties
.Prop(_SC("Abs"), &Vector2::Abs)
// Core Metamethods
.Func(_SC("_tostring"), &Vector2::ToString)
.SquirrelFunc(_SC("_typename"), &Vector2::Typename)
.Func(_SC("_cmp"), &Vector2::Cmp)
/* Metamethods */
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("_add"), &Vector2::operator +)
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("_sub"), &Vector2::operator -)
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("_mul"), &Vector2::operator *)
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("_div"), &Vector2::operator /)
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("_modulo"), &Vector2::operator %)
.Func<Vector2 (Vector2::*)(void) const>(_SC("_unm"), &Vector2::operator -)
/* Setters */
.Overload<void (Vector2::*)(Val)>(_SC("Set"), &Vector2::Set)
.Overload<void (Vector2::*)(Val, Val)>(_SC("Set"), &Vector2::Set)
.Overload<void (Vector2::*)(const Vector2 &)>(_SC("SetVec2"), &Vector2::Set)
.Overload<void (Vector2::*)(const Vector2i &)>(_SC("SetVec2i"), &Vector2::Set)
.Overload<void (Vector2::*)(CSStr, SQChar)>(_SC("SetStr"), &Vector2::Set)
/* Random Generators */
.Overload<void (Vector2::*)(void)>(_SC("Generate"), &Vector2::Generate)
.Overload<void (Vector2::*)(Val, Val)>(_SC("Generate"), &Vector2::Generate)
.Overload<void (Vector2::*)(Val, Val, Val, Val)>(_SC("Generate"), &Vector2::Generate)
/* Utility Methods */
// Metamethods
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_add"), &Vector2::operator +)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_sub"), &Vector2::operator -)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_mul"), &Vector2::operator *)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_div"), &Vector2::operator /)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_modulo"), &Vector2::operator %)
.Func< Vector2 (Vector2::*)(void) const >(_SC("_unm"), &Vector2::operator -)
// Setters
.Overload< void (Vector2::*)(Val) >(_SC("Set"), &Vector2::Set)
.Overload< void (Vector2::*)(Val, Val) >(_SC("Set"), &Vector2::Set)
.Overload< void (Vector2::*)(const Vector2 &) >(_SC("SetVec2"), &Vector2::Set)
.Overload< void (Vector2::*)(const Vector2i &) >(_SC("SetVec2i"), &Vector2::Set)
.Overload< void (Vector2::*)(CSStr, SQChar) >(_SC("SetStr"), &Vector2::Set)
// Random Generators
.Overload< void (Vector2::*)(void) >(_SC("Generate"), &Vector2::Generate)
.Overload< void (Vector2::*)(Val, Val) >(_SC("Generate"), &Vector2::Generate)
.Overload< void (Vector2::*)(Val, Val, Val, Val) >(_SC("Generate"), &Vector2::Generate)
// Utility Methods
.Func(_SC("Clear"), &Vector2::Clear)
/* Operator Exposure */
.Func<Vector2 & (Vector2::*)(const Vector2 &)>(_SC("opAddAssign"), &Vector2::operator +=)
.Func<Vector2 & (Vector2::*)(const Vector2 &)>(_SC("opSubAssign"), &Vector2::operator -=)
.Func<Vector2 & (Vector2::*)(const Vector2 &)>(_SC("opMulAssign"), &Vector2::operator *=)
.Func<Vector2 & (Vector2::*)(const Vector2 &)>(_SC("opDivAssign"), &Vector2::operator /=)
.Func<Vector2 & (Vector2::*)(const Vector2 &)>(_SC("opModAssign"), &Vector2::operator %=)
.Func<Vector2 & (Vector2::*)(Vector2::Value)>(_SC("opAddAssignS"), &Vector2::operator +=)
.Func<Vector2 & (Vector2::*)(Vector2::Value)>(_SC("opSubAssignS"), &Vector2::operator -=)
.Func<Vector2 & (Vector2::*)(Vector2::Value)>(_SC("opMulAssignS"), &Vector2::operator *=)
.Func<Vector2 & (Vector2::*)(Vector2::Value)>(_SC("opDivAssignS"), &Vector2::operator /=)
.Func<Vector2 & (Vector2::*)(Vector2::Value)>(_SC("opModAssignS"), &Vector2::operator %=)
.Func<Vector2 & (Vector2::*)(void)>(_SC("opPreInc"), &Vector2::operator ++)
.Func<Vector2 & (Vector2::*)(void)>(_SC("opPreDec"), &Vector2::operator --)
.Func<Vector2 (Vector2::*)(int)>(_SC("opPostInc"), &Vector2::operator ++)
.Func<Vector2 (Vector2::*)(int)>(_SC("opPostDec"), &Vector2::operator --)
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("opAdd"), &Vector2::operator +)
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("opSub"), &Vector2::operator -)
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("opMul"), &Vector2::operator *)
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("opDiv"), &Vector2::operator /)
.Func<Vector2 (Vector2::*)(const Vector2 &) const>(_SC("opMod"), &Vector2::operator %)
.Func<Vector2 (Vector2::*)(Vector2::Value) const>(_SC("opAddS"), &Vector2::operator +)
.Func<Vector2 (Vector2::*)(Vector2::Value) const>(_SC("opSubS"), &Vector2::operator -)
.Func<Vector2 (Vector2::*)(Vector2::Value) const>(_SC("opMulS"), &Vector2::operator *)
.Func<Vector2 (Vector2::*)(Vector2::Value) const>(_SC("opDivS"), &Vector2::operator /)
.Func<Vector2 (Vector2::*)(Vector2::Value) const>(_SC("opModS"), &Vector2::operator %)
.Func<Vector2 (Vector2::*)(void) const>(_SC("opUnPlus"), &Vector2::operator +)
.Func<Vector2 (Vector2::*)(void) const>(_SC("opUnMinus"), &Vector2::operator -)
.Func<bool (Vector2::*)(const Vector2 &) const>(_SC("opEqual"), &Vector2::operator ==)
.Func<bool (Vector2::*)(const Vector2 &) const>(_SC("opNotEqual"), &Vector2::operator !=)
.Func<bool (Vector2::*)(const Vector2 &) const>(_SC("opLessThan"), &Vector2::operator <)
.Func<bool (Vector2::*)(const Vector2 &) const>(_SC("opGreaterThan"), &Vector2::operator >)
.Func<bool (Vector2::*)(const Vector2 &) const>(_SC("opLessEqual"), &Vector2::operator <=)
.Func<bool (Vector2::*)(const Vector2 &) const>(_SC("opGreaterEqual"), &Vector2::operator >=)
// Static Overloads
.StaticOverload< const Vector2 & (*)(CSStr) >(_SC("FromStr"), &GetVector2)
.StaticOverload< const Vector2 & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetVector2)
.StaticOverload< const Vector2 & (*)(CSStr) >(_SC("FromStr"), &Vector2::Get)
.StaticOverload< const Vector2 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Vector2::Get)
// Operator Exposure
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opAddAssign"), &Vector2::operator +=)
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opSubAssign"), &Vector2::operator -=)
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opMulAssign"), &Vector2::operator *=)
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opDivAssign"), &Vector2::operator /=)
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opModAssign"), &Vector2::operator %=)
.Func< Vector2 & (Vector2::*)(Vector2::Value) >(_SC("opAddAssignS"), &Vector2::operator +=)
.Func< Vector2 & (Vector2::*)(Vector2::Value) >(_SC("opSubAssignS"), &Vector2::operator -=)
.Func< Vector2 & (Vector2::*)(Vector2::Value) >(_SC("opMulAssignS"), &Vector2::operator *=)
.Func< Vector2 & (Vector2::*)(Vector2::Value) >(_SC("opDivAssignS"), &Vector2::operator /=)
.Func< Vector2 & (Vector2::*)(Vector2::Value) >(_SC("opModAssignS"), &Vector2::operator %=)
.Func< Vector2 & (Vector2::*)(void) >(_SC("opPreInc"), &Vector2::operator ++)
.Func< Vector2 & (Vector2::*)(void) >(_SC("opPreDec"), &Vector2::operator --)
.Func< Vector2 (Vector2::*)(int) >(_SC("opPostInc"), &Vector2::operator ++)
.Func< Vector2 (Vector2::*)(int) >(_SC("opPostDec"), &Vector2::operator --)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("opAdd"), &Vector2::operator +)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("opSub"), &Vector2::operator -)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("opMul"), &Vector2::operator *)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("opDiv"), &Vector2::operator /)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("opMod"), &Vector2::operator %)
.Func< Vector2 (Vector2::*)(Vector2::Value) const >(_SC("opAddS"), &Vector2::operator +)
.Func< Vector2 (Vector2::*)(Vector2::Value) const >(_SC("opSubS"), &Vector2::operator -)
.Func< Vector2 (Vector2::*)(Vector2::Value) const >(_SC("opMulS"), &Vector2::operator *)
.Func< Vector2 (Vector2::*)(Vector2::Value) const >(_SC("opDivS"), &Vector2::operator /)
.Func< Vector2 (Vector2::*)(Vector2::Value) const >(_SC("opModS"), &Vector2::operator %)
.Func< Vector2 (Vector2::*)(void) const >(_SC("opUnPlus"), &Vector2::operator +)
.Func< Vector2 (Vector2::*)(void) const >(_SC("opUnMinus"), &Vector2::operator -)
.Func< bool (Vector2::*)(const Vector2 &) const >(_SC("opEqual"), &Vector2::operator ==)
.Func< bool (Vector2::*)(const Vector2 &) const >(_SC("opNotEqual"), &Vector2::operator !=)
.Func< bool (Vector2::*)(const Vector2 &) const >(_SC("opLessThan"), &Vector2::operator <)
.Func< bool (Vector2::*)(const Vector2 &) const >(_SC("opGreaterThan"), &Vector2::operator >)
.Func< bool (Vector2::*)(const Vector2 &) const >(_SC("opLessEqual"), &Vector2::operator <=)
.Func< bool (Vector2::*)(const Vector2 &) const >(_SC("opGreaterEqual"), &Vector2::operator >=)
);
}

View File

@ -7,16 +7,6 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2 type from a string.
*/
const Vector2 & GetVector2(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2 type from a string.
*/
const Vector2 & GetVector2(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent a two-dimensional vector.
*/
@ -326,6 +316,17 @@ struct Vector2
* Retrieve a new instance of this type with absolute component values.
*/
Vector2 Abs() const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2 type from a string.
*/
static const Vector2 & Get(CSStr str);
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2 type from a string.
*/
static const Vector2 & Get(CSStr str, SQChar delim);
};
} // Namespace:: SqMod

View File

@ -21,7 +21,7 @@ SQChar Vector2i::Delim = ',';
// ------------------------------------------------------------------------------------------------
SQInteger Vector2i::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("Vector2i");
static const SQChar name[] = _SC("Vector2i");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
@ -57,14 +57,14 @@ Vector2i & Vector2i::operator = (Value s)
Vector2i & Vector2i::operator = (CSStr values)
{
Set(GetVector2i(values, Delim));
Set(Vector2i::Get(values, Delim));
return *this;
}
Vector2i & Vector2i::operator = (const Vector2 & v)
{
x = Value(v.x);
y = Value(v.y);
x = ConvTo< Value >::From(v.x);
y = ConvTo< Value >::From(v.y);
return *this;
}
@ -347,7 +347,7 @@ Vector2i Vector2i::operator >> (Value s) const
// ------------------------------------------------------------------------------------------------
Vector2i Vector2i::operator + () const
{
return Vector2i(abs(x), abs(y));
return Vector2i(std::abs(x), std::abs(y));
}
Vector2i Vector2i::operator - () const
@ -396,11 +396,17 @@ bool Vector2i::operator >= (const Vector2i & v) const
Int32 Vector2i::Cmp(const Vector2i & o) const
{
if (*this == o)
{
return 0;
}
else if (*this > o)
{
return 1;
}
else
{
return -1;
}
}
// ------------------------------------------------------------------------------------------------
@ -431,14 +437,14 @@ void Vector2i::Set(const Vector2i & v)
void Vector2i::Set(const Vector2 & v)
{
x = Value(v.x);
y = Value(v.y);
x = ConvTo< Value >::From(v.x);
y = ConvTo< Value >::From(v.y);
}
// ------------------------------------------------------------------------------------------------
void Vector2i::Set(CSStr values, SQChar delim)
{
Set(GetVector2i(values, delim));
Set(Vector2i::Get(values, delim));
}
// ------------------------------------------------------------------------------------------------
@ -451,7 +457,9 @@ void Vector2i::Generate()
void Vector2i::Generate(Value min, Value max)
{
if (max < min)
{
STHROWF("max value is lower than min value");
}
x = GetRandomInt32(min, max);
y = GetRandomInt32(min, max);
@ -460,7 +468,9 @@ void Vector2i::Generate(Value min, Value max)
void Vector2i::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
{
if (xmax < xmin || ymax < ymin)
{
STHROWF("max value is lower than min value");
}
x = GetRandomInt32(ymin, ymax);
y = GetRandomInt32(xmin, xmax);
@ -469,17 +479,17 @@ void Vector2i::Generate(Value xmin, Value xmax, Value ymin, Value ymax)
// ------------------------------------------------------------------------------------------------
Vector2i Vector2i::Abs() const
{
return Vector2i(abs(x), abs(y));
return Vector2i(std::abs(x), std::abs(y));
}
// ------------------------------------------------------------------------------------------------
const Vector2i & GetVector2i(CSStr str)
const Vector2i & Vector2i::Get(CSStr str)
{
return GetVector2i(str, Vector2i::Delim);
return Vector2i::Get(str, Vector2i::Delim);
}
// ------------------------------------------------------------------------------------------------
const Vector2i & GetVector2i(CSStr str, SQChar delim)
const Vector2i & Vector2i::Get(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %d , %d ");
@ -494,114 +504,143 @@ const Vector2i & GetVector2i(CSStr str, SQChar delim)
// Assign the specified delimiter
fs[4] = delim;
// Attempt to extract the component values from the specified string
sscanf(str, &fs[0], &vec.x, &vec.y);
std::sscanf(str, &fs[0], &vec.x, &vec.y);
// Return the resulted value
return vec;
}
// ------------------------------------------------------------------------------------------------
const Vector2i & GetVector2i()
{
static Vector2i vec;
vec.Clear();
return vec;
}
const Vector2i & GetVector2i(Int32 sv)
{
static Vector2i vec;
vec.Set(sv);
return vec;
}
const Vector2i & GetVector2i(Int32 xv, Int32 yv)
{
static Vector2i vec;
vec.Set(xv, yv);
return vec;
}
const Vector2i & GetVector2i(const Vector2i & o)
{
static Vector2i vec;
vec.Set(o);
return vec;
}
// ================================================================================================
void Register_Vector2i(HSQUIRRELVM vm)
{
typedef Vector2i::Value Val;
RootTable(vm).Bind(_SC("Vector2i"), Class< Vector2i >(vm, _SC("Vector2i"))
/* Constructors */
// Constructors
.Ctor()
.Ctor< Val >()
.Ctor< Val, Val >()
/* Static Members */
// Static Members
.SetStaticValue(_SC("Delim"), &Vector2i::Delim)
/* Member Variables */
.Var(_SC("x"), &Vector2i::x)
.Var(_SC("y"), &Vector2i::y)
/* Properties */
.Prop(_SC("abs"), &Vector2i::Abs)
/* Core Metamethods */
// Member Variables
.Var(_SC("X"), &Vector2i::x)
.Var(_SC("Y"), &Vector2i::y)
// Properties
.Prop(_SC("Abs"), &Vector2i::Abs)
// Core Metamethods
.Func(_SC("_tostring"), &Vector2i::ToString)
.SquirrelFunc(_SC("_typename"), &Vector2i::Typename)
.Func(_SC("_cmp"), &Vector2i::Cmp)
/* Metamethods */
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("_add"), &Vector2i::operator +)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("_sub"), &Vector2i::operator -)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("_mul"), &Vector2i::operator *)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("_div"), &Vector2i::operator /)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("_modulo"), &Vector2i::operator %)
.Func<Vector2i (Vector2i::*)(void) const>(_SC("_unm"), &Vector2i::operator -)
/* Setters */
.Overload<void (Vector2i::*)(Val)>(_SC("Set"), &Vector2i::Set)
.Overload<void (Vector2i::*)(Val, Val)>(_SC("Set"), &Vector2i::Set)
.Overload<void (Vector2i::*)(const Vector2i &)>(_SC("SetVec2i"), &Vector2i::Set)
.Overload<void (Vector2i::*)(const Vector2 &)>(_SC("SetVec2"), &Vector2i::Set)
.Overload<void (Vector2i::*)(CSStr, SQChar)>(_SC("SetStr"), &Vector2i::Set)
/* Random Generators */
.Overload<void (Vector2i::*)(void)>(_SC("Generate"), &Vector2i::Generate)
.Overload<void (Vector2i::*)(Val, Val)>(_SC("Generate"), &Vector2i::Generate)
.Overload<void (Vector2i::*)(Val, Val, Val, Val)>(_SC("Generate"), &Vector2i::Generate)
/* Utility Methods */
// Metamethods
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("_add"), &Vector2i::operator +)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("_sub"), &Vector2i::operator -)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("_mul"), &Vector2i::operator *)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("_div"), &Vector2i::operator /)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("_modulo"), &Vector2i::operator %)
.Func< Vector2i (Vector2i::*)(void) const >(_SC("_unm"), &Vector2i::operator -)
// Setters
.Overload< void (Vector2i::*)(Val) >(_SC("Set"), &Vector2i::Set)
.Overload< void (Vector2i::*)(Val, Val) >(_SC("Set"), &Vector2i::Set)
.Overload< void (Vector2i::*)(const Vector2i &) >(_SC("SetVec2i"), &Vector2i::Set)
.Overload< void (Vector2i::*)(const Vector2 &) >(_SC("SetVec2"), &Vector2i::Set)
.Overload< void (Vector2i::*)(CSStr, SQChar) >(_SC("SetStr"), &Vector2i::Set)
// Random Generators
.Overload< void (Vector2i::*)(void) >(_SC("Generate"), &Vector2i::Generate)
.Overload< void (Vector2i::*)(Val, Val) >(_SC("Generate"), &Vector2i::Generate)
.Overload< void (Vector2i::*)(Val, Val, Val, Val) >(_SC("Generate"), &Vector2i::Generate)
// Utility Methods
.Func(_SC("Clear"), &Vector2i::Clear)
/* Operator Exposure */
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opAddAssign"), &Vector2i::operator +=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opSubAssign"), &Vector2i::operator -=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opMulAssign"), &Vector2i::operator *=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opDivAssign"), &Vector2i::operator /=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opModAssign"), &Vector2i::operator %=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opAndAssign"), &Vector2i::operator &=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opOrAssign"), &Vector2i::operator |=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opXorAssign"), &Vector2i::operator ^=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opShlAssign"), &Vector2i::operator <<=)
.Func<Vector2i & (Vector2i::*)(const Vector2i &)>(_SC("opShrAssign"), &Vector2i::operator >>=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opAddAssignS"), &Vector2i::operator +=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opSubAssignS"), &Vector2i::operator -=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opMulAssignS"), &Vector2i::operator *=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opDivAssignS"), &Vector2i::operator /=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opModAssignS"), &Vector2i::operator %=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opAndAssignS"), &Vector2i::operator &=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opOrAssignS"), &Vector2i::operator |=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opXorAssignS"), &Vector2i::operator ^=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opShlAssignS"), &Vector2i::operator <<=)
.Func<Vector2i & (Vector2i::*)(Vector2i::Value)>(_SC("opShrAssignS"), &Vector2i::operator >>=)
.Func<Vector2i & (Vector2i::*)(void)>(_SC("opPreInc"), &Vector2i::operator ++)
.Func<Vector2i & (Vector2i::*)(void)>(_SC("opPreDec"), &Vector2i::operator --)
.Func<Vector2i (Vector2i::*)(int)>(_SC("opPostInc"), &Vector2i::operator ++)
.Func<Vector2i (Vector2i::*)(int)>(_SC("opPostDec"), &Vector2i::operator --)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opAdd"), &Vector2i::operator +)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opSub"), &Vector2i::operator -)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opMul"), &Vector2i::operator *)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opDiv"), &Vector2i::operator /)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opMod"), &Vector2i::operator %)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opAnd"), &Vector2i::operator &)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opOr"), &Vector2i::operator |)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opShl"), &Vector2i::operator ^)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opShl"), &Vector2i::operator <<)
.Func<Vector2i (Vector2i::*)(const Vector2i &) const>(_SC("opShr"), &Vector2i::operator >>)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opAddS"), &Vector2i::operator +)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opSubS"), &Vector2i::operator -)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opMulS"), &Vector2i::operator *)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opDivS"), &Vector2i::operator /)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opModS"), &Vector2i::operator %)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opAndS"), &Vector2i::operator &)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opOrS"), &Vector2i::operator |)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opShlS"), &Vector2i::operator ^)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opShlS"), &Vector2i::operator <<)
.Func<Vector2i (Vector2i::*)(Vector2i::Value) const>(_SC("opShrS"), &Vector2i::operator >>)
.Func<Vector2i (Vector2i::*)(void) const>(_SC("opUnPlus"), &Vector2i::operator +)
.Func<Vector2i (Vector2i::*)(void) const>(_SC("opUnMinus"), &Vector2i::operator -)
.Func<Vector2i (Vector2i::*)(void) const>(_SC("opCom"), &Vector2i::operator ~)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opEqual"), &Vector2i::operator ==)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opNotEqual"), &Vector2i::operator !=)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opLessThan"), &Vector2i::operator <)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opGreaterThan"), &Vector2i::operator >)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opLessEqual"), &Vector2i::operator <=)
.Func<bool (Vector2i::*)(const Vector2i &) const>(_SC("opGreaterEqual"), &Vector2i::operator >=)
// Static Overloads
.StaticOverload< const Vector2i & (*)(CSStr) >(_SC("FromStr"), &GetVector2i)
.StaticOverload< const Vector2i & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetVector2i)
.StaticOverload< const Vector2i & (*)(CSStr) >(_SC("FromStr"), &Vector2i::Get)
.StaticOverload< const Vector2i & (*)(CSStr, SQChar) >(_SC("FromStr"), &Vector2i::Get)
// Operator Exposure
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opAddAssign"), &Vector2i::operator +=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opSubAssign"), &Vector2i::operator -=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opMulAssign"), &Vector2i::operator *=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opDivAssign"), &Vector2i::operator /=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opModAssign"), &Vector2i::operator %=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opAndAssign"), &Vector2i::operator &=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opOrAssign"), &Vector2i::operator |=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opXorAssign"), &Vector2i::operator ^=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opShlAssign"), &Vector2i::operator <<=)
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opShrAssign"), &Vector2i::operator >>=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opAddAssignS"), &Vector2i::operator +=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opSubAssignS"), &Vector2i::operator -=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opMulAssignS"), &Vector2i::operator *=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opDivAssignS"), &Vector2i::operator /=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opModAssignS"), &Vector2i::operator %=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opAndAssignS"), &Vector2i::operator &=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opOrAssignS"), &Vector2i::operator |=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opXorAssignS"), &Vector2i::operator ^=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opShlAssignS"), &Vector2i::operator <<=)
.Func< Vector2i & (Vector2i::*)(Vector2i::Value) >(_SC("opShrAssignS"), &Vector2i::operator >>=)
.Func< Vector2i & (Vector2i::*)(void) >(_SC("opPreInc"), &Vector2i::operator ++)
.Func< Vector2i & (Vector2i::*)(void) >(_SC("opPreDec"), &Vector2i::operator --)
.Func< Vector2i (Vector2i::*)(int) >(_SC("opPostInc"), &Vector2i::operator ++)
.Func< Vector2i (Vector2i::*)(int) >(_SC("opPostDec"), &Vector2i::operator --)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opAdd"), &Vector2i::operator +)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opSub"), &Vector2i::operator -)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opMul"), &Vector2i::operator *)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opDiv"), &Vector2i::operator /)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opMod"), &Vector2i::operator %)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opAnd"), &Vector2i::operator &)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opOr"), &Vector2i::operator |)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opShl"), &Vector2i::operator ^)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opShl"), &Vector2i::operator <<)
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("opShr"), &Vector2i::operator >>)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opAddS"), &Vector2i::operator +)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opSubS"), &Vector2i::operator -)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opMulS"), &Vector2i::operator *)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opDivS"), &Vector2i::operator /)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opModS"), &Vector2i::operator %)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opAndS"), &Vector2i::operator &)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opOrS"), &Vector2i::operator |)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opShlS"), &Vector2i::operator ^)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opShlS"), &Vector2i::operator <<)
.Func< Vector2i (Vector2i::*)(Vector2i::Value) const >(_SC("opShrS"), &Vector2i::operator >>)
.Func< Vector2i (Vector2i::*)(void) const >(_SC("opUnPlus"), &Vector2i::operator +)
.Func< Vector2i (Vector2i::*)(void) const >(_SC("opUnMinus"), &Vector2i::operator -)
.Func< Vector2i (Vector2i::*)(void) const >(_SC("opCom"), &Vector2i::operator ~)
.Func< bool (Vector2i::*)(const Vector2i &) const >(_SC("opEqual"), &Vector2i::operator ==)
.Func< bool (Vector2i::*)(const Vector2i &) const >(_SC("opNotEqual"), &Vector2i::operator !=)
.Func< bool (Vector2i::*)(const Vector2i &) const >(_SC("opLessThan"), &Vector2i::operator <)
.Func< bool (Vector2i::*)(const Vector2i &) const >(_SC("opGreaterThan"), &Vector2i::operator >)
.Func< bool (Vector2i::*)(const Vector2i &) const >(_SC("opLessEqual"), &Vector2i::operator <=)
.Func< bool (Vector2i::*)(const Vector2i &) const >(_SC("opGreaterEqual"), &Vector2i::operator >=)
);
}

View File

@ -7,16 +7,6 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2i type from a string.
*/
const Vector2i & GetVector2i(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2i type from a string.
*/
const Vector2i & GetVector2i(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent a two-dimensional vector using integral values.
*/
@ -431,6 +421,17 @@ struct Vector2i
* Retrieve a new instance of this type with absolute component values.
*/
Vector2i Abs() const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2i type from a string.
*/
static const Vector2i & Get(CSStr str);
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector2i type from a string.
*/
static const Vector2i & Get(CSStr str, SQChar delim);
};
} // Namespace:: SqMod

View File

@ -22,7 +22,7 @@ SQChar Vector3::Delim = ',';
// ------------------------------------------------------------------------------------------------
SQInteger Vector3::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("Vector3");
static const SQChar name[] = _SC("Vector3");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
@ -108,9 +108,9 @@ Vector3 & Vector3::operator /= (const Vector3 & v)
Vector3 & Vector3::operator %= (const Vector3 & v)
{
x = fmod(x, v.x);
y = fmod(y, v.y);
z = fmod(z, v.z);
x = std::fmod(x, v.x);
y = std::fmod(y, v.y);
z = std::fmod(z, v.z);
return *this;
}
@ -149,9 +149,9 @@ Vector3 & Vector3::operator /= (Value s)
Vector3 & Vector3::operator %= (Value s)
{
x = fmod(x, s);
y = fmod(y, s);
z = fmod(z, s);
x = std::fmod(x, s);
y = std::fmod(y, s);
z = std::fmod(z, s);
return *this;
}
@ -214,7 +214,7 @@ Vector3 Vector3::operator / (const Vector3 & v) const
Vector3 Vector3::operator % (const Vector3 & v) const
{
return Vector3(fmod(x, v.x), fmod(y, v.y), fmod(z, v.z));
return Vector3(std::fmod(x, v.x), std::fmod(y, v.y), std::fmod(z, v.z));
}
// ------------------------------------------------------------------------------------------------
@ -240,13 +240,13 @@ Vector3 Vector3::operator / (Value s) const
Vector3 Vector3::operator % (Value s) const
{
return Vector3(fmod(x, s), fmod(y, s), fmod(z, s));
return Vector3(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s));
}
// ------------------------------------------------------------------------------------------------
Vector3 Vector3::operator + () const
{
return Vector3(fabs(x), fabs(y), fabs(z));
return Vector3(std::fabs(x), std::fabs(y), std::fabs(z));
}
Vector3 Vector3::operator - () const
@ -289,11 +289,17 @@ bool Vector3::operator >= (const Vector3 & v) const
Int32 Vector3::Cmp(const Vector3 & o) const
{
if (*this == o)
{
return 0;
}
else if (*this > o)
{
return 1;
}
else
{
return -1;
}
}
// ------------------------------------------------------------------------------------------------
@ -342,7 +348,7 @@ void Vector3::Set(const Quaternion & q)
// ------------------------------------------------------------------------------------------------
void Vector3::Set(CSStr values, SQChar delim)
{
Set(GetVector3(values, delim));
Set(Vector3::Get(values, delim));
}
// ------------------------------------------------------------------------------------------------
@ -356,7 +362,9 @@ void Vector3::Generate()
void Vector3::Generate(Value min, Value max)
{
if (EpsLt(max, min))
{
STHROWF("max value is lower than min value");
}
x = GetRandomFloat32(min, max);
y = GetRandomFloat32(min, max);
@ -366,7 +374,9 @@ void Vector3::Generate(Value min, Value max)
void Vector3::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin))
{
STHROWF("max value is lower than min value");
}
x = GetRandomFloat32(xmin, xmax);
y = GetRandomFloat32(ymin, ymax);
@ -376,17 +386,17 @@ void Vector3::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmi
// ------------------------------------------------------------------------------------------------
Vector3 Vector3::Abs() const
{
return Vector3(fabs(x), fabs(y), fabs(z));
return Vector3(std::fabs(x), std::fabs(y), std::fabs(z));
}
// ------------------------------------------------------------------------------------------------
const Vector3 & GetVector3(CSStr str)
const Vector3 & Vector3::Get(CSStr str)
{
return GetVector3(str, Vector3::Delim);
return Vector3::Get(str, Vector3::Delim);
}
// ------------------------------------------------------------------------------------------------
const Vector3 & GetVector3(CSStr str, SQChar delim)
const Vector3 & Vector3::Get(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f , %f ");
@ -402,95 +412,124 @@ const Vector3 & GetVector3(CSStr str, SQChar delim)
fs[4] = delim;
fs[9] = delim;
// Attempt to extract the component values from the specified string
sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z);
std::sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z);
// Return the resulted value
return vec;
}
// ------------------------------------------------------------------------------------------------
const Vector3 & GetVector3()
{
static Vector3 vec;
vec.Clear();
return vec;
}
const Vector3 & GetVector3(Float32 sv)
{
static Vector3 vec;
vec.Set(sv);
return vec;
}
const Vector3 & GetVector3(Float32 xv, Float32 yv, Float32 zv)
{
static Vector3 vec;
vec.Set(xv, yv, zv);
return vec;
}
const Vector3 & GetVector3(const Vector3 & o)
{
static Vector3 vec;
vec.Set(o);
return vec;
}
// ================================================================================================
void Register_Vector3(HSQUIRRELVM vm)
{
typedef Vector3::Value Val;
RootTable(vm).Bind(_SC("Vector3"), Class< Vector3 >(vm, _SC("Vector3"))
/* Constructors */
// Constructors
.Ctor()
.Ctor< Val >()
.Ctor< Val, Val, Val >()
/* Static Members */
// Static Members
.SetStaticValue(_SC("Delim"), &Vector3::Delim)
/* Member Variables */
.Var(_SC("x"), &Vector3::x)
.Var(_SC("y"), &Vector3::y)
.Var(_SC("z"), &Vector3::z)
/* Properties */
.Prop(_SC("abs"), &Vector3::Abs)
/* Core Metamethods */
// Member Variables
.Var(_SC("X"), &Vector3::x)
.Var(_SC("Y"), &Vector3::y)
.Var(_SC("Z"), &Vector3::z)
// Properties
.Prop(_SC("Abs"), &Vector3::Abs)
// Core Metamethods
.Func(_SC("_tostring"), &Vector3::ToString)
.SquirrelFunc(_SC("_typename"), &Vector3::Typename)
.Func(_SC("_cmp"), &Vector3::Cmp)
/* Metamethods */
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_add"), &Vector3::operator +)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_sub"), &Vector3::operator -)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_mul"), &Vector3::operator *)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_div"), &Vector3::operator /)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("_modulo"), &Vector3::operator %)
.Func<Vector3 (Vector3::*)(void) const>(_SC("_unm"), &Vector3::operator -)
/* Setters */
.Overload<void (Vector3::*)(Val)>(_SC("Set"), &Vector3::Set)
.Overload<void (Vector3::*)(Val, Val, Val)>(_SC("Set"), &Vector3::Set)
.Overload<void (Vector3::*)(const Vector3 &)>(_SC("SetVec3"), &Vector3::Set)
.Overload<void (Vector3::*)(const Vector4 &)>(_SC("SetVec4"), &Vector3::Set)
.Overload<void (Vector3::*)(const Quaternion &)>(_SC("SetQuat"), &Vector3::Set)
.Overload<void (Vector3::*)(CSStr, SQChar)>(_SC("SetStr"), &Vector3::Set)
/* Random Generators */
.Overload<void (Vector3::*)(void)>(_SC("Generate"), &Vector3::Generate)
.Overload<void (Vector3::*)(Val, Val)>(_SC("Generate"), &Vector3::Generate)
.Overload<void (Vector3::*)(Val, Val, Val, Val, Val, Val)>(_SC("Generate"), &Vector3::Generate)
/* Utility Methods */
// Metamethods
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_add"), &Vector3::operator +)
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_sub"), &Vector3::operator -)
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_mul"), &Vector3::operator *)
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_div"), &Vector3::operator /)
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_modulo"), &Vector3::operator %)
.Func< Vector3 (Vector3::*)(void) const >(_SC("_unm"), &Vector3::operator -)
// Setters
.Overload< void (Vector3::*)(Val) >(_SC("Set"), &Vector3::Set)
.Overload< void (Vector3::*)(Val, Val, Val) >(_SC("Set"), &Vector3::Set)
.Overload< void (Vector3::*)(const Vector3 &) >(_SC("SetVec3"), &Vector3::Set)
.Overload< void (Vector3::*)(const Vector4 &) >(_SC("SetVec4"), &Vector3::Set)
.Overload< void (Vector3::*)(const Quaternion &) >(_SC("SetQuat"), &Vector3::Set)
.Overload< void (Vector3::*)(CSStr, SQChar) >(_SC("SetStr"), &Vector3::Set)
// Random Generators
.Overload< void (Vector3::*)(void) >(_SC("Generate"), &Vector3::Generate)
.Overload< void (Vector3::*)(Val, Val) >(_SC("Generate"), &Vector3::Generate)
.Overload< void (Vector3::*)(Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Vector3::Generate)
// Utility Methods
.Func(_SC("Clear"), &Vector3::Clear)
/* Operator Exposure */
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opAddAssign"), &Vector3::operator +=)
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opSubAssign"), &Vector3::operator -=)
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opMulAssign"), &Vector3::operator *=)
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opDivAssign"), &Vector3::operator /=)
.Func<Vector3 & (Vector3::*)(const Vector3 &)>(_SC("opModAssign"), &Vector3::operator %=)
.Func<Vector3 & (Vector3::*)(Vector3::Value)>(_SC("opAddAssignS"), &Vector3::operator +=)
.Func<Vector3 & (Vector3::*)(Vector3::Value)>(_SC("opSubAssignS"), &Vector3::operator -=)
.Func<Vector3 & (Vector3::*)(Vector3::Value)>(_SC("opMulAssignS"), &Vector3::operator *=)
.Func<Vector3 & (Vector3::*)(Vector3::Value)>(_SC("opDivAssignS"), &Vector3::operator /=)
.Func<Vector3 & (Vector3::*)(Vector3::Value)>(_SC("opModAssignS"), &Vector3::operator %=)
.Func<Vector3 & (Vector3::*)(void)>(_SC("opPreInc"), &Vector3::operator ++)
.Func<Vector3 & (Vector3::*)(void)>(_SC("opPreDec"), &Vector3::operator --)
.Func<Vector3 (Vector3::*)(int)>(_SC("opPostInc"), &Vector3::operator ++)
.Func<Vector3 (Vector3::*)(int)>(_SC("opPostDec"), &Vector3::operator --)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("opAdd"), &Vector3::operator +)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("opSub"), &Vector3::operator -)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("opMul"), &Vector3::operator *)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("opDiv"), &Vector3::operator /)
.Func<Vector3 (Vector3::*)(const Vector3 &) const>(_SC("opMod"), &Vector3::operator %)
.Func<Vector3 (Vector3::*)(Vector3::Value) const>(_SC("opAddS"), &Vector3::operator +)
.Func<Vector3 (Vector3::*)(Vector3::Value) const>(_SC("opSubS"), &Vector3::operator -)
.Func<Vector3 (Vector3::*)(Vector3::Value) const>(_SC("opMulS"), &Vector3::operator *)
.Func<Vector3 (Vector3::*)(Vector3::Value) const>(_SC("opDivS"), &Vector3::operator /)
.Func<Vector3 (Vector3::*)(Vector3::Value) const>(_SC("opModS"), &Vector3::operator %)
.Func<Vector3 (Vector3::*)(void) const>(_SC("opUnPlus"), &Vector3::operator +)
.Func<Vector3 (Vector3::*)(void) const>(_SC("opUnMinus"), &Vector3::operator -)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opEqual"), &Vector3::operator ==)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opNotEqual"), &Vector3::operator !=)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opLessThan"), &Vector3::operator <)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opGreaterThan"), &Vector3::operator >)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opLessEqual"), &Vector3::operator <=)
.Func<bool (Vector3::*)(const Vector3 &) const>(_SC("opGreaterEqual"), &Vector3::operator >=)
// Static Overloads
.StaticOverload< const Vector3 & (*)(CSStr) >(_SC("FromStr"), &GetVector3)
.StaticOverload< const Vector3 & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetVector3)
.StaticOverload< const Vector3 & (*)(CSStr) >(_SC("FromStr"), &Vector3::Get)
.StaticOverload< const Vector3 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Vector3::Get)
// Operator Exposure
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opAddAssign"), &Vector3::operator +=)
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opSubAssign"), &Vector3::operator -=)
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opMulAssign"), &Vector3::operator *=)
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opDivAssign"), &Vector3::operator /=)
.Func< Vector3 & (Vector3::*)(const Vector3 &) >(_SC("opModAssign"), &Vector3::operator %=)
.Func< Vector3 & (Vector3::*)(Vector3::Value) >(_SC("opAddAssignS"), &Vector3::operator +=)
.Func< Vector3 & (Vector3::*)(Vector3::Value) >(_SC("opSubAssignS"), &Vector3::operator -=)
.Func< Vector3 & (Vector3::*)(Vector3::Value) >(_SC("opMulAssignS"), &Vector3::operator *=)
.Func< Vector3 & (Vector3::*)(Vector3::Value) >(_SC("opDivAssignS"), &Vector3::operator /=)
.Func< Vector3 & (Vector3::*)(Vector3::Value) >(_SC("opModAssignS"), &Vector3::operator %=)
.Func< Vector3 & (Vector3::*)(void) >(_SC("opPreInc"), &Vector3::operator ++)
.Func< Vector3 & (Vector3::*)(void) >(_SC("opPreDec"), &Vector3::operator --)
.Func< Vector3 (Vector3::*)(int) >(_SC("opPostInc"), &Vector3::operator ++)
.Func< Vector3 (Vector3::*)(int) >(_SC("opPostDec"), &Vector3::operator --)
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("opAdd"), &Vector3::operator +)
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("opSub"), &Vector3::operator -)
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("opMul"), &Vector3::operator *)
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("opDiv"), &Vector3::operator /)
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("opMod"), &Vector3::operator %)
.Func< Vector3 (Vector3::*)(Vector3::Value) const >(_SC("opAddS"), &Vector3::operator +)
.Func< Vector3 (Vector3::*)(Vector3::Value) const >(_SC("opSubS"), &Vector3::operator -)
.Func< Vector3 (Vector3::*)(Vector3::Value) const >(_SC("opMulS"), &Vector3::operator *)
.Func< Vector3 (Vector3::*)(Vector3::Value) const >(_SC("opDivS"), &Vector3::operator /)
.Func< Vector3 (Vector3::*)(Vector3::Value) const >(_SC("opModS"), &Vector3::operator %)
.Func< Vector3 (Vector3::*)(void) const >(_SC("opUnPlus"), &Vector3::operator +)
.Func< Vector3 (Vector3::*)(void) const >(_SC("opUnMinus"), &Vector3::operator -)
.Func< bool (Vector3::*)(const Vector3 &) const >(_SC("opEqual"), &Vector3::operator ==)
.Func< bool (Vector3::*)(const Vector3 &) const >(_SC("opNotEqual"), &Vector3::operator !=)
.Func< bool (Vector3::*)(const Vector3 &) const >(_SC("opLessThan"), &Vector3::operator <)
.Func< bool (Vector3::*)(const Vector3 &) const >(_SC("opGreaterThan"), &Vector3::operator >)
.Func< bool (Vector3::*)(const Vector3 &) const >(_SC("opLessEqual"), &Vector3::operator <=)
.Func< bool (Vector3::*)(const Vector3 &) const >(_SC("opGreaterEqual"), &Vector3::operator >=)
);
}

View File

@ -7,16 +7,6 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector3 type from a string.
*/
const Vector3 & GetVector3(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector3 type from a string.
*/
const Vector3 & GetVector3(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent a three-dimensional vector.
*/
@ -331,6 +321,17 @@ struct Vector3
* Retrieve a new instance of this type with absolute component values.
*/
Vector3 Abs() const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector3 type from a string.
*/
static const Vector3 & Get(CSStr str);
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector3 type from a string.
*/
static const Vector3 & Get(CSStr str, SQChar delim);
};
} // Namespace:: SqMod

View File

@ -22,7 +22,7 @@ SQChar Vector4::Delim = ',';
// ------------------------------------------------------------------------------------------------
SQInteger Vector4::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("Vector4");
static const SQChar name[] = _SC("Vector4");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
@ -122,10 +122,10 @@ Vector4 & Vector4::operator /= (const Vector4 & v)
Vector4 & Vector4::operator %= (const Vector4 & v)
{
x = fmod(x, v.x);
y = fmod(y, v.y);
z = fmod(z, v.z);
w = fmod(w, v.w);
x = std::fmod(x, v.x);
y = std::fmod(y, v.y);
z = std::fmod(z, v.z);
w = std::fmod(w, v.w);
return *this;
}
@ -168,10 +168,10 @@ Vector4 & Vector4::operator /= (Value s)
Vector4 & Vector4::operator %= (Value s)
{
x = fmod(x, s);
y = fmod(y, s);
z = fmod(z, s);
w = fmod(w, s);
x = std::fmod(x, s);
y = std::fmod(y, s);
z = std::fmod(z, s);
w = std::fmod(w, s);
return *this;
}
@ -238,7 +238,7 @@ Vector4 Vector4::operator / (const Vector4 & v) const
Vector4 Vector4::operator % (const Vector4 & v) const
{
return Vector4(fmod(x, v.x), fmod(y, v.y), fmod(z, v.z), fmod(w, v.w));
return Vector4(std::fmod(x, v.x), std::fmod(y, v.y), std::fmod(z, v.z), std::fmod(w, v.w));
}
// ------------------------------------------------------------------------------------------------
@ -264,13 +264,13 @@ Vector4 Vector4::operator / (Value s) const
Vector4 Vector4::operator % (Value s) const
{
return Vector4(fmod(x, s), fmod(y, s), fmod(z, s), fmod(w, s));
return Vector4(std::fmod(x, s), std::fmod(y, s), std::fmod(z, s), std::fmod(w, s));
}
// ------------------------------------------------------------------------------------------------
Vector4 Vector4::operator + () const
{
return Vector4(fabs(x), fabs(y), fabs(z), fabs(w));
return Vector4(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
}
Vector4 Vector4::operator - () const
@ -313,11 +313,17 @@ bool Vector4::operator >= (const Vector4 & v) const
Int32 Vector4::Cmp(const Vector4 & o) const
{
if (*this == o)
{
return 0;
}
else if (*this > o)
{
return 1;
}
else
{
return -1;
}
}
// ------------------------------------------------------------------------------------------------
@ -378,7 +384,7 @@ void Vector4::Set(const Quaternion & q)
// ------------------------------------------------------------------------------------------------
void Vector4::Set(CSStr values, SQChar delim)
{
Set(GetVector4(values, delim));
Set(Vector4::Get(values, delim));
}
// ------------------------------------------------------------------------------------------------
@ -393,7 +399,9 @@ void Vector4::Generate()
void Vector4::Generate(Value min, Value max)
{
if (max < min)
{
STHROWF("max value is lower than min value");
}
x = GetRandomFloat32(min, max);
y = GetRandomFloat32(min, max);
@ -404,7 +412,9 @@ void Vector4::Generate(Value min, Value max)
void Vector4::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax)
{
if (EpsLt(xmax, xmin) || EpsLt(ymax, ymin) || EpsLt(zmax, zmin) || EpsLt(wmax, wmin))
{
STHROWF("max value is lower than min value");
}
x = GetRandomFloat32(xmin, xmax);
y = GetRandomFloat32(ymin, ymax);
@ -415,17 +425,17 @@ void Vector4::Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmi
// ------------------------------------------------------------------------------------------------
Vector4 Vector4::Abs() const
{
return Vector4(fabs(x), fabs(y), fabs(z), fabs(w));
return Vector4(std::fabs(x), std::fabs(y), std::fabs(z), std::fabs(w));
}
// ------------------------------------------------------------------------------------------------
const Vector4 & GetVector4(CSStr str)
const Vector4 & Vector4::Get(CSStr str)
{
return GetVector4(str, Vector4::Delim);
return Vector4::Get(str, Vector4::Delim);
}
// ------------------------------------------------------------------------------------------------
const Vector4 & GetVector4(CSStr str, SQChar delim)
const Vector4 & Vector4::Get(CSStr str, SQChar delim)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f , %f , %f ");
@ -442,98 +452,134 @@ const Vector4 & GetVector4(CSStr str, SQChar delim)
fs[9] = delim;
fs[14] = delim;
// Attempt to extract the component values from the specified string
sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z, &vec.w);
std::sscanf(str, &fs[0], &vec.x, &vec.y, &vec.z, &vec.w);
// Return the resulted value
return vec;
}
// ------------------------------------------------------------------------------------------------
const Vector4 & GetVector4()
{
static Vector4 vec;
vec.Clear();
return vec;
}
const Vector4 & GetVector4(Float32 sv)
{
static Vector4 vec;
vec.Set(sv);
return vec;
}
const Vector4 & GetVector4(Float32 xv, Float32 yv, Float32 zv)
{
static Vector4 vec;
vec.Set(xv, yv, zv);
return vec;
}
const Vector4 & GetVector4(Float32 xv, Float32 yv, Float32 zv, Float32 wv)
{
static Vector4 vec;
vec.Set(xv, yv, zv, wv);
return vec;
}
const Vector4 & GetVector4(const Vector4 & o)
{
static Vector4 vec;
vec.Set(o);
return vec;
}
// ================================================================================================
void Register_Vector4(HSQUIRRELVM vm)
{
typedef Vector4::Value Val;
RootTable(vm).Bind(_SC("Vector4"), Class< Vector4 >(vm, _SC("Vector4"))
/* Constructors */
// Constructors
.Ctor()
.Ctor< Val >()
.Ctor< Val, Val, Val >()
.Ctor< Val, Val, Val, Val >()
/* Static Members */
// Static Members
.SetStaticValue(_SC("Delim"), &Vector4::Delim)
/* Member Variables */
// Member Variables
.Var(_SC("x"), &Vector4::x)
.Var(_SC("y"), &Vector4::y)
.Var(_SC("z"), &Vector4::z)
.Var(_SC("w"), &Vector4::w)
/* Properties */
.Prop(_SC("abs"), &Vector4::Abs)
/* Core Metamethods */
// Properties
.Prop(_SC("Abs"), &Vector4::Abs)
// Core Metamethods
.Func(_SC("_tostring"), &Vector4::ToString)
.SquirrelFunc(_SC("_typename"), &Vector4::Typename)
.Func(_SC("_cmp"), &Vector4::Cmp)
/* Metamethods */
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("_add"), &Vector4::operator +)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("_sub"), &Vector4::operator -)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("_mul"), &Vector4::operator *)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("_div"), &Vector4::operator /)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("_modulo"), &Vector4::operator %)
.Func<Vector4 (Vector4::*)(void) const>(_SC("_unm"), &Vector4::operator -)
/* Setters */
.Overload<void (Vector4::*)(Val)>(_SC("Set"), &Vector4::Set)
.Overload<void (Vector4::*)(Val, Val, Val)>(_SC("Set"), &Vector4::Set)
.Overload<void (Vector4::*)(Val, Val, Val, Val)>(_SC("Set"), &Vector4::Set)
.Overload<void (Vector4::*)(const Vector4 &)>(_SC("SetVec4"), &Vector4::Set)
.Overload<void (Vector4::*)(const Vector3 &)>(_SC("SetVec3"), &Vector4::Set)
.Overload<void (Vector4::*)(const Quaternion &)>(_SC("SetQuat"), &Vector4::Set)
.Overload<void (Vector4::*)(CSStr, SQChar)>(_SC("SetStr"), &Vector4::Set)
/* Random Generators */
.Overload<void (Vector4::*)(void)>(_SC("Generate"), &Vector4::Generate)
.Overload<void (Vector4::*)(Val, Val)>(_SC("Generate"), &Vector4::Generate)
.Overload<void (Vector4::*)(Val, Val, Val, Val, Val, Val, Val, Val)>(_SC("Generate"), &Vector4::Generate)
/* Utility Methods */
// Metamethods
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("_add"), &Vector4::operator +)
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("_sub"), &Vector4::operator -)
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("_mul"), &Vector4::operator *)
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("_div"), &Vector4::operator /)
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("_modulo"), &Vector4::operator %)
.Func< Vector4 (Vector4::*)(void) const >(_SC("_unm"), &Vector4::operator -)
// Setters
.Overload< void (Vector4::*)(Val) >(_SC("Set"), &Vector4::Set)
.Overload< void (Vector4::*)(Val, Val, Val) >(_SC("Set"), &Vector4::Set)
.Overload< void (Vector4::*)(Val, Val, Val, Val) >(_SC("Set"), &Vector4::Set)
.Overload< void (Vector4::*)(const Vector4 &) >(_SC("SetVec4"), &Vector4::Set)
.Overload< void (Vector4::*)(const Vector3 &) >(_SC("SetVec3"), &Vector4::Set)
.Overload< void (Vector4::*)(const Quaternion &) >(_SC("SetQuat"), &Vector4::Set)
.Overload< void (Vector4::*)(CSStr, SQChar) >(_SC("SetStr"), &Vector4::Set)
// Random Generators
.Overload< void (Vector4::*)(void) >(_SC("Generate"), &Vector4::Generate)
.Overload< void (Vector4::*)(Val, Val) >(_SC("Generate"), &Vector4::Generate)
.Overload< void (Vector4::*)(Val, Val, Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Vector4::Generate)
// Utility Methods
.Func(_SC("Clear"), &Vector4::Clear)
/* Operator Exposure */
.Func<Vector4 & (Vector4::*)(const Vector4 &)>(_SC("opAddAssign"), &Vector4::operator +=)
.Func<Vector4 & (Vector4::*)(const Vector4 &)>(_SC("opSubAssign"), &Vector4::operator -=)
.Func<Vector4 & (Vector4::*)(const Vector4 &)>(_SC("opMulAssign"), &Vector4::operator *=)
.Func<Vector4 & (Vector4::*)(const Vector4 &)>(_SC("opDivAssign"), &Vector4::operator /=)
.Func<Vector4 & (Vector4::*)(const Vector4 &)>(_SC("opModAssign"), &Vector4::operator %=)
.Func<Vector4 & (Vector4::*)(Vector4::Value)>(_SC("opAddAssignS"), &Vector4::operator +=)
.Func<Vector4 & (Vector4::*)(Vector4::Value)>(_SC("opSubAssignS"), &Vector4::operator -=)
.Func<Vector4 & (Vector4::*)(Vector4::Value)>(_SC("opMulAssignS"), &Vector4::operator *=)
.Func<Vector4 & (Vector4::*)(Vector4::Value)>(_SC("opDivAssignS"), &Vector4::operator /=)
.Func<Vector4 & (Vector4::*)(Vector4::Value)>(_SC("opModAssignS"), &Vector4::operator %=)
.Func<Vector4 & (Vector4::*)(void)>(_SC("opPreInc"), &Vector4::operator ++)
.Func<Vector4 & (Vector4::*)(void)>(_SC("opPreDec"), &Vector4::operator --)
.Func<Vector4 (Vector4::*)(int)>(_SC("opPostInc"), &Vector4::operator ++)
.Func<Vector4 (Vector4::*)(int)>(_SC("opPostDec"), &Vector4::operator --)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("opAdd"), &Vector4::operator +)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("opSub"), &Vector4::operator -)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("opMul"), &Vector4::operator *)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("opDiv"), &Vector4::operator /)
.Func<Vector4 (Vector4::*)(const Vector4 &) const>(_SC("opMod"), &Vector4::operator %)
.Func<Vector4 (Vector4::*)(Vector4::Value) const>(_SC("opAddS"), &Vector4::operator +)
.Func<Vector4 (Vector4::*)(Vector4::Value) const>(_SC("opSubS"), &Vector4::operator -)
.Func<Vector4 (Vector4::*)(Vector4::Value) const>(_SC("opMulS"), &Vector4::operator *)
.Func<Vector4 (Vector4::*)(Vector4::Value) const>(_SC("opDivS"), &Vector4::operator /)
.Func<Vector4 (Vector4::*)(Vector4::Value) const>(_SC("opModS"), &Vector4::operator %)
.Func<Vector4 (Vector4::*)(void) const>(_SC("opUnPlus"), &Vector4::operator +)
.Func<Vector4 (Vector4::*)(void) const>(_SC("opUnMinus"), &Vector4::operator -)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opEqual"), &Vector4::operator ==)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opNotEqual"), &Vector4::operator !=)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opLessThan"), &Vector4::operator <)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opGreaterThan"), &Vector4::operator >)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opLessEqual"), &Vector4::operator <=)
.Func<bool (Vector4::*)(const Vector4 &) const>(_SC("opGreaterEqual"), &Vector4::operator >=)
// Static Overloads
.StaticOverload< const Vector4 & (*)(CSStr) >(_SC("FromStr"), &GetVector4)
.StaticOverload< const Vector4 & (*)(CSStr, SQChar) >(_SC("FromStr"), &GetVector4)
.StaticOverload< const Vector4 & (*)(CSStr) >(_SC("FromStr"), &Vector4::Get)
.StaticOverload< const Vector4 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Vector4::Get)
// Operator Exposure
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opAddAssign"), &Vector4::operator +=)
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opSubAssign"), &Vector4::operator -=)
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opMulAssign"), &Vector4::operator *=)
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opDivAssign"), &Vector4::operator /=)
.Func< Vector4 & (Vector4::*)(const Vector4 &) >(_SC("opModAssign"), &Vector4::operator %=)
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opAddAssignS"), &Vector4::operator +=)
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opSubAssignS"), &Vector4::operator -=)
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opMulAssignS"), &Vector4::operator *=)
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opDivAssignS"), &Vector4::operator /=)
.Func< Vector4 & (Vector4::*)(Vector4::Value) >(_SC("opModAssignS"), &Vector4::operator %=)
.Func< Vector4 & (Vector4::*)(void) >(_SC("opPreInc"), &Vector4::operator ++)
.Func< Vector4 & (Vector4::*)(void) >(_SC("opPreDec"), &Vector4::operator --)
.Func< Vector4 (Vector4::*)(int) >(_SC("opPostInc"), &Vector4::operator ++)
.Func< Vector4 (Vector4::*)(int) >(_SC("opPostDec"), &Vector4::operator --)
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opAdd"), &Vector4::operator +)
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opSub"), &Vector4::operator -)
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opMul"), &Vector4::operator *)
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opDiv"), &Vector4::operator /)
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("opMod"), &Vector4::operator %)
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opAddS"), &Vector4::operator +)
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opSubS"), &Vector4::operator -)
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opMulS"), &Vector4::operator *)
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opDivS"), &Vector4::operator /)
.Func< Vector4 (Vector4::*)(Vector4::Value) const >(_SC("opModS"), &Vector4::operator %)
.Func< Vector4 (Vector4::*)(void) const >(_SC("opUnPlus"), &Vector4::operator +)
.Func< Vector4 (Vector4::*)(void) const >(_SC("opUnMinus"), &Vector4::operator -)
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opEqual"), &Vector4::operator ==)
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opNotEqual"), &Vector4::operator !=)
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opLessThan"), &Vector4::operator <)
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opGreaterThan"), &Vector4::operator >)
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opLessEqual"), &Vector4::operator <=)
.Func< bool (Vector4::*)(const Vector4 &) const >(_SC("opGreaterEqual"), &Vector4::operator >=)
);
}

View File

@ -7,16 +7,6 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector4 type from a string.
*/
const Vector4 & GetVector4(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Vector4 type from a string.
*/
const Vector4 & GetVector4(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent a four-dimensional vector.
*/
@ -341,6 +331,17 @@ struct Vector4
* Retrieve a new instance of this type with absolute component values.
*/
Vector4 Abs() const;
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector4 type from a string.
*/
static const Vector4 & Get(CSStr str);
/* --------------------------------------------------------------------------------------------
* Extract the values for components of the Vector4 type from a string.
*/
static const Vector4 & Get(CSStr str, SQChar delim);
};
} // Namespace:: SqMod

Some files were not shown because too many files have changed in this diff Show More