aboutsummaryrefslogtreecommitdiffstats
path: root/src/ortho/llvm-nodebug/ortho_ident.adb
blob: e7b650539984b6e0b81fab6c28b08de236ace85f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
--  LLVM back-end for ortho.
--  Copyright (C) 2014 Tristan Gingold
--
--  GHDL is free software; you can redistribute it and/or modify it under
--  the terms of the GNU General Public License as published by the Free
--  Software Foundation; either version 2, or (at your option) any later
--  version.
--
--  GHDL is distributed in the hope that it will be useful, but WITHOUT ANY
--  WARRANTY; without even the implied warranty of MERCHANTABILITY or
--  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
--  for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with GCC; see the file COPYING.  If not, write to the Free
--  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
--  02111-1307, USA.

package body Ortho_Ident is
   type Chunk (Max : Positive);
   type Chunk_Acc is access Chunk;

   type Chunk (Max : Positive) is record
      Prev : Chunk_Acc;
      Len : Natural := 0;
      S : String (1 .. Max);
   end record;

   Cur_Chunk : Chunk_Acc := null;

   subtype Fat_String is String (Positive);

   function Get_Identifier (Str : String) return O_Ident
   is
      Len : constant Natural := Str'Length;
      Max : Positive;
      Org : Positive;
   begin
      if Cur_Chunk = null or else Cur_Chunk.Len + Len >= Cur_Chunk.Max then
         if Cur_Chunk = null then
            Max := 32 * 1024;
         else
            Max := 2 * Cur_Chunk.Max;
         end if;
         if Len + 2 > Max then
            Max := 2 * (Len + 2);
         end if;
         declare
            New_Chunk : Chunk_Acc;
         begin
            --  Do not use allocator by expression, as we don't want to
            --  initialize S.
            New_Chunk := new Chunk (Max);
            New_Chunk.Len := 0;
            New_Chunk.Prev := Cur_Chunk;
            Cur_Chunk := New_Chunk;
         end;
      end if;

      Org := Cur_Chunk.Len + 1;
      Cur_Chunk.S (Org .. Org + Len - 1) := Str;
      Cur_Chunk.S (Org + Len) := ASCII.NUL;
      Cur_Chunk.Len := Org + Len;

      return (Addr => Cur_Chunk.S (Org)'Address);
   end Get_Identifier;

   function Is_Equal (L, R : O_Ident) return Boolean
   is
   begin
      return L = R;
   end Is_Equal;

   function Get_String_Length (Id : O_Ident) return Natural
   is
      Str : Fat_String;
      pragma Import (Ada, Str);
      for Str'Address use Id.Addr;
   begin
      for I in Str'Range loop
         if Str (I) = ASCII.NUL then
            return I - 1;
         end if;
      end loop;
      raise Program_Error;
   end Get_String_Length;

   function Get_String (Id : O_Ident) return String
   is
      Str : Fat_String;
      pragma Import (Ada, Str);
      for Str'Address use Id.Addr;
   begin
      for I in Str'Range loop
         if Str (I) = ASCII.NUL then
            return Str (1 .. I - 1);
         end if;
      end loop;
      raise Program_Error;
   end Get_String;

   function Get_Cstring (Id : O_Ident) return System.Address is
   begin
      return Id.Addr;
   end Get_Cstring;

   function Is_Equal (Id : O_Ident; Str : String) return Boolean
   is
      Istr : Fat_String;
      pragma Import (Ada, Istr);
      for Istr'Address use Id.Addr;

      Str_Len : constant Natural := Str'Length;
   begin
      for I in Istr'Range loop
         if Istr (I) = ASCII.NUL then
            return I - 1 = Str_Len;
         end if;
         if I > Str_Len then
            return False;
         end if;
         if Istr (I) /= Str (Str'First + I - 1) then
            return False;
         end if;
      end loop;
      raise Program_Error;
   end Is_Equal;

   function Is_Nul (Id : O_Ident) return Boolean is
   begin
      return Id = O_Ident_Nul;
   end Is_Nul;

end Ortho_Ident;
lass="k">$(if $(wildcard $(GENERIC_PLATFORM_DIR)/backport-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER)) GENERIC_PATCH_DIR := $(GENERIC_PLATFORM_DIR)/pending$(if $(wildcard $(GENERIC_PLATFORM_DIR)/pending-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER)) GENERIC_HACK_DIR := $(GENERIC_PLATFORM_DIR)/hack$(if $(wildcard $(GENERIC_PLATFORM_DIR)/hack-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER)) GENERIC_FILES_DIR := $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR)/files $(GENERIC_PLATFORM_DIR)/files-$(KERNEL_PATCHVER)),"$(dir)") __config_name_list = $(1)/config-$(KERNEL_PATCHVER) $(1)/config-default __config_list = $(firstword $(wildcard $(call __config_name_list,$(1)))) find_kernel_config=$(if $(__config_list),$(__config_list),$(lastword $(__config_name_list))) GENERIC_LINUX_CONFIG = $(call find_kernel_config,$(GENERIC_PLATFORM_DIR)) LINUX_TARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_DIR)) ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR)) LINUX_SUBTARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_SUBDIR)) endif # config file list used for compiling LINUX_KCONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(TOPDIR)/env/kernel-config) # default config list for reconfiguring # defaults to subtarget if subtarget exists and target does not # defaults to target otherwise USE_SUBTARGET_CONFIG = $(if $(wildcard $(LINUX_TARGET_CONFIG)),,$(if $(LINUX_SUBTARGET_CONFIG),1)) LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG))) LINUX_RECONFIG_TARGET = $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG),$(LINUX_TARGET_CONFIG)) # select the config file to be changed by kernel_menuconfig/kernel_oldconfig ifeq ($(CONFIG_TARGET),platform) LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG)) LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG) endif ifeq ($(CONFIG_TARGET),subtarget) LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG)) LINUX_RECONFIG_TARGET = $(LINUX_SUBTARGET_CONFIG) endif ifeq ($(CONFIG_TARGET),subtarget_platform) LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(LINUX_TARGET_CONFIG)) LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG) endif ifeq ($(CONFIG_TARGET),env) LINUX_RECONFIG_LIST = $(LINUX_KCONFIG_LIST) LINUX_RECONFIG_TARGET = $(TOPDIR)/env/kernel-config endif __linux_confcmd = $(2) $(patsubst %,+,$(wordlist 2,9999,$(1))) $(1) LINUX_CONF_CMD = $(SCRIPT_DIR)/kconfig.pl $(call __linux_confcmd,$(LINUX_KCONFIG_LIST)) LINUX_RECONF_CMD = $(SCRIPT_DIR)/kconfig.pl $(call __linux_confcmd,$(LINUX_RECONFIG_LIST)) LINUX_RECONF_DIFF = $(SCRIPT_DIR)/kconfig.pl - '>' $(call __linux_confcmd,$(filter-out $(LINUX_RECONFIG_TARGET),$(LINUX_RECONFIG_LIST))) $(1) $(GENERIC_PLATFORM_DIR)/config-filter ifeq ($(DUMP),1) BuildTarget=$(BuildTargets/DumpCurrent) CPU_CFLAGS = -Os -pipe ifneq ($(findstring mips,$(ARCH)),) ifneq ($(findstring mips64,$(ARCH)),) CPU_TYPE ?= mips64 else CPU_TYPE ?= mips32 endif CPU_CFLAGS += -mno-branch-likely CPU_CFLAGS_mips32 = -mips32 -mtune=mips32 CPU_CFLAGS_mips64 = -mips64 -mtune=mips64 -mabi=64 CPU_CFLAGS_mips64r2 = -mips64r2 -mtune=mips64r2 -mabi=64 CPU_CFLAGS_4kec = -mips32r2 -mtune=4kec CPU_CFLAGS_24kc = -mips32r2 -mtune=24kc CPU_CFLAGS_74kc = -mips32r2 -mtune=74kc CPU_CFLAGS_octeonplus = -march=octeon+ -mabi=64 endif ifeq ($(ARCH),i386) CPU_TYPE ?= pentium-mmx CPU_CFLAGS_pentium-mmx = -march=pentium-mmx CPU_CFLAGS_pentium4 = -march=pentium4 endif ifneq ($(findstring arm,$(ARCH)),) CPU_TYPE ?= xscale endif ifeq ($(ARCH),powerpc) CPU_CFLAGS_603e:=-mcpu=603e CPU_CFLAGS_8540:=-mcpu=8540 CPU_CFLAGS_405:=-mcpu=405 CPU_CFLAGS_440:=-mcpu=440 CPU_CFLAGS_464fp:=-mcpu=464fp endif ifeq ($(ARCH),powerpc64) CPU_TYPE ?= powerpc64 CPU_CFLAGS_powerpc64:=-mcpu=powerpc64 endif ifeq ($(ARCH),sparc) CPU_TYPE = sparc CPU_CFLAGS_ultrasparc = -mcpu=ultrasparc endif ifeq ($(ARCH),aarch64) CPU_TYPE ?= generic CPU_CFLAGS_generic = -mcpu=generic CPU_CFLAGS_cortex-a53 = -mcpu=cortex-a53 endif ifeq ($(ARCH),arc) CPU_TYPE ?= arc700 CPU_CFLAGS += -matomic CPU_CFLAGS_arc700 = -mcpu=arc700 CPU_CFLAGS_archs = -mcpu=archs endif ifneq ($(CPU_TYPE),) ifndef CPU_CFLAGS_$(CPU_TYPE) $(warning CPU_TYPE "$(CPU_TYPE)" doesn't correspond to a known type) endif endif DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE))) ifneq ($(BOARD),) TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID)) $(TMP_CONFIG): $(LINUX_KCONFIG_LIST) $(LINUX_CONF_CMD) > $@ || rm -f $@ -include $(TMP_CONFIG) .SILENT: $(TMP_CONFIG) .PRECIOUS: $(TMP_CONFIG) ifdef KERNEL_TESTING_PATCHVER ifneq ($(KERNEL_TESTING_PATCHVER),$(KERNEL_PATCHVER)) FEATURES += testing-kernel endif endif ifneq ($(CONFIG_OF),) FEATURES += dt endif ifneq ($(CONFIG_GENERIC_GPIO)$(CONFIG_GPIOLIB),) FEATURES += gpio endif ifneq ($(CONFIG_PCI),) FEATURES += pci endif ifneq ($(CONFIG_PCIEPORTBUS),) FEATURES += pcie endif ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),) ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),) FEATURES += usb endif endif ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),) FEATURES += pcmcia endif ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),) FEATURES += display endif ifneq ($(CONFIG_RTC_CLASS),) FEATURES += rtc endif ifneq ($(CONFIG_VIRTIO),) FEATURES += virtio endif ifneq ($(CONFIG_CPU_MIPS32_R2),) FEATURES += mips16 endif FEATURES += $(foreach v,6 7,$(if $(CONFIG_CPU_V$(v)),arm_v$(v))) # remove duplicates FEATURES:=$(sort $(FEATURES)) endif endif CUR_SUBTARGET:=$(SUBTARGET) ifeq ($(SUBTARGETS),) CUR_SUBTARGET := default endif define BuildTargets/DumpCurrent .PHONY: dumpinfo dumpinfo : export DESCRIPTION=$$(Target/Description) dumpinfo: @echo 'Target: $(TARGETID)'; \ echo 'Target-Board: $(BOARD)'; \ echo 'Target-Name: $(BOARDNAME)$(if $(SUBTARGETS),$(if $(SUBTARGET),))'; \ echo 'Target-Arch: $(ARCH)'; \ echo 'Target-Arch-Packages: $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(ARCH)$(if $(CPU_TYPE),_$(CPU_TYPE))$(if $(CPU_SUBTYPE),_$(CPU_SUBTYPE)))'; \ echo 'Target-Features: $(FEATURES)'; \ echo 'Target-Depends: $(DEPENDS)'; \ echo 'Target-Optimization: $(if $(CFLAGS),$(CFLAGS),$(DEFAULT_CFLAGS))'; \ echo 'CPU-Type: $(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))'; \ echo 'Linux-Version: $(LINUX_VERSION)'; \ $(if $(LINUX_TESTING_VERSION),echo 'Linux-Testing-Version: $(LINUX_TESTING_VERSION)';) \ echo 'Linux-Release: $(LINUX_RELEASE)'; \ echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \ $(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget: $(DEFAULT_SUBTARGET)'; )) \ echo 'Target-Description:'; \ echo "$$$$DESCRIPTION"; \ echo '@@'; \ echo 'Default-Packages: $(DEFAULT_PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES))'; \ $(DUMPINFO) $(if $(CUR_SUBTARGET),$(SUBMAKE) -r --no-print-directory -C image -s DUMP=1 SUBTARGET=$(CUR_SUBTARGET)) $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); )) endef include $(INCLUDE_DIR)/kernel.mk ifeq ($(TARGET_BUILD),1) include $(INCLUDE_DIR)/kernel-build.mk BuildTarget?=$(BuildKernel) endif endif #__target_inc