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