[M3commit] [modula3/cm3] 9ee098: Add backend modes for standalone cm3-IR->llvm-IR t...

Jay K jay.krell at cornell.edu
Sun Aug 9 03:15:07 CEST 2015


I fixed Builder.m3 and cleaned it up a little.Hopefully didn't break the LLVM paths.

I think the model I followed for C is a good one.

I extended m3cgcat to have more output types, i.e. so it can input m3cg (same as before) and output C (new).

cm3cgcat is the Modula-3 BSD-licensed executable that canread the .mc files.

(Unfortunately we have no basis for BSD-licensed C/C++ reading .mc files.If someone could make a "preprocessor-friendly cm3cg description"outside of the m3cc directory, that'd be good..)

I used an existing mode: ExternalObject

I introduced a config variable:  USE_C_BACKEND_VIA_M3CGCAT  
Maybe not the best name.

And then conditionally replaced m3_backend in cm3cfg.common:

if USE_C_BACKEND_VIA_M3CGCATM3_BACKEND_MODE = "ExternalObject"

proc m3_backend(source, object, optimize, debug) is    ret_code = try_exec("m3cgcat", "-in-binary:" & source, "-out-c:" & source & ".c")    if not equal(ret_code, 0)        return ret_code    end    return compile_c(source & ".c", object, [ ], FALSE, TRUE)endend


Builder.m3 didn't need any changes to get everything working and forquicker turnaround on small changes. Efficiency compiling the entiretree was a bit off.

And then, I ran cm3, I guess cm3 -boot or cm3 -keep. It was a while ago. :)Generating a bunch of ".mc" files.

I then ran cm3cgat in my "inner loop".

Once things were further along, I added the C mode for efficiency,to avoid writing/reading the .mc files.
More likely I should have added a separate variable:  InternalBackend = "C".  
I think in your work, you'd again want the .mc files for the bulkof development time, and then you'd want, I think just one LLVM mode afterward,that constructs the LLVM IR in memory and writes out object files.

If you have the wherewithall to write LLVM IR bit code w/o linking to LLVM,then that might be another mode.

 - Jay



From: jay.krell at cornell.edu
To: rodney.m.bates at acm.org
CC: m3commit at elegosoft.com
Subject: RE: [M3commit] [modula3/cm3] 9ee098: Add backend modes for standalone cm3-IR->llvm-IR t...
Date: Sat, 8 Aug 2015 22:09:00 +0000




This or the previous seems to have broken the C mode.I'm debugging. - Jay




> Date: Thu, 6 Aug 2015 21:55:27 -0500
> From: rodney_bates at lcwb.coop
> To: jay.krell at cornell.edu
> CC: m3commit at elegosoft.com
> Subject: Re: [M3commit] [modula3/cm3] 9ee098: Add backend modes for standalone cm3-IR->llvm-IR t...
> 
> 
> 
> On 08/06/2015 04:28 PM, Jay wrote:
> > Not contradicting this necessarily but I'd like a separate flag to indicate save the IR, even if it isn't being used.
> >
> 
> Besides -keep?  Writing the cm3 IR, even when using a linked-in (to cm3) backend?
> That would not be hard.
> 
> > And then, indeed contradicting this, I wonder if "mode" is the right parameter. Maybe we can have "pipeline" and user lists a sequence of functions to call?
> >
> > Heck, maybe we should have quake functions for:
> >   save IR
> >   convert IR file to C in-proc
> >   convert IR file to LLVM IR
> >   save LLVM IR to file
> >   etc?
> >
> > Problem is that IR cannot be represented in quake?
> >
> 
> In working on this, I've thought about a Cartesian factoring of the various
> modes.  But there are already way more combinations than anybody has any
> use for now, or even likely use.  It does get complicated, figuring out
> the sequence of input and output file names, etc.  And it's full of stuff
> to include files in various intermediate formats that were not produced
> by the cm3 compiler.
> 
> >   - Jay
> >
> > On Aug 6, 2015, at 1:33 PM, Rodney Bates <rodney.m.bates at acm.org> wrote:
> >
> >>   Branch: refs/heads/master
> >>   Home:   https://github.com/modula3/cm3
> >>   Commit: 9ee0988a34e2ccfe8a0d95b9e12a249f8251be66
> >>       https://github.com/modula3/cm3/commit/9ee0988a34e2ccfe8a0d95b9e12a249f8251be66
> >>   Author: Rodney Bates <rodney.m.bates at acm.org>
> >>   Date:   2015-08-06 (Thu, 06 Aug 2015)
> >>
> >>   Changed paths:
> >>     M m3-sys/cm3/src/Builder.m3
> >>     M m3-sys/cm3/src/llvmdummy/LLGen.i3
> >>     M m3-sys/cm3/src/llvmdummy/LLGen.m3
> >>     M m3-sys/cm3/src/m3makefile
> >>     M m3-sys/cm3/src/version.quake
> >>     M m3-sys/cminstall/src/config-no-install/Unix.common
> >>     M m3-sys/m3middle/src/Target.i3
> >>
> >>   Log Message:
> >>   -----------
> >>   Add backend modes for standalone cm3-IR->llvm-IR translator executable.
> >>
> >> On branch master
> >> Changes to be committed:
> >>
> >>     modified:   m3-sys/cm3/src/Builder.m3
> >>     modified:   m3-sys/cm3/src/llvmdummy/LLGen.i3
> >>     modified:   m3-sys/cm3/src/llvmdummy/LLGen.m3
> >>     modified:   m3-sys/cm3/src/m3makefile
> >>     modified:   m3-sys/cm3/src/version.quake
> >>     modified:   m3-sys/cminstall/src/config-no-install/Unix.common
> >>     modified:   m3-sys/m3middle/src/Target.i3
> >>
> >> Add new backend modes StAloneLlvmAsm and StAloneLlvmObj.
> >> These produce cm3-IR (.ic/.mc) in cm3, run "m3llvm" as a separate executable,
> >> to translate to llvm-IR bitcode (.ib/.mb), run llc to compile that, and,
> >> in the case of StAloneLlvmAsm, run asm separately.
> >>
> >>
> >> _______________________________________________
> >> M3commit mailing list
> >> M3commit at elegosoft.com
> >> https://mail.elegosoft.com/cgi-bin/mailman/listinfo/m3commit
> >
> 
> -- 
> Rodney Bates
> rodney.m.bates at acm.org
 		 	   		   		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3commit/attachments/20150809/bb68cb96/attachment-0002.html>


More information about the M3commit mailing list