Skip to content

Commit

Permalink
fix compile with tcc
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-s168 committed Nov 14, 2024
1 parent d3186ec commit 6b836dc
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
build/
build.exe
build.changed
build.slowdb
venv/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ VXCC uses SSA IR with block arguments instead of the commonly used phi-nodes.
use the `./build.sh build`

## compile dependencies
`clang`: different C compiler can be used by doing `CC=someothercc ./build.sh [build|test]` (`test` can be executed after `build` to run all tests)
`clang`, `gcc`, or `tcc`: automatically detected. different C compiler can be used by doing `CC=someothercc ./build.sh [build|test]` (`test` can be executed after `build` to run all tests)

`python3`: it is recommended to create a venv in the repository root using `python -m venv venv`

Expand Down
2 changes: 1 addition & 1 deletion allib
Submodule allib updated 5 files
+1 −1 .gitignore
+6 −0 build.c
+1 −1 build_c
+5 −3 germanstr/germanstr.h
+4 −0 memlib.c
2 changes: 1 addition & 1 deletion build.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum CompileResult target_deps() {
});

START;
ss("allib/", ({
ssx("allib/", "-DHAVE_WINSOCK=0", ({
ss_task("all.a");
}));
END;
Expand Down
66 changes: 46 additions & 20 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
set -e

: ${CFLAGS:="-Wall -Wextra -Wno-unused -Wno-unused-parameter -Wno-comment -Wno-format -Wno-sign-compare -Wno-char-subscripts -Wno-implicit-fallthrough -Wno-missing-braces -Werror -g -glldb"}
set -e

if [ -z $EMPATH ]; then
: ${EX_CFLAGS:=""}
: ${EX_LDFLAGS:=""}

if [ -z $CC ]; then
if hash clang 2>/dev/null; then
CC="clang"
AUTO_CFLAGS_DBG="-g -glldb"
elif hash gcc 2>/dev/null; then
CC="gcc"
AUTO_CFLAGS_DBG="-g -ggdb"
elif hash tcc 2>/dev/null; then
CC="tcc"
: ${AR:="tcc -ar"}
: ${SERIAL:=1}
AUTO_CFLAGS_DBG="-g"
else
echo "could not find a C compiler. please manually set the CC variable"
fi
else
: ${CC:=clang}
: ${BUILD_CC:=$CC}
: ${EX_CFLAGS:=""}
: ${EX_LDFLAGS:=""}
: ${AR:="ar"}
fi

: ${AR:="ar"}
: ${BUILD_CC:=$CC}
else
: ${CC:=$EMPATH/emcc}
: ${BUILD_CC:=clang}
: ${EX_CFLAGS:="-O3"}
: ${EX_LDFLAGS:=""}
: ${AR:=$EMPATH/emar}
: ${CC:=$EMPATH/emcc}
: ${BUILD_CC:=clang}
: ${EX_CFLAGS:="-O3"}
: ${EX_LDFLAGS:=""}
: ${AR:=$EMPATH/emar}
fi

AUTO_CFLAGS="-Wall -Wextra -Wno-unused -Wno-unused-parameter -Wno-comment -Wno-format -Wno-sign-compare -Wno-char-subscripts -Wno-implicit-fallthrough -Wno-missing-braces -Werror ${AUTO_CFLAGS_DBG}"

: ${SERIAL:=0}
: ${CFLAGS:="$AUTO_CFLAGS"}

echo ""

ANALYZER_FLAGS="$CFLAGS -Wno-analyzer-malloc-leak -Wno-analyzer-deref-before-check"
CFLAGS="$CFLAGS $EX_CFLAGS"

Expand All @@ -41,7 +65,12 @@ FILES="ir/*.c common/*.c ir/opt/*.c ir/transform/*.c cg/x86_stupid/*.c irparser/
# shellcheck disable=SC2086

function prepare() {
$BUILD_CC build.c -lpthread -DVERBOSE=1 -DPYTHON="\"$python\"" -DCC="\"$CC\"" -DCC_ARGS="\"$CFLAGS\"" -DLD_ARGS="\"$EX_LDFLAGS -lpthread\"" -DAR="\"$AR\"" -o build.exe
if [[ $SERIAL == 1 ]]; then
SERIAL_ARGS="-DSERIAL=1"
else
SERIAL_ARGS="-lpthread"
fi
$BUILD_CC build.c $SERIAL_ARGS $CFLAGS -DVERBOSE=1 -DCC="\"$CC\"" -DCC_ARGS="\"$CFLAGS\"" -DLD_ARGS="\"$EX_LDFLAGS $SERIAL_ARGS\"" -DAR="\"$AR\"" -o build.exe
echo "# build.exe compiled"
echo "# gen cdef files"
./build.exe gen
Expand All @@ -58,14 +87,11 @@ elif [[ $1 == "ganalyze" ]]; then
echo "# starting analyzer (gcc)"
gcc -fanalyzer -fsanitize-trap=undefined $ANALYZER_FLAGS $FILES
elif [[ $1 == "info" ]]; then
echo clang:
clang --version
echo gcc:
gcc --version
echo cflags: $CFLAGS
echo files: $FILES
echo cc:
echo CC:
"$CC" --version
echo BUILD_CC:
"$CC" --version
echo cflags: $CFLAGS
elif [[ $1 == "build" ]]; then
echo "# compile Debug"
prepare
Expand Down
2 changes: 1 addition & 1 deletion build_c
Submodule build_c updated 4 files
+21 −33 build.h
+0 −1,253 includedb.h
+3 −1 minirent.h
+252 −0 slowdb.h
4 changes: 2 additions & 2 deletions common/common.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.h"
#include "../ir/ir.h"

int vx_Target_parse(vx_Target* dest, const char * str)
{
Expand Down Expand Up @@ -46,7 +46,7 @@ static bool x86_need_move_ret_to_arg(vx_CU* cu, vx_IrBlock* block, size_t ret_id
return ret_id >= 2;
}

static bool etca_need_move_ret_to_arg(vx_CU*, vx_IrBlock* block, size_t ret_id)
static bool etca_need_move_ret_to_arg(vx_CU* cu, vx_IrBlock* block, size_t ret_id)
{
// TODO
return ret_id >= 1;
Expand Down
1 change: 1 addition & 0 deletions ir/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <stdint.h>

#include "../common/common.h"
#include "../build/ir/ops.cdef.h"
Expand Down
9 changes: 4 additions & 5 deletions irparser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@


// serializable by memcpy
typedef enum : uint8_t {
OPERAND_TYPE_PLACEHOLDER = 0,
OPERAND_TYPE_IMM_INT = 1,
OPERAND_TYPE_IMM_FLT = 2,
} OperandType;
typedef uint8_t OperandType;
#define OPERAND_TYPE_PLACEHOLDER ((OperandType) 0)
#define OPERAND_TYPE_IMM_INT ((OperandType) 1)
#define OPERAND_TYPE_IMM_FLT ((OperandType) 2)

// serializable by memcpy
typedef struct {
Expand Down

0 comments on commit 6b836dc

Please sign in to comment.