Skip to content
This repository
tag: v1164
Fetching contributors…

Cannot retrieve contributors at this time

file 61 lines (54 sloc) 2.02 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
(*
Copyright © 2011 MLstate

This file is part of OPA.

OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.

OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.

You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)

module SAP = SurfaceAstPassesTypes
module SAH = SurfaceAstHelper
module P = Passes

let noloc v = v, SurfaceAstCons.Label.builtin ()

let register_code ~special files srcs =
  let add_file map f =
    StringMap.add f.P.inputFile_filename f.P.inputFile_org_content map
  in
  let sources = List.fold_left add_file StringMap.empty srcs in
  (* Puts:
_ = (%%BslAppSrcCode.register_src_code%%)(fn, code)
at the beginning of [code].
*)
  let register_src_code f_name =
    let f_content =
      match StringMap.find_opt f_name sources with
      | Some content -> content
      | None -> OManager.error "Internal error: cannot find source code for @{<bright>%S@}" f_name
    in
    let bypass = SAH.bypass (
      if special then
        Opacapi.Opabsl.BslAppSrcCode.register_special_src_code
      else
        Opacapi.Opabsl.BslAppSrcCode.register_src_code
    )
    in
    let args_tuple = [ ("f2", noloc (SAH.string f_name))
                     ; ("f3", noloc (SAH.string f_content))
                     ]
    in
    let register = SAH.apply (noloc bypass, noloc args_tuple) in
    let nv = SAH.newval ([noloc SAH.patany, noloc register], false) in
    noloc nv
  in
  let register_file f =
    { f with
        SAP.parsedFile_lcode =
          register_src_code f.SAP.parsedFile_filename :: f.SAP.parsedFile_lcode
    }
  in
  List.map register_file files
Something went wrong with that request. Please try again.