Skip to content
This repository
tree: 7f99541e97
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 286 lines (186 sloc) 9.195 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
(*
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/>.
*)

(** The main program for the OPA compiler. S3 version. *)

(* Opening the generic pass system. *)
module PH = PassHandler

(* FIXME: define a module InfixOperators in PassHandler *)
(* this could by the only case an 'open' is allowed *)
let (|+>) = PH.(|+>)
let (|>) = PH.(|>)
let (<?>) = PH.(<?>)
let (&) = PH.(&)
let (|?>) = PH.(|?>)
let (or) = PH.(or)

(* Shorthands for accessing options of compilation *)
module If = Main_utils.If

(* The deprecated passes *)
(* FIXME: adapt to the new PassHandler *)
module S2 = Passes

(* S3 implementations. *)
module S3 = S3Passes

(* Set title of generic pass system. *)
let _ = PH.set_title "Opa.exe"

(* Load warnings of opa s3 applications *)
let _ = WarningClass.load_set S3Warnings.warning_set

(* Run all passes *)
let () =
  (**********************************************)
  (* INITIALIZATION *****************************)
  PH.init

  |+> ("Welcome", S3.pass_Welcome)

  |+> ("CheckOptions", S3.pass_CheckOptions)

  |+> ("AddStdlibFiles", S3.pass_AddStdlibFiles)

  |> PH.old_handler
      "OpenFiles" S2.pass_OpenFiles

  |+> ("PreProcess", S3.pass_PreProcess)

  |+> ("Parse", S3.pass_Parse)

  |+> ("RegisterAppSrcCode", S3.pass_RegisterAppSrcCode)

  (**********************************************)
  (* SURFACE AST PASSES *************************)
  |> PH.handler ~count_time:false "LoadObjects" (S3.pass_LoadObjects (fun e -> e

    |+> ("BslLoading", S3.pass_BslLoading)

    |+> ("ConvertStructure", S3.pass_ConvertStructure)

    |> PH.old_handler
        "CheckOptionsConsistency" Pass_CheckOptionsConsistency.process_code

    |+> ("CheckServerEntryPoint", S3.pass_CheckServerEntryPoint)

    |+> ("ParserGeneration", S3.pass_ParserGeneration)

    |+> ("CheckDuplication", S3.pass_CheckDuplication)

    |+> ("ConvertStructure2", S3.pass_ConvertStructure2 ())

    |> PH.old_handler
        "ReplaceCompileTimeDirective" S2.pass_ReplaceCompileTimeDirective

    |> PH.old_if_handler
        "StaticInclusionDirectory" S2.pass_static_inclusion_directory

    |> PH.old_if_handler
        "StaticInclusions" S2.pass_static_inclusions

    |> PH.old_if_handler ~if_:If.server
        "ServerEntryPoint" S2.pass_resolve_server_entry_point

    (* inserting doctype directive for a collection later
currently always enable until an automated test verify that nobody breaks it
*)
    |+> ((*PH.old_if_handler ~if_:If.generate_interface, *)
        "AddDocApiDirectives", (S3.pass_AddDocApiDirectives ()))

    |> PH.old_if_handler
        "TupleTypeGeneration" S2.pass_tuple_types

    |+> ("Reorder", (S3.pass_ReorderToplevel ()))

    |+> ("RewriteModules", (S3.pass_RewriteModules ()))

    |> PH.old_if_handler ~if_:If.server
        "AddingServer" S2.pass_adding_server

    (**********************************************)
    (* QML AST PASSES *****************************)
    |+> ("SAtoQML", S3.pass_SaToQml)

    |+> ("AddCSS", S3.pass_AddCSS)

    |+> ("FunActionLifting", S3.pass_FunActionLifting)

    |+> ("TypesDefinitions", S3.pass_TypesDefinitions)

    |+> ("DbSchemaGeneration", S3.pass_DbSchemaGeneration)

    |+> ("DbPathCoercion", S3.pass_DbPathCoercion)

    |+> ("MacroExpansion", S3.pass_MacroExpansion)

    |+> ("Typing", S3.pass_Typing)

    (* Extracting interesting types for documentation *)
    |+> ("DocApiGeneration", S3.pass_DocApiGeneration)(*~if_:If.generate_interface*)

    |+> ("CheckPatternMatching", S3.pass_CheckPatternMatching)

    |+> ("WarnCoerce", S3.pass_WarnCoerce)

    |+> ("CompileRecursiveValues", S3.pass_CompileRecursiveValues)

    (*|+> ("Retyping", S3.pass_Retyping)*)

      |+> ("DbAccessorsGeneration", S3.pass_DbAccessorsGeneration)

      |+> ("DbCodeGeneration", S3.pass_DbCodeGeneration)

    (* could be just after typing, if dbgen didn't complain that it can't find its coercions :/ *)
    |+> ("PurgeTypeDirectivesAfterTyping", S3.pass_PurgeTypeDirectiveAfterTyping)

    |> PH.handler ~count_time:false "EndOfSeparateCompilation" (S3.pass_EndOfSeparateCompilation (fun e -> e

      |+> ("BypassHoisting", S3.pass_BypassHoisting)

      |+> ("RegisterFields", S3.pass_RegisterFields)

      |?> (If.undot,
           "Undot", S3.pass_QmlUndot)

      |+> ("CodingDirectives", S3.pass_CodingDirectives)

      <?> (If.closure,
          ("EnrichMagic", S3.pass_EnrichMagic),
          ("EnrichMagicPurge", S3.pass_EnrichMagicPurge))

      |+> ("SimplifyEquality", S3.pass_SimplifyEquality)

      |+> ("SimplifyMagic", S3.pass_SimplifyMagic)

      |+> ("JustReorder1", S3.pass_ReorderEnvGen)

      |> PH.old_if_handler
          "EarlyLambdaLifting" S2.pass_EarlyLambdaLifting

      (**********************************************)
      (* SLICED PASSES ******************************)
      <?> (If.server or If.separated or If.slicer_test,
          ("Slicing" , S3.pass_SimpleSlicer),
          ("NoSlicing", S3.pass_NoSlicer))

      |+> ("Assertion", S3.pass_Assertion)

      |?> (PH.neg (If.no_discard_of_unused_stdlib or If.separated),
           "SlicedCleaning", S3.pass_SlicedCleaning)

      (* Fun action resolution, step 2/3 *)
      |?> (If.server or If.separated,
           "FunActionEnvSerialize", S3.pass_FunActionEnvSerialize)

      (* Explicit instantiation *)
      |?> (If.explicit_instantiation,
           "ExplicitInstantiation", S3.pass_ExplicitInstantiation)

      |?> (If.explicit_instantiation,
           "OptimizeExplicitInstantiation", S3.pass_OptimizeExplicitInstantiation)

      (* Fun action resolution, step 3/3 *)
      |?> (If.server or If.separated,
           "FunActionJsCallGeneration", S3.pass_FunActionJsCallGeneration)

      |+> ("PurgeTypeDirectivesAfterEi", S3.pass_PurgeTypeDirectiveAfterEi)

      |?> (If.explicit_instantiation & (If.server or If.separated),
           "ResolveRemoteCalls", S3.pass_ResolveRemoteCalls)

      |?> (If.explicit_instantiation,
           "InsertMemoizedTypes", S3.pass_InsertMemoizedTypes)

      |+> ("JustReorder2", S3.pass_SlicedReorder)

      (* ***********************************************)
      (* FINAL COMPILATION *****************************)
      |+> ("SlicedToFinal", S3.pass_SlicedToFinal)

      (* ***********************************************)
      (* FINAL CLIENT COMPILATION **********************)
      (* ~precond:[check_ident_final_client] *)

      |?> (If.cps_client,
           "ClientQmlCpsRewriter", S3.pass_ClientCpsRewriter)

      |?> (If.closure,
           "ClientQmlLambdaLifting", S3.pass_ClientLambdaLifting)

(* |?> (If.closure,
"ClientQmlUncurry", S3.pass_ClientQmlUncurry)

|?> (If.closure,
"ClientQmlClosure", S3.pass_ClientQmlClosure)*)

      |?> (If.constant_sharing_client,
           "QmlClientConstantSharing", S3.pass_ClientQmlConstantSharing)
      (* Insert client code like a js string on server (if
necessary) - After that client qml code have no more
place to exist and it dropped *)
      |+> ("JavascriptCompilation", S3.pass_JavascriptCompilation)

      |?> (If.server or If.separated,
           "ResolveJsIdent", S3.pass_ResolveJsIdent)

      <?> (If.server or If.separated,
           ("GenerateServerAst", S3.pass_GenerateServerAst true),
           ("DontGenerateServerAst", S3.pass_GenerateServerAst false))

      (* ***********************************************)
      (* FINAL SERVER COMPILATION **********************)

      |+> ("CleanLambdaLiftingDirectives", S3.pass_CleanLambdaLiftingDirectives)

      |?> (If.init,
           "InitializeBslValues", S3.pass_InitializeBslValues)

      |+> ("ServerQmlCpsRewriter", S3.pass_ServerCpsRewriter)

      |> PH.old_if_handler ~if_:If.closure (* ~precond:[check_ident_final] *)
          "ServerQmlLambdaLifting" (S2.pass_LambdaLifting2 ~typed:false ~side:`server)

      |> PH.old_if_handler ~if_:If.closure
          "ServerQmlUncurry" (S2.pass_QmlUncurry2 ~typed:false ~side:`server)

      |?> (If.closure,
           "ServerQmlClosure", S3.pass_ServerQmlClosure)

      |?> (If.constant_sharing,
           "QmlConstantSharing", S3.pass_QmlConstantSharing)

      |+> ("QmlCompilation", S3.pass_QmlCompilation)

      |+> ("OcamlSplitCode", S3.pass_OcamlSplitCode)

      |+> ("OcamlGeneration", S3.pass_OcamlGeneration)

      |+> ("OcamlCompilation", S3.pass_OcamlCompilation)

      |+> ("CleanUp", S3.pass_CleanUp)

      |+> ("ByeBye", S3.pass_ByeBye)

      |> PH.return )) (* end of the pass endOfSeparateCompilation *)
    |> PH.return )) (* end of the pass loadObjects *)
  |> PH.return

let () = OManager.exit 0
Something went wrong with that request. Please try again.