| OLD | NEW |
| (Empty) | |
| 1 # -*- python -*- |
| 2 # Copyright (c) 2012 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('env') |
| 7 |
| 8 # |
| 9 # |
| 10 # Build on x86 only. |
| 11 # |
| 12 # |
| 13 if not env.Bit('target_x86'): |
| 14 Return() |
| 15 |
| 16 # General adjustments to the environment for builds. |
| 17 |
| 18 # TODO(khim): eliminate need for the following piece |
| 19 # See http://code.google.com/p/nativeclient/issues/detail?id=2718 for details. |
| 20 if env.Bit('windows'): |
| 21 env.FilterOut(CCFLAGS=['/O1']) |
| 22 # XCode 4.2 takes too long to compile with -Os, LLVM for MacOS times out. |
| 23 if env.Bit('mac') or env.Bit('asan'): |
| 24 env.FilterOut(CCFLAGS=['-Os']) |
| 25 |
| 26 # Defines the source directory where validator generated files should be added. |
| 27 rl_src_dir = '$OBJ_ROOT/src/trusted/validator_ragel' |
| 28 val_src_dir = '$MAIN_DIR/src/trusted/validator_ragel/gen' |
| 29 |
| 30 # Source generation: |
| 31 # |
| 32 # valgen : Regenerate any autogenerated source files. |
| 33 |
| 34 generate = False |
| 35 if ('valgen' in COMMAND_LINE_TARGETS) or ('valclean' in COMMAND_LINE_TARGETS): |
| 36 generate = True |
| 37 |
| 38 if generate: |
| 39 # Set of generated (source) decoder automatas. |
| 40 automatas = [] |
| 41 |
| 42 # Source generation step 1: Build generator of ragel files. |
| 43 # |
| 44 # We have generator which reads .def files and produced automata definition. |
| 45 # |
| 46 # Ragel is included in most Linux distributions, but it's not standard tool |
| 47 # on MacOS/Windows thus we only support gneration of automata under Linux. |
| 48 # This also means that we don't need to make sure gen-dfa.cc is portable to |
| 49 # non-POSIX platforms (in particular it's not Windows compatible). |
| 50 |
| 51 env_gen_dfa = env.Clone() |
| 52 env_gen_dfa.Append(CCFLAGS=['-std=c++0x', '-DNACL_TRUSTED_BUT_NOT_TCB']) |
| 53 |
| 54 gen_dfa = env_gen_dfa.ComponentProgram( |
| 55 'gen-dfa', |
| 56 ['unreviewed/gen-dfa.cc']) |
| 57 |
| 58 # Source generation step 2: Generate decoder automatas. |
| 59 # |
| 60 # Now we are back to conditionally defining the large automatas generated |
| 61 # by gen-dfa. |
| 62 |
| 63 # Generate 32 and 64 bit versions of decoders and validators. |
| 64 for bits in ['32', '64']: |
| 65 for automata in ['decoder', 'validator']: |
| 66 # We are cheating here: there are two autogenerated files: |
| 67 # .rl and -consts.c, but we only track .rl one. This is safe because |
| 68 # -consts.c file includes constants referenced by .rl file and if .rl |
| 69 # file is not changed -consts.c is guaranteed to be the same (reverse |
| 70 # is not true). |
| 71 rl_file = '%s-x86_%s-instruction.rl' % (automata, bits) |
| 72 const_file = '%s/%s-x86_%s-instruction-consts.c' % ( |
| 73 val_src_dir, automata, bits) |
| 74 exe_path = '${STAGING_DIR}/${PROGPREFIX}gen-dfa${PROGSUFFIX}' |
| 75 env.Command( |
| 76 target=rl_file, |
| 77 source=[ |
| 78 exe_path, |
| 79 'unreviewed/general-purpose-instructions.def', |
| 80 'unreviewed/system-instructions.def', |
| 81 'unreviewed/x87-instructions.def', |
| 82 'unreviewed/mmx-instructions.def', |
| 83 'unreviewed/xmm-instructions.def', |
| 84 'unreviewed/nops.def'], |
| 85 action=[('${SOURCES[0]} -o ${TARGET} -c %s -m %s -d %s ${SOURCES[1]} ' |
| 86 '${SOURCES[2]} ${SOURCES[3]} ${SOURCES[4]} ${SOURCES[5]} ' |
| 87 '${SOURCES[6]}') % ( |
| 88 # Const file (-c): not tracked by SCONS (see above) |
| 89 const_file, |
| 90 # Argument for CPU type (-m): either "ia32" or "amd64". |
| 91 {'32': 'ia32', '64': 'amd64'}[bits], |
| 92 # Argument for actions selection (-d): selects only actions we need. |
| 93 {'decoder32': |
| 94 'check_access,opcode,parse_operands_states,mark_data_fields', |
| 95 'decoder64': |
| 96 'check_access,opcode,parse_operands_states,mark_data_fields', |
| 97 'validator32': |
| 98 ('check_access,opcode,parse_operands,parse_operands_states,' |
| 99 'instruction_name,mark_data_fields,nacl-forbidden,' |
| 100 'imm_operand_action,rel_operand_action'), |
| 101 'validator64': |
| 102 ('opcode,instruction_name,mark_data_fields,rel_operand_action,' |
| 103 'nacl-forbidden')}[automata+bits])] |
| 104 ) |
| 105 automatas.append(rl_file) |
| 106 c_file = '%s/%s-x86_%s.c' % (val_src_dir, automata, bits) |
| 107 env.Command( |
| 108 target=c_file, |
| 109 source=['unreviewed/%s-x86_%s.rl' % (automata, bits), rl_file], |
| 110 action=['ragel -G2 -I%s ${SOURCES[0]} -o ${TARGET}' % (rl_src_dir)] |
| 111 ) |
| 112 automatas.append(c_file) |
| 113 |
| 114 # Generate 32 and 64 bit versions of decoders and validators |
| 115 env.AlwaysBuild(env.Alias('valgen', automatas)) |
| 116 env.AlwaysBuild(env.Alias('valclean', action=[Delete(x) for x in automatas])) |
| 117 |
| 118 # Generate 32 and 64 bit versions of decoders and validators. |
| 119 for bits in ['32', '64']: |
| 120 for automata in ['decoder', 'validator']: |
| 121 env.ComponentLibrary('%s_x86_%s' % (automata, bits), |
| 122 ['gen/%s-x86_%s.c' % (automata, bits)]) |
| 123 |
| 124 env.ComponentProgram( |
| 125 'decoder-test', |
| 126 ['unreviewed/decoder-test.c'], |
| 127 EXTRA_LIBS=['decoder_x86_32', 'decoder_x86_64']) |
| 128 |
| 129 env.ComponentProgram( |
| 130 'validator-test', |
| 131 ['unreviewed/validator-test.c'], |
| 132 EXTRA_LIBS=['validator_x86_32', 'validator_x86_64']) |
| OLD | NEW |