| 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 val_src_dir = '$MAIN_DIR/src/trusted/validator_ragel/generated' |
| 27 |
| 28 # Source generation: |
| 29 # |
| 30 # valgen : Regenerate any autogenerated source files. |
| 31 |
| 32 gen_env = env.Clone(); |
| 33 gen_env.Append(CCFLAGS=['-DNACL_TRUSTED_BUT_NOT_TCB']) |
| 34 |
| 35 generate = False |
| 36 if 'valgen' in COMMAND_LINE_TARGETS: generate = True |
| 37 if 'valclean' in COMMAND_LINE_TARGETS: generate = True |
| 38 |
| 39 # Set of generated (source) decoder tables. |
| 40 tables = [] |
| 41 |
| 42 # Ragel generator: |
| 43 # |
| 44 # We have generator which reads .def files and produced automata definition. |
| 45 |
| 46 env_gen_dfa = env.Clone() |
| 47 env_gen_dfa.Append(CCFLAGS=['-std=c++0x', '-DNACL_TRUSTED_BUT_NOT_TCB']) |
| 48 |
| 49 gen_dfa = env_gen_dfa.ComponentProgram( |
| 50 'gen-dfa', |
| 51 ['unreviewed/gen-dfa.cc']) |
| 52 |
| 53 # Source generation step 2: Generate decoder tables. |
| 54 # |
| 55 # Now we are back to conditionally defining the large tables generated |
| 56 # by ncdecode_tablegen. |
| 57 |
| 58 # Generate 32 and 64 bit versions of decoders and validators. |
| 59 if generate: |
| 60 for bits in ['32', '64']: |
| 61 for automata in ['decoder', 'validator']: |
| 62 rl_file = '%s/%s-x86_%s-instruction.rl' % (val_src_dir, automata, bits) |
| 63 exe_path = '${STAGING_DIR}/${PROGPREFIX}gen-dfa${PROGSUFFIX}' |
| 64 gen_env.Command( |
| 65 target=rl_file, |
| 66 source=[exe_path, |
| 67 'unreviewed/general-purpose-instructions.def', |
| 68 'unreviewed/system-instructions.def', |
| 69 'unreviewed/x87-instructions.def', |
| 70 'unreviewed/mmx-instructions.def', |
| 71 'unreviewed/xmm-instructions.def', |
| 72 'unreviewed/nops.def'], |
| 73 action=[('${SOURCES[0]} -o ${TARGET} -m %s -d %s ${SOURCES[1]} ' |
| 74 '${SOURCES[2]} ${SOURCES[3]} ${SOURCES[4]} ${SOURCES[5]} ' |
| 75 '${SOURCES[6]}') % ( |
| 76 {'32': 'ia32', '64': 'amd64'}[bits], |
| 77 {'decoder32': |
| 78 'check_access,opcode,parse_operands_states,mark_data_fields', |
| 79 'decoder64': |
| 80 'check_access,opcode,parse_operands_states,mark_data_fields', |
| 81 'validator32': |
| 82 ('check_access,opcode,parse_operands,parse_operands_states,' |
| 83 'instruction_name,mark_data_fields,nacl-forbidden,' |
| 84 'imm_operand_action,rel_operand_action'), |
| 85 'validator64': |
| 86 'opcode,instruction_name,mark_data_fields,rel_operand_action,' + |
| 87 'nacl-forbidden'}[automata+bits])] |
| 88 ) |
| 89 tables.append(rl_file) |
| 90 c_file = '%s/%s-x86_%s.c' % (val_src_dir, automata, bits) |
| 91 gen_env.Command( |
| 92 target=c_file, |
| 93 source=['unreviewed/%s-x86_%s.rl' % (automata, bits), rl_file], |
| 94 action=['ragel -G2 -I%s ${SOURCES[0]} -o ${TARGET}' % (val_src_dir)] |
| 95 ) |
| 96 tables.append(c_file) |
| 97 |
| 98 # Generate 32 and 64 bit versions of decoders and validators |
| 99 gen_env.AlwaysBuild( |
| 100 gen_env.Alias('valgen', tables)) |
| 101 gen_env.AlwaysBuild( |
| 102 gen_env.Alias('valclean', action=[Delete(x) for x in tables])) |
| 103 |
| 104 # Generate 32 and 64 bit versions of decoders and validators. |
| 105 for bits in ['32', '64']: |
| 106 for automata in ['decoder', 'validator']: |
| 107 env.ComponentLibrary('%s-x86_%s' % (automata, bits), |
| 108 ['generated/%s-x86_%s.c' % (automata, bits)]) |
| 109 |
| 110 env.ComponentProgram( |
| 111 'decoder-test', |
| 112 ['unreviewed/decoder-test.c'], |
| 113 EXTRA_LIBS=['decoder-x86_32', 'decoder-x86_64']) |
| 114 |
| 115 env.ComponentProgram( |
| 116 'validator-test', |
| 117 ['unreviewed/validator-test.c'], |
| 118 EXTRA_LIBS=['validator-x86_32', 'validator-x86_64']) |
| OLD | NEW |