Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Safe Haskell bindings for the `libgccjit` library

License

NotificationsYou must be signed in to change notification settings

Spydr06/libgccjit-haskell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Haskell bindings for thelibgccjit library

Example:

Examples are located in theexample/ directory. To compile an example, use:

$cabal run TutorialXX

The available examples are:

  • Tutorial01 "Hello world"(origin)
  • Tutorial02 Creating a trivial machine code function(origin)
  • Tutorial03 Loops and variables(origin)
  • Tutorial04 Adding JIT-compilation to a toy interpreter(origin)
  • Tutorial05 Implementing an Ahead-of-Time compiler(origin)

NoteAll the examples are ported from the officiallibgccjit tutorials. All credits go to the Freesoftware Foundation, Inc.

The "Hello World" example:

{-#LANGUAGE ForeignFunctionInterface #-}{- Ported from https://gcc.gnu.org/onlinedocs/jit/intro/tutorial01.html-}moduleMain (main)whereimportqualifiedGccJitimportGccJit.Utils (release)importForeign.PtrimportForeign.C (CString,newCString)importSystem.ExitimportSystem.IOtypeGreetFunction=CString->IO()foreignimport ccall"dynamic" mkFun::FunPtrGreetFunction->GreetFunctionunwrapOrDie::IO (Maybea)->String->IOaunwrapOrDie x msg=do    x'<- xcase x'ofNothing-> die msgJust x''->return x''createCode::PtrGccJit.Context->IO()createCode ctxt=do{-        Let's try to inject the equivalent of:        void greet (const char *name)        {            printf ("hello %s\n", name);        }-}    voidType<-GccJit.contextGetType ctxtGccJit.Void    constCharPtrType<-GccJit.contextGetType ctxtGccJit.ConstCharPtr    paramName<-GccJit.contextNewParam ctxt nullPtr constCharPtrType"format"    func<-GccJit.contextNewFunction ctxt nullPtrGccJit.FunctionExported voidType"greet" [paramName]False    paramFormat<-GccJit.contextNewParam ctxt nullPtr constCharPtrType"format"    intType<-GccJit.contextGetType ctxtGccJit.Int    printFunc<-GccJit.contextNewFunction ctxt nullPtrGccJit.FunctionImported intType"printf" [paramFormat]True    formatArg<-GccJit.contextNewStringLiteral ctxt"Hello %s!\n"    nameArg<-GccJit.paramAsRValue paramName    block<- unwrapOrDie (GccJit.functionNewBlock funcNothing)"NULL block"    printCall<-GccJit.contextNewCall ctxt nullPtr printFunc [formatArg, nameArg]GccJit.blockAddEval block nullPtr printCallGccJit.blockEndWithVoidReturn block nullPtrmain::IO()main=do-- Get a "context" object for working with the library.    ctxt<- unwrapOrDieGccJit.contextAcquire"NULL ctxt"-- Set some options on the context.-- Let's see the code being generated, in assembler form.GccJit.setBoolOption ctxtGccJit.DumpGeneratedCodeTrue-- Populate the context.    createCode ctxt-- Compile the code.    result<- unwrapOrDie (GccJit.contextCompile ctxt)"NULL result"-- Extract the generated code from "result".    greet<- unwrapOrDie (GccJit.resultGetCode result"greet")"NULL greet"-- Now call the generated function:    worldStr<- newCString"World"    mkFun greet worldStr    hFlush stdout    release ctxt    release result

Seeexamples/ for more example files.

License

libgccjit is part of the GCC project, which belongs to the Free Software Foundation, Inc. I take no credit of this software.

This code is licensed under the GNU General Public License V3. SeeLICENSE for more information.

About

Safe Haskell bindings for the `libgccjit` library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp