| OLD | NEW |
| (Empty) | |
| 1 # -*- python -*- |
| 2 # Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import os |
| 7 import sys |
| 8 Import('env') |
| 9 |
| 10 # |
| 11 # |
| 12 # Build on x86 only. |
| 13 # |
| 14 # |
| 15 if not env.Bit('target_x86'): |
| 16 Return() |
| 17 |
| 18 # General adjustments to the environment for builds. |
| 19 |
| 20 # TODO(khim): eliminate need for the following piece |
| 21 if env.Bit('windows'): |
| 22 env.FilterOut(CCFLAGS=['/O1']) |
| 23 env.Append(CCFLAGS=['/O0']) |
| 24 |
| 25 # Defines the source directory where validator generated files should be added. |
| 26 rl_src_dir = '$OBJ_ROOT/src/trusted/validator_ragel' |
| 27 val_src_dir = '$MAIN_DIR/src/trusted/validator_ragel/generated' |
| 28 |
| 29 # Source generation: |
| 30 # |
| 31 # valgen : Regenerate any autogenerated source files. |
| 32 |
| 33 gen_env = env.Clone(); |
| 34 gen_env.Append(CCFLAGS=['-DNACL_TRUSTED_BUT_NOT_TCB']) |
| 35 |
| 36 generate = False |
| 37 if 'valgen' in COMMAND_LINE_TARGETS: generate = True |
| 38 if 'valclean' in COMMAND_LINE_TARGETS: generate = True |
| 39 |
| 40 # Set of generated (source) decoder tables. |
| 41 tables = [] |
| 42 |
| 43 # Ragel generator: |
| 44 # |
| 45 # We have generator which reads .def files and produced automata definition. |
| 46 |
| 47 env_gen_dfa = env.Clone() |
| 48 env_gen_dfa.Append(CCFLAGS=['-std=c++0x', '-DNACL_TRUSTED_BUT_NOT_TCB']) |
| 49 |
| 50 gen_dfa = env_gen_dfa.ComponentProgram( |
| 51 'gen-dfa', |
| 52 ['unreviewed/gen-dfa.cc']) |
| 53 |
| 54 # Source generation step 2: Generate decoder tables. |
| 55 # |
| 56 # Now we are back to conditionally defining the large tables generated |
| 57 # by ncdecode_tablegen. |
| 58 |
| 59 # Generate 32 and 64 bit versions of decoders and validators. |
| 60 if generate: |
| 61 for bits in ['32', '64']: |
| 62 for automata in ['decoder', 'validator']: |
| 63 rl_file = '%s-x86_%s-instruction.rl' % (automata, bits) |
| 64 const_file = '%s/%s-x86_%s-instruction-consts.c' % ( |
| 65 rl_src_dir, automata, bits) |
| 66 exe_path = '${STAGING_DIR}/${PROGPREFIX}gen-dfa${PROGSUFFIX}' |
| 67 gen_env.Command( |
| 68 target=rl_file, |
| 69 source=[exe_path, |
| 70 'unreviewed/general-purpose-instructions.def', |
| 71 'unreviewed/system-instructions.def', |
| 72 'unreviewed/x87-instructions.def', |
| 73 'unreviewed/mmx-instructions.def', |
| 74 'unreviewed/xmm-instructions.def', |
| 75 'unreviewed/nops.def'], |
| 76 action=[('${SOURCES[0]} -o ${TARGET} -m %s -d %s ${SOURCES[1]} ' |
| 77 '${SOURCES[2]} ${SOURCES[3]} ${SOURCES[4]} ${SOURCES[5]} ' |
| 78 '${SOURCES[6]} && { ! test -e %s || mv -f %s %s ; }') % ( |
| 79 {'32': 'ia32', '64': 'amd64'}[bits], |
| 80 {'decoder32': |
| 81 'check_access,opcode,parse_operands_states,mark_data_fields', |
| 82 'decoder64': |
| 83 'check_access,opcode,parse_operands_states,mark_data_fields', |
| 84 'validator32': |
| 85 ('check_access,opcode,parse_operands,parse_operands_states,' |
| 86 'instruction_name,mark_data_fields,nacl-forbidden,' |
| 87 'imm_operand_action,rel_operand_action'), |
| 88 'validator64': |
| 89 'opcode,instruction_name,mark_data_fields,rel_operand_action,' + |
| 90 'nacl-forbidden'}[automata+bits], |
| 91 const_file, const_file, val_src_dir)] |
| 92 ) |
| 93 tables.append(rl_file) |
| 94 c_file = '%s/%s-x86_%s.c' % (val_src_dir, automata, bits) |
| 95 gen_env.Command( |
| 96 target=c_file, |
| 97 source=['unreviewed/%s-x86_%s.rl' % (automata, bits), rl_file], |
| 98 action=['ragel -G2 -I%s ${SOURCES[0]} -o ${TARGET}' % (rl_src_dir)] |
| 99 ) |
| 100 tables.append(c_file) |
| 101 |
| 102 # Generate 32 and 64 bit versions of decoders and validators |
| 103 gen_env.AlwaysBuild( |
| 104 gen_env.Alias('valgen', tables)) |
| 105 gen_env.AlwaysBuild( |
| 106 gen_env.Alias('valclean', action=[Delete(x) for x in tables])) |
| 107 |
| 108 # Generate 32 and 64 bit versions of decoders and validators. |
| 109 for bits in ['32', '64']: |
| 110 for automata in ['decoder', 'validator']: |
| 111 env.ComponentLibrary('%s-x86_%s' % (automata, bits), |
| 112 ['generated/%s-x86_%s.c' % (automata, bits)]) |
| 113 |
| 114 env.ComponentProgram( |
| 115 'decoder-test', |
| 116 ['unreviewed/decoder-test.c'], |
| 117 EXTRA_LIBS=['decoder-x86_32', 'decoder-x86_64']) |
| 118 |
| 119 env.ComponentProgram( |
| 120 'validator-test', |
| 121 ['unreviewed/validator-test.c'], |
| 122 EXTRA_LIBS=['validator-x86_32', 'validator-x86_64']) |
| OLD | NEW |