void arch_store16(cpu_t *cpu, Value *val, Value *addr, BasicBlock *bb) { Value *shift = arch_get_shift16(cpu, addr, bb); addr = AND(addr, CONST(~3ULL)); Value *mask = XOR(SHL(CONST(65535), shift),CONST(-1ULL)); Value *old = AND(arch_load32_aligned(cpu, addr, bb), mask); val = OR(old, SHL(AND(val, CONST(65535)), shift)); arch_store32_aligned(cpu, val, addr, bb); }
// Init class pointers and fix array layout void vm_init_const_table_elems(void) { uint8_t * ptr = const_table_g; class_t * str_cls = vm_find_class("String"); class_t * arr_cls = vm_find_class("Array"); constant_array_t * c_arr; int i; kek_obj_t ** elems; while (ptr != const_table_g + const_table_cnt_g) { kek_obj_t * obj = (kek_obj_t*) ptr; switch (obj->h.t) { case KEK_NIL: ptr += sizeof(kek_nil_t); break; case KEK_INT: ptr += sizeof(kek_int_t); break; case KEK_STR: obj->h.cls = str_cls; ptr += sizeof(kek_string_t) + obj->k_str.length; break; case KEK_SYM: if (obj->h.cls != NULL) { // Parent class name index stored in cls pointer assert(IS_SYM((kek_obj_t*) CONST((ptruint_t)obj->h.cls))); obj->h.cls = vm_find_class(CONST((ptruint_t)obj->h.cls)->k_sym.symbol); } else { obj->h.cls = vm_find_class(obj->k_sym.symbol); } ptr += sizeof(kek_symbol_t) + obj->k_sym.length; break; case KEK_ARR: obj->h.cls = arr_cls; c_arr = (constant_array_t*) obj; elems = alloc_const_arr_elems(obj->k_arr.length); //obj->k_arr.alloc_size = obj->k_arr.length; for (i = 0; i < c_arr->length; ++i) { elems[i] = CONST(c_arr->elems[i]); } obj->k_arr.elems = elems; arr_set_alloc_size(&obj->k_arr, obj->k_arr.length); assert(obj->k_arr.alloc_size > 0); add_carray_to_gc_rootset(&obj->k_arr); ptr += sizeof(constant_array_t) + (obj->k_arr.length - 1) * sizeof(uint32_t); break; case KEK_EXINFO: ptr += sizeof(kek_exinfo_t) + (obj->k_exi.length - 1) * sizeof(try_range_t); break; default: ; } } }
static Value * arch_get_shift16(cpu_t *cpu, Value *addr, BasicBlock *bb) { Value *shift = AND(LSHR(addr,CONST(1)),CONST(1)); if (!IS_LITTLE_ENDIAN(cpu)) shift = XOR(shift, CONST(1)); return SHL(shift, CONST(4)); }
std::shared_ptr<Expr> buildTpchQ6FilterExpression() { shared_ptr<Expr> expression(AND(GE(FIELD("l_shipdate"), CONST("1994-01-01")), LT(FIELD("l_shipdate"), CONST("1995-01-01")), GE(FIELD("l_discount"), CONST("0.05", DOUBLE)), LE(FIELD("l_discount"), CONST("0.07", DOUBLE)), LT(FIELD("l_quantity"), CONST("24", DOUBLE)) )); return expression; }
void setupNumberGenComboBox(QScriptEngine *engine) { QScriptValue glob = engine->newFunction(constructNumberGenComboBox); qScriptRegisterMetaType(engine, NumberGenComboBoxToScriptValue, NumberGenComboBoxFromScriptValue); glob.setProperty("Manual", CONST(NumberGenComboBox::Manual), CONSTFLAGS); glob.setProperty("Automatic", CONST(NumberGenComboBox::Automatic), CONSTFLAGS); glob.setProperty("Override", CONST(NumberGenComboBox::Override), CONSTFLAGS); glob.setProperty("Shared", CONST(NumberGenComboBox::Shared), CONSTFLAGS); engine->globalObject().setProperty("NumberGenComboBox", glob, CONSTFLAGS); }
static void check_store(LLVMValueRef rvalue, LLVMValueRef lvalue) { if (LLVMIsAGlobalValue(lvalue)) rvalue = LLVMBuildShl(builder, rvalue, CONST(WORDPOW), ""); LLVMBuildStore(builder, rvalue, lvalue); }
LLVMValueRef gen_name(struct node *ast) { LLVMValueRef func, ptr, val; LLVMTypeRef type; ptr = lvalue(ast); type = LLVMTypeOf(ptr); if (LLVMGetTypeKind(type) == LLVMLabelTypeKind) { func = LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder)); return LLVMBuildPtrToInt(builder, LLVMBlockAddress(func, (LLVMBasicBlockRef)ptr), TYPE_INT, ""); } type = LLVMGetElementType(LLVMTypeOf(ptr)); switch (LLVMGetTypeKind(type)) { case LLVMIntegerTypeKind: val = LLVMBuildLoad(builder, ptr, ast->val); if (LLVMIsAGlobalValue(ptr)) val = LLVMBuildLShr(builder, val, CONST(WORDPOW), ""); return val; default: generror("unexpected type '%s'", LLVMPrintTypeToString(type)); return NULL; } }
LLVMValueRef gen_if(struct node *ast) { LLVMValueRef condition, func; LLVMBasicBlockRef then_block, else_block, end; condition = codegen(ast->one); condition = LLVMBuildICmp(builder, LLVMIntNE, condition, CONST(0), ""); func = LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder)); then_block = LLVMAppendBasicBlock(func, ""); else_block = LLVMAppendBasicBlock(func, ""); end = LLVMAppendBasicBlock(func, ""); LLVMBuildCondBr(builder, condition, then_block, else_block); LLVMPositionBuilderAtEnd(builder, then_block); codegen(ast->two); LLVMBuildBr(builder, end); LLVMPositionBuilderAtEnd(builder, else_block); if (ast->three) codegen(ast->three); LLVMBuildBr(builder, end); LLVMPositionBuilderAtEnd(builder, end); return NULL; }
static SCM expand_and (SCM expr, SCM env) { const SCM cdr_expr = CDR (expr); if (scm_is_null (cdr_expr)) return CONST (SCM_BOOL_F, SCM_BOOL_T); ASSERT_SYNTAX (scm_is_pair (cdr_expr), s_bad_expression, expr); if (scm_is_null (CDR (cdr_expr))) return expand (CAR (cdr_expr), env); else return CONDITIONAL (scm_source_properties (expr), expand (CAR (cdr_expr), env), expand_and (cdr_expr, env), CONST (SCM_BOOL_F, SCM_BOOL_F)); }
static LLVMValueRef lvalue_to_rvalue(LLVMValueRef lvalue) { /* * TODO: Make sure all addresses are word-aligned * (autos, vectors, strings, etc.) */ lvalue = LLVMBuildPtrToInt(builder, lvalue, TYPE_INT, ""); return LLVMBuildLShr(builder, lvalue, CONST(WORDPOW), ""); }
static LLVMValueRef make_char(const char *str) { LLVMValueRef charval; /* Skip leading ' */ str += 1; charval = CONST(pack_char(&str)); return charval; }
static SCM expand_quote (SCM expr, SCM env SCM_UNUSED) { SCM quotee; const SCM cdr_expr = CDR (expr); ASSERT_SYNTAX (scm_ilength (cdr_expr) >= 0, s_bad_expression, expr); ASSERT_SYNTAX (scm_ilength (cdr_expr) == 1, s_expression, expr); quotee = CAR (cdr_expr); return CONST (scm_source_properties (expr), quotee); }
LLVMValueRef gen_simpledef(struct node *ast) { LLVMValueRef global, init; global = find_or_add_global(ast->one->val); init = LLVMConstShl(codegen(ast->two), CONST(WORDPOW)); LLVMSetInitializer(global, init); return NULL; }
static void init_const_sym_pointers(void) { uint32_t i, j; for (i = 0; i < classes_cnt_g; ++i) { for (j = 0; j < classes_g[i].syms_static_cnt; ++j) { if (classes_g[i].syms_static[j].const_flag) { classes_g[i].syms_static[j].value = CONST( classes_g[i].syms_static[j].const_ptr); } } } }
LLVMValueRef gen_not(struct node *ast) { LLVMValueRef truth; truth = LLVMBuildICmp(builder, LLVMIntEQ, codegen(ast->one), CONST(0), ""); return LLVMBuildZExt(builder, truth, TYPE_INT, ""); }
static LLVMValueRef make_str(const char *str) { LLVMValueRef global, strval, chars[MAX_STRSIZE]; const char *p; int size = 0; /* Skip leading " */ p = str + 1; while (p && size < MAX_STRSIZE - 1) chars[size++] = CONST(pack_char(&p)); chars[size++] = CONST(EOT); global = LLVMAddGlobal(module, TYPE_ARRAY(size), ".gstr"); LLVMSetLinkage(global, LLVMPrivateLinkage); strval = LLVMConstArray(TYPE_INT, chars, size); LLVMSetInitializer(global, strval); return lvalue_to_rvalue(global); }
LLVMValueRef gen_predec(struct node *ast) { LLVMValueRef result; result = LLVMBuildSub(builder, codegen(ast->one), CONST(1), ""); check_store(result, lvalue(ast->one)); return result; }
LLVMValueRef gen_postdec(struct node *ast) { LLVMValueRef orig, result; orig = codegen(ast->one); result = LLVMBuildSub(builder, orig, CONST(1), ""); check_store(result, lvalue(ast->one)); return orig; }
LLVMValueRef gen_cond(struct node *ast) { LLVMValueRef truth; truth = LLVMBuildICmp(builder, LLVMIntNE, codegen(ast->one), CONST(0), ""); return LLVMBuildSelect(builder, truth, codegen(ast->two), codegen(ast->three), ""); }
static SCM expand (SCM exp, SCM env) { if (scm_is_pair (exp)) { SCM car; scm_t_macro_primitive trans = NULL; SCM macro = SCM_BOOL_F; car = CAR (exp); if (scm_is_symbol (car)) macro = expand_env_ref_macro (env, car); if (scm_is_true (macro)) trans = scm_i_macro_primitive (macro); if (trans) return trans (exp, env); else { SCM arg_exps = SCM_EOL; SCM args = SCM_EOL; SCM proc = CAR (exp); for (arg_exps = CDR (exp); scm_is_pair (arg_exps); arg_exps = CDR (arg_exps)) args = scm_cons (expand (CAR (arg_exps), env), args); if (scm_is_null (arg_exps)) return CALL (scm_source_properties (exp), expand (proc, env), scm_reverse_x (args, SCM_UNDEFINED)); else syntax_error ("expected a proper list", exp, SCM_UNDEFINED); } } else if (scm_is_symbol (exp)) { SCM gensym = expand_env_lexical_gensym (env, exp); if (scm_is_true (gensym)) return LEXICAL_REF (SCM_BOOL_F, exp, gensym); else return TOPLEVEL_REF (SCM_BOOL_F, exp); } else return CONST (SCM_BOOL_F, exp); }
LLVMValueRef gen_ivals(struct node *ast) { LLVMValueRef *ival_list; int size, i; size = count_chain(ast); ival_list = calloc(sizeof(LLVMValueRef), size); if (size > 0 && ival_list == NULL) generror("out of memory"); for (i = 0; i < size; i++, ast = ast->two) ival_list[i] = codegen(ast->one); /* TODO: Figure out how to initialize int with vector without error */ /*return LLVMConstArray(TYPE_INT, ival_list, size);*/ return size ? ival_list[0] : CONST(0); }
LLVMValueRef gen_vecdef(struct node *ast) { LLVMValueRef global, array, init, *ival_list; struct node *n; int size, initsize, i; initsize = count_chain(ast->three); if (ast->two) size = LLVMConstIntGetZExtValue(codegen(ast->two)); else size = 0; if (initsize > size) size = initsize; ival_list = calloc(sizeof(LLVMValueRef), size); if (size > 0 && ival_list == NULL) generror("out of memory"); for (i = 0, n = ast->three; i < initsize; i++, n = n->two) /* TODO: handle NAMES (convert global pointer to int) */ ival_list[initsize - i - 1] = codegen(n->one); for (i = initsize; i < size; i++) ival_list[i] = CONST(0); global = find_or_add_global(ast->one->val); array = LLVMAddGlobal(module, TYPE_ARRAY(size), ".gvec"); LLVMSetLinkage(array, LLVMPrivateLinkage); if (initsize) init = LLVMConstArray(TYPE_INT, ival_list, size); else init = LLVMConstNull(TYPE_ARRAY(size)); LLVMSetInitializer(array, init); LLVMSetInitializer(global, LLVMBuildPtrToInt(builder, array, TYPE_INT, "")); return NULL; }
bool kexe_load(const char *filename) { FILE *f; f = fopen(filename, "rb"); if (f == NULL) { vm_error("Filename \"%s\" does not exists.\n", filename); return (false); } if (!kexe_load_magic(f)) { vm_error("kexe_load_magic has failed.\n"); goto error; } if (!kexe_load_classes(f)) { vm_error("kexe_load_classes has failed.\n"); goto error; } if (!kexe_load_const_table(f)) { vm_error("kexe_load_const_table has failed.\n"); goto error; } if (!kexe_load_bc_arr(f)) { vm_error("kexe_load_bc_arr has failed.\n"); goto error; } init_const_sym_pointers(); assert(IS_NIL(CONST(0))); fclose(f); return (true); error: /* cleanup */ /* TODO: cleanup */ fclose(f); return (false); }
static SCM expand_or (SCM expr, SCM env SCM_UNUSED) { SCM tail = CDR (expr); const long length = scm_ilength (tail); ASSERT_SYNTAX (length >= 0, s_bad_expression, expr); if (scm_is_null (CDR (expr))) return CONST (SCM_BOOL_F, SCM_BOOL_F); else { SCM tmp = scm_gensym (SCM_UNDEFINED); return LET (SCM_BOOL_F, scm_list_1 (tmp), scm_list_1 (tmp), scm_list_1 (expand (CADR (expr), env)), CONDITIONAL (SCM_BOOL_F, LEXICAL_REF (SCM_BOOL_F, tmp, tmp), LEXICAL_REF (SCM_BOOL_F, tmp, tmp), expand_or (CDR (expr), scm_acons (tmp, tmp, env)))); } }
#define OS_START_SEC_CODE #include "tpl_memmap.h" /** * Function used to call the application error hook * * @param error error code which raised the hook call * * Do not call it directly, use #PROCESS_ERROR macro * * @see #PROCESS_ERROR */ FUNC(void, OS_CODE) tpl_call_error_hook( CONST(tpl_status, AUTOMATIC) error) { /** * This flag is used to avoid error hook call recursion */ STATIC VAR(tpl_bool, AUTOMATIC) in_error_hook = FALSE; if (!in_error_hook) { #if WITH_MEMORY_PROTECTION == YES tpl_kern.running_trusted = 1; #endif /* WITH_MEMORY_PROTECTION == YES */ in_error_hook = TRUE; ErrorHook(error); #if WITH_MEMORY_PROTECTION == YES
* @section infos File informations * * $Date$ * $Rev$ * $Author$ * $URL$ */ #include "tpl_os_os.h" #include "tpl_os_kernel.h" #include "tpl_machine_interface.h" #define API_START_SEC_CODE #include "tpl_memmap.h" extern FUNC(void, OS_CODE) tpl_start_os(CONST(AppModeType, AUTOMATIC) mode); /** * Starts Trampoline * * @param mode chosen application mode * * see paragraph 13.7.2.2 page 66 of OSEK/VDX 2.2.2 spec */ FUNC(void, OS_CODE) StartOS( CONST(AppModeType, AUTOMATIC) mode) { GET_CURRENT_CORE_ID(core_id) if (tpl_current_os_state(CORE_ID_OR_NOTHING(core_id)) == OS_INIT) {
#include "tpl_os_definitions.h" #if WITH_SYSTEM_CALL == NO #include "tpl_os_event.h" #include "tpl_os_event_kernel.h" #define API_START_SEC_CODE #include "tpl_memmap.h" /* * SetEvent */ FUNC(StatusType, OS_CODE) SetEvent( CONST(TaskType, AUTOMATIC) task_id, CONST(EventMaskType, AUTOMATIC) event) { StatusType result = tpl_set_event_service(task_id, event); return result & OSEK_STATUS_MASK; } /* * ClearEvent * see paragraph 13.5.3.2, page 61 of OSEK spec 2.2.2 */ FUNC(StatusType, OS_CODE) ClearEvent( CONST(EventMaskType, AUTOMATIC) event) { return tpl_clear_event_service(event);
#include "tpl_memmap.h" /* * GetActiveApplicationMode return the active application mode */ FUNC(AppModeType, OS_CODE) GetActiveApplicationMode(void) { return tpl_get_active_application_mode_service(); } /* * StartOS can be called by the app to start the OS in * an appropriate mode. */ FUNC(void, OS_CODE) tpl_start_os( CONST(AppModeType, AUTOMATIC) mode) { tpl_start_os_service(mode); } /* * ShutdownOS can be called by the app to shutdown it */ FUNC(void, OS_CODE) ShutdownOS( CONST(StatusType, AUTOMATIC) error /*@unused@*/ ) { tpl_shutdown_os_service(error); } #define OS_STOP_SEC_CODE
#define OS_STOP_SEC_VAR_UNSPECIFIED #include "tpl_memmap.h" #define OS_START_SEC_CODE #include "tpl_memmap.h" /** * @internal * * tpl_release_all_resources releases all the resources got by a process * Since this function is called when the proccess is killed, the priority * of the process is not changed by this function. * No rescheduling is done. */ FUNC(void, OS_CODE) tpl_release_all_resources( CONST(tpl_proc_id, AUTOMATIC) proc_id) { /* Get the resource pointer of the process */ P2VAR(tpl_resource, AUTOMATIC, OS_APPL_DATA) res = tpl_dyn_proc_table[proc_id]->resources; #if WITH_TRACE == YES VAR(tpl_resource_id, AUTOMATIC) res_id; #endif /* WITH_TRACE */ if (res != NULL) { tpl_dyn_proc_table[proc_id]->resources = NULL; do { CONSTP2VAR(tpl_resource, AUTOMATIC, OS_APPL_DATA) next_res =
Value * arch_load16_aligned(cpu_t *cpu, Value *addr, BasicBlock *bb) { Value *shift = arch_get_shift16(cpu, addr, bb); Value *val = arch_load32_aligned(cpu, AND(addr, CONST(~3ULL)), bb); return TRUNC16(LSHR(val, shift)); }