xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/jit/docs/intro/tutorial01.rst (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
1*8feb0f0bSmrg.. Copyright (C) 2014-2020 Free Software Foundation, Inc.
236ac495dSmrg   Originally contributed by David Malcolm <dmalcolm@redhat.com>
336ac495dSmrg
436ac495dSmrg   This is free software: you can redistribute it and/or modify it
536ac495dSmrg   under the terms of the GNU General Public License as published by
636ac495dSmrg   the Free Software Foundation, either version 3 of the License, or
736ac495dSmrg   (at your option) any later version.
836ac495dSmrg
936ac495dSmrg   This program is distributed in the hope that it will be useful, but
1036ac495dSmrg   WITHOUT ANY WARRANTY; without even the implied warranty of
1136ac495dSmrg   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1236ac495dSmrg   General Public License for more details.
1336ac495dSmrg
1436ac495dSmrg   You should have received a copy of the GNU General Public License
1536ac495dSmrg   along with this program.  If not, see
1636ac495dSmrg   <http://www.gnu.org/licenses/>.
1736ac495dSmrg
1836ac495dSmrg.. default-domain:: c
1936ac495dSmrg
2036ac495dSmrgTutorial part 1: "Hello world"
2136ac495dSmrg==============================
2236ac495dSmrg
2336ac495dSmrgBefore we look at the details of the API, let's look at building and
2436ac495dSmrgrunning programs that use the library.
2536ac495dSmrg
2636ac495dSmrgHere's a toy "hello world" program that uses the library to synthesize
2736ac495dSmrga call to `printf` and uses it to write a message to stdout.
2836ac495dSmrg
2936ac495dSmrgDon't worry about the content of the program for now; we'll cover
3036ac495dSmrgthe details in later parts of this tutorial.
3136ac495dSmrg
3236ac495dSmrg   .. literalinclude:: ../examples/tut01-hello-world.c
3336ac495dSmrg    :language: c
3436ac495dSmrg
3536ac495dSmrgCopy the above to `tut01-hello-world.c`.
3636ac495dSmrg
3736ac495dSmrgAssuming you have the jit library installed, build the test program
3836ac495dSmrgusing:
3936ac495dSmrg
4036ac495dSmrg.. code-block:: console
4136ac495dSmrg
4236ac495dSmrg  $ gcc \
4336ac495dSmrg      tut01-hello-world.c \
4436ac495dSmrg      -o tut01-hello-world \
4536ac495dSmrg      -lgccjit
4636ac495dSmrg
4736ac495dSmrgYou should then be able to run the built program:
4836ac495dSmrg
4936ac495dSmrg.. code-block:: console
5036ac495dSmrg
5136ac495dSmrg  $ ./tut01-hello-world
5236ac495dSmrg  hello world
53