Skip to content

Commit

Permalink
[NFC] [iasmgcc.d] move public function to top of file (#16911)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilsonator authored Oct 3, 2024
1 parent ef495c0 commit cdd2ad7
Showing 1 changed file with 111 additions and 111 deletions.
222 changes: 111 additions & 111 deletions compiler/src/dmd/iasmgcc.d
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,117 @@ import dmd.tokens;
import dmd.statement;
import dmd.statementsem;

/***********************************
* Parse and run semantic analysis on a GccAsmStatement.
* Params:
* s = gcc asm statement being parsed
* sc = the scope where the asm statement is located
* Returns:
* the completed gcc asm statement, or null if errors occurred
*/
public Statement gccAsmSemantic(GccAsmStatement s, Scope *sc)
{
//printf("GccAsmStatement.semantic()\n");
const bool doUnittests = global.params.parsingUnittestsRequired();
scope p = new Parser!ASTCodegen(sc._module, ";", false, global.errorSink, &global.compileEnv, doUnittests);

// Make a safe copy of the token list before parsing.
Token *toklist = null;
Token **ptoklist = &toklist;

for (Token *token = s.tokens; token; token = token.next)
{
*ptoklist = p.allocateToken();
memcpy(*ptoklist, token, Token.sizeof);
ptoklist = &(*ptoklist).next;
*ptoklist = null;
}
p.token = *toklist;
p.scanloc = s.loc;

// Parse the gcc asm statement.
const errors = global.errors;
s = p.parseGccAsm(s);
if (errors != global.errors)
return null;
s.stc = sc.stc;

// Fold the instruction template string.
s.insn = semanticString(sc, s.insn, "asm instruction template");

if (s.labels && s.outputargs)
error(s.loc, "extended asm statements with labels cannot have output constraints");

// Analyse all input and output operands.
if (s.args)
{
foreach (i; 0 .. s.args.length)
{
Expression e = (*s.args)[i];
e = e.expressionSemantic(sc);
// Check argument is a valid lvalue/rvalue.
if (i < s.outputargs)
e = e.modifiableLvalue(sc);
else if (e.checkValue())
e = ErrorExp.get();
(*s.args)[i] = e;

e = (*s.constraints)[i];
e = e.expressionSemantic(sc);
assert(e.op == EXP.string_ && (cast(StringExp) e).sz == 1);
(*s.constraints)[i] = e;
}
}

// Analyse all clobbers.
if (s.clobbers)
{
foreach (i; 0 .. s.clobbers.length)
{
Expression e = (*s.clobbers)[i];
e = e.expressionSemantic(sc);
assert(e.op == EXP.string_ && (cast(StringExp) e).sz == 1);
(*s.clobbers)[i] = e;
}
}

// Analyse all goto labels.
if (s.labels)
{
foreach (i; 0 .. s.labels.length)
{
Identifier ident = (*s.labels)[i];
GotoStatement gs = new GotoStatement(s.loc, ident);
if (!s.gotos)
s.gotos = new GotoStatements();
s.gotos.push(gs);
gs.statementSemantic(sc);
}
}

return s;
}

/***********************************
* Run semantic analysis on an CAsmDeclaration.
* Params:
* ad = asm declaration
* sc = the scope where the asm declaration is located
*/
public void gccAsmSemantic(CAsmDeclaration ad, Scope *sc)
{
import dmd.typesem : pointerTo;
ad.code = semanticString(sc, ad.code, "asm definition");
ad.code.type = ad.code.type.nextOf().pointerTo();

// Asm definition always needs emitting into the root module.
import dmd.dmodule : Module;
if (sc._module && sc._module.isRoot())
return;
if (Module m = Module.rootModule)
m.members.push(ad);
}

private:

/***********************************
Expand Down Expand Up @@ -292,117 +403,6 @@ Ldone:
return s;
}

/***********************************
* Parse and run semantic analysis on a GccAsmStatement.
* Params:
* s = gcc asm statement being parsed
* sc = the scope where the asm statement is located
* Returns:
* the completed gcc asm statement, or null if errors occurred
*/
public Statement gccAsmSemantic(GccAsmStatement s, Scope *sc)
{
//printf("GccAsmStatement.semantic()\n");
const bool doUnittests = global.params.parsingUnittestsRequired();
scope p = new Parser!ASTCodegen(sc._module, ";", false, global.errorSink, &global.compileEnv, doUnittests);

// Make a safe copy of the token list before parsing.
Token *toklist = null;
Token **ptoklist = &toklist;

for (Token *token = s.tokens; token; token = token.next)
{
*ptoklist = p.allocateToken();
memcpy(*ptoklist, token, Token.sizeof);
ptoklist = &(*ptoklist).next;
*ptoklist = null;
}
p.token = *toklist;
p.scanloc = s.loc;

// Parse the gcc asm statement.
const errors = global.errors;
s = p.parseGccAsm(s);
if (errors != global.errors)
return null;
s.stc = sc.stc;

// Fold the instruction template string.
s.insn = semanticString(sc, s.insn, "asm instruction template");

if (s.labels && s.outputargs)
error(s.loc, "extended asm statements with labels cannot have output constraints");

// Analyse all input and output operands.
if (s.args)
{
foreach (i; 0 .. s.args.length)
{
Expression e = (*s.args)[i];
e = e.expressionSemantic(sc);
// Check argument is a valid lvalue/rvalue.
if (i < s.outputargs)
e = e.modifiableLvalue(sc);
else if (e.checkValue())
e = ErrorExp.get();
(*s.args)[i] = e;

e = (*s.constraints)[i];
e = e.expressionSemantic(sc);
assert(e.op == EXP.string_ && (cast(StringExp) e).sz == 1);
(*s.constraints)[i] = e;
}
}

// Analyse all clobbers.
if (s.clobbers)
{
foreach (i; 0 .. s.clobbers.length)
{
Expression e = (*s.clobbers)[i];
e = e.expressionSemantic(sc);
assert(e.op == EXP.string_ && (cast(StringExp) e).sz == 1);
(*s.clobbers)[i] = e;
}
}

// Analyse all goto labels.
if (s.labels)
{
foreach (i; 0 .. s.labels.length)
{
Identifier ident = (*s.labels)[i];
GotoStatement gs = new GotoStatement(s.loc, ident);
if (!s.gotos)
s.gotos = new GotoStatements();
s.gotos.push(gs);
gs.statementSemantic(sc);
}
}

return s;
}

/***********************************
* Run semantic analysis on an CAsmDeclaration.
* Params:
* ad = asm declaration
* sc = the scope where the asm declaration is located
*/
public void gccAsmSemantic(CAsmDeclaration ad, Scope *sc)
{
import dmd.typesem : pointerTo;
ad.code = semanticString(sc, ad.code, "asm definition");
ad.code.type = ad.code.type.nextOf().pointerTo();

// Asm definition always needs emitting into the root module.
import dmd.dmodule : Module;
if (sc._module && sc._module.isRoot())
return;
if (Module m = Module.rootModule)
m.members.push(ad);
}

unittest
{
import dmd.mtype : TypeBasic;
Expand Down

0 comments on commit cdd2ad7

Please sign in to comment.