Archive for 3月 13th, 2013

  1. Hello, Win32 API(LLVM) World!

    Posted on 3月 13th, 2013 by cx20

    Win32 API(LLVM)

    Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。
    以下は LLVM Assembler による呼出し例である。

    ソースコード(LLVM)

    ; ModuleID = 'hello.c'
    target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S32"
    target triple = "i686-w64-mingw32"
     
    %struct.HWND__ = type { i32 }
     
    @.str = private unnamed_addr constant [24 x i8] c"Hello, Win32 API World!

    上記コードは、下記の C のソースを clang にてアセンブリコード出力(clang -S -O4 hello.c)したものである。

    ソースコード(C言語)

    #include <windows.h>
     
    int main( int argc, char* argv[] )
    {
        MessageBox( NULL, "Hello, Win32 API World!", "Hello, World!", MB_OK );
        return 0;
    }

    コンパイル方法(MinGW版 clang)

    C:¥> clang -o hello hello.ll

    実行結果

    ---------------------------
    Hello, World!
    ---------------------------
    Hello, Win32 API World!
    ---------------------------
    OK   
    ---------------------------