dcsimg
Results 1 to 10 of 10
  1. #1

    Thread Starter
    Fanatic Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    623

    [WIP] LLVM bindings for VB6

    https://github.com/wqweto/VBLLVM/releases

    VBLLVM.dll in vbllvm-x86.[release|debug].zip is compiled with `stdcall` calling convention.

    There is a working basic sample in Module1.bas that show how to use LLVM to compile a function and how to interpret it vs JIT compile + execute.
    Code:
    Interpreter Result: 5
    MCJIT Result: 9
    ; ModuleID = 'my_module'
    source_filename = "my_module"
    target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
    
    define x86_stdcallcc i32 @sum(i32, i32) {
    entry:
      %tmp = add i32 %0, %1
      ret i32 %tmp
    }
    The sample dump function's IR (Intermediate Representation) and writes bytecode to Project1.bc which can be dumped with ..\..\lib\install-release\bin\llvm-dis.exe Project1.bc -o=con

    This is work in progress: will need a typelib to make all LLVM enums/types/functions available in VB6 projects and will need a complete Kaledoscope toy language sample implementatio
    Last edited by wqweto; Jul 6th, 2018 at 12:16 PM.

  2. #2
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,995

    Re: [WIP] LLVM bindings for VB6

    It's cool to see some good efforts towards an open source VB Compiler.
    Imagine what it would be like to set breakpoints in, or step through subclassing code;
    and then being able to hit stop/end/debug or continue, without crashing the IDE.

    VB6.tlb | Bulletproof Subclassing in the IDE (no thunks/assembly/DEP issues)

  3. #3
    Fanatic Member
    Join Date
    May 2014
    Location
    Preveza Greece
    Posts
    931

    Re: [WIP] LLVM bindings for VB6

    I am waiting to see how this can be used for M2000 interpreter. By the way here http://www.rosettacode.org/wiki/Cate...00_Interpreter you can find (at the end of page) code of M2000, running in an application M2000 Environment, written in VB6.

  4. #4
    Hyperactive Member
    Join Date
    Jul 2002
    Posts
    264

    Re: [WIP] LLVM bindings for VB6

    Can you explain in more simple terms how this can be used with vb6 projects? Are you aiming at creating a LLVM compiler for vb6 apps?

  5. #5
    Hyperactive Member
    Join Date
    Jul 2002
    Posts
    264

    Re: [WIP] LLVM bindings for VB6

    Quote Originally Posted by axisdj View Post
    Can you explain in more simple terms how this can be used with vb6 projects? Are you aiming at creating a LLVM compiler for vb6 apps?
    Anyone have insight on this?

    I see the sample can basically compile itself. Does this mean I can compile parts of my vb6 app using llvm, how do the objects get put back together? can this work for a GUI app?

    Thanks
    WP

  6. #6
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,995

    Re: [WIP] LLVM bindings for VB6

    The project is a proof of concept testing out a portion of the LLVM tool-chain that has been partially adapted for use in VB.
    Mainly the JIT which converts the generated IM and Bytecode to machine language in memory, and then calls it.
    He posted the IR (Intermediate Representation) function in the original post.
    This part of the tool-chain is the critical part needed for edit and continue, etc.


    Also as mentioned in the first post - you still need to implement the portion that transforms your the VB code, into IR.
    More info on how transform VB to IR is here http://llvm.org/docs/tutorial/ and here http://llvm.org/docs/tutorial/OCamlLangImpl2.html
    Of course the examples are in C++ and targeting an example language (Kaleidoscope Toy Language).

    edit: I was hesitant to go the LLVM route myself - but I think Vlad is right by pushing the use of LLVM.
    It's a way to position the future of VB for the long haul. Otherwise it's stuck with a handmade parser, written by one person. (which is much simpler, and potentially faster, but less flexible)

    maybe wqweto can chime in to clear up anything I've misinterpreted.
    Last edited by DEXWERX; Jul 9th, 2018 at 02:03 PM.
    Imagine what it would be like to set breakpoints in, or step through subclassing code;
    and then being able to hit stop/end/debug or continue, without crashing the IDE.

    VB6.tlb | Bulletproof Subclassing in the IDE (no thunks/assembly/DEP issues)

  7. #7

    Thread Starter
    Fanatic Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    623

    Re: [WIP] LLVM bindings for VB6

    Quote Originally Posted by axisdj View Post
    Can you explain in more simple terms how this can be used with vb6 projects? Are you aiming at creating a LLVM compiler for vb6 apps?
    This would be a long shot to go straight to the moon. . .

    LLVM is a library to enable writing compiler backends, the machine code generating part of a compiler/interpreter. It has lots of benefits like fairly easy aiming different OSes (Windows vs Linux), different architectures (x86 vs x64) and different CPUs (Intel vs ARM). And it allows to interpret/JIT compile your (dynamic) language too.

    It's the main booster rocket for clang compiler, which can emulate both gcc and cl.exe and optimize the final output better than the originals. That's the reason most recent languages are developed with LLVM as backend (e.g. Rust, Zig, etc.)

    My first aim is to port Kaleidoscope toy language in VB6, make a cross-compiler which can produce both x86 and x64 binaries and then make an interpreter that can JIT compile sources while executing them straight. I've already done a similar cross-compiler lowering to Lua but the LLVM backend is going to take much more effort as first I have to finish the tooling before starting the toy compiler project.

    My second aim is to make a VBScript compiler, then extend it w/ types, then evolve it w/ features the way VB1 to VB6 has evolved until finally it can bootstrap itself - i.e. it can compile it's own sources and the produced binaries can compile these sources once again successfully.

    cheers,
    </wqw>

  8. #8

    Thread Starter
    Fanatic Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    623

    Re: [WIP] LLVM bindings for VB6

    Hi all,

    Second release 0.2 includes an auto-generated typelib (VBLLVM.tlb) that declares all the 800+ functions exported by the DLL, along with all the enums, structs and typedefs used by parameters/return types.

    The source IDL for the typelib is automatically generated by a gen_idl utility that includes a PEG parser compiled w/ VbPeg that parses LLVM's C/C++ header files to internal JSON representation and converts C/C++ data-types to VB6/IDL compatible ones.

    cheers,
    </wqw>

  9. #9
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,995

    Re: [WIP] LLVM bindings for VB6

    could you make it so the enums and structs use the same name as the typedef. Otherwise MIDL will auto generate the alias. kind of pollutes the symbol table

    just nitpicking of course.

    Code:
        typedef enum LLVMVisibility {
            LLVMDefaultVisibility,
            LLVMHiddenVisibility,
            LLVMProtectedVisibility,
        } LLVMVisibility;
    Imagine what it would be like to set breakpoints in, or step through subclassing code;
    and then being able to hit stop/end/debug or continue, without crashing the IDE.

    VB6.tlb | Bulletproof Subclassing in the IDE (no thunks/assembly/DEP issues)

  10. #10
    Addicted Member
    Join Date
    Jan 2015
    Posts
    133

    Re: [WIP] LLVM bindings for VB6

    Last edited by loquat; Jul 10th, 2018 at 08:19 PM. Reason: update links

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width