From 8d2b402d69d85ae42dfdfa92a06bc4c76166cee7 Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Fri, 3 Jan 2020 21:40:02 +0100 Subject: [PATCH] as: handle .pushsection as a special case of .section --- erlang/apps/as/src/input.erl | 23 ----------------------- erlang/apps/as/src/parse.erl | 30 +++--------------------------- erlang/apps/as/src/tunit.hrl | 4 ---- 3 files changed, 3 insertions(+), 54 deletions(-) diff --git a/erlang/apps/as/src/input.erl b/erlang/apps/as/src/input.erl index 57d4a8d..21bd137 100644 --- a/erlang/apps/as/src/input.erl +++ b/erlang/apps/as/src/input.erl @@ -92,7 +92,6 @@ pass1_stmt(Location, Ctx, Stmt) -> #s_dot_data{} -> dot_data(Location, Ctx, Stmt); #s_dot_popsection{} -> dot_popsection(Location, Ctx, Stmt); #s_dot_previous{} -> dot_previous(Location, Ctx, Stmt); - #s_dot_pushsection{} -> dot_pushsection(Location, Ctx, Stmt); #s_dot_section{} -> dot_section(Location, Ctx, Stmt); #s_dot_subsection{} -> dot_subsection(Location, Ctx, Stmt); #s_dot_text{} -> dot_text(Location, Ctx, Stmt); @@ -114,10 +113,6 @@ dot_previous(Location, Ctx0, #s_dot_previous{}) -> false -> fmterr(Location, ".previous with empty section stack", []) end. -dot_pushsection(Location, Ctx, - #s_dot_pushsection{name = SectionName, nr = SubsectionNr}) -> - ctx_pushsection(Ctx, Location, SectionName, SubsectionNr). - dot_section(Location, Ctx, Stmt) -> #s_dot_section{ name = SectionName , nr = SubsectionNrOpt @@ -194,24 +189,6 @@ ctx_try_previous(Ctx0) -> % implements .previous }} end. -ctx_pushsection(Ctx0, Location, SectionName, SubsectionNr) -> % implements .pushsection - Ctx = ctx_flush(Ctx0), - #ctx{ sections_map = SectionsMap0 - , stack = Stack - , current = Current - , previous = Previous - } = Ctx, - case enter_section(Location, SectionName, SubsectionNr, SectionsMap0) of - {ok, {Stmts, SectionsMap}} -> - {ok, Ctx#ctx{ sections_map = SectionsMap - , stack = [{Current, Previous} | Stack] - , current = {SectionName, SubsectionNr} - , previous = Current - , stmts = Stmts - }}; - {error, _Reason} = Error -> Error - end. - ctx_section(Ctx0, Location, SectionName, SubsectionNrOpt, ShFlags, ShType, ShEntSize) -> {IsPushsection, SubsectionNr} = diff --git a/erlang/apps/as/src/parse.erl b/erlang/apps/as/src/parse.erl index aac3f5e..7628b80 100644 --- a/erlang/apps/as/src/parse.erl +++ b/erlang/apps/as/src/parse.erl @@ -372,33 +372,6 @@ dot_previous(ScanState, Location) -> ScanRes -> badtok("junk after .previous", ScanRes) end. -%% For now only accepts ".pushsection [, ]". TODO: extend -dot_pushsection(ScanState, Location) -> - case scan:token(ScanState) of - {ok, {_Location, {?T_STRING, Name}}} -> dot_pushsection(ScanState, Location, Name); - {ok, {_Location, {?T_SYMBOL, Name}}} -> dot_pushsection(ScanState, Location, Name); - %% TODO: do we need a general mapping from reserved to plain symbols? - {ok, {_Location, ?T_DOT_DATA}} -> dot_pushsection(ScanState, Location, _Name = ".data"); - {ok, {_Location, ?T_DOT_TEXT}} -> dot_pushsection(ScanState, Location, _Name = ".text"); - ScanRes -> badtok("junk after .pushsection", ScanRes) - end. - -%% Seen ".pushsection ", expects "[, ]". -dot_pushsection(ScanState, Location, Name) -> - case scan:token(ScanState) of - {ok, {_Location1, ?T_NEWLINE}} -> {ok, {Location, #s_dot_pushsection{name = Name, nr = 0}}}; - {ok, {_Location1, ?T_COMMA}} -> - case scan:token(ScanState) of - {ok, {_Location2, {?T_UINTEGER, Nr}}} -> - case scan:token(ScanState) of - {ok, {_Location3, ?T_NEWLINE}} -> {ok, {Location, #s_dot_pushsection{name = Name, nr = Nr}}}; - ScanRes -> badtok("junk after .pushsection , ", ScanRes) - end; - ScanRes -> badtok("junk after .pushsection ,", ScanRes) - end; - ScanRes -> badtok("junk after .pushsection ", ScanRes) - end. - dot_short(ScanState, Location) -> dot_short(ScanState, Location, ".short"). @@ -504,6 +477,9 @@ dot_word(ScanState, Location) -> dot_section(ScanState, Location) -> dot_section_name(ScanState, Location, _IsPushsection = false). +dot_pushsection(ScanState, Location) -> + dot_section_name(ScanState, Location, _IsPushsection = true). + dot_section_name(ScanState, Location, IsPushsection) -> case section_name(ScanState) of {ok, Name} -> dot_section_subsection(ScanState, Location, Name, IsPushsection); diff --git a/erlang/apps/as/src/tunit.hrl b/erlang/apps/as/src/tunit.hrl index c9f6cdd..85cfa35 100644 --- a/erlang/apps/as/src/tunit.hrl +++ b/erlang/apps/as/src/tunit.hrl @@ -63,9 +63,6 @@ %% .previous -record(s_dot_previous, {}). -%% .pushsection name [, nr] (TODO: extend) --record(s_dot_pushsection, {name :: string(), nr :: non_neg_integer()}). - %% .section name, "flags", @type, ... %% .pushsection name, [, nr], "flags", @type, ... %% TODO: add support for G and ? flags and ,, @@ -114,7 +111,6 @@ | #s_dot_long{} | #s_dot_popsection{} | #s_dot_previous{} - | #s_dot_pushsection{} | #s_dot_section{} | #s_dot_size{} | #s_dot_subsection{}