Skip to content

Commit

Permalink
m3front: Variable.Declare refactor slightly indirect param vs. direct. (
Browse files Browse the repository at this point in the history
#562)

It is nearly identical code, factor it better to reduce repitition.
  • Loading branch information
jaykrell committed May 31, 2021
1 parent 9833375 commit ba5deb3
Showing 1 changed file with 15 additions and 29 deletions.
44 changes: 15 additions & 29 deletions m3-sys/m3front/src/values/Variable.m3
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ PROCEDURE Declare (t: T): BOOLEAN =
externName :TEXT := NIL;
externM3ID := M3ID.NoID;
typename := M3ID.NoID;
indirect_text := " ";
BEGIN
Type.Compile (t.type);

Expand Down Expand Up @@ -629,36 +630,20 @@ PROCEDURE Declare (t: T): BOOLEAN =
t.cg_var := CG.Declare_local (t.name, size, align, mtype, typeUID,
t.need_addr, t.up_level, CG.Maybe);

ELSIF (t.indirect) THEN
(* formal passed by reference => param is an address *)
t.cg_align := t.align;
t.nextTWACGVar := TsWCGVars; TsWCGVars := t;
(* TODO typename *)

IF debug THEN
RTIO.PutText ("Variable.Declare indirect param type:");
RTIO.PutRef (t.type);
RTIO.PutText (" name:");
IF t.name # 0 THEN
RTIO.PutText (M3ID.ToText (t.name));
END;
RTIO.PutText (" typename:");
RTIO.PutInt (typename);
RTIO.PutText ("\n");
RTIO.Flush ();
END;

t.cg_var := CG.Declare_param (t.name, size, align, mtype, typeUID,
t.need_addr, t.up_level, CG.Maybe);
ELSE
(* simple parameter *)
(** align := FindAlignment (align, size); **)
t.cg_align := align;
t.nextTWACGVar := TsWCGVars; TsWCGVars := t;
Type.Typename (TypeOf (t), typename);
(* parameter *)
IF (t.indirect) THEN
(* formal passed by reference => param is an address *)
(* TODO typename *)
indirect_text := " indirect "
ELSE
(* simple parameter *)
(** align := FindAlignment (align, size); **)
Type.Typename (TypeOf (t), typename);
END;

IF debug THEN
RTIO.PutText ("Variable.Declare param type:");
RTIO.PutText ("Variable.Declare" & indirect_text & "param type:");
RTIO.PutRef (t.type);
RTIO.PutText (" name:");
IF t.name # 0 THEN
Expand All @@ -670,8 +655,9 @@ PROCEDURE Declare (t: T): BOOLEAN =
RTIO.Flush ();
END;

t.cg_var := CG.Declare_param (t.name, size, align, mtype, typeUID,
t.need_addr, t.up_level, CG.Maybe, typename);
t.cg_align := t.align;
t.nextTWACGVar := TsWCGVars; TsWCGVars := t;
t.cg_var := CG.Declare_param (t.name, size, align, mtype, typeUID, t.need_addr, t.up_level, CG.Maybe, typename);
END;

RETURN TRUE;
Expand Down

0 comments on commit ba5deb3

Please sign in to comment.