From 712f3cbae6bfd3c6f6cc40d44f438aa0affcd371 Mon Sep 17 00:00:00 2001 From: xleroy Date: Tue, 18 Dec 2012 07:54:35 +0000 Subject: Support for inline assembly (asm statements). cparser: add primitive support for enum types. bitfield emulation: for bitfields with enum type, choose signed/unsigned as appropriate git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2074 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- cparser/Env.ml | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'cparser/Env.ml') diff --git a/cparser/Env.ml b/cparser/Env.ml index 164fe59..355a996 100644 --- a/cparser/Env.ml +++ b/cparser/Env.ml @@ -72,26 +72,35 @@ type composite_info = { type ident_info = | II_ident of storage * typ - | II_enum of int64 (* value of the enum *) + | II_enum of int64 (* value of enumerator *) (* Infos associated with a typedef *) type typedef_info = typ +(* Infos associated with an enum *) + +type enum_info = { + ei_members: enumerator list; (* list of all members *) + ei_attr: attributes (* attributes, if any *) +} + (* Environments *) type t = { env_scope: int; env_ident: ident_info IdentMap.t; env_tag: composite_info IdentMap.t; - env_typedef: typedef_info IdentMap.t + env_typedef: typedef_info IdentMap.t; + env_enum: enum_info IdentMap.t } let empty = { env_scope = 0; env_ident = IdentMap.empty; env_tag = IdentMap.empty; - env_typedef = IdentMap.empty + env_typedef = IdentMap.empty; + env_enum = IdentMap.empty } (* Enter a new scope. *) @@ -143,6 +152,12 @@ let lookup_typedef env s = with Not_found -> raise(Error(Unbound_typedef s)) +let lookup_enum env s = + try + IdentMap.lookup s env.env_enum + with Not_found -> + raise(Error(Unbound_tag(s, "enum"))) + (* Checking if a source name is bound *) let ident_is_bound env s = StringMap.mem s env.env_ident @@ -200,6 +215,12 @@ let find_typedef env id = with Not_found -> raise(Error(Unbound_typedef(id.name))) +let find_enum env id = + try + IdentMap.find id env.env_enum + with Not_found -> + raise(Error(Unbound_tag(id.name, "enum"))) + (* Inserting things by source name, with generation of a translated name *) let enter_ident env s sto ty = @@ -219,6 +240,10 @@ let enter_typedef env s info = let id = fresh_ident s in (id, { env with env_typedef = IdentMap.add id info env.env_typedef }) +let enter_enum env s info = + let id = fresh_ident s in + (id, { env with env_enum = IdentMap.add id info env.env_enum }) + (* Inserting things by translated name *) let add_ident env id sto ty = @@ -230,6 +255,13 @@ let add_composite env id ci = let add_typedef env id info = { env with env_typedef = IdentMap.add id info env.env_typedef } +let add_enum env id info = + let add_enum_item env (id, v, exp) = + { env with env_ident = IdentMap.add id (II_enum v) env.env_ident } in + List.fold_left add_enum_item + { env with env_enum = IdentMap.add id info env.env_enum } + info.ei_members + (* Error reporting *) open Printf -- cgit v1.2.3