libjit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Libjit] Why jit_value_create_nint_constant() does not truncate the


From: Aleksey Demakov
Subject: Re: [Libjit] Why jit_value_create_nint_constant() does not truncate the data if the data is larger than the type can hold?
Date: Thu, 21 Feb 2019 12:02:06 +0300

This is because libjit is a backend compiler meant to work together with a user-implemented frontend. It is the responsibility of the frontend to validate source language or bytecode programs. For the case you provided a correctly behaving frontend should check if the constant fits the target type. If it detects a problem there is a choice:

* print a error message and reject the whole program;
* print a warning message and truncate the constant;
* silently truncate the constant. 

Such a choice can be made only by the frontend. It is not possible for libjit to decide. So it does not try to and simply expects to get sensible data from the frontend. 

Regards, 
Aleksey

чт, 21 февр. 2019 г., 6:00 Peng Yu <address@hidden>:
I still got 10000 which is larger than what a byte can hold. Does
anybody know why it is so? Thanks.

$ ./main.exe
100000


#include <stdio.h>
#include <jit/jit.h>
#include <stdlib.h>
#include <jit/jit-dump.h>

int main(int argc, char *argv[]) {
        jit_context_t context = jit_context_create();
        jit_context_build_start(context);

        jit_type_t params[] = { jit_type_int, jit_type_int };
        jit_type_t signature = jit_type_create_signature(jit_abi_cdecl,
jit_type_int, params, 2, 1);
        jit_function_t F = jit_function_create(context, signature);
        jit_type_free(signature);
        jit_dump_value(stdout, F, jit_value_create_nint_constant(F,
jit_type_ubyte, 100000), NULL); puts("");
        return 0;
}


--
Regards,
Peng


reply via email to

[Prev in Thread] Current Thread [Next in Thread]