Skip to content

Types corresponding to the compiler's target machine#755

Closed
mshinwell wants to merge 3 commits intoocaml:trunkfrom
mshinwell:target_system
Closed

Types corresponding to the compiler's target machine#755
mshinwell wants to merge 3 commits intoocaml:trunkfrom
mshinwell:target_system

Conversation

@mshinwell
Copy link
Contributor

This pull request provides a module that is intended to be used when code needs to manipulate values of the same width as the compiler's target machine. I think an abstraction like this will be needed for full cross compilation support; in the meanwhile, it is needed by the forthcoming Asm_directives pull request.

@nojb
Copy link
Contributor

nojb commented Aug 11, 2016

Since this is internal to the compiler it can easily be improved later. But why not, in the interest of generality, provide a module Targetint with the same interface as Nativeint (augmented with your word_size and of_int_exn and other needed utilities) and defined by

module type TARGETINT = sig ... end
module Targetint : TARGETINT = struct
include
  (val
    (match Sys.word_size with
    | 32 -> (module Int32)
    | 64 -> (module Int64)
    | _ -> assert false) : T)
end

This would make it easy to replace Nativeint by Targetint in the native code backends.

@mshinwell
Copy link
Contributor Author

I was planning to have such an "int" module, but haven't had time. If someone wants to make a pull request against my branch I'll happily include it.

@xavierleroy
Copy link
Contributor

I fully agree with @nojb 's proposal: in order for this to be reusable for cross-compilation, we need a compilation unit called Targetint (the name Address doesn't make much sense), obtained by selection between first-class modules corresponding to Int32 and Int64 enriched with whatever extra operations debugger support needs. The type Targetint.t should be abstract, not a sum of int32 and int64.

Let's try to work as a group to produce this, rather than pushing the strict minimum needed for debugging support.

@mshinwell
Copy link
Contributor Author

@xavierleroy : My original idea was that Target_system would have (at least) two submodules: one Int and one Address. The rationale for that was to cope with any cases where the target's addressing range might be substantively different from the range of machine integers. I am now thinking that it's maybe a mistake two have two such types, and instead, in the "target integer" module have some values that define e.g. the maximum representable address. What do you think?

@xavierleroy
Copy link
Contributor

@mshinwell : I'm not sure what you have in mind with "the target's addressing range might be substantively different from the range of machine integers". Since the birth of OCaml we've assumed that pointers/addresses, tagged integers, and native integers have the same bit size (32 or 64). I don't think we could make good use of a platform like x32 where pointers are 32 bits and integers are 64 bits. So, I fell that Targetint is enough and we don't need Targetaddress in addition.

@mshinwell
Copy link
Contributor Author

@xavierleroy The x32 case was the sort of thing I was thinking of. Will comment on the other GPR and close this one.

@mshinwell mshinwell closed this Aug 12, 2016
EduardoRFS pushed a commit to esy-ocaml/ocaml that referenced this pull request Dec 17, 2021
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Sep 21, 2022
Force the version of re (needed for ocamlformat to behave properly).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants