• j4k3@lemmy.world
    link
    fedilink
    English
    arrow-up
    5
    ·
    4 days ago

    How do languages in GCC map to hardware? Could I, for instance, write in Rust and compile for GCC-MSP430, or a 68k architecture?

    • Rossphorus@lemmy.world
      link
      fedilink
      English
      arrow-up
      7
      ·
      edit-2
      4 days ago

      Rust has support for many embedded targets. I can personally vouch for the MSP430. Rust compiles down to an intermediate language which can then use the same compilers and linkers as C. For instance when compiling Rust for the MSP430, GCC-MSP430 is actually part of the toolchain.

      • j4k3@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        ·
        4 days ago

        Thanks. What is this intermediate language you speak of? That sounds curious if it could be approached casually.

          • j4k3@lemmy.world
            link
            fedilink
            English
            arrow-up
            1
            ·
            4 days ago

            Probably a silly question, but why isn’t this intermediate representation of LLVM created in hardware, or is it?

            • bitcrafter@programming.dev
              link
              fedilink
              arrow-up
              5
              ·
              4 days ago

              The IR is designed to be easy to optimize, not easy for a real machine to execute. Among other things, it assumes it has access to an infinite number of registers so that it never needs to (and in fact is not allowed to) write a new value into a previously used register.

              • j4k3@lemmy.world
                link
                fedilink
                English
                arrow-up
                1
                ·
                4 days ago

                Thanks. It sounds like an interesting architecture to look into how the rest is abstracted within the CPU basics like ALU, timers, flags, and interrupts

                • bitcrafter@programming.dev
                  link
                  fedilink
                  arrow-up
                  2
                  ·
                  10 hours ago

                  It’s not really an architecture that is intended to map into anything in existing hardware, but having said that, Mill Computing is working on a new extremely unconventional architecture that is a lot closer to this; you can read more about it here, and specifically the design of the register file (which resembles a convener belt) is discussed here.

            • sugar_in_your_tea@sh.itjust.works
              link
              fedilink
              arrow-up
              1
              ·
              4 days ago

              There was (is?) an interpreter for llvm code, but code at that level hasn’t really gone through optimization, which will be specific to each compile target.

    • anton@lemmy.blahaj.zone
      link
      fedilink
      arrow-up
      6
      ·
      4 days ago

      I think both gcc and clang are roughly build around the C memory model.
      If you want to interface with hardware you probably do volatile reads and writes to specific memory addresses.
      You should be able to compile for most gcc supported platforms.