Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The C emitter now declares `sysml_parse_rec`, the argument parser the collection runtime over records calls: a compiled calc holding a record sequence (`attribute ps : Point[0..*]`) failed to build under gcc 15, whose defaults make an implicit declaration an error. `codegen.CFlags` carries `-Werror=implicit-function-declaration -Werror=int-conversion` so every C compiler reports such an omission.
6 changes: 3 additions & 3 deletions internal/translate/codegen/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func goCommand(name string) (string, error) {
return filepath.Abs(resolved)
}

// CFlags are the C compiler options; the prelude's explicit checks keep -O3 safe,
// and no contraction keeps every Real operation rounded as the interpreter rounds it.
var CFlags = []string{"-O3", "-flto", "-ffp-contract=off", "-std=gnu11", "-Wall", "-Wextra", "-Wno-unused-function", "-Wno-unused-parameter"}
// CFlags are the C compiler options; the prelude's explicit checks keep -O3 safe, and no contraction keeps
// every Real operation rounded as the interpreter rounds it. The two -Werror are gcc 15's defaults on every gcc.
var CFlags = []string{"-O3", "-flto", "-ffp-contract=off", "-std=gnu11", "-Wall", "-Wextra", "-Wno-unused-function", "-Wno-unused-parameter", "-Werror=implicit-function-declaration", "-Werror=int-conversion"}

// Source renders program for target, as a complete program with a main.
func Source(p *Program, target Target) ([]byte, error) {
Expand Down
1 change: 1 addition & 0 deletions internal/translate/codegen/emit_fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ static const char *sysml_show_rec(sysml_rec *r) {
sysml_format_rec(r, text, sizeof text);
return text;
}
static sysml_rec *sysml_parse_rec(const char *s, const char *name) { fprintf(stderr, "argument %s: %s is not a record value\n", name, s); exit(2); }
` + r.Replace(cSeqTemplate)
}

Expand Down
39 changes: 39 additions & 0 deletions internal/translate/codegen/record_seq_build_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package codegen_test

import (
"os"
"os/exec"
"path/filepath"
"testing"

"github.com/Open-MBEE/OpenSysML/internal/translate/codegen"
)

// TestCRecordSequencesBuildUnderStrictDeclarations: a calc holding a record sequence instantiates
// the collection runtime over records, whose argument parser gcc 15 refused as an implicit declaration.
func TestCRecordSequencesBuildUnderStrictDeclarations(t *testing.T) {
cc := os.Getenv(codegen.CCompilerEnvVar)
if cc == "" {
cc = "cc"
}
if _, err := exec.LookPath(cc); err != nil {
t.Skip("no C compiler on PATH")
}
for _, flag := range []string{"-Werror=implicit-function-declaration", "-Werror=int-conversion"} {
found := false
for _, f := range codegen.CFlags {
found = found || f == flag
}
if !found {
t.Errorf("CFlags lacks %s, so a missing runtime declaration compiles on an older gcc", flag)
}
}
compiler, pkg := recordCompiler(t)
program, err := compiler.Compile(recordCalc(t, pkg, "HoldsMany"), codegen.TargetC)
if err != nil {
t.Fatal(err)
}
if err := codegen.Build(program, codegen.TargetC, filepath.Join(t.TempDir(), "records")); err != nil {
t.Fatalf("the generated C does not build under CFlags: %v", err)
}
}
1 change: 1 addition & 0 deletions internal/translate/codegen/refuse_records_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const recordModel = `
calc def TakesMany { in ps : Point[0..*]; return : Real = 1.0; }
calc def ReadOff { in a : Real; return : Real = Make(a).y; }
calc def PassesInside { in a : Real; return : Real = Takes(new Point(a, 2.0)); }
calc def HoldsMany { in a : Real; attribute ps : Point[0..*] = (new Point(a, 1.0), new Point(2.0, a)); return : Real = ps#(2).y; }
attribute def Seg { attribute a : Point; attribute b : Point; }
calc def UnsetRead { in a : Real; return : Real = new Point(a).y; }
calc def UnsetInSeq { in a : Real; return : Real[0..*] = (a, new Point(a).y); }
Expand Down
Loading