mirror of
https://github.com/mikpe/pdp10-tools.git
synced 2026-03-10 20:53:47 +00:00
as: add support for .2byte and .4byte directives
This commit is contained in:
@@ -133,6 +133,8 @@ stmt_image(Stmt, Tunit, SectionName, Dot) ->
|
||||
#s_dot_byte{} -> dot_byte_image(Stmt, Tunit, SectionName, Dot);
|
||||
#s_dot_long{} -> dot_long_image(Stmt, Tunit, SectionName, Dot);
|
||||
#s_dot_short{} -> dot_short_image(Stmt, Tunit, SectionName, Dot);
|
||||
#s_dot_2byte{} -> dot_2byte_image(Stmt, Tunit, SectionName, Dot);
|
||||
#s_dot_4byte{} -> dot_4byte_image(Stmt, Tunit, SectionName, Dot);
|
||||
#s_insn{} -> insn_image(Stmt, Tunit, SectionName, Dot)
|
||||
end.
|
||||
|
||||
@@ -161,6 +163,16 @@ dot_short_image(#s_dot_short{exprs = Exprs}, Tunit, SectionName, Dot) ->
|
||||
integer_data_directive(Exprs, Tunit, SectionName, Dot, _Size = 2, _Context = short,
|
||||
fun pdp10_extint:uint18_to_ext/1).
|
||||
|
||||
%% TODO: merge with .short handling?
|
||||
dot_2byte_image(#s_dot_2byte{exprs = Exprs}, Tunit, SectionName, Dot) ->
|
||||
integer_data_directive(Exprs, Tunit, SectionName, Dot, _Size = 2, _Context = short,
|
||||
fun pdp10_extint:uint18_to_ext/1).
|
||||
|
||||
%% TODO: merge with .long handling?
|
||||
dot_4byte_image(#s_dot_4byte{exprs = Exprs}, Tunit, SectionName, Dot) ->
|
||||
integer_data_directive(Exprs, Tunit, SectionName, Dot, _Size = 4, _Context = long,
|
||||
fun pdp10_extint:uint36_to_ext/1).
|
||||
|
||||
insn_image(Stmt, Tunit, SectionName, Dot) ->
|
||||
#s_insn{ high13 = High13
|
||||
, at = At
|
||||
|
||||
@@ -439,6 +439,8 @@ pass2_stmt(Location, Tunit, Stmt) ->
|
||||
#s_dot_short{} -> dot_short(Location, Tunit, Stmt);
|
||||
#s_dot_size{} -> dot_size(Location, Tunit, Stmt);
|
||||
#s_dot_type{} -> dot_type(Location, Tunit, Stmt);
|
||||
#s_dot_2byte{} -> dot_2byte(Location, Tunit, Stmt);
|
||||
#s_dot_4byte{} -> dot_4byte(Location, Tunit, Stmt);
|
||||
#s_label{} -> label(Location, Tunit, Stmt);
|
||||
#s_local_label{} -> local_label(Location, Tunit, Stmt);
|
||||
#s_insn{} -> insn(Location, Tunit, Stmt)
|
||||
@@ -460,7 +462,9 @@ dot_ascii(_Location, Tunit, #s_dot_ascii{z = Z, strings = Strings} = Stmt) ->
|
||||
{ok, tunit:put_section(Tunit, NewSection)}.
|
||||
|
||||
dot_byte(Location, Tunit, #s_dot_byte{} = Stmt0) ->
|
||||
integer_data_directive(Location, Tunit, Stmt0, 1, ".byte",
|
||||
Size = 1,
|
||||
Align = 1,
|
||||
integer_data_directive(Location, Tunit, Stmt0, Size, Align, ".byte",
|
||||
fun(Stmt) -> Stmt#s_dot_byte.exprs end,
|
||||
fun(Stmt, Exprs) -> Stmt#s_dot_byte{exprs = Exprs} end).
|
||||
|
||||
@@ -509,16 +513,17 @@ dot_ident(_Location, Tunit, #s_dot_ident{} = Stmt) ->
|
||||
{ok, tunit:put_section(Tunit, NewSection)}.
|
||||
|
||||
dot_long(Location, Tunit, #s_dot_long{} = Stmt0) ->
|
||||
Size = 4, % FIXME: target-specific alignof and sizeof
|
||||
integer_data_directive(Location, Tunit, Stmt0, Size, ".long",
|
||||
Size = 4, % FIXME: target-specific
|
||||
Align = Size,
|
||||
integer_data_directive(Location, Tunit, Stmt0, Size, Align, ".long",
|
||||
fun(Stmt) -> Stmt#s_dot_long.exprs end,
|
||||
fun(Stmt, Exprs) -> Stmt#s_dot_long{exprs = Exprs} end).
|
||||
|
||||
integer_data_directive(Location, Tunit, Stmt, Size, Lexeme, GetExpr, SetExprs) ->
|
||||
integer_data_directive(Location, Tunit, Stmt, Size, Align, Lexeme, GetExpr, SetExprs) ->
|
||||
Exprs = GetExpr(Stmt),
|
||||
#tunit{cursect = Cursect} = Tunit,
|
||||
#section{data = {stmts, Stmts}, dot = Dot} = Section = tunit:get_section(Tunit, Cursect),
|
||||
case Dot rem Size of
|
||||
case Dot rem Align of
|
||||
0 ->
|
||||
NewExprs = [expr_fixup(Tunit, Expr) || Expr <- Exprs],
|
||||
NewStmt = SetExprs(Stmt, NewExprs),
|
||||
@@ -531,8 +536,9 @@ integer_data_directive(Location, Tunit, Stmt, Size, Lexeme, GetExpr, SetExprs) -
|
||||
end.
|
||||
|
||||
dot_short(Location, Tunit, #s_dot_short{} = Stmt0) ->
|
||||
Size = 2, % FIXME: target-specific alignof and sizeof
|
||||
integer_data_directive(Location, Tunit, Stmt0, Size, ".short",
|
||||
Size = 2, % FIXME: target-specific
|
||||
Align = Size,
|
||||
integer_data_directive(Location, Tunit, Stmt0, Size, Align, ".short",
|
||||
fun(Stmt) -> Stmt#s_dot_short.exprs end,
|
||||
fun(Stmt, Exprs) -> Stmt#s_dot_short{exprs = Exprs} end).
|
||||
|
||||
@@ -577,6 +583,20 @@ dot_type(Location, Tunit, #s_dot_type{name = Name}) ->
|
||||
end
|
||||
end.
|
||||
|
||||
dot_2byte(Location, Tunit, #s_dot_2byte{} = Stmt0) ->
|
||||
Size = 2, % FIXME: target-specific
|
||||
Align = 1,
|
||||
integer_data_directive(Location, Tunit, Stmt0, Size, Align, ".2byte",
|
||||
fun(Stmt) -> Stmt#s_dot_2byte.exprs end,
|
||||
fun(Stmt, Exprs) -> Stmt#s_dot_2byte{exprs = Exprs} end).
|
||||
|
||||
dot_4byte(Location, Tunit, #s_dot_4byte{} = Stmt0) ->
|
||||
Size = 4, % FIXME: target-specific
|
||||
Align = 1,
|
||||
integer_data_directive(Location, Tunit, Stmt0, Size, Align, ".4byte",
|
||||
fun(Stmt) -> Stmt#s_dot_4byte.exprs end,
|
||||
fun(Stmt, Exprs) -> Stmt#s_dot_4byte{exprs = Exprs} end).
|
||||
|
||||
label(Location, Tunit, #s_label{name = Name}) ->
|
||||
case tunit:get_symbol(Tunit, Name) of
|
||||
#symbol{section = false, st_value = false} = Symbol -> define_label(Tunit, Symbol);
|
||||
|
||||
@@ -54,6 +54,8 @@ stmt(ScanState) ->
|
||||
{ok, {Location, ?T_DOT_TEXT}} -> dot_text(ScanState, Location);
|
||||
{ok, {Location, ?T_DOT_TYPE}} -> dot_type(ScanState, Location);
|
||||
{ok, {Location, ?T_DOT_WORD}} -> dot_word(ScanState, Location);
|
||||
{ok, {Location, ?T_DOT_2BYTE}} -> dot_2byte(ScanState, Location);
|
||||
{ok, {Location, ?T_DOT_4BYTE}} -> dot_4byte(ScanState, Location);
|
||||
{ok, {Location, {?T_SYMBOL, Name}}} -> stmt_after_symbol(ScanState, Location, Name);
|
||||
{ok, {Location, {?T_UINTEGER, UInt}}} -> stmt_after_uinteger(ScanState, Location, UInt);
|
||||
{ok, {_Location, ?T_NEWLINE}} -> stmt(ScanState);
|
||||
@@ -424,6 +426,14 @@ dot_type(ScanState, Location) ->
|
||||
dot_word(ScanState, Location) ->
|
||||
dot_long(ScanState, Location).
|
||||
|
||||
dot_2byte(ScanState, Location) ->
|
||||
integer_data_directive(ScanState, Location,
|
||||
fun(Exprs) -> #s_dot_2byte{exprs = Exprs} end).
|
||||
|
||||
dot_4byte(ScanState, Location) ->
|
||||
integer_data_directive(ScanState, Location,
|
||||
fun(Exprs) -> #s_dot_4byte{exprs = Exprs} end).
|
||||
|
||||
%% .section/.pushsection directives --------------------------------------------
|
||||
%%
|
||||
%% .section <name> <sectionspec>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
%%% -*- erlang-indent-level: 2 -*-
|
||||
%%%
|
||||
%%% token handling for pdp10-elf as
|
||||
%%% Copyright (C) 2013-2020 Mikael Pettersson
|
||||
%%% Copyright (C) 2013-2023 Mikael Pettersson
|
||||
%%%
|
||||
%%% This file is part of pdp10-tools.
|
||||
%%%
|
||||
@@ -48,6 +48,8 @@ from_symbol(Name) ->
|
||||
".text" -> ?T_DOT_TEXT;
|
||||
".type" -> ?T_DOT_TYPE;
|
||||
".word" -> ?T_DOT_WORD;
|
||||
".2byte" -> ?T_DOT_2BYTE;
|
||||
".4byte" -> ?T_DOT_4BYTE;
|
||||
_ -> {?T_SYMBOL, Name}
|
||||
end.
|
||||
|
||||
@@ -73,6 +75,8 @@ format(Token) ->
|
||||
?T_DOT_TEXT -> ".text";
|
||||
?T_DOT_TYPE -> ".type";
|
||||
?T_DOT_WORD -> ".word";
|
||||
?T_DOT_2BYTE -> ".2byte";
|
||||
?T_DOT_4BYTE -> ".4byte";
|
||||
{?T_SYMBOL, Name} -> io_lib:format("symbol:~s", [Name]);
|
||||
{?T_LOCAL_LABEL, Number, Direction} ->
|
||||
io_lib:format("label: ~.10b~c", [Number, Direction]);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
%%% -*- erlang-indent-level: 2 -*-
|
||||
%%%
|
||||
%%% token definitions for pdp10-elf as
|
||||
%%% Copyright (C) 2013-2020 Mikael Pettersson
|
||||
%%% Copyright (C) 2013-2023 Mikael Pettersson
|
||||
%%%
|
||||
%%% This file is part of pdp10-tools.
|
||||
%%%
|
||||
@@ -45,8 +45,10 @@
|
||||
-define(T_DOT_TEXT, 'T_DOT_TEXT'). % .text
|
||||
-define(T_DOT_TYPE, 'T_DOT_TYPE'). % .type
|
||||
-define(T_DOT_WORD, 'T_DOT_WORD'). % .word
|
||||
-define(T_DOT_2BYTE, 'T_DOT_2BYTE'). % .2byte
|
||||
-define(T_DOT_4BYTE, 'T_DOT_4BYTE'). % .4byte
|
||||
|
||||
%% ordinary (non-reserved, non-special non-synthetic) symbols
|
||||
%% ordinary (non-reserved, non-special, non-synthetic) symbols
|
||||
-define(T_SYMBOL, 'T_SYMBOL'). % pushj, foo, .Lbar
|
||||
|
||||
%% literals
|
||||
@@ -87,6 +89,8 @@
|
||||
| ?T_DOT_TEXT
|
||||
| ?T_DOT_TYPE
|
||||
| ?T_DOT_WORD
|
||||
| ?T_DOT_2BYTE
|
||||
| ?T_DOT_4BYTE
|
||||
| {?T_SYMBOL, string()}
|
||||
| {?T_LOCAL_LABEL, non_neg_integer(), $b | $f}
|
||||
| {?T_STRING, string()}
|
||||
|
||||
@@ -93,6 +93,12 @@
|
||||
%% .type foo,@function (TODO: extend)
|
||||
-record(s_dot_type, {name :: string()}).
|
||||
|
||||
%% .2byte [expr (, expr)*]
|
||||
-record(s_dot_2byte, {exprs :: [expr()]}).
|
||||
|
||||
%% .4byte [expr (, expr)*]
|
||||
-record(s_dot_4byte, {exprs :: [expr()]}).
|
||||
|
||||
%% foo: 1:
|
||||
-record(s_label, {name :: string()}).
|
||||
-record(s_local_label, {number :: non_neg_integer()}).
|
||||
@@ -120,6 +126,8 @@
|
||||
| #s_dot_subsection{}
|
||||
| #s_dot_text{}
|
||||
| #s_dot_type{}
|
||||
| #s_dot_2byte{}
|
||||
| #s_dot_4byte{}
|
||||
| #s_label{}
|
||||
| #s_local_label{}
|
||||
| #s_insn{}
|
||||
|
||||
Reference in New Issue
Block a user