Page 3 of 3

Re: Compile for foreign systems.

Posted: Mon Jul 18, 2011 12:21 am
by netmaestro
I will definitely be avoiding bloat. This code compiled with GCC produces an 8k exe; PureBasic's equivalent, just the window and button, comes in at 18k:

Code: Select all

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <commctrl.h>

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
INITCOMMONCONTROLSEX icc;

char szClassName[ ] = "Windows App";

int WINAPI WinMain ( HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    InitCommonControlsEx(&icc);
    HWND button;
    HWND hwnd;
    MSG messages;
    WNDCLASSEX mywinclass;
    INT font;

    int windowx = GetSystemMetrics(SM_CXSCREEN)/2 - (640/2);
    int windowy = GetSystemMetrics(SM_CYSCREEN)/2 - (480/2);

    mywinclass.hInstance     = hThisInstance;
    mywinclass.lpszClassName = szClassName;
    mywinclass.lpfnWndProc   = WindowProcedure;
    mywinclass.style         = CS_DBLCLKS;
    mywinclass.cbSize        = sizeof (WNDCLASSEX);

    mywinclass.hIcon        = LoadIcon (NULL, IDI_APPLICATION);
    mywinclass.hIconSm      = LoadIcon (NULL, IDI_APPLICATION);
    mywinclass.hCursor      = LoadCursor (NULL, IDC_ARROW);
    mywinclass.lpszMenuName = NULL;
    mywinclass.cbClsExtra   = 0;
    mywinclass.cbWndExtra   = 0;
    mywinclass.hbrBackground = (HBRUSH) COLOR_WINDOW;

    if (!RegisterClassEx (&mywinclass))
        return 0;

    hwnd = CreateWindowEx (
           0,
           szClassName,
           "Windows App",
           WS_OVERLAPPEDWINDOW,
           windowx,
           windowy,
           640,
           480,
           HWND_DESKTOP,
           NULL,
           hThisInstance,
           NULL
           );

   button = CreateWindowEx (
           0,
           "BUTTON",
           "I can be pushed around",
           WS_CHILD | WS_VISIBLE,
           20,
           20,
           200,
           20,
           hwnd,
           NULL,
           hThisInstance,
           NULL
           );

    font = (INT)GetStockObject(DEFAULT_GUI_FONT);
    SendMessage(button,WM_SETFONT, font, 0);

    ShowWindow (hwnd, nCmdShow);

    while (GetMessage (&messages, NULL, 0, 0))
    {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }

    return messages.wParam;
}


LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_DESTROY:
            PostQuitMessage (0);
            break;
        default:
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

Re: Compile for foreign systems.

Posted: Mon Jul 18, 2011 12:52 am
by fsw
netmaestro wrote:I'm currently working on a compiler of my own, its output is ANSI C code which gets passed to GCC and theoretically it should be able to target Windows and Linux. But to get where I want to go with it will take years at the rate I'm going. I think the idea is sound enough though.
This is really funny... and I tell you why.

In this thread are (at least) 3 posters that work on compilers - just for fun.

Keep on coding :mrgreen:

Re: Compile for foreign systems.

Posted: Mon Jul 18, 2011 12:58 am
by Tenaja
I've seen some gcc output, and it can be rather sloppy. GCC is put together to be a do-all compiler, so it does not put out very efficient code. Well, at least not the target I was looking at. The target was a 32-bit mcu that contained operations for handling 64-bit vars, but gcc output code as if it could only handle 32 bits variables. It was pretty disappointing.

Re: Compile for foreign systems.

Posted: Mon Jul 18, 2011 1:01 am
by fsw
Tenaja wrote:I've seen some gcc output, and it can be rather sloppy. GCC is put together to be a do-all compiler, so it does not put out very efficient code. Well, at least not the target I was looking at. The target was a 32-bit mcu that contained operations for handling 64-bit vars, but gcc output code as if it could only handle 32 bits variables. It was pretty disappointing.
Did you look at TCC :?:
It has i32/x64/arm capabilities, don't know if it even optimizes though...

Re: Compile for foreign systems.

Posted: Mon Jul 18, 2011 1:03 am
by fsw
Suppose this thread will pretty soon be moved to offtopic :mrgreen:

Re: Compile for foreign systems.

Posted: Mon Jul 18, 2011 8:14 am
by idle
fsw wrote:
Tenaja wrote:I've seen some gcc output, and it can be rather sloppy. GCC is put together to be a do-all compiler, so it does not put out very efficient code. Well, at least not the target I was looking at. The target was a 32-bit mcu that contained operations for handling 64-bit vars, but gcc output code as if it could only handle 32 bits variables. It was pretty disappointing.
Did you look at TCC :?:
It has i32/x64/arm capabilities, don't know if it even optimizes though...
thats what llvm is for!
You just spit out butt ugly SSA asm, it optimizes it and you use the assembler and linker of your choice!