[cfe-dev] Clang Configuration Manager

Renato Golin via cfe-dev cfe-dev at lists.llvm.org
Tue Oct 13 15:29:56 PDT 2015


On 13 October 2015 at 22:45, Cornel Punga <cornel.punga at gmail.com> wrote:
> If I understood correctly, the first thing to implement is a tool that
> gathers information about the target, like (you mentioned):
> - cpu, OS, etc.
> The information gathered at this step will be used to generate the JSON file
> / local database. Did I understood correctly?

Yes, when target == host. A simple Python script that knows how to
gather that information (Clang knows how to, you can either use a
similar logic or expose that as an API).


> On the step when target != host, I need to think and research more, because
> I do not have a clear image.

That's the hard part. :)

A simpler way to do this is to keep the database in git.

Let's say you wrote a script that gathers all needed config for Linux
on x86, ARM, MIPS and PPC. They should all be *very* similar.

   Step #1: Generate CFLAGS from that info

You can use it like llvm-config, ex:

$ clang++ -c foo.c `target-info --target=host`

This would get the host's config and output CFLAGS, which will be used
by the Clang command line.

   Step #2: Try remote execution (optional)

Assuming you have ssh access to an "arm-board":

$ clang++ -c foo.cpp `target-info --target=foo at arm-board.localdomain`

That would supposedly connect to the target running Linux and run the
same script, producing CFLAGS.

   Step #3: Generate a JSON file

x86$ target-info --name="i7" --target=host >> targets.json
panda$ target-info --name=pandaboard" --target=host >> targets.json
mips64$ target-info --name="mymips" --target=host >> targets.json

Concatenating all results into a JSON file, and then using that file,
say, in your home dir, default to something like ".llvm-targets.json"

$ cp targets.json .llvm-targets.json

$ clang++ -c foo.cpp `target-info --target=pandaboard`

This would look for the JSON file, find the "pandaboard" entry, and
then output the CFLAGS.

   Step #4: Clang integration

Once the JSON location is stabilised, make Clang read the file and set
internally the flags (no CFLAGS)

$ clang++ -target=pandaboard -c foo.cpp

Target will not be recognised by the front-end, then your module kicks
in and finds the .llvm-targets.json, finds the "pandaboard", applies
the flags.


You'll have to keep the JSON file pretty simple to be able to make
both CFLAGS and Internal Clang flags from the same source. Keeping
only standard names like "fpu": "vfpv3" is the best, then the script
and the Clang module know what to do by themselves.

hope this helps.

cheers,
--renato



More information about the cfe-dev mailing list