Merge branch 'master' of git://github.com/graphitemaster/gmqcc

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-08-15 12:11:45 +02:00
commit 5b4c7a67a7
3 changed files with 160 additions and 23 deletions

48
gmqcc.h
View file

@ -29,6 +29,17 @@
#include <stdarg.h>
#include <ctype.h>
/*
* Disable some over protective warnings in visual studio because fixing them is a waste
* of my time.
*/
#ifdef _MSC_VER
# pragma warning(disable : 4244 ) // conversion from 'int' to 'float', possible loss of data
# pragma warning(disable : 4018 ) // signed/unsigned mismatch
# pragma warning(disable : 4996 ) // This function or variable may be unsafe
# pragma warning(disable : 4700 ) // uninitialized local variable used
#endif
#define GMQCC_VERSION_MAJOR 0
#define GMQCC_VERSION_MINOR 1
#define GMQCC_VERSION_PATCH 0
@ -135,31 +146,26 @@
#if INT_MAX == 0x7FFFFFFF
typedef int int32_t;
typedef unsigned int uint32_t;
typedef long int64_t;
typedef unsigned long uint64_t;
#elif LONG_MAX == 0x7FFFFFFF
typedef long int32_t;
typedef unsigned long uint32_t;
#endif
#if defined(__GNUC__) || defined (__CLANG__)
typedef int int64_t __attribute__((__mode__(__DI__)));
typedef unsigned int uint64_t __attribute__((__mode__(__DI__)));
#elif defined(_MSC_VER)
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
/*
* It's nearly impossible to figure out a 64bit type at
* this point without making assumptions about the build
* enviroment. So if clang or gcc is detected use some
* compiler builtins to create a 64 signed and unsigned
* type.
*/
# if defined(__GNUC__) || defined (__CLANG__)
typedef int int64_t __attribute__((__mode__(__DI__)));
typedef unsigned int uint64_t __attribute__((__mode__(__DI__)));
# else
/*
* Incoorectly size the types so static assertions below will
* fail. There is no valid way to get a 64bit type at this point
* without making assumptions of too many things.
*/
typedef struct { char _fail : 0; } int64_t;
typedef struct { char _fail : 0; } uint64_t;
# endif
* Incoorectly size the types so static assertions below will
* fail. There is no valid way to get a 64bit type at this point
* without making assumptions of too many things.
*/
typedef struct { char _fail : 0; } int64_t;
typedef struct { char _fail : 0; } uint64_t;
#endif
#ifdef _LP64 /* long pointer == 64 */
typedef unsigned long uintptr_t;
@ -175,7 +181,7 @@ typedef char uint32_size_is_correct [sizeof(uint32_t) == 4?1:-1];
typedef char uint64_size_is_correct [sizeof(uint64_t) == 8?1:-1];
typedef char int16_size_if_correct [sizeof(int16_t) == 2?1:-1];
typedef char int32_size_is_correct [sizeof(int32_t) == 4?1:-1];
typedef char int64_size_is_correct [sizeof(int64_t) == 8?1:-1];
typedef char int64_size_is_correct [sizeof(int64_t) >= 8?1:-1];
/* intptr_t / uintptr_t correct size check */
typedef char uintptr_size_is_correct[sizeof(intptr_t) == sizeof(int*)?1:-1];
typedef char intptr_size_is_correct [sizeof(uintptr_t)== sizeof(int*)?1:-1];

131
gmqcc.vcxproj Executable file
View file

@ -0,0 +1,131 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{85C266A8-7938-4AE6-AB64-428DC32B1ACD}</ProjectGuid>
<RootNamespace>gmqcc</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>.\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IntDir>.\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<TargetName>gmqcc</TargetName>
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>.</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IntDir>.</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<TargetName>gmqcc</TargetName>
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ExceptionHandling>false</ExceptionHandling>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FloatingPointModel>Fast</FloatingPointModel>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>
</PrecompiledHeaderOutputFile>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ManifestFile>
</ManifestFile>
<ProgramDatabaseFile>$(TargetName).pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ExceptionHandling>false</ExceptionHandling>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FloatingPointModel>Fast</FloatingPointModel>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>
</PrecompiledHeaderOutputFile>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ManifestFile>
</ManifestFile>
<ProgramDatabaseFile>$(TargetName).pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="asm.c" />
<ClCompile Include="ast.c" />
<ClCompile Include="code.c" />
<ClCompile Include="error.c" />
<ClCompile Include="exec.c" />
<ClCompile Include="ir.c" />
<ClCompile Include="lexer.c" />
<ClCompile Include="main.c" />
<ClCompile Include="parser.c" />
<ClCompile Include="util.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ast.h" />
<ClInclude Include="execloop.h" />
<ClInclude Include="gmqcc.h" />
<ClInclude Include="ir.h" />
<ClInclude Include="lexer.h" />
</ItemGroup>
<ItemGroup>
<None Include="flags.def" />
<None Include="warns.def" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

4
util.c
View file

@ -37,7 +37,7 @@ struct memblock_t {
void *util_memory_a(unsigned int byte, unsigned int line, const char *file) {
struct memblock_t *info = malloc(sizeof(struct memblock_t) + byte);
void *data =(void*)((uintptr_t)info+sizeof(struct memblock_t));
void *data =(void*)((unsigned char*)info+sizeof(struct memblock_t));
if (!data) return NULL;
info->line = line;
info->byte = byte;
@ -54,7 +54,7 @@ void util_memory_d(void *ptrn, unsigned int line, const char *file) {
void *data = NULL;
struct memblock_t *info = NULL;
if (!ptrn) return;
data = (void*)((uintptr_t)ptrn-sizeof(struct memblock_t));
data = (void*)((unsigned char *)ptrn-sizeof(struct memblock_t));
info = (struct memblock_t*)data;
util_debug("MEM", "released: % 8u (bytes) address 0x%08X @ %s:%u\n", info->byte, data, file, line);