jitgrammardefs.jcs
来自「This is a resource based on j2me embedde」· JCS 代码 · 共 876 行 · 第 1/3 页
JCS
876 行
////// @(#)jitgrammardefs.jcs 1.7 06/10/09//// Portions Copyright 2000-2008 Sun Microsystems, Inc. All Rights// Reserved. Use is subject to license terms.// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER// // This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License version// 2 only, as published by the Free Software Foundation.// // This program is distributed in the hope that it will be useful, but// WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// General Public License version 2 for more details (a copy is// included at /legal/license.txt).// // You should have received a copy of the GNU General Public License// version 2 along with this work; if not, write to the Free Software// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA// 02110-1301 USA// // Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa// Clara, CA 95054 or visit www.sun.com if you need additional// information or have any questions.////// converting CVM IR subset to RISC assembler//%{/* #define CVMJITCompileExpression_DEBUG 1 #define id(p) ((p)->tag)*/#ifndef CVM_INLINE#define CVM_INLINE /* */#ifdef __GNUC__#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 90)#undef CVM_INLINE#define CVM_INLINE inline#endif#endif /* __GNUC__ */#endif /* CVM_INLINE *//* * Some macros that create the regman register mask for some registers we use. */#undef ARG1#undef ARG2#undef ARG3#undef ARG4#undef RESULT1#undef RESULT2#define ARG1 (1U<<CVMCPU_ARG1_REG)#define ARG2 (1U<<CVMCPU_ARG2_REG)#define ARG3 (1U<<CVMCPU_ARG3_REG)#define ARG4 (1U<<CVMCPU_ARG4_REG)#define RESULT1 (1U<<CVMCPU_RESULT1_REG)#define RESULT2 (1U<<CVMCPU_RESULT2_REG)/* * Some useful constants. *//* offset of length field in array */#undef ARRAY_LENGTH_OFFSET#define ARRAY_LENGTH_OFFSET offsetof(CVMArrayOfAnyType, length)/* Array data offset */#undef ARRAY_DATA_OFFSET#define ARRAY_DATA_OFFSET offsetof(CVMArrayOfAnyType, elems)/* cb's offset in the object header */#undef OBJECT_CB_OFFSET#define OBJECT_CB_OFFSET offsetof(CVMObjectHeader, clas)/* MethodTable offset in cb */ #undef CB_VTBL_OFFSET#define CB_VTBL_OFFSET offsetof(CVMClassBlock, methodTablePtrX)#ifdef CVM_SEGMENTED_HEAP /* The offset */#undef GC_SEGMENT_CTV_OFFSET#define GC_SEGMENT_CTV_OFFSET offsetof(CVMGenSegment, cardTableVirtual)#endif/* Purpose: Verifies the condition, else throws a JIT error. */#define validateStack(condition, stackName) { \ CVMassert(condition); \ if (!(condition)) { \ CVMJITerror(con, CANNOT_COMPILE, #stackName " stack too small"); \ } \}#ifdef CVM_TRACE_JIT/* The following strings are used to emit codegen comments for the checks for each of the type of exceptions listed in the CVMJITIRTrapID enum list: */const char *const trapCheckComments[CVMJITIR_NUM_TRAP_IDS] = { "NULL check", "ArrayIndexOutOfBounds check", "DivideByZero check",};#endif#define IRRecordState(p,v) (p)->curRootCnt = (v)#define IRGetState(p) ((p)->curRootCnt)/* The following are for collecting stats about compilation stack usage: */#ifdef CVM_JIT_COLLECT_STATS#define INITIALIZE_STACK_STATS(name) \ int name##StackElements = 0;#define statsPushStack(name) { \ name##StackElements++; \ CVMJITstatsRecordUpdateMax(con, CVMJIT_STATS_ACTUAL_##name##_STACK_MAX, \ name##StackElements); \}#define statsPopStack(name) { \ name##StackElements--; \}#define statsPushResource() { \ int stackElements; \ stackElements = ((CVMInt8*)con->cgsp - (CVMInt8*)con->cgstackInit) / \ sizeof(struct CVMJITStackElement); \ CVMJITstatsRecordUpdateMax(con, CVMJIT_STATS_ACTUAL_RESOURCE_STACK_MAX, \ stackElements); \}#define statsPopResource()#else /* !CVM_JIT_COLLECT_STATS */#define INITIALIZE_STACK_STATS(name)#define statsPushStack(name)#define statsPopStack(name)#define statsPushResource()#define statsPopResource()#endif /* CVM_JIT_COLLECT_STATS */#define INITIALIZE_MATCH_STACK \ INITIALIZE_STACK_STATS(MATCH) \ struct CVMJITCompileExpression_match_computation_state* mcp = \ (struct CVMJITCompileExpression_match_computation_state*)\ (con->compilationStateStack);#define MATCH_PUSH( _p, op, l, r, n, arity ){ \ mcp->p = (_p); \ mcp->opcode = (op); \ mcp->subtrees[0] = (l); \ mcp->subtrees[1] = (r); \ mcp->which_submatch = (n); \ mcp++->n_submatch = (arity); \ statsPushStack(MATCH); \ validateStack(((void*)mcp < (void*)con->cgstackInit), Match); \}#define MATCH_POP( _p, op, l, r, n ) { \ statsPopStack(MATCH); \ _p = (--mcp)->p; \ op = mcp->opcode; \ l = mcp->subtrees[0]; \ r = mcp->subtrees[1]; \ n = mcp->which_submatch; \ CVMassert( (void*)mcp >= con->compilationStateStack );\}#define GET_MATCH_STACK_TOP (mcp-1)#define MATCH_STACK_EMPTY (mcp == con->compilationStateStack)#define INITIALIZE_GOAL_STACK \ goal_top = \ (struct CVMJITCompileExpression_rule_computation_state*)\ (con->compilationStateStack);#define GOAL_STACK_TOP \ ((struct CVMJITCompileExpression_rule_computation_state*)con->cgstackInit)#define GOAL_STACK_EMPTY (goal_top == con->compilationStateStack)#ifdef CVM_DEBUG_ASSERTS#define SET_ATTRIBUTE_TYPE(n, type_) \ goal_top->attributes[n].type = (type_)#else#define SET_ATTRIBUTE_TYPE(n, type_) ((void)0)#endif/* Purpose: Default synthesis action for chain rules */#define DEFAULT_SYNTHESIS_CHAIN(con, thisNode) \ DEFAULT_SYNTHESIS1(con, thisNode)/* Purpose: Default synthesis action for a rule with a unary node. */#define DEFAULT_SYNTHESIS1(con, thisNode) \ (thisNode)->regsRequired = submatch_roots[0]->regsRequired/* Purpose: Default synthesis action for a rule with a binary node. */#define DEFAULT_SYNTHESIS2(con, thisNode) \ (thisNode)->regsRequired = (submatch_roots[0]->regsRequired | \ submatch_roots[1]->regsRequired)#define IDENT_SYNTHESIS(con, thisNode) \{ \ if (!CVMJIT_JCS_DID_PHASE(IRGetState(thisNode), \ CVMJIT_JCS_STATE_SYNTHED)) \ { \ /* same as DEFAULT_SYNTHESIS_CHAIN */ \ DEFAULT_SYNTHESIS1(con, thisNode); \ } else { \ /* Leaf node */ \ } \}#define IDENT_INHERITANCE(con, thisNode) \{ \ CVMassert(!CVMJIT_DID_SEMANTIC_ACTION(thisNode)); \ DEFAULT_INHERITANCE_CHAIN(con, thisNode); \}#define DEFINE_SYNTHESIS(con, thisNode_) \ DEFAULT_SYNTHESIS1(con, thisNode_); \ { \ CVMJITIRNode* lhs = \ CVMJITirnodeValueOf(CVMJITirnodeGetLeftSubtree(thisNode_)); \ /* see if lhs is a USED node at the same spill location as the \ * DEFINE node. If so, then eager loading of the USED node is \ * a bad idea because it is already up-to-date and will never \ * be stored. \ */ \ if (CVMJITirnodeIsEndInlining(lhs)) { \ lhs = CVMJITirnodeGetLeftSubtree(lhs); \ } \ if (CVMJITirnodeIsUsedNode(lhs)) { \ CVMJITDefineOp* defineOp = CVMJITirnodeGetDefineOp(thisNode_); \ CVMJITUsedOp* usedOp = CVMJITirnodeGetUsedOp(lhs); \ if (usedOp->spillLocation == \ CVMJITirnodeGetUsedOp(CVMJITirnodeValueOf( \ defineOp->usedNode))->spillLocation) \ { \ /* this will prevent eager loading of the USED node \ * which may not get used before block exit. */ \ lhs->regsRequired = CVMCPU_AVOID_METHOD_CALL; \ } \ } \ }/* * Return the set of registers that the value should be computed into. * The main purpose of the function is to examine any decoration that * was put on the node to see if this node will have special register * requirements. computeTargetRegs((con), &(goal_top->attributes[0].u.rs), thisNode); \ */static voidcomputeTargetRegs( CVMJITCompilationContext* con, CVMJITCompileExpression_attribute * attr, CVMJITIRNode* node){ node = CVMJITirnodeValueOf(node); switch (node->decorationType) { case CVMJIT_REGHINT_DECORATION: { CVMInt16 targetReg = node->decorationData.regHint; if (targetReg == -1) { attr->u.rs.target = CVMRM_ANY_SET;#ifdef CVM_JIT_USE_FP_HARDWARE attr->u.rs.float_target = 1U << cnt;#endif } else { attr->u.rs.target = 1U << targetReg;#ifdef CVM_JIT_USE_FP_HARDWARE /* FIXME */ attr->u.rs.float_target = CVMRM_FP_ANY_SET;#endif } break; } default: attr->u.rs.target = CVMRM_ANY_SET;#ifdef CVM_JIT_USE_FP_HARDWARE attr->u.rs.float_target = CVMRM_FP_ANY_SET;#endif break; }}/* Purpose: Default inheritance action for chain rules */#define DEFAULT_INHERITANCE_CHAIN(con, thisNode) { \ if (GOAL_STACK_EMPTY) { \ SET_ATTRIBUTE_TYPE(0, CVMJIT_EXPRESSION_ATTRIBUTE_TARGET_AVOID); \ computeTargetRegs((con), &(goal_top->attributes[0]), thisNode); \
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?