Attempt supporting setjmp on MSVC

This commit is contained in:
Christoffer Lerno
2022-12-07 21:20:30 +01:00
committed by Christoffer Lerno
parent eaaa5362a5
commit de4bfe470e
8 changed files with 28 additions and 2 deletions

View File

@@ -52,6 +52,11 @@ jobs:
cd test
python3.exe src/tester.py ..\build\${{ matrix.build_type }}\c3c.exe test_suite/
- name: Compile run stdlib tests
run: |
cd test
..\build\${{ matrix.build_type }}\c3c.exe compile-test stdlib\conv_tests.c3 -g1 --safe
- name: upload artifacts
uses: actions/upload-artifact@v3
with:

View File

@@ -64,9 +64,14 @@ extern fn void srand(uint seed);
define JmpBuf = CInt[$$JMP_BUF_SIZE];
extern fn CInt setjmp(JmpBuf* buffer);
extern fn void longjmp(JmpBuf* buffer, CInt value);
$if (env::OS_TYPE == OsType.WIN32):
// TODO win32 aarch64
extern fn CInt _setjmp(void* frameptr, JmpBuf* buffer);
macro CInt setjmp(JmpBuf* buffer) = _setjmp($$frameaddress(), buffer);
$else:
extern fn CInt setjmp(JmpBuf* buffer);
$endif;
// MB functions omitted
// string

View File

@@ -841,6 +841,7 @@ typedef enum
BUILTIN_FLOOR,
BUILTIN_FMA,
BUILTIN_FMULADD,
BUILTIN_FRAMEADDRESS,
BUILTIN_FSHL,
BUILTIN_FSHR,
BUILTIN_GET_ROUNDING_MODE,

View File

@@ -637,6 +637,7 @@ static void llvm_codegen_setup()
intrinsic_id.floor = lookup_intrinsic("llvm.floor");
intrinsic_id.flt_rounds = lookup_intrinsic("llvm.flt.rounds");
intrinsic_id.fma = lookup_intrinsic("llvm.fma");
intrinsic_id.frameaddress = lookup_intrinsic("llvm.frameaddress");
intrinsic_id.fshl = lookup_intrinsic("llvm.fshl");
intrinsic_id.fshr = lookup_intrinsic("llvm.fshr");
intrinsic_id.lifetime_end = lookup_intrinsic("llvm.lifetime.end");

View File

@@ -449,6 +449,14 @@ void llvm_emit_builtin_call(GenContext *c, BEValue *result_value, Expr *expr)
case BUILTIN_SHUFFLEVECTOR:
llvm_emit_shufflevector(c, result_value, expr);
return;
case BUILTIN_FRAMEADDRESS:
{
LLVMTypeRef type[2] = { llvm_get_type(c, type_voidptr), llvm_get_type(c, type_int) };
LLVMValueRef value = LLVMConstNull(type[1]);
value = llvm_emit_call_intrinsic(c, intrinsic_id.frameaddress, type, 1, &value, 1);
llvm_value_set(result_value, value, expr->type);
return;
}
case BUILTIN_REVERSE:
llvm_emit_reverse(c, result_value, expr);
return;

View File

@@ -134,6 +134,7 @@ typedef struct
unsigned floor;
unsigned flt_rounds;
unsigned fma;
unsigned frameaddress;
unsigned fshl;
unsigned fshr;
unsigned lifetime_end;

View File

@@ -284,6 +284,9 @@ bool sema_expr_analyse_builtin_call(SemaContext *context, Expr *expr)
case BUILTIN_GET_ROUNDING_MODE:
rtype = type_int;
break;
case BUILTIN_FRAMEADDRESS:
rtype = type_voidptr;
break;
case BUILTIN_SET_ROUNDING_MODE:
if (!sema_check_builtin_args(args,
(BuiltinArg[]) { BA_INTEGER },
@@ -551,6 +554,7 @@ static inline unsigned builtin_expected_args(BuiltinFunction func)
case BUILTIN_SYSCLOCK:
case BUILTIN_TRAP:
case BUILTIN_UNREACHABLE:
case BUILTIN_FRAMEADDRESS:
return 0;
case BUILTIN_ABS:
case BUILTIN_BITREVERSE:

View File

@@ -203,6 +203,7 @@ void symtab_init(uint32_t capacity)
builtin_list[BUILTIN_FLOOR] = KW_DEF("floor");
builtin_list[BUILTIN_FMA] = KW_DEF("fma");
builtin_list[BUILTIN_FMULADD] = KW_DEF("fmuladd");
builtin_list[BUILTIN_FRAMEADDRESS] = KW_DEF("frameaddress");
builtin_list[BUILTIN_FSHL] = KW_DEF("fshl");
builtin_list[BUILTIN_FSHR] = KW_DEF("fshr");
builtin_list[BUILTIN_GET_ROUNDING_MODE] = KW_DEF("get_rounding_mode");