src/Tools/Code/code_target.ML
changeset 55188 7ca0204ece66
parent 55153 eedd549de3ef
child 55291 82780e5f7622
child 55304 55ac31bc08a4
equal deleted inserted replaced
55187:6d0d93316daf 55188:7ca0204ece66
     6 
     6 
     7 signature CODE_TARGET =
     7 signature CODE_TARGET =
     8 sig
     8 sig
     9   val cert_tyco: theory -> string -> string
     9   val cert_tyco: theory -> string -> string
    10   val read_tyco: theory -> string -> string
    10   val read_tyco: theory -> string -> string
    11   val read_const_exprs: theory -> string list -> string list
       
    12 
    11 
    13   val export_code_for: theory -> Path.T option -> string -> int option -> string -> Token.T list
    12   val export_code_for: theory -> Path.T option -> string -> int option -> string -> Token.T list
    14     -> Code_Thingol.program -> Code_Symbol.T list -> unit
    13     -> Code_Thingol.program -> Code_Symbol.T list -> unit
    15   val produce_code_for: theory -> string -> int option -> string -> Token.T list
    14   val produce_code_for: theory -> string -> int option -> string -> Token.T list
    16     -> Code_Thingol.program -> Code_Symbol.T list -> (string * string) list * string option list
    15     -> Code_Thingol.program -> Code_Symbol.T list -> (string * string) list * string option list
   456 end; (* local *)
   455 end; (* local *)
   457 
   456 
   458 
   457 
   459 (* code generation *)
   458 (* code generation *)
   460 
   459 
   461 fun read_const_exprs thy const_exprs =
       
   462   let
       
   463     val (cs1, cs2) = Code_Thingol.read_const_exprs thy const_exprs;
       
   464     val program = Code_Thingol.consts_program thy true cs2;
       
   465     val cs3 = Code_Thingol.implemented_deps program;
       
   466   in union (op =) cs3 cs1 end;
       
   467 
       
   468 fun prep_destination "" = NONE
   460 fun prep_destination "" = NONE
   469   | prep_destination s = SOME (Path.explode s);
   461   | prep_destination s = SOME (Path.explode s);
   470 
   462 
   471 fun export_code thy cs seris =
   463 fun export_code thy cs seris =
   472   let
   464   let
   473     val program = Code_Thingol.consts_program thy false cs;
   465     val program = Code_Thingol.consts_program thy cs;
   474     val _ = map (fn (((target, module_name), some_path), args) =>
   466     val _ = map (fn (((target, module_name), some_path), args) =>
   475       export_code_for thy some_path target NONE module_name args program (map Constant cs)) seris;
   467       export_code_for thy some_path target NONE module_name args program (map Constant cs)) seris;
   476   in () end;
   468   in () end;
   477 
   469 
   478 fun export_code_cmd raw_cs seris thy = export_code thy (read_const_exprs thy raw_cs)
   470 fun export_code_cmd raw_cs seris thy = export_code thy
       
   471   (Code_Thingol.read_const_exprs thy raw_cs)
   479   ((map o apfst o apsnd) prep_destination seris);
   472   ((map o apfst o apsnd) prep_destination seris);
   480 
   473 
   481 fun produce_code thy cs target some_width some_module_name args =
   474 fun produce_code thy cs target some_width some_module_name args =
   482   let
   475   let
   483     val program = Code_Thingol.consts_program thy false cs;
   476     val program = Code_Thingol.consts_program thy cs;
   484   in produce_code_for thy target some_width some_module_name args program (map Constant cs) end;
   477   in produce_code_for thy target some_width some_module_name args program (map Constant cs) end;
   485 
   478 
   486 fun present_code thy cs syms target some_width some_module_name args =
   479 fun present_code thy cs syms target some_width some_module_name args =
   487   let
   480   let
   488     val program = Code_Thingol.consts_program thy false cs;
   481     val program = Code_Thingol.consts_program thy cs;
   489   in present_code_for thy target some_width some_module_name args program (map Constant cs, syms) end;
   482   in present_code_for thy target some_width some_module_name args program (map Constant cs, syms) end;
   490 
   483 
   491 fun check_code thy cs seris =
   484 fun check_code thy cs seris =
   492   let
   485   let
   493     val program = Code_Thingol.consts_program thy false cs;
   486     val program = Code_Thingol.consts_program thy cs;
   494     val _ = map (fn ((target, strict), args) =>
   487     val _ = map (fn ((target, strict), args) =>
   495       check_code_for thy target strict args program (map Constant cs)) seris;
   488       check_code_for thy target strict args program (map Constant cs)) seris;
   496   in () end;
   489   in () end;
   497 
   490 
   498 fun check_code_cmd raw_cs seris thy = check_code thy (read_const_exprs thy raw_cs) seris;
   491 fun check_code_cmd raw_cs seris thy = check_code thy
       
   492   (Code_Thingol.read_const_exprs thy raw_cs) seris;
   499 
   493 
   500 local
   494 local
   501 
   495 
   502 val parse_const_terms = Scan.repeat1 Args.term
   496 val parse_const_terms = Scan.repeat1 Args.term
   503   >> (fn ts => fn thy => map (Code.check_const thy) ts);
   497   >> (fn ts => fn thy => map (Code.check_const thy) ts);