mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-15 02:12:22 -07:00
Merge remote-tracking branch 'upstream/master' into prototype-fmt
This commit is contained in:
@@ -7,20 +7,22 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Download LLVM
|
||||
run: sudo apt-get install llvm
|
||||
run: sudo apt-get install llvm-11 clang-11 llvm
|
||||
- name: build odin
|
||||
run: make release
|
||||
- name: Odin run
|
||||
run: ./odin run examples/demo/demo.odin
|
||||
- name: Odin check
|
||||
run: ./odin check examples/demo/demo.odin -vet
|
||||
- name: Odin version
|
||||
run: ./odin version
|
||||
build_macOS:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Download LLVM and setup PATH
|
||||
run: |
|
||||
brew install llvm
|
||||
brew install llvm@11
|
||||
echo "/usr/local/opt/llvm/bin" >> $GITHUB_PATH
|
||||
TMP_PATH=$(xcrun --show-sdk-path)/user/include
|
||||
echo "CPATH=$TMP_PATH" >> $GITHUB_ENV
|
||||
@@ -30,6 +32,8 @@ jobs:
|
||||
run: ./odin run examples/demo/demo.odin
|
||||
- name: Odin check
|
||||
run: ./odin check examples/demo/demo.odin -vet
|
||||
- name: Odin version
|
||||
run: ./odin version
|
||||
build_windows:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
@@ -56,5 +60,7 @@ jobs:
|
||||
run: |
|
||||
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat
|
||||
odin check examples/demo/demo.odin -vet
|
||||
- name: Odin version
|
||||
run: ./odin version
|
||||
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: (Linux) Download LLVM
|
||||
run: sudo apt-get install llvm
|
||||
run: sudo apt-get install llvm-11 clang-11 llvm
|
||||
- name: build odin
|
||||
run: make nightly
|
||||
- name: Odin run
|
||||
@@ -100,26 +100,26 @@ jobs:
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '3.x'
|
||||
|
||||
|
||||
- name: Install B2 CLI
|
||||
shell: bash
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install --upgrade b2
|
||||
|
||||
|
||||
- name: Display Python version
|
||||
run: python -c "import sys; print(sys.version)"
|
||||
|
||||
|
||||
- name: Download Windows artifacts
|
||||
uses: actions/download-artifact@v1
|
||||
with:
|
||||
name: windows_artifacts
|
||||
|
||||
|
||||
- name: Download Ubuntu artifacts
|
||||
uses: actions/download-artifact@v1
|
||||
with:
|
||||
name: ubuntu_artifacts
|
||||
|
||||
|
||||
- name: Download macOS artifacts
|
||||
uses: actions/download-artifact@v1
|
||||
with:
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
GIT_SHA=$(shell git rev-parse --short HEAD)
|
||||
DISABLED_WARNINGS=-Wno-switch -Wno-pointer-sign -Wno-tautological-constant-out-of-range-compare -Wno-tautological-compare -Wno-macro-redefined
|
||||
LDFLAGS=-pthread -ldl -lm -lstdc++
|
||||
CFLAGS=-std=c++11 -DGIT_SHA=\"$(GIT_SHA)\"
|
||||
CFLAGS=-std=c++14 -DGIT_SHA=\"$(GIT_SHA)\"
|
||||
CFLAGS:=$(CFLAGS) -DODIN_VERSION_RAW=\"dev-$(shell date +"%Y-%m")\"
|
||||
CC=clang
|
||||
|
||||
OS=$(shell uname)
|
||||
|
||||
ifeq ($(OS), Darwin)
|
||||
LDFLAGS:=$(LDFLAGS) -liconv
|
||||
CFLAGS:=$(CFLAGS) $(shell llvm-config --cxxflags --ldflags)
|
||||
LDFLAGS:=$(LDFLAGS) -lLLVM-C
|
||||
endif
|
||||
ifeq ($(OS), Linux)
|
||||
CFLAGS:=$(CFLAGS) $(shell llvm-config-11 --cxxflags --ldflags)
|
||||
LDFLAGS:=$(LDFLAGS) $(shell llvm-config-11 --libs core native --system-libs)
|
||||
endif
|
||||
|
||||
all: debug demo
|
||||
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
release_mode=$1
|
||||
|
||||
warnings_to_disable="-std=c++11 -Wno-switch"
|
||||
|
||||
libraries="-pthread -ldl -lm -lstdc++ -lz -lcurses -lxml2"
|
||||
other_args="-DLLVM_BACKEND_SUPPORT"
|
||||
compiler="clang"
|
||||
|
||||
if [ -z "$release_mode" ]; then release_mode="0"; fi
|
||||
|
||||
if [ "$release_mode" -eq "0" ]; then
|
||||
other_args="${other_args} -g"
|
||||
fi
|
||||
if [ "$release_mode" -eq "1" ]; then
|
||||
other_args="${other_args} -O3 -march=native"
|
||||
fi
|
||||
|
||||
if [[ "$(uname)" == "Darwin" ]]; then
|
||||
|
||||
# Set compiler to clang on MacOS
|
||||
# MacOS provides a symlink to clang called gcc, but it's nice to be explicit here.
|
||||
compiler="clang"
|
||||
|
||||
llvm_config_flags="--cxxflags --ldflags"
|
||||
# llvm_config_flags="${llvm_config_flags} --link-static"
|
||||
llvm_config="llvm-config ${llvm_config_flags}"
|
||||
|
||||
other_args="${other_args} -liconv"
|
||||
other_args="${other_args} `${llvm_config}` -lLLVM-C"
|
||||
elif [[ "$(uname)" == "FreeBSD" ]]; then
|
||||
compiler="clang"
|
||||
fi
|
||||
|
||||
${compiler} src/main.cpp ${warnings_to_disable} ${libraries} ${other_args} -o odin
|
||||
# && ./odin run examples/demo/demo.odin -llvm-api
|
||||
@@ -1,5 +1,10 @@
|
||||
@echo off
|
||||
|
||||
setlocal EnableDelayedExpansion
|
||||
|
||||
set curr_year=%DATE:~-4%
|
||||
set curr_month=%DATE:~3,2%
|
||||
|
||||
:: Make sure this is a decent name and not generic
|
||||
set exe_name=odin.exe
|
||||
|
||||
@@ -19,8 +24,10 @@ if "%2" == "1" (
|
||||
set nightly=0
|
||||
)
|
||||
|
||||
set odin_version_raw="dev-%curr_year%-%curr_month%"
|
||||
|
||||
set compiler_flags= -nologo -Oi -TP -fp:precise -Gm- -MP -FC -EHsc- -GR- -GF
|
||||
set compiler_defines= -DLLVM_BACKEND_SUPPORT -DUSE_NEW_LLVM_ABI_SYSTEM
|
||||
set compiler_defines= -DODIN_VERSION_RAW=\"%odin_version_raw%\"
|
||||
|
||||
for /f %%i in ('git rev-parse --short HEAD') do set GIT_SHA=%%i
|
||||
if %ERRORLEVEL% equ 0 set compiler_defines=%compiler_defines% -DGIT_SHA=\"%GIT_SHA%\"
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
release_mode=$1
|
||||
|
||||
warnings_to_disable="-std=c++11 -Wno-switch -Wno-pointer-sign -Wno-tautological-constant-out-of-range-compare -Wno-tautological-compare -Wno-macro-redefined"
|
||||
libraries="-pthread -ldl -lm -lstdc++"
|
||||
other_args=""
|
||||
compiler="clang"
|
||||
|
||||
if [ -z "$release_mode" ]; then release_mode="0"; fi
|
||||
|
||||
if [ "$release_mode" -eq "0" ]; then
|
||||
other_args="${other_args} -g"
|
||||
fi
|
||||
if [ "$release_mode" -eq "1" ]; then
|
||||
other_args="${other_args} -O3 -march=native"
|
||||
fi
|
||||
|
||||
if [[ "$(uname)" == "Darwin" ]]; then
|
||||
|
||||
# Set compiler to clang on MacOS
|
||||
# MacOS provides a symlink to clang called gcc, but it's nice to be explicit here.
|
||||
compiler="clang"
|
||||
|
||||
other_args="${other_args} -liconv"
|
||||
elif [[ "$(uname)" == "FreeBSD" ]]; then
|
||||
compiler="clang"
|
||||
fi
|
||||
|
||||
${compiler} src/main.cpp ${warnings_to_disable} ${libraries} ${other_args} -o odin && ./odin run examples/demo/demo.odin
|
||||
+13
-214
@@ -1,6 +1,6 @@
|
||||
package math_bits
|
||||
|
||||
import "core:runtime"
|
||||
import "intrinsics"
|
||||
|
||||
U8_MIN :: 0;
|
||||
U16_MIN :: 0;
|
||||
@@ -22,105 +22,19 @@ I16_MAX :: 1 << 15 - 1;
|
||||
I32_MAX :: 1 << 31 - 1;
|
||||
I64_MAX :: 1 << 63 - 1;
|
||||
|
||||
@(default_calling_convention="none")
|
||||
foreign {
|
||||
@(link_name="llvm.ctpop.i8") count_ones8 :: proc(i: u8) -> u8 ---
|
||||
@(link_name="llvm.ctpop.i16") count_ones16 :: proc(i: u16) -> u16 ---
|
||||
@(link_name="llvm.ctpop.i32") count_ones32 :: proc(i: u32) -> u32 ---
|
||||
@(link_name="llvm.ctpop.i64") count_ones64 :: proc(i: u64) -> u64 ---
|
||||
|
||||
@(link_name="llvm.cttz.i8") trailing_zeros8 :: proc(i: u8, is_zero_undef := false) -> u8 ---
|
||||
@(link_name="llvm.cttz.i16") trailing_zeros16 :: proc(i: u16, is_zero_undef := false) -> u16 ---
|
||||
@(link_name="llvm.cttz.i32") trailing_zeros32 :: proc(i: u32, is_zero_undef := false) -> u32 ---
|
||||
@(link_name="llvm.cttz.i64") trailing_zeros64 :: proc(i: u64, is_zero_undef := false) -> u64 ---
|
||||
count_ones :: intrinsics.count_ones;
|
||||
count_zeros :: intrinsics.count_zeros;
|
||||
trailing_zeros :: intrinsics.count_trailing_zeros;
|
||||
leading_zeros :: intrinsics.count_leading_zeros;
|
||||
count_trailing_zeros :: intrinsics.count_trailing_zeros;
|
||||
count_leading_zeros :: intrinsics.count_leading_zeros;
|
||||
reverse_bits :: intrinsics.reverse_bits;
|
||||
byte_swap :: intrinsics.byte_swap;
|
||||
|
||||
@(link_name="llvm.bitreverse.i8") reverse_bits8 :: proc(i: u8) -> u8 ---
|
||||
@(link_name="llvm.bitreverse.i16") reverse_bits16 :: proc(i: u16) -> u16 ---
|
||||
@(link_name="llvm.bitreverse.i32") reverse_bits32 :: proc(i: u32) -> u32 ---
|
||||
@(link_name="llvm.bitreverse.i64") reverse_bits64 :: proc(i: u64) -> u64 ---
|
||||
}
|
||||
|
||||
|
||||
trailing_zeros_uint :: proc(i: uint) -> uint {
|
||||
when size_of(uint) == size_of(u64) {
|
||||
return uint(trailing_zeros64(u64(i)));
|
||||
} else {
|
||||
return uint(trailing_zeros32(u32(i)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
leading_zeros_u8 :: proc(i: u8) -> int {
|
||||
return 8*size_of(i) - len_u8(i);
|
||||
}
|
||||
leading_zeros_u16 :: proc(i: u16) -> int {
|
||||
return 8*size_of(i) - len_u16(i);
|
||||
}
|
||||
leading_zeros_u32 :: proc(i: u32) -> int {
|
||||
return 8*size_of(i) - len_u32(i);
|
||||
}
|
||||
leading_zeros_u64 :: proc(i: u64) -> int {
|
||||
return 8*size_of(i) - len_u64(i);
|
||||
}
|
||||
|
||||
|
||||
byte_swap_u16 :: proc(x: u16) -> u16 {
|
||||
return runtime.bswap_16(x);
|
||||
}
|
||||
byte_swap_u32 :: proc(x: u32) -> u32 {
|
||||
return runtime.bswap_32(x);
|
||||
}
|
||||
byte_swap_u64 :: proc(x: u64) -> u64 {
|
||||
return runtime.bswap_64(x);
|
||||
}
|
||||
byte_swap_i16 :: proc(x: i16) -> i16 {
|
||||
return i16(runtime.bswap_16(u16(x)));
|
||||
}
|
||||
byte_swap_i32 :: proc(x: i32) -> i32 {
|
||||
return i32(runtime.bswap_32(u32(x)));
|
||||
}
|
||||
byte_swap_i64 :: proc(x: i64) -> i64 {
|
||||
return i64(runtime.bswap_64(u64(x)));
|
||||
}
|
||||
byte_swap_u128 :: proc(x: u128) -> u128 {
|
||||
return runtime.bswap_128(x);
|
||||
}
|
||||
byte_swap_i128 :: proc(x: i128) -> i128 {
|
||||
return i128(runtime.bswap_128(u128(x)));
|
||||
}
|
||||
|
||||
byte_swap_uint :: proc(i: uint) -> uint {
|
||||
when size_of(uint) == size_of(u32) {
|
||||
return uint(byte_swap_u32(u32(i)));
|
||||
} else {
|
||||
return uint(byte_swap_u64(u64(i)));
|
||||
}
|
||||
}
|
||||
byte_swap_int :: proc(i: int) -> int {
|
||||
when size_of(int) == size_of(i32) {
|
||||
return int(byte_swap_i32(i32(i)));
|
||||
} else {
|
||||
return int(byte_swap_i64(i64(i)));
|
||||
}
|
||||
}
|
||||
|
||||
byte_swap :: proc{
|
||||
byte_swap_u16,
|
||||
byte_swap_u32,
|
||||
byte_swap_u64,
|
||||
byte_swap_u128,
|
||||
byte_swap_i16,
|
||||
byte_swap_i32,
|
||||
byte_swap_i64,
|
||||
byte_swap_i128,
|
||||
byte_swap_uint,
|
||||
byte_swap_int,
|
||||
};
|
||||
|
||||
count_zeros8 :: proc(i: u8) -> u8 { return 8 - count_ones8(i); }
|
||||
count_zeros16 :: proc(i: u16) -> u16 { return 16 - count_ones16(i); }
|
||||
count_zeros32 :: proc(i: u32) -> u32 { return 32 - count_ones32(i); }
|
||||
count_zeros64 :: proc(i: u64) -> u64 { return 64 - count_ones64(i); }
|
||||
overflowing_add :: intrinsics.overflow_add;
|
||||
overflowing_sub :: intrinsics.overflow_sub;
|
||||
overflowing_mul :: intrinsics.overflow_mul;
|
||||
|
||||
|
||||
rotate_left8 :: proc(x: u8, k: int) -> u8 {
|
||||
@@ -176,121 +90,6 @@ to_le_u64 :: proc(i: u64) -> u64 { when ODIN_ENDIAN == "little" { return i; }
|
||||
to_le_uint :: proc(i: uint) -> uint { when ODIN_ENDIAN == "little" { return i; } else { return byte_swap(i); } }
|
||||
|
||||
|
||||
@(default_calling_convention="none")
|
||||
foreign {
|
||||
@(link_name="llvm.uadd.with.overflow.i8") overflowing_add_u8 :: proc(lhs, rhs: u8) -> (u8, bool) ---
|
||||
@(link_name="llvm.sadd.with.overflow.i8") overflowing_add_i8 :: proc(lhs, rhs: i8) -> (i8, bool) ---
|
||||
@(link_name="llvm.uadd.with.overflow.i16") overflowing_add_u16 :: proc(lhs, rhs: u16) -> (u16, bool) ---
|
||||
@(link_name="llvm.sadd.with.overflow.i16") overflowing_add_i16 :: proc(lhs, rhs: i16) -> (i16, bool) ---
|
||||
@(link_name="llvm.uadd.with.overflow.i32") overflowing_add_u32 :: proc(lhs, rhs: u32) -> (u32, bool) ---
|
||||
@(link_name="llvm.sadd.with.overflow.i32") overflowing_add_i32 :: proc(lhs, rhs: i32) -> (i32, bool) ---
|
||||
@(link_name="llvm.uadd.with.overflow.i64") overflowing_add_u64 :: proc(lhs, rhs: u64) -> (u64, bool) ---
|
||||
@(link_name="llvm.sadd.with.overflow.i64") overflowing_add_i64 :: proc(lhs, rhs: i64) -> (i64, bool) ---
|
||||
}
|
||||
|
||||
overflowing_add_uint :: proc(lhs, rhs: uint) -> (uint, bool) {
|
||||
when size_of(uint) == size_of(u32) {
|
||||
x, ok := overflowing_add_u32(u32(lhs), u32(rhs));
|
||||
return uint(x), ok;
|
||||
} else {
|
||||
x, ok := overflowing_add_u64(u64(lhs), u64(rhs));
|
||||
return uint(x), ok;
|
||||
}
|
||||
}
|
||||
overflowing_add_int :: proc(lhs, rhs: int) -> (int, bool) {
|
||||
when size_of(int) == size_of(i32) {
|
||||
x, ok := overflowing_add_i32(i32(lhs), i32(rhs));
|
||||
return int(x), ok;
|
||||
} else {
|
||||
x, ok := overflowing_add_i64(i64(lhs), i64(rhs));
|
||||
return int(x), ok;
|
||||
}
|
||||
}
|
||||
|
||||
overflowing_add :: proc{
|
||||
overflowing_add_u8, overflowing_add_i8,
|
||||
overflowing_add_u16, overflowing_add_i16,
|
||||
overflowing_add_u32, overflowing_add_i32,
|
||||
overflowing_add_u64, overflowing_add_i64,
|
||||
overflowing_add_uint, overflowing_add_int,
|
||||
};
|
||||
|
||||
@(default_calling_convention="none")
|
||||
foreign {
|
||||
@(link_name="llvm.usub.with.overflow.i8") overflowing_sub_u8 :: proc(lhs, rhs: u8) -> (u8, bool) ---
|
||||
@(link_name="llvm.ssub.with.overflow.i8") overflowing_sub_i8 :: proc(lhs, rhs: i8) -> (i8, bool) ---
|
||||
@(link_name="llvm.usub.with.overflow.i16") overflowing_sub_u16 :: proc(lhs, rhs: u16) -> (u16, bool) ---
|
||||
@(link_name="llvm.ssub.with.overflow.i16") overflowing_sub_i16 :: proc(lhs, rhs: i16) -> (i16, bool) ---
|
||||
@(link_name="llvm.usub.with.overflow.i32") overflowing_sub_u32 :: proc(lhs, rhs: u32) -> (u32, bool) ---
|
||||
@(link_name="llvm.ssub.with.overflow.i32") overflowing_sub_i32 :: proc(lhs, rhs: i32) -> (i32, bool) ---
|
||||
@(link_name="llvm.usub.with.overflow.i64") overflowing_sub_u64 :: proc(lhs, rhs: u64) -> (u64, bool) ---
|
||||
@(link_name="llvm.ssub.with.overflow.i64") overflowing_sub_i64 :: proc(lhs, rhs: i64) -> (i64, bool) ---
|
||||
}
|
||||
overflowing_sub_uint :: proc(lhs, rhs: uint) -> (uint, bool) {
|
||||
when size_of(uint) == size_of(u32) {
|
||||
x, ok := overflowing_sub_u32(u32(lhs), u32(rhs));
|
||||
return uint(x), ok;
|
||||
} else {
|
||||
x, ok := overflowing_sub_u64(u64(lhs), u64(rhs));
|
||||
return uint(x), ok;
|
||||
}
|
||||
}
|
||||
overflowing_sub_int :: proc(lhs, rhs: int) -> (int, bool) {
|
||||
when size_of(int) == size_of(i32) {
|
||||
x, ok := overflowing_sub_i32(i32(lhs), i32(rhs));
|
||||
return int(x), ok;
|
||||
} else {
|
||||
x, ok := overflowing_sub_i64(i64(lhs), i64(rhs));
|
||||
return int(x), ok;
|
||||
}
|
||||
}
|
||||
|
||||
overflowing_sub :: proc{
|
||||
overflowing_sub_u8, overflowing_sub_i8,
|
||||
overflowing_sub_u16, overflowing_sub_i16,
|
||||
overflowing_sub_u32, overflowing_sub_i32,
|
||||
overflowing_sub_u64, overflowing_sub_i64,
|
||||
overflowing_sub_uint, overflowing_sub_int,
|
||||
};
|
||||
|
||||
@(default_calling_convention="none")
|
||||
foreign {
|
||||
@(link_name="llvm.umul.with.overflow.i8") overflowing_mul_u8 :: proc(lhs, rhs: u8) -> (u8, bool) ---
|
||||
@(link_name="llvm.smul.with.overflow.i8") overflowing_mul_i8 :: proc(lhs, rhs: i8) -> (i8, bool) ---
|
||||
@(link_name="llvm.umul.with.overflow.i16") overflowing_mul_u16 :: proc(lhs, rhs: u16) -> (u16, bool) ---
|
||||
@(link_name="llvm.smul.with.overflow.i16") overflowing_mul_i16 :: proc(lhs, rhs: i16) -> (i16, bool) ---
|
||||
@(link_name="llvm.umul.with.overflow.i32") overflowing_mul_u32 :: proc(lhs, rhs: u32) -> (u32, bool) ---
|
||||
@(link_name="llvm.smul.with.overflow.i32") overflowing_mul_i32 :: proc(lhs, rhs: i32) -> (i32, bool) ---
|
||||
@(link_name="llvm.umul.with.overflow.i64") overflowing_mul_u64 :: proc(lhs, rhs: u64) -> (u64, bool) ---
|
||||
@(link_name="llvm.smul.with.overflow.i64") overflowing_mul_i64 :: proc(lhs, rhs: i64) -> (i64, bool) ---
|
||||
}
|
||||
overflowing_mul_uint :: proc(lhs, rhs: uint) -> (uint, bool) {
|
||||
when size_of(uint) == size_of(u32) {
|
||||
x, ok := overflowing_mul_u32(u32(lhs), u32(rhs));
|
||||
return uint(x), ok;
|
||||
} else {
|
||||
x, ok := overflowing_mul_u64(u64(lhs), u64(rhs));
|
||||
return uint(x), ok;
|
||||
}
|
||||
}
|
||||
overflowing_mul_int :: proc(lhs, rhs: int) -> (int, bool) {
|
||||
when size_of(int) == size_of(i32) {
|
||||
x, ok := overflowing_mul_i32(i32(lhs), i32(rhs));
|
||||
return int(x), ok;
|
||||
} else {
|
||||
x, ok := overflowing_mul_i64(i64(lhs), i64(rhs));
|
||||
return int(x), ok;
|
||||
}
|
||||
}
|
||||
|
||||
overflowing_mul :: proc{
|
||||
overflowing_mul_u8, overflowing_mul_i8,
|
||||
overflowing_mul_u16, overflowing_mul_i16,
|
||||
overflowing_mul_u32, overflowing_mul_i32,
|
||||
overflowing_mul_u64, overflowing_mul_i64,
|
||||
overflowing_mul_uint, overflowing_mul_int,
|
||||
};
|
||||
|
||||
|
||||
len_u8 :: proc(x: u8) -> int {
|
||||
return int(len_u8_table[x]);
|
||||
@@ -448,7 +247,7 @@ div_u64 :: proc(hi, lo, y: u64) -> (quo, rem: u64) {
|
||||
panic("overflow error");
|
||||
}
|
||||
|
||||
s := uint(leading_zeros_u64(y));
|
||||
s := uint(count_leading_zeros(y));
|
||||
y <<= s;
|
||||
|
||||
yn1 := y >> 32;
|
||||
|
||||
@@ -12,8 +12,8 @@ heap_allocator :: proc() -> runtime.Allocator {
|
||||
|
||||
heap_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode,
|
||||
size, alignment: int,
|
||||
old_memory: rawptr, old_size: int, flags: u64 = 0, loc := #caller_location) -> rawptr {
|
||||
return _heap_allocator_proc(allocator_data, mode, size, alignment, old_memory, old_size, flags, loc);
|
||||
old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, runtime.Allocator_Error) {
|
||||
return _heap_allocator_proc(allocator_data, mode, size, alignment, old_memory, old_size, loc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@ heap_free :: proc(ptr: rawptr) {
|
||||
win32.HeapFree(win32.GetProcessHeap(), 0, ptr);
|
||||
}
|
||||
|
||||
_heap_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode,
|
||||
_heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode,
|
||||
size, alignment: int,
|
||||
old_memory: rawptr, old_size: int, flags: u64 = 0, loc := #caller_location) -> rawptr {
|
||||
old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, mem.Allocator_Error) {
|
||||
//
|
||||
// NOTE(tetra, 2020-01-14): The heap doesn't respect alignment.
|
||||
// Instead, we overallocate by `alignment + size_of(rawptr) - 1`, and insert
|
||||
@@ -37,7 +37,7 @@ _heap_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mod
|
||||
// the pointer we return to the user.
|
||||
//
|
||||
|
||||
aligned_alloc :: proc(size, alignment: int, old_ptr: rawptr = nil) -> rawptr {
|
||||
aligned_alloc :: proc(size, alignment: int, old_ptr: rawptr = nil) -> ([]byte, mem.Allocator_Error) {
|
||||
a := max(alignment, align_of(rawptr));
|
||||
space := size + a - 1;
|
||||
|
||||
@@ -54,13 +54,13 @@ _heap_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mod
|
||||
aligned_ptr := (ptr - 1 + uintptr(a)) & -uintptr(a);
|
||||
diff := int(aligned_ptr - ptr);
|
||||
if (size + diff) > space {
|
||||
return nil;
|
||||
return nil, .Out_Of_Memory;
|
||||
}
|
||||
|
||||
aligned_mem = rawptr(aligned_ptr);
|
||||
mem.ptr_offset((^rawptr)(aligned_mem), -1)^ = allocated_mem;
|
||||
|
||||
return aligned_mem;
|
||||
return mem.byte_slice(aligned_mem, size), nil;
|
||||
}
|
||||
|
||||
aligned_free :: proc(p: rawptr) {
|
||||
@@ -69,9 +69,9 @@ _heap_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mod
|
||||
}
|
||||
}
|
||||
|
||||
aligned_resize :: proc(p: rawptr, old_size: int, new_size: int, new_alignment: int) -> rawptr {
|
||||
aligned_resize :: proc(p: rawptr, old_size: int, new_size: int, new_alignment: int) -> ([]byte, mem.Allocator_Error) {
|
||||
if p == nil {
|
||||
return nil;
|
||||
return nil, nil;
|
||||
}
|
||||
return aligned_alloc(new_size, new_alignment, p);
|
||||
}
|
||||
@@ -93,15 +93,15 @@ _heap_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mod
|
||||
return aligned_resize(old_memory, old_size, size, alignment);
|
||||
|
||||
case .Query_Features:
|
||||
set := (^runtime.Allocator_Mode_Set)(old_memory);
|
||||
set := (^mem.Allocator_Mode_Set)(old_memory);
|
||||
if set != nil {
|
||||
set^ = {.Alloc, .Free, .Resize, .Query_Features};
|
||||
}
|
||||
return set;
|
||||
return nil, nil;
|
||||
|
||||
case .Query_Info:
|
||||
return nil;
|
||||
return nil, nil;
|
||||
}
|
||||
|
||||
return nil;
|
||||
return nil, nil;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ _make_time_from_unix_file_time :: proc(uft: Unix_File_Time) -> time.Time {
|
||||
_fill_file_info_from_stat :: proc(fi: ^File_Info, s: OS_Stat) {
|
||||
fi.size = s.size;
|
||||
fi.mode = cast(File_Mode)s.mode;
|
||||
fi.is_dir = S_ISDIR(auto_cast s.mode);
|
||||
fi.is_dir = S_ISDIR(u32(s.mode));
|
||||
|
||||
// NOTE(laleksic, 2021-01-21): Not really creation time, but closest we can get (maybe better to leave it 0?)
|
||||
fi.creation_time = _make_time_from_unix_file_time(s.status_change);
|
||||
|
||||
+5
-12
@@ -20,6 +20,8 @@
|
||||
//
|
||||
package runtime
|
||||
|
||||
import "intrinsics"
|
||||
|
||||
// NOTE(bill): This must match the compiler's
|
||||
Calling_Convention :: enum u8 {
|
||||
Invalid = 0,
|
||||
@@ -430,17 +432,9 @@ typeid_base_without_enum :: typeid_core;
|
||||
|
||||
|
||||
|
||||
@(default_calling_convention = "none")
|
||||
foreign {
|
||||
@(link_name="llvm.debugtrap")
|
||||
debug_trap :: proc() ---;
|
||||
|
||||
@(link_name="llvm.trap")
|
||||
trap :: proc() -> ! ---;
|
||||
|
||||
@(link_name="llvm.readcyclecounter")
|
||||
read_cycle_counter :: proc() -> u64 ---;
|
||||
}
|
||||
debug_trap :: intrinsics.debug_trap;
|
||||
trap :: intrinsics.trap;
|
||||
read_cycle_counter :: intrinsics.read_cycle_counter;
|
||||
|
||||
|
||||
|
||||
@@ -488,7 +482,6 @@ __init_context :: proc "contextless" (c: ^Context) {
|
||||
c.logger.data = nil;
|
||||
}
|
||||
|
||||
|
||||
default_assertion_failure_proc :: proc(prefix, message: string, loc: Source_Code_Location) {
|
||||
print_caller_location(loc);
|
||||
print_string(" ");
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package runtime
|
||||
|
||||
import "intrinsics"
|
||||
|
||||
@builtin
|
||||
Maybe :: union(T: typeid) #maybe {T};
|
||||
|
||||
@@ -539,20 +541,15 @@ excl_bit_set :: proc(s: ^$S/bit_set[$E; $U], other: S) {
|
||||
@builtin
|
||||
card :: proc(s: $S/bit_set[$E; $U]) -> int {
|
||||
when size_of(S) == 1 {
|
||||
foreign { @(link_name="llvm.ctpop.i8") count_ones :: proc(i: u8) -> u8 --- }
|
||||
return int(count_ones(transmute(u8)s));
|
||||
return int(intrinsics.count_ones(transmute(u8)s));
|
||||
} else when size_of(S) == 2 {
|
||||
foreign { @(link_name="llvm.ctpop.i16") count_ones :: proc(i: u16) -> u16 --- }
|
||||
return int(count_ones(transmute(u16)s));
|
||||
return int(intrinsics.count_ones(transmute(u16)s));
|
||||
} else when size_of(S) == 4 {
|
||||
foreign { @(link_name="llvm.ctpop.i32") count_ones :: proc(i: u32) -> u32 --- }
|
||||
return int(count_ones(transmute(u32)s));
|
||||
return int(intrinsics.count_ones(transmute(u32)s));
|
||||
} else when size_of(S) == 8 {
|
||||
foreign { @(link_name="llvm.ctpop.i64") count_ones :: proc(i: u64) -> u64 --- }
|
||||
return int(count_ones(transmute(u64)s));
|
||||
return int(intrinsics.count_ones(transmute(u64)s));
|
||||
} else when size_of(S) == 16 {
|
||||
foreign { @(link_name="llvm.ctpop.i128") count_ones :: proc(i: u128) -> u128 --- }
|
||||
return int(count_ones(transmute(u128)s));
|
||||
return int(intrinsics.count_ones(transmute(u128)s));
|
||||
} else {
|
||||
#panic("Unhandled card bit_set size");
|
||||
}
|
||||
|
||||
+19
-66
@@ -107,22 +107,12 @@ mem_copy :: proc "contextless" (dst, src: rawptr, len: int) -> rawptr {
|
||||
}
|
||||
// NOTE(bill): This _must_ be implemented like C's memmove
|
||||
foreign _ {
|
||||
when ODIN_USE_LLVM_API {
|
||||
when size_of(rawptr) == 8 {
|
||||
@(link_name="llvm.memmove.p0i8.p0i8.i64")
|
||||
llvm_memmove :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---;
|
||||
} else {
|
||||
@(link_name="llvm.memmove.p0i8.p0i8.i32")
|
||||
llvm_memmove :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---;
|
||||
}
|
||||
when size_of(rawptr) == 8 {
|
||||
@(link_name="llvm.memmove.p0i8.p0i8.i64")
|
||||
llvm_memmove :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---;
|
||||
} else {
|
||||
when size_of(rawptr) == 8 {
|
||||
@(link_name="llvm.memmove.p0i8.p0i8.i64")
|
||||
llvm_memmove :: proc "none" (dst, src: rawptr, len: int, align: i32 = 1, is_volatile: bool = false) ---;
|
||||
} else {
|
||||
@(link_name="llvm.memmove.p0i8.p0i8.i32")
|
||||
llvm_memmove :: proc "none" (dst, src: rawptr, len: int, align: i32 = 1, is_volatile: bool = false) ---;
|
||||
}
|
||||
@(link_name="llvm.memmove.p0i8.p0i8.i32")
|
||||
llvm_memmove :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---;
|
||||
}
|
||||
}
|
||||
llvm_memmove(dst, src, len);
|
||||
@@ -135,22 +125,12 @@ mem_copy_non_overlapping :: proc "contextless" (dst, src: rawptr, len: int) -> r
|
||||
}
|
||||
// NOTE(bill): This _must_ be implemented like C's memcpy
|
||||
foreign _ {
|
||||
when ODIN_USE_LLVM_API {
|
||||
when size_of(rawptr) == 8 {
|
||||
@(link_name="llvm.memcpy.p0i8.p0i8.i64")
|
||||
llvm_memcpy :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---;
|
||||
} else {
|
||||
@(link_name="llvm.memcpy.p0i8.p0i8.i32")
|
||||
llvm_memcpy :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---;
|
||||
}
|
||||
when size_of(rawptr) == 8 {
|
||||
@(link_name="llvm.memcpy.p0i8.p0i8.i64")
|
||||
llvm_memcpy :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---;
|
||||
} else {
|
||||
when size_of(rawptr) == 8 {
|
||||
@(link_name="llvm.memcpy.p0i8.p0i8.i64")
|
||||
llvm_memcpy :: proc "none" (dst, src: rawptr, len: int, align: i32 = 1, is_volatile: bool = false) ---;
|
||||
} else {
|
||||
@(link_name="llvm.memcpy.p0i8.p0i8.i32")
|
||||
llvm_memcpy :: proc "none" (dst, src: rawptr, len: int, align: i32 = 1, is_volatile: bool = false) ---;
|
||||
}
|
||||
@(link_name="llvm.memcpy.p0i8.p0i8.i32")
|
||||
llvm_memcpy :: proc "none" (dst, src: rawptr, len: int, is_volatile: bool = false) ---;
|
||||
}
|
||||
}
|
||||
llvm_memcpy(dst, src, len);
|
||||
@@ -435,59 +415,32 @@ foreign {
|
||||
@(link_name="llvm.sqrt.f64") _sqrt_f64 :: proc(x: f64) -> f64 ---
|
||||
}
|
||||
abs_f16 :: #force_inline proc "contextless" (x: f16) -> f16 {
|
||||
foreign {
|
||||
@(link_name="llvm.fabs.f16") _abs :: proc "none" (x: f16) -> f16 ---
|
||||
}
|
||||
return _abs(x);
|
||||
return -x if x < 0 else x;
|
||||
}
|
||||
abs_f32 :: #force_inline proc "contextless" (x: f32) -> f32 {
|
||||
foreign {
|
||||
@(link_name="llvm.fabs.f32") _abs :: proc "none" (x: f32) -> f32 ---
|
||||
}
|
||||
return _abs(x);
|
||||
return -x if x < 0 else x;
|
||||
}
|
||||
abs_f64 :: #force_inline proc "contextless" (x: f64) -> f64 {
|
||||
foreign {
|
||||
@(link_name="llvm.fabs.f64") _abs :: proc "none" (x: f64) -> f64 ---
|
||||
}
|
||||
return _abs(x);
|
||||
return -x if x < 0 else x;
|
||||
}
|
||||
|
||||
min_f16 :: proc(a, b: f16) -> f16 {
|
||||
foreign {
|
||||
@(link_name="llvm.minnum.f16") _min :: proc "none" (a, b: f16) -> f16 ---
|
||||
}
|
||||
return _min(a, b);
|
||||
return a if a < b else b;
|
||||
}
|
||||
min_f32 :: proc(a, b: f32) -> f32 {
|
||||
foreign {
|
||||
@(link_name="llvm.minnum.f32") _min :: proc "none" (a, b: f32) -> f32 ---
|
||||
}
|
||||
return _min(a, b);
|
||||
return a if a < b else b;
|
||||
}
|
||||
min_f64 :: proc(a, b: f64) -> f64 {
|
||||
foreign {
|
||||
@(link_name="llvm.minnum.f64") _min :: proc "none" (a, b: f64) -> f64 ---
|
||||
}
|
||||
return _min(a, b);
|
||||
return a if a < b else b;
|
||||
}
|
||||
max_f16 :: proc(a, b: f16) -> f16 {
|
||||
foreign {
|
||||
@(link_name="llvm.maxnum.f16") _max :: proc "none" (a, b: f16) -> f16 ---
|
||||
}
|
||||
return _max(a, b);
|
||||
return a if a > b else b;
|
||||
}
|
||||
max_f32 :: proc(a, b: f32) -> f32 {
|
||||
foreign {
|
||||
@(link_name="llvm.maxnum.f32") _max :: proc "none" (a, b: f32) -> f32 ---
|
||||
}
|
||||
return _max(a, b);
|
||||
return a if a > b else b;
|
||||
}
|
||||
max_f64 :: proc(a, b: f64) -> f64 {
|
||||
foreign {
|
||||
@(link_name="llvm.maxnum.f64") _max :: proc "none" (a, b: f64) -> f64 ---
|
||||
}
|
||||
return _max(a, b);
|
||||
return a if a > b else b;
|
||||
}
|
||||
|
||||
abs_complex32 :: #force_inline proc "contextless" (x: complex32) -> f16 {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package runtime
|
||||
|
||||
import "intrinsics"
|
||||
|
||||
@(link_name="__umodti3")
|
||||
umodti3 :: proc "c" (a, b: u128) -> u128 {
|
||||
r: u128 = ---;
|
||||
@@ -86,12 +88,6 @@ fixdfti :: proc(a: u64) -> i128 {
|
||||
|
||||
}
|
||||
|
||||
@(default_calling_convention = "none")
|
||||
foreign {
|
||||
@(link_name="llvm.ctlz.i128") _clz_i128 :: proc(x: i128, is_zero_undef := false) -> i128 ---
|
||||
}
|
||||
|
||||
|
||||
@(link_name="__floattidf")
|
||||
floattidf :: proc(a: i128) -> f64 {
|
||||
DBL_MANT_DIG :: 53;
|
||||
@@ -102,7 +98,7 @@ floattidf :: proc(a: i128) -> f64 {
|
||||
N :: size_of(i128) * 8;
|
||||
s := a >> (N-1);
|
||||
a = (a ~ s) - s;
|
||||
sd: = N - _clz_i128(a); // number of significant digits
|
||||
sd: = N - intrinsics.count_leading_zeros(a); // number of significant digits
|
||||
e := u32(sd - 1); // exponent
|
||||
if sd > DBL_MANT_DIG {
|
||||
switch sd {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package runtime
|
||||
|
||||
import "intrinsics"
|
||||
|
||||
@(link_name="__umodti3")
|
||||
umodti3 :: proc "c" (a, b: u128) -> u128 {
|
||||
r: u128 = ---;
|
||||
@@ -86,12 +88,6 @@ fixdfti :: proc(a: u64) -> i128 {
|
||||
|
||||
}
|
||||
|
||||
@(default_calling_convention = "none")
|
||||
foreign {
|
||||
@(link_name="llvm.ctlz.i128") _clz_i128 :: proc(x: i128, is_zero_undef := false) -> i128 ---
|
||||
}
|
||||
|
||||
|
||||
@(link_name="__floattidf")
|
||||
floattidf :: proc(a: i128) -> f64 {
|
||||
DBL_MANT_DIG :: 53;
|
||||
@@ -102,7 +98,7 @@ floattidf :: proc(a: i128) -> f64 {
|
||||
N :: size_of(i128) * 8;
|
||||
s := a >> (N-1);
|
||||
a = (a ~ s) - s;
|
||||
sd: = N - _clz_i128(a); // number of significant digits
|
||||
sd: = N - intrinsics.count_leading_zeros(a); // number of significant digits
|
||||
e := u32(sd - 1); // exponent
|
||||
if sd > DBL_MANT_DIG {
|
||||
switch sd {
|
||||
|
||||
@@ -1,35 +1,11 @@
|
||||
package runtime
|
||||
|
||||
@(default_calling_convention="none")
|
||||
foreign {
|
||||
@(link_name="llvm.cttz.i8") _ctz_u8 :: proc(i: u8, is_zero_undef := false) -> u8 ---
|
||||
@(link_name="llvm.cttz.i16") _ctz_u16 :: proc(i: u16, is_zero_undef := false) -> u16 ---
|
||||
@(link_name="llvm.cttz.i32") _ctz_u32 :: proc(i: u32, is_zero_undef := false) -> u32 ---
|
||||
@(link_name="llvm.cttz.i64") _ctz_u64 :: proc(i: u64, is_zero_undef := false) -> u64 ---
|
||||
}
|
||||
_ctz :: proc{
|
||||
_ctz_u8,
|
||||
_ctz_u16,
|
||||
_ctz_u32,
|
||||
_ctz_u64,
|
||||
};
|
||||
|
||||
@(default_calling_convention="none")
|
||||
foreign {
|
||||
@(link_name="llvm.ctlz.i8") _clz_u8 :: proc(i: u8, is_zero_undef := false) -> u8 ---
|
||||
@(link_name="llvm.ctlz.i16") _clz_u16 :: proc(i: u16, is_zero_undef := false) -> u16 ---
|
||||
@(link_name="llvm.ctlz.i32") _clz_u32 :: proc(i: u32, is_zero_undef := false) -> u32 ---
|
||||
@(link_name="llvm.ctlz.i64") _clz_u64 :: proc(i: u64, is_zero_undef := false) -> u64 ---
|
||||
}
|
||||
_clz :: proc{
|
||||
_clz_u8,
|
||||
_clz_u16,
|
||||
_clz_u32,
|
||||
_clz_u64,
|
||||
};
|
||||
|
||||
import "intrinsics"
|
||||
|
||||
udivmod128 :: proc "c" (a, b: u128, rem: ^u128) -> u128 {
|
||||
_ctz :: intrinsics.count_trailing_zeros;
|
||||
_clz :: intrinsics.count_leading_zeros;
|
||||
|
||||
n := transmute([2]u64)a;
|
||||
d := transmute([2]u64)b;
|
||||
q, r: [2]u64 = ---, ---;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package sys_cpu
|
||||
|
||||
#assert(ODIN_USE_LLVM_API);
|
||||
|
||||
Cache_Line_Pad :: struct {_: [_cache_line_size]byte};
|
||||
|
||||
initialized: bool;
|
||||
|
||||
@@ -848,7 +848,7 @@ SID_TYPE :: enum SID_NAME_USE {
|
||||
Unknown,
|
||||
Computer,
|
||||
Label,
|
||||
LogonSession
|
||||
LogonSession,
|
||||
}
|
||||
|
||||
SECURITY_MAX_SID_SIZE :: 68;
|
||||
|
||||
+3
-5
@@ -1,5 +1,7 @@
|
||||
package time
|
||||
|
||||
import "intrinsics"
|
||||
|
||||
Duration :: distinct i64;
|
||||
|
||||
Nanosecond :: Duration(1);
|
||||
@@ -137,11 +139,7 @@ clock :: proc(t: Time) -> (hour, min, sec: int) {
|
||||
|
||||
|
||||
read_cycle_counter :: proc() -> u64 {
|
||||
foreign _ {
|
||||
@(link_name="llvm.readcyclecounter")
|
||||
llvm_readcyclecounter :: proc "none" () -> u64 ---
|
||||
}
|
||||
return llvm_readcyclecounter();
|
||||
return u64(intrinsics.read_cycle_counter());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1109,6 +1109,11 @@ prefix_table := [?]string{
|
||||
};
|
||||
|
||||
threading_example :: proc() {
|
||||
if ODIN_OS == "darwin" {
|
||||
// TODO: Fix threads on darwin/macOS
|
||||
return;
|
||||
}
|
||||
|
||||
fmt.println("\n# threading_example");
|
||||
|
||||
{ // Basic Threads
|
||||
|
||||
+34
-12
@@ -71,9 +71,11 @@ TargetEndianKind target_endians[TargetArch_COUNT] = {
|
||||
TargetEndian_Little,
|
||||
};
|
||||
|
||||
#ifndef ODIN_VERSION_RAW
|
||||
#define ODIN_VERSION_RAW "dev-unknown-unknown"
|
||||
#endif
|
||||
|
||||
|
||||
String const ODIN_VERSION = str_lit("0.13.1");
|
||||
String const ODIN_VERSION = str_lit(ODIN_VERSION_RAW);
|
||||
|
||||
|
||||
|
||||
@@ -199,13 +201,10 @@ struct BuildContext {
|
||||
bool keep_object_files;
|
||||
bool disallow_do;
|
||||
bool insert_semicolon;
|
||||
bool strict_style;
|
||||
|
||||
bool ignore_warnings;
|
||||
bool warnings_as_errors;
|
||||
|
||||
bool use_llvm_api;
|
||||
|
||||
bool use_subsystem_windows;
|
||||
bool ignore_microsoft_magic;
|
||||
bool linker_map_file;
|
||||
@@ -451,8 +450,35 @@ bool find_library_collection_path(String name, String *path) {
|
||||
String const WIN32_SEPARATOR_STRING = {cast(u8 *)"\\", 1};
|
||||
String const NIX_SEPARATOR_STRING = {cast(u8 *)"/", 1};
|
||||
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
|
||||
String internal_odin_root_dir(void);
|
||||
String odin_root_dir(void) {
|
||||
if (global_module_path_set) {
|
||||
return global_module_path;
|
||||
}
|
||||
|
||||
gbAllocator a = heap_allocator();
|
||||
char const *found = gb_get_env("ODIN_ROOT", a);
|
||||
if (found) {
|
||||
String path = path_to_full_path(a, make_string_c(found));
|
||||
if (path[path.len-1] != '/' && path[path.len-1] != '\\') {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
path = concatenate_strings(a, path, WIN32_SEPARATOR_STRING);
|
||||
#else
|
||||
path = concatenate_strings(a, path, NIX_SEPARATOR_STRING);
|
||||
#endif
|
||||
}
|
||||
|
||||
global_module_path = path;
|
||||
global_module_path_set = true;
|
||||
return global_module_path;
|
||||
}
|
||||
return internal_odin_root_dir();
|
||||
}
|
||||
|
||||
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
String internal_odin_root_dir(void) {
|
||||
String path = global_module_path;
|
||||
isize len, i;
|
||||
gbTempArenaMemory tmp;
|
||||
@@ -511,7 +537,7 @@ String odin_root_dir(void) {
|
||||
|
||||
String path_to_fullpath(gbAllocator a, String s);
|
||||
|
||||
String odin_root_dir(void) {
|
||||
String internal_odin_root_dir(void) {
|
||||
String path = global_module_path;
|
||||
isize len, i;
|
||||
gbTempArenaMemory tmp;
|
||||
@@ -569,7 +595,7 @@ String odin_root_dir(void) {
|
||||
|
||||
String path_to_fullpath(gbAllocator a, String s);
|
||||
|
||||
String odin_root_dir(void) {
|
||||
String internal_odin_root_dir(void) {
|
||||
String path = global_module_path;
|
||||
isize len, i;
|
||||
gbTempArenaMemory tmp;
|
||||
@@ -839,10 +865,6 @@ void init_build_context(TargetMetrics *cross_target) {
|
||||
bc->link_flags = str_lit("-arch arm64 ");
|
||||
break;
|
||||
}
|
||||
if ((bc->command_kind & Command__does_build) != 0 && !bc->use_llvm_api) {
|
||||
gb_printf_err("The arm64 architecture is only supported with -llvm-api\n");;
|
||||
gb_exit(1);
|
||||
}
|
||||
|
||||
} else if (bc->metrics.arch == TargetArch_wasm32) {
|
||||
bc->link_flags = str_lit("--no-entry --export-table --export-all --allow-undefined ");
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+3
-3
@@ -359,7 +359,7 @@ void override_entity_in_scope(Entity *original_entity, Entity *new_entity) {
|
||||
}
|
||||
if (original_entity->identifier != nullptr &&
|
||||
original_entity->identifier->kind == Ast_Ident) {
|
||||
original_entity->identifier->Ident.entity = new_entity;
|
||||
original_entity->identifier->Ident.entity = nullptr;
|
||||
}
|
||||
original_entity->flags |= EntityFlag_Overridden;
|
||||
|
||||
@@ -460,14 +460,14 @@ void check_const_decl(CheckerContext *ctx, Entity *e, Ast *type_expr, Ast *init,
|
||||
case Entity_LibraryName:
|
||||
case Entity_ImportName:
|
||||
{
|
||||
override_entity_in_scope(e, entity);
|
||||
|
||||
DeclInfo *decl = decl_info_of_entity(e);
|
||||
if (decl != nullptr) {
|
||||
if (decl->attributes.count > 0) {
|
||||
error(decl->attributes[0], "Constant alias declarations cannot have attributes");
|
||||
}
|
||||
}
|
||||
|
||||
override_entity_in_scope(e, entity);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2818
File diff suppressed because it is too large
Load Diff
+4
-7
@@ -217,7 +217,7 @@ bool check_is_terminating(Ast *node, String const &label) {
|
||||
}
|
||||
case_end;
|
||||
|
||||
case_ast_node(rs, InlineRangeStmt, node);
|
||||
case_ast_node(rs, UnrollRangeStmt, node);
|
||||
return false;
|
||||
case_end;
|
||||
|
||||
@@ -675,7 +675,7 @@ void add_constant_switch_case(CheckerContext *ctx, Map<TypeAndToken> *seen, Oper
|
||||
}
|
||||
|
||||
void check_inline_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
|
||||
ast_node(irs, InlineRangeStmt, node);
|
||||
ast_node(irs, UnrollRangeStmt, node);
|
||||
check_open_scope(ctx, node);
|
||||
|
||||
Type *val0 = nullptr;
|
||||
@@ -1303,7 +1303,7 @@ void check_block_stmt_for_errors(CheckerContext *ctx, Ast *body) {
|
||||
case Ast_IfStmt:
|
||||
case Ast_ForStmt:
|
||||
case Ast_RangeStmt:
|
||||
case Ast_InlineRangeStmt:
|
||||
case Ast_UnrollRangeStmt:
|
||||
case Ast_SwitchStmt:
|
||||
case Ast_TypeSwitchStmt:
|
||||
// TODO(bill): Is this a correct checking system?
|
||||
@@ -1795,9 +1795,6 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
|
||||
if (is_ptr) use_by_reference_for_value = true;
|
||||
array_add(&vals, t->Struct.soa_elem);
|
||||
array_add(&vals, t_int);
|
||||
if (!build_context.use_llvm_api) {
|
||||
error(operand.expr, "#soa structures do not yet support for in loop iteration");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1903,7 +1900,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
|
||||
check_close_scope(ctx);
|
||||
case_end;
|
||||
|
||||
case_ast_node(irs, InlineRangeStmt, node);
|
||||
case_ast_node(irs, UnrollRangeStmt, node);
|
||||
check_inline_range_stmt(ctx, node, mod_flags);
|
||||
case_end;
|
||||
|
||||
|
||||
@@ -1162,9 +1162,6 @@ Type *determine_type_from_polymorphic(CheckerContext *ctx, Type *poly_type, Oper
|
||||
}
|
||||
|
||||
if (is_polymorphic_type_assignable(ctx, poly_type, operand.type, false, modify_type)) {
|
||||
if (show_error) {
|
||||
set_procedure_abi_types(poly_type);
|
||||
}
|
||||
return poly_type;
|
||||
}
|
||||
if (show_error) {
|
||||
@@ -1767,623 +1764,8 @@ Type *check_get_results(CheckerContext *ctx, Scope *scope, Ast *_results) {
|
||||
return tuple;
|
||||
}
|
||||
|
||||
Array<Type *> systemv_distribute_struct_fields(Type *t) {
|
||||
Type *bt = core_type(t);
|
||||
|
||||
|
||||
isize distributed_cap = 1;
|
||||
if (bt->kind == Type_Struct) {
|
||||
distributed_cap = bt->Struct.fields.count;
|
||||
}
|
||||
auto distributed = array_make<Type *>(heap_allocator(), 0, distributed_cap);
|
||||
|
||||
i64 sz = type_size_of(bt);
|
||||
switch (bt->kind) {
|
||||
case Type_Basic:
|
||||
switch (bt->Basic.kind){
|
||||
case Basic_complex64:
|
||||
array_add(&distributed, t_f32);
|
||||
array_add(&distributed, t_f32);
|
||||
break;
|
||||
case Basic_complex128:
|
||||
array_add(&distributed, t_f64);
|
||||
array_add(&distributed, t_f64);
|
||||
break;
|
||||
case Basic_quaternion128:
|
||||
array_add(&distributed, t_f32);
|
||||
array_add(&distributed, t_f32);
|
||||
array_add(&distributed, t_f32);
|
||||
array_add(&distributed, t_f32);
|
||||
break;
|
||||
case Basic_quaternion256:
|
||||
goto DEFAULT;
|
||||
case Basic_string:
|
||||
array_add(&distributed, t_u8_ptr);
|
||||
array_add(&distributed, t_int);
|
||||
break;
|
||||
case Basic_any:
|
||||
GB_ASSERT(type_size_of(t_uintptr) == type_size_of(t_typeid));
|
||||
array_add(&distributed, t_rawptr);
|
||||
array_add(&distributed, t_uintptr);
|
||||
break;
|
||||
|
||||
case Basic_u128:
|
||||
case Basic_i128:
|
||||
if (build_context.ODIN_OS == "windows") {
|
||||
array_add(&distributed, alloc_type_simd_vector(2, t_u64));
|
||||
} else {
|
||||
array_add(&distributed, bt);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
goto DEFAULT;
|
||||
}
|
||||
break;
|
||||
|
||||
case Type_Struct:
|
||||
if (bt->Struct.is_raw_union) {
|
||||
goto DEFAULT;
|
||||
} else {
|
||||
// IMPORTANT TOOD(bill): handle #packed structs correctly
|
||||
// IMPORTANT TODO(bill): handle #align structs correctly
|
||||
for_array(field_index, bt->Struct.fields) {
|
||||
Entity *f = bt->Struct.fields[field_index];
|
||||
auto nested = systemv_distribute_struct_fields(f->type);
|
||||
array_add_elems(&distributed, nested.data, nested.count);
|
||||
array_free(&nested);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Type_Array:
|
||||
for (i64 i = 0; i < bt->Array.count; i++) {
|
||||
array_add(&distributed, bt->Array.elem);
|
||||
}
|
||||
break;
|
||||
|
||||
case Type_BitSet:
|
||||
array_add(&distributed, bit_set_to_int(bt));
|
||||
break;
|
||||
|
||||
case Type_Tuple:
|
||||
GB_PANIC("Invalid struct field type");
|
||||
break;
|
||||
|
||||
case Type_Slice:
|
||||
array_add(&distributed, t_rawptr);
|
||||
array_add(&distributed, t_int);
|
||||
break;
|
||||
|
||||
case Type_Union:
|
||||
case Type_DynamicArray:
|
||||
case Type_Map:
|
||||
// NOTE(bill, 2019-10-10): Odin specific, don't worry about C calling convention yet
|
||||
goto DEFAULT;
|
||||
|
||||
case Type_Pointer:
|
||||
case Type_Proc:
|
||||
case Type_SimdVector: // TODO(bill): Is this correct logic?
|
||||
default:
|
||||
DEFAULT:;
|
||||
if (sz > 0) {
|
||||
array_add(&distributed, bt);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return distributed;
|
||||
}
|
||||
|
||||
Type *struct_type_from_systemv_distribute_struct_fields(Type *abi_type) {
|
||||
GB_ASSERT(is_type_tuple(abi_type));
|
||||
Type *final_type = alloc_type_struct();
|
||||
final_type->Struct.fields = abi_type->Tuple.variables;
|
||||
return final_type;
|
||||
}
|
||||
|
||||
|
||||
Type *handle_single_distributed_type_parameter(Array<Type *> const &types, bool packed, isize *offset) {
|
||||
GB_ASSERT(types.count > 0);
|
||||
|
||||
if (types.count == 1) {
|
||||
if (offset) *offset = 1;
|
||||
|
||||
i64 sz = type_size_of(types[0]);
|
||||
|
||||
if (is_type_float(types[0])) {
|
||||
return types[0];
|
||||
}
|
||||
switch (sz) {
|
||||
case 0:
|
||||
GB_PANIC("Zero sized type found!");
|
||||
case 1: return t_u8;
|
||||
case 2: return t_u16;
|
||||
case 4: return t_u32;
|
||||
case 8: return t_u64;
|
||||
default:
|
||||
return types[0];
|
||||
}
|
||||
} else if (types.count >= 2) {
|
||||
if (types[0] == t_f32 && types[1] == t_f32) {
|
||||
if (offset) *offset = 2;
|
||||
return alloc_type_simd_vector(2, t_f32);
|
||||
} else if (type_size_of(types[0]) == 8) {
|
||||
if (offset) *offset = 1;
|
||||
return types[0];
|
||||
}
|
||||
|
||||
i64 total_size = 0;
|
||||
isize i = 0;
|
||||
if (packed) {
|
||||
for (; i < types.count && total_size < 8; i += 1) {
|
||||
Type *t = types[i];
|
||||
i64 s = type_size_of(t);
|
||||
total_size += s;
|
||||
}
|
||||
} else {
|
||||
for (; i < types.count && total_size < 8; i += 1) {
|
||||
Type *t = types[i];
|
||||
i64 s = gb_max(type_size_of(t), 0);
|
||||
i64 a = gb_max(type_align_of(t), 1);
|
||||
isize ts = align_formula(total_size, a);
|
||||
if (ts >= 8) {
|
||||
break;
|
||||
}
|
||||
total_size = ts + s;
|
||||
}
|
||||
}
|
||||
if (offset) *offset = i;
|
||||
switch (total_size) {
|
||||
case 1: return t_u8;
|
||||
case 2: return t_u16;
|
||||
case 4: return t_u32;
|
||||
case 8: return t_u64;
|
||||
}
|
||||
return t_u64;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Type *handle_struct_system_v_amd64_abi_type(Type *t) {
|
||||
if (type_size_of(t) > 16) {
|
||||
return alloc_type_pointer(t);
|
||||
}
|
||||
Type *original_type = t;
|
||||
Type *bt = core_type(t);
|
||||
t = base_type(t);
|
||||
i64 size = type_size_of(bt);
|
||||
|
||||
switch (t->kind) {
|
||||
case Type_Slice:
|
||||
case Type_Struct:
|
||||
break;
|
||||
|
||||
case Type_Basic:
|
||||
switch (bt->Basic.kind) {
|
||||
case Basic_string:
|
||||
case Basic_any:
|
||||
case Basic_complex64:
|
||||
case Basic_complex128:
|
||||
case Basic_quaternion128:
|
||||
break;
|
||||
default:
|
||||
return original_type;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return original_type;
|
||||
}
|
||||
|
||||
bool is_packed = false;
|
||||
if (is_type_struct(bt)) {
|
||||
is_packed = bt->Struct.is_packed;
|
||||
}
|
||||
|
||||
if (is_type_raw_union(bt)) {
|
||||
// TODO(bill): Handle raw union correctly for
|
||||
return t;
|
||||
} else {
|
||||
auto field_types = systemv_distribute_struct_fields(bt);
|
||||
defer (array_free(&field_types));
|
||||
|
||||
GB_ASSERT(field_types.count <= 16);
|
||||
|
||||
Type *final_type = nullptr;
|
||||
|
||||
if (field_types.count == 0) {
|
||||
final_type = t;
|
||||
} else if (field_types.count == 1) {
|
||||
final_type = field_types[0];
|
||||
} else {
|
||||
if (size <= 8) {
|
||||
isize offset = 0;
|
||||
final_type = handle_single_distributed_type_parameter(field_types, is_packed, &offset);
|
||||
} else {
|
||||
isize offset = 0;
|
||||
isize next_offset = 0;
|
||||
Type *two_types[2] = {};
|
||||
|
||||
two_types[0] = handle_single_distributed_type_parameter(field_types, is_packed, &offset);
|
||||
auto remaining = array_slice(field_types, offset, field_types.count);
|
||||
two_types[1] = handle_single_distributed_type_parameter(remaining, is_packed, &next_offset);
|
||||
GB_ASSERT(offset + next_offset == field_types.count);
|
||||
|
||||
auto variables = array_make<Entity *>(heap_allocator(), 2);
|
||||
variables[0] = alloc_entity_param(nullptr, empty_token, two_types[0], false, false);
|
||||
variables[1] = alloc_entity_param(nullptr, empty_token, two_types[1], false, false);
|
||||
final_type = alloc_type_tuple();
|
||||
final_type->Tuple.variables = variables;
|
||||
if (t->kind == Type_Struct) {
|
||||
// NOTE(bill): Make this packed
|
||||
final_type->Tuple.is_packed = t->Struct.is_packed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GB_ASSERT(final_type != nullptr);
|
||||
i64 ftsz = type_size_of(final_type);
|
||||
i64 otsz = type_size_of(original_type);
|
||||
if (ftsz != otsz) {
|
||||
// TODO(bill): Handle this case which will be caused by #packed most likely
|
||||
switch (otsz) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 4:
|
||||
case 8:
|
||||
GB_PANIC("Incorrectly handled case for handle_struct_system_v_amd64_abi_type, %s %lld vs %s %lld", type_to_string(final_type), ftsz, type_to_string(original_type), otsz);
|
||||
}
|
||||
}
|
||||
|
||||
return final_type;
|
||||
}
|
||||
}
|
||||
|
||||
Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type, ProcCallingConvention cc) {
|
||||
Type *new_type = original_type;
|
||||
|
||||
if (is_type_boolean(original_type)) {
|
||||
Type *t = core_type(base_type(new_type));
|
||||
if (t == t_bool) {
|
||||
return t_llvm_bool;
|
||||
}
|
||||
return new_type;
|
||||
}
|
||||
|
||||
if (is_type_proc(original_type)) {
|
||||
// NOTE(bill): Force a cast to prevent a possible type cycle
|
||||
return t_rawptr;
|
||||
}
|
||||
|
||||
if (is_calling_convention_none(cc)) {
|
||||
return new_type;
|
||||
}
|
||||
|
||||
if (build_context.ODIN_ARCH == "386") {
|
||||
return new_type;
|
||||
}
|
||||
|
||||
if (is_type_simd_vector(original_type)) {
|
||||
return new_type;
|
||||
}
|
||||
if (build_context.ODIN_ARCH == "amd64") {
|
||||
bool is_128 = is_type_integer_128bit(original_type);
|
||||
if (!is_128 && is_type_bit_set(original_type) && type_size_of(original_type) == 16) {
|
||||
// is_128 = true;
|
||||
}
|
||||
if (is_128) {
|
||||
if (build_context.ODIN_OS == "windows") {
|
||||
return alloc_type_simd_vector(2, t_u64);
|
||||
} else {
|
||||
return original_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (build_context.ODIN_OS == "windows") {
|
||||
// NOTE(bill): Changing the passing parameter value type is to match C's ABI
|
||||
// IMPORTANT TODO(bill): This only matches the ABI on MSVC at the moment
|
||||
// SEE: https://msdn.microsoft.com/en-us/library/zthk2dkh.aspx
|
||||
|
||||
|
||||
Type *bt = core_type(original_type);
|
||||
switch (bt->kind) {
|
||||
// Okay to pass by value (usually)
|
||||
// Especially the only Odin types
|
||||
case Type_Basic: {
|
||||
i64 sz = bt->Basic.size;
|
||||
// if (sz > 8 && build_context.word_size < 8) {
|
||||
if (sz > 8) {
|
||||
new_type = alloc_type_pointer(original_type);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Type_Pointer:
|
||||
if (is_type_struct(bt->Pointer.elem)) {
|
||||
// Force to a raw pointer
|
||||
new_type = t_rawptr;
|
||||
}
|
||||
break;
|
||||
case Type_Proc:
|
||||
new_type = t_rawptr;
|
||||
break; // NOTE(bill): Just a pointer
|
||||
|
||||
// Odin specific
|
||||
case Type_Slice:
|
||||
case Type_Array:
|
||||
case Type_DynamicArray:
|
||||
case Type_Map:
|
||||
case Type_Union:
|
||||
// Could be in C too
|
||||
case Type_Struct:
|
||||
{
|
||||
i64 align = type_align_of(original_type);
|
||||
i64 size = type_size_of(original_type);
|
||||
|
||||
switch (8*size) {
|
||||
case 8: new_type = t_u8; break;
|
||||
case 16: new_type = t_u16; break;
|
||||
case 32: new_type = t_u32; break;
|
||||
case 64: new_type = t_u64; break;
|
||||
default:
|
||||
new_type = alloc_type_pointer(original_type);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (build_context.ODIN_OS == "linux" ||
|
||||
build_context.ODIN_OS == "darwin") {
|
||||
Type *bt = core_type(original_type);
|
||||
switch (bt->kind) {
|
||||
// Okay to pass by value (usually)
|
||||
// Especially the only Odin types
|
||||
case Type_Basic: {
|
||||
i64 sz = bt->Basic.size;
|
||||
// if (sz > 8 && build_context.word_size < 8) {
|
||||
if (sz > 8) {
|
||||
new_type = alloc_type_pointer(original_type);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case Type_Pointer: break;
|
||||
case Type_Proc: break; // NOTE(bill): Just a pointer
|
||||
|
||||
default: {
|
||||
i64 size = type_size_of(original_type);
|
||||
if (size > 16) {
|
||||
new_type = alloc_type_pointer(original_type);
|
||||
} else if (build_context.ODIN_ARCH == "amd64") {
|
||||
// NOTE(bill): System V AMD64 ABI
|
||||
new_type = handle_struct_system_v_amd64_abi_type(bt);
|
||||
if (are_types_identical(core_type(original_type), new_type)) {
|
||||
new_type = original_type;
|
||||
}
|
||||
return new_type;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// IMPORTANT TODO(bill): figure out the ABI settings for Linux, OSX etc. for
|
||||
// their architectures
|
||||
}
|
||||
|
||||
return new_type;
|
||||
}
|
||||
|
||||
|
||||
Type *type_to_abi_compat_result_type(gbAllocator a, Type *original_type, ProcCallingConvention cc) {
|
||||
Type *new_type = original_type;
|
||||
if (new_type == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
GB_ASSERT(is_type_tuple(original_type));
|
||||
|
||||
Type *single_type = reduce_tuple_to_single_type(original_type);
|
||||
|
||||
if (cc == ProcCC_InlineAsm) {
|
||||
return new_type;
|
||||
}
|
||||
|
||||
if (is_type_proc(single_type)) {
|
||||
// NOTE(bill): Force a cast to prevent a possible type cycle
|
||||
return t_rawptr;
|
||||
}
|
||||
|
||||
if (is_type_simd_vector(single_type)) {
|
||||
return new_type;
|
||||
}
|
||||
|
||||
if (is_type_pointer(single_type)) {
|
||||
// NOTE(bill): Force a cast to prevent a possible type cycle
|
||||
return t_rawptr;
|
||||
}
|
||||
|
||||
if (build_context.ODIN_OS == "windows") {
|
||||
if (build_context.ODIN_ARCH == "amd64") {
|
||||
if (is_type_integer_128bit(single_type)) {
|
||||
if (is_calling_convention_none(cc)) {
|
||||
return original_type;
|
||||
} else {
|
||||
return alloc_type_simd_vector(2, t_u64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Type *bt = core_type(reduce_tuple_to_single_type(original_type));
|
||||
// NOTE(bill): This is just reversed engineered from LLVM IR output
|
||||
switch (bt->kind) {
|
||||
// Okay to pass by value
|
||||
// Especially the only Odin types
|
||||
case Type_Pointer: break;
|
||||
case Type_Proc: break; // NOTE(bill): Just a pointer
|
||||
case Type_Basic: break;
|
||||
|
||||
|
||||
default: {
|
||||
i64 align = type_align_of(original_type);
|
||||
i64 size = type_size_of(original_type);
|
||||
switch (8*size) {
|
||||
#if 1
|
||||
case 8: new_type = t_u8; break;
|
||||
case 16: new_type = t_u16; break;
|
||||
case 32: new_type = t_u32; break;
|
||||
case 64: new_type = t_u64; break;
|
||||
#endif
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (build_context.ODIN_OS == "linux" || build_context.ODIN_OS == "darwin") {
|
||||
if (build_context.ODIN_ARCH == "amd64") {
|
||||
|
||||
}
|
||||
} else {
|
||||
// IMPORTANT TODO(bill): figure out the ABI settings for Linux, OSX etc. for
|
||||
// their architectures
|
||||
}
|
||||
|
||||
if (is_type_integer_128bit(single_type)) {
|
||||
if (build_context.word_size == 8) {
|
||||
return original_type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (new_type != original_type) {
|
||||
Type *tuple = alloc_type_tuple();
|
||||
auto variables = array_make<Entity *>(a, 0, 1);
|
||||
array_add(&variables, alloc_entity_param(original_type->Tuple.variables[0]->scope, empty_token, new_type, false, false));
|
||||
tuple->Tuple.variables = variables;
|
||||
new_type = tuple;
|
||||
}
|
||||
|
||||
if (cc == ProcCC_None) {
|
||||
for_array(i, new_type->Tuple.variables) {
|
||||
Type **tp = &new_type->Tuple.variables[i]->type;
|
||||
Type *t = core_type(*tp);
|
||||
if (t == t_bool) {
|
||||
*tp = t_llvm_bool;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new_type->cached_size = -1;
|
||||
new_type->cached_align = -1;
|
||||
return new_type;
|
||||
}
|
||||
|
||||
bool abi_compat_return_by_pointer(gbAllocator a, ProcCallingConvention cc, Type *abi_return_type) {
|
||||
if (abi_return_type == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (is_calling_convention_none(cc)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Type *single_type = reduce_tuple_to_single_type(abi_return_type);
|
||||
|
||||
if (is_type_simd_vector(single_type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (build_context.word_size == 8) {
|
||||
if (is_type_integer_128bit(single_type)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (build_context.ODIN_OS == "windows" || build_context.ODIN_OS == "linux" ) {
|
||||
i64 size = 8*type_size_of(abi_return_type);
|
||||
switch (size) {
|
||||
case 0:
|
||||
case 8:
|
||||
case 16:
|
||||
case 32:
|
||||
case 64:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (is_type_integer_128bit(single_type)) {
|
||||
return build_context.word_size < 8;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void set_procedure_abi_types(Type *type) {
|
||||
type = base_type(type);
|
||||
if (type->kind != Type_Proc) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (type->Proc.abi_types_set || type->flags & TypeFlag_InProcessOfCheckingABI) {
|
||||
return;
|
||||
}
|
||||
|
||||
gbAllocator allocator = permanent_allocator();
|
||||
|
||||
u32 flags = type->flags;
|
||||
type->flags |= TypeFlag_InProcessOfCheckingABI;
|
||||
|
||||
type->Proc.abi_compat_params = array_make<Type *>(allocator, cast(isize)type->Proc.param_count);
|
||||
for (i32 i = 0; i < type->Proc.param_count; i++) {
|
||||
Entity *e = type->Proc.params->Tuple.variables[i];
|
||||
if (e->kind == Entity_Variable) {
|
||||
Type *original_type = e->type;
|
||||
Type *new_type = type_to_abi_compat_param_type(allocator, original_type, type->Proc.calling_convention);
|
||||
type->Proc.abi_compat_params[i] = new_type;
|
||||
switch (type->Proc.calling_convention) {
|
||||
case ProcCC_Odin:
|
||||
case ProcCC_Contextless:
|
||||
if (is_type_pointer(new_type) && !is_type_pointer(e->type) && !is_type_proc(e->type)) {
|
||||
e->flags |= EntityFlag_ImplicitReference;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (build_context.ODIN_OS == "linux" ||
|
||||
build_context.ODIN_OS == "darwin") {
|
||||
if (is_type_pointer(new_type) & !is_type_pointer(e->type) && !is_type_proc(e->type)) {
|
||||
e->flags |= EntityFlag_ByVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i32 i = 0; i < type->Proc.param_count; i++) {
|
||||
Entity *e = type->Proc.params->Tuple.variables[i];
|
||||
if (e->kind == Entity_Variable) {
|
||||
set_procedure_abi_types(e->type);
|
||||
}
|
||||
}
|
||||
for (i32 i = 0; i < type->Proc.result_count; i++) {
|
||||
Entity *e = type->Proc.results->Tuple.variables[i];
|
||||
if (e->kind == Entity_Variable) {
|
||||
set_procedure_abi_types(e->type);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE(bill): The types are the same
|
||||
type->Proc.abi_compat_result_type = type_to_abi_compat_result_type(allocator, type->Proc.results, type->Proc.calling_convention);
|
||||
type->Proc.return_by_pointer = abi_compat_return_by_pointer(allocator, type->Proc.calling_convention, type->Proc.abi_compat_result_type);
|
||||
|
||||
type->Proc.abi_types_set = true;
|
||||
type->flags = flags;
|
||||
}
|
||||
|
||||
// NOTE(bill): 'operands' is for generating non generic procedure type
|
||||
bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node, Array<Operand> *operands) {
|
||||
|
||||
+26
-26
@@ -732,15 +732,11 @@ void init_universal(void) {
|
||||
add_global_type_entity(str_lit("byte"), &basic_types[Basic_u8]);
|
||||
|
||||
{
|
||||
void set_procedure_abi_types(Type *type);
|
||||
|
||||
Type *equal_args[2] = {t_rawptr, t_rawptr};
|
||||
t_equal_proc = alloc_type_proc_from_types(equal_args, 2, t_bool, false, ProcCC_Contextless);
|
||||
set_procedure_abi_types(t_equal_proc);
|
||||
|
||||
Type *hasher_args[2] = {t_rawptr, t_uintptr};
|
||||
t_hasher_proc = alloc_type_proc_from_types(hasher_args, 2, t_uintptr, false, ProcCC_Contextless);
|
||||
set_procedure_abi_types(t_hasher_proc);
|
||||
}
|
||||
|
||||
// Constants
|
||||
@@ -759,7 +755,6 @@ void init_universal(void) {
|
||||
add_global_constant(str_lit("ODIN_DEBUG"), t_untyped_bool, exact_value_bool(bc->ODIN_DEBUG));
|
||||
add_global_constant(str_lit("ODIN_DISABLE_ASSERT"), t_untyped_bool, exact_value_bool(bc->ODIN_DISABLE_ASSERT));
|
||||
add_global_constant(str_lit("ODIN_DEFAULT_TO_NIL_ALLOCATOR"), t_untyped_bool, exact_value_bool(bc->ODIN_DEFAULT_TO_NIL_ALLOCATOR));
|
||||
add_global_constant(str_lit("ODIN_USE_LLVM_API"), t_untyped_bool, exact_value_bool(bc->use_llvm_api));
|
||||
add_global_constant(str_lit("ODIN_NO_DYNAMIC_LITERALS"), t_untyped_bool, exact_value_bool(bc->no_dynamic_literals));
|
||||
add_global_constant(str_lit("ODIN_TEST"), t_untyped_bool, exact_value_bool(bc->command_kind == Command_test));
|
||||
|
||||
@@ -1778,23 +1773,6 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) {
|
||||
force_add_dependency_entity(c, c->info.runtime_package->scope, required_runtime_entities[i]);
|
||||
}
|
||||
|
||||
if (!build_context.use_llvm_api) {
|
||||
String other_required_runtime_entities[] = {
|
||||
str_lit("bswap_16"),
|
||||
str_lit("bswap_32"),
|
||||
str_lit("bswap_64"),
|
||||
str_lit("bswap_128"),
|
||||
|
||||
str_lit("bswap_f16"),
|
||||
str_lit("bswap_f32"),
|
||||
str_lit("bswap_f64"),
|
||||
};
|
||||
|
||||
for (isize i = 0; i < gb_count_of(other_required_runtime_entities); i++) {
|
||||
force_add_dependency_entity(c, c->info.runtime_package->scope, other_required_runtime_entities[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (build_context.no_crt) {
|
||||
String required_no_crt_entities[] = {
|
||||
// NOTE(bill): Only if these exist
|
||||
@@ -2745,7 +2723,7 @@ DECL_ATTRIBUTE_PROC(type_decl_attribute) {
|
||||
}
|
||||
}
|
||||
|
||||
if (valid && build_context.use_llvm_api) {
|
||||
if (valid) {
|
||||
if (ac->atom_op_table == nullptr) {
|
||||
ac->atom_op_table = gb_alloc_item(permanent_allocator(), TypeAtomOpTable);
|
||||
}
|
||||
@@ -2804,7 +2782,7 @@ DECL_ATTRIBUTE_PROC(type_decl_attribute) {
|
||||
}
|
||||
}
|
||||
|
||||
if (valid && build_context.use_llvm_api) {
|
||||
if (valid) {
|
||||
if (ac->atom_op_table == nullptr) {
|
||||
ac->atom_op_table = gb_alloc_item(permanent_allocator(), TypeAtomOpTable);
|
||||
}
|
||||
@@ -2886,7 +2864,7 @@ DECL_ATTRIBUTE_PROC(type_decl_attribute) {
|
||||
}
|
||||
}
|
||||
|
||||
if (valid && build_context.use_llvm_api) {
|
||||
if (valid) {
|
||||
if (ac->atom_op_table == nullptr) {
|
||||
ac->atom_op_table = gb_alloc_item(permanent_allocator(), TypeAtomOpTable);
|
||||
}
|
||||
@@ -2903,6 +2881,7 @@ DECL_ATTRIBUTE_PROC(type_decl_attribute) {
|
||||
|
||||
|
||||
#include "check_expr.cpp"
|
||||
#include "check_builtin.cpp"
|
||||
#include "check_type.cpp"
|
||||
#include "check_decl.cpp"
|
||||
#include "check_stmt.cpp"
|
||||
@@ -3281,6 +3260,7 @@ void check_collect_value_decl(CheckerContext *c, Ast *decl) {
|
||||
d->type_expr = vd->type;
|
||||
d->init_expr = init;
|
||||
|
||||
|
||||
if (is_ast_type(init)) {
|
||||
e = alloc_entity_type_name(d->scope, token, nullptr);
|
||||
// if (vd->type != nullptr) {
|
||||
@@ -3747,6 +3727,19 @@ Array<ImportPathItem> find_import_path(Checker *c, AstPackage *start, AstPackage
|
||||
return empty_path;
|
||||
}
|
||||
#endif
|
||||
|
||||
String get_invalid_import_name(String input) {
|
||||
isize slash = 0;
|
||||
for (isize i = input.len-1; i >= 0; i--) {
|
||||
if (input[i] == '/' || input[i] == '\\') {
|
||||
break;
|
||||
}
|
||||
slash = i;
|
||||
}
|
||||
input = substring(input, slash, input.len);
|
||||
return input;
|
||||
}
|
||||
|
||||
void check_add_import_decl(CheckerContext *ctx, Ast *decl) {
|
||||
if (decl->state_flags & StateFlag_BeenHandled) return;
|
||||
decl->state_flags |= StateFlag_BeenHandled;
|
||||
@@ -3804,7 +3797,14 @@ void check_add_import_decl(CheckerContext *ctx, Ast *decl) {
|
||||
if (id->is_using) {
|
||||
// TODO(bill): Should this be a warning?
|
||||
} else {
|
||||
error(token, "Import name, %.*s, cannot be use as an import name as it is not a valid identifier", LIT(id->import_name.string));
|
||||
if (id->import_name.string == "") {
|
||||
String invalid_name = id->fullpath;
|
||||
invalid_name = get_invalid_import_name(invalid_name);
|
||||
|
||||
error(id->token, "Import name %.*s, is not a valid identifier. Perhaps you want to reference the package by a different name like this: import <new_name> \"%.*s\" ", LIT(invalid_name), LIT(invalid_name));
|
||||
} else {
|
||||
error(token, "Import name, %.*s, cannot be use as an import name as it is not a valid identifier", LIT(id->import_name.string));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
GB_ASSERT(id->import_name.pos.line != 0);
|
||||
|
||||
@@ -46,7 +46,9 @@ enum BuiltinProcId {
|
||||
BuiltinProc_read_cycle_counter,
|
||||
|
||||
BuiltinProc_count_ones,
|
||||
BuiltinProc_trailing_zeros,
|
||||
BuiltinProc_count_zeros,
|
||||
BuiltinProc_count_trailing_zeros,
|
||||
BuiltinProc_count_leading_zeros,
|
||||
BuiltinProc_reverse_bits,
|
||||
BuiltinProc_byte_swap,
|
||||
|
||||
@@ -263,10 +265,12 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
|
||||
{STR_LIT("debug_trap"), 0, false, Expr_Stmt, BuiltinProcPkg_intrinsics, /*diverging*/false},
|
||||
{STR_LIT("read_cycle_counter"), 0, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
{STR_LIT("count_ones"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("trailing_zeros"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("reverse_bits"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("byte_swap"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("count_ones"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("count_zeros"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("count_trailing_zeros"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("count_leading_zeros"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("reverse_bits"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("byte_swap"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
{STR_LIT("overflow_add"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("overflow_sub"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
@@ -167,7 +167,6 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) {
|
||||
#include "unicode.cpp"
|
||||
#include "array.cpp"
|
||||
#include "string.cpp"
|
||||
#include "murmurhash3.cpp"
|
||||
|
||||
#define for_array(index_, array_) for (isize index_ = 0; index_ < (array_).count; index_++)
|
||||
|
||||
|
||||
+42
@@ -2169,6 +2169,7 @@ GB_DEF f64 gb_random_range_f64 (gbRandom *r, f64 lower_inc, f64 higher_inc
|
||||
|
||||
GB_DEF void gb_exit (u32 code);
|
||||
GB_DEF void gb_yield (void);
|
||||
GB_DEF char const *gb_get_env (char const *name, gbAllocator allocator);
|
||||
GB_DEF void gb_set_env (char const *name, char const *value);
|
||||
GB_DEF void gb_unset_env(char const *name);
|
||||
|
||||
@@ -9174,6 +9175,47 @@ gb_inline void gb_yield(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
char const *gb_get_env(char const *name, gbAllocator allocator) {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
if (!name || !*name) {
|
||||
return NULL;
|
||||
} else {
|
||||
// TODO(bill): Should this be a Wide version?
|
||||
DWORD cap = 100;
|
||||
char *buf = gb_alloc_array(allocator, char, cap);
|
||||
for (;;) {
|
||||
DWORD n = GetEnvironmentVariableA(name, buf, cap-1);
|
||||
if (n == 0) {
|
||||
DWORD err = GetLastError();
|
||||
if (err == ERROR_ENVVAR_NOT_FOUND) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (n <= cap) {
|
||||
buf[n] = 0;
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
buf = cast(char *)gb_resize(allocator, buf, gb_size_of(char)*cap, gb_size_of(char)*cap*2);
|
||||
cap = cap*2;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (!name || !*name) {
|
||||
return NULL;
|
||||
} else {
|
||||
char const *res = getenv(name);
|
||||
if (!res) {
|
||||
return NULL;
|
||||
}
|
||||
return gb_alloc_str(allocator, res);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
gb_inline void gb_set_env(char const *name, char const *value) {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
// TODO(bill): Should this be a Wide version?
|
||||
|
||||
-13167
File diff suppressed because it is too large
Load Diff
-495
@@ -1,495 +0,0 @@
|
||||
// Optimizations for the IR code
|
||||
|
||||
void ir_opt_add_operands(Array<irValue *> *ops, irInstr *i) {
|
||||
switch (i->kind) {
|
||||
case irInstr_Comment:
|
||||
break;
|
||||
case irInstr_Local:
|
||||
break;
|
||||
case irInstr_ZeroInit:
|
||||
array_add(ops, i->ZeroInit.address);
|
||||
break;
|
||||
case irInstr_Store:
|
||||
array_add(ops, i->Store.address);
|
||||
array_add(ops, i->Store.value);
|
||||
break;
|
||||
case irInstr_Load:
|
||||
array_add(ops, i->Load.address);
|
||||
break;
|
||||
case irInstr_ArrayElementPtr:
|
||||
array_add(ops, i->ArrayElementPtr.address);
|
||||
array_add(ops, i->ArrayElementPtr.elem_index);
|
||||
break;
|
||||
case irInstr_StructElementPtr:
|
||||
array_add(ops, i->StructElementPtr.address);
|
||||
break;
|
||||
case irInstr_PtrOffset:
|
||||
array_add(ops, i->PtrOffset.address);
|
||||
array_add(ops, i->PtrOffset.offset);
|
||||
break;
|
||||
case irInstr_StructExtractValue:
|
||||
array_add(ops, i->StructExtractValue.address);
|
||||
break;
|
||||
case irInstr_Conv:
|
||||
array_add(ops, i->Conv.value);
|
||||
break;
|
||||
case irInstr_Jump:
|
||||
break;
|
||||
case irInstr_If:
|
||||
array_add(ops, i->If.cond);
|
||||
break;
|
||||
case irInstr_Return:
|
||||
if (i->Return.value != nullptr) {
|
||||
array_add(ops, i->Return.value);
|
||||
}
|
||||
break;
|
||||
case irInstr_Select:
|
||||
array_add(ops, i->Select.cond);
|
||||
break;
|
||||
case irInstr_Phi:
|
||||
for_array(j, i->Phi.edges) {
|
||||
array_add(ops, i->Phi.edges[j]);
|
||||
}
|
||||
break;
|
||||
case irInstr_Unreachable:
|
||||
break;
|
||||
case irInstr_UnaryOp:
|
||||
array_add(ops, i->UnaryOp.expr);
|
||||
break;
|
||||
case irInstr_BinaryOp:
|
||||
array_add(ops, i->BinaryOp.left);
|
||||
array_add(ops, i->BinaryOp.right);
|
||||
break;
|
||||
case irInstr_Call:
|
||||
array_add(ops, i->Call.value);
|
||||
for_array(j, i->Call.args) {
|
||||
array_add(ops, i->Call.args[j]);
|
||||
}
|
||||
break;
|
||||
// case irInstr_VectorExtractElement:
|
||||
// array_add(ops, i->VectorExtractElement.vector);
|
||||
// array_add(ops, i->VectorExtractElement.index);
|
||||
// break;
|
||||
// case irInstr_VectorInsertElement:
|
||||
// array_add(ops, i->VectorInsertElement.vector);
|
||||
// array_add(ops, i->VectorInsertElement.elem);
|
||||
// array_add(ops, i->VectorInsertElement.index);
|
||||
// break;
|
||||
// case irInstr_VectorShuffle:
|
||||
// array_add(ops, i->VectorShuffle.vector);
|
||||
// break;
|
||||
case irInstr_StartupRuntime:
|
||||
break;
|
||||
|
||||
#if 0
|
||||
case irInstr_BoundsCheck:
|
||||
array_add(ops, i->BoundsCheck.index);
|
||||
array_add(ops, i->BoundsCheck.len);
|
||||
break;
|
||||
case irInstr_SliceBoundsCheck:
|
||||
array_add(ops, i->SliceBoundsCheck.low);
|
||||
array_add(ops, i->SliceBoundsCheck.high);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void ir_opt_block_replace_pred(irBlock *b, irBlock *from, irBlock *to) {
|
||||
for_array(i, b->preds) {
|
||||
irBlock *pred = b->preds[i];
|
||||
if (pred == from) {
|
||||
b->preds[i] = to;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ir_opt_block_replace_succ(irBlock *b, irBlock *from, irBlock *to) {
|
||||
for_array(i, b->succs) {
|
||||
irBlock *succ = b->succs[i];
|
||||
if (succ == from) {
|
||||
b->succs[i] = to;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ir_opt_block_has_phi(irBlock *b) {
|
||||
return b->instrs[0]->Instr.kind == irInstr_Phi;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Array<irValue *> ir_get_block_phi_nodes(irBlock *b) {
|
||||
Array<irValue *> phis = {0};
|
||||
for_array(i, b->instrs) {
|
||||
irInstr *instr = &b->instrs[i]->Instr;
|
||||
if (instr->kind != irInstr_Phi) {
|
||||
phis = b->instrs;
|
||||
phis.count = i;
|
||||
return phis;
|
||||
}
|
||||
}
|
||||
return phis;
|
||||
}
|
||||
|
||||
void ir_remove_pred(irBlock *b, irBlock *p) {
|
||||
Array<irValue *> phis = ir_get_block_phi_nodes(b);
|
||||
isize i = 0;
|
||||
for_array(j, b->preds) {
|
||||
irBlock *pred = b->preds[j];
|
||||
if (pred != p) {
|
||||
b->preds[i] = b->preds[j];
|
||||
for_array(k, phis) {
|
||||
irInstrPhi *phi = &phis[k]->Instr.Phi;
|
||||
phi->edges[i] = phi->edges[j];
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
b->preds.count = i;
|
||||
for_array(k, phis) {
|
||||
irInstrPhi *phi = &phis[k]->Instr.Phi;
|
||||
phi->edges.count = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ir_remove_dead_blocks(irProcedure *proc) {
|
||||
isize j = 0;
|
||||
for_array(i, proc->blocks) {
|
||||
irBlock *b = proc->blocks[i];
|
||||
if (b == nullptr) {
|
||||
continue;
|
||||
}
|
||||
// NOTE(bill): Swap order
|
||||
b->index = cast(i32)j;
|
||||
proc->blocks[j++] = b;
|
||||
}
|
||||
proc->blocks.count = j;
|
||||
}
|
||||
|
||||
void ir_mark_reachable(irBlock *b) {
|
||||
isize const WHITE = 0;
|
||||
isize const BLACK = -1;
|
||||
b->index = BLACK;
|
||||
for_array(i, b->succs) {
|
||||
irBlock *succ = b->succs[i];
|
||||
if (succ->index == WHITE) {
|
||||
ir_mark_reachable(succ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ir_remove_unreachable_blocks(irProcedure *proc) {
|
||||
isize const WHITE = 0;
|
||||
isize const BLACK = -1;
|
||||
for_array(i, proc->blocks) {
|
||||
proc->blocks[i]->index = WHITE;
|
||||
}
|
||||
|
||||
ir_mark_reachable(proc->blocks[0]);
|
||||
|
||||
for_array(i, proc->blocks) {
|
||||
irBlock *b = proc->blocks[i];
|
||||
if (b->index == WHITE) {
|
||||
for_array(j, b->succs) {
|
||||
irBlock *c = b->succs[j];
|
||||
if (c->index == BLACK) {
|
||||
ir_remove_pred(c, b);
|
||||
}
|
||||
}
|
||||
// NOTE(bill): Mark as empty but don't actually free it
|
||||
// As it's been allocated with an arena
|
||||
proc->blocks[i] = nullptr;
|
||||
}
|
||||
}
|
||||
ir_remove_dead_blocks(proc);
|
||||
}
|
||||
|
||||
bool ir_opt_block_fusion(irProcedure *proc, irBlock *a) {
|
||||
if (a->succs.count != 1) {
|
||||
return false;
|
||||
}
|
||||
irBlock *b = a->succs[0];
|
||||
if (b->preds.count != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ir_opt_block_has_phi(b)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
array_pop(&a->instrs); // Remove branch at end
|
||||
for_array(i, b->instrs) {
|
||||
array_add(&a->instrs, b->instrs[i]);
|
||||
ir_set_instr_block(b->instrs[i], a);
|
||||
}
|
||||
|
||||
array_clear(&a->succs);
|
||||
for_array(i, b->succs) {
|
||||
array_add(&a->succs, b->succs[i]);
|
||||
}
|
||||
|
||||
// Fix preds links
|
||||
for_array(i, b->succs) {
|
||||
ir_opt_block_replace_pred(b->succs[i], b, a);
|
||||
}
|
||||
|
||||
proc->blocks[b->index] = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ir_opt_blocks(irProcedure *proc) {
|
||||
ir_remove_unreachable_blocks(proc);
|
||||
|
||||
#if 1
|
||||
bool changed = true;
|
||||
while (changed) {
|
||||
changed = false;
|
||||
for_array(i, proc->blocks) {
|
||||
irBlock *b = proc->blocks[i];
|
||||
if (b == nullptr) {
|
||||
continue;
|
||||
}
|
||||
GB_ASSERT_MSG(b->index == i, "%d, %td", b->index, i);
|
||||
|
||||
if (ir_opt_block_fusion(proc, b)) {
|
||||
changed = true;
|
||||
}
|
||||
// TODO(bill): other simple block optimizations
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
ir_remove_dead_blocks(proc);
|
||||
}
|
||||
void ir_opt_build_referrers(irProcedure *proc) {
|
||||
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&proc->module->tmp_arena);
|
||||
|
||||
// NOTE(bill): Acta as a buffer
|
||||
auto ops = array_make<irValue *>(proc->module->tmp_allocator, 0, 64); // TODO HACK(bill): This _could_ overflow the temp arena
|
||||
for_array(i, proc->blocks) {
|
||||
irBlock *b = proc->blocks[i];
|
||||
for_array(j, b->instrs) {
|
||||
irValue *instr = b->instrs[j];
|
||||
array_clear(&ops);
|
||||
ir_opt_add_operands(&ops, &instr->Instr);
|
||||
|
||||
for_array(k, ops) {
|
||||
irValue *op = ops[k];
|
||||
if (op == nullptr) {
|
||||
continue;
|
||||
}
|
||||
Array<irValue *> *refs = ir_value_referrers(op);
|
||||
if (refs != nullptr) {
|
||||
array_add(refs, instr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gb_temp_arena_memory_end(tmp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// State of Lengauer-Tarjan algorithm
|
||||
// Based on this paper: http://jgaa.info/accepted/2006/GeorgiadisTarjanWerneck2006.10.1.pdf
|
||||
typedef struct irLTState {
|
||||
isize count;
|
||||
// NOTE(bill): These are arrays
|
||||
irBlock **sdom; // Semidominator
|
||||
irBlock **parent; // Parent in DFS traversal of CFG
|
||||
irBlock **ancestor;
|
||||
} irLTState;
|
||||
|
||||
// §2.2 - bottom of page
|
||||
void ir_lt_link(irLTState *lt, irBlock *p, irBlock *q) {
|
||||
lt->ancestor[q->index] = p;
|
||||
}
|
||||
|
||||
i32 ir_lt_depth_first_search(irLTState *lt, irBlock *p, i32 i, irBlock **preorder) {
|
||||
preorder[i] = p;
|
||||
p->dom.pre = i++;
|
||||
lt->sdom[p->index] = p;
|
||||
ir_lt_link(lt, nullptr, p);
|
||||
for_array(index, p->succs) {
|
||||
irBlock *q = p->succs[index];
|
||||
if (lt->sdom[q->index] == nullptr) {
|
||||
lt->parent[q->index] = p;
|
||||
i = ir_lt_depth_first_search(lt, q, i, preorder);
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
irBlock *ir_lt_eval(irLTState *lt, irBlock *v) {
|
||||
irBlock *u = v;
|
||||
for (;
|
||||
lt->ancestor[v->index] != nullptr;
|
||||
v = lt->ancestor[v->index]) {
|
||||
if (lt->sdom[v->index]->dom.pre < lt->sdom[u->index]->dom.pre) {
|
||||
u = v;
|
||||
}
|
||||
}
|
||||
return u;
|
||||
}
|
||||
|
||||
typedef struct irDomPrePost {
|
||||
i32 pre, post;
|
||||
} irDomPrePost;
|
||||
|
||||
irDomPrePost ir_opt_number_dom_tree(irBlock *v, i32 pre, i32 post) {
|
||||
irDomPrePost result = {pre, post};
|
||||
|
||||
v->dom.pre = pre++;
|
||||
for_array(i, v->dom.children) {
|
||||
result = ir_opt_number_dom_tree(v->dom.children[i], result.pre, result.post);
|
||||
}
|
||||
v->dom.post = post++;
|
||||
|
||||
result.pre = pre;
|
||||
result.post = post;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// NOTE(bill): Requires `ir_opt_blocks` to be called before this
|
||||
void ir_opt_build_dom_tree(irProcedure *proc) {
|
||||
// Based on this paper: http://jgaa.info/accepted/2006/GeorgiadisTarjanWerneck2006.10.1.pdf
|
||||
|
||||
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&proc->module->tmp_arena);
|
||||
|
||||
i32 n = cast(i32)proc->blocks.count;
|
||||
irBlock **buf = gb_alloc_array(proc->module->tmp_allocator, irBlock *, 5*n);
|
||||
|
||||
irLTState lt = {0};
|
||||
lt.count = n;
|
||||
lt.sdom = &buf[0*n];
|
||||
lt.parent = &buf[1*n];
|
||||
lt.ancestor = &buf[2*n];
|
||||
|
||||
irBlock **preorder = &buf[3*n];
|
||||
irBlock **buckets = &buf[4*n];
|
||||
irBlock *root = proc->blocks[0];
|
||||
|
||||
// Step 1 - number vertices
|
||||
i32 pre_num = ir_lt_depth_first_search(<, root, 0, preorder);
|
||||
gb_memmove(buckets, preorder, n*gb_size_of(preorder[0]));
|
||||
|
||||
for (i32 i = n-1; i > 0; i--) {
|
||||
irBlock *w = preorder[i];
|
||||
|
||||
// Step 3 - Implicitly define idom for nodes
|
||||
for (irBlock *v = buckets[i]; v != w; v = buckets[v->dom.pre]) {
|
||||
irBlock *u = ir_lt_eval(<, v);
|
||||
if (lt.sdom[u->index]->dom.pre < i) {
|
||||
v->dom.idom = u;
|
||||
} else {
|
||||
v->dom.idom = w;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2 - Compute all sdoms
|
||||
lt.sdom[w->index] = lt.parent[w->index];
|
||||
for_array(pred_index, w->preds) {
|
||||
irBlock *v = w->preds[pred_index];
|
||||
irBlock *u = ir_lt_eval(<, v);
|
||||
if (lt.sdom[u->index]->dom.pre < lt.sdom[w->index]->dom.pre) {
|
||||
lt.sdom[w->index] = lt.sdom[u->index];
|
||||
}
|
||||
}
|
||||
|
||||
ir_lt_link(<, lt.parent[w->index], w);
|
||||
|
||||
if (lt.parent[w->index] == lt.sdom[w->index]) {
|
||||
w->dom.idom = lt.parent[w->index];
|
||||
} else {
|
||||
buckets[i] = buckets[lt.sdom[w->index]->dom.pre];
|
||||
buckets[lt.sdom[w->index]->dom.pre] = w;
|
||||
}
|
||||
}
|
||||
|
||||
// The rest of Step 3
|
||||
for (irBlock *v = buckets[0]; v != root; v = buckets[v->dom.pre]) {
|
||||
v->dom.idom = root;
|
||||
}
|
||||
|
||||
// Step 4 - Explicitly define idom for nodes (in preorder)
|
||||
for (isize i = 1; i < n; i++) {
|
||||
irBlock *w = preorder[i];
|
||||
if (w == root) {
|
||||
w->dom.idom = nullptr;
|
||||
} else {
|
||||
// Weird tree relationships here!
|
||||
|
||||
if (w->dom.idom != lt.sdom[w->index]) {
|
||||
w->dom.idom = w->dom.idom->dom.idom;
|
||||
}
|
||||
|
||||
// Calculate children relation as inverse of idom
|
||||
if (w->dom.idom->dom.children.data == nullptr) {
|
||||
// TODO(bill): Is this good enough for memory allocations?
|
||||
array_init(&w->dom.idom->dom.children, heap_allocator());
|
||||
}
|
||||
array_add(&w->dom.idom->dom.children, w);
|
||||
}
|
||||
}
|
||||
|
||||
ir_opt_number_dom_tree(root, 0, 0);
|
||||
|
||||
gb_temp_arena_memory_end(tmp);
|
||||
}
|
||||
|
||||
void ir_opt_mem2reg(irProcedure *proc) {
|
||||
// TODO(bill): ir_opt_mem2reg
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ir_opt_tree(irGen *s) {
|
||||
s->opt_called = true;
|
||||
|
||||
for_array(member_index, s->module.procs) {
|
||||
irProcedure *proc = s->module.procs[member_index];
|
||||
if (proc->blocks.count == 0) { // Prototype/external procedure
|
||||
continue;
|
||||
}
|
||||
|
||||
ir_opt_blocks(proc);
|
||||
#if 0
|
||||
ir_opt_build_referrers(proc);
|
||||
ir_opt_build_dom_tree(proc);
|
||||
|
||||
// TODO(bill): ir optimization
|
||||
// [ ] cse (common-subexpression) elim
|
||||
// [ ] copy elim
|
||||
// [ ] dead code elim
|
||||
// [ ] dead store/load elim
|
||||
// [ ] phi elim
|
||||
// [ ] short circuit elim
|
||||
// [ ] bounds check elim
|
||||
// [ ] lift/mem2reg
|
||||
// [ ] lift/mem2reg
|
||||
|
||||
ir_opt_mem2reg(proc);
|
||||
#endif
|
||||
|
||||
GB_ASSERT(proc->blocks.count > 0);
|
||||
ir_number_proc_registers(proc);
|
||||
}
|
||||
}
|
||||
-3092
File diff suppressed because it is too large
Load Diff
+139
-63
@@ -2323,7 +2323,7 @@ void lb_debug_complete_types(lbModule *m) {
|
||||
for (unsigned i = 0; i < element_count; i++) {
|
||||
u64 offset_in_bits = i;
|
||||
i64 val = bt->BitSet.lower + cast(i64)i;
|
||||
gb_snprintf(name, gb_count_of(name), "%lld", val);
|
||||
gb_snprintf(name, gb_count_of(name), "%lld", cast(long long)val);
|
||||
elements[i] = LLVMDIBuilderCreateBitFieldMemberType(
|
||||
m->debug_builder,
|
||||
scope,
|
||||
@@ -2545,8 +2545,6 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity) {
|
||||
Type *pt = base_type(entity->type);
|
||||
GB_ASSERT(pt->kind == Type_Proc);
|
||||
|
||||
set_procedure_abi_types(entity->type);
|
||||
|
||||
p->type = entity->type;
|
||||
p->type_expr = decl->type_expr;
|
||||
p->body = pl->body;
|
||||
@@ -2845,6 +2843,14 @@ lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbP
|
||||
return res;
|
||||
}
|
||||
|
||||
Type *struct_type_from_systemv_distribute_struct_fields(Type *abi_type) {
|
||||
GB_ASSERT(is_type_tuple(abi_type));
|
||||
Type *final_type = alloc_type_struct();
|
||||
final_type->Struct.fields = abi_type->Tuple.variables;
|
||||
return final_type;
|
||||
}
|
||||
|
||||
|
||||
lbValue lb_add_param(lbProcedure *p, Entity *e, Ast *expr, Type *abi_type, i32 index) {
|
||||
lbParamPasskind kind = lbParamPass_Value;
|
||||
lbValue v = lb_value_param(p, e, abi_type, index, &kind);
|
||||
@@ -3282,7 +3288,7 @@ void lb_end_procedure_body(lbProcedure *p) {
|
||||
// Make sure every block terminates, and if not, make it unreachable
|
||||
for (block = first_block; block != nullptr; block = LLVMGetNextBasicBlock(block)) {
|
||||
LLVMValueRef instr = LLVMGetLastInstruction(block);
|
||||
if (instr == nullptr) {
|
||||
if (instr == nullptr || !lb_is_instr_terminating(instr)) {
|
||||
LLVMPositionBuilderAtEnd(p->builder, block);
|
||||
LLVMBuildUnreachable(p->builder);
|
||||
}
|
||||
@@ -3476,9 +3482,6 @@ void lb_build_nested_proc(lbProcedure *p, AstProcLit *pd, Entity *e) {
|
||||
name_len = gb_snprintf(name_text, name_len, "%.*s.%.*s-%d", LIT(p->name), LIT(pd_name), guid);
|
||||
String name = make_string(cast(u8 *)name_text, name_len-1);
|
||||
|
||||
set_procedure_abi_types(e->type);
|
||||
|
||||
|
||||
e->Procedure.link_name = name;
|
||||
|
||||
lbProcedure *nested_proc = lb_create_procedure(p->module, e);
|
||||
@@ -3541,7 +3544,9 @@ void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) {
|
||||
Ast *ident = vd->names[i];
|
||||
GB_ASSERT(ident->kind == Ast_Ident);
|
||||
Entity *e = entity_of_node(ident);
|
||||
GB_ASSERT(e != nullptr);
|
||||
if (e == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (e->kind != Entity_TypeName) {
|
||||
continue;
|
||||
}
|
||||
@@ -3570,7 +3575,9 @@ void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) {
|
||||
Ast *ident = vd->names[i];
|
||||
GB_ASSERT(ident->kind == Ast_Ident);
|
||||
Entity *e = entity_of_node(ident);
|
||||
GB_ASSERT(e != nullptr);
|
||||
if (e == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (e->kind != Entity_Procedure) {
|
||||
continue;
|
||||
}
|
||||
@@ -3613,7 +3620,6 @@ void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) {
|
||||
return;
|
||||
}
|
||||
|
||||
set_procedure_abi_types(e->type);
|
||||
e->Procedure.link_name = name;
|
||||
|
||||
lbProcedure *nested_proc = lb_create_procedure(p->module, e);
|
||||
@@ -4295,7 +4301,7 @@ void lb_build_range_stmt(lbProcedure *p, AstRangeStmt *rs, Scope *scope) {
|
||||
lb_start_block(p, done);
|
||||
}
|
||||
|
||||
void lb_build_inline_range_stmt(lbProcedure *p, AstInlineRangeStmt *rs, Scope *scope) {
|
||||
void lb_build_inline_range_stmt(lbProcedure *p, AstUnrollRangeStmt *rs, Scope *scope) {
|
||||
lbModule *m = p->module;
|
||||
|
||||
lb_open_scope(p, scope); // Open scope here
|
||||
@@ -4641,9 +4647,13 @@ void lb_build_type_switch_stmt(lbProcedure *p, AstTypeSwitchStmt *ss) {
|
||||
lbValue tag_index = {};
|
||||
lbValue union_data = {};
|
||||
if (switch_kind == TypeSwitch_Union) {
|
||||
lbValue tag_ptr = lb_emit_union_tag_ptr(p, parent_ptr);
|
||||
tag_index = lb_emit_load(p, tag_ptr);
|
||||
union_data = lb_emit_conv(p, parent_ptr, t_rawptr);
|
||||
if (is_type_union_maybe_pointer(type_deref(parent_ptr.type))) {
|
||||
tag_index = lb_emit_conv(p, lb_emit_comp_against_nil(p, Token_NotEq, union_data), t_int);
|
||||
} else {
|
||||
lbValue tag_ptr = lb_emit_union_tag_ptr(p, parent_ptr);
|
||||
tag_index = lb_emit_load(p, tag_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
lbBlock *start_block = lb_create_block(p, "typeswitch.case.first");
|
||||
@@ -5288,7 +5298,7 @@ void lb_build_stmt(lbProcedure *p, Ast *node) {
|
||||
lb_build_range_stmt(p, rs, node->scope);
|
||||
case_end;
|
||||
|
||||
case_ast_node(rs, InlineRangeStmt, node);
|
||||
case_ast_node(rs, UnrollRangeStmt, node);
|
||||
lb_build_inline_range_stmt(p, rs, node->scope);
|
||||
case_end;
|
||||
|
||||
@@ -8197,8 +8207,6 @@ lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> const &args,
|
||||
LLVMBuildUnreachable(p->builder);
|
||||
});
|
||||
|
||||
set_procedure_abi_types(pt);
|
||||
|
||||
bool is_c_vararg = pt->Proc.c_vararg;
|
||||
isize param_count = pt->Proc.param_count;
|
||||
if (is_c_vararg) {
|
||||
@@ -9102,51 +9110,18 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
|
||||
return res;
|
||||
}
|
||||
|
||||
case BuiltinProc_trailing_zeros:
|
||||
{
|
||||
lbValue x = lb_build_expr(p, ce->args[0]);
|
||||
x = lb_emit_conv(p, x, tv.type);
|
||||
|
||||
char const *name = "llvm.cttz";
|
||||
LLVMTypeRef types[1] = {lb_type(p->module, tv.type)};
|
||||
unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name));
|
||||
GB_ASSERT_MSG(id != 0, "Unable to find %s.%s", name, LLVMPrintTypeToString(types[0]));
|
||||
LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, types, gb_count_of(types));
|
||||
|
||||
LLVMValueRef args[2] = {};
|
||||
args[0] = x.value;
|
||||
args[1] = LLVMConstNull(LLVMInt1TypeInContext(p->module->ctx));
|
||||
|
||||
lbValue res = {};
|
||||
res.value = LLVMBuildCall(p->builder, ip, args, gb_count_of(args), "");
|
||||
res.type = tv.type;
|
||||
return res;
|
||||
}
|
||||
case BuiltinProc_count_trailing_zeros:
|
||||
return lb_emit_count_trailing_zeros(p, lb_build_expr(p, ce->args[0]), tv.type);
|
||||
case BuiltinProc_count_leading_zeros:
|
||||
return lb_emit_count_leading_zeros(p, lb_build_expr(p, ce->args[0]), tv.type);
|
||||
|
||||
case BuiltinProc_count_ones:
|
||||
return lb_emit_count_ones(p, lb_build_expr(p, ce->args[0]), tv.type);
|
||||
case BuiltinProc_count_zeros:
|
||||
return lb_emit_count_zeros(p, lb_build_expr(p, ce->args[0]), tv.type);
|
||||
|
||||
case BuiltinProc_reverse_bits:
|
||||
{
|
||||
lbValue x = lb_build_expr(p, ce->args[0]);
|
||||
x = lb_emit_conv(p, x, tv.type);
|
||||
|
||||
char const *name = nullptr;
|
||||
switch (id) {
|
||||
case BuiltinProc_count_ones: name = "llvm.ctpop"; break;
|
||||
case BuiltinProc_reverse_bits: name = "llvm.bitreverse"; break;
|
||||
}
|
||||
LLVMTypeRef types[1] = {lb_type(p->module, tv.type)};
|
||||
unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name));
|
||||
GB_ASSERT_MSG(id != 0, "Unable to find %s.%s", name, LLVMPrintTypeToString(types[0]));
|
||||
LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, types, gb_count_of(types));
|
||||
|
||||
LLVMValueRef args[1] = {};
|
||||
args[0] = x.value;
|
||||
|
||||
lbValue res = {};
|
||||
res.value = LLVMBuildCall(p->builder, ip, args, gb_count_of(args), "");
|
||||
res.type = tv.type;
|
||||
return res;
|
||||
}
|
||||
return lb_emit_reverse_bits(p, lb_build_expr(p, ce->args[0]), tv.type);
|
||||
|
||||
case BuiltinProc_byte_swap:
|
||||
{
|
||||
@@ -9617,7 +9592,6 @@ lbValue lb_build_call_expr(lbProcedure *p, Ast *expr) {
|
||||
Type *proc_type_ = base_type(value.type);
|
||||
GB_ASSERT(proc_type_->kind == Type_Proc);
|
||||
TypeProc *pt = &proc_type_->Proc;
|
||||
set_procedure_abi_types(proc_type_);
|
||||
|
||||
if (is_call_expr_field_value(ce)) {
|
||||
auto args = array_make<lbValue>(permanent_allocator(), pt->param_count);
|
||||
@@ -9985,6 +9959,100 @@ lbValue lb_emit_byte_swap(lbProcedure *p, lbValue value, Type *end_type) {
|
||||
}
|
||||
|
||||
|
||||
lbValue lb_emit_count_ones(lbProcedure *p, lbValue x, Type *type) {
|
||||
x = lb_emit_conv(p, x, type);
|
||||
|
||||
char const *name = "llvm.ctpop";
|
||||
LLVMTypeRef types[1] = {lb_type(p->module, type)};
|
||||
unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name));
|
||||
GB_ASSERT_MSG(id != 0, "Unable to find %s.%s", name, LLVMPrintTypeToString(types[0]));
|
||||
LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, types, gb_count_of(types));
|
||||
|
||||
LLVMValueRef args[1] = {};
|
||||
args[0] = x.value;
|
||||
|
||||
lbValue res = {};
|
||||
res.value = LLVMBuildCall(p->builder, ip, args, gb_count_of(args), "");
|
||||
res.type = type;
|
||||
return res;
|
||||
}
|
||||
|
||||
lbValue lb_emit_count_zeros(lbProcedure *p, lbValue x, Type *type) {
|
||||
i64 sz = 8*type_size_of(type);
|
||||
lbValue size = lb_const_int(p->module, type, cast(u64)sz);
|
||||
lbValue count = lb_emit_count_ones(p, x, type);
|
||||
return lb_emit_arith(p, Token_Sub, size, count, type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
lbValue lb_emit_count_trailing_zeros(lbProcedure *p, lbValue x, Type *type) {
|
||||
x = lb_emit_conv(p, x, type);
|
||||
|
||||
char const *name = "llvm.cttz";
|
||||
LLVMTypeRef types[1] = {lb_type(p->module, type)};
|
||||
unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name));
|
||||
GB_ASSERT_MSG(id != 0, "Unable to find %s.%s", name, LLVMPrintTypeToString(types[0]));
|
||||
LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, types, gb_count_of(types));
|
||||
|
||||
LLVMValueRef args[2] = {};
|
||||
args[0] = x.value;
|
||||
args[1] = LLVMConstNull(LLVMInt1TypeInContext(p->module->ctx));
|
||||
|
||||
lbValue res = {};
|
||||
res.value = LLVMBuildCall(p->builder, ip, args, gb_count_of(args), "");
|
||||
res.type = type;
|
||||
return res;
|
||||
}
|
||||
|
||||
lbValue lb_emit_count_leading_zeros(lbProcedure *p, lbValue x, Type *type) {
|
||||
x = lb_emit_conv(p, x, type);
|
||||
|
||||
char const *name = "llvm.ctlz";
|
||||
LLVMTypeRef types[1] = {lb_type(p->module, type)};
|
||||
unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name));
|
||||
GB_ASSERT_MSG(id != 0, "Unable to find %s.%s", name, LLVMPrintTypeToString(types[0]));
|
||||
LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, types, gb_count_of(types));
|
||||
|
||||
LLVMValueRef args[2] = {};
|
||||
args[0] = x.value;
|
||||
args[1] = LLVMConstNull(LLVMInt1TypeInContext(p->module->ctx));
|
||||
|
||||
lbValue res = {};
|
||||
res.value = LLVMBuildCall(p->builder, ip, args, gb_count_of(args), "");
|
||||
res.type = type;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type) {
|
||||
x = lb_emit_conv(p, x, type);
|
||||
|
||||
char const *name = "llvm.bitreverse";
|
||||
LLVMTypeRef types[1] = {lb_type(p->module, type)};
|
||||
unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name));
|
||||
GB_ASSERT_MSG(id != 0, "Unable to find %s.%s", name, LLVMPrintTypeToString(types[0]));
|
||||
LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, types, gb_count_of(types));
|
||||
|
||||
LLVMValueRef args[1] = {};
|
||||
args[0] = x.value;
|
||||
|
||||
lbValue res = {};
|
||||
res.value = LLVMBuildCall(p->builder, ip, args, gb_count_of(args), "");
|
||||
res.type = type;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x) {
|
||||
GB_ASSERT(is_type_bit_set(x.type));
|
||||
Type *underlying = bit_set_to_int(x.type);
|
||||
lbValue card = lb_emit_count_ones(p, x, underlying);
|
||||
return lb_emit_conv(p, card, t_int);
|
||||
}
|
||||
|
||||
|
||||
lbLoopData lb_loop_start(lbProcedure *p, isize count, Type *index_type) {
|
||||
lbLoopData data = {};
|
||||
|
||||
@@ -10085,6 +10153,9 @@ lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x) {
|
||||
} else if (op_kind == Token_NotEq) {
|
||||
return lb_const_bool(p->module, t_llvm_bool, false);
|
||||
}
|
||||
} else if (is_type_union_maybe_pointer(t)) {
|
||||
lbValue tag = lb_emit_transmute(p, x, t_rawptr);
|
||||
return lb_emit_comp_against_nil(p, op_kind, tag);
|
||||
} else {
|
||||
lbValue tag = lb_emit_union_tag_value(p, x);
|
||||
return lb_emit_comp(p, op_kind, tag, lb_zero(p->module, tag.type));
|
||||
@@ -10732,8 +10803,6 @@ lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, A
|
||||
String name = make_string((u8 *)name_text, name_len-1);
|
||||
|
||||
Type *type = type_of_expr(expr);
|
||||
set_procedure_abi_types(type);
|
||||
|
||||
|
||||
Token token = {};
|
||||
token.pos = ast_token(expr).pos;
|
||||
@@ -11203,8 +11272,15 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
|
||||
Type *src_type = type_deref(v.type);
|
||||
Type *dst_type = type;
|
||||
|
||||
lbValue src_tag = lb_emit_load(p, lb_emit_union_tag_ptr(p, v));
|
||||
lbValue dst_tag = lb_const_union_tag(p->module, src_type, dst_type);
|
||||
lbValue src_tag = {};
|
||||
lbValue dst_tag = {};
|
||||
if (is_type_union_maybe_pointer(src_type)) {
|
||||
src_tag = lb_emit_comp_against_nil(p, Token_NotEq, v);
|
||||
dst_tag = lb_const_bool(p->module, t_bool, true);
|
||||
} else {
|
||||
src_tag = lb_emit_load(p, lb_emit_union_tag_ptr(p, v));
|
||||
dst_tag = lb_const_union_tag(p->module, src_type, dst_type);
|
||||
}
|
||||
|
||||
lbValue ok = lb_emit_comp(p, Token_CmpEq, src_tag, dst_tag);
|
||||
auto args = array_make<lbValue>(permanent_allocator(), 6);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#if defined(LLVM_BACKEND_SUPPORT)
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/ExecutionEngine.h"
|
||||
@@ -30,7 +29,6 @@
|
||||
#include <llvm-c/Transforms/Utils.h>
|
||||
#include <llvm-c/Transforms/Vectorize.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct lbProcedure;
|
||||
|
||||
@@ -396,6 +394,14 @@ lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t);
|
||||
|
||||
LLVMMetadataRef lb_debug_type(lbModule *m, Type *type);
|
||||
|
||||
lbValue lb_emit_count_ones(lbProcedure *p, lbValue x, Type *type);
|
||||
lbValue lb_emit_count_zeros(lbProcedure *p, lbValue x, Type *type);
|
||||
lbValue lb_emit_count_trailing_zeros(lbProcedure *p, lbValue x, Type *type);
|
||||
lbValue lb_emit_count_leading_zeros(lbProcedure *p, lbValue x, Type *type);
|
||||
lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type);
|
||||
|
||||
lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x);
|
||||
|
||||
|
||||
|
||||
#define LB_STARTUP_RUNTIME_PROC_NAME "__$startup_runtime"
|
||||
|
||||
+52
-472
@@ -10,13 +10,11 @@
|
||||
|
||||
gb_global Timings global_timings = {0};
|
||||
|
||||
#if defined(LLVM_BACKEND_SUPPORT)
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
#include "llvm-c/Types.h"
|
||||
#else
|
||||
#include <llvm-c/Types.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "parser.hpp"
|
||||
#include "checker.hpp"
|
||||
@@ -26,7 +24,6 @@ gb_global Timings global_timings = {0};
|
||||
#include "docs.cpp"
|
||||
|
||||
|
||||
#if defined(LLVM_BACKEND_SUPPORT)
|
||||
#include "llvm_backend.cpp"
|
||||
|
||||
#if defined(GB_SYSTEM_OSX)
|
||||
@@ -36,11 +33,6 @@ gb_global Timings global_timings = {0};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#include "ir.cpp"
|
||||
#include "ir_opt.cpp"
|
||||
#include "ir_print.cpp"
|
||||
#include "query_data.cpp"
|
||||
|
||||
|
||||
@@ -154,7 +146,6 @@ i32 system_exec_command_line_app(char const *name, char const *fmt, ...) {
|
||||
|
||||
|
||||
|
||||
#if defined(LLVM_BACKEND_SUPPORT)
|
||||
i32 linker_stage(lbGenerator *gen) {
|
||||
i32 result = 0;
|
||||
Timings *timings = &global_timings;
|
||||
@@ -470,7 +461,6 @@ i32 linker_stage(lbGenerator *gen) {
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
Array<String> setup_args(int argc, char const **argv) {
|
||||
gbAllocator a = heap_allocator();
|
||||
@@ -1194,7 +1184,8 @@ bool parse_build_flags(Array<String> args) {
|
||||
break;
|
||||
|
||||
case BuildFlag_UseLLVMApi:
|
||||
build_context.use_llvm_api = true;
|
||||
gb_printf_err("-llvm-api flag is not required any more\n");
|
||||
bad_flags = true;
|
||||
break;
|
||||
|
||||
case BuildFlag_IgnoreUnknownAttributes:
|
||||
@@ -1225,8 +1216,8 @@ bool parse_build_flags(Array<String> args) {
|
||||
break;
|
||||
|
||||
case BuildFlag_StrictStyle:
|
||||
build_context.insert_semicolon = true;
|
||||
build_context.strict_style = true;
|
||||
gb_printf_err("-strict-style flag is not required any more\n");
|
||||
bad_flags = true;
|
||||
break;
|
||||
|
||||
|
||||
@@ -1811,10 +1802,6 @@ void print_show_help(String const arg0, String const &command) {
|
||||
print_usage_line(2, "Inserts semicolons on newlines during tokenization using a basic rule");
|
||||
print_usage_line(0, "");
|
||||
|
||||
print_usage_line(1, "-strict-style");
|
||||
print_usage_line(2, "Enforces code style stricter whilst parsing, requiring such things as trailing commas");
|
||||
print_usage_line(0, "");
|
||||
|
||||
print_usage_line(1, "-ignore-warnings");
|
||||
print_usage_line(2, "Ignores warning messages");
|
||||
print_usage_line(0, "");
|
||||
@@ -1929,10 +1916,22 @@ void print_show_unused(Checker *c) {
|
||||
print_usage_line(0, "");
|
||||
}
|
||||
|
||||
void enforce_platform_settings(void) {
|
||||
#if defined(GB_SYSTEM_OSX) && defined(GB_CPU_ARM)
|
||||
build_context.use_llvm_api = true;
|
||||
#endif
|
||||
bool check_env(void) {
|
||||
gbAllocator a = heap_allocator();
|
||||
char const *odin_root = gb_get_env("ODIN_ROOT", a);
|
||||
defer (gb_free(a, cast(void *)odin_root));
|
||||
if (odin_root) {
|
||||
if (!gb_file_exists(odin_root)) {
|
||||
gb_printf_err("Invalid ODIN_ROOT, directory does not exist, got %s\n", odin_root);
|
||||
return false;
|
||||
}
|
||||
String path = make_string_c(odin_root);
|
||||
if (!path_is_directory(path)) {
|
||||
gb_printf_err("Invalid ODIN_ROOT, expected a directory, got %s\n", odin_root);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1958,6 +1957,10 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
init_keyword_hash_table();
|
||||
global_big_int_init();
|
||||
|
||||
if (!check_env()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
array_init(&library_collections, heap_allocator());
|
||||
// NOTE(bill): 'core' cannot be (re)defined by the user
|
||||
add_library_collection(str_lit("core"), get_fullpath_relative(heap_allocator(), odin_root_dir(), str_lit("core")));
|
||||
@@ -2064,7 +2067,7 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
#endif
|
||||
|
||||
#ifdef GIT_SHA
|
||||
gb_printf("-%s", GIT_SHA);
|
||||
gb_printf(":%s", GIT_SHA);
|
||||
#endif
|
||||
|
||||
gb_printf("\n");
|
||||
@@ -2089,8 +2092,6 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
enforce_platform_settings();
|
||||
|
||||
// NOTE(bill): add 'shared' directory if it is not already set
|
||||
if (!find_library_collection_path(str_lit("shared"), nullptr)) {
|
||||
add_library_collection(str_lit("shared"),
|
||||
@@ -2103,18 +2104,6 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
// print_usage_line(0, "%.*s 32-bit is not yet supported for this platform", LIT(args[0]));
|
||||
// return 1;
|
||||
// }
|
||||
if (build_context.metrics.os == TargetOs_js) {
|
||||
if (!build_context.use_llvm_api) {
|
||||
print_usage_line(0, "%.*s - js platform only supported with the -llvm-api backend", LIT(args[0]));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (!build_context.use_llvm_api) {
|
||||
if (build_context.build_mode == BuildMode_Assembly) {
|
||||
print_usage_line(0, "-build-mode:assembly is only supported with the -llvm-api backend", LIT(args[0]));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
init_universal();
|
||||
// TODO(bill): prevent compiling without a linker
|
||||
@@ -2187,450 +2176,41 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (build_context.use_llvm_api) {
|
||||
#if defined(LLVM_BACKEND_SUPPORT)
|
||||
timings_start_section(timings, str_lit("LLVM API Code Gen"));
|
||||
lbGenerator gen = {};
|
||||
if (!lb_init_generator(&gen, &checker)) {
|
||||
return 1;
|
||||
}
|
||||
lb_generate_code(&gen);
|
||||
|
||||
temp_allocator_free_all(&temporary_allocator_data);
|
||||
|
||||
switch (build_context.build_mode) {
|
||||
case BuildMode_Executable:
|
||||
case BuildMode_DynamicLibrary:
|
||||
i32 result = linker_stage(&gen);
|
||||
if(result != 0) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (build_context.show_timings) {
|
||||
show_timings(&checker, timings);
|
||||
}
|
||||
|
||||
remove_temp_files(gen.output_base);
|
||||
|
||||
#if defined(GB_COMPILER_MSVC)
|
||||
if (false) {
|
||||
PROCESS_MEMORY_COUNTERS_EX pmc = {};
|
||||
GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc));
|
||||
SIZE_T virtual_mem_used_by_me = pmc.PrivateUsage;
|
||||
gb_printf_err("virtual_memory_used: %tu B\n", virtual_mem_used_by_me);
|
||||
|
||||
Parser *p = checker.parser;
|
||||
isize lines = p->total_line_count;
|
||||
isize tokens = p->total_token_count;
|
||||
isize files = 0;
|
||||
isize packages = p->packages.count;
|
||||
isize total_file_size = 0;
|
||||
for_array(i, p->packages) {
|
||||
files += p->packages[i]->files.count;
|
||||
for_array(j, p->packages[i]->files) {
|
||||
AstFile *file = p->packages[i]->files[j];
|
||||
total_file_size += file->tokenizer.end - file->tokenizer.start;
|
||||
}
|
||||
}
|
||||
gb_printf_err("total_file_size: %lld B\n", total_file_size);
|
||||
gb_printf_err("lines: %lld\n", lines);
|
||||
gb_printf_err("files: %lld\n", files);
|
||||
gb_printf_err("tokens: %lld\n", tokens);
|
||||
gb_printf_err("packages: %lld\n", packages);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (run_output) {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
return system_exec_command_line_app("odin run", "%.*s.exe %.*s", LIT(gen.output_base), LIT(run_args_string));
|
||||
#else
|
||||
//NOTE(thebirk): This whole thing is a little leaky
|
||||
String output_ext = {};
|
||||
String complete_path = concatenate_strings(heap_allocator(), gen.output_base, output_ext);
|
||||
complete_path = path_to_full_path(heap_allocator(), complete_path);
|
||||
return system_exec_command_line_app("odin run", "\"%.*s\" %.*s", LIT(complete_path), LIT(run_args_string));
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
gb_printf_err("LLVM C API backend is not supported on this platform yet\n");
|
||||
timings_start_section(timings, str_lit("LLVM API Code Gen"));
|
||||
lbGenerator gen = {};
|
||||
if (!lb_init_generator(&gen, &checker)) {
|
||||
return 1;
|
||||
#endif
|
||||
} else {
|
||||
irGen ir_gen = {0};
|
||||
if (!ir_gen_init(&ir_gen, &checker)) {
|
||||
}
|
||||
lb_generate_code(&gen);
|
||||
|
||||
temp_allocator_free_all(&temporary_allocator_data);
|
||||
|
||||
switch (build_context.build_mode) {
|
||||
case BuildMode_Executable:
|
||||
case BuildMode_DynamicLibrary:
|
||||
i32 result = linker_stage(&gen);
|
||||
if (result != 0) {
|
||||
return 1;
|
||||
}
|
||||
// defer (ir_gen_destroy(&ir_gen));
|
||||
break;
|
||||
}
|
||||
|
||||
if (build_context.show_timings) {
|
||||
show_timings(&checker, timings);
|
||||
}
|
||||
|
||||
timings_start_section(timings, str_lit("llvm ir gen"));
|
||||
ir_gen_tree(&ir_gen);
|
||||
remove_temp_files(gen.output_base);
|
||||
|
||||
temp_allocator_free_all(&temporary_allocator_data);
|
||||
|
||||
timings_start_section(timings, str_lit("llvm ir opt tree"));
|
||||
ir_opt_tree(&ir_gen);
|
||||
|
||||
temp_allocator_free_all(&temporary_allocator_data);
|
||||
|
||||
timings_start_section(timings, str_lit("llvm ir print"));
|
||||
print_llvm_ir(&ir_gen);
|
||||
|
||||
temp_allocator_free_all(&temporary_allocator_data);
|
||||
|
||||
|
||||
String output_name = ir_gen.output_name;
|
||||
String output_base = ir_gen.output_base;
|
||||
|
||||
build_context.optimization_level = gb_clamp(build_context.optimization_level, 0, 3);
|
||||
|
||||
timings_start_section(timings, str_lit("llvm-opt"));
|
||||
exec_llvm_opt(output_base);
|
||||
|
||||
timings_start_section(timings, str_lit("llvm-llc"));
|
||||
exec_llvm_llc(output_base);
|
||||
|
||||
if (build_context.build_mode == BuildMode_Object) {
|
||||
// Ignore the linker
|
||||
if (build_context.show_timings) {
|
||||
show_timings(&checker, timings);
|
||||
}
|
||||
|
||||
remove_temp_files(output_base);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (build_context.cross_compiling && selected_target_metrics->metrics == &target_essence_amd64) {
|
||||
#ifdef GB_SYSTEM_UNIX
|
||||
system_exec_command_line_app("linker", "x86_64-essence-gcc -ffreestanding -nostdlib \"%.*s.o\" -o \"%.*s\" %.*s %.*s",
|
||||
LIT(output_base), LIT(output_base), LIT(build_context.link_flags), LIT(build_context.extra_linker_flags));
|
||||
if (run_output) {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
return system_exec_command_line_app("odin run", "%.*s.exe %.*s", LIT(gen.output_base), LIT(run_args_string));
|
||||
#else
|
||||
gb_printf_err("Linking for cross compilation for this platform is not yet supported (%.*s %.*s)\n",
|
||||
LIT(target_os_names[build_context.metrics.os]),
|
||||
LIT(target_arch_names[build_context.metrics.arch])
|
||||
);
|
||||
//NOTE(thebirk): This whole thing is a little leaky
|
||||
String output_ext = {};
|
||||
String complete_path = concatenate_strings(heap_allocator(), gen.output_base, output_ext);
|
||||
complete_path = path_to_full_path(heap_allocator(), complete_path);
|
||||
return system_exec_command_line_app("odin run", "\"%.*s\" %.*s", LIT(complete_path), LIT(run_args_string));
|
||||
#endif
|
||||
} else if (build_context.cross_compiling && build_context.different_os) {
|
||||
gb_printf_err("Linking for cross compilation for this platform is not yet supported (%.*s %.*s)\n",
|
||||
LIT(target_os_names[build_context.metrics.os]),
|
||||
LIT(target_arch_names[build_context.metrics.arch])
|
||||
);
|
||||
build_context.keep_object_files = true;
|
||||
} else {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
timings_start_section(timings, str_lit("msvc-link"));
|
||||
|
||||
gbString lib_str = gb_string_make(heap_allocator(), "");
|
||||
defer (gb_string_free(lib_str));
|
||||
char lib_str_buf[1024] = {0};
|
||||
|
||||
char const *output_ext = "exe";
|
||||
gbString link_settings = gb_string_make_reserve(heap_allocator(), 256);
|
||||
defer (gb_string_free(link_settings));
|
||||
|
||||
|
||||
// NOTE(ic): It would be nice to extend this so that we could specify the Visual Studio version that we want instead of defaulting to the latest.
|
||||
Find_Result_Utf8 find_result = find_visual_studio_and_windows_sdk_utf8();
|
||||
|
||||
if (find_result.windows_sdk_version == 0) {
|
||||
gb_printf_err("Windows SDK not found.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (build_context.ignore_microsoft_magic) {
|
||||
find_result = {};
|
||||
}
|
||||
|
||||
// Add library search paths.
|
||||
if (find_result.vs_library_path.len > 0) {
|
||||
GB_ASSERT(find_result.windows_sdk_um_library_path.len > 0);
|
||||
GB_ASSERT(find_result.windows_sdk_ucrt_library_path.len > 0);
|
||||
|
||||
String path = {};
|
||||
auto add_path = [&](String path) {
|
||||
if (path[path.len-1] == '\\') {
|
||||
path.len -= 1;
|
||||
}
|
||||
link_settings = gb_string_append_fmt(link_settings, " /LIBPATH:\"%.*s\"", LIT(path));
|
||||
};
|
||||
add_path(find_result.windows_sdk_um_library_path);
|
||||
add_path(find_result.windows_sdk_ucrt_library_path);
|
||||
add_path(find_result.vs_library_path);
|
||||
}
|
||||
|
||||
for_array(i, ir_gen.module.foreign_library_paths) {
|
||||
String lib = ir_gen.module.foreign_library_paths[i];
|
||||
GB_ASSERT(lib.len < gb_count_of(lib_str_buf)-1);
|
||||
isize len = gb_snprintf(lib_str_buf, gb_size_of(lib_str_buf),
|
||||
" \"%.*s\"", LIT(lib));
|
||||
lib_str = gb_string_appendc(lib_str, lib_str_buf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (build_context.build_mode == BuildMode_DynamicLibrary) {
|
||||
output_ext = "dll";
|
||||
link_settings = gb_string_append_fmt(link_settings, " /DLL");
|
||||
} else {
|
||||
link_settings = gb_string_append_fmt(link_settings, " /ENTRY:mainCRTStartup");
|
||||
}
|
||||
|
||||
if (build_context.pdb_filepath != "") {
|
||||
link_settings = gb_string_append_fmt(link_settings, " /PDB:%.*s", LIT(build_context.pdb_filepath));
|
||||
}
|
||||
|
||||
if (build_context.no_crt) {
|
||||
link_settings = gb_string_append_fmt(link_settings, " /nodefaultlib");
|
||||
} else {
|
||||
link_settings = gb_string_append_fmt(link_settings, " /defaultlib:libcmt");
|
||||
}
|
||||
|
||||
if (ir_gen.module.generate_debug_info) {
|
||||
link_settings = gb_string_append_fmt(link_settings, " /DEBUG");
|
||||
}
|
||||
|
||||
|
||||
char const *subsystem_str = build_context.use_subsystem_windows ? "WINDOWS" : "CONSOLE";
|
||||
|
||||
if (!build_context.use_lld) { // msvc
|
||||
if (build_context.has_resource) {
|
||||
i32 result = system_exec_command_line_app("msvc-link",
|
||||
"\"rc.exe\" /nologo /fo \"%.*s.res\" \"%.*s.rc\"",
|
||||
LIT(output_base),
|
||||
LIT(build_context.resource_filepath)
|
||||
);
|
||||
|
||||
if(result != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
result = system_exec_command_line_app("msvc-link",
|
||||
"\"%.*slink.exe\" \"%.*s.obj\" \"%.*s.res\" -OUT:\"%.*s.%s\" %s "
|
||||
"/nologo /incremental:no /opt:ref /subsystem:%s "
|
||||
" %.*s "
|
||||
" %.*s "
|
||||
" %s "
|
||||
"",
|
||||
LIT(find_result.vs_exe_path), LIT(output_base), LIT(output_base), LIT(output_base), output_ext,
|
||||
link_settings,
|
||||
subsystem_str,
|
||||
LIT(build_context.link_flags),
|
||||
LIT(build_context.extra_linker_flags),
|
||||
lib_str
|
||||
);
|
||||
|
||||
if(result != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
i32 result = system_exec_command_line_app("msvc-link",
|
||||
"\"%.*slink.exe\" \"%.*s.obj\" -OUT:\"%.*s.%s\" %s "
|
||||
"/nologo /incremental:no /opt:ref /subsystem:%s "
|
||||
" %.*s "
|
||||
" %.*s "
|
||||
" %s "
|
||||
"",
|
||||
LIT(find_result.vs_exe_path), LIT(output_base), LIT(output_base), output_ext,
|
||||
link_settings,
|
||||
subsystem_str,
|
||||
LIT(build_context.link_flags),
|
||||
LIT(build_context.extra_linker_flags),
|
||||
lib_str
|
||||
);
|
||||
|
||||
if(result != 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} else { // lld
|
||||
i32 result = system_exec_command_line_app("msvc-link",
|
||||
"\"%.*s\\bin\\lld-link\" \"%.*s.obj\" -OUT:\"%.*s.%s\" %s "
|
||||
"/nologo /incremental:no /opt:ref /subsystem:%s "
|
||||
" %.*s "
|
||||
" %.*s "
|
||||
" %s "
|
||||
"",
|
||||
LIT(build_context.ODIN_ROOT),
|
||||
LIT(output_base), LIT(output_base), output_ext,
|
||||
link_settings,
|
||||
subsystem_str,
|
||||
LIT(build_context.link_flags),
|
||||
LIT(build_context.extra_linker_flags),
|
||||
lib_str
|
||||
);
|
||||
|
||||
if(result != 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (build_context.show_timings) {
|
||||
show_timings(&checker, timings);
|
||||
}
|
||||
|
||||
remove_temp_files(output_base);
|
||||
|
||||
if (run_output) {
|
||||
return system_exec_command_line_app("odin run", "%.*s.exe %.*s", LIT(output_base), LIT(run_args_string));
|
||||
}
|
||||
#else
|
||||
timings_start_section(timings, str_lit("ld-link"));
|
||||
|
||||
// NOTE(vassvik): get cwd, for used for local shared libs linking, since those have to be relative to the exe
|
||||
char cwd[256];
|
||||
getcwd(&cwd[0], 256);
|
||||
//printf("%s\n", cwd);
|
||||
|
||||
// NOTE(vassvik): needs to add the root to the library search paths, so that the full filenames of the library
|
||||
// files can be passed with -l:
|
||||
gbString lib_str = gb_string_make(heap_allocator(), "-L/");
|
||||
defer (gb_string_free(lib_str));
|
||||
|
||||
for_array(i, ir_gen.module.foreign_library_paths) {
|
||||
String lib = ir_gen.module.foreign_library_paths[i];
|
||||
|
||||
// NOTE(zangent): Sometimes, you have to use -framework on MacOS.
|
||||
// This allows you to specify '-f' in a #foreign_system_library,
|
||||
// without having to implement any new syntax specifically for MacOS.
|
||||
#if defined(GB_SYSTEM_OSX)
|
||||
if (string_ends_with(lib, str_lit(".framework"))) {
|
||||
// framework thingie
|
||||
String lib_name = lib;
|
||||
lib_name = remove_extension_from_path(lib_name);
|
||||
lib_str = gb_string_append_fmt(lib_str, " -framework %.*s ", LIT(lib_name));
|
||||
|
||||
} else if (string_ends_with(lib, str_lit(".a")) || string_ends_with(lib, str_lit(".o")) || string_ends_with(lib, str_lit(".dylib"))) {
|
||||
// For:
|
||||
// object
|
||||
// dynamic lib
|
||||
// static libs, absolute full path relative to the file in which the lib was imported from
|
||||
lib_str = gb_string_append_fmt(lib_str, " %.*s ", LIT(lib));
|
||||
} else {
|
||||
// dynamic or static system lib, just link regularly searching system library paths
|
||||
lib_str = gb_string_append_fmt(lib_str, " -l%.*s ", LIT(lib));
|
||||
}
|
||||
#else
|
||||
// NOTE(vassvik): static libraries (.a files) in linux can be linked to directly using the full path,
|
||||
// since those are statically linked to at link time. shared libraries (.so) has to be
|
||||
// available at runtime wherever the executable is run, so we make require those to be
|
||||
// local to the executable (unless the system collection is used, in which case we search
|
||||
// the system library paths for the library file).
|
||||
if (string_ends_with(lib, str_lit(".a"))) {
|
||||
// static libs, absolute full path relative to the file in which the lib was imported from
|
||||
lib_str = gb_string_append_fmt(lib_str, " -l:\"%.*s\" ", LIT(lib));
|
||||
} else if (string_ends_with(lib, str_lit(".so"))) {
|
||||
// dynamic lib, relative path to executable
|
||||
// NOTE(vassvik): it is the user's responsibility to make sure the shared library files are visible
|
||||
// at runtimeto the executable
|
||||
lib_str = gb_string_append_fmt(lib_str, " -l:\"%s/%.*s\" ", cwd, LIT(lib));
|
||||
} else {
|
||||
// dynamic or static system lib, just link regularly searching system library paths
|
||||
lib_str = gb_string_append_fmt(lib_str, " -l%.*s ", LIT(lib));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Unlike the Win32 linker code, the output_ext includes the dot, because
|
||||
// typically executable files on *NIX systems don't have extensions.
|
||||
String output_ext = {};
|
||||
gbString link_settings = gb_string_make_reserve(heap_allocator(), 32);
|
||||
char const *linker;
|
||||
if (build_context.build_mode == BuildMode_DynamicLibrary) {
|
||||
// NOTE(tetra, 2020-11-06): __$startup_runtime must be called at DLL load time.
|
||||
// Clang, for some reason, won't let us pass the '-init' flag that lets us do this,
|
||||
// so use ld instead.
|
||||
// :UseLDForShared
|
||||
linker = "ld";
|
||||
// NOTE(tetra, 2021-02-24): On Darwin, the symbol has _3_ underscores; on Linux, it only has 2.
|
||||
link_settings = gb_string_append_fmt(link_settings, "-init '%s$startup_runtime' ", build_context.metrics.os == TargetOs_darwin ? "___" : "__");
|
||||
// Shared libraries are .dylib on MacOS and .so on Linux.
|
||||
#if defined(GB_SYSTEM_OSX)
|
||||
output_ext = STR_LIT(".dylib");
|
||||
link_settings = gb_string_appendc(link_settings, "-dylib -dynamic ");
|
||||
#else
|
||||
output_ext = STR_LIT(".so");
|
||||
link_settings = gb_string_appendc(link_settings, "-shared ");
|
||||
#endif
|
||||
} else {
|
||||
#if defined(GB_SYSTEM_OSX)
|
||||
linker = "ld";
|
||||
#else
|
||||
// TODO(zangent): Figure out how to make ld work on Linux.
|
||||
// It probably has to do with including the entire CRT, but
|
||||
// that's quite a complicated issue to solve while remaining distro-agnostic.
|
||||
// Clang can figure out linker flags for us, and that's good enough _for now_.
|
||||
linker = "clang -Wno-unused-command-line-argument";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
if (build_context.out_filepath.len > 0) {
|
||||
//NOTE(thebirk): We have a custom -out arguments, so we should use the extension from that
|
||||
isize pos = string_extension_position(build_context.out_filepath);
|
||||
if (pos > 0) {
|
||||
output_ext = substring(build_context.out_filepath, pos, build_context.out_filepath.len);
|
||||
}
|
||||
}
|
||||
|
||||
i32 result = system_exec_command_line_app("ld-link",
|
||||
"%s \"%.*s.o\" -o \"%.*s%.*s\" %s "
|
||||
" %s "
|
||||
" %.*s "
|
||||
" %.*s "
|
||||
" %s "
|
||||
#if defined(GB_SYSTEM_OSX)
|
||||
// This sets a requirement of Mountain Lion and up, but the compiler doesn't work without this limit.
|
||||
// NOTE: If you change this (although this minimum is as low as you can go with Odin working)
|
||||
// make sure to also change the 'mtriple' param passed to 'opt'
|
||||
" -macosx_version_min 10.8.0 "
|
||||
// This points the linker to where the entry point is
|
||||
" -e _main "
|
||||
#endif
|
||||
, linker, LIT(output_base), LIT(output_base), LIT(output_ext),
|
||||
lib_str,
|
||||
#if defined(GB_SYSTEM_OSX)
|
||||
"-lSystem -lm -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -L/usr/local/lib",
|
||||
#else
|
||||
"-lc -lm",
|
||||
#endif
|
||||
LIT(build_context.link_flags),
|
||||
LIT(build_context.extra_linker_flags),
|
||||
link_settings);
|
||||
|
||||
if(result != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if defined(GB_SYSTEM_OSX)
|
||||
if (build_context.ODIN_DEBUG) {
|
||||
// NOTE: macOS links DWARF symbols dynamically. Dsymutil will map the stubs in the exe
|
||||
// to the symbols in the object file
|
||||
system_exec_command_line_app("dsymutil",
|
||||
"dsymutil %.*s%.*s", LIT(output_base), LIT(output_ext)
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if (build_context.show_timings) {
|
||||
show_timings(&checker, timings);
|
||||
}
|
||||
|
||||
remove_temp_files(output_base);
|
||||
|
||||
if (run_output) {
|
||||
//NOTE(thebirk): This whole thing is a little leaky
|
||||
String complete_path = concatenate_strings(heap_allocator(), output_base, output_ext);
|
||||
complete_path = path_to_full_path(heap_allocator(), complete_path);
|
||||
return system_exec_command_line_app("odin run", "\"%.*s\" %.*s", LIT(complete_path), LIT(run_args_string));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -1,258 +0,0 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// MurmurHash3 was written by Austin Appleby, and is placed in the public
|
||||
// domain. The author hereby disclaims copyright to this source code.
|
||||
|
||||
// Note - The x86 and x64 versions do _not_ produce the same results, as the
|
||||
// algorithms are optimized for their respective platforms. You can still
|
||||
// compile and run any of them on any platform, but your performance with the
|
||||
// non-native version will be less than optimal.
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define ROTL32(x,y) _rotl(x,y)
|
||||
#define ROTL64(x,y) _rotl64(x,y)
|
||||
#else
|
||||
|
||||
gb_inline u32 rotl32(u32 x, i8 r) {
|
||||
return (x << r) | (x >> (32-r));
|
||||
}
|
||||
gb_inline u64 rotl64(u64 x, i8 r) {
|
||||
return (x << r) | (x >> (64-r));
|
||||
}
|
||||
|
||||
#define ROTL32(x,y) rotl32(x,y)
|
||||
#define ROTL64(x,y) rotl64(x,y)
|
||||
#endif
|
||||
|
||||
gb_inline u32 fmix32(u32 h) {
|
||||
h ^= h >> 16;
|
||||
h *= 0x85ebca6b;
|
||||
h ^= h >> 13;
|
||||
h *= 0xc2b2ae35;
|
||||
h ^= h >> 16;
|
||||
return h;
|
||||
}
|
||||
|
||||
gb_inline u64 fmix64(u64 k) {
|
||||
k ^= k >> 33;
|
||||
k *= 0xff51afd7ed558ccdULL;
|
||||
k ^= k >> 33;
|
||||
k *= 0xc4ceb9fe1a85ec53ULL;
|
||||
k ^= k >> 33;
|
||||
return k;
|
||||
}
|
||||
|
||||
gb_inline u32 mm3_getblock32(u32 const *p, isize i) {
|
||||
return p[i];
|
||||
}
|
||||
gb_inline u64 mm3_getblock64(u64 const *p, isize i) {
|
||||
return p[i];
|
||||
}
|
||||
|
||||
void MurmurHash3_x64_128(void const *key, isize len, u32 seed, void *out) {
|
||||
u8 const * data = cast(u8 const *)key;
|
||||
isize nblocks = len / 16;
|
||||
|
||||
u64 h1 = seed;
|
||||
u64 h2 = seed;
|
||||
|
||||
u64 const c1 = 0x87c37b91114253d5ULL;
|
||||
u64 const c2 = 0x4cf5ad432745937fULL;
|
||||
|
||||
u64 const * blocks = cast(u64 const *)data;
|
||||
|
||||
for (isize i = 0; i < nblocks; i++) {
|
||||
u64 k1 = mm3_getblock64(blocks, i*2 + 0);
|
||||
u64 k2 = mm3_getblock64(blocks, i*2 + 1);
|
||||
|
||||
k1 *= c1; k1 = ROTL64(k1, 31); k1 *= c2; h1 ^= k1;
|
||||
h1 = ROTL64(h1,27); h1 += h2; h1 = h1*5+0x52dce729;
|
||||
k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2;
|
||||
h2 = ROTL64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5;
|
||||
}
|
||||
|
||||
u8 const * tail = cast(u8 const *)(data + nblocks*16);
|
||||
|
||||
u64 k1 = 0;
|
||||
u64 k2 = 0;
|
||||
|
||||
switch(len & 15) {
|
||||
case 15: k2 ^= ((u64)tail[14]) << 48;
|
||||
case 14: k2 ^= ((u64)tail[13]) << 40;
|
||||
case 13: k2 ^= ((u64)tail[12]) << 32;
|
||||
case 12: k2 ^= ((u64)tail[11]) << 24;
|
||||
case 11: k2 ^= ((u64)tail[10]) << 16;
|
||||
case 10: k2 ^= ((u64)tail[ 9]) << 8;
|
||||
case 9: k2 ^= ((u64)tail[ 8]) << 0;
|
||||
k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2;
|
||||
|
||||
case 8: k1 ^= ((u64)tail[ 7]) << 56;
|
||||
case 7: k1 ^= ((u64)tail[ 6]) << 48;
|
||||
case 6: k1 ^= ((u64)tail[ 5]) << 40;
|
||||
case 5: k1 ^= ((u64)tail[ 4]) << 32;
|
||||
case 4: k1 ^= ((u64)tail[ 3]) << 24;
|
||||
case 3: k1 ^= ((u64)tail[ 2]) << 16;
|
||||
case 2: k1 ^= ((u64)tail[ 1]) << 8;
|
||||
case 1: k1 ^= ((u64)tail[ 0]) << 0;
|
||||
k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1;
|
||||
}
|
||||
|
||||
h1 ^= len;
|
||||
h2 ^= len;
|
||||
|
||||
h1 += h2;
|
||||
h2 += h1;
|
||||
|
||||
h1 = fmix64(h1);
|
||||
h2 = fmix64(h2);
|
||||
|
||||
h1 += h2;
|
||||
h2 += h1;
|
||||
|
||||
((u64 *)out)[0] = h1;
|
||||
((u64 *)out)[1] = h2;
|
||||
}
|
||||
|
||||
void MurmurHash3_x86_128(void const *key, isize len, u32 seed, void *out) {
|
||||
u8 const * data = cast(u8 * const)key;
|
||||
isize nblocks = len / 16;
|
||||
|
||||
u32 h1 = seed;
|
||||
u32 h2 = seed;
|
||||
u32 h3 = seed;
|
||||
u32 h4 = seed;
|
||||
|
||||
u32 const c1 = 0x239b961b;
|
||||
u32 const c2 = 0xab0e9789;
|
||||
u32 const c3 = 0x38b34ae5;
|
||||
u32 const c4 = 0xa1e38b93;
|
||||
|
||||
//----------
|
||||
// body
|
||||
|
||||
u32 const * blocks = cast(u32 const *)(data + nblocks*16);
|
||||
|
||||
for (isize i = -nblocks; i != 0; i++) {
|
||||
u32 k1 = mm3_getblock32(blocks, i*4 + 0);
|
||||
u32 k2 = mm3_getblock32(blocks, i*4 + 1);
|
||||
u32 k3 = mm3_getblock32(blocks, i*4 + 2);
|
||||
u32 k4 = mm3_getblock32(blocks, i*4 + 3);
|
||||
|
||||
k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
|
||||
|
||||
h1 = ROTL32(h1,19); h1 += h2; h1 = h1*5+0x561ccd1b;
|
||||
|
||||
k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2;
|
||||
|
||||
h2 = ROTL32(h2,17); h2 += h3; h2 = h2*5+0x0bcaa747;
|
||||
|
||||
k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3;
|
||||
|
||||
h3 = ROTL32(h3,15); h3 += h4; h3 = h3*5+0x96cd1c35;
|
||||
|
||||
k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4;
|
||||
|
||||
h4 = ROTL32(h4,13); h4 += h1; h4 = h4*5+0x32ac3b17;
|
||||
}
|
||||
|
||||
//----------
|
||||
// tail
|
||||
|
||||
u8 const * tail = cast(u8 const *)(data + nblocks*16);
|
||||
|
||||
u32 k1 = 0;
|
||||
u32 k2 = 0;
|
||||
u32 k3 = 0;
|
||||
u32 k4 = 0;
|
||||
|
||||
switch(len & 15) {
|
||||
case 15: k4 ^= tail[14] << 16;
|
||||
case 14: k4 ^= tail[13] << 8;
|
||||
case 13: k4 ^= tail[12] << 0;
|
||||
k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4;
|
||||
|
||||
case 12: k3 ^= tail[11] << 24;
|
||||
case 11: k3 ^= tail[10] << 16;
|
||||
case 10: k3 ^= tail[ 9] << 8;
|
||||
case 9: k3 ^= tail[ 8] << 0;
|
||||
k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3;
|
||||
|
||||
case 8: k2 ^= tail[ 7] << 24;
|
||||
case 7: k2 ^= tail[ 6] << 16;
|
||||
case 6: k2 ^= tail[ 5] << 8;
|
||||
case 5: k2 ^= tail[ 4] << 0;
|
||||
k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2;
|
||||
|
||||
case 4: k1 ^= tail[ 3] << 24;
|
||||
case 3: k1 ^= tail[ 2] << 16;
|
||||
case 2: k1 ^= tail[ 1] << 8;
|
||||
case 1: k1 ^= tail[ 0] << 0;
|
||||
k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
|
||||
};
|
||||
|
||||
//----------
|
||||
// finalization
|
||||
|
||||
h1 ^= len; h2 ^= len; h3 ^= len; h4 ^= len;
|
||||
|
||||
h1 += h2; h1 += h3; h1 += h4;
|
||||
h2 += h1; h3 += h1; h4 += h1;
|
||||
|
||||
h1 = fmix32(h1);
|
||||
h2 = fmix32(h2);
|
||||
h3 = fmix32(h3);
|
||||
h4 = fmix32(h4);
|
||||
|
||||
h1 += h2; h1 += h3; h1 += h4;
|
||||
h2 += h1; h3 += h1; h4 += h1;
|
||||
|
||||
|
||||
((u32 *)out)[0] = h1;
|
||||
((u32 *)out)[1] = h2;
|
||||
((u32 *)out)[2] = h3;
|
||||
((u32 *)out)[3] = h4;
|
||||
}
|
||||
|
||||
// gb_inline u128 MurmurHash3_128(void const *key, isize len, u32 seed) {
|
||||
// u128 res;
|
||||
// #if defined(GB_ARCH_64_BIT)
|
||||
// MurmurHash3_x64_128(key, len, seed, &res);
|
||||
// #else
|
||||
// MurmurHash3_x86_128(key, len, seed, &res);
|
||||
// #endif
|
||||
// return res;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
gb_internal gb_inline u32 murmur_32_scramble(u32 k) {
|
||||
k *= 0xcc9e2d51;
|
||||
k = (k << 15) | (k >> 17);
|
||||
k *= 0x1b873593;
|
||||
return k;
|
||||
}
|
||||
|
||||
u32 murmur3_32(u8 const *key, isize len, u32 seed) {
|
||||
u32 h = seed;
|
||||
u32 k;
|
||||
for (size_t i = len >> 2; i; i--) {
|
||||
memcpy(&k, key, sizeof(u32));
|
||||
key += sizeof(u32);
|
||||
h ^= murmur_32_scramble(k);
|
||||
h = (h << 13) | (h >> 19);
|
||||
h = h * 5 + 0xe6546b64;
|
||||
}
|
||||
k = 0;
|
||||
for (size_t i = len & 3; i; i--) {
|
||||
k <<= 8;
|
||||
k |= key[i - 1];
|
||||
}
|
||||
h ^= murmur_32_scramble(k);
|
||||
h ^= len;
|
||||
h ^= h >> 16;
|
||||
h *= 0x85ebca6b;
|
||||
h ^= h >> 13;
|
||||
h *= 0xc2b2ae35;
|
||||
h ^= h >> 16;
|
||||
return h;
|
||||
}
|
||||
+51
-35
@@ -58,7 +58,7 @@ Token ast_token(Ast *node) {
|
||||
case Ast_ReturnStmt: return node->ReturnStmt.token;
|
||||
case Ast_ForStmt: return node->ForStmt.token;
|
||||
case Ast_RangeStmt: return node->RangeStmt.token;
|
||||
case Ast_InlineRangeStmt: return node->InlineRangeStmt.inline_token;
|
||||
case Ast_UnrollRangeStmt: return node->UnrollRangeStmt.unroll_token;
|
||||
case Ast_CaseClause: return node->CaseClause.token;
|
||||
case Ast_SwitchStmt: return node->SwitchStmt.token;
|
||||
case Ast_TypeSwitchStmt: return node->TypeSwitchStmt.token;
|
||||
@@ -319,11 +319,11 @@ Ast *clone_ast(Ast *node) {
|
||||
n->RangeStmt.expr = clone_ast(n->RangeStmt.expr);
|
||||
n->RangeStmt.body = clone_ast(n->RangeStmt.body);
|
||||
break;
|
||||
case Ast_InlineRangeStmt:
|
||||
n->InlineRangeStmt.val0 = clone_ast(n->InlineRangeStmt.val0);
|
||||
n->InlineRangeStmt.val1 = clone_ast(n->InlineRangeStmt.val1);
|
||||
n->InlineRangeStmt.expr = clone_ast(n->InlineRangeStmt.expr);
|
||||
n->InlineRangeStmt.body = clone_ast(n->InlineRangeStmt.body);
|
||||
case Ast_UnrollRangeStmt:
|
||||
n->UnrollRangeStmt.val0 = clone_ast(n->UnrollRangeStmt.val0);
|
||||
n->UnrollRangeStmt.val1 = clone_ast(n->UnrollRangeStmt.val1);
|
||||
n->UnrollRangeStmt.expr = clone_ast(n->UnrollRangeStmt.expr);
|
||||
n->UnrollRangeStmt.body = clone_ast(n->UnrollRangeStmt.body);
|
||||
break;
|
||||
case Ast_CaseClause:
|
||||
n->CaseClause.list = clone_ast_array(n->CaseClause.list);
|
||||
@@ -851,15 +851,15 @@ Ast *ast_range_stmt(AstFile *f, Token token, Slice<Ast *> vals, Token in_token,
|
||||
return result;
|
||||
}
|
||||
|
||||
Ast *ast_inline_range_stmt(AstFile *f, Token inline_token, Token for_token, Ast *val0, Ast *val1, Token in_token, Ast *expr, Ast *body) {
|
||||
Ast *result = alloc_ast_node(f, Ast_InlineRangeStmt);
|
||||
result->InlineRangeStmt.inline_token = inline_token;
|
||||
result->InlineRangeStmt.for_token = for_token;
|
||||
result->InlineRangeStmt.val0 = val0;
|
||||
result->InlineRangeStmt.val1 = val1;
|
||||
result->InlineRangeStmt.in_token = in_token;
|
||||
result->InlineRangeStmt.expr = expr;
|
||||
result->InlineRangeStmt.body = body;
|
||||
Ast *ast_unroll_range_stmt(AstFile *f, Token unroll_token, Token for_token, Ast *val0, Ast *val1, Token in_token, Ast *expr, Ast *body) {
|
||||
Ast *result = alloc_ast_node(f, Ast_UnrollRangeStmt);
|
||||
result->UnrollRangeStmt.unroll_token = unroll_token;
|
||||
result->UnrollRangeStmt.for_token = for_token;
|
||||
result->UnrollRangeStmt.val0 = val0;
|
||||
result->UnrollRangeStmt.val1 = val1;
|
||||
result->UnrollRangeStmt.in_token = in_token;
|
||||
result->UnrollRangeStmt.expr = expr;
|
||||
result->UnrollRangeStmt.body = body;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1232,13 +1232,10 @@ void comsume_comment_groups(AstFile *f, Token prev) {
|
||||
}
|
||||
|
||||
bool ignore_newlines(AstFile *f) {
|
||||
if (build_context.strict_style) {
|
||||
if (f->allow_newline) {
|
||||
return f->expr_level > 0;
|
||||
}
|
||||
return f->expr_level >= 0;
|
||||
if (f->allow_newline) {
|
||||
return f->expr_level > 0;
|
||||
}
|
||||
return false;
|
||||
return f->expr_level >= 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1505,6 +1502,10 @@ bool is_semicolon_optional_for_node(AstFile *f, Ast *s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (build_context.insert_semicolon) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (s->kind) {
|
||||
case Ast_EmptyStmt:
|
||||
case Ast_BlockStmt:
|
||||
@@ -1556,7 +1557,7 @@ bool is_semicolon_optional_for_node(AstFile *f, Ast *s) {
|
||||
}
|
||||
|
||||
void expect_semicolon_newline_error(AstFile *f, Token const &token, Ast *s) {
|
||||
if (build_context.strict_style && token.string == "\n") {
|
||||
if (!build_context.insert_semicolon && token.string == "\n") {
|
||||
switch (token.kind) {
|
||||
case Token_CloseBrace:
|
||||
case Token_CloseParen:
|
||||
@@ -1718,11 +1719,12 @@ Array<Ast *> parse_element_list(AstFile *f) {
|
||||
Ast *parse_literal_value(AstFile *f, Ast *type) {
|
||||
Array<Ast *> elems = {};
|
||||
Token open = expect_token(f, Token_OpenBrace);
|
||||
f->expr_level++;
|
||||
isize expr_level = f->expr_level;
|
||||
f->expr_level = 0;
|
||||
if (f->curr_token.kind != Token_CloseBrace) {
|
||||
elems = parse_element_list(f);
|
||||
}
|
||||
f->expr_level--;
|
||||
f->expr_level = expr_level;
|
||||
Token close = expect_closing(f, Token_CloseBrace, str_lit("compound literal"));
|
||||
|
||||
return ast_compound_lit(f, type, elems, open, close);
|
||||
@@ -1974,12 +1976,21 @@ Ast *parse_operand(AstFile *f, bool lhs) {
|
||||
break;
|
||||
|
||||
case Token_OpenParen: {
|
||||
bool allow_newline;
|
||||
Token open, close;
|
||||
// NOTE(bill): Skip the Paren Expression
|
||||
open = expect_token(f, Token_OpenParen);
|
||||
allow_newline = f->allow_newline;
|
||||
if (f->expr_level < 0) {
|
||||
f->allow_newline = false;
|
||||
}
|
||||
|
||||
f->expr_level++;
|
||||
operand = parse_expr(f, false);
|
||||
f->expr_level--;
|
||||
|
||||
f->allow_newline = allow_newline;
|
||||
|
||||
close = expect_token(f, Token_CloseParen);
|
||||
return ast_paren_expr(f, operand, open, close);
|
||||
}
|
||||
@@ -2112,12 +2123,15 @@ Ast *parse_operand(AstFile *f, bool lhs) {
|
||||
return ast_proc_group(f, token, open, close, args);
|
||||
}
|
||||
|
||||
|
||||
Ast *type = parse_proc_type(f, token);
|
||||
Token where_token = {};
|
||||
Array<Ast *> where_clauses = {};
|
||||
u64 tags = 0;
|
||||
|
||||
skip_possible_newline_for_literal(f);
|
||||
|
||||
|
||||
if (f->curr_token.kind == Token_where) {
|
||||
where_token = expect_token(f, Token_where);
|
||||
isize prev_level = f->expr_level;
|
||||
@@ -2878,6 +2892,9 @@ Ast *parse_expr(AstFile *f, bool lhs) {
|
||||
|
||||
|
||||
Array<Ast *> parse_expr_list(AstFile *f, bool lhs) {
|
||||
bool allow_newline = f->allow_newline;
|
||||
f->allow_newline = true;
|
||||
|
||||
auto list = array_make<Ast *>(heap_allocator());
|
||||
for (;;) {
|
||||
Ast *e = parse_expr(f, lhs);
|
||||
@@ -2889,6 +2906,8 @@ Array<Ast *> parse_expr_list(AstFile *f, bool lhs) {
|
||||
advance_token(f);
|
||||
}
|
||||
|
||||
f->allow_newline = allow_newline;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -4258,9 +4277,9 @@ Ast *parse_attribute(AstFile *f, Token token, TokenKind open_kind, TokenKind clo
|
||||
}
|
||||
|
||||
|
||||
Ast *parse_unrolled_for_loop(AstFile *f, Token inline_token) {
|
||||
if (inline_token.kind == Token_inline) {
|
||||
syntax_warning(inline_token, "'inline for' is deprecated in favour of `#unroll for'");
|
||||
Ast *parse_unrolled_for_loop(AstFile *f, Token unroll_token) {
|
||||
if (unroll_token.kind == Token_inline) {
|
||||
syntax_warning(unroll_token, "'inline for' is deprecated in favour of `#unroll for'");
|
||||
}
|
||||
Token for_token = expect_token(f, Token_for);
|
||||
Ast *val0 = nullptr;
|
||||
@@ -4308,9 +4327,9 @@ Ast *parse_unrolled_for_loop(AstFile *f, Token inline_token) {
|
||||
body = parse_block_stmt(f, false);
|
||||
}
|
||||
if (bad_stmt) {
|
||||
return ast_bad_stmt(f, inline_token, f->curr_token);
|
||||
return ast_bad_stmt(f, unroll_token, f->curr_token);
|
||||
}
|
||||
return ast_inline_range_stmt(f, inline_token, for_token, val0, val1, in_token, expr, body);
|
||||
return ast_unroll_range_stmt(f, unroll_token, for_token, val0, val1, in_token, expr, body);
|
||||
}
|
||||
|
||||
Ast *parse_stmt(AstFile *f) {
|
||||
@@ -4320,8 +4339,8 @@ Ast *parse_stmt(AstFile *f) {
|
||||
// Operands
|
||||
case Token_inline:
|
||||
if (peek_token_kind(f, Token_for)) {
|
||||
Token inline_token = expect_token(f, Token_inline);
|
||||
return parse_unrolled_for_loop(f, inline_token);
|
||||
Token unroll_token = expect_token(f, Token_inline);
|
||||
return parse_unrolled_for_loop(f, unroll_token);
|
||||
}
|
||||
/* fallthrough */
|
||||
case Token_no_inline:
|
||||
@@ -4555,10 +4574,7 @@ ParseFileError init_ast_file(AstFile *f, String fullpath, TokenPos *err_pos) {
|
||||
if (!string_ends_with(f->fullpath, str_lit(".odin"))) {
|
||||
return ParseFile_WrongExtension;
|
||||
}
|
||||
TokenizerFlags tokenizer_flags = TokenizerFlag_None;
|
||||
if (build_context.insert_semicolon) {
|
||||
tokenizer_flags = TokenizerFlag_InsertSemicolon;
|
||||
}
|
||||
TokenizerFlags tokenizer_flags = TokenizerFlag_InsertSemicolon;
|
||||
|
||||
zero_item(&f->tokenizer);
|
||||
f->tokenizer.curr_file_id = f->id;
|
||||
|
||||
+2
-2
@@ -415,8 +415,8 @@ AST_KIND(_ComplexStmtBegin, "", bool) \
|
||||
Ast *expr; \
|
||||
Ast *body; \
|
||||
}) \
|
||||
AST_KIND(InlineRangeStmt, "inline range statement", struct { \
|
||||
Token inline_token; \
|
||||
AST_KIND(UnrollRangeStmt, "#unroll range statement", struct { \
|
||||
Token unroll_token; \
|
||||
Token for_token; \
|
||||
Ast *val0; \
|
||||
Ast *val1; \
|
||||
|
||||
@@ -198,11 +198,8 @@ struct TypeProc {
|
||||
isize specialization_count;
|
||||
ProcCallingConvention calling_convention;
|
||||
i32 variadic_index;
|
||||
Array<Type *> abi_compat_params;
|
||||
Type * abi_compat_result_type;
|
||||
// TODO(bill): Make this a flag set rather than bools
|
||||
bool variadic;
|
||||
bool abi_types_set;
|
||||
bool require_results;
|
||||
bool c_vararg;
|
||||
bool is_polymorphic;
|
||||
@@ -317,7 +314,6 @@ enum TypeFlag : u32 {
|
||||
TypeFlag_Polymorphic = 1<<1,
|
||||
TypeFlag_PolySpecialized = 1<<2,
|
||||
TypeFlag_InProcessOfCheckingPolymorphic = 1<<3,
|
||||
TypeFlag_InProcessOfCheckingABI = 1<<4,
|
||||
};
|
||||
|
||||
struct Type {
|
||||
|
||||
Reference in New Issue
Block a user