/*	Copyright  (c)	Günter Woigk 2018 - 2021
					mailto:kio@little-bat.de

	This file is free software.

	Permission to use, copy, modify, distribute, and sell this software
	and its documentation for any purpose is hereby granted without fee,
	provided that the above copyright notice appears in all copies and
	that both that copyright notice, this permission notice and the
	following disclaimer appear in supporting documentation.

	THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY,
	NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
	A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE COPYRIGHT HOLDER
	BE LIABLE FOR ANY DAMAGES ARISING FROM THE USE OF THIS SOFTWARE,
	TO THE EXTENT PERMITTED BY APPLICABLE LAW.
*/

#pragma once
#include "kio/kio.h"
#include "Templates/HashMap.h"
#include "Templates/StrArray.h"


namespace pp
{

class Type;
using cType = const Type;

extern struct Target target;
extern struct Target* setTarget (cstr name);


/*
	Compilation Targets
*/

struct Target
{
	const cstr  name;	// const or tempmem
	const cstr  descr;	// const or tempmem

	const ByteOrder	byteorder;

	const uint  b2b;	// bit-to-byte shift
	const uint  bpb;	// bits per byte		 smallest addressable memory unit
	const uint  bpc;	// bits per char		 characters

	const uint  bps;	// bits per short int:	 smallest numeric type used in arithmetics
	const uint  bpi;	// bits per dflt. int:	 fastest type with min. 16 bits: array index
	const uint  bpl;	// bits per long int:	 largest supported type: file position, pointer diff

	const uint  bpf;	// bits per float:		 0 if no floats supported
	const uint  bpsf;	// bits per short float: ""
	const uint  bplf;	// bits per long float:	 ""

	const uint  bpp;	// bits per pointer


	static cType *const tint8,  *const tuint8,  *const tint16, *const tuint16;
	static cType *const tint32, *const tuint32, *const tint64, *const tuint64;
	static cType *const tvoid;

	// target depending types:
	cType* tfloat;		// -> bpsf	NULL if if target supports no floating point numbers
	cType* tsfloat;		// -> bpf	""
	cType* tlfloat;		// -> bplf	""

	// Target depending aliases:
	cType* tbyte;		// -> bpb
	cType* tshort;		// -> bps
	cType* tint;		// -> bpi
	cType* tlong;		// -> bpl
	cType* tubyte;		// -> bpb
	cType* tushort;		// -> bps
	cType* tuint;		// -> bpi
	cType* tulong;		// -> bpl

	// target depending sub types:
	cType* tbool;		// -> bpb
	cType* tchar;		// -> bpc
	cType* tcstr;

protected:
	Target (
			cstr name, cstr descr,
			ByteOrder,
			uint bpp,	// bits per pointer
			uint bpc,	// bits per character
			uint bpb,	// bits per byte, ubyte
			uint bps,	// bits per short,ushort
			uint bpi,	// bits per int,  uint
			uint bpl,	// bits per long, ulong
			cType*, 	// sfloat
			cType*, 	// float
			cType*);	// lfloat
};


} // namespace pp


















